Received: by 10.213.65.68 with SMTP id h4csp18849imn; Mon, 12 Mar 2018 05:24:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELup9nEmmYwMB8t+H1DKMy6EX7G+gKGTqTZrNoNlvm7gGYTFwDScEXTIc1HNbl/xIGe8ERAf X-Received: by 10.98.249.10 with SMTP id o10mr7841461pfh.222.1520857482682; Mon, 12 Mar 2018 05:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520857482; cv=none; d=google.com; s=arc-20160816; b=SKkaqHryXvdupwpPdOosUmMiD2nYtMyYTgUDuEGwcAAw4CoN90cu1u2yD+7mkW4GPs sr2+po82i8+map7o6VC4503lCQrLQQzU6wjyw4YWQfgibboUD6v9seZYJ+UxbWlFFMqR J5kjDVJCET9PnaEmVyRqY9yPGCgDQpJXSt6Wk9WS2981bEuKjugG1v8Dh44gPZxTW/0f pbKnBwFXmi++3k6SOvEYGCVcsVmsolFJWqpufjf99v2sV+cJWjbuqin9kwCZbt833qim iy946zzhUl0rQDKTCbAKk1auxlHPZchwo5r/C9Wzra+PurTsSK7OgVGNtPcGNZqxKsn3 XuuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=Ton802+DzjP1emOA3VK2ZCFLtPnxcBc8dWOXlyxZDH0=; b=ANj+hPRIle23QV8Nq1lCO7o81b6k2ohdJmrR8ylszaq9sdpiFUtlSQ0T4p/dMu23NK 8TFyG4ttJGvGJa2CS53wy0hPbXrRKir5QyJUnx2dMJnwbncSt0tB+Qvyat612gmWqwe3 VbbJY+RETF8QA6CjYyWSDcLDS8vDI3Dz+kdABjC6ZWfYRfnaWbSbR0iRy66dBhDYLwrO N7MK+ZVvjlUBO5eHgFfPO0ED/xeiNWxL54WfjWUzkXviraiUk2izduoycspSkjnYZrs6 QbxqKEvBeH39FnB0iPa/rgfMDEv1Qaovi6h8zTsThKPODAc9do5IXC/UtDHcN5vYVfcc GmWg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si5699284pfl.312.2018.03.12.05.24.28; Mon, 12 Mar 2018 05:24:42 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751392AbeCLMW4 (ORCPT + 99 others); Mon, 12 Mar 2018 08:22:56 -0400 Received: from terminus.zytor.com ([198.137.202.136]:60993 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbeCLMWy (ORCPT ); Mon, 12 Mar 2018 08:22:54 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2CCMVSg017516; Mon, 12 Mar 2018 05:22:31 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2CCMVY0017513; Mon, 12 Mar 2018 05:22:31 -0700 Date: Mon, 12 Mar 2018 05:22:31 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Kirill A. Shutemov" Message-ID: Cc: kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, hpa@zytor.com, dave.hansen@intel.com, tglx@linutronix.de, torvalds@linux-foundation.org, mingo@kernel.org, peterz@infradead.org, kai.huang@linux.intel.com, thomas.lendacky@amd.com Reply-To: thomas.lendacky@amd.com, mingo@kernel.org, torvalds@linux-foundation.org, kai.huang@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, kirill.shutemov@linux.intel.com, dave.hansen@intel.com In-Reply-To: <20180305162610.37510-5-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-5-kirill.shutemov@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/pconfig: Detect PCONFIG targets Git-Commit-ID: be7825c19b4866ddc7b1431740b69ede2eeb93c1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: be7825c19b4866ddc7b1431740b69ede2eeb93c1 Gitweb: https://git.kernel.org/tip/be7825c19b4866ddc7b1431740b69ede2eeb93c1 Author: Kirill A. Shutemov AuthorDate: Mon, 5 Mar 2018 19:25:52 +0300 Committer: Ingo Molnar CommitDate: Mon, 12 Mar 2018 12:10:54 +0100 x86/pconfig: Detect PCONFIG targets Intel PCONFIG targets are enumerated via new CPUID leaf 0x1b. This patch detects all supported targets of PCONFIG and implements helper to check if the target is supported. Signed-off-by: Kirill A. Shutemov Cc: Dave Hansen Cc: Kai Huang Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Tom Lendacky Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180305162610.37510-5-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/include/asm/intel_pconfig.h | 15 +++++++ arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/intel_pconfig.c | 82 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/intel_pconfig.h b/arch/x86/include/asm/intel_pconfig.h new file mode 100644 index 000000000000..fb7a37c3798b --- /dev/null +++ b/arch/x86/include/asm/intel_pconfig.h @@ -0,0 +1,15 @@ +#ifndef _ASM_X86_INTEL_PCONFIG_H +#define _ASM_X86_INTEL_PCONFIG_H + +#include +#include + +enum pconfig_target { + INVALID_TARGET = 0, + MKTME_TARGET = 1, + PCONFIG_TARGET_NR +}; + +int pconfig_target_supported(enum pconfig_target target); + +#endif /* _ASM_X86_INTEL_PCONFIG_H */ diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 570e8bb1f386..a66229f51b12 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -28,7 +28,7 @@ obj-y += cpuid-deps.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_X86_FEATURE_NAMES) += capflags.o powerflags.o -obj-$(CONFIG_CPU_SUP_INTEL) += intel.o +obj-$(CONFIG_CPU_SUP_INTEL) += intel.o intel_pconfig.o obj-$(CONFIG_CPU_SUP_AMD) += amd.o obj-$(CONFIG_CPU_SUP_CYRIX_32) += cyrix.o obj-$(CONFIG_CPU_SUP_CENTAUR) += centaur.o diff --git a/arch/x86/kernel/cpu/intel_pconfig.c b/arch/x86/kernel/cpu/intel_pconfig.c new file mode 100644 index 000000000000..0771a905b286 --- /dev/null +++ b/arch/x86/kernel/cpu/intel_pconfig.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Intel PCONFIG instruction support. + * + * Copyright (C) 2017 Intel Corporation + * + * Author: + * Kirill A. Shutemov + */ + +#include +#include + +#define PCONFIG_CPUID 0x1b + +#define PCONFIG_CPUID_SUBLEAF_MASK ((1 << 12) - 1) + +/* Subleaf type (EAX) for PCONFIG CPUID leaf (0x1B) */ +enum { + PCONFIG_CPUID_SUBLEAF_INVALID = 0, + PCONFIG_CPUID_SUBLEAF_TARGETID = 1, +}; + +/* Bitmask of supported targets */ +static u64 targets_supported __read_mostly; + +int pconfig_target_supported(enum pconfig_target target) +{ + /* + * We would need to re-think the implementation once we get > 64 + * PCONFIG targets. Spec allows up to 2^32 targets. + */ + BUILD_BUG_ON(PCONFIG_TARGET_NR >= 64); + + if (WARN_ON_ONCE(target >= 64)) + return 0; + return targets_supported & (1ULL << target); +} + +static int __init intel_pconfig_init(void) +{ + int subleaf; + + if (!boot_cpu_has(X86_FEATURE_PCONFIG)) + return 0; + + /* + * Scan subleafs of PCONFIG CPUID leaf. + * + * Subleafs of the same type need not to be consecutive. + * + * Stop on the first invalid subleaf type. All subleafs after the first + * invalid are invalid too. + */ + for (subleaf = 0; subleaf < INT_MAX; subleaf++) { + struct cpuid_regs regs; + + cpuid_count(PCONFIG_CPUID, subleaf, + ®s.eax, ®s.ebx, ®s.ecx, ®s.edx); + + switch (regs.eax & PCONFIG_CPUID_SUBLEAF_MASK) { + case PCONFIG_CPUID_SUBLEAF_INVALID: + /* Stop on the first invalid subleaf */ + goto out; + case PCONFIG_CPUID_SUBLEAF_TARGETID: + /* Mark supported PCONFIG targets */ + if (regs.ebx < 64) + targets_supported |= (1ULL << regs.ebx); + if (regs.ecx < 64) + targets_supported |= (1ULL << regs.ecx); + if (regs.edx < 64) + targets_supported |= (1ULL << regs.edx); + break; + default: + /* Unknown CPUID.PCONFIG subleaf: ignore */ + break; + } + } +out: + return 0; +} +arch_initcall(intel_pconfig_init);