lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <BYAPR12MB32057EF854A36230B5BC7E1AD5FD2@BYAPR12MB3205.namprd12.prod.outlook.com>
Date: Tue, 11 Feb 2025 09:32:08 +0000
From: Zhou Stephen Eta <stephen.eta.zhou@...look.com>
To: "richard.henderson@...aro.org" <richard.henderson@...aro.org>,
	"mattst88@...il.com" <mattst88@...il.com>, "arnd@...db.de" <arnd@...db.de>,
	"paulmck@...nel.org" <paulmck@...nel.org>, "linus.walleij@...aro.org"
	<linus.walleij@...aro.org>
CC: "linux-alpha@...r.kernel.org" <linux-alpha@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] arch/alpha: optimize virt_to_phys with compiler automatic
 sign extension

>From 0bf2dd816c8369e2c690869b5f6c671f28c2b196 Mon Sep 17 00:00:00 2001
From: "stephen.eta.zhou" <stephen.eta.zhou@...look.com>
Date: Tue, 11 Feb 2025 16:48:14 +0800
Subject: [PATCH] arch/alpha: optimize virt_to_phys with compiler automatic
 sign extension

In the `virt_to_phys` function, the following changes have been made:
1. **Automatic Sign Extension**:
   - The manual sign extension code has been replaced with the
     compiler's automatic sign extension.
   - This simplifies the code and leverages the
     compiler's optimization.

2. **Fix for 64-bit Address Overflow**:
   - Previously, when the input was a 64-bit address with a
     negative high bit (sign bit), the sign extension caused an
     overflow, resulting in an incorrect conversion to 0.
   - This issue has been addressed by using the compiler's
     automatic sign extension,
     which ensures proper handling of negative addresses.

3. **NULL Pointer Check**:
   - A NULL pointer check has been added at the
     beginning of the function.
   - If the address is NULL, the function now
     returns 0 to prevent potential crashes.

Signed-off-by: stephen.eta.zhou <stephen.eta.zhou@...look.com>
---
 arch/alpha/include/asm/io.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/include/asm/io.h b/arch/alpha/include/asm/io.h
index 65fe1e54c6da..4d7cd7486b7d 100644
--- a/arch/alpha/include/asm/io.h
+++ b/arch/alpha/include/asm/io.h
@@ -70,9 +70,11 @@ static inline unsigned long virt_to_phys(volatile void *address)
 {
         unsigned long phys = (unsigned long)address;
 
-	/* Sign-extend from bit 41.  */
-	phys <<= (64 - 41);
-	phys = (long)phys >> (64 - 41);
+	if (!address)
+		return 0;
+
+	/* Automatic Sign-extend  */
+	phys = (long)phys;
 
 	/* Crop to the physical address width of the processor.  */
         phys &= (1ul << hwrpb->pa_bits) - 1;
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