From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932459AbdBQI2S (ORCPT ); Fri, 17 Feb 2017 03:28:18 -0500 Received: from mx3-phx2.redhat.com ([209.132.183.24]:55797 "EHLO mx3-phx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754542AbdBQI2R (ORCPT ); Fri, 17 Feb 2017 03:28:17 -0500 Date: Fri, 17 Feb 2017 03:28:17 -0500 (EST) From: Paolo Bonzini To: Bandan Das Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Message-ID: <2103533406.23066784.1487320097082.JavaMail.zimbra@redhat.com> In-Reply-To: References: <20170215220048.3423-1-pbonzini@redhat.com> <20170215220048.3423-3-pbonzini@redhat.com> Subject: Re: [PATCH 2/3] KVM: use separate generations for each address space MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.4.164.1, 10.5.100.50] X-Mailer: Zimbra 8.0.6_GA_5922 (ZimbraWebClient - FF51 (Linux)/8.0.6_GA_5922) Thread-Topic: use separate generations for each address space Thread-Index: qKZL3hE67Yg1E3ikx7J5Nhh9qjtPRw== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > + /* > > + * 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 ? Actually, a better match is RCU_INIT_POINTER. Here there is no concurrent reader because we're just initializing the struct kvm. There is something else providing synchronization between this writer and the "first" RCU read-side. It could be signaling a condition variable, creating a thread, or releasing a mutex; all three of them have release semantics, which means they imply a smp_wmb just like rcu_assign_pointer does. Paolo > > 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); >