public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/MMU: Do not check unsync status for root SP.
@ 2021-01-16  0:21 Yu Zhang
  2021-01-26 13:45 ` Yu Zhang
  2021-02-05 17:50 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Yu Zhang @ 2021-01-16  0:21 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel, seanjc, vkuznets, wanpengli, jmattson, joro

In shadow page table, only leaf SPs may be marked as unsync.
And for non-leaf SPs, we use unsync_children to keep the number
of the unsynced children. In kvm_mmu_sync_root(), sp->unsync
shall always be zero for the root SP, hence no need to check it.

Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
---
 arch/x86/kvm/mmu/mmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 6d16481a..1a6bb03 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3412,8 +3412,7 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
 		 * mmu_need_write_protect() describe what could go wrong if this
 		 * requirement isn't satisfied.
 		 */
-		if (!smp_load_acquire(&sp->unsync) &&
-		    !smp_load_acquire(&sp->unsync_children))
+		if (!smp_load_acquire(&sp->unsync_children))
 			return;
 
 		spin_lock(&vcpu->kvm->mmu_lock);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86/MMU: Do not check unsync status for root SP.
  2021-01-16  0:21 [PATCH] KVM: x86/MMU: Do not check unsync status for root SP Yu Zhang
@ 2021-01-26 13:45 ` Yu Zhang
  2021-02-05 17:50 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Yu Zhang @ 2021-01-26 13:45 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel, seanjc, vkuznets, wanpengli, jmattson, joro

Hi Paolo,

  Any comments? Thanks!

B.R.
Yu

On Sat, Jan 16, 2021 at 08:21:00AM +0800, Yu Zhang wrote:
> In shadow page table, only leaf SPs may be marked as unsync.
> And for non-leaf SPs, we use unsync_children to keep the number
> of the unsynced children. In kvm_mmu_sync_root(), sp->unsync
> shall always be zero for the root SP, hence no need to check it.
> 
> Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> ---
>  arch/x86/kvm/mmu/mmu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 6d16481a..1a6bb03 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -3412,8 +3412,7 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
>  		 * mmu_need_write_protect() describe what could go wrong if this
>  		 * requirement isn't satisfied.
>  		 */
> -		if (!smp_load_acquire(&sp->unsync) &&
> -		    !smp_load_acquire(&sp->unsync_children))
> +		if (!smp_load_acquire(&sp->unsync_children))
>  			return;
>  
>  		spin_lock(&vcpu->kvm->mmu_lock);
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86/MMU: Do not check unsync status for root SP.
  2021-01-16  0:21 [PATCH] KVM: x86/MMU: Do not check unsync status for root SP Yu Zhang
  2021-01-26 13:45 ` Yu Zhang
@ 2021-02-05 17:50 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2021-02-05 17:50 UTC (permalink / raw)
  To: Yu Zhang; +Cc: pbonzini, kvm, linux-kernel, vkuznets, wanpengli, jmattson, joro

On Sat, Jan 16, 2021, Yu Zhang wrote:
> In shadow page table, only leaf SPs may be marked as unsync.
> And for non-leaf SPs, we use unsync_children to keep the number
> of the unsynced children. In kvm_mmu_sync_root(), sp->unsync
> shall always be zero for the root SP, hence no need to check it.
> 
> Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> ---
>  arch/x86/kvm/mmu/mmu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 6d16481a..1a6bb03 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -3412,8 +3412,7 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
>  		 * mmu_need_write_protect() describe what could go wrong if this
>  		 * requirement isn't satisfied.
>  		 */
> -		if (!smp_load_acquire(&sp->unsync) &&
> -		    !smp_load_acquire(&sp->unsync_children))
> +		if (!smp_load_acquire(&sp->unsync_children))
>  			return;
>  
>  		spin_lock(&vcpu->kvm->mmu_lock);

Looks good.  To make this less scary and more obviously correct, maybe move the
the WARN on !PG_LEVEL_4K into kvm_unsync_page() instead of having the WARN in
its sole caller, and add a WARN in mmu_sync_children()?

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 86af58294272..bc8ee05bb3d3 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -1995,6 +1995,12 @@ static void mmu_sync_children(struct kvm_vcpu *vcpu,
        LIST_HEAD(invalid_list);
        bool flush = false;

+       /*
+        * Only 4k SPTEs can directly be made unsync, the root shadow page
+        * should never be unsyc'd.
+        */
+       WARN_ON_ONCE(sp->unsync);
+
        while (mmu_unsync_walk(parent, &pages)) {
                bool protected = false;

@@ -2502,6 +2508,8 @@ EXPORT_SYMBOL_GPL(kvm_mmu_unprotect_page);

 static void kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
 {
+       WARN_ON(sp->role.level != PG_LEVEL_4K);
+
        trace_kvm_mmu_unsync_page(sp);
        ++vcpu->kvm->stat.mmu_unsync;
        sp->unsync = 1;
@@ -2524,7 +2532,6 @@ bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
                if (sp->unsync)
                        continue;

-               WARN_ON(sp->role.level != PG_LEVEL_4K);
                kvm_unsync_page(vcpu, sp);
        }

@@ -3406,8 +3413,7 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
                 * mmu_need_write_protect() describe what could go wrong if this
                 * requirement isn't satisfied.
                 */
-               if (!smp_load_acquire(&sp->unsync) &&
-                   !smp_load_acquire(&sp->unsync_children))
+               if (!smp_load_acquire(&sp->unsync_children))
                        return;

                write_lock(&vcpu->kvm->mmu_lock);


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-05 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-16  0:21 [PATCH] KVM: x86/MMU: Do not check unsync status for root SP Yu Zhang
2021-01-26 13:45 ` Yu Zhang
2021-02-05 17:50 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox