From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08DA8C4332E for ; Fri, 20 Mar 2020 04:11:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF2E020773 for ; Fri, 20 Mar 2020 04:11:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726866AbgCTELD (ORCPT ); Fri, 20 Mar 2020 00:11:03 -0400 Received: from mga02.intel.com ([134.134.136.20]:8176 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgCTELD (ORCPT ); Fri, 20 Mar 2020 00:11:03 -0400 IronPort-SDR: nPLQpVSQWslliwwzUsTqjkrtVj+4Qem5kNU8KAPXRbb0v1xZLWbQHvDv0IrcfvQcmaR0HJByJ9 tc5L2BPXmunQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2020 21:11:02 -0700 IronPort-SDR: w3bTWbbZ23larvI1SORC8UY+DGaYEWukj8OMaFJtlkwN6+aHD0PU/e1A1LWlFgIdUzLw7U0+On RZoOtJ3LqgQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,283,1580803200"; d="scan'208";a="418586574" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga005.jf.intel.com with ESMTP; 19 Mar 2020 21:11:02 -0700 Date: Thu, 19 Mar 2020 21:11:02 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , Junaid Shahid , Liran Alon , Boris Ostrovsky , John Haxby , Miaohe Lin , Tom Lendacky Subject: Re: [PATCH v2 04/32] KVM: nVMX: Invalidate all L2 roots when emulating INVVPID without EPT Message-ID: <20200320041102.GG11305@linux.intel.com> References: <20200317045238.30434-1-sean.j.christopherson@intel.com> <20200317045238.30434-5-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200317045238.30434-5-sean.j.christopherson@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, Mar 16, 2020 at 09:52:10PM -0700, Sean Christopherson wrote: > From: Junaid Shahid > > Free all L2 (guest_mmu) roots when emulating INVVPID for L1 and EPT is > disabled, as outstanding changes to the page tables managed by L1 need > to be recognized. > > Similar to handle_invpcid() and handle_invept(), rely on > kvm_mmu_free_roots() to do a remote TLB flush if necessary, e.g. if L1 > has never entered L2 then there is nothing to be done. > > Fixes: 5c614b3583e7b ("KVM: nVMX: nested VPID emulation") > Signed-off-by: Junaid Shahid > [sean: ported to upstream KVM, reworded the comment and changelog] > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/nested.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index 9624cea4ed9f..50bb7d8862aa 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -5250,6 +5250,17 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) > return kvm_skip_emulated_instruction(vcpu); > } > > + /* > + * Sync L2's shadow page tables if EPT is disabled, L1 is effectively > + * invalidating linear mappings for L2 (tagged with L2's VPID). Sync > + * all roots as VPIDs are not tracked in the MMU role. > + * > + * TODO: sync only the affected SPTEs for INVDIVIDUAL_ADDR. > + */ > + if (!enable_ept) > + kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, Aha! This is wrong. guest_mmu is only used if EPT is enabled. The silver lining is that I have confirmed that this code is needed and works as intended (when the correct mmu is nuked). > + KVM_MMU_ROOTS_ALL); > + > return nested_vmx_succeed(vcpu); > } > > -- > 2.24.1 >