... to improve the legibility of the following fix.
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
Best reviewed with `git show --ignore-all-space`
---
xen/arch/x86/xstate.c | 131 ++++++++++++++++++++++--------------------
1 file changed, 68 insertions(+), 63 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index e990abc9d18c..384f78bd5281 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -407,19 +407,19 @@ void xrstor(struct vcpu *v, uint64_t mask)
*/
for ( prev_faults = faults = 0; ; prev_faults = faults )
{
- switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
- {
- BUILD_BUG_ON(sizeof(faults) != 4); /* Clang doesn't support %z in asm. */
-#define _xrstor(insn) \
- asm volatile ( "1: .byte " insn "\n" \
- "3:\n" \
- " .section .fixup,\"ax\"\n" \
- "2: incl %[faults]\n" \
- " jmp 3b\n" \
- " .previous\n" \
- _ASM_EXTABLE(1b, 2b) \
- : [mem] "+m" (*ptr), [faults] "+g" (faults) \
- : [lmask] "a" (lmask), [hmask] "d" (hmask), \
+ switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
+ {
+ BUILD_BUG_ON(sizeof(faults) != 4); /* Clang doesn't support %z in asm. */
+#define _xrstor(insn) \
+ asm volatile ( "1: .byte " insn "\n" \
+ "3:\n" \
+ " .section .fixup,\"ax\"\n" \
+ "2: incl %[faults]\n" \
+ " jmp 3b\n" \
+ " .previous\n" \
+ _ASM_EXTABLE(1b, 2b) \
+ : [mem] "+m" (*ptr), [faults] "+g" (faults) \
+ : [lmask] "a" (lmask), [hmask] "d" (hmask), \
[ptr] "D" (ptr) )
#define XRSTOR(pfx) \
@@ -437,62 +437,67 @@ void xrstor(struct vcpu *v, uint64_t mask)
else \
_xrstor(pfx "0x0f,0xae,0x2f") /* xrstor */
- default:
- XRSTOR("0x48,");
- break;
- case 4: case 2:
- XRSTOR("");
- break;
+ default:
+ XRSTOR("0x48,");
+ break;
+
+ case 4: case 2:
+ XRSTOR("");
+ break;
+
#undef XRSTOR
#undef _xrstor
- }
- if ( likely(faults == prev_faults) )
- break;
+ }
+
+ if ( likely(faults == prev_faults) )
+ break;
+
#ifndef NDEBUG
- gprintk(XENLOG_WARNING, "fault#%u: mxcsr=%08x\n",
- faults, ptr->fpu_sse.mxcsr);
- gprintk(XENLOG_WARNING, "xs=%016lx xc=%016lx\n",
- ptr->xsave_hdr.xstate_bv, ptr->xsave_hdr.xcomp_bv);
- gprintk(XENLOG_WARNING, "r0=%016lx r1=%016lx\n",
- ptr->xsave_hdr.reserved[0], ptr->xsave_hdr.reserved[1]);
- gprintk(XENLOG_WARNING, "r2=%016lx r3=%016lx\n",
- ptr->xsave_hdr.reserved[2], ptr->xsave_hdr.reserved[3]);
- gprintk(XENLOG_WARNING, "r4=%016lx r5=%016lx\n",
- ptr->xsave_hdr.reserved[4], ptr->xsave_hdr.reserved[5]);
+ gprintk(XENLOG_WARNING, "fault#%u: mxcsr=%08x\n",
+ faults, ptr->fpu_sse.mxcsr);
+ gprintk(XENLOG_WARNING, "xs=%016lx xc=%016lx\n",
+ ptr->xsave_hdr.xstate_bv, ptr->xsave_hdr.xcomp_bv);
+ gprintk(XENLOG_WARNING, "r0=%016lx r1=%016lx\n",
+ ptr->xsave_hdr.reserved[0], ptr->xsave_hdr.reserved[1]);
+ gprintk(XENLOG_WARNING, "r2=%016lx r3=%016lx\n",
+ ptr->xsave_hdr.reserved[2], ptr->xsave_hdr.reserved[3]);
+ gprintk(XENLOG_WARNING, "r4=%016lx r5=%016lx\n",
+ ptr->xsave_hdr.reserved[4], ptr->xsave_hdr.reserved[5]);
#endif
- switch ( faults )
+
+ switch ( faults )
+ {
+ case 1: /* Stage 1: Reset state to be loaded. */
+ ptr->xsave_hdr.xstate_bv &= ~mask;
+ /*
+ * Also try to eliminate fault reasons, even if this shouldn't be
+ * needed here (other code should ensure the sanity of the data).
+ */
+ if ( ((mask & X86_XCR0_SSE) ||
+ ((mask & X86_XCR0_YMM) &&
+ !(ptr->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED))) )
+ ptr->fpu_sse.mxcsr &= mxcsr_mask;
+ if ( v->arch.xcr0_accum & XSTATE_XSAVES_ONLY )
{
- case 1: /* Stage 1: Reset state to be loaded. */
- ptr->xsave_hdr.xstate_bv &= ~mask;
- /*
- * Also try to eliminate fault reasons, even if this shouldn't be
- * needed here (other code should ensure the sanity of the data).
- */
- if ( ((mask & X86_XCR0_SSE) ||
- ((mask & X86_XCR0_YMM) &&
- !(ptr->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED))) )
- ptr->fpu_sse.mxcsr &= mxcsr_mask;
- if ( v->arch.xcr0_accum & XSTATE_XSAVES_ONLY )
- {
- ptr->xsave_hdr.xcomp_bv &= this_cpu(xcr0) | this_cpu(xss);
- ptr->xsave_hdr.xstate_bv &= ptr->xsave_hdr.xcomp_bv;
- ptr->xsave_hdr.xcomp_bv |= XSTATE_COMPACTION_ENABLED;
- }
- else
- {
- ptr->xsave_hdr.xstate_bv &= this_cpu(xcr0);
- ptr->xsave_hdr.xcomp_bv = 0;
- }
- memset(ptr->xsave_hdr.reserved, 0, sizeof(ptr->xsave_hdr.reserved));
- continue;
-
- case 2: /* Stage 2: Reset all state. */
- ptr->fpu_sse.mxcsr = MXCSR_DEFAULT;
- ptr->xsave_hdr.xstate_bv = 0;
- ptr->xsave_hdr.xcomp_bv = v->arch.xcr0_accum & XSTATE_XSAVES_ONLY
- ? XSTATE_COMPACTION_ENABLED : 0;
- continue;
+ ptr->xsave_hdr.xcomp_bv &= this_cpu(xcr0) | this_cpu(xss);
+ ptr->xsave_hdr.xstate_bv &= ptr->xsave_hdr.xcomp_bv;
+ ptr->xsave_hdr.xcomp_bv |= XSTATE_COMPACTION_ENABLED;
}
+ else
+ {
+ ptr->xsave_hdr.xstate_bv &= this_cpu(xcr0);
+ ptr->xsave_hdr.xcomp_bv = 0;
+ }
+ memset(ptr->xsave_hdr.reserved, 0, sizeof(ptr->xsave_hdr.reserved));
+ continue;
+
+ case 2: /* Stage 2: Reset all state. */
+ ptr->fpu_sse.mxcsr = MXCSR_DEFAULT;
+ ptr->xsave_hdr.xstate_bv = 0;
+ ptr->xsave_hdr.xcomp_bv = v->arch.xcr0_accum & XSTATE_XSAVES_ONLY
+ ? XSTATE_COMPACTION_ENABLED : 0;
+ continue;
+ }
domain_crash(current->domain);
return;
--
2.39.5
On 30.12.2025 14:54, Andrew Cooper wrote: > ... to improve the legibility of the following fix. ... wanting to replace the for() with an open-coded form of a loop. Which is fine, but could have done with saying here. > No functional change. > > Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Jan Beulich <jbeulich@suse.com> Jan
© 2016 - 2026 Red Hat, Inc.