On Fri, Dec 25, 2020, Borislav Petkov wrote: > On Fri, Dec 25, 2020 at 06:50:33PM +0800, kernel test robot wrote: > > If you fix the issue, kindly add following tag as appropriate > > Reported-by: kernel test robot <l...@intel.com> > > > > All warnings (new ones prefixed by >>): > > > > >> arch/x86/kernel/sev-es.c:258:7: warning: variable 'ret' is used > > >> uninitialized whenever 'if' condition is false > > >> [-Wsometimes-uninitialized] > > if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer, > > res)) > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Yeah, good catch, thanks for reporting. > > Frankly, the readability and "extensiblity" of that function can be > improved by splitting the two cases (diff ontop):
Alternatively, could the kernel case use insn_decode_regs()? If vc_fetch_insn_kernel() were also modified to mirror insn_fetch_from_user(), the two code paths could be unified except for the the fetch and the PFEC. E.g. static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt, unsigned char *buffer) { if (copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE)) return 0; return MAX_INSN_SIZE; } static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) { char buffer[MAX_INSN_SIZE]; int nbytes; if (user_mode(ctxt->regs)) nbytes = insn_fetch_from_user(ctxt->regs, buffer); else nbytes = vc_fetch_insn_kernel(ctxt, buffer); if (!nbytes) { ctxt->fi.vector = X86_TRAP_PF; ctxt->fi.error_code = X86_PF_INSTR; if (user_mode(ctxt->regs)) ctxt->fi.error_code |= X86_PF_USER; ctxt->fi.cr2 = ctxt->regs->ip; return ES_EXCEPTION; } if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer, nbytes)) return ES_DECODE_FAILED; return ctxt->insn.immediate.got ? ES_OK : ES_DECODE_FAILED; }