BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf, x86: Mask the shift counts of the magic number division
@ 2026-10-18 11:33 Daniel Borkmann
  2026-10-18 15:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Borkmann @ 2026-10-18 11:33 UTC (permalink / raw)
  To: bpf; +Cc: kernel test robot

The kernel test robot reports for a clang 22 randconfig with UBSAN
and ThinLTO:

  vmlinux.o: error: objtool: do_jit(): unexpected end of section .text.do_jit

Fix by masking the counts to their range like rol64() does, which keeps the
shifts defined for the sanitizer and removes the __ubsan_handle_shift_out_of_bounds()
checks. The counts are below 32 and 64 anyway, so the emitted code does not
change. Reproduced with clang 20 and the robot's config without LTO.

Fixes: 02cfd66f3d9a ("bpf, x86: Divide by constants via multiplication with a magic number")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202610171029.DfoBvNXv-lkp@intel.com/
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 arch/x86/net/bpf_jit_comp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 11a4e4f87aac..d3843045dc71 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2080,7 +2080,7 @@ struct bpf_div_magic {
  */
 static void bpf_magic_udiv(u64 d, int lz, struct bpf_div_magic *mag)
 {
-	u64 mask = ~0ULL >> lz;
+	u64 mask = ~0ULL >> (lz & 63);
 	u64 nc, delta, q1, r1, q2, r2;
 	int p;
 
@@ -2200,7 +2200,7 @@ static bool emit_div_const(u8 **pprog, const struct bpf_insn *insn, u32 dst_reg)
 		 * the add sequence.
 		 */
 		if (mag.add && !(imm32 & 1)) {
-			pre = __ffs(imm32);
+			pre = __ffs(imm32) & 31;
 			bpf_magic_udiv(imm32 >> pre, pre, &mag);
 			if (mag.add)
 				return false;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] bpf, x86: Mask the shift counts of the magic number division
  2026-10-18 11:33 [PATCH bpf-next] bpf, x86: Mask the shift counts of the magic number division Daniel Borkmann
@ 2026-10-18 15:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-18 15:10 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: bpf, lkp

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Sun, 18 Oct 2026 13:33:52 +0200 you wrote:
> The kernel test robot reports for a clang 22 randconfig with UBSAN
> and ThinLTO:
> 
>   vmlinux.o: error: objtool: do_jit(): unexpected end of section .text.do_jit
> 
> Fix by masking the counts to their range like rol64() does, which keeps the
> shifts defined for the sanitizer and removes the __ubsan_handle_shift_out_of_bounds()
> checks. The counts are below 32 and 64 anyway, so the emitted code does not
> change. Reproduced with clang 20 and the robot's config without LTO.
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf, x86: Mask the shift counts of the magic number division
    https://git.kernel.org/bpf/bpf-next/c/73a5accbfd21

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-18 15:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 11:33 [PATCH bpf-next] bpf, x86: Mask the shift counts of the magic number division Daniel Borkmann
2026-10-18 15:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox