Blob Blame History Raw
From: Joerg Roedel <jroedel@suse.de>
Date: Wed, 19 May 2021 15:52:45 +0200
Subject: x86/sev-es: Forward page-faults which happen during emulation
Git-commit: c25bbdb564060adaad5c3a8a10765c13487ba6a3
Patch-mainline: v5.13-rc3
References: bsc#1187350

When emulating guest instructions for MMIO or IOIO accesses, the #VC
handler might get a page-fault and will not be able to complete. Forward
the page-fault in this case to the correct handler instead of killing
the machine.

Fixes: 0786138c78e7 ("x86/sev-es: Add a Runtime #VC Exception Handler")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: stable@vger.kernel.org # v5.10+
Link: https://lkml.kernel.org/r/20210519135251.30093-3-joro@8bytes.org
---
 arch/x86/kernel/sev-es.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/arch/x86/kernel/sev-es.c
+++ b/arch/x86/kernel/sev-es.c
@@ -1236,6 +1236,10 @@ static __always_inline void vc_forward_e
 	case X86_TRAP_UD:
 		do_invalid_op(ctxt->regs, error_code);
 		break;
+	case X86_TRAP_PF:
+		write_cr2(ctxt->fi.cr2);
+		do_page_fault(ctxt->regs, error_code, ctxt->fi.cr2);
+		break;
 	case X86_TRAP_AC:
 		do_alignment_check(ctxt->regs, error_code);
 		break;