* + mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch added to mm-nonmm-unstable branch
@ 2025-06-16 23:16 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2025-06-16 23:16 UTC (permalink / raw)
To: mm-commits, u.kleine-koenig, peterz, oleg, linux,
david.laight.linux, biju.das.jz, npitre, akpm
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2907 bytes --]
The patch titled
Subject: mul_u64_u64_div_u64: fix the division-by-zero behavior
has been added to the -mm mm-nonmm-unstable branch. Its filename is
mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Nicolas Pitre <npitre@baylibre.com>
Subject: mul_u64_u64_div_u64: fix the division-by-zero behavior
Date: Mon, 16 Jun 2025 15:22:44 -0400 (EDT)
The current implementation forces a compile-time 1/0 division, which
generates an undefined instruction (ud2 on x86) rather than a proper
runtime division-by-zero exception.
Change to trigger an actual div-by-0 exception at runtime, consistent with
other division operations. Use a non-1 dividend to prevent the compiler
from optimizing the division into a comparison.
Link: https://lkml.kernel.org/r/q246p466-1453-qon9-29so-37105116009q@onlyvoer.pbz
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Weißschuh <linux@weissschuh.net>
Cc: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Cc: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
lib/math/div64.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
--- a/lib/math/div64.c~mul_u64_u64_div_u64-fix-the-division-by-zero-behavior
+++ a/lib/math/div64.c
@@ -212,12 +212,13 @@ u64 mul_u64_u64_div_u64(u64 a, u64 b, u6
#endif
- /* make sure c is not zero, trigger exception otherwise */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdiv-by-zero"
- if (unlikely(c == 0))
- return 1/0;
-#pragma GCC diagnostic pop
+ /* make sure c is not zero, trigger runtime exception otherwise */
+ if (unlikely(c == 0)) {
+ unsigned long zero = 0;
+
+ OPTIMIZER_HIDE_VAR(zero);
+ return ~0UL/zero;
+ }
int shift = __builtin_ctzll(c);
_
Patches currently in -mm which might be from npitre@baylibre.com are
mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-16 23:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 23:16 + mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch added to mm-nonmm-unstable branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.