From patchwork Tue Nov 1 01:37:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 9406787 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 5B27D601C0 for ; Tue, 1 Nov 2016 01:40:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BA4329395 for ; Tue, 1 Nov 2016 01:40:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FFC428D62; Tue, 1 Nov 2016 01:40:00 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 B283B29395 for ; Tue, 1 Nov 2016 01:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161282AbcKABj1 (ORCPT ); Mon, 31 Oct 2016 21:39:27 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33361 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034550AbcKABid (ORCPT ); Mon, 31 Oct 2016 21:38:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id a136so6744829pfa.0 for ; Mon, 31 Oct 2016 18:38:33 -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=n5OmFN9y6CJLg1apQ1dh6kVAbCWJ25Jt1uFLLsJuakY=; b=E87KbWRLbFD2lrbCdZ/soKCzQnNMWdC4vtTx6wCQTDFXpveEqBT+lBB3TjQRwmiPsD ILHtW05nRAfUao6J87bGM/fFHZklZWBnLfi+cvxRUnue0JRaDDbSzxH1qdaGsaSbSe5p CyzmkXrJSReUoklZXBLkZ0FW0PoUW1PGb1vxG1bUemF/G2GrZEjF1XxAU4SOysc8tiaM 1P816fl1I1jBKKCiFKq5GKxyzuKoH7FqjE660P8qKkoiofNGTfyZCA4obVqt+o/nFvLG XYnaSDik5DLefGDJrBOZkdCM8blpuB1yMNZ1fNOUsr2Qt5aEJtGpRbaBPFRd/hHlVvLe Kp9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n5OmFN9y6CJLg1apQ1dh6kVAbCWJ25Jt1uFLLsJuakY=; b=TbtblbwXljVePbojb6FufbvmJppsP7rNhnu5LCULv8hREJn538XOV15C339EJaGRXR tyUVJq1wHYIT8znfDzWoo7j11AKQOKyT5uTmzLxjIdEfHYg6pZvzafbO6X1DekLd66MN PDu5y/qPCjHJDroPl36rcchkrt7kqQMBbIvTWW7/2lCk0w93b+NjYAljFmqFd6hMuHsC gbPs8CorvSW3ePQ1jcCPB5GPHxFtOVIwXB2ASAmOTxcO+vbsRp29D1fhQ3aHmZbkQwQE 7gIgy2BM7O3tL/XijDXhHpiDX13WN6t1z4d14YAWs7eC4wPVpQzUnzYyHMUkzOZgYCFo IjDw== X-Gm-Message-State: ABUngve3fl7PKxCgDGnzX/8crY2J4m8wgorjrEHjhVKAriCplWf1pNcy5Lp3yWs4MH7N2w== X-Received: by 10.99.143.2 with SMTP id n2mr44805827pgd.70.1477964312812; Mon, 31 Oct 2016 18:38:32 -0700 (PDT) Received: from minbar.hsd1.ca.comcast.net (c-73-162-102-141.hsd1.ca.comcast.net. [73.162.102.141]) by smtp.gmail.com with ESMTPSA id u17sm38188144pfi.1.2016.10.31.18.38.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Oct 2016 18:38:32 -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 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 v8 5/7] x86/cpufeature: Detect CPUID faulting support Date: Mon, 31 Oct 2016 18:37:47 -0700 Message-Id: <20161101013749.4003-6-khuey@kylehuey.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161101013749.4003-1-khuey@kylehuey.com> References: <20161101013749.4003-1-khuey@kylehuey.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/virtualization-technology-flexmigration-application-note.pdf Detect support for this feature and expose it as X86_FEATURE_CPUID_FAULT. Signed-off-by: Kyle Huey Reviewed-by: Andy Lutomirski --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/scattered.c | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index a396292..62962e8 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -184,16 +184,17 @@ * Auxiliary flags: Linux defined - For features scattered in various * CPUID levels like 0x6, 0xA etc, word 7. * * Reuse free bits when adding new feature flags! */ #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_CPUID_FAULT ( 7*32+ 4) /* Intel CPUID faulting */ #define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */ #define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ #define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */ #define X86_FEATURE_AVX512_4VNNIW (7*32+16) /* AVX-512 Neural Network Instructions */ #define X86_FEATURE_AVX512_4FMAPS (7*32+17) /* AVX-512 Multiply Accumulation Single precision */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 78f3760..97fb50b 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -36,16 +36,18 @@ #define EFER_LMSLE (1<<_EFER_LMSLE) #define EFER_FFXSR (1<<_EFER_FFXSR) /* Intel MSRs. Some also available on other CPUs */ #define MSR_IA32_PERFCTR0 0x000000c1 #define MSR_IA32_PERFCTR1 0x000000c2 #define MSR_FSB_FREQ 0x000000cd #define MSR_PLATFORM_INFO 0x000000ce +#define PLATINFO_CPUID_FAULT_BIT 31 +#define PLATINFO_CPUID_FAULT (1ULL << PLATINFO_CPUID_FAULT_BIT) #define MSR_NHM_SNB_PKG_CST_CFG_CTL 0x000000e2 #define NHM_C3_AUTO_DEMOTE (1UL << 25) #define NHM_C1_AUTO_DEMOTE (1UL << 26) #define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25) #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index 1db8dc4..97a340d 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -19,41 +19,61 @@ struct cpuid_bit { enum cpuid_regs { CR_EAX = 0, CR_ECX, CR_EDX, CR_EBX }; +struct msr_bit { + u16 feature; + u16 msr; + u8 bit; +}; + void init_scattered_cpuid_features(struct cpuinfo_x86 *c) { + const struct cpuid_bit *cb; + const struct msr_bit *mb; u32 max_level; u32 regs[4]; - const struct cpuid_bit *cb; + u64 msrval; static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_INTEL_PT, CR_EBX,25, 0x00000007, 0 }, { X86_FEATURE_AVX512_4VNNIW, CR_EDX, 2, 0x00000007, 0 }, { X86_FEATURE_AVX512_4FMAPS, CR_EDX, 3, 0x00000007, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 }, { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CR_EDX,11, 0x80000007, 0 }, { 0, 0, 0, 0, 0 } }; + static const struct msr_bit msr_bits[] = { + { X86_FEATURE_CPUID_FAULT, MSR_PLATFORM_INFO, 31 }, + { 0, 0, 0 } + }; + for (cb = cpuid_bits; cb->feature; cb++) { /* Verify that the level is valid */ max_level = cpuid_eax(cb->level & 0xffff0000); if (max_level < cb->level || max_level > (cb->level | 0xffff)) continue; cpuid_count(cb->level, cb->sub_leaf, ®s[CR_EAX], ®s[CR_EBX], ®s[CR_ECX], ®s[CR_EDX]); if (regs[cb->reg] & (1 << cb->bit)) set_cpu_cap(c, cb->feature); } + + for (mb = msr_bits; mb->feature; mb++) { + if (rdmsrl_safe(mb->msr, &msrval)) + continue; + if (msrval & (1ULL << mb->bit)) + set_cpu_cap(c, mb->feature); + } }