Skip to contentSkip to conversation

x86/msr: Rework wrmsr_safe() using asm goto()

PATCH In review Andrew Cooper 3 participants 13 messages May 21, 2025 – May 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/msr: Rework wrmsr_safe() using asm goto()

This avoids needing to hold rc in a register across the WRMSR, and in most cases removes direct testing and branching based on rc, as the fault label can be rearranged to directly land on the out-of-line block.

No functional change.

Resolves: https://gitlab.com/xen-project/xen/-/work_items/214

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/include/asm/msr.h | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
xen/arch/x86/include/asm/msr.h +14 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr, uint32_t lo, uint32_t hi)
 /* wrmsr with exception handling */
 static inline int wrmsr_safe(unsigned int msr, uint64_t val)
 {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
 }
 
 static inline uint64_t msr_fold(const struct cpu_user_regs *regs)
Signature · 1 line
2.39.5
#2 lore raw
In reply to Andrew Cooper
Quoted 27 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr, uint32_t lo, uint32_t hi)
 /* wrmsr with exception handling */
 static inline int wrmsr_safe(unsigned int msr, uint64_t val)
 {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, uint32_t lo, uint32_t hi) · line 86

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
 }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

~Andrew

#3 lore raw
Quoted 49 lines · Andrew Cooper
Quoted 28 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr, uint32_t 
 lo, uint32_t hi)
 /* wrmsr with exception handling */
 static inline int wrmsr_safe(unsigned int msr, uint64_t val)
 {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, uint32_t · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
 }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

Quoted 8 lines

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

Hi Andrew,

R1.1 is easy to fix, I'll send a patch myself. On R2.6 you are probably right. I suggest marking the rule not clean to unblock while we investigate. It should not be hard to fix this FP.

Thanks,
Nicola

Quoted 1 line

~Andrew

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#4 lore raw
Quoted 61 lines · Nicola Vetrini
Quoted 51 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

Quoted 8 lines

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

Quoted 5 lines

Hi Andrew,

R1.1 is easy to fix, I'll send a patch myself. On R2.6 you are probably right. I suggest marking the rule not clean to unblock while we investigate. It should not be hard to fix this FP.

I've not committed the patch yet, so staging is still green.

But, it occurs to me that this is not the first asm goto() to be scanned by Eclair.  There's wrmsr_amd_safe() in amd.c (c/s b3d8b3e3f3aa from ~6w ago) using exactly the same pattern, which has been passing just fine.

Clearly something else is relevant in terms of triggering violations.

~Andrew

#5 lore raw
Quoted 70 lines · Andrew Cooper
Quoted 61 lines · Nicola Vetrini
Quoted 51 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

Quoted 8 lines

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

Quoted 5 lines

Hi Andrew,

R1.1 is easy to fix, I'll send a patch myself. On R2.6 you are probably right. I suggest marking the rule not clean to unblock while we investigate. It should not be hard to fix this FP.

I've not committed the patch yet, so staging is still green.

Quoted 7 lines

But, it occurs to me that this is not the first asm goto() to be scanned by Eclair.  There's wrmsr_amd_safe() in amd.c (c/s b3d8b3e3f3aa from ~6w ago) using exactly the same pattern, which has been passing just fine.

Clearly something else is relevant in terms of triggering violations.

~Andrew

I think the reason it's simply that file being out of scope due to being imported from Linux (whether that is still true I don't know), which is unfortunate. We ought to revise that list (docs/misra/exclude-list.json).

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#6 lore raw
Quoted 77 lines · Nicola Vetrini
Quoted 76 lines · Andrew Cooper
Quoted 63 lines · Nicola Vetrini
Quoted 52 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

Quoted 9 lines

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto()
yet.  The labels listed are reachable from inside the asm block.

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

Quoted 5 lines

Hi Andrew,

R1.1 is easy to fix, I'll send a patch myself. On R2.6 you are probably right. I suggest marking the rule not clean to unblock while we investigate. It should not be hard to fix this FP.

I've not committed the patch yet, so staging is still green.

But, it occurs to me that this is not the first asm goto() to be scanned by Eclair.  There's wrmsr_amd_safe() in amd.c (c/s b3d8b3e3f3aa from ~6w ago) using exactly the same pattern, which has been passing just fine.

Quoted 9 lines
Quoted 3 lines

Clearly something else is relevant in terms of triggering violations.

~Andrew

I think the reason it's simply that file being out of scope due to being imported from Linux (whether that is still true I don't know), which is unfortunate. We ought to revise that list (docs/misra/exclude-list.json).

Oh, that.  Anyone who takes a cursory look at amd.c will find it has diverged entirely from Linux.

If I were an examiner, I wouldn't accept such a claim for being out of scope...

~Andrew

