From patchwork Wed Oct 11 09:01:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 151223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp394987vqb; Wed, 11 Oct 2023 02:01:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGberyXKQQGaGXeMg4lqr7xp4jSEZF8WOjFaBgR00QuVUg8rE+Jz6PxFIm8h+dameOHgls2 X-Received: by 2002:a92:d14a:0:b0:349:983c:4940 with SMTP id t10-20020a92d14a000000b00349983c4940mr21066712ilg.1.1697014907138; Wed, 11 Oct 2023 02:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697014907; cv=none; d=google.com; s=arc-20160816; b=EwS9HKbe81fhvutBdYAVpeYFNx222eBkWuS7mK0jezKiVNL6Kv7GeMuqtpT7Aj4Ndo vpKuKmm7CRbIs/4od8B7xS+CHbo6BH2awJ/dKfSKiFq9DP6FtfxE8ZkPobMaKuio830i cAk6KApoauRDJF9oSKjZy01uogqevlkLqAUNxgyLnWwTr0mmozjSskQO/2rjl9RW735x oZ2DuguWJ0M+HYUOKGKi7XKhAyrIujeLJyDC58+tlLBefqCjKcvUa/bCRopmWiFMyVem stYUxnLjpFgygghVsvJ4Il+X+zigeB1jlcNbYL95wS1/uPthss//X5RRKdmMimRuje8b trtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=dxm8OCayxRKnDHzPNxT9AUCGMnByDbKkikAbJCfl4H8=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=lUR/9b/m8hqrF19/Rr8Ae9cK7PqiwkM7+fttv2DOk8uHZuKVpp7prxZmRk0GVSpEnh cLmlhmEvCmAClk0Ewe3rmYlDwfrCG9KrRWl57sFvA7Gpb/WNFSD1JKxArk8D92v4H5Rn jXMcbRA25FUS17Sms/qBfYtRqBthNh9wbc3XOJ+1qAmpSPRddiLwtNItMdecBI0X3VvJ aTp9h6v0AVkqrSR1fta1phVtQgxbdULgps4+7BppXId/EwpxYuWQV+signdhpLUi4B1M rQnBP5njbVn3VErSVEWFDACvqGpPA3rQnOQl3i6zZqZld7G+pE9dEUF6gifq3xFaHtSZ 4YzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vBbRQzFS; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id z14-20020a63190e000000b0057828b85afdsi13544837pgl.795.2023.10.11.02.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 02:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=vBbRQzFS; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3BF12822CB28; Wed, 11 Oct 2023 02:01:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345935AbjJKJBP (ORCPT + 19 others); Wed, 11 Oct 2023 05:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345801AbjJKJBG (ORCPT ); Wed, 11 Oct 2023 05:01:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36AE0A7; Wed, 11 Oct 2023 02:01:03 -0700 (PDT) Date: Wed, 11 Oct 2023 09:01:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697014861; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dxm8OCayxRKnDHzPNxT9AUCGMnByDbKkikAbJCfl4H8=; b=vBbRQzFSDrTbsqgm2ZuD67z1QxO9YIhMhNogE7tl56+n3jYCgQy5it2KBNPttV3G37v63K 8CUQR7Uptdy1fEY7r9HjbcP1oI1uulKlCEDFwZYVxpFzx3qHduXmOFfxYtKY1oGRuOSOoP vV4emBsOMCd0xTzevts4jjNy6LhVMkSZ8puNL23aK8Rfg9g5lPYk6xJGASKGnhAsw1/SPR POh+VSVkuZBf5EM9JgdazGITtwjevPcnf9lyDmOV+rLjVt875nP8gIbMEK0oDqnlVdfSHi VDqcxbgPbRAgmFDdD8SaVdxx6Ilti8qr3UFacFE+NegyMO1yXmuyqORYVhHWYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697014861; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dxm8OCayxRKnDHzPNxT9AUCGMnByDbKkikAbJCfl4H8=; b=3yaNYAbPixjvnw2TcVGv4m3U/6qxS7ZCSkO3SaACPxznYjNS1L8BY9P0AX9bZZ9zpG7nLq cF2kXaAEYidZqlDw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/microcode/amd: Cache builtin/initrd microcode early Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231010150702.551141238@linutronix.de> References: <20231010150702.551141238@linutronix.de> MIME-Version: 1.0 Message-ID: <169701486116.3135.15017272680281918553.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 02:01:38 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779381622239991736 X-GMAIL-MSGID: 1779449103437556337 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 924acbaab3d99de9b141568a7bb2fc0bb553c116 Gitweb: https://git.kernel.org/tip/924acbaab3d99de9b141568a7bb2fc0bb553c116 Author: Thomas Gleixner AuthorDate: Tue, 10 Oct 2023 17:08:44 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 10 Oct 2023 19:48:59 +02:00 x86/microcode/amd: Cache builtin/initrd microcode early There is no reason to scan builtin/initrd microcode on each AP. Cache the builtin/initrd microcode in an early initcall so that the early AP loader can utilize the cache. The existing fs initcall which invoked save_microcode_in_initrd_amd() is still required to maintain the initrd_gone flag. Rename it accordingly. This will be removed once the AP loader code is converted to use the cache. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231010150702.551141238@linutronix.de --- arch/x86/kernel/cpu/microcode/amd.c | 8 +++++++- arch/x86/kernel/cpu/microcode/core.c | 20 ++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 046b3a6..6a1495a 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -527,12 +527,17 @@ void load_ucode_amd_early(unsigned int cpuid_1_eax) static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t size); -int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax) +static int __init save_microcode_in_initrd(void) { + unsigned int cpuid_1_eax = native_cpuid_eax(1); + struct cpuinfo_x86 *c = &boot_cpu_data; struct cont_desc desc = { 0 }; enum ucode_state ret; struct cpio_data cp; + if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) + return 0; + find_blobs_in_containers(cpuid_1_eax, &cp); if (!(cp.data && cp.size)) return -EINVAL; @@ -549,6 +554,7 @@ int __init save_microcode_in_initrd_amd(unsigned int cpuid_1_eax) return 0; } +early_initcall(save_microcode_in_initrd); /* * a small, trivial cache of per-family ucode patches diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 591032b..b71bac0 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -185,24 +185,13 @@ void load_ucode_ap(void) } } -static int __init save_microcode_in_initrd(void) +/* Temporary workaround until find_microcode_in_initrd() is __init */ +static int __init mark_initrd_gone(void) { - struct cpuinfo_x86 *c = &boot_cpu_data; - int ret = -EINVAL; - - switch (c->x86_vendor) { - case X86_VENDOR_AMD: - if (c->x86 >= 0x10) - ret = save_microcode_in_initrd_amd(cpuid_eax(1)); - break; - default: - break; - } - initrd_gone = true; - - return ret; + return 0; } +fs_initcall(mark_initrd_gone); struct cpio_data find_microcode_in_initrd(const char *path) { @@ -895,5 +884,4 @@ static int __init microcode_init(void) return error; } -fs_initcall(save_microcode_in_initrd); late_initcall(microcode_init);