All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: pbonzini@redhat.com
Cc: joro@8bytes.org, kvm@vger.kernel.org, nadav.amit@gmail.com,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH] x86: Test debug exceptions with disabled fast-string
Date: Wed, 20 Aug 2014 17:00:09 +0300	[thread overview]
Message-ID: <1408543209-30731-1-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1408543109-30687-1-git-send-email-namit@cs.technion.ac.il>

x86 allows to enable "fast strings", sacrificing the precision of debug
watchpoints.  Previously, KVM did not reflect the guest "fast strings" settings
in the actual MSR, resulting always in imprecise exception.

This test checks whether disabled "fast strings" causes the debug trap on
rep-string to occur on the precise iteration. A debug watchpoint which is not
cache-line aligned is set, and 128 bytes are set using rep-string operation.
The iteration in which the debug exception occurred is then checked.

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

diff --git a/x86/debug.c b/x86/debug.c
index 34e56fb..eb96dbe 100644
--- a/x86/debug.c
+++ b/x86/debug.c
@@ -11,10 +11,13 @@
 
 #include "libcflat.h"
 #include "desc.h"
+#include "msr.h"
+#include "processor.h"
 
-static volatile unsigned long bp_addr[10], dr6[10];
+static volatile unsigned long bp_addr[10], dr6[10], rcx[10];
 static volatile unsigned int n;
 static volatile unsigned long value;
+static unsigned char dst[128] __attribute__ ((aligned(64)));
 
 static unsigned long get_dr6(void)
 {
@@ -43,6 +46,7 @@ static void handle_db(struct ex_regs *regs)
 {
 	bp_addr[n] = regs->rip;
 	dr6[n] = get_dr6();
+	rcx[n] = regs->rcx;
 
 	if (dr6[n] & 0x1)
 		regs->rflags |= (1 << 16);
@@ -60,7 +64,7 @@ static void handle_bp(struct ex_regs *regs)
 
 int main(int ac, char **av)
 {
-	unsigned long start;
+	unsigned long start, misc_enable;
 
 	setup_idt();
 	handle_exception(DB_VECTOR, handle_db);
@@ -109,5 +113,18 @@ hw_wp:
 	       n == 1 &&
 	       bp_addr[0] == ((unsigned long)&&hw_wp) && dr6[0] == 0xffff4ff2);
 
+	misc_enable = rdmsr(MSR_IA32_MISC_ENABLE);
+	wrmsr(MSR_IA32_MISC_ENABLE,
+	      misc_enable & ~MSR_IA32_MISC_ENABLE_FAST_STRING);
+
+	n = 0;
+	set_dr1((void *)&dst[59]);
+	set_dr7(0x0010040a);
+
+	asm volatile("rep stosb\n\t" : : "D"(dst), "c"(128) : "cc", "memory");
+
+	report("hw watchpoint with disabled fast-string", rcx[0] == 128-1-59);
+	wrmsr(MSR_IA32_MISC_ENABLE, misc_enable);
+
 	return report_summary();
 }
-- 
1.9.1


      parent reply	other threads:[~2014-08-20 14:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 13:58 [PATCH 0/2] KVM: vmx: Supporting IA32_MISC_ENABLE MSR Nadav Amit
2014-08-20 13:58 ` [PATCH 1/2] KVM: x86: update cpuid according to IA32_MISC_ENABLE Nadav Amit
2014-08-20 13:58 ` [PATCH 2/2] KVM: vmx: Reflect misc_enables in real CPU Nadav Amit
2014-08-21 11:51   ` Paolo Bonzini
2014-08-21 12:28     ` Nadav Amit
2014-08-20 14:00 ` 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=1408543209-30731-1-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=nadav.amit@gmail.com \
    --cc=pbonzini@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.