From patchwork Fri Nov 25 12:58:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 26002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4000789wrr; Fri, 25 Nov 2022 05:06:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5arhkk7v5OIYizJcKhzIzD2A+3zwx4q0ppf4EpItXL4sofjYJrwcOF3YGbQxBtKcep68Wi X-Received: by 2002:aa7:d816:0:b0:458:4868:814 with SMTP id v22-20020aa7d816000000b0045848680814mr35249043edq.190.1669381579581; Fri, 25 Nov 2022 05:06:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381579; cv=none; d=google.com; s=arc-20160816; b=gO0kOasfA/ffDxBjPVYTfLt3+wPJq3QajSxgAO44eIGrDuls2MuOkDFu510XsEGiR/ TxRL9oW9++c3EA5V0LgOD9bceo2RNLekSgoy7tA7E5Rh1W8x58aiNvOib/u8Db/hFJRm vbu5g2dOB6SjV2Wj3B+w0zD0fxoMMxWWBSmIG6rtUW/p5jFG62ESJaOBL6U456UEg9Ux 5D+bG8yeqLEVSiRiZLHR4lRZi4nsMOx4t9/shQtSqjJMu29fk6xxOQLlU2NRRg+1R6dY rpG1SJCrSnpiIhIoBCnxcmOh2FJwNpWcrsMmVTMJT2nrQeTtxTCZPvtwYMkbk4vIrc9q X5zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Yl10Hzc3YsRO8Qx5IgVpvVvfIVu4zTlTA4C5AF4rqMQ=; b=Jh7J9e9tdayIXiGSBC6FgzxBfQCRIBeckWtP3kdRdC0DeVpZl3pgeZhyg2W9Mu7ROB bVa2v7h33ZJkTRyT35/UO7mNwh9t7U4w3g4onfE4AHYfelCbtAZ8pQktBERFUvDGFOhl gNdSS3a1sEKRt3ukXeqN0fefUykVIAO7pT1BqKHQwHpygktj5XE6TaEJ5M2dKss7yz2T AfosDyHJpphYd4Cl64QGefot5Vb109GYBdGaLvgw2zBw07K0xecrx/ZpJUkR59IyXOCc 3MHB87BWEfpdgWO7v35wOSxBQ27CULvZEauQkykeoDnvxJtnsczIg8bUYjev3SBNqG5Q dgKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ia0Bh5Ou; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du15-20020a17090772cf00b0078db5170767si3289482ejc.18.2022.11.25.05.05.53; Fri, 25 Nov 2022 05:06:19 -0800 (PST) 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=Ia0Bh5Ou; 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 S230132AbiKYNAB (ORCPT + 99 others); Fri, 25 Nov 2022 08:00:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbiKYM71 (ORCPT ); Fri, 25 Nov 2022 07:59:27 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F8B84EC15; Fri, 25 Nov 2022 04:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381158; x=1700917158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uot9L1uQxBV1A/wpS9xDkw6yGvTv6P2vf7vUoxfOr6M=; b=Ia0Bh5OuRFJclAPGDlthxk+k8QHmP/VxomhrJl2PhG2iSRFMGMbT+TIV hy0spLzlJoH1suS7ifjTz5moT5AjSo5JFXO5LJhXCT4Qpus8j3RTWbr/S 80HQCxIfEd+MHY7J7NSISvRTN1Cn7PIVORi6djnQaMQWaHKZx+o8g3X22 AxUyV1hDEV91KV3lDskY911APW8lY34/rVtNQ5bYWuWN0E9NrmaIj1k05 hFt2dVpnC0qzRg4Cn+WLUWkr2A9zZQsIf3VZi2n0diHqmkI9Re8CZtoq8 xH+PgowqSrCgWCUJfqCZabl2vBcdowbzEGYlEFfH3y0amyEy3y4dwfPcs g==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="376622372" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="376622372" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:59:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061350" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061350" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:59:13 -0800 From: Jiaxi Chen To: kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, ndesaulniers@google.com, alexandre.belloni@bootlin.com, peterz@infradead.org, jpoimboe@kernel.org, chang.seok.bae@intel.com, pawan.kumar.gupta@linux.intel.com, babu.moger@amd.com, jmattson@google.com, sandipan.das@amd.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, fenghua.yu@intel.com, keescook@chromium.org, nathan@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 8/8] KVM: x86: Advertise PREFETCHIT0/1 CPUID to user space Date: Fri, 25 Nov 2022 20:58:45 +0800 Message-Id: <20221125125845.1182922-9-jiaxi.chen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221125125845.1182922-1-jiaxi.chen@linux.intel.com> References: <20221125125845.1182922-1-jiaxi.chen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750473459181740598?= X-GMAIL-MSGID: =?utf-8?q?1750473459181740598?= Latest Intel platform Granite Rapids has introduced a new instruction - PREFETCHIT0/1, which moves code to memory (cache) closer to the processor depending on specific hints. The bit definition: CPUID.(EAX=7,ECX=1):EDX[bit 14] PREFETCHIT0/1 is on a KVM-only subleaf. Plus an x86_FEATURE definition for this feature bit to direct it to the KVM entry. Advertise PREFETCHIT0/1 to KVM userspace. This is safe because there are no new VMX controls or additional host enabling required for guests to use this feature. Signed-off-by: Jiaxi Chen --- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/reverse_cpuid.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index c4ea8f593b72..f60e9fa1b777 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -668,7 +668,7 @@ void kvm_set_cpu_caps(void) ); kvm_cpu_cap_init_kvm_defined(CPUID_7_1_EDX, - F(AVX_VNNI_INT8) | F(AVX_NE_CONVERT) + F(AVX_VNNI_INT8) | F(AVX_NE_CONVERT) | F(PREFETCHITI) ); kvm_cpu_cap_mask(CPUID_D_1_EAX, diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 43eff7207e01..203fdad07bae 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -40,6 +40,7 @@ enum kvm_only_cpuid_leafs { /* Intel-defined sub-features, CPUID level 0x00000007:1 (EDX) */ #define X86_FEATURE_AVX_VNNI_INT8 KVM_X86_FEATURE(CPUID_7_1_EDX, 4) #define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5) +#define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) struct cpuid_reg { u32 function;