mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: pbonzini@redhat.com
Cc: gleb@kernel.org, tglx@linutronix.de, mingo@redhat.com,
	hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH kvm-unit-tests v2] x86: emulator: long mode smsw tests
Date: Sun,  8 Jun 2014 13:02:45 +0300	[thread overview]
Message-ID: <1402221765-24337-1-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <5391760E.2030401@redhat.com>

SMSW instruction on long-mode is performed according to the operand size, if
the destination operand is a register.  This patch tests whether it is
performed correctly instead of always using two-bytes operands (as KVM
previously did).  Note that when a dword destination operand is used, the
result is zero-extended to qword on long-mode.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
 x86/emulator.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/x86/emulator.c b/x86/emulator.c
index 033f246..f653127 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -825,6 +825,26 @@ static void test_movabs(uint64_t *mem, uint8_t *insn_page,
     report("64-bit mov imm2", outregs.rcx == 0x9090909090909090);
 }
 
+static void test_smsw_reg(uint64_t *mem, uint8_t *insn_page,
+		      uint8_t *alt_insn_page, void *insn_ram)
+{
+	unsigned long cr0 = read_cr0();
+	inregs = (struct regs){ .rax = 0x1234567890abcdeful };
+
+	MK_INSN(smsww, "smsww %ax\n\t");
+	trap_emulator(mem, alt_insn_page, &insn_smsww);
+	report("16-bit smsw reg", (u16)outregs.rax == (u16)cr0 &&
+				  outregs.rax >> 16 == inregs.rax >> 16);
+
+	MK_INSN(smswl, "smswl %eax\n\t");
+	trap_emulator(mem, alt_insn_page, &insn_smswl);
+	report("32-bit smsw reg", outregs.rax == (u32)cr0);
+
+	MK_INSN(smswq, "smswq %rax\n\t");
+	trap_emulator(mem, alt_insn_page, &insn_smswq);
+	report("64-bit smsw reg", outregs.rax == cr0);
+}
+
 static void test_crosspage_mmio(volatile uint8_t *mem)
 {
     volatile uint16_t w, *pw;
@@ -1024,6 +1044,7 @@ int main()
 
 	test_mmx_movq_mf(mem, insn_page, alt_insn_page, insn_ram);
 	test_movabs(mem, insn_page, alt_insn_page, insn_ram);
+	test_smsw_reg(mem, insn_page, alt_insn_page, insn_ram);
 
 	test_crosspage_mmio(mem);
 
-- 
1.9.1


      reply	other threads:[~2014-06-08 10:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 15:34 [PATCH 0/9] KVM: x86: Fixes for various emulator bugs Nadav Amit
2014-06-02 15:34 ` [PATCH 1/9] KVM: x86: Mark VEX-prefix instructions emulation as unimplemented Nadav Amit
2014-06-02 15:34 ` [PATCH 2/9] KVM: x86: Emulator ignores LDTR/TR extended base on LLDT/LTR Nadav Amit
2014-06-02 15:34 ` [PATCH 3/9] KVM: x86: Loading segments on 64-bit mode may be wrong Nadav Amit
2014-06-02 15:34 ` [PATCH 4/9] KVM: x86: sgdt and sidt are not privilaged Nadav Amit
2014-06-02 15:34 ` [PATCH 5/9] KVM: x86: cmpxchg emulation should compare in reverse order Nadav Amit
2014-06-02 15:34 ` [PATCH 6/9] KVM: x86: movnti minimum op size of 32-bit is not kept Nadav Amit
2014-06-02 15:34 ` [PATCH 7/9] KVM: x86: rdpmc emulation checks the counter incorrectly Nadav Amit
2014-06-02 15:34 ` [PATCH 8/9] KVM: x86: Return error on cmpxchg16b emulation Nadav Amit
2014-06-02 15:34 ` [PATCH 9/9] KVM: x86: smsw emulation is incorrect in 64-bit mode Nadav Amit
2014-06-05 14:53   ` Paolo Bonzini
2014-06-05 15:02     ` Nadav Amit
2014-06-05 15:04       ` H. Peter Anvin
2014-06-05 15:27         ` Paolo Bonzini
2014-06-05 23:56           ` [PATCH kvm-unit-tests 0/2] x86: Additional smsw tests Nadav Amit
2014-06-05 23:56             ` [PATCH kvm-unit-tests1/2] x86: emulator: additional smsw test-case Nadav Amit
2014-06-09 11:36               ` Paolo Bonzini
2014-06-05 23:56             ` [PATCH kvm-unit-tests 2/2] x86: realmode: test smsw behavior with register operand Nadav Amit
2014-06-06  8:04             ` [PATCH kvm-unit-tests 0/2] x86: Additional smsw tests Paolo Bonzini
2014-06-08 10:02               ` Nadav Amit [this message]

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=1402221765-24337-1-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --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®