public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM:x86: Clean up ModR/M "reg" initialization in reg op decoding
@ 2022-09-08 14:12 Liam Ni
  2022-09-08 15:50 ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Liam Ni @ 2022-09-08 14:12 UTC (permalink / raw)
  To: linux-kernel, kvm, x86; +Cc: pbonzini, tglx, dave.hansen, seanjc, zhiguangni01

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

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-09 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-08 14:12 [PATCH v2] KVM:x86: Clean up ModR/M "reg" initialization in reg op decoding Liam Ni
2022-09-08 15:50 ` Sean Christopherson
2022-09-09 13:47   ` Liam Ni
2022-09-09 14:57     ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox