Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3891804ybb; Mon, 23 Mar 2020 09:35:23 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvpY7MS0X3Ah+5WF9iK71ekJUSoiBEotNE9cJLuA50BSCQ9RxbKgs1fFuc7L3es+DGqOPHG X-Received: by 2002:a9d:6354:: with SMTP id y20mr18875296otk.171.1584981323137; Mon, 23 Mar 2020 09:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584981323; cv=none; d=google.com; s=arc-20160816; b=t4d9HV5hfJJDxuD1wK82vgHIHuzRsUkdJUF+apy5W9GxPtim69OLd5orC1JRRrYMlW N4G+pv+mGXyO9riT3+MWRQNoSGTPujzLfZjxq43VyzSGUS41QltBQgOPWpMHDBDxDiCO Z822GPGb1ffg/W1Yqt9Zl3SRITsOa/pn3Fo6k7fQPBcEq3hwqzyLzpf/m4Xmy32GF50r 6s8l6DLDOYmv4oTOeLKrAeKohGujnVIgUNykKBN3FYsPxKjyd2qIDlULLdziQn+vJpgm pYDZdYo4qOSf8cKAE8smMUAqvi9NUHuEEmpRhT2IFrUd/3wV7FGBBOCUqQwervqxbOe5 8Ciw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=KCvacwiU6OTRKkamU+WDDamahYADSqAV/L9BazSCR94=; b=diJ9kh+I8xEPakVZ+VPgE/sIDoHr8f6yPN8hJvPQiFSIwLpZ9f0DAS/uk3yh2WeJp3 +k3LTGmjmn1j24ILm7Fa3MDwQrPJD7JCjz7tMpDxaAOm1cy2F172hud+fx4Cz5x0b93t 8BH0t985aIvR6ER6S34vthsW6LhWqIjOWqdMd36IjTCyEMMm6bRG36ymz2wUGKXZpWfp AqQBGRUtDycM4vMkyu/eVJ/zxIrQChblvZ9Icil7PrF0hBAp2Nhx0M4d1bBDzKYxL8IK JClKHnBLEwVwcKsqW7A73vQVlVignH2i4lfiiourf0KOtnCI59gcWNrqtvURMC9pmdU9 0jpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FyDsCBjA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si3379337otj.223.2020.03.23.09.35.09; Mon, 23 Mar 2020 09:35:23 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FyDsCBjA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727574AbgCWQdQ (ORCPT + 99 others); Mon, 23 Mar 2020 12:33:16 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:56893 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727411AbgCWQdP (ORCPT ); Mon, 23 Mar 2020 12:33:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584981193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KCvacwiU6OTRKkamU+WDDamahYADSqAV/L9BazSCR94=; b=FyDsCBjAuszSEz/Qix1nNSdnyL8pT1oGIeUj/ny9Rdbll9TDFSuTM/URQBIeIYU7x63+UP +uRuUcbVIEcLMaqW76YMJFsfykPuMxx7I4M7qHclek8LX7GBZZSvYTKC1MVAXUS+jMLWNQ k5V5YUGm/45UUpjDgSkGbCnRuDn9oDs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-qE8KsxTrMbysGhWP8DqqnQ-1; Mon, 23 Mar 2020 12:33:11 -0400 X-MC-Unique: qE8KsxTrMbysGhWP8DqqnQ-1 Received: by mail-wr1-f71.google.com with SMTP id e10so5858601wru.6 for ; Mon, 23 Mar 2020 09:33:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=KCvacwiU6OTRKkamU+WDDamahYADSqAV/L9BazSCR94=; b=Fyd/SCeR6xD1Mc+AK+9bp4UQ1Hj4nJ+3FR7aWScbOtkWSv70N9cOJkDpvTclgVfwwJ 82a8EjBvztfHiSTwcX9XrGJK/q4OKi1XJGw3akc+tIvSxlLktwIjfpqN/j4P0V4mp5Il gJGczDHW7Z+Iehx5oiYoRiK217FaXJOG+CLId77lI24kMyen07iVN4XLM11eH9MSbfW1 R9vH2+Lujzd358npDmNCI6J6E8tS0Oj34xo0AjubjqxxausIO2LEa3Wn5qYSae4+QNgO 0yVhJOV+BQRQT/3Zfllzq2KUH1tPoSzmg7u3+VkK+a0xY++JhCfyk8piN2Y3szyR94qF xq3A== X-Gm-Message-State: ANhLgQ2zoih4kwyDjb/bT54emlnHTl9jM0pK4vQOawCei1Wq76TO/FKI eue4cZihd239F7e/H5ViU4zWEOcL5rBsORAJ/9KcnXbhLrSi/yQ5VT7bE4AoBA++XCx6GCv2Jdu rmAV2KaJZVlNRIBXWnwDsJUrh X-Received: by 2002:adf:a387:: with SMTP id l7mr30790721wrb.250.1584981190739; Mon, 23 Mar 2020 09:33:10 -0700 (PDT) X-Received: by 2002:adf:a387:: with SMTP id l7mr30790696wrb.250.1584981190471; Mon, 23 Mar 2020 09:33:10 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id 61sm26456602wrn.82.2020.03.23.09.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 09:33:09 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson 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 In-Reply-To: <20200323160432.GJ28711@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> Date: Mon, 23 Mar 2020 17:33:08 +0100 Message-ID: <87lfnr820r.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- Vitaly