From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH 2/2] KVM: Prevent internal slots from being COWed Date: Mon, 21 Jun 2010 17:23:34 -0300 Message-ID: <20100621202334.GA17362@amt.cnet> References: <1277108293-9918-1-git-send-email-avi@redhat.com> <1277108293-9918-3-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20973 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758245Ab0FUUeA (ORCPT ); Mon, 21 Jun 2010 16:34:00 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5LKY0j9012825 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Jun 2010 16:34:00 -0400 Content-Disposition: inline In-Reply-To: <1277108293-9918-3-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jun 21, 2010 at 11:18:13AM +0300, Avi Kivity wrote: > If a process with a memory slot is COWed, the page will change its address > (despite having an elevated reference count). This breaks internal memory > slots which have their physical addresses loaded into vmcs registers (see > the APIC access memory slot). > > Signed-off-by: Avi Kivity > --- > arch/x86/kvm/x86.c | 5 +++++ > 1 files changed, 5 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 33156a3..d9a33e6 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -5633,6 +5633,11 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > int user_alloc) > { > int npages = memslot->npages; > + int map_flags = MAP_PRIVATE | MAP_ANONYMOUS; > + > + /* Prevent internal slot pages from being moved by fork()/COW. */ > + if (memslot->id >= KVM_MEMORY_SLOTS) > + map_flags = MAP_SHARED | MAP_ANONYMOUS; > > /*To keep backward compatibility with older userspace, > *x86 needs to hanlde !user_alloc case. Forgot to use map_flags below.