From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,u.kleine-koenig@baylibre.com,peterz@infradead.org,oleg@redhat.com,linux@weissschuh.net,david.laight.linux@gmail.com,biju.das.jz@bp.renesas.com,npitre@baylibre.com,akpm@linux-foundation.org
Subject: + mul_u64_u64_div_u64-fix-the-division-by-zero-behavior.patch added to mm-nonmm-unstable branch
Date: Mon, 16 Jun 2025 16:16:13 -0700 [thread overview]
Message-ID: <20250616231614.6966FC4CEEA@smtp.kernel.org> (raw)
[-- 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
reply other threads:[~2025-06-16 23:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250616231614.6966FC4CEEA@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=biju.das.jz@bp.renesas.com \
--cc=david.laight.linux@gmail.com \
--cc=linux@weissschuh.net \
--cc=mm-commits@vger.kernel.org \
--cc=npitre@baylibre.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=u.kleine-koenig@baylibre.com \
/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 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.