KVM: PPC: Book3S HV: Don't lose pending doorbell request on migration on P9
diff mbox series

Message ID 20190827013540.GC16075@blackberry
State Accepted
Headers show
Series
  • KVM: PPC: Book3S HV: Don't lose pending doorbell request on migration on P9
Related show

Commit Message

Paul Mackerras Aug. 27, 2019, 1:35 a.m. UTC
On POWER9, when userspace reads the value of the DPDES register on a
vCPU, it is possible for 0 to be returned although there is a doorbell
interrupt pending for the vCPU.  This can lead to a doorbell interrupt
being lost across migration.  If the guest kernel uses doorbell
interrupts for IPIs, then it could malfunction because of the lost
interrupt.

This happens because a newly-generated doorbell interrupt is signalled
by setting vcpu->arch.doorbell_request to 1; the DPDES value in
vcpu->arch.vcore->dpdes is not updated, because it can only be updated
when holding the vcpu mutex, in order to avoid races.

To fix this, we OR in vcpu->arch.doorbell_request when reading the
DPDES value.

Cc: stable@vger.kernel.org # v4.13+
Fixes: 579006944e0d ("KVM: PPC: Book3S HV: Virtualize doorbell facility on POWER9")
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
 arch/powerpc/kvm/book3s_hv.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Alexey Kardashevskiy Aug. 27, 2019, 1:54 a.m. UTC | #1
On 27/08/2019 11:35, Paul Mackerras wrote:
> On POWER9, when userspace reads the value of the DPDES register on a
> vCPU, it is possible for 0 to be returned although there is a doorbell
> interrupt pending for the vCPU.  This can lead to a doorbell interrupt
> being lost across migration.  If the guest kernel uses doorbell
> interrupts for IPIs, then it could malfunction because of the lost
> interrupt.
> 
> This happens because a newly-generated doorbell interrupt is signalled
> by setting vcpu->arch.doorbell_request to 1; the DPDES value in
> vcpu->arch.vcore->dpdes is not updated, because it can only be updated
> when holding the vcpu mutex, in order to avoid races.
> 
> To fix this, we OR in vcpu->arch.doorbell_request when reading the
> DPDES value.
> 
> Cc: stable@vger.kernel.org # v4.13+
> Fixes: 579006944e0d ("KVM: PPC: Book3S HV: Virtualize doorbell facility on POWER9")
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>



Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>


> ---
>   arch/powerpc/kvm/book3s_hv.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index ca6c6ec..88c42e7 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -1678,7 +1678,14 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
>   		*val = get_reg_val(id, vcpu->arch.pspb);
>   		break;
>   	case KVM_REG_PPC_DPDES:
> -		*val = get_reg_val(id, vcpu->arch.vcore->dpdes);
> +		/*
> +		 * On POWER9, where we are emulating msgsndp etc.,
> +		 * we return 1 bit for each vcpu, which can come from
> +		 * either vcore->dpdes or doorbell_request.
> +		 * On POWER8, doorbell_request is 0.
> +		 */
> +		*val = get_reg_val(id, vcpu->arch.vcore->dpdes |
> +				   vcpu->arch.doorbell_request);
>   		break;
>   	case KVM_REG_PPC_VTB:
>   		*val = get_reg_val(id, vcpu->arch.vcore->vtb);
>

Patch
diff mbox series

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index ca6c6ec..88c42e7 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1678,7 +1678,14 @@  static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 		*val = get_reg_val(id, vcpu->arch.pspb);
 		break;
 	case KVM_REG_PPC_DPDES:
-		*val = get_reg_val(id, vcpu->arch.vcore->dpdes);
+		/*
+		 * On POWER9, where we are emulating msgsndp etc.,
+		 * we return 1 bit for each vcpu, which can come from
+		 * either vcore->dpdes or doorbell_request.
+		 * On POWER8, doorbell_request is 0.
+		 */
+		*val = get_reg_val(id, vcpu->arch.vcore->dpdes |
+				   vcpu->arch.doorbell_request);
 		break;
 	case KVM_REG_PPC_VTB:
 		*val = get_reg_val(id, vcpu->arch.vcore->vtb);