Re: [PATCH v1 11/19] x86/sev-es: Convert to insn_decode()

From: Borislav Petkov
Date: Thu Jan 21 2021 - 12:00:40 EST


On Mon, Dec 28, 2020 at 11:15:11AM -0800, Sean Christopherson wrote:
> 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.

Personal Firearms Eligibility Check?

In any case, I prefer simple, easy to follow code at a quick glance.
Stuff like...

>
> 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))

... this second repeated check here is not what I would call that.

But this is my personal preference only so it's up for a vote now.

:-)

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette