From patchwork Fri Nov 25 12:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 25995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3994925wrr; Fri, 25 Nov 2022 04:59:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf45+u+BV04cLOeaSaQWSFqmeX6TjGMPuWb3BW5wFlWWZqLLHR3L0JA+EXajJT4NFqbbz1MR X-Received: by 2002:a17:906:4b04:b0:7b9:a75b:faf9 with SMTP id y4-20020a1709064b0400b007b9a75bfaf9mr11467254eju.473.1669381157514; Fri, 25 Nov 2022 04:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381157; cv=none; d=google.com; s=arc-20160816; b=eb5H9uFRrbmb9h9FYw5tJ8qZZjWmZAFRbrHhly91oR79gqyxMlU1OisTI9uIDvkF/s 8werSG4LvW29sX1VWQFir+fyR7WZtZaevUcU0T9bXmtVaOlwlLbPMtqeHfx1ZxMFnA6r azbcFxi+BqSuoDpaFgLi0nUiZqmLtiscSCQooZo6WSnMiG+uCh0qblSxjSJibd2BSeDD Ffr5oNCXmAHbgYw59X4IVNzH265sWYs5c1wJAdyCD8TMqHu9ph+c2q2uMHh2SakiUWIp POo1PKu+w8r7zC78NuMBZ7rAyhzI7YeVXN7XfSfobT2U53Ke6vvaUZ3gD0qgw6g5LKtZ rRdQ== 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=wlxRWvY1AHg90Gj8hMLtlbNLYi+P8ePKNwc/UDWKJIM=; b=wVz0Q3yPYmbuOWwg1lbqB7/tB7sV5eI6XeI0a0RDANsbXEMXMgAYTeTrHWLPO4zt+N 9LCQFZHl/0JTVnp5TJKrLrpUZZjIcWgxNb6djTo7rEERJtZqimsNxrNGAPWdKCaPhhVk yH/Dztz4NHjVGdo32Hu9Sw54qxljQy91JHAVpKM3HMEBE0vu72YmGR057APf8u5zuxsK Oe3uGDVjoGWwbA9j4Vwo5STjQIZsRypllkLwekn4MQptNtbqJM6VWUJ0rMpQbLY/owBa Gzlbp7S6lIjU7aHfnfBQY+e/SyIlTobfSz9/BBsuWMK+X0ZJ/cIsArbhAu5MFrLqP2/B 3DBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BkzJ2uiD; 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 b8-20020a056402350800b00459fc3fcf3csi2374392edd.102.2022.11.25.04.58.53; Fri, 25 Nov 2022 04:59:17 -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=BkzJ2uiD; 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 S229686AbiKYM6r (ORCPT + 99 others); Fri, 25 Nov 2022 07:58:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbiKYM6n (ORCPT ); Fri, 25 Nov 2022 07:58:43 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76DC227DF7; Fri, 25 Nov 2022 04:58:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381122; x=1700917122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q5uru/FJg753cngn4X04rdHO32+oaebGg6gCaJzWBcU=; b=BkzJ2uiD9EKbYtRXxHpve8wq4lfvvfe55mpiJ4gRbh1jWk8JV+MlGsbi 4vzd1SKrfvN2O7DwYnDzBS67x8oeQuqVozo/0cO2c61thQ+h1EWgDXTPP EJWwpC6TW/acPoWjRRq+F19Kiu6u41Cl6JNcLd7rFRC3yIV9pxD/qqZL7 0iM0PDsMfuprV4pe7X71BYa2ugYtEJSH/ybcHOO04mKCbbf120goxq9ca vYgNbkKlAD0vFvq1JGSDGWNGyAfbkvl3+qVJIFu4PjqnAxqFtcIUt36Oy 3PlnioqajmTo59xAgIdIYngdwgxtfWFPg1DEH4pc/oosXiQurrmI8dZIe A==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="314513176" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="314513176" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:58:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061216" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061216" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:58:37 -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 1/8] KVM: x86: Add BUILD_BUG_ON() to detect bad usage of "scattered" flags Date: Fri, 25 Nov 2022 20:58:38 +0800 Message-Id: <20221125125845.1182922-2-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=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,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?1750473016500034619?= X-GMAIL-MSGID: =?utf-8?q?1750473016500034619?= From: Sean Christopherson Add a compile-time assert in the SF() macro to detect improper usage, i.e. to detect passing in an X86_FEATURE_* flag that isn't actually scattered by the kernel. Upcoming feature flags will be 100% KVM-only and will have X86_FEATURE_* macros that point at a kvm_only_cpuid_leafs word, not a kernel-defined word. Using SF() and thus boot_cpu_has() for such feature flags would access memory beyond x86_capability[NCAPINTS] and at best incorrectly hide a feature, and at worst leak kernel state to userspace. Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 62bc7a01cecc..65b103874139 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -65,7 +65,13 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted) #define KVM_X86_FEATURE_PSFD (13*32+28) /* Predictive Store Forwarding Disable */ #define F feature_bit -#define SF(name) (boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0) + +/* Scattered Flag - For features that are scattered by cpufeatures.h. */ +#define SF(name) \ +({ \ + BUILD_BUG_ON(X86_FEATURE_##name >= MAX_CPU_FEATURES); \ + (boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0); \ +}) /* * Magic value used by KVM when querying userspace-provided CPUID entries and From patchwork Fri Nov 25 12:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 25996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3995138wrr; Fri, 25 Nov 2022 04:59:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d83s2sdxv3ehd8LjT+/WgC0ghM7YjCJXPK8MrurNc6r5hpaVeikCvYcnF/fOlpoCAAbai X-Received: by 2002:a63:ef55:0:b0:45f:efc9:5935 with SMTP id c21-20020a63ef55000000b0045fefc95935mr33811604pgk.28.1669381184722; Fri, 25 Nov 2022 04:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381184; cv=none; d=google.com; s=arc-20160816; b=a+ZGagYm4yHbjzl43ijHlKpPKfj/KPgpjF7eZSpkwYNcUSW/zmWiu/K/lnbdJnIeBx ie1aKafvpolEMEqpjoSGZO7a4rmSSuT1H/b/9+wWsjFqNqDZCxT0T8yT66FL7bO349qr k7q3xlYvVmuFgRfLvH0xanXYfmtROKzJbE9J17O2FcChbmx0yE0XyQ0qKDy3c9RdklHo u6uoqYWoawylQPLDxYjkgjUGiO/4vIBDrFY0J1s/CbYdIvEfA3NtlBZ1pRKK0dDXMxyA oLq8FoIVMHD4/hK/sNMmfv8j0J8+xxY2vboK6zqxbSwbcQoYIa3xxPD12uHjdN/kG8sb qXeA== 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=7Z4hoP7GdakKMOBc3WVFKqiTYuXZswsZS9MuWNsieLY=; b=vxugJ9I7UMnwwh8GX2FHJHVtjQm4jOvr3V9p1FoQ7tbUV6Dnz8MkpNlz7+p4YVaXXn v/dlsr1nIEbxVptx+7rlZZSKVLG++cG3IiU/WoWDD6GTTVQqczTBUT53SHXqSWUu4NYz DL+7TEsFL9H2+yCkNKMypSysK6Hw7mb4HRMgKzpFZDx1yjUxd5RryEqs9eT8DINprzUJ CqmEP/d4OSBXKLgScQ6awgDGLS++VDz0/njqLXt1GX26tAfSfZ0KBP3Qst0TFRz4aMGF M+FdoNo+txax0V6jgyrsLqBoLPnHo6sp/mWPZC4vl1gBp6WfgFOhqtGTyAhdApFo61w9 IdzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fT0Ox0Jy; 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 74-20020a63044d000000b00476a48051edsi3895497pge.476.2022.11.25.04.59.31; Fri, 25 Nov 2022 04:59:44 -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=fT0Ox0Jy; 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 S229734AbiKYM6v (ORCPT + 99 others); Fri, 25 Nov 2022 07:58:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiKYM6s (ORCPT ); Fri, 25 Nov 2022 07:58:48 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C75522870A; Fri, 25 Nov 2022 04:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381127; x=1700917127; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gVUECM94yIRd057tWclrKJlWO+Krnw3qbsLeXiY67U4=; b=fT0Ox0Jyw2gCVYCnv8Cq/WO2HrKeK2yu9P1GZXcaXGGvXyLUBa2d3uY4 8pTs7muKOCnXoSuOo8jyZBa5NGToV0PEsTJSQLxOWJI10G1p1XzFSNcjL ISzUnG72076CzBcmUkNlEPPBEQjhbP2zJC46q6W3Rycn6jHwFdi+DRkcp OVGfK14rkQUNK/OE2EXOKXhxBd29Cc4DpOMAcJhw8UQp79HiGvKQKXKGg SfIfqApcC9LfucsEX1fL/4UF7eBoVWZBLaNyciFAQ9n4nJPQ00bH9Bhno 0tVmxOUflLXMQZFb1zSNNWqBnnUse0VcwE+Q9sS8r6O8VEQu2GIf6oW/e Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="294180562" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294180562" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:58:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061243" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061243" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:58:42 -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 2/8] KVM: x86: Update KVM-only leaf handling to allow for 100% KVM-only leafs Date: Fri, 25 Nov 2022 20:58:39 +0800 Message-Id: <20221125125845.1182922-3-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_PASS, 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?1750473044944428429?= X-GMAIL-MSGID: =?utf-8?q?1750473044944428429?= From: Sean Christopherson Rename kvm_cpu_cap_init_scattered() to kvm_cpu_cap_init_kvm_defined() in anticipation of adding KVM-only CPUID leafs that aren't recognized by the kernel and thus not scattered, i.e. for leafs that are 100% KVM-defined. Adjust/add comments to kvm_only_cpuid_leafs and KVM_X86_FEATURE to document how to create new kvm_only_cpuid_leafs entries for scattered features as well as features that are entirely unknown to the kernel. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 8 ++++---- arch/x86/kvm/reverse_cpuid.h | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 65b103874139..a3adac48766b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -549,9 +549,9 @@ static __always_inline void __kvm_cpu_cap_mask(unsigned int leaf) } static __always_inline -void kvm_cpu_cap_init_scattered(enum kvm_only_cpuid_leafs leaf, u32 mask) +void kvm_cpu_cap_init_kvm_defined(enum kvm_only_cpuid_leafs leaf, u32 mask) { - /* Use kvm_cpu_cap_mask for non-scattered leafs. */ + /* Use kvm_cpu_cap_mask for leafs that aren't KVM-only. */ BUILD_BUG_ON(leaf < NCAPINTS); kvm_cpu_caps[leaf] = mask; @@ -561,7 +561,7 @@ void kvm_cpu_cap_init_scattered(enum kvm_only_cpuid_leafs leaf, u32 mask) static __always_inline void kvm_cpu_cap_mask(enum cpuid_leafs leaf, u32 mask) { - /* Use kvm_cpu_cap_init_scattered for scattered leafs. */ + /* Use kvm_cpu_cap_init_kvm_defined for KVM-only leafs. */ BUILD_BUG_ON(leaf >= NCAPINTS); kvm_cpu_caps[leaf] &= mask; @@ -670,7 +670,7 @@ void kvm_set_cpu_caps(void) F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | F(XSAVES) | f_xfd ); - kvm_cpu_cap_init_scattered(CPUID_12_EAX, + kvm_cpu_cap_init_kvm_defined(CPUID_12_EAX, SF(SGX1) | SF(SGX2) ); diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index a19d473d0184..443a6b3e66c0 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -7,9 +7,9 @@ #include /* - * Hardware-defined CPUID leafs that are scattered in the kernel, but need to - * be directly used by KVM. Note, these word values conflict with the kernel's - * "bug" caps, but KVM doesn't use those. + * Hardware-defined CPUID leafs that are either scattered by the kernel or are + * unknown to the kernel, but need to be directly used by KVM. Note, these + * word values conflict with the kernel's "bug" caps, but KVM doesn't use those. */ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, @@ -18,6 +18,18 @@ enum kvm_only_cpuid_leafs { NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, }; +/* + * Define a KVM-only feature flag. + * + * For features that are scattered by cpufeatures.h, __feature_translate() also + * needs to be updated to translate the kernel-defined feature into the + * KVM-defined feature. + * + * For features that are 100% KVM-only, i.e. not defined by cpufeatures.h, + * forego the intermediate KVM_X86_FEATURE and directly define X86_FEATURE_* so + * that X86_FEATURE_* can be used in KVM. No __feature_translate() handling is + * needed in this case. + */ #define KVM_X86_FEATURE(w, f) ((w)*32 + (f)) /* Intel-defined SGX sub-features, CPUID level 0x12 (EAX). */ From patchwork Fri Nov 25 12:58:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 25998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3995367wrr; Fri, 25 Nov 2022 05:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Koou4Gz6BoGXmXLbooamVaexL24nAM8ruPD2EelV08fwjJURcKfYej13DNY0sgW4JkVtI X-Received: by 2002:a17:902:f2c5:b0:189:3c6e:d1b5 with SMTP id h5-20020a170902f2c500b001893c6ed1b5mr14211217plc.108.1669381208521; Fri, 25 Nov 2022 05:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381208; cv=none; d=google.com; s=arc-20160816; b=lNUNZAR/SSTr8QokoPEwgn1O+EuCO1nvB6ngTZBo9dovDdHcZ9/NAXCMeGPFfKGMB6 5x+sGvt+OL63ZZc0ob/r6qwD1+mQC9ZPr1JgyVs/0fyryRqdptWLcOelrTJ4WQNZ7oTW jkhDGMI258YcSpxKeZU820RF/euNByXbpfXTaWWChkH7Ip+rYm7cAGVxwjm3kRIoecPM axSjnCRg5x/WPalVHVJh2Fs6po2/sarnloO7NdIPc4qQjVX89TS0McWs+ju24n1Apycd G1h+O414aUAyi6WuC6oc1Jkk+BlE/WfVKhf7oqPU/4Tb5t9mE1JLUkWnCn1SNRDT8ggv gujA== 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=HUBqUSaRMWxbRFSJh8/mx0/w4VuQXMdLObiCawNwass=; b=EcNHojPNgTVeE/wdp6nqMAIKehKVpBDOMH+BD9xphLo5DPqLhmNluxAXHrUmW4Bagj /CFz88Y570rdV/aIjevCcG3YXkx74M6UnMMdhQsa9N9AqI1sChLd0SFZSKaZl8Z0TWDx g9Cz0BzlXMp9uuSZrjnjOpa1Pz9GO8Y4PmnCHlq3QUvEUXHiyubs9tasFkkWim4GPYP2 nu3UOjTMuWPaqIRgJTZvi16/O+blciZEST3+PSIHwJrggHNLGUVK+Yvueti5MQG1JB6t szw2BhSZefWWDEPoE75lYP7fAZDp4XQ6S6u62gpbukKwUyGvWGHfSQ2BNk2LksUqFVfM KZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wnotmkja; 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 q13-20020a17090ad38d00b00216616c5fc4si6858469pju.166.2022.11.25.04.59.55; Fri, 25 Nov 2022 05:00:08 -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=Wnotmkja; 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 S229698AbiKYM7b (ORCPT + 99 others); Fri, 25 Nov 2022 07:59:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbiKYM7H (ORCPT ); Fri, 25 Nov 2022 07:59:07 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 812AC4B9A9; Fri, 25 Nov 2022 04:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381139; x=1700917139; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2dlacMSLYc4en8Dy6BoVcxx+ZaMBjc+9W62cGBZqkas=; b=WnotmkjajYrTZeeLL+uDHmgkQ3LwVow+FyxR36shLkWd4ql+pvOt3Na+ O+AHb49hffycnRgNoOHUHRKR3YVMxSWiziua0ALU0kIK7w+aSfjeKc0M2 kn95FiMbEwzX0lcQq9l9hPq+Bn8L0A1aZWsPSZj5ZyDeemHECP0/kItGy bI1XLUX5NtTRpjdDvUGIv1rSbOK8q9Kr3wdTh98keAJvwJR6ENzmS49of Oj8AhMga9sUiG7EvTUe67A0m6WVOlARHyOFA2HPjkxk6mzNb+zfmVNBPp 3suieWf829Zs0oD9aJaihAERIBifCGB2XavwgSG5ALK/dupi4AMZIAAeX Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="294180576" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294180576" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:58:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061253" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061253" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:58:47 -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 3/8] x86: KVM: Advertise CMPccXADD CPUID to user space Date: Fri, 25 Nov 2022 20:58:40 +0800 Message-Id: <20221125125845.1182922-4-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_PASS, 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?1750473069821657791?= X-GMAIL-MSGID: =?utf-8?q?1750473069821657791?= CMPccXADD is a new set of instructions in the latest Intel platform Sierra Forest. This new instruction set includes a semaphore operation that can compare and add the operands if condition is met, which can improve database performance. The bit definition: CPUID.(EAX=7,ECX=1):EAX[bit 7] CMPccXADD is on an expected-dense CPUID leaf and some other bits on this leaf have kernel usages. Given that, define this feature bit like X86_FEATURE_ in kernel. Considering CMPccXADD itself has no truly kernel usages and /proc/cpuinfo has too much unreadable flags, hide this one in /proc/cpuinfo. Advertise CMPCCXADD 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 Acked-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/cpuid.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index b71f4f2ecdd5..5cdd57133d90 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -308,6 +308,7 @@ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ #define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* AVX512 BFLOAT16 instructions */ +#define X86_FEATURE_CMPCCXADD (12*32+ 7) /* "" CMPccXADD instructions */ /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */ #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index a3adac48766b..f8bf4fb30b96 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -663,7 +663,7 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL_SSBD); kvm_cpu_cap_mask(CPUID_7_1_EAX, - F(AVX_VNNI) | F(AVX512_BF16) + F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) ); kvm_cpu_cap_mask(CPUID_D_1_EAX, From patchwork Fri Nov 25 12:58:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 25997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3995347wrr; Fri, 25 Nov 2022 05:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Gm0lUJmx/bvogypw1wEgxyZhN9ATZmkeG3/3c7eEKsnj0fgsGBox14LigwnHbOqu3/Nu3 X-Received: by 2002:a17:90a:de0f:b0:213:1143:9886 with SMTP id m15-20020a17090ade0f00b0021311439886mr41060503pjv.236.1669381207623; Fri, 25 Nov 2022 05:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381207; cv=none; d=google.com; s=arc-20160816; b=gNA3mcRfQ8RwgwyGHgkXikuFinrTVFdvbY76ecczkncBwbZvDNI11mR2Q8u9EeJZ5g eOLPlZX4o7kJlhBBBGDXbB8SX9dJXjOuU7+5sz4FUnOlCD5IereyNyksrmbF5yy5VF5t iBWsLPhlIaV63QpiHqY6a8pfXjKSW46NiBZ9M1MjOUPVpJYBk8N/jh9nRRSNlvqVM+lu BgZ0Z0qUwQ+DHj4FpfhJEQQbNcz6jI+9VfB2yDuOheOg9h2w4bCTMAHUIO2l3T2fBya3 J1HDUljnGyEXu1Lg4uBO2fSSCs1dhz2Bq4eB7XQUyjOUfG9SZx6gHO7OydNeGV7pRLOs l18g== 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=Ig9wK0qM6mNs0IGIrNWcaor7w/7KqlulFGC1ytcXJHE=; b=CrQP9RzTm5kr8ZVXwwu4hRodKUA7mvyVw6O1QFQQvEWMDRhYPfRR05QmqwmckuCuI1 K4I4vR6h7mKKnRdJnLn5nUc+Cr48eNzi69nfFYZvXbY55lZsk4hlvq8UcnaB5Q3ybGiJ R6jklAcXPZv77zU2LlYOs/WOjFwlKltOd1zKLqg9g4ex72v7ktaIfoBXOlZPgnAcH386 ETcuLzorRnux62sw2d51gg4GQkgh6b1vcIVfNpRdHVLoecxF08fqbmaxXq4HBk/SpffB Eg2hiJYi3EcbeaODuN0dmopuh24TaQcpKwqxGlJFQz043i5O47XDFcbUDSuEkL2RxI9L pPMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Y4Ss+10Q; 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 h15-20020a63df4f000000b0046f357face9si4163981pgj.356.2022.11.25.04.59.54; Fri, 25 Nov 2022 05:00:07 -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=Y4Ss+10Q; 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 S229947AbiKYM72 (ORCPT + 99 others); Fri, 25 Nov 2022 07:59:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbiKYM7G (ORCPT ); Fri, 25 Nov 2022 07:59:06 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7AD04E402; Fri, 25 Nov 2022 04:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381137; x=1700917137; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rDEZLqmqx1Il4mtQD+1kAxu0Wn7dw3dDQlDtYrg5pd8=; b=Y4Ss+10Q+yp/wN/2AZtxUR3vw8xNdaClikv43xfbHTc701S1+XnV2jzI a96vddc+X1rf0iAHIG92GI94GajWwze3cHtf6+Jz4C86KIEVy8wWKR197 2zvdhlpwqycrC2SUihoRwxstvDhmliRNYrLsb01iOK5wufSlVlDIl7jGA 6YBX9YWQyXpEn97jhDVh6JTJ33LbVfLwER5873+foLoOUhpDLLBI100Zf 69nYAxwxK7P7SHdDm/jY6+8P3eB3zS/dIHZNUbpQBxpjvgSjHlWSztmL7 mWfj2v+YDJkayK6A5R3gbuvPVs/hsV4bPdlDII3bqU6oslpc40QqlP3Ou w==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="341381289" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="341381289" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:58:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061267" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061267" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:58:52 -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 4/8] x86: KVM: Advertise AMX-FP16 CPUID to user space Date: Fri, 25 Nov 2022 20:58:41 +0800 Message-Id: <20221125125845.1182922-5-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=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1750473069379052406?= X-GMAIL-MSGID: =?utf-8?q?1750473069379052406?= From: "Chang S. Bae" Latest Intel platform Granite Rapids has introduced a new instruction - AMX-FP16, which performs dot-products of two FP16 tiles and accumulates the results into a packed single precision tile. AMX-FP16 adds FP16 capability and also allows a FP16 GPU trained model to run faster without loss of accuracy or added SW overhead. The bit definition: CPUID.(EAX=7,ECX=1):EAX[bit 21] AMX-FP16 is on an expected-dense CPUID leaf and some other bits on this leaf have kernel usages. Given that, define this feature bit like X86_FEATURE_ in kernel. Considering AMX-FP16 itself has no truly kernel usages and /proc/cpuinfo has too much unreadable flags, hide this one in /proc/cpuinfo. Advertise AMX-FP16 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: Chang S. Bae Signed-off-by: Jiaxi Chen Acked-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/cpuid.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 5cdd57133d90..20059dc33d24 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -309,6 +309,7 @@ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ #define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* AVX512 BFLOAT16 instructions */ #define X86_FEATURE_CMPCCXADD (12*32+ 7) /* "" CMPccXADD instructions */ +#define X86_FEATURE_AMX_FP16 (12*32+21) /* "" AMX fp16 Support */ /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */ #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index f8bf4fb30b96..0e04d1138bca 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -663,7 +663,7 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL_SSBD); kvm_cpu_cap_mask(CPUID_7_1_EAX, - F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) + F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) | F(AMX_FP16) ); kvm_cpu_cap_mask(CPUID_D_1_EAX, From patchwork Fri Nov 25 12:58:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 25999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3995421wrr; Fri, 25 Nov 2022 05:00:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf65rvNDlntAt4XoW+NjbQF47nUQi2Y3LCds5nQZ4Tn8jfZEDgjIQtd/j3nnjEZyErW7aLjs X-Received: by 2002:a62:e702:0:b0:573:38f0:c910 with SMTP id s2-20020a62e702000000b0057338f0c910mr18711221pfh.52.1669381212592; Fri, 25 Nov 2022 05:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381212; cv=none; d=google.com; s=arc-20160816; b=aPm0GIbs1c/4c6YfgGUz9a345rK0X6EzkhOWvcPNZWc0+/6mPsvEGHR9ilt0JX+dHP 0PYkTOiMOnnDHb5Bl+VxuBqvYF4TcxlSx9+5Z/ZBu/7AQ5zs5rEvHNuBeBN3QYZ82KXo FjQAvl+RSf3ACYIvI1zrICEd6btd/Hlwg5ZDeNOIzh6TbCl8/+WNSg8s68h3iqD1KaTA W9ZiAZW8k9mGp8K0NmmPdYapUcwhrNWtb8IIEMFNHCwKEd/tCD64g0XbPMBdt1LKcYYa xIW0PUDnKP5Y8B9gk0RAi0sl4D6sMlFumcFFxC8IHp0A3DgnPHqqzKReOZ8t7HLMJEud 6gfw== 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=WfJ4ndE3lLd9GccZz3ObXlaED2XpkTCXebkw3Rxp4uM=; b=eylXeYijjZT/BXMRiYbaYdO+F2zt6JF57HzQ9fCg9x3FZNppG60vVzZbWyv8qzmb3k 78ObeSMRT+oOM1ytQEXJ74tUOyipnlP5oH+K0297Pxfv2l8cP5Ij8jE9xre56XSg0Rk5 9ntIWrJcA3JY6yC59zc+csjKBL0cOK17ednQt7pDze5T6r33xIRLPYu+9PZicxy6TlhG /KT61nzcL9b0xV9/5Ey1GQ0f4wfZpY5CnaIZlq23v3F0A+WrkvXxy9Y0S+Xw52xpzsRx S5tQiqeE+hl2goaV5O6HC3osAJX7QihD/YNdXsNrONxEskXIEje53tz28oUNphsEMt5M v6tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j0RotfVV; 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 l191-20020a6388c8000000b004772afcec3asi3900269pgd.263.2022.11.25.04.59.58; Fri, 25 Nov 2022 05:00:12 -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=j0RotfVV; 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 S229731AbiKYM7m (ORCPT + 99 others); Fri, 25 Nov 2022 07:59:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiKYM7M (ORCPT ); Fri, 25 Nov 2022 07:59:12 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D599528E2F; Fri, 25 Nov 2022 04:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381142; x=1700917142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v4fej//7FpkGY53wVCQwPqHO2iJNyMNdkMs+y+xX9pI=; b=j0RotfVV9pC3r9m9PGRVJ4i4RKhevmsXfYUTNUNbOx9Yp1znoeK1HYa0 M7vm0lqBlb/Yskyu4tHQI8yiQLEm+rkuCsQtIV8V9ODAz2S/VxW50cLus WF5GqRLkAsoUGYrqMiU+mmYYkgm2GfFVf3D5EwL/rWf9QxD45SRk8qs9b aqOMNug0hMUL0haVCi1ivEGurgD80H8tYD6gBgH627QxmDwZVd6DJecrx QWpryQFtZcXQXp4s2pDSCkU7Eeguw2z7gJCjK/GWmKhoZW9LRqHdyoE9U lg5irSsn+CkdsEqebn8Dr00+HMUzekAJF5kefUWPkfOs3IMktRj5RFchT g==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="341381295" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="341381295" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 04:59:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061282" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061282" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 25 Nov 2022 04:58:57 -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 5/8] x86: KVM: Advertise AVX-IFMA CPUID to user space Date: Fri, 25 Nov 2022 20:58:42 +0800 Message-Id: <20221125125845.1182922-6-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=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1750473073941838072?= X-GMAIL-MSGID: =?utf-8?q?1750473073941838072?= AVX-IFMA is a new instruction in the latest Intel platform Sierra Forest. This instruction packed multiplies unsigned 52-bit integers and adds the low/high 52-bit products to Qword Accumulators. The bit definition: CPUID.(EAX=7,ECX=1):EAX[bit 23] AVX-IFMA is on an expected-dense CPUID leaf and some other bits on this leaf have kernel usages. Given that, define this feature bit like X86_FEATURE_ in kernel. Considering AVX-IFMA itself has no truly kernel usages and /proc/cpuinfo has too much unreadable flags, hide this one in /proc/cpuinfo. Advertise AVX-IFMA 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 Acked-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/cpuid.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 20059dc33d24..1419c4e04d45 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -310,6 +310,7 @@ #define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* AVX512 BFLOAT16 instructions */ #define X86_FEATURE_CMPCCXADD (12*32+ 7) /* "" CMPccXADD instructions */ #define X86_FEATURE_AMX_FP16 (12*32+21) /* "" AMX fp16 Support */ +#define X86_FEATURE_AVX_IFMA (12*32+23) /* "" Support for VPMADD52[H,L]UQ */ /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */ #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 0e04d1138bca..8612cddd9838 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -663,7 +663,8 @@ void kvm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL_SSBD); kvm_cpu_cap_mask(CPUID_7_1_EAX, - F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) | F(AMX_FP16) + F(AVX_VNNI) | F(AVX512_BF16) | F(CMPCCXADD) | F(AMX_FP16) | + F(AVX_IFMA) ); kvm_cpu_cap_mask(CPUID_D_1_EAX, From patchwork Fri Nov 25 12:58:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 26001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3999984wrr; Fri, 25 Nov 2022 05:05:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf46NRCUtRCaqn8NbTRO88RwtvapTEKTPgaYwbTFMwOeiMfZLNdNrd8GcXDjA0ujxxSS60C0 X-Received: by 2002:a63:4d5e:0:b0:42a:babf:9f1f with SMTP id n30-20020a634d5e000000b0042ababf9f1fmr15569946pgl.324.1669381526322; Fri, 25 Nov 2022 05:05:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381526; cv=none; d=google.com; s=arc-20160816; b=fkAYycp2RHMc/pxnq+elzgfeAO+ycbXyXM0MfdmPsgNPVoDGt0CZpVrI8LzojGGurw 022fbTVmijPlB1Vdjv7u1h81Ul2B+HPednxehNuPz5DbrAK/Ufp6ESuM/1zH/Smtb9oo EoDIq2NhdG35Q5XP0Ip9GJ3My2pD3GgloNxB3W6jJaibfwLgFeiy+yelCpV+C6w1jHE7 SsTsMIPA00CUwV5UwfqVqaW6YLWNYD9k0s5c80eeKvx4bGKCnR5qfrsmeQQpzUYkTEva LqtmVHdt6Yw/H8oY7uagaN1WcQqvQwu7cuOgFxsv1FwqxDOWp8g1IfaJYY34xoB+Z5JB et5g== 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=pGxuxXQzwU0gJrala1r5JagwAIOYVGSkNo+vSQf7uHA=; b=PKsrWbxcgMtXS4pkDZDwKFqLz0CvU/GwaCIhUP+68PGBwWFkJLNYY6hdpzLqJM5Pe/ ObeFIWEXzhK27pM70ZQb8LlYf8eVJNU95jbuuYbXioRTvb+FrFkViYv54msVyB+a/pbL ydtHrNzYFdzZqQjF3NFgUUhWztatum6UVUHAmZibJhfGhXJc0gajrqkrRsY1AiSq8DEz I6RtZKUE6yUzLYH87b0bYFqi9Pyjc3y1LTDemXd0SqpT9DuBCbr9YLSJjsavLPBTtzQO /B1hdUPiDllDwJ0As/Ft/DppYQoaGtanUEsAsj5VQIRJCs+CaVSDhPL5Bhsvp7qjPBBV ppwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="bwyIE4/a"; 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 f15-20020a056a001acf00b0056cf72b41cdsi4112652pfv.1.2022.11.25.05.05.09; Fri, 25 Nov 2022 05:05:26 -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="bwyIE4/a"; 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 S230032AbiKYM76 (ORCPT + 99 others); Fri, 25 Nov 2022 07:59:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbiKYM7Z (ORCPT ); Fri, 25 Nov 2022 07:59:25 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B3431F97; Fri, 25 Nov 2022 04:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381152; x=1700917152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jPQVnGMdqccMf+MxoNJO0uQw53INMkUJGNjpZ6qw38Q=; b=bwyIE4/aFXcXN2XztqMw2oGeq4Xk9wOagU8rgJanvk6OGzJ/OFdQXTKt a8NivG8lcygzhbil6QQvIKHmKBL+CIF0dSoSkvaSzI9+sgefuKhFxTw0Z cTtvey5Y4Yz9vOFtKt0finvtbCWrU4TVEZLpUthGGo6SemxKsTqS3GKSd 340g59cAcWuCwFfH/8kREkp3KtC1fKFXVvX3mVaZPsghOe+2IBvQRlcR8 qa16a0CcMAg79VYrYtG5i768cmgYN4+BkqNM6Y9wihjqHtP9wEowoxqnp XTXX3nSsLVGCV+kF2WvFDnuk4VIVPyBBvq1D6gqMbC0eZHkzw+iEyOaaa A==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="376622357" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="376622357" 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:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061313" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061313" 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:02 -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 6/8] KVM: x86: Advertise AVX-VNNI-INT8 CPUID to user space Date: Fri, 25 Nov 2022 20:58:43 +0800 Message-Id: <20221125125845.1182922-7-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?1750473403311790626?= X-GMAIL-MSGID: =?utf-8?q?1750473403311790626?= AVX-VNNI-INT8 is a new set of instructions in the latest Intel platform Sierra Forest, aims for the platform to have superior AI capabilities. This instruction multiplies the individual bytes of two unsigned or unsigned source operands, then adds and accumulates the results into the destination dword element size operand. The bit definition: CPUID.(EAX=7,ECX=1):EDX[bit 4] AVX-VNNI-INT8 is on a new and sparse CPUID leaf and all bits on this leaf have no truly kernel use case for now. Given that and to save space for kernel feature bits, move this new leaf to KVM-only subleaf and plus an x86_FEATURE definition for AVX-VNNI-INT8 to direct it to the KVM entry. Advertise AVX-VNNI-INT8 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 | 6 +++++- arch/x86/kvm/reverse_cpuid.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 8612cddd9838..2dfa8363b9d9 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -667,6 +667,10 @@ void kvm_set_cpu_caps(void) F(AVX_IFMA) ); + kvm_cpu_cap_init_kvm_defined(CPUID_7_1_EDX, + F(AVX_VNNI_INT8) + ); + kvm_cpu_cap_mask(CPUID_D_1_EAX, F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | F(XSAVES) | f_xfd ); @@ -920,9 +924,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) goto out; cpuid_entry_override(entry, CPUID_7_1_EAX); + cpuid_entry_override(entry, CPUID_7_1_EDX); entry->ebx = 0; entry->ecx = 0; - entry->edx = 0; } break; case 0xa: { /* Architectural Performance Monitoring */ diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 443a6b3e66c0..84f56b662424 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -13,6 +13,7 @@ */ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, + CPUID_7_1_EDX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -36,6 +37,9 @@ enum kvm_only_cpuid_leafs { #define KVM_X86_FEATURE_SGX1 KVM_X86_FEATURE(CPUID_12_EAX, 0) #define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1) +/* Intel-defined sub-features, CPUID level 0x00000007:1 (EDX) */ +#define X86_FEATURE_AVX_VNNI_INT8 KVM_X86_FEATURE(CPUID_7_1_EDX, 4) + struct cpuid_reg { u32 function; u32 index; @@ -60,6 +64,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_7_1_EAX] = { 7, 1, CPUID_EAX}, [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, + [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, }; /* From patchwork Fri Nov 25 12:58:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 26000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3995671wrr; Fri, 25 Nov 2022 05:00:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4I/icak6+A+nO5NTC/QpcvZXeYzUtPdG2JdBjix0JGDIjVbsqN24Ur4YNpBQBYQWEYk9y6 X-Received: by 2002:a65:4c04:0:b0:470:3fc2:65af with SMTP id u4-20020a654c04000000b004703fc265afmr17059135pgq.492.1669381231892; Fri, 25 Nov 2022 05:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381231; cv=none; d=google.com; s=arc-20160816; b=dg64plyIs8AgYoi9xHwCnY/wHBTH5bHDSmkw7/oK1iypJdaLndyzk19pnBrHfr+GXn HQABkaEk/O1VklE40wHcMsubg0g1BfHUIphTG78QVGHcjD7mGSwCKO+Vg1/Fh0kLmB2t RDCy7fMie4vBeb7cX9/hhbwdYPvFCKUe4HW2+LC8eKqymzYmbfSglNnVzgl5nHepL4vf MiqK3D4ToElWxh+qDItGVC2kTky3DGzfgVf6QX50BqoKvXFlfbLwJM3gz93WRz79/n7T PtYI92nFFuuwIArSvVdq7A24KdwWwQ5EwDitQLe8kCRojJ4tA9EUsxpHzqxRGjjlUQxs SdIg== 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=vjTBP6eVQPWPsdHIYyOMk8DQCGN+Zh2uf7AuyEZ9F4Q=; b=RRL5ad9mHpdkMOEdzhwjry79Mcs+fWAaP8mnyPBV0P/7Bw2K8oqNpsYpF9AntG9i7Y QYtRdDhbVzxYdGBNtbPlmabtwgKVHn8KtviCpgbUc2rrXUiUCLQBcUVKctU8T7vvNJgL 0aHbErVcJh/2lWil8AZevpZEFdkftX7sm3XFXzu8U8Pm7XHqgZeIBK6BsS5+5g4Or5bA sKduiwHPJsejzrFOCV33fHlgP46+gb6WLgqeKZhWyLAteFPtaKvYvqLao4ECRcg2l22p an/znyiGuVtL3D1lKj0kJRNKnuZGQ1+AiXIbvUDNFHjPElKMn7BTmHaLqRJU+est5aNI U/RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="R/bB2L2U"; 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 s5-20020a056a0008c500b005614fb190e4si4252093pfu.193.2022.11.25.05.00.18; Fri, 25 Nov 2022 05:00:31 -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="R/bB2L2U"; 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 S230004AbiKYM7x (ORCPT + 99 others); Fri, 25 Nov 2022 07:59:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbiKYM70 (ORCPT ); Fri, 25 Nov 2022 07:59:26 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B86B4B74C; Fri, 25 Nov 2022 04:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669381153; x=1700917153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=16du4i0I8Bj9j8DC+WImdAtC9niWfE1nLhKyIXA12A8=; b=R/bB2L2U5aLizb9jjf6toL5jlxecxLRaFPwDSFqwT65LPULxkkhF8a/U qTpbFaB5z/JYBGwW/RzQDhshlgdm42f57OF+L34M+yi8zbWvv5B4Zlkti oby0tuJohWs419l/VKyRixV9zlNrCtU4CyRIZAXsYy+Guy5lTlS7fxAlx h2wN3gPryIT9Z0skae7EbyJm6OXsbV3HaSbBf3YMIRHre6FTxJtEWDCt4 3kAn1V6gUdtgHI8hw+1p0W2dmhVHcK+Ct6k92VrGBS+HRJsx52plyS9MZ isFVcKe0tM2SWOLPPO0hpTmiqQG3HYAuauP46hT1gz7ix1jT6WzdUAxwZ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="376622366" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="376622366" 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:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10541"; a="706061331" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="706061331" 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:08 -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 7/8] KVM: x86: Advertise AVX-NE-CONVERT CPUID to user space Date: Fri, 25 Nov 2022 20:58:44 +0800 Message-Id: <20221125125845.1182922-8-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?1750473094390120021?= X-GMAIL-MSGID: =?utf-8?q?1750473094390120021?= AVX-NE-CONVERT is a new set of instructions which can convert low precision floating point like BF16/FP16 to high precision floating point FP32, and can also convert FP32 elements to BF16. This instruction allows the platform to have improved AI capabilities and better compatibility. The bit definition: CPUID.(EAX=7,ECX=1):EDX[bit 5] AVX-NE-CONVERT is on a KVM-only subleaf. Plus an x86_FEATURE definition for this feature bit to direct it to the KVM entry. Advertise AVX-NE-CONVERT 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 2dfa8363b9d9..c4ea8f593b72 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_VNNI_INT8) | F(AVX_NE_CONVERT) ); 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 84f56b662424..43eff7207e01 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -39,6 +39,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) struct cpuid_reg { u32 function; 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;