public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: mtosatti@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2 6/6] KVM: MMU: init kvm generation close to mmio wrap-around value
Date: Thu, 25 Apr 2013 17:23:14 +0800	[thread overview]
Message-ID: <5178F602.9040100@linux.vnet.ibm.com> (raw)
In-Reply-To: <20130424125911.GQ12401@redhat.com>

On 04/24/2013 08:59 PM, Gleb Natapov wrote:
> On Mon, Apr 01, 2013 at 05:56:49PM +0800, Xiao Guangrong wrote:
>> Then it has chance to trigger mmio generation number wrap-around
>>
>> Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
>> ---
>>  arch/x86/include/asm/kvm_host.h |    1 +
>>  arch/x86/kvm/mmu.c              |    8 ++++++++
>>  virt/kvm/kvm_main.c             |    6 ++++++
>>  3 files changed, 15 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
>> index 6c1e642..4e1f7cb 100644
>> --- a/arch/x86/include/asm/kvm_host.h
>> +++ b/arch/x86/include/asm/kvm_host.h
>> @@ -767,6 +767,7 @@ void kvm_mmu_write_protect_pt_masked(struct kvm *kvm,
>>  				     struct kvm_memory_slot *slot,
>>  				     gfn_t gfn_offset, unsigned long mask);
>>  void kvm_mmu_zap_all(struct kvm *kvm);
>> +void kvm_arch_init_generation(struct kvm *kvm);
>>  void kvm_mmu_invalid_mmio_sptes(struct kvm *kvm);
>>  unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
>>  void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
>> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
>> index d314e21..dcc059c 100644
>> --- a/arch/x86/kvm/mmu.c
>> +++ b/arch/x86/kvm/mmu.c
>> @@ -4279,6 +4279,14 @@ restart:
>>  	spin_unlock(&kvm->mmu_lock);
>>  }
>>  
>> +void kvm_arch_init_generation(struct kvm *kvm)
>> +{
>> +	mutex_lock(&kvm->slots_lock);
>> +	/* It is easier to trigger mmio generation-number wrap-around. */
>> +	kvm_memslots(kvm)->generation = MMIO_MAX_GEN - 13;
> kvm_memslots(kvm)->generation should never overflow since
> (read|write)_cached mechanism does not handle it. Initialising it to
> anything but 0 makes overflow more likely.
> 
> You can hide mmio overflow trick in kvm_current_mmio_generation():
> 
> static unsigned int kvm_current_mmio_generation(struct kvm *kvm)
> {
> 	return (kvm_memslots(kvm)->generation + MMIO_MAX_GEN - 13) & MMIO_GEN_MASK;
> }

Very smart idea. Thanks you, Gleb!

  reply	other threads:[~2013-04-25  9:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01  9:56 [PATCH v2 0/6] KVM: MMU: fast invalid all mmio sptes Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 1/6] KVM: MMU: retain more available bits on mmio spte Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 2/6] KVM: MMU: store generation-number into " Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 3/6] KVM: MMU: make return value of mmio page fault handler more readable Xiao Guangrong
2013-04-24 13:34   ` Gleb Natapov
2013-04-25  9:24     ` Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 4/6] KVM: MMU: fast invalid all mmio sptes Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 5/6] KVM: MMU: add tracepoint for check_mmio_spte Xiao Guangrong
2013-04-01  9:56 ` [PATCH v2 6/6] KVM: MMU: init kvm generation close to mmio wrap-around value Xiao Guangrong
2013-04-24 12:59   ` Gleb Natapov
2013-04-25  9:23     ` Xiao Guangrong [this message]
2013-04-16  0:54 ` [PATCH v2 0/6] KVM: MMU: fast invalid all mmio sptes Marcelo Tosatti
2013-04-16  3:09   ` Xiao Guangrong

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=5178F602.9040100@linux.vnet.ibm.com \
    --to=xiaoguangrong@linux.vnet.ibm.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.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