crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver
Subsystems (5)
Ashish Kalra
maintainerv5 cover crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver
From: Ashish Kalra <[email protected]>
AMD Seamless Firmware Servicing (SFS) is a secure method to allow non-persistent updates to running firmware and settings without requiring BIOS reflash and/or system reset.
SFS does not address anything that runs on the x86 processors and it can be used to update ASP firmware, modules, register settings and update firmware for other microprocessors like TMPM, etc.
SFS driver support adds ioctl support to communicate the SFS commands to the ASP/PSP by using the TEE mailbox interface.
The Seamless Firmware Servicing (SFS) driver is added as a PSP sub-device.
Includes pre-patch to add new generic SEV API interface to allocate/free hypervisor fixed pages which abstracts hypervisor fixed page allocation and free for PSP sub devices. The API internally uses SNP_INIT_EX to transition pages to HV-Fixed page state.
For detailed information, please look at the SFS specifications:
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/58604.pdf
v5:
- Print pathname for firmware_request_nowarn() failure message.
- Changed all dev_warn() to dev_warn_ratelimited() for all ioctl error mesages.
- Add Reviewed-by's for all patches.
v4:
- Ensure that sev_cmd_mutex is acquired before the snp_initialized check in snp_alloc_hv_fixed_pages().
- Restore memory attributes back to the default "write-back" type in sfs_dev_destroy() and cleanup path for the error handling in sfs_dev_init().
v3:
- As not dumping the RMP entry is the rare case, crafting the APIs to reflect that, i.e. make snp_leak_pages() a wrapper for the common case to allow existing users to continue to dump RMP entries by calling new __snp_leak_pages() API with dump_rmp bool parameter set to true. The new parameter also adds support to continue adding pages to the snp_leaked_pages_list but not issue dump_rmpentry().
- Fix kernel test robot build warning for uninitialized "ret" variable.
v2:
- Change API interface from adding/removing HV_Fixed pages to allocate/free HV_Fixed pages.
- Move to guard() for all mutexes/spinlocks.
- Handle case of SFS capability bit being set on multiple PSPs, add protection based on sev_dev_init() and sev_misc_init().
- Add new sfs_command structure and use it for programming both the GetFirmareVersions and UpdatePackage command.
- Use sfs_user_get_fw_versions and sfs_user_update_package structures for copy_to_/copy_from_user for the iotcls.
- Fix payload_path buffer size to prevent buffer overrun/stack corruption issues and also sanitize user provided payload_name to ensure it is null-terminated and use snprintf() to setup payload_path.
- Add new quiet parameter to snp_leak_pages() API and additionally change all existing users of this API to pass quiet=false parameter maintaining current behavior.
- Remove mutex_init() and mutex_destroy() calls for statically declared mutex.
- Fix comments and commit logs.
Ashish Kalra (3):
x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
crypto: ccp - Add new HV-Fixed page allocation/free API.
crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver
arch/x86/include/asm/sev.h | 8 +- arch/x86/virt/svm/sev.c | 7 +- drivers/crypto/ccp/Makefile | 3 +- drivers/crypto/ccp/psp-dev.c | 20 ++ drivers/crypto/ccp/psp-dev.h | 8 +- drivers/crypto/ccp/sev-dev.c | 182 ++++++++++++++++ drivers/crypto/ccp/sev-dev.h | 3 + drivers/crypto/ccp/sfs.c | 311 ++++++++++++++++++++++++++++ drivers/crypto/ccp/sfs.h | 47 +++++ include/linux/psp-platform-access.h | 2 + include/uapi/linux/psp-sfs.h | 87 ++++++++ 11 files changed, 672 insertions(+), 6 deletions(-) create mode 100644 drivers/crypto/ccp/sfs.c create mode 100644 drivers/crypto/ccp/sfs.h create mode 100644 include/uapi/linux/psp-sfs.h
Signature · 1 line
2.34.1
Ashish Kalra
maintainerPATCH v5 1/3 x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
From: Ashish Kalra <[email protected]>
When leaking certain page types, such as Hypervisor Fixed (HV_FIXED) pages, it does not make sense to dump RMP contents for the 2MB range of the page(s) being leaked. In the case of HV_FIXED pages, this is not an error situation where the surrounding 2MB page RMP entries can provide debug information.
Add new __snp_leak_pages() API with dump_rmp bool parameter to support continue adding pages to the snp_leaked_pages_list but not issue dump_rmpentry().
Make snp_leak_pages() a wrapper for the common case which also allows existing users to continue to dump RMP entries.
--- arch/x86/include/asm/sev.h | 8 +++++++- arch/x86/virt/svm/sev.c | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
arch/x86/include/asm/sev.h +7 -1
@@ -635,10 +635,15 @@ void snp_dump_hva_rmpentry(unsigned long address);int psmash (u64 pfn);int rmp_make_private (u64 pfn,u64 gpa,enum pg_level level,u32 asid,bool immutable);int rmp_make_shared (u64 pfn,enum pg_level level); -void snp_leak_pages (u64 pfn,unsigned int npages); +void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp);void kdump_sev_callback (void );void snp_fixup_e820_tables (void ); +static inline void snp_leak_pages (u64 pfn,unsigned int pages) +{ +__snp_leak_pages (pfn, pages, true); +} +static inline void sev_evict_cache (void *va,int npages) {volatile u8 val__always_unused ;
@@ -668,6 +673,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asreturn -ENODEV ; }static inline int rmp_make_shared (u64 pfn,enum pg_level level) {return -ENODEV ; } +static inline void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp) {}static inline void snp_leak_pages (u64 pfn,unsigned int npages) {}static inline void kdump_sev_callback (void ) { }static inline void snp_fixup_e820_tables (void ) {}
arch/x86/virt/svm/sev.c +4 -3
@@ -1029,7 +1029,7 @@ int rmp_make_shared(u64 pfn, enum pg_level level) }EXPORT_SYMBOL_GPL (rmp_make_shared); -void snp_leak_pages (u64 pfn,unsigned int npages) +void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp) {struct page *page =pfn_to_page (pfn);
@@ -1052,14 +1052,15 @@ void snp_leak_pages(u64 pfn, unsigned int npages) (PageHead(page) && compound_nr(page) <= npages))list_add_tail (&page->buddy_list, &snp_leaked_pages_list); -dump_rmpentry (pfn); +if (dump_rmp) +dump_rmpentry (pfn); snp_nr_leaked_pages++; pfn++; page++; }spin_unlock (&snp_leaked_pages_list_lock); } -EXPORT_SYMBOL_GPL (snp_leak_pages); +EXPORT_SYMBOL_GPL (__snp_leak_pages);void kdump_sev_callback (void ) {
Signature · 1 line
2.34.1
Borislav Petkov
maintainerRe: [PATCH v5 1/3] x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
arch/x86/include/asm/sev.h static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 as · line 677
Quoted 6 lines · Ashish Kalra
arch/x86/include/asm/sev.h +1
-0@@ -668,6 +673,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asreturn -ENODEV ; }static inline int rmp_make_shared (u64 pfn,enum pg_level level) {return -ENODEV ; } +static inline void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp) {}static inline void snp_leak_pages (u64 pfn,unsigned int npages) {}
I basically don't even have to build your patch to see that this can't build. See below.
When your patch touches code behind different CONFIG_ items, you must make sure it builds with both settings of each CONFIG_ item.
In file included from arch/x86/boot/startup/gdt_idt.c:9:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline void snp_leak_pages(u64 pfn, unsigned int pages)
| ^~~~~~~~~~~~~~
./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’}
673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
| ^~~~~~~~~~~~~~make[4]: *** [scripts/Makefile.build:287: arch/x86/boot/startup/gdt_idt.o] Error 1 make[3]: *** [scripts/Makefile.build:556: arch/x86/boot/startup] Error 2 make[2]: *** [scripts/Makefile.build:556: arch/x86] Error 2
make[2]: *** Waiting for unfinished jobs....
In file included from drivers/iommu/amd/init.c:32:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline void snp_leak_pages(u64 pfn, unsigned int pages)
| ^~~~~~~~~~~~~~
./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’}
673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
| ^~~~~~~~~~~~~~make[5]: *** [scripts/Makefile.build:287: drivers/iommu/amd/init.o] Error 1 make[4]: *** [scripts/Makefile.build:556: drivers/iommu/amd] Error 2 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:556: drivers/iommu] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:556: drivers] Error 2 make[1]: *** [/mnt/kernel/kernel/linux/Makefile:2011: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteTom Lendacky
maintainerRe: [PATCH v5 1/3] x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
Quoted 10 lines · Borislav Petkov
arch/x86/include/asm/sev.h static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 as · line 677
Quoted 6 lines · Ashish Kalra
arch/x86/include/asm/sev.h +1
-0@@ -668,6 +673,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asreturn -ENODEV ; }static inline int rmp_make_shared (u64 pfn,enum pg_level level) {return -ENODEV ; } +static inline void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp) {}static inline void snp_leak_pages (u64 pfn,unsigned int npages) {}I basically don't even have to build your patch to see that this can't build. See below.
Did the patch merge correctly? I can't see how it would fail since both the original and new definitions are in separate parts of the #ifdef... It should have failed even before given the way it was changed.
Maybe I'm missing something.
Thanks,
Tom
Quoted 31 lines
When your patch touches code behind different
CONFIG_items, you must make sure it builds with both settings of eachCONFIG_item.In file included from
arch/x86/boot/startup/gdt_idt.c:9:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline voidsnp_leak_pages(u64 pfn, unsigned int pages)| ^~~~~~~~~~~~~~ ./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’} 673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {} | ^~~~~~~~~~~~~~make[4]: *** [
scripts/Makefile.build:287:arch/x86/boot/startup/gdt_idt.o] Error 1 make[3]: *** [scripts/Makefile.build:556:arch/x86/boot/startup] Error 2 make[2]: *** [scripts/Makefile.build:556:arch/x86] Error 2
make[2]: *** Waiting for unfinished jobs....
In file included fromdrivers/iommu/amd/init.c:32:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline voidsnp_leak_pages(u64 pfn, unsigned int pages)| ^~~~~~~~~~~~~~ ./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’} 673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {} | ^~~~~~~~~~~~~~make[5]: *** [
scripts/Makefile.build:287:drivers/iommu/amd/init.o] Error 1 make[4]: *** [scripts/Makefile.build:556:drivers/iommu/amd] Error 2 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:556:drivers/iommu] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:556: drivers] Error 2 make[1]: *** [/mnt/kernel/kernel/linux/Makefile:2011: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Borislav Petkov
maintainerRe: [PATCH v5 1/3] x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
Quoted 5 lines · Tom Lendacky
Did the patch merge correctly? I can't see how it would fail since both the original and new definitions are in separate parts of the #ifdef... It should have failed even before given the way it was changed.
Maybe I'm missing something.
Nah, you're right. Because your patch is moving sev_evict_cache(), I ended up resolving it wrong. Sorry for the noise.
Ashish, all patches against tip go ontop of the tip/master branch. Please redo your set ontop.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteKalra, Ashish
maintainerRe: [PATCH v5 1/3] x86/sev: Add new dump_rmp parameter to snp_leak_pages() API
In reply to Borislav PetkovQuoted 11 lines · Borislav Petkov
arch/x86/include/asm/sev.h static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 as · line 677
Quoted 6 lines · Ashish Kalra
arch/x86/include/asm/sev.h +1
-0@@ -668,6 +673,7 @@ static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asreturn -ENODEV ; }static inline int rmp_make_shared (u64 pfn,enum pg_level level) {return -ENODEV ; } +static inline void __snp_leak_pages (u64 pfn,unsigned int npages,bool dump_rmp) {}static inline void snp_leak_pages (u64 pfn,unsigned int npages) {}I basically don't even have to build your patch to see that this can't build. See below.
Quoted 3 lines
When your patch touches code behind different
CONFIG_items, you must make sure it builds with both settings of eachCONFIG_item.
I have done the builds with both CONFIG_KVM_AMD_SEV and !CONFIG_KVM_AMD_SEV and the builds are done without any errors.
And i don't understand how can snp_leak_pages() have this redefinition, as one of them is under #ifdef CONFIG_KVM_AMD_SEV and the other one is the #else part of it.
Thanks,
Ashish
Quoted 27 lines
In file included from
arch/x86/boot/startup/gdt_idt.c:9:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline voidsnp_leak_pages(u64 pfn, unsigned int pages)| ^~~~~~~~~~~~~~ ./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’} 673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {} | ^~~~~~~~~~~~~~make[4]: *** [
scripts/Makefile.build:287:arch/x86/boot/startup/gdt_idt.o] Error 1 make[3]: *** [scripts/Makefile.build:556:arch/x86/boot/startup] Error 2 make[2]: *** [scripts/Makefile.build:556:arch/x86] Error 2
make[2]: *** Waiting for unfinished jobs....
In file included fromdrivers/iommu/amd/init.c:32:./arch/x86/include/asm/sev.h:679:20: error: redefinition of ‘snp_leak_pages’
679 | static inline voidsnp_leak_pages(u64 pfn, unsigned int pages)| ^~~~~~~~~~~~~~ ./arch/x86/include/asm/sev.h:673:20: note: previous definition of ‘snp_leak_pages’ with type ‘void(u64, unsigned int)’ {aka ‘void(long long unsigned int, unsigned int)’} 673 | static inline void snp_leak_pages(u64 pfn, unsigned int npages) {} | ^~~~~~~~~~~~~~make[5]: *** [
scripts/Makefile.build:287:drivers/iommu/amd/init.o] Error 1 make[4]: *** [scripts/Makefile.build:556:drivers/iommu/amd] Error 2 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:556:drivers/iommu] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:556: drivers] Error 2 make[1]: *** [/mnt/kernel/kernel/linux/Makefile:2011: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Ashish Kalra
maintainerPATCH v5 2/3 crypto: ccp - Add new HV-Fixed page allocation/free API.
In reply to Ashish KalraFrom: Ashish Kalra <[email protected]>
When SEV-SNP is active, the TEE extended command header page and all output buffers for TEE extended commands (such as used by Seamless Firmware servicing support) must be in hypervisor-fixed state, assigned to the hypervisor and marked immutable in the RMP entrie(s).
Add a new generic SEV API interface to allocate/free hypervisor fixed pages which abstracts hypervisor fixed page allocation/free for PSP sub devices. The API internally uses SNP_INIT_EX to transition pages to HV-Fixed page state.
If SNP is not enabled then the allocator is simply a wrapper over alloc_pages() and __free_pages().
When the sub device free the pages, they are put on a free list and future allocation requests will try to re-use the freed pages from this list. But this list is not preserved across PSP driver load/unload hence this free/reuse support is only supported while PSP driver is loaded. As HV_FIXED page state is only changed at reboot, these pages are leaked as they cannot be returned back to the page allocator and then potentially allocated to guests, which will cause SEV-SNP guests to fail to start or terminate when accessing the HV_FIXED page.
--- drivers/crypto/ccp/sev-dev.c | 182 +++++++++++++++++++++++++++++++++++ drivers/crypto/ccp/sev-dev.h | 3 + 2 files changed, 185 insertions(+)
drivers/crypto/ccp/sev-dev.c +182 -0
@@ -83,6 +83,21 @@ MODULE_FIRMWARE("amd/amd_sev_fam19h_model1xh.sbin"); /* 4th gen EPYC */static bool psp_dead;static int psp_timeout; +enum snp_hv_fixed_pages_state { +ALLOCATED , +HV_FIXED , +}; + +struct snp_hv_fixed_pages_entry { +struct list_head list; +struct page *page; +unsigned int order; +bool free; +enum snp_hv_fixed_pages_state page_state; +}; + +static LIST_HEAD (snp_hv_fixed_pages); +/* Trusted Memory Region (TMR): * The TMR is a 1MB area that must be 1MB aligned. Use the page allocator * to allocate the memory, which will return aligned memory for the specified
@@ -1158,6 +1173,165 @@ static int snp_get_platform_data(struct sev_device *sev, int *error)return rc; } +/* Hypervisor Fixed pages API interface */ +static void snp_hv_fixed_pages_state_update (struct sev_device *sev, +enum snp_hv_fixed_pages_state page_state) +{ +struct snp_hv_fixed_pages_entry *entry; + +/* List is protected by sev_cmd_mutex */ +lockdep_assert_held (&sev_cmd_mutex); + +if (list_empty (&snp_hv_fixed_pages)) +return ; + +list_for_each_entry (entry, &snp_hv_fixed_pages, list) + entry->page_state = page_state; +} + +/* +* Allocate HV_FIXED pages in 2MB aligned sizes to ensure the whole +* 2MB pages are marked as HV_FIXED. +*/ +struct page *snp_alloc_hv_fixed_pages (unsigned int num_2mb_pages) +{ +struct psp_device *psp_master =psp_get_master_device (); +struct snp_hv_fixed_pages_entry *entry; +struct sev_device *sev; +unsigned int order; +struct page *page; + +if (!psp_master || !psp_master->sev_data) +return NULL ; + + sev = psp_master->sev_data; + + order =get_order (PMD_SIZE * num_2mb_pages); + +/* +* SNP_INIT_EX is protected by sev_cmd_mutex, therefore this list +* also needs to be protected using the same mutex. +*/ +guard (mutex)(&sev_cmd_mutex); + +/* +* This API uses SNP_INIT_EX to transition allocated pages to HV_Fixed +* page state, fail if SNP is already initialized. +*/ +if (sev->snp_initialized) +return NULL ; + +/* Re-use freed pages that match the request */ +list_for_each_entry (entry, &snp_hv_fixed_pages, list) { +/* Hypervisor fixed page allocator implements exact fit policy */ +if (entry->order == order && entry->free) { + entry->free = false; +memset (page_address (entry->page),0 , + (1 << entry->order) *PAGE_SIZE ); +return entry->page; + } + } + + page =alloc_pages (GFP_KERNEL | __GFP_ZERO, order); +if (!page) +return NULL ; + + entry =kzalloc (sizeof (*entry),GFP_KERNEL ); +if (!entry) { +__free_pages (page, order); +return NULL ; + } + + entry->page = page; + entry->order = order; +list_add_tail (&entry->list, &snp_hv_fixed_pages); + +return page; +} + +void snp_free_hv_fixed_pages (struct page *page) +{ +struct psp_device *psp_master =psp_get_master_device (); +struct snp_hv_fixed_pages_entry *entry, *nentry; + +if (!psp_master || !psp_master->sev_data) +return ; + +/* +* SNP_INIT_EX is protected by sev_cmd_mutex, therefore this list +* also needs to be protected using the same mutex. +*/ +guard (mutex)(&sev_cmd_mutex); + +list_for_each_entry_safe (entry, nentry, &snp_hv_fixed_pages, list) { +if (entry->page != page) +continue ; + +/* +* HV_FIXED page state cannot be changed until reboot +* and they cannot be used by an SNP guest, so they cannot +* be returned back to the page allocator. +* Mark the pages as free internally to allow possible re-use. +*/ +if (entry->page_state ==HV_FIXED ) { + entry->free = true; + }else { +__free_pages (page, entry->order); +list_del (&entry->list); +kfree (entry); + } +return ; + } +} + +static void snp_add_hv_fixed_pages (struct sev_device *sev,struct sev_data_range_list *range_list) +{ +struct snp_hv_fixed_pages_entry *entry; +struct sev_data_range *range; +int num_elements; + +lockdep_assert_held (&sev_cmd_mutex); + +if (list_empty (&snp_hv_fixed_pages)) +return ; + + num_elements =list_count_nodes (&snp_hv_fixed_pages) + + range_list->num_elements; + +/* +* Ensure the list of HV_FIXED pages that will be passed to firmware +* do not exceed the page-sized argument buffer. +*/ +if (num_elements *sizeof (*range) +sizeof (*range_list) >PAGE_SIZE ) { +dev_warn (sev->dev,"Additional HV_Fixed pages cannot be accommodated, omitting\n" ); +return ; + } + + range = &range_list->ranges[range_list->num_elements]; +list_for_each_entry (entry, &snp_hv_fixed_pages, list) { + range->base =page_to_pfn (entry->page) <<PAGE_SHIFT ; + range->page_count =1 << entry->order; + range++; + } + range_list->num_elements = num_elements; +} + +static void snp_leak_hv_fixed_pages (void ) +{ +struct snp_hv_fixed_pages_entry *entry; + +/* List is protected by sev_cmd_mutex */ +lockdep_assert_held (&sev_cmd_mutex); + +if (list_empty (&snp_hv_fixed_pages)) +return ; + +list_for_each_entry (entry, &snp_hv_fixed_pages, list) +if (entry->page_state ==HV_FIXED ) +__snp_leak_pages (page_to_pfn (entry->page), +1 << entry->order, false); +} +static int snp_filter_reserved_mem_regions (struct resource *rs,void *arg) {struct sev_data_range_list *range_list = arg;
@@ -1248,6 +1422,12 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)return rc; } +/* +* Add HV_Fixed pages from other PSP sub-devices, such as SFS to the +* HV_Fixed page list. +*/ +snp_add_hv_fixed_pages (sev, snp_range_list); +memset (&data,0 ,sizeof (data));if (max_snp_asid) {
@@ -1293,6 +1473,7 @@ static int __sev_snp_init_locked(int *error, unsigned int max_snp_asid)return rc; } +snp_hv_fixed_pages_state_update (sev,HV_FIXED ); sev->snp_initialized = true;dev_dbg (sev->dev,"SEV-SNP firmware initialized\n" );
@@ -1896,6 +2077,7 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)return ret; } +snp_leak_hv_fixed_pages (); sev->snp_initialized = false;dev_dbg (sev->dev,"SEV-SNP firmware shutdown\n" );
drivers/crypto/ccp/sev-dev.h +3 -0
@@ -69,4 +69,7 @@ void sev_dev_destroy(struct psp_device *psp);void sev_pci_init (void );void sev_pci_exit (void ); +struct page *snp_alloc_hv_fixed_pages (unsigned int num_2mb_pages); +void snp_free_hv_fixed_pages (struct page *page); +#endif /* __SEV_DEV_H */
Signature · 1 line
2.34.1
Ashish Kalra
maintainerPATCH v5 3/3 crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver
In reply to Ashish KalraFrom: Ashish Kalra <[email protected]>
AMD Seamless Firmware Servicing (SFS) is a secure method to allow non-persistent updates to running firmware and settings without requiring BIOS reflash and/or system reset.
SFS does not address anything that runs on the x86 processors and it can be used to update ASP firmware, modules, register settings and update firmware for other microprocessors like TMPM, etc.
SFS driver support adds ioctl support to communicate the SFS commands to the ASP/PSP by using the TEE mailbox interface.
The Seamless Firmware Servicing (SFS) driver is added as a PSP sub-device.
For detailed information, please look at the SFS specifications:
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/58604.pdf
--- drivers/crypto/ccp/Makefile | 3 +- drivers/crypto/ccp/psp-dev.c | 20 ++ drivers/crypto/ccp/psp-dev.h | 8 +- drivers/crypto/ccp/sfs.c | 311 ++++++++++++++++++++++++++++ drivers/crypto/ccp/sfs.h | 47 +++++ include/linux/psp-platform-access.h | 2 + include/uapi/linux/psp-sfs.h | 87 ++++++++ 7 files changed, 476 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/ccp/sfs.c create mode 100644 drivers/crypto/ccp/sfs.h create mode 100644 include/uapi/linux/psp-sfs.h
drivers/crypto/ccp/Makefile +2 -1
@@ -13,7 +13,8 @@ ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \ tee-dev.o \ platform-access.o \ dbc.o \ - hsti.o + hsti.o \ + sfs.o obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o ccp-crypto-objs := ccp-crypto-main.o \
drivers/crypto/ccp/psp-dev.c +20 -0
@@ -17,6 +17,7 @@#include "psp-dev.h" #include "sev-dev.h" #include "tee-dev.h" +#include "sfs.h" #include "platform-access.h" #include "dbc.h" #include "hsti.h"
@@ -182,6 +183,17 @@ static int psp_check_tee_support(struct psp_device *psp)return 0 ; } +static int psp_check_sfs_support (struct psp_device *psp) +{ +/* Check if device supports SFS feature */ +if (!psp->capability.sfs) { +dev_dbg (psp->dev,"psp does not support SFS\n" ); +return -ENODEV ; + } + +return 0 ; +} +static int psp_init (struct psp_device *psp) {int ret;
@@ -198,6 +210,12 @@ static int psp_init(struct psp_device *psp)return ret; } +if (!psp_check_sfs_support (psp)) { + ret =sfs_dev_init (psp); +if (ret) +return ret; + } +if (psp->vdata->platform_access) { ret =platform_access_dev_init (psp);if (ret)
@@ -302,6 +320,8 @@ void psp_dev_destroy(struct sp_device *sp)tee_dev_destroy (psp); +sfs_dev_destroy (psp); +dbc_dev_destroy (psp);platform_access_dev_destroy (psp);
drivers/crypto/ccp/psp-dev.h +7 -1
@@ -32,7 +32,8 @@ union psp_cap_register { unsigned int sev :1, tee :1, dbc_thru_ext :1, - rsvd1 :4, + sfs :1, + rsvd1 :3, security_reporting :1, fused_part :1, rsvd2 :1,
@@ -68,6 +69,7 @@ struct psp_device {void *tee_data;void *platform_access_data;void *dbc_data; +void *sfs_data;union psp_cap_register capability; };
@@ -118,12 +120,16 @@ struct psp_ext_request {* @PSP_SUB_CMD_DBC_SET_UID: Set UID for DBC * @PSP_SUB_CMD_DBC_GET_PARAMETER: Get parameter from DBC * @PSP_SUB_CMD_DBC_SET_PARAMETER: Set parameter for DBC +* @PSP_SUB_CMD_SFS_GET_FW_VERS: Get firmware versions for ASP and other MP +* @PSP_SUB_CMD_SFS_UPDATE: Command to load, verify and execute SFS package */ enum psp_sub_cmd {PSP_SUB_CMD_DBC_GET_NONCE =PSP_DYNAMIC_BOOST_GET_NONCE ,PSP_SUB_CMD_DBC_SET_UID =PSP_DYNAMIC_BOOST_SET_UID ,PSP_SUB_CMD_DBC_GET_PARAMETER =PSP_DYNAMIC_BOOST_GET_PARAMETER ,PSP_SUB_CMD_DBC_SET_PARAMETER =PSP_DYNAMIC_BOOST_SET_PARAMETER , +PSP_SUB_CMD_SFS_GET_FW_VERS =PSP_SFS_GET_FW_VERSIONS , +PSP_SUB_CMD_SFS_UPDATE =PSP_SFS_UPDATE , }; int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs,
drivers/crypto/ccp/sfs.c new file +311 -0
311 lines not on this page · raw message
drivers/crypto/ccp/sfs.h new file +47 -0
47 lines not on this page · raw message
include/linux/psp-platform-access.h +2 -0
@@ -7,6 +7,8 @@enum psp_platform_access_msg {PSP_CMD_NONE =0x0 , +PSP_SFS_GET_FW_VERSIONS , +PSP_SFS_UPDATE ,PSP_CMD_HSTI_QUERY =0x14 ,PSP_I2C_REQ_BUS_CMD =0x64 ,PSP_DYNAMIC_BOOST_GET_NONCE ,
include/uapi/linux/psp-sfs.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.34.1