From patchwork Fri Oct 20 11:38: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: 156068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp992809vqb; Fri, 20 Oct 2023 04:43:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw82NKnSNx04hhnbtlT+1p8+ME7jPA/ChHJADT5YsB/nUymldF2D7XSsMrT3C7F0Xl8fbQ X-Received: by 2002:a05:6871:806:b0:1ea:2c8b:e18b with SMTP id q6-20020a056871080600b001ea2c8be18bmr1984155oap.35.1697802182832; Fri, 20 Oct 2023 04:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802182; cv=none; d=google.com; s=arc-20160816; b=kA6BCZdW7vDLv8NsBV7tCVl/5PHDdBCRWjKG5xd/y5sDgtSlIUWL3SERn6+JKM97Gr lx2H2Q6URLRnZXUwE1XjcNNEI9n6kPM1p2d0l0Jp5XYVFpX4Ghao8Djjzv6pmAIW63dg EHIKFAT2LvRj2m0Ros01x5tIbAKOwR3oWi+wxvMiewEpHYJdJXEO2u06k5/+xdJ8i251 VzlG5EaTu4yJv1OMD9h5jbBpBIqEI/g1r0hZHIelzRxzkVN7DiBdoc4asFW3WZ6+xz0v nDmx7xyax4mv6TlmH/4dmbjaNW5O91lo1CsqJ6U8BqPBxiQYD5Iy4fHh9qNk3Z6T7wR9 zc0A== 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=bI6h3ZXrFJlAz85xZf+eWjJqfjcQj5YN3Qw988FOZXE=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=txx41tRu7/m05QB28/Sf953ru6lRykyr0liwLUH+lN1tS9dBGJCQfpli37qoELZ8MN q51kIforddDrQ7d30wUmp7aOVjkoXJTUuJQqt+TXvMF9DnPTHpKLfKUrAdnVGJSOufr9 iNh44cOxlg1EVkoUgpT79PS7ws9IazaUP51mNeQgOFdKpHQqEF7JF0XOXnta07ewNutF sarxoJT4wSHPwOpG9MUkiqANquHyY43tfXu9FjApQ1vJGdGAxXl7/Bf781UOmF8b3GUY 0qupn1PBUjd3JgBqNu3jV/d3yg+n219IVYx8mRix6sLQHV1XX96bt+O4k2JUVachbwJm EE7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YVRAuBSb; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id w186-20020a6382c3000000b00584d3c90592si1776513pgd.411.2023.10.20.04.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:43:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YVRAuBSb; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 2965983AEFE6; Fri, 20 Oct 2023 04:42:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377433AbjJTLkg (ORCPT + 25 others); Fri, 20 Oct 2023 07:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377053AbjJTLkJ (ORCPT ); Fri, 20 Oct 2023 07:40:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A511E2D4F; Fri, 20 Oct 2023 04:38:33 -0700 (PDT) Date: Fri, 20 Oct 2023 11:38:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801882; 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=bI6h3ZXrFJlAz85xZf+eWjJqfjcQj5YN3Qw988FOZXE=; b=YVRAuBSbGwFifToF/lRDFUoI3a0y6NLpdG43fGffsitoFetiFxVioghoMjeFOTLhLe4oJs hBpwoGIodbtmUfhN7DSvgBvm+0UxuKgwJ13oNR6BI9J7WJOHX23f3dqQy1URskhLP7A/H2 x0aTezzF8gLOX4gcOIVNBJwJfqGp04WYX7+6tzwUMwx4mAwhSuwY3RT5mVwObNvv88APlI AULdtYYDcgMZirdpYVhpp74HoRLPcxhCD3qN1XZ13FU1aePs6zkcSunmMmjS2x8Kcss3Ju yivYsV6oqQEpmDO6jKQ3TdGyNs+ROzuZG9wsu4R2cGEkYRV7U3oUl+0+ddK9fQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801882; 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=bI6h3ZXrFJlAz85xZf+eWjJqfjcQj5YN3Qw988FOZXE=; b=rCGaZU613bEwO0VPkOGee2cFEIbhg/jZRKNeGpEmfRCtgd+7JTwN8U1GDPOIa2OShhDhvz Wo7uihWhedF4URAw== 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/intel: Simplify scan_microcode() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115902.271940980@linutronix.de> References: <20231002115902.271940980@linutronix.de> MIME-Version: 1.0 Message-ID: <169780188168.3135.16642949444992662278.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:42:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778682777060467805 X-GMAIL-MSGID: 1780274621586128173 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: b0f0bf5eef5fac6ba30b7cac15ca4cb01f8a6ca9 Gitweb: https://git.kernel.org/tip/b0f0bf5eef5fac6ba30b7cac15ca4cb01f8a6ca9 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:39 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 12:32:40 +02:00 x86/microcode/intel: Simplify scan_microcode() Make it readable and comprehensible. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115902.271940980@linutronix.de --- arch/x86/kernel/cpu/microcode/intel.c | 28 ++++++-------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index 03a55bf..26f759b 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -266,22 +266,16 @@ static void save_microcode_patch(void *data, unsigned int size) intel_ucode_patch = (struct microcode_intel *)p; } -/* - * Get microcode matching with BSP's model. Only CPUs with the same model as - * BSP can stay in the platform. - */ -static struct microcode_intel * -scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save) +/* Scan CPIO for microcode matching the boot CPU's family, model, stepping */ +static struct microcode_intel *scan_microcode(void *data, size_t size, + struct ucode_cpu_info *uci, bool save) { struct microcode_header_intel *mc_header; struct microcode_intel *patch = NULL; u32 cur_rev = uci->cpu_sig.rev; unsigned int mc_size; - while (size) { - if (size < sizeof(struct microcode_header_intel)) - break; - + for (; size >= sizeof(struct microcode_header_intel); size -= mc_size, data += mc_size) { mc_header = (struct microcode_header_intel *)data; mc_size = get_totalsize(mc_header); @@ -289,27 +283,19 @@ scan_microcode(void *data, size_t size, struct ucode_cpu_info *uci, bool save) intel_microcode_sanity_check(data, false, MC_HEADER_TYPE_MICROCODE) < 0) break; - size -= mc_size; - - if (!intel_find_matching_signature(data, uci->cpu_sig.sig, - uci->cpu_sig.pf)) { - data += mc_size; + if (!intel_find_matching_signature(data, uci->cpu_sig.sig, uci->cpu_sig.pf)) continue; - } /* BSP scan: Check whether there is newer microcode */ if (!save && cur_rev >= mc_header->rev) - goto next; + continue; /* Save scan: Check whether there is newer or matching microcode */ if (save && cur_rev != mc_header->rev) - goto next; + continue; patch = data; cur_rev = mc_header->rev; - -next: - data += mc_size; } if (size)