From patchwork Mon Oct 9 12:29:55 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: 150060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1834011vqo; Mon, 9 Oct 2023 05:32:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqKtf1DW+i+33lk6rbH3qa503webwgtUWvWzYcoIA+rp6OJ7VSMvBo1HMent40e8mCe40j X-Received: by 2002:a05:6a00:cd5:b0:693:4123:1f63 with SMTP id b21-20020a056a000cd500b0069341231f63mr14592170pfv.15.1696854763640; Mon, 09 Oct 2023 05:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854763; cv=none; d=google.com; s=arc-20160816; b=SWlJUIu+sxlzyul8FYou6Nqv519d7qNK4RaMp0X4pYt4A63dQhJA581xbuEb6mKehb zn4H0k8/3sYD/4Mn27Tzv6oHA/eJlzHFTy60yjabnj5eWatuz/JXdb1XXi80xVk3QmoR Q9KIZmmfeWpx8XeCwmmNe++t2ob9SNN4/7ZLpzg+yc4DBAuTOUk32P9EdfpwFH1qM7KE O9CCcxF6xbQBwwJhYgsVqV3fWMYgv5SIfvu0/+dIw6myHIvnwh5RbeVfx2WoSGIkdJcC 771/BTCiJFQmyOHP6R/zIbweanH3BS+f3XMp/VF4Q8lnd1b2j95EOnhhxQ5cXvPHNk+a zoGg== 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=bhfqCckWvnV/j5byneENoHX8ZYayJ0wGsSvFwyrW12Y=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=CU3H0vysbDlY0w9Vih7WymiZ1px43UyVSl90OFAcdstnvpXGrKgedbz9MtHJVjxCK6 Gm1LbqYCFhXvo4bp5MrMH0BBsI+SiCSW0DBoDo1p764TS4sh9Ot1z3ppYRMjJGdbL0dE PhgowkF/MuGFemN6ogx7bhQ2GKkQJDA20rpBqFERB5DM7ZCNH/F75mBUrdByyvA2twUu ok26Z/g+EB8gFOP+mAanFQU4hXTD1+o/xKE2oyERzZlI8Jx1v6TLULHC5APo3cu1/Apg 2JSyoz6G6DMd1z2jO1ZJY8HnoBZST9xWH/cY2bSQVZWjJT91fCMs9jqcgJYy8wSAZdQ5 IMbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zvqGo0u+; dkim=neutral (no key) header.i=@linutronix.de; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cm15-20020a056a020a0f00b00578b9fb24f6si8834255pgb.616.2023.10.09.05.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:32:43 -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=zvqGo0u+; dkim=neutral (no key) header.i=@linutronix.de; 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 EBF0180A8B44; Mon, 9 Oct 2023 05:31:16 -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 S1376459AbjJIMbL (ORCPT + 18 others); Mon, 9 Oct 2023 08:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376479AbjJIMaG (ORCPT ); Mon, 9 Oct 2023 08:30:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E2D0E4; Mon, 9 Oct 2023 05:29:57 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854595; 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=bhfqCckWvnV/j5byneENoHX8ZYayJ0wGsSvFwyrW12Y=; b=zvqGo0u+eKQsDfGt3QyAOyt5dyWHdNA6HzMrL70qwb9bD6mKMumJZ+rXnUAgVCGxBzHQXL dyJh/QWaQ+Py/2+mF9YS/60x20iZxUMBiV8h99R7542aLCvwZu2xTJ2Xd6EG+ZNQQ9EKvL ETYyycbHDRq9wkqdgR+JRklVAx1Zpm0LNuviOaPvZDlxubQLgo+ZGn8q8DENRoh0yS4Wvf SWv+5WclVQyA+kmI+9Lk9pWD47m24faU0BeIxM5Y7C77P7cdoprBocwgmqZwQplQeNgt// sR11V2TvnA0HG9c+bUyMgqhbfa5amBLksBz0mFEMJz7eYTy861ZryjGRLDcJOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854595; 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=bhfqCckWvnV/j5byneENoHX8ZYayJ0wGsSvFwyrW12Y=; b=GaQn+Owa4Ys+BdrKBWkJHNnBNc9wBjyNEkWEKRxKS7hazkurNKDkBZM3cN8QD5ESYAIuHB W55hN8jol8VWWqDQ== 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: <169685459534.3135.9973581340812617063.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 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]); Mon, 09 Oct 2023 05:31:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778682777060467805 X-GMAIL-MSGID: 1779281181018491191 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 6a92484124b21e24aaa04be33fc4938f42d56733 Gitweb: https://git.kernel.org/tip/6a92484124b21e24aaa04be33fc4938f42d56733 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:39 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 02 Oct 2023 18:30:44 +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 1f45f5c..24dd483 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -268,22 +268,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); @@ -291,27 +285,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)