Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp273912rwn; Thu, 8 Sep 2022 01:05:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+4X3pyTaa/yDgjfRZ43o0EzDaavnAyMFvzSyPBJj1qXQYSWK23KEd7luq4eaUeKYvNxFc X-Received: by 2002:a17:907:6d03:b0:741:9b9d:ad8b with SMTP id sa3-20020a1709076d0300b007419b9dad8bmr5150417ejc.197.1662624343413; Thu, 08 Sep 2022 01:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662624343; cv=none; d=google.com; s=arc-20160816; b=Z7gWeY3is2rqf6Hx/xJAX31rtbNK9Ki4BuXdo+buMhkbR+DCCyX7oiL2ojfnC1zVUX vMIXtc52IaSMvi79nXUemGimwhTDL28Ygs76rClAIaVOzVeCQo2dRuLKUg/LtbLLwY/e OWo8UAFCVR/Jzn5YP6SEsrmgJfGse5KaTgbnmeFFdl8U2ePuD1klUQYRMXzcrBWFxLhe F2e74Izo7MpwPPp4mbNdSsTeLudKRZQoDGTePNJZstqcJb/ipgBFSFRPmMNkCIiQ53w9 FwEBIqhw0bRlqcu0t3oqAk52kLCeuMx8e7G0P6zKHc15vHFXaNaP5WiAk37oMkbQkxiK 8bUA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=R8zeBI33JQE161cSzuZ1/ZAK1yvWGkUNXkMuzy1AVZQ=; b=qgqQMs7dGxEcxDyeZyI4bLX4QHypyfl774lEqXNeFZ17V5jkiDWsnZ3PIs31qV/ySO 5ewTMIDoW6jjPDQgFGntgH2EwCztvy5GKYKx5Yv+1aRCpaCsvesTaPW3KLXZGOQ4YjCN z9NhgoeEmE3pcv2Z7conUcePYXhM2GJ2HsWKzqB9qlKbXgvuah+y8/1ZgcyNWVH2L+Ax /6b98c78BvuDQZF/OvUV45wVCwfOPi+cd9NdizVxxhZsfRF1NPfZOvb/vAC9BkH+9iSD EgHvfUI8Rh4MUSKk5RqIoazCFT3WgqBfGImFXHXz3RQR/BMmQgHzWBBpSxrgjyHD73/v tnqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hartkopp.net header.s=strato-dkim-0002 header.b=oET3Fu1n; 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=REJECT sp=REJECT dis=NONE) header.from=hartkopp.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb25-20020a1709077e9900b0072b7fa15683si1589815ejc.312.2022.09.08.01.05.18; Thu, 08 Sep 2022 01:05:43 -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=@hartkopp.net header.s=strato-dkim-0002 header.b=oET3Fu1n; 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=REJECT sp=REJECT dis=NONE) header.from=hartkopp.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbiIHHUu (ORCPT + 99 others); Thu, 8 Sep 2022 03:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiIHHUt (ORCPT ); Thu, 8 Sep 2022 03:20:49 -0400 X-Greylist: delayed 180 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 08 Sep 2022 00:20:47 PDT Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C547CA570D; Thu, 8 Sep 2022 00:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1662621464; s=strato-dkim-0002; d=hartkopp.net; h=In-Reply-To:References:Cc:To:From:Subject:Date:Message-ID:Cc:Date: From:Subject:Sender; bh=R8zeBI33JQE161cSzuZ1/ZAK1yvWGkUNXkMuzy1AVZQ=; b=oET3Fu1nJulbWnwUxXLWrdG0OdMl5Si0JnBWlQQlc/g2XThlRQ7Ur+nqF+1l1SPImL kDn2DFeZ65IBrhwucaWA5ANVUbUfO+Um9rTgfly+cBL5vPmQsqWUl+YDGZGTP0GVJuxA ysb+9i4cZOrrMMVmBpVm+/g86J/B2DX+hc5wWdMerU5DtxiepjNlE7QiqsN2rHh2iwmA ogX4/FLnwBp4zdyJHiO+UAxjMRIEBRIasVE5cGFY0BOmppyyCMYywi488HSotaPp65n9 1tgaEzDSLGMdjrq2qv0Ty85ikHRCyxGXjSTo2WvFVl/cXfmJcs3PLu48+LEebAvJ7ldr Idjg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjG14FZxedJy6qgO1qCHSa1GLptZHusx3hdIrpKytJSr63tDxrw==" X-RZG-CLASS-ID: mo00 Received: from [IPV6:2a00:6020:1cfd:d100::b82] by smtp.strato.de (RZmta 48.0.2 AUTH) with ESMTPSA id wfa541y887Hi6Fq (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 8 Sep 2022 09:17:44 +0200 (CEST) Message-ID: Date: Thu, 8 Sep 2022 09:17:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH 1/2] can: bcm: registration process optimization in bcm_module_init() Content-Language: en-US From: Oliver Hartkopp To: Ziyang Xuan , mkl@pengutronix.de, edumazet@google.com, kuba@kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org References: <823cff0ebec33fa9389eeaf8b8ded3217c32cb38.1662606045.git.william.xuanziyang@huawei.com> <381dd961-f786-2400-0977-9639c3f7006e@hartkopp.net> In-Reply-To: <381dd961-f786-2400-0977-9639c3f7006e@hartkopp.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Just another reference which make it clear that the reordering of function calls in your patch is likely not correct: https://elixir.bootlin.com/linux/v5.19.7/source/net/packet/af_packet.c#L4734 static int __init packet_init(void) { int rc; rc = proto_register(&packet_proto, 0); if (rc) goto out; rc = sock_register(&packet_family_ops); if (rc) goto out_proto; rc = register_pernet_subsys(&packet_net_ops); if (rc) goto out_sock; rc = register_netdevice_notifier(&packet_netdev_notifier); if (rc) goto out_pernet; return 0; out_pernet: unregister_pernet_subsys(&packet_net_ops); out_sock: sock_unregister(PF_PACKET); out_proto: proto_unregister(&packet_proto); out: return rc; } On 08.09.22 09:10, Oliver Hartkopp wrote: > > > On 08.09.22 05:04, Ziyang Xuan wrote: >> Now, register_netdevice_notifier() and register_pernet_subsys() are both >> after can_proto_register(). It can create CAN_BCM socket and process >> socket >> once can_proto_register() successfully, so it is possible missing >> notifier >> event or proc node creation because notifier or bcm proc directory is not >> registered or created yet. Although this is a low probability >> scenario, it >> is not impossible. >> >> Move register_pernet_subsys() and register_netdevice_notifier() to the >> front of can_proto_register(). In addition, register_pernet_subsys() and >> register_netdevice_notifier() may fail, check their results are >> necessary. >> >> Signed-off-by: Ziyang Xuan >> --- >>   net/can/bcm.c | 18 +++++++++++++++--- >>   1 file changed, 15 insertions(+), 3 deletions(-) >> >> diff --git a/net/can/bcm.c b/net/can/bcm.c >> index e60161bec850..e2783156bfd1 100644 >> --- a/net/can/bcm.c >> +++ b/net/can/bcm.c >> @@ -1744,15 +1744,27 @@ static int __init bcm_module_init(void) >>       pr_info("can: broadcast manager protocol\n"); >> +    err = register_pernet_subsys(&canbcm_pernet_ops); >> +    if (err) >> +        return err; > > Analogue to your patch for the CAN_RAW socket here (which has been > applied to can-next right now) ... > > https://lore.kernel.org/linux-can/7af9401f0d2d9fed36c1667b5ac9b8df8f8b87ee.1661584485.git.william.xuanziyang@huawei.com/T/#u > > > ... I'm not sure whether this is the right sequence to acquire the > different resources here. > > E.g. in ipsec_pfkey_init() in af_key.c > > https://elixir.bootlin.com/linux/v5.19.7/source/net/key/af_key.c#L3887 > > proto_register() is executed before register_pernet_subsys() > > Which seems to be more natural to me. > > Best regards, > Oliver > >> + >> +    err = register_netdevice_notifier(&canbcm_notifier); >> +    if (err) >> +        goto register_notifier_failed; >> + >>       err = can_proto_register(&bcm_can_proto); >>       if (err < 0) { >>           printk(KERN_ERR "can: registration of bcm protocol failed\n"); >> -        return err; >> +        goto register_proto_failed; >>       } >> -    register_pernet_subsys(&canbcm_pernet_ops); >> -    register_netdevice_notifier(&canbcm_notifier); >>       return 0; >> + >> +register_proto_failed: >> +    unregister_netdevice_notifier(&canbcm_notifier); >> +register_notifier_failed: >> +    unregister_pernet_subsys(&canbcm_pernet_ops); >> +    return err; >>   } >>   static void __exit bcm_module_exit(void)