From patchwork Wed Nov 2 16:09:00 2022 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: 14327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp63374dyb; Wed, 2 Nov 2022 09:11:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/nZOCAu9J/6jsz/rBLWS7GzlO7h6K32ayGv99KGJrIOd6BzypgrO7mbjCFsss4f+Vw9Uu X-Received: by 2002:a17:903:2303:b0:186:ed93:fc46 with SMTP id d3-20020a170903230300b00186ed93fc46mr24411434plh.172.1667405484773; Wed, 02 Nov 2022 09:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667405484; cv=none; d=google.com; s=arc-20160816; b=TFb2ZpBBj1/1/Q8egpBqsLJtMt3CzkFZ2gUyOaCNCQDC/NC+QEtz+0rcxPsaxXx714 ZKaG6b7OwflOaRJqHvdKXqYmUV+Qs38tdYE1ultZgsFgVFL3LwPzJLrBz8lPjj55mLqG EBO7WvqDY7+wVfDzPbh//7Z89oIshalhrqm7UHyzQOGMtnLSKAVXYis49zWXb/4zey/8 IMUxOu61ZbbcCjXy+gjHqLMF29XyAsiEmK1xJuA3lK10xF4YCnKeqYIXvw9wfvoIC1tl Wh8aoZedz0x8Tl+JOTeni1wFrWvAp+vMV2NGKZ/okraBPqqyY/uV1XfK376CuLvbwLI+ /JbQ== 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=SAxxY47SOfNP0WUkTp6VcHa2VWY1wYWp1foEsG9fWAk=; b=SYpcMpWCi+pzeJAIzFJp4ytQuw0+xgC/m2IlOYyLX1POgBJp2U8u5OAiVGE3Qv5Y9v CLWApmxKnkSlcS6Q/b+ZDhr0zR5st6YqmbYWTbV7yTcXJkt3m7O7qXm7V4VLdXkM+t4p xfBqcHtTzxARwzGpx06YZXZ/obYyvwKqMe99nKm9zQPsuMQqM0/8a+Zhv51hGV91q1Hh PcnIxIX/ZKKi81cBTSWm6j7gj3GwNDbBSDV5hE0uYY7DrrB0qitxXYi49TzW6seSlULU CvLLKpv9YmhgIDiMXJyRrGcYt+lQ9v2c9pyTzZG2952nPuzMT3JUdOFPhaaYA4IDJV0I Hm7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JW893CoR; dkim=neutral (no key) header.i=@linutronix.de header.b=r0Xxrb2e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n3-20020a17090a5a8300b00212e738ac60si2527525pji.84.2022.11.02.09.11.11; Wed, 02 Nov 2022 09:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JW893CoR; dkim=neutral (no key) header.i=@linutronix.de header.b=r0Xxrb2e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbiKBQJN (ORCPT + 99 others); Wed, 2 Nov 2022 12:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231224AbiKBQJE (ORCPT ); Wed, 2 Nov 2022 12:09:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E95552B1AF; Wed, 2 Nov 2022 09:09:02 -0700 (PDT) Date: Wed, 02 Nov 2022 16:09:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667405341; 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=SAxxY47SOfNP0WUkTp6VcHa2VWY1wYWp1foEsG9fWAk=; b=JW893CoRs0pLOvktc+THQ+8Bii9ITNEeTn0T1qJAEbX2+GSirVTFDNpKqnxNdce8TPopu2 ioYCDNNzn8g63VHgwUR3iL4sToLej+TaOpfh34QBohJzFnDiT5AgJhsQEV4Zfv+FZYowrw JnSg/9wQk866kx8c3MPoUnLznE1W5v6a1+JvpYqveF8utvll8qelTe6WtAk3QATM+uw1e0 kwr/J6nSOpWQgM8XxUcIMxdEpEe7hEwG8wJIXpfxATbr1N5ONckiEDnqqIZisfxTnJv5m0 VgMWgsc/7ifP6EXhXgSePneL+im2n7RESW88mIJw1DJL5mzL4eH1dZesNw/CBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667405341; 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=SAxxY47SOfNP0WUkTp6VcHa2VWY1wYWp1foEsG9fWAk=; b=r0Xxrb2etHVxMinpeNO6lziZwPi5UAtfacwOiECFvR46Yw5T4IYemDApxzfz+/7cJVoZ/0 ozZg8RTAc2n1H5Bw== From: "tip-bot2 for Borislav Petkov" 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: Rip out the subsys interface gunk Cc: Borislav Petkov , Ashok Raj , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221028142638.28498-2-bp@alien8.de> References: <20221028142638.28498-2-bp@alien8.de> MIME-Version: 1.0 Message-ID: <166740534039.6127.1049032930807424667.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747942006455493463?= X-GMAIL-MSGID: =?utf-8?q?1748401373755922620?= The following commit has been merged into the x86/microcode branch of tip: Commit-ID: b6f86689d5b740f2cc3ac3a1032c7374b24381cc Gitweb: https://git.kernel.org/tip/b6f86689d5b740f2cc3ac3a1032c7374b24381cc Author: Borislav Petkov AuthorDate: Wed, 19 Oct 2022 18:13:06 +02:00 Committer: Borislav Petkov CommitterDate: Wed, 02 Nov 2022 16:45:46 +01:00 x86/microcode: Rip out the subsys interface gunk This is a left-over from the old days when CPU hotplug wasn't as robust as it is now. Currently, microcode gets loaded early on the CPU init path and there's no need to attempt to load it again, which that subsys interface callback is doing. The only other thing that the subsys interface init path was doing is adding the /sys/devices/system/cpu/cpu*/microcode/ hierarchy. So add a function which gets called on each CPU after all the necessary driver setup has happened. Use schedule_on_each_cpu() which can block because the sysfs creating code does kmem_cache_zalloc() which can block too and the initial version of this where it did that setup in an IPI handler of on_each_cpu() can cause a deadlock of the sort: lock(fs_reclaim); lock(fs_reclaim); as the IPI handler runs in IRQ context. Signed-off-by: Borislav Petkov Reviewed-by: Ashok Raj Link: https://lore.kernel.org/r/20221028142638.28498-2-bp@alien8.de --- arch/x86/kernel/cpu/microcode/core.c | 78 ++++++--------------------- 1 file changed, 20 insertions(+), 58 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 6a41cee..4c222e6 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -601,8 +601,8 @@ static enum ucode_state microcode_resume_cpu(int cpu) static enum ucode_state microcode_init_cpu(int cpu, bool refresh_fw) { - enum ucode_state ustate; struct ucode_cpu_info *uci = ucode_cpu_info + cpu; + enum ucode_state ustate; if (uci->valid) return UCODE_OK; @@ -636,44 +636,6 @@ static enum ucode_state microcode_update_cpu(int cpu) return microcode_init_cpu(cpu, false); } -static int mc_device_add(struct device *dev, struct subsys_interface *sif) -{ - int err, cpu = dev->id; - - if (!cpu_online(cpu)) - return 0; - - pr_debug("CPU%d added\n", cpu); - - err = sysfs_create_group(&dev->kobj, &mc_attr_group); - if (err) - return err; - - if (microcode_init_cpu(cpu, true) == UCODE_ERROR) - return -EINVAL; - - return err; -} - -static void mc_device_remove(struct device *dev, struct subsys_interface *sif) -{ - int cpu = dev->id; - - if (!cpu_online(cpu)) - return; - - pr_debug("CPU%d removed\n", cpu); - microcode_fini_cpu(cpu); - sysfs_remove_group(&dev->kobj, &mc_attr_group); -} - -static struct subsys_interface mc_cpu_interface = { - .name = "microcode", - .subsys = &cpu_subsys, - .add_dev = mc_device_add, - .remove_dev = mc_device_remove, -}; - /** * microcode_bsp_resume - Update boot CPU microcode during resume. */ @@ -713,6 +675,9 @@ static int mc_cpu_down_prep(unsigned int cpu) struct device *dev; dev = get_cpu_device(cpu); + + microcode_fini_cpu(cpu); + /* Suspend is in progress, only remove the interface */ sysfs_remove_group(&dev->kobj, &mc_attr_group); pr_debug("CPU%d removed\n", cpu); @@ -720,6 +685,18 @@ static int mc_cpu_down_prep(unsigned int cpu) return 0; } +static void setup_online_cpu(struct work_struct *work) +{ + int cpu = smp_processor_id(); + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; + + memset(uci, 0, sizeof(*uci)); + + microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig); + + mc_cpu_online(cpu); +} + static struct attribute *cpu_root_microcode_attrs[] = { #ifdef CONFIG_MICROCODE_LATE_LOADING &dev_attr_reload.attr, @@ -755,23 +732,17 @@ static int __init microcode_init(void) if (IS_ERR(microcode_pdev)) return PTR_ERR(microcode_pdev); - cpus_read_lock(); - mutex_lock(µcode_mutex); - error = subsys_interface_register(&mc_cpu_interface); - mutex_unlock(µcode_mutex); - cpus_read_unlock(); - - if (error) - goto out_pdev; - error = sysfs_create_group(&cpu_subsys.dev_root->kobj, &cpu_root_microcode_group); if (error) { pr_err("Error creating microcode group!\n"); - goto out_driver; + goto out_pdev; } + /* Do per-CPU setup */ + schedule_on_each_cpu(setup_online_cpu); + register_syscore_ops(&mc_syscore_ops); cpuhp_setup_state_nocalls(CPUHP_AP_MICROCODE_LOADER, "x86/microcode:starting", mc_cpu_starting, NULL); @@ -782,15 +753,6 @@ static int __init microcode_init(void) return 0; - out_driver: - cpus_read_lock(); - mutex_lock(µcode_mutex); - - subsys_interface_unregister(&mc_cpu_interface); - - mutex_unlock(µcode_mutex); - cpus_read_unlock(); - out_pdev: platform_device_unregister(microcode_pdev); return error;