From patchwork Mon Apr 10 09:44:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9672249 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 BC4F160244 for ; Mon, 10 Apr 2017 09:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4C67212BE for ; Mon, 10 Apr 2017 09:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9725C24603; Mon, 10 Apr 2017 09:47:20 +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 23540212BE for ; Mon, 10 Apr 2017 09:47:20 +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 1cxVsa-0007FI-Pj; Mon, 10 Apr 2017 09:45:00 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxVsa-0007FC-Az for xen-devel@lists.xen.org; Mon, 10 Apr 2017 09:45:00 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 5A/04-20914-B145BE85; Mon, 10 Apr 2017 09:44:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRWlGSWpSXmKPExsUSfTxjoa5UyOs Ig223zS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1owvH84zFTxUqDjUc4SlgfGfaBcjJ4eQgIfE jNerWLsYuYDstYwSEzd0QznXGCVeXXrMBFN1e9tkRojEfkaJz3c2sYIk2AQMJVZvbGEDsUUEp CWufb7MCGIzC5RLzJjewQJiCws4SrxY0ApWwyKgKrH31E92EJtXwFNizvmjYLaEgJzEyWOTWS HsHIlp1xcB2RxAtpTE/1YlkL0SAhtZJDYvfg5VIyPxaOJNtgmMAgsYGVYxahSnFpWlFukaWeg lFWWmZ5TkJmbm6BoaGOvlphYXJ6an5iQmFesl5+duYgSGVj0DA+MOxvYTfocYJTmYlER50y1f RwjxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4D0XBJQTLEpNT61Iy8wBBjlMWoKDR0mEtxokzVtck JhbnJkOkTrFqMvxbumH90xCLHn5ealS4rzbQYoEQIoySvPgRsAi7hKjrJQwLyMDA4MQT0FqUW 5mCar8K0ZxDkYlYV7xYKApPJl5JXCbXgEdwQR0xJldL0GOKElESEk1MEYatH/j9L/Wzjf5c+v Db6/1H5+0vuvU0V0RN2+esJTJnmcval80Zxvrmd/8vUPh7OvYzHOswmo/k2+ar30SMn/X2tCm 8Ec/3TVOhe9e9MpQJf68qdtzZdmSHTPLvotu6JfcfMjlwB67+sQrv9+eL3ntrXNXpvNDteES/ vrWzZONb7Psbjf4PEmJpTgj0VCLuag4EQBt6p36swIAAA== X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1491817497!95036860!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 8519 invoked from network); 10 Apr 2017 09:44:58 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-14.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 10 Apr 2017 09:44:58 -0000 Received: (qmail 14025 invoked from network); 10 Apr 2017 12:44:56 +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; 10 Apr 2017 12:44:56 +0300 Received: from smtp01.buh.bitdefender.com (smtp.bitdefender.biz [10.17.80.75]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 9BB7F7FC78 for ; Mon, 10 Apr 2017 12:44:56 +0300 (EEST) Received: (qmail 10912 invoked from network); 10 Apr 2017 12:44:56 +0300 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp01.buh.bitdefender.com with AES128-SHA256 encrypted SMTP; 10 Apr 2017 12:44:56 +0300 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Mon, 10 Apr 2017 12:44:45 +0300 Message-Id: <1491817485-16896-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 smtp01.buh.bitdefender.com, sigver: 7.70731 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 445788, Stamp: 3], Multi: [Enabled, t: (0.000012, 0.017772)], BW: [Enabled, t: (0.000011)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.005603), 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.013308, 0.000205)], URL: [Enabled, t: (0.000005, 0.000001)], RTDA: [Enabled, t: (0.383727), Hit: No, Details: v2.4.6; Id: 11.5eumo9.1bcsfon38.3qra7], 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] 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 --- tools/tests/xen-access/xen-access.c | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index ff4d289..0ba2e45 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -335,7 +335,7 @@ static void put_response(vm_event_t *vm_event, vm_event_response_t *rsp) void usage(char* progname) { - fprintf(stderr, "Usage: %s [-m] write|exec", progname); + fprintf(stderr, "Usage: %s [-m] write|exec|emulate_write|emulate_exec", progname); #if defined(__i386__) || defined(__x86_64__) fprintf(stderr, "|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access"); #elif defined(__arm__) || defined(__aarch64__) @@ -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]; @@ -404,12 +405,26 @@ int main(int argc, char *argv[]) after_first_access = XENMEM_access_rwx; memaccess = 1; } + else if ( !strcmp(argv[0], "emulate_write") ) + { + default_access = XENMEM_access_rx; + after_first_access = XENMEM_access_rwx; + emulate = 1; + memaccess = 1; + } else if ( !strcmp(argv[0], "exec") ) { default_access = XENMEM_access_rw; after_first_access = XENMEM_access_rwx; memaccess = 1; } + else if ( !strcmp(argv[0], "emulate_exec") ) + { + default_access = XENMEM_access_rw; + after_first_access = XENMEM_access_rwx; + emulate = 1; + memaccess = 1; + } #if defined(__i386__) || defined(__x86_64__) else if ( !strcmp(argv[0], "breakpoint") ) { @@ -536,7 +551,7 @@ int main(int argc, char *argv[]) } rc = xc_set_mem_access(xch, domain_id, default_access, START_PFN, - (xenaccess->max_gpfn - START_PFN) ); + emulate ? 1000 : (xenaccess->max_gpfn - START_PFN)); if ( rc < 0 ) { @@ -702,15 +717,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;