From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH] selinux: use explicit 64-bit division
Date: Tue, 15 Sep 2026 20:05:22 +0000 [thread overview]
Message-ID: <20260915200522.BBC8A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915195728.3519469-1-arnd@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selinux: unnecessary 64-bit division for 24-bit bounded value
--
commit 7622bbc45f42944796ad657eff450b2c4b7eb729
Author: Arnd Bergmann <arnd@arndb.de>
selinux: use explicit 64-bit division
The patch addresses a 32-bit build error where dividing a 64-bit integer
by 33 caused an undefined reference to __aeabi_uldivmod. It fixes this
by replacing standard division and modulo with explicit 64-bit division
helpers.
> diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
> index f60f92e2ac341..7894a2f480f74 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c
> @@ -1573,7 +1573,7 @@ static inline u64 sel_class_to_ino(u16 class)
>
> static inline u16 sel_ino_to_class(u64 ino)
> {
> - return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
> + return div_u64(ino & SEL_INO_MASK, SEL_VEC_MAX + 1);
> }
[Severity: Low]
Since SEL_INO_MASK restricts the dividend to 24 bits, the masked value fits
comfortably in a standard 32-bit unsigned integer.
Would it be better to downcast the masked value to u32 before division?
This would avoid the 64-bit division overhead entirely and allow the
compiler to use fast 32-bit math or optimize the constant division into a
multiply-and-shift.
> static inline u64 sel_perm_to_ino(u16 class, u32 perm)
> @@ -1583,7 +1583,11 @@ static inline u64 sel_perm_to_ino(u16 class, u32 perm)
>
> static inline u32 sel_ino_to_perm(u64 ino)
> {
> - return (ino & SEL_INO_MASK) % (SEL_VEC_MAX + 1);
> + u32 rem;
> +
> + div_u64_rem(ino & SEL_INO_MASK, SEL_VEC_MAX + 1, &rem);
> +
> + return rem;
> }
[Severity: Low]
Similar to sel_ino_to_class(), does this need a full 64-bit quotient and
remainder calculation?
Given the dividend is also bounded to 24 bits by SEL_INO_MASK here, could
this be replaced with a 32-bit downcast and a standard modulo operation to be
more efficient while remaining mathematically identical?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915195728.3519469-1-arnd@kernel.org?part=1
next prev parent reply other threads:[~2026-09-15 20:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:56 [PATCH] selinux: use explicit 64-bit division Arnd Bergmann
2026-09-15 20:05 ` sashiko-bot [this message]
2026-09-15 20:36 ` Paul Moore
2026-09-15 20:42 ` Arnd Bergmann
2026-09-15 21:40 ` Paul Moore
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=20260915200522.BBC8A1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.kernel.org \
/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