linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/math64: handle #DE in mul_u64_u64_div_u64()
@ 2025-07-21 13:04 Oleg Nesterov
  2025-07-21 18:20 ` David Laight
  2025-07-27 12:34 ` [PATCH v2] " Oleg Nesterov
  0 siblings, 2 replies; 28+ messages in thread
From: Oleg Nesterov @ 2025-07-21 13:04 UTC (permalink / raw)
  To: David Laight, Ingo Molnar, Peter Zijlstra
  Cc: Thomas Gleixner, Borislav Petkov, Dave Hansen, H. Peter Anvin,
	Li,Rongqing, Steven Rostedt, linux-kernel, x86

Change mul_u64_u64_div_u64() to return ULONG_MAX if the result doesn't
fit u64, this matches the generic implementation in lib/math/div64.c.

Reported-by: "Li,Rongqing" <lirongqing@baidu.com>
Link: https://lore.kernel.org/all/78a0d7bb20504c0884d474868eccd858@baidu.com/
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 arch/x86/include/asm/div64.h | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
index 9931e4c7d73f..dfd25cfd1c33 100644
--- a/arch/x86/include/asm/div64.h
+++ b/arch/x86/include/asm/div64.h
@@ -79,20 +79,27 @@ static inline u64 mul_u32_u32(u32 a, u32 b)
 
 #else
 # include <asm-generic/div64.h>
+# include <asm/asm.h>
+# include <asm/bug.h>
 
 /*
- * Will generate an #DE when the result doesn't fit u64, could fix with an
- * __ex_table[] entry when it becomes an issue.
+ * Returns ULONG_MAX when the result doesn't fit u64.
  */
 static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
 {
+	int ok = 0;
 	u64 q;
 
-	asm ("mulq %2; divq %3" : "=a" (q)
-				: "a" (a), "rm" (mul), "rm" (div)
-				: "rdx");
+	asm ("mulq %3; 1: divq %4; movl $1,%1; 2:\n"
+		_ASM_EXTABLE(1b, 2b)
+		: "=a" (q), "+r" (ok)
+		: "a" (a), "rm" (mul), "rm" (div)
+		: "rdx");
 
-	return q;
+	if (ok)
+		return q;
+	WARN_ON_ONCE(!div);
+	return ~(u64)0;
 }
 #define mul_u64_u64_div_u64 mul_u64_u64_div_u64
 
-- 
2.25.1.362.g51ebf55



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

end of thread, other threads:[~2025-07-30  4:53 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-21 13:04 [PATCH] x86/math64: handle #DE in mul_u64_u64_div_u64() Oleg Nesterov
2025-07-21 18:20 ` David Laight
2025-07-22 10:50   ` Oleg Nesterov
2025-07-22 12:09     ` David Laight
2025-07-22 13:21       ` Oleg Nesterov
2025-07-22 22:03         ` David Laight
2025-07-23  9:38           ` Oleg Nesterov
2025-07-23 21:48             ` David Laight
2025-07-24  8:11               ` Oleg Nesterov
2025-07-24  8:25                 ` Oleg Nesterov
2025-07-24 11:14                   ` Oleg Nesterov
2025-07-25  1:00                     ` H. Peter Anvin
2025-07-25 10:12                       ` Oleg Nesterov
2025-07-25 21:46                         ` David Laight
2025-07-26  9:55                           ` Oleg Nesterov
2025-07-24 12:00                   ` David Laight
2025-07-24 13:58                     ` Oleg Nesterov
2025-07-22 16:53       ` H. Peter Anvin
2025-07-22 21:53         ` David Laight
2025-07-22 16:50     ` H. Peter Anvin
2025-07-22 17:58       ` Oleg Nesterov
2025-07-22 18:12         ` H. Peter Anvin
2025-07-22 18:38           ` Oleg Nesterov
2025-07-22 19:26             ` H. Peter Anvin
2025-07-22 21:56             ` David Laight
2025-07-27 12:34 ` [PATCH v2] " Oleg Nesterov
2025-07-28 18:53   ` David Laight
2025-07-30  2:30   ` [????] " Li,Rongqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).