Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp65032pxh; Thu, 7 Apr 2022 14:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTJ3Fi2SZsK8J0Hy4tvvqQHAyG7m8AHZY9A8guyJqq2faDHv7os6Bc2ZzafodYnt/ExHDu X-Received: by 2002:a17:90b:3b89:b0:1c6:56a2:1397 with SMTP id pc9-20020a17090b3b8900b001c656a21397mr18040070pjb.239.1649365610424; Thu, 07 Apr 2022 14:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649365610; cv=none; d=google.com; s=arc-20160816; b=yqnwAACBFJi6wsDAQNrRNGEGkU+yQxuO54gB1QfRIRrwX0dLx2Mn0JYGSjBqiwo0lZ sgCosH3FRxayiR4TBe1lYrF/DijdwNAZfHzczGx/OkSH6vQSCKboRpl6Z2bUT6srMLR1 vKFQu1tdAImMC4BLuuXRDXfdZlAMBRcRQ8pn1l5zu1s7nkINIMURn7xH4AqYY9Y0ALFk Tcye7FStEZHYyc2/eohTLwQNk/YwQWjVLLCRZKh0GTqsJF5HqiBvsEGkb1RTLppU2FAm bbJPugp9K3RL6mKqqcjOmwHTcYBuZWVgEJ0VH7BBizAC+apOs4rl0RHedVq/iSUU1j7z ZRew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=+VxRhvKoMuhNJZ5sOFzqAixG8I0goilWTrcee8L0es0=; b=LPM3kUEkpwFWwqsavX7/VsYY9sCzu+QRwERVeA+1v2txyWVdQpd5yqaKawBLzgvE7c OhkYj88iApOzbaztGG7IcibF2Ka2f43dwbDtVi5qrRb5VC3qafbULhNNICWqrWT5/HFY 9VlkX5eXfW0uEM3USV8OEUM9CjUq8EzwVNlcUSNlK8ETqy/YPrNxdrrBaT72rWjFOKbq xR1MsubI/T1kJpY/fZHDGg/oSkj37Fxb6AXUcslYOCaUqgJY6IvojxFuZ8LRo4TAg6Gy w/4HtJGQ/vkVLr3uGsRUbLtdeFB272fhyRPABNWPIx0kJbHhTbvcW8B3EdKm6DTsqWL4 bzrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TpNm7HBO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s194-20020a6377cb000000b0039caf300531si6581473pgc.1.2022.04.07.14.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 14:06:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TpNm7HBO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6AF744808C4; Thu, 7 Apr 2022 13:12:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234204AbiDGTQl (ORCPT + 99 others); Thu, 7 Apr 2022 15:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235977AbiDGTQ0 (ORCPT ); Thu, 7 Apr 2022 15:16:26 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB62F23F38A; Thu, 7 Apr 2022 12:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649358865; x=1680894865; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=v8fg/6b+RiL40tjdRPvkX79y7/36eLSaDV4i3s78nKQ=; b=TpNm7HBOUinCMXnni9Ss2kZmx0VG5I3OjDNZNKukdLuE9kn4v11j5ayu 31BrwyEf301w8Ose18kwwq/rDGGdJQXcPRXTtFD/ucr65HwCnJMHlfYmA MFAqlJtqYaQzLunJ56eyYJ7ECxqpgxA3R+1oyKiWdxuiCdeowVzRJhuXB QCk9FxK7pJWXWVAQqgfODDbEF1xfAJzCfPMF1YFxWOg3N3x/nv8DrOF80 g9ModjSBxkoiOMvAULsi6XC5p/PvwWxYKqQ+bgn/modsao/32Zt6VJL8m eOz9KwTlT4htCV1dEQfCqEq/DNyL2gTPyN6QMPDEMVsBDytCzHtagj+Ov Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="260255376" X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="260255376" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 12:14:16 -0700 X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="571193702" Received: from coffy.sc.intel.com ([10.3.79.166]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 12:14:15 -0700 From: Jithu Joseph To: hdegoede@redhat.com, markgross@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, corbet@lwn.net, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, jithu.joseph@intel.com, ashok.raj@intel.com, tony.luck@intel.com, rostedt@goodmis.org, dan.j.williams@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, platform-driver-x86@vger.kernel.org, patches@lists.linux.dev, ravi.v.shankar@intel.com Subject: [PATCH v2 01/10] x86/microcode/intel: expose collect_cpu_info_early() for IFS Date: Thu, 7 Apr 2022 12:13:38 -0700 Message-Id: <20220407191347.9681-2-jithu.joseph@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220407191347.9681-1-jithu.joseph@intel.com> References: <20220407191347.9681-1-jithu.joseph@intel.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 IFS is a CPU feature that allows a binary blob, similar to microcode, to be loaded and consumed to perform low level validation of CPU circuitry. In fact, it carries the same Processor Signature (family/model/stepping) details that are contained in Intel microcode blobs. In support of an IFS driver to trigger loading, validation, and running of these tests blobs, export cpu_signatures_match() and collect_cpu_info_early(). Rename collect_cpu_info_early() to cpu_collect_info_early() to keep a more appropriate prefix. Per Boris [1], move these helpers to a generic location. No functional change intended. Link: https://lore.kernel.org/lkml/Yh9HKhESkcUIYzSr@nazgul.tnic/ [1] Reviewed-by: Tony Luck Signed-off-by: Jithu Joseph --- arch/x86/include/asm/microcode_intel.h | 4 ++ arch/x86/kernel/cpu/intel.c | 47 ++++++++++++++++++++++ arch/x86/kernel/cpu/microcode/intel.c | 55 +++----------------------- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h index d85a07d7154f..cf0fd1d712b4 100644 --- a/arch/x86/include/asm/microcode_intel.h +++ b/arch/x86/include/asm/microcode_intel.h @@ -68,6 +68,10 @@ static inline u32 intel_get_microcode_revision(void) return rev; } +int cpu_collect_info_early(struct ucode_cpu_info *uci); +bool cpu_signatures_match(unsigned int s1, unsigned int p1, + unsigned int s2, unsigned int p2); + #ifdef CONFIG_MICROCODE_INTEL extern void __init load_ucode_intel_bsp(void); extern void load_ucode_intel_ap(void); diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 8321c43554a1..2008c8267fd3 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -181,6 +181,53 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c) return false; } +bool cpu_signatures_match(unsigned int s1, unsigned int p1, + unsigned int s2, unsigned int p2) +{ + if (s1 != s2) + return false; + + /* Processor flags are either both 0 ... */ + if (!p1 && !p2) + return true; + + /* ... or they intersect. */ + return p1 & p2; +} +EXPORT_SYMBOL_GPL(cpu_signatures_match); + +int cpu_collect_info_early(struct ucode_cpu_info *uci) +{ + unsigned int val[2]; + unsigned int family, model; + struct cpu_signature csig = { 0 }; + unsigned int eax, ebx, ecx, edx; + + memset(uci, 0, sizeof(*uci)); + + eax = 0x00000001; + ecx = 0; + native_cpuid(&eax, &ebx, &ecx, &edx); + csig.sig = eax; + + family = x86_family(eax); + model = x86_model(eax); + + if ((model >= 5) || (family > 6)) { + /* get processor flags from MSR 0x17 */ + native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); + csig.pf = 1 << ((val[1] >> 18) & 7); + } + + csig.rev = intel_get_microcode_revision(); + + uci->cpu_sig = csig; + uci->valid = 1; + + return 0; +} +EXPORT_SYMBOL_GPL(cpu_collect_info_early); + static void early_init_intel(struct cpuinfo_x86 *c) { u64 misc_enable; diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index d28a9f8f3fec..7220327a6b1f 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -45,20 +45,6 @@ static struct microcode_intel *intel_ucode_patch; /* last level cache size per core */ static int llc_size_per_core; -static inline bool cpu_signatures_match(unsigned int s1, unsigned int p1, - unsigned int s2, unsigned int p2) -{ - if (s1 != s2) - return false; - - /* Processor flags are either both 0 ... */ - if (!p1 && !p2) - return true; - - /* ... or they intersect. */ - return p1 & p2; -} - /* * Returns 1 if update has been found, 0 otherwise. */ @@ -342,37 +328,6 @@ scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save) return patch; } -static int collect_cpu_info_early(struct ucode_cpu_info *uci) -{ - unsigned int val[2]; - unsigned int family, model; - struct cpu_signature csig = { 0 }; - unsigned int eax, ebx, ecx, edx; - - memset(uci, 0, sizeof(*uci)); - - eax = 0x00000001; - ecx = 0; - native_cpuid(&eax, &ebx, &ecx, &edx); - csig.sig = eax; - - family = x86_family(eax); - model = x86_model(eax); - - if ((model >= 5) || (family > 6)) { - /* get processor flags from MSR 0x17 */ - native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); - csig.pf = 1 << ((val[1] >> 18) & 7); - } - - csig.rev = intel_get_microcode_revision(); - - uci->cpu_sig = csig; - uci->valid = 1; - - return 0; -} - static void show_saved_mc(void) { #ifdef DEBUG @@ -386,7 +341,7 @@ static void show_saved_mc(void) return; } - collect_cpu_info_early(&uci); + cpu_collect_info_early(&uci); sig = uci.cpu_sig.sig; pf = uci.cpu_sig.pf; @@ -502,7 +457,7 @@ void show_ucode_info_early(void) struct ucode_cpu_info uci; if (delay_ucode_info) { - collect_cpu_info_early(&uci); + cpu_collect_info_early(&uci); print_ucode_info(&uci, current_mc_date); delay_ucode_info = 0; } @@ -604,7 +559,7 @@ int __init save_microcode_in_initrd_intel(void) if (!(cp.data && cp.size)) return 0; - collect_cpu_info_early(&uci); + cpu_collect_info_early(&uci); scan_microcode(cp.data, cp.size, &uci, true); @@ -637,7 +592,7 @@ static struct microcode_intel *__load_ucode_intel(struct ucode_cpu_info *uci) if (!(cp.data && cp.size)) return NULL; - collect_cpu_info_early(uci); + cpu_collect_info_early(uci); return scan_microcode(cp.data, cp.size, uci, false); } @@ -712,7 +667,7 @@ void reload_ucode_intel(void) struct microcode_intel *p; struct ucode_cpu_info uci; - collect_cpu_info_early(&uci); + cpu_collect_info_early(&uci); p = find_patch(&uci); if (!p) -- 2.17.1