Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Oct 2015 14:09:07 +0000 (UTC)
From:      =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= <royger@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r398918 - in head: emulators/xen-kernel emulators/xen-kernel/files sysutils/xen-tools sysutils/xen-tools/files
Message-ID:  <201510091409.t99E97ca079157@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: royger (src committer)
Date: Fri Oct  9 14:09:07 2015
New Revision: 398918
URL: https://svnweb.freebsd.org/changeset/ports/398918

Log:
  xen: update to 4.5.1
  
  Update xen-kernel to 4.5.1 and add patches to allow live migration, save and
  restore. Remove qemu-traditional patches (FreeBSD doesn't support
  qemu-traditional) and add XSA-142.
  
  Approved by:		bapt
  Differential revision:	https://reviews.freebsd.org/D3854
  Sponsored by:		Citrix Systems R&D

Added:
  head/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0002-vmap-avoid-hitting-an-ASSERT-with-vfree-NULL.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0003-x86-shadow-fix-shadow_track_dirty_vram-to-work-on-hv.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0004-x86-hap-make-hap_track_dirty_vram-use-non-contiguous.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0005-x86-rework-paging_log_dirty_op-to-work-with-hvm-gues.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0006-xen-pvh-enable-mmu_update-hypercall.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0007-iommu-fix-usage-of-shared-EPT-IOMMU-page-tables-on-P.patch   (contents, props changed)
  head/emulators/xen-kernel/files/0008-xen-arm-mm-Do-not-dump-the-p2m-when-mapping-a-foreig.patch   (contents, props changed)
  head/sysutils/xen-tools/files/xsa142-4.5.patch   (contents, props changed)
Deleted:
  head/emulators/xen-kernel/files/0001-libelf-fix-elf_parse_bsdsyms-call.patch
  head/emulators/xen-kernel/files/0001-x86-pvh-disable-posted-interrupts.patch
  head/emulators/xen-kernel/files/iommu_share_p2m_table.patch
  head/emulators/xen-kernel/files/xsa117.patch
  head/emulators/xen-kernel/files/xsa118-4.5-unstable-1.patch
  head/emulators/xen-kernel/files/xsa118-4.5-unstable-2.patch
  head/emulators/xen-kernel/files/xsa121.patch
  head/emulators/xen-kernel/files/xsa122.patch
  head/emulators/xen-kernel/files/xsa123.patch
  head/emulators/xen-kernel/files/xsa125.patch
  head/emulators/xen-kernel/files/xsa127-4.x.patch
  head/emulators/xen-kernel/files/xsa132.patch
  head/emulators/xen-kernel/files/xsa134.patch
  head/emulators/xen-kernel/files/xsa136.patch
  head/sysutils/xen-tools/files/xsa135-qemut-1.patch
  head/sysutils/xen-tools/files/xsa135-qemut-2.patch
  head/sysutils/xen-tools/files/xsa138-qemut-1.patch
  head/sysutils/xen-tools/files/xsa138-qemut-2.patch
Modified:
  head/emulators/xen-kernel/Makefile
  head/emulators/xen-kernel/distinfo
  head/sysutils/xen-tools/Makefile

Modified: head/emulators/xen-kernel/Makefile
==============================================================================
--- head/emulators/xen-kernel/Makefile	Fri Oct  9 13:39:22 2015	(r398917)
+++ head/emulators/xen-kernel/Makefile	Fri Oct  9 14:09:07 2015	(r398918)
@@ -2,8 +2,7 @@
 
 PORTNAME=	xen
 PKGNAMESUFFIX=	-kernel
-PORTVERSION=	4.5.0
-PORTREVISION=	5
+PORTVERSION=	4.5.1
 CATEGORIES=	emulators
 MASTER_SITES=	http://bits.xensource.com/oss-xen/release/${PORTVERSION}/
 
@@ -24,20 +23,14 @@ PLIST_FILES=	/boot/xen \
 ALL_TARGET=	build
 STRIP=		#
 WRKSRC_SUBDIR=	xen
-EXTRA_PATCHES=	${FILESDIR}/iommu_share_p2m_table.patch:-p2 \
-		${FILESDIR}/0001-x86-pvh-disable-posted-interrupts.patch:-p2 \
-		${FILESDIR}/xsa117.patch:-p2 \
-		${FILESDIR}/xsa118-4.5-unstable-1.patch:-p2 \
-		${FILESDIR}/xsa118-4.5-unstable-2.patch:-p2 \
-		${FILESDIR}/xsa121.patch:-p2 \
-		${FILESDIR}/xsa122.patch:-p2 \
-		${FILESDIR}/xsa123.patch:-p2 \
-		${FILESDIR}/xsa125.patch:-p2 \
-		${FILESDIR}/xsa127-4.x.patch:-p2 \
-		${FILESDIR}/xsa132.patch:-p2 \
-		${FILESDIR}/xsa134.patch:-p2 \
-		${FILESDIR}/xsa136.patch:-p2 \
-		${FILESDIR}/0001-libelf-fix-elf_parse_bsdsyms-call.patch:-p2
+EXTRA_PATCHES=	${FILESDIR}/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch:-p2 \
+		${FILESDIR}/0002-vmap-avoid-hitting-an-ASSERT-with-vfree-NULL.patch:-p2 \
+		${FILESDIR}/0003-x86-shadow-fix-shadow_track_dirty_vram-to-work-on-hv.patch:-p2 \
+		${FILESDIR}/0004-x86-hap-make-hap_track_dirty_vram-use-non-contiguous.patch:-p2 \
+		${FILESDIR}/0005-x86-rework-paging_log_dirty_op-to-work-with-hvm-gues.patch:-p2 \
+		${FILESDIR}/0006-xen-pvh-enable-mmu_update-hypercall.patch:-p2 \
+		${FILESDIR}/0007-iommu-fix-usage-of-shared-EPT-IOMMU-page-tables-on-P.patch:-p2 \
+		${FILESDIR}/0008-xen-arm-mm-Do-not-dump-the-p2m-when-mapping-a-foreig.patch:-p2
 
 .include <bsd.port.options.mk>
 

