x86/AMD: make HT range dynamic for Fam17 and up
PATCH v2 1/1 x86/AMD: make HT range dynamic for Fam17 and up
At the time of d838ac2539cf ("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.
To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of paddr_bits also gets adjusted.
While for paddr_bits < 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.
---
v2: Move adjustment last, to leave hap_paddr_bits unaffected. Add
comment.
xen/arch/x86/cpu/common.c +7 -0
@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; + vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS ) hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ; }if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON )))
xen/arch/x86/dom0_build.c +5 -2
@@ -524,8 +524,11 @@ int __init dom0_setup_permissions(struct MSI_ADDR_DEST_ID_MASK));/* HyperTransport range. */ if ( boot_cpu_data.x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ) ) - rc |=iomem_deny_access (d,paddr_to_pfn (0xfdULL <<32 ), -paddr_to_pfn ((1ULL <<40 ) -1 )); + { + mfn =paddr_to_pfn (1UL << + (boot_cpu_data.x86 <0x17 ?40 : paddr_bits)); + rc |=iomem_deny_access (d, mfn -paddr_to_pfn (3UL <<32 ), mfn -1 ); + }/* Remove access to E820_UNUSABLE I/O regions above 1MB. */ for ( i =0 ; i < e820.nr_map; i++ )
Ping: [PATCH v2] x86/AMD: make HT range dynamic for Fam17 and up
Quoted 13 lines · Jan Beulich
At the time of
d838ac2539cf("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of
paddr_bitsalso gets adjusted.While for
paddr_bits< 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.
Quoted 5 lines
Reported-by Igor Druzhinin <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
v2: Move adjustment last, to leavehap_paddr_bitsunaffected. Add
comment.
If there are any further adjustments needed here (or if the whole situation needs to be addressed differently altogether), could respective requests please be voiced? Or else may I please ask for an ack?
Jan
Quoted 44 lines
xen/arch/x86/cpu/common.c +7
-0@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; + vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS ) hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ; }if (!(c->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON )))xen/arch/x86/dom0_build.c +5
-2@@ -524,8 +524,11 @@ int __init dom0_setup_permissions(struct MSI_ADDR_DEST_ID_MASK));/* HyperTransport range. */ if ( boot_cpu_data.x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON ) ) - rc |=iomem_deny_access (d,paddr_to_pfn (0xfdULL <<32 ), -paddr_to_pfn ((1ULL <<40 ) -1 )); + { + mfn =paddr_to_pfn (1UL << + (boot_cpu_data.x86 <0x17 ?40 : paddr_bits)); + rc |=iomem_deny_access (d, mfn -paddr_to_pfn (3UL <<32 ), mfn -1 ); + }/* Remove access to E820_UNUSABLE I/O regions above 1MB. */ for ( i =0 ; i < e820.nr_map; i++ )
Quoted 9 lines · Jan Beulich
At the time of
d838ac2539cf("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of
paddr_bitsalso gets adjusted.
Quoted 6 lines
While for
paddr_bits< 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.Reported-by Igor Druzhinin <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Quoted 17 lines
---
v2: Move adjustment last, to leavehap_paddr_bitsunaffected. Add
comment.xen/arch/x86/cpu/common.c +3
-0@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; +
xen/arch/x86/cpu/common.c void __init early_cpu_init(void) · line 368
Quoted 10 lines
xen/arch/x86/cpu/common.c +4
-0vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS ) hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ;
Does it make sense to check for 0x8000001f[eax] bit 0 in order to assert that there's support for SME, or assuming that the reduction is != 0 in the other cpuid leaf is enough.
It's possible for firmware vendors to disable advertising the SME support bit and leave the physical address space reduction one in place?
Thanks, Roger.
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Jan Beulich
At the time of
d838ac2539cf("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of
paddr_bitsalso gets adjusted.
Quoted 8 lines
Quoted 6 lines
While for
paddr_bits< 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.Reported-by Igor Druzhinin <[email protected]>Signed-off-by Jan Beulich <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Thanks, but before applying this I'd prefer to resolve your concern voiced below.
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/cpu/common.c +4
-0@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; + vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS )
Quoted 8 lines
xen/arch/x86/cpu/common.c void __init early_cpu_init(void) · line 368
Quoted 4 lines
xen/arch/x86/cpu/common.c +3
-0hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ;Does it make sense to check for 0x8000001f[eax] bit 0 in order to assert that there's support for SME, or assuming that the reduction is != 0 in the other cpuid leaf is enough.
Documentation doesn't really tie them together afaics, so I thought I wouldn't either. I was reading into this lack of an explicit connection the possibility of address space reduction to also, hypothetically at this point, apply to other features.
Quoted 3 lines
It's possible for firmware vendors to disable advertising the SME support bit and leave the physical address space reduction one in place?
I don't know if it's possible (I'm unaware of e.g. MSR-level control allowing to modify these independently), but if it is I'd consider it inconsistent if one but not the other was zapped. I'm unconvinced that we really would need to deal with such inconsistencies, the more that it's not really clear what the inconsistent setting would really mean for the placement of the HT range.
While writing this, there was one more thing I came to think of:
Should we perhaps suppress the iomem_deny_access() altogether when running virtualized ourselves?
Jan
Quoted 60 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Jan Beulich
At the time of
d838ac2539cf("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of
paddr_bitsalso gets adjusted.Quoted 8 lines
Quoted 6 lines
While for
paddr_bits< 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.Reported-by Igor Druzhinin <[email protected]>Signed-off-by Jan Beulich <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Thanks, but before applying this I'd prefer to resolve your concern voiced below.
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/cpu/common.c +4
-0@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; + vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS )Quoted 8 lines
xen/arch/x86/cpu/common.c void __init early_cpu_init(void) · line 368
Quoted 4 lines
xen/arch/x86/cpu/common.c +3
-0hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ;Does it make sense to check for 0x8000001f[eax] bit 0 in order to assert that there's support for SME, or assuming that the reduction is != 0 in the other cpuid leaf is enough.
Documentation doesn't really tie them together afaics, so I thought I wouldn't either. I was reading into this lack of an explicit connection the possibility of address space reduction to also, hypothetically at this point, apply to other features.
Quoted 3 lines
It's possible for firmware vendors to disable advertising the SME support bit and leave the physical address space reduction one in place?
Quoted 6 lines
I don't know if it's possible (I'm unaware of e.g. MSR-level control allowing to modify these independently), but if it is I'd consider it inconsistent if one but not the other was zapped. I'm unconvinced that we really would need to deal with such inconsistencies, the more that it's not really clear what the inconsistent setting would really mean for the placement of the HT range.
Thanks, I think your proposed solution is fine.
Quoted 3 lines
While writing this, there was one more thing I came to think of:
Should we perhaps suppress theiomem_deny_access()altogether when running virtualized ourselves?
Hm, hard to tell TBH. HT being part of the platform specification for AMD it would feel wrong for hypervisors to attempt to populate this range.
Regards, Roger.
Quoted 70 lines · Roger Pau Monné
Quoted 60 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Jan Beulich
At the time of
d838ac2539cf("x86: don't allow Dom0 access to the HT address range") documentation correctly stated that the range was completely fixed. For Fam17 and newer, it lives at the top of physical address space, though.To correctly determine the top of physical address space, we need to account for their physical address reduction, hence the calculation of
paddr_bitsalso gets adjusted.Quoted 8 lines
Quoted 6 lines
While for
paddr_bits< 40 the HT range is completely hidden, there's no need to suppress the range insertion in that case: It'll just have no real meaning.Reported-by Igor Druzhinin <[email protected]>Signed-off-by Jan Beulich <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Thanks, but before applying this I'd prefer to resolve your concern voiced below.
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/cpu/common.c +4
-0@@ -349,16 +349,23 @@ void __init early_cpu_init(void) eax =cpuid_eax (0x80000000 );if ((eax >>16 ) ==0x8000 && eax >=0x80000008 ) { + ebx = eax >=0x8000001f ?cpuid_ebx (0x8000001f ) :0 ; eax =cpuid_eax (0x80000008 ); + paddr_bits = eax &0xff ;if (paddr_bits >PADDR_BITS ) paddr_bits =PADDR_BITS ; + vaddr_bits = (eax >>8 ) &0xff ;if (vaddr_bits >VADDR_BITS ) vaddr_bits =VADDR_BITS ; + hap_paddr_bits = ((eax >>16 ) &0xff ) ?: paddr_bits;if (hap_paddr_bits >PADDR_BITS )Quoted 8 lines
xen/arch/x86/cpu/common.c void __init early_cpu_init(void) · line 368
Quoted 4 lines
xen/arch/x86/cpu/common.c +3
-0hap_paddr_bits =PADDR_BITS ; + +/* Account for SME's physical address space reduction. */ + paddr_bits -= (ebx >>6 ) &0x3f ;Does it make sense to check for 0x8000001f[eax] bit 0 in order to assert that there's support for SME, or assuming that the reduction is != 0 in the other cpuid leaf is enough.
Documentation doesn't really tie them together afaics, so I thought I wouldn't either. I was reading into this lack of an explicit connection the possibility of address space reduction to also, hypothetically at this point, apply to other features.
Quoted 3 lines
It's possible for firmware vendors to disable advertising the SME support bit and leave the physical address space reduction one in place?
Quoted 6 lines
I don't know if it's possible (I'm unaware of e.g. MSR-level control allowing to modify these independently), but if it is I'd consider it inconsistent if one but not the other was zapped. I'm unconvinced that we really would need to deal with such inconsistencies, the more that it's not really clear what the inconsistent setting would really mean for the placement of the HT range.
Thanks, I think your proposed solution is fine.
Quoted 7 lines
Quoted 3 lines
While writing this, there was one more thing I came to think of:
Should we perhaps suppress theiomem_deny_access()altogether when running virtualized ourselves?Hm, hard to tell TBH. HT being part of the platform specification for AMD it would feel wrong for hypervisors to attempt to populate this range.
Okay, I'll leave it as is then. If we decide otherwise, we always can make an incremental change. Thanks for the feedback!
Jan