mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Joerg Roedel <jroedel@suse.de>,
	Kuppuswamy Sathyanarayanan 
	<sathyanarayanan.kuppuswamy@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Sean Christopherson <seanjc@google.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Tony Luck <tony.luck@intel.com>
Subject: Re: [PATCH 2/3] x86/insn-eval: Introduce insn_decode_mmio()
Date: Tue, 19 Oct 2021 10:34:45 +0200	[thread overview]
Message-ID: <YW6DJZBLe0eJaQMu@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20211018164941.3nqq73pupep3cejz@box.shutemov.name>

On Mon, Oct 18, 2021 at 07:49:41PM +0300, Kirill A. Shutemov wrote:
> On Mon, Oct 18, 2021 at 05:53:49PM +0200, Peter Zijlstra wrote:
> > On Mon, Oct 18, 2021 at 06:33:32PM +0300, Kirill A. Shutemov wrote:
> > 
> > > diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
> > > index fbaa3fa24bde..2ab29d8d6731 100644
> > > --- a/arch/x86/lib/insn-eval.c
> > > +++ b/arch/x86/lib/insn-eval.c
> > > @@ -1559,3 +1559,85 @@ bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
> > >  
> > >  	return true;
> > >  }
> > > +
> > > +/**
> > > + * insn_decode_mmio() - Decode a MMIO instruction
> > > + * @insn:	Structure to store decoded instruction
> > > + * @bytes:	Returns size of memory operand
> > > + *
> > > + * Decodes instruction that used for Memory-mapped I/O.
> > > + *
> > > + * Returns:
> > > + *
> > > + * Type of the instruction. Size of the memory operand is stored in
> > > + * @bytes. If decode failed, MMIO_DECODE_FAILED returned.
> > > + */
> > > +enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
> > > +{
> > > +	int type = MMIO_DECODE_FAILED;
> > > +
> > > +	*bytes = 0;
> > > +
> > > +	insn_get_opcode(insn);
> > 
> > insn_get_opcode() can fail. Either you assume it's already called and
> > don't call it, or you can't assume anything and get to do error
> > handling.
> 
> Fair enough. I will return MMIO_DECODE_FAILED if insn_get_opcode() fails.
> 
> BTW, looks like is_string_insn() suffers from the same issue. Not sure how
> to fix it though.

AFAICT all callers of insn_get_addr_ref() (which is what
is_string_insn() seems to be part of) do a insn_decode_*() call with
error checking before.

So it looks like that insn_get_opcode() in there is superfluous.
probably same for insn_has_rep_prefix() / get_seg_reg_override_idx() /
get_eff_addr_modrm_*(). That all wants cleaning up.

The esaiest way is probably to push those things up the callchains into
the !static function and have it fail early there.

  reply	other threads:[~2021-10-19  8:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18 15:33 [PATCH 0/3] Add generic MMIO instruction deconding to be used in SEV and TDX Kirill A. Shutemov
2021-10-18 15:33 ` [PATCH 1/3] x86/insn-eval: Introduce insn_get_modrm_reg_ptr() Kirill A. Shutemov
2021-10-18 15:47   ` Peter Zijlstra
2021-10-18 16:44     ` Kirill A. Shutemov
2021-10-18 15:33 ` [PATCH 2/3] x86/insn-eval: Introduce insn_decode_mmio() Kirill A. Shutemov
2021-10-18 15:53   ` Peter Zijlstra
2021-10-18 16:49     ` Kirill A. Shutemov
2021-10-19  8:34       ` Peter Zijlstra [this message]
2021-10-23 16:32         ` Kirill A. Shutemov
2021-10-18 15:33 ` [PATCH 3/3] x86/sev-es: Use insn_decode_mmio() for MMIO implementation Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YW6DJZBLe0eJaQMu@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=jroedel@suse.de \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®