Modified: head/emulators/xen-kernel/distinfo
==============================================================================
--- head/emulators/xen-kernel/distinfo	Fri Oct  9 13:39:22 2015	(r398917)
+++ head/emulators/xen-kernel/distinfo	Fri Oct  9 14:09:07 2015	(r398918)
@@ -1,2 +1,2 @@
-SHA256 (xen-4.5.0.tar.gz) = 5bdb40e2b28d2eeb541bd71a9777f40cbe2ae444b987521d33f099541a006f3b
-SIZE (xen-4.5.0.tar.gz) = 18404933
+SHA256 (xen-4.5.1.tar.gz) = 668c11d4fca67ac44329e369f810356eacd37b28d28fb96e66aac77f3c5e1371
+SIZE (xen-4.5.1.tar.gz) = 18410400

Added: head/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,141 @@
+From 411801087603a1a070de7abbfa4373afe91ca3f5 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:31 +0200
+Subject: [PATCH 1/8] introduce a helper to allocate non-contiguous memory
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The allocator uses independent calls to alloc_domheap_pages in order to get
+the desired amount of memory and then maps all the independent physical
+addresses into a contiguous virtual address space.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Tested-by: Julien Grall <julien.grall@citrix.com> (ARM)
+Reviewed-by: Tim Deegan <tim@xen.org>
+---
+ xen/common/vmap.c          | 67 ++++++++++++++++++++++++++++++++++++++++++++++
+ xen/include/asm-arm/mm.h   |  2 ++
+ xen/include/asm-x86/page.h |  2 ++
+ xen/include/xen/vmap.h     |  3 +++
+ 4 files changed, 74 insertions(+)
+
+diff --git a/xen/common/vmap.c b/xen/common/vmap.c
+index 783cea3..b6827b5 100644
+--- a/xen/common/vmap.c
++++ b/xen/common/vmap.c
+@@ -215,4 +215,71 @@ void vunmap(const void *va)
+ #endif
+     vm_free(va);
+ }
++
++void *vmalloc(size_t size)
++{
++    unsigned long *mfn;
++    size_t pages, i;
++    struct page_info *pg;
++    void *va;
++
++    ASSERT(size);
++
++    pages = PFN_UP(size);
++    mfn = xmalloc_array(unsigned long, pages);
++    if ( mfn == NULL )
++        return NULL;
++
++    for ( i = 0; i < pages; i++ )
++    {
++        pg = alloc_domheap_page(NULL, 0);
++        if ( pg == NULL )
++            goto error;
++        mfn[i] = page_to_mfn(pg);
++    }
++
++    va = vmap(mfn, pages);
++    if ( va == NULL )
++        goto error;
++
++    xfree(mfn);
++    return va;
++
++ error:
++    while ( i-- )
++         free_domheap_page(mfn_to_page(mfn[i]));
++    xfree(mfn);
++    return NULL;
++}
++
++void *vzalloc(size_t size)
++{
++    void *p = vmalloc(size);
++    int i;
++
++    if ( p == NULL )
++        return NULL;
++
++    for ( i = 0; i < size; i += PAGE_SIZE )
++        clear_page(p + i);
++
++    return p;
++}
++
++void vfree(void *va)
++{
++    unsigned int i, pages = vm_size(va);
++    struct page_info *pg;
++    PAGE_LIST_HEAD(pg_list);
++
++    ASSERT(pages);
++
++    for ( i = 0; i < pages; i++ )
++        page_list_add(vmap_to_page(va + i * PAGE_SIZE), &pg_list);
++
++    vunmap(va);
++
++    while ( (pg = page_list_remove_head(&pg_list)) != NULL )
++        free_domheap_page(pg);
++}
+ #endif
+diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
+index d25e485..c0afcec 100644
+--- a/xen/include/asm-arm/mm.h
++++ b/xen/include/asm-arm/mm.h
+@@ -208,6 +208,8 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
+ #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
+ #define paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))
+ #define paddr_to_pdx(pa)    pfn_to_pdx(paddr_to_pfn(pa))
++#define vmap_to_mfn(va)     paddr_to_pfn(virt_to_maddr((vaddr_t)va))
++#define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
+ 
+ /* Page-align address and convert to frame number format */
+ #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
+diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h
+index ccf0752..27c2ae7 100644
+--- a/xen/include/asm-x86/page.h
++++ b/xen/include/asm-x86/page.h
+@@ -262,6 +262,8 @@ void copy_page_sse2(void *, const void *);
+ #define pfn_to_paddr(pfn)   __pfn_to_paddr(pfn)
+ #define paddr_to_pfn(pa)    __paddr_to_pfn(pa)
+ #define paddr_to_pdx(pa)    pfn_to_pdx(paddr_to_pfn(pa))
++#define vmap_to_mfn(va)     l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va)))
++#define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
+ 
+ #endif /* !defined(__ASSEMBLY__) */
+ 
+diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h
+index b1923dd..a13591d 100644
+--- a/xen/include/xen/vmap.h
++++ b/xen/include/xen/vmap.h
+@@ -11,6 +11,9 @@ void *__vmap(const unsigned long *mfn, unsigned int granularity,
+              unsigned int nr, unsigned int align, unsigned int flags);
+ void *vmap(const unsigned long *mfn, unsigned int nr);
+ void vunmap(const void *);
++void *vmalloc(size_t size);
++void *vzalloc(size_t size);
++void vfree(void *va);
+ 
+ void __iomem *ioremap(paddr_t, size_t);
+ 
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0002-vmap-avoid-hitting-an-ASSERT-with-vfree-NULL.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0002-vmap-avoid-hitting-an-ASSERT-with-vfree-NULL.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,43 @@
+From ed4a7917a6faa8b7e8f211eaeda270f96e45de7d Mon Sep 17 00:00:00 2001
+From: Andrew Cooper <andrew.cooper3@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:31 +0200
+Subject: [PATCH 2/8] vmap: avoid hitting an ASSERT with vfree(NULL)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+and unconditionally defer the vm_size() call, as it doesn't have a NULL
+short circuit.
+
+Reported-by: Wei Liu <wei.liu2@citrix.com>
+Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
+Tested-by: Wei Liu <wei.liu2@citrix.com>
+Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
+Acked-by: Tim Deegan <tim@xen.org>
+---
+ xen/common/vmap.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/xen/common/vmap.c b/xen/common/vmap.c
+index b6827b5..9028802 100644
+--- a/xen/common/vmap.c
++++ b/xen/common/vmap.c
+@@ -268,10 +268,14 @@ void *vzalloc(size_t size)
+ 
+ void vfree(void *va)
+ {
+-    unsigned int i, pages = vm_size(va);
++    unsigned int i, pages;
+     struct page_info *pg;
+     PAGE_LIST_HEAD(pg_list);
+ 
++    if ( !va )
++        return;
++
++    pages = vm_size(va);
+     ASSERT(pages);
+ 
+     for ( i = 0; i < pages; i++ )
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0003-x86-shadow-fix-shadow_track_dirty_vram-to-work-on-hv.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0003-x86-shadow-fix-shadow_track_dirty_vram-to-work-on-hv.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,120 @@
+From 055ee44e3cc7c40dc3a3319370d287591771a7f3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:32 +0200
+Subject: [PATCH 3/8] x86/shadow: fix shadow_track_dirty_vram to work on hvm
+ guests
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Modify shadow_track_dirty_vram to use a local buffer and then flush to the
+guest without the paging_lock held. This is modeled after
+hap_track_dirty_vram.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Reviewed-by: Tim Deegan <tim@xen.org>
+---
+ xen/arch/x86/mm/shadow/common.c | 49 +++++++++++++++++++++++++----------------
+ 1 file changed, 30 insertions(+), 19 deletions(-)
+
+diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c
+index a5eed28..6b91b8c 100644
+--- a/xen/arch/x86/mm/shadow/common.c
++++ b/xen/arch/x86/mm/shadow/common.c
+@@ -3478,7 +3478,7 @@ void shadow_clean_dirty_bitmap(struct domain *d)
+ int shadow_track_dirty_vram(struct domain *d,
+                             unsigned long begin_pfn,
+                             unsigned long nr,
+-                            XEN_GUEST_HANDLE_64(uint8) dirty_bitmap)
++                            XEN_GUEST_HANDLE_64(uint8) guest_dirty_bitmap)
+ {
+     int rc;
+     unsigned long end_pfn = begin_pfn + nr;
+@@ -3488,6 +3488,7 @@ int shadow_track_dirty_vram(struct domain *d,
+     p2m_type_t t;
+     struct sh_dirty_vram *dirty_vram;
+     struct p2m_domain *p2m = p2m_get_hostp2m(d);
++    uint8_t *dirty_bitmap = NULL;
+ 
+     if ( end_pfn < begin_pfn || end_pfn > p2m->max_mapped_pfn + 1 )
+         return -EINVAL;
+@@ -3516,6 +3517,12 @@ int shadow_track_dirty_vram(struct domain *d,
+         goto out;
+     }
+ 
++    dirty_bitmap = vzalloc(dirty_size);
++    if ( dirty_bitmap == NULL )
++    {
++        rc = -ENOMEM;
++        goto out;
++    }
+     /* This should happen seldomly (Video mode change),
+      * no need to be careful. */
+     if ( !dirty_vram )
+@@ -3546,12 +3553,8 @@ int shadow_track_dirty_vram(struct domain *d,
+         rc = -ENODATA;
+     }
+     else if (dirty_vram->last_dirty == -1)
+-    {
+         /* still completely clean, just copy our empty bitmap */
+-        rc = -EFAULT;
+-        if ( copy_to_guest(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size) == 0 )
+-            rc = 0;
+-    }
++        memcpy(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size);
+     else
+     {
+         unsigned long map_mfn = INVALID_MFN;
+@@ -3630,21 +3633,19 @@ int shadow_track_dirty_vram(struct domain *d,
+         if ( map_sl1p )
+             sh_unmap_domain_page(map_sl1p);
+ 
+-        rc = -EFAULT;
+-        if ( copy_to_guest(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size) == 0 ) {
+-            memset(dirty_vram->dirty_bitmap, 0, dirty_size);
+-            if (dirty_vram->last_dirty + SECONDS(2) < NOW())
++        memcpy(dirty_bitmap, dirty_vram->dirty_bitmap, dirty_size);
++        memset(dirty_vram->dirty_bitmap, 0, dirty_size);
++        if ( dirty_vram->last_dirty + SECONDS(2) < NOW() )
++        {
++            /* was clean for more than two seconds, try to disable guest
++             * write access */
++            for ( i = begin_pfn; i < end_pfn; i++ )
+             {
+-                /* was clean for more than two seconds, try to disable guest
+-                 * write access */
+-                for ( i = begin_pfn; i < end_pfn; i++ ) {
+-                    mfn_t mfn = get_gfn_query_unlocked(d, i, &t);
+-                    if (mfn_x(mfn) != INVALID_MFN)
+-                        flush_tlb |= sh_remove_write_access(d->vcpu[0], mfn, 1, 0);
+-                }
+-                dirty_vram->last_dirty = -1;
++                mfn_t mfn = get_gfn_query_unlocked(d, i, &t);
++                if ( mfn_x(mfn) != INVALID_MFN )
++                    flush_tlb |= sh_remove_write_access(d->vcpu[0], mfn, 1, 0);
+             }
+-            rc = 0;
++            dirty_vram->last_dirty = -1;
+         }
+     }
+     if ( flush_tlb )
+@@ -3659,6 +3660,16 @@ out_dirty_vram:
+ 
+ out:
+     paging_unlock(d);
++    if ( rc == 0 && dirty_bitmap != NULL &&
++         copy_to_guest(guest_dirty_bitmap, dirty_bitmap, dirty_size) )
++    {
++        paging_lock(d);
++        for ( i = 0; i < dirty_size; i++ )
++            dirty_vram->dirty_bitmap[i] |= dirty_bitmap[i];
++        paging_unlock(d);
++        rc = -EFAULT;
++    }
++    vfree(dirty_bitmap);
+     p2m_unlock(p2m_get_hostp2m(d));
+     return rc;
+ }
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0004-x86-hap-make-hap_track_dirty_vram-use-non-contiguous.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0004-x86-hap-make-hap_track_dirty_vram-use-non-contiguous.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,44 @@
+From 50ca52274eda838f0562938fae3432a0f05f2585 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:32 +0200
+Subject: [PATCH 4/8] x86/hap: make hap_track_dirty_vram use non-contiguous
+ memory for temporary map
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Just like it's done for shadow_track_dirty_vram allocate the temporary
+buffer using non-contiguous memory.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Reviewed-by: Tim Deegan <tim@xen.org>
+---
+ xen/arch/x86/mm/hap/hap.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
+index abf3d7a..f7b12a8 100644
+--- a/xen/arch/x86/mm/hap/hap.c
++++ b/xen/arch/x86/mm/hap/hap.c
+@@ -87,7 +87,7 @@ int hap_track_dirty_vram(struct domain *d,
+         }
+ 
+         rc = -ENOMEM;
+-        dirty_bitmap = xzalloc_bytes(size);
++        dirty_bitmap = vzalloc(size);
+         if ( !dirty_bitmap )
+             goto out;
+ 
+@@ -168,8 +168,7 @@ int hap_track_dirty_vram(struct domain *d,
+                                   p2m_ram_logdirty, p2m_ram_rw);
+     }
+ out:
+-    if ( dirty_bitmap )
+-        xfree(dirty_bitmap);
++    vfree(dirty_bitmap);
+ 
+     return rc;
+ }
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0005-x86-rework-paging_log_dirty_op-to-work-with-hvm-gues.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0005-x86-rework-paging_log_dirty_op-to-work-with-hvm-gues.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,214 @@
+From 63d4838f2f5644060c064f356078a748ca413364 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:32 +0200
+Subject: [PATCH 5/8] x86: rework paging_log_dirty_op to work with hvm guests
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+When the caller of paging_log_dirty_op is a hvm guest Xen would choke when
+trying to copy the dirty bitmap to the guest because the paging lock is
+already held.
+
+Fix this by independently mapping each page of the guest bitmap as needed
+without the paging lock held.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Reviewed-by: Tim Deegan <tim@xen.org>
+---
+ xen/arch/x86/mm/paging.c     | 98 +++++++++++++++++++++++++++++++++++++++-----
+ xen/include/asm-x86/domain.h |  1 +
+ 2 files changed, 88 insertions(+), 11 deletions(-)
+
+diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c
+index 6b788f7..06dc7fa 100644
+--- a/xen/arch/x86/mm/paging.c
++++ b/xen/arch/x86/mm/paging.c
+@@ -397,6 +397,51 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn)
+     return rv;
+ }
+ 
++static inline void *map_dirty_bitmap(XEN_GUEST_HANDLE_64(uint8) dirty_bitmap,
++                                     unsigned long pages,
++                                     struct page_info **page)
++{
++    uint32_t pfec = PFEC_page_present | PFEC_write_access;
++    unsigned long gfn;
++    p2m_type_t p2mt;
++
++    gfn = paging_gva_to_gfn(current,
++                            (unsigned long)(dirty_bitmap.p + (pages >> 3)),
++                            &pfec);
++    if ( gfn == INVALID_GFN )
++        return NULL;
++
++    *page = get_page_from_gfn(current->domain, gfn, &p2mt, P2M_UNSHARE);
++
++    if ( !p2m_is_ram(p2mt) )
++    {
++        put_page(*page);
++        return NULL;
++    }
++    if ( p2m_is_paging(p2mt) )
++    {
++        put_page(*page);
++        p2m_mem_paging_populate(current->domain, gfn);
++        return NULL;
++    }
++    if ( p2m_is_shared(p2mt) )
++    {
++        put_page(*page);
++        return NULL;
++    }
++
++    return __map_domain_page(*page);
++}
++
++static inline void unmap_dirty_bitmap(void *addr, struct page_info *page)
++{
++    if ( addr != NULL )
++    {
++        unmap_domain_page(addr);
++        put_page(page);
++    }
++}
++
+ 
+ /* Read a domain's log-dirty bitmap and stats.  If the operation is a CLEAN,
+  * clear the bitmap and stats as well. */
+@@ -409,9 +454,22 @@ static int paging_log_dirty_op(struct domain *d,
+     mfn_t *l4 = NULL, *l3 = NULL, *l2 = NULL;
+     unsigned long *l1 = NULL;
+     int i4, i3, i2;
++    uint8_t *dirty_bitmap;
++    struct page_info *page;
++    unsigned long index_mapped;
+ 
++ again:
+     if ( !resuming )
+         domain_pause(d);
++
++    index_mapped = resuming ? d->arch.paging.preempt.log_dirty.done : 0;
++    dirty_bitmap = map_dirty_bitmap(sc->dirty_bitmap, index_mapped, &page);
++    if ( dirty_bitmap == NULL )
++    {
++        domain_unpause(d);
++        return -EFAULT;
++    }
++
+     paging_lock(d);
+ 
+     if ( !d->arch.paging.preempt.dom )
+@@ -451,18 +509,18 @@ static int paging_log_dirty_op(struct domain *d,
+     l4 = paging_map_log_dirty_bitmap(d);
+     i4 = d->arch.paging.preempt.log_dirty.i4;
+     i3 = d->arch.paging.preempt.log_dirty.i3;
++    i2 = d->arch.paging.preempt.log_dirty.i2;
+     pages = d->arch.paging.preempt.log_dirty.done;
+ 
+     for ( ; (pages < sc->pages) && (i4 < LOGDIRTY_NODE_ENTRIES); i4++, i3 = 0 )
+     {
+         l3 = (l4 && mfn_valid(l4[i4])) ? map_domain_page(mfn_x(l4[i4])) : NULL;
+-        for ( ; (pages < sc->pages) && (i3 < LOGDIRTY_NODE_ENTRIES); i3++ )
++        for ( ; (pages < sc->pages) && (i3 < LOGDIRTY_NODE_ENTRIES);
++             i3++, i2 = 0 )
+         {
+             l2 = ((l3 && mfn_valid(l3[i3])) ?
+                   map_domain_page(mfn_x(l3[i3])) : NULL);
+-            for ( i2 = 0;
+-                  (pages < sc->pages) && (i2 < LOGDIRTY_NODE_ENTRIES);
+-                  i2++ )
++            for ( ; (pages < sc->pages) && (i2 < LOGDIRTY_NODE_ENTRIES); i2++ )
+             {
+                 unsigned int bytes = PAGE_SIZE;
+                 l1 = ((l2 && mfn_valid(l2[i2])) ?
+@@ -471,15 +529,28 @@ static int paging_log_dirty_op(struct domain *d,
+                     bytes = (unsigned int)((sc->pages - pages + 7) >> 3);
+                 if ( likely(peek) )
+                 {
+-                    if ( (l1 ? copy_to_guest_offset(sc->dirty_bitmap,
+-                                                    pages >> 3, (uint8_t *)l1,
+-                                                    bytes)
+-                             : clear_guest_offset(sc->dirty_bitmap,
+-                                                  pages >> 3, bytes)) != 0 )
++                    if ( pages >> (3 + PAGE_SHIFT) !=
++                         index_mapped >> (3 + PAGE_SHIFT) )
+                     {
+-                        rv = -EFAULT;
+-                        goto out;
++                        /* We need to map next page */
++                        d->arch.paging.preempt.log_dirty.i4 = i4;
++                        d->arch.paging.preempt.log_dirty.i3 = i3;
++                        d->arch.paging.preempt.log_dirty.i2 = i2;
++                        d->arch.paging.preempt.log_dirty.done = pages;
++                        d->arch.paging.preempt.dom = current->domain;
++                        d->arch.paging.preempt.op = sc->op;
++                        resuming = 1;
++                        paging_unlock(d);
++                        unmap_dirty_bitmap(dirty_bitmap, page);
++                        goto again;
+                     }
++                    ASSERT(((pages >> 3) % PAGE_SIZE) + bytes <= PAGE_SIZE);
++                    if ( l1 )
++                        memcpy(dirty_bitmap + ((pages >> 3) % PAGE_SIZE), l1,
++                               bytes);
++                    else
++                        memset(dirty_bitmap + ((pages >> 3) % PAGE_SIZE), 0,
++                               bytes);
+                 }
+                 pages += bytes << 3;
+                 if ( l1 )
+@@ -496,6 +567,7 @@ static int paging_log_dirty_op(struct domain *d,
+             {
+                 d->arch.paging.preempt.log_dirty.i4 = i4;
+                 d->arch.paging.preempt.log_dirty.i3 = i3 + 1;
++                d->arch.paging.preempt.log_dirty.i2 = 0;
+                 rv = -ERESTART;
+                 break;
+             }
+@@ -508,6 +580,7 @@ static int paging_log_dirty_op(struct domain *d,
+         {
+             d->arch.paging.preempt.log_dirty.i4 = i4 + 1;
+             d->arch.paging.preempt.log_dirty.i3 = 0;
++            d->arch.paging.preempt.log_dirty.i2 = 0;
+             rv = -ERESTART;
+         }
+         if ( rv )
+@@ -537,6 +610,7 @@ static int paging_log_dirty_op(struct domain *d,
+     if ( rv )
+     {
+         /* Never leave the domain paused on real errors. */
++        unmap_dirty_bitmap(dirty_bitmap, page);
+         ASSERT(rv == -ERESTART);
+         return rv;
+     }
+@@ -549,12 +623,14 @@ static int paging_log_dirty_op(struct domain *d,
+          * paging modes (shadow or hap).  Safe because the domain is paused. */
+         d->arch.paging.log_dirty.clean_dirty_bitmap(d);
+     }
++    unmap_dirty_bitmap(dirty_bitmap, page);
+     domain_unpause(d);
+     return rv;
+ 
+  out:
+     d->arch.paging.preempt.dom = NULL;
+     paging_unlock(d);
++    unmap_dirty_bitmap(dirty_bitmap, page);
+     domain_unpause(d);
+ 
+     if ( l1 )
+diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
+index 6a77a93..63dea9c 100644
+--- a/xen/include/asm-x86/domain.h
++++ b/xen/include/asm-x86/domain.h
+@@ -197,6 +197,7 @@ struct paging_domain {
+                 unsigned long done:PADDR_BITS - PAGE_SHIFT;
+                 unsigned long i4:PAGETABLE_ORDER;
+                 unsigned long i3:PAGETABLE_ORDER;
++                unsigned long i2:PAGETABLE_ORDER;
+             } log_dirty;
+         };
+     } preempt;
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0006-xen-pvh-enable-mmu_update-hypercall.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0006-xen-pvh-enable-mmu_update-hypercall.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,33 @@
+From bec71ff2b61acc42e71a2bd79ec5cf172130e5f8 Mon Sep 17 00:00:00 2001
+From: Roger Pau Monne <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:32 +0200
+Subject: [PATCH 6/8] xen/pvh: enable mmu_update hypercall
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This is needed for performing save/restore of PV guests.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Cc: Tim Deegan <tim@xen.org>
+Cc: Jan Beulich <jbeulich@suse.com>
+Cc: Andrew Cooper <andrew.cooper3@citrix.com>
+---
+ xen/arch/x86/hvm/hvm.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
+index 7d53c6c..d3fdc3d 100644
+--- a/xen/arch/x86/hvm/hvm.c
++++ b/xen/arch/x86/hvm/hvm.c
+@@ -4843,6 +4843,7 @@ static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = {
+     [ __HYPERVISOR_grant_table_op ]  = (hvm_hypercall_t *)hvm_grant_table_op,
+     HYPERCALL(vcpu_op),
+     HYPERCALL(mmuext_op),
++    HYPERCALL(mmu_update),
+     HYPERCALL(xsm_op),
+     HYPERCALL(sched_op),
+     HYPERCALL(event_channel_op),
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0007-iommu-fix-usage-of-shared-EPT-IOMMU-page-tables-on-P.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0007-iommu-fix-usage-of-shared-EPT-IOMMU-page-tables-on-P.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,86 @@
+From 43f76b1443c8fc3b54dbb9fb466becbb9d584d6d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com>
+Date: Fri, 9 Oct 2015 12:57:33 +0200
+Subject: [PATCH 7/8] iommu: fix usage of shared EPT/IOMMU page tables on PVH
+ guests
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+iommu_share_p2m_table should not prevent PVH guests from using a shared page
+table between the IOMMU and EPT. Clean the code by removing the asserts in
+the vendor specific implementations (amd_iommu_share_p2m, iommu_set_pgd),
+and moving the hap_enabled assert to the caller (iommu_share_p2m_table).
+
+Also fix another incorrect usage of is_hvm_domain usage in
+arch_iommu_populate_page_table. This has not given problems so far because
+all the pages in PVH guests are of type PGT_writable_page.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Reviewed-by: Jan Beulich <jbeulich@suse.com>
+Tested-by: David Vrabel <david.vrabel@citrix.com>
+Reviewed-by: Tim Deegan <tim@xen.org>
+Acked-by: Kevin Tian <kevin.tian@intel.com>
+---
+ xen/drivers/passthrough/amd/iommu_map.c | 2 --
+ xen/drivers/passthrough/iommu.c         | 3 ++-
+ xen/drivers/passthrough/vtd/iommu.c     | 2 --
+ xen/drivers/passthrough/x86/iommu.c     | 2 +-
+ 4 files changed, 3 insertions(+), 6 deletions(-)
+
+diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c
+index a8c60ec..31dc05d 100644
+--- a/xen/drivers/passthrough/amd/iommu_map.c
++++ b/xen/drivers/passthrough/amd/iommu_map.c
+@@ -785,8 +785,6 @@ void amd_iommu_share_p2m(struct domain *d)
+     struct page_info *p2m_table;
+     mfn_t pgd_mfn;
+ 
+-    ASSERT( is_hvm_domain(d) && d->arch.hvm_domain.hap_enabled );
+-
+     if ( !iommu_use_hap_pt(d) )
+         return;
+ 
+diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
+index cc12735..7fcbbb1 100644
+--- a/xen/drivers/passthrough/iommu.c
++++ b/xen/drivers/passthrough/iommu.c
+@@ -332,7 +332,8 @@ void iommu_share_p2m_table(struct domain* d)
+ {
+     const struct iommu_ops *ops = iommu_get_ops();
+ 
+-    if ( iommu_enabled && is_hvm_domain(d) )
++    ASSERT( hap_enabled(d) );
++    if ( iommu_enabled )
+         ops->share_p2m(d);
+ }
+ 
+diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
+index 5a946d4..a5a111c 100644
+--- a/xen/drivers/passthrough/vtd/iommu.c
++++ b/xen/drivers/passthrough/vtd/iommu.c
+@@ -1802,8 +1802,6 @@ static void iommu_set_pgd(struct domain *d)
+     struct hvm_iommu *hd  = domain_hvm_iommu(d);
+     mfn_t pgd_mfn;
+ 
+-    ASSERT( is_hvm_domain(d) && d->arch.hvm_domain.hap_enabled );
+-
+     if ( !iommu_use_hap_pt(d) )
+         return;
+ 
+diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c
+index ce0ca5a..3d2c12a 100644
+--- a/xen/drivers/passthrough/x86/iommu.c
++++ b/xen/drivers/passthrough/x86/iommu.c
+@@ -56,7 +56,7 @@ int arch_iommu_populate_page_table(struct domain *d)
+ 
+     while ( !rc && (page = page_list_remove_head(&d->page_list)) )
+     {
+-        if ( is_hvm_domain(d) ||
++        if ( has_hvm_container_domain(d) ||
+             (page->u.inuse.type_info & PGT_type_mask) == PGT_writable_page )
+         {
+             BUG_ON(SHARED_M2P(mfn_to_gmfn(d, page_to_mfn(page))));
+-- 
+1.9.5 (Apple Git-50.3)
+

Added: head/emulators/xen-kernel/files/0008-xen-arm-mm-Do-not-dump-the-p2m-when-mapping-a-foreig.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/xen-kernel/files/0008-xen-arm-mm-Do-not-dump-the-p2m-when-mapping-a-foreig.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,39 @@
+From 403805aca7a4a508cf193d63aa525b3a76bb09dd Mon Sep 17 00:00:00 2001
+From: Julien Grall <julien.grall@citrix.com>
+Date: Fri, 9 Oct 2015 13:00:35 +0200
+Subject: [PATCH 8/8] xen/arm: mm: Do not dump the p2m when mapping a foreign
+ gfn
+
+The physmap operation XENMAPSPACE_gfmn_foreign is dumping the p2m when
+an error occured by calling dump_p2m_lookup. But this function is not
+using ratelimited printk.
+
+Any domain able to map foreign gfmn would be able to flood the Xen
+console.
+
+The information wasn't not useful so drop it.
+
+This is XSA-141.
+
+Signed-off-by: Julien Grall <julien.grall@citrix.com>
+Acked-by: Ian Campbell <ian.campbell@citrix.com>
+(cherry picked from commit afc13fe5e21d18c09e44f8ae6f7f4484e9f1de7f)
+---
+ xen/arch/arm/mm.c | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
+index 7d4ba0c..7d95961 100644
+--- a/xen/arch/arm/mm.c
++++ b/xen/arch/arm/mm.c
+@@ -1103,7 +1103,6 @@ int xenmem_add_to_physmap_one(
+         page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC);
+         if ( !page )
+         {
+-            dump_p2m_lookup(od, pfn_to_paddr(idx));
+             rcu_unlock_domain(od);
+             return -EINVAL;
+         }
+-- 
+1.9.5 (Apple Git-50.3)
+

Modified: head/sysutils/xen-tools/Makefile
==============================================================================
--- head/sysutils/xen-tools/Makefile	Fri Oct  9 13:39:22 2015	(r398917)
+++ head/sysutils/xen-tools/Makefile	Fri Oct  9 14:09:07 2015	(r398918)
@@ -2,6 +2,7 @@
 
 PORTNAME=	xen
 PORTVERSION=	4.5.1
+PORTREVISION=	1
 CATEGORIES=	sysutils emulators
 MASTER_SITES=	http://bits.xensource.com/oss-xen/release/${PORTVERSION}/ \
 		http://code.coreboot.org/p/seabios/downloads/get/:seabios
@@ -48,6 +49,7 @@ QEMU_ARGS=	--disable-gtk \
 		--cxx=c++
 
 EXTRA_PATCHES=	${FILESDIR}/xsa137.patch:-p1 \
+		${FILESDIR}/xsa142-4.5.patch:-p1 \
 		${FILESDIR}/0002-libxc-fix-xc_dom_load_elf_symtab.patch:-p1
 
 CONFIGURE_ARGS+=	--with-extra-qemuu-configure-args="${QEMU_ARGS}"
@@ -75,10 +77,6 @@ post-patch:
 		${WRKSRC}/tools/libxl/libxl_dm.c \
 		${WRKSRC}/tools/qemu-xen-traditional/i386-dm/helper2.c \
 		${WRKSRC}/docs/man/*
-	@for p in ${FILESDIR}/*qemut*.patch; do \
-		${ECHO_CMD} "====> Applying $${p##*/}" ; \
-		${PATCH} -s -p1 -i $${p} -d ${WRKSRC}/tools/qemu-xen-traditional ; \
-	done
 	@for p in ${FILESDIR}/*qemuu*.patch; do \
 		${ECHO_CMD} "====> Applying $${p##*/}" ; \
 		${PATCH} -s -p1 -i $${p} -d ${WRKSRC}/tools/qemu-xen ; \

Added: head/sysutils/xen-tools/files/xsa142-4.5.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/xen-tools/files/xsa142-4.5.patch	Fri Oct  9 14:09:07 2015	(r398918)
@@ -0,0 +1,53 @@
+From 07ca00703f76ad392eda5ee52cce1197cf49c30a Mon Sep 17 00:00:00 2001
+From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
+Subject: [PATCH v2.1 for-4.5] libxl: handle read-only drives with qemu-xen
+
+The current libxl code doesn't deal with read-only drives at all.
+
+Upstream QEMU and qemu-xen only support read-only cdrom drives: make
+sure to specify "readonly=on" for cdrom drives and return error in case
+the user requested a non-cdrom read-only drive.
+
+This is XSA-142, discovered by Lin Liu
+(https://bugzilla.redhat.com/show_bug.cgi?id=1257893).
+
+Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
+
+Backport to Xen 4.5 and earlier, apropos of report and review from
+Michael Young.
+
+Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
+---
+ tools/libxl/libxl_dm.c |   13 +++++++++----
+ 1 file changed, 9 insertions(+), 4 deletions(-)
+
+diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
+index b4ce523..d74fb14 100644
+--- a/tools/libxl/libxl_dm.c
++++ b/tools/libxl/libxl_dm.c
+@@ -797,13 +797,18 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
+             if (disks[i].is_cdrom) {
+                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
+                     drive = libxl__sprintf
+-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
+-                         disk, dev_number);
++                        (gc, "if=ide,index=%d,readonly=%s,media=cdrom,cache=writeback,id=ide-%i",
++                         disk, disks[i].readwrite ? "off" : "on", dev_number);
+                 else
+                     drive = libxl__sprintf
+-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+-                         disks[i].pdev_path, disk, format, dev_number);
++                        (gc, "file=%s,if=ide,index=%d,readonly=%s,media=cdrom,format=%s,cache=writeback,id=ide-%i",
++                         disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number);
+             } else {
++                if (!disks[i].readwrite) {
++                    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "qemu-xen doesn't support read-only disk drivers");
++                    return NULL;
++                }
++
+                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
+                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
+                                " empty disk format for %s", disks[i].vdev);
+-- 
+1.7.10.4
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510091409.t99E97ca079157>