diff mbox series

[v2] KVM:x86: Clean up ModR/M "reg" initialization in reg op decoding

Message ID 20220908141210.1375828-1-zhiguangni01@zhaoxin.com (mailing list archive)
State New, archived
Headers show
Series [v2] KVM:x86: Clean up ModR/M "reg" initialization in reg op decoding | expand

Commit Message

Liam Ni Sept. 8, 2022, 2:12 p.m. UTC
From: Liam Ni <zhiguangni01@gmail.com>

Refactor decode_register_operand() to get the ModR/M register if and
only if the instruction uses a ModR/M encoding to make it more obvious
how the register operand is retrieved.

Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
---
 arch/x86/kvm/emulate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Sean Christopherson Sept. 8, 2022, 3:50 p.m. UTC | #1
On Thu, Sep 08, 2022, Liam Ni wrote:
> From: Liam Ni <zhiguangni01@gmail.com>
> 
> Refactor decode_register_operand() to get the ModR/M register if and
> only if the instruction uses a ModR/M encoding to make it more obvious
> how the register operand is retrieved.
> 
> Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
> ---

Pushed to branch `for_paolo/6.1` at:

    https://github.com/sean-jc/linux.git

with the below nit sqaushed.  Unless you hear otherwise, it will make its way to
kvm/queue "soon".

Note, the commit IDs are not guaranteed to be stable.

>  arch/x86/kvm/emulate.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index f092c54d1a2f..879b52af763a 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -1137,9 +1137,11 @@ static int em_fnstsw(struct x86_emulate_ctxt *ctxt)
>  static void decode_register_operand(struct x86_emulate_ctxt *ctxt,
>  				    struct operand *op)
>  {
> -	unsigned reg = ctxt->modrm_reg;
> +	unsigned int reg;
>  
> -	if (!(ctxt->d & ModRM))
> +	if ((ctxt->d & ModRM))

Only need one set of parentheses.  

> +		reg = ctxt->modrm_reg;
> +	else
>  		reg = (ctxt->b & 7) | ((ctxt->rex_prefix & 1) << 3);
>  
>  	if (ctxt->d & Sse) {
> -- 
> 2.34.1
>
Liam Ni Sept. 9, 2022, 1:47 p.m. UTC | #2
On Thu, 8 Sept 2022 at 23:50, Sean Christopherson <seanjc@google.com> wrote:
>
> On Thu, Sep 08, 2022, Liam Ni wrote:
> > From: Liam Ni <zhiguangni01@gmail.com>
> >
> > Refactor decode_register_operand() to get the ModR/M register if and
> > only if the instruction uses a ModR/M encoding to make it more obvious
> > how the register operand is retrieved.
> >
> > Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
> > ---
>
> Pushed to branch `for_paolo/6.1` at:
>
>     https://github.com/sean-jc/linux.git
>
> with the below nit sqaushed.  Unless you hear otherwise, it will make its way to
> kvm/queue "soon".
>
> Note, the commit IDs are not guaranteed to be stable.
>
> >  arch/x86/kvm/emulate.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> > index f092c54d1a2f..879b52af763a 100644
> > --- a/arch/x86/kvm/emulate.c
> > +++ b/arch/x86/kvm/emulate.c
> > @@ -1137,9 +1137,11 @@ static int em_fnstsw(struct x86_emulate_ctxt *ctxt)
> >  static void decode_register_operand(struct x86_emulate_ctxt *ctxt,
> >                                   struct operand *op)
> >  {
> > -     unsigned reg = ctxt->modrm_reg;
> > +     unsigned int reg;
> >
> > -     if (!(ctxt->d & ModRM))
> > +     if ((ctxt->d & ModRM))
>
> Only need one set of parentheses.

Sorry,  Should I prepare a new patch?

>
> > +             reg = ctxt->modrm_reg;
> > +     else
> >               reg = (ctxt->b & 7) | ((ctxt->rex_prefix & 1) << 3);
> >
> >       if (ctxt->d & Sse) {
> > --
> > 2.34.1
> >
Sean Christopherson Sept. 9, 2022, 2:57 p.m. UTC | #3
On Fri, Sep 09, 2022, Liam Ni wrote:
> On Thu, 8 Sept 2022 at 23:50, Sean Christopherson <seanjc@google.com> wrote:
> >
> > On Thu, Sep 08, 2022, Liam Ni wrote:
> > > From: Liam Ni <zhiguangni01@gmail.com>
> > >
> > > Refactor decode_register_operand() to get the ModR/M register if and
> > > only if the instruction uses a ModR/M encoding to make it more obvious
> > > how the register operand is retrieved.
> > >
> > > Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
> > > ---
> >
> > Pushed to branch `for_paolo/6.1` at:
> >
> >     https://github.com/sean-jc/linux.git
> >
> > with the below nit sqaushed.  Unless you hear otherwise, it will make its way to
> > kvm/queue "soon".
> >
> > Note, the commit IDs are not guaranteed to be stable.
> >
> > >  arch/x86/kvm/emulate.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> > > index f092c54d1a2f..879b52af763a 100644
> > > --- a/arch/x86/kvm/emulate.c
> > > +++ b/arch/x86/kvm/emulate.c
> > > @@ -1137,9 +1137,11 @@ static int em_fnstsw(struct x86_emulate_ctxt *ctxt)
> > >  static void decode_register_operand(struct x86_emulate_ctxt *ctxt,
> > >                                   struct operand *op)
> > >  {
> > > -     unsigned reg = ctxt->modrm_reg;
> > > +     unsigned int reg;
> > >
> > > -     if (!(ctxt->d & ModRM))
> > > +     if ((ctxt->d & ModRM))
> >
> > Only need one set of parentheses.
> 
> Sorry,  Should I prepare a new patch?

Nope, all taken care of.  Thanks!
diff mbox series

Patch

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f092c54d1a2f..879b52af763a 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1137,9 +1137,11 @@  static int em_fnstsw(struct x86_emulate_ctxt *ctxt)
 static void decode_register_operand(struct x86_emulate_ctxt *ctxt,
 				    struct operand *op)
 {
-	unsigned reg = ctxt->modrm_reg;
+	unsigned int reg;
 
-	if (!(ctxt->d & ModRM))
+	if ((ctxt->d & ModRM))
+		reg = ctxt->modrm_reg;
+	else
 		reg = (ctxt->b & 7) | ((ctxt->rex_prefix & 1) << 3);
 
 	if (ctxt->d & Sse) {