Skip to contentSkip to conversation

x86/CPU: don't hard-code MTRR availability

PATCH In review Jan Beulich 2 participants 8 messages Mar 25, 2025 – Mar 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/CPU: don't hard-code MTRR availability

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")
xen/arch/x86/include/asm/cpufeature.h +1 -1
@@ -70,7 +70,7 @@ static inline bool boot_cpu_has(unsigned
 #define cpu_has_pse             1
 #define cpu_has_apic            boot_cpu_has(X86_FEATURE_APIC)
 #define cpu_has_sep             boot_cpu_has(X86_FEATURE_SEP)
-#define cpu_has_mtrr            1
+#define cpu_has_mtrr            boot_cpu_has(X86_FEATURE_MTRR)
 #define cpu_has_pge             1
 #define cpu_has_pse36           boot_cpu_has(X86_FEATURE_PSE36)
 #define cpu_has_clflush         boot_cpu_has(X86_FEATURE_CLFLUSH)
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Jan Beulich

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

At least for Xen, I think we offer MTRR uniformly, even on PVH guests?

Quoted 2 lines
Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

(or alternatively short-circuiting cpu_has_mtrr == 0?)

Thanks, Roger.

#2 lore raw
Quoted 6 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

At least for Xen, I think we offer MTRR uniformly, even on PVH guests?

By default we do, but we discussed the option of offering PAT-only environments beyond leaving it open whether people disabling MTRR support in their guest config are outside of supported terrain.

Quoted 9 lines
Quoted 2 lines
Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

(or alternatively short-circuiting cpu_has_mtrr == 0?)

I didn't think this would be a prereq here. If we boot in an environment truly lacking MTRR, we'll crash on the first MTRR MSR access - none of those accesses use the safe accessors. Since you asked, I tried booting with "cpuid=no-mtrr". As I'm doing this on a system with console, all I can say is that it takes minutes to reach the point where we'd start setting up Dom0 (which itself then takes so long that I timed out waiting for it to make progress), due to all screen output becoming unbelievably slow after AP bringup. Surely something's screwed somewhere, as VRAM accesses being slow (or fast) shouldn't depend on AP bringup having completed. I actually suspect it's not just VRAM accesses which are slow, but that we're left running in uncachable mode altogether for whatever reason.

What this maybe useful for is to figure out the reason of "Platform timer appears to have unexpectedly wrapped <N> times", which I saw appear once.

Given this, I'm actually uncertain whether it is legitimate then to take your ack.

Jan

#3 lore raw
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

(or alternatively short-circuiting cpu_has_mtrr == 0?)

Quoted 11 lines

I didn't think this would be a prereq here. If we boot in an environment truly lacking MTRR, we'll crash on the first MTRR MSR access - none of those accesses use the safe accessors. Since you asked, I tried booting with "cpuid=no-mtrr". As I'm doing this on a system with console, all I can say is that it takes minutes to reach the point where we'd start setting up Dom0 (which itself then takes so long that I timed out waiting for it to make progress), due to all screen output becoming unbelievably slow after AP bringup. Surely something's screwed somewhere, as VRAM accesses being slow (or fast) shouldn't depend on AP bringup having completed. I actually suspect it's not just VRAM accesses which are slow, but that we're left running in uncachable mode altogether for whatever reason.

I think found a trivial way to avoid this, and the change there imo makes sense even if I can't explain this particular aspect of it. I'll submit that independently.

Jan

#4 lore raw
In reply to Jan Beulich
Quoted 17 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

At least for Xen, I think we offer MTRR uniformly, even on PVH guests?

By default we do, but we discussed the option of offering PAT-only environments beyond leaving it open whether people disabling MTRR support in their guest config are outside of supported terrain.

Quoted 5 lines
Quoted 2 lines
Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")
Quoted 8 lines
Quoted 4 lines

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

(or alternatively short-circuiting cpu_has_mtrr == 0?)

I didn't think this would be a prereq here. If we boot in an environment truly lacking MTRR, we'll crash on the first MTRR MSR access - none of those accesses use the safe accessors.

Right, hopefully we don't have unprotected MTRR MSR accesses, so cpu_has_mtrr == 0 should prevent those.

Quoted 10 lines

Since you asked, I tried booting with "cpuid=no-mtrr".
As I'm doing this on a system with console, all I can say is that it takes minutes to reach the point where we'd start setting up Dom0 (which itself then takes so long that I timed out waiting for it to make progress), due to all screen output becoming unbelievably slow after AP bringup. Surely something's screwed somewhere, as VRAM accesses being slow (or fast) shouldn't depend on AP bringup having completed. I actually suspect it's not just VRAM accesses which are slow, but that we're left running in uncachable mode altogether for whatever reason.

Quoted 5 lines

What this maybe useful for is to figure out the reason of "Platform timer appears to have unexpectedly wrapped <N> times", which I saw appear once.

Given this, I'm actually uncertain whether it is legitimate then to take your ack.

I think it might be best if we can figure out what causes those issues (and possibly fix them) before taking this patch?

Albeit you could argue that running excruciatingly slow is better than just crashing of an unhandled #GP from a rdmsr.

Thanks, Roger.

#5 lore raw
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

At least for Xen, I think we offer MTRR uniformly, even on PVH guests?

By default we do, but we discussed the option of offering PAT-only environments beyond leaving it open whether people disabling MTRR support in their guest config are outside of supported terrain.

Quoted 8 lines
Quoted 2 lines
Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

(or alternatively short-circuiting cpu_has_mtrr == 0?)

I didn't think this would be a prereq here. If we boot in an environment truly lacking MTRR, we'll crash on the first MTRR MSR access - none of those accesses use the safe accessors.

Right, hopefully we don't have unprotected MTRR MSR accesses, so cpu_has_mtrr == 0 should prevent those.

Actually we do, see my other patch just posted.

Quoted 13 lines
Quoted 13 lines

Since you asked, I tried booting with "cpuid=no-mtrr".
As I'm doing this on a system with console, all I can say is that it takes minutes to reach the point where we'd start setting up Dom0 (which itself then takes so long that I timed out waiting for it to make progress), due to all screen output becoming unbelievably slow after AP bringup. Surely something's screwed somewhere, as VRAM accesses being slow (or fast) shouldn't depend on AP bringup having completed. I actually suspect it's not just VRAM accesses which are slow, but that we're left running in uncachable mode altogether for whatever reason.

What this maybe useful for is to figure out the reason of "Platform timer appears to have unexpectedly wrapped <N> times", which I saw appear once.

Quoted 8 lines
Quoted 2 lines

Given this, I'm actually uncertain whether it is legitimate then to take your ack.

I think it might be best if we can figure out what causes those issues (and possibly fix them) before taking this patch?

Albeit you could argue that running excruciatingly slow is better than just crashing of an unhandled #GP from a rdmsr.

Indeed that's my thinking. But if you prefer, I can wait with this patch until after the other one has gone in.

Jan

#6 lore raw
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Roger Pau Monné
Quoted 22 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich

In particular if we're running virtualized, the underlying hypervisor (which may be another Xen) may not surface MTRRs, and offer PAT only.

At least for Xen, I think we offer MTRR uniformly, even on PVH guests?

By default we do, but we discussed the option of offering PAT-only environments beyond leaving it open whether people disabling MTRR support in their guest config are outside of supported terrain.

Quoted 9 lines
Quoted 2 lines
Fixes 5a281883cdc3 ("Hardcode many cpu features for x86/64 -- we know 64-bit")

My main concern is whether the !mtrr path is still functional. Have you tried booting the resulting hypervisor with MTRR masked on CPUID?

(or alternatively short-circuiting cpu_has_mtrr == 0?)

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I didn't think this would be a prereq here. If we boot in an environment truly lacking MTRR, we'll crash on the first MTRR MSR access - none of those accesses use the safe accessors.

Right, hopefully we don't have unprotected MTRR MSR accesses, so cpu_has_mtrr == 0 should prevent those.

Actually we do, see my other patch just posted.

Oh, yes, that was one of my concerns, but I've failed to spot it.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

Since you asked, I tried booting with "cpuid=no-mtrr".
As I'm doing this on a system with console, all I can say is that it takes minutes to reach the point where we'd start setting up Dom0 (which itself then takes so long that I timed out waiting for it to make progress), due to all screen output becoming unbelievably slow after AP bringup. Surely something's screwed somewhere, as VRAM accesses being slow (or fast) shouldn't depend on AP bringup having completed. I actually suspect it's not just VRAM accesses which are slow, but that we're left running in uncachable mode altogether for whatever reason.

What this maybe useful for is to figure out the reason of "Platform timer appears to have unexpectedly wrapped <N> times", which I saw appear once.

Given this, I'm actually uncertain whether it is legitimate then to take your ack.

Quoted 8 lines
Quoted 5 lines

I think it might be best if we can figure out what causes those issues (and possibly fix them) before taking this patch?

Albeit you could argue that running excruciatingly slow is better than just crashing of an unhandled #GP from a rdmsr.

Indeed that's my thinking. But if you prefer, I can wait with this patch until after the other one has gone in.

Given the small context of the other patch, you might as well put both in together.

Thanks, Roger.