kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Yu Zhao <yuzhao@google.com>, Gleb Natapov <gleb@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2] kvm: set page dirty only if page has been writable
Date: Wed, 30 Mar 2016 23:08:06 +0200	[thread overview]
Message-ID: <56FC4036.1090501@redhat.com> (raw)
In-Reply-To: <1459370289-15994-1-git-send-email-yuzhao@google.com>



On 30/03/2016 22:38, Yu Zhao wrote:
> In absence of shadow dirty mask, there is no need to set page dirty
> if page has never been writable. This is a tiny optimization but
> good to have for people who care much about dirty page tracking.
> 
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> ---
>  arch/x86/kvm/mmu.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 70e95d0..1ff4dbb 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -557,8 +557,15 @@ static bool mmu_spte_update(u64 *sptep, u64 new_spte)
>  	      !is_writable_pte(new_spte))
>  		ret = true;
>  
> -	if (!shadow_accessed_mask)
> +	if (!shadow_accessed_mask) {
> +		/*
> +		 * We don't set page dirty when dropping non-writable spte.
> +		 * So do it now if the new spte is becoming non-writable.
> +		 */
> +		if (ret)
> +			kvm_set_pfn_dirty(spte_to_pfn(old_spte));
>  		return ret;
> +	}
>  
>  	/*
>  	 * Flush TLB when accessed/dirty bits are changed in the page tables,
> @@ -605,7 +612,8 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
>  
>  	if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
>  		kvm_set_pfn_accessed(pfn);
> -	if (!shadow_dirty_mask || (old_spte & shadow_dirty_mask))
> +	if (old_spte & (shadow_dirty_mask ? shadow_dirty_mask :
> +					    PT_WRITABLE_MASK))
>  		kvm_set_pfn_dirty(pfn);
>  	return 1;
>  }
> 

Looks good, thanks!

Paolo

      reply	other threads:[~2016-03-30 21:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 20:38 [PATCH v2] kvm: set page dirty only if page has been writable Yu Zhao
2016-03-30 21:08 ` Paolo Bonzini [this message]

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=56FC4036.1090501@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yuzhao@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).