On Thu, Jan 21, 2021, Borislav Petkov wrote:
> 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?

Ha, Page Fault Error Code.

> 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 then you're stuck maintaining two separate flows that do the same thing.

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

Rock Paper Scissors?

Reply via email to