diff mbox series

[1/5] KVM: PPC: Book3S HV: Hold kvm->mmu_lock across updating nested pte rc bits

Message ID 20181221032843.13012-2-sjitindarsingh@gmail.com (mailing list archive)
State New, archived
Headers show
Series KVM: PPC: Book3S HV: Fix dirty page logging for a nested guest | expand

Commit Message

Suraj Jitindar Singh Dec. 21, 2018, 3:28 a.m. UTC
We already hold the kvm->mmu_lock spin lock across updating the rc bits
in the pte for the L1 guest. Continue to hold the lock across updating
the rc bits in the pte for the nested guest as well to prevent
invalidations from occurring.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_nested.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

David Gibson Jan. 2, 2019, 2:47 a.m. UTC | #1
On Fri, Dec 21, 2018 at 02:28:39PM +1100, Suraj Jitindar Singh wrote:
> We already hold the kvm->mmu_lock spin lock across updating the rc bits
> in the pte for the L1 guest. Continue to hold the lock across updating
> the rc bits in the pte for the nested guest as well to prevent
> invalidations from occurring.
> 
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  arch/powerpc/kvm/book3s_hv_nested.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
> index 401d2ecbebc5..0dfbf093bde5 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -1049,7 +1049,7 @@ static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
>  	struct kvm *kvm = vcpu->kvm;
>  	bool writing = !!(dsisr & DSISR_ISSTORE);
>  	u64 pgflags;
> -	bool ret;
> +	long ret;
>  
>  	/* Are the rc bits set in the L1 partition scoped pte? */
>  	pgflags = _PAGE_ACCESSED;
> @@ -1062,16 +1062,22 @@ static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
>  	/* Set the rc bit in the pte of our (L0) pgtable for the L1 guest */
>  	ret = kvmppc_hv_handle_set_rc(kvm, kvm->arch.pgtable, writing,
>  				     gpte.raddr, kvm->arch.lpid);
> -	spin_unlock(&kvm->mmu_lock);
> -	if (!ret)
> -		return -EINVAL;
> +	if (!ret) {
> +		ret = -EINVAL;
> +		goto out_unlock;
> +	}
>  
>  	/* Set the rc bit in the pte of the shadow_pgtable for the nest guest */
>  	ret = kvmppc_hv_handle_set_rc(kvm, gp->shadow_pgtable, writing, n_gpa,
>  				      gp->shadow_lpid);
>  	if (!ret)
> -		return -EINVAL;
> -	return 0;
> +		ret = -EINVAL;
> +	else
> +		ret = 0;
> +
> +out_unlock:
> +	spin_unlock(&kvm->mmu_lock);
> +	return ret;
>  }
>  
>  static inline int kvmppc_radix_level_to_shift(int level)
diff mbox series

Patch

diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
index 401d2ecbebc5..0dfbf093bde5 100644
--- a/arch/powerpc/kvm/book3s_hv_nested.c
+++ b/arch/powerpc/kvm/book3s_hv_nested.c
@@ -1049,7 +1049,7 @@  static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
 	struct kvm *kvm = vcpu->kvm;
 	bool writing = !!(dsisr & DSISR_ISSTORE);
 	u64 pgflags;
-	bool ret;
+	long ret;
 
 	/* Are the rc bits set in the L1 partition scoped pte? */
 	pgflags = _PAGE_ACCESSED;
@@ -1062,16 +1062,22 @@  static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
 	/* Set the rc bit in the pte of our (L0) pgtable for the L1 guest */
 	ret = kvmppc_hv_handle_set_rc(kvm, kvm->arch.pgtable, writing,
 				     gpte.raddr, kvm->arch.lpid);
-	spin_unlock(&kvm->mmu_lock);
-	if (!ret)
-		return -EINVAL;
+	if (!ret) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
 
 	/* Set the rc bit in the pte of the shadow_pgtable for the nest guest */
 	ret = kvmppc_hv_handle_set_rc(kvm, gp->shadow_pgtable, writing, n_gpa,
 				      gp->shadow_lpid);
 	if (!ret)
-		return -EINVAL;
-	return 0;
+		ret = -EINVAL;
+	else
+		ret = 0;
+
+out_unlock:
+	spin_unlock(&kvm->mmu_lock);
+	return ret;
 }
 
 static inline int kvmppc_radix_level_to_shift(int level)