From patchwork Sat Feb 3 09:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 196301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1012464dyc; Sat, 3 Feb 2024 05:17:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVtG0Yv/EZyquLbX0r1MMShqbRcDeTfzoAWJ0ZyIyPqiR/lFRzbIh1I7aCR6fpceVFdZ0q X-Received: by 2002:a17:903:249:b0:1d4:e208:9b0 with SMTP id j9-20020a170903024900b001d4e20809b0mr10078091plh.44.1706966273409; Sat, 03 Feb 2024 05:17:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706966273; cv=pass; d=google.com; s=arc-20160816; b=lbvT2CImUtv5BX6801pJ+4DH3ywFOGUVP3Hensdbx8WQD09f7Nx8/PKBW3N/uxqUJi 7lsIRGUyapQbJkcjtPgLkhX913erZ2BdAjPBGab7hMr78cuQOPE7xvW8daiqPfUYoABX /vlLs6QCn6vB9J1SZ85Ea/fLWPj8XSE4TRUOBRDoNhv83hq+cF8t48wEyE7brQV9bwR1 vDil26o9zjGPcqHpYuDTirQgPlApQ4ErKze3cbq7VokNJ15hLVH0qEddOnpHq4ojPYpp AvOxsEIXIXbLcVDoRvvQtTf8VFGpkL8rY6wyO00Mo+LI1TNfSSRKxhnPO45nQaY2a2Do iYjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cNk31bRpWlZoflVQHfM4m2vYm3DmzE7yWp+YekN1lAo=; fh=3BkW3Tpe9NMe0+vjUHvflUp4t6OQVnh0LGRqAjf9qHo=; b=v5c4NscmAxpVSWXDZRH2m3sotuK2i1egJkOIMvOvZ4J3iessd1UKWxIdhIPvu2S1vQ 9//6170glCjjl2fNwCFZAbPBV3rZ61PiG8GPgtKbLJ1qp/tzCzTKT3SqGC1OEYuxk2UV kV1t5e2I82T8zAoPn60nxJuhannGnw7I3cIify7hDwNEmgoJi/54KAVj4ptzQsJNIeOL sHKGEwe7pUZFSeSambLugFDpYSONDdgg1RbaFNKIPEBM3gnwqF4+5pHo1s9eHlNtpIvq NOQ8fgMHqXUfOSyukIA69Izivc2YvPU9JKRwVGFpVa2uoCCpm2o2qCvciMA2177rLPxO D04w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CkZuKTJ1; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51003-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51003-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCW0JSWL6Ga55VQNOzt5pEi4dz1ak174jbLNpztOZVo24AFhU5UCyKvrTFpliQSqqxm15gMiIlmi7cnntaXAYVYF1zxZVA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r4-20020a63d904000000b005d81bb64355si3203465pgg.892.2024.02.03.05.17.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 05:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51003-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CkZuKTJ1; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51003-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51003-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 546D4292889 for ; Sat, 3 Feb 2024 09:09:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C87606E2D2; Sat, 3 Feb 2024 09:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CkZuKTJ1" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0E9369D13; Sat, 3 Feb 2024 09:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950931; cv=none; b=Oa8fSH4IG/oZqErhRbiU078Qx+dkhOT+Mo1qRS/ZwwR3T4OYtYYZ3TYDbIJm3Ka7ucGsZmxaNsI2vZys744zeYc1JpaRwkf+AEID6iDhuq/VnnwcPqGrkT9GbN1dz+Ih/sX6oie8ozW3BGo6sfa4JZvM0sOTUFpXbWoH8TlO748= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950931; c=relaxed/simple; bh=McvWIfrMDVQQK98OonhC4shsYqFjFCcrohaIF+ih4cY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mUB5f/K/wtDBQ/W9tZ1mVaI8JVBiVhoQSxv9PXwDs6K0IsuzDS5fy8s7umVFo1CURDYuy1r9voI8P7bS87d8ept4wJJlB9UGVmJgS62l3DOturN8UWucLej8RB3hnau4v61uGnAfHB3oWM28pRK61LUJRfcF5RSMPxGDClCt7eI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CkZuKTJ1; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706950930; x=1738486930; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=McvWIfrMDVQQK98OonhC4shsYqFjFCcrohaIF+ih4cY=; b=CkZuKTJ1SXWDRkQOtDVAYmKcvQUPUsrmemyaHFXpRknte9OGcIP/e9Qr kycoguiF6c7fcsgC39hZjBF8zuYmvklm8nxuTztkLhgx7lNEnAqyDYhUA 3L+F3tkDbmZv9KwTvdJVJtCCftjAwIr86E3weiEd5nPDoVct7EUh5rDia oxFB1INPCOsk14R0bYmcrpjJ4pLQFHeVR8RrgWB5Y7DDKfjpWkAjVc3JG 8vGndeEv5N7D/FkELrHXf+mgl/NMOpmksCFeq18JPxlPs+i8lkljKLBqZ 6qw4vFpxBsm4mjQy7JsaLpU8k2rtVZuAcprQnpqkI5FU0REWjt1PxViXZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="4132259" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="4132259" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:02:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="291606" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa009.fm.intel.com with ESMTP; 03 Feb 2024 01:02:03 -0800 From: Zhao Liu To: Paolo Bonzini , Sean Christopherson , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , kvm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ricardo Neri , Len Brown , Zhang Rui , Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Vineeth Pillai , Suleiman Souhlal , Masami Hiramatsu , David Dai , Saravana Kannan , Zhao Liu Subject: [RFC 25/26] KVM: x86: Expose HRESET feature's CPUID to Guest Date: Sat, 3 Feb 2024 17:12:13 +0800 Message-Id: <20240203091214.411862-26-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203091214.411862-1-zhao1.liu@linux.intel.com> References: <20240203091214.411862-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789883867000843445 X-GMAIL-MSGID: 1789883867000843445 From: Zhuocheng Ding The HRESET feature needs to have not only the feature bit of 0x07.0x01. eax[bit 22] in the CPUID, but also the associated 0x20 leaf, so, pass- through the Host's 0x20 leaf to Guest. Since currently, HRESET is only used to clear ITD's classification history, only expose HRESET related CPUID when Guest has the ITD capability. Tested-by: Yanting Jiang Signed-off-by: Zhuocheng Ding Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- arch/x86/kvm/cpuid.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 9e78398f29dc..726b723ee34b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -197,6 +197,16 @@ static int kvm_check_hfi_cpuid(struct kvm_vcpu *vcpu, if (data_size > hfi_features.nr_table_pages << PAGE_SHIFT) return -EINVAL; + /* + * Check HRESET leaf since Guest's control of MSR_IA32_HW_HRESET_ENABLE + * needs to take effect on hardware. + */ + best = cpuid_entry2_find(entries, nent, 0x20, 0); + + /* Cannot set the Guest bit that is unsopported by Host. */ + if (best && best->ebx & ~cpuid_ebx(0x20)) + return -EINVAL; + return 0; } @@ -784,6 +794,10 @@ void kvm_set_cpu_caps(void) F(AMX_FP16) | F(AVX_IFMA) | F(LAM) ); + /* Currently HRESET is used to reset the ITD related history. */ + if (kvm_cpu_cap_has(X86_FEATURE_ITD)) + kvm_cpu_cap_set(X86_FEATURE_HRESET); + kvm_cpu_cap_init_kvm_defined(CPUID_7_1_EDX, F(AVX_VNNI_INT8) | F(AVX_NE_CONVERT) | F(PREFETCHITI) | F(AMX_COMPLEX) @@ -1030,7 +1044,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) switch (function) { case 0: /* Limited to the highest leaf implemented in KVM. */ - entry->eax = min(entry->eax, 0x1fU); + entry->eax = min(entry->eax, 0x20U); break; case 1: cpuid_entry_override(entry, CPUID_1_EDX); @@ -1300,6 +1314,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) break; } break; + /* Intel HRESET */ + case 0x20: + if (!kvm_cpu_cap_has(X86_FEATURE_HRESET)) { + entry->eax = 0; + entry->ebx = 0; + entry->ecx = 0; + entry->edx = 0; + break; + } + break; case KVM_CPUID_SIGNATURE: { const u32 *sigptr = (const u32 *)KVM_SIGNATURE; entry->eax = KVM_CPUID_FEATURES;