From: Stanislav Fomichev <stfomichev@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Stanislav Fomichev <sdf@fomichev.me>,
netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, Saeed Mahameed <saeed@kernel.org>
Subject: Re: [PATCH net-next v4 07/12] net: hold netdev instance lock during ndo_bpf
Date: Tue, 18 Feb 2025 20:54:55 -0800 [thread overview]
Message-ID: <Z7VkH56cwF8u2RjX@mini-arch> (raw)
In-Reply-To: <20250218190258.5c82026b@kernel.org>
On 02/18, Jakub Kicinski wrote:
> On Mon, 17 Feb 2025 18:09:43 -0800 Stanislav Fomichev wrote:
> > --- a/kernel/bpf/offload.c
> > +++ b/kernel/bpf/offload.c
> > @@ -528,10 +528,10 @@ struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
> > return ERR_PTR(-ENOMEM);
> >
> > bpf_map_init_from_attr(&offmap->map, attr);
> > -
> > rtnl_lock();
> > - down_write(&bpf_devs_lock);
> > offmap->netdev = __dev_get_by_index(net, attr->map_ifindex);
> > + netdev_lock_ops(offmap->netdev);
> > + down_write(&bpf_devs_lock);
> > err = bpf_dev_offload_check(offmap->netdev);
> > if (err)
> > goto err_unlock;
> > @@ -548,12 +548,14 @@ struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
> >
> > list_add_tail(&offmap->offloads, &ondev->maps);
> > up_write(&bpf_devs_lock);
> > + netdev_unlock_ops(offmap->netdev);
> > rtnl_unlock();
> >
> > return &offmap->map;
> >
> > err_unlock:
> > up_write(&bpf_devs_lock);
> > + netdev_unlock_ops(offmap->netdev);
> > rtnl_unlock();
> > bpf_map_area_free(offmap);
> > return ERR_PTR(err);
>
> Any reason for this lock ordering? My intuition would be from biggest
> to smallest, so rtnl_lock -> sem -> instance
From rtnl we take the following:
rtnl_newlink
rtnl_lock
do_setlink
netdev_lock_ops
dev_change_xdp_fd
dev_xdp_attach
bpf_offload_dev_match
down_read(bpf_devs_lock)
So I made bpf syscall path to look similar:
map_create
bpf_map_offload_map_alloc
rtnl_lock
netdev_ops_lock
down_write(bpf_devs_lock)
next prev parent reply other threads:[~2025-02-19 4:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 2:09 [PATCH net-next v4 00/12] net: Hold netdev instance lock during ndo operations Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 01/12] net: hold netdev instance lock during ndo_open/ndo_stop Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 02/12] net: hold netdev instance lock during ndo_setup_tc Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 03/12] net: hold netdev instance lock during queue operations Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 04/12] net: hold netdev instance lock during rtnetlink operations Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 05/12] net: hold netdev instance lock during ioctl operations Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 06/12] net: hold netdev instance lock during sysfs operations Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 07/12] net: hold netdev instance lock during ndo_bpf Stanislav Fomichev
2025-02-19 3:02 ` Jakub Kicinski
2025-02-19 4:54 ` Stanislav Fomichev [this message]
2025-02-18 2:09 ` [PATCH net-next v4 08/12] net: ethtool: try to protect all callback with netdev instance lock Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 09/12] net: replace dev_addr_sem " Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 10/12] net: dummy: add dummy shaper API Stanislav Fomichev
2025-02-19 3:09 ` Jakub Kicinski
2025-02-19 4:56 ` Stanislav Fomichev
2025-02-19 17:36 ` Jakub Kicinski
2025-02-18 2:09 ` [PATCH net-next v4 11/12] docs: net: document new locking reality Stanislav Fomichev
2025-02-19 2:53 ` Jakub Kicinski
2025-02-19 4:52 ` Stanislav Fomichev
2025-02-19 8:37 ` Paolo Abeni
2025-02-19 15:43 ` Stanislav Fomichev
2025-02-18 2:09 ` [PATCH net-next v4 12/12] eth: bnxt: remove most dependencies on RTNL Stanislav Fomichev
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=Z7VkH56cwF8u2RjX@mini-arch \
--to=stfomichev@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeed@kernel.org \
--cc=sdf@fomichev.me \
/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