Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp581556pxk; Wed, 23 Sep 2020 10:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySc8C1k0STuxvPL+eSeQy/QmN2CxWYFTk3TMEyqqQ810jfuL36nQw3ofTWumkJVk7WFxbH X-Received: by 2002:a17:906:9389:: with SMTP id l9mr690552ejx.537.1600882021943; Wed, 23 Sep 2020 10:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600882021; cv=none; d=google.com; s=arc-20160816; b=nbQCtdj/uY82SXWVWg2CDMbrUTVC2FqiVsKZC92QPmKIelWja9wdLHJV3COc3vjXLx ZjeRWTr6a1/kWrbyOi09+EZkiGgYGl8sNwTKt+gERpiFUg+CcBWyZYTu9knPlSORioVN kk3UWiuYMBRqWgcCx1RYKb4/7cQUfo9TDKmEedaRuXr0GESh7h+1fLWSQW0iAcwMRhYL FG+HBTlBfFwJY5P0/kRBO211dcKUtlPuI++TJQ6qdYAtu6FX6Zm0AniOchxHpUlO0Otk dD/SRvwe8iJp8AD5uBwudNce1+N4aVkv42yj5gNdXFM5Psfq+nQlkbILnPVybwCNP3i/ FWRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Q6tnByusYeU+TVxG5Re3j+mmtEuKFnOyGqlIj3o5A10=; b=H4jkdng//dj1iWwPG5BcnAZvl9yM3AXSMitZbO+KXEkO9zbt0sWnaqtAHQlu1xcmA+ CJ+DOycCx2bTXraQOSKl4b6Yg48ndlKdCvKqwcufZqtkezOIAYo04J5bGMCGI+1PNEEh RlZGyEzNBfvE1TZH4YQMrQC5FVpYw9itOpmWQ0thrLjLqBnuL3QTF6dkq1wFL1UnM0Pl LAVA55vSkkAHcEdADpuFaDaMmiTNCWDhnCMZ63cbMwJII0LfVHBO/eMtufTGPdZj846H +gKTR+pIzlRr2eEnT6MjWOQZmGukZuXOg0jurUn+rI4QQvRx61lOvAzi0IlwQwGExjxe NR8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JZ9JbVtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id d12si533799ejj.33.2020.09.23.10.26.37; Wed, 23 Sep 2020 10:27:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JZ9JbVtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726572AbgIWRZg (ORCPT + 99 others); Wed, 23 Sep 2020 13:25:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23335 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgIWRZg (ORCPT ); Wed, 23 Sep 2020 13:25:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600881934; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q6tnByusYeU+TVxG5Re3j+mmtEuKFnOyGqlIj3o5A10=; b=JZ9JbVtDZRjJSeKGPDY6aMReoQEsV7R+nCfEhZ7WEqSJO71bQDjOJJDzqxfDrPItMwujRg FQwO5T9p5o9b0AF7Xqc30YSeaULeXdqqK+FnVFNVvYEQNQDpxUf1ZnjlQW9qWlzGnwJlDZ uh8OQbvzoo45XQxEcKWRffyfCuOCvOw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-535-bP_ovPh6N6-3QEwrC_v-Lg-1; Wed, 23 Sep 2020 13:25:32 -0400 X-MC-Unique: bP_ovPh6N6-3QEwrC_v-Lg-1 Received: by mail-wm1-f71.google.com with SMTP id s24so189684wmh.1 for ; Wed, 23 Sep 2020 10:25:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Q6tnByusYeU+TVxG5Re3j+mmtEuKFnOyGqlIj3o5A10=; b=jDfEYpfQqBHl/l/2xIBEsH9dO8i7bGO3oywO6KF9uFDvo6yahkcfqH8LsBPSGz0ezg pZxBT3MXb9A24BekYvZXbGFgvJjoWg+fZPtGt31QDelRlDl/wjheQJlOf5pqBrJ91yPd YmS++PO45Mg1MXWiDKyLXedMBH2jqvKZbj51quRfwKAYXQ0LpfOlgBaKjR6ACRbagr3w MsuyyMdo1rxAThMYqrHlnU75IYKgV3vkn7y6BzWl871cOO5k+iwiclLdYruItiruE+iC fvNVmAiUu1T+dUJJTd/bY0JhB9+63H83Rs+CrvYEdNqMmGNs27E4wNhh5++yJa8BRUGn htFA== X-Gm-Message-State: AOAM533FdXhuOIn4lt0T9hJW4v5TCKlvL0HeKf7ik57shneYjp1jEp3A nhQjtXLw1I8+4Y5VbRKEsfT6frneBw3LLN01iLEhKkJlC/RaF7uQLGPovsNgaMwD8RaeL1+Mtsk HwL2SjiSU/A8vIGLIb0Q1iHM4 X-Received: by 2002:a1c:2e08:: with SMTP id u8mr659678wmu.156.1600881930818; Wed, 23 Sep 2020 10:25:30 -0700 (PDT) X-Received: by 2002:a1c:2e08:: with SMTP id u8mr659651wmu.156.1600881930529; Wed, 23 Sep 2020 10:25:30 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:15f1:648d:7de6:bad9? ([2001:b07:6468:f312:15f1:648d:7de6:bad9]) by smtp.gmail.com with ESMTPSA id p1sm10824020wma.0.2020.09.23.10.25.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Sep 2020 10:25:29 -0700 (PDT) Subject: Re: [PATCH 2/4] KVM: VMX: Unconditionally clear CPUID.INVPCID if !CPUID.PCID To: Jim Mattson , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML References: <20200923165048.20486-1-sean.j.christopherson@intel.com> <20200923165048.20486-3-sean.j.christopherson@intel.com> From: Paolo Bonzini Message-ID: <010a907b-d838-532d-7869-7342c3aca1c8@redhat.com> Date: Wed, 23 Sep 2020 19:25:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/09/20 19:15, Jim Mattson wrote: > On Wed, Sep 23, 2020 at 9:51 AM Sean Christopherson > wrote: >> >> If PCID is not exposed to the guest, clear INVPCID in the guest's CPUID >> even if the VMCS INVPCID enable is not supported. This will allow >> consolidating the secondary execution control adjustment code without >> having to special case INVPCID. >> >> Technically, this fixes a bug where !CPUID.PCID && CPUID.INVCPID would >> result in unexpected guest behavior (#UD instead of #GP/#PF), but KVM >> doesn't support exposing INVPCID if it's not supported in the VMCS, i.e. >> such a config is broken/bogus no matter what. >> >> Signed-off-by: Sean Christopherson >> --- >> arch/x86/kvm/vmx/vmx.c | 16 +++++++++++----- >> 1 file changed, 11 insertions(+), 5 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> index cfed29329e4f..57e48c5a1e91 100644 >> --- a/arch/x86/kvm/vmx/vmx.c >> +++ b/arch/x86/kvm/vmx/vmx.c >> @@ -4149,16 +4149,22 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) >> } >> } >> >> + /* >> + * Expose INVPCID if and only if PCID is also exposed to the guest. >> + * INVPCID takes a #UD when it's disabled in the VMCS, but a #GP or #PF >> + * if CR4.PCIDE=0. Enumerating CPUID.INVPCID=1 would lead to incorrect >> + * behavior from the guest perspective (it would expect #GP or #PF). >> + */ >> + if (!guest_cpuid_has(vcpu, X86_FEATURE_PCID)) >> + guest_cpuid_clear(vcpu, X86_FEATURE_INVPCID); >> + > > I thought the general rule for userspace provided CPUID bits was that > kvm only made any adjustments necessary to prevent bad things from > happening at the host level. Proper guest semantics are entirely the > responsibility of userspace. Or did I misunderstand? > Yes, that's generally the idea. INVPCID has always been a bit special due to the secondary execution control being of the "enable" kind; this led the original author to try and disable the instruction (which is by itself something we do not always do, and sometimes cannot always do). So I agree that Sean's patch is of marginal utility by itself; however it lets him use the new macros in patch 4 and it is a good idea to separate the small functional change into its own commit. Paolo