Skip to contentSkip to conversation

x86/Xen: swap NX determination and GDT setup on BSP

PATCH Applied Jan Beulich 3 participants 11 messages May 20, 2021 – May 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/Xen: swap NX determination and GDT setup on BSP

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs to be called first.

arch/x86/xen/enlighten_pv.c +4 -4
@@ -1273,16 +1273,16 @@ asmlinkage __visible void __init xen_sta
 	/* Get mfn list */
 	xen_build_dynamic_phys_to_machine();
 
+	/* Work out if we support NX */
+	get_cpu_cap(&boot_cpu_data);
+	x86_configure_nx();
+
 	/*
 	 * Set up kernel GDT and segment registers, mainly so that
 	 * -fstack-protector code can be executed.
 	 */
 	xen_setup_gdt(0);
 
-	/* Work out if we support NX */
-	get_cpu_cap(&boot_cpu_data);
-	x86_configure_nx();
-
 	/* Determine virtual and physical address sizes */
 	get_cpu_address_sizes(&boot_cpu_data);
 
#2 lore raw
Quoted 9 lines · Juergen Gross
Quoted 6 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs to be called first.

Thanks. I guess I forgot

If you agree, can you please add this before pushing to Linus?

Jan

maintainer
#3 lore raw
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Juergen Gross
Quoted 6 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs to be called first.

Quoted 7 lines
Quoted 1 line

Thanks. I guess I forgot

If you agree, can you please add this before pushing to Linus?

Yes, will do that.

Juergen

maintainer
#4 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Juergen Gross
Quoted 6 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs to be called first.

Quoted 7 lines
Quoted 1 line

Thanks. I guess I forgot

If you agree, can you please add this before pushing to Linus?

Uh, just had a look why x86_configure_nx() was called after xen_setup_gdt().

Upstream your patch will be fine, but before kernel 5.9 it will break running as 32-bit PV guest (see commit 36104cb9012a82e7).

So I will take your patch as is, but for kernels 5.8 and older I recommend a different approach by directly setting the NX capability after checking the cpuid bit instead of letting that do get_cpu_cap().

Juergen

#5 lore raw
Quoted 16 lines · Juergen Gross
Quoted 15 lines · Jan Beulich
Quoted 9 lines · Juergen Gross
Quoted 6 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs to be called first.

Thanks. I guess I forgot

Quoted 7 lines
Quoted 1 line

If you agree, can you please add this before pushing to Linus?

Uh, just had a look why x86_configure_nx() was called after xen_setup_gdt().

Upstream your patch will be fine, but before kernel 5.9 it will break running as 32-bit PV guest (see commit 36104cb9012a82e7).

Oh, indeed. That commit then actually introduced the issue here, and hence a Fixes: tag may be warranted.

Quoted 4 lines

So I will take your patch as is, but for kernels 5.8 and older I recommend a different approach by directly setting the NX capability after checking the cpuid bit instead of letting that do get_cpu_cap().

Right - perhaps the only halfway viable option.

64-bit kernels predating 4f277295e54c may then also need that one, but perhaps all stable ones already have it because it was tagged for stable.

Jan

maintainer
#6 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Juergen Gross
Quoted 2 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs

to

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
Quoted 4 lines

be called first.

Thanks. I guess I forgot

If you agree, can you please add this before pushing to Linus?

Quoted 8 lines
Quoted 5 lines

Uh, just had a look why x86_configure_nx() was called after xen_setup_gdt().

Upstream your patch will be fine, but before kernel 5.9 it will break running as 32-bit PV guest (see commit 36104cb9012a82e7).

Oh, indeed. That commit then actually introduced the issue here, and hence a Fixes: tag may be warranted.

Added it already. :-)

And I've limited the backport to happen not for 5.8 and older, of course.

Juergen

#7 lore raw
Quoted 27 lines · Juergen Gross
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Juergen Gross
Quoted 2 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs

to

Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

be called first.

Quoted 7 lines
Quoted 1 line

Thanks. I guess I forgot

If you agree, can you please add this before pushing to Linus?

Uh, just had a look why x86_configure_nx() was called after xen_setup_gdt().

Upstream your patch will be fine, but before kernel 5.9 it will break running as 32-bit PV guest (see commit 36104cb9012a82e7).

Quoted 7 lines
Quoted 2 lines

Oh, indeed. That commit then actually introduced the issue here, and hence a Fixes: tag may be warranted.

Added it already. :-)

And I've limited the backport to happen not for 5.8 and older, of course.

Did something changed recently that this became a problem? That commit has been there for 3 years.

Didn't Olaf report this to be a problem only on SLES kernels?

-boris

#8 lore raw
Quoted 32 lines · Boris Ostrovsky
Quoted 30 lines · Juergen Gross
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Juergen Gross
Quoted 2 lines · Jan Beulich

xen_setup_gdt(), via xen_load_gdt_boot(), wants to adjust page tables. For this to work when NX is not available, x86_configure_nx() needs

to

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

be called first.

Thanks. I guess I forgot

Quoted 7 lines
Quoted 1 line

If you agree, can you please add this before pushing to Linus?

Uh, just had a look why x86_configure_nx() was called after xen_setup_gdt().

Upstream your patch will be fine, but before kernel 5.9 it will break running as 32-bit PV guest (see commit 36104cb9012a82e7).

Oh, indeed. That commit then actually introduced the issue here, and hence a Fixes: tag may be warranted.

Quoted 7 lines
Quoted 4 lines

Added it already. :-)

And I've limited the backport to happen not for 5.8 and older, of course.

Did something changed recently that this became a problem? That commit has been there for 3 years.

He happened to try on a system where NX was turned off in the BIOS. That's not a setting you would usually find in use.

Quoted 1 line

Didn't Olaf report this to be a problem only on SLES kernels?

Which I assume have backports of the problematic change.

Jan

#9 lore raw
Quoted 4 lines · Jan Beulich
Quoted 2 lines · Boris Ostrovsky

Did something changed recently that this became a problem? That commit has been there for 3 years.

He happened to try on a system where NX was turned off in the BIOS.

Yes, I missed that part.

-boris