SEV-SNP guest policy bit support updates
Subsystems (6)
Tom Lendacky
maintainerv4 cover SEV-SNP guest policy bit support updates
This series aims to allow more flexibility in specifying SEV-SNP policy bits by improving discoverability of supported policy bits from userspace and enabling support for newer policy bits.
- The first patch consolidates the policy definitions into a single header file.
- The second patch adds a CCP driver API to return the supported policy bits. Policy bit support is dependent on the version of SEV firmware.
- The third patch adds a new KVM_X86_GRP_SEV attribute group, KVM_X86_SNP_POLICY_BITS, that can be used to return the supported SEV-SNP policy bits. The initial support for this attribute will use the new CCP driver API to return the firmware supported policy bits ANDed with the KVM supported policy bits.
- The fourth patch expands the number of policy bits that KVM supports.
The series is based off of:
git://git.kernel.org/pub/scm/virt/kvm/kvm.git master
---
Changes for v4:
- Swizzle the patch order in order to preserve ABI.
- Use the new CCP API from the start for the KVM_X86_SNP_POLICY_BITS attribute.
Changes for v3:
- Remove RFC tag.
Changes for v2:
- Marked the KVM supported policy bits as read-only after init.
Tom Lendacky (4):
KVM: SEV: Consolidate the SEV policy bits in a single header file
crypto: ccp - Add an API to return the supported SEV-SNP policy bits
KVM: SEV: Publish supported SEV-SNP policy bits
KVM: SEV: Add known supported SEV-SNP policy bits
arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/sev.c | 45 ++++++++++++++++++++------------- arch/x86/kvm/svm/svm.h | 3 --- drivers/crypto/ccp/sev-dev.c | 37 +++++++++++++++++++++++++++ include/linux/psp-sev.h | 39 ++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 20 deletions(-)
base-commit: 4361f5aa8bfcecbab3fc8db987482b9e08115a6a
Signature · 1 line
2.51.1
Tom Lendacky
maintainerPATCH v4 1/4 KVM: SEV: Consolidate the SEV policy bits in a single header file
Consolidate SEV policy bit definitions into a single file. Use include/linux/psp-sev.h to hold the definitions and remove the current definitions from the arch/x86/kvm/svm/sev.c and arch/x86/include/svm.h files.
No functional change intended.
--- arch/x86/kvm/svm/sev.c | 16 ++++------------ arch/x86/kvm/svm/svm.h | 3 --- include/linux/psp-sev.h | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 15 deletions(-)
arch/x86/kvm/svm/sev.c +4 -12
@@ -65,15 +65,7 @@ module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 04#define AP_RESET_HOLD_NAE_EVENT 1#define AP_RESET_HOLD_MSR_PROTO 2 -/* As defined by SEV-SNP Firmware ABI, under "Guest Policy". */ -#define SNP_POLICY_MASK_API_MINOR GENMASK_ULL(7, 0) -#define SNP_POLICY_MASK_API_MAJOR GENMASK_ULL(15, 8) -#define SNP_POLICY_MASK_SMT BIT_ULL(16) -#define SNP_POLICY_MASK_RSVD_MBO BIT_ULL(17) -#define SNP_POLICY_MASK_DEBUG BIT_ULL(19) -#define SNP_POLICY_MASK_SINGLE_SOCKET BIT_ULL(20) - -#define SNP_POLICY_MASK_VALID (SNP_POLICY_MASK_API_MINOR | \ +#define KVM_SNP_POLICY_MASK_VALID (SNP_POLICY_MASK_API_MINOR | \ SNP_POLICY_MASK_API_MAJOR | \ SNP_POLICY_MASK_SMT | \ SNP_POLICY_MASK_RSVD_MBO | \
@@ -2207,7 +2199,7 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)if (params.flags)return -EINVAL ; -if (params.policy & ~SNP_POLICY_MASK_VALID ) +if (params.policy & ~KVM_SNP_POLICY_MASK_VALID )return -EINVAL ;/* Check for policy bits that must be set */
@@ -5085,10 +5077,10 @@ struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcpu)/* Check if the SEV policy allows debugging */ if (sev_snp_guest (vcpu->kvm)) { -if (!(sev->policy &SNP_POLICY_DEBUG )) +if (!(sev->policy &SNP_POLICY_MASK_DEBUG ))return NULL ; }else { -if (sev->policy &SEV_POLICY_NODBG ) +if (sev->policy &SEV_POLICY_MASK_NODBG )return NULL ; }
arch/x86/kvm/svm/svm.h +0 -3
@@ -117,9 +117,6 @@ struct kvm_sev_info {cpumask_var_t have_run_cpus;/* CPUs that have done VMRUN for this VM. */ }; -#define SEV_POLICY_NODBG BIT_ULL(0) -#define SNP_POLICY_DEBUG BIT_ULL(19) -struct kvm_svm {struct kvm kvm;
include/linux/psp-sev.h +19 -0
@@ -14,6 +14,25 @@#include <uapi/linux/psp-sev.h> +/* As defined by SEV API, under "Guest Policy". */ +#define SEV_POLICY_MASK_NODBG BIT(0) +#define SEV_POLICY_MASK_NOKS BIT(1) +#define SEV_POLICY_MASK_ES BIT(2) +#define SEV_POLICY_MASK_NOSEND BIT(3) +#define SEV_POLICY_MASK_DOMAIN BIT(4) +#define SEV_POLICY_MASK_SEV BIT(5) +#define SEV_POLICY_MASK_API_MAJOR GENMASK(23, 16) +#define SEV_POLICY_MASK_API_MINOR GENMASK(31, 24) + +/* As defined by SEV-SNP Firmware ABI, under "Guest Policy". */ +#define SNP_POLICY_MASK_API_MINOR GENMASK_ULL(7, 0) +#define SNP_POLICY_MASK_API_MAJOR GENMASK_ULL(15, 8) +#define SNP_POLICY_MASK_SMT BIT_ULL(16) +#define SNP_POLICY_MASK_RSVD_MBO BIT_ULL(17) +#define SNP_POLICY_MASK_MIGRATE_MA BIT_ULL(18) +#define SNP_POLICY_MASK_DEBUG BIT_ULL(19) +#define SNP_POLICY_MASK_SINGLE_SOCKET BIT_ULL(20) +#define SEV_FW_BLOB_MAX_SIZE 0x4000/* 16KB */ /**
Signature · 1 line
2.51.1
Tom Lendacky
maintainerPATCH v4 2/4 crypto: ccp - Add an API to return the supported SEV-SNP policy bits
In reply to Tom LendackySupported policy bits are dependent on the level of SEV firmware that is currently running. Create an API to return the supported policy bits for the current level of firmware.
--- drivers/crypto/ccp/sev-dev.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/psp-sev.h | 20 +++++++++++++++++++ 2 files changed, 57 insertions(+)
drivers/crypto/ccp/sev-dev.c +37 -0
@@ -2777,6 +2777,43 @@ void sev_platform_shutdown(void) }EXPORT_SYMBOL_GPL (sev_platform_shutdown); +u64 sev_get_snp_policy_bits (void ) +{ +struct psp_device *psp = psp_master; +struct sev_device *sev; +u64 policy_bits; + +if (!cc_platform_has (CC_ATTR_HOST_SEV_SNP )) +return 0 ; + +if (!psp || !psp->sev_data) +return 0 ; + + sev = psp->sev_data; + + policy_bits =SNP_POLICY_MASK_BASE ; + +if (sev->snp_plat_status.feature_info) { +if (sev->snp_feat_info_0.ecx &SNP_RAPL_DISABLE_SUPPORTED ) + policy_bits |=SNP_POLICY_MASK_RAPL_DIS ; + +if (sev->snp_feat_info_0.ecx &SNP_CIPHER_TEXT_HIDING_SUPPORTED ) + policy_bits |=SNP_POLICY_MASK_CIPHERTEXT_HIDING_DRAM ; + +if (sev->snp_feat_info_0.ecx &SNP_AES_256_XTS_POLICY_SUPPORTED ) + policy_bits |=SNP_POLICY_MASK_MEM_AES_256_XTS ; + +if (sev->snp_feat_info_0.ecx &SNP_CXL_ALLOW_POLICY_SUPPORTED ) + policy_bits |=SNP_POLICY_MASK_CXL_ALLOW ; + +if (sev_version_greater_or_equal (1 ,58 )) + policy_bits |=SNP_POLICY_MASK_PAGE_SWAP_DISABLE ; + } + +return policy_bits; +} +EXPORT_SYMBOL_GPL (sev_get_snp_policy_bits); +void sev_dev_destroy (struct psp_device *psp) {struct sev_device *sev = psp->sev_data;
include/linux/psp-sev.h +20 -0
@@ -32,6 +32,20 @@#define SNP_POLICY_MASK_MIGRATE_MA BIT_ULL(18)#define SNP_POLICY_MASK_DEBUG BIT_ULL(19)#define SNP_POLICY_MASK_SINGLE_SOCKET BIT_ULL(20) +#define SNP_POLICY_MASK_CXL_ALLOW BIT_ULL(21) +#define SNP_POLICY_MASK_MEM_AES_256_XTS BIT_ULL(22) +#define SNP_POLICY_MASK_RAPL_DIS BIT_ULL(23) +#define SNP_POLICY_MASK_CIPHERTEXT_HIDING_DRAM BIT_ULL(24) +#define SNP_POLICY_MASK_PAGE_SWAP_DISABLE BIT_ULL(25) + +/* Base SEV-SNP policy bitmask for minimum supported SEV firmware version */ +#define SNP_POLICY_MASK_BASE (SNP_POLICY_MASK_API_MINOR | \ + SNP_POLICY_MASK_API_MAJOR | \ + SNP_POLICY_MASK_SMT | \ + SNP_POLICY_MASK_RSVD_MBO | \ + SNP_POLICY_MASK_MIGRATE_MA | \ + SNP_POLICY_MASK_DEBUG | \ + SNP_POLICY_MASK_SINGLE_SOCKET)#define SEV_FW_BLOB_MAX_SIZE 0x4000/* 16KB */
@@ -868,7 +882,10 @@ struct snp_feature_info {u32 edx; } __packed; +#define SNP_RAPL_DISABLE_SUPPORTED BIT(2)#define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3) +#define SNP_AES_256_XTS_POLICY_SUPPORTED BIT(4) +#define SNP_CXL_ALLOW_POLICY_SUPPORTED BIT(5)#ifdef CONFIG_CRYPTO_DEV_SP_PSP
@@ -1014,6 +1031,7 @@ void *snp_alloc_firmware_page(gfp_t mask);void snp_free_firmware_page (void *addr);void sev_platform_shutdown (void );bool sev_is_snp_ciphertext_hiding_supported (void ); +u64 sev_get_snp_policy_bits (void );#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
@@ -1052,6 +1070,8 @@ static inline void sev_platform_shutdown(void) { }static inline bool sev_is_snp_ciphertext_hiding_supported (void ) {return false; } +static inline u64 sev_get_snp_policy_bits (void ) {return 0 ; } +#endif /* CONFIG_CRYPTO_DEV_SP_PSP */ #endif /* __PSP_SEV_H__ */
Signature · 1 line
2.51.1
Sean Christopherson
maintainerRe: [PATCH v4 2/4] crypto: ccp - Add an API to return the supported SEV-SNP policy bits
Quoted 6 lines · Tom Lendacky
Supported policy bits are dependent on the level of SEV firmware that is currently running. Create an API to return the supported policy bits for the current level of firmware.
Signed-off-by Tom Lendacky <[email protected]>---
...
include/linux/psp-sev.h static inline void sev_platform_shutdown(void) { } · line 1073
Quoted 13 lines
include/linux/psp-sev.h +2
-0@@ -1014,6 +1031,7 @@ void *snp_alloc_firmware_page(gfp_t mask);void snp_free_firmware_page (void *addr);void sev_platform_shutdown (void );bool sev_is_snp_ciphertext_hiding_supported (void ); +u64 sev_get_snp_policy_bits (void );#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ @@ -1052,6 +1070,8 @@ static inline void sev_platform_shutdown(void) { }static inline bool sev_is_snp_ciphertext_hiding_supported (void ) {return false; } +static inline u64 sev_get_snp_policy_bits (void ) {return 0 ; }
As called out in the RFC[*], this stub is unnecesary.
Tom Lendacky
maintainerRe: [PATCH v4 2/4] crypto: ccp - Add an API to return the supported SEV-SNP policy bits
Quoted 20 lines · Sean Christopherson
Quoted 6 lines · Tom Lendacky
Supported policy bits are dependent on the level of SEV firmware that is currently running. Create an API to return the supported policy bits for the current level of firmware.
Signed-off-by Tom Lendacky <[email protected]>---
...
Quoted 10 lines
include/linux/psp-sev.h +1
-0@@ -1014,6 +1031,7 @@ void *snp_alloc_firmware_page(gfp_t mask);void snp_free_firmware_page (void *addr);void sev_platform_shutdown (void );bool sev_is_snp_ciphertext_hiding_supported (void ); +u64 sev_get_snp_policy_bits (void );#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ @@ -1052,6 +1070,8 @@ static inline void sev_platform_shutdown(void) { }
Quoted 7 lines
include/linux/psp-sev.h static inline void sev_platform_shutdown(void) { } · line 1073
Quoted 3 lines
include/linux/psp-sev.h +1
-0static inline bool sev_is_snp_ciphertext_hiding_supported (void ) {return false; } +static inline u64 sev_get_snp_policy_bits (void ) {return 0 ; }As called out in the RFC[*], this stub is unnecesary.
Ah, sorry, missed that one. Do you want a fix up or do you want to handle it?
Thanks,
Tom
Sean Christopherson
maintainerRe: [PATCH v4 2/4] crypto: ccp - Add an API to return the supported SEV-SNP policy bits
Quoted 14 lines · Tom Lendacky
Quoted 13 lines · Sean Christopherson
Quoted 12 lines · Tom Lendacky
include/linux/psp-sev.h +1
-0@@ -1014,6 +1031,7 @@ void *snp_alloc_firmware_page(gfp_t mask);void snp_free_firmware_page (void *addr);void sev_platform_shutdown (void );bool sev_is_snp_ciphertext_hiding_supported (void ); +u64 sev_get_snp_policy_bits (void );#else /* !CONFIG_CRYPTO_DEV_SP_PSP */ @@ -1052,6 +1070,8 @@ static inline void sev_platform_shutdown(void) { }static inline bool sev_is_snp_ciphertext_hiding_supported (void ) {return false; }
Quoted 7 lines
Quoted 5 lines
include/linux/psp-sev.h static inline void sev_platform_shutdown(void) { } · line 1073
Quoted 1 line
include/linux/psp-sev.h +1
-0+static inline u64 sev_get_snp_policy_bits (void ) {return 0 ; }As called out in the RFC[*], this stub is unnecesary.
Ah, sorry, missed that one. Do you want a fix up or do you want to handle it?
No fixup necessary, assuming this goes through kvm-x86.
Re: [PATCH v4 2/4] crypto: ccp - Add an API to return the supported SEV-SNP policy bits
In reply to Tom LendackyQuoted 9 lines · Tom Lendacky
Supported policy bits are dependent on the level of SEV firmware that is currently running. Create an API to return the supported policy bits for the current level of firmware.
Signed-off-by Tom Lendacky <[email protected]>--- drivers/crypto/ccp/sev-dev.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/psp-sev.h | 20 +++++++++++++++++++ 2 files changed, 57 insertions(+)
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Tom Lendacky
maintainerPATCH v4 3/4 KVM: SEV: Publish supported SEV-SNP policy bits
In reply to Tom LendackyDefine the set of policy bits that KVM currently knows as not requiring any implementation support within KVM. Provide this value to userspace via the KVM_GET_DEVICE_ATTR ioctl.
--- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/sev.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
arch/x86/include/uapi/asm/kvm.h +1 -0
@@ -502,6 +502,7 @@ struct kvm_sync_regs {/* vendor-specific groups and attributes for system fd */ #define KVM_X86_GRP_SEV 1# define KVM_X86_SEV_VMSA_FEATURES 0 +# define KVM_X86_SNP_POLICY_BITS 1struct kvm_vmx_nested_state_data {__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE ];
arch/x86/kvm/svm/sev.c +11 -2
@@ -72,6 +72,8 @@ module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 04 SNP_POLICY_MASK_DEBUG | \ SNP_POLICY_MASK_SINGLE_SOCKET) +static u64 snp_supported_policy_bits__ro_after_init ; +#define INITIAL_VMSA_GPA 0xFFFFFFFFF000static u8 sev_enc_bit;
@@ -2135,6 +2137,10 @@ int sev_dev_get_attr(u32 group, u64 attr, u64 *val) *val = sev_supported_vmsa_features;return 0 ; +case KVM_X86_SNP_POLICY_BITS : + *val = snp_supported_policy_bits; +return 0 ; +default :return -ENXIO ; }
@@ -2199,7 +2205,7 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp)if (params.flags)return -EINVAL ; -if (params.policy & ~KVM_SNP_POLICY_MASK_VALID ) +if (params.policy & ~snp_supported_policy_bits)return -EINVAL ;/* Check for policy bits that must be set */
@@ -3092,8 +3098,11 @@ void __init sev_hardware_setup(void)else if (sev_snp_supported) sev_snp_supported =is_sev_snp_initialized (); -if (sev_snp_supported) +if (sev_snp_supported) { + snp_supported_policy_bits =sev_get_snp_policy_bits () & +KVM_SNP_POLICY_MASK_VALID ; nr_ciphertext_hiding_asids = init_args.max_snp_asid; + }/* * If ciphertext hiding is enabled, the joint SEV-ES/SEV-SNP
Signature · 1 line
2.51.1
Tom Lendacky
maintainerPATCH v4 4/4 KVM: SEV: Add known supported SEV-SNP policy bits
In reply to Tom LendackyAdd to the known supported SEV-SNP policy bits that don't require any implementation support from KVM in order to successfully use them.
At this time, this includes:
- CXL_ALLOW
- MEM_AES_256_XTS
- RAPL_DIS
- CIPHERTEXT_HIDING_DRAM
- PAGE_SWAP_DISABLE
Arguably, RAPL_DIS and CIPHERTEXT_HIDING_DRAM require KVM and the CCP driver to enable these features in order for the setting of the policy bits to be successfully handled. But, a guest owner may not wish their guest to run on a system that doesn't provide support for those features, so allowing the specification of these bits accomplishes that. Whether or not the bit is supported by SEV firmware, a system that doesn't support these features will either fail during the KVM validation of supported policy bits before issuing the LAUNCH_START or fail during the LAUNCH_START.
--- arch/x86/kvm/svm/sev.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
arch/x86/kvm/svm/sev.c +16 -6
@@ -65,12 +65,22 @@ module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 04#define AP_RESET_HOLD_NAE_EVENT 1#define AP_RESET_HOLD_MSR_PROTO 2 -#define KVM_SNP_POLICY_MASK_VALID (SNP_POLICY_MASK_API_MINOR | \ - SNP_POLICY_MASK_API_MAJOR | \ - SNP_POLICY_MASK_SMT | \ - SNP_POLICY_MASK_RSVD_MBO | \ - SNP_POLICY_MASK_DEBUG | \ - SNP_POLICY_MASK_SINGLE_SOCKET) +/* +* SEV-SNP policy bits that can be supported by KVM. These include policy bits +* that have implementation support within KVM or policy bits that do not +* require implementation support within KVM to enforce the policy. +*/ +#define KVM_SNP_POLICY_MASK_VALID (SNP_POLICY_MASK_API_MINOR | \ + SNP_POLICY_MASK_API_MAJOR | \ + SNP_POLICY_MASK_SMT | \ + SNP_POLICY_MASK_RSVD_MBO | \ + SNP_POLICY_MASK_DEBUG | \ + SNP_POLICY_MASK_SINGLE_SOCKET | \ + SNP_POLICY_MASK_CXL_ALLOW | \ + SNP_POLICY_MASK_MEM_AES_256_XTS | \ + SNP_POLICY_MASK_RAPL_DIS | \ + SNP_POLICY_MASK_CIPHERTEXT_HIDING_DRAM | \ + SNP_POLICY_MASK_PAGE_SWAP_DISABLE)static u64 snp_supported_policy_bits__ro_after_init ;
Signature · 1 line
2.51.1
Sean Christopherson
maintainerQuoted 3 lines · Tom Lendacky
This series aims to allow more flexibility in specifying SEV-SNP policy bits by improving discoverability of supported policy bits from userspace and enabling support for newer policy bits.
...
Quoted 6 lines
Tom Lendacky (4):
KVM: SEV: Consolidate the SEV policy bits in a single header file
crypto: ccp - Add an API to return the supported SEV-SNP policy bits
KVM: SEV: Publish supported SEV-SNP policy bits
KVM: SEV: Add known supported SEV-SNP policy bits
Quoted 6 lines
arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/sev.c | 45 ++++++++++++++++++++------------- arch/x86/kvm/svm/svm.h | 3 --- drivers/crypto/ccp/sev-dev.c | 37 +++++++++++++++++++++++++++ include/linux/psp-sev.h | 39 ++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 20 deletions(-)
Looks good overall, just the one minor nit. Given that this adds new KVM uAPI, and the CCP changes are fairly minor in the grand scheme, my preference would be to take the entire series through kvm-x86 (with Acks as appropriate).
Quoted 8 lines · Tom Lendacky
This series aims to allow more flexibility in specifying SEV-SNP policy bits by improving discoverability of supported policy bits from userspace and enabling support for newer policy bits.
- The first patch consolidates the policy definitions into a single header file.
[...]
Applied to kvm-x86 svm, thanks!
[1/4] KVM: SEV: Consolidate the SEV policy bits in a single header file
https://github.com/kvm-x86/linux/commit/ce62118a2e48 [2/4] crypto: ccp - Add an API to return the supported SEV-SNP policy bits https://github.com/kvm-x86/linux/commit/c9434e64e8b4 [3/4] KVM: SEV: Publish supported SEV-SNP policy bits https://github.com/kvm-x86/linux/commit/7a61d61396b9 [4/4] KVM: SEV: Add known supported SEV-SNP policy bits https://github.com/kvm-x86/linux/commit/275d6d1189e6