[PATCH v3 06/10] x86/sev: Avoid crossing the page boundary
From: Alexey Gladkov
Date: Fri Aug 16 2024 - 09:46:50 EST
From: "Alexey Gladkov (Intel)" <legion@xxxxxxxxxx>
Try to avoid crossing the page boundary to avoid side effects if the
next page belongs to another VMA.
Signed-off-by: Alexey Gladkov (Intel) <legion@xxxxxxxxxx>
---
arch/x86/coco/sev/core.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 082d61d85dfc..b0e8e4264464 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -311,17 +311,16 @@ static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,
static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt)
{
- char buffer[MAX_INSN_SIZE];
- int insn_bytes;
+ int ret;
- insn_bytes = insn_fetch_from_user_inatomic(ctxt->regs, buffer);
- if (insn_bytes == 0) {
+ ret = insn_fetch_decode_from_user_inatomic(&ctxt->insn, ctxt->regs);
+ if (ret == -EFAULT) {
/* Nothing could be copied */
ctxt->fi.vector = X86_TRAP_PF;
ctxt->fi.error_code = X86_PF_INSTR | X86_PF_USER;
ctxt->fi.cr2 = ctxt->regs->ip;
return ES_EXCEPTION;
- } else if (insn_bytes == -EINVAL) {
+ } else if (ret == -EINVAL) {
/* Effective RIP could not be calculated */
ctxt->fi.vector = X86_TRAP_GP;
ctxt->fi.error_code = 0;
@@ -329,9 +328,6 @@ static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt)
return ES_EXCEPTION;
}
- if (!insn_decode_from_regs(&ctxt->insn, ctxt->regs, buffer, insn_bytes))
- return ES_DECODE_FAILED;
-
if (ctxt->insn.immediate.got)
return ES_OK;
else
--
2.45.2