diff mbox

vm_event: Fix regression caused by b701ccc8

Message ID 1454707216-13471-1-git-send-email-tlengyel@novetta.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tamas K Lengyel Feb. 5, 2016, 9:20 p.m. UTC
When xc_map_foreign_batch got deprecated reinitializing vm_event on a domain
where an event listener was previously active broke as it relied on the flag
XEN_DOMCTL_PFINFO_XTAB to indicate that the magic page is not in the physmap.
Manually check the gpfn type, add it to the physmap if needed, and only then
try to map it.

Signed-off-by: Tamas K Lengyel <tlengyel@novetta.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libxc/xc_vm_event.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Comments

Ian Campbell Feb. 8, 2016, 9:39 a.m. UTC | #1
On Fri, 2016-02-05 at 14:20 -0700, Tamas K Lengyel wrote:
> When xc_map_foreign_batch got deprecated reinitializing vm_event on a domain
> where an event listener was previously active broke as it relied on the flag
> XEN_DOMCTL_PFINFO_XTAB to indicate that the magic page is not in the physmap.
> Manually check the gpfn type, add it to the physmap if needed, and only then
> try to map it.
> 
> Signed-off-by: Tamas K Lengyel <tlengyel@novetta.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>

Sorry for the breakage!

Acked-by: Ian Campbell <ian.campbell@citrix.com>

> ---
>  tools/libxc/xc_vm_event.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/libxc/xc_vm_event.c b/tools/libxc/xc_vm_event.c
> index 57abce0..443c73b 100644
> --- a/tools/libxc/xc_vm_event.c
> +++ b/tools/libxc/xc_vm_event.c
> @@ -72,11 +72,10 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t
> domain_id, int param,
>  
>      ring_pfn = pfn;
>      mmap_pfn = pfn;
> -    ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ |
> PROT_WRITE,
> -                                     &mmap_pfn, 1);
> -    if ( !ring_page )
> +    rc1 = xc_get_pfn_type_batch(xch, domain_id, 1, &mmap_pfn);
> +    if ( rc1 || mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
>      {
> -        /* Map failed, populate ring page */
> +        /* Page not in the physmap, try to populate it */
>          rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
>                                                &ring_pfn);
>          if ( rc1 != 0 )
> @@ -84,15 +83,15 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t
> domain_id, int param,
>              PERROR("Failed to populate ring pfn\n");
>              goto out;
>          }
> +    }
>  
> -        mmap_pfn = ring_pfn;
> -        ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ |
> PROT_WRITE,
> +    mmap_pfn = ring_pfn;
> +    ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ |
> PROT_WRITE,
>                                           &mmap_pfn, 1);
> -        if ( !ring_page )
> -        {
> -            PERROR("Could not map the ring page\n");
> -            goto out;
> -        }
> +    if ( !ring_page )
> +    {
> +        PERROR("Could not map the ring page\n");
> +        goto out;
>      }
>  
>      switch ( param )
Ian Campbell Feb. 8, 2016, 3:46 p.m. UTC | #2
On Mon, 2016-02-08 at 09:39 +0000, Ian Campbell wrote:
> On Fri, 2016-02-05 at 14:20 -0700, Tamas K Lengyel wrote:
> > When xc_map_foreign_batch got deprecated reinitializing vm_event on a
> > domain
> > where an event listener was previously active broke as it relied on the
> > flag
> > XEN_DOMCTL_PFINFO_XTAB to indicate that the magic page is not in the
> > physmap.
> > Manually check the gpfn type, add it to the physmap if needed, and only
> > then
> > try to map it.
> > 
> > Signed-off-by: Tamas K Lengyel <tlengyel@novetta.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> 
> Sorry for the breakage!
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

+ applied now.
diff mbox

Patch

diff --git a/tools/libxc/xc_vm_event.c b/tools/libxc/xc_vm_event.c
index 57abce0..443c73b 100644
--- a/tools/libxc/xc_vm_event.c
+++ b/tools/libxc/xc_vm_event.c
@@ -72,11 +72,10 @@  void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
 
     ring_pfn = pfn;
     mmap_pfn = pfn;
-    ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ | PROT_WRITE,
-                                     &mmap_pfn, 1);
-    if ( !ring_page )
+    rc1 = xc_get_pfn_type_batch(xch, domain_id, 1, &mmap_pfn);
+    if ( rc1 || mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
     {
-        /* Map failed, populate ring page */
+        /* Page not in the physmap, try to populate it */
         rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
                                               &ring_pfn);
         if ( rc1 != 0 )
@@ -84,15 +83,15 @@  void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
             PERROR("Failed to populate ring pfn\n");
             goto out;
         }
+    }
 
-        mmap_pfn = ring_pfn;
-        ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ | PROT_WRITE,
+    mmap_pfn = ring_pfn;
+    ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ | PROT_WRITE,
                                          &mmap_pfn, 1);
-        if ( !ring_page )
-        {
-            PERROR("Could not map the ring page\n");
-            goto out;
-        }
+    if ( !ring_page )
+    {
+        PERROR("Could not map the ring page\n");
+        goto out;
     }
 
     switch ( param )