From: "Ziyang Xuan (William)" <william.xuanziyang@huawei.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>
Cc: <edumazet@google.com>, <kuba@kernel.org>,
<linux-can@vger.kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] can: bcm: registration process optimization in bcm_module_init()
Date: Wed, 14 Sep 2022 14:42:39 +0800 [thread overview]
Message-ID: <dbf68897-c719-db79-b856-792bf8fbf533@huawei.com> (raw)
In-Reply-To: <4791cc31-db17-7720-4a86-f83e7bf0918d@hartkopp.net>
>
>
> On 12.09.22 14:00, Marc Kleine-Budde wrote:
>> On 09.09.2022 17:04:06, Oliver Hartkopp wrote:
>>>
>>>
>>> On 09.09.22 05:58, Ziyang Xuan (William) wrote:
>>>>>
>>>>>
>>>>> On 9/8/22 13:14, Ziyang Xuan (William) wrote:
>>>>>>> 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;
>>>>>>> }
>>>>>>>
>>>
>>>> Yes,all these socket operations need time, most likely, register_netdevice_notifier() and register_pernet_subsys() had been done.
>>>> But it maybe not for some reasons, for example, cpu# that runs {raw,bcm}_module_init() is stuck temporary,
>>>> or pernet_ops_rwsem lock competition in register_netdevice_notifier() and register_pernet_subsys().
>>>>
>>>> If the condition which I pointed happens, I think my solution can solve.
>>>>
>>>
>>> No, I don't think so.
>>>
>>> We need to maintain the exact order which is depicted in the af_packet.c
>>> code from above as the notifier call references the sock pointer.
>>
>> The notifier calls bcm_notifier() first, which will loop over the
>> bcm_notifier_list. The list is empty if there are no sockets open, yet.
>> So from my point of view this change looks fine.
>>
>> IMHO it's better to make a series where all these notifiers are moved in
>> front of the respective socket proto_register().
>
> Notifiers and/or pernet_subsys ?
>
> But yes, that would be better to have a clean consistent sequence in all these cases.
>
> Would this affect af_packet.c then too?
Yes.
When we create a sock by packet_create() after proto_register() and sock_register().
It will use net->packet.sklist_lock and net->packet.sklist directly in packet_create().
net->packet.sklist_lock and net->packet.sklist are initialized in packet_net_init().
The code snippet is as follows:
static int packet_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
...
mutex_lock(&net->packet.sklist_lock);
sk_add_node_tail_rcu(sk, &net->packet.sklist);
mutex_unlock(&net->packet.sklist_lock);
...
}
static int __net_init packet_net_init(struct net *net)
{
mutex_init(&net->packet.sklist_lock);
INIT_HLIST_HEAD(&net->packet.sklist);
...
}
So, if the sock is created firstly, we will get illegal access bug.
>
> Regards,
> Oliver
>
> .
next prev parent reply other threads:[~2022-09-14 6:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 3:04 [PATCH 0/2] can: bcm: random optimizations Ziyang Xuan
2022-09-08 3:04 ` [PATCH 1/2] can: bcm: registration process optimization in bcm_module_init() Ziyang Xuan
2022-09-08 7:10 ` Oliver Hartkopp
2022-09-08 7:17 ` Oliver Hartkopp
2022-09-08 11:14 ` Ziyang Xuan (William)
2022-09-08 13:05 ` Oliver Hartkopp
2022-09-09 3:58 ` Ziyang Xuan (William)
2022-09-09 15:04 ` Oliver Hartkopp
2022-09-12 12:00 ` Marc Kleine-Budde
2022-09-12 14:54 ` Oliver Hartkopp
2022-09-14 6:42 ` Ziyang Xuan (William) [this message]
2022-09-08 3:04 ` [PATCH 2/2] can: bcm: check the result of can_send() in bcm_can_tx() Ziyang Xuan
2022-09-08 6:47 ` Oliver Hartkopp
2022-09-08 12:09 ` Ziyang Xuan (William)
2022-09-12 12:02 ` Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbf68897-c719-db79-b856-792bf8fbf533@huawei.com \
--to=william.xuanziyang@huawei.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®