#7 lore raw
In reply to Andrew Cooper
Quoted 45 lines · Andrew Cooper
Quoted 28 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr, uint32_t 
 lo, uint32_t hi)
 /* wrmsr with exception handling */
 static inline int wrmsr_safe(unsigned int msr, uint64_t val)
 {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, uint32_t · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
 }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

Quoted 9 lines

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Thanks,
Nicola

Quoted 4 lines

From a qualification point of view, this allows for some extensive optimisations dropping emitted code.

~Andrew

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#8 lore raw
Quoted 54 lines · Nicola Vetrini
Quoted 53 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

Quoted 7 lines
Quoted 3 lines

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Oh, fantastic thanks.

I'll hold off pushing until then.

~Andrew

#9 lore raw
Quoted 63 lines · Andrew Cooper
Quoted 54 lines · Nicola Vetrini
Quoted 53 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

Quoted 7 lines
Quoted 3 lines

I expect this means that Eclair doesn't know how to interpret asm goto() yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Quoted 5 lines

Oh, fantastic thanks.

I'll hold off pushing until then.

~Andrew

Hi Andrew,

both runners are now updated with the new images, so you can rerun the tests.

Thanks,
Nicola

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#10 lore raw
Quoted 68 lines · Nicola Vetrini
Quoted 67 lines · Andrew Cooper
Quoted 55 lines · Nicola Vetrini
Quoted 54 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

Quoted 8 lines
Quoted 4 lines

I expect this means that Eclair doesn't know how to interpret asm goto()
yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Oh, fantastic thanks.

Quoted 8 lines
Quoted 3 lines

I'll hold off pushing until then.

~Andrew

Hi Andrew,

both runners are now updated with the new images, so you can rerun the tests.

Both Eclair runs are unhappy, and not even completing analysis.

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1835567532

This is the same branch as before, plus your config change for R1.1

~Andrew

#11 lore raw
Quoted 78 lines · Andrew Cooper
Quoted 68 lines · Nicola Vetrini
Quoted 67 lines · Andrew Cooper
Quoted 55 lines · Nicola Vetrini
Quoted 54 lines · Andrew Cooper
Quoted 29 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 87

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

Quoted 8 lines
Quoted 4 lines

I expect this means that Eclair doesn't know how to interpret asm goto()
yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Oh, fantastic thanks.

Quoted 8 lines
Quoted 3 lines

I'll hold off pushing until then.

~Andrew

Hi Andrew,

both runners are now updated with the new images, so you can rerun the tests.

Quoted 7 lines

Both Eclair runs are unhappy, and not even completing analysis.

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1835567532

This is the same branch as before, plus your config change for R1.1

~Andrew

There might be something wrong with the image I used, it's erroring on a speculative call to the compiler. I rolled back to the previous images (without the fix for R2.6). I will investigate tomorrow.

Thanks,
Nicola

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
#12 lore raw
Quoted 82 lines · Nicola Vetrini
Quoted 81 lines · Andrew Cooper
Quoted 69 lines · Nicola Vetrini
Quoted 68 lines · Andrew Cooper
Quoted 56 lines · Nicola Vetrini
Quoted 55 lines · Andrew Cooper
Quoted 30 lines · Andrew Cooper
xen/arch/x86/include/asm/msr.h +5 -14
index 0d3b1d637488..4c4f18b3a54d 100644
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr,
 uint32_t lo, uint32_t hi)
  /* wrmsr with exception handling */
  static inline int wrmsr_safe(unsigned int msr, uint64_t val)
  {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" 
 (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])

xen/arch/x86/include/asm/msr.h static inline void wrmsr_ns(uint32_t msr, · line 88

Quoted 10 lines
xen/arch/x86/include/asm/msr.h +9 -0
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
  }

It turns out this is the first piece of Eclair-scanned code using asm goto.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/10108558677
(The run also contained an equivalent change to xsetbv())

We're getting R1.1 and R2.6 violations.

R1.1 complains about [STD.adrslabl] "label address" not being valid C99.

R2.6 complains about unused labels.

Quoted 8 lines
Quoted 4 lines

I expect this means that Eclair doesn't know how to interpret asm goto()
yet.  The labels listed are reachable from inside the asm block.

That has been fixed upstream. I'll reach out to you when that fix trickles down to the runners, so that you're able to test and push that change.

Oh, fantastic thanks.

Quoted 8 lines
Quoted 3 lines

I'll hold off pushing until then.

~Andrew

Hi Andrew,

both runners are now updated with the new images, so you can rerun the tests.

Both Eclair runs are unhappy, and not even completing analysis.

Quoted 7 lines
Quoted 5 lines

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1835567532

This is the same branch as before, plus your config change for R1.1

~Andrew

There might be something wrong with the image I used, it's erroring on a speculative call to the compiler. I rolled back to the previous images (without the fix for R2.6). I will investigate tomorrow.

Fixed, I will let you know when runners are updated. It was a change unrelated to Rule 2.6.

Thanks,
Nicola

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253