From patchwork Thu Mar 16 12:32:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9628077 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 39AFD60244 for ; Thu, 16 Mar 2017 12:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BE4227D0E for ; Thu, 16 Mar 2017 12:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DCE8285ED; Thu, 16 Mar 2017 12:35:01 +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 3EA1E27D0E for ; Thu, 16 Mar 2017 12:34:59 +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 1coUZw-0001I5-Da; Thu, 16 Mar 2017 12:32:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coUZv-0001Hz-Mx for xen-devel@lists.xen.org; Thu, 16 Mar 2017 12:32:27 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 16/58-13095-BD58AC85; Thu, 16 Mar 2017 12:32:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRWlGSWpSXmKPExsUSfTxjoe6N1lM RBjfu81ks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmfWk6zF1xIr7i1fCVTA+M7ry5GTg4hAQ+J my0H2boYuYDstYwSm6Z2sUM4Vxklzi0+ywZR5S5x4MlkqMR+Ronta+8wgyTYBAwlVm9sASsSE ZCWuPb5MiNIETNI0aEla8ESwkA7TrbuZAGxWQRUJc5s+sMIYvMKeErMOPoRrEZCQE7i5LHJrB B2jkTnnjNA2ziAbCmJ/61KIDMlBNazSMy4/5AdokZG4tHEm2wTGAUWMDKsYlQvTi0qSy3SNdF LKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAgMLQYg2MHYfdn/EKMkB5OSKK+K4IkI Ib6k/JTKjMTijPii0pzU4kOMMhwcShK8V2YD5QSLUtNTK9Iyc4BBDpOW4OBREuHtngWU5i0uS MwtzkyHSJ1i1OWYM3v3GyYhlrz8vFQpcd4+kBkCIEUZpXlwI2ARd4lRVkqYlxHoKCGegtSi3M wSVPlXjOIcjErCvKZzgKbwZOaVwG16BXQEE9ARiT+PgBxRkoiQkmpgjH/Jvq9utu0tp2vs5vw XefTKLl5ZbaEUIHGh6VxY4we99rdrdzfomYvOliydckHs986udzkyOo9mb+f/P3ObfGw+160F n1db/9g7Ydv1d9ZKXz6JlPcc+SBlqnqf1fKf3XNuxkJpO1GRjdbCmo0r7h257c32Uu3hnMOb3 imqimZcn3fJcc3hTCWW4oxEQy3mouJEAM8tmd6zAgAA X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-9.tower-21.messagelabs.com!1489667543!62519435!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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46244 invoked from network); 16 Mar 2017 12:32:24 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-9.tower-21.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 16 Mar 2017 12:32:24 -0000 Received: (qmail 18928 invoked from network); 16 Mar 2017 14:32:22 +0200 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; 16 Mar 2017 14:32:22 +0200 Received: from smtp03.buh.bitdefender.org (smtp.bitdefender.biz [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 9A3BB7FBE8 for ; Thu, 16 Mar 2017 14:32:22 +0200 (EET) Received: (qmail 6970 invoked from network); 16 Mar 2017 14:32:22 +0200 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; 16 Mar 2017 14:32:22 +0200 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Thu, 16 Mar 2017 14:32:07 +0200 Message-Id: <1489667527-14559-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.70199 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 443395, Stamp: 3], Multi: [Enabled, t: (0.000017, 0.054961)], BW: [Enabled, t: (0.000010)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.014603), 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.019548, 0.000649)], URL: [Enabled, t: (0.000005, 0.000001)], RTDA: [Enabled, t: (0.150180), Hit: No, Details: v2.4.4; Id: 11.5eu384.1bbbgsfj7.7uj], total: 0(775) X-BitDefender-CF-Stamp: none Cc: ravi.sahita@intel.com, tamas@tklengyel.com, wei.liu2@citrix.com, Razvan Cojocaru , andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH] common/mem_access: merged mem_access setting interfaces 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 xc_altp2m_set_mem_access() and xc_set_mem_access() end up doing the same thing in the hypervisor, but the former is a HVMOP and the latter a DOMCTL. Since nobody is currently using, or has stated intent to use, this functionality specifically as an HVMOP, this patch removes the HVMOP while adding an extra parameter to the more flexible DOMCTL variant, in which the altp2m view can be transmitted (0 for the default view, or when altp2m is disabled). The xen-access test has been updated in the process. Signed-off-by: Razvan Cojocaru Acked-by: Wei Liu --- tools/libxc/include/xenctrl.h | 10 +++------- tools/libxc/xc_altp2m.c | 25 ------------------------- tools/libxc/xc_mem_access.c | 14 +++++++++----- tools/tests/xen-access/xen-access.c | 25 ++++++++----------------- xen/arch/x86/hvm/hvm.c | 10 ---------- xen/common/mem_access.c | 4 ++-- xen/include/public/domctl.h | 2 +- xen/include/public/hvm/hvm_op.h | 15 +-------------- xen/include/public/memory.h | 2 ++ 9 files changed, 26 insertions(+), 81 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index b80d150..8a00fba 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1923,9 +1923,6 @@ int xc_altp2m_destroy_view(xc_interface *handle, domid_t domid, /* Switch all vCPUs of the domain to the specified altp2m view */ int xc_altp2m_switch_to_view(xc_interface *handle, domid_t domid, uint16_t view_id); -int xc_altp2m_set_mem_access(xc_interface *handle, domid_t domid, - uint16_t view_id, xen_pfn_t gfn, - xenmem_access_t access); int xc_altp2m_change_gfn(xc_interface *handle, domid_t domid, uint16_t view_id, xen_pfn_t old_gfn, xen_pfn_t new_gfn); @@ -1956,9 +1953,8 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id, * Allowed types are XENMEM_access_default, XENMEM_access_n, any combination of * XENMEM_access_ + (rwx), and XENMEM_access_rx2rw */ -int xc_set_mem_access(xc_interface *xch, domid_t domain_id, - xenmem_access_t access, uint64_t first_pfn, - uint32_t nr); +int xc_set_mem_access(xc_interface *xch, domid_t domain_id, uint16_t view_id, + xenmem_access_t access, uint64_t first_pfn, uint32_t nr); /* * Set an array of pages to their respective access in the access array. @@ -1966,7 +1962,7 @@ int xc_set_mem_access(xc_interface *xch, domid_t domain_id, * The same allowed access types as for xc_set_mem_access() apply. */ int xc_set_mem_access_multi(xc_interface *xch, domid_t domain_id, - uint8_t *access, uint64_t *pages, + uint16_t view_id, uint8_t *access, uint64_t *pages, uint32_t nr); /* diff --git a/tools/libxc/xc_altp2m.c b/tools/libxc/xc_altp2m.c index 0639632..4f44a7b 100644 --- a/tools/libxc/xc_altp2m.c +++ b/tools/libxc/xc_altp2m.c @@ -163,31 +163,6 @@ int xc_altp2m_switch_to_view(xc_interface *handle, domid_t domid, return rc; } -int xc_altp2m_set_mem_access(xc_interface *handle, domid_t domid, - uint16_t view_id, xen_pfn_t gfn, - xenmem_access_t access) -{ - int rc; - DECLARE_HYPERCALL_BUFFER(xen_hvm_altp2m_op_t, arg); - - arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg)); - if ( arg == NULL ) - return -1; - - arg->version = HVMOP_ALTP2M_INTERFACE_VERSION; - arg->cmd = HVMOP_altp2m_set_mem_access; - arg->domain = domid; - arg->u.set_mem_access.view = view_id; - arg->u.set_mem_access.hvmmem_access = access; - arg->u.set_mem_access.gfn = gfn; - - rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(handle, arg); - return rc; -} - int xc_altp2m_change_gfn(xc_interface *handle, domid_t domid, uint16_t view_id, xen_pfn_t old_gfn, xen_pfn_t new_gfn) diff --git a/tools/libxc/xc_mem_access.c b/tools/libxc/xc_mem_access.c index 9536635..4242527 100644 --- a/tools/libxc/xc_mem_access.c +++ b/tools/libxc/xc_mem_access.c @@ -25,17 +25,19 @@ int xc_set_mem_access(xc_interface *xch, domid_t domain_id, + uint16_t view_id, xenmem_access_t access, uint64_t first_pfn, uint32_t nr) { xen_mem_access_op_t mao = { - .op = XENMEM_access_op_set_access, - .domid = domain_id, - .access = access, - .pfn = first_pfn, - .nr = nr + .op = XENMEM_access_op_set_access, + .domid = domain_id, + .access = access, + .pfn = first_pfn, + .nr = nr, + .view_id = view_id }; return do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao)); @@ -43,6 +45,7 @@ int xc_set_mem_access(xc_interface *xch, int xc_set_mem_access_multi(xc_interface *xch, domid_t domain_id, + uint16_t view_id, uint8_t *access, uint64_t *pages, uint32_t nr) @@ -59,6 +62,7 @@ int xc_set_mem_access_multi(xc_interface *xch, .access = XENMEM_access_default + 1, /* Invalid value */ .pfn = ~0UL, /* Invalid GFN */ .nr = nr, + .view_id = view_id, }; if ( xc_hypercall_bounce_pre(xch, pages) || diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index 9d4f957..bd348ef 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -475,9 +475,6 @@ int main(int argc, char *argv[]) /* With altp2m we just create a new, restricted view of the memory */ if ( memaccess && altp2m ) { - xen_pfn_t gfn = 0; - unsigned long perm_set = 0; - rc = xc_altp2m_set_domain_state( xch, domain_id, 1 ); if ( rc < 0 ) { @@ -495,15 +492,9 @@ int main(int argc, char *argv[]) DPRINTF("altp2m view created with id %u\n", altp2m_view_id); DPRINTF("Setting altp2m mem_access permissions.. "); - for(; gfn < xenaccess->max_gpfn; ++gfn) - { - rc = xc_altp2m_set_mem_access( xch, domain_id, altp2m_view_id, gfn, - default_access); - if ( !rc ) - perm_set++; - } - - DPRINTF("done! Permissions set on %lu pages.\n", perm_set); + rc = xc_set_mem_access(xch, domain_id, altp2m_view_id, default_access, + 0, xenaccess->max_gpfn); + DPRINTF("done!"); rc = xc_altp2m_switch_to_view( xch, domain_id, altp2m_view_id ); if ( rc < 0 ) @@ -523,14 +514,14 @@ int main(int argc, char *argv[]) if ( memaccess && !altp2m ) { /* Set the default access type and convert all pages to it */ - rc = xc_set_mem_access(xch, domain_id, default_access, ~0ull, 0); + rc = xc_set_mem_access(xch, domain_id, 0, default_access, ~0ull, 0); if ( rc < 0 ) { ERROR("Error %d setting default mem access type\n", rc); goto exit; } - rc = xc_set_mem_access(xch, domain_id, default_access, START_PFN, + rc = xc_set_mem_access(xch, domain_id, 0, default_access, START_PFN, (xenaccess->max_gpfn - START_PFN) ); if ( rc < 0 ) @@ -606,8 +597,8 @@ int main(int argc, char *argv[]) rc = xc_altp2m_set_domain_state(xch, domain_id, 0); rc = xc_monitor_singlestep(xch, domain_id, 0); } else { - rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, ~0ull, 0); - rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, START_PFN, + rc = xc_set_mem_access(xch, domain_id, 0, XENMEM_access_rwx, ~0ull, 0); + rc = xc_set_mem_access(xch, domain_id, 0, XENMEM_access_rwx, START_PFN, (xenaccess->max_gpfn - START_PFN) ); } @@ -685,7 +676,7 @@ int main(int argc, char *argv[]) } else if ( default_access != after_first_access ) { - rc = xc_set_mem_access(xch, domain_id, after_first_access, + rc = xc_set_mem_access(xch, domain_id, 0, after_first_access, req.u.mem_access.gfn, 1); if (rc < 0) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index ccfae4f..fdd8637 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4418,7 +4418,6 @@ static int do_altp2m_op( case HVMOP_altp2m_create_p2m: case HVMOP_altp2m_destroy_p2m: case HVMOP_altp2m_switch_p2m: - case HVMOP_altp2m_set_mem_access: case HVMOP_altp2m_change_gfn: break; default: @@ -4526,15 +4525,6 @@ static int do_altp2m_op( rc = p2m_switch_domain_altp2m_by_id(d, a.u.view.view); break; - case HVMOP_altp2m_set_mem_access: - if ( a.u.set_mem_access.pad ) - rc = -EINVAL; - else - rc = p2m_set_mem_access(d, _gfn(a.u.set_mem_access.gfn), 1, 0, 0, - a.u.set_mem_access.hvmmem_access, - a.u.set_mem_access.view); - break; - case HVMOP_altp2m_change_gfn: if ( a.u.change_gfn.pad1 || a.u.change_gfn.pad2 ) rc = -EINVAL; diff --git a/xen/common/mem_access.c b/xen/common/mem_access.c index 19f63bb..35afb1c 100644 --- a/xen/common/mem_access.c +++ b/xen/common/mem_access.c @@ -67,7 +67,7 @@ int mem_access_memop(unsigned long cmd, break; rc = p2m_set_mem_access(d, _gfn(mao.pfn), mao.nr, start_iter, - MEMOP_CMD_MASK, mao.access, 0); + MEMOP_CMD_MASK, mao.access, mao.view_id); if ( rc > 0 ) { ASSERT(!(rc & MEMOP_CMD_MASK)); @@ -78,7 +78,7 @@ int mem_access_memop(unsigned long cmd, case XENMEM_access_op_set_access_multi: rc = p2m_set_mem_access_multi(d, mao.pfn_list, mao.access_list, mao.nr, - start_iter, MEMOP_CMD_MASK, 0); + start_iter, MEMOP_CMD_MASK, mao.view_id); if ( rc > 0 ) { ASSERT(!(rc & MEMOP_CMD_MASK)); diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 85cbb7c..2842589 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -37,7 +37,7 @@ #include "hvm/save.h" #include "memory.h" -#define XEN_DOMCTL_INTERFACE_VERSION 0x0000000c +#define XEN_DOMCTL_INTERFACE_VERSION 0x0000000d /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index bc00ef0..cf6f24f 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -219,18 +219,6 @@ struct xen_hvm_altp2m_view { typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t; DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_view_t); -struct xen_hvm_altp2m_set_mem_access { - /* view */ - uint16_t view; - /* Memory type */ - uint16_t hvmmem_access; /* xenmem_access_t */ - uint32_t pad; - /* gfn */ - uint64_t gfn; -}; -typedef struct xen_hvm_altp2m_set_mem_access xen_hvm_altp2m_set_mem_access_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_set_mem_access_t); - struct xen_hvm_altp2m_change_gfn { /* view */ uint16_t view; @@ -258,7 +246,7 @@ struct xen_hvm_altp2m_op { #define HVMOP_altp2m_destroy_p2m 5 /* Switch view for an entire domain */ #define HVMOP_altp2m_switch_p2m 6 -/* Notify that a page of memory is to have specific access types */ +/* Deprecated by XENMEM_access_op_set_access */ #define HVMOP_altp2m_set_mem_access 7 /* Change a p2m entry to have a different gfn->mfn mapping */ #define HVMOP_altp2m_change_gfn 8 @@ -269,7 +257,6 @@ struct xen_hvm_altp2m_op { struct xen_hvm_altp2m_domain_state domain_state; struct xen_hvm_altp2m_vcpu_enable_notify enable_notify; struct xen_hvm_altp2m_view view; - struct xen_hvm_altp2m_set_mem_access set_mem_access; struct xen_hvm_altp2m_change_gfn change_gfn; uint8_t pad[64]; } u; diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 6eee0c8..ca53a0c 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -444,6 +444,8 @@ struct xen_mem_access_op { /* xenmem_access_t */ uint8_t access; domid_t domid; + uint16_t view_id; + uint16_t pad; /* * Number of pages for set op (or size of pfn_list for * XENMEM_access_op_set_access_multi)