All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuan Yao <yuan.yao@linux.intel.com>
To: Yun Lu <luyun_611@163.com>
Cc: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com,
	wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/mmu: optimizing the code in mmu_try_to_unsync_pages
Date: Fri, 20 May 2022 17:54:28 +0800	[thread overview]
Message-ID: <20220520095428.bahy37jxkznqtwx5@yy-desk-7060> (raw)
In-Reply-To: <20220520060907.863136-1-luyun_611@163.com>

On Fri, May 20, 2022 at 02:09:07PM +0800, Yun Lu wrote:
> There is no need to check can_unsync and prefetch in the loop
> every time, just move this check before the loop.
>
> Signed-off-by: Yun Lu <luyun@kylinos.cn>
> ---
>  arch/x86/kvm/mmu/mmu.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 311e4e1d7870..e51e7735adca 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -2534,6 +2534,12 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
>  	if (kvm_slot_page_track_is_active(kvm, slot, gfn, KVM_PAGE_TRACK_WRITE))
>  		return -EPERM;
>
> +	if (!can_unsync)
> +		return -EPERM;
> +
> +	if (prefetch)
> +		return -EEXIST;
> +
>  	/*
>  	 * The page is not write-tracked, mark existing shadow pages unsync
>  	 * unless KVM is synchronizing an unsync SP (can_unsync = false).  In
> @@ -2541,15 +2547,9 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
>  	 * allowing shadow pages to become unsync (writable by the guest).
>  	 */
>  	for_each_gfn_indirect_valid_sp(kvm, sp, gfn) {
> -		if (!can_unsync)
> -			return -EPERM;
> -
>  		if (sp->unsync)
>  			continue;
>
> -		if (prefetch)
> -			return -EEXIST;
> -

Consider the case that for_each_gfn_indirect_valid_sp() loop is
not triggered, means the gfn is not MMU page table page:

The old behavior when : return 0;
The new behavior with this change: returrn -EPERM / -EEXIST;

It at least breaks FNAME(sync_page) -> make_spte(prefetch = true, can_unsync = false)
which removes PT_WRITABLE_MASK from last level mapping unexpectedly.


>  		/*
>  		 * TDP MMU page faults require an additional spinlock as they
>  		 * run with mmu_lock held for read, not write, and the unsync
> --
> 2.25.1
>
>
> No virus found
> 		Checked by Hillstone Network AntiVirus
>

  reply	other threads:[~2022-05-20  9:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20  6:09 [PATCH] KVM: x86/mmu: optimizing the code in mmu_try_to_unsync_pages Yun Lu
2022-05-20  9:54 ` Yuan Yao [this message]
2022-05-20 14:47   ` Sean Christopherson
2022-05-23  9:27     ` Yun Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220520095428.bahy37jxkznqtwx5@yy-desk-7060 \
    --to=yuan.yao@linux.intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luyun_611@163.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.