* [PATCH] kernfs: avoid READ_ONCE() on a kgid_t in kernfs_new_node()
@ 2026-10-27 14:32 Shakeel Butt
2026-10-27 14:36 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Shakeel Butt @ 2026-10-27 14:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Tejun Heo, Christian Brauner
Cc: Meta kernel team, driver-core, linux-kernel, kernel test robot
kernfs_new_node() reads the parent's gid with READ_ONCE(attrs->ia_gid).
That gid is a kgid_t, which is a struct.
On SMP alpha, READ_ONCE() ends by casting the value it loaded back to
the type of its argument. Here that is a cast from a struct to the same
struct. GCC accepts that as an extension, but ISO C does not allow a
cast to or from a struct type, so sparse warns:
fs/kernfs/dir.c:751:31: sparse: sparse: cast to non-scalar
fs/kernfs/dir.c:751:31: sparse: sparse: cast from non-scalar
Read the gid_t inside the kgid_t instead, and wrap it back up with
KGIDT_INIT(). This is still a single marked load of the same four bytes.
There is no functional change. With GCC 12 for alpha (the config from
the report) and GCC 14 for x86-64 (with and without KCSAN),
fs/kernfs/dir.o has the same object code before and after this change.
Fixes: 81bdc85b4c08 ("kernfs: fix up the unlocked attribute reads on the creation paths")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202610261608.vItiXCGW-lkp@intel.com/
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
fs/kernfs/dir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 324d61a00545..800af10d9511 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -750,7 +750,7 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
struct kernfs_iattrs *attrs = READ_ONCE(parent->iattr);
if (attrs)
- gid = READ_ONCE(attrs->ia_gid);
+ gid = KGIDT_INIT(READ_ONCE(attrs->ia_gid.val));
if (flags & KERNFS_DIR)
mode |= S_ISGID;
--
2.53.0-Meta
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] kernfs: avoid READ_ONCE() on a kgid_t in kernfs_new_node()
2026-10-27 14:32 [PATCH] kernfs: avoid READ_ONCE() on a kgid_t in kernfs_new_node() Shakeel Butt
@ 2026-10-27 14:36 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-10-27 14:36 UTC (permalink / raw)
To: Shakeel Butt
Cc: Greg Kroah-Hartman, Christian Brauner, Meta kernel team,
driver-core, linux-kernel, kernel test robot
On Tue, Oct 27, 2026 at 07:32:47AM -0700, Shakeel Butt wrote:
> kernfs_new_node() reads the parent's gid with READ_ONCE(attrs->ia_gid).
> That gid is a kgid_t, which is a struct.
>
> On SMP alpha, READ_ONCE() ends by casting the value it loaded back to
> the type of its argument. Here that is a cast from a struct to the same
> struct. GCC accepts that as an extension, but ISO C does not allow a
> cast to or from a struct type, so sparse warns:
>
> fs/kernfs/dir.c:751:31: sparse: sparse: cast to non-scalar
> fs/kernfs/dir.c:751:31: sparse: sparse: cast from non-scalar
>
> Read the gid_t inside the kgid_t instead, and wrap it back up with
> KGIDT_INIT(). This is still a single marked load of the same four bytes.
>
> There is no functional change. With GCC 12 for alpha (the config from
> the report) and GCC 14 for x86-64 (with and without KCSAN),
> fs/kernfs/dir.o has the same object code before and after this change.
>
> Fixes: 81bdc85b4c08 ("kernfs: fix up the unlocked attribute reads on the creation paths")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202610261608.vItiXCGW-lkp@intel.com/
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-27 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 14:32 [PATCH] kernfs: avoid READ_ONCE() on a kgid_t in kernfs_new_node() Shakeel Butt
2026-10-27 14:36 ` Tejun Heo
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®