From patchwork Mon Mar 20 08:16:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 9634541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49E5160327 for ; Mon, 20 Mar 2017 16:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BE94267EC for ; Mon, 20 Mar 2017 16:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 306F227F8C; Mon, 20 Mar 2017 16:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A31F626E73 for ; Mon, 20 Mar 2017 16:48:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755956AbdCTQsp (ORCPT ); Mon, 20 Mar 2017 12:48:45 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34398 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753224AbdCTIRO (ORCPT ); Mon, 20 Mar 2017 04:17:14 -0400 Received: by mail-pf0-f194.google.com with SMTP id o126so16012718pfb.1 for ; Mon, 20 Mar 2017 01:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ACPt35jqey2WL7IwikxkchJncHm82TLtWSIezMhmhgk=; b=hOKvkPmLQ7RGBhap5wMB6ijLlwh23OajztZkf5ZYwoUvhEM4ABCA6e8UuKb+f1vvBD Y2lyBasFHTBXko8faOUawQigJEBTunGFqewSlQbKWv5D9mW20ZaSGBOTg/blR3o65vTF dh6UH/hiaKXNQvFAt/fyYj1/CwN/vxyl6tOCpUU1zM/sUhUzDE9lypBRYx4msy2V0yeC yBtgdEC3LvGBdtc4TbBhEEoDogPkzggi0FRPn1vXG/kAv3QCtsRbGfrCJ2eh8ufweRyA 8tM+A8afEBwmh5UD/D35USyKs0llVqaizdHoDjyBN9MKVewijgCiaFjdCRhDBc8PbXB9 FuIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ACPt35jqey2WL7IwikxkchJncHm82TLtWSIezMhmhgk=; b=ieowogoboDMbmnGyUHyCNhOeGe1TIBVFncnvOa//egNdTo0CNr/t1vFskutf8K/O6M RCtLZE7nvTzCeBxigVGjesrsjkQPSXDjL5FOmCdE4D9zePo/WLzbatzjiHoUDxvDCs0a tljSvGhH3nvVVB/XmPe14O9RIPviQ0kyGtdTl5D9pbWmCiJlFNhM+6NVtARlG5vewmxc bZx/59HIxGq4xBoA7YAr/tYEKaCsGKNhZQqk0CjRqm1wLHzkBFxPXMTa2sFEUIjPkY1y NQNLJZHghvORGmgZ44bLz+hmzEQQJbfeQF7e8Y0nUyL405kqW73Y4J5sbyxCmMpBGkpS W7kQ== X-Gm-Message-State: AFeK/H1aZJiVA0GVbLjSfmWcDUR+pGX4FKSLi8DGzrpI0reUyRXPSKm391zW6nbWNEZrqA== X-Received: by 10.84.229.1 with SMTP id b1mr16597598plk.169.1489997832280; Mon, 20 Mar 2017 01:17:12 -0700 (PDT) Received: from minbar.home.kylehuey.com (c-50-150-100-179.hsd1.ca.comcast.net. [50.150.100.179]) by smtp.gmail.com with ESMTPSA id m20sm7792029pgd.32.2017.03.20.01.17.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 01:17:11 -0700 (PDT) From: Kyle Huey X-Google-Original-From: Kyle Huey To: Robert O'Callahan , Thomas Gleixner , Andy Lutomirski , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Jeff Dike , Richard Weinberger , Alexander Viro , Shuah Khan , Dave Hansen , Borislav Petkov , Peter Zijlstra , Boris Ostrovsky , Len Brown , "Rafael J. Wysocki" , Dmitry Safonov , David Matlack , Nadav Amit , Andi Kleen , Grzegorz Andrejczuk Cc: linux-kernel@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH v16 07/10] x86/cpufeature: Detect CPUID faulting support Date: Mon, 20 Mar 2017 01:16:25 -0700 Message-Id: <20170320081628.18952-8-khuey@kylehuey.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170320081628.18952-1-khuey@kylehuey.com> References: <20170320081628.18952-1-khuey@kylehuey.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Intel supports faulting on the CPUID instruction beginning with Ivy Bridge. When enabled, the processor will fault on attempts to execute the CPUID instruction with CPL>0. This will allow a ptracer to emulate the CPUID instruction. Bit 31 of MSR_PLATFORM_INFO advertises support for this feature. It is documented in detail in Section 2.3.2 of https://bugzilla.kernel.org/attachment.cgi?id=243991 Detect support for this feature and expose it as X86_FEATURE_CPUID_FAULT. Signed-off-by: Kyle Huey Reviewed-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/intel.c | 24 +++++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index b04bb6dfed7f..0fe00446f9ca 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -187,6 +187,7 @@ * Reuse free bits when adding new feature flags! */ #define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */ +#define X86_FEATURE_CPUID_FAULT ( 7*32+ 1) /* Intel CPUID faulting */ #define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ #define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ #define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index f429b70ebaef..b1f75daca34b 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -45,6 +45,8 @@ #define MSR_IA32_PERFCTR1 0x000000c2 #define MSR_FSB_FREQ 0x000000cd #define MSR_PLATFORM_INFO 0x000000ce +#define MSR_PLATFORM_INFO_CPUID_FAULT_BIT 31 +#define MSR_PLATFORM_INFO_CPUID_FAULT BIT_ULL(MSR_PLATFORM_INFO_CPUID_FAULT_BIT) #define MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 #define NHM_C3_AUTO_DEMOTE (1UL << 25) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index e229318d7230..a07f8295c9ed 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -488,6 +488,28 @@ static void intel_bsp_resume(struct cpuinfo_x86 *c) init_intel_energy_perf(c); } +static void init_cpuid_fault(struct cpuinfo_x86 *c) +{ + u64 msr; + + if (!rdmsrl_safe(MSR_PLATFORM_INFO, &msr)) { + if (msr & MSR_PLATFORM_INFO_CPUID_FAULT) + set_cpu_cap(c, X86_FEATURE_CPUID_FAULT); + } +} + +static void init_intel_misc_features(struct cpuinfo_x86 *c) +{ + u64 msr; + + if (rdmsrl_safe(MSR_MISC_FEATURES_ENABLES, &msr)) + return; + + /* Check features and update capabilities */ + init_cpuid_fault(c); + probe_xeon_phi_r3mwait(c); +} + static void init_intel(struct cpuinfo_x86 *c) { unsigned int l2 = 0; @@ -602,7 +624,7 @@ static void init_intel(struct cpuinfo_x86 *c) init_intel_energy_perf(c); - probe_xeon_phi_r3mwait(c); + init_intel_misc_features(c); } #ifdef CONFIG_X86_32