Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1451110rdb; Sat, 3 Feb 2024 06:52:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvrW2OV7Qn1M0H8AQfs2dR8/+ba3AcsCYwS3lXOejvYQbI38+Vhpru2i9+EMs8heSi7iut X-Received: by 2002:a05:6358:6a41:b0:176:2bb2:12bb with SMTP id c1-20020a0563586a4100b001762bb212bbmr9611302rwh.1.1706971974653; Sat, 03 Feb 2024 06:52:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706971974; cv=pass; d=google.com; s=arc-20160816; b=I6eaqKpVX5doLs8hlNnrm7e0Gwyzpwr9/Mzv8DYY7Gdvtfnojuf6HJ5wBsq1x6v0Qw Avrn4bCW/58ca60nosW1GNwpbM4MA3rLWqM8VvkEP5lGhMBACy4l/fjQgXiTVljI2i2w vgSyo2h7XmRZkcJUy0mNfnq6TciabOyJ4M+b8nXJB0gz6QB7Qz+Qdd4JlFJqI4sFoArK J+k9J1pFkhFzvDHI1DS9lys7uhWGG3rorxOPJqGEJ/N+pYZOILdG0JixfCtxBd0YP4f2 9iZcthXIPo5lCOTanxuWPlZa0ZMthK+Tdt/DnrNAmObXNMogTd0YT192qrx9BcESa5fq fhMA== 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=hPoFPs/ZweaGkhrvmmBW3+qTHtC13YUt3irn+u6gkI4=; fh=EZq3crp7cBQvhvfFxeLKM+Zq5ELQ8KStUngVpGAP0kI=; b=F5yzuagJ2IWlKGt9NelOhibDVtkcwCB/fUqwOB+DVeGqUT6C99kdOQLEhyjYfYO4YZ c5A6rhJuLg6EjBc6HxFfqT5DN7uiIOC8Ez/X6yETQvTxWM5AqMxQ/CEx4fZT3VFbVXAX hnlkai6H840kX26YeSFQObA3XhDTu3d0pAzX7Ubmg91Pwe1rrPdzlYYd9e+vnXP3bLrn V+eoF1s/qXA/Hxc20jZSMrbM5+i91CuISu+BqEqF4Yqdz3GQ4y5KI907SM/7f2++ehuK NsiKZxAJlJH6Uc6PGjx0Uvody2qmymRZmV2BWKGLue/tQENE0Y+JeOmycMmFlNr/+Ye2 8TSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="YKfFuU/Y"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWjqpP28dEMEqIdKVkV9f0lPbvxYAlwreumxzJZBQ//WehN5QLJabN7DscQ4EhtaWByZILmP/5YaQZUCY5pUtwYGo1PGZR5iugD6xpkOQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x11-20020a056a00188b00b006e0268c54e7si1402242pfh.206.2024.02.03.06.52.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 06:52:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="YKfFuU/Y"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-50999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50999-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C4855B2BE0A for ; Sat, 3 Feb 2024 09:07:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F6F26350D; Sat, 3 Feb 2024 09:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YKfFuU/Y" 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 1F5B6634F9; Sat, 3 Feb 2024 09:01:47 +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=1706950909; cv=none; b=pX1r2pyfdeG28eFYOEuJpLPD+lFfEqrUZfHd96RFqy0+Zud2M0Jp/3+szyo5y0M/Iz+ghLxGnzD6Rb33pht1jxF99eL/8uhtYOma7ESilaGuzE+awt5iMrV93+avUisBUWd17jfuwdGUKwskHV1FZGJEj1XpzFAmJrJI/20wKC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706950909; c=relaxed/simple; bh=lSCiO+p9r/GjQUjj3pkuJGjUOV3DAnIfLLhwnD/+1iI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FngUg57vi5NDHpjD/iGFPTxBKzfeLTuWGgAT1EmrT62n2DU26yxVmri93E0LVu7FJj7LjafVruvIfsqx2CJxUIIABHbHgbXWnKVPhQaATY7ri95HlHVKAoJNKfR9oemd/fTOn+ahutUciggZLnbCUj6PvWwfcDN2O/vcMARhMjs= 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=YKfFuU/Y; 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=1706950907; x=1738486907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lSCiO+p9r/GjQUjj3pkuJGjUOV3DAnIfLLhwnD/+1iI=; b=YKfFuU/Y0cuYxO2Kynb5wtEjNQ1Q+xXcv4+rnrk4lPgwKCQNrDd111Fr Jx275Ga900i/5mI4HbWfSD+zy9b86Jl0Em9x4nv7vIyoQIcIsYkOaXReS yGty4VwwMEvIRargPa+GDAaJiK/ixA8wFmXN2HPn2kaUFEIQi9TCjc5WD iP6KhNPC3rbP6kmEwK++plqlBOWY5tSSLfrbF1djIIwG6bETRf9X22Wp5 6lyaBdsrTONFmB9Fw7S7WQRbYhqqO9jgu/KbFHJ+Js/a5cZWe1AYKNBEN whS7nZ/gB7maItztlk/P6qfVd2jDBHTNN55aBLtt9ZnqeKjtMnCYSb29b A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="4132136" X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="4132136" 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:01:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,240,1701158400"; d="scan'208";a="291543" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa009.fm.intel.com with ESMTP; 03 Feb 2024 01:01:40 -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 21/26] KVM: VMX: Extend HFI table and MSR emulation to support ITD Date: Sat, 3 Feb 2024 17:12:09 +0800 Message-Id: <20240203091214.411862-22-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 Content-Transfer-Encoding: 8bit From: Zhao Liu ITD (Intel Thread Director) is the extension of HFI feature. Based on HFI, it adds 4 classes in HFI table and it provides the MSR interface to support the OS to classify the currently running task into one of 4 classes. As the first step of ITD support, extend the HFI table and related HFI MSRs' emulation to support the ITD: * More classes in HFI table If ITD is configured in Guest's CPUID, the virtual HFI table will be built with 4 classes. But only when ITD is enabled in MSR_IA32_HW_FEEDBACK_CONFIG, the virtual HFI table will update all these 4 classes, otherwise it will only update class 0's data if HFI is enabled. * MSR_IA32_HW_FEEDBACK_CONFIG (HW_FEEDBACK_CONFIG_ITD_ENABLE bit) With ITD support, MSR_IA32_HW_FEEDBACK_CONFIG has 2 feature enabling bits: HW_FEEDBACK_CONFIG_HFI_ENABLE and HW_FEEDBACK_CONFIG_ITD_ENABLE bit. These 2 bits control whether the HFI and ITD features are enabled or not, and also affect which class data should actually be updated in the virtual HFI table [1]. For the MSR_IA32_HW_FEEDBACK_CONFIG's emulation, add support for dynamically changing these two bits and the corresponding HFI update adjustments. [1]: SDM, vol. 3B, section 15.6.5 Hardware Feedback Interface Configuration, Table 15-10. IA32_HW_FEEDBACK_CONFIG Control Option Tested-by: Yanting Jiang Co-developed-by: Zhuocheng Ding Signed-off-by: Zhuocheng Ding Signed-off-by: Zhao Liu --- arch/x86/kvm/vmx/vmx.c | 68 +++++++++++++++++++++++++++++++----------- arch/x86/kvm/vmx/vmx.h | 3 ++ 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 636f2bd68546..bdff1d424b2f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1547,11 +1547,11 @@ static int vmx_init_hfi_table(struct kvm *kvm) struct hfi_table *hfi_table = &kvm_vmx_hfi->hfi_table; int nr_classes, ret = 0; - /* - * Currently we haven't supported ITD. HFI is the default feature - * with 1 class. - */ - nr_classes = 1; + if (guest_cpuid_has(kvm_get_vcpu(kvm, 0), X86_FEATURE_ITD)) + nr_classes = 4; + else + nr_classes = 1; + ret = intel_hfi_build_virt_features(hfi_features, nr_classes, kvm->created_vcpus); @@ -1579,11 +1579,11 @@ static int vmx_build_hfi_table(struct kvm *kvm) struct kvm_vcpu *v; unsigned long i; - /* - * Currently we haven't supported ITD. HFI is the default feature - * with 1 class. - */ - nr_classes = 1; + if (kvm_vmx_hfi->itd_enabled) + nr_classes = kvm_vmx_hfi->hfi_features.nr_classes; + else + nr_classes = 1; + for (int j = 0; j < nr_classes; j++) { hfi_hdr->perf_updated = 0; hfi_hdr->ee_updated = 0; @@ -2575,7 +2575,7 @@ static int vmx_set_hfi_cfg_msr(struct kvm_vcpu *vcpu, struct kvm_vmx *kvm_vmx = to_kvm_vmx(vcpu->kvm); struct hfi_desc *kvm_vmx_hfi = &kvm_vmx->pkg_therm.hfi_desc; u64 data = msr_info->data; - bool hfi_enabled, hfi_changed; + bool hfi_enabled, hfi_changed, itd_enabled, itd_changed; /* * When the HFI enable bit changes (either from 0 to 1 or 1 to @@ -2584,12 +2584,44 @@ static int vmx_set_hfi_cfg_msr(struct kvm_vcpu *vcpu, */ hfi_enabled = data & HW_FEEDBACK_CONFIG_HFI_ENABLE; hfi_changed = kvm_vmx_hfi->hfi_enabled != hfi_enabled; + itd_enabled = data & HW_FEEDBACK_CONFIG_ITD_ENABLE; + itd_changed = kvm_vmx_hfi->itd_enabled != itd_enabled; kvm_vmx->pkg_therm.msr_ia32_hfi_cfg = data; kvm_vmx_hfi->hfi_enabled = hfi_enabled; + kvm_vmx_hfi->itd_enabled = itd_enabled; + + if (!hfi_changed && !itd_changed) + return 0; + + /* + * Refer to SDM, vol. 3B, Table 15-10. IA32_HW_FEEDBACK_CONFIG + * Control Option. + */ + + /* Invalid option; quietly ignored by the hardware. */ + if (!hfi_changed && itd_changed && !hfi_enabled && itd_enabled) { + /* No action (no update in the table). */ + return 0; + } - if (!hfi_changed) + /* No action; keep HFI and Intel Thread Director disabled. */ + if (!hfi_changed && itd_changed && !hfi_enabled && !itd_enabled) { + /* No action (no update in the table). */ return 0; + } + + /* No action; keep HFI enabled. */ + if (!hfi_changed && itd_changed && hfi_enabled && !itd_enabled) { + /* No action (no update in the table). */ + return 0; + } + + /* Disable HFI and Intel Thread Director whether ITD changed. */ + if (hfi_changed && !hfi_enabled && itd_enabled) { + kvm_vmx_hfi->hfi_enabled = false; + kvm_vmx_hfi->itd_enabled = false; + } if (!hfi_enabled) { /* @@ -3006,12 +3038,14 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (!msr_info->host_initiated && !guest_cpuid_has(vcpu, X86_FEATURE_HFI)) return 1; - /* - * Unsupported and reserved bits. ITD is not supported - * (CPUID.06H:EAX[19]) yet. - */ + /* Unsupported bit: generate the exception. */ + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_ITD) && + (data & HW_FEEDBACK_CONFIG_ITD_ENABLE)) + return 1; + /* Reserved bits: generate the exception. */ if (!msr_info->host_initiated && - data & ~(HW_FEEDBACK_CONFIG_HFI_ENABLE)) + data & ~(HW_FEEDBACK_CONFIG_HFI_ENABLE | HW_FEEDBACK_CONFIG_ITD_ENABLE)) return 1; mutex_lock(&kvm_vmx->pkg_therm.pkg_therm_lock); diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index d9db8bf3726f..0ef767d63def 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -377,6 +377,8 @@ struct vcpu_vmx { * struct hfi_desc - Representation of an HFI instance (i.e., a table) * @hfi_enabled: Flag to indicate whether HFI is enabled at runtime. * Parsed from the Guest's MSR_IA32_HW_FEEDBACK_CONFIG. + * @itd_enabled: Flag to indicate whether ITD is enabled at runtime. + * Parsed from the Guest's MSR_IA32_HW_FEEDBACK_CONFIG. * @hfi_int_enabled: Flag to indicate whether HFI is enabled at runtime. * Parsed from Guest's MSR_IA32_PACKAGE_THERM_INTERRUPT[bit 25]. * @table_ptr_valid: Flag to indicate whether the memory of Guest HFI table is ready. @@ -407,6 +409,7 @@ struct vcpu_vmx { struct hfi_desc { bool hfi_enabled; + bool itd_enabled; bool hfi_int_enabled; bool table_ptr_valid; bool hfi_update_status; -- 2.34.1