Skip to contentSkip to conversation

x86/FPU: make vcpu_reset_fpu() build again with old gcc

PATCH In review Jan Beulich 2 participants 6 messages Dec 9, 2024 – Dec 10, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/FPU: make vcpu_reset_fpu() build again with old gcc

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Fixes 49a068471d77 ("x86/fpu: Rework fpu_setup_fpu() uses to split it in two")
xen/arch/x86/i387.c +5 -5
@@ -306,13 +306,13 @@ void vcpu_reset_fpu(struct vcpu *v)
 {
     v->fpu_initialised = false;
     *v->arch.xsave_area = (struct xsave_struct) {
-        .fpu_sse = {
-            .mxcsr = MXCSR_DEFAULT,
-            .fcw = FCW_RESET,
-            .ftw = FXSAVE_FTW_RESET,
-        },
         .xsave_hdr.xstate_bv = X86_XCR0_X87,
     };
+
+    /* Old gcc doesn't permit these to be part of the initializer. */
+    v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT;
+    v->arch.xsave_area->fpu_sse.fcw = FCW_RESET;
+    v->arch.xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET;
 }
 
 void vcpu_setup_fpu(struct vcpu *v, const void *data)
#1 lore raw
Quoted 2 lines · Jan Beulich

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Can you add the specific version for tracking purposes?

Quoted 12 lines
Fixes 49a068471d77 ("x86/fpu: Rework fpu_setup_fpu() uses to split it in two")
xen/arch/x86/i387.c +0 -2
@@ -306,13 +306,13 @@ void vcpu_reset_fpu(struct vcpu *v)
 {
     v->fpu_initialised = false;
     *v->arch.xsave_area = (struct xsave_struct) {
-        .fpu_sse = {
-            .mxcsr = MXCSR_DEFAULT,

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 315

Quoted 10 lines
xen/arch/x86/i387.c +5 -3
-            .fcw = FCW_RESET,
-            .ftw = FXSAVE_FTW_RESET,
-        },
         .xsave_hdr.xstate_bv = X86_XCR0_X87,
     };
+
+    /* Old gcc doesn't permit these to be part of the initializer. */
+    v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT;
+    v->arch.xsave_area->fpu_sse.fcw = FCW_RESET;
+    v->arch.xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET;

That's not quite the same though. A more apt equivalence would be to memset the area to zero ahead of the assignments. Otherwise rubble will be left behind.

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 318

Quoted 3 lines
xen/arch/x86/i387.c +0 -0
 }
 
 void vcpu_setup_fpu(struct vcpu *v, const void *data)

Out of context and not triggering the GCC bug, but vcpu_setup_fpu() should probably share the same initialization style as vcpu_reset_fpu(), imo.

Cheers,
Alejandro

#2 lore raw
Quoted 5 lines · Alejandro Vallejo
Quoted 2 lines · Jan Beulich

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Can you add the specific version for tracking purposes?

It's all the same as before, and I really didn't want to waste time on once again figuring out which exact version it was that the behavior changed to the better.

Quoted 16 lines
Quoted 16 lines
Fixes 49a068471d77 ("x86/fpu: Rework fpu_setup_fpu() uses to split it in two")
xen/arch/x86/i387.c +0 -5
@@ -306,13 +306,13 @@ void vcpu_reset_fpu(struct vcpu *v)
 {
     v->fpu_initialised = false;
     *v->arch.xsave_area = (struct xsave_struct) {
-        .fpu_sse = {
-            .mxcsr = MXCSR_DEFAULT,
-            .fcw = FCW_RESET,
-            .ftw = FXSAVE_FTW_RESET,
-        },
         .xsave_hdr.xstate_bv = X86_XCR0_X87,
     };
Quoted 8 lines

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 315

Quoted 5 lines
xen/arch/x86/i387.c +5 -0
+
+    /* Old gcc doesn't permit these to be part of the initializer. */
+    v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT;
+    v->arch.xsave_area->fpu_sse.fcw = FCW_RESET;
+    v->arch.xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET;

That's not quite the same though. A more apt equivalence would be to memset the area to zero ahead of the assignments. Otherwise rubble will be left behind.

No. I didn't delete the initializer. All fields not mentioned there will be default-initialized.

Quoted 6 lines

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 318

Quoted 3 lines
xen/arch/x86/i387.c +0 -0
 }
 
 void vcpu_setup_fpu(struct vcpu *v, const void *data)

Out of context and not triggering the GCC bug, but vcpu_setup_fpu() should probably share the same initialization style as vcpu_reset_fpu(), imo.

