Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp207967rdg; Tue, 10 Oct 2023 08:09:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbIJ2GG7oYgxYLk5f2PnIDj+wPet9eFY3BE6yNColdwQssQCjheVNwVwNMPwYonlgQnu+Q X-Received: by 2002:a05:6a21:9986:b0:160:cf09:8014 with SMTP id ve6-20020a056a21998600b00160cf098014mr17325465pzb.56.1696950570140; Tue, 10 Oct 2023 08:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696950570; cv=none; d=google.com; s=arc-20160816; b=UkvqxDB1Un+z58Tqyd/7A3d4mDN74BGOSxIS1IIHQrHVE6j61ZwjNmf9cJbdSkmDsd gcja7rsG/qkddv/Q0OgiMwgqloYel7JOM395VvdjLBQyWib6Pwr7NGAu5kEy8wQ/AV3U fVD3y4+qirOL7U604DdYPlFO4XnLM06pesrH4pUKmnrtGFdaxRkVZ+r564EHLECGBu9T jMUtDBsSPga8Y383fZrS7+4cFwM0S6bRZme77/en9Igtb34Qna86NpJj9DcS6L3dVdTU cyLNXf7w6EiwB/MFTNuxznSMceoxejWd3+TQgFPUR0gIytWi2d3Qh8ZWkbfLdKZiKZ0W 3dXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=g/Yygr9A2Il7UvnXxciW5CWUkAO8Yu2F0f5qpSzvguA=; fh=8iy+GLBXZdpcs/hIddJ7mbUapYjefwP9Gb111pAzFms=; b=cf3+rt7KlprKy90Xx5CBIsVCYbLcqy5d2ao79Nhbj1EeDFT64K16YlA5tctTwTrgb6 j70J7NoNYRcyHe7ZeW/zyfXhKHcNvQVrW0RQ92ue1t7kvmCkcAmLtZOZJVtsE/MxaNDb TL9bldQq4AGSHAxTvZJCDqbS6aZeVJ7xmKsMu0uubwgiA2gg2GgdIS5fdnpQRZ97pgp0 DJ00YPXIgV0hInhit9fD5+Um0phiD0CUF3Hsj0hfGRch04GIA0yEvAHmh+yBbey9el62 N71OcONz+334WqPU/1CA48lazXFG045hEORCk2EZwdnRr8hqbafl9XyWottZZ5eSaesS KZjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=144ei3Nn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h1-20020a636c01000000b0058556a636dbsi11558172pgc.434.2023.10.10.08.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 08:09:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=144ei3Nn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8C6FC8040EB0; Tue, 10 Oct 2023 08:09:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233404AbjJJPI5 (ORCPT + 99 others); Tue, 10 Oct 2023 11:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbjJJPIv (ORCPT ); Tue, 10 Oct 2023 11:08:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 643FCB8 for ; Tue, 10 Oct 2023 08:08:46 -0700 (PDT) Message-ID: <20231010150702.551141238@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696950524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=g/Yygr9A2Il7UvnXxciW5CWUkAO8Yu2F0f5qpSzvguA=; b=144ei3NnW+bCXOx31fsFaFPjODLcJ4BuZdguAbxZW8FQayQc/LZ65jfFRGFxy9LSHIJnrM BFo+VFyKc1EkoNbJd7wIk8cAkw93McVCL9JOqnXwSbjrZcI2prCs6fb/4hi4kiXY55IAeP QS5MhbJA/3SW9UOyxP44jFQpMoIQmI39ZdfT2F3xQrPEDAeaECqfQGRdR5wBDOd6lX6rlN iDSgal6RFT9Oyyw0z4G7PgIQ2idJRBZ4ZTYEBKtcc/s1I9pma+SASf9ZZlGVFRjJj6pJkq q/0vESVJ6N3jTrC1iRXCbnp8zjd+56hFP44f5YLtVC2fpmguHFllgpakwWFEvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696950524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=g/Yygr9A2Il7UvnXxciW5CWUkAO8Yu2F0f5qpSzvguA=; b=XkO1cBpyl7r/ik0f1fyWT5d2N0ZgKCx1IcXv18nXfhCEIR4nrDbwDs4gRdkcdMMSz1BVYS DDs0KgiruzBzwfCQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov Subject: [patch 3/5] x86/microcode/amd: Cache builtin/initrd microcode early References: <20231010145130.987300357@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 10 Oct 2023 17:08:44 +0200 (CEST) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 08:09:03 -0700 (PDT) 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 --- arch/x86/kernel/cpu/microcode/amd.c | 8 +++++++- arch/x86/kernel/cpu/microcode/core.c | 20 ++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) --- 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 c 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( return 0; } +early_initcall(save_microcode_in_initrd); /* * a small, trivial cache of per-family ucode patches --- 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);