Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2D74C636CC for ; Tue, 31 Jan 2023 11:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231611AbjAaLu4 (ORCPT ); Tue, 31 Jan 2023 06:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbjAaLuy (ORCPT ); Tue, 31 Jan 2023 06:50:54 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65619101 for ; Tue, 31 Jan 2023 03:50:51 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 824D71EC03B3; Tue, 31 Jan 2023 12:50:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1675165849; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=OKfnuTrZYSVnVFbkRYRHSmoyog1UQGkLSVDafNAA0BA=; b=n7G6LnXgTx+iTXTz5YqUpYnFaD5qwD4Z198beewlTnKp51c54KFWvGmma3fEwijnJlwJGa K9Z30FcSQ69BjasiKkuE+VvO6vUiZ2zHjQ0uF1fBqKJg3X8MQWcpjnsc69CWPJ1TE4/4Qj fnJvz8QMAf/Ceradj3YTVxQ0R4l08aQ= Date: Tue, 31 Jan 2023 12:50:44 +0100 From: Borislav Petkov To: Ashok Raj Cc: Thomas Gleixner , LKML , x86 , Ingo Molnar , Tony Luck , Dave Hansen , Alison Schofield , Reinette Chatre , Tom Lendacky , Stefan Talpalaru , David Woodhouse , Benjamin Herrenschmidt , Jonathan Corbet , "Rafael J . Wysocki" , Peter Zilstra , Andy Lutomirski , Andrew Cooper , Boris Ostrovsky , Martin Pohlack Subject: Re: [Patch v3 Part2 1/9] x86/microcode: Taint kernel only if microcode loading was successful Message-ID: References: <20230130213955.6046-1-ashok.raj@intel.com> <20230130213955.6046-2-ashok.raj@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230130213955.6046-2-ashok.raj@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 30, 2023 at 01:39:47PM -0800, Ashok Raj wrote: > arch/x86/kernel/cpu/microcode/core.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) Why all this hoopla and unrelated changes? Why don't you simply hoist the call to ->request_microcode_fw outside of the locked region as it doesn't have to be there and then do the usual pattern? --- diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 14a2280fdcd2..23f4f22df581 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -481,28 +481,28 @@ static ssize_t reload_store(struct device *dev, if (val != 1) return size; + tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev); + if (tmp_ret != UCODE_NEW) + return ret; + cpus_read_lock(); ret = check_online_cpus(); if (ret) - goto put; - - tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev); - if (tmp_ret != UCODE_NEW) - goto put; + goto unlock; mutex_lock(µcode_mutex); ret = microcode_reload_late(); mutex_unlock(µcode_mutex); -put: - cpus_read_unlock(); - if (ret == 0) ret = size; add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); +unlock: + cpus_read_unlock(); + return ret; } -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette