From patchwork Sat Feb 3 09:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544007 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 ADA685CDC9 for ; Sat, 3 Feb 2024 09:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951851; cv=none; b=NtbOEhEa9xWZVOJkL1+A6nzqYQHG7kgbWTpTothAq8ikgyl66KO9LHZcO1GbK9ZD/hmqwOKz/8tFzsYNTpcgkJQg2RvnHKTHi3NaUbadBVH4q7QtPsdbyof9MmXd+U/oTZ+XP9VwQDdH4lEVxyNhTU9BLGvA9i1bUDsAzCFYDY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951851; c=relaxed/simple; bh=An89nTsf2RBLksmwt0+NzzeKNYWSam6kADPQj32WHLQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DfLBRjdQw1MMOcXL3M6BQERo0mKmaqi7DmElCF88s/lnVQb6Z2AHYkGRmqO7JHfXOpIWMuQRQj0nYKmjJ/U3PArR6ZNO8hPsvZo8dKxrqTIjxPwo++8JVQW28Zr8ztjjQuixareOKLyxGMXuunxBDEDan0EBp4+SEutsmsS5G6M= 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=OxUcNdp3; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OxUcNdp3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951850; x=1738487850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=An89nTsf2RBLksmwt0+NzzeKNYWSam6kADPQj32WHLQ=; b=OxUcNdp33b6ni75sJ1QCcKJvGZsyNWMGqJs1+m9+OkjsECczXSzMa9sC bL9iilXmAh66YlewZA+izPy4dXpwtLkn9fbC6mE5Ly9OyW08ardj2RfFj NuAywQiZRwLqfmuz5TsGyOSrDsNpPd8UUcMBh5URzD3zzy7kxArtkfvzV gYo9zQzI2J/+mhPVj4WAAGj9gl/R3/muK9rTjGNmQYYI57OZEztaKwhrG gHZGFmPNBBqC5IEVV5C9z/lQMG/2bAf2DjnwYOACs30HORUTexioGDdy5 VCp/dtsadXQFRyTVPoV5/uwX21B4dg8lXOagalnai3b+Jr2941vKW5O06 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216354" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216354" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31378978" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:26 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 1/6] target/i386: Add support for save/load of ACPI thermal MSRs Date: Sat, 3 Feb 2024 17:30:49 +0800 Message-Id: <20240203093054.412135-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhuocheng Ding The CPUID_ACPI (CPUID.0x01.edx[bit 22]) feature bit has been introduced as the TCG feature. Currently, based on KVM's ACPI emulation, add related ACPI support in QEMU. From SDM [1], ACPI feature means: "The ACPI flag (bit 22) of the CPUID feature flags indicates the presence of the IA32_THERM_STATUS, IA32_THERM_INTERRUPT, IA32_CLOCK_MODULATION MSRs, and the xAPIC thermal LVT entry." With the emulation of ACPI in KVM, add the support for save/load of ACPI thermal MSRs: MSR_IA32_THERM_CONTROL, MSR_IA32_THERM_INTERRUPT and MSR_IA32_THERM_STATUS. [1]: SDM, vol. 3B, section 15.8.4.1, Detection of Software Controlled Clock Modulation Extension. Tested-by: Yanting Jiang Signed-off-by: Zhuocheng Ding Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- target/i386/cpu.h | 9 +++++++++ target/i386/kvm/kvm.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7f0786e8b98f..e453b3f010e2 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -526,6 +526,10 @@ typedef enum X86Seg { #define MSR_IA32_XSS 0x00000da0 #define MSR_IA32_UMWAIT_CONTROL 0xe1 +#define MSR_IA32_THERM_CONTROL 0x0000019a +#define MSR_IA32_THERM_INTERRUPT 0x0000019b +#define MSR_IA32_THERM_STATUS 0x0000019c + #define MSR_IA32_VMX_BASIC 0x00000480 #define MSR_IA32_VMX_PINBASED_CTLS 0x00000481 #define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482 @@ -1758,6 +1762,11 @@ typedef struct CPUArchState { uint64_t msr_lbr_depth; LBREntry lbr_records[ARCH_LBR_NR_ENTRIES]; + /* Per-VCPU thermal MSRs */ + uint64_t therm_control; + uint64_t therm_interrupt; + uint64_t therm_status; + /* exception/interrupt handling */ int error_code; int exception_is_int; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 76a66246eb72..3bf57b35bfcd 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -138,6 +138,7 @@ static bool has_msr_ucode_rev; static bool has_msr_vmx_procbased_ctls2; static bool has_msr_perf_capabs; static bool has_msr_pkrs; +static bool has_msr_therm; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -2455,6 +2456,11 @@ static int kvm_get_supported_msrs(KVMState *s) case MSR_IA32_PKRS: has_msr_pkrs = true; break; + case MSR_IA32_THERM_CONTROL: + case MSR_IA32_THERM_INTERRUPT: + case MSR_IA32_THERM_STATUS: + has_msr_therm = true; + break; } } } @@ -3302,6 +3308,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level) if (has_msr_virt_ssbd) { kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, env->virt_ssbd); } + if (has_msr_therm) { + kvm_msr_entry_add(cpu, MSR_IA32_THERM_CONTROL, env->therm_control); + kvm_msr_entry_add(cpu, MSR_IA32_THERM_INTERRUPT, env->therm_interrupt); + kvm_msr_entry_add(cpu, MSR_IA32_THERM_STATUS, env->therm_status); + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -3774,6 +3785,11 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_TSC, 0); env->tsc_valid = !runstate_is_running(); } + if (has_msr_therm) { + kvm_msr_entry_add(cpu, MSR_IA32_THERM_CONTROL, 0); + kvm_msr_entry_add(cpu, MSR_IA32_THERM_INTERRUPT, 0); + kvm_msr_entry_add(cpu, MSR_IA32_THERM_STATUS, 0); + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -4255,6 +4271,15 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_ARCH_LBR_INFO_0 ... MSR_ARCH_LBR_INFO_0 + 31: env->lbr_records[index - MSR_ARCH_LBR_INFO_0].info = msrs[i].data; break; + case MSR_IA32_THERM_CONTROL: + env->therm_control = msrs[i].data; + break; + case MSR_IA32_THERM_INTERRUPT: + env->therm_interrupt = msrs[i].data; + break; + case MSR_IA32_THERM_STATUS: + env->therm_status = msrs[i].data; + break; } } From patchwork Sat Feb 3 09:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544008 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 A3A885D49F for ; Sat, 3 Feb 2024 09:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951853; cv=none; b=ONIENCiSXv5SZIesY9I3+DdT4/EIrlpE7De2rbFeDxb7VsMJAd3T4r0Sx+hwI4kE3mA5OT/WoPF5131saycr7BDPaPEJVW2ylQJYMxp3tR79+eMGdN2sLtVUIPKfuZTXLS9U0LBumyNhxDYVUjyAwwj6k41XkZxL6LkWQVIFKo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951853; c=relaxed/simple; bh=z/gHOWUxcMMP/K6p2By1JSy8BtlD3n84UcB8hXvdztQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lR7+jDHlN5nRW66s2Hm8q0+Wmb/tqEAl2wm32DBmSy6JkX6scFRZuqu+fIjckZBJW2ryy73z/zftiMEEiQKgtfH2/nu1Riat9GBEN8aQdUGaPDgatkOUVYdlUNRekx6Fyk8ErGvCWL0mT1W+5uGSa0SPQqAF0GEvzbsTUCIjsTE= 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=OfM2d54A; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OfM2d54A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951852; x=1738487852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z/gHOWUxcMMP/K6p2By1JSy8BtlD3n84UcB8hXvdztQ=; b=OfM2d54AP8Miq5+x1ROFk7HX+pK8xuYtgfMMOBPALWBi5+lTXJVvJjPr LTFaPInt7GMQDOmhYNaCiHiyeDQYYJKEDvMJ49oxBZIj/2B9gGb8eeGV9 uR9QHD+607SaRfOiYJhmWXzbG0TJPCAmUeNLLy1F9Wt/0WvicU0Rya9Xc V4XM75KUXH1Q4eEgV5gUAdKzGQk08Btr12C/EU3kBB08soaG7kA5AYJGC TnjW/Y7b7v3JzUXC8FSPLYmSzIPeIV6k6q4XFoq3Ls97L8ylruvxv9LE3 I4dKrXS9W7LF6jfXPD8ZrrxH59CkUC6mY52vh5ZwzNWZAR5/coXnRHfN4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216361" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216361" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31378988" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:29 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 2/6] target/i386: Add support for Package Thermal Management feature Date: Sat, 3 Feb 2024 17:30:50 +0800 Message-Id: <20240203093054.412135-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhuocheng Ding PTS feature (Package Thermal Management) is a dependency of ITD. PTS provides 2 package level MSRs: MSR_IA32_PACKAGE_THERM_STATUS and MSR_IA32_PACKAGE_THERM_INTERRUPT. They're emulated in KVM, but currently KVM hasn't supported msr topology. Thus the emulation of these 2 package-level MSRs are only supported at the whole VM-level, and all vCPUs share these two MSRs, so that the emulation of these two MSRs does not distinguish between the different virtual-packages. In order to avoid potential contention problems caused by multiple virtual-packages, add the following restrictions to the PTS feature bit: 1. Mark PTS as no_autoenable_flags and it won't be enabled by default. 2. PTS can't be enabled for the case with multiple packages. 3. PTS can't be enabled if ITD is not set for Guest, since currently PTS is only used to help enable ITD in virtualization scenario. Additionally, add save/load support for 2 PTS related MSRs. Tested-by: Yanting Jiang Co-developed-by: Zhuocheng Ding Signed-off-by: Zhuocheng Ding Signed-off-by: Zhao Liu --- target/i386/cpu.c | 22 +++++++++++++++++++++- target/i386/cpu.h | 13 +++++++++++++ target/i386/kvm/kvm.c | 24 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 03822d9ba8ee..e772d35d9403 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1114,7 +1114,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .type = CPUID_FEATURE_WORD, .feat_names = { NULL, NULL, "arat", NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, "pts", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -1124,6 +1124,11 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { }, .cpuid = { .eax = 6, .reg = R_EAX, }, .tcg_features = TCG_6_EAX_FEATURES, + /* + * PTS shouldn't be enabled by default since it has + * requirement for cpu topology. + */ + .no_autoenable_flags = CPUID_6_EAX_PTS, }, [FEAT_XSAVE_XCR0_LO] = { .type = CPUID_FEATURE_WORD, @@ -7424,6 +7429,21 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } } + + if (env->features[FEAT_6_EAX] & CPUID_6_EAX_PTS && ms->smp.sockets > 1) { + error_setg(errp, + "PTS currently only supports 1 package, " + "please set by \"-smp ...,sockets=1\""); + return; + } + + if (env->features[FEAT_6_EAX] & CPUID_6_EAX_PTS && + !(env->features[FEAT_6_EAX] & CPUID_6_EAX_ITD)) { + error_setg(errp, + "In the absence of ITD, Guest does " + "not need PTS"); + return; + } #endif mce_init(cpu); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e453b3f010e2..a8c247b2ef89 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -530,6 +530,9 @@ typedef enum X86Seg { #define MSR_IA32_THERM_INTERRUPT 0x0000019b #define MSR_IA32_THERM_STATUS 0x0000019c +#define MSR_IA32_PACKAGE_THERM_STATUS 0x000001b1 +#define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x000001b2 + #define MSR_IA32_VMX_BASIC 0x00000480 #define MSR_IA32_VMX_PINBASED_CTLS 0x00000481 #define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482 @@ -982,6 +985,8 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, #define CPUID_XSAVE_XSAVES (1U << 3) #define CPUID_6_EAX_ARAT (1U << 2) +#define CPUID_6_EAX_PTS (1U << 6) +#define CPUID_6_EAX_ITD (1U << 23) /* CPUID[0x80000007].EDX flags: */ #define CPUID_APM_INVTSC (1U << 8) @@ -1767,6 +1772,14 @@ typedef struct CPUArchState { uint64_t therm_interrupt; uint64_t therm_status; + /* + * Although these are package level MSRs, for the PTS feature, we + * temporarily limit it to be enabled for only 1 package, so the value + * of each vCPU is same and it's enough to support the save/load. + */ + uint64_t pkg_therm_interrupt; + uint64_t pkg_therm_status; + /* exception/interrupt handling */ int error_code; int exception_is_int; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 3bf57b35bfcd..258591535fd5 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -139,6 +139,7 @@ static bool has_msr_vmx_procbased_ctls2; static bool has_msr_perf_capabs; static bool has_msr_pkrs; static bool has_msr_therm; +static bool has_msr_pkg_therm; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -2461,6 +2462,10 @@ static int kvm_get_supported_msrs(KVMState *s) case MSR_IA32_THERM_STATUS: has_msr_therm = true; break; + case MSR_IA32_PACKAGE_THERM_STATUS: + case MSR_IA32_PACKAGE_THERM_INTERRUPT: + has_msr_pkg_therm = true; + break; } } } @@ -3313,6 +3318,15 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_IA32_THERM_INTERRUPT, env->therm_interrupt); kvm_msr_entry_add(cpu, MSR_IA32_THERM_STATUS, env->therm_status); } + /* Only sync package level MSRs to KVM on the first cpu */ + if (current_cpu == first_cpu) { + if (has_msr_pkg_therm) { + kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_STATUS, + env->therm_control); + kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, + env->therm_interrupt); + } + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -3790,6 +3804,10 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_THERM_INTERRUPT, 0); kvm_msr_entry_add(cpu, MSR_IA32_THERM_STATUS, 0); } + if (has_msr_pkg_therm) { + kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_STATUS, 0); + kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 0); + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -4280,6 +4298,12 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_THERM_STATUS: env->therm_status = msrs[i].data; break; + case MSR_IA32_PACKAGE_THERM_STATUS: + env->pkg_therm_status = msrs[i].data; + break; + case MSR_IA32_PACKAGE_THERM_INTERRUPT: + env->pkg_therm_interrupt = msrs[i].data; + break; } } From patchwork Sat Feb 3 09:30:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544009 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 627EA5D72F for ; Sat, 3 Feb 2024 09:17:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951856; cv=none; b=q8I0DdPUOsujcuq2ehSPA8UASJ5M3WYGFSuyFTqc3aXN9FkTNRf/d1ZTBHPGJQYQ64QYosyXdkdLgCFHse2NRbSB/PquoQUwf3TTivBUqHtxEeVQF6iURqiDCOFlypZMH09RHxHF/F3zSfmLCCtx/15Fh36uKsOhHQGQzlEvyus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951856; c=relaxed/simple; bh=UyIppaYlMKCeYNOfMLCrY6Qljm+AMerAyC7gI0Br97s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DuNoShwEtCPVEttWWiEqmSvUxWDGjpXCXqcZWgvHvw3wjTdF3aGKl4bQU8EidUcrQov1QvuZIRuzzHTWypvjonDfwsBa0E7J7nRZ2vMgg6Q+cal69PjdZgMI2w+Fk1Fza8OxYmzmqwTliJJTdi/fQM5C1bi1OuOqKGrXvtwIqvE= 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=a61WlOfJ; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="a61WlOfJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951854; x=1738487854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UyIppaYlMKCeYNOfMLCrY6Qljm+AMerAyC7gI0Br97s=; b=a61WlOfJZWPeq/OT8VEqg8HQZXlzy/kvqL5AUivqduEW/6gWEKn5foat Bmfn2xKO4/H2tSYAqGmPS5qmOatSlzGLAhyGQVUH8B8oXYTIO5I66DkUK J0oB6Pb06rPmaqu85+bcXr8slIeKU7dbgktEtoE5+yfGOT9uccyKRAgEm AJXTUYxek1VHGQUo2H1r8EYuR5IBXnCMuqiIB2rtEbrl2wTxTIeQCYZA9 mH9byLnqSLKLH8ktr4Hm1uUfib7vAuRI3KaEY4Ran5e2mq80p3ga78gKg qQh18lWY5o+dy21drTJJ902LXo4GVesbxTcBdius77EjGkEz0Wc6RvLl/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216365" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216365" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31378997" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:31 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 3/6] target/i386: Add support for Hardware Feedback Interface feature Date: Sat, 3 Feb 2024 17:30:51 +0800 Message-Id: <20240203093054.412135-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhuocheng Ding Hardware Feedback Interface (HFI) is a basic dependency of ITD. HFI is the feature to allow hardware to provide guidance to the Operating System (OS) scheduler to perform optimal workload scheduling through a hardware feedback interface structure in memory [1]. Currently in virtualization scenario it is used to help enable ITD. HFI feature provides the basic HFI information in CPUID.0x06: * 0x06.eax[bit 19]: HFI feature bit * 0x06.ecx[bits 08-15]: Number of HFI/ITD supported classes * 0x06.edx[bits 00-07]: Bitmap of supported HFI capabilities * 0x06.edx[bits 08-11]: Enumerates the size of the HFI table in number of 4 KB pages * 0x06.edx[bits 16-31]: HFI table index of processor Here the basic information is generated by KVM based on the virtual HFI table that can be emulated, and QEMU needs to specify the HFI table index for each vCPU. HFI feature also provides 2 package level MSRs: MSR_IA32_HW_FEEDBACK_CONFIG and MSR_IA32_HW_FEEDBACK_PTR. They're emulated in KVM, but currently KVM hasn't supported msr topology. Thus, like PTS MSRs, the emulation of these 2 package-level HFI MSRs are only supported at the whole VM-level, and all vCPUs share these two MSRs, so that the emulation of these two MSRs does not distinguish between the different virtual-packages. And HFI driver maintains per die HFI instances, so this can also cause problems with access to HFI MSRs when multiple virtual-dies exist. In order to avoid potential contention problems caused by multiple virtual-packages/dies, add the following restrictions to the HFI feature bit: 1. Mark HFI as no_autoenable_flags and it won't be enabled by default. 2. HFI can't be enabled for the case with multiple packages/dies. 3. HFI can't be enabled if ITD is not set for Guest, since currently HFI is only used to help enable ITD in virtualization scenario. HFI feature depends on ACPI, TM and PTS, also add their dependencies. Additionally, add save/load support for 2 HFI related MSRs. [1]: SDM, vol. 3B, section 15.6 HARDWARE FEEDBACK INTERFACE AND INTEL THREAD DIRECTOR Tested-by: Yanting Jiang Co-developed-by: Zhuocheng Ding Signed-off-by: Zhuocheng Ding Signed-off-by: Zhao Liu --- target/i386/cpu.c | 49 ++++++++++++++++++++++++++++++++++++++----- target/i386/cpu.h | 8 ++++++- target/i386/kvm/kvm.c | 21 +++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e772d35d9403..e3eb361436c9 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1117,7 +1117,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, NULL, "pts", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, "hfi", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -1125,10 +1125,10 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .cpuid = { .eax = 6, .reg = R_EAX, }, .tcg_features = TCG_6_EAX_FEATURES, /* - * PTS shouldn't be enabled by default since it has + * PTS and HFI shouldn't be enabled by default since they have * requirement for cpu topology. */ - .no_autoenable_flags = CPUID_6_EAX_PTS, + .no_autoenable_flags = CPUID_6_EAX_PTS | CPUID_6_EAX_HFI, }, [FEAT_XSAVE_XCR0_LO] = { .type = CPUID_FEATURE_WORD, @@ -1557,6 +1557,18 @@ static FeatureDep feature_dependencies[] = { .from = { FEAT_VMX_SECONDARY_CTLS, VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE }, .to = { FEAT_7_0_ECX, CPUID_7_0_ECX_WAITPKG }, }, + { + .from = { FEAT_1_EDX, CPUID_ACPI }, + .to = { FEAT_6_EAX, CPUID_6_EAX_HFI }, + }, + { + .from = { FEAT_1_EDX, CPUID_TM }, + .to = { FEAT_6_EAX, CPUID_6_EAX_HFI }, + }, + { + .from = { FEAT_6_EAX, CPUID_6_EAX_PTS }, + .to = { FEAT_6_EAX, CPUID_6_EAX_HFI }, + }, }; typedef struct X86RegisterInfo32 { @@ -6158,6 +6170,25 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *ebx = 0; *ecx = 0; *edx = 0; + /* + * KVM only supports HFI virtualization with ITD, so + * set the HFI information only if the ITD is enabled. + */ + if (*eax & CPUID_6_EAX_ITD) { + if (kvm_enabled()) { + *ecx = kvm_arch_get_supported_cpuid(cs->kvm_state, 0x6, + count, R_ECX); + /* + * No need to adjust the number of pages since the default + * 1 4KB page is enough to hold the HFI entries of max_cpus + * (1024) supported by i386 machine (q35). + */ + *edx = kvm_arch_get_supported_cpuid(cs->kvm_state, 0x6, + count, R_EDX); + /* Set HFI table index as CPU index. */ + *edx |= cs->cpu_index << 16; + } + } break; case 7: /* Structured Extended Feature Flags Enumeration Leaf */ @@ -7437,11 +7468,19 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) return; } - if (env->features[FEAT_6_EAX] & CPUID_6_EAX_PTS && + if (env->features[FEAT_6_EAX] & CPUID_6_EAX_HFI && + (ms->smp.dies > 1 || ms->smp.sockets > 1)) { + error_setg(errp, + "HFI currently only supports die/package, " + "please set by \"-smp ...,sockets=1,dies=1\""); + return; + } + + if (env->features[FEAT_6_EAX] & (CPUID_6_EAX_PTS | CPUID_6_EAX_HFI) && !(env->features[FEAT_6_EAX] & CPUID_6_EAX_ITD)) { error_setg(errp, "In the absence of ITD, Guest does " - "not need PTS"); + "not need PTS/HFI"); return; } #endif diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a8c247b2ef89..b54a2ccd6a6e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -533,6 +533,9 @@ typedef enum X86Seg { #define MSR_IA32_PACKAGE_THERM_STATUS 0x000001b1 #define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x000001b2 +#define MSR_IA32_HW_FEEDBACK_CONFIG 0x000017d0 +#define MSR_IA32_HW_FEEDBACK_PTR 0x000017d1 + #define MSR_IA32_VMX_BASIC 0x00000480 #define MSR_IA32_VMX_PINBASED_CTLS 0x00000481 #define MSR_IA32_VMX_PROCBASED_CTLS 0x00000482 @@ -986,6 +989,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, #define CPUID_6_EAX_ARAT (1U << 2) #define CPUID_6_EAX_PTS (1U << 6) +#define CPUID_6_EAX_HFI (1U << 19) #define CPUID_6_EAX_ITD (1U << 23) /* CPUID[0x80000007].EDX flags: */ @@ -1773,12 +1777,14 @@ typedef struct CPUArchState { uint64_t therm_status; /* - * Although these are package level MSRs, for the PTS feature, we + * Although these are package level MSRs, for the PTS/HFI feature, we * temporarily limit it to be enabled for only 1 package, so the value * of each vCPU is same and it's enough to support the save/load. */ uint64_t pkg_therm_interrupt; uint64_t pkg_therm_status; + uint64_t hfi_config; + uint64_t hfi_ptr; /* exception/interrupt handling */ int error_code; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 258591535fd5..694aa20afc67 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -140,6 +140,7 @@ static bool has_msr_perf_capabs; static bool has_msr_pkrs; static bool has_msr_therm; static bool has_msr_pkg_therm; +static bool has_msr_hfi; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -2466,6 +2467,10 @@ static int kvm_get_supported_msrs(KVMState *s) case MSR_IA32_PACKAGE_THERM_INTERRUPT: has_msr_pkg_therm = true; break; + case MSR_IA32_HW_FEEDBACK_CONFIG: + case MSR_IA32_HW_FEEDBACK_PTR: + has_msr_hfi = true; + break; } } } @@ -3326,6 +3331,12 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, env->therm_interrupt); } + if (has_msr_hfi) { + kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_CONFIG, + env->hfi_config); + kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_PTR, + env->hfi_ptr); + } } #ifdef TARGET_X86_64 @@ -3808,6 +3819,10 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_STATUS, 0); kvm_msr_entry_add(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 0); } + if (has_msr_hfi) { + kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_CONFIG, 0); + kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_PTR, 0); + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -4304,6 +4319,12 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_PACKAGE_THERM_INTERRUPT: env->pkg_therm_interrupt = msrs[i].data; break; + case MSR_IA32_HW_FEEDBACK_CONFIG: + env->hfi_config = msrs[i].data; + break; + case MSR_IA32_HW_FEEDBACK_PTR: + env->hfi_ptr = msrs[i].data; + break; } } From patchwork Sat Feb 3 09:30:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544010 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 B939F5D751 for ; Sat, 3 Feb 2024 09:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951858; cv=none; b=LSqh35qjCrNAM2pzwsKB9o2tXinrrfUZaC+uinUFGmMk85rlUWl0F9EzuVjI9bq+2yLtMNDxmDUm//syVDIca/8KJdpnb53qLccrEl0R4CuDjNOeTDbP4K41sWcRXsCMFkt0Ub8V4FyHdFSwC/HSWHNeHXJAMNV7Bc7g74E1hyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951858; c=relaxed/simple; bh=Qw/YbJpx31Y4rkwPhKpfzP6ZtmWqCYJuII8bNQ2v5T0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aL++cFvZQw/s/z79ojj1FRU4Zuebhnlw93ag4JZ4J2h2mQzOeUmiw/wurJI68S2+wk1+JNIxj+ESoKUJo8R2wyja27MV22yE7n4ZkqRXz7n7gveCLKQIdZSWFOSGPpcQq2oTYX3AokcVoZMXqEcabaAV3NV0ZMBpUFY8kvAkLcQ= 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=LWkqzO0x; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LWkqzO0x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951857; x=1738487857; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qw/YbJpx31Y4rkwPhKpfzP6ZtmWqCYJuII8bNQ2v5T0=; b=LWkqzO0xrA6ivYL/QuknokXIQo/NSwdVDKBdHlC+326QrvkI22MTx0rt wR/adBB9qsv45JpoaPn98nu0WD0zzsHclv4isSTj/KnQP80W/1Y5jyUng v+NRiRzKQ7Gqdzxrq/0M9tx7Ibz2zl6kIJyDFYZXo04frqDWq9XUwDIYU rE/180WzRCrlGSwdIr6wNES3gNN6XQmJPa9Mko3W9QEX/v22Hs8LsuPEc 9hPzIYIDadc4SDqRRaLKezOUZftpGZvXoGkBxldHOhnx4BhL+1hU0LmbV MU+p66Y3wGbzXb/l3Z7eUdimJWiHVgVZRCPzcICQuUkWBWt+HPM2kt7ev w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216373" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216373" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31379008" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:34 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 4/6] target/i386: Add support for Intel Thread Director feature Date: Sat, 3 Feb 2024 17:30:52 +0800 Message-Id: <20240203093054.412135-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhao Liu Intel Thread Director (ITD) is the extension of HFI, and it extends the HFI to provide performance and energy efficiency data for advanced classes of instructions [1]. From Alder Lake, Intel's client products support ITD, and this feature can be used in VM to optimize scheduling on hybrid architectures. Like HFI, ITD virtualization also has the same topology limitations (only 1 die and 1 socket) because ITD's virtualization support is based on HFI. In order to avoid potential contention problems caused by multiple virtual-packages/dies, add the following restrictions to the ITD feature bit: 1. Mark ITD as no_autoenable_flags and it won't be enabled by default. 2. ITD can't be enabled for the case with multiple packages/dies. ITD feature depends on HFI, so also add its dependency. [1]: SDM, vol. 3B, section 15.6 HARDWARE FEEDBACK INTERFACE AND INTEL THREAD DIRECTOR Tested-by: Yanting Jiang Co-developed-by: Zhuocheng Ding Signed-off-by: Zhuocheng Ding Signed-off-by: Zhao Liu --- target/i386/cpu.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e3eb361436c9..55287d0a3e73 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1118,17 +1118,18 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "hfi", - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, "itd", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, .cpuid = { .eax = 6, .reg = R_EAX, }, .tcg_features = TCG_6_EAX_FEATURES, /* - * PTS and HFI shouldn't be enabled by default since they have + * PTS, HFI and ITD shouldn't be enabled by default since they have * requirement for cpu topology. */ - .no_autoenable_flags = CPUID_6_EAX_PTS | CPUID_6_EAX_HFI, + .no_autoenable_flags = CPUID_6_EAX_PTS | CPUID_6_EAX_HFI | + CPUID_6_EAX_ITD, }, [FEAT_XSAVE_XCR0_LO] = { .type = CPUID_FEATURE_WORD, @@ -1569,6 +1570,10 @@ static FeatureDep feature_dependencies[] = { .from = { FEAT_6_EAX, CPUID_6_EAX_PTS }, .to = { FEAT_6_EAX, CPUID_6_EAX_HFI }, }, + { + .from = { FEAT_6_EAX, CPUID_6_EAX_HFI }, + .to = { FEAT_6_EAX, CPUID_6_EAX_ITD }, + }, }; typedef struct X86RegisterInfo32 { @@ -7468,10 +7473,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) return; } - if (env->features[FEAT_6_EAX] & CPUID_6_EAX_HFI && + if (env->features[FEAT_6_EAX] & (CPUID_6_EAX_HFI | CPUID_6_EAX_ITD) && (ms->smp.dies > 1 || ms->smp.sockets > 1)) { error_setg(errp, - "HFI currently only supports die/package, " + "HFI/ITD currently only supports die/package, " "please set by \"-smp ...,sockets=1,dies=1\""); return; } From patchwork Sat Feb 3 09:30:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544011 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 25E545C90B for ; Sat, 3 Feb 2024 09:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951867; cv=none; b=DOHNCytF3kh44zOcn+snOTiaCXaerEvBs5ckenkYl7tSMg2eKglU/Ozun1UqMGV6/uKRnkvESIErJvT/svJqZrQ0DDlBignng28WMJhqHDebMe9nZXUSvLyUNCVXt+3zqAaF1egytvI3q8CX/pjbw/keJGwbu1e9uAQaEDs/ZCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951867; c=relaxed/simple; bh=LHXTdjtZ2r3RyYP7b3t0ffj/yUzzPpSDCGrT79qcd+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SdW0TAJ/mEtytD5yWB83Q9bQtUKsb3V8ZN4OAr5qij3cS9VjdzICTKaYpXq2TrbHFVK5p6VlSJf8kBQQ2u9GjPouwl/pCmDHbKC7nxNzrBv5wPmuL95OMOwz1oXvrgwqYzEyOdiXARK56LnLjhLggjYXouc8zCygS0YBDcSLG2k= 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=Cnk1Xsdv; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Cnk1Xsdv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951866; x=1738487866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LHXTdjtZ2r3RyYP7b3t0ffj/yUzzPpSDCGrT79qcd+k=; b=Cnk1XsdvTOd7JNmUj7kZgDcrGydzjetMJbk6JiSfGX27OIrsGofjXWP1 pljcG7fmrWTq3R+YU0tT8LMNfH5aMmpjCKskbmd5p4qn4GZXLFor3U+mJ geBTp9ZeJS23rk0d0GAEXd6l6s+bYMW4PzOfAFzUvB/y7bnSdJrGfqE/A RMtNwV2NKtvUAasILDAY3ua3iadvReZTr+60QIBtjn1QD/Q3TQdXNi3XW 8GHHpjodcu/efjJBRXjOUXjCX0grE5YU9ktckub5uBzxKg0/mrHc1H4uj tuAZapKXjTZCJcGuhTkpJyPcg/kGQ8zifu7hGZO5+Fs7pAxO+nM0AQ2Vv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216385" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216385" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31379019" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:36 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 5/6] target/i386: Add support for HRESET feature Date: Sat, 3 Feb 2024 17:30:53 +0800 Message-Id: <20240203093054.412135-6-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhuocheng Ding HRESET provides an HRESET instruction to reset the ITD related history accumulated on the current logical processor it is executing on [1]. HRESET feature not only needs to have the feature bit of 0x07.0x01.eax [bit 22] in the CPUID, but also the associated 0x20 leaf, thus, we also fill HRESET related info provided by KVM into Guest's 0x20 leaf. Because currently HRESET is only used to reset ITD's history and ITD has been marked as no_autoenable_flags, mark the HRESET feature bit as no_autoenable_flags, too. Additionally, add MSR_IA32_HW_HRESET_ENABLE save/load support since it's emulated in KVM. This MSR is used to control the enabling of ITD's history reset. [1]: SDM, vol. 3B, section 15.6.11 Logical Processor Scope History Tested-by: Yanting Jiang Co-developed-by: Zhuocheng Ding Signed-off-by: Zhuocheng Ding Signed-off-by: Zhao Liu --- target/i386/cpu.c | 28 +++++++++++++++++++++++++++- target/i386/cpu.h | 6 ++++++ target/i386/kvm/kvm.c | 14 ++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 55287d0a3e73..3b26b471b861 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -966,7 +966,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, NULL, "fzrm", "fsrs", "fsrc", NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, "amx-fp16", NULL, "avx-ifma", + NULL, "amx-fp16", "hreset", "avx-ifma", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, @@ -976,6 +976,11 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .reg = R_EAX, }, .tcg_features = TCG_7_1_EAX_FEATURES, + /* + * Currently HRESET is only used for ITD history reset. ITD is not + * autoenable, so also don't enable HRESET by default. + */ + .no_autoenable_flags = CPUID_7_1_EAX_HRESET, }, [FEAT_7_1_EDX] = { .type = CPUID_FEATURE_WORD, @@ -6502,6 +6507,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } break; } + case 0x20: { + /* Processor History Reset */ + if (kvm_enabled() && + env->features[FEAT_7_1_EAX] & CPUID_7_1_EAX_HRESET) { + *eax = kvm_arch_get_supported_cpuid(cs->kvm_state, 0x20, + count, R_EAX); + *ebx = kvm_arch_get_supported_cpuid(cs->kvm_state, 0x20, + count, R_EBX); + } else { + *eax = 0; + *ebx = 0; + } + *ecx = 0; + *edx = 0; + break; + } case 0x40000000: /* * CPUID code in kvm_arch_init_vcpu() ignores stuff @@ -7147,6 +7168,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SGX) { x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x12); } + + /* HRESET requires CPUID[0x20] */ + if (env->features[FEAT_7_1_EAX] & CPUID_7_1_EAX_HRESET) { + x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x20); + } } /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b54a2ccd6a6e..a68c9d8a8660 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -535,6 +535,7 @@ typedef enum X86Seg { #define MSR_IA32_HW_FEEDBACK_CONFIG 0x000017d0 #define MSR_IA32_HW_FEEDBACK_PTR 0x000017d1 +#define MSR_IA32_HW_HRESET_ENABLE 0x000017da #define MSR_IA32_VMX_BASIC 0x00000480 #define MSR_IA32_VMX_PINBASED_CTLS 0x00000481 @@ -933,6 +934,8 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, #define CPUID_7_1_EAX_FSRC (1U << 12) /* Support Tile Computational Operations on FP16 Numbers */ #define CPUID_7_1_EAX_AMX_FP16 (1U << 21) +/* HISTORY RESET */ +#define CPUID_7_1_EAX_HRESET (1U << 22) /* Support for VPMADD52[H,L]UQ */ #define CPUID_7_1_EAX_AVX_IFMA (1U << 23) @@ -1786,6 +1789,9 @@ typedef struct CPUArchState { uint64_t hfi_config; uint64_t hfi_ptr; + /* Per-VCPU HRESET MSR */ + uint64_t hreset_enable; + /* exception/interrupt handling */ int error_code; int exception_is_int; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 694aa20afc67..e490126f23ca 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -141,6 +141,7 @@ static bool has_msr_pkrs; static bool has_msr_therm; static bool has_msr_pkg_therm; static bool has_msr_hfi; +static bool has_msr_hreset; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -2471,6 +2472,9 @@ static int kvm_get_supported_msrs(KVMState *s) case MSR_IA32_HW_FEEDBACK_PTR: has_msr_hfi = true; break; + case MSR_IA32_HW_HRESET_ENABLE: + has_msr_hreset = true; + break; } } } @@ -3337,6 +3341,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_PTR, env->hfi_ptr); } + if (has_msr_hreset) { + kvm_msr_entry_add(cpu, MSR_IA32_HW_HRESET_ENABLE, + env->hreset_enable); + } } #ifdef TARGET_X86_64 @@ -3823,6 +3831,9 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_CONFIG, 0); kvm_msr_entry_add(cpu, MSR_IA32_HW_FEEDBACK_PTR, 0); } + if (has_msr_hreset) { + kvm_msr_entry_add(cpu, MSR_IA32_HW_HRESET_ENABLE, 0); + } #ifdef TARGET_X86_64 if (lm_capable_kernel) { @@ -4325,6 +4336,9 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_HW_FEEDBACK_PTR: env->hfi_ptr = msrs[i].data; break; + case MSR_IA32_HW_HRESET_ENABLE: + env->hreset_enable = msrs[i].data; + break; } } From patchwork Sat Feb 3 09:30:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13544016 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 D25AE5CDD0 for ; Sat, 3 Feb 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951869; cv=none; b=pQV0zTJ3DlRtYQw45547qN9e4hpPJ43gh0+zYI2UhU4RwRiM39ydY+sjriWqCVVk9uTSobuaF1YzlceY20uzGTDc5d4tHXs+bj9OhTSDkcm0yYMVEHcy1Az1PnqdUIi3I0xJvTfxOlTcwxnM+j1Z/ALE6EiuNGf3CikVrDBFgr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706951869; c=relaxed/simple; bh=868VAJN89eGkinOq4EOD+Tl9/QzBYeTq2J6+WiPTTIA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Th9vTYeEizqaFekaIiAduxxT7+zMD3YdcXGK/pF0L9ZAlp1YOVrZVLIAUIBt2dtXKmfw/qbPUqq4gziVNHLFd7xlT9QO5DkrtB1ZeMYcxOJ7ThqHxFDHfCZyUg8GpztaIwrOu5xWd1MbZLk6jvcGAQkKWHWGlv8JRmQDBYYbt9E= 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=ewZUn2ec; arc=none smtp.client-ip=198.175.65.20 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ewZUn2ec" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706951868; x=1738487868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=868VAJN89eGkinOq4EOD+Tl9/QzBYeTq2J6+WiPTTIA=; b=ewZUn2ecv7ST4Hmft7az1vOn0kxf/DA8ykc5+ix1ZMOW6lbPCJJ2toNJ EkSD1+xfGwEhb00cmh4MERnzme0KUQSHf0J6xAfQRArpaVv8BBno0rZcv OYFNKMSv6t28ca0wiTd6MurOZql94vUIBPgXCtRpBpHt40FvVvoEMT2z3 zxPHCWOScA0xNdQHc/abMwgTR4fBANDimWFQ1P5nXpcPDE7muR1pm9x5t +Q+UuUSfpcFWjHxdsB6XLlQImKQ9tcyBuKn0jRE5tCGEOFTF0qCowh52l 3Jv1w2KTief5KbKTnlruBpB+qMLC6Zll4kU5UYsrxOlHPmCxohPePYcEk Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="216392" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="216392" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2024 01:17:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="31379033" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa001.fm.intel.com with ESMTP; 03 Feb 2024 01:17:38 -0800 From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Zhenyu Wang , Zhuocheng Ding , Dapeng Mi , Yanting Jiang , Yongwei Ma , Zhao Liu Subject: [RFC 6/6] i386: Add a new property to set ITD related feature bits for Guest Date: Sat, 3 Feb 2024 17:30:54 +0800 Message-Id: <20240203093054.412135-7-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240203093054.412135-1-zhao1.liu@linux.intel.com> References: <20240203093054.412135-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhao Liu The property enable-itd will be used to set ITD related feature bits for Guest, which includes PTS, HFI, ITD and HRESET. Now PTS, HFI, ITD and HRESET are marked as no_autoenable_flags, since PTS, HFI and ITD have additional restrictions on CPU topology, and HRESET is only used in ITD case. If user wants to enable ITD for Guest, he need to specify PTS, HFI, ITD and HRESET explicitly in the -cpu command. Thus it's necessary to introduce "-cpu enable-itd" to help set these feature bits. Tested-by: Yanting Jiang Signed-off-by: Zhao Liu --- target/i386/cpu.c | 20 +++++++++++++++----- target/i386/cpu.h | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3b26b471b861..070f7ff43a1b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7304,6 +7304,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) */ x86_cpu_hyperv_realize(cpu); + if (cpu->enable_itd) { + env->features[FEAT_6_EAX] |= CPUID_6_EAX_PTS | CPUID_6_EAX_HFI | + CPUID_6_EAX_ITD; + env->features[FEAT_7_1_EAX] |= CPUID_7_1_EAX_HRESET; + } + x86_cpu_expand_features(cpu, &local_err); if (local_err) { goto out; @@ -7494,22 +7500,25 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) if (env->features[FEAT_6_EAX] & CPUID_6_EAX_PTS && ms->smp.sockets > 1) { error_setg(errp, - "PTS currently only supports 1 package, " - "please set by \"-smp ...,sockets=1\""); + "%s currently only supports 1 package, " + "please set by \"-smp ...,sockets=1\"", + cpu->enable_itd ? "enable-itd" : "PTS"); return; } if (env->features[FEAT_6_EAX] & (CPUID_6_EAX_HFI | CPUID_6_EAX_ITD) && (ms->smp.dies > 1 || ms->smp.sockets > 1)) { error_setg(errp, - "HFI/ITD currently only supports die/package, " - "please set by \"-smp ...,sockets=1,dies=1\""); + "%s currently only supports 1 die/package, " + "please set by \"-smp ...,sockets=1,dies=1\"", + cpu->enable_itd ? "enable-itd" : "HFI/ITD"); return; } if (env->features[FEAT_6_EAX] & (CPUID_6_EAX_PTS | CPUID_6_EAX_HFI) && !(env->features[FEAT_6_EAX] & CPUID_6_EAX_ITD)) { - error_setg(errp, + error_setg(errp, "%s", cpu->enable_itd ? + "Host doesn't support ITD" : "In the absence of ITD, Guest does " "not need PTS/HFI"); return; @@ -8003,6 +8012,7 @@ static Property x86_cpu_properties[] = { false), DEFINE_PROP_BOOL("x-intel-pt-auto-level", X86CPU, intel_pt_auto_level, true), + DEFINE_PROP_BOOL("enable-itd", X86CPU, enable_itd, false), DEFINE_PROP_END_OF_LIST() }; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a68c9d8a8660..009ec66dead0 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2071,6 +2071,9 @@ struct ArchCPU { int32_t hv_max_vps; bool xen_vapic; + + /* Set ITD and related feature bits (PTS, HFI and HRESET) for Guest. */ + bool enable_itd; }; typedef struct X86CPUModel X86CPUModel;