From patchwork Thu Nov 3 02:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxi Chen X-Patchwork-Id: 14608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp279691wru; Wed, 2 Nov 2022 19:53:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OfrITwGbXxvgWtvJujw4R/6CewYCL08d4B0aR5AU+bzGD7QPppb/5+5P51ymIU5VFIa8F X-Received: by 2002:a17:902:e1ca:b0:186:878e:3b03 with SMTP id t10-20020a170902e1ca00b00186878e3b03mr28424694pla.95.1667443993404; Wed, 02 Nov 2022 19:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667443993; cv=none; d=google.com; s=arc-20160816; b=Nnvo84Pp85ptJPRw2qiQhf45zC8K0XmwQxmG+gzgr5UNnm+24KJnQPqdAwLoVOzMaD poZ9QtepdTrGyvQqVs+iiXdi0j9yCiByTTTBSt7+88/fnYW5E/S3LjgqWZ75Iyr6Whla O9h5mzXeGsg+PtbFOQFKGUJTD2tuYmzBTYy+V8eGOVqsWrjwS68gBphSv4CwgqoOvV7p ars+XMmqiv/Vh0+7Yoe2LhSQr39ZknIw6qhRAqYQWDYMbTJlU7Jpjj3uX0cmoB23/Fhi qHzuQisPw7CiYIt7+iTgUeaCYOdmY/LNNHZ1EUMH3hCVjVt6vjjlz5TXj0DbVIfc7G4M J+9Q== 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=hTw+jb4iRb0MJYCDEyEUxV167FGqorP9Oa7HKRA8mHc=; b=WR1kxkoVZD6HXLDQor9h29veNv2PYFEvtxxcMJV/TyRUD6LGGbtmqeLdRwDweezKzG NwPjGJgd/lez18pPfWuIrbwFFZMv8+Kg3pB08qZAyBSdXdHYuJblqK1CW1yWgc4EHGq8 wR72aUQu8oaabK1vOsrrSEEUgJLvYHNVSxBf3RdiH0N5tE8xO6L5NShNVqwxz4m837QA NTMP+t9ZKfV0nClaluT4c+t7u7bGmUUC5AN4ZRvL9lPqI5xxKlE0X66tiowoLT95VpsV DuauzzQFIEKyvJ5l7zYOz4m/H5aqgTA1CTQXpJIhKf6x4k6Knr3IvJeGSvncOe2r+aYm iTfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPshaeWW; 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 d22-20020a056a0024d600b0056bffcfc30csi19680801pfv.249.2022.11.02.19.53.00; Wed, 02 Nov 2022 19:53:13 -0700 (PDT) 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=VPshaeWW; 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 S231391AbiKCCv5 (ORCPT + 99 others); Wed, 2 Nov 2022 22:51:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbiKCCvZ (ORCPT ); Wed, 2 Nov 2022 22:51:25 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CC715721; Wed, 2 Nov 2022 19:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667443865; x=1698979865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QZah9F13AjoVe9tv/CykWOC6OrnYXLMSXtZoIq5C0N0=; b=VPshaeWWC+w/wq2XqKqj43wHvKnGfJWlDgNRNLywEZjOf5JlkTscNPmC fqmbsuBHuyRMyQUQ0ekf63Iiv0r9Lv6tQjKvDSob/4KYUM0/EXg2k0BRa GBul/rjhP3vGk8afERl3pkiqV9GPR/aLdfWpmwNFk/WvsqREvZAUi8haX 4EDc7q0Sn6POS3ahaUY0VEduU0qvsiRV4K4RfSk4AugPJHtTS2Xr3eaGy /HckDOTdu/ztIpzNKKMNbhCEJKCYn4n0CmV5u0a0simbPhAfYlUvmtYbi NG5tu/GttnCvE0Y895bC1KpWVTM24EQIeWfjydLPFGUrtcIivxmzRzp3I w==; X-IronPort-AV: E=McAfee;i="6500,9779,10519"; a="307186654" X-IronPort-AV: E=Sophos;i="5.95,235,1661842800"; d="scan'208";a="307186654" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2022 19:51:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10519"; a="698047919" X-IronPort-AV: E=Sophos;i="5.95,235,1661842800"; d="scan'208";a="698047919" Received: from jiaxichen-precision-3650-tower.sh.intel.com ([10.239.159.75]) by fmsmga008.fm.intel.com with ESMTP; 02 Nov 2022 19:51:00 -0700 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 v2 6/8] x86: KVM: Advertise AVX-VNNI-INT8 CPUID to user space Date: Thu, 3 Nov 2022 10:50:28 +0800 Message-Id: <20221103025030.78371-7-jiaxi.chen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103025030.78371-1-jiaxi.chen@linux.intel.com> References: <20221103025030.78371-1-jiaxi.chen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.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?1748441752606022974?= X-GMAIL-MSGID: =?utf-8?q?1748441752606022974?= 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] This CPUID is exposed to user space. Besides, there is no other VMX control for this instruction. Signed-off-by: Jiaxi Chen --- arch/x86/kvm/cpuid.c | 5 ++++- arch/x86/kvm/reverse_cpuid.h | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index e84c6216a72c..06dacf71ff9c 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -661,6 +661,9 @@ void kvm_set_cpu_caps(void) F(AVX_IFMA) ); + kvm_cpu_cap_init_scattered(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 ); @@ -914,9 +917,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 954c0ceb1e90..819b4e0b13a3 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -14,6 +14,7 @@ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, CPUID_7_1_EAX, + CPUID_7_1_EDX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -32,6 +33,9 @@ enum kvm_only_cpuid_leafs { #define X86_FEATURE_AMX_FP16 KVM_X86_FEATURE(CPUID_7_1_EAX, 21) #define X86_FEATURE_AVX_IFMA KVM_X86_FEATURE(CPUID_7_1_EAX, 23) +/* 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; @@ -56,6 +60,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}, }; /*