Skip to content

Commit 3f6819d

Browse files
kirylhansendc
authored andcommitted
x86/mm: Allow guest.enc_status_change_prepare() to fail
TDX code is going to provide guest.enc_status_change_prepare() that is able to fail. TDX will use the call to convert the GPA range from shared to private. This operation can fail. Add a way to return an error from the callback. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Link: https://lore.kernel.org/all/20230606095622.1939-2-kirill.shutemov%40linux.intel.com
1 parent 122333d commit 3f6819d

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

arch/x86/include/asm/x86_init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct x86_init_acpi {
150150
* @enc_cache_flush_required Returns true if a cache flush is needed before changing page encryption status
151151
*/
152152
struct x86_guest {
153-
void (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc);
153+
bool (*enc_status_change_prepare)(unsigned long vaddr, int npages, bool enc);
154154
bool (*enc_status_change_finish)(unsigned long vaddr, int npages, bool enc);
155155
bool (*enc_tlb_flush_required)(bool enc);
156156
bool (*enc_cache_flush_required)(void);

arch/x86/kernel/x86_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
130130

131131
static void default_nmi_init(void) { };
132132

133-
static void enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { }
133+
static bool enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return true; }
134134
static bool enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return false; }
135135
static bool enc_tlb_flush_required_noop(bool enc) { return false; }
136136
static bool enc_cache_flush_required_noop(void) { return false; }

arch/x86/mm/mem_encrypt_amd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,16 @@ static void enc_dec_hypercall(unsigned long vaddr, int npages, bool enc)
319319
#endif
320320
}
321321

322-
static void amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc)
322+
static bool amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc)
323323
{
324324
/*
325325
* To maintain the security guarantees of SEV-SNP guests, make sure
326326
* to invalidate the memory before encryption attribute is cleared.
327327
*/
328328
if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP) && !enc)
329329
snp_set_memory_shared(vaddr, npages);
330+
331+
return true;
330332
}
331333

332334
/* Return true unconditionally: return value doesn't matter for the SEV side */

arch/x86/mm/pat/set_memory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,8 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc)
21512151
cpa_flush(&cpa, x86_platform.guest.enc_cache_flush_required());
21522152

21532153
/* Notify hypervisor that we are about to set/clr encryption attribute. */
2154-
x86_platform.guest.enc_status_change_prepare(addr, numpages, enc);
2154+
if (!x86_platform.guest.enc_status_change_prepare(addr, numpages, enc))
2155+
return -EIO;
21552156

21562157
ret = __change_page_attr_set_clr(&cpa, 1);
21572158

0 commit comments

Comments
 (0)