x86/sev: clean up initialization of variables info and v
Subsystems (2)
PATCH 1/1 x86/sev: clean up initialization of variables info and v
Currently variable info is being assigned twice, the second assignment is redundant. Clean up the code by making the assignments at declaration time and remove the latter two assignments.
--- arch/x86/kernel/sev-shared.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/kernel/sev-shared.c +1 -4
@@ -104,10 +104,7 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxtif (ret ==1 ) {u64 info = ghcb->save.sw_exit_info_2; -unsigned long v; - - info = ghcb->save.sw_exit_info_2; - v = info &SVM_EVTINJ_VEC_MASK ; +unsigned long v = info &SVM_EVTINJ_VEC_MASK ;/* Check if exception information from hypervisor is sane. */ if ((info & SVM_EVTINJ_VALID) &&
Signature · 1 line
2.33.1
Quoted 5 lines · Colin Ian King
Currently variable info is being assigned twice, the second assignment is redundant. Clean up the code by making the assignments at declaration time and remove the latter two assignments.
Signed-off-by Colin Ian King <[email protected]>
Heh, checkpatch complains about the different email domains as it doesn't know that googlemail.com and gmail.com are more or less the same. Doubt it matters much, but probably worth having your SoB match your local git config.
Quoted 9 lines
--- arch/x86/kernel/sev-shared.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)arch/x86/kernel/sev-shared.c +0
-0
arch/x86/kernel/sev-shared.c static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt · line 107
Quoted 8 lines
arch/x86/kernel/sev-shared.c +1
-4@@ -104,10 +104,7 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxtif (ret ==1 ) {u64 info = ghcb->save.sw_exit_info_2; -unsigned long v; - - info = ghcb->save.sw_exit_info_2; - v = info &SVM_EVTINJ_VEC_MASK ; +unsigned long v = info &SVM_EVTINJ_VEC_MASK ;
'v' should really be a u8, and IMO 'v' is a pointlessly short. Opportunistically squash this in?
--- arch/x86/kernel/sev-shared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/sev-shared.c +3 -3
@@ -104,13 +104,13 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxtif (ret ==1 ) {u64 info = ghcb->save.sw_exit_info_2; -unsigned long v = info &SVM_EVTINJ_VEC_MASK ; +u8 vector = info &SVM_EVTINJ_VEC_MASK ;/* Check if exception information from hypervisor is sane. */ if ((info &SVM_EVTINJ_VALID ) && - ((v ==X86_TRAP_GP ) || (v ==X86_TRAP_UD )) && + ((vector ==X86_TRAP_GP ) || (vector ==X86_TRAP_UD )) && ((info &SVM_EVTINJ_TYPE_MASK ) ==SVM_EVTINJ_TYPE_EXEPT )) { - ctxt->fi.vector = v; + ctxt->fi.vector = vector;if (info &SVM_EVTINJ_VALID_ERR ) ctxt->fi.error_code = info >>32 ;
--
arch/x86/kernel/sev-shared.c static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt · line 108
Quoted 1 line
arch/x86/kernel/sev-shared.c +0
-0/* Check if exception information from hypervisor is sane. */
s/sane/mostly sane, this code doesn't check that the hypervisor correctly provided an error. It doesn't really matter since ctxt->fi.error_code is zeroed, i.e. will have clean data for #GP, and is ignored by #UD. And nothing downstream should be doing anything more than reporting the error code anyways since the value is fully VMM controlled. But to be pedantic...
From: Sean Christopherson <[email protected]>
Date: Tue, 30 Nov 2021 18:40:30 -0800
Subject: [PATCH] x86/sev: Verify that VMM provides error code on #GP, and not
on #UD
When handling an "injected" exception after #VMGEXIT, verify that the VMM did (not) provide an error code as appropriate for the signaled vector. Treat an error code mismatch as a VMM error instead of synthesizing an exception.
--- arch/x86/kernel/sev-shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/sev-shared.c +3 -1
@@ -105,11 +105,13 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxtif (ret ==1 ) {u64 info = ghcb->save.sw_exit_info_2;u8 vector = info &SVM_EVTINJ_VEC_MASK ; +bool want_error_code = (vector ==X86_TRAP_GP );/* Check if exception information from hypervisor is sane. */ if ((info &SVM_EVTINJ_VALID ) && ((vector ==X86_TRAP_GP ) || (vector ==X86_TRAP_UD )) && - ((info &SVM_EVTINJ_TYPE_MASK ) ==SVM_EVTINJ_TYPE_EXEPT )) { + ((info &SVM_EVTINJ_TYPE_MASK ) ==SVM_EVTINJ_TYPE_EXEPT ) && + (!!(info &SVM_EVTINJ_VALID_ERR ) == want_error_code)) { ctxt->fi.vector = vector;if (info &SVM_EVTINJ_VALID_ERR )
--