From patchwork Sat Apr 15 07:45:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9682157 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 4C948601E7 for ; Sat, 15 Apr 2017 07:49:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28FED28533 for ; Sat, 15 Apr 2017 07:49:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B19E285F7; Sat, 15 Apr 2017 07:49:31 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 C4A1528533 for ; Sat, 15 Apr 2017 07:49:29 +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 1czIOx-00055E-GR; Sat, 15 Apr 2017 07:45:47 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1czIOv-000558-Gs for xen-devel@lists.xen.org; Sat, 15 Apr 2017 07:45:45 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id F1/59-27751-8AFC1F85; Sat, 15 Apr 2017 07:45:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRWlGSWpSXmKPExsUSfTxjoe6K8x8 jDOZ/ZrVY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDM2nF/DWHBEo2L1r7VMDYzHpbsYOTmEBDwk jmx7wtjFyAVkr2WUaD0xgQXCucYo8fFKPzNM1eyLM9khEvsZJbYe3AeWYBMwlFi9sYUNxBYRk Ja49vkyI4jNLFAuMWN6BwuILSzgInHs01UmEJtFQFVi8oNJYDW8Ap4S3b19YHMkBOQkTh6bzA ph50h0r94GZHMA2VIS/1uVQPZKCKxgkZi55SRUjYzEo4k32SYwCixgZFjFqF6cWlSWWqRrqZd UlJmeUZKbmJmja2hgppebWlycmJ6ak5hUrJecn7uJERhYDECwg/HupoBDjJIcTEqivK4xHyOE +JLyUyozEosz4otKc1KLDzHKcHAoSfD6ngPKCRalpqdWpGXmAEMcJi3BwaMkwusOkuYtLkjML c5Mh0idYtTleLf0w3smIZa8/LxUKXHe9SBFAiBFGaV5cCNg8XaJUVZKmJcR6CghnoLUotzMEl T5V4ziHIxKwrwRIFN4MvNK4Da9AjqCCegIhskfQI4oSURISTUw2rXGNpbP/LTgU5fnxxsld79 tnDeJsT1gy1M2c7f5ErW/lKf8C+RbvSboe/fnXU5C/3249xR2CnQe+czLf+DNvqbpUuHhR+2l jIqOtUdd/98bs0TwosyJr10MJyua/015HCHVLXrf3q/FRPDHC703V/SXfl2lFHjVWu7ZGVeWh xVfC5zPST94qsRSnJFoqMVcVJwIAFAuhFeyAgAA X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1492242343!60318239!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51331 invoked from network); 15 Apr 2017 07:45:44 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-3.tower-21.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 15 Apr 2017 07:45:43 -0000 Received: (qmail 30349 invoked from network); 15 Apr 2017 10:45:42 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 15 Apr 2017 10:45:42 +0300 Received: from smtp03.buh.bitdefender.org (smtp.bitdefender.biz [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 1D4617FBE6 for ; Sat, 15 Apr 2017 10:45:42 +0300 (EEST) Received: (qmail 22792 invoked from network); 15 Apr 2017 10:45:42 +0300 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp03.buh.bitdefender.org with AES128-SHA256 encrypted SMTP; 15 Apr 2017 10:45:41 +0300 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Sat, 15 Apr 2017 10:45:28 +0300 Message-Id: <1492242328-22912-1-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp03.buh.bitdefender.org, sigver: 7.70832 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 446260, Stamp: 3], Multi: [Enabled, t: (0.000012, 0.022336)], BW: [Enabled, t: (0.000010)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.006682), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.014114,0.000290)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.047430), Hit: No, Details: v2.4.6; Id: 11.5eumo9.1bcsfon38.7dn0f], total: 0(775) X-BitDefender-CF-Stamp: none Cc: wei.liu2@citrix.com, tamas@tklengyel.com, ian.jackson@eu.citrix.com, Razvan Cojocaru Subject: [Xen-devel] [PATCH V2] tests/xen-access: Added vm_event emulation tests 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 This patch adds support for testing instruction emulation when required by the vm_event reply sent for MEM_ACCESS events. To this end, it adds the "emulate_write" and "emulate_exec" parameters that behave like the old "write" and "exec" parameters, except instead of allowing writes / executes for a hit page, they emulate the trigger instruction. The new parameters don't mark all of the guest's pages, instead they stop at the arbitrary low limit of the first 1000 pages - otherwise the guest would slow to a crawl. Since the emulator is still incomplete and has trouble with emulating competing writes in SMP scenarios, the new tests are only meant for debugging issues. Signed-off-by: Razvan Cojocaru Acked-by: Tamas K Lengyel --- Changes since V1: - Moved emulate_write and emulate_exec to the x86-only part of the code. - Stopped pointlessly setting after_first_access. - Added a comment explaining the 1000 pages limit. --- tools/tests/xen-access/xen-access.c | 52 ++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index ff4d289..0852ac5 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -337,7 +337,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, "|emulate_write|emulate_exec|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access"); #elif defined(__arm__) || defined(__aarch64__) fprintf(stderr, "|privcall"); #endif @@ -369,6 +369,7 @@ int main(int argc, char *argv[]) int debug = 0; int cpuid = 0; int desc_access = 0; + int emulate = 0; uint16_t altp2m_view_id = 0; char* progname = argv[0]; @@ -411,6 +412,18 @@ int main(int argc, char *argv[]) memaccess = 1; } #if defined(__i386__) || defined(__x86_64__) + else if ( !strcmp(argv[0], "emulate_write") ) + { + default_access = XENMEM_access_rx; + emulate = 1; + memaccess = 1; + } + else if ( !strcmp(argv[0], "emulate_exec") ) + { + default_access = XENMEM_access_rw; + emulate = 1; + memaccess = 1; + } else if ( !strcmp(argv[0], "breakpoint") ) { breakpoint = 1; @@ -527,6 +540,21 @@ int main(int argc, char *argv[]) if ( memaccess && !altp2m ) { + uint32_t nr_pages = xenaccess->max_gpfn - START_PFN; + + /* + The Xen emulator is not yet complete. Limiting ourselves to a small number + of pages from the first part of the guest's memory makes it less likely for + the guest to get stuck on an UNHANDLEABLE instruction (since that memory + tends to be used by simpler kernel code), and is less likely to have a heavy + impact on the guest (since emulating everything will take a heavy toll). + While it presents no guarantee that all the instructions will pass emulation, + using the first 1000 pages has proven useful in practice. The limit can be + changed in the future. + */ + if ( emulate && nr_pages > 1000 ) + nr_pages = 1000; + /* Set the default access type and convert all pages to it */ rc = xc_set_mem_access(xch, domain_id, default_access, ~0ull, 0); if ( rc < 0 ) @@ -535,8 +563,7 @@ int main(int argc, char *argv[]) goto exit; } - rc = xc_set_mem_access(xch, domain_id, default_access, START_PFN, - (xenaccess->max_gpfn - START_PFN) ); + rc = xc_set_mem_access(xch, domain_id, default_access, START_PFN, nr_pages); if ( rc < 0 ) { @@ -702,15 +729,20 @@ int main(int argc, char *argv[]) } else if ( default_access != after_first_access ) { - rc = xc_set_mem_access(xch, domain_id, after_first_access, - req.u.mem_access.gfn, 1); - if (rc < 0) + if ( !emulate ) { - ERROR("Error %d setting gfn to access_type %d\n", rc, - after_first_access); - interrupted = -1; - continue; + rc = xc_set_mem_access(xch, domain_id, after_first_access, + req.u.mem_access.gfn, 1); + if (rc < 0) + { + ERROR("Error %d setting gfn to access_type %d\n", rc, + after_first_access); + interrupted = -1; + continue; + } } + else + rsp.flags |= VM_EVENT_FLAG_EMULATE; } rsp.u.mem_access = req.u.mem_access;