Skip to contentSkip to conversation

x86: remove memory constraint from "mov" instruction

PATCH Applied Bill Wendling 4 participants 7 messages Sep 9, 2019 – Sep 24, 2019 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: remove memory constraint from "mov" instruction

The "mov" instruction to get the error code shouldn't move into a memory location. Don't allow the compiler to make this decision. Instead specify that only a register is appropriate here.

---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 5f37cef..451f504 100644
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
#2 lore raw
In reply to Bill Wendling
Quoted 3 lines · Bill Wendling

The "mov" instruction to get the error code shouldn't move into a memory location. Don't allow the compiler to make this decision. Instead specify that only a register is appropriate here.

I'd prefer the changelog to say something like:

Remove a bogus memory contraint as x86 does not have a generic memory-to-memory "mov" instruction.

Saying "shouldn't move into a memory location" makes it sound like there's an unwanted side effect when the compiler selects memory, though I suppose you could argue that a build error is an unwanted side effect :-).

Out of curiosity, do any compilers actually generate errors because of this, or is it simply dead code?

Quoted 18 lines
---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 5f37cef..451f504 100644
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
#3 lore raw
Quoted 6 lines · Sean Christopherson
Quoted 3 lines · Bill Wendling

The "mov" instruction to get the error code shouldn't move into a memory location. Don't allow the compiler to make this decision. Instead specify that only a register is appropriate here.

Quoted 9 lines

I'd prefer the changelog to say something like:

Remove a bogus memory contraint as x86 does not have a generic memory-to-memory "mov" instruction.

Saying "shouldn't move into a memory location" makes it sound like there's an unwanted side effect when the compiler selects memory, though I suppose you could argue that a build error is an unwanted side effect :-).

No prob. :-) I'm not familiar with sending these patches via email. Do I need to regenerate the patch and send via "send-email"? (Similar question for the "Reviewed-By" comments.)

Quoted 3 lines

Out of curiosity, do any compilers actually generate errors because of this, or is it simply dead code?

Yeah, clang uses a memory location, probably due to inlining causing register pressure (that's a guess, I didn't explore it too deeply).

-bw

Quoted 17 lines
Quoted 17 lines
---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 5f37cef..451f504 100644
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
#4 lore raw

PATCH 1/1 x86: remove memory constraint from "mov" instruction

Remove a bogus memory constraint as x86 does not have a generic memory-to-memory "mov" instruction.

---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 5f37cef..451f504 100644
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
 
Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
Reviewed-by on v1 1/1
#5 lore raw

+cc Paolo, Radim and Marc (to avoid saying the same thing twice)

I recommend having Paolo and Radim in the To: field when sending patches for KVM or kvm-unit-tests, simply cc'ing the KVM list may not be enough to ensure Paolo/Radim sees the patch.

https://lkml.kernel.org/r/[email protected]

Quoted 4 lines · Bill Wendling

Remove a bogus memory constraint as x86 does not have a generic memory-to-memory "mov" instruction.

For the actual patch:

Quoted 20 lines
---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 5f37cef..451f504 100644
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
 
Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
maintainer Applied
#6 lore raw
In reply to Bill Wendling
Quoted 14 lines · Bill Wendling

The "mov" instruction to get the error code shouldn't move into a memory location. Don't allow the compiler to make this decision. Instead specify that only a register is appropriate here.

---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +0 -0
index 5f37cef..451f504 100644

lib/x86/desc.c unsigned exception_error_code(void) · line 269

Quoted 8 lines
lib/x86/desc.c +1 -1
@@ -263,7 +263,7 @@ unsigned exception_error_code(void)
 {
     unsigned short error_code;
 
-    asm("mov %%gs:6, %0" : "=rm"(error_code));
+    asm("mov %%gs:6, %0" : "=r"(error_code));
     return error_code;
 }
 

Queued, thanks. (With fixed commit message).

Paolo