@@ -67,8 +67,14 @@ void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu)
6767 void __iomem * tima = local_paca -> kvm_hstate .xive_tima_virt ;
6868 u64 pq ;
6969
70- if (!tima )
70+ /*
71+ * Nothing to do if the platform doesn't have a XIVE
72+ * or this vCPU doesn't have its own XIVE context
73+ * (e.g. because it's not using an in-kernel interrupt controller).
74+ */
75+ if (!tima || !vcpu -> arch .xive_cam_word )
7176 return ;
77+
7278 eieio ();
7379 __raw_writeq (vcpu -> arch .xive_saved_state .w01 , tima + TM_QW1_OS );
7480 __raw_writel (vcpu -> arch .xive_cam_word , tima + TM_QW1_OS + TM_WORD2 );
@@ -160,6 +166,9 @@ static irqreturn_t xive_esc_irq(int irq, void *data)
160166 */
161167 vcpu -> arch .xive_esc_on = false;
162168
169+ /* This orders xive_esc_on = false vs. subsequent stale_p = true */
170+ smp_wmb (); /* goes with smp_mb() in cleanup_single_escalation */
171+
163172 return IRQ_HANDLED ;
164173}
165174
@@ -1113,6 +1122,31 @@ void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu)
11131122 vcpu -> arch .xive_esc_raddr = 0 ;
11141123}
11151124
1125+ /*
1126+ * In single escalation mode, the escalation interrupt is marked so
1127+ * that EOI doesn't re-enable it, but just sets the stale_p flag to
1128+ * indicate that the P bit has already been dealt with. However, the
1129+ * assembly code that enters the guest sets PQ to 00 without clearing
1130+ * stale_p (because it has no easy way to address it). Hence we have
1131+ * to adjust stale_p before shutting down the interrupt.
1132+ */
1133+ void xive_cleanup_single_escalation (struct kvm_vcpu * vcpu ,
1134+ struct kvmppc_xive_vcpu * xc , int irq )
1135+ {
1136+ struct irq_data * d = irq_get_irq_data (irq );
1137+ struct xive_irq_data * xd = irq_data_get_irq_handler_data (d );
1138+
1139+ /*
1140+ * This slightly odd sequence gives the right result
1141+ * (i.e. stale_p set if xive_esc_on is false) even if
1142+ * we race with xive_esc_irq() and xive_irq_eoi().
1143+ */
1144+ xd -> stale_p = false;
1145+ smp_mb (); /* paired with smb_wmb in xive_esc_irq */
1146+ if (!vcpu -> arch .xive_esc_on )
1147+ xd -> stale_p = true;
1148+ }
1149+
11161150void kvmppc_xive_cleanup_vcpu (struct kvm_vcpu * vcpu )
11171151{
11181152 struct kvmppc_xive_vcpu * xc = vcpu -> arch .xive_vcpu ;
@@ -1134,20 +1168,28 @@ void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu)
11341168 /* Mask the VP IPI */
11351169 xive_vm_esb_load (& xc -> vp_ipi_data , XIVE_ESB_SET_PQ_01 );
11361170
1137- /* Disable the VP */
1138- xive_native_disable_vp (xc -> vp_id );
1139-
1140- /* Free the queues & associated interrupts */
1171+ /* Free escalations */
11411172 for (i = 0 ; i < KVMPPC_XIVE_Q_COUNT ; i ++ ) {
1142- struct xive_q * q = & xc -> queues [i ];
1143-
1144- /* Free the escalation irq */
11451173 if (xc -> esc_virq [i ]) {
1174+ if (xc -> xive -> single_escalation )
1175+ xive_cleanup_single_escalation (vcpu , xc ,
1176+ xc -> esc_virq [i ]);
11461177 free_irq (xc -> esc_virq [i ], vcpu );
11471178 irq_dispose_mapping (xc -> esc_virq [i ]);
11481179 kfree (xc -> esc_virq_names [i ]);
11491180 }
1150- /* Free the queue */
1181+ }
1182+
1183+ /* Disable the VP */
1184+ xive_native_disable_vp (xc -> vp_id );
1185+
1186+ /* Clear the cam word so guest entry won't try to push context */
1187+ vcpu -> arch .xive_cam_word = 0 ;
1188+
1189+ /* Free the queues */
1190+ for (i = 0 ; i < KVMPPC_XIVE_Q_COUNT ; i ++ ) {
1191+ struct xive_q * q = & xc -> queues [i ];
1192+
11511193 xive_native_disable_queue (xc -> vp_id , q , i );
11521194 if (q -> qpage ) {
11531195 free_pages ((unsigned long )q -> qpage ,
0 commit comments