Why?

Jan

#3 lore raw
Quoted 10 lines · Jan Beulich
Quoted 5 lines · Alejandro Vallejo
Quoted 2 lines · Jan Beulich

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Can you add the specific version for tracking purposes?

It's all the same as before, and I really didn't want to waste time on once again figuring out which exact version it was that the behavior changed to the better.

Just checked on Godbolt. 4.7.1 works and 4.6.4 doesn't. Adding that data point to the commit message really helps when navigating git-blame, even if it's not as precise as it could be. Particularly if one wants to understand exactly which quirk of which version of which compiler is being dealt with.

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Fixes 49a068471d77 ("x86/fpu: Rework fpu_setup_fpu() uses to split it in two")
xen/arch/x86/i387.c +0 -5
@@ -306,13 +306,13 @@ void vcpu_reset_fpu(struct vcpu *v)
 {
     v->fpu_initialised = false;
     *v->arch.xsave_area = (struct xsave_struct) {
-        .fpu_sse = {
-            .mxcsr = MXCSR_DEFAULT,
-            .fcw = FCW_RESET,
-            .ftw = FXSAVE_FTW_RESET,
-        },
         .xsave_hdr.xstate_bv = X86_XCR0_X87,
     };
Quoted 8 lines

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 315

Quoted 5 lines
xen/arch/x86/i387.c +5 -0
+
+    /* Old gcc doesn't permit these to be part of the initializer. */
+    v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT;
+    v->arch.xsave_area->fpu_sse.fcw = FCW_RESET;
+    v->arch.xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET;

That's not quite the same though. A more apt equivalence would be to memset the area to zero ahead of the assignments. Otherwise rubble will be left behind.

Quoted 2 lines

No. I didn't delete the initializer. All fields not mentioned there will be default-initialized.

Right. I misread the diff and thought you had nuked the initializer. That's indeed all fine. Which means...

Quoted 9 lines
Quoted 7 lines

xen/arch/x86/i387.c void vcpu_reset_fpu(struct vcpu *v) · line 318

Quoted 4 lines
xen/arch/x86/i387.c +0 -0
 }
 
 void vcpu_setup_fpu(struct vcpu *v, const void *data)

Out of context and not triggering the GCC bug, but vcpu_setup_fpu() should probably share the same initialization style as vcpu_reset_fpu(), imo.

Why?

... there's indeed no reason to touch that.

Quoted 2 lines

Jan

With the commit message adjusted with the offending GCC version (i.e: <4.7.1):

Cheers,
Alejandro

#4 lore raw
Quoted 8 lines · Alejandro Vallejo
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Alejandro Vallejo
Quoted 2 lines · Jan Beulich

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Can you add the specific version for tracking purposes?

Quoted 8 lines
Quoted 3 lines

It's all the same as before, and I really didn't want to waste time on once again figuring out which exact version it was that the behavior changed to the better.

Just checked on Godbolt. 4.7.1 works and 4.6.4 doesn't. Adding that data point to the commit message really helps when navigating git-blame, even if it's not as precise as it could be. Particularly if one wants to understand exactly which quirk of which version of which compiler is being dealt with.

Well, thanks for sorting that out. I've added that info.

Quoted 3 lines

With the commit message adjusted with the offending GCC version (i.e: <4.7.1):

Thanks here as well. Any chance though you would be willing to upgrade that to R-b? Only that would allow me to put in the patch without waiting for yet another tag.

Jan

Reviewed-by
#5 lore raw
Quoted 23 lines · Jan Beulich
Quoted 8 lines · Alejandro Vallejo
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Alejandro Vallejo
Quoted 2 lines · Jan Beulich

Fields of anonymous structs/unions may not be part of an initializer for rather old gcc.

Can you add the specific version for tracking purposes?

Quoted 8 lines
Quoted 3 lines

It's all the same as before, and I really didn't want to waste time on once again figuring out which exact version it was that the behavior changed to the better.

Just checked on Godbolt. 4.7.1 works and 4.6.4 doesn't. Adding that data point to the commit message really helps when navigating git-blame, even if it's not as precise as it could be. Particularly if one wants to understand exactly which quirk of which version of which compiler is being dealt with.

Well, thanks for sorting that out. I've added that info.

Quoted 2 lines

With the commit message adjusted with the offending GCC version (i.e: <4.7.1):

Quoted 7 lines
Quoted 1 line

Thanks here as well. Any chance though you would be willing to upgrade that to R-b? Only that would allow me to put in the patch without waiting for yet another tag.

Jan

Sure.

Cheers,
Alejandro