Qemu SEV reduced-phys-bits fixes
cover Qemu SEV reduced-phys-bits fixes
This patch series fixes up and tries to remove some confusion around the SEV reduced-phys-bits parameter.
Based on the "AMD64 Architecture Programmer's Manual Volume 2: System Programming", section "15.34.6 Page Table Support" [1], a guest should only ever see a maximum of 1 bit of physical address space reduction.
- Update the documentation, to change the default value from 5 to 1.
- Update the validation of the parameter to ensure the parameter value is within the range of the CPUID field that it is reported in. To allow for backwards compatibility, especially to support the previously documented value of 5, allow the full range of values from 1 to 63 (0 was never allowed).
- Update the setting of CPUID 0x8000001F_EBX to limit the values to the field width that they are setting as an additional safeguard.
[1] https://www.amd.com/system/files/TechDocs/24593.pdf
Tom Lendacky (4):
qapi, i386/sev: Change the reduced-phys-bits value from 5 to 1 qemu-options.hx: Update the reduced-phys-bits documentation i386/sev: Update checks and information related to reduced-phys-bits i386/cpu: Update how the EBX register of CPUID 0x8000001F is set
qapi/misc-target.json | 2 +- qemu-options.hx | 4 ++-- target/i386/cpu.c | 4 ++-- target/i386/sev.c | 17 ++++++++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.3
PATCH 1/4 qapi, i386/sev: Change the reduced-phys-bits value from 5 to 1
A guest only ever experiences, at most, 1 bit of reduced physical addressing. Change the query-sev-capabilities json comment to use 1.
--- qapi/misc-target.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +1 -1
@@ -172,7 +172,7 @@ # -> { "execute": "query-sev-capabilities" } # <- { "return": { "pdh": "8CCDD8DDD", "cert-chain": "888CCCDDDEE", # "cpu0-id": "2lvmGwo+...61iEinw==", -# "cbitpos": 47, "reduced-phys-bits": 5}} +# "cbitpos": 47, "reduced-phys-bits": 1}} # ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability',
Signature · 1 line
2.37.3
Re: [PATCH 1/4] qapi, i386/sev: Change the reduced-phys-bits value from 5 to 1
Quoted 5 lines · * Tom Lendacky ([email protected]) wrote:
A guest only ever experiences, at most, 1 bit of reduced physical addressing. Change the query-sev-capabilities json comment to use 1.
Fixes 31dd67f684 ("sev/i386: qmp: add query-sev-capabilities command")Signed-off-by Tom Lendacky <[email protected]>
Quoted 21 lines
--- qapi/misc-target.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qapi/misc-target.json +1
-1@@ -172,7 +172,7 @@ # -> { "execute": "query-sev-capabilities" } # <- { "return": { "pdh": "8CCDD8DDD", "cert-chain": "888CCCDDDEE", # "cpu0-id": "2lvmGwo+...61iEinw==", -# "cbitpos": 47, "reduced-phys-bits": 5}} +# "cbitpos": 47, "reduced-phys-bits": 1}} # ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability',Signature · 1 line
2.37.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 2/4 qemu-options.hx: Update the reduced-phys-bits documentation
In reply to Tom LendackyA guest only ever experiences, at most, 1 bit of reduced physical addressing. Update the documentation to reflect this as well as change the example value on the reduced-phys-bits option.
--- qemu-options.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu-options.hx +2 -2
@@ -5391,7 +5391,7 @@ SRST physical address space. The ``reduced-phys-bits`` is used to provide the number of bits we loose in physical address space. Similar to C-bit, the value is Host family dependent. On EPYC, - the value should be 5. + a guest will lose a maximum of 1 bit, so the value should be 1. The ``sev-device`` provides the device file to use for communicating with the SEV firmware running inside AMD Secure
@@ -5426,7 +5426,7 @@ SRST # |qemu_system_x86| \\ ...... \\ - -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=5 \\ + -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=1 \\ -machine ...,memory-encryption=sev0 \\ .....
Signature · 1 line
2.37.3
Re: [PATCH 2/4] qemu-options.hx: Update the reduced-phys-bits documentation
Quoted 6 lines · * Tom Lendacky ([email protected]) wrote:
A guest only ever experiences, at most, 1 bit of reduced physical addressing. Update the documentation to reflect this as well as change the example value on the reduced-phys-bits option.
Fixes a9b4942f48 ("target/i386: add Secure Encrypted Virtualization (SEV) object")Signed-off-by Tom Lendacky <[email protected]>
Quoted 30 lines
--- qemu-options.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)qemu-options.hx +2
-2@@ -5391,7 +5391,7 @@ SRST physical address space. The ``reduced-phys-bits`` is used to provide the number of bits we loose in physical address space. Similar to C-bit, the value is Host family dependent. On EPYC, - the value should be 5. + a guest will lose a maximum of 1 bit, so the value should be 1. The ``sev-device`` provides the device file to use for communicating with the SEV firmware running inside AMD Secure@@ -5426,7 +5426,7 @@ SRST # |qemu_system_x86| \\ ...... \\ - -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=5 \\ + -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=1 \\ -machine ...,memory-encryption=sev0 \\Signature · 2 lines
-- 2.37.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 3/4 i386/sev: Update checks and information related to reduced-phys-bits
In reply to Tom LendackyThe value of the reduced-phys-bits parameter is propogated to the CPUID information exposed to the guest. Update the current validation check to account for the size of the CPUID field (6-bits), ensuring the value is in the range of 1 to 63.
Maintain backward compatibility, to an extent, by allowing a value greater than 1 (so that the previously documented value of 5 still works), but not allowing anything over 63.
--- target/i386/sev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
target/i386/sev.c +14 -3
@@ -932,15 +932,26 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)host_cpuid (0x8000001F ,0 ,NULL , &ebx,NULL ,NULL ); host_cbitpos = ebx &0x3f ; +/* +* The cbitpos value will be placed in bit positions 5:0 of the EBX +* register of CPUID 0x8000001F. No need to verify the range as the +* comparison against the host value accomplishes that. +*/ if (host_cbitpos != sev->cbitpos) {error_setg (errp,"%s: cbitpos check failed, host '%d' requested '%d'" , __func__, host_cbitpos, sev->cbitpos); goto err; } -if (sev->reduced_phys_bits <1 ) { -error_setg (errp,"%s: reduced_phys_bits check failed, it should be >=1," -" requested '%d'" , __func__, sev->reduced_phys_bits); +/* +* The reduced-phys-bits value will be placed in bit positions 11:6 of +* the EBX register of CPUID 0x8000001F, so verify the supplied value +* is in the range of 1 to 63. +*/ +if (sev->reduced_phys_bits <1 || sev->reduced_phys_bits >63 ) { +error_setg (errp,"%s: reduced_phys_bits check failed," +" it should be in the range of 1 to 63, requested '%d'" , + __func__, sev->reduced_phys_bits); goto err; }
Signature · 1 line
2.37.3
Re: [PATCH 3/4] i386/sev: Update checks and information related to reduced-phys-bits
Quoted 11 lines · * Tom Lendacky ([email protected]) wrote:
The value of the reduced-phys-bits parameter is propogated to the CPUID information exposed to the guest. Update the current validation check to account for the size of the CPUID field (6-bits), ensuring the value is in the range of 1 to 63.
Maintain backward compatibility, to an extent, by allowing a value greater than 1 (so that the previously documented value of 5 still works), but not allowing anything over 63.
Fixes d8575c6c02 ("sev/i386: add command to initialize the memory encryption context")Signed-off-by Tom Lendacky <[email protected]>
Quoted 42 lines
--- target/i386/sev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)target/i386/sev.c +14
-3@@ -932,15 +932,26 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)host_cpuid (0x8000001F ,0 ,NULL , &ebx,NULL ,NULL ); host_cbitpos = ebx &0x3f ; +/* +* The cbitpos value will be placed in bit positions 5:0 of the EBX +* register of CPUID 0x8000001F. No need to verify the range as the +* comparison against the host value accomplishes that. +*/ if (host_cbitpos != sev->cbitpos) {error_setg (errp,"%s: cbitpos check failed, host '%d' requested '%d'" , __func__, host_cbitpos, sev->cbitpos); goto err; } -if (sev->reduced_phys_bits <1 ) { -error_setg (errp,"%s: reduced_phys_bits check failed, it should be >=1," -" requested '%d'" , __func__, sev->reduced_phys_bits); +/* +* The reduced-phys-bits value will be placed in bit positions 11:6 of +* the EBX register of CPUID 0x8000001F, so verify the supplied value +* is in the range of 1 to 63. +*/ +if (sev->reduced_phys_bits <1 || sev->reduced_phys_bits >63 ) { +error_setg (errp,"%s: reduced_phys_bits check failed," +" it should be in the range of 1 to 63, requested '%d'" , + __func__, sev->reduced_phys_bits); goto err; }Signature · 1 line
2.37.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 4/4 i386/cpu: Update how the EBX register of CPUID 0x8000001F is set
In reply to Tom LendackyUpdate the setting of CPUID 0x8000001F EBX to clearly document the ranges associated with fields being set.
--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/cpu.c +2 -2
@@ -5853,8 +5853,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (sev_enabled ()) { *eax =0x2 ; *eax |=sev_es_enabled () ?0x8 :0 ; - *ebx =sev_get_cbit_position (); - *ebx |=sev_get_reduced_phys_bits () <<6 ; + *ebx =sev_get_cbit_position () &0x3f ;/* EBX[5:0] */ + *ebx |= (sev_get_reduced_phys_bits () &0x3f ) <<6 ;/* EBX[11:6] */ }break ;default :
Signature · 1 line
2.37.3
Re: [PATCH 4/4] i386/cpu: Update how the EBX register of CPUID 0x8000001F is set
Quoted 5 lines · * Tom Lendacky ([email protected]) wrote:
Update the setting of CPUID
0x8000001FEBX to clearly document the ranges associated with fields being set.Fixes 6cb8f2a663 ("cpu/i386: populate CPUID 0x8000_001F when SEV is active")Signed-off-by Tom Lendacky <[email protected]>
Quoted 23 lines
--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/cpu.c +2
-2@@ -5853,8 +5853,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (sev_enabled ()) { *eax =0x2 ; *eax |=sev_es_enabled () ?0x8 :0 ; - *ebx =sev_get_cbit_position (); - *ebx |=sev_get_reduced_phys_bits () <<6 ; + *ebx =sev_get_cbit_position () &0x3f ;/* EBX[5:0] */ + *ebx |= (sev_get_reduced_phys_bits () &0x3f ) <<6 ;/* EBX[11:6] */ }break ;default :Signature · 1 line
2.37.3
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 16 lines · Tom Lendacky
This patch series fixes up and tries to remove some confusion around the SEV reduced-phys-bits parameter.
Based on the "AMD64 Architecture Programmer's Manual Volume 2: System Programming", section "15.34.6 Page Table Support" [1], a guest should only ever see a maximum of 1 bit of physical address space reduction.
- Update the documentation, to change the default value from 5 to 1.
- Update the validation of the parameter to ensure the parameter value is within the range of the CPUID field that it is reported in. To allow for backwards compatibility, especially to support the previously documented value of 5, allow the full range of values from 1 to 63 (0 was never allowed).
- Update the setting of CPUID 0x8000001F_EBX to limit the values to the field width that they are setting as an additional safeguard.
Quoted 1 line
Ping, any concerns with this series?
Thanks,
Tom
Quoted 13 lines
Tom Lendacky (4):
qapi, i386/sev: Change the reduced-phys-bits value from 5 to 1 qemu-options.hx: Update the reduced-phys-bits documentation i386/sev: Update checks and information related to reduced-phys-bits i386/cpu: Update how the EBX register of CPUID0x8000001Fis setqapi/misc-target.json | 2 +- qemu-options.hx | 4 ++-- target/i386/cpu.c | 4 ++-- target/i386/sev.c | 17 ++++++++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-)
Quoted 17 lines · Tom Lendacky
Quoted 16 lines · Tom Lendacky
This patch series fixes up and tries to remove some confusion around the SEV reduced-phys-bits parameter.
Based on the "AMD64 Architecture Programmer's Manual Volume 2: System Programming", section "15.34.6 Page Table Support" [1], a guest should only ever see a maximum of 1 bit of physical address space reduction.
- Update the documentation, to change the default value from 5 to 1.
- Update the validation of the parameter to ensure the parameter value is within the range of the CPUID field that it is reported in. To allow for backwards compatibility, especially to support the previously documented value of 5, allow the full range of values from 1 to 63 (0 was never allowed).
- Update the setting of CPUID 0x8000001F_EBX to limit the values to the field width that they are setting as an additional safeguard.
Quoted 3 lines
Quoted 1 line
Ping, any concerns with this series?
Looks like you got postive review from David in Oct, so this needs one of the x86 maintainers to queue the series.
Quoted 6 lines
Quoted 6 lines
Tom Lendacky (4):
qapi, i386/sev: Change the reduced-phys-bits value from 5 to 1 qemu-options.hx: Update the reduced-phys-bits documentation i386/sev: Update checks and information related to reduced-phys-bits i386/cpu: Update how the EBX register of CPUID0x8000001Fis set
Quoted 7 lines
Quoted 6 lines
qapi/misc-target.json | 2 +- qemu-options.hx | 4 ++-- target/i386/cpu.c | 4 ++-- target/i386/sev.c | 17 ++++++++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Queued, thanks.
Paolo