Re: [PATCH v3 1/3] fs: speed up path lookup with cheaper handling of MAY_EXEC
From: Mateusz Guzik
Date: Tue Nov 11 2025 - 06:58:54 EST
On Tue, Nov 11, 2025 at 11:51 AM Mateusz Guzik <mjguzik@xxxxxxxxx> wrote:
>
> On Tue, Nov 11, 2025 at 10:41 AM Christian Brauner <brauner@xxxxxxxxxx> wrote:
> >
> > On Fri, Nov 07, 2025 at 03:21:47PM +0100, Mateusz Guzik wrote:
> > > + if (unlikely(((inode->i_mode & 0111) != 0111) || !no_acl_inode(inode)))
> >
> > Can you send a follow-up where 0111 is a constant with some descriptive
> > name, please? Can be local to the file. I hate these raw-coded
> > permission masks with a passion.
> >
>
> #define UNIX_PERM_ALL_X 0111?
>
> I have no opinion about hardcoding this vs using a macro, but don't
> have a good name for that one either.
Apart from usage added by me here there is:
fs/coredump.c: if
((READ_ONCE(file_inode(vma->vm_file)->i_mode) & 0111) != 0)
fs/namei.c: * - multiplying by 0111 spreads them out to all of ugo
fs/namei.c: if (!((mask & 7) * 0111 & ~mode)) {
That's ignoring other spots which definitely want 0111 spelled out in
per-fs code.
I would argue the other 2 in namei.c want this spelled out numerically as well:
│* - 'mask&7' is the requested permission bit set
│* - multiplying by 0111 spreads them out to all of ugo
│* - '& ~mode' looks for missing inode permission bits
│* - the '!' is for "no missing permissions"
[snip]
if (!((mask & 7) * 0111 & ~mode)) {
But then it may make sense to keep this numerical in the new code as
well so that anyone looking at lookup_inode_permission_may_exec() and
inode_permission()->generic_permission()->acl_permission_check() can
see it's the same thing.
I figured maybe a comment would do the trick above the 0111 usage, but
the commentary added at the top of the func imo covers it:
* Since majority of real-world traversal happens on inodes which
grant it for
* everyone, we check it upfront and only resort to more expensive
work if it
* fails.
All that said, now that I look at it, I think the code is best left
off with spelled out 0111 in place so I wont be submitting a patch to
change that.
Given that hiding it behind some name or adding a comment is a trivial
edit, I don't think it's much of a burden for you to do it should you
chose to make such a change anyway.