From patchwork Mon Jun 19 12:24:39 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: 9795833 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 87E16600C5 for ; Mon, 19 Jun 2017 12:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79C7526E75 for ; Mon, 19 Jun 2017 12:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E86C283B0; Mon, 19 Jun 2017 12:28:09 +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 AFB3F26E75 for ; Mon, 19 Jun 2017 12:28:05 +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 1dMvjb-0006K9-KD; Mon, 19 Jun 2017 12:24:47 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMvja-0006Jh-8f for xen-devel@lists.xen.org; Mon, 19 Jun 2017 12:24:46 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 4E/1E-02196-D82C7495; Mon, 19 Jun 2017 12:24:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRWlGSWpSXmKPExsUSfTyjVbf7kHu kwbmJphZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8alSy3sBddkK1o2PmVpYLwt2sXIycEsYC3R +6+ZsYuRi4NFYBaLxLv2JnYIZwKLxPype5i7GDk4hATcJZbd5wGJCwksYJRYtWMhO0i3kICHx OSpb9kg7MVAiY8sIDabgJHEkmVvwWpEBKQlrn2+DLaBWeAIo8Tmq//AioQFLCX6365gBrFZBF QlLn9dCtbAK+ApseVMD5gtISAncfNcJ9gRnAJeEvc/VkMc0cEosfLVX9YJjEDnMKxiVC9OLSp LLdI11UsqykzPKMlNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECAysegYGxh2Ml786HWKU5GBS EuW13e4eKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC1/YgUE6wKDU9tSItMwcY4jBpCQ4eJRHen SBp3uKCxNzizHSI1ClGXY4Nq9d/YRJiycvPS5US500DKRIAKcoozYMbAYu3S4yyUsK8jAwMDE I8BalFuZklqPKvGMU5GJWEeUUOAE3hycwrgdv0CugIJqAjmM+4gBxRkoiQkmpgDNddJ91/gKX t7bb54aLnd8zMi/v+7/yeRcwXljaeCs9gWTblI3OIYWWnWO/W4Ngvk07lbZ3/WPKpt95pJ7UF wo25gf433eP0w9OnsO19bqWrUXTdt5Q1On9NnJ7GAcudAXEBz4oXXmAVfPs0zY3hyqQNPIxXO xbsP/FaVsqAeccOG0sZCfnlSizFGYmGWsxFxYkAnSreBbICAAA= X-Env-Sender: ppircalabu@bitdefender.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1497875083!48226138!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 23959 invoked from network); 19 Jun 2017 12:24:43 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-4.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 19 Jun 2017 12:24:43 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=cIfUkb2m0fNiJSsA4OKnKjNjCvBzfpAxgp8C7yDTkC5dFZVYSbf0vwwSsUhQ4PQkclQ+J1foPAn+m8rweYz2707eyqXk5iZw8BAQ5dc0PG5Z41Xsn0mAIyxk6GaYKhncUaVymRAgVS+BbaEnWtJnm1O6FFR8gSy6UP4v+SSnmY4LZDocdj5fS0QXyhFOrX4Yi6DfBAslsGO68y98APwb3SJUFslVgVEHTUrCcR23ow7WMHMyM2cLnfZU8ORt7bfVBH9A35gLco9eGgDA7JWa3SQW0GEqN4A12vyYXodzmn2CEnReKmjnSYudTqvHdcK6UNlEisPsDinNsiHFIKg0vg==; 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=U5JqxSWuI8srPM36Qiwfr2ZgycI=; b=XyXoy0Z1JHAPav/Owg7Do6bPOoFU RXOv7CRxz55S7YWruduRcOIs6EZAcSmrD7ARtaZcL0FMQt2I2XWBIDWagRbMGFeW +/XqnMVlyHbBvBESZHKQEXbEl5QPhBewqPLxSpApCLx1oWhzED3xlth3QW/tSvod ceb+RFdTRKDxai85nlvSeIR2k9B+OVYaCitX3NZFk2+Y+3s33tEeBV25GWdELtzO vw87jfm5ryGK2cnVx4NM5/CSx253smeMZ7/zb1jVZk22DMaVCtGAoAfblINYBABE vtny7s1pGm5MRbOqpZPUYgmeQlYwRC3zZCmXohUnwmOqlFFiRCduxGYWfg== Received: (qmail 7125 invoked from network); 19 Jun 2017 15:24:42 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 19 Jun 2017 15:24:42 +0300 Received: (qmail 11409 invoked from network); 19 Jun 2017 15:24:42 +0300 Received: from unknown (HELO pepi-OptiPlex-9020.dsd.bitdefender.biz) (10.10.194.146) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 19 Jun 2017 15:24:42 +0300 From: Petre Pircalabu To: xen-devel@lists.xen.org Date: Mon, 19 Jun 2017 15:24:39 +0300 Message-Id: <1497875079-8169-3-git-send-email-ppircalabu@bitdefender.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497875079-8169-1-git-send-email-ppircalabu@bitdefender.com> References: <1496137567-6574-1-git-send-email-ppircalabu@bitdefender.com> <1497875079-8169-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 v4 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 Acked-by: Tamas K Lengyel --- 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..1e69e25 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] 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); }