From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aravindh Puthiyaparambil Subject: [PATCH RFC 4/4] tool/xen-access: Add support for PV domains Date: Mon, 28 Apr 2014 21:45:05 -0700 Message-ID: <1398746705-6658-5-git-send-email-aravindp@cisco.com> References: <1398746705-6658-1-git-send-email-aravindp@cisco.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wezv0-0004Nr-V6 for xen-devel@lists.xenproject.org; Tue, 29 Apr 2014 04:45:23 +0000 In-Reply-To: <1398746705-6658-1-git-send-email-aravindp@cisco.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Ian Jackson , Ian Campbell , Aravindh Puthiyaprambil List-Id: xen-devel@lists.xenproject.org Add support to the xen-access test program for it work with PV domains. The main difference is that for PV domains, unlike HVM domains, xc_mem_access_create_ring_page() has to be called as the page is not created during domain creation time. PV domains do not need to set all individual page access permissions during setup and teardown. Enabling and disabling mem_access does that indirectly. Signed-off-by: Aravindh Puthiyaprambil Cc: Ian Jackson Cc: Stefano Stabellini Cc: Ian Campbell --- tools/tests/xen-access/xen-access.c | 122 ++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 41 deletions(-) diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index 0a84bd5..f9883f4 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -114,7 +114,8 @@ typedef struct xenaccess { } xenaccess_t; static int interrupted; -bool evtchn_bind = 0, evtchn_open = 0, mem_access_enable = 0; +bool evtchn_bind = 0, evtchn_open = 0, mem_access_enable = 0, pv_ring_page = 0; +bool hvm = 0; static void close_handler(int sig) { @@ -173,7 +174,7 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess) if ( xenaccess->mem_event.ring_page ) munmap(xenaccess->mem_event.ring_page, XC_PAGE_SIZE); - if ( mem_access_enable ) + if ( mem_access_enable || (!hvm && pv_ring_page) ) { rc = xc_mem_access_disable(xenaccess->xc_handle, xenaccess->mem_event.domain_id); @@ -245,9 +246,57 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id) /* Initialise lock */ mem_event_ring_lock_init(&xenaccess->mem_event); + /* Get domaininfo */ + xenaccess->domain_info = malloc(sizeof(xc_domaininfo_t)); + if ( xenaccess->domain_info == NULL ) + { + ERROR("Error allocating memory for domain info"); + goto err; + } + + rc = xc_domain_getinfolist(xenaccess->xc_handle, domain_id, 1, + xenaccess->domain_info); + if ( rc != 1 ) + { + ERROR("Error getting domain info"); + goto err; + } + + if ( xenaccess->domain_info->flags & XEN_DOMINF_hvm_guest ) + hvm = 1; + + DPRINTF("max_pages = %"PRIx64"\n", xenaccess->domain_info->max_pages); + + if ( hvm ) + { + rc = xc_get_hvm_param(xch, xenaccess->mem_event.domain_id, + HVM_PARAM_ACCESS_RING_PFN, &ring_pfn); + + } + else + { + rc = xc_mem_access_create_ring_page(xch, xenaccess->mem_event.domain_id); + if ( rc != 0 ) + { + PERROR("Failed to set ring gfn\n"); + goto err; + } + + pv_ring_page = 1; + + rc = xc_mem_access_get_ring_mfn(xch, xenaccess->mem_event.domain_id, + &ring_pfn); + } + + if ( rc != 0 ) + { + PERROR("Failed to get ring gfn\n"); + goto err; + } + + DPRINTF("ring_mfn: 0x%lx\n", ring_pfn); + /* Map the ring page */ - xc_get_hvm_param(xch, xenaccess->mem_event.domain_id, - HVM_PARAM_ACCESS_RING_PFN, &ring_pfn); mmap_pfn = ring_pfn; xenaccess->mem_event.ring_page = xc_map_foreign_batch(xch, xenaccess->mem_event.domain_id, @@ -327,24 +376,6 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id) xenaccess->mem_event.domain_id, 1, 0, &ring_pfn) ) PERROR("Failed to remove ring from guest physmap"); - /* Get domaininfo */ - xenaccess->domain_info = malloc(sizeof(xc_domaininfo_t)); - if ( xenaccess->domain_info == NULL ) - { - ERROR("Error allocating memory for domain info"); - goto err; - } - - rc = xc_domain_getinfolist(xenaccess->xc_handle, domain_id, 1, - xenaccess->domain_info); - if ( rc != 1 ) - { - ERROR("Error getting domain info"); - goto err; - } - - DPRINTF("max_pages = %"PRIx64"\n", xenaccess->domain_info->max_pages); - return xenaccess; err: @@ -526,23 +557,28 @@ int main(int argc, char *argv[]) goto exit; } - rc = xc_set_mem_access(xch, domain_id, default_access, 0, - xenaccess->domain_info->max_pages); - if ( rc < 0 ) + if ( hvm ) { - ERROR("Error %d setting all memory to access type %d\n", rc, - default_access); - goto exit; - } + rc = xc_set_mem_access(xch, domain_id, default_access, 0, + xenaccess->domain_info->max_pages); + if ( rc < 0 ) + { + ERROR("Error %d setting all memory to access type %d\n", rc, + default_access); + goto exit; + } - if ( int3 ) - rc = xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, HVMPME_mode_sync); - else - rc = xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, HVMPME_mode_disabled); - if ( rc < 0 ) - { - ERROR("Error %d setting int3 mem_event\n", rc); - goto exit; + if ( int3 ) + rc = xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, + HVMPME_mode_sync); + else + rc = xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, + HVMPME_mode_disabled); + if ( rc < 0 ) + { + ERROR("Error %d setting int3 mem_event\n", rc); + goto exit; + } } /* Wait for access */ @@ -554,10 +590,14 @@ int main(int argc, char *argv[]) /* Unregister for every event */ rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, ~0ull, 0); - rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, 0, - xenaccess->domain_info->max_pages); - rc = xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, HVMPME_mode_disabled); - + if ( hvm ) + { + rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, 0, + xenaccess->domain_info->max_pages); + rc = xc_set_hvm_param(xch, domain_id, + HVM_PARAM_MEMORY_EVENT_INT3, + HVMPME_mode_disabled); + } shutting_down = 1; } -- 1.9.1