From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v2 2/4] KVM: introduce "xinterface" API for external interaction with guests Date: Wed, 07 Oct 2009 10:11:50 +0200 Message-ID: <4ACC4D46.1090805@redhat.com> References: <20091002201159.4014.33268.stgit@dev.haskins.net> <20091002201927.4014.29432.stgit@dev.haskins.net> <4AC8780D.1060800@redhat.com> <4ACA87D7.1080206@gmail.com> <4ACB0F3C.1000705@redhat.com> <4ACB46AD.8010405@gmail.com> <4ACB528D.6030408@gmail.com> <4ACB6F0E.4000407@redhat.com> <4ACB7794.5040308@gmail.com> <4ACB77C8.9060007@gmail.com> <4ACB9D24.2060105@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Gregory Haskins , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "alacrityvm-devel@lists.sourceforge.net" , David Howells To: Gregory Haskins Return-path: In-Reply-To: <4ACB9D24.2060105@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 10/06/2009 09:40 PM, Gregory Haskins wrote: > Thinking about this some more over lunch, I think we (Avi and I) might > both be wrong (and David is right). Avi is right that we don't need > rmb() or barrier() for the reasons already stated, but I think David is > right that we need an smp_mb() to ensure the cpu doesn't do the > reordering. Otherwise a different cpu could invalidate the memory if it > reuses the freed memory in the meantime, iiuc. IOW: its not a compiler > issue but a cpu issue. > > Or am I still confused? > > The sequence of operations is: v = p->v; f(); // rmb() ? g(v); You are worried that the compiler or cpu will fetch p->v after f() has executed? The compiler may not, since it can't tell whether f() might change p->v. If f() can cause another agent to write to p (by freeing it to a global list, for example), then it is its responsibility to issue the smp_rmb(), otherwise no calculation that took place before f() and accessed p is safe. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.