From: Bandan Das <bsd@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: use separate generations for each address space
Date: Thu, 16 Feb 2017 19:29:15 -0500 [thread overview]
Message-ID: <jpg37fdacdg.fsf@linux.bootlegged.copy> (raw)
In-Reply-To: 20170215220048.3423-3-pbonzini@redhat.com
Paolo Bonzini <pbonzini@redhat.com> writes:
> This will make it easier to support multiple address spaces in
> kvm_gfn_to_hva_cache_init. Instead of having to check the address
> space id, we can keep on checking just the generation number.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> virt/kvm/kvm_main.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index e21bac7ed5d3..a83c186cefc1 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -506,11 +506,6 @@ static struct kvm_memslots *kvm_alloc_memslots(void)
> if (!slots)
> return NULL;
>
> - /*
> - * Init kvm generation close to the maximum to easily test the
> - * code of handling generation number wrap-around.
> - */
> - slots->generation = -150;
> for (i = 0; i < KVM_MEM_SLOTS_NUM; i++)
> slots->id_to_index[i] = slots->memslots[i].id = i;
>
> @@ -641,9 +636,16 @@ static struct kvm *kvm_create_vm(unsigned long type)
>
> r = -ENOMEM;
> for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
> - kvm->memslots[i] = kvm_alloc_memslots();
> - if (!kvm->memslots[i])
> + struct kvm_memslots *slots = kvm_alloc_memslots();
> + if (!slots)
> goto out_err_no_srcu;
> + /*
> + * Generations must be different for each address space.
> + * Init kvm generation close to the maximum to easily test the
> + * code of handling generation number wrap-around.
> + */
> + slots->generation = i * 2 - 150;
> + rcu_assign_pointer(kvm->memslots[i], slots);
> }
I can't seem to understand why rcu_assign_pointer wasn't used before.
kvm->memslots[i] was a rcu protected pointer even before this change,
right ?
> if (init_srcu_struct(&kvm->srcu))
> @@ -870,8 +872,14 @@ static struct kvm_memslots *install_new_memslots(struct kvm *kvm,
> * Increment the new memslot generation a second time. This prevents
> * vm exits that race with memslot updates from caching a memslot
> * generation that will (potentially) be valid forever.
> + *
> + * Generations must be unique even across address spaces. We do not need
> + * a global counter for that, instead the generation space is evenly split
> + * across address spaces. For example, with two address spaces, address
> + * space 0 will use generations 0, 4, 8, ... while * address space 1 will
> + * use generations 2, 6, 10, 14, ...
> */
> - slots->generation++;
> + slots->generation += KVM_ADDRESS_SPACE_NUM * 2 - 1;
>
> kvm_arch_memslots_updated(kvm, slots);
next prev parent reply other threads:[~2017-02-17 0:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-15 22:00 [PATCH 0/3] KVM: change gfn->hva cache to use per-VCPU memslots Paolo Bonzini
2017-02-15 22:00 ` [PATCH 1/3] KVM: only retrieve memslots once when initializing cache Paolo Bonzini
2017-02-16 16:31 ` Radim Krčmář
2017-02-15 22:00 ` [PATCH 2/3] KVM: use separate generations for each address space Paolo Bonzini
2017-02-16 17:04 ` Radim Krčmář
2017-02-17 0:29 ` Bandan Das [this message]
2017-02-17 8:28 ` Paolo Bonzini
2017-02-15 22:00 ` [PATCH 3/3] KVM: Support vCPU-based gfn->hva cache Paolo Bonzini
2017-02-16 17:07 ` Radim Krčmář
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=jpg37fdacdg.fsf@linux.bootlegged.copy \
--to=bsd@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@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;
as well as URLs for NNTP newsgroup(s).