Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2724336ybi; Sun, 26 May 2019 06:40:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdrfYQJO5GbKk4fk/v4EVbm01dHD4GsXbpd/KGIPxs7Nq763oi7lOlOfQkAyVvCxTwRvkf X-Received: by 2002:a17:902:b18c:: with SMTP id s12mr101081284plr.181.1558878038813; Sun, 26 May 2019 06:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558878038; cv=none; d=google.com; s=arc-20160816; b=n5zwW8mNz+jONFrHx9LoSpdCvgPmhG6Y/W352RR4Mlw+T0cxV9x2weWETuC2fwlUiS a7SoT/QkP0SkRAM0X2o2MKo3e4+cckFEZo58h9FPCsK1YB/vNUkCgI3C+XcYtTPspYI8 7vA+KabN8h1TFoJziW/uk2dEgnuyGybmm/Oh8r6x1Y7QP5UrnBEMX5MEQvZO6dxbQ9JT F2VNosV+IaRuYnoX9e/+Xt33Qsv/34AL7XbJNuJYRmAyGMEOKguHsQrMZgSoEyRJOg/5 BulaNe+nn47jaSOd+m6p/+HuP6omnZRawUEp91bHvpXwGOWI5YmO8z7SzBMWJqkMvXEN bS5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Yh6XheNRXsF/itXemCaCYYNudgKQx9mNj969vdBwKLQ=; b=Si3vnO3L/TNofYlqkncOk8t3Ex41x7YUnDGjX+GygvXekMre6UOlk5I8AAS8YJfkGA mg4ojGQWb0PCyYr8YppzKZ7+fNX5xn9DkR8UGDcQTNa4yDRsrZtkWJFYhzykeWZtFl45 GClUvCZdMvLKjlpxN8HfLJI5y/d8BRPJkEnUk+0lShYblx7x3CAV3PZzaFxuJaXFHB4Y 3QBUgITBPe1M+IAd0rik2DhpTXO47nzMKFbsKH8HiFeECRh7MhViNKxy23cdaaIC+0SQ KNT/9La3Y+wfzFNXSBTkmefvaGjnhuGfc+15txVxaWbcFf8dVucg+MHjmjlAr4+BVUHk dbWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si2714836pfo.155.2019.05.26.06.39.49; Sun, 26 May 2019 06:40:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727829AbfEZNc4 (ORCPT + 99 others); Sun, 26 May 2019 09:32:56 -0400 Received: from mga14.intel.com ([192.55.52.115]:7991 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfEZNcz (ORCPT ); Sun, 26 May 2019 09:32:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 May 2019 06:32:54 -0700 X-ExtLoop1: 1 Received: from likexu-e5-2699-v4.sh.intel.com ([10.239.48.178]) by FMSMGA003.fm.intel.com with ESMTP; 26 May 2019 06:32:53 -0700 From: Like Xu To: Paolo Bonzini , kvm@vger.kernel.org Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [RESEND PATCH v3] KVM: x86: Add Intel CPUID.1F cpuid emulation support Date: Sun, 26 May 2019 21:30:52 +0800 Message-Id: <20190526133052.4069-1-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to expose Intel V2 Extended Topology Enumeration Leaf for some new systems with multiple software-visible die within each package. Per Intel's SDM, when CPUID executes with EAX set to 1FH, the processor returns information about extended topology enumeration data. Software must detect the presence of CPUID leaf 1FH by verifying (a) the highest leaf index supported by CPUID is >= 1FH, and (b) CPUID.1FH:EBX[15:0] reports a non-zero value. Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li Signed-off-by: Like Xu Reviewed-by: Sean Christopherson --- ==changelog== v3: - Refine commit message and comment v2: https://lkml.org/lkml/2019/4/25/1246 - Apply cpuid.1f check rule on Intel SDM page 3-222 Vol.2A - Add comment to handle 0x1f anf 0xb in common code - Reduce check time in a descending-break style v1: https://lkml.org/lkml/2019/4/22/28 arch/x86/kvm/cpuid.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 80a642a0143d..f9b41f0103b3 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -426,6 +426,11 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, switch (function) { case 0: + /* Check if the cpuid leaf 0x1f is actually implemented */ + if (entry->eax >= 0x1f && (cpuid_ebx(0x1f) & 0x0000ffff)) { + entry->eax = 0x1f; + break; + } entry->eax = min(entry->eax, (u32)(f_intel_pt ? 0x14 : 0xd)); break; case 1: @@ -545,7 +550,11 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->edx = edx.full; break; } - /* function 0xb has additional index. */ + /* + * Per Intel's SDM, 0x1f is a superset of 0xb, thus they can be handled + * by common code. + */ + case 0x1f: case 0xb: { int i, level_type; -- 2.21.0