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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250506165227.158932-2-ubizjak@gmail.com>
Date: Tue,  6 May 2025 18:52:07 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: x86@...nel.org,
	linux-kernel@...r.kernel.org
Cc: Uros Bizjak <ubizjak@...il.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...nel.org>,
	Borislav Petkov <bp@...en8.de>,
	Dave Hansen <dave.hansen@...ux.intel.com>,
	"H. Peter Anvin" <hpa@...or.com>
Subject: [PATCH -tip 2/3] x86/asm/32: Modernize __constant_memcpy()

Use inout "+" constraint modifier where appropriate and declare
temporary variables as unsigned long.

No functional changes intended.

Signed-off-by: Uros Bizjak <ubizjak@...il.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: "H. Peter Anvin" <hpa@...or.com>
---
 arch/x86/include/asm/string_32.h | 51 +++++++++++++-------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/arch/x86/include/asm/string_32.h b/arch/x86/include/asm/string_32.h
index 9152d2c0f60e..00d497837571 100644
--- a/arch/x86/include/asm/string_32.h
+++ b/arch/x86/include/asm/string_32.h
@@ -52,7 +52,7 @@ static __always_inline void *__memcpy(void *to, const void *from, size_t n)
 static __always_inline void *__constant_memcpy(void *to, const void *from,
 					       size_t n)
 {
-	long esi, edi;
+	unsigned long esi, edi;
 	if (!n)
 		return to;
 
@@ -84,60 +84,51 @@ static __always_inline void *__constant_memcpy(void *to, const void *from,
 		return to;
 	}
 
-	esi = (long)from;
-	edi = (long)to;
+	esi = (unsigned long)from;
+	edi = (unsigned long)to;
 	if (n >= 5 * 4) {
 		/* large block: use rep prefix */
-		int ecx;
+		unsigned long ecx = n >> 2;
 		asm volatile("rep movsl"
-			     : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
-			     : "0" (n / 4), "1" (edi), "2" (esi)
-			     : "memory"
-		);
+			     : "+D" (edi), "+S" (esi), "+c" (ecx)
+			     : : "memory");
 	} else {
 		/* small block: don't clobber ecx + smaller code */
 		if (n >= 4 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 3 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 2 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 		if (n >= 1 * 4)
 			asm volatile("movsl"
-				     : "=&D"(edi), "=&S"(esi)
-				     : "0"(edi), "1"(esi)
-				     : "memory");
+				     : "+D" (edi), "+S" (esi)
+				     : : "memory");
 	}
-	switch (n % 4) {
+	switch (n & 3) {
 		/* tail */
 	case 0:
 		return to;
 	case 1:
 		asm volatile("movsb"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	case 2:
 		asm volatile("movsw"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	default:
 		asm volatile("movsw\n\tmovsb"
-			     : "=&D"(edi), "=&S"(esi)
-			     : "0"(edi), "1"(esi)
-			     : "memory");
+			     : "+D" (edi), "+S" (esi)
+			     : : "memory");
 		return to;
 	}
 }
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