Skip to content

Commit 9f91164

Browse files
kiryltorvalds
authored andcommitted
x86/traps: Fix load_unaligned_zeropad() handling for shared TDX memory
Commit c4e34dd ("x86: simplify load_unaligned_zeropad() implementation") changes how exceptions around load_unaligned_zeropad() handled. The kernel now uses the fault_address in fixup_exception() to verify the address calculations for the load_unaligned_zeropad(). It works fine for #PF, but breaks on #VE since no fault address is passed down to fixup_exception(). Propagating ve_info.gla down to fixup_exception() resolves the issue. See commit 1e77696 ("x86/tdx: Handle load_unaligned_zeropad() page-cross to a shared page") for more context. Signed-off-by: Kirill A. Shutemov <[email protected]> Reported-by: Michael Kelley <[email protected]> Fixes: c4e34dd ("x86: simplify load_unaligned_zeropad() implementation") Acked-by: Dave Hansen <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0b4a9fd commit 9f91164

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

arch/x86/kernel/traps.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,10 @@ static bool try_fixup_enqcmd_gp(void)
697697
}
698698

699699
static bool gp_try_fixup_and_notify(struct pt_regs *regs, int trapnr,
700-
unsigned long error_code, const char *str)
700+
unsigned long error_code, const char *str,
701+
unsigned long address)
701702
{
702-
if (fixup_exception(regs, trapnr, error_code, 0))
703+
if (fixup_exception(regs, trapnr, error_code, address))
703704
return true;
704705

705706
current->thread.error_code = error_code;
@@ -759,7 +760,7 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection)
759760
goto exit;
760761
}
761762

762-
if (gp_try_fixup_and_notify(regs, X86_TRAP_GP, error_code, desc))
763+
if (gp_try_fixup_and_notify(regs, X86_TRAP_GP, error_code, desc, 0))
763764
goto exit;
764765

765766
if (error_code)
@@ -1357,17 +1358,20 @@ DEFINE_IDTENTRY(exc_device_not_available)
13571358

13581359
#define VE_FAULT_STR "VE fault"
13591360

1360-
static void ve_raise_fault(struct pt_regs *regs, long error_code)
1361+
static void ve_raise_fault(struct pt_regs *regs, long error_code,
1362+
unsigned long address)
13611363
{
13621364
if (user_mode(regs)) {
13631365
gp_user_force_sig_segv(regs, X86_TRAP_VE, error_code, VE_FAULT_STR);
13641366
return;
13651367
}
13661368

1367-
if (gp_try_fixup_and_notify(regs, X86_TRAP_VE, error_code, VE_FAULT_STR))
1369+
if (gp_try_fixup_and_notify(regs, X86_TRAP_VE, error_code,
1370+
VE_FAULT_STR, address)) {
13681371
return;
1372+
}
13691373

1370-
die_addr(VE_FAULT_STR, regs, error_code, 0);
1374+
die_addr(VE_FAULT_STR, regs, error_code, address);
13711375
}
13721376

13731377
/*
@@ -1431,7 +1435,7 @@ DEFINE_IDTENTRY(exc_virtualization_exception)
14311435
* it successfully, treat it as #GP(0) and handle it.
14321436
*/
14331437
if (!tdx_handle_virt_exception(regs, &ve))
1434-
ve_raise_fault(regs, 0);
1438+
ve_raise_fault(regs, 0, ve.gla);
14351439

14361440
cond_local_irq_disable(regs);
14371441
}

0 commit comments

Comments
 (0)