All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petre Pircalabu <ppircalabu@bitdefender.com>
To: xen-devel@lists.xen.org
Cc: Petre Pircalabu <ppircalabu@bitdefender.com>,
	tamas@tklengyel.com, wei.liu2@citrix.com,
	rcojocaru@bitdefender.com, andrew.cooper3@citrix.com,
	ian.jackson@eu.citrix.com, jbeulich@suse.com
Subject: [PATCH v3 2/2] xen-access: write_ctrlreg_c4 test
Date: Fri, 16 Jun 2017 22:20:22 +0300	[thread overview]
Message-ID: <1497640822-7741-3-git-send-email-ppircalabu@bitdefender.com> (raw)
In-Reply-To: <1497640822-7741-1-git-send-email-ppircalabu@bitdefender.com>

Add test for write_ctrlreg event handling.

Signed-off-by: Petre Pircalabu <ppircalabu@bitdefender.com>
---
 tools/tests/xen-access/xen-access.c | 53 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c
index 238011e..bbf5047 100644
--- a/tools/tests/xen-access/xen-access.c
+++ b/tools/tests/xen-access/xen-access.c
@@ -57,6 +57,13 @@
 #define X86_TRAP_DEBUG  1
 #define X86_TRAP_INT3   3
 
+/* From xen/include/asm-x86/x86-defns.h */
+#define X86_CR4_PGE        0x00000080 /* enable global pages */
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
 typedef struct vm_event {
     domid_t domain_id;
     xenevtchn_handle *xce_handle;
@@ -314,6 +321,24 @@ static void get_request(vm_event_t *vm_event, vm_event_request_t *req)
 }
 
 /*
+ * X86 control register names
+ */
+static const char* get_x86_ctrl_reg_name(uint32_t index)
+{
+    static const char* names[] = {
+        [VM_EVENT_X86_CR0]  = "CR0",
+        [VM_EVENT_X86_CR3]  = "CR3",
+        [VM_EVENT_X86_CR4]  = "CR4",
+        [VM_EVENT_X86_XCR0] = "XCR0",
+    };
+
+    if ( index > ARRAY_SIZE(names) || names[index] == NULL )
+        return "";
+
+    return names[index];
+}
+
+/*
  * Note that this function is not thread safe.
  */
 static void put_response(vm_event_t *vm_event, vm_event_response_t *rsp)
@@ -337,7 +362,7 @@ void usage(char* progname)
 {
     fprintf(stderr, "Usage: %s [-m] <domain_id> write|exec", progname);
 #if defined(__i386__) || defined(__x86_64__)
-            fprintf(stderr, "|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access");
+            fprintf(stderr, "|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access|write_ctrlreg_cr4");
 #elif defined(__arm__) || defined(__aarch64__)
             fprintf(stderr, "|privcall");
 #endif
@@ -369,6 +394,7 @@ int main(int argc, char *argv[])
     int debug = 0;
     int cpuid = 0;
     int desc_access = 0;
+    int write_ctrlreg_cr4 = 1;
     uint16_t altp2m_view_id = 0;
 
     char* progname = argv[0];
@@ -439,6 +465,10 @@ int main(int argc, char *argv[])
     {
         desc_access = 1;
     }
+    else if ( !strcmp(argv[0], "write_ctrlreg_cr4") )
+    {
+        write_ctrlreg_cr4 = 1;
+    }
 #elif defined(__arm__) || defined(__aarch64__)
     else if ( !strcmp(argv[0], "privcall") )
     {
@@ -596,6 +626,18 @@ int main(int argc, char *argv[])
         }
     }
 
+    if ( write_ctrlreg_cr4 )
+    {
+        /* Mask the CR4.PGE bit so no events will be generated for global TLB flushes. */
+        rc = xc_monitor_write_ctrlreg(xch, domain_id, VM_EVENT_X86_CR4, 1, 1,
+                                      X86_CR4_PGE, 1);
+        if ( rc < 0 )
+        {
+            ERROR("Error %d setting write control register trapping with vm_event\n", rc);
+            goto exit;
+        }
+    }
+
     /* Wait for access */
     for (;;)
     {
@@ -806,6 +848,15 @@ int main(int argc, char *argv[])
                        req.u.desc_access.is_write);
                 rsp.flags |= VM_EVENT_FLAG_EMULATE;
                 break;
+            case VM_EVENT_REASON_WRITE_CTRLREG:
+                printf("Control register written: rip=%016"PRIx64", vcpu %d: "
+                       "reg=%s, old_value=%016"PRIx64", new_value=%016"PRIx64"\n",
+                       req.data.regs.x86.rip,
+                       req.vcpu_id,
+                       get_x86_ctrl_reg_name(req.u.write_ctrlreg.index),
+                       req.u.write_ctrlreg.old_value,
+                       req.u.write_ctrlreg.new_value);
+                break;
             default:
                 fprintf(stderr, "UNKNOWN REASON CODE %d\n", req.reason);
             }
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-06-16 19:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 13:41 write_ctrlreg event masking Petre Pircalabu
2017-05-26 13:41 ` [PATCH 1/2] x86/monitor: add masking support for write_ctrlreg events Petre Pircalabu
2017-05-29 15:01   ` Jan Beulich
2017-05-30  9:38     ` Petre PIRCALABU
2017-05-26 13:41 ` [PATCH 2/2] xen-access: write_ctrlreg_c4 test Petre Pircalabu
2017-05-30  9:46 ` write_ctrlreg event masking Petre Pircalabu
2017-05-30  9:46   ` [PATCH v2 1/2] x86/monitor: add masking support for write_ctrlreg events Petre Pircalabu
2017-06-16 14:26     ` Tamas K Lengyel
2017-06-16 15:15       ` Jan Beulich
2017-06-16 15:28         ` Tamas K Lengyel
2017-06-16 15:33           ` Jan Beulich
2017-06-16 16:24             ` Tamas K Lengyel
2017-05-30  9:46   ` [PATCH v2 2/2] xen-access: write_ctrlreg_c4 test Petre Pircalabu
2017-06-16 14:32     ` Tamas K Lengyel
2017-06-16 15:12       ` Jan Beulich
2017-06-16 15:24         ` Tamas K Lengyel
2017-06-16 14:09   ` write_ctrlreg event masking Petre Ovidiu PIRCALABU
2017-06-16 19:20   ` [PATCH v3 0/2] " Petre Pircalabu
2017-06-16 19:20     ` [PATCH v3 1/2] x86/monitor: add masking support for write_ctrlreg events Petre Pircalabu
2017-06-16 19:20     ` Petre Pircalabu [this message]
2017-06-16 19:45       ` [PATCH v3 2/2] xen-access: write_ctrlreg_c4 test Razvan Cojocaru
2017-06-19 12:24   ` [PATCH v4 0/2] write_ctrlreg event masking Petre Pircalabu
2017-06-19 12:24     ` [PATCH v4 1/2] x86/monitor: add masking support for write_ctrlreg events Petre Pircalabu
2017-06-20 12:42       ` Wei Liu
2017-06-21 13:58       ` Wei Liu
2017-06-21 14:11         ` Tamas K Lengyel
2017-06-21 14:13         ` Razvan Cojocaru
2017-06-21 14:19           ` Wei Liu
2017-06-19 12:24     ` [PATCH v4 2/2] xen-access: write_ctrlreg_c4 test Petre Pircalabu
2017-06-19 14:51       ` Tamas K Lengyel

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=1497640822-7741-3-git-send-email-ppircalabu@bitdefender.com \
    --to=ppircalabu@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=tamas@tklengyel.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 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.