From patchwork Tue May 30 09:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petre Ovidiu PIRCALABU X-Patchwork-Id: 9754221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E9F9602B9 for ; Tue, 30 May 2017 09:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F8227CEA for ; Tue, 30 May 2017 09:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 355DA27FA5; Tue, 30 May 2017 09:48:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA21327CEA for ; Tue, 30 May 2017 09:48:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFdjE-0006D1-Tx; Tue, 30 May 2017 09:46:16 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFdjD-0006CL-AB for xen-devel@lists.xen.org; Tue, 30 May 2017 09:46:15 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 64/54-01733-66F3D295; Tue, 30 May 2017 09:46:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrMIsWRWlGSWpSXmKPExsUSfTyjVTfJXjf SYFaXucWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmtF4YzlbwVPpik+nj7M0ME4Q6WLk5GAWsJbo /dfM2MXIxcEiMItF4srJB+wQzgQWiVvnjzKCVAkJeEis7D7HBJIQEljAKNG27TIzRMJd4uaK2 ewQicWMEnevNbKDJNgEjCSWLHsLZosISEtc+3wZbAezwBFGif0nzoIlhAUsJeY0TmUCsVkEVC Xab/8BW8cr4Clxv3MaK4gtISAncfNcJ9g2TgEviePbdrBCbOtklJjf9YZpAiPQQQyrGDWKU4v KUot0DU31kooy0zNKchMzc3QNDUz1clOLixPTU3MSk4r1kvNzNzECA4wBCHYwNmz3PMQoycGk JMrrbK0bKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCV90OKCdYlJqeWpGWmQMMdZi0BAePkgivK Uiat7ggMbc4Mx0idYpRl2PD6vVfmIRY8vLzUqXEeX/YAhUJgBRllObBjYDF3SVGWSlhXkago4 R4ClKLcjNLUOVfMYpzMCoJ854GmcKTmVcCt+kV0BFMQEfs2qENckRJIkJKqoFRp+ZpmW+V27I Pe/8GzWQ99/OUeXL1Ftvrv9qf8QSse8e3c5ece53hlYPHIh4+yrvw58zu83y/uCoP//y4O95B 9UtAxL3yI5uPzd9+2O+3u7PQ9IgXha370tz0w6+E/rkk+jxLKU9Y8tyjjcX11Xs59ofOuckhV Xu9+cWRxTvKP3MUP7V9/9vhohJLcUaioRZzUXEiAHFL7mu2AgAA X-Env-Sender: ppircalabu@bitdefender.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1496137570!81124524!1 X-Originating-IP: [91.199.104.133] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43955 invoked from network); 30 May 2017 09:46:10 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-11.tower-206.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 30 May 2017 09:46:10 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=SEvUs5GVU0TTrOyfHJvWH68Ya+SuqHobVnrXsRr9bdKjVY5skQ5tTJhiQz5yu/7ur1MF/yvdpZc3fl9osEtMYUOCS3PUekd9NaYm4bdNIhesLS9dsUVtTSng1T0mhUmAmXGwvJ1l7PwC/HlwZu/4kEv2d53fjSbsdtOX1rdqxQoECN9PCty6YEFpqImrzYAz0OrQMAEfB66ScNC4Vt6qwnvdJiOXuqu3iboHWN6KHsV7ee3yeE5ckAoUiPubYE8mMVLKhJJoJ581jMjWxeJCjT5beTyd/MYrn1B+rmAdGb/iyynuws179lAZ3IuMwiAsAFjwO+STpfaxelDK6HT7bg==; h=Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id:in-reply-to:references; s=default; bh=wyLrVJG+sIREhWxyZqYlJIyYI/Q=; b=Bl2YxIHr4Ewvu+gUeot/rUFN7CPa yqU0r5lglAzneuFxEcRaEgh03BE4GxQtXEiuqEiY/VJCXrS2mwv+/zwOvaWWjIsV RqwhbNVdOp9RT2PwItIQn8mJlpULm2ICfwO/A22wH+NIltdkwiDc/2U37tVBcoAv tnVbjccTt2ygJP/vaXgJz+h5aWdPx22OLRyh5fCLeQ0rx53ERmBfIxhojeiAiJEh iwdhpTo58T+w4NP7LjKoMrNy0oh081UcXMNJ4lMAI+kxQ9Ri7BWoBVpv2WlQe03i HJR1QUE0LrEv3EwWzmkRCWkivg6WPZMQGTccFsSoArCceRX/hCeV0Y7iBA== Received: (qmail 19372 invoked from network); 30 May 2017 12:46:09 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 30 May 2017 12:46:09 +0300 Received: (qmail 8778 invoked from network); 30 May 2017 12:46:09 +0300 Received: from unknown (HELO pepi-OptiPlex-9020.dsd.bitdefender.biz) (10.10.194.146) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 30 May 2017 12:46:09 +0300 From: Petre Pircalabu To: xen-devel@lists.xen.org Date: Tue, 30 May 2017 12:46:07 +0300 Message-Id: <1496137567-6574-3-git-send-email-ppircalabu@bitdefender.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496137567-6574-1-git-send-email-ppircalabu@bitdefender.com> References: <1495806118-12223-1-git-send-email-ppircalabu@bitdefender.com> <1496137567-6574-1-git-send-email-ppircalabu@bitdefender.com> Cc: Petre Pircalabu , tamas@tklengyel.com, wei.liu2@citrix.com, rcojocaru@bitdefender.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v2 2/2] xen-access: write_ctrlreg_c4 test X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add test for write_ctrlreg event handling. Signed-off-by: Petre Pircalabu --- tools/tests/xen-access/xen-access.c | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index 238011e..29b60e8 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -57,6 +57,9 @@ #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 */ + typedef struct vm_event { domid_t domain_id; xenevtchn_handle *xce_handle; @@ -314,6 +317,22 @@ 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[] = { + "CR0", + "CR3", + "CR4", + "XCR0", + }; + + return (index > 3) ? "" : 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 +356,7 @@ void usage(char* progname) { fprintf(stderr, "Usage: %s [-m] 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 +388,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 +459,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 +620,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 +842,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); }