Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp43503rwd; Mon, 15 May 2023 19:44:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TCGOY2OreRFZlKXSyEzOw99gmMoEpJ3p7NpMEuE/qKKfQv/PhI8kPJEVLK1mXtvx1w21B X-Received: by 2002:a17:90a:db8e:b0:250:83ef:a038 with SMTP id h14-20020a17090adb8e00b0025083efa038mr34643738pjv.8.1684205065347; Mon, 15 May 2023 19:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684205065; cv=none; d=google.com; s=arc-20160816; b=KtFt5QRgGQ1XblUxx1Hsgg8R+S64d9f883RjEqztF83Pk9lNbLRmaMBjLWJO9h/vJT UPaMRBNv1fvGM56/CYqXaFimNSHGsZ6xAcDI29vpGKlHxQWCWqeqAZJnYBCbMeQK+sfH D4PWeIq1MEAdWb1lKFdZNkYd3gaX+2r4aePGSHJ0CYM2I4atzj5moYFr0dlE5oJDU0of AZ+jlwkoFxm/wSIHRaU5oFbGwpZRwL7GDdhsFIyvRY/6r+vBExB+x36F/WT2TxtvSFk4 QZ9aGcBp6NhHa6C0FCQBvv57hpAwg4CGwCxYWKpaLf0tWwsWq6lau9qGOtmtx7UfqnJD 9ngw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=0KSpG8Aqj+EfOBH9aL5anPdw7dbpixuxCCsQgexNLlI=; b=gr3n3WE0SZ8mKl5oHPhcYawWZ0eFpIlQxZWkJfCeDTxXQ30Pldj6rJnhbaH4P6/5NB 9nvrFpq/GROjIQ9RQV0GI3oF1Bm9azJp4jcC1drPI5H+E0GrjLNifHAL8KViurvHrOe8 z049fuXVwF5gWeZ4FvyT4+eDXM2TRhpeTFILUBGoVJez5EKqVAsUC8bAivfKWWoeRX8H GtZH3I+Iszg+8MUwSoNqiNs5L1j+pMkyfqh5Za6Tsc3S0hkfmcxhiFAUHoDLY4hWdivN X9wzUIAhaphwCB6bKelQ2g3UEBAyfZPyc6UFAedTO8mQUd6yntJEmF1mVbfnLkKEFdoF gVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nyA0Yhl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kx5-20020a17090b228500b0024dec84c2fcsi684135pjb.122.2023.05.15.19.44.13; Mon, 15 May 2023 19:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nyA0Yhl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbjEPCWc (ORCPT + 99 others); Mon, 15 May 2023 22:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjEPCWb (ORCPT ); Mon, 15 May 2023 22:22:31 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11DE3F2; Mon, 15 May 2023 19:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684203749; x=1715739749; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Xhub620MvUkYB5ByKu+zzBEV74A0k3faGyp2jpIPNqo=; b=nyA0Yhl4OJIhJERB3C9eHDKSGvW5u4/1gyxkPV8GWRHCJOavYtA5wAu4 Wr4dnSLKe332AYy1XApP0bj4NBptUUnlUaDM7nfwkCFkCLV63PE2X9k/d MMSQ6Hjf/m1cP5uH719+m/NR+eF9irAr6k44qMcDG3me1L0J8zA2yblz2 jo8Yj/fQTnq6XTinurc9+JL+uOYmtJkKqSel6CUpk47+tygEKUu4qqZn3 e4qoTS0czsgi9V4H6X8/GJ3o/OOl6elDNwOsqTPjy9lBpbnKOwPsdDYtm ioqcC73AYdC6gyMtXt5jik4i/Edeafpn0kyTePPFzw/bJdfHIBW3028p8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="417018389" X-IronPort-AV: E=Sophos;i="5.99,277,1677571200"; d="scan'208";a="417018389" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2023 19:22:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10711"; a="695261042" X-IronPort-AV: E=Sophos;i="5.99,277,1677571200"; d="scan'208";a="695261042" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.249.174.127]) ([10.249.174.127]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2023 19:22:25 -0700 Message-ID: <9c75663c-6363-34e7-8341-d8f719365768@intel.com> Date: Tue, 16 May 2023 10:22:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.10.1 Subject: Re: [RFC PATCH v2 02/11] KVM: x86: Advertise CPUID.7.2.EDX and RRSBA_CTRL support Content-Language: en-US To: Chao Gao Cc: kvm@vger.kernel.org, Jiaan Lu , Zhang Chen , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org References: <20230414062545.270178-1-chao.gao@intel.com> <20230414062545.270178-3-chao.gao@intel.com> From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/16/2023 10:04 AM, Chao Gao wrote: > On Mon, May 15, 2023 at 02:53:07PM +0800, Xiaoyao Li wrote: >> On 4/14/2023 2:25 PM, Chao Gao wrote: >>> From: Zhang Chen >>> >>> Add a kvm-only CPUID feature leaf for CPUID.7.2.EDX and RRSBA_CTRL >>> as the first feature in the leaf. >>> >>> RRSBA_CTRL is enumerated by CPUID.7.2.EDX[2]. If supported, RRSBA_DIS_U >>> (bit 5) and RRSBA_DIS_S (bit 6) of IA32_SPEC_CTRL MSR can be used to >>> disable RRSBA behavior for CPL3 and CPL0/1/2 respectively. >>> >>> Note that KVM does not intercept guests' IA32_SPEC_CTRL MSR accesses >>> after a non-zero is written to the MSR. Therefore, guests can already >>> toggle the two bits if the host supports RRSBA_CTRL, and no extra code >>> is needed to allow guests to toggle the two bits. >> >> This is a bug that also matters with other bits in MSR_IA32_SPEC_CTRL which >> has a dedicated enumeration CPUID bit and no support in KVM yet. > > Do you mean passing through the MSR is a bug? guest can write any hardware > supported value to the MSR if the MSR isn't intercepted. > > I guess this is intentional and a trade-off for performance (note that > context-switch may cause writes to the MSR). And see > > commit 841c2be09fe4 ("kvm: x86: replace kvm_spec_ctrl_test_value with runtime test on the host") > > it appears that this behavior is widely recognized. > >> >> I think we need to fix this bug at first. > > I have no idea how to fix the "bug" without intercepting the MSR. The > performance penalty makes me think intercepting the MSR is not a viable > solution. I thought correctness always takes higher priority over performance. >> >>> Signed-off-by: Zhang Chen >>> Signed-off-by: Chao Gao >>> Tested-by: Jiaan Lu >>> --- >>> arch/x86/kvm/cpuid.c | 22 +++++++++++++++++++--- >>> arch/x86/kvm/reverse_cpuid.h | 7 +++++++ >>> 2 files changed, 26 insertions(+), 3 deletions(-) >>> >>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >>> index 9583a110cf5f..f024c3ac2203 100644 >>> --- a/arch/x86/kvm/cpuid.c >>> +++ b/arch/x86/kvm/cpuid.c >>> @@ -685,6 +685,10 @@ void kvm_set_cpu_caps(void) >>> SF(SGX1) | SF(SGX2) | SF(SGX_EDECCSSA) >>> ); >>> + kvm_cpu_cap_init_kvm_defined(CPUID_7_2_EDX, >>> + SF(RRSBA_CTRL) >>> + ); >>> + >> >> Please move this hook up to right follow the leaf CPUID_7_1_EAX. > > sure. will do.