[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMuHMdW4iYbi-cwGBZgiS72=hP9X9r9Tc_UQaYBAsC=KNox2dw@mail.gmail.com>
Date: Fri, 12 Jan 2024 13:34:48 +0100
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Tejun Heo <tj@...nel.org>
Cc: gregkh@...uxfoundation.org, andrea.righi@...onical.com, ast@...nel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCHSET driver-core-next] kernfs: Protect kernfs_find_and_get_node_by_id()
with RCU
Hi Tejun,
On Tue, Jan 9, 2024 at 10:48 PM Tejun Heo <tj@...nel.org> wrote:
> The BPF helper bpf_cgroup_from_id() calls kernfs_find_and_get_node_by_id()
> which acquires kernfs_idr_lock, which is an non-raw non-IRQ-safe lock.
> kernfs_idr_lock used to be a non-irq-safe lock which could lead to deadlocks
> as bpf_cgroup_from_id() can be called from any BPF programs including e.g.
> the ones that attach to functions which are holding the scheduler rq lock.
>
> To resolve the situation dad3fb67ca1c ("kernfs: convert kernfs_idr_lock to
> an irq safe raw spinlock") converted kernfs_idr_lock to an irq-safe raw
> spinlock. However, this was also broken as we call idr_alloc*() while
> holding the lock and idr itself uses an non-irq-safe lock and also calls
> into memory allocator.
>
> Let's instead RCU protect kernfs_node and kernfs_root so that
> kernfs_find_and_get_node_by_id() can use rcu_read_lock() instead of
> kernfs_idr_lock. While this unfortunately increases the size of kernfs_node,
> it's the most straightforward thing to do and there likely are other places
> that can take advantage of RCU protection and improve scalability too.
>
> Please see the patch descriptions for more details.
>
> This patchset is on top of the current driver-core-next - dad3fb67ca1c
> ("kernfs: convert kernfs_idr_lock to an irq safe raw spinlock"), and also
> available in the following git branch.
>
> git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git kernfs-use-rcu
No more BUGs seen (with v2) on the few platforms I tried, so
Tested-by: Geert Uytterhoeven <geert+renesas@...der.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68korg
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Powered by blists - more mailing lists