From: Ashish Kalra <ashish.kalra@amd.com>
Ciphertext hiding needs to be enabled on SNP_INIT_EX.
Add two new arguments to sev_platform_init_args to allow KVM
module to specify during SNP initialization if CipherTextHiding
feature is to be enabled and the maximum ASID usable for an
SEV-SNP guest when CipherTextHiding feature is enabled.
Add new API interface to indicate if SEV-SNP CipherTextHiding
feature is supported and enabled in the Platform/BIOS.
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
---
drivers/crypto/ccp/sev-dev.c | 31 ++++++++++++++++++++++++++++---
include/linux/psp-sev.h | 18 ++++++++++++++++--
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index f4f8a8905115..ca4b156598de 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1073,6 +1073,25 @@ static void snp_set_hsave_pa(void *arg)
wrmsrq(MSR_VM_HSAVE_PA, 0);
}
+bool is_sev_snp_ciphertext_hiding_supported(void)
+{
+ struct psp_device *psp = psp_master;
+ struct sev_device *sev;
+
+ sev = psp->sev_data;
+
+ /*
+ * Check if CipherTextHiding feature is supported and enabled
+ * in the Platform/BIOS.
+ */
+ if ((sev->feat_info.ecx & SNP_CIPHER_TEXT_HIDING_SUPPORTED) &&
+ sev->snp_plat_status.ciphertext_hiding_cap)
+ return true;
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(is_sev_snp_ciphertext_hiding_supported);
+
static void snp_get_platform_data(void)
{
struct sev_device *sev = psp_master->sev_data;
@@ -1147,7 +1166,7 @@ static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg)
return 0;
}
-static int __sev_snp_init_locked(int *error)
+static int __sev_snp_init_locked(int *error, bool cipher_text_hiding_en, unsigned int snp_max_snp_asid)
{
struct psp_device *psp = psp_master;
struct sev_data_snp_init_ex data;
@@ -1208,6 +1227,12 @@ static int __sev_snp_init_locked(int *error)
}
memset(&data, 0, sizeof(data));
+
+ if (cipher_text_hiding_en) {
+ data.ciphertext_hiding_en = 1;
+ data.max_snp_asid = snp_max_snp_asid;
+ }
+
data.init_rmp = 1;
data.list_paddr_en = 1;
data.list_paddr = __psp_pa(snp_range_list);
@@ -1392,7 +1417,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args)
if (sev->state == SEV_STATE_INIT)
return 0;
- rc = __sev_snp_init_locked(&args->error);
+ rc = __sev_snp_init_locked(&args->error, args->cipher_text_hiding_en, args->snp_max_snp_asid);
if (rc && rc != -ENODEV)
return rc;
@@ -1475,7 +1500,7 @@ static int snp_move_to_init_state(struct sev_issue_cmd *argp, bool *shutdown_req
{
int error, rc;
- rc = __sev_snp_init_locked(&error);
+ rc = __sev_snp_init_locked(&error, false, 0);
if (rc) {
argp->error = SEV_RET_INVALID_PLATFORM_STATE;
return rc;
diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h
index 0149d4a6aceb..af45e3e372f5 100644
--- a/include/linux/psp-sev.h
+++ b/include/linux/psp-sev.h
@@ -746,10 +746,13 @@ struct sev_data_snp_guest_request {
struct sev_data_snp_init_ex {
u32 init_rmp:1;
u32 list_paddr_en:1;
- u32 rsvd:30;
+ u32 rapl_dis:1;
+ u32 ciphertext_hiding_en:1;
+ u32 rsvd:28;
u32 rsvd1;
u64 list_paddr;
- u8 rsvd2[48];
+ u16 max_snp_asid;
+ u8 rsvd2[46];
} __packed;
/**
@@ -798,10 +801,16 @@ struct sev_data_snp_shutdown_ex {
* @probe: True if this is being called as part of CCP module probe, which
* will defer SEV_INIT/SEV_INIT_EX firmware initialization until needed
* unless psp_init_on_probe module param is set
+ * @cipher_text_hiding_en: True if SEV-SNP CipherTextHiding support is
+ * enabled
+ * @snp_max_snp_asid: maximum ASID usable for SEV-SNP guest if
+ * CipherTextHiding is enabled
*/
struct sev_platform_init_args {
int error;
bool probe;
+ bool cipher_text_hiding_en;
+ unsigned int snp_max_snp_asid;
};
/**
@@ -841,6 +850,8 @@ struct snp_feature_info {
u32 edx;
} __packed;
+#define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3)
+
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
/**
@@ -984,6 +995,7 @@ void *psp_copy_user_blob(u64 uaddr, u32 len);
void *snp_alloc_firmware_page(gfp_t mask);
void snp_free_firmware_page(void *addr);
void sev_platform_shutdown(void);
+bool is_sev_snp_ciphertext_hiding_supported(void);
#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
@@ -1020,6 +1032,8 @@ static inline void snp_free_firmware_page(void *addr) { }
static inline void sev_platform_shutdown(void) { }
+static inline bool is_sev_snp_ciphertext_hiding_supported(void) { return FALSE; }
+
#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
#endif /* __PSP_SEV_H__ */
--
2.34.1
Hi Ashish,
kernel test robot noticed the following build errors:
[auto build test ERROR on next-20250417]
[cannot apply to herbert-cryptodev-2.6/master herbert-crypto-2.6/master kvm/queue kvm/next linus/master kvm/linux-next v6.15-rc3 v6.15-rc2 v6.15-rc1 v6.15-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ashish-Kalra/crypto-ccp-New-bit-field-definitions-for-SNP_PLATFORM_STATUS-command/20250422-082725
base: next-20250417
patch link: https://lore.kernel.org/r/94ffa7595fca67cfdcd2352354791bdb6ac00499.1745279916.git.ashish.kalra%40amd.com
patch subject: [PATCH v3 3/4] crypto: ccp: Add support to enable CipherTextHiding on SNP_INIT_EX
config: i386-buildonly-randconfig-002-20250422 (https://download.01.org/0day-ci/archive/20250507/202505071309.cJl7zfy2-lkp@intel.com/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250507/202505071309.cJl7zfy2-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505071309.cJl7zfy2-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from arch/x86/kvm/svm/svm.c:24:
>> include/linux/psp-sev.h:1035:74: error: use of undeclared identifier 'FALSE'
1035 | static inline bool is_sev_snp_ciphertext_hiding_supported(void) { return FALSE; }
| ^
1 error generated.
vim +/FALSE +1035 include/linux/psp-sev.h
1034
> 1035 static inline bool is_sev_snp_ciphertext_hiding_supported(void) { return FALSE; }
1036
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On 4/21/25 19:25, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> Ciphertext hiding needs to be enabled on SNP_INIT_EX.
>
> Add two new arguments to sev_platform_init_args to allow KVM
> module to specify during SNP initialization if CipherTextHiding
> feature is to be enabled and the maximum ASID usable for an
> SEV-SNP guest when CipherTextHiding feature is enabled.
>
> Add new API interface to indicate if SEV-SNP CipherTextHiding
> feature is supported and enabled in the Platform/BIOS.
>
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
> drivers/crypto/ccp/sev-dev.c | 31 ++++++++++++++++++++++++++++---
> include/linux/psp-sev.h | 18 ++++++++++++++++--
> 2 files changed, 44 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index f4f8a8905115..ca4b156598de 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1073,6 +1073,25 @@ static void snp_set_hsave_pa(void *arg)
> wrmsrq(MSR_VM_HSAVE_PA, 0);
> }
>
> +bool is_sev_snp_ciphertext_hiding_supported(void)
sev_is_snp_ciphertext_hiding_supported
> +{
> + struct psp_device *psp = psp_master;
> + struct sev_device *sev;
> +
> + sev = psp->sev_data;
> +
> + /*
> + * Check if CipherTextHiding feature is supported and enabled
> + * in the Platform/BIOS.
I think this should be expanded a bit to indicate why both the feature
info and the platform status fields have to be checked.
> + */
> + if ((sev->feat_info.ecx & SNP_CIPHER_TEXT_HIDING_SUPPORTED) &&
> + sev->snp_plat_status.ciphertext_hiding_cap)
> + return true;
> +
> + return false;
And then just make this:
return (sev->feat_info.ecx & SNP_CIPHER_TEXT_HIDING_SUPPORTED) &&
sev->snp_plat_status.ciphertext_hiding_cap);
> +}
> +EXPORT_SYMBOL_GPL(is_sev_snp_ciphertext_hiding_supported);
> +
> static void snp_get_platform_data(void)
> {
> struct sev_device *sev = psp_master->sev_data;
> @@ -1147,7 +1166,7 @@ static int snp_filter_reserved_mem_regions(struct resource *rs, void *arg)
> return 0;
> }
>
> -static int __sev_snp_init_locked(int *error)
> +static int __sev_snp_init_locked(int *error, bool cipher_text_hiding_en, unsigned int snp_max_snp_asid)
> {
> struct psp_device *psp = psp_master;
> struct sev_data_snp_init_ex data;
> @@ -1208,6 +1227,12 @@ static int __sev_snp_init_locked(int *error)
> }
>
> memset(&data, 0, sizeof(data));
> +
> + if (cipher_text_hiding_en) {
> + data.ciphertext_hiding_en = 1;
> + data.max_snp_asid = snp_max_snp_asid;
> + }
> +
> data.init_rmp = 1;
> data.list_paddr_en = 1;
> data.list_paddr = __psp_pa(snp_range_list);
> @@ -1392,7 +1417,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args)
> if (sev->state == SEV_STATE_INIT)
> return 0;
>
> - rc = __sev_snp_init_locked(&args->error);
> + rc = __sev_snp_init_locked(&args->error, args->cipher_text_hiding_en, args->snp_max_snp_asid);
> if (rc && rc != -ENODEV)
> return rc;
>
> @@ -1475,7 +1500,7 @@ static int snp_move_to_init_state(struct sev_issue_cmd *argp, bool *shutdown_req
> {
> int error, rc;
>
> - rc = __sev_snp_init_locked(&error);
> + rc = __sev_snp_init_locked(&error, false, 0);
> if (rc) {
> argp->error = SEV_RET_INVALID_PLATFORM_STATE;
> return rc;
> diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h
> index 0149d4a6aceb..af45e3e372f5 100644
> --- a/include/linux/psp-sev.h
> +++ b/include/linux/psp-sev.h
> @@ -746,10 +746,13 @@ struct sev_data_snp_guest_request {
> struct sev_data_snp_init_ex {
> u32 init_rmp:1;
> u32 list_paddr_en:1;
> - u32 rsvd:30;
> + u32 rapl_dis:1;
> + u32 ciphertext_hiding_en:1;
> + u32 rsvd:28;
> u32 rsvd1;
> u64 list_paddr;
> - u8 rsvd2[48];
> + u16 max_snp_asid;
> + u8 rsvd2[46];
> } __packed;
>
> /**
> @@ -798,10 +801,16 @@ struct sev_data_snp_shutdown_ex {
> * @probe: True if this is being called as part of CCP module probe, which
> * will defer SEV_INIT/SEV_INIT_EX firmware initialization until needed
> * unless psp_init_on_probe module param is set
> + * @cipher_text_hiding_en: True if SEV-SNP CipherTextHiding support is
s/is/is to be/
Thanks,
Tom
> + * enabled
> + * @snp_max_snp_asid: maximum ASID usable for SEV-SNP guest if
> + * CipherTextHiding is enabled
> */
> struct sev_platform_init_args {
> int error;
> bool probe;
> + bool cipher_text_hiding_en;
> + unsigned int snp_max_snp_asid;
> };
>
> /**
> @@ -841,6 +850,8 @@ struct snp_feature_info {
> u32 edx;
> } __packed;
>
> +#define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3)
> +
> #ifdef CONFIG_CRYPTO_DEV_SP_PSP
>
> /**
> @@ -984,6 +995,7 @@ void *psp_copy_user_blob(u64 uaddr, u32 len);
> void *snp_alloc_firmware_page(gfp_t mask);
> void snp_free_firmware_page(void *addr);
> void sev_platform_shutdown(void);
> +bool is_sev_snp_ciphertext_hiding_supported(void);
>
> #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
>
> @@ -1020,6 +1032,8 @@ static inline void snp_free_firmware_page(void *addr) { }
>
> static inline void sev_platform_shutdown(void) { }
>
> +static inline bool is_sev_snp_ciphertext_hiding_supported(void) { return FALSE; }
> +
> #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
>
> #endif /* __PSP_SEV_H__ */
© 2016 - 2025 Red Hat, Inc.