Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3905427ybb; Mon, 23 Mar 2020 09:50:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvMg9115GGpj6hX7q2GQdEvSnqzu/TorZc0qOhvWyppA2oQR+HWvvM5TdXUk1wFw8FIQb6B X-Received: by 2002:a4a:bf19:: with SMTP id r25mr652573oop.3.1584982244124; Mon, 23 Mar 2020 09:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584982244; cv=none; d=google.com; s=arc-20160816; b=gdx9Rwc8Ry/+snSmw3GEk/Rch2ZKnPu1OwGIXyUDiZcLSJGDAD/e/q+LzxTz6EVkt1 1f9uGdpTaTDicR88rc0a4+jy08uLw97ttssiY6CrWwv39fW6yCNYcV1PjDKkIEpUB1Y3 aLCr9J6FEQs3XWnjBSPhRQCc9vG5PjnYO4Kx8/j0b7JggtREmqNYGC+T0XJR+8fF3aPn Bpij7FRBwfuWGPKwBHGhb/HpNyeRbTN8wUvWzn/GQJHT7KHZuvwffNNtzIq4VzF3Wd13 HYZbSJB4NI2+PetiLbySwq4cFUpltuLQXOktUpFhtyCtiOYtQs/kxkMgNBk6/8O+rjXw yRbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=/ItOyXTxhJ3pRMYEDPRUszmDc9lic5NOAGtEDFuLeek=; b=tIt+d4ukrREKUGcYFgcOBb+31CtYhxoV1rBnfoZzFesJEjWl9DpubUW6hskNe10+zT A4RGvJXG2xEU1tvHVnwLBO2abFRg5HF8KUhkdDBK618Eu/LlNDvGH44zipb5RNxdpLyt P9M4j/kqE+h/gwPAEsfR8YmpmzhYcAyZbKJqLBWw+Mj3U6U0oYPnqkq/XAEMmRKZR4Xi y46VF4oMtTLqTdGYu/9PpxqyQ7sQjfoMDULwixkWvbIMnmVsnJ0lh/z+G5CbYDYczVOK fzSp+UJQ97VGdqlHYZA5UlGUwyEnoUwH9yULuClyNJVDJZbZfzAchty/DKcyT3YQg4ic 4T6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w83si7336232oie.244.2020.03.23.09.50.31; Mon, 23 Mar 2020 09:50:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbgCWQuD (ORCPT + 99 others); Mon, 23 Mar 2020 12:50:03 -0400 Received: from mga02.intel.com ([134.134.136.20]:36306 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbgCWQuD (ORCPT ); Mon, 23 Mar 2020 12:50:03 -0400 IronPort-SDR: AuCpJwR6e+ND5waOSVyALQJStdbEozrPuOUoz/2Mxvlrcu1zQ1eQBxNe6dslk0xrCuFupYLwkT TTZ8E36hxLXg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2020 09:50:02 -0700 IronPort-SDR: YOjnM1lhGB6aAHFakbm39vv7nwcKvrPIL1qKbD+3OLR+h+dn9jhdjj/+lZlvnev8270tbaFZmK d5gqoSd7NAcQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,297,1580803200"; d="scan'208";a="447452716" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga006.fm.intel.com with ESMTP; 23 Mar 2020 09:50:01 -0700 Date: Mon, 23 Mar 2020 09:50:01 -0700 From: Sean Christopherson To: Vitaly Kuznetsov Cc: Paolo Bonzini , 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 v3 04/37] KVM: nVMX: Invalidate all roots when emulating INVVPID without EPT Message-ID: <20200323165001.GR28711@linux.intel.com> References: <20200320212833.3507-1-sean.j.christopherson@intel.com> <20200320212833.3507-5-sean.j.christopherson@intel.com> <87v9mv84qu.fsf@vitty.brq.redhat.com> <20200323160432.GJ28711@linux.intel.com> <87lfnr820r.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lfnr820r.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 05:33:08PM +0100, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > On Mon, Mar 23, 2020 at 04:34:17PM +0100, Vitaly Kuznetsov wrote: > >> Sean Christopherson writes: > >> > >> > From: Junaid Shahid > >> > > >> > Free all roots when emulating INVVPID for L1 and EPT is disabled, as > >> > outstanding changes to the page tables managed by L1 need to be > >> > recognized. Because L1 and L2 share an MMU when EPT is disabled, and > >> > because VPID is not tracked by the MMU role, all roots in the current > >> > MMU (root_mmu) need to be freed, otherwise a future nested VM-Enter or > >> > VM-Exit could do a fast CR3 switch (without a flush/sync) and consume > >> > stale SPTEs. > >> > > >> > 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 | 14 ++++++++++++++ > >> > 1 file changed, 14 insertions(+) > >> > > >> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > >> > index 9624cea4ed9f..bc74fbbf33c6 100644 > >> > --- a/arch/x86/kvm/vmx/nested.c > >> > +++ b/arch/x86/kvm/vmx/nested.c > >> > @@ -5250,6 +5250,20 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) > >> > return kvm_skip_emulated_instruction(vcpu); > >> > } > >> > > >> > + /* > >> > + * Sync the shadow page tables if EPT is disabled, L1 is invalidating > >> > + * linear mappings for L2 (tagged with L2's VPID). Free all roots as > >> > + * VPIDs are not tracked in the MMU role. > >> > + * > >> > + * Note, this operates on root_mmu, not guest_mmu, as L1 and L2 share > >> > + * an MMU when EPT is disabled. > >> > + * > >> > + * TODO: sync only the affected SPTEs for INVDIVIDUAL_ADDR. > >> > + */ > >> > + if (!enable_ept) > >> > + kvm_mmu_free_roots(vcpu, &vcpu->arch.root_mmu, > >> > + KVM_MMU_ROOTS_ALL); > >> > + > >> > >> This is related to my remark on the previous patch; the comment above > >> makes me think I'm missing something obvious, enlighten me please) > >> > >> My understanding is that L1 and L2 will share arch.root_mmu not only > >> when EPT is globally disabled, we seem to switch between > >> root_mmu/guest_mmu only when nested_cpu_has_ept(vmcs12) but different L2 > >> guests may be different on this. Do we need to handle this somehow? > > > > guest_mmu is used iff nested EPT is enabled, which requires enable_ept=1. > > enable_ept is global and cannot be changed without reloading kvm_intel. > > > > This most definitely over-invalidates, e.g. it blasts away L1's page > > tables. But, fixing that requires tracking VPID in mmu_role and/or adding > > support for using guest_mmu when L1 isn't using TDP, i.e. nested EPT is > > disabled. Assuming the vast majority of nested deployments enable EPT in > > L0, the cost of both options likely outweighs the benefits. > > > > Yes but my question rather was: what if global 'enable_ept' is true but > nested EPT is not being used by L1, don't we still need to do > kvm_mmu_free_roots(&vcpu->arch.root_mmu) here? No, because L0 isn't shadowing the L1->L2 page tables, i.e. there can't be unsync'd SPTEs for L2. The vpid_sync_*() above flushes the TLB for L2's effective VPID, which is all that's required.