Skip to content

Commit 8a5dd10

Browse files
aikdjbw
authored andcommitted
ccp: Make snp_reclaim_pages and __sev_do_cmd_locked public
The snp_reclaim_pages() helper reclaims pages in the FW state. SEV-TIO and the TMPM driver (a hardware engine which smashes IOMMU PDEs among other things) will use to reclaim memory when cleaning up. Share and export snp_reclaim_pages(). Most of the SEV-TIO code uses sev_do_cmd() which locks the sev_cmd_mutex and already exported. But the SNP init code (which also sets up SEV-TIO) executes under the sev_cmd_mutex lock so the SEV-TIO code has to use the __sev_do_cmd_locked() helper. This one though does not need to be exported/shared globally as SEV-TIO is a part of the CCP driver still. Share __sev_do_cmd_locked() via the CCP internal header. Signed-off-by: Alexey Kardashevskiy <aik@amd.com> Link: https://patch.msgid.link/20251202024449.542361-2-aik@amd.com Acked-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f7ae6d4 commit 8a5dd10

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

drivers/crypto/ccp/sev-dev.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,7 @@ static int sev_write_init_ex_file_if_required(int cmd_id)
387387
return sev_write_init_ex_file();
388388
}
389389

390-
/*
391-
* snp_reclaim_pages() needs __sev_do_cmd_locked(), and __sev_do_cmd_locked()
392-
* needs snp_reclaim_pages(), so a forward declaration is needed.
393-
*/
394-
static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret);
395-
396-
static int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool locked)
390+
int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool locked)
397391
{
398392
int ret, err, i;
399393

@@ -427,6 +421,7 @@ static int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool lock
427421
snp_leak_pages(__phys_to_pfn(paddr), npages - i);
428422
return ret;
429423
}
424+
EXPORT_SYMBOL_GPL(snp_reclaim_pages);
430425

431426
static int rmp_mark_pages_firmware(unsigned long paddr, unsigned int npages, bool locked)
432427
{
@@ -857,7 +852,7 @@ static int snp_reclaim_cmd_buf(int cmd, void *cmd_buf)
857852
return 0;
858853
}
859854

860-
static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
855+
int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
861856
{
862857
struct cmd_buf_desc desc_list[CMD_BUF_DESC_MAX] = {0};
863858
struct psp_device *psp = psp_master;

drivers/crypto/ccp/sev-dev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct sev_device {
6666
int sev_dev_init(struct psp_device *psp);
6767
void sev_dev_destroy(struct psp_device *psp);
6868

69+
int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret);
70+
6971
void sev_pci_init(void);
7072
void sev_pci_exit(void);
7173

include/linux/psp-sev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ int sev_do_cmd(int cmd, void *data, int *psp_ret);
992992

993993
void *psp_copy_user_blob(u64 uaddr, u32 len);
994994
void *snp_alloc_firmware_page(gfp_t mask);
995+
int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool locked);
995996
void snp_free_firmware_page(void *addr);
996997
void sev_platform_shutdown(void);
997998
bool sev_is_snp_ciphertext_hiding_supported(void);
@@ -1027,6 +1028,11 @@ static inline void *snp_alloc_firmware_page(gfp_t mask)
10271028
return NULL;
10281029
}
10291030

1031+
static inline int snp_reclaim_pages(unsigned long paddr, unsigned int npages, bool locked)
1032+
{
1033+
return -ENODEV;
1034+
}
1035+
10301036
static inline void snp_free_firmware_page(void *addr) { }
10311037

10321038
static inline void sev_platform_shutdown(void) { }

0 commit comments

Comments
 (0)