Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp115125rwi; Wed, 19 Oct 2022 18:19:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76fAaqkqmxD+wzaqH72WwpiYXi7LWAXFwKFp9WZ02MiacFzsuch1YPB51qJlbm7LNySZha X-Received: by 2002:a17:903:2285:b0:185:44df:d916 with SMTP id b5-20020a170903228500b0018544dfd916mr11327061plh.120.1666228757162; Wed, 19 Oct 2022 18:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666228757; cv=none; d=google.com; s=arc-20160816; b=Jv+c7aM/AoQzWtbNQT+ABY0JHAsQD67cys1LSMBgGPpo80rTIpelbSXBnrtFly+5MK hShzOBpZ56+fhiPyLe7sOOKCrLKBbNPi5bb3eo50pzR8buS/4q2H9ffws8jGjeAC8sTX 46SM0+xa8oHoo7acezKRrQhWaT8TZSTmw7VVw3UwE9A7pU6b59ZIknOt927eLEuj/7ru DJ7i4DPbEfdKR4qsfLSutaOryov2QqF92sRx3ln+FEOqen8uj7RndG6EH0yxmUzuSCa/ GjEtU5GTYd6VD065i4z/wGJbCewlHkWqXFIkqU98eClszUYSNID1cNEPWSYhc5Qy8BYR v/gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=S8Tpplgbg87qo0/g/zAMmb2z5RHSuiV5J2IUDMBNfEc=; b=FlYrNypeWRFpT/YRWeunFTvMF7fYVkeeJTha8fu2dWmJ8/iJ0En0Jqf4MUrilsKW3k tncOwpRTxb74DyKfg4l4EgpkyqeO/emoopR51ckLb4QfGICWosJm+Q+xzYEM9E3mhJ48 Fu0hBZVE3dhebg/6g0DdBjb9iQpu/ZapYfvVMPjWckNref6jgavHCi/R98Ny3PTODJj/ Anx2P73s8zdPCOXKBXG/NuQ9QypYSRFBMqcSGS5tm4g+xdIABp8KhGUT+7YXEgcBvzRY TOzJKsDuhezb9u0hGVF/Vidf0PI0hmz5bz6s5zGowTdSxBqdKkI92uBy4zxyixSTU6X5 QqbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=G0hL1zoR; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020a056a00230c00b00563126613f4si20703146pfh.366.2022.10.19.18.19.04; Wed, 19 Oct 2022 18:19:17 -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=@chromium.org header.s=google header.b=G0hL1zoR; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbiJTBLO (ORCPT + 99 others); Wed, 19 Oct 2022 21:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiJTBLF (ORCPT ); Wed, 19 Oct 2022 21:11:05 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8164A165501 for ; Wed, 19 Oct 2022 18:11:04 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id u71so17851129pgd.2 for ; Wed, 19 Oct 2022 18:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=S8Tpplgbg87qo0/g/zAMmb2z5RHSuiV5J2IUDMBNfEc=; b=G0hL1zoRGGsjihjXU32+8JsjEhOY2MncZzEc20xvMpburVkRNBdPHXW3Q3WqNbr86j n+oXDnwOm+QoLBvITuRWiejRu622H8Gw8M3O/w/I30IjGItXzFVMlKtGYvYxP8hcGC+X 1EQ9kJfImQkOipmNnUODUFe2QuOUU8bqqp31w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S8Tpplgbg87qo0/g/zAMmb2z5RHSuiV5J2IUDMBNfEc=; b=qt99+J9zN7Ip+1CMLSPPDAdnJMiQc64Iw8a8Mbkts3l3XDxsL/2ok3syLeJjlQlkna YeEumltwZSRlpf5yY2bsgAmKMFGSd+Yt/EqZBCYYOBnAjHTFhejsPk50Z9UrzNPQQaeU eVz6vxMhSSesZJ0CBKYtoVXY66r7m+TqOCmsIxSv14/VmKdgAZmK4+gzHqUy9wyD1seA Kk/OM19yt4WewsA7/q0vJW4A2A7dQXyRyePKrBqQJU0XS3VT9+EsHKQLDI25QQFHis4v DTRGeI1rEsfBcrxXJP3/WU4rvBb/DkrujWvzFuYugMEZ/UZug40wOJ/BRQVgFgrA4NIK 0RuA== X-Gm-Message-State: ACrzQf3x1xEvftUsWI2pcaRq4QdjXQtTsxO3i5gfb9CpYQsB6Oj7wcfG 7CS2iggVpomNAXABJ2BxlNfnMw== X-Received: by 2002:a63:54b:0:b0:464:8e6:11e7 with SMTP id 72-20020a63054b000000b0046408e611e7mr9745907pgf.212.1666228263924; Wed, 19 Oct 2022 18:11:03 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:57b7:1f0e:44d1:f252]) by smtp.gmail.com with UTF8SMTPSA id bf1-20020a170902b90100b0017f7d7e95d3sm11330738plb.167.2022.10.19.18.11.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Oct 2022 18:11:03 -0700 (PDT) From: Brian Norris To: Greg Kroah-Hartman Cc: Benson Leung , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, Samuel Holland , Julius Werner , Stephen Boyd , Guenter Roeck , Brian Norris , stable@vger.kernel.org Subject: [PATCH] firmware: coreboot: Register bus in module init Date: Wed, 19 Oct 2022 18:10:53 -0700 Message-Id: <20221019180934.1.If29e167d8a4771b0bf4a39c89c6946ed764817b9@changeid> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 The coreboot_table driver registers a coreboot bus while probing a "coreboot_table" device representing the coreboot table memory region. Probing this device (i.e., registering the bus) is a dependency for the module_init() functions of any driver for this bus (e.g., memconsole-coreboot.c / memconsole_driver_init()). With synchronous probe, this dependency works OK, as the link order in the Makefile ensures coreboot_table_driver_init() (and thus, coreboot_table_probe()) completes before a coreboot device driver tries to add itself to the bus. With asynchronous probe, however, coreboot_table_probe() may race with memconsole_driver_init(), and so we're liable to hit one of these two: 1. coreboot_driver_register() eventually hits "[...] the bus was not initialized.", and the memconsole driver fails to register; or 2. coreboot_driver_register() gets past #1, but still races with bus_register() and hits some other undefined/crashing behavior (e.g., in driver_find() [1]) We can resolve this by registering the bus in our initcall, and only deferring "device" work (scanning the coreboot memory region and creating sub-devices) to probe(). [1] Example failure, using 'driver_async_probe=*' kernel command line: [ 0.114217] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... [ 0.114307] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc1 #63 [ 0.114316] Hardware name: Google Scarlet (DT) ... [ 0.114488] Call trace: [ 0.114494] _raw_spin_lock+0x34/0x60 [ 0.114502] kset_find_obj+0x28/0x84 [ 0.114511] driver_find+0x30/0x50 [ 0.114520] driver_register+0x64/0x10c [ 0.114528] coreboot_driver_register+0x30/0x3c [ 0.114540] memconsole_driver_init+0x24/0x30 [ 0.114550] do_one_initcall+0x154/0x2e0 [ 0.114560] do_initcall_level+0x134/0x160 [ 0.114571] do_initcalls+0x60/0xa0 [ 0.114579] do_basic_setup+0x28/0x34 [ 0.114588] kernel_init_freeable+0xf8/0x150 [ 0.114596] kernel_init+0x2c/0x12c [ 0.114607] ret_from_fork+0x10/0x20 [ 0.114624] Code: 5280002b 1100054a b900092a f9800011 (885ffc01) [ 0.114631] ---[ end trace 0000000000000000 ]--- Fixes: b81e3140e412 ("firmware: coreboot: Make bus registration symmetric") Cc: Signed-off-by: Brian Norris --- Currently, get_maintainers.pl tells me Greg should pick this up. But I CC the chrome-platform list too, since it seems reasonable for Google folks (probably ChromeOS folks are most active here?) to maintain Google/Chrome drivers. Let me know if y'all would like this official, and I'll push out a MAINTAINERS patch. drivers/firmware/google/coreboot_table.c | 37 +++++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c index c52bcaa9def6..9ca21feb9d45 100644 --- a/drivers/firmware/google/coreboot_table.c +++ b/drivers/firmware/google/coreboot_table.c @@ -149,12 +149,8 @@ static int coreboot_table_probe(struct platform_device *pdev) if (!ptr) return -ENOMEM; - ret = bus_register(&coreboot_bus_type); - if (!ret) { - ret = coreboot_table_populate(dev, ptr); - if (ret) - bus_unregister(&coreboot_bus_type); - } + ret = coreboot_table_populate(dev, ptr); + memunmap(ptr); return ret; @@ -169,7 +165,6 @@ static int __cb_dev_unregister(struct device *dev, void *dummy) static int coreboot_table_remove(struct platform_device *pdev) { bus_for_each_dev(&coreboot_bus_type, NULL, NULL, __cb_dev_unregister); - bus_unregister(&coreboot_bus_type); return 0; } @@ -199,6 +194,32 @@ static struct platform_driver coreboot_table_driver = { .of_match_table = of_match_ptr(coreboot_of_match), }, }; -module_platform_driver(coreboot_table_driver); + +static int __init coreboot_table_driver_init(void) +{ + int ret; + + ret = bus_register(&coreboot_bus_type); + if (ret) + return ret; + + ret = platform_driver_register(&coreboot_table_driver); + if (ret) { + bus_unregister(&coreboot_bus_type); + return ret; + } + + return 0; +} + +static void __exit coreboot_table_driver_exit(void) +{ + platform_driver_unregister(&coreboot_table_driver); + bus_unregister(&coreboot_bus_type); +} + +module_init(coreboot_table_driver_init); +module_exit(coreboot_table_driver_exit); + MODULE_AUTHOR("Google, Inc."); MODULE_LICENSE("GPL"); -- 2.38.0.413.g74048e4d9e-goog