From patchwork Fri Jun 24 10:31:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9197275 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 4650E6077D for ; Fri, 24 Jun 2016 10:33:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33E2E27F85 for ; Fri, 24 Jun 2016 10:33:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28935284AB; Fri, 24 Jun 2016 10:33:47 +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 14B3727F85 for ; Fri, 24 Jun 2016 10:33:46 +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 1bGOOr-0003wY-EU; Fri, 24 Jun 2016 10:31:49 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGOOq-0003w1-IR for xen-devel@lists.xenproject.org; Fri, 24 Jun 2016 10:31:48 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 9F/40-09129-31C0D675; Fri, 24 Jun 2016 10:31:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRWlGSWpSXmKPExsXS6fjDS1eIJzf c4NtdC4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNeP5l3nsBZsmMla8WTKDqYHxUm4XIyeHkECe xIqlGxhBbF4BO4mnsycxgdgSAoYS++avYgOxWQRUJdbf3gpWwyagLtH2bDtrFyMHh4iAgcS5o 0kgYWaBSUwSW65pgtjCAvYSPy90skCMt5NY9H09G0g5J1B8/2txEJNXQFDi7w5hiE47iXmrXr BNYOSZhZCZhSQDYWtJPPx1iwXC1pZYtvA1M0g5s4C0xPJ/HBBhA4mnPW8ZUZWA2NYSn46+YVz AyLGKUaM4tagstUjXyFgvqSgzPaMkNzEzR9fQwFQvN7W4ODE9NScxqVgvOT93EyMwWOsZGBh3 MO5o9zvEKMnBpCTKO21RTrgQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd5HXLnhQoJFqempFWmZO cC4gUlLcPAoifAeB0nzFhck5hZnpkOkTjHqchybe2MtkxBLXn5eqpQ470SQIgGQoozSPLgRsB i+xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUUmYt4EbaApPZl4J3KZXQEcwAR1xtz8b5IiSRIS UVANj2hyRM87/u0oUuzO6XFZ1ZK7imabwede1a84vrJmFbGMfdvudWlXpNuv5N5Gag6VNIt83 R7mtUWDo+nz1i2UBa2LxR+WS+pYfxzsSQs5aJzxq2f106ikubpnUPZqRObuv3jC3DTwy7aTOT O2gu6dD9j9T2PIp2HxZStNso9Iy7cDfk5WsJ19SYinOSDTUYi4qTgQAbnJKZtwCAAA= X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1466764304!34564311!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21884 invoked from network); 24 Jun 2016 10:31:46 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Jun 2016 10:31:46 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 24 Jun 2016 04:31:44 -0600 Message-Id: <576D282F02000078000F8700@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 24 Jun 2016 04:31:43 -0600 From: "Jan Beulich" To: "xen-devel" References: <576D25DA02000078000F86C2@prv-mh.provo.novell.com> In-Reply-To: <576D25DA02000078000F86C2@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , dgdegra@tycho.nsa.gov Subject: [Xen-devel] [PATCH v2 06/11] hvmctl: convert HVMOP_modified_memory 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Also limiting "nr" at the libxc level to 32 bits (the high 32 bits of the previous 64-bit parameter got ignore so far). Signed-off-by: Jan Beulich Reviewed-by: Wei Liu Reviewed-by: Andrew Cooper hvmctl: convert HVMOP_modified_memory Also limiting "nr" at the libxc level to 32 bits (the high 32 bits of the previous 64-bit parameter got ignore so far). Signed-off-by: Jan Beulich Reviewed-by: Wei Liu Reviewed-by: Andrew Cooper --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1620,7 +1620,7 @@ int xc_hvm_track_dirty_vram( * Notify that some pages got modified by the Device Model */ int xc_hvm_modified_memory( - xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr); + xc_interface *xch, domid_t dom, uint64_t first_gfn, uint32_t nr); /* * Set a range of memory to a specific type. --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -558,29 +558,13 @@ int xc_hvm_track_dirty_vram( } int xc_hvm_modified_memory( - xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr) + xc_interface *xch, domid_t dom, uint64_t first_gfn, uint32_t nr) { - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_modified_memory, arg); - int rc; + DECLARE_HVMCTL(modified_memory, dom, + .first_gfn = first_gfn, + .nr = nr); - arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg == NULL ) - { - PERROR("Could not allocate memory for xc_hvm_modified_memory hypercall"); - return -1; - } - - arg->domid = dom; - arg->first_pfn = first_pfn; - arg->nr = nr; - - rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_modified_memory, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - - return rc; + return do_hvmctl(xch, &hvmctl); } int xc_hvm_set_mem_type( --- a/xen/arch/x86/hvm/control.c +++ b/xen/arch/x86/hvm/control.c @@ -14,6 +14,7 @@ * this program; If not, see . */ +#include #include #include #include @@ -90,6 +91,51 @@ static int track_dirty_vram(struct domai : hap_track_dirty_vram(d, op->first_gfn, op->nr, op->dirty_bitmap); } +static int modified_memory(struct domain *d, + const struct xen_hvm_modified_memory *op, + uint64_t *iter) +{ + if ( !is_hvm_domain(d) ) + return -EINVAL; + + if ( op->rsvd || op->nr < *iter || + ((op->first_gfn + op->nr - 1) < op->first_gfn) || + ((op->first_gfn + op->nr - 1) > domain_get_maximum_gpfn(d)) ) + return -EINVAL; + + if ( !paging_mode_log_dirty(d) ) + return 0; + + while ( op->nr > *iter ) + { + unsigned long gfn = op->first_gfn + *iter; + struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE); + + if ( page ) + { + unsigned long mfn = page_to_mfn(page); + + paging_mark_dirty(d, mfn); + /* + * These are most probably not page tables any more: + * Don't take a long time, and don't die either. + */ + sh_remove_shadows(d, _mfn(mfn), 1, 0); + put_page(page); + } + + /* + * Check for continuation every once in a while, and if it's not the + * last interation. + */ + if ( op->nr > ++*iter && !(*iter & 0xff) && + hypercall_preempt_check() ) + return -ERESTART; + } + + return 0; +} + long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xen_hvmctl_t) u_hvmctl) { xen_hvmctl_t op; @@ -140,6 +186,10 @@ long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xe rc = track_dirty_vram(d, &op.u.track_dirty_vram); break; + case XEN_HVMCTL_modified_memory: + rc = modified_memory(d, &op.u.modified_memory, &op.opaque); + break; + default: rc = -EOPNOTSUPP; break; --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5233,7 +5233,6 @@ long do_hvm_op(unsigned long op, XEN_GUE default: mask = ~0UL; break; - case HVMOP_modified_memory: case HVMOP_set_mem_type: mask = HVMOP_op_mask; break; @@ -5296,65 +5295,6 @@ long do_hvm_op(unsigned long op, XEN_GUE rc = guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -ENOSYS; break; - case HVMOP_modified_memory: - { - struct xen_hvm_modified_memory a; - struct domain *d; - - if ( copy_from_guest(&a, arg, 1) ) - return -EFAULT; - - rc = rcu_lock_remote_domain_by_id(a.domid, &d); - if ( rc != 0 ) - return rc; - - rc = -EINVAL; - if ( !is_hvm_domain(d) ) - goto modmem_fail; - - rc = xsm_hvm_control(XSM_DM_PRIV, d, op); - if ( rc ) - goto modmem_fail; - - rc = -EINVAL; - if ( a.nr < start_iter || - ((a.first_pfn + a.nr - 1) < a.first_pfn) || - ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) ) - goto modmem_fail; - - rc = 0; - if ( !paging_mode_log_dirty(d) ) - goto modmem_fail; - - while ( a.nr > start_iter ) - { - unsigned long pfn = a.first_pfn + start_iter; - struct page_info *page; - - page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE); - if ( page ) - { - paging_mark_dirty(d, page_to_mfn(page)); - /* These are most probably not page tables any more */ - /* don't take a long time and don't die either */ - sh_remove_shadows(d, _mfn(page_to_mfn(page)), 1, 0); - put_page(page); - } - - /* Check for continuation if it's not the last interation */ - if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) && - hypercall_preempt_check() ) - { - rc = -ERESTART; - break; - } - } - - modmem_fail: - rcu_unlock_domain(d); - break; - } - case HVMOP_get_mem_type: { struct xen_hvm_get_mem_type a; --- a/xen/include/public/hvm/control.h +++ b/xen/include/public/hvm/control.h @@ -67,6 +67,16 @@ struct xen_hvm_track_dirty_vram { XEN_GUEST_HANDLE_64(uint8) dirty_bitmap; }; +/* XEN_HVMCTL_modified_memory */ +/* Notify that some pages got modified by the Device Model. */ +struct xen_hvm_modified_memory { + /* Number of pages. */ + uint32_t nr; + uint32_t rsvd; + /* First GFN. */ + uint64_aligned_t first_gfn; +}; + struct xen_hvmctl { uint16_t interface_version; /* XEN_HVMCTL_INTERFACE_VERSION */ domid_t domain; @@ -75,12 +85,14 @@ struct xen_hvmctl { #define XEN_HVMCTL_set_isa_irq_level 2 #define XEN_HVMCTL_set_pci_link_route 3 #define XEN_HVMCTL_track_dirty_vram 4 +#define XEN_HVMCTL_modified_memory 5 uint64_t opaque; /* Must be zero on initial invocation. */ union { struct xen_hvm_set_pci_intx_level set_pci_intx_level; struct xen_hvm_set_isa_irq_level set_isa_irq_level; struct xen_hvm_set_pci_link_route set_pci_link_route; struct xen_hvm_track_dirty_vram track_dirty_vram; + struct xen_hvm_modified_memory modified_memory; uint8_t pad[120]; } u; }; --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -98,19 +98,6 @@ typedef enum { /* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) -/* Notify that some pages got modified by the Device Model. */ -#define HVMOP_modified_memory 7 -struct xen_hvm_modified_memory { - /* Domain to be updated. */ - domid_t domid; - /* Number of pages. */ - uint32_t nr; - /* First pfn. */ - uint64_aligned_t first_pfn; -}; -typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t); - #define HVMOP_set_mem_type 8 /* Notify that a region of memory is to be treated in a specific way. */ struct xen_hvm_set_mem_type { --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -272,7 +272,7 @@ class hvm cacheattr # XEN_HVMCTL_track_dirty_vram trackdirtyvram -# HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, +# XEN_HVMCTL_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, # HVMOP_inject_trap hvmctl Acked-by: Daniel De Graaf --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1620,7 +1620,7 @@ int xc_hvm_track_dirty_vram( * Notify that some pages got modified by the Device Model */ int xc_hvm_modified_memory( - xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr); + xc_interface *xch, domid_t dom, uint64_t first_gfn, uint32_t nr); /* * Set a range of memory to a specific type. --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -558,29 +558,13 @@ int xc_hvm_track_dirty_vram( } int xc_hvm_modified_memory( - xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr) + xc_interface *xch, domid_t dom, uint64_t first_gfn, uint32_t nr) { - DECLARE_HYPERCALL_BUFFER(struct xen_hvm_modified_memory, arg); - int rc; + DECLARE_HVMCTL(modified_memory, dom, + .first_gfn = first_gfn, + .nr = nr); - arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg == NULL ) - { - PERROR("Could not allocate memory for xc_hvm_modified_memory hypercall"); - return -1; - } - - arg->domid = dom; - arg->first_pfn = first_pfn; - arg->nr = nr; - - rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_modified_memory, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - - return rc; + return do_hvmctl(xch, &hvmctl); } int xc_hvm_set_mem_type( --- a/xen/arch/x86/hvm/control.c +++ b/xen/arch/x86/hvm/control.c @@ -14,6 +14,7 @@ * this program; If not, see . */ +#include #include #include #include @@ -90,6 +91,51 @@ static int track_dirty_vram(struct domai : hap_track_dirty_vram(d, op->first_gfn, op->nr, op->dirty_bitmap); } +static int modified_memory(struct domain *d, + const struct xen_hvm_modified_memory *op, + uint64_t *iter) +{ + if ( !is_hvm_domain(d) ) + return -EINVAL; + + if ( op->rsvd || op->nr < *iter || + ((op->first_gfn + op->nr - 1) < op->first_gfn) || + ((op->first_gfn + op->nr - 1) > domain_get_maximum_gpfn(d)) ) + return -EINVAL; + + if ( !paging_mode_log_dirty(d) ) + return 0; + + while ( op->nr > *iter ) + { + unsigned long gfn = op->first_gfn + *iter; + struct page_info *page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE); + + if ( page ) + { + unsigned long mfn = page_to_mfn(page); + + paging_mark_dirty(d, mfn); + /* + * These are most probably not page tables any more: + * Don't take a long time, and don't die either. + */ + sh_remove_shadows(d, _mfn(mfn), 1, 0); + put_page(page); + } + + /* + * Check for continuation every once in a while, and if it's not the + * last interation. + */ + if ( op->nr > ++*iter && !(*iter & 0xff) && + hypercall_preempt_check() ) + return -ERESTART; + } + + return 0; +} + long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xen_hvmctl_t) u_hvmctl) { xen_hvmctl_t op; @@ -140,6 +186,10 @@ long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xe rc = track_dirty_vram(d, &op.u.track_dirty_vram); break; + case XEN_HVMCTL_modified_memory: + rc = modified_memory(d, &op.u.modified_memory, &op.opaque); + break; + default: rc = -EOPNOTSUPP; break; --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5233,7 +5233,6 @@ long do_hvm_op(unsigned long op, XEN_GUE default: mask = ~0UL; break; - case HVMOP_modified_memory: case HVMOP_set_mem_type: mask = HVMOP_op_mask; break; @@ -5296,65 +5295,6 @@ long do_hvm_op(unsigned long op, XEN_GUE rc = guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -ENOSYS; break; - case HVMOP_modified_memory: - { - struct xen_hvm_modified_memory a; - struct domain *d; - - if ( copy_from_guest(&a, arg, 1) ) - return -EFAULT; - - rc = rcu_lock_remote_domain_by_id(a.domid, &d); - if ( rc != 0 ) - return rc; - - rc = -EINVAL; - if ( !is_hvm_domain(d) ) - goto modmem_fail; - - rc = xsm_hvm_control(XSM_DM_PRIV, d, op); - if ( rc ) - goto modmem_fail; - - rc = -EINVAL; - if ( a.nr < start_iter || - ((a.first_pfn + a.nr - 1) < a.first_pfn) || - ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) ) - goto modmem_fail; - - rc = 0; - if ( !paging_mode_log_dirty(d) ) - goto modmem_fail; - - while ( a.nr > start_iter ) - { - unsigned long pfn = a.first_pfn + start_iter; - struct page_info *page; - - page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE); - if ( page ) - { - paging_mark_dirty(d, page_to_mfn(page)); - /* These are most probably not page tables any more */ - /* don't take a long time and don't die either */ - sh_remove_shadows(d, _mfn(page_to_mfn(page)), 1, 0); - put_page(page); - } - - /* Check for continuation if it's not the last interation */ - if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) && - hypercall_preempt_check() ) - { - rc = -ERESTART; - break; - } - } - - modmem_fail: - rcu_unlock_domain(d); - break; - } - case HVMOP_get_mem_type: { struct xen_hvm_get_mem_type a; --- a/xen/include/public/hvm/control.h +++ b/xen/include/public/hvm/control.h @@ -67,6 +67,16 @@ struct xen_hvm_track_dirty_vram { XEN_GUEST_HANDLE_64(uint8) dirty_bitmap; }; +/* XEN_HVMCTL_modified_memory */ +/* Notify that some pages got modified by the Device Model. */ +struct xen_hvm_modified_memory { + /* Number of pages. */ + uint32_t nr; + uint32_t rsvd; + /* First GFN. */ + uint64_aligned_t first_gfn; +}; + struct xen_hvmctl { uint16_t interface_version; /* XEN_HVMCTL_INTERFACE_VERSION */ domid_t domain; @@ -75,12 +85,14 @@ struct xen_hvmctl { #define XEN_HVMCTL_set_isa_irq_level 2 #define XEN_HVMCTL_set_pci_link_route 3 #define XEN_HVMCTL_track_dirty_vram 4 +#define XEN_HVMCTL_modified_memory 5 uint64_t opaque; /* Must be zero on initial invocation. */ union { struct xen_hvm_set_pci_intx_level set_pci_intx_level; struct xen_hvm_set_isa_irq_level set_isa_irq_level; struct xen_hvm_set_pci_link_route set_pci_link_route; struct xen_hvm_track_dirty_vram track_dirty_vram; + struct xen_hvm_modified_memory modified_memory; uint8_t pad[120]; } u; }; --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -98,19 +98,6 @@ typedef enum { /* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__) -/* Notify that some pages got modified by the Device Model. */ -#define HVMOP_modified_memory 7 -struct xen_hvm_modified_memory { - /* Domain to be updated. */ - domid_t domid; - /* Number of pages. */ - uint32_t nr; - /* First pfn. */ - uint64_aligned_t first_pfn; -}; -typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t); - #define HVMOP_set_mem_type 8 /* Notify that a region of memory is to be treated in a specific way. */ struct xen_hvm_set_mem_type { --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -272,7 +272,7 @@ class hvm cacheattr # XEN_HVMCTL_track_dirty_vram trackdirtyvram -# HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, +# XEN_HVMCTL_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type, # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying, # HVMOP_inject_trap hvmctl