Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp906985rwb; Fri, 23 Sep 2022 05:55:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5h2tTr6Oco8NOpF2rNcV8+niUVYd/Fe+n9rOjUvEqufbfHqEoseioacAhDqyDfL20Oi9Im X-Received: by 2002:a05:6402:f10:b0:455:224a:c339 with SMTP id i16-20020a0564020f1000b00455224ac339mr7881651eda.307.1663937734744; Fri, 23 Sep 2022 05:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663937734; cv=none; d=google.com; s=arc-20160816; b=0mUc0A9vAZFlILaK+vhrNatdaF9ApPb0LlfPUfDGDX4nU+VD64S4yDuhqYK4jNge8f FauXh73nBzF2b8ngB55J5QZk+3YIvyEmqEBUmDfYa1pfmdDjWKoktwSSJQ6ya03NoxXO 6waKMyl6/4mH1CRV71NP3Dm/D5GzboQtWfy8xA0jeOu0nuYIeQ1muuVOTVknOhnsywgd 7HTrq1d5a4xSAhtvI3wZJJ1/M9ESKJKDxCdHJGFHf+BUD/xSHcNMsyySfHoKnQvMl33t GOs7u2/ZYOJ2qRO8ZiTVjKbMMagHyNwLe1DNbUVK7vVQX3SwAoUH6/Hi3Plkw+y7lRgq nxBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=1B0MXTvecLOdTETsSk3xRVIacqqyWj8k3/YtgxurHyI=; b=d/0H8QvjmBs4L3KKrmCpytugdN/JScLGK+5RIMYxzI2v2KjItOorOG6iwCBgcTT4za Hi4vD3wHFcrFDJ3jGefCo9Fip5BRiT0zgbTutpwkDFjOJIgNAdowGyvPJYy6epXTGTRa E0+t2/AgVS1udGJ3YGFyC9Om4Vq4Na0UeN6BMU2q++X+06bCoBzKW1sQROK1IBcQX8o3 vgodcTRSqdz87tFgiZL15jXl6rmcCZz2lEzyBsRA7gkssCHEFLetAsCTwgC8E619QTJS 7KU6c44MaMGPYvjnWLkIGJE9JTRign1RtkwFeNMlkG70YHhhOQ+yRKP4J6MWmrAd8E0q LGZQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he36-20020a1709073da400b00734b2821879si8518171ejc.898.2022.09.23.05.55.08; Fri, 23 Sep 2022 05:55:34 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232152AbiIWMS3 (ORCPT + 99 others); Fri, 23 Sep 2022 08:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbiIWMQV (ORCPT ); Fri, 23 Sep 2022 08:16:21 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2808C2BB3A; Fri, 23 Sep 2022 05:09:50 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D675139F; Fri, 23 Sep 2022 05:09:56 -0700 (PDT) Received: from [10.57.65.170] (unknown [10.57.65.170]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6A84D3F73D; Fri, 23 Sep 2022 05:09:48 -0700 (PDT) Message-ID: Date: Fri, 23 Sep 2022 13:09:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] lib/sg_pool: change module_init(sg_pool_init) to subsys_initcall Content-Language: en-GB To: Masahiro Yamada , linux-kernel@vger.kernel.org, Christoph Hellwig , Marek Szyprowski , iommu@lists.linux.dev Cc: Guenter Roeck , linux-kbuild@vger.kernel.org, "Martin K. Petersen" , Ming Lin , Sagi Grimberg References: <20220923113835.21544-1-masahiroy@kernel.org> From: Robin Murphy In-Reply-To: <20220923113835.21544-1-masahiroy@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 On 2022-09-23 12:38, Masahiro Yamada wrote: > sg_alloc_table_chained() is called by several drivers, but if it is > called before sg_pool_init(), it results in a NULL pointer dereference > in sg_pool_alloc(). > > Since commit 9b1d6c895002 ("lib: scatterlist: move SG pool code from > SCSI driver to lib/sg_pool.c"), we rely on module_init(sg_pool_init) > is invoked before other module_init calls but this assumption is > fragile. > > I slightly changed the link order while Kbuild refactoring Kbuild, > then uncovered this issue. I should keep the current link order, but > depending on a specific call order among module_init is so fragine. > > We usually define the init order by specifying *_initcall correctly, > or delay the driver probing by returning -EPROBE_DEFER. > > Change module_initcall() to subsys_initcall(), and also delete the > pointless module_exit() because lib/sg_pool.c is always compiled as > built-in. (CONFIG_SG_POOL is bool) Makes sense to me. Short of having some cool-but-impractically-complex system to derive a dependency graph from the config and compute an initcall order from that, initialising helper library code at an earlier step than drivers certainly seems like the next-best option, and subsys doesn't seem inappropriate for the nature of this code. FWIW, Reviewed-by: Robin Murphy > Link: https://lore.kernel.org/all/20220921043946.GA1355561@roeck-us.net/ > Link: https://lore.kernel.org/all/8e70837d-d859-dfb2-bf7f-83f8b31467bc@samsung.com/ > Fixes: 9b1d6c895002 ("lib: scatterlist: move SG pool code from SCSI driver to lib/sg_pool.c") > Reported-by: Guenter Roeck > Reported-by: Marek Szyprowski > Signed-off-by: Masahiro Yamada > --- > > I am sending this to DMA subsystem because I did not find > a corresponding one for lib/sg_pool.c > > lib/sg_pool.c | 16 ++-------------- > 1 file changed, 2 insertions(+), 14 deletions(-) > > diff --git a/lib/sg_pool.c b/lib/sg_pool.c > index a0b1a52cd6f7..9bfe60ca3f37 100644 > --- a/lib/sg_pool.c > +++ b/lib/sg_pool.c > @@ -1,5 +1,5 @@ > // SPDX-License-Identifier: GPL-2.0-only > -#include > +#include > #include > #include > #include > @@ -177,16 +177,4 @@ static __init int sg_pool_init(void) > return -ENOMEM; > } > > -static __exit void sg_pool_exit(void) > -{ > - int i; > - > - for (i = 0; i < SG_MEMPOOL_NR; i++) { > - struct sg_pool *sgp = sg_pools + i; > - mempool_destroy(sgp->pool); > - kmem_cache_destroy(sgp->slab); > - } > -} > - > -module_init(sg_pool_init); > -module_exit(sg_pool_exit); > +subsys_initcall(sg_pool_init);