From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH v3] kvm: x86: fix stale mmio cache bug Date: Fri, 08 Aug 2014 09:36:20 +0800 Message-ID: <53E42994.7040700@linux.vnet.ibm.com> References: <1407436366-7582-1-git-send-email-dmatlack@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Eric Northup To: David Matlack , Gleb Natapov , Paolo Bonzini , kvm@vger.kernel.org, x86@kernel.org Return-path: Received: from e23smtp02.au.ibm.com ([202.81.31.144]:45986 "EHLO e23smtp02.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754814AbaHHBg2 (ORCPT ); Thu, 7 Aug 2014 21:36:28 -0400 Received: from /spool/local by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 Aug 2014 11:36:26 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 5A8632BB0052 for ; Fri, 8 Aug 2014 11:36:23 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay06.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s781axHY17825972 for ; Fri, 8 Aug 2014 11:37:00 +1000 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s781aLeP019908 for ; Fri, 8 Aug 2014 11:36:22 +1000 In-Reply-To: <1407436366-7582-1-git-send-email-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org List-ID: On 08/08/2014 02:32 AM, David Matlack wrote: > The following events can lead to an incorrect KVM_EXIT_MMIO bubbling > up to userspace: > > (1) Guest accesses gpa X without a memory slot. The gfn is cached in > struct kvm_vcpu_arch (mmio_gfn). On Intel EPT-enabled hosts, KVM sets > the SPTE write-execute-noread so that future accesses cause > EPT_MISCONFIGs. > > (2) Host userspace creates a memory slot via KVM_SET_USER_MEMORY_REGION > covering the page just accessed. > > (3) Guest attempts to read or write to gpa X again. On Intel, this > generates an EPT_MISCONFIG. The memory slot generation number that > was incremented in (2) would normally take care of this but we fast > path mmio faults through quickly_check_mmio_pf(), which only checks > the per-vcpu mmio cache. Since we hit the cache, KVM passes a > KVM_EXIT_MMIO up to userspace. > > This patch fixes the issue by using the memslot generation number > to validate the mmio cache. > > Signed-off-by: David Matlack > --- > The patch diff is rather large because I had to pull some code out > of x86.h and mmu.c and into mmu.h. The main change is adding the > memslot generation in vcpu_cach_mmio_info() and then validating > that slot in vcpu_match_mmio_*(). Why not just move vcpu_cach_mmio_info() into mmu.c where is the only place vcpu_cach_mmio_info is called. :) BTW, i will post a patch to fix the generation-number issue soon.