From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7v6-0002qF-AY; Fri, 04 Sep 2020 09:22:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7v4-0002qA-UU
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:06 +0000
X-Inumbo-ID: 4b9bc2ec-cc2f-42de-9516-7e9797ac724f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4b9bc2ec-cc2f-42de-9516-7e9797ac724f;
 Fri, 04 Sep 2020 09:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PpDjy3BlluTE8Atx1zyQFjs9rMsk5aud+6X+kFOKcFc=; b=p6mWYBEvMoh+TXBSyNaf/aOSzJ
 8MLHSbfgS13JcUyLjDyhd26bZdVa5gHRPV8f0C6dl9p6QlngOn2w/w/fPxkMdVsN3SnbJPC8dMOf5
 lviVSzedWi1+wkOemGDRr8uAfW4r/XjdokB4RJhQn8Xnk9z0mGW2OT9k8l1ECol+8644=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7v3-00006P-Je
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7v3-0001Yc-GA
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: simplify is_guest_l2_slot()
Message-Id: <E1kE7v3-0001Yc-GA@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8cf225013582723275f0d60f1107319f5963af7f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 10:59:33 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 10:59:33 2020 +0200

    x86: simplify is_guest_l2_slot()
    
    is_pv_32bit_domain() has become expensive, and its use here is
    redundant: Only 32-bit guests would ever get PGT_pae_xen_l2 set on
    their L2 page table pages anyway. (If some other error does lead to
    PGT_pae_xen_l2 ending up anywhere else, we still don't want to allow a
    guest to control the entries.)
    
    Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/page.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/page.h b/xen/include/asm-x86/x86_64/page.h
index 26621f9519..60db28f4e7 100644
--- a/xen/include/asm-x86/x86_64/page.h
+++ b/xen/include/asm-x86/x86_64/page.h
@@ -106,8 +106,7 @@ typedef l4_pgentry_t root_pgentry_t;
 #define l4_linear_offset(_a) (((_a) & VADDR_MASK) >> L4_PAGETABLE_SHIFT)
 
 #define is_guest_l2_slot(_d, _t, _s)                   \
-    ( !is_pv_32bit_domain(_d) ||                       \
-      !((_t) & PGT_pae_xen_l2) ||                      \
+    ( !((_t) & PGT_pae_xen_l2) ||                      \
       ((_s) < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_d)) )
 #define is_guest_l4_slot(_d, _s)                    \
     ( is_pv_32bit_domain(_d)                        \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7vF-0002qj-C5; Fri, 04 Sep 2020 09:22:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7vE-0002qe-Ii
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:16 +0000
X-Inumbo-ID: d07103a5-85aa-4cf4-8b29-e300cadc6556
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d07103a5-85aa-4cf4-8b29-e300cadc6556;
 Fri, 04 Sep 2020 09:22:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Qo+xxeUaa5lSBvUAVl4HYVl6DJmnpCn1gzOpKZqZeGc=; b=gUCGUIaNwPlBMODONaBJ5BjkTh
 /7aY6y6MUbhyG+QaJIQ0dOOQFcSVVLZvvqoRphcR1aEZ8GQGtoNJiRFbak3hH4MBZh4jweVjw3wXE
 oUZzHtpxyYPpycKwAEfUbegP1tcmq6BgpQWu2mKNf9mAZfbunGl/oKpyLFGdNr2/zqO0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vD-00006S-NX
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vD-0001Zq-Md
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/msr: explicitly handle AMD DE_CFG
Message-Id: <E1kE7vD-0001Zq-Md@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4175fd3ccd17face664036fa98e9329aa317f7b6
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 4 11:00:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:00:46 2020 +0200

    x86/msr: explicitly handle AMD DE_CFG
    
    Report LFENCE_SERIALISE unconditionally for DE_CFG on AMD hardware and
    silently drop writes.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/msr.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index a478b91f23..74bf7d9589 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -292,6 +292,12 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         *val = msrs->tsc_aux;
         break;
 
+    case MSR_AMD64_DE_CFG:
+        if ( !(cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
+            goto gp_fault;
+        *val = AMD64_DE_CFG_LFENCE_SERIALISE;
+        break;
+
     case MSR_AMD64_DR0_ADDRESS_MASK:
     case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
         if ( !cp->extd.dbext )
@@ -517,6 +523,15 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
             wrmsr_tsc_aux(val);
         break;
 
+    case MSR_AMD64_DE_CFG:
+        /*
+         * OpenBSD 6.7 will panic if writing to DE_CFG triggers a #GP:
+         * https://www.illumos.org/issues/12998 - drop writes.
+         */
+        if ( !(cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
+            goto gp_fault;
+        break;
+
     case MSR_AMD64_DR0_ADDRESS_MASK:
     case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
         if ( !cp->extd.dbext || val != (uint32_t)val )
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7vQ-0002ta-Dk; Fri, 04 Sep 2020 09:22:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7vP-0002tP-BO
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:27 +0000
X-Inumbo-ID: 58ae6a8f-02f3-479c-ba55-05ec01d7f782
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 58ae6a8f-02f3-479c-ba55-05ec01d7f782;
 Fri, 04 Sep 2020 09:22:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rgyKJnG1IqimwWpF5PqPLbdUlYTgr4KH+FYd0tn1KNg=; b=IEb5/ONz5pRV7TK1oKRv5giQuS
 59iewKELcR8xdVv2mruXXZJfTLEj9L5yK6bgjBr/xJnslWABsndav0Sxtjq4A73SE2J8k8tDG6w2Q
 bV5zmOqNBgwHaW2kgnJwJaqYsNQUuKk6IuqhKNGEBaInOBhF7IEYgF6lEVyNowCIvRBU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vN-00006b-R6
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vN-0001aN-Py
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] add additional symbols to xen-syms.map
Message-Id: <E1kE7vN-0001aN-Py@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c9e88d200d1b8c4edef5bddb91690e76f7f87780
Author:     Michael Kurth <mku@amazon.de>
AuthorDate: Fri Sep 4 11:01:45 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:01:45 2020 +0200

    add additional symbols to xen-syms.map
    
    Add "all_symbols" to all /tools/symbols calls so that
    xen-syms.map lists all symbols and not only .text section
    symbols. This change enhances debugging and livepatch
    capabilities.
    
    Signed-off-by: Michael Kurth <mku@amazon.de>
    Reviewed-by: Eslam Elnikety <elnikety@amazon.de>
    Reviewed-by: Julien Grall <jgrall@amazon.co.uk>
    Reviewed-by: Robert Stonehouse <rjstone@amazon.co.uk>
    Reviewed-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/arm/Makefile | 2 +-
 xen/arch/x86/Makefile | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 7e82b2178c..51173d9712 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -115,7 +115,7 @@ $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
 	    $(@D)/.$(@F).1.o -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \
 		>$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]*
 
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 1073e454b1..1f279b6b2e 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -168,7 +168,7 @@ $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
 	    $(@D)/.$(@F).1.o -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \
 		>$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
 
@@ -224,7 +224,7 @@ $(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o efi/mkreloc
 	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \
 	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(note_file_option) -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort >$(@D)/$(@F).map
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort >$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
 else
 $(TARGET).efi: FORCE
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7vb-0002ui-FR; Fri, 04 Sep 2020 09:22:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7va-0002ua-J5
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:38 +0000
X-Inumbo-ID: 8bcbe7bd-595e-4f7a-9085-c0bbe087349b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8bcbe7bd-595e-4f7a-9085-c0bbe087349b;
 Fri, 04 Sep 2020 09:22:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LhiLUxW1uuU9L7vK5/VLK/DbJ5MrvxSprKHdpCY20/M=; b=5HPMXNyT7r7bDWNHJiODP/XqJd
 82NSz21XdDL+cjFakPjd/RcSWljiISMfWWU2NzLHIx0dCGi1Jpudmj1S9Ehtj5BwFezqoEgTeYt//
 GTu5JiJ247GKR3A24eS4UebWG6ffPDXXTb60FmaZfoNsNAg8iKuNKDKyId8KSA07RClc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vY-00006k-0J
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vX-0001b1-UE
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: fix compat header generation
Message-Id: <E1kE7vX-0001b1-UE@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0dd40d68b10a2b3191a06ff8a996a57dcca96a88
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:05:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:05:46 2020 +0200

    x86: fix compat header generation
    
    As was pointed out by 0e2e54966af5 ("mm: fix public declaration of
    struct xen_mem_acquire_resource"), we're not currently handling structs
    correctly that have uint64_aligned_t fields. #pragma pack(4) suppresses
    the necessary alignment even if the type did properly survive (which
    it also didn't) in the process of generating the headers. Overall,
    with the above mentioned change applied, there's only a latent issue
    here afaict, i.e. no other of our interface structs is currently
    affected.
    
    As a result it is clear that using #pragma pack(4) is not an option.
    Drop all uses from compat header generation. Make sure
    {,u}int64_aligned_t actually survives, such that explicitly aligned
    fields will remain aligned. Arrange for {,u}int64_t to be transformed
    into a type that's 64 bits wide and 4-byte aligned, by utilizing that
    in typedef-s the "aligned" attribute can be used to reduce alignment.
    Additionally, for the cases where native structures get re-used,
    enforce suitable alignment via typedef-s (which allow alignment to be
    reduced).
    
    This use of typedef-s makes necessary changes to CHECK_*() macro
    generation: Previously get-fields.sh relied on finding struct/union
    keywords when other compound types were used. We need to use the
    typedef-s (guaranteeing suitable alignment) now, and hence the script
    has to recognize those cases, too. (Unfortunately there are a few
    special cases to be dealt with, but this is really not much different
    from e.g. the pre-existing compat_domain_handle_t special case.)
    
    This need to use typedef-s is certainly somewhat fragile going forward,
    as in similar future cases it is imperative to also use typedef-s, or
    else the CHECK_*() macros won't check what they're supposed to check. I
    don't currently see any means to avoid this fragility, though.
    
    There's one change to generated code according to my observations: In
    arch_compat_vcpu_op() the runstate area "area" variable would previously
    have been put in a just 4-byte aligned stack slot (despite being 8 bytes
    in size), whereas now it gets put in an 8-byte aligned location.
    
    There also results some curious inconsistency in struct xen_mc from
    these changes - I intend to clean this up later on. Otherwise unrelated
    code would also need adjustment right here.
    
    Additionally a note about the apparently superfluous () in
    compat-build-header.py: The simpler form
    
     [ r"typedef(.*)@KeeP@(xen_?)?([\w]+)([^\w])",
       r"typedef\1\2\3 __attribute__((__aligned__(__alignof(\1compat_\3))))\4" ],
    
    upsets Python up to at least 3.4.6, claiming to be unable to find the
    expansion of \2 (at least when it's empty).
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/Makefile                  | 11 -------
 xen/include/public/arch-x86/pmu.h     |  6 ++--
 xen/include/public/arch-x86/xen-mca.h | 33 ++++++++++++---------
 xen/include/public/argo.h             | 10 +++----
 xen/include/public/event_channel.h    | 20 ++++++-------
 xen/include/public/hvm/dm_op.h        | 54 +++++++++++++++++++++++------------
 xen/include/public/hvm/hvm_vcpu.h     |  6 ++--
 xen/include/public/hypfs.h            |  3 +-
 xen/include/public/memory.h           |  2 +-
 xen/include/public/physdev.h          | 12 ++++----
 xen/include/public/platform.h         | 50 +++++++++++++++++---------------
 xen/include/public/pmu.h              |  2 +-
 xen/include/public/xen.h              |  3 +-
 xen/include/public/xsm/flask_op.h     | 39 ++++++++++++++++---------
 xen/tools/compat-build-header.py      |  8 ++++--
 xen/tools/compat-build-source.py      |  1 +
 xen/tools/get-fields.sh               | 23 +++++++++++++++
 17 files changed, 170 insertions(+), 113 deletions(-)

diff --git a/xen/include/Makefile b/xen/include/Makefile
index 089314dc72..0be5540886 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -34,15 +34,6 @@ headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h
 cppflags-y                := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS
 cppflags-$(CONFIG_X86)    += -m32
 
-# 8-byte types are 4-byte aligned on x86_32 ...
-ifeq ($(CONFIG_CC_IS_CLANG),y)
-prefix-$(CONFIG_X86)      := \#pragma pack(push, 4)
-suffix-$(CONFIG_X86)      := \#pragma pack(pop)
-else
-prefix-$(CONFIG_X86)      := \#pragma pack(4)
-suffix-$(CONFIG_X86)      := \#pragma pack()
-endif
-
 endif
 
 public-$(CONFIG_X86) := $(wildcard public/arch-x86/*.h public/arch-x86/*/*.h)
@@ -57,10 +48,8 @@ compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
 	echo "#define $$id" >>$@.new; \
 	echo "#include <xen/compat.h>" >>$@.new; \
 	$(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \
-	$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
 	grep -v '^# [0-9]' $< | \
 	$(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
-	$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
 	echo "#endif /* $$id */" >>$@.new
 	mv -f $@.new $@
 
diff --git a/xen/include/public/arch-x86/pmu.h b/xen/include/public/arch-x86/pmu.h
index c421cb7a4a..464c65dac1 100644
--- a/xen/include/public/arch-x86/pmu.h
+++ b/xen/include/public/arch-x86/pmu.h
@@ -105,7 +105,7 @@ struct xen_pmu_arch {
          * Processor's registers at the time of interrupt.
          * WO for hypervisor, RO for guests.
          */
-        struct xen_pmu_regs regs;
+        xen_pmu_regs_t regs;
         /* Padding for adding new registers to xen_pmu_regs in the future */
 #define XENPMU_REGS_PAD_SZ  64
         uint8_t pad[XENPMU_REGS_PAD_SZ];
@@ -132,8 +132,8 @@ struct xen_pmu_arch {
      * hypervisor into hardware during XENPMU_flush
      */
     union {
-        struct xen_pmu_amd_ctxt amd;
-        struct xen_pmu_intel_ctxt intel;
+        xen_pmu_amd_ctxt_t amd;
+        xen_pmu_intel_ctxt_t intel;
 
         /*
          * Padding for contexts (fixed parts only, does not include MSR banks
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index b5e04b5444..702998b0eb 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -112,7 +112,7 @@ struct mcinfo_common {
     uint16_t type;      /* structure type */
     uint16_t size;      /* size of this struct in bytes */
 };
-
+typedef struct mcinfo_common xen_mcinfo_common_t;
 
 #define MC_FLAG_CORRECTABLE     (1 << 0)
 #define MC_FLAG_UNCORRECTABLE   (1 << 1)
@@ -123,7 +123,7 @@ struct mcinfo_common {
 #define MC_FLAG_MCE		(1 << 6)
 /* contains global x86 mc information */
 struct mcinfo_global {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     /* running domain at the time in error (most likely the impacted one) */
     uint16_t mc_domid;
@@ -138,7 +138,7 @@ struct mcinfo_global {
 
 /* contains bank local x86 mc information */
 struct mcinfo_bank {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     uint16_t mc_bank; /* bank nr */
     uint16_t mc_domid; /* Usecase 5: domain referenced by mc_addr on dom0
@@ -156,11 +156,12 @@ struct mcinfo_msr {
     uint64_t reg;   /* MSR */
     uint64_t value; /* MSR value */
 };
+typedef struct mcinfo_msr xen_mcinfo_msr_t;
 
 /* contains mc information from other
  * or additional mc MSRs */
 struct mcinfo_extended {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     /* You can fill up to five registers.
      * If you need more, then use this structure
@@ -172,7 +173,7 @@ struct mcinfo_extended {
      * and E(R)FLAGS, E(R)IP, E(R)MISC, up to 11/19 of them might be
      * useful at present. So expand this array to 32 to leave room.
      */
-    struct mcinfo_msr mc_msr[32];
+    xen_mcinfo_msr_t mc_msr[32];
 };
 
 /* Recovery Action flags. Giving recovery result information to DOM0 */
@@ -208,6 +209,7 @@ struct page_offline_action
     uint64_t mfn;
     uint64_t status;
 };
+typedef struct page_offline_action xen_page_offline_action_t;
 
 struct cpu_offline_action
 {
@@ -216,17 +218,18 @@ struct cpu_offline_action
     uint16_t mc_coreid;
     uint16_t mc_core_threadid;
 };
+typedef struct cpu_offline_action xen_cpu_offline_action_t;
 
 #define MAX_UNION_SIZE 16
 struct mcinfo_recovery
 {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
     uint16_t mc_bank; /* bank nr */
     uint8_t action_flags;
     uint8_t action_types;
     union {
-        struct page_offline_action page_retire;
-        struct cpu_offline_action cpu_offline;
+        xen_page_offline_action_t page_retire;
+        xen_cpu_offline_action_t cpu_offline;
         uint8_t pad[MAX_UNION_SIZE];
     } action_info;
 };
@@ -279,7 +282,7 @@ struct mcinfo_logical_cpu {
     uint32_t mc_cache_size;
     uint32_t mc_cache_alignment;
     int32_t mc_nmsrvals;
-    struct mcinfo_msr mc_msrvalues[__MC_MSR_ARRAYSIZE];
+    xen_mcinfo_msr_t mc_msrvalues[__MC_MSR_ARRAYSIZE];
 };
 typedef struct mcinfo_logical_cpu xen_mc_logical_cpu_t;
 DEFINE_XEN_GUEST_HANDLE(xen_mc_logical_cpu_t);
@@ -399,8 +402,9 @@ struct xen_mc_msrinject {
     domid_t  mcinj_domid;           /* valid only if MC_MSRINJ_F_GPADDR is
                                        present in mcinj_flags */
     uint16_t _pad0;
-    struct mcinfo_msr mcinj_msr[MC_MSRINJ_MAXMSRS];
+    xen_mcinfo_msr_t mcinj_msr[MC_MSRINJ_MAXMSRS];
 };
+typedef struct xen_mc_msrinject xen_mc_msrinject_t;
 
 /* Flags for mcinj_flags above; bits 16-31 are reserved */
 #define MC_MSRINJ_F_INTERPOSE   0x1
@@ -410,6 +414,7 @@ struct xen_mc_msrinject {
 struct xen_mc_mceinject {
     unsigned int mceinj_cpunr;      /* target processor id */
 };
+typedef struct xen_mc_mceinject xen_mc_mceinject_t;
 
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 #define XEN_MC_inject_v2        6
@@ -422,7 +427,7 @@ struct xen_mc_mceinject {
 
 struct xen_mc_inject_v2 {
     uint32_t flags;
-    struct xenctl_bitmap cpumap;
+    xenctl_bitmap_t cpumap;
 };
 #endif
 
@@ -431,10 +436,10 @@ struct xen_mc {
     uint32_t interface_version; /* XEN_MCA_INTERFACE_VERSION */
     union {
         struct xen_mc_fetch        mc_fetch;
-        struct xen_mc_notifydomain mc_notifydomain;
+        xen_mc_notifydomain_t      mc_notifydomain;
         struct xen_mc_physcpuinfo  mc_physcpuinfo;
-        struct xen_mc_msrinject    mc_msrinject;
-        struct xen_mc_mceinject    mc_mceinject;
+        xen_mc_msrinject_t         mc_msrinject;
+        xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
         struct xen_mc_inject_v2    mc_inject_v2;
 #endif
diff --git a/xen/include/public/argo.h b/xen/include/public/argo.h
index 6b645f34e6..3397a3a33f 100644
--- a/xen/include/public/argo.h
+++ b/xen/include/public/argo.h
@@ -67,8 +67,8 @@ typedef struct xen_argo_addr
 
 typedef struct xen_argo_send_addr
 {
-    struct xen_argo_addr src;
-    struct xen_argo_addr dst;
+    xen_argo_addr_t src;
+    xen_argo_addr_t dst;
 } xen_argo_send_addr_t;
 
 typedef struct xen_argo_ring
@@ -121,7 +121,7 @@ typedef struct xen_argo_unregister_ring
 
 typedef struct xen_argo_ring_data_ent
 {
-    struct xen_argo_addr ring;
+    xen_argo_addr_t ring;
     uint16_t flags;
     uint16_t pad;
     uint32_t space_required;
@@ -132,13 +132,13 @@ typedef struct xen_argo_ring_data
 {
     uint32_t nent;
     uint32_t pad;
-    struct xen_argo_ring_data_ent data[XEN_FLEX_ARRAY_DIM];
+    xen_argo_ring_data_ent_t data[XEN_FLEX_ARRAY_DIM];
 } xen_argo_ring_data_t;
 
 struct xen_argo_ring_message_header
 {
     uint32_t len;
-    struct xen_argo_addr source;
+    xen_argo_addr_t source;
     uint32_t message_type;
     uint8_t data[XEN_FLEX_ARRAY_DIM];
 };
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index cfb7929fef..246ace4d19 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -321,16 +321,16 @@ typedef struct evtchn_set_priority evtchn_set_priority_t;
 struct evtchn_op {
     uint32_t cmd; /* enum event_channel_op */
     union {
-        struct evtchn_alloc_unbound    alloc_unbound;
-        struct evtchn_bind_interdomain bind_interdomain;
-        struct evtchn_bind_virq        bind_virq;
-        struct evtchn_bind_pirq        bind_pirq;
-        struct evtchn_bind_ipi         bind_ipi;
-        struct evtchn_close            close;
-        struct evtchn_send             send;
-        struct evtchn_status           status;
-        struct evtchn_bind_vcpu        bind_vcpu;
-        struct evtchn_unmask           unmask;
+        evtchn_alloc_unbound_t    alloc_unbound;
+        evtchn_bind_interdomain_t bind_interdomain;
+        evtchn_bind_virq_t        bind_virq;
+        evtchn_bind_pirq_t        bind_pirq;
+        evtchn_bind_ipi_t         bind_ipi;
+        evtchn_close_t            close;
+        evtchn_send_t             send;
+        evtchn_status_t           status;
+        evtchn_bind_vcpu_t        bind_vcpu;
+        evtchn_unmask_t           unmask;
     } u;
 };
 typedef struct evtchn_op evtchn_op_t;
diff --git a/xen/include/public/hvm/dm_op.h b/xen/include/public/hvm/dm_op.h
index fd00e9d761..66cae1afbd 100644
--- a/xen/include/public/hvm/dm_op.h
+++ b/xen/include/public/hvm/dm_op.h
@@ -74,6 +74,7 @@ struct xen_dm_op_create_ioreq_server {
     /* OUT - server id */
     ioservid_t id;
 };
+typedef struct xen_dm_op_create_ioreq_server xen_dm_op_create_ioreq_server_t;
 
 /*
  * XEN_DMOP_get_ioreq_server_info: Get all the information necessary to
@@ -113,6 +114,7 @@ struct xen_dm_op_get_ioreq_server_info {
     /* OUT - buffered ioreq gfn (see block comment above)*/
     uint64_aligned_t bufioreq_gfn;
 };
+typedef struct xen_dm_op_get_ioreq_server_info xen_dm_op_get_ioreq_server_info_t;
 
 /*
  * XEN_DMOP_map_io_range_to_ioreq_server: Register an I/O range for
@@ -148,6 +150,7 @@ struct xen_dm_op_ioreq_server_range {
     /* IN - inclusive start and end of range */
     uint64_aligned_t start, end;
 };
+typedef struct xen_dm_op_ioreq_server_range xen_dm_op_ioreq_server_range_t;
 
 #define XEN_DMOP_PCI_SBDF(s,b,d,f) \
 	((((s) & 0xffff) << 16) |  \
@@ -173,6 +176,7 @@ struct xen_dm_op_set_ioreq_server_state {
     uint8_t enabled;
     uint8_t pad;
 };
+typedef struct xen_dm_op_set_ioreq_server_state xen_dm_op_set_ioreq_server_state_t;
 
 /*
  * XEN_DMOP_destroy_ioreq_server: Destroy the IOREQ Server <id>.
@@ -186,6 +190,7 @@ struct xen_dm_op_destroy_ioreq_server {
     ioservid_t id;
     uint16_t pad;
 };
+typedef struct xen_dm_op_destroy_ioreq_server xen_dm_op_destroy_ioreq_server_t;
 
 /*
  * XEN_DMOP_track_dirty_vram: Track modifications to the specified pfn
@@ -203,6 +208,7 @@ struct xen_dm_op_track_dirty_vram {
     /* IN - first pfn to track */
     uint64_aligned_t first_pfn;
 };
+typedef struct xen_dm_op_track_dirty_vram xen_dm_op_track_dirty_vram_t;
 
 /*
  * XEN_DMOP_set_pci_intx_level: Set the logical level of one of a domain's
@@ -217,6 +223,7 @@ struct xen_dm_op_set_pci_intx_level {
     /* IN - Level: 0 -> deasserted, 1 -> asserted */
     uint8_t  level;
 };
+typedef struct xen_dm_op_set_pci_intx_level xen_dm_op_set_pci_intx_level_t;
 
 /*
  * XEN_DMOP_set_isa_irq_level: Set the logical level of a one of a domain's
@@ -230,6 +237,7 @@ struct xen_dm_op_set_isa_irq_level {
     /* IN - Level: 0 -> deasserted, 1 -> asserted */
     uint8_t  level;
 };
+typedef struct xen_dm_op_set_isa_irq_level xen_dm_op_set_isa_irq_level_t;
 
 /*
  * XEN_DMOP_set_pci_link_route: Map a PCI INTx line to an IRQ line.
@@ -242,6 +250,7 @@ struct xen_dm_op_set_pci_link_route {
     /* ISA IRQ (1-15) or 0 -> disable link */
     uint8_t  isa_irq;
 };
+typedef struct xen_dm_op_set_pci_link_route xen_dm_op_set_pci_link_route_t;
 
 /*
  * XEN_DMOP_modified_memory: Notify that a set of pages were modified by
@@ -265,6 +274,7 @@ struct xen_dm_op_modified_memory {
     /* IN/OUT - Must be set to 0 */
     uint32_t opaque;
 };
+typedef struct xen_dm_op_modified_memory xen_dm_op_modified_memory_t;
 
 struct xen_dm_op_modified_memory_extent {
     /* IN - number of contiguous pages modified */
@@ -294,6 +304,7 @@ struct xen_dm_op_set_mem_type {
     /* IN - first pfn in region */
     uint64_aligned_t first_pfn;
 };
+typedef struct xen_dm_op_set_mem_type xen_dm_op_set_mem_type_t;
 
 /*
  * XEN_DMOP_inject_event: Inject an event into a VCPU, which will
@@ -327,6 +338,7 @@ struct xen_dm_op_inject_event {
     /* IN - type-specific extra data (%cr2 for #PF, pending_dbg for #DB) */
     uint64_aligned_t cr2;
 };
+typedef struct xen_dm_op_inject_event xen_dm_op_inject_event_t;
 
 /*
  * XEN_DMOP_inject_msi: Inject an MSI for an emulated device.
@@ -340,6 +352,7 @@ struct xen_dm_op_inject_msi {
     /* IN - MSI address (0xfeexxxxx) */
     uint64_aligned_t addr;
 };
+typedef struct xen_dm_op_inject_msi xen_dm_op_inject_msi_t;
 
 /*
  * XEN_DMOP_map_mem_type_to_ioreq_server : map or unmap the IOREQ Server <id>
@@ -366,6 +379,7 @@ struct xen_dm_op_map_mem_type_to_ioreq_server {
     uint64_t opaque;    /* IN/OUT - only used for hypercall continuation,
                            has to be set to zero by the caller */
 };
+typedef struct xen_dm_op_map_mem_type_to_ioreq_server xen_dm_op_map_mem_type_to_ioreq_server_t;
 
 /*
  * XEN_DMOP_remote_shutdown : Declare a shutdown for another domain
@@ -377,6 +391,7 @@ struct xen_dm_op_remote_shutdown {
     uint32_t reason;       /* SHUTDOWN_* => enum sched_shutdown_reason */
                            /* (Other reason values are not blocked) */
 };
+typedef struct xen_dm_op_remote_shutdown xen_dm_op_remote_shutdown_t;
 
 /*
  * XEN_DMOP_relocate_memory : Relocate GFNs for the specified guest.
@@ -395,6 +410,7 @@ struct xen_dm_op_relocate_memory {
     /* Starting GFN where GFNs should be relocated. */
     uint64_aligned_t dst_gfn;
 };
+typedef struct xen_dm_op_relocate_memory xen_dm_op_relocate_memory_t;
 
 /*
  * XEN_DMOP_pin_memory_cacheattr : Pin caching type of RAM space.
@@ -416,30 +432,30 @@ struct xen_dm_op_pin_memory_cacheattr {
     uint32_t type;          /* XEN_DMOP_MEM_CACHEATTR_* */
     uint32_t pad;
 };
+typedef struct xen_dm_op_pin_memory_cacheattr xen_dm_op_pin_memory_cacheattr_t;
 
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
     union {
-        struct xen_dm_op_create_ioreq_server create_ioreq_server;
-        struct xen_dm_op_get_ioreq_server_info get_ioreq_server_info;
-        struct xen_dm_op_ioreq_server_range map_io_range_to_ioreq_server;
-        struct xen_dm_op_ioreq_server_range unmap_io_range_from_ioreq_server;
-        struct xen_dm_op_set_ioreq_server_state set_ioreq_server_state;
-        struct xen_dm_op_destroy_ioreq_server destroy_ioreq_server;
-        struct xen_dm_op_track_dirty_vram track_dirty_vram;
-        struct xen_dm_op_set_pci_intx_level set_pci_intx_level;
-        struct xen_dm_op_set_isa_irq_level set_isa_irq_level;
-        struct xen_dm_op_set_pci_link_route set_pci_link_route;
-        struct xen_dm_op_modified_memory modified_memory;
-        struct xen_dm_op_set_mem_type set_mem_type;
-        struct xen_dm_op_inject_event inject_event;
-        struct xen_dm_op_inject_msi inject_msi;
-        struct xen_dm_op_map_mem_type_to_ioreq_server
-                map_mem_type_to_ioreq_server;
-        struct xen_dm_op_remote_shutdown remote_shutdown;
-        struct xen_dm_op_relocate_memory relocate_memory;
-        struct xen_dm_op_pin_memory_cacheattr pin_memory_cacheattr;
+        xen_dm_op_create_ioreq_server_t create_ioreq_server;
+        xen_dm_op_get_ioreq_server_info_t get_ioreq_server_info;
+        xen_dm_op_ioreq_server_range_t map_io_range_to_ioreq_server;
+        xen_dm_op_ioreq_server_range_t unmap_io_range_from_ioreq_server;
+        xen_dm_op_set_ioreq_server_state_t set_ioreq_server_state;
+        xen_dm_op_destroy_ioreq_server_t destroy_ioreq_server;
+        xen_dm_op_track_dirty_vram_t track_dirty_vram;
+        xen_dm_op_set_pci_intx_level_t set_pci_intx_level;
+        xen_dm_op_set_isa_irq_level_t set_isa_irq_level;
+        xen_dm_op_set_pci_link_route_t set_pci_link_route;
+        xen_dm_op_modified_memory_t modified_memory;
+        xen_dm_op_set_mem_type_t set_mem_type;
+        xen_dm_op_inject_event_t inject_event;
+        xen_dm_op_inject_msi_t inject_msi;
+        xen_dm_op_map_mem_type_to_ioreq_server_t map_mem_type_to_ioreq_server;
+        xen_dm_op_remote_shutdown_t remote_shutdown;
+        xen_dm_op_relocate_memory_t relocate_memory;
+        xen_dm_op_pin_memory_cacheattr_t pin_memory_cacheattr;
     } u;
 };
 
diff --git a/xen/include/public/hvm/hvm_vcpu.h b/xen/include/public/hvm/hvm_vcpu.h
index d21abf1885..661cf89e1e 100644
--- a/xen/include/public/hvm/hvm_vcpu.h
+++ b/xen/include/public/hvm/hvm_vcpu.h
@@ -69,6 +69,7 @@ struct vcpu_hvm_x86_32 {
 
     uint16_t pad2[3];
 };
+typedef struct vcpu_hvm_x86_32 xen_vcpu_hvm_x86_32_t;
 
 /*
  * The layout of the _ar fields of the segment registers is the
@@ -114,6 +115,7 @@ struct vcpu_hvm_x86_64 {
      * the 32-bit structure should be used instead.
      */
 };
+typedef struct vcpu_hvm_x86_64 xen_vcpu_hvm_x86_64_t;
 
 struct vcpu_hvm_context {
 #define VCPU_HVM_MODE_32B 0  /* 32bit fields of the structure will be used. */
@@ -124,8 +126,8 @@ struct vcpu_hvm_context {
 
     /* CPU registers. */
     union {
-        struct vcpu_hvm_x86_32 x86_32;
-        struct vcpu_hvm_x86_64 x86_64;
+        xen_vcpu_hvm_x86_32_t x86_32;
+        xen_vcpu_hvm_x86_64_t x86_64;
     } cpu_regs;
 };
 typedef struct vcpu_hvm_context vcpu_hvm_context_t;
diff --git a/xen/include/public/hypfs.h b/xen/include/public/hypfs.h
index 63a5df1629..2b7a66d68d 100644
--- a/xen/include/public/hypfs.h
+++ b/xen/include/public/hypfs.h
@@ -53,9 +53,10 @@ struct xen_hypfs_direntry {
     uint32_t content_len;      /* Current length of data. */
     uint32_t max_write_len;    /* Max. length for writes (0 if read-only). */
 };
+typedef struct xen_hypfs_direntry xen_hypfs_direntry_t;
 
 struct xen_hypfs_dirlistentry {
-    struct xen_hypfs_direntry e;
+    xen_hypfs_direntry_t e;
     /* Offset in bytes to next entry (0 == this is the last entry). */
     uint16_t off_next;
     /* Zero terminated entry name, possibly with some padding for alignment. */
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index 21057ed78e..21d483298e 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -604,7 +604,7 @@ struct xen_reserved_device_memory_map {
     XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer;
     /* IN */
     union {
-        struct physdev_pci_device pci;
+        physdev_pci_device_t pci;
     } dev;
 };
 typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t;
diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h
index aedb71d678..d271766ad0 100644
--- a/xen/include/public/physdev.h
+++ b/xen/include/public/physdev.h
@@ -229,11 +229,11 @@ DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_ext_t);
 struct physdev_op {
     uint32_t cmd;
     union {
-        struct physdev_irq_status_query      irq_status_query;
-        struct physdev_set_iopl              set_iopl;
-        struct physdev_set_iobitmap          set_iobitmap;
-        struct physdev_apic                  apic_op;
-        struct physdev_irq                   irq_op;
+        physdev_irq_status_query_t irq_status_query;
+        physdev_set_iopl_t         set_iopl;
+        physdev_set_iobitmap_t     set_iobitmap;
+        physdev_apic_t             apic_op;
+        physdev_irq_t              irq_op;
     } u;
 };
 typedef struct physdev_op physdev_op_t;
@@ -334,7 +334,7 @@ struct physdev_dbgp_op {
     uint8_t op;
     uint8_t bus;
     union {
-        struct physdev_pci_device pci;
+        physdev_pci_device_t pci;
     } u;
 };
 typedef struct physdev_dbgp_op physdev_dbgp_op_t;
diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h
index f3c84ebc78..a4c0eb6224 100644
--- a/xen/include/public/platform.h
+++ b/xen/include/public/platform.h
@@ -42,6 +42,7 @@ struct xenpf_settime32 {
     uint32_t nsecs;
     uint64_t system_time;
 };
+typedef struct xenpf_settime32 xenpf_settime32_t;
 #define XENPF_settime64           62
 struct xenpf_settime64 {
     /* IN variables. */
@@ -50,6 +51,7 @@ struct xenpf_settime64 {
     uint32_t mbz;
     uint64_t system_time;
 };
+typedef struct xenpf_settime64 xenpf_settime64_t;
 #if __XEN_INTERFACE_VERSION__ < 0x00040600
 #define XENPF_settime XENPF_settime32
 #define xenpf_settime xenpf_settime32
@@ -529,6 +531,7 @@ struct xenpf_cpu_hotadd
 	uint32_t acpi_id;
 	uint32_t pxm;
 };
+typedef struct xenpf_cpu_hotadd xenpf_cpu_hotadd_t;
 
 #define XENPF_mem_hotadd    59
 struct xenpf_mem_hotadd
@@ -538,6 +541,7 @@ struct xenpf_mem_hotadd
     uint32_t pxm;
     uint32_t flags;
 };
+typedef struct xenpf_mem_hotadd xenpf_mem_hotadd_t;
 
 #define XENPF_core_parking  60
 
@@ -622,29 +626,29 @@ struct xen_platform_op {
     uint32_t cmd;
     uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
     union {
-        struct xenpf_settime           settime;
-        struct xenpf_settime32         settime32;
-        struct xenpf_settime64         settime64;
-        struct xenpf_add_memtype       add_memtype;
-        struct xenpf_del_memtype       del_memtype;
-        struct xenpf_read_memtype      read_memtype;
-        struct xenpf_microcode_update  microcode;
-        struct xenpf_platform_quirk    platform_quirk;
-        struct xenpf_efi_runtime_call  efi_runtime_call;
-        struct xenpf_firmware_info     firmware_info;
-        struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
-        struct xenpf_change_freq       change_freq;
-        struct xenpf_getidletime       getidletime;
-        struct xenpf_set_processor_pminfo set_pminfo;
-        struct xenpf_pcpuinfo          pcpu_info;
-        struct xenpf_pcpu_version      pcpu_version;
-        struct xenpf_cpu_ol            cpu_ol;
-        struct xenpf_cpu_hotadd        cpu_add;
-        struct xenpf_mem_hotadd        mem_add;
-        struct xenpf_core_parking      core_parking;
-        struct xenpf_resource_op       resource_op;
-        struct xenpf_symdata           symdata;
-        uint8_t                        pad[128];
+        xenpf_settime_t               settime;
+        xenpf_settime32_t             settime32;
+        xenpf_settime64_t             settime64;
+        xenpf_add_memtype_t           add_memtype;
+        xenpf_del_memtype_t           del_memtype;
+        xenpf_read_memtype_t          read_memtype;
+        xenpf_microcode_update_t      microcode;
+        xenpf_platform_quirk_t        platform_quirk;
+        xenpf_efi_runtime_call_t      efi_runtime_call;
+        xenpf_firmware_info_t         firmware_info;
+        xenpf_enter_acpi_sleep_t      enter_acpi_sleep;
+        xenpf_change_freq_t           change_freq;
+        xenpf_getidletime_t           getidletime;
+        xenpf_set_processor_pminfo_t  set_pminfo;
+        xenpf_pcpuinfo_t              pcpu_info;
+        xenpf_pcpu_version_t          pcpu_version;
+        xenpf_cpu_ol_t                cpu_ol;
+        xenpf_cpu_hotadd_t            cpu_add;
+        xenpf_mem_hotadd_t            mem_add;
+        xenpf_core_parking_t          core_parking;
+        xenpf_resource_op_t           resource_op;
+        xenpf_symdata_t               symdata;
+        uint8_t                       pad[128];
     } u;
 };
 typedef struct xen_platform_op xen_platform_op_t;
diff --git a/xen/include/public/pmu.h b/xen/include/public/pmu.h
index 0e1312cfe5..cc2fcf8816 100644
--- a/xen/include/public/pmu.h
+++ b/xen/include/public/pmu.h
@@ -127,7 +127,7 @@ struct xen_pmu_data {
     uint8_t pad[6];
 
     /* Architecture-specific information */
-    struct xen_pmu_arch pmu;
+    xen_pmu_arch_t pmu;
 };
 
 #endif /* __XEN_PUBLIC_PMU_H__ */
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 945ef30273..e373592c33 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -726,7 +726,7 @@ struct vcpu_info {
 #endif /* XEN_HAVE_PV_UPCALL_MASK */
     xen_ulong_t evtchn_pending_sel;
     struct arch_vcpu_info arch;
-    struct vcpu_time_info time;
+    vcpu_time_info_t time;
 }; /* 64 bytes (x86) */
 #ifndef __XEN__
 typedef struct vcpu_info vcpu_info_t;
@@ -1031,6 +1031,7 @@ struct xenctl_bitmap {
     XEN_GUEST_HANDLE_64(uint8) bitmap;
     uint32_t nr_bits;
 };
+typedef struct xenctl_bitmap xenctl_bitmap_t;
 #endif
 
 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
diff --git a/xen/include/public/xsm/flask_op.h b/xen/include/public/xsm/flask_op.h
index 970ec07f0b..16af7bc22f 100644
--- a/xen/include/public/xsm/flask_op.h
+++ b/xen/include/public/xsm/flask_op.h
@@ -33,10 +33,12 @@ struct xen_flask_load {
     XEN_GUEST_HANDLE(char) buffer;
     uint32_t size;
 };
+typedef struct xen_flask_load xen_flask_load_t;
 
 struct xen_flask_setenforce {
     uint32_t enforcing;
 };
+typedef struct xen_flask_setenforce xen_flask_setenforce_t;
 
 struct xen_flask_sid_context {
     /* IN/OUT: sid to convert to/from string */
@@ -47,6 +49,7 @@ struct xen_flask_sid_context {
     uint32_t size;
     XEN_GUEST_HANDLE(char) context;
 };
+typedef struct xen_flask_sid_context xen_flask_sid_context_t;
 
 struct xen_flask_access {
     /* IN: access request */
@@ -60,6 +63,7 @@ struct xen_flask_access {
     uint32_t audit_deny;
     uint32_t seqno;
 };
+typedef struct xen_flask_access xen_flask_access_t;
 
 struct xen_flask_transition {
     /* IN: transition SIDs and class */
@@ -69,6 +73,7 @@ struct xen_flask_transition {
     /* OUT: new SID */
     uint32_t newsid;
 };
+typedef struct xen_flask_transition xen_flask_transition_t;
 
 #if __XEN_INTERFACE_VERSION__ < 0x00040800
 struct xen_flask_userlist {
@@ -106,11 +111,13 @@ struct xen_flask_boolean {
      */
     XEN_GUEST_HANDLE(char) name;
 };
+typedef struct xen_flask_boolean xen_flask_boolean_t;
 
 struct xen_flask_setavc_threshold {
     /* IN */
     uint32_t threshold;
 };
+typedef struct xen_flask_setavc_threshold xen_flask_setavc_threshold_t;
 
 struct xen_flask_hash_stats {
     /* OUT */
@@ -119,6 +126,7 @@ struct xen_flask_hash_stats {
     uint32_t buckets_total;
     uint32_t max_chain_len;
 };
+typedef struct xen_flask_hash_stats xen_flask_hash_stats_t;
 
 struct xen_flask_cache_stats {
     /* IN */
@@ -131,6 +139,7 @@ struct xen_flask_cache_stats {
     uint32_t reclaims;
     uint32_t frees;
 };
+typedef struct xen_flask_cache_stats xen_flask_cache_stats_t;
 
 struct xen_flask_ocontext {
     /* IN */
@@ -138,6 +147,7 @@ struct xen_flask_ocontext {
     uint32_t sid;
     uint64_t low, high;
 };
+typedef struct xen_flask_ocontext xen_flask_ocontext_t;
 
 struct xen_flask_peersid {
     /* IN */
@@ -145,12 +155,14 @@ struct xen_flask_peersid {
     /* OUT */
     uint32_t sid;
 };
+typedef struct xen_flask_peersid xen_flask_peersid_t;
 
 struct xen_flask_relabel {
     /* IN */
     uint32_t domid;
     uint32_t sid;
 };
+typedef struct xen_flask_relabel xen_flask_relabel_t;
 
 struct xen_flask_devicetree_label {
     /* IN */
@@ -158,6 +170,7 @@ struct xen_flask_devicetree_label {
     uint32_t length;
     XEN_GUEST_HANDLE(char) path;
 };
+typedef struct xen_flask_devicetree_label xen_flask_devicetree_label_t;
 
 struct xen_flask_op {
     uint32_t cmd;
@@ -188,26 +201,26 @@ struct xen_flask_op {
 #define FLASK_DEVICETREE_LABEL  25
     uint32_t interface_version; /* XEN_FLASK_INTERFACE_VERSION */
     union {
-        struct xen_flask_load load;
-        struct xen_flask_setenforce enforce;
+        xen_flask_load_t load;
+        xen_flask_setenforce_t enforce;
         /* FLASK_CONTEXT_TO_SID and FLASK_SID_TO_CONTEXT */
-        struct xen_flask_sid_context sid_context;
-        struct xen_flask_access access;
+        xen_flask_sid_context_t sid_context;
+        xen_flask_access_t access;
         /* FLASK_CREATE, FLASK_RELABEL, FLASK_MEMBER */
-        struct xen_flask_transition transition;
+        xen_flask_transition_t transition;
 #if __XEN_INTERFACE_VERSION__ < 0x00040800
         struct xen_flask_userlist userlist;
 #endif
         /* FLASK_GETBOOL, FLASK_SETBOOL */
-        struct xen_flask_boolean boolean;
-        struct xen_flask_setavc_threshold setavc_threshold;
-        struct xen_flask_hash_stats hash_stats;
-        struct xen_flask_cache_stats cache_stats;
+        xen_flask_boolean_t boolean;
+        xen_flask_setavc_threshold_t setavc_threshold;
+        xen_flask_hash_stats_t hash_stats;
+        xen_flask_cache_stats_t cache_stats;
         /* FLASK_ADD_OCONTEXT, FLASK_DEL_OCONTEXT */
-        struct xen_flask_ocontext ocontext;
-        struct xen_flask_peersid peersid;
-        struct xen_flask_relabel relabel;
-        struct xen_flask_devicetree_label devicetree_label;
+        xen_flask_ocontext_t ocontext;
+        xen_flask_peersid_t peersid;
+        xen_flask_relabel_t relabel;
+        xen_flask_devicetree_label_t devicetree_label;
     } u;
 };
 typedef struct xen_flask_op xen_flask_op_t;
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index b85c43f13f..ca706ce353 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -3,7 +3,7 @@
 import re,sys
 
 pats = [
- [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ],
+ [ r"__InClUdE__(.*)", r"#include\1" ],
  [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ],
  [ r"__ElSe__", r"#else" ],
  [ r"__EnDif__", r"#endif" ],
@@ -11,9 +11,11 @@ pats = [
  [ r"__UnDeF__", r"#undef" ],
  [ r"\"xen-compat.h\"", r"<public/xen-compat.h>" ],
  [ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ],
- [ r"@KeeP@", r"" ],
+ [ r"typedef(.*)@KeeP@((xen_?)?)([\w]+)([^\w])",
+   r"typedef\1\2\4 __attribute__((__aligned__(__alignof(\1compat_\4))))\5" ],
  [ r"_t([^\w]|$)", r"_compat_t\1" ],
- [ r"(8|16|32|64)_compat_t([^\w]|$)", r"\1_t\2" ],
+ [ r"int(8|16|32|64_aligned)_compat_t([^\w]|$)", r"int\1_t\2" ],
+ [ r"(\su?int64(_compat)?)_T([^\w]|$)", r"\1_t\3" ],
  [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
  [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ],
  [ r"(^|[^\w])Xen_?", r"\1Compat_" ],
diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py
index c664eb85e6..fc10c7063f 100755
--- a/xen/tools/compat-build-source.py
+++ b/xen/tools/compat-build-source.py
@@ -9,6 +9,7 @@ pats = [
  [ r"^\s*#\s*endif /\* (XEN_HAVE.*) \*/\s+", r"__EnDif__" ],
  [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
  [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
+ [ r"^\s*#\s*define\s+(u?int64)_aligned_t\s.*aligned.*", r"typedef \1_T __attribute__((aligned(4))) \1_compat_T;" ],
  [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
 ];
 
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 45a0e2ed50..002db2093f 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -418,6 +418,21 @@ check_field ()
 			"}")
 				level=$(expr $level - 1) id=
 				;;
+			compat_*_t)
+				if [ $level = 2 ]
+				then
+					fields=" "
+					token="${token%_t}"
+					token="${token#compat_}"
+				fi
+				;;
+			evtchn_*_compat_t)
+				if [ $level = 2 -a $token != evtchn_port_compat_t ]
+				then
+					fields=" "
+					token="${token%_compat_t}"
+				fi
+				;;
 			[a-zA-Z]*)
 				id=$token
 				;;
@@ -464,6 +479,14 @@ build_check ()
 		"]")
 			arrlvl=$(expr $arrlvl - 1)
 			;;
+		compat_*_t)
+			if [ $level = 2 -a $token != compat_argo_port_t ]
+			then
+				fields=" "
+				token="${token%_t}"
+				token="${token#compat_}"
+			fi
+			;;
 		[a-zA-Z_]*)
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7vk-0002vn-Im; Fri, 04 Sep 2020 09:22:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7vj-0002vY-3G
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:47 +0000
X-Inumbo-ID: d5c3d76a-1941-47e6-bcc5-85ca25633589
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d5c3d76a-1941-47e6-bcc5-85ca25633589;
 Fri, 04 Sep 2020 09:22:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2HlkN0YrpOSOBZY+9HT6eQVe6TXQN6gnZhXmHnl9DAI=; b=DBlt7CHo4lzBJ7riPV+gnyIfda
 fQOj3whT9lHljzwFwRccRhhavYtM3fIPmnLAE+45zjwJtn/kY2mBFVi1okbbCLBz1NZtU6i96raLO
 V7mmNw1duMjgCa9pE97phRc4XupszfRrdHAz07FOO+3EYQg9t3VYj4oLG8jbwcZRmAFg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vi-00007W-5W
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vi-0001bn-3p
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/mce: add compat struct checking for XEN_MC_inject_v2
Message-Id: <E1kE7vi-0001bn-3p@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9d207b88ff208ad829822a4f1da9d8ab020ef263
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:06:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:06:56 2020 +0200

    x86/mce: add compat struct checking for XEN_MC_inject_v2
    
    84e364f2eda2 ("x86: add CMCI software injection interface") merely made
    sure things would build, without any concern about things actually
    working:
    - despite the addition of xenctl_bitmap to xlat.lst, the resulting macro
      wasn't invoked anywhere (which would have lead to recognizing that the
      structure appeared to have no fully compatible layout, despite the use
      of a 64-bit handle),
    - the interface struct itself was neither added to xlat.lst (and the
      resulting macro then invoked) nor was any manual checking of
      individual fields added.
    
    Adjust compat header generation logic to retain XEN_GUEST_HANDLE_64(),
    which is intentionally layed out to be compatible between different size
    guests. Invoke the missing checking (implicitly through CHECK_mc).
    
    No change in the resulting generated code.
    
    Fixes: 84e364f2eda2 ("x86: add CMCI software injection interface")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/cpu/mcheck/mce.c         | 4 +++-
 xen/include/public/arch-x86/xen-mca.h | 3 ++-
 xen/include/xlat.lst                  | 1 +
 xen/tools/compat-build-header.py      | 1 +
 xen/tools/compat-build-source.py      | 2 +-
 5 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index fe9667e0c3..5ec16fab87 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1312,10 +1312,12 @@ CHECK_FIELD_(struct, mc_fetch, fetch_id);
 CHECK_FIELD_(struct, mc_physcpuinfo, ncpus);
 # define CHECK_compat_mc_physcpuinfo struct mc_physcpuinfo
 
-#define CHECK_compat_mc_inject_v2   struct mc_inject_v2
+# define xen_ctl_bitmap              xenctl_bitmap
+
 CHECK_mc;
 # undef CHECK_compat_mc_fetch
 # undef CHECK_compat_mc_physcpuinfo
+# undef xen_ctl_bitmap
 
 # define xen_mc_info                 mc_info
 CHECK_mc_info;
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index 702998b0eb..628b79e22a 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -429,6 +429,7 @@ struct xen_mc_inject_v2 {
     uint32_t flags;
     xenctl_bitmap_t cpumap;
 };
+typedef struct xen_mc_inject_v2 xen_mc_inject_v2_t;
 #endif
 
 struct xen_mc {
@@ -441,7 +442,7 @@ struct xen_mc {
         xen_mc_msrinject_t         mc_msrinject;
         xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
-        struct xen_mc_inject_v2    mc_inject_v2;
+        xen_mc_inject_v2_t         mc_inject_v2;
 #endif
     } u;
 };
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 20d4dccce6..1eb28dbe66 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -44,6 +44,7 @@
 ?	mcinfo_recovery			arch-x86/xen-mca.h
 !	mc_fetch			arch-x86/xen-mca.h
 ?	mc_info				arch-x86/xen-mca.h
+?	mc_inject_v2			arch-x86/xen-mca.h
 ?	mc_mceinject			arch-x86/xen-mca.h
 ?	mc_msrinject			arch-x86/xen-mca.h
 ?	mc_notifydomain			arch-x86/xen-mca.h
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index ca706ce353..065d3b1b6e 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -19,6 +19,7 @@ pats = [
  [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
  [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ],
  [ r"(^|[^\w])Xen_?", r"\1Compat_" ],
+ [ r"(^|[^\w])COMPAT_HANDLE_64\(", r"\1XEN_GUEST_HANDLE_64(" ],
  [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ]
 ];
 
diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py
index fc10c7063f..2bcaf27d05 100755
--- a/xen/tools/compat-build-source.py
+++ b/xen/tools/compat-build-source.py
@@ -10,7 +10,7 @@ pats = [
  [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
  [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
  [ r"^\s*#\s*define\s+(u?int64)_aligned_t\s.*aligned.*", r"typedef \1_T __attribute__((aligned(4))) \1_compat_T;" ],
- [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
+ [ r"XEN_GUEST_HANDLE", r"COMPAT_HANDLE" ],
 ];
 
 xlatf = open('xlat.lst', 'r')
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:22:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:22:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7vv-0002xT-KO; Fri, 04 Sep 2020 09:22:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7vt-0002xE-RS
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:57 +0000
X-Inumbo-ID: 64cf948e-66b3-43ad-ae1c-d4c99eadd6ae
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 64cf948e-66b3-43ad-ae1c-d4c99eadd6ae;
 Fri, 04 Sep 2020 09:22:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=OpqSLD6cVThfv1w09oLtw6XfMYXwvdfq4jJDqSdzJZA=; b=ole2RvA794h6Da6FwvTIV75lqO
 uj455F9TQ6exm14zUMXN7qO0N2Nom8uHlgOeIlSy/6YR+mcmGYGIBSGQ4M+I8n9yxyYGzEoPubZGU
 ld9mGOsotMlyckaJ9DfG5DRU6OIYHay+U/w1N0S8DxV7wkChfY3XefYoPd7s/5EeZT3s=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vs-00007j-8z
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7vs-0001ce-8A
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:22:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/mce: bring hypercall subop compat checking in sync
 again
Message-Id: <E1kE7vs-0001ce-8A@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:22:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7dcd33d562ee8a8177c843f42721d5345f796fe8
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:07:47 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:07:47 2020 +0200

    x86/mce: bring hypercall subop compat checking in sync again
    
    Use a typedef in struct xen_mc also for the two subops "manually"
    translated in the handler, just for consistency. No functional
    change.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/cpu/mcheck/mce.c         | 8 ++++----
 xen/include/public/arch-x86/xen-mca.h | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index 5ec16fab87..0e84368ae2 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1307,16 +1307,16 @@ CHECK_mcinfo_common;
 
 CHECK_FIELD_(struct, mc_fetch, flags);
 CHECK_FIELD_(struct, mc_fetch, fetch_id);
-# define CHECK_compat_mc_fetch       struct mc_fetch
+# define CHECK_mc_fetch              struct mc_fetch
 
 CHECK_FIELD_(struct, mc_physcpuinfo, ncpus);
-# define CHECK_compat_mc_physcpuinfo struct mc_physcpuinfo
+# define CHECK_mc_physcpuinfo        struct mc_physcpuinfo
 
 # define xen_ctl_bitmap              xenctl_bitmap
 
 CHECK_mc;
-# undef CHECK_compat_mc_fetch
-# undef CHECK_compat_mc_physcpuinfo
+# undef CHECK_mc_fetch
+# undef CHECK_mc_physcpuinfo
 # undef xen_ctl_bitmap
 
 # define xen_mc_info                 mc_info
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index 628b79e22a..d930c344c0 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -391,6 +391,7 @@ struct xen_mc_physcpuinfo {
     /* OUT */
     XEN_GUEST_HANDLE(xen_mc_logical_cpu_t) info;
 };
+typedef struct xen_mc_physcpuinfo xen_mc_physcpuinfo_t;
 
 #define XEN_MC_msrinject    4
 #define MC_MSRINJ_MAXMSRS       8
@@ -436,9 +437,9 @@ struct xen_mc {
     uint32_t cmd;
     uint32_t interface_version; /* XEN_MCA_INTERFACE_VERSION */
     union {
-        struct xen_mc_fetch        mc_fetch;
+        xen_mc_fetch_t             mc_fetch;
         xen_mc_notifydomain_t      mc_notifydomain;
-        struct xen_mc_physcpuinfo  mc_physcpuinfo;
+        xen_mc_physcpuinfo_t       mc_physcpuinfo;
         xen_mc_msrinject_t         mc_msrinject;
         xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:23:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:23:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7w4-0002yP-M2; Fri, 04 Sep 2020 09:23:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7w3-0002yH-6b
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:07 +0000
X-Inumbo-ID: e24d76cf-540e-4f33-beb2-fb793eec852a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e24d76cf-540e-4f33-beb2-fb793eec852a;
 Fri, 04 Sep 2020 09:23:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=XqAcJdDYzTHFvO9vb4163OIwJh6DBQpVjfnm3rY4MK8=; b=6mROWEMJOoPmcjZyQwZisO+q2g
 8Rr2cv76LUl4zARxFD5RXMM+Xsz1zoNHMrpuDsVDRo/ddUfNFmaXqQf02Z0lfAQB8Yck2saXvAdrR
 c1DF9DgwaonQKOB4YHMlbslk5zzcQw3fMp+cFHMBmR9RH0mekWCKeivKF+C+eUhtsdY8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7w2-00008H-Cr
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7w2-0001dG-Bg
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/dmop: add compat struct checking for
 XEN_DMOP_map_mem_type_to_ioreq_server
Message-Id: <E1kE7w2-0001dG-Bg@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:23:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4d7bcd128f11dff49b0fd8eb367a3c546a8e38af
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:08:40 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:08:40 2020 +0200

    x86/dmop: add compat struct checking for XEN_DMOP_map_mem_type_to_ioreq_server
    
    This was forgotten when the subop was added.
    
    Also take the opportunity and move the dm_op_relocate_memory entry in
    xlat.lst to its designated place.
    
    No change in the resulting generated code.
    
    Fixes: ca2b511d3ff4 ("x86/ioreq server: add DMOP to map guest ram with p2m_ioreq_server to an ioreq server")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/hvm/dm.c | 1 +
 xen/include/xlat.lst  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 9930d68860..cf3787d9ff 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -731,6 +731,7 @@ CHECK_dm_op_modified_memory;
 CHECK_dm_op_set_mem_type;
 CHECK_dm_op_inject_event;
 CHECK_dm_op_inject_msi;
+CHECK_dm_op_map_mem_type_to_ioreq_server;
 CHECK_dm_op_remote_shutdown;
 CHECK_dm_op_relocate_memory;
 CHECK_dm_op_pin_memory_cacheattr;
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 1eb28dbe66..bab3a9bad1 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -86,15 +86,16 @@
 ?	grant_entry_v2			grant_table.h
 ?	gnttab_swap_grant_ref		grant_table.h
 !	dm_op_buf			hvm/dm_op.h
-?	dm_op_relocate_memory		hvm/dm_op.h
 ?	dm_op_create_ioreq_server	hvm/dm_op.h
 ?	dm_op_destroy_ioreq_server	hvm/dm_op.h
 ?	dm_op_get_ioreq_server_info	hvm/dm_op.h
 ?	dm_op_inject_event		hvm/dm_op.h
 ?	dm_op_inject_msi		hvm/dm_op.h
 ?	dm_op_ioreq_server_range	hvm/dm_op.h
+?	dm_op_map_mem_type_to_ioreq_server hvm/dm_op.h
 ?	dm_op_modified_memory		hvm/dm_op.h
 ?	dm_op_pin_memory_cacheattr	hvm/dm_op.h
+?	dm_op_relocate_memory		hvm/dm_op.h
 ?	dm_op_remote_shutdown		hvm/dm_op.h
 ?	dm_op_set_ioreq_server_state	hvm/dm_op.h
 ?	dm_op_set_isa_irq_level		hvm/dm_op.h
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:23:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:23:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7wE-0002zS-Nb; Fri, 04 Sep 2020 09:23:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7wD-0002zH-9H
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:17 +0000
X-Inumbo-ID: 1e572164-38eb-4d4e-8b27-d6af483df0fc
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1e572164-38eb-4d4e-8b27-d6af483df0fc;
 Fri, 04 Sep 2020 09:23:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rW2PEkV+zKGxEzthP6vdQ/J6NSt1RabrK4dESlyz9RI=; b=avwl5LtpB23k73qcPwL/82YccU
 +GG762nt35tGg9YsP9iBtxlaxxaXKdJYHwXvua7WdkMTLAoCjLOb7pHAhqHRXEHyLH1Zg3DOEq7n2
 IfALCKL9JxEHYb0RlGBOnpenVebdAzaSUMEF7197/R2sFpobLaUxsgG8PlBPAlrogO1g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wC-00008V-GI
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wC-0001di-FS
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: add compat struct checking for newer sub-ops
Message-Id: <E1kE7wC-0001di-FS@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:23:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a609b6577f7867db4be1470130b7b3c686398c4f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:11:35 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:11:35 2020 +0200

    evtchn: add compat struct checking for newer sub-ops
    
    Various additions to the interface did not get mirrored into the compat
    handling machinery. Luckily all additions were done in ways not making
    any form of translation necessary.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/common/compat/xlat.c | 16 ++++++++++++++++
 xen/include/xlat.lst     |  4 ++++
 2 files changed, 20 insertions(+)

diff --git a/xen/common/compat/xlat.c b/xen/common/compat/xlat.c
index ffc8f8f50e..e21f032413 100644
--- a/xen/common/compat/xlat.c
+++ b/xen/common/compat/xlat.c
@@ -54,6 +54,22 @@ CHECK_evtchn_op;
 #undef xen_evtchn_status
 #undef xen_evtchn_unmask
 
+#define xen_evtchn_expand_array evtchn_expand_array
+CHECK_evtchn_expand_array;
+#undef xen_evtchn_expand_array
+
+#define xen_evtchn_init_control evtchn_init_control
+CHECK_evtchn_init_control;
+#undef xen_evtchn_init_control
+
+#define xen_evtchn_reset evtchn_reset
+CHECK_evtchn_reset;
+#undef xen_evtchn_reset
+
+#define xen_evtchn_set_priority evtchn_set_priority
+CHECK_evtchn_set_priority;
+#undef xen_evtchn_set_priority
+
 #define xen_mmu_update mmu_update
 CHECK_mmu_update;
 #undef xen_mmu_update
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index bab3a9bad1..57a17a2b62 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -66,8 +66,12 @@
 ?	evtchn_bind_vcpu		event_channel.h
 ?	evtchn_bind_virq		event_channel.h
 ?	evtchn_close			event_channel.h
+?	evtchn_expand_array		event_channel.h
+?	evtchn_init_control		event_channel.h
 ?	evtchn_op			event_channel.h
+?	evtchn_reset			event_channel.h
 ?	evtchn_send			event_channel.h
+?	evtchn_set_priority		event_channel.h
 ?	evtchn_status			event_channel.h
 ?	evtchn_unmask			event_channel.h
 ?	gnttab_cache_flush		grant_table.h
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:23:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:23:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7wO-00030Q-PI; Fri, 04 Sep 2020 09:23:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7wN-00030G-HF
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:27 +0000
X-Inumbo-ID: 8552804a-4092-4a2c-867d-1ad0aa3aa86c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8552804a-4092-4a2c-867d-1ad0aa3aa86c;
 Fri, 04 Sep 2020 09:23:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=C7Ur/5zKl99To7rk65g6P0QWwtEFAKHejmhx1aICiBw=; b=sHd7ZyQTCFU3m9MssYTfU0GD+F
 lQKWTFUWXMMFdHIO89SDaEqiolnSoSOpdsBMmDwbysfuPw9H9CdJ1ZvAspAJOmBlGP81I6SkJ70PJ
 1yQdrEp0q3ddDNCPy7IPQpecxZMglv+FVTXwEyzLHnWVX14aP7PabR6HxKQF3xVgJibY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wM-00008f-K7
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wM-0001e6-Ip
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: generalize padding field handling
Message-Id: <E1kE7wM-0001e6-Ip@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:23:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 696c273f3d9a169911308fb7e0a702a3eb6a150d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:13:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:13:01 2020 +0200

    x86: generalize padding field handling
    
    The original intention was to ignore padding fields, but the pattern
    matched only ones whose names started with an underscore. Also match
    fields whose names are in line with the C spec by not having a leading
    underscore. (Note that the leading ^ in the sed regexps was pointless
    and hence get dropped.)
    
    This requires adjusting some vNUMA macros, to avoid triggering
    "enumeration value ... not handled in switch" warnings, which - due to
    -Werror - would cause the build to fail. (I have to admit that I find
    these padding fields odd, when translation of the containing structure
    is needed anyway.)
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/common/compat/memory.c | 3 +++
 xen/tools/get-fields.sh    | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 3851f756c7..215b8f52d6 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -354,10 +354,13 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
                 return -EFAULT;
 
 #define XLAT_vnuma_topology_info_HNDL_vdistance_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vdistance_pad:                \
             guest_from_compat_handle((_d_)->vdistance.h, (_s_)->vdistance.h)
 #define XLAT_vnuma_topology_info_HNDL_vcpu_to_vnode_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vcpu_to_vnode_pad:            \
             guest_from_compat_handle((_d_)->vcpu_to_vnode.h, (_s_)->vcpu_to_vnode.h)
 #define XLAT_vnuma_topology_info_HNDL_vmemrange_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vmemrange_pad:                \
             guest_from_compat_handle((_d_)->vmemrange.h, (_s_)->vmemrange.h)
 
             XLAT_vnuma_topology_info(nat.vnuma, &cmp.vnuma);
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 002db2093f..753e37eb2e 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -218,7 +218,7 @@ for line in sys.stdin.readlines():
 				fi
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 				then
 					if [ $kind = union ]
 					then
@@ -347,7 +347,7 @@ build_body ()
 			fi
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 			then
 				if [ -z "$array" -a -z "$array_type" ]
 				then
@@ -437,7 +437,7 @@ check_field ()
 				id=$token
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 				then
 					check_field $1 $2 $3.$id "$fields"
 					test "$token" != ";" || fields= id=
@@ -491,7 +491,7 @@ build_check ()
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 			then
 				check_field $kind $1 $id "$fields"
 				test "$token" != ";" || fields= id=
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:23:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:23:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7wZ-00031a-Qv; Fri, 04 Sep 2020 09:23:39 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7wY-00031P-F4
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:38 +0000
X-Inumbo-ID: a41eac9d-dd47-42fb-94fb-99db024a22d2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a41eac9d-dd47-42fb-94fb-99db024a22d2;
 Fri, 04 Sep 2020 09:23:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Y6umMvoBadTWSzp+Na/fB5kiGLzSknUGooxINnGoZkA=; b=4Er4mcvtcCB03WGHk2qP+edCyb
 NloAVRESgDT0XMLIVAsxcl/BpgpNxKVE+Oe8Sw0y5ilz/y+NCsPJV+nr5Hcryyha4g3kupQbvVbtw
 CaaS4kH84JfvPRukjWm/lDMbKM5FLGY9v/3gBV4DiUi2i1IMzbCP9vSNBuOt4u19tGEo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wW-00008n-NS
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wW-0001ea-Me
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] flask: drop dead compat translation code
Message-Id: <E1kE7wW-0001ea-Me@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:23:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7dcf89d9ec96254f69744ab6d91e8af13f4cda83
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:14:28 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:14:28 2020 +0200

    flask: drop dead compat translation code
    
    Translation macros aren't used (and hence needed) at all (or else a
    devicetree_label entry would have been missing), and userlist has been
    removed quite some time ago.
    
    No functional change.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/xlat.lst     | 3 ---
 xen/xsm/flask/flask_op.c | 2 --
 2 files changed, 5 deletions(-)

diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 57a17a2b62..398993d5f4 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -171,14 +171,11 @@
 ?	xenoprof_init			xenoprof.h
 ?	xenoprof_passive		xenoprof.h
 ?	flask_access			xsm/flask_op.h
-!	flask_boolean			xsm/flask_op.h
 ?	flask_cache_stats		xsm/flask_op.h
 ?	flask_hash_stats		xsm/flask_op.h
-!	flask_load			xsm/flask_op.h
 ?	flask_ocontext			xsm/flask_op.h
 ?	flask_peersid			xsm/flask_op.h
 ?	flask_relabel			xsm/flask_op.h
 ?	flask_setavc_threshold		xsm/flask_op.h
 ?	flask_setenforce		xsm/flask_op.h
-!	flask_sid_context		xsm/flask_op.h
 ?	flask_transition		xsm/flask_op.h
diff --git a/xen/xsm/flask/flask_op.c b/xen/xsm/flask/flask_op.c
index a5f2b104e2..01e52138a1 100644
--- a/xen/xsm/flask/flask_op.c
+++ b/xen/xsm/flask/flask_op.c
@@ -790,8 +790,6 @@ CHECK_flask_transition;
 #define xen_flask_load compat_flask_load
 #define flask_security_load compat_security_load
 
-#define xen_flask_userlist compat_flask_userlist
-
 #define xen_flask_sid_context compat_flask_sid_context
 #define flask_security_context compat_security_context
 #define flask_security_sid compat_security_sid
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 09:23:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 09:23:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE7wj-00032m-Th; Fri, 04 Sep 2020 09:23:49 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE7wh-00032Z-QU
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:47 +0000
X-Inumbo-ID: fc5b80b0-8646-457a-a32c-c21198c2e27b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id fc5b80b0-8646-457a-a32c-c21198c2e27b;
 Fri, 04 Sep 2020 09:23:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=qH3wJylSOdgq9ZJrcB5RGaNnYunhDxLztCNBt3jgs5o=; b=RDK9yFoAC+cHx4Hl6t7cAVy7Zy
 EtwuGNbpnVuhIREmEfX6cUUMlJXyiZVTpCO3zRfr72i/be+BBmKmhitsjUqpEUdN76qV0Srsm7LWD
 V3zalmI/GkvEH4SU7+AlJoPSISnxyPHykK6IFJJVPGPEX8H/saXxq9s226wzQeBRk9Nw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wg-00009K-RV
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE7wg-0001fI-QN
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 09:23:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: only generate compat headers actually needed
Message-Id: <E1kE7wg-0001fI-QN@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 09:23:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2c8fabb2232d34d6d20a9ce6989e2e6cbee07d52
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:15:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:15:21 2020 +0200

    x86: only generate compat headers actually needed
    
    As was already the case for XSM/Flask, avoid generating compat headers
    when they're not going to be needed. To address resulting build issues
    - move compat/hvm/dm_op.h inclusion to the only source file needing it,
    - add a little bit of #ifdef-ary.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/hvm/dm.c       |  2 ++
 xen/common/compat/domain.c  |  9 ++++++++-
 xen/include/Makefile        | 24 +++++++++++++-----------
 xen/include/xen/hypercall.h |  2 --
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index cf3787d9ff..71f5ca4941 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -718,6 +718,8 @@ static int dm_op(const struct dmop_args *op_args)
     return rc;
 }
 
+#include <compat/hvm/dm_op.h>
+
 CHECK_dm_op_create_ioreq_server;
 CHECK_dm_op_get_ioreq_server_info;
 CHECK_dm_op_ioreq_server_range;
diff --git a/xen/common/compat/domain.c b/xen/common/compat/domain.c
index 11c6afc463..98b8c15cea 100644
--- a/xen/common/compat/domain.c
+++ b/xen/common/compat/domain.c
@@ -11,7 +11,6 @@ EMIT_FILE;
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <compat/vcpu.h>
-#include <compat/hvm/hvm_vcpu.h>
 
 #define xen_vcpu_set_periodic_timer vcpu_set_periodic_timer
 CHECK_vcpu_set_periodic_timer;
@@ -25,6 +24,10 @@ CHECK_SIZE_(struct, vcpu_info);
 CHECK_vcpu_register_vcpu_info;
 #undef xen_vcpu_register_vcpu_info
 
+#ifdef CONFIG_HVM
+
+#include <compat/hvm/hvm_vcpu.h>
+
 #define xen_vcpu_hvm_context vcpu_hvm_context
 #define xen_vcpu_hvm_x86_32 vcpu_hvm_x86_32
 #define xen_vcpu_hvm_x86_64 vcpu_hvm_x86_64
@@ -33,6 +36,8 @@ CHECK_vcpu_hvm_context;
 #undef xen_vcpu_hvm_x86_32
 #undef xen_vcpu_hvm_context
 
+#endif
+
 int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d = current->domain;
@@ -49,6 +54,7 @@ int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) ar
         if ( v->vcpu_info == &dummy_vcpu_info )
             return -EINVAL;
 
+#ifdef CONFIG_HVM
         if ( is_hvm_vcpu(v) )
         {
             struct vcpu_hvm_context ctxt;
@@ -61,6 +67,7 @@ int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) ar
             domain_unlock(d);
         }
         else
+#endif
         {
             struct compat_vcpu_guest_context *ctxt;
 
diff --git a/xen/include/Makefile b/xen/include/Makefile
index 0be5540886..5c2f57a0f6 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -3,32 +3,34 @@ ifneq ($(CONFIG_COMPAT),)
 compat-arch-$(CONFIG_X86) := x86_32
 
 headers-y := \
-    compat/argo.h \
-    compat/callback.h \
+    compat/arch-$(compat-arch-y).h \
     compat/elfnote.h \
     compat/event_channel.h \
     compat/features.h \
-    compat/grant_table.h \
-    compat/hypfs.h \
-    compat/kexec.h \
     compat/memory.h \
     compat/nmi.h \
     compat/physdev.h \
     compat/platform.h \
+    compat/pmu.h \
     compat/sched.h \
-    compat/trace.h \
     compat/vcpu.h \
     compat/version.h \
     compat/xen.h \
-    compat/xenoprof.h
+    compat/xlat.h
 headers-$(CONFIG_X86)     += compat/arch-x86/pmu.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-mca.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
-headers-$(CONFIG_X86)     += compat/hvm/dm_op.h
-headers-$(CONFIG_X86)     += compat/hvm/hvm_op.h
-headers-$(CONFIG_X86)     += compat/hvm/hvm_vcpu.h
-headers-y                 += compat/arch-$(compat-arch-y).h compat/pmu.h compat/xlat.h
+headers-$(CONFIG_ARGO)    += compat/argo.h
+headers-$(CONFIG_PV)      += compat/callback.h
+headers-$(CONFIG_GRANT_TABLE) += compat/grant_table.h
+headers-$(CONFIG_HVM)     += compat/hvm/dm_op.h
+headers-$(CONFIG_HVM)     += compat/hvm/hvm_op.h
+headers-$(CONFIG_HVM)     += compat/hvm/hvm_vcpu.h
+headers-$(CONFIG_HYPFS)   += compat/hypfs.h
+headers-$(CONFIG_KEXEC)   += compat/kexec.h
+headers-$(CONFIG_TRACEBUFFER) += compat/trace.h
+headers-$(CONFIG_XENOPROF) += compat/xenoprof.h
 headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h
 
 cppflags-y                := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS
diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h
index 655acc7f47..34b7f1fed6 100644
--- a/xen/include/xen/hypercall.h
+++ b/xen/include/xen/hypercall.h
@@ -216,8 +216,6 @@ extern long compat_argo_op(
     unsigned long arg4);
 #endif
 
-#include <compat/hvm/dm_op.h>
-
 extern int
 compat_dm_op(
     domid_t domid,
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 11:22:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 11:22:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kE9nD-0007yl-1h; Fri, 04 Sep 2020 11:22:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kE9nC-0007yf-K3
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 11:22:06 +0000
X-Inumbo-ID: 9b4e6064-2154-4d4f-aac3-8c9bcba00f23
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9b4e6064-2154-4d4f-aac3-8c9bcba00f23;
 Fri, 04 Sep 2020 11:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0iXwK6B7oERa+Fp51Ux7JbXKc5QiCPIK97HZVkF0eOg=; b=FzjRqHOipHGQKHZfYCyXV7n9eV
 ztFlOQ1V/gR/STTvSdMC/Ua8juwwNT6kDH4ZHn9RjxgpQ4gSVxDpTQ3U1/OV9uor6feXxFF/KyQY9
 3ycLVTh4uTsWMx+RbtqXcTqYha5Y88eaEvA2KwMxW1WNZx2E2nh78mA7z3vOQwk0FtS0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE9nB-0002ix-AO
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 11:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kE9nB-0000Yi-8I
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 11:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] fix build with make 3.81
Message-Id: <E1kE9nB-0000Yi-8I@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 11:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fc4b1cbd8d8d22c80dd8f2fc744287ab7c89c912
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Tue Sep 1 13:58:16 2020 +0200
Commit:     Ian Jackson <ian.jackson@eu.citrix.com>
CommitDate: Fri Sep 4 12:15:54 2020 +0100

    fix build with make 3.81
    
    make 3.81 doesn't support multiline variables defined with
    
     define var =
     ...
     endef
    
    Dropping the "=" in the first line will fix the issue.
    
    Fixes: ded08cdfa72bb ("tools: generate most contents of library make variables")
    Fixes: ddb2934a914df ("stubdom: add correct dependencies for Xen libraries")
    Reported-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 stubdom/Makefile | 2 +-
 tools/Rules.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index 4fd86dd44b..98eba8efe3 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -25,7 +25,7 @@ endif
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-define LIB_deps =
+define LIB_deps
  LIBDEPS_$(1) = $$(foreach use,$$(USELIBS_$(1)),libxen$$(use))
 endef
 $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_deps,$(lib))))
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 7e019a8a65..385807a71c 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -94,7 +94,7 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-define LIB_defs =
+define LIB_defs
  XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
  CFLAGS_libxen$(1) = -I$$(XEN_libxen$(1))/include $$(CFLAGS_xeninclude)
  SHDEPS_libxen$(1) = $$(foreach use,$$(USELIBS_$(1)),$$(SHLIB_libxen$$(use)))
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 14:44:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 14:44:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kECwh-00043v-Ip; Fri, 04 Sep 2020 14:44:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kECwg-00043q-Kj
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 14:44:06 +0000
X-Inumbo-ID: d6653c88-2647-4281-82c7-446011c0fa82
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d6653c88-2647-4281-82c7-446011c0fa82;
 Fri, 04 Sep 2020 14:44:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=WWI3gxxar6OnVarL1gNLcD2n8nGVyr9v0V79lEsLwJE=; b=U4C5ShlRR08X0bNnE4aM2ychm0
 6o1gmvn+oexEe1A3PA/TNVEzXaq6w61xz7WJD8bD6ZX3t+0qx7YZPDBPbupd5EgyjF20l2/I+SyUl
 TAE95erluo6XyRKfJhDhpzEz8Qnn+v0xl7kHHcy7EcbuJrZrgd/Vq532fSGQnJRRPk5c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kECwf-0006wp-ER
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 14:44:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kECwf-0005pL-Bz
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 14:44:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] Revert "libxl: Generate golang bindings in libxl
 Makefile"
Message-Id: <E1kECwf-0005pL-Bz@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 14:44:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ac7a21cf5c125810ee0193338a0f710cba0ab079
Author:     George Dunlap <george.dunlap@citrix.com>
AuthorDate: Fri Aug 28 15:33:37 2020 +0100
Commit:     George Dunlap <george.dunlap@citrix.com>
CommitDate: Fri Sep 4 15:38:56 2020 +0100

    Revert "libxl: Generate golang bindings in libxl Makefile"
    
    This reverts commit 60db5da62ac051aab0b217fa2d96acca1cd3ca3e.
    
    This is in preparation for the planned move to hosting the xenlight
    package in a separate repo.
    
    This also fixes a regression when building with a read-only source and
    an out-of-tree build.
    
    Signed-off-by: George Dunlap <george.dunlap@citrix.com>
    Acked-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/golang/xenlight/Makefile |  7 -------
 tools/libxl/Makefile           | 17 +----------------
 2 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
index a83fff7573..b17095e64b 100644
--- a/tools/golang/xenlight/Makefile
+++ b/tools/golang/xenlight/Makefile
@@ -15,13 +15,6 @@ all: build
 
 GOXL_GEN_FILES = types.gen.go helpers.gen.go
 
-# NOTE: This target is called from libxl/Makefile:all.  Since that
-# target must finish before golang/Makefile is called, this is
-# currently safe.  It must not be called from anywhere else in the
-# Makefile system without careful thought about races with
-# xenlight/Makefile:all
-idl-gen: $(GOXL_GEN_FILES)
-
 %.gen.go: gengotypes.py $(LIBXL_SRC_DIR)/libxl_types.idl $(LIBXL_SRC_DIR)/idl.py
 	XEN_ROOT=$(XEN_ROOT) $(PYTHON) gengotypes.py $(LIBXL_SRC_DIR)/libxl_types.idl
 
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 0e8dfc6193..c26b3a8093 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -219,7 +219,7 @@ testidl.c: libxl_types.idl gentest.py libxl.h $(AUTOINCS)
 .PHONY: all
 all: $(CLIENTS) $(TEST_PROGS) $(PKG_CONFIG) $(PKG_CONFIG_LOCAL) \
 		libxenlight.so libxenlight.a libxlutil.so libxlutil.a \
-	$(AUTOSRCS) $(AUTOINCS) idl-external
+	$(AUTOSRCS) $(AUTOINCS)
 
 $(LIBXL_OBJS) $(LIBXLU_OBJS) $(SAVE_HELPER_OBJS) \
 		$(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): \
@@ -275,21 +275,6 @@ _libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: libxl_
 	$(call move-if-changed,__libxl_type$(stem)_json.h,_libxl_type$(stem)_json.h)
 	$(call move-if-changed,__libxl_type$(stem).c,_libxl_type$(stem).c)
 
-# NOTE: This is safe to do at the moment because idl-external and
-# idl-gen are only called from libxl/Makefile:all, which must return
-# before golang/Makefile is callid.  idl-external and idl-gen must
-# never be called from another part of the make system without careful thought
-# about races with tools/golang/xenlight/Makefile:all
-.PHONY: idl-external
-idl-external:
-	$(MAKE) -C $(XEN_ROOT)/tools/golang/xenlight idl-gen
-
-LIBXL_IDLGEN_FILES = _libxl_types.h _libxl_types_json.h _libxl_types_private.h _libxl_types.c \
-	_libxl_types_internal.h _libxl_types_internal_json.h _libxl_types_internal_private.h _libxl_types_internal.c
-
-
-idl-gen: $(LIBXL_GEN_FILES) idl-external
-
 libxenlight.so: libxenlight.so.$(MAJOR)
 	$(SYMLINK_SHLIB) $< $@
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 16:55:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 16:55:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kEEzT-0001ge-RR; Fri, 04 Sep 2020 16:55:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kEEzS-0001gZ-S8
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 16:55:06 +0000
X-Inumbo-ID: 062062c5-df6e-414f-b5e4-70c737efc0d9
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 062062c5-df6e-414f-b5e4-70c737efc0d9;
 Fri, 04 Sep 2020 16:55:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=iY3XO9QFw2JZ89ry7k+EpIivQUeXKBaeXP38IRTyi9g=; b=ERXduYb15PYa78KXnUnscylaId
 Q5Hv57XONFPksKb8wuTg2sg2zpsK1GeCS8GD+jRmAtLgWDKMWhWlTI/1zXCUHVqTYBLoCPcJKFyfD
 497FM6cuBapus6ttSy7Sz+VxL1HdJvzH5LEgdo8r2tZdnIWrI2224USi4z0L5oftIok0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEEzR-0001q6-0N
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 16:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEEzQ-00016G-Uo
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 16:55:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] minios: Revert recent change and revert to working
 minios
Message-Id: <E1kEEzQ-00016G-Uo@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 16:55:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 82c3d15c903aa434473dfdb570096ae5db809b94
Author:     Ian Jackson <iwj@xenproject.org>
AuthorDate: Fri Sep 4 16:42:01 2020 +0100
Commit:     Ian Jackson <iwj@xenproject.org>
CommitDate: Fri Sep 4 16:50:55 2020 +0100

    minios: Revert recent change and revert to working minios
    
    Currently, xen.git#staging does not build in many environments because
    of issues with minios master.  This regression was introduced in an
    uncontrolled manner by an update to mini-os.git#master.
    
    This is because in e013e8514389 "config: use mini-os master for
    unstable" we switched to tracking minios master in an uncontrolled
    manner.  At the time we thought it was unlikely that minios changes
    would break the Xen build.  This turns out to have been overly
    optimistic.
    
    Xen currently uses unstable internal interfaces of minios.  Until this
    can be sorted out, internal changes to minios can require lockstep
    changes in Xen.
    
    All this means that "config: use mini-os master for unstable" was
    wrong.  We should undo it.  Instead, we go back to the previous
    situation: xen.git names a specific minios commit.
    
    This scheme is the model used for qemu-xen-traditional.
    
    That nailed commit must be updated manually, to have xen.git pick up
    changes from minios.  If the minios changes require changes in xen.git
    too, to avoid breaking the Xen build, they can be made freely in
    minios without adverse consequences.  When the minios commitid is
    updated in xen.git, the corresponding changes to the actual source
    files in xen.git should be bundled together.
    
    For example, when minios is fixed, 8d990807ec2c "stubdom/grub: update
    init_netfront() call for mini-os" will need to be reapplied, folded
    into the same commit as updates MINIOS_UPSTREAM_REVISION.  For now
    that commit must be reverted as we are going back to a previous
    version of minios.
    
    This reverts commit 8d990807ec2cde3061222a5ed2df62aba78bace9.
    This reverts commit e013e8514389b739153016349e49f5a78e34ddf0.
    
    CC: Jan Beulich <jbeulich@suse.com>
    CC: Costin Lupu <costin.lupu@cs.pub.ro>
    CC: Wei Liu <wl@xen.org>
    CC: Samuel Thibault <samuel.thibault@ens-lyon.org>
    Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 Config.mk              | 2 +-
 stubdom/grub/mini-os.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Config.mk b/Config.mk
index 8269503f73..db434ee2c6 100644
--- a/Config.mk
+++ b/Config.mk
@@ -246,7 +246,7 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= a3741780fe3535e19e02efa869a7cac481891129
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= master
+MINIOS_UPSTREAM_REVISION ?= 0b4b7897e08b967a09bed2028a79fabff82342dd
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.14.0
 
diff --git a/stubdom/grub/mini-os.c b/stubdom/grub/mini-os.c
index b33dbf02fb..4fc052a255 100644
--- a/stubdom/grub/mini-os.c
+++ b/stubdom/grub/mini-os.c
@@ -291,6 +291,8 @@ struct netfront_dev *net_dev;
 int
 minios_probe (struct nic *nic)
 {
+    char *ip;
+
     if (net_dev)
         return 1;
 
@@ -298,7 +300,7 @@ minios_probe (struct nic *nic)
     grub_memset ((char *) arptable, 0,
                  MAX_ARP * sizeof (struct arptable_t));
 
-    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, NULL, NULL, NULL);
+    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, &ip);
     if (!net_dev)
         return 0;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 17:11:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 17:11:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kEFF0-0003dU-2d; Fri, 04 Sep 2020 17:11:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kEFEy-0003dP-PI
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:08 +0000
X-Inumbo-ID: 365ea15a-5b72-460e-b2ff-827d5ab9d25c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 365ea15a-5b72-460e-b2ff-827d5ab9d25c;
 Fri, 04 Sep 2020 17:11:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ZBLMaGeR0kK7JjE9j1P3rXuFPqVu9oTC7WpRR1qCqWg=; b=wBt7TGI+9P+BGmesw+ljHFM3eC
 5uZb2W8MgsEUKZd4oaNSvm5dPiE+rE0lSMgTxZ0FZYVmb9g/5pzu+dpHnlkX4pLFGlPHdL5sP8rJq
 q/fIBpTMmv8G/idJrposSxnbrYTHFt24VX1FngEJxhjBfJxgbVCkfT93lvFn7nTgmvO0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFEw-0002BJ-8L
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFEw-0002G7-56
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: Update silicon-errata.txt with the Neovers AT
 erratum
Message-Id: <E1kEFEw-0002G7-56@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 17:11:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1814a626fb5811184eda64fe22f0055df4600211
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:01:40 2020 +0100

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 17:11:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 17:11:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kEFF9-0003dw-45; Fri, 04 Sep 2020 17:11:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kEFF7-0003dp-Rf
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:17 +0000
X-Inumbo-ID: 6e373d02-9105-42c7-8439-38c27af36e63
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6e373d02-9105-42c7-8439-38c27af36e63;
 Fri, 04 Sep 2020 17:11:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ivXvfEDs+u0Vu/d++tlDfheARjVmc5EQwKVWp1ET2wE=; b=mDlr+rP9qCHLhjGtSwQ3YevF53
 JnQ/xqlldzCtWVe0FHGx+3dJC+Nskgf/3B4IC7RlIAqdHRCH5XVEH4Iy4nGalH/DKRTeB3e5Zr2R0
 zlCzweXF3QjY/dO6PK/AqJTdgHgoyJ3QEsyletvdzOCqq1drIO4touz6G5+U6GGfYHS0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFF6-0002BO-DA
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFF6-0002Gk-B9
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kEFF6-0002Gk-B9@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 17:11:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 968bb86d04913f52d7678a842474f2a674a8b23e
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:02:35 2020 +0100

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 674beb0353..10878ead8a 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 04 17:11:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 04 Sep 2020 17:11:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kEFFJ-0003fD-5x; Fri, 04 Sep 2020 17:11:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=LUxL=CN=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kEFFH-0003ex-AU
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:27 +0000
X-Inumbo-ID: 0e26d072-1ad7-486e-b7cd-a86fc74d25bd
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0e26d072-1ad7-486e-b7cd-a86fc74d25bd;
 Fri, 04 Sep 2020 17:11:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DRsaOF9NXJBMcBoAomLmeVRIgNU1jQkt5SqcEJPSdjQ=; b=BK/9zn2a5NDu/3HvzZbp6VQxfv
 T+1/JY5ecEdNoNrC2RV7LoOz5W30LyWDHbkZ/agm76HcUqWsUNqTyEFG29Wtti033kze6dhDqgYV1
 fvIyxoiwVbJ+4f4dAaLJGxAWGpLe21KcUg36S45L6ugnJXdUmMKMfsq0PtRBe/YQMz5U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFFG-0002D9-HS
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kEFFG-0002HF-Fi
 for xen-changelog@lists.xenproject.org; Fri, 04 Sep 2020 17:11:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: Throw messages for unknown FP/SIMD implement ID
Message-Id: <E1kEFFG-0002HF-Fi@xenbits.xenproject.org>
Date: Fri, 04 Sep 2020 17:11:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f4c1a541fa351e4f613471bbf397931f9e1ddd27
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:04 2020 +0000
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:02:35 2020 +0100

    xen/arm: Throw messages for unknown FP/SIMD implement ID
    
    Arm ID_AA64PFR0_EL1 register provides two fields to describe CPU
    FP/SIMD implementations. Currently, we exactly know the meaning of
    0x0, 0x1 and 0xf of these fields. Xen treats value < 8 as FP/SIMD
    features presented. If there is a value 0x2 bumped in the future,
    Xen behaviors for value <= 0x1 can also take effect. But what Xen
    done for value <= 0x1 may not always cover new value 0x2 required.
    We throw these messages to break the silence when Xen detected
    unknown FP/SIMD IDs to notice user to check.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/setup.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 7968cee47d..f16b33fa87 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -133,6 +133,18 @@ static void __init processor_id(void)
            cpu_has_simd ? " AdvancedSIMD" : "",
            cpu_has_gicv3 ? " GICv3-SysReg" : "");
 
+    /* Warn user if we find unknown floating-point features */
+    if ( cpu_has_fp && (boot_cpu_feature64(fp) >= 2) )
+        printk(XENLOG_WARNING "WARNING: Unknown Floating-point ID:%d, "
+               "this may result in corruption on the platform\n",
+               boot_cpu_feature64(fp));
+
+    /* Warn user if we find unknown AdvancedSIMD features */
+    if ( cpu_has_simd && (boot_cpu_feature64(simd) >= 2) )
+        printk(XENLOG_WARNING "WARNING: Unknown AdvancedSIMD ID:%d, "
+               "this may result in corruption on the platform\n",
+               boot_cpu_feature64(simd));
+
     printk("  Debug Features: %016"PRIx64" %016"PRIx64"\n",
            boot_cpu_data.dbg64.bits[0], boot_cpu_data.dbg64.bits[1]);
     printk("  Auxiliary Features: %016"PRIx64" %016"PRIx64"\n",
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 08:44:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 08:44:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFClC-0001px-IM; Mon, 07 Sep 2020 08:44:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFClB-0001pe-4h
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:21 +0000
X-Inumbo-ID: e9563438-f560-4389-85d5-08db4095b105
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e9563438-f560-4389-85d5-08db4095b105;
 Mon, 07 Sep 2020 08:44:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cG6HeMe5tvjBsjo/I/LkZSRlBxayu6rLBRxAdfKiFsY=; b=6+Q2V/RFvxOJVLQB99oWe/Ebkb
 eg4rtvmrd3XiaeYklTC/s9Zs0+XCeTYBYs6nv2uLBkSQqTwmj5J5t76jEnW7ai0hTKptRN1q43ELN
 F9NcXGJQEn5r10miwQb8C+vtTRHKY/P3v5NXxrGj3ywahH0KwJq+DSM608gtOMOuYWQI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFCkv-0002mQ-6m
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFCkv-0003gT-5F
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] Revert "x86: generalize padding field handling"
Message-Id: <E1kFCkv-0003gT-5F@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 08:44:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e52716154da04967f9b9d7cf9a1655ea4bcd9e93
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 7 10:34:03 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:34:03 2020 +0200

    Revert "x86: generalize padding field handling"
    
    This reverts commit 696c273f3d9a169911308fb7e0a702a3eb6a150d.
    
    I was based on the flase assumption that padding fields need no
    copying: If native code checks such fields, they of course need
    copying in. And if the ABI specifies them to be zero on
    completion, we also need to copy them out.
---
 xen/common/compat/memory.c | 3 ---
 xen/tools/get-fields.sh    | 8 ++++----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 215b8f52d6..3851f756c7 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -354,13 +354,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
                 return -EFAULT;
 
 #define XLAT_vnuma_topology_info_HNDL_vdistance_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vdistance_pad:                \
             guest_from_compat_handle((_d_)->vdistance.h, (_s_)->vdistance.h)
 #define XLAT_vnuma_topology_info_HNDL_vcpu_to_vnode_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vcpu_to_vnode_pad:            \
             guest_from_compat_handle((_d_)->vcpu_to_vnode.h, (_s_)->vcpu_to_vnode.h)
 #define XLAT_vnuma_topology_info_HNDL_vmemrange_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vmemrange_pad:                \
             guest_from_compat_handle((_d_)->vmemrange.h, (_s_)->vmemrange.h)
 
             XLAT_vnuma_topology_info(nat.vnuma, &cmp.vnuma);
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 753e37eb2e..002db2093f 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -218,7 +218,7 @@ for line in sys.stdin.readlines():
 				fi
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					if [ $kind = union ]
 					then
@@ -347,7 +347,7 @@ build_body ()
 			fi
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				if [ -z "$array" -a -z "$array_type" ]
 				then
@@ -437,7 +437,7 @@ check_field ()
 				id=$token
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					check_field $1 $2 $3.$id "$fields"
 					test "$token" != ";" || fields= id=
@@ -491,7 +491,7 @@ build_check ()
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				check_field $kind $1 $id "$fields"
 				test "$token" != ";" || fields= id=
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 08:44:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 08:44:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFCl7-0001pj-Gt; Mon, 07 Sep 2020 08:44:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFCl6-0001pe-BE
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:16 +0000
X-Inumbo-ID: a303fa33-0602-4193-8d25-67027b6c3edb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a303fa33-0602-4193-8d25-67027b6c3edb;
 Mon, 07 Sep 2020 08:44:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PSHHHdd6s3vVB9RrIk/Z5IL1TpOo4hxrOduV9i1GOPI=; b=zXDwFvwOIdu74bfMfGlrSjH3d6
 LNk+NtldY5Q0aAwthkrrAvAtO53qUhXWcYVK0umRMOxYL1ky0dyNeckwz/jt8qPTPx373+++hTMCr
 rnnIX6vnt7ArEixWNmo9Mpc46w0Dhx+qdSekPSIE1g8MxiRwamE5SI8MqKGdT0YGDcKc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFCl5-0002mT-AU
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFCl5-0003h5-9Q
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/vmx: handle writes to MISC_ENABLE MSR
Message-Id: <E1kFCl5-0003h5-9Q@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 08:44:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2454fa428d0b0d1705b8395db7674426ebf182aa
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 10:37:23 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:37:23 2020 +0200

    x86/vmx: handle writes to MISC_ENABLE MSR
    
    Such handling consist in checking that no bits have been changed from
    the read value, if that's the case silently drop the write, otherwise
    inject a fault.
    
    At least Windows guests will expect to write to the MISC_ENABLE MSR
    with the same value that's been read from it.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index a0d58ffbe2..c4b40bf3cb 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3163,7 +3163,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
 
     switch ( msr )
     {
-        uint64_t rsvd;
+        uint64_t rsvd, tmp;
 
     case MSR_IA32_SYSENTER_CS:
         __vmwrite(GUEST_SYSENTER_CS, msr_content);
@@ -3301,6 +3301,17 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         /* None of these MSRs are writeable. */
         goto gp_fault;
 
+    case MSR_IA32_MISC_ENABLE:
+        /*
+         * Silently drop writes that don't change the reported value: At least
+         * some Windows guests will expect to be able to write to MISC_ENABLE
+         * with the same value that's been read from it.
+         */
+        if ( vmx_msr_read_intercept(msr, &tmp) != X86EMUL_OKAY ||
+             tmp != msr_content )
+            goto gp_fault;
+        break;
+
     case MSR_P6_PERFCTR(0)...MSR_P6_PERFCTR(7):
     case MSR_P6_EVNTSEL(0)...MSR_P6_EVNTSEL(7):
     case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 08:44:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 08:44:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFClI-0001qp-Jq; Mon, 07 Sep 2020 08:44:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFClH-0001qj-N4
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:27 +0000
X-Inumbo-ID: 41da9ca6-d7cd-4e9c-a1b8-6a5ab8acff63
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 41da9ca6-d7cd-4e9c-a1b8-6a5ab8acff63;
 Mon, 07 Sep 2020 08:44:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=CNMqUt4iTZD56O4Gwa1H/AaTbGMviUIx1oNseh5lAow=; b=I5baLhMbFvb1ecdli2OErAwU40
 Lzm6XLkoqEldaV7UIxRbaHJtWckIJr9EqVCJh5TxQD7hYX1agnzn3vleCDnXWo6OBdAYu7GiQJ9tf
 w74QQQyO0MKbol3vEwqXna13RIIYacqAwtlWV3LtSBpgvM8BjK3Bf9Q4f+F6oVKPe0jY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFClF-0002mW-GV
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFClF-0003hX-D2
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 08:44:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/svm: silently drop writes to SYSCFG and related MSRs
Message-Id: <E1kFClF-0003hX-D2@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 08:44:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f5b44269fc734474f3272a22ba9d426d234ed460
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 10:38:00 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:38:00 2020 +0200

    x86/svm: silently drop writes to SYSCFG and related MSRs
    
    The SYSCFG, TOP_MEM1 and TOP_MEM2 MSRs are currently exposed to guests
    and writes are silently discarded. Make this explicit in the SVM code
    now, and just return default constant values when attempting to read
    any of the MSRs, while continuing to silently drop writes.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index ca3bbfcbb3..af584ff5d1 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1917,6 +1917,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
             goto gpf;
         break;
 
+    case MSR_K8_SYSCFG:
+    case MSR_K8_TOP_MEM1:
+    case MSR_K8_TOP_MEM2:
     case MSR_K8_VM_CR:
         *msr_content = 0;
         break;
@@ -2094,6 +2097,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
             goto gpf;
         break;
 
+    case MSR_K8_TOP_MEM1:
+    case MSR_K8_TOP_MEM2:
+    case MSR_K8_SYSCFG:
     case MSR_K8_VM_CR:
         /* ignore write. handle all bits as read-only. */
         break;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 10:55:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 10:55:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFEnl-00067T-33; Mon, 07 Sep 2020 10:55:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFEnj-00067M-Th
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:07 +0000
X-Inumbo-ID: c494a23c-6e18-4981-9258-b983e864275a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c494a23c-6e18-4981-9258-b983e864275a;
 Mon, 07 Sep 2020 10:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Ic6edeQ1dR8aIJzR49InSQtOUfOHKaFBuMZj4Crk9R8=; b=t0rDRspm7Q/eF0B15zRdM3z2NR
 eS+NfGDYYa5qZZedxNbWY8bH0LBMJhoLuzMMrc10okICAVjU/ivpS9i9zXAm3hJ/qY43J1ZP6ZypS
 gAP2/OBY9mX/3dEmm9SV5sNUt0pcQ7aGCS902TOGQnOoOM2M+9M+/PinVak7sGi9kIIM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFEni-0005fN-7N
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFEni-0003ul-69
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kFEni-0003ul-69@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 10:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 7 11:32:34 2020 +0100

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 18 ++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 66975d5f2c..f479bc6857 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1728,6 +1728,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1738,14 +1748,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index ec5a7d2dca..44e4ea2582 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -444,17 +444,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 void toggle_guest_mode(struct vcpu *v)
 {
     const struct domain *d = v->domain;
+    unsigned long gs_base;
 
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index bcc1188f6a..a192160f84 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -801,17 +801,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -882,15 +871,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -1007,14 +994,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 28bc98f8f2..b69cf2dc4f 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1030,10 +1030,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1050,10 +1047,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 5fb347a94c..df657dc69f 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -527,7 +527,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 10:55:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 10:55:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFEnv-00068F-4e; Mon, 07 Sep 2020 10:55:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFEnt-000685-O9
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:17 +0000
X-Inumbo-ID: 7a864168-4966-48cb-bbca-84fb547b3a44
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 7a864168-4966-48cb-bbca-84fb547b3a44;
 Mon, 07 Sep 2020 10:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=X5dEYxXJ/9W7c2Rpa30Qr5H6CCfP+3GGZH9vnkxbYVM=; b=b5T75Bs4/fNvaFHKbEkqFGlcVb
 UcdwNGyD5jv5ew8AanPLu96gf0Q/OwXe30lVKZTPNbwLg8NqWGHSl9rvXRYoekewk6WOpi6uRhX9A
 OCTgssMNfma79iMLtoh/lXYHIbMITi5rp7U8odCgT9WirSSuSv0xsSnLwOOQgqWrDXgA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFEns-0005fW-C3
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFEns-0003vW-AD
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 10:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Rewrite segment context switching from scratch
Message-Id: <E1kFEns-0003vW-AD@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 10:55:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ad0fd291c5e79191c2e3c70e43dded569f11a450
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 7 11:32:34 2020 +0100

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c                    | 184 ++++++++++---------------------
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 2 files changed, 60 insertions(+), 128 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index f479bc6857..d4f4ced681 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1186,13 +1186,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1508,58 +1504,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1572,57 +1570,21 @@ static void load_segments(struct vcpu *n)
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1741,7 +1703,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1758,35 +1719,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1996,7 +1928,7 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
+         !is_idle_domain(nd) )
         svm_load_segs(0, 0, 0, 0, 0, 0, 0);
 #endif
 
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 14:22:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 14:22:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFI24-0008L1-9v; Mon, 07 Sep 2020 14:22:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFI23-0008Kw-0z
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:07 +0000
X-Inumbo-ID: 864493ff-86b8-428e-9767-d793f759b8a3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 864493ff-86b8-428e-9767-d793f759b8a3;
 Mon, 07 Sep 2020 14:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hT3vSVbywYV4HdtcjLyydr/9BomjZWody4qKn0Rn0SE=; b=rZ17+QAju3JINWdDB2SRXwuTxC
 l8C7htn+bJ3oClLu++T8QeBiO3K7Y8X7inleo0reCq5Iliqk86leWW4RlBq/tISQRGWuavgwQJypn
 2tQUi0zw/B5HeXLo44OfV8f5TEeN2TCr2NaMqwuzBr1Z/m6rg8+O1bQIlFpZtUIKJewk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFI22-0001e5-1U
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFI21-0000E4-Vf
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] libgnttab/freebsd: add tools libs.h
Message-Id: <E1kFI21-0000E4-Vf@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 14:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1be24cd17741192d1e18f24e6cf92f0ae9324e62
Author:     Roger Pau Monne <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 12:18:05 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:13:31 2020 +0000

    libgnttab/freebsd: add tools libs.h
    
    In order to get the ROUNDUP macro, or else the build fails. I assume
    ROUNDUP would previously get included from a different header.
    
    Seeing as Linux does explicitly include libs.h do the same for
    FreeBSD.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/gnttab/freebsd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c
index 0588501d0f..768af701c6 100644
--- a/tools/libs/gnttab/freebsd.c
+++ b/tools/libs/gnttab/freebsd.c
@@ -30,6 +30,8 @@
 
 #include <xen/sys/gntdev.h>
 
+#include <xen-tools/libs.h>
+
 #include "private.h"
 
 #define PAGE_SHIFT           12
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 14:22:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 14:22:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFI2E-0008Ld-BZ; Mon, 07 Sep 2020 14:22:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFI2D-0008LU-6r
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:17 +0000
X-Inumbo-ID: 99b0664f-dd27-4e9c-a8c3-4d430578412d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 99b0664f-dd27-4e9c-a8c3-4d430578412d;
 Mon, 07 Sep 2020 14:22:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Qu8+59Z63AQFUk9mg+wTy8O2BVbwBCNXIMHJPBDu4ZU=; b=Vowxi4P+b4DJjd8gV1RVgqdRQe
 L21qmWhQshmubbT+dpQB82lAAR2+x4jeQ8UJSvDD6Ycong5wP6fH9vFfPjR9kvRw5P26Bxg7k9uz5
 UL9p1R7d0jN6mwoWYpNn3fgs8VdLdYX7sB52DWCPllzFavw1Q6gBLQQKbJ7HQ2j5JROo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFI2C-0001e8-6u
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFI2C-0000Ff-41
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:22:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] minios: use more recent commit for building xen unstable
Message-Id: <E1kFI2C-0000Ff-41@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 14:22:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 71039ed743a3fbf7b58815138d667913a5742e6f
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Mon Sep 7 13:48:14 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:14:40 2020 +0000

    minios: use more recent commit for building xen unstable
    
    Commit 82c3d15c903aa43 ("minios: Revert recent change and revert to
    working minios") switched the used commit for the build of Xen unstable
    from master to a rather old commit (the one used for Xen 4.13 instead
    of the last one without a known problem).
    
    Switch to Mini-OS commit 051b87bb9c196 instead, which doesn't contain
    the problematic modification being reason for switching away from
    master.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 Config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Config.mk b/Config.mk
index db434ee2c6..259e68863d 100644
--- a/Config.mk
+++ b/Config.mk
@@ -246,7 +246,7 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= a3741780fe3535e19e02efa869a7cac481891129
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= 0b4b7897e08b967a09bed2028a79fabff82342dd
+MINIOS_UPSTREAM_REVISION ?= 051b87bb9c19609976fb038f386920e1ce5454c5
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.14.0
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 07 14:33:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 07 Sep 2020 14:33:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFICg-0001GP-LH; Mon, 07 Sep 2020 14:33:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=cwGY=CQ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFICg-0001GK-0V
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:33:06 +0000
X-Inumbo-ID: 5d502c7f-17d8-45e7-a1ad-356d476ab234
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5d502c7f-17d8-45e7-a1ad-356d476ab234;
 Mon, 07 Sep 2020 14:33:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cnSj83Not6oglPZPO4hmv2m3KJmt5XhtZFVjy/2cDmU=; b=Rzk5dEUMB881SgM9c1Q5nYnhYl
 sPyp3p+5CyH6TLUh2wfgpBKbKkn22laDMJQROCGnLG2UxrO8fZF8FNqXvuh349WA08oKJDn0mbB8a
 hTxHBPzRkqR0HXWaJ02dPtaoLoQHRhDObeRsOx0ynj9fBc/ttOmEsusZLIL90We8d/Fc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFICf-0001so-41
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:33:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFICf-0000sD-1P
 for xen-changelog@lists.xenproject.org; Mon, 07 Sep 2020 14:33:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/hotplug/Linux: don't needlessly use non-standard
 features in vif-{bridge, route}
Message-Id: <E1kFICf-0000sD-1P@xenbits.xenproject.org>
Date: Mon, 07 Sep 2020 14:33:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b11910082d90bb1597f6679524eb726a33306672
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 2 08:09:28 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:28:59 2020 +0000

    tools/hotplug/Linux: don't needlessly use non-standard features in vif-{bridge,route}
    
    We're not after any "fall-through" behavior here. Replace the constructs
    with ones understood by all conforming shells, including older bash
    (problem observed with 3.1.51(1)).
    
    Fixes: b51715f02bf9 ("tools/hotplug/Linux: remove code duplication in vif-bridge")
    Fixes: 3683290fc0b0 ("tools/hotplug: only attempt to call 'ip route' if there is valid command")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-bridge | 8 ++------
 tools/hotplug/Linux/vif-route  | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index b99cc82a21..906047e82f 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -77,16 +77,12 @@ then
 fi
 
 case "$command" in
-    add)
-        ;&
-    online)
+    add|online)
         setup_virtual_bridge_port "$dev"
         set_mtu "$bridge" "$dev" "$type_if"
         add_to_bridge "$bridge" "$dev"
         ;;
-    remove)
-        ;&
-    offline)
+    remove|offline)
         remove_from_bridge "$bridge" "$dev"
         ;;
 esac
diff --git a/tools/hotplug/Linux/vif-route b/tools/hotplug/Linux/vif-route
index 05199bf741..9cd417a005 100755
--- a/tools/hotplug/Linux/vif-route
+++ b/tools/hotplug/Linux/vif-route
@@ -22,17 +22,13 @@ dir=$(dirname "$0")
 main_ip=$(dom0_ip)
 
 case "${command}" in
-    add)
-        ;&
-    online)
+    add|online)
         ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up
         echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
         ipcmd='add'
         cmdprefix=''
         ;;
-    remove)
-        ;&
-    offline)
+    remove|offline)
         do_without_error ifdown ${dev}
         ipcmd='del'
         cmdprefix='do_without_error'
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 08 15:55:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 08 Sep 2020 15:55:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFfxc-0005j4-2W; Tue, 08 Sep 2020 15:55:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=PtlF=CR=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFfxb-0005iy-Hu
 for xen-changelog@lists.xenproject.org; Tue, 08 Sep 2020 15:55:07 +0000
X-Inumbo-ID: 9a50b0ba-607c-4ed8-889b-b1efd36a7861
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9a50b0ba-607c-4ed8-889b-b1efd36a7861;
 Tue, 08 Sep 2020 15:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rwdl+jT8O2yASRigy82DXGMXmme0eYvGYMmYkXpGvJU=; b=vf8GVAPKjQz+UezGoP2pMI48wu
 kauk2YQsPh1u9+45G7cxt+AI1l66t5dyIqXOrK5zBtHu7Z9oFPf4lqOpJMJ0bOHJtnaFnUcGDI+4r
 dtNMvWjXMVqcZsYmwRSWpILwQY1Uj8fkdoKn0Nr+7BgDC+XqgVXjM2OxgwKg2hqAjrUs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFfxa-0007qs-3L
 for xen-changelog@lists.xenproject.org; Tue, 08 Sep 2020 15:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFfxa-0004vw-1E
 for xen-changelog@lists.xenproject.org; Tue, 08 Sep 2020 15:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Fix assertions in svm_load_segs()
Message-Id: <E1kFfxa-0004vw-1E@xenbits.xenproject.org>
Date: Tue, 08 Sep 2020 15:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1e2d3be2e516e6f415ca6029f651b76a8563a27c
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 8 10:47:57 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 8 16:46:31 2020 +0100

    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c             | 7 +++----
 xen/arch/x86/hvm/svm/svm.c        | 9 +++------
 xen/include/asm-x86/hvm/svm/svm.h | 6 ++++--
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index d4f4ced681..e8e91cf080 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1557,7 +1557,7 @@ static void load_segments(struct vcpu *n)
                    : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !compat )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1565,8 +1565,7 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
@@ -1929,7 +1928,7 @@ static void __context_switch(void)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
          !is_idle_domain(nd) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index af584ff5d1..23b2a2aa17 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1521,8 +1521,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1559,14 +1558,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index d568e86db9..2310878e41 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxEs-0003Ou-9f; Wed, 09 Sep 2020 10:22:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxEq-0003Oo-Sa
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:04 +0000
X-Inumbo-ID: d98134e5-640a-4713-b804-4b0efb18563a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d98134e5-640a-4713-b804-4b0efb18563a;
 Wed, 09 Sep 2020 10:22:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2/7JHwBlRpaOsvaiEWvHpogI5gt0MRPA1rUGOEqFjM4=; b=1OGbaOqv+MbL/xIH7SNFbYkV+5
 fLbYLbOyc+kRSBtVXgfI5C5lFJCPM3E8PQO1Sp/sxt/Mn9t7PBYSCYlNyr6aXGbDFLYJBQ//OsBw0
 cIr8u4umCsTa+sZBAkeSU9bgGNVlOngNnQTO26Nl2g5DjhISf7eIm8ySdFy6ZgiIJhkA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxEp-0004vC-Bs
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:03 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxEp-0006iX-Ao
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:03 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] build: also check for empty .bss.* in .o -> .init.o
 conversion
Message-Id: <E1kFxEp-0006iX-Ao@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:03 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8856a914bffd56c018a794c06d4abb6018aa958d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Thu Aug 27 09:46:55 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Thu Aug 27 09:46:55 2020 +0200

    build: also check for empty .bss.* in .o -> .init.o conversion
    
    We're gaining such sections, and like .text.* and .data.* they shouldn't
    be present in objects subject to automatic to-init conversion. Oddly
    enough for quite some time we did have an instance breaking this rule,
    which gets fixed at this occasion, by breaking out the EFI boot
    allocator functions into its own translation unit.
    
    Fixes: c5b9805bc1f7 ("efi: create new early memory allocator")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/Makefile              |  2 +-
 xen/Rules.mk              |  2 +-
 xen/arch/arm/efi/Makefile |  2 +-
 xen/arch/x86/efi/Makefile |  2 +-
 xen/common/efi/boot.c     | 53 +----------------------------------------------
 xen/common/efi/ebmalloc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/common/efi/efi.h      |  6 ++++++
 7 files changed, 63 insertions(+), 56 deletions(-)

diff --git a/xen/Makefile b/xen/Makefile
index a87bb225dc..bf0c804d43 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -355,7 +355,7 @@ $(TARGET): delete-unfresh-files
 	$(MAKE) -C tools
 	$(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h
 	[ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm
-	[ -e arch/$(TARGET_ARCH)/efi ] && for f in boot.c runtime.c compat.c efi.h;\
+	[ -e arch/$(TARGET_ARCH)/efi ] && for f in $$(cd common/efi; echo *.[ch]); \
 		do test -r arch/$(TARGET_ARCH)/efi/$$f || \
 		   ln -nsf ../../../common/efi/$$f arch/$(TARGET_ARCH)/efi/; \
 		done; \
diff --git a/xen/Rules.mk b/xen/Rules.mk
index e90a03d116..891c94e6ad 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -188,7 +188,7 @@ define cmd_obj_init_o
     $(OBJDUMP) -h $< | while read idx name sz rest; do \
         case "$$name" in \
         .*.local) ;; \
-        .text|.text.*|.data|.data.*|.bss) \
+        .text|.text.*|.data|.data.*|.bss|.bss.*) \
             test $$(echo $$sz | sed 's,00*,0,') != 0 || continue; \
             echo "Error: size of $<:$$name is 0x$$sz" >&2; \
             exit $$(expr $$idx + 1);; \
diff --git a/xen/arch/arm/efi/Makefile b/xen/arch/arm/efi/Makefile
index e3ff2c3f28..662892babd 100644
--- a/xen/arch/arm/efi/Makefile
+++ b/xen/arch/arm/efi/Makefile
@@ -1,4 +1,4 @@
 CFLAGS-y += -fshort-wchar
 
-obj-y +=  boot.init.o runtime.o
+obj-y += boot.init.o ebmalloc.o runtime.o
 obj-$(CONFIG_ACPI) +=  efi-dom0.init.o
diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
index 4b2b010a80..770438a029 100644
--- a/xen/arch/x86/efi/Makefile
+++ b/xen/arch/x86/efi/Makefile
@@ -8,7 +8,7 @@ cmd_objcopy_o_ihex = $(OBJCOPY) -I ihex -O binary $< $@
 
 boot.init.o: buildid.o
 
-EFIOBJ := boot.init.o compat.o runtime.o
+EFIOBJ := boot.init.o ebmalloc.o compat.o runtime.o
 
 $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4)
 $(EFIOBJ): CFLAGS-stack-boundary := $(cflags-stack-boundary)
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 5a520bf21d..4022a672c9 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -112,7 +112,6 @@ static CHAR16 *FormatDec(UINT64 Val, CHAR16 *Buffer);
 static CHAR16 *FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer);
 static void  DisplayUint(UINT64 Val, INTN Width);
 static CHAR16 *wstrcpy(CHAR16 *d, const CHAR16 *s);
-static void noreturn blexit(const CHAR16 *str);
 static void PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode);
 static char *get_value(const struct file *cfg, const char *section,
                               const char *item);
@@ -155,56 +154,6 @@ static CHAR16 __initdata newline[] = L"\r\n";
 #define PrintStr(s) StdOut->OutputString(StdOut, s)
 #define PrintErr(s) StdErr->OutputString(StdErr, s)
 
-#ifdef CONFIG_ARM
-/*
- * TODO: Enable EFI boot allocator on ARM.
- * This code can be common for x86 and ARM.
- * Things TODO on ARM before enabling ebmalloc:
- *   - estimate required EBMALLOC_SIZE value,
- *   - where (in which section) ebmalloc_mem[] should live; if in
- *     .bss.page_aligned, as it is right now, then whole BSS zeroing
- *     have to be disabled in xen/arch/arm/arm64/head.S; though BSS
- *     should be initialized somehow before use of variables living there,
- *   - use ebmalloc() in ARM/common EFI boot code,
- *   - call free_ebmalloc_unused_mem() somewhere in init code.
- */
-#define EBMALLOC_SIZE	MB(0)
-#else
-#define EBMALLOC_SIZE	MB(1)
-#endif
-
-static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
-    ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __initdata ebmalloc_allocated;
-
-/* EFI boot allocator. */
-static void __init __maybe_unused *ebmalloc(size_t size)
-{
-    void *ptr = ebmalloc_mem + ebmalloc_allocated;
-
-    ebmalloc_allocated += ROUNDUP(size, sizeof(void *));
-
-    if ( ebmalloc_allocated > sizeof(ebmalloc_mem) )
-        blexit(L"Out of static memory\r\n");
-
-    return ptr;
-}
-
-static void __init __maybe_unused free_ebmalloc_unused_mem(void)
-{
-#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
-    unsigned long start, end;
-
-    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
-    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
-
-    destroy_xen_mappings(start, end);
-    init_xenheap_pages(__pa(start), __pa(end));
-
-    printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
-#endif
-}
-
 /*
  * Include architecture specific implementation here, which references the
  * static globals defined above.
@@ -321,7 +270,7 @@ static bool __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
            !memcmp(guid1->Data4, guid2->Data4, sizeof(guid1->Data4));
 }
 
-static void __init noreturn blexit(const CHAR16 *str)
+void __init noreturn blexit(const CHAR16 *str)
 {
     if ( str )
         PrintStr((CHAR16 *)str);
diff --git a/xen/common/efi/ebmalloc.c b/xen/common/efi/ebmalloc.c
new file mode 100644
index 0000000000..c65dbd946f
--- /dev/null
+++ b/xen/common/efi/ebmalloc.c
@@ -0,0 +1,52 @@
+#include "efi.h"
+#include <xen/init.h>
+
+#ifdef CONFIG_ARM
+/*
+ * TODO: Enable EFI boot allocator on ARM.
+ * This code can be common for x86 and ARM.
+ * Things TODO on ARM before enabling ebmalloc:
+ *   - estimate required EBMALLOC_SIZE value,
+ *   - where (in which section) ebmalloc_mem[] should live; if in
+ *     .bss.page_aligned, as it is right now, then whole BSS zeroing
+ *     have to be disabled in xen/arch/arm/arm64/head.S; though BSS
+ *     should be initialized somehow before use of variables living there,
+ *   - use ebmalloc() in ARM/common EFI boot code,
+ *   - call free_ebmalloc_unused_mem() somewhere in init code.
+ */
+#define EBMALLOC_SIZE	MB(0)
+#else
+#define EBMALLOC_SIZE	MB(1)
+#endif
+
+static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
+    ebmalloc_mem[EBMALLOC_SIZE];
+static unsigned long __initdata ebmalloc_allocated;
+
+/* EFI boot allocator. */
+void __init *ebmalloc(size_t size)
+{
+    void *ptr = ebmalloc_mem + ebmalloc_allocated;
+
+    ebmalloc_allocated += ROUNDUP(size, sizeof(void *));
+
+    if ( ebmalloc_allocated > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
+void __init free_ebmalloc_unused_mem(void)
+{
+#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
+    unsigned long start, end;
+
+    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    destroy_xen_mappings(start, end);
+    init_xenheap_pages(__pa(start), __pa(end));
+
+    printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
+#endif
+}
diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h
index 2e38d05f3d..4845d84913 100644
--- a/xen/common/efi/efi.h
+++ b/xen/common/efi/efi.h
@@ -40,4 +40,10 @@ extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,
 extern UINT64 efi_apple_properties_addr;
 extern UINTN efi_apple_properties_len;
 
+void noreturn blexit(const CHAR16 *str);
+
 const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n);
+
+/* EFI boot allocator. */
+void *ebmalloc(size_t size);
+void free_ebmalloc_unused_mem(void);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxF4-0003Q9-Ba; Wed, 09 Sep 2020 10:22:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxF3-0003Pz-Br
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:17 +0000
X-Inumbo-ID: 04bc9e45-2704-448a-9bdd-72f53bf75a4f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 04bc9e45-2704-448a-9bdd-72f53bf75a4f;
 Wed, 09 Sep 2020 10:22:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=R+/8thiSmcusEQPdYiUskIz5hN3BSSCIaFKY2q7rFcY=; b=kWuiug1l/zMDIUzI8eTrU/N62v
 X8yzzkespN0xxmni0+KwLp8ndzXXNRGPiHLRRmjIfTB6VlFzeTrO+GlMx6GG0in2BMoFbJv+yaeoL
 LUqxh/k00sxBJMIDxX9j2XYzZWXB/if14AeP2MdFJwWnz8sZf/jWA8B2lmQK1FtnoJGA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxEz-0004vI-HR
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxEz-0006kY-Eh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:13 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: don't build with EFI support in shim-exclusive mode
Message-Id: <E1kFxEz-0006kY-Eh@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:13 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit de58ea464fb6db4b78102edc8ac4598d4eebe6c5
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Thu Aug 27 09:51:07 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Thu Aug 27 09:51:07 2020 +0200

    x86: don't build with EFI support in shim-exclusive mode
    
    There's no need for xen.efi at all, and there's also no need for EFI
    support in xen.gz since the shim runs in PVH mode, i.e. without any
    firmware (and hence by implication also without EFI one).
    
    The slightly odd looking use of $(space) is to ensure the new ifneq()
    evaluates consistently between "build" and "install" invocations of
    make.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 7d89467dc9..93e6dcdc70 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -80,7 +80,9 @@ x86_emulate.o: x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
 
 efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
                       -O $(BASEDIR)/include/xen/compile.h ]; then \
-                         echo '$(TARGET).efi'; fi)
+                         echo '$(TARGET).efi'; fi) \
+         $(space)
+efi-$(CONFIG_PV_SHIM_EXCLUSIVE) :=
 
 ifneq ($(build_id_linker),)
 notes_phdrs = --notes
@@ -113,11 +115,13 @@ $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 		{ echo "No Multiboot2 header found" >&2; false; }
 	mv $(TMP) $(TARGET)
 
+ifneq ($(efi-y),)
 # Check if the compiler supports the MS ABI.
 export XEN_BUILD_EFI := $(shell $(CC) $(XEN_CFLAGS) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
 # Check if the linker supports PE.
 XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
 CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
+endif
 
 ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
 EFI_OBJS-$(XEN_BUILD_EFI) := efi/relocs-dummy.o
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxFB-0003Sg-D8; Wed, 09 Sep 2020 10:22:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFA-0003SY-VC
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:24 +0000
X-Inumbo-ID: bf9e8d08-0d74-4752-a6d3-47c9b89b59ff
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bf9e8d08-0d74-4752-a6d3-47c9b89b59ff;
 Wed, 09 Sep 2020 10:22:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=kyxo+9WMWN30Y8iIdvXlFiO8NGOcapy/G0fbxyln+jw=; b=x6CY61wSKnAMTwGaESSeSP43kC
 d28BrRZx2zUeaGuXuXH9tOE7uAc/A6U6ea5nXr+mAJEk6icjRbompclWhk2bg5GpDGRA2GfotZAcM
 ATUQTyIWOpQHKIP/TWeOwZvlGgm+Ep/M+lyvyO2HQKcAjrD9yr8dKPe4nSWzirFN/vn4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxF9-0004vQ-Lv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxF9-0006l5-KL
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] bitmap: move to/from xenctl_bitmap conversion helpers
Message-Id: <E1kFxF9-0006l5-KL@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a1568878df7d914853ba8c712aaa2315cd33ed3c
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Thu Aug 27 09:52:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Thu Aug 27 09:52:01 2020 +0200

    bitmap: move to/from xenctl_bitmap conversion helpers
    
    A subsequent change will exclude domctl.c from getting built for a
    particular configuration, yet the two functions get used from elsewhere.
    
    While moving the code
    - drop unmotivated uses of min_t(),
    - fix style violations in the moved code,
    - xfree() as early as possible.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/bitmap.c      | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 xen/common/domctl.c      | 85 ----------------------------------------------
 xen/include/xen/bitmap.h |  7 ++++
 xen/include/xen/domain.h |  3 --
 4 files changed, 94 insertions(+), 88 deletions(-)

diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c
index 88768bf8bc..b7aa2db7c7 100644
--- a/xen/common/bitmap.c
+++ b/xen/common/bitmap.c
@@ -9,6 +9,8 @@
 #include <xen/errno.h>
 #include <xen/bitmap.h>
 #include <xen/bitops.h>
+#include <xen/cpumask.h>
+#include <xen/guest_access.h>
 #include <asm/byteorder.h>
 
 /*
@@ -384,3 +386,88 @@ void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
 }
 
 #endif
+
+int bitmap_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_bitmap,
+                            const unsigned long *bitmap, unsigned int nbits)
+{
+    unsigned int guest_bytes, copy_bytes, i;
+    uint8_t zero = 0;
+    int err = 0;
+    uint8_t *bytemap = xmalloc_array(uint8_t, (nbits + 7) / 8);
+
+    if ( !bytemap )
+        return -ENOMEM;
+
+    guest_bytes = (xenctl_bitmap->nr_bits + 7) / 8;
+    copy_bytes  = min(guest_bytes, (nbits + 7) / 8);
+
+    bitmap_long_to_byte(bytemap, bitmap, nbits);
+
+    if ( copy_bytes &&
+         copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes) )
+        err = -EFAULT;
+
+    xfree(bytemap);
+
+    for ( i = copy_bytes; !err && i < guest_bytes; i++ )
+        if ( copy_to_guest_offset(xenctl_bitmap->bitmap, i, &zero, 1) )
+            err = -EFAULT;
+
+    return err;
+}
+
+int xenctl_bitmap_to_bitmap(unsigned long *bitmap,
+                            const struct xenctl_bitmap *xenctl_bitmap,
+                            unsigned int nbits)
+{
+    unsigned int guest_bytes, copy_bytes;
+    int err = 0;
+    uint8_t *bytemap = xzalloc_array(uint8_t, (nbits + 7) / 8);
+
+    if ( !bytemap )
+        return -ENOMEM;
+
+    guest_bytes = (xenctl_bitmap->nr_bits + 7) / 8;
+    copy_bytes  = min(guest_bytes, (nbits + 7) / 8);
+
+    if ( copy_bytes )
+    {
+        if ( copy_from_guest(bytemap, xenctl_bitmap->bitmap, copy_bytes) )
+            err = -EFAULT;
+        if ( (xenctl_bitmap->nr_bits & 7) && (guest_bytes == copy_bytes) )
+            bytemap[guest_bytes - 1] &= ~(0xff << (xenctl_bitmap->nr_bits & 7));
+    }
+
+    if ( !err )
+        bitmap_byte_to_long(bitmap, bytemap, nbits);
+
+    xfree(bytemap);
+
+    return err;
+}
+
+int cpumask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_cpumap,
+                             const cpumask_t *cpumask)
+{
+    return bitmap_to_xenctl_bitmap(xenctl_cpumap, cpumask_bits(cpumask),
+                                   nr_cpu_ids);
+}
+
+int xenctl_bitmap_to_cpumask(cpumask_var_t *cpumask,
+                             const struct xenctl_bitmap *xenctl_cpumap)
+{
+    int err = 0;
+
+    if ( alloc_cpumask_var(cpumask) )
+    {
+        err = xenctl_bitmap_to_bitmap(cpumask_bits(*cpumask), xenctl_cpumap,
+                                      nr_cpu_ids);
+        /* In case of error, cleanup is up to us, as the caller won't care! */
+        if ( err )
+            free_cpumask_var(*cpumask);
+    }
+    else
+        err = -ENOMEM;
+
+    return err;
+}
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 20ef8399bd..5ac6e9c5ca 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -34,91 +34,6 @@
 
 static DEFINE_SPINLOCK(domctl_lock);
 
-static int bitmap_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_bitmap,
-                                   const unsigned long *bitmap,
-                                   unsigned int nbits)
-{
-    unsigned int guest_bytes, copy_bytes, i;
-    uint8_t zero = 0;
-    int err = 0;
-    uint8_t *bytemap = xmalloc_array(uint8_t, (nbits + 7) / 8);
-
-    if ( !bytemap )
-        return -ENOMEM;
-
-    guest_bytes = (xenctl_bitmap->nr_bits + 7) / 8;
-    copy_bytes  = min_t(unsigned int, guest_bytes, (nbits + 7) / 8);
-
-    bitmap_long_to_byte(bytemap, bitmap, nbits);
-
-    if ( copy_bytes != 0 )
-        if ( copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes) )
-            err = -EFAULT;
-
-    for ( i = copy_bytes; !err && i < guest_bytes; i++ )
-        if ( copy_to_guest_offset(xenctl_bitmap->bitmap, i, &zero, 1) )
-            err = -EFAULT;
-
-    xfree(bytemap);
-
-    return err;
-}
-
-int xenctl_bitmap_to_bitmap(unsigned long *bitmap,
-                            const struct xenctl_bitmap *xenctl_bitmap,
-                            unsigned int nbits)
-{
-    unsigned int guest_bytes, copy_bytes;
-    int err = 0;
-    uint8_t *bytemap = xzalloc_array(uint8_t, (nbits + 7) / 8);
-
-    if ( !bytemap )
-        return -ENOMEM;
-
-    guest_bytes = (xenctl_bitmap->nr_bits + 7) / 8;
-    copy_bytes  = min_t(unsigned int, guest_bytes, (nbits + 7) / 8);
-
-    if ( copy_bytes != 0 )
-    {
-        if ( copy_from_guest(bytemap, xenctl_bitmap->bitmap, copy_bytes) )
-            err = -EFAULT;
-        if ( (xenctl_bitmap->nr_bits & 7) && (guest_bytes == copy_bytes) )
-            bytemap[guest_bytes-1] &= ~(0xff << (xenctl_bitmap->nr_bits & 7));
-    }
-
-    if ( !err )
-        bitmap_byte_to_long(bitmap, bytemap, nbits);
-
-    xfree(bytemap);
-
-    return err;
-}
-
-int cpumask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_cpumap,
-                             const cpumask_t *cpumask)
-{
-    return bitmap_to_xenctl_bitmap(xenctl_cpumap, cpumask_bits(cpumask),
-                                   nr_cpu_ids);
-}
-
-int xenctl_bitmap_to_cpumask(cpumask_var_t *cpumask,
-                             const struct xenctl_bitmap *xenctl_cpumap)
-{
-    int err = 0;
-
-    if ( alloc_cpumask_var(cpumask) ) {
-        err = xenctl_bitmap_to_bitmap(cpumask_bits(*cpumask), xenctl_cpumap,
-                                      nr_cpu_ids);
-        /* In case of error, cleanup is up to us, as the caller won't care! */
-        if ( err )
-            free_cpumask_var(*cpumask);
-    }
-    else
-        err = -ENOMEM;
-
-    return err;
-}
-
 static int nodemask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_nodemap,
                                      const nodemask_t *nodemask)
 {
diff --git a/xen/include/xen/bitmap.h b/xen/include/xen/bitmap.h
index c44e009f8c..634a259645 100644
--- a/xen/include/xen/bitmap.h
+++ b/xen/include/xen/bitmap.h
@@ -273,6 +273,13 @@ static inline void bitmap_clear(unsigned long *map, unsigned int start,
 void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits);
 void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits);
 
+struct xenctl_bitmap;
+int xenctl_bitmap_to_bitmap(unsigned long *bitmap,
+                            const struct xenctl_bitmap *xenctl_bitmap,
+                            unsigned int nbits);
+int bitmap_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_bitmap,
+                            const unsigned long *bitmap, unsigned int nbits);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __XEN_BITMAP_H */
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 7e51d361de..1cb205d977 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -27,9 +27,6 @@ struct xen_domctl_getdomaininfo;
 void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info);
 void arch_get_domain_info(const struct domain *d,
                           struct xen_domctl_getdomaininfo *info);
-int xenctl_bitmap_to_bitmap(unsigned long *bitmap,
-                            const struct xenctl_bitmap *xenctl_bitmap,
-                            unsigned int nbits);
 
 /*
  * Arch-specifics.
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxFL-0003U3-GR; Wed, 09 Sep 2020 10:22:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFK-0003Tw-Sm
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:34 +0000
X-Inumbo-ID: 280ff707-5951-4f98-be59-ca7edbd8339d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 280ff707-5951-4f98-be59-ca7edbd8339d;
 Wed, 09 Sep 2020 10:22:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LdPBWp5qkP1oD4z/5Y8zMLFGppfVnWbHV1tol4SQWV0=; b=S5TDBX5o5yf3POM4sdhehrXRGf
 p+6jL6VL2SM4bAf6PP9nQ2GHyrPGiZpxtDfyI4SHuHqqs/FEf40txt4Dnq65a1Oz/xPx/AYllCJ95
 38Z1Z+nqqcZEW0Ara2kN0GzugblKWvqpT2PTRi5/UNAW6JCafdU6kuUobs41N2woSbgU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFJ-0004vX-QB
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFJ-0006lj-P2
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: don't include domctl and alike in shim-exclusive
 builds
Message-Id: <E1kFxFJ-0006lj-P2@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8b5b49ceb3d9aaf87776584fdf0926fa6f39eb2d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Thu Aug 27 09:52:45 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Thu Aug 27 09:52:45 2020 +0200

    x86: don't include domctl and alike in shim-exclusive builds
    
    There is no need for platform-wide, system-wide, or per-domain control
    in this case. Hence avoid including this dead code in the build.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/Makefile        | 10 +++++++---
 xen/arch/x86/mm/paging.c     |  9 ++++++++-
 xen/arch/x86/pv/hypercall.c  |  6 ++++++
 xen/common/Makefile          |  9 ++++++---
 xen/include/asm-x86/paging.h | 11 +++++++++++
 xen/include/xen/domain.h     |  4 ++++
 6 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 93e6dcdc70..1073e454b1 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -23,7 +23,6 @@ obj-$(CONFIG_GDBSX) += debug.o
 obj-y += delay.o
 obj-y += desc.o
 obj-bin-y += dmi_scan.init.o
-obj-y += domctl.o
 obj-y += domain.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain_page.o
@@ -51,7 +50,6 @@ obj-y += numa.o
 obj-y += pci.o
 obj-y += percpu.o
 obj-y += physdev.o x86_64/physdev.o
-obj-y += platform_hypercall.o x86_64/platform_hypercall.o
 obj-y += psr.o
 obj-y += setup.o
 obj-y += shutdown.o
@@ -60,7 +58,6 @@ obj-y += smpboot.o
 obj-y += spec_ctrl.o
 obj-y += srat.o
 obj-y += string.o
-obj-y += sysctl.o
 obj-y += time.o
 obj-y += trace.o
 obj-y += traps.o
@@ -71,6 +68,13 @@ obj-$(CONFIG_TBOOT) += tboot.o
 obj-y += hpet.o
 obj-y += vm_event.o
 obj-y += xstate.o
+
+ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
+obj-y += domctl.o
+obj-y += platform_hypercall.o x86_64/platform_hypercall.o
+obj-y += sysctl.o
+endif
+
 extra-y += asm-macros.i
 
 ifneq ($(CONFIG_HVM),y)
diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c
index 7c265fb5f3..695372783d 100644
--- a/xen/arch/x86/mm/paging.c
+++ b/xen/arch/x86/mm/paging.c
@@ -47,6 +47,8 @@
 /* Per-CPU variable for enforcing the lock ordering */
 DEFINE_PER_CPU(int, mm_lock_level);
 
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
+
 /************************************************/
 /*              LOG DIRTY SUPPORT               */
 /************************************************/
@@ -628,6 +630,8 @@ void paging_log_dirty_init(struct domain *d, const struct log_dirty_ops *ops)
     d->arch.paging.log_dirty.ops = ops;
 }
 
+#endif /* CONFIG_PV_SHIM_EXCLUSIVE */
+
 /************************************************/
 /*           CODE FOR PAGING SUPPORT            */
 /************************************************/
@@ -667,7 +671,7 @@ void paging_vcpu_init(struct vcpu *v)
         shadow_vcpu_init(v);
 }
 
-
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                   XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl,
                   bool_t resuming)
@@ -788,6 +792,7 @@ long paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
     return ret;
 }
+#endif /* CONFIG_PV_SHIM_EXCLUSIVE */
 
 /* Call when destroying a domain */
 int paging_teardown(struct domain *d)
@@ -803,10 +808,12 @@ int paging_teardown(struct domain *d)
     if ( preempted )
         return -ERESTART;
 
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
     /* clean up log dirty resources. */
     rc = paging_free_log_dirty_bitmap(d, 0);
     if ( rc == -ERESTART )
         return rc;
+#endif
 
     /* Move populate-on-demand cache back to domain_list for destruction */
     rc = p2m_pod_empty_cache(d);
diff --git a/xen/arch/x86/pv/hypercall.c b/xen/arch/x86/pv/hypercall.c
index 53a52360fa..20795b4b57 100644
--- a/xen/arch/x86/pv/hypercall.c
+++ b/xen/arch/x86/pv/hypercall.c
@@ -42,7 +42,9 @@ const hypercall_table_t pv_hypercall_table[] = {
     COMPAT_CALL(set_callbacks),
     HYPERCALL(fpu_taskswitch),
     HYPERCALL(sched_op_compat),
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
     COMPAT_CALL(platform_op),
+#endif
     HYPERCALL(set_debugreg),
     HYPERCALL(get_debugreg),
     COMPAT_CALL(update_descriptor),
@@ -72,8 +74,10 @@ const hypercall_table_t pv_hypercall_table[] = {
 #endif
     HYPERCALL(event_channel_op),
     COMPAT_CALL(physdev_op),
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
     HYPERCALL(sysctl),
     HYPERCALL(domctl),
+#endif
 #ifdef CONFIG_KEXEC
     COMPAT_CALL(kexec_op),
 #endif
@@ -89,7 +93,9 @@ const hypercall_table_t pv_hypercall_table[] = {
     HYPERCALL(hypfs_op),
 #endif
     HYPERCALL(mca),
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
     HYPERCALL(arch_1),
+#endif
 };
 
 #undef do_arch_1
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 06881d023c..b3b60a1ba2 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -6,7 +6,6 @@ obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
 obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o
-obj-y += domctl.o
 obj-y += domain.o
 obj-y += event_2l.o
 obj-y += event_channel.o
@@ -26,7 +25,6 @@ obj-$(CONFIG_NEEDS_LIST_SORT) += list_sort.o
 obj-$(CONFIG_LIVEPATCH) += livepatch.o livepatch_elf.o
 obj-$(CONFIG_MEM_ACCESS) += mem_access.o
 obj-y += memory.o
-obj-y += monitor.o
 obj-y += multicall.o
 obj-y += notifier.o
 obj-y += page_alloc.o
@@ -47,7 +45,6 @@ obj-y += spinlock.o
 obj-y += stop_machine.o
 obj-y += string.o
 obj-y += symbols.o
-obj-y += sysctl.o
 obj-y += tasklet.o
 obj-y += time.o
 obj-y += timer.o
@@ -66,6 +63,12 @@ obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo un
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o kernel.o memory.o multicall.o xlat.o)
 
+ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
+obj-y += domctl.o
+obj-y += monitor.o
+obj-y += sysctl.o
+endif
+
 extra-y := symbols-dummy.o
 
 obj-$(CONFIG_COVERAGE) += coverage/
diff --git a/xen/include/asm-x86/paging.h b/xen/include/asm-x86/paging.h
index f53575f3d9..b803efa7b5 100644
--- a/xen/include/asm-x86/paging.h
+++ b/xen/include/asm-x86/paging.h
@@ -154,6 +154,8 @@ struct paging_mode {
 /*****************************************************************************
  * Log dirty code */
 
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
+
 /* get the dirty bitmap for a specific range of pfns */
 void paging_log_dirty_range(struct domain *d,
                             unsigned long begin_pfn,
@@ -202,6 +204,15 @@ struct sh_dirty_vram {
     s_time_t last_dirty;
 };
 
+#else /* !CONFIG_PV_SHIM_EXCLUSIVE */
+
+static inline void paging_log_dirty_init(struct domain *d,
+                                         const struct log_dirty_ops *ops) {}
+static inline void paging_mark_dirty(struct domain *d, mfn_t gmfn) {}
+static inline void paging_mark_pfn_dirty(struct domain *d, pfn_t pfn) {}
+
+#endif /* CONFIG_PV_SHIM_EXCLUSIVE */
+
 /*****************************************************************************
  * Entry points into the paging-assistance code */
 
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 1cb205d977..cde0d9c7fe 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -125,6 +125,10 @@ struct vnuma_info {
     struct xen_vmemrange *vmemrange;
 };
 
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 void vnuma_destroy(struct vnuma_info *vnuma);
+#else
+static inline void vnuma_destroy(struct vnuma_info *vnuma) { ASSERT(!vnuma); }
+#endif
 
 #endif /* __XEN_DOMAIN_H__ */
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxFV-0003V7-IS; Wed, 09 Sep 2020 10:22:45 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFU-0003Uz-Pa
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:44 +0000
X-Inumbo-ID: b02b94af-354b-40d6-be54-3d3a1d9a2810
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b02b94af-354b-40d6-be54-3d3a1d9a2810;
 Wed, 09 Sep 2020 10:22:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=W37vBffjt/z01xAppQCTiaxtlRn7gpoc4bm0ErTVmtU=; b=jFHix+vRWCdeLov+ZqnE3f0wlV
 xbbParCPHLEbIpVhbLA04gCDzLwHeitf6LG2woa0yfwj4GhmE2rNp4UnSHDpq8RRNxGbFJsW2Q02U
 CvYs/+ruT8Ikw+aEgT+n5lid4cTxp0mkIDQe8U2l3m74+jpSL/U+gR/msAqscCULKmpY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFT-0004ve-U7
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFT-0006mA-TC
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: use constant flags for section .init.rodata
Message-Id: <E1kFxFT-0006mA-TC@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d2770047a277ccdc7924fb99d1b051eeb0d5a90f
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Thu Aug 27 09:53:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Thu Aug 27 09:53:46 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 8b57a00040..1e880eb9f6 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -967,7 +967,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -1012,5 +1012,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:22:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:22:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxFj-0003WN-Ki; Wed, 09 Sep 2020 10:22:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFi-0003WG-2J
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:58 +0000
X-Inumbo-ID: 7efcfda6-3de5-461e-a24e-affb7ac266e0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 7efcfda6-3de5-461e-a24e-affb7ac266e0;
 Wed, 09 Sep 2020 10:22:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=oENxBh1OYfwtafY3clxfthqSCa5JghhmkwSfgbp7AXo=; b=H8LxdP4wXbl15mqh99uFFmqymW
 ANXBoNBsgf5slqXt79qmRfN70i5A0feApPKfReWA2OYgIWGkZ2H/79vVKf3ZPzM3/iNmwsOdYfFsz
 RF5dsUiY6S/2DeSZMM2gqGcDpyLQA54HrU6VUkzmrOIYMl0c9WWPigVmtDIgDqb2+cvA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFe-0004vo-1M
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:54 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFe-0006mc-0Y
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:22:54 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] MAINTAINERS: Update my email address
Message-Id: <E1kFxFe-0006mc-0Y@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:22:54 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 86c076f06526e410c3d23af5e5d48511ae204508
Author:     Ian Jackson <iwj@xenproject.org>
AuthorDate: Wed Aug 26 15:47:19 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 09:33:02 2020 +0000

    MAINTAINERS: Update my email address
    
    I am changing my email address.  (My affiliation to Citrix remains
    unchanged.)  See
       https://xenbits.xen.org/people/iwj/2020/email-transition.txt
    for a signed confirmation with full details.
    
    Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
    Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 MAINTAINERS | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 978fc2fe72..ffe2310294 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -353,7 +353,7 @@ F:	xen/arch/x86/machine_kexec.c
 F:	xen/arch/x86/x86_64/kexec_reloc.S
 
 LIBXENLIGHT
-M:	Ian Jackson <ian.jackson@eu.citrix.com>
+M:	Ian Jackson <iwj@xenproject.org>
 M:	Wei Liu <wl@xen.org>
 M:	Anthony PERARD <anthony.perard@citrix.com>
 S:	Supported
@@ -413,7 +413,7 @@ S:	Supported
 F:	tools/python
 
 QEMU-DM
-M:	Ian Jackson <ian.jackson@eu.citrix.com>
+M:	Ian Jackson <iwj@xenproject.org>
 S:	Supported
 T:	git https://xenbits.xenproject.org/git-http/qemu-xen-traditional.git
 
@@ -465,7 +465,7 @@ F:	xen/arch/arm/tee/
 F:	xen/include/asm-arm/tee
 
 TOOLSTACK
-M:	Ian Jackson <ian.jackson@eu.citrix.com>
+M:	Ian Jackson <iwj@xenproject.org>
 M:	Wei Liu <wl@xen.org>
 S:	Supported
 F:	autogen.sh
@@ -602,7 +602,7 @@ F:	docs/misc/xsm-flask.txt
 THE REST
 M:	Andrew Cooper <andrew.cooper3@citrix.com>
 M:	George Dunlap <george.dunlap@citrix.com>
-M:	Ian Jackson <ian.jackson@eu.citrix.com>
+M:	Ian Jackson <iwj@xenproject.org>
 M:	Jan Beulich <jbeulich@suse.com>
 M:	Julien Grall <julien@xen.org>
 M:	Stefano Stabellini <sstabellini@kernel.org>
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxFw-0003YE-MT; Wed, 09 Sep 2020 10:23:12 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFv-0003Y5-Qo
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:11 +0000
X-Inumbo-ID: 72c50e5c-6a35-4d14-a160-519fb6f7a2cc
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 72c50e5c-6a35-4d14-a160-519fb6f7a2cc;
 Wed, 09 Sep 2020 10:23:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=bnhBLFgEJ51NYlsYZ/W3TkLwVlhs5qVVQoviNDBjIro=; b=XE+ZDm2SDKZQEBG+JpIqfChDc0
 GgR1LVtMx+97jWdlN3KADXZvy8y5SElodknMp2iGQ8AG7gH2JwueiCDtb219yZVpazgTN+9E//A7/
 rsBM3ALFjzZibOpozc3Cb1O7B20zZGMHxWbjtRDXQl+GzWjp+0p+U/wc7+RM1LbGgCeA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFo-0004wZ-4w
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFo-0006nJ-40
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/firmware: Fix typo in uninstall target
Message-Id: <E1kFxFo-0006nJ-40@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a623841b85bde261d0627676c7cff7745f107f3c
Author:     Hubert Jasudowicz <hubert.jasudowicz@cert.pl>
AuthorDate: Tue Aug 18 21:29:48 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 09:35:35 2020 +0000

    tools/firmware: Fix typo in uninstall target
    
    When ipxe.bin is missing, make uninstall will fail due to
    wrong switch (-r) passed to rm command. Replace it with -f.
    
    Signed-off-by: Hubert Jasudowicz <hubert.jasudowicz@cert.pl>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/firmware/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/firmware/Makefile b/tools/firmware/Makefile
index 809a5fd025..1f27117794 100644
--- a/tools/firmware/Makefile
+++ b/tools/firmware/Makefile
@@ -72,7 +72,7 @@ ifeq ($(CONFIG_OVMF),y)
 	rm -f $(INST_DIR)/ovmf.bin
 endif
 ifeq ($(CONFIG_IPXE),y)
-	rm -r $(INST_DIR)/ipxe.bin
+	rm -f $(INST_DIR)/ipxe.bin
 endif
 ifeq ($(CONFIG_PV_SHIM),y)
 	rm -f $(INST_DIR)/xen-shim
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxG0-0003Yq-Nu; Wed, 09 Sep 2020 10:23:16 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxFz-0003Yg-5a
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:15 +0000
X-Inumbo-ID: bfda53e4-611e-48f2-b0a4-17a70fcc07ff
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bfda53e4-611e-48f2-b0a4-17a70fcc07ff;
 Wed, 09 Sep 2020 10:23:14 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ROE7r8gHDwgYkzKLg6JqVjLatfbf0LxiJCHZwXmBuzk=; b=no4ludRDDazJdSL1mBVKSI2fdN
 GXJi+gcTyrmLSrFAwCJplHXSZ7hwdqG1nEpyMiAHV5+rphg206+D3Avqm6JVjXva3tsMWinbHMROg
 rifnKRNhVjT4FpV4KrWPrv2xFctIAfjnZ0FsTiH3BcMeUfviN/b/Fe2ypLNkctrwgFmM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFy-0004wm-8O
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxFy-0006nn-7Y
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] libxl: workaround gcc 10.2 maybe-uninitialized warning
Message-Id: <E1kFxFy-0006nn-7Y@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d25cc3ec93ebda030349045d2c7fa14ffde07ed7
Author:     Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
AuthorDate: Wed Aug 19 04:00:35 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 09:36:39 2020 +0000

    libxl: workaround gcc 10.2 maybe-uninitialized warning
    
    It seems xlu_pci_parse_bdf has a state machine that is too complex for
    gcc to understand. The build fails with:
    
        libxlu_pci.c: In function 'xlu_pci_parse_bdf':
        libxlu_pci.c:32:18: error: 'func' may be used uninitialized in this function [-Werror=maybe-uninitialized]
           32 |     pcidev->func = func;
              |     ~~~~~~~~~~~~~^~~~~~
        libxlu_pci.c:51:29: note: 'func' was declared here
           51 |     unsigned dom, bus, dev, func, vslot = 0;
              |                             ^~~~
        libxlu_pci.c:31:17: error: 'dev' may be used uninitialized in this function [-Werror=maybe-uninitialized]
           31 |     pcidev->dev = dev;
              |     ~~~~~~~~~~~~^~~~~
        libxlu_pci.c:51:24: note: 'dev' was declared here
           51 |     unsigned dom, bus, dev, func, vslot = 0;
              |                        ^~~
        libxlu_pci.c:30:17: error: 'bus' may be used uninitialized in this function [-Werror=maybe-uninitialized]
           30 |     pcidev->bus = bus;
              |     ~~~~~~~~~~~~^~~~~
        libxlu_pci.c:51:19: note: 'bus' was declared here
           51 |     unsigned dom, bus, dev, func, vslot = 0;
              |                   ^~~
        libxlu_pci.c:29:20: error: 'dom' may be used uninitialized in this function [-Werror=maybe-uninitialized]
           29 |     pcidev->domain = domain;
              |     ~~~~~~~~~~~~~~~^~~~~~~~
        libxlu_pci.c:51:14: note: 'dom' was declared here
           51 |     unsigned dom, bus, dev, func, vslot = 0;
              |              ^~~
        cc1: all warnings being treated as errors
    
    Workaround it by setting the initial value to invalid value (0xffffffff)
    and then assert on each value being set. This way we mute the gcc
    warning, while still detecting bugs in the parse code.
    
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libxl/libxlu_pci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxlu_pci.c b/tools/libxl/libxlu_pci.c
index 7947687661..e2709c5f89 100644
--- a/tools/libxl/libxlu_pci.c
+++ b/tools/libxl/libxlu_pci.c
@@ -45,10 +45,11 @@ static int pcidev_struct_fill(libxl_device_pci *pcidev, unsigned int domain,
 #define STATE_TYPE      9
 #define STATE_RDM_STRATEGY      10
 #define STATE_RESERVE_POLICY    11
+#define INVALID         0xffffffff
 int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str)
 {
     unsigned state = STATE_DOMAIN;
-    unsigned dom, bus, dev, func, vslot = 0;
+    unsigned dom = INVALID, bus = INVALID, dev = INVALID, func = INVALID, vslot = 0;
     char *buf2, *tok, *ptr, *end, *optkey = NULL;
 
     if ( NULL == (buf2 = ptr = strdup(str)) )
@@ -170,6 +171,8 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str
     if ( tok != ptr || state != STATE_TERMINAL )
         goto parse_error;
 
+    assert(dom != INVALID && bus != INVALID && dev != INVALID && func != INVALID);
+
     /* Just a pretty way to fill in the values */
     pcidev_struct_fill(pcidev, dom, bus, dev, func, vslot << 3);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:26 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGA-0003a6-Pl; Wed, 09 Sep 2020 10:23:26 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxG9-0003Zt-9P
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:25 +0000
X-Inumbo-ID: bebeb8c2-55f3-4c66-9d2d-9811f296b43e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bebeb8c2-55f3-4c66-9d2d-9811f296b43e;
 Wed, 09 Sep 2020 10:23:24 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=pjPxkoyCSqvgPMldo+WPtR3JknQama7magSZDYITtVI=; b=OYDX07QyhlV0txehCY9U5TIiyR
 uk+CthBerHCZWdvtNI1kSy6uk84KzQIBfKNSlBMQ0yQYF7SgaR4wr1+InLUbunr16SXjhuuhpMVXQ
 QH3/9bmURlJJlvMBwHZRItOoeEaa1Cl0yqwFaWM1ga+KnocHLIx8Bg+esomN7q/ZEjxw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxG8-0004x0-Cc
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:24 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxG8-0006oD-BC
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:24 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] libxl: fix -Werror=stringop-truncation in
 libxl__prepare_sockaddr_un
Message-Id: <E1kFxG8-0006oD-BC@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:24 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fff1b7f50e75ad9535c86f3fcf425b4945c50a1c
Author:     Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
AuthorDate: Wed Aug 19 04:00:36 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 09:38:47 2020 +0000

    libxl: fix -Werror=stringop-truncation in libxl__prepare_sockaddr_un
    
    In file included from /usr/include/string.h:495,
                     from libxl_internal.h:38,
                     from libxl_utils.c:20:
    In function 'strncpy',
        inlined from 'libxl__prepare_sockaddr_un' at libxl_utils.c:1262:5:
    /usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation]
      106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libxl/libxl_utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index f360f5e228..b039143b8a 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -1252,14 +1252,14 @@ int libxl__prepare_sockaddr_un(libxl__gc *gc,
                                struct sockaddr_un *un, const char *path,
                                const char *what)
 {
-    if (sizeof(un->sun_path) <= strlen(path)) {
+    if (sizeof(un->sun_path) - 1 <= strlen(path)) {
         LOG(ERROR, "UNIX socket path '%s' is too long for %s", path, what);
-        LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path));
+        LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path) - 1);
         return ERROR_INVAL;
     }
     memset(un, 0, sizeof(struct sockaddr_un));
     un->sun_family = AF_UNIX;
-    strncpy(un->sun_path, path, sizeof(un->sun_path));
+    strncpy(un->sun_path, path, sizeof(un->sun_path) - 1);
     return 0;
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:36 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGK-0003bT-Su; Wed, 09 Sep 2020 10:23:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxGJ-0003bI-Be
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:35 +0000
X-Inumbo-ID: c56f765d-a325-40e6-8b4c-930156b42fca
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c56f765d-a325-40e6-8b4c-930156b42fca;
 Wed, 09 Sep 2020 10:23:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Y6BmCMLXYnL+jyTBDxD/wbP60B3g/IYUbYADLWePRmA=; b=Z/7aBFUISZ76PT5LvmKf/EhpRz
 8i5IJqs9Qr3xE/OEARu6iZdKlJPzSXGnhz5VmE1Rv1u4TQXAqsCBQZCILyC2NXfm4FBGtWaB4JFo4
 HxzuRlrSfLR7ynmhYILm3SAxS5lpmRsLgSdMYrGDJuZeBmGGSmNkWo1mmcMcDcyrs7Rs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGI-0004x8-GR
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:34 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGI-0006p8-FQ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:34 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] public/io/netif: specify MTU override node
Message-Id: <E1kFxGI-0006p8-FQ@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:34 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f9d25fa3faf66bcd4265fe01f23c5fd724e27601
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:01:55 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:03:54 2020 +0000

    public/io/netif: specify MTU override node
    
    There is currently no documentation to state what MTU a frontend should
    adertise to its network stack. It has however long been assumed that the
    default value of 1500 is correct.
    
    This patch specifies a mechanism to allow the tools to set the MTU via a
    xenstore node in the frontend area and states that the absence of that node
    means the frontend should assume an MTU of 1500 octets.
    
    NOTE: The Windows PV frontend has used an MTU sampled from the xenstore
          node specified in this patch.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Reviewed-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 docs/misc/xenstore-paths.pandoc |  3 +++
 xen/include/public/io/netif.h   | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/docs/misc/xenstore-paths.pandoc b/docs/misc/xenstore-paths.pandoc
index 766e8008dc..5cd5c8a3b9 100644
--- a/docs/misc/xenstore-paths.pandoc
+++ b/docs/misc/xenstore-paths.pandoc
@@ -298,6 +298,9 @@ A virtual keyboard device frontend. Described by
 A virtual network device frontend. Described by
 [xen/include/public/io/netif.h][NETIF]
 
+NOTE: ~/device/vif/$DEVID/mtu can be used to inform the frontend of an
+      increased MTU. (The default MTU is 1500 octets).
+
 #### ~/device/vscsi/$DEVID/* []
 
 A virtual scsi device frontend. Described by
diff --git a/xen/include/public/io/netif.h b/xen/include/public/io/netif.h
index 9fcf91a2fe..00dd258712 100644
--- a/xen/include/public/io/netif.h
+++ b/xen/include/public/io/netif.h
@@ -204,6 +204,18 @@
  * present).
  */
 
+/*
+ * MTU
+ * ===
+ *
+ * The toolstack may set a value of MTU for the frontend by setting the
+ * /local/domain/<domid>/device/vif/<vif>/mtu node with the MTU value in
+ * octets. If this node is absent the frontend should assume an MTU value
+ * of 1500 octets. A frontend is also at liberty to ignore this value so
+ * it is only suitable for informing the frontend that a packet payload
+ * >1500 octets is permitted.
+ */
+
 /*
  * Hash types
  * ==========
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:46 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGU-0003cV-UZ; Wed, 09 Sep 2020 10:23:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxGT-0003cJ-FO
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:45 +0000
X-Inumbo-ID: 6689a2f2-156c-4949-a07f-42c25d05d061
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6689a2f2-156c-4949-a07f-42c25d05d061;
 Wed, 09 Sep 2020 10:23:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ZbkCKoC1hwvwHEl2cUkvhbQf4bTpZRSIPzxx7CwKE9c=; b=qPo5DSTpThWXA/bnSpDsm/zp3Q
 Rgnhq8HLi6Y3Gga5V9ZzlwSFjJ/keB7g/mOUlRd7uFKwtJaAL9ZNAohCNujuROpXXziLYKsoeJnmN
 Hk44KRWvdJPEsIv/NohuyVgJzBQCoNDVPWWwEyaDeFLmYiV0Ij5vrV0v7+QXBOlcAgy8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGS-0004xG-K9
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:44 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGS-0006pg-J7
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:44 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug/Linux: re-factor add_to_bridge() in
 xen-network-common.sh
Message-Id: <E1kFxGS-0006pg-J7@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:44 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 70fea87a3a595632cd0a17a8388a43b95cbe7af7
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:01:56 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:04 2020 +0000

    tools/hotplug/Linux: re-factor add_to_bridge() in xen-network-common.sh
    
    Remove duplication of 'ip link set dev'. It is perfectly fine to call it
    even if the device has already been added to the bridge.
    
    NOTE: This patch also adds code to write a debug log entry if the device
          was already on the bridge.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/xen-network-common.sh | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index 8dd3a62068..ec3bd4ec4a 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -126,16 +126,18 @@ add_to_bridge () {
     local bridge=$1
     local dev=$2
 
-    # Don't add $dev to $bridge if it's already on a bridge.
-    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
-	ip link set dev ${dev} up || true
-	return
-    fi
-    if which brctl >&/dev/null; then
-        brctl addif ${bridge} ${dev}
+    # Don't add $dev to $bridge if it's already on the bridge.
+    if [ ! -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "adding $dev to bridge $bridge"
+        if which brctl >&/dev/null; then
+            brctl addif ${bridge} ${dev}
+        else
+            ip link set ${dev} master ${bridge}
+        fi
     else
-        ip link set ${dev} master ${bridge}
+        log debug "$dev already on bridge $bridge"
     fi
+
     ip link set dev ${dev} up
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:23:57 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:23:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGf-0003dT-01; Wed, 09 Sep 2020 10:23:57 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxGd-0003dH-Ht
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:55 +0000
X-Inumbo-ID: aab00577-c6f9-43ac-806a-04ca09511601
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id aab00577-c6f9-43ac-806a-04ca09511601;
 Wed, 09 Sep 2020 10:23:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mxIvIPF4COXVidY58Bbligt6hzfEuUCE5nPKWi50v1k=; b=plLx/W+Ua0Ri0eDt8NDjok3RQW
 v9eBRuzj1ZHa3LbP61T76/J4AzfLXGAvBDHf6psrm91Z/L0zDdJJrr2nRhEHw92/yOz1W/TdnsBlH
 nTiw+NB38CgqHvYPWGsRno6rwQFV2HRZ3GeJ8hDuVo9rvFeHsb/1UBOWVf288xtsQmEA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGc-0004xO-NU
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:54 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGc-0006qG-Mj
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:23:54 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug/Linux: add remove_from_bridge()
Message-Id: <E1kFxGc-0006qG-Mj@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:23:54 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit bb13d936d2500f303c8fbf9420da9ed340818294
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:01:57 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:10 2020 +0000

    tools/hotplug/Linux: add remove_from_bridge()
    
    This patch adds a remove_from_bridge() function into xen-network-common.sh
    to partner with the existing add_to_bridge() function. The vif-bridge
    script is then modified to use it.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-bridge            |  7 +------
 tools/hotplug/Linux/xen-network-common.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index e722090ca8..c3e409926d 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -84,12 +84,7 @@ case "$command" in
         ;;
 
     offline)
-        if which brctl >&/dev/null; then
-            do_without_error brctl delif "$bridge" "$dev"
-        else
-            do_without_error ip link set "$dev" nomaster
-        fi
-        do_without_error ifconfig "$dev" down
+        remove_from_bridge "$bridge" "$dev"
         ;;
 
     add)
diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index ec3bd4ec4a..6a0904361f 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -141,6 +141,25 @@ add_to_bridge () {
     ip link set dev ${dev} up
 }
 
+remove_from_bridge () {
+    local bridge=$1
+    local dev=$2
+
+    do_without_error ip link set dev ${dev} down
+
+    # Don't remove $dev from $bridge if it's not on the bridge.
+    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "removing $dev from bridge $bridge"
+        if which brctl >&/dev/null; then
+            do_without_error brctl delif ${bridge} ${dev}
+        else
+            do_without_error ip link set ${dev} nomaster
+        fi
+    else
+        log debug "$dev not on bridge $bridge"
+    fi
+}
+
 # Usage: set_mtu bridge dev
 set_mtu () {
     local bridge=$1
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:07 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:07 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGp-0003ed-1d; Wed, 09 Sep 2020 10:24:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxGo-0003eR-1h
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:06 +0000
X-Inumbo-ID: 3b5910bf-f9ec-40b6-90e0-d0b9f5f77101
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3b5910bf-f9ec-40b6-90e0-d0b9f5f77101;
 Wed, 09 Sep 2020 10:24:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=yITYWjYSwneDcNPAKBW32wEGjSGl1nPd9GGOLaH00EM=; b=A2UvSFF7+8ttdFsFN3nZ80nApn
 p57fTEihVQaKbjPBZv7mcDRctqTCNlzAMJbksyoAmJhG/XsbJbC8eKGBtbiNKjTuIQVlfO5NK+Nj6
 ZbqvN1MQVliuijcUGlkzjiFFWzM2OIScdfkiCz4hYsf8tcmqaaixz7t8PrwW8ZXts374=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGm-0004yQ-RJ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGm-0006qr-QT
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug/Linux: remove code duplication in
 vif-bridge
Message-Id: <E1kFxGm-0006qr-QT@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b51715f02bf916c9cd6740b1047ba4396d85bbb0
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:01:58 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:14 2020 +0000

    tools/hotplug/Linux: remove code duplication in vif-bridge
    
    The 'add' and 'online' cases do exactly the same thing so have 'add' simply
    fall through to 'online'.
    
    NOTE: This patch also adds in the missing 'remove' case, which falls though
          to 'offline'. (The former is passed for 'tap' devices, the latter for
          'vif' devices).
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-bridge | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index c3e409926d..e1d7c49788 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -77,21 +77,18 @@ then
 fi
 
 case "$command" in
+    add)
+        ;&
     online)
         setup_virtual_bridge_port "$dev"
         set_mtu "$bridge" "$dev"
         add_to_bridge "$bridge" "$dev"
         ;;
-
+    remove)
+        ;&
     offline)
         remove_from_bridge "$bridge" "$dev"
         ;;
-
-    add)
-        setup_virtual_bridge_port "$dev"
-        set_mtu "$bridge" "$dev"
-        add_to_bridge "$bridge" "$dev"
-        ;;
 esac
 
 handle_iptable
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxGz-0003g1-3E; Wed, 09 Sep 2020 10:24:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxGx-0003ft-Sh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:15 +0000
X-Inumbo-ID: 59e641de-f150-4657-b64c-73cf510ebfba
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 59e641de-f150-4657-b64c-73cf510ebfba;
 Wed, 09 Sep 2020 10:24:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LveUlXt1KQRZonhbNAn3G+ehaLnfGtqy7dsdON2tLHQ=; b=YZWZ8FQNZoHeF+YeieYFbvWeBl
 Q2EM0P4hJIW/3USjl06NkskQc7P5LksllKLEgWlrIyTvj0KYNQtS/6qQHqn6Hs+E3WhPh6hROAJjH
 1bMQG+ggBDg+V1CscTIUUfzQ9I0iToE7Na0RSDGM+MPRJ1Ooc0/rzoOrz16pnPZPNKhk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGw-0004yT-VZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxGw-0006rX-UD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] libxl: wire the libxl_device_nic 'mtu' value into
 xenstore
Message-Id: <E1kFxGw-0006rX-UD@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 22cdff931d1239156dea74d8b4a50e91e44c5817
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:01:59 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:17 2020 +0000

    libxl: wire the libxl_device_nic 'mtu' value into xenstore
    
    Currently the 'mtu' field of libxl_device_nic objects is effectively ignored:
    It is set by libxl__device_nic_setdefault() to a slightly odd default value of
    1492 but otherwise ignored.
    
    This patch changes the default value to a more conventional 1500 and modifies
    libxl__set_xenstore_nic() to write the value into an 'mtu' node in the
    xenstore backend area (if it is a non-default value), as well as a read-only
    node of the same name in the frontend area.
    
    The backend node is used to set the value of 'mtu' in
    libxl__nic_from_xenstore(), when retrieving the configuration.
    
    NOTE: There is currently no way to set a non-default value of 'mtu', hence
          the backend node is never written. This, however, will be addressed
          by a subsequent patch.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/libxl_nic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c
index 07880b39e1..0e5d120ae9 100644
--- a/tools/libxl/libxl_nic.c
+++ b/tools/libxl/libxl_nic.c
@@ -53,13 +53,15 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
+#define LIBXL_DEVICE_NIC_MTU_DEFAULT 1500
+
 static int libxl__device_nic_setdefault(libxl__gc *gc, uint32_t domid,
                                         libxl_device_nic *nic, bool hotplug)
 {
     int rc;
 
     if (!nic->mtu)
-        nic->mtu = 1492;
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
     if (!nic->model) {
         nic->model = strdup("rtl8139");
         if (!nic->model) return ERROR_NOMEM;
@@ -223,6 +225,11 @@ static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
                             nic->rate_interval_usecs));
     }
 
+    if (nic->mtu != LIBXL_DEVICE_NIC_MTU_DEFAULT) {
+        flexarray_append(back, "mtu");
+        flexarray_append(back, GCSPRINTF("%u", nic->mtu));
+    }
+    
     flexarray_append(back, "bridge");
     flexarray_append(back, libxl__strdup(gc, nic->bridge));
     flexarray_append(back, "handle");
@@ -237,6 +244,9 @@ static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
     flexarray_append(front, GCSPRINTF(
                                     LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
 
+    flexarray_append(ro_front, "mtu");
+    flexarray_append(ro_front, GCSPRINTF("%u", nic->mtu));
+
     return 0;
 }
 
@@ -275,7 +285,20 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path,
     rc = libxl__backendpath_parse_domid(gc, tmp, &nic->backend_domid);
     if (rc) goto out;
 
-    /* nic->mtu = */
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                GCSPRINTF("%s/mtu", libxl_path), &tmp);
+    if (rc) goto out;
+    if (tmp) {
+        char *endptr;
+
+        nic->mtu = strtol(tmp, &endptr, 10);
+        if (*endptr != '\0') {
+            rc = ERROR_INVAL;
+            goto out;
+        }
+    } else {
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
+    }
 
     rc = libxl__xs_read_checked(gc, XBT_NULL,
                                 GCSPRINTF("%s/mac", libxl_path), &tmp);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxH9-0003h0-4x; Wed, 09 Sep 2020 10:24:27 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxH7-0003gr-VQ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:26 +0000
X-Inumbo-ID: 5af508a8-71d6-4469-93ed-744760af1b63
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5af508a8-71d6-4469-93ed-744760af1b63;
 Wed, 09 Sep 2020 10:24:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=R0V7uydwIEoAWCxFyQwDtYrmJyfjIgyOUQe9tty8sGk=; b=ZnkR1NOJMX3WpcwyMdxAuKoO/k
 9R4wCKZ6hP/bNyItt8u2cHzkspnjctWXtUq5r2uTKRwQNbtIUZJSIb1w5W70ycARzHbRDgOdruxeW
 AksGGgnF/1E+eoeqRE5DUilJb8urm3MBHipfEPO5aO1KPnCcUX48JPMMGvGWXhk33X2o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxH7-0004yb-3n
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxH7-0006s1-25
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug/Linux: modify set_mtu() to optionally use
 a configured value...
Message-Id: <E1kFxH7-0006s1-25@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c7c6de0cb9b00efc203790743ef8c37ba113d3ee
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:02:00 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:21 2020 +0000

    tools/hotplug/Linux: modify set_mtu() to optionally use a configured value...
    
    ...and also inform the frontend.
    
    The set_mtu() function in xen-network-common.sh currently sets the backend
    vif MTU to match that of the bridge.
    
    A prior patch added code into libxl such that a tools-configured 'mtu' value
    may be present in the xenstore backend area. If the node is present in
    xenstore then it should be authoritative. Hence set_mtu() is modified to only
    read the MTU of the bridge if it is not present.
    
    The function is also modified to write whatever value it applies to the
    backend vif into the xenstore frontend area where is may then be used to
    configure the frontend network stack.
    
    NOTE: There is also a small modification replacing '$mtu' with '${mtu}'
          for style consistency.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-bridge            |  2 +-
 tools/hotplug/Linux/xen-network-common.sh | 28 ++++++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index e1d7c49788..b99cc82a21 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -81,7 +81,7 @@ case "$command" in
         ;&
     online)
         setup_virtual_bridge_port "$dev"
-        set_mtu "$bridge" "$dev"
+        set_mtu "$bridge" "$dev" "$type_if"
         add_to_bridge "$bridge" "$dev"
         ;;
     remove)
diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index 6a0904361f..82ee70aab4 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -164,9 +164,33 @@ remove_from_bridge () {
 set_mtu () {
     local bridge=$1
     local dev=$2
-    mtu="`ip link show dev ${bridge}| awk '/mtu/ { print $5 }'`"
+    local type_if=$3
+
+    XENBUS_PATH="${XENBUS_PATH:?}"
+
+    local mtu=$(xenstore_read_default "$XENBUS_PATH/mtu" "")
+    if [ -z "$mtu" ]
+    then
+        mtu="`ip link show dev ${bridge}| awk '/mtu/ { print $5 }'`"
+        if [ -n "$mtu" ]
+        then
+            log debug "$bridge MTU is $mtu"
+        fi
+    fi
     if [ -n "$mtu" ] && [ "$mtu" -gt 0 ]
     then
-            ip link set dev ${dev} mtu $mtu || :
+        log debug "setting $dev MTU to $mtu"
+        ip link set dev ${dev} mtu ${mtu} || :
+
+        if [ ${type_if} = vif ]
+        then
+            local dev_=${dev#vif}
+            local domid=${dev_%.*}
+            local devid=${dev_#*.}
+
+            local FRONTEND_PATH="/local/domain/$domid/device/vif/$devid"
+
+            xenstore_write "$FRONTEND_PATH/mtu" ${mtu}
+        fi
     fi
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxHJ-0003i4-6m; Wed, 09 Sep 2020 10:24:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxHI-0003hu-16
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:36 +0000
X-Inumbo-ID: 1955b847-794e-4b0b-8701-8cd6309a2437
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1955b847-794e-4b0b-8701-8cd6309a2437;
 Wed, 09 Sep 2020 10:24:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UQlgwwE3WoIGSCMI56yzSyEONeS7pO6gDOyF+36El8Y=; b=NxObklLNEJ8FyIYeuIDh/THE/4
 Z7Kqh2nYQx/qMZKv58WQNEqi/KkHyxY323p4yCyszxlXvXu2L6pfNhV2+KY6h8TsLn8cnZNnyHQ0v
 pytZVQ66jPwiqJhF/1mhWq7W1GlTQkX/J4ABNhZnRvjjcoDQJ+/4gF4sGYsYmQcHNZvI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHH-0004yk-7a
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHH-0006sX-6m
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xl: add 'mtu' option to network configuration
Message-Id: <E1kFxHH-0006sX-6m@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 812c8e01dbb352b93ae93d24cd0df7dee139c290
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:02:01 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:25 2020 +0000

    xl: add 'mtu' option to network configuration
    
    This patch adds code to parse a value for MTU from the network configuration
    if it is present. The documentation in xl-network-configuration.5.pod is
    also modified accordingly.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 docs/man/xl-network-configuration.5.pod | 6 ++++++
 tools/xl/xl_cmdtable.c                  | 2 +-
 tools/xl/xl_parse.c                     | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/docs/man/xl-network-configuration.5.pod b/docs/man/xl-network-configuration.5.pod
index 0ac24c4a18..af058d4d3c 100644
--- a/docs/man/xl-network-configuration.5.pod
+++ b/docs/man/xl-network-configuration.5.pod
@@ -249,3 +249,9 @@ on the underlying netback implementation.
 Specifies the devid manually instead of letting xl choose the lowest index available.
 
 NOTE: This should not be set unless you have a reason to.
+
+=head2 mtu
+
+Specifies the MTU (i.e. the maximum size of an IP payload, exclusing headers). The
+default value is 1500 but, if the VIF is attached to a bridge, it will be set to match
+unless overridden by this parameter.
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 08335394e5..2b8e1b321a 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -338,7 +338,7 @@ struct cmd_spec cmd_table[] = {
       "Create a new virtual network device",
       "<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] "
       "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
-      "[rate=<rate>] [model=<model>] [accel=<accel>]",
+      "[rate=<rate>] [model=<model>] [accel=<accel>] [mtu=<mtu>]",
     },
     { "network-list",
       &main_networklist, 0, 0,
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 61b4ef7b7e..cae8eb679c 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -563,6 +563,8 @@ int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token)
         fprintf(stderr, "the accel parameter for vifs is currently not supported\n");
     } else if (MATCH_OPTION("devid", token, oparg)) {
         nic->devid = parse_ulong(oparg);
+    } else if (MATCH_OPTION("mtu", token, oparg)) {
+        nic->mtu = parse_ulong(oparg);
     } else {
         fprintf(stderr, "unrecognized argument `%s'\n", token);
         return 1;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxHT-0003jK-9n; Wed, 09 Sep 2020 10:24:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxHS-0003j8-5D
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:46 +0000
X-Inumbo-ID: d1d497c0-8602-436e-a1d6-2c3721d06e57
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d1d497c0-8602-436e-a1d6-2c3721d06e57;
 Wed, 09 Sep 2020 10:24:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tyX6h8XeB5wUxlJc7HzDTlCHrlHI+enBpHPVA6snIvY=; b=kstIaHv2O3JZmIUTBemmAE3OyR
 aAVz7Y7bfPBITZ6dxE3O5jQUYtYYBqv9K877Mht1yFLWSWzXFu0yVbrTR1lZn2fS+g/gIb8Hhj/SH
 60GeeSqGPDYXWbcyuOpzHoDOyHTyHFZrEX773pHVgdXOw8RFzLnDdJvlfzZWh6xSGyyo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHR-0004yr-BG
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHR-0006t4-AR
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] remove netchannel2 hotplug script... ancient history
Message-Id: <E1kFxHR-0006t4-AR@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 484fca9569f03fbcb0fa5704f59164f95b0a8fcb
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Aug 11 09:02:02 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 10:04:28 2020 +0000

    remove netchannel2 hotplug script... ancient history
    
    configuration is not parsed by libxl so there is no reason for the hotplug
    script to exist
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/Makefile |  1 -
 tools/hotplug/Linux/vif2     | 54 --------------------------------------------
 2 files changed, 55 deletions(-)

diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index 3a90990594..0b1d111d7e 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -6,7 +6,6 @@ XEN_SCRIPTS = vif-bridge
 XEN_SCRIPTS += vif-route
 XEN_SCRIPTS += vif-nat
 XEN_SCRIPTS += vif-openvswitch
-XEN_SCRIPTS += vif2
 XEN_SCRIPTS += vif-setup
 XEN_SCRIPTS-$(CONFIG_LIBNL) += remus-netbuf-setup
 XEN_SCRIPTS += block
diff --git a/tools/hotplug/Linux/vif2 b/tools/hotplug/Linux/vif2
deleted file mode 100644
index 5bd555c6f0..0000000000
--- a/tools/hotplug/Linux/vif2
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-dir=$(dirname "$0")
-. "$dir/xen-hotplug-common.sh"
-. "$dir/xen-network-common.sh"
-
-bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
-if [ -z "$bridge" ]
-    then
-    if which brctl >&/dev/null; then
-        nr_bridges=$(($(brctl show | cut -f 1 | grep -v "^$" | wc -l) - 1))
-    else
-        nr_bridges=$(bridge link | wc -l)
-    fi
-    if [ "$nr_bridges" != 1 ]
-	then
-	fatal "no bridge specified, and don't know which one to use ($nr_bridges found)"
-    fi
-    if which brctl >&/dev/null; then
-        bridge=$(brctl show | cut -d "
-" -f 2 | cut -f 1)
-    else
-        bridge=$(bridge link | cut -d" " -f6)
-    fi
-fi
-
-command="$1"
-shift
-
-case "$command" in
-    "online")
-	if [ "$bridge" != "-" ]
-	    then
-	    setup_virtual_bridge_port "$vif"
-	    add_to_bridge "$bridge" "$vif"
-	else
-	    # Just let the normal udev rules for interfaces handle it.
-	    true
-	fi
-	success
-	;;
-
-    "add")
-	success
-	;;
-
-    "remove")
-	;;
-
-    *)
-	echo "Unknown command: $command"
-	echo 'Valid commands are: add, remove, online'
-	exit 1
-esac
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:24:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:24:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxHe-0003kQ-Ba; Wed, 09 Sep 2020 10:24:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxHc-0003kF-N4
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:56 +0000
X-Inumbo-ID: bf1bb743-e47a-4dd4-a6e4-32aa809c3db1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id bf1bb743-e47a-4dd4-a6e4-32aa809c3db1;
 Wed, 09 Sep 2020 10:24:55 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=em3Bus+vxrpJY9c2QFFdmaXHsx1f7Ss72/Ag+GLB8ns=; b=2yu8DmiRh+OL5OLxYDobThfb5D
 S9DtSViAeaam0V+xE/KDnCkc4hYelTZRqsXJWPUiXe6IQ9Uc2tRXRSLaK/goJ3FqMlpZRIkUxpMbi
 hGrd9qm2C7+mza762k5i9MoFXuSz5DcY8xkD1GIcjbH8P3/leGfRS0lBY5vTQWXQS9eY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHb-0004yy-Ez
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:55 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHb-0006tf-E9
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:24:55 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] gitignore: ignore ebmalloc.c soft link
Message-Id: <E1kFxHb-0006tf-E9@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:24:55 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 70c52c46bca89de00f04aa9294e14d11a2adff80
Author:     Wei Liu <wl@xen.org>
AuthorDate: Thu Aug 27 10:48:38 2020 +0000
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 11:11:05 2020 +0000

    gitignore: ignore ebmalloc.c soft link
    
    A previous commit split ebmalloc to its own translation unit but forgot
    to modify gitignore.
    
    Fixes: 8856a914bffd ("build: also check for empty .bss.* in .o -> .init.o conversion")
    Signed-off-by: Wei Liu <wl@xen.org>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 36ce2ea104..0f03518f91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -296,6 +296,7 @@ xen/arch/*/xen.lds
 xen/arch/*/asm-offsets.s
 xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
+xen/arch/*/efi/ebmalloc.c
 xen/arch/*/efi/efi.h
 xen/arch/*/efi/runtime.c
 xen/common/config_data.S
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxHo-0003lO-DH; Wed, 09 Sep 2020 10:25:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxHm-0003lE-I1
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:06 +0000
X-Inumbo-ID: 44691217-6a8d-400b-9c3d-8931844a9ec0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 44691217-6a8d-400b-9c3d-8931844a9ec0;
 Wed, 09 Sep 2020 10:25:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2VKI9RPS1QWf3qOTQf7TlD7lGhNeMWiqTxT90W2uCQI=; b=PDML27Sy+wMROq0pvptdSTcNkv
 xfqo2Ezf7VrtoSMJqZev2NRDowTDt6Y9ZfGIapQdjv7h4xQefu7mK3mPa7FU0pG2qH2U0+wPbVmXE
 sqb9zKmTKsCmJFOvTiRFAXLBIxga84Gf7yV8oBWGn0MGCb2YKEvArbRNHrs7bv4dP+jY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHl-0004zm-J7
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHl-0006uX-IF
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kFxHl-0006uX-IF@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Apr 10 16:25:40 2018 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Aug 27 12:48:46 2020 +0100

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 tools/tests/cpu-policy/test-cpu-policy.c    |  5 +++++
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index 7ba9707236..0fa209f1ea 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -374,6 +374,11 @@ static void test_msr_deserialise_failure(void)
             .msr = { .idx = 0xce, .val = ~0ull },
             .rc = -EOVERFLOW,
         },
+        {
+            .name = "truncated val",
+            .msr = { .idx = 0x10a, .val = ~0ull },
+            .rc = -EOVERFLOW,
+        },
     };
 
     printf("Testing MSR deserialise failure:\n");
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index ca4307e19f..c3862033eb 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -220,8 +220,10 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index ce3deaa5c7..fc733e64f6 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -268,7 +268,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*a  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(CORE_CAPS,     9*32+30) /*   IA32_CORE_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 203c713320..48ba4a59c0 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } platform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 171abf7008..7d71e92a38 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -99,6 +100,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);     break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxHy-0003n7-Ex; Wed, 09 Sep 2020 10:25:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxHw-0003mv-Dz
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:16 +0000
X-Inumbo-ID: 8e585218-1f35-4212-b856-cdbbdfe6c787
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8e585218-1f35-4212-b856-cdbbdfe6c787;
 Wed, 09 Sep 2020 10:25:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=bNvOmChgSmmIm6DOYxxEbGPRVOv5e0XoKXS3Yxpn1b4=; b=Pxz5qnjNJyPSMRwiNJKcWD/62W
 bVVT4+d3M9TOKFKXMNBs8n+Wh75h0o80/IjcOOvFbaKRvsBVbiVZ5B28E39lPzVUci2P3XuIkQLRd
 YNG5Y4ucmMphbf8K0K5g0oJE/Ch6bLoEy1ZD7d09QkPqafFOQHzeCM7fUb5GQl51XOoE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHv-000501-NN
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxHv-0006ux-Lw
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] stubdom: add stubdom/mini-os.mk for Xen paths used by
 Mini-OS
Message-Id: <E1kFxHv-0006ux-Lw@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 314d8cc0d87e04dd81eb9970709e71c50fef7b14
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:10 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    stubdom: add stubdom/mini-os.mk for Xen paths used by Mini-OS
    
    stubdom/mini-os.mk should contain paths used by Mini-OS when built as
    stubdom.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 stubdom/mini-os.mk | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
new file mode 100644
index 0000000000..32528bb91f
--- /dev/null
+++ b/stubdom/mini-os.mk
@@ -0,0 +1,17 @@
+# Included by Mini-OS stubdom builds to set variables depending on Xen
+# internal paths.
+#
+# Input variables are:
+# XEN_ROOT
+# MINIOS_TARGET_ARCH
+
+XENSTORE_CPPFLAGS = -isystem $(XEN_ROOT)/tools/xenstore/include
+TOOLCORE_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
+TOOLLOG_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
+EVTCHN_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
+GNTTAB_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
+CALL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
+FOREIGNMEMORY_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
+DEVICEMODEL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
+CTRL_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+GUEST_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxI9-0003o6-Ge; Wed, 09 Sep 2020 10:25:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxI7-0003nu-Rl
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:27 +0000
X-Inumbo-ID: 3d56bb87-23ae-4fe4-a5ec-fa0fbb5742c3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3d56bb87-23ae-4fe4-a5ec-fa0fbb5742c3;
 Wed, 09 Sep 2020 10:25:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2Gfv80n8kz4/Kp3dH2avzz2JWEOeSFNCBTqQIYxSx38=; b=gZVD4jBTFXHLrS2sDvBhZGoBoZ
 X0Cx4+QDJ9U6uyyfMP8V/keiXpTiaRJDWreS9+juvQgWByP3hWxlVHt5QzvP3tU0VOj8bev1pSsJK
 bze+/NSzD4wavnLUxTXEbSVdNJcVSN3f56wjb7wd+tKfJMM8AhDFy4NTmyJpOnmext0g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxI5-00050B-RQ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxI5-0006vR-QS
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: switch XEN_LIBXEN* make variables to lower case
 (XEN_libxen*)
Message-Id: <E1kFxI5-0006vR-QS@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 725ef89164e38349c9e6210f720e0cdc0c52e69e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    tools: switch XEN_LIBXEN* make variables to lower case (XEN_libxen*)
    
    In order to harmonize names of library related make variables switch
    XEN_LIBXEN* names to XEN_libxen*, as all other related variables (e.g.
    CFLAGS_libxen*, SHDEPS_libxen*, ...) already use this pattern.
    
    Rename XEN_LIBXC to XEN_libxenctrl, XEN_XENSTORE to XEN_libxenstore,
    XEN_XENLIGHT to XEN_libxenlight, XEN_XLUTIL to XEN_libxlutil, and
    XEN_LIBVCHAN to XEN_libxenvchan for the same reason.
    
    Introduce XEN_libxenguest with the same value as XEN_libxenctrl.
    
    No functional change.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk                    | 120 +++++++++++++++++++-------------------
 tools/golang/xenlight/Makefile    |   4 +-
 tools/libs/call/Makefile          |   2 +-
 tools/libs/devicemodel/Makefile   |   2 +-
 tools/libs/evtchn/Makefile        |   2 +-
 tools/libs/foreignmemory/Makefile |   2 +-
 tools/libs/gnttab/Makefile        |   2 +-
 tools/libs/hypfs/Makefile         |   2 +-
 tools/libs/toolcore/Makefile      |   2 +-
 tools/libs/toollog/Makefile       |   2 +-
 tools/libvchan/Makefile           |   2 +-
 tools/libxc/Makefile              |   2 +-
 tools/xenstat/libxenstat/Makefile |   2 +-
 tools/xenstore/Makefile           |   2 +-
 14 files changed, 75 insertions(+), 73 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 5ed5664bf7..b42e50ebf6 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -12,21 +12,23 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 LDFLAGS += $(PREPEND_LDFLAGS_XEN_TOOLS)
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
-XEN_LIBXENTOOLCORE  = $(XEN_ROOT)/tools/libs/toolcore
-XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
-XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
-XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
-XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libs/call
-XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory
-XEN_LIBXENDEVICEMODEL = $(XEN_ROOT)/tools/libs/devicemodel
-XEN_LIBXENHYPFS    = $(XEN_ROOT)/tools/libs/hypfs
-XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
-XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
+XEN_libxentoolcore = $(XEN_ROOT)/tools/libs/toolcore
+XEN_libxentoollog  = $(XEN_ROOT)/tools/libs/toollog
+XEN_libxenevtchn   = $(XEN_ROOT)/tools/libs/evtchn
+XEN_libxengnttab   = $(XEN_ROOT)/tools/libs/gnttab
+XEN_libxencall     = $(XEN_ROOT)/tools/libs/call
+XEN_libxenforeignmemory = $(XEN_ROOT)/tools/libs/foreignmemory
+XEN_libxendevicemodel = $(XEN_ROOT)/tools/libs/devicemodel
+XEN_libxenhypfs    = $(XEN_ROOT)/tools/libs/hypfs
+XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
+# Currently libxenguest lives in the same directory as libxenctrl
+XEN_libxenguest    = $(XEN_libxenctrl)
+XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
-XEN_XLUTIL         = $(XEN_XENLIGHT)
-XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
-XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
-XEN_LIBVCHAN       = $(XEN_ROOT)/tools/libvchan
+XEN_libxlutil      = $(XEN_libxenlight)
+XEN_libxenstore    = $(XEN_ROOT)/tools/xenstore
+XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
+XEN_libxenvchan    = $(XEN_ROOT)/tools/libvchan
 
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
@@ -97,75 +99,75 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-CFLAGS_libxentoollog = -I$(XEN_LIBXENTOOLLOG)/include $(CFLAGS_xeninclude)
+CFLAGS_libxentoollog = -I$(XEN_libxentoollog)/include $(CFLAGS_xeninclude)
 SHDEPS_libxentoollog =
-LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
-SHLIB_libxentoollog  = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
+LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_libxentoollog)/libxentoollog$(libextension)
+SHLIB_libxentoollog  = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_libxentoollog)
 
-CFLAGS_libxentoolcore = -I$(XEN_LIBXENTOOLCORE)/include $(CFLAGS_xeninclude)
+CFLAGS_libxentoolcore = -I$(XEN_libxentoolcore)/include $(CFLAGS_xeninclude)
 SHDEPS_libxentoolcore =
-LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_LIBXENTOOLCORE)/libxentoolcore$(libextension)
-SHLIB_libxentoolcore  = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_LIBXENTOOLCORE)
+LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_libxentoolcore)/libxentoolcore$(libextension)
+SHLIB_libxentoolcore  = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_libxentoolcore)
 
-CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude)
+CFLAGS_libxenevtchn = -I$(XEN_libxenevtchn)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore)
-LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension)
-SHLIB_libxenevtchn  = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
+LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_libxenevtchn)/libxenevtchn$(libextension)
+SHLIB_libxenevtchn  = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_libxenevtchn)
 
-CFLAGS_libxengnttab = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
+CFLAGS_libxengnttab = -I$(XEN_libxengnttab)/include $(CFLAGS_xeninclude)
 SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore)
-LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
-SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
+LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_libxengnttab)/libxengnttab$(libextension)
+SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_libxengnttab)
 
-CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
+CFLAGS_libxencall = -I$(XEN_libxencall)/include $(CFLAGS_xeninclude)
 SHDEPS_libxencall = $(SHLIB_libxentoolcore)
-LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_LIBXENCALL)/libxencall$(libextension)
-SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_LIBXENCALL)
+LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_libxencall)/libxencall$(libextension)
+SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_libxencall)
 
-CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude)
+CFLAGS_libxenforeignmemory = -I$(XEN_libxenforeignmemory)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore)
-LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
-SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
+LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_libxenforeignmemory)/libxenforeignmemory$(libextension)
+SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_libxenforeignmemory)
 
-CFLAGS_libxendevicemodel = -I$(XEN_LIBXENDEVICEMODEL)/include $(CFLAGS_xeninclude)
+CFLAGS_libxendevicemodel = -I$(XEN_libxendevicemodel)/include $(CFLAGS_xeninclude)
 SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall)
-LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
-SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
+LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_libxendevicemodel)/libxendevicemodel$(libextension)
+SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_libxendevicemodel)
 
-CFLAGS_libxenhypfs = -I$(XEN_LIBXENHYPFS)/include $(CFLAGS_xeninclude)
+CFLAGS_libxenhypfs = -I$(XEN_libxenhypfs)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall)
-LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_LIBXENHYPFS)/libxenhypfs$(libextension)
-SHLIB_libxenhypfs  = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_LIBXENHYPFS)
+LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_libxenhypfs)/libxenhypfs$(libextension)
+SHLIB_libxenhypfs  = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_libxenhypfs)
 
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
+CFLAGS_libxenctrl = -I$(XEN_libxenctrl)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
 SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) $(SHLIB_libxendevicemodel)
-LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
-SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
+LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_libxenctrl)/libxenctrl$(libextension)
+SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_libxenctrl)
 
-CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
+CFLAGS_libxenguest = -I$(XEN_libxenguest)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
 SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
-LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
-SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
+LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libextension)
+SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
 
-CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude)
+CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenstore = $(SHLIB_libxentoolcore)
-LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_XENSTORE)/libxenstore$(libextension)
-SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_XENSTORE)
+LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_libxenstore)/libxenstore$(libextension)
+SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_libxenstore)
 ifeq ($(CONFIG_Linux),y)
 LDLIBS_libxenstore += -ldl
 endif
 
-CFLAGS_libxenstat  = -I$(XEN_LIBXENSTAT)
+CFLAGS_libxenstat  = -I$(XEN_libxenstat)
 SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
-LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libextension)
-SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT)
+LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_libxenstat)/libxenstat$(libextension)
+SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_libxenstat)
 
-CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
+CFLAGS_libxenvchan = -I$(XEN_libxenvchan) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
 SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab)
-LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension)
-SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
+LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_libxenvchan)/libxenvchan$(libextension)
+SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_libxenvchan)
 
 ifeq ($(debug),y)
 # Disable optimizations
@@ -176,15 +178,15 @@ else
 CFLAGS += -O2 -fomit-frame-pointer
 endif
 
-CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
+CFLAGS_libxenlight = -I$(XEN_libxenlight) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
 SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs)
-LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_XENLIGHT)/libxenlight$(libextension)
-SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_XENLIGHT)
+LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_libxenlight)/libxenlight$(libextension)
+SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_libxenlight)
 
-CFLAGS_libxlutil = -I$(XEN_XLUTIL)
+CFLAGS_libxlutil = -I$(XEN_libxlutil)
 SHDEPS_libxlutil = $(SHLIB_libxenlight)
-LDLIBS_libxlutil = $(SHDEPS_libxlutil) $(XEN_XLUTIL)/libxlutil$(libextension)
-SHLIB_libxlutil  = $(SHDEPS_libxlutil) -Wl,-rpath-link=$(XEN_XLUTIL)
+LDLIBS_libxlutil = $(SHDEPS_libxlutil) $(XEN_libxlutil)/libxlutil$(libextension)
+SHLIB_libxlutil  = $(SHDEPS_libxlutil) -Wl,-rpath-link=$(XEN_libxlutil)
 
 CFLAGS += -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__
 
diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
index eac9dbf12a..a83fff7573 100644
--- a/tools/golang/xenlight/Makefile
+++ b/tools/golang/xenlight/Makefile
@@ -30,11 +30,11 @@ idl-gen: $(GOXL_GEN_FILES)
 #
 # NB that because the users of this library need to be able to
 # recompile the library from source, it needs to include '-lxenlight'
-# in the LDFLAGS; and thus we need to add -L$(XEN_XENLIGHT) here
+# in the LDFLAGS; and thus we need to add -L$(XEN_libxenlight) here
 # so that it can find the actual library.
 .PHONY: build
 build: xenlight.go $(GOXL_GEN_FILES)
-	CGO_CFLAGS="$(CFLAGS_libxenlight) $(CFLAGS_libxentoollog)" CGO_LDFLAGS="$(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -L$(XEN_XENLIGHT) -L$(XEN_LIBXENTOOLLOG)" $(GO) build -x
+	CGO_CFLAGS="$(CFLAGS_libxenlight) $(CFLAGS_libxentoollog)" CGO_LDFLAGS="$(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -L$(XEN_libxenlight) -L$(XEN_libxentoollog)" $(GO) build -x
 
 .PHONY: install
 install: build
diff --git a/tools/libs/call/Makefile b/tools/libs/call/Makefile
index 7f6dc3fcbd..7994b411fa 100644
--- a/tools/libs/call/Makefile
+++ b/tools/libs/call/Makefile
@@ -15,5 +15,5 @@ SRCS-$(CONFIG_MiniOS)  += minios.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENCALL)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxencall)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
diff --git a/tools/libs/devicemodel/Makefile b/tools/libs/devicemodel/Makefile
index 61bfa35273..d9d1d1b850 100644
--- a/tools/libs/devicemodel/Makefile
+++ b/tools/libs/devicemodel/Makefile
@@ -15,5 +15,5 @@ SRCS-$(CONFIG_MiniOS)  += compat.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENDEVICEMODEL)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxendevicemodel)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
diff --git a/tools/libs/evtchn/Makefile b/tools/libs/evtchn/Makefile
index 9206f622ef..d7aa4d402f 100644
--- a/tools/libs/evtchn/Makefile
+++ b/tools/libs/evtchn/Makefile
@@ -15,4 +15,4 @@ SRCS-$(CONFIG_MiniOS)  += minios.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENEVTCHN)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenevtchn)/include
diff --git a/tools/libs/foreignmemory/Makefile b/tools/libs/foreignmemory/Makefile
index 28f1bddc96..823989681d 100644
--- a/tools/libs/foreignmemory/Makefile
+++ b/tools/libs/foreignmemory/Makefile
@@ -15,5 +15,5 @@ SRCS-$(CONFIG_MiniOS)  += minios.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENFOREIGNMEMORY)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenforeignmemory)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
diff --git a/tools/libs/gnttab/Makefile b/tools/libs/gnttab/Makefile
index 2da8fbbb7f..c0fffdac71 100644
--- a/tools/libs/gnttab/Makefile
+++ b/tools/libs/gnttab/Makefile
@@ -17,5 +17,5 @@ SRCS-$(CONFIG_NetBSD)  += gnttab_unimp.c gntshr_unimp.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENGNTTAB)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxengnttab)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
diff --git a/tools/libs/hypfs/Makefile b/tools/libs/hypfs/Makefile
index 06dd449929..b4c41f6189 100644
--- a/tools/libs/hypfs/Makefile
+++ b/tools/libs/hypfs/Makefile
@@ -12,5 +12,5 @@ SRCS-y                 += core.c
 
 include ../libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENHYPFS)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenhypfs)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
diff --git a/tools/libs/toolcore/Makefile b/tools/libs/toolcore/Makefile
index 9c5a92d93f..85ff2b26fd 100644
--- a/tools/libs/toolcore/Makefile
+++ b/tools/libs/toolcore/Makefile
@@ -10,7 +10,7 @@ SRCS-y	+= handlereg.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENTOOLCORE)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxentoolcore)/include
 
 $(LIB_OBJS): $(AUTOINCS)
 $(PIC_OBJS): $(AUTOINCS)
diff --git a/tools/libs/toollog/Makefile b/tools/libs/toollog/Makefile
index 9156e5d08e..2d3ae4e627 100644
--- a/tools/libs/toollog/Makefile
+++ b/tools/libs/toollog/Makefile
@@ -10,4 +10,4 @@ SRCS-y	+= xtl_logger_stdio.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENTOOLLOG)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxentoollog)/include
diff --git a/tools/libvchan/Makefile b/tools/libvchan/Makefile
index d99a6137e1..a5441162a0 100644
--- a/tools/libvchan/Makefile
+++ b/tools/libvchan/Makefile
@@ -35,7 +35,7 @@ endif
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBVCHAN)
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
 
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 955cd5ab18..c1e41a8ee9 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -168,7 +168,7 @@ endif
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXC)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenctrl)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
 
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index ab980852da..b5e623b155 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -50,7 +50,7 @@ endif
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENSTAT)
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstat)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 
 .PHONY: all
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 445e9911b2..0a64ac1571 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -128,7 +128,7 @@ endif
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_XENSTORE)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstore)/include
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxIH-0003p8-Jl; Wed, 09 Sep 2020 10:25:37 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxIG-0003p3-Vl
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:37 +0000
X-Inumbo-ID: ec0cffa4-634f-4de6-9791-6bd6350eb2d9
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ec0cffa4-634f-4de6-9791-6bd6350eb2d9;
 Wed, 09 Sep 2020 10:25:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=uvmmZ3K2ykQHKgrZcIHnIIw5PGusi3zreiFxVCuoB0Q=; b=HXbQb8r3Bm7lZ2IQARMe8ZK5BX
 8XqzsvOo599r1udwo9SbbO1FHNyK19nyr/SoWA73dXlJ3inujTI7FGZrK0esDHoCdmDxXWOktWYY4
 s7d+39W88CFGPvenfya+Qww9Oe2CsGeL9W3obHV84nXQaMXDJHf159nj9Lhb9M4htgmc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIF-00050H-Uv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIF-0006vr-UC
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: add a copy of library headers in tools/include
Message-Id: <E1kFxIF-0006vr-UC@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit bc44e2fb3199ecd8461bbdd093806f76ee61776a
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    tools: add a copy of library headers in tools/include
    
    The headers.chk target in tools/Rules.mk tries to compile all headers
    stand alone for testing them not to include any internal header.
    
    Unfortunately the headers tested against are not complete, as any
    header for a Xen library is not included in the include path of the
    test compile run, resulting in a failure in case any of the tested
    headers in including an official Xen library header.
    
    Fix that by copying the official headers located in
    tools/libs/*/include to tools/include.
    
    In order to support libraries with header name other than xen<lib>.h
    or with multiple headers add a LIBHEADER make variable a lib specific
    Makefile can set in that case.
    
    Move the headers.chk target from Rules.mk to libs.mk as it is used
    for libraries in tools/libs only.
    
    Add NO_HEADERS_CHK variable to skip checking headers as this will be
    needed e.g. for libxenctrl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore         |  1 +
 tools/Rules.mk     |  8 --------
 tools/libs/libs.mk | 26 +++++++++++++++++++++++---
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0f03518f91..823f4743dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -188,6 +188,7 @@ tools/hotplug/Linux/xendomains
 tools/hotplug/NetBSD/rc.d/xencommons
 tools/hotplug/NetBSD/rc.d/xendriverdomain
 tools/include/acpi
+tools/include/*.h
 tools/include/xen/*
 tools/include/xen-xsm/*
 tools/include/xen-foreign/*.(c|h|size)
diff --git a/tools/Rules.mk b/tools/Rules.mk
index b42e50ebf6..5d699cfd39 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -225,14 +225,6 @@ INSTALL_PYTHON_PROG = \
 %.opic: %.S
 	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) $(CFLAGS.opic) -fPIC -c -o $@ $< $(APPEND_CFLAGS)
 
-headers.chk:
-	for i in $(filter %.h,$^); do \
-	    $(CC) -x c -ansi -Wall -Werror $(CFLAGS_xeninclude) \
-	          -S -o /dev/null $$i || exit 1; \
-	    echo $$i; \
-	done >$@.new
-	mv $@.new $@
-
 subdirs-all subdirs-clean subdirs-install subdirs-distclean subdirs-uninstall: .phony
 	@set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y); do \
 		$(MAKE) subdir-$(patsubst subdirs-%,%,$@)-$$subdir; \
diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 8027ae7400..8045c00e9a 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -34,6 +34,10 @@ endif
 
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
+LIBHEADER ?= xen$(LIBNAME).h
+LIBHEADERS = $(foreach h, $(LIBHEADER), include/$(h))
+LIBHEADERSGLOB = $(foreach h, $(LIBHEADER), $(XEN_ROOT)/tools/include/$(h))
+
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 
@@ -47,7 +51,22 @@ build:
 .PHONY: libs
 libs: headers.chk $(LIB) $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
 
-headers.chk: $(wildcard include/*.h) $(AUTOINCS)
+ifneq ($(NO_HEADERS_CHK),y)
+headers.chk:
+	for i in $(filter %.h,$^); do \
+	    $(CC) -x c -ansi -Wall -Werror $(CFLAGS_xeninclude) \
+	          -S -o /dev/null $$i || exit 1; \
+	    echo $$i; \
+	done >$@.new
+	mv $@.new $@
+else
+.PHONY: headers.chk
+endif
+
+headers.chk: $(LIBHEADERSGLOB) $(AUTOINCS)
+
+$(LIBHEADERSGLOB): $(LIBHEADERS)
+	for i in $(realpath $(LIBHEADERS)); do ln -sf $$i $(XEN_ROOT)/tools/include; done
 
 libxen$(LIBNAME).a: $(LIB_OBJS)
 	$(AR) rc $@ $^
@@ -68,13 +87,13 @@ install: build
 	$(INSTALL_DATA) libxen$(LIBNAME).a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so
-	$(INSTALL_DATA) include/xen$(LIBNAME).h $(DESTDIR)$(includedir)
+	for i in $(LIBHEADERS); do $(INSTALL_DATA) $$i $(DESTDIR)$(includedir); done
 	$(INSTALL_DATA) xen$(LIBNAME).pc $(DESTDIR)$(PKG_INSTALLDIR)
 
 .PHONY: uninstall
 uninstall:
 	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xen$(LIBNAME).pc
-	rm -f $(DESTDIR)$(includedir)/xen$(LIBNAME).h
+	for i in $(LIBHEADER); do rm -f $(DESTDIR)$(includedir)/$(LIBHEADER); done
 	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so
 	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR)
 	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR).$(MINOR)
@@ -90,6 +109,7 @@ clean:
 	rm -f libxen$(LIBNAME).so.$(MAJOR).$(MINOR) libxen$(LIBNAME).so.$(MAJOR)
 	rm -f headers.chk
 	rm -f xen$(LIBNAME).pc
+	rm -f $(LIBHEADERSGLOB)
 
 .PHONY: distclean
 distclean: clean
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxIR-0003qG-LY; Wed, 09 Sep 2020 10:25:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxIQ-0003q8-SD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:46 +0000
X-Inumbo-ID: f798bbdc-0ba6-4548-9a24-e35ecc2acc88
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f798bbdc-0ba6-4548-9a24-e35ecc2acc88;
 Wed, 09 Sep 2020 10:25:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Ju4BkQckGIFuk6SfgnK4kmGhVvLlxg75q40g8mtVC9g=; b=if5JyAY1SkOuXpmE87YKDjUhTW
 OQLmWVlTgGzU5UHPVHhP72QhEvqdQRUAgSRbYT4MWc54JbKXQeROn0UsShT11xZ+6IyiVU/LrkCW+
 QjpOhg9GNF9cJDGivzRcqIbTCMa60+vPYgVCwrN9LRpSVQOLYICWS0O++KRh2dfcU1So=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIQ-00050O-25
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIQ-0006wN-1N
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: don't call make recursively from libs.mk
Message-Id: <E1kFxIQ-0006wN-1N@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 097b6fe1df89a0506a4feb1379ba5d9d14ec3a3b
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    tools: don't call make recursively from libs.mk
    
    During build of a xen library make is called again via libs.mk. This is
    not necessary as the same can be achieved by a simple dependency.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/libs.mk | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 8045c00e9a..764f5441e2 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -45,8 +45,7 @@ $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 all: build
 
 .PHONY: build
-build:
-	$(MAKE) libs
+build: libs
 
 .PHONY: libs
 libs: headers.chk $(LIB) $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:25:57 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:25:57 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxIb-0003rL-N8; Wed, 09 Sep 2020 10:25:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxIb-0003rD-6D
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:57 +0000
X-Inumbo-ID: 327a7ca7-a432-4d9b-a7c8-484a547cc8aa
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 327a7ca7-a432-4d9b-a7c8-484a547cc8aa;
 Wed, 09 Sep 2020 10:25:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=paElGznAal7umImctaYSC8BHMzdzk98bKFKzEIpGHzg=; b=1FMtZujUG+QNmkAeTDbiddSqT3
 NMg+1ao1jInMc1X1W4+CMJHo2pg8/0VzHxI/OJNamVL4uBQktzRqgVO+mRz/NiDAmkE+0sIfQKgUl
 vuzZuWYMIQHYYFn3KtVDzCIYrJ++Bt2r03QHHg22RmGm0vckIzXQFgfnAyWKlvovoCjM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIa-00050e-6Z
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIa-0006wl-5k
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:25:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: define ROUNDUP() in tools/include/xen-tools/libs.h
Message-Id: <E1kFxIa-0006wl-5k@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:25:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 09bf2917046f78a5f0b42da771602bb4ef5dcc09
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    tools: define ROUNDUP() in tools/include/xen-tools/libs.h
    
    Today there are multiple copies of the ROUNDUP() macro in various
    sources and headers. Define it once in tools/include/xen-tools/libs.h.
    
    Using xen-tools/libs.h enables removing copies of MIN() and MAX(), too.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/console/daemon/io.c        | 6 +-----
 tools/include/xen-tools/libs.h   | 4 ++++
 tools/libs/call/buffer.c         | 3 +--
 tools/libs/foreignmemory/linux.c | 3 +--
 tools/libs/gnttab/private.h      | 3 ---
 tools/libxc/xg_private.h         | 1 -
 tools/libxl/libxl_internal.h     | 3 ---
 tools/xenstore/xenstored_core.c  | 2 --
 8 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index a43c57edad..4af27ffc5d 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -49,9 +49,7 @@
 #include <sys/ioctl.h>
 #include <libutil.h>
 #endif
-
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#include <xen-tools/libs.h>
 
 /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
 #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
@@ -80,8 +78,6 @@ static struct pollfd  *fds;
 static unsigned int current_array_size;
 static unsigned int nr_fds;
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 struct buffer {
 	char *data;
 	size_t consumed;
diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h
index cc7dfc8c64..a16e0c3807 100644
--- a/tools/include/xen-tools/libs.h
+++ b/tools/include/xen-tools/libs.h
@@ -59,4 +59,8 @@
     })
 #endif
 
+#ifndef ROUNDUP
+#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
+#endif
+
 #endif	/* __XEN_TOOLS_LIBS__ */
diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
index 0b6af2db60..085674d882 100644
--- a/tools/libs/call/buffer.c
+++ b/tools/libs/call/buffer.c
@@ -16,14 +16,13 @@
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#include <xen-tools/libs.h>
 
 #include "private.h"
 
 #define DBGPRINTF(_m...) \
     xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m)
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static void cache_lock(xencall_handle *xcall)
diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c
index 8daa5828e3..fe73d5ab72 100644
--- a/tools/libs/foreignmemory/linux.c
+++ b/tools/libs/foreignmemory/linux.c
@@ -25,11 +25,10 @@
 
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#include <xen-tools/libs.h>
 
 #include "private.h"
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
diff --git a/tools/libs/gnttab/private.h b/tools/libs/gnttab/private.h
index c5e23639b1..eb6a6abe54 100644
--- a/tools/libs/gnttab/private.h
+++ b/tools/libs/gnttab/private.h
@@ -5,9 +5,6 @@
 #include <xentoolcore_internal.h>
 #include <xengnttab.h>
 
-/* Set of macros/defines used by both Linux and FreeBSD */
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 #define GTERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gnttab", _f)
 #define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f)
 
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index f0a4b2c616..40b5baecde 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -95,7 +95,6 @@ typedef uint64_t x86_pgentry_t;
 #define PAGE_SIZE_X86           (1UL << PAGE_SHIFT_X86)
 #define PAGE_MASK_X86           (~(PAGE_SIZE_X86-1))
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 #define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)
 
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 94a23179d3..c63d0686fd 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -132,9 +132,6 @@
 #define MB(_mb)     (_AC(_mb, ULL) << 20)
 #define GB(_gb)     (_AC(_gb, ULL) << 30)
 
-#define ROUNDUP(_val, _order)                                           \
-    (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1))
-
 #define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d))
 
 #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 7bd959f28b..9700772d40 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -73,8 +73,6 @@ static unsigned int nr_fds;
 static int sock = -1;
 static int ro_sock = -1;
 
-#define ROUNDUP(_x, _w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 static bool verbose = false;
 LIST_HEAD(connections);
 int tracefd = -1;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxIm-0003sH-Oh; Wed, 09 Sep 2020 10:26:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxIm-0003sB-7P
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:08 +0000
X-Inumbo-ID: 2f02cc9f-5810-4675-90a6-a7c92ef16c71
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2f02cc9f-5810-4675-90a6-a7c92ef16c71;
 Wed, 09 Sep 2020 10:26:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=fkgRkn8ZMdeCSNiA+DSzYL0l0tJq/LuMRHWKC27FxZI=; b=25eCcm0hw6rjSmvytNLEzJA9oT
 aD8S5BzMxTk/4OaENIOqTfpa4naEcSQLlEX1XF6jmn8su8eMvBg2EcoZsydldInazBMAgzZVpn5iH
 l+Z9lEWJByuVL6jse1UtrvAkYn7ulzl1HBtxhSXPmLaTILylABDorYXlpCIGMaapvi+s=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIk-00051d-B6
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIk-0006xY-9i
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: generate most contents of library make variables
Message-Id: <E1kFxIk-0006xY-9i@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ded08cdfa72bb1555a2beb5c4300dedb1f830358
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    tools: generate most contents of library make variables
    
    Library related make variables (CFLAGS_lib*, SHDEPS_lib*, LDLIBS_lib*
    and SHLIB_lib*) mostly have a common pattern for their values. Generate
    most of this content automatically by adding a new per-library variable
    defining on which other libraries a lib is depending. Those definitions
    are put into an own file in order to make it possible to include it
    from various Makefiles, especially for stubdom.
    
    This in turn makes it possible to drop the USELIB variable from each
    library Makefile.
    
    The LIBNAME variable can be dropped, too, as it can be derived from the
    directory name the library is residing in.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk                    | 59 ++++++++-------------------------------
 tools/libs/call/Makefile          |  2 --
 tools/libs/devicemodel/Makefile   |  2 --
 tools/libs/evtchn/Makefile        |  2 --
 tools/libs/foreignmemory/Makefile |  2 --
 tools/libs/gnttab/Makefile        |  2 --
 tools/libs/hypfs/Makefile         |  2 --
 tools/libs/libs.mk                |  8 +++---
 tools/libs/toolcore/Makefile      |  1 -
 tools/libs/toollog/Makefile       |  1 -
 tools/libs/uselibs.mk             | 18 ++++++++++++
 11 files changed, 34 insertions(+), 65 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 5d699cfd39..7e019a8a65 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -12,14 +12,9 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 LDFLAGS += $(PREPEND_LDFLAGS_XEN_TOOLS)
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
-XEN_libxentoolcore = $(XEN_ROOT)/tools/libs/toolcore
-XEN_libxentoollog  = $(XEN_ROOT)/tools/libs/toollog
-XEN_libxenevtchn   = $(XEN_ROOT)/tools/libs/evtchn
-XEN_libxengnttab   = $(XEN_ROOT)/tools/libs/gnttab
-XEN_libxencall     = $(XEN_ROOT)/tools/libs/call
-XEN_libxenforeignmemory = $(XEN_ROOT)/tools/libs/foreignmemory
-XEN_libxendevicemodel = $(XEN_ROOT)/tools/libs/devicemodel
-XEN_libxenhypfs    = $(XEN_ROOT)/tools/libs/hypfs
+
+include $(XEN_ROOT)/tools/libs/uselibs.mk
+
 XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
 # Currently libxenguest lives in the same directory as libxenctrl
 XEN_libxenguest    = $(XEN_libxenctrl)
@@ -99,45 +94,15 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-CFLAGS_libxentoollog = -I$(XEN_libxentoollog)/include $(CFLAGS_xeninclude)
-SHDEPS_libxentoollog =
-LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_libxentoollog)/libxentoollog$(libextension)
-SHLIB_libxentoollog  = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_libxentoollog)
-
-CFLAGS_libxentoolcore = -I$(XEN_libxentoolcore)/include $(CFLAGS_xeninclude)
-SHDEPS_libxentoolcore =
-LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_libxentoolcore)/libxentoolcore$(libextension)
-SHLIB_libxentoolcore  = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_libxentoolcore)
-
-CFLAGS_libxenevtchn = -I$(XEN_libxenevtchn)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore)
-LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_libxenevtchn)/libxenevtchn$(libextension)
-SHLIB_libxenevtchn  = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_libxenevtchn)
-
-CFLAGS_libxengnttab = -I$(XEN_libxengnttab)/include $(CFLAGS_xeninclude)
-SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore)
-LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_libxengnttab)/libxengnttab$(libextension)
-SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_libxengnttab)
-
-CFLAGS_libxencall = -I$(XEN_libxencall)/include $(CFLAGS_xeninclude)
-SHDEPS_libxencall = $(SHLIB_libxentoolcore)
-LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_libxencall)/libxencall$(libextension)
-SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_libxencall)
-
-CFLAGS_libxenforeignmemory = -I$(XEN_libxenforeignmemory)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore)
-LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_libxenforeignmemory)/libxenforeignmemory$(libextension)
-SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_libxenforeignmemory)
-
-CFLAGS_libxendevicemodel = -I$(XEN_libxendevicemodel)/include $(CFLAGS_xeninclude)
-SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall)
-LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_libxendevicemodel)/libxendevicemodel$(libextension)
-SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_libxendevicemodel)
-
-CFLAGS_libxenhypfs = -I$(XEN_libxenhypfs)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall)
-LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_libxenhypfs)/libxenhypfs$(libextension)
-SHLIB_libxenhypfs  = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_libxenhypfs)
+define LIB_defs =
+ XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
+ CFLAGS_libxen$(1) = -I$$(XEN_libxen$(1))/include $$(CFLAGS_xeninclude)
+ SHDEPS_libxen$(1) = $$(foreach use,$$(USELIBS_$(1)),$$(SHLIB_libxen$$(use)))
+ LDLIBS_libxen$(1) = $$(SHDEPS_libxen$(1)) $$(XEN_libxen$(1))/libxen$(1)$$(libextension)
+ SHLIB_libxen$(1) = $$(SHDEPS_libxen$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1))
+endef
+
+$(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
diff --git a/tools/libs/call/Makefile b/tools/libs/call/Makefile
index 7994b411fa..81c7478efd 100644
--- a/tools/libs/call/Makefile
+++ b/tools/libs/call/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 2
-LIBNAME  := call
-USELIBS  := toollog toolcore
 
 SRCS-y                 += core.c buffer.c
 SRCS-$(CONFIG_Linux)   += linux.c
diff --git a/tools/libs/devicemodel/Makefile b/tools/libs/devicemodel/Makefile
index d9d1d1b850..42417958f2 100644
--- a/tools/libs/devicemodel/Makefile
+++ b/tools/libs/devicemodel/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 3
-LIBNAME  := devicemodel
-USELIBS  := toollog toolcore call
 
 SRCS-y                 += core.c
 SRCS-$(CONFIG_Linux)   += linux.c
diff --git a/tools/libs/evtchn/Makefile b/tools/libs/evtchn/Makefile
index d7aa4d402f..aec76641e8 100644
--- a/tools/libs/evtchn/Makefile
+++ b/tools/libs/evtchn/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 1
-LIBNAME  := evtchn
-USELIBS  := toollog toolcore
 
 SRCS-y                 += core.c
 SRCS-$(CONFIG_Linux)   += linux.c
diff --git a/tools/libs/foreignmemory/Makefile b/tools/libs/foreignmemory/Makefile
index 823989681d..cf444d3c1a 100644
--- a/tools/libs/foreignmemory/Makefile
+++ b/tools/libs/foreignmemory/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 3
-LIBNAME  := foreignmemory
-USELIBS  := toollog toolcore
 
 SRCS-y                 += core.c
 SRCS-$(CONFIG_Linux)   += linux.c
diff --git a/tools/libs/gnttab/Makefile b/tools/libs/gnttab/Makefile
index c0fffdac71..d8d4d55e27 100644
--- a/tools/libs/gnttab/Makefile
+++ b/tools/libs/gnttab/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 2
-LIBNAME  := gnttab
-USELIBS  := toollog toolcore
 
 SRCS-GNTTAB            += gnttab_core.c
 SRCS-GNTSHR            += gntshr_core.c
diff --git a/tools/libs/hypfs/Makefile b/tools/libs/hypfs/Makefile
index b4c41f6189..668d68853f 100644
--- a/tools/libs/hypfs/Makefile
+++ b/tools/libs/hypfs/Makefile
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 0
-LIBNAME  := hypfs
-USELIBS  := toollog toolcore call
 
 APPEND_LDFLAGS += -lz
 
diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 764f5441e2..19efc5e743 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -1,18 +1,18 @@
 # Common Makefile for building a lib.
 #
 # Variables taken as input:
-#   LIBNAME: name of lib to build, will be prepended with "libxen"
 #   MAJOR:   major version of lib
 #   MINOR:   minor version of lib
-#   USELIBS: xen libs to use (e.g. "toolcore toollog")
+
+LIBNAME := $(notdir $(CURDIR))
 
 SHLIB_LDFLAGS += -Wl,--version-script=libxen$(LIBNAME).map
 
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
-CFLAGS   += $(foreach lib, $(USELIBS), $(CFLAGS_libxen$(lib)))
+CFLAGS   += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib)))
 
-LDUSELIBS = $(foreach lib, $(USELIBS), $(LDLIBS_libxen$(lib)))
+LDUSELIBS = $(foreach lib, $(USELIBS_$(LIBNAME)), $(LDLIBS_libxen$(lib)))
 
 LIB_OBJS := $(SRCS-y:.c=.o)
 PIC_OBJS := $(SRCS-y:.c=.opic)
diff --git a/tools/libs/toolcore/Makefile b/tools/libs/toolcore/Makefile
index 85ff2b26fd..34b08a4236 100644
--- a/tools/libs/toolcore/Makefile
+++ b/tools/libs/toolcore/Makefile
@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR	= 1
 MINOR	= 0
-LIBNAME  := toolcore
 AUTOINCS := include/_xentoolcore_list.h
 
 SRCS-y	+= handlereg.c
diff --git a/tools/libs/toollog/Makefile b/tools/libs/toollog/Makefile
index 2d3ae4e627..3f986835d6 100644
--- a/tools/libs/toollog/Makefile
+++ b/tools/libs/toollog/Makefile
@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR	= 1
 MINOR	= 0
-LIBNAME  := toollog
 
 SRCS-y	+= xtl_core.c
 SRCS-y	+= xtl_logger_stdio.c
diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk
new file mode 100644
index 0000000000..db73fe314e
--- /dev/null
+++ b/tools/libs/uselibs.mk
@@ -0,0 +1,18 @@
+# Libraries below tools/libs/ and their dependencies
+
+LIBS_LIBS += toolcore
+USELIBS_toolcore :=
+LIBS_LIBS += toollog
+USELIBS_toollog :=
+LIBS_LIBS += evtchn
+USELIBS_evtchn := toollog toolcore
+LIBS_LIBS += gnttab
+USELIBS_gnttab := toollog toolcore
+LIBS_LIBS += call
+USELIBS_call := toollog toolcore
+LIBS_LIBS += foreignmemory
+USELIBS_foreignmemory := toollog toolcore
+LIBS_LIBS += devicemodel
+USELIBS_devicemodel := toollog toolcore call
+LIBS_LIBS += hypfs
+USELIBS_hypfs := toollog toolcore call
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxIv-0003tn-Rm; Wed, 09 Sep 2020 10:26:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxIv-0003ti-DV
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:17 +0000
X-Inumbo-ID: db1fc057-6cf6-46e3-9f03-ee0dd7081dc7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id db1fc057-6cf6-46e3-9f03-ee0dd7081dc7;
 Wed, 09 Sep 2020 10:26:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=8i5sXjuyzF8FspJ2FTioHMXUIOnTdhOEJwZalEz9+IU=; b=7DR5zowWG+7CmE5fBLo1nFZqed
 YS2qIpgA7OxKNhe/kO1wNb+LFhs0yuBMl7HSG6GuD0AfUBvONwplvOTB4MMk8rTejwcpu06TzdL3B
 H8CsXGkC4KaexLhxrU8X782GWaL92QOhbjXrTn3kN+l3G/otk4PfosAitf2mhXLUBX5E=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIu-00051n-F1
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxIu-0006y5-E2
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] stubdom: add correct dependencies for Xen libraries
Message-Id: <E1kFxIu-0006y5-E2@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ddb2934a914df26762c45f0b114fa358a045e0ee
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:11 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    stubdom: add correct dependencies for Xen libraries
    
    The stubdom Makefile is missing several dependencies between Xen
    libraries. Add them.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 stubdom/Makefile | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index af8cde41b9..a95212e363 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -23,6 +23,13 @@ endif
 
 -include $(XEN_ROOT)/config/Stubdom.mk
 
+include $(XEN_ROOT)/tools/libs/uselibs.mk
+
+define LIB_deps =
+ LIBDEPS_$(1) = $$(foreach use,$$(USELIBS_$(1)),libxen$$(use))
+endef
+$(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_deps,$(lib))))
+
 GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
 ifeq ($(XEN_TARGET_ARCH),x86_32)
 GNU_TARGET_ARCH:=i686
@@ -387,6 +394,7 @@ $(TARGETS_MINIOS): mini-os-%:
 
 .PHONY: libxentoolcore
 libxentoolcore: libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a
+libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: $(LIBDEPS_toolcore)
 libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toolcore
 
@@ -396,6 +404,7 @@ libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: mk-headers-$(XEN_TARGET_ARCH)
 
 .PHONY: libxentoollog
 libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
+libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: $(LIBDEPS_toollog)
 libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
 
@@ -405,6 +414,7 @@ libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $
 
 .PHONY: libxenevtchn
 libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
+libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: $(LIBDEPS_evtchn)
 libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
 
@@ -414,6 +424,7 @@ libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(N
 
 .PHONY: libxengnttab
 libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
+libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: $(LIBDEPS_gnttab)
 libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
 
@@ -423,6 +434,7 @@ libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(N
 
 .PHONY: libxencall
 libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
+libs-$(XEN_TARGET_ARCH)/call/libxencall.a: $(LIBDEPS_call)
 libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
 
@@ -432,6 +444,7 @@ libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLI
 
 .PHONY: libxenforeignmemory
 libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
+libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: $(LIBDEPS_foreignmemory)
 libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
 
@@ -441,6 +454,7 @@ libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TA
 
 .PHONY: libxendevicemodel
 libxendevicemodel: libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a
+libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: $(LIBDEPS_devicemodel)
 libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel
 
@@ -450,7 +464,7 @@ libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: mk-headers-$(XEN_TARGET
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoolcore libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJ6-0003vM-Td; Wed, 09 Sep 2020 10:26:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJ5-0003vE-OA
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:27 +0000
X-Inumbo-ID: dbf5f22e-4fdd-4446-9d6d-0af05ce33ffb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id dbf5f22e-4fdd-4446-9d6d-0af05ce33ffb;
 Wed, 09 Sep 2020 10:26:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=lwNQcbYHOym3+aZW2Yvut7CtxL4VanlMbwqJupMP9Pk=; b=MUip8yU/ccD3b/joKPY/6Bq8LA
 V0OO4ZJlNprZ0y7U00RrUy8FOX5Q5xOtqyfksjSN4Yv3cF6MHS8R1mR/CULjYuOJ81N5KH8j6IIy3
 +/XGaYZtdyZSMNsScXCAh43C1xVp1dd586hYP5gcYWuXmF2Jr9pIp8ktJg2VJMhg9sJ8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJ4-00053Z-Is
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJ4-0006yT-Hv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] stubdom: simplify building xen libraries for stubdoms
Message-Id: <E1kFxJ4-0006yT-Hv@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0de9cbf9cfeedbd2a2e4719a2faa6084f0fcbb52
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:12 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Thu Aug 27 12:59:46 2020 +0000

    stubdom: simplify building xen libraries for stubdoms
    
    The pattern for building a Xen library with sources under tools/libs
    is always the same. Simplify stubdom/Makefile by defining a callable
    make program for those libraries.
    
    Even if not needed right now add the possibility for defining
    additional dependencies for a library.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 stubdom/Makefile | 120 +++++++++++--------------------------------------------
 1 file changed, 24 insertions(+), 96 deletions(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index a95212e363..4fd86dd44b 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -327,6 +327,16 @@ ioemu/linkfarm.stamp:
 	touch ioemu/linkfarm.stamp
 endif
 
+#######
+# libraries under tools/libs
+#######
+
+STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel
+
+#######
+# common handling
+#######
+
 define do_links
   mkdir -p $(dir $@)include
   cd $(dir $@); \
@@ -337,26 +347,21 @@ define do_links
   touch $@
 endef
 
-libs-$(XEN_TARGET_ARCH)/toolcore/stamp: $(XEN_ROOT)/tools/libs/toolcore/Makefile
-	$(do_links)
-
-libs-$(XEN_TARGET_ARCH)/toollog/stamp: $(XEN_ROOT)/tools/libs/toollog/Makefile
-	$(do_links)
+define BUILD_lib
+ .PHONY: libxen$(1) clean-libxen$(1)
+ libxen$(1): libs-$$(XEN_TARGET_ARCH)/$(1)/libxen$(1).a
+ libs-$$(XEN_TARGET_ARCH)/$(1)/libxen$(1).a: $$(LIBDEPS_$(1)) $$(LIBDEP_$(1))
+ libs-$$(XEN_TARGET_ARCH)/$(1)/libxen$(1).a: mk-headers-$$(XEN_TARGET_ARCH) $$(NEWLIB_STAMPFILE)
+	CPPFLAGS="$$(TARGET_CPPFLAGS)" CFLAGS="$$(TARGET_CFLAGS)" $$(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libs-$$(XEN_TARGET_ARCH)/$(1)
 
-libs-$(XEN_TARGET_ARCH)/evtchn/stamp: $(XEN_ROOT)/tools/libs/evtchn/Makefile
-	$(do_links)
+ clean-libxen$(1):
+	[ ! -e libs-$$(XEN_TARGET_ARCH)/$(1)/Makefile ] || $$(MAKE) DESTDIR= -C libs-$$(XEN_TARGET_ARCH)/$(1) clean
 
-libs-$(XEN_TARGET_ARCH)/gnttab/stamp: $(XEN_ROOT)/tools/libs/gnttab/Makefile
-	$(do_links)
-
-libs-$(XEN_TARGET_ARCH)/call/stamp: $(XEN_ROOT)/tools/libs/call/Makefile
-	$(do_links)
-
-libs-$(XEN_TARGET_ARCH)/foreignmemory/stamp: $(XEN_ROOT)/tools/libs/foreignmemory/Makefile
-	$(do_links)
+ libs-$$(XEN_TARGET_ARCH)/$(1)/stamp: $$(XEN_ROOT)/tools/libs/$(1)/Makefile
+	$$(do_links)
+endef
 
-libs-$(XEN_TARGET_ARCH)/devicemodel/stamp: $(XEN_ROOT)/tools/libs/devicemodel/Makefile
-	$(do_links)
+$(foreach lib,$(STUB_LIBS),$(eval $(call BUILD_lib,$(lib))))
 
 libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
 	$(do_links)
@@ -364,8 +369,7 @@ libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
 xenstore/stamp: $(XEN_ROOT)/tools/xenstore/Makefile
 	$(do_links)
 
-LINK_LIBS_DIRS := toolcore toollog evtchn gnttab call foreignmemory devicemodel
-LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(LINK_LIBS_DIRS),libs-$(XEN_TARGET_ARCH)/$(dir))
+LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(STUB_LIBS),libs-$(XEN_TARGET_ARCH)/$(dir))
 LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp)
 
 mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) $(LINK_STAMPS)
@@ -388,76 +392,6 @@ $(TARGETS_MINIOS): mini-os-%:
                 mkdir -p $@/$$i ; \
 	done
 
-#######
-# libxentoolcore
-#######
-
-.PHONY: libxentoolcore
-libxentoolcore: libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a
-libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: $(LIBDEPS_toolcore)
-libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toolcore
-
-#######
-# libxentoollog
-#######
-
-.PHONY: libxentoollog
-libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
-libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: $(LIBDEPS_toollog)
-libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
-
-#######
-# libxenevtchn
-#######
-
-.PHONY: libxenevtchn
-libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
-libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: $(LIBDEPS_evtchn)
-libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
-
-#######
-# libxengnttab
-#######
-
-.PHONY: libxengnttab
-libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
-libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: $(LIBDEPS_gnttab)
-libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
-
-#######
-# libxencall
-#######
-
-.PHONY: libxencall
-libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
-libs-$(XEN_TARGET_ARCH)/call/libxencall.a: $(LIBDEPS_call)
-libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
-
-#######
-# libxenforeignmemory
-#######
-
-.PHONY: libxenforeignmemory
-libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
-libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: $(LIBDEPS_foreignmemory)
-libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
-
-#######
-# libxendevicemodel
-#######
-
-.PHONY: libxendevicemodel
-libxendevicemodel: libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a
-libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: $(LIBDEPS_devicemodel)
-libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel
-
 #######
 # libxc
 #######
@@ -672,6 +606,7 @@ uninstall-vtpmmgr:
 
 # Only clean the libxc/ioemu/mini-os part
 .PHONY: clean
+clean: $(foreach lib,$(STUB_LIBS),clean-libxen$(lib))
 clean:
 	rm -fr mini-os-$(XEN_TARGET_ARCH)-ioemu
 	rm -fr mini-os-$(XEN_TARGET_ARCH)-c
@@ -688,13 +623,6 @@ clean:
 	rm -f $(STUBDOMPATH)
 	rm -f *-minios-config.mk
 	rm -fr pkg-config
-	[ ! -e libs-$(XEN_TARGET_ARCH)/toolcore/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toolcore clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory clean
-	[ ! -e libs-$(XEN_TARGET_ARCH)/devicemodel/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel clean
 	[ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
 	-[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
 	-[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJG-0003wE-VG; Wed, 09 Sep 2020 10:26:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJF-0003w2-LI
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:37 +0000
X-Inumbo-ID: cc3560b1-628f-4ff2-9e37-3f681a0badc5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cc3560b1-628f-4ff2-9e37-3f681a0badc5;
 Wed, 09 Sep 2020 10:26:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LcHRXWOBMrntwDmT2Cqy9A6zQqWqF9N5rW5GX03kK04=; b=UtCKpCS2pNrn3H/ygm/Rw7QsZz
 y5nj/AxcIpsZe8WBA33cJ+F6lzgjLlGh5c3G3nUgcinPuWRiI6RYVEWLOpNvOJdoG6iUPKSLCHO6f
 dff9wkl5aLKe0I1wLg0kN6qRYxx89DtZfAUKvlEBpXvXpBxByRidK+qvosr/izVIytXU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJE-00053f-NM
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJE-0006z3-Lh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] stubdom/grub: update init_netfront() call for mini-os
Message-Id: <E1kFxJE-0006z3-Lh@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8d990807ec2cde3061222a5ed2df62aba78bace9
Author:     Costin Lupu <costin.lupu@cs.pub.ro>
AuthorDate: Fri Aug 28 09:17:44 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Aug 28 09:17:44 2020 +0200

    stubdom/grub: update init_netfront() call for mini-os
    
    This patch updates the call of init_netfront() function according to its
    recently updated declaration which can also include parameters for gateway
    and netmask addresses. While we are here, the patch also removes passing
    the ip parameter because (a) it is not used anywhere and (b) it wastes
    memory since it would reference a dynamically allocated string.
    
    Reported-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 stubdom/grub/mini-os.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/stubdom/grub/mini-os.c b/stubdom/grub/mini-os.c
index 4fc052a255..b33dbf02fb 100644
--- a/stubdom/grub/mini-os.c
+++ b/stubdom/grub/mini-os.c
@@ -291,8 +291,6 @@ struct netfront_dev *net_dev;
 int
 minios_probe (struct nic *nic)
 {
-    char *ip;
-
     if (net_dev)
         return 1;
 
@@ -300,7 +298,7 @@ minios_probe (struct nic *nic)
     grub_memset ((char *) arptable, 0,
                  MAX_ARP * sizeof (struct arptable_t));
 
-    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, &ip);
+    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, NULL, NULL, NULL);
     if (!net_dev)
         return 0;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJR-0003xJ-0i; Wed, 09 Sep 2020 10:26:49 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJQ-0003xA-HY
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:48 +0000
X-Inumbo-ID: 06b4a1db-b5c8-4f4f-93d2-22e21665a560
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 06b4a1db-b5c8-4f4f-93d2-22e21665a560;
 Wed, 09 Sep 2020 10:26:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=OqnMyUe+kT/xoZnY91mr1RWT2eX+RGc/lAGGgKLaE2s=; b=pjKHmX7wMH9nEge61tj3xlNO0K
 4akST3IfPSKFjj3zC/jBtjpFTHFDA8cmvjhNdUea5YwnOY+8RJzAezkXJah8fse2Pwp7ymuhlYhiH
 mbdqxkVoRKXVTC1pWD/u5YGBjrZD2b6hG5O+AVr6es6wjbwtsTSc33fcEPSimpvutp/8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJO-00053m-RP
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJO-0006zV-Q9
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: tweak tools/libs/libs.mk for being able to
 support libxenctrl
Message-Id: <E1kFxJO-0006zV-Q9@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d400dc5729e4e132d61c2e7df57d81aaed762044
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sun Aug 23 10:00:12 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Fri Aug 28 09:02:13 2020 +0000

    tools: tweak tools/libs/libs.mk for being able to support libxenctrl
    
    tools/libs/libs.mk needs to be modified for being able to support
    building libxenctrl, as the pkg-config file of that library is not
    following the same conventions as those of the other libraries.
    
    So add support for specifying PKG_CONFIG before including libs.mk.
    
    In order to make life easier for unstable libraries like libxenctrl
    set MAJOR and MINOR automatically to the Xen-version and 0 when not
    specified. This removes the need to bump the versions of unstable
    libraries when switching to a new Xen version.
    
    As all libraries built via libs.mk require a map file generate a dummy
    one in case there is none existing. This again will help avoiding the
    need to bump the libarary version in the map file of an unstable
    library in case it is exporting all symbols.
    
    The clean target is missing the removal of _paths.h.
    
    Finally drop the foreach loop when setting PKG_CONFIG_LOCAL, as there
    is always only one element in PKG_CONFIG.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/libs.mk | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 19efc5e743..8b1ca2aa62 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -1,10 +1,13 @@
 # Common Makefile for building a lib.
 #
 # Variables taken as input:
-#   MAJOR:   major version of lib
-#   MINOR:   minor version of lib
+#   PKG_CONFIG: name of pkg-config file (xen$(LIBNAME).pc if empty)
+#   MAJOR:   major version of lib (Xen version if empty)
+#   MINOR:   minor version of lib (0 if empty)
 
 LIBNAME := $(notdir $(CURDIR))
+MAJOR ?= $(shell $(XEN_ROOT)/version.sh $(XEN_ROOT)/xen/Makefile)
+MINOR ?= 0
 
 SHLIB_LDFLAGS += -Wl,--version-script=libxen$(LIBNAME).map
 
@@ -22,7 +25,7 @@ ifneq ($(nosharedlibs),y)
 LIB += libxen$(LIBNAME).so
 endif
 
-PKG_CONFIG := xen$(LIBNAME).pc
+PKG_CONFIG ?= xen$(LIBNAME).pc
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
@@ -32,7 +35,7 @@ $(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
 $(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
 endif
 
-PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
+PKG_CONFIG_LOCAL := $(PKG_CONFIG_DIR)/$(PKG_CONFIG)
 
 LIBHEADER ?= xen$(LIBNAME).h
 LIBHEADERS = $(foreach h, $(LIBHEADER), include/$(h))
@@ -45,7 +48,7 @@ $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 all: build
 
 .PHONY: build
-build: libs
+build: libs libxen$(LIBNAME).map
 
 .PHONY: libs
 libs: headers.chk $(LIB) $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
@@ -64,6 +67,9 @@ endif
 
 headers.chk: $(LIBHEADERSGLOB) $(AUTOINCS)
 
+libxen$(LIBNAME).map:
+	echo 'VERS_$(MAJOR).$(MINOR) { global: *; };' >$@
+
 $(LIBHEADERSGLOB): $(LIBHEADERS)
 	for i in $(realpath $(LIBHEADERS)); do ln -sf $$i $(XEN_ROOT)/tools/include; done
 
@@ -87,7 +93,7 @@ install: build
 	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so
 	for i in $(LIBHEADERS); do $(INSTALL_DATA) $$i $(DESTDIR)$(includedir); done
-	$(INSTALL_DATA) xen$(LIBNAME).pc $(DESTDIR)$(PKG_INSTALLDIR)
+	$(INSTALL_DATA) $(PKG_CONFIG) $(DESTDIR)$(PKG_INSTALLDIR)
 
 .PHONY: uninstall
 uninstall:
@@ -107,8 +113,9 @@ clean:
 	rm -rf *.rpm $(LIB) *~ $(DEPS_RM) $(LIB_OBJS) $(PIC_OBJS)
 	rm -f libxen$(LIBNAME).so.$(MAJOR).$(MINOR) libxen$(LIBNAME).so.$(MAJOR)
 	rm -f headers.chk
-	rm -f xen$(LIBNAME).pc
+	rm -f $(PKG_CONFIG)
 	rm -f $(LIBHEADERSGLOB)
+	rm -f _paths.h
 
 .PHONY: distclean
 distclean: clean
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:26:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:26:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJb-0003yL-2L; Wed, 09 Sep 2020 10:26:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJZ-0003y9-PZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:57 +0000
X-Inumbo-ID: f479e8e1-2bd5-421b-b768-132a8f2df434
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f479e8e1-2bd5-421b-b768-132a8f2df434;
 Wed, 09 Sep 2020 10:26:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eQO6TAcYghVws2FAJVH6jvAYu0IWaiMSmBpFa+q5ngg=; b=Ew98NSK1KlYQn9O9wYGaX7prnZ
 9dYBKXbGESzULuSQmXSMQQc7e+laQe0r8Ni0IaFeev4UY4QbmVarrgFlp7DBWzz6EB8a5EXmPmX83
 5YgRZkmZjukqJb5CFakx53EeBnwyCCppPd10TOtjWDacTh/mh1TacOtMlRSkXKeBdMLo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJY-000545-VJ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJY-0006zz-UP
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:26:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kFxJY-0006zz-UP@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:26:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Apr 10 16:25:40 2018 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Aug 31 13:43:26 2020 +0100

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 63a03ef1e5..4b424fac95 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -719,6 +719,14 @@ int init_domain_cpuid_policy(struct domain *d)
     if ( d->disable_migrate )
         p->extd.itsc = cpu_has_itsc;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     d->arch.cpuid = p;
 
     recalculate_cpuid_policy(d);
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index c3862033eb..a478b91f23 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -130,6 +130,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
         mp->platform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:27:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:27:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJl-0003zh-5p; Wed, 09 Sep 2020 10:27:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJk-0003zW-7a
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:08 +0000
X-Inumbo-ID: 5d58c737-db90-4fb9-a6cb-e145a704aad3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5d58c737-db90-4fb9-a6cb-e145a704aad3;
 Wed, 09 Sep 2020 10:27:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Xztjdn5phnsE3BQs0b2otpcD9obtkx0S7zX5sIaSHuc=; b=RxU6Z5AS1DrVfLJgEssk4d0RmS
 j+1XiSVMYT0LXDtIyuQFaEPNXy6k6T5g3JMd9KlaaRktvcf+9wzt3H9dGV+NLw9l/7WBfV3krYhxZ
 PzSeRjOzfg+gniG9XxAVhPjgwdoDpg7hhi2lsFYwVNhAx8Rwafi/3QzcbHJ/zBGqHn7Q=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJj-00054q-3e
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJj-00072B-21
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kFxJj-00072B-21@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit afe018e041ec112d90a8b4e6ed607d22aa06f280
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Aug 31 12:18:42 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Aug 31 14:21:46 2020 +0100

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/mm.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 29048d34dc..28bc98f8f2 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1059,17 +1059,54 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:27:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:27:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxJv-00041G-7j; Wed, 09 Sep 2020 10:27:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxJu-000416-2o
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:18 +0000
X-Inumbo-ID: aaa829d0-c8dd-412b-a4f0-7f660a72d33c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id aaa829d0-c8dd-412b-a4f0-7f660a72d33c;
 Wed, 09 Sep 2020 10:27:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=9m1VS1nZa9xH//PYx3qyKAck26lJDRCsb9oRaC1HdBQ=; b=52Zk9NiwNo85tVoBgG+JVrePcJ
 1apF+7XETAV1D90/6P6OV1n+hczA7FhjIn0809s5Lwu1PmAKGaFDQgtyQHWFdtorgK9eHYcOu3Cvw
 M8Myqi+1aHC0OoDLfxaNXBD1ZZ0GIBjb4iy4ooTpy+p9i72ZzqW/VyRHvuc6pSBjSa7Y=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJt-00054w-7Y
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxJt-00072e-6f
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: simplify is_guest_l2_slot()
Message-Id: <E1kFxJt-00072e-6f@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8cf225013582723275f0d60f1107319f5963af7f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 10:59:33 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 10:59:33 2020 +0200

    x86: simplify is_guest_l2_slot()
    
    is_pv_32bit_domain() has become expensive, and its use here is
    redundant: Only 32-bit guests would ever get PGT_pae_xen_l2 set on
    their L2 page table pages anyway. (If some other error does lead to
    PGT_pae_xen_l2 ending up anywhere else, we still don't want to allow a
    guest to control the entries.)
    
    Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/page.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/page.h b/xen/include/asm-x86/x86_64/page.h
index 26621f9519..60db28f4e7 100644
--- a/xen/include/asm-x86/x86_64/page.h
+++ b/xen/include/asm-x86/x86_64/page.h
@@ -106,8 +106,7 @@ typedef l4_pgentry_t root_pgentry_t;
 #define l4_linear_offset(_a) (((_a) & VADDR_MASK) >> L4_PAGETABLE_SHIFT)
 
 #define is_guest_l2_slot(_d, _t, _s)                   \
-    ( !is_pv_32bit_domain(_d) ||                       \
-      !((_t) & PGT_pae_xen_l2) ||                      \
+    ( !((_t) & PGT_pae_xen_l2) ||                      \
       ((_s) < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_d)) )
 #define is_guest_l4_slot(_d, _s)                    \
     ( is_pv_32bit_domain(_d)                        \
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:27:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:27:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxK5-00043s-9U; Wed, 09 Sep 2020 10:27:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxK4-00043e-3s
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:28 +0000
X-Inumbo-ID: 6f3b02b6-877b-4f7e-96f7-86c68591e7d6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6f3b02b6-877b-4f7e-96f7-86c68591e7d6;
 Wed, 09 Sep 2020 10:27:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=t9H2pOFsot0ZBkDteiMyJAynOuEyVxMrRaByEvOJXRE=; b=FmGTsRa5DfjAnTzXT8Y++lZU5A
 8UoAljKE01f+9cKXuxoC43AbNFI/ZU76WXAUgw3IUNcfT876lE9wjSnIQOgwWNRSKudcH0AnSj15l
 sL+CckxTMlAID3hwXS6nqbvW1AcYFwXjAlfc/ma+4muCYcitUER8tSNXTh37+fjmf4z8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxK3-000553-BG
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxK3-00073C-AR
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/msr: explicitly handle AMD DE_CFG
Message-Id: <E1kFxK3-00073C-AR@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4175fd3ccd17face664036fa98e9329aa317f7b6
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 4 11:00:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:00:46 2020 +0200

    x86/msr: explicitly handle AMD DE_CFG
    
    Report LFENCE_SERIALISE unconditionally for DE_CFG on AMD hardware and
    silently drop writes.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/msr.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index a478b91f23..74bf7d9589 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -292,6 +292,12 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         *val = msrs->tsc_aux;
         break;
 
+    case MSR_AMD64_DE_CFG:
+        if ( !(cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
+            goto gp_fault;
+        *val = AMD64_DE_CFG_LFENCE_SERIALISE;
+        break;
+
     case MSR_AMD64_DR0_ADDRESS_MASK:
     case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
         if ( !cp->extd.dbext )
@@ -517,6 +523,15 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
             wrmsr_tsc_aux(val);
         break;
 
+    case MSR_AMD64_DE_CFG:
+        /*
+         * OpenBSD 6.7 will panic if writing to DE_CFG triggers a #GP:
+         * https://www.illumos.org/issues/12998 - drop writes.
+         */
+        if ( !(cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )
+            goto gp_fault;
+        break;
+
     case MSR_AMD64_DR0_ADDRESS_MASK:
     case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
         if ( !cp->extd.dbext || val != (uint32_t)val )
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:27:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:27:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxKF-00044t-Ay; Wed, 09 Sep 2020 10:27:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxKE-00044h-8U
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:38 +0000
X-Inumbo-ID: e8029841-19f3-4c9a-b2d7-6acdef0f8f97
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e8029841-19f3-4c9a-b2d7-6acdef0f8f97;
 Wed, 09 Sep 2020 10:27:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=I1cCbDJsfFfBGDLGCsIyJDdL9laaZgXox9ckUC8/6OY=; b=YMdZ3FC7oazrfSSphFRgMAf8BT
 1oaIBXq9mN37gRABjxpN9M75LAt/QMMnasUaKfiztA7MmNdnJjPft/WwmLDs92JVz2hZRE14HSShi
 WbraxQw3v5BDfO5KLWQ/oTKxD0FhTCLq0z2w5iJJaG8G5Cq1vbawZN0JaTS1lsjYCjRA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKD-00055D-Ez
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKD-00073l-EA
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] add additional symbols to xen-syms.map
Message-Id: <E1kFxKD-00073l-EA@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c9e88d200d1b8c4edef5bddb91690e76f7f87780
Author:     Michael Kurth <mku@amazon.de>
AuthorDate: Fri Sep 4 11:01:45 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:01:45 2020 +0200

    add additional symbols to xen-syms.map
    
    Add "all_symbols" to all /tools/symbols calls so that
    xen-syms.map lists all symbols and not only .text section
    symbols. This change enhances debugging and livepatch
    capabilities.
    
    Signed-off-by: Michael Kurth <mku@amazon.de>
    Reviewed-by: Eslam Elnikety <elnikety@amazon.de>
    Reviewed-by: Julien Grall <jgrall@amazon.co.uk>
    Reviewed-by: Robert Stonehouse <rjstone@amazon.co.uk>
    Reviewed-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/arm/Makefile | 2 +-
 xen/arch/x86/Makefile | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 7e82b2178c..51173d9712 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -115,7 +115,7 @@ $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
 	    $(@D)/.$(@F).1.o -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \
 		>$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]*
 
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 1073e454b1..1f279b6b2e 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -168,7 +168,7 @@ $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
 	    $(@D)/.$(@F).1.o -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort \
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \
 		>$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
 
@@ -224,7 +224,7 @@ $(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o efi/mkreloc
 	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \
 	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(note_file_option) -o $@
 	$(NM) -pa --format=sysv $(@D)/$(@F) \
-		| $(BASEDIR)/tools/symbols --xensyms --sysv --sort >$(@D)/$(@F).map
+		| $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort >$(@D)/$(@F).map
 	rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
 else
 $(TARGET).efi: FORCE
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:27:51 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:27:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxKR-00045y-Co; Wed, 09 Sep 2020 10:27:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxKQ-00045r-5Q
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:50 +0000
X-Inumbo-ID: 5aad4587-501e-4eba-b9c1-58b4cd993fe6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5aad4587-501e-4eba-b9c1-58b4cd993fe6;
 Wed, 09 Sep 2020 10:27:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/N5zraCQnUxNaQq90wKWA2BgYO5rVL6MPOA3iHHZqo0=; b=yftytMh0DRMaUiWmrXSYyXPmmG
 vj2u9txsH33+uNyZ3LQ3GULZNUj7MgHKe2VBkwV5w7KX/GOob5ONg/8PhFhQeGabn6/vyn/brIs7p
 ptULArsBZMGE9XwQiuYy+f0gtyG787nYX/Z6oenbNqFvcJRf005qgPWhTIHy23NSSPfs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKN-00055K-LD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKN-00074J-Ih
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: fix compat header generation
Message-Id: <E1kFxKN-00074J-Ih@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0dd40d68b10a2b3191a06ff8a996a57dcca96a88
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:05:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:05:46 2020 +0200

    x86: fix compat header generation
    
    As was pointed out by 0e2e54966af5 ("mm: fix public declaration of
    struct xen_mem_acquire_resource"), we're not currently handling structs
    correctly that have uint64_aligned_t fields. #pragma pack(4) suppresses
    the necessary alignment even if the type did properly survive (which
    it also didn't) in the process of generating the headers. Overall,
    with the above mentioned change applied, there's only a latent issue
    here afaict, i.e. no other of our interface structs is currently
    affected.
    
    As a result it is clear that using #pragma pack(4) is not an option.
    Drop all uses from compat header generation. Make sure
    {,u}int64_aligned_t actually survives, such that explicitly aligned
    fields will remain aligned. Arrange for {,u}int64_t to be transformed
    into a type that's 64 bits wide and 4-byte aligned, by utilizing that
    in typedef-s the "aligned" attribute can be used to reduce alignment.
    Additionally, for the cases where native structures get re-used,
    enforce suitable alignment via typedef-s (which allow alignment to be
    reduced).
    
    This use of typedef-s makes necessary changes to CHECK_*() macro
    generation: Previously get-fields.sh relied on finding struct/union
    keywords when other compound types were used. We need to use the
    typedef-s (guaranteeing suitable alignment) now, and hence the script
    has to recognize those cases, too. (Unfortunately there are a few
    special cases to be dealt with, but this is really not much different
    from e.g. the pre-existing compat_domain_handle_t special case.)
    
    This need to use typedef-s is certainly somewhat fragile going forward,
    as in similar future cases it is imperative to also use typedef-s, or
    else the CHECK_*() macros won't check what they're supposed to check. I
    don't currently see any means to avoid this fragility, though.
    
    There's one change to generated code according to my observations: In
    arch_compat_vcpu_op() the runstate area "area" variable would previously
    have been put in a just 4-byte aligned stack slot (despite being 8 bytes
    in size), whereas now it gets put in an 8-byte aligned location.
    
    There also results some curious inconsistency in struct xen_mc from
    these changes - I intend to clean this up later on. Otherwise unrelated
    code would also need adjustment right here.
    
    Additionally a note about the apparently superfluous () in
    compat-build-header.py: The simpler form
    
     [ r"typedef(.*)@KeeP@(xen_?)?([\w]+)([^\w])",
       r"typedef\1\2\3 __attribute__((__aligned__(__alignof(\1compat_\3))))\4" ],
    
    upsets Python up to at least 3.4.6, claiming to be unable to find the
    expansion of \2 (at least when it's empty).
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/Makefile                  | 11 -------
 xen/include/public/arch-x86/pmu.h     |  6 ++--
 xen/include/public/arch-x86/xen-mca.h | 33 ++++++++++++---------
 xen/include/public/argo.h             | 10 +++----
 xen/include/public/event_channel.h    | 20 ++++++-------
 xen/include/public/hvm/dm_op.h        | 54 +++++++++++++++++++++++------------
 xen/include/public/hvm/hvm_vcpu.h     |  6 ++--
 xen/include/public/hypfs.h            |  3 +-
 xen/include/public/memory.h           |  2 +-
 xen/include/public/physdev.h          | 12 ++++----
 xen/include/public/platform.h         | 50 +++++++++++++++++---------------
 xen/include/public/pmu.h              |  2 +-
 xen/include/public/xen.h              |  3 +-
 xen/include/public/xsm/flask_op.h     | 39 ++++++++++++++++---------
 xen/tools/compat-build-header.py      |  8 ++++--
 xen/tools/compat-build-source.py      |  1 +
 xen/tools/get-fields.sh               | 23 +++++++++++++++
 17 files changed, 170 insertions(+), 113 deletions(-)

diff --git a/xen/include/Makefile b/xen/include/Makefile
index 089314dc72..0be5540886 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -34,15 +34,6 @@ headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h
 cppflags-y                := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS
 cppflags-$(CONFIG_X86)    += -m32
 
-# 8-byte types are 4-byte aligned on x86_32 ...
-ifeq ($(CONFIG_CC_IS_CLANG),y)
-prefix-$(CONFIG_X86)      := \#pragma pack(push, 4)
-suffix-$(CONFIG_X86)      := \#pragma pack(pop)
-else
-prefix-$(CONFIG_X86)      := \#pragma pack(4)
-suffix-$(CONFIG_X86)      := \#pragma pack()
-endif
-
 endif
 
 public-$(CONFIG_X86) := $(wildcard public/arch-x86/*.h public/arch-x86/*/*.h)
@@ -57,10 +48,8 @@ compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
 	echo "#define $$id" >>$@.new; \
 	echo "#include <xen/compat.h>" >>$@.new; \
 	$(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \
-	$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
 	grep -v '^# [0-9]' $< | \
 	$(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
-	$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
 	echo "#endif /* $$id */" >>$@.new
 	mv -f $@.new $@
 
diff --git a/xen/include/public/arch-x86/pmu.h b/xen/include/public/arch-x86/pmu.h
index c421cb7a4a..464c65dac1 100644
--- a/xen/include/public/arch-x86/pmu.h
+++ b/xen/include/public/arch-x86/pmu.h
@@ -105,7 +105,7 @@ struct xen_pmu_arch {
          * Processor's registers at the time of interrupt.
          * WO for hypervisor, RO for guests.
          */
-        struct xen_pmu_regs regs;
+        xen_pmu_regs_t regs;
         /* Padding for adding new registers to xen_pmu_regs in the future */
 #define XENPMU_REGS_PAD_SZ  64
         uint8_t pad[XENPMU_REGS_PAD_SZ];
@@ -132,8 +132,8 @@ struct xen_pmu_arch {
      * hypervisor into hardware during XENPMU_flush
      */
     union {
-        struct xen_pmu_amd_ctxt amd;
-        struct xen_pmu_intel_ctxt intel;
+        xen_pmu_amd_ctxt_t amd;
+        xen_pmu_intel_ctxt_t intel;
 
         /*
          * Padding for contexts (fixed parts only, does not include MSR banks
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index b5e04b5444..702998b0eb 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -112,7 +112,7 @@ struct mcinfo_common {
     uint16_t type;      /* structure type */
     uint16_t size;      /* size of this struct in bytes */
 };
-
+typedef struct mcinfo_common xen_mcinfo_common_t;
 
 #define MC_FLAG_CORRECTABLE     (1 << 0)
 #define MC_FLAG_UNCORRECTABLE   (1 << 1)
@@ -123,7 +123,7 @@ struct mcinfo_common {
 #define MC_FLAG_MCE		(1 << 6)
 /* contains global x86 mc information */
 struct mcinfo_global {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     /* running domain at the time in error (most likely the impacted one) */
     uint16_t mc_domid;
@@ -138,7 +138,7 @@ struct mcinfo_global {
 
 /* contains bank local x86 mc information */
 struct mcinfo_bank {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     uint16_t mc_bank; /* bank nr */
     uint16_t mc_domid; /* Usecase 5: domain referenced by mc_addr on dom0
@@ -156,11 +156,12 @@ struct mcinfo_msr {
     uint64_t reg;   /* MSR */
     uint64_t value; /* MSR value */
 };
+typedef struct mcinfo_msr xen_mcinfo_msr_t;
 
 /* contains mc information from other
  * or additional mc MSRs */
 struct mcinfo_extended {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
 
     /* You can fill up to five registers.
      * If you need more, then use this structure
@@ -172,7 +173,7 @@ struct mcinfo_extended {
      * and E(R)FLAGS, E(R)IP, E(R)MISC, up to 11/19 of them might be
      * useful at present. So expand this array to 32 to leave room.
      */
-    struct mcinfo_msr mc_msr[32];
+    xen_mcinfo_msr_t mc_msr[32];
 };
 
 /* Recovery Action flags. Giving recovery result information to DOM0 */
@@ -208,6 +209,7 @@ struct page_offline_action
     uint64_t mfn;
     uint64_t status;
 };
+typedef struct page_offline_action xen_page_offline_action_t;
 
 struct cpu_offline_action
 {
@@ -216,17 +218,18 @@ struct cpu_offline_action
     uint16_t mc_coreid;
     uint16_t mc_core_threadid;
 };
+typedef struct cpu_offline_action xen_cpu_offline_action_t;
 
 #define MAX_UNION_SIZE 16
 struct mcinfo_recovery
 {
-    struct mcinfo_common common;
+    xen_mcinfo_common_t common;
     uint16_t mc_bank; /* bank nr */
     uint8_t action_flags;
     uint8_t action_types;
     union {
-        struct page_offline_action page_retire;
-        struct cpu_offline_action cpu_offline;
+        xen_page_offline_action_t page_retire;
+        xen_cpu_offline_action_t cpu_offline;
         uint8_t pad[MAX_UNION_SIZE];
     } action_info;
 };
@@ -279,7 +282,7 @@ struct mcinfo_logical_cpu {
     uint32_t mc_cache_size;
     uint32_t mc_cache_alignment;
     int32_t mc_nmsrvals;
-    struct mcinfo_msr mc_msrvalues[__MC_MSR_ARRAYSIZE];
+    xen_mcinfo_msr_t mc_msrvalues[__MC_MSR_ARRAYSIZE];
 };
 typedef struct mcinfo_logical_cpu xen_mc_logical_cpu_t;
 DEFINE_XEN_GUEST_HANDLE(xen_mc_logical_cpu_t);
@@ -399,8 +402,9 @@ struct xen_mc_msrinject {
     domid_t  mcinj_domid;           /* valid only if MC_MSRINJ_F_GPADDR is
                                        present in mcinj_flags */
     uint16_t _pad0;
-    struct mcinfo_msr mcinj_msr[MC_MSRINJ_MAXMSRS];
+    xen_mcinfo_msr_t mcinj_msr[MC_MSRINJ_MAXMSRS];
 };
+typedef struct xen_mc_msrinject xen_mc_msrinject_t;
 
 /* Flags for mcinj_flags above; bits 16-31 are reserved */
 #define MC_MSRINJ_F_INTERPOSE   0x1
@@ -410,6 +414,7 @@ struct xen_mc_msrinject {
 struct xen_mc_mceinject {
     unsigned int mceinj_cpunr;      /* target processor id */
 };
+typedef struct xen_mc_mceinject xen_mc_mceinject_t;
 
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 #define XEN_MC_inject_v2        6
@@ -422,7 +427,7 @@ struct xen_mc_mceinject {
 
 struct xen_mc_inject_v2 {
     uint32_t flags;
-    struct xenctl_bitmap cpumap;
+    xenctl_bitmap_t cpumap;
 };
 #endif
 
@@ -431,10 +436,10 @@ struct xen_mc {
     uint32_t interface_version; /* XEN_MCA_INTERFACE_VERSION */
     union {
         struct xen_mc_fetch        mc_fetch;
-        struct xen_mc_notifydomain mc_notifydomain;
+        xen_mc_notifydomain_t      mc_notifydomain;
         struct xen_mc_physcpuinfo  mc_physcpuinfo;
-        struct xen_mc_msrinject    mc_msrinject;
-        struct xen_mc_mceinject    mc_mceinject;
+        xen_mc_msrinject_t         mc_msrinject;
+        xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
         struct xen_mc_inject_v2    mc_inject_v2;
 #endif
diff --git a/xen/include/public/argo.h b/xen/include/public/argo.h
index 6b645f34e6..3397a3a33f 100644
--- a/xen/include/public/argo.h
+++ b/xen/include/public/argo.h
@@ -67,8 +67,8 @@ typedef struct xen_argo_addr
 
 typedef struct xen_argo_send_addr
 {
-    struct xen_argo_addr src;
-    struct xen_argo_addr dst;
+    xen_argo_addr_t src;
+    xen_argo_addr_t dst;
 } xen_argo_send_addr_t;
 
 typedef struct xen_argo_ring
@@ -121,7 +121,7 @@ typedef struct xen_argo_unregister_ring
 
 typedef struct xen_argo_ring_data_ent
 {
-    struct xen_argo_addr ring;
+    xen_argo_addr_t ring;
     uint16_t flags;
     uint16_t pad;
     uint32_t space_required;
@@ -132,13 +132,13 @@ typedef struct xen_argo_ring_data
 {
     uint32_t nent;
     uint32_t pad;
-    struct xen_argo_ring_data_ent data[XEN_FLEX_ARRAY_DIM];
+    xen_argo_ring_data_ent_t data[XEN_FLEX_ARRAY_DIM];
 } xen_argo_ring_data_t;
 
 struct xen_argo_ring_message_header
 {
     uint32_t len;
-    struct xen_argo_addr source;
+    xen_argo_addr_t source;
     uint32_t message_type;
     uint8_t data[XEN_FLEX_ARRAY_DIM];
 };
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index cfb7929fef..246ace4d19 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -321,16 +321,16 @@ typedef struct evtchn_set_priority evtchn_set_priority_t;
 struct evtchn_op {
     uint32_t cmd; /* enum event_channel_op */
     union {
-        struct evtchn_alloc_unbound    alloc_unbound;
-        struct evtchn_bind_interdomain bind_interdomain;
-        struct evtchn_bind_virq        bind_virq;
-        struct evtchn_bind_pirq        bind_pirq;
-        struct evtchn_bind_ipi         bind_ipi;
-        struct evtchn_close            close;
-        struct evtchn_send             send;
-        struct evtchn_status           status;
-        struct evtchn_bind_vcpu        bind_vcpu;
-        struct evtchn_unmask           unmask;
+        evtchn_alloc_unbound_t    alloc_unbound;
+        evtchn_bind_interdomain_t bind_interdomain;
+        evtchn_bind_virq_t        bind_virq;
+        evtchn_bind_pirq_t        bind_pirq;
+        evtchn_bind_ipi_t         bind_ipi;
+        evtchn_close_t            close;
+        evtchn_send_t             send;
+        evtchn_status_t           status;
+        evtchn_bind_vcpu_t        bind_vcpu;
+        evtchn_unmask_t           unmask;
     } u;
 };
 typedef struct evtchn_op evtchn_op_t;
diff --git a/xen/include/public/hvm/dm_op.h b/xen/include/public/hvm/dm_op.h
index fd00e9d761..66cae1afbd 100644
--- a/xen/include/public/hvm/dm_op.h
+++ b/xen/include/public/hvm/dm_op.h
@@ -74,6 +74,7 @@ struct xen_dm_op_create_ioreq_server {
     /* OUT - server id */
     ioservid_t id;
 };
+typedef struct xen_dm_op_create_ioreq_server xen_dm_op_create_ioreq_server_t;
 
 /*
  * XEN_DMOP_get_ioreq_server_info: Get all the information necessary to
@@ -113,6 +114,7 @@ struct xen_dm_op_get_ioreq_server_info {
     /* OUT - buffered ioreq gfn (see block comment above)*/
     uint64_aligned_t bufioreq_gfn;
 };
+typedef struct xen_dm_op_get_ioreq_server_info xen_dm_op_get_ioreq_server_info_t;
 
 /*
  * XEN_DMOP_map_io_range_to_ioreq_server: Register an I/O range for
@@ -148,6 +150,7 @@ struct xen_dm_op_ioreq_server_range {
     /* IN - inclusive start and end of range */
     uint64_aligned_t start, end;
 };
+typedef struct xen_dm_op_ioreq_server_range xen_dm_op_ioreq_server_range_t;
 
 #define XEN_DMOP_PCI_SBDF(s,b,d,f) \
 	((((s) & 0xffff) << 16) |  \
@@ -173,6 +176,7 @@ struct xen_dm_op_set_ioreq_server_state {
     uint8_t enabled;
     uint8_t pad;
 };
+typedef struct xen_dm_op_set_ioreq_server_state xen_dm_op_set_ioreq_server_state_t;
 
 /*
  * XEN_DMOP_destroy_ioreq_server: Destroy the IOREQ Server <id>.
@@ -186,6 +190,7 @@ struct xen_dm_op_destroy_ioreq_server {
     ioservid_t id;
     uint16_t pad;
 };
+typedef struct xen_dm_op_destroy_ioreq_server xen_dm_op_destroy_ioreq_server_t;
 
 /*
  * XEN_DMOP_track_dirty_vram: Track modifications to the specified pfn
@@ -203,6 +208,7 @@ struct xen_dm_op_track_dirty_vram {
     /* IN - first pfn to track */
     uint64_aligned_t first_pfn;
 };
+typedef struct xen_dm_op_track_dirty_vram xen_dm_op_track_dirty_vram_t;
 
 /*
  * XEN_DMOP_set_pci_intx_level: Set the logical level of one of a domain's
@@ -217,6 +223,7 @@ struct xen_dm_op_set_pci_intx_level {
     /* IN - Level: 0 -> deasserted, 1 -> asserted */
     uint8_t  level;
 };
+typedef struct xen_dm_op_set_pci_intx_level xen_dm_op_set_pci_intx_level_t;
 
 /*
  * XEN_DMOP_set_isa_irq_level: Set the logical level of a one of a domain's
@@ -230,6 +237,7 @@ struct xen_dm_op_set_isa_irq_level {
     /* IN - Level: 0 -> deasserted, 1 -> asserted */
     uint8_t  level;
 };
+typedef struct xen_dm_op_set_isa_irq_level xen_dm_op_set_isa_irq_level_t;
 
 /*
  * XEN_DMOP_set_pci_link_route: Map a PCI INTx line to an IRQ line.
@@ -242,6 +250,7 @@ struct xen_dm_op_set_pci_link_route {
     /* ISA IRQ (1-15) or 0 -> disable link */
     uint8_t  isa_irq;
 };
+typedef struct xen_dm_op_set_pci_link_route xen_dm_op_set_pci_link_route_t;
 
 /*
  * XEN_DMOP_modified_memory: Notify that a set of pages were modified by
@@ -265,6 +274,7 @@ struct xen_dm_op_modified_memory {
     /* IN/OUT - Must be set to 0 */
     uint32_t opaque;
 };
+typedef struct xen_dm_op_modified_memory xen_dm_op_modified_memory_t;
 
 struct xen_dm_op_modified_memory_extent {
     /* IN - number of contiguous pages modified */
@@ -294,6 +304,7 @@ struct xen_dm_op_set_mem_type {
     /* IN - first pfn in region */
     uint64_aligned_t first_pfn;
 };
+typedef struct xen_dm_op_set_mem_type xen_dm_op_set_mem_type_t;
 
 /*
  * XEN_DMOP_inject_event: Inject an event into a VCPU, which will
@@ -327,6 +338,7 @@ struct xen_dm_op_inject_event {
     /* IN - type-specific extra data (%cr2 for #PF, pending_dbg for #DB) */
     uint64_aligned_t cr2;
 };
+typedef struct xen_dm_op_inject_event xen_dm_op_inject_event_t;
 
 /*
  * XEN_DMOP_inject_msi: Inject an MSI for an emulated device.
@@ -340,6 +352,7 @@ struct xen_dm_op_inject_msi {
     /* IN - MSI address (0xfeexxxxx) */
     uint64_aligned_t addr;
 };
+typedef struct xen_dm_op_inject_msi xen_dm_op_inject_msi_t;
 
 /*
  * XEN_DMOP_map_mem_type_to_ioreq_server : map or unmap the IOREQ Server <id>
@@ -366,6 +379,7 @@ struct xen_dm_op_map_mem_type_to_ioreq_server {
     uint64_t opaque;    /* IN/OUT - only used for hypercall continuation,
                            has to be set to zero by the caller */
 };
+typedef struct xen_dm_op_map_mem_type_to_ioreq_server xen_dm_op_map_mem_type_to_ioreq_server_t;
 
 /*
  * XEN_DMOP_remote_shutdown : Declare a shutdown for another domain
@@ -377,6 +391,7 @@ struct xen_dm_op_remote_shutdown {
     uint32_t reason;       /* SHUTDOWN_* => enum sched_shutdown_reason */
                            /* (Other reason values are not blocked) */
 };
+typedef struct xen_dm_op_remote_shutdown xen_dm_op_remote_shutdown_t;
 
 /*
  * XEN_DMOP_relocate_memory : Relocate GFNs for the specified guest.
@@ -395,6 +410,7 @@ struct xen_dm_op_relocate_memory {
     /* Starting GFN where GFNs should be relocated. */
     uint64_aligned_t dst_gfn;
 };
+typedef struct xen_dm_op_relocate_memory xen_dm_op_relocate_memory_t;
 
 /*
  * XEN_DMOP_pin_memory_cacheattr : Pin caching type of RAM space.
@@ -416,30 +432,30 @@ struct xen_dm_op_pin_memory_cacheattr {
     uint32_t type;          /* XEN_DMOP_MEM_CACHEATTR_* */
     uint32_t pad;
 };
+typedef struct xen_dm_op_pin_memory_cacheattr xen_dm_op_pin_memory_cacheattr_t;
 
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
     union {
-        struct xen_dm_op_create_ioreq_server create_ioreq_server;
-        struct xen_dm_op_get_ioreq_server_info get_ioreq_server_info;
-        struct xen_dm_op_ioreq_server_range map_io_range_to_ioreq_server;
-        struct xen_dm_op_ioreq_server_range unmap_io_range_from_ioreq_server;
-        struct xen_dm_op_set_ioreq_server_state set_ioreq_server_state;
-        struct xen_dm_op_destroy_ioreq_server destroy_ioreq_server;
-        struct xen_dm_op_track_dirty_vram track_dirty_vram;
-        struct xen_dm_op_set_pci_intx_level set_pci_intx_level;
-        struct xen_dm_op_set_isa_irq_level set_isa_irq_level;
-        struct xen_dm_op_set_pci_link_route set_pci_link_route;
-        struct xen_dm_op_modified_memory modified_memory;
-        struct xen_dm_op_set_mem_type set_mem_type;
-        struct xen_dm_op_inject_event inject_event;
-        struct xen_dm_op_inject_msi inject_msi;
-        struct xen_dm_op_map_mem_type_to_ioreq_server
-                map_mem_type_to_ioreq_server;
-        struct xen_dm_op_remote_shutdown remote_shutdown;
-        struct xen_dm_op_relocate_memory relocate_memory;
-        struct xen_dm_op_pin_memory_cacheattr pin_memory_cacheattr;
+        xen_dm_op_create_ioreq_server_t create_ioreq_server;
+        xen_dm_op_get_ioreq_server_info_t get_ioreq_server_info;
+        xen_dm_op_ioreq_server_range_t map_io_range_to_ioreq_server;
+        xen_dm_op_ioreq_server_range_t unmap_io_range_from_ioreq_server;
+        xen_dm_op_set_ioreq_server_state_t set_ioreq_server_state;
+        xen_dm_op_destroy_ioreq_server_t destroy_ioreq_server;
+        xen_dm_op_track_dirty_vram_t track_dirty_vram;
+        xen_dm_op_set_pci_intx_level_t set_pci_intx_level;
+        xen_dm_op_set_isa_irq_level_t set_isa_irq_level;
+        xen_dm_op_set_pci_link_route_t set_pci_link_route;
+        xen_dm_op_modified_memory_t modified_memory;
+        xen_dm_op_set_mem_type_t set_mem_type;
+        xen_dm_op_inject_event_t inject_event;
+        xen_dm_op_inject_msi_t inject_msi;
+        xen_dm_op_map_mem_type_to_ioreq_server_t map_mem_type_to_ioreq_server;
+        xen_dm_op_remote_shutdown_t remote_shutdown;
+        xen_dm_op_relocate_memory_t relocate_memory;
+        xen_dm_op_pin_memory_cacheattr_t pin_memory_cacheattr;
     } u;
 };
 
diff --git a/xen/include/public/hvm/hvm_vcpu.h b/xen/include/public/hvm/hvm_vcpu.h
index d21abf1885..661cf89e1e 100644
--- a/xen/include/public/hvm/hvm_vcpu.h
+++ b/xen/include/public/hvm/hvm_vcpu.h
@@ -69,6 +69,7 @@ struct vcpu_hvm_x86_32 {
 
     uint16_t pad2[3];
 };
+typedef struct vcpu_hvm_x86_32 xen_vcpu_hvm_x86_32_t;
 
 /*
  * The layout of the _ar fields of the segment registers is the
@@ -114,6 +115,7 @@ struct vcpu_hvm_x86_64 {
      * the 32-bit structure should be used instead.
      */
 };
+typedef struct vcpu_hvm_x86_64 xen_vcpu_hvm_x86_64_t;
 
 struct vcpu_hvm_context {
 #define VCPU_HVM_MODE_32B 0  /* 32bit fields of the structure will be used. */
@@ -124,8 +126,8 @@ struct vcpu_hvm_context {
 
     /* CPU registers. */
     union {
-        struct vcpu_hvm_x86_32 x86_32;
-        struct vcpu_hvm_x86_64 x86_64;
+        xen_vcpu_hvm_x86_32_t x86_32;
+        xen_vcpu_hvm_x86_64_t x86_64;
     } cpu_regs;
 };
 typedef struct vcpu_hvm_context vcpu_hvm_context_t;
diff --git a/xen/include/public/hypfs.h b/xen/include/public/hypfs.h
index 63a5df1629..2b7a66d68d 100644
--- a/xen/include/public/hypfs.h
+++ b/xen/include/public/hypfs.h
@@ -53,9 +53,10 @@ struct xen_hypfs_direntry {
     uint32_t content_len;      /* Current length of data. */
     uint32_t max_write_len;    /* Max. length for writes (0 if read-only). */
 };
+typedef struct xen_hypfs_direntry xen_hypfs_direntry_t;
 
 struct xen_hypfs_dirlistentry {
-    struct xen_hypfs_direntry e;
+    xen_hypfs_direntry_t e;
     /* Offset in bytes to next entry (0 == this is the last entry). */
     uint16_t off_next;
     /* Zero terminated entry name, possibly with some padding for alignment. */
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index 21057ed78e..21d483298e 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -604,7 +604,7 @@ struct xen_reserved_device_memory_map {
     XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer;
     /* IN */
     union {
-        struct physdev_pci_device pci;
+        physdev_pci_device_t pci;
     } dev;
 };
 typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t;
diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h
index aedb71d678..d271766ad0 100644
--- a/xen/include/public/physdev.h
+++ b/xen/include/public/physdev.h
@@ -229,11 +229,11 @@ DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_ext_t);
 struct physdev_op {
     uint32_t cmd;
     union {
-        struct physdev_irq_status_query      irq_status_query;
-        struct physdev_set_iopl              set_iopl;
-        struct physdev_set_iobitmap          set_iobitmap;
-        struct physdev_apic                  apic_op;
-        struct physdev_irq                   irq_op;
+        physdev_irq_status_query_t irq_status_query;
+        physdev_set_iopl_t         set_iopl;
+        physdev_set_iobitmap_t     set_iobitmap;
+        physdev_apic_t             apic_op;
+        physdev_irq_t              irq_op;
     } u;
 };
 typedef struct physdev_op physdev_op_t;
@@ -334,7 +334,7 @@ struct physdev_dbgp_op {
     uint8_t op;
     uint8_t bus;
     union {
-        struct physdev_pci_device pci;
+        physdev_pci_device_t pci;
     } u;
 };
 typedef struct physdev_dbgp_op physdev_dbgp_op_t;
diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h
index f3c84ebc78..a4c0eb6224 100644
--- a/xen/include/public/platform.h
+++ b/xen/include/public/platform.h
@@ -42,6 +42,7 @@ struct xenpf_settime32 {
     uint32_t nsecs;
     uint64_t system_time;
 };
+typedef struct xenpf_settime32 xenpf_settime32_t;
 #define XENPF_settime64           62
 struct xenpf_settime64 {
     /* IN variables. */
@@ -50,6 +51,7 @@ struct xenpf_settime64 {
     uint32_t mbz;
     uint64_t system_time;
 };
+typedef struct xenpf_settime64 xenpf_settime64_t;
 #if __XEN_INTERFACE_VERSION__ < 0x00040600
 #define XENPF_settime XENPF_settime32
 #define xenpf_settime xenpf_settime32
@@ -529,6 +531,7 @@ struct xenpf_cpu_hotadd
 	uint32_t acpi_id;
 	uint32_t pxm;
 };
+typedef struct xenpf_cpu_hotadd xenpf_cpu_hotadd_t;
 
 #define XENPF_mem_hotadd    59
 struct xenpf_mem_hotadd
@@ -538,6 +541,7 @@ struct xenpf_mem_hotadd
     uint32_t pxm;
     uint32_t flags;
 };
+typedef struct xenpf_mem_hotadd xenpf_mem_hotadd_t;
 
 #define XENPF_core_parking  60
 
@@ -622,29 +626,29 @@ struct xen_platform_op {
     uint32_t cmd;
     uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
     union {
-        struct xenpf_settime           settime;
-        struct xenpf_settime32         settime32;
-        struct xenpf_settime64         settime64;
-        struct xenpf_add_memtype       add_memtype;
-        struct xenpf_del_memtype       del_memtype;
-        struct xenpf_read_memtype      read_memtype;
-        struct xenpf_microcode_update  microcode;
-        struct xenpf_platform_quirk    platform_quirk;
-        struct xenpf_efi_runtime_call  efi_runtime_call;
-        struct xenpf_firmware_info     firmware_info;
-        struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
-        struct xenpf_change_freq       change_freq;
-        struct xenpf_getidletime       getidletime;
-        struct xenpf_set_processor_pminfo set_pminfo;
-        struct xenpf_pcpuinfo          pcpu_info;
-        struct xenpf_pcpu_version      pcpu_version;
-        struct xenpf_cpu_ol            cpu_ol;
-        struct xenpf_cpu_hotadd        cpu_add;
-        struct xenpf_mem_hotadd        mem_add;
-        struct xenpf_core_parking      core_parking;
-        struct xenpf_resource_op       resource_op;
-        struct xenpf_symdata           symdata;
-        uint8_t                        pad[128];
+        xenpf_settime_t               settime;
+        xenpf_settime32_t             settime32;
+        xenpf_settime64_t             settime64;
+        xenpf_add_memtype_t           add_memtype;
+        xenpf_del_memtype_t           del_memtype;
+        xenpf_read_memtype_t          read_memtype;
+        xenpf_microcode_update_t      microcode;
+        xenpf_platform_quirk_t        platform_quirk;
+        xenpf_efi_runtime_call_t      efi_runtime_call;
+        xenpf_firmware_info_t         firmware_info;
+        xenpf_enter_acpi_sleep_t      enter_acpi_sleep;
+        xenpf_change_freq_t           change_freq;
+        xenpf_getidletime_t           getidletime;
+        xenpf_set_processor_pminfo_t  set_pminfo;
+        xenpf_pcpuinfo_t              pcpu_info;
+        xenpf_pcpu_version_t          pcpu_version;
+        xenpf_cpu_ol_t                cpu_ol;
+        xenpf_cpu_hotadd_t            cpu_add;
+        xenpf_mem_hotadd_t            mem_add;
+        xenpf_core_parking_t          core_parking;
+        xenpf_resource_op_t           resource_op;
+        xenpf_symdata_t               symdata;
+        uint8_t                       pad[128];
     } u;
 };
 typedef struct xen_platform_op xen_platform_op_t;
diff --git a/xen/include/public/pmu.h b/xen/include/public/pmu.h
index 0e1312cfe5..cc2fcf8816 100644
--- a/xen/include/public/pmu.h
+++ b/xen/include/public/pmu.h
@@ -127,7 +127,7 @@ struct xen_pmu_data {
     uint8_t pad[6];
 
     /* Architecture-specific information */
-    struct xen_pmu_arch pmu;
+    xen_pmu_arch_t pmu;
 };
 
 #endif /* __XEN_PUBLIC_PMU_H__ */
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 945ef30273..e373592c33 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -726,7 +726,7 @@ struct vcpu_info {
 #endif /* XEN_HAVE_PV_UPCALL_MASK */
     xen_ulong_t evtchn_pending_sel;
     struct arch_vcpu_info arch;
-    struct vcpu_time_info time;
+    vcpu_time_info_t time;
 }; /* 64 bytes (x86) */
 #ifndef __XEN__
 typedef struct vcpu_info vcpu_info_t;
@@ -1031,6 +1031,7 @@ struct xenctl_bitmap {
     XEN_GUEST_HANDLE_64(uint8) bitmap;
     uint32_t nr_bits;
 };
+typedef struct xenctl_bitmap xenctl_bitmap_t;
 #endif
 
 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
diff --git a/xen/include/public/xsm/flask_op.h b/xen/include/public/xsm/flask_op.h
index 970ec07f0b..16af7bc22f 100644
--- a/xen/include/public/xsm/flask_op.h
+++ b/xen/include/public/xsm/flask_op.h
@@ -33,10 +33,12 @@ struct xen_flask_load {
     XEN_GUEST_HANDLE(char) buffer;
     uint32_t size;
 };
+typedef struct xen_flask_load xen_flask_load_t;
 
 struct xen_flask_setenforce {
     uint32_t enforcing;
 };
+typedef struct xen_flask_setenforce xen_flask_setenforce_t;
 
 struct xen_flask_sid_context {
     /* IN/OUT: sid to convert to/from string */
@@ -47,6 +49,7 @@ struct xen_flask_sid_context {
     uint32_t size;
     XEN_GUEST_HANDLE(char) context;
 };
+typedef struct xen_flask_sid_context xen_flask_sid_context_t;
 
 struct xen_flask_access {
     /* IN: access request */
@@ -60,6 +63,7 @@ struct xen_flask_access {
     uint32_t audit_deny;
     uint32_t seqno;
 };
+typedef struct xen_flask_access xen_flask_access_t;
 
 struct xen_flask_transition {
     /* IN: transition SIDs and class */
@@ -69,6 +73,7 @@ struct xen_flask_transition {
     /* OUT: new SID */
     uint32_t newsid;
 };
+typedef struct xen_flask_transition xen_flask_transition_t;
 
 #if __XEN_INTERFACE_VERSION__ < 0x00040800
 struct xen_flask_userlist {
@@ -106,11 +111,13 @@ struct xen_flask_boolean {
      */
     XEN_GUEST_HANDLE(char) name;
 };
+typedef struct xen_flask_boolean xen_flask_boolean_t;
 
 struct xen_flask_setavc_threshold {
     /* IN */
     uint32_t threshold;
 };
+typedef struct xen_flask_setavc_threshold xen_flask_setavc_threshold_t;
 
 struct xen_flask_hash_stats {
     /* OUT */
@@ -119,6 +126,7 @@ struct xen_flask_hash_stats {
     uint32_t buckets_total;
     uint32_t max_chain_len;
 };
+typedef struct xen_flask_hash_stats xen_flask_hash_stats_t;
 
 struct xen_flask_cache_stats {
     /* IN */
@@ -131,6 +139,7 @@ struct xen_flask_cache_stats {
     uint32_t reclaims;
     uint32_t frees;
 };
+typedef struct xen_flask_cache_stats xen_flask_cache_stats_t;
 
 struct xen_flask_ocontext {
     /* IN */
@@ -138,6 +147,7 @@ struct xen_flask_ocontext {
     uint32_t sid;
     uint64_t low, high;
 };
+typedef struct xen_flask_ocontext xen_flask_ocontext_t;
 
 struct xen_flask_peersid {
     /* IN */
@@ -145,12 +155,14 @@ struct xen_flask_peersid {
     /* OUT */
     uint32_t sid;
 };
+typedef struct xen_flask_peersid xen_flask_peersid_t;
 
 struct xen_flask_relabel {
     /* IN */
     uint32_t domid;
     uint32_t sid;
 };
+typedef struct xen_flask_relabel xen_flask_relabel_t;
 
 struct xen_flask_devicetree_label {
     /* IN */
@@ -158,6 +170,7 @@ struct xen_flask_devicetree_label {
     uint32_t length;
     XEN_GUEST_HANDLE(char) path;
 };
+typedef struct xen_flask_devicetree_label xen_flask_devicetree_label_t;
 
 struct xen_flask_op {
     uint32_t cmd;
@@ -188,26 +201,26 @@ struct xen_flask_op {
 #define FLASK_DEVICETREE_LABEL  25
     uint32_t interface_version; /* XEN_FLASK_INTERFACE_VERSION */
     union {
-        struct xen_flask_load load;
-        struct xen_flask_setenforce enforce;
+        xen_flask_load_t load;
+        xen_flask_setenforce_t enforce;
         /* FLASK_CONTEXT_TO_SID and FLASK_SID_TO_CONTEXT */
-        struct xen_flask_sid_context sid_context;
-        struct xen_flask_access access;
+        xen_flask_sid_context_t sid_context;
+        xen_flask_access_t access;
         /* FLASK_CREATE, FLASK_RELABEL, FLASK_MEMBER */
-        struct xen_flask_transition transition;
+        xen_flask_transition_t transition;
 #if __XEN_INTERFACE_VERSION__ < 0x00040800
         struct xen_flask_userlist userlist;
 #endif
         /* FLASK_GETBOOL, FLASK_SETBOOL */
-        struct xen_flask_boolean boolean;
-        struct xen_flask_setavc_threshold setavc_threshold;
-        struct xen_flask_hash_stats hash_stats;
-        struct xen_flask_cache_stats cache_stats;
+        xen_flask_boolean_t boolean;
+        xen_flask_setavc_threshold_t setavc_threshold;
+        xen_flask_hash_stats_t hash_stats;
+        xen_flask_cache_stats_t cache_stats;
         /* FLASK_ADD_OCONTEXT, FLASK_DEL_OCONTEXT */
-        struct xen_flask_ocontext ocontext;
-        struct xen_flask_peersid peersid;
-        struct xen_flask_relabel relabel;
-        struct xen_flask_devicetree_label devicetree_label;
+        xen_flask_ocontext_t ocontext;
+        xen_flask_peersid_t peersid;
+        xen_flask_relabel_t relabel;
+        xen_flask_devicetree_label_t devicetree_label;
     } u;
 };
 typedef struct xen_flask_op xen_flask_op_t;
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index b85c43f13f..ca706ce353 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -3,7 +3,7 @@
 import re,sys
 
 pats = [
- [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ],
+ [ r"__InClUdE__(.*)", r"#include\1" ],
  [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ],
  [ r"__ElSe__", r"#else" ],
  [ r"__EnDif__", r"#endif" ],
@@ -11,9 +11,11 @@ pats = [
  [ r"__UnDeF__", r"#undef" ],
  [ r"\"xen-compat.h\"", r"<public/xen-compat.h>" ],
  [ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ],
- [ r"@KeeP@", r"" ],
+ [ r"typedef(.*)@KeeP@((xen_?)?)([\w]+)([^\w])",
+   r"typedef\1\2\4 __attribute__((__aligned__(__alignof(\1compat_\4))))\5" ],
  [ r"_t([^\w]|$)", r"_compat_t\1" ],
- [ r"(8|16|32|64)_compat_t([^\w]|$)", r"\1_t\2" ],
+ [ r"int(8|16|32|64_aligned)_compat_t([^\w]|$)", r"int\1_t\2" ],
+ [ r"(\su?int64(_compat)?)_T([^\w]|$)", r"\1_t\3" ],
  [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
  [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ],
  [ r"(^|[^\w])Xen_?", r"\1Compat_" ],
diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py
index c664eb85e6..fc10c7063f 100755
--- a/xen/tools/compat-build-source.py
+++ b/xen/tools/compat-build-source.py
@@ -9,6 +9,7 @@ pats = [
  [ r"^\s*#\s*endif /\* (XEN_HAVE.*) \*/\s+", r"__EnDif__" ],
  [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
  [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
+ [ r"^\s*#\s*define\s+(u?int64)_aligned_t\s.*aligned.*", r"typedef \1_T __attribute__((aligned(4))) \1_compat_T;" ],
  [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
 ];
 
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 45a0e2ed50..002db2093f 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -418,6 +418,21 @@ check_field ()
 			"}")
 				level=$(expr $level - 1) id=
 				;;
+			compat_*_t)
+				if [ $level = 2 ]
+				then
+					fields=" "
+					token="${token%_t}"
+					token="${token#compat_}"
+				fi
+				;;
+			evtchn_*_compat_t)
+				if [ $level = 2 -a $token != evtchn_port_compat_t ]
+				then
+					fields=" "
+					token="${token%_compat_t}"
+				fi
+				;;
 			[a-zA-Z]*)
 				id=$token
 				;;
@@ -464,6 +479,14 @@ build_check ()
 		"]")
 			arrlvl=$(expr $arrlvl - 1)
 			;;
+		compat_*_t)
+			if [ $level = 2 -a $token != compat_argo_port_t ]
+			then
+				fields=" "
+				token="${token%_t}"
+				token="${token#compat_}"
+			fi
+			;;
 		[a-zA-Z_]*)
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:00 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxKa-00046x-Gp; Wed, 09 Sep 2020 10:28:00 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxKY-00046p-Qe
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:58 +0000
X-Inumbo-ID: ba88c7b9-a493-47d5-8554-8e6e316f38e8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ba88c7b9-a493-47d5-8554-8e6e316f38e8;
 Wed, 09 Sep 2020 10:27:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=bzTAhgW9u4UrffwOVsVDqpMbukFzwNuzRAA9rV503hk=; b=DwBylef30kjx4b2tj4INVi41WL
 r/rZ/66sLrT9EQObrR3cbzoy1a2GmUi2UUP9figLL2qQ79zjAOyDSufU/aND1hQExyND/6ldhtr3W
 eXfZCsbpBlS2lh7eRaNPqAH8q8+kW/xaG/u7jcx+P29FHHrkiQ+P8IJs3sL0HEKoLl5k=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKX-00055N-Qi
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKX-00074m-OL
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:27:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/mce: add compat struct checking for XEN_MC_inject_v2
Message-Id: <E1kFxKX-00074m-OL@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:27:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9d207b88ff208ad829822a4f1da9d8ab020ef263
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:06:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:06:56 2020 +0200

    x86/mce: add compat struct checking for XEN_MC_inject_v2
    
    84e364f2eda2 ("x86: add CMCI software injection interface") merely made
    sure things would build, without any concern about things actually
    working:
    - despite the addition of xenctl_bitmap to xlat.lst, the resulting macro
      wasn't invoked anywhere (which would have lead to recognizing that the
      structure appeared to have no fully compatible layout, despite the use
      of a 64-bit handle),
    - the interface struct itself was neither added to xlat.lst (and the
      resulting macro then invoked) nor was any manual checking of
      individual fields added.
    
    Adjust compat header generation logic to retain XEN_GUEST_HANDLE_64(),
    which is intentionally layed out to be compatible between different size
    guests. Invoke the missing checking (implicitly through CHECK_mc).
    
    No change in the resulting generated code.
    
    Fixes: 84e364f2eda2 ("x86: add CMCI software injection interface")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/cpu/mcheck/mce.c         | 4 +++-
 xen/include/public/arch-x86/xen-mca.h | 3 ++-
 xen/include/xlat.lst                  | 1 +
 xen/tools/compat-build-header.py      | 1 +
 xen/tools/compat-build-source.py      | 2 +-
 5 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index fe9667e0c3..5ec16fab87 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1312,10 +1312,12 @@ CHECK_FIELD_(struct, mc_fetch, fetch_id);
 CHECK_FIELD_(struct, mc_physcpuinfo, ncpus);
 # define CHECK_compat_mc_physcpuinfo struct mc_physcpuinfo
 
-#define CHECK_compat_mc_inject_v2   struct mc_inject_v2
+# define xen_ctl_bitmap              xenctl_bitmap
+
 CHECK_mc;
 # undef CHECK_compat_mc_fetch
 # undef CHECK_compat_mc_physcpuinfo
+# undef xen_ctl_bitmap
 
 # define xen_mc_info                 mc_info
 CHECK_mc_info;
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index 702998b0eb..628b79e22a 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -429,6 +429,7 @@ struct xen_mc_inject_v2 {
     uint32_t flags;
     xenctl_bitmap_t cpumap;
 };
+typedef struct xen_mc_inject_v2 xen_mc_inject_v2_t;
 #endif
 
 struct xen_mc {
@@ -441,7 +442,7 @@ struct xen_mc {
         xen_mc_msrinject_t         mc_msrinject;
         xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
-        struct xen_mc_inject_v2    mc_inject_v2;
+        xen_mc_inject_v2_t         mc_inject_v2;
 #endif
     } u;
 };
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 20d4dccce6..1eb28dbe66 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -44,6 +44,7 @@
 ?	mcinfo_recovery			arch-x86/xen-mca.h
 !	mc_fetch			arch-x86/xen-mca.h
 ?	mc_info				arch-x86/xen-mca.h
+?	mc_inject_v2			arch-x86/xen-mca.h
 ?	mc_mceinject			arch-x86/xen-mca.h
 ?	mc_msrinject			arch-x86/xen-mca.h
 ?	mc_notifydomain			arch-x86/xen-mca.h
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index ca706ce353..065d3b1b6e 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -19,6 +19,7 @@ pats = [
  [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ],
  [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ],
  [ r"(^|[^\w])Xen_?", r"\1Compat_" ],
+ [ r"(^|[^\w])COMPAT_HANDLE_64\(", r"\1XEN_GUEST_HANDLE_64(" ],
  [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ]
 ];
 
diff --git a/xen/tools/compat-build-source.py b/xen/tools/compat-build-source.py
index fc10c7063f..2bcaf27d05 100755
--- a/xen/tools/compat-build-source.py
+++ b/xen/tools/compat-build-source.py
@@ -10,7 +10,7 @@ pats = [
  [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
  [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
  [ r"^\s*#\s*define\s+(u?int64)_aligned_t\s.*aligned.*", r"typedef \1_T __attribute__((aligned(4))) \1_compat_T;" ],
- [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
+ [ r"XEN_GUEST_HANDLE", r"COMPAT_HANDLE" ],
 ];
 
 xlatf = open('xlat.lst', 'r')
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxKk-00048b-Ir; Wed, 09 Sep 2020 10:28:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxKi-00047z-Vp
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:09 +0000
X-Inumbo-ID: 6d047550-80fa-498d-a96c-f01c24a4e60b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6d047550-80fa-498d-a96c-f01c24a4e60b;
 Wed, 09 Sep 2020 10:28:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=F85IfaHcy7Q+TLxmw2OhHVd6MUpRtOyzVrkaafCE0pA=; b=uR3lBYQMl27kUzPew8jaJN5q2u
 czhakJfySkkEM/pC+7YA1knUFsbXx3gwQKzrPRFAvY9JohvdgbV81pQC3bs+8kWuHfvaurpGXznpa
 zi/n7BiVYfaN6hrh+sV5EkO53YByI35C1TsHQudqaf6MhG6ReIQDoPcgtA4YUhLRyISs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKh-00056R-V7
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKh-00075W-Tz
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/mce: bring hypercall subop compat checking in sync
 again
Message-Id: <E1kFxKh-00075W-Tz@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7dcd33d562ee8a8177c843f42721d5345f796fe8
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:07:47 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:07:47 2020 +0200

    x86/mce: bring hypercall subop compat checking in sync again
    
    Use a typedef in struct xen_mc also for the two subops "manually"
    translated in the handler, just for consistency. No functional
    change.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/cpu/mcheck/mce.c         | 8 ++++----
 xen/include/public/arch-x86/xen-mca.h | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index 5ec16fab87..0e84368ae2 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1307,16 +1307,16 @@ CHECK_mcinfo_common;
 
 CHECK_FIELD_(struct, mc_fetch, flags);
 CHECK_FIELD_(struct, mc_fetch, fetch_id);
-# define CHECK_compat_mc_fetch       struct mc_fetch
+# define CHECK_mc_fetch              struct mc_fetch
 
 CHECK_FIELD_(struct, mc_physcpuinfo, ncpus);
-# define CHECK_compat_mc_physcpuinfo struct mc_physcpuinfo
+# define CHECK_mc_physcpuinfo        struct mc_physcpuinfo
 
 # define xen_ctl_bitmap              xenctl_bitmap
 
 CHECK_mc;
-# undef CHECK_compat_mc_fetch
-# undef CHECK_compat_mc_physcpuinfo
+# undef CHECK_mc_fetch
+# undef CHECK_mc_physcpuinfo
 # undef xen_ctl_bitmap
 
 # define xen_mc_info                 mc_info
diff --git a/xen/include/public/arch-x86/xen-mca.h b/xen/include/public/arch-x86/xen-mca.h
index 628b79e22a..d930c344c0 100644
--- a/xen/include/public/arch-x86/xen-mca.h
+++ b/xen/include/public/arch-x86/xen-mca.h
@@ -391,6 +391,7 @@ struct xen_mc_physcpuinfo {
     /* OUT */
     XEN_GUEST_HANDLE(xen_mc_logical_cpu_t) info;
 };
+typedef struct xen_mc_physcpuinfo xen_mc_physcpuinfo_t;
 
 #define XEN_MC_msrinject    4
 #define MC_MSRINJ_MAXMSRS       8
@@ -436,9 +437,9 @@ struct xen_mc {
     uint32_t cmd;
     uint32_t interface_version; /* XEN_MCA_INTERFACE_VERSION */
     union {
-        struct xen_mc_fetch        mc_fetch;
+        xen_mc_fetch_t             mc_fetch;
         xen_mc_notifydomain_t      mc_notifydomain;
-        struct xen_mc_physcpuinfo  mc_physcpuinfo;
+        xen_mc_physcpuinfo_t       mc_physcpuinfo;
         xen_mc_msrinject_t         mc_msrinject;
         xen_mc_mceinject_t         mc_mceinject;
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:20 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxKu-00049d-KZ; Wed, 09 Sep 2020 10:28:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxKt-00049R-8w
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:19 +0000
X-Inumbo-ID: c83faab1-d101-4d76-b2b6-8aa1afb70ebe
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c83faab1-d101-4d76-b2b6-8aa1afb70ebe;
 Wed, 09 Sep 2020 10:28:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=loc8c5bCa6dd2UNovpfjeIn8H22jUO3WfsCYK4omHHg=; b=TRZ4iZyZW3H6jVKpdzUc3YtzBb
 nbbIobfWk1ACj+f5FC2Daya7KV4kWym61/v6saHy21lrQd+PmIf2mM9VYrvEx2hnIfNE14bc5gS3f
 9xixK36ztTrmoVfgjpt/ky4I8kv9J7wrRy6TELJDT0To3VQ/vkfcmeHPUjoiN8FW26tM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKs-00056e-FZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:18 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxKs-00075y-1k
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/dmop: add compat struct checking for
 XEN_DMOP_map_mem_type_to_ioreq_server
Message-Id: <E1kFxKs-00075y-1k@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4d7bcd128f11dff49b0fd8eb367a3c546a8e38af
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:08:40 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:08:40 2020 +0200

    x86/dmop: add compat struct checking for XEN_DMOP_map_mem_type_to_ioreq_server
    
    This was forgotten when the subop was added.
    
    Also take the opportunity and move the dm_op_relocate_memory entry in
    xlat.lst to its designated place.
    
    No change in the resulting generated code.
    
    Fixes: ca2b511d3ff4 ("x86/ioreq server: add DMOP to map guest ram with p2m_ioreq_server to an ioreq server")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/hvm/dm.c | 1 +
 xen/include/xlat.lst  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 9930d68860..cf3787d9ff 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -731,6 +731,7 @@ CHECK_dm_op_modified_memory;
 CHECK_dm_op_set_mem_type;
 CHECK_dm_op_inject_event;
 CHECK_dm_op_inject_msi;
+CHECK_dm_op_map_mem_type_to_ioreq_server;
 CHECK_dm_op_remote_shutdown;
 CHECK_dm_op_relocate_memory;
 CHECK_dm_op_pin_memory_cacheattr;
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 1eb28dbe66..bab3a9bad1 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -86,15 +86,16 @@
 ?	grant_entry_v2			grant_table.h
 ?	gnttab_swap_grant_ref		grant_table.h
 !	dm_op_buf			hvm/dm_op.h
-?	dm_op_relocate_memory		hvm/dm_op.h
 ?	dm_op_create_ioreq_server	hvm/dm_op.h
 ?	dm_op_destroy_ioreq_server	hvm/dm_op.h
 ?	dm_op_get_ioreq_server_info	hvm/dm_op.h
 ?	dm_op_inject_event		hvm/dm_op.h
 ?	dm_op_inject_msi		hvm/dm_op.h
 ?	dm_op_ioreq_server_range	hvm/dm_op.h
+?	dm_op_map_mem_type_to_ioreq_server hvm/dm_op.h
 ?	dm_op_modified_memory		hvm/dm_op.h
 ?	dm_op_pin_memory_cacheattr	hvm/dm_op.h
+?	dm_op_relocate_memory		hvm/dm_op.h
 ?	dm_op_remote_shutdown		hvm/dm_op.h
 ?	dm_op_set_ioreq_server_state	hvm/dm_op.h
 ?	dm_op_set_isa_irq_level		hvm/dm_op.h
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxL4-0004AZ-MB; Wed, 09 Sep 2020 10:28:30 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxL3-0004AP-E1
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:29 +0000
X-Inumbo-ID: a5d75c05-954a-4669-b568-5713047e8c80
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a5d75c05-954a-4669-b568-5713047e8c80;
 Wed, 09 Sep 2020 10:28:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ASBcbhDgWaLkK/YF48Gc0HvoX/XiUkJkB2wgIStd7Wk=; b=xWIlDiCJOSM348mg/Tl5d8dg4D
 9CE3zHLBMR70SCSNJIoUcNKS/VMEz4leAb8iYUBGX20Xs+3qLV2y11Sd0AXkJAFIcDuOicXVBRKs+
 CTCFcWIqJUwf1JOVjerfW07mDznQyaMIqqBKfqajbc7IWhh1inGNlv9HuHQ62jiA1qwc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxL2-00056p-JH
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:28 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxL2-00076U-IU
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:28 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] evtchn: add compat struct checking for newer sub-ops
Message-Id: <E1kFxL2-00076U-IU@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a609b6577f7867db4be1470130b7b3c686398c4f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:11:35 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:11:35 2020 +0200

    evtchn: add compat struct checking for newer sub-ops
    
    Various additions to the interface did not get mirrored into the compat
    handling machinery. Luckily all additions were done in ways not making
    any form of translation necessary.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/common/compat/xlat.c | 16 ++++++++++++++++
 xen/include/xlat.lst     |  4 ++++
 2 files changed, 20 insertions(+)

diff --git a/xen/common/compat/xlat.c b/xen/common/compat/xlat.c
index ffc8f8f50e..e21f032413 100644
--- a/xen/common/compat/xlat.c
+++ b/xen/common/compat/xlat.c
@@ -54,6 +54,22 @@ CHECK_evtchn_op;
 #undef xen_evtchn_status
 #undef xen_evtchn_unmask
 
+#define xen_evtchn_expand_array evtchn_expand_array
+CHECK_evtchn_expand_array;
+#undef xen_evtchn_expand_array
+
+#define xen_evtchn_init_control evtchn_init_control
+CHECK_evtchn_init_control;
+#undef xen_evtchn_init_control
+
+#define xen_evtchn_reset evtchn_reset
+CHECK_evtchn_reset;
+#undef xen_evtchn_reset
+
+#define xen_evtchn_set_priority evtchn_set_priority
+CHECK_evtchn_set_priority;
+#undef xen_evtchn_set_priority
+
 #define xen_mmu_update mmu_update
 CHECK_mmu_update;
 #undef xen_mmu_update
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index bab3a9bad1..57a17a2b62 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -66,8 +66,12 @@
 ?	evtchn_bind_vcpu		event_channel.h
 ?	evtchn_bind_virq		event_channel.h
 ?	evtchn_close			event_channel.h
+?	evtchn_expand_array		event_channel.h
+?	evtchn_init_control		event_channel.h
 ?	evtchn_op			event_channel.h
+?	evtchn_reset			event_channel.h
 ?	evtchn_send			event_channel.h
+?	evtchn_set_priority		event_channel.h
 ?	evtchn_status			event_channel.h
 ?	evtchn_unmask			event_channel.h
 ?	gnttab_cache_flush		grant_table.h
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:40 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxLE-0004Bc-Nz; Wed, 09 Sep 2020 10:28:40 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxLD-0004BQ-Ka
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:39 +0000
X-Inumbo-ID: 3a2e2a24-0156-4c83-893b-9cb32562d6cd
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3a2e2a24-0156-4c83-893b-9cb32562d6cd;
 Wed, 09 Sep 2020 10:28:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=q/UIeF+A7q/G8PKznBYRfUAFKTsrhEbCjFplCIdtycA=; b=s7ZVecbCEBLmFkyaFGQhHNNLn8
 XdvsWghogMgRn+C0A8WI0aNDF9gQNGG6M/zWvnTsOJSlHlWAXMFQjt9I/4KyTOov9CbAEq0ZeVTFs
 d6zmFQeKLY0Podb0r3UlTMnJg1w4txfhg2cfUzK+i0+XoKI6fC9NQ4G7UnghnEr3V6Yo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLC-00056x-NS
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:38 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLC-00076u-M8
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:38 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: generalize padding field handling
Message-Id: <E1kFxLC-00076u-M8@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 696c273f3d9a169911308fb7e0a702a3eb6a150d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:13:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:13:01 2020 +0200

    x86: generalize padding field handling
    
    The original intention was to ignore padding fields, but the pattern
    matched only ones whose names started with an underscore. Also match
    fields whose names are in line with the C spec by not having a leading
    underscore. (Note that the leading ^ in the sed regexps was pointless
    and hence get dropped.)
    
    This requires adjusting some vNUMA macros, to avoid triggering
    "enumeration value ... not handled in switch" warnings, which - due to
    -Werror - would cause the build to fail. (I have to admit that I find
    these padding fields odd, when translation of the containing structure
    is needed anyway.)
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/common/compat/memory.c | 3 +++
 xen/tools/get-fields.sh    | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 3851f756c7..215b8f52d6 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -354,10 +354,13 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
                 return -EFAULT;
 
 #define XLAT_vnuma_topology_info_HNDL_vdistance_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vdistance_pad:                \
             guest_from_compat_handle((_d_)->vdistance.h, (_s_)->vdistance.h)
 #define XLAT_vnuma_topology_info_HNDL_vcpu_to_vnode_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vcpu_to_vnode_pad:            \
             guest_from_compat_handle((_d_)->vcpu_to_vnode.h, (_s_)->vcpu_to_vnode.h)
 #define XLAT_vnuma_topology_info_HNDL_vmemrange_h(_d_, _s_)		\
+            case XLAT_vnuma_topology_info_vmemrange_pad:                \
             guest_from_compat_handle((_d_)->vmemrange.h, (_s_)->vmemrange.h)
 
             XLAT_vnuma_topology_info(nat.vnuma, &cmp.vnuma);
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 002db2093f..753e37eb2e 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -218,7 +218,7 @@ for line in sys.stdin.readlines():
 				fi
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 				then
 					if [ $kind = union ]
 					then
@@ -347,7 +347,7 @@ build_body ()
 			fi
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 			then
 				if [ -z "$array" -a -z "$array_type" ]
 				then
@@ -437,7 +437,7 @@ check_field ()
 				id=$token
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 				then
 					check_field $1 $2 $3.$id "$fields"
 					test "$token" != ";" || fields= id=
@@ -491,7 +491,7 @@ build_check ()
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
 			then
 				check_field $kind $1 $id "$fields"
 				test "$token" != ";" || fields= id=
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:28:50 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:28:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxLO-0004Cd-Pd; Wed, 09 Sep 2020 10:28:50 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxLN-0004CS-N8
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:49 +0000
X-Inumbo-ID: aeebec0f-b4b9-4297-9557-511018a46e8d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id aeebec0f-b4b9-4297-9557-511018a46e8d;
 Wed, 09 Sep 2020 10:28:49 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Iu6wg8PW6bPN3rUUsGosiWiPKyQOHDK/dRoUge5lRpo=; b=Fr9bKuTOoD/8QIy393vWBx/0/O
 3xalEoCME3jeVB93odnXBCyBUv4dSCQRCT1qtA81MENbIaeM6zzYy8ikvlaMWJNQe/XpYMx7HQmTi
 4MlE0FxPEtUraR8y++NZ8uJE/DBSMpebtk+BdG71k0zwMNUM2E6dj3cwOYwWM+E8vVFU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLM-000575-Rd
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:48 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLM-00077T-QV
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:48 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] flask: drop dead compat translation code
Message-Id: <E1kFxLM-00077T-QV@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:48 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7dcf89d9ec96254f69744ab6d91e8af13f4cda83
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:14:28 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:14:28 2020 +0200

    flask: drop dead compat translation code
    
    Translation macros aren't used (and hence needed) at all (or else a
    devicetree_label entry would have been missing), and userlist has been
    removed quite some time ago.
    
    No functional change.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/include/xlat.lst     | 3 ---
 xen/xsm/flask/flask_op.c | 2 --
 2 files changed, 5 deletions(-)

diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 57a17a2b62..398993d5f4 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -171,14 +171,11 @@
 ?	xenoprof_init			xenoprof.h
 ?	xenoprof_passive		xenoprof.h
 ?	flask_access			xsm/flask_op.h
-!	flask_boolean			xsm/flask_op.h
 ?	flask_cache_stats		xsm/flask_op.h
 ?	flask_hash_stats		xsm/flask_op.h
-!	flask_load			xsm/flask_op.h
 ?	flask_ocontext			xsm/flask_op.h
 ?	flask_peersid			xsm/flask_op.h
 ?	flask_relabel			xsm/flask_op.h
 ?	flask_setavc_threshold		xsm/flask_op.h
 ?	flask_setenforce		xsm/flask_op.h
-!	flask_sid_context		xsm/flask_op.h
 ?	flask_transition		xsm/flask_op.h
diff --git a/xen/xsm/flask/flask_op.c b/xen/xsm/flask/flask_op.c
index a5f2b104e2..01e52138a1 100644
--- a/xen/xsm/flask/flask_op.c
+++ b/xen/xsm/flask/flask_op.c
@@ -790,8 +790,6 @@ CHECK_flask_transition;
 #define xen_flask_load compat_flask_load
 #define flask_security_load compat_security_load
 
-#define xen_flask_userlist compat_flask_userlist
-
 #define xen_flask_sid_context compat_flask_sid_context
 #define flask_security_context compat_security_context
 #define flask_security_sid compat_security_sid
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxLZ-0004E2-Sv; Wed, 09 Sep 2020 10:29:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxLX-0004Dr-VJ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:59 +0000
X-Inumbo-ID: c3ad0eb0-8d8d-4505-aafe-50a319d5778a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c3ad0eb0-8d8d-4505-aafe-50a319d5778a;
 Wed, 09 Sep 2020 10:28:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/peEKaQ1AL4/KcTWXcX4+X0edsGjb9khh565Kcauy/8=; b=xgcRzM6S92SVkLhrXd+fE+IhR5
 G8NvpzP/XNTnPWxmWD5sUpu1H/d5ov5qpDe7sBqzhdPsiSpGC2f//y98hLrLDBtGZdsLxdDk6rxVy
 jcyVf7hn3Wpv+0fjEWh662G6ngJZcen3dXfoMaXWiOYY/10E1EtvjuIjOJGQur0d7e6U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLW-00057e-WF
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:59 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLW-00077t-UW
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:28:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: only generate compat headers actually needed
Message-Id: <E1kFxLW-00077t-UW@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:28:58 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2c8fabb2232d34d6d20a9ce6989e2e6cbee07d52
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 4 11:15:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 4 11:15:21 2020 +0200

    x86: only generate compat headers actually needed
    
    As was already the case for XSM/Flask, avoid generating compat headers
    when they're not going to be needed. To address resulting build issues
    - move compat/hvm/dm_op.h inclusion to the only source file needing it,
    - add a little bit of #ifdef-ary.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/hvm/dm.c       |  2 ++
 xen/common/compat/domain.c  |  9 ++++++++-
 xen/include/Makefile        | 24 +++++++++++++-----------
 xen/include/xen/hypercall.h |  2 --
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index cf3787d9ff..71f5ca4941 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -718,6 +718,8 @@ static int dm_op(const struct dmop_args *op_args)
     return rc;
 }
 
+#include <compat/hvm/dm_op.h>
+
 CHECK_dm_op_create_ioreq_server;
 CHECK_dm_op_get_ioreq_server_info;
 CHECK_dm_op_ioreq_server_range;
diff --git a/xen/common/compat/domain.c b/xen/common/compat/domain.c
index 11c6afc463..98b8c15cea 100644
--- a/xen/common/compat/domain.c
+++ b/xen/common/compat/domain.c
@@ -11,7 +11,6 @@ EMIT_FILE;
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <compat/vcpu.h>
-#include <compat/hvm/hvm_vcpu.h>
 
 #define xen_vcpu_set_periodic_timer vcpu_set_periodic_timer
 CHECK_vcpu_set_periodic_timer;
@@ -25,6 +24,10 @@ CHECK_SIZE_(struct, vcpu_info);
 CHECK_vcpu_register_vcpu_info;
 #undef xen_vcpu_register_vcpu_info
 
+#ifdef CONFIG_HVM
+
+#include <compat/hvm/hvm_vcpu.h>
+
 #define xen_vcpu_hvm_context vcpu_hvm_context
 #define xen_vcpu_hvm_x86_32 vcpu_hvm_x86_32
 #define xen_vcpu_hvm_x86_64 vcpu_hvm_x86_64
@@ -33,6 +36,8 @@ CHECK_vcpu_hvm_context;
 #undef xen_vcpu_hvm_x86_32
 #undef xen_vcpu_hvm_context
 
+#endif
+
 int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d = current->domain;
@@ -49,6 +54,7 @@ int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) ar
         if ( v->vcpu_info == &dummy_vcpu_info )
             return -EINVAL;
 
+#ifdef CONFIG_HVM
         if ( is_hvm_vcpu(v) )
         {
             struct vcpu_hvm_context ctxt;
@@ -61,6 +67,7 @@ int compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) ar
             domain_unlock(d);
         }
         else
+#endif
         {
             struct compat_vcpu_guest_context *ctxt;
 
diff --git a/xen/include/Makefile b/xen/include/Makefile
index 0be5540886..5c2f57a0f6 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -3,32 +3,34 @@ ifneq ($(CONFIG_COMPAT),)
 compat-arch-$(CONFIG_X86) := x86_32
 
 headers-y := \
-    compat/argo.h \
-    compat/callback.h \
+    compat/arch-$(compat-arch-y).h \
     compat/elfnote.h \
     compat/event_channel.h \
     compat/features.h \
-    compat/grant_table.h \
-    compat/hypfs.h \
-    compat/kexec.h \
     compat/memory.h \
     compat/nmi.h \
     compat/physdev.h \
     compat/platform.h \
+    compat/pmu.h \
     compat/sched.h \
-    compat/trace.h \
     compat/vcpu.h \
     compat/version.h \
     compat/xen.h \
-    compat/xenoprof.h
+    compat/xlat.h
 headers-$(CONFIG_X86)     += compat/arch-x86/pmu.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-mca.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
-headers-$(CONFIG_X86)     += compat/hvm/dm_op.h
-headers-$(CONFIG_X86)     += compat/hvm/hvm_op.h
-headers-$(CONFIG_X86)     += compat/hvm/hvm_vcpu.h
-headers-y                 += compat/arch-$(compat-arch-y).h compat/pmu.h compat/xlat.h
+headers-$(CONFIG_ARGO)    += compat/argo.h
+headers-$(CONFIG_PV)      += compat/callback.h
+headers-$(CONFIG_GRANT_TABLE) += compat/grant_table.h
+headers-$(CONFIG_HVM)     += compat/hvm/dm_op.h
+headers-$(CONFIG_HVM)     += compat/hvm/hvm_op.h
+headers-$(CONFIG_HVM)     += compat/hvm/hvm_vcpu.h
+headers-$(CONFIG_HYPFS)   += compat/hypfs.h
+headers-$(CONFIG_KEXEC)   += compat/kexec.h
+headers-$(CONFIG_TRACEBUFFER) += compat/trace.h
+headers-$(CONFIG_XENOPROF) += compat/xenoprof.h
 headers-$(CONFIG_XSM_FLASK) += compat/xsm/flask_op.h
 
 cppflags-y                := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS
diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h
index 655acc7f47..34b7f1fed6 100644
--- a/xen/include/xen/hypercall.h
+++ b/xen/include/xen/hypercall.h
@@ -216,8 +216,6 @@ extern long compat_argo_op(
     unsigned long arg4);
 #endif
 
-#include <compat/hvm/dm_op.h>
-
 extern int
 compat_dm_op(
     domid_t domid,
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxLi-0004FZ-VC; Wed, 09 Sep 2020 10:29:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxLh-0004FR-Qj
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:09 +0000
X-Inumbo-ID: aed0c2bd-a831-47bd-a20d-727d8f4b34fd
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id aed0c2bd-a831-47bd-a20d-727d8f4b34fd;
 Wed, 09 Sep 2020 10:29:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=C1Q3kgpjdX+CV01SDqF3WRo3kQe6VmFYT/6KmwBCWzM=; b=NR1gPVAMTg6mAFURobGocnrLfM
 /+TEhm0YqlfQwbvFbDOcQQMMVBo1xWlcP+EJiqsadvBhtLObobB42vrqHG4FX+4u44mxXnuseD3Rc
 O6QTs6UKt3AzfMW+Cvyj1A2/A8kTWZmseP5EMGMjWhWXSL7i/knrspWFRekfmF41qq3o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLh-00057z-3W
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:09 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLh-00078S-2l
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:09 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] fix build with make 3.81
Message-Id: <E1kFxLh-00078S-2l@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:09 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fc4b1cbd8d8d22c80dd8f2fc744287ab7c89c912
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Tue Sep 1 13:58:16 2020 +0200
Commit:     Ian Jackson <ian.jackson@eu.citrix.com>
CommitDate: Fri Sep 4 12:15:54 2020 +0100

    fix build with make 3.81
    
    make 3.81 doesn't support multiline variables defined with
    
     define var =
     ...
     endef
    
    Dropping the "=" in the first line will fix the issue.
    
    Fixes: ded08cdfa72bb ("tools: generate most contents of library make variables")
    Fixes: ddb2934a914df ("stubdom: add correct dependencies for Xen libraries")
    Reported-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 stubdom/Makefile | 2 +-
 tools/Rules.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index 4fd86dd44b..98eba8efe3 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -25,7 +25,7 @@ endif
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-define LIB_deps =
+define LIB_deps
  LIBDEPS_$(1) = $$(foreach use,$$(USELIBS_$(1)),libxen$$(use))
 endef
 $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_deps,$(lib))))
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 7e019a8a65..385807a71c 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -94,7 +94,7 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-define LIB_defs =
+define LIB_defs
  XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
  CFLAGS_libxen$(1) = -I$$(XEN_libxen$(1))/include $$(CFLAGS_xeninclude)
  SHDEPS_libxen$(1) = $$(foreach use,$$(USELIBS_$(1)),$$(SHLIB_libxen$$(use)))
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxLv-0004Go-0d; Wed, 09 Sep 2020 10:29:23 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxLt-0004Gd-1k
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:21 +0000
X-Inumbo-ID: 1c12125f-4442-4f7c-b598-25364577a44f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1c12125f-4442-4f7c-b598-25364577a44f;
 Wed, 09 Sep 2020 10:29:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=t/ls829op7mlZF2gPmdxflKpP3a5VB7+bKoWYmnGlOA=; b=GzZWcCmW2YawB6lYYSpF7+Hide
 FJS9Z8diUgciJA8XOnu0ffCUmOv0dVv96r2H9tKzUeL1Dfcmg4dI2mweoPS4lXJVpca1SsSu+g4Rx
 fuPzCa81ttzTmoncgcdtv04zx0w1VXZ2DmcpgMDJzOsjmk1w6sP4+Zn+T3KlVY+U/Q1M=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLr-000587-86
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxLr-00078u-6N
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] Revert "libxl: Generate golang bindings in libxl
 Makefile"
Message-Id: <E1kFxLr-00078u-6N@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ac7a21cf5c125810ee0193338a0f710cba0ab079
Author:     George Dunlap <george.dunlap@citrix.com>
AuthorDate: Fri Aug 28 15:33:37 2020 +0100
Commit:     George Dunlap <george.dunlap@citrix.com>
CommitDate: Fri Sep 4 15:38:56 2020 +0100

    Revert "libxl: Generate golang bindings in libxl Makefile"
    
    This reverts commit 60db5da62ac051aab0b217fa2d96acca1cd3ca3e.
    
    This is in preparation for the planned move to hosting the xenlight
    package in a separate repo.
    
    This also fixes a regression when building with a read-only source and
    an out-of-tree build.
    
    Signed-off-by: George Dunlap <george.dunlap@citrix.com>
    Acked-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/golang/xenlight/Makefile |  7 -------
 tools/libxl/Makefile           | 17 +----------------
 2 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
index a83fff7573..b17095e64b 100644
--- a/tools/golang/xenlight/Makefile
+++ b/tools/golang/xenlight/Makefile
@@ -15,13 +15,6 @@ all: build
 
 GOXL_GEN_FILES = types.gen.go helpers.gen.go
 
-# NOTE: This target is called from libxl/Makefile:all.  Since that
-# target must finish before golang/Makefile is called, this is
-# currently safe.  It must not be called from anywhere else in the
-# Makefile system without careful thought about races with
-# xenlight/Makefile:all
-idl-gen: $(GOXL_GEN_FILES)
-
 %.gen.go: gengotypes.py $(LIBXL_SRC_DIR)/libxl_types.idl $(LIBXL_SRC_DIR)/idl.py
 	XEN_ROOT=$(XEN_ROOT) $(PYTHON) gengotypes.py $(LIBXL_SRC_DIR)/libxl_types.idl
 
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 0e8dfc6193..c26b3a8093 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -219,7 +219,7 @@ testidl.c: libxl_types.idl gentest.py libxl.h $(AUTOINCS)
 .PHONY: all
 all: $(CLIENTS) $(TEST_PROGS) $(PKG_CONFIG) $(PKG_CONFIG_LOCAL) \
 		libxenlight.so libxenlight.a libxlutil.so libxlutil.a \
-	$(AUTOSRCS) $(AUTOINCS) idl-external
+	$(AUTOSRCS) $(AUTOINCS)
 
 $(LIBXL_OBJS) $(LIBXLU_OBJS) $(SAVE_HELPER_OBJS) \
 		$(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): \
@@ -275,21 +275,6 @@ _libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: libxl_
 	$(call move-if-changed,__libxl_type$(stem)_json.h,_libxl_type$(stem)_json.h)
 	$(call move-if-changed,__libxl_type$(stem).c,_libxl_type$(stem).c)
 
-# NOTE: This is safe to do at the moment because idl-external and
-# idl-gen are only called from libxl/Makefile:all, which must return
-# before golang/Makefile is callid.  idl-external and idl-gen must
-# never be called from another part of the make system without careful thought
-# about races with tools/golang/xenlight/Makefile:all
-.PHONY: idl-external
-idl-external:
-	$(MAKE) -C $(XEN_ROOT)/tools/golang/xenlight idl-gen
-
-LIBXL_IDLGEN_FILES = _libxl_types.h _libxl_types_json.h _libxl_types_private.h _libxl_types.c \
-	_libxl_types_internal.h _libxl_types_internal_json.h _libxl_types_internal_private.h _libxl_types_internal.c
-
-
-idl-gen: $(LIBXL_GEN_FILES) idl-external
-
 libxenlight.so: libxenlight.so.$(MAJOR)
 	$(SYMLINK_SHLIB) $< $@
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxM4-0004Hc-2G; Wed, 09 Sep 2020 10:29:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxM2-0004HT-Ke
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:30 +0000
X-Inumbo-ID: af638248-5631-41d4-a063-a196a652e111
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id af638248-5631-41d4-a063-a196a652e111;
 Wed, 09 Sep 2020 10:29:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tXbbAgXuHGDopB8qVkJEugPotexddVDRmOS9ehUKm/w=; b=v5o81RSv9svPVl8osbzRN6Xe79
 hYQ4YStLdTSj4WDz7NwsQqdvXaiOnyUcIK76n8y7bLUteFv+RepXLtKXNyWxTv/EfeJ8r8ho1Djft
 Epl3gNdoVQd0NRAa1h+Iork0aZQ6V1EVCeuaJrVOxH2lI+Q2UNTbx++CgywCh/QZvR9Y=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxM1-00058F-Ba
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:29 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxM1-00079K-An
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] minios: Revert recent change and revert to working minios
Message-Id: <E1kFxM1-00079K-An@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 82c3d15c903aa434473dfdb570096ae5db809b94
Author:     Ian Jackson <iwj@xenproject.org>
AuthorDate: Fri Sep 4 16:42:01 2020 +0100
Commit:     Ian Jackson <iwj@xenproject.org>
CommitDate: Fri Sep 4 16:50:55 2020 +0100

    minios: Revert recent change and revert to working minios
    
    Currently, xen.git#staging does not build in many environments because
    of issues with minios master.  This regression was introduced in an
    uncontrolled manner by an update to mini-os.git#master.
    
    This is because in e013e8514389 "config: use mini-os master for
    unstable" we switched to tracking minios master in an uncontrolled
    manner.  At the time we thought it was unlikely that minios changes
    would break the Xen build.  This turns out to have been overly
    optimistic.
    
    Xen currently uses unstable internal interfaces of minios.  Until this
    can be sorted out, internal changes to minios can require lockstep
    changes in Xen.
    
    All this means that "config: use mini-os master for unstable" was
    wrong.  We should undo it.  Instead, we go back to the previous
    situation: xen.git names a specific minios commit.
    
    This scheme is the model used for qemu-xen-traditional.
    
    That nailed commit must be updated manually, to have xen.git pick up
    changes from minios.  If the minios changes require changes in xen.git
    too, to avoid breaking the Xen build, they can be made freely in
    minios without adverse consequences.  When the minios commitid is
    updated in xen.git, the corresponding changes to the actual source
    files in xen.git should be bundled together.
    
    For example, when minios is fixed, 8d990807ec2c "stubdom/grub: update
    init_netfront() call for mini-os" will need to be reapplied, folded
    into the same commit as updates MINIOS_UPSTREAM_REVISION.  For now
    that commit must be reverted as we are going back to a previous
    version of minios.
    
    This reverts commit 8d990807ec2cde3061222a5ed2df62aba78bace9.
    This reverts commit e013e8514389b739153016349e49f5a78e34ddf0.
    
    CC: Jan Beulich <jbeulich@suse.com>
    CC: Costin Lupu <costin.lupu@cs.pub.ro>
    CC: Wei Liu <wl@xen.org>
    CC: Samuel Thibault <samuel.thibault@ens-lyon.org>
    Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 Config.mk              | 2 +-
 stubdom/grub/mini-os.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Config.mk b/Config.mk
index 8269503f73..db434ee2c6 100644
--- a/Config.mk
+++ b/Config.mk
@@ -246,7 +246,7 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= a3741780fe3535e19e02efa869a7cac481891129
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= master
+MINIOS_UPSTREAM_REVISION ?= 0b4b7897e08b967a09bed2028a79fabff82342dd
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.14.0
 
diff --git a/stubdom/grub/mini-os.c b/stubdom/grub/mini-os.c
index b33dbf02fb..4fc052a255 100644
--- a/stubdom/grub/mini-os.c
+++ b/stubdom/grub/mini-os.c
@@ -291,6 +291,8 @@ struct netfront_dev *net_dev;
 int
 minios_probe (struct nic *nic)
 {
+    char *ip;
+
     if (net_dev)
         return 1;
 
@@ -298,7 +300,7 @@ minios_probe (struct nic *nic)
     grub_memset ((char *) arptable, 0,
                  MAX_ARP * sizeof (struct arptable_t));
 
-    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, NULL, NULL, NULL);
+    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, &ip);
     if (!net_dev)
         return 0;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:42 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxME-0004Ii-47; Wed, 09 Sep 2020 10:29:42 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxMC-0004IW-AY
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:40 +0000
X-Inumbo-ID: 574fbc47-4b6f-4a44-8054-41a18b8c696f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 574fbc47-4b6f-4a44-8054-41a18b8c696f;
 Wed, 09 Sep 2020 10:29:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=zD5B2REIPfR+NtM3hGIiIk3jJ3K++Qc3jcWMWg+mg6I=; b=IZRUJbUCxDAvv+QdjzHNg5l8DB
 H9JDDfFOIrS8NY2Xxa3ko9yMSQ6c/2fU0YajqXwGEYjZpZhH/xYIXacbTlq9sHI6clsi/jNJO9Ajd
 tlVJHfw83mLh9meTSHVht/Sud+PqxC+y6x2avmoVEP33qZBAL4/IPGnN/DGU1T5i4WPE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMB-00058L-Fx
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:39 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMB-00079q-EF
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:39 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/arm: Update silicon-errata.txt with the Neovers AT
 erratum
Message-Id: <E1kFxMB-00079q-EF@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:39 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1814a626fb5811184eda64fe22f0055df4600211
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:01:40 2020 +0100

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:29:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:29:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxMO-0004Js-5p; Wed, 09 Sep 2020 10:29:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxMM-0004JY-EH
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:50 +0000
X-Inumbo-ID: 5a4e287d-1cf2-4d7e-853c-3cae77b0372d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5a4e287d-1cf2-4d7e-853c-3cae77b0372d;
 Wed, 09 Sep 2020 10:29:49 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=+pLbiev1YjWUt9l76PnRC5VKezD2OUd7C4c8XuwDwO8=; b=JICw8RMBV4H1Jtx9vHwcsu9qkI
 x0eiDz0k8HzapO0LvH1gWTLU5z2CJcgInRbvgBroSfxt3G5p2llXcpf8BZwyvl9+/jjJH48tVSMXt
 c4Zr6dVCpxcKVc3s+QnwpKVA+6aLWQeCguL6cq/XapyL3pldNETncvg9B3XbTt6fUXSU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxML-00058S-KX
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:49 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxML-0007AL-Io
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:49 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/arm: Missing N1/A76/A75 FP registers in vCPU context
 switch
Message-Id: <E1kFxML-0007AL-Io@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:49 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 968bb86d04913f52d7678a842474f2a674a8b23e
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:02:35 2020 +0100

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 674beb0353..10878ead8a 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxMX-0004Kz-98; Wed, 09 Sep 2020 10:30:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxMW-0004Kq-JJ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:00 +0000
X-Inumbo-ID: d771a3d3-fe97-4009-8fcf-d64b7482b616
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d771a3d3-fe97-4009-8fcf-d64b7482b616;
 Wed, 09 Sep 2020 10:29:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eQ9qrjnvHrgHH8cfLyEASVs6sjWMM7Na//DCzuPAoR8=; b=bgQDO2GhDl2Q3wOqU0GjF5wbA9
 /Dznyqzlv5FTVJV5ucR15Gq4rPdsVWRaQOE1eREtUZ1igBA+N72tjru/beuw1CeiyznGfXJgbxNOO
 eqoVMqooNyiuaoCLWgbCWjoAqB2kz8xRID1QUAHQNUtRc65SlF5wHGXmEloxgI8oLd5o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMV-00059K-O3
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:59 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMV-0007B3-NH
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:29:59 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/arm: Throw messages for unknown FP/SIMD implement ID
Message-Id: <E1kFxMV-0007B3-NH@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:29:59 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f4c1a541fa351e4f613471bbf397931f9e1ddd27
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:04 2020 +0000
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 4 18:02:35 2020 +0100

    xen/arm: Throw messages for unknown FP/SIMD implement ID
    
    Arm ID_AA64PFR0_EL1 register provides two fields to describe CPU
    FP/SIMD implementations. Currently, we exactly know the meaning of
    0x0, 0x1 and 0xf of these fields. Xen treats value < 8 as FP/SIMD
    features presented. If there is a value 0x2 bumped in the future,
    Xen behaviors for value <= 0x1 can also take effect. But what Xen
    done for value <= 0x1 may not always cover new value 0x2 required.
    We throw these messages to break the silence when Xen detected
    unknown FP/SIMD IDs to notice user to check.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/setup.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 7968cee47d..f16b33fa87 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -133,6 +133,18 @@ static void __init processor_id(void)
            cpu_has_simd ? " AdvancedSIMD" : "",
            cpu_has_gicv3 ? " GICv3-SysReg" : "");
 
+    /* Warn user if we find unknown floating-point features */
+    if ( cpu_has_fp && (boot_cpu_feature64(fp) >= 2) )
+        printk(XENLOG_WARNING "WARNING: Unknown Floating-point ID:%d, "
+               "this may result in corruption on the platform\n",
+               boot_cpu_feature64(fp));
+
+    /* Warn user if we find unknown AdvancedSIMD features */
+    if ( cpu_has_simd && (boot_cpu_feature64(simd) >= 2) )
+        printk(XENLOG_WARNING "WARNING: Unknown AdvancedSIMD ID:%d, "
+               "this may result in corruption on the platform\n",
+               boot_cpu_feature64(simd));
+
     printk("  Debug Features: %016"PRIx64" %016"PRIx64"\n",
            boot_cpu_data.dbg64.bits[0], boot_cpu_data.dbg64.bits[1]);
     printk("  Auxiliary Features: %016"PRIx64" %016"PRIx64"\n",
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxMh-000514-B4; Wed, 09 Sep 2020 10:30:11 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxMg-00050v-Nn
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:10 +0000
X-Inumbo-ID: 27b4c064-8fc2-4d9f-80ab-e7a64f02a31d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 27b4c064-8fc2-4d9f-80ab-e7a64f02a31d;
 Wed, 09 Sep 2020 10:30:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7n3KnaIZlCoGQ1s82CaQCf6bZFOApa9RYHcygeDHqgM=; b=1qpJgp5LKB+hgDfxoadzFiVsgG
 B+C0FLI08ZBOa0ueHL3JiZ7D9/XEzDc+Gp6bIKzeO+eTfFx+TFMKCOBkGwPguLb5gh9h/PdOZKosQ
 avbIGdKNir/a3sgHo3HlzMnN1EL8shOzy8xZ0j+xOKk6poetuQJrwLdUzyuav7IxQiNc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMf-00059r-Rs
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:09 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMf-0007Bj-Qu
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:09 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] Revert "x86: generalize padding field handling"
Message-Id: <E1kFxMf-0007Bj-Qu@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:30:09 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e52716154da04967f9b9d7cf9a1655ea4bcd9e93
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 7 10:34:03 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:34:03 2020 +0200

    Revert "x86: generalize padding field handling"
    
    This reverts commit 696c273f3d9a169911308fb7e0a702a3eb6a150d.
    
    I was based on the flase assumption that padding fields need no
    copying: If native code checks such fields, they of course need
    copying in. And if the ABI specifies them to be zero on
    completion, we also need to copy them out.
---
 xen/common/compat/memory.c | 3 ---
 xen/tools/get-fields.sh    | 8 ++++----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 215b8f52d6..3851f756c7 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -354,13 +354,10 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
                 return -EFAULT;
 
 #define XLAT_vnuma_topology_info_HNDL_vdistance_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vdistance_pad:                \
             guest_from_compat_handle((_d_)->vdistance.h, (_s_)->vdistance.h)
 #define XLAT_vnuma_topology_info_HNDL_vcpu_to_vnode_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vcpu_to_vnode_pad:            \
             guest_from_compat_handle((_d_)->vcpu_to_vnode.h, (_s_)->vcpu_to_vnode.h)
 #define XLAT_vnuma_topology_info_HNDL_vmemrange_h(_d_, _s_)		\
-            case XLAT_vnuma_topology_info_vmemrange_pad:                \
             guest_from_compat_handle((_d_)->vmemrange.h, (_s_)->vmemrange.h)
 
             XLAT_vnuma_topology_info(nat.vnuma, &cmp.vnuma);
diff --git a/xen/tools/get-fields.sh b/xen/tools/get-fields.sh
index 753e37eb2e..002db2093f 100644
--- a/xen/tools/get-fields.sh
+++ b/xen/tools/get-fields.sh
@@ -218,7 +218,7 @@ for line in sys.stdin.readlines():
 				fi
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					if [ $kind = union ]
 					then
@@ -347,7 +347,7 @@ build_body ()
 			fi
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				if [ -z "$array" -a -z "$array_type" ]
 				then
@@ -437,7 +437,7 @@ check_field ()
 				id=$token
 				;;
 			[\,\;])
-				if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 				then
 					check_field $1 $2 $3.$id "$fields"
 					test "$token" != ";" || fields= id=
@@ -491,7 +491,7 @@ build_check ()
 			test $level != 2 -o $arrlvl != 1 || id=$token
 			;;
 		[\,\;])
-			if [ $level = 2 -a -n "$(echo $id | $SED 's,_\?pad[[:digit:]]*,,')" ]
+			if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
 			then
 				check_field $kind $1 $id "$fields"
 				test "$token" != ";" || fields= id=
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxMt-000527-Co; Wed, 09 Sep 2020 10:30:23 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxMs-000521-Lp
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:22 +0000
X-Inumbo-ID: 1f20db74-543e-4d61-b55b-3bcd2ac1c25a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1f20db74-543e-4d61-b55b-3bcd2ac1c25a;
 Wed, 09 Sep 2020 10:30:20 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=yRJ2Kf0UR3nJEZ5mLDayjJt7/oUwksOgnoHGsdlACVo=; b=ZJTwWiNuJPRExw0BaNtmL/mtYy
 Z/KD1kdj8X3U0z4GqSOWhhRgZXVZpYgrB24zVBod5HhDvGhMv+T5FashY7//9CwqumeC8rma3+ZQY
 FYlZUR/m+TmD/UW4e5SVkoGh9SpZtWq3dK8YDvTjOPRk4vAUvMk7WTxodAR/ibhyW65o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMp-0005A5-Vo
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxMp-0007CD-Ux
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/vmx: handle writes to MISC_ENABLE MSR
Message-Id: <E1kFxMp-0007CD-Ux@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:30:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2454fa428d0b0d1705b8395db7674426ebf182aa
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 10:37:23 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:37:23 2020 +0200

    x86/vmx: handle writes to MISC_ENABLE MSR
    
    Such handling consist in checking that no bits have been changed from
    the read value, if that's the case silently drop the write, otherwise
    inject a fault.
    
    At least Windows guests will expect to write to the MISC_ENABLE MSR
    with the same value that's been read from it.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index a0d58ffbe2..c4b40bf3cb 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3163,7 +3163,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
 
     switch ( msr )
     {
-        uint64_t rsvd;
+        uint64_t rsvd, tmp;
 
     case MSR_IA32_SYSENTER_CS:
         __vmwrite(GUEST_SYSENTER_CS, msr_content);
@@ -3301,6 +3301,17 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         /* None of these MSRs are writeable. */
         goto gp_fault;
 
+    case MSR_IA32_MISC_ENABLE:
+        /*
+         * Silently drop writes that don't change the reported value: At least
+         * some Windows guests will expect to be able to write to MISC_ENABLE
+         * with the same value that's been read from it.
+         */
+        if ( vmx_msr_read_intercept(msr, &tmp) != X86EMUL_OKAY ||
+             tmp != msr_content )
+            goto gp_fault;
+        break;
+
     case MSR_P6_PERFCTR(0)...MSR_P6_PERFCTR(7):
     case MSR_P6_EVNTSEL(0)...MSR_P6_EVNTSEL(7):
     case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:31 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxN1-00052t-Ec; Wed, 09 Sep 2020 10:30:31 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxN0-00052o-Rz
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:30 +0000
X-Inumbo-ID: a648b639-5fb9-4ec9-ad75-d88f0e1388d7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a648b639-5fb9-4ec9-ad75-d88f0e1388d7;
 Wed, 09 Sep 2020 10:30:30 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=icFFCan8JJ/YPQ12R+yszjqUP6KwfWtbH7KpXer9Lpg=; b=PgOCVFQwsQGBIxoduGRSCuyYqv
 qrY99SVOC54fWS+LC+5gKEBU0L6DWdYFmdmJzo2d3vnt1AVlmudjOdvo/ofwnRZs5q92PA/zlFoUx
 TT7LcAguD4KBcbtTk3EKvBb3BCcDOeUdU0byUdogN8c2E3QilqUf6QSfqlSkufVN5zmY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxN0-0005AB-3U
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:30 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxN0-0007Cb-2Z
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:30 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/svm: silently drop writes to SYSCFG and related MSRs
Message-Id: <E1kFxN0-0007Cb-2Z@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:30:30 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f5b44269fc734474f3272a22ba9d426d234ed460
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 10:38:00 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 7 10:38:00 2020 +0200

    x86/svm: silently drop writes to SYSCFG and related MSRs
    
    The SYSCFG, TOP_MEM1 and TOP_MEM2 MSRs are currently exposed to guests
    and writes are silently discarded. Make this explicit in the SVM code
    now, and just return default constant values when attempting to read
    any of the MSRs, while continuing to silently drop writes.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index ca3bbfcbb3..af584ff5d1 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1917,6 +1917,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
             goto gpf;
         break;
 
+    case MSR_K8_SYSCFG:
+    case MSR_K8_TOP_MEM1:
+    case MSR_K8_TOP_MEM2:
     case MSR_K8_VM_CR:
         *msr_content = 0;
         break;
@@ -2094,6 +2097,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
             goto gpf;
         break;
 
+    case MSR_K8_TOP_MEM1:
+    case MSR_K8_TOP_MEM2:
+    case MSR_K8_SYSCFG:
     case MSR_K8_VM_CR:
         /* ignore write. handle all bits as read-only. */
         break;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:42 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxNC-000544-GI; Wed, 09 Sep 2020 10:30:42 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNB-00053t-EA
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:41 +0000
X-Inumbo-ID: 0cdff25e-9c2a-48ed-9e7c-9fb6283e6322
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0cdff25e-9c2a-48ed-9e7c-9fb6283e6322;
 Wed, 09 Sep 2020 10:30:40 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ADaIaZxyMqkliqpOCSZChWpxtJXdKVtK+QFN/D6D8LY=; b=h5A8q3N3sUQtAoa5Hnt1iqLF8x
 0yp5/thMte5epJN40mOxF8a1NEt4LOaP1vfYx9Yp3nswV9BQpEZZuT7toxVGHsztKfwnFx6t9NszU
 W6roAdE8caf9yABEPQ32xQTpxL/l4EU6hatoKgzP5gQX6UaOYBHkAHS+YEXMFg1ZBVBQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNA-0005AI-95
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:40 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNA-0007D3-6i
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:40 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kFxNA-0007D3-6i@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:30:40 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 7 11:32:34 2020 +0100

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 18 ++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 66975d5f2c..f479bc6857 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1728,6 +1728,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1738,14 +1748,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index ec5a7d2dca..44e4ea2582 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -444,17 +444,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 void toggle_guest_mode(struct vcpu *v)
 {
     const struct domain *d = v->domain;
+    unsigned long gs_base;
 
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index bcc1188f6a..a192160f84 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -801,17 +801,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -882,15 +871,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -1007,14 +994,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 28bc98f8f2..b69cf2dc4f 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1030,10 +1030,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1050,10 +1047,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 5fb347a94c..df657dc69f 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -527,7 +527,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:30:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:30:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxNM-000550-Hz; Wed, 09 Sep 2020 10:30:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNL-00054r-TD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:51 +0000
X-Inumbo-ID: 3fbb712f-588a-472f-9531-b66a6cb0a773
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3fbb712f-588a-472f-9531-b66a6cb0a773;
 Wed, 09 Sep 2020 10:30:50 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=5HpUlTBgWgeViERYYTBr7llDoFHbXba2RiFhWInc8As=; b=5ORqwU8iAyAsG+hwQih4+XrKol
 JsNUO0csHMrSA/8vC90Rng8Pi22/+F3f8aZzz/nYL8k1INMB71Z4u0nKhndyI/QU9chUvuS31xTap
 favcfA53wap421qNT90gWclVWTNzXj80sf0k2qI3le0ffgUfDlcCPj9fOsbYD03WO8vQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNK-0005AQ-Cl
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:50 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNK-0007DV-C0
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:30:50 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Rewrite segment context switching from scratch
Message-Id: <E1kFxNK-0007DV-C0@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:30:50 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ad0fd291c5e79191c2e3c70e43dded569f11a450
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 7 11:32:34 2020 +0100

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c                    | 184 ++++++++++---------------------
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 2 files changed, 60 insertions(+), 128 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index f479bc6857..d4f4ced681 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1186,13 +1186,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1508,58 +1504,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1572,57 +1570,21 @@ static void load_segments(struct vcpu *n)
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1741,7 +1703,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1758,35 +1719,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1996,7 +1928,7 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
+         !is_idle_domain(nd) )
         svm_load_segs(0, 0, 0, 0, 0, 0, 0);
 #endif
 
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:31:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:31:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxNW-00056F-LA; Wed, 09 Sep 2020 10:31:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNV-000563-8S
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:01 +0000
X-Inumbo-ID: 14403838-baa0-45c3-a536-9a7e40607f1e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 14403838-baa0-45c3-a536-9a7e40607f1e;
 Wed, 09 Sep 2020 10:31:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hUvLnvZT+gudvDBqJGH/wquYKZ344mPIYyvf2SDZRSs=; b=kZXyIAQZ/3yQzyrZ7rTZXWBmF5
 CREJNQB7nrPm3RzGxeDyhMrATXpi0/qdasTf322Hzof3nVGKRtk+1bdQg1wyuZw84ZhUPveJPK7CJ
 ewzMiUUNfqMD92fBfcCIK0yGOmYGx/8tY+ckdU8WRdp9oQJvXaoEK7bK5OyjG2hXIexY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNU-0005B7-GY
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:00 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNU-0007E3-FZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:00 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] libgnttab/freebsd: add tools libs.h
Message-Id: <E1kFxNU-0007E3-FZ@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:31:00 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1be24cd17741192d1e18f24e6cf92f0ae9324e62
Author:     Roger Pau Monne <roger.pau@citrix.com>
AuthorDate: Mon Sep 7 12:18:05 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:13:31 2020 +0000

    libgnttab/freebsd: add tools libs.h
    
    In order to get the ROUNDUP macro, or else the build fails. I assume
    ROUNDUP would previously get included from a different header.
    
    Seeing as Linux does explicitly include libs.h do the same for
    FreeBSD.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/gnttab/freebsd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c
index 0588501d0f..768af701c6 100644
--- a/tools/libs/gnttab/freebsd.c
+++ b/tools/libs/gnttab/freebsd.c
@@ -30,6 +30,8 @@
 
 #include <xen/sys/gntdev.h>
 
+#include <xen-tools/libs.h>
+
 #include "private.h"
 
 #define PAGE_SHIFT           12
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:31:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:31:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxNg-00057q-N3; Wed, 09 Sep 2020 10:31:12 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNf-00057j-GE
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:11 +0000
X-Inumbo-ID: 1f154c69-12ef-4caf-b153-9fa385adeef1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1f154c69-12ef-4caf-b153-9fa385adeef1;
 Wed, 09 Sep 2020 10:31:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=c/KAlCoQSYQGBYfdgbCLR25vNhZ2GgB6VLfJ1YpoBPw=; b=bpGcvL0VkXlZ48pcr5HHhSuWlz
 KQrjIdq1xULd+CLGGqlFdIVWDtBoRjT8wNB8/ul1ET/E1GI0f3R+hkuFc6reIa9FI4XBg9rSkufdX
 jacVLIFEQ7E9CsCxm0fXtfdrgeg4ovFAJZkqdM1SVy3Dg10kNgcd2gk8+IjyqtkNsiQU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNe-0005BR-KK
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:10 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNe-0007El-JI
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:10 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] minios: use more recent commit for building xen unstable
Message-Id: <E1kFxNe-0007El-JI@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:31:10 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 71039ed743a3fbf7b58815138d667913a5742e6f
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Mon Sep 7 13:48:14 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:14:40 2020 +0000

    minios: use more recent commit for building xen unstable
    
    Commit 82c3d15c903aa43 ("minios: Revert recent change and revert to
    working minios") switched the used commit for the build of Xen unstable
    from master to a rather old commit (the one used for Xen 4.13 instead
    of the last one without a known problem).
    
    Switch to Mini-OS commit 051b87bb9c196 instead, which doesn't contain
    the problematic modification being reason for switching away from
    master.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 Config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Config.mk b/Config.mk
index db434ee2c6..259e68863d 100644
--- a/Config.mk
+++ b/Config.mk
@@ -246,7 +246,7 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= a3741780fe3535e19e02efa869a7cac481891129
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= 0b4b7897e08b967a09bed2028a79fabff82342dd
+MINIOS_UPSTREAM_REVISION ?= 051b87bb9c19609976fb038f386920e1ce5454c5
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.14.0
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:31:22 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:31:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxNq-000590-Og; Wed, 09 Sep 2020 10:31:22 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNq-00058s-8N
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:22 +0000
X-Inumbo-ID: 5be7f4ea-fb79-42aa-a6c0-e400c33ffc03
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5be7f4ea-fb79-42aa-a6c0-e400c33ffc03;
 Wed, 09 Sep 2020 10:31:20 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=za15oWU48jRuKc4acVtRm37eVVUxEl0ODyXzw4AJxjE=; b=rCxDdmzfXrBvXKRlfnrAJsBc2G
 9d/iNOueJ5UbdPfZlqZ95sMC9Lk3bTZMUviDNd90dERpVbZsxwhVQkDnGIC+Emhn+nXIrUMg2jtTE
 Gzw/Y1SbR1NHTnQYFpQZ1h96DsdHMyco+n13LfUGBr69rjDihUI/WsDLo/IOtzZYXBFc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNo-0005DG-Ny
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:20 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNo-0007FD-N3
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:20 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug/Linux: don't needlessly use non-standard
 features in vif-{bridge, route}
Message-Id: <E1kFxNo-0007FD-N3@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:31:20 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b11910082d90bb1597f6679524eb726a33306672
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 2 08:09:28 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 7 14:28:59 2020 +0000

    tools/hotplug/Linux: don't needlessly use non-standard features in vif-{bridge,route}
    
    We're not after any "fall-through" behavior here. Replace the constructs
    with ones understood by all conforming shells, including older bash
    (problem observed with 3.1.51(1)).
    
    Fixes: b51715f02bf9 ("tools/hotplug/Linux: remove code duplication in vif-bridge")
    Fixes: 3683290fc0b0 ("tools/hotplug: only attempt to call 'ip route' if there is valid command")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-bridge | 8 ++------
 tools/hotplug/Linux/vif-route  | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge
index b99cc82a21..906047e82f 100644
--- a/tools/hotplug/Linux/vif-bridge
+++ b/tools/hotplug/Linux/vif-bridge
@@ -77,16 +77,12 @@ then
 fi
 
 case "$command" in
-    add)
-        ;&
-    online)
+    add|online)
         setup_virtual_bridge_port "$dev"
         set_mtu "$bridge" "$dev" "$type_if"
         add_to_bridge "$bridge" "$dev"
         ;;
-    remove)
-        ;&
-    offline)
+    remove|offline)
         remove_from_bridge "$bridge" "$dev"
         ;;
 esac
diff --git a/tools/hotplug/Linux/vif-route b/tools/hotplug/Linux/vif-route
index 05199bf741..9cd417a005 100755
--- a/tools/hotplug/Linux/vif-route
+++ b/tools/hotplug/Linux/vif-route
@@ -22,17 +22,13 @@ dir=$(dirname "$0")
 main_ip=$(dom0_ip)
 
 case "${command}" in
-    add)
-        ;&
-    online)
+    add|online)
         ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up
         echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
         ipcmd='add'
         cmdprefix=''
         ;;
-    remove)
-        ;&
-    offline)
+    remove|offline)
         do_without_error ifdown ${dev}
         ipcmd='del'
         cmdprefix='do_without_error'
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 10:31:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 10:31:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFxO0-00059y-QO; Wed, 09 Sep 2020 10:31:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFxNz-00059p-QU
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:31 +0000
X-Inumbo-ID: c7c53efe-e883-4cef-9218-fe57335afc24
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c7c53efe-e883-4cef-9218-fe57335afc24;
 Wed, 09 Sep 2020 10:31:31 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7EGpjsXHGEhJhTGMMu69/u82hh4OQFELBQ0q68qzS7c=; b=SLb00LPwKNDeSEUD14VjO9yq9c
 hA4qaoiZr1aFPU1WHztghvXRZG1+fIjkUmYcO7YGASr0fOywP8sZc5+sBDXszm4APZYR5Z8+D8D6X
 V29ppHypn/LslV4b+wPMvGXR499rTiiQGaeb/F+ll1B0dVx1Wr2M2O3lGs9CbXrWpqcI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNy-0005DO-Ru
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:30 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFxNy-0007Fh-R1
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 10:31:30 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Fix assertions in svm_load_segs()
Message-Id: <E1kFxNy-0007Fh-R1@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 10:31:30 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1e2d3be2e516e6f415ca6029f651b76a8563a27c
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 8 10:47:57 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 8 16:46:31 2020 +0100

    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c             | 7 +++----
 xen/arch/x86/hvm/svm/svm.c        | 9 +++------
 xen/include/asm-x86/hvm/svm/svm.h | 6 ++++--
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index d4f4ced681..e8e91cf080 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1557,7 +1557,7 @@ static void load_segments(struct vcpu *n)
                    : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !compat )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1565,8 +1565,7 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
@@ -1929,7 +1928,7 @@ static void __context_switch(void)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
          !is_idle_domain(nd) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index af584ff5d1..23b2a2aa17 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1521,8 +1521,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1559,14 +1558,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index d568e86db9..2310878e41 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:11:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:11:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy0P-0000Lu-1r; Wed, 09 Sep 2020 11:11:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy0N-0000Lm-QI
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:11 +0000
X-Inumbo-ID: 4328d7f7-f504-4de6-9fbf-c310edd4fa8d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4328d7f7-f504-4de6-9fbf-c310edd4fa8d;
 Wed, 09 Sep 2020 11:11:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6jLs87oo7ANMGzMCykI3LvLyVmMtG/GwqQUfak+f8yc=; b=WDEFjTmmlHdnM5/VVGVaJuFsuN
 PyLxiwynQ13iG2vRJNLTrffVbZXFF+4sYzx1UVgR49Adqb210gPXhhH+Bwd/Hv0n09tYrvDKgzlDI
 MFnSZ68syPpBWYSihVKzVXp7EUtreZDRmDHkQ3buvd6T8VdNZY6dp7tPlRRvE/PRblNE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0I-00061a-K4
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0I-0001Im-Ij
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: generate pkg-config files from make variables
Message-Id: <E1kFy0I-0001Im-Ij@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 52dbd6f07cea7a776ba1fcc76f111c311c8a1412
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:17 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:16 2020 +0000

    tools: generate pkg-config files from make variables
    
    For each library built two variants of pkg-config files are created
    from a per-library template: an "official" one for installation on
    the user's system, and one used for building internal tools, like e.g.
    qemu.
    
    Instead of the template which is looking very similar for all libraries
    generate the pkg-config files directly from make variables.
    
    This will reduce the need to specify some pkg-config file entries in
    the templates, as the contents can easily be generated from available
    data (e.g. "Version:" and "Requires.private:" entries).
    
    Especially the variant used for building internal tools needs to gain
    additional runtime link parameters for the internally used libraries,
    as otherwise those won't be found by the users (e.g. qemu).
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 stubdom/Makefile                                |  1 -
 tools/Rules.mk                                  | 52 ++++++++++++++-----------
 tools/libs/call/xencall.pc.in                   | 10 -----
 tools/libs/devicemodel/xendevicemodel.pc.in     | 10 -----
 tools/libs/evtchn/xenevtchn.pc.in               | 10 -----
 tools/libs/foreignmemory/xenforeignmemory.pc.in | 10 -----
 tools/libs/gnttab/xengnttab.pc.in               | 10 -----
 tools/libs/hypfs/xenhypfs.pc.in                 | 10 -----
 tools/libs/libs.mk                              |  8 ++++
 tools/libs/toolcore/Makefile                    |  1 +
 tools/libs/toolcore/xentoolcore.pc.in           |  9 -----
 tools/libs/toollog/xentoollog.pc.in             |  9 -----
 tools/libvchan/Makefile                         |  5 +++
 tools/libvchan/xenvchan.pc.in                   | 10 -----
 tools/libxc/Makefile                            | 22 +++++++++++
 tools/libxc/xencontrol.pc.in                    | 10 -----
 tools/libxc/xenguest.pc.in                      | 10 -----
 tools/libxl/Makefile                            | 22 +++++++++++
 tools/libxl/xenlight.pc.in                      | 12 ------
 tools/libxl/xlutil.pc.in                        | 10 -----
 tools/xenstat/libxenstat/Makefile               |  5 +++
 tools/xenstat/libxenstat/xenstat.pc.in          | 10 -----
 tools/xenstore/Makefile                         |  8 +++-
 tools/xenstore/xenstore.pc.in                   | 11 ------
 24 files changed, 98 insertions(+), 177 deletions(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index 98eba8efe3..f000f56e68 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -342,7 +342,6 @@ define do_links
   cd $(dir $@); \
   ln -sf $(dir $<)include/*.h include/; \
   ln -sf $(dir $<)*.[ch] .; \
-  ln -sf $(dir $<)*.pc.in .; \
   ln -sf $(dir $<)Makefile .
   touch $@
 endef
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 385807a71c..52a16c9ac3 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -209,27 +209,33 @@ endif
 
 PKG_CONFIG_DIR ?= $(XEN_ROOT)/tools/pkg-config
 
-PKG_CONFIG_FILTER = $(foreach l,$(PKG_CONFIG_REMOVE),-e 's!\([ ,]\)$(l),!\1!g' -e 's![ ,]$(l)$$!!g')
-
-$(PKG_CONFIG_DIR)/%.pc: %.pc.in Makefile $(XEN_ROOT)/tools/Rules.mk
+$(PKG_CONFIG_DIR):
 	mkdir -p $(PKG_CONFIG_DIR)
-	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
-	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
-	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
-	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
-	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
-	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
-	     -e 's!@@cflagslocal@@!$(PKG_CONFIG_CFLAGS_LOCAL)!g' \
-	     -e 's!@@libsflag@@\([^ ]*\)!-L\1 -Wl,-rpath-link=\1!g' \
-	     $(PKG_CONFIG_FILTER) < $< > $@
-
-%.pc: %.pc.in Makefile $(XEN_ROOT)/tools/Rules.mk
-	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
-	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
-	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
-	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
-	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
-	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
-	     -e 's!@@cflagslocal@@!!g' \
-	     -e 's!@@libsflag@@!-L!g' \
-	     $(PKG_CONFIG_FILTER) < $< > $@
+
+$(PKG_CONFIG_DIR)/%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk $(PKG_CONFIG_DIR)
+	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
+	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
+	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
+	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
+	$(file >>$@,)
+	$(file >>$@,Name: $(PKG_CONFIG_NAME))
+	$(file >>$@,Description: $(PKG_CONFIG_DESC))
+	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
+	$(file >>$@,Cflags: -I$${includedir} $(CFLAGS_xeninclude))
+	$(file >>$@,Libs: -L$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB))
+	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
+	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+
+%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk
+	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
+	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
+	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
+	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
+	$(file >>$@,)
+	$(file >>$@,Name: $(PKG_CONFIG_NAME))
+	$(file >>$@,Description: $(PKG_CONFIG_DESC))
+	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
+	$(file >>$@,Cflags: -I$${includedir})
+	$(file >>$@,Libs: -L$${libdir} -l$(PKG_CONFIG_LIB))
+	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
+	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
diff --git a/tools/libs/call/xencall.pc.in b/tools/libs/call/xencall.pc.in
deleted file mode 100644
index 409773e535..0000000000
--- a/tools/libs/call/xencall.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xencall
-Description: The Xencall library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxencall
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/devicemodel/xendevicemodel.pc.in b/tools/libs/devicemodel/xendevicemodel.pc.in
deleted file mode 100644
index 8bd04faf47..0000000000
--- a/tools/libs/devicemodel/xendevicemodel.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xendevicemodel
-Description: The Xendevicemodel library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxendevicemodel
-Requires.private: xentoolcore,xentoollog,xencall
diff --git a/tools/libs/evtchn/xenevtchn.pc.in b/tools/libs/evtchn/xenevtchn.pc.in
deleted file mode 100644
index c74af1ece4..0000000000
--- a/tools/libs/evtchn/xenevtchn.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenevtchn
-Description: The Xenevtchn library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenevtchn
-Requires.private: xentoollog
diff --git a/tools/libs/foreignmemory/xenforeignmemory.pc.in b/tools/libs/foreignmemory/xenforeignmemory.pc.in
deleted file mode 100644
index 61c9def69c..0000000000
--- a/tools/libs/foreignmemory/xenforeignmemory.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenforeignmemory
-Description: The Xenforeignmemory library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenforeignmemory
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/gnttab/xengnttab.pc.in b/tools/libs/gnttab/xengnttab.pc.in
deleted file mode 100644
index 4c3beed5dc..0000000000
--- a/tools/libs/gnttab/xengnttab.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xengnttab
-Description: The Xengnttab library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxengnttab
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/hypfs/xenhypfs.pc.in b/tools/libs/hypfs/xenhypfs.pc.in
deleted file mode 100644
index ef9fcc87bf..0000000000
--- a/tools/libs/hypfs/xenhypfs.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenhypfs
-Description: The Xenhypfs library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenhypfs
-Requires.private: xentoolcore,xentoollog,xencall,zlib
diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 8b1ca2aa62..4679268fc2 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -25,8 +25,16 @@ ifneq ($(nosharedlibs),y)
 LIB += libxen$(LIBNAME).so
 endif
 
+comma:= ,
+empty:=
+space:= $(empty) $(empty)
 PKG_CONFIG ?= xen$(LIBNAME).pc
+PKG_CONFIG_NAME ?= Xen$(LIBNAME)
+PKG_CONFIG_DESC ?= The $(PKG_CONFIG_NAME) library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxen$(LIBNAME))
+PKG_CONFIG_LIB := xen$(LIBNAME)
+PKG_CONFIG_REQPRIV := $(subst $(space),$(comma),$(strip $(foreach lib,$(USELIBS_$(LIBNAME)),xen$(lib))))
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/libs/toolcore/Makefile b/tools/libs/toolcore/Makefile
index 34b08a4236..5819bbc8ee 100644
--- a/tools/libs/toolcore/Makefile
+++ b/tools/libs/toolcore/Makefile
@@ -9,6 +9,7 @@ SRCS-y	+= handlereg.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
+PKG_CONFIG_DESC := Central support for Xen Hypervisor userland libraries
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxentoolcore)/include
 
 $(LIB_OBJS): $(AUTOINCS)
diff --git a/tools/libs/toolcore/xentoolcore.pc.in b/tools/libs/toolcore/xentoolcore.pc.in
deleted file mode 100644
index 55ff4e25e4..0000000000
--- a/tools/libs/toolcore/xentoolcore.pc.in
+++ /dev/null
@@ -1,9 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xentoolcore
-Description: Central support for Xen Hypervisor userland libraries
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxentoolcore
diff --git a/tools/libs/toollog/xentoollog.pc.in b/tools/libs/toollog/xentoollog.pc.in
deleted file mode 100644
index 554e4d5b34..0000000000
--- a/tools/libs/toollog/xentoollog.pc.in
+++ /dev/null
@@ -1,9 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xentoollog
-Description: The Xentoollog library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxentoollog
diff --git a/tools/libvchan/Makefile b/tools/libvchan/Makefile
index a5441162a0..e718447977 100644
--- a/tools/libvchan/Makefile
+++ b/tools/libvchan/Makefile
@@ -23,7 +23,12 @@ CFLAGS += -I../include -I.
 io.o io.opic: CFLAGS += $(CFLAGS_libxenctrl) # for xen_mb et al
 
 PKG_CONFIG := xenvchan.pc
+PKG_CONFIG_NAME := Xenvchan
+PKG_CONFIG_DESC := The Xenvchan library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenvchan)
+PKG_CONFIG_LIB := xenvchan
+PKG_CONFIG_REQPRIV := xentoollog,xenstore,xenevtchn,xengnttab
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/libvchan/xenvchan.pc.in b/tools/libvchan/xenvchan.pc.in
deleted file mode 100644
index 6fd13108d2..0000000000
--- a/tools/libvchan/xenvchan.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenvchan
-Description: The Xenvchan library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenvchan
-Requires.private: xentoollog,xenstore,xenevtchn,xengnttab
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index c1e41a8ee9..315ac0b4f3 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -158,6 +158,28 @@ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): xc_private.h
 PKG_CONFIG := xencontrol.pc xenguest.pc
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
 
+xencontrol.pc: PKG_CONFIG_NAME = Xencontrol
+xencontrol.pc: PKG_CONFIG_DESC = The Xencontrol library for Xen hypervisor
+xencontrol.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenctrl)
+xencontrol.pc: PKG_CONFIG_LIB = xenctrl
+xencontrol.pc: PKG_CONFIG_REQPRIV = xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
+xenguest.pc: PKG_CONFIG_NAME = Xenguest
+xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
+xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
+xenguest.pc: PKG_CONFIG_LIB = xenguest
+xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_NAME = Xencontrol
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_DESC = The Xencontrol library for Xen hypervisor
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenctrl)
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_LIB = xenctrl
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_REQPRIV = xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_NAME = Xenguest
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_LIB = xenguest
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
 $(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
diff --git a/tools/libxc/xencontrol.pc.in b/tools/libxc/xencontrol.pc.in
deleted file mode 100644
index e653ba2543..0000000000
--- a/tools/libxc/xencontrol.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xencontrol
-Description: The Xencontrol library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenctrl
-Requires.private: xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
diff --git a/tools/libxc/xenguest.pc.in b/tools/libxc/xenguest.pc.in
deleted file mode 100644
index 225ac0b9c8..0000000000
--- a/tools/libxc/xenguest.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenguest
-Description: The Xenguest library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenguest
-Requires.private: xentoollog,xencall,xenforeignmemory,xenevtchn
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index c26b3a8093..f61f761e1e 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -195,8 +195,19 @@ PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
+xenlight.pc: PKG_CONFIG_NAME = Xenlight
+xenlight.pc: PKG_CONFIG_DESC = The Xenlight library for Xen hypervisor
 xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR)
+xenlight.pc: PKG_CONFIG_VARS = xenfirmwaredir=$(XENFIRMWAREDIR) libexec_bin=$(LIBEXEC_BIN)
+xenlight.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenlight)
+xenlight.pc: PKG_CONFIG_LIB = xenlight
+xenlight.pc: PKG_CONFIG_REQPRIV = xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
+xlutil.pc: PKG_CONFIG_NAME = Xlutil
+xlutil.pc: PKG_CONFIG_DESC = The xl utility library for Xen hypervisor
 xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR)
+xlutil.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxlutil)
+xlutil.pc: PKG_CONFIG_LIB = xlutil
+xlutil.pc: PKG_CONFIG_REQPRIV = xenlight
 $(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
 $(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
 $(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
@@ -204,8 +215,19 @@ endif
 
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_NAME = Xenlight
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_DESC = The Xenlight library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_VARS = xenfirmwaredir=$(XENFIRMWAREDIR) libexec_bin=$(LIBEXEC_BIN)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenlight)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_LIB = xenlight
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_REQPRIV = xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_NAME = Xlutil
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_DESC = The xl utility library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR)
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxlutil)
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_LIB = xlutil
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_REQPRIV = xenlight
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(CURDIR)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
diff --git a/tools/libxl/xenlight.pc.in b/tools/libxl/xenlight.pc.in
deleted file mode 100644
index 6b351ba096..0000000000
--- a/tools/libxl/xenlight.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-xenfirmwaredir=@@firmwaredir@@
-libexec_bin=@@libexecbin@@
-
-Name: Xenlight
-Description: The Xenlight library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenlight
-Requires.private: xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
diff --git a/tools/libxl/xlutil.pc.in b/tools/libxl/xlutil.pc.in
deleted file mode 100644
index cdd98fba74..0000000000
--- a/tools/libxl/xlutil.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xlutil
-Description: The xl utility library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxlutil
-Requires.private: xenlight
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index b5e623b155..bdd5a0f469 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -38,7 +38,12 @@ LDLIBS-y = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) -lyajl
 LDLIBS-$(CONFIG_SunOS) += -lkstat
 
 PKG_CONFIG := xenstat.pc
+PKG_CONFIG_NAME := Xenstat
+PKG_CONFIG_DESC := The Xenstat library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenstat)
+PKG_CONFIG_LIB := xenstat
+PKG_CONFIG_REQPRIV := xencontrol,xenstore
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/xenstat/libxenstat/xenstat.pc.in b/tools/xenstat/libxenstat/xenstat.pc.in
deleted file mode 100644
index ad00577c89..0000000000
--- a/tools/xenstat/libxenstat/xenstat.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenstat
-Description: The Xenstat library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenstat
-Requires.private: xencontrol,xenstore
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 0a64ac1571..574be8d15c 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -105,8 +105,7 @@ xs.opic: CFLAGS += -DUSE_PTHREAD
 ifeq ($(CONFIG_Linux),y)
 xs.opic: CFLAGS += -DUSE_DLSYM
 libxenstore.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += -ldl
-else
-PKG_CONFIG_REMOVE += -ldl
+PKG_CONFIG_LIBSPRIV := -ldl
 endif
 
 libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
@@ -116,7 +115,12 @@ libxenstore.a: xs.o xs_lib.o
 	$(AR) rcs $@ $^
 
 PKG_CONFIG := xenstore.pc
+PKG_CONFIG_NAME := Xenstore
+PKG_CONFIG_DESC := The Xenstore library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenstore)
+PKG_CONFIG_LIB := xenstore
+PKG_CONFIG_REQPRIV := xenevtchn,xencontrol,xengnttab,xentoolcore
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/xenstore/xenstore.pc.in b/tools/xenstore/xenstore.pc.in
deleted file mode 100644
index 2f64a6b824..0000000000
--- a/tools/xenstore/xenstore.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenstore
-Description: The Xenstore library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenstore
-Libs.private: -ldl
-Requires.private: xenevtchn,xencontrol,xengnttab,xentoolcore
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:11:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:11:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy0V-0000N8-4o; Wed, 09 Sep 2020 11:11:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy0T-0000Mo-J9
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:17 +0000
X-Inumbo-ID: 6a877c67-06b5-462f-8a89-84094da0150c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6a877c67-06b5-462f-8a89-84094da0150c;
 Wed, 09 Sep 2020 11:11:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eK5OoDqpMRSV9/bKByvMv9R4WOirmqUCYc+UwIbNP68=; b=yarW1Cr27gtIhZvwlk0C7TUGcG
 WMXoJc9U/SRsuXr2VPytn4uv46xntw1mzfSnrWnghIuBcOoEmEInjiKH4R4CoVXyKBWyeknvC9ll6
 eW0MEGo1A+F3QHe09ePeRja1Bz7emtGY3Fz7KNbL2s9VeFxapWbYF2Ve8I0PuEewMkFA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0S-00061f-PF
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0S-0001JJ-Mh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: drop explicit path specifications for qemu build
Message-Id: <E1kFy0S-0001JJ-Mh@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0b77395ef2f20058305240f2395883b1d961982a
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:18 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:21 2020 +0000

    tools: drop explicit path specifications for qemu build
    
    Since more than three years now qemu is capable to set the needed
    include and library paths for the Xen libraries via pkg-config.
    
    So drop the specification of those paths in tools/Makefile. This will
    enable to move libxenctrl away from tools/libxc, as qemu's configure
    script has special treatment of this path.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Makefile | 26 +-------------------------
 1 file changed, 1 insertion(+), 25 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index 198b239edc..7c9f9fc900 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -245,32 +245,8 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-DXC_WANT_COMPAT_GNTTAB_API=1 \
 		-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
 		-DXC_WANT_COMPAT_DEVICEMODEL_API=1 \
-		-I$(XEN_ROOT)/tools/include \
-		-I$(XEN_ROOT)/tools/libs/toolcore/include \
-		-I$(XEN_ROOT)/tools/libs/toollog/include \
-		-I$(XEN_ROOT)/tools/libs/evtchn/include \
-		-I$(XEN_ROOT)/tools/libs/gnttab/include \
-		-I$(XEN_ROOT)/tools/libs/foreignmemory/include \
-		-I$(XEN_ROOT)/tools/libs/devicemodel/include \
-		-I$(XEN_ROOT)/tools/libxc/include \
-		-I$(XEN_ROOT)/tools/xenstore/include \
-		-I$(XEN_ROOT)/tools/xenstore/compat/include \
 		$(EXTRA_CFLAGS_QEMU_XEN)" \
-		--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
-		-L$(XEN_ROOT)/tools/xenstore \
-		-L$(XEN_ROOT)/tools/libs/toolcore \
-		-L$(XEN_ROOT)/tools/libs/evtchn \
-		-L$(XEN_ROOT)/tools/libs/gnttab \
-		-L$(XEN_ROOT)/tools/libs/foreignmemory \
-		-L$(XEN_ROOT)/tools/libs/devicemodel \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toolcore \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/devicemodel \
-		$(QEMU_UPSTREAM_RPATH)" \
+		--extra-ldflags="$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
 		--localstatedir=$(localstatedir) \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:11:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:11:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy0f-0000PN-6a; Wed, 09 Sep 2020 11:11:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy0d-0000Or-Kz
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:27 +0000
X-Inumbo-ID: c1abfacb-37b9-4353-a6ef-ab0ab97c4f68
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c1abfacb-37b9-4353-a6ef-ab0ab97c4f68;
 Wed, 09 Sep 2020 11:11:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Kcpi0UzXZ/RweluQzvD/bhEKl7Vl5+xNqL38tYV7bhU=; b=1hJy9NWDRIWioLG039V8/ZBnwN
 BykEj32vBAnCYiCkEQo1vRvh+GssU1FNccOllVn60KOhow9gOhQQa8gSTy70q8p2B4B5RBUAp6eZE
 Ik3qcIxc/bswFvEWR7jTRCQiKNgBaivBaV4dz4m85FnMYJzY5RwbU0Q0nckZ8PDpsZnQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0c-00063T-TK
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0c-0001Jv-Rw
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/python: drop libxenguest from setup.py
Message-Id: <E1kFy0c-0001Jv-Rw@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7c273ffdd0e91d9eeb975b7d531a4ed235931bb1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:19 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/python: drop libxenguest from setup.py
    
    There is not a single wrapper for a libxenguest function defined.
    So drop libxenguest from tools/python/setup.py.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/python/setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8faf1c0ddc..44696b3998 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -21,8 +21,8 @@ xc = Extension("xc",
                                       PATH_LIBXC + "/include",
                                       "xen/lowlevel/xc" ],
                library_dirs       = [ PATH_LIBXC ],
-               libraries          = [ "xenctrl", "xenguest" ],
-               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ],
+               libraries          = [ "xenctrl" ],
+               depends            = [ PATH_LIBXC + "/libxenctrl.so" ],
                extra_link_args    = [ "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:11:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:11:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy0p-0000Rg-84; Wed, 09 Sep 2020 11:11:39 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy0n-0000RM-SZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:37 +0000
X-Inumbo-ID: f6cb2c5d-ce85-42cb-8812-bebdb93c9edb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f6cb2c5d-ce85-42cb-8812-bebdb93c9edb;
 Wed, 09 Sep 2020 11:11:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0ySNoB8t5ccxOTNRpQ89O/oByl3dBTmfThAeTUJbrco=; b=a1WZ6GEA3fKUvoraH/Xy5xGjN4
 a7gibcVU9njzzEcuhCeWC5yCIZqmt38+LQF1UOntaRK3KmPk7QlcH/AV0Ewf08od9+lbrby+VvlMI
 6YzucOAhu25GxSMjidUoOXmJULxfR2Axt0SdIM2toKD03BvWPz6aWjF70GsCNsDNNMDI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0n-00063c-1S
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0m-0001LE-Vu
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: fix pkg-config file for libxenguest
Message-Id: <E1kFy0m-0001LE-Vu@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit bb2ea7f392348b2697c5b9140deea56b1b56776e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:20 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: fix pkg-config file for libxenguest
    
    The pkg-config file for libxenguest is missing the private dependency
    on libxenctrl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 315ac0b4f3..763231065c 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -178,7 +178,7 @@ $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_NAME = Xenguest
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_LIB = xenguest
-$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn,xencontrol
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:11:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:11:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy0z-0000TO-9p; Wed, 09 Sep 2020 11:11:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy0y-0000TC-0k
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:48 +0000
X-Inumbo-ID: a359d807-133e-4007-b96c-e2add56b0684
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a359d807-133e-4007-b96c-e2add56b0684;
 Wed, 09 Sep 2020 11:11:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GqD9miaz7au/As1TFuSXMdmIvSrvv3kO1wqEaK6v1Gk=; b=jw0ZNGJFaYzqq7wm0Ozzc+Yec4
 xDTc5zWvhYBiJ7cVnOfW3cwRwz2M7aG7PGevUj2h9FAR5SFIn5ZFs0SkQN46Xm+wz0TBqkFvOmH2Q
 dDyqZ3V2hKHcjll7S5P62uyuWZKk/+p9budvA4kk8iDt0UaTuMWvfUHgPhRvnwX+WZwk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0x-00063k-5I
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy0x-0001Lo-4K
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: don't assume libxenguest and libxenctrl to be in
 same directory
Message-Id: <E1kFy0x-0001Lo-4K@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0c293ad3a2842452bff0fe0515cc9046a60afa5e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:21 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: don't assume libxenguest and libxenctrl to be in same directory
    
    There are quite some places in Makefiles assuming libxenguest and
    libxenctrl being built in the same directory via a single Makefile.
    
    Drop this assumption by specifying the dependencies and path variables
    for both libraries correctly.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk       | 7 +++----
 tools/libxl/Makefile | 2 +-
 tools/misc/Makefile  | 1 +
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 52a16c9ac3..13432560ff 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -16,8 +16,7 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
 XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
-# Currently libxenguest lives in the same directory as libxenctrl
-XEN_libxenguest    = $(XEN_libxenctrl)
+XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
@@ -117,7 +116,7 @@ LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libex
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
 
 CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenstore = $(SHLIB_libxentoolcore)
+SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
 LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_libxenstore)/libxenstore$(libextension)
 SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_libxenstore)
 ifeq ($(CONFIG_Linux),y)
@@ -144,7 +143,7 @@ CFLAGS += -O2 -fomit-frame-pointer
 endif
 
 CFLAGS_libxenlight = -I$(XEN_libxenlight) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
-SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs)
+SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs) $(SHLIB_libxenguest)
 LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_libxenlight)/libxenlight$(libextension)
 SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_libxenlight)
 
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index f61f761e1e..b3815390f3 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -188,7 +188,7 @@ libxl_dom.o: CFLAGS += -I$(XEN_ROOT)/tools  # include libacpi/x86.h
 libxl_x86_acpi.o: CFLAGS += -I$(XEN_ROOT)/tools
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
-$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn)
+$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 PKG_CONFIG = xenlight.pc xlutil.pc
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 9fdb13597f..e7e74db85f 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -6,6 +6,7 @@ CFLAGS += -Werror
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 CFLAGS += $(CFLAGS_libxenevtchn)
 CFLAGS += $(CFLAGS_libxenctrl)
+CFLAGS += $(CFLAGS_libxenguest)
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenstore)
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1B-0000Va-BQ; Wed, 09 Sep 2020 11:12:01 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy19-0000VI-Iv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:59 +0000
X-Inumbo-ID: 962640d7-68d3-4586-b1e4-f9490c97bf6a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 962640d7-68d3-4586-b1e4-f9490c97bf6a;
 Wed, 09 Sep 2020 11:11:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hKH4RrAbOHGEm4ZU2BIyNe/R4KtLJadTnRjWnj8v2uM=; b=hg8BhGPeofpAy8zyRPQTOTpvDK
 Qx28/WrGT6UOISnMiRcg3iB6xLrI3MvuClm36AuP2zhXT9eZvXaKc7diyDntxtFsn7ze+osqQukxr
 TnmE7OwZsMeJ8vOCy+xbeAlGnCj969Nzgkmemlyc9z9gDLlnhLXYmstbCgvU0tFZzYGQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy18-00063w-PK
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:58 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy17-0001Mo-7t
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:11:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/misc: don't use libxenctrl internals from
 xen-hptool
Message-Id: <E1kFy17-0001Mo-7t@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:11:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 76020cc98b0c6da6241e51979071df8ab0643930
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:22 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: don't use libxenctrl internals from xen-hptool
    
    xen-hptool is including private headers from tools/libxc without any
    need. Switch it to use official headers only.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/Makefile     | 2 --
 tools/misc/xen-hptool.c | 8 +++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index e7e74db85f..2a7f2ec42d 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -94,8 +94,6 @@ xenhypfs: xenhypfs.o
 xenlockprof: xenlockprof.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
-# xen-hptool incorrectly uses libxc internals
-xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-hptool: xen-hptool.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-hptool.c b/tools/misc/xen-hptool.c
index 6e27d9cf43..7f17f24942 100644
--- a/tools/misc/xen-hptool.c
+++ b/tools/misc/xen-hptool.c
@@ -1,9 +1,11 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include <xenevtchn.h>
 #include <xenctrl.h>
-#include <xc_private.h>
-#include <xc_core.h>
+#include <xenguest.h>
 #include <xenstore.h>
-#include <unistd.h>
+#include <xen-tools/libs.h>
 
 static xc_interface *xch;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1L-0000Xd-Co; Wed, 09 Sep 2020 11:12:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy1J-0000Wu-Mu
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:09 +0000
X-Inumbo-ID: 7243b50b-1d42-45d8-ab0c-22d030d91230
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7243b50b-1d42-45d8-ab0c-22d030d91230;
 Wed, 09 Sep 2020 11:12:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6Dfjcynkh6OJztvVoFyp6hK1vkBlY2S8rQ5Inq/9+cY=; b=NtOuldmlJQ7sXukOuaoXzFKEiM
 IxqJ5amzL73Jc7ZxilrH0ENiwOYCG7iwrG6Dy0iMQCPHjZ0kK1JEop4IaJ5W8Lj8gLwxxSMdPeeyn
 QgPTtojDcMrMcl6JJl3JQtCbDcGnAD/7Uj1T9NjdExG21yBw0RB8YZboa8zwYBvjuBaM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1I-00064w-T6
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1I-0001Pl-SB
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/misc: don't include xg_save_restore.h from
 xen-mfndump.c
Message-Id: <E1kFy1I-0001Pl-SB@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a547703b243767185d69731a922c5b77cf2b4a2b
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:23 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: don't include xg_save_restore.h from xen-mfndump.c
    
    xen-mfndump.c is including the libxc private header xg_save_restore.h.
    Avoid that by moving the definition of is_mapped() to xen-mfndump.c
    (it is used there only) and by duplicating the definition of
    M2P_SIZE() in xen-mfndump.c.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xg_save_restore.h | 4 ----
 tools/misc/xen-mfndump.c      | 5 ++++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index 303081df0d..b904296997 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -109,10 +109,6 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT)
 #define M2P_CHUNKS(_m)  (M2P_SIZE((_m)) >> M2P_SHIFT)
 
-/* Returns TRUE if the PFN is currently mapped */
-#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
-
-
 #define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
 
 #define SET_FIELD(_p, _f, _v, _w) do {          \
diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index 858bd0e26b..cb15d08c7e 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -5,7 +5,10 @@
 #include <unistd.h>
 #include <inttypes.h>
 
-#include "xg_save_restore.h"
+#include <xen-tools/libs.h>
+
+#define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)
+#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
 
 static xc_interface *xch;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:21 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:21 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1V-0000ZM-EV; Wed, 09 Sep 2020 11:12:21 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy1T-0000Z7-UW
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:19 +0000
X-Inumbo-ID: e6bb506d-22ca-4e31-84f2-893a91b4887d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e6bb506d-22ca-4e31-84f2-893a91b4887d;
 Wed, 09 Sep 2020 11:12:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=5vcj4XvKNrn6c76YpyOGNW7tsFKxOqDh/z/kxGqFg54=; b=yQi8Trlf9ync1T9G7DMzS3Xoc0
 SW2sS2ehX8KDtKxWHVwvYmr3JGOkQlrt5qBvYluVJS1iHdiKssmLWnjcXBh3JV6uUn/fzxjSSgfA5
 zMdS2C0XhoRsQgP9//ULkl8T+oGrSDgZ2l8qDxkrXCMD2K0U1kuwKl9CVUuLD9fXfRck=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1T-000657-0g
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1S-0001R0-Vy
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/misc: replace PAGE_SIZE with XC_PAGE_SIZE in
 xen-mfndump.c
Message-Id: <E1kFy1S-0001R0-Vy@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 790f2dfb598acb5f3f3f75b47c5e3ab642c16478
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:24 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: replace PAGE_SIZE with XC_PAGE_SIZE in xen-mfndump.c
    
    The definition of PAGE_SIZE comes from xc_private.h, which shouldn't be
    used by xen-mfndump.c. Replace PAGE_SIZE by XC_PAGE_SIZE, as
    xc_private.h contains:
    
    #define PAGE_SIZE XC_PAGE_SIZE
    
    For the same reason PAGE_SHIFT_X86 needs to replaced with
    XC_PAGE_SHIFT.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/xen-mfndump.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index cb15d08c7e..92bc954ce0 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -207,7 +207,7 @@ int dump_ptes_func(int argc, char *argv[])
         goto out;
     }
 
-    page = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+    page = xc_map_foreign_range(xch, domid, XC_PAGE_SIZE, PROT_READ,
                                 minfo.p2m_table[pfn]);
     if ( !page )
     {
@@ -216,7 +216,7 @@ int dump_ptes_func(int argc, char *argv[])
         goto out;
     }
 
-    pte_num = PAGE_SIZE / 8;
+    pte_num = XC_PAGE_SIZE / 8;
 
     printf(" --- Dumping %d PTEs for domain %d ---\n", pte_num, domid);
     printf(" Guest Width: %u, PT Levels: %u P2M size: = %lu\n",
@@ -252,7 +252,7 @@ int dump_ptes_func(int argc, char *argv[])
 
  out:
     if ( page )
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
     xc_unmap_domain_meminfo(xch, &minfo);
     munmap(m2p_table, M2P_SIZE(max_mfn));
     return rc;
@@ -290,7 +290,7 @@ int lookup_pte_func(int argc, char *argv[])
         return -1;
     }
 
-    pte_num = PAGE_SIZE / 8;
+    pte_num = XC_PAGE_SIZE / 8;
 
     printf(" --- Lookig for PTEs mapping mfn 0x%lx for domain %d ---\n",
            mfn, domid);
@@ -302,7 +302,7 @@ int lookup_pte_func(int argc, char *argv[])
         if ( !(minfo.pfn_type[i] & XEN_DOMCTL_PFINFO_LTABTYPE_MASK) )
             continue;
 
-        page = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+        page = xc_map_foreign_range(xch, domid, XC_PAGE_SIZE, PROT_READ,
                                     minfo.p2m_table[i]);
         if ( !page )
             continue;
@@ -312,15 +312,15 @@ int lookup_pte_func(int argc, char *argv[])
             uint64_t pte = ((const uint64_t*)page)[j];
 
 #define __MADDR_BITS_X86  ((minfo.guest_width == 8) ? 52 : 44)
-#define __MFN_MASK_X86    ((1ULL << (__MADDR_BITS_X86 - PAGE_SHIFT_X86)) - 1)
-            if ( ((pte >> PAGE_SHIFT_X86) & __MFN_MASK_X86) == mfn)
+#define __MFN_MASK_X86    ((1ULL << (__MADDR_BITS_X86 - XC_PAGE_SHIFT)) - 1)
+            if ( ((pte >> XC_PAGE_SHIFT) & __MFN_MASK_X86) == mfn)
                 printf("  0x%lx <-- [0x%lx][%lu]: 0x%"PRIx64"\n",
                        mfn, minfo.p2m_table[i], j, pte);
 #undef __MADDR_BITS_X86
 #undef __MFN_MASK_X8
         }
 
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
         page = NULL;
     }
 
@@ -355,8 +355,8 @@ int memcmp_mfns_func(int argc, char *argv[])
         return -1;
     }
 
-    page1 = xc_map_foreign_range(xch, domid1, PAGE_SIZE, PROT_READ, mfn1);
-    page2 = xc_map_foreign_range(xch, domid2, PAGE_SIZE, PROT_READ, mfn2);
+    page1 = xc_map_foreign_range(xch, domid1, XC_PAGE_SIZE, PROT_READ, mfn1);
+    page2 = xc_map_foreign_range(xch, domid2, XC_PAGE_SIZE, PROT_READ, mfn2);
     if ( !page1 || !page2 )
     {
         ERROR("Failed to map either 0x%lx[dom %d] or 0x%lx[dom %d]\n",
@@ -368,13 +368,13 @@ int memcmp_mfns_func(int argc, char *argv[])
     printf(" --- Comparing the content of 2 MFNs ---\n");
     printf(" 1: 0x%lx[dom %d], 2: 0x%lx[dom %d]\n",
            mfn1, domid1, mfn2, domid2);
-    printf("  memcpy(1, 2) = %d\n", memcmp(page1, page2, PAGE_SIZE));
+    printf("  memcpy(1, 2) = %d\n", memcmp(page1, page2, XC_PAGE_SIZE));
 
  out:
     if ( page1 )
-        munmap(page1, PAGE_SIZE);
+        munmap(page1, XC_PAGE_SIZE);
     if ( page2 )
-        munmap(page2, PAGE_SIZE);
+        munmap(page2, XC_PAGE_SIZE);
     return rc;
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:31 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1f-0000ce-Hi; Wed, 09 Sep 2020 11:12:31 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy1d-0000cM-VV
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:30 +0000
X-Inumbo-ID: 0ee8b168-2a13-42a8-99b5-d52e20f724ca
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 0ee8b168-2a13-42a8-99b5-d52e20f724ca;
 Wed, 09 Sep 2020 11:12:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=o9kj7ZCa3Oi3mOOUMJ8gf7evF69VI33gWlxYKrvNtPk=; b=krSRYLm1fqxTZZyaNeNlLdo5ZY
 tkc+Tj7GvKFCyxJhsdWMQ+nmRGSxzftTPKMxqsvSdqLMcyEs3cabDfPUu9RgSk5Qb3r3aYPtq0K74
 gD1c1ur699trAcT8UROZf5nF0bEGRPZSfzPdeFTJEDFIBGnEvRgi67j8aOUVU8UTnEZ0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1d-00065H-4z
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:29 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1d-0001Ri-3b
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/misc: drop all libxc internals from xen-mfndump.c
Message-Id: <E1kFy1d-0001Ri-3b@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 45397d49fa7f0f236b783df48713dbf5a68bf599
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:25 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: drop all libxc internals from xen-mfndump.c
    
    The last libxc internal used by xen-mfndump.c is the ERROR() macro.
    Add a simple definition for that macro to xen-mfndump.c and replace
    the libxc private header includes by official ones.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/Makefile      |  2 --
 tools/misc/xen-mfndump.c | 13 +++++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 2a7f2ec42d..7d37f297a9 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -99,8 +99,6 @@ xen-hptool: xen-hptool.o
 
 xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs)
 
-# xen-mfndump incorrectly uses libxc internals
-xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-mfndump: xen-mfndump.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index 92bc954ce0..62121bd241 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -1,15 +1,20 @@
-#define XC_WANT_COMPAT_MAP_FOREIGN_API
-#include <xenctrl.h>
-#include <xc_private.h>
-#include <xc_core.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
 #include <unistd.h>
 #include <inttypes.h>
 
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
+#include <xenguest.h>
+
 #include <xen-tools/libs.h>
 
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)
 #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
 
+#define ERROR(msg, args...) fprintf(stderr, msg, ## args)
+
 static xc_interface *xch;
 
 int help_func(int argc, char *argv[])
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:41 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1p-0000e8-JI; Wed, 09 Sep 2020 11:12:41 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy1o-0000dy-It
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:40 +0000
X-Inumbo-ID: 14752a36-0029-48b0-85d2-efe9fc9b6780
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 14752a36-0029-48b0-85d2-efe9fc9b6780;
 Wed, 09 Sep 2020 11:12:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PHJBbGgJURTQO/xQeUW1BUImfZHl7Cj95qMnmEDe+cs=; b=WR1+lQCo/3VdqRM1oYFjlWRZ8B
 B4Gx8uFzEt3mm/+fP0wrJpbK7YX+71VjXVljE2+1y5LNYXIkDjlQwijfMelv53X82iSBzxh8coxPb
 JTFebMpz9VF0r6EFsvSCbmtO9mWEgHYCM6ydtsr/35DkmkpdfDP0OHXwaiURESsqjrlI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1n-00065O-8c
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:39 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1n-0001SN-7k
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:39 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: remove unused headers xc_efi.h and xc_elf.h
Message-Id: <E1kFy1n-0001SN-7k@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:39 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6797d1ed45a4089a22f7278bb45cddb6fd861d72
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:26 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: remove unused headers xc_efi.h and xc_elf.h
    
    Remove xc_efi.h and xc_elf.h as they aren't used anywhere.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xc_efi.h | 158 ---------------------------------------------------
 tools/libxc/xc_elf.h |  16 ------
 2 files changed, 174 deletions(-)

diff --git a/tools/libxc/xc_efi.h b/tools/libxc/xc_efi.h
deleted file mode 100644
index dbe105be8f..0000000000
--- a/tools/libxc/xc_efi.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Extensible Firmware Interface
- * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) 1999 VA Linux Systems
- * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
- * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
- *      David Mosberger-Tang <davidm@hpl.hp.com>
- *      Stephane Eranian <eranian@hpl.hp.com>
- */
-
-#ifndef XC_EFI_H
-#define XC_EFI_H
-
-/* definitions from xen/include/asm-ia64/linux-xen/linux/efi.h */
-
-typedef struct {
-        uint8_t b[16];
-} efi_guid_t;
-
-#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
-  (b) & 0xff, ((b) >> 8) & 0xff, \
-  (c) & 0xff, ((c) >> 8) & 0xff, \
-  (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
-
-/*
- * Generic EFI table header
- */
-typedef struct {
-	uint64_t signature;
-	uint32_t revision;
-	uint32_t headersize;
-	uint32_t crc32;
-	uint32_t reserved;
-} efi_table_hdr_t;
-
-/*
- * Memory map descriptor:
- */
-
-/* Memory types: */
-#define EFI_RESERVED_TYPE                0
-#define EFI_LOADER_CODE                  1
-#define EFI_LOADER_DATA                  2
-#define EFI_BOOT_SERVICES_CODE           3
-#define EFI_BOOT_SERVICES_DATA           4
-#define EFI_RUNTIME_SERVICES_CODE        5
-#define EFI_RUNTIME_SERVICES_DATA        6
-#define EFI_CONVENTIONAL_MEMORY          7
-#define EFI_UNUSABLE_MEMORY              8
-#define EFI_ACPI_RECLAIM_MEMORY          9
-#define EFI_ACPI_MEMORY_NVS             10
-#define EFI_MEMORY_MAPPED_IO            11
-#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
-#define EFI_PAL_CODE                    13
-#define EFI_MAX_MEMORY_TYPE             14
-
-/* Attribute values: */
-#define EFI_MEMORY_UC           ((uint64_t)0x0000000000000001ULL)    /* uncached */
-#define EFI_MEMORY_WC           ((uint64_t)0x0000000000000002ULL)    /* write-coalescing */
-#define EFI_MEMORY_WT           ((uint64_t)0x0000000000000004ULL)    /* write-through */
-#define EFI_MEMORY_WB           ((uint64_t)0x0000000000000008ULL)    /* write-back */
-#define EFI_MEMORY_WP           ((uint64_t)0x0000000000001000ULL)    /* write-protect */
-#define EFI_MEMORY_RP           ((uint64_t)0x0000000000002000ULL)    /* read-protect */
-#define EFI_MEMORY_XP           ((uint64_t)0x0000000000004000ULL)    /* execute-protect */
-#define EFI_MEMORY_RUNTIME      ((uint64_t)0x8000000000000000ULL)    /* range requires runtime mapping */
-#define EFI_MEMORY_DESCRIPTOR_VERSION   1
-
-#define EFI_PAGE_SHIFT          12
-
-/*
- * For current x86 implementations of EFI, there is
- * additional padding in the mem descriptors.  This is not
- * the case in ia64.  Need to have this fixed in the f/w.
- */
-typedef struct {
-        uint32_t type;
-        uint32_t pad;
-        uint64_t phys_addr;
-        uint64_t virt_addr;
-        uint64_t num_pages;
-        uint64_t attribute;
-#if defined (__i386__)
-        uint64_t pad1;
-#endif
-} efi_memory_desc_t;
-
-/*
- * EFI Runtime Services table
- */
-#define EFI_RUNTIME_SERVICES_SIGNATURE	((uint64_t)0x5652453544e5552ULL)
-#define EFI_RUNTIME_SERVICES_REVISION	0x00010000
-
-typedef struct {
-	efi_table_hdr_t hdr;
-	unsigned long get_time;
-	unsigned long set_time;
-	unsigned long get_wakeup_time;
-	unsigned long set_wakeup_time;
-	unsigned long set_virtual_address_map;
-	unsigned long convert_pointer;
-	unsigned long get_variable;
-	unsigned long get_next_variable;
-	unsigned long set_variable;
-	unsigned long get_next_high_mono_count;
-	unsigned long reset_system;
-} efi_runtime_services_t;
-
-/*
- *  EFI Configuration Table and GUID definitions
- */
-#define NULL_GUID \
-    EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
-#define ACPI_20_TABLE_GUID    \
-    EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
-#define SAL_SYSTEM_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-typedef struct {
-	efi_guid_t guid;
-	unsigned long table;
-} efi_config_table_t;
-
-#define EFI_SYSTEM_TABLE_SIGNATURE ((uint64_t)0x5453595320494249ULL)
-#define EFI_SYSTEM_TABLE_REVISION  ((1 << 16) | 00)
-
-typedef struct {
-	efi_table_hdr_t hdr;
-	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
-	uint32_t fw_revision;
-	unsigned long con_in_handle;
-	unsigned long con_in;
-	unsigned long con_out_handle;
-	unsigned long con_out;
-	unsigned long stderr_handle;
-	unsigned long stderr;
-	efi_runtime_services_t *runtime;
-	unsigned long boottime;
-	unsigned long nr_tables;
-	unsigned long tables;
-} efi_system_table_t;
-
-#endif /* XC_EFI_H */
diff --git a/tools/libxc/xc_elf.h b/tools/libxc/xc_elf.h
deleted file mode 100644
index acbc0280bd..0000000000
--- a/tools/libxc/xc_elf.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <xen/libelf/elfstructs.h>
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:12:51 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:12:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy1z-0000fF-L1; Wed, 09 Sep 2020 11:12:51 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy1y-0000f3-KC
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:50 +0000
X-Inumbo-ID: cb79a5c9-d9ce-4117-9579-747979e4c3a2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cb79a5c9-d9ce-4117-9579-747979e4c3a2;
 Wed, 09 Sep 2020 11:12:49 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6CqniBh+Jwii4yzLFG3T7m13obp/q7ncAmEjSsDWibU=; b=Ul9i/iAYxMiwigKfls5m+TvZdc
 LYMv4N+3nokNUoJ6KZMF4YBuxJNoC4ZnUona2Fet+g0d1KIOob0/HgLNXNRoONqMhaf4Y02JOF7QG
 pyQALfUZEF1W9u2b0znYJ2x3uPCCSlZqzxe4JMkGIv1zjej9nm+16ialxOnhNmzk2pbk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1x-00065V-Ck
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:49 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy1x-0001Sw-Bb
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:49 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: move xc_[un]map_domain_meminfo() into new
 source xg_domain.c
Message-Id: <E1kFy1x-0001Sw-Bb@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:49 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 735749c8316d2f8b074e38138989336cfdec65f2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:27 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: move xc_[un]map_domain_meminfo() into new source xg_domain.c
    
    Move xc_[un]map_domain_meminfo() functions to new source xg_domain.c as
    they are defined in include/xenguest.h and should be in libxenguest.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile    |   4 +-
 tools/libxc/xc_domain.c | 126 ----------------------------------------
 tools/libxc/xg_domain.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 127 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 763231065c..7b81f8c193 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -52,7 +52,9 @@ CTRL_SRCS-y       += xc_gnttab_compat.c
 CTRL_SRCS-y       += xc_devicemodel_compat.c
 
 GUEST_SRCS-y :=
-GUEST_SRCS-y += xg_private.c xc_suspend.c
+GUEST_SRCS-y += xg_private.c
+GUEST_SRCS-y += xg_domain.c
+GUEST_SRCS-y += xc_suspend.c
 ifeq ($(CONFIG_MIGRATE),y)
 GUEST_SRCS-y += xc_sr_common.c
 GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 71829c2bce..fbc22c4df6 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -1892,132 +1892,6 @@ int xc_domain_unbind_pt_spi_irq(xc_interface *xch,
                                         PT_IRQ_TYPE_SPI, 0, 0, 0, 0, spi));
 }
 
-int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *minfo)
-{
-    struct domain_info_context _di = { .guest_width = minfo->guest_width,
-                                       .p2m_size = minfo->p2m_size};
-    struct domain_info_context *dinfo = &_di;
-
-    free(minfo->pfn_type);
-    if ( minfo->p2m_table )
-        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
-    minfo->p2m_table = NULL;
-
-    return 0;
-}
-
-int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
-                          struct xc_domain_meminfo *minfo)
-{
-    struct domain_info_context _di;
-    struct domain_info_context *dinfo = &_di;
-
-    xc_dominfo_t info;
-    shared_info_any_t *live_shinfo;
-    xen_capabilities_info_t xen_caps = "";
-    int i;
-
-    /* Only be initialized once */
-    if ( minfo->pfn_type || minfo->p2m_table )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
-    {
-        PERROR("Could not get domain info");
-        return -1;
-    }
-
-    if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) )
-    {
-        PERROR("Could not get domain address size");
-        return -1;
-    }
-    _di.guest_width = minfo->guest_width;
-
-    /* Get page table levels (see get_platform_info() in xg_save_restore.h */
-    if ( xc_version(xch, XENVER_capabilities, &xen_caps) )
-    {
-        PERROR("Could not get Xen capabilities (for page table levels)");
-        return -1;
-    }
-    if ( strstr(xen_caps, "xen-3.0-x86_64") )
-        /* Depends on whether it's a compat 32-on-64 guest */
-        minfo->pt_levels = ( (minfo->guest_width == 8) ? 4 : 3 );
-    else if ( strstr(xen_caps, "xen-3.0-x86_32p") )
-        minfo->pt_levels = 3;
-    else if ( strstr(xen_caps, "xen-3.0-x86_32") )
-        minfo->pt_levels = 2;
-    else
-    {
-        errno = EFAULT;
-        return -1;
-    }
-
-    /* We need the shared info page for mapping the P2M */
-    live_shinfo = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
-                                       info.shared_info_frame);
-    if ( !live_shinfo )
-    {
-        PERROR("Could not map the shared info frame (MFN 0x%lx)",
-               info.shared_info_frame);
-        return -1;
-    }
-
-    if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info,
-                                       live_shinfo, &minfo->p2m_table,
-                                       &minfo->p2m_size) )
-    {
-        PERROR("Could not map the P2M table");
-        munmap(live_shinfo, PAGE_SIZE);
-        return -1;
-    }
-    munmap(live_shinfo, PAGE_SIZE);
-    _di.p2m_size = minfo->p2m_size;
-
-    /* Make space and prepare for getting the PFN types */
-    minfo->pfn_type = calloc(sizeof(*minfo->pfn_type), minfo->p2m_size);
-    if ( !minfo->pfn_type )
-    {
-        PERROR("Could not allocate memory for the PFN types");
-        goto failed;
-    }
-    for ( i = 0; i < minfo->p2m_size; i++ )
-        minfo->pfn_type[i] = xc_pfn_to_mfn(i, minfo->p2m_table,
-                                           minfo->guest_width);
-
-    /* Retrieve PFN types in batches */
-    for ( i = 0; i < minfo->p2m_size ; i+=1024 )
-    {
-        int count = ((minfo->p2m_size - i ) > 1024 ) ?
-                        1024: (minfo->p2m_size - i);
-
-        if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i) )
-        {
-            PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024);
-            goto failed;
-        }
-    }
-
-    return 0;
-
-failed:
-    if ( minfo->pfn_type )
-    {
-        free(minfo->pfn_type);
-        minfo->pfn_type = NULL;
-    }
-    if ( minfo->p2m_table )
-    {
-        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
-        minfo->p2m_table = NULL;
-    }
-
-    return -1;
-}
-
 int xc_domain_memory_mapping(
     xc_interface *xch,
     uint32_t domid,
diff --git a/tools/libxc/xg_domain.c b/tools/libxc/xg_domain.c
new file mode 100644
index 0000000000..58713cd35d
--- /dev/null
+++ b/tools/libxc/xg_domain.c
@@ -0,0 +1,149 @@
+/******************************************************************************
+ * xg_domain.c
+ *
+ * API for manipulating and obtaining information on domains.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2003, K A Fraser.
+ */
+
+#include "xg_private.h"
+#include "xc_core.h"
+
+int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *minfo)
+{
+    struct domain_info_context _di = { .guest_width = minfo->guest_width,
+                                       .p2m_size = minfo->p2m_size};
+    struct domain_info_context *dinfo = &_di;
+
+    free(minfo->pfn_type);
+    if ( minfo->p2m_table )
+        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
+    minfo->p2m_table = NULL;
+
+    return 0;
+}
+
+int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
+                          struct xc_domain_meminfo *minfo)
+{
+    struct domain_info_context _di;
+    struct domain_info_context *dinfo = &_di;
+
+    xc_dominfo_t info;
+    shared_info_any_t *live_shinfo;
+    xen_capabilities_info_t xen_caps = "";
+    int i;
+
+    /* Only be initialized once */
+    if ( minfo->pfn_type || minfo->p2m_table )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
+    {
+        PERROR("Could not get domain info");
+        return -1;
+    }
+
+    if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) )
+    {
+        PERROR("Could not get domain address size");
+        return -1;
+    }
+    _di.guest_width = minfo->guest_width;
+
+    /* Get page table levels (see get_platform_info() in xg_save_restore.h */
+    if ( xc_version(xch, XENVER_capabilities, &xen_caps) )
+    {
+        PERROR("Could not get Xen capabilities (for page table levels)");
+        return -1;
+    }
+    if ( strstr(xen_caps, "xen-3.0-x86_64") )
+        /* Depends on whether it's a compat 32-on-64 guest */
+        minfo->pt_levels = ( (minfo->guest_width == 8) ? 4 : 3 );
+    else if ( strstr(xen_caps, "xen-3.0-x86_32p") )
+        minfo->pt_levels = 3;
+    else if ( strstr(xen_caps, "xen-3.0-x86_32") )
+        minfo->pt_levels = 2;
+    else
+    {
+        errno = EFAULT;
+        return -1;
+    }
+
+    /* We need the shared info page for mapping the P2M */
+    live_shinfo = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+                                       info.shared_info_frame);
+    if ( !live_shinfo )
+    {
+        PERROR("Could not map the shared info frame (MFN 0x%lx)",
+               info.shared_info_frame);
+        return -1;
+    }
+
+    if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info,
+                                       live_shinfo, &minfo->p2m_table,
+                                       &minfo->p2m_size) )
+    {
+        PERROR("Could not map the P2M table");
+        munmap(live_shinfo, PAGE_SIZE);
+        return -1;
+    }
+    munmap(live_shinfo, PAGE_SIZE);
+    _di.p2m_size = minfo->p2m_size;
+
+    /* Make space and prepare for getting the PFN types */
+    minfo->pfn_type = calloc(sizeof(*minfo->pfn_type), minfo->p2m_size);
+    if ( !minfo->pfn_type )
+    {
+        PERROR("Could not allocate memory for the PFN types");
+        goto failed;
+    }
+    for ( i = 0; i < minfo->p2m_size; i++ )
+        minfo->pfn_type[i] = xc_pfn_to_mfn(i, minfo->p2m_table,
+                                           minfo->guest_width);
+
+    /* Retrieve PFN types in batches */
+    for ( i = 0; i < minfo->p2m_size ; i+=1024 )
+    {
+        int count = ((minfo->p2m_size - i ) > 1024 ) ?
+                        1024: (minfo->p2m_size - i);
+
+        if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i) )
+        {
+            PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024);
+            goto failed;
+        }
+    }
+
+    return 0;
+
+failed:
+    if ( minfo->pfn_type )
+    {
+        free(minfo->pfn_type);
+        minfo->pfn_type = NULL;
+    }
+    if ( minfo->p2m_table )
+    {
+        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
+        minfo->p2m_table = NULL;
+    }
+
+    return -1;
+}
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:06 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2E-0000gX-N1; Wed, 09 Sep 2020 11:13:06 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2C-0000gP-VG
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:05 +0000
X-Inumbo-ID: c2f08dce-edd1-41c4-9cec-65bd29b4899e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c2f08dce-edd1-41c4-9cec-65bd29b4899e;
 Wed, 09 Sep 2020 11:12:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DGBImIYWD3IDq/8g1lVP/NpmFSxn6Li4OKxcPtGgSIY=; b=wPxOxcV5+39Q+uIb0Fo/cnfj1f
 Q6Wk2Ay2p8YsZg43RL3hHFMNLXO44+N0mIORw4blQUzD+I4eCPlZ8Ot2CX8ouRLvJnb+DsFaCzZui
 V76I5bCfQYY1icxO5T7TfrX59NBXT9CDW4i1o/H49MdzJUwOw+7GyHVxgGRTibcgCrbA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy27-000663-He
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:59 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy27-0001TY-Gi
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:12:59 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: rename all libxenguest sources to xg_*
Message-Id: <E1kFy27-0001TY-Gi@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:12:59 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f55893171feb64f712d2892a288e3f3dc70f39d8
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:28 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: rename all libxenguest sources to xg_*
    
    Some sources of libxenguest are named xg_*.c and some xc_*.c. Rename
    the xc_*.c files to xg_*.c.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile                         |   59 +-
 tools/libxc/xc_cpuid_x86.c                   |  665 ---------
 tools/libxc/xc_dom_arm.c                     |  552 --------
 tools/libxc/xc_dom_armzimageloader.c         |  271 ----
 tools/libxc/xc_dom_binloader.c               |  329 -----
 tools/libxc/xc_dom_boot.c                    |  451 ------
 tools/libxc/xc_dom_bzimageloader.c           |  812 -----------
 tools/libxc/xc_dom_compat_linux.c            |   97 --
 tools/libxc/xc_dom_core.c                    | 1272 -----------------
 tools/libxc/xc_dom_decompress_lz4.c          |  141 --
 tools/libxc/xc_dom_decompress_unsafe.c       |   48 -
 tools/libxc/xc_dom_decompress_unsafe_bzip2.c |   14 -
 tools/libxc/xc_dom_decompress_unsafe_lzma.c  |   14 -
 tools/libxc/xc_dom_decompress_unsafe_lzo1x.c |   50 -
 tools/libxc/xc_dom_decompress_unsafe_xz.c    |   46 -
 tools/libxc/xc_dom_elfloader.c               |  249 ----
 tools/libxc/xc_dom_hvmloader.c               |  264 ----
 tools/libxc/xc_dom_x86.c                     | 1945 --------------------------
 tools/libxc/xc_nomigrate.c                   |   50 -
 tools/libxc/xc_offline_page.c                |  708 ----------
 tools/libxc/xc_sr_common.c                   |  167 ---
 tools/libxc/xc_sr_common_x86.c               |  173 ---
 tools/libxc/xc_sr_common_x86_pv.c            |  193 ---
 tools/libxc/xc_sr_restore.c                  |  986 -------------
 tools/libxc/xc_sr_restore_x86_hvm.c          |  274 ----
 tools/libxc/xc_sr_restore_x86_pv.c           | 1210 ----------------
 tools/libxc/xc_sr_save.c                     | 1059 --------------
 tools/libxc/xc_sr_save_x86_hvm.c             |  251 ----
 tools/libxc/xc_sr_save_x86_pv.c              | 1156 ---------------
 tools/libxc/xc_suspend.c                     |  202 ---
 tools/libxc/xg_cpuid_x86.c                   |  665 +++++++++
 tools/libxc/xg_dom_arm.c                     |  552 ++++++++
 tools/libxc/xg_dom_armzimageloader.c         |  271 ++++
 tools/libxc/xg_dom_binloader.c               |  329 +++++
 tools/libxc/xg_dom_boot.c                    |  451 ++++++
 tools/libxc/xg_dom_bzimageloader.c           |  812 +++++++++++
 tools/libxc/xg_dom_compat_linux.c            |   97 ++
 tools/libxc/xg_dom_core.c                    | 1272 +++++++++++++++++
 tools/libxc/xg_dom_decompress_lz4.c          |  141 ++
 tools/libxc/xg_dom_decompress_unsafe.c       |   48 +
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c |   14 +
 tools/libxc/xg_dom_decompress_unsafe_lzma.c  |   14 +
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c |   50 +
 tools/libxc/xg_dom_decompress_unsafe_xz.c    |   46 +
 tools/libxc/xg_dom_elfloader.c               |  249 ++++
 tools/libxc/xg_dom_hvmloader.c               |  264 ++++
 tools/libxc/xg_dom_x86.c                     | 1945 ++++++++++++++++++++++++++
 tools/libxc/xg_nomigrate.c                   |   50 +
 tools/libxc/xg_offline_page.c                |  708 ++++++++++
 tools/libxc/xg_sr_common.c                   |  167 +++
 tools/libxc/xg_sr_common_x86.c               |  173 +++
 tools/libxc/xg_sr_common_x86_pv.c            |  193 +++
 tools/libxc/xg_sr_restore.c                  |  986 +++++++++++++
 tools/libxc/xg_sr_restore_x86_hvm.c          |  274 ++++
 tools/libxc/xg_sr_restore_x86_pv.c           | 1210 ++++++++++++++++
 tools/libxc/xg_sr_save.c                     | 1059 ++++++++++++++
 tools/libxc/xg_sr_save_x86_hvm.c             |  251 ++++
 tools/libxc/xg_sr_save_x86_pv.c              | 1156 +++++++++++++++
 tools/libxc/xg_suspend.c                     |  202 +++
 59 files changed, 13679 insertions(+), 13678 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 7b81f8c193..0fd5511143 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -54,20 +54,20 @@ CTRL_SRCS-y       += xc_devicemodel_compat.c
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c
 GUEST_SRCS-y += xg_domain.c
-GUEST_SRCS-y += xc_suspend.c
+GUEST_SRCS-y += xg_suspend.c
 ifeq ($(CONFIG_MIGRATE),y)
-GUEST_SRCS-y += xc_sr_common.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_hvm.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c
-GUEST_SRCS-y += xc_sr_restore.c
-GUEST_SRCS-y += xc_sr_save.c
-GUEST_SRCS-y += xc_offline_page.c
+GUEST_SRCS-y += xg_sr_common.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_common_x86.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_common_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_restore_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_restore_x86_hvm.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_save_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_save_x86_hvm.c
+GUEST_SRCS-y += xg_sr_restore.c
+GUEST_SRCS-y += xg_sr_save.c
+GUEST_SRCS-y += xg_offline_page.c
 else
-GUEST_SRCS-y += xc_nomigrate.c
+GUEST_SRCS-y += xg_nomigrate.c
 endif
 
 vpath %.c ../../xen/common/libelf
@@ -88,25 +88,26 @@ GUEST_SRCS-y                 += cpuid.c msr.c
 endif
 
 # new domain builder
-GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
-GUEST_SRCS-y                 += xc_dom_elfloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_decompress_lz4.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_hvmloader.c
-GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_armzimageloader.c
-GUEST_SRCS-y                 += xc_dom_binloader.c
-GUEST_SRCS-y                 += xc_dom_compat_linux.c
-
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_cpuid_x86.c
-GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_arm.c
+GUEST_SRCS-y                 += xg_dom_core.c
+GUEST_SRCS-y                 += xg_dom_boot.c
+GUEST_SRCS-y                 += xg_dom_elfloader.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_bzimageloader.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_decompress_lz4.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_hvmloader.c
+GUEST_SRCS-$(CONFIG_ARM)     += xg_dom_armzimageloader.c
+GUEST_SRCS-y                 += xg_dom_binloader.c
+GUEST_SRCS-y                 += xg_dom_compat_linux.c
+
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_x86.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_cpuid_x86.c
+GUEST_SRCS-$(CONFIG_ARM)     += xg_dom_arm.c
 
 ifeq ($(CONFIG_LIBXC_MINIOS),y)
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_bzip2.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzma.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzo1x.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_xz.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_bzip2.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_lzma.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_lzo1x.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_xz.c
 endif
 
 -include $(XEN_TARGET_ARCH)/Makefile
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
deleted file mode 100644
index 0f24d6dd08..0000000000
--- a/tools/libxc/xc_cpuid_x86.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/******************************************************************************
- * xc_cpuid_x86.c
- *
- * Compute cpuid of a domain.
- *
- * Copyright (c) 2008, Citrix Systems, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <limits.h>
-#include "xc_private.h"
-#include "xc_bitops.h"
-#include <xen/hvm/params.h>
-#include <xen-tools/libs.h>
-
-enum {
-#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
-#include <xen/arch-x86/cpufeatureset.h>
-};
-
-#include <xen/asm/x86-vendors.h>
-
-#include <xen/lib/x86/cpu-policy.h>
-
-#define bitmaskof(idx)      (1u << ((idx) & 31))
-#define featureword_of(idx) ((idx) >> 5)
-
-int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps)
-{
-    DECLARE_SYSCTL;
-    int ret;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_levelling_caps;
-    ret = do_sysctl(xch, &sysctl);
-
-    if ( !ret )
-        *caps = sysctl.u.cpu_levelling_caps.caps;
-
-    return ret;
-}
-
-int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
-                          uint32_t *nr_features, uint32_t *featureset)
-{
-    DECLARE_SYSCTL;
-    DECLARE_HYPERCALL_BOUNCE(featureset,
-                             *nr_features * sizeof(*featureset),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, featureset) )
-        return -1;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_featureset;
-    sysctl.u.cpu_featureset.index = index;
-    sysctl.u.cpu_featureset.nr_features = *nr_features;
-    set_xen_guest_handle(sysctl.u.cpu_featureset.features, featureset);
-
-    ret = do_sysctl(xch, &sysctl);
-
-    xc_hypercall_bounce_post(xch, featureset);
-
-    if ( !ret )
-        *nr_features = sysctl.u.cpu_featureset.nr_features;
-
-    return ret;
-}
-
-uint32_t xc_get_cpu_featureset_size(void)
-{
-    return FEATURESET_NR_ENTRIES;
-}
-
-const uint32_t *xc_get_static_cpu_featuremask(
-    enum xc_static_cpu_featuremask mask)
-{
-    static const uint32_t masks[][FEATURESET_NR_ENTRIES] = {
-#define MASK(x) [XC_FEATUREMASK_ ## x] = INIT_ ## x ## _FEATURES
-
-        MASK(KNOWN),
-        MASK(SPECIAL),
-        MASK(PV_MAX),
-        MASK(PV_DEF),
-        MASK(HVM_SHADOW_MAX),
-        MASK(HVM_SHADOW_DEF),
-        MASK(HVM_HAP_MAX),
-        MASK(HVM_HAP_DEF),
-
-#undef MASK
-    };
-
-    if ( (unsigned int)mask >= ARRAY_SIZE(masks) )
-        return NULL;
-
-    return masks[mask];
-}
-
-int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
-                           uint32_t *nr_msrs)
-{
-    struct xen_sysctl sysctl = {};
-    int ret;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
-
-    ret = do_sysctl(xch, &sysctl);
-
-    if ( !ret )
-    {
-        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
-                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
-{
-    struct xen_sysctl sysctl = {};
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) ||
-         xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
-    sysctl.u.cpu_policy.index = index;
-    sysctl.u.cpu_policy.nr_leaves = *nr_leaves;
-    set_xen_guest_handle(sysctl.u.cpu_policy.cpuid_policy, leaves);
-    sysctl.u.cpu_policy.nr_msrs = *nr_msrs;
-    set_xen_guest_handle(sysctl.u.cpu_policy.msr_policy, msrs);
-
-    ret = do_sysctl(xch, &sysctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( !ret )
-    {
-        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
-                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
-{
-    DECLARE_DOMCTL;
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) ||
-         xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    domctl.cmd = XEN_DOMCTL_get_cpu_policy;
-    domctl.domain = domid;
-    domctl.u.cpu_policy.nr_leaves = *nr_leaves;
-    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
-    domctl.u.cpu_policy.nr_msrs = *nr_msrs;
-    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
-
-    ret = do_domctl(xch, &domctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( !ret )
-    {
-        *nr_leaves = domctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = domctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
-                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
-                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
-                             uint32_t *err_msr_p)
-{
-    DECLARE_DOMCTL;
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
-    int ret;
-
-    if ( err_leaf_p )
-        *err_leaf_p = -1;
-    if ( err_subleaf_p )
-        *err_subleaf_p = -1;
-    if ( err_msr_p )
-        *err_msr_p = -1;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) )
-        return -1;
-
-    if ( xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    domctl.cmd = XEN_DOMCTL_set_cpu_policy;
-    domctl.domain = domid;
-    domctl.u.cpu_policy.nr_leaves = nr_leaves;
-    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
-    domctl.u.cpu_policy.nr_msrs = nr_msrs;
-    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
-    domctl.u.cpu_policy.err_leaf = -1;
-    domctl.u.cpu_policy.err_subleaf = -1;
-    domctl.u.cpu_policy.err_msr = -1;
-
-    ret = do_domctl(xch, &domctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( err_leaf_p )
-        *err_leaf_p = domctl.u.cpu_policy.err_leaf;
-    if ( err_subleaf_p )
-        *err_subleaf_p = domctl.u.cpu_policy.err_subleaf;
-    if ( err_msr_p )
-        *err_msr_p = domctl.u.cpu_policy.err_msr;
-
-    return ret;
-}
-
-static int compare_leaves(const void *l, const void *r)
-{
-    const xen_cpuid_leaf_t *lhs = l;
-    const xen_cpuid_leaf_t *rhs = r;
-
-    if ( lhs->leaf != rhs->leaf )
-        return lhs->leaf < rhs->leaf ? -1 : 1;
-
-    if ( lhs->subleaf != rhs->subleaf )
-        return lhs->subleaf < rhs->subleaf ? -1 : 1;
-
-    return 0;
-}
-
-static xen_cpuid_leaf_t *find_leaf(
-    xen_cpuid_leaf_t *leaves, unsigned int nr_leaves,
-    const struct xc_xend_cpuid *xend)
-{
-    const xen_cpuid_leaf_t key = { xend->leaf, xend->subleaf };
-
-    return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves);
-}
-
-static int xc_cpuid_xend_policy(
-    xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend)
-{
-    int rc;
-    xc_dominfo_t di;
-    unsigned int nr_leaves, nr_msrs;
-    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
-    /*
-     * Three full policies.  The host, domain max, and domain current for the
-     * domain type.
-     */
-    xen_cpuid_leaf_t *host = NULL, *max = NULL, *cur = NULL;
-    unsigned int nr_host, nr_max, nr_cur;
-
-    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
-         di.domid != domid )
-    {
-        ERROR("Failed to obtain d%d info", domid);
-        rc = -ESRCH;
-        goto fail;
-    }
-
-    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
-    if ( rc )
-    {
-        PERROR("Failed to obtain policy info size");
-        rc = -errno;
-        goto fail;
-    }
-
-    rc = -ENOMEM;
-    if ( (host = calloc(nr_leaves, sizeof(*host))) == NULL ||
-         (max  = calloc(nr_leaves, sizeof(*max)))  == NULL ||
-         (cur  = calloc(nr_leaves, sizeof(*cur)))  == NULL )
-    {
-        ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves);
-        goto fail;
-    }
-
-    /* Get the domain's current policy. */
-    nr_msrs = 0;
-    nr_cur = nr_leaves;
-    rc = xc_get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain d%d current policy", domid);
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Get the domain's max policy. */
-    nr_msrs = 0;
-    nr_max = nr_leaves;
-    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max
-                                              : XEN_SYSCTL_cpu_policy_pv_max,
-                                  &nr_max, max, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv");
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Get the host policy. */
-    nr_msrs = 0;
-    nr_host = nr_leaves;
-    rc = xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host,
-                                  &nr_host, host, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain host policy");
-        rc = -errno;
-        goto fail;
-    }
-
-    rc = -EINVAL;
-    for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend )
-    {
-        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend);
-        const xen_cpuid_leaf_t *max_leaf = find_leaf(max, nr_max, xend);
-        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend);
-
-        if ( cur_leaf == NULL || max_leaf == NULL || host_leaf == NULL )
-        {
-            ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->subleaf);
-            goto fail;
-        }
-
-        for ( unsigned int i = 0; i < ARRAY_SIZE(xend->policy); i++ )
-        {
-            uint32_t *cur_reg = &cur_leaf->a + i;
-            const uint32_t *max_reg = &max_leaf->a + i;
-            const uint32_t *host_reg = &host_leaf->a + i;
-
-            if ( xend->policy[i] == NULL )
-                continue;
-
-            for ( unsigned int j = 0; j < 32; j++ )
-            {
-                bool val;
-
-                if ( xend->policy[i][j] == '1' )
-                    val = true;
-                else if ( xend->policy[i][j] == '0' )
-                    val = false;
-                else if ( xend->policy[i][j] == 'x' )
-                    val = test_bit(31 - j, max_reg);
-                else if ( xend->policy[i][j] == 'k' ||
-                          xend->policy[i][j] == 's' )
-                    val = test_bit(31 - j, host_reg);
-                else
-                {
-                    ERROR("Bad character '%c' in policy[%d] string '%s'",
-                          xend->policy[i][j], i, xend->policy[i]);
-                    goto fail;
-                }
-
-                clear_bit(31 - j, cur_reg);
-                if ( val )
-                    set_bit(31 - j, cur_reg);
-            }
-        }
-    }
-
-    /* Feed the transformed currrent policy back up to Xen. */
-    rc = xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL,
-                                  &err_leaf, &err_subleaf, &err_msr);
-    if ( rc )
-    {
-        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
-               domid, err_leaf, err_subleaf, err_msr);
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Success! */
-
- fail:
-    free(cur);
-    free(max);
-    free(host);
-
-    return rc;
-}
-
-int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
-                          const uint32_t *featureset, unsigned int nr_features,
-                          bool pae,
-                          const struct xc_xend_cpuid *xend)
-{
-    int rc;
-    xc_dominfo_t di;
-    unsigned int i, nr_leaves, nr_msrs;
-    xen_cpuid_leaf_t *leaves = NULL;
-    struct cpuid_policy *p = NULL;
-    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
-    uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {};
-    uint32_t len = ARRAY_SIZE(host_featureset);
-
-    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
-         di.domid != domid )
-    {
-        ERROR("Failed to obtain d%d info", domid);
-        rc = -ESRCH;
-        goto out;
-    }
-
-    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
-    if ( rc )
-    {
-        PERROR("Failed to obtain policy info size");
-        rc = -errno;
-        goto out;
-    }
-
-    rc = -ENOMEM;
-    if ( (leaves = calloc(nr_leaves, sizeof(*leaves))) == NULL ||
-         (p = calloc(1, sizeof(*p))) == NULL )
-        goto out;
-
-    /* Get the host policy. */
-    rc = xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host,
-                               &len, host_featureset);
-    if ( rc )
-    {
-        /* Tolerate "buffer too small", as we've got the bits we need. */
-        if ( errno == ENOBUFS )
-            rc = 0;
-        else
-        {
-            PERROR("Failed to obtain host featureset");
-            rc = -errno;
-            goto out;
-        }
-    }
-
-    /* Get the domain's default policy. */
-    nr_msrs = 0;
-    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default
-                                              : XEN_SYSCTL_cpu_policy_pv_default,
-                                  &nr_leaves, leaves, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv");
-        rc = -errno;
-        goto out;
-    }
-
-    rc = x86_cpuid_copy_from_buffer(p, leaves, nr_leaves,
-                                    &err_leaf, &err_subleaf);
-    if ( rc )
-    {
-        ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)",
-              err_leaf, err_subleaf, -rc, strerror(-rc));
-        goto out;
-    }
-
-    /*
-     * Account for feature which have been disabled by default since Xen 4.13,
-     * so migrated-in VM's don't risk seeing features disappearing.
-     */
-    if ( restore )
-    {
-        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
-
-        if ( di.hvm )
-        {
-            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
-        }
-    }
-
-    if ( featureset )
-    {
-        uint32_t disabled_features[FEATURESET_NR_ENTRIES],
-            feat[FEATURESET_NR_ENTRIES] = {};
-        static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
-        unsigned int i, b;
-
-        /*
-         * The user supplied featureset may be shorter or longer than
-         * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
-         * Longer is fine, so long as it only padded with zeros.
-         */
-        unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
-
-        /* Check for truncated set bits. */
-        rc = -EOPNOTSUPP;
-        for ( i = user_len; i < nr_features; ++i )
-            if ( featureset[i] != 0 )
-                goto out;
-
-        memcpy(feat, featureset, sizeof(*featureset) * user_len);
-
-        /* Disable deep dependencies of disabled features. */
-        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            disabled_features[i] = ~feat[i] & deep_features[i];
-
-        for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
-        {
-            const uint32_t *dfs;
-
-            if ( !test_bit(b, disabled_features) ||
-                 !(dfs = x86_cpuid_lookup_deep_deps(b)) )
-                continue;
-
-            for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            {
-                feat[i] &= ~dfs[i];
-                disabled_features[i] &= ~dfs[i];
-            }
-        }
-
-        cpuid_featureset_to_policy(feat, p);
-    }
-    else
-    {
-        if ( di.hvm )
-            p->basic.pae = pae;
-    }
-
-    if ( !di.hvm )
-    {
-        /*
-         * On hardware without CPUID Faulting, PV guests see real topology.
-         * As a consequence, they also need to see the host htt/cmp fields.
-         */
-        p->basic.htt       = test_bit(X86_FEATURE_HTT, host_featureset);
-        p->extd.cmp_legacy = test_bit(X86_FEATURE_CMP_LEGACY, host_featureset);
-    }
-    else
-    {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
-        p->extd.cmp_legacy = false;
-
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-
-        switch ( p->x86_vendor )
-        {
-        case X86_VENDOR_INTEL:
-            for ( i = 0; (p->cache.subleaf[i].type &&
-                          i < ARRAY_SIZE(p->cache.raw)); ++i )
-            {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
-                p->cache.subleaf[i].threads_per_cache = 0;
-            }
-            break;
-
-        case X86_VENDOR_AMD:
-        case X86_VENDOR_HYGON:
-            /*
-             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
-             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
-             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
-             * - overflow,
-             * - going out of sync with leaf 1 EBX[23:16],
-             * - incrementing ApicIdCoreSize when it's zero (which changes the
-             *   meaning of bits 7:0).
-             *
-             * UPDATE: I addition to avoiding overflow, some
-             * proprietary operating systems have trouble with
-             * apic_id_size values greater than 7.  Limit the value to
-             * 7 for now.
-             */
-            if ( p->extd.nc < 0x7f )
-            {
-                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size < 0x7 )
-                    p->extd.apic_id_size++;
-
-                p->extd.nc = (p->extd.nc << 1) | 1;
-            }
-            break;
-        }
-
-        /*
-         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
-         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
-         * CPUID.  Xen will discard these bits if configuration hasn't been
-         * set for the domain.
-         */
-        p->extd.itsc = true;
-        p->basic.vmx = true;
-        p->extd.svm = true;
-    }
-
-    rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
-    if ( rc )
-    {
-        ERROR("Failed to serialise CPUID (%d = %s)", -rc, strerror(-rc));
-        goto out;
-    }
-
-    rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL,
-                                  &err_leaf, &err_subleaf, &err_msr);
-    if ( rc )
-    {
-        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
-               domid, err_leaf, err_subleaf, err_msr);
-        rc = -errno;
-        goto out;
-    }
-
-    if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) )
-        goto out;
-
-    rc = 0;
-
-out:
-    free(p);
-    free(leaves);
-
-    return rc;
-}
diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
deleted file mode 100644
index 931404c222..0000000000
--- a/tools/libxc/xc_dom_arm.c
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Xen domain builder -- ARM
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (c) 2011, Citrix Systems
- */
-#include <inttypes.h>
-#include <assert.h>
-
-#include <xen/xen.h>
-#include <xen/io/protocols.h>
-#include <xen-tools/libs.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#define NR_MAGIC_PAGES 4
-#define CONSOLE_PFN_OFFSET 0
-#define XENSTORE_PFN_OFFSET 1
-#define MEMACCESS_PFN_OFFSET 2
-#define VUART_PFN_OFFSET 3
-
-#define LPAE_SHIFT 9
-
-#define PFN_4K_SHIFT  (0)
-#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
-#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
-#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
-
-/* get guest IO ABI protocol */
-const char *xc_domain_get_native_protocol(xc_interface *xch,
-                                          uint32_t domid)
-{
-    return XEN_IO_PROTO_ABI_ARM;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int alloc_magic_pages(struct xc_dom_image *dom)
-{
-    int rc, i;
-    const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
-    xen_pfn_t p2m[NR_MAGIC_PAGES];
-
-    BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    for (i = 0; i < NR_MAGIC_PAGES; i++)
-        p2m[i] = base + i;
-
-    rc = xc_domain_populate_physmap_exact(
-            dom->xch, dom->guest_domid, NR_MAGIC_PAGES,
-            0, 0, p2m);
-    if ( rc < 0 )
-        return rc;
-
-    dom->console_pfn = base + CONSOLE_PFN_OFFSET;
-    dom->xenstore_pfn = base + XENSTORE_PFN_OFFSET;
-    dom->vuart_gfn = base + VUART_PFN_OFFSET;
-
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, base + MEMACCESS_PFN_OFFSET);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->vuart_gfn);
-
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
-            dom->console_pfn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
-            dom->xenstore_pfn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MONITOR_RING_PFN,
-            base + MEMACCESS_PFN_OFFSET);
-    /* allocated by toolstack */
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN,
-            dom->console_evtchn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN,
-            dom->xenstore_evtchn);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int start_info_arm(struct xc_dom_image *dom)
-{
-    DOMPRINTF_CALLED(dom->xch);
-    return 0;
-}
-
-static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
-{
-    DOMPRINTF_CALLED(dom->xch);
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int vcpu_arm32(struct xc_dom_image *dom)
-{
-    vcpu_guest_context_any_t any_ctx;
-    vcpu_guest_context_t *ctxt = &any_ctx.c;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    /* clear everything */
-    memset(ctxt, 0, sizeof(*ctxt));
-
-    ctxt->user_regs.pc32 = dom->parms.virt_entry;
-
-    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
-    ctxt->user_regs.r0_usr = 0; /* SBZ */
-    /* Machine ID: We use DTB therefore no machine id */
-    ctxt->user_regs.r1_usr = 0xffffffff;
-    /* ATAGS/DTB: We currently require that the guest kernel to be
-     * using CONFIG_ARM_APPENDED_DTB. Ensure that r2 does not look
-     * like a valid pointer to a set of ATAGS or a DTB.
-     */
-    ctxt->user_regs.r2_usr = dom->devicetree_blob ?
-        dom->devicetree_seg.vstart : 0xffffffff;
-
-    ctxt->sctlr = SCTLR_GUEST_INIT;
-
-    ctxt->ttbr0 = 0;
-    ctxt->ttbr1 = 0;
-    ctxt->ttbcr = 0; /* Defined Reset Value */
-
-    ctxt->user_regs.cpsr = PSR_GUEST32_INIT;
-
-    ctxt->flags = VGCF_online;
-
-    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx32,
-           ctxt->user_regs.cpsr, ctxt->user_regs.pc32);
-
-    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
-
-    return rc;
-}
-
-static int vcpu_arm64(struct xc_dom_image *dom)
-{
-    vcpu_guest_context_any_t any_ctx;
-    vcpu_guest_context_t *ctxt = &any_ctx.c;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-    /* clear everything */
-    memset(ctxt, 0, sizeof(*ctxt));
-
-    ctxt->user_regs.pc64 = dom->parms.virt_entry;
-
-    /* Linux boot protocol. See linux.Documentation/arm64/booting.txt. */
-    ctxt->user_regs.x0 = dom->devicetree_blob ?
-        dom->devicetree_seg.vstart : 0xffffffff;
-    ctxt->user_regs.x1 = 0;
-    ctxt->user_regs.x2 = 0;
-    ctxt->user_regs.x3 = 0;
-
-    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
-
-    ctxt->sctlr = SCTLR_GUEST_INIT;
-
-    ctxt->ttbr0 = 0;
-    ctxt->ttbr1 = 0;
-    ctxt->ttbcr = 0; /* Defined Reset Value */
-
-    ctxt->user_regs.cpsr = PSR_GUEST64_INIT;
-
-    ctxt->flags = VGCF_online;
-
-    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
-           ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
-
-    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
-
-    return rc;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int set_mode(xc_interface *xch, uint32_t domid, char *guest_type)
-{
-    static const struct {
-        char           *guest;
-        uint32_t        size;
-    } types[] = {
-        { "xen-3.0-aarch64", 64 },
-        { "xen-3.0-armv7l",  32 },
-    };
-    DECLARE_DOMCTL;
-    int i,rc;
-
-    domctl.domain = domid;
-    domctl.cmd    = XEN_DOMCTL_set_address_size;
-    domctl.u.address_size.size = 0;
-
-    for ( i = 0; i < ARRAY_SIZE(types); i++ )
-        if ( !strcmp(types[i].guest, guest_type) )
-            domctl.u.address_size.size = types[i].size;
-    if ( domctl.u.address_size.size == 0 )
-    {
-        xc_dom_printf(xch, "%s: warning: unknown guest type %s",
-                      __FUNCTION__, guest_type);
-        return -EINVAL;
-    }
-
-    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
-                  guest_type, domctl.u.address_size.size);
-    rc = do_domctl(xch, &domctl);
-    if ( rc != 0 )
-        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
-                      __FUNCTION__, rc);
-    return rc;
-}
-
-/*  >0: success, *nr_pfns set to number actually populated
- *   0: didn't try with this pfn shift (e.g. misaligned base etc)
- *  <0: ERROR
- */
-static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
-                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns,
-                             xen_pfn_t *extents)
-{
-    /* The mask for this level */
-    const uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
-    /* The shift, mask and next boundary for the level above this one */
-    const int next_shift = pfn_shift + LPAE_SHIFT;
-    const uint64_t next_mask = ((uint64_t)1<<next_shift)-1;
-    const xen_pfn_t next_boundary
-        = (base_pfn + ((uint64_t)1<<next_shift)) & ~next_mask;
-
-    int nr, i, count;
-    xen_pfn_t end_pfn = base_pfn + *nr_pfns;
-
-    /* No level zero super pages with current hardware */
-    if ( pfn_shift == PFN_512G_SHIFT )
-        return 0;
-
-    /* base is misaligned for this level */
-    if ( mask & base_pfn )
-        return 0;
-
-    /*
-     * If base is not aligned at the next level up then try and make
-     * it so for next time around.
-     */
-    if ( (base_pfn & next_mask) && end_pfn > next_boundary )
-        end_pfn = next_boundary;
-
-    count = ( end_pfn - base_pfn ) >> pfn_shift;
-
-    /* Nothing to allocate */
-    if ( !count )
-        return 0;
-
-    for ( i = 0 ; i < count ; i ++ )
-        extents[i] = base_pfn + (i<<pfn_shift);
-
-    nr = xc_domain_populate_physmap(dom->xch, dom->guest_domid, count,
-                                    pfn_shift, 0, extents);
-    if ( nr <= 0 ) return nr;
-    DOMPRINTF("%s: populated %#x/%#x entries with shift %d",
-              __FUNCTION__, nr, count, pfn_shift);
-
-    *nr_pfns = nr << pfn_shift;
-
-    return 1;
-}
-
-static int populate_guest_memory(struct xc_dom_image *dom,
-                                 xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
-{
-    int rc = 0;
-    xen_pfn_t allocsz, pfn, *extents;
-
-    extents = calloc(1024*1024,sizeof(xen_pfn_t));
-    if ( extents == NULL )
-    {
-        DOMPRINTF("%s: Unable to allocate extent array", __FUNCTION__);
-        return -1;
-    }
-
-    DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
-              __FUNCTION__,
-              (uint64_t)base_pfn << XC_PAGE_SHIFT,
-              (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
-              (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
-
-    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
-    {
-        allocsz = min_t(int, 1024*1024, nr_pfns - pfn);
-#if 0 /* Enable this to exercise/debug the code which tries to realign
-       * to a superpage boundary, by misaligning at the start. */
-        if ( pfn == 0 )
-        {
-            allocsz = 1;
-            rc = populate_one_size(dom, PFN_4K_SHIFT,
-                                   base_pfn + pfn, &allocsz, extents);
-            if (rc < 0) break;
-            if (rc > 0) continue;
-            /* Failed to allocate a single page? */
-            break;
-        }
-#endif
-
-        rc = populate_one_size(dom, PFN_512G_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_1G_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_2M_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_4K_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc == 0 )
-        {
-            DOMPRINTF("%s: Not enough RAM", __FUNCTION__);
-            errno = ENOMEM;
-            rc = -1;
-            goto out;
-        }
-    }
-
-out:
-    free(extents);
-    return rc < 0 ? rc : 0;
-}
-
-static int meminit(struct xc_dom_image *dom)
-{
-    int i, rc;
-    uint64_t modbase;
-
-    uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT;
-
-    const uint64_t bankbase[] = GUEST_RAM_BANK_BASES;
-    const uint64_t bankmax[] = GUEST_RAM_BANK_SIZES;
-
-    /* Convenient */
-    const uint64_t kernbase = dom->kernel_seg.vstart;
-    const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
-    const uint64_t kernsize = kernend - kernbase;
-    const uint64_t dtb_size = dom->devicetree_blob ?
-        ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
-    const uint64_t ramdisk_size = dom->modules[0].blob ?
-        ROUNDUP(dom->modules[0].size, XC_PAGE_SHIFT) : 0;
-    const uint64_t modsize = dtb_size + ramdisk_size;
-    const uint64_t ram128mb = bankbase[0] + (128<<20);
-
-    xen_pfn_t p2m_size;
-    uint64_t bank0end;
-
-    assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
-
-    if ( modsize + kernsize > bankmax[0] )
-    {
-        DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
-                  __FUNCTION__);
-        return -1;
-    }
-
-    if ( ramsize == 0 )
-    {
-        DOMPRINTF("%s: ram size is 0", __FUNCTION__);
-        return -1;
-    }
-
-    if ( ramsize > GUEST_RAM_MAX )
-    {
-        DOMPRINTF("%s: ram size is too large for guest address space: "
-                  "%"PRIx64" > %llx",
-                  __FUNCTION__, ramsize, GUEST_RAM_MAX);
-        return -1;
-    }
-
-    rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
-    if ( rc )
-        return rc;
-
-    for ( i = 0; ramsize && i < GUEST_RAM_BANKS; i++ )
-    {
-        uint64_t banksize = ramsize > bankmax[i] ? bankmax[i] : ramsize;
-
-        ramsize -= banksize;
-
-        p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT;
-
-        dom->rambank_size[i] = banksize >> XC_PAGE_SHIFT;
-    }
-
-    assert(dom->rambank_size[0] != 0);
-    assert(ramsize == 0); /* Too much RAM is rejected above */
-
-    dom->p2m_size = p2m_size;
-
-    /* setup initial p2m and allocate guest memory */
-    for ( i = 0; i < GUEST_RAM_BANKS && dom->rambank_size[i]; i++ )
-    {
-        if ((rc = populate_guest_memory(dom,
-                                        bankbase[i] >> XC_PAGE_SHIFT,
-                                        dom->rambank_size[i])))
-            return rc;
-    }
-
-    /*
-     * We try to place dtb+initrd at 128MB or if we have less RAM
-     * as high as possible. If there is no space then fallback to
-     * just before the kernel.
-     *
-     * If changing this then consider
-     * xen/arch/arm/kernel.c:place_modules as well.
-     */
-    bank0end = bankbase[0] + ((uint64_t)dom->rambank_size[0] << XC_PAGE_SHIFT);
-
-    if ( bank0end >= ram128mb + modsize && kernend < ram128mb )
-        modbase = ram128mb;
-    else if ( bank0end - modsize > kernend )
-        modbase = bank0end - modsize;
-    else if (kernbase - bankbase[0] > modsize )
-        modbase = kernbase - modsize;
-    else
-        return -1;
-
-    DOMPRINTF("%s: placing boot modules at 0x%" PRIx64, __FUNCTION__, modbase);
-
-    /*
-     * Must map DTB *after* initrd, to satisfy order of calls to
-     * xc_dom_alloc_segment in xc_dom_build_image, which must map
-     * things at monotonolically increasing addresses.
-     */
-    if ( ramdisk_size )
-    {
-        dom->modules[0].seg.vstart = modbase;
-        dom->modules[0].seg.vend = modbase + ramdisk_size;
-
-        DOMPRINTF("%s: ramdisk: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-                  __FUNCTION__,
-                  dom->modules[0].seg.vstart, dom->modules[0].seg.vend);
-
-        modbase += ramdisk_size;
-    }
-
-    if ( dtb_size )
-    {
-        dom->devicetree_seg.vstart = modbase;
-        dom->devicetree_seg.vend = modbase + dtb_size;
-
-        DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-                  __FUNCTION__,
-                  dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
-
-        modbase += dtb_size;
-    }
-
-    return 0;
-}
-
-bool xc_dom_translated(const struct xc_dom_image *dom)
-{
-    return true;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int bootearly(struct xc_dom_image *dom)
-{
-    DOMPRINTF("%s: doing nothing", __FUNCTION__);
-    return 0;
-}
-
-static int bootlate(struct xc_dom_image *dom)
-{
-    /* XXX
-     *   map shared info
-     *   map grant tables
-     *   setup shared info
-     */
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static struct xc_dom_arch xc_dom_32 = {
-    .guest_type = "xen-3.0-armv7l",
-    .native_protocol = XEN_IO_PROTO_ABI_ARM,
-    .page_shift = PAGE_SHIFT_ARM,
-    .sizeof_pfn = 8,
-    .alloc_magic_pages = alloc_magic_pages,
-    .start_info = start_info_arm,
-    .shared_info = shared_info_arm,
-    .vcpu = vcpu_arm32,
-    .meminit = meminit,
-    .bootearly = bootearly,
-    .bootlate = bootlate,
-};
-
-static struct xc_dom_arch xc_dom_64 = {
-    .guest_type = "xen-3.0-aarch64",
-    .native_protocol = XEN_IO_PROTO_ABI_ARM,
-    .page_shift = PAGE_SHIFT_ARM,
-    .sizeof_pfn = 8,
-    .alloc_magic_pages = alloc_magic_pages,
-    .start_info = start_info_arm,
-    .shared_info = shared_info_arm,
-    .vcpu = vcpu_arm64,
-    .meminit = meminit,
-    .bootearly = bootearly,
-    .bootlate = bootlate,
-};
-
-static void __init register_arch_hooks(void)
-{
-    xc_dom_register_arch_hooks(&xc_dom_32);
-    xc_dom_register_arch_hooks(&xc_dom_64);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_armzimageloader.c b/tools/libxc/xc_dom_armzimageloader.c
deleted file mode 100644
index 0df8c2a4b1..0000000000
--- a/tools/libxc/xc_dom_armzimageloader.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Xen domain builder -- ARM zImage bits
- *
- * Parse and load ARM zImage kernel images.
- *
- * Copyright (C) 2012, Citrix Systems.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#include <arpa/inet.h> /* XXX ntohl is not the right function... */
-
-struct minimal_dtb_header {
-    uint32_t magic;
-    uint32_t total_size;
-    /* There are other fields but we don't use them yet. */
-};
-
-#define DTB_MAGIC 0xd00dfeed
-
-/* ------------------------------------------------------------ */
-/* 32-bit zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-#define ZIMAGE32_MAGIC_OFFSET 0x24
-#define ZIMAGE32_START_OFFSET 0x28
-#define ZIMAGE32_END_OFFSET   0x2c
-
-#define ZIMAGE32_MAGIC 0x016f2818
-
-static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
-{
-    uint32_t *zimage;
-
-    if ( dom->kernel_blob == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: no kernel image loaded", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dom->kernel_size < 0x30 /*sizeof(struct setup_header)*/ )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    zimage = (uint32_t *)dom->kernel_blob;
-    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
-{
-    uint32_t *zimage;
-    uint32_t start, entry_addr;
-    uint64_t v_start, v_end;
-    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    zimage = (uint32_t *)dom->kernel_blob;
-
-    /* Do not load kernel at the very first RAM address */
-    v_start = rambase + 0x8000;
-
-    if ( dom->kernel_size > UINT64_MAX - v_start )
-    {
-        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_end = v_start + dom->kernel_size;
-
-    /*
-     * If start is invalid then the guest will start at some invalid
-     * address and crash, but this happens in guest context so doesn't
-     * concern us here.
-     */
-    start = zimage[ZIMAGE32_START_OFFSET/4];
-
-    if (start == 0)
-        entry_addr = v_start;
-    else
-        entry_addr = start;
-
-    /* find kernel segment */
-    dom->kernel_seg.vstart = v_start;
-    dom->kernel_seg.vend   = v_end;
-
-    dom->parms.virt_entry = entry_addr;
-    dom->parms.virt_base = rambase;
-
-    dom->guest_type = "xen-3.0-armv7l";
-    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-              __FUNCTION__, dom->guest_type,
-              dom->kernel_seg.vstart, dom->kernel_seg.vend);
-    return 0;
-}
-
-/* ------------------------------------------------------------ */
-/* 64-bit zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-#define ZIMAGE64_MAGIC_V0 0x14000008
-#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
-
-/* linux/Documentation/arm64/booting.txt */
-struct zimage64_hdr {
-    uint32_t magic0;
-    uint32_t res0;
-    uint64_t text_offset;  /* Image load offset */
-    uint64_t res1;
-    uint64_t res2;
-    /* zImage V1 only from here */
-    uint64_t res3;
-    uint64_t res4;
-    uint64_t res5;
-    uint32_t magic1;
-    uint32_t res6;
-};
-static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
-{
-    struct zimage64_hdr *zimage;
-
-    if ( dom->kernel_blob == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: no kernel image loaded", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dom->kernel_size < sizeof(*zimage) )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    zimage =  dom->kernel_blob;
-    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
-         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
-{
-    struct zimage64_hdr *zimage;
-    uint64_t v_start, v_end;
-    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    zimage = dom->kernel_blob;
-
-    if ( zimage->text_offset > UINT64_MAX - rambase )
-    {
-        DOMPRINTF("%s: kernel text offset is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_start = rambase + zimage->text_offset;
-
-    if ( dom->kernel_size > UINT64_MAX - v_start )
-    {
-        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_end = v_start + dom->kernel_size;
-
-    dom->kernel_seg.vstart = v_start;
-    dom->kernel_seg.vend   = v_end;
-
-    /* Call the kernel at offset 0 */
-    dom->parms.virt_entry = v_start;
-    dom->parms.virt_base = rambase;
-
-    dom->guest_type = "xen-3.0-aarch64";
-    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-              __FUNCTION__, dom->guest_type,
-              dom->kernel_seg.vstart, dom->kernel_seg.vend);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------ */
-/* Common zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
-{
-    void *dst;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    dst = xc_dom_seg_to_ptr(dom, &dom->kernel_seg);
-    if ( dst == NULL )
-    {
-        DOMPRINTF("%s: xc_dom_seg_to_ptr(dom, &dom->kernel_seg) => NULL",
-                  __func__);
-        return -1;
-    }
-
-    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
-              __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
-    DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
-              __func__, dom->kernel_size, dom->kernel_blob, dst);
-
-    memcpy(dst, dom->kernel_blob, dom->kernel_size);
-
-    return 0;
-}
-
-static struct xc_dom_loader zimage32_loader = {
-    .name = "Linux zImage (ARM32)",
-    .probe = xc_dom_probe_zimage32_kernel,
-    .parser = xc_dom_parse_zimage32_kernel,
-    .loader = xc_dom_load_zimage_kernel,
-};
-
-static struct xc_dom_loader zimage64_loader = {
-    .name = "Linux zImage (ARM64)",
-    .probe = xc_dom_probe_zimage64_kernel,
-    .parser = xc_dom_parse_zimage64_kernel,
-    .loader = xc_dom_load_zimage_kernel,
-};
-
-static void __init register_loader(void)
-{
-    xc_dom_register_loader(&zimage32_loader);
-    xc_dom_register_loader(&zimage64_loader);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_binloader.c b/tools/libxc/xc_dom_binloader.c
deleted file mode 100644
index d6f7f2a500..0000000000
--- a/tools/libxc/xc_dom_binloader.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Some of the field descriptions were copied from "The Multiboot
- * Specification", Copyright 1995, 96 Bryan Ford <baford@cs.utah.edu>,
- * Erich Stefan Boleyn <erich@uruk.org> Copyright 1999, 2000, 2001, 2002
- * Free Software Foundation, Inc.
- */
-
-/******************************************************************************
- *
- * Loads simple binary images. It's like a .COM file in MS-DOS. No headers are
- * present. The only requirement is that it must have a xen_bin_image table
- * somewhere in the first 8192 bytes, starting on a 32-bit aligned address.
- * Those familiar with the multiboot specification should recognize this, it's
- * (almost) the same as the multiboot header.
- * The layout of the xen_bin_image table is:
- *
- * Offset Type Name          Note
- * 0      uint32_t  magic         required
- * 4      uint32_t  flags         required
- * 8      uint32_t  checksum      required
- * 12     uint32_t  header_addr   required
- * 16     uint32_t  load_addr     required
- * 20     uint32_t  load_end_addr required
- * 24     uint32_t  bss_end_addr  required
- * 28     uint32_t  entry_addr    required
- *
- * - magic
- *   Magic number identifying the table. For images to be loaded by Xen 3, the
- *   magic value is 0x336ec578 ("xEn3" with the 0x80 bit of the "E" set).
- * - flags
- *   bit 0: indicates whether the image needs to be loaded on a page boundary
- *   bit 1: reserved, must be 0 (the multiboot spec uses this bit to indicate
- *          that memory info should be passed to the image)
- *   bit 2: reserved, must be 0 (the multiboot spec uses this bit to indicate
- *          that the bootloader should pass video mode info to the image)
- *   bit 16: reserved, must be 1 (the multiboot spec uses this bit to indicate
- *           that the values in the fields header_addr - entry_addr are
- *           valid)
- *   All other bits should be set to 0.
- * - checksum
- *   When added to "magic" and "flags", the resulting value should be 0.
- * - header_addr
- *   Contains the virtual address corresponding to the beginning of the
- *   table - the memory location at which the magic value is supposed to be
- *   loaded. This field serves to synchronize the mapping between OS image
- *   offsets and virtual memory addresses.
- * - load_addr
- *   Contains the virtual address of the beginning of the text segment. The
- *   offset in the OS image file at which to start loading is defined by the
- *   offset at which the table was found, minus (header addr - load addr).
- *   load addr must be less than or equal to header addr.
- * - load_end_addr
- *   Contains the virtual address of the end of the data segment.
- *   (load_end_addr - load_addr) specifies how much data to load. This implies
- *   that the text and data segments must be consecutive in the OS image. If
- *   this field is zero, the domain builder assumes that the text and data
- *   segments occupy the whole OS image file.
- * - bss_end_addr
- *   Contains the virtual address of the end of the bss segment. The domain
- *   builder initializes this area to zero, and reserves the memory it occupies
- *   to avoid placing boot modules and other data relevant to the loaded image
- *   in that area. If this field is zero, the domain builder assumes that no bss
- *   segment is present.
- * - entry_addr
- *   The virtual address at which to start execution of the loaded image.
- *
- */
-
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
-#define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
-
-struct xen_bin_image_table
-{
-    uint32_t magic;
-    uint32_t flags;
-    uint32_t checksum;
-    uint32_t header_addr;
-    uint32_t load_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t entry_addr;
-};
-
-#define XEN_MULTIBOOT_MAGIC3 0x336ec578
-
-#define XEN_MULTIBOOT_FLAG_ALIGN4K     0x00000001
-#define XEN_MULTIBOOT_FLAG_NEEDMEMINFO 0x00000002
-#define XEN_MULTIBOOT_FLAG_NEEDVIDINFO 0x00000004
-#define XEN_MULTIBOOT_FLAG_ADDRSVALID  0x00010000
-#define XEN_MULTIBOOT_FLAG_PAE_SHIFT   14
-#define XEN_MULTIBOOT_FLAG_PAE_MASK    (3 << XEN_MULTIBOOT_FLAG_PAE_SHIFT)
-
-/* Flags we test for */
-#define FLAGS_MASK     ((~ 0) & (~ XEN_MULTIBOOT_FLAG_ALIGN4K) & \
-    (~ XEN_MULTIBOOT_FLAG_PAE_MASK))
-#define FLAGS_REQUIRED XEN_MULTIBOOT_FLAG_ADDRSVALID
-
-/* --------------------------------------------------------------------- */
-
-static struct xen_bin_image_table *find_table(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *table;
-    uint32_t *probe_ptr;
-    uint32_t *probe_end;
-
-    if ( dom->kernel_size < sizeof(*table) )
-        return NULL;
-    probe_ptr = dom->kernel_blob;
-    if ( dom->kernel_size > (8192 + sizeof(*table)) )
-        probe_end = dom->kernel_blob + 8192;
-    else
-        probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table);
-
-    for ( table = NULL; probe_ptr < probe_end; probe_ptr++ )
-    {
-        if ( *probe_ptr == XEN_MULTIBOOT_MAGIC3 )
-        {
-            table = (struct xen_bin_image_table *) probe_ptr;
-            /* Checksum correct? */
-            if ( (table->magic + table->flags + table->checksum) == 0 )
-                return table;
-        }
-    }
-    return NULL;
-}
-
-static int xc_dom_probe_bin_kernel(struct xc_dom_image *dom)
-{
-    return find_table(dom) ? 0 : -EINVAL;
-}
-
-static int xc_dom_parse_bin_kernel(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *image_info;
-    char *image = dom->kernel_blob;
-    size_t image_size = dom->kernel_size;
-    uint32_t start_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t pae_flags;
-
-    image_info = find_table(dom);
-    if ( !image_info )
-        return -EINVAL;
-
-    DOMPRINTF("%s: multiboot header fields", __FUNCTION__);
-    DOMPRINTF("  flags:         0x%" PRIx32 "", image_info->flags);
-    DOMPRINTF("  header_addr:   0x%" PRIx32 "", image_info->header_addr);
-    DOMPRINTF("  load_addr:     0x%" PRIx32 "", image_info->load_addr);
-    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", image_info->load_end_addr);
-    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", image_info->bss_end_addr);
-    DOMPRINTF("  entry_addr:    0x%" PRIx32 "", image_info->entry_addr);
-
-    /* Check the flags */
-    if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
-                     "%s: xen_bin_image_table flags required "
-                     "0x%08" PRIx32 " found 0x%08" PRIx32 "",
-                     __FUNCTION__, FLAGS_REQUIRED, image_info->flags & FLAGS_MASK);
-        return -EINVAL;
-    }
-
-    /* Sanity check on the addresses */
-    if ( (image_info->header_addr < image_info->load_addr) ||
-         ((char *) image_info - image) <
-         (image_info->header_addr - image_info->load_addr) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid header_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    start_addr = image_info->header_addr - ((char *)image_info - image);
-    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
-    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
-
-    DOMPRINTF("%s: calculated addresses", __FUNCTION__);
-    DOMPRINTF("  start_addr:    0x%" PRIx32 "", start_addr);
-    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", load_end_addr);
-    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", bss_end_addr);
-
-    if ( (start_addr + image_size) < load_end_addr )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid load_end_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( bss_end_addr < load_end_addr)
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid bss_end_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    dom->kernel_seg.vstart = image_info->load_addr;
-    dom->kernel_seg.vend   = bss_end_addr;
-    dom->parms.virt_base   = start_addr;
-    dom->parms.virt_entry  = image_info->entry_addr;
-
-    pae_flags = image_info->flags & XEN_MULTIBOOT_FLAG_PAE_MASK;
-    switch (pae_flags >> XEN_MULTIBOOT_FLAG_PAE_SHIFT) {
-    case 0:
-        dom->guest_type = "xen-3.0-x86_32";
-        break;
-    case 1:
-        dom->guest_type = "xen-3.0-x86_32p";
-        break;
-    case 2:
-        dom->guest_type = "xen-3.0-x86_64";
-        break;
-    case 3:
-        /* Kernel detects PAE at runtime.  So try to figure whenever
-         * xen supports PAE and advertise a PAE-capable kernel in case
-         * it does. */
-        dom->guest_type = "xen-3.0-x86_32";
-        if ( strstr(dom->xen_caps, "xen-3.0-x86_32p") )
-        {
-            DOMPRINTF("%s: PAE fixup", __FUNCTION__);
-            dom->guest_type = "xen-3.0-x86_32p";
-            dom->parms.pae  = XEN_PAE_EXTCR3;
-        }
-        break;
-    }
-    return 0;
-}
-
-static int xc_dom_load_bin_kernel(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *image_info;
-    char *image = dom->kernel_blob;
-    char *dest;
-    size_t image_size = dom->kernel_size;
-    size_t dest_size;
-    uint32_t start_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t skip, text_size, bss_size;
-
-    image_info = find_table(dom);
-    if ( !image_info )
-        return -EINVAL;
-
-    start_addr = image_info->header_addr - ((char *)image_info - image);
-    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
-    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
-
-    /* It's possible that we need to skip the first part of the image */
-    skip = image_info->load_addr - start_addr;
-    text_size = load_end_addr - image_info->load_addr;
-    bss_size = bss_end_addr - load_end_addr;
-
-    DOMPRINTF("%s: calculated sizes", __FUNCTION__);
-    DOMPRINTF("  skip:      0x%" PRIx32 "", skip);
-    DOMPRINTF("  text_size: 0x%" PRIx32 "", text_size);
-    DOMPRINTF("  bss_size:  0x%" PRIx32 "", bss_size);
-
-    dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart, &dest_size);
-    if ( dest == NULL )
-    {
-        DOMPRINTF("%s: xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart)"
-                  " => NULL", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dest_size < text_size ||
-         dest_size - text_size < bss_size )
-    {
-        DOMPRINTF("%s: mapped region is too small for image", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( image_size < skip ||
-         image_size - skip < text_size )
-    {
-        DOMPRINTF("%s: image is too small for declared text size",
-                  __FUNCTION__);
-        return -EINVAL;
-    }
-
-    memcpy(dest, image + skip, text_size);
-    memset(dest + text_size, 0, bss_size);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static struct xc_dom_loader bin_loader = {
-    .name = "multiboot-binary",
-    .probe = xc_dom_probe_bin_kernel,
-    .parser = xc_dom_parse_bin_kernel,
-    .loader = xc_dom_load_bin_kernel,
-};
-
-static void __init register_loader(void)
-{
-    xc_dom_register_loader(&bin_loader);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_boot.c b/tools/libxc/xc_dom_boot.c
deleted file mode 100644
index bb599b33ba..0000000000
--- a/tools/libxc/xc_dom_boot.c
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Xen domain builder -- xen booter.
- *
- * This is the code which actually boots a fresh
- * prepared domain image as xen guest domain.
- *
- * ==>  this is the only domain builder code piece
- *          where xen hypercalls are allowed        <==
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <zlib.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-#include "xc_core.h"
-#include <xen/hvm/params.h>
-#include <xen/grant_table.h>
-
-/* ------------------------------------------------------------------------ */
-
-static int setup_hypercall_page(struct xc_dom_image *dom)
-{
-    DECLARE_DOMCTL;
-    xen_pfn_t pfn;
-    int rc;
-
-    if ( dom->parms.virt_hypercall == -1 )
-        return 0;
-    pfn = (dom->parms.virt_hypercall - dom->parms.virt_base)
-        >> XC_DOM_PAGE_SHIFT(dom);
-
-    DOMPRINTF("%s: vaddr=0x%" PRIx64 " pfn=0x%" PRIpfn "", __FUNCTION__,
-                  dom->parms.virt_hypercall, pfn);
-    domctl.cmd = XEN_DOMCTL_hypercall_init;
-    domctl.domain = dom->guest_domid;
-    domctl.u.hypercall_init.gmfn = xc_dom_p2m(dom, pfn);
-    rc = do_domctl(dom->xch, &domctl);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: HYPERCALL_INIT failed: %d - %s)",
-                     __FUNCTION__, errno, strerror(errno));
-    return rc;
-}
-
-
-/* ------------------------------------------------------------------------ */
-
-int xc_dom_compat_check(struct xc_dom_image *dom)
-{
-    xen_capabilities_info_t xen_caps;
-    char *item, *ptr;
-    int match, found = 0;
-
-    strncpy(xen_caps, dom->xen_caps, XEN_CAPABILITIES_INFO_LEN - 1);
-    xen_caps[XEN_CAPABILITIES_INFO_LEN - 1] = '\0';
-
-    for ( item = strtok_r(xen_caps, " ", &ptr);
-          item != NULL ; item = strtok_r(NULL, " ", &ptr) )
-    {
-        match = !strcmp(dom->guest_type, item);
-        DOMPRINTF("%s: supported guest type: %s%s", __FUNCTION__,
-                  item, match ? " <= matches" : "");
-        if ( match )
-            found++;
-    }
-    if ( !found )
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
-                     "%s: guest type %s not supported by xen kernel, sorry",
-                     __FUNCTION__, dom->guest_type);
-
-    return found;
-}
-
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch, uint32_t domid)
-{
-    dom->xch = xch;
-    dom->guest_domid = domid;
-
-    dom->xen_version = xc_version(xch, XENVER_version, NULL);
-    if ( xc_version(xch, XENVER_capabilities, &dom->xen_caps) < 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR, "can't get xen capabilities");
-        return -1;
-    }
-    DOMPRINTF("%s: ver %d.%d, caps %s", __FUNCTION__,
-              dom->xen_version >> 16, dom->xen_version & 0xff,
-              dom->xen_caps);
-    return 0;
-}
-
-int xc_dom_boot_mem_init(struct xc_dom_image *dom)
-{
-    long rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    rc = dom->arch_hooks->meminit(dom);
-    if ( rc != 0 )
-    {
-        xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
-                     "%s: can't allocate low memory for domain",
-                     __FUNCTION__);
-        return rc;
-    }
-
-    return 0;
-}
-
-void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
-                           xen_pfn_t count)
-{
-    int page_shift = XC_DOM_PAGE_SHIFT(dom);
-    privcmd_mmap_entry_t *entries;
-    void *ptr;
-    int i;
-    int err;
-
-    entries = xc_dom_malloc(dom, count * sizeof(privcmd_mmap_entry_t));
-    if ( entries == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [malloc]", __FUNCTION__, pfn, count);
-        return NULL;
-    }
-
-    for ( i = 0; i < count; i++ )
-        entries[i].mfn = xc_dom_p2m(dom, pfn + i);
-
-    ptr = xc_map_foreign_ranges(dom->xch, dom->guest_domid,
-                count << page_shift, PROT_READ | PROT_WRITE, 1 << page_shift,
-                entries, count);
-    if ( ptr == NULL )
-    {
-        err = errno;
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [mmap, errno=%i (%s)]", __FUNCTION__, pfn, count,
-                     err, strerror(err));
-        return NULL;
-    }
-
-    return ptr;
-}
-
-int xc_dom_boot_image(struct xc_dom_image *dom)
-{
-    xc_dominfo_t info;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    /* misc stuff*/
-    if ( (rc = dom->arch_hooks->bootearly(dom)) != 0 )
-        return rc;
-
-    /* collect some info */
-    rc = xc_domain_getinfo(dom->xch, dom->guest_domid, 1, &info);
-    if ( rc < 0 )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: getdomaininfo failed (rc=%d)", __FUNCTION__, rc);
-        return rc;
-    }
-    if ( rc == 0 || info.domid != dom->guest_domid )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: Huh? No domains found (nr_domains=%d) "
-                     "or domid mismatch (%d != %d)", __FUNCTION__,
-                     rc, info.domid, dom->guest_domid);
-        return -1;
-    }
-    dom->shared_info_mfn = info.shared_info_frame;
-
-    /* sanity checks */
-    if ( !xc_dom_compat_check(dom) )
-        return -1;
-
-    /* initial mm setup */
-    if ( dom->arch_hooks->setup_pgtables &&
-         (rc = dom->arch_hooks->setup_pgtables(dom)) != 0 )
-        return rc;
-
-    /* start info page */
-    if ( dom->arch_hooks->start_info )
-        dom->arch_hooks->start_info(dom);
-
-    /* hypercall page */
-    if ( (rc = setup_hypercall_page(dom)) != 0 )
-        return rc;
-    xc_dom_log_memory_footprint(dom);
-
-    /* misc x86 stuff */
-    if ( (rc = dom->arch_hooks->bootlate(dom)) != 0 )
-        return rc;
-
-    /* let the vm run */
-    if ( (rc = dom->arch_hooks->vcpu(dom)) != 0 )
-        return rc;
-    xc_dom_unmap_all(dom);
-
-    return rc;
-}
-
-static xen_pfn_t xc_dom_gnttab_setup(xc_interface *xch, uint32_t domid)
-{
-    gnttab_setup_table_t setup;
-    DECLARE_HYPERCALL_BUFFER(xen_pfn_t, gmfnp);
-    int rc;
-    xen_pfn_t gmfn;
-
-    gmfnp = xc_hypercall_buffer_alloc(xch, gmfnp, sizeof(*gmfnp));
-    if (gmfnp == NULL)
-        return -1;
-
-    setup.dom = domid;
-    setup.nr_frames = 1;
-    set_xen_guest_handle(setup.frame_list, gmfnp);
-    setup.status = 0;
-
-    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), 1);
-    gmfn = *gmfnp;
-    xc_hypercall_buffer_free(xch, gmfnp);
-
-    if ( rc != 0 || setup.status != GNTST_okay )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to setup domU grant table "
-                     "[errno=%d, status=%" PRId16 "]\n",
-                     __FUNCTION__, rc != 0 ? errno : 0, setup.status);
-        return -1;
-    }
-
-    return gmfn;
-}
-
-static void xc_dom_set_gnttab_entry(xc_interface *xch,
-                                    grant_entry_v1_t *gnttab,
-                                    unsigned int idx,
-                                    uint32_t guest_domid,
-                                    uint32_t backend_domid,
-                                    xen_pfn_t guest_gfn)
-{
-    if ( guest_domid == backend_domid || guest_gfn == -1 )
-        return;
-
-    xc_dom_printf(xch, "%s: d%d gnt[%u] -> d%d 0x%"PRI_xen_pfn,
-                  __func__, guest_domid, idx, backend_domid, guest_gfn);
-
-    gnttab[idx].flags = GTF_permit_access;
-    gnttab[idx].domid = backend_domid;
-    gnttab[idx].frame = guest_gfn;
-}
-
-static int compat_gnttab_seed(xc_interface *xch, uint32_t domid,
-                              xen_pfn_t console_gfn,
-                              xen_pfn_t xenstore_gfn,
-                              uint32_t console_domid,
-                              uint32_t xenstore_domid)
-{
-
-    xen_pfn_t gnttab_gfn;
-    grant_entry_v1_t *gnttab;
-
-    gnttab_gfn = xc_dom_gnttab_setup(xch, domid);
-    if ( gnttab_gfn == -1 )
-        return -1;
-
-    gnttab = xc_map_foreign_range(xch,
-                                  domid,
-                                  PAGE_SIZE,
-                                  PROT_READ|PROT_WRITE,
-                                  gnttab_gfn);
-    if ( gnttab == NULL )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to map d%d grant table "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    xc_dom_set_gnttab_entry(xch, gnttab, GNTTAB_RESERVED_CONSOLE,
-                            domid, console_domid, console_gfn);
-    xc_dom_set_gnttab_entry(xch, gnttab, GNTTAB_RESERVED_XENSTORE,
-                            domid, xenstore_domid, xenstore_gfn);
-
-    if ( munmap(gnttab, PAGE_SIZE) == -1 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to unmap d%d grant table "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    /* Guest shouldn't really touch its grant table until it has
-     * enabled its caches. But lets be nice. */
-    xc_domain_cacheflush(xch, domid, gnttab_gfn, 1);
-
-    return 0;
-}
-
-static int compat_gnttab_hvm_seed(xc_interface *xch, uint32_t domid,
-                                  xen_pfn_t console_gfn,
-                                  xen_pfn_t xenstore_gfn,
-                                  uint32_t console_domid,
-                                  uint32_t xenstore_domid)
-{
-    int rc;
-    xen_pfn_t scratch_gfn;
-    struct xen_add_to_physmap xatp = {
-        .domid = domid,
-        .space = XENMAPSPACE_grant_table,
-        .idx   = 0,
-    };
-    struct xen_remove_from_physmap xrfp = {
-        .domid = domid,
-    };
-
-    rc = xc_core_arch_get_scratch_gpfn(xch, domid, &scratch_gfn);
-    if ( rc < 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to get a scratch gfn from d%d"
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-    xatp.gpfn = scratch_gfn;
-    xrfp.gpfn = scratch_gfn;
-
-    xc_dom_printf(xch, "%s: d%d: pfn=0x%"PRI_xen_pfn, __func__,
-                  domid, scratch_gfn);
-
-    rc = do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp));
-    if ( rc != 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to add gnttab to d%d physmap "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    rc = compat_gnttab_seed(xch, domid,
-                            console_gfn, xenstore_gfn,
-                            console_domid, xenstore_domid);
-    if (rc != 0)
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to seed gnttab entries for d%d\n",
-                     __func__, domid);
-        (void) do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp,
-                            sizeof(xrfp));
-        return -1;
-    }
-
-    rc = do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp, sizeof(xrfp));
-    if (rc != 0)
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to remove gnttab from d%d physmap "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    return 0;
-}
-
-int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
-                       bool is_hvm, xen_pfn_t console_gfn,
-                       xen_pfn_t xenstore_gfn, uint32_t console_domid,
-                       uint32_t xenstore_domid)
-{
-    xenforeignmemory_handle* fmem = xch->fmem;
-    xenforeignmemory_resource_handle *fres;
-    void *addr = NULL;
-
-    fres = xenforeignmemory_map_resource(
-        fmem, guest_domid, XENMEM_resource_grant_table,
-        XENMEM_resource_grant_table_id_shared, 0, 1, &addr,
-        PROT_READ | PROT_WRITE, 0);
-    if ( !fres )
-    {
-        if ( errno == EOPNOTSUPP )
-            return is_hvm ?
-                compat_gnttab_hvm_seed(xch, guest_domid,
-                                       console_gfn, xenstore_gfn,
-                                       console_domid, xenstore_domid) :
-                compat_gnttab_seed(xch, guest_domid,
-                                   console_gfn, xenstore_gfn,
-                                   console_domid, xenstore_domid);
-
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to acquire d%d grant table [errno=%d]\n",
-                     __func__, guest_domid, errno);
-        return -1;
-    }
-
-    xc_dom_set_gnttab_entry(xch, addr, GNTTAB_RESERVED_CONSOLE,
-                            guest_domid, console_domid, console_gfn);
-    xc_dom_set_gnttab_entry(xch, addr, GNTTAB_RESERVED_XENSTORE,
-                            guest_domid, xenstore_domid, xenstore_gfn);
-
-    xenforeignmemory_unmap_resource(fmem, fres);
-
-    return 0;
-}
-
-int xc_dom_gnttab_init(struct xc_dom_image *dom)
-{
-    bool is_hvm = xc_dom_translated(dom);
-    xen_pfn_t console_gfn = xc_dom_p2m(dom, dom->console_pfn);
-    xen_pfn_t xenstore_gfn = xc_dom_p2m(dom, dom->xenstore_pfn);
-
-    return xc_dom_gnttab_seed(dom->xch, dom->guest_domid, is_hvm,
-                              console_gfn, xenstore_gfn,
-                              dom->console_domid, dom->xenstore_domid);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_bzimageloader.c b/tools/libxc/xc_dom_bzimageloader.c
deleted file mode 100644
index a7d70cc7c6..0000000000
--- a/tools/libxc/xc_dom_bzimageloader.c
+++ /dev/null
@@ -1,812 +0,0 @@
-/*
- * Xen domain builder -- bzImage bits
- *
- * Parse and load bzImage kernel images.
- *
- * This relies on version 2.08 of the boot protocol, which contains an
- * ELF file embedded in the bzImage.  The loader extracts this ELF
- * image and passes it off to the standard ELF loader.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
- * written 2007 by Jeremy Fitzhardinge <jeremy@xensource.com>
- * written 2008 by Ian Campbell <ijc@hellion.org.uk>
- * written 2009 by Chris Lalancette <clalance@redhat.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom_decompress.h"
-
-#include <xen-tools/libs.h>
-
-#ifndef __MINIOS__
-
-#if defined(HAVE_BZLIB)
-
-#include <bzlib.h>
-
-static int xc_try_bzip2_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    bz_stream stream;
-    int ret;
-    char *out_buf;
-    char *tmp_buf;
-    int retval = -1;
-    unsigned int outsize;
-    uint64_t total;
-
-    stream.bzalloc = NULL;
-    stream.bzfree = NULL;
-    stream.opaque = NULL;
-
-    if ( dom->kernel_size == 0)
-    {
-        DOMPRINTF("BZIP2: Input is 0 size");
-        return -1;
-    }
-
-    ret = BZ2_bzDecompressInit(&stream, 0, 0);
-    if ( ret != BZ_OK )
-    {
-        DOMPRINTF("BZIP2: Error initting stream");
-        return -1;
-    }
-
-    /* sigh.  We don't know up-front how much memory we are going to need
-     * for the output buffer.  Allocate the output buffer to be equal
-     * the input buffer to start, and we'll realloc as needed.
-     */
-    outsize = dom->kernel_size;
-
-    /*
-     * stream.avail_in and outsize are unsigned int, while kernel_size
-     * is a size_t. Check we aren't overflowing.
-     */
-    if ( outsize != dom->kernel_size )
-    {
-        DOMPRINTF("BZIP2: Input too large");
-        goto bzip2_cleanup;
-    }
-
-    out_buf = malloc(outsize);
-    if ( out_buf == NULL )
-    {
-        DOMPRINTF("BZIP2: Failed to alloc memory");
-        goto bzip2_cleanup;
-    }
-
-    stream.next_in = dom->kernel_blob;
-    stream.avail_in = dom->kernel_size;
-
-    stream.next_out = out_buf;
-    stream.avail_out = dom->kernel_size;
-
-    for ( ; ; )
-    {
-        ret = BZ2_bzDecompress(&stream);
-        if ( ret == BZ_STREAM_END )
-        {
-            DOMPRINTF("BZIP2: Saw data stream end");
-            retval = 0;
-            break;
-        }
-        if ( ret != BZ_OK )
-        {
-            DOMPRINTF("BZIP2: error %d", ret);
-            free(out_buf);
-            goto bzip2_cleanup;
-        }
-
-        if ( stream.avail_out == 0 )
-        {
-            /* Protect against output buffer overflow */
-            if ( outsize > UINT_MAX / 2 )
-            {
-                DOMPRINTF("BZIP2: output buffer overflow");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-
-            if ( xc_dom_kernel_check_size(dom, outsize * 2) )
-            {
-                DOMPRINTF("BZIP2: output too large");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-
-            tmp_buf = realloc(out_buf, outsize * 2);
-            if ( tmp_buf == NULL )
-            {
-                DOMPRINTF("BZIP2: Failed to realloc memory");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-            out_buf = tmp_buf;
-
-            stream.next_out = out_buf + outsize;
-            stream.avail_out = (outsize * 2) - outsize;
-            outsize *= 2;
-        }
-        else if ( stream.avail_in == 0 )
-        {
-            /*
-             * If there is output buffer available then this indicates
-             * that BZ2_bzDecompress would like more input data to be
-             * provided.  However our complete input buffer is in
-             * memory and provided upfront so if avail_in is zero this
-             * actually indicates a truncated input.
-             */
-            DOMPRINTF("BZIP2: not enough input");
-            free(out_buf);
-            goto bzip2_cleanup;
-        }
-    }
-
-    total = (((uint64_t)stream.total_out_hi32) << 32) | stream.total_out_lo32;
-
-    if ( xc_dom_register_external(dom, out_buf, total) )
-    {
-        DOMPRINTF("BZIP2: Error registering stream output");
-        free(out_buf);
-        goto bzip2_cleanup;
-    }
-
-    DOMPRINTF("%s: BZIP2 decompress OK, 0x%zx -> 0x%lx",
-              __FUNCTION__, *size, (long unsigned int) total);
-
-    *blob = out_buf;
-    *size = total;
-
- bzip2_cleanup:
-    BZ2_bzDecompressEnd(&stream);
-
-    return retval;
-}
-
-#else /* !defined(HAVE_BZLIB) */
-
-static int xc_try_bzip2_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: BZIP2 decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-#endif
-
-#if defined(HAVE_LZMA)
-
-#include <lzma.h>
-
-static int _xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size,
-    lzma_stream *stream, const char *what)
-{
-    lzma_ret ret;
-    lzma_action action = LZMA_RUN;
-    unsigned char *out_buf;
-    unsigned char *tmp_buf;
-    int retval = -1;
-    size_t outsize;
-    const char *msg;
-
-    if ( dom->kernel_size == 0)
-    {
-        DOMPRINTF("%s: Input is 0 size", what);
-        return -1;
-    }
-
-    /* sigh.  We don't know up-front how much memory we are going to need
-     * for the output buffer.  Allocate the output buffer to be equal
-     * the input buffer to start, and we'll realloc as needed.
-     */
-    outsize = dom->kernel_size;
-    out_buf = malloc(outsize);
-    if ( out_buf == NULL )
-    {
-        DOMPRINTF("%s: Failed to alloc memory", what);
-        goto lzma_cleanup;
-    }
-
-    stream->next_in = dom->kernel_blob;
-    stream->avail_in = dom->kernel_size;
-
-    stream->next_out = out_buf;
-    stream->avail_out = dom->kernel_size;
-
-    for ( ; ; )
-    {
-        ret = lzma_code(stream, action);
-        if ( ret == LZMA_STREAM_END )
-        {
-            DOMPRINTF("%s: Saw data stream end", what);
-            retval = 0;
-            break;
-        }
-        if ( ret != LZMA_OK )
-        {
-            switch ( ret )
-            {
-            case LZMA_MEM_ERROR:
-                msg = strerror(ENOMEM);
-                break;
-
-            case LZMA_MEMLIMIT_ERROR:
-                msg = "Memory usage limit reached";
-                break;
-
-            case LZMA_FORMAT_ERROR:
-                msg = "File format not recognized";
-                break;
-
-            case LZMA_OPTIONS_ERROR:
-                // FIXME: Better message?
-                msg = "Unsupported compression options";
-                break;
-
-            case LZMA_DATA_ERROR:
-                msg = "File is corrupt";
-                break;
-
-            case LZMA_BUF_ERROR:
-                msg = "Unexpected end of input";
-                break;
-
-            default:
-                msg = "Internal program error (bug)";
-                break;
-            }
-            DOMPRINTF("%s: %s decompression error: %s",
-                      __FUNCTION__, what, msg);
-            free(out_buf);
-            goto lzma_cleanup;
-        }
-
-        if ( stream->avail_out == 0 )
-        {
-            /* Protect against output buffer overflow */
-            if ( outsize > SIZE_MAX / 2 )
-            {
-                DOMPRINTF("%s: output buffer overflow", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-
-            if ( xc_dom_kernel_check_size(dom, outsize * 2) )
-            {
-                DOMPRINTF("%s: output too large", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-
-            tmp_buf = realloc(out_buf, outsize * 2);
-            if ( tmp_buf == NULL )
-            {
-                DOMPRINTF("%s: Failed to realloc memory", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-            out_buf = tmp_buf;
-
-            stream->next_out = out_buf + outsize;
-            stream->avail_out = (outsize * 2) - outsize;
-            outsize *= 2;
-        }
-    }
-
-    if ( xc_dom_register_external(dom, out_buf, stream->total_out) )
-    {
-        DOMPRINTF("%s: Error registering stream output", what);
-        free(out_buf);
-        goto lzma_cleanup;
-    }
-
-    DOMPRINTF("%s: %s decompress OK, 0x%zx -> 0x%zx",
-              __FUNCTION__, what, *size, (size_t)stream->total_out);
-
-    *blob = out_buf;
-    *size = stream->total_out;
-
- lzma_cleanup:
-    lzma_end(stream);
-
-    return retval;
-}
-
-/* 128 Mb is the minimum size (half-way) documented to work for all inputs. */
-#define LZMA_BLOCK_SIZE (128*1024*1024)
-
-static int xc_try_xz_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    lzma_stream stream = LZMA_STREAM_INIT;
-
-    if ( lzma_stream_decoder(&stream, LZMA_BLOCK_SIZE, 0) != LZMA_OK )
-    {
-        DOMPRINTF("XZ: Failed to init decoder");
-        return -1;
-    }
-
-    return _xc_try_lzma_decode(dom, blob, size, &stream, "XZ");
-}
-
-static int xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    lzma_stream stream = LZMA_STREAM_INIT;
-
-    if ( lzma_alone_decoder(&stream, LZMA_BLOCK_SIZE) != LZMA_OK )
-    {
-        DOMPRINTF("LZMA: Failed to init decoder");
-        return -1;
-    }
-
-    return _xc_try_lzma_decode(dom, blob, size, &stream, "LZMA");
-}
-
-#else /* !defined(HAVE_LZMA) */
-
-static int xc_try_xz_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: XZ decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-static int xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: LZMA decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-#endif
-
-#if defined(HAVE_LZO1X)
-
-#include <lzo/lzo1x.h>
-
-#define LZOP_HEADER_HAS_FILTER 0x00000800
-#define LZOP_MAX_BLOCK_SIZE (64*1024*1024)
-
-static inline uint_fast16_t lzo_read_16(const unsigned char *buf)
-{
-    return buf[1] | (buf[0] << 8);
-}
-
-static inline uint_fast32_t lzo_read_32(const unsigned char *buf)
-{
-    return lzo_read_16(buf + 2) | ((uint32_t)lzo_read_16(buf) << 16);
-}
-
-static int xc_try_lzo1x_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    int ret;
-    const unsigned char *cur = dom->kernel_blob;
-    unsigned char *out_buf = NULL;
-    size_t left = dom->kernel_size;
-    const char *msg;
-    unsigned version;
-    static const unsigned char magic[] = {
-        0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
-    };
-
-    /*
-     * lzo_uint should match size_t. Check that this is the case to be
-     * sure we won't overflow various lzo_uint fields.
-     */
-    BUILD_BUG_ON(sizeof(lzo_uint) != sizeof(size_t));
-
-    ret = lzo_init();
-    if ( ret != LZO_E_OK )
-    {
-        DOMPRINTF("LZO1x: Failed to init library (%d)\n", ret);
-        return -1;
-    }
-
-    if ( left < 16 || memcmp(cur, magic, 9) )
-    {
-        DOMPRINTF("LZO1x: Unrecognized magic\n");
-        return -1;
-    }
-
-    /* get version (2bytes), skip library version (2),
-     * 'need to be extracted' version (2) and method (1) */
-    version = lzo_read_16(cur + 9);
-    cur += 16;
-    left -= 16;
-
-    if ( version >= 0x0940 )
-    {
-        /* skip level */
-        ++cur;
-        if ( left )
-            --left;
-    }
-
-    if ( left >= 4 && (lzo_read_32(cur) & LZOP_HEADER_HAS_FILTER) )
-        ret = 8; /* flags + filter info */
-    else
-        ret = 4; /* flags */
-
-    /* skip mode and mtime_low */
-    ret += 8;
-    if ( version >= 0x0940 )
-        ret += 4; /* skip mtime_high */
-
-    /* don't care about the file name, and skip checksum */
-    if ( left > ret )
-        ret += 1 + cur[ret] + 4;
-
-    if ( left < ret )
-    {
-        DOMPRINTF("LZO1x: Incomplete header\n");
-        return -1;
-    }
-    cur += ret;
-    left -= ret;
-
-    for ( *size = 0; ; )
-    {
-        lzo_uint src_len, dst_len, out_len;
-        unsigned char *tmp_buf;
-
-        msg = "Short input";
-        if ( left < 4 )
-            break;
-
-        dst_len = lzo_read_32(cur);
-        if ( !dst_len )
-        {
-            msg = "Error registering stream output";
-            if ( xc_dom_register_external(dom, out_buf, *size) )
-                break;
-
-            return 0;
-        }
-
-        if ( dst_len > LZOP_MAX_BLOCK_SIZE )
-        {
-            msg = "Block size too large";
-            break;
-        }
-
-        if ( left < 12 )
-            break;
-
-        src_len = lzo_read_32(cur + 4);
-        cur += 12; /* also skip block checksum info */
-        left -= 12;
-
-        msg = "Bad source length";
-        if ( src_len <= 0 || src_len > dst_len || src_len > left )
-            break;
-
-        msg = "Output buffer overflow";
-        if ( *size > SIZE_MAX - dst_len )
-            break;
-
-        msg = "Decompressed image too large";
-        if ( xc_dom_kernel_check_size(dom, *size + dst_len) )
-            break;
-
-        msg = "Failed to (re)alloc memory";
-        tmp_buf = realloc(out_buf, *size + dst_len);
-        if ( tmp_buf == NULL )
-            break;
-
-        out_buf = tmp_buf;
-        out_len = dst_len;
-
-        ret = lzo1x_decompress_safe(cur, src_len,
-                                    out_buf + *size, &out_len, NULL);
-        switch ( ret )
-        {
-        case LZO_E_OK:
-            msg = "Input underrun";
-            if ( out_len != dst_len )
-                break;
-
-            *blob = out_buf;


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2M-0000i2-RV; Wed, 09 Sep 2020 11:13:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2L-0000ht-HO
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:13 +0000
X-Inumbo-ID: 0768afbe-9454-435d-819c-ed9abbcbb05d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0768afbe-9454-435d-819c-ed9abbcbb05d;
 Wed, 09 Sep 2020 11:13:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=QUp8Ir85J/D/lV0ZLBZ9D3W0q6BHPDQ8LVK2sN0eyv8=; b=Jq1sSesFPOman9A0vtW1L8se5s
 HXPrwQT6qwj4rLtetzk9h8RUEFH3WPOw5+rdQy/VfQvQxBJDXLRzkebtmDu+dgmvtcSQgAPCAGzie
 Ix01Kvzuwz+CTLSH8Vcnp/K7s+p7nuZ1G+lJQuL0mEzGybQuyvrYDC+f8dBG/h+11aPo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2H-00066R-MA
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:09 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2H-0001UE-L4
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:09 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: rename libxenguest internal headers
Message-Id: <E1kFy2H-0001UE-L4@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:13:09 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 256920d3a232c2e6631dbd505d036c0d3046d299
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:29 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: rename libxenguest internal headers
    
    Rename the header files private to libxenguest from xc_*.h to xg_*.h.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xc_dom_decompress.h              |   8 -
 tools/libxc/xc_dom_decompress_unsafe.h       |  20 --
 tools/libxc/xc_sr_common.h                   | 468 ---------------------------
 tools/libxc/xc_sr_common_x86.h               |  51 ---
 tools/libxc/xc_sr_common_x86_pv.h            | 109 -------
 tools/libxc/xc_sr_stream_format.h            | 150 ---------
 tools/libxc/xg_dom_bzimageloader.c           |   2 +-
 tools/libxc/xg_dom_decompress.h              |   8 +
 tools/libxc/xg_dom_decompress_lz4.c          |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.c       |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.h       |  20 ++
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_lzma.c  |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_xz.c    |   2 +-
 tools/libxc/xg_sr_common.c                   |   2 +-
 tools/libxc/xg_sr_common.h                   | 468 +++++++++++++++++++++++++++
 tools/libxc/xg_sr_common_x86.c               |   2 +-
 tools/libxc/xg_sr_common_x86.h               |  51 +++
 tools/libxc/xg_sr_common_x86_pv.c            |   2 +-
 tools/libxc/xg_sr_common_x86_pv.h            | 109 +++++++
 tools/libxc/xg_sr_restore.c                  |   2 +-
 tools/libxc/xg_sr_restore_x86_hvm.c          |   2 +-
 tools/libxc/xg_sr_restore_x86_pv.c           |   2 +-
 tools/libxc/xg_sr_save.c                     |   2 +-
 tools/libxc/xg_sr_save_x86_hvm.c             |   2 +-
 tools/libxc/xg_sr_save_x86_pv.c              |   2 +-
 tools/libxc/xg_sr_stream_format.h            | 150 +++++++++
 28 files changed, 822 insertions(+), 822 deletions(-)

diff --git a/tools/libxc/xc_dom_decompress.h b/tools/libxc/xc_dom_decompress.h
deleted file mode 100644
index 42cefa3f0e..0000000000
--- a/tools/libxc/xc_dom_decompress.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __MINIOS__
-# include "xc_dom.h"
-#else
-# include "xc_dom_decompress_unsafe.h"
-#endif
-
-int xc_try_lz4_decode(struct xc_dom_image *dom, void **blob, size_t *size);
-
diff --git a/tools/libxc/xc_dom_decompress_unsafe.h b/tools/libxc/xc_dom_decompress_unsafe.h
deleted file mode 100644
index 64f68864b1..0000000000
--- a/tools/libxc/xc_dom_decompress_unsafe.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "xc_dom.h"
-
-typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
-                          int (*fill)(void*, unsigned int),
-                          int (*flush)(void*, unsigned int),
-                          unsigned char *outbuf, unsigned int *posp,
-                          void (*error)(const char *x));
-
-int xc_dom_decompress_unsafe(
-    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-
-int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
deleted file mode 100644
index f3bdea8006..0000000000
--- a/tools/libxc/xc_sr_common.h
+++ /dev/null
@@ -1,468 +0,0 @@
-#ifndef __COMMON__H
-#define __COMMON__H
-
-#include <stdbool.h>
-
-#include "xg_private.h"
-#include "xg_save_restore.h"
-#include "xc_dom.h"
-#include "xc_bitops.h"
-
-#include "xc_sr_stream_format.h"
-
-/* String representation of Domain Header types. */
-const char *dhdr_type_to_str(uint32_t type);
-
-/* String representation of Record types. */
-const char *rec_type_to_str(uint32_t type);
-
-struct xc_sr_context;
-struct xc_sr_record;
-
-/**
- * Save operations.  To be implemented for each type of guest, for use by the
- * common save algorithm.
- *
- * Every function must be implemented, even if only with a no-op stub.
- */
-struct xc_sr_save_ops
-{
-    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
-    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /**
-     * Optionally transform the contents of a page from being specific to the
-     * sending environment, to being generic for the stream.
-     *
-     * The page of data at the end of 'page' may be a read-only mapping of a
-     * running guest; it must not be modified.  If no transformation is
-     * required, the callee should leave '*pages' untouched.
-     *
-     * If a transformation is required, the callee should allocate themselves
-     * a local page using malloc() and return it via '*page'.
-     *
-     * The caller shall free() '*page' in all cases.  In the case that the
-     * callee encounters an error, it should *NOT* free() the memory it
-     * allocated for '*page'.
-     *
-     * It is valid to fail with EAGAIN if the transformation is not able to be
-     * completed at this point.  The page shall be retried later.
-     *
-     * @returns 0 for success, -1 for failure, with errno appropriately set.
-     */
-    int (*normalise_page)(struct xc_sr_context *ctx, xen_pfn_t type,
-                          void **page);
-
-    /**
-     * Set up local environment to save a domain. (Typically querying
-     * running domain state, setting up mappings etc.)
-     *
-     * This is called once before any common setup has occurred, allowing for
-     * guest-specific adjustments to be made to common state.
-     */
-    int (*setup)(struct xc_sr_context *ctx);
-
-    /**
-     * Send static records at the head of the stream.  This is called once,
-     * after the Image and Domain headers are written.
-     */
-    int (*static_data)(struct xc_sr_context *ctx);
-
-    /**
-     * Send dynamic records which need to be at the start of the stream.  This
-     * is called after the STATIC_DATA_END record is written.
-     */
-    int (*start_of_stream)(struct xc_sr_context *ctx);
-
-    /**
-     * Send records which need to be at the start of a checkpoint.  This is
-     * called once, or once per checkpoint in a checkpointed stream, and is
-     * ahead of memory data.
-     */
-    int (*start_of_checkpoint)(struct xc_sr_context *ctx);
-
-    /**
-     * Send records which need to be at the end of the checkpoint.  This is
-     * called once, or once per checkpoint in a checkpointed stream, and is
-     * after the memory data.
-     */
-    int (*end_of_checkpoint)(struct xc_sr_context *ctx);
-
-    /**
-     * Check state of guest to decide whether it makes sense to continue
-     * migration.  This is called in each iteration or checkpoint to check
-     * whether all criteria for the migration are still met.  If that's not
-     * the case either migration is cancelled via a bad rc or the situation
-     * is handled, e.g. by sending appropriate records.
-     */
-    int (*check_vm_state)(struct xc_sr_context *ctx);
-
-    /**
-     * Clean up the local environment.  Will be called exactly once, either
-     * after a successful save, or upon encountering an error.
-     */
-    int (*cleanup)(struct xc_sr_context *ctx);
-};
-
-
-/**
- * Restore operations.  To be implemented for each type of guest, for use by
- * the common restore algorithm.
- *
- * Every function must be implemented, even if only with a no-op stub.
- */
-struct xc_sr_restore_ops
-{
-    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
-    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /* Check to see whether a PFN is valid. */
-    bool (*pfn_is_valid)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /* Set the GFN of a PFN. */
-    void (*set_gfn)(struct xc_sr_context *ctx, xen_pfn_t pfn, xen_pfn_t gfn);
-
-    /* Set the type of a PFN. */
-    void (*set_page_type)(struct xc_sr_context *ctx, xen_pfn_t pfn,
-                          xen_pfn_t type);
-
-    /**
-     * Optionally transform the contents of a page from being generic in the
-     * stream, to being specific to the restoring environment.
-     *
-     * 'page' is expected to be modified in-place if a transformation is
-     * required.
-     *
-     * @returns 0 for success, -1 for failure, with errno appropriately set.
-     */
-    int (*localise_page)(struct xc_sr_context *ctx, uint32_t type, void *page);
-
-    /**
-     * Set up local environment to restore a domain.
-     *
-     * This is called once before any common setup has occurred, allowing for
-     * guest-specific adjustments to be made to common state.
-     */
-    int (*setup)(struct xc_sr_context *ctx);
-
-    /**
-     * Process an individual record from the stream.  The caller shall take
-     * care of processing common records (e.g. END, PAGE_DATA).
-     *
-     * @return 0 for success, -1 for failure, or the following sentinels:
-     *  - RECORD_NOT_PROCESSED
-     *  - BROKEN_CHANNEL: under Remus/COLO, this means master may be dead, and
-     *    a failover is needed.
-     */
-#define RECORD_NOT_PROCESSED 1
-#define BROKEN_CHANNEL 2
-    int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
-
-    /**
-     * Perform any actions required after the static data has arrived.  Called
-     * when the STATIC_DATA_COMPLETE record has been recieved/inferred.
-     * 'missing' should be filled in for any data item the higher level
-     * toolstack needs to provide compatiblity for.
-     */
-    int (*static_data_complete)(struct xc_sr_context *ctx,
-                                unsigned int *missing);
-
-    /**
-     * Perform any actions required after the stream has been finished. Called
-     * after the END record has been received.
-     */
-    int (*stream_complete)(struct xc_sr_context *ctx);
-
-    /**
-     * Clean up the local environment.  Will be called exactly once, either
-     * after a successful restore, or upon encountering an error.
-     */
-    int (*cleanup)(struct xc_sr_context *ctx);
-};
-
-/* Wrapper for blobs of data heading Xen-wards. */
-struct xc_sr_blob
-{
-    void *ptr;
-    size_t size;
-};
-
-/*
- * Update a blob.  Duplicate src/size, freeing the old blob if necessary.  May
- * fail due to memory allocation.
- */
-static inline int update_blob(struct xc_sr_blob *blob,
-                              const void *src, size_t size)
-{
-    void *ptr;
-
-    if ( !src || !size )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( (ptr = malloc(size)) == NULL )
-        return -1;
-
-    free(blob->ptr);
-    blob->ptr = memcpy(ptr, src, size);
-    blob->size = size;
-
-    return 0;
-}
-
-struct xc_sr_context
-{
-    xc_interface *xch;
-    uint32_t domid;
-    int fd;
-
-    /* Plain VM, or checkpoints over time. */
-    xc_stream_type_t stream_type;
-
-    xc_dominfo_t dominfo;
-
-    union /* Common save or restore data. */
-    {
-        struct /* Save data. */
-        {
-            int recv_fd;
-
-            struct xc_sr_save_ops ops;
-            struct save_callbacks *callbacks;
-
-            /* Live migrate vs non live suspend. */
-            bool live;
-
-            /* Further debugging information in the stream. */
-            bool debug;
-
-            unsigned long p2m_size;
-
-            struct precopy_stats stats;
-
-            xen_pfn_t *batch_pfns;
-            unsigned int nr_batch_pfns;
-            unsigned long *deferred_pages;
-            unsigned long nr_deferred_pages;
-            xc_hypercall_buffer_t dirty_bitmap_hbuf;
-        } save;
-
-        struct /* Restore data. */
-        {
-            struct xc_sr_restore_ops ops;
-            struct restore_callbacks *callbacks;
-
-            int send_back_fd;
-            unsigned long p2m_size;
-            xc_hypercall_buffer_t dirty_bitmap_hbuf;
-
-            /* From Image Header. */
-            uint32_t format_version;
-
-            /* From Domain Header. */
-            uint32_t guest_type;
-            uint32_t guest_page_size;
-
-            /* Currently buffering records between a checkpoint */
-            bool buffer_all_records;
-
-            /* Whether a STATIC_DATA_END record has been seen/inferred. */
-            bool seen_static_data_end;
-
-/*
- * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
- * in case the primary will fail, we can recover from the last
- * checkpoint state.
- * This should be enough for most of the cases because primary only send
- * dirty pages at checkpoint.
- */
-#define DEFAULT_BUF_RECORDS 1024
-            struct xc_sr_record *buffered_records;
-            unsigned int allocated_rec_num;
-            unsigned int buffered_rec_num;
-
-            /*
-             * Xenstore and Console parameters.
-             * INPUT:  evtchn & domid
-             * OUTPUT: gfn
-             */
-            xen_pfn_t    xenstore_gfn,    console_gfn;
-            unsigned int xenstore_evtchn, console_evtchn;
-            uint32_t     xenstore_domid,  console_domid;
-
-            /* Bitmap of currently populated PFNs during restore. */
-            unsigned long *populated_pfns;
-            xen_pfn_t max_populated_pfn;
-
-            /* Sender has invoked verify mode on the stream. */
-            bool verify;
-        } restore;
-    };
-
-    union /* Guest-arch specific data. */
-    {
-        struct /* x86 */
-        {
-            /* Common save/restore data. */
-            union
-            {
-                struct
-                {
-                    /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */
-                    struct xc_sr_blob cpuid, msr;
-                } restore;
-            };
-
-            struct /* x86 PV guest. */
-            {
-                /* 4 or 8; 32 or 64 bit domain */
-                unsigned int width;
-                /* 3 or 4 pagetable levels */
-                unsigned int levels;
-
-                /* Maximum Xen frame */
-                xen_pfn_t max_mfn;
-                /* Read-only machine to phys map */
-                xen_pfn_t *m2p;
-                /* first mfn of the compat m2p (Only needed for 32bit PV guests) */
-                xen_pfn_t compat_m2p_mfn0;
-                /* Number of m2p frames mapped */
-                unsigned long nr_m2p_frames;
-
-                /* Maximum guest frame */
-                xen_pfn_t max_pfn;
-
-                /* Number of frames making up the p2m */
-                unsigned int p2m_frames;
-                /* Guest's phys to machine map.  Mapped read-only (save) or
-                 * allocated locally (restore).  Uses guest unsigned longs. */
-                void *p2m;
-                /* The guest pfns containing the p2m leaves */
-                xen_pfn_t *p2m_pfns;
-
-                /* Read-only mapping of guests shared info page */
-                shared_info_any_t *shinfo;
-
-                /* p2m generation count for verifying validity of local p2m. */
-                uint64_t p2m_generation;
-
-                union
-                {
-                    struct
-                    {
-                        /* State machine for the order of received records. */
-                        bool seen_pv_info;
-
-                        /* Types for each page (bounded by max_pfn). */
-                        uint32_t *pfn_types;
-
-                        /* x86 PV per-vcpu storage structure for blobs. */
-                        struct xc_sr_x86_pv_restore_vcpu
-                        {
-                            struct xc_sr_blob basic, extd, xsave, msr;
-                        } *vcpus;
-                        unsigned int nr_vcpus;
-                    } restore;
-                };
-            } pv;
-
-            struct /* x86 HVM guest. */
-            {
-                union
-                {
-                    struct
-                    {
-                        /* Whether qemu enabled logdirty mode, and we should
-                         * disable on cleanup. */
-                        bool qemu_enabled_logdirty;
-                    } save;
-
-                    struct
-                    {
-                        /* HVM context blob. */
-                        struct xc_sr_blob context;
-                    } restore;
-                };
-            } hvm;
-
-        } x86;
-    };
-};
-
-extern struct xc_sr_save_ops save_ops_x86_pv;
-extern struct xc_sr_save_ops save_ops_x86_hvm;
-
-extern struct xc_sr_restore_ops restore_ops_x86_pv;
-extern struct xc_sr_restore_ops restore_ops_x86_hvm;
-
-struct xc_sr_record
-{
-    uint32_t type;
-    uint32_t length;
-    void *data;
-};
-
-/*
- * Writes a split record to the stream, applying correct padding where
- * appropriate.  It is common when sending records containing blobs from Xen
- * that the header and blob data are separate.  This function accepts a second
- * buffer and length, and will merge it with the main record when sending.
- *
- * Records with a non-zero length must provide a valid data field; records
- * with a 0 length shall have their data field ignored.
- *
- * Returns 0 on success and non0 on failure.
- */
-int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
-                       void *buf, size_t sz);
-
-/*
- * Writes a record to the stream, applying correct padding where appropriate.
- * Records with a non-zero length must provide a valid data field; records
- * with a 0 length shall have their data field ignored.
- *
- * Returns 0 on success and non0 on failure.
- */
-static inline int write_record(struct xc_sr_context *ctx,
-                               struct xc_sr_record *rec)
-{
-    return write_split_record(ctx, rec, NULL, 0);
-}
-
-/*
- * Reads a record from the stream, and fills in the record structure.
- *
- * Returns 0 on success and non-0 on failure.
- *
- * On success, the records type and size shall be valid.
- * - If size is 0, data shall be NULL.
- * - If size is non-0, data shall be a buffer allocated by malloc() which must
- *   be passed to free() by the caller.
- *
- * On failure, the contents of the record structure are undefined.
- */
-int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
-
-/*
- * This would ideally be private in restore.c, but is needed by
- * x86_pv_localise_page() if we receive pagetables frames ahead of the
- * contents of the frames they point at.
- */
-int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
-                  const xen_pfn_t *original_pfns, const uint32_t *types);
-
-/* Handle a STATIC_DATA_END record. */
-int handle_static_data_end(struct xc_sr_context *ctx);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h
deleted file mode 100644
index e08d81e0e7..0000000000
--- a/tools/libxc/xc_sr_common_x86.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef __COMMON_X86__H
-#define __COMMON_X86__H
-
-#include "xc_sr_common.h"
-
-/*
- * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO record
- * into the stream.
- */
-int write_x86_tsc_info(struct xc_sr_context *ctx);
-
-/*
- * Parses a X86_TSC_INFO record and applies the result to the domain.
- */
-int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
-
-/*
- * Obtains a domains CPU Policy from Xen, and writes X86_{CPUID,MSR}_POLICY
- * records into the stream.
- */
-int write_x86_cpu_policy_records(struct xc_sr_context *ctx);
-
-/*
- * Parses an X86_CPUID_POLICY record and stashes the content for application
- * when a STATIC_DATA_END record is encountered.
- */
-int handle_x86_cpuid_policy(struct xc_sr_context *ctx,
-                            struct xc_sr_record *rec);
-
-/*
- * Parses an X86_MSR_POLICY record and stashes the content for application
- * when a STATIC_DATA_END record is encountered.
- */
-int handle_x86_msr_policy(struct xc_sr_context *ctx,
-                          struct xc_sr_record *rec);
-
-/*
- * Perform common x86 actions required after the static data has arrived.
- */
-int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_common_x86_pv.h b/tools/libxc/xc_sr_common_x86_pv.h
deleted file mode 100644
index 2ed03309af..0000000000
--- a/tools/libxc/xc_sr_common_x86_pv.h
+++ /dev/null
@@ -1,109 +0,0 @@
-#ifndef __COMMON_X86_PV_H
-#define __COMMON_X86_PV_H
-
-#include "xc_sr_common_x86.h"
-
-/* Virtual address ranges reserved for hypervisor. */
-#define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL
-#define HYPERVISOR_VIRT_END_X86_64   0xFFFF87FFFFFFFFFFULL
-
-#define HYPERVISOR_VIRT_START_X86_32 0x00000000F5800000ULL
-#define HYPERVISOR_VIRT_END_X86_32   0x00000000FFFFFFFFULL
-
-/*
- * Convert an mfn to a pfn, given Xen's m2p table.
- *
- * Caller must ensure that the requested mfn is in range.
- */
-xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Query whether a particular mfn is valid in the physmap of a guest.
- */
-bool mfn_in_pseudophysmap(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Debug a particular mfn by walking the p2m and m2p.
- */
-void dump_bad_pseudophysmap_entry(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Convert a PV cr3 field to an mfn.
- *
- * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
- * a 32bit architectural cr3.
- */
-xen_pfn_t cr3_to_mfn(struct xc_sr_context *ctx, uint64_t cr3);
-
-/*
- * Convert an mfn to a PV cr3 field.
- *
- * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
- * a 32bit architectural cr3.
- */
-uint64_t mfn_to_cr3(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/* Bits 12 through 51 of a PTE point at the frame */
-#define PTE_FRAME_MASK 0x000ffffffffff000ULL
-
-/*
- * Extract an mfn from a Pagetable Entry.  May return INVALID_MFN if the pte
- * would overflow a 32bit xen_pfn_t.
- */
-static inline xen_pfn_t pte_to_frame(uint64_t pte)
-{
-    uint64_t frame = (pte & PTE_FRAME_MASK) >> PAGE_SHIFT;
-
-#ifdef __i386__
-    if ( frame >= INVALID_MFN )
-        return INVALID_MFN;
-#endif
-
-    return frame;
-}
-
-/*
- * Change the frame in a Pagetable Entry while leaving the flags alone.
- */
-static inline uint64_t merge_pte(uint64_t pte, xen_pfn_t mfn)
-{
-    return (pte & ~PTE_FRAME_MASK) | ((uint64_t)mfn << PAGE_SHIFT);
-}
-
-/*
- * Get current domain information.
- *
- * Fills ctx->x86.pv
- * - .width
- * - .levels
- * - .fpp
- * - .p2m_frames
- *
- * Used by the save side to create the X86_PV_INFO record, and by the restore
- * side to verify the incoming stream.
- *
- * Returns 0 on success and non-zero on error.
- */
-int x86_pv_domain_info(struct xc_sr_context *ctx);
-
-/*
- * Maps the Xen M2P.
- *
- * Fills ctx->x86.pv.
- * - .max_mfn
- * - .m2p
- *
- * Returns 0 on success and non-zero on error.
- */
-int x86_pv_map_m2p(struct xc_sr_context *ctx);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_stream_format.h b/tools/libxc/xc_sr_stream_format.h
deleted file mode 100644
index 8a0da26f75..0000000000
--- a/tools/libxc/xc_sr_stream_format.h
+++ /dev/null
@@ -1,150 +0,0 @@
-#ifndef __STREAM_FORMAT__H
-#define __STREAM_FORMAT__H
-
-/*
- * C structures for the Migration v2 stream format.
- * See docs/specs/libxc-migration-stream.pandoc
- */
-
-#include <inttypes.h>
-
-/*
- * Image Header
- */
-struct xc_sr_ihdr
-{
-    uint64_t marker;
-    uint32_t id;
-    uint32_t version;
-    uint16_t options;
-    uint16_t _res1;
-    uint32_t _res2;
-};
-
-#define IHDR_MARKER  0xffffffffffffffffULL
-#define IHDR_ID      0x58454E46U
-
-#define _IHDR_OPT_ENDIAN 0
-#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
-#define IHDR_OPT_BIG_ENDIAN    (1 << _IHDR_OPT_ENDIAN)
-
-/*
- * Domain Header
- */
-struct xc_sr_dhdr
-{
-    uint32_t type;
-    uint16_t page_shift;
-    uint16_t _res1;
-    uint32_t xen_major;
-    uint32_t xen_minor;
-};
-
-#define DHDR_TYPE_X86_PV  0x00000001U
-#define DHDR_TYPE_X86_HVM 0x00000002U
-
-/*
- * Record Header
- */
-struct xc_sr_rhdr
-{
-    uint32_t type;
-    uint32_t length;
-};
-
-/* All records must be aligned up to an 8 octet boundary */
-#define REC_ALIGN_ORDER               (3U)
-/* Somewhat arbitrary - 128MB */
-#define REC_LENGTH_MAX                (128U << 20)
-
-#define REC_TYPE_END                        0x00000000U
-#define REC_TYPE_PAGE_DATA                  0x00000001U
-#define REC_TYPE_X86_PV_INFO                0x00000002U
-#define REC_TYPE_X86_PV_P2M_FRAMES          0x00000003U
-#define REC_TYPE_X86_PV_VCPU_BASIC          0x00000004U
-#define REC_TYPE_X86_PV_VCPU_EXTENDED       0x00000005U
-#define REC_TYPE_X86_PV_VCPU_XSAVE          0x00000006U
-#define REC_TYPE_SHARED_INFO                0x00000007U
-#define REC_TYPE_X86_TSC_INFO               0x00000008U
-#define REC_TYPE_HVM_CONTEXT                0x00000009U
-#define REC_TYPE_HVM_PARAMS                 0x0000000aU
-#define REC_TYPE_TOOLSTACK                  0x0000000bU
-#define REC_TYPE_X86_PV_VCPU_MSRS           0x0000000cU
-#define REC_TYPE_VERIFY                     0x0000000dU
-#define REC_TYPE_CHECKPOINT                 0x0000000eU
-#define REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST  0x0000000fU
-#define REC_TYPE_STATIC_DATA_END            0x00000010U
-#define REC_TYPE_X86_CPUID_POLICY           0x00000011U
-#define REC_TYPE_X86_MSR_POLICY             0x00000012U
-
-#define REC_TYPE_OPTIONAL             0x80000000U
-
-/* PAGE_DATA */
-struct xc_sr_rec_page_data_header
-{
-    uint32_t count;
-    uint32_t _res1;
-    uint64_t pfn[0];
-};
-
-#define PAGE_DATA_PFN_MASK  0x000fffffffffffffULL
-#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
-
-/* X86_PV_INFO */
-struct xc_sr_rec_x86_pv_info
-{
-    uint8_t guest_width;
-    uint8_t pt_levels;
-    uint8_t _res[6];
-};
-
-/* X86_PV_P2M_FRAMES */
-struct xc_sr_rec_x86_pv_p2m_frames
-{
-    uint32_t start_pfn;
-    uint32_t end_pfn;
-    uint64_t p2m_pfns[0];
-};
-
-/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */
-struct xc_sr_rec_x86_pv_vcpu_hdr
-{
-    uint32_t vcpu_id;
-    uint32_t _res1;
-    uint8_t context[0];
-};
-
-/* X86_TSC_INFO */
-struct xc_sr_rec_x86_tsc_info
-{
-    uint32_t mode;
-    uint32_t khz;
-    uint64_t nsec;
-    uint32_t incarnation;
-    uint32_t _res1;
-};
-
-/* HVM_PARAMS */
-struct xc_sr_rec_hvm_params_entry
-{
-    uint64_t index;
-    uint64_t value;
-};
-
-struct xc_sr_rec_hvm_params
-{
-    uint32_t count;
-    uint32_t _res1;
-    struct xc_sr_rec_hvm_params_entry param[0];
-};
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xg_dom_bzimageloader.c b/tools/libxc/xg_dom_bzimageloader.c
index a7d70cc7c6..f959a77602 100644
--- a/tools/libxc/xg_dom_bzimageloader.c
+++ b/tools/libxc/xg_dom_bzimageloader.c
@@ -32,7 +32,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress.h"
+#include "xg_dom_decompress.h"
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxc/xg_dom_decompress.h b/tools/libxc/xg_dom_decompress.h
new file mode 100644
index 0000000000..d9a21cf297
--- /dev/null
+++ b/tools/libxc/xg_dom_decompress.h
@@ -0,0 +1,8 @@
+#ifndef __MINIOS__
+# include "xc_dom.h"
+#else
+# include "xg_dom_decompress_unsafe.h"
+#endif
+
+int xc_try_lz4_decode(struct xc_dom_image *dom, void **blob, size_t *size);
+
diff --git a/tools/libxc/xg_dom_decompress_lz4.c b/tools/libxc/xg_dom_decompress_lz4.c
index b6a33f27a8..97ba620d86 100644
--- a/tools/libxc/xg_dom_decompress_lz4.c
+++ b/tools/libxc/xg_dom_decompress_lz4.c
@@ -4,7 +4,7 @@
 #include <stdint.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress.h"
+#include "xg_dom_decompress.h"
 
 #define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe.c b/tools/libxc/xg_dom_decompress_unsafe.c
index 164e35558f..21d964787d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe.c
+++ b/tools/libxc/xg_dom_decompress_unsafe.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 static struct xc_dom_image *unsafe_dom;
 static unsigned char *output_blob;
diff --git a/tools/libxc/xg_dom_decompress_unsafe.h b/tools/libxc/xg_dom_decompress_unsafe.h
new file mode 100644
index 0000000000..64f68864b1
--- /dev/null
+++ b/tools/libxc/xg_dom_decompress_unsafe.h
@@ -0,0 +1,20 @@
+#include "xc_dom.h"
+
+typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
+                          int (*fill)(void*, unsigned int),
+                          int (*flush)(void*, unsigned int),
+                          unsigned char *outbuf, unsigned int *posp,
+                          void (*error)(const char *x));
+
+int xc_dom_decompress_unsafe(
+    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+
+int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
diff --git a/tools/libxc/xg_dom_decompress_unsafe_bzip2.c b/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
index 4dcabe4061..9d3709e6cc 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 #include "../../xen/common/bunzip2.c"
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe_lzma.c b/tools/libxc/xg_dom_decompress_unsafe_lzma.c
index 4ee8cdbab1..5d178f0c43 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_lzma.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_lzma.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 #include "../../xen/common/unlzma.c"
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c b/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
index 59888b9da2..a4f8ebd42d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
@@ -5,7 +5,7 @@
 #include <stdint.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 typedef uint8_t u8;
 typedef uint32_t u32;
diff --git a/tools/libxc/xg_dom_decompress_unsafe_xz.c b/tools/libxc/xg_dom_decompress_unsafe_xz.c
index fe7a7f49b4..ff6824b38d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_xz.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_xz.c
@@ -6,7 +6,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 // TODO
 #define XZ_DEC_X86
diff --git a/tools/libxc/xg_sr_common.c b/tools/libxc/xg_sr_common.c
index 7c54b03414..17567ab133 100644
--- a/tools/libxc/xg_sr_common.c
+++ b/tools/libxc/xg_sr_common.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxc/xg_sr_common.h b/tools/libxc/xg_sr_common.h
new file mode 100644
index 0000000000..35f23fabb5
--- /dev/null
+++ b/tools/libxc/xg_sr_common.h
@@ -0,0 +1,468 @@
+#ifndef __COMMON__H
+#define __COMMON__H
+
+#include <stdbool.h>
+
+#include "xg_private.h"
+#include "xg_save_restore.h"
+#include "xc_dom.h"
+#include "xc_bitops.h"
+
+#include "xg_sr_stream_format.h"
+
+/* String representation of Domain Header types. */
+const char *dhdr_type_to_str(uint32_t type);
+
+/* String representation of Record types. */
+const char *rec_type_to_str(uint32_t type);
+
+struct xc_sr_context;
+struct xc_sr_record;
+
+/**
+ * Save operations.  To be implemented for each type of guest, for use by the
+ * common save algorithm.
+ *
+ * Every function must be implemented, even if only with a no-op stub.
+ */
+struct xc_sr_save_ops
+{
+    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
+    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /**
+     * Optionally transform the contents of a page from being specific to the
+     * sending environment, to being generic for the stream.
+     *
+     * The page of data at the end of 'page' may be a read-only mapping of a
+     * running guest; it must not be modified.  If no transformation is
+     * required, the callee should leave '*pages' untouched.
+     *
+     * If a transformation is required, the callee should allocate themselves
+     * a local page using malloc() and return it via '*page'.
+     *
+     * The caller shall free() '*page' in all cases.  In the case that the
+     * callee encounters an error, it should *NOT* free() the memory it
+     * allocated for '*page'.
+     *
+     * It is valid to fail with EAGAIN if the transformation is not able to be
+     * completed at this point.  The page shall be retried later.
+     *
+     * @returns 0 for success, -1 for failure, with errno appropriately set.
+     */
+    int (*normalise_page)(struct xc_sr_context *ctx, xen_pfn_t type,
+                          void **page);
+
+    /**
+     * Set up local environment to save a domain. (Typically querying
+     * running domain state, setting up mappings etc.)
+     *
+     * This is called once before any common setup has occurred, allowing for
+     * guest-specific adjustments to be made to common state.
+     */
+    int (*setup)(struct xc_sr_context *ctx);
+
+    /**
+     * Send static records at the head of the stream.  This is called once,
+     * after the Image and Domain headers are written.
+     */
+    int (*static_data)(struct xc_sr_context *ctx);
+
+    /**
+     * Send dynamic records which need to be at the start of the stream.  This
+     * is called after the STATIC_DATA_END record is written.
+     */
+    int (*start_of_stream)(struct xc_sr_context *ctx);
+
+    /**
+     * Send records which need to be at the start of a checkpoint.  This is
+     * called once, or once per checkpoint in a checkpointed stream, and is
+     * ahead of memory data.
+     */
+    int (*start_of_checkpoint)(struct xc_sr_context *ctx);
+
+    /**
+     * Send records which need to be at the end of the checkpoint.  This is
+     * called once, or once per checkpoint in a checkpointed stream, and is
+     * after the memory data.
+     */
+    int (*end_of_checkpoint)(struct xc_sr_context *ctx);
+
+    /**
+     * Check state of guest to decide whether it makes sense to continue
+     * migration.  This is called in each iteration or checkpoint to check
+     * whether all criteria for the migration are still met.  If that's not
+     * the case either migration is cancelled via a bad rc or the situation
+     * is handled, e.g. by sending appropriate records.
+     */
+    int (*check_vm_state)(struct xc_sr_context *ctx);
+
+    /**
+     * Clean up the local environment.  Will be called exactly once, either
+     * after a successful save, or upon encountering an error.
+     */
+    int (*cleanup)(struct xc_sr_context *ctx);
+};
+
+
+/**
+ * Restore operations.  To be implemented for each type of guest, for use by
+ * the common restore algorithm.
+ *
+ * Every function must be implemented, even if only with a no-op stub.
+ */
+struct xc_sr_restore_ops
+{
+    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
+    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /* Check to see whether a PFN is valid. */
+    bool (*pfn_is_valid)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /* Set the GFN of a PFN. */
+    void (*set_gfn)(struct xc_sr_context *ctx, xen_pfn_t pfn, xen_pfn_t gfn);
+
+    /* Set the type of a PFN. */
+    void (*set_page_type)(struct xc_sr_context *ctx, xen_pfn_t pfn,
+                          xen_pfn_t type);
+
+    /**
+     * Optionally transform the contents of a page from being generic in the
+     * stream, to being specific to the restoring environment.
+     *
+     * 'page' is expected to be modified in-place if a transformation is
+     * required.
+     *
+     * @returns 0 for success, -1 for failure, with errno appropriately set.
+     */
+    int (*localise_page)(struct xc_sr_context *ctx, uint32_t type, void *page);
+
+    /**
+     * Set up local environment to restore a domain.
+     *
+     * This is called once before any common setup has occurred, allowing for
+     * guest-specific adjustments to be made to common state.
+     */
+    int (*setup)(struct xc_sr_context *ctx);
+
+    /**
+     * Process an individual record from the stream.  The caller shall take
+     * care of processing common records (e.g. END, PAGE_DATA).
+     *
+     * @return 0 for success, -1 for failure, or the following sentinels:
+     *  - RECORD_NOT_PROCESSED
+     *  - BROKEN_CHANNEL: under Remus/COLO, this means master may be dead, and
+     *    a failover is needed.
+     */
+#define RECORD_NOT_PROCESSED 1
+#define BROKEN_CHANNEL 2
+    int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+
+    /**
+     * Perform any actions required after the static data has arrived.  Called
+     * when the STATIC_DATA_COMPLETE record has been recieved/inferred.
+     * 'missing' should be filled in for any data item the higher level
+     * toolstack needs to provide compatiblity for.
+     */
+    int (*static_data_complete)(struct xc_sr_context *ctx,
+                                unsigned int *missing);
+
+    /**
+     * Perform any actions required after the stream has been finished. Called
+     * after the END record has been received.
+     */
+    int (*stream_complete)(struct xc_sr_context *ctx);
+
+    /**
+     * Clean up the local environment.  Will be called exactly once, either
+     * after a successful restore, or upon encountering an error.
+     */
+    int (*cleanup)(struct xc_sr_context *ctx);
+};
+
+/* Wrapper for blobs of data heading Xen-wards. */
+struct xc_sr_blob
+{
+    void *ptr;
+    size_t size;
+};
+
+/*
+ * Update a blob.  Duplicate src/size, freeing the old blob if necessary.  May
+ * fail due to memory allocation.
+ */
+static inline int update_blob(struct xc_sr_blob *blob,
+                              const void *src, size_t size)
+{
+    void *ptr;
+
+    if ( !src || !size )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    if ( (ptr = malloc(size)) == NULL )
+        return -1;
+
+    free(blob->ptr);
+    blob->ptr = memcpy(ptr, src, size);
+    blob->size = size;
+
+    return 0;
+}
+
+struct xc_sr_context
+{
+    xc_interface *xch;
+    uint32_t domid;
+    int fd;
+
+    /* Plain VM, or checkpoints over time. */
+    xc_stream_type_t stream_type;
+
+    xc_dominfo_t dominfo;
+
+    union /* Common save or restore data. */
+    {
+        struct /* Save data. */
+        {
+            int recv_fd;
+
+            struct xc_sr_save_ops ops;
+            struct save_callbacks *callbacks;
+
+            /* Live migrate vs non live suspend. */
+            bool live;
+
+            /* Further debugging information in the stream. */
+            bool debug;
+
+            unsigned long p2m_size;
+
+            struct precopy_stats stats;
+
+            xen_pfn_t *batch_pfns;
+            unsigned int nr_batch_pfns;
+            unsigned long *deferred_pages;
+            unsigned long nr_deferred_pages;
+            xc_hypercall_buffer_t dirty_bitmap_hbuf;
+        } save;
+
+        struct /* Restore data. */
+        {
+            struct xc_sr_restore_ops ops;
+            struct restore_callbacks *callbacks;
+
+            int send_back_fd;
+            unsigned long p2m_size;
+            xc_hypercall_buffer_t dirty_bitmap_hbuf;
+
+            /* From Image Header. */
+            uint32_t format_version;
+
+            /* From Domain Header. */
+            uint32_t guest_type;
+            uint32_t guest_page_size;
+
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+            /* Whether a STATIC_DATA_END record has been seen/inferred. */
+            bool seen_static_data_end;
+
+/*
+ * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough for most of the cases because primary only send
+ * dirty pages at checkpoint.
+ */
+#define DEFAULT_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned int allocated_rec_num;
+            unsigned int buffered_rec_num;
+
+            /*
+             * Xenstore and Console parameters.
+             * INPUT:  evtchn & domid
+             * OUTPUT: gfn
+             */
+            xen_pfn_t    xenstore_gfn,    console_gfn;
+            unsigned int xenstore_evtchn, console_evtchn;
+            uint32_t     xenstore_domid,  console_domid;
+
+            /* Bitmap of currently populated PFNs during restore. */
+            unsigned long *populated_pfns;
+            xen_pfn_t max_populated_pfn;
+
+            /* Sender has invoked verify mode on the stream. */
+            bool verify;
+        } restore;
+    };
+
+    union /* Guest-arch specific data. */
+    {
+        struct /* x86 */
+        {
+            /* Common save/restore data. */
+            union
+            {
+                struct
+                {
+                    /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */
+                    struct xc_sr_blob cpuid, msr;
+                } restore;
+            };
+
+            struct /* x86 PV guest. */
+            {
+                /* 4 or 8; 32 or 64 bit domain */
+                unsigned int width;
+                /* 3 or 4 pagetable levels */
+                unsigned int levels;
+
+                /* Maximum Xen frame */
+                xen_pfn_t max_mfn;
+                /* Read-only machine to phys map */
+                xen_pfn_t *m2p;
+                /* first mfn of the compat m2p (Only needed for 32bit PV guests) */
+                xen_pfn_t compat_m2p_mfn0;
+                /* Number of m2p frames mapped */
+                unsigned long nr_m2p_frames;
+
+                /* Maximum guest frame */
+                xen_pfn_t max_pfn;
+
+                /* Number of frames making up the p2m */
+                unsigned int p2m_frames;
+                /* Guest's phys to machine map.  Mapped read-only (save) or
+                 * allocated locally (restore).  Uses guest unsigned longs. */
+                void *p2m;
+                /* The guest pfns containing the p2m leaves */
+                xen_pfn_t *p2m_pfns;
+
+                /* Read-only mapping of guests shared info page */
+                shared_info_any_t *shinfo;
+
+                /* p2m generation count for verifying validity of local p2m. */
+                uint64_t p2m_generation;
+
+                union
+                {
+                    struct
+                    {
+                        /* State machine for the order of received records. */
+                        bool seen_pv_info;
+
+                        /* Types for each page (bounded by max_pfn). */
+                        uint32_t *pfn_types;
+
+                        /* x86 PV per-vcpu storage structure for blobs. */
+                        struct xc_sr_x86_pv_restore_vcpu
+                        {
+                            struct xc_sr_blob basic, extd, xsave, msr;
+                        } *vcpus;
+                        unsigned int nr_vcpus;
+                    } restore;
+                };
+            } pv;
+
+            struct /* x86 HVM guest. */
+            {
+                union
+                {
+                    struct
+                    {
+                        /* Whether qemu enabled logdirty mode, and we should
+                         * disable on cleanup. */
+                        bool qemu_enabled_logdirty;
+                    } save;
+
+                    struct
+                    {
+                        /* HVM context blob. */
+                        struct xc_sr_blob context;
+                    } restore;
+                };
+            } hvm;
+
+        } x86;
+    };
+};
+
+extern struct xc_sr_save_ops save_ops_x86_pv;
+extern struct xc_sr_save_ops save_ops_x86_hvm;
+
+extern struct xc_sr_restore_ops restore_ops_x86_pv;
+extern struct xc_sr_restore_ops restore_ops_x86_hvm;
+
+struct xc_sr_record
+{
+    uint32_t type;
+    uint32_t length;
+    void *data;
+};
+
+/*
+ * Writes a split record to the stream, applying correct padding where
+ * appropriate.  It is common when sending records containing blobs from Xen
+ * that the header and blob data are separate.  This function accepts a second
+ * buffer and length, and will merge it with the main record when sending.
+ *
+ * Records with a non-zero length must provide a valid data field; records
+ * with a 0 length shall have their data field ignored.
+ *
+ * Returns 0 on success and non0 on failure.
+ */
+int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
+                       void *buf, size_t sz);
+
+/*
+ * Writes a record to the stream, applying correct padding where appropriate.
+ * Records with a non-zero length must provide a valid data field; records
+ * with a 0 length shall have their data field ignored.
+ *
+ * Returns 0 on success and non0 on failure.
+ */
+static inline int write_record(struct xc_sr_context *ctx,
+                               struct xc_sr_record *rec)
+{
+    return write_split_record(ctx, rec, NULL, 0);
+}
+
+/*
+ * Reads a record from the stream, and fills in the record structure.
+ *
+ * Returns 0 on success and non-0 on failure.
+ *
+ * On success, the records type and size shall be valid.
+ * - If size is 0, data shall be NULL.
+ * - If size is non-0, data shall be a buffer allocated by malloc() which must
+ *   be passed to free() by the caller.
+ *
+ * On failure, the contents of the record structure are undefined.
+ */
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
+
+/*
+ * This would ideally be private in restore.c, but is needed by
+ * x86_pv_localise_page() if we receive pagetables frames ahead of the
+ * contents of the frames they point at.
+ */
+int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
+                  const xen_pfn_t *original_pfns, const uint32_t *types);
+
+/* Handle a STATIC_DATA_END record. */
+int handle_static_data_end(struct xc_sr_context *ctx);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_common_x86.c b/tools/libxc/xg_sr_common_x86.c
index 77ea044a74..6f12483907 100644
--- a/tools/libxc/xg_sr_common_x86.c
+++ b/tools/libxc/xg_sr_common_x86.c
@@ -1,4 +1,4 @@
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 int write_x86_tsc_info(struct xc_sr_context *ctx)
 {
diff --git a/tools/libxc/xg_sr_common_x86.h b/tools/libxc/xg_sr_common_x86.h
new file mode 100644
index 0000000000..b55758c96d
--- /dev/null
+++ b/tools/libxc/xg_sr_common_x86.h
@@ -0,0 +1,51 @@
+#ifndef __COMMON_X86__H
+#define __COMMON_X86__H
+
+#include "xg_sr_common.h"
+
+/*
+ * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO record
+ * into the stream.
+ */
+int write_x86_tsc_info(struct xc_sr_context *ctx);
+
+/*
+ * Parses a X86_TSC_INFO record and applies the result to the domain.
+ */
+int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+
+/*
+ * Obtains a domains CPU Policy from Xen, and writes X86_{CPUID,MSR}_POLICY
+ * records into the stream.
+ */
+int write_x86_cpu_policy_records(struct xc_sr_context *ctx);
+
+/*
+ * Parses an X86_CPUID_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_cpuid_policy(struct xc_sr_context *ctx,
+                            struct xc_sr_record *rec);
+
+/*
+ * Parses an X86_MSR_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_msr_policy(struct xc_sr_context *ctx,
+                          struct xc_sr_record *rec);
+
+/*
+ * Perform common x86 actions required after the static data has arrived.
+ */
+int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_common_x86_pv.c b/tools/libxc/xg_sr_common_x86_pv.c
index d3d425cb82..cd33406aab 100644
--- a/tools/libxc/xg_sr_common_x86_pv.c
+++ b/tools/libxc/xg_sr_common_x86_pv.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn)
 {
diff --git a/tools/libxc/xg_sr_common_x86_pv.h b/tools/libxc/xg_sr_common_x86_pv.h
new file mode 100644
index 0000000000..953b5bfb8d
--- /dev/null
+++ b/tools/libxc/xg_sr_common_x86_pv.h
@@ -0,0 +1,109 @@
+#ifndef __COMMON_X86_PV_H
+#define __COMMON_X86_PV_H
+
+#include "xg_sr_common_x86.h"
+
+/* Virtual address ranges reserved for hypervisor. */
+#define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL
+#define HYPERVISOR_VIRT_END_X86_64   0xFFFF87FFFFFFFFFFULL
+
+#define HYPERVISOR_VIRT_START_X86_32 0x00000000F5800000ULL
+#define HYPERVISOR_VIRT_END_X86_32   0x00000000FFFFFFFFULL
+
+/*
+ * Convert an mfn to a pfn, given Xen's m2p table.
+ *
+ * Caller must ensure that the requested mfn is in range.
+ */
+xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Query whether a particular mfn is valid in the physmap of a guest.
+ */
+bool mfn_in_pseudophysmap(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Debug a particular mfn by walking the p2m and m2p.
+ */
+void dump_bad_pseudophysmap_entry(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Convert a PV cr3 field to an mfn.
+ *
+ * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
+ * a 32bit architectural cr3.
+ */
+xen_pfn_t cr3_to_mfn(struct xc_sr_context *ctx, uint64_t cr3);
+
+/*
+ * Convert an mfn to a PV cr3 field.
+ *
+ * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
+ * a 32bit architectural cr3.
+ */
+uint64_t mfn_to_cr3(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/* Bits 12 through 51 of a PTE point at the frame */
+#define PTE_FRAME_MASK 0x000ffffffffff000ULL
+
+/*
+ * Extract an mfn from a Pagetable Entry.  May return INVALID_MFN if the pte
+ * would overflow a 32bit xen_pfn_t.
+ */
+static inline xen_pfn_t pte_to_frame(uint64_t pte)
+{
+    uint64_t frame = (pte & PTE_FRAME_MASK) >> PAGE_SHIFT;
+
+#ifdef __i386__
+    if ( frame >= INVALID_MFN )
+        return INVALID_MFN;
+#endif
+
+    return frame;
+}
+
+/*
+ * Change the frame in a Pagetable Entry while leaving the flags alone.
+ */
+static inline uint64_t merge_pte(uint64_t pte, xen_pfn_t mfn)
+{
+    return (pte & ~PTE_FRAME_MASK) | ((uint64_t)mfn << PAGE_SHIFT);
+}
+
+/*
+ * Get current domain information.
+ *
+ * Fills ctx->x86.pv
+ * - .width
+ * - .levels
+ * - .fpp
+ * - .p2m_frames
+ *
+ * Used by the save side to create the X86_PV_INFO record, and by the restore
+ * side to verify the incoming stream.
+ *
+ * Returns 0 on success and non-zero on error.
+ */
+int x86_pv_domain_info(struct xc_sr_context *ctx);
+
+/*
+ * Maps the Xen M2P.
+ *
+ * Fills ctx->x86.pv.
+ * - .max_mfn
+ * - .m2p
+ *
+ * Returns 0 on success and non-zero on error.
+ */
+int x86_pv_map_m2p(struct xc_sr_context *ctx);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_restore.c b/tools/libxc/xg_sr_restore.c
index bc811e6e3a..b57a787519 100644
--- a/tools/libxc/xg_sr_restore.c
+++ b/tools/libxc/xg_sr_restore.c
@@ -2,7 +2,7 @@
 
 #include <assert.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 /*
  * Read and validate the Image and Domain headers.
diff --git a/tools/libxc/xg_sr_restore_x86_hvm.c b/tools/libxc/xg_sr_restore_x86_hvm.c
index a77624cc9d..d6ea6f3012 100644
--- a/tools/libxc/xg_sr_restore_x86_hvm.c
+++ b/tools/libxc/xg_sr_restore_x86_hvm.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <arpa/inet.h>
 
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 /*
  * Process an HVM_CONTEXT record from the stream.
diff --git a/tools/libxc/xg_sr_restore_x86_pv.c b/tools/libxc/xg_sr_restore_x86_pv.c
index d086271efb..dc50b0f5a8 100644
--- a/tools/libxc/xg_sr_restore_x86_pv.c
+++ b/tools/libxc/xg_sr_restore_x86_pv.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 static xen_pfn_t pfn_to_mfn(const struct xc_sr_context *ctx, xen_pfn_t pfn)
 {
diff --git a/tools/libxc/xg_sr_save.c b/tools/libxc/xg_sr_save.c
index 80b1d5de1f..d74c72cba6 100644
--- a/tools/libxc/xg_sr_save.c
+++ b/tools/libxc/xg_sr_save.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <arpa/inet.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 /*
  * Writes an Image header and Domain header into the stream.
diff --git a/tools/libxc/xg_sr_save_x86_hvm.c b/tools/libxc/xg_sr_save_x86_hvm.c
index 0b2abb26bd..1634a7bc43 100644
--- a/tools/libxc/xg_sr_save_x86_hvm.c
+++ b/tools/libxc/xg_sr_save_x86_hvm.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 #include <xen/hvm/params.h>
 
diff --git a/tools/libxc/xg_sr_save_x86_pv.c b/tools/libxc/xg_sr_save_x86_pv.c
index c7e246ef4f..4964f1f7b8 100644
--- a/tools/libxc/xg_sr_save_x86_pv.c
+++ b/tools/libxc/xg_sr_save_x86_pv.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <limits.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 /* Check a 64 bit virtual address for being canonical. */
 static inline bool is_canonical_address(xen_vaddr_t vaddr)
diff --git a/tools/libxc/xg_sr_stream_format.h b/tools/libxc/xg_sr_stream_format.h
new file mode 100644
index 0000000000..8a0da26f75
--- /dev/null
+++ b/tools/libxc/xg_sr_stream_format.h
@@ -0,0 +1,150 @@
+#ifndef __STREAM_FORMAT__H
+#define __STREAM_FORMAT__H
+
+/*
+ * C structures for the Migration v2 stream format.
+ * See docs/specs/libxc-migration-stream.pandoc
+ */
+
+#include <inttypes.h>
+
+/*
+ * Image Header
+ */
+struct xc_sr_ihdr
+{
+    uint64_t marker;
+    uint32_t id;
+    uint32_t version;
+    uint16_t options;
+    uint16_t _res1;
+    uint32_t _res2;
+};
+
+#define IHDR_MARKER  0xffffffffffffffffULL
+#define IHDR_ID      0x58454E46U
+
+#define _IHDR_OPT_ENDIAN 0
+#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
+#define IHDR_OPT_BIG_ENDIAN    (1 << _IHDR_OPT_ENDIAN)
+
+/*
+ * Domain Header
+ */
+struct xc_sr_dhdr
+{
+    uint32_t type;
+    uint16_t page_shift;
+    uint16_t _res1;
+    uint32_t xen_major;
+    uint32_t xen_minor;
+};
+
+#define DHDR_TYPE_X86_PV  0x00000001U
+#define DHDR_TYPE_X86_HVM 0x00000002U
+
+/*
+ * Record Header
+ */
+struct xc_sr_rhdr
+{
+    uint32_t type;
+    uint32_t length;
+};
+
+/* All records must be aligned up to an 8 octet boundary */
+#define REC_ALIGN_ORDER               (3U)
+/* Somewhat arbitrary - 128MB */
+#define REC_LENGTH_MAX                (128U << 20)
+
+#define REC_TYPE_END                        0x00000000U
+#define REC_TYPE_PAGE_DATA                  0x00000001U
+#define REC_TYPE_X86_PV_INFO                0x00000002U
+#define REC_TYPE_X86_PV_P2M_FRAMES          0x00000003U
+#define REC_TYPE_X86_PV_VCPU_BASIC          0x00000004U
+#define REC_TYPE_X86_PV_VCPU_EXTENDED       0x00000005U
+#define REC_TYPE_X86_PV_VCPU_XSAVE          0x00000006U
+#define REC_TYPE_SHARED_INFO                0x00000007U
+#define REC_TYPE_X86_TSC_INFO               0x00000008U
+#define REC_TYPE_HVM_CONTEXT                0x00000009U
+#define REC_TYPE_HVM_PARAMS                 0x0000000aU
+#define REC_TYPE_TOOLSTACK                  0x0000000bU
+#define REC_TYPE_X86_PV_VCPU_MSRS           0x0000000cU
+#define REC_TYPE_VERIFY                     0x0000000dU
+#define REC_TYPE_CHECKPOINT                 0x0000000eU
+#define REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST  0x0000000fU
+#define REC_TYPE_STATIC_DATA_END            0x00000010U
+#define REC_TYPE_X86_CPUID_POLICY           0x00000011U
+#define REC_TYPE_X86_MSR_POLICY             0x00000012U
+
+#define REC_TYPE_OPTIONAL             0x80000000U
+
+/* PAGE_DATA */
+struct xc_sr_rec_page_data_header
+{
+    uint32_t count;
+    uint32_t _res1;
+    uint64_t pfn[0];
+};
+
+#define PAGE_DATA_PFN_MASK  0x000fffffffffffffULL
+#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
+
+/* X86_PV_INFO */
+struct xc_sr_rec_x86_pv_info
+{
+    uint8_t guest_width;
+    uint8_t pt_levels;
+    uint8_t _res[6];
+};
+
+/* X86_PV_P2M_FRAMES */
+struct xc_sr_rec_x86_pv_p2m_frames
+{
+    uint32_t start_pfn;
+    uint32_t end_pfn;
+    uint64_t p2m_pfns[0];
+};
+
+/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */
+struct xc_sr_rec_x86_pv_vcpu_hdr
+{
+    uint32_t vcpu_id;
+    uint32_t _res1;
+    uint8_t context[0];
+};
+
+/* X86_TSC_INFO */
+struct xc_sr_rec_x86_tsc_info
+{
+    uint32_t mode;
+    uint32_t khz;
+    uint64_t nsec;
+    uint32_t incarnation;
+    uint32_t _res1;
+};
+
+/* HVM_PARAMS */
+struct xc_sr_rec_hvm_params_entry
+{
+    uint64_t index;
+    uint64_t value;
+};
+
+struct xc_sr_rec_hvm_params
+{
+    uint32_t count;
+    uint32_t _res1;
+    struct xc_sr_rec_hvm_params_entry param[0];
+};
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:24 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2V-0000j8-VS; Wed, 09 Sep 2020 11:13:23 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2U-0000iz-Rn
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:22 +0000
X-Inumbo-ID: 9bddfa12-fd99-4427-88ff-95bdb9eef941
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9bddfa12-fd99-4427-88ff-95bdb9eef941;
 Wed, 09 Sep 2020 11:13:20 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=aHE56Yxy0GpzjVZnPv3/NOPrjxxKXYrGOitGKWwqoL4=; b=5dFl/VpwA/QNrHYzJSCm3fffQs
 kxSNx06ZqoJjoTTT7CyRZkK0rrOsjjuxXc5+VluHLsu3oTtrY2TtKtGVcDI6fW7b9YRbJElX5ZQRp
 YujHNAuYJJVWr+i2ZPJqtDZCXk1zKqDnDqqgqFyNgb4SLfR1ISt+xcMC8r7Yb52bySRw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2R-00066a-RW
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2R-0001Ut-QZ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/misc: rename xc_dom.h do xenctrl_dom.h
Message-Id: <E1kFy2R-0001Ut-QZ@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:13:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 068000ab05f8e8195762d3ba580758cd8ea0857b
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:30 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: rename xc_dom.h do xenctrl_dom.h
    
    For being able to disentangle lixenctrl and libxenguest headers
    xc_dom.h will need to be public. Prepare that by renaming xc_dom.h
    to xenctrl_dom.h.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 stubdom/grub/kexec.c                   |   2 +-
 tools/helpers/init-xenstore-domain.c   |   2 +-
 tools/libxc/include/xc_dom.h           | 449 ---------------------------------
 tools/libxc/include/xenctrl_dom.h      | 449 +++++++++++++++++++++++++++++++++
 tools/libxc/xc_core.c                  |   2 +-
 tools/libxc/xc_private.c               |   2 +-
 tools/libxc/xg_dom_arm.c               |   2 +-
 tools/libxc/xg_dom_armzimageloader.c   |   2 +-
 tools/libxc/xg_dom_binloader.c         |   2 +-
 tools/libxc/xg_dom_boot.c              |   2 +-
 tools/libxc/xg_dom_compat_linux.c      |   2 +-
 tools/libxc/xg_dom_core.c              |   2 +-
 tools/libxc/xg_dom_decompress.h        |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.h |   2 +-
 tools/libxc/xg_dom_elfloader.c         |   2 +-
 tools/libxc/xg_dom_hvmloader.c         |   2 +-
 tools/libxc/xg_dom_x86.c               |   2 +-
 tools/libxc/xg_offline_page.c          |   2 +-
 tools/libxc/xg_sr_common.h             |   2 +-
 tools/libxl/libxl_arm.c                |   2 +-
 tools/libxl/libxl_arm.h                |   2 +-
 tools/libxl/libxl_create.c             |   2 +-
 tools/libxl/libxl_dm.c                 |   2 +-
 tools/libxl/libxl_dom.c                |   2 +-
 tools/libxl/libxl_internal.h           |   2 +-
 tools/libxl/libxl_vnuma.c              |   2 +-
 tools/libxl/libxl_x86.c                |   2 +-
 tools/libxl/libxl_x86_acpi.c           |   2 +-
 tools/python/xen/lowlevel/xc/xc.c      |   2 +-
 tools/xcutils/readnotes.c              |   2 +-
 30 files changed, 477 insertions(+), 477 deletions(-)

diff --git a/stubdom/grub/kexec.c b/stubdom/grub/kexec.c
index 0e68b969a2..24001220a9 100644
--- a/stubdom/grub/kexec.c
+++ b/stubdom/grub/kexec.c
@@ -20,7 +20,7 @@
 #include <sys/mman.h>
 
 #include <xenctrl.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 #include <kernel.h>
 #include <console.h>
diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 4ce8299c3c..5bdb48dc80 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -8,7 +8,7 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <xenctrl.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xenstore.h>
 #include <xen/sys/xenbus_dev.h>
 #include <xen-xsm/flask/flask.h>
diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h
deleted file mode 100644
index 52a4d6c8c0..0000000000
--- a/tools/libxc/include/xc_dom.h
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _XC_DOM_H
-#define _XC_DOM_H
-
-#include <xen/libelf/libelf.h>
-#include <xenguest.h>
-
-#define INVALID_PFN ((xen_pfn_t)-1)
-#define X86_HVM_NR_SPECIAL_PAGES    8
-#define X86_HVM_END_SPECIAL_REGION  0xff000u
-#define XG_MAX_MODULES 2
-
-/* --- typedefs and structs ---------------------------------------- */
-
-typedef uint64_t xen_vaddr_t;
-typedef uint64_t xen_paddr_t;
-
-#define PRIpfn PRI_xen_pfn
-
-struct xc_dom_seg {
-    xen_vaddr_t vstart;
-    xen_vaddr_t vend;
-    xen_pfn_t pfn;
-    xen_pfn_t pages;
-};
-
-struct xc_dom_mem {
-    struct xc_dom_mem *next;
-    void *ptr;
-    enum {
-        XC_DOM_MEM_TYPE_MALLOC_INTERNAL,
-        XC_DOM_MEM_TYPE_MALLOC_EXTERNAL,
-        XC_DOM_MEM_TYPE_MMAP,
-    } type;
-    size_t len;
-    unsigned char memory[0];
-};
-
-struct xc_dom_phys {
-    struct xc_dom_phys *next;
-    void *ptr;
-    xen_pfn_t first;
-    xen_pfn_t count;
-};
-
-struct xc_dom_module {
-    void *blob;
-    size_t size;
-    void *cmdline;
-    /* If seg.vstart is non zero then the module will be loaded at that
-     * address, otherwise it will automatically placed.
-     *
-     * If automatic placement is used and the module is gzip
-     * compressed then it will be decompressed as it is loaded. If the
-     * module has been explicitly placed then it is loaded as is
-     * otherwise decompressing risks undoing the manual placement.
-     */
-    struct xc_dom_seg seg;
-};
-
-struct xc_dom_image {
-    /* files */
-    void *kernel_blob;
-    size_t kernel_size;
-    unsigned int num_modules;
-    struct xc_dom_module modules[XG_MAX_MODULES];
-    void *devicetree_blob;
-    size_t devicetree_size;
-
-    size_t max_kernel_size;
-    size_t max_module_size;
-    size_t max_devicetree_size;
-
-    /* arguments and parameters */
-    char *cmdline;
-    size_t cmdline_size;
-    uint32_t f_requested[XENFEAT_NR_SUBMAPS];
-
-    /* info from (elf) kernel image */
-    struct elf_dom_parms parms;
-    char *guest_type;
-
-    /* memory layout */
-    struct xc_dom_seg kernel_seg;
-    struct xc_dom_seg p2m_seg;
-    struct xc_dom_seg pgtables_seg;
-    struct xc_dom_seg devicetree_seg;
-    struct xc_dom_seg start_info_seg;
-    xen_pfn_t start_info_pfn;
-    xen_pfn_t console_pfn;
-    xen_pfn_t xenstore_pfn;
-    xen_pfn_t shared_info_pfn;
-    xen_pfn_t bootstack_pfn;
-    xen_pfn_t pfn_alloc_end;
-    xen_vaddr_t virt_alloc_end;
-    xen_vaddr_t bsd_symtab_start;
-
-    /*
-     * initrd parameters as specified in start_info page
-     * Depending on capabilities of the booted kernel this may be a virtual
-     * address or a pfn. Type is neutral and large enough to hold a virtual
-     * address of a 64 bit kernel even with 32 bit toolstack.
-     */
-    uint64_t initrd_start;
-    uint64_t initrd_len;
-
-    unsigned int alloc_bootstack;
-    xen_vaddr_t virt_pgtab_end;
-
-    /* other state info */
-    uint32_t f_active[XENFEAT_NR_SUBMAPS];
-
-    /*
-     * pv_p2m is specific to x86 PV guests, and maps GFNs to MFNs.  It is
-     * eventually copied into guest context.
-     */
-    xen_pfn_t *pv_p2m;
-
-    /* physical memory
-     *
-     * An x86 PV guest has one or more blocks of physical RAM,
-     * consisting of total_pages starting at 0. The start address and
-     * size of each block is controlled by vNUMA structures.
-     *
-     * An ARM guest has GUEST_RAM_BANKS regions of RAM, with
-     * rambank_size[i] pages in each. The lowest RAM address
-     * (corresponding to the base of the p2m arrays above) is stored
-     * in rambase_pfn.
-     */
-    xen_pfn_t rambase_pfn;
-    xen_pfn_t total_pages;
-    xen_pfn_t p2m_size;         /* number of pfns covered by p2m */
-    struct xc_dom_phys *phys_pages;
-#if defined (__arm__) || defined(__aarch64__)
-    xen_pfn_t rambank_size[GUEST_RAM_BANKS];
-#endif
-
-    /* malloc memory pool */
-    struct xc_dom_mem *memblocks;
-
-    /* memory footprint stats */
-    size_t alloc_malloc;
-    size_t alloc_mem_map;
-    size_t alloc_file_map;
-    size_t alloc_domU_map;
-
-    /* misc xen domain config stuff */
-    unsigned long flags;
-    unsigned int console_evtchn;
-    unsigned int xenstore_evtchn;
-    uint32_t console_domid;
-    uint32_t xenstore_domid;
-    xen_pfn_t shared_info_mfn;
-
-    xc_interface *xch;
-    uint32_t guest_domid;
-    int claim_enabled; /* 0 by default, 1 enables it */
-
-    int xen_version;
-    xen_capabilities_info_t xen_caps;
-
-    /* kernel loader, arch hooks */
-    struct xc_dom_loader *kernel_loader;
-    void *private_loader;
-
-    /* vNUMA information */
-    xen_vmemrange_t *vmemranges;
-    unsigned int nr_vmemranges;
-    unsigned int *vnode_to_pnode;
-    unsigned int nr_vnodes;
-
-    /* domain type/architecture specific data */
-    void *arch_private;
-
-    /* kernel loader */
-    struct xc_dom_arch *arch_hooks;
-    /* allocate up to pfn_alloc_end */
-    int (*allocate) (struct xc_dom_image * dom);
-
-    /* Container type (HVM or PV). */
-    enum {
-        XC_DOM_PV_CONTAINER,
-        XC_DOM_HVM_CONTAINER,
-    } container_type;
-
-    /* HVM specific fields. */
-    xen_pfn_t target_pages;
-    xen_paddr_t mmio_start;
-    xen_paddr_t mmio_size;
-    xen_paddr_t lowmem_end;
-    xen_paddr_t highmem_end;
-    xen_pfn_t vga_hole_size;
-
-    /* If unset disables the setup of the IOREQ pages. */
-    bool device_model;
-
-    /* BIOS/Firmware passed to HVMLOADER */
-    struct xc_hvm_firmware_module system_firmware_module;
-
-    /* Extra ACPI tables */
-#define MAX_ACPI_MODULES        4
-    struct xc_hvm_firmware_module acpi_modules[MAX_ACPI_MODULES];
-
-    /* Extra SMBIOS structures passed to HVMLOADER */
-    struct xc_hvm_firmware_module smbios_module;
-
-#if defined(__i386__) || defined(__x86_64__)
-    struct e820entry *e820;
-    unsigned int e820_entries;
-#endif
-
-    xen_pfn_t vuart_gfn;
-
-    /* Number of vCPUs */
-    unsigned int max_vcpus;
-};
-
-/* --- pluggable kernel loader ------------------------------------- */
-
-struct xc_dom_loader {
-    char *name;
-    /* Sadly the error returns from these functions are not consistent: */
-    elf_negerrnoval (*probe) (struct xc_dom_image * dom);
-    elf_negerrnoval (*parser) (struct xc_dom_image * dom);
-    elf_errorstatus (*loader) (struct xc_dom_image * dom);
-
-    struct xc_dom_loader *next;
-};
-
-#define __init __attribute__ ((constructor))
-void xc_dom_register_loader(struct xc_dom_loader *loader);
-
-/* --- arch specific hooks ----------------------------------------- */
-
-struct xc_dom_arch {
-    int (*alloc_magic_pages) (struct xc_dom_image * dom);
-
-    /* pagetable setup - x86 PV only */
-    int (*alloc_pgtables) (struct xc_dom_image * dom);
-    int (*alloc_p2m_list) (struct xc_dom_image * dom);
-    int (*setup_pgtables) (struct xc_dom_image * dom);
-
-    /* arch-specific data structs setup */
-    int (*start_info) (struct xc_dom_image * dom);
-    int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
-    int (*vcpu) (struct xc_dom_image * dom);
-    int (*bootearly) (struct xc_dom_image * dom);
-    int (*bootlate) (struct xc_dom_image * dom);
-
-    /* arch-specific memory initialization. */
-    int (*meminit) (struct xc_dom_image * dom);
-
-    char *guest_type;
-    char *native_protocol;
-    int page_shift;
-    int sizeof_pfn;
-    int p2m_base_supported;
-    int arch_private_size;
-
-    struct xc_dom_arch *next;
-};
-void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
-
-#define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
-#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
-
-/* --- main functions ---------------------------------------------- */
-
-struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
-                                     const char *cmdline, const char *features);
-void xc_dom_release_phys(struct xc_dom_image *dom);
-void xc_dom_release(struct xc_dom_image *dom);
-int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase);
-int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
-
-/* Set this larger if you have enormous modules/kernels. Note that
- * you should trust all kernels not to be maliciously large (e.g. to
- * exhaust all dom0 memory) if you do this (see CVE-2012-4544 /
- * XSA-25). You can also set the default independently for
- * modules/kernels in xc_dom_allocate() or call
- * xc_dom_{kernel,module}_max_size.
- */
-#ifndef XC_DOM_DECOMPRESS_MAX
-#define XC_DOM_DECOMPRESS_MAX (1024*1024*1024) /* 1GB */
-#endif
-
-int xc_dom_kernel_check_size(struct xc_dom_image *dom, size_t sz);
-int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
-
-int xc_dom_module_max_size(struct xc_dom_image *dom, size_t sz);
-
-int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
-
-size_t xc_dom_check_gzip(xc_interface *xch,
-                     void *blob, size_t ziplen);
-int xc_dom_do_gunzip(xc_interface *xch,
-                     void *src, size_t srclen, void *dst, size_t dstlen);
-int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
-
-int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
-int xc_dom_module_file(struct xc_dom_image *dom, const char *filename,
-                       const char *cmdline);
-int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
-                      size_t memsize);
-int xc_dom_module_mem(struct xc_dom_image *dom, const void *mem,
-                       size_t memsize, const char *cmdline);
-int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename);
-int xc_dom_devicetree_mem(struct xc_dom_image *dom, const void *mem,
-                          size_t memsize);
-
-int xc_dom_parse_image(struct xc_dom_image *dom);
-int xc_dom_set_arch_hooks(struct xc_dom_image *dom);
-int xc_dom_build_image(struct xc_dom_image *dom);
-
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch,
-                         uint32_t domid);
-int xc_dom_boot_mem_init(struct xc_dom_image *dom);
-void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
-                           xen_pfn_t count);
-int xc_dom_boot_image(struct xc_dom_image *dom);
-int xc_dom_compat_check(struct xc_dom_image *dom);
-int xc_dom_gnttab_init(struct xc_dom_image *dom);
-int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
-                       bool is_hvm,
-                       xen_pfn_t console_gfn,
-                       xen_pfn_t xenstore_gfn,
-                       uint32_t console_domid,
-                       uint32_t xenstore_domid);
-bool xc_dom_translated(const struct xc_dom_image *dom);
-
-/* --- debugging bits ---------------------------------------------- */
-
-int xc_dom_loginit(xc_interface *xch);
-
-void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
-     __attribute__ ((format(printf, 2, 3)));
-void xc_dom_panic_func(xc_interface *xch,
-                      const char *file, int line, xc_error_code err,
-                      const char *fmt, ...)
-    __attribute__ ((format(printf, 5, 6)));
-
-#define xc_dom_panic(xch, err, fmt, args...) \
-    xc_dom_panic_func(xch, __FILE__, __LINE__, err, fmt, ## args)
-#define xc_dom_trace(mark) \
-    xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
-
-void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
-
-/* --- simple memory pool ------------------------------------------ */
-
-void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
-int xc_dom_register_external(struct xc_dom_image *dom, void *ptr, size_t size);
-void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
-void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
-                            const char *filename, size_t * size,
-                            const size_t max_size);
-char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
-
-/* --- alloc memory pool ------------------------------------------- */
-
-xen_pfn_t xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
-int xc_dom_alloc_segment(struct xc_dom_image *dom,
-                         struct xc_dom_seg *seg, char *name,
-                         xen_vaddr_t start, xen_vaddr_t size);
-
-/* --- misc bits --------------------------------------------------- */
-
-void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
-                        xen_pfn_t count);
-void *xc_dom_pfn_to_ptr_retcount(struct xc_dom_image *dom, xen_pfn_t first,
-                                 xen_pfn_t count, xen_pfn_t *count_out);
-void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
-void xc_dom_unmap_all(struct xc_dom_image *dom);
-
-static inline void *xc_dom_seg_to_ptr_pages(struct xc_dom_image *dom,
-                                      struct xc_dom_seg *seg,
-                                      xen_pfn_t *pages_out)
-{
-    void *retval;
-
-    retval = xc_dom_pfn_to_ptr(dom, seg->pfn, seg->pages);
-
-    *pages_out = retval ? seg->pages : 0;
-    return retval;
-}
-
-static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
-                                      struct xc_dom_seg *seg)
-{
-    xen_pfn_t dummy;
-
-    return xc_dom_seg_to_ptr_pages(dom, seg, &dummy);
-}
-
-static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
-                                        xen_vaddr_t vaddr,
-                                        size_t *safe_region_out)
-{
-    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
-    xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
-    unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
-    xen_pfn_t safe_region_count;
-    void *ptr;
-
-    *safe_region_out = 0;
-    ptr = xc_dom_pfn_to_ptr_retcount(dom, page, 0, &safe_region_count);
-    if ( ptr == NULL )
-        return ptr;
-    *safe_region_out = (safe_region_count << XC_DOM_PAGE_SHIFT(dom)) - offset;
-    return ptr + offset;
-}
-
-static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
-{
-    if ( xc_dom_translated(dom) )
-        return pfn;
-
-    /* x86 PV only now. */
-    if ( pfn >= dom->total_pages )
-        return INVALID_MFN;
-
-    return dom->pv_p2m[pfn];
-}
-
-#endif /* _XC_DOM_H */
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/include/xenctrl_dom.h b/tools/libxc/include/xenctrl_dom.h
new file mode 100644
index 0000000000..52a4d6c8c0
--- /dev/null
+++ b/tools/libxc/include/xenctrl_dom.h
@@ -0,0 +1,449 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _XC_DOM_H
+#define _XC_DOM_H
+
+#include <xen/libelf/libelf.h>
+#include <xenguest.h>
+
+#define INVALID_PFN ((xen_pfn_t)-1)
+#define X86_HVM_NR_SPECIAL_PAGES    8
+#define X86_HVM_END_SPECIAL_REGION  0xff000u
+#define XG_MAX_MODULES 2
+
+/* --- typedefs and structs ---------------------------------------- */
+
+typedef uint64_t xen_vaddr_t;
+typedef uint64_t xen_paddr_t;
+
+#define PRIpfn PRI_xen_pfn
+
+struct xc_dom_seg {
+    xen_vaddr_t vstart;
+    xen_vaddr_t vend;
+    xen_pfn_t pfn;
+    xen_pfn_t pages;
+};
+
+struct xc_dom_mem {
+    struct xc_dom_mem *next;
+    void *ptr;
+    enum {
+        XC_DOM_MEM_TYPE_MALLOC_INTERNAL,
+        XC_DOM_MEM_TYPE_MALLOC_EXTERNAL,
+        XC_DOM_MEM_TYPE_MMAP,
+    } type;
+    size_t len;
+    unsigned char memory[0];
+};
+
+struct xc_dom_phys {
+    struct xc_dom_phys *next;
+    void *ptr;
+    xen_pfn_t first;
+    xen_pfn_t count;
+};
+
+struct xc_dom_module {
+    void *blob;
+    size_t size;
+    void *cmdline;
+    /* If seg.vstart is non zero then the module will be loaded at that
+     * address, otherwise it will automatically placed.
+     *
+     * If automatic placement is used and the module is gzip
+     * compressed then it will be decompressed as it is loaded. If the
+     * module has been explicitly placed then it is loaded as is
+     * otherwise decompressing risks undoing the manual placement.
+     */
+    struct xc_dom_seg seg;
+};
+
+struct xc_dom_image {
+    /* files */
+    void *kernel_blob;
+    size_t kernel_size;
+    unsigned int num_modules;
+    struct xc_dom_module modules[XG_MAX_MODULES];
+    void *devicetree_blob;
+    size_t devicetree_size;
+
+    size_t max_kernel_size;
+    size_t max_module_size;
+    size_t max_devicetree_size;
+
+    /* arguments and parameters */
+    char *cmdline;
+    size_t cmdline_size;
+    uint32_t f_requested[XENFEAT_NR_SUBMAPS];
+
+    /* info from (elf) kernel image */
+    struct elf_dom_parms parms;
+    char *guest_type;
+
+    /* memory layout */
+    struct xc_dom_seg kernel_seg;
+    struct xc_dom_seg p2m_seg;
+    struct xc_dom_seg pgtables_seg;
+    struct xc_dom_seg devicetree_seg;
+    struct xc_dom_seg start_info_seg;
+    xen_pfn_t start_info_pfn;
+    xen_pfn_t console_pfn;
+    xen_pfn_t xenstore_pfn;
+    xen_pfn_t shared_info_pfn;
+    xen_pfn_t bootstack_pfn;
+    xen_pfn_t pfn_alloc_end;
+    xen_vaddr_t virt_alloc_end;
+    xen_vaddr_t bsd_symtab_start;
+
+    /*
+     * initrd parameters as specified in start_info page
+     * Depending on capabilities of the booted kernel this may be a virtual
+     * address or a pfn. Type is neutral and large enough to hold a virtual
+     * address of a 64 bit kernel even with 32 bit toolstack.
+     */
+    uint64_t initrd_start;
+    uint64_t initrd_len;
+
+    unsigned int alloc_bootstack;
+    xen_vaddr_t virt_pgtab_end;
+
+    /* other state info */
+    uint32_t f_active[XENFEAT_NR_SUBMAPS];
+
+    /*
+     * pv_p2m is specific to x86 PV guests, and maps GFNs to MFNs.  It is
+     * eventually copied into guest context.
+     */
+    xen_pfn_t *pv_p2m;
+
+    /* physical memory
+     *
+     * An x86 PV guest has one or more blocks of physical RAM,
+     * consisting of total_pages starting at 0. The start address and
+     * size of each block is controlled by vNUMA structures.
+     *
+     * An ARM guest has GUEST_RAM_BANKS regions of RAM, with
+     * rambank_size[i] pages in each. The lowest RAM address
+     * (corresponding to the base of the p2m arrays above) is stored
+     * in rambase_pfn.
+     */
+    xen_pfn_t rambase_pfn;
+    xen_pfn_t total_pages;
+    xen_pfn_t p2m_size;         /* number of pfns covered by p2m */
+    struct xc_dom_phys *phys_pages;
+#if defined (__arm__) || defined(__aarch64__)
+    xen_pfn_t rambank_size[GUEST_RAM_BANKS];
+#endif
+
+    /* malloc memory pool */
+    struct xc_dom_mem *memblocks;
+
+    /* memory footprint stats */
+    size_t alloc_malloc;
+    size_t alloc_mem_map;
+    size_t alloc_file_map;
+    size_t alloc_domU_map;
+
+    /* misc xen domain config stuff */
+    unsigned long flags;
+    unsigned int console_evtchn;
+    unsigned int xenstore_evtchn;
+    uint32_t console_domid;
+    uint32_t xenstore_domid;
+    xen_pfn_t shared_info_mfn;
+
+    xc_interface *xch;
+    uint32_t guest_domid;
+    int claim_enabled; /* 0 by default, 1 enables it */
+
+    int xen_version;
+    xen_capabilities_info_t xen_caps;
+
+    /* kernel loader, arch hooks */
+    struct xc_dom_loader *kernel_loader;
+    void *private_loader;
+
+    /* vNUMA information */
+    xen_vmemrange_t *vmemranges;
+    unsigned int nr_vmemranges;
+    unsigned int *vnode_to_pnode;
+    unsigned int nr_vnodes;
+
+    /* domain type/architecture specific data */
+    void *arch_private;
+
+    /* kernel loader */
+    struct xc_dom_arch *arch_hooks;
+    /* allocate up to pfn_alloc_end */
+    int (*allocate) (struct xc_dom_image * dom);
+
+    /* Container type (HVM or PV). */
+    enum {
+        XC_DOM_PV_CONTAINER,
+        XC_DOM_HVM_CONTAINER,
+    } container_type;
+
+    /* HVM specific fields. */
+    xen_pfn_t target_pages;
+    xen_paddr_t mmio_start;
+    xen_paddr_t mmio_size;
+    xen_paddr_t lowmem_end;
+    xen_paddr_t highmem_end;
+    xen_pfn_t vga_hole_size;
+
+    /* If unset disables the setup of the IOREQ pages. */
+    bool device_model;
+
+    /* BIOS/Firmware passed to HVMLOADER */
+    struct xc_hvm_firmware_module system_firmware_module;
+
+    /* Extra ACPI tables */
+#define MAX_ACPI_MODULES        4
+    struct xc_hvm_firmware_module acpi_modules[MAX_ACPI_MODULES];
+
+    /* Extra SMBIOS structures passed to HVMLOADER */
+    struct xc_hvm_firmware_module smbios_module;
+
+#if defined(__i386__) || defined(__x86_64__)
+    struct e820entry *e820;
+    unsigned int e820_entries;
+#endif
+
+    xen_pfn_t vuart_gfn;
+
+    /* Number of vCPUs */
+    unsigned int max_vcpus;
+};
+
+/* --- pluggable kernel loader ------------------------------------- */
+
+struct xc_dom_loader {
+    char *name;
+    /* Sadly the error returns from these functions are not consistent: */
+    elf_negerrnoval (*probe) (struct xc_dom_image * dom);
+    elf_negerrnoval (*parser) (struct xc_dom_image * dom);
+    elf_errorstatus (*loader) (struct xc_dom_image * dom);
+
+    struct xc_dom_loader *next;
+};
+
+#define __init __attribute__ ((constructor))
+void xc_dom_register_loader(struct xc_dom_loader *loader);
+
+/* --- arch specific hooks ----------------------------------------- */
+
+struct xc_dom_arch {
+    int (*alloc_magic_pages) (struct xc_dom_image * dom);
+
+    /* pagetable setup - x86 PV only */
+    int (*alloc_pgtables) (struct xc_dom_image * dom);
+    int (*alloc_p2m_list) (struct xc_dom_image * dom);
+    int (*setup_pgtables) (struct xc_dom_image * dom);
+
+    /* arch-specific data structs setup */
+    int (*start_info) (struct xc_dom_image * dom);
+    int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
+    int (*vcpu) (struct xc_dom_image * dom);
+    int (*bootearly) (struct xc_dom_image * dom);
+    int (*bootlate) (struct xc_dom_image * dom);
+
+    /* arch-specific memory initialization. */
+    int (*meminit) (struct xc_dom_image * dom);
+
+    char *guest_type;
+    char *native_protocol;
+    int page_shift;
+    int sizeof_pfn;
+    int p2m_base_supported;
+    int arch_private_size;
+
+    struct xc_dom_arch *next;
+};
+void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
+
+#define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
+#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
+
+/* --- main functions ---------------------------------------------- */
+
+struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
+                                     const char *cmdline, const char *features);
+void xc_dom_release_phys(struct xc_dom_image *dom);
+void xc_dom_release(struct xc_dom_image *dom);
+int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase);
+int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
+
+/* Set this larger if you have enormous modules/kernels. Note that
+ * you should trust all kernels not to be maliciously large (e.g. to
+ * exhaust all dom0 memory) if you do this (see CVE-2012-4544 /
+ * XSA-25). You can also set the default independently for
+ * modules/kernels in xc_dom_allocate() or call
+ * xc_dom_{kernel,module}_max_size.
+ */
+#ifndef XC_DOM_DECOMPRESS_MAX
+#define XC_DOM_DECOMPRESS_MAX (1024*1024*1024) /* 1GB */
+#endif
+
+int xc_dom_kernel_check_size(struct xc_dom_image *dom, size_t sz);
+int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
+
+int xc_dom_module_max_size(struct xc_dom_image *dom, size_t sz);
+
+int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
+
+size_t xc_dom_check_gzip(xc_interface *xch,
+                     void *blob, size_t ziplen);
+int xc_dom_do_gunzip(xc_interface *xch,
+                     void *src, size_t srclen, void *dst, size_t dstlen);
+int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
+
+int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
+int xc_dom_module_file(struct xc_dom_image *dom, const char *filename,
+                       const char *cmdline);
+int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
+                      size_t memsize);
+int xc_dom_module_mem(struct xc_dom_image *dom, const void *mem,
+                       size_t memsize, const char *cmdline);
+int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename);
+int xc_dom_devicetree_mem(struct xc_dom_image *dom, const void *mem,
+                          size_t memsize);
+
+int xc_dom_parse_image(struct xc_dom_image *dom);
+int xc_dom_set_arch_hooks(struct xc_dom_image *dom);
+int xc_dom_build_image(struct xc_dom_image *dom);
+
+int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch,
+                         uint32_t domid);
+int xc_dom_boot_mem_init(struct xc_dom_image *dom);
+void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
+                           xen_pfn_t count);
+int xc_dom_boot_image(struct xc_dom_image *dom);
+int xc_dom_compat_check(struct xc_dom_image *dom);
+int xc_dom_gnttab_init(struct xc_dom_image *dom);
+int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
+                       bool is_hvm,
+                       xen_pfn_t console_gfn,
+                       xen_pfn_t xenstore_gfn,
+                       uint32_t console_domid,
+                       uint32_t xenstore_domid);
+bool xc_dom_translated(const struct xc_dom_image *dom);
+
+/* --- debugging bits ---------------------------------------------- */
+
+int xc_dom_loginit(xc_interface *xch);
+
+void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
+     __attribute__ ((format(printf, 2, 3)));
+void xc_dom_panic_func(xc_interface *xch,
+                      const char *file, int line, xc_error_code err,
+                      const char *fmt, ...)
+    __attribute__ ((format(printf, 5, 6)));
+
+#define xc_dom_panic(xch, err, fmt, args...) \
+    xc_dom_panic_func(xch, __FILE__, __LINE__, err, fmt, ## args)
+#define xc_dom_trace(mark) \
+    xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
+
+void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
+
+/* --- simple memory pool ------------------------------------------ */
+
+void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
+int xc_dom_register_external(struct xc_dom_image *dom, void *ptr, size_t size);
+void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
+void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
+                            const char *filename, size_t * size,
+                            const size_t max_size);
+char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
+
+/* --- alloc memory pool ------------------------------------------- */
+
+xen_pfn_t xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
+int xc_dom_alloc_segment(struct xc_dom_image *dom,
+                         struct xc_dom_seg *seg, char *name,
+                         xen_vaddr_t start, xen_vaddr_t size);
+
+/* --- misc bits --------------------------------------------------- */
+
+void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
+                        xen_pfn_t count);
+void *xc_dom_pfn_to_ptr_retcount(struct xc_dom_image *dom, xen_pfn_t first,
+                                 xen_pfn_t count, xen_pfn_t *count_out);
+void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
+void xc_dom_unmap_all(struct xc_dom_image *dom);
+
+static inline void *xc_dom_seg_to_ptr_pages(struct xc_dom_image *dom,
+                                      struct xc_dom_seg *seg,
+                                      xen_pfn_t *pages_out)
+{
+    void *retval;
+
+    retval = xc_dom_pfn_to_ptr(dom, seg->pfn, seg->pages);
+
+    *pages_out = retval ? seg->pages : 0;
+    return retval;
+}
+
+static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
+                                      struct xc_dom_seg *seg)
+{
+    xen_pfn_t dummy;
+
+    return xc_dom_seg_to_ptr_pages(dom, seg, &dummy);
+}
+
+static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
+                                        xen_vaddr_t vaddr,
+                                        size_t *safe_region_out)
+{
+    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
+    xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
+    unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
+    xen_pfn_t safe_region_count;
+    void *ptr;
+
+    *safe_region_out = 0;
+    ptr = xc_dom_pfn_to_ptr_retcount(dom, page, 0, &safe_region_count);
+    if ( ptr == NULL )
+        return ptr;
+    *safe_region_out = (safe_region_count << XC_DOM_PAGE_SHIFT(dom)) - offset;
+    return ptr + offset;
+}
+
+static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
+{
+    if ( xc_dom_translated(dom) )
+        return pfn;
+
+    /* x86 PV only now. */
+    if ( pfn >= dom->total_pages )
+        return INVALID_MFN;
+
+    return dom->pv_p2m[pfn];
+}
+
+#endif /* _XC_DOM_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index 2ee1d205b4..7df1fccd62 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -62,7 +62,7 @@
 
 #include "xg_private.h"
 #include "xc_core.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <stdlib.h>
 #include <unistd.h>
 
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 90974d572e..6ecdf6953f 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -19,7 +19,7 @@
 
 #include "xc_private.h"
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
diff --git a/tools/libxc/xg_dom_arm.c b/tools/libxc/xg_dom_arm.c
index 931404c222..3f66f1d890 100644
--- a/tools/libxc/xg_dom_arm.c
+++ b/tools/libxc/xg_dom_arm.c
@@ -24,7 +24,7 @@
 #include <xen-tools/libs.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #define NR_MAGIC_PAGES 4
 #define CONSOLE_PFN_OFFSET 0
diff --git a/tools/libxc/xg_dom_armzimageloader.c b/tools/libxc/xg_dom_armzimageloader.c
index 0df8c2a4b1..4246c8e5fa 100644
--- a/tools/libxc/xg_dom_armzimageloader.c
+++ b/tools/libxc/xg_dom_armzimageloader.c
@@ -25,7 +25,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #include <arpa/inet.h> /* XXX ntohl is not the right function... */
 
diff --git a/tools/libxc/xg_dom_binloader.c b/tools/libxc/xg_dom_binloader.c
index d6f7f2a500..870a921427 100644
--- a/tools/libxc/xg_dom_binloader.c
+++ b/tools/libxc/xg_dom_binloader.c
@@ -83,7 +83,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
diff --git a/tools/libxc/xg_dom_boot.c b/tools/libxc/xg_dom_boot.c
index bb599b33ba..1e31e92244 100644
--- a/tools/libxc/xg_dom_boot.c
+++ b/tools/libxc/xg_dom_boot.c
@@ -31,7 +31,7 @@
 #include <zlib.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_core.h"
 #include <xen/hvm/params.h>
 #include <xen/grant_table.h>
diff --git a/tools/libxc/xg_dom_compat_linux.c b/tools/libxc/xg_dom_compat_linux.c
index b3d43feed9..b645f0b14b 100644
--- a/tools/libxc/xg_dom_compat_linux.c
+++ b/tools/libxc/xg_dom_compat_linux.c
@@ -30,7 +30,7 @@
 
 #include "xenctrl.h"
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 /* ------------------------------------------------------------------------ */
 
diff --git a/tools/libxc/xg_dom_core.c b/tools/libxc/xg_dom_core.c
index 327c8a8575..1c91cce315 100644
--- a/tools/libxc/xg_dom_core.c
+++ b/tools/libxc/xg_dom_core.c
@@ -32,7 +32,7 @@
 #include <assert.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "_paths.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_dom_decompress.h b/tools/libxc/xg_dom_decompress.h
index d9a21cf297..c5ab2e59eb 100644
--- a/tools/libxc/xg_dom_decompress.h
+++ b/tools/libxc/xg_dom_decompress.h
@@ -1,5 +1,5 @@
 #ifndef __MINIOS__
-# include "xc_dom.h"
+# include "xenctrl_dom.h"
 #else
 # include "xg_dom_decompress_unsafe.h"
 #endif
diff --git a/tools/libxc/xg_dom_decompress_unsafe.h b/tools/libxc/xg_dom_decompress_unsafe.h
index 64f68864b1..fb84b6add8 100644
--- a/tools/libxc/xg_dom_decompress_unsafe.h
+++ b/tools/libxc/xg_dom_decompress_unsafe.h
@@ -1,4 +1,4 @@
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
                           int (*fill)(void*, unsigned int),
diff --git a/tools/libxc/xg_dom_elfloader.c b/tools/libxc/xg_dom_elfloader.c
index b327db219d..7043c3bbba 100644
--- a/tools/libxc/xg_dom_elfloader.c
+++ b/tools/libxc/xg_dom_elfloader.c
@@ -26,7 +26,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 #define XEN_VER "xen-3.0"
diff --git a/tools/libxc/xg_dom_hvmloader.c b/tools/libxc/xg_dom_hvmloader.c
index 3f0bd65547..995a0f3dc3 100644
--- a/tools/libxc/xg_dom_hvmloader.c
+++ b/tools/libxc/xg_dom_hvmloader.c
@@ -26,7 +26,7 @@
 #include <assert.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_dom_x86.c b/tools/libxc/xg_dom_x86.c
index 9439805eaa..842dbcccdd 100644
--- a/tools/libxc/xg_dom_x86.c
+++ b/tools/libxc/xg_dom_x86.c
@@ -38,7 +38,7 @@
 #include <xen-tools/libs.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xenctrl.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_offline_page.c b/tools/libxc/xg_offline_page.c
index 19538fc436..77e8889b11 100644
--- a/tools/libxc/xg_offline_page.c
+++ b/tools/libxc/xg_offline_page.c
@@ -28,7 +28,7 @@
 #include <xc_core.h>
 
 #include "xc_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xg_private.h"
 #include "xg_save_restore.h"
 
diff --git a/tools/libxc/xg_sr_common.h b/tools/libxc/xg_sr_common.h
index 35f23fabb5..13fcc47420 100644
--- a/tools/libxc/xg_sr_common.h
+++ b/tools/libxc/xg_sr_common.h
@@ -5,7 +5,7 @@
 
 #include "xg_private.h"
 #include "xg_save_restore.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 #include "xg_sr_stream_format.h"
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 34f8a29056..975a4d730a 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -3,7 +3,7 @@
 #include "libxl_libfdt_compat.h"
 #include "libxl_arm.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <stdbool.h>
 #include <libfdt.h>
 #include <assert.h>
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index 8aef210d4c..52c2ab5e3a 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -17,7 +17,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 _hidden
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 2814818e34..1031b75159 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -20,7 +20,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xenguest.h>
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/e820.h>
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index f2dc5696b9..fec4e0fbe5 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -19,7 +19,7 @@
 
 #include "libxl_internal.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xen/hvm/e820.h>
 #include <sys/types.h>
 #include <pwd.h>
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index f8661e90d4..e2dca64aa1 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -20,7 +20,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index c63d0686fd..e16ae9630b 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -57,7 +57,7 @@
 #include <xenctrl.h>
 #include <xenguest.h>
 #include <xenhypfs.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxl/libxl_vnuma.c b/tools/libxl/libxl_vnuma.c
index 8ec2abb2e6..c2e144ceae 100644
--- a/tools/libxl/libxl_vnuma.c
+++ b/tools/libxl/libxl_vnuma.c
@@ -17,7 +17,7 @@
 #include "libxl_arch.h"
 #include <stdlib.h>
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 bool libxl__vnuma_configured(const libxl_domain_build_info *b_info)
 {
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index e57f63282e..7d95506e00 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -1,7 +1,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c
index ed6610c84e..3df86c7be5 100644
--- a/tools/libxl/libxl_x86_acpi.c
+++ b/tools/libxl/libxl_x86_acpi.c
@@ -18,7 +18,7 @@
 #include <xen/hvm/e820.h>
 #include "libacpi/libacpi.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
  /* Number of pages holding ACPI tables */
 #define NUM_ACPI_PAGES 16
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 8fde5f311f..8c7b184f0b 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -17,7 +17,7 @@
 #include <arpa/inet.h>
 
 #include <xen/elfnote.h>
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/params.h>
 
diff --git a/tools/xcutils/readnotes.c b/tools/xcutils/readnotes.c
index e682dd1a21..a6b7358e70 100644
--- a/tools/xcutils/readnotes.c
+++ b/tools/xcutils/readnotes.c
@@ -12,7 +12,7 @@
 #include <sys/mman.h>
 
 #include <xg_private.h>
-#include <xc_dom.h> /* gunzip bits */
+#include <xenctrl_dom.h> /* gunzip bits */
 
 #include <xen/libelf/libelf.h>
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2e-0000kM-2Z; Wed, 09 Sep 2020 11:13:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2d-0000kD-9l
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:31 +0000
X-Inumbo-ID: cdf69f2e-fecb-47d8-b09a-f5f12cdf5783
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cdf69f2e-fecb-47d8-b09a-f5f12cdf5783;
 Wed, 09 Sep 2020 11:13:30 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IaWfhOsz+rLRYedB7SJ+d5aJHkV9qjg3aK009bNVPck=; b=oh5RZdR1G/teX8QjmGTLTVz1bC
 MzpBAO6/uSMOv33micwjuQWTF3h7Q8GHE017HXruG9teQOgP/lRQITkYtowtRWuiBf/Z21q/OLPzB
 +57Mc2CMK4Txmtj5pPIZORTZkOVqxotNdDwP87Twq0GBI5Cxj6M1gZnIO39b1oXbv0kA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2b-00066h-Vt
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:29 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2b-0001Ve-Uu
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: untangle libxenctrl from libxenguest
Message-Id: <E1kFy2b-0001Ve-Uu@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:13:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7e0165c19387e8eece4c3b28d20f7fcc86533685
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:31 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: untangle libxenctrl from libxenguest
    
    Sources of libxenctrl and libxenguest are completely entangled. In
    practice libxenguest is a user of libxenctrl, so don't let any source
    libxenctrl include xg_private.h.
    
    This can be achieved by moving all definitions used by libxenctrl from
    xg_private.h to xc_private.h.
    
    Export xenctrl_dom.h as it will now be included by other public
    headers.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile              |  3 ++-
 tools/libxc/include/xenctrl_dom.h | 10 ++++++++--
 tools/libxc/include/xenguest.h    |  8 ++------
 tools/libxc/xc_core.c             |  5 +++--
 tools/libxc/xc_core.h             |  2 +-
 tools/libxc/xc_core_arm.c         |  2 +-
 tools/libxc/xc_core_x86.c         |  6 ++----
 tools/libxc/xc_domain.c           |  3 +--
 tools/libxc/xc_hcall_buf.c        |  1 -
 tools/libxc/xc_private.c          |  1 -
 tools/libxc/xc_private.h          | 36 ++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_resume.c           |  2 --
 tools/libxc/xg_private.h          | 22 ----------------------
 tools/libxc/xg_save_restore.h     |  9 ---------
 14 files changed, 56 insertions(+), 54 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 0fd5511143..faf2639894 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -215,7 +215,7 @@ install: build
 	$(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
-	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h $(DESTDIR)$(includedir)
+	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrl_dom.h $(DESTDIR)$(includedir)
 	$(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -235,6 +235,7 @@ uninstall:
 	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xencontrol.pc
 	rm -f $(DESTDIR)$(includedir)/xenctrl.h
 	rm -f $(DESTDIR)$(includedir)/xenctrl_compat.h
+	rm -f $(DESTDIR)$(includedir)/xenctrl_dom.h
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR).$(MINOR)
diff --git a/tools/libxc/include/xenctrl_dom.h b/tools/libxc/include/xenctrl_dom.h
index 52a4d6c8c0..40b85b7755 100644
--- a/tools/libxc/include/xenctrl_dom.h
+++ b/tools/libxc/include/xenctrl_dom.h
@@ -17,9 +17,7 @@
 #define _XC_DOM_H
 
 #include <xen/libelf/libelf.h>
-#include <xenguest.h>
 
-#define INVALID_PFN ((xen_pfn_t)-1)
 #define X86_HVM_NR_SPECIAL_PAGES    8
 #define X86_HVM_END_SPECIAL_REGION  0xff000u
 #define XG_MAX_MODULES 2
@@ -38,6 +36,12 @@ struct xc_dom_seg {
     xen_pfn_t pages;
 };
 
+struct xc_hvm_firmware_module {
+    uint8_t  *data;
+    uint32_t  length;
+    uint64_t  guest_addr_out;
+};
+
 struct xc_dom_mem {
     struct xc_dom_mem *next;
     void *ptr;
@@ -255,6 +259,8 @@ struct xc_dom_arch {
     int (*setup_pgtables) (struct xc_dom_image * dom);
 
     /* arch-specific data structs setup */
+    /* in Mini-OS environment start_info might be a macro, avoid collision. */
+#undef start_info
     int (*start_info) (struct xc_dom_image * dom);
     int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
     int (*vcpu) (struct xc_dom_image * dom);
diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index 7a12d21ff2..4643384790 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -22,6 +22,8 @@
 #ifndef XENGUEST_H
 #define XENGUEST_H
 
+#include <xenctrl_dom.h>
+
 #define XC_NUMA_NO_NODE   (~0U)
 
 #define XCFLAGS_LIVE      (1 << 0)
@@ -249,12 +251,6 @@ int xc_linux_build(xc_interface *xch,
                    unsigned int console_evtchn,
                    unsigned long *console_mfn);
 
-struct xc_hvm_firmware_module {
-    uint8_t  *data;
-    uint32_t  length;
-    uint64_t  guest_addr_out;
-};
-
 /*
  * Sets *lockfd to -1.
  * Has deallocated everything even on error.
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index 7df1fccd62..e8c6fb96f9 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -60,12 +60,13 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
-#include "xenctrl_dom.h"
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <xen/libelf/libelf.h>
+
 /* number of pages to write at a time */
 #define DUMP_INCREMENT (4 * 1024)
 
diff --git a/tools/libxc/xc_core.h b/tools/libxc/xc_core.h
index ed7ed53ca5..36fb755da2 100644
--- a/tools/libxc/xc_core.h
+++ b/tools/libxc/xc_core.h
@@ -21,7 +21,7 @@
 #define XC_CORE_H
 
 #include "xen/version.h"
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xen/libelf/elfstructs.h"
 
 /* section names */
diff --git a/tools/libxc/xc_core_arm.c b/tools/libxc/xc_core_arm.c
index c3c492c971..7b587b4cc5 100644
--- a/tools/libxc/xc_core_arm.c
+++ b/tools/libxc/xc_core_arm.c
@@ -16,7 +16,7 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
 
 #include <xen-tools/libs.h>
diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c
index 54852a2d1a..cb76e6207b 100644
--- a/tools/libxc/xc_core_x86.c
+++ b/tools/libxc/xc_core_x86.c
@@ -17,12 +17,10 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
 #include <xen/hvm/e820.h>
 
-#define GET_FIELD(_p, _f) ((dinfo->guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f))
-
 int
 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
                               unsigned long pfn)
@@ -98,7 +96,7 @@ xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, xc
 
     live_p2m_frame_list_list =
         xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_READ,
-                             GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list));
+                             GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list, dinfo->guest_width));
 
     if ( !live_p2m_frame_list_list )
     {
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index fbc22c4df6..43fab50c06 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -21,8 +21,7 @@
 
 #include "xc_private.h"
 #include "xc_core.h"
-#include "xg_private.h"
-#include "xg_save_restore.h"
+#include "xc_private.h"
 #include <xen/memory.h>
 #include <xen/hvm/hvm_op.h>
 
diff --git a/tools/libxc/xc_hcall_buf.c b/tools/libxc/xc_hcall_buf.c
index c1230a1e2b..200671f36f 100644
--- a/tools/libxc/xc_hcall_buf.c
+++ b/tools/libxc/xc_hcall_buf.c
@@ -19,7 +19,6 @@
 #include <string.h>
 
 #include "xc_private.h"
-#include "xg_private.h"
 
 xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(HYPERCALL_BUFFER_NULL) = {
     .hbuf = NULL,
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 6ecdf6953f..8af96b1b7e 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -18,7 +18,6 @@
  */
 
 #include "xc_private.h"
-#include "xg_private.h"
 #include "xenctrl_dom.h"
 #include <stdarg.h>
 #include <stdlib.h>
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index c77edb3c4c..f0b5f83ac8 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <sys/ioctl.h>
 
 #include "_paths.h"
@@ -62,6 +63,39 @@ struct iovec {
 #include <sys/uio.h>
 #endif
 
+#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
+
+#define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
+
+#define SET_FIELD(_p, _f, _v, _w) do {          \
+    if ((_w) == 8)                              \
+        (_p)->x64._f = (_v);                    \
+    else                                        \
+        (_p)->x32._f = (_v);                    \
+} while (0)
+
+/* XXX SMH: following skanky macros rely on variable p2m_size being set */
+/* XXX TJD: also, "guest_width" should be the guest's sizeof(unsigned long) */
+
+struct domain_info_context {
+    unsigned int guest_width;
+    unsigned long p2m_size;
+};
+
+/* Number of xen_pfn_t in a page */
+#define FPP             (PAGE_SIZE/(dinfo->guest_width))
+
+/* Number of entries in the pfn_to_mfn_frame_list_list */
+#define P2M_FLL_ENTRIES (((dinfo->p2m_size)+(FPP*FPP)-1)/(FPP*FPP))
+
+/* Number of entries in the pfn_to_mfn_frame_list */
+#define P2M_FL_ENTRIES  (((dinfo->p2m_size)+FPP-1)/FPP)
+
+/* Size in bytes of the pfn_to_mfn_frame_list     */
+#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (dinfo->guest_width))
+#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) *                           \
+                           max_t(size_t, sizeof(xen_pfn_t), dinfo->guest_width))
+
 #define DECLARE_DOMCTL struct xen_domctl domctl
 #define DECLARE_SYSCTL struct xen_sysctl sysctl
 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
@@ -75,6 +109,8 @@ struct iovec {
 #define PAGE_SIZE               XC_PAGE_SIZE
 #define PAGE_MASK               XC_PAGE_MASK
 
+#define INVALID_PFN ((xen_pfn_t)-1)
+
 /*
 ** Define max dirty page cache to permit during save/restore -- need to balance 
 ** keeping cache usage down with CPU impact of invalidating too often.
diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c
index c169204fac..94c6c9fb31 100644
--- a/tools/libxc/xc_resume.c
+++ b/tools/libxc/xc_resume.c
@@ -14,8 +14,6 @@
  */
 
 #include "xc_private.h"
-#include "xg_private.h"
-#include "xg_save_restore.h"
 
 #if defined(__i386__) || defined(__x86_64__)
 
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index 40b5baecde..0000b2b9b6 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -97,15 +97,6 @@ typedef uint64_t x86_pgentry_t;
 
 #define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)
 
-
-/* XXX SMH: following skanky macros rely on variable p2m_size being set */
-/* XXX TJD: also, "guest_width" should be the guest's sizeof(unsigned long) */
-
-struct domain_info_context {
-    unsigned int guest_width;
-    unsigned long p2m_size;
-};
-
 static inline xen_pfn_t xc_pfn_to_mfn(xen_pfn_t pfn, xen_pfn_t *p2m,
                                       unsigned gwidth)
 {
@@ -121,19 +112,6 @@ static inline xen_pfn_t xc_pfn_to_mfn(xen_pfn_t pfn, xen_pfn_t *p2m,
     }
 }
 
-/* Number of xen_pfn_t in a page */
-#define FPP             (PAGE_SIZE/(dinfo->guest_width))
-
-/* Number of entries in the pfn_to_mfn_frame_list_list */
-#define P2M_FLL_ENTRIES (((dinfo->p2m_size)+(FPP*FPP)-1)/(FPP*FPP))
-
-/* Number of entries in the pfn_to_mfn_frame_list */
-#define P2M_FL_ENTRIES  (((dinfo->p2m_size)+FPP-1)/FPP)
-
-/* Size in bytes of the pfn_to_mfn_frame_list     */
-#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (dinfo->guest_width))
-#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) *                           \
-                           max_t(size_t, sizeof(xen_pfn_t), dinfo->guest_width))
 
 /* Masks for PTE<->PFN conversions */
 #define MADDR_BITS_X86  ((dinfo->guest_width == 8) ? 52 : 44)
diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index b904296997..88120eb54b 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -109,15 +109,6 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT)
 #define M2P_CHUNKS(_m)  (M2P_SIZE((_m)) >> M2P_SHIFT)
 
-#define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
-
-#define SET_FIELD(_p, _f, _v, _w) do {          \
-    if ((_w) == 8)                              \
-        (_p)->x64._f = (_v);                    \
-    else                                        \
-        (_p)->x32._f = (_v);                    \
-} while (0)
-
 #define UNFOLD_CR3(_c)                                                  \
   ((uint64_t)((dinfo->guest_width == 8)                                 \
               ? ((_c) >> 12)                                            \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:42 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2o-0000li-4C; Wed, 09 Sep 2020 11:13:42 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2n-0000lb-LP
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:41 +0000
X-Inumbo-ID: 3dcddfb3-045a-41b0-bd4a-8fe02014ebe1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3dcddfb3-045a-41b0-bd4a-8fe02014ebe1;
 Wed, 09 Sep 2020 11:13:40 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=A4THdFwEymvqXsLfRuquaUmDVnLoIxSJL/2kDtV3WHU=; b=5ab0CZu7n3Qtzb4Q6kv7DWKj0V
 ncgWrwc7w4flrBjlW37MNRyeZj/+snk35piTeHfX/+yagcq+OdPKRcX9qmP5Bn6DzO4qv94AINZpp
 wVUbr7N6GYsiZkzMv6DfZ7nwE1WKnSJTKj+UNgrxEfcqWRSPk0jRxT9DhtDVYoqHPd9Y=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2m-00066o-3U
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:40 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2m-0001WN-2N
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:40 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/xcutils: use official headers in readnotes
Message-Id: <E1kFy2m-0001WN-2N@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:13:40 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 725588cfd11443689a40db4bf31e71b974ff5555
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:32 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xcutils: use official headers in readnotes
    
    readnotes.c is including xg_private.h. Now that the xenctrl headers
    are structured better this is no longer needed.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xcutils/Makefile    | 3 +--
 tools/xcutils/readnotes.c | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/xcutils/Makefile b/tools/xcutils/Makefile
index 2811893980..82d42624c8 100644
--- a/tools/xcutils/Makefile
+++ b/tools/xcutils/Makefile
@@ -15,8 +15,7 @@ PROGRAMS = readnotes lsevtchn
 
 CFLAGS += -Werror
 
-# incorrectly uses libxc internals
-CFLAGS_readnotes.o  := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
+CFLAGS_readnotes.o  := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
 CFLAGS_lsevtchn.o   := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl)
 
 .PHONY: all
diff --git a/tools/xcutils/readnotes.c b/tools/xcutils/readnotes.c
index a6b7358e70..ff684c7dcb 100644
--- a/tools/xcutils/readnotes.c
+++ b/tools/xcutils/readnotes.c
@@ -11,8 +11,9 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-#include <xg_private.h>
-#include <xenctrl_dom.h> /* gunzip bits */
+#include <xen/xen.h>
+#include <xenctrl.h>
+#include <xenguest.h>
 
 #include <xen/libelf/libelf.h>
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:13:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:13:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy2y-0000n0-5t; Wed, 09 Sep 2020 11:13:52 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy2x-0000ms-DD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:51 +0000
X-Inumbo-ID: 91b62413-de3c-4481-9f6e-974ecde4cee5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 91b62413-de3c-4481-9f6e-974ecde4cee5;
 Wed, 09 Sep 2020 11:13:50 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=MGd0F7L0u7rBJqblGT+BYcmD7fVUrgHYgex5d1SxKOc=; b=ulRfrhH2jUEQ8u2MW+mAwQ+hCO
 n2PsiLZn85E//NzcR4VXB/9AWLi2dOhERI+m/HC15Net7vLonYYGh4mu76W7STexE0439xO4HdNig
 FS0+x4RfV2y2j0LZdB4yZ8X653kgMvObmXG5y1AZgA6jXzXH9vaAD8xOJWiZbDLFO64U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2w-00066v-7G
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:50 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy2w-0001XC-6S
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:13:50 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/xenpaging: remove libxc internals
Message-Id: <E1kFy2w-0001XC-6S@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:13:50 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 30f5e8aba1e3e24fc9c4220bbacee37ca7c87ba6
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:33 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xenpaging: remove libxc internals
    
    xenpaging is using libxc internals. Fix that.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xenpaging/Makefile         |  3 +-
 tools/xenpaging/file_ops.c       |  8 ++---
 tools/xenpaging/pagein.c         |  2 +-
 tools/xenpaging/policy_default.c |  2 +-
 tools/xenpaging/xenpaging.c      | 32 +++++++++---------
 tools/xenpaging/xenpaging.h      | 70 +++++++++++++++++++++++++++++++++++++++-
 6 files changed, 92 insertions(+), 25 deletions(-)

diff --git a/tools/xenpaging/Makefile b/tools/xenpaging/Makefile
index 968678c4e8..04743b335c 100644
--- a/tools/xenpaging/Makefile
+++ b/tools/xenpaging/Makefile
@@ -1,8 +1,7 @@
 XEN_ROOT=$(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-# xenpaging.c and file_ops.c incorrectly use libxc internals
-CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
+CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) $(CFLAGS_libxencall)
 LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
diff --git a/tools/xenpaging/file_ops.c b/tools/xenpaging/file_ops.c
index 8210f426df..301fb3427c 100644
--- a/tools/xenpaging/file_ops.c
+++ b/tools/xenpaging/file_ops.c
@@ -20,7 +20,7 @@
 
 
 #include <unistd.h>
-#include <xc_private.h>
+#include <xenctrl.h>
 
 static int file_op(int fd, void *page, int i,
                    ssize_t (*fn)(int, void *, size_t))
@@ -29,13 +29,13 @@ static int file_op(int fd, void *page, int i,
     int total = 0;
     int bytes;
 
-    offset = lseek(fd, offset << PAGE_SHIFT, SEEK_SET);
+    offset = lseek(fd, offset << XC_PAGE_SHIFT, SEEK_SET);
     if ( offset == (off_t)-1 )
         return -1;
 
-    while ( total < PAGE_SIZE )
+    while ( total < XC_PAGE_SIZE )
     {
-        bytes = fn(fd, page + total, PAGE_SIZE - total);
+        bytes = fn(fd, page + total, XC_PAGE_SIZE - total);
         if ( bytes <= 0 )
             return -1;
 
diff --git a/tools/xenpaging/pagein.c b/tools/xenpaging/pagein.c
index 2a298b436c..1c8a7d983d 100644
--- a/tools/xenpaging/pagein.c
+++ b/tools/xenpaging/pagein.c
@@ -43,7 +43,7 @@ static void *page_in(void *arg)
         /* Ignore errors */
         page = xc_map_foreign_pages(pia->xch, pia->dom, PROT_READ, gfns, num);
         if (page)
-            munmap(page, PAGE_SIZE * num);
+            munmap(page, XC_PAGE_SIZE * num);
     }
     page_in_possible = 0;
     pthread_exit(NULL);
diff --git a/tools/xenpaging/policy_default.c b/tools/xenpaging/policy_default.c
index 3324835957..979d251230 100644
--- a/tools/xenpaging/policy_default.c
+++ b/tools/xenpaging/policy_default.c
@@ -18,8 +18,8 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <errno.h>
 
-#include "xc_bitops.h"
 #include "policy.h"
 
 
diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c
index d0571cabac..33098046c2 100644
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -30,7 +30,6 @@
 #include <xenstore.h>
 #include <getopt.h>
 
-#include "xc_bitops.h"
 #include "file_ops.h"
 #include "policy.h"
 #include "xenpaging.h"
@@ -183,12 +182,12 @@ static void *init_page(void)
     void *buffer;
 
     /* Allocated page memory */
-    errno = posix_memalign(&buffer, PAGE_SIZE, PAGE_SIZE);
+    errno = posix_memalign(&buffer, XC_PAGE_SIZE, XC_PAGE_SIZE);
     if ( errno != 0 )
         return NULL;
 
     /* Lock buffer in memory so it can't be paged out */
-    if ( mlock(buffer, PAGE_SIZE) < 0 )
+    if ( mlock(buffer, XC_PAGE_SIZE) < 0 )
     {
         free(buffer);
         buffer = NULL;
@@ -277,7 +276,6 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     struct xenpaging *paging;
     xc_domaininfo_t domain_info;
     xc_interface *xch = NULL;
-    xentoollog_logger *dbg = NULL;
     char *p;
     int rc;
     unsigned long ring_pfn, mmap_pfn;
@@ -291,12 +289,11 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     if ( xenpaging_getopts(paging, argc, argv) )
         goto err;
 
-    /* Enable debug output */
-    if ( paging->debug )
-        dbg = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0);
+    paging->logger = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr,
+                         paging->debug ? XTL_DEBUG : XTL_PROGRESS, 0);
 
     /* Open connection to xen */
-    paging->xc_handle = xch = xc_interface_open(dbg, NULL, 0);
+    paging->xc_handle = xch = xc_interface_open(paging->logger, NULL, 0);
     if ( !xch )
         goto err;
 
@@ -416,7 +413,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     SHARED_RING_INIT((vm_event_sring_t *)paging->vm_event.ring_page);
     BACK_RING_INIT(&paging->vm_event.back_ring,
                    (vm_event_sring_t *)paging->vm_event.ring_page,
-                   PAGE_SIZE);
+                   XC_PAGE_SIZE);
 
     /* Now that the ring is set, remove it from the guest's physmap */
     if ( xc_domain_decrease_reservation_exact(xch, 
@@ -490,15 +487,17 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
             xs_close(paging->xs_handle);
         if ( xch )
             xc_interface_close(xch);
+        if ( paging->logger )
+            xtl_logger_destroy(paging->logger);
         if ( paging->paging_buffer )
         {
-            munlock(paging->paging_buffer, PAGE_SIZE);
+            munlock(paging->paging_buffer, XC_PAGE_SIZE);
             free(paging->paging_buffer);
         }
 
         if ( paging->vm_event.ring_page )
         {
-            munmap(paging->vm_event.ring_page, PAGE_SIZE);
+            munmap(paging->vm_event.ring_page, XC_PAGE_SIZE);
         }
 
         free(dom_path);
@@ -523,7 +522,7 @@ static void xenpaging_teardown(struct xenpaging *paging)
 
     paging->xc_handle = NULL;
     /* Tear down domain paging in Xen */
-    munmap(paging->vm_event.ring_page, PAGE_SIZE);
+    munmap(paging->vm_event.ring_page, XC_PAGE_SIZE);
     rc = xc_mem_paging_disable(xch, paging->vm_event.domain_id);
     if ( rc != 0 )
     {
@@ -551,6 +550,8 @@ static void xenpaging_teardown(struct xenpaging *paging)
 
     /* Close connection to Xen */
     xc_interface_close(xch);
+
+    xtl_logger_destroy(paging->logger);
 }
 
 static void get_request(struct vm_event *vm_event, vm_event_request_t *req)
@@ -598,8 +599,7 @@ static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int
     void *page;
     xen_pfn_t victim = gfn;
     int ret;
-
-    DECLARE_DOMCTL;
+    struct xen_domctl domctl;
 
     /* Nominate page */
     ret = xc_mem_paging_nominate(xch, paging->vm_event.domain_id, gfn);
@@ -627,13 +627,13 @@ static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int
     if ( ret < 0 )
     {
         PERROR("Error copying page %lx", gfn);
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
         ret = -1;
         goto out;
     }
 
     /* Release page */
-    munmap(page, PAGE_SIZE);
+    munmap(page, XC_PAGE_SIZE);
 
     /* Tell Xen to evict page */
     ret = xc_mem_paging_evict(xch, paging->vm_event.domain_id, gfn);
diff --git a/tools/xenpaging/xenpaging.h b/tools/xenpaging/xenpaging.h
index d6c8ee5221..e0fc7b31b8 100644
--- a/tools/xenpaging/xenpaging.h
+++ b/tools/xenpaging/xenpaging.h
@@ -23,11 +23,17 @@
 #ifndef __XEN_PAGING2_H__
 #define __XEN_PAGING2_H__
 
+#include <malloc.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
 
 #include <xenevtchn.h>
 #define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
-#include <xc_private.h>
+// #include <xc_private.h>
 #include <xen/event_channel.h>
 #include <xen/vm_event.h>
 
@@ -44,6 +50,7 @@ struct vm_event {
 
 struct xenpaging {
     xc_interface *xc_handle;
+    xentoollog_logger *logger;
     struct xs_handle *xs_handle;
 
     unsigned long *bitmap;
@@ -67,9 +74,70 @@ struct xenpaging {
     unsigned long pagein_queue[XENPAGING_PAGEIN_QUEUE_SIZE];
 };
 
+#define DPRINTF(msg, args...) xtl_log(paging->logger, XTL_DETAIL, 0,      \
+                                      "paging", msg, ## args)
+#define ERROR(msg, args...)   xtl_log(paging->logger, XTL_ERROR, -1,      \
+                                      "paging", msg, ## args)
+#define PERROR(msg, args...)  xtl_log(paging->logger, XTL_ERROR, -1,      \
+                                      "paging", msg "(%d = %s)", ## args, \
+                                      errno, strerror(errno))
+
 extern void create_page_in_thread(struct xenpaging *paging);
 extern void page_in_trigger(void);
 
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
+#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)
+
+#define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8]
+#define BITMAP_SHIFT(_nr) ((_nr) % 8)
+
+static inline int bitmap_size(int nr_bits)
+{
+    return (nr_bits + 7) / 8;
+}
+
+static inline void *bitmap_alloc(int nr_bits)
+{
+    return calloc(1, bitmap_size(nr_bits));
+}
+
+static inline void bitmap_clear(void *addr, int nr_bits)
+{
+    memset(addr, 0, bitmap_size(nr_bits));
+}
+
+static inline int test_bit(int nr, const void *_addr)
+{
+    const char *addr = _addr;
+    return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
+}
+
+static inline void clear_bit(int nr, void *_addr)
+{
+    char *addr = _addr;
+    BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr));
+}
+
+static inline void set_bit(int nr, void *_addr)
+{
+    char *addr = _addr;
+    BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr));
+}
+
+static inline int test_and_clear_bit(int nr, void *addr)
+{
+    int oldbit = test_bit(nr, addr);
+    clear_bit(nr, addr);
+    return oldbit;
+}
+
+static inline int test_and_set_bit(int nr, void *addr)
+{
+    int oldbit = test_bit(nr, addr);
+    set_bit(nr, addr);
+    return oldbit;
+}
+
 #endif // __XEN_PAGING_H__
 
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:07 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:07 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3D-0000oU-9l; Wed, 09 Sep 2020 11:14:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3C-0000oN-12
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:06 +0000
X-Inumbo-ID: cf1c3075-d378-408d-9cfa-3f9bd0f8c1d9
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cf1c3075-d378-408d-9cfa-3f9bd0f8c1d9;
 Wed, 09 Sep 2020 11:14:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IQ6B7YDmUqyTx6F2xD4Pk+QBM/34UiypNDmBUKNdz6g=; b=KNc8Aewdx3vgV3jUacP+57z8JT
 /7jwHjmfZRODLrxQApdkJQdPenQ2BeURY6aBmavuVanEGDEtwxw5BvHFcOC9UOc7E52pRwoK1dwc7
 veWoy+RcpmNBxDjz3D04kMkhHVrY3ua3Jwr2W29u2nyurvhDbq6Mq3YEaypOxwmb/BV4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy36-00067g-Ct
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:00 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy36-0001Xl-Bv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:00 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: move libxenctrl below tools/libs
Message-Id: <E1kFy36-0001Xl-Bv@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:00 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit af6c78d9dc68366d0d9a1d41de26f3765dfef5f0
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:34 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: move libxenctrl below tools/libs
    
    Today tools/libxc needs to be built after tools/libs as libxenctrl is
    depending on some libraries in tools/libs. This in turn blocks moving
    other libraries depending on libxenctrl below tools/libs.
    
    So carve out libxenctrl from tools/libxc and move it into
    tools/libs/ctrl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> (stubdom parts)
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> (python parts)
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                               |    8 +
 MAINTAINERS                              |    2 +-
 stubdom/Makefile                         |    9 +-
 stubdom/grub/Makefile                    |    4 +-
 stubdom/mini-os.mk                       |    2 +-
 tools/Rules.mk                           |    8 +-
 tools/libs/Makefile                      |    1 +
 tools/libs/ctrl/Makefile                 |   72 +
 tools/libs/ctrl/include/xenctrl.h        | 2668 ++++++++++++++++++++++++++++++
 tools/libs/ctrl/include/xenctrl_compat.h |  183 ++
 tools/libs/ctrl/include/xenctrl_dom.h    |  455 +++++
 tools/libs/ctrl/xc_altp2m.c              |  436 +++++
 tools/libs/ctrl/xc_arinc653.c            |   87 +
 tools/libs/ctrl/xc_bitops.h              |   79 +
 tools/libs/ctrl/xc_core.c                | 1008 +++++++++++
 tools/libs/ctrl/xc_core.h                |  176 ++
 tools/libs/ctrl/xc_core_arm.c            |  122 ++
 tools/libs/ctrl/xc_core_arm.h            |   59 +
 tools/libs/ctrl/xc_core_x86.c            |  223 +++
 tools/libs/ctrl/xc_core_x86.h            |   60 +
 tools/libs/ctrl/xc_cpu_hotplug.c         |   74 +
 tools/libs/ctrl/xc_cpupool.c             |  219 +++
 tools/libs/ctrl/xc_csched.c              |  109 ++
 tools/libs/ctrl/xc_csched2.c             |  109 ++
 tools/libs/ctrl/xc_devicemodel_compat.c  |  147 ++
 tools/libs/ctrl/xc_domain.c              | 2205 ++++++++++++++++++++++++
 tools/libs/ctrl/xc_evtchn.c              |   85 +
 tools/libs/ctrl/xc_evtchn_compat.c       |   75 +
 tools/libs/ctrl/xc_flask.c               |  450 +++++
 tools/libs/ctrl/xc_foreign_memory.c      |   98 ++
 tools/libs/ctrl/xc_freebsd.c             |   71 +
 tools/libs/ctrl/xc_gnttab.c              |  161 ++
 tools/libs/ctrl/xc_gnttab_compat.c       |  111 ++
 tools/libs/ctrl/xc_hcall_buf.c           |  190 +++
 tools/libs/ctrl/xc_kexec.c               |  152 ++
 tools/libs/ctrl/xc_linux.c               |   77 +
 tools/libs/ctrl/xc_mem_access.c          |  110 ++
 tools/libs/ctrl/xc_mem_paging.c          |  130 ++
 tools/libs/ctrl/xc_memshr.c              |  289 ++++
 tools/libs/ctrl/xc_minios.c              |   67 +
 tools/libs/ctrl/xc_misc.c                |  999 +++++++++++
 tools/libs/ctrl/xc_monitor.c             |  257 +++
 tools/libs/ctrl/xc_msr_x86.h             |   37 +
 tools/libs/ctrl/xc_netbsd.c              |   74 +
 tools/libs/ctrl/xc_pagetab.c             |  113 ++
 tools/libs/ctrl/xc_physdev.c             |  113 ++
 tools/libs/ctrl/xc_pm.c                  |  455 +++++
 tools/libs/ctrl/xc_private.c             |  781 +++++++++
 tools/libs/ctrl/xc_private.h             |  479 ++++++
 tools/libs/ctrl/xc_psr.c                 |  395 +++++
 tools/libs/ctrl/xc_resource.c            |  151 ++
 tools/libs/ctrl/xc_resume.c              |  288 ++++
 tools/libs/ctrl/xc_rt.c                  |  132 ++
 tools/libs/ctrl/xc_solaris.c             |   43 +
 tools/libs/ctrl/xc_tbuf.c                |  172 ++
 tools/libs/ctrl/xc_vm_event.c            |  183 ++
 tools/libs/uselibs.mk                    |    2 +
 tools/libxc/Makefile                     |  109 +-
 tools/libxc/include/xenctrl.h            | 2668 ------------------------------
 tools/libxc/include/xenctrl_compat.h     |  183 --
 tools/libxc/include/xenctrl_dom.h        |  455 -----
 tools/libxc/xc_altp2m.c                  |  436 -----
 tools/libxc/xc_arinc653.c                |   87 -
 tools/libxc/xc_bitops.h                  |   79 -
 tools/libxc/xc_core.c                    | 1008 -----------
 tools/libxc/xc_core.h                    |  176 --
 tools/libxc/xc_core_arm.c                |  122 --
 tools/libxc/xc_core_arm.h                |   59 -
 tools/libxc/xc_core_x86.c                |  223 ---
 tools/libxc/xc_core_x86.h                |   60 -
 tools/libxc/xc_cpu_hotplug.c             |   74 -
 tools/libxc/xc_cpupool.c                 |  219 ---
 tools/libxc/xc_csched.c                  |  109 --
 tools/libxc/xc_csched2.c                 |  109 --
 tools/libxc/xc_devicemodel_compat.c      |  147 --
 tools/libxc/xc_domain.c                  | 2205 ------------------------
 tools/libxc/xc_evtchn.c                  |   85 -
 tools/libxc/xc_evtchn_compat.c           |   75 -
 tools/libxc/xc_flask.c                   |  450 -----
 tools/libxc/xc_foreign_memory.c          |   98 --
 tools/libxc/xc_freebsd.c                 |   71 -
 tools/libxc/xc_gnttab.c                  |  161 --
 tools/libxc/xc_gnttab_compat.c           |  111 --
 tools/libxc/xc_hcall_buf.c               |  190 ---
 tools/libxc/xc_kexec.c                   |  152 --
 tools/libxc/xc_linux.c                   |   77 -
 tools/libxc/xc_mem_access.c              |  110 --
 tools/libxc/xc_mem_paging.c              |  130 --
 tools/libxc/xc_memshr.c                  |  289 ----
 tools/libxc/xc_minios.c                  |   67 -
 tools/libxc/xc_misc.c                    |  999 -----------
 tools/libxc/xc_monitor.c                 |  257 ---
 tools/libxc/xc_msr_x86.h                 |   37 -
 tools/libxc/xc_netbsd.c                  |   74 -
 tools/libxc/xc_pagetab.c                 |  113 --
 tools/libxc/xc_physdev.c                 |  113 --
 tools/libxc/xc_pm.c                      |  455 -----
 tools/libxc/xc_private.c                 |  781 ---------
 tools/libxc/xc_private.h                 |  479 ------
 tools/libxc/xc_psr.c                     |  395 -----
 tools/libxc/xc_resource.c                |  151 --
 tools/libxc/xc_resume.c                  |  288 ----
 tools/libxc/xc_rt.c                      |  132 --
 tools/libxc/xc_solaris.c                 |   43 -
 tools/libxc/xc_tbuf.c                    |  172 --
 tools/libxc/xc_vm_event.c                |  183 --
 tools/ocaml/xenstored/Makefile           |    2 +-
 tools/python/Makefile                    |    2 +-
 tools/python/setup.py                    |    8 +-
 109 files changed, 15268 insertions(+), 15275 deletions(-)

diff --git a/.gitignore b/.gitignore
index 823f4743dc..d22b031ed2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,9 @@ tools/libs/hypfs/headers.chk
 tools/libs/hypfs/xenhypfs.pc
 tools/libs/call/headers.chk
 tools/libs/call/xencall.pc
+tools/libs/ctrl/_*.[ch]
+tools/libs/ctrl/libxenctrl.map
+tools/libs/ctrl/xencontrol.pc
 tools/libs/foreignmemory/headers.chk
 tools/libs/foreignmemory/xenforeignmemory.pc
 tools/libs/devicemodel/headers.chk
@@ -195,6 +198,11 @@ tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
 tools/libvchan/xenvchan.pc
 tools/libxc/*.pc
+tools/libxc/xc_bitops.h
+tools/libxc/xc_core.h
+tools/libxc/xc_core_arm.h
+tools/libxc/xc_core_x86.h
+tools/libxc/xc_private.h
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
diff --git a/MAINTAINERS b/MAINTAINERS
index ffe2310294..26c5382075 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -226,7 +226,7 @@ M:	Stewart Hildebrand <stewart.hildebrand@dornerworks.com>
 S:	Supported
 L:	xen-devel@dornerworks.com
 F:	xen/common/sched/arinc653.c
-F:	tools/libxc/xc_arinc653.c
+F:	tools/libs/ctrl/xc_arinc653.c
 
 ARM (W/ VIRTUALISATION EXTENSIONS) ARCHITECTURE
 M:	Stefano Stabellini <sstabellini@kernel.org>
diff --git a/stubdom/Makefile b/stubdom/Makefile
index f000f56e68..6c481285ec 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -331,7 +331,7 @@ endif
 # libraries under tools/libs
 #######
 
-STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel
+STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl
 
 #######
 # common handling
@@ -396,12 +396,11 @@ $(TARGETS_MINIOS): mini-os-%:
 #######
 
 .PHONY: libxc
-libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel cross-zlib
+libxc: libxc-$(XEN_TARGET_ARCH)/libxenguest.a
+libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxenevtchn libxenctrl cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenguest.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
- libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
-
 #######
 # ioemu
 #######
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
index 26dff45a8f..d33fa2f71e 100644
--- a/stubdom/grub/Makefile
+++ b/stubdom/grub/Makefile
@@ -6,7 +6,9 @@ vpath %.c ../grub-upstream
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include -I$(XEN_ROOT)/tools/include -I.
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
 DEF_CPPFLAGS += -I../grub-upstream/netboot
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index 32528bb91f..b1387df3f8 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -13,5 +13,5 @@ GNTTAB_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
 CALL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
 FOREIGNMEMORY_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
 DEVICEMODEL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
-CTRL_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+CTRL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/ctrl
 GUEST_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 13432560ff..35940cb338 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -15,7 +15,6 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
 XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
@@ -105,13 +104,10 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
-CFLAGS_libxenctrl = -I$(XEN_libxenctrl)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) $(SHLIB_libxendevicemodel)
-LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_libxenctrl)/libxenctrl$(libextension)
-SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_libxenctrl)
+CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
 
 CFLAGS_libxenguest = -I$(XEN_libxenguest)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
-SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
+SHDEPS_libxenguest = $(SHLIB_libxenevtchn) $(SHLIB_libxenctrl)
 LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libextension)
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
 
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 69cdfb5975..7648ea0e4c 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -9,6 +9,7 @@ SUBDIRS-y += gnttab
 SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
 SUBDIRS-y += devicemodel
+SUBDIRS-y += ctrl
 SUBDIRS-y += hypfs
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile
new file mode 100644
index 0000000000..ec93fb5b73
--- /dev/null
+++ b/tools/libs/ctrl/Makefile
@@ -0,0 +1,72 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SRCS-y       += xc_altp2m.c
+SRCS-y       += xc_core.c
+SRCS-$(CONFIG_X86) += xc_core_x86.c
+SRCS-$(CONFIG_ARM) += xc_core_arm.c
+SRCS-y       += xc_cpupool.c
+SRCS-y       += xc_domain.c
+SRCS-y       += xc_evtchn.c
+SRCS-y       += xc_gnttab.c
+SRCS-y       += xc_misc.c
+SRCS-y       += xc_flask.c
+SRCS-y       += xc_physdev.c
+SRCS-y       += xc_private.c
+SRCS-y       += xc_csched.c
+SRCS-y       += xc_csched2.c
+SRCS-y       += xc_arinc653.c
+SRCS-y       += xc_rt.c
+SRCS-y       += xc_tbuf.c
+SRCS-y       += xc_pm.c
+SRCS-y       += xc_cpu_hotplug.c
+SRCS-y       += xc_resume.c
+SRCS-y       += xc_vm_event.c
+SRCS-y       += xc_monitor.c
+SRCS-y       += xc_mem_paging.c
+SRCS-y       += xc_mem_access.c
+SRCS-y       += xc_memshr.c
+SRCS-y       += xc_hcall_buf.c
+SRCS-y       += xc_foreign_memory.c
+SRCS-y       += xc_kexec.c
+SRCS-y       += xc_resource.c
+SRCS-$(CONFIG_X86) += xc_psr.c
+SRCS-$(CONFIG_X86) += xc_pagetab.c
+SRCS-$(CONFIG_Linux) += xc_linux.c
+SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c
+SRCS-$(CONFIG_SunOS) += xc_solaris.c
+SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
+SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
+SRCS-$(CONFIG_MiniOS) += xc_minios.c
+SRCS-y       += xc_evtchn_compat.c
+SRCS-y       += xc_gnttab_compat.c
+SRCS-y       += xc_devicemodel_compat.c
+
+CFLAGS   += -D__XEN_TOOLS__
+CFLAGS	+= $(PTHREAD_CFLAGS)
+CFLAGS += -include $(XEN_ROOT)/tools/config.h
+
+# Needed for posix_fadvise64() in xc_linux.c
+CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
+
+LIBHEADER := xenctrl.h xenctrl_compat.h xenctrl_dom.h
+PKG_CONFIG := xencontrol.pc
+PKG_CONFIG_NAME := Xencontrol
+
+NO_HEADERS_CHK := y
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
+
+$(LIB_OBJS) $(PIC_OBJS): _paths.h
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenctrl)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenctrl.map
diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
new file mode 100644
index 0000000000..4c89b7294c
--- /dev/null
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -0,0 +1,2668 @@
+/******************************************************************************
+ * xenctrl.h
+ *
+ * A library for low-level access to the Xen control interfaces.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XENCTRL_H
+#define XENCTRL_H
+
+/* Tell the Xen public headers we are a user-space tools build. */
+#ifndef __XEN_TOOLS__
+#define __XEN_TOOLS__ 1
+#endif
+
+#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <xen/xen.h>
+#include <xen/domctl.h>
+#include <xen/physdev.h>
+#include <xen/sysctl.h>
+#include <xen/version.h>
+#include <xen/event_channel.h>
+#include <xen/sched.h>
+#include <xen/memory.h>
+#include <xen/grant_table.h>
+#include <xen/hvm/dm_op.h>
+#include <xen/hvm/params.h>
+#include <xen/xsm/flask_op.h>
+#include <xen/kexec.h>
+#include <xen/platform.h>
+
+#include "xentoollog.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/arch-x86/xen-mca.h>
+#endif
+
+#define XC_PAGE_SHIFT           12
+#define XC_PAGE_SIZE            (1UL << XC_PAGE_SHIFT)
+#define XC_PAGE_MASK            (~(XC_PAGE_SIZE-1))
+
+#define INVALID_MFN  (~0UL)
+
+/*
+ *  DEFINITIONS FOR CPU BARRIERS
+ */
+
+#define xen_barrier() asm volatile ( "" : : : "memory")
+
+#if defined(__i386__)
+#define xen_mb()  asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
+#define xen_rmb() xen_barrier()
+#define xen_wmb() xen_barrier()
+#elif defined(__x86_64__)
+#define xen_mb()  asm volatile ( "mfence" : : : "memory")
+#define xen_rmb() xen_barrier()
+#define xen_wmb() xen_barrier()
+#elif defined(__arm__)
+#define xen_mb()   asm volatile ("dmb" : : : "memory")
+#define xen_rmb()  asm volatile ("dmb" : : : "memory")
+#define xen_wmb()  asm volatile ("dmb" : : : "memory")
+#elif defined(__aarch64__)
+#define xen_mb()   asm volatile ("dmb sy" : : : "memory")
+#define xen_rmb()  asm volatile ("dmb sy" : : : "memory")
+#define xen_wmb()  asm volatile ("dmb sy" : : : "memory")
+#else
+#error "Define barriers"
+#endif
+
+
+#define XENCTRL_HAS_XC_INTERFACE 1
+/* In Xen 4.0 and earlier, xc_interface_open and xc_evtchn_open would
+ * both return ints being the file descriptor.  In 4.1 and later, they
+ * return an xc_interface* and xc_evtchn*, respectively - ie, a
+ * pointer to an opaque struct.  This #define is provided in 4.1 and
+ * later, allowing out-of-tree callers to more easily distinguish
+ * between, and be compatible with, both versions.
+ */
+
+
+/*
+ *  GENERAL
+ *
+ * Unless otherwise specified, each function here returns zero or a
+ * non-null pointer on success; or in case of failure, sets errno and
+ * returns -1 or a null pointer.
+ *
+ * Unless otherwise specified, errors result in a call to the error
+ * handler function, which by default prints a message to the
+ * FILE* passed as the caller_data, which by default is stderr.
+ * (This is described below as "logging errors".)
+ *
+ * The error handler can safely trash errno, as libxc saves it across
+ * the callback.
+ */
+
+typedef struct xc_interface_core xc_interface;
+
+enum xc_error_code {
+  XC_ERROR_NONE = 0,
+  XC_INTERNAL_ERROR = 1,
+  XC_INVALID_KERNEL = 2,
+  XC_INVALID_PARAM = 3,
+  XC_OUT_OF_MEMORY = 4,
+  /* new codes need to be added to xc_error_level_to_desc too */
+};
+
+typedef enum xc_error_code xc_error_code;
+
+
+/*
+ *  INITIALIZATION FUNCTIONS
+ */
+
+/**
+ * This function opens a handle to the hypervisor interface.  This function can
+ * be called multiple times within a single process.  Multiple processes can
+ * have an open hypervisor interface at the same time.
+ *
+ * Note:
+ * After fork a child process must not use any opened xc interface
+ * handle inherited from their parent. They must open a new handle if
+ * they want to interact with xc.
+ *
+ * Each call to this function should have a corresponding call to
+ * xc_interface_close().
+ *
+ * This function can fail if the caller does not have superuser permission or
+ * if a Xen-enabled kernel is not currently running.
+ *
+ * @return a handle to the hypervisor interface
+ */
+xc_interface *xc_interface_open(xentoollog_logger *logger,
+                                xentoollog_logger *dombuild_logger,
+                                unsigned open_flags);
+  /* if logger==NULL, will log to stderr
+   * if dombuild_logger=NULL, will log to a file
+   */
+
+/*
+ * Note: if XC_OPENFLAG_NON_REENTRANT is passed then libxc must not be
+ * called reentrantly and the calling application is responsible for
+ * providing mutual exclusion surrounding all libxc calls itself.
+ *
+ * In particular xc_{get,clear}_last_error only remain valid for the
+ * duration of the critical section containing the call which failed.
+ */
+enum xc_open_flags {
+    XC_OPENFLAG_DUMMY =  1<<0, /* do not actually open a xenctrl interface */
+    XC_OPENFLAG_NON_REENTRANT = 1<<1, /* assume library is only every called from a single thread */
+};
+
+/**
+ * This function closes an open hypervisor interface.
+ *
+ * This function can fail if the handle does not represent an open interface or
+ * if there were problems closing the interface.  In the latter case
+ * the interface is still closed.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @return 0 on success, -1 otherwise.
+ */
+int xc_interface_close(xc_interface *xch);
+
+/**
+ * Return the handles which xch has opened and will use for
+ * hypercalls, foreign memory accesses and device model operations.
+ * These may be used with the corresponding libraries so long as the
+ * xch itself remains open.
+ */
+struct xencall_handle *xc_interface_xcall_handle(xc_interface *xch);
+struct xenforeignmemory_handle *xc_interface_fmem_handle(xc_interface *xch);
+struct xendevicemodel_handle *xc_interface_dmod_handle(xc_interface *xch);
+
+/*
+ * HYPERCALL SAFE MEMORY BUFFER
+ *
+ * Ensure that memory which is passed to a hypercall has been
+ * specially allocated in order to be safe to access from the
+ * hypervisor.
+ *
+ * Each user data pointer is shadowed by an xc_hypercall_buffer data
+ * structure. You should never define an xc_hypercall_buffer type
+ * directly, instead use the DECLARE_HYPERCALL_BUFFER* macros below.
+ *
+ * The strucuture should be considered opaque and all access should be
+ * via the macros and helper functions defined below.
+ *
+ * Once the buffer is declared the user is responsible for explicitly
+ * allocating and releasing the memory using
+ * xc_hypercall_buffer_alloc(_pages) and
+ * xc_hypercall_buffer_free(_pages).
+ *
+ * Once the buffer has been allocated the user can initialise the data
+ * via the normal pointer. The xc_hypercall_buffer structure is
+ * transparently referenced by the helper macros (such as
+ * xen_set_guest_handle) in order to check at compile time that the
+ * correct type of memory is being used.
+ */
+struct xc_hypercall_buffer {
+    /* Hypercall safe memory buffer. */
+    void *hbuf;
+
+    /*
+     * Reference to xc_hypercall_buffer passed as argument to the
+     * current function.
+     */
+    struct xc_hypercall_buffer *param_shadow;
+
+    /*
+     * Direction of copy for bounce buffering.
+     */
+    int dir;
+
+    /* Used iff dir != 0. */
+    void *ubuf;
+    size_t sz;
+};
+typedef struct xc_hypercall_buffer xc_hypercall_buffer_t;
+
+/*
+ * Construct the name of the hypercall buffer for a given variable.
+ * For internal use only
+ */
+#define XC__HYPERCALL_BUFFER_NAME(_name) xc__hypercall_buffer_##_name
+
+/*
+ * Returns the hypercall_buffer associated with a variable.
+ */
+#define HYPERCALL_BUFFER(_name)                                 \
+    ({  xc_hypercall_buffer_t _hcbuf_buf1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_buf2 = \
+                &XC__HYPERCALL_BUFFER_NAME(_name);              \
+        (void)(&_hcbuf_buf1 == _hcbuf_buf2);                    \
+        (_hcbuf_buf2)->param_shadow ?                           \
+                (_hcbuf_buf2)->param_shadow : (_hcbuf_buf2);    \
+     })
+
+#define HYPERCALL_BUFFER_INIT_NO_BOUNCE .dir = 0, .sz = 0, .ubuf = (void *)-1
+
+/*
+ * Defines a hypercall buffer and user pointer with _name of _type.
+ *
+ * The user accesses the data as normal via _name which will be
+ * transparently converted to the hypercall buffer as necessary.
+ */
+#define DECLARE_HYPERCALL_BUFFER(_type, _name)                 \
+    _type *(_name) = NULL;                                     \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = NULL,                                          \
+        .param_shadow = NULL,                                  \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Like DECLARE_HYPERCALL_BUFFER() but using an already allocated
+ * hypercall buffer, _hbuf.
+ *
+ * Useful when a hypercall buffer is passed to a function and access
+ * via the user pointer is required.
+ *
+ * See DECLARE_HYPERCALL_BUFFER_ARGUMENT() if the user pointer is not
+ * required.
+ */
+#define DECLARE_HYPERCALL_BUFFER_SHADOW(_type, _name, _hbuf)   \
+    _type *(_name) = (_hbuf)->hbuf;                            \
+    __attribute__((unused))                                    \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = (void *)-1,                                    \
+        .param_shadow = (_hbuf),                               \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Declare the necessary data structure to allow a hypercall buffer
+ * passed as an argument to a function to be used in the normal way.
+ */
+#define DECLARE_HYPERCALL_BUFFER_ARGUMENT(_name)               \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = (void *)-1,                                    \
+        .param_shadow = (_name),                               \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Get the hypercall buffer data pointer in a form suitable for use
+ * directly as a hypercall argument.
+ */
+#define HYPERCALL_BUFFER_AS_ARG(_name)                          \
+    ({  xc_hypercall_buffer_t _hcbuf_arg1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_arg2 = \
+                HYPERCALL_BUFFER(_name);                        \
+        (void)(&_hcbuf_arg1 == _hcbuf_arg2);                    \
+        (unsigned long)(_hcbuf_arg2)->hbuf;                     \
+     })
+
+/*
+ * Set a xen_guest_handle in a type safe manner, ensuring that the
+ * data pointer has been correctly allocated.
+ */
+#define set_xen_guest_handle_impl(_hnd, _val, _byte_off)        \
+    do {                                                        \
+        xc_hypercall_buffer_t _hcbuf_hnd1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_hcbuf_hnd2 =  \
+                HYPERCALL_BUFFER(_val);                         \
+        (void) (&_hcbuf_hnd1 == _hcbuf_hnd2);                   \
+        set_xen_guest_handle_raw(_hnd,                          \
+                (_hcbuf_hnd2)->hbuf + (_byte_off));             \
+    } while (0)
+
+#undef set_xen_guest_handle
+#define set_xen_guest_handle(_hnd, _val)                        \
+    set_xen_guest_handle_impl(_hnd, _val, 0)
+
+#define set_xen_guest_handle_offset(_hnd, _val, _off)           \
+    set_xen_guest_handle_impl(_hnd, _val,                       \
+            ((sizeof(*_val)*(_off))))
+
+/* Use with set_xen_guest_handle in place of NULL */
+extern xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(HYPERCALL_BUFFER_NULL);
+
+/*
+ * Allocate and free hypercall buffers with byte granularity.
+ */
+void *xc__hypercall_buffer_alloc(xc_interface *xch, xc_hypercall_buffer_t *b, size_t size);
+#define xc_hypercall_buffer_alloc(_xch, _name, _size) xc__hypercall_buffer_alloc(_xch, HYPERCALL_BUFFER(_name), _size)
+void xc__hypercall_buffer_free(xc_interface *xch, xc_hypercall_buffer_t *b);
+#define xc_hypercall_buffer_free(_xch, _name) xc__hypercall_buffer_free(_xch, HYPERCALL_BUFFER(_name))
+
+/*
+ * Allocate and free hypercall buffers with page alignment.
+ */
+void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages);
+#define xc_hypercall_buffer_alloc_pages(_xch, _name, _nr) xc__hypercall_buffer_alloc_pages(_xch, HYPERCALL_BUFFER(_name), _nr)
+void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages);
+#define xc_hypercall_buffer_free_pages(_xch, _name, _nr)                    \
+    do {                                                                    \
+        if ( _name )                                                        \
+            xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name),  \
+                                            _nr);                           \
+    } while (0)
+
+/*
+ * Array of hypercall buffers.
+ *
+ * Create an array with xc_hypercall_buffer_array_create() and
+ * populate it by declaring one hypercall buffer in a loop and
+ * allocating the buffer with xc_hypercall_buffer_array_alloc().
+ *
+ * To access a previously allocated buffers, declare a new hypercall
+ * buffer and call xc_hypercall_buffer_array_get().
+ *
+ * Destroy the array with xc_hypercall_buffer_array_destroy() to free
+ * the array and all its allocated hypercall buffers.
+ */
+struct xc_hypercall_buffer_array;
+typedef struct xc_hypercall_buffer_array xc_hypercall_buffer_array_t;
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch, unsigned n);
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                       unsigned index, xc_hypercall_buffer_t *hbuf, size_t size);
+#define xc_hypercall_buffer_array_alloc(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_alloc(_xch, _array, _index, HYPERCALL_BUFFER(_name), _size)
+void *xc__hypercall_buffer_array_get(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                     unsigned index, xc_hypercall_buffer_t *hbuf);
+#define xc_hypercall_buffer_array_get(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_get(_xch, _array, _index, HYPERCALL_BUFFER(_name))
+void xc_hypercall_buffer_array_destroy(xc_interface *xc, xc_hypercall_buffer_array_t *array);
+
+/*
+ * CPUMAP handling
+ */
+typedef uint8_t *xc_cpumap_t;
+
+/* return maximum number of cpus the hypervisor supports */
+int xc_get_max_cpus(xc_interface *xch);
+
+/* return the number of online cpus */
+int xc_get_online_cpus(xc_interface *xch);
+
+/* return array size for cpumap */
+int xc_get_cpumap_size(xc_interface *xch);
+
+/* allocate a cpumap */
+xc_cpumap_t xc_cpumap_alloc(xc_interface *xch);
+
+/* clear an CPU from the cpumap. */
+void xc_cpumap_clearcpu(int cpu, xc_cpumap_t map);
+
+/* set an CPU in the cpumap. */
+void xc_cpumap_setcpu(int cpu, xc_cpumap_t map);
+
+/* Test whether the CPU in cpumap is set. */
+int xc_cpumap_testcpu(int cpu, xc_cpumap_t map);
+
+/*
+ * NODEMAP handling
+ */
+typedef uint8_t *xc_nodemap_t;
+
+/* return maximum number of NUMA nodes the hypervisor supports */
+int xc_get_max_nodes(xc_interface *xch);
+
+/* return array size for nodemap */
+int xc_get_nodemap_size(xc_interface *xch);
+
+/* allocate a nodemap */
+xc_nodemap_t xc_nodemap_alloc(xc_interface *xch);
+
+/*
+ * DOMAIN DEBUGGING FUNCTIONS
+ */
+
+typedef struct xc_core_header {
+    unsigned int xch_magic;
+    unsigned int xch_nr_vcpus;
+    unsigned int xch_nr_pages;
+    unsigned int xch_ctxt_offset;
+    unsigned int xch_index_offset;
+    unsigned int xch_pages_offset;
+} xc_core_header_t;
+
+#define XC_CORE_MAGIC     0xF00FEBED
+#define XC_CORE_MAGIC_HVM 0xF00FEBEE
+
+/*
+ * DOMAIN MANAGEMENT FUNCTIONS
+ */
+
+typedef struct xc_dominfo {
+    uint32_t      domid;
+    uint32_t      ssidref;
+    unsigned int  dying:1, crashed:1, shutdown:1,
+                  paused:1, blocked:1, running:1,
+                  hvm:1, debugged:1, xenstore:1, hap:1;
+    unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
+    unsigned long nr_pages; /* current number, not maximum */
+    unsigned long nr_outstanding_pages;
+    unsigned long nr_shared_pages;
+    unsigned long nr_paged_pages;
+    unsigned long shared_info_frame;
+    uint64_t      cpu_time;
+    unsigned long max_memkb;
+    unsigned int  nr_online_vcpus;
+    unsigned int  max_vcpu_id;
+    xen_domain_handle_t handle;
+    unsigned int  cpupool;
+    struct xen_arch_domainconfig arch_config;
+} xc_dominfo_t;
+
+typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+
+typedef union 
+{
+#if defined(__i386__) || defined(__x86_64__)
+    vcpu_guest_context_x86_64_t x64;
+    vcpu_guest_context_x86_32_t x32;   
+#endif
+    vcpu_guest_context_t c;
+} vcpu_guest_context_any_t;
+
+typedef union
+{
+#if defined(__i386__) || defined(__x86_64__)
+    shared_info_x86_64_t x64;
+    shared_info_x86_32_t x32;
+#endif
+    shared_info_t s;
+} shared_info_any_t;
+
+#if defined(__i386__) || defined(__x86_64__)
+typedef union
+{
+    start_info_x86_64_t x64;
+    start_info_x86_32_t x32;
+    start_info_t s;
+} start_info_any_t;
+#endif
+
+typedef struct xc_vcpu_extstate {
+    uint64_t xfeature_mask;
+    uint64_t size;
+    void *buffer;
+} xc_vcpu_extstate_t;
+
+int xc_domain_create(xc_interface *xch, uint32_t *pdomid,
+                     struct xen_domctl_createdomain *config);
+
+
+/* Functions to produce a dump of a given domain
+ *  xc_domain_dumpcore - produces a dump to a specified file
+ *  xc_domain_dumpcore_via_callback - produces a dump, using a specified
+ *                                    callback function
+ */
+int xc_domain_dumpcore(xc_interface *xch,
+                       uint32_t domid,
+                       const char *corename);
+
+/* Define the callback function type for xc_domain_dumpcore_via_callback.
+ *
+ * This function is called by the coredump code for every "write",
+ * and passes an opaque object for the use of the function and
+ * created by the caller of xc_domain_dumpcore_via_callback.
+ */
+typedef int (dumpcore_rtn_t)(xc_interface *xch,
+                             void *arg, char *buffer, unsigned int length);
+
+int xc_domain_dumpcore_via_callback(xc_interface *xch,
+                                    uint32_t domid,
+                                    void *arg,
+                                    dumpcore_rtn_t dump_rtn);
+
+/*
+ * This function sets the maximum number of vcpus that a domain may create.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id in which vcpus are to be created.
+ * @parm max the maximum number of vcpus that the domain may create.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_max_vcpus(xc_interface *xch,
+                        uint32_t domid,
+                        unsigned int max);
+
+/**
+ * This function pauses a domain. A paused domain still exists in memory
+ * however it does not receive any timeslices from the hypervisor.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to pause
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_pause(xc_interface *xch,
+                    uint32_t domid);
+/**
+ * This function unpauses a domain.  The domain should have been previously
+ * paused.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to unpause
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_unpause(xc_interface *xch,
+                      uint32_t domid);
+
+/**
+ * This function will destroy a domain.  Destroying a domain removes the domain
+ * completely from memory.  This function should be called after sending the
+ * domain a SHUTDOWN control message to free up the domain resources.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to destroy
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_destroy(xc_interface *xch,
+                      uint32_t domid);
+
+
+/**
+ * This function resumes a suspended domain. The domain should have
+ * been previously suspended.
+ *
+ * Note that there are 'xc_domain_suspend' as suspending a domain
+ * is quite the endeavour.
+ *
+ * For the purpose of this explanation there are three guests:
+ * PV (using hypercalls for privilgied operations), HVM
+ * (fully hardware virtualized guests using emulated devices for everything),
+ * and PVHVM (PV aware with hardware virtualisation).
+ *
+ * HVM guest are the simplest - they suspend via S3 / S4 and resume from
+ * S3 / S4. Upon resume they have to re-negotiate with the emulated devices.
+ *
+ * PV and PVHVM communicate via hypercalls for suspend (and resume).
+ * For suspend the toolstack initiates the process by writing an value
+ * in XenBus "control/shutdown" with the string "suspend".
+ *
+ * The PV guest stashes anything it deems neccessary in 'struct
+ * start_info' in case of failure (PVHVM may ignore this) and calls
+ * the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall (for PV as
+ * argument it passes the MFN to 'struct start_info').
+ *
+ * And then the guest is suspended.
+ *
+ * The checkpointing or notifying a guest that the suspend failed or
+ * cancelled (in case of checkpoint) is by having the
+ * SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return a non-zero
+ * value.
+ *
+ * The PV and PVHVM resume path are similar. For PV it would be
+ * similar to bootup - figure out where the 'struct start_info' is (or
+ * if the suspend was cancelled aka checkpointed - reuse the saved
+ * values).
+ *
+ * From here on they differ depending whether the guest is PV or PVHVM
+ * in specifics but follow overall the same path:
+ *  - PV: Bringing up the vCPUS,
+ *  - PVHVM: Setup vector callback,
+ *  - Bring up vCPU runstates,
+ *  - Remap the grant tables if checkpointing or setup from scratch,
+ *
+ *
+ * If the resume was not checkpointing (or if suspend was succesful) we would
+ * setup the PV timers and the different PV events. Lastly the PV drivers
+ * re-negotiate with the backend.
+ *
+ * This function would return before the guest started resuming. That is
+ * the guest would be in non-running state and its vCPU context would be
+ * in the the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return path
+ * (for PV and PVHVM). For HVM it would be in would be in QEMU emulated
+ * BIOS handling S3 suspend.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to resume
+ * @parm fast use cooperative resume (guest must support this)
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_resume(xc_interface *xch,
+		     uint32_t domid,
+		     int fast);
+
+/**
+ * This function will shutdown a domain. This is intended for use in
+ * fully-virtualized domains where this operation is analogous to the
+ * sched_op operations in a paravirtualized domain. The caller is
+ * expected to give the reason for the shutdown.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to destroy
+ * @parm reason is the reason (SHUTDOWN_xxx) for the shutdown
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_shutdown(xc_interface *xch,
+                       uint32_t domid,
+                       int reason);
+
+int xc_watchdog(xc_interface *xch,
+		uint32_t id,
+		uint32_t timeout);
+
+/**
+ * This function explicitly sets the host NUMA nodes the domain will
+ * have affinity with.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id one wants to set the affinity of.
+ * @parm nodemap the map of the affine nodes.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_node_setaffinity(xc_interface *xch,
+                               uint32_t domind,
+                               xc_nodemap_t nodemap);
+
+/**
+ * This function retrieves the host NUMA nodes the domain has
+ * affinity with.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id one wants to get the node affinity of.
+ * @parm nodemap the map of the affine nodes.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_node_getaffinity(xc_interface *xch,
+                               uint32_t domind,
+                               xc_nodemap_t nodemap);
+
+/**
+ * This function specifies the CPU affinity for a vcpu.
+ *
+ * There are two kinds of affinity. Soft affinity is on what CPUs a vcpu
+ * prefers to run. Hard affinity is on what CPUs a vcpu is allowed to run.
+ * If flags contains XEN_VCPUAFFINITY_SOFT, the soft affinity it is set to
+ * what cpumap_soft_inout contains. If flags contains XEN_VCPUAFFINITY_HARD,
+ * the hard affinity is set to what cpumap_hard_inout contains. Both flags
+ * can be set at the same time, in which case both soft and hard affinity are
+ * set to what the respective parameter contains.
+ *
+ * The function also returns the effective hard or/and soft affinity, still
+ * via the cpumap_soft_inout and cpumap_hard_inout parameters. Effective
+ * affinity is, in case of soft affinity, the intersection of soft affinity,
+ * hard affinity and the cpupool's online CPUs for the domain, and is returned
+ * in cpumap_soft_inout, if XEN_VCPUAFFINITY_SOFT is set in flags. In case of
+ * hard affinity, it is the intersection between hard affinity and the
+ * cpupool's online CPUs, and is returned in cpumap_hard_inout, if
+ * XEN_VCPUAFFINITY_HARD is set in flags. If both flags are set, both soft
+ * and hard affinity are returned in the respective parameter.
+ *
+ * We do report it back as effective affinity is what the Xen scheduler will
+ * actually use, and we thus allow checking whether or not that matches with,
+ * or at least is good enough for, the caller's purposes.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the id of the domain to which the vcpu belongs
+ * @param vcpu the vcpu id wihin the domain
+ * @param cpumap_hard_inout specifies(/returns) the (effective) hard affinity
+ * @param cpumap_soft_inout specifies(/returns) the (effective) soft affinity
+ * @param flags what we want to set
+ */
+int xc_vcpu_setaffinity(xc_interface *xch,
+                        uint32_t domid,
+                        int vcpu,
+                        xc_cpumap_t cpumap_hard_inout,
+                        xc_cpumap_t cpumap_soft_inout,
+                        uint32_t flags);
+
+/**
+ * This function retrieves hard and soft CPU affinity of a vcpu,
+ * depending on what flags are set.
+ *
+ * Soft affinity is returned in cpumap_soft if XEN_VCPUAFFINITY_SOFT is set.
+ * Hard affinity is returned in cpumap_hard if XEN_VCPUAFFINITY_HARD is set.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the id of the domain to which the vcpu belongs
+ * @param vcpu the vcpu id wihin the domain
+ * @param cpumap_hard is where hard affinity is returned
+ * @param cpumap_soft is where soft affinity is returned
+ * @param flags what we want get
+ */
+int xc_vcpu_getaffinity(xc_interface *xch,
+                        uint32_t domid,
+                        int vcpu,
+                        xc_cpumap_t cpumap_hard,
+                        xc_cpumap_t cpumap_soft,
+                        uint32_t flags);
+
+
+/**
+ * This function will return the guest_width (in bytes) for the
+ * specified domain.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the domain id one wants the address size width of.
+ * @param addr_size the address size.
+ */
+int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid,
+                              unsigned int *guest_width);
+
+
+/**
+ * This function will return information about one or more domains. It is
+ * designed to iterate over the list of domains. If a single domain is
+ * requested, this function will return the next domain in the list - if
+ * one exists. It is, therefore, important in this case to make sure the
+ * domain requested was the one returned.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm first_domid the first domain to enumerate information from.  Domains
+ *                   are currently enumerate in order of creation.
+ * @parm max_doms the number of elements in info
+ * @parm info an array of max_doms size that will contain the information for
+ *            the enumerated domains.
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_domain_getinfo(xc_interface *xch,
+                      uint32_t first_domid,
+                      unsigned int max_doms,
+                      xc_dominfo_t *info);
+
+
+/**
+ * This function will set the execution context for the specified vcpu.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to set the vcpu context for
+ * @parm vcpu the vcpu number for the context
+ * @parm ctxt pointer to the the cpu context with the values to set
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_vcpu_setcontext(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_any_t *ctxt);
+/**
+ * This function will return information about one or more domains, using a
+ * single hypercall.  The domain information will be stored into the supplied
+ * array of xc_domaininfo_t structures.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm first_domain the first domain to enumerate information from.
+ *                    Domains are currently enumerate in order of creation.
+ * @parm max_domains the number of elements in info
+ * @parm info an array of max_doms size that will contain the information for
+ *            the enumerated domains.
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_domain_getinfolist(xc_interface *xch,
+                          uint32_t first_domain,
+                          unsigned int max_domains,
+                          xc_domaininfo_t *info);
+
+/**
+ * This function set p2m for broken page
+ * &parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id which broken page belong to
+ * @parm pfn the pfn number of the broken page
+ * @return 0 on success, -1 on failure
+ */
+int xc_set_broken_page_p2m(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned long pfn);
+
+/**
+ * This function returns information about the context of a hvm domain
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm ctxt_buf a pointer to a structure to store the execution context of
+ *            the hvm domain
+ * @parm size the size of ctxt_buf in bytes
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_getcontext(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t *ctxt_buf,
+                             uint32_t size);
+
+
+/**
+ * This function returns one element of the context of a hvm domain
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm typecode which type of elemnt required 
+ * @parm instance which instance of the type
+ * @parm ctxt_buf a pointer to a structure to store the execution context of
+ *            the hvm domain
+ * @parm size the size of ctxt_buf (must be >= HVM_SAVE_LENGTH(typecode))
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_getcontext_partial(xc_interface *xch,
+                                     uint32_t domid,
+                                     uint16_t typecode,
+                                     uint16_t instance,
+                                     void *ctxt_buf,
+                                     uint32_t size);
+
+/**
+ * This function will set the context for hvm domain
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to set the hvm domain context for
+ * @parm hvm_ctxt pointer to the the hvm context with the values to set
+ * @parm size the size of hvm_ctxt in bytes
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_setcontext(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t *hvm_ctxt,
+                             uint32_t size);
+
+/**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
+ * This function returns information about the execution context of a
+ * particular vcpu of a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm vcpu the vcpu number
+ * @parm ctxt a pointer to a structure to store the execution context of the
+ *            domain
+ * @return 0 on success, -1 on failure
+ */
+int xc_vcpu_getcontext(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_any_t *ctxt);
+
+/**
+ * This function initializes the vuart emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * #parm type type of vuart
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vuart_init(xc_interface *xch,
+                      uint32_t type,
+                      uint32_t domid,
+                      uint32_t console_domid,
+                      xen_pfn_t gfn,
+                      evtchn_port_t *evtchn);
+
+/**
+ * This function returns information about the XSAVE state of a particular
+ * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
+ * the call is considered a query to retrieve them and the buffer is not
+ * filled.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm vcpu the vcpu number
+ * @parm extstate a pointer to a structure to store the XSAVE state of the
+ *                domain
+ * @return 0 on success, negative error code on failure
+ */
+int xc_vcpu_get_extstate(xc_interface *xch,
+                         uint32_t domid,
+                         uint32_t vcpu,
+                         xc_vcpu_extstate_t *extstate);
+
+typedef struct xen_domctl_getvcpuinfo xc_vcpuinfo_t;
+int xc_vcpu_getinfo(xc_interface *xch,
+                    uint32_t domid,
+                    uint32_t vcpu,
+                    xc_vcpuinfo_t *info);
+
+long long xc_domain_get_cpu_usage(xc_interface *xch,
+                                  uint32_t domid,
+                                  int vcpu);
+
+int xc_domain_sethandle(xc_interface *xch, uint32_t domid,
+                        xen_domain_handle_t handle);
+
+typedef struct xen_domctl_shadow_op_stats xc_shadow_op_stats_t;
+int xc_shadow_control(xc_interface *xch,
+                      uint32_t domid,
+                      unsigned int sop,
+                      xc_hypercall_buffer_t *dirty_bitmap,
+                      unsigned long pages,
+                      unsigned long *mb,
+                      uint32_t mode,
+                      xc_shadow_op_stats_t *stats);
+
+int xc_sched_credit_domain_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit *sdom);
+
+int xc_sched_credit_domain_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit *sdom);
+int xc_sched_credit_params_set(xc_interface *xch,
+                               uint32_t cpupool_id,
+                               struct xen_sysctl_credit_schedule *schedule);
+int xc_sched_credit_params_get(xc_interface *xch,
+                               uint32_t cpupool_id,
+                               struct xen_sysctl_credit_schedule *schedule);
+
+int xc_sched_credit2_params_set(xc_interface *xch,
+                                uint32_t cpupool_id,
+                                struct xen_sysctl_credit2_schedule *schedule);
+int xc_sched_credit2_params_get(xc_interface *xch,
+                                uint32_t cpupool_id,
+                                struct xen_sysctl_credit2_schedule *schedule);
+int xc_sched_credit2_domain_set(xc_interface *xch,
+                                uint32_t domid,
+                                struct xen_domctl_sched_credit2 *sdom);
+int xc_sched_credit2_domain_get(xc_interface *xch,
+                                uint32_t domid,
+                                struct xen_domctl_sched_credit2 *sdom);
+
+int xc_sched_rtds_domain_set(xc_interface *xch,
+                             uint32_t domid,
+                             struct xen_domctl_sched_rtds *sdom);
+int xc_sched_rtds_domain_get(xc_interface *xch,
+                             uint32_t domid,
+                             struct xen_domctl_sched_rtds *sdom);
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_schedparam_vcpu *vcpus,
+                           uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_schedparam_vcpu *vcpus,
+                           uint32_t num_vcpus);
+
+int
+xc_sched_arinc653_schedule_set(
+    xc_interface *xch,
+    uint32_t cpupool_id,
+    struct xen_sysctl_arinc653_schedule *schedule);
+
+int
+xc_sched_arinc653_schedule_get(
+    xc_interface *xch,
+    uint32_t cpupool_id,
+    struct xen_sysctl_arinc653_schedule *schedule);
+
+/**
+ * This function sends a trigger to a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm trigger the trigger type
+ * @parm vcpu the vcpu number to send trigger 
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_send_trigger(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t trigger,
+                           uint32_t vcpu);
+
+/**
+ * This function enables or disable debugging of a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm enable true to enable debugging
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_setdebugging(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned int enable);
+
+/**
+ * This function audits the (top level) p2m of a domain 
+ * and returns the different error counts, if any.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id whose top level p2m we 
+ *       want to audit
+ * @parm orphans count of m2p entries for valid
+ *       domain pages containing an invalid value
+ * @parm m2p_bad count of m2p entries mismatching the
+ *       associated p2m entry for this domain
+ * @parm p2m_bad count of p2m entries for this domain
+ *       mismatching the associated m2p entry
+ * return 0 on success, -1 on failure
+ * errno values on failure include: 
+ *          -ENOSYS: not implemented
+ *          -EFAULT: could not copy results back to guest
+ */
+int xc_domain_p2m_audit(xc_interface *xch,
+                        uint32_t domid,
+                        uint64_t *orphans,
+                        uint64_t *m2p_bad,   
+                        uint64_t *p2m_bad);
+
+/**
+ * This function sets or clears the requirement that an access memory
+ * event listener is required on the domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm enable true to require a listener
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_set_access_required(xc_interface *xch,
+				  uint32_t domid,
+				  unsigned int required);
+/**
+ * This function sets the handler of global VIRQs sent by the hypervisor
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id which will handle the VIRQ
+ * @parm virq the virq number (VIRQ_*)
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
+
+/*
+ * CPUPOOL MANAGEMENT FUNCTIONS
+ */
+
+typedef struct xc_cpupoolinfo {
+    uint32_t cpupool_id;
+    uint32_t sched_id;
+    uint32_t n_dom;
+    xc_cpumap_t cpumap;
+} xc_cpupoolinfo_t;
+
+#define XC_CPUPOOL_POOLID_ANY 0xFFFFFFFF
+
+/**
+ * Create a new cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm ppoolid pointer to the new cpupool id (in/out)
+ * @parm sched_id id of scheduler to use for pool
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_create(xc_interface *xch,
+                      uint32_t *ppoolid,
+                      uint32_t sched_id);
+
+/**
+ * Destroy a cpupool. Pool must be unused and have no cpu assigned.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool to destroy
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_destroy(xc_interface *xch,
+                       uint32_t poolid);
+
+/**
+ * Get cpupool info. Returns info for up to the specified number of cpupools
+ * starting at the given id.
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid lowest id for which info is returned
+ * return cpupool info ptr (to be freed via xc_cpupool_infofree)
+ */
+xc_cpupoolinfo_t *xc_cpupool_getinfo(xc_interface *xch,
+                       uint32_t poolid);
+
+/**
+ * Free cpupool info. Used to free info obtained via xc_cpupool_getinfo.
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm info area to free
+ */
+void xc_cpupool_infofree(xc_interface *xch,
+                         xc_cpupoolinfo_t *info);
+
+/**
+ * Add cpu to a cpupool. cpu may be -1 indicating the first unassigned.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool
+ * @parm cpu cpu number to add
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_addcpu(xc_interface *xch,
+                      uint32_t poolid,
+                      int cpu);
+
+/**
+ * Remove cpu from cpupool. cpu may be -1 indicating the last cpu of the pool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool
+ * @parm cpu cpu number to remove
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_removecpu(xc_interface *xch,
+                         uint32_t poolid,
+                         int cpu);
+
+/**
+ * Move domain to another cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the destination cpupool
+ * @parm domid id of the domain to move
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_movedomain(xc_interface *xch,
+                          uint32_t poolid,
+                          uint32_t domid);
+
+/**
+ * Return map of cpus not in any cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * return cpumap array on success, NULL else
+ */
+xc_cpumap_t xc_cpupool_freeinfo(xc_interface *xch);
+
+/*
+ * EVENT CHANNEL FUNCTIONS
+ *
+ * None of these do any logging.
+ */
+
+/* A port identifier is guaranteed to fit in 31 bits. */
+typedef int xc_evtchn_port_or_error_t;
+
+/**
+ * This function allocates an unbound port.  Ports are named endpoints used for
+ * interdomain communication.  This function is most useful in opening a
+ * well-known port within a domain to receive events on.
+ * 
+ * NOTE: If you are allocating a *local* unbound port, you probably want to
+ * use xc_evtchn_bind_unbound_port(). This function is intended for allocating
+ * ports *only* during domain creation.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm dom the ID of the local domain (the 'allocatee')
+ * @parm remote_dom the ID of the domain who will later bind
+ * @return allocated port (in @dom) on success, -1 on failure
+ */
+xc_evtchn_port_or_error_t
+xc_evtchn_alloc_unbound(xc_interface *xch,
+                        uint32_t dom,
+                        uint32_t remote_dom);
+
+int xc_evtchn_reset(xc_interface *xch,
+                    uint32_t dom);
+
+typedef struct evtchn_status xc_evtchn_status_t;
+int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status);
+
+
+
+int xc_physdev_pci_access_modify(xc_interface *xch,
+                                 uint32_t domid,
+                                 int bus,
+                                 int dev,
+                                 int func,
+                                 int enable);
+
+int xc_readconsolering(xc_interface *xch,
+                       char *buffer,
+                       unsigned int *pnr_chars,
+                       int clear, int incremental, uint32_t *pindex);
+
+int xc_send_debug_keys(xc_interface *xch, const char *keys);
+
+typedef struct xen_sysctl_physinfo xc_physinfo_t;
+typedef struct xen_sysctl_cputopo xc_cputopo_t;
+typedef struct xen_sysctl_numainfo xc_numainfo_t;
+typedef struct xen_sysctl_meminfo xc_meminfo_t;
+typedef struct xen_sysctl_pcitopoinfo xc_pcitopoinfo_t;
+
+typedef uint32_t xc_cpu_to_node_t;
+typedef uint32_t xc_cpu_to_socket_t;
+typedef uint32_t xc_cpu_to_core_t;
+typedef uint64_t xc_node_to_memsize_t;
+typedef uint64_t xc_node_to_memfree_t;
+typedef uint32_t xc_node_to_node_dist_t;
+
+int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus,
+                   xc_cputopo_t *cputopo);
+int xc_microcode_update(xc_interface *xch, const void *buf, size_t len);
+int xc_numainfo(xc_interface *xch, unsigned *max_nodes,
+                xc_meminfo_t *meminfo, uint32_t *distance);
+int xc_pcitopoinfo(xc_interface *xch, unsigned num_devs,
+                   physdev_pci_device_t *devs, uint32_t *nodes);
+
+int xc_sched_id(xc_interface *xch,
+                int *sched_id);
+
+int xc_machphys_mfn_list(xc_interface *xch,
+                         unsigned long max_extents,
+                         xen_pfn_t *extent_start);
+
+typedef struct xen_sysctl_cpuinfo xc_cpuinfo_t;
+int xc_getcpuinfo(xc_interface *xch, int max_cpus,
+                  xc_cpuinfo_t *info, int *nr_cpus); 
+
+int xc_domain_setmaxmem(xc_interface *xch,
+                        uint32_t domid,
+                        uint64_t max_memkb);
+
+int xc_domain_set_memmap_limit(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long map_limitkb);
+
+int xc_domain_setvnuma(xc_interface *xch,
+                        uint32_t domid,
+                        uint32_t nr_vnodes,
+                        uint32_t nr_regions,
+                        uint32_t nr_vcpus,
+                        xen_vmemrange_t *vmemrange,
+                        unsigned int *vdistance,
+                        unsigned int *vcpu_to_vnode,
+                        unsigned int *vnode_to_pnode);
+/*
+ * Retrieve vnuma configuration
+ * domid: IN, target domid
+ * nr_vnodes: IN/OUT, number of vnodes, not NULL
+ * nr_vmemranges: IN/OUT, number of vmemranges, not NULL
+ * nr_vcpus: IN/OUT, number of vcpus, not NULL
+ * vmemranges: OUT, an array which has length of nr_vmemranges
+ * vdistance: OUT, an array which has length of nr_vnodes * nr_vnodes
+ * vcpu_to_vnode: OUT, an array which has length of nr_vcpus
+ */
+int xc_domain_getvnuma(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t *nr_vnodes,
+                       uint32_t *nr_vmemranges,
+                       uint32_t *nr_vcpus,
+                       xen_vmemrange_t *vmemrange,
+                       unsigned int *vdistance,
+                       unsigned int *vcpu_to_vnode);
+
+int xc_domain_soft_reset(xc_interface *xch,
+                         uint32_t domid);
+
+#if defined(__i386__) || defined(__x86_64__)
+/*
+ * PC BIOS standard E820 types and structure.
+ */
+#define E820_RAM          1
+#define E820_RESERVED     2
+#define E820_ACPI         3
+#define E820_NVS          4
+#define E820_UNUSABLE     5
+
+#define E820MAX           (128)
+
+struct e820entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+} __attribute__((packed));
+int xc_domain_set_memory_map(xc_interface *xch,
+                               uint32_t domid,
+                               struct e820entry entries[],
+                               uint32_t nr_entries);
+
+int xc_get_machine_memory_map(xc_interface *xch,
+                              struct e820entry entries[],
+                              uint32_t max_entries);
+#endif
+
+int xc_reserved_device_memory_map(xc_interface *xch,
+                                  uint32_t flags,
+                                  uint16_t seg,
+                                  uint8_t bus,
+                                  uint8_t devfn,
+                                  struct xen_reserved_device_memory entries[],
+                                  uint32_t *max_entries);
+int xc_domain_set_time_offset(xc_interface *xch,
+                              uint32_t domid,
+                              int32_t time_offset_seconds);
+
+int xc_domain_set_tsc_info(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t tsc_mode,
+                           uint64_t elapsed_nsec,
+                           uint32_t gtsc_khz,
+                           uint32_t incarnation);
+
+int xc_domain_get_tsc_info(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t *tsc_mode,
+                           uint64_t *elapsed_nsec,
+                           uint32_t *gtsc_khz,
+                           uint32_t *incarnation);
+
+int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid);
+
+int xc_domain_maximum_gpfn(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
+
+int xc_domain_nr_gpfns(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
+
+int xc_domain_increase_reservation(xc_interface *xch,
+                                   uint32_t domid,
+                                   unsigned long nr_extents,
+                                   unsigned int extent_order,
+                                   unsigned int mem_flags,
+                                   xen_pfn_t *extent_start);
+
+int xc_domain_increase_reservation_exact(xc_interface *xch,
+                                         uint32_t domid,
+                                         unsigned long nr_extents,
+                                         unsigned int extent_order,
+                                         unsigned int mem_flags,
+                                         xen_pfn_t *extent_start);
+
+int xc_domain_decrease_reservation(xc_interface *xch,
+                                   uint32_t domid,
+                                   unsigned long nr_extents,
+                                   unsigned int extent_order,
+                                   xen_pfn_t *extent_start);
+
+int xc_domain_decrease_reservation_exact(xc_interface *xch,
+                                         uint32_t domid,
+                                         unsigned long nr_extents,
+                                         unsigned int extent_order,
+                                         xen_pfn_t *extent_start);
+
+int xc_domain_add_to_physmap(xc_interface *xch,
+                             uint32_t domid,
+                             unsigned int space,
+                             unsigned long idx,
+                             xen_pfn_t gpfn);
+
+int xc_domain_add_to_physmap_batch(xc_interface *xch,
+                                   uint32_t domid,
+                                   uint32_t foreign_domid,
+                                   unsigned int space,
+                                   unsigned int size,
+                                   xen_ulong_t *idxs,
+                                   xen_pfn_t *gfpns,
+                                   int *errs);
+
+int xc_domain_remove_from_physmap(xc_interface *xch,
+                                  uint32_t domid,
+                                  xen_pfn_t gpfn);
+
+int xc_domain_populate_physmap(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_extents,
+                               unsigned int extent_order,
+                               unsigned int mem_flags,
+                               xen_pfn_t *extent_start);
+
+int xc_domain_populate_physmap_exact(xc_interface *xch,
+                                     uint32_t domid,
+                                     unsigned long nr_extents,
+                                     unsigned int extent_order,
+                                     unsigned int mem_flags,
+                                     xen_pfn_t *extent_start);
+
+int xc_domain_claim_pages(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_pages);
+
+int xc_domain_memory_exchange_pages(xc_interface *xch,
+                                    uint32_t domid,
+                                    unsigned long nr_in_extents,
+                                    unsigned int in_order,
+                                    xen_pfn_t *in_extents,
+                                    unsigned long nr_out_extents,
+                                    unsigned int out_order,
+                                    xen_pfn_t *out_extents);
+
+int xc_domain_set_pod_target(xc_interface *xch,
+                             uint32_t domid,
+                             uint64_t target_pages,
+                             uint64_t *tot_pages,
+                             uint64_t *pod_cache_pages,
+                             uint64_t *pod_entries);
+
+int xc_domain_get_pod_target(xc_interface *xch,
+                             uint32_t domid,
+                             uint64_t *tot_pages,
+                             uint64_t *pod_cache_pages,
+                             uint64_t *pod_entries);
+
+int xc_domain_ioport_permission(xc_interface *xch,
+                                uint32_t domid,
+                                uint32_t first_port,
+                                uint32_t nr_ports,
+                                uint32_t allow_access);
+
+int xc_domain_irq_permission(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t pirq,
+                             uint8_t allow_access);
+
+int xc_domain_iomem_permission(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long first_mfn,
+                               unsigned long nr_mfns,
+                               uint8_t allow_access);
+
+unsigned long xc_make_page_below_4G(xc_interface *xch, uint32_t domid,
+                                    unsigned long mfn);
+
+typedef xen_sysctl_perfc_desc_t xc_perfc_desc_t;
+typedef xen_sysctl_perfc_val_t xc_perfc_val_t;
+int xc_perfc_reset(xc_interface *xch);
+int xc_perfc_query_number(xc_interface *xch,
+                          int *nbr_desc,
+                          int *nbr_val);
+int xc_perfc_query(xc_interface *xch,
+                   xc_hypercall_buffer_t *desc,
+                   xc_hypercall_buffer_t *val);
+
+typedef xen_sysctl_lockprof_data_t xc_lockprof_data_t;
+int xc_lockprof_reset(xc_interface *xch);
+int xc_lockprof_query_number(xc_interface *xch,
+                             uint32_t *n_elems);
+int xc_lockprof_query(xc_interface *xch,
+                      uint32_t *n_elems,
+                      uint64_t *time,
+                      xc_hypercall_buffer_t *data);
+
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
+/**
+ * Avoid using this function, as it does not work for all cases (such
+ * as 4M superpages, or guests using PSE36). Only used for debugging.
+ *
+ * Translates a virtual address in the context of a given domain and
+ * vcpu returning the GFN containing the address (that is, an MFN for 
+ * PV guests, a PFN for HVM guests).  Returns 0 for failure.
+ *
+ * @parm xch a handle on an open hypervisor interface
+ * @parm dom the domain to perform the translation in
+ * @parm vcpu the vcpu to perform the translation on
+ * @parm virt the virtual address to translate
+ */
+unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
+                                           int vcpu, unsigned long long virt);
+
+
+int xc_copy_to_domain_page(xc_interface *xch, uint32_t domid,
+                           unsigned long dst_pfn, const char *src_page);
+
+int xc_clear_domain_pages(xc_interface *xch, uint32_t domid,
+                          unsigned long dst_pfn, int num);
+
+static inline int xc_clear_domain_page(xc_interface *xch, uint32_t domid,
+                                       unsigned long dst_pfn)
+{
+    return xc_clear_domain_pages(xch, domid, dst_pfn, 1);
+}
+
+int xc_mmuext_op(xc_interface *xch, struct mmuext_op *op, unsigned int nr_ops,
+                 uint32_t dom);
+
+/* System wide memory properties */
+int xc_maximum_ram_page(xc_interface *xch, unsigned long *max_mfn);
+
+/* Get current total pages allocated to a domain. */
+long xc_get_tot_pages(xc_interface *xch, uint32_t domid);
+
+/**
+ * This function retrieves the the number of bytes available
+ * in the heap in a specific range of address-widths and nodes.
+ * 
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to query
+ * @parm min_width the smallest address width to query (0 if don't care)
+ * @parm max_width the largest address width to query (0 if don't care)
+ * @parm node the node to query (-1 for all)
+ * @parm *bytes caller variable to put total bytes counted
+ * @return 0 on success, <0 on failure.
+ */
+int xc_availheap(xc_interface *xch, int min_width, int max_width, int node,
+                 uint64_t *bytes);
+
+/*
+ * Trace Buffer Operations
+ */
+
+/**
+ * xc_tbuf_enable - enable tracing buffers
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm cnt size of tracing buffers to create (in pages)
+ * @parm mfn location to store mfn of the trace buffers to
+ * @parm size location to store the size (in bytes) of a trace buffer to
+ *
+ * Gets the machine address of the trace pointer area and the size of the
+ * per CPU buffers.
+ */
+int xc_tbuf_enable(xc_interface *xch, unsigned long pages,
+                   unsigned long *mfn, unsigned long *size);
+
+/*
+ * Disable tracing buffers.
+ */
+int xc_tbuf_disable(xc_interface *xch);
+
+/**
+ * This function sets the size of the trace buffers. Setting the size
+ * is currently a one-shot operation that may be performed either at boot
+ * time or via this interface, not both. The buffer size must be set before
+ * enabling tracing.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm size the size in pages per cpu for the trace buffers
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_set_size(xc_interface *xch, unsigned long size);
+
+/**
+ * This function retrieves the current size of the trace buffers.
+ * Note that the size returned is in terms of bytes, not pages.
+
+ * @parm xch a handle to an open hypervisor interface
+ * @parm size will contain the size in bytes for the trace buffers
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_get_size(xc_interface *xch, unsigned long *size);
+
+int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpumap_t mask);
+
+int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);
+
+int xc_domctl(xc_interface *xch, struct xen_domctl *domctl);
+int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl);
+
+int xc_version(xc_interface *xch, int cmd, void *arg);
+
+int xc_flask_op(xc_interface *xch, xen_flask_op_t *op);
+
+/*
+ * Subscribe to domain suspend via evtchn.
+ * Returns -1 on failure, in which case errno will be set appropriately.
+ * Just calls XEN_DOMCTL_subscribe - see the caveats for that domctl
+ * (in its doc comment in domctl.h).
+ */
+int xc_domain_subscribe_for_suspend(
+    xc_interface *xch, uint32_t domid, evtchn_port_t port);
+
+/**************************
+ * GRANT TABLE OPERATIONS *
+ **************************/
+
+/*
+ * These functions sometimes log messages as above, but not always.
+ */
+
+
+int xc_gnttab_op(xc_interface *xch, int cmd,
+                 void * op, int op_size, int count);
+/* Logs iff hypercall bounce fails, otherwise doesn't. */
+
+int xc_gnttab_query_size(xc_interface *xch, struct gnttab_query_size *query);
+int xc_gnttab_get_version(xc_interface *xch, uint32_t domid); /* Never logs */
+grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, uint32_t domid, int *gnt_num);
+grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, uint32_t domid, int *gnt_num);
+/* Sometimes these don't set errno [fixme], and sometimes they don't log. */
+
+int xc_physdev_map_pirq(xc_interface *xch,
+                        uint32_t domid,
+                        int index,
+                        int *pirq);
+
+int xc_physdev_map_pirq_msi(xc_interface *xch,
+                            uint32_t domid,
+                            int index,
+                            int *pirq,
+                            int devfn,
+                            int bus,
+                            int entry_nr,
+                            uint64_t table_base);
+
+int xc_physdev_unmap_pirq(xc_interface *xch,
+                          uint32_t domid,
+                          int pirq);
+
+/*
+ *  LOGGING AND ERROR REPORTING
+ */
+
+
+#define XC_MAX_ERROR_MSG_LEN 1024
+typedef struct xc_error {
+  enum xc_error_code code;
+  char message[XC_MAX_ERROR_MSG_LEN];
+} xc_error;
+
+
+/*
+ * Convert an error code or level into a text description.  Return values
+ * are pointers to fixed strings and do not need to be freed.
+ * Do not fail, but return pointers to generic strings if fed bogus input.
+ */
+const char *xc_error_code_to_desc(int code);
+
+/*
+ * Convert an errno value to a text description.
+ */
+const char *xc_strerror(xc_interface *xch, int errcode);
+
+
+/*
+ * Return a pointer to the last error with level XC_REPORT_ERROR. This
+ * pointer and the data pointed to are only valid until the next call
+ * to libxc in the same thread.
+ */
+const xc_error *xc_get_last_error(xc_interface *handle);
+
+/*
+ * Clear the last error
+ */
+void xc_clear_last_error(xc_interface *xch);
+
+int xc_hvm_param_set(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t value);
+int xc_hvm_param_get(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t *value);
+
+/* Deprecated: use xc_hvm_param_set/get() instead. */
+int xc_set_hvm_param(xc_interface *handle, uint32_t dom, int param, unsigned long value);
+int xc_get_hvm_param(xc_interface *handle, uint32_t dom, int param, unsigned long *value);
+
+/* HVM guest pass-through */
+int xc_assign_device(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf,
+                     uint32_t flag);
+
+int xc_get_device_group(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf,
+                     uint32_t max_sdevs,
+                     uint32_t *num_sdevs,
+                     uint32_t *sdev_array);
+
+int xc_test_assign_device(xc_interface *xch,
+                          uint32_t domid,
+                          uint32_t machine_sbdf);
+
+int xc_deassign_device(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf);
+
+int xc_assign_dt_device(xc_interface *xch,
+                        uint32_t domid,
+                        char *path);
+int xc_test_assign_dt_device(xc_interface *xch,
+                             uint32_t domid,
+                             char *path);
+int xc_deassign_dt_device(xc_interface *xch,
+                          uint32_t domid,
+                          char *path);
+
+int xc_domain_memory_mapping(xc_interface *xch,
+                             uint32_t domid,
+                             unsigned long first_gfn,
+                             unsigned long first_mfn,
+                             unsigned long nr_mfns,
+                             uint32_t add_mapping);
+
+int xc_domain_ioport_mapping(xc_interface *xch,
+                             uint32_t domid,
+                             uint32_t first_gport,
+                             uint32_t first_mport,
+                             uint32_t nr_ports,
+                             uint32_t add_mapping);
+
+int xc_domain_update_msi_irq(
+    xc_interface *xch,
+    uint32_t domid,
+    uint32_t gvec,
+    uint32_t pirq,
+    uint32_t gflags,
+    uint64_t gtable);
+
+int xc_domain_unbind_msi_irq(xc_interface *xch,
+                             uint32_t domid,
+                             uint32_t gvec,
+                             uint32_t pirq,
+                             uint32_t gflags);
+
+int xc_domain_bind_pt_irq(xc_interface *xch,
+                          uint32_t domid,
+                          uint8_t machine_irq,
+                          uint8_t irq_type,
+                          uint8_t bus,
+                          uint8_t device,
+                          uint8_t intx,
+                          uint8_t isa_irq);
+
+int xc_domain_unbind_pt_irq(xc_interface *xch,
+                          uint32_t domid,
+                          uint8_t machine_irq,
+                          uint8_t irq_type,
+                          uint8_t bus,
+                          uint8_t device,
+                          uint8_t intx,
+                          uint8_t isa_irq);
+
+int xc_domain_bind_pt_pci_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint8_t machine_irq,
+                              uint8_t bus,
+                              uint8_t device,
+                              uint8_t intx);
+
+int xc_domain_bind_pt_isa_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint8_t machine_irq);
+
+int xc_domain_bind_pt_spi_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint16_t vspi,
+                              uint16_t spi);
+
+int xc_domain_unbind_pt_spi_irq(xc_interface *xch,
+                                uint32_t domid,
+                                uint16_t vspi,
+                                uint16_t spi);
+
+/* Set the target domain */
+int xc_domain_set_target(xc_interface *xch,
+                         uint32_t domid,
+                         uint32_t target);
+
+/* Control the domain for debug */
+int xc_domain_debug_control(xc_interface *xch,
+                            uint32_t domid,
+                            uint32_t sop,
+                            uint32_t vcpu);
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/*
+ * CPUID policy data, expressed in the legacy XEND format.
+ *
+ * Policy is an array of strings, 32 chars long:
+ *   policy[0] = eax
+ *   policy[1] = ebx
+ *   policy[2] = ecx
+ *   policy[3] = edx
+ *
+ * The format of the string is the following:
+ *   '1' -> force to 1
+ *   '0' -> force to 0
+ *   'x' -> we don't care (use default)
+ *   'k' -> pass through host value
+ *   's' -> legacy alias for 'k'
+ */
+struct xc_xend_cpuid {
+    union {
+        struct {
+            uint32_t leaf, subleaf;
+        };
+        uint32_t input[2];
+    };
+    char *policy[4];
+};
+
+/*
+ * Make adjustments to the CPUID settings for a domain.
+ *
+ * This path is used in two cases.  First, for fresh boots of the domain, and
+ * secondly for migrate-in/restore of pre-4.14 guests (where CPUID data was
+ * missing from the stream).  The @restore parameter distinguishes these
+ * cases, and the generated policy must be compatible with a 4.13.
+ *
+ * Either pass a full new @featureset (and @nr_features), or adjust individual
+ * features (@pae).
+ *
+ * Then (optionally) apply legacy XEND overrides (@xend) to the result.
+ */
+int xc_cpuid_apply_policy(xc_interface *xch,
+                          uint32_t domid, bool restore,
+                          const uint32_t *featureset,
+                          unsigned int nr_features, bool pae,
+                          const struct xc_xend_cpuid *xend);
+int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
+int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
+                        xc_cpumap_t cpumap, unsigned int nr_cpus);
+#endif
+
+struct xc_px_val {
+    uint64_t freq;        /* Px core frequency */
+    uint64_t residency;   /* Px residency time */
+    uint64_t count;       /* Px transition count */
+};
+
+struct xc_px_stat {
+    uint8_t total;        /* total Px states */
+    uint8_t usable;       /* usable Px states */
+    uint8_t last;         /* last Px state */
+    uint8_t cur;          /* current Px state */
+    uint64_t *trans_pt;   /* Px transition table */
+    struct xc_px_val *pt;
+};
+
+int xc_pm_get_max_px(xc_interface *xch, int cpuid, int *max_px);
+int xc_pm_get_pxstat(xc_interface *xch, int cpuid, struct xc_px_stat *pxpt);
+int xc_pm_reset_pxstat(xc_interface *xch, int cpuid);
+
+struct xc_cx_stat {
+    uint32_t nr;           /* entry nr in triggers[]/residencies[], incl C0 */
+    uint32_t last;         /* last Cx state */
+    uint64_t idle_time;    /* idle time from boot */
+    uint64_t *triggers;    /* Cx trigger counts */
+    uint64_t *residencies; /* Cx residencies */
+    uint32_t nr_pc;        /* entry nr in pc[] */
+    uint32_t nr_cc;        /* entry nr in cc[] */
+    uint64_t *pc;          /* 1-biased indexing (i.e. excl C0) */
+    uint64_t *cc;          /* 1-biased indexing (i.e. excl C0) */
+};
+typedef struct xc_cx_stat xc_cx_stat_t;
+
+int xc_pm_get_max_cx(xc_interface *xch, int cpuid, int *max_cx);
+int xc_pm_get_cxstat(xc_interface *xch, int cpuid, struct xc_cx_stat *cxpt);
+int xc_pm_reset_cxstat(xc_interface *xch, int cpuid);
+
+int xc_cpu_online(xc_interface *xch, int cpu);
+int xc_cpu_offline(xc_interface *xch, int cpu);
+int xc_smt_enable(xc_interface *xch);
+int xc_smt_disable(xc_interface *xch);
+
+/* 
+ * cpufreq para name of this structure named 
+ * same as sysfs file name of native linux
+ */
+typedef struct xen_userspace xc_userspace_t;
+typedef struct xen_ondemand xc_ondemand_t;
+
+struct xc_get_cpufreq_para {
+    /* IN/OUT variable */
+    uint32_t cpu_num;
+    uint32_t freq_num;
+    uint32_t gov_num;
+
+    /* for all governors */
+    /* OUT variable */
+    uint32_t *affected_cpus;
+    uint32_t *scaling_available_frequencies;
+    char     *scaling_available_governors;
+    char scaling_driver[CPUFREQ_NAME_LEN];
+
+    uint32_t cpuinfo_cur_freq;
+    uint32_t cpuinfo_max_freq;
+    uint32_t cpuinfo_min_freq;
+    uint32_t scaling_cur_freq;
+
+    char scaling_governor[CPUFREQ_NAME_LEN];
+    uint32_t scaling_max_freq;
+    uint32_t scaling_min_freq;
+
+    /* for specific governor */
+    union {
+        xc_userspace_t userspace;
+        xc_ondemand_t ondemand;
+    } u;
+
+    int32_t turbo_enabled;
+};
+
+int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
+                        struct xc_get_cpufreq_para *user_para);
+int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname);
+int xc_set_cpufreq_para(xc_interface *xch, int cpuid,
+                        int ctrl_type, int ctrl_value);
+int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq);
+
+int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value);
+
+int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value);
+int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value);
+
+int xc_get_cpuidle_max_csubstate(xc_interface *xch, uint32_t *value);
+int xc_set_cpuidle_max_csubstate(xc_interface *xch, uint32_t value);
+
+int xc_enable_turbo(xc_interface *xch, int cpuid);
+int xc_disable_turbo(xc_interface *xch, int cpuid);
+
+/**
+ * altp2m operations
+ */
+
+int xc_altp2m_get_domain_state(xc_interface *handle, uint32_t dom, bool *state);
+int xc_altp2m_set_domain_state(xc_interface *handle, uint32_t dom, bool state);
+int xc_altp2m_set_vcpu_enable_notify(xc_interface *handle, uint32_t domid,
+                                     uint32_t vcpuid, xen_pfn_t gfn);
+int xc_altp2m_set_vcpu_disable_notify(xc_interface *handle, uint32_t domid,
+                                      uint32_t vcpuid);
+int xc_altp2m_create_view(xc_interface *handle, uint32_t domid,
+                          xenmem_access_t default_access, uint16_t *view_id);
+int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,
+                           uint16_t view_id);
+/* Switch all vCPUs of the domain to the specified altp2m view */
+int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id);
+int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,
+                              uint16_t view_id, xen_pfn_t gfn, bool sve);
+int xc_altp2m_set_supress_ve_multi(xc_interface *handle, uint32_t domid,
+                                   uint16_t view_id, xen_pfn_t first_gfn,
+                                   xen_pfn_t last_gfn, bool sve,
+                                   xen_pfn_t *error_gfn, int32_t *error_code);
+int xc_altp2m_get_suppress_ve(xc_interface *handle, uint32_t domid,
+                              uint16_t view_id, xen_pfn_t gfn, bool *sve);
+int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, xen_pfn_t gfn,
+                             xenmem_access_t access);
+int xc_altp2m_set_mem_access_multi(xc_interface *handle, uint32_t domid,
+                                   uint16_t view_id, uint8_t *access,
+                                   uint64_t *gfns, uint32_t nr);
+int xc_altp2m_get_mem_access(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, xen_pfn_t gfn,
+                             xenmem_access_t *access);
+int xc_altp2m_change_gfn(xc_interface *handle, uint32_t domid,
+                         uint16_t view_id, xen_pfn_t old_gfn,
+                         xen_pfn_t new_gfn);
+int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid,
+                               uint32_t vcpuid, uint16_t *p2midx);
+/*
+ * Set view visibility for xc_altp2m_switch_to_view and vmfunc.
+ * Note: If altp2m mode is set to mixed the guest is able to change the view
+ * visibility and then call vmfunc.
+ */
+int xc_altp2m_set_visibility(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, bool visible);
+
+/** 
+ * Mem paging operations.
+ * Paging is supported only on the x86 architecture in 64 bit mode, with
+ * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
+ * support is considered experimental.
+ */
+int xc_mem_paging_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port);
+int xc_mem_paging_disable(xc_interface *xch, uint32_t domain_id);
+int xc_mem_paging_resume(xc_interface *xch, uint32_t domain_id);
+int xc_mem_paging_nominate(xc_interface *xch, uint32_t domain_id,
+                           uint64_t gfn);
+int xc_mem_paging_evict(xc_interface *xch, uint32_t domain_id, uint64_t gfn);
+int xc_mem_paging_prep(xc_interface *xch, uint32_t domain_id, uint64_t gfn);
+int xc_mem_paging_load(xc_interface *xch, uint32_t domain_id,
+                       uint64_t gfn, void *buffer);
+
+/** 
+ * Access tracking operations.
+ * Supported only on Intel EPT 64 bit processors.
+ */
+
+/*
+ * Set a range of memory to a specific access.
+ * 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, uint32_t domain_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.
+ * The nr parameter specifies the size of the pages and access arrays.
+ * The same allowed access types as for xc_set_mem_access() apply.
+ */
+int xc_set_mem_access_multi(xc_interface *xch, uint32_t domain_id,
+                            uint8_t *access, uint64_t *pages,
+                            uint32_t nr);
+
+/*
+ * Gets the mem access for the given page (returned in access on success)
+ */
+int xc_get_mem_access(xc_interface *xch, uint32_t domain_id,
+                      uint64_t pfn, xenmem_access_t *access);
+
+/*
+ * Returns the VM_EVENT_INTERFACE version.
+ */
+int xc_vm_event_get_version(xc_interface *xch);
+
+/***
+ * Monitor control operations.
+ *
+ * Enables the VM event monitor ring and returns the mapped ring page.
+ * This ring is used to deliver mem_access events, as well a set of additional
+ * events that can be enabled with the xc_monitor_* functions.
+ *
+ * Will return NULL on error.
+ * Caller has to unmap this page when done.
+ */
+void *xc_monitor_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port);
+int xc_monitor_disable(xc_interface *xch, uint32_t domain_id);
+int xc_monitor_resume(xc_interface *xch, uint32_t domain_id);
+/*
+ * Get a bitmap of supported monitor events in the form
+ * (1 << XEN_DOMCTL_MONITOR_EVENT_*).
+ */
+int xc_monitor_get_capabilities(xc_interface *xch, uint32_t domain_id,
+                                uint32_t *capabilities);
+int xc_monitor_write_ctrlreg(xc_interface *xch, uint32_t domain_id,
+                             uint16_t index, bool enable, bool sync,
+                             uint64_t bitmask, bool onchangeonly);
+/*
+ * A list of MSR indices can usually be found in /usr/include/asm/msr-index.h.
+ * Please consult the Intel/AMD manuals for more information on
+ * non-architectural indices.
+ */
+int xc_monitor_mov_to_msr(xc_interface *xch, uint32_t domain_id, uint32_t msr,
+                          bool enable, bool onchangeonly);
+int xc_monitor_singlestep(xc_interface *xch, uint32_t domain_id, bool enable);
+int xc_monitor_software_breakpoint(xc_interface *xch, uint32_t domain_id,
+                                   bool enable);
+int xc_monitor_descriptor_access(xc_interface *xch, uint32_t domain_id,
+                                 bool enable);
+int xc_monitor_guest_request(xc_interface *xch, uint32_t domain_id,
+                             bool enable, bool sync, bool allow_userspace);
+/*
+ * Disables page-walk mem_access events by emulating. If the
+ * emulation can not be performed then a VM_EVENT_REASON_EMUL_UNIMPLEMENTED
+ * event will be issued.
+ */
+int xc_monitor_inguest_pagefault(xc_interface *xch, uint32_t domain_id,
+                                 bool disable);
+int xc_monitor_debug_exceptions(xc_interface *xch, uint32_t domain_id,
+                                bool enable, bool sync);
+int xc_monitor_cpuid(xc_interface *xch, uint32_t domain_id, bool enable);
+int xc_monitor_privileged_call(xc_interface *xch, uint32_t domain_id,
+                               bool enable);
+int xc_monitor_emul_unimplemented(xc_interface *xch, uint32_t domain_id,
+                                  bool enable);
+/**
+ * This function enables / disables emulation for each REP for a
+ * REP-compatible instruction.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domain_id the domain id one wants to get the node affinity of.
+ * @parm enable if 0 optimize when possible, else emulate each REP.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_monitor_emulate_each_rep(xc_interface *xch, uint32_t domain_id,
+                                bool enable);
+
+/***
+ * Memory sharing operations.
+ *
+ * Unles otherwise noted, these calls return 0 on succes, -1 and errno on
+ * failure.
+ *
+ * Sharing is supported only on the x86 architecture in 64 bit mode, with
+ * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
+ * support is considered experimental.
+
+ * Calls below return ENOSYS if not in the x86_64 architecture.
+ * Calls below return ENODEV if the domain does not support HAP.
+ * Calls below return ESRCH if the specified domain does not exist.
+ * Calls below return EPERM if the caller is unprivileged for this domain.
+ */
+
+/* Turn on/off sharing for the domid, depending on the enable flag.
+ *
+ * Returns EXDEV if trying to enable and the domain has had a PCI device
+ * assigned for passthrough (these two features are mutually exclusive).
+ *
+ * When sharing for a domain is turned off, the domain may still reference
+ * shared pages. Unsharing happens lazily. */
+int xc_memshr_control(xc_interface *xch,
+                      uint32_t domid,
+                      int enable);
+
+/* Create a communication ring in which the hypervisor will place ENOMEM
+ * notifications.
+ *
+ * ENOMEM happens when unsharing pages: a Copy-on-Write duplicate needs to be
+ * allocated, and thus the out-of-memory error occurr.
+ *
+ * For complete examples on how to plumb a notification ring, look into
+ * xenpaging or xen-access.
+ *
+ * On receipt of a notification, the helper should ensure there is memory
+ * available to the domain before retrying.
+ *
+ * If a domain encounters an ENOMEM condition when sharing and this ring
+ * has not been set up, the hypervisor will crash the domain.
+ *
+ * Fails with:
+ *  EINVAL if port is NULL
+ *  EINVAL if the sharing ring has already been enabled
+ *  ENOSYS if no guest gfn has been specified to host the ring via an hvm param
+ *  EINVAL if the gfn for the ring has not been populated
+ *  ENOENT if the gfn for the ring is paged out, or cannot be unshared
+ *  EINVAL if the gfn for the ring cannot be written to
+ *  EINVAL if the domain is dying
+ *  ENOSPC if an event channel cannot be allocated for the ring
+ *  ENOMEM if memory cannot be allocated for internal data structures
+ *  EINVAL or EACCESS if the request is denied by the security policy
+ */
+
+int xc_memshr_ring_enable(xc_interface *xch,
+                          uint32_t domid,
+                          uint32_t *port);
+/* Disable the ring for ENOMEM communication.
+ * May fail with EINVAL if the ring was not enabled in the first place.
+ */
+int xc_memshr_ring_disable(xc_interface *xch,
+                           uint32_t domid);
+
+/*
+ * Calls below return EINVAL if sharing has not been enabled for the domain
+ * Calls below return EINVAL if the domain is dying
+ */
+/* Once a reponse to an ENOMEM notification is prepared, the tool can
+ * notify the hypervisor to re-schedule the faulting vcpu of the domain with an
+ * event channel kick and/or this call. */
+int xc_memshr_domain_resume(xc_interface *xch,
+                            uint32_t domid);
+
+/* Select a page for sharing.
+ *
+ * A 64 bit opaque handle will be stored in handle.  The hypervisor ensures
+ * that if the page is modified, the handle will be invalidated, and future
+ * users of it will fail. If the page has already been selected and is still
+ * associated to a valid handle, the existing handle will be returned.
+ *
+ * May fail with:
+ *  EINVAL if the gfn is not populated or not sharable (mmio, etc)
+ *  ENOMEM if internal data structures cannot be allocated
+ *  E2BIG if the page is being referenced by other subsytems (e.g. qemu)
+ *  ENOENT or EEXIST if there are internal hypervisor errors.
+ */
+int xc_memshr_nominate_gfn(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned long gfn,
+                           uint64_t *handle);
+/* Same as above, but instead of a guest frame number, the input is a grant
+ * reference provided by the guest.
+ *
+ * May fail with EINVAL if the grant reference is invalid.
+ */
+int xc_memshr_nominate_gref(xc_interface *xch,
+                            uint32_t domid,
+                            grant_ref_t gref,
+                            uint64_t *handle);
+
+/* The three calls below may fail with
+ * 10 (or -XENMEM_SHARING_OP_S_HANDLE_INVALID) if the handle passed as source
+ * is invalid.
+ * 9 (or -XENMEM_SHARING_OP_C_HANDLE_INVALID) if the handle passed as client is
+ * invalid.
+ */
+/* Share two nominated guest pages.
+ *
+ * If the call succeeds, both pages will point to the same backing frame (or
+ * mfn). The hypervisor will verify the handles are still valid, but it will
+ * not perform any sanity checking on the contens of the pages (the selection
+ * mechanism for sharing candidates is entirely up to the user-space tool).
+ *
+ * After successful sharing, the client handle becomes invalid. Both <domain,
+ * gfn> tuples point to the same mfn with the same handle, the one specified as
+ * source. Either 3-tuple can be specified later for further re-sharing.
+ */
+int xc_memshr_share_gfns(xc_interface *xch,
+                    uint32_t source_domain,
+                    unsigned long source_gfn,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    unsigned long client_gfn,
+                    uint64_t client_handle);
+
+/* Same as above, but share two grant references instead.
+ *
+ * May fail with EINVAL if either grant reference is invalid.
+ */
+int xc_memshr_share_grefs(xc_interface *xch,
+                    uint32_t source_domain,
+                    grant_ref_t source_gref,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    grant_ref_t client_gref,
+                    uint64_t client_handle);
+
+/* Allows to add to the guest physmap of the client domain a shared frame
+ * directly.
+ *
+ * May additionally fail with
+ *  9 (-XENMEM_SHARING_OP_C_HANDLE_INVALID) if the physmap entry for the gfn is
+ *  not suitable.
+ *  ENOMEM if internal data structures cannot be allocated.
+ *  ENOENT if there is an internal hypervisor error.
+ */
+int xc_memshr_add_to_physmap(xc_interface *xch,
+                    uint32_t source_domain,
+                    unsigned long source_gfn,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    unsigned long client_gfn);
+
+/* Allows to deduplicate a range of memory of a client domain. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns.
+ *
+ * May fail with -EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ * May also fail with -ENOMEM if there isn't enough memory available to store
+ * the sharing metadata before deduplication can happen.
+ */
+int xc_memshr_range_share(xc_interface *xch,
+                          uint32_t source_domain,
+                          uint32_t client_domain,
+                          uint64_t first_gfn,
+                          uint64_t last_gfn);
+
+int xc_memshr_fork(xc_interface *xch,
+                   uint32_t source_domain,
+                   uint32_t client_domain,
+                   bool allow_with_iommu,
+                   bool block_interrupts);
+
+/*
+ * Note: this function is only intended to be used on short-lived forks that
+ * haven't yet aquired a lot of memory. In case the fork has a lot of memory
+ * it is likely more performant to create a new fork with xc_memshr_fork.
+ *
+ * With VMs that have a lot of memory this call may block for a long time.
+ */
+int xc_memshr_fork_reset(xc_interface *xch, uint32_t forked_domain);
+
+/* Debug calls: return the number of pages referencing the shared frame backing
+ * the input argument. Should be one or greater.
+ *
+ * May fail with EINVAL if there is no backing shared frame for the input
+ * argument.
+ */
+int xc_memshr_debug_gfn(xc_interface *xch,
+                        uint32_t domid,
+                        unsigned long gfn);
+/* May additionally fail with EINVAL if the grant reference is invalid. */
+int xc_memshr_debug_gref(xc_interface *xch,
+                         uint32_t domid,
+                         grant_ref_t gref);
+
+/* Audits the share subsystem.
+ *
+ * Returns ENOSYS if not supported (may not be compiled into the hypervisor).
+ *
+ * Returns the number of errors found during auditing otherwise. May be (should
+ * be!) zero.
+ *
+ * If debugtrace support has been compiled into the hypervisor and is enabled,
+ * verbose descriptions for the errors are available in the hypervisor console.
+ */
+int xc_memshr_audit(xc_interface *xch);
+
+/* Stats reporting.
+ *
+ * At any point in time, the following equality should hold for a host:
+ *
+ *  Let dominfo(d) be the xc_dominfo_t struct filled by a call to
+ *  xc_domain_getinfo(d)
+ *
+ *  The summation of dominfo(d)->shr_pages for all domains in the system
+ *      should be equal to
+ *  xc_sharing_freed_pages + xc_sharing_used_frames
+ */
+/*
+ * This function returns the total number of pages freed by using sharing
+ * on the system.  For example, if two domains contain a single entry in
+ * their p2m table that points to the same shared page (and no other pages
+ * in the system are shared), then this function should return 1.
+ */
+long xc_sharing_freed_pages(xc_interface *xch);
+
+/*
+ * This function returns the total number of frames occupied by shared
+ * pages on the system.  This is independent of the number of domains
+ * pointing at these frames.  For example, in the above scenario this
+ * should return 1. (And dominfo(d) for each of the two domains should return 1
+ * as well).
+ *
+ * Note that some of these sharing_used_frames may be referenced by
+ * a single domain page, and thus not realize any savings. The same
+ * applies to some of the pages counted in dominfo(d)->shr_pages.
+ */
+long xc_sharing_used_frames(xc_interface *xch);
+/*** End sharing interface ***/
+
+int xc_flask_load(xc_interface *xc_handle, char *buf, uint32_t size);
+int xc_flask_context_to_sid(xc_interface *xc_handle, char *buf, uint32_t size, uint32_t *sid);
+int xc_flask_sid_to_context(xc_interface *xc_handle, int sid, char *buf, uint32_t size);
+int xc_flask_getenforce(xc_interface *xc_handle);
+int xc_flask_setenforce(xc_interface *xc_handle, int mode);
+int xc_flask_getbool_byid(xc_interface *xc_handle, int id, char *name, uint32_t size, int *curr, int *pend);
+int xc_flask_getbool_byname(xc_interface *xc_handle, char *name, int *curr, int *pend);
+int xc_flask_setbool(xc_interface *xc_handle, char *name, int value, int commit);
+int xc_flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext);
+int xc_flask_add_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high,
+                      char *scontext);
+int xc_flask_add_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high,
+                     char *scontext);
+int xc_flask_add_device(xc_interface *xc_handle, unsigned long device, char *scontext);
+int xc_flask_del_pirq(xc_interface *xc_handle, unsigned int pirq);
+int xc_flask_del_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high);
+int xc_flask_del_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high);
+int xc_flask_del_device(xc_interface *xc_handle, unsigned long device);
+int xc_flask_access(xc_interface *xc_handle, const char *scon, const char *tcon,
+                  uint16_t tclass, uint32_t req,
+                  uint32_t *allowed, uint32_t *decided,
+                  uint32_t *auditallow, uint32_t *auditdeny,
+                  uint32_t *seqno);
+int xc_flask_avc_cachestats(xc_interface *xc_handle, char *buf, int size);
+int xc_flask_policyvers(xc_interface *xc_handle);
+int xc_flask_avc_hashstats(xc_interface *xc_handle, char *buf, int size);
+int xc_flask_getavc_threshold(xc_interface *xc_handle);
+int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold);
+int xc_flask_relabel_domain(xc_interface *xch, uint32_t domid, uint32_t sid);
+
+struct elf_binary;
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
+                        int verbose);
+/* Useful for callers who also use libelf. */
+
+/*
+ * Execute an image previously loaded with xc_kexec_load().
+ *
+ * Does not return on success.
+ *
+ * Fails with:
+ *   ENOENT if the specified image has not been loaded.
+ */
+int xc_kexec_exec(xc_interface *xch, int type);
+
+/*
+ * Find the machine address and size of certain memory areas.
+ *
+ *   KEXEC_RANGE_MA_CRASH       crash area
+ *   KEXEC_RANGE_MA_XEN         Xen itself
+ *   KEXEC_RANGE_MA_CPU         CPU note for CPU number 'nr'
+ *   KEXEC_RANGE_MA_XENHEAP     xenheap
+ *   KEXEC_RANGE_MA_EFI_MEMMAP  EFI Memory Map
+ *   KEXEC_RANGE_MA_VMCOREINFO  vmcoreinfo
+ *
+ * Fails with:
+ *   EINVAL if the range or CPU number isn't valid.
+ */
+int xc_kexec_get_range(xc_interface *xch, int range,  int nr,
+                       uint64_t *size, uint64_t *start);
+
+/*
+ * Load a kexec image into memory.
+ *
+ * The image may be of type KEXEC_TYPE_DEFAULT (executed on request)
+ * or KEXEC_TYPE_CRASH (executed on a crash).
+ *
+ * The image architecture may be a 32-bit variant of the hypervisor
+ * architecture (e.g, EM_386 on a x86-64 hypervisor).
+ *
+ * Fails with:
+ *   ENOMEM if there is insufficient memory for the new image.
+ *   EINVAL if the image does not fit into the crash area or the entry
+ *          point isn't within one of segments.
+ *   EBUSY  if another image is being executed.
+ */
+int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch,
+                  uint64_t entry_maddr,
+                  uint32_t nr_segments, xen_kexec_segment_t *segments);
+
+/*
+ * Unload a kexec image.
+ *
+ * This prevents a KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH image from
+ * being executed.  The crash images are not cleared from the crash
+ * region.
+ */
+int xc_kexec_unload(xc_interface *xch, int type);
+
+/*
+ * Find out whether the image has been succesfully loaded.
+ *
+ * The type can be either KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
+ * If zero is returned, that means no image is loaded for the type.
+ * If one is returned, that means an image is loaded for the type.
+ * Otherwise, negative return value indicates error.
+ */
+int xc_kexec_status(xc_interface *xch, int type);
+
+typedef xenpf_resource_entry_t xc_resource_entry_t;
+
+/*
+ * Generic resource operation which contains multiple non-preemptible
+ * resource access entries that passed to xc_resource_op().
+ */
+struct xc_resource_op {
+    uint64_t result;        /* on return, check this field first */
+    uint32_t cpu;           /* which cpu to run */
+    uint32_t nr_entries;    /* number of resource entries */
+    xc_resource_entry_t *entries;
+};
+
+typedef struct xc_resource_op xc_resource_op_t;
+int xc_resource_op(xc_interface *xch, uint32_t nr_ops, xc_resource_op_t *ops);
+
+#if defined(__i386__) || defined(__x86_64__)
+enum xc_psr_cmt_type {
+    XC_PSR_CMT_L3_OCCUPANCY,
+    XC_PSR_CMT_TOTAL_MEM_COUNT,
+    XC_PSR_CMT_LOCAL_MEM_COUNT,
+};
+typedef enum xc_psr_cmt_type xc_psr_cmt_type;
+
+enum xc_psr_type {
+    XC_PSR_CAT_L3_CBM      = 1,
+    XC_PSR_CAT_L3_CBM_CODE = 2,
+    XC_PSR_CAT_L3_CBM_DATA = 3,
+    XC_PSR_CAT_L2_CBM      = 4,
+    XC_PSR_MBA_THRTL       = 5,
+};
+typedef enum xc_psr_type xc_psr_type;
+
+enum xc_psr_feat_type {
+    XC_PSR_CAT_L3,
+    XC_PSR_CAT_L2,
+    XC_PSR_MBA,
+};
+typedef enum xc_psr_feat_type xc_psr_feat_type;
+
+union xc_psr_hw_info {
+    struct {
+        uint32_t cos_max;
+        uint32_t cbm_len;
+        bool     cdp_enabled;
+    } cat;
+
+    struct {
+        uint32_t cos_max;
+        uint32_t thrtl_max;
+        bool     linear;
+    } mba;
+};
+typedef union xc_psr_hw_info xc_psr_hw_info;
+
+int xc_psr_cmt_attach(xc_interface *xch, uint32_t domid);
+int xc_psr_cmt_detach(xc_interface *xch, uint32_t domid);
+int xc_psr_cmt_get_domain_rmid(xc_interface *xch, uint32_t domid,
+                               uint32_t *rmid);
+int xc_psr_cmt_get_total_rmid(xc_interface *xch, uint32_t *total_rmid);
+int xc_psr_cmt_get_l3_upscaling_factor(xc_interface *xch,
+                                       uint32_t *upscaling_factor);
+int xc_psr_cmt_get_l3_event_mask(xc_interface *xch, uint32_t *event_mask);
+int xc_psr_cmt_get_l3_cache_size(xc_interface *xch, uint32_t cpu,
+                                 uint32_t *l3_cache_size);
+int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu,
+                        uint32_t psr_cmt_type, uint64_t *monitor_data,
+                        uint64_t *tsc);
+int xc_psr_cmt_enabled(xc_interface *xch);
+
+int xc_psr_set_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_type type, uint32_t target,
+                           uint64_t data);
+int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_type type, uint32_t target,
+                           uint64_t *data);
+int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket,
+                       xc_psr_feat_type type, xc_psr_hw_info *hw_info);
+
+int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
+int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
+                          uint32_t *nr_features, uint32_t *featureset);
+
+int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
+                           uint32_t *nr_msrs);
+int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs);
+int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs);
+int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
+                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
+                             uint32_t *err_msr_p);
+
+uint32_t xc_get_cpu_featureset_size(void);
+
+enum xc_static_cpu_featuremask {
+    XC_FEATUREMASK_KNOWN,
+    XC_FEATUREMASK_SPECIAL,
+    XC_FEATUREMASK_PV_MAX,
+    XC_FEATUREMASK_PV_DEF,
+    XC_FEATUREMASK_HVM_SHADOW_MAX,
+    XC_FEATUREMASK_HVM_SHADOW_DEF,
+    XC_FEATUREMASK_HVM_HAP_MAX,
+    XC_FEATUREMASK_HVM_HAP_DEF,
+};
+const uint32_t *xc_get_static_cpu_featuremask(enum xc_static_cpu_featuremask);
+
+#endif
+
+int xc_livepatch_upload(xc_interface *xch,
+                        char *name, unsigned char *payload, uint32_t size);
+
+int xc_livepatch_get(xc_interface *xch,
+                     char *name,
+                     xen_livepatch_status_t *status);
+
+/*
+ * Get a number of available payloads and get actual total size of
+ * the payloads' name and metadata arrays.
+ *
+ * This functions is typically executed first before the xc_livepatch_list()
+ * to obtain the sizes and correctly allocate all necessary data resources.
+ *
+ * The return value is zero if the hypercall completed successfully.
+ *
+ * If there was an error performing the sysctl operation, the return value
+ * will contain the hypercall error code value.
+ */
+int xc_livepatch_list_get_sizes(xc_interface *xch, unsigned int *nr,
+                                uint32_t *name_total_size,
+                                uint32_t *metadata_total_size);
+
+/*
+ * The heart of this function is to get an array of the following objects:
+ *   - xen_livepatch_status_t: states and return codes of payloads
+ *   - name: names of payloads
+ *   - len: lengths of corresponding payloads' names
+ *   - metadata: payloads' metadata
+ *   - metadata_len: lengths of corresponding payloads' metadata
+ *
+ * However it is complex because it has to deal with the hypervisor
+ * returning some of the requested data or data being stale
+ * (another hypercall might alter the list).
+ *
+ * The parameters that the function expects to contain data from
+ * the hypervisor are: 'info', 'name', and 'len'. The 'done' and
+ * 'left' are also updated with the number of entries filled out
+ * and respectively the number of entries left to get from hypervisor.
+ *
+ * It is expected that the caller of this function will first issue the
+ * xc_livepatch_list_get_sizes() in order to obtain total sizes of names
+ * and all metadata as well as the current number of payload entries.
+ * The total sizes are required and supplied via the 'name_total_size' and
+ * 'metadata_total_size' parameters.
+ *
+ * The 'max' is to be provided by the caller with the maximum number of
+ * entries that 'info', 'name', 'len', 'metadata' and 'metadata_len' arrays
+ * can be filled up with.
+ *
+ * Each entry in the 'info' array is expected to be of xen_livepatch_status_t
+ * structure size.
+ *
+ * Each entry in the 'name' array may have an arbitrary size.
+ *
+ * Each entry in the 'len' array is expected to be of uint32_t size.
+ *
+ * Each entry in the 'metadata' array may have an arbitrary size.
+ *
+ * Each entry in the 'metadata_len' array is expected to be of uint32_t size.
+ *
+ * The return value is zero if the hypercall completed successfully.
+ * Note that the return value is _not_ the amount of entries filled
+ * out - that is saved in 'done'.
+ *
+ * If there was an error performing the operation, the return value
+ * will contain an negative -EXX type value. The 'done' and 'left'
+ * will contain the number of entries that had been succesfully
+ * retrieved (if any).
+ */
+int xc_livepatch_list(xc_interface *xch, const unsigned int max,
+                      const unsigned int start,
+                      struct xen_livepatch_status *info,
+                      char *name, uint32_t *len,
+                      const uint32_t name_total_size,
+                      char *metadata, uint32_t *metadata_len,
+                      const uint32_t metadata_total_size,
+                      unsigned int *done, unsigned int *left);
+
+/*
+ * The operations are asynchronous and the hypervisor may take a while
+ * to complete them. The `timeout` offers an option to expire the
+ * operation if it could not be completed within the specified time
+ * (in ns). Value of 0 means let hypervisor decide the best timeout.
+ * The `flags` allows to pass extra parameters to the actions.
+ */
+int xc_livepatch_apply(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3O-0000q4-EJ; Wed, 09 Sep 2020 11:14:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3N-0000pw-3h
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:17 +0000
X-Inumbo-ID: 09540afc-b4f9-4cec-9ea4-be539ab69b0e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 09540afc-b4f9-4cec-9ea4-be539ab69b0e;
 Wed, 09 Sep 2020 11:14:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=1cD5SinPZ2JlIf0fOVvO80sj6HhBA5UbrVEZclGyhzA=; b=ej7936QlyR7XlT1FxUryL71JJi
 KJgNgt9moo8eNxQwP7veTO9ozXu8Amub4JK7OZVZAzBAybRHOYdRifhFvrleqMjMQTZV6nuES2XLw
 XQaDTTnfqn1hCZ4bCwCnD9+/Hvo6T9k+UxI9KasQH0/gLEXBt3bG1Uxcj28ac6mFtMBM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3G-00067y-JG
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:10 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3G-0001YS-Hr
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:10 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxc: move libxenguest to tools/libs/guest
Message-Id: <E1kFy3G-0001YS-Hr@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:10 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e3dd624e487c1aca1835138d3990f78af9906238
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:35 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: move libxenguest to tools/libs/guest
    
    tools/libxc now contains libxenguest only. Move it to tools/libs/guest.
    
    When generating the pkg-config file for libxenguest a filter is now
    required for replacing "xenctrl" by "xencontrol" in the
    "Requires.private:" entry. Add this filter to tools/libs/libs.mk.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> (stubdom parts)
---
 .gitignore                                        |   16 +-
 stubdom/Makefile                                  |   34 +-
 stubdom/grub/Makefile                             |    2 +-
 stubdom/mini-os.mk                                |    2 +-
 tools/Makefile                                    |    3 +-
 tools/Rules.mk                                    |    7 +-
 tools/libs/Makefile                               |    1 +
 tools/libs/guest/COPYING                          |  467 +++++
 tools/libs/guest/Makefile                         |  121 ++
 tools/libs/guest/include/xenguest.h               |  327 ++++
 tools/libs/guest/xg_cpuid_x86.c                   |  665 +++++++
 tools/libs/guest/xg_dom_arm.c                     |  552 ++++++
 tools/libs/guest/xg_dom_armzimageloader.c         |  271 +++
 tools/libs/guest/xg_dom_binloader.c               |  329 ++++
 tools/libs/guest/xg_dom_boot.c                    |  451 +++++
 tools/libs/guest/xg_dom_bzimageloader.c           |  812 +++++++++
 tools/libs/guest/xg_dom_compat_linux.c            |   97 +
 tools/libs/guest/xg_dom_core.c                    | 1272 ++++++++++++++
 tools/libs/guest/xg_dom_decompress.h              |    8 +
 tools/libs/guest/xg_dom_decompress_lz4.c          |  141 ++
 tools/libs/guest/xg_dom_decompress_unsafe.c       |   48 +
 tools/libs/guest/xg_dom_decompress_unsafe.h       |   20 +
 tools/libs/guest/xg_dom_decompress_unsafe_bzip2.c |   14 +
 tools/libs/guest/xg_dom_decompress_unsafe_lzma.c  |   14 +
 tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c |   50 +
 tools/libs/guest/xg_dom_decompress_unsafe_xz.c    |   46 +
 tools/libs/guest/xg_dom_elfloader.c               |  249 +++
 tools/libs/guest/xg_dom_hvmloader.c               |  264 +++
 tools/libs/guest/xg_dom_x86.c                     | 1945 +++++++++++++++++++++
 tools/libs/guest/xg_domain.c                      |  149 ++
 tools/libs/guest/xg_nomigrate.c                   |   50 +
 tools/libs/guest/xg_offline_page.c                |  708 ++++++++
 tools/libs/guest/xg_private.c                     |  198 +++
 tools/libs/guest/xg_private.h                     |  124 ++
 tools/libs/guest/xg_save_restore.h                |  134 ++
 tools/libs/guest/xg_sr_common.c                   |  167 ++
 tools/libs/guest/xg_sr_common.h                   |  468 +++++
 tools/libs/guest/xg_sr_common_x86.c               |  173 ++
 tools/libs/guest/xg_sr_common_x86.h               |   51 +
 tools/libs/guest/xg_sr_common_x86_pv.c            |  193 ++
 tools/libs/guest/xg_sr_common_x86_pv.h            |  109 ++
 tools/libs/guest/xg_sr_restore.c                  |  986 +++++++++++
 tools/libs/guest/xg_sr_restore_x86_hvm.c          |  274 +++
 tools/libs/guest/xg_sr_restore_x86_pv.c           | 1210 +++++++++++++
 tools/libs/guest/xg_sr_save.c                     | 1059 +++++++++++
 tools/libs/guest/xg_sr_save_x86_hvm.c             |  251 +++
 tools/libs/guest/xg_sr_save_x86_pv.c              | 1156 ++++++++++++
 tools/libs/guest/xg_sr_stream_format.h            |  150 ++
 tools/libs/guest/xg_suspend.c                     |  202 +++
 tools/libs/libs.mk                                |    2 +-
 tools/libs/uselibs.mk                             |    2 +
 tools/libxc/COPYING                               |  467 -----
 tools/libxc/Makefile                              |  219 ---
 tools/libxc/include/xenguest.h                    |  327 ----
 tools/libxc/xg_cpuid_x86.c                        |  665 -------
 tools/libxc/xg_dom_arm.c                          |  552 ------
 tools/libxc/xg_dom_armzimageloader.c              |  271 ---
 tools/libxc/xg_dom_binloader.c                    |  329 ----
 tools/libxc/xg_dom_boot.c                         |  451 -----
 tools/libxc/xg_dom_bzimageloader.c                |  812 ---------
 tools/libxc/xg_dom_compat_linux.c                 |   97 -
 tools/libxc/xg_dom_core.c                         | 1272 --------------
 tools/libxc/xg_dom_decompress.h                   |    8 -
 tools/libxc/xg_dom_decompress_lz4.c               |  141 --
 tools/libxc/xg_dom_decompress_unsafe.c            |   48 -
 tools/libxc/xg_dom_decompress_unsafe.h            |   20 -
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c      |   14 -
 tools/libxc/xg_dom_decompress_unsafe_lzma.c       |   14 -
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c      |   50 -
 tools/libxc/xg_dom_decompress_unsafe_xz.c         |   46 -
 tools/libxc/xg_dom_elfloader.c                    |  249 ---
 tools/libxc/xg_dom_hvmloader.c                    |  264 ---
 tools/libxc/xg_dom_x86.c                          | 1945 ---------------------
 tools/libxc/xg_domain.c                           |  149 --
 tools/libxc/xg_nomigrate.c                        |   50 -
 tools/libxc/xg_offline_page.c                     |  708 --------
 tools/libxc/xg_private.c                          |  198 ---
 tools/libxc/xg_private.h                          |  124 --
 tools/libxc/xg_save_restore.h                     |  134 --
 tools/libxc/xg_sr_common.c                        |  167 --
 tools/libxc/xg_sr_common.h                        |  468 -----
 tools/libxc/xg_sr_common_x86.c                    |  173 --
 tools/libxc/xg_sr_common_x86.h                    |   51 -
 tools/libxc/xg_sr_common_x86_pv.c                 |  193 --
 tools/libxc/xg_sr_common_x86_pv.h                 |  109 --
 tools/libxc/xg_sr_restore.c                       |  986 -----------
 tools/libxc/xg_sr_restore_x86_hvm.c               |  274 ---
 tools/libxc/xg_sr_restore_x86_pv.c                | 1210 -------------
 tools/libxc/xg_sr_save.c                          | 1059 -----------
 tools/libxc/xg_sr_save_x86_hvm.c                  |  251 ---
 tools/libxc/xg_sr_save_x86_pv.c                   | 1156 ------------
 tools/libxc/xg_sr_stream_format.h                 |  150 --
 tools/libxc/xg_suspend.c                          |  202 ---
 93 files changed, 16002 insertions(+), 16115 deletions(-)

diff --git a/.gitignore b/.gitignore
index d22b031ed2..eb637a98e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,7 +71,6 @@ stubdom/include
 stubdom/ioemu
 stubdom/ioemu/
 stubdom/libs-*
-stubdom/libxc-*
 stubdom/libxencall-*
 stubdom/libxenevtchn-*
 stubdom/libxenforeignmemory-*
@@ -121,6 +120,14 @@ tools/libs/foreignmemory/headers.chk
 tools/libs/foreignmemory/xenforeignmemory.pc
 tools/libs/devicemodel/headers.chk
 tools/libs/devicemodel/xendevicemodel.pc
+tools/libs/guest/_*.[ch]
+tools/libs/guest/libxenguest.map
+tools/libs/guest/xenguest.pc
+tools/libs/guest/xc_bitops.h
+tools/libs/guest/xc_core.h
+tools/libs/guest/xc_core_arm.h
+tools/libs/guest/xc_core_x86.h
+tools/libs/guest/xc_private.h
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -197,12 +204,6 @@ tools/include/xen-xsm/*
 tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
 tools/libvchan/xenvchan.pc
-tools/libxc/*.pc
-tools/libxc/xc_bitops.h
-tools/libxc/xc_core.h
-tools/libxc/xc_core_arm.h
-tools/libxc/xc_core_x86.h
-tools/libxc/xc_private.h
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
@@ -370,7 +371,6 @@ tools/include/xen-foreign/arm64.h
 tools/misc/xen-hptool
 tools/misc/xen-mfndump
 tools/libs/toolcore/include/_*.h
-tools/libxc/_*.[ch]
 tools/libxl/_*.[ch]
 tools/libxl/testidl
 tools/libxl/testidl.c
diff --git a/stubdom/Makefile b/stubdom/Makefile
index 6c481285ec..fb9617fa14 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -331,7 +331,9 @@ endif
 # libraries under tools/libs
 #######
 
-STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl
+STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl guest
+
+LIBDEP_guest := cross-zlib
 
 #######
 # common handling
@@ -362,13 +364,10 @@ endef
 
 $(foreach lib,$(STUB_LIBS),$(eval $(call BUILD_lib,$(lib))))
 
-libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
-	$(do_links)
-
 xenstore/stamp: $(XEN_ROOT)/tools/xenstore/Makefile
 	$(do_links)
 
-LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(STUB_LIBS),libs-$(XEN_TARGET_ARCH)/$(dir))
+LINK_DIRS := xenstore $(foreach dir,$(STUB_LIBS),libs-$(XEN_TARGET_ARCH)/$(dir))
 LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp)
 
 mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) $(LINK_STAMPS)
@@ -391,16 +390,6 @@ $(TARGETS_MINIOS): mini-os-%:
                 mkdir -p $@/$$i ; \
 	done
 
-#######
-# libxc
-#######
-
-.PHONY: libxc
-libxc: libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxenevtchn libxenctrl cross-zlib
-libxc-$(XEN_TARGET_ARCH)/libxenguest.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
-
 #######
 # ioemu
 #######
@@ -409,7 +398,7 @@ ioemu-minios-config.mk: $(CURDIR)/ioemu-minios.cfg
 	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
 
 .PHONY: ioemu
-ioemu: cross-zlib cross-libpci libxc ioemu-minios-config.mk
+ioemu: cross-zlib cross-libpci libxenguest ioemu-minios-config.mk
 	[ -f ioemu/config-host.mak ] || \
 	  ( $(buildmakevars2shellvars); \
 	    cd ioemu ; \
@@ -503,15 +492,15 @@ xenstore: $(CROSS_ROOT) xenstore-minios-config.mk
 
 .PHONY: ioemu-stubdom
 ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
-ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
+ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxenguest ioemu
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/ioemu-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
 
 .PHONY: caml-stubdom
-caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc cross-ocaml caml
+caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxenguest cross-ocaml caml
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/caml/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
 
 .PHONY: c-stubdom
-c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
+c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxenguest c
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/c/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
 
 .PHONY: vtpm-stubdom
@@ -523,11 +512,11 @@ vtpmmgr-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpmmgr vtpmmgr
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpmmgr/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpmmgr/vtpmmgr.a" APP_LDLIBS="-lm -lpolarssl"
 
 .PHONY: pv-grub
-pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
+pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxenguest grub
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/grub/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
 
 .PHONY: xenstore-stubdom
-xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
+xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxenguest xenstore
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/xenstore-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/xenstore/xenstored.a
 
 #########
@@ -621,7 +610,6 @@ clean:
 	rm -f $(STUBDOMPATH)
 	rm -f *-minios-config.mk
 	rm -fr pkg-config
-	[ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
 	-[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
 	-[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
 
@@ -632,7 +620,7 @@ crossclean: clean
 	rm -fr newlib-$(XEN_TARGET_ARCH)
 	rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
 	rm -fr libs-$(XEN_TARGET_ARCH)
-	rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
+	rm -fr ioemu xenstore
 	rm -fr gmp-$(XEN_TARGET_ARCH)
 	rm -fr polarssl-$(XEN_TARGET_ARCH)
 	rm -fr openssl-$(XEN_TARGET_ARCH)
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
index d33fa2f71e..7397661c9b 100644
--- a/stubdom/grub/Makefile
+++ b/stubdom/grub/Makefile
@@ -7,7 +7,7 @@ BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/guest/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index b1387df3f8..e1640a7cbc 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -14,4 +14,4 @@ CALL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
 FOREIGNMEMORY_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
 DEVICEMODEL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
 CTRL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/ctrl
-GUEST_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+GUEST_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/guest
diff --git a/tools/Makefile b/tools/Makefile
index 7c9f9fc900..f9b4012290 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -6,7 +6,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += libs
-SUBDIRS-y += libxc
 SUBDIRS-y += flask
 SUBDIRS-y += fuzz
 SUBDIRS-y += xenstore
@@ -44,7 +43,7 @@ SUBDIRS-y += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 
 ifeq ($(CONFIG_RUMP),y)
-SUBDIRS-y := libs libxc xenstore
+SUBDIRS-y := libs xenstore
 endif
 
 # For the sake of linking, set the sys-root
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 35940cb338..e17ac3ecc6 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -15,7 +15,6 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
@@ -105,11 +104,7 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
 CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
-
-CFLAGS_libxenguest = -I$(XEN_libxenguest)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
-SHDEPS_libxenguest = $(SHLIB_libxenevtchn) $(SHLIB_libxenctrl)
-LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libextension)
-SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
+CFLAGS_libxenguest += $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory)
 
 CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 7648ea0e4c..f15c1688f7 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -10,6 +10,7 @@ SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
 SUBDIRS-y += devicemodel
 SUBDIRS-y += ctrl
+SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/guest/COPYING b/tools/libs/guest/COPYING
new file mode 100644
index 0000000000..7ca8702509
--- /dev/null
+++ b/tools/libs/guest/COPYING
@@ -0,0 +1,467 @@
+Note that the only valid version of the LGPL as far as the files in
+this directory (and its subdirectories) are concerned is _this_
+particular version of the license (i.e., *only* v2.1, not v2.2 or v3.x
+or whatever), unless explicitly otherwise stated.
+
+Where clause 3 is invoked in order to relicense under the GPL then
+this shall be considered to be GPL v2 only for files which have
+specified LGPL v2.1 only.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile
new file mode 100644
index 0000000000..e53aeabd3e
--- /dev/null
+++ b/tools/libs/guest/Makefile
@@ -0,0 +1,121 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+ifeq ($(CONFIG_LIBXC_MINIOS),y)
+# Save/restore of a domain is currently incompatible with a stubdom environment
+override CONFIG_MIGRATE := n
+endif
+
+LINK_FILES := xc_private.h xc_core.h xc_core_x86.h xc_core_arm.h xc_bitops.h
+
+$(LINK_FILES):
+	ln -sf $(XEN_ROOT)/tools/libs/ctrl/$(notdir $@) $@
+
+SRCS-y += xg_private.c
+SRCS-y += xg_domain.c
+SRCS-y += xg_suspend.c
+ifeq ($(CONFIG_MIGRATE),y)
+SRCS-y += xg_sr_common.c
+SRCS-$(CONFIG_X86) += xg_sr_common_x86.c
+SRCS-$(CONFIG_X86) += xg_sr_common_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_restore_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_restore_x86_hvm.c
+SRCS-$(CONFIG_X86) += xg_sr_save_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_save_x86_hvm.c
+SRCS-y += xg_sr_restore.c
+SRCS-y += xg_sr_save.c
+SRCS-y += xg_offline_page.c
+else
+SRCS-y += xg_nomigrate.c
+endif
+
+vpath %.c ../../../xen/common/libelf
+CFLAGS += -I../../../xen/common/libelf
+
+ELF_SRCS-y += libelf-tools.c libelf-loader.c
+ELF_SRCS-y += libelf-dominfo.c
+
+SRCS-y += $(ELF_SRCS-y)
+
+$(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
+$(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
+
+ifeq ($(CONFIG_X86),y) # Add libx86 to the build
+vpath %.c ../../../xen/lib/x86
+
+SRCS-y                 += cpuid.c msr.c
+endif
+
+# new domain builder
+SRCS-y                 += xg_dom_core.c
+SRCS-y                 += xg_dom_boot.c
+SRCS-y                 += xg_dom_elfloader.c
+SRCS-$(CONFIG_X86)     += xg_dom_bzimageloader.c
+SRCS-$(CONFIG_X86)     += xg_dom_decompress_lz4.c
+SRCS-$(CONFIG_X86)     += xg_dom_hvmloader.c
+SRCS-$(CONFIG_ARM)     += xg_dom_armzimageloader.c
+SRCS-y                 += xg_dom_binloader.c
+SRCS-y                 += xg_dom_compat_linux.c
+
+SRCS-$(CONFIG_X86)     += xg_dom_x86.c
+SRCS-$(CONFIG_X86)     += xg_cpuid_x86.c
+SRCS-$(CONFIG_ARM)     += xg_dom_arm.c
+
+ifeq ($(CONFIG_LIBXC_MINIOS),y)
+SRCS-y                 += xg_dom_decompress_unsafe.c
+SRCS-y                 += xg_dom_decompress_unsafe_bzip2.c
+SRCS-y                 += xg_dom_decompress_unsafe_lzma.c
+SRCS-y                 += xg_dom_decompress_unsafe_lzo1x.c
+SRCS-y                 += xg_dom_decompress_unsafe_xz.c
+endif
+
+-include $(XEN_TARGET_ARCH)/Makefile
+
+CFLAGS   += -Werror -Wmissing-prototypes
+CFLAGS   += -I. -I./include $(CFLAGS_xeninclude)
+CFLAGS   += -D__XEN_TOOLS__
+CFLAGS   += -include $(XEN_ROOT)/tools/config.h
+
+# Needed for posix_fadvise64() in xc_linux.c
+CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
+
+CFLAGS	+= $(PTHREAD_CFLAGS)
+CFLAGS	+= $(CFLAGS_libxentoollog)
+CFLAGS	+= $(CFLAGS_libxenevtchn)
+CFLAGS	+= $(CFLAGS_libxendevicemodel)
+
+# libxenguest includes xc_private.h, so needs this despite not using
+# this functionality directly.
+CFLAGS += $(CFLAGS_libxencall) $(CFLAGS_libxenforeignmemory)
+
+ifeq ($(CONFIG_MiniOS),y)
+zlib-options =
+else
+zlib-options = $(ZLIB)
+endif
+
+xc_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
+xc_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
+
+LIBHEADER := xenguest.h
+
+NO_HEADERS_CHK := y
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(filter -l%,$(zlib-options))
+libxenguest.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += $(COMPRESSION_LIBS) -lz
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
+
+xc_private.h: _paths.h
+
+$(LIB_OBJS) $(PIC_OBJS): $(LINK_FILES)
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenctrl)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenguest.map
diff --git a/tools/libs/guest/include/xenguest.h b/tools/libs/guest/include/xenguest.h
new file mode 100644
index 0000000000..4643384790
--- /dev/null
+++ b/tools/libs/guest/include/xenguest.h
@@ -0,0 +1,327 @@
+/******************************************************************************
+ * xenguest.h
+ *
+ * A library for guest domain management in Xen.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XENGUEST_H
+#define XENGUEST_H
+
+#include <xenctrl_dom.h>
+
+#define XC_NUMA_NO_NODE   (~0U)
+
+#define XCFLAGS_LIVE      (1 << 0)
+#define XCFLAGS_DEBUG     (1 << 1)
+
+#define X86_64_B_SIZE   64 
+#define X86_32_B_SIZE   32
+
+/*
+ * User not using xc_suspend_* / xc_await_suspent may not want to
+ * include the full libxenevtchn API here.
+ */
+struct xenevtchn_handle;
+
+/* For save's precopy_policy(). */
+struct precopy_stats
+{
+    unsigned int iteration;
+    unsigned int total_written;
+    long dirty_count; /* -1 if unknown */
+};
+
+/*
+ * A precopy_policy callback may not be running in the same address
+ * space as libxc an so precopy_stats is passed by value.
+ */
+typedef int (*precopy_policy_t)(struct precopy_stats, void *);
+
+/* callbacks provided by xc_domain_save */
+struct save_callbacks {
+    /*
+     * Called after expiration of checkpoint interval,
+     * to suspend the guest.
+     */
+    int (*suspend)(void *data);
+
+    /*
+     * Called before and after every batch of page data sent during
+     * the precopy phase of a live migration to ask the caller what
+     * to do next based on the current state of the precopy migration.
+     *
+     * Should return one of the values listed below:
+     */
+#define XGS_POLICY_ABORT          (-1) /* Abandon the migration entirely
+                                        * and tidy up. */
+#define XGS_POLICY_CONTINUE_PRECOPY 0  /* Remain in the precopy phase. */
+#define XGS_POLICY_STOP_AND_COPY    1  /* Immediately suspend and transmit the
+                                        * remaining dirty pages. */
+    precopy_policy_t precopy_policy;
+
+    /*
+     * Called after the guest's dirty pages have been
+     *  copied into an output buffer.
+     * Callback function resumes the guest & the device model,
+     *  returns to xc_domain_save.
+     * xc_domain_save then flushes the output buffer, while the
+     *  guest continues to run.
+     */
+    int (*postcopy)(void *data);
+
+    /*
+     * Called after the memory checkpoint has been flushed
+     * out into the network. Typical actions performed in this
+     * callback include:
+     *   (a) send the saved device model state (for HVM guests),
+     *   (b) wait for checkpoint ack
+     *   (c) release the network output buffer pertaining to the acked checkpoint.
+     *   (c) sleep for the checkpoint interval.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*checkpoint)(void *data);
+
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*wait_checkpoint)(void *data);
+
+    /* Enable qemu-dm logging dirty pages to xen */
+    int (*switch_qemu_logdirty)(uint32_t domid, unsigned enable, void *data); /* HVM only */
+
+    /* to be provided as the last argument to each callback function */
+    void *data;
+};
+
+/* Type of stream.  Plain, or using a continuous replication protocol? */
+typedef enum {
+    XC_STREAM_PLAIN,
+    XC_STREAM_REMUS,
+    XC_STREAM_COLO,
+} xc_stream_type_t;
+
+/**
+ * This function will save a running domain.
+ *
+ * @param xch a handle to an open hypervisor interface
+ * @param io_fd the file descriptor to save a domain to
+ * @param dom the id of the domain
+ * @param flags XCFLAGS_xxx
+ * @param stream_type XC_STREAM_PLAIN if the far end of the stream
+ *        doesn't use checkpointing
+ * @param recv_fd Only used for XC_STREAM_COLO.  Contains backchannel from
+ *        the destination side.
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   uint32_t flags, struct save_callbacks *callbacks,
+                   xc_stream_type_t stream_type, int recv_fd);
+
+/* callbacks provided by xc_domain_restore */
+struct restore_callbacks {
+    /*
+     * Called once the STATIC_DATA_END record has been received/inferred.
+     *
+     * For compatibility with older streams, provides a list of static data
+     * expected to be found in the stream, which was missing.  A higher level
+     * toolstack is responsible for providing any necessary compatibiltiy.
+     */
+#define XGR_SDD_MISSING_CPUID (1 << 0)
+#define XGR_SDD_MISSING_MSR   (1 << 1)
+    int (*static_data_done)(unsigned int missing, void *data);
+
+    /* Called after a new checkpoint to suspend the guest. */
+    int (*suspend)(void *data);
+
+    /*
+     * Called after the secondary vm is ready to resume.
+     * Callback function resumes the guest & the device model,
+     * returns to xc_domain_restore.
+     */
+    int (*postcopy)(void *data);
+
+    /*
+     * A checkpoint record has been found in the stream.
+     * returns:
+     */
+#define XGR_CHECKPOINT_ERROR    0 /* Terminate processing */
+#define XGR_CHECKPOINT_SUCCESS  1 /* Continue reading more data from the stream */
+#define XGR_CHECKPOINT_FAILOVER 2 /* Failover and resume VM */
+    int (*checkpoint)(void *data);
+
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*wait_checkpoint)(void *data);
+
+    /*
+     * callback to send store gfn and console gfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(xen_pfn_t store_gfn, xen_pfn_t console_gfn,
+                            void *data);
+
+    /* to be provided as the last argument to each callback function */
+    void *data;
+};
+
+/**
+ * This function will restore a saved domain.
+ *
+ * Domain is restored in a suspended state ready to be unpaused.
+ *
+ * @param xch a handle to an open hypervisor interface
+ * @param io_fd the file descriptor to restore a domain from
+ * @param dom the id of the domain
+ * @param store_evtchn the xenstore event channel for this domain to use
+ * @param store_mfn filled with the gfn of the store page
+ * @param store_domid the backend domain for xenstore
+ * @param console_evtchn the console event channel for this domain to use
+ * @param console_mfn filled with the gfn of the console page
+ * @param console_domid the backend domain for xenconsole
+ * @param stream_type XC_STREAM_PLAIN if the far end of the stream is using
+ *        checkpointing
+ * @param callbacks non-NULL to receive a callback to restore toolstack
+ *        specific data
+ * @param send_back_fd Only used for XC_STREAM_COLO.  Contains backchannel to
+ *        the source side.
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
+                      unsigned int store_evtchn, unsigned long *store_mfn,
+                      uint32_t store_domid, unsigned int console_evtchn,
+                      unsigned long *console_mfn, uint32_t console_domid,
+                      xc_stream_type_t stream_type,
+                      struct restore_callbacks *callbacks, int send_back_fd);
+
+/**
+ * This function will create a domain for a paravirtualized Linux
+ * using file names pointing to kernel and ramdisk
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the id of the domain
+ * @parm mem_mb memory size in megabytes
+ * @parm image_name name of the kernel image file
+ * @parm ramdisk_name name of the ramdisk image file
+ * @parm cmdline command line string
+ * @parm flags domain creation flags
+ * @parm store_evtchn the store event channel for this domain to use
+ * @parm store_mfn returned with the mfn of the store page
+ * @parm console_evtchn the console event channel for this domain to use
+ * @parm conole_mfn returned with the mfn of the console page
+ * @return 0 on success, -1 on failure
+ */
+int xc_linux_build(xc_interface *xch,
+                   uint32_t domid,
+                   unsigned int mem_mb,
+                   const char *image_name,
+                   const char *ramdisk_name,
+                   const char *cmdline,
+                   const char *features,
+                   unsigned long flags,
+                   unsigned int store_evtchn,
+                   unsigned long *store_mfn,
+                   unsigned int console_evtchn,
+                   unsigned long *console_mfn);
+
+/*
+ * Sets *lockfd to -1.
+ * Has deallocated everything even on error.
+ */
+int xc_suspend_evtchn_release(xc_interface *xch,
+                              struct xenevtchn_handle *xce,
+                              uint32_t domid, int suspend_evtchn, int *lockfd);
+
+/**
+ * This function eats the initial notification.
+ * xce must not be used for anything else
+ * See xc_suspend_evtchn_init_sane re lockfd.
+ */
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch,
+                                     struct xenevtchn_handle *xce,
+                                     uint32_t domid, int port, int *lockfd);
+
+/* xce must not be used for anything else */
+int xc_await_suspend(xc_interface *xch, struct xenevtchn_handle *xce,
+                     int suspend_evtchn);
+
+/**
+ * The port will be signaled immediately after this call
+ * The caller should check the domain status and look for the next event
+ * On success, *lockfd will be set to >=0 and *lockfd must be preserved
+ * and fed to xc_suspend_evtchn_release.  (On error *lockfd is
+ * undefined and xc_suspend_evtchn_release is not allowed.)
+ */
+int xc_suspend_evtchn_init_sane(xc_interface *xch,
+                                struct xenevtchn_handle *xce,
+                                uint32_t domid, int port, int *lockfd);
+
+int xc_mark_page_online(xc_interface *xch, unsigned long start,
+                        unsigned long end, uint32_t *status);
+
+int xc_mark_page_offline(xc_interface *xch, unsigned long start,
+                          unsigned long end, uint32_t *status);
+
+int xc_query_page_offline_status(xc_interface *xch, unsigned long start,
+                                 unsigned long end, uint32_t *status);
+
+int xc_exchange_page(xc_interface *xch, uint32_t domid, xen_pfn_t mfn);
+
+
+/**
+ * Memory related information, such as PFN types, the P2M table,
+ * the guest word width and the guest page table levels.
+ */
+struct xc_domain_meminfo {
+    unsigned int pt_levels;
+    unsigned int guest_width;
+    xen_pfn_t *pfn_type;
+    xen_pfn_t *p2m_table;
+    unsigned long p2m_size;
+};
+
+int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
+                          struct xc_domain_meminfo *minfo);
+
+int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *mem);
+
+/**
+ * This function map m2p table
+ * @parm xch a handle to an open hypervisor interface
+ * @parm max_mfn the max pfn
+ * @parm prot the flags to map, such as read/write etc
+ * @parm mfn0 return the first mfn, can be NULL
+ * @return mapped m2p table on success, NULL on failure
+ */
+xen_pfn_t *xc_map_m2p(xc_interface *xch,
+                      unsigned long max_mfn,
+                      int prot,
+                      unsigned long *mfn0);
+#endif /* XENGUEST_H */
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
new file mode 100644
index 0000000000..0f24d6dd08
--- /dev/null
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -0,0 +1,665 @@
+/******************************************************************************
+ * xc_cpuid_x86.c
+ *
+ * Compute cpuid of a domain.
+ *
+ * Copyright (c) 2008, Citrix Systems, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <limits.h>
+#include "xc_private.h"
+#include "xc_bitops.h"
+#include <xen/hvm/params.h>
+#include <xen-tools/libs.h>
+
+enum {
+#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
+#include <xen/arch-x86/cpufeatureset.h>
+};
+
+#include <xen/asm/x86-vendors.h>
+
+#include <xen/lib/x86/cpu-policy.h>
+
+#define bitmaskof(idx)      (1u << ((idx) & 31))
+#define featureword_of(idx) ((idx) >> 5)
+
+int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps)
+{
+    DECLARE_SYSCTL;
+    int ret;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_levelling_caps;
+    ret = do_sysctl(xch, &sysctl);
+
+    if ( !ret )
+        *caps = sysctl.u.cpu_levelling_caps.caps;
+
+    return ret;
+}
+
+int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
+                          uint32_t *nr_features, uint32_t *featureset)
+{
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(featureset,
+                             *nr_features * sizeof(*featureset),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, featureset) )
+        return -1;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_featureset;
+    sysctl.u.cpu_featureset.index = index;
+    sysctl.u.cpu_featureset.nr_features = *nr_features;
+    set_xen_guest_handle(sysctl.u.cpu_featureset.features, featureset);
+
+    ret = do_sysctl(xch, &sysctl);
+
+    xc_hypercall_bounce_post(xch, featureset);
+
+    if ( !ret )
+        *nr_features = sysctl.u.cpu_featureset.nr_features;
+
+    return ret;
+}
+
+uint32_t xc_get_cpu_featureset_size(void)
+{
+    return FEATURESET_NR_ENTRIES;
+}
+
+const uint32_t *xc_get_static_cpu_featuremask(
+    enum xc_static_cpu_featuremask mask)
+{
+    static const uint32_t masks[][FEATURESET_NR_ENTRIES] = {
+#define MASK(x) [XC_FEATUREMASK_ ## x] = INIT_ ## x ## _FEATURES
+
+        MASK(KNOWN),
+        MASK(SPECIAL),
+        MASK(PV_MAX),
+        MASK(PV_DEF),
+        MASK(HVM_SHADOW_MAX),
+        MASK(HVM_SHADOW_DEF),
+        MASK(HVM_HAP_MAX),
+        MASK(HVM_HAP_DEF),
+
+#undef MASK
+    };
+
+    if ( (unsigned int)mask >= ARRAY_SIZE(masks) )
+        return NULL;
+
+    return masks[mask];
+}
+
+int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
+                           uint32_t *nr_msrs)
+{
+    struct xen_sysctl sysctl = {};
+    int ret;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
+
+    ret = do_sysctl(xch, &sysctl);
+
+    if ( !ret )
+    {
+        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+{
+    struct xen_sysctl sysctl = {};
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             *nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             *nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) ||
+         xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
+    sysctl.u.cpu_policy.index = index;
+    sysctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    set_xen_guest_handle(sysctl.u.cpu_policy.cpuid_policy, leaves);
+    sysctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    set_xen_guest_handle(sysctl.u.cpu_policy.msr_policy, msrs);
+
+    ret = do_sysctl(xch, &sysctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( !ret )
+    {
+        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+{
+    DECLARE_DOMCTL;
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             *nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             *nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) ||
+         xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_get_cpu_policy;
+    domctl.domain = domid;
+    domctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
+    domctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( !ret )
+    {
+        *nr_leaves = domctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = domctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
+                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
+                             uint32_t *err_msr_p)
+{
+    DECLARE_DOMCTL;
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    int ret;
+
+    if ( err_leaf_p )
+        *err_leaf_p = -1;
+    if ( err_subleaf_p )
+        *err_subleaf_p = -1;
+    if ( err_msr_p )
+        *err_msr_p = -1;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) )
+        return -1;
+
+    if ( xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_set_cpu_policy;
+    domctl.domain = domid;
+    domctl.u.cpu_policy.nr_leaves = nr_leaves;
+    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
+    domctl.u.cpu_policy.nr_msrs = nr_msrs;
+    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
+    domctl.u.cpu_policy.err_leaf = -1;
+    domctl.u.cpu_policy.err_subleaf = -1;
+    domctl.u.cpu_policy.err_msr = -1;
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( err_leaf_p )
+        *err_leaf_p = domctl.u.cpu_policy.err_leaf;
+    if ( err_subleaf_p )
+        *err_subleaf_p = domctl.u.cpu_policy.err_subleaf;
+    if ( err_msr_p )
+        *err_msr_p = domctl.u.cpu_policy.err_msr;
+
+    return ret;
+}
+
+static int compare_leaves(const void *l, const void *r)
+{
+    const xen_cpuid_leaf_t *lhs = l;
+    const xen_cpuid_leaf_t *rhs = r;
+
+    if ( lhs->leaf != rhs->leaf )
+        return lhs->leaf < rhs->leaf ? -1 : 1;
+
+    if ( lhs->subleaf != rhs->subleaf )
+        return lhs->subleaf < rhs->subleaf ? -1 : 1;
+
+    return 0;
+}
+
+static xen_cpuid_leaf_t *find_leaf(
+    xen_cpuid_leaf_t *leaves, unsigned int nr_leaves,
+    const struct xc_xend_cpuid *xend)
+{
+    const xen_cpuid_leaf_t key = { xend->leaf, xend->subleaf };
+
+    return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves);
+}
+
+static int xc_cpuid_xend_policy(
+    xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend)
+{
+    int rc;
+    xc_dominfo_t di;
+    unsigned int nr_leaves, nr_msrs;
+    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
+    /*
+     * Three full policies.  The host, domain max, and domain current for the
+     * domain type.
+     */
+    xen_cpuid_leaf_t *host = NULL, *max = NULL, *cur = NULL;
+    unsigned int nr_host, nr_max, nr_cur;
+
+    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
+         di.domid != domid )
+    {
+        ERROR("Failed to obtain d%d info", domid);
+        rc = -ESRCH;
+        goto fail;
+    }
+
+    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
+    if ( rc )
+    {
+        PERROR("Failed to obtain policy info size");
+        rc = -errno;
+        goto fail;
+    }
+
+    rc = -ENOMEM;
+    if ( (host = calloc(nr_leaves, sizeof(*host))) == NULL ||
+         (max  = calloc(nr_leaves, sizeof(*max)))  == NULL ||
+         (cur  = calloc(nr_leaves, sizeof(*cur)))  == NULL )
+    {
+        ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves);
+        goto fail;
+    }
+
+    /* Get the domain's current policy. */
+    nr_msrs = 0;
+    nr_cur = nr_leaves;
+    rc = xc_get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain d%d current policy", domid);
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Get the domain's max policy. */
+    nr_msrs = 0;
+    nr_max = nr_leaves;
+    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max
+                                              : XEN_SYSCTL_cpu_policy_pv_max,
+                                  &nr_max, max, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv");
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Get the host policy. */
+    nr_msrs = 0;
+    nr_host = nr_leaves;
+    rc = xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host,
+                                  &nr_host, host, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain host policy");
+        rc = -errno;
+        goto fail;
+    }
+
+    rc = -EINVAL;
+    for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend )
+    {
+        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend);
+        const xen_cpuid_leaf_t *max_leaf = find_leaf(max, nr_max, xend);
+        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend);
+
+        if ( cur_leaf == NULL || max_leaf == NULL || host_leaf == NULL )
+        {
+            ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->subleaf);
+            goto fail;
+        }
+
+        for ( unsigned int i = 0; i < ARRAY_SIZE(xend->policy); i++ )
+        {
+            uint32_t *cur_reg = &cur_leaf->a + i;
+            const uint32_t *max_reg = &max_leaf->a + i;
+            const uint32_t *host_reg = &host_leaf->a + i;
+
+            if ( xend->policy[i] == NULL )
+                continue;
+
+            for ( unsigned int j = 0; j < 32; j++ )
+            {
+                bool val;
+
+                if ( xend->policy[i][j] == '1' )
+                    val = true;
+                else if ( xend->policy[i][j] == '0' )
+                    val = false;
+                else if ( xend->policy[i][j] == 'x' )
+                    val = test_bit(31 - j, max_reg);
+                else if ( xend->policy[i][j] == 'k' ||
+                          xend->policy[i][j] == 's' )
+                    val = test_bit(31 - j, host_reg);
+                else
+                {
+                    ERROR("Bad character '%c' in policy[%d] string '%s'",
+                          xend->policy[i][j], i, xend->policy[i]);
+                    goto fail;
+                }
+
+                clear_bit(31 - j, cur_reg);
+                if ( val )
+                    set_bit(31 - j, cur_reg);
+            }
+        }
+    }
+
+    /* Feed the transformed currrent policy back up to Xen. */
+    rc = xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL,
+                                  &err_leaf, &err_subleaf, &err_msr);
+    if ( rc )
+    {
+        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
+               domid, err_leaf, err_subleaf, err_msr);
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Success! */
+
+ fail:
+    free(cur);
+    free(max);
+    free(host);
+
+    return rc;
+}
+
+int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
+                          const uint32_t *featureset, unsigned int nr_features,
+                          bool pae,
+                          const struct xc_xend_cpuid *xend)
+{
+    int rc;
+    xc_dominfo_t di;
+    unsigned int i, nr_leaves, nr_msrs;
+    xen_cpuid_leaf_t *leaves = NULL;
+    struct cpuid_policy *p = NULL;
+    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
+    uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {};
+    uint32_t len = ARRAY_SIZE(host_featureset);
+
+    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
+         di.domid != domid )
+    {
+        ERROR("Failed to obtain d%d info", domid);
+        rc = -ESRCH;
+        goto out;
+    }
+
+    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
+    if ( rc )
+    {
+        PERROR("Failed to obtain policy info size");
+        rc = -errno;
+        goto out;
+    }
+
+    rc = -ENOMEM;
+    if ( (leaves = calloc(nr_leaves, sizeof(*leaves))) == NULL ||
+         (p = calloc(1, sizeof(*p))) == NULL )
+        goto out;
+
+    /* Get the host policy. */
+    rc = xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host,
+                               &len, host_featureset);
+    if ( rc )
+    {
+        /* Tolerate "buffer too small", as we've got the bits we need. */
+        if ( errno == ENOBUFS )
+            rc = 0;
+        else
+        {
+            PERROR("Failed to obtain host featureset");
+            rc = -errno;
+            goto out;
+        }
+    }
+
+    /* Get the domain's default policy. */
+    nr_msrs = 0;
+    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default
+                                              : XEN_SYSCTL_cpu_policy_pv_default,
+                                  &nr_leaves, leaves, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv");
+        rc = -errno;
+        goto out;
+    }
+
+    rc = x86_cpuid_copy_from_buffer(p, leaves, nr_leaves,
+                                    &err_leaf, &err_subleaf);
+    if ( rc )
+    {
+        ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)",
+              err_leaf, err_subleaf, -rc, strerror(-rc));
+        goto out;
+    }
+
+    /*
+     * Account for feature which have been disabled by default since Xen 4.13,
+     * so migrated-in VM's don't risk seeing features disappearing.
+     */
+    if ( restore )
+    {
+        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
+
+        if ( di.hvm )
+        {
+            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
+        }
+    }
+
+    if ( featureset )
+    {
+        uint32_t disabled_features[FEATURESET_NR_ENTRIES],
+            feat[FEATURESET_NR_ENTRIES] = {};
+        static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
+        unsigned int i, b;
+
+        /*
+         * The user supplied featureset may be shorter or longer than
+         * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
+         * Longer is fine, so long as it only padded with zeros.
+         */
+        unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
+
+        /* Check for truncated set bits. */
+        rc = -EOPNOTSUPP;
+        for ( i = user_len; i < nr_features; ++i )
+            if ( featureset[i] != 0 )
+                goto out;
+
+        memcpy(feat, featureset, sizeof(*featureset) * user_len);
+
+        /* Disable deep dependencies of disabled features. */
+        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+            disabled_features[i] = ~feat[i] & deep_features[i];
+
+        for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
+        {
+            const uint32_t *dfs;
+
+            if ( !test_bit(b, disabled_features) ||
+                 !(dfs = x86_cpuid_lookup_deep_deps(b)) )
+                continue;
+
+            for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+            {
+                feat[i] &= ~dfs[i];
+                disabled_features[i] &= ~dfs[i];
+            }
+        }
+
+        cpuid_featureset_to_policy(feat, p);
+    }
+    else
+    {
+        if ( di.hvm )
+            p->basic.pae = pae;
+    }
+
+    if ( !di.hvm )
+    {
+        /*
+         * On hardware without CPUID Faulting, PV guests see real topology.
+         * As a consequence, they also need to see the host htt/cmp fields.
+         */
+        p->basic.htt       = test_bit(X86_FEATURE_HTT, host_featureset);
+        p->extd.cmp_legacy = test_bit(X86_FEATURE_CMP_LEGACY, host_featureset);
+    }
+    else
+    {
+        /*
+         * Topology for HVM guests is entirely controlled by Xen.  For now, we
+         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
+         */
+        p->basic.htt = true;
+        p->extd.cmp_legacy = false;
+
+        /*
+         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
+         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
+         * overflow.
+         */
+        if ( !(p->basic.lppp & 0x80) )
+            p->basic.lppp *= 2;
+
+        switch ( p->x86_vendor )
+        {
+        case X86_VENDOR_INTEL:
+            for ( i = 0; (p->cache.subleaf[i].type &&
+                          i < ARRAY_SIZE(p->cache.raw)); ++i )
+            {
+                p->cache.subleaf[i].cores_per_package =
+                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                p->cache.subleaf[i].threads_per_cache = 0;
+            }
+            break;
+
+        case X86_VENDOR_AMD:
+        case X86_VENDOR_HYGON:
+            /*
+             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
+             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
+             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
+             * - overflow,
+             * - going out of sync with leaf 1 EBX[23:16],
+             * - incrementing ApicIdCoreSize when it's zero (which changes the
+             *   meaning of bits 7:0).
+             *
+             * UPDATE: I addition to avoiding overflow, some
+             * proprietary operating systems have trouble with
+             * apic_id_size values greater than 7.  Limit the value to
+             * 7 for now.
+             */
+            if ( p->extd.nc < 0x7f )
+            {
+                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size < 0x7 )
+                    p->extd.apic_id_size++;
+
+                p->extd.nc = (p->extd.nc << 1) | 1;
+            }
+            break;
+        }
+
+        /*
+         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
+         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
+         * CPUID.  Xen will discard these bits if configuration hasn't been
+         * set for the domain.
+         */
+        p->extd.itsc = true;
+        p->basic.vmx = true;
+        p->extd.svm = true;
+    }
+
+    rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
+    if ( rc )
+    {
+        ERROR("Failed to serialise CPUID (%d = %s)", -rc, strerror(-rc));
+        goto out;
+    }
+
+    rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL,
+                                  &err_leaf, &err_subleaf, &err_msr);
+    if ( rc )
+    {
+        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
+               domid, err_leaf, err_subleaf, err_msr);
+        rc = -errno;
+        goto out;
+    }
+
+    if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) )
+        goto out;
+
+    rc = 0;
+
+out:
+    free(p);
+    free(leaves);
+
+    return rc;
+}
diff --git a/tools/libs/guest/xg_dom_arm.c b/tools/libs/guest/xg_dom_arm.c
new file mode 100644
index 0000000000..3f66f1d890
--- /dev/null
+++ b/tools/libs/guest/xg_dom_arm.c
@@ -0,0 +1,552 @@
+/*
+ * Xen domain builder -- ARM
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2011, Citrix Systems
+ */
+#include <inttypes.h>
+#include <assert.h>
+
+#include <xen/xen.h>
+#include <xen/io/protocols.h>
+#include <xen-tools/libs.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#define NR_MAGIC_PAGES 4
+#define CONSOLE_PFN_OFFSET 0
+#define XENSTORE_PFN_OFFSET 1
+#define MEMACCESS_PFN_OFFSET 2
+#define VUART_PFN_OFFSET 3
+
+#define LPAE_SHIFT 9
+
+#define PFN_4K_SHIFT  (0)
+#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
+#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
+#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
+
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int alloc_magic_pages(struct xc_dom_image *dom)
+{
+    int rc, i;
+    const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
+    xen_pfn_t p2m[NR_MAGIC_PAGES];
+
+    BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    for (i = 0; i < NR_MAGIC_PAGES; i++)
+        p2m[i] = base + i;
+
+    rc = xc_domain_populate_physmap_exact(
+            dom->xch, dom->guest_domid, NR_MAGIC_PAGES,
+            0, 0, p2m);
+    if ( rc < 0 )
+        return rc;
+
+    dom->console_pfn = base + CONSOLE_PFN_OFFSET;
+    dom->xenstore_pfn = base + XENSTORE_PFN_OFFSET;
+    dom->vuart_gfn = base + VUART_PFN_OFFSET;
+
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, base + MEMACCESS_PFN_OFFSET);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->vuart_gfn);
+
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
+            dom->console_pfn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
+            dom->xenstore_pfn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MONITOR_RING_PFN,
+            base + MEMACCESS_PFN_OFFSET);
+    /* allocated by toolstack */
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN,
+            dom->console_evtchn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN,
+            dom->xenstore_evtchn);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int start_info_arm(struct xc_dom_image *dom)
+{
+    DOMPRINTF_CALLED(dom->xch);
+    return 0;
+}
+
+static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
+{
+    DOMPRINTF_CALLED(dom->xch);
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int vcpu_arm32(struct xc_dom_image *dom)
+{
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
+    int rc;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc32 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
+    ctxt->user_regs.r0_usr = 0; /* SBZ */
+    /* Machine ID: We use DTB therefore no machine id */
+    ctxt->user_regs.r1_usr = 0xffffffff;
+    /* ATAGS/DTB: We currently require that the guest kernel to be
+     * using CONFIG_ARM_APPENDED_DTB. Ensure that r2 does not look
+     * like a valid pointer to a set of ATAGS or a DTB.
+     */
+    ctxt->user_regs.r2_usr = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+
+    ctxt->sctlr = SCTLR_GUEST_INIT;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_GUEST32_INIT;
+
+    ctxt->flags = VGCF_online;
+
+    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx32,
+           ctxt->user_regs.cpsr, ctxt->user_regs.pc32);
+
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
+}
+
+static int vcpu_arm64(struct xc_dom_image *dom)
+{
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
+    int rc;
+
+    DOMPRINTF_CALLED(dom->xch);
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc64 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm64/booting.txt. */
+    ctxt->user_regs.x0 = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+    ctxt->user_regs.x1 = 0;
+    ctxt->user_regs.x2 = 0;
+    ctxt->user_regs.x3 = 0;
+
+    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
+
+    ctxt->sctlr = SCTLR_GUEST_INIT;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_GUEST64_INIT;
+
+    ctxt->flags = VGCF_online;
+
+    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
+           ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
+
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int set_mode(xc_interface *xch, uint32_t domid, char *guest_type)
+{
+    static const struct {
+        char           *guest;
+        uint32_t        size;
+    } types[] = {
+        { "xen-3.0-aarch64", 64 },
+        { "xen-3.0-armv7l",  32 },
+    };
+    DECLARE_DOMCTL;
+    int i,rc;
+
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_set_address_size;
+    domctl.u.address_size.size = 0;
+
+    for ( i = 0; i < ARRAY_SIZE(types); i++ )
+        if ( !strcmp(types[i].guest, guest_type) )
+            domctl.u.address_size.size = types[i].size;
+    if ( domctl.u.address_size.size == 0 )
+    {
+        xc_dom_printf(xch, "%s: warning: unknown guest type %s",
+                      __FUNCTION__, guest_type);
+        return -EINVAL;
+    }
+
+    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
+                  guest_type, domctl.u.address_size.size);
+    rc = do_domctl(xch, &domctl);
+    if ( rc != 0 )
+        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
+                      __FUNCTION__, rc);
+    return rc;
+}
+
+/*  >0: success, *nr_pfns set to number actually populated
+ *   0: didn't try with this pfn shift (e.g. misaligned base etc)
+ *  <0: ERROR
+ */
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns,
+                             xen_pfn_t *extents)
+{
+    /* The mask for this level */
+    const uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    /* The shift, mask and next boundary for the level above this one */
+    const int next_shift = pfn_shift + LPAE_SHIFT;
+    const uint64_t next_mask = ((uint64_t)1<<next_shift)-1;
+    const xen_pfn_t next_boundary
+        = (base_pfn + ((uint64_t)1<<next_shift)) & ~next_mask;
+
+    int nr, i, count;
+    xen_pfn_t end_pfn = base_pfn + *nr_pfns;
+
+    /* No level zero super pages with current hardware */
+    if ( pfn_shift == PFN_512G_SHIFT )
+        return 0;
+
+    /* base is misaligned for this level */
+    if ( mask & base_pfn )
+        return 0;
+
+    /*
+     * If base is not aligned at the next level up then try and make
+     * it so for next time around.
+     */
+    if ( (base_pfn & next_mask) && end_pfn > next_boundary )
+        end_pfn = next_boundary;
+
+    count = ( end_pfn - base_pfn ) >> pfn_shift;
+
+    /* Nothing to allocate */
+    if ( !count )
+        return 0;
+
+    for ( i = 0 ; i < count ; i ++ )
+        extents[i] = base_pfn + (i<<pfn_shift);
+
+    nr = xc_domain_populate_physmap(dom->xch, dom->guest_domid, count,
+                                    pfn_shift, 0, extents);
+    if ( nr <= 0 ) return nr;
+    DOMPRINTF("%s: populated %#x/%#x entries with shift %d",
+              __FUNCTION__, nr, count, pfn_shift);
+
+    *nr_pfns = nr << pfn_shift;
+
+    return 1;
+}
+
+static int populate_guest_memory(struct xc_dom_image *dom,
+                                 xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
+{
+    int rc = 0;
+    xen_pfn_t allocsz, pfn, *extents;
+
+    extents = calloc(1024*1024,sizeof(xen_pfn_t));
+    if ( extents == NULL )
+    {
+        DOMPRINTF("%s: Unable to allocate extent array", __FUNCTION__);
+        return -1;
+    }
+
+    DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
+              __FUNCTION__,
+              (uint64_t)base_pfn << XC_PAGE_SHIFT,
+              (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
+              (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
+
+    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
+    {
+        allocsz = min_t(int, 1024*1024, nr_pfns - pfn);
+#if 0 /* Enable this to exercise/debug the code which tries to realign
+       * to a superpage boundary, by misaligning at the start. */
+        if ( pfn == 0 )
+        {
+            allocsz = 1;
+            rc = populate_one_size(dom, PFN_4K_SHIFT,
+                                   base_pfn + pfn, &allocsz, extents);
+            if (rc < 0) break;
+            if (rc > 0) continue;
+            /* Failed to allocate a single page? */
+            break;
+        }
+#endif
+
+        rc = populate_one_size(dom, PFN_512G_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_1G_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_2M_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_4K_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc == 0 )
+        {
+            DOMPRINTF("%s: Not enough RAM", __FUNCTION__);
+            errno = ENOMEM;
+            rc = -1;
+            goto out;
+        }
+    }
+
+out:
+    free(extents);
+    return rc < 0 ? rc : 0;
+}
+
+static int meminit(struct xc_dom_image *dom)
+{
+    int i, rc;
+    uint64_t modbase;
+
+    uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT;
+
+    const uint64_t bankbase[] = GUEST_RAM_BANK_BASES;
+    const uint64_t bankmax[] = GUEST_RAM_BANK_SIZES;
+
+    /* Convenient */
+    const uint64_t kernbase = dom->kernel_seg.vstart;
+    const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
+    const uint64_t kernsize = kernend - kernbase;
+    const uint64_t dtb_size = dom->devicetree_blob ?
+        ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
+    const uint64_t ramdisk_size = dom->modules[0].blob ?
+        ROUNDUP(dom->modules[0].size, XC_PAGE_SHIFT) : 0;
+    const uint64_t modsize = dtb_size + ramdisk_size;
+    const uint64_t ram128mb = bankbase[0] + (128<<20);
+
+    xen_pfn_t p2m_size;
+    uint64_t bank0end;
+
+    assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
+
+    if ( modsize + kernsize > bankmax[0] )
+    {
+        DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
+                  __FUNCTION__);
+        return -1;
+    }
+
+    if ( ramsize == 0 )
+    {
+        DOMPRINTF("%s: ram size is 0", __FUNCTION__);
+        return -1;
+    }
+
+    if ( ramsize > GUEST_RAM_MAX )
+    {
+        DOMPRINTF("%s: ram size is too large for guest address space: "
+                  "%"PRIx64" > %llx",
+                  __FUNCTION__, ramsize, GUEST_RAM_MAX);
+        return -1;
+    }
+
+    rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
+    if ( rc )
+        return rc;
+
+    for ( i = 0; ramsize && i < GUEST_RAM_BANKS; i++ )
+    {
+        uint64_t banksize = ramsize > bankmax[i] ? bankmax[i] : ramsize;
+
+        ramsize -= banksize;
+
+        p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT;
+
+        dom->rambank_size[i] = banksize >> XC_PAGE_SHIFT;
+    }
+
+    assert(dom->rambank_size[0] != 0);
+    assert(ramsize == 0); /* Too much RAM is rejected above */
+
+    dom->p2m_size = p2m_size;
+
+    /* setup initial p2m and allocate guest memory */
+    for ( i = 0; i < GUEST_RAM_BANKS && dom->rambank_size[i]; i++ )
+    {
+        if ((rc = populate_guest_memory(dom,
+                                        bankbase[i] >> XC_PAGE_SHIFT,
+                                        dom->rambank_size[i])))
+            return rc;
+    }
+
+    /*
+     * We try to place dtb+initrd at 128MB or if we have less RAM
+     * as high as possible. If there is no space then fallback to
+     * just before the kernel.
+     *
+     * If changing this then consider
+     * xen/arch/arm/kernel.c:place_modules as well.
+     */
+    bank0end = bankbase[0] + ((uint64_t)dom->rambank_size[0] << XC_PAGE_SHIFT);
+
+    if ( bank0end >= ram128mb + modsize && kernend < ram128mb )
+        modbase = ram128mb;
+    else if ( bank0end - modsize > kernend )
+        modbase = bank0end - modsize;
+    else if (kernbase - bankbase[0] > modsize )
+        modbase = kernbase - modsize;
+    else
+        return -1;
+
+    DOMPRINTF("%s: placing boot modules at 0x%" PRIx64, __FUNCTION__, modbase);
+
+    /*
+     * Must map DTB *after* initrd, to satisfy order of calls to
+     * xc_dom_alloc_segment in xc_dom_build_image, which must map
+     * things at monotonolically increasing addresses.
+     */
+    if ( ramdisk_size )
+    {
+        dom->modules[0].seg.vstart = modbase;
+        dom->modules[0].seg.vend = modbase + ramdisk_size;
+
+        DOMPRINTF("%s: ramdisk: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->modules[0].seg.vstart, dom->modules[0].seg.vend);
+
+        modbase += ramdisk_size;
+    }
+
+    if ( dtb_size )
+    {
+        dom->devicetree_seg.vstart = modbase;
+        dom->devicetree_seg.vend = modbase + dtb_size;
+
+        DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
+
+        modbase += dtb_size;
+    }
+
+    return 0;
+}
+
+bool xc_dom_translated(const struct xc_dom_image *dom)
+{
+    return true;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int bootearly(struct xc_dom_image *dom)
+{
+    DOMPRINTF("%s: doing nothing", __FUNCTION__);
+    return 0;
+}
+
+static int bootlate(struct xc_dom_image *dom)
+{
+    /* XXX
+     *   map shared info
+     *   map grant tables
+     *   setup shared info
+     */
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static struct xc_dom_arch xc_dom_32 = {
+    .guest_type = "xen-3.0-armv7l",
+    .native_protocol = XEN_IO_PROTO_ABI_ARM,
+    .page_shift = PAGE_SHIFT_ARM,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,
+    .start_info = start_info_arm,
+    .shared_info = shared_info_arm,
+    .vcpu = vcpu_arm32,
+    .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
+};
+
+static struct xc_dom_arch xc_dom_64 = {
+    .guest_type = "xen-3.0-aarch64",
+    .native_protocol = XEN_IO_PROTO_ABI_ARM,
+    .page_shift = PAGE_SHIFT_ARM,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,
+    .start_info = start_info_arm,
+    .shared_info = shared_info_arm,
+    .vcpu = vcpu_arm64,
+    .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
+};
+
+static void __init register_arch_hooks(void)
+{
+    xc_dom_register_arch_hooks(&xc_dom_32);
+    xc_dom_register_arch_hooks(&xc_dom_64);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libs/guest/xg_dom_armzimageloader.c b/tools/libs/guest/xg_dom_armzimageloader.c
new file mode 100644
index 0000000000..4246c8e5fa
--- /dev/null
+++ b/tools/libs/guest/xg_dom_armzimageloader.c
@@ -0,0 +1,271 @@
+/*
+ * Xen domain builder -- ARM zImage bits
+ *
+ * Parse and load ARM zImage kernel images.
+ *
+ * Copyright (C) 2012, Citrix Systems.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#include <arpa/inet.h> /* XXX ntohl is not the right function... */
+
+struct minimal_dtb_header {
+    uint32_t magic;
+    uint32_t total_size;
+    /* There are other fields but we don't use them yet. */
+};
+
+#define DTB_MAGIC 0xd00dfeed
+
+/* ------------------------------------------------------------ */
+/* 32-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE32_MAGIC_OFFSET 0x24
+#define ZIMAGE32_START_OFFSET 0x28
+#define ZIMAGE32_END_OFFSET   0x2c
+
+#define ZIMAGE32_MAGIC 0x016f2818
+
+static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
+{
+    uint32_t *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < 0x30 /*sizeof(struct setup_header)*/ )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage = (uint32_t *)dom->kernel_blob;
+    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
+{
+    uint32_t *zimage;
+    uint32_t start, entry_addr;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = (uint32_t *)dom->kernel_blob;
+
+    /* Do not load kernel at the very first RAM address */
+    v_start = rambase + 0x8000;
+
+    if ( dom->kernel_size > UINT64_MAX - v_start )
+    {
+        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_end = v_start + dom->kernel_size;
+
+    /*
+     * If start is invalid then the guest will start at some invalid
+     * address and crash, but this happens in guest context so doesn't
+     * concern us here.
+     */
+    start = zimage[ZIMAGE32_START_OFFSET/4];
+
+    if (start == 0)
+        entry_addr = v_start;
+    else
+        entry_addr = start;
+
+    /* find kernel segment */
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_end;
+
+    dom->parms.virt_entry = entry_addr;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-armv7l";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
+/* 64-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE64_MAGIC_V0 0x14000008
+#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
+
+/* linux/Documentation/arm64/booting.txt */
+struct zimage64_hdr {
+    uint32_t magic0;
+    uint32_t res0;
+    uint64_t text_offset;  /* Image load offset */
+    uint64_t res1;
+    uint64_t res2;
+    /* zImage V1 only from here */
+    uint64_t res3;
+    uint64_t res4;
+    uint64_t res5;
+    uint32_t magic1;
+    uint32_t res6;
+};
+static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < sizeof(*zimage) )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage =  dom->kernel_blob;
+    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
+         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = dom->kernel_blob;
+
+    if ( zimage->text_offset > UINT64_MAX - rambase )
+    {
+        DOMPRINTF("%s: kernel text offset is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_start = rambase + zimage->text_offset;
+
+    if ( dom->kernel_size > UINT64_MAX - v_start )
+    {
+        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_end = v_start + dom->kernel_size;
+
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_end;
+
+    /* Call the kernel at offset 0 */
+    dom->parms.virt_entry = v_start;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-aarch64";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
+/* Common zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
+{
+    void *dst;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    dst = xc_dom_seg_to_ptr(dom, &dom->kernel_seg);
+    if ( dst == NULL )
+    {
+        DOMPRINTF("%s: xc_dom_seg_to_ptr(dom, &dom->kernel_seg) => NULL",
+                  __func__);
+        return -1;
+    }
+
+    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
+              __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
+    DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
+              __func__, dom->kernel_size, dom->kernel_blob, dst);
+
+    memcpy(dst, dom->kernel_blob, dom->kernel_size);
+
+    return 0;
+}
+
+static struct xc_dom_loader zimage32_loader = {
+    .name = "Linux zImage (ARM32)",
+    .probe = xc_dom_probe_zimage32_kernel,
+    .parser = xc_dom_parse_zimage32_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
+static struct xc_dom_loader zimage64_loader = {
+    .name = "Linux zImage (ARM64)",
+    .probe = xc_dom_probe_zimage64_kernel,
+    .parser = xc_dom_parse_zimage64_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
+static void __init register_loader(void)
+{
+    xc_dom_register_loader(&zimage32_loader);
+    xc_dom_register_loader(&zimage64_loader);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libs/guest/xg_dom_binloader.c b/tools/libs/guest/xg_dom_binloader.c
new file mode 100644
index 0000000000..870a921427
--- /dev/null
+++ b/tools/libs/guest/xg_dom_binloader.c
@@ -0,0 +1,329 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Some of the field descriptions were copied from "The Multiboot
+ * Specification", Copyright 1995, 96 Bryan Ford <baford@cs.utah.edu>,
+ * Erich Stefan Boleyn <erich@uruk.org> Copyright 1999, 2000, 2001, 2002
+ * Free Software Foundation, Inc.
+ */
+
+/******************************************************************************
+ *
+ * Loads simple binary images. It's like a .COM file in MS-DOS. No headers are
+ * present. The only requirement is that it must have a xen_bin_image table
+ * somewhere in the first 8192 bytes, starting on a 32-bit aligned address.
+ * Those familiar with the multiboot specification should recognize this, it's
+ * (almost) the same as the multiboot header.
+ * The layout of the xen_bin_image table is:
+ *
+ * Offset Type Name          Note
+ * 0      uint32_t  magic         required
+ * 4      uint32_t  flags         required
+ * 8      uint32_t  checksum      required
+ * 12     uint32_t  header_addr   required
+ * 16     uint32_t  load_addr     required
+ * 20     uint32_t  load_end_addr required
+ * 24     uint32_t  bss_end_addr  required
+ * 28     uint32_t  entry_addr    required
+ *
+ * - magic
+ *   Magic number identifying the table. For images to be loaded by Xen 3, the
+ *   magic value is 0x336ec578 ("xEn3" with the 0x80 bit of the "E" set).
+ * - flags
+ *   bit 0: indicates whether the image needs to be loaded on a page boundary
+ *   bit 1: reserved, must be 0 (the multiboot spec uses this bit to indicate
+ *          that memory info should be passed to the image)
+ *   bit 2: reserved, must be 0 (the multiboot spec uses this bit to indicate
+ *          that the bootloader should pass video mode info to the image)
+ *   bit 16: reserved, must be 1 (the multiboot spec uses this bit to indicate
+ *           that the values in the fields header_addr - entry_addr are
+ *           valid)
+ *   All other bits should be set to 0.
+ * - checksum
+ *   When added to "magic" and "flags", the resulting value should be 0.
+ * - header_addr
+ *   Contains the virtual address corresponding to the beginning of the
+ *   table - the memory location at which the magic value is supposed to be
+ *   loaded. This field serves to synchronize the mapping between OS image
+ *   offsets and virtual memory addresses.
+ * - load_addr
+ *   Contains the virtual address of the beginning of the text segment. The
+ *   offset in the OS image file at which to start loading is defined by the
+ *   offset at which the table was found, minus (header addr - load addr).
+ *   load addr must be less than or equal to header addr.
+ * - load_end_addr
+ *   Contains the virtual address of the end of the data segment.
+ *   (load_end_addr - load_addr) specifies how much data to load. This implies
+ *   that the text and data segments must be consecutive in the OS image. If
+ *   this field is zero, the domain builder assumes that the text and data
+ *   segments occupy the whole OS image file.
+ * - bss_end_addr
+ *   Contains the virtual address of the end of the bss segment. The domain
+ *   builder initializes this area to zero, and reserves the memory it occupies
+ *   to avoid placing boot modules and other data relevant to the loaded image
+ *   in that area. If this field is zero, the domain builder assumes that no bss
+ *   segment is present.
+ * - entry_addr
+ *   The virtual address at which to start execution of the loaded image.
+ *
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
+#define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
+
+struct xen_bin_image_table
+{
+    uint32_t magic;
+    uint32_t flags;
+    uint32_t checksum;
+    uint32_t header_addr;
+    uint32_t load_addr;
+    uint32_t load_end_addr;
+    uint32_t bss_end_addr;
+    uint32_t entry_addr;
+};
+
+#define XEN_MULTIBOOT_MAGIC3 0x336ec578
+
+#define XEN_MULTIBOOT_FLAG_ALIGN4K     0x00000001
+#define XEN_MULTIBOOT_FLAG_NEEDMEMINFO 0x00000002
+#define XEN_MULTIBOOT_FLAG_NEEDVIDINFO 0x00000004
+#define XEN_MULTIBOOT_FLAG_ADDRSVALID  0x00010000
+#define XEN_MULTIBOOT_FLAG_PAE_SHIFT   14
+#define XEN_MULTIBOOT_FLAG_PAE_MASK    (3 << XEN_MULTIBOOT_FLAG_PAE_SHIFT)
+
+/* Flags we test for */
+#define FLAGS_MASK     ((~ 0) & (~ XEN_MULTIBOOT_FLAG_ALIGN4K) & \
+    (~ XEN_MULTIBOOT_FLAG_PAE_MASK))
+#define FLAGS_REQUIRED XEN_MULTIBOOT_FLAG_ADDRSVALID
+
+/* --------------------------------------------------------------------- */
+
+static struct xen_bin_image_table *find_table(struct xc_dom_image *dom)
+{
+    struct xen_bin_image_table *table;
+    uint32_t *probe_ptr;
+    uint32_t *probe_end;
+
+    if ( dom->kernel_size < sizeof(*table) )
+        return NULL;
+    probe_ptr = dom->kernel_blob;
+    if ( dom->kernel_size > (8192 + sizeof(*table)) )
+        probe_end = dom->kernel_blob + 8192;
+    else
+        probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table);
+
+    for ( table = NULL; probe_ptr < probe_end; probe_ptr++ )
+    {
+        if ( *probe_ptr == XEN_MULTIBOOT_MAGIC3 )
+        {
+            table = (struct xen_bin_image_table *) probe_ptr;
+            /* Checksum correct? */
+            if ( (table->magic + table->flags + table->checksum) == 0 )
+                return table;
+        }
+    }
+    return NULL;
+}
+
+static int xc_dom_probe_bin_kernel(struct xc_dom_image *dom)
+{
+    return find_table(dom) ? 0 : -EINVAL;
+}
+
+static int xc_dom_parse_bin_kernel(struct xc_dom_image *dom)
+{
+    struct xen_bin_image_table *image_info;
+    char *image = dom->kernel_blob;
+    size_t image_size = dom->kernel_size;
+    uint32_t start_addr;
+    uint32_t load_end_addr;
+    uint32_t bss_end_addr;
+    uint32_t pae_flags;
+
+    image_info = find_table(dom);
+    if ( !image_info )
+        return -EINVAL;
+
+    DOMPRINTF("%s: multiboot header fields", __FUNCTION__);
+    DOMPRINTF("  flags:         0x%" PRIx32 "", image_info->flags);
+    DOMPRINTF("  header_addr:   0x%" PRIx32 "", image_info->header_addr);
+    DOMPRINTF("  load_addr:     0x%" PRIx32 "", image_info->load_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", image_info->load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", image_info->bss_end_addr);
+    DOMPRINTF("  entry_addr:    0x%" PRIx32 "", image_info->entry_addr);
+
+    /* Check the flags */
+    if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: xen_bin_image_table flags required "
+                     "0x%08" PRIx32 " found 0x%08" PRIx32 "",
+                     __FUNCTION__, FLAGS_REQUIRED, image_info->flags & FLAGS_MASK);
+        return -EINVAL;
+    }
+
+    /* Sanity check on the addresses */
+    if ( (image_info->header_addr < image_info->load_addr) ||
+         ((char *) image_info - image) <
+         (image_info->header_addr - image_info->load_addr) )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid header_addr.",
+                     __FUNCTION__);
+        return -EINVAL;
+    }
+
+    start_addr = image_info->header_addr - ((char *)image_info - image);
+    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
+    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
+
+    DOMPRINTF("%s: calculated addresses", __FUNCTION__);
+    DOMPRINTF("  start_addr:    0x%" PRIx32 "", start_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", bss_end_addr);
+
+    if ( (start_addr + image_size) < load_end_addr )
+    {


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3X-0000rD-Ih; Wed, 09 Sep 2020 11:14:27 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3W-0000r3-JQ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:26 +0000
X-Inumbo-ID: eb8d6a55-d1f7-4c2e-92ba-2ccecd07f5de
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eb8d6a55-d1f7-4c2e-92ba-2ccecd07f5de;
 Wed, 09 Sep 2020 11:14:21 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mcW/NlmgcyhqiFj6S2lymvI/a4NavHV0/nJi6W+vG64=; b=J7dE5f7/l4IW34CV/zICgMyO3J
 X5BAA0HVekEeXkwNiL7kuGP85qlKofvbkQFp6ze/0R/eUtAvRRkOoQXNLnytJwmr+WxdfxIsQ+P0Q
 shzQIuVP9pN2e9GYtT1CCuBdT/ontVIkPDv8FsrhA4JeVCqdo73zdWyuUxc/sj4yBp9Y=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3R-000681-1z
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:21 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3Q-0001Z7-Mc
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:21 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: split libxenstore into new tools/libs/store
 directory
Message-Id: <E1kFy3Q-0001Z7-Mc@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:20 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit dd33fd2e81a0e83707cc203b974e501fa336590f
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:36 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenstore into new tools/libs/store directory
    
    There is no reason why libxenstore is not placed in the tools/libs
    directory.
    
    The common files between libxenstore and xenstored are kept in the
    tools/xenstore directory to be easily accessible by xenstore-stubdom
    which needs the xenstored files to be built.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                               |    7 +-
 stubdom/mini-os.mk                       |    2 +-
 tools/Makefile                           |    2 +-
 tools/Rules.mk                           |    5 -
 tools/libs/Makefile                      |    1 +
 tools/libs/store/Makefile                |   64 ++
 tools/libs/store/include/compat/xs.h     |    2 +
 tools/libs/store/include/compat/xs_lib.h |    2 +
 tools/libs/store/include/xenstore.h      |  290 ++++++
 tools/libs/store/libxenstore.map         |   49 +
 tools/libs/store/xs.c                    | 1473 ++++++++++++++++++++++++++++++
 tools/libs/uselibs.mk                    |    2 +
 tools/python/setup.py                    |    2 +-
 tools/xenstore/Makefile                  |   86 +-
 tools/xenstore/include/compat/xs.h       |    2 -
 tools/xenstore/include/compat/xs_lib.h   |    2 -
 tools/xenstore/include/xenstore.h        |  290 ------
 tools/xenstore/include/xenstore_lib.h    |   94 --
 tools/xenstore/xenstore_lib.h            |   94 ++
 tools/xenstore/xs.c                      | 1473 ------------------------------
 20 files changed, 1990 insertions(+), 1952 deletions(-)

diff --git a/.gitignore b/.gitignore
index eb637a98e9..1335034fd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,6 +128,12 @@ tools/libs/guest/xc_core.h
 tools/libs/guest/xc_core_arm.h
 tools/libs/guest/xc_core_x86.h
 tools/libs/guest/xc_private.h
+tools/libs/store/headers.chk
+tools/libs/store/list.h
+tools/libs/store/utils.h
+tools/libs/store/xenstore.pc
+tools/libs/store/xs_lib.c
+tools/libs/store/include/xenstore_lib.h
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -282,7 +288,6 @@ tools/xenstore/xenstore-control
 tools/xenstore/xenstore-ls
 tools/xenstore/xenstored
 tools/xenstore/xenstored_test
-tools/xenstore/xenstore.pc
 tools/xenstore/xs_tdb_dump
 tools/xentrace/xentrace_setsize
 tools/xentrace/tbctl
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index e1640a7cbc..420e9a8771 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -5,7 +5,7 @@
 # XEN_ROOT
 # MINIOS_TARGET_ARCH
 
-XENSTORE_CPPFLAGS = -isystem $(XEN_ROOT)/tools/xenstore/include
+XENSTORE_CPPFLAGS = -isystem $(XEN_ROOT)/tools/libs/store/include
 TOOLCORE_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
 TOOLLOG_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
 EVTCHN_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
diff --git a/tools/Makefile b/tools/Makefile
index f9b4012290..4a3646871c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -43,7 +43,7 @@ SUBDIRS-y += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 
 ifeq ($(CONFIG_RUMP),y)
-SUBDIRS-y := libs xenstore
+SUBDIRS-y := libs
 endif
 
 # For the sake of linking, set the sys-root
diff --git a/tools/Rules.mk b/tools/Rules.mk
index e17ac3ecc6..21aa8ea844 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -18,7 +18,6 @@ include $(XEN_ROOT)/tools/libs/uselibs.mk
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
-XEN_libxenstore    = $(XEN_ROOT)/tools/xenstore
 XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
 XEN_libxenvchan    = $(XEN_ROOT)/tools/libvchan
 
@@ -106,10 +105,6 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
 CFLAGS_libxenguest += $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory)
 
-CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
-LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_libxenstore)/libxenstore$(libextension)
-SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_libxenstore)
 ifeq ($(CONFIG_Linux),y)
 LDLIBS_libxenstore += -ldl
 endif
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index f15c1688f7..62bd8f5292 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -12,6 +12,7 @@ SUBDIRS-y += devicemodel
 SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
+SUBDIRS-y += store
 
 ifeq ($(CONFIG_RUMP),y)
 SUBDIRS-y := toolcore
diff --git a/tools/libs/store/Makefile b/tools/libs/store/Makefile
new file mode 100644
index 0000000000..4da502646e
--- /dev/null
+++ b/tools/libs/store/Makefile
@@ -0,0 +1,64 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR = 3.0
+MINOR = 3
+
+ifeq ($(CONFIG_Linux),y)
+APPEND_LDFLAGS += -ldl
+endif
+
+SRCS-y   += xs_lib.c
+SRCS-y   += xs.c
+
+LIBHEADER = xenstore.h xenstore_lib.h
+
+include ../libs.mk
+
+# Include configure output (config.h)
+CFLAGS += -include $(XEN_ROOT)/tools/config.h
+CFLAGS += $(CFLAGS_libxentoolcore)
+CFLAGS += -DXEN_LIB_STORED="\"$(XEN_LIB_STORED)\""
+CFLAGS += -DXEN_RUN_STORED="\"$(XEN_RUN_STORED)\""
+
+LINK_FILES = xs_lib.c include/xenstore_lib.h list.h utils.h
+
+$(LIB_OBJS): $(LINK_FILES)
+
+$(LINK_FILES):
+	ln -sf $(XEN_ROOT)/tools/xenstore/$(notdir $@) $@
+
+xs.opic: CFLAGS += -DUSE_PTHREAD
+ifeq ($(CONFIG_Linux),y)
+xs.opic: CFLAGS += -DUSE_DLSYM
+else
+PKG_CONFIG_REMOVE += -ldl
+endif
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstore)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+.PHONY: install
+install: install-headers
+
+.PHONY: install-headers
+install-headers:
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)/xenstore-compat
+	$(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(includedir)/xenstore-compat/xs.h
+	$(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
+	ln -sf xenstore-compat/xs.h  $(DESTDIR)$(includedir)/xs.h
+	ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(includedir)/xs_lib.h
+
+.PHONY: uninstall
+uninstall: uninstall-headers
+
+.PHONY: uninstall-headers
+uninstall-headers:
+	rm -f $(DESTDIR)$(includedir)/xs_lib.h
+	rm -f $(DESTDIR)$(includedir)/xs.h
+	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
+	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs.h
+	if [ -d $(DESTDIR)$(includedir)/xenstore-compat ]; then \
+		rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/xenstore-compat; \
+	fi
diff --git a/tools/libs/store/include/compat/xs.h b/tools/libs/store/include/compat/xs.h
new file mode 100644
index 0000000000..99cf39bb1a
--- /dev/null
+++ b/tools/libs/store/include/compat/xs.h
@@ -0,0 +1,2 @@
+#warning xs.h is deprecated use xenstore.h instead
+#include <xenstore.h>
diff --git a/tools/libs/store/include/compat/xs_lib.h b/tools/libs/store/include/compat/xs_lib.h
new file mode 100644
index 0000000000..ad81b54c0e
--- /dev/null
+++ b/tools/libs/store/include/compat/xs_lib.h
@@ -0,0 +1,2 @@
+#warning xs_lib.h is deprecated use xenstore_lib.h instead
+#include <xenstore_lib.h>
diff --git a/tools/libs/store/include/xenstore.h b/tools/libs/store/include/xenstore.h
new file mode 100644
index 0000000000..25b31881c8
--- /dev/null
+++ b/tools/libs/store/include/xenstore.h
@@ -0,0 +1,290 @@
+/* 
+    Xen Store Daemon providing simple tree-like database.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef XENSTORE_H
+#define XENSTORE_H
+
+#include <xenstore_lib.h>
+
+#define XBT_NULL 0
+
+#define XS_OPEN_READONLY	(1UL<<0)
+#define XS_OPEN_SOCKETONLY      (1UL<<1)
+
+/*
+ * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no
+ * related watch events will be delivered via xs_read_watch.  But
+ * this relies on the couple token, subpath is unique.
+ *
+ * XS_UNWATCH_FILTER clear          XS_UNWATCH_FILTER set
+ *
+ * Even after xs_unwatch, "stale"   After xs_unwatch returns, no
+ * instances of the watch event     watch events with the same
+ * may be delivered.                token and with the same subpath
+ *                                  will be delivered.
+ *
+ * A path and a subpath can be      The application must avoid
+ * register with the same token.    registering a path (/foo/) and
+ *                                  a subpath (/foo/bar) with the
+ *                                  same path until a successful
+ *                                  xs_unwatch for the first watch
+ *                                  has returned.
+ */
+#define XS_UNWATCH_FILTER     (1UL<<2)
+
+struct xs_handle;
+typedef uint32_t xs_transaction_t;
+
+/* IMPORTANT: For details on xenstore protocol limits, see
+ * docs/misc/xenstore.txt in the Xen public source repository, and use the
+ * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h.
+ */
+
+/* On failure, these routines set errno. */
+
+/* Open a connection to the xs daemon.
+ * Attempts to make a connection over the socket interface,
+ * and if it fails, then over the  xenbus interface.
+ * Mode 0 specifies read-write access, XS_OPEN_READONLY for
+ * read-only access.
+ *
+ * * Connections made with xs_open(0) (which might be shared page or
+ *   socket based) are only guaranteed to work in the parent after
+ *   fork.
+ * * Connections made with xs_open(XS_OPEN_SOCKETONLY) will be usable
+ *   in either the parent or the child after fork, but not both.
+ * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
+ *   for xs_open(0).
+ * * XS_OPEN_READONLY has no bearing on any of this.
+ *
+ * Returns a handle or NULL.
+ */
+struct xs_handle *xs_open(unsigned long flags);
+
+/* Close the connection to the xs daemon. */
+void xs_close(struct xs_handle *xsh /* NULL ok */);
+
+/* Connect to the xs daemon.
+ * Returns a handle or NULL.
+ * Deprecated, please use xs_open(0) instead
+ */
+struct xs_handle *xs_daemon_open(void);
+struct xs_handle *xs_domain_open(void);
+
+/* Connect to the xs daemon (readonly for non-root clients).
+ * Returns a handle or NULL.
+ * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
+ */
+struct xs_handle *xs_daemon_open_readonly(void);
+
+/* Close the connection to the xs daemon.
+ * Deprecated, please use xs_close() instead
+ */
+void xs_daemon_close(struct xs_handle *);
+
+/* Throw away the connection to the xs daemon, for use after fork(). */
+void xs_daemon_destroy_postfork(struct xs_handle *);
+
+/* Get contents of a directory.
+ * Returns a malloced array: call free() on it after use.
+ * Num indicates size.
+ * Returns NULL on failure.
+ */
+char **xs_directory(struct xs_handle *h, xs_transaction_t t,
+		    const char *path, unsigned int *num);
+
+/* Get the value of a single file, nul terminated.
+ * Returns a malloced value: call free() on it after use.
+ * len indicates length in bytes, not including terminator.
+ * Returns NULL on failure.
+ */
+void *xs_read(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, unsigned int *len);
+
+/* Write the value of a single file.
+ * Returns false on failure.
+ */
+bool xs_write(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, const void *data, unsigned int len);
+
+/* Create a new directory.
+ * Returns false on failure, or success if it already exists.
+ */
+bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
+	      const char *path);
+
+/* Destroy a file or directory (and children).
+ * Returns false on failure, or if it doesn't exist.
+ */
+bool xs_rm(struct xs_handle *h, xs_transaction_t t,
+	   const char *path);
+
+/* Fake function which will always return false (required to let
+ * libxenstore remain at 3.0 version.
+ */
+bool xs_restrict(struct xs_handle *h, unsigned domid);
+
+/* Get permissions of node (first element is owner, first perms is "other").
+ * Returns malloced array, or NULL: call free() after use.
+ */
+struct xs_permissions *xs_get_permissions(struct xs_handle *h,
+					  xs_transaction_t t,
+					  const char *path, unsigned int *num);
+
+/* Set permissions of node (must be owner).  Returns false on failure.
+ *
+ * Domain 0 may read / write anywhere in the store, regardless of
+ * permission settings.
+ *
+ * Note:
+ * The perms array is a list of (domid, permissions) pairs. The first
+ * element in the list specifies the owner of the list, plus the flags
+ * for every domain not explicitly specified subsequently. The
+ * subsequent entries are normal capabilities.
+ *
+ * Example C code:
+ *
+ *  struct xs_permissions perms[2];
+ *
+ *  perms[0].id = dm_domid;
+ *  perms[0].perms = XS_PERM_NONE;
+ *  perms[1].id = guest_domid;
+ *  perms[1].perms = XS_PERM_READ;
+ *
+ * It means the owner of the path is domain $dm_domid (hence it always
+ * has read and write permission), all other domains (unless specified
+ * in subsequent pair) can neither read from nor write to that
+ * path. It then specifies domain $guest_domid can read from that
+ * path.
+ */
+bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t,
+			const char *path, struct xs_permissions *perms,
+			unsigned int num_perms);
+
+/* Watch a node for changes (poll on fd to detect, or call read_watch()).
+ * When the node (or any child) changes, fd will become readable.
+ * Token is returned when watch is read, to allow matching.
+ * Returns false on failure.
+ */
+bool xs_watch(struct xs_handle *h, const char *path, const char *token);
+
+/* Return the FD to poll on to see if a watch has fired. */
+int xs_fileno(struct xs_handle *h);
+
+/* Check for node changes.  On success, returns a non-NULL pointer ret
+ * such that ret[0] and ret[1] are valid C strings, namely the
+ * triggering path (see docs/misc/xenstore.txt) and the token (from
+ * xs_watch).  On error return value is NULL setting errno.
+ * 
+ * Callers should, after xs_fileno has become readable, repeatedly
+ * call xs_check_watch until it returns NULL and sets errno to EAGAIN.
+ * (If the fd became readable, xs_check_watch is allowed to make it no
+ * longer show up as readable even if future calls to xs_check_watch
+ * will return more watch events.)
+ *
+ * After the caller is finished with the returned information it
+ * should be freed all in one go with free(ret).
+ */
+char **xs_check_watch(struct xs_handle *h);
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array containing the path and token, or NULL.
+ * Use XS_WATCH_* to access these elements.
+ * Call free() after use.
+ */
+char **xs_read_watch(struct xs_handle *h, unsigned int *num);
+
+/* Remove a watch on a node: implicitly acks any outstanding watch.
+ * Returns false on failure (no watch on that node).
+ */
+bool xs_unwatch(struct xs_handle *h, const char *path, const char *token);
+
+/* Start a transaction: changes by others will not be seen during this
+ * transaction, and changes will not be visible to others until end.
+ * Returns NULL on failure.
+ */
+xs_transaction_t xs_transaction_start(struct xs_handle *h);
+
+/* End a transaction.
+ * If abandon is true, transaction is discarded instead of committed.
+ * Returns false on failure: if errno == EAGAIN, you have to restart
+ * transaction.
+ */
+bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
+			bool abort);
+
+/* Introduce a new domain.
+ * This tells the store daemon about a shared memory page, event channel and
+ * store path associated with a domain: the domain uses these to communicate.
+ */
+bool xs_introduce_domain(struct xs_handle *h,
+			 unsigned int domid,
+			 unsigned long mfn,
+                         unsigned int eventchn); 
+
+/* Set the target of a domain
+ * This tells the store daemon that a domain is targetting another one, so
+ * it should let it tinker with it.
+ */
+bool xs_set_target(struct xs_handle *h,
+		   unsigned int domid,
+		   unsigned int target);
+
+/* Resume a domain.
+ * Clear the shutdown flag for this domain in the store.
+ */
+bool xs_resume_domain(struct xs_handle *h, unsigned int domid);
+
+/* Release a domain.
+ * Tells the store domain to release the memory page to the domain.
+ */
+bool xs_release_domain(struct xs_handle *h, unsigned int domid);
+
+/* Query the home path of a domain.  Call free() after use.
+ */
+char *xs_get_domain_path(struct xs_handle *h, unsigned int domid);
+
+/* Returns true if child is either equal to parent, or a node underneath
+ * parent; or false otherwise.  Done by string comparison, so relative and
+ * absolute pathnames never in a parent/child relationship by this
+ * definition.  Cannot fail.
+ */
+bool xs_path_is_subpath(const char *parent, const char *child);
+
+/* Return whether the domain specified has been introduced to xenstored.
+ */
+bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid);
+
+char *xs_control_command(struct xs_handle *h, const char *cmd,
+			 void *data, unsigned int len);
+/* Deprecated: use xs_control_command() instead. */
+char *xs_debug_command(struct xs_handle *h, const char *cmd,
+		       void *data, unsigned int len);
+
+int xs_suspend_evtchn_port(int domid);
+#endif /* XENSTORE_H */
+
+/*
+ * Local variables:
+ *  mode: C
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff --git a/tools/libs/store/libxenstore.map b/tools/libs/store/libxenstore.map
new file mode 100644
index 0000000000..9854305a2c
--- /dev/null
+++ b/tools/libs/store/libxenstore.map
@@ -0,0 +1,49 @@
+VERS_3.0.3 {
+	global:
+		xs_open;
+		xs_close;
+		xs_daemon_open;
+		xs_domain_open;
+		xs_daemon_open_readonly;
+		xs_daemon_close;
+		xs_daemon_destroy_postfork;
+		xs_directory;
+		xs_read;
+		xs_write;
+		xs_mkdir;
+		xs_rm;
+		xs_restrict;
+		xs_get_permissions;
+		xs_set_permissions;
+		xs_watch;
+		xs_fileno;
+		xs_check_watch;
+		xs_read_watch;
+		xs_unwatch;
+		xs_transaction_start;
+		xs_transaction_end;
+		xs_introduce_domain;
+		xs_set_target;
+		xs_resume_domain;
+		xs_release_domain;
+		xs_get_domain_path;
+		xs_path_is_subpath;
+		xs_is_domain_introduced;
+		xs_control_command;
+		xs_debug_command;
+		xs_suspend_evtchn_port;
+		xs_daemon_rootdir;
+		xs_daemon_rundir;
+		xs_daemon_socket;
+		xs_daemon_socket_ro;
+		xs_domain_dev;
+		xs_daemon_tdb;
+		xs_write_all;
+		xs_strings_to_perms;
+		xs_perm_to_string;
+		xs_count_strings;
+		expanding_buffer_ensure;
+		sanitise_value;
+		unsanitise_value;
+	local: *; /* Do not expose anything by default */
+};
diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c
new file mode 100644
index 0000000000..aa1d24b8b9
--- /dev/null
+++ b/tools/libs/store/xs.c
@@ -0,0 +1,1473 @@
+/* 
+    Xen Store Daemon interface providing simple tree-like database.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <signal.h>
+#include <stdint.h>
+#include <errno.h>
+#include "xenstore.h"
+#include "list.h"
+#include "utils.h"
+
+#include <xentoolcore_internal.h>
+
+struct xs_stored_msg {
+	struct list_head list;
+	struct xsd_sockmsg hdr;
+	char *body;
+};
+
+#ifdef USE_PTHREAD
+
+#include <pthread.h>
+
+#ifdef USE_DLSYM
+#include <dlfcn.h>
+#endif
+
+struct xs_handle {
+	/* Communications channel to xenstore daemon. */
+	int fd;
+	Xentoolcore__Active_Handle tc_ah; /* for restrict */
+
+	/*
+         * A read thread which pulls messages off the comms channel and
+         * signals waiters.
+         */
+	pthread_t read_thr;
+	int read_thr_exists;
+
+	/*
+         * A list of fired watch messages, protected by a mutex. Users can
+         * wait on the conditional variable until a watch is pending.
+         */
+	struct list_head watch_list;
+	pthread_mutex_t watch_mutex;
+	pthread_cond_t watch_condvar;
+
+	/* Clients can select() on this pipe to wait for a watch to fire. */
+	int watch_pipe[2];
+	/* Filtering watch event in unwatch function? */
+	bool unwatch_filter;
+
+	/*
+         * A list of replies. Currently only one will ever be outstanding
+         * because we serialise requests. The requester can wait on the
+         * conditional variable for its response.
+         */
+	struct list_head reply_list;
+	pthread_mutex_t reply_mutex;
+	pthread_cond_t reply_condvar;
+
+	/* One request at a time. */
+	pthread_mutex_t request_mutex;
+
+	/* Lock discipline:
+	 *  Only holder of the request lock may write to h->fd.
+	 *  Only holder of the request lock may access read_thr_exists.
+	 *  If read_thr_exists==0, only holder of request lock may read h->fd;
+	 *  If read_thr_exists==1, only the read thread may read h->fd.
+	 *  Only holder of the reply lock may access reply_list.
+	 *  Only holder of the watch lock may access watch_list.
+	 * Lock hierarchy:
+	 *  The order in which to acquire locks is
+	 *     request_mutex
+	 *     reply_mutex
+	 *     watch_mutex
+	 */
+};
+
+#define mutex_lock(m)		pthread_mutex_lock(m)
+#define mutex_unlock(m)		pthread_mutex_unlock(m)
+#define condvar_signal(c)	pthread_cond_signal(c)
+#define condvar_wait(c,m)	pthread_cond_wait(c,m)
+#define cleanup_push(f, a)	\
+    pthread_cleanup_push((void (*)(void *))(f), (void *)(a))
+/*
+ * Some definitions of pthread_cleanup_pop() are a macro starting with an
+ * end-brace. GCC then complains if we immediately precede that with a label.
+ * Hence we insert a dummy statement to appease the compiler in this situation.
+ */
+#define cleanup_pop(run)        ((void)0); pthread_cleanup_pop(run)
+
+#define read_thread_exists(h)	(h->read_thr_exists)
+
+/* Because pthread_cleanup_p* are not available when USE_PTHREAD is
+ * disabled, use these macros which convert appropriately. */
+#define cleanup_push_heap(p)        cleanup_push(free, p)
+#define cleanup_pop_heap(run, p)    cleanup_pop((run))
+
+static void *read_thread(void *arg);
+
+#else /* !defined(USE_PTHREAD) */
+
+struct xs_handle {
+	int fd;
+	Xentoolcore__Active_Handle tc_ah; /* for restrict */
+	struct list_head reply_list;
+	struct list_head watch_list;
+	/* Clients can select() on this pipe to wait for a watch to fire. */
+	int watch_pipe[2];
+	/* Filtering watch event in unwatch function? */
+	bool unwatch_filter;
+};
+
+#define mutex_lock(m)		((void)0)
+#define mutex_unlock(m)		((void)0)
+#define condvar_signal(c)	((void)0)
+#define condvar_wait(c,m)	((void)0)
+#define cleanup_push(f, a)	((void)0)
+#define cleanup_pop(run)	((void)0)
+#define read_thread_exists(h)	(0)
+
+#define cleanup_push_heap(p)        ((void)0)
+#define cleanup_pop_heap(run, p)    do { if ((run)) free(p); } while(0)
+
+#endif
+
+static int read_message(struct xs_handle *h, int nonblocking);
+
+static bool setnonblock(int fd, int nonblock) {
+	int flags = fcntl(fd, F_GETFL);
+	if (flags == -1)
+		return false;
+
+	if (nonblock)
+		flags |= O_NONBLOCK;
+	else
+		flags &= ~O_NONBLOCK;
+
+	if (fcntl(fd, F_SETFL, flags) == -1)
+		return false;
+
+	return true;
+}
+
+int xs_fileno(struct xs_handle *h)
+{
+	char c = 0;
+
+	mutex_lock(&h->watch_mutex);
+
+	if ((h->watch_pipe[0] == -1) && (pipe(h->watch_pipe) != -1)) {
+		/* Kick things off if the watch list is already non-empty. */
+		if (!list_empty(&h->watch_list))
+			while (write(h->watch_pipe[1], &c, 1) != 1)
+				continue;
+	}
+
+	mutex_unlock(&h->watch_mutex);
+
+	return h->watch_pipe[0];
+}
+
+static int get_socket(const char *connect_to)
+{
+	struct sockaddr_un addr;
+	int sock, saved_errno, flags;
+
+	sock = socket(PF_UNIX, SOCK_STREAM, 0);
+	if (sock < 0)
+		return -1;
+
+	if ((flags = fcntl(sock, F_GETFD)) < 0)
+		goto error;
+	flags |= FD_CLOEXEC;
+	if (fcntl(sock, F_SETFD, flags) < 0)
+		goto error;
+
+	addr.sun_family = AF_UNIX;
+	if(strlen(connect_to) >= sizeof(addr.sun_path)) {
+		errno = EINVAL;
+		goto error;
+	}
+	strcpy(addr.sun_path, connect_to);
+
+	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
+		goto error;
+
+	return sock;
+
+error:
+	saved_errno = errno;
+	close(sock);
+	errno = saved_errno;
+	return -1;
+}
+
+static int get_dev(const char *connect_to)
+{
+	/* We cannot open read-only because requests are writes */
+	return open(connect_to, O_RDWR);
+}
+
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) {
+    struct xs_handle *h = CONTAINER_OF(ah, *h, tc_ah);
+    return xentoolcore__restrict_by_dup2_null(h->fd);
+}
+
+static struct xs_handle *get_handle(const char *connect_to)
+{
+	struct stat buf;
+	struct xs_handle *h = NULL;
+	int saved_errno;
+
+	h = malloc(sizeof(*h));
+	if (h == NULL)
+		goto err;
+
+	memset(h, 0, sizeof(*h));
+	h->fd = -1;
+
+	h->tc_ah.restrict_callback = all_restrict_cb;
+	xentoolcore__register_active_handle(&h->tc_ah);
+
+	if (stat(connect_to, &buf) != 0)
+		goto err;
+
+	if (S_ISSOCK(buf.st_mode))
+		h->fd = get_socket(connect_to);
+	else
+		h->fd = get_dev(connect_to);
+
+	if (h->fd == -1)
+		goto err;
+
+	INIT_LIST_HEAD(&h->reply_list);
+	INIT_LIST_HEAD(&h->watch_list);
+
+	/* Watch pipe is allocated on demand in xs_fileno(). */
+	h->watch_pipe[0] = h->watch_pipe[1] = -1;
+
+	h->unwatch_filter = false;
+
+#ifdef USE_PTHREAD
+	pthread_mutex_init(&h->watch_mutex, NULL);
+	pthread_cond_init(&h->watch_condvar, NULL);
+
+	pthread_mutex_init(&h->reply_mutex, NULL);
+	pthread_cond_init(&h->reply_condvar, NULL);
+
+	pthread_mutex_init(&h->request_mutex, NULL);
+#endif
+
+	return h;
+
+err:
+	saved_errno = errno;
+
+	if (h) {
+		xentoolcore__deregister_active_handle(&h->tc_ah);
+		if (h->fd >= 0)
+			close(h->fd);
+	}
+	free(h);
+
+	errno = saved_errno;
+	return NULL;
+}
+
+struct xs_handle *xs_daemon_open(void)
+{
+	return xs_open(0);
+}
+
+struct xs_handle *xs_daemon_open_readonly(void)
+{
+	return xs_open(XS_OPEN_READONLY);
+}
+
+struct xs_handle *xs_domain_open(void)
+{
+	return xs_open(0);
+}
+
+struct xs_handle *xs_open(unsigned long flags)
+{
+	struct xs_handle *xsh = NULL;
+
+	if (flags & XS_OPEN_READONLY)
+		xsh = get_handle(xs_daemon_socket_ro());
+	else
+		xsh = get_handle(xs_daemon_socket());
+
+	if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
+		xsh = get_handle(xs_domain_dev());
+
+	if (xsh && (flags & XS_UNWATCH_FILTER))
+		xsh->unwatch_filter = true;
+
+	return xsh;
+}
+
+static void close_free_msgs(struct xs_handle *h) {
+	struct xs_stored_msg *msg, *tmsg;
+
+	list_for_each_entry_safe(msg, tmsg, &h->reply_list, list) {
+		free(msg->body);
+		free(msg);
+	}
+
+	list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+		free(msg->body);
+		free(msg);
+	}
+}
+
+static void close_fds_free(struct xs_handle *h) {
+	if (h->watch_pipe[0] != -1) {
+		close(h->watch_pipe[0]);
+		close(h->watch_pipe[1]);
+	}
+
+	xentoolcore__deregister_active_handle(&h->tc_ah);
+        close(h->fd);
+        
+	free(h);
+}
+
+void xs_daemon_destroy_postfork(struct xs_handle *h)
+{
+        close_free_msgs(h);
+        close_fds_free(h);
+}
+
+void xs_daemon_close(struct xs_handle *h)
+{
+#ifdef USE_PTHREAD
+	if (h->read_thr_exists) {
+		pthread_cancel(h->read_thr);
+		pthread_join(h->read_thr, NULL);
+	}
+#endif
+
+	mutex_lock(&h->request_mutex);
+	mutex_lock(&h->reply_mutex);
+	mutex_lock(&h->watch_mutex);
+
+        close_free_msgs(h);
+
+	mutex_unlock(&h->request_mutex);
+	mutex_unlock(&h->reply_mutex);
+	mutex_unlock(&h->watch_mutex);
+
+        close_fds_free(h);
+}
+
+void xs_close(struct xs_handle* xsh)
+{
+	if (xsh)
+		xs_daemon_close(xsh);
+}
+
+static bool read_all(int fd, void *data, unsigned int len, int nonblocking)
+	/* With nonblocking, either reads either everything requested,
+	 * or nothing. */
+{
+	if (!len)
+		return true;
+
+	if (nonblocking && !setnonblock(fd, 1))
+		return false;
+
+	while (len) {
+		int done;
+
+		done = read(fd, data, len);
+		if (done < 0) {
+			if (errno == EINTR)
+				continue;
+			goto out_false;
+		}
+		if (done == 0) {
+			/* It closed fd on us?  EBADF is appropriate. */
+			errno = EBADF;
+			goto out_false;
+		}
+		data += done;
+		len -= done;
+
+		if (nonblocking) {
+			nonblocking = 0;
+			if (!setnonblock(fd, 0))
+				goto out_false;
+		}
+	}
+
+	return true;
+
+out_false:
+	if (nonblocking)
+		setnonblock(fd, 0);
+	return false;
+}
+
+#ifdef XSTEST
+#define read_all read_all_choice
+#define xs_write_all write_all_choice
+#endif
+
+static int get_error(const char *errorstring)
+{
+	unsigned int i;
+
+	for (i = 0; !streq(errorstring, xsd_errors[i].errstring); i++)
+		if (i == ARRAY_SIZE(xsd_errors) - 1)
+			return EINVAL;
+	return xsd_errors[i].errnum;
+}
+
+/* Adds extra nul terminator, because we generally (always?) hold strings. */
+static void *read_reply(
+	struct xs_handle *h, enum xsd_sockmsg_type *type, unsigned int *len)
+{
+	struct xs_stored_msg *msg;
+	char *body;
+	int read_from_thread;
+
+	read_from_thread = read_thread_exists(h);
+
+	/* Read from comms channel ourselves if there is no reader thread. */
+	if (!read_from_thread && (read_message(h, 0) == -1))
+		return NULL;
+
+	mutex_lock(&h->reply_mutex);
+#ifdef USE_PTHREAD
+	while (list_empty(&h->reply_list) && read_from_thread && h->fd != -1)
+		condvar_wait(&h->reply_condvar, &h->reply_mutex);
+#endif
+	if (list_empty(&h->reply_list)) {
+		mutex_unlock(&h->reply_mutex);
+		errno = EINVAL;
+		return NULL;
+	}
+	msg = list_top(&h->reply_list, struct xs_stored_msg, list);
+	list_del(&msg->list);
+	assert(list_empty(&h->reply_list));
+	mutex_unlock(&h->reply_mutex);
+
+	*type = msg->hdr.type;
+	if (len)
+		*len = msg->hdr.len;
+	body = msg->body;
+
+	free(msg);
+
+	return body;
+}
+
+/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
+static void *xs_talkv(struct xs_handle *h, xs_transaction_t t,
+		      enum xsd_sockmsg_type type,
+		      const struct iovec *iovec,
+		      unsigned int num_vecs,
+		      unsigned int *len)
+{
+	struct xsd_sockmsg msg;
+	void *ret = NULL;
+	int saved_errno;
+	unsigned int i;
+	struct sigaction ignorepipe, oldact;
+
+	msg.tx_id = t;
+	msg.req_id = 0;
+	msg.type = type;
+	msg.len = 0;
+	for (i = 0; i < num_vecs; i++)
+		msg.len += iovec[i].iov_len;
+
+	if (msg.len > XENSTORE_PAYLOAD_MAX) {
+		errno = E2BIG;
+		return 0;
+	}
+
+	ignorepipe.sa_handler = SIG_IGN;
+	sigemptyset(&ignorepipe.sa_mask);
+	ignorepipe.sa_flags = 0;
+	sigaction(SIGPIPE, &ignorepipe, &oldact);
+
+	mutex_lock(&h->request_mutex);
+
+	if (!xs_write_all(h->fd, &msg, sizeof(msg)))
+		goto fail;
+
+	for (i = 0; i < num_vecs; i++)
+		if (!xs_write_all(h->fd, iovec[i].iov_base, iovec[i].iov_len))
+			goto fail;
+
+	ret = read_reply(h, &msg.type, len);
+	if (!ret)
+		goto fail;
+
+	mutex_unlock(&h->request_mutex);
+
+	sigaction(SIGPIPE, &oldact, NULL);
+	if (msg.type == XS_ERROR) {
+		saved_errno = get_error(ret);
+		free(ret);
+		errno = saved_errno;
+		return NULL;
+	}
+
+	if (msg.type != type) {
+		free(ret);
+		saved_errno = EBADF;
+		goto close_fd;
+	}
+	return ret;
+
+fail:
+	/* We're in a bad state, so close fd. */
+	saved_errno = errno;
+	mutex_unlock(&h->request_mutex);
+	sigaction(SIGPIPE, &oldact, NULL);
+close_fd:
+	close(h->fd);
+	h->fd = -1;
+	errno = saved_errno;
+	return NULL;
+}
+
+/* free(), but don't change errno. */
+static void free_no_errno(void *p)
+{
+	int saved_errno = errno;
+	free(p);
+	errno = saved_errno;
+}
+
+/* Simplified version of xs_talkv: single message. */
+static void *xs_single(struct xs_handle *h, xs_transaction_t t,
+		       enum xsd_sockmsg_type type,
+		       const char *string,
+		       unsigned int *len)
+{
+	struct iovec iovec;
+
+	iovec.iov_base = (void *)string;
+	iovec.iov_len = strlen(string) + 1;
+	return xs_talkv(h, t, type, &iovec, 1, len);
+}
+
+static bool xs_bool(char *reply)
+{
+	if (!reply)
+		return false;
+	free(reply);
+	return true;
+}
+
+static char **xs_directory_common(char *strings, unsigned int len,
+				  unsigned int *num)
+{
+	char *p, **ret;
+
+	/* Count the strings. */
+	*num = xs_count_strings(strings, len);
+
+	/* Transfer to one big alloc for easy freeing. */
+	ret = malloc(*num * sizeof(char *) + len);
+	if (!ret) {
+		free_no_errno(strings);
+		return NULL;
+	}
+	memcpy(&ret[*num], strings, len);
+	free_no_errno(strings);
+
+	strings = (char *)&ret[*num];
+	for (p = strings, *num = 0; p < strings + len; p += strlen(p) + 1)
+		ret[(*num)++] = p;
+	return ret;
+}
+
+static char **xs_directory_part(struct xs_handle *h, xs_transaction_t t,
+				const char *path, unsigned int *num)
+{
+	unsigned int off, result_len;
+	char gen[24], offstr[8];
+	struct iovec iovec[2];
+	char *result = NULL, *strings = NULL;
+
+	memset(gen, 0, sizeof(gen));
+	iovec[0].iov_base = (void *)path;
+	iovec[0].iov_len = strlen(path) + 1;
+
+	for (off = 0;;) {
+		snprintf(offstr, sizeof(offstr), "%u", off);
+		iovec[1].iov_base = (void *)offstr;
+		iovec[1].iov_len = strlen(offstr) + 1;
+		result = xs_talkv(h, t, XS_DIRECTORY_PART, iovec, 2,
+				  &result_len);
+
+		/* If XS_DIRECTORY_PART isn't supported return E2BIG. */
+		if (!result) {
+			if (errno == ENOSYS)
+				errno = E2BIG;
+			return NULL;
+		}
+
+		if (off) {
+			if (strcmp(gen, result)) {
+				free(result);
+				free(strings);
+				strings = NULL;
+				off = 0;
+				continue;
+			}
+		} else
+			strncpy(gen, result, sizeof(gen) - 1);
+
+		result_len -= strlen(result) + 1;
+		strings = realloc(strings, off + result_len);
+		memcpy(strings + off, result + strlen(result) + 1, result_len);
+		free(result);
+		off += result_len;
+
+		if (off <= 1 || strings[off - 2] == 0)
+			break;
+	}
+
+	if (off > 1)
+		off--;
+
+	return xs_directory_common(strings, off, num);
+}
+
+char **xs_directory(struct xs_handle *h, xs_transaction_t t,
+		    const char *path, unsigned int *num)
+{
+	char *strings;
+	unsigned int len;
+
+	strings = xs_single(h, t, XS_DIRECTORY, path, &len);
+	if (!strings) {
+		if (errno != E2BIG)
+			return NULL;
+		return xs_directory_part(h, t, path, num);
+	}
+
+	return xs_directory_common(strings, len, num);
+}
+
+/* Get the value of a single file, nul terminated.
+ * Returns a malloced value: call free() on it after use.
+ * len indicates length in bytes, not including the nul.
+ * Returns NULL on failure.
+ */
+void *xs_read(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, unsigned int *len)
+{
+	return xs_single(h, t, XS_READ, path, len);
+}
+
+/* Write the value of a single file.
+ * Returns false on failure.
+ */
+bool xs_write(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, const void *data, unsigned int len)
+{
+	struct iovec iovec[2];
+
+	iovec[0].iov_base = (void *)path;
+	iovec[0].iov_len = strlen(path) + 1;
+	iovec[1].iov_base = (void *)data;
+	iovec[1].iov_len = len;
+
+	return xs_bool(xs_talkv(h, t, XS_WRITE, iovec,
+				ARRAY_SIZE(iovec), NULL));
+}
+
+/* Create a new directory.
+ * Returns false on failure, or success if it already exists.
+ */
+bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
+	      const char *path)
+{
+	return xs_bool(xs_single(h, t, XS_MKDIR, path, NULL));
+}
+
+/* Destroy a file or directory (directories must be empty).
+ * Returns false on failure, or success if it doesn't exist.
+ */
+bool xs_rm(struct xs_handle *h, xs_transaction_t t,
+	   const char *path)
+{
+	return xs_bool(xs_single(h, t, XS_RM, path, NULL));
+}
+
+/* Get permissions of node (first element is owner).
+ * Returns malloced array, or NULL: call free() after use.
+ */
+struct xs_permissions *xs_get_permissions(struct xs_handle *h,
+					  xs_transaction_t t,
+					  const char *path, unsigned int *num)
+{
+	char *strings;
+	unsigned int len;
+	struct xs_permissions *ret;
+
+	strings = xs_single(h, t, XS_GET_PERMS, path, &len);
+	if (!strings)
+		return NULL;
+
+	/* Count the strings: each one perms then domid. */
+	*num = xs_count_strings(strings, len);
+
+	/* Transfer to one big alloc for easy freeing. */
+	ret = malloc(*num * sizeof(struct xs_permissions));
+	if (!ret) {
+		free_no_errno(strings);
+		return NULL;
+	}
+
+	if (!xs_strings_to_perms(ret, *num, strings)) {
+		free_no_errno(ret);
+		ret = NULL;
+	}
+
+	free(strings);
+	return ret;
+}
+
+/* Set permissions of node (must be owner).
+ * Returns false on failure.
+ */
+bool xs_set_permissions(struct xs_handle *h,
+			xs_transaction_t t,
+			const char *path,
+			struct xs_permissions *perms,
+			unsigned int num_perms)
+{
+	unsigned int i;
+	struct iovec iov[1+num_perms];
+
+	iov[0].iov_base = (void *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	
+	for (i = 0; i < num_perms; i++) {
+		char buffer[MAX_STRLEN(unsigned int)+1];
+
+		if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
+			goto unwind;
+
+		iov[i+1].iov_base = strdup(buffer);
+		iov[i+1].iov_len = strlen(buffer) + 1;
+		if (!iov[i+1].iov_base)
+			goto unwind;
+	}
+
+	if (!xs_bool(xs_talkv(h, t, XS_SET_PERMS, iov, 1+num_perms, NULL)))
+		goto unwind;
+	for (i = 0; i < num_perms; i++)
+		free(iov[i+1].iov_base);
+	return true;
+
+unwind:
+	num_perms = i;
+	for (i = 0; i < num_perms; i++)
+		free_no_errno(iov[i+1].iov_base);
+	return false;
+}
+
+/* Always return false a functionality has been removed in Xen 4.9 */
+bool xs_restrict(struct xs_handle *h, unsigned domid)
+{
+	return false;
+}
+
+/* Watch a node for changes (poll on fd to detect, or call read_watch()).
+ * When the node (or any child) changes, fd will become readable.
+ * Token is returned when watch is read, to allow matching.
+ * Returns false on failure.
+ */
+bool xs_watch(struct xs_handle *h, const char *path, const char *token)
+{
+	struct iovec iov[2];
+
+#ifdef USE_PTHREAD
+#define DEFAULT_THREAD_STACKSIZE (16 * 1024)
+#define READ_THREAD_STACKSIZE 					\
+	((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? 	\
+	PTHREAD_STACK_MIN : DEFAULT_THREAD_STACKSIZE)
+
+	/* We dynamically create a reader thread on demand. */
+	mutex_lock(&h->request_mutex);
+	if (!h->read_thr_exists) {
+		sigset_t set, old_set;
+		pthread_attr_t attr;
+		static size_t stack_size;
+#ifdef USE_DLSYM
+		size_t (*getsz)(pthread_attr_t *attr);
+#endif
+
+		if (pthread_attr_init(&attr) != 0) {
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+		if (!stack_size) {
+#ifdef USE_DLSYM
+			getsz = dlsym(RTLD_DEFAULT, "__pthread_get_minstack");
+			if (getsz)
+				stack_size = getsz(&attr);
+#endif
+			if (stack_size < READ_THREAD_STACKSIZE)
+				stack_size = READ_THREAD_STACKSIZE;
+		}
+		if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
+			pthread_attr_destroy(&attr);
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+
+		sigfillset(&set);
+		pthread_sigmask(SIG_SETMASK, &set, &old_set);
+
+		if (pthread_create(&h->read_thr, &attr, read_thread, h) != 0) {
+			pthread_sigmask(SIG_SETMASK, &old_set, NULL);
+			pthread_attr_destroy(&attr);
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+		h->read_thr_exists = 1;
+		pthread_sigmask(SIG_SETMASK, &old_set, NULL);
+		pthread_attr_destroy(&attr);
+	}
+	mutex_unlock(&h->request_mutex);
+#endif
+
+	iov[0].iov_base = (void *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	iov[1].iov_base = (void *)token;
+	iov[1].iov_len = strlen(token) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_WATCH, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+
+/* Clear the pipe token if there are no more pending watchs.
+ * We suppose the watch_mutex is already taken.
+ */
+static void xs_maybe_clear_watch_pipe(struct xs_handle *h)
+{
+	char c;
+
+	if (list_empty(&h->watch_list) && (h->watch_pipe[0] != -1))
+		while (read(h->watch_pipe[0], &c, 1) != 1)
+			continue;
+}
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array of two pointers: path and token, or NULL.
+ * Call free() after use.
+ */
+static char **read_watch_internal(struct xs_handle *h, unsigned int *num,
+				  int nonblocking)
+{
+	struct xs_stored_msg *msg;
+	char **ret, *strings;
+	unsigned int num_strings, i;
+
+	mutex_lock(&h->watch_mutex);
+
+#ifdef USE_PTHREAD
+	/* Wait on the condition variable for a watch to fire.
+	 * If the reader thread doesn't exist yet, then that's because
+	 * we haven't called xs_watch.	Presumably the application
+	 * will do so later; in the meantime we just block.
+	 */
+	while (list_empty(&h->watch_list) && h->fd != -1) {
+		if (nonblocking) {
+			mutex_unlock(&h->watch_mutex);
+			errno = EAGAIN;
+			return 0;
+		}
+		condvar_wait(&h->watch_condvar, &h->watch_mutex);
+	}
+#else /* !defined(USE_PTHREAD) */
+	/* Read from comms channel ourselves if there are no threads
+	 * and therefore no reader thread. */
+
+	assert(!read_thread_exists(h)); /* not threadsafe but worth a check */
+	if ((read_message(h, nonblocking) == -1))
+		return NULL;
+
+#endif /* !defined(USE_PTHREAD) */
+
+	if (list_empty(&h->watch_list)) {
+		mutex_unlock(&h->watch_mutex);
+		errno = EINVAL;
+		return NULL;
+	}
+	msg = list_top(&h->watch_list, struct xs_stored_msg, list);
+	list_del(&msg->list);
+
+	xs_maybe_clear_watch_pipe(h);
+	mutex_unlock(&h->watch_mutex);
+
+	assert(msg->hdr.type == XS_WATCH_EVENT);
+
+	strings     = msg->body;
+	num_strings = xs_count_strings(strings, msg->hdr.len);
+
+	ret = malloc(sizeof(char*) * num_strings + msg->hdr.len);
+	if (!ret) {
+		free_no_errno(strings);
+		free_no_errno(msg);
+		return NULL;
+	}
+
+	ret[0] = (char *)(ret + num_strings);
+	memcpy(ret[0], strings, msg->hdr.len);
+
+	free(strings);
+	free(msg);
+
+	for (i = 1; i < num_strings; i++)
+		ret[i] = ret[i - 1] + strlen(ret[i - 1]) + 1;
+
+	*num = num_strings;
+
+	return ret;
+}
+
+char **xs_check_watch(struct xs_handle *h)
+{
+	unsigned int num;
+	char **ret;
+	ret = read_watch_internal(h, &num, 1);
+	if (ret) assert(num >= 2);
+	return ret;
+}
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array of two pointers: path and token, or NULL.
+ * Call free() after use.
+ */
+char **xs_read_watch(struct xs_handle *h, unsigned int *num)
+{
+	return read_watch_internal(h, num, 0);
+}
+
+/* Remove a watch on a node.
+ * Returns false on failure (no watch on that node).
+ */
+bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)
+{
+	struct iovec iov[2];
+	struct xs_stored_msg *msg, *tmsg;
+	bool res;
+	char *s, *p;
+	unsigned int i;
+	char *l_token, *l_path;
+
+	iov[0].iov_base = (char *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	iov[1].iov_base = (char *)token;
+	iov[1].iov_len = strlen(token) + 1;
+
+	res = xs_bool(xs_talkv(h, XBT_NULL, XS_UNWATCH, iov,
+			       ARRAY_SIZE(iov), NULL));
+
+	if (!h->unwatch_filter) /* Don't filter the watch list */
+		return res;
+
+
+	/* Filter the watch list to remove potential message */
+	mutex_lock(&h->watch_mutex);
+
+	if (list_empty(&h->watch_list)) {
+		mutex_unlock(&h->watch_mutex);
+		return res;
+	}
+
+	list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+		assert(msg->hdr.type == XS_WATCH_EVENT);
+
+		s = msg->body;
+
+		l_token = NULL;
+		l_path = NULL;
+
+		for (p = s, i = 0; p < msg->body + msg->hdr.len; p++) {
+			if (*p == '\0')
+			{
+				if (i == XS_WATCH_TOKEN)
+					l_token = s;
+				else if (i == XS_WATCH_PATH)
+					l_path = s;
+				i++;
+				s = p + 1;
+			}
+		}
+
+		if (l_token && !strcmp(token, l_token) &&
+		    l_path && xs_path_is_subpath(path, l_path)) {
+			list_del(&msg->list);
+			free(msg);
+		}
+	}
+
+	xs_maybe_clear_watch_pipe(h);
+
+	mutex_unlock(&h->watch_mutex);
+
+	return res;
+}
+
+/* Start a transaction: changes by others will not be seen during this
+ * transaction, and changes will not be visible to others until end.
+ * Returns XBT_NULL on failure.
+ */
+xs_transaction_t xs_transaction_start(struct xs_handle *h)
+{
+	char *id_str;
+	xs_transaction_t id;
+
+	id_str = xs_single(h, XBT_NULL, XS_TRANSACTION_START, "", NULL);
+	if (id_str == NULL)
+		return XBT_NULL;
+
+	id = strtoul(id_str, NULL, 0);
+	free(id_str);
+
+	return id;
+}
+
+/* End a transaction.
+ * If abandon is true, transaction is discarded instead of committed.
+ * Returns false on failure, which indicates an error: transactions will
+ * not fail spuriously.
+ */
+bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
+			bool abort)
+{
+	char abortstr[2];
+
+	if (abort)
+		strcpy(abortstr, "F");
+	else
+		strcpy(abortstr, "T");
+	
+	return xs_bool(xs_single(h, t, XS_TRANSACTION_END, abortstr, NULL));
+}
+
+/* Introduce a new domain.
+ * This tells the store daemon about a shared memory page and event channel
+ * associated with a domain: the domain uses these to communicate.
+ */
+bool xs_introduce_domain(struct xs_handle *h,
+			 unsigned int domid, unsigned long mfn,
+			 unsigned int eventchn)
+{
+	char domid_str[MAX_STRLEN(domid)];
+	char mfn_str[MAX_STRLEN(mfn)];
+	char eventchn_str[MAX_STRLEN(eventchn)];
+	struct iovec iov[3];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+	snprintf(mfn_str, sizeof(mfn_str), "%lu", mfn);
+	snprintf(eventchn_str, sizeof(eventchn_str), "%u", eventchn);
+
+	iov[0].iov_base = domid_str;
+	iov[0].iov_len = strlen(domid_str) + 1;
+	iov[1].iov_base = mfn_str;
+	iov[1].iov_len = strlen(mfn_str) + 1;
+	iov[2].iov_base = eventchn_str;
+	iov[2].iov_len = strlen(eventchn_str) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_INTRODUCE, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+bool xs_set_target(struct xs_handle *h,
+			 unsigned int domid, unsigned int target)
+{
+	char domid_str[MAX_STRLEN(domid)];
+	char target_str[MAX_STRLEN(target)];
+	struct iovec iov[2];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+	snprintf(target_str, sizeof(target_str), "%u", target);
+
+	iov[0].iov_base = domid_str;
+	iov[0].iov_len = strlen(domid_str) + 1;
+	iov[1].iov_base = target_str;
+	iov[1].iov_len = strlen(target_str) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_SET_TARGET, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+static void * single_with_domid(struct xs_handle *h,
+				enum xsd_sockmsg_type type,
+				unsigned int domid)
+{
+	char domid_str[MAX_STRLEN(domid)];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+
+	return xs_single(h, XBT_NULL, type, domid_str, NULL);
+}
+
+bool xs_release_domain(struct xs_handle *h, unsigned int domid)
+{
+	return xs_bool(single_with_domid(h, XS_RELEASE, domid));
+}
+
+/* clear the shutdown bit for the given domain */
+bool xs_resume_domain(struct xs_handle *h, unsigned int domid)
+{
+	return xs_bool(single_with_domid(h, XS_RESUME, domid));
+}
+
+char *xs_get_domain_path(struct xs_handle *h, unsigned int domid)
+{
+	char domid_str[MAX_STRLEN(domid)];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+
+	return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
+}
+
+bool xs_path_is_subpath(const char *parent, const char *child)
+{
+        size_t childlen = strlen(child);
+        size_t parentlen = strlen(parent);
+
+	if (childlen < parentlen)
+		return false;
+
+	if (memcmp(child, parent, parentlen))
+		return false;
+
+	if (childlen > parentlen && child[parentlen] != '/')
+		return false;
+
+	return true;
+}
+
+bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid)
+{
+	char *domain = single_with_domid(h, XS_IS_DOMAIN_INTRODUCED, domid);
+	int rc = strcmp("F", domain);
+
+	free(domain);
+	return rc;
+}
+
+int xs_suspend_evtchn_port(int domid)
+{
+    char path[128];
+    char *portstr;
+    int port;
+    unsigned int plen;
+    struct xs_handle *xs;
+
+    xs = xs_daemon_open();
+    if (!xs)
+        return -1;
+
+    sprintf(path, "/local/domain/%d/device/suspend/event-channel", domid);
+    portstr = xs_read(xs, XBT_NULL, path, &plen);
+    xs_daemon_close(xs);
+
+    if (!portstr || !plen) {
+        port = -1;
+        goto out;
+    }
+
+    port = atoi(portstr);
+
+out:
+    free(portstr);
+    return port;
+}
+
+char *xs_control_command(struct xs_handle *h, const char *cmd,
+			 void *data, unsigned int len)
+{
+	struct iovec iov[2];
+
+	iov[0].iov_base = (void *)cmd;
+	iov[0].iov_len = strlen(cmd) + 1;
+	iov[1].iov_base = data;
+	iov[1].iov_len = len;
+
+	return xs_talkv(h, XBT_NULL, XS_CONTROL, iov,
+			ARRAY_SIZE(iov), NULL);
+}
+
+char *xs_debug_command(struct xs_handle *h, const char *cmd,
+		       void *data, unsigned int len)
+{
+	return xs_control_command(h, cmd, data, len);
+}
+
+static int read_message(struct xs_handle *h, int nonblocking)
+{
+	/* IMPORTANT: It is forbidden to call this function without
+	 * acquiring the request lock and checking that h->read_thr_exists
+	 * is false.  See "Lock discipline" in struct xs_handle, above. */
+
+	/* If nonblocking==1, this function will always read either
+	 * nothing, returning -1 and setting errno==EAGAIN, or we read
+	 * whole amount requested.  Ie as soon as we have the start of
+	 * the message we block until we get all of it.
+	 */
+         
+	struct xs_stored_msg *msg = NULL;
+	char *body = NULL;
+	int saved_errno = 0;
+	int ret = -1;
+
+	/* Allocate message structure and read the message header. */
+	msg = malloc(sizeof(*msg));
+	if (msg == NULL)
+		goto error;
+	cleanup_push_heap(msg);
+	if (!read_all(h->fd, &msg->hdr, sizeof(msg->hdr), nonblocking)) { /* Cancellation point */
+		saved_errno = errno;
+		goto error_freemsg;
+	}
+
+	/* Sanity check message body length. */
+	if (msg->hdr.len > XENSTORE_PAYLOAD_MAX) {
+		saved_errno = E2BIG;
+		goto error_freemsg;
+	}
+
+	/* Allocate and read the message body. */
+	body = msg->body = malloc(msg->hdr.len + 1);
+	if (body == NULL)
+		goto error_freemsg;
+	cleanup_push_heap(body);
+	if (!read_all(h->fd, body, msg->hdr.len, 0)) { /* Cancellation point */
+		saved_errno = errno;
+		goto error_freebody;
+	}
+
+	body[msg->hdr.len] = '\0';
+
+	if (msg->hdr.type == XS_WATCH_EVENT) {
+		mutex_lock(&h->watch_mutex);
+		cleanup_push(pthread_mutex_unlock, &h->watch_mutex);
+
+		/* Kick users out of their select() loop. */
+		if (list_empty(&h->watch_list) &&
+		    (h->watch_pipe[1] != -1))
+			while (write(h->watch_pipe[1], body, 1) != 1) /* Cancellation point */
+				continue;
+
+		list_add_tail(&msg->list, &h->watch_list);
+
+		condvar_signal(&h->watch_condvar);
+
+		cleanup_pop(1);
+	} else {
+		mutex_lock(&h->reply_mutex);
+
+		/* There should only ever be one response pending! */
+		if (!list_empty(&h->reply_list)) {
+			mutex_unlock(&h->reply_mutex);
+			saved_errno = EEXIST;
+			goto error_freebody;
+		}
+
+		list_add_tail(&msg->list, &h->reply_list);
+		condvar_signal(&h->reply_condvar);
+
+		mutex_unlock(&h->reply_mutex);
+	}
+
+	ret = 0;
+
+error_freebody:
+	cleanup_pop_heap(ret == -1, body);
+error_freemsg:
+	cleanup_pop_heap(ret == -1, msg);
+error:
+	errno = saved_errno;
+
+	return ret;
+}
+
+#ifdef USE_PTHREAD
+static void *read_thread(void *arg)
+{
+	struct xs_handle *h = arg;
+	int fd;
+
+	while (read_message(h, 0) != -1)
+		continue;
+
+	/* An error return from read_message leaves the socket in an undefined
+	 * state; we might have read only the header and not the message after
+	 * it, or (more commonly) the other end has closed the connection.
+	 * Since further communication is unsafe, close the socket.
+	 */
+	fd = h->fd;
+	h->fd = -1;
+	close(fd);
+
+	/* wake up all waiters */
+	pthread_mutex_lock(&h->reply_mutex);
+	pthread_cond_broadcast(&h->reply_condvar);
+	pthread_mutex_unlock(&h->reply_mutex);
+
+	pthread_mutex_lock(&h->watch_mutex);
+	pthread_cond_broadcast(&h->watch_condvar);
+	pthread_mutex_unlock(&h->watch_mutex);
+
+	return NULL;
+}
+#endif
+
+char *expanding_buffer_ensure(struct expanding_buffer *ebuf, int min_avail)
+{
+	int want;
+	char *got;
+
+	if (ebuf->avail >= min_avail)
+		return ebuf->buf;
+
+	if (min_avail >= INT_MAX/3)
+		return 0;
+
+	want = ebuf->avail + min_avail + 10;
+	got = realloc(ebuf->buf, want);
+	if (!got)
+		return 0;
+
+	ebuf->buf = got;
+	ebuf->avail = want;
+	return ebuf->buf;
+}
+
+char *sanitise_value(struct expanding_buffer *ebuf,
+		     const char *val, unsigned len)
+{
+	int used, remain, c;
+	unsigned char *ip;
+
+#define ADD(c) (ebuf->buf[used++] = (c))
+#define ADDF(f,c) (used += sprintf(ebuf->buf+used, (f), (c)))
+
+	assert(len < INT_MAX/5);
+
+	ip = (unsigned char *)val;
+	used = 0;
+	remain = len;
+
+	if (!expanding_buffer_ensure(ebuf, remain + 1))
+		return NULL;
+
+	while (remain-- > 0) {
+		c= *ip++;
+
+		if (c >= ' ' && c <= '~' && c != '\\') {
+			ADD(c);
+			continue;
+		}
+
+		if (!expanding_buffer_ensure(ebuf, used + remain + 5))
+			/* for "<used>\\nnn<remain>\0" */
+			return 0;
+
+		ADD('\\');
+		switch (c) {
+		case '\t':  ADD('t');   break;
+		case '\n':  ADD('n');   break;
+		case '\r':  ADD('r');   break;
+		case '\\':  ADD('\\');  break;
+		default:
+			if (c < 010) ADDF("%03o", c);
+			else         ADDF("x%02x", c);
+		}
+	}
+
+	ADD(0);
+	assert(used <= ebuf->avail);
+	return ebuf->buf;
+
+#undef ADD
+#undef ADDF
+}
+
+void unsanitise_value(char *out, unsigned *out_len_r, const char *in)
+{
+	const char *ip;
+	char *op;
+	unsigned c;
+	int n;
+
+	for (ip = in, op = out; (c = *ip++); *op++ = c) {
+		if (c == '\\') {
+			c = *ip++;
+
+#define GETF(f) do {					\
+			n = 0;				\
+			sscanf(ip, f "%n", &c, &n);	\
+			ip += n;			\
+		} while (0)
+
+			switch (c) {
+			case 't':              c= '\t';            break;
+			case 'n':              c= '\n';            break;
+			case 'r':              c= '\r';            break;
+			case '\\':             c= '\\';            break;
+			case 'x':                    GETF("%2x");  break;
+			case '0': case '4':
+			case '1': case '5':
+			case '2': case '6':
+			case '3': case '7':    --ip; GETF("%3o");  break;
+			case 0:                --ip;               break;
+			default:;
+			}
+#undef GETF
+		}
+	}
+
+	*op = 0;
+
+	if (out_len_r)
+		*out_len_r = op - out;
+}
+
+/*
+ * Local variables:
+ *  mode: C
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk
index 9619c576ba..a0fe0402ff 100644
--- a/tools/libs/uselibs.mk
+++ b/tools/libs/uselibs.mk
@@ -20,3 +20,5 @@ LIBS_LIBS += ctrl
 USELIBS_ctrl := toollog call evtchn gnttab foreignmemory devicemodel
 LIBS_LIBS += guest
 USELIBS_guest := evtchn ctrl
+LIBS_LIBS += store
+USELIBS_store := toolcore
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 24b284af39..8254464aff 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -11,7 +11,7 @@ PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
 PATH_LIBXENEVTCHN = XEN_ROOT + "/tools/libs/evtchn"
 PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
 PATH_LIBXL    = XEN_ROOT + "/tools/libxl"
-PATH_XENSTORE = XEN_ROOT + "/tools/xenstore"
+PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 574be8d15c..9a0f0d012d 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -34,17 +34,7 @@ XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o
 XENSTORED_OBJS += $(XENSTORED_OBJS_y)
 LDLIBS_xenstored += -lrt
 
-ifneq ($(XENSTORE_STATIC_CLIENTS),y)
-LIBXENSTORE := libxenstore.so
-else
-LIBXENSTORE := libxenstore.a
-xenstore xenstore-control: CFLAGS += -static
-endif
-
-ALL_TARGETS = libxenstore.a clients
-ifneq ($(nosharedlibs),y)
-ALL_TARGETS += libxenstore.so
-endif
+ALL_TARGETS = clients
 ifeq ($(XENSTORE_XENSTORED),y)
 ALL_TARGETS += xs_tdb_dump xenstored
 endif
@@ -87,64 +77,21 @@ xenstored.a: $(XENSTORED_OBJS)
 $(CLIENTS): xenstore
 	ln -f xenstore $@
 
-xenstore: xenstore_client.o $(LIBXENSTORE)
+xenstore: xenstore_client.o
 	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
-xenstore-control: xenstore_control.o $(LIBXENSTORE)
+xenstore-control: xenstore_control.o
 	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
 xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
 	$(CC) $^ $(LDFLAGS) -o $@ $(APPEND_LDFLAGS)
 
-libxenstore.so: libxenstore.so.$(MAJOR)
-	ln -sf $< $@
-libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
-	ln -sf $< $@
-
-xs.opic: CFLAGS += -DUSE_PTHREAD
-ifeq ($(CONFIG_Linux),y)
-xs.opic: CFLAGS += -DUSE_DLSYM
-libxenstore.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += -ldl
-PKG_CONFIG_LIBSPRIV := -ldl
-endif
-
-libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
-
-libxenstore.a: xs.o xs_lib.o
-	$(AR) rcs $@ $^
-
-PKG_CONFIG := xenstore.pc
-PKG_CONFIG_NAME := Xenstore
-PKG_CONFIG_DESC := The Xenstore library for Xen hypervisor
-PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
-PKG_CONFIG_USELIBS := $(SHLIB_libxenstore)
-PKG_CONFIG_LIB := xenstore
-PKG_CONFIG_REQPRIV := xenevtchn,xencontrol,xengnttab,xentoolcore
-
-ifneq ($(CONFIG_LIBXC_MINIOS),y)
-PKG_CONFIG_INST := $(PKG_CONFIG)
-$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
-$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
-$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
-endif
-
-PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
-
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstore)/include
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
-
-$(LIBXENSTORE): $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
-
 .PHONY: clean
 clean:
-	rm -f *.a *.o *.opic *.so* xenstored_probes.h
+	rm -f *.a *.o xenstored_probes.h
 	rm -f xenstored xs_random xs_stress xs_crashme
 	rm -f xs_tdb_dump xenstore-control init-xenstore-domain
 	rm -f xenstore $(CLIENTS)
-	rm -f xenstore.pc
 	$(RM) $(DEPS_RM)
 
 .PHONY: distclean
@@ -161,8 +108,6 @@ tarball: clean
 .PHONY: install
 install: all
 	$(INSTALL_DIR) $(DESTDIR)$(bindir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)/xenstore-compat
 ifeq ($(XENSTORE_XENSTORED),y)
 	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
 	$(INSTALL_DIR) $(DESTDIR)$(XEN_LIB_STORED)
@@ -173,32 +118,9 @@ endif
 	set -e ; for c in $(CLIENTS) ; do \
 		ln -f $(DESTDIR)$(bindir)/xenstore $(DESTDIR)$(bindir)/$${c} ; \
 	done
-	$(INSTALL_DIR) $(DESTDIR)$(libdir)
-	$(INSTALL_SHLIB) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
-	ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
-	ln -sf libxenstore.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenstore.so
-	$(INSTALL_DATA) libxenstore.a $(DESTDIR)$(libdir)
-	$(INSTALL_DATA) include/xenstore.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) include/xenstore_lib.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(includedir)/xenstore-compat/xs.h
-	$(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
-	ln -sf xenstore-compat/xs.h  $(DESTDIR)$(includedir)/xs.h
-	ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(includedir)/xs_lib.h
-	$(INSTALL_DATA) xenstore.pc $(DESTDIR)$(PKG_INSTALLDIR)
 
 .PHONY: uninstall
 uninstall:
-	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenstore.pc
-	rm -f $(DESTDIR)$(includedir)/xs_lib.h
-	rm -f $(DESTDIR)$(includedir)/xs.h
-	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
-	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs.h
-	rm -f $(DESTDIR)$(includedir)/xenstore_lib.h
-	rm -f $(DESTDIR)$(includedir)/xenstore.h
-	rm -f $(DESTDIR)$(libdir)/libxenstore.a
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR).$(MINOR)
 	rm -f $(addprefix $(DESTDIR)$(bindir)/, $(CLIENTS))
 	rm -f $(DESTDIR)$(bindir)/xenstore
 	rm -f $(DESTDIR)$(bindir)/xenstore-control
diff --git a/tools/xenstore/include/compat/xs.h b/tools/xenstore/include/compat/xs.h
deleted file mode 100644
index 99cf39bb1a..0000000000
--- a/tools/xenstore/include/compat/xs.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#warning xs.h is deprecated use xenstore.h instead
-#include <xenstore.h>
diff --git a/tools/xenstore/include/compat/xs_lib.h b/tools/xenstore/include/compat/xs_lib.h
deleted file mode 100644
index ad81b54c0e..0000000000
--- a/tools/xenstore/include/compat/xs_lib.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#warning xs_lib.h is deprecated use xenstore_lib.h instead
-#include <xenstore_lib.h>
diff --git a/tools/xenstore/include/xenstore.h b/tools/xenstore/include/xenstore.h
deleted file mode 100644
index 25b31881c8..0000000000
--- a/tools/xenstore/include/xenstore.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/* 
-    Xen Store Daemon providing simple tree-like database.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef XENSTORE_H
-#define XENSTORE_H
-
-#include <xenstore_lib.h>
-
-#define XBT_NULL 0
-
-#define XS_OPEN_READONLY	(1UL<<0)
-#define XS_OPEN_SOCKETONLY      (1UL<<1)
-
-/*
- * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no
- * related watch events will be delivered via xs_read_watch.  But
- * this relies on the couple token, subpath is unique.
- *
- * XS_UNWATCH_FILTER clear          XS_UNWATCH_FILTER set
- *
- * Even after xs_unwatch, "stale"   After xs_unwatch returns, no
- * instances of the watch event     watch events with the same
- * may be delivered.                token and with the same subpath
- *                                  will be delivered.
- *
- * A path and a subpath can be      The application must avoid
- * register with the same token.    registering a path (/foo/) and
- *                                  a subpath (/foo/bar) with the
- *                                  same path until a successful
- *                                  xs_unwatch for the first watch
- *                                  has returned.
- */
-#define XS_UNWATCH_FILTER     (1UL<<2)
-
-struct xs_handle;
-typedef uint32_t xs_transaction_t;
-
-/* IMPORTANT: For details on xenstore protocol limits, see
- * docs/misc/xenstore.txt in the Xen public source repository, and use the
- * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h.
- */
-
-/* On failure, these routines set errno. */
-
-/* Open a connection to the xs daemon.
- * Attempts to make a connection over the socket interface,
- * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
- *
- * * Connections made with xs_open(0) (which might be shared page or
- *   socket based) are only guaranteed to work in the parent after
- *   fork.
- * * Connections made with xs_open(XS_OPEN_SOCKETONLY) will be usable
- *   in either the parent or the child after fork, but not both.
- * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
- *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
- *
- * Returns a handle or NULL.
- */
-struct xs_handle *xs_open(unsigned long flags);
-
-/* Close the connection to the xs daemon. */
-void xs_close(struct xs_handle *xsh /* NULL ok */);
-
-/* Connect to the xs daemon.
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(0) instead
- */
-struct xs_handle *xs_daemon_open(void);
-struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
-struct xs_handle *xs_daemon_open_readonly(void);
-
-/* Close the connection to the xs daemon.
- * Deprecated, please use xs_close() instead
- */
-void xs_daemon_close(struct xs_handle *);
-
-/* Throw away the connection to the xs daemon, for use after fork(). */
-void xs_daemon_destroy_postfork(struct xs_handle *);
-
-/* Get contents of a directory.
- * Returns a malloced array: call free() on it after use.
- * Num indicates size.
- * Returns NULL on failure.
- */
-char **xs_directory(struct xs_handle *h, xs_transaction_t t,
-		    const char *path, unsigned int *num);
-
-/* Get the value of a single file, nul terminated.
- * Returns a malloced value: call free() on it after use.
- * len indicates length in bytes, not including terminator.
- * Returns NULL on failure.
- */
-void *xs_read(struct xs_handle *h, xs_transaction_t t,
-	      const char *path, unsigned int *len);
-
-/* Write the value of a single file.
- * Returns false on failure.
- */
-bool xs_write(struct xs_handle *h, xs_transaction_t t,
-	      const char *path, const void *data, unsigned int len);
-
-/* Create a new directory.
- * Returns false on failure, or success if it already exists.
- */
-bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
-	      const char *path);
-
-/* Destroy a file or directory (and children).
- * Returns false on failure, or if it doesn't exist.
- */
-bool xs_rm(struct xs_handle *h, xs_transaction_t t,
-	   const char *path);
-
-/* Fake function which will always return false (required to let
- * libxenstore remain at 3.0 version.
- */
-bool xs_restrict(struct xs_handle *h, unsigned domid);
-
-/* Get permissions of node (first element is owner, first perms is "other").
- * Returns malloced array, or NULL: call free() after use.
- */
-struct xs_permissions *xs_get_permissions(struct xs_handle *h,
-					  xs_transaction_t t,
-					  const char *path, unsigned int *num);
-
-/* Set permissions of node (must be owner).  Returns false on failure.
- *
- * Domain 0 may read / write anywhere in the store, regardless of
- * permission settings.
- *
- * Note:
- * The perms array is a list of (domid, permissions) pairs. The first
- * element in the list specifies the owner of the list, plus the flags
- * for every domain not explicitly specified subsequently. The
- * subsequent entries are normal capabilities.
- *
- * Example C code:
- *
- *  struct xs_permissions perms[2];
- *
- *  perms[0].id = dm_domid;
- *  perms[0].perms = XS_PERM_NONE;
- *  perms[1].id = guest_domid;
- *  perms[1].perms = XS_PERM_READ;
- *
- * It means the owner of the path is domain $dm_domid (hence it always
- * has read and write permission), all other domains (unless specified
- * in subsequent pair) can neither read from nor write to that
- * path. It then specifies domain $guest_domid can read from that
- * path.
- */
-bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t,
-			const char *path, struct xs_permissions *perms,
-			unsigned int num_perms);
-
-/* Watch a node for changes (poll on fd to detect, or call read_watch()).
- * When the node (or any child) changes, fd will become readable.
- * Token is returned when watch is read, to allow matching.
- * Returns false on failure.
- */
-bool xs_watch(struct xs_handle *h, const char *path, const char *token);
-
-/* Return the FD to poll on to see if a watch has fired. */
-int xs_fileno(struct xs_handle *h);
-
-/* Check for node changes.  On success, returns a non-NULL pointer ret
- * such that ret[0] and ret[1] are valid C strings, namely the
- * triggering path (see docs/misc/xenstore.txt) and the token (from
- * xs_watch).  On error return value is NULL setting errno.
- * 
- * Callers should, after xs_fileno has become readable, repeatedly
- * call xs_check_watch until it returns NULL and sets errno to EAGAIN.
- * (If the fd became readable, xs_check_watch is allowed to make it no
- * longer show up as readable even if future calls to xs_check_watch
- * will return more watch events.)
- *
- * After the caller is finished with the returned information it
- * should be freed all in one go with free(ret).
- */
-char **xs_check_watch(struct xs_handle *h);
-
-/* Find out what node change was on (will block if nothing pending).
- * Returns array containing the path and token, or NULL.
- * Use XS_WATCH_* to access these elements.
- * Call free() after use.
- */
-char **xs_read_watch(struct xs_handle *h, unsigned int *num);
-
-/* Remove a watch on a node: implicitly acks any outstanding watch.
- * Returns false on failure (no watch on that node).
- */
-bool xs_unwatch(struct xs_handle *h, const char *path, const char *token);
-
-/* Start a transaction: changes by others will not be seen during this
- * transaction, and changes will not be visible to others until end.
- * Returns NULL on failure.
- */
-xs_transaction_t xs_transaction_start(struct xs_handle *h);
-
-/* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
- * Returns false on failure: if errno == EAGAIN, you have to restart
- * transaction.
- */
-bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
-			bool abort);
-
-/* Introduce a new domain.
- * This tells the store daemon about a shared memory page, event channel and
- * store path associated with a domain: the domain uses these to communicate.
- */
-bool xs_introduce_domain(struct xs_handle *h,
-			 unsigned int domid,
-			 unsigned long mfn,
-                         unsigned int eventchn); 
-
-/* Set the target of a domain
- * This tells the store daemon that a domain is targetting another one, so
- * it should let it tinker with it.
- */
-bool xs_set_target(struct xs_handle *h,
-		   unsigned int domid,
-		   unsigned int target);
-
-/* Resume a domain.
- * Clear the shutdown flag for this domain in the store.
- */
-bool xs_resume_domain(struct xs_handle *h, unsigned int domid);
-
-/* Release a domain.
- * Tells the store domain to release the memory page to the domain.
- */
-bool xs_release_domain(struct xs_handle *h, unsigned int domid);
-
-/* Query the home path of a domain.  Call free() after use.
- */
-char *xs_get_domain_path(struct xs_handle *h, unsigned int domid);
-
-/* Returns true if child is either equal to parent, or a node underneath
- * parent; or false otherwise.  Done by string comparison, so relative and
- * absolute pathnames never in a parent/child relationship by this
- * definition.  Cannot fail.
- */
-bool xs_path_is_subpath(const char *parent, const char *child);
-
-/* Return whether the domain specified has been introduced to xenstored.
- */
-bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid);
-
-char *xs_control_command(struct xs_handle *h, const char *cmd,
-			 void *data, unsigned int len);
-/* Deprecated: use xs_control_command() instead. */
-char *xs_debug_command(struct xs_handle *h, const char *cmd,
-		       void *data, unsigned int len);
-
-int xs_suspend_evtchn_port(int domid);
-#endif /* XENSTORE_H */
-
-/*
- * Local variables:
- *  mode: C
- *  c-file-style: "linux"
- *  indent-tabs-mode: t
- *  c-basic-offset: 8
- *  tab-width: 8
- * End:
- */
diff --git a/tools/xenstore/include/xenstore_lib.h b/tools/xenstore/include/xenstore_lib.h
deleted file mode 100644
index 0ffbae9eb5..0000000000
--- a/tools/xenstore/include/xenstore_lib.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 
-    Common routines between Xen store user library and daemon.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef XENSTORE_LIB_H
-#define XENSTORE_LIB_H
-
-#include <stddef.h>
-#include <stdbool.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdint.h>
-#include <xen/io/xs_wire.h>
-
-/* Bitmask of permissions. */
-enum xs_perm_type {
-	XS_PERM_NONE = 0,
-	XS_PERM_READ = 1,
-	XS_PERM_WRITE = 2,
-	/* Internal use. */
-	XS_PERM_ENOENT_OK = 4,
-	XS_PERM_OWNER = 8,
-};
-
-struct xs_permissions
-{
-	unsigned int id;
-	enum xs_perm_type perms;
-};
-
-/* Header of the node record in tdb. */
-struct xs_tdb_record_hdr {
-	uint64_t generation;
-	uint32_t num_perms;
-	uint32_t datalen;
-	uint32_t childlen;
-	struct xs_permissions perms[0];
-};
-
-/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
-#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
-
-/* Path for various daemon things: env vars can override. */
-const char *xs_daemon_rootdir(void);
-const char *xs_daemon_rundir(void);
-const char *xs_daemon_socket(void);
-const char *xs_daemon_socket_ro(void);
-const char *xs_domain_dev(void);
-const char *xs_daemon_tdb(void);
-
-/* Simple write function: loops for you. */
-bool xs_write_all(int fd, const void *data, unsigned int len);
-
-/* Convert strings to permissions.  False if a problem. */
-bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
-			 const char *strings);
-
-/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
-bool xs_perm_to_string(const struct xs_permissions *perm,
-                       char *buffer, size_t buf_len);
-
-/* Given a string and a length, count how many strings (nul terms). */
-unsigned int xs_count_strings(const char *strings, unsigned int len);
-
-/* Sanitising (quoting) possibly-binary strings. */
-struct expanding_buffer {
-	char *buf;
-	int avail;
-};
-
-/* Ensure that given expanding buffer has at least min_avail characters. */
-char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail);
-
-/* sanitise_value() may return NULL if malloc fails. */
-char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len);
-
-/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
-void unsanitise_value(char *out, unsigned *out_len_r, const char *in);
-
-#endif /* XENSTORE_LIB_H */
diff --git a/tools/xenstore/xenstore_lib.h b/tools/xenstore/xenstore_lib.h
new file mode 100644
index 0000000000..0ffbae9eb5
--- /dev/null
+++ b/tools/xenstore/xenstore_lib.h
@@ -0,0 +1,94 @@
+/* 
+    Common routines between Xen store user library and daemon.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef XENSTORE_LIB_H
+#define XENSTORE_LIB_H
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdint.h>
+#include <xen/io/xs_wire.h>
+
+/* Bitmask of permissions. */
+enum xs_perm_type {
+	XS_PERM_NONE = 0,
+	XS_PERM_READ = 1,
+	XS_PERM_WRITE = 2,
+	/* Internal use. */
+	XS_PERM_ENOENT_OK = 4,
+	XS_PERM_OWNER = 8,
+};
+
+struct xs_permissions
+{
+	unsigned int id;
+	enum xs_perm_type perms;
+};
+
+/* Header of the node record in tdb. */
+struct xs_tdb_record_hdr {
+	uint64_t generation;
+	uint32_t num_perms;
+	uint32_t datalen;
+	uint32_t childlen;
+	struct xs_permissions perms[0];
+};
+
+/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
+#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
+
+/* Path for various daemon things: env vars can override. */
+const char *xs_daemon_rootdir(void);
+const char *xs_daemon_rundir(void);
+const char *xs_daemon_socket(void);
+const char *xs_daemon_socket_ro(void);
+const char *xs_domain_dev(void);
+const char *xs_daemon_tdb(void);
+
+/* Simple write function: loops for you. */
+bool xs_write_all(int fd, const void *data, unsigned int len);
+
+/* Convert strings to permissions.  False if a problem. */
+bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
+			 const char *strings);
+
+/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
+bool xs_perm_to_string(const struct xs_permissions *perm,
+                       char *buffer, size_t buf_len);
+
+/* Given a string and a length, count how many strings (nul terms). */
+unsigned int xs_count_strings(const char *strings, unsigned int len);
+
+/* Sanitising (quoting) possibly-binary strings. */
+struct expanding_buffer {
+	char *buf;
+	int avail;
+};
+
+/* Ensure that given expanding buffer has at least min_avail characters. */
+char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail);
+
+/* sanitise_value() may return NULL if malloc fails. */
+char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len);
+
+/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
+void unsanitise_value(char *out, unsigned *out_len_r, const char *in);
+
+#endif /* XENSTORE_LIB_H */
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
deleted file mode 100644
index aa1d24b8b9..0000000000
--- a/tools/xenstore/xs.c
+++ /dev/null
@@ -1,1473 +0,0 @@
-/* 
-    Xen Store Daemon interface providing simple tree-like database.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#define _GNU_SOURCE
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdint.h>
-#include <errno.h>
-#include "xenstore.h"
-#include "list.h"
-#include "utils.h"
-
-#include <xentoolcore_internal.h>
-
-struct xs_stored_msg {
-	struct list_head list;
-	struct xsd_sockmsg hdr;
-	char *body;
-};
-
-#ifdef USE_PTHREAD
-
-#include <pthread.h>
-
-#ifdef USE_DLSYM
-#include <dlfcn.h>
-#endif
-
-struct xs_handle {
-	/* Communications channel to xenstore daemon. */
-	int fd;
-	Xentoolcore__Active_Handle tc_ah; /* for restrict */
-
-	/*
-         * A read thread which pulls messages off the comms channel and
-         * signals waiters.
-         */
-	pthread_t read_thr;
-	int read_thr_exists;
-
-	/*
-         * A list of fired watch messages, protected by a mutex. Users can
-         * wait on the conditional variable until a watch is pending.
-         */
-	struct list_head watch_list;
-	pthread_mutex_t watch_mutex;
-	pthread_cond_t watch_condvar;
-
-	/* Clients can select() on this pipe to wait for a watch to fire. */
-	int watch_pipe[2];
-	/* Filtering watch event in unwatch function? */
-	bool unwatch_filter;
-
-	/*
-         * A list of replies. Currently only one will ever be outstanding
-         * because we serialise requests. The requester can wait on the
-         * conditional variable for its response.
-         */
-	struct list_head reply_list;
-	pthread_mutex_t reply_mutex;
-	pthread_cond_t reply_condvar;
-
-	/* One request at a time. */
-	pthread_mutex_t request_mutex;
-
-	/* Lock discipline:
-	 *  Only holder of the request lock may write to h->fd.
-	 *  Only holder of the request lock may access read_thr_exists.
-	 *  If read_thr_exists==0, only holder of request lock may read h->fd;
-	 *  If read_thr_exists==1, only the read thread may read h->fd.
-	 *  Only holder of the reply lock may access reply_list.
-	 *  Only holder of the watch lock may access watch_list.
-	 * Lock hierarchy:
-	 *  The order in which to acquire locks is
-	 *     request_mutex
-	 *     reply_mutex
-	 *     watch_mutex
-	 */
-};
-
-#define mutex_lock(m)		pthread_mutex_lock(m)
-#define mutex_unlock(m)		pthread_mutex_unlock(m)
-#define condvar_signal(c)	pthread_cond_signal(c)
-#define condvar_wait(c,m)	pthread_cond_wait(c,m)
-#define cleanup_push(f, a)	\
-    pthread_cleanup_push((void (*)(void *))(f), (void *)(a))
-/*
- * Some definitions of pthread_cleanup_pop() are a macro starting with an
- * end-brace. GCC then complains if we immediately precede that with a label.
- * Hence we insert a dummy statement to appease the compiler in this situation.
- */
-#define cleanup_pop(run)        ((void)0); pthread_cleanup_pop(run)
-
-#define read_thread_exists(h)	(h->read_thr_exists)
-
-/* Because pthread_cleanup_p* are not available when USE_PTHREAD is
- * disabled, use these macros which convert appropriately. */
-#define cleanup_push_heap(p)        cleanup_push(free, p)
-#define cleanup_pop_heap(run, p)    cleanup_pop((run))
-
-static void *read_thread(void *arg);
-
-#else /* !defined(USE_PTHREAD) */
-
-struct xs_handle {
-	int fd;
-	Xentoolcore__Active_Handle tc_ah; /* for restrict */
-	struct list_head reply_list;
-	struct list_head watch_list;
-	/* Clients can select() on this pipe to wait for a watch to fire. */
-	int watch_pipe[2];
-	/* Filtering watch event in unwatch function? */
-	bool unwatch_filter;
-};
-
-#define mutex_lock(m)		((void)0)
-#define mutex_unlock(m)		((void)0)
-#define condvar_signal(c)	((void)0)
-#define condvar_wait(c,m)	((void)0)
-#define cleanup_push(f, a)	((void)0)
-#define cleanup_pop(run)	((void)0)
-#define read_thread_exists(h)	(0)
-
-#define cleanup_push_heap(p)        ((void)0)
-#define cleanup_pop_heap(run, p)    do { if ((run)) free(p); } while(0)
-
-#endif
-
-static int read_message(struct xs_handle *h, int nonblocking);
-
-static bool setnonblock(int fd, int nonblock) {
-	int flags = fcntl(fd, F_GETFL);
-	if (flags == -1)
-		return false;
-
-	if (nonblock)
-		flags |= O_NONBLOCK;
-	else
-		flags &= ~O_NONBLOCK;
-
-	if (fcntl(fd, F_SETFL, flags) == -1)
-		return false;
-
-	return true;
-}
-
-int xs_fileno(struct xs_handle *h)
-{
-	char c = 0;
-
-	mutex_lock(&h->watch_mutex);
-
-	if ((h->watch_pipe[0] == -1) && (pipe(h->watch_pipe) != -1)) {
-		/* Kick things off if the watch list is already non-empty. */
-		if (!list_empty(&h->watch_list))
-			while (write(h->watch_pipe[1], &c, 1) != 1)
-				continue;
-	}
-
-	mutex_unlock(&h->watch_mutex);
-
-	return h->watch_pipe[0];
-}
-
-static int get_socket(const char *connect_to)
-{
-	struct sockaddr_un addr;
-	int sock, saved_errno, flags;
-
-	sock = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (sock < 0)
-		return -1;
-
-	if ((flags = fcntl(sock, F_GETFD)) < 0)
-		goto error;
-	flags |= FD_CLOEXEC;
-	if (fcntl(sock, F_SETFD, flags) < 0)
-		goto error;
-
-	addr.sun_family = AF_UNIX;
-	if(strlen(connect_to) >= sizeof(addr.sun_path)) {
-		errno = EINVAL;
-		goto error;
-	}
-	strcpy(addr.sun_path, connect_to);
-
-	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
-		goto error;
-
-	return sock;
-
-error:
-	saved_errno = errno;
-	close(sock);
-	errno = saved_errno;
-	return -1;
-}
-
-static int get_dev(const char *connect_to)
-{
-	/* We cannot open read-only because requests are writes */
-	return open(connect_to, O_RDWR);
-}
-
-static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) {
-    struct xs_handle *h = CONTAINER_OF(ah, *h, tc_ah);
-    return xentoolcore__restrict_by_dup2_null(h->fd);
-}
-
-static struct xs_handle *get_handle(const char *connect_to)
-{
-	struct stat buf;
-	struct xs_handle *h = NULL;
-	int saved_errno;
-
-	h = malloc(sizeof(*h));
-	if (h == NULL)
-		goto err;
-
-	memset(h, 0, sizeof(*h));
-	h->fd = -1;
-
-	h->tc_ah.restrict_callback = all_restrict_cb;
-	xentoolcore__register_active_handle(&h->tc_ah);
-
-	if (stat(connect_to, &buf) != 0)
-		goto err;
-
-	if (S_ISSOCK(buf.st_mode))
-		h->fd = get_socket(connect_to);
-	else
-		h->fd = get_dev(connect_to);
-
-	if (h->fd == -1)
-		goto err;
-
-	INIT_LIST_HEAD(&h->reply_list);
-	INIT_LIST_HEAD(&h->watch_list);
-
-	/* Watch pipe is allocated on demand in xs_fileno(). */
-	h->watch_pipe[0] = h->watch_pipe[1] = -1;
-
-	h->unwatch_filter = false;
-
-#ifdef USE_PTHREAD
-	pthread_mutex_init(&h->watch_mutex, NULL);
-	pthread_cond_init(&h->watch_condvar, NULL);
-
-	pthread_mutex_init(&h->reply_mutex, NULL);
-	pthread_cond_init(&h->reply_condvar, NULL);
-
-	pthread_mutex_init(&h->request_mutex, NULL);


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3h-0000sR-N0; Wed, 09 Sep 2020 11:14:37 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3g-0000sF-0x
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:36 +0000
X-Inumbo-ID: dfefdd2c-fe49-4d90-b8e6-927c790a16fd
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id dfefdd2c-fe49-4d90-b8e6-927c790a16fd;
 Wed, 09 Sep 2020 11:14:31 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=9GEi4sJlShHw1YguHhUvD6Y1xaEBrPvV9SxPjg/reRA=; b=u9D2mYaZfXQ7UDZAXKUm+Ilsry
 j98GXpZoQkkz3v2FaCm70cyAGYX53Hz1lhA1kLnDkAwYczIR1OvaEOuXTKM6UNDt8Ak6Dkx1ON3ZS
 oQYYdYXVvbyD5du4hcvJDJAukdamto8xMXamSZmo/MfIfQM5UQ+D6Im/c/9LUXh1JjkI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3b-000689-6L
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:31 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3b-0001a2-5Q
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:31 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: split libxenvchan into new tools/libs/vchan
 directory
Message-Id: <E1kFy3b-0001a2-5Q@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:31 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8ab2429f1221ebae9fc8e72d8af205f3db93cde2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:37 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenvchan into new tools/libs/vchan directory
    
    There is no reason why libvchan is not placed in the tools/libs
    directory.
    
    At the same time move libxenvchan.h to a dedicated include directory
    in tools/libs/vchan in order to follow the same pattern as the other
    libraries in tools/libs.
    
    As tools/libvchan now contains no library any longer rename it to
    tools/vchan.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                             |   8 +-
 tools/Makefile                         |   2 +-
 tools/Rules.mk                         |   6 -
 tools/libs/Makefile                    |   1 +
 tools/libs/uselibs.mk                  |   2 +
 tools/libs/vchan/Makefile              |  20 ++
 tools/libs/vchan/include/libxenvchan.h | 176 +++++++++++
 tools/libs/vchan/init.c                | 461 ++++++++++++++++++++++++++++
 tools/libs/vchan/io.c                  | 388 ++++++++++++++++++++++++
 tools/libvchan/Makefile                | 100 -------
 tools/libvchan/init.c                  | 461 ----------------------------
 tools/libvchan/io.c                    | 388 ------------------------
 tools/libvchan/libxenvchan.h           | 176 -----------
 tools/libvchan/node-select.c           | 186 ------------
 tools/libvchan/node.c                  | 168 -----------
 tools/libvchan/vchan-socket-proxy.c    | 533 ---------------------------------
 tools/vchan/Makefile                   |  37 +++
 tools/vchan/node-select.c              | 186 ++++++++++++
 tools/vchan/node.c                     | 168 +++++++++++
 tools/vchan/vchan-socket-proxy.c       | 533 +++++++++++++++++++++++++++++++++
 20 files changed, 1978 insertions(+), 2022 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1335034fd3..364b09506b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -134,6 +134,9 @@ tools/libs/store/utils.h
 tools/libs/store/xenstore.pc
 tools/libs/store/xs_lib.c
 tools/libs/store/include/xenstore_lib.h
+tools/libs/vchan/headers.chk
+tools/libs/vchan/libxenvchan.map
+tools/libs/vchan/xenvchan.pc
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -209,7 +212,6 @@ tools/include/xen/*
 tools/include/xen-xsm/*
 tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
-tools/libvchan/xenvchan.pc
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
@@ -389,8 +391,8 @@ tools/misc/xenhypfs
 tools/misc/xenwatchdogd
 tools/misc/xen-hvmcrash
 tools/misc/xen-lowmemd
-tools/libvchan/vchan-node[12]
-tools/libvchan/vchan-socket-proxy
+tools/vchan/vchan-node[12]
+tools/vchan/vchan-socket-proxy
 tools/ocaml/*/.ocamldep.make
 tools/ocaml/*/*.cm[ixao]
 tools/ocaml/*/*.cmxa
diff --git a/tools/Makefile b/tools/Makefile
index 4a3646871c..0db01707a4 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -20,7 +20,7 @@ SUBDIRS-y += xenmon
 SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
 SUBDIRS-y += libfsimage
-SUBDIRS-$(CONFIG_Linux) += libvchan
+SUBDIRS-$(CONFIG_Linux) += vchan
 
 # do not recurse in to a dir we are about to delete
 ifneq "$(MAKECMDGOALS)" "distclean"
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 21aa8ea844..5f17492a68 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -19,7 +19,6 @@ XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
 XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
-XEN_libxenvchan    = $(XEN_ROOT)/tools/libvchan
 
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
@@ -114,11 +113,6 @@ SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
 LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_libxenstat)/libxenstat$(libextension)
 SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_libxenstat)
 
-CFLAGS_libxenvchan = -I$(XEN_libxenvchan) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab)
-LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_libxenvchan)/libxenvchan$(libextension)
-SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_libxenvchan)
-
 ifeq ($(debug),y)
 # Disable optimizations
 CFLAGS += -O0 -fno-omit-frame-pointer
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 62bd8f5292..756d059ee7 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -13,6 +13,7 @@ SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 SUBDIRS-y += store
+SUBDIRS-$(CONFIG_Linux) += vchan
 
 ifeq ($(CONFIG_RUMP),y)
 SUBDIRS-y := toolcore
diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk
index a0fe0402ff..edb4b34256 100644
--- a/tools/libs/uselibs.mk
+++ b/tools/libs/uselibs.mk
@@ -22,3 +22,5 @@ LIBS_LIBS += guest
 USELIBS_guest := evtchn ctrl
 LIBS_LIBS += store
 USELIBS_store := toolcore
+LIBS_LIBS += vchan
+USELIBS_vchan := toollog store gnttab evtchn
diff --git a/tools/libs/vchan/Makefile b/tools/libs/vchan/Makefile
new file mode 100644
index 0000000000..87ff608f45
--- /dev/null
+++ b/tools/libs/vchan/Makefile
@@ -0,0 +1,20 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += $(CFLAGS_libxenctrl)
+
+LIBHEADER := libxenvchan.h
+
+SRCS-y += init.c
+SRCS-y += io.c
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenvchan.map
diff --git a/tools/libs/vchan/include/libxenvchan.h b/tools/libs/vchan/include/libxenvchan.h
new file mode 100644
index 0000000000..d6010b145d
--- /dev/null
+++ b/tools/libs/vchan/include/libxenvchan.h
@@ -0,0 +1,176 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
+ *  this code has been substantially rewritten to use the gntdev and gntalloc
+ *  devices instead of raw MFNs and map_foreign_range.
+ *
+ *  This is a library for inter-domain communication.  A standard Xen ring
+ *  buffer is used, with a datagram-based interface built on top.  The grant
+ *  reference and event channels are shared in XenStore under the path
+ *  /local/domain/<srv-id>/data/vchan/<cli-id>/<port>/{ring-ref,event-channel}
+ *
+ *  The ring.h macros define an asymmetric interface to a shared data structure
+ *  that assumes all rings reside in a single contiguous memory space. This is
+ *  not suitable for vchan because the interface to the ring is symmetric except
+ *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
+ *  size of the rings used in vchan are determined at execution time instead of
+ *  compile time, so the macros in ring.h cannot be used to access the rings.
+ */
+
+#include <xen/io/libxenvchan.h>
+#include <xen/xen.h>
+#include <xen/sys/evtchn.h>
+#include <xenevtchn.h>
+#include <xengnttab.h>
+
+/* Callers who don't care don't need to #include <xentoollog.h> */
+struct xentoollog_logger;
+
+struct libxenvchan_ring {
+	/* Pointer into the shared page. Offsets into buffer. */
+	struct ring_shared* shr;
+	/* ring data; may be its own shared page(s) depending on order */
+	void* buffer;
+	/**
+	 * The size of the ring is (1 << order); offsets wrap around when they
+	 * exceed this. This copy is required because we can't trust the order
+	 * in the shared page to remain constant.
+	 */
+	int order;
+};
+
+/**
+ * struct libxenvchan: control structure passed to all library calls
+ */
+struct libxenvchan {
+	/* Mapping handle for shared ring page */
+	union {
+		xengntshr_handle *gntshr; /* for server */
+		xengnttab_handle *gnttab; /* for client */
+	};
+	/* Pointer to shared ring page */
+	struct vchan_interface *ring;
+	/* event channel interface */
+	xenevtchn_handle *event;
+	uint32_t event_port;
+	/* informative flags: are we acting as server? */
+	int is_server:1;
+	/* true if server remains active when client closes (allows reconnection) */
+	int server_persist:1;
+	/* true if operations should block instead of returning 0 */
+	int blocking:1;
+	/* communication rings */
+	struct libxenvchan_ring read, write;
+};
+
+/**
+ * Set up a vchan, including granting pages
+ * @param logger Logger for libxc errors
+ * @param domain The peer domain that will be connecting
+ * @param xs_path Base xenstore path for storing ring/event data
+ * @param send_min The minimum size (in bytes) of the send ring (left)
+ * @param recv_min The minimum size (in bytes) of the receive ring (right)
+ * @return The structure, or NULL in case of an error
+ */
+struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path,
+                                            size_t read_min, size_t write_min);
+/**
+ * Connect to an existing vchan. Note: you can reconnect to an existing vchan
+ * safely, however no locking is performed, so you must prevent multiple clients
+ * from connecting to a single server.
+ *
+ * @param logger Logger for libxc errors
+ * @param domain The peer domain to connect to
+ * @param xs_path Base xenstore path for storing ring/event data
+ * @return The structure, or NULL in case of an error
+ */
+struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path);
+/**
+ * Close a vchan. This deallocates the vchan and attempts to free its
+ * resources. The other side is notified of the close, but can still read any
+ * data pending prior to the close.
+ */
+void libxenvchan_close(struct libxenvchan *ctrl);
+
+/**
+ * Packet-based receive: always reads exactly $size bytes.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data that was read
+ * @param size Size of the buffer and amount of data to read
+ * @return -1 on error, 0 if nonblocking and insufficient data is available, or $size
+ */
+int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size);
+/**
+ * Stream-based receive: reads as much data as possible.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data that was read
+ * @param size Size of the buffer
+ * @return -1 on error, otherwise the amount of data read (which may be zero if
+ *         the vchan is nonblocking)
+ */
+int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size);
+/**
+ * Packet-based send: send entire buffer if possible
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data to send
+ * @param size Size of the buffer and amount of data to send
+ * @return -1 on error, 0 if nonblocking and insufficient space is available, or $size
+ */
+int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size);
+/**
+ * Stream-based send: send as much data as possible.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data to send
+ * @param size Size of the buffer
+ * @return -1 on error, otherwise the amount of data sent (which may be zero if
+ *         the vchan is nonblocking)
+ */
+int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size);
+/**
+ * Waits for reads or writes to unblock, or for a close
+ */
+int libxenvchan_wait(struct libxenvchan *ctrl);
+/**
+ * Returns the event file descriptor for this vchan. When this FD is readable,
+ * libxenvchan_wait() will not block, and the state of the vchan has changed since
+ * the last invocation of libxenvchan_wait().
+ */
+int libxenvchan_fd_for_select(struct libxenvchan *ctrl);
+/**
+ * Query the state of the vchan shared page:
+ *  return 0 when one side has called libxenvchan_close() or crashed
+ *  return 1 when both sides are open
+ *  return 2 [server only] when no client has yet connected
+ */
+int libxenvchan_is_open(struct libxenvchan* ctrl);
+/** Amount of data ready to read, in bytes */
+int libxenvchan_data_ready(struct libxenvchan *ctrl);
+/** Amount of data it is possible to send without blocking */
+int libxenvchan_buffer_space(struct libxenvchan *ctrl);
diff --git a/tools/libs/vchan/init.c b/tools/libs/vchan/init.c
new file mode 100644
index 0000000000..ad4b64fbe3
--- /dev/null
+++ b/tools/libs/vchan/init.c
@@ -0,0 +1,461 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  This file contains the setup code used to establish the ring buffer.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/user.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <xenstore.h>
+#include <xen/xen.h>
+#include <xen/sys/evtchn.h>
+#include <xen/sys/gntalloc.h>
+#include <xen/sys/gntdev.h>
+#include <libxenvchan.h>
+
+#ifndef PAGE_SHIFT
+#define PAGE_SHIFT 12
+#endif
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+#define SMALL_RING_SHIFT 10
+#define LARGE_RING_SHIFT 11
+
+#define MAX_SMALL_RING (1 << SMALL_RING_SHIFT)
+#define SMALL_RING_OFFSET 1024
+#define MAX_LARGE_RING (1 << LARGE_RING_SHIFT)
+#define LARGE_RING_OFFSET 2048
+
+// if you go over this size, you'll have too many grants to fit in the shared page.
+#define MAX_RING_SHIFT 20
+#define MAX_RING_SIZE (1 << MAX_RING_SHIFT)
+
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define max(a,b) ((a > b) ? a : b)
+
+static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
+{
+	int pages_left = ctrl->read.order >= PAGE_SHIFT ? 1 << (ctrl->read.order - PAGE_SHIFT) : 0;
+	int pages_right = ctrl->write.order >= PAGE_SHIFT ? 1 << (ctrl->write.order - PAGE_SHIFT) : 0;
+	uint32_t ring_ref = -1;
+	void *ring;
+
+	ring = xengntshr_share_page_notify(ctrl->gntshr, domain,
+			&ring_ref, 1, offsetof(struct vchan_interface, srv_live),
+			ctrl->event_port);
+
+	if (!ring)
+		goto out;
+
+	memset(ring, 0, PAGE_SIZE);
+
+	ctrl->ring = ring;
+	ctrl->read.shr = &ctrl->ring->left;
+	ctrl->write.shr = &ctrl->ring->right;
+	ctrl->ring->left_order = ctrl->read.order;
+	ctrl->ring->right_order = ctrl->write.order;
+	ctrl->ring->cli_live = 2;
+	ctrl->ring->srv_live = 1;
+	ctrl->ring->cli_notify = VCHAN_NOTIFY_WRITE;
+
+	switch (ctrl->read.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
+			pages_left, ctrl->ring->grants, 1);
+		if (!ctrl->read.buffer)
+			goto out_ring;
+	}
+
+	switch (ctrl->write.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
+			pages_right, ctrl->ring->grants + pages_left, 1);
+		if (!ctrl->write.buffer)
+			goto out_unmap_left;
+	}
+
+out:
+	return ring_ref;
+out_unmap_left:
+	if (pages_left)
+		xengntshr_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left);
+out_ring:
+	xengntshr_unshare(ctrl->gntshr, ring, 1);
+	ring_ref = -1;
+	ctrl->ring = NULL;
+	ctrl->write.order = ctrl->read.order = 0;
+	goto out;
+}
+
+static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
+{
+	int rv = -1;
+	uint32_t *grants;
+
+	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
+		domain, ring_ref, PROT_READ|PROT_WRITE,
+		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
+
+	if (!ctrl->ring)
+		goto out;
+
+	ctrl->write.order = ctrl->ring->left_order;
+	ctrl->read.order = ctrl->ring->right_order;
+	ctrl->write.shr = &ctrl->ring->left;
+	ctrl->read.shr = &ctrl->ring->right;
+	if (ctrl->write.order < SMALL_RING_SHIFT || ctrl->write.order > MAX_RING_SHIFT)
+		goto out_unmap_ring;
+	if (ctrl->read.order < SMALL_RING_SHIFT || ctrl->read.order > MAX_RING_SHIFT)
+		goto out_unmap_ring;
+	if (ctrl->read.order == ctrl->write.order && ctrl->read.order < PAGE_SHIFT)
+		goto out_unmap_ring;
+
+	grants = ctrl->ring->grants;
+
+	switch (ctrl->write.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		{
+			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
+			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
+				pages_left, domain, grants, PROT_READ|PROT_WRITE);
+			if (!ctrl->write.buffer)
+				goto out_unmap_ring;
+			grants += pages_left;
+		}
+	}
+
+	switch (ctrl->read.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		{
+			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
+			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
+				pages_right, domain, grants, PROT_READ);
+			if (!ctrl->read.buffer)
+				goto out_unmap_left;
+		}
+	}
+
+	rv = 0;
+ out:
+	return rv;
+ out_unmap_left:
+	if (ctrl->write.order >= PAGE_SHIFT)
+		xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer,
+		                1 << (ctrl->write.order - PAGE_SHIFT));
+ out_unmap_ring:
+	xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
+	ctrl->ring = 0;
+	ctrl->write.order = ctrl->read.order = 0;
+	rv = -1;
+	goto out;
+}
+
+static int init_evt_srv(struct libxenvchan *ctrl, int domain,
+                        struct xentoollog_logger *logger)
+{
+	xenevtchn_port_or_error_t port;
+
+	ctrl->event = xenevtchn_open(logger, 0);
+	if (!ctrl->event)
+		return -1;
+
+	port = xenevtchn_bind_unbound_port(ctrl->event, domain);
+	if (port < 0)
+		goto fail;
+	ctrl->event_port = port;
+
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
+		goto fail;
+
+	return 0;
+
+fail:
+	if (port >= 0)
+		xenevtchn_unbind(ctrl->event, port);
+
+	xenevtchn_close(ctrl->event);
+	ctrl->event = NULL;
+
+	return -1;
+}
+
+static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref)
+{
+	int ret = -1;
+	struct xs_handle *xs;
+	struct xs_permissions perms[2];
+	char buf[64];
+	char ref[16];
+	char* domid_str = NULL;
+	xs_transaction_t xs_trans = XBT_NULL;
+	xs = xs_domain_open();
+	if (!xs)
+		goto fail;
+	domid_str = xs_read(xs, 0, "domid", NULL);
+	if (!domid_str)
+		goto fail_xs_open;
+
+	// owner domain is us
+	perms[0].id = atoi(domid_str);
+	// permissions for domains not listed = none
+	perms[0].perms = XS_PERM_NONE;
+	// other domains
+	perms[1].id = domain;
+	perms[1].perms = XS_PERM_READ;
+
+retry_transaction:
+	xs_trans = xs_transaction_start(xs);
+	if (!xs_trans)
+		goto fail_xs_open;
+
+	snprintf(ref, sizeof ref, "%d", ring_ref);
+	snprintf(buf, sizeof buf, "%s/ring-ref", xs_base);
+	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+		goto fail_xs_open;
+	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+		goto fail_xs_open;
+
+	snprintf(ref, sizeof ref, "%d", ctrl->event_port);
+	snprintf(buf, sizeof buf, "%s/event-channel", xs_base);
+	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+		goto fail_xs_open;
+	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+		goto fail_xs_open;
+
+	if (!xs_transaction_end(xs, xs_trans, 0)) {
+		if (errno == EAGAIN)
+			goto retry_transaction;
+	} else {
+		ret = 0;
+	}
+ fail_xs_open:
+	free(domid_str);
+	xs_daemon_close(xs);
+ fail:
+	return ret;
+}
+
+static int min_order(size_t siz)
+{
+	int rv = PAGE_SHIFT;
+	while (siz > (1 << rv))
+		rv++;
+	return rv;
+}
+
+struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path,
+                                            size_t left_min, size_t right_min)
+{
+	struct libxenvchan *ctrl;
+	int ring_ref;
+	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
+		return 0;
+
+	ctrl = malloc(sizeof(*ctrl));
+	if (!ctrl)
+		return 0;
+
+	ctrl->ring = NULL;
+	ctrl->event = NULL;
+	ctrl->is_server = 1;
+	ctrl->server_persist = 0;
+
+	ctrl->read.order = min_order(left_min);
+	ctrl->write.order = min_order(right_min);
+
+	// if we can avoid allocating extra pages by using in-page rings, do so
+	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
+		ctrl->read.order = SMALL_RING_SHIFT;
+		ctrl->write.order = LARGE_RING_SHIFT;
+	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
+		ctrl->read.order = LARGE_RING_SHIFT;
+		ctrl->write.order = SMALL_RING_SHIFT;
+	} else if (left_min <= MAX_LARGE_RING) {
+		ctrl->read.order = LARGE_RING_SHIFT;
+	} else if (right_min <= MAX_LARGE_RING) {
+		ctrl->write.order = LARGE_RING_SHIFT;
+	}
+
+	ctrl->gntshr = xengntshr_open(logger, 0);
+	if (!ctrl->gntshr) {
+		free(ctrl);
+		return 0;
+	}
+
+	if (init_evt_srv(ctrl, domain, logger))
+		goto out;
+	ring_ref = init_gnt_srv(ctrl, domain);
+	if (ring_ref < 0)
+		goto out;
+	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
+		goto out;
+	return ctrl;
+out:
+	libxenvchan_close(ctrl);
+	return 0;
+}
+
+static int init_evt_cli(struct libxenvchan *ctrl, int domain,
+                        struct xentoollog_logger *logger)
+{
+	xenevtchn_port_or_error_t port;
+
+	ctrl->event = xenevtchn_open(logger, 0);
+	if (!ctrl->event)
+		return -1;
+
+	port = xenevtchn_bind_interdomain(ctrl->event,
+		domain, ctrl->event_port);
+	if (port < 0)
+		goto fail;
+	ctrl->event_port = port;
+
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
+		goto fail;
+
+	return 0;
+
+fail:
+	if (port >= 0)
+		xenevtchn_unbind(ctrl->event, port);
+
+	xenevtchn_close(ctrl->event);
+	ctrl->event = NULL;
+
+	return -1;
+}
+
+
+struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path)
+{
+	struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan));
+	struct xs_handle *xs = NULL;
+	char buf[64];
+	char *ref;
+	int ring_ref;
+	unsigned int len;
+
+	if (!ctrl)
+		return 0;
+	ctrl->ring = NULL;
+	ctrl->event = NULL;
+	ctrl->gnttab = NULL;
+	ctrl->write.order = ctrl->read.order = 0;
+	ctrl->is_server = 0;
+
+	xs = xs_daemon_open();
+	if (!xs)
+		xs = xs_domain_open();
+	if (!xs)
+		goto fail;
+
+// find xenstore entry
+	snprintf(buf, sizeof buf, "%s/ring-ref", xs_path);
+	ref = xs_read(xs, 0, buf, &len);
+	if (!ref)
+		goto fail;
+	ring_ref = atoi(ref);
+	free(ref);
+	if (!ring_ref)
+		goto fail;
+	snprintf(buf, sizeof buf, "%s/event-channel", xs_path);
+	ref = xs_read(xs, 0, buf, &len);
+	if (!ref)
+		goto fail;
+	ctrl->event_port = atoi(ref);
+	free(ref);
+	if (!ctrl->event_port)
+		goto fail;
+
+	ctrl->gnttab = xengnttab_open(logger, 0);
+	if (!ctrl->gnttab)
+		goto fail;
+
+// set up event channel
+	if (init_evt_cli(ctrl, domain, logger))
+		goto fail;
+
+// set up shared page(s)
+	if (init_gnt_cli(ctrl, domain, ring_ref))
+		goto fail;
+
+	ctrl->ring->cli_live = 1;
+	ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE;
+
+	/* wake up the server */
+	xenevtchn_notify(ctrl->event, ctrl->event_port);
+
+ out:
+	if (xs)
+		xs_daemon_close(xs);
+	return ctrl;
+ fail:
+	libxenvchan_close(ctrl);
+	ctrl = NULL;
+	goto out;
+}
diff --git a/tools/libs/vchan/io.c b/tools/libs/vchan/io.c
new file mode 100644
index 0000000000..da303fbc01
--- /dev/null
+++ b/tools/libs/vchan/io.c
@@ -0,0 +1,388 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  This file contains the communications interface built on the ring buffer.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/uio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <xenctrl.h>
+#include <libxenvchan.h>
+
+#ifndef PAGE_SHIFT
+#define PAGE_SHIFT 12
+#endif
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+
+static inline uint32_t rd_prod(struct libxenvchan *ctrl)
+{
+	return ctrl->read.shr->prod;
+}
+
+static inline uint32_t* _rd_cons(struct libxenvchan *ctrl)
+{
+	return &ctrl->read.shr->cons;
+}
+#define rd_cons(x) (*_rd_cons(x))
+
+static inline uint32_t* _wr_prod(struct libxenvchan *ctrl)
+{
+	return &ctrl->write.shr->prod;
+}
+#define wr_prod(x) (*_wr_prod(x))
+
+static inline uint32_t wr_cons(struct libxenvchan *ctrl)
+{
+	return ctrl->write.shr->cons;
+}
+
+static inline const void* rd_ring(struct libxenvchan *ctrl)
+{
+	return ctrl->read.buffer;
+}
+
+static inline void* wr_ring(struct libxenvchan *ctrl)
+{
+	return ctrl->write.buffer;
+}
+
+static inline uint32_t wr_ring_size(struct libxenvchan *ctrl)
+{
+	return (1 << ctrl->write.order);
+}
+
+static inline uint32_t rd_ring_size(struct libxenvchan *ctrl)
+{
+	return (1 << ctrl->read.order);
+}
+
+static inline void request_notify(struct libxenvchan *ctrl, uint8_t bit)
+{
+	uint8_t *notify = ctrl->is_server ? &ctrl->ring->cli_notify : &ctrl->ring->srv_notify;
+	__sync_or_and_fetch(notify, bit);
+	xen_mb(); /* post the request /before/ caller re-reads any indexes */
+}
+
+static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
+{
+	uint8_t *notify, prev;
+	xen_mb(); /* caller updates indexes /before/ we decode to notify */
+	notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify;
+	prev = __sync_fetch_and_and(notify, ~bit);
+	if (prev & bit)
+		return xenevtchn_notify(ctrl->event, ctrl->event_port);
+	else
+		return 0;
+}
+
+/*
+ * Get the amount of buffer space available, and do nothing about
+ * notifications.
+ */
+static inline int raw_get_data_ready(struct libxenvchan *ctrl)
+{
+	uint32_t ready = rd_prod(ctrl) - rd_cons(ctrl);
+	xen_mb(); /* Ensure 'ready' is read only once. */
+	if (ready > rd_ring_size(ctrl))
+		/* We have no way to return errors.  Locking up the ring is
+		 * better than the alternatives. */
+		return 0;
+	return ready;
+}
+
+/**
+ * Get the amount of buffer space available and enable notifications if needed.
+ */
+static inline int fast_get_data_ready(struct libxenvchan *ctrl, size_t request)
+{
+	int ready = raw_get_data_ready(ctrl);
+	if (ready >= request)
+		return ready;
+	/* We plan to consume all data; please tell us if you send more */
+	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
+	/*
+	 * If the writer moved rd_prod after our read but before request, we
+	 * will not get notified even though the actual amount of data ready is
+	 * above request. Reread rd_prod to cover this case.
+	 */
+	return raw_get_data_ready(ctrl);
+}
+
+int libxenvchan_data_ready(struct libxenvchan *ctrl)
+{
+	/* Since this value is being used outside libxenvchan, request notification
+	 * when it changes
+	 */
+	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
+	return raw_get_data_ready(ctrl);
+}
+
+/**
+ * Get the amount of buffer space available, and do nothing
+ * about notifications
+ */
+static inline int raw_get_buffer_space(struct libxenvchan *ctrl)
+{
+	uint32_t ready = wr_ring_size(ctrl) - (wr_prod(ctrl) - wr_cons(ctrl));
+	xen_mb(); /* Ensure 'ready' is read only once. */
+	if (ready > wr_ring_size(ctrl))
+		/* We have no way to return errors.  Locking up the ring is
+		 * better than the alternatives. */
+		return 0;
+	return ready;
+}
+
+/**
+ * Get the amount of buffer space available and enable notifications if needed.
+ */
+static inline int fast_get_buffer_space(struct libxenvchan *ctrl, size_t request)
+{
+	int ready = raw_get_buffer_space(ctrl);
+	if (ready >= request)
+		return ready;
+	/* We plan to fill the buffer; please tell us when you've read it */
+	request_notify(ctrl, VCHAN_NOTIFY_READ);
+	/*
+	 * If the reader moved wr_cons after our read but before request, we
+	 * will not get notified even though the actual amount of buffer space
+	 * is above request. Reread wr_cons to cover this case.
+	 */
+	return raw_get_buffer_space(ctrl);
+}
+
+int libxenvchan_buffer_space(struct libxenvchan *ctrl)
+{
+	/* Since this value is being used outside libxenvchan, request notification
+	 * when it changes
+	 */
+	request_notify(ctrl, VCHAN_NOTIFY_READ);
+	return raw_get_buffer_space(ctrl);
+}
+
+int libxenvchan_wait(struct libxenvchan *ctrl)
+{
+	int ret = xenevtchn_pending(ctrl->event);
+	if (ret < 0)
+		return -1;
+	xenevtchn_unmask(ctrl->event, ret);
+	return 0;
+}
+
+/**
+ * returns -1 on error, or size on success
+ *
+ * caller must have checked that enough space is available
+ */
+static int do_send(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int real_idx = wr_prod(ctrl) & (wr_ring_size(ctrl) - 1);
+	int avail_contig = wr_ring_size(ctrl) - real_idx;
+	if (avail_contig > size)
+		avail_contig = size;
+	xen_mb(); /* read indexes /then/ write data */
+	memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
+	if (avail_contig < size)
+	{
+		// we rolled across the end of the ring
+		memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
+	}
+	xen_wmb(); /* write data /then/ notify */
+	wr_prod(ctrl) += size;
+	if (send_notify(ctrl, VCHAN_NOTIFY_WRITE))
+		return -1;
+	return size;
+}
+
+/**
+ * returns 0 if no buffer space is available, -1 on error, or size on success
+ */
+int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int avail;
+	while (1) {
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		avail = fast_get_buffer_space(ctrl, size);
+		if (size <= avail)
+			return do_send(ctrl, data, size);
+		if (!ctrl->blocking)
+			return 0;
+		if (size > wr_ring_size(ctrl))
+			return -1;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int avail;
+	if (!libxenvchan_is_open(ctrl))
+		return -1;
+	if (ctrl->blocking) {
+		size_t pos = 0;
+		while (1) {
+			avail = fast_get_buffer_space(ctrl, size - pos);
+			if (pos + avail > size)
+				avail = size - pos;
+			if (avail)
+				pos += do_send(ctrl, data + pos, avail);
+			if (pos == size)
+				return pos;
+			if (libxenvchan_wait(ctrl))
+				return -1;
+			if (!libxenvchan_is_open(ctrl))
+				return -1;
+		}
+	} else {
+		avail = fast_get_buffer_space(ctrl, size);
+		if (size > avail)
+			size = avail;
+		if (size == 0)
+			return 0;
+		return do_send(ctrl, data, size);
+	}
+}
+
+/**
+ * returns -1 on error, or size on success
+ *
+ * caller must have checked that enough data is available
+ */
+static int do_recv(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	int real_idx = rd_cons(ctrl) & (rd_ring_size(ctrl) - 1);
+	int avail_contig = rd_ring_size(ctrl) - real_idx;
+	if (avail_contig > size)
+		avail_contig = size;
+	xen_rmb(); /* data read must happen /after/ rd_cons read */
+	memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
+	if (avail_contig < size)
+	{
+		// we rolled across the end of the ring
+		memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
+	}
+	xen_mb(); /* consume /then/ notify */
+	rd_cons(ctrl) += size;
+	if (send_notify(ctrl, VCHAN_NOTIFY_READ))
+		return -1;
+	return size;
+}
+
+/**
+ * reads exactly size bytes from the vchan.
+ * returns 0 if insufficient data is available, -1 on error, or size on success
+ */
+int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	while (1) {
+		int avail = fast_get_data_ready(ctrl, size);
+		if (size <= avail)
+			return do_recv(ctrl, data, size);
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		if (!ctrl->blocking)
+			return 0;
+		if (size > rd_ring_size(ctrl))
+			return -1;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	while (1) {
+		int avail = fast_get_data_ready(ctrl, size);
+		if (avail && size > avail)
+			size = avail;
+		if (avail)
+			return do_recv(ctrl, data, size);
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		if (!ctrl->blocking)
+			return 0;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_is_open(struct libxenvchan* ctrl)
+{
+	if (ctrl->is_server)
+		return ctrl->server_persist ? 1 : ctrl->ring->cli_live;
+	else
+		return ctrl->ring->srv_live;
+}
+
+int libxenvchan_fd_for_select(struct libxenvchan *ctrl)
+{
+	return xenevtchn_fd(ctrl->event);
+}
+
+void libxenvchan_close(struct libxenvchan *ctrl)
+{
+	if (!ctrl)
+		return;
+	if (ctrl->read.order >= PAGE_SHIFT)
+		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+	if (ctrl->write.order >= PAGE_SHIFT)
+		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+	if (ctrl->ring) {
+		if (ctrl->is_server) {
+			ctrl->ring->srv_live = 0;
+			xengntshr_unshare(ctrl->gntshr, ctrl->ring, 1);
+		} else {
+			ctrl->ring->cli_live = 0;
+			xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
+		}
+	}
+	if (ctrl->event) {
+		if (ctrl->ring)
+			xenevtchn_notify(ctrl->event, ctrl->event_port);
+		xenevtchn_close(ctrl->event);
+	}
+	if (ctrl->is_server) {
+		if (ctrl->gntshr)
+			xengntshr_close(ctrl->gntshr);
+	} else {
+		if (ctrl->gnttab)
+			xengnttab_close(ctrl->gnttab);
+	}
+	free(ctrl);
+}
diff --git a/tools/libvchan/Makefile b/tools/libvchan/Makefile
deleted file mode 100644
index e718447977..0000000000
--- a/tools/libvchan/Makefile
+++ /dev/null
@@ -1,100 +0,0 @@
-#
-# tools/libvchan/Makefile
-#
-
-XEN_ROOT = $(CURDIR)/../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-LIBVCHAN_OBJS = init.o io.o
-NODE_OBJS = node.o
-NODE2_OBJS = node-select.o
-
-LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS))
-LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) $(LDLIBS_libxenevtchn)
-$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-vchan-socket-proxy.o: CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-
-MAJOR = 4.15
-MINOR = 0
-
-CFLAGS += -I../include -I.
-
-io.o io.opic: CFLAGS += $(CFLAGS_libxenctrl) # for xen_mb et al
-
-PKG_CONFIG := xenvchan.pc
-PKG_CONFIG_NAME := Xenvchan
-PKG_CONFIG_DESC := The Xenvchan library for Xen hypervisor
-PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
-PKG_CONFIG_USELIBS := $(SHLIB_libxenvchan)
-PKG_CONFIG_LIB := xenvchan
-PKG_CONFIG_REQPRIV := xentoollog,xenstore,xenevtchn,xengnttab
-
-ifneq ($(CONFIG_LIBXC_MINIOS),y)
-PKG_CONFIG_INST := $(PKG_CONFIG)
-$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
-$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
-$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
-endif
-
-PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
-
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
-
-.PHONY: all
-all: libxenvchan.so vchan-node1 vchan-node2 vchan-socket-proxy libxenvchan.a $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
-
-libxenvchan.so: libxenvchan.so.$(MAJOR)
-	ln -sf $< $@
-
-libxenvchan.so.$(MAJOR): libxenvchan.so.$(MAJOR).$(MINOR)
-	ln -sf $< $@
-
-libxenvchan.so.$(MAJOR).$(MINOR): $(LIBVCHAN_PIC_OBJS)
-	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenvchan.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBVCHAN_LIBS) $(APPEND_LDFLAGS)
-
-libxenvchan.a: $(LIBVCHAN_OBJS)
-	$(AR) rcs libxenvchan.a $^
-
-vchan-node1: $(NODE_OBJS) libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $(NODE_OBJS) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
-
-vchan-node2: $(NODE2_OBJS) libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $(NODE2_OBJS) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
-
-vchan-socket-proxy: vchan-socket-proxy.o libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenvchan) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(libdir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)
-	$(INSTALL_DIR) $(DESTDIR)$(bindir)
-	$(INSTALL_PROG) libxenvchan.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
-	ln -sf libxenvchan.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR)
-	ln -sf libxenvchan.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenvchan.so
-	$(INSTALL_PROG) vchan-socket-proxy $(DESTDIR)$(bindir)
-	$(INSTALL_DATA) libxenvchan.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) libxenvchan.a $(DESTDIR)$(libdir)
-	$(INSTALL_DATA) xenvchan.pc $(DESTDIR)$(PKG_INSTALLDIR)
-
-.PHONY: uninstall
-uninstall:
-	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenvchan.pc
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.a
-	rm -f $(DESTDIR)$(includedir)/libxenvchan.h
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR)
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR).$(MINOR)
-
-.PHONY: clean
-clean:
-	$(RM) -f *.o *.opic *.so* *.a vchan-node1 vchan-node2 $(DEPS_RM)
-	$(RM) -f xenvchan.pc
-
-distclean: clean
-
--include $(DEPS_INCLUDE)
diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c
deleted file mode 100644
index ad4b64fbe3..0000000000
--- a/tools/libvchan/init.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  This file contains the setup code used to establish the ring buffer.
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/user.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <xenstore.h>
-#include <xen/xen.h>
-#include <xen/sys/evtchn.h>
-#include <xen/sys/gntalloc.h>
-#include <xen/sys/gntdev.h>
-#include <libxenvchan.h>
-
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT 12
-#endif
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
-#define SMALL_RING_SHIFT 10
-#define LARGE_RING_SHIFT 11
-
-#define MAX_SMALL_RING (1 << SMALL_RING_SHIFT)
-#define SMALL_RING_OFFSET 1024
-#define MAX_LARGE_RING (1 << LARGE_RING_SHIFT)
-#define LARGE_RING_OFFSET 2048
-
-// if you go over this size, you'll have too many grants to fit in the shared page.
-#define MAX_RING_SHIFT 20
-#define MAX_RING_SIZE (1 << MAX_RING_SHIFT)
-
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-#define max(a,b) ((a > b) ? a : b)
-
-static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
-{
-	int pages_left = ctrl->read.order >= PAGE_SHIFT ? 1 << (ctrl->read.order - PAGE_SHIFT) : 0;
-	int pages_right = ctrl->write.order >= PAGE_SHIFT ? 1 << (ctrl->write.order - PAGE_SHIFT) : 0;
-	uint32_t ring_ref = -1;
-	void *ring;
-
-	ring = xengntshr_share_page_notify(ctrl->gntshr, domain,
-			&ring_ref, 1, offsetof(struct vchan_interface, srv_live),
-			ctrl->event_port);
-
-	if (!ring)
-		goto out;
-
-	memset(ring, 0, PAGE_SIZE);
-
-	ctrl->ring = ring;
-	ctrl->read.shr = &ctrl->ring->left;
-	ctrl->write.shr = &ctrl->ring->right;
-	ctrl->ring->left_order = ctrl->read.order;
-	ctrl->ring->right_order = ctrl->write.order;
-	ctrl->ring->cli_live = 2;
-	ctrl->ring->srv_live = 1;
-	ctrl->ring->cli_notify = VCHAN_NOTIFY_WRITE;
-
-	switch (ctrl->read.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
-			pages_left, ctrl->ring->grants, 1);
-		if (!ctrl->read.buffer)
-			goto out_ring;
-	}
-
-	switch (ctrl->write.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
-			pages_right, ctrl->ring->grants + pages_left, 1);
-		if (!ctrl->write.buffer)
-			goto out_unmap_left;
-	}
-
-out:
-	return ring_ref;
-out_unmap_left:
-	if (pages_left)
-		xengntshr_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left);
-out_ring:
-	xengntshr_unshare(ctrl->gntshr, ring, 1);
-	ring_ref = -1;
-	ctrl->ring = NULL;
-	ctrl->write.order = ctrl->read.order = 0;
-	goto out;
-}
-
-static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
-{
-	int rv = -1;
-	uint32_t *grants;
-
-	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
-		domain, ring_ref, PROT_READ|PROT_WRITE,
-		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
-
-	if (!ctrl->ring)
-		goto out;
-
-	ctrl->write.order = ctrl->ring->left_order;
-	ctrl->read.order = ctrl->ring->right_order;
-	ctrl->write.shr = &ctrl->ring->left;
-	ctrl->read.shr = &ctrl->ring->right;
-	if (ctrl->write.order < SMALL_RING_SHIFT || ctrl->write.order > MAX_RING_SHIFT)
-		goto out_unmap_ring;
-	if (ctrl->read.order < SMALL_RING_SHIFT || ctrl->read.order > MAX_RING_SHIFT)
-		goto out_unmap_ring;
-	if (ctrl->read.order == ctrl->write.order && ctrl->read.order < PAGE_SHIFT)
-		goto out_unmap_ring;
-
-	grants = ctrl->ring->grants;
-
-	switch (ctrl->write.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		{
-			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
-			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
-				pages_left, domain, grants, PROT_READ|PROT_WRITE);
-			if (!ctrl->write.buffer)
-				goto out_unmap_ring;
-			grants += pages_left;
-		}
-	}
-
-	switch (ctrl->read.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		{
-			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
-			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
-				pages_right, domain, grants, PROT_READ);
-			if (!ctrl->read.buffer)
-				goto out_unmap_left;
-		}
-	}
-
-	rv = 0;
- out:
-	return rv;
- out_unmap_left:
-	if (ctrl->write.order >= PAGE_SHIFT)
-		xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer,
-		                1 << (ctrl->write.order - PAGE_SHIFT));
- out_unmap_ring:
-	xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
-	ctrl->ring = 0;
-	ctrl->write.order = ctrl->read.order = 0;
-	rv = -1;
-	goto out;
-}
-
-static int init_evt_srv(struct libxenvchan *ctrl, int domain,
-                        struct xentoollog_logger *logger)
-{
-	xenevtchn_port_or_error_t port;
-
-	ctrl->event = xenevtchn_open(logger, 0);
-	if (!ctrl->event)
-		return -1;
-
-	port = xenevtchn_bind_unbound_port(ctrl->event, domain);
-	if (port < 0)
-		goto fail;
-	ctrl->event_port = port;
-
-	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
-		goto fail;
-
-	return 0;
-
-fail:
-	if (port >= 0)
-		xenevtchn_unbind(ctrl->event, port);
-
-	xenevtchn_close(ctrl->event);
-	ctrl->event = NULL;
-
-	return -1;
-}
-
-static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref)
-{
-	int ret = -1;
-	struct xs_handle *xs;
-	struct xs_permissions perms[2];
-	char buf[64];
-	char ref[16];
-	char* domid_str = NULL;
-	xs_transaction_t xs_trans = XBT_NULL;
-	xs = xs_domain_open();
-	if (!xs)
-		goto fail;
-	domid_str = xs_read(xs, 0, "domid", NULL);
-	if (!domid_str)
-		goto fail_xs_open;
-
-	// owner domain is us
-	perms[0].id = atoi(domid_str);
-	// permissions for domains not listed = none
-	perms[0].perms = XS_PERM_NONE;
-	// other domains
-	perms[1].id = domain;
-	perms[1].perms = XS_PERM_READ;
-
-retry_transaction:
-	xs_trans = xs_transaction_start(xs);
-	if (!xs_trans)
-		goto fail_xs_open;
-
-	snprintf(ref, sizeof ref, "%d", ring_ref);
-	snprintf(buf, sizeof buf, "%s/ring-ref", xs_base);
-	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
-		goto fail_xs_open;
-	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
-		goto fail_xs_open;
-
-	snprintf(ref, sizeof ref, "%d", ctrl->event_port);
-	snprintf(buf, sizeof buf, "%s/event-channel", xs_base);
-	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
-		goto fail_xs_open;
-	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
-		goto fail_xs_open;
-
-	if (!xs_transaction_end(xs, xs_trans, 0)) {
-		if (errno == EAGAIN)
-			goto retry_transaction;
-	} else {
-		ret = 0;
-	}
- fail_xs_open:
-	free(domid_str);
-	xs_daemon_close(xs);
- fail:
-	return ret;
-}
-
-static int min_order(size_t siz)
-{
-	int rv = PAGE_SHIFT;
-	while (siz > (1 << rv))
-		rv++;
-	return rv;
-}
-
-struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path,
-                                            size_t left_min, size_t right_min)
-{
-	struct libxenvchan *ctrl;
-	int ring_ref;
-	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
-		return 0;
-
-	ctrl = malloc(sizeof(*ctrl));
-	if (!ctrl)
-		return 0;
-
-	ctrl->ring = NULL;
-	ctrl->event = NULL;
-	ctrl->is_server = 1;
-	ctrl->server_persist = 0;
-
-	ctrl->read.order = min_order(left_min);
-	ctrl->write.order = min_order(right_min);
-
-	// if we can avoid allocating extra pages by using in-page rings, do so
-	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
-		ctrl->read.order = SMALL_RING_SHIFT;
-		ctrl->write.order = LARGE_RING_SHIFT;
-	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
-		ctrl->read.order = LARGE_RING_SHIFT;
-		ctrl->write.order = SMALL_RING_SHIFT;
-	} else if (left_min <= MAX_LARGE_RING) {
-		ctrl->read.order = LARGE_RING_SHIFT;
-	} else if (right_min <= MAX_LARGE_RING) {
-		ctrl->write.order = LARGE_RING_SHIFT;
-	}
-
-	ctrl->gntshr = xengntshr_open(logger, 0);
-	if (!ctrl->gntshr) {
-		free(ctrl);
-		return 0;
-	}
-
-	if (init_evt_srv(ctrl, domain, logger))
-		goto out;
-	ring_ref = init_gnt_srv(ctrl, domain);
-	if (ring_ref < 0)
-		goto out;
-	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
-		goto out;
-	return ctrl;
-out:
-	libxenvchan_close(ctrl);
-	return 0;
-}
-
-static int init_evt_cli(struct libxenvchan *ctrl, int domain,
-                        struct xentoollog_logger *logger)
-{
-	xenevtchn_port_or_error_t port;
-
-	ctrl->event = xenevtchn_open(logger, 0);
-	if (!ctrl->event)
-		return -1;
-
-	port = xenevtchn_bind_interdomain(ctrl->event,
-		domain, ctrl->event_port);
-	if (port < 0)
-		goto fail;
-	ctrl->event_port = port;
-
-	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
-		goto fail;
-
-	return 0;
-
-fail:
-	if (port >= 0)
-		xenevtchn_unbind(ctrl->event, port);
-
-	xenevtchn_close(ctrl->event);
-	ctrl->event = NULL;
-
-	return -1;
-}
-
-
-struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path)
-{
-	struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan));
-	struct xs_handle *xs = NULL;
-	char buf[64];
-	char *ref;
-	int ring_ref;
-	unsigned int len;
-
-	if (!ctrl)
-		return 0;
-	ctrl->ring = NULL;
-	ctrl->event = NULL;
-	ctrl->gnttab = NULL;
-	ctrl->write.order = ctrl->read.order = 0;
-	ctrl->is_server = 0;
-
-	xs = xs_daemon_open();
-	if (!xs)
-		xs = xs_domain_open();
-	if (!xs)
-		goto fail;
-
-// find xenstore entry
-	snprintf(buf, sizeof buf, "%s/ring-ref", xs_path);
-	ref = xs_read(xs, 0, buf, &len);
-	if (!ref)
-		goto fail;
-	ring_ref = atoi(ref);
-	free(ref);
-	if (!ring_ref)
-		goto fail;
-	snprintf(buf, sizeof buf, "%s/event-channel", xs_path);
-	ref = xs_read(xs, 0, buf, &len);
-	if (!ref)
-		goto fail;
-	ctrl->event_port = atoi(ref);
-	free(ref);
-	if (!ctrl->event_port)
-		goto fail;
-
-	ctrl->gnttab = xengnttab_open(logger, 0);
-	if (!ctrl->gnttab)
-		goto fail;
-
-// set up event channel
-	if (init_evt_cli(ctrl, domain, logger))
-		goto fail;
-
-// set up shared page(s)
-	if (init_gnt_cli(ctrl, domain, ring_ref))
-		goto fail;
-
-	ctrl->ring->cli_live = 1;
-	ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE;
-
-	/* wake up the server */
-	xenevtchn_notify(ctrl->event, ctrl->event_port);
-
- out:
-	if (xs)
-		xs_daemon_close(xs);
-	return ctrl;
- fail:
-	libxenvchan_close(ctrl);
-	ctrl = NULL;
-	goto out;
-}
diff --git a/tools/libvchan/io.c b/tools/libvchan/io.c
deleted file mode 100644
index da303fbc01..0000000000
--- a/tools/libvchan/io.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  This file contains the communications interface built on the ring buffer.
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <xenctrl.h>
-#include <libxenvchan.h>
-
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT 12
-#endif
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
-
-static inline uint32_t rd_prod(struct libxenvchan *ctrl)
-{
-	return ctrl->read.shr->prod;
-}
-
-static inline uint32_t* _rd_cons(struct libxenvchan *ctrl)
-{
-	return &ctrl->read.shr->cons;
-}
-#define rd_cons(x) (*_rd_cons(x))
-
-static inline uint32_t* _wr_prod(struct libxenvchan *ctrl)
-{
-	return &ctrl->write.shr->prod;
-}
-#define wr_prod(x) (*_wr_prod(x))
-
-static inline uint32_t wr_cons(struct libxenvchan *ctrl)
-{
-	return ctrl->write.shr->cons;
-}
-
-static inline const void* rd_ring(struct libxenvchan *ctrl)
-{
-	return ctrl->read.buffer;
-}
-
-static inline void* wr_ring(struct libxenvchan *ctrl)
-{
-	return ctrl->write.buffer;
-}
-
-static inline uint32_t wr_ring_size(struct libxenvchan *ctrl)
-{
-	return (1 << ctrl->write.order);
-}
-
-static inline uint32_t rd_ring_size(struct libxenvchan *ctrl)
-{
-	return (1 << ctrl->read.order);
-}
-
-static inline void request_notify(struct libxenvchan *ctrl, uint8_t bit)
-{
-	uint8_t *notify = ctrl->is_server ? &ctrl->ring->cli_notify : &ctrl->ring->srv_notify;
-	__sync_or_and_fetch(notify, bit);
-	xen_mb(); /* post the request /before/ caller re-reads any indexes */
-}
-
-static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
-{
-	uint8_t *notify, prev;
-	xen_mb(); /* caller updates indexes /before/ we decode to notify */
-	notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify;
-	prev = __sync_fetch_and_and(notify, ~bit);
-	if (prev & bit)
-		return xenevtchn_notify(ctrl->event, ctrl->event_port);
-	else
-		return 0;
-}
-
-/*
- * Get the amount of buffer space available, and do nothing about
- * notifications.
- */
-static inline int raw_get_data_ready(struct libxenvchan *ctrl)
-{
-	uint32_t ready = rd_prod(ctrl) - rd_cons(ctrl);
-	xen_mb(); /* Ensure 'ready' is read only once. */
-	if (ready > rd_ring_size(ctrl))
-		/* We have no way to return errors.  Locking up the ring is
-		 * better than the alternatives. */
-		return 0;
-	return ready;
-}
-
-/**
- * Get the amount of buffer space available and enable notifications if needed.
- */
-static inline int fast_get_data_ready(struct libxenvchan *ctrl, size_t request)
-{
-	int ready = raw_get_data_ready(ctrl);
-	if (ready >= request)
-		return ready;
-	/* We plan to consume all data; please tell us if you send more */
-	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
-	/*
-	 * If the writer moved rd_prod after our read but before request, we
-	 * will not get notified even though the actual amount of data ready is
-	 * above request. Reread rd_prod to cover this case.
-	 */
-	return raw_get_data_ready(ctrl);
-}
-
-int libxenvchan_data_ready(struct libxenvchan *ctrl)
-{
-	/* Since this value is being used outside libxenvchan, request notification
-	 * when it changes
-	 */
-	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
-	return raw_get_data_ready(ctrl);
-}
-
-/**
- * Get the amount of buffer space available, and do nothing
- * about notifications
- */
-static inline int raw_get_buffer_space(struct libxenvchan *ctrl)
-{
-	uint32_t ready = wr_ring_size(ctrl) - (wr_prod(ctrl) - wr_cons(ctrl));
-	xen_mb(); /* Ensure 'ready' is read only once. */
-	if (ready > wr_ring_size(ctrl))
-		/* We have no way to return errors.  Locking up the ring is
-		 * better than the alternatives. */
-		return 0;
-	return ready;
-}
-
-/**
- * Get the amount of buffer space available and enable notifications if needed.
- */
-static inline int fast_get_buffer_space(struct libxenvchan *ctrl, size_t request)
-{
-	int ready = raw_get_buffer_space(ctrl);
-	if (ready >= request)
-		return ready;
-	/* We plan to fill the buffer; please tell us when you've read it */
-	request_notify(ctrl, VCHAN_NOTIFY_READ);
-	/*
-	 * If the reader moved wr_cons after our read but before request, we
-	 * will not get notified even though the actual amount of buffer space
-	 * is above request. Reread wr_cons to cover this case.
-	 */
-	return raw_get_buffer_space(ctrl);
-}
-
-int libxenvchan_buffer_space(struct libxenvchan *ctrl)
-{
-	/* Since this value is being used outside libxenvchan, request notification
-	 * when it changes
-	 */
-	request_notify(ctrl, VCHAN_NOTIFY_READ);
-	return raw_get_buffer_space(ctrl);
-}
-
-int libxenvchan_wait(struct libxenvchan *ctrl)
-{
-	int ret = xenevtchn_pending(ctrl->event);
-	if (ret < 0)
-		return -1;
-	xenevtchn_unmask(ctrl->event, ret);
-	return 0;
-}
-
-/**
- * returns -1 on error, or size on success
- *
- * caller must have checked that enough space is available
- */
-static int do_send(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int real_idx = wr_prod(ctrl) & (wr_ring_size(ctrl) - 1);
-	int avail_contig = wr_ring_size(ctrl) - real_idx;
-	if (avail_contig > size)
-		avail_contig = size;
-	xen_mb(); /* read indexes /then/ write data */
-	memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
-	if (avail_contig < size)
-	{
-		// we rolled across the end of the ring
-		memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
-	}
-	xen_wmb(); /* write data /then/ notify */
-	wr_prod(ctrl) += size;
-	if (send_notify(ctrl, VCHAN_NOTIFY_WRITE))
-		return -1;
-	return size;
-}
-
-/**
- * returns 0 if no buffer space is available, -1 on error, or size on success
- */
-int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int avail;
-	while (1) {
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		avail = fast_get_buffer_space(ctrl, size);
-		if (size <= avail)
-			return do_send(ctrl, data, size);
-		if (!ctrl->blocking)
-			return 0;
-		if (size > wr_ring_size(ctrl))
-			return -1;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int avail;
-	if (!libxenvchan_is_open(ctrl))
-		return -1;
-	if (ctrl->blocking) {
-		size_t pos = 0;
-		while (1) {
-			avail = fast_get_buffer_space(ctrl, size - pos);
-			if (pos + avail > size)
-				avail = size - pos;
-			if (avail)
-				pos += do_send(ctrl, data + pos, avail);
-			if (pos == size)
-				return pos;
-			if (libxenvchan_wait(ctrl))
-				return -1;
-			if (!libxenvchan_is_open(ctrl))
-				return -1;
-		}
-	} else {
-		avail = fast_get_buffer_space(ctrl, size);
-		if (size > avail)
-			size = avail;
-		if (size == 0)
-			return 0;
-		return do_send(ctrl, data, size);
-	}
-}
-
-/**
- * returns -1 on error, or size on success
- *
- * caller must have checked that enough data is available
- */
-static int do_recv(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	int real_idx = rd_cons(ctrl) & (rd_ring_size(ctrl) - 1);
-	int avail_contig = rd_ring_size(ctrl) - real_idx;
-	if (avail_contig > size)
-		avail_contig = size;
-	xen_rmb(); /* data read must happen /after/ rd_cons read */
-	memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
-	if (avail_contig < size)
-	{
-		// we rolled across the end of the ring
-		memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
-	}
-	xen_mb(); /* consume /then/ notify */
-	rd_cons(ctrl) += size;
-	if (send_notify(ctrl, VCHAN_NOTIFY_READ))
-		return -1;
-	return size;
-}
-
-/**
- * reads exactly size bytes from the vchan.
- * returns 0 if insufficient data is available, -1 on error, or size on success
- */
-int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	while (1) {
-		int avail = fast_get_data_ready(ctrl, size);
-		if (size <= avail)
-			return do_recv(ctrl, data, size);
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		if (!ctrl->blocking)
-			return 0;
-		if (size > rd_ring_size(ctrl))
-			return -1;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	while (1) {
-		int avail = fast_get_data_ready(ctrl, size);
-		if (avail && size > avail)
-			size = avail;
-		if (avail)
-			return do_recv(ctrl, data, size);
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		if (!ctrl->blocking)
-			return 0;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_is_open(struct libxenvchan* ctrl)
-{
-	if (ctrl->is_server)
-		return ctrl->server_persist ? 1 : ctrl->ring->cli_live;
-	else
-		return ctrl->ring->srv_live;
-}
-
-int libxenvchan_fd_for_select(struct libxenvchan *ctrl)
-{
-	return xenevtchn_fd(ctrl->event);
-}
-
-void libxenvchan_close(struct libxenvchan *ctrl)
-{
-	if (!ctrl)
-		return;
-	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
-	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
-	if (ctrl->ring) {
-		if (ctrl->is_server) {
-			ctrl->ring->srv_live = 0;
-			xengntshr_unshare(ctrl->gntshr, ctrl->ring, 1);
-		} else {
-			ctrl->ring->cli_live = 0;
-			xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
-		}
-	}
-	if (ctrl->event) {
-		if (ctrl->ring)
-			xenevtchn_notify(ctrl->event, ctrl->event_port);
-		xenevtchn_close(ctrl->event);
-	}
-	if (ctrl->is_server) {
-		if (ctrl->gntshr)
-			xengntshr_close(ctrl->gntshr);
-	} else {
-		if (ctrl->gnttab)
-			xengnttab_close(ctrl->gnttab);
-	}
-	free(ctrl);
-}
diff --git a/tools/libvchan/libxenvchan.h b/tools/libvchan/libxenvchan.h
deleted file mode 100644
index d6010b145d..0000000000
--- a/tools/libvchan/libxenvchan.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
- *  this code has been substantially rewritten to use the gntdev and gntalloc
- *  devices instead of raw MFNs and map_foreign_range.
- *
- *  This is a library for inter-domain communication.  A standard Xen ring
- *  buffer is used, with a datagram-based interface built on top.  The grant
- *  reference and event channels are shared in XenStore under the path
- *  /local/domain/<srv-id>/data/vchan/<cli-id>/<port>/{ring-ref,event-channel}
- *
- *  The ring.h macros define an asymmetric interface to a shared data structure
- *  that assumes all rings reside in a single contiguous memory space. This is
- *  not suitable for vchan because the interface to the ring is symmetric except
- *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
- *  size of the rings used in vchan are determined at execution time instead of
- *  compile time, so the macros in ring.h cannot be used to access the rings.
- */
-
-#include <xen/io/libxenvchan.h>
-#include <xen/xen.h>
-#include <xen/sys/evtchn.h>
-#include <xenevtchn.h>
-#include <xengnttab.h>
-
-/* Callers who don't care don't need to #include <xentoollog.h> */
-struct xentoollog_logger;
-
-struct libxenvchan_ring {
-	/* Pointer into the shared page. Offsets into buffer. */
-	struct ring_shared* shr;
-	/* ring data; may be its own shared page(s) depending on order */
-	void* buffer;
-	/**
-	 * The size of the ring is (1 << order); offsets wrap around when they
-	 * exceed this. This copy is required because we can't trust the order
-	 * in the shared page to remain constant.
-	 */
-	int order;
-};
-
-/**
- * struct libxenvchan: control structure passed to all library calls
- */
-struct libxenvchan {
-	/* Mapping handle for shared ring page */
-	union {
-		xengntshr_handle *gntshr; /* for server */
-		xengnttab_handle *gnttab; /* for client */
-	};
-	/* Pointer to shared ring page */
-	struct vchan_interface *ring;
-	/* event channel interface */
-	xenevtchn_handle *event;
-	uint32_t event_port;
-	/* informative flags: are we acting as server? */
-	int is_server:1;
-	/* true if server remains active when client closes (allows reconnection) */
-	int server_persist:1;
-	/* true if operations should block instead of returning 0 */
-	int blocking:1;
-	/* communication rings */
-	struct libxenvchan_ring read, write;
-};
-
-/**
- * Set up a vchan, including granting pages
- * @param logger Logger for libxc errors
- * @param domain The peer domain that will be connecting
- * @param xs_path Base xenstore path for storing ring/event data
- * @param send_min The minimum size (in bytes) of the send ring (left)
- * @param recv_min The minimum size (in bytes) of the receive ring (right)
- * @return The structure, or NULL in case of an error
- */
-struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path,
-                                            size_t read_min, size_t write_min);
-/**
- * Connect to an existing vchan. Note: you can reconnect to an existing vchan
- * safely, however no locking is performed, so you must prevent multiple clients
- * from connecting to a single server.
- *
- * @param logger Logger for libxc errors
- * @param domain The peer domain to connect to
- * @param xs_path Base xenstore path for storing ring/event data
- * @return The structure, or NULL in case of an error
- */
-struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path);
-/**
- * Close a vchan. This deallocates the vchan and attempts to free its
- * resources. The other side is notified of the close, but can still read any
- * data pending prior to the close.
- */
-void libxenvchan_close(struct libxenvchan *ctrl);
-
-/**
- * Packet-based receive: always reads exactly $size bytes.
- * @param ctrl The vchan control structure
- * @param data Buffer for data that was read
- * @param size Size of the buffer and amount of data to read
- * @return -1 on error, 0 if nonblocking and insufficient data is available, or $size
- */
-int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size);
-/**
- * Stream-based receive: reads as much data as possible.
- * @param ctrl The vchan control structure
- * @param data Buffer for data that was read
- * @param size Size of the buffer
- * @return -1 on error, otherwise the amount of data read (which may be zero if
- *         the vchan is nonblocking)
- */
-int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size);
-/**
- * Packet-based send: send entire buffer if possible
- * @param ctrl The vchan control structure
- * @param data Buffer for data to send
- * @param size Size of the buffer and amount of data to send
- * @return -1 on error, 0 if nonblocking and insufficient space is available, or $size
- */
-int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size);
-/**
- * Stream-based send: send as much data as possible.
- * @param ctrl The vchan control structure
- * @param data Buffer for data to send
- * @param size Size of the buffer
- * @return -1 on error, otherwise the amount of data sent (which may be zero if
- *         the vchan is nonblocking)
- */
-int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size);
-/**
- * Waits for reads or writes to unblock, or for a close
- */
-int libxenvchan_wait(struct libxenvchan *ctrl);
-/**
- * Returns the event file descriptor for this vchan. When this FD is readable,
- * libxenvchan_wait() will not block, and the state of the vchan has changed since
- * the last invocation of libxenvchan_wait().
- */
-int libxenvchan_fd_for_select(struct libxenvchan *ctrl);
-/**
- * Query the state of the vchan shared page:
- *  return 0 when one side has called libxenvchan_close() or crashed
- *  return 1 when both sides are open
- *  return 2 [server only] when no client has yet connected
- */
-int libxenvchan_is_open(struct libxenvchan* ctrl);
-/** Amount of data ready to read, in bytes */
-int libxenvchan_data_ready(struct libxenvchan *ctrl);
-/** Amount of data it is possible to send without blocking */
-int libxenvchan_buffer_space(struct libxenvchan *ctrl);
diff --git a/tools/libvchan/node-select.c b/tools/libvchan/node-select.c
deleted file mode 100644
index 039464427a..0000000000
--- a/tools/libvchan/node-select.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a test program for libxenvchan.  Communications are bidirectional,
- * with either server (grant offeror) or client able to read and write.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <libxenvchan.h>
-
-static void usage(char** argv)
-{
-	fprintf(stderr, "usage:\n"
-		"\t%s [client|server] domainid nodepath [rbufsiz wbufsiz]\n",
-		argv[0]);
-	exit(1);
-}
-
-#define BUFSIZE 5000
-char inbuf[BUFSIZE];
-char outbuf[BUFSIZE];
-int insiz = 0;
-int outsiz = 0;
-struct libxenvchan *ctrl = 0;
-
-static void vchan_wr(void) {
-	int ret;
-
-	if (!insiz)
-		return;
-	ret = libxenvchan_write(ctrl, inbuf, insiz);
-	if (ret < 0) {
-		fprintf(stderr, "vchan write failed\n");
-		exit(1);
-	}
-	if (ret > 0) {
-		insiz -= ret;
-		memmove(inbuf, inbuf + ret, insiz);
-	}
-}
-
-static void stdout_wr(void) {
-	int ret;
-
-	if (!outsiz)
-		return;
-	ret = write(1, outbuf, outsiz);
-	if (ret < 0 && errno != EAGAIN)
-		exit(1);
-	if (ret > 0) {
-		outsiz -= ret;
-		memmove(outbuf, outbuf + ret, outsiz);
-	}
-}
-
-static int set_nonblocking(int fd, int nonblocking) {
-	int flags = fcntl(fd, F_GETFL);
-	if (flags == -1)
-		return -1;
-
-	if (nonblocking)
-		flags |= O_NONBLOCK;
-	else
-		flags &= ~O_NONBLOCK;
-
-	if (fcntl(fd, F_SETFL, flags) == -1)
-		return -1;
-
-	return 0;
-}
-
-/**
-    Simple libxenvchan application, both client and server.
-	Both sides may write and read, both from the libxenvchan and from 
-	stdin/stdout (just like netcat).
-*/
-
-int main(int argc, char **argv)
-{
-	int ret;
-	int libxenvchan_fd;
-	if (argc < 4 || argv[3][0] != '/')
-		usage(argv);
-	if (!strcmp(argv[1], "server")) {
-		int rsiz = argc > 4 ? atoi(argv[4]) : 0;
-		int wsiz = argc > 5 ? atoi(argv[5]) : 0;
-		ctrl = libxenvchan_server_init(NULL, atoi(argv[2]), argv[3], rsiz, wsiz);
-	} else if (!strcmp(argv[1], "client"))
-		ctrl = libxenvchan_client_init(NULL, atoi(argv[2]), argv[3]);
-	else
-		usage(argv);
-	if (!ctrl) {
-		perror("libxenvchan_*_init");
-		exit(1);
-	}
-
-	if (set_nonblocking(0, 1) || set_nonblocking(1, 1)) {
-		perror("set_nonblocking");
-		exit(1);
-	}
-
-	libxenvchan_fd = libxenvchan_fd_for_select(ctrl);
-	for (;;) {
-		fd_set rfds;
-		fd_set wfds;
-		FD_ZERO(&rfds);
-		FD_ZERO(&wfds);
-		if (insiz != BUFSIZE)
-			FD_SET(0, &rfds);
-		if (outsiz)
-			FD_SET(1, &wfds);
-		FD_SET(libxenvchan_fd, &rfds);
-		ret = select(libxenvchan_fd + 1, &rfds, &wfds, NULL, NULL);
-		if (ret < 0) {
-			perror("select");
-			exit(1);
-		}
-		if (FD_ISSET(0, &rfds)) {
-			ret = read(0, inbuf + insiz, BUFSIZE - insiz);
-			if (ret < 0 && errno != EAGAIN)
-				exit(1);
-			if (ret == 0) {
-				while (insiz) {
-					vchan_wr();
-					libxenvchan_wait(ctrl);
-				}
-				return 0;
-			}
-			if (ret)
-				insiz += ret;
-			vchan_wr();
-		}
-		if (FD_ISSET(libxenvchan_fd, &rfds)) {
-			libxenvchan_wait(ctrl);
-			vchan_wr();
-		}
-		if (FD_ISSET(1, &wfds))
-			stdout_wr();
-		while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) {
-			ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz);
-			if (ret < 0)
-				exit(1);
-			outsiz += ret;
-			stdout_wr();
-		}
-		if (!libxenvchan_is_open(ctrl)) {
-			if (set_nonblocking(1, 0)) {
-				perror("set_nonblocking");
-				exit(1);
-			}
-			while (outsiz)
-				stdout_wr();
-			return 0;
-		}
-	}
-}
diff --git a/tools/libvchan/node.c b/tools/libvchan/node.c
deleted file mode 100644
index f1638f013d..0000000000
--- a/tools/libvchan/node.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a test program for libxenvchan.  Communications are in one direction,
- * either server (grant offeror) to client or vice versa.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <libxenvchan.h>
-
-int libxenvchan_write_all(struct libxenvchan *ctrl, char *buf, int size)
-{
-	int written = 0;
-	int ret;
-	while (written < size) {
-		ret = libxenvchan_write(ctrl, buf + written, size - written);
-		if (ret <= 0) {
-			perror("write");
-			exit(1);
-		}
-		written += ret;
-	}
-	return size;
-}
-
-int write_all(int fd, char *buf, int size)
-{
-	int written = 0;
-	int ret;
-	while (written < size) {
-		ret = write(fd, buf + written, size - written);
-		if (ret <= 0) {
-			perror("write");
-			exit(1);
-		}
-		written += ret;
-	}
-	return size;
-}
-
-void usage(char** argv)
-{
-	fprintf(stderr, "usage:\n"
-		"%s [client|server] [read|write] domid nodepath\n", argv[0]);
-	exit(1);
-}
-
-#define BUFSIZE 5000
-char buf[BUFSIZE];
-void reader(struct libxenvchan *ctrl)
-{
-	int size;
-	for (;;) {
-		size = rand() % (BUFSIZE - 1) + 1;
-		size = libxenvchan_read(ctrl, buf, size);
-		fprintf(stderr, "#");
-		if (size < 0) {
-			perror("read vchan");
-			libxenvchan_close(ctrl);
-			exit(1);
-		}
-		size = write_all(1, buf, size);
-		if (size < 0) {
-			perror("stdout write");
-			exit(1);
-		}
-		if (size == 0) {
-			perror("write size=0?\n");
-			exit(1);
-		}
-	}
-}
-
-void writer(struct libxenvchan *ctrl)
-{
-	int size;
-	for (;;) {
-		size = rand() % (BUFSIZE - 1) + 1;
-		size = read(0, buf, size);
-		if (size < 0) {
-			perror("read stdin");
-			libxenvchan_close(ctrl);
-			exit(1);
-		}
-		if (size == 0)
-			break;
-		size = libxenvchan_write_all(ctrl, buf, size);
-		fprintf(stderr, "#");
-		if (size < 0) {
-			perror("vchan write");
-			exit(1);
-		}
-		if (size == 0) {
-			perror("write size=0?\n");
-			exit(1);
-		}
-	}
-}
-
-
-/**
-	Simple libxenvchan application, both client and server.
-	One side does writing, the other side does reading; both from
-	standard input/output fds.
-*/
-int main(int argc, char **argv)
-{
-	int seed = time(0);
-	struct libxenvchan *ctrl = 0;
-	int wr = 0;
-	if (argc < 4)
-		usage(argv);
-	if (!strcmp(argv[2], "read"))
-		wr = 0;
-	else if (!strcmp(argv[2], "write"))
-		wr = 1;
-	else
-		usage(argv);
-	if (!strcmp(argv[1], "server"))
-		ctrl = libxenvchan_server_init(NULL, atoi(argv[3]), argv[4], 0, 0);
-	else if (!strcmp(argv[1], "client"))
-		ctrl = libxenvchan_client_init(NULL, atoi(argv[3]), argv[4]);
-	else
-		usage(argv);
-	if (!ctrl) {
-		perror("libxenvchan_*_init");
-		exit(1);
-	}
-	ctrl->blocking = 1;
-
-	srand(seed);
-	fprintf(stderr, "seed=%d\n", seed);
-	if (wr)
-		writer(ctrl);
-	else
-		reader(ctrl);
-	libxenvchan_close(ctrl);
-	return 0;
-}
diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c
deleted file mode 100644
index e1d959c6d1..0000000000
--- a/tools/libvchan/vchan-socket-proxy.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *       Marek Marczykowski-Górecki  <marmarek@invisiblethingslab.com>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a vchan to unix socket proxy. Vchan server is set, and on client
- * connection, local socket connection is established. Communication is bidirectional.
- * One client is served at a time, clients needs to coordinate this themselves.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <getopt.h>
-
-#include <xenstore.h>
-#include <xenctrl.h>
-#include <libxenvchan.h>
-
-static void usage(char** argv)
-{
-    fprintf(stderr, "usage:\n"
-        "\t%s [options] domainid nodepath [socket-path|file-no|-]\n"
-        "\n"
-        "options:\n"
-        "\t-m, --mode=client|server - vchan connection mode (client by default)\n"
-        "\t-s, --state-path=path - xenstore path where write \"running\" to \n"
-        "\t                        at startup\n"
-        "\t-v, --verbose - verbose logging\n"
-        "\n"
-        "client: client of a vchan connection, fourth parameter can be:\n"
-        "\tsocket-path: listen on a UNIX socket at this path and connect to vchan\n"
-        "\t             whenever new connection is accepted;\n"
-        "\t             handle multiple _subsequent_ connections, until terminated\n"
-        "\n"
-        "\tfile-no:     except open FD of a socket in listen mode;\n"
-        "\t             otherwise similar to socket-path\n"
-        "\n"
-        "\t-:           open vchan connection immediately and pass the data\n"
-        "\t             from stdin/stdout; terminate when vchan connection\n"
-        "\t             is closed\n"
-        "\n"
-        "server: server of a vchan connection, fourth parameter can be:\n"
-        "\tsocket-path: connect to this UNIX socket when new vchan connection\n"
-        "\t             is accepted;\n"
-        "\t             handle multiple _subsequent_ connections, until terminated\n"
-        "\n"
-        "\tfile-no:     pass data to/from this FD; terminate when vchan connection\n"
-        "\t             is closed\n"
-        "\n"
-        "\t-:           pass data to/from stdin/stdout; terminate when vchan\n"
-        "\t             connection is closed\n",
-        argv[0]);
-    exit(1);
-}
-
-#define BUFSIZE 8192
-char inbuf[BUFSIZE];
-char outbuf[BUFSIZE];
-int insiz = 0;
-int outsiz = 0;
-int verbose = 0;
-
-struct vchan_proxy_state {
-    struct libxenvchan *ctrl;
-    int output_fd;
-    int input_fd;
-};
-
-static void vchan_wr(struct libxenvchan *ctrl) {
-    int ret;
-
-    if (!insiz)
-        return;
-    ret = libxenvchan_write(ctrl, inbuf, insiz);
-    if (ret < 0) {
-        fprintf(stderr, "vchan write failed\n");
-        exit(1);
-    }
-    if (verbose)
-        fprintf(stderr, "wrote %d bytes to vchan\n", ret);
-    if (ret > 0) {
-        insiz -= ret;
-        memmove(inbuf, inbuf + ret, insiz);
-    }
-}
-
-static void socket_wr(int output_fd) {
-    int ret;
-
-    if (!outsiz)
-        return;
-    ret = write(output_fd, outbuf, outsiz);
-    if (ret < 0 && errno != EAGAIN)
-        exit(1);
-    if (ret > 0) {
-        outsiz -= ret;
-        memmove(outbuf, outbuf + ret, outsiz);
-    }
-}
-
-static int set_nonblocking(int fd, int nonblocking) {
-    int flags = fcntl(fd, F_GETFL);
-    if (flags == -1)
-        return -1;
-
-    if (nonblocking)
-        flags |= O_NONBLOCK;
-    else
-        flags &= ~O_NONBLOCK;
-
-    if (fcntl(fd, F_SETFL, flags) == -1)
-        return -1;
-
-    return 0;
-}
-
-static int connect_socket(const char *path_or_fd) {
-    int fd;
-    char *endptr;
-    struct sockaddr_un addr;
-
-    fd = strtoll(path_or_fd, &endptr, 0);
-    if (*endptr == '\0') {
-        set_nonblocking(fd, 1);
-        return fd;
-    }
-
-    if (strlen(path_or_fd) >= sizeof(addr.sun_path)) {
-        fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n",
-                path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path));
-        return -1;
-    }
-
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (fd == -1) {
-        perror("socket");
-        return -1;
-    }
-
-    addr.sun_family = AF_UNIX;
-    strcpy(addr.sun_path, path_or_fd);
-    if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        perror("connect");
-        close(fd);
-        return -1;
-    }
-
-    set_nonblocking(fd, 1);
-
-    return fd;
-}
-
-static int listen_socket(const char *path_or_fd) {
-    int fd;
-    char *endptr;
-    struct sockaddr_un addr;
-
-    fd = strtoll(path_or_fd, &endptr, 0);
-    if (*endptr == '\0') {
-        return fd;
-    }
-
-    if (strlen(path_or_fd) >= sizeof(addr.sun_path)) {
-        fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n",
-                path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path));
-        return -1;
-    }
-
-    /* if not a number, assume a socket path */
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (fd == -1) {
-        perror("socket");
-        return -1;
-    }
-
-    addr.sun_family = AF_UNIX;
-    strcpy(addr.sun_path, path_or_fd);
-    if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        perror("bind");
-        close(fd);
-        return -1;
-    }
-    if (listen(fd, 5) != 0) {
-        perror("listen");
-        close(fd);
-        return -1;
-    }
-
-    return fd;
-}
-
-static struct libxenvchan *connect_vchan(int domid, const char *path) {
-    struct libxenvchan *ctrl = NULL;
-    struct xs_handle *xs = NULL;
-    xc_interface *xc = NULL;
-    xc_dominfo_t dominfo;
-    char **watch_ret;
-    unsigned int watch_num;
-    int ret;
-
-    xs = xs_open(XS_OPEN_READONLY);
-    if (!xs) {
-        perror("xs_open");
-        goto out;
-    }
-    xc = xc_interface_open(NULL, NULL, XC_OPENFLAG_NON_REENTRANT);
-    if (!xc) {
-        perror("xc_interface_open");
-        goto out;
-    }
-    /* wait for vchan server to create *path* */
-    if (!xs_watch(xs, path, "path")) {
-        fprintf(stderr, "xs_watch(%s) failed.\n", path);
-        goto out;
-    }
-    if (!xs_watch(xs, "@releaseDomain", "release")) {
-        fprintf(stderr, "xs_watch(@releaseDomain failed.\n");
-        goto out;
-    }
-
-    while ((watch_ret = xs_read_watch(xs, &watch_num))) {
-        /* don't care about exact which fired the watch */
-        free(watch_ret);
-        ctrl = libxenvchan_client_init(NULL, domid, path);
-        if (ctrl)
-            break;
-
-        ret = xc_domain_getinfo(xc, domid, 1, &dominfo);
-        /* break the loop if domain is definitely not there anymore, but
-         * continue if it is or the call failed (like EPERM) */
-        if (ret == -1 && errno == ESRCH)
-            break;
-        if (ret == 1 && (dominfo.domid != (uint32_t)domid || dominfo.dying))
-            break;
-    }
-
-out:
-    if (xc)
-        xc_interface_close(xc);
-    if (xs)
-        xs_close(xs);


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3s-0000ts-RQ; Wed, 09 Sep 2020 11:14:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3r-0000tl-Qn
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:47 +0000
X-Inumbo-ID: bf235fe3-f7b3-4785-b4ce-a2474074abd8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id bf235fe3-f7b3-4785-b4ce-a2474074abd8;
 Wed, 09 Sep 2020 11:14:41 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=aBXCyFgv1e1A2miz8UoqgWdNP/Bjjz+kg0b8v4CNT7w=; b=6vOCD2Wt9zRTxkRIzDzZVQ26Iy
 ZQWbcWPuw2OitTevbedCx9umP7wREN2P47WSf0ocg821/rd6BGXHc3YZIKfXIMP/M1Wormezp3pF6
 IYhwcVqf17ya9EgsAVrjHx1xrVreuWlhWGfLH5QREf1aUVYdO+shbPNmhWAbjhWuOE48=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3l-00068H-Ay
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:41 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3l-0001aq-A4
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:41 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: split libxenstat into new tools/libs/stat
 directory
Message-Id: <E1kFy3l-0001aq-A4@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:41 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6d0ec0539077943af6d02be2adc79766c7950132
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:38 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenstat into new tools/libs/stat directory
    
    There is no reason why libxenstat is not placed in the tools/libs
    directory.
    
    At the same time move xenstat.h to a dedicated include directory
    in tools/libs/stat in order to follow the same pattern as the other
    libraries in tools/libs.
    
    As now xentop is the only left directory in xenstat move it directly
    under tools and get rid of tools/xenstat.
    
    Fix some missing prototype errors (add one prototype and make two
    functions static).
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                                         |    8 +-
 tools/Makefile                                     |    2 +-
 tools/Rules.mk                                     |    6 -
 tools/libs/Makefile                                |    1 +
 tools/libs/stat/COPYING                            |  509 ++++++++
 tools/libs/stat/Makefile                           |  132 ++
 tools/libs/stat/bindings/swig/perl/.empty          |    1 +
 tools/libs/stat/bindings/swig/python/.empty        |    1 +
 tools/libs/stat/bindings/swig/xenstat.i            |    8 +
 tools/libs/stat/include/xenstat.h                  |  197 +++
 tools/libs/stat/xenstat.c                          |  735 +++++++++++
 tools/libs/stat/xenstat_freebsd.c                  |   47 +
 tools/libs/stat/xenstat_linux.c                    |  496 ++++++++
 tools/libs/stat/xenstat_netbsd.c                   |   97 ++
 tools/libs/stat/xenstat_priv.h                     |  108 ++
 tools/libs/stat/xenstat_qmp.c                      |  446 +++++++
 tools/libs/stat/xenstat_solaris.c                  |  405 ++++++
 tools/libs/uselibs.mk                              |    2 +
 tools/xenstat/Makefile                             |   10 -
 tools/xenstat/libxenstat/COPYING                   |  509 --------
 tools/xenstat/libxenstat/Makefile                  |  195 ---
 tools/xenstat/libxenstat/bindings/swig/perl/.empty |    1 -
 .../xenstat/libxenstat/bindings/swig/python/.empty |    1 -
 tools/xenstat/libxenstat/bindings/swig/xenstat.i   |    8 -
 tools/xenstat/libxenstat/src/xenstat.c             |  735 -----------
 tools/xenstat/libxenstat/src/xenstat.h             |  194 ---
 tools/xenstat/libxenstat/src/xenstat_freebsd.c     |   47 -
 tools/xenstat/libxenstat/src/xenstat_linux.c       |  496 --------
 tools/xenstat/libxenstat/src/xenstat_netbsd.c      |   97 --
 tools/xenstat/libxenstat/src/xenstat_priv.h        |  108 --
 tools/xenstat/libxenstat/src/xenstat_qmp.c         |  446 -------
 tools/xenstat/libxenstat/src/xenstat_solaris.c     |  405 ------
 tools/xenstat/xentop/Makefile                      |   50 -
 tools/xenstat/xentop/TODO                          |   34 -
 tools/xenstat/xentop/xentop.c                      | 1346 --------------------
 tools/xentop/Makefile                              |   50 +
 tools/xentop/TODO                                  |   34 +
 tools/xentop/xentop.c                              | 1346 ++++++++++++++++++++
 38 files changed, 4621 insertions(+), 4692 deletions(-)

diff --git a/.gitignore b/.gitignore
index 364b09506b..5e8c47e2db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,6 +128,10 @@ tools/libs/guest/xc_core.h
 tools/libs/guest/xc_core_arm.h
 tools/libs/guest/xc_core_x86.h
 tools/libs/guest/xc_private.h
+tools/libs/stat/_paths.h
+tools/libs/stat/headers.chk
+tools/libs/stat/libxenstat.map
+tools/libs/stat/xenstat.pc
 tools/libs/store/headers.chk
 tools/libs/store/list.h
 tools/libs/store/utils.h
@@ -276,9 +280,6 @@ tools/xenmon/xentrace_setmask
 tools/xenmon/xenbaked
 tools/xenpaging/xenpaging
 tools/xenpmd/xenpmd
-tools/xenstat/libxenstat/src/_paths.h
-tools/xenstat/libxenstat/xenstat.pc
-tools/xenstat/xentop/xentop
 tools/xenstore/xenstore
 tools/xenstore/xenstore-chmod
 tools/xenstore/xenstore-exists
@@ -291,6 +292,7 @@ tools/xenstore/xenstore-ls
 tools/xenstore/xenstored
 tools/xenstore/xenstored_test
 tools/xenstore/xs_tdb_dump
+tools/xentop/xentop
 tools/xentrace/xentrace_setsize
 tools/xentrace/tbctl
 tools/xentrace/xenctx
diff --git a/tools/Makefile b/tools/Makefile
index 0db01707a4..ea69675cca 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -17,7 +17,7 @@ SUBDIRS-$(CONFIG_XCUTILS) += xcutils
 SUBDIRS-$(CONFIG_X86) += firmware
 SUBDIRS-y += console
 SUBDIRS-y += xenmon
-SUBDIRS-y += xenstat
+SUBDIRS-y += xentop
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
 SUBDIRS-y += libfsimage
 SUBDIRS-$(CONFIG_Linux) += vchan
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 5f17492a68..4fd91fa444 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -18,7 +18,6 @@ include $(XEN_ROOT)/tools/libs/uselibs.mk
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
-XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
 
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
@@ -108,11 +107,6 @@ ifeq ($(CONFIG_Linux),y)
 LDLIBS_libxenstore += -ldl
 endif
 
-CFLAGS_libxenstat  = -I$(XEN_libxenstat)
-SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
-LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_libxenstat)/libxenstat$(libextension)
-SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_libxenstat)
-
 ifeq ($(debug),y)
 # Disable optimizations
 CFLAGS += -O0 -fno-omit-frame-pointer
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 756d059ee7..e8fcd59214 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -13,6 +13,7 @@ SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 SUBDIRS-y += store
+SUBDIRS-y += stat
 SUBDIRS-$(CONFIG_Linux) += vchan
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/stat/COPYING b/tools/libs/stat/COPYING
new file mode 100644
index 0000000000..480e5f1876
--- /dev/null
+++ b/tools/libs/stat/COPYING
@@ -0,0 +1,509 @@
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+	51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard.  To achieve this, non-free programs must
+be allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at least
+    three years, to give the same user the materials specified in
+    Subsection 6a, above, for a charge no more than the cost of
+    performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James
+  Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/tools/libs/stat/Makefile b/tools/libs/stat/Makefile
new file mode 100644
index 0000000000..5463f5f7ca
--- /dev/null
+++ b/tools/libs/stat/Makefile
@@ -0,0 +1,132 @@
+# libxenstat: statistics-collection library for Xen
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Josh Triplett <josh@kernel.org>
+# 
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(CFLAGS_xeninclude) -include $(XEN_ROOT)/tools/config.h
+
+SRCS-y += xenstat.c
+SRCS-y += xenstat_qmp.c
+SRCS-$(CONFIG_Linux) += xenstat_linux.c
+SRCS-$(CONFIG_SunOS) += xenstat_solaris.c
+SRCS-$(CONFIG_NetBSD) += xenstat_netbsd.c
+SRCS-$(CONFIG_FreeBSD) += xenstat_freebsd.c
+
+LDLIBS-y += -lyajl
+LDLIBS-$(CONFIG_SunOS) += -lkstat
+APPEND_LDFLAGS += $(LDLIBS-y)
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstat)/include
+
+$(LIB_OBJS): _paths.h
+
+PYLIB=bindings/swig/python/_xenstat.so
+PYMOD=bindings/swig/python/xenstat.py
+PYSRC=bindings/swig/python/_xenstat.c
+PERLLIB=bindings/swig/perl/xenstat.so
+PERLMOD=bindings/swig/perl/xenstat.pm
+PERLSRC=bindings/swig/perl/xenstat.c
+BINDINGS=$(PYLIB) $(PYMOD) $(PERLLIB) $(PERLMOD)
+BINDINGSRC=$(PYSRC) $(PERLSRC)
+
+# The all-bindings target builds all the language bindings
+.PHONY: all-bindings
+all-bindings: perl-bindings python-bindings
+
+# The install-bindings target installs all the language bindings
+install-bindings: install-perl-bindings install-python-bindings
+
+.PHONY: uninstall-bindings
+uninstall-bindings: uninstall-perl-bindings uninstall-python-bindings
+
+$(BINDINGS): $(SHLIB) $(SHLIB_LINKS) include/xenstat.h
+
+SWIG_FLAGS=-module xenstat -Iinclude -I.
+
+# Python bindings
+PYTHON_VERSION=$(PYTHON:python%=%)
+PYTHON_FLAGS=-I/usr/include/python$(PYTHON_VERSION) -lpython$(PYTHON_VERSION)
+$(PYMOD): $(PYSRC)
+$(PYSRC): bindings/swig/xenstat.i
+	swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $<
+
+$(PYLIB): $(PYSRC)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
+
+python-bindings: $(PYLIB) $(PYMOD)
+
+pythonlibdir=$(prefix)/lib/python$(PYTHON_VERSION)/site-packages
+install-python-bindings: $(PYLIB) $(PYMOD)
+	$(INSTALL_PROG) $(PYLIB) $(DESTDIR)$(pythonlibdir)/_xenstat.so
+	$(INSTALL_PROG) $(PYMOD) $(DESTDIR)$(pythonlibdir)/xenstat.py
+
+.PHONY: uninstall-python-bindings
+uninstall-python-bindings:
+	rm -f $(DESTDIR)$(pythonlibdir)/_xenstat.so
+	rm -f $(DESTDIR)$(pythonlibdir)/xenstat.py
+
+ifeq ($(XENSTAT_PYTHON_BINDINGS),y)
+.PHONY: all
+all: python-bindings
+install: install-python-bindings
+uninstall: uninstall-python-bindings
+endif
+
+# Perl bindings
+PERL_FLAGS=`perl -MConfig -e 'print "$$Config{ccflags} -I$$Config{archlib}/CORE";'`
+$(PERLMOD): $(PERLSRC)
+$(PERLSRC): bindings/swig/xenstat.i
+	swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $<
+
+$(PERLLIB): $(PERLSRC)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
+
+.PHONY: perl-bindings
+perl-bindings: $(PERLLIB) $(PERLMOD)
+
+.PHONY: install-perl-bindings
+perllibdir=$(prefix)/lib/perl5
+perlmoddir=$(prefix)/share/perl5
+install-perl-bindings: $(PERLLIB) $(PERLMOD)
+	$(INSTALL_PROG) $(PERLLIB) $(DESTDIR)$(perllibdir)/xenstat.so
+	$(INSTALL_PROG) $(PERLMOD) $(DESTDIR)$(perlmoddir)/xenstat.pm
+
+.PHONY: uninstall-perl-bindings
+uninstall-perl-bindings:
+	rm -f $(DESTDIR)$(perllibdir)/xenstat.so
+	rm -f $(DESTDIR)$(perlmoddir)/xenstat.pm
+
+ifeq ($(XENSTAT_PERL_BINDINGS),y)
+.PHONY: all
+all: perl-bindings
+
+.PHONY: install
+install: install-perl-bindings
+uninstall: uninstall-perl-bindings
+endif
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f $(BINDINGS) $(BINDINGSRC) $(DEPS_RM) _paths.h
+	rm -f libxenstat.map
+
+-include $(DEPS_INCLUDE)
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
diff --git a/tools/libs/stat/bindings/swig/perl/.empty b/tools/libs/stat/bindings/swig/perl/.empty
new file mode 100644
index 0000000000..2a8dd4274d
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/perl/.empty
@@ -0,0 +1 @@
+This directory is empty; this file is included to prevent version control systems from removing the directory.
diff --git a/tools/libs/stat/bindings/swig/python/.empty b/tools/libs/stat/bindings/swig/python/.empty
new file mode 100644
index 0000000000..2a8dd4274d
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/python/.empty
@@ -0,0 +1 @@
+This directory is empty; this file is included to prevent version control systems from removing the directory.
diff --git a/tools/libs/stat/bindings/swig/xenstat.i b/tools/libs/stat/bindings/swig/xenstat.i
new file mode 100644
index 0000000000..d18fe0b155
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/xenstat.i
@@ -0,0 +1,8 @@
+%module xenstat_swig
+%{
+/* Includes the header in the wrapper code */
+#include "xenstat.h"
+%}
+
+/* Parse the header file to generate wrappers */
+%include "xenstat.h"
diff --git a/tools/libs/stat/include/xenstat.h b/tools/libs/stat/include/xenstat.h
new file mode 100644
index 0000000000..c3b98909dd
--- /dev/null
+++ b/tools/libs/stat/include/xenstat.h
@@ -0,0 +1,197 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/* libxenstat API */
+
+#ifndef XENSTAT_H
+#define XENSTAT_H
+
+#include <stdbool.h>
+
+/* Opaque handles */
+typedef struct xenstat_handle xenstat_handle;
+typedef struct xenstat_domain xenstat_domain;
+typedef struct xenstat_node xenstat_node;
+typedef struct xenstat_vcpu xenstat_vcpu;
+typedef struct xenstat_network xenstat_network;
+typedef struct xenstat_vbd xenstat_vbd;
+
+/* Initialize the xenstat library.  Returns a handle to be used with
+ * subsequent calls to the xenstat library, or NULL if an error occurs. */
+xenstat_handle *xenstat_init(void);
+
+/* Release the handle to libxc, free resources, etc. */
+void xenstat_uninit(xenstat_handle * handle);
+
+/* Flags for types of information to collect in xenstat_get_node */
+#define XENSTAT_VCPU 0x1
+#define XENSTAT_NETWORK 0x2
+#define XENSTAT_XEN_VERSION 0x4
+#define XENSTAT_VBD 0x8
+#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK|XENSTAT_XEN_VERSION|XENSTAT_VBD)
+
+/* Get all available information about a node */
+xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags);
+
+/* Free the information */
+void xenstat_free_node(xenstat_node * node);
+
+/*
+ * Node functions - extract information from a xenstat_node
+ */
+
+/* Get information about the domain with the given domain ID */
+xenstat_domain *xenstat_node_domain(xenstat_node * node,
+				    unsigned int domid);
+
+/* Get the domain with the given index; used to loop over all domains. */
+xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
+					     unsigned index);
+
+/* Get xen version of the node */
+const char *xenstat_node_xen_version(xenstat_node * node);
+
+/* Get amount of total memory on a node */
+unsigned long long xenstat_node_tot_mem(xenstat_node * node);
+
+/* Get amount of free memory on a node */
+unsigned long long xenstat_node_free_mem(xenstat_node * node);
+
+/* Get amount of freeable memory on a node */
+long xenstat_node_freeable_mb(xenstat_node * node);
+
+/* Find the number of domains existing on a node */
+unsigned int xenstat_node_num_domains(xenstat_node * node);
+
+/* Find the number of CPUs existing on a node */
+unsigned int xenstat_node_num_cpus(xenstat_node * node);
+
+/* Get information about the CPU speed */
+unsigned long long xenstat_node_cpu_hz(xenstat_node * node);
+
+/*
+ * Domain functions - extract information from a xenstat_domain
+ */
+
+/* Get the domain ID for this domain */
+unsigned xenstat_domain_id(xenstat_domain * domain);
+
+/* Set the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain);
+
+/* Get information about how much CPU time has been used */
+unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain);
+
+/* Find the number of VCPUs allocated to a domain */
+unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain);
+
+/* Get the VCPU handle to obtain VCPU stats */
+xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain,
+				  unsigned int vcpu);
+
+/* Find the current memory reservation for this domain */
+unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain);
+
+/* Find the maximum memory reservation for this domain */
+unsigned long long xenstat_domain_max_mem(xenstat_domain * domain);
+
+/* Find the domain's SSID */
+unsigned int xenstat_domain_ssid(xenstat_domain * domain);
+
+/* Get domain states */
+unsigned int xenstat_domain_dying(xenstat_domain * domain);
+unsigned int xenstat_domain_crashed(xenstat_domain * domain);
+unsigned int xenstat_domain_shutdown(xenstat_domain * domain);
+unsigned int xenstat_domain_paused(xenstat_domain * domain);
+unsigned int xenstat_domain_blocked(xenstat_domain * domain);
+unsigned int xenstat_domain_running(xenstat_domain * domain);
+
+/* Get the number of networks for a given domain */
+unsigned int xenstat_domain_num_networks(xenstat_domain *);
+
+/* Get the network handle to obtain network stats */
+xenstat_network *xenstat_domain_network(xenstat_domain * domain,
+					unsigned int network);
+
+/* Get the number of VBDs for a given domain */
+unsigned int xenstat_domain_num_vbds(xenstat_domain *);
+
+/* Get the VBD handle to obtain VBD stats */
+xenstat_vbd *xenstat_domain_vbd(xenstat_domain * domain,
+				    unsigned int vbd);
+
+/*
+ * VCPU functions - extract information from a xenstat_vcpu
+ */
+
+/* Get VCPU usage */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu);
+unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu);
+
+
+/*
+ * Network functions - extract information from a xenstat_network
+ */
+
+/* Get the ID for this network */
+unsigned int xenstat_network_id(xenstat_network * network);
+
+/* Get the number of receive bytes for this network */
+unsigned long long xenstat_network_rbytes(xenstat_network * network);
+
+/* Get the number of receive packets for this network */
+unsigned long long xenstat_network_rpackets(xenstat_network * network);
+
+/* Get the number of receive errors for this network */
+unsigned long long xenstat_network_rerrs(xenstat_network * network);
+
+/* Get the number of receive drops for this network */
+unsigned long long xenstat_network_rdrop(xenstat_network * network);
+
+/* Get the number of transmit bytes for this network */
+unsigned long long xenstat_network_tbytes(xenstat_network * network);
+
+/* Get the number of transmit packets for this network */
+unsigned long long xenstat_network_tpackets(xenstat_network * network);
+
+/* Get the number of transmit errors for this network */
+unsigned long long xenstat_network_terrs(xenstat_network * network);
+
+/* Get the number of transmit drops for this network */
+unsigned long long xenstat_network_tdrop(xenstat_network * network);
+
+/*
+ * VBD functions - extract information from a xen_vbd
+ */
+
+/* Get the back driver type  for Virtual Block Device */
+unsigned int xenstat_vbd_type(xenstat_vbd * vbd);
+
+/* Get the device number for Virtual Block Device */
+unsigned int xenstat_vbd_dev(xenstat_vbd * vbd);
+
+/* Get the number of OO/RD/WR requests for vbd */
+unsigned long long xenstat_vbd_oo_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_rd_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_wr_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_rd_sects(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_wr_sects(xenstat_vbd * vbd);
+
+/* Returns error while getting stats (1 if error happened, 0 otherwise) */
+bool xenstat_vbd_error(xenstat_vbd * vbd);
+
+#endif /* XENSTAT_H */
diff --git a/tools/libs/stat/xenstat.c b/tools/libs/stat/xenstat.c
new file mode 100644
index 0000000000..6f93d4e982
--- /dev/null
+++ b/tools/libs/stat/xenstat.c
@@ -0,0 +1,735 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "xenstat_priv.h"
+
+/*
+ * Data-collection types
+ */
+/* Called to collect the information for the node and all the domains on
+ * it. When called, the domain information has already been collected. 
+ * Return status is 0 if fatal error occurs, 1 for success. Collectors
+ * may prune a domain from the list if it has been deleted between the
+ * time the list was setup and the time the colector is called */
+typedef int (*xenstat_collect_func)(xenstat_node * node);
+/* Called to free the information collected by the collect function.  The free
+ * function will only be called on a xenstat_node if that node includes
+ * information collected by the corresponding collector. */
+typedef void (*xenstat_free_func)(xenstat_node * node);
+/* Called to free any information stored in the handle.  Note the lack of a
+ * matching init function; the collect functions should initialize on first
+ * use.  Also, the uninit function must handle the case that the collector has
+ * never been initialized. */
+typedef void (*xenstat_uninit_func)(xenstat_handle * handle);
+typedef struct xenstat_collector {
+	unsigned int flag;
+	xenstat_collect_func collect;
+	xenstat_free_func free;
+	xenstat_uninit_func uninit;
+} xenstat_collector;
+
+static int  xenstat_collect_vcpus(xenstat_node * node);
+static int  xenstat_collect_xen_version(xenstat_node * node);
+static void xenstat_free_vcpus(xenstat_node * node);
+static void xenstat_free_networks(xenstat_node * node);
+static void xenstat_free_xen_version(xenstat_node * node);
+static void xenstat_free_vbds(xenstat_node * node);
+static void xenstat_uninit_vcpus(xenstat_handle * handle);
+static void xenstat_uninit_xen_version(xenstat_handle * handle);
+static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id);
+static void xenstat_prune_domain(xenstat_node *node, unsigned int entry);
+
+static xenstat_collector collectors[] = {
+	{ XENSTAT_VCPU, xenstat_collect_vcpus,
+	  xenstat_free_vcpus, xenstat_uninit_vcpus },
+	{ XENSTAT_NETWORK, xenstat_collect_networks,
+	  xenstat_free_networks, xenstat_uninit_networks },
+	{ XENSTAT_XEN_VERSION, xenstat_collect_xen_version,
+	  xenstat_free_xen_version, xenstat_uninit_xen_version },
+	{ XENSTAT_VBD, xenstat_collect_vbds,
+	  xenstat_free_vbds, xenstat_uninit_vbds }
+};
+
+#define NUM_COLLECTORS (sizeof(collectors)/sizeof(xenstat_collector))
+
+/*
+ * libxenstat API
+ */
+xenstat_handle *xenstat_init(void)
+{
+	xenstat_handle *handle;
+
+	handle = (xenstat_handle *) calloc(1, sizeof(xenstat_handle));
+	if (handle == NULL)
+		return NULL;
+
+#if defined(PAGESIZE)
+	handle->page_size = PAGESIZE;
+#elif defined(PAGE_SIZE)
+	handle->page_size = PAGE_SIZE;
+#else
+	handle->page_size = sysconf(_SC_PAGE_SIZE);
+	if (handle->page_size < 0) {
+		perror("Failed to retrieve page size.");
+		free(handle);
+		return NULL;
+	}
+#endif
+
+	handle->xc_handle = xc_interface_open(0,0,0);
+	if (!handle->xc_handle) {
+		perror("xc_interface_open");
+		free(handle);
+		return NULL;
+	}
+
+	handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
+	if (handle->xshandle == NULL) {
+		perror("unable to open xenstore");
+		xc_interface_close(handle->xc_handle);
+		free(handle);
+		return NULL;
+	}
+
+	return handle;
+}
+
+void xenstat_uninit(xenstat_handle * handle)
+{
+	unsigned int i;
+	if (handle) {
+		for (i = 0; i < NUM_COLLECTORS; i++)
+			collectors[i].uninit(handle);
+		xc_interface_close(handle->xc_handle);
+		xs_daemon_close(handle->xshandle);
+		free(handle->priv);
+		free(handle);
+	}
+}
+
+xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
+{
+#define DOMAIN_CHUNK_SIZE 256
+	xenstat_node *node;
+	xc_physinfo_t physinfo = { 0 };
+	xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
+	int new_domains;
+	unsigned int i;
+
+	/* Create the node */
+	node = (xenstat_node *) calloc(1, sizeof(xenstat_node));
+	if (node == NULL)
+		return NULL;
+
+	/* Store the handle in the node for later access */
+	node->handle = handle;
+
+	/* Get information about the physical system */
+	if (xc_physinfo(handle->xc_handle, &physinfo) < 0) {
+		free(node);
+		return NULL;
+	}
+
+
+	node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
+        node->num_cpus = physinfo.nr_cpus;
+	node->tot_mem = ((unsigned long long)physinfo.total_pages)
+	    * handle->page_size;
+	node->free_mem = ((unsigned long long)physinfo.free_pages)
+	    * handle->page_size;
+
+	node->freeable_mb = 0;
+	/* malloc(0) is not portable, so allocate a single domain.  This will
+	 * be resized below. */
+	node->domains = malloc(sizeof(xenstat_domain));
+	if (node->domains == NULL) {
+		free(node);
+		return NULL;
+	}
+
+	node->num_domains = 0;
+	do {
+		xenstat_domain *domain, *tmp;
+
+		new_domains = xc_domain_getinfolist(handle->xc_handle,
+						    node->num_domains, 
+						    DOMAIN_CHUNK_SIZE, 
+						    domaininfo);
+		if (new_domains < 0)
+			goto err;
+
+		tmp = realloc(node->domains,
+			      (node->num_domains + new_domains)
+			      * sizeof(xenstat_domain));
+		if (tmp == NULL)
+			goto err;
+
+		node->domains = tmp;
+
+		domain = node->domains + node->num_domains;
+
+		/* zero out newly allocated memory in case error occurs below */
+		memset(domain, 0, new_domains * sizeof(xenstat_domain));
+
+		for (i = 0; i < new_domains; i++) {
+			/* Fill in domain using domaininfo[i] */
+			domain->id = domaininfo[i].domain;
+			domain->name = xenstat_get_domain_name(handle, 
+							       domain->id);
+			if (domain->name == NULL) {
+				if (errno == ENOMEM) {
+					/* fatal error */
+					xenstat_free_node(node);
+					return NULL;
+				}
+				else {
+					/* failed to get name -- this means the
+					   domain is being destroyed so simply
+					   ignore this entry */
+					continue;
+				}
+			}
+			domain->state = domaininfo[i].flags;
+			domain->cpu_ns = domaininfo[i].cpu_time;
+			domain->num_vcpus = (domaininfo[i].max_vcpu_id+1);
+			domain->vcpus = NULL;
+			domain->cur_mem =
+			    ((unsigned long long)domaininfo[i].tot_pages)
+			    * handle->page_size;
+			domain->max_mem =
+			    domaininfo[i].max_pages == UINT_MAX
+			    ? (unsigned long long)-1
+			    : (unsigned long long)(domaininfo[i].max_pages
+						   * handle->page_size);
+			domain->ssid = domaininfo[i].ssidref;
+			domain->num_networks = 0;
+			domain->networks = NULL;
+			domain->num_vbds = 0;
+			domain->vbds = NULL;
+
+			domain++;
+			node->num_domains++;
+		}
+	} while (new_domains == DOMAIN_CHUNK_SIZE);
+
+
+	/* Run all the extra data collectors requested */
+	node->flags = 0;
+	for (i = 0; i < NUM_COLLECTORS; i++) {
+		if ((flags & collectors[i].flag) == collectors[i].flag) {
+			node->flags |= collectors[i].flag;
+			if(collectors[i].collect(node) == 0) {
+				xenstat_free_node(node);
+				return NULL;
+			}
+		}
+	}
+
+	return node;
+err:
+	free(node->domains);
+	free(node);
+	return NULL;
+}
+
+void xenstat_free_node(xenstat_node * node)
+{
+	int i;
+
+	if (node) {
+		if (node->domains) {
+			for (i = 0; i < node->num_domains; i++)
+				free(node->domains[i].name);
+
+			for (i = 0; i < NUM_COLLECTORS; i++)
+				if((node->flags & collectors[i].flag)
+				   == collectors[i].flag)
+					collectors[i].free(node);
+			free(node->domains);
+		}
+		free(node);
+	}
+}
+
+xenstat_domain *xenstat_node_domain(xenstat_node * node, unsigned int domid)
+{
+	unsigned int i;
+
+	/* FIXME: binary search */
+	/* Find the appropriate domain entry in the node struct. */
+	for (i = 0; i < node->num_domains; i++) {
+		if (node->domains[i].id == domid)
+			return &(node->domains[i]);
+	}
+	return NULL;
+}
+
+xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
+					     unsigned int index)
+{
+	if (index < node->num_domains)
+		return &(node->domains[index]);
+	return NULL;
+}
+
+const char *xenstat_node_xen_version(xenstat_node * node)
+{
+	return node->handle->xen_version;
+}
+
+unsigned long long xenstat_node_tot_mem(xenstat_node * node)
+{
+	return node->tot_mem;
+}
+
+unsigned long long xenstat_node_free_mem(xenstat_node * node)
+{
+	return node->free_mem;
+}
+
+long xenstat_node_freeable_mb(xenstat_node * node)
+{
+	return node->freeable_mb;
+}
+
+unsigned int xenstat_node_num_domains(xenstat_node * node)
+{
+	return node->num_domains;
+}
+
+unsigned int xenstat_node_num_cpus(xenstat_node * node)
+{
+	return node->num_cpus;
+}
+
+/* Get information about the CPU speed */
+unsigned long long xenstat_node_cpu_hz(xenstat_node * node)
+{
+	return node->cpu_hz;
+}
+
+/* Get the domain ID for this domain */
+unsigned xenstat_domain_id(xenstat_domain * domain)
+{
+	return domain->id;
+}
+
+/* Get the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain)
+{
+	return domain->name;
+}
+
+/* Get information about how much CPU time has been used */
+unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
+{
+	return domain->cpu_ns;
+}
+
+/* Find the number of VCPUs for a domain */
+unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain)
+{
+	return domain->num_vcpus;
+}
+
+xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain, unsigned int vcpu)
+{
+	if (vcpu < domain->num_vcpus)
+		return &(domain->vcpus[vcpu]);
+	return NULL;
+}
+
+/* Find the current memory reservation for this domain */
+unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain)
+{
+	return domain->cur_mem;
+}
+
+/* Find the maximum memory reservation for this domain */
+unsigned long long xenstat_domain_max_mem(xenstat_domain * domain)
+{
+	return domain->max_mem;
+}
+
+/* Find the domain's SSID */
+unsigned int xenstat_domain_ssid(xenstat_domain * domain)
+{
+	return domain->ssid;
+}
+
+/* Get domain states */
+unsigned int xenstat_domain_dying(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_dying) == XEN_DOMINF_dying;
+}
+
+unsigned int xenstat_domain_crashed(xenstat_domain * domain)
+{
+	return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+	    && (((domain->state >> XEN_DOMINF_shutdownshift)
+		 & XEN_DOMINF_shutdownmask) == SHUTDOWN_crash);
+}
+
+unsigned int xenstat_domain_shutdown(xenstat_domain * domain)
+{
+	return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+	    && (((domain->state >> XEN_DOMINF_shutdownshift)
+		 & XEN_DOMINF_shutdownmask) != SHUTDOWN_crash);
+}
+
+unsigned int xenstat_domain_paused(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_paused) == XEN_DOMINF_paused;
+}
+
+unsigned int xenstat_domain_blocked(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_blocked) == XEN_DOMINF_blocked;
+}
+
+unsigned int xenstat_domain_running(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_running) == XEN_DOMINF_running;
+}
+
+/* Get the number of networks for a given domain */
+unsigned int xenstat_domain_num_networks(xenstat_domain * domain)
+{
+	return domain->num_networks;
+}
+
+/* Get the network handle to obtain network stats */
+xenstat_network *xenstat_domain_network(xenstat_domain * domain,
+					unsigned int network)
+{
+	if (domain->networks && network < domain->num_networks)
+		return &(domain->networks[network]);
+	return NULL;
+}
+
+/* Get the number of VBDs for a given domain */
+unsigned int xenstat_domain_num_vbds(xenstat_domain * domain)
+{
+	return domain->num_vbds;
+}
+
+/* Get the VBD handle to obtain VBD stats */
+xenstat_vbd *xenstat_domain_vbd(xenstat_domain * domain,
+				unsigned int vbd)
+{
+	if (domain->vbds && vbd < domain->num_vbds)
+		return &(domain->vbds[vbd]);
+	return NULL;
+}
+
+/*
+ * VCPU functions
+ */
+/* Collect information about VCPUs */
+static int xenstat_collect_vcpus(xenstat_node * node)
+{
+	unsigned int i, vcpu, inc_index;
+
+	/* Fill in VCPU information */
+	for (i = 0; i < node->num_domains; i+=inc_index) {
+		inc_index = 1; /* default is to increment to next domain */
+
+		node->domains[i].vcpus = malloc(node->domains[i].num_vcpus
+						* sizeof(xenstat_vcpu));
+		if (node->domains[i].vcpus == NULL)
+			return 0;
+	
+		for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) {
+			/* FIXME: need to be using a more efficient mechanism*/
+			xc_vcpuinfo_t info;
+
+			if (xc_vcpu_getinfo(node->handle->xc_handle,
+					    node->domains[i].id, vcpu, &info) != 0) {
+				if (errno == ENOMEM) {
+					/* fatal error */ 
+					return 0;
+				}
+				else {
+					/* domain is in transition - remove
+					   from list */
+					xenstat_prune_domain(node, i);
+
+					/* remember not to increment index! */
+					inc_index = 0;
+					break;
+				}
+			}
+			else {
+				node->domains[i].vcpus[vcpu].online = info.online;
+				node->domains[i].vcpus[vcpu].ns = info.cpu_time;
+			}
+		}
+	}
+	return 1;
+}
+
+/* Free VCPU information */
+static void xenstat_free_vcpus(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].vcpus);
+}
+
+/* Free VCPU information in handle - nothing to do */
+static void xenstat_uninit_vcpus(xenstat_handle * handle)
+{
+}
+
+/* Get VCPU online status */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu)
+{
+	return vcpu->online;
+}
+
+/* Get VCPU usage */
+unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu)
+{
+	return vcpu->ns;
+}
+
+/*
+ * Network functions
+ */
+
+/* Free network information */
+static void xenstat_free_networks(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].networks);
+}
+
+/* Get the network ID */
+unsigned int xenstat_network_id(xenstat_network * network)
+{
+	return network->id;
+}
+
+/* Get the number of receive bytes */
+unsigned long long xenstat_network_rbytes(xenstat_network * network)
+{
+	return network->rbytes;
+}
+
+/* Get the number of receive packets */
+unsigned long long xenstat_network_rpackets(xenstat_network * network)
+{
+	return network->rpackets;
+}
+
+/* Get the number of receive errors */
+unsigned long long xenstat_network_rerrs(xenstat_network * network)
+{
+	return network->rerrs;
+}
+
+/* Get the number of receive drops */
+unsigned long long xenstat_network_rdrop(xenstat_network * network)
+{
+	return network->rdrop;
+}
+
+/* Get the number of transmit bytes */
+unsigned long long xenstat_network_tbytes(xenstat_network * network)
+{
+	return network->tbytes;
+}
+
+/* Get the number of transmit packets */
+unsigned long long xenstat_network_tpackets(xenstat_network * network)
+{
+	return network->tpackets;
+}
+
+/* Get the number of transmit errors */
+unsigned long long xenstat_network_terrs(xenstat_network * network)
+{
+	return network->terrs;
+}
+
+/* Get the number of transmit dropped packets */
+unsigned long long xenstat_network_tdrop(xenstat_network * network)
+{
+	return network->tdrop;
+}
+
+/*
+ * Xen version functions
+ */
+
+/* Collect Xen version information */
+static int xenstat_collect_xen_version(xenstat_node * node)
+{
+	long vnum = 0;
+	xen_extraversion_t version;
+
+	/* Collect Xen version information if not already collected */
+	if (node->handle->xen_version[0] == '\0') {
+		/* Get the Xen version number and extraversion string */
+		vnum = xc_version(node->handle->xc_handle,
+			XENVER_version, NULL);
+
+		if (vnum < 0)
+			return 0;
+
+		if (xc_version(node->handle->xc_handle, XENVER_extraversion,
+			&version) < 0)
+			return 0;
+		/* Format the version information as a string and store it */
+		snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
+			 ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, version);
+	}
+
+	return 1;
+}
+
+/* Free Xen version information in node - nothing to do */
+static void xenstat_free_xen_version(xenstat_node * node)
+{
+}
+
+/* Free Xen version information in handle - nothing to do */
+static void xenstat_uninit_xen_version(xenstat_handle * handle)
+{
+}
+
+/*
+ * VBD functions
+ */
+
+/* Save VBD information */
+xenstat_vbd *xenstat_save_vbd(xenstat_domain *domain, xenstat_vbd *vbd)
+{
+        xenstat_vbd *vbds = domain->vbds;
+
+        domain->num_vbds++;
+        domain->vbds = realloc(domain->vbds,
+                               domain->num_vbds *
+                               sizeof(xenstat_vbd));
+
+        if (domain->vbds == NULL) {
+                domain->num_vbds = 0;
+                free(vbds);
+        }
+        else {
+                domain->vbds[domain->num_vbds - 1] = *vbd;
+        }
+
+        return domain->vbds;
+}
+
+/* Free VBD information */
+static void xenstat_free_vbds(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].vbds);
+}
+
+/* Get the back driver type  for Virtual Block Device */
+unsigned int xenstat_vbd_type(xenstat_vbd * vbd)
+{
+	return vbd->back_type;
+}
+
+/* Get the major number of VBD device */
+unsigned int xenstat_vbd_dev(xenstat_vbd * vbd)
+{
+	return vbd->dev;
+}
+
+/* Get the number of OO(Out of) requests */
+unsigned long long xenstat_vbd_oo_reqs(xenstat_vbd * vbd)
+{
+	return vbd->oo_reqs;
+}
+
+/* Get the number of READ requests */
+unsigned long long xenstat_vbd_rd_reqs(xenstat_vbd * vbd)
+{
+	return vbd->rd_reqs;
+}
+
+/* Get the number of WRITE requests */
+unsigned long long xenstat_vbd_wr_reqs(xenstat_vbd * vbd)
+{
+	return vbd->wr_reqs;
+}
+
+/* Get the number of READ sectors */
+unsigned long long xenstat_vbd_rd_sects(xenstat_vbd * vbd)
+{
+	return vbd->rd_sects;
+}
+
+/* Get the number of WRITE sectors */
+unsigned long long xenstat_vbd_wr_sects(xenstat_vbd * vbd)
+{
+	return vbd->wr_sects;
+}
+
+/* Returns error while getting stats (1 if error happened, 0 otherwise) */
+bool xenstat_vbd_error(xenstat_vbd * vbd)
+{
+	return vbd->error;
+}
+
+static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id)
+{
+	char path[80];
+
+	snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id);
+
+	return xs_read(handle->xshandle, XBT_NULL, path, NULL);
+}
+
+/* Remove specified entry from list of domains */
+static void xenstat_prune_domain(xenstat_node *node, unsigned int entry)
+{
+	/* nothing to do if array is empty or entry is beyond end */
+	if (node->num_domains == 0 || entry >= node->num_domains)
+		return;
+
+	/* decrement count of domains */
+	node->num_domains--;
+
+	/* shift entries following specified entry up by one */
+	if (entry < node->num_domains) {
+		xenstat_domain *domain = &node->domains[entry];
+		memmove(domain,domain+1,(node->num_domains - entry) * sizeof(xenstat_domain) );
+	}
+
+	/* zero out original last entry from node -- not
+	   strictly necessary but safer! */
+	memset(&node->domains[node->num_domains], 0, sizeof(xenstat_domain)); 
+}
diff --git a/tools/libs/stat/xenstat_freebsd.c b/tools/libs/stat/xenstat_freebsd.c
new file mode 100644
index 0000000000..0c488dffac
--- /dev/null
+++ b/tools/libs/stat/xenstat_freebsd.c
@@ -0,0 +1,47 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josht@us.ibm.com>
+ *          Judy Fischbach <jfisch@us.ibm.com>
+ *          David Hendricks <dhendrix@us.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include "xenstat_priv.h"
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+
+	return 1;
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+}
diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
new file mode 100644
index 0000000000..793263f2b6
--- /dev/null
+++ b/tools/libs/stat/xenstat_linux.c
@@ -0,0 +1,496 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <regex.h>
+
+#include "xenstat_priv.h"
+
+#define SYSFS_VBD_PATH "/sys/bus/xen-backend/devices"
+
+struct priv_data {
+	FILE *procnetdev;
+	DIR *sysfsvbd;
+};
+
+static struct priv_data *
+get_priv_data(xenstat_handle *handle)
+{
+	if (handle->priv != NULL)
+		return handle->priv;
+
+	handle->priv = malloc(sizeof(struct priv_data));
+	if (handle->priv == NULL)
+		return (NULL);
+
+	((struct priv_data *)handle->priv)->procnetdev = NULL;
+	((struct priv_data *)handle->priv)->sysfsvbd = NULL;
+
+	return handle->priv;
+}
+
+/* Expected format of /proc/net/dev */
+static const char PROCNETDEV_HEADER[] =
+    "Inter-|   Receive                                                |"
+    "  Transmit\n"
+    " face |bytes    packets errs drop fifo frame compressed multicast|"
+    "bytes    packets errs drop fifo colls carrier compressed\n";
+
+/* We need to get the name of the bridge interface for use with bonding interfaces */
+/* Use excludeName parameter to avoid adding bridges we don't care about, eg. virbr0 */
+static void getBridge(char *excludeName, char *result, size_t resultLen)
+{
+	struct dirent *de;
+	DIR *d;
+
+	char tmp[512] = { 0 };
+
+	d = opendir("/sys/class/net");
+	while ((de = readdir(d)) != NULL) {
+		if ((strlen(de->d_name) > 0) && (de->d_name[0] != '.')
+			&& (strstr(de->d_name, excludeName) == NULL)) {
+				sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
+
+				if (access(tmp, F_OK) == 0) {
+					strncpy(result, de->d_name, resultLen - 1);
+					result[resultLen - 1] = 0;
+				}
+		}
+	}
+
+	closedir(d);
+}
+
+/* parseNetLine provides regular expression based parsing for lines from /proc/net/dev, all the */
+/* information are parsed but not all are used in our case, ie. for xenstat */
+static int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsigned long long *rxPackets,
+		unsigned long long *rxErrs, unsigned long long *rxDrops, unsigned long long *rxFifo,
+		unsigned long long *rxFrames, unsigned long long *rxComp, unsigned long long *rxMcast,
+		unsigned long long *txBytes, unsigned long long *txPackets, unsigned long long *txErrs,
+		unsigned long long *txDrops, unsigned long long *txFifo, unsigned long long *txColls,
+		unsigned long long *txCarrier, unsigned long long *txComp)
+{
+	/* Temporary/helper variables */
+	int ret;
+	char *tmp;
+	int i = 0, x = 0, col = 0;
+	regex_t r;
+	regmatch_t matches[19];
+	int num = 19;
+
+	/* Regular exception to parse all the information from /proc/net/dev line */
+	char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
+			"[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*"
+			"([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)";
+
+	/* Initialize all variables called has passed as non-NULL to zeros */
+	if (iface != NULL)
+		memset(iface, 0, sizeof(*iface));
+	if (rxBytes != NULL)
+		*rxBytes = 0;
+	if (rxPackets != NULL)
+		*rxPackets = 0;
+	if (rxErrs != NULL)
+		*rxErrs = 0;
+	if (rxDrops != NULL)
+		*rxDrops = 0;
+	if (rxFifo != NULL)
+		*rxFifo = 0;
+	if (rxFrames != NULL)
+		*rxFrames = 0;
+	if (rxPackets != NULL)
+		*rxPackets = 0;
+	if (rxComp != NULL)
+		*rxComp = 0;
+	if (txBytes != NULL)
+		*txBytes = 0;
+	if (txPackets != NULL)
+		*txPackets = 0;
+	if (txErrs != NULL)
+		*txErrs = 0;
+	if (txDrops != NULL)
+		*txDrops = 0;
+	if (txFifo != NULL)
+		*txFifo = 0;
+	if (txColls != NULL)
+		*txColls = 0;
+	if (txCarrier != NULL)
+		*txCarrier = 0;
+	if (txComp != NULL)
+		*txComp = 0;
+
+	if ((ret = regcomp(&r, regex, REG_EXTENDED))) {
+		regfree(&r);
+		return ret;
+	}
+
+	tmp = (char *)malloc( sizeof(char) );
+	if (regexec (&r, line, num, matches, REG_EXTENDED) == 0){
+		for (i = 1; i < num; i++) {
+			/* The expression matches are empty sometimes so we need to check it first */
+			if (matches[i].rm_eo - matches[i].rm_so > 0) {
+				/* Col variable contains current id of non-empty match */
+				col++;
+				tmp = (char *)realloc(tmp, (matches[i].rm_eo - 
+							matches[i].rm_so + 1) * sizeof(char));
+				for (x = matches[i].rm_so; x < matches[i].rm_eo; x++)
+					tmp[x - matches[i].rm_so] = line[x];
+
+				/* We populate all the fields from /proc/net/dev line */
+				if (i > 1) {
+					unsigned long long ullTmp = strtoull(tmp, NULL, 10);
+
+					switch (col) {
+						case 2: if (rxBytes != NULL)
+								*rxBytes = ullTmp;
+							break;
+						case 3: if (rxPackets != NULL)
+								*rxPackets = ullTmp;
+							break;
+						case 4: if (rxErrs != NULL)
+								*rxErrs = ullTmp;
+							break;
+						case 5: if (rxDrops != NULL)
+								*rxDrops = ullTmp;
+							break;
+						case 6: if (rxFifo != NULL)
+								*rxFifo = ullTmp;
+							break;
+						case 7: if (rxFrames != NULL)
+								*rxFrames = ullTmp;
+							break;
+						case 8: if (rxComp != NULL)
+								*rxComp = ullTmp;
+							break;
+						case 9: if (rxMcast != NULL)
+								*rxMcast = ullTmp;
+							break;
+						case 10: if (txBytes != NULL)
+								*txBytes = ullTmp;
+							break;
+						case 11: if (txPackets != NULL)
+								*txPackets = ullTmp;
+							break;
+						case 12: if (txErrs != NULL)
+								*txErrs = ullTmp;
+							break;
+						case 13: if (txDrops != NULL)
+								*txDrops = ullTmp;
+							break;
+						case 14: if (txFifo != NULL)
+								*txFifo = ullTmp;
+							break;
+						case 15: if (txColls != NULL)
+								*txColls = ullTmp;
+							break;
+						case 16: if (txCarrier != NULL)
+								*txCarrier = ullTmp;
+							break;
+						case 17: if (txComp != NULL)
+								*txComp = ullTmp;
+							break;
+					}
+				}
+				else
+				/* There were errors when parsing this directly in RE. strpbrk() helps */
+				if (iface != NULL) {
+					char *tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+					if (tmp2 != NULL)
+						strcpy(iface, tmp2);
+				}
+
+				memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so);
+			}
+		}
+	}
+
+	free(tmp);
+	regfree(&r);
+
+	return 0;
+}
+
+/* Find out the domid and network number given an interface name.
+ * Return 0 if the iface cannot be recognized as a Xen VIF. */
+static int get_iface_domid_network(const char *iface, unsigned int *domid_p, unsigned int *netid_p)
+{
+	char nodename_path[48];
+	FILE * nodename_file;
+	int ret;
+
+	snprintf(nodename_path, 48, "/sys/class/net/%s/device/nodename", iface);
+	nodename_file = fopen(nodename_path, "r");
+	if (nodename_file != NULL) {
+		ret = fscanf(nodename_file, "backend/vif/%u/%u", domid_p, netid_p);
+		fclose(nodename_file);
+		if (ret == 2)
+			return 1;
+	}
+
+	if (sscanf(iface, "vif%u.%u", domid_p, netid_p) == 2)
+		return 1;
+
+	return 0;
+}
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+	/* Helper variables for parseNetDevLine() function defined above */
+	int i;
+	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
+	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
+
+	struct priv_data *priv = get_priv_data(node->handle);
+
+	if (priv == NULL) {
+		perror("Allocation error");
+		return 0;
+	}
+
+	/* Open and validate /proc/net/dev if we haven't already */
+	if (priv->procnetdev == NULL) {
+		char header[sizeof(PROCNETDEV_HEADER)];
+		priv->procnetdev = fopen("/proc/net/dev", "r");
+		if (priv->procnetdev == NULL) {
+			perror("Error opening /proc/net/dev");
+			return 0;
+		}
+
+		/* Validate the format of /proc/net/dev */
+		if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
+			  priv->procnetdev) != 1) {
+			perror("Error reading /proc/net/dev header");
+			return 0;
+		}
+		header[sizeof(PROCNETDEV_HEADER) - 1] = '\0';
+		if (strcmp(header, PROCNETDEV_HEADER) != 0) {
+			fprintf(stderr,
+				"Unexpected /proc/net/dev format\n");
+			return 0;
+		}
+	}
+
+	/* Fill in networks */
+	/* FIXME: optimize this */
+	fseek(priv->procnetdev, sizeof(PROCNETDEV_HEADER) - 1,
+	      SEEK_SET);
+
+	/* We get the bridge devices for use with bonding interface to get bonding interface stats */
+	getBridge("vir", devBridge, sizeof(devBridge));
+	snprintf(devNoBridge, sizeof(devNoBridge), "p%s", devBridge);
+
+	while (fgets(line, 512, priv->procnetdev)) {
+		xenstat_domain *domain;
+		xenstat_network net;
+		unsigned int domid;
+
+		parseNetDevLine(line, iface, &rxBytes, &rxPackets, &rxErrs, &rxDrops, NULL, NULL, NULL,
+				NULL, &txBytes, &txPackets, &txErrs, &txDrops, NULL, NULL, NULL, NULL);
+
+		/* If the device parsed is network bridge and both tx & rx packets are zero, we are most */
+		/* likely using bonding so we alter the configuration for dom0 to have bridge stats */
+		if ((strstr(iface, devBridge) != NULL) &&
+		    (strstr(iface, devNoBridge) == NULL) &&
+		    ((domain = xenstat_node_domain(node, 0)) != NULL)) {
+			for (i = 0; i < domain->num_networks; i++) {
+				if ((domain->networks[i].id != 0) ||
+				    (domain->networks[i].tbytes != 0) ||
+				    (domain->networks[i].rbytes != 0))
+					continue;
+				domain->networks[i].tbytes = txBytes;
+				domain->networks[i].tpackets = txPackets;
+				domain->networks[i].terrs = txErrs;
+				domain->networks[i].tdrop = txDrops;
+				domain->networks[i].rbytes = rxBytes;
+				domain->networks[i].rpackets = rxPackets;
+				domain->networks[i].rerrs = rxErrs;
+				domain->networks[i].rdrop = rxDrops;
+			}
+		}
+		else /* Otherwise we need to preserve old behaviour */
+		if (get_iface_domid_network(iface, &domid, &net.id)) {
+
+			net.tbytes = txBytes;
+			net.tpackets = txPackets;
+			net.terrs = txErrs;
+			net.tdrop = txDrops;
+			net.rbytes = rxBytes;
+			net.rpackets = rxPackets;
+			net.rerrs = rxErrs;
+			net.rdrop = rxDrops;
+
+		/* FIXME: this does a search for the domid */
+		  domain = xenstat_node_domain(node, domid);
+		  if (domain == NULL) {
+			fprintf(stderr,
+				"Found interface vif%u.%u but domain %u"
+				" does not exist.\n", domid, net.id,
+				domid);
+			continue;
+		  }
+		  if (domain->networks == NULL) {
+			domain->num_networks = 1;
+			domain->networks = malloc(sizeof(xenstat_network));
+		  } else {
+			struct xenstat_network *tmp;
+			domain->num_networks++;
+			tmp = realloc(domain->networks,
+				      domain->num_networks *
+				      sizeof(xenstat_network));
+			if (tmp == NULL)
+				free(domain->networks);
+			domain->networks = tmp;
+		  }
+		  if (domain->networks == NULL)
+			return 0;
+		  domain->networks[domain->num_networks - 1] = net;
+          }
+        }
+
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->procnetdev != NULL)
+		fclose(priv->procnetdev);
+}
+
+static int read_attributes_vbd(const char *vbd_directory, const char *what, char *ret, int cap)
+{
+	static char file_name[80];
+	int fd, num_read;
+
+	snprintf(file_name, sizeof(file_name), "%s/%s/%s",
+		SYSFS_VBD_PATH, vbd_directory, what);
+	fd = open(file_name, O_RDONLY, 0);
+	if (fd==-1) return -1;
+	num_read = read(fd, ret, cap - 1);
+	close(fd);
+	if (num_read<=0) return -1;
+	ret[num_read] = '\0';
+	return num_read;
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+	struct dirent *dp;
+	struct priv_data *priv = get_priv_data(node->handle);
+
+	if (priv == NULL) {
+		perror("Allocation error");
+		return 0;
+	}
+
+	if (priv->sysfsvbd == NULL) {
+		priv->sysfsvbd = opendir(SYSFS_VBD_PATH);
+		if (priv->sysfsvbd == NULL) {
+			perror("Error opening " SYSFS_VBD_PATH);
+			return 0;
+		}
+	}
+
+	/* Get qdisk statistics */
+	read_attributes_qdisk(node);
+
+	rewinddir(priv->sysfsvbd);
+
+	for(dp = readdir(priv->sysfsvbd); dp != NULL ;
+	    dp = readdir(priv->sysfsvbd)) {
+		xenstat_domain *domain;
+		xenstat_vbd vbd;
+		unsigned int domid;
+		int ret;
+		char buf[256];
+
+		ret = sscanf(dp->d_name, "%3s-%u-%u", buf, &domid, &vbd.dev);
+		if (ret != 3)
+			continue;
+		if (!(strstr(buf, "vbd")) && !(strstr(buf, "tap")))
+			continue;
+
+		if (strcmp(buf,"vbd") == 0)
+			vbd.back_type = 1;
+		else if (strcmp(buf,"tap") == 0)
+			vbd.back_type = 2;
+		else
+			vbd.back_type = 0;
+
+		domain = xenstat_node_domain(node, domid);
+		if (domain == NULL) {
+			fprintf(stderr,
+				"Found interface %s-%u-%u but domain %u"
+				" does not exist.\n",
+				buf, domid, vbd.dev, domid);
+			continue;
+		}
+
+		if (vbd.back_type == 1 || vbd.back_type == 2)
+		{
+
+			vbd.error = 0;
+
+			if ((read_attributes_vbd(dp->d_name, "statistics/oo_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.oo_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/rd_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.rd_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/wr_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/rd_sect", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_sects)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/wr_sect", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_sects)) != 1))
+			{
+				vbd.error = 1;
+			}
+		}
+		else
+		{
+			vbd.error = 1;
+		}
+		if ((xenstat_save_vbd(domain, &vbd)) == NULL) {
+			perror("Allocation error");
+			return 0;
+		}
+	}
+
+	return 1;	
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->sysfsvbd != NULL)
+		closedir(priv->sysfsvbd);
+}
diff --git a/tools/libs/stat/xenstat_netbsd.c b/tools/libs/stat/xenstat_netbsd.c
new file mode 100644
index 0000000000..6e9d6aee10
--- /dev/null
+++ b/tools/libs/stat/xenstat_netbsd.c
@@ -0,0 +1,97 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josht@us.ibm.com>
+ *          Judy Fischbach <jfisch@us.ibm.com>
+ *          David Hendricks <dhendrix@us.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "xenstat_priv.h"
+
+#define SYSFS_VBD_PATH "/sys/devices/xen-backend/"
+
+struct priv_data {
+	FILE *procnetdev;
+	DIR *sysfsvbd;
+};
+
+static struct priv_data *
+get_priv_data(xenstat_handle *handle)
+{
+	if (handle->priv != NULL)
+		return handle->priv;
+
+	handle->priv = malloc(sizeof(struct priv_data));
+	if (handle->priv == NULL)
+		return (NULL);
+
+	((struct priv_data *)handle->priv)->procnetdev = NULL;
+	((struct priv_data *)handle->priv)->sysfsvbd = NULL;
+
+	return handle->priv;
+}
+
+/* Expected format of /proc/net/dev */
+static const char PROCNETDEV_HEADER[] =
+    "Inter-|   Receive                                                |"
+    "  Transmit\n"
+    " face |bytes    packets errs drop fifo frame compressed multicast|"
+    "bytes    packets errs drop fifo colls carrier compressed\n";
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+	/* XXX fixme: implement code to get stats from libkvm ! */
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->procnetdev != NULL)
+		fclose(priv->procnetdev);
+}
+
+static int read_attributes_vbd(const char *vbd_directory, const char *what, char *ret, int cap)
+{
+	/* XXX implement */
+	return 0;
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+	return 1;	
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->sysfsvbd != NULL)
+		closedir(priv->sysfsvbd);
+}
diff --git a/tools/libs/stat/xenstat_priv.h b/tools/libs/stat/xenstat_priv.h
new file mode 100644
index 0000000000..4eb44a8ebb
--- /dev/null
+++ b/tools/libs/stat/xenstat_priv.h
@@ -0,0 +1,108 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef XENSTAT_PRIV_H
+#define XENSTAT_PRIV_H
+
+#include <sys/types.h>
+#include <xenstore.h>
+#include "xenstat.h"
+
+#include "xenctrl.h"
+
+#define SHORT_ASC_LEN 5                 /* length of 65535 */
+#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
+
+struct xenstat_handle {
+	xc_interface *xc_handle;
+	struct xs_handle *xshandle; /* xenstore handle */
+	int page_size;
+	void *priv;
+	char xen_version[VERSION_SIZE]; /* xen version running on this node */
+};
+
+struct xenstat_node {
+	xenstat_handle *handle;
+	unsigned int flags;
+	unsigned long long cpu_hz;
+	unsigned int num_cpus;
+	unsigned long long tot_mem;
+	unsigned long long free_mem;
+	unsigned int num_domains;
+	xenstat_domain *domains;	/* Array of length num_domains */
+	long freeable_mb;
+};
+
+struct xenstat_domain {
+	unsigned int id;
+	char *name;
+	unsigned int state;
+	unsigned long long cpu_ns;
+	unsigned int num_vcpus;		/* No. vcpus configured for domain */
+	xenstat_vcpu *vcpus;		/* Array of length num_vcpus */
+	unsigned long long cur_mem;	/* Current memory reservation */
+	unsigned long long max_mem;	/* Total memory allowed */
+	unsigned int ssid;
+	unsigned int num_networks;
+	xenstat_network *networks;	/* Array of length num_networks */
+	unsigned int num_vbds;
+	xenstat_vbd *vbds;
+};
+
+struct xenstat_vcpu {
+	unsigned int online;
+	unsigned long long ns;
+};
+
+struct xenstat_network {
+	unsigned int id;
+	/* Received */
+	unsigned long long rbytes;
+	unsigned long long rpackets;
+	unsigned long long rerrs;
+	unsigned long long rdrop;
+	/* Transmitted */
+	unsigned long long tbytes;
+	unsigned long long tpackets;
+	unsigned long long terrs;
+	unsigned long long tdrop;
+};
+
+struct xenstat_vbd {
+	unsigned int back_type;
+	unsigned int dev;
+	unsigned int error;
+	unsigned long long oo_reqs;
+	unsigned long long rd_reqs;
+	unsigned long long wr_reqs;
+	unsigned long long rd_sects;
+	unsigned long long wr_sects;
+};
+
+extern int xenstat_collect_networks(xenstat_node * node);
+extern void xenstat_uninit_networks(xenstat_handle * handle);
+extern int xenstat_collect_vbds(xenstat_node * node);
+extern void xenstat_uninit_vbds(xenstat_handle * handle);
+extern void read_attributes_qdisk(xenstat_node * node);
+extern xenstat_vbd *xenstat_save_vbd(xenstat_domain * domain, xenstat_vbd * vbd);
+
+#endif /* XENSTAT_PRIV_H */
diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c
new file mode 100644
index 0000000000..19b236e7b6
--- /dev/null
+++ b/tools/libs/stat/xenstat_qmp.c
@@ -0,0 +1,446 @@
+/* libxenstat: statistics-collection library for Xen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <poll.h>
+#include <sys/un.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <xenctrl.h>
+
+#include "xenstat_priv.h"
+#include "_paths.h"
+
+#ifdef HAVE_YAJL_YAJL_VERSION_H
+#  include <yajl/yajl_version.h>
+#endif
+
+/* YAJL version check */
+#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+#  define HAVE_YAJL_V2 1
+#endif
+
+#ifdef HAVE_YAJL_V2
+
+#include <yajl/yajl_tree.h>
+
+static unsigned char *qmp_query(int, char *);
+
+enum query_blockstats {
+    QMP_STATS_RETURN  = 0,
+    QMP_STATS_DEVICE  = 1,
+    QMP_STATS         = 2,
+    QMP_RD_BYTES      = 3,
+    QMP_WR_BYTES      = 4,
+    QMP_RD_OPERATIONS = 5,
+    QMP_WR_OPERATIONS = 6,
+};
+
+enum query_block {
+    QMP_BLOCK_RETURN  = 0,
+    QMP_BLOCK_DEVICE  = 1,
+    QMP_INSERTED      = 2,
+    QMP_FILE          = 3,
+};
+
+
+/* Given the qmp device name, get the image filename associated with it
+   QMP Syntax for querying block information:
+     In: { "execute": "query-block" }
+     Out: {"return": [{
+            "device": 'str, "locked": 'bool', "removable": bool,
+            "inserted": {
+              "iops_rd": 'int',
+              "image": {
+                "virtual-size": 'int', "filename": 'str', "cluster-size": 'int',
+                "format": 'str', "actual-size": 'int', "dirty-flag": 'bool'
+              },
+              "iops_wr": 'int', "ro": 'bool', "backing_file_depth": 'int',
+              "drv": 'str', "iops": 'int', "bps_wr": 'int', "encrypted": 'bool',
+              "bps": 'int', "bps_rd": 'int',
+              "file": 'str', "encryption_key_missing": 'bool'
+            },
+            "type": 'str'
+          }]}
+*/
+static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
+{
+	char *tmp, *file = NULL;
+	char *query_block_cmd = "{ \"execute\": \"query-block\" }";
+	static const char *const qblock[] = {
+		[ QMP_BLOCK_RETURN  ] = "return",
+		[ QMP_BLOCK_DEVICE  ] = "device",
+		[ QMP_INSERTED      ] = "inserted",
+		[ QMP_FILE          ] = "file",
+	};
+	const char *ptr[] = {0, 0};
+	unsigned char *qmp_stats;
+	yajl_val info, ret_obj, dev_obj, n;
+	int i;
+
+	if ((qmp_stats = qmp_query(qfd, query_block_cmd)) == NULL)
+		return NULL;
+
+	/* Use libyajl version 2.0.3 or newer for the tree parser feature with bug fixes */
+	info = yajl_tree_parse((char *)qmp_stats, NULL, 0);
+	free(qmp_stats);
+	if (info == NULL)
+		return NULL;
+
+	ptr[0] = qblock[QMP_BLOCK_RETURN]; /* "return" */
+	if ((ret_obj = yajl_tree_get(info, ptr, yajl_t_array)) == NULL)
+		goto done;
+
+	for (i=0; i<YAJL_GET_ARRAY(ret_obj)->len; i++) {
+		n = YAJL_GET_ARRAY(ret_obj)->values[i];
+
+		ptr[0] = qblock[QMP_BLOCK_DEVICE]; /* "device" */
+		if ((dev_obj = yajl_tree_get(n, ptr, yajl_t_any)) != NULL) {
+			tmp = YAJL_GET_STRING(dev_obj);
+			if (!tmp || strcmp(qmp_devname, tmp))
+				continue;
+		}
+		else
+			continue;
+
+		ptr[0] = qblock[QMP_INSERTED]; /* "inserted" */
+		n = yajl_tree_get(n, ptr, yajl_t_any);
+		if (n) {
+			ptr[0] = qblock[QMP_FILE]; /* "file" */
+			n = yajl_tree_get(n, ptr, yajl_t_any);
+			if (n && YAJL_IS_STRING(n)) {
+				tmp = YAJL_GET_STRING(n);
+				file = malloc(strlen(tmp)+1);
+				if (file != NULL)
+					strcpy(file, tmp);
+				goto done;
+			}
+		}
+	}
+done:
+	yajl_tree_free(info);
+	return file;
+}
+
+
+/* Given a QMP device name, lookup the associated xenstore qdisk device id */
+static void lookup_xenstore_devid(xenstat_node * node, unsigned int domid, char *qmp_devname,
+	int qfd, unsigned int *dev, unsigned int *sector_size)
+{
+	char **dev_ids, *tmp, *ptr, *image, path[80];
+	unsigned int num_dev_ids;
+	int i, devid;
+
+	/* Get all the qdisk dev IDs associated with the this VM */
+	snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i", domid);
+	dev_ids = xs_directory(node->handle->xshandle, XBT_NULL, path, &num_dev_ids);
+	if (dev_ids == NULL) {
+		return;
+	}
+
+	/* Get the filename of the image associated with this QMP device */
+	image = qmp_get_block_image(node, qmp_devname, qfd);
+	if (image == NULL) {
+		free(dev_ids);
+		return;
+	}
+
+	/* Look for a matching image in xenstore */
+	for (i=0; i<num_dev_ids; i++) {
+		devid = atoi(dev_ids[i]);
+		/* Get the xenstore name of the image */
+		snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i/%i/params", domid, devid);
+		if ((ptr = xs_read(node->handle->xshandle, XBT_NULL, path, NULL)) == NULL)
+			continue;
+
+		/* Get to actual path in string */
+		if ((tmp = strchr(ptr, '/')) == NULL)
+			tmp = ptr;
+		if (!strcmp(tmp,image)) {
+			*dev = devid;
+			free(ptr);
+
+			/* Get the xenstore sector size of the image while we're here */
+			snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i/%i/sector-size", domid, devid);
+			if ((ptr = xs_read(node->handle->xshandle, XBT_NULL, path, NULL)) != NULL) {
+				*sector_size = atoi((char *)ptr);
+				free(ptr);
+			}
+			break;
+		}
+		free(ptr);
+	}
+
+	free(image);
+	free(dev_ids);
+}
+
+/* Parse the stats buffer which contains I/O data for all the disks belonging to domid */
+static void qmp_parse_stats(xenstat_node *node, unsigned int domid, unsigned char *stats_buf, int qfd)
+{
+	char *qmp_devname;
+	static const char *const qstats[] = {
+		[ QMP_STATS_RETURN  ] = "return",
+		[ QMP_STATS_DEVICE  ] = "device",
+		[ QMP_STATS         ] = "stats",
+		[ QMP_RD_BYTES      ] = "rd_bytes",
+		[ QMP_WR_BYTES      ] = "wr_bytes",
+		[ QMP_RD_OPERATIONS ] = "rd_operations",
+		[ QMP_WR_OPERATIONS ] = "wr_operations",
+	};
+	const char *ptr[] = {0, 0};
+	yajl_val info, ret_obj, stats_obj, n;
+	xenstat_vbd vbd;
+	xenstat_domain *domain;
+	unsigned int sector_size = 512;
+	int i, j;
+
+	/* Use libyajl version 2.0.3 or newer for the tree parser feature */
+	if ((info = yajl_tree_parse((char *)stats_buf, NULL, 0)) == NULL)
+		return;
+
+	ptr[0] = qstats[QMP_STATS_RETURN]; /* "return" */
+	if ((ret_obj = yajl_tree_get(info, ptr, yajl_t_array)) == NULL)
+		goto done;
+
+	/* Array of devices */
+	for (i=0; i<YAJL_GET_ARRAY(ret_obj)->len; i++) {
+		memset(&vbd, 0, sizeof(xenstat_vbd));
+		qmp_devname = NULL;
+		stats_obj = YAJL_GET_ARRAY(ret_obj)->values[i];
+
+		ptr[0] = qstats[QMP_STATS_DEVICE]; /* "device" */
+		if ((n = yajl_tree_get(stats_obj, ptr, yajl_t_any)) != NULL)
+			qmp_devname = YAJL_GET_STRING(n);
+
+		ptr[0] = qstats[QMP_STATS]; /* "stats" */
+		stats_obj = yajl_tree_get(stats_obj, ptr, yajl_t_object);
+		if (stats_obj && YAJL_IS_OBJECT(stats_obj)) {
+			for (j=3; j<7; j++) {
+				ptr[0] = qstats[j];
+				n = yajl_tree_get(stats_obj, ptr, yajl_t_number);
+				if (n && YAJL_IS_NUMBER(n)) {
+					switch(j) {
+					case QMP_RD_BYTES: /* "rd_bytes" */
+						vbd.rd_sects = YAJL_GET_INTEGER(n) / sector_size;
+						break;
+					case QMP_WR_BYTES: /* "wr_bytes" */
+						vbd.wr_sects = YAJL_GET_INTEGER(n) / sector_size;
+						break;
+					case QMP_RD_OPERATIONS: /* "rd_operations" */
+						vbd.rd_reqs = YAJL_GET_INTEGER(n);
+						break;
+					case QMP_WR_OPERATIONS: /* "wr_operations" */
+						vbd.wr_reqs = YAJL_GET_INTEGER(n);
+						break;
+					}
+				}
+			}
+			/* With the QMP device name, lookup the xenstore qdisk device ID and set vdb.dev */
+			if (qmp_devname)
+				lookup_xenstore_devid(node, domid, qmp_devname, qfd, &vbd.dev, &sector_size);
+			if ((domain = xenstat_node_domain(node, domid)) == NULL)
+				continue;
+			if ((xenstat_save_vbd(domain, &vbd)) == NULL)
+				goto done;
+		}
+	}
+done:
+	yajl_tree_free(info);
+}
+
+/* Write a command via the QMP. Returns number of bytes written */
+static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
+{
+	size_t pos = 0;
+	ssize_t res;
+
+	while (cmd_len > pos) {
+		res = write(qfd, cmd + pos, cmd_len - pos);
+		switch (res) {
+		case -1:
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return 0;
+		case 0:
+			errno = EPIPE;
+			return pos;
+		default:
+			pos += (size_t)res;
+		}
+	}
+	return pos;
+}
+
+/* Read the data sent in response to a QMP execute query. Returns 1 for success */
+static int qmp_read(int qfd, unsigned char **qstats)
+{
+	unsigned char buf[1024], *ptr;
+	struct pollfd pfd[1];
+	int n, qsize = 0;
+
+	*qstats = NULL;
+	pfd[0].fd = qfd;
+	pfd[0].events = POLLIN;
+	while ((n = poll(pfd, 1, 10)) > 0) {
+		if (pfd[0].revents & POLLIN) {
+			if ((n = read(qfd, buf, sizeof(buf))) < 0) {
+				free(*qstats);
+				return 0;
+			}
+			ptr = realloc(*qstats, qsize+n+1);
+			if (ptr == NULL) {
+				free(*qstats);
+				return 0;
+			}
+			memcpy(&ptr[qsize], buf, n);
+			qsize += n;
+			ptr[qsize] = 0;
+			*qstats = ptr;
+		}
+	}
+	return 1;
+}
+
+/* With the given cmd, query QMP for requested data. Returns allocated buffer containing data or NULL */
+static unsigned char *qmp_query(int qfd, char *cmd)
+{
+	unsigned char *qstats = NULL;
+	int n;
+
+	n = strlen(cmd);
+	if (qmp_write(qfd, cmd, n) != n)
+		return NULL;
+	if (!qmp_read(qfd, &qstats))
+		return NULL;
+	return qstats;
+}
+
+/* Returns a socket connected to the QMP socket. Returns -1 on failure. */
+static int qmp_connect(char *path)
+{
+	struct sockaddr_un sun;
+	int s;
+
+	if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+		return -1;
+	(void)fcntl(s, F_SETFD, 1);
+
+	memset(&sun, 0, sizeof(struct sockaddr_un));
+	sun.sun_family = AF_UNIX;
+
+	if (strlen(path) >= sizeof(sun.sun_path)) {
+		close(s);
+		return -1;
+	}
+
+	strcpy(sun.sun_path, path);
+	if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+		close(s);
+		return -1;
+	}
+
+	return s;
+}
+
+/* Gather the qdisk statistics by querying QMP
+   Resources: http://wiki.qemu.org/QMP and qmp-commands.hx from the qemu code
+   QMP Syntax for entering command mode. This command must be issued before
+   issuing any other command:
+     In: {"execute": "qmp_capabilities"}
+     Out: {"return": {}}
+   QMP Syntax for querying block statistics:
+     In: { "execute": "query-blockstats" }
+     Out: {"return": [{
+            "device": 'str',
+            "parent": {
+              "stats": {
+                "flush_total_time_ns": 'int', "wr_highest_offset": 'int',
+                "wr_total_time_ns": 'int', "wr_bytes": 'int',
+                "rd_total_time_ns": 'int', "flush_operations": 'int',
+                "wr_operations": 'int', "rd_bytes": 'int', "rd_operations": 'int'
+              }
+            },
+            "stats": {
+              "flush_total_time_ns": 'int', "wr_highest_offset": 'int',
+              "wr_total_time_ns": 'int', "wr_bytes": 'int',
+              "rd_total_time_ns": 'int', "flush_operations": 'int',
+              "wr_operations": 'int', "rd_bytes": 'int', "rd_operations": 'int'
+            }
+          }]}
+*/
+static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain)
+{
+	char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
+	char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
+	unsigned char *qmp_stats, *val;
+	char path[80];
+	int qfd;
+
+	/* Verify that qdisk disks are used with this VM */
+	snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i", domain);
+	val = xs_read(node->handle->xshandle, XBT_NULL, path, NULL);
+	if (val == NULL)
+		return;
+	free(val);
+
+	/* Connect to this VMs QMP socket */
+	snprintf(path, sizeof(path), XEN_RUN_DIR "/qmp-libxenstat-%i", domain);
+	if ((qfd = qmp_connect(path)) < 0)
+		return;
+
+	/* First enable QMP capabilities so that we can query for data */
+	if ((qmp_stats = qmp_query(qfd, cmd_mode)) != NULL) {
+		free(qmp_stats);
+		/* Query QMP for this VMs blockstats */
+		qmp_stats = qmp_query(qfd, query_blockstats_cmd);
+		if (qmp_stats != NULL) {
+			qmp_parse_stats(node, domain, qmp_stats, qfd);
+			free(qmp_stats);
+		}
+	}
+	close(qfd);
+}
+
+void read_attributes_qdisk(xenstat_node * node)
+{
+	xc_domaininfo_t dominfo[1024];
+	int i, num_doms;
+	domid_t next_domid = 0;
+
+	for (;;) {
+		num_doms = xc_domain_getinfolist(node->handle->xc_handle,
+						 next_domid, 1024, dominfo);
+		if (num_doms <= 0)
+			return;
+
+		for (i = 0; i < num_doms; i++)
+			if (dominfo[i].domain > 0)
+				read_attributes_qdisk_dom(node, dominfo[i].domain);
+
+		next_domid = dominfo[num_doms - 1].domain + 1;
+	}
+}
+
+#else /* !HAVE_YAJL_V2 */
+
+/* Statistics gathering for qdisks requires at least yajl v2 */
+void read_attributes_qdisk(xenstat_node * node)
+{
+}
+
+#endif /* !HAVE_YAJL_V2 */


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:14:54 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:14:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy3x-0000v1-W0; Wed, 09 Sep 2020 11:14:53 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy3w-0000um-Ef
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:52 +0000
X-Inumbo-ID: 2baff471-5df3-4438-98b6-d2d20a654a03
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2baff471-5df3-4438-98b6-d2d20a654a03;
 Wed, 09 Sep 2020 11:14:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=qcLFL7cLQVRb9df0cASp83O1/0YE/wx+uSgaXcMVhkE=; b=JuhoX3Fqh0SJrUntFitkZcupvf
 vO692Tqf/fP9QI9McPz7CN4tBz87fNZDOZWeVcQnUgQSHNqXAQVb3DKAh040QyX+a82PatN2Jymni
 h0dkKbZFclJ3twZnrCJq2yjp1gCfqT6+olDEOeQ2QQInpUhcF0niOhbutCGV5we4/JC0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3v-00068O-Eh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:51 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy3v-0001bh-Du
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:14:51 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxl: fix dependencies of libxl tests
Message-Id: <E1kFy3v-0001bh-Du@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:14:51 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3df903ec5270673bb3b3834e7b8387e85c2c73ef
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:39 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: fix dependencies of libxl tests
    
    Today building the libxl internal tests depends on libxlutil having
    been built, in spite of the tests not using any functionality of
    libxlutil. Fix this by dropping the dependency.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index b3815390f3..4fbd9ebbca 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -324,14 +324,14 @@ libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $(LIBXLU_OBJS) libxenlight.so
 libxlutil.a: $(LIBXLU_OBJS)
 	$(AR) rcs libxlutil.a $^
 
-test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
+test_%: test_%.o test_common.o libxenlight_test.so
 	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
-testidl: testidl.o libxlutil.so libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
+testidl: testidl.o libxenlight.so
+	$(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:15:09 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:15:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy4D-0000wh-1d; Wed, 09 Sep 2020 11:15:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy4B-0000um-Dh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:07 +0000
X-Inumbo-ID: 889076ce-b362-4b96-8290-0d4c8df3499c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 889076ce-b362-4b96-8290-0d4c8df3499c;
 Wed, 09 Sep 2020 11:15:01 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6YPer7Fgw4EVheuSGIvPP31mmPgB1i9YNR4oNIQg4PI=; b=oOnO1mYpEmbji6GrfpIgaZjfCF
 dkEkl27LCsDsfhH8CRS4WRvSJmtlIqfv/CFHcrdxgiDwV/kRAhY/CLDfYnYbUVKyPlnjxEX1HAbgq
 6DyjPXTiFR2/R3UnlBFiRM0zlHXs8V0wq9iUU13CbMg6o8w85BZHBR7nsQI+9VTl1jFk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy45-00068y-K3
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:01 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy45-0001cc-J6
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:01 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxl: don't include libxl_osdeps.h from
 libxlutil sources
Message-Id: <E1kFy45-0001cc-J6@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:15:01 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e69a56bcf82fbbb80b159b6ba5c6982932678063
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:40 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: don't include libxl_osdeps.h from libxlutil sources
    
    There is no need for the sources of libxlutil to include libxl_osdeps.h
    as the only dependency is the leading
    
    #define _GNU_SOURCE
    
    in libxl_osdeps.h. So replace including libxl_osdeps.h by the needed
    define.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/libxlu_cfg.c    |  3 +--
 tools/libxl/libxlu_cfg_i.h  |  1 -
 tools/libxl/libxlu_disk.c   |  1 -
 tools/libxl/libxlu_disk_l.c | 14 +++++++-------
 tools/libxl/libxlu_disk_l.h |  8 ++++----
 tools/libxl/libxlu_disk_l.l |  2 +-
 tools/libxl/libxlu_pci.c    |  3 ++-
 tools/libxl/libxlu_vif.c    |  3 ++-
 8 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/tools/libxl/libxlu_cfg.c b/tools/libxl/libxlu_cfg.c
index f9e8aa2f3a..874f5abfb9 100644
--- a/tools/libxl/libxlu_cfg.c
+++ b/tools/libxl/libxlu_cfg.c
@@ -15,8 +15,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
 
 #include <limits.h>
 
diff --git a/tools/libxl/libxlu_cfg_i.h b/tools/libxl/libxlu_cfg_i.h
index 87b19df311..4217f5b28d 100644
--- a/tools/libxl/libxlu_cfg_i.h
+++ b/tools/libxl/libxlu_cfg_i.h
@@ -18,7 +18,6 @@
 #ifndef LIBXLU_CFG_I_H
 #define LIBXLU_CFG_I_H
 
-#include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxlu_internal.h"
 #include "libxlu_cfg_y.h"
 
diff --git a/tools/libxl/libxlu_disk.c b/tools/libxl/libxlu_disk.c
index 18fe386dbe..1de16a6a06 100644
--- a/tools/libxl/libxlu_disk.c
+++ b/tools/libxl/libxlu_disk.c
@@ -1,4 +1,3 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxlu_internal.h"
 #include "libxlu_disk_l.h"
 #include "libxlu_disk_i.h"
diff --git a/tools/libxl/libxlu_disk_l.c b/tools/libxl/libxlu_disk_l.c
index 05f7ac74a0..32d4b74b58 100644
--- a/tools/libxl/libxlu_disk_l.c
+++ b/tools/libxl/libxlu_disk_l.c
@@ -1,7 +1,7 @@
-#line 2 "libxlu_disk_l.c"
-#include "libxl_osdeps.h" /* must come before any other headers */
+#line 1 "libxlu_disk_l.c"
+#define _GNU_SOURCE
 
-#line 5 "libxlu_disk_l.c"
+#line 4 "libxlu_disk_l.c"
 
 #define  YY_INT_ALIGNED short int
 
@@ -1199,9 +1199,9 @@ static int vdev_and_devtype(DiskParseContext *dpc, char *str) {
 #undef DPC /* needs to be defined differently the actual lexer */
 #define DPC ((DiskParseContext*)yyextra)
 
-#line 1203 "libxlu_disk_l.c"
+#line 1202 "libxlu_disk_l.c"
 
-#line 1205 "libxlu_disk_l.c"
+#line 1204 "libxlu_disk_l.c"
 
 #define INITIAL 0
 #define LEXERR 1
@@ -1483,7 +1483,7 @@ YY_DECL
 #line 180 "libxlu_disk_l.l"
  /*----- the scanner rules which do the parsing -----*/
 
-#line 1487 "libxlu_disk_l.c"
+#line 1486 "libxlu_disk_l.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -1836,7 +1836,7 @@ YY_RULE_SETUP
 #line 291 "libxlu_disk_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1840 "libxlu_disk_l.c"
+#line 1839 "libxlu_disk_l.c"
 			case YY_STATE_EOF(INITIAL):
 			case YY_STATE_EOF(LEXERR):
 				yyterminate();
diff --git a/tools/libxl/libxlu_disk_l.h b/tools/libxl/libxlu_disk_l.h
index 54f4662d7a..6abeecf279 100644
--- a/tools/libxl/libxlu_disk_l.h
+++ b/tools/libxl/libxlu_disk_l.h
@@ -2,10 +2,10 @@
 #define xlu__disk_yyHEADER_H 1
 #define xlu__disk_yyIN_HEADER 1
 
-#line 6 "libxlu_disk_l.h"
-#include "libxl_osdeps.h" /* must come before any other headers */
+#line 5 "libxlu_disk_l.h"
+#define _GNU_SOURCE
 
-#line 9 "libxlu_disk_l.h"
+#line 8 "libxlu_disk_l.h"
 
 #define  YY_INT_ALIGNED short int
 
@@ -696,6 +696,6 @@ extern int yylex (yyscan_t yyscanner);
 
 #line 291 "libxlu_disk_l.l"
 
-#line 700 "libxlu_disk_l.h"
+#line 699 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l
index 7a46f4a30c..3bd639aab0 100644
--- a/tools/libxl/libxlu_disk_l.l
+++ b/tools/libxl/libxlu_disk_l.l
@@ -28,7 +28,7 @@
  */
 
 %top{
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
 }
 
 %{
diff --git a/tools/libxl/libxlu_pci.c b/tools/libxl/libxlu_pci.c
index e2709c5f89..12fc0b3a7f 100644
--- a/tools/libxl/libxlu_pci.c
+++ b/tools/libxl/libxlu_pci.c
@@ -1,4 +1,5 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
+
 #include "libxlu_internal.h"
 #include "libxlu_disk_l.h"
 #include "libxlu_disk_i.h"
diff --git a/tools/libxl/libxlu_vif.c b/tools/libxl/libxlu_vif.c
index 0665e624dc..ccf0cbdf57 100644
--- a/tools/libxl/libxlu_vif.c
+++ b/tools/libxl/libxlu_vif.c
@@ -1,4 +1,5 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
+
 #include "libxlu_internal.h"
 
 static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$";
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:15:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:15:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy4I-0000y5-31; Wed, 09 Sep 2020 11:15:14 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy4G-0000um-Eh
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:12 +0000
X-Inumbo-ID: 784eea68-fd04-4b78-8091-ad66ba5f1aa7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 784eea68-fd04-4b78-8091-ad66ba5f1aa7;
 Wed, 09 Sep 2020 11:15:11 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0GS8WPBPXwVfZUws3CnampqfUSqpR0LF1SJ+Ll3xX4U=; b=3qFq/5gvBoXsrb1G7IpKIh00LR
 P897rZVf1KFYkJH11LaX/d0tWPNjwKlWL23eQxEOHdKOHVI9tSxuOHbRaDx6gHkjmWcH5auElpfZq
 5QxP21kV5gHzqZ1PIeSROORAQCD1+QNqqKDOTaEK0GCX+HkwUmxDWSO680wgbvzeiPYw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4F-00069Z-OU
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:11 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4F-0001eC-NO
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:11 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxl: add missing items to clean target
Message-Id: <E1kFy4F-0001eC-NO@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:15:11 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0ca1af64f1053ffbf0c7784f4ed13ec75aacb874
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:41 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: add missing items to clean target
    
    Some generated files are not removed by "make clean". Add them.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 4fbd9ebbca..51c4c22f22 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -370,8 +370,10 @@ clean:
 	$(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS_RM)
 	$(RM) -f _*.c *.pyc _paths.*.tmp _*.api-for-check
 	$(RM) -f testidl.c.new testidl.c *.api-ok
+	$(RM) -f $(TEST_PROGS)
 	$(RM) -f xenlight.pc
 	$(RM) -f xlutil.pc
+	$(RM) -rf __pycache__
 	$(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) clean
 
 distclean: clean
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:15:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:15:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy4V-0000zC-4n; Wed, 09 Sep 2020 11:15:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy4T-0000z6-B9
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:25 +0000
X-Inumbo-ID: a744eb5f-c518-4d90-a21f-7d10d3732370
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a744eb5f-c518-4d90-a21f-7d10d3732370;
 Wed, 09 Sep 2020 11:15:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=9YynjHk2nwCIUZs/FQB9XbTiUNCRAX6WeXcSnVDvlCU=; b=oVFSA1MXPdnKLUjpNuthp7uidP
 6x3m5Q/2e9uhUkcKOkHyxPXoXHPpCKVm3swIKfTMlukeFbEZtekMfddFFOQXuRO+Cdyn4AWCOd9JP
 s+lLGnJqw6+xBUXgkltBc2kRwKfO151Mr9SIavcC4uxVunTJbt4prdSNaydnOKUQgQFo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4P-00069i-SQ
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:21 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4P-0001ez-RX
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:21 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libxl: move xl parsing checks to tools/xl
Message-Id: <E1kFy4P-0001ez-RX@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:15:21 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 82651ae662f25ff845b7f0bb87fbf7550a509cd1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:42 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: move xl parsing checks to tools/xl
    
    check-xl-* scripts and data are not libxl- but xl-specific. Move them
    from tools/libxl/ to tools/xl/.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/check-xl-disk-parse                 | 181 ---------------
 tools/libxl/check-xl-vcpupin-parse              | 294 ------------------------
 tools/libxl/check-xl-vcpupin-parse.data-example |  53 -----
 tools/libxl/check-xl-vif-parse                  | 213 -----------------
 tools/xl/check-xl-disk-parse                    | 181 +++++++++++++++
 tools/xl/check-xl-vcpupin-parse                 | 294 ++++++++++++++++++++++++
 tools/xl/check-xl-vcpupin-parse.data-example    |  53 +++++
 tools/xl/check-xl-vif-parse                     | 213 +++++++++++++++++
 8 files changed, 741 insertions(+), 741 deletions(-)

diff --git a/tools/libxl/check-xl-disk-parse b/tools/libxl/check-xl-disk-parse
deleted file mode 100755
index 643f4f4ecb..0000000000
--- a/tools/libxl/check-xl-disk-parse
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.:../libxc:../xenstore
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-disk-parse
-
-expected () {
-    cat >$fprefix.expected
-}
-
-failures=0
-
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N block-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    diff -u $fprefix.expected $fprefix.actual
-    diff_rc=$?
-    set -e
-    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-e=1
-
-
-#---------- test data ----------
-#
-# culled from docs/misc/xl-disk-configuration.txt
-
-expected </dev/null
-one $e foo
-
-expected <<END
-disk: {
-    "pdev_path": "/dev/vg/guest-volume",
-    "vdev": "hda",
-    "format": "raw",
-    "readwrite": 1
-}
-
-END
-one 0 /dev/vg/guest-volume,,hda
-one 0 /dev/vg/guest-volume,raw,hda,rw
-one 0 "format=raw, vdev=hda, access=rw, target=/dev/vg/guest-volume"
-one 0  format=raw  vdev=hda  access=rw  target=/dev/vg/guest-volume
-one 0 raw:/dev/vg/guest-volume,hda,w
-
-expected <<END
-disk: {
-    "pdev_path": "/root/image.iso",
-    "vdev": "hdc",
-    "format": "raw",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-END
-one 0 /root/image.iso,,hdc,cdrom
-one 0 /root/image.iso,,hdc,,cdrom
-one 0 /root/image.iso,raw,hdc,devtype=cdrom
-one 0 "format=raw, vdev=hdc, access=ro, devtype=cdrom, target=/root/image.iso"
-one 0  format=raw  vdev=hdc  access=ro  devtype=cdrom  target=/root/image.iso
-one 0 raw:/root/image.iso,hdc:cdrom,ro
-
-expected <<EOF
-disk: {
-    "pdev_path": "/dev/vg/guest-volume",
-    "vdev": "xvdb",
-    "backend": "phy",
-    "format": "raw",
-    "readwrite": 1
-}
-
-EOF
-one 0 backendtype=phy,vdev=xvdb,access=w,target=/dev/vg/guest-volume
-
-expected <<EOF
-disk: {
-    "pdev_path": "",
-    "vdev": "hdc",
-    "format": "empty",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-EOF
-one 0 devtype=cdrom,,,hdc
-one 0 ,,hdc:cdrom,r
-one 0 ,hdc:cdrom,r
-one 0 vdev=hdc,access=r,devtype=cdrom,target=
-one 0 ,empty,hdc:cdrom,r
-
-expected <<EOF
-disk: {
-    "vdev": "hdc",
-    "format": "empty",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-EOF
-one 0 vdev=hdc,access=r,devtype=cdrom,format=empty
-one 0 vdev=hdc,access=r,devtype=cdrom
-
-expected <<EOF
-disk: {
-    "pdev_path": "iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost",
-    "vdev": "xvda",
-    "format": "raw",
-    "script": "block-iscsi",
-    "readwrite": 1
-}
-
-EOF
-
-# http://backdrift.org/xen-block-iscsi-script-with-multipath-support
-one 0 iscsi:iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost,xvda,w
-one 0 vdev=xvda,access=w,script=block-iscsi,target=iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost
-
-expected <<EOF
-disk: {
-    "pdev_path": "app01",
-    "vdev": "hda",
-    "format": "raw",
-    "script": "block-drbd",
-    "readwrite": 1
-}
-
-EOF
-
-# http://lists.linbit.com/pipermail/drbd-user/2008-September/010221.html
-# http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html
-one 0 drbd:app01,hda,w
-
-expected <<END
-disk: {
-    "pdev_path": "/some/disk/image.raw",
-    "vdev": "hda",
-    "format": "raw",
-    "readwrite": 1,
-    "discard_enable": "True"
-}
-
-END
-one 0  discard vdev=hda target=/some/disk/image.raw
-one 0  discard vdev=hda target=/some/disk/image.raw
-
-expected <<END
-disk: {
-    "pdev_path": "/some/disk/image.iso",
-    "vdev": "hda",
-    "format": "raw",
-    "removable": 1,
-    "is_cdrom": 1,
-    "discard_enable": "False"
-}
-
-END
-one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
-
-complete
diff --git a/tools/libxl/check-xl-vcpupin-parse b/tools/libxl/check-xl-vcpupin-parse
deleted file mode 100755
index 21f8421ad0..0000000000
--- a/tools/libxl/check-xl-vcpupin-parse
+++ /dev/null
@@ -1,294 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.:../libxc:../xenstore:
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-vcpupin-parse
-outfile=check-xl-vcpupin-parse.data
-
-usage () {
-cat <<END
-usage: $0 [options]
-
-Tests various vcpu-pinning strings. If run without arguments acts
-as follows:
- - generates some test data and saves them in $outfile;
- - tests all the generated configurations (reading them back from
-   $outfile).
-
-An example of a test vector file is provided in ${outfile}-example.
-
-Options:
- -h         prints this message
- -r seed    uses seed for initializing the rundom number generator
-            (default: the script PID)
- -s string  tries using string as a vcpu pinning configuration and
-            reports whether that succeeds or not
- -o ofile   save the test data in ofile (default: $outfile)
- -i ifile   read test data from ifile
-END
-}
-
-expected () {
-    cat >$fprefix.expected
-}
-
-# by default, re-seed with our PID
-seed=$$
-failures=0
-
-# Execute one test and check the result against the provided
-# rc value and output
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N vcpu-pin 0 all "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    if [ $actual_rc != $expected_rc ]; then
-        diff -u $fprefix.expected $fprefix.actual
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-    set -e
-}
-
-# Write an entry in the test vector file. Format is as follows:
-#  test-string*expected-rc*expected-output
-write () {
-    printf "$1*$2*$3\n" >> $outfile
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-# Test a specific pinning string
-string () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N vcpu-pin 0 all "$@" &> /dev/null
-    actual_rc=$?
-    set -e
-
-    if [ $actual_rc != $expected_rc ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc)"
-    else
-        echo >&2 "test case \`$*' succeeded"
-    fi
-
-    exit 0
-}
-
-# Read a test vector file (provided as $1) line by line and
-# test all the entries it contains
-run ()
-{
-    while read line
-    do
-        if [ ${line:0:1} != '#' ]; then
-            test_string="`echo $line | cut -f1 -d'*'`"
-            exp_rc="`echo $line | cut -f2 -d'*'`"
-            exp_output="`echo $line | cut -f3 -d'*'`"
-
-            expected <<END
-$exp_output
-END
-            one $exp_rc "$test_string"
-        fi
-    done < $1
-
-    complete
-
-    exit 0
-}
-
-while getopts "hr:s:o:i:" option
-do
-    case $option in
-    h)
-        usage
-        exit 0
-        ;;
-    r)
-        seed=$OPTARG
-        ;;
-    s)
-        string 0 "$OPTARG"
-        ;;
-    o)
-        outfile=$OPTARG
-        ;;
-    i)
-        run $OPTARG
-        ;;
-    esac
-done
-
-#---------- test data ----------
-#
-nr_cpus=`xl info | grep nr_cpus | cut -f2 -d':'`
-nr_nodes=`xl info | grep nr_nodes | cut -f2 -d':'`
-nr_cpus_per_node=`xl info -n | sed '/cpu:/,/numa_info/!d' | head -n -1 | \
-    awk '{print $4}' | uniq -c | tail -1 | awk '{print $1}'`
-cat >$outfile <<END
-# WARNING: some of these tests are topology based tests.
-# Expect failures if the topology is not detected correctly
-# detected topology: $nr_cpus CPUs, $nr_nodes nodes, $nr_cpus_per_node CPUs per node.
-#
-# seed used for random number generation: seed=${seed}.
-#
-# Format is as follows:
-#  test-string*expected-return-code*expected-output
-#
-END
-
-# Re-seed the random number generator
-RANDOM=$seed
-
-echo "# Testing a wrong configuration" >> $outfile
-write foo 255 ""
-
-echo "# Testing the 'all' syntax" >> $outfile
-write "all" 0 "cpumap: all"
-write "nodes:all" 0 "cpumap: all"
-write "all,nodes:all" 0 "cpumap: all"
-write "all,^nodes:0,all" 0 "cpumap: all"
-
-echo "# Testing the empty cpumap case" >> $outfile
-write "^0" 0 "cpumap: none"
-
-echo "# A few attempts of pinning to just one random cpu" >> $outfile
-if [ $nr_cpus -gt 1 ]; then
-    for i in `seq 0 3`; do
-        cpu=$(($RANDOM % nr_cpus))
-        write "$cpu" 0 "cpumap: $cpu"
-    done
-fi
-
-echo "# A few attempts of pinning to all but one random cpu" >> $outfile
-if [ $nr_cpus -gt 2 ]; then
-    for i in `seq 0 3`; do
-        cpu=$(($RANDOM % nr_cpus))
-        if [ $cpu -eq 0 ]; then
-            expected_range="1-$((nr_cpus - 1))"
-        elif [ $cpu -eq 1 ]; then
-            expected_range="0,2-$((nr_cpus - 1))"
-        elif [ $cpu -eq $((nr_cpus - 2)) ]; then
-            expected_range="0-$((cpu - 1)),$((nr_cpus - 1))"
-        elif [ $cpu -eq $((nr_cpus - 1)) ]; then
-            expected_range="0-$((nr_cpus - 2))"
-        else
-            expected_range="0-$((cpu - 1)),$((cpu + 1))-$((nr_cpus - 1))"
-        fi
-        write "all,^$cpu" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a random range of cpus" >> $outfile
-if [ $nr_cpus -gt 2 ]; then
-    for i in `seq 0 3`; do
-        cpua=$(($RANDOM % nr_cpus))
-        range=$((nr_cpus - cpua))
-        cpub=$(($RANDOM % range))
-        cpubb=$((cpua + cpub))
-        if [ $cpua -eq $cpubb ]; then
-            expected_range="$cpua"
-        else
-            expected_range="$cpua-$cpubb"
-        fi
-        write "$expected_range" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to just one random node" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        write "nodes:$node" 0 "cpumap: $((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1)-1))"
-    done
-fi
-
-echo "# A few attempts of pinning to all but one random node" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        if [ $node -eq 0 ]; then
-            expected_range="$nr_cpus_per_node-$((nr_cpus - 1))"
-        elif [ $node -eq $((nr_nodes - 1)) ]; then
-            expected_range="0-$((nr_cpus - nr_cpus_per_node - 1))"
-        else
-            expected_range="0-$((nr_cpus_per_node*node-1)),$((nr_cpus_per_node*(node+1)))-$nr_cpus"
-        fi
-        write "all,^nodes:$node" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a random range of nodes" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        nodea=$(($RANDOM % nr_nodes))
-        range=$((nr_nodes - nodea))
-        nodeb=$(($RANDOM % range))
-        nodebb=$((nodea + nodeb))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        if [ $nodea -eq 0 ] && [ $nodebb -eq $((nr_nodes - 1)) ]; then
-            expected_range="all"
-        else
-            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodebb+1) - 1))"
-        fi
-        write "nodes:$nodea-$nodebb" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a node but excluding one random cpu" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        cpu=$(($RANDOM % nr_cpus_per_node + nr_cpus_per_node*node))
-        if [ $cpu -eq $((nr_cpus_per_node*node)) ]; then
-            expected_range="$((nr_cpus_per_node*node + 1))-$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*node + 1)) ]; then
-            expected_range="$((nr_cpus_per_node*node)),$((nr_cpus_per_node*node + 2))-$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 2)) ]; then
-            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 3)),$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 1)) ]; then
-            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 2))"
-        else
-            expected_range="$((nr_cpus_per_node*node))-$((cpu - 1)),$((cpu + 1))-$((nr_cpus_per_node*(node+1) - 1))"
-        fi
-        write "nodes:$node,^$cpu" 0 "cpumap: $expected_range"
-    done
-fi
-
-run $outfile
diff --git a/tools/libxl/check-xl-vcpupin-parse.data-example b/tools/libxl/check-xl-vcpupin-parse.data-example
deleted file mode 100644
index 4bbd5de76c..0000000000
--- a/tools/libxl/check-xl-vcpupin-parse.data-example
+++ /dev/null
@@ -1,53 +0,0 @@
-# WARNING: some of these tests are topology based tests.
-# Expect failures if the topology is not detected correctly
-# detected topology:  16 CPUs,  2 nodes, 8 CPUs per node.
-#
-# seed used for random number generation: seed=13328.
-#
-# Format is as follows:
-#  test-string*expected-return-code*expected-output
-#
-# Testing a wrong configuration
-foo*255*
-# Testing the 'all' syntax
-all*0*cpumap: all
-nodes:all*0*cpumap: all
-all,nodes:all*0*cpumap: all
-all,^nodes:0,all*0*cpumap: all
-# Testing the empty cpumap case
-^0*0*cpumap: none
-# A few attempts of pinning to just one random cpu
-0*0*cpumap: 0
-9*0*cpumap: 9
-6*0*cpumap: 6
-0*0*cpumap: 0
-# A few attempts of pinning to all but one random cpu
-all,^12*0*cpumap: 0-11,13-15
-all,^6*0*cpumap: 0-5,7-15
-all,^3*0*cpumap: 0-2,4-15
-all,^7*0*cpumap: 0-6,8-15
-# A few attempts of pinning to a random range of cpus
-13-15*0*cpumap: 13-15
-7*0*cpumap: 7
-3-5*0*cpumap: 3-5
-8-11*0*cpumap: 8-11
-# A few attempts of pinning to just one random node
-nodes:1*0*cpumap: 8-15
-nodes:0*0*cpumap: 0-7
-nodes:0*0*cpumap: 0-7
-nodes:0*0*cpumap: 0-7
-# A few attempts of pinning to all but one random node
-all,^nodes:0*0*cpumap: 8-15
-all,^nodes:1*0*cpumap: 0-7
-all,^nodes:1*0*cpumap: 0-7
-all,^nodes:0*0*cpumap: 8-15
-# A few attempts of pinning to a random range of nodes
-nodes:1-1*0*cpumap: 8-15
-nodes:1-1*0*cpumap: 8-15
-nodes:0-1*0*cpumap: all
-nodes:0-0*0*cpumap: 0-7
-# A few attempts of pinning to a node but excluding one random cpu
-nodes:1,^8*0*cpumap: 9-15
-nodes:0,^6*0*cpumap: 0-5,7
-nodes:1,^9*0*cpumap: 8,10-15
-nodes:0,^5*0*cpumap: 0-4,6-7
diff --git a/tools/libxl/check-xl-vif-parse b/tools/libxl/check-xl-vif-parse
deleted file mode 100755
index 02c6dbaeb6..0000000000
--- a/tools/libxl/check-xl-vif-parse
+++ /dev/null
@@ -1,213 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-vif-parse
-
-expected () {
-    cat >$fprefix.expected
-}
-
-failures=0
-
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N network-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    diff -u $fprefix.expected $fprefix.actual
-    diff_rc=$?
-    set -e
-    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-e=255
-
-
-#---------- test data ----------
-
-# test invalid vif config
-expected </dev/null
-one 1 foo
-
-# test invalid rate units
-expected </dev/null
-one $e rate=foo
-one $e rate=foo
-one $e rate=10MB
-one $e rate=10MB/m
-one $e rate=10ZB
-one $e rate=10ZB/s
-one $e rate=10ZB/m
-
-# test b/s and B/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100000,
-    "rate_interval_usecs": 50000
-}
-
-END
-
-one 0 rate=16000000b/s
-one 0 rate=16000000b/s@50ms
-one 0 rate=2000000B/s
-one 0 rate=2000000B/s@50ms
-
-# test Kb/s and KB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=16Kb/s
-one 0 rate=16Kb/s@50ms
-one 0 rate=2KB/s
-one 0 rate=2KB/s@50ms
-
-# test Mb/s and MB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100000,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=16Mb/s
-one 0 rate=16Mb/s@50ms
-one 0 rate=2MB/s
-one 0 rate=2MB/s@50ms
-
-# test Gb/s and GB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 50000000,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=8Gb/s
-one 0 rate=8Gb/s@50ms
-one 0 rate=1GB/s
-one 0 rate=1GB/s@50ms
-
-# test rate overflow
-expected </dev/null
-one $e rate=4294967296b/s
-one $e rate=4294967296Kb/s
-one $e rate=4294967296Mb/s
-one $e rate=4294967296Gb/s
-
-# test rate underflow
-expected </dev/null
-one $e rate=0B/s
-
-# test invalid replenishment interval
-expected </dev/null
-one $e rate=10Mb/s@foo
-one $e rate=10Mb/s@10h
-one $e rate=10MB/s@foo
-one $e rate=10MB/s@10h
-
-# test replenishment interval in seconds
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 10000000,
-    "rate_interval_usecs": 1000000
-}
-
-END
-one 0 rate=80Mb/s@1s
-one 0 rate=10MB/s@1s
-
-# test replenishment interval overflow
-expected </dev/null
-one $e rate=1B/s@4294967296us
-one $e rate=1B/s@4294968ms
-one $e rate=1B/s@4295s
-
-# test replenishment interval underflow
-expected </dev/null
-one $e rate=1B/s@0us
-
-# test rate limiting resulting in overflow
-expected </dev/null
-one $e rate=4294967295GB/s@5us
-one $e rate=4296MB/s@4294s
-
-# test include of single '@'
-expected </dev/null
-one $e rate=@
-
-complete
diff --git a/tools/xl/check-xl-disk-parse b/tools/xl/check-xl-disk-parse
new file mode 100755
index 0000000000..643f4f4ecb
--- /dev/null
+++ b/tools/xl/check-xl-disk-parse
@@ -0,0 +1,181 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.:../libxc:../xenstore
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-disk-parse
+
+expected () {
+    cat >$fprefix.expected
+}
+
+failures=0
+
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N block-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    diff -u $fprefix.expected $fprefix.actual
+    diff_rc=$?
+    set -e
+    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+e=1
+
+
+#---------- test data ----------
+#
+# culled from docs/misc/xl-disk-configuration.txt
+
+expected </dev/null
+one $e foo
+
+expected <<END
+disk: {
+    "pdev_path": "/dev/vg/guest-volume",
+    "vdev": "hda",
+    "format": "raw",
+    "readwrite": 1
+}
+
+END
+one 0 /dev/vg/guest-volume,,hda
+one 0 /dev/vg/guest-volume,raw,hda,rw
+one 0 "format=raw, vdev=hda, access=rw, target=/dev/vg/guest-volume"
+one 0  format=raw  vdev=hda  access=rw  target=/dev/vg/guest-volume
+one 0 raw:/dev/vg/guest-volume,hda,w
+
+expected <<END
+disk: {
+    "pdev_path": "/root/image.iso",
+    "vdev": "hdc",
+    "format": "raw",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+END
+one 0 /root/image.iso,,hdc,cdrom
+one 0 /root/image.iso,,hdc,,cdrom
+one 0 /root/image.iso,raw,hdc,devtype=cdrom
+one 0 "format=raw, vdev=hdc, access=ro, devtype=cdrom, target=/root/image.iso"
+one 0  format=raw  vdev=hdc  access=ro  devtype=cdrom  target=/root/image.iso
+one 0 raw:/root/image.iso,hdc:cdrom,ro
+
+expected <<EOF
+disk: {
+    "pdev_path": "/dev/vg/guest-volume",
+    "vdev": "xvdb",
+    "backend": "phy",
+    "format": "raw",
+    "readwrite": 1
+}
+
+EOF
+one 0 backendtype=phy,vdev=xvdb,access=w,target=/dev/vg/guest-volume
+
+expected <<EOF
+disk: {
+    "pdev_path": "",
+    "vdev": "hdc",
+    "format": "empty",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+EOF
+one 0 devtype=cdrom,,,hdc
+one 0 ,,hdc:cdrom,r
+one 0 ,hdc:cdrom,r
+one 0 vdev=hdc,access=r,devtype=cdrom,target=
+one 0 ,empty,hdc:cdrom,r
+
+expected <<EOF
+disk: {
+    "vdev": "hdc",
+    "format": "empty",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+EOF
+one 0 vdev=hdc,access=r,devtype=cdrom,format=empty
+one 0 vdev=hdc,access=r,devtype=cdrom
+
+expected <<EOF
+disk: {
+    "pdev_path": "iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost",
+    "vdev": "xvda",
+    "format": "raw",
+    "script": "block-iscsi",
+    "readwrite": 1
+}
+
+EOF
+
+# http://backdrift.org/xen-block-iscsi-script-with-multipath-support
+one 0 iscsi:iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost,xvda,w
+one 0 vdev=xvda,access=w,script=block-iscsi,target=iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost
+
+expected <<EOF
+disk: {
+    "pdev_path": "app01",
+    "vdev": "hda",
+    "format": "raw",
+    "script": "block-drbd",
+    "readwrite": 1
+}
+
+EOF
+
+# http://lists.linbit.com/pipermail/drbd-user/2008-September/010221.html
+# http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html
+one 0 drbd:app01,hda,w
+
+expected <<END
+disk: {
+    "pdev_path": "/some/disk/image.raw",
+    "vdev": "hda",
+    "format": "raw",
+    "readwrite": 1,
+    "discard_enable": "True"
+}
+
+END
+one 0  discard vdev=hda target=/some/disk/image.raw
+one 0  discard vdev=hda target=/some/disk/image.raw
+
+expected <<END
+disk: {
+    "pdev_path": "/some/disk/image.iso",
+    "vdev": "hda",
+    "format": "raw",
+    "removable": 1,
+    "is_cdrom": 1,
+    "discard_enable": "False"
+}
+
+END
+one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
+
+complete
diff --git a/tools/xl/check-xl-vcpupin-parse b/tools/xl/check-xl-vcpupin-parse
new file mode 100755
index 0000000000..21f8421ad0
--- /dev/null
+++ b/tools/xl/check-xl-vcpupin-parse
@@ -0,0 +1,294 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.:../libxc:../xenstore:
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-vcpupin-parse
+outfile=check-xl-vcpupin-parse.data
+
+usage () {
+cat <<END
+usage: $0 [options]
+
+Tests various vcpu-pinning strings. If run without arguments acts
+as follows:
+ - generates some test data and saves them in $outfile;
+ - tests all the generated configurations (reading them back from
+   $outfile).
+
+An example of a test vector file is provided in ${outfile}-example.
+
+Options:
+ -h         prints this message
+ -r seed    uses seed for initializing the rundom number generator
+            (default: the script PID)
+ -s string  tries using string as a vcpu pinning configuration and
+            reports whether that succeeds or not
+ -o ofile   save the test data in ofile (default: $outfile)
+ -i ifile   read test data from ifile
+END
+}
+
+expected () {
+    cat >$fprefix.expected
+}
+
+# by default, re-seed with our PID
+seed=$$
+failures=0
+
+# Execute one test and check the result against the provided
+# rc value and output
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N vcpu-pin 0 all "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    if [ $actual_rc != $expected_rc ]; then
+        diff -u $fprefix.expected $fprefix.actual
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+    set -e
+}
+
+# Write an entry in the test vector file. Format is as follows:
+#  test-string*expected-rc*expected-output
+write () {
+    printf "$1*$2*$3\n" >> $outfile
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+# Test a specific pinning string
+string () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N vcpu-pin 0 all "$@" &> /dev/null
+    actual_rc=$?
+    set -e
+
+    if [ $actual_rc != $expected_rc ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc)"
+    else
+        echo >&2 "test case \`$*' succeeded"
+    fi
+
+    exit 0
+}
+
+# Read a test vector file (provided as $1) line by line and
+# test all the entries it contains
+run ()
+{
+    while read line
+    do
+        if [ ${line:0:1} != '#' ]; then
+            test_string="`echo $line | cut -f1 -d'*'`"
+            exp_rc="`echo $line | cut -f2 -d'*'`"
+            exp_output="`echo $line | cut -f3 -d'*'`"
+
+            expected <<END
+$exp_output
+END
+            one $exp_rc "$test_string"
+        fi
+    done < $1
+
+    complete
+
+    exit 0
+}
+
+while getopts "hr:s:o:i:" option
+do
+    case $option in
+    h)
+        usage
+        exit 0
+        ;;
+    r)
+        seed=$OPTARG
+        ;;
+    s)
+        string 0 "$OPTARG"
+        ;;
+    o)
+        outfile=$OPTARG
+        ;;
+    i)
+        run $OPTARG
+        ;;
+    esac
+done
+
+#---------- test data ----------
+#
+nr_cpus=`xl info | grep nr_cpus | cut -f2 -d':'`
+nr_nodes=`xl info | grep nr_nodes | cut -f2 -d':'`
+nr_cpus_per_node=`xl info -n | sed '/cpu:/,/numa_info/!d' | head -n -1 | \
+    awk '{print $4}' | uniq -c | tail -1 | awk '{print $1}'`
+cat >$outfile <<END
+# WARNING: some of these tests are topology based tests.
+# Expect failures if the topology is not detected correctly
+# detected topology: $nr_cpus CPUs, $nr_nodes nodes, $nr_cpus_per_node CPUs per node.
+#
+# seed used for random number generation: seed=${seed}.
+#
+# Format is as follows:
+#  test-string*expected-return-code*expected-output
+#
+END
+
+# Re-seed the random number generator
+RANDOM=$seed
+
+echo "# Testing a wrong configuration" >> $outfile
+write foo 255 ""
+
+echo "# Testing the 'all' syntax" >> $outfile
+write "all" 0 "cpumap: all"
+write "nodes:all" 0 "cpumap: all"
+write "all,nodes:all" 0 "cpumap: all"
+write "all,^nodes:0,all" 0 "cpumap: all"
+
+echo "# Testing the empty cpumap case" >> $outfile
+write "^0" 0 "cpumap: none"
+
+echo "# A few attempts of pinning to just one random cpu" >> $outfile
+if [ $nr_cpus -gt 1 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        write "$cpu" 0 "cpumap: $cpu"
+    done
+fi
+
+echo "# A few attempts of pinning to all but one random cpu" >> $outfile
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        if [ $cpu -eq 0 ]; then
+            expected_range="1-$((nr_cpus - 1))"
+        elif [ $cpu -eq 1 ]; then
+            expected_range="0,2-$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 2)) ]; then
+            expected_range="0-$((cpu - 1)),$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 1)) ]; then
+            expected_range="0-$((nr_cpus - 2))"
+        else
+            expected_range="0-$((cpu - 1)),$((cpu + 1))-$((nr_cpus - 1))"
+        fi
+        write "all,^$cpu" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a random range of cpus" >> $outfile
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpua=$(($RANDOM % nr_cpus))
+        range=$((nr_cpus - cpua))
+        cpub=$(($RANDOM % range))
+        cpubb=$((cpua + cpub))
+        if [ $cpua -eq $cpubb ]; then
+            expected_range="$cpua"
+        else
+            expected_range="$cpua-$cpubb"
+        fi
+        write "$expected_range" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to just one random node" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        write "nodes:$node" 0 "cpumap: $((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1)-1))"
+    done
+fi
+
+echo "# A few attempts of pinning to all but one random node" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $node -eq 0 ]; then
+            expected_range="$nr_cpus_per_node-$((nr_cpus - 1))"
+        elif [ $node -eq $((nr_nodes - 1)) ]; then
+            expected_range="0-$((nr_cpus - nr_cpus_per_node - 1))"
+        else
+            expected_range="0-$((nr_cpus_per_node*node-1)),$((nr_cpus_per_node*(node+1)))-$nr_cpus"
+        fi
+        write "all,^nodes:$node" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a random range of nodes" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        nodea=$(($RANDOM % nr_nodes))
+        range=$((nr_nodes - nodea))
+        nodeb=$(($RANDOM % range))
+        nodebb=$((nodea + nodeb))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $nodea -eq 0 ] && [ $nodebb -eq $((nr_nodes - 1)) ]; then
+            expected_range="all"
+        else
+            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodebb+1) - 1))"
+        fi
+        write "nodes:$nodea-$nodebb" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a node but excluding one random cpu" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        cpu=$(($RANDOM % nr_cpus_per_node + nr_cpus_per_node*node))
+        if [ $cpu -eq $((nr_cpus_per_node*node)) ]; then
+            expected_range="$((nr_cpus_per_node*node + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*node + 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node)),$((nr_cpus_per_node*node + 2))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 2)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 3)),$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 2))"
+        else
+            expected_range="$((nr_cpus_per_node*node))-$((cpu - 1)),$((cpu + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        fi
+        write "nodes:$node,^$cpu" 0 "cpumap: $expected_range"
+    done
+fi
+
+run $outfile
diff --git a/tools/xl/check-xl-vcpupin-parse.data-example b/tools/xl/check-xl-vcpupin-parse.data-example
new file mode 100644
index 0000000000..4bbd5de76c
--- /dev/null
+++ b/tools/xl/check-xl-vcpupin-parse.data-example
@@ -0,0 +1,53 @@
+# WARNING: some of these tests are topology based tests.
+# Expect failures if the topology is not detected correctly
+# detected topology:  16 CPUs,  2 nodes, 8 CPUs per node.
+#
+# seed used for random number generation: seed=13328.
+#
+# Format is as follows:
+#  test-string*expected-return-code*expected-output
+#
+# Testing a wrong configuration
+foo*255*
+# Testing the 'all' syntax
+all*0*cpumap: all
+nodes:all*0*cpumap: all
+all,nodes:all*0*cpumap: all
+all,^nodes:0,all*0*cpumap: all
+# Testing the empty cpumap case
+^0*0*cpumap: none
+# A few attempts of pinning to just one random cpu
+0*0*cpumap: 0
+9*0*cpumap: 9
+6*0*cpumap: 6
+0*0*cpumap: 0
+# A few attempts of pinning to all but one random cpu
+all,^12*0*cpumap: 0-11,13-15
+all,^6*0*cpumap: 0-5,7-15
+all,^3*0*cpumap: 0-2,4-15
+all,^7*0*cpumap: 0-6,8-15
+# A few attempts of pinning to a random range of cpus
+13-15*0*cpumap: 13-15
+7*0*cpumap: 7
+3-5*0*cpumap: 3-5
+8-11*0*cpumap: 8-11
+# A few attempts of pinning to just one random node
+nodes:1*0*cpumap: 8-15
+nodes:0*0*cpumap: 0-7
+nodes:0*0*cpumap: 0-7
+nodes:0*0*cpumap: 0-7
+# A few attempts of pinning to all but one random node
+all,^nodes:0*0*cpumap: 8-15
+all,^nodes:1*0*cpumap: 0-7
+all,^nodes:1*0*cpumap: 0-7
+all,^nodes:0*0*cpumap: 8-15
+# A few attempts of pinning to a random range of nodes
+nodes:1-1*0*cpumap: 8-15
+nodes:1-1*0*cpumap: 8-15
+nodes:0-1*0*cpumap: all
+nodes:0-0*0*cpumap: 0-7
+# A few attempts of pinning to a node but excluding one random cpu
+nodes:1,^8*0*cpumap: 9-15
+nodes:0,^6*0*cpumap: 0-5,7
+nodes:1,^9*0*cpumap: 8,10-15
+nodes:0,^5*0*cpumap: 0-4,6-7
diff --git a/tools/xl/check-xl-vif-parse b/tools/xl/check-xl-vif-parse
new file mode 100755
index 0000000000..02c6dbaeb6
--- /dev/null
+++ b/tools/xl/check-xl-vif-parse
@@ -0,0 +1,213 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-vif-parse
+
+expected () {
+    cat >$fprefix.expected
+}
+
+failures=0
+
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N network-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    diff -u $fprefix.expected $fprefix.actual
+    diff_rc=$?
+    set -e
+    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+e=255
+
+
+#---------- test data ----------
+
+# test invalid vif config
+expected </dev/null
+one 1 foo
+
+# test invalid rate units
+expected </dev/null
+one $e rate=foo
+one $e rate=foo
+one $e rate=10MB
+one $e rate=10MB/m
+one $e rate=10ZB
+one $e rate=10ZB/s
+one $e rate=10ZB/m
+
+# test b/s and B/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100000,
+    "rate_interval_usecs": 50000
+}
+
+END
+
+one 0 rate=16000000b/s
+one 0 rate=16000000b/s@50ms
+one 0 rate=2000000B/s
+one 0 rate=2000000B/s@50ms
+
+# test Kb/s and KB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=16Kb/s
+one 0 rate=16Kb/s@50ms
+one 0 rate=2KB/s
+one 0 rate=2KB/s@50ms
+
+# test Mb/s and MB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100000,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=16Mb/s
+one 0 rate=16Mb/s@50ms
+one 0 rate=2MB/s
+one 0 rate=2MB/s@50ms
+
+# test Gb/s and GB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 50000000,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=8Gb/s
+one 0 rate=8Gb/s@50ms
+one 0 rate=1GB/s
+one 0 rate=1GB/s@50ms
+
+# test rate overflow
+expected </dev/null
+one $e rate=4294967296b/s
+one $e rate=4294967296Kb/s
+one $e rate=4294967296Mb/s
+one $e rate=4294967296Gb/s
+
+# test rate underflow
+expected </dev/null
+one $e rate=0B/s
+
+# test invalid replenishment interval
+expected </dev/null
+one $e rate=10Mb/s@foo
+one $e rate=10Mb/s@10h
+one $e rate=10MB/s@foo
+one $e rate=10MB/s@10h
+
+# test replenishment interval in seconds
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 10000000,
+    "rate_interval_usecs": 1000000
+}
+
+END
+one 0 rate=80Mb/s@1s
+one 0 rate=10MB/s@1s
+
+# test replenishment interval overflow
+expected </dev/null
+one $e rate=1B/s@4294967296us
+one $e rate=1B/s@4294968ms
+one $e rate=1B/s@4295s
+
+# test replenishment interval underflow
+expected </dev/null
+one $e rate=1B/s@0us
+
+# test rate limiting resulting in overflow
+expected </dev/null
+one $e rate=4294967295GB/s@5us
+one $e rate=4296MB/s@4294s
+
+# test include of single '@'
+expected </dev/null
+one $e rate=@
+
+complete
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:15:34 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:15:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy4c-000108-8O; Wed, 09 Sep 2020 11:15:34 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy4a-0000zy-Mi
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:32 +0000
X-Inumbo-ID: 8f4a8e7f-7277-4363-9711-18d0c515292e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8f4a8e7f-7277-4363-9711-18d0c515292e;
 Wed, 09 Sep 2020 11:15:32 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2NnlT8xK2cbWZczz8LDnLVVF5zNA4F9OI1cYWXMEW84=; b=l3YWqQJS/mlM98zT5Ne2XreJf6
 CJy4/KeG9lx4law9ShMsmY6I+qH8hB/P5mxMlIssrN6XlDtZVf9sUgRzw3zOCpbsp48gRzOcnglpD
 jKLYU8aV9Fe1o/4aCuIF7/mJfd78yA9bcjOPQ8721aIT4rCluGRq0plWnlICV18TpgVA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4Z-00069l-Vw
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:31 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4Z-0001fu-VA
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:31 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/xl: don't assume libxl and libxlutil are in one
 directory
Message-Id: <E1kFy4Z-0001fu-VA@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:15:31 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b72aa3968dd5e4f75dfd816db7fae067b07e3711
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:43 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xl: don't assume libxl and libxlutil are in one directory
    
    Add the correct flags for both, libxenlight and libxlutil, when
    building xl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xl/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index af4912e67a..407dd7554c 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -13,6 +13,7 @@ CFLAGS += $(PTHREAD_CFLAGS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
 CFLAGS_XL += $(CFLAGS_libxenlight)
+CFLAGS_XL += $(CFLAGS_libxlutil)
 CFLAGS_XL += -Wshadow
 
 XL_OBJS-$(CONFIG_X86) = xl_psr.o
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 11:15:44 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 11:15:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kFy4m-00011F-A5; Wed, 09 Sep 2020 11:15:44 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kFy4k-000114-RU
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:42 +0000
X-Inumbo-ID: 914f56e6-1b8b-46aa-8aef-9f8a63974ed6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 914f56e6-1b8b-46aa-8aef-9f8a63974ed6;
 Wed, 09 Sep 2020 11:15:42 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ItCLuWqpU4+Xikjh3Jc0xRD1YjyUtD1YnZoU8IzMzK8=; b=wQ3hDP/sauTIvQ8M1SiuNJyDv9
 bn2EScz4s1RktAB28T1imhEHl7xXgM7iCbDu8rDYNYUfGZjNKGx96pls4qjqCIyx+EfjS6BvtHItR
 JEnDQDwWQXL77JUs427SOdiv8hUmClLexAIZdL8TKFNP4OWsFkQwnI3MU91rYHJDIA9E=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4k-00069t-4R
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:42 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kFy4k-0001gl-3L
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 11:15:42 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] libxenguest: use bitmap_alloc
Message-Id: <E1kFy4k-0001gl-3L@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 11:15:42 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3cccdae45242dab27198b8e150be0c85acd5d3c9
Author:     Olaf Hering <olaf@aepfle.de>
AuthorDate: Wed Sep 9 11:06:37 2020 +0000
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 11:07:31 2020 +0000

    libxenguest: use bitmap_alloc
    
    Use existing helper to allocate a bitmap.
    
    Signed-off-by: Olaf Hering <olaf@aepfle.de>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
    [ wei: rebase to staging ]
    Signed-off-by: Wei Liu <wl@xen.org>
---
 tools/libs/guest/xg_sr_save.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c
index d74c72cba6..2ba7c3200c 100644
--- a/tools/libs/guest/xg_sr_save.c
+++ b/tools/libs/guest/xg_sr_save.c
@@ -809,7 +809,7 @@ static int setup(struct xc_sr_context *ctx)
         xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)));
     ctx->save.batch_pfns = malloc(MAX_BATCH_SIZE *
                                   sizeof(*ctx->save.batch_pfns));
-    ctx->save.deferred_pages = calloc(1, bitmap_size(ctx->save.p2m_size));
+    ctx->save.deferred_pages = bitmap_alloc(ctx->save.p2m_size);
 
     if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pages )
     {
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 13:44:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 13:44:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG0OO-0007S9-HM; Wed, 09 Sep 2020 13:44:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG0ON-0007Rx-BK
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:07 +0000
X-Inumbo-ID: 857d13e7-b232-4d79-b547-b91e38b24c34
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 857d13e7-b232-4d79-b547-b91e38b24c34;
 Wed, 09 Sep 2020 13:44:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ZrvbsJPytTxQXbugVExslS80FnbyBOpDCGGSA472V2A=; b=wGItEfH1SriRtuUeR8y/AAWz/o
 HagERCc6rnox8RUsINOm702ab7hA7V2BTIsnqhDW1hZQXAViImCYO3ulYGEdruZ+HYWZoeIusZC+j
 MH1+Inoj28pmLOfVm3BvJHNWVblwlIbByVX9GKo+auGmVCmfsS63SENJibZbWy4SP87c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0OM-0000ul-1q
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0OL-00030P-V3
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/hotplug: Fix hostname setting in vif-nat
Message-Id: <E1kG0OL-00030P-V3@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 13:44:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5499e0fc8082024bf7e2d0facd5c976e82105070
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Thu Aug 20 11:58:20 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:30 2020 +0000

    tools/hotplug: Fix hostname setting in vif-nat
    
    Setting the hostname is failing because the "$XENBUS_PATH/domain"
    doesn't exist anymore. To fix this we set it to dom$domid
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-nat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
index a76d9c784b..26144350b3 100644
--- a/tools/hotplug/Linux/vif-nat
+++ b/tools/hotplug/Linux/vif-nat
@@ -85,7 +85,7 @@ router_ip=$(routing_ip "$ip")
 # Split the given IP/bits pair.
 vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
 
-hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----')
+hostname=dom$domid
 if [ "$vifid" != "1" ]
 then
   hostname="$hostname-$vifid"
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 13:44:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 13:44:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG0OX-0007Te-J9; Wed, 09 Sep 2020 13:44:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG0OX-0007TY-0Z
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:17 +0000
X-Inumbo-ID: 8a24fce9-9180-4e38-8412-60fede2edbf0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8a24fce9-9180-4e38-8412-60fede2edbf0;
 Wed, 09 Sep 2020 13:44:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PpEcsYYNBxEcTjQw0VetY7kdUfjSGS7FR04jQxATU/o=; b=6Af8xfv/jLjO2Ki8z5Bcw7Hncm
 1qSaBQGNV7VOw9jsA2iHkZihldBtVe+vLImgNmud0hmVxYqF4K8+4IFSxcRfzFE/7uFZECCn9muig
 zYNh0RDIQXqrBxL529NT/KeknawcaHnc1TlC5uClXk5YxUNRFZmrqW3NWoIl7B2yDxt4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0OW-0000uo-67
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0OW-000316-4O
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/hotplug: Extend dhcpd conf,
 init and arg files search
Message-Id: <E1kG0OW-000316-4O@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 13:44:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 17f80e7fc1e3bb49fc91794ef1b6e5a2f1b540cb
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Thu Aug 20 12:01:11 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:34 2020 +0000

    tools/hotplug: Extend dhcpd conf, init and arg files search
    
    Newer versions of the ISC dhcp server expect the dhcpd.conf file
    to be located at /etc/dhcp directory.
    
    Also, some distributions and Yocto based ones have these installation
    paths by default: /etc/init.d/{isc-dhcp-server,dhcp-server} and
    /etc/default/dhcp-server.
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/xen-network-common.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index 82ee70aab4..42fa704e8d 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -64,18 +64,18 @@ first_file()
 
 find_dhcpd_conf_file()
 {
-  first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
+  first_file -f /etc/dhcp/dhcpd.conf /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
 }
 
 
 find_dhcpd_init_file()
 {
-  first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
+  first_file -x /etc/init.d/{isc-dhcp-server,dhcp-server,dhcp3-server,dhcp,dhcpd}
 }
 
 find_dhcpd_arg_file()
 {
-  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server
+  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp-server /etc/default/dhcp3-server
 }
 
 # configure interfaces which act as pure bridge ports:
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 13:44:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 13:44:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG0Oi-0007VL-Km; Wed, 09 Sep 2020 13:44:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG0Oh-0007V3-SD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:27 +0000
X-Inumbo-ID: 2e4b7d82-2373-462d-85e3-44029fad085c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 2e4b7d82-2373-462d-85e3-44029fad085c;
 Wed, 09 Sep 2020 13:44:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cf0tG57Cn6sasymqhR4y/nwU9ShU6Ordm83KSP7Ffzc=; b=FWL9cNZG300Fs14pIr1/Vuy6Vv
 Opgv4M6NQc1ZIqMaeWrAKXfZhjmeu9asEoOLpOOj6712BN0er9TBCC+tWDm9zc2ijhwWA2EhFahLN
 /U0FQKStDz9oN9mcdYeRq7ghFxYXaRkLSejdUZI/bktaf32Z5UkeOzjkgQJrsDvcSVOE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0Og-0000v4-9O
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG0Og-00031Y-8d
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 13:44:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Message-Id: <E1kG0Og-00031Y-8d@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 13:44:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6d2f1ebccdef655d64fbc3abc83db76c3de08cb1
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Wed Sep 9 13:35:56 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:59 2020 +0000

    tools/hotplug: Fix dhcpd symlink removal in vif-nat
    
    Copy temp files used to add/remove dhcpd configurations to avoid
    replacing potential symlinks.
    
    If dhcp.conf is a symlink pointing to dhcp.conf.real, using 'mv'
    creates a new file dhcp.conf where cp will actually modify
    dhcp.conf.real instead of replacing the symlink with a real
    file.
    
    Using 'cp' prevents some mistakes where the user will actually
    continue to modify dhcp.conf.real where it would not be the one
    used anymore.
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-nat | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
index 26144350b3..fd34afbb96 100644
--- a/tools/hotplug/Linux/vif-nat
+++ b/tools/hotplug/Linux/vif-nat
@@ -95,12 +95,11 @@ dhcparg_remove_entry()
 {
   local tmpfile=$(mktemp)
   sed -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile"
-  if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
+  if ! diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
   then
-    rm "$tmpfile"
-  else
-    mv "$tmpfile" "$dhcpd_arg_file"
+    cp "$tmpfile" "$dhcpd_arg_file"
   fi
+  rm "$tmpfile"
 }
 
 dhcparg_add_entry()
@@ -109,11 +108,11 @@ dhcparg_add_entry()
   local tmpfile=$(mktemp)
   # handle Red Hat, SUSE, and Debian styles, with or without quotes
   sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   rm -f "$tmpfile"
 }
 
@@ -121,12 +120,11 @@ dhcp_remove_entry()
 {
   local tmpfile=$(mktemp)
   grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
-  if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
+  if ! diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
   then
-    rm "$tmpfile"
-  else
-    mv "$tmpfile" "$dhcpd_conf_file"
+    cp "$tmpfile" "$dhcpd_conf_file"
   fi
+  rm "$tmpfile"
   dhcparg_remove_entry
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 15:55:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 15:55:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG2RB-0002UZ-88; Wed, 09 Sep 2020 15:55:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG2R9-0002UU-PD
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 15:55:07 +0000
X-Inumbo-ID: d625bfd9-c885-487a-b595-f6f06c02e35d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d625bfd9-c885-487a-b595-f6f06c02e35d;
 Wed, 09 Sep 2020 15:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=gwqbID9fn7y4gADyprnukWuOkMharXfLXVwAEteRLFM=; b=5lhPrHCmWF/2XIX/bjAey5JBX2
 X2/+5ct/rC1UM0XjdNyawvIZv6qh6dclrskhFsQhejD8npoMnrGmZXtDsSxPT6zUsDctmFTdVJsE8
 3ggQ3BN9Q2NEQDWsMPLb5W/l6OmmoILgVkxNh5iE3h2xZHf7EBAbtgRRmVYNFB8fAwyA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2R8-0003p8-Gn
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 15:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2R8-0001kp-Dj
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 15:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Move stack_switch()/seg_segment_base() into
 PV-only files
Message-Id: <E1kG2R8-0001kp-Dj@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 15:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a4c4b288069cf0c7285ec3d3efb1df0b46051d46
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Thu Sep 3 19:09:45 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Wed Sep 9 16:53:28 2020 +0100

    x86/pv: Move stack_switch()/seg_segment_base() into PV-only files
    
    So they are excluded from !CONFIG_PV builds.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/pv/misc-hypercalls.c | 101 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c          | 101 --------------------------------------
 2 files changed, 101 insertions(+), 101 deletions(-)

diff --git a/xen/arch/x86/pv/misc-hypercalls.c b/xen/arch/x86/pv/misc-hypercalls.c
index 136fa10c96..b353972e3d 100644
--- a/xen/arch/x86/pv/misc-hypercalls.c
+++ b/xen/arch/x86/pv/misc-hypercalls.c
@@ -171,6 +171,107 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
     return 0;
 }
 
+long do_stack_switch(unsigned long ss, unsigned long esp)
+{
+    fixup_guest_stack_selector(current->domain, ss);
+    current->arch.pv.kernel_ss = ss;
+    current->arch.pv.kernel_sp = esp;
+
+    return 0;
+}
+
+long do_set_segment_base(unsigned int which, unsigned long base)
+{
+    struct vcpu *v = current;
+    long ret = 0;
+
+    if ( is_pv_32bit_vcpu(v) )
+        return -ENOSYS; /* x86/64 only. */
+
+    switch ( which )
+    {
+    case SEGBASE_FS:
+        if ( is_canonical_address(base) )
+            wrfsbase(base);
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_USER:
+        if ( is_canonical_address(base) )
+        {
+            wrgsshadow(base);
+            v->arch.pv.gs_base_user = base;
+        }
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_KERNEL:
+        if ( is_canonical_address(base) )
+            wrgsbase(base);
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_USER_SEL:
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
+        break;
+    }
+
+    default:
+        ret = -EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index b69cf2dc4f..98581dfe5f 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1010,107 +1010,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
-long do_stack_switch(unsigned long ss, unsigned long esp)
-{
-    fixup_guest_stack_selector(current->domain, ss);
-    current->arch.pv.kernel_ss = ss;
-    current->arch.pv.kernel_sp = esp;
-    return 0;
-}
-
-long do_set_segment_base(unsigned int which, unsigned long base)
-{
-    struct vcpu *v = current;
-    long ret = 0;
-
-    if ( is_pv_32bit_vcpu(v) )
-        return -ENOSYS; /* x86/64 only. */
-
-    switch ( which )
-    {
-    case SEGBASE_FS:
-        if ( is_canonical_address(base) )
-            wrfsbase(base);
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_USER:
-        if ( is_canonical_address(base) )
-        {
-            wrgsshadow(base);
-            v->arch.pv.gs_base_user = base;
-        }
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_KERNEL:
-        if ( is_canonical_address(base) )
-            wrgsbase(base);
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_USER_SEL:
-    {
-        unsigned int sel = (uint16_t)base;
-
-        /*
-         * We wish to update the user %gs from the GDT/LDT.  Currently, the
-         * guest kernel's GS_BASE is in context.
-         */
-        asm volatile ( "swapgs" );
-
-        if ( sel > 3 )
-            /* Fix up RPL for non-NUL selectors. */
-            sel |= 3;
-        else if ( boot_cpu_data.x86_vendor &
-                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
-            /* Work around NUL segment behaviour on AMD hardware. */
-            asm volatile ( "mov %[sel], %%gs"
-                           :: [sel] "r" (FLAT_USER_DS32) );
-
-        /*
-         * Load the chosen selector, with fault handling.
-         *
-         * Errors ought to fail the hypercall, but that was never built in
-         * originally, and Linux will BUG() if this call fails.
-         *
-         * NUL the selector in the case of an error.  This too needs to deal
-         * with the AMD NUL segment behaviour, but it is already a slowpath in
-         * #GP context so perform the flat load unconditionally to avoid
-         * complicated logic.
-         *
-         * Anyone wanting to check for errors from this hypercall should
-         * re-read %gs and compare against the input.
-         */
-        asm volatile ( "1: mov %[sel], %%gs\n\t"
-                       ".section .fixup, \"ax\", @progbits\n\t"
-                       "2: mov %k[flat], %%gs\n\t"
-                       "   xor %[sel], %[sel]\n\t"
-                       "   jmp 1b\n\t"
-                       ".previous\n\t"
-                       _ASM_EXTABLE(1b, 2b)
-                       : [sel] "+r" (sel)
-                       : [flat] "r" (FLAT_USER_DS32) );
-
-        /* Update the cache of the inactive base, as read from the GDT/LDT. */
-        v->arch.pv.gs_base_user = rdgsbase();
-
-        asm volatile ( safe_swapgs );
-        break;
-    }
-
-    default:
-        ret = -EINVAL;
-        break;
-    }
-
-    return ret;
-}
-
-
 /* Returns TRUE if given descriptor is valid for GDT or LDT. */
 int check_descriptor(const struct domain *dom, seg_desc_t *d)
 {
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 16:00:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 16:00:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG2W1-0003ka-VK; Wed, 09 Sep 2020 16:00:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG2W0-0003kV-Qq
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:08 +0000
X-Inumbo-ID: 8ae0e170-c1b6-41a3-b625-0cc2d13bdd55
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8ae0e170-c1b6-41a3-b625-0cc2d13bdd55;
 Wed, 09 Sep 2020 16:00:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=5T+aoRA/+5kuvcPOmOCFquTRLNpSnHjZMK/DZEkzNmY=; b=iHIHQdevuv+6MLODe2pRO20yTB
 zxXJjo9jieFYjHjzXUgStzn5lUPXtHIpWoly9dzYpaXrjDEtrSJFjyQgbxtJg8z9zVvQhjR1yjZZW
 RSTTGw51RAW/7X5AknbpFsbttPpf19tMSsOWp6zQN27dwQfMIJMgUyTN/36zeRU5Xqog=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2Vz-0004QI-Ht
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2Vz-0002AN-Eq
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] lib: correct __moddi3() description
Message-Id: <E1kG2Vz-0002AN-Eq@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 16:00:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 033b534be50b0c53cf32171e8b013df505758c13
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 9 17:55:41 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:55:41 2020 +0200

    lib: correct __moddi3() description
    
    The remainder of a division, when non-zero, is specified to always be of
    the same sign as the dividend. Bring a comment in line with the code it
    describes.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/common/lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/lib.c b/xen/common/lib.c
index 8ebec811b3..b2b799da44 100644
--- a/xen/common/lib.c
+++ b/xen/common/lib.c
@@ -390,7 +390,7 @@ u64 __umoddi3(u64 a, u64 b)
  *  11 %  5 =  1
  * -11 %  5 = -1
  *  11 % -5 =  1
- * -11 % -5 =  1
+ * -11 % -5 = -1
  */
 s64 __moddi3(s64 a, s64 b)
 {
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 16:00:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 16:00:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG2WC-0003oY-0Y; Wed, 09 Sep 2020 16:00:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG2WB-0003lb-10
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:19 +0000
X-Inumbo-ID: 8ff385ee-7361-4a85-91e5-c8d90245beaf
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8ff385ee-7361-4a85-91e5-c8d90245beaf;
 Wed, 09 Sep 2020 16:00:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=WagSl4dN3Q3M1JBVHQSPmqgM4MkDzJZJGvqTBq/45Ns=; b=mrKnPiT9LFUSc73XFoO02rlNUU
 sncEbaIK27Vkzvvso6TpAwpA7LUL9HTdd0hBNfDgWnMU1OBcksLXJCHlPraorTK/xwOEKU7+HR8zU
 fddNL2gkvpEJXv6mN0+4XfYczBQAtVujATyPq7gEUfOooS6iSgZ3790gSR2ObAi8T+UQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2W9-0004VP-N5
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2W9-0002B5-Kv
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] hvmloader: indicate ACPI tables with "ACPI data" type
 in e820
Message-Id: <E1kG2W9-0002B5-Kv@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 16:00:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8efa46516c5f4cf185c8df179812c185d3c27eb6
Author:     Igor Druzhinin <igor.druzhinin@citrix.com>
AuthorDate: Wed Sep 9 17:56:13 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:56:13 2020 +0200

    hvmloader: indicate ACPI tables with "ACPI data" type in e820
    
    Guest kernel does need to know in some cases where the tables are located
    to treat these regions properly. One example is kexec process where
    the first kernel needs to pass ACPI region locations to the second
    kernel which is now a requirement in Linux after 02a3e3cdb7f12 ("x86/boot:
    Parse SRAT table and count immovable memory regions") in order for kexec
    transition to actually work.
    
    That commit introduced accesses to XSDT and SRAT while the second kernel
    is still using kexec transition tables. The transition tables do not have
    e820 "reserved" regions mapped where those tables are located currently
    in a Xen guest. Instead "ACPI data" regions are mapped with the transition
    tables that was introduced by the following commit 6bbeb276b7 ("x86/kexec:
    Add the EFI system tables and ACPI tables to the ident map").
    
    Reserve 1MB (out of 16MB currently available) right after ACPI info page for
    ACPI tables exclusively but populate this region on demand and only indicate
    populated memory as "ACPI data" since according to ACPI spec that memory is
    reclaimable by the guest if necessary. That is close to how we treat
    the same ACPI data in PVH guests. 1MB should be enough for now but could be
    later extended if required.
    
    Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 tools/firmware/hvmloader/config.h    |  6 +++++-
 tools/firmware/hvmloader/e820.c      | 26 ++++++++++++++++++++++----
 tools/firmware/hvmloader/hvmloader.c |  3 ++-
 tools/firmware/hvmloader/pci.c       |  1 -
 tools/firmware/hvmloader/util.c      | 29 ++++++++++++++++++++++++++++-
 tools/firmware/hvmloader/util.h      |  2 ++
 6 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index d9b4713d63..844120bc87 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -2,6 +2,7 @@
 #define __HVMLOADER_CONFIG_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 
 enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
@@ -62,6 +63,8 @@ extern uint8_t ioapic_version;
 extern unsigned long pci_mem_start, pci_mem_end;
 extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 
+extern bool acpi_enabled;
+
 /* Memory map. */
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
@@ -71,7 +74,8 @@ extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 #define RESERVED_MEMBASE              0xFC000000
 /* NB. ACPI_INFO_PHYSICAL_ADDRESS *MUST* match definition in acpi/dsdt.asl! */
 #define ACPI_INFO_PHYSICAL_ADDRESS    0xFC000000
-#define RESERVED_MEMORY_DYNAMIC_START 0xFC001000
+#define ACPI_MEMORY_DYNAMIC_START     0xFC001000
+#define RESERVED_MEMORY_DYNAMIC_START 0xFC100000
 #define RESERVED_MEMORY_DYNAMIC_END   0xFE000000
 /*
  * GUEST_RESERVED: Physical address space reserved for guest use.
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 4d1c955a02..38bcf18b63 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -155,6 +155,9 @@ int build_e820_table(struct e820entry *e820,
 {
     unsigned int nr = 0, i, j;
     uint32_t low_mem_end = hvm_info->low_mem_pgend << PAGE_SHIFT;
+    unsigned long acpi_mem_end = acpi_enabled ?
+        ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated() << PAGE_SHIFT) :
+        RESERVED_MEMBASE;
 
     if ( !lowmem_reserved_base )
             lowmem_reserved_base = 0xA0000;
@@ -198,9 +201,24 @@ int build_e820_table(struct e820entry *e820,
     e820[nr].type = E820_RESERVED;
     nr++;
 
+    /*
+     * Mark populated reserved memory that contains ACPI tables as ACPI data.
+     * That should help the guest to treat it correctly later: e.g. pass to
+     * the next kernel on kexec or reclaim if necessary.
+     */
+
+    if ( acpi_enabled )
+    {
+        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].size = acpi_mem_end - RESERVED_MEMBASE;
+        e820[nr].type = E820_ACPI;
+        nr++;
+    }
+
     /*
      * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * This space starts right after ACPI region (to avoid creating a hole that
+     * might be accidentally occupied by MMIO) and extends to cover various
      * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
      *
      * If igd_opregion_pgbase we need to split the RESERVED region in two.
@@ -210,8 +228,8 @@ int build_e820_table(struct e820entry *e820,
     {
         uint32_t igd_opregion_base = igd_opregion_pgbase << PAGE_SHIFT;
 
-        e820[nr].addr = RESERVED_MEMBASE;
-        e820[nr].size = (uint32_t) igd_opregion_base - RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
+        e820[nr].size = igd_opregion_base - acpi_mem_end;
         e820[nr].type = E820_RESERVED;
         nr++;
 
@@ -227,7 +245,7 @@ int build_e820_table(struct e820entry *e820,
     }
     else
     {
-        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
         e820[nr].size = (uint32_t)-e820[nr].addr;
         e820[nr].type = E820_RESERVED;
         nr++;
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 598a226278..c58841e5b5 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -116,6 +116,8 @@ unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
 uint32_t ioapic_base_address = 0xfec00000;
 uint8_t ioapic_version;
 
+bool acpi_enabled;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -321,7 +323,6 @@ const struct hvm_modlist_entry *get_module_entry(
 int main(void)
 {
     const struct bios_config *bios;
-    int acpi_enabled;
     const struct hvm_modlist_entry *bios_module;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index dcd097a866..72f92d4450 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -28,7 +28,6 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
-#include <stdbool.h>
 
 unsigned long pci_mem_start = HVM_BELOW_4G_MMIO_START;
 unsigned long pci_mem_end = PCI_MEM_END;
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 0c3f2d24cd..7da144b0bb 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -871,10 +871,37 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static unsigned long acpi_alloc_up = ACPI_MEMORY_DYNAMIC_START - 1;
+
+unsigned long acpi_pages_allocated(void)
+{
+    return (acpi_alloc_up >> PAGE_SHIFT) -
+            ((ACPI_MEMORY_DYNAMIC_START - 1) >> PAGE_SHIFT);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
-    return mem_alloc(size, align);
+    unsigned long s, e;
+
+    /* Align to at least 16 bytes. */
+    if ( align < 16 )
+        align = 16;
+
+    s = (acpi_alloc_up + align) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON((e < s) || (e >= RESERVED_MEMORY_DYNAMIC_START));
+
+    while ( (acpi_alloc_up >> PAGE_SHIFT) != (e >> PAGE_SHIFT) )
+    {
+        acpi_alloc_up += PAGE_SIZE;
+        mem_hole_populate_ram(acpi_alloc_up >> PAGE_SHIFT, 1);
+    }
+
+    acpi_alloc_up = e;
+
+    return (void *)s;
 }
 
 static void acpi_mem_free(struct acpi_ctxt *ctxt,
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 7bca6418d2..31889de634 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -282,6 +282,8 @@ bool check_overlap(uint64_t start, uint64_t size,
 extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
 extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
 
+unsigned long acpi_pages_allocated(void);
+
 struct acpi_config;
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 16:00:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 16:00:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG2WM-0003vP-CH; Wed, 09 Sep 2020 16:00:30 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG2WK-0003lb-Ug
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:28 +0000
X-Inumbo-ID: 7df6d918-f344-40eb-b8ed-f6286aa9d7c7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7df6d918-f344-40eb-b8ed-f6286aa9d7c7;
 Wed, 09 Sep 2020 16:00:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=iA9X6FvBFauZF+KPur5s8gZkDfW6i4iuv5BXafDD5E0=; b=bXU7PaALB0AUWIEsmo+veK4qeB
 fhORZJVtY3ORO921maQYIpodDXlqeB2RT12Sr1Vo+rRlyv1mX2DuoM0gkDSqhyqohn3SGHCTvpUv7
 ghDcdsQPSrWwdZY1/n+e+js59hsLas3S5CbdcgA+Pl8cgsOIuhm9CwxwOVC4yhKBP3Aw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2WJ-0004VZ-Rs
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG2WJ-0002BX-Pw
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 16:00:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: drop use of prelink-efi_lto.o
Message-Id: <E1kG2WJ-0002BX-Pw@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 16:00:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ba65a2ff688f1eb390b3f91fdfd09d799925f460
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 9 17:56:49 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:56:49 2020 +0200

    x86: drop use of prelink-efi_lto.o
    
    As of de94e8b4f996 ("x86/EFI: sanitize build logic") it is identical to
    prelink_lto.o.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/Makefile | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 1f279b6b2e..74152f2a0d 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -135,14 +135,11 @@ ifeq ($(CONFIG_LTO),y)
 prelink_lto.o: $(ALL_OBJS)
 	$(LD_LTO) -r -o $@ $^
 
-prelink-efi_lto.o: $(ALL_OBJS)
-	$(LD_LTO) -r -o $@ $^
-
 # Link it with all the binary objects
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y)
 	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
 else
 prelink.o: $(ALL_OBJS) $(EFI_OBJS-y)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 09 17:00:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 09 Sep 2020 17:00:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kG3S6-0000qd-Il; Wed, 09 Sep 2020 17:00:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=tIdc=CS=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kG3S4-0000qY-SR
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 17:00:08 +0000
X-Inumbo-ID: fa684660-bba9-40c0-87e1-9f45c4cf53da
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fa684660-bba9-40c0-87e1-9f45c4cf53da;
 Wed, 09 Sep 2020 17:00:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=xHdWvdcH7PDB2R5SnDnDbUiyDnwzLeDfk0/7Cfb0SAs=; b=ryFf6Q343ZMf2uNjcFFJqVOXMV
 BeIFZl0JfoyAedPYinjdy1DkB16j9GUnq50SoPQqnSvvs90ogvXok0jek8y8fmCzJ/d4IrdCi/RU0
 LPu5iQsnIZj28bJ1HCtHFTYwKnOUGfZmV6jMgCD3hKMExliJJQfq0JRuMrFZ6iFRq/5k=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG3S3-0005k6-36
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 17:00:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kG3S3-0000sJ-1f
 for xen-changelog@lists.xenproject.org; Wed, 09 Sep 2020 17:00:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Move segment descriptor infrastructure into
 PV-only files
Message-Id: <E1kG3S3-0000sJ-1f@xenbits.xenproject.org>
Date: Wed, 09 Sep 2020 17:00:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 89002866bb6c6f26024f015820c8f52012f95cf2
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Thu Sep 3 19:28:15 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Wed Sep 9 17:57:26 2020 +0100

    x86/pv: Move segment descriptor infrastructure into PV-only files
    
    ... so all segment checking/adjustment logic is co-located.
    
    Perform some trivial style cleanup to check_descriptor() as it moves,
    converting types, and cleaning up trailing whitespace.
    
    In particular, this means that check_descriptor() is now excluded from
    !CONFIG_PV builds.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/mm.c                   |  17 ------
 xen/arch/x86/pv/descriptor-tables.c | 100 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c            |  87 -------------------------------
 xen/include/asm-x86/mm.h            |   2 -
 xen/include/asm-x86/pv/mm.h         |   2 +
 5 files changed, 102 insertions(+), 106 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 35ec0e11f6..56bf7add2b 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -585,23 +585,6 @@ const char __section(".bss.page_aligned.const") __aligned(PAGE_SIZE)
     zero_page[PAGE_SIZE];
 
 
-#ifdef CONFIG_PV
-static int validate_segdesc_page(struct page_info *page)
-{
-    const struct domain *owner = page_get_owner(page);
-    seg_desc_t *descs = __map_domain_page(page);
-    unsigned i;
-
-    for ( i = 0; i < 512; i++ )
-        if ( unlikely(!check_descriptor(owner, &descs[i])) )
-            break;
-
-    unmap_domain_page(descs);
-
-    return i == 512 ? 0 : -EINVAL;
-}
-#endif
-
 static int _get_page_type(struct page_info *page, unsigned long type,
                           bool preemptible);
 
diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c
index 3856128993..39c1a2311a 100644
--- a/xen/arch/x86/pv/descriptor-tables.c
+++ b/xen/arch/x86/pv/descriptor-tables.c
@@ -185,6 +185,106 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list,
     return ret;
 }
 
+static bool check_descriptor(const struct domain *dom, seg_desc_t *d)
+{
+    unsigned int a = d->a, b = d->b, cs, dpl;
+
+    /* A not-present descriptor will always fault, so is safe. */
+    if ( !(b & _SEGMENT_P) )
+        return true;
+
+    /* Check and fix up the DPL. */
+    dpl = (b >> 13) & 3;
+    __fixup_guest_selector(dom, dpl);
+    b = (b & ~_SEGMENT_DPL) | (dpl << 13);
+
+    /* All code and data segments are okay. No base/limit checking. */
+    if ( b & _SEGMENT_S )
+    {
+        if ( is_pv_32bit_domain(dom) )
+        {
+            unsigned long base, limit;
+
+            if ( b & _SEGMENT_L )
+                goto bad;
+
+            /*
+             * Older PAE Linux guests use segments which are limited to
+             * 0xf6800000. Extend these to allow access to the larger read-only
+             * M2P table available in 32on64 mode.
+             */
+            base = (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16);
+
+            limit = (b & 0xf0000) | (a & 0xffff);
+            limit++; /* We add one because limit is inclusive. */
+
+            if ( b & _SEGMENT_G )
+                limit <<= 12;
+
+            if ( (base == 0) && (limit > HYPERVISOR_COMPAT_VIRT_START(dom)) )
+            {
+                a |= 0x0000ffff;
+                b |= 0x000f0000;
+            }
+        }
+
+        goto good;
+    }
+
+    /* Invalid type 0 is harmless. It is used for 2nd half of a call gate. */
+    if ( (b & _SEGMENT_TYPE) == 0x000 )
+        return true;
+
+    /* Everything but a call gate is discarded here. */
+    if ( (b & _SEGMENT_TYPE) != 0xc00 )
+        goto bad;
+
+    /* Validate the target code selector. */
+    cs = a >> 16;
+    if ( !guest_gate_selector_okay(dom, cs) )
+        goto bad;
+    /*
+     * Force DPL to zero, causing a GP fault with its error code indicating
+     * the gate in use, allowing emulation. This is necessary because with
+     * native guests (kernel in ring 3) call gates cannot be used directly
+     * to transition from user to kernel mode (and whether a gate is used
+     * to enter the kernel can only be determined when the gate is being
+     * used), and with compat guests call gates cannot be used at all as
+     * there are only 64-bit ones.
+     * Store the original DPL in the selector's RPL field.
+     */
+    b &= ~_SEGMENT_DPL;
+    cs = (cs & ~3) | dpl;
+    a = (a & 0xffffU) | (cs << 16);
+
+    /* Reserved bits must be zero. */
+    if ( b & (is_pv_32bit_domain(dom) ? 0xe0 : 0xff) )
+        goto bad;
+
+ good:
+    d->a = a;
+    d->b = b;
+    return true;
+
+ bad:
+    return false;
+}
+
+int validate_segdesc_page(struct page_info *page)
+{
+    const struct domain *owner = page_get_owner(page);
+    seg_desc_t *descs = __map_domain_page(page);
+    unsigned i;
+
+    for ( i = 0; i < 512; i++ )
+        if ( unlikely(!check_descriptor(owner, &descs[i])) )
+            break;
+
+    unmap_domain_page(descs);
+
+    return i == 512 ? 0 : -EINVAL;
+}
+
 long do_update_descriptor(uint64_t gaddr, seg_desc_t d)
 {
     struct domain *currd = current->domain;
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 98581dfe5f..1f32062c15 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1010,93 +1010,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
-/* Returns TRUE if given descriptor is valid for GDT or LDT. */
-int check_descriptor(const struct domain *dom, seg_desc_t *d)
-{
-    u32 a = d->a, b = d->b;
-    u16 cs;
-    unsigned int dpl;
-
-    /* A not-present descriptor will always fault, so is safe. */
-    if ( !(b & _SEGMENT_P) ) 
-        return 1;
-
-    /* Check and fix up the DPL. */
-    dpl = (b >> 13) & 3;
-    __fixup_guest_selector(dom, dpl);
-    b = (b & ~_SEGMENT_DPL) | (dpl << 13);
-
-    /* All code and data segments are okay. No base/limit checking. */
-    if ( (b & _SEGMENT_S) )
-    {
-        if ( is_pv_32bit_domain(dom) )
-        {
-            unsigned long base, limit;
-
-            if ( b & _SEGMENT_L )
-                goto bad;
-
-            /*
-             * Older PAE Linux guests use segments which are limited to
-             * 0xf6800000. Extend these to allow access to the larger read-only
-             * M2P table available in 32on64 mode.
-             */
-            base = (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16);
-
-            limit = (b & 0xf0000) | (a & 0xffff);
-            limit++; /* We add one because limit is inclusive. */
-
-            if ( (b & _SEGMENT_G) )
-                limit <<= 12;
-
-            if ( (base == 0) && (limit > HYPERVISOR_COMPAT_VIRT_START(dom)) )
-            {
-                a |= 0x0000ffff;
-                b |= 0x000f0000;
-            }
-        }
-
-        goto good;
-    }
-
-    /* Invalid type 0 is harmless. It is used for 2nd half of a call gate. */
-    if ( (b & _SEGMENT_TYPE) == 0x000 )
-        return 1;
-
-    /* Everything but a call gate is discarded here. */
-    if ( (b & _SEGMENT_TYPE) != 0xc00 )
-        goto bad;
-
-    /* Validate the target code selector. */
-    cs = a >> 16;
-    if ( !guest_gate_selector_okay(dom, cs) )
-        goto bad;
-    /*
-     * Force DPL to zero, causing a GP fault with its error code indicating
-     * the gate in use, allowing emulation. This is necessary because with
-     * native guests (kernel in ring 3) call gates cannot be used directly
-     * to transition from user to kernel mode (and whether a gate is used
-     * to enter the kernel can only be determined when the gate is being
-     * used), and with compat guests call gates cannot be used at all as
-     * there are only 64-bit ones.
-     * Store the original DPL in the selector's RPL field.
-     */
-    b &= ~_SEGMENT_DPL;
-    cs = (cs & ~3) | dpl;
-    a = (a & 0xffffU) | (cs << 16);
-
-    /* Reserved bits must be zero. */
-    if ( b & (is_pv_32bit_domain(dom) ? 0xe0 : 0xff) )
-        goto bad;
-        
- good:
-    d->a = a;
-    d->b = b;
-    return 1;
- bad:
-    return 0;
-}
-
 int pagefault_by_memadd(unsigned long addr, struct cpu_user_regs *regs)
 {
     struct domain *d = current->domain;
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 632ece1cee..deeba75a1c 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -454,8 +454,6 @@ static inline int get_page_and_type(struct page_info *page,
     ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
     ASSERT(page_get_owner(_p) == (_d))
 
-int check_descriptor(const struct domain *d, seg_desc_t *desc);
-
 extern paddr_t mem_hotplug;
 
 /******************************************************************************
diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h
index 07a12d5c49..9983f8257c 100644
--- a/xen/include/asm-x86/pv/mm.h
+++ b/xen/include/asm-x86/pv/mm.h
@@ -32,6 +32,8 @@ void pv_destroy_gdt(struct vcpu *v);
 bool pv_map_ldt_shadow_page(unsigned int off);
 bool pv_destroy_ldt(struct vcpu *v);
 
+int validate_segdesc_page(struct page_info *page);
+
 #else
 
 #include <xen/errno.h>
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Thu Sep 10 19:33:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Thu, 10 Sep 2020 19:33:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGSJh-0008Rx-3D; Thu, 10 Sep 2020 19:33:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=K8zg=CT=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGSJg-0008Rs-Dv
 for xen-changelog@lists.xenproject.org; Thu, 10 Sep 2020 19:33:08 +0000
X-Inumbo-ID: a298bd96-f783-4fd2-a4de-a8ef940adb9e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a298bd96-f783-4fd2-a4de-a8ef940adb9e;
 Thu, 10 Sep 2020 19:33:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LHIproLqLpN79gqS22mEe7osLtoWD5H7TcfajXKkTtw=; b=J2vCMyOu4ENTYCZA0u57BrJ1Js
 FEQgcG6OR1kR7wHXIUoF4J1hFv6UWj3QQOosRuyuSqZbw6bwMi/PVEV56uh6Zt9DsAaMP1j1J1moK
 3JYvNkdFvuZ47DhkWicjFUEMTtGsCkZdBBK0vMa0wqIXM2YaOj4NYJc7B8gpTR4TIAnU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGSJe-0004yE-Jw
 for xen-changelog@lists.xenproject.org; Thu, 10 Sep 2020 19:33:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGSJe-0006p3-GI
 for xen-changelog@lists.xenproject.org; Thu, 10 Sep 2020 19:33:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libs/guest: fix Makefile regarding zlib options
Message-Id: <E1kGSJe-0006p3-GI@xenbits.xenproject.org>
Date: Thu, 10 Sep 2020 19:33:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit cc13835377debe4e300c5f5f11f8f78920778c4e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Thu Sep 10 17:42:10 2020 +0200
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Sep 10 20:27:00 2020 +0100

    tools/libs/guest: fix Makefile regarding zlib options
    
    When renaming the libxenguest sources to xg_*.c there was an omission
    in the Makefile when setting the zlib related define for the related
    sources. Fix that.
    
    Fixes: e3dd624e487c ("tools/libxc: move libxenguest to tools/libs/guest")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libs/guest/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile
index e53aeabd3e..f24732fbcd 100644
--- a/tools/libs/guest/Makefile
+++ b/tools/libs/guest/Makefile
@@ -94,8 +94,8 @@ else
 zlib-options = $(ZLIB)
 endif
 
-xc_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
-xc_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
+xg_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
+xg_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
 
 LIBHEADER := xenguest.h
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi49-0004Ta-5X; Fri, 11 Sep 2020 12:22:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi48-0004TV-3q
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:08 +0000
X-Inumbo-ID: e51bd6ed-768d-4dc1-9cf8-4d2d2a16e008
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e51bd6ed-768d-4dc1-9cf8-4d2d2a16e008;
 Fri, 11 Sep 2020 12:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=W3A1Izo4TXLGSiB+HBOftOWII0VA/YKbBJh7bTAesv8=; b=lZe99skzM7Kz+xZWISJm/9bC6x
 5E0yoR7+EbEcBr9LKVl+ZV+kg4qND4SgS/QJGfuVgeDsqvYM/HtzGBg49oxzw3cQ/gzinD1st2kVq
 rxnNcLiRSrVKNylaG81ADGs8HXFi8h8xEInG8bnD7qtI4g0ESFKUNfxm1SXEPsmDYQw0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi45-00084u-Qq
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi45-0002k2-Ol
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: guard against port I/O overlapping the RTC/CMOS
 range
Message-Id: <E1kGi45-0002k2-Ol@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 899316e02e0d1c9bfe65cca1b20f8140ee9c4d17
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:13:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:13:46 2020 +0200

    x86: guard against port I/O overlapping the RTC/CMOS range
    
    Since we intercept RTC/CMOS port accesses, let's do so consistently in
    all cases, i.e. also for e.g. a dword access to [006E,0071]. To avoid
    the risk of unintended impact on Dom0 code actually doing so (despite
    the belief that none ought to exist), also extend
    guest_io_{read,write}() to decompose accesses where some ports are
    allowed to be directly accessed and some aren't.
    
    While splitting out the new _guest_io_write() also
    - add ASSERT_UNREACHABLE(),
    - drop stray casts,
    - add blank lines.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/pv/emul-priv-op.c | 59 +++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index a192160f84..c6fbf8f92d 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -210,7 +210,7 @@ static bool admin_io_okay(unsigned int port, unsigned int bytes,
         return false;
 
     /* We also never permit direct access to the RTC/CMOS registers. */
-    if ( ((port & ~1) == RTC_PORT(0)) )
+    if ( port <= RTC_PORT(1) && port + bytes > RTC_PORT(0) )
         return false;
 
     return ioports_access_permitted(d, port, port + bytes - 1);
@@ -297,6 +297,17 @@ static uint32_t guest_io_read(unsigned int port, unsigned int bytes,
             if ( pci_cfg_ok(currd, port & 3, size, NULL) )
                 sub_data = pci_conf_read(currd->arch.pci_cf8, port & 3, size);
         }
+        else if ( ioports_access_permitted(currd, port, port) )
+        {
+            if ( bytes > 1 && !(port & 1) &&
+                 ioports_access_permitted(currd, port, port + 1) )
+            {
+                sub_data = inw(port);
+                size = 2;
+            }
+            else
+                sub_data = inb(port);
+        }
 
         if ( size == 4 )
             return sub_data;
@@ -373,25 +384,36 @@ static int read_io(unsigned int port, unsigned int bytes,
     return X86EMUL_OKAY;
 }
 
+static void _guest_io_write(unsigned int port, unsigned int bytes,
+                            uint32_t data)
+{
+    switch ( bytes )
+    {
+    case 1:
+        outb(data, port);
+        if ( amd_acpi_c1e_quirk )
+            amd_check_disable_c1e(port, data);
+        break;
+
+    case 2:
+        outw(data, port);
+        break;
+
+    case 4:
+        outl(data, port);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
+    }
+}
+
 static void guest_io_write(unsigned int port, unsigned int bytes,
                            uint32_t data, struct domain *currd)
 {
     if ( admin_io_okay(port, bytes, currd) )
     {
-        switch ( bytes )
-        {
-        case 1:
-            outb((uint8_t)data, port);
-            if ( amd_acpi_c1e_quirk )
-                amd_check_disable_c1e(port, (uint8_t)data);
-            break;
-        case 2:
-            outw((uint16_t)data, port);
-            break;
-        case 4:
-            outl(data, port);
-            break;
-        }
+        _guest_io_write(port, bytes, data);
         return;
     }
 
@@ -420,6 +442,13 @@ static void guest_io_write(unsigned int port, unsigned int bytes,
             if ( pci_cfg_ok(currd, port & 3, size, &data) )
                 pci_conf_write(currd->arch.pci_cf8, port & 3, size, data);
         }
+        else if ( ioports_access_permitted(currd, port, port) )
+        {
+            if ( bytes > 1 && !(port & 1) &&
+                 ioports_access_permitted(currd, port, port + 1) )
+                size = 2;
+            _guest_io_write(port, size, data);
+        }
 
         if ( size == 4 )
             return;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi4I-0004U8-7H; Fri, 11 Sep 2020 12:22:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi4H-0004U1-4t
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:17 +0000
X-Inumbo-ID: b5c16212-342f-452c-a400-ca389ee1da55
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b5c16212-342f-452c-a400-ca389ee1da55;
 Fri, 11 Sep 2020 12:22:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=POpnr2WmZm2+XiHqvpDxW6Yu82IrAbe0NHSyNm0Y6v0=; b=Jcp9KE+RWLT07zgSXSuOdtoDZz
 LncDIWvqAb1q4R1x2Z8Z4BhzrIbKCh3RrT2uaHZorWW1SyNY2agNXEVpxnKuWKv8NZ3z2+nLgNnK0
 GLi9L2I8cRRLL4C+JTC2tESME+yVwtZCeKUel3b8PpdNQ/6j+pXtn4ae7rRQT00Aqu98=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4F-00084x-Vb
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4F-0002lU-Tg
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: don't override INVALID_M2P_ENTRY with
 SHARED_M2P_ENTRY
Message-Id: <E1kGi4F-0002lU-Tg@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c9476c4ad72e8a1842d713c74843034c7ec6eb51
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:14:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:14:43 2020 +0200

    x86: don't override INVALID_M2P_ENTRY with SHARED_M2P_ENTRY
    
    While in most cases code ahead of the invocation of set_gpfn_from_mfn()
    deals with shared pages, at least in set_typed_p2m_entry() I can't spot
    such handling (it's entirely possible there's code missing there). Let's
    try to play safe and add an extra check.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/x86_64/mm.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 1f32062c15..0d1aadbfce 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1327,12 +1327,19 @@ destroy_frametable:
 
 void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
 {
-    const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
-    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
+    unsigned long entry = pfn;
 
     if ( unlikely(!machine_to_phys_mapping_valid) )
         return;
 
+    if ( entry != INVALID_M2P_ENTRY )
+    {
+        const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+
+        if ( d && (d == dom_cow) )
+            entry = SHARED_M2P_ENTRY;
+    }
+
     if ( opt_pv32 &&
          mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
         compat_machine_to_phys_mapping[mfn] = entry;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi4S-0004X5-8t; Fri, 11 Sep 2020 12:22:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi4R-0004Wt-3d
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:27 +0000
X-Inumbo-ID: f6c2c38c-60e7-4ed8-9de0-94308643d260
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f6c2c38c-60e7-4ed8-9de0-94308643d260;
 Fri, 11 Sep 2020 12:22:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UR6s5GBiAi5s+ENomBFQAxrrmoT5QkGcctny+d1/42E=; b=cH4iGgIT6mJOa2FfKM2SfWOV0p
 jGfi0anFeOLnp1qccuxi5RKlc/k6t6MHbZPyQBZNVzUklISYfRc8Vfp14uIvDA+IKisLn5uJLLybL
 ORJSk+7HMTGXx6ehtUG5V+s4V66hbRir7qdrhpa/JkQxgpzsVjSk6NMvhAHNhsO1Glfk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4Q-00085b-4z
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4Q-0002m3-2D
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/mm: do not mark IO regions as Xen heap
Message-Id: <E1kGi4Q-0002m3-2D@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e5a1b6f0d2070c7a03f0f2cff5126a5fea94cc4d
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:15:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:15:26 2020 +0200

    x86/mm: do not mark IO regions as Xen heap
    
    arch_init_memory will treat all the gaps on the physical memory map
    between RAM regions as MMIO and use share_xen_page_with_guest in order
    to assign them to dom_io. This has the side effect of setting the Xen
    heap flag on such pages, and thus is_special_page would then return
    true which is an issue in epte_get_entry_emt because such pages will
    be forced to use write-back cache attributes.
    
    Fix this by introducing a new helper to assign the MMIO regions to
    dom_io without setting the Xen heap flag on the pages, so that
    is_special_page will return false and the pages won't be forced to use
    write-back cache attributes.
    
    Fixes: 81fd0d3ca4b2cd ('x86/hvm: simplify 'mmio_direct' check in epte_get_entry_emt()')
    Suggested-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/mm.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 56bf7add2b..42a6dc9ba4 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -271,6 +271,23 @@ static l4_pgentry_t __read_mostly split_l4e;
 #define root_pgt_pv_xen_slots ROOT_PAGETABLE_PV_XEN_SLOTS
 #endif
 
+/*
+ * Originally cloned from share_xen_page_with_guest(), just to avoid setting
+ * PGC_xen_heap on non-heap (typically) MMIO pages. Other pieces got dropped
+ * simply because they're not needed in this context.
+ */ 
+static void __init assign_io_page(struct page_info *page)
+{
+    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY);
+
+    /* The incremented type count pins as writable. */
+    page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
+
+    page_set_owner(page, dom_io);
+
+    page->count_info |= PGC_allocated | 1;
+}
+
 void __init arch_init_memory(void)
 {
     unsigned long i, pfn, rstart_pfn, rend_pfn, iostart_pfn, ioend_pfn;
@@ -291,7 +308,7 @@ void __init arch_init_memory(void)
      */
     BUG_ON(pvh_boot && trampoline_phys != 0x1000);
     for ( i = 0; i < 0x100; i++ )
-        share_xen_page_with_guest(mfn_to_page(_mfn(i)), dom_io, SHARE_rw);
+        assign_io_page(mfn_to_page(_mfn(i)));
 
     /* Any areas not specified as RAM by the e820 map are considered I/O. */
     for ( i = 0, pfn = 0; pfn < max_page; i++ )
@@ -332,7 +349,7 @@ void __init arch_init_memory(void)
             if ( !mfn_valid(_mfn(pfn)) )
                 continue;
 
-            share_xen_page_with_guest(mfn_to_page(_mfn(pfn)), dom_io, SHARE_rw);
+            assign_io_page(mfn_to_page(_mfn(pfn)));
         }
 
         /* Skip the RAM region. */
@@ -477,6 +494,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
 void share_xen_page_with_guest(struct page_info *page, struct domain *d,
                                enum XENSHARE_flags flags)
 {
+    ASSERT(d != dom_io); /* Should use assign_io_page(). */
+
     if ( page_get_owner(page) == d )
         return;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi4c-0004Yl-Ag; Fri, 11 Sep 2020 12:22:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi4b-0004Ya-8L
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:37 +0000
X-Inumbo-ID: b08e71ae-8c78-46b1-adf6-195d8d22f175
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b08e71ae-8c78-46b1-adf6-195d8d22f175;
 Fri, 11 Sep 2020 12:22:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Swk5m1BRMno+6Dp+ZfptKcjSQv3W8dDUvD07btifQyc=; b=IETmlEaJVBGFbryBAwZtTAy/pt
 V7aauUbrTvVfz2jkhNPur55XGCgari6kJFYq33+08hy/RRoChCEUdliuRoz8ViNVvzVoEcrfajrf3
 Ia8gwadpAcJnlIKVFOqFxqzgEqVEtkuuY1GfigOKgOQJ9JZGOPaFfvefni/LkbZZA/UM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4a-00085j-9U
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4a-0002mX-7g
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/PV: fold exit paths of ptwr_do_page_fault()
Message-Id: <E1kGi4a-0002mX-7g@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0fcfe9d95f8bb1d53cf68038f13bc3563020e8cd
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:16:14 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:16:14 2020 +0200

    x86/PV: fold exit paths of ptwr_do_page_fault()
    
    One less aspect to keep an eye on for things to stay in sync.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/pv/ro-page-fault.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c
index 0eedb70002..556ee7ca11 100644
--- a/xen/arch/x86/pv/ro-page-fault.c
+++ b/xen/arch/x86/pv/ro-page-fault.c
@@ -262,29 +262,23 @@ static int ptwr_do_page_fault(struct x86_emulate_ctxt *ctxt,
         .pte = pte,
     };
     struct page_info *page;
-    int rc;
+    int rc = X86EMUL_UNHANDLEABLE;
 
     page = get_page_from_mfn(l1e_get_mfn(pte), current->domain);
     if ( !page )
         return X86EMUL_UNHANDLEABLE;
 
-    if ( !page_lock(page) )
+    if ( page_lock(page) )
     {
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
-    }
+        if ( (page->u.inuse.type_info & PGT_type_mask) == PGT_l1_page_table )
+        {
+            ctxt->data = &ptwr_ctxt;
+            rc = x86_emulate(ctxt, &ptwr_emulate_ops);
+        }
 
-    if ( (page->u.inuse.type_info & PGT_type_mask) != PGT_l1_page_table )
-    {
         page_unlock(page);
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
     }
 
-    ctxt->data = &ptwr_ctxt;
-    rc = x86_emulate(ctxt, &ptwr_emulate_ops);
-
-    page_unlock(page);
     put_page(page);
 
     return rc;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi4m-0004Zp-Cc; Fri, 11 Sep 2020 12:22:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi4l-0004Ze-Cv
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:47 +0000
X-Inumbo-ID: 50ed6eed-2df0-4fbd-a618-808b0f9e2ab5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 50ed6eed-2df0-4fbd-a618-808b0f9e2ab5;
 Fri, 11 Sep 2020 12:22:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=39udyW2LawGUVsjyPWa0CtGOfFlBzq6XhAc+tVPOB7A=; b=RK2Hleqzm+7Inly6NS+HFBydmY
 vnr6bXct0idFReyxS6gdCFRS00eFL4xaCn74t5MJ6bFA7XR9YOJ38uJM48DbffzfuLxS2r+I2cQ+L
 9k+yApjtKo9W0CnC0cvLze3/EGUSXL7JqqMS5FY7T2DTbesLJAnCcoMjOl7JhqrwZrjQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4k-00085u-Dc
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4k-0002n0-C6
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/hypfs: fix writing of custom parameter
Message-Id: <E1kGi4k-0002n0-C6@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b4e41b1750d550bf2b1ccf97ee46f4f682bdbb62
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Sep 11 14:20:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:20:10 2020 +0200

    xen/hypfs: fix writing of custom parameter
    
    Today the maximum allowed data length for writing a hypfs node is
    tested in the generic hypfs_write() function. For custom runtime
    parameters this might be wrong, as the maximum allowed size is derived
    from the buffer holding the current setting, while there might be ways
    to set the parameter needing more characters than the minimal
    representation of that value.
    
    One example for this is the "ept" parameter. Its value buffer is sized
    to be able to hold the string "exec-sp=0" or "exec-sp=1", while it is
    allowed to use e.g. "no-exec-sp" or "exec-sp=yes" for setting it.
    
    Fix that by moving the length check one level down to the type
    specific write function.
    
    In order to avoid allocation of arbitrary sized buffers use a new
    MAX_PARAM_SIZE macro as an upper limit for custom writes. The value
    of MAX_PARAM_SIZE is the same as the limit in parse_params() for a
    single parameter.
    
    Fixes: a659d7cab9af ("xen: add runtime parameter access support to hypfs")
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/common/hypfs.c      | 11 +++++++----
 xen/common/kernel.c     |  2 +-
 xen/include/xen/param.h |  3 +++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c
index b74c228191..8e932b5cf9 100644
--- a/xen/common/hypfs.c
+++ b/xen/common/hypfs.c
@@ -297,7 +297,9 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
     int ret;
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
-    ASSERT(ulen <= leaf->e.max_size);
+
+    if ( ulen > leaf->e.max_size )
+        return -ENOSPC;
 
     if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
          leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
@@ -356,6 +358,10 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
 
+    /* Avoid oversized buffer allocation. */
+    if ( ulen > MAX_PARAM_SIZE )
+        return -ENOSPC;
+
     buf = xzalloc_array(char, ulen);
     if ( !buf )
         return -ENOMEM;
@@ -386,9 +392,6 @@ static int hypfs_write(struct hypfs_entry *entry,
 
     ASSERT(entry->max_size);
 
-    if ( ulen > entry->max_size )
-        return -ENOSPC;
-
     l = container_of(entry, struct hypfs_entry_leaf, e);
 
     return entry->write(l, uaddr, ulen);
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 9de07b7ac5..c3a943f077 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -57,7 +57,7 @@ static int assign_integer_param(const struct kernel_param *param, uint64_t val)
 static int parse_params(const char *cmdline, const struct kernel_param *start,
                         const struct kernel_param *end)
 {
-    char opt[128], *optval, *optkey, *q;
+    char opt[MAX_PARAM_SIZE], *optval, *optkey, *q;
     const char *p = cmdline, *key;
     const struct kernel_param *param;
     int rc, final_rc = 0;
diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h
index f4be944248..d0409d3a0e 100644
--- a/xen/include/xen/param.h
+++ b/xen/include/xen/param.h
@@ -26,6 +26,9 @@ struct kernel_param {
     } par;
 };
 
+/* Maximum length of a single parameter string. */
+#define MAX_PARAM_SIZE 128
+
 extern const struct kernel_param __setup_start[], __setup_end[];
 
 #define __param(att)      static const att \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:22:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:22:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi4x-0004au-EH; Fri, 11 Sep 2020 12:22:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi4w-0004al-Dp
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:58 +0000
X-Inumbo-ID: f436e823-c70e-49ac-8499-2baedced235b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f436e823-c70e-49ac-8499-2baedced235b;
 Fri, 11 Sep 2020 12:22:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=aXHQkuFgBhtY6pfEixGpxKqM9+0za2FDH42gUXoI5Uc=; b=nf6LVTyTUCR3wFg3eqVuk/olb9
 Ie6KSMHc/BfxhFUX41sr/NzpLM36LGYVWzigbV4QbjTAsP0LAmA25I034fNqw9kj/QWWqmfSKY1YL
 zhPmuNL5V7X8n3ByHOCXsx/DE2BAd+DUmouNk/UUx1qxG6FkA720btbPNk4rfszWmHS4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4v-000862-JH
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi4v-0002ol-II
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:22:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kGi4v-0002ol-II@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:22:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit eca6d5e914ddc134b3c4d2697e40002182eb6c06
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:06:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:06:48 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 878ee5192d..e66fa99ec7 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2543,7 +2543,7 @@ static void __init ioapic_init_mappings(void)
 
     nr_irqs_gsi = 0;
 
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         union IO_APIC_reg_01 reg_01;
         paddr_t ioapic_phys = mp_ioapics[i].mpc_apicaddr;
@@ -2560,7 +2560,6 @@ static void __init ioapic_init_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:23:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:23:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi58-0004c7-Hc; Fri, 11 Sep 2020 12:23:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi57-0004bw-4b
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:09 +0000
X-Inumbo-ID: 6e63ad6a-40be-4f74-8d52-62ecbaf57b94
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6e63ad6a-40be-4f74-8d52-62ecbaf57b94;
 Fri, 11 Sep 2020 12:23:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mm5wHAh5mZd4urpFvDsFau30nhNdmuXZ2MoKo3NXSFA=; b=2MG/e2b4Nyu0fSAIgb6+QXLRr0
 OHFu5Q7e1SUGk7IyVoLv4a3qOrAkmkCgknYpymPXnwVvJsNwT93XlJGqvDLXaGI1AMEJKwWij5Bv+
 InDMDYYukOoiQO7Je81+kvJi/Nxdo46VgE9aGrUXNzrrnAbEJhXj/0a1HJcpgwGCbqGE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi55-00086Q-N1
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi55-0002pX-Lz
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/tsc: Fix diagnostics for TSC frequency
Message-Id: <E1kGi55-0002pX-Lz@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit edf5b8627fc8568d14bffef400a9753bf7ce5766
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:07:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:07:34 2020 +0200

    x86/tsc: Fix diagnostics for TSC frequency
    
    A Gemini Lake platform prints:
    
      (XEN) CPU0: TSC: 19200000MHz * 279 / 3 = 1785600000MHz
      (XEN) CPU0: 800..1800 MHz
    
    during boot.  The units on the first line are Hz, not MHz, so correct that and
    add a space for clarity.
    
    Also, for the min/max line, use three dots instead of two and add more spaces
    so that the line can't be mistaken for being a double decimal point typo.
    
    Boot now reads:
    
      (XEN) CPU0: TSC: 19200000 Hz * 279 / 3 = 1785600000 Hz
      (XEN) CPU0: 800 ... 1800 MHz
    
    Extend these changes to the other TSC diagnostics.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b2bc1e714462c6cc222e3bbc38d87b039b4fa405
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/cpu/amd.c   |  4 ++--
 xen/arch/x86/cpu/intel.c | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 0cc6853c42..8bc51bec10 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -624,10 +624,10 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 	if (idx && idx < h &&
 	    !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
 	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu (%lu..%lu) MHz\n",
+		printk("CPU%u: %lu (%lu ... %lu) MHz\n",
 		       smp_processor_id(), FREQ(val), FREQ(lo), FREQ(hi));
 	else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu..%lu MHz\n",
+		printk("CPU%u: %lu ... %lu MHz\n",
 		       smp_processor_id(), FREQ(lo), FREQ(hi));
 	else
 		printk("CPU%u: %lu MHz\n", smp_processor_id(), FREQ(lo));
diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c
index 69e99bb358..37439071d9 100644
--- a/xen/arch/x86/cpu/intel.c
+++ b/xen/arch/x86/cpu/intel.c
@@ -396,14 +396,14 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
 
             val *= ebx;
             do_div(val, eax);
-            printk("CPU%u: TSC: %uMHz * %u / %u = %LuMHz\n",
+            printk("CPU%u: TSC: %u Hz * %u / %u = %Lu Hz\n",
                    smp_processor_id(), ecx, ebx, eax, val);
         }
         else if ( ecx | eax | ebx )
         {
             printk("CPU%u: TSC:", smp_processor_id());
             if ( ecx )
-                printk(" core: %uMHz", ecx);
+                printk(" core: %u Hz", ecx);
             if ( ebx && eax )
                 printk(" ratio: %u / %u", ebx, eax);
             printk("\n");
@@ -417,11 +417,11 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
         {
             printk("CPU%u:", smp_processor_id());
             if ( ecx )
-                printk(" bus: %uMHz", ecx);
+                printk(" bus: %u MHz", ecx);
             if ( eax )
-                printk(" base: %uMHz", eax);
+                printk(" base: %u MHz", eax);
             if ( ebx )
-                printk(" max: %uMHz", ebx);
+                printk(" max: %u MHz", ebx);
             printk("\n");
         }
     }
@@ -446,7 +446,7 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
 
         printk("CPU%u: ", smp_processor_id());
         if ( min_ratio )
-            printk("%u..", (factor * min_ratio + 50) / 100);
+            printk("%u ... ", (factor * min_ratio + 50) / 100);
         printk("%u MHz\n", (factor * max_ratio + 50) / 100);
     }
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:23:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:23:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi5H-0004d1-JB; Fri, 11 Sep 2020 12:23:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi5G-0004cr-NK
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:18 +0000
X-Inumbo-ID: a1445ee6-87bc-4256-8f1d-f99227513beb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a1445ee6-87bc-4256-8f1d-f99227513beb;
 Fri, 11 Sep 2020 12:23:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=nG8hafiNRp5ZVMxUvm+mqnEkiJWYAO1jWuVr+lxxBRc=; b=AAphDJbGGpD01OubBsK5k9vm3i
 NEDowbVSaYBP5R+M51tzihsvtDYHq76dlVpNjejbf2GsJMKxKr+lHc4/0tChMizjDng0kZBOYkeIr
 1a8vyyFX5lKGliWGMslt5Lom6kTBZmmbtV4eExh+BuM5c3vA7YnTP8TpcF2l89F7HMYY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5F-00087I-Ra
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5F-0002q9-Pg
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] build: work around bash issue
Message-Id: <E1kGi5F-0002q9-Pg@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5482c2887d89bf742fd982b8c47510617a5096ef
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:08:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:08:09 2020 +0200

    build: work around bash issue
    
    Older bash (observed with 3.2.57(2)) fails to honor "set -e" for certain
    built-in commands ("while" here), despite the command's status correctly
    being non-zero. The subsequent objcopy invocation now being separated by
    a semicolon results in no failure. Insert an explicit "exit" (replacing
    ; by && ought to be another possible workaround).
    
    Fixes: e321576f4047 ("xen/build: start using if_changed")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    master commit: 5132a0a37190b73c99dbbecf48dc4fb214feaf14
    master date: 2020-08-07 13:12:00 +0200
---
 xen/Rules.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/Rules.mk b/xen/Rules.mk
index ebfd40caff..62e9fabe7a 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -193,7 +193,7 @@ define cmd_obj_init_o
             echo "Error: size of $<:$$name is 0x$$sz" >&2; \
             exit $$(expr $$idx + 1);; \
         esac; \
-    done; \
+    done || exit $$?; \
     $(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
 endef
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:23:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:23:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi5R-0004e1-Kh; Fri, 11 Sep 2020 12:23:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi5Q-0004ds-QC
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:28 +0000
X-Inumbo-ID: c6560210-a953-46f4-9a64-dc2fdbfd622e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c6560210-a953-46f4-9a64-dc2fdbfd622e;
 Fri, 11 Sep 2020 12:23:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LtIg6TgAZcY/DBnpzKs9a5G89+OuxOnDmk729btOj0c=; b=obAxNCrqOYSzCHQRcNC01npETH
 85wN1x4bOk386mj6Q9usudR/CP1SpULpKtN3oDb/2McO0SGvkNDBpOLRyLGbKxLoMoEyTo1TwePFK
 yQH4AGPWFnjLvJjUdSWlY7esHqHqQrZIpxW0pun0JPySK2IggWv4emqGLbUvD32emQCs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5P-00087R-Ve
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5P-0002qf-UF
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86: use constant flags for section .init.rodata
Message-Id: <E1kGi5P-0002qf-UF@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 80dec06f6a5f4e56ef1f26087282402c21708ebf
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:08:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:08:37 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 8b57a00040..1e880eb9f6 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -967,7 +967,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -1012,5 +1012,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:23:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:23:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi5b-0004fQ-MF; Fri, 11 Sep 2020 12:23:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi5b-0004fK-1S
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:39 +0000
X-Inumbo-ID: f0fce05e-eab4-4045-bd47-e1c3e9933da0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f0fce05e-eab4-4045-bd47-e1c3e9933da0;
 Fri, 11 Sep 2020 12:23:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cjydPU7uKYvp0aAvkHh2P13DpQecjZGn8McHIs8CLU4=; b=eplqoph8oyRbaDr18NgWzBqmXz
 hbjZQ5gJ76rj1C1qvq4Wk9LgUAj2758MWrP2Bbk66rffvp4SK2xMJVn/FK6S/fDMns6lhQ7eCp425
 qKMBjRmR/huxxxtLD89YRF6j0sp4luwJtDsE95HekAypX6n0m474uzqPpV3EBA2AoAKQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5a-00087Y-3K
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:38 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5a-0002rM-2K
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:38 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kGi5a-0002rM-2K@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 98aa6ea75152115297ad26aed6c1c5f8d202bdba
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:09:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:09:10 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 tools/tests/cpu-policy/test-cpu-policy.c    |  5 +++++
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index 7ba9707236..0fa209f1ea 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -374,6 +374,11 @@ static void test_msr_deserialise_failure(void)
             .msr = { .idx = 0xce, .val = ~0ull },
             .rc = -EOVERFLOW,
         },
+        {
+            .name = "truncated val",
+            .msr = { .idx = 0x10a, .val = ~0ull },
+            .rc = -EOVERFLOW,
+        },
     };
 
     printf("Testing MSR deserialise failure:\n");
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 22f921cc71..7d99c0e64c 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -220,8 +220,10 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index fe7492a225..d06a2fd4c8 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -267,7 +267,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*a  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(CORE_CAPS,     9*32+30) /*   IA32_CORE_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 203c713320..48ba4a59c0 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } platform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 171abf7008..7d71e92a38 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -99,6 +100,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);     break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:23:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:23:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi5l-0004gT-Nt; Fri, 11 Sep 2020 12:23:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi5l-0004gK-37
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:49 +0000
X-Inumbo-ID: 7ef2a970-bac7-4575-98a6-8aa6630d93d2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7ef2a970-bac7-4575-98a6-8aa6630d93d2;
 Fri, 11 Sep 2020 12:23:48 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=8sP8DQo9COSiwPmPa8yQOQpBhyGJWmiYDwEkpnsJC1U=; b=eL0Ga97sALoSEu4B6MtxtEzHiD
 Asju/Jot8sHSt5a4FHonwPCR5Ooc5gNh8Pt36ivQ+dbobRh5HPa1zsHgrumREz3OZ+tqRl8hLEjWu
 4gFjeoB62zEWH5PRYup6EimAM6s0INUCIzR0DJGcy1+TQViSE6wCZ6aKgI/sOAJcSb2A=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5k-00087g-7J
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:48 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5k-0002sM-6F
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:48 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kGi5k-0002sM-6F@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:48 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 369e7a35bf651ce46778ff5598428b31c78924b7
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:09:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:09:56 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 63a03ef1e5..4b424fac95 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -719,6 +719,14 @@ int init_domain_cpuid_policy(struct domain *d)
     if ( d->disable_migrate )
         p->extd.itsc = cpu_has_itsc;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     d->arch.cpuid = p;
 
     recalculate_cpuid_policy(d);
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 7d99c0e64c..d72ab0fa1f 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -130,6 +130,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
         mp->platform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:24:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:24:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi5x-0004hm-Pm; Fri, 11 Sep 2020 12:24:01 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi5w-0004hf-D7
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:00 +0000
X-Inumbo-ID: 8c960f9e-292a-401d-b501-d15c43993d18
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8c960f9e-292a-401d-b501-d15c43993d18;
 Fri, 11 Sep 2020 12:23:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tX9ikMSfH+e5xLRQm29hXBoNXoD4Gd5E6+atIol7B8I=; b=EFzKMwK5bir+/SpESsil/Kt+hp
 v9tDIlft+Zts8MrKMenVwjYXZQDJYToWQ3cNpgf8XRoPmvoBpYztPIKejvneMtfDE2fOwFuyKih2P
 PyMHDf8AVhznw2SXh46ycOKaR82hwmA05qdDP7HU2K8F0iHFfPxmrMDhEYSX3I/0e76c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5u-00087o-Az
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:58 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi5u-0002t2-A8
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:23:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kGi5u-0002t2-A8@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:23:58 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ceafff707c96ca5cf01a435e4cf6f64c2dfc9a4d
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:10:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:10:26 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 102079a801..3b726f7c00 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1031,17 +1031,54 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:24:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:24:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi66-0004it-TD; Fri, 11 Sep 2020 12:24:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi65-0004il-MU
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:09 +0000
X-Inumbo-ID: 546b168a-7e16-4bff-b3a3-c2ba39e46bb8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 546b168a-7e16-4bff-b3a3-c2ba39e46bb8;
 Fri, 11 Sep 2020 12:24:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/t4H6VDYnR4D1AYiJn4Z88zBlzvbVd0EZ0D9GuyYA6g=; b=NI1fkcmfCQbpy5Yz8pyAT79A2q
 UZq6prVkttVqVEwyEW5kqnfB9ynRLM7b8zQHKmdDN6MXkQ4+Dky3FWRtSpw3lIjaUy6bBjTPpRGYn
 YSGp27NW4chRgmGbKqNUjZhRj7bc6/fduJV4lomZ3w0Ou/2P/iGMIvbta6fQl7Pn1Y5g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi64-000887-F8
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi64-0002uX-E6
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kGi64-0002uX-E6@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:24:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 431d52afd9438a3a126dfd787bd2d69b76906cb5
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:10:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:10:57 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 18 ++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index fee6c3931a..8351391cdd 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1562,6 +1562,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1572,14 +1582,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index ec5a7d2dca..44e4ea2582 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -444,17 +444,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 void toggle_guest_mode(struct vcpu *v)
 {
     const struct domain *d = v->domain;
+    unsigned long gs_base;
 
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 254da2b849..7c21076dd0 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -801,17 +801,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -860,15 +849,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -997,14 +984,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 3b726f7c00..48fd60a876 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1002,10 +1002,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1022,10 +1019,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 6fd94c2e14..40385f5eaa 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -516,7 +516,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:24:20 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:24:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGi6G-0004jy-Uy; Fri, 11 Sep 2020 12:24:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGi6G-0004jq-6H
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:20 +0000
X-Inumbo-ID: 7e92ce69-08ad-4885-87c6-a254960206a0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7e92ce69-08ad-4885-87c6-a254960206a0;
 Fri, 11 Sep 2020 12:24:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=CjuGVAPvpvY/xho+oUQAbN3zElY7j2PagsRLM4Eutkw=; b=adwvq3wUEAtsswr51sJsMVKlFP
 g1X/0v6ud0T5Kl4LXvfLRuHozSy8+PK8Sf5314nfqLtP7mTd6HbNsL1GnQsHm56Qy7HHHfhBi7sd/
 yo0oyufKcrXpoNNG0kBUm3846ynoI9O+2zRvlJ8/YA6crtH0XO7FB8Rrq2/RoCq3Kb4M=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi6E-00088f-J6
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:18 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGi6E-0002vS-IG
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:24:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kGi6E-0002vS-IG@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:24:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 483b43c4573329a28f1c9e18f90694e5be35ddb9
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:11:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:11:43 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 189 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 139 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 8351391cdd..b1c8644945 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1017,13 +1017,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1342,58 +1338,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1401,62 +1399,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1575,7 +1536,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1592,35 +1552,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1830,8 +1761,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 4eb41792e2..0c0c2a964e 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1518,8 +1518,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1556,14 +1555,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index d568e86db9..2310878e41 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:44:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:44:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiPP-0007bc-JA; Fri, 11 Sep 2020 12:44:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiPP-0007bW-44
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:44:07 +0000
X-Inumbo-ID: 1be6895d-a3eb-4c79-91a0-67d52ae74fb4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1be6895d-a3eb-4c79-91a0-67d52ae74fb4;
 Fri, 11 Sep 2020 12:44:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=lxT0K/C69jxH7Afp53wm54n/fWjFdJX6lnH+um4zPXA=; b=rmgXyeons3aG/6Hv3SQPjS6+VZ
 BmQIrR3ReV5WKh5OQoMzaVX/9F1Ke/YfUFxeJ+5dAHmCpPrs8AVftvsP8+TGCMaHmrUO7SGcQjkXk
 ayn8t3BpaO+FHUKKFxuq+gzuM3Mrc6dmGu9srvCgWuIM654hPJf5tHCsVmvl9Va54cFw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiPO-00006J-6e
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:44:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiPO-00048k-4E
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:44:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm64: force gcc 10+ to always inline generic
 atomics helpers
Message-Id: <E1kGiPO-00048k-4E@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:44:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5d45ecabe3c0b2097df623ab7b471f8915cfdde6
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 12:45:33 2020 +0200
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 11 13:36:27 2020 +0100

    xen/arm64: force gcc 10+ to always inline generic atomics helpers
    
    Recent versions of gcc (at least 10.x) will not inline generic atomics
    helpers by default. Instead they will expect the software to either link
    with libatomic.so or implement the helpers, which would result in
    
    undefined reference to `__aarch64_ldadd4_acq_rel'
    
    for us (not having any local implementation).
    
    To keep the previous behavior, force gcc to always inline the generic
    atomics helpers.
    
    Long term we probably want to avoid relying on gcc atomics helpers as
    this doesn't allow us to switch between LSE and LL/SC atomics.
    
    Suggested-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/arch.mk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/arch/arm/arch.mk b/xen/arch/arm/arch.mk
index c8186f5828..11caec86ba 100644
--- a/xen/arch/arm/arch.mk
+++ b/xen/arch/arm/arch.mk
@@ -12,6 +12,7 @@ CFLAGS-$(CONFIG_ARM_32) += -mcpu=cortex-a15
 
 CFLAGS-$(CONFIG_ARM_64) += -mcpu=generic
 CFLAGS-$(CONFIG_ARM_64) += -mgeneral-regs-only # No fp registers etc
+$(call cc-option-add,CFLAGS-$(CONFIG_ARM_64),CC,-mno-outline-atomics)
 
 ifneq ($(filter command line environment,$(origin CONFIG_EARLY_PRINTK)),)
     $(error You must use 'make menuconfig' to enable/disable early printk now)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGia4-00008b-Th; Fri, 11 Sep 2020 12:55:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGia3-00008Q-7c
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:07 +0000
X-Inumbo-ID: fe821e02-1f3d-4ed6-b02c-0ee59ac5bf7e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fe821e02-1f3d-4ed6-b02c-0ee59ac5bf7e;
 Fri, 11 Sep 2020 12:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0qMrVQ4cBrGj8CX6cAPQMja/Jaa3oN2k/CTvs7O5M5w=; b=NtH/fBdKY5MmE5lnPWK1JUO98q
 Edm7W1zGmI2DlSk5gn2vmUT+3chvZpa7qo5FSylLy2+3XYSsb4tgZDHO43gl0l7h49Ok1tZjSqj/Z
 AZZOXB1Mk4sLmuxJ+IB9234IqC5Fhm/VIAQOYD8QRB42YlZy59nCIOrTJz/Vw71X9Mnk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGia2-0000KE-DZ
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGia2-0004nW-Bn
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kGia2-0004nW-Bn@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0861885b5f88213ac393053f496b98f05085577c
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:48:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:48:57 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 97cb2d154a..e710827dcf 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2542,7 +2542,7 @@ void __init init_ioapic_mappings(void)
 
     if ( smp_found_config )
         nr_irqs_gsi = 0;
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         if ( smp_found_config )
         {
@@ -2565,7 +2565,6 @@ void __init init_ioapic_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiaI-00009d-VW; Fri, 11 Sep 2020 12:55:22 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiaI-00009W-7D
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:22 +0000
X-Inumbo-ID: 236b683d-2c10-462b-92a3-5c57e9574a76
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 236b683d-2c10-462b-92a3-5c57e9574a76;
 Fri, 11 Sep 2020 12:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=HDza1KUrVhTJRYU4M62JDCQXnY/f0QpkesTn+w/Nh/8=; b=g9QGj/XN4RjA5smX3PtiJKRZ+A
 7K3/tCrD7BAZtdfYpWOf+28Bqwkjo6QR0Or716mrMh1aeMIqXrmiEOHN3DI/a9nBRfWzAS6OH+Y1H
 D8g+mFCTvsKEH9j305mbYXDag6pRAYeWfk2zGSl33GUsme6kMHvSilAPpW5TnVOM9nSo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaC-0000KQ-HW
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaC-0004o6-GK
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86: use constant flags for section .init.rodata
Message-Id: <E1kGiaC-0004o6-GK@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a7f0434093f52768e333b64b73c1b02fa0b310fb
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:49:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:49:52 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index c7cfcf9199..24731eeb37 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -914,7 +914,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -958,5 +958,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiaP-0000AX-0k; Fri, 11 Sep 2020 12:55:29 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiaN-0000AP-Lb
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:27 +0000
X-Inumbo-ID: 2efce858-c602-46b0-a98c-5b6676cd3534
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 2efce858-c602-46b0-a98c-5b6676cd3534;
 Fri, 11 Sep 2020 12:55:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7zMnrNxp/KTYsQFxNAceRZy3YY/mmkHm9P3ml+euuiU=; b=SWPepV57j7aNVeML7u78y5aiRw
 l+EgZriM0c5xy/vXtJc9YjCpjU/mC7KvewJtYPB9nFu63qylFaXX+e1g2jm+fPCnGnhc4AFTf5xQk
 1iQdFdMPnYXkUm+XNVdIs4xJ7c5uMbn6NEX6sLrDOd44iVLgxDwPA1YbhxbnytidXjjw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaM-0000LC-Lk
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaM-0004oi-KR
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kGiaM-0004oi-KR@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ac4ec487e086dc9ed00f1c230df8f1621e536c5a
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:50:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:50:26 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 tools/tests/cpu-policy/test-cpu-policy.c    |  5 +++++
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index fe8cdf6ea9..124eec21da 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -328,6 +328,11 @@ static void test_msr_deserialise_failure(void)
             .msr = { .idx = 0xce, .val = ~0ull },
             .rc = -EOVERFLOW,
         },
+        {
+            .name = "truncated val",
+            .msr = { .idx = 0x10a, .val = ~0ull },
+            .rc = -EOVERFLOW,
+        },
     };
 
     printf("Testing MSR deserialise failure:\n");
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 6cbc078d73..9caa387eda 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -183,8 +183,10 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index a2482c3627..3162ee0378 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -259,7 +259,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*!  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:1.eax, word 10 */
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 203c713320..48ba4a59c0 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } platform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 171abf7008..7d71e92a38 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -99,6 +100,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);     break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiaZ-0000CQ-2J; Fri, 11 Sep 2020 12:55:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiaX-0000CF-Sk
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:37 +0000
X-Inumbo-ID: 50dd8c19-5288-4edb-924b-f7d44c7641db
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 50dd8c19-5288-4edb-924b-f7d44c7641db;
 Fri, 11 Sep 2020 12:55:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=X0Hj/4bw6VoPhMWKLFhRYPaGeJDwgFN74wy5UCenVAk=; b=Bt6cWdSILOHk3l4+qM1xa10oqQ
 N5beZ1dGGyLGrMCKREjhLE69Ikp9qF0lm3eW7KXLbRKC7NPN+hqgKmEmxicCIlA0a1xtDURY4uUWW
 4uoleHtdbEoloQGgMroUwMGSWOJQfC6pLufTEI/L2kqJOXyzQ8ycujDpiAsHdyXNDWvc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaW-0000LK-Ph
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiaW-0004pB-Oc
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kGiaW-0004pB-Oc@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b9083432f1d40ff1b7b8b9a849a8ec54c4b23c88
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:51:08 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:51:08 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index a887f38d7f..27132f91a6 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -627,6 +627,14 @@ int init_domain_cpuid_policy(struct domain *d)
 
     recalculate_cpuid_policy(d);
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     return 0;
 }
 
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 9caa387eda..875ac39d30 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -96,6 +96,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
         mp->platform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiaj-0000DS-47; Fri, 11 Sep 2020 12:55:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiah-0000DI-QA
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:47 +0000
X-Inumbo-ID: e03d3e57-68fc-4025-85aa-3d71cb9fd75b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e03d3e57-68fc-4025-85aa-3d71cb9fd75b;
 Fri, 11 Sep 2020 12:55:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mUlIHxhiv4ey7QIZzgqrHalO1SgcJvF/WNr6F1Hu/zc=; b=qbWf4Hq9GcOUexQNVLhl7ejCuB
 v/ZAvIHCM5yFeQMgo9JRKJsR02HAD3XEDKbKBLmimMWLKh/KAT40yAwfzFgv2vuHVKr00mSXWUTdy
 slKMudxW4o9nK4Eqj7Xv+NskoN1lLpaEugYBN1t/eA57B1zlUDW/eY701MzYnweIlpOE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiag-0000LR-Tb
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiag-0004pz-SH
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kGiag-0004pz-SH@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 64690393a81c96296dbde5b865460144a86290c3
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:51:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:51:43 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 8ea09ecc30..27fd0d5fbf 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1056,17 +1056,54 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:55:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:55:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiat-0000EY-5o; Fri, 11 Sep 2020 12:55:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGias-0000EN-7K
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:58 +0000
X-Inumbo-ID: d4cb69b5-8f8d-4765-8c21-a90b3a738ed1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d4cb69b5-8f8d-4765-8c21-a90b3a738ed1;
 Fri, 11 Sep 2020 12:55:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=SlUf5GPyi11MCY20Bm5Jct0jX66aoU2T/L3KY3Rpl10=; b=UpzqMHRTOWazve1kaH9v8UxGgo
 mD1Qw2hu8hyFknf36vtuQUiOY5PHxAtc6dPBMLjtLfXHSZz2RhY5MXhPJGWmKFwJxLlKGdicZCMkf
 o4UIoaq3n5hIYNLgUGZiQWG2usSgUeNj5y/wa/TdDZNsyuUkCnQXLcN3E2i19MFj/1f4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiar-0000Lh-1h
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiar-0004qq-0d
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:55:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kGiar-0004qq-0d@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:55:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 761e8df102594da97cc32a895daa44386ee9476e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:52:35 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:52:35 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 19 +++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index a905aec8e1..2a2327580e 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1546,6 +1546,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1556,14 +1566,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 3308b6b7d4..aea8d6b2b9 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -408,16 +408,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 
 void toggle_guest_mode(struct vcpu *v)
 {
+    unsigned long gs_base;
+
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 90693fe9ee..9a5b3edfae 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -757,17 +757,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -816,15 +805,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -953,14 +940,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 27fd0d5fbf..db4f035d8d 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1027,10 +1027,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1047,10 +1044,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 81f32bb56d..1cd8743d11 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -505,7 +505,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 12:56:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 12:56:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGib4-0000Fv-8r; Fri, 11 Sep 2020 12:56:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGib2-0000Fk-QC
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:56:08 +0000
X-Inumbo-ID: 60388a0a-49ae-45ff-a602-22f6cd9f4956
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 60388a0a-49ae-45ff-a602-22f6cd9f4956;
 Fri, 11 Sep 2020 12:56:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=WSmFV+SiOHCTey+/PNTjeAOw9HBy0Rea2cLdrLP05sA=; b=uT5NOl6phByWLTqOUb/diIcgTz
 OBRc8so8+IcaOsUtkx06u2v55WYKoeWab7BQSOaRF49Kr5KlnIh2P8QYA6wnR+qK6sq3FaqaXPVY0
 imgr2JABz3UAFqkS7NY55JtC7jIDipOdLsRc2LSFCeNzjTBDLpKTSEWMeNFdKVTTcFlA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGib1-0000M6-6a
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:56:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGib1-0004rm-4k
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 12:56:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kGib1-0004rm-4k@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 12:56:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c663fa577b42e7f4731bb33fc7f94f7ffb05a1ef
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:53:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:53:37 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 189 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 139 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 2a2327580e..4b5ad0fd17 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1009,13 +1009,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1326,58 +1322,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1385,62 +1383,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1559,7 +1520,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1576,35 +1536,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1813,8 +1744,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 8317ef8fb0..fb73319cae 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1522,8 +1522,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1560,14 +1559,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index 63eebab48a..52752fe5ab 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGipa-0001ta-Cc; Fri, 11 Sep 2020 13:11:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGipY-0001tV-OQ
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:08 +0000
X-Inumbo-ID: 99a7d1e3-f160-4c6b-ab1a-07314bf6aaf8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 99a7d1e3-f160-4c6b-ab1a-07314bf6aaf8;
 Fri, 11 Sep 2020 13:11:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DBKO2OqLwqHVlMf0LCufGikTvIrxORK7n9IjzGKMkNo=; b=sFvhZMvm9QaD/121enzvcD0fto
 /Eh1BhAE0YsKM2tveoHXlo7dMI2iX9uqmoNEOTKuox8AcQYmTWjf4MoQtI5v+tJkv0o+b2x+bXMzV
 U8dr1MS6hLI+rA1IC7zK5q0OeYYlgueXzi5JtSkYiX9ny5BmRIzzv8TtdI24MR7N9PMA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipW-0000gE-Pn
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipW-00068i-Nn
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] libx86: introduce a helper to deserialise
 msr_policy objects
Message-Id: <E1kGipW-00068i-Nn@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c481b9f32da5af232edaf0feff0bf213fa23e0ba
Author:     Sergey Dyasli <sergey.dyasli@citrix.com>
AuthorDate: Fri Sep 11 14:56:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:56:34 2020 +0200

    libx86: introduce a helper to deserialise msr_policy objects
    
    As with the serialise side, Xen's copy_from_guest API is used, with a
    compatibility wrapper for the userspace build.
    
    Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Wei Liu <wei.liu2@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afec08b92ffe8b85d2bf2e8c7c221b63ba96743e
    master date: 2019-03-12 14:12:23 +0000
---
 xen/include/xen/lib/x86/msr.h | 21 ++++++++++++++
 xen/lib/x86/msr.c             | 67 +++++++++++++++++++++++++++++++++++++++++++
 xen/lib/x86/private.h         | 14 +++++++++
 3 files changed, 102 insertions(+)

diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index e2cfbb1a8d..6236622adf 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -48,6 +48,27 @@ typedef xen_msr_entry_t msr_entry_buffer_t[];
 int x86_msr_copy_to_buffer(const struct msr_policy *policy,
                            msr_entry_buffer_t msrs, uint32_t *nr_entries);
 
+/**
+ * Unserialise an msr_policy object from an array of msrs.
+ *
+ * @param policy     The msr_policy object to unserialise into.
+ * @param msrs       The array of msrs to unserialise from.
+ * @param nr_entries The number of entries in 'msrs'.
+ * @param err_msr    Optional hint filled on error.
+ * @returns -errno
+ *
+ * Reads at most MSR_MAX_SERIALISED_ENTRIES.  May fail for a number of reasons
+ * based on the content in an individual 'msrs' entry, including the MSR index
+ * not being valid in the policy, the flags field being nonzero, or if the
+ * value provided would truncate when stored in the policy.  In such cases,
+ * the optional err_* pointer is filled in to aid diagnostics.
+ *
+ * No content validation is performed on the data stored in the policy object.
+ */
+int x86_msr_copy_from_buffer(struct msr_policy *policy,
+                             const msr_entry_buffer_t msrs, uint32_t nr_entries,
+                             uint32_t *err_msr);
+
 #endif /* !XEN_LIB_X86_MSR_H */
 
 /*
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 60fb567687..7c92f0dd9e 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -47,6 +47,73 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     return 0;
 }
 
+int x86_msr_copy_from_buffer(struct msr_policy *p,
+                             const msr_entry_buffer_t msrs, uint32_t nr_entries,
+                             uint32_t *err_msr)
+{
+    unsigned int i;
+    xen_msr_entry_t data;
+    int rc;
+
+    /*
+     * A well formed caller is expected to pass an array with entries in
+     * order, and without any repetitions.  However, due to per-vendor
+     * differences, and in the case of upgrade or levelled scenarios, we
+     * typically expect fewer than MAX entries to be passed.
+     *
+     * Detecting repeated entries is prohibitively complicated, so we don't
+     * bother.  That said, one way or another if more than MAX entries are
+     * passed, something is wrong.
+     */
+    if ( nr_entries > MSR_MAX_SERIALISED_ENTRIES )
+        return -E2BIG;
+
+    for ( i = 0; i < nr_entries; i++ )
+    {
+        if ( copy_from_buffer_offset(&data, msrs, i, 1) )
+            return -EFAULT;
+
+        if ( data.flags ) /* .flags MBZ */
+        {
+            rc = -EINVAL;
+            goto err;
+        }
+
+        switch ( data.idx )
+        {
+            /*
+             * Assign data.val to p->field, checking for truncation if the
+             * backing storage for field is smaller than uint64_t
+             */
+#define ASSIGN(field)                             \
+({                                                \
+    if ( (typeof(p->field))data.val != data.val ) \
+    {                                             \
+        rc = -EOVERFLOW;                          \
+        goto err;                                 \
+    }                                             \
+    p->field = data.val;                          \
+})
+
+        case MSR_INTEL_PLATFORM_INFO: ASSIGN(plaform_info.raw); break;
+
+#undef ASSIGN
+
+        default:
+            rc = -ERANGE;
+            goto err;
+        }
+    }
+
+    return 0;
+
+ err:
+    if ( err_msr )
+        *err_msr = data.idx;
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h
index 3ee99aad62..e0ff2dae23 100644
--- a/xen/lib/x86/private.h
+++ b/xen/lib/x86/private.h
@@ -12,6 +12,7 @@
 #include <asm/msr-index.h>
 
 #define copy_to_buffer_offset copy_to_guest_offset
+#define copy_from_buffer_offset copy_from_guest_offset
 
 #else
 
@@ -44,6 +45,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)
     0;                                                  \
 })
 
+/* memcpy(), but with copy_from_guest_offset()'s API. */
+#define copy_from_buffer_offset(dst, src, index, nr)    \
+({                                                      \
+    const typeof(*(src)) *src_ = (src);                 \
+    typeof(*(dst)) *dst_ = (dst);                       \
+    typeof(index) index_ = (index);                     \
+    typeof(nr) nr_ = (nr), i_;                          \
+                                                        \
+    for ( i_ = 0; i_ < nr_; i_++ )                      \
+        dst_[i_] = src_[index_ + i_];                   \
+    0;                                                  \
+})
+
 #endif /* __XEN__ */
 
 #endif /* XEN_LIB_X86_PRIVATE_H */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGipj-0001u9-E0; Fri, 11 Sep 2020 13:11:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiph-0001tz-OY
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:17 +0000
X-Inumbo-ID: 93f40460-03db-4e62-83dd-f44e8a68ccce
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 93f40460-03db-4e62-83dd-f44e8a68ccce;
 Fri, 11 Sep 2020 13:11:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=syU+cL6KAPZkA4DK7SdsvY/5KtyDDhbo6nk2bovLodY=; b=QtvBHSEqfalxpCmv3qPdsxH3ld
 vlcf+zEEO2rgcW/wgPQrp4UUOHs97fCugRsnvn7XQFPZ7sIP48ME0+4kMkoo0a2qldRud7Qjaj1nE
 J2C27VqJObI0FpaEPoll29SgUrrLlHg4xQihQK0vkOlRfmFJRhVbxwaPR1DyP74LZ8Gs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipg-0000gJ-U4
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipg-00069v-Sd
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kGipg-00069v-Sd@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e0bd8996b40066ffda685ea7c6f01aae6a86b984
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:57:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:57:38 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 44865a35ac..b4c6b90456 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2525,7 +2525,7 @@ void __init init_ioapic_mappings(void)
 
     if ( smp_found_config )
         nr_irqs_gsi = 0;
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         if ( smp_found_config )
         {
@@ -2548,7 +2548,6 @@ void __init init_ioapic_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGipu-0001vg-HC; Fri, 11 Sep 2020 13:11:30 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGipt-0001vW-9v
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:29 +0000
X-Inumbo-ID: 10ed8674-22ba-4648-8770-8ecb5be80644
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 10ed8674-22ba-4648-8770-8ecb5be80644;
 Fri, 11 Sep 2020 13:11:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ahvY+UBh05W//qJ+BR1jNnv+Kj0f31vr7f98J2apD3M=; b=Oqu9OI5wwlZJf3FwNNGfVEMHAM
 k4dSPRDOb6f/h/HFDBwIUafNf7uS7d7JUB62Wbaxo4f4R1GCOjyGO3KqvC8Dyy1PDWYm2/hAT9zRa
 GTSQ/L4XU+At2cqVyHAKboiPjpuF3R5mudi4jDPZsRNsWAVqneWWdgHr5BQzZQB/nAS0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipr-0000ij-2x
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGipr-0006Ay-0b
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86: use constant flags for section .init.rodata
Message-Id: <E1kGipr-0006Ay-0b@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5bd49ca50e7454834085bd7d63cc06295dedd1fb
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:58:19 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:58:19 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 94d9a51a17..f9d64cca84 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -917,7 +917,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -961,5 +961,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiq3-0001x4-Ip; Fri, 11 Sep 2020 13:11:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiq2-0001wx-3v
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:38 +0000
X-Inumbo-ID: ba6d8b1b-e495-4d17-b027-90fc05fb7039
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id ba6d8b1b-e495-4d17-b027-90fc05fb7039;
 Fri, 11 Sep 2020 13:11:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=drfIgqzBwnWFjrfigylMRfobQBWWEF6boZSsVtz0etw=; b=ceK4tZlDWIKPSqxTZ6phc1i3Zs
 j/OkNhmEoEM9RGZwCbo5giCYaVcaQvX3s68S31R3nEG5E2lEFBwyFNGuMPLCho/ycEfunADC06aPz
 uFTyjZE6mlnZ6olTWmArKRrCJh403/u60mADQ87zEiBxPssy2H6HwUPM4Y7oL0ZqVo6E=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiq1-0000it-6d
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiq1-0006C6-5e
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kGiq1-0006C6-5e@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8c1c3e7d2565f4d82ffb82b258ef68341028c0f4
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:58:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:58:57 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 1c18e10345..0579c6a396 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -181,8 +181,10 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index 31490a7c10..f26a8b52e1 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -250,7 +250,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*!  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
 #endif /* XEN_CPUFEATURE */
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 6236622adf..0e18e1221c 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } plaform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 7c92f0dd9e..a722571617 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->plaform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -96,6 +97,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(plaform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);    break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiqD-0001yA-KV; Fri, 11 Sep 2020 13:11:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiqC-0001xw-3b
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:48 +0000
X-Inumbo-ID: 80cc429b-ff8b-4125-98ae-90527da63255
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 80cc429b-ff8b-4125-98ae-90527da63255;
 Fri, 11 Sep 2020 13:11:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ty66BGLU2miWNB7Lp+nyf4sVbmw9zGMeqn6zj9G/gxQ=; b=UFGR5xULppRq/y3pEX6S01haVs
 z4RICMpRHCVSrEDtDixe/YSlVF+xqXRtCBcHdkPUci/hAg2PmBannR+vcRHzLF9f21qdsb702l0NZ
 cKcT8yp1ieRfJl7u/t7/I3SzzaeYX/VUSHULkoUud3vO5Abdvegxp7x42KSR0+JQAaZ4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqB-0000j1-A3
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqB-0006Cq-9D
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kGiqB-0006Cq-9D@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fbf016f2b289a762ac6cf46e6b9f8024794412cb
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:59:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:59:48 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 56072d4316..07f52e7130 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -634,6 +634,14 @@ int init_domain_cpuid_policy(struct domain *d)
 
     recalculate_cpuid_policy(d);
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     return 0;
 }
 
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 0579c6a396..4677222c40 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -95,6 +95,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( is_control_domain(d) )
         mp->plaform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:11:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:11:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiqM-0001zV-UA; Fri, 11 Sep 2020 13:11:58 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiqM-0001zN-9j
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:58 +0000
X-Inumbo-ID: dcc1b417-5862-4866-bdff-182870c25040
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id dcc1b417-5862-4866-bdff-182870c25040;
 Fri, 11 Sep 2020 13:11:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=4SQkLW7paumobp67gDkfj7ezkTDT8KQ1/LOnydeHRJk=; b=B2c3baQz93o9gRMkomn1yUgJH7
 xLTxOr3OMeNzUYnbrCHgEjS8nTnUoNbXis8tAIArs9/oF+2kd6uuUQH3tOymBqGitm8hnN7qOXb81
 C5XH/hIAIwLQUMmEXynhgzqdRkJg+2E7hFICrexSDL3N4D7KMNmEPDrbO1Tul9AdBuQc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqL-0000jF-Dg
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqL-0006DX-Cm
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:11:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kGiqL-0006DX-Cm@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:11:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 40e0cf810806bf331d3ff6c3990ffae4426e25c8
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:00:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:00:21 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 56 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 46 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index cda9fbba00..d6e3f4dfe7 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1054,17 +1054,53 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:12:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:12:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiqY-00021M-Vu; Fri, 11 Sep 2020 13:12:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiqY-000219-0c
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:10 +0000
X-Inumbo-ID: f64e6a78-fed3-4c02-8a4c-5faaab17b790
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f64e6a78-fed3-4c02-8a4c-5faaab17b790;
 Fri, 11 Sep 2020 13:12:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=JrpYINGb3/ta9Hk/V/kK7qtWHRR8GqhZ0HBGA/XGJSQ=; b=kY5Tl78DRGIRlFygYx1EAe5/Cu
 YHr4J/koqb7e3+wkERMMqXvWJZ6++Y7mq2blzfW9fj5p6q9+hImyESv30jvWruZEdQ1+UJGLrpabF
 Vlc5gxbqlgYvFmwSGxZ6wpRSnOihDU8d8iOBgw7qMHekY7bZRoYH5gvqchcSBaOHkwNw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqW-0000jd-Py
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqW-0006GB-Nb
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kGiqW-0006GB-Nb@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:12:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3186568505e38f498d0f2b068d33229f9c4ece60
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:00:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:00:59 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 19 +++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 6b0cb689a1..d528f8a63b 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1481,6 +1481,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1491,14 +1501,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 4b6f48dea2..079de1e15d 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -394,16 +394,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 
 void toggle_guest_mode(struct vcpu *v)
 {
+    unsigned long gs_base;
+
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 8f93b4e9df..5d4065333a 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -780,17 +780,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -839,15 +828,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -975,14 +962,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index d6e3f4dfe7..7246ee50ef 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1025,10 +1025,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1045,10 +1042,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 86d6e2b226..5afa1ef6e3 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -516,7 +516,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 13:12:21 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 13:12:21 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGiqj-000232-2k; Fri, 11 Sep 2020 13:12:21 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGiqi-00022u-JO
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:20 +0000
X-Inumbo-ID: 7b75d8be-37c6-4db4-a4d5-f9a36be69629
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7b75d8be-37c6-4db4-a4d5-f9a36be69629;
 Fri, 11 Sep 2020 13:12:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=4uBDyTUx/1i5C1kWo9ZWE/x9W5uqGj16TwWClANkYvE=; b=dfo/yX+O4dT02jxHvlRaBOgCr9
 ZU499UmEr9uy/dvGgjx2J4rh9xHaNXweRo76YNDTPjz+1+/xxuR230SaJMRP86LRfUtJCbrGQenqG
 HALbWF6P89AHoMiAin1KTagx/BKXk+3lw7/HkbAuOhFTmtn/gfqRf/NdZGEtyTgPXKmU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqg-0000kD-V5
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:18 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGiqg-0006Gv-Tv
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 13:12:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kGiqg-0006Gv-Tv@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 13:12:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ff79981ecb331864f89f1ce4c0cc17fe0e332070
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:01:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:01:58 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 188 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 138 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index d528f8a63b..019dc57459 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -945,13 +945,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1262,57 +1258,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD CPUs. Be on
- * the safe side and re-initialize both to flat segment values before loading
- * a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1320,62 +1319,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1494,7 +1456,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1511,35 +1472,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1745,8 +1677,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) &&
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index d74701718b..281260d181 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1590,8 +1590,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1628,14 +1627,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index 49dca39e0b..09fa179de2 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -56,10 +56,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 064b4aae70..b3095fabcb 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Fri Sep 11 17:22:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 11 Sep 2020 17:22:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGmkS-0000eX-Qq; Fri, 11 Sep 2020 17:22:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=dDsj=CU=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGmkQ-0000eS-VN
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 17:22:07 +0000
X-Inumbo-ID: 8a1500f0-4c77-42ba-b1ad-5324a32b3dde
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8a1500f0-4c77-42ba-b1ad-5324a32b3dde;
 Fri, 11 Sep 2020 17:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=3wksQ/719u3U4JnsxN8llRcOYKo8//vHLsAJUnbFkjM=; b=XWhIpnGgmKesL3Ke2H7Hc3Nm4G
 pTA4J4tfjxl9I8xasM0POE8nY/SlfGLFO1hbJMzOcML/REAzSAB5SZocayA+GJV41FIAS/xpTXvFI
 WxvdG5cPoZT1QlwlG/4ZsbY5Sbt6MpgyhDi8IVsdcMf5OhH0gT1JTdOslVvqtdkkhRUM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGmkP-0006Vj-Nk
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 17:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGmkP-0001jm-MT
 for xen-changelog@lists.xenproject.org; Fri, 11 Sep 2020 17:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/cpuid: Untangle Invariant TSC handling
Message-Id: <E1kGmkP-0001jm-MT@xenbits.xenproject.org>
Date: Fri, 11 Sep 2020 17:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6c5fb129e88b9c06b5fd62a410163ebb8ef77ee6
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Feb 24 17:15:22 2020 +0000
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Fri Sep 11 18:17:59 2020 +0100

    tools/cpuid: Untangle Invariant TSC handling
    
    ITSC being visible to the guest is currently implicit with the toolstack
    unconditionally asking for it, and Xen clipping it based on the vTSC and/or
    XEN_DOMCTL_disable_migrate settings.
    
    This is problematic for several reasons.
    
    First, the implicit vTSC behaviour manifests as a real bug on migration to a
    host with a different frequency, with ITSC but without TSC scaling
    capabilities, whereby the ITSC feature becomes advertised to the guest.  ITSC
    will disappear again if the guest migrates to server with the same frequency
    as the original, or to one with TSC scaling support.
    
    Secondly, disallowing ITSC unless the guest doesn't migrate is conceptually
    wrong.  It is common to have migration pools of identical hardware, at which
    point the TSC frequency is nominally the same, and more modern hardware has
    TSC scaling support anyway.  In both cases, it is safe to advertise ITSC and
    migrate the guest.
    
    Remove all implicit logic in Xen, and make ITSC part of the max CPUID policies
    for guests.  Plumb an itsc parameter into xc_cpuid_apply_policy() and have
    libxl__cpuid_legacy() fill in the two cases where it can reasonably expect
    ITSC to be safe for the guest to see.  This retains the current side effect of
    enabling ITSC if the guest is marked as nomigrate.
    
    This is a behaviour change for TSC_MODE_NATIVE, where the ITSC will now
    reliably not appear, and for the case where the user explicitly requests ITSC,
    in which case it will appear even if the guest isn't marked as nomigrate.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Ian Jackson <Ian.Jackson@citrix.com>
---
 tools/libs/ctrl/include/xenctrl.h           |  4 ++--
 tools/libs/guest/xg_cpuid_x86.c             | 12 ++++++------
 tools/libxl/libxl_cpuid.c                   | 19 ++++++++++++++++++-
 xen/arch/x86/cpuid.c                        |  8 --------
 xen/arch/x86/time.c                         |  2 --
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 6 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
index 4c89b7294c..0a921a95fa 100644
--- a/tools/libs/ctrl/include/xenctrl.h
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -1828,14 +1828,14 @@ struct xc_xend_cpuid {
  * cases, and the generated policy must be compatible with a 4.13.
  *
  * Either pass a full new @featureset (and @nr_features), or adjust individual
- * features (@pae).
+ * features (@pae, @itsc).
  *
  * Then (optionally) apply legacy XEND overrides (@xend) to the result.
  */
 int xc_cpuid_apply_policy(xc_interface *xch,
                           uint32_t domid, bool restore,
                           const uint32_t *featureset,
-                          unsigned int nr_features, bool pae,
+                          unsigned int nr_features, bool pae, bool itsc,
                           const struct xc_xend_cpuid *xend);
 int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
 int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 0f24d6dd08..dc50106975 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -427,7 +427,7 @@ static int xc_cpuid_xend_policy(
 
 int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
                           const uint32_t *featureset, unsigned int nr_features,
-                          bool pae,
+                          bool pae, bool itsc,
                           const struct xc_xend_cpuid *xend)
 {
     int rc;
@@ -556,6 +556,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
     }
     else
     {
+        p->extd.itsc = itsc;
+
         if ( di.hvm )
             p->basic.pae = pae;
     }
@@ -625,12 +627,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         }
 
         /*
-         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
-         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
-         * CPUID.  Xen will discard these bits if configuration hasn't been
-         * set for the domain.
+         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM
+         * to be reflected correctly in CPUID.  Xen will discard these bits if
+         * configuration hasn't been set for the domain.
          */
-        p->extd.itsc = true;
         p->basic.vmx = true;
         p->extd.svm = true;
     }
diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c
index 8b570b7e27..f54eb83a90 100644
--- a/tools/libxl/libxl_cpuid.c
+++ b/tools/libxl/libxl_cpuid.c
@@ -421,6 +421,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
                          libxl_domain_build_info *info)
 {
     bool pae = true;
+    bool itsc;
 
     /*
      * For PV guests, PAE is Xen-controlled (it is the 'p' that differentiates
@@ -435,7 +436,23 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
     if (info->type == LIBXL_DOMAIN_TYPE_HVM)
         pae = libxl_defbool_val(info->u.hvm.pae);
 
-    xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, pae, info->cpuid);
+    /*
+     * Advertising Invariant TSC to a guest means that the TSC frequency won't
+     * change at any point in the future.
+     *
+     * We do not have enough information about potential migration
+     * destinations to know whether advertising ITSC is safe, but if the guest
+     * isn't going to migrate, then the current hardware is all that matters.
+     *
+     * Alternatively, an internal property of vTSC is that the values read are
+     * invariant.  Advertise ITSC when we know the domain will have emualted
+     * TSC everywhere it goes.
+     */
+    itsc = (libxl_defbool_val(info->disable_migrate) ||
+            info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE);
+
+    xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0,
+                          pae, itsc, info->cpuid);
 }
 
 static const char *input_names[2] = { "leaf", "subleaf" };
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 4b424fac95..23425790e1 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -620,14 +620,6 @@ void recalculate_cpuid_policy(struct domain *d)
             __clear_bit(X86_FEATURE_SYSCALL, max_fs);
     }
 
-    /*
-     * ITSC is masked by default (so domains are safe to migrate), but a
-     * toolstack which has configured disable_migrate or vTSC for a domain may
-     * safely select it, and needs a way of doing so.
-     */
-    if ( cpu_has_itsc && (d->disable_migrate || d->arch.vtsc) )
-        __set_bit(X86_FEATURE_ITSC, max_fs);
-
     /*
      * On hardware with MSR_TSX_CTRL, the admin may have elected to disable
      * TSX and hide the feature bits.  Migrating-in VMs may have been booted
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 505e54ebd7..8938c0f435 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2448,8 +2448,6 @@ int tsc_set_info(struct domain *d,
         }
     }
 
-    recalculate_cpuid_policy(d);
-
     return 0;
 }
 
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index fc733e64f6..abd18722ee 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -246,7 +246,7 @@ XEN_CPUFEATURE(MOVDIR64B,     6*32+28) /*a  MOVDIR64B instruction */
 XEN_CPUFEATURE(ENQCMD,        6*32+29) /*   ENQCMD{,S} instructions */
 
 /* AMD-defined CPU features, CPUID level 0x80000007.edx, word 7 */
-XEN_CPUFEATURE(ITSC,          7*32+ 8) /*   Invariant TSC */
+XEN_CPUFEATURE(ITSC,          7*32+ 8) /*a  Invariant TSC */
 XEN_CPUFEATURE(EFRO,          7*32+10) /*   APERF/MPERF Read Only interface */
 
 /* AMD-defined CPU features, CPUID level 0x80000008.ebx, word 8 */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGya0-0003tm-8s; Sat, 12 Sep 2020 06:00:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyZz-0003th-4B
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:07 +0000
X-Inumbo-ID: d008e82d-5531-4377-b088-3836de1e8867
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d008e82d-5531-4377-b088-3836de1e8867;
 Sat, 12 Sep 2020 06:00:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=a7vBMU6gO6xLHm8C2F5xlTbouG9C8YORHySwbybLG10=; b=rNb0eqlTYXTbvBbC9aZALLXwXF
 6eyBAovUyPjkCAEQxF8tFsdQzohTC5hOop4Ve6mpP1PCb3ryqP6wt1GAjjJYz1SjqtcCJx7Kn3wUN
 u3cIdnRyy9IFd2aFu+7HCILDMksUYRz9Y77lWVjhPDjCgVgNHSsEmXKXBPBe45FIacpM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyZu-0003ai-RY
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyZu-0008B2-P9
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] libx86: introduce a helper to deserialise
 msr_policy objects
Message-Id: <E1kGyZu-0008B2-P9@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c481b9f32da5af232edaf0feff0bf213fa23e0ba
Author:     Sergey Dyasli <sergey.dyasli@citrix.com>
AuthorDate: Fri Sep 11 14:56:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:56:34 2020 +0200

    libx86: introduce a helper to deserialise msr_policy objects
    
    As with the serialise side, Xen's copy_from_guest API is used, with a
    compatibility wrapper for the userspace build.
    
    Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Wei Liu <wei.liu2@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afec08b92ffe8b85d2bf2e8c7c221b63ba96743e
    master date: 2019-03-12 14:12:23 +0000
---
 xen/include/xen/lib/x86/msr.h | 21 ++++++++++++++
 xen/lib/x86/msr.c             | 67 +++++++++++++++++++++++++++++++++++++++++++
 xen/lib/x86/private.h         | 14 +++++++++
 3 files changed, 102 insertions(+)

diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index e2cfbb1a8d..6236622adf 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -48,6 +48,27 @@ typedef xen_msr_entry_t msr_entry_buffer_t[];
 int x86_msr_copy_to_buffer(const struct msr_policy *policy,
                            msr_entry_buffer_t msrs, uint32_t *nr_entries);
 
+/**
+ * Unserialise an msr_policy object from an array of msrs.
+ *
+ * @param policy     The msr_policy object to unserialise into.
+ * @param msrs       The array of msrs to unserialise from.
+ * @param nr_entries The number of entries in 'msrs'.
+ * @param err_msr    Optional hint filled on error.
+ * @returns -errno
+ *
+ * Reads at most MSR_MAX_SERIALISED_ENTRIES.  May fail for a number of reasons
+ * based on the content in an individual 'msrs' entry, including the MSR index
+ * not being valid in the policy, the flags field being nonzero, or if the
+ * value provided would truncate when stored in the policy.  In such cases,
+ * the optional err_* pointer is filled in to aid diagnostics.
+ *
+ * No content validation is performed on the data stored in the policy object.
+ */
+int x86_msr_copy_from_buffer(struct msr_policy *policy,
+                             const msr_entry_buffer_t msrs, uint32_t nr_entries,
+                             uint32_t *err_msr);
+
 #endif /* !XEN_LIB_X86_MSR_H */
 
 /*
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 60fb567687..7c92f0dd9e 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -47,6 +47,73 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     return 0;
 }
 
+int x86_msr_copy_from_buffer(struct msr_policy *p,
+                             const msr_entry_buffer_t msrs, uint32_t nr_entries,
+                             uint32_t *err_msr)
+{
+    unsigned int i;
+    xen_msr_entry_t data;
+    int rc;
+
+    /*
+     * A well formed caller is expected to pass an array with entries in
+     * order, and without any repetitions.  However, due to per-vendor
+     * differences, and in the case of upgrade or levelled scenarios, we
+     * typically expect fewer than MAX entries to be passed.
+     *
+     * Detecting repeated entries is prohibitively complicated, so we don't
+     * bother.  That said, one way or another if more than MAX entries are
+     * passed, something is wrong.
+     */
+    if ( nr_entries > MSR_MAX_SERIALISED_ENTRIES )
+        return -E2BIG;
+
+    for ( i = 0; i < nr_entries; i++ )
+    {
+        if ( copy_from_buffer_offset(&data, msrs, i, 1) )
+            return -EFAULT;
+
+        if ( data.flags ) /* .flags MBZ */
+        {
+            rc = -EINVAL;
+            goto err;
+        }
+
+        switch ( data.idx )
+        {
+            /*
+             * Assign data.val to p->field, checking for truncation if the
+             * backing storage for field is smaller than uint64_t
+             */
+#define ASSIGN(field)                             \
+({                                                \
+    if ( (typeof(p->field))data.val != data.val ) \
+    {                                             \
+        rc = -EOVERFLOW;                          \
+        goto err;                                 \
+    }                                             \
+    p->field = data.val;                          \
+})
+
+        case MSR_INTEL_PLATFORM_INFO: ASSIGN(plaform_info.raw); break;
+
+#undef ASSIGN
+
+        default:
+            rc = -ERANGE;
+            goto err;
+        }
+    }
+
+    return 0;
+
+ err:
+    if ( err_msr )
+        *err_msr = data.idx;
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h
index 3ee99aad62..e0ff2dae23 100644
--- a/xen/lib/x86/private.h
+++ b/xen/lib/x86/private.h
@@ -12,6 +12,7 @@
 #include <asm/msr-index.h>
 
 #define copy_to_buffer_offset copy_to_guest_offset
+#define copy_from_buffer_offset copy_from_guest_offset
 
 #else
 
@@ -44,6 +45,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)
     0;                                                  \
 })
 
+/* memcpy(), but with copy_from_guest_offset()'s API. */
+#define copy_from_buffer_offset(dst, src, index, nr)    \
+({                                                      \
+    const typeof(*(src)) *src_ = (src);                 \
+    typeof(*(dst)) *dst_ = (dst);                       \
+    typeof(index) index_ = (index);                     \
+    typeof(nr) nr_ = (nr), i_;                          \
+                                                        \
+    for ( i_ = 0; i_ < nr_; i_++ )                      \
+        dst_[i_] = src_[index_ + i_];                   \
+    0;                                                  \
+})
+
 #endif /* __XEN__ */
 
 #endif /* XEN_LIB_X86_PRIVATE_H */
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGya7-0003uB-C7; Sat, 12 Sep 2020 06:00:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGya6-0003u6-4v
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:14 +0000
X-Inumbo-ID: 9af6b619-e748-4e15-9e40-42573ac442ee
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9af6b619-e748-4e15-9e40-42573ac442ee;
 Sat, 12 Sep 2020 06:00:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=YEVmWtBQlLOKYpzjYluJ5BmF9UkVa3cUq6MZ95dMhcA=; b=HQv+Mrlk+g1fVkUrSTJsrqeHVg
 cmB5M3PUafMSXUaQx2Fg20PYSnzbrwaRRWTaTRKt2oiKYoqNZ04XRtEUoybEB93SE4BAOkrrz2z49
 kOr/ePCnQ7nJM//581QVnNY28RNzohFejgLZluZjlSOyJyo353wEHmFupkCjnxLE6t5w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGya5-0003ar-0W
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGya4-0008Cq-US
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kGya4-0008Cq-US@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e0bd8996b40066ffda685ea7c6f01aae6a86b984
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:57:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:57:38 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 44865a35ac..b4c6b90456 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2525,7 +2525,7 @@ void __init init_ioapic_mappings(void)
 
     if ( smp_found_config )
         nr_irqs_gsi = 0;
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         if ( smp_found_config )
         {
@@ -2548,7 +2548,6 @@ void __init init_ioapic_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyaH-0003vG-Dv; Sat, 12 Sep 2020 06:00:25 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyaF-0003v2-W0
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:24 +0000
X-Inumbo-ID: 82f34e2f-babe-4d43-9360-f84b31b4ca96
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 82f34e2f-babe-4d43-9360-f84b31b4ca96;
 Sat, 12 Sep 2020 06:00:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ya5yJan+35KcCqnjfBj4ANPMo71+B6uA4v+BGQRA6vs=; b=fsUObVFs/j+uTVeiNRngV356He
 Via4f7fe9I5XGjgezbeDZ7y3hpkjg5TyMehgaryoHjTJTsLgBVbo9leVJ6iNIkpdb/HCL2zBuh6RA
 oLOwZuHfzx/sngkbhCdS4K7yjVZGxtnHl0XdL/k1DVuz2vmEQmve6sXeeLi14Slu6Y/s=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaF-0003ay-5U
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaF-0008DQ-3J
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86: use constant flags for section .init.rodata
Message-Id: <E1kGyaF-0008DQ-3J@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5bd49ca50e7454834085bd7d63cc06295dedd1fb
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:58:19 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:58:19 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 94d9a51a17..f9d64cca84 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -917,7 +917,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -961,5 +961,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyaR-0003wh-FP; Sat, 12 Sep 2020 06:00:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyaQ-0003wS-9N
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:34 +0000
X-Inumbo-ID: 741a4a6c-756c-444d-922a-173c4694a7d2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 741a4a6c-756c-444d-922a-173c4694a7d2;
 Sat, 12 Sep 2020 06:00:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GAkOlos1qk+ejDH9FO9VwPQglRy2hYphwSkUkasky30=; b=6TzBXq0/RCsg2LCjDcAvUYurh7
 5cTs8HQOGbBnwSGU50jj5FdKSPPF9wDMgcox7qXnC9woeWH20jLAHgsJ2gpTlAOdzM20QP/HJOJ5G
 r7JQyhvW16OiCKgqJ1xG8JmJEwKgBhu5leH4V47HcZwXnPxD2LstXv22qjZnd5mZBLbo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaP-0003bB-92
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaP-0008Dw-86
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kGyaP-0008Dw-86@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8c1c3e7d2565f4d82ffb82b258ef68341028c0f4
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:58:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:58:57 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 1c18e10345..0579c6a396 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -181,8 +181,10 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index 31490a7c10..f26a8b52e1 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -250,7 +250,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*!  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
 #endif /* XEN_CPUFEATURE */
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 6236622adf..0e18e1221c 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } plaform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 7c92f0dd9e..a722571617 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->plaform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -96,6 +97,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(plaform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);    break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:46 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyac-0003y0-HG; Sat, 12 Sep 2020 06:00:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyab-0003xl-K8
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:45 +0000
X-Inumbo-ID: c9223400-61d5-464a-840d-5a01f7500000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c9223400-61d5-464a-840d-5a01f7500000;
 Sat, 12 Sep 2020 06:00:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=vXir9FYxnyrZiXgaU86VSDtbwBEZjMDIjNXp5ydreeA=; b=sh9xsnzb1e9OacF8hEb4nhZcuf
 KybE4yqEfXKvCKw7IzAtK/u9l5RRqm/MpQSM7KmIcPWgU+T6p6L4M7JRVH6TuIXJZPsuONEMyMzhF
 J8lgWX7bM1YcYPBBN+zaXYulInkXiHUNDme0O9E9f8sPSrQDYULgo2mt9VmL5ueJ2mfU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaa-0003bR-76
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:44 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyaZ-0008Ea-Bn
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kGyaZ-0008Ea-Bn@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fbf016f2b289a762ac6cf46e6b9f8024794412cb
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:59:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:59:48 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 56072d4316..07f52e7130 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -634,6 +634,14 @@ int init_domain_cpuid_policy(struct domain *d)
 
     recalculate_cpuid_policy(d);
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     return 0;
 }
 
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 0579c6a396..4677222c40 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -95,6 +95,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( is_control_domain(d) )
         mp->plaform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:00:55 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:00:55 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyal-0003zZ-SU; Sat, 12 Sep 2020 06:00:55 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyal-0003zS-EQ
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:55 +0000
X-Inumbo-ID: 494b7ce3-d779-44b4-826b-f7c1b7c2f3c7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 494b7ce3-d779-44b4-826b-f7c1b7c2f3c7;
 Sat, 12 Sep 2020 06:00:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hNSuI3ILfY43s3G2qASDU51FeXmn6XncAfyD70DkxOk=; b=OF269cJQFptkWm1WDXe578t86a
 boF4MOkmGthKZlTuObDX76YvnKC/AfOMPI04lrvGwmWoY4kRbV8064y8EAB9echoADbFoRN/XmvlQ
 wc6YyokR67YEOIAMGrIwz8ULhE7z1ZuQNmgsa83aBwjkXkD9iLGPDiZzGZC7zcclbqps=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyak-0003cB-Gc
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:54 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyak-0008FS-9r
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:00:54 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kGyak-0008FS-9r@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:00:54 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 40e0cf810806bf331d3ff6c3990ffae4426e25c8
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:00:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:00:21 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 56 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 46 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index cda9fbba00..d6e3f4dfe7 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1054,17 +1054,53 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:01:06 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:01:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyaw-00041e-U8; Sat, 12 Sep 2020 06:01:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyav-00041U-U5
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:05 +0000
X-Inumbo-ID: 4fb9335d-17cd-460b-83d8-8b2d730dabcc
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4fb9335d-17cd-460b-83d8-8b2d730dabcc;
 Sat, 12 Sep 2020 06:01:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=5x8EoHoQDITYfDqABkuRPzBOIRA/eQy4yR0Qcc3hWEE=; b=zQtlJkohuBxbyWBA8ocHjhgWNk
 4vuZPbLqtyhukWVomYjqp7V9By4SgLcIa8MQUJRFCGIWTAvvPJx7Y+o+JTjwSgNK/rjvQyTxMV1xQ
 kkM3IEl40MQex/HM20dVQsbErE7NSbpbvm8+3K9tiul8gdXth26SQHqplXNrdiEkluvU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyau-0003cY-LX
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyau-0008GO-Jn
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kGyau-0008GO-Jn@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:01:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3186568505e38f498d0f2b068d33229f9c4ece60
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:00:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:00:59 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 19 +++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 6b0cb689a1..d528f8a63b 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1481,6 +1481,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1491,14 +1501,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 4b6f48dea2..079de1e15d 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -394,16 +394,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 
 void toggle_guest_mode(struct vcpu *v)
 {
+    unsigned long gs_base;
+
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 8f93b4e9df..5d4065333a 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -780,17 +780,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -839,15 +828,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -975,14 +962,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index d6e3f4dfe7..7246ee50ef 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1025,10 +1025,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1045,10 +1042,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 86d6e2b226..5afa1ef6e3 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -516,7 +516,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sat Sep 12 06:01:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sat, 12 Sep 2020 06:01:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kGyb7-00043J-1d; Sat, 12 Sep 2020 06:01:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=i35g=CV=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kGyb6-00043C-Fk
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:16 +0000
X-Inumbo-ID: 5de87f76-a52d-4bff-86e6-f24765ac40f7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5de87f76-a52d-4bff-86e6-f24765ac40f7;
 Sat, 12 Sep 2020 06:01:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6s9eemis7TON+NwiD+W0l8jsSyzi8YcxDovnbLvRzTk=; b=Z5rKh58zxIXyzTkzYYGg03VocO
 r318XOS4bZvOWpENIneUUzRBFiNZorKNErvYxCFnFqVaK7T0pVxA3wFQLDeYfe/XXJWqNEVIdoxId
 qVm34rAlwzhxB0KP4OHu7y22+ukhmQshYE5oP3Pn7/l3dPzPHgXqi3GU76ZMAFwFWhm4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyb4-0003cm-PZ
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kGyb4-0008HC-OX
 for xen-changelog@lists.xenproject.org; Sat, 12 Sep 2020 06:01:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kGyb4-0008HC-OX@xenbits.xenproject.org>
Date: Sat, 12 Sep 2020 06:01:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ff79981ecb331864f89f1ce4c0cc17fe0e332070
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 15:01:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 15:01:58 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 188 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 138 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index d528f8a63b..019dc57459 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -945,13 +945,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1262,57 +1258,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD CPUs. Be on
- * the safe side and re-initialize both to flat segment values before loading
- * a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1320,62 +1319,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1494,7 +1456,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1511,35 +1472,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1745,8 +1677,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) &&
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index d74701718b..281260d181 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1590,8 +1590,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1628,14 +1627,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index 49dca39e0b..09fa179de2 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -56,10 +56,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 064b4aae70..b3095fabcb 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:33:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:33:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGt7-0000Q9-EB; Sun, 13 Sep 2020 01:33:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGt5-0000Q4-TI
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:03 +0000
X-Inumbo-ID: ae7cea28-f64b-4012-b8ae-c7954805ffaa
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id ae7cea28-f64b-4012-b8ae-c7954805ffaa;
 Sun, 13 Sep 2020 01:33:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GFY6qj62jrRfR3CgEfEzcqJl8w9tkur0ZWi101ld6/0=; b=DZ0qa99BHN5Kl9E4ejG472yqd1
 UGcYOTTEZAQnBOKGcTPErugbqLJy6GmlPr4vrZy6+jP3dRcxOFSnx5eeMXENY6yyA5/aYgl/bxjNJ
 Ixi7sJhuuQ+sAc3XNM0XcU7mFAKaFmcV5cigI4h5Bq73KF99VkQxVNG74d7gbzFdg+2Q=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGt4-00017h-Gt
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGt4-0005LX-Fo
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kHGt4-0005LX-Fo@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit eca6d5e914ddc134b3c4d2697e40002182eb6c06
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:06:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:06:48 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 878ee5192d..e66fa99ec7 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2543,7 +2543,7 @@ static void __init ioapic_init_mappings(void)
 
     nr_irqs_gsi = 0;
 
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         union IO_APIC_reg_01 reg_01;
         paddr_t ioapic_phys = mp_ioapics[i].mpc_apicaddr;
@@ -2560,7 +2560,6 @@ static void __init ioapic_init_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:33:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:33:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGtG-0000Qi-Fl; Sun, 13 Sep 2020 01:33:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGtF-0000Qb-HC
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:13 +0000
X-Inumbo-ID: 575c3c10-1d9a-42ea-9b9a-f1f791b91829
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 575c3c10-1d9a-42ea-9b9a-f1f791b91829;
 Sun, 13 Sep 2020 01:33:12 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=zGm3OmEjz5wMwQj7CAIeJxh5Kbx8KWeGBTnWVwau5kA=; b=3bVgUV7dGBZ7VxgZkBSOtkPc0u
 Knh8ADKl5CMGjmMMgXqUqfz5lY46l529qG3BrDhjWPc3CcGXUCWUg1TnDXiFhF3gfashVXI/YmwUG
 Dj4NYJpFOrI9dJBvdudF6axiVYkILFIAkAOdOSCu4zNXdnqq+NppwV5zqX4ECpkaroTU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtE-00017q-Kg
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:12 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtE-0005M8-JX
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/tsc: Fix diagnostics for TSC frequency
Message-Id: <E1kHGtE-0005M8-JX@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit edf5b8627fc8568d14bffef400a9753bf7ce5766
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:07:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:07:34 2020 +0200

    x86/tsc: Fix diagnostics for TSC frequency
    
    A Gemini Lake platform prints:
    
      (XEN) CPU0: TSC: 19200000MHz * 279 / 3 = 1785600000MHz
      (XEN) CPU0: 800..1800 MHz
    
    during boot.  The units on the first line are Hz, not MHz, so correct that and
    add a space for clarity.
    
    Also, for the min/max line, use three dots instead of two and add more spaces
    so that the line can't be mistaken for being a double decimal point typo.
    
    Boot now reads:
    
      (XEN) CPU0: TSC: 19200000 Hz * 279 / 3 = 1785600000 Hz
      (XEN) CPU0: 800 ... 1800 MHz
    
    Extend these changes to the other TSC diagnostics.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b2bc1e714462c6cc222e3bbc38d87b039b4fa405
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/cpu/amd.c   |  4 ++--
 xen/arch/x86/cpu/intel.c | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 0cc6853c42..8bc51bec10 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -624,10 +624,10 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 	if (idx && idx < h &&
 	    !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
 	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu (%lu..%lu) MHz\n",
+		printk("CPU%u: %lu (%lu ... %lu) MHz\n",
 		       smp_processor_id(), FREQ(val), FREQ(lo), FREQ(hi));
 	else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu..%lu MHz\n",
+		printk("CPU%u: %lu ... %lu MHz\n",
 		       smp_processor_id(), FREQ(lo), FREQ(hi));
 	else
 		printk("CPU%u: %lu MHz\n", smp_processor_id(), FREQ(lo));
diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c
index 69e99bb358..37439071d9 100644
--- a/xen/arch/x86/cpu/intel.c
+++ b/xen/arch/x86/cpu/intel.c
@@ -396,14 +396,14 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
 
             val *= ebx;
             do_div(val, eax);
-            printk("CPU%u: TSC: %uMHz * %u / %u = %LuMHz\n",
+            printk("CPU%u: TSC: %u Hz * %u / %u = %Lu Hz\n",
                    smp_processor_id(), ecx, ebx, eax, val);
         }
         else if ( ecx | eax | ebx )
         {
             printk("CPU%u: TSC:", smp_processor_id());
             if ( ecx )
-                printk(" core: %uMHz", ecx);
+                printk(" core: %u Hz", ecx);
             if ( ebx && eax )
                 printk(" ratio: %u / %u", ebx, eax);
             printk("\n");
@@ -417,11 +417,11 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
         {
             printk("CPU%u:", smp_processor_id());
             if ( ecx )
-                printk(" bus: %uMHz", ecx);
+                printk(" bus: %u MHz", ecx);
             if ( eax )
-                printk(" base: %uMHz", eax);
+                printk(" base: %u MHz", eax);
             if ( ebx )
-                printk(" max: %uMHz", ebx);
+                printk(" max: %u MHz", ebx);
             printk("\n");
         }
     }
@@ -446,7 +446,7 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
 
         printk("CPU%u: ", smp_processor_id());
         if ( min_ratio )
-            printk("%u..", (factor * min_ratio + 50) / 100);
+            printk("%u ... ", (factor * min_ratio + 50) / 100);
         printk("%u MHz\n", (factor * max_ratio + 50) / 100);
     }
 }
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:33:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:33:26 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGtS-0000S0-HY; Sun, 13 Sep 2020 01:33:26 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGtR-0000Rp-Aa
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:25 +0000
X-Inumbo-ID: c347d19a-df80-4413-927a-92250d6fbc61
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c347d19a-df80-4413-927a-92250d6fbc61;
 Sun, 13 Sep 2020 01:33:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=NErCfbS43/c6iqs944JEbIlU4vMMN4DnCSVnC5oB7dQ=; b=AjiTq0jWd/j0Wm7bIsSSYSsc9U
 xPUkV1VEq1fN3Dhnx4m7y/fAbNF6RxBPu3u6bTLD1NY7zOcWMqG1rCnzH0Da1irztbGSjb+89/ENv
 4wadUfo/N+ZoIMo114axB95WKbr3UjlAZiFObkkzVWzodYQBAbOVf6eublU5Fpx2MmoY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtO-00018Q-OJ
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:22 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtO-0005Me-N7
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:22 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] build: work around bash issue
Message-Id: <E1kHGtO-0005Me-N7@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:22 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5482c2887d89bf742fd982b8c47510617a5096ef
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:08:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:08:09 2020 +0200

    build: work around bash issue
    
    Older bash (observed with 3.2.57(2)) fails to honor "set -e" for certain
    built-in commands ("while" here), despite the command's status correctly
    being non-zero. The subsequent objcopy invocation now being separated by
    a semicolon results in no failure. Insert an explicit "exit" (replacing
    ; by && ought to be another possible workaround).
    
    Fixes: e321576f4047 ("xen/build: start using if_changed")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    master commit: 5132a0a37190b73c99dbbecf48dc4fb214feaf14
    master date: 2020-08-07 13:12:00 +0200
---
 xen/Rules.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/Rules.mk b/xen/Rules.mk
index ebfd40caff..62e9fabe7a 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -193,7 +193,7 @@ define cmd_obj_init_o
             echo "Error: size of $<:$$name is 0x$$sz" >&2; \
             exit $$(expr $$idx + 1);; \
         esac; \
-    done; \
+    done || exit $$?; \
     $(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
 endef
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:33:34 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:33:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGta-0000Tf-JB; Sun, 13 Sep 2020 01:33:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGtZ-0000TX-N7
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:33 +0000
X-Inumbo-ID: d05e8fe5-8d47-4f4d-a41a-e0e704af4c85
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d05e8fe5-8d47-4f4d-a41a-e0e704af4c85;
 Sun, 13 Sep 2020 01:33:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Kgd/K3ytQ+Ca1VPt+jF2I3ujuBG6gr7dSGZKWKWaOqI=; b=uGhDmBP24+6o8nsfUv+yFqyTSP
 r3bjhkzCGFF1OYvKJTnymT3w4F093vkY/AriR3tl9I+le5XruSK9Ka9WzL5hOP3QWkqO+EsLWNB7y
 z+tfnBr88y1tiZQiHEW+OxZZbMcuE3B/ePa0TmQFzHUoTrDW4ZTzl9Q7943DICATxs08=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtY-00018X-Rk
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:32 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtY-0005NA-Qs
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:32 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86: use constant flags for section .init.rodata
Message-Id: <E1kHGtY-0005NA-Qs@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:32 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 80dec06f6a5f4e56ef1f26087282402c21708ebf
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:08:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:08:37 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 8b57a00040..1e880eb9f6 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -967,7 +967,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -1012,5 +1012,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:33:55 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:33:55 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGtv-0000Ut-LV; Sun, 13 Sep 2020 01:33:55 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGtu-0000Uo-41
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:54 +0000
X-Inumbo-ID: 0a451224-0988-4c31-9d45-f72bbbf481be
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 0a451224-0988-4c31-9d45-f72bbbf481be;
 Sun, 13 Sep 2020 01:33:53 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rwGlmznxyrLdAjShr6QZDjpbD3gTGCIXi3L8fljHIFY=; b=4lkWMENtmkMjjor+pAnaHIvJSG
 brMgJcc0BG/KNXIyGJivvQUy1eQ1LVBd7RZpZMlsvO8X68KUQAiB6nqhnecNFwEsjsrKNv0Fnesxd
 zaTJv0IrbI+zqDsqQ0Qrb86sTW1OQ/IQ8wYgSKgtxeqh5VAM502KMKoVW2vED9kQkb0o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtt-00018l-5D
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:53 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtt-0005OT-3O
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:53 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kHGtt-0005OT-3O@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:53 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 369e7a35bf651ce46778ff5598428b31c78924b7
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:09:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:09:56 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 63a03ef1e5..4b424fac95 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -719,6 +719,14 @@ int init_domain_cpuid_policy(struct domain *d)
     if ( d->disable_migrate )
         p->extd.itsc = cpu_has_itsc;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     d->arch.cpuid = p;
 
     recalculate_cpuid_policy(d);
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 7d99c0e64c..d72ab0fa1f 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -130,6 +130,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
         mp->platform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:34:00 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:34:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGu0-0000Vh-NG; Sun, 13 Sep 2020 01:34:00 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGtz-0000Uo-2P
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:59 +0000
X-Inumbo-ID: debd8534-6cd1-46f4-81e8-a5c53a502bd2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id debd8534-6cd1-46f4-81e8-a5c53a502bd2;
 Sun, 13 Sep 2020 01:33:43 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=fnCX+7DiUrTeuFkZHHyLUvOiUX7Q8g+Us8Fzsg4mqG8=; b=WVp2Og7F9VDPNv1ML0n3QFUb7m
 GIg7Bclzm70LQJH3eNlh1rF/HE6dYYaRU9ukuU/Q928KjW4A/LVz5p9Waa00knlHVsSEM9ZQfw2Db
 kNsRzZnVoyYEUiL3Y3anez17M53OmdQbKpSW3W6zTjP3/JdXSZrAFISvlxym4nl/BIhI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGtj-00018e-0l
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGti-0005Nl-Uc
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:33:42 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kHGti-0005Nl-Uc@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:33:42 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 98aa6ea75152115297ad26aed6c1c5f8d202bdba
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:09:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:09:10 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 tools/tests/cpu-policy/test-cpu-policy.c    |  5 +++++
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index 7ba9707236..0fa209f1ea 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -374,6 +374,11 @@ static void test_msr_deserialise_failure(void)
             .msr = { .idx = 0xce, .val = ~0ull },
             .rc = -EOVERFLOW,
         },
+        {
+            .name = "truncated val",
+            .msr = { .idx = 0x10a, .val = ~0ull },
+            .rc = -EOVERFLOW,
+        },
     };
 
     printf("Testing MSR deserialise failure:\n");
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 22f921cc71..7d99c0e64c 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -220,8 +220,10 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index fe7492a225..d06a2fd4c8 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -267,7 +267,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*a  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(CORE_CAPS,     9*32+30) /*   IA32_CORE_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 203c713320..48ba4a59c0 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } platform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 171abf7008..7d71e92a38 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -99,6 +100,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);     break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:34:05 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:34:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGu5-0000Wo-RC; Sun, 13 Sep 2020 01:34:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGu4-0000WZ-4z
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:04 +0000
X-Inumbo-ID: 7b4020d0-350d-4901-a6a8-3f8dab70a051
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7b4020d0-350d-4901-a6a8-3f8dab70a051;
 Sun, 13 Sep 2020 01:34:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hcwsUFO2z8rObu6n0VR8YAOJdaG1Hsk7jrI0KbjR/Po=; b=s9A+mDaP/03bZuvJWwIWbdY0sy
 yljyg58GWXmQfBEX2/9NGqjiFHtEFkxXBfRvDpq7/VxAzHxkwU5EkjqH1ZjpSjjsbxHASpPeMQxL/
 oLcxJZAU6WgOYwYVST8qWZFMUMOh27YwSeaNCZpEUJNQq0+dgpcJJeERLQkkIa1CNLsQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGu3-000191-8z
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:03 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGu3-0005PK-83
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:03 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kHGu3-0005PK-83@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:34:03 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ceafff707c96ca5cf01a435e4cf6f64c2dfc9a4d
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:10:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:10:26 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 102079a801..3b726f7c00 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1031,17 +1031,54 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:34:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:34:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGuF-0000Y4-TG; Sun, 13 Sep 2020 01:34:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGuE-0000Xv-Jm
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:14 +0000
X-Inumbo-ID: 23d9fdd9-a1ce-4e99-b0ab-b2fca8c4a89e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 23d9fdd9-a1ce-4e99-b0ab-b2fca8c4a89e;
 Sun, 13 Sep 2020 01:34:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=uMCUKCXX9YLNbrz0UHiWWmay9YPx27RxoGLjBxVIFa8=; b=qAJS0X66H9q2T1U5G547XZXZSC
 QvMIKkuP/apxm7qjXCB+HzKes2AogJl9PsDcEd85lDEB7F4ue14YeJdx98jge+U+Zhi3yu+Jf4LfN
 kgt6POfOoZTZqz+o4OlqnVe2T12+LsRzDPhNYgi1c6ZdI39GzTfq2e13oxhTloRHSxvQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGuD-00019J-DF
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGuD-0005Pq-CJ
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:13 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kHGuD-0005Pq-CJ@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:34:13 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 431d52afd9438a3a126dfd787bd2d69b76906cb5
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:10:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:10:57 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 18 ++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index fee6c3931a..8351391cdd 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1562,6 +1562,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1572,14 +1582,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index ec5a7d2dca..44e4ea2582 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -444,17 +444,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 void toggle_guest_mode(struct vcpu *v)
 {
     const struct domain *d = v->domain;
+    unsigned long gs_base;
 
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 254da2b849..7c21076dd0 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -801,17 +801,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -860,15 +849,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -997,14 +984,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 3b726f7c00..48fd60a876 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1002,10 +1002,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1022,10 +1019,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 6fd94c2e14..40385f5eaa 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -516,7 +516,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Sun Sep 13 01:34:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 13 Sep 2020 01:34:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHGuQ-0000Z5-V9; Sun, 13 Sep 2020 01:34:26 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=4qU1=CW=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHGuP-0000Ys-90
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:25 +0000
X-Inumbo-ID: 194eb60b-f17e-4049-888b-880fffe02ba7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 194eb60b-f17e-4049-888b-880fffe02ba7;
 Sun, 13 Sep 2020 01:34:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DcrukqBSTbHqgoh/CoNIv+NCZa6ldVv83ppZzkTG3bw=; b=4XeosUl40/it4nlhy6kL+QS7IR
 E4hxseqJMnzPcc2TiB2Cp0xxfXW2CtPpdoypnMuY9u/GAcz+ln8IxZ4SZPaj9J9b5+f4YZRwZHk1p
 CeGrBg4vnkgd0pjUkHeV5L6YNw8+bKoYo7++PUXhzw6G1i0pF+4VpP02PEfZa0sHww08=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGuN-0001A5-L4
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHGuN-0005QQ-Gh
 for xen-changelog@lists.xenproject.org; Sun, 13 Sep 2020 01:34:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kHGuN-0005QQ-Gh@xenbits.xenproject.org>
Date: Sun, 13 Sep 2020 01:34:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 483b43c4573329a28f1c9e18f90694e5be35ddb9
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:11:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:11:43 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 189 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 139 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 8351391cdd..b1c8644945 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1017,13 +1017,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1342,58 +1338,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1401,62 +1399,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1575,7 +1536,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1592,35 +1552,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1830,8 +1761,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 4eb41792e2..0c0c2a964e 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1518,8 +1518,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1556,14 +1555,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index d568e86db9..2310878e41 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Mon Sep 14 10:11:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 14 Sep 2020 10:11:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHlSA-00046k-Cz; Mon, 14 Sep 2020 10:11:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0hoC=CX=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHlS9-00046f-9M
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:17 +0000
X-Inumbo-ID: f69fe0bc-4351-4863-9f04-cc78916fb0de
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f69fe0bc-4351-4863-9f04-cc78916fb0de;
 Mon, 14 Sep 2020 10:11:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=4XmWLVgep0a+YUbnTuBsGWFEIo9gl07pLJCbTTuWADQ=; b=kbfnohGTA7imXN5W6DmrgBOE1K
 hRVl+X+BiWYAw72BmloBz1Tadsafw0nAxxkGYA3jVeClE4yXjCY2dTvYT3647n4a2aGvKmKnlSO3N
 XPhfden3Ke8P1OIOCLQWdnC04/O0B77lB2b1y4BZ0DxJUtOtLvEq6ESIKCq2FCglBYh8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlRx-0002uA-Ry
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlRx-0006Fu-Q0
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libs/stat: fix broken build
Message-Id: <E1kHlRx-0006Fu-Q0@xenbits.xenproject.org>
Date: Mon, 14 Sep 2020 10:11:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c8099e48c3dbb8c7399551a265756ecf354eece2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sat Sep 12 15:08:36 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:48:08 2020 +0000

    tools/libs/stat: fix broken build
    
    Making getBridge() static triggered a build error with some gcc versions:
    
    error: 'strncpy' output may be truncated copying 15 bytes from a string of
    length 255 [-Werror=stringop-truncation]
    
    Fix that by using a buffer with 256 bytes instead.
    
    Fixes: 6d0ec053907794 ("tools: split libxenstat into new tools/libs/stat directory")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/stat/xenstat_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index 793263f2b6..d2ee6fda64 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -78,7 +78,7 @@ static void getBridge(char *excludeName, char *result, size_t resultLen)
 				sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
 
 				if (access(tmp, F_OK) == 0) {
-					strncpy(result, de->d_name, resultLen - 1);
+					strncpy(result, de->d_name, resultLen);
 					result[resultLen - 1] = 0;
 				}
 		}
@@ -264,7 +264,7 @@ int xenstat_collect_networks(xenstat_node * node)
 {
 	/* Helper variables for parseNetDevLine() function defined above */
 	int i;
-	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
+	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
 	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
 
 	struct priv_data *priv = get_priv_data(node->handle);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 14 10:11:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 14 Sep 2020 10:11:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHlSJ-00047I-Eh; Mon, 14 Sep 2020 10:11:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0hoC=CX=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHlSI-00047B-Q7
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:26 +0000
X-Inumbo-ID: d930b5c1-5180-4b25-b2a5-343383ea03f7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d930b5c1-5180-4b25-b2a5-343383ea03f7;
 Mon, 14 Sep 2020 10:11:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=bSemXEOpUYSdthHrO86a2uaVQvEzUJdjIOzVKsU7UuU=; b=LzKTq23K0p7cu2ZOrJuDTRdTuE
 lSN0sEqh6gH02SpTVIwvgeEIRePkw8y6DWN/t8MCLCiw3vb5a7euuYa8FBC/TyIxyOcJ82zjvo6Ps
 9H5Y1qizqaQOxFSJXZ9LgFlDNDJyLmVK5LLpwyAXw3Zwwet+bL7piCkVl99Lvkvpo4Ds=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlS8-0002v5-01
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlS7-0006Gf-UC
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/build: fix python xc bindings
Message-Id: <E1kHlS7-0006Gf-UC@xenbits.xenproject.org>
Date: Mon, 14 Sep 2020 10:11:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ed7cbd55040fde693ab721d643e829f7218d51e1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sat Sep 12 15:58:07 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:48:26 2020 +0000

    tools/build: fix python xc bindings
    
    Commit 7c273ffdd0e91 ("tools/python: drop libxenguest from setup.py")
    was just wrong: there is one function from libxenguest used in the
    bindings, so readd the library again.
    
    While at it remove the unused PATH_LIBXL setting.
    
    Fixes: 7c273ffdd0e91 ("tools/python: drop libxenguest from setup.py")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/python/setup.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8254464aff..1afe800479 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -10,7 +10,7 @@ PATH_XEN      = XEN_ROOT + "/tools/include"
 PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
 PATH_LIBXENEVTCHN = XEN_ROOT + "/tools/libs/evtchn"
 PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
-PATH_LIBXL    = XEN_ROOT + "/tools/libxl"
+PATH_LIBXENGUEST = XEN_ROOT + "/tools/libs/guest"
 PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
 xc = Extension("xc",
@@ -19,10 +19,11 @@ xc = Extension("xc",
                                       PATH_LIBXENTOOLLOG + "/include",
                                       PATH_LIBXENEVTCHN + "/include",
                                       PATH_LIBXENCTRL + "/include",
+                                      PATH_LIBXENGUEST + "/include",
                                       "xen/lowlevel/xc" ],
-               library_dirs       = [ PATH_LIBXENCTRL ],
-               libraries          = [ "xenctrl" ],
-               depends            = [ PATH_LIBXENCTRL + "/libxenctrl.so" ],
+               library_dirs       = [ PATH_LIBXENCTRL, PATH_LIBXENGUEST ],
+               libraries          = [ "xenctrl", "xenguest" ],
+               depends            = [ PATH_LIBXENCTRL + "/libxenctrl.so", PATH_LIBXENGUEST + "/libxenguest.so" ],
                extra_link_args    = [ "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 14 10:11:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 14 Sep 2020 10:11:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHlST-00048M-Gg; Mon, 14 Sep 2020 10:11:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0hoC=CX=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHlSS-00048G-NQ
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:36 +0000
X-Inumbo-ID: 862eb4f1-e5b2-43d3-8c19-b44eea2ae23c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 862eb4f1-e5b2-43d3-8c19-b44eea2ae23c;
 Mon, 14 Sep 2020 10:11:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=VI5i+WeDGketyujn1BH8MT28f8TY87XuwWED6jsOcdg=; b=NtCz6Yi4QAFyfFa02WKVSru7/q
 FYytmgXlTLx5ucTeZGyIxBPsdA6LnytdU/76i6v0IO6Nv9TrodvO/Ipq0cWjQuOxISoNLP00R8sZv
 5zsufX+9+vseQjs2OxVjjV2aL8ndm6ldrB3Xhu6QXwMQoE/G+FacXr5HmLJ623agGgok=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlSI-0002vG-2x
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlSI-0006HR-28
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/libs/vchan: Don't run the headers check
Message-Id: <E1kHlSI-0006HR-28@xenbits.xenproject.org>
Date: Mon, 14 Sep 2020 10:11:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4f9a6165604b89da592860d9821b920eed79f5a2
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 10:24:19 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:49:15 2020 +0000

    tools/libs/vchan: Don't run the headers check
    
    There was never a headers check previously, and CentOS 6 can't cope with the
    anonymous union in struct libxenvchan.
    
      cc1: warnings being treated as errors
      ... tools/include/libxenvchan.h:75: error: declaration does not declare anything
      make[6]: *** [headers.chk] Error 1
    
    Fixes: 8ab2429f12 ("tools: split libxenvchan into new tools/libs/vchan directory")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/vchan/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libs/vchan/Makefile b/tools/libs/vchan/Makefile
index 87ff608f45..5e18d5b196 100644
--- a/tools/libs/vchan/Makefile
+++ b/tools/libs/vchan/Makefile
@@ -8,6 +8,8 @@ LIBHEADER := libxenvchan.h
 SRCS-y += init.c
 SRCS-y += io.c
 
+NO_HEADERS_CHK := y
+
 include $(XEN_ROOT)/tools/libs/libs.mk
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)/include
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 14 10:11:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 14 Sep 2020 10:11:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHlSe-00049i-Ie; Mon, 14 Sep 2020 10:11:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0hoC=CX=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHlSd-00049Z-1g
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:47 +0000
X-Inumbo-ID: ca0a488e-8238-470e-bc8b-f9bfeb61de99
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ca0a488e-8238-470e-bc8b-f9bfeb61de99;
 Mon, 14 Sep 2020 10:11:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ul3wn7xGx4NKUGgPKbgziB4Tffq3K4humgWxOZFoIz8=; b=6uxFKspox3+9MvLalNcTzVjElf
 qKtT3QDq90znGIISZXDv/loCZ/aWdOOQBCrQONd05DzV4AQzRYq+DlJVJDxYl9lU6p6DixK375l3E
 X6FpZOjlQI3y/U4HBVFhnevVhFCJJLf+PYdd/6wC9oZvZUg9AxzfcLGY7n6V4FeoQYoU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlSS-0002vJ-6L
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHlSS-0006I1-52
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 10:11:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools/Makefile: Drop the use of $(file ...)
Message-Id: <E1kHlSS-0006I1-52@xenbits.xenproject.org>
Date: Mon, 14 Sep 2020 10:11:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d16467b18e0c0a77743c3111bed2a833a77fbfe7
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 10:24:20 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:49:18 2020 +0000

    tools/Makefile: Drop the use of $(file ...)
    
    It is only available in make 4.0 and later, and not for example in CentOS 7.
    
    Rewrite the logic to use echo and shell redirection, using a single capture
    group to avoid having 12 different processes in quick succession each
    appending one line to the file.
    
    Fixes: 52dbd6f07cea7a ("tools: generate pkg-config files from make variables")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk | 52 ++++++++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 4fd91fa444..a71abb2e4f 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -186,29 +186,33 @@ $(PKG_CONFIG_DIR):
 	mkdir -p $(PKG_CONFIG_DIR)
 
 $(PKG_CONFIG_DIR)/%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk $(PKG_CONFIG_DIR)
-	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
-	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
-	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
-	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
-	$(file >>$@,)
-	$(file >>$@,Name: $(PKG_CONFIG_NAME))
-	$(file >>$@,Description: $(PKG_CONFIG_DESC))
-	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
-	$(file >>$@,Cflags: -I$${includedir} $(CFLAGS_xeninclude))
-	$(file >>$@,Libs: -L$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB))
-	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
-	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+	{ \
+	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
+	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
+	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
+	$(foreach var,$(PKG_CONFIG_VARS),echo $(var);) \
+	echo ""; \
+	echo "Name: $(PKG_CONFIG_NAME)"; \
+	echo "Description: $(PKG_CONFIG_DESC)"; \
+	echo "Version: $(PKG_CONFIG_VERSION)"; \
+	echo "Cflags: -I\$${includedir} $(CFLAGS_xeninclude)"; \
+	echo "Libs: -L\$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB)"; \
+	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
+	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
+	} > $@
 
 %.pc: Makefile $(XEN_ROOT)/tools/Rules.mk
-	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
-	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
-	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
-	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
-	$(file >>$@,)
-	$(file >>$@,Name: $(PKG_CONFIG_NAME))
-	$(file >>$@,Description: $(PKG_CONFIG_DESC))
-	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
-	$(file >>$@,Cflags: -I$${includedir})
-	$(file >>$@,Libs: -L$${libdir} -l$(PKG_CONFIG_LIB))
-	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
-	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+	{ \
+	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
+	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
+	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
+	$(foreach var,$(PKG_CONFIG_VARS),echo $(var);) \
+	echo ""; \
+	echo "Name: $(PKG_CONFIG_NAME)"; \
+	echo "Description: $(PKG_CONFIG_DESC)"; \
+	echo "Version: $(PKG_CONFIG_VERSION)"; \
+	echo "Cflags: -I\$${includedir}"; \
+	echo "Libs: -L\$${libdir} -l$(PKG_CONFIG_LIB)"; \
+	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
+	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
+	} > $@
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 14 15:44:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 14 Sep 2020 15:44:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHqeF-0003kE-Kv; Mon, 14 Sep 2020 15:44:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=0hoC=CX=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHqeF-0003k9-0b
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 15:44:07 +0000
X-Inumbo-ID: d2019504-8ef0-4706-9800-9a2725c71f21
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d2019504-8ef0-4706-9800-9a2725c71f21;
 Mon, 14 Sep 2020 15:44:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=oCOMK5DYbYsTPCgSbPMEJpHpr47tuyJ14f3xEsUUVzg=; b=h3oPELB85tITzhfs3UApDEHdWm
 MxcC05ac90+f7R6EBvSleOuTWj6kLxE4q22gWltsYtj7MyZahIYWXLjvP2QH/mFtHit28Cn4ofKDw
 AgZ0V/ZTy2dqlikFqhc//rSIr/c5hq/aPk0jnqeRZ76xIbfKHdeUnZ+l2WOoBKSqrhuw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHqeD-0001Zp-Jh
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 15:44:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHqeD-0007d9-IU
 for xen-changelog@lists.xenproject.org; Mon, 14 Sep 2020 15:44:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] travis: Fix build with newer Qemu
Message-Id: <E1kHqeD-0007d9-IU@xenbits.xenproject.org>
Date: Mon, 14 Sep 2020 15:44:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fc4e79c3f77f4360064f3614e32557a105458bae
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 14:21:01 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 14 16:37:30 2020 +0100

    travis: Fix build with newer Qemu
    
    Qemu requires a bleeding edge version of Python, not found in the current
    travis environment.  Skip building Qemu in that case.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 scripts/travis-build | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/travis-build b/scripts/travis-build
index 0cb15a89e4..84d74266a0 100755
--- a/scripts/travis-build
+++ b/scripts/travis-build
@@ -16,6 +16,11 @@ cfgargs+=("--disable-rombios")
 cfgargs+=("--enable-docs")
 cfgargs+=("--with-system-seabios=/usr/share/seabios/bios.bin")
 
+# Qemu requires Python 3.5 or later
+if ! type python3 || python3 -c "import sys; res = sys.version_info < (3, 5); exit(not(res))"; then
+    cfgargs+=("--with-system-qemu=/bin/false")
+fi
+
 if [[ "${XEN_TARGET_ARCH}" == "x86_64" ]]; then
     cfgargs+=("--enable-tools")
 else
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 00:33:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 00:33:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHyuD-0008Dd-Ng; Tue, 15 Sep 2020 00:33:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHyuC-0008DY-Dc
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:08 +0000
X-Inumbo-ID: 926c166d-f660-42e8-9299-949d49467d0e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 926c166d-f660-42e8-9299-949d49467d0e;
 Tue, 15 Sep 2020 00:33:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=FyyW/G0hzBmo+aWjiruroOz4urH6+KAhiQg67L7ZkeY=; b=pkHX8naw6A63IQ7fnsq/6WtHlm
 gTQPIfCB4TcHMzxz4lt4PzIlEB2Kg/puKfnWGNXc+/sCxhROsdOw2GYIJx7ELgwMRZTQ98ytTQNMb
 p8Ll1SetNbErzwkZlymqbRUX9/Ti7KGnOeIhEy8XqGrxha6zMD4hNEtFj+B7RrCWOE/w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyu9-0005Cx-P1
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyu9-0006I8-NV
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] arm: Add Neoverse N1 processor identification
Message-Id: <E1kHyu9-0006I8-NV@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 00:33:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit de7e543685c97136c7ebb961c9344dbdee528f67
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:38 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:19:39 2020 -0700

    arm: Add Neoverse N1 processor identification
    
    Add MIDR and CPU part numbers for Neoverse N1
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 3b418b33265402aab0cb1bf2b745a25724bae2d8)
---
 xen/include/asm-arm/processor.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
index aa642e3ab2..3ca67f8157 100644
--- a/xen/include/asm-arm/processor.h
+++ b/xen/include/asm-arm/processor.h
@@ -58,6 +58,7 @@
 #define ARM_CPU_PART_CORTEX_A73     0xD09
 #define ARM_CPU_PART_CORTEX_A75     0xD0A
 #define ARM_CPU_PART_CORTEX_A76     0xD0B
+#define ARM_CPU_PART_NEOVERSE_N1    0xD0C
 
 #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12)
 #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17)
@@ -68,6 +69,7 @@
 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
+#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
 
 /* MPIDR Multiprocessor Affinity Register */
 #define _MPIDR_UP           (30)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 00:33:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 00:33:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHyuM-0008EH-P9; Tue, 15 Sep 2020 00:33:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHyuK-0008E3-Mt
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:16 +0000
X-Inumbo-ID: 6c8b2afb-c877-4ad7-a94c-cc7745d50e0c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6c8b2afb-c877-4ad7-a94c-cc7745d50e0c;
 Tue, 15 Sep 2020 00:33:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=V4qVlbiIyt/f4/gy/My//Y/8ZCqPq7BmOOsJN+jjWfY=; b=orqLFnypwtVs2ocG8WEzFA+fn+
 3tyN0rbJ75iaybt//AS7oiJOz5ne/D9KKckvaqgL3Pkr0vY5Yl5m9bMV8TCME8yI6jAyDF0s+2CcT
 b1YqM6PdcSucMqJc9zxShqF+TRLoppauhXcMPqyGFc0YQktAUi15GO5WE8fH9XTiyP4c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuJ-0005D6-T3
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuJ-0006Ie-RC
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/arm: Enable CPU Erratum 1165522 for Neoverse
Message-Id: <E1kHyuJ-0006Ie-RC@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 00:33:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3535f2325fd9e247e268588fb4eda07bd33a2393
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:39 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:19:54 2020 -0700

    xen/arm: Enable CPU Erratum 1165522 for Neoverse
    
    Enable CPU erratum of Speculative AT on the Neoverse N1 processor
    versions r0p0 to r2p0.
    Also Fix Cortex A76 Erratum string which had a wrong errata number.
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 858c0be8c2fa4125a0fa0acaa03ae730e5c7cb3c)
---
 xen/arch/arm/cpuerrata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index 0248893de0..6c09017515 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -476,9 +476,15 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .matches = has_ssbd_mitigation,
     },
 #endif
+    {
+        /* Neoverse r0p0 - r2p0 */
+        .desc = "ARM erratum 1165522",
+        .capability = ARM64_WORKAROUND_AT_SPECULATE,
+        MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 2 << MIDR_VARIANT_SHIFT),
+    },
     {
         /* Cortex-A76 r0p0 - r2p0 */
-        .desc = "ARM erratum 116522",
+        .desc = "ARM erratum 1165522",
         .capability = ARM64_WORKAROUND_AT_SPECULATE,
         MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT),
     },
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 00:33:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 00:33:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHyuW-0008FY-Qn; Tue, 15 Sep 2020 00:33:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHyuU-0008FH-Rh
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:26 +0000
X-Inumbo-ID: c37fc2c8-dcd3-48e3-823f-c68123dca500
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c37fc2c8-dcd3-48e3-823f-c68123dca500;
 Tue, 15 Sep 2020 00:33:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=P1PNPcXNb0/zFWQ3RbddZ9ByA2KoFkC07rda34+6sA0=; b=sAeuVpmewIu7HiMkzQ92wKa/U7
 m1q7CAogFRY/ydjgTgrCi2tZTIWZgbt/3mylknDNMBAyjf5xm/cLw9Py7A3l8k/QdvSOyHWrHHOOf
 xTMFMRJNc394uXM6WCn6f7Cjz/jbH3ZrpL/Cky2NiwZCsJ5CW8olW7xDPsb8fvjgES4o=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuU-0005DH-0Z
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuT-0006JC-VB
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/arm: Update silicon-errata.txt with the
 Neovers AT erratum
Message-Id: <E1kHyuT-0006JC-VB@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 00:33:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 158c3bdc499aa860d7218803867e48534f4d6730
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:07 2020 -0700

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    (cherry picked from commit 1814a626fb5811184eda64fe22f0055df4600211)
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 00:33:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 00:33:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHyuf-0008HB-SQ; Tue, 15 Sep 2020 00:33:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHyuf-0008H3-6G
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:37 +0000
X-Inumbo-ID: 5259c685-e2b8-423a-864b-3bf5537ba320
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5259c685-e2b8-423a-864b-3bf5537ba320;
 Tue, 15 Sep 2020 00:33:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rSyZiAJwNSMYpoHf/oSuSMeqdufI2Y7JoUB2OkCkogw=; b=xVPKOZS228m5QJ8Hf59d5cV6db
 YQDX19JvLGyPf/eN0uWTRIPX/EhkDA5kFPdTmrow0hXjX/l4Aa4gXi5wfXedEcR1VWK3/4YWojvcY
 Anoc6at1T40wPnAnYkdRoeN2W4lQZKCr/YSkDJDmFjZYLkUpJI6b2tMnaQMPcbuWiTHA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyue-0005DR-3h
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyue-0006Jm-2j
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kHyue-0006Jm-2j@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 00:33:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 174be04403be87eaa217c47a59665fc5fe317c05
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:20 2020 -0700

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 968bb86d04913f52d7678a842474f2a674a8b23e)
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 674beb0353..10878ead8a 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 00:33:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 00:33:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kHyup-0008IU-UE; Tue, 15 Sep 2020 00:33:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kHyup-0008IM-4e
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:47 +0000
X-Inumbo-ID: 564f637a-311d-4765-a3ae-a134804be7ac
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 564f637a-311d-4765-a3ae-a134804be7ac;
 Tue, 15 Sep 2020 00:33:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Qe5T83tsE1SDqUQUaRtsFtFUptrJ4VydjGL/Z3/OmjM=; b=3hYK9gCeYoh8r7/0HEoi5pErkn
 bf1kl60CSf+Rukgg2U6IgewY4rzdaW12F9T+kwPCk/+W1fcKNPeReYwqP7xL8I5IRtyt1XOZmrEUx
 WwkDDn5MYAO02qnFTxvRsPWH+iZfW/pILDB9uYxVEcTcKFHwq2VtnO9vyV6kFDzbeGaQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuo-0005EF-6d
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kHyuo-0006KE-5t
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 00:33:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/arm: cmpxchg: Add missing memory barriers in
 __cmpxchg_mb_timeout()
Message-Id: <E1kHyuo-0006KE-5t@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 00:33:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 28855ebcdbfa437e60bc16c761405476fe16bc39
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Jul 29 14:50:37 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:52 2020 -0700

    xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()
    
    The function __cmpxchg_mb_timeout() was intended to have the same
    semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were
    not added when first implemented.
    
    There is no known issue with the existing callers, but the barriers are
    added given this is the expected semantics in Xen.
    
    The issue was introduced by XSA-295.
    
    Backport: 4.8+
    Fixes: 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    (cherry picked from commit d501ef90ae7f2a79130ea89acb3d6d1792972934)
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 49ca2a0d7a..0770f272ee 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index 5bc2e1f786..fc5c60f0bd 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 08:22:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 08:22:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI6E3-0005J7-Mc; Tue, 15 Sep 2020 08:22:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI6E2-0005J2-Nl
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:06 +0000
X-Inumbo-ID: 954b3295-15f7-4659-9225-5f14b2390356
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 954b3295-15f7-4659-9225-5f14b2390356;
 Tue, 15 Sep 2020 08:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IPH2zUvJFjJu0DMNYi6le1kjkaW5l0B+uQPj3nglxT0=; b=XaC/tZPiJr0KBtkQyFZeb5LkgC
 orswxChSTvRUgBMB9kl9sLkOedzONjkJ8D8R/ZpQxD2NWOODj25x8rDGPvX3aOjuc4eklpIWAAEkJ
 aU3mTTzneAXD4ixs3Xc5Y0SZLJvTWujAZ/eM4IoHN7njZfNhDfcIW7CXwgCVVVg1XtmA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6E0-0004hg-PA
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6E0-00074J-MQ
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/HVM: more consistently set I/O completion
Message-Id: <E1kI6E0-00074J-MQ@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 08:22:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b807cfe954b8d0d8852398b4c8a586d95d69a342
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 15 10:19:33 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:19:33 2020 +0200

    x86/HVM: more consistently set I/O completion
    
    Doing this just in hvm_emulate_one_insn() is not enough.
    hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
    insns requiring one or more continuations, and at least in principle
    hvm_emulate_one_mmio() could, too. Without proper setting of the field,
    handle_hvm_io_completion() will do nothing completion-wise, and in
    particular the missing re-invocation of the insn emulation paths will
    lead to emulation caching not getting disabled in due course, causing
    the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
    
    Reported-by: Don Slutz <don.slutz@gmail.com>
    
    Similar considerations go for the clearing of vio->mmio_access, which
    gets moved as well.
    
    Additionally all updating of vio->mmio_* now gets done dependent upon
    the new completion value, rather than hvm_ioreq_needs_completion()'s
    return value. This is because it is the completion chosen which controls
    what path will be taken when handling the completion, not the simple
    boolean return value. In particular, PIO completion doesn't involve
    going through the insn emulator, and hence emulator state ought to get
    cleared early (or it won't get cleared at all).
    
    The new logic, besides allowing for a caller override for the
    continuation type to be set (for VMX real mode emulation), will also
    avoid setting an MMIO completion when a simpler PIO one will do. This
    is a minor optimization only as a side effect - the behavior is strictly
    needed at least for hvm_ud_intercept(), as only memory accesses can
    successfully complete through handle_mmio(). Care of course needs to be
    taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
    the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
    whether the insn being emulated is a memory access, as this information
    is no longer easily available at the point where we want to consume it.
    
    Note that the presence of non-NULL .validate fields in the two ops
    structures in hvm_emulate_one_mmio() was really necessary even before
    the changes here: Without this, passing non-NULL as middle argument to
    hvm_emulate_init_once() is meaningless.
    
    The restrictions on when the #UD intercept gets actually enabled are why
    it was decided that this is not a security issue:
    - the "hvm_fep" option to enable its use is a debugging option only,
    - for the cross-vendor case is considered experimental, even if
      unfortunately SUPPORT.md doesn't have an explicit statement about
      this.
    The other two affected functions are
    - hvm_emulate_one_vm_event(), used for introspection,
    - hvm_emulate_one_mmio(), used for Dom0 only,
    which aren't qualifying this as needing an XSA either.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Don Slutz <don.slutz@gmail.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/emulate.c        | 51 ++++++++++++++++++++++++++++++---------
 xen/arch/x86/hvm/hvm.c            |  2 +-
 xen/arch/x86/hvm/io.c             | 11 +--------
 xen/arch/x86/hvm/vmx/realmode.c   |  6 +----
 xen/include/asm-x86/hvm/emulate.h |  5 +++-
 5 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 8b4e73ab06..24cf85fb4f 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1683,9 +1683,11 @@ static int hvmemul_validate(
     const struct x86_emulate_state *state,
     struct x86_emulate_ctxt *ctxt)
 {
-    const struct hvm_emulate_ctxt *hvmemul_ctxt =
+    struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
 
+    hvmemul_ctxt->is_mem_access = x86_insn_is_mem_access(state, ctxt);
+
     return !hvmemul_ctxt->validate || hvmemul_ctxt->validate(state, ctxt)
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
 }
@@ -2610,8 +2612,14 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
     .vmfunc        = hvmemul_vmfunc,
 };
 
+/*
+ * Note that passing HVMIO_no_completion into this function serves as kind
+ * of (but not fully) an "auto select completion" indicator.  When there's
+ * no completion needed, the passed in value will be ignored in any case.
+ */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
-    const struct x86_emulate_ops *ops)
+    const struct x86_emulate_ops *ops,
+    enum hvm_io_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
@@ -2642,16 +2650,31 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
         rc = X86EMUL_RETRY;
 
     if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+        completion = HVMIO_no_completion;
+    else if ( completion == HVMIO_no_completion )
+        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
+                                                   : HVMIO_pio_completion;
+
+    switch ( vio->io_completion = completion )
     {
+    case HVMIO_no_completion:
+    case HVMIO_pio_completion:
         vio->mmio_cache_count = 0;
         vio->mmio_insn_bytes = 0;
+        vio->mmio_access = (struct npfec){};
         hvmemul_cache_disable(curr);
-    }
-    else
-    {
+        break;
+
+    case HVMIO_mmio_completion:
+    case HVMIO_realmode_completion:
         BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
         vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
         memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
     }
 
     if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2692,9 +2715,10 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 }
 
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt)
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion)
 {
-    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops);
+    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
 
 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
@@ -2703,11 +2727,13 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmcfg_intercept_write,
+        .validate   = hvmemul_validate,
     };
     static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = {
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmio_ro_emulated_write,
+        .validate   = hvmemul_validate,
     };
     struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla };
     struct hvm_emulate_ctxt ctxt;
@@ -2727,8 +2753,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
     hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write,
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
-    rc = _hvm_emulate_one(&ctxt, ops);
-    switch ( rc )
+
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2755,7 +2781,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     switch ( kind )
     {
     case EMUL_KIND_NOWRITE:
-        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write);
+        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
+                              HVMIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
@@ -2776,7 +2803,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx);
+        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
     }
 
     switch ( rc )
@@ -2874,6 +2901,8 @@ void hvm_emulate_init_per_insn(
                                         pfec, NULL) == HVMTRANS_okay) ?
             sizeof(hvmemul_ctxt->insn_buf) : 0;
     }
+
+    hvmemul_ctxt->is_mem_access = false;
 }
 
 void hvm_emulate_writeback(
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index a9d1685549..32719b6d01 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3798,7 +3798,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt) )
+    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 724ab44a76..3e09d9b726 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -81,20 +81,11 @@ void send_invalidate_req(void)
 bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 {
     struct hvm_emulate_ctxt ctxt;
-    struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    rc = hvm_emulate_one(&ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_mmio_completion;
-    else
-        vio->mmio_access = (struct npfec){};
-
-    switch ( rc )
+    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c
index bdbd9cb921..768f01eb04 100644
--- a/xen/arch/x86/hvm/vmx/realmode.c
+++ b/xen/arch/x86/hvm/vmx/realmode.c
@@ -97,15 +97,11 @@ static void realmode_deliver_exception(
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_realmode_completion;
+    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
diff --git a/xen/include/asm-x86/hvm/emulate.h b/xen/include/asm-x86/hvm/emulate.h
index f40290945c..1620cc7b7a 100644
--- a/xen/include/asm-x86/hvm/emulate.h
+++ b/xen/include/asm-x86/hvm/emulate.h
@@ -48,6 +48,8 @@ struct hvm_emulate_ctxt {
 
     uint32_t intr_shadow;
 
+    bool is_mem_access;
+
     bool_t set_context;
 };
 
@@ -62,7 +64,8 @@ bool __nonnull(1, 2) hvm_emulate_one_insn(
     hvm_emulate_validate_t *validate,
     const char *descr);
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt);
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 08:22:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 08:22:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI6ED-0005Ju-PX; Tue, 15 Sep 2020 08:22:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI6EC-0005Jn-4S
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:16 +0000
X-Inumbo-ID: 0ded2fd8-496b-463a-b04e-37c810ae15b8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0ded2fd8-496b-463a-b04e-37c810ae15b8;
 Tue, 15 Sep 2020 08:22:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7B1je4E15WLzbbfC/Hqb0JV+eXREtP3REbJzJtbxoFQ=; b=MjH8priiotqummaxejnvCCa4Yl
 URHK2okJr5OqoDNokaMkYF6HTkaju9csHnKX1pVCw8g8pjEvHe82WKI0FFiF00l4CK+fTbHmjKOME
 nfncPixCjS8d6PpxVVvkhvSCgxpzcH4+oPKG1hHu3nhQyntY4GEcxGBd3Obq7+CQUplw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6EA-0004hj-TV
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6EA-00074v-RW
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] EFI: free unused boot mem in at least some cases
Message-Id: <E1kI6EA-00074v-RW@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 08:22:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a4cbe0f3b47656ea125922fd48d394731a0163fd
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 15 10:20:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:20:37 2020 +0200

    EFI: free unused boot mem in at least some cases
    
    Address at least the primary reason why 52bba67f8b87 ("efi/boot: Don't
    free ebmalloc area at all") was put in place: Make xen_in_range() aware
    of the freed range. This is in particular relevant for EFI-enabled
    builds not actually running on EFI, as the entire range will be unused
    in this case.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/efi/stub.c   |  6 ++++++
 xen/arch/x86/setup.c      | 26 +++++++++++++++++++++++---
 xen/arch/x86/tboot.c      | 12 ++++++++++++
 xen/common/efi/ebmalloc.c | 31 ++++++++++++++++++++++++++-----
 xen/include/xen/efi.h     |  1 +
 5 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index c578bffc71..0e01e7322b 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -52,6 +52,12 @@ bool efi_enabled(unsigned int feature)
 
 void __init efi_init_memory(void) { }
 
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
+{
+    *start = *end = (unsigned long)_end;
+    return false;
+}
+
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
 
 bool efi_rs_using_pgtables(void)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 4b15e067fa..44c04e2735 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -830,6 +830,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
     int i, j, e820_warn = 0, bytes = 0;
+    unsigned long eb_start, eb_end;
     bool acpi_boot_table_init_done = false, relocated = false;
     int ret;
     struct ns16550_defaults ns16550 = {
@@ -1145,7 +1146,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
         /*
          * This needs to remain in sync with xen_in_range() and the
-         * respective reserve_e820_ram() invocation below.
+         * respective reserve_e820_ram() invocation below. No need to
+         * query efi_boot_mem_unused() here, though.
          */
         mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
@@ -1417,8 +1419,18 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen\n");
 
+    /* FIXME: Putting a hole in .bss would shatter the large page mapping. */
+    if ( using_2M_mapping() )
+        efi_boot_mem_unused(NULL, NULL);
+
     /* This needs to remain in sync with xen_in_range(). */
-    reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
+    if ( efi_boot_mem_unused(&eb_start, &eb_end) )
+    {
+        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start));
+        reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end));
+    }
+    else
+        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1979,7 +1991,7 @@ int __hwdom_init xen_in_range(unsigned long mfn)
     paddr_t start, end;
     int i;
 
-    enum { region_s3, region_ro, region_rw, nr_regions };
+    enum { region_s3, region_ro, region_rw, region_bss, nr_regions };
     static struct {
         paddr_t s, e;
     } xen_regions[nr_regions] __hwdom_initdata;
@@ -2004,6 +2016,14 @@ int __hwdom_init xen_in_range(unsigned long mfn)
         /* hypervisor .data + .bss */
         xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
         xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
+        if ( efi_boot_mem_unused(&start, &end) )
+        {
+            ASSERT(__pa(start) >= xen_regions[region_rw].s);
+            ASSERT(__pa(end) <= xen_regions[region_rw].e);
+            xen_regions[region_rw].e = __pa(start);
+            xen_regions[region_bss].s = __pa(end);
+            xen_regions[region_bss].e = __pa(&__2M_rwdata_end);
+        }
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index e66b0940c4..aadcce591f 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -1,3 +1,4 @@
+#include <xen/efi.h>
 #include <xen/init.h>
 #include <xen/types.h>
 #include <xen/lib.h>
@@ -364,6 +365,8 @@ void tboot_shutdown(uint32_t shutdown_type)
     /* if this is S3 then set regions to MAC */
     if ( shutdown_type == TB_SHUTDOWN_S3 )
     {
+        unsigned long s, e;
+
         /*
          * Xen regions for tboot to MAC. This needs to remain in sync with
          * xen_in_range().
@@ -378,6 +381,15 @@ void tboot_shutdown(uint32_t shutdown_type)
         /* hypervisor .data + .bss */
         g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(&__2M_rwdata_start);
         g_tboot_shared->mac_regions[2].size = __2M_rwdata_end - __2M_rwdata_start;
+        if ( efi_boot_mem_unused(&s, &e) )
+        {
+            g_tboot_shared->mac_regions[2].size =
+                s - (unsigned long)__2M_rwdata_start;
+            g_tboot_shared->mac_regions[3].start = __pa(e);
+            g_tboot_shared->mac_regions[3].size =
+                (unsigned long)__2M_rwdata_end - e;
+            g_tboot_shared->num_mac_regions = 4;
+        }
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/common/efi/ebmalloc.c b/xen/common/efi/ebmalloc.c
index c65dbd946f..136838eb8e 100644
--- a/xen/common/efi/ebmalloc.c
+++ b/xen/common/efi/ebmalloc.c
@@ -1,5 +1,6 @@
 #include "efi.h"
 #include <xen/init.h>
+#include <xen/mm.h>
 
 #ifdef CONFIG_ARM
 /*
@@ -21,7 +22,7 @@
 
 static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
     ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __initdata ebmalloc_allocated;
+static unsigned long __read_mostly ebmalloc_allocated;
 
 /* EFI boot allocator. */
 void __init *ebmalloc(size_t size)
@@ -36,17 +37,37 @@ void __init *ebmalloc(size_t size)
     return ptr;
 }
 
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
+{
+    if ( !start && !end )
+    {
+        ebmalloc_allocated = sizeof(ebmalloc_mem);
+        return false;
+    }
+
+    *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
+    *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    return *start < *end;
+}
+
 void __init free_ebmalloc_unused_mem(void)
 {
-#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
     unsigned long start, end;
 
-    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
-    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+    if ( !efi_boot_mem_unused(&start, &end) )
+        return;
 
     destroy_xen_mappings(start, end);
+
+#ifdef CONFIG_X86
+    /*
+     * By reserving the space early in the E820 map, it gets freed way before
+     * we make it here. Don't free the range a 2nd time.
+     */
+#else
     init_xenheap_pages(__pa(start), __pa(end));
+#endif
 
     printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
-#endif
 }
diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h
index 44b7d3ec3a..94a7e547f9 100644
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -33,6 +33,7 @@ struct compat_pf_efi_runtime_call;
 
 bool efi_enabled(unsigned int feature);
 void efi_init_memory(void);
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end);
 bool efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
 void efi_halt_system(void);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 08:22:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 08:22:26 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI6EM-0005Kv-R2; Tue, 15 Sep 2020 08:22:26 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI6EL-0005Ko-St
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:25 +0000
X-Inumbo-ID: 9d31e2d3-04ad-4e1e-a0d4-5265a1a1b30e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9d31e2d3-04ad-4e1e-a0d4-5265a1a1b30e;
 Tue, 15 Sep 2020 08:22:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=RuJiq8u4uZ044ARbECv1ekAD4kQMWaOHGBWp9NpZ8Sg=; b=tdKZn8g+YNi5IWLAAgKmyzurqb
 tO+zOrstJHBLZg+Ip89LQ2yuHAkCLtsY3kQgghukQjzgpo3T+Smwo1Ri5HiCS5tCyQ7s5CznoHa5Q
 mr0AN+i2pKqImQ27OqYlHqS11ldm67B1eIrl9jurpkUcgDy5pBemsPgaNYqSALNebvfM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6EL-0004hp-19
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI6EK-00075i-Vs
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 08:22:24 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: allow reading FEATURE_CONTROL MSR
Message-Id: <E1kI6EK-00075i-Vs@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 08:22:24 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 39ab598c50a2b539f376adc363d684c2df6c8dd7
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 10:21:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:21:09 2020 +0200

    x86/pv: allow reading FEATURE_CONTROL MSR
    
    Linux PV guests will attempt to read the FEATURE_CONTROL MSR, so move
    the handling done in VMX code into guest_rdmsr as it can be shared
    between PV and HVM guests that way.
    
    Note that there's a slight behavior change and attempting to read the
    MSR when no features are available will result in a fault.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c |  8 +-------
 xen/arch/x86/msr.c         | 12 ++++++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index c4b40bf3cb..709ea149d1 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     case MSR_IA32_DEBUGCTLMSR:
         __vmread(GUEST_IA32_DEBUGCTL, msr_content);
         break;
-    case MSR_IA32_FEATURE_CONTROL:
-        *msr_content = IA32_FEATURE_CONTROL_LOCK;
-        if ( vmce_has_lmce(curr) )
-            *msr_content |= IA32_FEATURE_CONTROL_LMCE_ON;
-        if ( nestedhvm_enabled(curr->domain) )
-            *msr_content |= IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX;
-        break;
+
     case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:
         if ( !nvmx_msr_read_intercept(msr, msr_content) )
             goto gp_fault;
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 74bf7d9589..79fbb9e940 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -25,6 +25,7 @@
 #include <xen/sched.h>
 
 #include <asm/debugreg.h>
+#include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/viridian.h>
 #include <asm/msr.h>
 #include <asm/setup.h>
@@ -197,6 +198,17 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         /* Not offered to guests. */
         goto gp_fault;
 
+    case MSR_IA32_FEATURE_CONTROL:
+        if ( !cp->basic.vmx && !vmce_has_lmce(v) )
+            goto gp_fault;
+
+        *val = IA32_FEATURE_CONTROL_LOCK;
+        if ( vmce_has_lmce(v) )
+            *val |= IA32_FEATURE_CONTROL_LMCE_ON;
+        if ( cp->basic.vmx )
+            *val |= IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX;
+        break;
+
     case MSR_IA32_PLATFORM_ID:
         if ( !(cp->x86_vendor & X86_VENDOR_INTEL) ||
              !(boot_cpu_data.x86_vendor & X86_VENDOR_INTEL) )
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 09:33:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 09:33:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI7Kl-0004S1-Uv; Tue, 15 Sep 2020 09:33:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI7Kk-0004Rv-Li
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:06 +0000
X-Inumbo-ID: d4eeda22-104b-462a-ae55-6f6f931cdf29
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d4eeda22-104b-462a-ae55-6f6f931cdf29;
 Tue, 15 Sep 2020 09:33:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6HumcODMMrEcnS2LGKzK0a+wuv9mU7+QzW5Vrp1Q5mo=; b=hFoXn/ezol2ywfLlS9xZk2jAro
 iPMyqepWwjmV8NzzDPFkdmVZdg0BQaD++ooeuBhp6sIPKx2vlVZh3CWgtA7Y0oTOCxqz64Q1CsTdm
 keby7Tdpq2LVA6ud4/GpEU9Ih2M0izIaIzGHgO2Frprzi9+Z6uKZTfkEf6d9XYAUMIl8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7Kg-0006Ne-7n
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7Kg-0002rA-5q
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] arm: Add Neoverse N1 processor identification
Message-Id: <E1kI7Kg-0002rA-5q@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 09:33:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit de7e543685c97136c7ebb961c9344dbdee528f67
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:38 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:19:39 2020 -0700

    arm: Add Neoverse N1 processor identification
    
    Add MIDR and CPU part numbers for Neoverse N1
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 3b418b33265402aab0cb1bf2b745a25724bae2d8)
---
 xen/include/asm-arm/processor.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
index aa642e3ab2..3ca67f8157 100644
--- a/xen/include/asm-arm/processor.h
+++ b/xen/include/asm-arm/processor.h
@@ -58,6 +58,7 @@
 #define ARM_CPU_PART_CORTEX_A73     0xD09
 #define ARM_CPU_PART_CORTEX_A75     0xD0A
 #define ARM_CPU_PART_CORTEX_A76     0xD0B
+#define ARM_CPU_PART_NEOVERSE_N1    0xD0C
 
 #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12)
 #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17)
@@ -68,6 +69,7 @@
 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
+#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
 
 /* MPIDR Multiprocessor Affinity Register */
 #define _MPIDR_UP           (30)
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 09:33:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 09:33:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI7Kt-0004ST-06; Tue, 15 Sep 2020 09:33:15 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI7Ks-0004SO-FN
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:14 +0000
X-Inumbo-ID: b75a2898-2c43-44f5-a749-8979e7c3c8a1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b75a2898-2c43-44f5-a749-8979e7c3c8a1;
 Tue, 15 Sep 2020 09:33:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DEL9IQvJy51z4TRI9kf4DsMf/FXfiUX4hpvxRpZRcS4=; b=JhdQd7sc+DoPPrWeSiQgCs3fZ7
 S7mJnUloQda74oS+wGQDTEyt7dOjQygQctcD5bx5Dxr+sR5eEm/mm9DW0YF/0Pw0KOr7ld0yUubW7
 ieS4HRssRbWN58EdnWxju2QVj1zUadRPkIrurlGeMX23/NyJOlA9cpl0cwFwQN4JsFAY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7Kr-0006Nn-LU
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7Kq-0002sB-A6
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:13 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] xen/arm: Enable CPU Erratum 1165522 for Neoverse
Message-Id: <E1kI7Kq-0002sB-A6@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 09:33:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3535f2325fd9e247e268588fb4eda07bd33a2393
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:39 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:19:54 2020 -0700

    xen/arm: Enable CPU Erratum 1165522 for Neoverse
    
    Enable CPU erratum of Speculative AT on the Neoverse N1 processor
    versions r0p0 to r2p0.
    Also Fix Cortex A76 Erratum string which had a wrong errata number.
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 858c0be8c2fa4125a0fa0acaa03ae730e5c7cb3c)
---
 xen/arch/arm/cpuerrata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index 0248893de0..6c09017515 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -476,9 +476,15 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .matches = has_ssbd_mitigation,
     },
 #endif
+    {
+        /* Neoverse r0p0 - r2p0 */
+        .desc = "ARM erratum 1165522",
+        .capability = ARM64_WORKAROUND_AT_SPECULATE,
+        MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 2 << MIDR_VARIANT_SHIFT),
+    },
     {
         /* Cortex-A76 r0p0 - r2p0 */
-        .desc = "ARM erratum 116522",
+        .desc = "ARM erratum 1165522",
         .capability = ARM64_WORKAROUND_AT_SPECULATE,
         MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT),
     },
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 09:33:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 09:33:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI7L3-0004Th-1a; Tue, 15 Sep 2020 09:33:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI7L2-0004TY-Gq
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:24 +0000
X-Inumbo-ID: 2e354062-ba12-4c2b-b905-edb40a5a20c6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2e354062-ba12-4c2b-b905-edb40a5a20c6;
 Tue, 15 Sep 2020 09:33:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=MozQ7aP81aoZmxSzWDSdEZdSB5KPx35EJFfZEf1bhQo=; b=5Dpcb9EJ+X8EHWetZt1vEYA+rF
 O8RnXBxErbi43DvqVFFqzc45DmBjMTk2AkKZf9j/DhVOASfVLLS+Gg+EB+bKU6IWtY8hYkx1tsJ4y
 XlEIelg6uNpaI7qoczuuelj4vWy8d5CK/1hxiiO5KP1Dqfi8sI6cSxpzOSd2z7mAxmkk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7L1-0006Nv-Ob
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7L1-0002sy-Ng
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] xen/arm: Update silicon-errata.txt with the Neovers
 AT erratum
Message-Id: <E1kI7L1-0002sy-Ng@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 09:33:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 158c3bdc499aa860d7218803867e48534f4d6730
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:07 2020 -0700

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    (cherry picked from commit 1814a626fb5811184eda64fe22f0055df4600211)
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 09:33:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 09:33:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI7LD-0004Uw-3A; Tue, 15 Sep 2020 09:33:35 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI7LC-0004Un-MW
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:34 +0000
X-Inumbo-ID: 65431e88-bd4e-4b02-b1e5-857708ddd695
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 65431e88-bd4e-4b02-b1e5-857708ddd695;
 Tue, 15 Sep 2020 09:33:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=pu919s/b0aEGRyzbNGUJ/8cGsIalSyWMJzHHShnqLQ0=; b=Tu5JuPIqQuTsDpn5Ogulug4O/Y
 sfEuj1T4mWLCvKPDh+RVAbSrewIGYoRqknafX4tXlkX+ze2n1ojoMPmLsAMyFXL2dbtFjFikcq/G8
 8HL3pCOWVKWbNxnUdWhmFoFBqfnUOU0Ceb8DTCJRzjPU3Az8i9YO/zy+50biehwYmEdY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7LB-0006O3-Rj
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7LB-0002tj-Qt
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kI7LB-0002tj-Qt@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 09:33:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 174be04403be87eaa217c47a59665fc5fe317c05
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:20 2020 -0700

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 968bb86d04913f52d7678a842474f2a674a8b23e)
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 674beb0353..10878ead8a 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 09:33:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 09:33:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI7LN-0004Wy-66; Tue, 15 Sep 2020 09:33:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI7LM-0004WE-Qg
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:44 +0000
X-Inumbo-ID: 3f222108-cb26-4eaa-acb4-14bf01ff95d4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3f222108-cb26-4eaa-acb4-14bf01ff95d4;
 Tue, 15 Sep 2020 09:33:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6CIC8DpYMowbYjrpVP3lbv0UOfzRyrtgCbHeyq6rcck=; b=RlOnog4ZgrgEySgINlmaieUYtM
 JlKVtoagamVDsYA1+2q9prn14S6Vz+HKkkdT9lsunN8H6Agj8z3TuSjeWHzbYRs/iVVurMCanmavo
 aYV4vxfEQjKHFqryanhq21MaCQvTMaPaG+96sboKADTsSvoyWN2+BauapVcSCsv4fcjo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7LL-0006OD-Vg
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI7LL-0002uS-Ts
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 09:33:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.14] xen/arm: cmpxchg: Add missing memory barriers in
 __cmpxchg_mb_timeout()
Message-Id: <E1kI7LL-0002uS-Ts@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 09:33:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 28855ebcdbfa437e60bc16c761405476fe16bc39
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Jul 29 14:50:37 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:20:52 2020 -0700

    xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()
    
    The function __cmpxchg_mb_timeout() was intended to have the same
    semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were
    not added when first implemented.
    
    There is no known issue with the existing callers, but the barriers are
    added given this is the expected semantics in Xen.
    
    The issue was introduced by XSA-295.
    
    Backport: 4.8+
    Fixes: 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    (cherry picked from commit d501ef90ae7f2a79130ea89acb3d6d1792972934)
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 49ca2a0d7a..0770f272ee 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index 5bc2e1f786..fc5c60f0bd 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 10:55:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 10:55:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI8c8-0003QX-7R; Tue, 15 Sep 2020 10:55:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI8c6-0003QS-V7
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:07 +0000
X-Inumbo-ID: 24b9c992-8ef4-4a53-8a58-dd06b149b751
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 24b9c992-8ef4-4a53-8a58-dd06b149b751;
 Tue, 15 Sep 2020 10:55:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=TG/IhTCdl72TeGLE2JIGdxKh8qOESZ+3hcmHKsT0yi4=; b=ItuVFK/cohcVvd100GcFsMCGhf
 AjilYqPJJ9AkcBP2ygwUoU7//Oik1kABo6+ITQT0HF2mKYCKOKQMxmH4y3pjuwsSj1tELWYGbeAls
 7Rd61CSbelvJwkUD9Fg16jX1m4gkxEOX+qMKuJscmgPlNkuKrxUPD05hQuy/d2Io9KLo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8c5-00089K-ET
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8c5-0007W9-Cc
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/svm: handle BU_CFG and BU_CFG2 with cases
Message-Id: <E1kI8c5-0007W9-Cc@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 10:55:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8a31c255afab71f30f0fa1f8c7cef309aa2ec483
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 12:42:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:42:21 2020 +0200

    x86/svm: handle BU_CFG and BU_CFG2 with cases
    
    Move the special handling of reads to it's own switch case, and also
    add support for BU_CFG2. On the write side ignore writes if the MSR is
    readable, otherwise return a #GP.
    
    This is in preparation for changing the default MSR read/write
    behavior, which will instead return #GP on not explicitly handled
    cases.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 23b2a2aa17..e14c0cce30 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1861,6 +1861,30 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         *msr_content = 1ULL << 61; /* MC4_MISC.Locked */
         break;
 
+    case MSR_F10_BU_CFG:
+        if ( !rdmsr_safe(msr, *msr_content) )
+            break;
+
+        if ( boot_cpu_data.x86 == 0xf )
+        {
+            /*
+             * Win2k8 x64 reads this MSR on revF chips, where it wasn't
+             * publically available; it uses a magic constant in %rdi as a
+             * password, which we don't have in rdmsr_safe().  Since we'll
+             * throw a #GP for later writes, just use a plausible value here
+             * (the reset value from rev10h chips) if the real CPU didn't
+             * provide one.
+             */
+            *msr_content = 0x10200020;
+            break;
+        }
+        goto gpf;
+
+    case MSR_F10_BU_CFG2:
+        if ( rdmsr_safe(msr, *msr_content) )
+            goto gpf;
+        break;
+
     case MSR_IA32_EBC_FREQUENCY_ID:
         /*
          * This Intel-only register may be accessed if this HVM guest
@@ -1939,19 +1963,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     default:
         if ( rdmsr_safe(msr, *msr_content) == 0 )
             break;
-
-        if ( boot_cpu_data.x86 == 0xf && msr == MSR_F10_BU_CFG )
-        {
-            /* Win2k8 x64 reads this MSR on revF chips, where it
-             * wasn't publically available; it uses a magic constant
-             * in %rdi as a password, which we don't have in
-             * rdmsr_safe().  Since we'll ignore the later writes,
-             * just use a plausible value here (the reset value from
-             * rev10h chips) if the real CPU didn't provide one. */
-            *msr_content = 0x0000000010200020ull;
-            break;
-        }
-
         goto gpf;
     }
 
@@ -2107,6 +2118,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         nsvm->ns_msr_hsavepa = msr_content;
         break;
 
+    case MSR_F10_BU_CFG:
+    case MSR_F10_BU_CFG2:
+        if ( rdmsr_safe(msr, msr_content) )
+            goto gpf;
+        break;
+
     case MSR_AMD64_TSC_RATIO:
         if ( msr_content & TSC_RATIO_RSVD_BITS )
             goto gpf;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 10:55:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 10:55:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI8cI-0003RB-99; Tue, 15 Sep 2020 10:55:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI8cG-0003R1-Is
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:16 +0000
X-Inumbo-ID: 7beae21a-a01c-4277-8e7b-8c23042090a5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7beae21a-a01c-4277-8e7b-8c23042090a5;
 Tue, 15 Sep 2020 10:55:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0u1Oxw0rXyXbfyqSbDxoDc/fWlg2zOm1VSt4mMktw20=; b=HHn0Yfk8uiKRg1xZxxtCnEAgZz
 SGd2IP9+Ubo+vFzVlDrgrHxxYYdQOlz8snyinP9L+v78wDXv5Tng3cQXdJDgz/T0lJnIc6Ri9Dsjt
 Me8g4i6pcMxCp9aD4t0j03Ya4Om74bvhY11p1wxxbBWN/0KGJHeK9+lvBBTVbUdlXRMs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cF-00089N-Ij
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cF-0007X2-Gm
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: disallow access to unknown MSRs
Message-Id: <E1kI8cF-0007X2-Gm@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 10:55:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 322ec7c89f6640ee2a99d1040b6f786cf04872cf
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 12:42:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:42:58 2020 +0200

    x86/pv: disallow access to unknown MSRs
    
    Change the catch-all behavior for MSR not explicitly handled. Instead
    of allow full read-access to the MSR space and silently dropping
    writes return an exception when the MSR is not explicitly handled.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/pv/emul-priv-op.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index c6fbf8f92d..d793eed401 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -988,9 +988,10 @@ static int read_msr(unsigned int reg, uint64_t *val,
         }
         /* fall through */
     default:
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", reg);
+        break;
+
     normal:
-        /* Everyone can read the MSR space. */
-        /* gdprintk(XENLOG_WARNING, "Domain attempted RDMSR %08x\n", reg); */
         if ( rdmsr_safe(reg, *val) )
             break;
         return X86EMUL_OKAY;
@@ -1155,14 +1156,15 @@ static int write_msr(unsigned int reg, uint64_t val,
         }
         /* fall through */
     default:
-        if ( rdmsr_safe(reg, temp) )
-            break;
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 reg, val);
+        break;
 
-        if ( val != temp )
     invalid:
-            gdprintk(XENLOG_WARNING,
-                     "Domain attempted WRMSR %08x from 0x%016"PRIx64" to 0x%016"PRIx64"\n",
-                     reg, temp, val);
+        gdprintk(XENLOG_WARNING,
+                 "Domain attempted WRMSR 0x%08x from 0x%016"PRIx64" to 0x%016"PRIx64"\n",
+                 reg, temp, val);
         return X86EMUL_OKAY;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 10:55:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 10:55:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI8cS-0003SM-At; Tue, 15 Sep 2020 10:55:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI8cQ-0003SC-NS
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:26 +0000
X-Inumbo-ID: cb28f281-9493-4f8b-a5f7-d55d082bf373
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cb28f281-9493-4f8b-a5f7-d55d082bf373;
 Tue, 15 Sep 2020 10:55:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=b9WKroEjQA/FRa/qUVMZs+XA27ViPZlKBBaD8twbOVo=; b=VJPb7/tWs5iIuB9d5Cs1rwpi8M
 BaqfRvd50EmhJYEmr0DtcGBUcN6/0n+B3QAhlVQoyWlV6jW1goGrJpW/xhfnRWWEY6XJS2Dy2OeCh
 vWKbNZFk7DGs8xBgDmXvNHer2V5m7ll2vPPn7OykzcDhgFY2OBTLdAHkriQFrGDNry1w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cP-00089Z-M0
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cP-0007Xw-LD
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/hvm: disallow access to unknown MSRs
Message-Id: <E1kI8cP-0007Xw-LD@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 10:55:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 84e848fd7a162f669cf8248ce502ca864f869447
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 15 12:43:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:43:32 2020 +0200

    x86/hvm: disallow access to unknown MSRs
    
    Change the catch-all behavior for MSR not explicitly handled. Instead
    of allow full read-access to the MSR space and silently dropping
    writes return an exception when the MSR is not explicitly handled.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    [remove rdmsr_safe from default case in svm_msr_read_intercept]
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/svm/svm.c | 10 ++++------
 xen/arch/x86/hvm/vmx/vmx.c | 16 ++++------------
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index e14c0cce30..136445972e 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1961,8 +1961,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         break;
 
     default:
-        if ( rdmsr_safe(msr, *msr_content) == 0 )
-            break;
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr);
         goto gpf;
     }
 
@@ -2147,10 +2146,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         break;
 
     default:
-        /* Match up with the RDMSR side; ultimately this should go away. */
-        if ( rdmsr_safe(msr, msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 msr, msr_content);
         goto gpf;
     }
 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 709ea149d1..a3aadce4d8 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3015,9 +3015,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
             break;
         }
 
-        if ( rdmsr_safe(msr, *msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr);
         goto gp_fault;
     }
 
@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         __vmwrite(GUEST_IA32_DEBUGCTL, msr_content);
         break;
 
-    case MSR_IA32_FEATURE_CONTROL:
-    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
-        /* None of these MSRs are writeable. */
-        goto gp_fault;
-
     case MSR_IA32_MISC_ENABLE:
         /*
          * Silently drop writes that don't change the reported value: At least
@@ -3324,10 +3317,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
              is_last_branch_msr(msr) )
             break;
 
-        /* Match up with the RDMSR side; ultimately this should go away. */
-        if ( rdmsr_safe(msr, msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 msr, msr_content);
         goto gp_fault;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 10:55:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 10:55:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kI8cb-0003TO-CY; Tue, 15 Sep 2020 10:55:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kI8ca-0003TG-ML
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:36 +0000
X-Inumbo-ID: e0e94279-9174-4eee-bdb2-cbf24d243d34
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e0e94279-9174-4eee-bdb2-cbf24d243d34;
 Tue, 15 Sep 2020 10:55:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=zNClSXGIztGr/j7Q4O9jB4x7ZP5QQp7D058M1SPApxs=; b=QFYSphn/FCIh0aKVp2+Ge0IBw6
 bf/ah2mkwtwjIuhhCLMMAnSaTWfdLuiyAcufE4EuiSEkWHvKLM8xHJbHB8683ljO7dg6e8qBskTiE
 Ku39AFAi5b8Vbb/K4yoSEhPQo5+e+olgmy34bO/Lp6SxoyQlqYp7pUb6Bmy/0H4MMuqA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cZ-00089j-Q1
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kI8cZ-0007Yt-O9
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 10:55:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/msr: drop compatibility #GP handling in guest_{rd,
 wr}msr()
Message-Id: <E1kI8cZ-0007Yt-O9@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 10:55:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 51526576219f122ec7ccfd55dea95afbca70d330
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 15 12:44:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:44:01 2020 +0200

    x86/msr: drop compatibility #GP handling in guest_{rd,wr}msr()
    
    Now that the main PV/HVM MSR handlers raise #GP for all unknown MSRs, there is
    no need to special case these MSRs any more.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msr.c | 46 ----------------------------------------------
 1 file changed, 46 deletions(-)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 79fbb9e940..81b34fb212 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -175,29 +175,6 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
 
     switch ( msr )
     {
-    case MSR_AMD_PATCHLOADER:
-    case MSR_IA32_UCODE_WRITE:
-    case MSR_PRED_CMD:
-    case MSR_FLUSH_CMD:
-        /* Write-only */
-    case MSR_TEST_CTRL:
-    case MSR_CORE_CAPABILITIES:
-    case MSR_TSX_FORCE_ABORT:
-    case MSR_TSX_CTRL:
-    case MSR_MCU_OPT_CTRL:
-    case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7):
-    case MSR_U_CET:
-    case MSR_S_CET:
-    case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE:
-    case MSR_AMD64_LWP_CFG:
-    case MSR_AMD64_LWP_CBADDR:
-    case MSR_PPIN_CTL:
-    case MSR_PPIN:
-    case MSR_AMD_PPIN_CTL:
-    case MSR_AMD_PPIN:
-        /* Not offered to guests. */
-        goto gp_fault;
-
     case MSR_IA32_FEATURE_CONTROL:
         if ( !cp->basic.vmx && !vmce_has_lmce(v) )
             goto gp_fault;
@@ -364,29 +341,6 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
     {
         uint64_t rsvd;
 
-    case MSR_IA32_PLATFORM_ID:
-    case MSR_CORE_CAPABILITIES:
-    case MSR_INTEL_CORE_THREAD_COUNT:
-    case MSR_INTEL_PLATFORM_INFO:
-    case MSR_ARCH_CAPABILITIES:
-        /* Read-only */
-    case MSR_TEST_CTRL:
-    case MSR_TSX_FORCE_ABORT:
-    case MSR_TSX_CTRL:
-    case MSR_MCU_OPT_CTRL:
-    case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7):
-    case MSR_U_CET:
-    case MSR_S_CET:
-    case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE:
-    case MSR_AMD64_LWP_CFG:
-    case MSR_AMD64_LWP_CBADDR:
-    case MSR_PPIN_CTL:
-    case MSR_PPIN:
-    case MSR_AMD_PPIN_CTL:
-    case MSR_AMD_PPIN:
-        /* Not offered to guests. */
-        goto gp_fault;
-
     case MSR_AMD_PATCHLEVEL:
         BUILD_BUG_ON(MSR_IA32_UCODE_REV != MSR_AMD_PATCHLEVEL);
         /*
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHdQ-0007kV-Gr; Tue, 15 Sep 2020 20:33:04 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHdP-0007kQ-Dn
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:03 +0000
X-Inumbo-ID: 16b120ae-ed2c-46a1-9488-0ecd14c183a3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 16b120ae-ed2c-46a1-9488-0ecd14c183a3;
 Tue, 15 Sep 2020 20:33:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=4lh7610tVR2DpgbF6uvM1Bn/w2wF/LPJAy+KleS4Aq4=; b=kRyw+JGffu2wi9gXQzEtwkr6me
 SnvSXBJ/R0dHlvPrU0q9F/AVAtQzrj5scd2P5nwVGJ6QbUQL5cVB3bCtof2EULsIry6Jy7QK2Xvr6
 NAPjW6SWgHMY7J4eya/DFZBRFelS/RNcfddFvH9d3RVQ0PgbVnBP9FRmgm4tD5DwaeKE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdO-00043s-BN
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdO-0002cp-9u
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86/ioapic: Fix fixmap error path logic in
 ioapic_init_mappings()
Message-Id: <E1kIHdO-0002cp-9u@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0861885b5f88213ac393053f496b98f05085577c
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:48:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:48:57 2020 +0200

    x86/ioapic: Fix fixmap error path logic in ioapic_init_mappings()
    
    In the case that bad_ioapic_register() fails, the current position of idx++
    means that clear_fixmap(idx) will be called with the wrong index, and not
    clean up the mapping just created.
    
    Increment idx as part of the loop, rather than midway through the loop body.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: b4175c6693e089ffcd77cd1ea388e76e67d36d57
    master date: 2020-08-05 17:35:11 +0100
---
 xen/arch/x86/io_apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 97cb2d154a..e710827dcf 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -2542,7 +2542,7 @@ void __init init_ioapic_mappings(void)
 
     if ( smp_found_config )
         nr_irqs_gsi = 0;
-    for ( i = 0; i < nr_ioapics; i++ )
+    for ( i = 0; i < nr_ioapics; i++, idx++ )
     {
         if ( smp_found_config )
         {
@@ -2565,7 +2565,6 @@ void __init init_ioapic_mappings(void)
         set_fixmap_nocache(idx, ioapic_phys);
         apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
                     __fix_to_virt(idx), ioapic_phys);
-        idx++;
 
         if ( bad_ioapic_register(i) )
         {
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHda-0007kz-IO; Tue, 15 Sep 2020 20:33:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHdZ-0007ks-9D
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:13 +0000
X-Inumbo-ID: fb9d091b-3961-4d60-85c0-f5fcf6c0ea15
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fb9d091b-3961-4d60-85c0-f5fcf6c0ea15;
 Tue, 15 Sep 2020 20:33:12 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=VzgobS5cI4NvtcdrBEJBJVI1+PUMLAeZmc6UsCanZeg=; b=hCt4Dp1BuTJNZpVPNOGfdNX6zx
 RSYU1eSqymE2cRfC8gMHgteDXx2zI/XKK4j9OqfQJJ6bc3kWOekR0AI454BbjQgYKV4JeUD2o18i4
 aN4NUm0qAcDczaYIL8/bkxHoV9hfvlsi+n84ogLqibZkowfuIevLDVeXdt1irtd5I/Zs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdY-00044N-EU
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:12 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdY-0002dS-DY
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86: use constant flags for section .init.rodata
Message-Id: <E1kIHdY-0002dS-DY@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a7f0434093f52768e333b64b73c1b02fa0b310fb
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:49:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:49:52 2020 +0200

    x86: use constant flags for section .init.rodata
    
    LLVM 11 complains with:
    
    <instantiation>:1:1: error: changed section flags for .init.rodata, expected: 0x2
    .pushsection .init.rodata
    ^
    <instantiation>:30:9: note: while in macro instantiation
            entrypoint 0
            ^
    entry.S:979:9: note: while in macro instantiation
            .rept 256
            ^
    
    And:
    
    entry.S:1015:9: error: changed section flags for .init.rodata, expected: 0x2
            .section .init.rodata
            ^
    
    Fix it by explicitly using the same flags and type in all the
    instances.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    master commit: d2770047a277ccdc7924fb99d1b051eeb0d5a90f
    master date: 2020-08-27 09:53:46 +0200
---
 xen/arch/x86/x86_64/entry.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index c7cfcf9199..24731eeb37 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -914,7 +914,7 @@ GLOBAL(trap_nop)
 GLOBAL(autogen_entrypoints)
         /* pop into the .init.rodata section and record an entry point. */
         .macro entrypoint ent
-        .pushsection .init.rodata
+        .pushsection .init.rodata, "a", @progbits
         .quad \ent
         .popsection
         .endm
@@ -958,5 +958,5 @@ autogen_stubs: /* Automatically generated stubs. */
         vec = vec + 1
         .endr
 
-        .section .init.rodata
+        .section .init.rodata, "a", @progbits
         .size autogen_entrypoints, . - autogen_entrypoints
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:24 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHdk-0007mD-Jw; Tue, 15 Sep 2020 20:33:24 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHdj-0007m5-HV
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:23 +0000
X-Inumbo-ID: f2e805b8-f065-4f12-8c94-74a6f748825c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f2e805b8-f065-4f12-8c94-74a6f748825c;
 Tue, 15 Sep 2020 20:33:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=FwFHTFbFai8POBG9T2X6KvpB6BH+HWgIqYC0qqOGNgY=; b=fbKezdi1B8pvRPhjHLke10HmVE
 /+b4Eex95VYWH0B5+bN2EXCKoJK2usCXDCxsZwzxmVcjfBtEcbIx2ptigmK1B/gpX/RVLZMOv6VhQ
 +WxQd/40Ya6aNPam0Gtx3H54Lm/6f1pBu/EAajLDZK09SyZ3+Cu0bxRY6VvcCaf/Jd0w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdi-00044d-Hi
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:22 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHdi-0002dx-Gt
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:22 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86: Begin to introduce support for MSR_ARCH_CAPS
Message-Id: <E1kIHdi-0002dx-Gt@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:22 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ac4ec487e086dc9ed00f1c230df8f1621e536c5a
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:50:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:50:26 2020 +0200

    x86: Begin to introduce support for MSR_ARCH_CAPS
    
    ... including serialisation/deserialisation logic and unit tests.
    
    There is no current way to configure this MSR correctly for guests.
    The toolstack side this logic needs building, which is far easier to
    do with it in place.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e32605b07ef2e01c9d05da9b2d5d7b8f9a5c7c1b
    master date: 2020-08-27 12:48:46 +0100
---
 tools/tests/cpu-policy/test-cpu-policy.c    |  5 +++++
 xen/arch/x86/msr.c                          |  6 ++++--
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 xen/include/xen/lib/x86/msr.h               | 24 +++++++++++++++++++++++-
 xen/lib/x86/msr.c                           |  2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index fe8cdf6ea9..124eec21da 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -328,6 +328,11 @@ static void test_msr_deserialise_failure(void)
             .msr = { .idx = 0xce, .val = ~0ull },
             .rc = -EOVERFLOW,
         },
+        {
+            .name = "truncated val",
+            .msr = { .idx = 0x10a, .val = ~0ull },
+            .rc = -EOVERFLOW,
+        },
     };
 
     printf("Testing MSR deserialise failure:\n");
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 6cbc078d73..9caa387eda 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -183,8 +183,10 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         break;
 
     case MSR_ARCH_CAPABILITIES:
-        /* Not implemented yet. */
-        goto gp_fault;
+        if ( !cp->feat.arch_caps )
+            goto gp_fault;
+        *val = mp->arch_caps.raw;
+        break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
         *val = msrs->misc_features_enables.raw;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index a2482c3627..3162ee0378 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -259,7 +259,7 @@ XEN_CPUFEATURE(CET_IBT,       9*32+20) /*   CET - Indirect Branch Tracking */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */
-XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*   IA32_ARCH_CAPABILITIES MSR */
+XEN_CPUFEATURE(ARCH_CAPS,     9*32+29) /*!  IA32_ARCH_CAPABILITIES MSR */
 XEN_CPUFEATURE(SSBD,          9*32+31) /*A  MSR_SPEC_CTRL.SSBD available */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:1.eax, word 10 */
diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h
index 203c713320..48ba4a59c0 100644
--- a/xen/include/xen/lib/x86/msr.h
+++ b/xen/include/xen/lib/x86/msr.h
@@ -3,7 +3,7 @@
 #define XEN_LIB_X86_MSR_H
 
 /* Maximum number of MSRs written when serialising msr_policy. */
-#define MSR_MAX_SERIALISED_ENTRIES 1
+#define MSR_MAX_SERIALISED_ENTRIES 2
 
 /* MSR policy object for shared per-domain MSRs */
 struct msr_policy
@@ -23,6 +23,28 @@ struct msr_policy
             bool cpuid_faulting:1;
         };
     } platform_info;
+
+    /*
+     * 0x0000010a - MSR_ARCH_CAPABILITIES
+     *
+     * This is an Intel-only MSR, which provides miscellaneous enumeration,
+     * including those which indicate that microarchitectrual sidechannels are
+     * fixed in hardware.
+     */
+    union {
+        uint32_t raw;
+        struct {
+            bool rdcl_no:1;
+            bool ibrs_all:1;
+            bool rsba:1;
+            bool skip_l1dfl:1;
+            bool ssb_no:1;
+            bool mds_no:1;
+            bool if_pschange_mc_no:1;
+            bool tsx_ctrl:1;
+            bool taa_no:1;
+        };
+    } arch_caps;
 };
 
 #ifdef __XEN__
diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c
index 171abf7008..7d71e92a38 100644
--- a/xen/lib/x86/msr.c
+++ b/xen/lib/x86/msr.c
@@ -39,6 +39,7 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,
     })
 
     COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->platform_info.raw);
+    COPY_MSR(MSR_ARCH_CAPABILITIES,   p->arch_caps.raw);
 
 #undef COPY_MSR
 
@@ -99,6 +100,7 @@ int x86_msr_copy_from_buffer(struct msr_policy *p,
 })
 
         case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break;
+        case MSR_ARCH_CAPABILITIES:   ASSIGN(arch_caps.raw);     break;
 
 #undef ASSIGN
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:34 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHdu-0007nR-Lc; Tue, 15 Sep 2020 20:33:34 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHdt-0007nF-Fi
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:33 +0000
X-Inumbo-ID: 18583ea3-6f7f-4b5e-b7ef-a5f08ce51e0f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 18583ea3-6f7f-4b5e-b7ef-a5f08ce51e0f;
 Tue, 15 Sep 2020 20:33:32 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=qB9fKRjENbM5e9co59nD3KpN3wG0a4JEl43idf/K88I=; b=omjAGekGBNGrcy6beQaul4R0JU
 5Wn5SiyK9G8L0+jxI0ggIT4APwkFccIurzDo+GVWflzza37dxBM7jN3ZPZjllVoep7yLKFCVIbN7A
 rbLlzJe2r3KEMY7VKGN7pWYSPBzwQQ8GagaNUGrVrtpiloLfISSWSe5DRtK6YB7e4a08=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHds-00044k-Kg
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:32 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHds-0002eV-Jv
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:32 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86/intel: Expose MSR_ARCH_CAPS to dom0
Message-Id: <E1kIHds-0002eV-Jv@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:32 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b9083432f1d40ff1b7b8b9a849a8ec54c4b23c88
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:51:08 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:51:08 2020 +0200

    x86/intel: Expose MSR_ARCH_CAPS to dom0
    
    The overhead of (the lack of) MDS_NO alone has been measured at 30% on some
    workloads.  While we're not in a position yet to offer MSR_ARCH_CAPS generally
    to guests, dom0 doesn't migrate, so we can pass a subset of hardware values
    straight through.
    
    This will cause PVH dom0's not to use KPTI by default, and all dom0's not to
    use VERW flushing by default, and to use eIBRS in preference to retpoline on
    recent Intel CPUs.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: e46474278a0e87e2b32ad5dd5fc20e8d2cb0688b
    master date: 2020-08-31 13:43:26 +0100
---
 xen/arch/x86/cpuid.c |  8 ++++++++
 xen/arch/x86/msr.c   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index a887f38d7f..27132f91a6 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -627,6 +627,14 @@ int init_domain_cpuid_policy(struct domain *d)
 
     recalculate_cpuid_policy(d);
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+        p->feat.arch_caps = true;
+
     return 0;
 }
 
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 9caa387eda..875ac39d30 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -96,6 +96,22 @@ int init_domain_msr_policy(struct domain *d)
     if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
         mp->platform_info.cpuid_faulting = false;
 
+    /*
+     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
+     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
+     * domain policy logic gains a better understanding of MSRs.
+     */
+    if ( is_hardware_domain(d) && boot_cpu_has(X86_FEATURE_ARCH_CAPS) )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        mp->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_TAA_NO);
+    }
+
     d->arch.msr = mp;
 
     return 0;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHe4-0007ot-Vh; Tue, 15 Sep 2020 20:33:44 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHe3-0007ob-LU
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:43 +0000
X-Inumbo-ID: 91448b46-b9bb-4fdd-9856-7401c8b36f10
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 91448b46-b9bb-4fdd-9856-7401c8b36f10;
 Tue, 15 Sep 2020 20:33:42 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=AS3Ga6KYD5AzoIUpLpaWY8nZkpQxNf0F2WRxGV9d0KY=; b=V6AkNJWLJN7uX033XCj8/cmFeW
 0w+MoOp0phTznfmck4q1lIF8aN2gFTApoD4VAKiWx0ebwSIBLIT0ephO7fXRO1ugfszq6wT863yen
 vq27+jEHrkAimEfnDXkLjZru6F0pM2Wq1HgF4zNutxzxRW7U3E2noVi/qLLZMvHsEI5c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHe2-00044y-Nk
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:42 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHe2-0002ez-Mp
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:42 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
Message-Id: <E1kIHe2-0002ez-Mp@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:42 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 64690393a81c96296dbde5b865460144a86290c3
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:51:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:51:43 2020 +0200

    x86/pv: Fix multiple bugs with SEGBASE_GS_USER_SEL
    
    The logic takes the segment selector unmodified from guest context.  This
    allowed the guest to load DPL0 descriptors into %gs.  Fix up the RPL for
    non-NUL selectors to be 3.
    
    Xen's context switch logic skips saving the inactive %gs base, as it cannot be
    modified by the guest behind Xen's back.  This depends on Xen caching updates
    to the inactive base, which is was missing from this path.
    
    The consequence is that, following SEGBASE_GS_USER_SEL, the next context
    switch will restore the stale inactive %gs base, and corrupt vcpu state.
    
    Rework the hypercall to update the cached idea of gs_base_user, and fix the
    behaviour in the case of the AMD NUL selector bug to always zero the segment
    base.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: afe018e041ec112d90a8b4e6ed607d22aa06f280
    master date: 2020-08-31 14:21:46 +0100
---
 xen/arch/x86/x86_64/mm.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 8ea09ecc30..27fd0d5fbf 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1056,17 +1056,54 @@ long do_set_segment_base(unsigned int which, unsigned long base)
         break;
 
     case SEGBASE_GS_USER_SEL:
-        __asm__ __volatile__ (
-            "     swapgs              \n"
-            "1:   movl %k0,%%gs       \n"
-            "    "safe_swapgs"        \n"
-            ".section .fixup,\"ax\"   \n"
-            "2:   xorl %k0,%k0        \n"
-            "     jmp  1b             \n"
-            ".previous                \n"
-            _ASM_EXTABLE(1b, 2b)
-            : "+r" (base) );
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
         break;
+    }
 
     default:
         ret = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:33:56 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:33:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHeG-0007qv-37; Tue, 15 Sep 2020 20:33:56 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHeE-0007qe-Jb
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:54 +0000
X-Inumbo-ID: 4e929dca-9201-45b0-af7b-0dc012a20a89
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4e929dca-9201-45b0-af7b-0dc012a20a89;
 Tue, 15 Sep 2020 20:33:53 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=3A/FkbS4P68fQOLaM+dyEHArpxMvqupf+gA6/JXeIHc=; b=ISFsH+ANcCoPiixPy/2n21mfz1
 mGzk7RgO6M5Mx+Tsou7q1Ihan4AG764ionLOZP9Lig1pKJUpFyyENbSn/m6qS2h1zy8aFLSUauvgT
 fQHuZhElN+DgsrxXQm0qsQ79bAR8xT+c2XJXg79DGFFbMtKp6DCdjr4HRTzCwbgnKpGM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHeC-000457-Rk
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:52 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHeC-0002fY-QM
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:33:52 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86/pv: Fix consistency of 64bit segment bases
Message-Id: <E1kIHeC-0002fY-QM@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:33:52 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 761e8df102594da97cc32a895daa44386ee9476e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:52:35 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:52:35 2020 +0200

    x86/pv: Fix consistency of 64bit segment bases
    
    The comments in save_segments(), _toggle_guest_pt() and write_cr() are false.
    The %fs and %gs bases can be updated at any time by the guest.
    
    As a consequence, Xen's fs_base/etc tracking state is always stale when the
    vcpu is in context, and must not be used to complete MSR_{FS,GS}_BASE reads, etc.
    
    In particular, a sequence such as:
    
      wrmsr(MSR_FS_BASE, 0x1ull << 32);
      write_fs(__USER_DS);
      base = rdmsr(MSR_FS_BASE);
    
    will return the stale base, not the new base.  This may cause guest a guest
    kernel's context switching of userspace to malfunction.
    
    Therefore:
     * Update save_segments(), _toggle_guest_pt() and read_msr() to always read
       the segment bases from hardware.
     * Update write_cr(), write_msr() and do_set_segment_base() to not not waste
       time caching data which is instantly going to become stale again.
     * Provide comments explaining when the tracking state is and isn't stale.
    
    This bug has been present for 14 years, but several bugfixes since have built
    on and extended the original flawed logic.
    
    Fixes: ba9adb737ba ("Apply stricter checking to RDMSR/WRMSR emulations.")
    Fixes: c42494acb2f ("x86: fix FS/GS base handling when using the fsgsbase feature")
    Fixed: eccc170053e ("x86/pv: Don't have %cr4.fsgsbase active behind a guest kernels back")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: a5eaac9245f4f382a3cd0e9710e9d1cba7db20e4
    master date: 2020-09-07 11:32:34 +0100
---
 xen/arch/x86/domain.c          | 21 ++++++++++++++++-----
 xen/arch/x86/pv/domain.c       | 19 +++++++++++--------
 xen/arch/x86/pv/emul-priv-op.c | 19 ++-----------------
 xen/arch/x86/x86_64/mm.c       |  6 ------
 xen/include/asm-x86/domain.h   | 19 ++++++++++++++++++-
 5 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index a905aec8e1..2a2327580e 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1546,6 +1546,16 @@ static void load_segments(struct vcpu *n)
     }
 }
 
+/*
+ * Record all guest segment state.  The guest can load segment selectors
+ * without trapping, which will also alter the 64bit FS/GS bases.  Arbitrary
+ * changes to bases can also be made with the WR{FS,GS}BASE instructions, when
+ * enabled.
+ *
+ * Guests however cannot use SWAPGS, so there is no mechanism to modify the
+ * inactive GS base behind Xen's back.  Therefore, Xen's copy of the inactive
+ * GS base is still accurate, and doesn't need reading back from hardware.
+ */
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
@@ -1556,14 +1566,15 @@ static void save_segments(struct vcpu *v)
     regs->fs = read_sreg(fs);
     regs->gs = read_sreg(gs);
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( (read_cr4() & X86_CR4_FSGSBASE) && !is_pv_32bit_vcpu(v) )
+    if ( !is_pv_32bit_vcpu(v) )
     {
-        v->arch.pv.fs_base = __rdfsbase();
+        unsigned long gs_base = rdgsbase();
+
+        v->arch.pv.fs_base = rdfsbase();
         if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
+            v->arch.pv.gs_base_kernel = gs_base;
         else
-            v->arch.pv.gs_base_user = __rdgsbase();
+            v->arch.pv.gs_base_user = gs_base;
     }
 
     if ( regs->ds )
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 3308b6b7d4..aea8d6b2b9 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -408,16 +408,19 @@ static void _toggle_guest_pt(struct vcpu *v)
 
 void toggle_guest_mode(struct vcpu *v)
 {
+    unsigned long gs_base;
+
     ASSERT(!is_pv_32bit_vcpu(v));
 
-    /* %fs/%gs bases can only be stale if WR{FS,GS}BASE are usable. */
-    if ( read_cr4() & X86_CR4_FSGSBASE )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv.gs_base_user = __rdgsbase();
-    }
+    /*
+     * Update the cached value of the GS base about to become inactive, as a
+     * subsequent context switch won't bother re-reading it.
+     */
+    gs_base = rdgsbase();
+    if ( v->arch.flags & TF_kernel_mode )
+        v->arch.pv.gs_base_kernel = gs_base;
+    else
+        v->arch.pv.gs_base_user = gs_base;
     asm volatile ( "swapgs" );
 
     _toggle_guest_pt(v);
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 90693fe9ee..9a5b3edfae 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -757,17 +757,6 @@ static int write_cr(unsigned int reg, unsigned long val,
     }
 
     case 4: /* Write CR4 */
-        /*
-         * If this write will disable FSGSBASE, refresh Xen's idea of the
-         * guest bases now that they can no longer change.
-         */
-        if ( (curr->arch.pv.ctrlreg[4] & X86_CR4_FSGSBASE) &&
-             !(val & X86_CR4_FSGSBASE) )
-        {
-            curr->arch.pv.fs_base = __rdfsbase();
-            curr->arch.pv.gs_base_kernel = __rdgsbase();
-        }
-
         curr->arch.pv.ctrlreg[4] = pv_fixup_guest_cr4(curr, val);
         write_cr4(pv_make_cr4(curr));
         ctxt_switch_levelling(curr);
@@ -816,15 +805,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdfsbase()
-                                               : curr->arch.pv.fs_base;
+        *val = rdfsbase();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = (read_cr4() & X86_CR4_FSGSBASE) ? __rdgsbase()
-                                               : curr->arch.pv.gs_base_kernel;
+        *val = rdgsbase();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -953,14 +940,12 @@ static int write_msr(unsigned int reg, uint64_t val,
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrfsbase(val);
-        curr->arch.pv.fs_base = val;
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
         wrgsbase(val);
-        curr->arch.pv.gs_base_kernel = val;
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 27fd0d5fbf..db4f035d8d 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1027,10 +1027,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-        {
             wrfsbase(base);
-            v->arch.pv.fs_base = base;
-        }
         else
             ret = -EINVAL;
         break;
@@ -1047,10 +1044,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-        {
             wrgsbase(base);
-            v->arch.pv.gs_base_kernel = base;
-        }
         else
             ret = -EINVAL;
         break;
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 81f32bb56d..1cd8743d11 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -505,7 +505,24 @@ struct pv_vcpu
     bool_t syscall32_disables_events;
     bool_t sysenter_disables_events;
 
-    /* Segment base addresses. */
+    /*
+     * 64bit segment bases.
+     *
+     * FS and the active GS are always stale when the vCPU is in context, as
+     * the guest can change them behind Xen's back with MOV SREG, or
+     * WR{FS,GS}BASE on capable hardware.
+     *
+     * The inactive GS base is never stale, as guests can't use SWAPGS to
+     * access it - all modification is performed by Xen either directly
+     * (hypercall, #GP emulation), or indirectly (toggle_guest_mode()).
+     *
+     * The vCPU context switch path is optimised based on this fact, so any
+     * path updating or swapping the inactive base must update the cached
+     * value as well.
+     *
+     * Which GS base is active and inactive depends on whether the vCPU is in
+     * user or kernel context.
+     */
     unsigned long fs_base;
     unsigned long gs_base_kernel;
     unsigned long gs_base_user;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 15 20:34:06 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 15 Sep 2020 20:34:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kIHeQ-0007t5-68; Tue, 15 Sep 2020 20:34:06 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=YJ9H=CY=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kIHeO-0007sv-WE
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:34:05 +0000
X-Inumbo-ID: 8139b32f-0c0e-4463-9a33-1b513188479e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 8139b32f-0c0e-4463-9a33-1b513188479e;
 Tue, 15 Sep 2020 20:34:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Hg6gcEk9H2WfM3hmWuIMyu2b29K9wd02RiXbxUb9LW8=; b=DfC502s4BtOgbrFMaF9yYIA0Ia
 X42C0gnquN2Igbjzix4ILSVmDhhTmP/vRF594SwUSoIT3XUKOSb/idPsLntAZ1g255dK8P+/O0NIY
 EcRg4d1j3hcHQ2JPU6tN0VlLrf/JbhQFKp8bXDY3hDEIAuuQy0cwBXEKGOrukOmXj+fg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHeM-00045V-VQ
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:34:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kIHeM-0002gJ-UW
 for xen-changelog@lists.xenproject.org; Tue, 15 Sep 2020 20:34:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.13] x86/pv: Rewrite segment context switching from
 scratch
Message-Id: <E1kIHeM-0002gJ-UW@xenbits.xenproject.org>
Date: Tue, 15 Sep 2020 20:34:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c663fa577b42e7f4731bb33fc7f94f7ffb05a1ef
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 11 14:53:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:53:37 2020 +0200

    x86/pv: Rewrite segment context switching from scratch
    
    There are multiple bugs with the existing implementation.
    
    On AMD CPUs prior to Zen2, loading a NUL segment selector doesn't clear the
    segment base, which is a problem for 64bit code which typically expects to use
    a NUL %fs/%gs selector.
    
    On a context switch from any PV vcpu, to a 64bit PV vcpu with an %fs/%gs
    selector which faults, the fixup logic loads NUL, and the guest is entered at
    the failsafe callback with the stale base.
    
    Alternatively, a PV context switch sequence of 64 (NUL, non-zero base) =>
    32 (NUL) => 64 (NUL, zero base) will similarly cause Xen to enter the guest
    with a stale base.
    
    Both of these corner cases manifest as state corruption in the final vcpu.
    However, damage is limited to to 64bit code expecting to use Thread Local
    Storage with a base pointer of 0, which doesn't occur by default.
    
    The context switch logic is extremely complicated, and is attempting to
    optimise away loading a NUL selector (which is fast), or writing a 64bit base
    of 0 (which is rare).  Furthermore, it fails to respect Linux's ABI with
    userspace, which manifests as userspace state corruption as far as Linux is
    concerned.
    
    Always restore all selector and base state, in all cases.
    
    Leave a large comment explaining hardware behaviour, and the new ABI
    expectations.  Update the comments in the public headers.
    
    Drop all "segment preloading" to handle the AMD corner case.  It was never
    anything but a waste of time for %ds/%es, and isn't needed now that %fs/%gs
    bases are unconditionally written for 64bit PV guests.  In load_segments(),
    store the result of is_pv_32bit_vcpu() as it is an expensive predicate now,
    and not used in a way which impacts speculative safety.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Reported-by: Sarah Newman <srn@prgmr.com>
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    
    x86/pv: Fix assertions in svm_load_segs()
    
    OSSTest has shown an assertion failure:
    http://logs.test-lab.xenproject.org/osstest/logs/153906/test-xtf-amd64-amd64-1/serial-rimava1.log
    
    This is because we pass a non-NUL selector into svm_load_segs(), which is
    something we must not do, as this path does not load the attributes/limits
    from the GDT/LDT.
    
    Drop the {fs,gs}_sel parameters from svm_load_segs() and use 0 instead.  This
    is acceptable even for non-zero NUL segments, as it is how the IRET
    instruction behaves in all CPUs.
    
    Only use the svm_load_segs() path when both FS and GS are NUL, which is the
    common case when scheduling a 64bit vcpu with 64bit userspace in context.
    
    Fixes: ad0fd291c5 ("x86/pv: Rewrite segment context switching from scratch")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: ad0fd291c5e79191c2e3c70e43dded569f11a450
    master date: 2020-09-07 11:32:34 +0100
    master commit: 1e2d3be2e516e6f415ca6029f651b76a8563a27c
    master date: 2020-09-08 16:46:31 +0100
---
 xen/arch/x86/domain.c                    | 189 ++++++++++---------------------
 xen/arch/x86/hvm/svm/svm.c               |   9 +-
 xen/include/asm-x86/hvm/svm/svm.h        |   6 +-
 xen/include/public/arch-x86/xen-x86_64.h |   4 +-
 4 files changed, 69 insertions(+), 139 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 2a2327580e..4b5ad0fd17 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1009,13 +1009,9 @@ int arch_set_info_guest(
     if ( !compat )
     {
         v->arch.pv.syscall_callback_eip = c.nat->syscall_callback_eip;
-        /* non-nul selector kills fs_base */
-        v->arch.pv.fs_base =
-            !(v->arch.user_regs.fs & ~3) ? c.nat->fs_base : 0;
+        v->arch.pv.fs_base = c.nat->fs_base;
         v->arch.pv.gs_base_kernel = c.nat->gs_base_kernel;
-        /* non-nul selector kills gs_base_user */
-        v->arch.pv.gs_base_user =
-            !(v->arch.user_regs.gs & ~3) ? c.nat->gs_base_user : 0;
+        v->arch.pv.gs_base_user = c.nat->gs_base_user;
     }
     else
     {
@@ -1326,58 +1322,60 @@ arch_do_vcpu_op(
 }
 
 /*
- * Loading a nul selector does not clear bases and limits on AMD or Hygon
- * CPUs. Be on the safe side and re-initialize both to flat segment values
- * before loading a nul selector.
- */
-#define preload_segment(seg, value) do {              \
-    if ( !((value) & ~3) &&                           \
-         (boot_cpu_data.x86_vendor &                  \
-          (X86_VENDOR_AMD | X86_VENDOR_HYGON)) )      \
-        asm volatile ( "movl %k0, %%" #seg            \
-                       :: "r" (FLAT_USER_DS32) );     \
-} while ( false )
-
-#define loadsegment(seg,value) ({               \
-    int __r = 1;                                \
-    asm volatile (                              \
-        "1: movl %k1,%%" #seg "\n2:\n"          \
-        ".section .fixup,\"ax\"\n"              \
-        "3: xorl %k0,%k0\n"                     \
-        "   movl %k0,%%" #seg "\n"              \
-        "   jmp 2b\n"                           \
-        ".previous\n"                           \
-        _ASM_EXTABLE(1b, 3b)                    \
-        : "=r" (__r) : "r" (value), "0" (__r) );\
-    __r; })
-
-/*
- * save_segments() writes a mask of segments which are dirty (non-zero),
- * allowing load_segments() to avoid some expensive segment loads and
- * MSR writes.
+ * Notes on PV segment handling:
+ *  - 32bit: All data from the GDT/LDT.
+ *  - 64bit: In addition, 64bit FS/GS/GS_KERN bases.
+ *
+ * Linux's ABI with userspace expects to preserve the full selector and
+ * segment base, even sel != NUL, base != GDT/LDT for 64bit code.  Xen must
+ * honour this when context switching, to avoid breaking Linux's ABI.
+ *
+ * Note: It is impossible to preserve a selector value of 1, 2 or 3, as these
+ *       get reset to 0 by an IRET back to guest context.  Code playing with
+ *       arcane corners of x86 get to keep all resulting pieces.
+ *
+ * Therefore, we:
+ *  - Load the LDT.
+ *  - Load each segment selector.
+ *    - Any error loads zero, and triggers a failsafe callback.
+ *  - For 64bit, further load the 64bit bases.
+ *
+ * An optimisation exists on SVM-capable hardware, where we use a VMLOAD
+ * instruction to load the LDT and full FS/GS/GS_KERN data in one go.
+ *
+ * AMD-like CPUs prior to Zen2 do not zero the segment base or limit when
+ * loading a NUL selector.  This is a problem in principle when context
+ * switching to a 64bit guest, as a NUL FS/GS segment is usable and will pick
+ * up the stale base.
+ *
+ * However, it is not an issue in practice.  NUL segments are unusable for
+ * 32bit guests (so any stale base won't be used), and we unconditionally
+ * write the full FS/GS bases for 64bit guests.
  */
-static DEFINE_PER_CPU(unsigned int, dirty_segment_mask);
-#define DIRTY_DS           0x01
-#define DIRTY_ES           0x02
-#define DIRTY_FS           0x04
-#define DIRTY_GS           0x08
-#define DIRTY_FS_BASE      0x10
-#define DIRTY_GS_BASE      0x20
-
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
-    int all_segs_okay = 1;
-    unsigned int dirty_segment_mask, cpu = smp_processor_id();
-    bool fs_gs_done = false;
+    bool compat = is_pv_32bit_vcpu(n);
+    bool all_segs_okay = true, fs_gs_done = false;
 
-    /* Load and clear the dirty segment mask. */
-    dirty_segment_mask = per_cpu(dirty_segment_mask, cpu);
-    per_cpu(dirty_segment_mask, cpu) = 0;
+    /*
+     * Attempt to load @seg with selector @val.  On error, clear
+     * @all_segs_okay in function scope, and load NUL into @sel.
+     */
+#define TRY_LOAD_SEG(seg, val)                          \
+    asm volatile ( "1: mov %k[_val], %%" #seg "\n\t"    \
+                   "2:\n\t"                             \
+                   ".section .fixup, \"ax\"\n\t"        \
+                   "3: xor %k[ok], %k[ok]\n\t"          \
+                   "   mov %k[ok], %%" #seg "\n\t"      \
+                   "   jmp 2b\n\t"                      \
+                   ".previous\n\t"                      \
+                   _ASM_EXTABLE(1b, 3b)                 \
+                   : [ok] "+r" (all_segs_okay)          \
+                   : [_val] "rm" (val) )
 
 #ifdef CONFIG_HVM
-    if ( cpu_has_svm && !is_pv_32bit_vcpu(n) &&
-         !(read_cr4() & X86_CR4_FSGSBASE) && !((uregs->fs | uregs->gs) & ~3) )
+    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
     {
         unsigned long gsb = n->arch.flags & TF_kernel_mode
             ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
@@ -1385,62 +1383,25 @@ static void load_segments(struct vcpu *n)
             ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
 
         fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   uregs->fs, n->arch.pv.fs_base,
-                                   uregs->gs, gsb, gss);
+                                   n->arch.pv.fs_base, gsb, gss);
     }
 #endif
     if ( !fs_gs_done )
-        load_LDT(n);
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_DS) | uregs->ds) )
     {
-        preload_segment(ds, uregs->ds);
-        all_segs_okay &= loadsegment(ds, uregs->ds);
-    }
-
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_ES) | uregs->es) )
-    {
-        preload_segment(es, uregs->es);
-        all_segs_okay &= loadsegment(es, uregs->es);
-    }
+        load_LDT(n);
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_FS) | uregs->fs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(fs, uregs->fs);
-        /* non-nul selector updates fs_base */
-        if ( uregs->fs & ~3 )
-            dirty_segment_mask &= ~DIRTY_FS_BASE;
+        TRY_LOAD_SEG(fs, uregs->fs);
+        TRY_LOAD_SEG(gs, uregs->gs);
     }
 
-    /* Either selector != 0 ==> reload. */
-    if ( unlikely((dirty_segment_mask & DIRTY_GS) | uregs->gs) && !fs_gs_done )
-    {
-        all_segs_okay &= loadsegment(gs, uregs->gs);
-        /* non-nul selector updates gs_base_user */
-        if ( uregs->gs & ~3 )
-            dirty_segment_mask &= ~DIRTY_GS_BASE;
-    }
+    TRY_LOAD_SEG(ds, uregs->ds);
+    TRY_LOAD_SEG(es, uregs->es);
 
-    if ( !fs_gs_done && !is_pv_32bit_vcpu(n) )
+    if ( !fs_gs_done && !compat )
     {
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.fs_base | (dirty_segment_mask & DIRTY_FS_BASE) )
-            wrfsbase(n->arch.pv.fs_base);
-
-        /*
-         * Most kernels have non-zero GS base, so don't bother testing.
-         * (For old AMD hardware this is also a serialising instruction,
-         * avoiding erratum #88.)
-         */
+        wrfsbase(n->arch.pv.fs_base);
         wrgsshadow(n->arch.pv.gs_base_kernel);
-
-        /* This can only be non-zero if selector is NULL. */
-        if ( n->arch.pv.gs_base_user |
-             (dirty_segment_mask & DIRTY_GS_BASE) )
-            wrgsbase(n->arch.pv.gs_base_user);
+        wrgsbase(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1559,7 +1520,6 @@ static void load_segments(struct vcpu *n)
 static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
-    unsigned int dirty_segment_mask = 0;
 
     regs->ds = read_sreg(ds);
     regs->es = read_sreg(es);
@@ -1576,35 +1536,6 @@ static void save_segments(struct vcpu *v)
         else
             v->arch.pv.gs_base_user = gs_base;
     }
-
-    if ( regs->ds )
-        dirty_segment_mask |= DIRTY_DS;
-
-    if ( regs->es )
-        dirty_segment_mask |= DIRTY_ES;
-
-    if ( regs->fs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_FS;
-        /* non-nul selector kills fs_base */
-        if ( regs->fs & ~3 )
-            v->arch.pv.fs_base = 0;
-    }
-    if ( v->arch.pv.fs_base )
-        dirty_segment_mask |= DIRTY_FS_BASE;
-
-    if ( regs->gs || is_pv_32bit_vcpu(v) )
-    {
-        dirty_segment_mask |= DIRTY_GS;
-        /* non-nul selector kills gs_base_user */
-        if ( regs->gs & ~3 )
-            v->arch.pv.gs_base_user = 0;
-    }
-    if ( v->arch.flags & TF_kernel_mode ? v->arch.pv.gs_base_kernel
-                                        : v->arch.pv.gs_base_user )
-        dirty_segment_mask |= DIRTY_GS_BASE;
-
-    this_cpu(dirty_segment_mask) = dirty_segment_mask;
 }
 
 void paravirt_ctxt_switch_from(struct vcpu *v)
@@ -1813,8 +1744,8 @@ static void __context_switch(void)
 #if defined(CONFIG_PV) && defined(CONFIG_HVM)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
-         !is_idle_domain(nd) && !(read_cr4() & X86_CR4_FSGSBASE) )
-        svm_load_segs(0, 0, 0, 0, 0, 0, 0);
+         !is_idle_domain(nd) )
+        svm_load_segs(0, 0, 0, 0, 0);
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 8317ef8fb0..fb73319cae 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1522,8 +1522,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 
 #ifdef CONFIG_PV
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
 {
     unsigned int cpu = smp_processor_id();
@@ -1560,14 +1559,12 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    ASSERT(!(fs_sel & ~3));
-    vmcb->fs.sel = fs_sel;
+    vmcb->fs.sel = 0;
     vmcb->fs.attr = 0;
     vmcb->fs.limit = 0;
     vmcb->fs.base = fs_base;
 
-    ASSERT(!(gs_sel & ~3));
-    vmcb->gs.sel = gs_sel;
+    vmcb->gs.sel = 0;
     vmcb->gs.attr = 0;
     vmcb->gs.limit = 0;
     vmcb->gs.base = gs_base;
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index 63eebab48a..52752fe5ab 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -52,10 +52,12 @@ void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 /*
  * PV context switch helper. Calls with zero ldt_base request a prefetch of
  * the VMCB area to be loaded from, instead of an actual load of state.
+ *
+ * Must only be used for NUL FS/GS, as the segment attributes/limits are not
+ * read from the GDT/LDT.
  */
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
-                   unsigned int fs_sel, unsigned long fs_base,
-                   unsigned int gs_sel, unsigned long gs_base,
+                   unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
 
 extern u32 svm_feature_flags;
diff --git a/xen/include/public/arch-x86/xen-x86_64.h b/xen/include/public/arch-x86/xen-x86_64.h
index 342eabc957..40aed14366 100644
--- a/xen/include/public/arch-x86/xen-x86_64.h
+++ b/xen/include/public/arch-x86/xen-x86_64.h
@@ -203,8 +203,8 @@ struct cpu_user_regs {
     uint16_t ss, _pad2[3];
     uint16_t es, _pad3[3];
     uint16_t ds, _pad4[3];
-    uint16_t fs, _pad5[3]; /* Non-nul => takes precedence over fs_base.      */
-    uint16_t gs, _pad6[3]; /* Non-nul => takes precedence over gs_base_user. */
+    uint16_t fs, _pad5[3];
+    uint16_t gs, _pad6[3];
 };
 typedef struct cpu_user_regs cpu_user_regs_t;
 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.13


From xen-changelog-bounces@lists.xenproject.org Wed Sep 16 09:22:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 16 Sep 2020 09:22:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kITdj-0006Xx-Lz; Wed, 16 Sep 2020 09:22:11 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=GH6q=CZ=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kITdi-0006Xs-43
 for xen-changelog@lists.xenproject.org; Wed, 16 Sep 2020 09:22:10 +0000
X-Inumbo-ID: 4e30d662-1945-4626-b3a2-96580deb7b69
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4e30d662-1945-4626-b3a2-96580deb7b69;
 Wed, 16 Sep 2020 09:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mp5NwlMCLH6s5X+8jzGBc1NtiviJHfonMCg0ZJo23YE=; b=Og2Ii+FmpHlK1aFyA8AvrFeIUW
 QX0npytkJZcyHvhOQ9j8VdkLGarTTKcHHldlxWBwtxyVRN6u1kQgbzjSXQjrOOtQyTHpAhlTjTAuf
 veTJ5C3p2FTN1Js6clq3rs91RQG2AZbwbSFBIp+XIpNP6qgCuMEA1B4UufEIG3CxaEsI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kITdd-0001kj-Vm
 for xen-changelog@lists.xenproject.org; Wed, 16 Sep 2020 09:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kITdd-0003ok-Sq
 for xen-changelog@lists.xenproject.org; Wed, 16 Sep 2020 09:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] Revert "EFI: free unused boot mem in at least some
 cases"
Message-Id: <E1kITdd-0003ok-Sq@xenbits.xenproject.org>
Date: Wed, 16 Sep 2020 09:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 414d22cc092eab4a5b90d2ce594495733b07c77a
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 16 11:16:41 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 16 11:16:41 2020 +0200

    Revert "EFI: free unused boot mem in at least some cases"
    
    This reverts commit a4cbe0f3b47656ea125922fd48d394731a0163fd,
    which breaks PV shim in a not yet analyzed way.
---
 xen/arch/x86/efi/stub.c   |  6 ------
 xen/arch/x86/setup.c      | 26 +++-----------------------
 xen/arch/x86/tboot.c      | 12 ------------
 xen/common/efi/ebmalloc.c | 31 +++++--------------------------
 xen/include/xen/efi.h     |  1 -
 5 files changed, 8 insertions(+), 68 deletions(-)

diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index 0e01e7322b..c578bffc71 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -52,12 +52,6 @@ bool efi_enabled(unsigned int feature)
 
 void __init efi_init_memory(void) { }
 
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
-{
-    *start = *end = (unsigned long)_end;
-    return false;
-}
-
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
 
 bool efi_rs_using_pgtables(void)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 44c04e2735..4b15e067fa 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -830,7 +830,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
     int i, j, e820_warn = 0, bytes = 0;
-    unsigned long eb_start, eb_end;
     bool acpi_boot_table_init_done = false, relocated = false;
     int ret;
     struct ns16550_defaults ns16550 = {
@@ -1146,8 +1145,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
         /*
          * This needs to remain in sync with xen_in_range() and the
-         * respective reserve_e820_ram() invocation below. No need to
-         * query efi_boot_mem_unused() here, though.
+         * respective reserve_e820_ram() invocation below.
          */
         mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
@@ -1419,18 +1417,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen\n");
 
-    /* FIXME: Putting a hole in .bss would shatter the large page mapping. */
-    if ( using_2M_mapping() )
-        efi_boot_mem_unused(NULL, NULL);
-
     /* This needs to remain in sync with xen_in_range(). */
-    if ( efi_boot_mem_unused(&eb_start, &eb_end) )
-    {
-        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start));
-        reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end));
-    }
-    else
-        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
+    reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1991,7 +1979,7 @@ int __hwdom_init xen_in_range(unsigned long mfn)
     paddr_t start, end;
     int i;
 
-    enum { region_s3, region_ro, region_rw, region_bss, nr_regions };
+    enum { region_s3, region_ro, region_rw, nr_regions };
     static struct {
         paddr_t s, e;
     } xen_regions[nr_regions] __hwdom_initdata;
@@ -2016,14 +2004,6 @@ int __hwdom_init xen_in_range(unsigned long mfn)
         /* hypervisor .data + .bss */
         xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
         xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
-        if ( efi_boot_mem_unused(&start, &end) )
-        {
-            ASSERT(__pa(start) >= xen_regions[region_rw].s);
-            ASSERT(__pa(end) <= xen_regions[region_rw].e);
-            xen_regions[region_rw].e = __pa(start);
-            xen_regions[region_bss].s = __pa(end);
-            xen_regions[region_bss].e = __pa(&__2M_rwdata_end);
-        }
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index aadcce591f..e66b0940c4 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -1,4 +1,3 @@
-#include <xen/efi.h>
 #include <xen/init.h>
 #include <xen/types.h>
 #include <xen/lib.h>
@@ -365,8 +364,6 @@ void tboot_shutdown(uint32_t shutdown_type)
     /* if this is S3 then set regions to MAC */
     if ( shutdown_type == TB_SHUTDOWN_S3 )
     {
-        unsigned long s, e;
-
         /*
          * Xen regions for tboot to MAC. This needs to remain in sync with
          * xen_in_range().
@@ -381,15 +378,6 @@ void tboot_shutdown(uint32_t shutdown_type)
         /* hypervisor .data + .bss */
         g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(&__2M_rwdata_start);
         g_tboot_shared->mac_regions[2].size = __2M_rwdata_end - __2M_rwdata_start;
-        if ( efi_boot_mem_unused(&s, &e) )
-        {
-            g_tboot_shared->mac_regions[2].size =
-                s - (unsigned long)__2M_rwdata_start;
-            g_tboot_shared->mac_regions[3].start = __pa(e);
-            g_tboot_shared->mac_regions[3].size =
-                (unsigned long)__2M_rwdata_end - e;
-            g_tboot_shared->num_mac_regions = 4;
-        }
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/common/efi/ebmalloc.c b/xen/common/efi/ebmalloc.c
index 136838eb8e..c65dbd946f 100644
--- a/xen/common/efi/ebmalloc.c
+++ b/xen/common/efi/ebmalloc.c
@@ -1,6 +1,5 @@
 #include "efi.h"
 #include <xen/init.h>
-#include <xen/mm.h>
 
 #ifdef CONFIG_ARM
 /*
@@ -22,7 +21,7 @@
 
 static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
     ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __read_mostly ebmalloc_allocated;
+static unsigned long __initdata ebmalloc_allocated;
 
 /* EFI boot allocator. */
 void __init *ebmalloc(size_t size)
@@ -37,37 +36,17 @@ void __init *ebmalloc(size_t size)
     return ptr;
 }
 
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
-{
-    if ( !start && !end )
-    {
-        ebmalloc_allocated = sizeof(ebmalloc_mem);
-        return false;
-    }
-
-    *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
-    *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
-
-    return *start < *end;
-}
-
 void __init free_ebmalloc_unused_mem(void)
 {
+#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
     unsigned long start, end;
 
-    if ( !efi_boot_mem_unused(&start, &end) )
-        return;
+    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
 
     destroy_xen_mappings(start, end);
-
-#ifdef CONFIG_X86
-    /*
-     * By reserving the space early in the E820 map, it gets freed way before
-     * we make it here. Don't free the range a 2nd time.
-     */
-#else
     init_xenheap_pages(__pa(start), __pa(end));
-#endif
 
     printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
+#endif
 }
diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h
index 94a7e547f9..44b7d3ec3a 100644
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -33,7 +33,6 @@ struct compat_pf_efi_runtime_call;
 
 bool efi_enabled(unsigned int feature);
 void efi_init_memory(void);
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end);
 bool efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
 void efi_halt_system(void);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 16:44:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 16:44:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJJUV-0006L3-BG; Fri, 18 Sep 2020 16:44:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJJUT-0006Kw-T5
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:05 +0000
X-Inumbo-ID: 163c3a93-4fd3-4ceb-80f8-e872bfac47e1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 163c3a93-4fd3-4ceb-80f8-e872bfac47e1;
 Fri, 18 Sep 2020 16:44:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wqH7kxPxwqyZEvSMyQAIIw9tr9vLG+Kd+EUT1qahF/c=; b=2yWpPvHph6M/nsdzy83EO2RRYQ
 1dpncsNDgLSHrMHCGe0WotaMEooWugBcHyfc4wW7lbtBNnquh5/FczYQO+FzdNM21fHhD8I/G/kfU
 X3uhdkVhcuz7aRXDpaE+KLpDOGKHUarn2ZjL7/fFvQCCGTAbBg+LnG+jhXtgdI9tJiPQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJJUS-0003DC-N5
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJJUS-0006Kx-MD
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: Remove cmpxchg_local() and drop _mb from the
 other helpers
Message-Id: <E1kJJUS-0006Kx-MD@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 16:44:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5a15c8a65f871d2d8bf4f0c01389f8fbb86455d3
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Fri Sep 11 17:06:21 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 18 17:33:01 2020 +0100

    xen/arm: Remove cmpxchg_local() and drop _mb from the other helpers
    
    The current set of helpers are quite confusing to follow as the naming
    is not very consistent.
    
    Given that cmpxchg_local() is not used in Xen, drop it completely.
    Furthermore, adopt a naming with _mb so all names are now consistent.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/include/asm-arm/arm32/cmpxchg.h | 31 +++++++-----------------------
 xen/include/asm-arm/arm64/cmpxchg.h | 38 +++++++++----------------------------
 xen/include/asm-arm/guest_atomics.h |  6 +++---
 3 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 0770f272ee..3ef1e5c632 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -112,23 +112,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
-                                                unsigned long old,
-                                                unsigned long new, int size)
-{
-	unsigned long ret;
-
-	smp_mb();
-	ret = __cmpxchg(ptr, old, new, size);
 	smp_mb();
 
-	return ret;
+	return old;
 }
 
 /*
@@ -141,11 +130,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -157,12 +146,6 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 }
 
 #define cmpxchg(ptr,o,n)						\
-	((__typeof__(*(ptr)))__cmpxchg_mb((ptr),			\
-					  (unsigned long)(o),		\
-					  (unsigned long)(n),		\
-					  sizeof(*(ptr))))
-
-#define cmpxchg_local(ptr,o,n)						\
 	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
 				       (unsigned long)(o),		\
 				       (unsigned long)(n),		\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index fc5c60f0bd..f4a8c1ccba 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -125,23 +125,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
-						unsigned long old,
-						unsigned long new, int size)
-{
-	unsigned long ret;
-
-	smp_mb();
-	ret = __cmpxchg(ptr, old, new, size);
 	smp_mb();
 
-	return ret;
+	return old;
 }
 
 /*
@@ -154,11 +143,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -173,17 +162,8 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 ({ \
 	__typeof__(*(ptr)) __ret; \
 	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg_mb((ptr), (unsigned long)(o), (unsigned long)(n), \
-			     sizeof(*(ptr))); \
-	__ret; \
-})
-
-#define cmpxchg_local(ptr, o, n) \
-({ \
-	__typeof__(*(ptr)) __ret; \
-	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg((ptr), (unsigned long)(o), \
-			  (unsigned long)(n), sizeof(*(ptr))); \
+		__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \
+			  sizeof(*(ptr))); \
 	__ret; \
 })
 
diff --git a/xen/include/asm-arm/guest_atomics.h b/xen/include/asm-arm/guest_atomics.h
index af27cc627b..20347849e5 100644
--- a/xen/include/asm-arm/guest_atomics.h
+++ b/xen/include/asm-arm/guest_atomics.h
@@ -96,14 +96,14 @@ static inline unsigned long __guest_cmpxchg(struct domain *d,
 
     perfc_incr(atomics_guest);
 
-    if ( __cmpxchg_mb_timeout(ptr, &oldval, new, size,
-                              this_cpu(guest_safe_atomic_max)) )
+    if ( __cmpxchg_timeout(ptr, &oldval, new, size,
+                           this_cpu(guest_safe_atomic_max)) )
         return oldval;
 
     perfc_incr(atomics_guest_paused);
 
     domain_pause_nosync(d);
-    oldval = __cmpxchg_mb(ptr, old, new, size);
+    oldval = __cmpxchg(ptr, old, new, size);
     domain_unpause(d);
 
     return oldval;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 16:44:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 16:44:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJJUh-0006N9-LB; Fri, 18 Sep 2020 16:44:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJJUg-0006Mp-2P
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:18 +0000
X-Inumbo-ID: 9cfb18c4-4553-46e7-a900-77ca672f9752
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9cfb18c4-4553-46e7-a900-77ca672f9752;
 Fri, 18 Sep 2020 16:44:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=svA04P5NVwWYg7udAV4S9VvZTgv6AH3vL9KyfjtVmRQ=; b=a+uhADbQBxM0X6anySU6W6gzKc
 gMvf3YCVAO5aO9JpRTNUZMWSaJ/mIxHcjZAY5ne6jojF+rn8Y/mN/hDt1Ti+0EysloUianbRpygxr
 Pu1UNCePiI7WPn9zTkX/FfYS1uYOyyfQN6m3ruv0W5z7PRjg8BxZ+df2U67Uru/yHIRY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJJUc-0003DF-Qz
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJJUc-0006M3-PI
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 16:44:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen: Introduce cmpxchg64() and guest_cmpxchg64()
Message-Id: <E1kJJUc-0006M3-PI@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 16:44:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c729d54331ffb05abe93ed2349377092f134fdbd
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Fri Sep 11 17:06:22 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 18 17:33:01 2020 +0100

    xen: Introduce cmpxchg64() and guest_cmpxchg64()
    
    The IOREQ code is using cmpxchg() with 64-bit value. At the moment, this
    is x86 code, but there is plan to make it common.
    
    To cater 32-bit arch, introduce two new helpers to deal with 64-bit
    cmpxchg().
    
    The Arm 32-bit implementation of cmpxchg64() is based on the __cmpxchg64
    in Linux v5.8 (arch/arm/include/asm/cmpxchg.h).
    
    Note that only guest_cmpxchg64() is introduced on x86 so far.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/include/asm-arm/arm32/cmpxchg.h | 68 +++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/arm64/cmpxchg.h |  5 +++
 xen/include/asm-arm/guest_atomics.h | 22 ++++++++++++
 xen/include/asm-x86/guest_atomics.h |  1 +
 4 files changed, 96 insertions(+)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 3ef1e5c632..b0bd1d8b68 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -87,6 +87,37 @@ __CMPXCHG_CASE(b, 1)
 __CMPXCHG_CASE(h, 2)
 __CMPXCHG_CASE( , 4)
 
+static inline bool __cmpxchg_case_8(volatile uint64_t *ptr,
+			 	    uint64_t *old,
+			 	    uint64_t new,
+			 	    bool timeout,
+				    unsigned int max_try)
+{
+	uint64_t oldval;
+	uint64_t res;
+
+	do {
+		asm volatile(
+		"	ldrexd		%1, %H1, [%3]\n"
+		"	teq		%1, %4\n"
+		"	teqeq		%H1, %H4\n"
+		"	movne		%0, #0\n"
+		"	movne		%H0, #0\n"
+		"	bne		2f\n"
+		"	strexd		%0, %5, %H5, [%3]\n"
+		"2:"
+		: "=&r" (res), "=&r" (oldval), "+Qo" (*ptr)
+		: "r" (ptr), "r" (*old), "r" (new)
+		: "memory", "cc");
+		if (!res)
+			break;
+	} while (!timeout || ((--max_try) > 0));
+
+	*old = oldval;
+
+	return !res;
+}
+
 static always_inline bool __int_cmpxchg(volatile void *ptr, unsigned long *old,
 					unsigned long new, int size,
 					bool timeout, unsigned int max_try)
@@ -145,11 +176,48 @@ static always_inline bool __cmpxchg_timeout(volatile void *ptr,
 	return ret;
 }
 
+/*
+ * The helper may fail to update the memory if the action takes too long.
+ *
+ * @old: On call the value pointed contains the expected old value. It will be
+ * updated to the actual old value.
+ * @max_try: Maximum number of iterations
+ *
+ * The helper will return true when the update has succeeded (i.e no
+ * timeout) and false if the update has failed.
+ */
+static always_inline bool __cmpxchg64_timeout(volatile uint64_t *ptr,
+					      uint64_t *old,
+					      uint64_t new,
+					      unsigned int max_try)
+{
+	bool ret;
+
+	smp_mb();
+	ret = __cmpxchg_case_8(ptr, old, new, true, max_try);
+	smp_mb();
+
+	return ret;
+}
+
 #define cmpxchg(ptr,o,n)						\
 	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
 				       (unsigned long)(o),		\
 				       (unsigned long)(n),		\
 				       sizeof(*(ptr))))
+
+static inline uint64_t cmpxchg64(volatile uint64_t *ptr,
+				 uint64_t old,
+				 uint64_t new)
+{
+	smp_mb();
+	if (!__cmpxchg_case_8(ptr, &old, new, false, 0))
+		ASSERT_UNREACHABLE();
+	smp_mb();
+
+	return old;
+}
+
 #endif
 /*
  * Local variables:
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index f4a8c1ccba..10e4edc022 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -167,6 +167,11 @@ static always_inline bool __cmpxchg_timeout(volatile void *ptr,
 	__ret; \
 })
 
+#define cmpxchg64(ptr, o, n) cmpxchg(ptr, o, n)
+
+#define __cmpxchg64_timeout(ptr, old, new, max_try)	\
+	__cmpxchg_timeout(ptr, old, new, 8, max_try)
+
 #endif
 /*
  * Local variables:
diff --git a/xen/include/asm-arm/guest_atomics.h b/xen/include/asm-arm/guest_atomics.h
index 20347849e5..9e2e96d4ff 100644
--- a/xen/include/asm-arm/guest_atomics.h
+++ b/xen/include/asm-arm/guest_atomics.h
@@ -115,6 +115,28 @@ static inline unsigned long __guest_cmpxchg(struct domain *d,
                                          (unsigned long)(n),\
                                          sizeof (*(ptr))))
 
+static inline uint64_t guest_cmpxchg64(struct domain *d,
+                                       volatile uint64_t *ptr,
+                                       uint64_t old,
+                                       uint64_t new)
+{
+    uint64_t oldval = old;
+
+    perfc_incr(atomics_guest);
+
+    if ( __cmpxchg64_timeout(ptr, &oldval, new,
+                             this_cpu(guest_safe_atomic_max)) )
+        return oldval;
+
+    perfc_incr(atomics_guest_paused);
+
+    domain_pause_nosync(d);
+    oldval = cmpxchg64(ptr, old, new);
+    domain_unpause(d);
+
+    return oldval;
+}
+
 #endif /* _ARM_GUEST_ATOMICS_H */
 /*
  * Local variables:
diff --git a/xen/include/asm-x86/guest_atomics.h b/xen/include/asm-x86/guest_atomics.h
index 029417c8ff..c2dec0d650 100644
--- a/xen/include/asm-x86/guest_atomics.h
+++ b/xen/include/asm-x86/guest_atomics.h
@@ -20,6 +20,7 @@
     ((void)(d), test_and_change_bit(nr, p))
 
 #define guest_cmpxchg(d, ptr, o, n) ((void)(d), cmpxchg(ptr, o, n))
+#define guest_cmpxchg64 guest_cmpxchg
 
 #endif /* _X86_GUEST_ATOMICS_H */
 /*
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMIh-000636-Hj; Fri, 18 Sep 2020 19:44:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMIf-000631-Sw
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:05 +0000
X-Inumbo-ID: 32ca7dff-26d6-423d-ba88-6e8c24d9fe69
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 32ca7dff-26d6-423d-ba88-6e8c24d9fe69;
 Fri, 18 Sep 2020 19:44:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=KGkc4uOimzY3X41kdur78sjuIkbnmlSWTkjmqF3M6Fw=; b=utTV5wkPQC0+xra8kSkoNb5zEX
 Q4kPzbDDKpI+7fTDFKzCprn69h+BYFgOTUfauqjNzrp/Z8HEVSJiEg5dvQ3pase7chykdr6PrbQnL
 T5T06tLU9oo52aCLBFqpINnvVIL/IC6mQWKMliRLzgUzxjBFCbSUoMg2G64CG/u5VvTk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMId-00071A-EL
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:03 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMId-0004Ai-Ax
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:03 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: generate pkg-config files from make variables
Message-Id: <E1kJMId-0004Ai-Ax@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:03 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 52dbd6f07cea7a776ba1fcc76f111c311c8a1412
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:17 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:16 2020 +0000

    tools: generate pkg-config files from make variables
    
    For each library built two variants of pkg-config files are created
    from a per-library template: an "official" one for installation on
    the user's system, and one used for building internal tools, like e.g.
    qemu.
    
    Instead of the template which is looking very similar for all libraries
    generate the pkg-config files directly from make variables.
    
    This will reduce the need to specify some pkg-config file entries in
    the templates, as the contents can easily be generated from available
    data (e.g. "Version:" and "Requires.private:" entries).
    
    Especially the variant used for building internal tools needs to gain
    additional runtime link parameters for the internally used libraries,
    as otherwise those won't be found by the users (e.g. qemu).
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 stubdom/Makefile                                |  1 -
 tools/Rules.mk                                  | 52 ++++++++++++++-----------
 tools/libs/call/xencall.pc.in                   | 10 -----
 tools/libs/devicemodel/xendevicemodel.pc.in     | 10 -----
 tools/libs/evtchn/xenevtchn.pc.in               | 10 -----
 tools/libs/foreignmemory/xenforeignmemory.pc.in | 10 -----
 tools/libs/gnttab/xengnttab.pc.in               | 10 -----
 tools/libs/hypfs/xenhypfs.pc.in                 | 10 -----
 tools/libs/libs.mk                              |  8 ++++
 tools/libs/toolcore/Makefile                    |  1 +
 tools/libs/toolcore/xentoolcore.pc.in           |  9 -----
 tools/libs/toollog/xentoollog.pc.in             |  9 -----
 tools/libvchan/Makefile                         |  5 +++
 tools/libvchan/xenvchan.pc.in                   | 10 -----
 tools/libxc/Makefile                            | 22 +++++++++++
 tools/libxc/xencontrol.pc.in                    | 10 -----
 tools/libxc/xenguest.pc.in                      | 10 -----
 tools/libxl/Makefile                            | 22 +++++++++++
 tools/libxl/xenlight.pc.in                      | 12 ------
 tools/libxl/xlutil.pc.in                        | 10 -----
 tools/xenstat/libxenstat/Makefile               |  5 +++
 tools/xenstat/libxenstat/xenstat.pc.in          | 10 -----
 tools/xenstore/Makefile                         |  8 +++-
 tools/xenstore/xenstore.pc.in                   | 11 ------
 24 files changed, 98 insertions(+), 177 deletions(-)

diff --git a/stubdom/Makefile b/stubdom/Makefile
index 98eba8efe3..f000f56e68 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -342,7 +342,6 @@ define do_links
   cd $(dir $@); \
   ln -sf $(dir $<)include/*.h include/; \
   ln -sf $(dir $<)*.[ch] .; \
-  ln -sf $(dir $<)*.pc.in .; \
   ln -sf $(dir $<)Makefile .
   touch $@
 endef
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 385807a71c..52a16c9ac3 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -209,27 +209,33 @@ endif
 
 PKG_CONFIG_DIR ?= $(XEN_ROOT)/tools/pkg-config
 
-PKG_CONFIG_FILTER = $(foreach l,$(PKG_CONFIG_REMOVE),-e 's!\([ ,]\)$(l),!\1!g' -e 's![ ,]$(l)$$!!g')
-
-$(PKG_CONFIG_DIR)/%.pc: %.pc.in Makefile $(XEN_ROOT)/tools/Rules.mk
+$(PKG_CONFIG_DIR):
 	mkdir -p $(PKG_CONFIG_DIR)
-	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
-	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
-	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
-	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
-	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
-	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
-	     -e 's!@@cflagslocal@@!$(PKG_CONFIG_CFLAGS_LOCAL)!g' \
-	     -e 's!@@libsflag@@\([^ ]*\)!-L\1 -Wl,-rpath-link=\1!g' \
-	     $(PKG_CONFIG_FILTER) < $< > $@
-
-%.pc: %.pc.in Makefile $(XEN_ROOT)/tools/Rules.mk
-	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
-	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
-	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
-	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
-	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
-	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
-	     -e 's!@@cflagslocal@@!!g' \
-	     -e 's!@@libsflag@@!-L!g' \
-	     $(PKG_CONFIG_FILTER) < $< > $@
+
+$(PKG_CONFIG_DIR)/%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk $(PKG_CONFIG_DIR)
+	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
+	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
+	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
+	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
+	$(file >>$@,)
+	$(file >>$@,Name: $(PKG_CONFIG_NAME))
+	$(file >>$@,Description: $(PKG_CONFIG_DESC))
+	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
+	$(file >>$@,Cflags: -I$${includedir} $(CFLAGS_xeninclude))
+	$(file >>$@,Libs: -L$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB))
+	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
+	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+
+%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk
+	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
+	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
+	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
+	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
+	$(file >>$@,)
+	$(file >>$@,Name: $(PKG_CONFIG_NAME))
+	$(file >>$@,Description: $(PKG_CONFIG_DESC))
+	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
+	$(file >>$@,Cflags: -I$${includedir})
+	$(file >>$@,Libs: -L$${libdir} -l$(PKG_CONFIG_LIB))
+	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
+	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
diff --git a/tools/libs/call/xencall.pc.in b/tools/libs/call/xencall.pc.in
deleted file mode 100644
index 409773e535..0000000000
--- a/tools/libs/call/xencall.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xencall
-Description: The Xencall library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxencall
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/devicemodel/xendevicemodel.pc.in b/tools/libs/devicemodel/xendevicemodel.pc.in
deleted file mode 100644
index 8bd04faf47..0000000000
--- a/tools/libs/devicemodel/xendevicemodel.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xendevicemodel
-Description: The Xendevicemodel library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxendevicemodel
-Requires.private: xentoolcore,xentoollog,xencall
diff --git a/tools/libs/evtchn/xenevtchn.pc.in b/tools/libs/evtchn/xenevtchn.pc.in
deleted file mode 100644
index c74af1ece4..0000000000
--- a/tools/libs/evtchn/xenevtchn.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenevtchn
-Description: The Xenevtchn library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenevtchn
-Requires.private: xentoollog
diff --git a/tools/libs/foreignmemory/xenforeignmemory.pc.in b/tools/libs/foreignmemory/xenforeignmemory.pc.in
deleted file mode 100644
index 61c9def69c..0000000000
--- a/tools/libs/foreignmemory/xenforeignmemory.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenforeignmemory
-Description: The Xenforeignmemory library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenforeignmemory
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/gnttab/xengnttab.pc.in b/tools/libs/gnttab/xengnttab.pc.in
deleted file mode 100644
index 4c3beed5dc..0000000000
--- a/tools/libs/gnttab/xengnttab.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xengnttab
-Description: The Xengnttab library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxengnttab
-Requires.private: xentoollog,xentoolcore
diff --git a/tools/libs/hypfs/xenhypfs.pc.in b/tools/libs/hypfs/xenhypfs.pc.in
deleted file mode 100644
index ef9fcc87bf..0000000000
--- a/tools/libs/hypfs/xenhypfs.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenhypfs
-Description: The Xenhypfs library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenhypfs
-Requires.private: xentoolcore,xentoollog,xencall,zlib
diff --git a/tools/libs/libs.mk b/tools/libs/libs.mk
index 8b1ca2aa62..4679268fc2 100644
--- a/tools/libs/libs.mk
+++ b/tools/libs/libs.mk
@@ -25,8 +25,16 @@ ifneq ($(nosharedlibs),y)
 LIB += libxen$(LIBNAME).so
 endif
 
+comma:= ,
+empty:=
+space:= $(empty) $(empty)
 PKG_CONFIG ?= xen$(LIBNAME).pc
+PKG_CONFIG_NAME ?= Xen$(LIBNAME)
+PKG_CONFIG_DESC ?= The $(PKG_CONFIG_NAME) library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxen$(LIBNAME))
+PKG_CONFIG_LIB := xen$(LIBNAME)
+PKG_CONFIG_REQPRIV := $(subst $(space),$(comma),$(strip $(foreach lib,$(USELIBS_$(LIBNAME)),xen$(lib))))
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/libs/toolcore/Makefile b/tools/libs/toolcore/Makefile
index 34b08a4236..5819bbc8ee 100644
--- a/tools/libs/toolcore/Makefile
+++ b/tools/libs/toolcore/Makefile
@@ -9,6 +9,7 @@ SRCS-y	+= handlereg.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
 
+PKG_CONFIG_DESC := Central support for Xen Hypervisor userland libraries
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxentoolcore)/include
 
 $(LIB_OBJS): $(AUTOINCS)
diff --git a/tools/libs/toolcore/xentoolcore.pc.in b/tools/libs/toolcore/xentoolcore.pc.in
deleted file mode 100644
index 55ff4e25e4..0000000000
--- a/tools/libs/toolcore/xentoolcore.pc.in
+++ /dev/null
@@ -1,9 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xentoolcore
-Description: Central support for Xen Hypervisor userland libraries
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxentoolcore
diff --git a/tools/libs/toollog/xentoollog.pc.in b/tools/libs/toollog/xentoollog.pc.in
deleted file mode 100644
index 554e4d5b34..0000000000
--- a/tools/libs/toollog/xentoollog.pc.in
+++ /dev/null
@@ -1,9 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xentoollog
-Description: The Xentoollog library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxentoollog
diff --git a/tools/libvchan/Makefile b/tools/libvchan/Makefile
index a5441162a0..e718447977 100644
--- a/tools/libvchan/Makefile
+++ b/tools/libvchan/Makefile
@@ -23,7 +23,12 @@ CFLAGS += -I../include -I.
 io.o io.opic: CFLAGS += $(CFLAGS_libxenctrl) # for xen_mb et al
 
 PKG_CONFIG := xenvchan.pc
+PKG_CONFIG_NAME := Xenvchan
+PKG_CONFIG_DESC := The Xenvchan library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenvchan)
+PKG_CONFIG_LIB := xenvchan
+PKG_CONFIG_REQPRIV := xentoollog,xenstore,xenevtchn,xengnttab
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/libvchan/xenvchan.pc.in b/tools/libvchan/xenvchan.pc.in
deleted file mode 100644
index 6fd13108d2..0000000000
--- a/tools/libvchan/xenvchan.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenvchan
-Description: The Xenvchan library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenvchan
-Requires.private: xentoollog,xenstore,xenevtchn,xengnttab
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index c1e41a8ee9..315ac0b4f3 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -158,6 +158,28 @@ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): xc_private.h
 PKG_CONFIG := xencontrol.pc xenguest.pc
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
 
+xencontrol.pc: PKG_CONFIG_NAME = Xencontrol
+xencontrol.pc: PKG_CONFIG_DESC = The Xencontrol library for Xen hypervisor
+xencontrol.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenctrl)
+xencontrol.pc: PKG_CONFIG_LIB = xenctrl
+xencontrol.pc: PKG_CONFIG_REQPRIV = xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
+xenguest.pc: PKG_CONFIG_NAME = Xenguest
+xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
+xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
+xenguest.pc: PKG_CONFIG_LIB = xenguest
+xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_NAME = Xencontrol
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_DESC = The Xencontrol library for Xen hypervisor
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenctrl)
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_LIB = xenctrl
+$(PKG_CONFIG_DIR)/xencontrol.pc: PKG_CONFIG_REQPRIV = xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_NAME = Xenguest
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_LIB = xenguest
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
 $(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
diff --git a/tools/libxc/xencontrol.pc.in b/tools/libxc/xencontrol.pc.in
deleted file mode 100644
index e653ba2543..0000000000
--- a/tools/libxc/xencontrol.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xencontrol
-Description: The Xencontrol library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenctrl
-Requires.private: xenevtchn,xengnttab,xencall,xenforeignmemory,xendevicemodel,xentoollog
diff --git a/tools/libxc/xenguest.pc.in b/tools/libxc/xenguest.pc.in
deleted file mode 100644
index 225ac0b9c8..0000000000
--- a/tools/libxc/xenguest.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenguest
-Description: The Xenguest library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenguest
-Requires.private: xentoollog,xencall,xenforeignmemory,xenevtchn
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index c26b3a8093..f61f761e1e 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -195,8 +195,19 @@ PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
+xenlight.pc: PKG_CONFIG_NAME = Xenlight
+xenlight.pc: PKG_CONFIG_DESC = The Xenlight library for Xen hypervisor
 xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR)
+xenlight.pc: PKG_CONFIG_VARS = xenfirmwaredir=$(XENFIRMWAREDIR) libexec_bin=$(LIBEXEC_BIN)
+xenlight.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenlight)
+xenlight.pc: PKG_CONFIG_LIB = xenlight
+xenlight.pc: PKG_CONFIG_REQPRIV = xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
+xlutil.pc: PKG_CONFIG_NAME = Xlutil
+xlutil.pc: PKG_CONFIG_DESC = The xl utility library for Xen hypervisor
 xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR)
+xlutil.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxlutil)
+xlutil.pc: PKG_CONFIG_LIB = xlutil
+xlutil.pc: PKG_CONFIG_REQPRIV = xenlight
 $(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
 $(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
 $(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
@@ -204,8 +215,19 @@ endif
 
 PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
 
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_NAME = Xenlight
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_DESC = The Xenlight library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_VARS = xenfirmwaredir=$(XENFIRMWAREDIR) libexec_bin=$(LIBEXEC_BIN)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenlight)
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_LIB = xenlight
+$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_REQPRIV = xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_NAME = Xlutil
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_DESC = The xl utility library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR)
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxlutil)
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_LIB = xlutil
+$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_REQPRIV = xenlight
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(CURDIR)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
diff --git a/tools/libxl/xenlight.pc.in b/tools/libxl/xenlight.pc.in
deleted file mode 100644
index 6b351ba096..0000000000
--- a/tools/libxl/xenlight.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-xenfirmwaredir=@@firmwaredir@@
-libexec_bin=@@libexecbin@@
-
-Name: Xenlight
-Description: The Xenlight library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenlight
-Requires.private: xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
diff --git a/tools/libxl/xlutil.pc.in b/tools/libxl/xlutil.pc.in
deleted file mode 100644
index cdd98fba74..0000000000
--- a/tools/libxl/xlutil.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xlutil
-Description: The xl utility library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxlutil
-Requires.private: xenlight
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index b5e623b155..bdd5a0f469 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -38,7 +38,12 @@ LDLIBS-y = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) -lyajl
 LDLIBS-$(CONFIG_SunOS) += -lkstat
 
 PKG_CONFIG := xenstat.pc
+PKG_CONFIG_NAME := Xenstat
+PKG_CONFIG_DESC := The Xenstat library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenstat)
+PKG_CONFIG_LIB := xenstat
+PKG_CONFIG_REQPRIV := xencontrol,xenstore
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/xenstat/libxenstat/xenstat.pc.in b/tools/xenstat/libxenstat/xenstat.pc.in
deleted file mode 100644
index ad00577c89..0000000000
--- a/tools/xenstat/libxenstat/xenstat.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenstat
-Description: The Xenstat library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir}
-Libs: @@libsflag@@${libdir} -lxenstat
-Requires.private: xencontrol,xenstore
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 0a64ac1571..574be8d15c 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -105,8 +105,7 @@ xs.opic: CFLAGS += -DUSE_PTHREAD
 ifeq ($(CONFIG_Linux),y)
 xs.opic: CFLAGS += -DUSE_DLSYM
 libxenstore.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += -ldl
-else
-PKG_CONFIG_REMOVE += -ldl
+PKG_CONFIG_LIBSPRIV := -ldl
 endif
 
 libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
@@ -116,7 +115,12 @@ libxenstore.a: xs.o xs_lib.o
 	$(AR) rcs $@ $^
 
 PKG_CONFIG := xenstore.pc
+PKG_CONFIG_NAME := Xenstore
+PKG_CONFIG_DESC := The Xenstore library for Xen hypervisor
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+PKG_CONFIG_USELIBS := $(SHLIB_libxenstore)
+PKG_CONFIG_LIB := xenstore
+PKG_CONFIG_REQPRIV := xenevtchn,xencontrol,xengnttab,xentoolcore
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
diff --git a/tools/xenstore/xenstore.pc.in b/tools/xenstore/xenstore.pc.in
deleted file mode 100644
index 2f64a6b824..0000000000
--- a/tools/xenstore/xenstore.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@@prefix@@
-includedir=@@incdir@@
-libdir=@@libdir@@
-
-Name: Xenstore
-Description: The Xenstore library for Xen hypervisor
-Version: @@version@@
-Cflags: -I${includedir} @@cflagslocal@@
-Libs: @@libsflag@@${libdir} -lxenstore
-Libs.private: -ldl
-Requires.private: xenevtchn,xencontrol,xengnttab,xentoolcore
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMIq-00063u-L3; Fri, 18 Sep 2020 19:44:16 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMIp-00063k-53
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:15 +0000
X-Inumbo-ID: d60ccb0b-7531-48a8-a8a5-722c35889b1d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d60ccb0b-7531-48a8-a8a5-722c35889b1d;
 Fri, 18 Sep 2020 19:44:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ublG/i3a3QGO9DMNDgDRtS1v9jodVsewGk+la0dKgSY=; b=O3TBfyq/cmScsvpVZcLJhEjK+A
 tK1ktHUddjeFWZQuCd/No1JiSIH7RlYAcSxEa+73rQP4tCbHNwQiwTTJDUDPJi5ynx2espw43jqZl
 2JKtqxHJ2vvmfJwCXdem98EBXsqIEgFcCC0gBQIxbi2E6bhu334WvZW3PvXcOozHQsjg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMIn-00071r-Hy
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMIn-0004CE-Gy
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:13 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: drop explicit path specifications for qemu build
Message-Id: <E1kJMIn-0004CE-Gy@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:13 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0b77395ef2f20058305240f2395883b1d961982a
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:18 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:21 2020 +0000

    tools: drop explicit path specifications for qemu build
    
    Since more than three years now qemu is capable to set the needed
    include and library paths for the Xen libraries via pkg-config.
    
    So drop the specification of those paths in tools/Makefile. This will
    enable to move libxenctrl away from tools/libxc, as qemu's configure
    script has special treatment of this path.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Makefile | 26 +-------------------------
 1 file changed, 1 insertion(+), 25 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index 198b239edc..7c9f9fc900 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -245,32 +245,8 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-DXC_WANT_COMPAT_GNTTAB_API=1 \
 		-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
 		-DXC_WANT_COMPAT_DEVICEMODEL_API=1 \
-		-I$(XEN_ROOT)/tools/include \
-		-I$(XEN_ROOT)/tools/libs/toolcore/include \
-		-I$(XEN_ROOT)/tools/libs/toollog/include \
-		-I$(XEN_ROOT)/tools/libs/evtchn/include \
-		-I$(XEN_ROOT)/tools/libs/gnttab/include \
-		-I$(XEN_ROOT)/tools/libs/foreignmemory/include \
-		-I$(XEN_ROOT)/tools/libs/devicemodel/include \
-		-I$(XEN_ROOT)/tools/libxc/include \
-		-I$(XEN_ROOT)/tools/xenstore/include \
-		-I$(XEN_ROOT)/tools/xenstore/compat/include \
 		$(EXTRA_CFLAGS_QEMU_XEN)" \
-		--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
-		-L$(XEN_ROOT)/tools/xenstore \
-		-L$(XEN_ROOT)/tools/libs/toolcore \
-		-L$(XEN_ROOT)/tools/libs/evtchn \
-		-L$(XEN_ROOT)/tools/libs/gnttab \
-		-L$(XEN_ROOT)/tools/libs/foreignmemory \
-		-L$(XEN_ROOT)/tools/libs/devicemodel \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toolcore \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
-		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/devicemodel \
-		$(QEMU_UPSTREAM_RPATH)" \
+		--extra-ldflags="$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
 		--localstatedir=$(localstatedir) \
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMIz-00064t-Mc; Fri, 18 Sep 2020 19:44:25 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMIy-00064i-HG
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:24 +0000
X-Inumbo-ID: 368322d6-1e66-4602-a59a-52a50522cf36
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 368322d6-1e66-4602-a59a-52a50522cf36;
 Fri, 18 Sep 2020 19:44:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Mj3XPYKSYeX1tJiJeKj/MdCwrkXKBgQ9lxcDfU1PFRI=; b=YAKVYhEF2csWucRhZAjhZZOxty
 tCoF+ToWHxQd9Bif7/h2dIV3rL6+ksLSMEKgu38aosUxghsK1HG9S+4kWeZuAT0faZk++vt/Q/ABd
 qz6VUir+4dsL+uDoPT6yXg8tOsdOYZVFS6fQInb+5npSC6KcKJJzyD1wk0viphuwiG+I=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMIx-000727-LA
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMIx-0004DS-KM
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/python: drop libxenguest from setup.py
Message-Id: <E1kJMIx-0004DS-KM@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7c273ffdd0e91d9eeb975b7d531a4ed235931bb1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:19 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/python: drop libxenguest from setup.py
    
    There is not a single wrapper for a libxenguest function defined.
    So drop libxenguest from tools/python/setup.py.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/python/setup.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8faf1c0ddc..44696b3998 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -21,8 +21,8 @@ xc = Extension("xc",
                                       PATH_LIBXC + "/include",
                                       "xen/lowlevel/xc" ],
                library_dirs       = [ PATH_LIBXC ],
-               libraries          = [ "xenctrl", "xenguest" ],
-               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ],
+               libraries          = [ "xenctrl" ],
+               depends            = [ PATH_LIBXC + "/libxenctrl.so" ],
                extra_link_args    = [ "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJ9-00066A-OE; Fri, 18 Sep 2020 19:44:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJ8-00065x-Ny
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:34 +0000
X-Inumbo-ID: e29f2e8a-5255-4409-a1f9-54bab1f041fa
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e29f2e8a-5255-4409-a1f9-54bab1f041fa;
 Fri, 18 Sep 2020 19:44:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=5rkiyTHfketCLcc1bhEiDZsaR437SSzWTk10/NHwb04=; b=rgYtRMn7PYGwz42dmSGaEf/Kls
 9md+DpbCbn6Jmx+zJ6J88D3Aec3eL10ftcFWoo2nR6EgFInHaM76RYN007fWLJAkscXGIfpwRb0OE
 Dqq7idbzFBeol731H4UoSlK3jbrrc1kNlijcMsWkdd5acE1v9oPY/bMe2SOGjZ//85cY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJ7-00072H-OL
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJ7-0004EH-NT
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: fix pkg-config file for libxenguest
Message-Id: <E1kJMJ7-0004EH-NT@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit bb2ea7f392348b2697c5b9140deea56b1b56776e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:20 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: fix pkg-config file for libxenguest
    
    The pkg-config file for libxenguest is missing the private dependency
    on libxenctrl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 315ac0b4f3..763231065c 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -178,7 +178,7 @@ $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_NAME = Xenguest
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_DESC = The Xenguest library for Xen hypervisor
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_USELIBS = $(SHLIB_libxenguest)
 $(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_LIB = xenguest
-$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn
+$(PKG_CONFIG_DIR)/xenguest.pc: PKG_CONFIG_REQPRIV = xentoollog,xencall,xenforeignmemory,xenevtchn,xencontrol
 
 ifneq ($(CONFIG_LIBXC_MINIOS),y)
 PKG_CONFIG_INST := $(PKG_CONFIG)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJJ-00067C-Pw; Fri, 18 Sep 2020 19:44:45 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJI-000674-RW
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:44 +0000
X-Inumbo-ID: 21b94e36-9cbc-4abc-918f-f751786a37a9
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 21b94e36-9cbc-4abc-918f-f751786a37a9;
 Fri, 18 Sep 2020 19:44:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ydRIxNLc4p7N5hO4I3aOnLbKatSJyO2TCiTxcaN6iQg=; b=KHBIFfVAfEd5vz6ImtNV1aDl+c
 QN1/MJZnqgs03umhcMETrsqkxYT9DuGQ/bGSm/w04cTRN21z99Et3KPFaVZ1C5sbsgrhKmGHEklzB
 MmzDJ0BjO/IxLhU+aj0JQ6kPDgPElfCHnQPaX6+1t2QtE7P3dO6rNT7OeAVf11TzHdw4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJH-00073x-SL
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJH-0004GS-Qh
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: don't assume libxenguest and libxenctrl to be in
 same directory
Message-Id: <E1kJMJH-0004GS-Qh@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0c293ad3a2842452bff0fe0515cc9046a60afa5e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:21 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: don't assume libxenguest and libxenctrl to be in same directory
    
    There are quite some places in Makefiles assuming libxenguest and
    libxenctrl being built in the same directory via a single Makefile.
    
    Drop this assumption by specifying the dependencies and path variables
    for both libraries correctly.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk       | 7 +++----
 tools/libxl/Makefile | 2 +-
 tools/misc/Makefile  | 1 +
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 52a16c9ac3..13432560ff 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -16,8 +16,7 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
 XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
-# Currently libxenguest lives in the same directory as libxenctrl
-XEN_libxenguest    = $(XEN_libxenctrl)
+XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
@@ -117,7 +116,7 @@ LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libex
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
 
 CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenstore = $(SHLIB_libxentoolcore)
+SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
 LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_libxenstore)/libxenstore$(libextension)
 SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_libxenstore)
 ifeq ($(CONFIG_Linux),y)
@@ -144,7 +143,7 @@ CFLAGS += -O2 -fomit-frame-pointer
 endif
 
 CFLAGS_libxenlight = -I$(XEN_libxenlight) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
-SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs)
+SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs) $(SHLIB_libxenguest)
 LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_libxenlight)/libxenlight$(libextension)
 SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_libxenlight)
 
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index f61f761e1e..b3815390f3 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -188,7 +188,7 @@ libxl_dom.o: CFLAGS += -I$(XEN_ROOT)/tools  # include libacpi/x86.h
 libxl_x86_acpi.o: CFLAGS += -I$(XEN_ROOT)/tools
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
-$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn)
+$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 PKG_CONFIG = xenlight.pc xlutil.pc
 PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 9fdb13597f..e7e74db85f 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -6,6 +6,7 @@ CFLAGS += -Werror
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 CFLAGS += $(CFLAGS_libxenevtchn)
 CFLAGS += $(CFLAGS_libxenctrl)
+CFLAGS += $(CFLAGS_libxenguest)
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenstore)
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:44:55 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:44:55 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJT-00068b-RU; Fri, 18 Sep 2020 19:44:55 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJS-00068R-TI
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:54 +0000
X-Inumbo-ID: fccf8655-e69e-4248-948f-812e5a804ff8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id fccf8655-e69e-4248-948f-812e5a804ff8;
 Fri, 18 Sep 2020 19:44:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IjtB/F1OLO4vlO/PQ+XB1KKM33XeI29F+NiN2b/KwBY=; b=3oNStPHL3LLQFwCoZnQKAjGWCk
 AXXeX5uoyoNvk1wN2mYlV/lPxUzFsbSLayVis5gZh9E0ZWa2IJKVwxwl54ZGLe/IA/6UY8v3SEuUb
 CVBwz94j5Z0k51WNuoZFC6upxFXth1zmCVmHjrdsFC/j7pj1cffkgOmU1qWe9Lm1fS/4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJR-000746-Vd
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:53 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJR-0004HX-Ui
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:44:53 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/misc: don't use libxenctrl internals from
 xen-hptool
Message-Id: <E1kJMJR-0004HX-Ui@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:44:53 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 76020cc98b0c6da6241e51979071df8ab0643930
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:22 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: don't use libxenctrl internals from xen-hptool
    
    xen-hptool is including private headers from tools/libxc without any
    need. Switch it to use official headers only.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/Makefile     | 2 --
 tools/misc/xen-hptool.c | 8 +++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index e7e74db85f..2a7f2ec42d 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -94,8 +94,6 @@ xenhypfs: xenhypfs.o
 xenlockprof: xenlockprof.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
-# xen-hptool incorrectly uses libxc internals
-xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-hptool: xen-hptool.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-hptool.c b/tools/misc/xen-hptool.c
index 6e27d9cf43..7f17f24942 100644
--- a/tools/misc/xen-hptool.c
+++ b/tools/misc/xen-hptool.c
@@ -1,9 +1,11 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include <xenevtchn.h>
 #include <xenctrl.h>
-#include <xc_private.h>
-#include <xc_core.h>
+#include <xenguest.h>
 #include <xenstore.h>
-#include <unistd.h>
+#include <xen-tools/libs.h>
 
 static xc_interface *xch;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:45:05 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:45:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJd-00069z-Uj; Fri, 18 Sep 2020 19:45:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJc-00069o-Tr
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:04 +0000
X-Inumbo-ID: 17800207-21fd-4839-909e-0dfe6dbed6df
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 17800207-21fd-4839-909e-0dfe6dbed6df;
 Fri, 18 Sep 2020 19:45:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=O0hjsNGRcuJTKIEF+Nnz6AmHx1pCGeB+hGvPDlm3uU4=; b=E/npwiPIIKVjJWsBplQRDj7h0z
 SEV3kXwH9BzqSgyqMju/GEuNtH+cBumAC8XW8xIkOYDcBIcMlFH2hAyIpbPUARKA/amUPpvktASwt
 C3ZY5BdBF2nL8WYpD3XzcHLgdNLFPVNiJbF4LI/1Ta8IJVLgPWnebrJUuWdYLCwhljyo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJc-00074j-32
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJc-0004Ic-23
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/misc: don't include xg_save_restore.h from
 xen-mfndump.c
Message-Id: <E1kJMJc-0004Ic-23@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a547703b243767185d69731a922c5b77cf2b4a2b
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:23 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: don't include xg_save_restore.h from xen-mfndump.c
    
    xen-mfndump.c is including the libxc private header xg_save_restore.h.
    Avoid that by moving the definition of is_mapped() to xen-mfndump.c
    (it is used there only) and by duplicating the definition of
    M2P_SIZE() in xen-mfndump.c.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xg_save_restore.h | 4 ----
 tools/misc/xen-mfndump.c      | 5 ++++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index 303081df0d..b904296997 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -109,10 +109,6 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT)
 #define M2P_CHUNKS(_m)  (M2P_SIZE((_m)) >> M2P_SHIFT)
 
-/* Returns TRUE if the PFN is currently mapped */
-#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
-
-
 #define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
 
 #define SET_FIELD(_p, _f, _v, _w) do {          \
diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index 858bd0e26b..cb15d08c7e 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -5,7 +5,10 @@
 #include <unistd.h>
 #include <inttypes.h>
 
-#include "xg_save_restore.h"
+#include <xen-tools/libs.h>
+
+#define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)
+#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
 
 static xc_interface *xch;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:45:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:45:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJo-0006B0-07; Fri, 18 Sep 2020 19:45:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJn-0006Ar-1e
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:15 +0000
X-Inumbo-ID: 4f1ff449-d260-4e07-bdca-b85c93e49e53
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4f1ff449-d260-4e07-bdca-b85c93e49e53;
 Fri, 18 Sep 2020 19:45:14 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Zh/sr1vI6ng3CkuYDM9nlzQx820kvO6jiFuQoRdCYTY=; b=4TwHeHc3T7DadkVv0fWtnxmw0R
 knzg+67DSLKogZv077Sfz/Kxx1w2NF565jvLx4i/IA6CxOslV15/froV2WvhCHiv4OJ5YAK4P6VZ6
 0ROha/i+NWAjEhQphNvz05H7nhXBkAaxErcaob0dg1nrtE03RbGZqfrKv9i06se/oqgk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJm-00075I-68
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJm-0004JC-5Q
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/misc: replace PAGE_SIZE with XC_PAGE_SIZE in
 xen-mfndump.c
Message-Id: <E1kJMJm-0004JC-5Q@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 790f2dfb598acb5f3f3f75b47c5e3ab642c16478
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:24 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: replace PAGE_SIZE with XC_PAGE_SIZE in xen-mfndump.c
    
    The definition of PAGE_SIZE comes from xc_private.h, which shouldn't be
    used by xen-mfndump.c. Replace PAGE_SIZE by XC_PAGE_SIZE, as
    xc_private.h contains:
    
    #define PAGE_SIZE XC_PAGE_SIZE
    
    For the same reason PAGE_SHIFT_X86 needs to replaced with
    XC_PAGE_SHIFT.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/xen-mfndump.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index cb15d08c7e..92bc954ce0 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -207,7 +207,7 @@ int dump_ptes_func(int argc, char *argv[])
         goto out;
     }
 
-    page = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+    page = xc_map_foreign_range(xch, domid, XC_PAGE_SIZE, PROT_READ,
                                 minfo.p2m_table[pfn]);
     if ( !page )
     {
@@ -216,7 +216,7 @@ int dump_ptes_func(int argc, char *argv[])
         goto out;
     }
 
-    pte_num = PAGE_SIZE / 8;
+    pte_num = XC_PAGE_SIZE / 8;
 
     printf(" --- Dumping %d PTEs for domain %d ---\n", pte_num, domid);
     printf(" Guest Width: %u, PT Levels: %u P2M size: = %lu\n",
@@ -252,7 +252,7 @@ int dump_ptes_func(int argc, char *argv[])
 
  out:
     if ( page )
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
     xc_unmap_domain_meminfo(xch, &minfo);
     munmap(m2p_table, M2P_SIZE(max_mfn));
     return rc;
@@ -290,7 +290,7 @@ int lookup_pte_func(int argc, char *argv[])
         return -1;
     }
 
-    pte_num = PAGE_SIZE / 8;
+    pte_num = XC_PAGE_SIZE / 8;
 
     printf(" --- Lookig for PTEs mapping mfn 0x%lx for domain %d ---\n",
            mfn, domid);
@@ -302,7 +302,7 @@ int lookup_pte_func(int argc, char *argv[])
         if ( !(minfo.pfn_type[i] & XEN_DOMCTL_PFINFO_LTABTYPE_MASK) )
             continue;
 
-        page = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+        page = xc_map_foreign_range(xch, domid, XC_PAGE_SIZE, PROT_READ,
                                     minfo.p2m_table[i]);
         if ( !page )
             continue;
@@ -312,15 +312,15 @@ int lookup_pte_func(int argc, char *argv[])
             uint64_t pte = ((const uint64_t*)page)[j];
 
 #define __MADDR_BITS_X86  ((minfo.guest_width == 8) ? 52 : 44)
-#define __MFN_MASK_X86    ((1ULL << (__MADDR_BITS_X86 - PAGE_SHIFT_X86)) - 1)
-            if ( ((pte >> PAGE_SHIFT_X86) & __MFN_MASK_X86) == mfn)
+#define __MFN_MASK_X86    ((1ULL << (__MADDR_BITS_X86 - XC_PAGE_SHIFT)) - 1)
+            if ( ((pte >> XC_PAGE_SHIFT) & __MFN_MASK_X86) == mfn)
                 printf("  0x%lx <-- [0x%lx][%lu]: 0x%"PRIx64"\n",
                        mfn, minfo.p2m_table[i], j, pte);
 #undef __MADDR_BITS_X86
 #undef __MFN_MASK_X8
         }
 
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
         page = NULL;
     }
 
@@ -355,8 +355,8 @@ int memcmp_mfns_func(int argc, char *argv[])
         return -1;
     }
 
-    page1 = xc_map_foreign_range(xch, domid1, PAGE_SIZE, PROT_READ, mfn1);
-    page2 = xc_map_foreign_range(xch, domid2, PAGE_SIZE, PROT_READ, mfn2);
+    page1 = xc_map_foreign_range(xch, domid1, XC_PAGE_SIZE, PROT_READ, mfn1);
+    page2 = xc_map_foreign_range(xch, domid2, XC_PAGE_SIZE, PROT_READ, mfn2);
     if ( !page1 || !page2 )
     {
         ERROR("Failed to map either 0x%lx[dom %d] or 0x%lx[dom %d]\n",
@@ -368,13 +368,13 @@ int memcmp_mfns_func(int argc, char *argv[])
     printf(" --- Comparing the content of 2 MFNs ---\n");
     printf(" 1: 0x%lx[dom %d], 2: 0x%lx[dom %d]\n",
            mfn1, domid1, mfn2, domid2);
-    printf("  memcpy(1, 2) = %d\n", memcmp(page1, page2, PAGE_SIZE));
+    printf("  memcpy(1, 2) = %d\n", memcmp(page1, page2, XC_PAGE_SIZE));
 
  out:
     if ( page1 )
-        munmap(page1, PAGE_SIZE);
+        munmap(page1, XC_PAGE_SIZE);
     if ( page2 )
-        munmap(page2, PAGE_SIZE);
+        munmap(page2, XC_PAGE_SIZE);
     return rc;
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:45:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:45:26 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMJy-0006CJ-34; Fri, 18 Sep 2020 19:45:26 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMJx-0006C9-1x
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:25 +0000
X-Inumbo-ID: dd71039d-4237-4c28-acb0-d9a50360567b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id dd71039d-4237-4c28-acb0-d9a50360567b;
 Fri, 18 Sep 2020 19:45:24 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ja5Vv5gAnK311squwVH0I9R/KjEQfBpt+4T8w8Xrmk0=; b=kVMO0P1kCUqPW1JqEdbSH9zJji
 EN7Oxw1nDW2WLgYI327wugNB8ACtrz/HmfGPpo28z3ymgf5ycf2UBwPSFPaabNS+H5lFBwZbFrSN8
 QAwHvgwbr0jt9AawtAxkrgaweV5pf6q9PBCpoZ5rlWwUZkxVEHYJANGQSlc7LB9AzlWc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJw-00075Q-9O
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:24 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMJw-0004K0-8V
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:24 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/misc: drop all libxc internals from xen-mfndump.c
Message-Id: <E1kJMJw-0004K0-8V@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:24 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 45397d49fa7f0f236b783df48713dbf5a68bf599
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:25 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: drop all libxc internals from xen-mfndump.c
    
    The last libxc internal used by xen-mfndump.c is the ERROR() macro.
    Add a simple definition for that macro to xen-mfndump.c and replace
    the libxc private header includes by official ones.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/misc/Makefile      |  2 --
 tools/misc/xen-mfndump.c | 13 +++++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 2a7f2ec42d..7d37f297a9 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -99,8 +99,6 @@ xen-hptool: xen-hptool.o
 
 xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs)
 
-# xen-mfndump incorrectly uses libxc internals
-xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-mfndump: xen-mfndump.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c
index 92bc954ce0..62121bd241 100644
--- a/tools/misc/xen-mfndump.c
+++ b/tools/misc/xen-mfndump.c
@@ -1,15 +1,20 @@
-#define XC_WANT_COMPAT_MAP_FOREIGN_API
-#include <xenctrl.h>
-#include <xc_private.h>
-#include <xc_core.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
 #include <unistd.h>
 #include <inttypes.h>
 
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
+#include <xenguest.h>
+
 #include <xen-tools/libs.h>
 
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)
 #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
 
+#define ERROR(msg, args...) fprintf(stderr, msg, ## args)
+
 static xc_interface *xch;
 
 int help_func(int argc, char *argv[])
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:45:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:45:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMK9-0006DQ-4l; Fri, 18 Sep 2020 19:45:37 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMK7-0006DG-Pb
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:35 +0000
X-Inumbo-ID: 9827151f-6416-4194-8d94-af92b919c644
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9827151f-6416-4194-8d94-af92b919c644;
 Fri, 18 Sep 2020 19:45:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=A0KiTqtOA9IMQlmcOFhATJGuaWz6qVuf2RGNEoW2ahI=; b=BGFs5n3JVStX4DlGGljZVnjnbK
 KxZSJfDQ0jnIkT9QF8ZEJkUQMwx3VMlG5DkJRsT+1b10g7EUi/bIGEWk34pH46bE/8rHnzm+QssHa
 iTCegzJBi5/ZrhEYvdjWtUqAne8jdcMBN96IaWmH0qit78smbDvLEn1FU7o6HoR2GQj4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMK6-00075g-Cq
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:34 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMK6-0004KY-Bx
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:34 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: remove unused headers xc_efi.h and xc_elf.h
Message-Id: <E1kJMK6-0004KY-Bx@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:34 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6797d1ed45a4089a22f7278bb45cddb6fd861d72
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:26 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: remove unused headers xc_efi.h and xc_elf.h
    
    Remove xc_efi.h and xc_elf.h as they aren't used anywhere.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xc_efi.h | 158 ---------------------------------------------------
 tools/libxc/xc_elf.h |  16 ------
 2 files changed, 174 deletions(-)

diff --git a/tools/libxc/xc_efi.h b/tools/libxc/xc_efi.h
deleted file mode 100644
index dbe105be8f..0000000000
--- a/tools/libxc/xc_efi.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Extensible Firmware Interface
- * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) 1999 VA Linux Systems
- * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
- * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
- *      David Mosberger-Tang <davidm@hpl.hp.com>
- *      Stephane Eranian <eranian@hpl.hp.com>
- */
-
-#ifndef XC_EFI_H
-#define XC_EFI_H
-
-/* definitions from xen/include/asm-ia64/linux-xen/linux/efi.h */
-
-typedef struct {
-        uint8_t b[16];
-} efi_guid_t;
-
-#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
-  (b) & 0xff, ((b) >> 8) & 0xff, \
-  (c) & 0xff, ((c) >> 8) & 0xff, \
-  (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
-
-/*
- * Generic EFI table header
- */
-typedef struct {
-	uint64_t signature;
-	uint32_t revision;
-	uint32_t headersize;
-	uint32_t crc32;
-	uint32_t reserved;
-} efi_table_hdr_t;
-
-/*
- * Memory map descriptor:
- */
-
-/* Memory types: */
-#define EFI_RESERVED_TYPE                0
-#define EFI_LOADER_CODE                  1
-#define EFI_LOADER_DATA                  2
-#define EFI_BOOT_SERVICES_CODE           3
-#define EFI_BOOT_SERVICES_DATA           4
-#define EFI_RUNTIME_SERVICES_CODE        5
-#define EFI_RUNTIME_SERVICES_DATA        6
-#define EFI_CONVENTIONAL_MEMORY          7
-#define EFI_UNUSABLE_MEMORY              8
-#define EFI_ACPI_RECLAIM_MEMORY          9
-#define EFI_ACPI_MEMORY_NVS             10
-#define EFI_MEMORY_MAPPED_IO            11
-#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
-#define EFI_PAL_CODE                    13
-#define EFI_MAX_MEMORY_TYPE             14
-
-/* Attribute values: */
-#define EFI_MEMORY_UC           ((uint64_t)0x0000000000000001ULL)    /* uncached */
-#define EFI_MEMORY_WC           ((uint64_t)0x0000000000000002ULL)    /* write-coalescing */
-#define EFI_MEMORY_WT           ((uint64_t)0x0000000000000004ULL)    /* write-through */
-#define EFI_MEMORY_WB           ((uint64_t)0x0000000000000008ULL)    /* write-back */
-#define EFI_MEMORY_WP           ((uint64_t)0x0000000000001000ULL)    /* write-protect */
-#define EFI_MEMORY_RP           ((uint64_t)0x0000000000002000ULL)    /* read-protect */
-#define EFI_MEMORY_XP           ((uint64_t)0x0000000000004000ULL)    /* execute-protect */
-#define EFI_MEMORY_RUNTIME      ((uint64_t)0x8000000000000000ULL)    /* range requires runtime mapping */
-#define EFI_MEMORY_DESCRIPTOR_VERSION   1
-
-#define EFI_PAGE_SHIFT          12
-
-/*
- * For current x86 implementations of EFI, there is
- * additional padding in the mem descriptors.  This is not
- * the case in ia64.  Need to have this fixed in the f/w.
- */
-typedef struct {
-        uint32_t type;
-        uint32_t pad;
-        uint64_t phys_addr;
-        uint64_t virt_addr;
-        uint64_t num_pages;
-        uint64_t attribute;
-#if defined (__i386__)
-        uint64_t pad1;
-#endif
-} efi_memory_desc_t;
-
-/*
- * EFI Runtime Services table
- */
-#define EFI_RUNTIME_SERVICES_SIGNATURE	((uint64_t)0x5652453544e5552ULL)
-#define EFI_RUNTIME_SERVICES_REVISION	0x00010000
-
-typedef struct {
-	efi_table_hdr_t hdr;
-	unsigned long get_time;
-	unsigned long set_time;
-	unsigned long get_wakeup_time;
-	unsigned long set_wakeup_time;
-	unsigned long set_virtual_address_map;
-	unsigned long convert_pointer;
-	unsigned long get_variable;
-	unsigned long get_next_variable;
-	unsigned long set_variable;
-	unsigned long get_next_high_mono_count;
-	unsigned long reset_system;
-} efi_runtime_services_t;
-
-/*
- *  EFI Configuration Table and GUID definitions
- */
-#define NULL_GUID \
-    EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
-#define ACPI_20_TABLE_GUID    \
-    EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
-#define SAL_SYSTEM_TABLE_GUID    \
-    EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
-
-typedef struct {
-	efi_guid_t guid;
-	unsigned long table;
-} efi_config_table_t;
-
-#define EFI_SYSTEM_TABLE_SIGNATURE ((uint64_t)0x5453595320494249ULL)
-#define EFI_SYSTEM_TABLE_REVISION  ((1 << 16) | 00)
-
-typedef struct {
-	efi_table_hdr_t hdr;
-	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
-	uint32_t fw_revision;
-	unsigned long con_in_handle;
-	unsigned long con_in;
-	unsigned long con_out_handle;
-	unsigned long con_out;
-	unsigned long stderr_handle;
-	unsigned long stderr;
-	efi_runtime_services_t *runtime;
-	unsigned long boottime;
-	unsigned long nr_tables;
-	unsigned long tables;
-} efi_system_table_t;
-
-#endif /* XC_EFI_H */
diff --git a/tools/libxc/xc_elf.h b/tools/libxc/xc_elf.h
deleted file mode 100644
index acbc0280bd..0000000000
--- a/tools/libxc/xc_elf.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <xen/libelf/elfstructs.h>
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:45:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:45:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMKJ-0006Fo-6R; Fri, 18 Sep 2020 19:45:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMKH-0006Eq-MQ
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:45 +0000
X-Inumbo-ID: 1523b44f-b23e-40c1-9eca-3487b59bf190
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1523b44f-b23e-40c1-9eca-3487b59bf190;
 Fri, 18 Sep 2020 19:45:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=nmOHbylb6uqIrJ3tFeZE9OHviY0i76Bp1qwGG6bCvBo=; b=d7V/hhllMN5J8ANUvDdSFxSIuK
 RcnehMYVwItUur3F/jtjrih3q+VfUPCl82EXXFiWeE2//gkQqP7wdnNyngUyWmC5NsBXKeTVvPv79
 4P36gl9gtp/mioRHWenh8v6yjBLkiluyWdA8Dc1KuCoNDI5EM3OaCkb99LnPp90yQxII=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKG-00075o-G6
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:44 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKG-0004LM-FH
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:44 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: move xc_[un]map_domain_meminfo() into new
 source xg_domain.c
Message-Id: <E1kJMKG-0004LM-FH@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:44 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 735749c8316d2f8b074e38138989336cfdec65f2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:27 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: move xc_[un]map_domain_meminfo() into new source xg_domain.c
    
    Move xc_[un]map_domain_meminfo() functions to new source xg_domain.c as
    they are defined in include/xenguest.h and should be in libxenguest.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile    |   4 +-
 tools/libxc/xc_domain.c | 126 ----------------------------------------
 tools/libxc/xg_domain.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 127 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 763231065c..7b81f8c193 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -52,7 +52,9 @@ CTRL_SRCS-y       += xc_gnttab_compat.c
 CTRL_SRCS-y       += xc_devicemodel_compat.c
 
 GUEST_SRCS-y :=
-GUEST_SRCS-y += xg_private.c xc_suspend.c
+GUEST_SRCS-y += xg_private.c
+GUEST_SRCS-y += xg_domain.c
+GUEST_SRCS-y += xc_suspend.c
 ifeq ($(CONFIG_MIGRATE),y)
 GUEST_SRCS-y += xc_sr_common.c
 GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 71829c2bce..fbc22c4df6 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -1892,132 +1892,6 @@ int xc_domain_unbind_pt_spi_irq(xc_interface *xch,
                                         PT_IRQ_TYPE_SPI, 0, 0, 0, 0, spi));
 }
 
-int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *minfo)
-{
-    struct domain_info_context _di = { .guest_width = minfo->guest_width,
-                                       .p2m_size = minfo->p2m_size};
-    struct domain_info_context *dinfo = &_di;
-
-    free(minfo->pfn_type);
-    if ( minfo->p2m_table )
-        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
-    minfo->p2m_table = NULL;
-
-    return 0;
-}
-
-int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
-                          struct xc_domain_meminfo *minfo)
-{
-    struct domain_info_context _di;
-    struct domain_info_context *dinfo = &_di;
-
-    xc_dominfo_t info;
-    shared_info_any_t *live_shinfo;
-    xen_capabilities_info_t xen_caps = "";
-    int i;
-
-    /* Only be initialized once */
-    if ( minfo->pfn_type || minfo->p2m_table )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
-    {
-        PERROR("Could not get domain info");
-        return -1;
-    }
-
-    if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) )
-    {
-        PERROR("Could not get domain address size");
-        return -1;
-    }
-    _di.guest_width = minfo->guest_width;
-
-    /* Get page table levels (see get_platform_info() in xg_save_restore.h */
-    if ( xc_version(xch, XENVER_capabilities, &xen_caps) )
-    {
-        PERROR("Could not get Xen capabilities (for page table levels)");
-        return -1;
-    }
-    if ( strstr(xen_caps, "xen-3.0-x86_64") )
-        /* Depends on whether it's a compat 32-on-64 guest */
-        minfo->pt_levels = ( (minfo->guest_width == 8) ? 4 : 3 );
-    else if ( strstr(xen_caps, "xen-3.0-x86_32p") )
-        minfo->pt_levels = 3;
-    else if ( strstr(xen_caps, "xen-3.0-x86_32") )
-        minfo->pt_levels = 2;
-    else
-    {
-        errno = EFAULT;
-        return -1;
-    }
-
-    /* We need the shared info page for mapping the P2M */
-    live_shinfo = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
-                                       info.shared_info_frame);
-    if ( !live_shinfo )
-    {
-        PERROR("Could not map the shared info frame (MFN 0x%lx)",
-               info.shared_info_frame);
-        return -1;
-    }
-
-    if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info,
-                                       live_shinfo, &minfo->p2m_table,
-                                       &minfo->p2m_size) )
-    {
-        PERROR("Could not map the P2M table");
-        munmap(live_shinfo, PAGE_SIZE);
-        return -1;
-    }
-    munmap(live_shinfo, PAGE_SIZE);
-    _di.p2m_size = minfo->p2m_size;
-
-    /* Make space and prepare for getting the PFN types */
-    minfo->pfn_type = calloc(sizeof(*minfo->pfn_type), minfo->p2m_size);
-    if ( !minfo->pfn_type )
-    {
-        PERROR("Could not allocate memory for the PFN types");
-        goto failed;
-    }
-    for ( i = 0; i < minfo->p2m_size; i++ )
-        minfo->pfn_type[i] = xc_pfn_to_mfn(i, minfo->p2m_table,
-                                           minfo->guest_width);
-
-    /* Retrieve PFN types in batches */
-    for ( i = 0; i < minfo->p2m_size ; i+=1024 )
-    {
-        int count = ((minfo->p2m_size - i ) > 1024 ) ?
-                        1024: (minfo->p2m_size - i);
-
-        if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i) )
-        {
-            PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024);
-            goto failed;
-        }
-    }
-
-    return 0;
-
-failed:
-    if ( minfo->pfn_type )
-    {
-        free(minfo->pfn_type);
-        minfo->pfn_type = NULL;
-    }
-    if ( minfo->p2m_table )
-    {
-        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
-        minfo->p2m_table = NULL;
-    }
-
-    return -1;
-}
-
 int xc_domain_memory_mapping(
     xc_interface *xch,
     uint32_t domid,
diff --git a/tools/libxc/xg_domain.c b/tools/libxc/xg_domain.c
new file mode 100644
index 0000000000..58713cd35d
--- /dev/null
+++ b/tools/libxc/xg_domain.c
@@ -0,0 +1,149 @@
+/******************************************************************************
+ * xg_domain.c
+ *
+ * API for manipulating and obtaining information on domains.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2003, K A Fraser.
+ */
+
+#include "xg_private.h"
+#include "xc_core.h"
+
+int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *minfo)
+{
+    struct domain_info_context _di = { .guest_width = minfo->guest_width,
+                                       .p2m_size = minfo->p2m_size};
+    struct domain_info_context *dinfo = &_di;
+
+    free(minfo->pfn_type);
+    if ( minfo->p2m_table )
+        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
+    minfo->p2m_table = NULL;
+
+    return 0;
+}
+
+int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
+                          struct xc_domain_meminfo *minfo)
+{
+    struct domain_info_context _di;
+    struct domain_info_context *dinfo = &_di;
+
+    xc_dominfo_t info;
+    shared_info_any_t *live_shinfo;
+    xen_capabilities_info_t xen_caps = "";
+    int i;
+
+    /* Only be initialized once */
+    if ( minfo->pfn_type || minfo->p2m_table )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
+    {
+        PERROR("Could not get domain info");
+        return -1;
+    }
+
+    if ( xc_domain_get_guest_width(xch, domid, &minfo->guest_width) )
+    {
+        PERROR("Could not get domain address size");
+        return -1;
+    }
+    _di.guest_width = minfo->guest_width;
+
+    /* Get page table levels (see get_platform_info() in xg_save_restore.h */
+    if ( xc_version(xch, XENVER_capabilities, &xen_caps) )
+    {
+        PERROR("Could not get Xen capabilities (for page table levels)");
+        return -1;
+    }
+    if ( strstr(xen_caps, "xen-3.0-x86_64") )
+        /* Depends on whether it's a compat 32-on-64 guest */
+        minfo->pt_levels = ( (minfo->guest_width == 8) ? 4 : 3 );
+    else if ( strstr(xen_caps, "xen-3.0-x86_32p") )
+        minfo->pt_levels = 3;
+    else if ( strstr(xen_caps, "xen-3.0-x86_32") )
+        minfo->pt_levels = 2;
+    else
+    {
+        errno = EFAULT;
+        return -1;
+    }
+
+    /* We need the shared info page for mapping the P2M */
+    live_shinfo = xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ,
+                                       info.shared_info_frame);
+    if ( !live_shinfo )
+    {
+        PERROR("Could not map the shared info frame (MFN 0x%lx)",
+               info.shared_info_frame);
+        return -1;
+    }
+
+    if ( xc_core_arch_map_p2m_writable(xch, minfo->guest_width, &info,
+                                       live_shinfo, &minfo->p2m_table,
+                                       &minfo->p2m_size) )
+    {
+        PERROR("Could not map the P2M table");
+        munmap(live_shinfo, PAGE_SIZE);
+        return -1;
+    }
+    munmap(live_shinfo, PAGE_SIZE);
+    _di.p2m_size = minfo->p2m_size;
+
+    /* Make space and prepare for getting the PFN types */
+    minfo->pfn_type = calloc(sizeof(*minfo->pfn_type), minfo->p2m_size);
+    if ( !minfo->pfn_type )
+    {
+        PERROR("Could not allocate memory for the PFN types");
+        goto failed;
+    }
+    for ( i = 0; i < minfo->p2m_size; i++ )
+        minfo->pfn_type[i] = xc_pfn_to_mfn(i, minfo->p2m_table,
+                                           minfo->guest_width);
+
+    /* Retrieve PFN types in batches */
+    for ( i = 0; i < minfo->p2m_size ; i+=1024 )
+    {
+        int count = ((minfo->p2m_size - i ) > 1024 ) ?
+                        1024: (minfo->p2m_size - i);
+
+        if ( xc_get_pfn_type_batch(xch, domid, count, minfo->pfn_type + i) )
+        {
+            PERROR("Could not get %d-eth batch of PFN types", (i+1)/1024);
+            goto failed;
+        }
+    }
+
+    return 0;
+
+failed:
+    if ( minfo->pfn_type )
+    {
+        free(minfo->pfn_type);
+        minfo->pfn_type = NULL;
+    }
+    if ( minfo->p2m_table )
+    {
+        munmap(minfo->p2m_table, P2M_FL_ENTRIES * PAGE_SIZE);
+        minfo->p2m_table = NULL;
+    }
+
+    return -1;
+}
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMKX-0006Hh-8V; Fri, 18 Sep 2020 19:46:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMKW-0006Hb-1E
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:00 +0000
X-Inumbo-ID: 4a4d2210-a8fb-4116-81a2-2cdcef7fccfd
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4a4d2210-a8fb-4116-81a2-2cdcef7fccfd;
 Fri, 18 Sep 2020 19:45:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DGBImIYWD3IDq/8g1lVP/NpmFSxn6Li4OKxcPtGgSIY=; b=SQpP8inZzI+YJysNY9u3gWtMuC
 gp0i7WEN+a7pYDYCZfLdrPFwUhf/SxUAPBEUhWGQF0wTxvH6H0XmR/FBA/GaGe/vyZus5ycLxR048
 1giJ75gctZobzkVm92MalNA95N7JT/HakL/yUaFlGKHo+3fXKfm80nM/uKunTZUttoPI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKQ-000761-KC
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:54 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKQ-0004Lr-JT
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:45:54 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: rename all libxenguest sources to xg_*
Message-Id: <E1kJMKQ-0004Lr-JT@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:45:54 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f55893171feb64f712d2892a288e3f3dc70f39d8
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:28 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: rename all libxenguest sources to xg_*
    
    Some sources of libxenguest are named xg_*.c and some xc_*.c. Rename
    the xc_*.c files to xg_*.c.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile                         |   59 +-
 tools/libxc/xc_cpuid_x86.c                   |  665 ---------
 tools/libxc/xc_dom_arm.c                     |  552 --------
 tools/libxc/xc_dom_armzimageloader.c         |  271 ----
 tools/libxc/xc_dom_binloader.c               |  329 -----
 tools/libxc/xc_dom_boot.c                    |  451 ------
 tools/libxc/xc_dom_bzimageloader.c           |  812 -----------
 tools/libxc/xc_dom_compat_linux.c            |   97 --
 tools/libxc/xc_dom_core.c                    | 1272 -----------------
 tools/libxc/xc_dom_decompress_lz4.c          |  141 --
 tools/libxc/xc_dom_decompress_unsafe.c       |   48 -
 tools/libxc/xc_dom_decompress_unsafe_bzip2.c |   14 -
 tools/libxc/xc_dom_decompress_unsafe_lzma.c  |   14 -
 tools/libxc/xc_dom_decompress_unsafe_lzo1x.c |   50 -
 tools/libxc/xc_dom_decompress_unsafe_xz.c    |   46 -
 tools/libxc/xc_dom_elfloader.c               |  249 ----
 tools/libxc/xc_dom_hvmloader.c               |  264 ----
 tools/libxc/xc_dom_x86.c                     | 1945 --------------------------
 tools/libxc/xc_nomigrate.c                   |   50 -
 tools/libxc/xc_offline_page.c                |  708 ----------
 tools/libxc/xc_sr_common.c                   |  167 ---
 tools/libxc/xc_sr_common_x86.c               |  173 ---
 tools/libxc/xc_sr_common_x86_pv.c            |  193 ---
 tools/libxc/xc_sr_restore.c                  |  986 -------------
 tools/libxc/xc_sr_restore_x86_hvm.c          |  274 ----
 tools/libxc/xc_sr_restore_x86_pv.c           | 1210 ----------------
 tools/libxc/xc_sr_save.c                     | 1059 --------------
 tools/libxc/xc_sr_save_x86_hvm.c             |  251 ----
 tools/libxc/xc_sr_save_x86_pv.c              | 1156 ---------------
 tools/libxc/xc_suspend.c                     |  202 ---
 tools/libxc/xg_cpuid_x86.c                   |  665 +++++++++
 tools/libxc/xg_dom_arm.c                     |  552 ++++++++
 tools/libxc/xg_dom_armzimageloader.c         |  271 ++++
 tools/libxc/xg_dom_binloader.c               |  329 +++++
 tools/libxc/xg_dom_boot.c                    |  451 ++++++
 tools/libxc/xg_dom_bzimageloader.c           |  812 +++++++++++
 tools/libxc/xg_dom_compat_linux.c            |   97 ++
 tools/libxc/xg_dom_core.c                    | 1272 +++++++++++++++++
 tools/libxc/xg_dom_decompress_lz4.c          |  141 ++
 tools/libxc/xg_dom_decompress_unsafe.c       |   48 +
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c |   14 +
 tools/libxc/xg_dom_decompress_unsafe_lzma.c  |   14 +
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c |   50 +
 tools/libxc/xg_dom_decompress_unsafe_xz.c    |   46 +
 tools/libxc/xg_dom_elfloader.c               |  249 ++++
 tools/libxc/xg_dom_hvmloader.c               |  264 ++++
 tools/libxc/xg_dom_x86.c                     | 1945 ++++++++++++++++++++++++++
 tools/libxc/xg_nomigrate.c                   |   50 +
 tools/libxc/xg_offline_page.c                |  708 ++++++++++
 tools/libxc/xg_sr_common.c                   |  167 +++
 tools/libxc/xg_sr_common_x86.c               |  173 +++
 tools/libxc/xg_sr_common_x86_pv.c            |  193 +++
 tools/libxc/xg_sr_restore.c                  |  986 +++++++++++++
 tools/libxc/xg_sr_restore_x86_hvm.c          |  274 ++++
 tools/libxc/xg_sr_restore_x86_pv.c           | 1210 ++++++++++++++++
 tools/libxc/xg_sr_save.c                     | 1059 ++++++++++++++
 tools/libxc/xg_sr_save_x86_hvm.c             |  251 ++++
 tools/libxc/xg_sr_save_x86_pv.c              | 1156 +++++++++++++++
 tools/libxc/xg_suspend.c                     |  202 +++
 59 files changed, 13679 insertions(+), 13678 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 7b81f8c193..0fd5511143 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -54,20 +54,20 @@ CTRL_SRCS-y       += xc_devicemodel_compat.c
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c
 GUEST_SRCS-y += xg_domain.c
-GUEST_SRCS-y += xc_suspend.c
+GUEST_SRCS-y += xg_suspend.c
 ifeq ($(CONFIG_MIGRATE),y)
-GUEST_SRCS-y += xc_sr_common.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_hvm.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c
-GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c
-GUEST_SRCS-y += xc_sr_restore.c
-GUEST_SRCS-y += xc_sr_save.c
-GUEST_SRCS-y += xc_offline_page.c
+GUEST_SRCS-y += xg_sr_common.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_common_x86.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_common_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_restore_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_restore_x86_hvm.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_save_x86_pv.c
+GUEST_SRCS-$(CONFIG_X86) += xg_sr_save_x86_hvm.c
+GUEST_SRCS-y += xg_sr_restore.c
+GUEST_SRCS-y += xg_sr_save.c
+GUEST_SRCS-y += xg_offline_page.c
 else
-GUEST_SRCS-y += xc_nomigrate.c
+GUEST_SRCS-y += xg_nomigrate.c
 endif
 
 vpath %.c ../../xen/common/libelf
@@ -88,25 +88,26 @@ GUEST_SRCS-y                 += cpuid.c msr.c
 endif
 
 # new domain builder
-GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
-GUEST_SRCS-y                 += xc_dom_elfloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_decompress_lz4.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_hvmloader.c
-GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_armzimageloader.c
-GUEST_SRCS-y                 += xc_dom_binloader.c
-GUEST_SRCS-y                 += xc_dom_compat_linux.c
-
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_cpuid_x86.c
-GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_arm.c
+GUEST_SRCS-y                 += xg_dom_core.c
+GUEST_SRCS-y                 += xg_dom_boot.c
+GUEST_SRCS-y                 += xg_dom_elfloader.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_bzimageloader.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_decompress_lz4.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_hvmloader.c
+GUEST_SRCS-$(CONFIG_ARM)     += xg_dom_armzimageloader.c
+GUEST_SRCS-y                 += xg_dom_binloader.c
+GUEST_SRCS-y                 += xg_dom_compat_linux.c
+
+GUEST_SRCS-$(CONFIG_X86)     += xg_dom_x86.c
+GUEST_SRCS-$(CONFIG_X86)     += xg_cpuid_x86.c
+GUEST_SRCS-$(CONFIG_ARM)     += xg_dom_arm.c
 
 ifeq ($(CONFIG_LIBXC_MINIOS),y)
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_bzip2.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzma.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzo1x.c
-GUEST_SRCS-y                 += xc_dom_decompress_unsafe_xz.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_bzip2.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_lzma.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_lzo1x.c
+GUEST_SRCS-y                 += xg_dom_decompress_unsafe_xz.c
 endif
 
 -include $(XEN_TARGET_ARCH)/Makefile
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
deleted file mode 100644
index 0f24d6dd08..0000000000
--- a/tools/libxc/xc_cpuid_x86.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/******************************************************************************
- * xc_cpuid_x86.c
- *
- * Compute cpuid of a domain.
- *
- * Copyright (c) 2008, Citrix Systems, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <limits.h>
-#include "xc_private.h"
-#include "xc_bitops.h"
-#include <xen/hvm/params.h>
-#include <xen-tools/libs.h>
-
-enum {
-#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
-#include <xen/arch-x86/cpufeatureset.h>
-};
-
-#include <xen/asm/x86-vendors.h>
-
-#include <xen/lib/x86/cpu-policy.h>
-
-#define bitmaskof(idx)      (1u << ((idx) & 31))
-#define featureword_of(idx) ((idx) >> 5)
-
-int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps)
-{
-    DECLARE_SYSCTL;
-    int ret;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_levelling_caps;
-    ret = do_sysctl(xch, &sysctl);
-
-    if ( !ret )
-        *caps = sysctl.u.cpu_levelling_caps.caps;
-
-    return ret;
-}
-
-int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
-                          uint32_t *nr_features, uint32_t *featureset)
-{
-    DECLARE_SYSCTL;
-    DECLARE_HYPERCALL_BOUNCE(featureset,
-                             *nr_features * sizeof(*featureset),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, featureset) )
-        return -1;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_featureset;
-    sysctl.u.cpu_featureset.index = index;
-    sysctl.u.cpu_featureset.nr_features = *nr_features;
-    set_xen_guest_handle(sysctl.u.cpu_featureset.features, featureset);
-
-    ret = do_sysctl(xch, &sysctl);
-
-    xc_hypercall_bounce_post(xch, featureset);
-
-    if ( !ret )
-        *nr_features = sysctl.u.cpu_featureset.nr_features;
-
-    return ret;
-}
-
-uint32_t xc_get_cpu_featureset_size(void)
-{
-    return FEATURESET_NR_ENTRIES;
-}
-
-const uint32_t *xc_get_static_cpu_featuremask(
-    enum xc_static_cpu_featuremask mask)
-{
-    static const uint32_t masks[][FEATURESET_NR_ENTRIES] = {
-#define MASK(x) [XC_FEATUREMASK_ ## x] = INIT_ ## x ## _FEATURES
-
-        MASK(KNOWN),
-        MASK(SPECIAL),
-        MASK(PV_MAX),
-        MASK(PV_DEF),
-        MASK(HVM_SHADOW_MAX),
-        MASK(HVM_SHADOW_DEF),
-        MASK(HVM_HAP_MAX),
-        MASK(HVM_HAP_DEF),
-
-#undef MASK
-    };
-
-    if ( (unsigned int)mask >= ARRAY_SIZE(masks) )
-        return NULL;
-
-    return masks[mask];
-}
-
-int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
-                           uint32_t *nr_msrs)
-{
-    struct xen_sysctl sysctl = {};
-    int ret;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
-
-    ret = do_sysctl(xch, &sysctl);
-
-    if ( !ret )
-    {
-        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
-                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
-{
-    struct xen_sysctl sysctl = {};
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) ||
-         xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
-    sysctl.u.cpu_policy.index = index;
-    sysctl.u.cpu_policy.nr_leaves = *nr_leaves;
-    set_xen_guest_handle(sysctl.u.cpu_policy.cpuid_policy, leaves);
-    sysctl.u.cpu_policy.nr_msrs = *nr_msrs;
-    set_xen_guest_handle(sysctl.u.cpu_policy.msr_policy, msrs);
-
-    ret = do_sysctl(xch, &sysctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( !ret )
-    {
-        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
-                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
-{
-    DECLARE_DOMCTL;
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    int ret;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) ||
-         xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    domctl.cmd = XEN_DOMCTL_get_cpu_policy;
-    domctl.domain = domid;
-    domctl.u.cpu_policy.nr_leaves = *nr_leaves;
-    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
-    domctl.u.cpu_policy.nr_msrs = *nr_msrs;
-    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
-
-    ret = do_domctl(xch, &domctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( !ret )
-    {
-        *nr_leaves = domctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = domctl.u.cpu_policy.nr_msrs;
-    }
-
-    return ret;
-}
-
-int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
-                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
-                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
-                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
-                             uint32_t *err_msr_p)
-{
-    DECLARE_DOMCTL;
-    DECLARE_HYPERCALL_BOUNCE(leaves,
-                             nr_leaves * sizeof(*leaves),
-                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
-    DECLARE_HYPERCALL_BOUNCE(msrs,
-                             nr_msrs * sizeof(*msrs),
-                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
-    int ret;
-
-    if ( err_leaf_p )
-        *err_leaf_p = -1;
-    if ( err_subleaf_p )
-        *err_subleaf_p = -1;
-    if ( err_msr_p )
-        *err_msr_p = -1;
-
-    if ( xc_hypercall_bounce_pre(xch, leaves) )
-        return -1;
-
-    if ( xc_hypercall_bounce_pre(xch, msrs) )
-        return -1;
-
-    domctl.cmd = XEN_DOMCTL_set_cpu_policy;
-    domctl.domain = domid;
-    domctl.u.cpu_policy.nr_leaves = nr_leaves;
-    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
-    domctl.u.cpu_policy.nr_msrs = nr_msrs;
-    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
-    domctl.u.cpu_policy.err_leaf = -1;
-    domctl.u.cpu_policy.err_subleaf = -1;
-    domctl.u.cpu_policy.err_msr = -1;
-
-    ret = do_domctl(xch, &domctl);
-
-    xc_hypercall_bounce_post(xch, leaves);
-    xc_hypercall_bounce_post(xch, msrs);
-
-    if ( err_leaf_p )
-        *err_leaf_p = domctl.u.cpu_policy.err_leaf;
-    if ( err_subleaf_p )
-        *err_subleaf_p = domctl.u.cpu_policy.err_subleaf;
-    if ( err_msr_p )
-        *err_msr_p = domctl.u.cpu_policy.err_msr;
-
-    return ret;
-}
-
-static int compare_leaves(const void *l, const void *r)
-{
-    const xen_cpuid_leaf_t *lhs = l;
-    const xen_cpuid_leaf_t *rhs = r;
-
-    if ( lhs->leaf != rhs->leaf )
-        return lhs->leaf < rhs->leaf ? -1 : 1;
-
-    if ( lhs->subleaf != rhs->subleaf )
-        return lhs->subleaf < rhs->subleaf ? -1 : 1;
-
-    return 0;
-}
-
-static xen_cpuid_leaf_t *find_leaf(
-    xen_cpuid_leaf_t *leaves, unsigned int nr_leaves,
-    const struct xc_xend_cpuid *xend)
-{
-    const xen_cpuid_leaf_t key = { xend->leaf, xend->subleaf };
-
-    return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves);
-}
-
-static int xc_cpuid_xend_policy(
-    xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend)
-{
-    int rc;
-    xc_dominfo_t di;
-    unsigned int nr_leaves, nr_msrs;
-    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
-    /*
-     * Three full policies.  The host, domain max, and domain current for the
-     * domain type.
-     */
-    xen_cpuid_leaf_t *host = NULL, *max = NULL, *cur = NULL;
-    unsigned int nr_host, nr_max, nr_cur;
-
-    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
-         di.domid != domid )
-    {
-        ERROR("Failed to obtain d%d info", domid);
-        rc = -ESRCH;
-        goto fail;
-    }
-
-    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
-    if ( rc )
-    {
-        PERROR("Failed to obtain policy info size");
-        rc = -errno;
-        goto fail;
-    }
-
-    rc = -ENOMEM;
-    if ( (host = calloc(nr_leaves, sizeof(*host))) == NULL ||
-         (max  = calloc(nr_leaves, sizeof(*max)))  == NULL ||
-         (cur  = calloc(nr_leaves, sizeof(*cur)))  == NULL )
-    {
-        ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves);
-        goto fail;
-    }
-
-    /* Get the domain's current policy. */
-    nr_msrs = 0;
-    nr_cur = nr_leaves;
-    rc = xc_get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain d%d current policy", domid);
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Get the domain's max policy. */
-    nr_msrs = 0;
-    nr_max = nr_leaves;
-    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max
-                                              : XEN_SYSCTL_cpu_policy_pv_max,
-                                  &nr_max, max, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv");
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Get the host policy. */
-    nr_msrs = 0;
-    nr_host = nr_leaves;
-    rc = xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host,
-                                  &nr_host, host, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain host policy");
-        rc = -errno;
-        goto fail;
-    }
-
-    rc = -EINVAL;
-    for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend )
-    {
-        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend);
-        const xen_cpuid_leaf_t *max_leaf = find_leaf(max, nr_max, xend);
-        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend);
-
-        if ( cur_leaf == NULL || max_leaf == NULL || host_leaf == NULL )
-        {
-            ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->subleaf);
-            goto fail;
-        }
-
-        for ( unsigned int i = 0; i < ARRAY_SIZE(xend->policy); i++ )
-        {
-            uint32_t *cur_reg = &cur_leaf->a + i;
-            const uint32_t *max_reg = &max_leaf->a + i;
-            const uint32_t *host_reg = &host_leaf->a + i;
-
-            if ( xend->policy[i] == NULL )
-                continue;
-
-            for ( unsigned int j = 0; j < 32; j++ )
-            {
-                bool val;
-
-                if ( xend->policy[i][j] == '1' )
-                    val = true;
-                else if ( xend->policy[i][j] == '0' )
-                    val = false;
-                else if ( xend->policy[i][j] == 'x' )
-                    val = test_bit(31 - j, max_reg);
-                else if ( xend->policy[i][j] == 'k' ||
-                          xend->policy[i][j] == 's' )
-                    val = test_bit(31 - j, host_reg);
-                else
-                {
-                    ERROR("Bad character '%c' in policy[%d] string '%s'",
-                          xend->policy[i][j], i, xend->policy[i]);
-                    goto fail;
-                }
-
-                clear_bit(31 - j, cur_reg);
-                if ( val )
-                    set_bit(31 - j, cur_reg);
-            }
-        }
-    }
-
-    /* Feed the transformed currrent policy back up to Xen. */
-    rc = xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL,
-                                  &err_leaf, &err_subleaf, &err_msr);
-    if ( rc )
-    {
-        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
-               domid, err_leaf, err_subleaf, err_msr);
-        rc = -errno;
-        goto fail;
-    }
-
-    /* Success! */
-
- fail:
-    free(cur);
-    free(max);
-    free(host);
-
-    return rc;
-}
-
-int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
-                          const uint32_t *featureset, unsigned int nr_features,
-                          bool pae,
-                          const struct xc_xend_cpuid *xend)
-{
-    int rc;
-    xc_dominfo_t di;
-    unsigned int i, nr_leaves, nr_msrs;
-    xen_cpuid_leaf_t *leaves = NULL;
-    struct cpuid_policy *p = NULL;
-    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
-    uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {};
-    uint32_t len = ARRAY_SIZE(host_featureset);
-
-    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
-         di.domid != domid )
-    {
-        ERROR("Failed to obtain d%d info", domid);
-        rc = -ESRCH;
-        goto out;
-    }
-
-    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
-    if ( rc )
-    {
-        PERROR("Failed to obtain policy info size");
-        rc = -errno;
-        goto out;
-    }
-
-    rc = -ENOMEM;
-    if ( (leaves = calloc(nr_leaves, sizeof(*leaves))) == NULL ||
-         (p = calloc(1, sizeof(*p))) == NULL )
-        goto out;
-
-    /* Get the host policy. */
-    rc = xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host,
-                               &len, host_featureset);
-    if ( rc )
-    {
-        /* Tolerate "buffer too small", as we've got the bits we need. */
-        if ( errno == ENOBUFS )
-            rc = 0;
-        else
-        {
-            PERROR("Failed to obtain host featureset");
-            rc = -errno;
-            goto out;
-        }
-    }
-
-    /* Get the domain's default policy. */
-    nr_msrs = 0;
-    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default
-                                              : XEN_SYSCTL_cpu_policy_pv_default,
-                                  &nr_leaves, leaves, &nr_msrs, NULL);
-    if ( rc )
-    {
-        PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv");
-        rc = -errno;
-        goto out;
-    }
-
-    rc = x86_cpuid_copy_from_buffer(p, leaves, nr_leaves,
-                                    &err_leaf, &err_subleaf);
-    if ( rc )
-    {
-        ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)",
-              err_leaf, err_subleaf, -rc, strerror(-rc));
-        goto out;
-    }
-
-    /*
-     * Account for feature which have been disabled by default since Xen 4.13,
-     * so migrated-in VM's don't risk seeing features disappearing.
-     */
-    if ( restore )
-    {
-        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
-
-        if ( di.hvm )
-        {
-            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
-        }
-    }
-
-    if ( featureset )
-    {
-        uint32_t disabled_features[FEATURESET_NR_ENTRIES],
-            feat[FEATURESET_NR_ENTRIES] = {};
-        static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
-        unsigned int i, b;
-
-        /*
-         * The user supplied featureset may be shorter or longer than
-         * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
-         * Longer is fine, so long as it only padded with zeros.
-         */
-        unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
-
-        /* Check for truncated set bits. */
-        rc = -EOPNOTSUPP;
-        for ( i = user_len; i < nr_features; ++i )
-            if ( featureset[i] != 0 )
-                goto out;
-
-        memcpy(feat, featureset, sizeof(*featureset) * user_len);
-
-        /* Disable deep dependencies of disabled features. */
-        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            disabled_features[i] = ~feat[i] & deep_features[i];
-
-        for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
-        {
-            const uint32_t *dfs;
-
-            if ( !test_bit(b, disabled_features) ||
-                 !(dfs = x86_cpuid_lookup_deep_deps(b)) )
-                continue;
-
-            for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            {
-                feat[i] &= ~dfs[i];
-                disabled_features[i] &= ~dfs[i];
-            }
-        }
-
-        cpuid_featureset_to_policy(feat, p);
-    }
-    else
-    {
-        if ( di.hvm )
-            p->basic.pae = pae;
-    }
-
-    if ( !di.hvm )
-    {
-        /*
-         * On hardware without CPUID Faulting, PV guests see real topology.
-         * As a consequence, they also need to see the host htt/cmp fields.
-         */
-        p->basic.htt       = test_bit(X86_FEATURE_HTT, host_featureset);
-        p->extd.cmp_legacy = test_bit(X86_FEATURE_CMP_LEGACY, host_featureset);
-    }
-    else
-    {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
-        p->extd.cmp_legacy = false;
-
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-
-        switch ( p->x86_vendor )
-        {
-        case X86_VENDOR_INTEL:
-            for ( i = 0; (p->cache.subleaf[i].type &&
-                          i < ARRAY_SIZE(p->cache.raw)); ++i )
-            {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
-                p->cache.subleaf[i].threads_per_cache = 0;
-            }
-            break;
-
-        case X86_VENDOR_AMD:
-        case X86_VENDOR_HYGON:
-            /*
-             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
-             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
-             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
-             * - overflow,
-             * - going out of sync with leaf 1 EBX[23:16],
-             * - incrementing ApicIdCoreSize when it's zero (which changes the
-             *   meaning of bits 7:0).
-             *
-             * UPDATE: I addition to avoiding overflow, some
-             * proprietary operating systems have trouble with
-             * apic_id_size values greater than 7.  Limit the value to
-             * 7 for now.
-             */
-            if ( p->extd.nc < 0x7f )
-            {
-                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size < 0x7 )
-                    p->extd.apic_id_size++;
-
-                p->extd.nc = (p->extd.nc << 1) | 1;
-            }
-            break;
-        }
-
-        /*
-         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
-         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
-         * CPUID.  Xen will discard these bits if configuration hasn't been
-         * set for the domain.
-         */
-        p->extd.itsc = true;
-        p->basic.vmx = true;
-        p->extd.svm = true;
-    }
-
-    rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
-    if ( rc )
-    {
-        ERROR("Failed to serialise CPUID (%d = %s)", -rc, strerror(-rc));
-        goto out;
-    }
-
-    rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL,
-                                  &err_leaf, &err_subleaf, &err_msr);
-    if ( rc )
-    {
-        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
-               domid, err_leaf, err_subleaf, err_msr);
-        rc = -errno;
-        goto out;
-    }
-
-    if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) )
-        goto out;
-
-    rc = 0;
-
-out:
-    free(p);
-    free(leaves);
-
-    return rc;
-}
diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
deleted file mode 100644
index 931404c222..0000000000
--- a/tools/libxc/xc_dom_arm.c
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Xen domain builder -- ARM
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (c) 2011, Citrix Systems
- */
-#include <inttypes.h>
-#include <assert.h>
-
-#include <xen/xen.h>
-#include <xen/io/protocols.h>
-#include <xen-tools/libs.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#define NR_MAGIC_PAGES 4
-#define CONSOLE_PFN_OFFSET 0
-#define XENSTORE_PFN_OFFSET 1
-#define MEMACCESS_PFN_OFFSET 2
-#define VUART_PFN_OFFSET 3
-
-#define LPAE_SHIFT 9
-
-#define PFN_4K_SHIFT  (0)
-#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
-#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
-#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
-
-/* get guest IO ABI protocol */
-const char *xc_domain_get_native_protocol(xc_interface *xch,
-                                          uint32_t domid)
-{
-    return XEN_IO_PROTO_ABI_ARM;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int alloc_magic_pages(struct xc_dom_image *dom)
-{
-    int rc, i;
-    const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
-    xen_pfn_t p2m[NR_MAGIC_PAGES];
-
-    BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    for (i = 0; i < NR_MAGIC_PAGES; i++)
-        p2m[i] = base + i;
-
-    rc = xc_domain_populate_physmap_exact(
-            dom->xch, dom->guest_domid, NR_MAGIC_PAGES,
-            0, 0, p2m);
-    if ( rc < 0 )
-        return rc;
-
-    dom->console_pfn = base + CONSOLE_PFN_OFFSET;
-    dom->xenstore_pfn = base + XENSTORE_PFN_OFFSET;
-    dom->vuart_gfn = base + VUART_PFN_OFFSET;
-
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, base + MEMACCESS_PFN_OFFSET);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->vuart_gfn);
-
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
-            dom->console_pfn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
-            dom->xenstore_pfn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MONITOR_RING_PFN,
-            base + MEMACCESS_PFN_OFFSET);
-    /* allocated by toolstack */
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN,
-            dom->console_evtchn);
-    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN,
-            dom->xenstore_evtchn);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int start_info_arm(struct xc_dom_image *dom)
-{
-    DOMPRINTF_CALLED(dom->xch);
-    return 0;
-}
-
-static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
-{
-    DOMPRINTF_CALLED(dom->xch);
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int vcpu_arm32(struct xc_dom_image *dom)
-{
-    vcpu_guest_context_any_t any_ctx;
-    vcpu_guest_context_t *ctxt = &any_ctx.c;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    /* clear everything */
-    memset(ctxt, 0, sizeof(*ctxt));
-
-    ctxt->user_regs.pc32 = dom->parms.virt_entry;
-
-    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
-    ctxt->user_regs.r0_usr = 0; /* SBZ */
-    /* Machine ID: We use DTB therefore no machine id */
-    ctxt->user_regs.r1_usr = 0xffffffff;
-    /* ATAGS/DTB: We currently require that the guest kernel to be
-     * using CONFIG_ARM_APPENDED_DTB. Ensure that r2 does not look
-     * like a valid pointer to a set of ATAGS or a DTB.
-     */
-    ctxt->user_regs.r2_usr = dom->devicetree_blob ?
-        dom->devicetree_seg.vstart : 0xffffffff;
-
-    ctxt->sctlr = SCTLR_GUEST_INIT;
-
-    ctxt->ttbr0 = 0;
-    ctxt->ttbr1 = 0;
-    ctxt->ttbcr = 0; /* Defined Reset Value */
-
-    ctxt->user_regs.cpsr = PSR_GUEST32_INIT;
-
-    ctxt->flags = VGCF_online;
-
-    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx32,
-           ctxt->user_regs.cpsr, ctxt->user_regs.pc32);
-
-    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
-
-    return rc;
-}
-
-static int vcpu_arm64(struct xc_dom_image *dom)
-{
-    vcpu_guest_context_any_t any_ctx;
-    vcpu_guest_context_t *ctxt = &any_ctx.c;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-    /* clear everything */
-    memset(ctxt, 0, sizeof(*ctxt));
-
-    ctxt->user_regs.pc64 = dom->parms.virt_entry;
-
-    /* Linux boot protocol. See linux.Documentation/arm64/booting.txt. */
-    ctxt->user_regs.x0 = dom->devicetree_blob ?
-        dom->devicetree_seg.vstart : 0xffffffff;
-    ctxt->user_regs.x1 = 0;
-    ctxt->user_regs.x2 = 0;
-    ctxt->user_regs.x3 = 0;
-
-    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
-
-    ctxt->sctlr = SCTLR_GUEST_INIT;
-
-    ctxt->ttbr0 = 0;
-    ctxt->ttbr1 = 0;
-    ctxt->ttbcr = 0; /* Defined Reset Value */
-
-    ctxt->user_regs.cpsr = PSR_GUEST64_INIT;
-
-    ctxt->flags = VGCF_online;
-
-    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
-           ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
-
-    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
-
-    return rc;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int set_mode(xc_interface *xch, uint32_t domid, char *guest_type)
-{
-    static const struct {
-        char           *guest;
-        uint32_t        size;
-    } types[] = {
-        { "xen-3.0-aarch64", 64 },
-        { "xen-3.0-armv7l",  32 },
-    };
-    DECLARE_DOMCTL;
-    int i,rc;
-
-    domctl.domain = domid;
-    domctl.cmd    = XEN_DOMCTL_set_address_size;
-    domctl.u.address_size.size = 0;
-
-    for ( i = 0; i < ARRAY_SIZE(types); i++ )
-        if ( !strcmp(types[i].guest, guest_type) )
-            domctl.u.address_size.size = types[i].size;
-    if ( domctl.u.address_size.size == 0 )
-    {
-        xc_dom_printf(xch, "%s: warning: unknown guest type %s",
-                      __FUNCTION__, guest_type);
-        return -EINVAL;
-    }
-
-    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
-                  guest_type, domctl.u.address_size.size);
-    rc = do_domctl(xch, &domctl);
-    if ( rc != 0 )
-        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
-                      __FUNCTION__, rc);
-    return rc;
-}
-
-/*  >0: success, *nr_pfns set to number actually populated
- *   0: didn't try with this pfn shift (e.g. misaligned base etc)
- *  <0: ERROR
- */
-static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
-                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns,
-                             xen_pfn_t *extents)
-{
-    /* The mask for this level */
-    const uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
-    /* The shift, mask and next boundary for the level above this one */
-    const int next_shift = pfn_shift + LPAE_SHIFT;
-    const uint64_t next_mask = ((uint64_t)1<<next_shift)-1;
-    const xen_pfn_t next_boundary
-        = (base_pfn + ((uint64_t)1<<next_shift)) & ~next_mask;
-
-    int nr, i, count;
-    xen_pfn_t end_pfn = base_pfn + *nr_pfns;
-
-    /* No level zero super pages with current hardware */
-    if ( pfn_shift == PFN_512G_SHIFT )
-        return 0;
-
-    /* base is misaligned for this level */
-    if ( mask & base_pfn )
-        return 0;
-
-    /*
-     * If base is not aligned at the next level up then try and make
-     * it so for next time around.
-     */
-    if ( (base_pfn & next_mask) && end_pfn > next_boundary )
-        end_pfn = next_boundary;
-
-    count = ( end_pfn - base_pfn ) >> pfn_shift;
-
-    /* Nothing to allocate */
-    if ( !count )
-        return 0;
-
-    for ( i = 0 ; i < count ; i ++ )
-        extents[i] = base_pfn + (i<<pfn_shift);
-
-    nr = xc_domain_populate_physmap(dom->xch, dom->guest_domid, count,
-                                    pfn_shift, 0, extents);
-    if ( nr <= 0 ) return nr;
-    DOMPRINTF("%s: populated %#x/%#x entries with shift %d",
-              __FUNCTION__, nr, count, pfn_shift);
-
-    *nr_pfns = nr << pfn_shift;
-
-    return 1;
-}
-
-static int populate_guest_memory(struct xc_dom_image *dom,
-                                 xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
-{
-    int rc = 0;
-    xen_pfn_t allocsz, pfn, *extents;
-
-    extents = calloc(1024*1024,sizeof(xen_pfn_t));
-    if ( extents == NULL )
-    {
-        DOMPRINTF("%s: Unable to allocate extent array", __FUNCTION__);
-        return -1;
-    }
-
-    DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
-              __FUNCTION__,
-              (uint64_t)base_pfn << XC_PAGE_SHIFT,
-              (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
-              (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
-
-    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
-    {
-        allocsz = min_t(int, 1024*1024, nr_pfns - pfn);
-#if 0 /* Enable this to exercise/debug the code which tries to realign
-       * to a superpage boundary, by misaligning at the start. */
-        if ( pfn == 0 )
-        {
-            allocsz = 1;
-            rc = populate_one_size(dom, PFN_4K_SHIFT,
-                                   base_pfn + pfn, &allocsz, extents);
-            if (rc < 0) break;
-            if (rc > 0) continue;
-            /* Failed to allocate a single page? */
-            break;
-        }
-#endif
-
-        rc = populate_one_size(dom, PFN_512G_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_1G_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_2M_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc > 0 ) continue;
-
-        rc = populate_one_size(dom, PFN_4K_SHIFT,
-                               base_pfn + pfn, &allocsz, extents);
-        if ( rc < 0 ) break;
-        if ( rc == 0 )
-        {
-            DOMPRINTF("%s: Not enough RAM", __FUNCTION__);
-            errno = ENOMEM;
-            rc = -1;
-            goto out;
-        }
-    }
-
-out:
-    free(extents);
-    return rc < 0 ? rc : 0;
-}
-
-static int meminit(struct xc_dom_image *dom)
-{
-    int i, rc;
-    uint64_t modbase;
-
-    uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT;
-
-    const uint64_t bankbase[] = GUEST_RAM_BANK_BASES;
-    const uint64_t bankmax[] = GUEST_RAM_BANK_SIZES;
-
-    /* Convenient */
-    const uint64_t kernbase = dom->kernel_seg.vstart;
-    const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
-    const uint64_t kernsize = kernend - kernbase;
-    const uint64_t dtb_size = dom->devicetree_blob ?
-        ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
-    const uint64_t ramdisk_size = dom->modules[0].blob ?
-        ROUNDUP(dom->modules[0].size, XC_PAGE_SHIFT) : 0;
-    const uint64_t modsize = dtb_size + ramdisk_size;
-    const uint64_t ram128mb = bankbase[0] + (128<<20);
-
-    xen_pfn_t p2m_size;
-    uint64_t bank0end;
-
-    assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
-
-    if ( modsize + kernsize > bankmax[0] )
-    {
-        DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
-                  __FUNCTION__);
-        return -1;
-    }
-
-    if ( ramsize == 0 )
-    {
-        DOMPRINTF("%s: ram size is 0", __FUNCTION__);
-        return -1;
-    }
-
-    if ( ramsize > GUEST_RAM_MAX )
-    {
-        DOMPRINTF("%s: ram size is too large for guest address space: "
-                  "%"PRIx64" > %llx",
-                  __FUNCTION__, ramsize, GUEST_RAM_MAX);
-        return -1;
-    }
-
-    rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
-    if ( rc )
-        return rc;
-
-    for ( i = 0; ramsize && i < GUEST_RAM_BANKS; i++ )
-    {
-        uint64_t banksize = ramsize > bankmax[i] ? bankmax[i] : ramsize;
-
-        ramsize -= banksize;
-
-        p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT;
-
-        dom->rambank_size[i] = banksize >> XC_PAGE_SHIFT;
-    }
-
-    assert(dom->rambank_size[0] != 0);
-    assert(ramsize == 0); /* Too much RAM is rejected above */
-
-    dom->p2m_size = p2m_size;
-
-    /* setup initial p2m and allocate guest memory */
-    for ( i = 0; i < GUEST_RAM_BANKS && dom->rambank_size[i]; i++ )
-    {
-        if ((rc = populate_guest_memory(dom,
-                                        bankbase[i] >> XC_PAGE_SHIFT,
-                                        dom->rambank_size[i])))
-            return rc;
-    }
-
-    /*
-     * We try to place dtb+initrd at 128MB or if we have less RAM
-     * as high as possible. If there is no space then fallback to
-     * just before the kernel.
-     *
-     * If changing this then consider
-     * xen/arch/arm/kernel.c:place_modules as well.
-     */
-    bank0end = bankbase[0] + ((uint64_t)dom->rambank_size[0] << XC_PAGE_SHIFT);
-
-    if ( bank0end >= ram128mb + modsize && kernend < ram128mb )
-        modbase = ram128mb;
-    else if ( bank0end - modsize > kernend )
-        modbase = bank0end - modsize;
-    else if (kernbase - bankbase[0] > modsize )
-        modbase = kernbase - modsize;
-    else
-        return -1;
-
-    DOMPRINTF("%s: placing boot modules at 0x%" PRIx64, __FUNCTION__, modbase);
-
-    /*
-     * Must map DTB *after* initrd, to satisfy order of calls to
-     * xc_dom_alloc_segment in xc_dom_build_image, which must map
-     * things at monotonolically increasing addresses.
-     */
-    if ( ramdisk_size )
-    {
-        dom->modules[0].seg.vstart = modbase;
-        dom->modules[0].seg.vend = modbase + ramdisk_size;
-
-        DOMPRINTF("%s: ramdisk: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-                  __FUNCTION__,
-                  dom->modules[0].seg.vstart, dom->modules[0].seg.vend);
-
-        modbase += ramdisk_size;
-    }
-
-    if ( dtb_size )
-    {
-        dom->devicetree_seg.vstart = modbase;
-        dom->devicetree_seg.vend = modbase + dtb_size;
-
-        DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-                  __FUNCTION__,
-                  dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
-
-        modbase += dtb_size;
-    }
-
-    return 0;
-}
-
-bool xc_dom_translated(const struct xc_dom_image *dom)
-{
-    return true;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static int bootearly(struct xc_dom_image *dom)
-{
-    DOMPRINTF("%s: doing nothing", __FUNCTION__);
-    return 0;
-}
-
-static int bootlate(struct xc_dom_image *dom)
-{
-    /* XXX
-     *   map shared info
-     *   map grant tables
-     *   setup shared info
-     */
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static struct xc_dom_arch xc_dom_32 = {
-    .guest_type = "xen-3.0-armv7l",
-    .native_protocol = XEN_IO_PROTO_ABI_ARM,
-    .page_shift = PAGE_SHIFT_ARM,
-    .sizeof_pfn = 8,
-    .alloc_magic_pages = alloc_magic_pages,
-    .start_info = start_info_arm,
-    .shared_info = shared_info_arm,
-    .vcpu = vcpu_arm32,
-    .meminit = meminit,
-    .bootearly = bootearly,
-    .bootlate = bootlate,
-};
-
-static struct xc_dom_arch xc_dom_64 = {
-    .guest_type = "xen-3.0-aarch64",
-    .native_protocol = XEN_IO_PROTO_ABI_ARM,
-    .page_shift = PAGE_SHIFT_ARM,
-    .sizeof_pfn = 8,
-    .alloc_magic_pages = alloc_magic_pages,
-    .start_info = start_info_arm,
-    .shared_info = shared_info_arm,
-    .vcpu = vcpu_arm64,
-    .meminit = meminit,
-    .bootearly = bootearly,
-    .bootlate = bootlate,
-};
-
-static void __init register_arch_hooks(void)
-{
-    xc_dom_register_arch_hooks(&xc_dom_32);
-    xc_dom_register_arch_hooks(&xc_dom_64);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_armzimageloader.c b/tools/libxc/xc_dom_armzimageloader.c
deleted file mode 100644
index 0df8c2a4b1..0000000000
--- a/tools/libxc/xc_dom_armzimageloader.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Xen domain builder -- ARM zImage bits
- *
- * Parse and load ARM zImage kernel images.
- *
- * Copyright (C) 2012, Citrix Systems.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#include <arpa/inet.h> /* XXX ntohl is not the right function... */
-
-struct minimal_dtb_header {
-    uint32_t magic;
-    uint32_t total_size;
-    /* There are other fields but we don't use them yet. */
-};
-
-#define DTB_MAGIC 0xd00dfeed
-
-/* ------------------------------------------------------------ */
-/* 32-bit zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-#define ZIMAGE32_MAGIC_OFFSET 0x24
-#define ZIMAGE32_START_OFFSET 0x28
-#define ZIMAGE32_END_OFFSET   0x2c
-
-#define ZIMAGE32_MAGIC 0x016f2818
-
-static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
-{
-    uint32_t *zimage;
-
-    if ( dom->kernel_blob == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: no kernel image loaded", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dom->kernel_size < 0x30 /*sizeof(struct setup_header)*/ )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    zimage = (uint32_t *)dom->kernel_blob;
-    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
-{
-    uint32_t *zimage;
-    uint32_t start, entry_addr;
-    uint64_t v_start, v_end;
-    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    zimage = (uint32_t *)dom->kernel_blob;
-
-    /* Do not load kernel at the very first RAM address */
-    v_start = rambase + 0x8000;
-
-    if ( dom->kernel_size > UINT64_MAX - v_start )
-    {
-        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_end = v_start + dom->kernel_size;
-
-    /*
-     * If start is invalid then the guest will start at some invalid
-     * address and crash, but this happens in guest context so doesn't
-     * concern us here.
-     */
-    start = zimage[ZIMAGE32_START_OFFSET/4];
-
-    if (start == 0)
-        entry_addr = v_start;
-    else
-        entry_addr = start;
-
-    /* find kernel segment */
-    dom->kernel_seg.vstart = v_start;
-    dom->kernel_seg.vend   = v_end;
-
-    dom->parms.virt_entry = entry_addr;
-    dom->parms.virt_base = rambase;
-
-    dom->guest_type = "xen-3.0-armv7l";
-    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-              __FUNCTION__, dom->guest_type,
-              dom->kernel_seg.vstart, dom->kernel_seg.vend);
-    return 0;
-}
-
-/* ------------------------------------------------------------ */
-/* 64-bit zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-#define ZIMAGE64_MAGIC_V0 0x14000008
-#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
-
-/* linux/Documentation/arm64/booting.txt */
-struct zimage64_hdr {
-    uint32_t magic0;
-    uint32_t res0;
-    uint64_t text_offset;  /* Image load offset */
-    uint64_t res1;
-    uint64_t res2;
-    /* zImage V1 only from here */
-    uint64_t res3;
-    uint64_t res4;
-    uint64_t res5;
-    uint32_t magic1;
-    uint32_t res6;
-};
-static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
-{
-    struct zimage64_hdr *zimage;
-
-    if ( dom->kernel_blob == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: no kernel image loaded", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dom->kernel_size < sizeof(*zimage) )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    zimage =  dom->kernel_blob;
-    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
-         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
-    {
-        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
-{
-    struct zimage64_hdr *zimage;
-    uint64_t v_start, v_end;
-    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    zimage = dom->kernel_blob;
-
-    if ( zimage->text_offset > UINT64_MAX - rambase )
-    {
-        DOMPRINTF("%s: kernel text offset is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_start = rambase + zimage->text_offset;
-
-    if ( dom->kernel_size > UINT64_MAX - v_start )
-    {
-        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    v_end = v_start + dom->kernel_size;
-
-    dom->kernel_seg.vstart = v_start;
-    dom->kernel_seg.vend   = v_end;
-
-    /* Call the kernel at offset 0 */
-    dom->parms.virt_entry = v_start;
-    dom->parms.virt_base = rambase;
-
-    dom->guest_type = "xen-3.0-aarch64";
-    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
-              __FUNCTION__, dom->guest_type,
-              dom->kernel_seg.vstart, dom->kernel_seg.vend);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------ */
-/* Common zImage Support                                        */
-/* ------------------------------------------------------------ */
-
-static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
-{
-    void *dst;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    dst = xc_dom_seg_to_ptr(dom, &dom->kernel_seg);
-    if ( dst == NULL )
-    {
-        DOMPRINTF("%s: xc_dom_seg_to_ptr(dom, &dom->kernel_seg) => NULL",
-                  __func__);
-        return -1;
-    }
-
-    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
-              __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
-    DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
-              __func__, dom->kernel_size, dom->kernel_blob, dst);
-
-    memcpy(dst, dom->kernel_blob, dom->kernel_size);
-
-    return 0;
-}
-
-static struct xc_dom_loader zimage32_loader = {
-    .name = "Linux zImage (ARM32)",
-    .probe = xc_dom_probe_zimage32_kernel,
-    .parser = xc_dom_parse_zimage32_kernel,
-    .loader = xc_dom_load_zimage_kernel,
-};
-
-static struct xc_dom_loader zimage64_loader = {
-    .name = "Linux zImage (ARM64)",
-    .probe = xc_dom_probe_zimage64_kernel,
-    .parser = xc_dom_parse_zimage64_kernel,
-    .loader = xc_dom_load_zimage_kernel,
-};
-
-static void __init register_loader(void)
-{
-    xc_dom_register_loader(&zimage32_loader);
-    xc_dom_register_loader(&zimage64_loader);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_binloader.c b/tools/libxc/xc_dom_binloader.c
deleted file mode 100644
index d6f7f2a500..0000000000
--- a/tools/libxc/xc_dom_binloader.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * Some of the field descriptions were copied from "The Multiboot
- * Specification", Copyright 1995, 96 Bryan Ford <baford@cs.utah.edu>,
- * Erich Stefan Boleyn <erich@uruk.org> Copyright 1999, 2000, 2001, 2002
- * Free Software Foundation, Inc.
- */
-
-/******************************************************************************
- *
- * Loads simple binary images. It's like a .COM file in MS-DOS. No headers are
- * present. The only requirement is that it must have a xen_bin_image table
- * somewhere in the first 8192 bytes, starting on a 32-bit aligned address.
- * Those familiar with the multiboot specification should recognize this, it's
- * (almost) the same as the multiboot header.
- * The layout of the xen_bin_image table is:
- *
- * Offset Type Name          Note
- * 0      uint32_t  magic         required
- * 4      uint32_t  flags         required
- * 8      uint32_t  checksum      required
- * 12     uint32_t  header_addr   required
- * 16     uint32_t  load_addr     required
- * 20     uint32_t  load_end_addr required
- * 24     uint32_t  bss_end_addr  required
- * 28     uint32_t  entry_addr    required
- *
- * - magic
- *   Magic number identifying the table. For images to be loaded by Xen 3, the
- *   magic value is 0x336ec578 ("xEn3" with the 0x80 bit of the "E" set).
- * - flags
- *   bit 0: indicates whether the image needs to be loaded on a page boundary
- *   bit 1: reserved, must be 0 (the multiboot spec uses this bit to indicate
- *          that memory info should be passed to the image)
- *   bit 2: reserved, must be 0 (the multiboot spec uses this bit to indicate
- *          that the bootloader should pass video mode info to the image)
- *   bit 16: reserved, must be 1 (the multiboot spec uses this bit to indicate
- *           that the values in the fields header_addr - entry_addr are
- *           valid)
- *   All other bits should be set to 0.
- * - checksum
- *   When added to "magic" and "flags", the resulting value should be 0.
- * - header_addr
- *   Contains the virtual address corresponding to the beginning of the
- *   table - the memory location at which the magic value is supposed to be
- *   loaded. This field serves to synchronize the mapping between OS image
- *   offsets and virtual memory addresses.
- * - load_addr
- *   Contains the virtual address of the beginning of the text segment. The
- *   offset in the OS image file at which to start loading is defined by the
- *   offset at which the table was found, minus (header addr - load addr).
- *   load addr must be less than or equal to header addr.
- * - load_end_addr
- *   Contains the virtual address of the end of the data segment.
- *   (load_end_addr - load_addr) specifies how much data to load. This implies
- *   that the text and data segments must be consecutive in the OS image. If
- *   this field is zero, the domain builder assumes that the text and data
- *   segments occupy the whole OS image file.
- * - bss_end_addr
- *   Contains the virtual address of the end of the bss segment. The domain
- *   builder initializes this area to zero, and reserves the memory it occupies
- *   to avoid placing boot modules and other data relevant to the loaded image
- *   in that area. If this field is zero, the domain builder assumes that no bss
- *   segment is present.
- * - entry_addr
- *   The virtual address at which to start execution of the loaded image.
- *
- */
-
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-#define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
-#define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
-
-struct xen_bin_image_table
-{
-    uint32_t magic;
-    uint32_t flags;
-    uint32_t checksum;
-    uint32_t header_addr;
-    uint32_t load_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t entry_addr;
-};
-
-#define XEN_MULTIBOOT_MAGIC3 0x336ec578
-
-#define XEN_MULTIBOOT_FLAG_ALIGN4K     0x00000001
-#define XEN_MULTIBOOT_FLAG_NEEDMEMINFO 0x00000002
-#define XEN_MULTIBOOT_FLAG_NEEDVIDINFO 0x00000004
-#define XEN_MULTIBOOT_FLAG_ADDRSVALID  0x00010000
-#define XEN_MULTIBOOT_FLAG_PAE_SHIFT   14
-#define XEN_MULTIBOOT_FLAG_PAE_MASK    (3 << XEN_MULTIBOOT_FLAG_PAE_SHIFT)
-
-/* Flags we test for */
-#define FLAGS_MASK     ((~ 0) & (~ XEN_MULTIBOOT_FLAG_ALIGN4K) & \
-    (~ XEN_MULTIBOOT_FLAG_PAE_MASK))
-#define FLAGS_REQUIRED XEN_MULTIBOOT_FLAG_ADDRSVALID
-
-/* --------------------------------------------------------------------- */
-
-static struct xen_bin_image_table *find_table(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *table;
-    uint32_t *probe_ptr;
-    uint32_t *probe_end;
-
-    if ( dom->kernel_size < sizeof(*table) )
-        return NULL;
-    probe_ptr = dom->kernel_blob;
-    if ( dom->kernel_size > (8192 + sizeof(*table)) )
-        probe_end = dom->kernel_blob + 8192;
-    else
-        probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table);
-
-    for ( table = NULL; probe_ptr < probe_end; probe_ptr++ )
-    {
-        if ( *probe_ptr == XEN_MULTIBOOT_MAGIC3 )
-        {
-            table = (struct xen_bin_image_table *) probe_ptr;
-            /* Checksum correct? */
-            if ( (table->magic + table->flags + table->checksum) == 0 )
-                return table;
-        }
-    }
-    return NULL;
-}
-
-static int xc_dom_probe_bin_kernel(struct xc_dom_image *dom)
-{
-    return find_table(dom) ? 0 : -EINVAL;
-}
-
-static int xc_dom_parse_bin_kernel(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *image_info;
-    char *image = dom->kernel_blob;
-    size_t image_size = dom->kernel_size;
-    uint32_t start_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t pae_flags;
-
-    image_info = find_table(dom);
-    if ( !image_info )
-        return -EINVAL;
-
-    DOMPRINTF("%s: multiboot header fields", __FUNCTION__);
-    DOMPRINTF("  flags:         0x%" PRIx32 "", image_info->flags);
-    DOMPRINTF("  header_addr:   0x%" PRIx32 "", image_info->header_addr);
-    DOMPRINTF("  load_addr:     0x%" PRIx32 "", image_info->load_addr);
-    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", image_info->load_end_addr);
-    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", image_info->bss_end_addr);
-    DOMPRINTF("  entry_addr:    0x%" PRIx32 "", image_info->entry_addr);
-
-    /* Check the flags */
-    if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
-                     "%s: xen_bin_image_table flags required "
-                     "0x%08" PRIx32 " found 0x%08" PRIx32 "",
-                     __FUNCTION__, FLAGS_REQUIRED, image_info->flags & FLAGS_MASK);
-        return -EINVAL;
-    }
-
-    /* Sanity check on the addresses */
-    if ( (image_info->header_addr < image_info->load_addr) ||
-         ((char *) image_info - image) <
-         (image_info->header_addr - image_info->load_addr) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid header_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    start_addr = image_info->header_addr - ((char *)image_info - image);
-    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
-    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
-
-    DOMPRINTF("%s: calculated addresses", __FUNCTION__);
-    DOMPRINTF("  start_addr:    0x%" PRIx32 "", start_addr);
-    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", load_end_addr);
-    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", bss_end_addr);
-
-    if ( (start_addr + image_size) < load_end_addr )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid load_end_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( bss_end_addr < load_end_addr)
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid bss_end_addr.",
-                     __FUNCTION__);
-        return -EINVAL;
-    }
-
-    dom->kernel_seg.vstart = image_info->load_addr;
-    dom->kernel_seg.vend   = bss_end_addr;
-    dom->parms.virt_base   = start_addr;
-    dom->parms.virt_entry  = image_info->entry_addr;
-
-    pae_flags = image_info->flags & XEN_MULTIBOOT_FLAG_PAE_MASK;
-    switch (pae_flags >> XEN_MULTIBOOT_FLAG_PAE_SHIFT) {
-    case 0:
-        dom->guest_type = "xen-3.0-x86_32";
-        break;
-    case 1:
-        dom->guest_type = "xen-3.0-x86_32p";
-        break;
-    case 2:
-        dom->guest_type = "xen-3.0-x86_64";
-        break;
-    case 3:
-        /* Kernel detects PAE at runtime.  So try to figure whenever
-         * xen supports PAE and advertise a PAE-capable kernel in case
-         * it does. */
-        dom->guest_type = "xen-3.0-x86_32";
-        if ( strstr(dom->xen_caps, "xen-3.0-x86_32p") )
-        {
-            DOMPRINTF("%s: PAE fixup", __FUNCTION__);
-            dom->guest_type = "xen-3.0-x86_32p";
-            dom->parms.pae  = XEN_PAE_EXTCR3;
-        }
-        break;
-    }
-    return 0;
-}
-
-static int xc_dom_load_bin_kernel(struct xc_dom_image *dom)
-{
-    struct xen_bin_image_table *image_info;
-    char *image = dom->kernel_blob;
-    char *dest;
-    size_t image_size = dom->kernel_size;
-    size_t dest_size;
-    uint32_t start_addr;
-    uint32_t load_end_addr;
-    uint32_t bss_end_addr;
-    uint32_t skip, text_size, bss_size;
-
-    image_info = find_table(dom);
-    if ( !image_info )
-        return -EINVAL;
-
-    start_addr = image_info->header_addr - ((char *)image_info - image);
-    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
-    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
-
-    /* It's possible that we need to skip the first part of the image */
-    skip = image_info->load_addr - start_addr;
-    text_size = load_end_addr - image_info->load_addr;
-    bss_size = bss_end_addr - load_end_addr;
-
-    DOMPRINTF("%s: calculated sizes", __FUNCTION__);
-    DOMPRINTF("  skip:      0x%" PRIx32 "", skip);
-    DOMPRINTF("  text_size: 0x%" PRIx32 "", text_size);
-    DOMPRINTF("  bss_size:  0x%" PRIx32 "", bss_size);
-
-    dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart, &dest_size);
-    if ( dest == NULL )
-    {
-        DOMPRINTF("%s: xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart)"
-                  " => NULL", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( dest_size < text_size ||
-         dest_size - text_size < bss_size )
-    {
-        DOMPRINTF("%s: mapped region is too small for image", __FUNCTION__);
-        return -EINVAL;
-    }
-
-    if ( image_size < skip ||
-         image_size - skip < text_size )
-    {
-        DOMPRINTF("%s: image is too small for declared text size",
-                  __FUNCTION__);
-        return -EINVAL;
-    }
-
-    memcpy(dest, image + skip, text_size);
-    memset(dest + text_size, 0, bss_size);
-
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static struct xc_dom_loader bin_loader = {
-    .name = "multiboot-binary",
-    .probe = xc_dom_probe_bin_kernel,
-    .parser = xc_dom_parse_bin_kernel,
-    .loader = xc_dom_load_bin_kernel,
-};
-
-static void __init register_loader(void)
-{
-    xc_dom_register_loader(&bin_loader);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_boot.c b/tools/libxc/xc_dom_boot.c
deleted file mode 100644
index bb599b33ba..0000000000
--- a/tools/libxc/xc_dom_boot.c
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Xen domain builder -- xen booter.
- *
- * This is the code which actually boots a fresh
- * prepared domain image as xen guest domain.
- *
- * ==>  this is the only domain builder code piece
- *          where xen hypercalls are allowed        <==
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <zlib.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-#include "xc_core.h"
-#include <xen/hvm/params.h>
-#include <xen/grant_table.h>
-
-/* ------------------------------------------------------------------------ */
-
-static int setup_hypercall_page(struct xc_dom_image *dom)
-{
-    DECLARE_DOMCTL;
-    xen_pfn_t pfn;
-    int rc;
-
-    if ( dom->parms.virt_hypercall == -1 )
-        return 0;
-    pfn = (dom->parms.virt_hypercall - dom->parms.virt_base)
-        >> XC_DOM_PAGE_SHIFT(dom);
-
-    DOMPRINTF("%s: vaddr=0x%" PRIx64 " pfn=0x%" PRIpfn "", __FUNCTION__,
-                  dom->parms.virt_hypercall, pfn);
-    domctl.cmd = XEN_DOMCTL_hypercall_init;
-    domctl.domain = dom->guest_domid;
-    domctl.u.hypercall_init.gmfn = xc_dom_p2m(dom, pfn);
-    rc = do_domctl(dom->xch, &domctl);
-    if ( rc != 0 )
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: HYPERCALL_INIT failed: %d - %s)",
-                     __FUNCTION__, errno, strerror(errno));
-    return rc;
-}
-
-
-/* ------------------------------------------------------------------------ */
-
-int xc_dom_compat_check(struct xc_dom_image *dom)
-{
-    xen_capabilities_info_t xen_caps;
-    char *item, *ptr;
-    int match, found = 0;
-
-    strncpy(xen_caps, dom->xen_caps, XEN_CAPABILITIES_INFO_LEN - 1);
-    xen_caps[XEN_CAPABILITIES_INFO_LEN - 1] = '\0';
-
-    for ( item = strtok_r(xen_caps, " ", &ptr);
-          item != NULL ; item = strtok_r(NULL, " ", &ptr) )
-    {
-        match = !strcmp(dom->guest_type, item);
-        DOMPRINTF("%s: supported guest type: %s%s", __FUNCTION__,
-                  item, match ? " <= matches" : "");
-        if ( match )
-            found++;
-    }
-    if ( !found )
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
-                     "%s: guest type %s not supported by xen kernel, sorry",
-                     __FUNCTION__, dom->guest_type);
-
-    return found;
-}
-
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch, uint32_t domid)
-{
-    dom->xch = xch;
-    dom->guest_domid = domid;
-
-    dom->xen_version = xc_version(xch, XENVER_version, NULL);
-    if ( xc_version(xch, XENVER_capabilities, &dom->xen_caps) < 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR, "can't get xen capabilities");
-        return -1;
-    }
-    DOMPRINTF("%s: ver %d.%d, caps %s", __FUNCTION__,
-              dom->xen_version >> 16, dom->xen_version & 0xff,
-              dom->xen_caps);
-    return 0;
-}
-
-int xc_dom_boot_mem_init(struct xc_dom_image *dom)
-{
-    long rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    rc = dom->arch_hooks->meminit(dom);
-    if ( rc != 0 )
-    {
-        xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
-                     "%s: can't allocate low memory for domain",
-                     __FUNCTION__);
-        return rc;
-    }
-
-    return 0;
-}
-
-void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
-                           xen_pfn_t count)
-{
-    int page_shift = XC_DOM_PAGE_SHIFT(dom);
-    privcmd_mmap_entry_t *entries;
-    void *ptr;
-    int i;
-    int err;
-
-    entries = xc_dom_malloc(dom, count * sizeof(privcmd_mmap_entry_t));
-    if ( entries == NULL )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [malloc]", __FUNCTION__, pfn, count);
-        return NULL;
-    }
-
-    for ( i = 0; i < count; i++ )
-        entries[i].mfn = xc_dom_p2m(dom, pfn + i);
-
-    ptr = xc_map_foreign_ranges(dom->xch, dom->guest_domid,
-                count << page_shift, PROT_READ | PROT_WRITE, 1 << page_shift,
-                entries, count);
-    if ( ptr == NULL )
-    {
-        err = errno;
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [mmap, errno=%i (%s)]", __FUNCTION__, pfn, count,
-                     err, strerror(err));
-        return NULL;
-    }
-
-    return ptr;
-}
-
-int xc_dom_boot_image(struct xc_dom_image *dom)
-{
-    xc_dominfo_t info;
-    int rc;
-
-    DOMPRINTF_CALLED(dom->xch);
-
-    /* misc stuff*/
-    if ( (rc = dom->arch_hooks->bootearly(dom)) != 0 )
-        return rc;
-
-    /* collect some info */
-    rc = xc_domain_getinfo(dom->xch, dom->guest_domid, 1, &info);
-    if ( rc < 0 )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: getdomaininfo failed (rc=%d)", __FUNCTION__, rc);
-        return rc;
-    }
-    if ( rc == 0 || info.domid != dom->guest_domid )
-    {
-        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                     "%s: Huh? No domains found (nr_domains=%d) "
-                     "or domid mismatch (%d != %d)", __FUNCTION__,
-                     rc, info.domid, dom->guest_domid);
-        return -1;
-    }
-    dom->shared_info_mfn = info.shared_info_frame;
-
-    /* sanity checks */
-    if ( !xc_dom_compat_check(dom) )
-        return -1;
-
-    /* initial mm setup */
-    if ( dom->arch_hooks->setup_pgtables &&
-         (rc = dom->arch_hooks->setup_pgtables(dom)) != 0 )
-        return rc;
-
-    /* start info page */
-    if ( dom->arch_hooks->start_info )
-        dom->arch_hooks->start_info(dom);
-
-    /* hypercall page */
-    if ( (rc = setup_hypercall_page(dom)) != 0 )
-        return rc;
-    xc_dom_log_memory_footprint(dom);
-
-    /* misc x86 stuff */
-    if ( (rc = dom->arch_hooks->bootlate(dom)) != 0 )
-        return rc;
-
-    /* let the vm run */
-    if ( (rc = dom->arch_hooks->vcpu(dom)) != 0 )
-        return rc;
-    xc_dom_unmap_all(dom);
-
-    return rc;
-}
-
-static xen_pfn_t xc_dom_gnttab_setup(xc_interface *xch, uint32_t domid)
-{
-    gnttab_setup_table_t setup;
-    DECLARE_HYPERCALL_BUFFER(xen_pfn_t, gmfnp);
-    int rc;
-    xen_pfn_t gmfn;
-
-    gmfnp = xc_hypercall_buffer_alloc(xch, gmfnp, sizeof(*gmfnp));
-    if (gmfnp == NULL)
-        return -1;
-
-    setup.dom = domid;
-    setup.nr_frames = 1;
-    set_xen_guest_handle(setup.frame_list, gmfnp);
-    setup.status = 0;
-
-    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup), 1);
-    gmfn = *gmfnp;
-    xc_hypercall_buffer_free(xch, gmfnp);
-
-    if ( rc != 0 || setup.status != GNTST_okay )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to setup domU grant table "
-                     "[errno=%d, status=%" PRId16 "]\n",
-                     __FUNCTION__, rc != 0 ? errno : 0, setup.status);
-        return -1;
-    }
-
-    return gmfn;
-}
-
-static void xc_dom_set_gnttab_entry(xc_interface *xch,
-                                    grant_entry_v1_t *gnttab,
-                                    unsigned int idx,
-                                    uint32_t guest_domid,
-                                    uint32_t backend_domid,
-                                    xen_pfn_t guest_gfn)
-{
-    if ( guest_domid == backend_domid || guest_gfn == -1 )
-        return;
-
-    xc_dom_printf(xch, "%s: d%d gnt[%u] -> d%d 0x%"PRI_xen_pfn,
-                  __func__, guest_domid, idx, backend_domid, guest_gfn);
-
-    gnttab[idx].flags = GTF_permit_access;
-    gnttab[idx].domid = backend_domid;
-    gnttab[idx].frame = guest_gfn;
-}
-
-static int compat_gnttab_seed(xc_interface *xch, uint32_t domid,
-                              xen_pfn_t console_gfn,
-                              xen_pfn_t xenstore_gfn,
-                              uint32_t console_domid,
-                              uint32_t xenstore_domid)
-{
-
-    xen_pfn_t gnttab_gfn;
-    grant_entry_v1_t *gnttab;
-
-    gnttab_gfn = xc_dom_gnttab_setup(xch, domid);
-    if ( gnttab_gfn == -1 )
-        return -1;
-
-    gnttab = xc_map_foreign_range(xch,
-                                  domid,
-                                  PAGE_SIZE,
-                                  PROT_READ|PROT_WRITE,
-                                  gnttab_gfn);
-    if ( gnttab == NULL )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to map d%d grant table "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    xc_dom_set_gnttab_entry(xch, gnttab, GNTTAB_RESERVED_CONSOLE,
-                            domid, console_domid, console_gfn);
-    xc_dom_set_gnttab_entry(xch, gnttab, GNTTAB_RESERVED_XENSTORE,
-                            domid, xenstore_domid, xenstore_gfn);
-
-    if ( munmap(gnttab, PAGE_SIZE) == -1 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to unmap d%d grant table "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    /* Guest shouldn't really touch its grant table until it has
-     * enabled its caches. But lets be nice. */
-    xc_domain_cacheflush(xch, domid, gnttab_gfn, 1);
-
-    return 0;
-}
-
-static int compat_gnttab_hvm_seed(xc_interface *xch, uint32_t domid,
-                                  xen_pfn_t console_gfn,
-                                  xen_pfn_t xenstore_gfn,
-                                  uint32_t console_domid,
-                                  uint32_t xenstore_domid)
-{
-    int rc;
-    xen_pfn_t scratch_gfn;
-    struct xen_add_to_physmap xatp = {
-        .domid = domid,
-        .space = XENMAPSPACE_grant_table,
-        .idx   = 0,
-    };
-    struct xen_remove_from_physmap xrfp = {
-        .domid = domid,
-    };
-
-    rc = xc_core_arch_get_scratch_gpfn(xch, domid, &scratch_gfn);
-    if ( rc < 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to get a scratch gfn from d%d"
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-    xatp.gpfn = scratch_gfn;
-    xrfp.gpfn = scratch_gfn;
-
-    xc_dom_printf(xch, "%s: d%d: pfn=0x%"PRI_xen_pfn, __func__,
-                  domid, scratch_gfn);
-
-    rc = do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp));
-    if ( rc != 0 )
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to add gnttab to d%d physmap "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    rc = compat_gnttab_seed(xch, domid,
-                            console_gfn, xenstore_gfn,
-                            console_domid, xenstore_domid);
-    if (rc != 0)
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to seed gnttab entries for d%d\n",
-                     __func__, domid);
-        (void) do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp,
-                            sizeof(xrfp));
-        return -1;
-    }
-
-    rc = do_memory_op(xch, XENMEM_remove_from_physmap, &xrfp, sizeof(xrfp));
-    if (rc != 0)
-    {
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to remove gnttab from d%d physmap "
-                     "[errno=%d]\n",
-                     __func__, domid, errno);
-        return -1;
-    }
-
-    return 0;
-}
-
-int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
-                       bool is_hvm, xen_pfn_t console_gfn,
-                       xen_pfn_t xenstore_gfn, uint32_t console_domid,
-                       uint32_t xenstore_domid)
-{
-    xenforeignmemory_handle* fmem = xch->fmem;
-    xenforeignmemory_resource_handle *fres;
-    void *addr = NULL;
-
-    fres = xenforeignmemory_map_resource(
-        fmem, guest_domid, XENMEM_resource_grant_table,
-        XENMEM_resource_grant_table_id_shared, 0, 1, &addr,
-        PROT_READ | PROT_WRITE, 0);
-    if ( !fres )
-    {
-        if ( errno == EOPNOTSUPP )
-            return is_hvm ?
-                compat_gnttab_hvm_seed(xch, guest_domid,
-                                       console_gfn, xenstore_gfn,
-                                       console_domid, xenstore_domid) :
-                compat_gnttab_seed(xch, guest_domid,
-                                   console_gfn, xenstore_gfn,
-                                   console_domid, xenstore_domid);
-
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: failed to acquire d%d grant table [errno=%d]\n",
-                     __func__, guest_domid, errno);
-        return -1;
-    }
-
-    xc_dom_set_gnttab_entry(xch, addr, GNTTAB_RESERVED_CONSOLE,
-                            guest_domid, console_domid, console_gfn);
-    xc_dom_set_gnttab_entry(xch, addr, GNTTAB_RESERVED_XENSTORE,
-                            guest_domid, xenstore_domid, xenstore_gfn);
-
-    xenforeignmemory_unmap_resource(fmem, fres);
-
-    return 0;
-}
-
-int xc_dom_gnttab_init(struct xc_dom_image *dom)
-{
-    bool is_hvm = xc_dom_translated(dom);
-    xen_pfn_t console_gfn = xc_dom_p2m(dom, dom->console_pfn);
-    xen_pfn_t xenstore_gfn = xc_dom_p2m(dom, dom->xenstore_pfn);
-
-    return xc_dom_gnttab_seed(dom->xch, dom->guest_domid, is_hvm,
-                              console_gfn, xenstore_gfn,
-                              dom->console_domid, dom->xenstore_domid);
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_dom_bzimageloader.c b/tools/libxc/xc_dom_bzimageloader.c
deleted file mode 100644
index a7d70cc7c6..0000000000
--- a/tools/libxc/xc_dom_bzimageloader.c
+++ /dev/null
@@ -1,812 +0,0 @@
-/*
- * Xen domain builder -- bzImage bits
- *
- * Parse and load bzImage kernel images.
- *
- * This relies on version 2.08 of the boot protocol, which contains an
- * ELF file embedded in the bzImage.  The loader extracts this ELF
- * image and passes it off to the standard ELF loader.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
- * written 2007 by Jeremy Fitzhardinge <jeremy@xensource.com>
- * written 2008 by Ian Campbell <ijc@hellion.org.uk>
- * written 2009 by Chris Lalancette <clalance@redhat.com>
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#include "xg_private.h"
-#include "xc_dom_decompress.h"
-
-#include <xen-tools/libs.h>
-
-#ifndef __MINIOS__
-
-#if defined(HAVE_BZLIB)
-
-#include <bzlib.h>
-
-static int xc_try_bzip2_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    bz_stream stream;
-    int ret;
-    char *out_buf;
-    char *tmp_buf;
-    int retval = -1;
-    unsigned int outsize;
-    uint64_t total;
-
-    stream.bzalloc = NULL;
-    stream.bzfree = NULL;
-    stream.opaque = NULL;
-
-    if ( dom->kernel_size == 0)
-    {
-        DOMPRINTF("BZIP2: Input is 0 size");
-        return -1;
-    }
-
-    ret = BZ2_bzDecompressInit(&stream, 0, 0);
-    if ( ret != BZ_OK )
-    {
-        DOMPRINTF("BZIP2: Error initting stream");
-        return -1;
-    }
-
-    /* sigh.  We don't know up-front how much memory we are going to need
-     * for the output buffer.  Allocate the output buffer to be equal
-     * the input buffer to start, and we'll realloc as needed.
-     */
-    outsize = dom->kernel_size;
-
-    /*
-     * stream.avail_in and outsize are unsigned int, while kernel_size
-     * is a size_t. Check we aren't overflowing.
-     */
-    if ( outsize != dom->kernel_size )
-    {
-        DOMPRINTF("BZIP2: Input too large");
-        goto bzip2_cleanup;
-    }
-
-    out_buf = malloc(outsize);
-    if ( out_buf == NULL )
-    {
-        DOMPRINTF("BZIP2: Failed to alloc memory");
-        goto bzip2_cleanup;
-    }
-
-    stream.next_in = dom->kernel_blob;
-    stream.avail_in = dom->kernel_size;
-
-    stream.next_out = out_buf;
-    stream.avail_out = dom->kernel_size;
-
-    for ( ; ; )
-    {
-        ret = BZ2_bzDecompress(&stream);
-        if ( ret == BZ_STREAM_END )
-        {
-            DOMPRINTF("BZIP2: Saw data stream end");
-            retval = 0;
-            break;
-        }
-        if ( ret != BZ_OK )
-        {
-            DOMPRINTF("BZIP2: error %d", ret);
-            free(out_buf);
-            goto bzip2_cleanup;
-        }
-
-        if ( stream.avail_out == 0 )
-        {
-            /* Protect against output buffer overflow */
-            if ( outsize > UINT_MAX / 2 )
-            {
-                DOMPRINTF("BZIP2: output buffer overflow");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-
-            if ( xc_dom_kernel_check_size(dom, outsize * 2) )
-            {
-                DOMPRINTF("BZIP2: output too large");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-
-            tmp_buf = realloc(out_buf, outsize * 2);
-            if ( tmp_buf == NULL )
-            {
-                DOMPRINTF("BZIP2: Failed to realloc memory");
-                free(out_buf);
-                goto bzip2_cleanup;
-            }
-            out_buf = tmp_buf;
-
-            stream.next_out = out_buf + outsize;
-            stream.avail_out = (outsize * 2) - outsize;
-            outsize *= 2;
-        }
-        else if ( stream.avail_in == 0 )
-        {
-            /*
-             * If there is output buffer available then this indicates
-             * that BZ2_bzDecompress would like more input data to be
-             * provided.  However our complete input buffer is in
-             * memory and provided upfront so if avail_in is zero this
-             * actually indicates a truncated input.
-             */
-            DOMPRINTF("BZIP2: not enough input");
-            free(out_buf);
-            goto bzip2_cleanup;
-        }
-    }
-
-    total = (((uint64_t)stream.total_out_hi32) << 32) | stream.total_out_lo32;
-
-    if ( xc_dom_register_external(dom, out_buf, total) )
-    {
-        DOMPRINTF("BZIP2: Error registering stream output");
-        free(out_buf);
-        goto bzip2_cleanup;
-    }
-
-    DOMPRINTF("%s: BZIP2 decompress OK, 0x%zx -> 0x%lx",
-              __FUNCTION__, *size, (long unsigned int) total);
-
-    *blob = out_buf;
-    *size = total;
-
- bzip2_cleanup:
-    BZ2_bzDecompressEnd(&stream);
-
-    return retval;
-}
-
-#else /* !defined(HAVE_BZLIB) */
-
-static int xc_try_bzip2_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: BZIP2 decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-#endif
-
-#if defined(HAVE_LZMA)
-
-#include <lzma.h>
-
-static int _xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size,
-    lzma_stream *stream, const char *what)
-{
-    lzma_ret ret;
-    lzma_action action = LZMA_RUN;
-    unsigned char *out_buf;
-    unsigned char *tmp_buf;
-    int retval = -1;
-    size_t outsize;
-    const char *msg;
-
-    if ( dom->kernel_size == 0)
-    {
-        DOMPRINTF("%s: Input is 0 size", what);
-        return -1;
-    }
-
-    /* sigh.  We don't know up-front how much memory we are going to need
-     * for the output buffer.  Allocate the output buffer to be equal
-     * the input buffer to start, and we'll realloc as needed.
-     */
-    outsize = dom->kernel_size;
-    out_buf = malloc(outsize);
-    if ( out_buf == NULL )
-    {
-        DOMPRINTF("%s: Failed to alloc memory", what);
-        goto lzma_cleanup;
-    }
-
-    stream->next_in = dom->kernel_blob;
-    stream->avail_in = dom->kernel_size;
-
-    stream->next_out = out_buf;
-    stream->avail_out = dom->kernel_size;
-
-    for ( ; ; )
-    {
-        ret = lzma_code(stream, action);
-        if ( ret == LZMA_STREAM_END )
-        {
-            DOMPRINTF("%s: Saw data stream end", what);
-            retval = 0;
-            break;
-        }
-        if ( ret != LZMA_OK )
-        {
-            switch ( ret )
-            {
-            case LZMA_MEM_ERROR:
-                msg = strerror(ENOMEM);
-                break;
-
-            case LZMA_MEMLIMIT_ERROR:
-                msg = "Memory usage limit reached";
-                break;
-
-            case LZMA_FORMAT_ERROR:
-                msg = "File format not recognized";
-                break;
-
-            case LZMA_OPTIONS_ERROR:
-                // FIXME: Better message?
-                msg = "Unsupported compression options";
-                break;
-
-            case LZMA_DATA_ERROR:
-                msg = "File is corrupt";
-                break;
-
-            case LZMA_BUF_ERROR:
-                msg = "Unexpected end of input";
-                break;
-
-            default:
-                msg = "Internal program error (bug)";
-                break;
-            }
-            DOMPRINTF("%s: %s decompression error: %s",
-                      __FUNCTION__, what, msg);
-            free(out_buf);
-            goto lzma_cleanup;
-        }
-
-        if ( stream->avail_out == 0 )
-        {
-            /* Protect against output buffer overflow */
-            if ( outsize > SIZE_MAX / 2 )
-            {
-                DOMPRINTF("%s: output buffer overflow", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-
-            if ( xc_dom_kernel_check_size(dom, outsize * 2) )
-            {
-                DOMPRINTF("%s: output too large", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-
-            tmp_buf = realloc(out_buf, outsize * 2);
-            if ( tmp_buf == NULL )
-            {
-                DOMPRINTF("%s: Failed to realloc memory", what);
-                free(out_buf);
-                goto lzma_cleanup;
-            }
-            out_buf = tmp_buf;
-
-            stream->next_out = out_buf + outsize;
-            stream->avail_out = (outsize * 2) - outsize;
-            outsize *= 2;
-        }
-    }
-
-    if ( xc_dom_register_external(dom, out_buf, stream->total_out) )
-    {
-        DOMPRINTF("%s: Error registering stream output", what);
-        free(out_buf);
-        goto lzma_cleanup;
-    }
-
-    DOMPRINTF("%s: %s decompress OK, 0x%zx -> 0x%zx",
-              __FUNCTION__, what, *size, (size_t)stream->total_out);
-
-    *blob = out_buf;
-    *size = stream->total_out;
-
- lzma_cleanup:
-    lzma_end(stream);
-
-    return retval;
-}
-
-/* 128 Mb is the minimum size (half-way) documented to work for all inputs. */
-#define LZMA_BLOCK_SIZE (128*1024*1024)
-
-static int xc_try_xz_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    lzma_stream stream = LZMA_STREAM_INIT;
-
-    if ( lzma_stream_decoder(&stream, LZMA_BLOCK_SIZE, 0) != LZMA_OK )
-    {
-        DOMPRINTF("XZ: Failed to init decoder");
-        return -1;
-    }
-
-    return _xc_try_lzma_decode(dom, blob, size, &stream, "XZ");
-}
-
-static int xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    lzma_stream stream = LZMA_STREAM_INIT;
-
-    if ( lzma_alone_decoder(&stream, LZMA_BLOCK_SIZE) != LZMA_OK )
-    {
-        DOMPRINTF("LZMA: Failed to init decoder");
-        return -1;
-    }
-
-    return _xc_try_lzma_decode(dom, blob, size, &stream, "LZMA");
-}
-
-#else /* !defined(HAVE_LZMA) */
-
-static int xc_try_xz_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: XZ decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-static int xc_try_lzma_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
-                 "%s: LZMA decompress support unavailable",
-                 __FUNCTION__);
-    return -1;
-}
-
-#endif
-
-#if defined(HAVE_LZO1X)
-
-#include <lzo/lzo1x.h>
-
-#define LZOP_HEADER_HAS_FILTER 0x00000800
-#define LZOP_MAX_BLOCK_SIZE (64*1024*1024)
-
-static inline uint_fast16_t lzo_read_16(const unsigned char *buf)
-{
-    return buf[1] | (buf[0] << 8);
-}
-
-static inline uint_fast32_t lzo_read_32(const unsigned char *buf)
-{
-    return lzo_read_16(buf + 2) | ((uint32_t)lzo_read_16(buf) << 16);
-}
-
-static int xc_try_lzo1x_decode(
-    struct xc_dom_image *dom, void **blob, size_t *size)
-{
-    int ret;
-    const unsigned char *cur = dom->kernel_blob;
-    unsigned char *out_buf = NULL;
-    size_t left = dom->kernel_size;
-    const char *msg;
-    unsigned version;
-    static const unsigned char magic[] = {
-        0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
-    };
-
-    /*
-     * lzo_uint should match size_t. Check that this is the case to be
-     * sure we won't overflow various lzo_uint fields.
-     */
-    BUILD_BUG_ON(sizeof(lzo_uint) != sizeof(size_t));
-
-    ret = lzo_init();
-    if ( ret != LZO_E_OK )
-    {
-        DOMPRINTF("LZO1x: Failed to init library (%d)\n", ret);
-        return -1;
-    }
-
-    if ( left < 16 || memcmp(cur, magic, 9) )
-    {
-        DOMPRINTF("LZO1x: Unrecognized magic\n");
-        return -1;
-    }
-
-    /* get version (2bytes), skip library version (2),
-     * 'need to be extracted' version (2) and method (1) */
-    version = lzo_read_16(cur + 9);
-    cur += 16;
-    left -= 16;
-
-    if ( version >= 0x0940 )
-    {
-        /* skip level */
-        ++cur;
-        if ( left )
-            --left;
-    }
-
-    if ( left >= 4 && (lzo_read_32(cur) & LZOP_HEADER_HAS_FILTER) )
-        ret = 8; /* flags + filter info */
-    else
-        ret = 4; /* flags */
-
-    /* skip mode and mtime_low */
-    ret += 8;
-    if ( version >= 0x0940 )
-        ret += 4; /* skip mtime_high */
-
-    /* don't care about the file name, and skip checksum */
-    if ( left > ret )
-        ret += 1 + cur[ret] + 4;
-
-    if ( left < ret )
-    {
-        DOMPRINTF("LZO1x: Incomplete header\n");
-        return -1;
-    }
-    cur += ret;
-    left -= ret;
-
-    for ( *size = 0; ; )
-    {
-        lzo_uint src_len, dst_len, out_len;
-        unsigned char *tmp_buf;
-
-        msg = "Short input";
-        if ( left < 4 )
-            break;
-
-        dst_len = lzo_read_32(cur);
-        if ( !dst_len )
-        {
-            msg = "Error registering stream output";
-            if ( xc_dom_register_external(dom, out_buf, *size) )
-                break;
-
-            return 0;
-        }
-
-        if ( dst_len > LZOP_MAX_BLOCK_SIZE )
-        {
-            msg = "Block size too large";
-            break;
-        }
-
-        if ( left < 12 )
-            break;
-
-        src_len = lzo_read_32(cur + 4);
-        cur += 12; /* also skip block checksum info */
-        left -= 12;
-
-        msg = "Bad source length";
-        if ( src_len <= 0 || src_len > dst_len || src_len > left )
-            break;
-
-        msg = "Output buffer overflow";
-        if ( *size > SIZE_MAX - dst_len )
-            break;
-
-        msg = "Decompressed image too large";
-        if ( xc_dom_kernel_check_size(dom, *size + dst_len) )
-            break;
-
-        msg = "Failed to (re)alloc memory";
-        tmp_buf = realloc(out_buf, *size + dst_len);
-        if ( tmp_buf == NULL )
-            break;
-
-        out_buf = tmp_buf;
-        out_len = dst_len;
-
-        ret = lzo1x_decompress_safe(cur, src_len,
-                                    out_buf + *size, &out_len, NULL);
-        switch ( ret )
-        {
-        case LZO_E_OK:
-            msg = "Input underrun";
-            if ( out_len != dst_len )
-                break;
-
-            *blob = out_buf;


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMKg-0006Ii-Cm; Fri, 18 Sep 2020 19:46:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMKe-0006IZ-LV
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:08 +0000
X-Inumbo-ID: 96155126-5d7d-4bb2-900a-6801da6f1ced
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 96155126-5d7d-4bb2-900a-6801da6f1ced;
 Fri, 18 Sep 2020 19:46:04 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/cRkBA/0t7I86roN7dnW/0IKdtWdqyetqdlxUTIFBiM=; b=2z8Cy1pUexv+CTAqWgZ/tFutPK
 aSAU6I2ySqSQagVsI8k2rntGZYgWEocTlMo8eXCfDK1I7eIvkgd4D+peSc3Uske/CaXmq0rfQjnr3
 0o9/+p+hozyQ3qG7T3KkQoJyUH7I7ZunpIsrt+Q3EGaV/HvJlkrtUQkqX2XKCUWg0IK0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKa-00076H-O8
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKa-0004Mj-NF
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: rename libxenguest internal headers
Message-Id: <E1kJMKa-0004Mj-NF@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 256920d3a232c2e6631dbd505d036c0d3046d299
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:29 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: rename libxenguest internal headers
    
    Rename the header files private to libxenguest from xc_*.h to xg_*.h.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/xc_dom_decompress.h              |   8 -
 tools/libxc/xc_dom_decompress_unsafe.h       |  20 --
 tools/libxc/xc_sr_common.h                   | 468 ---------------------------
 tools/libxc/xc_sr_common_x86.h               |  51 ---
 tools/libxc/xc_sr_common_x86_pv.h            | 109 -------
 tools/libxc/xc_sr_stream_format.h            | 150 ---------
 tools/libxc/xg_dom_bzimageloader.c           |   2 +-
 tools/libxc/xg_dom_decompress.h              |   8 +
 tools/libxc/xg_dom_decompress_lz4.c          |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.c       |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.h       |  20 ++
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_lzma.c  |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c |   2 +-
 tools/libxc/xg_dom_decompress_unsafe_xz.c    |   2 +-
 tools/libxc/xg_sr_common.c                   |   2 +-
 tools/libxc/xg_sr_common.h                   | 468 +++++++++++++++++++++++++++
 tools/libxc/xg_sr_common_x86.c               |   2 +-
 tools/libxc/xg_sr_common_x86.h               |  51 +++
 tools/libxc/xg_sr_common_x86_pv.c            |   2 +-
 tools/libxc/xg_sr_common_x86_pv.h            | 109 +++++++
 tools/libxc/xg_sr_restore.c                  |   2 +-
 tools/libxc/xg_sr_restore_x86_hvm.c          |   2 +-
 tools/libxc/xg_sr_restore_x86_pv.c           |   2 +-
 tools/libxc/xg_sr_save.c                     |   2 +-
 tools/libxc/xg_sr_save_x86_hvm.c             |   2 +-
 tools/libxc/xg_sr_save_x86_pv.c              |   2 +-
 tools/libxc/xg_sr_stream_format.h            | 150 +++++++++
 28 files changed, 822 insertions(+), 822 deletions(-)

diff --git a/tools/libxc/xc_dom_decompress.h b/tools/libxc/xc_dom_decompress.h
deleted file mode 100644
index 42cefa3f0e..0000000000
--- a/tools/libxc/xc_dom_decompress.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __MINIOS__
-# include "xc_dom.h"
-#else
-# include "xc_dom_decompress_unsafe.h"
-#endif
-
-int xc_try_lz4_decode(struct xc_dom_image *dom, void **blob, size_t *size);
-
diff --git a/tools/libxc/xc_dom_decompress_unsafe.h b/tools/libxc/xc_dom_decompress_unsafe.h
deleted file mode 100644
index 64f68864b1..0000000000
--- a/tools/libxc/xc_dom_decompress_unsafe.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "xc_dom.h"
-
-typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
-                          int (*fill)(void*, unsigned int),
-                          int (*flush)(void*, unsigned int),
-                          unsigned char *outbuf, unsigned int *posp,
-                          void (*error)(const char *x));
-
-int xc_dom_decompress_unsafe(
-    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-
-int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
-int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size)
-    __attribute__((visibility("internal")));
diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
deleted file mode 100644
index f3bdea8006..0000000000
--- a/tools/libxc/xc_sr_common.h
+++ /dev/null
@@ -1,468 +0,0 @@
-#ifndef __COMMON__H
-#define __COMMON__H
-
-#include <stdbool.h>
-
-#include "xg_private.h"
-#include "xg_save_restore.h"
-#include "xc_dom.h"
-#include "xc_bitops.h"
-
-#include "xc_sr_stream_format.h"
-
-/* String representation of Domain Header types. */
-const char *dhdr_type_to_str(uint32_t type);
-
-/* String representation of Record types. */
-const char *rec_type_to_str(uint32_t type);
-
-struct xc_sr_context;
-struct xc_sr_record;
-
-/**
- * Save operations.  To be implemented for each type of guest, for use by the
- * common save algorithm.
- *
- * Every function must be implemented, even if only with a no-op stub.
- */
-struct xc_sr_save_ops
-{
-    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
-    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /**
-     * Optionally transform the contents of a page from being specific to the
-     * sending environment, to being generic for the stream.
-     *
-     * The page of data at the end of 'page' may be a read-only mapping of a
-     * running guest; it must not be modified.  If no transformation is
-     * required, the callee should leave '*pages' untouched.
-     *
-     * If a transformation is required, the callee should allocate themselves
-     * a local page using malloc() and return it via '*page'.
-     *
-     * The caller shall free() '*page' in all cases.  In the case that the
-     * callee encounters an error, it should *NOT* free() the memory it
-     * allocated for '*page'.
-     *
-     * It is valid to fail with EAGAIN if the transformation is not able to be
-     * completed at this point.  The page shall be retried later.
-     *
-     * @returns 0 for success, -1 for failure, with errno appropriately set.
-     */
-    int (*normalise_page)(struct xc_sr_context *ctx, xen_pfn_t type,
-                          void **page);
-
-    /**
-     * Set up local environment to save a domain. (Typically querying
-     * running domain state, setting up mappings etc.)
-     *
-     * This is called once before any common setup has occurred, allowing for
-     * guest-specific adjustments to be made to common state.
-     */
-    int (*setup)(struct xc_sr_context *ctx);
-
-    /**
-     * Send static records at the head of the stream.  This is called once,
-     * after the Image and Domain headers are written.
-     */
-    int (*static_data)(struct xc_sr_context *ctx);
-
-    /**
-     * Send dynamic records which need to be at the start of the stream.  This
-     * is called after the STATIC_DATA_END record is written.
-     */
-    int (*start_of_stream)(struct xc_sr_context *ctx);
-
-    /**
-     * Send records which need to be at the start of a checkpoint.  This is
-     * called once, or once per checkpoint in a checkpointed stream, and is
-     * ahead of memory data.
-     */
-    int (*start_of_checkpoint)(struct xc_sr_context *ctx);
-
-    /**
-     * Send records which need to be at the end of the checkpoint.  This is
-     * called once, or once per checkpoint in a checkpointed stream, and is
-     * after the memory data.
-     */
-    int (*end_of_checkpoint)(struct xc_sr_context *ctx);
-
-    /**
-     * Check state of guest to decide whether it makes sense to continue
-     * migration.  This is called in each iteration or checkpoint to check
-     * whether all criteria for the migration are still met.  If that's not
-     * the case either migration is cancelled via a bad rc or the situation
-     * is handled, e.g. by sending appropriate records.
-     */
-    int (*check_vm_state)(struct xc_sr_context *ctx);
-
-    /**
-     * Clean up the local environment.  Will be called exactly once, either
-     * after a successful save, or upon encountering an error.
-     */
-    int (*cleanup)(struct xc_sr_context *ctx);
-};
-
-
-/**
- * Restore operations.  To be implemented for each type of guest, for use by
- * the common restore algorithm.
- *
- * Every function must be implemented, even if only with a no-op stub.
- */
-struct xc_sr_restore_ops
-{
-    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
-    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /* Check to see whether a PFN is valid. */
-    bool (*pfn_is_valid)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
-
-    /* Set the GFN of a PFN. */
-    void (*set_gfn)(struct xc_sr_context *ctx, xen_pfn_t pfn, xen_pfn_t gfn);
-
-    /* Set the type of a PFN. */
-    void (*set_page_type)(struct xc_sr_context *ctx, xen_pfn_t pfn,
-                          xen_pfn_t type);
-
-    /**
-     * Optionally transform the contents of a page from being generic in the
-     * stream, to being specific to the restoring environment.
-     *
-     * 'page' is expected to be modified in-place if a transformation is
-     * required.
-     *
-     * @returns 0 for success, -1 for failure, with errno appropriately set.
-     */
-    int (*localise_page)(struct xc_sr_context *ctx, uint32_t type, void *page);
-
-    /**
-     * Set up local environment to restore a domain.
-     *
-     * This is called once before any common setup has occurred, allowing for
-     * guest-specific adjustments to be made to common state.
-     */
-    int (*setup)(struct xc_sr_context *ctx);
-
-    /**
-     * Process an individual record from the stream.  The caller shall take
-     * care of processing common records (e.g. END, PAGE_DATA).
-     *
-     * @return 0 for success, -1 for failure, or the following sentinels:
-     *  - RECORD_NOT_PROCESSED
-     *  - BROKEN_CHANNEL: under Remus/COLO, this means master may be dead, and
-     *    a failover is needed.
-     */
-#define RECORD_NOT_PROCESSED 1
-#define BROKEN_CHANNEL 2
-    int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
-
-    /**
-     * Perform any actions required after the static data has arrived.  Called
-     * when the STATIC_DATA_COMPLETE record has been recieved/inferred.
-     * 'missing' should be filled in for any data item the higher level
-     * toolstack needs to provide compatiblity for.
-     */
-    int (*static_data_complete)(struct xc_sr_context *ctx,
-                                unsigned int *missing);
-
-    /**
-     * Perform any actions required after the stream has been finished. Called
-     * after the END record has been received.
-     */
-    int (*stream_complete)(struct xc_sr_context *ctx);
-
-    /**
-     * Clean up the local environment.  Will be called exactly once, either
-     * after a successful restore, or upon encountering an error.
-     */
-    int (*cleanup)(struct xc_sr_context *ctx);
-};
-
-/* Wrapper for blobs of data heading Xen-wards. */
-struct xc_sr_blob
-{
-    void *ptr;
-    size_t size;
-};
-
-/*
- * Update a blob.  Duplicate src/size, freeing the old blob if necessary.  May
- * fail due to memory allocation.
- */
-static inline int update_blob(struct xc_sr_blob *blob,
-                              const void *src, size_t size)
-{
-    void *ptr;
-
-    if ( !src || !size )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if ( (ptr = malloc(size)) == NULL )
-        return -1;
-
-    free(blob->ptr);
-    blob->ptr = memcpy(ptr, src, size);
-    blob->size = size;
-
-    return 0;
-}
-
-struct xc_sr_context
-{
-    xc_interface *xch;
-    uint32_t domid;
-    int fd;
-
-    /* Plain VM, or checkpoints over time. */
-    xc_stream_type_t stream_type;
-
-    xc_dominfo_t dominfo;
-
-    union /* Common save or restore data. */
-    {
-        struct /* Save data. */
-        {
-            int recv_fd;
-
-            struct xc_sr_save_ops ops;
-            struct save_callbacks *callbacks;
-
-            /* Live migrate vs non live suspend. */
-            bool live;
-
-            /* Further debugging information in the stream. */
-            bool debug;
-
-            unsigned long p2m_size;
-
-            struct precopy_stats stats;
-
-            xen_pfn_t *batch_pfns;
-            unsigned int nr_batch_pfns;
-            unsigned long *deferred_pages;
-            unsigned long nr_deferred_pages;
-            xc_hypercall_buffer_t dirty_bitmap_hbuf;
-        } save;
-
-        struct /* Restore data. */
-        {
-            struct xc_sr_restore_ops ops;
-            struct restore_callbacks *callbacks;
-
-            int send_back_fd;
-            unsigned long p2m_size;
-            xc_hypercall_buffer_t dirty_bitmap_hbuf;
-
-            /* From Image Header. */
-            uint32_t format_version;
-
-            /* From Domain Header. */
-            uint32_t guest_type;
-            uint32_t guest_page_size;
-
-            /* Currently buffering records between a checkpoint */
-            bool buffer_all_records;
-
-            /* Whether a STATIC_DATA_END record has been seen/inferred. */
-            bool seen_static_data_end;
-
-/*
- * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
- * in case the primary will fail, we can recover from the last
- * checkpoint state.
- * This should be enough for most of the cases because primary only send
- * dirty pages at checkpoint.
- */
-#define DEFAULT_BUF_RECORDS 1024
-            struct xc_sr_record *buffered_records;
-            unsigned int allocated_rec_num;
-            unsigned int buffered_rec_num;
-
-            /*
-             * Xenstore and Console parameters.
-             * INPUT:  evtchn & domid
-             * OUTPUT: gfn
-             */
-            xen_pfn_t    xenstore_gfn,    console_gfn;
-            unsigned int xenstore_evtchn, console_evtchn;
-            uint32_t     xenstore_domid,  console_domid;
-
-            /* Bitmap of currently populated PFNs during restore. */
-            unsigned long *populated_pfns;
-            xen_pfn_t max_populated_pfn;
-
-            /* Sender has invoked verify mode on the stream. */
-            bool verify;
-        } restore;
-    };
-
-    union /* Guest-arch specific data. */
-    {
-        struct /* x86 */
-        {
-            /* Common save/restore data. */
-            union
-            {
-                struct
-                {
-                    /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */
-                    struct xc_sr_blob cpuid, msr;
-                } restore;
-            };
-
-            struct /* x86 PV guest. */
-            {
-                /* 4 or 8; 32 or 64 bit domain */
-                unsigned int width;
-                /* 3 or 4 pagetable levels */
-                unsigned int levels;
-
-                /* Maximum Xen frame */
-                xen_pfn_t max_mfn;
-                /* Read-only machine to phys map */
-                xen_pfn_t *m2p;
-                /* first mfn of the compat m2p (Only needed for 32bit PV guests) */
-                xen_pfn_t compat_m2p_mfn0;
-                /* Number of m2p frames mapped */
-                unsigned long nr_m2p_frames;
-
-                /* Maximum guest frame */
-                xen_pfn_t max_pfn;
-
-                /* Number of frames making up the p2m */
-                unsigned int p2m_frames;
-                /* Guest's phys to machine map.  Mapped read-only (save) or
-                 * allocated locally (restore).  Uses guest unsigned longs. */
-                void *p2m;
-                /* The guest pfns containing the p2m leaves */
-                xen_pfn_t *p2m_pfns;
-
-                /* Read-only mapping of guests shared info page */
-                shared_info_any_t *shinfo;
-
-                /* p2m generation count for verifying validity of local p2m. */
-                uint64_t p2m_generation;
-
-                union
-                {
-                    struct
-                    {
-                        /* State machine for the order of received records. */
-                        bool seen_pv_info;
-
-                        /* Types for each page (bounded by max_pfn). */
-                        uint32_t *pfn_types;
-
-                        /* x86 PV per-vcpu storage structure for blobs. */
-                        struct xc_sr_x86_pv_restore_vcpu
-                        {
-                            struct xc_sr_blob basic, extd, xsave, msr;
-                        } *vcpus;
-                        unsigned int nr_vcpus;
-                    } restore;
-                };
-            } pv;
-
-            struct /* x86 HVM guest. */
-            {
-                union
-                {
-                    struct
-                    {
-                        /* Whether qemu enabled logdirty mode, and we should
-                         * disable on cleanup. */
-                        bool qemu_enabled_logdirty;
-                    } save;
-
-                    struct
-                    {
-                        /* HVM context blob. */
-                        struct xc_sr_blob context;
-                    } restore;
-                };
-            } hvm;
-
-        } x86;
-    };
-};
-
-extern struct xc_sr_save_ops save_ops_x86_pv;
-extern struct xc_sr_save_ops save_ops_x86_hvm;
-
-extern struct xc_sr_restore_ops restore_ops_x86_pv;
-extern struct xc_sr_restore_ops restore_ops_x86_hvm;
-
-struct xc_sr_record
-{
-    uint32_t type;
-    uint32_t length;
-    void *data;
-};
-
-/*
- * Writes a split record to the stream, applying correct padding where
- * appropriate.  It is common when sending records containing blobs from Xen
- * that the header and blob data are separate.  This function accepts a second
- * buffer and length, and will merge it with the main record when sending.
- *
- * Records with a non-zero length must provide a valid data field; records
- * with a 0 length shall have their data field ignored.
- *
- * Returns 0 on success and non0 on failure.
- */
-int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
-                       void *buf, size_t sz);
-
-/*
- * Writes a record to the stream, applying correct padding where appropriate.
- * Records with a non-zero length must provide a valid data field; records
- * with a 0 length shall have their data field ignored.
- *
- * Returns 0 on success and non0 on failure.
- */
-static inline int write_record(struct xc_sr_context *ctx,
-                               struct xc_sr_record *rec)
-{
-    return write_split_record(ctx, rec, NULL, 0);
-}
-
-/*
- * Reads a record from the stream, and fills in the record structure.
- *
- * Returns 0 on success and non-0 on failure.
- *
- * On success, the records type and size shall be valid.
- * - If size is 0, data shall be NULL.
- * - If size is non-0, data shall be a buffer allocated by malloc() which must
- *   be passed to free() by the caller.
- *
- * On failure, the contents of the record structure are undefined.
- */
-int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
-
-/*
- * This would ideally be private in restore.c, but is needed by
- * x86_pv_localise_page() if we receive pagetables frames ahead of the
- * contents of the frames they point at.
- */
-int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
-                  const xen_pfn_t *original_pfns, const uint32_t *types);
-
-/* Handle a STATIC_DATA_END record. */
-int handle_static_data_end(struct xc_sr_context *ctx);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h
deleted file mode 100644
index e08d81e0e7..0000000000
--- a/tools/libxc/xc_sr_common_x86.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef __COMMON_X86__H
-#define __COMMON_X86__H
-
-#include "xc_sr_common.h"
-
-/*
- * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO record
- * into the stream.
- */
-int write_x86_tsc_info(struct xc_sr_context *ctx);
-
-/*
- * Parses a X86_TSC_INFO record and applies the result to the domain.
- */
-int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
-
-/*
- * Obtains a domains CPU Policy from Xen, and writes X86_{CPUID,MSR}_POLICY
- * records into the stream.
- */
-int write_x86_cpu_policy_records(struct xc_sr_context *ctx);
-
-/*
- * Parses an X86_CPUID_POLICY record and stashes the content for application
- * when a STATIC_DATA_END record is encountered.
- */
-int handle_x86_cpuid_policy(struct xc_sr_context *ctx,
-                            struct xc_sr_record *rec);
-
-/*
- * Parses an X86_MSR_POLICY record and stashes the content for application
- * when a STATIC_DATA_END record is encountered.
- */
-int handle_x86_msr_policy(struct xc_sr_context *ctx,
-                          struct xc_sr_record *rec);
-
-/*
- * Perform common x86 actions required after the static data has arrived.
- */
-int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_common_x86_pv.h b/tools/libxc/xc_sr_common_x86_pv.h
deleted file mode 100644
index 2ed03309af..0000000000
--- a/tools/libxc/xc_sr_common_x86_pv.h
+++ /dev/null
@@ -1,109 +0,0 @@
-#ifndef __COMMON_X86_PV_H
-#define __COMMON_X86_PV_H
-
-#include "xc_sr_common_x86.h"
-
-/* Virtual address ranges reserved for hypervisor. */
-#define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL
-#define HYPERVISOR_VIRT_END_X86_64   0xFFFF87FFFFFFFFFFULL
-
-#define HYPERVISOR_VIRT_START_X86_32 0x00000000F5800000ULL
-#define HYPERVISOR_VIRT_END_X86_32   0x00000000FFFFFFFFULL
-
-/*
- * Convert an mfn to a pfn, given Xen's m2p table.
- *
- * Caller must ensure that the requested mfn is in range.
- */
-xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Query whether a particular mfn is valid in the physmap of a guest.
- */
-bool mfn_in_pseudophysmap(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Debug a particular mfn by walking the p2m and m2p.
- */
-void dump_bad_pseudophysmap_entry(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/*
- * Convert a PV cr3 field to an mfn.
- *
- * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
- * a 32bit architectural cr3.
- */
-xen_pfn_t cr3_to_mfn(struct xc_sr_context *ctx, uint64_t cr3);
-
-/*
- * Convert an mfn to a PV cr3 field.
- *
- * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
- * a 32bit architectural cr3.
- */
-uint64_t mfn_to_cr3(struct xc_sr_context *ctx, xen_pfn_t mfn);
-
-/* Bits 12 through 51 of a PTE point at the frame */
-#define PTE_FRAME_MASK 0x000ffffffffff000ULL
-
-/*
- * Extract an mfn from a Pagetable Entry.  May return INVALID_MFN if the pte
- * would overflow a 32bit xen_pfn_t.
- */
-static inline xen_pfn_t pte_to_frame(uint64_t pte)
-{
-    uint64_t frame = (pte & PTE_FRAME_MASK) >> PAGE_SHIFT;
-
-#ifdef __i386__
-    if ( frame >= INVALID_MFN )
-        return INVALID_MFN;
-#endif
-
-    return frame;
-}
-
-/*
- * Change the frame in a Pagetable Entry while leaving the flags alone.
- */
-static inline uint64_t merge_pte(uint64_t pte, xen_pfn_t mfn)
-{
-    return (pte & ~PTE_FRAME_MASK) | ((uint64_t)mfn << PAGE_SHIFT);
-}
-
-/*
- * Get current domain information.
- *
- * Fills ctx->x86.pv
- * - .width
- * - .levels
- * - .fpp
- * - .p2m_frames
- *
- * Used by the save side to create the X86_PV_INFO record, and by the restore
- * side to verify the incoming stream.
- *
- * Returns 0 on success and non-zero on error.
- */
-int x86_pv_domain_info(struct xc_sr_context *ctx);
-
-/*
- * Maps the Xen M2P.
- *
- * Fills ctx->x86.pv.
- * - .max_mfn
- * - .m2p
- *
- * Returns 0 on success and non-zero on error.
- */
-int x86_pv_map_m2p(struct xc_sr_context *ctx);
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xc_sr_stream_format.h b/tools/libxc/xc_sr_stream_format.h
deleted file mode 100644
index 8a0da26f75..0000000000
--- a/tools/libxc/xc_sr_stream_format.h
+++ /dev/null
@@ -1,150 +0,0 @@
-#ifndef __STREAM_FORMAT__H
-#define __STREAM_FORMAT__H
-
-/*
- * C structures for the Migration v2 stream format.
- * See docs/specs/libxc-migration-stream.pandoc
- */
-
-#include <inttypes.h>
-
-/*
- * Image Header
- */
-struct xc_sr_ihdr
-{
-    uint64_t marker;
-    uint32_t id;
-    uint32_t version;
-    uint16_t options;
-    uint16_t _res1;
-    uint32_t _res2;
-};
-
-#define IHDR_MARKER  0xffffffffffffffffULL
-#define IHDR_ID      0x58454E46U
-
-#define _IHDR_OPT_ENDIAN 0
-#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
-#define IHDR_OPT_BIG_ENDIAN    (1 << _IHDR_OPT_ENDIAN)
-
-/*
- * Domain Header
- */
-struct xc_sr_dhdr
-{
-    uint32_t type;
-    uint16_t page_shift;
-    uint16_t _res1;
-    uint32_t xen_major;
-    uint32_t xen_minor;
-};
-
-#define DHDR_TYPE_X86_PV  0x00000001U
-#define DHDR_TYPE_X86_HVM 0x00000002U
-
-/*
- * Record Header
- */
-struct xc_sr_rhdr
-{
-    uint32_t type;
-    uint32_t length;
-};
-
-/* All records must be aligned up to an 8 octet boundary */
-#define REC_ALIGN_ORDER               (3U)
-/* Somewhat arbitrary - 128MB */
-#define REC_LENGTH_MAX                (128U << 20)
-
-#define REC_TYPE_END                        0x00000000U
-#define REC_TYPE_PAGE_DATA                  0x00000001U
-#define REC_TYPE_X86_PV_INFO                0x00000002U
-#define REC_TYPE_X86_PV_P2M_FRAMES          0x00000003U
-#define REC_TYPE_X86_PV_VCPU_BASIC          0x00000004U
-#define REC_TYPE_X86_PV_VCPU_EXTENDED       0x00000005U
-#define REC_TYPE_X86_PV_VCPU_XSAVE          0x00000006U
-#define REC_TYPE_SHARED_INFO                0x00000007U
-#define REC_TYPE_X86_TSC_INFO               0x00000008U
-#define REC_TYPE_HVM_CONTEXT                0x00000009U
-#define REC_TYPE_HVM_PARAMS                 0x0000000aU
-#define REC_TYPE_TOOLSTACK                  0x0000000bU
-#define REC_TYPE_X86_PV_VCPU_MSRS           0x0000000cU
-#define REC_TYPE_VERIFY                     0x0000000dU
-#define REC_TYPE_CHECKPOINT                 0x0000000eU
-#define REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST  0x0000000fU
-#define REC_TYPE_STATIC_DATA_END            0x00000010U
-#define REC_TYPE_X86_CPUID_POLICY           0x00000011U
-#define REC_TYPE_X86_MSR_POLICY             0x00000012U
-
-#define REC_TYPE_OPTIONAL             0x80000000U
-
-/* PAGE_DATA */
-struct xc_sr_rec_page_data_header
-{
-    uint32_t count;
-    uint32_t _res1;
-    uint64_t pfn[0];
-};
-
-#define PAGE_DATA_PFN_MASK  0x000fffffffffffffULL
-#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
-
-/* X86_PV_INFO */
-struct xc_sr_rec_x86_pv_info
-{
-    uint8_t guest_width;
-    uint8_t pt_levels;
-    uint8_t _res[6];
-};
-
-/* X86_PV_P2M_FRAMES */
-struct xc_sr_rec_x86_pv_p2m_frames
-{
-    uint32_t start_pfn;
-    uint32_t end_pfn;
-    uint64_t p2m_pfns[0];
-};
-
-/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */
-struct xc_sr_rec_x86_pv_vcpu_hdr
-{
-    uint32_t vcpu_id;
-    uint32_t _res1;
-    uint8_t context[0];
-};
-
-/* X86_TSC_INFO */
-struct xc_sr_rec_x86_tsc_info
-{
-    uint32_t mode;
-    uint32_t khz;
-    uint64_t nsec;
-    uint32_t incarnation;
-    uint32_t _res1;
-};
-
-/* HVM_PARAMS */
-struct xc_sr_rec_hvm_params_entry
-{
-    uint64_t index;
-    uint64_t value;
-};
-
-struct xc_sr_rec_hvm_params
-{
-    uint32_t count;
-    uint32_t _res1;
-    struct xc_sr_rec_hvm_params_entry param[0];
-};
-
-#endif
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/xg_dom_bzimageloader.c b/tools/libxc/xg_dom_bzimageloader.c
index a7d70cc7c6..f959a77602 100644
--- a/tools/libxc/xg_dom_bzimageloader.c
+++ b/tools/libxc/xg_dom_bzimageloader.c
@@ -32,7 +32,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress.h"
+#include "xg_dom_decompress.h"
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxc/xg_dom_decompress.h b/tools/libxc/xg_dom_decompress.h
new file mode 100644
index 0000000000..d9a21cf297
--- /dev/null
+++ b/tools/libxc/xg_dom_decompress.h
@@ -0,0 +1,8 @@
+#ifndef __MINIOS__
+# include "xc_dom.h"
+#else
+# include "xg_dom_decompress_unsafe.h"
+#endif
+
+int xc_try_lz4_decode(struct xc_dom_image *dom, void **blob, size_t *size);
+
diff --git a/tools/libxc/xg_dom_decompress_lz4.c b/tools/libxc/xg_dom_decompress_lz4.c
index b6a33f27a8..97ba620d86 100644
--- a/tools/libxc/xg_dom_decompress_lz4.c
+++ b/tools/libxc/xg_dom_decompress_lz4.c
@@ -4,7 +4,7 @@
 #include <stdint.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress.h"
+#include "xg_dom_decompress.h"
 
 #define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe.c b/tools/libxc/xg_dom_decompress_unsafe.c
index 164e35558f..21d964787d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe.c
+++ b/tools/libxc/xg_dom_decompress_unsafe.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 static struct xc_dom_image *unsafe_dom;
 static unsigned char *output_blob;
diff --git a/tools/libxc/xg_dom_decompress_unsafe.h b/tools/libxc/xg_dom_decompress_unsafe.h
new file mode 100644
index 0000000000..64f68864b1
--- /dev/null
+++ b/tools/libxc/xg_dom_decompress_unsafe.h
@@ -0,0 +1,20 @@
+#include "xc_dom.h"
+
+typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
+                          int (*fill)(void*, unsigned int),
+                          int (*flush)(void*, unsigned int),
+                          unsigned char *outbuf, unsigned int *posp,
+                          void (*error)(const char *x));
+
+int xc_dom_decompress_unsafe(
+    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+
+int xc_try_bzip2_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_lzma_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_lzo1x_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
+int xc_try_xz_decode(struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("internal")));
diff --git a/tools/libxc/xg_dom_decompress_unsafe_bzip2.c b/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
index 4dcabe4061..9d3709e6cc 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_bzip2.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 #include "../../xen/common/bunzip2.c"
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe_lzma.c b/tools/libxc/xg_dom_decompress_unsafe_lzma.c
index 4ee8cdbab1..5d178f0c43 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_lzma.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_lzma.c
@@ -3,7 +3,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 #include "../../xen/common/unlzma.c"
 
diff --git a/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c b/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
index 59888b9da2..a4f8ebd42d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_lzo1x.c
@@ -5,7 +5,7 @@
 #include <stdint.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 typedef uint8_t u8;
 typedef uint32_t u32;
diff --git a/tools/libxc/xg_dom_decompress_unsafe_xz.c b/tools/libxc/xg_dom_decompress_unsafe_xz.c
index fe7a7f49b4..ff6824b38d 100644
--- a/tools/libxc/xg_dom_decompress_unsafe_xz.c
+++ b/tools/libxc/xg_dom_decompress_unsafe_xz.c
@@ -6,7 +6,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom_decompress_unsafe.h"
+#include "xg_dom_decompress_unsafe.h"
 
 // TODO
 #define XZ_DEC_X86
diff --git a/tools/libxc/xg_sr_common.c b/tools/libxc/xg_sr_common.c
index 7c54b03414..17567ab133 100644
--- a/tools/libxc/xg_sr_common.c
+++ b/tools/libxc/xg_sr_common.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxc/xg_sr_common.h b/tools/libxc/xg_sr_common.h
new file mode 100644
index 0000000000..35f23fabb5
--- /dev/null
+++ b/tools/libxc/xg_sr_common.h
@@ -0,0 +1,468 @@
+#ifndef __COMMON__H
+#define __COMMON__H
+
+#include <stdbool.h>
+
+#include "xg_private.h"
+#include "xg_save_restore.h"
+#include "xc_dom.h"
+#include "xc_bitops.h"
+
+#include "xg_sr_stream_format.h"
+
+/* String representation of Domain Header types. */
+const char *dhdr_type_to_str(uint32_t type);
+
+/* String representation of Record types. */
+const char *rec_type_to_str(uint32_t type);
+
+struct xc_sr_context;
+struct xc_sr_record;
+
+/**
+ * Save operations.  To be implemented for each type of guest, for use by the
+ * common save algorithm.
+ *
+ * Every function must be implemented, even if only with a no-op stub.
+ */
+struct xc_sr_save_ops
+{
+    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
+    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /**
+     * Optionally transform the contents of a page from being specific to the
+     * sending environment, to being generic for the stream.
+     *
+     * The page of data at the end of 'page' may be a read-only mapping of a
+     * running guest; it must not be modified.  If no transformation is
+     * required, the callee should leave '*pages' untouched.
+     *
+     * If a transformation is required, the callee should allocate themselves
+     * a local page using malloc() and return it via '*page'.
+     *
+     * The caller shall free() '*page' in all cases.  In the case that the
+     * callee encounters an error, it should *NOT* free() the memory it
+     * allocated for '*page'.
+     *
+     * It is valid to fail with EAGAIN if the transformation is not able to be
+     * completed at this point.  The page shall be retried later.
+     *
+     * @returns 0 for success, -1 for failure, with errno appropriately set.
+     */
+    int (*normalise_page)(struct xc_sr_context *ctx, xen_pfn_t type,
+                          void **page);
+
+    /**
+     * Set up local environment to save a domain. (Typically querying
+     * running domain state, setting up mappings etc.)
+     *
+     * This is called once before any common setup has occurred, allowing for
+     * guest-specific adjustments to be made to common state.
+     */
+    int (*setup)(struct xc_sr_context *ctx);
+
+    /**
+     * Send static records at the head of the stream.  This is called once,
+     * after the Image and Domain headers are written.
+     */
+    int (*static_data)(struct xc_sr_context *ctx);
+
+    /**
+     * Send dynamic records which need to be at the start of the stream.  This
+     * is called after the STATIC_DATA_END record is written.
+     */
+    int (*start_of_stream)(struct xc_sr_context *ctx);
+
+    /**
+     * Send records which need to be at the start of a checkpoint.  This is
+     * called once, or once per checkpoint in a checkpointed stream, and is
+     * ahead of memory data.
+     */
+    int (*start_of_checkpoint)(struct xc_sr_context *ctx);
+
+    /**
+     * Send records which need to be at the end of the checkpoint.  This is
+     * called once, or once per checkpoint in a checkpointed stream, and is
+     * after the memory data.
+     */
+    int (*end_of_checkpoint)(struct xc_sr_context *ctx);
+
+    /**
+     * Check state of guest to decide whether it makes sense to continue
+     * migration.  This is called in each iteration or checkpoint to check
+     * whether all criteria for the migration are still met.  If that's not
+     * the case either migration is cancelled via a bad rc or the situation
+     * is handled, e.g. by sending appropriate records.
+     */
+    int (*check_vm_state)(struct xc_sr_context *ctx);
+
+    /**
+     * Clean up the local environment.  Will be called exactly once, either
+     * after a successful save, or upon encountering an error.
+     */
+    int (*cleanup)(struct xc_sr_context *ctx);
+};
+
+
+/**
+ * Restore operations.  To be implemented for each type of guest, for use by
+ * the common restore algorithm.
+ *
+ * Every function must be implemented, even if only with a no-op stub.
+ */
+struct xc_sr_restore_ops
+{
+    /* Convert a PFN to GFN.  May return ~0UL for an invalid mapping. */
+    xen_pfn_t (*pfn_to_gfn)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /* Check to see whether a PFN is valid. */
+    bool (*pfn_is_valid)(const struct xc_sr_context *ctx, xen_pfn_t pfn);
+
+    /* Set the GFN of a PFN. */
+    void (*set_gfn)(struct xc_sr_context *ctx, xen_pfn_t pfn, xen_pfn_t gfn);
+
+    /* Set the type of a PFN. */
+    void (*set_page_type)(struct xc_sr_context *ctx, xen_pfn_t pfn,
+                          xen_pfn_t type);
+
+    /**
+     * Optionally transform the contents of a page from being generic in the
+     * stream, to being specific to the restoring environment.
+     *
+     * 'page' is expected to be modified in-place if a transformation is
+     * required.
+     *
+     * @returns 0 for success, -1 for failure, with errno appropriately set.
+     */
+    int (*localise_page)(struct xc_sr_context *ctx, uint32_t type, void *page);
+
+    /**
+     * Set up local environment to restore a domain.
+     *
+     * This is called once before any common setup has occurred, allowing for
+     * guest-specific adjustments to be made to common state.
+     */
+    int (*setup)(struct xc_sr_context *ctx);
+
+    /**
+     * Process an individual record from the stream.  The caller shall take
+     * care of processing common records (e.g. END, PAGE_DATA).
+     *
+     * @return 0 for success, -1 for failure, or the following sentinels:
+     *  - RECORD_NOT_PROCESSED
+     *  - BROKEN_CHANNEL: under Remus/COLO, this means master may be dead, and
+     *    a failover is needed.
+     */
+#define RECORD_NOT_PROCESSED 1
+#define BROKEN_CHANNEL 2
+    int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+
+    /**
+     * Perform any actions required after the static data has arrived.  Called
+     * when the STATIC_DATA_COMPLETE record has been recieved/inferred.
+     * 'missing' should be filled in for any data item the higher level
+     * toolstack needs to provide compatiblity for.
+     */
+    int (*static_data_complete)(struct xc_sr_context *ctx,
+                                unsigned int *missing);
+
+    /**
+     * Perform any actions required after the stream has been finished. Called
+     * after the END record has been received.
+     */
+    int (*stream_complete)(struct xc_sr_context *ctx);
+
+    /**
+     * Clean up the local environment.  Will be called exactly once, either
+     * after a successful restore, or upon encountering an error.
+     */
+    int (*cleanup)(struct xc_sr_context *ctx);
+};
+
+/* Wrapper for blobs of data heading Xen-wards. */
+struct xc_sr_blob
+{
+    void *ptr;
+    size_t size;
+};
+
+/*
+ * Update a blob.  Duplicate src/size, freeing the old blob if necessary.  May
+ * fail due to memory allocation.
+ */
+static inline int update_blob(struct xc_sr_blob *blob,
+                              const void *src, size_t size)
+{
+    void *ptr;
+
+    if ( !src || !size )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    if ( (ptr = malloc(size)) == NULL )
+        return -1;
+
+    free(blob->ptr);
+    blob->ptr = memcpy(ptr, src, size);
+    blob->size = size;
+
+    return 0;
+}
+
+struct xc_sr_context
+{
+    xc_interface *xch;
+    uint32_t domid;
+    int fd;
+
+    /* Plain VM, or checkpoints over time. */
+    xc_stream_type_t stream_type;
+
+    xc_dominfo_t dominfo;
+
+    union /* Common save or restore data. */
+    {
+        struct /* Save data. */
+        {
+            int recv_fd;
+
+            struct xc_sr_save_ops ops;
+            struct save_callbacks *callbacks;
+
+            /* Live migrate vs non live suspend. */
+            bool live;
+
+            /* Further debugging information in the stream. */
+            bool debug;
+
+            unsigned long p2m_size;
+
+            struct precopy_stats stats;
+
+            xen_pfn_t *batch_pfns;
+            unsigned int nr_batch_pfns;
+            unsigned long *deferred_pages;
+            unsigned long nr_deferred_pages;
+            xc_hypercall_buffer_t dirty_bitmap_hbuf;
+        } save;
+
+        struct /* Restore data. */
+        {
+            struct xc_sr_restore_ops ops;
+            struct restore_callbacks *callbacks;
+
+            int send_back_fd;
+            unsigned long p2m_size;
+            xc_hypercall_buffer_t dirty_bitmap_hbuf;
+
+            /* From Image Header. */
+            uint32_t format_version;
+
+            /* From Domain Header. */
+            uint32_t guest_type;
+            uint32_t guest_page_size;
+
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+            /* Whether a STATIC_DATA_END record has been seen/inferred. */
+            bool seen_static_data_end;
+
+/*
+ * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough for most of the cases because primary only send
+ * dirty pages at checkpoint.
+ */
+#define DEFAULT_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned int allocated_rec_num;
+            unsigned int buffered_rec_num;
+
+            /*
+             * Xenstore and Console parameters.
+             * INPUT:  evtchn & domid
+             * OUTPUT: gfn
+             */
+            xen_pfn_t    xenstore_gfn,    console_gfn;
+            unsigned int xenstore_evtchn, console_evtchn;
+            uint32_t     xenstore_domid,  console_domid;
+
+            /* Bitmap of currently populated PFNs during restore. */
+            unsigned long *populated_pfns;
+            xen_pfn_t max_populated_pfn;
+
+            /* Sender has invoked verify mode on the stream. */
+            bool verify;
+        } restore;
+    };
+
+    union /* Guest-arch specific data. */
+    {
+        struct /* x86 */
+        {
+            /* Common save/restore data. */
+            union
+            {
+                struct
+                {
+                    /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */
+                    struct xc_sr_blob cpuid, msr;
+                } restore;
+            };
+
+            struct /* x86 PV guest. */
+            {
+                /* 4 or 8; 32 or 64 bit domain */
+                unsigned int width;
+                /* 3 or 4 pagetable levels */
+                unsigned int levels;
+
+                /* Maximum Xen frame */
+                xen_pfn_t max_mfn;
+                /* Read-only machine to phys map */
+                xen_pfn_t *m2p;
+                /* first mfn of the compat m2p (Only needed for 32bit PV guests) */
+                xen_pfn_t compat_m2p_mfn0;
+                /* Number of m2p frames mapped */
+                unsigned long nr_m2p_frames;
+
+                /* Maximum guest frame */
+                xen_pfn_t max_pfn;
+
+                /* Number of frames making up the p2m */
+                unsigned int p2m_frames;
+                /* Guest's phys to machine map.  Mapped read-only (save) or
+                 * allocated locally (restore).  Uses guest unsigned longs. */
+                void *p2m;
+                /* The guest pfns containing the p2m leaves */
+                xen_pfn_t *p2m_pfns;
+
+                /* Read-only mapping of guests shared info page */
+                shared_info_any_t *shinfo;
+
+                /* p2m generation count for verifying validity of local p2m. */
+                uint64_t p2m_generation;
+
+                union
+                {
+                    struct
+                    {
+                        /* State machine for the order of received records. */
+                        bool seen_pv_info;
+
+                        /* Types for each page (bounded by max_pfn). */
+                        uint32_t *pfn_types;
+
+                        /* x86 PV per-vcpu storage structure for blobs. */
+                        struct xc_sr_x86_pv_restore_vcpu
+                        {
+                            struct xc_sr_blob basic, extd, xsave, msr;
+                        } *vcpus;
+                        unsigned int nr_vcpus;
+                    } restore;
+                };
+            } pv;
+
+            struct /* x86 HVM guest. */
+            {
+                union
+                {
+                    struct
+                    {
+                        /* Whether qemu enabled logdirty mode, and we should
+                         * disable on cleanup. */
+                        bool qemu_enabled_logdirty;
+                    } save;
+
+                    struct
+                    {
+                        /* HVM context blob. */
+                        struct xc_sr_blob context;
+                    } restore;
+                };
+            } hvm;
+
+        } x86;
+    };
+};
+
+extern struct xc_sr_save_ops save_ops_x86_pv;
+extern struct xc_sr_save_ops save_ops_x86_hvm;
+
+extern struct xc_sr_restore_ops restore_ops_x86_pv;
+extern struct xc_sr_restore_ops restore_ops_x86_hvm;
+
+struct xc_sr_record
+{
+    uint32_t type;
+    uint32_t length;
+    void *data;
+};
+
+/*
+ * Writes a split record to the stream, applying correct padding where
+ * appropriate.  It is common when sending records containing blobs from Xen
+ * that the header and blob data are separate.  This function accepts a second
+ * buffer and length, and will merge it with the main record when sending.
+ *
+ * Records with a non-zero length must provide a valid data field; records
+ * with a 0 length shall have their data field ignored.
+ *
+ * Returns 0 on success and non0 on failure.
+ */
+int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
+                       void *buf, size_t sz);
+
+/*
+ * Writes a record to the stream, applying correct padding where appropriate.
+ * Records with a non-zero length must provide a valid data field; records
+ * with a 0 length shall have their data field ignored.
+ *
+ * Returns 0 on success and non0 on failure.
+ */
+static inline int write_record(struct xc_sr_context *ctx,
+                               struct xc_sr_record *rec)
+{
+    return write_split_record(ctx, rec, NULL, 0);
+}
+
+/*
+ * Reads a record from the stream, and fills in the record structure.
+ *
+ * Returns 0 on success and non-0 on failure.
+ *
+ * On success, the records type and size shall be valid.
+ * - If size is 0, data shall be NULL.
+ * - If size is non-0, data shall be a buffer allocated by malloc() which must
+ *   be passed to free() by the caller.
+ *
+ * On failure, the contents of the record structure are undefined.
+ */
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
+
+/*
+ * This would ideally be private in restore.c, but is needed by
+ * x86_pv_localise_page() if we receive pagetables frames ahead of the
+ * contents of the frames they point at.
+ */
+int populate_pfns(struct xc_sr_context *ctx, unsigned int count,
+                  const xen_pfn_t *original_pfns, const uint32_t *types);
+
+/* Handle a STATIC_DATA_END record. */
+int handle_static_data_end(struct xc_sr_context *ctx);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_common_x86.c b/tools/libxc/xg_sr_common_x86.c
index 77ea044a74..6f12483907 100644
--- a/tools/libxc/xg_sr_common_x86.c
+++ b/tools/libxc/xg_sr_common_x86.c
@@ -1,4 +1,4 @@
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 int write_x86_tsc_info(struct xc_sr_context *ctx)
 {
diff --git a/tools/libxc/xg_sr_common_x86.h b/tools/libxc/xg_sr_common_x86.h
new file mode 100644
index 0000000000..b55758c96d
--- /dev/null
+++ b/tools/libxc/xg_sr_common_x86.h
@@ -0,0 +1,51 @@
+#ifndef __COMMON_X86__H
+#define __COMMON_X86__H
+
+#include "xg_sr_common.h"
+
+/*
+ * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO record
+ * into the stream.
+ */
+int write_x86_tsc_info(struct xc_sr_context *ctx);
+
+/*
+ * Parses a X86_TSC_INFO record and applies the result to the domain.
+ */
+int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+
+/*
+ * Obtains a domains CPU Policy from Xen, and writes X86_{CPUID,MSR}_POLICY
+ * records into the stream.
+ */
+int write_x86_cpu_policy_records(struct xc_sr_context *ctx);
+
+/*
+ * Parses an X86_CPUID_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_cpuid_policy(struct xc_sr_context *ctx,
+                            struct xc_sr_record *rec);
+
+/*
+ * Parses an X86_MSR_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_msr_policy(struct xc_sr_context *ctx,
+                          struct xc_sr_record *rec);
+
+/*
+ * Perform common x86 actions required after the static data has arrived.
+ */
+int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_common_x86_pv.c b/tools/libxc/xg_sr_common_x86_pv.c
index d3d425cb82..cd33406aab 100644
--- a/tools/libxc/xg_sr_common_x86_pv.c
+++ b/tools/libxc/xg_sr_common_x86_pv.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn)
 {
diff --git a/tools/libxc/xg_sr_common_x86_pv.h b/tools/libxc/xg_sr_common_x86_pv.h
new file mode 100644
index 0000000000..953b5bfb8d
--- /dev/null
+++ b/tools/libxc/xg_sr_common_x86_pv.h
@@ -0,0 +1,109 @@
+#ifndef __COMMON_X86_PV_H
+#define __COMMON_X86_PV_H
+
+#include "xg_sr_common_x86.h"
+
+/* Virtual address ranges reserved for hypervisor. */
+#define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL
+#define HYPERVISOR_VIRT_END_X86_64   0xFFFF87FFFFFFFFFFULL
+
+#define HYPERVISOR_VIRT_START_X86_32 0x00000000F5800000ULL
+#define HYPERVISOR_VIRT_END_X86_32   0x00000000FFFFFFFFULL
+
+/*
+ * Convert an mfn to a pfn, given Xen's m2p table.
+ *
+ * Caller must ensure that the requested mfn is in range.
+ */
+xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Query whether a particular mfn is valid in the physmap of a guest.
+ */
+bool mfn_in_pseudophysmap(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Debug a particular mfn by walking the p2m and m2p.
+ */
+void dump_bad_pseudophysmap_entry(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/*
+ * Convert a PV cr3 field to an mfn.
+ *
+ * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
+ * a 32bit architectural cr3.
+ */
+xen_pfn_t cr3_to_mfn(struct xc_sr_context *ctx, uint64_t cr3);
+
+/*
+ * Convert an mfn to a PV cr3 field.
+ *
+ * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into
+ * a 32bit architectural cr3.
+ */
+uint64_t mfn_to_cr3(struct xc_sr_context *ctx, xen_pfn_t mfn);
+
+/* Bits 12 through 51 of a PTE point at the frame */
+#define PTE_FRAME_MASK 0x000ffffffffff000ULL
+
+/*
+ * Extract an mfn from a Pagetable Entry.  May return INVALID_MFN if the pte
+ * would overflow a 32bit xen_pfn_t.
+ */
+static inline xen_pfn_t pte_to_frame(uint64_t pte)
+{
+    uint64_t frame = (pte & PTE_FRAME_MASK) >> PAGE_SHIFT;
+
+#ifdef __i386__
+    if ( frame >= INVALID_MFN )
+        return INVALID_MFN;
+#endif
+
+    return frame;
+}
+
+/*
+ * Change the frame in a Pagetable Entry while leaving the flags alone.
+ */
+static inline uint64_t merge_pte(uint64_t pte, xen_pfn_t mfn)
+{
+    return (pte & ~PTE_FRAME_MASK) | ((uint64_t)mfn << PAGE_SHIFT);
+}
+
+/*
+ * Get current domain information.
+ *
+ * Fills ctx->x86.pv
+ * - .width
+ * - .levels
+ * - .fpp
+ * - .p2m_frames
+ *
+ * Used by the save side to create the X86_PV_INFO record, and by the restore
+ * side to verify the incoming stream.
+ *
+ * Returns 0 on success and non-zero on error.
+ */
+int x86_pv_domain_info(struct xc_sr_context *ctx);
+
+/*
+ * Maps the Xen M2P.
+ *
+ * Fills ctx->x86.pv.
+ * - .max_mfn
+ * - .m2p
+ *
+ * Returns 0 on success and non-zero on error.
+ */
+int x86_pv_map_m2p(struct xc_sr_context *ctx);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xg_sr_restore.c b/tools/libxc/xg_sr_restore.c
index bc811e6e3a..b57a787519 100644
--- a/tools/libxc/xg_sr_restore.c
+++ b/tools/libxc/xg_sr_restore.c
@@ -2,7 +2,7 @@
 
 #include <assert.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 /*
  * Read and validate the Image and Domain headers.
diff --git a/tools/libxc/xg_sr_restore_x86_hvm.c b/tools/libxc/xg_sr_restore_x86_hvm.c
index a77624cc9d..d6ea6f3012 100644
--- a/tools/libxc/xg_sr_restore_x86_hvm.c
+++ b/tools/libxc/xg_sr_restore_x86_hvm.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <arpa/inet.h>
 
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 /*
  * Process an HVM_CONTEXT record from the stream.
diff --git a/tools/libxc/xg_sr_restore_x86_pv.c b/tools/libxc/xg_sr_restore_x86_pv.c
index d086271efb..dc50b0f5a8 100644
--- a/tools/libxc/xg_sr_restore_x86_pv.c
+++ b/tools/libxc/xg_sr_restore_x86_pv.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 static xen_pfn_t pfn_to_mfn(const struct xc_sr_context *ctx, xen_pfn_t pfn)
 {
diff --git a/tools/libxc/xg_sr_save.c b/tools/libxc/xg_sr_save.c
index 80b1d5de1f..d74c72cba6 100644
--- a/tools/libxc/xg_sr_save.c
+++ b/tools/libxc/xg_sr_save.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <arpa/inet.h>
 
-#include "xc_sr_common.h"
+#include "xg_sr_common.h"
 
 /*
  * Writes an Image header and Domain header into the stream.
diff --git a/tools/libxc/xg_sr_save_x86_hvm.c b/tools/libxc/xg_sr_save_x86_hvm.c
index 0b2abb26bd..1634a7bc43 100644
--- a/tools/libxc/xg_sr_save_x86_hvm.c
+++ b/tools/libxc/xg_sr_save_x86_hvm.c
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#include "xc_sr_common_x86.h"
+#include "xg_sr_common_x86.h"
 
 #include <xen/hvm/params.h>
 
diff --git a/tools/libxc/xg_sr_save_x86_pv.c b/tools/libxc/xg_sr_save_x86_pv.c
index c7e246ef4f..4964f1f7b8 100644
--- a/tools/libxc/xg_sr_save_x86_pv.c
+++ b/tools/libxc/xg_sr_save_x86_pv.c
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <limits.h>
 
-#include "xc_sr_common_x86_pv.h"
+#include "xg_sr_common_x86_pv.h"
 
 /* Check a 64 bit virtual address for being canonical. */
 static inline bool is_canonical_address(xen_vaddr_t vaddr)
diff --git a/tools/libxc/xg_sr_stream_format.h b/tools/libxc/xg_sr_stream_format.h
new file mode 100644
index 0000000000..8a0da26f75
--- /dev/null
+++ b/tools/libxc/xg_sr_stream_format.h
@@ -0,0 +1,150 @@
+#ifndef __STREAM_FORMAT__H
+#define __STREAM_FORMAT__H
+
+/*
+ * C structures for the Migration v2 stream format.
+ * See docs/specs/libxc-migration-stream.pandoc
+ */
+
+#include <inttypes.h>
+
+/*
+ * Image Header
+ */
+struct xc_sr_ihdr
+{
+    uint64_t marker;
+    uint32_t id;
+    uint32_t version;
+    uint16_t options;
+    uint16_t _res1;
+    uint32_t _res2;
+};
+
+#define IHDR_MARKER  0xffffffffffffffffULL
+#define IHDR_ID      0x58454E46U
+
+#define _IHDR_OPT_ENDIAN 0
+#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
+#define IHDR_OPT_BIG_ENDIAN    (1 << _IHDR_OPT_ENDIAN)
+
+/*
+ * Domain Header
+ */
+struct xc_sr_dhdr
+{
+    uint32_t type;
+    uint16_t page_shift;
+    uint16_t _res1;
+    uint32_t xen_major;
+    uint32_t xen_minor;
+};
+
+#define DHDR_TYPE_X86_PV  0x00000001U
+#define DHDR_TYPE_X86_HVM 0x00000002U
+
+/*
+ * Record Header
+ */
+struct xc_sr_rhdr
+{
+    uint32_t type;
+    uint32_t length;
+};
+
+/* All records must be aligned up to an 8 octet boundary */
+#define REC_ALIGN_ORDER               (3U)
+/* Somewhat arbitrary - 128MB */
+#define REC_LENGTH_MAX                (128U << 20)
+
+#define REC_TYPE_END                        0x00000000U
+#define REC_TYPE_PAGE_DATA                  0x00000001U
+#define REC_TYPE_X86_PV_INFO                0x00000002U
+#define REC_TYPE_X86_PV_P2M_FRAMES          0x00000003U
+#define REC_TYPE_X86_PV_VCPU_BASIC          0x00000004U
+#define REC_TYPE_X86_PV_VCPU_EXTENDED       0x00000005U
+#define REC_TYPE_X86_PV_VCPU_XSAVE          0x00000006U
+#define REC_TYPE_SHARED_INFO                0x00000007U
+#define REC_TYPE_X86_TSC_INFO               0x00000008U
+#define REC_TYPE_HVM_CONTEXT                0x00000009U
+#define REC_TYPE_HVM_PARAMS                 0x0000000aU
+#define REC_TYPE_TOOLSTACK                  0x0000000bU
+#define REC_TYPE_X86_PV_VCPU_MSRS           0x0000000cU
+#define REC_TYPE_VERIFY                     0x0000000dU
+#define REC_TYPE_CHECKPOINT                 0x0000000eU
+#define REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST  0x0000000fU
+#define REC_TYPE_STATIC_DATA_END            0x00000010U
+#define REC_TYPE_X86_CPUID_POLICY           0x00000011U
+#define REC_TYPE_X86_MSR_POLICY             0x00000012U
+
+#define REC_TYPE_OPTIONAL             0x80000000U
+
+/* PAGE_DATA */
+struct xc_sr_rec_page_data_header
+{
+    uint32_t count;
+    uint32_t _res1;
+    uint64_t pfn[0];
+};
+
+#define PAGE_DATA_PFN_MASK  0x000fffffffffffffULL
+#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
+
+/* X86_PV_INFO */
+struct xc_sr_rec_x86_pv_info
+{
+    uint8_t guest_width;
+    uint8_t pt_levels;
+    uint8_t _res[6];
+};
+
+/* X86_PV_P2M_FRAMES */
+struct xc_sr_rec_x86_pv_p2m_frames
+{
+    uint32_t start_pfn;
+    uint32_t end_pfn;
+    uint64_t p2m_pfns[0];
+};
+
+/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */
+struct xc_sr_rec_x86_pv_vcpu_hdr
+{
+    uint32_t vcpu_id;
+    uint32_t _res1;
+    uint8_t context[0];
+};
+
+/* X86_TSC_INFO */
+struct xc_sr_rec_x86_tsc_info
+{
+    uint32_t mode;
+    uint32_t khz;
+    uint64_t nsec;
+    uint32_t incarnation;
+    uint32_t _res1;
+};
+
+/* HVM_PARAMS */
+struct xc_sr_rec_hvm_params_entry
+{
+    uint64_t index;
+    uint64_t value;
+};
+
+struct xc_sr_rec_hvm_params
+{
+    uint32_t count;
+    uint32_t _res1;
+    struct xc_sr_rec_hvm_params_entry param[0];
+};
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMKo-0006Jn-GQ; Fri, 18 Sep 2020 19:46:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMKn-0006Jg-WB
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:18 +0000
X-Inumbo-ID: dcc5a7de-56b2-4a05-aaa6-242e07a13bd8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id dcc5a7de-56b2-4a05-aaa6-242e07a13bd8;
 Fri, 18 Sep 2020 19:46:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=f3yOjuwOaYzlBCGgYQL1M3MEFwKJwXXm0aTad9x6oKc=; b=yuNHmRzOpPvAzi/nDzVjiWbmA9
 uGGACf2S4s4WxiFtpFfEAot5MG1YtORHCtshhCbD3xBvCXsZy8j8Upp40hKqZr3u9b8G/vGcEZm9U
 wCOcEzd1qrojsS6SY32T+snqmSmlefAkx8I3ffkGMAQGF95Ec5CxGgd3NRAWML9t3LDw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKk-000774-Ta
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:14 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKk-0004NP-Sp
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/misc: rename xc_dom.h do xenctrl_dom.h
Message-Id: <E1kJMKk-0004NP-Sp@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 068000ab05f8e8195762d3ba580758cd8ea0857b
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:30 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/misc: rename xc_dom.h do xenctrl_dom.h
    
    For being able to disentangle lixenctrl and libxenguest headers
    xc_dom.h will need to be public. Prepare that by renaming xc_dom.h
    to xenctrl_dom.h.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 stubdom/grub/kexec.c                   |   2 +-
 tools/helpers/init-xenstore-domain.c   |   2 +-
 tools/libxc/include/xc_dom.h           | 449 ---------------------------------
 tools/libxc/include/xenctrl_dom.h      | 449 +++++++++++++++++++++++++++++++++
 tools/libxc/xc_core.c                  |   2 +-
 tools/libxc/xc_private.c               |   2 +-
 tools/libxc/xg_dom_arm.c               |   2 +-
 tools/libxc/xg_dom_armzimageloader.c   |   2 +-
 tools/libxc/xg_dom_binloader.c         |   2 +-
 tools/libxc/xg_dom_boot.c              |   2 +-
 tools/libxc/xg_dom_compat_linux.c      |   2 +-
 tools/libxc/xg_dom_core.c              |   2 +-
 tools/libxc/xg_dom_decompress.h        |   2 +-
 tools/libxc/xg_dom_decompress_unsafe.h |   2 +-
 tools/libxc/xg_dom_elfloader.c         |   2 +-
 tools/libxc/xg_dom_hvmloader.c         |   2 +-
 tools/libxc/xg_dom_x86.c               |   2 +-
 tools/libxc/xg_offline_page.c          |   2 +-
 tools/libxc/xg_sr_common.h             |   2 +-
 tools/libxl/libxl_arm.c                |   2 +-
 tools/libxl/libxl_arm.h                |   2 +-
 tools/libxl/libxl_create.c             |   2 +-
 tools/libxl/libxl_dm.c                 |   2 +-
 tools/libxl/libxl_dom.c                |   2 +-
 tools/libxl/libxl_internal.h           |   2 +-
 tools/libxl/libxl_vnuma.c              |   2 +-
 tools/libxl/libxl_x86.c                |   2 +-
 tools/libxl/libxl_x86_acpi.c           |   2 +-
 tools/python/xen/lowlevel/xc/xc.c      |   2 +-
 tools/xcutils/readnotes.c              |   2 +-
 30 files changed, 477 insertions(+), 477 deletions(-)

diff --git a/stubdom/grub/kexec.c b/stubdom/grub/kexec.c
index 0e68b969a2..24001220a9 100644
--- a/stubdom/grub/kexec.c
+++ b/stubdom/grub/kexec.c
@@ -20,7 +20,7 @@
 #include <sys/mman.h>
 
 #include <xenctrl.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 #include <kernel.h>
 #include <console.h>
diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 4ce8299c3c..5bdb48dc80 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -8,7 +8,7 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <xenctrl.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xenstore.h>
 #include <xen/sys/xenbus_dev.h>
 #include <xen-xsm/flask/flask.h>
diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h
deleted file mode 100644
index 52a4d6c8c0..0000000000
--- a/tools/libxc/include/xc_dom.h
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _XC_DOM_H
-#define _XC_DOM_H
-
-#include <xen/libelf/libelf.h>
-#include <xenguest.h>
-
-#define INVALID_PFN ((xen_pfn_t)-1)
-#define X86_HVM_NR_SPECIAL_PAGES    8
-#define X86_HVM_END_SPECIAL_REGION  0xff000u
-#define XG_MAX_MODULES 2
-
-/* --- typedefs and structs ---------------------------------------- */
-
-typedef uint64_t xen_vaddr_t;
-typedef uint64_t xen_paddr_t;
-
-#define PRIpfn PRI_xen_pfn
-
-struct xc_dom_seg {
-    xen_vaddr_t vstart;
-    xen_vaddr_t vend;
-    xen_pfn_t pfn;
-    xen_pfn_t pages;
-};
-
-struct xc_dom_mem {
-    struct xc_dom_mem *next;
-    void *ptr;
-    enum {
-        XC_DOM_MEM_TYPE_MALLOC_INTERNAL,
-        XC_DOM_MEM_TYPE_MALLOC_EXTERNAL,
-        XC_DOM_MEM_TYPE_MMAP,
-    } type;
-    size_t len;
-    unsigned char memory[0];
-};
-
-struct xc_dom_phys {
-    struct xc_dom_phys *next;
-    void *ptr;
-    xen_pfn_t first;
-    xen_pfn_t count;
-};
-
-struct xc_dom_module {
-    void *blob;
-    size_t size;
-    void *cmdline;
-    /* If seg.vstart is non zero then the module will be loaded at that
-     * address, otherwise it will automatically placed.
-     *
-     * If automatic placement is used and the module is gzip
-     * compressed then it will be decompressed as it is loaded. If the
-     * module has been explicitly placed then it is loaded as is
-     * otherwise decompressing risks undoing the manual placement.
-     */
-    struct xc_dom_seg seg;
-};
-
-struct xc_dom_image {
-    /* files */
-    void *kernel_blob;
-    size_t kernel_size;
-    unsigned int num_modules;
-    struct xc_dom_module modules[XG_MAX_MODULES];
-    void *devicetree_blob;
-    size_t devicetree_size;
-
-    size_t max_kernel_size;
-    size_t max_module_size;
-    size_t max_devicetree_size;
-
-    /* arguments and parameters */
-    char *cmdline;
-    size_t cmdline_size;
-    uint32_t f_requested[XENFEAT_NR_SUBMAPS];
-
-    /* info from (elf) kernel image */
-    struct elf_dom_parms parms;
-    char *guest_type;
-
-    /* memory layout */
-    struct xc_dom_seg kernel_seg;
-    struct xc_dom_seg p2m_seg;
-    struct xc_dom_seg pgtables_seg;
-    struct xc_dom_seg devicetree_seg;
-    struct xc_dom_seg start_info_seg;
-    xen_pfn_t start_info_pfn;
-    xen_pfn_t console_pfn;
-    xen_pfn_t xenstore_pfn;
-    xen_pfn_t shared_info_pfn;
-    xen_pfn_t bootstack_pfn;
-    xen_pfn_t pfn_alloc_end;
-    xen_vaddr_t virt_alloc_end;
-    xen_vaddr_t bsd_symtab_start;
-
-    /*
-     * initrd parameters as specified in start_info page
-     * Depending on capabilities of the booted kernel this may be a virtual
-     * address or a pfn. Type is neutral and large enough to hold a virtual
-     * address of a 64 bit kernel even with 32 bit toolstack.
-     */
-    uint64_t initrd_start;
-    uint64_t initrd_len;
-
-    unsigned int alloc_bootstack;
-    xen_vaddr_t virt_pgtab_end;
-
-    /* other state info */
-    uint32_t f_active[XENFEAT_NR_SUBMAPS];
-
-    /*
-     * pv_p2m is specific to x86 PV guests, and maps GFNs to MFNs.  It is
-     * eventually copied into guest context.
-     */
-    xen_pfn_t *pv_p2m;
-
-    /* physical memory
-     *
-     * An x86 PV guest has one or more blocks of physical RAM,
-     * consisting of total_pages starting at 0. The start address and
-     * size of each block is controlled by vNUMA structures.
-     *
-     * An ARM guest has GUEST_RAM_BANKS regions of RAM, with
-     * rambank_size[i] pages in each. The lowest RAM address
-     * (corresponding to the base of the p2m arrays above) is stored
-     * in rambase_pfn.
-     */
-    xen_pfn_t rambase_pfn;
-    xen_pfn_t total_pages;
-    xen_pfn_t p2m_size;         /* number of pfns covered by p2m */
-    struct xc_dom_phys *phys_pages;
-#if defined (__arm__) || defined(__aarch64__)
-    xen_pfn_t rambank_size[GUEST_RAM_BANKS];
-#endif
-
-    /* malloc memory pool */
-    struct xc_dom_mem *memblocks;
-
-    /* memory footprint stats */
-    size_t alloc_malloc;
-    size_t alloc_mem_map;
-    size_t alloc_file_map;
-    size_t alloc_domU_map;
-
-    /* misc xen domain config stuff */
-    unsigned long flags;
-    unsigned int console_evtchn;
-    unsigned int xenstore_evtchn;
-    uint32_t console_domid;
-    uint32_t xenstore_domid;
-    xen_pfn_t shared_info_mfn;
-
-    xc_interface *xch;
-    uint32_t guest_domid;
-    int claim_enabled; /* 0 by default, 1 enables it */
-
-    int xen_version;
-    xen_capabilities_info_t xen_caps;
-
-    /* kernel loader, arch hooks */
-    struct xc_dom_loader *kernel_loader;
-    void *private_loader;
-
-    /* vNUMA information */
-    xen_vmemrange_t *vmemranges;
-    unsigned int nr_vmemranges;
-    unsigned int *vnode_to_pnode;
-    unsigned int nr_vnodes;
-
-    /* domain type/architecture specific data */
-    void *arch_private;
-
-    /* kernel loader */
-    struct xc_dom_arch *arch_hooks;
-    /* allocate up to pfn_alloc_end */
-    int (*allocate) (struct xc_dom_image * dom);
-
-    /* Container type (HVM or PV). */
-    enum {
-        XC_DOM_PV_CONTAINER,
-        XC_DOM_HVM_CONTAINER,
-    } container_type;
-
-    /* HVM specific fields. */
-    xen_pfn_t target_pages;
-    xen_paddr_t mmio_start;
-    xen_paddr_t mmio_size;
-    xen_paddr_t lowmem_end;
-    xen_paddr_t highmem_end;
-    xen_pfn_t vga_hole_size;
-
-    /* If unset disables the setup of the IOREQ pages. */
-    bool device_model;
-
-    /* BIOS/Firmware passed to HVMLOADER */
-    struct xc_hvm_firmware_module system_firmware_module;
-
-    /* Extra ACPI tables */
-#define MAX_ACPI_MODULES        4
-    struct xc_hvm_firmware_module acpi_modules[MAX_ACPI_MODULES];
-
-    /* Extra SMBIOS structures passed to HVMLOADER */
-    struct xc_hvm_firmware_module smbios_module;
-
-#if defined(__i386__) || defined(__x86_64__)
-    struct e820entry *e820;
-    unsigned int e820_entries;
-#endif
-
-    xen_pfn_t vuart_gfn;
-
-    /* Number of vCPUs */
-    unsigned int max_vcpus;
-};
-
-/* --- pluggable kernel loader ------------------------------------- */
-
-struct xc_dom_loader {
-    char *name;
-    /* Sadly the error returns from these functions are not consistent: */
-    elf_negerrnoval (*probe) (struct xc_dom_image * dom);
-    elf_negerrnoval (*parser) (struct xc_dom_image * dom);
-    elf_errorstatus (*loader) (struct xc_dom_image * dom);
-
-    struct xc_dom_loader *next;
-};
-
-#define __init __attribute__ ((constructor))
-void xc_dom_register_loader(struct xc_dom_loader *loader);
-
-/* --- arch specific hooks ----------------------------------------- */
-
-struct xc_dom_arch {
-    int (*alloc_magic_pages) (struct xc_dom_image * dom);
-
-    /* pagetable setup - x86 PV only */
-    int (*alloc_pgtables) (struct xc_dom_image * dom);
-    int (*alloc_p2m_list) (struct xc_dom_image * dom);
-    int (*setup_pgtables) (struct xc_dom_image * dom);
-
-    /* arch-specific data structs setup */
-    int (*start_info) (struct xc_dom_image * dom);
-    int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
-    int (*vcpu) (struct xc_dom_image * dom);
-    int (*bootearly) (struct xc_dom_image * dom);
-    int (*bootlate) (struct xc_dom_image * dom);
-
-    /* arch-specific memory initialization. */
-    int (*meminit) (struct xc_dom_image * dom);
-
-    char *guest_type;
-    char *native_protocol;
-    int page_shift;
-    int sizeof_pfn;
-    int p2m_base_supported;
-    int arch_private_size;
-
-    struct xc_dom_arch *next;
-};
-void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
-
-#define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
-#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
-
-/* --- main functions ---------------------------------------------- */
-
-struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
-                                     const char *cmdline, const char *features);
-void xc_dom_release_phys(struct xc_dom_image *dom);
-void xc_dom_release(struct xc_dom_image *dom);
-int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase);
-int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
-
-/* Set this larger if you have enormous modules/kernels. Note that
- * you should trust all kernels not to be maliciously large (e.g. to
- * exhaust all dom0 memory) if you do this (see CVE-2012-4544 /
- * XSA-25). You can also set the default independently for
- * modules/kernels in xc_dom_allocate() or call
- * xc_dom_{kernel,module}_max_size.
- */
-#ifndef XC_DOM_DECOMPRESS_MAX
-#define XC_DOM_DECOMPRESS_MAX (1024*1024*1024) /* 1GB */
-#endif
-
-int xc_dom_kernel_check_size(struct xc_dom_image *dom, size_t sz);
-int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
-
-int xc_dom_module_max_size(struct xc_dom_image *dom, size_t sz);
-
-int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
-
-size_t xc_dom_check_gzip(xc_interface *xch,
-                     void *blob, size_t ziplen);
-int xc_dom_do_gunzip(xc_interface *xch,
-                     void *src, size_t srclen, void *dst, size_t dstlen);
-int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
-
-int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
-int xc_dom_module_file(struct xc_dom_image *dom, const char *filename,
-                       const char *cmdline);
-int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
-                      size_t memsize);
-int xc_dom_module_mem(struct xc_dom_image *dom, const void *mem,
-                       size_t memsize, const char *cmdline);
-int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename);
-int xc_dom_devicetree_mem(struct xc_dom_image *dom, const void *mem,
-                          size_t memsize);
-
-int xc_dom_parse_image(struct xc_dom_image *dom);
-int xc_dom_set_arch_hooks(struct xc_dom_image *dom);
-int xc_dom_build_image(struct xc_dom_image *dom);
-
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch,
-                         uint32_t domid);
-int xc_dom_boot_mem_init(struct xc_dom_image *dom);
-void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
-                           xen_pfn_t count);
-int xc_dom_boot_image(struct xc_dom_image *dom);
-int xc_dom_compat_check(struct xc_dom_image *dom);
-int xc_dom_gnttab_init(struct xc_dom_image *dom);
-int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
-                       bool is_hvm,
-                       xen_pfn_t console_gfn,
-                       xen_pfn_t xenstore_gfn,
-                       uint32_t console_domid,
-                       uint32_t xenstore_domid);
-bool xc_dom_translated(const struct xc_dom_image *dom);
-
-/* --- debugging bits ---------------------------------------------- */
-
-int xc_dom_loginit(xc_interface *xch);
-
-void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
-     __attribute__ ((format(printf, 2, 3)));
-void xc_dom_panic_func(xc_interface *xch,
-                      const char *file, int line, xc_error_code err,
-                      const char *fmt, ...)
-    __attribute__ ((format(printf, 5, 6)));
-
-#define xc_dom_panic(xch, err, fmt, args...) \
-    xc_dom_panic_func(xch, __FILE__, __LINE__, err, fmt, ## args)
-#define xc_dom_trace(mark) \
-    xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
-
-void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
-
-/* --- simple memory pool ------------------------------------------ */
-
-void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
-int xc_dom_register_external(struct xc_dom_image *dom, void *ptr, size_t size);
-void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
-void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
-                            const char *filename, size_t * size,
-                            const size_t max_size);
-char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
-
-/* --- alloc memory pool ------------------------------------------- */
-
-xen_pfn_t xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
-int xc_dom_alloc_segment(struct xc_dom_image *dom,
-                         struct xc_dom_seg *seg, char *name,
-                         xen_vaddr_t start, xen_vaddr_t size);
-
-/* --- misc bits --------------------------------------------------- */
-
-void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
-                        xen_pfn_t count);
-void *xc_dom_pfn_to_ptr_retcount(struct xc_dom_image *dom, xen_pfn_t first,
-                                 xen_pfn_t count, xen_pfn_t *count_out);
-void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
-void xc_dom_unmap_all(struct xc_dom_image *dom);
-
-static inline void *xc_dom_seg_to_ptr_pages(struct xc_dom_image *dom,
-                                      struct xc_dom_seg *seg,
-                                      xen_pfn_t *pages_out)
-{
-    void *retval;
-
-    retval = xc_dom_pfn_to_ptr(dom, seg->pfn, seg->pages);
-
-    *pages_out = retval ? seg->pages : 0;
-    return retval;
-}
-
-static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
-                                      struct xc_dom_seg *seg)
-{
-    xen_pfn_t dummy;
-
-    return xc_dom_seg_to_ptr_pages(dom, seg, &dummy);
-}
-
-static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
-                                        xen_vaddr_t vaddr,
-                                        size_t *safe_region_out)
-{
-    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
-    xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
-    unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
-    xen_pfn_t safe_region_count;
-    void *ptr;
-
-    *safe_region_out = 0;
-    ptr = xc_dom_pfn_to_ptr_retcount(dom, page, 0, &safe_region_count);
-    if ( ptr == NULL )
-        return ptr;
-    *safe_region_out = (safe_region_count << XC_DOM_PAGE_SHIFT(dom)) - offset;
-    return ptr + offset;
-}
-
-static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
-{
-    if ( xc_dom_translated(dom) )
-        return pfn;
-
-    /* x86 PV only now. */
-    if ( pfn >= dom->total_pages )
-        return INVALID_MFN;
-
-    return dom->pv_p2m[pfn];
-}
-
-#endif /* _XC_DOM_H */
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxc/include/xenctrl_dom.h b/tools/libxc/include/xenctrl_dom.h
new file mode 100644
index 0000000000..52a4d6c8c0
--- /dev/null
+++ b/tools/libxc/include/xenctrl_dom.h
@@ -0,0 +1,449 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _XC_DOM_H
+#define _XC_DOM_H
+
+#include <xen/libelf/libelf.h>
+#include <xenguest.h>
+
+#define INVALID_PFN ((xen_pfn_t)-1)
+#define X86_HVM_NR_SPECIAL_PAGES    8
+#define X86_HVM_END_SPECIAL_REGION  0xff000u
+#define XG_MAX_MODULES 2
+
+/* --- typedefs and structs ---------------------------------------- */
+
+typedef uint64_t xen_vaddr_t;
+typedef uint64_t xen_paddr_t;
+
+#define PRIpfn PRI_xen_pfn
+
+struct xc_dom_seg {
+    xen_vaddr_t vstart;
+    xen_vaddr_t vend;
+    xen_pfn_t pfn;
+    xen_pfn_t pages;
+};
+
+struct xc_dom_mem {
+    struct xc_dom_mem *next;
+    void *ptr;
+    enum {
+        XC_DOM_MEM_TYPE_MALLOC_INTERNAL,
+        XC_DOM_MEM_TYPE_MALLOC_EXTERNAL,
+        XC_DOM_MEM_TYPE_MMAP,
+    } type;
+    size_t len;
+    unsigned char memory[0];
+};
+
+struct xc_dom_phys {
+    struct xc_dom_phys *next;
+    void *ptr;
+    xen_pfn_t first;
+    xen_pfn_t count;
+};
+
+struct xc_dom_module {
+    void *blob;
+    size_t size;
+    void *cmdline;
+    /* If seg.vstart is non zero then the module will be loaded at that
+     * address, otherwise it will automatically placed.
+     *
+     * If automatic placement is used and the module is gzip
+     * compressed then it will be decompressed as it is loaded. If the
+     * module has been explicitly placed then it is loaded as is
+     * otherwise decompressing risks undoing the manual placement.
+     */
+    struct xc_dom_seg seg;
+};
+
+struct xc_dom_image {
+    /* files */
+    void *kernel_blob;
+    size_t kernel_size;
+    unsigned int num_modules;
+    struct xc_dom_module modules[XG_MAX_MODULES];
+    void *devicetree_blob;
+    size_t devicetree_size;
+
+    size_t max_kernel_size;
+    size_t max_module_size;
+    size_t max_devicetree_size;
+
+    /* arguments and parameters */
+    char *cmdline;
+    size_t cmdline_size;
+    uint32_t f_requested[XENFEAT_NR_SUBMAPS];
+
+    /* info from (elf) kernel image */
+    struct elf_dom_parms parms;
+    char *guest_type;
+
+    /* memory layout */
+    struct xc_dom_seg kernel_seg;
+    struct xc_dom_seg p2m_seg;
+    struct xc_dom_seg pgtables_seg;
+    struct xc_dom_seg devicetree_seg;
+    struct xc_dom_seg start_info_seg;
+    xen_pfn_t start_info_pfn;
+    xen_pfn_t console_pfn;
+    xen_pfn_t xenstore_pfn;
+    xen_pfn_t shared_info_pfn;
+    xen_pfn_t bootstack_pfn;
+    xen_pfn_t pfn_alloc_end;
+    xen_vaddr_t virt_alloc_end;
+    xen_vaddr_t bsd_symtab_start;
+
+    /*
+     * initrd parameters as specified in start_info page
+     * Depending on capabilities of the booted kernel this may be a virtual
+     * address or a pfn. Type is neutral and large enough to hold a virtual
+     * address of a 64 bit kernel even with 32 bit toolstack.
+     */
+    uint64_t initrd_start;
+    uint64_t initrd_len;
+
+    unsigned int alloc_bootstack;
+    xen_vaddr_t virt_pgtab_end;
+
+    /* other state info */
+    uint32_t f_active[XENFEAT_NR_SUBMAPS];
+
+    /*
+     * pv_p2m is specific to x86 PV guests, and maps GFNs to MFNs.  It is
+     * eventually copied into guest context.
+     */
+    xen_pfn_t *pv_p2m;
+
+    /* physical memory
+     *
+     * An x86 PV guest has one or more blocks of physical RAM,
+     * consisting of total_pages starting at 0. The start address and
+     * size of each block is controlled by vNUMA structures.
+     *
+     * An ARM guest has GUEST_RAM_BANKS regions of RAM, with
+     * rambank_size[i] pages in each. The lowest RAM address
+     * (corresponding to the base of the p2m arrays above) is stored
+     * in rambase_pfn.
+     */
+    xen_pfn_t rambase_pfn;
+    xen_pfn_t total_pages;
+    xen_pfn_t p2m_size;         /* number of pfns covered by p2m */
+    struct xc_dom_phys *phys_pages;
+#if defined (__arm__) || defined(__aarch64__)
+    xen_pfn_t rambank_size[GUEST_RAM_BANKS];
+#endif
+
+    /* malloc memory pool */
+    struct xc_dom_mem *memblocks;
+
+    /* memory footprint stats */
+    size_t alloc_malloc;
+    size_t alloc_mem_map;
+    size_t alloc_file_map;
+    size_t alloc_domU_map;
+
+    /* misc xen domain config stuff */
+    unsigned long flags;
+    unsigned int console_evtchn;
+    unsigned int xenstore_evtchn;
+    uint32_t console_domid;
+    uint32_t xenstore_domid;
+    xen_pfn_t shared_info_mfn;
+
+    xc_interface *xch;
+    uint32_t guest_domid;
+    int claim_enabled; /* 0 by default, 1 enables it */
+
+    int xen_version;
+    xen_capabilities_info_t xen_caps;
+
+    /* kernel loader, arch hooks */
+    struct xc_dom_loader *kernel_loader;
+    void *private_loader;
+
+    /* vNUMA information */
+    xen_vmemrange_t *vmemranges;
+    unsigned int nr_vmemranges;
+    unsigned int *vnode_to_pnode;
+    unsigned int nr_vnodes;
+
+    /* domain type/architecture specific data */
+    void *arch_private;
+
+    /* kernel loader */
+    struct xc_dom_arch *arch_hooks;
+    /* allocate up to pfn_alloc_end */
+    int (*allocate) (struct xc_dom_image * dom);
+
+    /* Container type (HVM or PV). */
+    enum {
+        XC_DOM_PV_CONTAINER,
+        XC_DOM_HVM_CONTAINER,
+    } container_type;
+
+    /* HVM specific fields. */
+    xen_pfn_t target_pages;
+    xen_paddr_t mmio_start;
+    xen_paddr_t mmio_size;
+    xen_paddr_t lowmem_end;
+    xen_paddr_t highmem_end;
+    xen_pfn_t vga_hole_size;
+
+    /* If unset disables the setup of the IOREQ pages. */
+    bool device_model;
+
+    /* BIOS/Firmware passed to HVMLOADER */
+    struct xc_hvm_firmware_module system_firmware_module;
+
+    /* Extra ACPI tables */
+#define MAX_ACPI_MODULES        4
+    struct xc_hvm_firmware_module acpi_modules[MAX_ACPI_MODULES];
+
+    /* Extra SMBIOS structures passed to HVMLOADER */
+    struct xc_hvm_firmware_module smbios_module;
+
+#if defined(__i386__) || defined(__x86_64__)
+    struct e820entry *e820;
+    unsigned int e820_entries;
+#endif
+
+    xen_pfn_t vuart_gfn;
+
+    /* Number of vCPUs */
+    unsigned int max_vcpus;
+};
+
+/* --- pluggable kernel loader ------------------------------------- */
+
+struct xc_dom_loader {
+    char *name;
+    /* Sadly the error returns from these functions are not consistent: */
+    elf_negerrnoval (*probe) (struct xc_dom_image * dom);
+    elf_negerrnoval (*parser) (struct xc_dom_image * dom);
+    elf_errorstatus (*loader) (struct xc_dom_image * dom);
+
+    struct xc_dom_loader *next;
+};
+
+#define __init __attribute__ ((constructor))
+void xc_dom_register_loader(struct xc_dom_loader *loader);
+
+/* --- arch specific hooks ----------------------------------------- */
+
+struct xc_dom_arch {
+    int (*alloc_magic_pages) (struct xc_dom_image * dom);
+
+    /* pagetable setup - x86 PV only */
+    int (*alloc_pgtables) (struct xc_dom_image * dom);
+    int (*alloc_p2m_list) (struct xc_dom_image * dom);
+    int (*setup_pgtables) (struct xc_dom_image * dom);
+
+    /* arch-specific data structs setup */
+    int (*start_info) (struct xc_dom_image * dom);
+    int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
+    int (*vcpu) (struct xc_dom_image * dom);
+    int (*bootearly) (struct xc_dom_image * dom);
+    int (*bootlate) (struct xc_dom_image * dom);
+
+    /* arch-specific memory initialization. */
+    int (*meminit) (struct xc_dom_image * dom);
+
+    char *guest_type;
+    char *native_protocol;
+    int page_shift;
+    int sizeof_pfn;
+    int p2m_base_supported;
+    int arch_private_size;
+
+    struct xc_dom_arch *next;
+};
+void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
+
+#define XC_DOM_PAGE_SHIFT(dom)  ((dom)->arch_hooks->page_shift)
+#define XC_DOM_PAGE_SIZE(dom)   (1LL << (dom)->arch_hooks->page_shift)
+
+/* --- main functions ---------------------------------------------- */
+
+struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
+                                     const char *cmdline, const char *features);
+void xc_dom_release_phys(struct xc_dom_image *dom);
+void xc_dom_release(struct xc_dom_image *dom);
+int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase);
+int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
+
+/* Set this larger if you have enormous modules/kernels. Note that
+ * you should trust all kernels not to be maliciously large (e.g. to
+ * exhaust all dom0 memory) if you do this (see CVE-2012-4544 /
+ * XSA-25). You can also set the default independently for
+ * modules/kernels in xc_dom_allocate() or call
+ * xc_dom_{kernel,module}_max_size.
+ */
+#ifndef XC_DOM_DECOMPRESS_MAX
+#define XC_DOM_DECOMPRESS_MAX (1024*1024*1024) /* 1GB */
+#endif
+
+int xc_dom_kernel_check_size(struct xc_dom_image *dom, size_t sz);
+int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
+
+int xc_dom_module_max_size(struct xc_dom_image *dom, size_t sz);
+
+int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
+
+size_t xc_dom_check_gzip(xc_interface *xch,
+                     void *blob, size_t ziplen);
+int xc_dom_do_gunzip(xc_interface *xch,
+                     void *src, size_t srclen, void *dst, size_t dstlen);
+int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
+
+int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
+int xc_dom_module_file(struct xc_dom_image *dom, const char *filename,
+                       const char *cmdline);
+int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
+                      size_t memsize);
+int xc_dom_module_mem(struct xc_dom_image *dom, const void *mem,
+                       size_t memsize, const char *cmdline);
+int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename);
+int xc_dom_devicetree_mem(struct xc_dom_image *dom, const void *mem,
+                          size_t memsize);
+
+int xc_dom_parse_image(struct xc_dom_image *dom);
+int xc_dom_set_arch_hooks(struct xc_dom_image *dom);
+int xc_dom_build_image(struct xc_dom_image *dom);
+
+int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch,
+                         uint32_t domid);
+int xc_dom_boot_mem_init(struct xc_dom_image *dom);
+void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
+                           xen_pfn_t count);
+int xc_dom_boot_image(struct xc_dom_image *dom);
+int xc_dom_compat_check(struct xc_dom_image *dom);
+int xc_dom_gnttab_init(struct xc_dom_image *dom);
+int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid,
+                       bool is_hvm,
+                       xen_pfn_t console_gfn,
+                       xen_pfn_t xenstore_gfn,
+                       uint32_t console_domid,
+                       uint32_t xenstore_domid);
+bool xc_dom_translated(const struct xc_dom_image *dom);
+
+/* --- debugging bits ---------------------------------------------- */
+
+int xc_dom_loginit(xc_interface *xch);
+
+void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
+     __attribute__ ((format(printf, 2, 3)));
+void xc_dom_panic_func(xc_interface *xch,
+                      const char *file, int line, xc_error_code err,
+                      const char *fmt, ...)
+    __attribute__ ((format(printf, 5, 6)));
+
+#define xc_dom_panic(xch, err, fmt, args...) \
+    xc_dom_panic_func(xch, __FILE__, __LINE__, err, fmt, ## args)
+#define xc_dom_trace(mark) \
+    xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
+
+void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
+
+/* --- simple memory pool ------------------------------------------ */
+
+void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
+int xc_dom_register_external(struct xc_dom_image *dom, void *ptr, size_t size);
+void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
+void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
+                            const char *filename, size_t * size,
+                            const size_t max_size);
+char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
+
+/* --- alloc memory pool ------------------------------------------- */
+
+xen_pfn_t xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
+int xc_dom_alloc_segment(struct xc_dom_image *dom,
+                         struct xc_dom_seg *seg, char *name,
+                         xen_vaddr_t start, xen_vaddr_t size);
+
+/* --- misc bits --------------------------------------------------- */
+
+void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
+                        xen_pfn_t count);
+void *xc_dom_pfn_to_ptr_retcount(struct xc_dom_image *dom, xen_pfn_t first,
+                                 xen_pfn_t count, xen_pfn_t *count_out);
+void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
+void xc_dom_unmap_all(struct xc_dom_image *dom);
+
+static inline void *xc_dom_seg_to_ptr_pages(struct xc_dom_image *dom,
+                                      struct xc_dom_seg *seg,
+                                      xen_pfn_t *pages_out)
+{
+    void *retval;
+
+    retval = xc_dom_pfn_to_ptr(dom, seg->pfn, seg->pages);
+
+    *pages_out = retval ? seg->pages : 0;
+    return retval;
+}
+
+static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
+                                      struct xc_dom_seg *seg)
+{
+    xen_pfn_t dummy;
+
+    return xc_dom_seg_to_ptr_pages(dom, seg, &dummy);
+}
+
+static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
+                                        xen_vaddr_t vaddr,
+                                        size_t *safe_region_out)
+{
+    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
+    xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
+    unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
+    xen_pfn_t safe_region_count;
+    void *ptr;
+
+    *safe_region_out = 0;
+    ptr = xc_dom_pfn_to_ptr_retcount(dom, page, 0, &safe_region_count);
+    if ( ptr == NULL )
+        return ptr;
+    *safe_region_out = (safe_region_count << XC_DOM_PAGE_SHIFT(dom)) - offset;
+    return ptr + offset;
+}
+
+static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
+{
+    if ( xc_dom_translated(dom) )
+        return pfn;
+
+    /* x86 PV only now. */
+    if ( pfn >= dom->total_pages )
+        return INVALID_MFN;
+
+    return dom->pv_p2m[pfn];
+}
+
+#endif /* _XC_DOM_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index 2ee1d205b4..7df1fccd62 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -62,7 +62,7 @@
 
 #include "xg_private.h"
 #include "xc_core.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <stdlib.h>
 #include <unistd.h>
 
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 90974d572e..6ecdf6953f 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -19,7 +19,7 @@
 
 #include "xc_private.h"
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
diff --git a/tools/libxc/xg_dom_arm.c b/tools/libxc/xg_dom_arm.c
index 931404c222..3f66f1d890 100644
--- a/tools/libxc/xg_dom_arm.c
+++ b/tools/libxc/xg_dom_arm.c
@@ -24,7 +24,7 @@
 #include <xen-tools/libs.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #define NR_MAGIC_PAGES 4
 #define CONSOLE_PFN_OFFSET 0
diff --git a/tools/libxc/xg_dom_armzimageloader.c b/tools/libxc/xg_dom_armzimageloader.c
index 0df8c2a4b1..4246c8e5fa 100644
--- a/tools/libxc/xg_dom_armzimageloader.c
+++ b/tools/libxc/xg_dom_armzimageloader.c
@@ -25,7 +25,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #include <arpa/inet.h> /* XXX ntohl is not the right function... */
 
diff --git a/tools/libxc/xg_dom_binloader.c b/tools/libxc/xg_dom_binloader.c
index d6f7f2a500..870a921427 100644
--- a/tools/libxc/xg_dom_binloader.c
+++ b/tools/libxc/xg_dom_binloader.c
@@ -83,7 +83,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
diff --git a/tools/libxc/xg_dom_boot.c b/tools/libxc/xg_dom_boot.c
index bb599b33ba..1e31e92244 100644
--- a/tools/libxc/xg_dom_boot.c
+++ b/tools/libxc/xg_dom_boot.c
@@ -31,7 +31,7 @@
 #include <zlib.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_core.h"
 #include <xen/hvm/params.h>
 #include <xen/grant_table.h>
diff --git a/tools/libxc/xg_dom_compat_linux.c b/tools/libxc/xg_dom_compat_linux.c
index b3d43feed9..b645f0b14b 100644
--- a/tools/libxc/xg_dom_compat_linux.c
+++ b/tools/libxc/xg_dom_compat_linux.c
@@ -30,7 +30,7 @@
 
 #include "xenctrl.h"
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 /* ------------------------------------------------------------------------ */
 
diff --git a/tools/libxc/xg_dom_core.c b/tools/libxc/xg_dom_core.c
index 327c8a8575..1c91cce315 100644
--- a/tools/libxc/xg_dom_core.c
+++ b/tools/libxc/xg_dom_core.c
@@ -32,7 +32,7 @@
 #include <assert.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "_paths.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_dom_decompress.h b/tools/libxc/xg_dom_decompress.h
index d9a21cf297..c5ab2e59eb 100644
--- a/tools/libxc/xg_dom_decompress.h
+++ b/tools/libxc/xg_dom_decompress.h
@@ -1,5 +1,5 @@
 #ifndef __MINIOS__
-# include "xc_dom.h"
+# include "xenctrl_dom.h"
 #else
 # include "xg_dom_decompress_unsafe.h"
 #endif
diff --git a/tools/libxc/xg_dom_decompress_unsafe.h b/tools/libxc/xg_dom_decompress_unsafe.h
index 64f68864b1..fb84b6add8 100644
--- a/tools/libxc/xg_dom_decompress_unsafe.h
+++ b/tools/libxc/xg_dom_decompress_unsafe.h
@@ -1,4 +1,4 @@
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 
 typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
                           int (*fill)(void*, unsigned int),
diff --git a/tools/libxc/xg_dom_elfloader.c b/tools/libxc/xg_dom_elfloader.c
index b327db219d..7043c3bbba 100644
--- a/tools/libxc/xg_dom_elfloader.c
+++ b/tools/libxc/xg_dom_elfloader.c
@@ -26,7 +26,7 @@
 #include <inttypes.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 #define XEN_VER "xen-3.0"
diff --git a/tools/libxc/xg_dom_hvmloader.c b/tools/libxc/xg_dom_hvmloader.c
index 3f0bd65547..995a0f3dc3 100644
--- a/tools/libxc/xg_dom_hvmloader.c
+++ b/tools/libxc/xg_dom_hvmloader.c
@@ -26,7 +26,7 @@
 #include <assert.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_dom_x86.c b/tools/libxc/xg_dom_x86.c
index 9439805eaa..842dbcccdd 100644
--- a/tools/libxc/xg_dom_x86.c
+++ b/tools/libxc/xg_dom_x86.c
@@ -38,7 +38,7 @@
 #include <xen-tools/libs.h>
 
 #include "xg_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xenctrl.h"
 
 /* ------------------------------------------------------------------------ */
diff --git a/tools/libxc/xg_offline_page.c b/tools/libxc/xg_offline_page.c
index 19538fc436..77e8889b11 100644
--- a/tools/libxc/xg_offline_page.c
+++ b/tools/libxc/xg_offline_page.c
@@ -28,7 +28,7 @@
 #include <xc_core.h>
 
 #include "xc_private.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xg_private.h"
 #include "xg_save_restore.h"
 
diff --git a/tools/libxc/xg_sr_common.h b/tools/libxc/xg_sr_common.h
index 35f23fabb5..13fcc47420 100644
--- a/tools/libxc/xg_sr_common.h
+++ b/tools/libxc/xg_sr_common.h
@@ -5,7 +5,7 @@
 
 #include "xg_private.h"
 #include "xg_save_restore.h"
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include "xc_bitops.h"
 
 #include "xg_sr_stream_format.h"
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 34f8a29056..975a4d730a 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -3,7 +3,7 @@
 #include "libxl_libfdt_compat.h"
 #include "libxl_arm.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <stdbool.h>
 #include <libfdt.h>
 #include <assert.h>
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index 8aef210d4c..52c2ab5e3a 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -17,7 +17,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 _hidden
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 2814818e34..1031b75159 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -20,7 +20,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xenguest.h>
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/e820.h>
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index f2dc5696b9..fec4e0fbe5 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -19,7 +19,7 @@
 
 #include "libxl_internal.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xen/hvm/e820.h>
 #include <sys/types.h>
 #include <pwd.h>
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index f8661e90d4..e2dca64aa1 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -20,7 +20,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index c63d0686fd..e16ae9630b 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -57,7 +57,7 @@
 #include <xenctrl.h>
 #include <xenguest.h>
 #include <xenhypfs.h>
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 #include <xen-tools/libs.h>
 
diff --git a/tools/libxl/libxl_vnuma.c b/tools/libxl/libxl_vnuma.c
index 8ec2abb2e6..c2e144ceae 100644
--- a/tools/libxl/libxl_vnuma.c
+++ b/tools/libxl/libxl_vnuma.c
@@ -17,7 +17,7 @@
 #include "libxl_arch.h"
 #include <stdlib.h>
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 bool libxl__vnuma_configured(const libxl_domain_build_info *b_info)
 {
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index e57f63282e..7d95506e00 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -1,7 +1,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c
index ed6610c84e..3df86c7be5 100644
--- a/tools/libxl/libxl_x86_acpi.c
+++ b/tools/libxl/libxl_x86_acpi.c
@@ -18,7 +18,7 @@
 #include <xen/hvm/e820.h>
 #include "libacpi/libacpi.h"
 
-#include <xc_dom.h>
+#include <xenctrl_dom.h>
 
  /* Number of pages holding ACPI tables */
 #define NUM_ACPI_PAGES 16
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 8fde5f311f..8c7b184f0b 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -17,7 +17,7 @@
 #include <arpa/inet.h>
 
 #include <xen/elfnote.h>
-#include "xc_dom.h"
+#include "xenctrl_dom.h"
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/params.h>
 
diff --git a/tools/xcutils/readnotes.c b/tools/xcutils/readnotes.c
index e682dd1a21..a6b7358e70 100644
--- a/tools/xcutils/readnotes.c
+++ b/tools/xcutils/readnotes.c
@@ -12,7 +12,7 @@
 #include <sys/mman.h>
 
 #include <xg_private.h>
-#include <xc_dom.h> /* gunzip bits */
+#include <xenctrl_dom.h> /* gunzip bits */
 
 #include <xen/libelf/libelf.h>
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMKx-0006Ku-Jy; Fri, 18 Sep 2020 19:46:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMKw-0006Kj-DK
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:26 +0000
X-Inumbo-ID: 76538dc9-55d7-4814-9834-d8cc78626c0a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 76538dc9-55d7-4814-9834-d8cc78626c0a;
 Fri, 18 Sep 2020 19:46:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cZ5wPfPlos/T2bLlxd8Agwi5eBVL0yXrxJLglxakGzg=; b=ze2Vpv+Bb+UgwuPRCydgQOk1jD
 Xcc7vmE1vk6Hj+O5xw4TxuWjqEcQfmNOpdDIhYvyXsbPjelgxCHjG2mxYK/dstySRuBJMqFiFxd6j
 pOjRpRwA5N1tYvwA6bw99fVTNqG3GrEmTdu96oTb2HPa4kWUaZgW8AnGrzrdO8Qy1Qgs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKv-00077E-1Y
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMKv-0004OG-03
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: untangle libxenctrl from libxenguest
Message-Id: <E1kJMKv-0004OG-03@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7e0165c19387e8eece4c3b28d20f7fcc86533685
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:31 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: untangle libxenctrl from libxenguest
    
    Sources of libxenctrl and libxenguest are completely entangled. In
    practice libxenguest is a user of libxenctrl, so don't let any source
    libxenctrl include xg_private.h.
    
    This can be achieved by moving all definitions used by libxenctrl from
    xg_private.h to xc_private.h.
    
    Export xenctrl_dom.h as it will now be included by other public
    headers.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxc/Makefile              |  3 ++-
 tools/libxc/include/xenctrl_dom.h | 10 ++++++++--
 tools/libxc/include/xenguest.h    |  8 ++------
 tools/libxc/xc_core.c             |  5 +++--
 tools/libxc/xc_core.h             |  2 +-
 tools/libxc/xc_core_arm.c         |  2 +-
 tools/libxc/xc_core_x86.c         |  6 ++----
 tools/libxc/xc_domain.c           |  3 +--
 tools/libxc/xc_hcall_buf.c        |  1 -
 tools/libxc/xc_private.c          |  1 -
 tools/libxc/xc_private.h          | 36 ++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_resume.c           |  2 --
 tools/libxc/xg_private.h          | 22 ----------------------
 tools/libxc/xg_save_restore.h     |  9 ---------
 14 files changed, 56 insertions(+), 54 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 0fd5511143..faf2639894 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -215,7 +215,7 @@ install: build
 	$(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
-	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h $(DESTDIR)$(includedir)
+	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrl_dom.h $(DESTDIR)$(includedir)
 	$(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -235,6 +235,7 @@ uninstall:
 	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xencontrol.pc
 	rm -f $(DESTDIR)$(includedir)/xenctrl.h
 	rm -f $(DESTDIR)$(includedir)/xenctrl_compat.h
+	rm -f $(DESTDIR)$(includedir)/xenctrl_dom.h
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	rm -f $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR).$(MINOR)
diff --git a/tools/libxc/include/xenctrl_dom.h b/tools/libxc/include/xenctrl_dom.h
index 52a4d6c8c0..40b85b7755 100644
--- a/tools/libxc/include/xenctrl_dom.h
+++ b/tools/libxc/include/xenctrl_dom.h
@@ -17,9 +17,7 @@
 #define _XC_DOM_H
 
 #include <xen/libelf/libelf.h>
-#include <xenguest.h>
 
-#define INVALID_PFN ((xen_pfn_t)-1)
 #define X86_HVM_NR_SPECIAL_PAGES    8
 #define X86_HVM_END_SPECIAL_REGION  0xff000u
 #define XG_MAX_MODULES 2
@@ -38,6 +36,12 @@ struct xc_dom_seg {
     xen_pfn_t pages;
 };
 
+struct xc_hvm_firmware_module {
+    uint8_t  *data;
+    uint32_t  length;
+    uint64_t  guest_addr_out;
+};
+
 struct xc_dom_mem {
     struct xc_dom_mem *next;
     void *ptr;
@@ -255,6 +259,8 @@ struct xc_dom_arch {
     int (*setup_pgtables) (struct xc_dom_image * dom);
 
     /* arch-specific data structs setup */
+    /* in Mini-OS environment start_info might be a macro, avoid collision. */
+#undef start_info
     int (*start_info) (struct xc_dom_image * dom);
     int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
     int (*vcpu) (struct xc_dom_image * dom);
diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index 7a12d21ff2..4643384790 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -22,6 +22,8 @@
 #ifndef XENGUEST_H
 #define XENGUEST_H
 
+#include <xenctrl_dom.h>
+
 #define XC_NUMA_NO_NODE   (~0U)
 
 #define XCFLAGS_LIVE      (1 << 0)
@@ -249,12 +251,6 @@ int xc_linux_build(xc_interface *xch,
                    unsigned int console_evtchn,
                    unsigned long *console_mfn);
 
-struct xc_hvm_firmware_module {
-    uint8_t  *data;
-    uint32_t  length;
-    uint64_t  guest_addr_out;
-};
-
 /*
  * Sets *lockfd to -1.
  * Has deallocated everything even on error.
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index 7df1fccd62..e8c6fb96f9 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -60,12 +60,13 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
-#include "xenctrl_dom.h"
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <xen/libelf/libelf.h>
+
 /* number of pages to write at a time */
 #define DUMP_INCREMENT (4 * 1024)
 
diff --git a/tools/libxc/xc_core.h b/tools/libxc/xc_core.h
index ed7ed53ca5..36fb755da2 100644
--- a/tools/libxc/xc_core.h
+++ b/tools/libxc/xc_core.h
@@ -21,7 +21,7 @@
 #define XC_CORE_H
 
 #include "xen/version.h"
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xen/libelf/elfstructs.h"
 
 /* section names */
diff --git a/tools/libxc/xc_core_arm.c b/tools/libxc/xc_core_arm.c
index c3c492c971..7b587b4cc5 100644
--- a/tools/libxc/xc_core_arm.c
+++ b/tools/libxc/xc_core_arm.c
@@ -16,7 +16,7 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
 
 #include <xen-tools/libs.h>
diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c
index 54852a2d1a..cb76e6207b 100644
--- a/tools/libxc/xc_core_x86.c
+++ b/tools/libxc/xc_core_x86.c
@@ -17,12 +17,10 @@
  *
  */
 
-#include "xg_private.h"
+#include "xc_private.h"
 #include "xc_core.h"
 #include <xen/hvm/e820.h>
 
-#define GET_FIELD(_p, _f) ((dinfo->guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f))
-
 int
 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
                               unsigned long pfn)
@@ -98,7 +96,7 @@ xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, xc
 
     live_p2m_frame_list_list =
         xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_READ,
-                             GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list));
+                             GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list, dinfo->guest_width));
 
     if ( !live_p2m_frame_list_list )
     {
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index fbc22c4df6..43fab50c06 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -21,8 +21,7 @@
 
 #include "xc_private.h"
 #include "xc_core.h"
-#include "xg_private.h"
-#include "xg_save_restore.h"
+#include "xc_private.h"
 #include <xen/memory.h>
 #include <xen/hvm/hvm_op.h>
 
diff --git a/tools/libxc/xc_hcall_buf.c b/tools/libxc/xc_hcall_buf.c
index c1230a1e2b..200671f36f 100644
--- a/tools/libxc/xc_hcall_buf.c
+++ b/tools/libxc/xc_hcall_buf.c
@@ -19,7 +19,6 @@
 #include <string.h>
 
 #include "xc_private.h"
-#include "xg_private.h"
 
 xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(HYPERCALL_BUFFER_NULL) = {
     .hbuf = NULL,
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 6ecdf6953f..8af96b1b7e 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -18,7 +18,6 @@
  */
 
 #include "xc_private.h"
-#include "xg_private.h"
 #include "xenctrl_dom.h"
 #include <stdarg.h>
 #include <stdlib.h>
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index c77edb3c4c..f0b5f83ac8 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <sys/ioctl.h>
 
 #include "_paths.h"
@@ -62,6 +63,39 @@ struct iovec {
 #include <sys/uio.h>
 #endif
 
+#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
+
+#define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
+
+#define SET_FIELD(_p, _f, _v, _w) do {          \
+    if ((_w) == 8)                              \
+        (_p)->x64._f = (_v);                    \
+    else                                        \
+        (_p)->x32._f = (_v);                    \
+} while (0)
+
+/* XXX SMH: following skanky macros rely on variable p2m_size being set */
+/* XXX TJD: also, "guest_width" should be the guest's sizeof(unsigned long) */
+
+struct domain_info_context {
+    unsigned int guest_width;
+    unsigned long p2m_size;
+};
+
+/* Number of xen_pfn_t in a page */
+#define FPP             (PAGE_SIZE/(dinfo->guest_width))
+
+/* Number of entries in the pfn_to_mfn_frame_list_list */
+#define P2M_FLL_ENTRIES (((dinfo->p2m_size)+(FPP*FPP)-1)/(FPP*FPP))
+
+/* Number of entries in the pfn_to_mfn_frame_list */
+#define P2M_FL_ENTRIES  (((dinfo->p2m_size)+FPP-1)/FPP)
+
+/* Size in bytes of the pfn_to_mfn_frame_list     */
+#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (dinfo->guest_width))
+#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) *                           \
+                           max_t(size_t, sizeof(xen_pfn_t), dinfo->guest_width))
+
 #define DECLARE_DOMCTL struct xen_domctl domctl
 #define DECLARE_SYSCTL struct xen_sysctl sysctl
 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
@@ -75,6 +109,8 @@ struct iovec {
 #define PAGE_SIZE               XC_PAGE_SIZE
 #define PAGE_MASK               XC_PAGE_MASK
 
+#define INVALID_PFN ((xen_pfn_t)-1)
+
 /*
 ** Define max dirty page cache to permit during save/restore -- need to balance 
 ** keeping cache usage down with CPU impact of invalidating too often.
diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c
index c169204fac..94c6c9fb31 100644
--- a/tools/libxc/xc_resume.c
+++ b/tools/libxc/xc_resume.c
@@ -14,8 +14,6 @@
  */
 
 #include "xc_private.h"
-#include "xg_private.h"
-#include "xg_save_restore.h"
 
 #if defined(__i386__) || defined(__x86_64__)
 
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index 40b5baecde..0000b2b9b6 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -97,15 +97,6 @@ typedef uint64_t x86_pgentry_t;
 
 #define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)
 
-
-/* XXX SMH: following skanky macros rely on variable p2m_size being set */
-/* XXX TJD: also, "guest_width" should be the guest's sizeof(unsigned long) */
-
-struct domain_info_context {
-    unsigned int guest_width;
-    unsigned long p2m_size;
-};
-
 static inline xen_pfn_t xc_pfn_to_mfn(xen_pfn_t pfn, xen_pfn_t *p2m,
                                       unsigned gwidth)
 {
@@ -121,19 +112,6 @@ static inline xen_pfn_t xc_pfn_to_mfn(xen_pfn_t pfn, xen_pfn_t *p2m,
     }
 }
 
-/* Number of xen_pfn_t in a page */
-#define FPP             (PAGE_SIZE/(dinfo->guest_width))
-
-/* Number of entries in the pfn_to_mfn_frame_list_list */
-#define P2M_FLL_ENTRIES (((dinfo->p2m_size)+(FPP*FPP)-1)/(FPP*FPP))
-
-/* Number of entries in the pfn_to_mfn_frame_list */
-#define P2M_FL_ENTRIES  (((dinfo->p2m_size)+FPP-1)/FPP)
-
-/* Size in bytes of the pfn_to_mfn_frame_list     */
-#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (dinfo->guest_width))
-#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) *                           \
-                           max_t(size_t, sizeof(xen_pfn_t), dinfo->guest_width))
 
 /* Masks for PTE<->PFN conversions */
 #define MADDR_BITS_X86  ((dinfo->guest_width == 8) ? 52 : 44)
diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index b904296997..88120eb54b 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -109,15 +109,6 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
 #define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(xen_pfn_t)), M2P_SHIFT)
 #define M2P_CHUNKS(_m)  (M2P_SIZE((_m)) >> M2P_SHIFT)
 
-#define GET_FIELD(_p, _f, _w) (((_w) == 8) ? ((_p)->x64._f) : ((_p)->x32._f))
-
-#define SET_FIELD(_p, _f, _v, _w) do {          \
-    if ((_w) == 8)                              \
-        (_p)->x64._f = (_v);                    \
-    else                                        \
-        (_p)->x32._f = (_v);                    \
-} while (0)
-
 #define UNFOLD_CR3(_c)                                                  \
   ((uint64_t)((dinfo->guest_width == 8)                                 \
               ? ((_c) >> 12)                                            \
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:36 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJML6-0006Lv-Lc; Fri, 18 Sep 2020 19:46:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJML6-0006Lo-3F
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:36 +0000
X-Inumbo-ID: 589bbab6-2198-45f6-9542-f60d2ee92c5f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 589bbab6-2198-45f6-9542-f60d2ee92c5f;
 Fri, 18 Sep 2020 19:46:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Pt2ScjCLT8oY0pz0GGEo9sUih7piUiGxbRNzOkPS1L0=; b=NApJLr/ddlI77iBVcPEjiXGYNR
 X9Su6uZwjESow+cLVcGgFpRB5aTgYkMibrsWN8rOkSiHE/5U0mrhmpvcbpsiKZJjqQ7BHkssQoGDm
 e6yyNt7KEy5a5j87jfZys5Qj5712+9naLnq/GkKvd17wW3X9bNcFvv/PjpduekAUOxq0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJML5-00077O-5v
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJML5-0004P5-3u
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/xcutils: use official headers in readnotes
Message-Id: <E1kJML5-0004P5-3u@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 725588cfd11443689a40db4bf31e71b974ff5555
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:32 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xcutils: use official headers in readnotes
    
    readnotes.c is including xg_private.h. Now that the xenctrl headers
    are structured better this is no longer needed.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xcutils/Makefile    | 3 +--
 tools/xcutils/readnotes.c | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/xcutils/Makefile b/tools/xcutils/Makefile
index 2811893980..82d42624c8 100644
--- a/tools/xcutils/Makefile
+++ b/tools/xcutils/Makefile
@@ -15,8 +15,7 @@ PROGRAMS = readnotes lsevtchn
 
 CFLAGS += -Werror
 
-# incorrectly uses libxc internals
-CFLAGS_readnotes.o  := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
+CFLAGS_readnotes.o  := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
 CFLAGS_lsevtchn.o   := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl)
 
 .PHONY: all
diff --git a/tools/xcutils/readnotes.c b/tools/xcutils/readnotes.c
index a6b7358e70..ff684c7dcb 100644
--- a/tools/xcutils/readnotes.c
+++ b/tools/xcutils/readnotes.c
@@ -11,8 +11,9 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-#include <xg_private.h>
-#include <xenctrl_dom.h> /* gunzip bits */
+#include <xen/xen.h>
+#include <xenctrl.h>
+#include <xenguest.h>
 
 #include <xen/libelf/libelf.h>
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:46:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:46:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMLH-0006N7-NK; Fri, 18 Sep 2020 19:46:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMLG-0006My-Lf
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:46 +0000
X-Inumbo-ID: f86c4462-be84-4509-afa8-b7fedd559cd0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f86c4462-be84-4509-afa8-b7fedd559cd0;
 Fri, 18 Sep 2020 19:46:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=BcIwCOldHTgauYZVfzqj/UqTX++U0hWHcx/XOa0Tq0I=; b=RYCsEIfSdlMsA/8VqHUNMTqFO3
 AH98gpvde6ApdQTUMqyyCY9eUanJBzxUqRgnQif/UtYijXoKkSZFsCLPg715qkfQWMuIMo7ckSSur
 M+M6zLLbHhwjcmFzqk8YT/BGhFjUY+RNrfeUt2f24iVzfvJ+skI/CfF83FlRurlUkQhg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLF-00077b-93
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLF-0004Pb-8K
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/xenpaging: remove libxc internals
Message-Id: <E1kJMLF-0004Pb-8K@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 30f5e8aba1e3e24fc9c4220bbacee37ca7c87ba6
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:33 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xenpaging: remove libxc internals
    
    xenpaging is using libxc internals. Fix that.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xenpaging/Makefile         |  3 +-
 tools/xenpaging/file_ops.c       |  8 ++---
 tools/xenpaging/pagein.c         |  2 +-
 tools/xenpaging/policy_default.c |  2 +-
 tools/xenpaging/xenpaging.c      | 32 +++++++++---------
 tools/xenpaging/xenpaging.h      | 70 +++++++++++++++++++++++++++++++++++++++-
 6 files changed, 92 insertions(+), 25 deletions(-)

diff --git a/tools/xenpaging/Makefile b/tools/xenpaging/Makefile
index 968678c4e8..04743b335c 100644
--- a/tools/xenpaging/Makefile
+++ b/tools/xenpaging/Makefile
@@ -1,8 +1,7 @@
 XEN_ROOT=$(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-# xenpaging.c and file_ops.c incorrectly use libxc internals
-CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
+CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) $(CFLAGS_libxencall)
 LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
diff --git a/tools/xenpaging/file_ops.c b/tools/xenpaging/file_ops.c
index 8210f426df..301fb3427c 100644
--- a/tools/xenpaging/file_ops.c
+++ b/tools/xenpaging/file_ops.c
@@ -20,7 +20,7 @@
 
 
 #include <unistd.h>
-#include <xc_private.h>
+#include <xenctrl.h>
 
 static int file_op(int fd, void *page, int i,
                    ssize_t (*fn)(int, void *, size_t))
@@ -29,13 +29,13 @@ static int file_op(int fd, void *page, int i,
     int total = 0;
     int bytes;
 
-    offset = lseek(fd, offset << PAGE_SHIFT, SEEK_SET);
+    offset = lseek(fd, offset << XC_PAGE_SHIFT, SEEK_SET);
     if ( offset == (off_t)-1 )
         return -1;
 
-    while ( total < PAGE_SIZE )
+    while ( total < XC_PAGE_SIZE )
     {
-        bytes = fn(fd, page + total, PAGE_SIZE - total);
+        bytes = fn(fd, page + total, XC_PAGE_SIZE - total);
         if ( bytes <= 0 )
             return -1;
 
diff --git a/tools/xenpaging/pagein.c b/tools/xenpaging/pagein.c
index 2a298b436c..1c8a7d983d 100644
--- a/tools/xenpaging/pagein.c
+++ b/tools/xenpaging/pagein.c
@@ -43,7 +43,7 @@ static void *page_in(void *arg)
         /* Ignore errors */
         page = xc_map_foreign_pages(pia->xch, pia->dom, PROT_READ, gfns, num);
         if (page)
-            munmap(page, PAGE_SIZE * num);
+            munmap(page, XC_PAGE_SIZE * num);
     }
     page_in_possible = 0;
     pthread_exit(NULL);
diff --git a/tools/xenpaging/policy_default.c b/tools/xenpaging/policy_default.c
index 3324835957..979d251230 100644
--- a/tools/xenpaging/policy_default.c
+++ b/tools/xenpaging/policy_default.c
@@ -18,8 +18,8 @@
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <errno.h>
 
-#include "xc_bitops.h"
 #include "policy.h"
 
 
diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c
index d0571cabac..33098046c2 100644
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -30,7 +30,6 @@
 #include <xenstore.h>
 #include <getopt.h>
 
-#include "xc_bitops.h"
 #include "file_ops.h"
 #include "policy.h"
 #include "xenpaging.h"
@@ -183,12 +182,12 @@ static void *init_page(void)
     void *buffer;
 
     /* Allocated page memory */
-    errno = posix_memalign(&buffer, PAGE_SIZE, PAGE_SIZE);
+    errno = posix_memalign(&buffer, XC_PAGE_SIZE, XC_PAGE_SIZE);
     if ( errno != 0 )
         return NULL;
 
     /* Lock buffer in memory so it can't be paged out */
-    if ( mlock(buffer, PAGE_SIZE) < 0 )
+    if ( mlock(buffer, XC_PAGE_SIZE) < 0 )
     {
         free(buffer);
         buffer = NULL;
@@ -277,7 +276,6 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     struct xenpaging *paging;
     xc_domaininfo_t domain_info;
     xc_interface *xch = NULL;
-    xentoollog_logger *dbg = NULL;
     char *p;
     int rc;
     unsigned long ring_pfn, mmap_pfn;
@@ -291,12 +289,11 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     if ( xenpaging_getopts(paging, argc, argv) )
         goto err;
 
-    /* Enable debug output */
-    if ( paging->debug )
-        dbg = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0);
+    paging->logger = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr,
+                         paging->debug ? XTL_DEBUG : XTL_PROGRESS, 0);
 
     /* Open connection to xen */
-    paging->xc_handle = xch = xc_interface_open(dbg, NULL, 0);
+    paging->xc_handle = xch = xc_interface_open(paging->logger, NULL, 0);
     if ( !xch )
         goto err;
 
@@ -416,7 +413,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     SHARED_RING_INIT((vm_event_sring_t *)paging->vm_event.ring_page);
     BACK_RING_INIT(&paging->vm_event.back_ring,
                    (vm_event_sring_t *)paging->vm_event.ring_page,
-                   PAGE_SIZE);
+                   XC_PAGE_SIZE);
 
     /* Now that the ring is set, remove it from the guest's physmap */
     if ( xc_domain_decrease_reservation_exact(xch, 
@@ -490,15 +487,17 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
             xs_close(paging->xs_handle);
         if ( xch )
             xc_interface_close(xch);
+        if ( paging->logger )
+            xtl_logger_destroy(paging->logger);
         if ( paging->paging_buffer )
         {
-            munlock(paging->paging_buffer, PAGE_SIZE);
+            munlock(paging->paging_buffer, XC_PAGE_SIZE);
             free(paging->paging_buffer);
         }
 
         if ( paging->vm_event.ring_page )
         {
-            munmap(paging->vm_event.ring_page, PAGE_SIZE);
+            munmap(paging->vm_event.ring_page, XC_PAGE_SIZE);
         }
 
         free(dom_path);
@@ -523,7 +522,7 @@ static void xenpaging_teardown(struct xenpaging *paging)
 
     paging->xc_handle = NULL;
     /* Tear down domain paging in Xen */
-    munmap(paging->vm_event.ring_page, PAGE_SIZE);
+    munmap(paging->vm_event.ring_page, XC_PAGE_SIZE);
     rc = xc_mem_paging_disable(xch, paging->vm_event.domain_id);
     if ( rc != 0 )
     {
@@ -551,6 +550,8 @@ static void xenpaging_teardown(struct xenpaging *paging)
 
     /* Close connection to Xen */
     xc_interface_close(xch);
+
+    xtl_logger_destroy(paging->logger);
 }
 
 static void get_request(struct vm_event *vm_event, vm_event_request_t *req)
@@ -598,8 +599,7 @@ static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int
     void *page;
     xen_pfn_t victim = gfn;
     int ret;
-
-    DECLARE_DOMCTL;
+    struct xen_domctl domctl;
 
     /* Nominate page */
     ret = xc_mem_paging_nominate(xch, paging->vm_event.domain_id, gfn);
@@ -627,13 +627,13 @@ static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn, int
     if ( ret < 0 )
     {
         PERROR("Error copying page %lx", gfn);
-        munmap(page, PAGE_SIZE);
+        munmap(page, XC_PAGE_SIZE);
         ret = -1;
         goto out;
     }
 
     /* Release page */
-    munmap(page, PAGE_SIZE);
+    munmap(page, XC_PAGE_SIZE);
 
     /* Tell Xen to evict page */
     ret = xc_mem_paging_evict(xch, paging->vm_event.domain_id, gfn);
diff --git a/tools/xenpaging/xenpaging.h b/tools/xenpaging/xenpaging.h
index d6c8ee5221..e0fc7b31b8 100644
--- a/tools/xenpaging/xenpaging.h
+++ b/tools/xenpaging/xenpaging.h
@@ -23,11 +23,17 @@
 #ifndef __XEN_PAGING2_H__
 #define __XEN_PAGING2_H__
 
+#include <malloc.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
 
 #include <xenevtchn.h>
 #define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
-#include <xc_private.h>
+// #include <xc_private.h>
 #include <xen/event_channel.h>
 #include <xen/vm_event.h>
 
@@ -44,6 +50,7 @@ struct vm_event {
 
 struct xenpaging {
     xc_interface *xc_handle;
+    xentoollog_logger *logger;
     struct xs_handle *xs_handle;
 
     unsigned long *bitmap;
@@ -67,9 +74,70 @@ struct xenpaging {
     unsigned long pagein_queue[XENPAGING_PAGEIN_QUEUE_SIZE];
 };
 
+#define DPRINTF(msg, args...) xtl_log(paging->logger, XTL_DETAIL, 0,      \
+                                      "paging", msg, ## args)
+#define ERROR(msg, args...)   xtl_log(paging->logger, XTL_ERROR, -1,      \
+                                      "paging", msg, ## args)
+#define PERROR(msg, args...)  xtl_log(paging->logger, XTL_ERROR, -1,      \
+                                      "paging", msg "(%d = %s)", ## args, \
+                                      errno, strerror(errno))
+
 extern void create_page_in_thread(struct xenpaging *paging);
 extern void page_in_trigger(void);
 
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
+#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)
+
+#define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8]
+#define BITMAP_SHIFT(_nr) ((_nr) % 8)
+
+static inline int bitmap_size(int nr_bits)
+{
+    return (nr_bits + 7) / 8;
+}
+
+static inline void *bitmap_alloc(int nr_bits)
+{
+    return calloc(1, bitmap_size(nr_bits));
+}
+
+static inline void bitmap_clear(void *addr, int nr_bits)
+{
+    memset(addr, 0, bitmap_size(nr_bits));
+}
+
+static inline int test_bit(int nr, const void *_addr)
+{
+    const char *addr = _addr;
+    return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
+}
+
+static inline void clear_bit(int nr, void *_addr)
+{
+    char *addr = _addr;
+    BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr));
+}
+
+static inline void set_bit(int nr, void *_addr)
+{
+    char *addr = _addr;
+    BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr));
+}
+
+static inline int test_and_clear_bit(int nr, void *addr)
+{
+    int oldbit = test_bit(nr, addr);
+    clear_bit(nr, addr);
+    return oldbit;
+}
+
+static inline int test_and_set_bit(int nr, void *addr)
+{
+    int oldbit = test_bit(nr, addr);
+    set_bit(nr, addr);
+    return oldbit;
+}
+
 #endif // __XEN_PAGING_H__
 
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMLW-0006Ol-Qn; Fri, 18 Sep 2020 19:47:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMLW-0006Of-35
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:02 +0000
X-Inumbo-ID: 062353dc-f34d-411e-8826-6d39a9786d58
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 062353dc-f34d-411e-8826-6d39a9786d58;
 Fri, 18 Sep 2020 19:46:55 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IQ6B7YDmUqyTx6F2xD4Pk+QBM/34UiypNDmBUKNdz6g=; b=myYyaSKCEVGP76Kar2kJlYHduF
 UsLIS5WjhtynG5OsIg1OVt9/rWaFLC6KctT4J4638krNY4o5vwkAC8HCM8m3+us2U4+capnSTeBXI
 RBxXyvaCbkKIydUDaYtAIB/NGXBJoLpL5gyBbFsFMb7CBgSK/Mk+mgOrb/R8iJQH2E+M=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLP-00077i-Dy
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:55 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLP-0004Q9-D7
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:46:55 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: move libxenctrl below tools/libs
Message-Id: <E1kJMLP-0004Q9-D7@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:46:55 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit af6c78d9dc68366d0d9a1d41de26f3765dfef5f0
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:34 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: move libxenctrl below tools/libs
    
    Today tools/libxc needs to be built after tools/libs as libxenctrl is
    depending on some libraries in tools/libs. This in turn blocks moving
    other libraries depending on libxenctrl below tools/libs.
    
    So carve out libxenctrl from tools/libxc and move it into
    tools/libs/ctrl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> (stubdom parts)
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> (python parts)
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                               |    8 +
 MAINTAINERS                              |    2 +-
 stubdom/Makefile                         |    9 +-
 stubdom/grub/Makefile                    |    4 +-
 stubdom/mini-os.mk                       |    2 +-
 tools/Rules.mk                           |    8 +-
 tools/libs/Makefile                      |    1 +
 tools/libs/ctrl/Makefile                 |   72 +
 tools/libs/ctrl/include/xenctrl.h        | 2668 ++++++++++++++++++++++++++++++
 tools/libs/ctrl/include/xenctrl_compat.h |  183 ++
 tools/libs/ctrl/include/xenctrl_dom.h    |  455 +++++
 tools/libs/ctrl/xc_altp2m.c              |  436 +++++
 tools/libs/ctrl/xc_arinc653.c            |   87 +
 tools/libs/ctrl/xc_bitops.h              |   79 +
 tools/libs/ctrl/xc_core.c                | 1008 +++++++++++
 tools/libs/ctrl/xc_core.h                |  176 ++
 tools/libs/ctrl/xc_core_arm.c            |  122 ++
 tools/libs/ctrl/xc_core_arm.h            |   59 +
 tools/libs/ctrl/xc_core_x86.c            |  223 +++
 tools/libs/ctrl/xc_core_x86.h            |   60 +
 tools/libs/ctrl/xc_cpu_hotplug.c         |   74 +
 tools/libs/ctrl/xc_cpupool.c             |  219 +++
 tools/libs/ctrl/xc_csched.c              |  109 ++
 tools/libs/ctrl/xc_csched2.c             |  109 ++
 tools/libs/ctrl/xc_devicemodel_compat.c  |  147 ++
 tools/libs/ctrl/xc_domain.c              | 2205 ++++++++++++++++++++++++
 tools/libs/ctrl/xc_evtchn.c              |   85 +
 tools/libs/ctrl/xc_evtchn_compat.c       |   75 +
 tools/libs/ctrl/xc_flask.c               |  450 +++++
 tools/libs/ctrl/xc_foreign_memory.c      |   98 ++
 tools/libs/ctrl/xc_freebsd.c             |   71 +
 tools/libs/ctrl/xc_gnttab.c              |  161 ++
 tools/libs/ctrl/xc_gnttab_compat.c       |  111 ++
 tools/libs/ctrl/xc_hcall_buf.c           |  190 +++
 tools/libs/ctrl/xc_kexec.c               |  152 ++
 tools/libs/ctrl/xc_linux.c               |   77 +
 tools/libs/ctrl/xc_mem_access.c          |  110 ++
 tools/libs/ctrl/xc_mem_paging.c          |  130 ++
 tools/libs/ctrl/xc_memshr.c              |  289 ++++
 tools/libs/ctrl/xc_minios.c              |   67 +
 tools/libs/ctrl/xc_misc.c                |  999 +++++++++++
 tools/libs/ctrl/xc_monitor.c             |  257 +++
 tools/libs/ctrl/xc_msr_x86.h             |   37 +
 tools/libs/ctrl/xc_netbsd.c              |   74 +
 tools/libs/ctrl/xc_pagetab.c             |  113 ++
 tools/libs/ctrl/xc_physdev.c             |  113 ++
 tools/libs/ctrl/xc_pm.c                  |  455 +++++
 tools/libs/ctrl/xc_private.c             |  781 +++++++++
 tools/libs/ctrl/xc_private.h             |  479 ++++++
 tools/libs/ctrl/xc_psr.c                 |  395 +++++
 tools/libs/ctrl/xc_resource.c            |  151 ++
 tools/libs/ctrl/xc_resume.c              |  288 ++++
 tools/libs/ctrl/xc_rt.c                  |  132 ++
 tools/libs/ctrl/xc_solaris.c             |   43 +
 tools/libs/ctrl/xc_tbuf.c                |  172 ++
 tools/libs/ctrl/xc_vm_event.c            |  183 ++
 tools/libs/uselibs.mk                    |    2 +
 tools/libxc/Makefile                     |  109 +-
 tools/libxc/include/xenctrl.h            | 2668 ------------------------------
 tools/libxc/include/xenctrl_compat.h     |  183 --
 tools/libxc/include/xenctrl_dom.h        |  455 -----
 tools/libxc/xc_altp2m.c                  |  436 -----
 tools/libxc/xc_arinc653.c                |   87 -
 tools/libxc/xc_bitops.h                  |   79 -
 tools/libxc/xc_core.c                    | 1008 -----------
 tools/libxc/xc_core.h                    |  176 --
 tools/libxc/xc_core_arm.c                |  122 --
 tools/libxc/xc_core_arm.h                |   59 -
 tools/libxc/xc_core_x86.c                |  223 ---
 tools/libxc/xc_core_x86.h                |   60 -
 tools/libxc/xc_cpu_hotplug.c             |   74 -
 tools/libxc/xc_cpupool.c                 |  219 ---
 tools/libxc/xc_csched.c                  |  109 --
 tools/libxc/xc_csched2.c                 |  109 --
 tools/libxc/xc_devicemodel_compat.c      |  147 --
 tools/libxc/xc_domain.c                  | 2205 ------------------------
 tools/libxc/xc_evtchn.c                  |   85 -
 tools/libxc/xc_evtchn_compat.c           |   75 -
 tools/libxc/xc_flask.c                   |  450 -----
 tools/libxc/xc_foreign_memory.c          |   98 --
 tools/libxc/xc_freebsd.c                 |   71 -
 tools/libxc/xc_gnttab.c                  |  161 --
 tools/libxc/xc_gnttab_compat.c           |  111 --
 tools/libxc/xc_hcall_buf.c               |  190 ---
 tools/libxc/xc_kexec.c                   |  152 --
 tools/libxc/xc_linux.c                   |   77 -
 tools/libxc/xc_mem_access.c              |  110 --
 tools/libxc/xc_mem_paging.c              |  130 --
 tools/libxc/xc_memshr.c                  |  289 ----
 tools/libxc/xc_minios.c                  |   67 -
 tools/libxc/xc_misc.c                    |  999 -----------
 tools/libxc/xc_monitor.c                 |  257 ---
 tools/libxc/xc_msr_x86.h                 |   37 -
 tools/libxc/xc_netbsd.c                  |   74 -
 tools/libxc/xc_pagetab.c                 |  113 --
 tools/libxc/xc_physdev.c                 |  113 --
 tools/libxc/xc_pm.c                      |  455 -----
 tools/libxc/xc_private.c                 |  781 ---------
 tools/libxc/xc_private.h                 |  479 ------
 tools/libxc/xc_psr.c                     |  395 -----
 tools/libxc/xc_resource.c                |  151 --
 tools/libxc/xc_resume.c                  |  288 ----
 tools/libxc/xc_rt.c                      |  132 --
 tools/libxc/xc_solaris.c                 |   43 -
 tools/libxc/xc_tbuf.c                    |  172 --
 tools/libxc/xc_vm_event.c                |  183 --
 tools/ocaml/xenstored/Makefile           |    2 +-
 tools/python/Makefile                    |    2 +-
 tools/python/setup.py                    |    8 +-
 109 files changed, 15268 insertions(+), 15275 deletions(-)

diff --git a/.gitignore b/.gitignore
index 823f4743dc..d22b031ed2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,9 @@ tools/libs/hypfs/headers.chk
 tools/libs/hypfs/xenhypfs.pc
 tools/libs/call/headers.chk
 tools/libs/call/xencall.pc
+tools/libs/ctrl/_*.[ch]
+tools/libs/ctrl/libxenctrl.map
+tools/libs/ctrl/xencontrol.pc
 tools/libs/foreignmemory/headers.chk
 tools/libs/foreignmemory/xenforeignmemory.pc
 tools/libs/devicemodel/headers.chk
@@ -195,6 +198,11 @@ tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
 tools/libvchan/xenvchan.pc
 tools/libxc/*.pc
+tools/libxc/xc_bitops.h
+tools/libxc/xc_core.h
+tools/libxc/xc_core_arm.h
+tools/libxc/xc_core_x86.h
+tools/libxc/xc_private.h
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
diff --git a/MAINTAINERS b/MAINTAINERS
index ffe2310294..26c5382075 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -226,7 +226,7 @@ M:	Stewart Hildebrand <stewart.hildebrand@dornerworks.com>
 S:	Supported
 L:	xen-devel@dornerworks.com
 F:	xen/common/sched/arinc653.c
-F:	tools/libxc/xc_arinc653.c
+F:	tools/libs/ctrl/xc_arinc653.c
 
 ARM (W/ VIRTUALISATION EXTENSIONS) ARCHITECTURE
 M:	Stefano Stabellini <sstabellini@kernel.org>
diff --git a/stubdom/Makefile b/stubdom/Makefile
index f000f56e68..6c481285ec 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -331,7 +331,7 @@ endif
 # libraries under tools/libs
 #######
 
-STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel
+STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl
 
 #######
 # common handling
@@ -396,12 +396,11 @@ $(TARGETS_MINIOS): mini-os-%:
 #######
 
 .PHONY: libxc
-libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel cross-zlib
+libxc: libxc-$(XEN_TARGET_ARCH)/libxenguest.a
+libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxenevtchn libxenctrl cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenguest.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
- libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
-
 #######
 # ioemu
 #######
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
index 26dff45a8f..d33fa2f71e 100644
--- a/stubdom/grub/Makefile
+++ b/stubdom/grub/Makefile
@@ -6,7 +6,9 @@ vpath %.c ../grub-upstream
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include -I$(XEN_ROOT)/tools/include -I.
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
 DEF_CPPFLAGS += -I../grub-upstream/netboot
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index 32528bb91f..b1387df3f8 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -13,5 +13,5 @@ GNTTAB_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab
 CALL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
 FOREIGNMEMORY_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
 DEVICEMODEL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
-CTRL_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+CTRL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/ctrl
 GUEST_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 13432560ff..35940cb338 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -15,7 +15,6 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-XEN_libxenctrl     = $(XEN_ROOT)/tools/libxc
 XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
@@ -105,13 +104,10 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
-CFLAGS_libxenctrl = -I$(XEN_libxenctrl)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) $(SHLIB_libxendevicemodel)
-LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_libxenctrl)/libxenctrl$(libextension)
-SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_libxenctrl)
+CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
 
 CFLAGS_libxenguest = -I$(XEN_libxenguest)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
-SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
+SHDEPS_libxenguest = $(SHLIB_libxenevtchn) $(SHLIB_libxenctrl)
 LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libextension)
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
 
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 69cdfb5975..7648ea0e4c 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -9,6 +9,7 @@ SUBDIRS-y += gnttab
 SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
 SUBDIRS-y += devicemodel
+SUBDIRS-y += ctrl
 SUBDIRS-y += hypfs
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile
new file mode 100644
index 0000000000..ec93fb5b73
--- /dev/null
+++ b/tools/libs/ctrl/Makefile
@@ -0,0 +1,72 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SRCS-y       += xc_altp2m.c
+SRCS-y       += xc_core.c
+SRCS-$(CONFIG_X86) += xc_core_x86.c
+SRCS-$(CONFIG_ARM) += xc_core_arm.c
+SRCS-y       += xc_cpupool.c
+SRCS-y       += xc_domain.c
+SRCS-y       += xc_evtchn.c
+SRCS-y       += xc_gnttab.c
+SRCS-y       += xc_misc.c
+SRCS-y       += xc_flask.c
+SRCS-y       += xc_physdev.c
+SRCS-y       += xc_private.c
+SRCS-y       += xc_csched.c
+SRCS-y       += xc_csched2.c
+SRCS-y       += xc_arinc653.c
+SRCS-y       += xc_rt.c
+SRCS-y       += xc_tbuf.c
+SRCS-y       += xc_pm.c
+SRCS-y       += xc_cpu_hotplug.c
+SRCS-y       += xc_resume.c
+SRCS-y       += xc_vm_event.c
+SRCS-y       += xc_monitor.c
+SRCS-y       += xc_mem_paging.c
+SRCS-y       += xc_mem_access.c
+SRCS-y       += xc_memshr.c
+SRCS-y       += xc_hcall_buf.c
+SRCS-y       += xc_foreign_memory.c
+SRCS-y       += xc_kexec.c
+SRCS-y       += xc_resource.c
+SRCS-$(CONFIG_X86) += xc_psr.c
+SRCS-$(CONFIG_X86) += xc_pagetab.c
+SRCS-$(CONFIG_Linux) += xc_linux.c
+SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c
+SRCS-$(CONFIG_SunOS) += xc_solaris.c
+SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
+SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
+SRCS-$(CONFIG_MiniOS) += xc_minios.c
+SRCS-y       += xc_evtchn_compat.c
+SRCS-y       += xc_gnttab_compat.c
+SRCS-y       += xc_devicemodel_compat.c
+
+CFLAGS   += -D__XEN_TOOLS__
+CFLAGS	+= $(PTHREAD_CFLAGS)
+CFLAGS += -include $(XEN_ROOT)/tools/config.h
+
+# Needed for posix_fadvise64() in xc_linux.c
+CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
+
+LIBHEADER := xenctrl.h xenctrl_compat.h xenctrl_dom.h
+PKG_CONFIG := xencontrol.pc
+PKG_CONFIG_NAME := Xencontrol
+
+NO_HEADERS_CHK := y
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
+
+$(LIB_OBJS) $(PIC_OBJS): _paths.h
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenctrl)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenctrl.map
diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
new file mode 100644
index 0000000000..4c89b7294c
--- /dev/null
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -0,0 +1,2668 @@
+/******************************************************************************
+ * xenctrl.h
+ *
+ * A library for low-level access to the Xen control interfaces.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XENCTRL_H
+#define XENCTRL_H
+
+/* Tell the Xen public headers we are a user-space tools build. */
+#ifndef __XEN_TOOLS__
+#define __XEN_TOOLS__ 1
+#endif
+
+#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <xen/xen.h>
+#include <xen/domctl.h>
+#include <xen/physdev.h>
+#include <xen/sysctl.h>
+#include <xen/version.h>
+#include <xen/event_channel.h>
+#include <xen/sched.h>
+#include <xen/memory.h>
+#include <xen/grant_table.h>
+#include <xen/hvm/dm_op.h>
+#include <xen/hvm/params.h>
+#include <xen/xsm/flask_op.h>
+#include <xen/kexec.h>
+#include <xen/platform.h>
+
+#include "xentoollog.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/arch-x86/xen-mca.h>
+#endif
+
+#define XC_PAGE_SHIFT           12
+#define XC_PAGE_SIZE            (1UL << XC_PAGE_SHIFT)
+#define XC_PAGE_MASK            (~(XC_PAGE_SIZE-1))
+
+#define INVALID_MFN  (~0UL)
+
+/*
+ *  DEFINITIONS FOR CPU BARRIERS
+ */
+
+#define xen_barrier() asm volatile ( "" : : : "memory")
+
+#if defined(__i386__)
+#define xen_mb()  asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
+#define xen_rmb() xen_barrier()
+#define xen_wmb() xen_barrier()
+#elif defined(__x86_64__)
+#define xen_mb()  asm volatile ( "mfence" : : : "memory")
+#define xen_rmb() xen_barrier()
+#define xen_wmb() xen_barrier()
+#elif defined(__arm__)
+#define xen_mb()   asm volatile ("dmb" : : : "memory")
+#define xen_rmb()  asm volatile ("dmb" : : : "memory")
+#define xen_wmb()  asm volatile ("dmb" : : : "memory")
+#elif defined(__aarch64__)
+#define xen_mb()   asm volatile ("dmb sy" : : : "memory")
+#define xen_rmb()  asm volatile ("dmb sy" : : : "memory")
+#define xen_wmb()  asm volatile ("dmb sy" : : : "memory")
+#else
+#error "Define barriers"
+#endif
+
+
+#define XENCTRL_HAS_XC_INTERFACE 1
+/* In Xen 4.0 and earlier, xc_interface_open and xc_evtchn_open would
+ * both return ints being the file descriptor.  In 4.1 and later, they
+ * return an xc_interface* and xc_evtchn*, respectively - ie, a
+ * pointer to an opaque struct.  This #define is provided in 4.1 and
+ * later, allowing out-of-tree callers to more easily distinguish
+ * between, and be compatible with, both versions.
+ */
+
+
+/*
+ *  GENERAL
+ *
+ * Unless otherwise specified, each function here returns zero or a
+ * non-null pointer on success; or in case of failure, sets errno and
+ * returns -1 or a null pointer.
+ *
+ * Unless otherwise specified, errors result in a call to the error
+ * handler function, which by default prints a message to the
+ * FILE* passed as the caller_data, which by default is stderr.
+ * (This is described below as "logging errors".)
+ *
+ * The error handler can safely trash errno, as libxc saves it across
+ * the callback.
+ */
+
+typedef struct xc_interface_core xc_interface;
+
+enum xc_error_code {
+  XC_ERROR_NONE = 0,
+  XC_INTERNAL_ERROR = 1,
+  XC_INVALID_KERNEL = 2,
+  XC_INVALID_PARAM = 3,
+  XC_OUT_OF_MEMORY = 4,
+  /* new codes need to be added to xc_error_level_to_desc too */
+};
+
+typedef enum xc_error_code xc_error_code;
+
+
+/*
+ *  INITIALIZATION FUNCTIONS
+ */
+
+/**
+ * This function opens a handle to the hypervisor interface.  This function can
+ * be called multiple times within a single process.  Multiple processes can
+ * have an open hypervisor interface at the same time.
+ *
+ * Note:
+ * After fork a child process must not use any opened xc interface
+ * handle inherited from their parent. They must open a new handle if
+ * they want to interact with xc.
+ *
+ * Each call to this function should have a corresponding call to
+ * xc_interface_close().
+ *
+ * This function can fail if the caller does not have superuser permission or
+ * if a Xen-enabled kernel is not currently running.
+ *
+ * @return a handle to the hypervisor interface
+ */
+xc_interface *xc_interface_open(xentoollog_logger *logger,
+                                xentoollog_logger *dombuild_logger,
+                                unsigned open_flags);
+  /* if logger==NULL, will log to stderr
+   * if dombuild_logger=NULL, will log to a file
+   */
+
+/*
+ * Note: if XC_OPENFLAG_NON_REENTRANT is passed then libxc must not be
+ * called reentrantly and the calling application is responsible for
+ * providing mutual exclusion surrounding all libxc calls itself.
+ *
+ * In particular xc_{get,clear}_last_error only remain valid for the
+ * duration of the critical section containing the call which failed.
+ */
+enum xc_open_flags {
+    XC_OPENFLAG_DUMMY =  1<<0, /* do not actually open a xenctrl interface */
+    XC_OPENFLAG_NON_REENTRANT = 1<<1, /* assume library is only every called from a single thread */
+};
+
+/**
+ * This function closes an open hypervisor interface.
+ *
+ * This function can fail if the handle does not represent an open interface or
+ * if there were problems closing the interface.  In the latter case
+ * the interface is still closed.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @return 0 on success, -1 otherwise.
+ */
+int xc_interface_close(xc_interface *xch);
+
+/**
+ * Return the handles which xch has opened and will use for
+ * hypercalls, foreign memory accesses and device model operations.
+ * These may be used with the corresponding libraries so long as the
+ * xch itself remains open.
+ */
+struct xencall_handle *xc_interface_xcall_handle(xc_interface *xch);
+struct xenforeignmemory_handle *xc_interface_fmem_handle(xc_interface *xch);
+struct xendevicemodel_handle *xc_interface_dmod_handle(xc_interface *xch);
+
+/*
+ * HYPERCALL SAFE MEMORY BUFFER
+ *
+ * Ensure that memory which is passed to a hypercall has been
+ * specially allocated in order to be safe to access from the
+ * hypervisor.
+ *
+ * Each user data pointer is shadowed by an xc_hypercall_buffer data
+ * structure. You should never define an xc_hypercall_buffer type
+ * directly, instead use the DECLARE_HYPERCALL_BUFFER* macros below.
+ *
+ * The strucuture should be considered opaque and all access should be
+ * via the macros and helper functions defined below.
+ *
+ * Once the buffer is declared the user is responsible for explicitly
+ * allocating and releasing the memory using
+ * xc_hypercall_buffer_alloc(_pages) and
+ * xc_hypercall_buffer_free(_pages).
+ *
+ * Once the buffer has been allocated the user can initialise the data
+ * via the normal pointer. The xc_hypercall_buffer structure is
+ * transparently referenced by the helper macros (such as
+ * xen_set_guest_handle) in order to check at compile time that the
+ * correct type of memory is being used.
+ */
+struct xc_hypercall_buffer {
+    /* Hypercall safe memory buffer. */
+    void *hbuf;
+
+    /*
+     * Reference to xc_hypercall_buffer passed as argument to the
+     * current function.
+     */
+    struct xc_hypercall_buffer *param_shadow;
+
+    /*
+     * Direction of copy for bounce buffering.
+     */
+    int dir;
+
+    /* Used iff dir != 0. */
+    void *ubuf;
+    size_t sz;
+};
+typedef struct xc_hypercall_buffer xc_hypercall_buffer_t;
+
+/*
+ * Construct the name of the hypercall buffer for a given variable.
+ * For internal use only
+ */
+#define XC__HYPERCALL_BUFFER_NAME(_name) xc__hypercall_buffer_##_name
+
+/*
+ * Returns the hypercall_buffer associated with a variable.
+ */
+#define HYPERCALL_BUFFER(_name)                                 \
+    ({  xc_hypercall_buffer_t _hcbuf_buf1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_buf2 = \
+                &XC__HYPERCALL_BUFFER_NAME(_name);              \
+        (void)(&_hcbuf_buf1 == _hcbuf_buf2);                    \
+        (_hcbuf_buf2)->param_shadow ?                           \
+                (_hcbuf_buf2)->param_shadow : (_hcbuf_buf2);    \
+     })
+
+#define HYPERCALL_BUFFER_INIT_NO_BOUNCE .dir = 0, .sz = 0, .ubuf = (void *)-1
+
+/*
+ * Defines a hypercall buffer and user pointer with _name of _type.
+ *
+ * The user accesses the data as normal via _name which will be
+ * transparently converted to the hypercall buffer as necessary.
+ */
+#define DECLARE_HYPERCALL_BUFFER(_type, _name)                 \
+    _type *(_name) = NULL;                                     \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = NULL,                                          \
+        .param_shadow = NULL,                                  \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Like DECLARE_HYPERCALL_BUFFER() but using an already allocated
+ * hypercall buffer, _hbuf.
+ *
+ * Useful when a hypercall buffer is passed to a function and access
+ * via the user pointer is required.
+ *
+ * See DECLARE_HYPERCALL_BUFFER_ARGUMENT() if the user pointer is not
+ * required.
+ */
+#define DECLARE_HYPERCALL_BUFFER_SHADOW(_type, _name, _hbuf)   \
+    _type *(_name) = (_hbuf)->hbuf;                            \
+    __attribute__((unused))                                    \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = (void *)-1,                                    \
+        .param_shadow = (_hbuf),                               \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Declare the necessary data structure to allow a hypercall buffer
+ * passed as an argument to a function to be used in the normal way.
+ */
+#define DECLARE_HYPERCALL_BUFFER_ARGUMENT(_name)               \
+    xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \
+        .hbuf = (void *)-1,                                    \
+        .param_shadow = (_name),                               \
+        HYPERCALL_BUFFER_INIT_NO_BOUNCE                        \
+    }
+
+/*
+ * Get the hypercall buffer data pointer in a form suitable for use
+ * directly as a hypercall argument.
+ */
+#define HYPERCALL_BUFFER_AS_ARG(_name)                          \
+    ({  xc_hypercall_buffer_t _hcbuf_arg1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_arg2 = \
+                HYPERCALL_BUFFER(_name);                        \
+        (void)(&_hcbuf_arg1 == _hcbuf_arg2);                    \
+        (unsigned long)(_hcbuf_arg2)->hbuf;                     \
+     })
+
+/*
+ * Set a xen_guest_handle in a type safe manner, ensuring that the
+ * data pointer has been correctly allocated.
+ */
+#define set_xen_guest_handle_impl(_hnd, _val, _byte_off)        \
+    do {                                                        \
+        xc_hypercall_buffer_t _hcbuf_hnd1;                      \
+        typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_hcbuf_hnd2 =  \
+                HYPERCALL_BUFFER(_val);                         \
+        (void) (&_hcbuf_hnd1 == _hcbuf_hnd2);                   \
+        set_xen_guest_handle_raw(_hnd,                          \
+                (_hcbuf_hnd2)->hbuf + (_byte_off));             \
+    } while (0)
+
+#undef set_xen_guest_handle
+#define set_xen_guest_handle(_hnd, _val)                        \
+    set_xen_guest_handle_impl(_hnd, _val, 0)
+
+#define set_xen_guest_handle_offset(_hnd, _val, _off)           \
+    set_xen_guest_handle_impl(_hnd, _val,                       \
+            ((sizeof(*_val)*(_off))))
+
+/* Use with set_xen_guest_handle in place of NULL */
+extern xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(HYPERCALL_BUFFER_NULL);
+
+/*
+ * Allocate and free hypercall buffers with byte granularity.
+ */
+void *xc__hypercall_buffer_alloc(xc_interface *xch, xc_hypercall_buffer_t *b, size_t size);
+#define xc_hypercall_buffer_alloc(_xch, _name, _size) xc__hypercall_buffer_alloc(_xch, HYPERCALL_BUFFER(_name), _size)
+void xc__hypercall_buffer_free(xc_interface *xch, xc_hypercall_buffer_t *b);
+#define xc_hypercall_buffer_free(_xch, _name) xc__hypercall_buffer_free(_xch, HYPERCALL_BUFFER(_name))
+
+/*
+ * Allocate and free hypercall buffers with page alignment.
+ */
+void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages);
+#define xc_hypercall_buffer_alloc_pages(_xch, _name, _nr) xc__hypercall_buffer_alloc_pages(_xch, HYPERCALL_BUFFER(_name), _nr)
+void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages);
+#define xc_hypercall_buffer_free_pages(_xch, _name, _nr)                    \
+    do {                                                                    \
+        if ( _name )                                                        \
+            xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name),  \
+                                            _nr);                           \
+    } while (0)
+
+/*
+ * Array of hypercall buffers.
+ *
+ * Create an array with xc_hypercall_buffer_array_create() and
+ * populate it by declaring one hypercall buffer in a loop and
+ * allocating the buffer with xc_hypercall_buffer_array_alloc().
+ *
+ * To access a previously allocated buffers, declare a new hypercall
+ * buffer and call xc_hypercall_buffer_array_get().
+ *
+ * Destroy the array with xc_hypercall_buffer_array_destroy() to free
+ * the array and all its allocated hypercall buffers.
+ */
+struct xc_hypercall_buffer_array;
+typedef struct xc_hypercall_buffer_array xc_hypercall_buffer_array_t;
+
+xc_hypercall_buffer_array_t *xc_hypercall_buffer_array_create(xc_interface *xch, unsigned n);
+void *xc__hypercall_buffer_array_alloc(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                       unsigned index, xc_hypercall_buffer_t *hbuf, size_t size);
+#define xc_hypercall_buffer_array_alloc(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_alloc(_xch, _array, _index, HYPERCALL_BUFFER(_name), _size)
+void *xc__hypercall_buffer_array_get(xc_interface *xch, xc_hypercall_buffer_array_t *array,
+                                     unsigned index, xc_hypercall_buffer_t *hbuf);
+#define xc_hypercall_buffer_array_get(_xch, _array, _index, _name, _size) \
+    xc__hypercall_buffer_array_get(_xch, _array, _index, HYPERCALL_BUFFER(_name))
+void xc_hypercall_buffer_array_destroy(xc_interface *xc, xc_hypercall_buffer_array_t *array);
+
+/*
+ * CPUMAP handling
+ */
+typedef uint8_t *xc_cpumap_t;
+
+/* return maximum number of cpus the hypervisor supports */
+int xc_get_max_cpus(xc_interface *xch);
+
+/* return the number of online cpus */
+int xc_get_online_cpus(xc_interface *xch);
+
+/* return array size for cpumap */
+int xc_get_cpumap_size(xc_interface *xch);
+
+/* allocate a cpumap */
+xc_cpumap_t xc_cpumap_alloc(xc_interface *xch);
+
+/* clear an CPU from the cpumap. */
+void xc_cpumap_clearcpu(int cpu, xc_cpumap_t map);
+
+/* set an CPU in the cpumap. */
+void xc_cpumap_setcpu(int cpu, xc_cpumap_t map);
+
+/* Test whether the CPU in cpumap is set. */
+int xc_cpumap_testcpu(int cpu, xc_cpumap_t map);
+
+/*
+ * NODEMAP handling
+ */
+typedef uint8_t *xc_nodemap_t;
+
+/* return maximum number of NUMA nodes the hypervisor supports */
+int xc_get_max_nodes(xc_interface *xch);
+
+/* return array size for nodemap */
+int xc_get_nodemap_size(xc_interface *xch);
+
+/* allocate a nodemap */
+xc_nodemap_t xc_nodemap_alloc(xc_interface *xch);
+
+/*
+ * DOMAIN DEBUGGING FUNCTIONS
+ */
+
+typedef struct xc_core_header {
+    unsigned int xch_magic;
+    unsigned int xch_nr_vcpus;
+    unsigned int xch_nr_pages;
+    unsigned int xch_ctxt_offset;
+    unsigned int xch_index_offset;
+    unsigned int xch_pages_offset;
+} xc_core_header_t;
+
+#define XC_CORE_MAGIC     0xF00FEBED
+#define XC_CORE_MAGIC_HVM 0xF00FEBEE
+
+/*
+ * DOMAIN MANAGEMENT FUNCTIONS
+ */
+
+typedef struct xc_dominfo {
+    uint32_t      domid;
+    uint32_t      ssidref;
+    unsigned int  dying:1, crashed:1, shutdown:1,
+                  paused:1, blocked:1, running:1,
+                  hvm:1, debugged:1, xenstore:1, hap:1;
+    unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
+    unsigned long nr_pages; /* current number, not maximum */
+    unsigned long nr_outstanding_pages;
+    unsigned long nr_shared_pages;
+    unsigned long nr_paged_pages;
+    unsigned long shared_info_frame;
+    uint64_t      cpu_time;
+    unsigned long max_memkb;
+    unsigned int  nr_online_vcpus;
+    unsigned int  max_vcpu_id;
+    xen_domain_handle_t handle;
+    unsigned int  cpupool;
+    struct xen_arch_domainconfig arch_config;
+} xc_dominfo_t;
+
+typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+
+typedef union 
+{
+#if defined(__i386__) || defined(__x86_64__)
+    vcpu_guest_context_x86_64_t x64;
+    vcpu_guest_context_x86_32_t x32;   
+#endif
+    vcpu_guest_context_t c;
+} vcpu_guest_context_any_t;
+
+typedef union
+{
+#if defined(__i386__) || defined(__x86_64__)
+    shared_info_x86_64_t x64;
+    shared_info_x86_32_t x32;
+#endif
+    shared_info_t s;
+} shared_info_any_t;
+
+#if defined(__i386__) || defined(__x86_64__)
+typedef union
+{
+    start_info_x86_64_t x64;
+    start_info_x86_32_t x32;
+    start_info_t s;
+} start_info_any_t;
+#endif
+
+typedef struct xc_vcpu_extstate {
+    uint64_t xfeature_mask;
+    uint64_t size;
+    void *buffer;
+} xc_vcpu_extstate_t;
+
+int xc_domain_create(xc_interface *xch, uint32_t *pdomid,
+                     struct xen_domctl_createdomain *config);
+
+
+/* Functions to produce a dump of a given domain
+ *  xc_domain_dumpcore - produces a dump to a specified file
+ *  xc_domain_dumpcore_via_callback - produces a dump, using a specified
+ *                                    callback function
+ */
+int xc_domain_dumpcore(xc_interface *xch,
+                       uint32_t domid,
+                       const char *corename);
+
+/* Define the callback function type for xc_domain_dumpcore_via_callback.
+ *
+ * This function is called by the coredump code for every "write",
+ * and passes an opaque object for the use of the function and
+ * created by the caller of xc_domain_dumpcore_via_callback.
+ */
+typedef int (dumpcore_rtn_t)(xc_interface *xch,
+                             void *arg, char *buffer, unsigned int length);
+
+int xc_domain_dumpcore_via_callback(xc_interface *xch,
+                                    uint32_t domid,
+                                    void *arg,
+                                    dumpcore_rtn_t dump_rtn);
+
+/*
+ * This function sets the maximum number of vcpus that a domain may create.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id in which vcpus are to be created.
+ * @parm max the maximum number of vcpus that the domain may create.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_max_vcpus(xc_interface *xch,
+                        uint32_t domid,
+                        unsigned int max);
+
+/**
+ * This function pauses a domain. A paused domain still exists in memory
+ * however it does not receive any timeslices from the hypervisor.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to pause
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_pause(xc_interface *xch,
+                    uint32_t domid);
+/**
+ * This function unpauses a domain.  The domain should have been previously
+ * paused.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to unpause
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_unpause(xc_interface *xch,
+                      uint32_t domid);
+
+/**
+ * This function will destroy a domain.  Destroying a domain removes the domain
+ * completely from memory.  This function should be called after sending the
+ * domain a SHUTDOWN control message to free up the domain resources.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to destroy
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_destroy(xc_interface *xch,
+                      uint32_t domid);
+
+
+/**
+ * This function resumes a suspended domain. The domain should have
+ * been previously suspended.
+ *
+ * Note that there are 'xc_domain_suspend' as suspending a domain
+ * is quite the endeavour.
+ *
+ * For the purpose of this explanation there are three guests:
+ * PV (using hypercalls for privilgied operations), HVM
+ * (fully hardware virtualized guests using emulated devices for everything),
+ * and PVHVM (PV aware with hardware virtualisation).
+ *
+ * HVM guest are the simplest - they suspend via S3 / S4 and resume from
+ * S3 / S4. Upon resume they have to re-negotiate with the emulated devices.
+ *
+ * PV and PVHVM communicate via hypercalls for suspend (and resume).
+ * For suspend the toolstack initiates the process by writing an value
+ * in XenBus "control/shutdown" with the string "suspend".
+ *
+ * The PV guest stashes anything it deems neccessary in 'struct
+ * start_info' in case of failure (PVHVM may ignore this) and calls
+ * the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall (for PV as
+ * argument it passes the MFN to 'struct start_info').
+ *
+ * And then the guest is suspended.
+ *
+ * The checkpointing or notifying a guest that the suspend failed or
+ * cancelled (in case of checkpoint) is by having the
+ * SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return a non-zero
+ * value.
+ *
+ * The PV and PVHVM resume path are similar. For PV it would be
+ * similar to bootup - figure out where the 'struct start_info' is (or
+ * if the suspend was cancelled aka checkpointed - reuse the saved
+ * values).
+ *
+ * From here on they differ depending whether the guest is PV or PVHVM
+ * in specifics but follow overall the same path:
+ *  - PV: Bringing up the vCPUS,
+ *  - PVHVM: Setup vector callback,
+ *  - Bring up vCPU runstates,
+ *  - Remap the grant tables if checkpointing or setup from scratch,
+ *
+ *
+ * If the resume was not checkpointing (or if suspend was succesful) we would
+ * setup the PV timers and the different PV events. Lastly the PV drivers
+ * re-negotiate with the backend.
+ *
+ * This function would return before the guest started resuming. That is
+ * the guest would be in non-running state and its vCPU context would be
+ * in the the SCHEDOP_shutdown::SHUTDOWN_suspend hypercall return path
+ * (for PV and PVHVM). For HVM it would be in would be in QEMU emulated
+ * BIOS handling S3 suspend.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to resume
+ * @parm fast use cooperative resume (guest must support this)
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_resume(xc_interface *xch,
+		     uint32_t domid,
+		     int fast);
+
+/**
+ * This function will shutdown a domain. This is intended for use in
+ * fully-virtualized domains where this operation is analogous to the
+ * sched_op operations in a paravirtualized domain. The caller is
+ * expected to give the reason for the shutdown.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to destroy
+ * @parm reason is the reason (SHUTDOWN_xxx) for the shutdown
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_shutdown(xc_interface *xch,
+                       uint32_t domid,
+                       int reason);
+
+int xc_watchdog(xc_interface *xch,
+		uint32_t id,
+		uint32_t timeout);
+
+/**
+ * This function explicitly sets the host NUMA nodes the domain will
+ * have affinity with.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id one wants to set the affinity of.
+ * @parm nodemap the map of the affine nodes.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_node_setaffinity(xc_interface *xch,
+                               uint32_t domind,
+                               xc_nodemap_t nodemap);
+
+/**
+ * This function retrieves the host NUMA nodes the domain has
+ * affinity with.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domid the domain id one wants to get the node affinity of.
+ * @parm nodemap the map of the affine nodes.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_domain_node_getaffinity(xc_interface *xch,
+                               uint32_t domind,
+                               xc_nodemap_t nodemap);
+
+/**
+ * This function specifies the CPU affinity for a vcpu.
+ *
+ * There are two kinds of affinity. Soft affinity is on what CPUs a vcpu
+ * prefers to run. Hard affinity is on what CPUs a vcpu is allowed to run.
+ * If flags contains XEN_VCPUAFFINITY_SOFT, the soft affinity it is set to
+ * what cpumap_soft_inout contains. If flags contains XEN_VCPUAFFINITY_HARD,
+ * the hard affinity is set to what cpumap_hard_inout contains. Both flags
+ * can be set at the same time, in which case both soft and hard affinity are
+ * set to what the respective parameter contains.
+ *
+ * The function also returns the effective hard or/and soft affinity, still
+ * via the cpumap_soft_inout and cpumap_hard_inout parameters. Effective
+ * affinity is, in case of soft affinity, the intersection of soft affinity,
+ * hard affinity and the cpupool's online CPUs for the domain, and is returned
+ * in cpumap_soft_inout, if XEN_VCPUAFFINITY_SOFT is set in flags. In case of
+ * hard affinity, it is the intersection between hard affinity and the
+ * cpupool's online CPUs, and is returned in cpumap_hard_inout, if
+ * XEN_VCPUAFFINITY_HARD is set in flags. If both flags are set, both soft
+ * and hard affinity are returned in the respective parameter.
+ *
+ * We do report it back as effective affinity is what the Xen scheduler will
+ * actually use, and we thus allow checking whether or not that matches with,
+ * or at least is good enough for, the caller's purposes.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the id of the domain to which the vcpu belongs
+ * @param vcpu the vcpu id wihin the domain
+ * @param cpumap_hard_inout specifies(/returns) the (effective) hard affinity
+ * @param cpumap_soft_inout specifies(/returns) the (effective) soft affinity
+ * @param flags what we want to set
+ */
+int xc_vcpu_setaffinity(xc_interface *xch,
+                        uint32_t domid,
+                        int vcpu,
+                        xc_cpumap_t cpumap_hard_inout,
+                        xc_cpumap_t cpumap_soft_inout,
+                        uint32_t flags);
+
+/**
+ * This function retrieves hard and soft CPU affinity of a vcpu,
+ * depending on what flags are set.
+ *
+ * Soft affinity is returned in cpumap_soft if XEN_VCPUAFFINITY_SOFT is set.
+ * Hard affinity is returned in cpumap_hard if XEN_VCPUAFFINITY_HARD is set.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the id of the domain to which the vcpu belongs
+ * @param vcpu the vcpu id wihin the domain
+ * @param cpumap_hard is where hard affinity is returned
+ * @param cpumap_soft is where soft affinity is returned
+ * @param flags what we want get
+ */
+int xc_vcpu_getaffinity(xc_interface *xch,
+                        uint32_t domid,
+                        int vcpu,
+                        xc_cpumap_t cpumap_hard,
+                        xc_cpumap_t cpumap_soft,
+                        uint32_t flags);
+
+
+/**
+ * This function will return the guest_width (in bytes) for the
+ * specified domain.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the domain id one wants the address size width of.
+ * @param addr_size the address size.
+ */
+int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid,
+                              unsigned int *guest_width);
+
+
+/**
+ * This function will return information about one or more domains. It is
+ * designed to iterate over the list of domains. If a single domain is
+ * requested, this function will return the next domain in the list - if
+ * one exists. It is, therefore, important in this case to make sure the
+ * domain requested was the one returned.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm first_domid the first domain to enumerate information from.  Domains
+ *                   are currently enumerate in order of creation.
+ * @parm max_doms the number of elements in info
+ * @parm info an array of max_doms size that will contain the information for
+ *            the enumerated domains.
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_domain_getinfo(xc_interface *xch,
+                      uint32_t first_domid,
+                      unsigned int max_doms,
+                      xc_dominfo_t *info);
+
+
+/**
+ * This function will set the execution context for the specified vcpu.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to set the vcpu context for
+ * @parm vcpu the vcpu number for the context
+ * @parm ctxt pointer to the the cpu context with the values to set
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_vcpu_setcontext(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_any_t *ctxt);
+/**
+ * This function will return information about one or more domains, using a
+ * single hypercall.  The domain information will be stored into the supplied
+ * array of xc_domaininfo_t structures.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm first_domain the first domain to enumerate information from.
+ *                    Domains are currently enumerate in order of creation.
+ * @parm max_domains the number of elements in info
+ * @parm info an array of max_doms size that will contain the information for
+ *            the enumerated domains.
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_domain_getinfolist(xc_interface *xch,
+                          uint32_t first_domain,
+                          unsigned int max_domains,
+                          xc_domaininfo_t *info);
+
+/**
+ * This function set p2m for broken page
+ * &parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id which broken page belong to
+ * @parm pfn the pfn number of the broken page
+ * @return 0 on success, -1 on failure
+ */
+int xc_set_broken_page_p2m(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned long pfn);
+
+/**
+ * This function returns information about the context of a hvm domain
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm ctxt_buf a pointer to a structure to store the execution context of
+ *            the hvm domain
+ * @parm size the size of ctxt_buf in bytes
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_getcontext(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t *ctxt_buf,
+                             uint32_t size);
+
+
+/**
+ * This function returns one element of the context of a hvm domain
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm typecode which type of elemnt required 
+ * @parm instance which instance of the type
+ * @parm ctxt_buf a pointer to a structure to store the execution context of
+ *            the hvm domain
+ * @parm size the size of ctxt_buf (must be >= HVM_SAVE_LENGTH(typecode))
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_getcontext_partial(xc_interface *xch,
+                                     uint32_t domid,
+                                     uint16_t typecode,
+                                     uint16_t instance,
+                                     void *ctxt_buf,
+                                     uint32_t size);
+
+/**
+ * This function will set the context for hvm domain
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to set the hvm domain context for
+ * @parm hvm_ctxt pointer to the the hvm context with the values to set
+ * @parm size the size of hvm_ctxt in bytes
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_hvm_setcontext(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t *hvm_ctxt,
+                             uint32_t size);
+
+/**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
+ * This function returns information about the execution context of a
+ * particular vcpu of a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm vcpu the vcpu number
+ * @parm ctxt a pointer to a structure to store the execution context of the
+ *            domain
+ * @return 0 on success, -1 on failure
+ */
+int xc_vcpu_getcontext(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_any_t *ctxt);
+
+/**
+ * This function initializes the vuart emulation and returns
+ * the event to be used by the backend for communicating with
+ * the emulation code.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * #parm type type of vuart
+ * @parm domid the domain to get information from
+ * @parm console_domid the domid of the backend console
+ * @parm gfn the guest pfn to be used as the ring buffer
+ * @parm evtchn the event channel to be used for events
+ * @return 0 on success, negative error on failure
+ */
+int xc_dom_vuart_init(xc_interface *xch,
+                      uint32_t type,
+                      uint32_t domid,
+                      uint32_t console_domid,
+                      xen_pfn_t gfn,
+                      evtchn_port_t *evtchn);
+
+/**
+ * This function returns information about the XSAVE state of a particular
+ * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0,
+ * the call is considered a query to retrieve them and the buffer is not
+ * filled.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm vcpu the vcpu number
+ * @parm extstate a pointer to a structure to store the XSAVE state of the
+ *                domain
+ * @return 0 on success, negative error code on failure
+ */
+int xc_vcpu_get_extstate(xc_interface *xch,
+                         uint32_t domid,
+                         uint32_t vcpu,
+                         xc_vcpu_extstate_t *extstate);
+
+typedef struct xen_domctl_getvcpuinfo xc_vcpuinfo_t;
+int xc_vcpu_getinfo(xc_interface *xch,
+                    uint32_t domid,
+                    uint32_t vcpu,
+                    xc_vcpuinfo_t *info);
+
+long long xc_domain_get_cpu_usage(xc_interface *xch,
+                                  uint32_t domid,
+                                  int vcpu);
+
+int xc_domain_sethandle(xc_interface *xch, uint32_t domid,
+                        xen_domain_handle_t handle);
+
+typedef struct xen_domctl_shadow_op_stats xc_shadow_op_stats_t;
+int xc_shadow_control(xc_interface *xch,
+                      uint32_t domid,
+                      unsigned int sop,
+                      xc_hypercall_buffer_t *dirty_bitmap,
+                      unsigned long pages,
+                      unsigned long *mb,
+                      uint32_t mode,
+                      xc_shadow_op_stats_t *stats);
+
+int xc_sched_credit_domain_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit *sdom);
+
+int xc_sched_credit_domain_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit *sdom);
+int xc_sched_credit_params_set(xc_interface *xch,
+                               uint32_t cpupool_id,
+                               struct xen_sysctl_credit_schedule *schedule);
+int xc_sched_credit_params_get(xc_interface *xch,
+                               uint32_t cpupool_id,
+                               struct xen_sysctl_credit_schedule *schedule);
+
+int xc_sched_credit2_params_set(xc_interface *xch,
+                                uint32_t cpupool_id,
+                                struct xen_sysctl_credit2_schedule *schedule);
+int xc_sched_credit2_params_get(xc_interface *xch,
+                                uint32_t cpupool_id,
+                                struct xen_sysctl_credit2_schedule *schedule);
+int xc_sched_credit2_domain_set(xc_interface *xch,
+                                uint32_t domid,
+                                struct xen_domctl_sched_credit2 *sdom);
+int xc_sched_credit2_domain_get(xc_interface *xch,
+                                uint32_t domid,
+                                struct xen_domctl_sched_credit2 *sdom);
+
+int xc_sched_rtds_domain_set(xc_interface *xch,
+                             uint32_t domid,
+                             struct xen_domctl_sched_rtds *sdom);
+int xc_sched_rtds_domain_get(xc_interface *xch,
+                             uint32_t domid,
+                             struct xen_domctl_sched_rtds *sdom);
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_schedparam_vcpu *vcpus,
+                           uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_schedparam_vcpu *vcpus,
+                           uint32_t num_vcpus);
+
+int
+xc_sched_arinc653_schedule_set(
+    xc_interface *xch,
+    uint32_t cpupool_id,
+    struct xen_sysctl_arinc653_schedule *schedule);
+
+int
+xc_sched_arinc653_schedule_get(
+    xc_interface *xch,
+    uint32_t cpupool_id,
+    struct xen_sysctl_arinc653_schedule *schedule);
+
+/**
+ * This function sends a trigger to a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm trigger the trigger type
+ * @parm vcpu the vcpu number to send trigger 
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_send_trigger(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t trigger,
+                           uint32_t vcpu);
+
+/**
+ * This function enables or disable debugging of a domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm enable true to enable debugging
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_setdebugging(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned int enable);
+
+/**
+ * This function audits the (top level) p2m of a domain 
+ * and returns the different error counts, if any.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id whose top level p2m we 
+ *       want to audit
+ * @parm orphans count of m2p entries for valid
+ *       domain pages containing an invalid value
+ * @parm m2p_bad count of m2p entries mismatching the
+ *       associated p2m entry for this domain
+ * @parm p2m_bad count of p2m entries for this domain
+ *       mismatching the associated m2p entry
+ * return 0 on success, -1 on failure
+ * errno values on failure include: 
+ *          -ENOSYS: not implemented
+ *          -EFAULT: could not copy results back to guest
+ */
+int xc_domain_p2m_audit(xc_interface *xch,
+                        uint32_t domid,
+                        uint64_t *orphans,
+                        uint64_t *m2p_bad,   
+                        uint64_t *p2m_bad);
+
+/**
+ * This function sets or clears the requirement that an access memory
+ * event listener is required on the domain.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id to send trigger
+ * @parm enable true to require a listener
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_set_access_required(xc_interface *xch,
+				  uint32_t domid,
+				  unsigned int required);
+/**
+ * This function sets the handler of global VIRQs sent by the hypervisor
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain id which will handle the VIRQ
+ * @parm virq the virq number (VIRQ_*)
+ * return 0 on success, -1 on failure
+ */
+int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
+
+/*
+ * CPUPOOL MANAGEMENT FUNCTIONS
+ */
+
+typedef struct xc_cpupoolinfo {
+    uint32_t cpupool_id;
+    uint32_t sched_id;
+    uint32_t n_dom;
+    xc_cpumap_t cpumap;
+} xc_cpupoolinfo_t;
+
+#define XC_CPUPOOL_POOLID_ANY 0xFFFFFFFF
+
+/**
+ * Create a new cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm ppoolid pointer to the new cpupool id (in/out)
+ * @parm sched_id id of scheduler to use for pool
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_create(xc_interface *xch,
+                      uint32_t *ppoolid,
+                      uint32_t sched_id);
+
+/**
+ * Destroy a cpupool. Pool must be unused and have no cpu assigned.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool to destroy
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_destroy(xc_interface *xch,
+                       uint32_t poolid);
+
+/**
+ * Get cpupool info. Returns info for up to the specified number of cpupools
+ * starting at the given id.
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid lowest id for which info is returned
+ * return cpupool info ptr (to be freed via xc_cpupool_infofree)
+ */
+xc_cpupoolinfo_t *xc_cpupool_getinfo(xc_interface *xch,
+                       uint32_t poolid);
+
+/**
+ * Free cpupool info. Used to free info obtained via xc_cpupool_getinfo.
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm info area to free
+ */
+void xc_cpupool_infofree(xc_interface *xch,
+                         xc_cpupoolinfo_t *info);
+
+/**
+ * Add cpu to a cpupool. cpu may be -1 indicating the first unassigned.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool
+ * @parm cpu cpu number to add
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_addcpu(xc_interface *xch,
+                      uint32_t poolid,
+                      int cpu);
+
+/**
+ * Remove cpu from cpupool. cpu may be -1 indicating the last cpu of the pool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the cpupool
+ * @parm cpu cpu number to remove
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_removecpu(xc_interface *xch,
+                         uint32_t poolid,
+                         int cpu);
+
+/**
+ * Move domain to another cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm poolid id of the destination cpupool
+ * @parm domid id of the domain to move
+ * return 0 on success, -1 on failure
+ */
+int xc_cpupool_movedomain(xc_interface *xch,
+                          uint32_t poolid,
+                          uint32_t domid);
+
+/**
+ * Return map of cpus not in any cpupool.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * return cpumap array on success, NULL else
+ */
+xc_cpumap_t xc_cpupool_freeinfo(xc_interface *xch);
+
+/*
+ * EVENT CHANNEL FUNCTIONS
+ *
+ * None of these do any logging.
+ */
+
+/* A port identifier is guaranteed to fit in 31 bits. */
+typedef int xc_evtchn_port_or_error_t;
+
+/**
+ * This function allocates an unbound port.  Ports are named endpoints used for
+ * interdomain communication.  This function is most useful in opening a
+ * well-known port within a domain to receive events on.
+ * 
+ * NOTE: If you are allocating a *local* unbound port, you probably want to
+ * use xc_evtchn_bind_unbound_port(). This function is intended for allocating
+ * ports *only* during domain creation.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm dom the ID of the local domain (the 'allocatee')
+ * @parm remote_dom the ID of the domain who will later bind
+ * @return allocated port (in @dom) on success, -1 on failure
+ */
+xc_evtchn_port_or_error_t
+xc_evtchn_alloc_unbound(xc_interface *xch,
+                        uint32_t dom,
+                        uint32_t remote_dom);
+
+int xc_evtchn_reset(xc_interface *xch,
+                    uint32_t dom);
+
+typedef struct evtchn_status xc_evtchn_status_t;
+int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status);
+
+
+
+int xc_physdev_pci_access_modify(xc_interface *xch,
+                                 uint32_t domid,
+                                 int bus,
+                                 int dev,
+                                 int func,
+                                 int enable);
+
+int xc_readconsolering(xc_interface *xch,
+                       char *buffer,
+                       unsigned int *pnr_chars,
+                       int clear, int incremental, uint32_t *pindex);
+
+int xc_send_debug_keys(xc_interface *xch, const char *keys);
+
+typedef struct xen_sysctl_physinfo xc_physinfo_t;
+typedef struct xen_sysctl_cputopo xc_cputopo_t;
+typedef struct xen_sysctl_numainfo xc_numainfo_t;
+typedef struct xen_sysctl_meminfo xc_meminfo_t;
+typedef struct xen_sysctl_pcitopoinfo xc_pcitopoinfo_t;
+
+typedef uint32_t xc_cpu_to_node_t;
+typedef uint32_t xc_cpu_to_socket_t;
+typedef uint32_t xc_cpu_to_core_t;
+typedef uint64_t xc_node_to_memsize_t;
+typedef uint64_t xc_node_to_memfree_t;
+typedef uint32_t xc_node_to_node_dist_t;
+
+int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus,
+                   xc_cputopo_t *cputopo);
+int xc_microcode_update(xc_interface *xch, const void *buf, size_t len);
+int xc_numainfo(xc_interface *xch, unsigned *max_nodes,
+                xc_meminfo_t *meminfo, uint32_t *distance);
+int xc_pcitopoinfo(xc_interface *xch, unsigned num_devs,
+                   physdev_pci_device_t *devs, uint32_t *nodes);
+
+int xc_sched_id(xc_interface *xch,
+                int *sched_id);
+
+int xc_machphys_mfn_list(xc_interface *xch,
+                         unsigned long max_extents,
+                         xen_pfn_t *extent_start);
+
+typedef struct xen_sysctl_cpuinfo xc_cpuinfo_t;
+int xc_getcpuinfo(xc_interface *xch, int max_cpus,
+                  xc_cpuinfo_t *info, int *nr_cpus); 
+
+int xc_domain_setmaxmem(xc_interface *xch,
+                        uint32_t domid,
+                        uint64_t max_memkb);
+
+int xc_domain_set_memmap_limit(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long map_limitkb);
+
+int xc_domain_setvnuma(xc_interface *xch,
+                        uint32_t domid,
+                        uint32_t nr_vnodes,
+                        uint32_t nr_regions,
+                        uint32_t nr_vcpus,
+                        xen_vmemrange_t *vmemrange,
+                        unsigned int *vdistance,
+                        unsigned int *vcpu_to_vnode,
+                        unsigned int *vnode_to_pnode);
+/*
+ * Retrieve vnuma configuration
+ * domid: IN, target domid
+ * nr_vnodes: IN/OUT, number of vnodes, not NULL
+ * nr_vmemranges: IN/OUT, number of vmemranges, not NULL
+ * nr_vcpus: IN/OUT, number of vcpus, not NULL
+ * vmemranges: OUT, an array which has length of nr_vmemranges
+ * vdistance: OUT, an array which has length of nr_vnodes * nr_vnodes
+ * vcpu_to_vnode: OUT, an array which has length of nr_vcpus
+ */
+int xc_domain_getvnuma(xc_interface *xch,
+                       uint32_t domid,
+                       uint32_t *nr_vnodes,
+                       uint32_t *nr_vmemranges,
+                       uint32_t *nr_vcpus,
+                       xen_vmemrange_t *vmemrange,
+                       unsigned int *vdistance,
+                       unsigned int *vcpu_to_vnode);
+
+int xc_domain_soft_reset(xc_interface *xch,
+                         uint32_t domid);
+
+#if defined(__i386__) || defined(__x86_64__)
+/*
+ * PC BIOS standard E820 types and structure.
+ */
+#define E820_RAM          1
+#define E820_RESERVED     2
+#define E820_ACPI         3
+#define E820_NVS          4
+#define E820_UNUSABLE     5
+
+#define E820MAX           (128)
+
+struct e820entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+} __attribute__((packed));
+int xc_domain_set_memory_map(xc_interface *xch,
+                               uint32_t domid,
+                               struct e820entry entries[],
+                               uint32_t nr_entries);
+
+int xc_get_machine_memory_map(xc_interface *xch,
+                              struct e820entry entries[],
+                              uint32_t max_entries);
+#endif
+
+int xc_reserved_device_memory_map(xc_interface *xch,
+                                  uint32_t flags,
+                                  uint16_t seg,
+                                  uint8_t bus,
+                                  uint8_t devfn,
+                                  struct xen_reserved_device_memory entries[],
+                                  uint32_t *max_entries);
+int xc_domain_set_time_offset(xc_interface *xch,
+                              uint32_t domid,
+                              int32_t time_offset_seconds);
+
+int xc_domain_set_tsc_info(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t tsc_mode,
+                           uint64_t elapsed_nsec,
+                           uint32_t gtsc_khz,
+                           uint32_t incarnation);
+
+int xc_domain_get_tsc_info(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t *tsc_mode,
+                           uint64_t *elapsed_nsec,
+                           uint32_t *gtsc_khz,
+                           uint32_t *incarnation);
+
+int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid);
+
+int xc_domain_maximum_gpfn(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
+
+int xc_domain_nr_gpfns(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
+
+int xc_domain_increase_reservation(xc_interface *xch,
+                                   uint32_t domid,
+                                   unsigned long nr_extents,
+                                   unsigned int extent_order,
+                                   unsigned int mem_flags,
+                                   xen_pfn_t *extent_start);
+
+int xc_domain_increase_reservation_exact(xc_interface *xch,
+                                         uint32_t domid,
+                                         unsigned long nr_extents,
+                                         unsigned int extent_order,
+                                         unsigned int mem_flags,
+                                         xen_pfn_t *extent_start);
+
+int xc_domain_decrease_reservation(xc_interface *xch,
+                                   uint32_t domid,
+                                   unsigned long nr_extents,
+                                   unsigned int extent_order,
+                                   xen_pfn_t *extent_start);
+
+int xc_domain_decrease_reservation_exact(xc_interface *xch,
+                                         uint32_t domid,
+                                         unsigned long nr_extents,
+                                         unsigned int extent_order,
+                                         xen_pfn_t *extent_start);
+
+int xc_domain_add_to_physmap(xc_interface *xch,
+                             uint32_t domid,
+                             unsigned int space,
+                             unsigned long idx,
+                             xen_pfn_t gpfn);
+
+int xc_domain_add_to_physmap_batch(xc_interface *xch,
+                                   uint32_t domid,
+                                   uint32_t foreign_domid,
+                                   unsigned int space,
+                                   unsigned int size,
+                                   xen_ulong_t *idxs,
+                                   xen_pfn_t *gfpns,
+                                   int *errs);
+
+int xc_domain_remove_from_physmap(xc_interface *xch,
+                                  uint32_t domid,
+                                  xen_pfn_t gpfn);
+
+int xc_domain_populate_physmap(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_extents,
+                               unsigned int extent_order,
+                               unsigned int mem_flags,
+                               xen_pfn_t *extent_start);
+
+int xc_domain_populate_physmap_exact(xc_interface *xch,
+                                     uint32_t domid,
+                                     unsigned long nr_extents,
+                                     unsigned int extent_order,
+                                     unsigned int mem_flags,
+                                     xen_pfn_t *extent_start);
+
+int xc_domain_claim_pages(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_pages);
+
+int xc_domain_memory_exchange_pages(xc_interface *xch,
+                                    uint32_t domid,
+                                    unsigned long nr_in_extents,
+                                    unsigned int in_order,
+                                    xen_pfn_t *in_extents,
+                                    unsigned long nr_out_extents,
+                                    unsigned int out_order,
+                                    xen_pfn_t *out_extents);
+
+int xc_domain_set_pod_target(xc_interface *xch,
+                             uint32_t domid,
+                             uint64_t target_pages,
+                             uint64_t *tot_pages,
+                             uint64_t *pod_cache_pages,
+                             uint64_t *pod_entries);
+
+int xc_domain_get_pod_target(xc_interface *xch,
+                             uint32_t domid,
+                             uint64_t *tot_pages,
+                             uint64_t *pod_cache_pages,
+                             uint64_t *pod_entries);
+
+int xc_domain_ioport_permission(xc_interface *xch,
+                                uint32_t domid,
+                                uint32_t first_port,
+                                uint32_t nr_ports,
+                                uint32_t allow_access);
+
+int xc_domain_irq_permission(xc_interface *xch,
+                             uint32_t domid,
+                             uint8_t pirq,
+                             uint8_t allow_access);
+
+int xc_domain_iomem_permission(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long first_mfn,
+                               unsigned long nr_mfns,
+                               uint8_t allow_access);
+
+unsigned long xc_make_page_below_4G(xc_interface *xch, uint32_t domid,
+                                    unsigned long mfn);
+
+typedef xen_sysctl_perfc_desc_t xc_perfc_desc_t;
+typedef xen_sysctl_perfc_val_t xc_perfc_val_t;
+int xc_perfc_reset(xc_interface *xch);
+int xc_perfc_query_number(xc_interface *xch,
+                          int *nbr_desc,
+                          int *nbr_val);
+int xc_perfc_query(xc_interface *xch,
+                   xc_hypercall_buffer_t *desc,
+                   xc_hypercall_buffer_t *val);
+
+typedef xen_sysctl_lockprof_data_t xc_lockprof_data_t;
+int xc_lockprof_reset(xc_interface *xch);
+int xc_lockprof_query_number(xc_interface *xch,
+                             uint32_t *n_elems);
+int xc_lockprof_query(xc_interface *xch,
+                      uint32_t *n_elems,
+                      uint64_t *time,
+                      xc_hypercall_buffer_t *data);
+
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
+/**
+ * Avoid using this function, as it does not work for all cases (such
+ * as 4M superpages, or guests using PSE36). Only used for debugging.
+ *
+ * Translates a virtual address in the context of a given domain and
+ * vcpu returning the GFN containing the address (that is, an MFN for 
+ * PV guests, a PFN for HVM guests).  Returns 0 for failure.
+ *
+ * @parm xch a handle on an open hypervisor interface
+ * @parm dom the domain to perform the translation in
+ * @parm vcpu the vcpu to perform the translation on
+ * @parm virt the virtual address to translate
+ */
+unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
+                                           int vcpu, unsigned long long virt);
+
+
+int xc_copy_to_domain_page(xc_interface *xch, uint32_t domid,
+                           unsigned long dst_pfn, const char *src_page);
+
+int xc_clear_domain_pages(xc_interface *xch, uint32_t domid,
+                          unsigned long dst_pfn, int num);
+
+static inline int xc_clear_domain_page(xc_interface *xch, uint32_t domid,
+                                       unsigned long dst_pfn)
+{
+    return xc_clear_domain_pages(xch, domid, dst_pfn, 1);
+}
+
+int xc_mmuext_op(xc_interface *xch, struct mmuext_op *op, unsigned int nr_ops,
+                 uint32_t dom);
+
+/* System wide memory properties */
+int xc_maximum_ram_page(xc_interface *xch, unsigned long *max_mfn);
+
+/* Get current total pages allocated to a domain. */
+long xc_get_tot_pages(xc_interface *xch, uint32_t domid);
+
+/**
+ * This function retrieves the the number of bytes available
+ * in the heap in a specific range of address-widths and nodes.
+ * 
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to query
+ * @parm min_width the smallest address width to query (0 if don't care)
+ * @parm max_width the largest address width to query (0 if don't care)
+ * @parm node the node to query (-1 for all)
+ * @parm *bytes caller variable to put total bytes counted
+ * @return 0 on success, <0 on failure.
+ */
+int xc_availheap(xc_interface *xch, int min_width, int max_width, int node,
+                 uint64_t *bytes);
+
+/*
+ * Trace Buffer Operations
+ */
+
+/**
+ * xc_tbuf_enable - enable tracing buffers
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm cnt size of tracing buffers to create (in pages)
+ * @parm mfn location to store mfn of the trace buffers to
+ * @parm size location to store the size (in bytes) of a trace buffer to
+ *
+ * Gets the machine address of the trace pointer area and the size of the
+ * per CPU buffers.
+ */
+int xc_tbuf_enable(xc_interface *xch, unsigned long pages,
+                   unsigned long *mfn, unsigned long *size);
+
+/*
+ * Disable tracing buffers.
+ */
+int xc_tbuf_disable(xc_interface *xch);
+
+/**
+ * This function sets the size of the trace buffers. Setting the size
+ * is currently a one-shot operation that may be performed either at boot
+ * time or via this interface, not both. The buffer size must be set before
+ * enabling tracing.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm size the size in pages per cpu for the trace buffers
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_set_size(xc_interface *xch, unsigned long size);
+
+/**
+ * This function retrieves the current size of the trace buffers.
+ * Note that the size returned is in terms of bytes, not pages.
+
+ * @parm xch a handle to an open hypervisor interface
+ * @parm size will contain the size in bytes for the trace buffers
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_get_size(xc_interface *xch, unsigned long *size);
+
+int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpumap_t mask);
+
+int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);
+
+int xc_domctl(xc_interface *xch, struct xen_domctl *domctl);
+int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl);
+
+int xc_version(xc_interface *xch, int cmd, void *arg);
+
+int xc_flask_op(xc_interface *xch, xen_flask_op_t *op);
+
+/*
+ * Subscribe to domain suspend via evtchn.
+ * Returns -1 on failure, in which case errno will be set appropriately.
+ * Just calls XEN_DOMCTL_subscribe - see the caveats for that domctl
+ * (in its doc comment in domctl.h).
+ */
+int xc_domain_subscribe_for_suspend(
+    xc_interface *xch, uint32_t domid, evtchn_port_t port);
+
+/**************************
+ * GRANT TABLE OPERATIONS *
+ **************************/
+
+/*
+ * These functions sometimes log messages as above, but not always.
+ */
+
+
+int xc_gnttab_op(xc_interface *xch, int cmd,
+                 void * op, int op_size, int count);
+/* Logs iff hypercall bounce fails, otherwise doesn't. */
+
+int xc_gnttab_query_size(xc_interface *xch, struct gnttab_query_size *query);
+int xc_gnttab_get_version(xc_interface *xch, uint32_t domid); /* Never logs */
+grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, uint32_t domid, int *gnt_num);
+grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, uint32_t domid, int *gnt_num);
+/* Sometimes these don't set errno [fixme], and sometimes they don't log. */
+
+int xc_physdev_map_pirq(xc_interface *xch,
+                        uint32_t domid,
+                        int index,
+                        int *pirq);
+
+int xc_physdev_map_pirq_msi(xc_interface *xch,
+                            uint32_t domid,
+                            int index,
+                            int *pirq,
+                            int devfn,
+                            int bus,
+                            int entry_nr,
+                            uint64_t table_base);
+
+int xc_physdev_unmap_pirq(xc_interface *xch,
+                          uint32_t domid,
+                          int pirq);
+
+/*
+ *  LOGGING AND ERROR REPORTING
+ */
+
+
+#define XC_MAX_ERROR_MSG_LEN 1024
+typedef struct xc_error {
+  enum xc_error_code code;
+  char message[XC_MAX_ERROR_MSG_LEN];
+} xc_error;
+
+
+/*
+ * Convert an error code or level into a text description.  Return values
+ * are pointers to fixed strings and do not need to be freed.
+ * Do not fail, but return pointers to generic strings if fed bogus input.
+ */
+const char *xc_error_code_to_desc(int code);
+
+/*
+ * Convert an errno value to a text description.
+ */
+const char *xc_strerror(xc_interface *xch, int errcode);
+
+
+/*
+ * Return a pointer to the last error with level XC_REPORT_ERROR. This
+ * pointer and the data pointed to are only valid until the next call
+ * to libxc in the same thread.
+ */
+const xc_error *xc_get_last_error(xc_interface *handle);
+
+/*
+ * Clear the last error
+ */
+void xc_clear_last_error(xc_interface *xch);
+
+int xc_hvm_param_set(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t value);
+int xc_hvm_param_get(xc_interface *handle, uint32_t dom, uint32_t param, uint64_t *value);
+
+/* Deprecated: use xc_hvm_param_set/get() instead. */
+int xc_set_hvm_param(xc_interface *handle, uint32_t dom, int param, unsigned long value);
+int xc_get_hvm_param(xc_interface *handle, uint32_t dom, int param, unsigned long *value);
+
+/* HVM guest pass-through */
+int xc_assign_device(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf,
+                     uint32_t flag);
+
+int xc_get_device_group(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf,
+                     uint32_t max_sdevs,
+                     uint32_t *num_sdevs,
+                     uint32_t *sdev_array);
+
+int xc_test_assign_device(xc_interface *xch,
+                          uint32_t domid,
+                          uint32_t machine_sbdf);
+
+int xc_deassign_device(xc_interface *xch,
+                     uint32_t domid,
+                     uint32_t machine_sbdf);
+
+int xc_assign_dt_device(xc_interface *xch,
+                        uint32_t domid,
+                        char *path);
+int xc_test_assign_dt_device(xc_interface *xch,
+                             uint32_t domid,
+                             char *path);
+int xc_deassign_dt_device(xc_interface *xch,
+                          uint32_t domid,
+                          char *path);
+
+int xc_domain_memory_mapping(xc_interface *xch,
+                             uint32_t domid,
+                             unsigned long first_gfn,
+                             unsigned long first_mfn,
+                             unsigned long nr_mfns,
+                             uint32_t add_mapping);
+
+int xc_domain_ioport_mapping(xc_interface *xch,
+                             uint32_t domid,
+                             uint32_t first_gport,
+                             uint32_t first_mport,
+                             uint32_t nr_ports,
+                             uint32_t add_mapping);
+
+int xc_domain_update_msi_irq(
+    xc_interface *xch,
+    uint32_t domid,
+    uint32_t gvec,
+    uint32_t pirq,
+    uint32_t gflags,
+    uint64_t gtable);
+
+int xc_domain_unbind_msi_irq(xc_interface *xch,
+                             uint32_t domid,
+                             uint32_t gvec,
+                             uint32_t pirq,
+                             uint32_t gflags);
+
+int xc_domain_bind_pt_irq(xc_interface *xch,
+                          uint32_t domid,
+                          uint8_t machine_irq,
+                          uint8_t irq_type,
+                          uint8_t bus,
+                          uint8_t device,
+                          uint8_t intx,
+                          uint8_t isa_irq);
+
+int xc_domain_unbind_pt_irq(xc_interface *xch,
+                          uint32_t domid,
+                          uint8_t machine_irq,
+                          uint8_t irq_type,
+                          uint8_t bus,
+                          uint8_t device,
+                          uint8_t intx,
+                          uint8_t isa_irq);
+
+int xc_domain_bind_pt_pci_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint8_t machine_irq,
+                              uint8_t bus,
+                              uint8_t device,
+                              uint8_t intx);
+
+int xc_domain_bind_pt_isa_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint8_t machine_irq);
+
+int xc_domain_bind_pt_spi_irq(xc_interface *xch,
+                              uint32_t domid,
+                              uint16_t vspi,
+                              uint16_t spi);
+
+int xc_domain_unbind_pt_spi_irq(xc_interface *xch,
+                                uint32_t domid,
+                                uint16_t vspi,
+                                uint16_t spi);
+
+/* Set the target domain */
+int xc_domain_set_target(xc_interface *xch,
+                         uint32_t domid,
+                         uint32_t target);
+
+/* Control the domain for debug */
+int xc_domain_debug_control(xc_interface *xch,
+                            uint32_t domid,
+                            uint32_t sop,
+                            uint32_t vcpu);
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/*
+ * CPUID policy data, expressed in the legacy XEND format.
+ *
+ * Policy is an array of strings, 32 chars long:
+ *   policy[0] = eax
+ *   policy[1] = ebx
+ *   policy[2] = ecx
+ *   policy[3] = edx
+ *
+ * The format of the string is the following:
+ *   '1' -> force to 1
+ *   '0' -> force to 0
+ *   'x' -> we don't care (use default)
+ *   'k' -> pass through host value
+ *   's' -> legacy alias for 'k'
+ */
+struct xc_xend_cpuid {
+    union {
+        struct {
+            uint32_t leaf, subleaf;
+        };
+        uint32_t input[2];
+    };
+    char *policy[4];
+};
+
+/*
+ * Make adjustments to the CPUID settings for a domain.
+ *
+ * This path is used in two cases.  First, for fresh boots of the domain, and
+ * secondly for migrate-in/restore of pre-4.14 guests (where CPUID data was
+ * missing from the stream).  The @restore parameter distinguishes these
+ * cases, and the generated policy must be compatible with a 4.13.
+ *
+ * Either pass a full new @featureset (and @nr_features), or adjust individual
+ * features (@pae).
+ *
+ * Then (optionally) apply legacy XEND overrides (@xend) to the result.
+ */
+int xc_cpuid_apply_policy(xc_interface *xch,
+                          uint32_t domid, bool restore,
+                          const uint32_t *featureset,
+                          unsigned int nr_features, bool pae,
+                          const struct xc_xend_cpuid *xend);
+int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
+int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
+                        xc_cpumap_t cpumap, unsigned int nr_cpus);
+#endif
+
+struct xc_px_val {
+    uint64_t freq;        /* Px core frequency */
+    uint64_t residency;   /* Px residency time */
+    uint64_t count;       /* Px transition count */
+};
+
+struct xc_px_stat {
+    uint8_t total;        /* total Px states */
+    uint8_t usable;       /* usable Px states */
+    uint8_t last;         /* last Px state */
+    uint8_t cur;          /* current Px state */
+    uint64_t *trans_pt;   /* Px transition table */
+    struct xc_px_val *pt;
+};
+
+int xc_pm_get_max_px(xc_interface *xch, int cpuid, int *max_px);
+int xc_pm_get_pxstat(xc_interface *xch, int cpuid, struct xc_px_stat *pxpt);
+int xc_pm_reset_pxstat(xc_interface *xch, int cpuid);
+
+struct xc_cx_stat {
+    uint32_t nr;           /* entry nr in triggers[]/residencies[], incl C0 */
+    uint32_t last;         /* last Cx state */
+    uint64_t idle_time;    /* idle time from boot */
+    uint64_t *triggers;    /* Cx trigger counts */
+    uint64_t *residencies; /* Cx residencies */
+    uint32_t nr_pc;        /* entry nr in pc[] */
+    uint32_t nr_cc;        /* entry nr in cc[] */
+    uint64_t *pc;          /* 1-biased indexing (i.e. excl C0) */
+    uint64_t *cc;          /* 1-biased indexing (i.e. excl C0) */
+};
+typedef struct xc_cx_stat xc_cx_stat_t;
+
+int xc_pm_get_max_cx(xc_interface *xch, int cpuid, int *max_cx);
+int xc_pm_get_cxstat(xc_interface *xch, int cpuid, struct xc_cx_stat *cxpt);
+int xc_pm_reset_cxstat(xc_interface *xch, int cpuid);
+
+int xc_cpu_online(xc_interface *xch, int cpu);
+int xc_cpu_offline(xc_interface *xch, int cpu);
+int xc_smt_enable(xc_interface *xch);
+int xc_smt_disable(xc_interface *xch);
+
+/* 
+ * cpufreq para name of this structure named 
+ * same as sysfs file name of native linux
+ */
+typedef struct xen_userspace xc_userspace_t;
+typedef struct xen_ondemand xc_ondemand_t;
+
+struct xc_get_cpufreq_para {
+    /* IN/OUT variable */
+    uint32_t cpu_num;
+    uint32_t freq_num;
+    uint32_t gov_num;
+
+    /* for all governors */
+    /* OUT variable */
+    uint32_t *affected_cpus;
+    uint32_t *scaling_available_frequencies;
+    char     *scaling_available_governors;
+    char scaling_driver[CPUFREQ_NAME_LEN];
+
+    uint32_t cpuinfo_cur_freq;
+    uint32_t cpuinfo_max_freq;
+    uint32_t cpuinfo_min_freq;
+    uint32_t scaling_cur_freq;
+
+    char scaling_governor[CPUFREQ_NAME_LEN];
+    uint32_t scaling_max_freq;
+    uint32_t scaling_min_freq;
+
+    /* for specific governor */
+    union {
+        xc_userspace_t userspace;
+        xc_ondemand_t ondemand;
+    } u;
+
+    int32_t turbo_enabled;
+};
+
+int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
+                        struct xc_get_cpufreq_para *user_para);
+int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname);
+int xc_set_cpufreq_para(xc_interface *xch, int cpuid,
+                        int ctrl_type, int ctrl_value);
+int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq);
+
+int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value);
+
+int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value);
+int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value);
+
+int xc_get_cpuidle_max_csubstate(xc_interface *xch, uint32_t *value);
+int xc_set_cpuidle_max_csubstate(xc_interface *xch, uint32_t value);
+
+int xc_enable_turbo(xc_interface *xch, int cpuid);
+int xc_disable_turbo(xc_interface *xch, int cpuid);
+
+/**
+ * altp2m operations
+ */
+
+int xc_altp2m_get_domain_state(xc_interface *handle, uint32_t dom, bool *state);
+int xc_altp2m_set_domain_state(xc_interface *handle, uint32_t dom, bool state);
+int xc_altp2m_set_vcpu_enable_notify(xc_interface *handle, uint32_t domid,
+                                     uint32_t vcpuid, xen_pfn_t gfn);
+int xc_altp2m_set_vcpu_disable_notify(xc_interface *handle, uint32_t domid,
+                                      uint32_t vcpuid);
+int xc_altp2m_create_view(xc_interface *handle, uint32_t domid,
+                          xenmem_access_t default_access, uint16_t *view_id);
+int xc_altp2m_destroy_view(xc_interface *handle, uint32_t domid,
+                           uint16_t view_id);
+/* Switch all vCPUs of the domain to the specified altp2m view */
+int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id);
+int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid,
+                              uint16_t view_id, xen_pfn_t gfn, bool sve);
+int xc_altp2m_set_supress_ve_multi(xc_interface *handle, uint32_t domid,
+                                   uint16_t view_id, xen_pfn_t first_gfn,
+                                   xen_pfn_t last_gfn, bool sve,
+                                   xen_pfn_t *error_gfn, int32_t *error_code);
+int xc_altp2m_get_suppress_ve(xc_interface *handle, uint32_t domid,
+                              uint16_t view_id, xen_pfn_t gfn, bool *sve);
+int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, xen_pfn_t gfn,
+                             xenmem_access_t access);
+int xc_altp2m_set_mem_access_multi(xc_interface *handle, uint32_t domid,
+                                   uint16_t view_id, uint8_t *access,
+                                   uint64_t *gfns, uint32_t nr);
+int xc_altp2m_get_mem_access(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, xen_pfn_t gfn,
+                             xenmem_access_t *access);
+int xc_altp2m_change_gfn(xc_interface *handle, uint32_t domid,
+                         uint16_t view_id, xen_pfn_t old_gfn,
+                         xen_pfn_t new_gfn);
+int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid,
+                               uint32_t vcpuid, uint16_t *p2midx);
+/*
+ * Set view visibility for xc_altp2m_switch_to_view and vmfunc.
+ * Note: If altp2m mode is set to mixed the guest is able to change the view
+ * visibility and then call vmfunc.
+ */
+int xc_altp2m_set_visibility(xc_interface *handle, uint32_t domid,
+                             uint16_t view_id, bool visible);
+
+/** 
+ * Mem paging operations.
+ * Paging is supported only on the x86 architecture in 64 bit mode, with
+ * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
+ * support is considered experimental.
+ */
+int xc_mem_paging_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port);
+int xc_mem_paging_disable(xc_interface *xch, uint32_t domain_id);
+int xc_mem_paging_resume(xc_interface *xch, uint32_t domain_id);
+int xc_mem_paging_nominate(xc_interface *xch, uint32_t domain_id,
+                           uint64_t gfn);
+int xc_mem_paging_evict(xc_interface *xch, uint32_t domain_id, uint64_t gfn);
+int xc_mem_paging_prep(xc_interface *xch, uint32_t domain_id, uint64_t gfn);
+int xc_mem_paging_load(xc_interface *xch, uint32_t domain_id,
+                       uint64_t gfn, void *buffer);
+
+/** 
+ * Access tracking operations.
+ * Supported only on Intel EPT 64 bit processors.
+ */
+
+/*
+ * Set a range of memory to a specific access.
+ * 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, uint32_t domain_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.
+ * The nr parameter specifies the size of the pages and access arrays.
+ * The same allowed access types as for xc_set_mem_access() apply.
+ */
+int xc_set_mem_access_multi(xc_interface *xch, uint32_t domain_id,
+                            uint8_t *access, uint64_t *pages,
+                            uint32_t nr);
+
+/*
+ * Gets the mem access for the given page (returned in access on success)
+ */
+int xc_get_mem_access(xc_interface *xch, uint32_t domain_id,
+                      uint64_t pfn, xenmem_access_t *access);
+
+/*
+ * Returns the VM_EVENT_INTERFACE version.
+ */
+int xc_vm_event_get_version(xc_interface *xch);
+
+/***
+ * Monitor control operations.
+ *
+ * Enables the VM event monitor ring and returns the mapped ring page.
+ * This ring is used to deliver mem_access events, as well a set of additional
+ * events that can be enabled with the xc_monitor_* functions.
+ *
+ * Will return NULL on error.
+ * Caller has to unmap this page when done.
+ */
+void *xc_monitor_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port);
+int xc_monitor_disable(xc_interface *xch, uint32_t domain_id);
+int xc_monitor_resume(xc_interface *xch, uint32_t domain_id);
+/*
+ * Get a bitmap of supported monitor events in the form
+ * (1 << XEN_DOMCTL_MONITOR_EVENT_*).
+ */
+int xc_monitor_get_capabilities(xc_interface *xch, uint32_t domain_id,
+                                uint32_t *capabilities);
+int xc_monitor_write_ctrlreg(xc_interface *xch, uint32_t domain_id,
+                             uint16_t index, bool enable, bool sync,
+                             uint64_t bitmask, bool onchangeonly);
+/*
+ * A list of MSR indices can usually be found in /usr/include/asm/msr-index.h.
+ * Please consult the Intel/AMD manuals for more information on
+ * non-architectural indices.
+ */
+int xc_monitor_mov_to_msr(xc_interface *xch, uint32_t domain_id, uint32_t msr,
+                          bool enable, bool onchangeonly);
+int xc_monitor_singlestep(xc_interface *xch, uint32_t domain_id, bool enable);
+int xc_monitor_software_breakpoint(xc_interface *xch, uint32_t domain_id,
+                                   bool enable);
+int xc_monitor_descriptor_access(xc_interface *xch, uint32_t domain_id,
+                                 bool enable);
+int xc_monitor_guest_request(xc_interface *xch, uint32_t domain_id,
+                             bool enable, bool sync, bool allow_userspace);
+/*
+ * Disables page-walk mem_access events by emulating. If the
+ * emulation can not be performed then a VM_EVENT_REASON_EMUL_UNIMPLEMENTED
+ * event will be issued.
+ */
+int xc_monitor_inguest_pagefault(xc_interface *xch, uint32_t domain_id,
+                                 bool disable);
+int xc_monitor_debug_exceptions(xc_interface *xch, uint32_t domain_id,
+                                bool enable, bool sync);
+int xc_monitor_cpuid(xc_interface *xch, uint32_t domain_id, bool enable);
+int xc_monitor_privileged_call(xc_interface *xch, uint32_t domain_id,
+                               bool enable);
+int xc_monitor_emul_unimplemented(xc_interface *xch, uint32_t domain_id,
+                                  bool enable);
+/**
+ * This function enables / disables emulation for each REP for a
+ * REP-compatible instruction.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domain_id the domain id one wants to get the node affinity of.
+ * @parm enable if 0 optimize when possible, else emulate each REP.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_monitor_emulate_each_rep(xc_interface *xch, uint32_t domain_id,
+                                bool enable);
+
+/***
+ * Memory sharing operations.
+ *
+ * Unles otherwise noted, these calls return 0 on succes, -1 and errno on
+ * failure.
+ *
+ * Sharing is supported only on the x86 architecture in 64 bit mode, with
+ * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
+ * support is considered experimental.
+
+ * Calls below return ENOSYS if not in the x86_64 architecture.
+ * Calls below return ENODEV if the domain does not support HAP.
+ * Calls below return ESRCH if the specified domain does not exist.
+ * Calls below return EPERM if the caller is unprivileged for this domain.
+ */
+
+/* Turn on/off sharing for the domid, depending on the enable flag.
+ *
+ * Returns EXDEV if trying to enable and the domain has had a PCI device
+ * assigned for passthrough (these two features are mutually exclusive).
+ *
+ * When sharing for a domain is turned off, the domain may still reference
+ * shared pages. Unsharing happens lazily. */
+int xc_memshr_control(xc_interface *xch,
+                      uint32_t domid,
+                      int enable);
+
+/* Create a communication ring in which the hypervisor will place ENOMEM
+ * notifications.
+ *
+ * ENOMEM happens when unsharing pages: a Copy-on-Write duplicate needs to be
+ * allocated, and thus the out-of-memory error occurr.
+ *
+ * For complete examples on how to plumb a notification ring, look into
+ * xenpaging or xen-access.
+ *
+ * On receipt of a notification, the helper should ensure there is memory
+ * available to the domain before retrying.
+ *
+ * If a domain encounters an ENOMEM condition when sharing and this ring
+ * has not been set up, the hypervisor will crash the domain.
+ *
+ * Fails with:
+ *  EINVAL if port is NULL
+ *  EINVAL if the sharing ring has already been enabled
+ *  ENOSYS if no guest gfn has been specified to host the ring via an hvm param
+ *  EINVAL if the gfn for the ring has not been populated
+ *  ENOENT if the gfn for the ring is paged out, or cannot be unshared
+ *  EINVAL if the gfn for the ring cannot be written to
+ *  EINVAL if the domain is dying
+ *  ENOSPC if an event channel cannot be allocated for the ring
+ *  ENOMEM if memory cannot be allocated for internal data structures
+ *  EINVAL or EACCESS if the request is denied by the security policy
+ */
+
+int xc_memshr_ring_enable(xc_interface *xch,
+                          uint32_t domid,
+                          uint32_t *port);
+/* Disable the ring for ENOMEM communication.
+ * May fail with EINVAL if the ring was not enabled in the first place.
+ */
+int xc_memshr_ring_disable(xc_interface *xch,
+                           uint32_t domid);
+
+/*
+ * Calls below return EINVAL if sharing has not been enabled for the domain
+ * Calls below return EINVAL if the domain is dying
+ */
+/* Once a reponse to an ENOMEM notification is prepared, the tool can
+ * notify the hypervisor to re-schedule the faulting vcpu of the domain with an
+ * event channel kick and/or this call. */
+int xc_memshr_domain_resume(xc_interface *xch,
+                            uint32_t domid);
+
+/* Select a page for sharing.
+ *
+ * A 64 bit opaque handle will be stored in handle.  The hypervisor ensures
+ * that if the page is modified, the handle will be invalidated, and future
+ * users of it will fail. If the page has already been selected and is still
+ * associated to a valid handle, the existing handle will be returned.
+ *
+ * May fail with:
+ *  EINVAL if the gfn is not populated or not sharable (mmio, etc)
+ *  ENOMEM if internal data structures cannot be allocated
+ *  E2BIG if the page is being referenced by other subsytems (e.g. qemu)
+ *  ENOENT or EEXIST if there are internal hypervisor errors.
+ */
+int xc_memshr_nominate_gfn(xc_interface *xch,
+                           uint32_t domid,
+                           unsigned long gfn,
+                           uint64_t *handle);
+/* Same as above, but instead of a guest frame number, the input is a grant
+ * reference provided by the guest.
+ *
+ * May fail with EINVAL if the grant reference is invalid.
+ */
+int xc_memshr_nominate_gref(xc_interface *xch,
+                            uint32_t domid,
+                            grant_ref_t gref,
+                            uint64_t *handle);
+
+/* The three calls below may fail with
+ * 10 (or -XENMEM_SHARING_OP_S_HANDLE_INVALID) if the handle passed as source
+ * is invalid.
+ * 9 (or -XENMEM_SHARING_OP_C_HANDLE_INVALID) if the handle passed as client is
+ * invalid.
+ */
+/* Share two nominated guest pages.
+ *
+ * If the call succeeds, both pages will point to the same backing frame (or
+ * mfn). The hypervisor will verify the handles are still valid, but it will
+ * not perform any sanity checking on the contens of the pages (the selection
+ * mechanism for sharing candidates is entirely up to the user-space tool).
+ *
+ * After successful sharing, the client handle becomes invalid. Both <domain,
+ * gfn> tuples point to the same mfn with the same handle, the one specified as
+ * source. Either 3-tuple can be specified later for further re-sharing.
+ */
+int xc_memshr_share_gfns(xc_interface *xch,
+                    uint32_t source_domain,
+                    unsigned long source_gfn,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    unsigned long client_gfn,
+                    uint64_t client_handle);
+
+/* Same as above, but share two grant references instead.
+ *
+ * May fail with EINVAL if either grant reference is invalid.
+ */
+int xc_memshr_share_grefs(xc_interface *xch,
+                    uint32_t source_domain,
+                    grant_ref_t source_gref,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    grant_ref_t client_gref,
+                    uint64_t client_handle);
+
+/* Allows to add to the guest physmap of the client domain a shared frame
+ * directly.
+ *
+ * May additionally fail with
+ *  9 (-XENMEM_SHARING_OP_C_HANDLE_INVALID) if the physmap entry for the gfn is
+ *  not suitable.
+ *  ENOMEM if internal data structures cannot be allocated.
+ *  ENOENT if there is an internal hypervisor error.
+ */
+int xc_memshr_add_to_physmap(xc_interface *xch,
+                    uint32_t source_domain,
+                    unsigned long source_gfn,
+                    uint64_t source_handle,
+                    uint32_t client_domain,
+                    unsigned long client_gfn);
+
+/* Allows to deduplicate a range of memory of a client domain. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns.
+ *
+ * May fail with -EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ * May also fail with -ENOMEM if there isn't enough memory available to store
+ * the sharing metadata before deduplication can happen.
+ */
+int xc_memshr_range_share(xc_interface *xch,
+                          uint32_t source_domain,
+                          uint32_t client_domain,
+                          uint64_t first_gfn,
+                          uint64_t last_gfn);
+
+int xc_memshr_fork(xc_interface *xch,
+                   uint32_t source_domain,
+                   uint32_t client_domain,
+                   bool allow_with_iommu,
+                   bool block_interrupts);
+
+/*
+ * Note: this function is only intended to be used on short-lived forks that
+ * haven't yet aquired a lot of memory. In case the fork has a lot of memory
+ * it is likely more performant to create a new fork with xc_memshr_fork.
+ *
+ * With VMs that have a lot of memory this call may block for a long time.
+ */
+int xc_memshr_fork_reset(xc_interface *xch, uint32_t forked_domain);
+
+/* Debug calls: return the number of pages referencing the shared frame backing
+ * the input argument. Should be one or greater.
+ *
+ * May fail with EINVAL if there is no backing shared frame for the input
+ * argument.
+ */
+int xc_memshr_debug_gfn(xc_interface *xch,
+                        uint32_t domid,
+                        unsigned long gfn);
+/* May additionally fail with EINVAL if the grant reference is invalid. */
+int xc_memshr_debug_gref(xc_interface *xch,
+                         uint32_t domid,
+                         grant_ref_t gref);
+
+/* Audits the share subsystem.
+ *
+ * Returns ENOSYS if not supported (may not be compiled into the hypervisor).
+ *
+ * Returns the number of errors found during auditing otherwise. May be (should
+ * be!) zero.
+ *
+ * If debugtrace support has been compiled into the hypervisor and is enabled,
+ * verbose descriptions for the errors are available in the hypervisor console.
+ */
+int xc_memshr_audit(xc_interface *xch);
+
+/* Stats reporting.
+ *
+ * At any point in time, the following equality should hold for a host:
+ *
+ *  Let dominfo(d) be the xc_dominfo_t struct filled by a call to
+ *  xc_domain_getinfo(d)
+ *
+ *  The summation of dominfo(d)->shr_pages for all domains in the system
+ *      should be equal to
+ *  xc_sharing_freed_pages + xc_sharing_used_frames
+ */
+/*
+ * This function returns the total number of pages freed by using sharing
+ * on the system.  For example, if two domains contain a single entry in
+ * their p2m table that points to the same shared page (and no other pages
+ * in the system are shared), then this function should return 1.
+ */
+long xc_sharing_freed_pages(xc_interface *xch);
+
+/*
+ * This function returns the total number of frames occupied by shared
+ * pages on the system.  This is independent of the number of domains
+ * pointing at these frames.  For example, in the above scenario this
+ * should return 1. (And dominfo(d) for each of the two domains should return 1
+ * as well).
+ *
+ * Note that some of these sharing_used_frames may be referenced by
+ * a single domain page, and thus not realize any savings. The same
+ * applies to some of the pages counted in dominfo(d)->shr_pages.
+ */
+long xc_sharing_used_frames(xc_interface *xch);
+/*** End sharing interface ***/
+
+int xc_flask_load(xc_interface *xc_handle, char *buf, uint32_t size);
+int xc_flask_context_to_sid(xc_interface *xc_handle, char *buf, uint32_t size, uint32_t *sid);
+int xc_flask_sid_to_context(xc_interface *xc_handle, int sid, char *buf, uint32_t size);
+int xc_flask_getenforce(xc_interface *xc_handle);
+int xc_flask_setenforce(xc_interface *xc_handle, int mode);
+int xc_flask_getbool_byid(xc_interface *xc_handle, int id, char *name, uint32_t size, int *curr, int *pend);
+int xc_flask_getbool_byname(xc_interface *xc_handle, char *name, int *curr, int *pend);
+int xc_flask_setbool(xc_interface *xc_handle, char *name, int value, int commit);
+int xc_flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext);
+int xc_flask_add_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high,
+                      char *scontext);
+int xc_flask_add_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high,
+                     char *scontext);
+int xc_flask_add_device(xc_interface *xc_handle, unsigned long device, char *scontext);
+int xc_flask_del_pirq(xc_interface *xc_handle, unsigned int pirq);
+int xc_flask_del_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high);
+int xc_flask_del_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high);
+int xc_flask_del_device(xc_interface *xc_handle, unsigned long device);
+int xc_flask_access(xc_interface *xc_handle, const char *scon, const char *tcon,
+                  uint16_t tclass, uint32_t req,
+                  uint32_t *allowed, uint32_t *decided,
+                  uint32_t *auditallow, uint32_t *auditdeny,
+                  uint32_t *seqno);
+int xc_flask_avc_cachestats(xc_interface *xc_handle, char *buf, int size);
+int xc_flask_policyvers(xc_interface *xc_handle);
+int xc_flask_avc_hashstats(xc_interface *xc_handle, char *buf, int size);
+int xc_flask_getavc_threshold(xc_interface *xc_handle);
+int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold);
+int xc_flask_relabel_domain(xc_interface *xch, uint32_t domid, uint32_t sid);
+
+struct elf_binary;
+void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
+                        int verbose);
+/* Useful for callers who also use libelf. */
+
+/*
+ * Execute an image previously loaded with xc_kexec_load().
+ *
+ * Does not return on success.
+ *
+ * Fails with:
+ *   ENOENT if the specified image has not been loaded.
+ */
+int xc_kexec_exec(xc_interface *xch, int type);
+
+/*
+ * Find the machine address and size of certain memory areas.
+ *
+ *   KEXEC_RANGE_MA_CRASH       crash area
+ *   KEXEC_RANGE_MA_XEN         Xen itself
+ *   KEXEC_RANGE_MA_CPU         CPU note for CPU number 'nr'
+ *   KEXEC_RANGE_MA_XENHEAP     xenheap
+ *   KEXEC_RANGE_MA_EFI_MEMMAP  EFI Memory Map
+ *   KEXEC_RANGE_MA_VMCOREINFO  vmcoreinfo
+ *
+ * Fails with:
+ *   EINVAL if the range or CPU number isn't valid.
+ */
+int xc_kexec_get_range(xc_interface *xch, int range,  int nr,
+                       uint64_t *size, uint64_t *start);
+
+/*
+ * Load a kexec image into memory.
+ *
+ * The image may be of type KEXEC_TYPE_DEFAULT (executed on request)
+ * or KEXEC_TYPE_CRASH (executed on a crash).
+ *
+ * The image architecture may be a 32-bit variant of the hypervisor
+ * architecture (e.g, EM_386 on a x86-64 hypervisor).
+ *
+ * Fails with:
+ *   ENOMEM if there is insufficient memory for the new image.
+ *   EINVAL if the image does not fit into the crash area or the entry
+ *          point isn't within one of segments.
+ *   EBUSY  if another image is being executed.
+ */
+int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch,
+                  uint64_t entry_maddr,
+                  uint32_t nr_segments, xen_kexec_segment_t *segments);
+
+/*
+ * Unload a kexec image.
+ *
+ * This prevents a KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH image from
+ * being executed.  The crash images are not cleared from the crash
+ * region.
+ */
+int xc_kexec_unload(xc_interface *xch, int type);
+
+/*
+ * Find out whether the image has been succesfully loaded.
+ *
+ * The type can be either KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
+ * If zero is returned, that means no image is loaded for the type.
+ * If one is returned, that means an image is loaded for the type.
+ * Otherwise, negative return value indicates error.
+ */
+int xc_kexec_status(xc_interface *xch, int type);
+
+typedef xenpf_resource_entry_t xc_resource_entry_t;
+
+/*
+ * Generic resource operation which contains multiple non-preemptible
+ * resource access entries that passed to xc_resource_op().
+ */
+struct xc_resource_op {
+    uint64_t result;        /* on return, check this field first */
+    uint32_t cpu;           /* which cpu to run */
+    uint32_t nr_entries;    /* number of resource entries */
+    xc_resource_entry_t *entries;
+};
+
+typedef struct xc_resource_op xc_resource_op_t;
+int xc_resource_op(xc_interface *xch, uint32_t nr_ops, xc_resource_op_t *ops);
+
+#if defined(__i386__) || defined(__x86_64__)
+enum xc_psr_cmt_type {
+    XC_PSR_CMT_L3_OCCUPANCY,
+    XC_PSR_CMT_TOTAL_MEM_COUNT,
+    XC_PSR_CMT_LOCAL_MEM_COUNT,
+};
+typedef enum xc_psr_cmt_type xc_psr_cmt_type;
+
+enum xc_psr_type {
+    XC_PSR_CAT_L3_CBM      = 1,
+    XC_PSR_CAT_L3_CBM_CODE = 2,
+    XC_PSR_CAT_L3_CBM_DATA = 3,
+    XC_PSR_CAT_L2_CBM      = 4,
+    XC_PSR_MBA_THRTL       = 5,
+};
+typedef enum xc_psr_type xc_psr_type;
+
+enum xc_psr_feat_type {
+    XC_PSR_CAT_L3,
+    XC_PSR_CAT_L2,
+    XC_PSR_MBA,
+};
+typedef enum xc_psr_feat_type xc_psr_feat_type;
+
+union xc_psr_hw_info {
+    struct {
+        uint32_t cos_max;
+        uint32_t cbm_len;
+        bool     cdp_enabled;
+    } cat;
+
+    struct {
+        uint32_t cos_max;
+        uint32_t thrtl_max;
+        bool     linear;
+    } mba;
+};
+typedef union xc_psr_hw_info xc_psr_hw_info;
+
+int xc_psr_cmt_attach(xc_interface *xch, uint32_t domid);
+int xc_psr_cmt_detach(xc_interface *xch, uint32_t domid);
+int xc_psr_cmt_get_domain_rmid(xc_interface *xch, uint32_t domid,
+                               uint32_t *rmid);
+int xc_psr_cmt_get_total_rmid(xc_interface *xch, uint32_t *total_rmid);
+int xc_psr_cmt_get_l3_upscaling_factor(xc_interface *xch,
+                                       uint32_t *upscaling_factor);
+int xc_psr_cmt_get_l3_event_mask(xc_interface *xch, uint32_t *event_mask);
+int xc_psr_cmt_get_l3_cache_size(xc_interface *xch, uint32_t cpu,
+                                 uint32_t *l3_cache_size);
+int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu,
+                        uint32_t psr_cmt_type, uint64_t *monitor_data,
+                        uint64_t *tsc);
+int xc_psr_cmt_enabled(xc_interface *xch);
+
+int xc_psr_set_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_type type, uint32_t target,
+                           uint64_t data);
+int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_type type, uint32_t target,
+                           uint64_t *data);
+int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket,
+                       xc_psr_feat_type type, xc_psr_hw_info *hw_info);
+
+int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
+int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
+                          uint32_t *nr_features, uint32_t *featureset);
+
+int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
+                           uint32_t *nr_msrs);
+int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs);
+int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs);
+int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
+                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
+                             uint32_t *err_msr_p);
+
+uint32_t xc_get_cpu_featureset_size(void);
+
+enum xc_static_cpu_featuremask {
+    XC_FEATUREMASK_KNOWN,
+    XC_FEATUREMASK_SPECIAL,
+    XC_FEATUREMASK_PV_MAX,
+    XC_FEATUREMASK_PV_DEF,
+    XC_FEATUREMASK_HVM_SHADOW_MAX,
+    XC_FEATUREMASK_HVM_SHADOW_DEF,
+    XC_FEATUREMASK_HVM_HAP_MAX,
+    XC_FEATUREMASK_HVM_HAP_DEF,
+};
+const uint32_t *xc_get_static_cpu_featuremask(enum xc_static_cpu_featuremask);
+
+#endif
+
+int xc_livepatch_upload(xc_interface *xch,
+                        char *name, unsigned char *payload, uint32_t size);
+
+int xc_livepatch_get(xc_interface *xch,
+                     char *name,
+                     xen_livepatch_status_t *status);
+
+/*
+ * Get a number of available payloads and get actual total size of
+ * the payloads' name and metadata arrays.
+ *
+ * This functions is typically executed first before the xc_livepatch_list()
+ * to obtain the sizes and correctly allocate all necessary data resources.
+ *
+ * The return value is zero if the hypercall completed successfully.
+ *
+ * If there was an error performing the sysctl operation, the return value
+ * will contain the hypercall error code value.
+ */
+int xc_livepatch_list_get_sizes(xc_interface *xch, unsigned int *nr,
+                                uint32_t *name_total_size,
+                                uint32_t *metadata_total_size);
+
+/*
+ * The heart of this function is to get an array of the following objects:
+ *   - xen_livepatch_status_t: states and return codes of payloads
+ *   - name: names of payloads
+ *   - len: lengths of corresponding payloads' names
+ *   - metadata: payloads' metadata
+ *   - metadata_len: lengths of corresponding payloads' metadata
+ *
+ * However it is complex because it has to deal with the hypervisor
+ * returning some of the requested data or data being stale
+ * (another hypercall might alter the list).
+ *
+ * The parameters that the function expects to contain data from
+ * the hypervisor are: 'info', 'name', and 'len'. The 'done' and
+ * 'left' are also updated with the number of entries filled out
+ * and respectively the number of entries left to get from hypervisor.
+ *
+ * It is expected that the caller of this function will first issue the
+ * xc_livepatch_list_get_sizes() in order to obtain total sizes of names
+ * and all metadata as well as the current number of payload entries.
+ * The total sizes are required and supplied via the 'name_total_size' and
+ * 'metadata_total_size' parameters.
+ *
+ * The 'max' is to be provided by the caller with the maximum number of
+ * entries that 'info', 'name', 'len', 'metadata' and 'metadata_len' arrays
+ * can be filled up with.
+ *
+ * Each entry in the 'info' array is expected to be of xen_livepatch_status_t
+ * structure size.
+ *
+ * Each entry in the 'name' array may have an arbitrary size.
+ *
+ * Each entry in the 'len' array is expected to be of uint32_t size.
+ *
+ * Each entry in the 'metadata' array may have an arbitrary size.
+ *
+ * Each entry in the 'metadata_len' array is expected to be of uint32_t size.
+ *
+ * The return value is zero if the hypercall completed successfully.
+ * Note that the return value is _not_ the amount of entries filled
+ * out - that is saved in 'done'.
+ *
+ * If there was an error performing the operation, the return value
+ * will contain an negative -EXX type value. The 'done' and 'left'
+ * will contain the number of entries that had been succesfully
+ * retrieved (if any).
+ */
+int xc_livepatch_list(xc_interface *xch, const unsigned int max,
+                      const unsigned int start,
+                      struct xen_livepatch_status *info,
+                      char *name, uint32_t *len,
+                      const uint32_t name_total_size,
+                      char *metadata, uint32_t *metadata_len,
+                      const uint32_t metadata_total_size,
+                      unsigned int *done, unsigned int *left);
+
+/*
+ * The operations are asynchronous and the hypervisor may take a while
+ * to complete them. The `timeout` offers an option to expire the
+ * operation if it could not be completed within the specified time
+ * (in ns). Value of 0 means let hypervisor decide the best timeout.
+ * The `flags` allows to pass extra parameters to the actions.
+ */
+int xc_livepatch_apply(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags);
+


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMLh-0006Pt-VK; Fri, 18 Sep 2020 19:47:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMLg-0006Pj-CC
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:12 +0000
X-Inumbo-ID: 3e50fd98-4169-4e94-9b3e-4a67753900ca
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3e50fd98-4169-4e94-9b3e-4a67753900ca;
 Fri, 18 Sep 2020 19:47:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=1cD5SinPZ2JlIf0fOVvO80sj6HhBA5UbrVEZclGyhzA=; b=jI/cgMmkiZ4RN3EWt/g5pmiVav
 opxIfHSHBetWwBFCzIH8wHjvYRkeqZ44yNqmz6IK1aDRKOXobG5Ni6AIXeo09D0vPvpiqN48Fzn73
 F9L415p/TfbqYkmpSdeDwZDZg29qs0ETY1Ft10yN18vD2vNYbtG41Bujqh4HQ6zv6yqQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLZ-00078W-JL
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLZ-0004Qo-IU
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxc: move libxenguest to tools/libs/guest
Message-Id: <E1kJMLZ-0004Qo-IU@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e3dd624e487c1aca1835138d3990f78af9906238
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:35 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxc: move libxenguest to tools/libs/guest
    
    tools/libxc now contains libxenguest only. Move it to tools/libs/guest.
    
    When generating the pkg-config file for libxenguest a filter is now
    required for replacing "xenctrl" by "xencontrol" in the
    "Requires.private:" entry. Add this filter to tools/libs/libs.mk.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> (stubdom parts)
---
 .gitignore                                        |   16 +-
 stubdom/Makefile                                  |   34 +-
 stubdom/grub/Makefile                             |    2 +-
 stubdom/mini-os.mk                                |    2 +-
 tools/Makefile                                    |    3 +-
 tools/Rules.mk                                    |    7 +-
 tools/libs/Makefile                               |    1 +
 tools/libs/guest/COPYING                          |  467 +++++
 tools/libs/guest/Makefile                         |  121 ++
 tools/libs/guest/include/xenguest.h               |  327 ++++
 tools/libs/guest/xg_cpuid_x86.c                   |  665 +++++++
 tools/libs/guest/xg_dom_arm.c                     |  552 ++++++
 tools/libs/guest/xg_dom_armzimageloader.c         |  271 +++
 tools/libs/guest/xg_dom_binloader.c               |  329 ++++
 tools/libs/guest/xg_dom_boot.c                    |  451 +++++
 tools/libs/guest/xg_dom_bzimageloader.c           |  812 +++++++++
 tools/libs/guest/xg_dom_compat_linux.c            |   97 +
 tools/libs/guest/xg_dom_core.c                    | 1272 ++++++++++++++
 tools/libs/guest/xg_dom_decompress.h              |    8 +
 tools/libs/guest/xg_dom_decompress_lz4.c          |  141 ++
 tools/libs/guest/xg_dom_decompress_unsafe.c       |   48 +
 tools/libs/guest/xg_dom_decompress_unsafe.h       |   20 +
 tools/libs/guest/xg_dom_decompress_unsafe_bzip2.c |   14 +
 tools/libs/guest/xg_dom_decompress_unsafe_lzma.c  |   14 +
 tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c |   50 +
 tools/libs/guest/xg_dom_decompress_unsafe_xz.c    |   46 +
 tools/libs/guest/xg_dom_elfloader.c               |  249 +++
 tools/libs/guest/xg_dom_hvmloader.c               |  264 +++
 tools/libs/guest/xg_dom_x86.c                     | 1945 +++++++++++++++++++++
 tools/libs/guest/xg_domain.c                      |  149 ++
 tools/libs/guest/xg_nomigrate.c                   |   50 +
 tools/libs/guest/xg_offline_page.c                |  708 ++++++++
 tools/libs/guest/xg_private.c                     |  198 +++
 tools/libs/guest/xg_private.h                     |  124 ++
 tools/libs/guest/xg_save_restore.h                |  134 ++
 tools/libs/guest/xg_sr_common.c                   |  167 ++
 tools/libs/guest/xg_sr_common.h                   |  468 +++++
 tools/libs/guest/xg_sr_common_x86.c               |  173 ++
 tools/libs/guest/xg_sr_common_x86.h               |   51 +
 tools/libs/guest/xg_sr_common_x86_pv.c            |  193 ++
 tools/libs/guest/xg_sr_common_x86_pv.h            |  109 ++
 tools/libs/guest/xg_sr_restore.c                  |  986 +++++++++++
 tools/libs/guest/xg_sr_restore_x86_hvm.c          |  274 +++
 tools/libs/guest/xg_sr_restore_x86_pv.c           | 1210 +++++++++++++
 tools/libs/guest/xg_sr_save.c                     | 1059 +++++++++++
 tools/libs/guest/xg_sr_save_x86_hvm.c             |  251 +++
 tools/libs/guest/xg_sr_save_x86_pv.c              | 1156 ++++++++++++
 tools/libs/guest/xg_sr_stream_format.h            |  150 ++
 tools/libs/guest/xg_suspend.c                     |  202 +++
 tools/libs/libs.mk                                |    2 +-
 tools/libs/uselibs.mk                             |    2 +
 tools/libxc/COPYING                               |  467 -----
 tools/libxc/Makefile                              |  219 ---
 tools/libxc/include/xenguest.h                    |  327 ----
 tools/libxc/xg_cpuid_x86.c                        |  665 -------
 tools/libxc/xg_dom_arm.c                          |  552 ------
 tools/libxc/xg_dom_armzimageloader.c              |  271 ---
 tools/libxc/xg_dom_binloader.c                    |  329 ----
 tools/libxc/xg_dom_boot.c                         |  451 -----
 tools/libxc/xg_dom_bzimageloader.c                |  812 ---------
 tools/libxc/xg_dom_compat_linux.c                 |   97 -
 tools/libxc/xg_dom_core.c                         | 1272 --------------
 tools/libxc/xg_dom_decompress.h                   |    8 -
 tools/libxc/xg_dom_decompress_lz4.c               |  141 --
 tools/libxc/xg_dom_decompress_unsafe.c            |   48 -
 tools/libxc/xg_dom_decompress_unsafe.h            |   20 -
 tools/libxc/xg_dom_decompress_unsafe_bzip2.c      |   14 -
 tools/libxc/xg_dom_decompress_unsafe_lzma.c       |   14 -
 tools/libxc/xg_dom_decompress_unsafe_lzo1x.c      |   50 -
 tools/libxc/xg_dom_decompress_unsafe_xz.c         |   46 -
 tools/libxc/xg_dom_elfloader.c                    |  249 ---
 tools/libxc/xg_dom_hvmloader.c                    |  264 ---
 tools/libxc/xg_dom_x86.c                          | 1945 ---------------------
 tools/libxc/xg_domain.c                           |  149 --
 tools/libxc/xg_nomigrate.c                        |   50 -
 tools/libxc/xg_offline_page.c                     |  708 --------
 tools/libxc/xg_private.c                          |  198 ---
 tools/libxc/xg_private.h                          |  124 --
 tools/libxc/xg_save_restore.h                     |  134 --
 tools/libxc/xg_sr_common.c                        |  167 --
 tools/libxc/xg_sr_common.h                        |  468 -----
 tools/libxc/xg_sr_common_x86.c                    |  173 --
 tools/libxc/xg_sr_common_x86.h                    |   51 -
 tools/libxc/xg_sr_common_x86_pv.c                 |  193 --
 tools/libxc/xg_sr_common_x86_pv.h                 |  109 --
 tools/libxc/xg_sr_restore.c                       |  986 -----------
 tools/libxc/xg_sr_restore_x86_hvm.c               |  274 ---
 tools/libxc/xg_sr_restore_x86_pv.c                | 1210 -------------
 tools/libxc/xg_sr_save.c                          | 1059 -----------
 tools/libxc/xg_sr_save_x86_hvm.c                  |  251 ---
 tools/libxc/xg_sr_save_x86_pv.c                   | 1156 ------------
 tools/libxc/xg_sr_stream_format.h                 |  150 --
 tools/libxc/xg_suspend.c                          |  202 ---
 93 files changed, 16002 insertions(+), 16115 deletions(-)

diff --git a/.gitignore b/.gitignore
index d22b031ed2..eb637a98e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,7 +71,6 @@ stubdom/include
 stubdom/ioemu
 stubdom/ioemu/
 stubdom/libs-*
-stubdom/libxc-*
 stubdom/libxencall-*
 stubdom/libxenevtchn-*
 stubdom/libxenforeignmemory-*
@@ -121,6 +120,14 @@ tools/libs/foreignmemory/headers.chk
 tools/libs/foreignmemory/xenforeignmemory.pc
 tools/libs/devicemodel/headers.chk
 tools/libs/devicemodel/xendevicemodel.pc
+tools/libs/guest/_*.[ch]
+tools/libs/guest/libxenguest.map
+tools/libs/guest/xenguest.pc
+tools/libs/guest/xc_bitops.h
+tools/libs/guest/xc_core.h
+tools/libs/guest/xc_core_arm.h
+tools/libs/guest/xc_core_x86.h
+tools/libs/guest/xc_private.h
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -197,12 +204,6 @@ tools/include/xen-xsm/*
 tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
 tools/libvchan/xenvchan.pc
-tools/libxc/*.pc
-tools/libxc/xc_bitops.h
-tools/libxc/xc_core.h
-tools/libxc/xc_core_arm.h
-tools/libxc/xc_core_x86.h
-tools/libxc/xc_private.h
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
@@ -370,7 +371,6 @@ tools/include/xen-foreign/arm64.h
 tools/misc/xen-hptool
 tools/misc/xen-mfndump
 tools/libs/toolcore/include/_*.h
-tools/libxc/_*.[ch]
 tools/libxl/_*.[ch]
 tools/libxl/testidl
 tools/libxl/testidl.c
diff --git a/stubdom/Makefile b/stubdom/Makefile
index 6c481285ec..fb9617fa14 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -331,7 +331,9 @@ endif
 # libraries under tools/libs
 #######
 
-STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl
+STUB_LIBS := toolcore toollog evtchn gnttab call foreignmemory devicemodel ctrl guest
+
+LIBDEP_guest := cross-zlib
 
 #######
 # common handling
@@ -362,13 +364,10 @@ endef
 
 $(foreach lib,$(STUB_LIBS),$(eval $(call BUILD_lib,$(lib))))
 
-libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
-	$(do_links)
-
 xenstore/stamp: $(XEN_ROOT)/tools/xenstore/Makefile
 	$(do_links)
 
-LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(STUB_LIBS),libs-$(XEN_TARGET_ARCH)/$(dir))
+LINK_DIRS := xenstore $(foreach dir,$(STUB_LIBS),libs-$(XEN_TARGET_ARCH)/$(dir))
 LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp)
 
 mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) $(LINK_STAMPS)
@@ -391,16 +390,6 @@ $(TARGETS_MINIOS): mini-os-%:
                 mkdir -p $@/$$i ; \
 	done
 
-#######
-# libxc
-#######
-
-.PHONY: libxc
-libxc: libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxenevtchn libxenctrl cross-zlib
-libxc-$(XEN_TARGET_ARCH)/libxenguest.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
-
 #######
 # ioemu
 #######
@@ -409,7 +398,7 @@ ioemu-minios-config.mk: $(CURDIR)/ioemu-minios.cfg
 	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
 
 .PHONY: ioemu
-ioemu: cross-zlib cross-libpci libxc ioemu-minios-config.mk
+ioemu: cross-zlib cross-libpci libxenguest ioemu-minios-config.mk
 	[ -f ioemu/config-host.mak ] || \
 	  ( $(buildmakevars2shellvars); \
 	    cd ioemu ; \
@@ -503,15 +492,15 @@ xenstore: $(CROSS_ROOT) xenstore-minios-config.mk
 
 .PHONY: ioemu-stubdom
 ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
-ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
+ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxenguest ioemu
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/ioemu-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
 
 .PHONY: caml-stubdom
-caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc cross-ocaml caml
+caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxenguest cross-ocaml caml
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/caml/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
 
 .PHONY: c-stubdom
-c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
+c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxenguest c
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/c/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
 
 .PHONY: vtpm-stubdom
@@ -523,11 +512,11 @@ vtpmmgr-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpmmgr vtpmmgr
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpmmgr/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpmmgr/vtpmmgr.a" APP_LDLIBS="-lm -lpolarssl"
 
 .PHONY: pv-grub
-pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
+pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxenguest grub
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/grub/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
 
 .PHONY: xenstore-stubdom
-xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
+xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxenguest xenstore
 	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/xenstore-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/xenstore/xenstored.a
 
 #########
@@ -621,7 +610,6 @@ clean:
 	rm -f $(STUBDOMPATH)
 	rm -f *-minios-config.mk
 	rm -fr pkg-config
-	[ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
 	-[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
 	-[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
 
@@ -632,7 +620,7 @@ crossclean: clean
 	rm -fr newlib-$(XEN_TARGET_ARCH)
 	rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
 	rm -fr libs-$(XEN_TARGET_ARCH)
-	rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
+	rm -fr ioemu xenstore
 	rm -fr gmp-$(XEN_TARGET_ARCH)
 	rm -fr polarssl-$(XEN_TARGET_ARCH)
 	rm -fr openssl-$(XEN_TARGET_ARCH)
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
index d33fa2f71e..7397661c9b 100644
--- a/stubdom/grub/Makefile
+++ b/stubdom/grub/Makefile
@@ -7,7 +7,7 @@ BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/ctrl/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/guest/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index b1387df3f8..e1640a7cbc 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -14,4 +14,4 @@ CALL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call
 FOREIGNMEMORY_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory
 DEVICEMODEL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/devicemodel
 CTRL_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/ctrl
-GUEST_PATH = $(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH)
+GUEST_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/guest
diff --git a/tools/Makefile b/tools/Makefile
index 7c9f9fc900..f9b4012290 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -6,7 +6,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += libs
-SUBDIRS-y += libxc
 SUBDIRS-y += flask
 SUBDIRS-y += fuzz
 SUBDIRS-y += xenstore
@@ -44,7 +43,7 @@ SUBDIRS-y += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 
 ifeq ($(CONFIG_RUMP),y)
-SUBDIRS-y := libs libxc xenstore
+SUBDIRS-y := libs xenstore
 endif
 
 # For the sake of linking, set the sys-root
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 35940cb338..e17ac3ecc6 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -15,7 +15,6 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 
 include $(XEN_ROOT)/tools/libs/uselibs.mk
 
-XEN_libxenguest    = $(XEN_ROOT)/tools/libxc
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
@@ -105,11 +104,7 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
 CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
-
-CFLAGS_libxenguest = -I$(XEN_libxenguest)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
-SHDEPS_libxenguest = $(SHLIB_libxenevtchn) $(SHLIB_libxenctrl)
-LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_libxenguest)/libxenguest$(libextension)
-SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_libxenguest)
+CFLAGS_libxenguest += $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory)
 
 CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 7648ea0e4c..f15c1688f7 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -10,6 +10,7 @@ SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
 SUBDIRS-y += devicemodel
 SUBDIRS-y += ctrl
+SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/guest/COPYING b/tools/libs/guest/COPYING
new file mode 100644
index 0000000000..7ca8702509
--- /dev/null
+++ b/tools/libs/guest/COPYING
@@ -0,0 +1,467 @@
+Note that the only valid version of the LGPL as far as the files in
+this directory (and its subdirectories) are concerned is _this_
+particular version of the license (i.e., *only* v2.1, not v2.2 or v3.x
+or whatever), unless explicitly otherwise stated.
+
+Where clause 3 is invoked in order to relicense under the GPL then
+this shall be considered to be GPL v2 only for files which have
+specified LGPL v2.1 only.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile
new file mode 100644
index 0000000000..e53aeabd3e
--- /dev/null
+++ b/tools/libs/guest/Makefile
@@ -0,0 +1,121 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+ifeq ($(CONFIG_LIBXC_MINIOS),y)
+# Save/restore of a domain is currently incompatible with a stubdom environment
+override CONFIG_MIGRATE := n
+endif
+
+LINK_FILES := xc_private.h xc_core.h xc_core_x86.h xc_core_arm.h xc_bitops.h
+
+$(LINK_FILES):
+	ln -sf $(XEN_ROOT)/tools/libs/ctrl/$(notdir $@) $@
+
+SRCS-y += xg_private.c
+SRCS-y += xg_domain.c
+SRCS-y += xg_suspend.c
+ifeq ($(CONFIG_MIGRATE),y)
+SRCS-y += xg_sr_common.c
+SRCS-$(CONFIG_X86) += xg_sr_common_x86.c
+SRCS-$(CONFIG_X86) += xg_sr_common_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_restore_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_restore_x86_hvm.c
+SRCS-$(CONFIG_X86) += xg_sr_save_x86_pv.c
+SRCS-$(CONFIG_X86) += xg_sr_save_x86_hvm.c
+SRCS-y += xg_sr_restore.c
+SRCS-y += xg_sr_save.c
+SRCS-y += xg_offline_page.c
+else
+SRCS-y += xg_nomigrate.c
+endif
+
+vpath %.c ../../../xen/common/libelf
+CFLAGS += -I../../../xen/common/libelf
+
+ELF_SRCS-y += libelf-tools.c libelf-loader.c
+ELF_SRCS-y += libelf-dominfo.c
+
+SRCS-y += $(ELF_SRCS-y)
+
+$(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
+$(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
+
+ifeq ($(CONFIG_X86),y) # Add libx86 to the build
+vpath %.c ../../../xen/lib/x86
+
+SRCS-y                 += cpuid.c msr.c
+endif
+
+# new domain builder
+SRCS-y                 += xg_dom_core.c
+SRCS-y                 += xg_dom_boot.c
+SRCS-y                 += xg_dom_elfloader.c
+SRCS-$(CONFIG_X86)     += xg_dom_bzimageloader.c
+SRCS-$(CONFIG_X86)     += xg_dom_decompress_lz4.c
+SRCS-$(CONFIG_X86)     += xg_dom_hvmloader.c
+SRCS-$(CONFIG_ARM)     += xg_dom_armzimageloader.c
+SRCS-y                 += xg_dom_binloader.c
+SRCS-y                 += xg_dom_compat_linux.c
+
+SRCS-$(CONFIG_X86)     += xg_dom_x86.c
+SRCS-$(CONFIG_X86)     += xg_cpuid_x86.c
+SRCS-$(CONFIG_ARM)     += xg_dom_arm.c
+
+ifeq ($(CONFIG_LIBXC_MINIOS),y)
+SRCS-y                 += xg_dom_decompress_unsafe.c
+SRCS-y                 += xg_dom_decompress_unsafe_bzip2.c
+SRCS-y                 += xg_dom_decompress_unsafe_lzma.c
+SRCS-y                 += xg_dom_decompress_unsafe_lzo1x.c
+SRCS-y                 += xg_dom_decompress_unsafe_xz.c
+endif
+
+-include $(XEN_TARGET_ARCH)/Makefile
+
+CFLAGS   += -Werror -Wmissing-prototypes
+CFLAGS   += -I. -I./include $(CFLAGS_xeninclude)
+CFLAGS   += -D__XEN_TOOLS__
+CFLAGS   += -include $(XEN_ROOT)/tools/config.h
+
+# Needed for posix_fadvise64() in xc_linux.c
+CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
+
+CFLAGS	+= $(PTHREAD_CFLAGS)
+CFLAGS	+= $(CFLAGS_libxentoollog)
+CFLAGS	+= $(CFLAGS_libxenevtchn)
+CFLAGS	+= $(CFLAGS_libxendevicemodel)
+
+# libxenguest includes xc_private.h, so needs this despite not using
+# this functionality directly.
+CFLAGS += $(CFLAGS_libxencall) $(CFLAGS_libxenforeignmemory)
+
+ifeq ($(CONFIG_MiniOS),y)
+zlib-options =
+else
+zlib-options = $(ZLIB)
+endif
+
+xc_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
+xc_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
+
+LIBHEADER := xenguest.h
+
+NO_HEADERS_CHK := y
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(filter -l%,$(zlib-options))
+libxenguest.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += $(COMPRESSION_LIBS) -lz
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
+
+xc_private.h: _paths.h
+
+$(LIB_OBJS) $(PIC_OBJS): $(LINK_FILES)
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenctrl)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenguest.map
diff --git a/tools/libs/guest/include/xenguest.h b/tools/libs/guest/include/xenguest.h
new file mode 100644
index 0000000000..4643384790
--- /dev/null
+++ b/tools/libs/guest/include/xenguest.h
@@ -0,0 +1,327 @@
+/******************************************************************************
+ * xenguest.h
+ *
+ * A library for guest domain management in Xen.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef XENGUEST_H
+#define XENGUEST_H
+
+#include <xenctrl_dom.h>
+
+#define XC_NUMA_NO_NODE   (~0U)
+
+#define XCFLAGS_LIVE      (1 << 0)
+#define XCFLAGS_DEBUG     (1 << 1)
+
+#define X86_64_B_SIZE   64 
+#define X86_32_B_SIZE   32
+
+/*
+ * User not using xc_suspend_* / xc_await_suspent may not want to
+ * include the full libxenevtchn API here.
+ */
+struct xenevtchn_handle;
+
+/* For save's precopy_policy(). */
+struct precopy_stats
+{
+    unsigned int iteration;
+    unsigned int total_written;
+    long dirty_count; /* -1 if unknown */
+};
+
+/*
+ * A precopy_policy callback may not be running in the same address
+ * space as libxc an so precopy_stats is passed by value.
+ */
+typedef int (*precopy_policy_t)(struct precopy_stats, void *);
+
+/* callbacks provided by xc_domain_save */
+struct save_callbacks {
+    /*
+     * Called after expiration of checkpoint interval,
+     * to suspend the guest.
+     */
+    int (*suspend)(void *data);
+
+    /*
+     * Called before and after every batch of page data sent during
+     * the precopy phase of a live migration to ask the caller what
+     * to do next based on the current state of the precopy migration.
+     *
+     * Should return one of the values listed below:
+     */
+#define XGS_POLICY_ABORT          (-1) /* Abandon the migration entirely
+                                        * and tidy up. */
+#define XGS_POLICY_CONTINUE_PRECOPY 0  /* Remain in the precopy phase. */
+#define XGS_POLICY_STOP_AND_COPY    1  /* Immediately suspend and transmit the
+                                        * remaining dirty pages. */
+    precopy_policy_t precopy_policy;
+
+    /*
+     * Called after the guest's dirty pages have been
+     *  copied into an output buffer.
+     * Callback function resumes the guest & the device model,
+     *  returns to xc_domain_save.
+     * xc_domain_save then flushes the output buffer, while the
+     *  guest continues to run.
+     */
+    int (*postcopy)(void *data);
+
+    /*
+     * Called after the memory checkpoint has been flushed
+     * out into the network. Typical actions performed in this
+     * callback include:
+     *   (a) send the saved device model state (for HVM guests),
+     *   (b) wait for checkpoint ack
+     *   (c) release the network output buffer pertaining to the acked checkpoint.
+     *   (c) sleep for the checkpoint interval.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*checkpoint)(void *data);
+
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*wait_checkpoint)(void *data);
+
+    /* Enable qemu-dm logging dirty pages to xen */
+    int (*switch_qemu_logdirty)(uint32_t domid, unsigned enable, void *data); /* HVM only */
+
+    /* to be provided as the last argument to each callback function */
+    void *data;
+};
+
+/* Type of stream.  Plain, or using a continuous replication protocol? */
+typedef enum {
+    XC_STREAM_PLAIN,
+    XC_STREAM_REMUS,
+    XC_STREAM_COLO,
+} xc_stream_type_t;
+
+/**
+ * This function will save a running domain.
+ *
+ * @param xch a handle to an open hypervisor interface
+ * @param io_fd the file descriptor to save a domain to
+ * @param dom the id of the domain
+ * @param flags XCFLAGS_xxx
+ * @param stream_type XC_STREAM_PLAIN if the far end of the stream
+ *        doesn't use checkpointing
+ * @param recv_fd Only used for XC_STREAM_COLO.  Contains backchannel from
+ *        the destination side.
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   uint32_t flags, struct save_callbacks *callbacks,
+                   xc_stream_type_t stream_type, int recv_fd);
+
+/* callbacks provided by xc_domain_restore */
+struct restore_callbacks {
+    /*
+     * Called once the STATIC_DATA_END record has been received/inferred.
+     *
+     * For compatibility with older streams, provides a list of static data
+     * expected to be found in the stream, which was missing.  A higher level
+     * toolstack is responsible for providing any necessary compatibiltiy.
+     */
+#define XGR_SDD_MISSING_CPUID (1 << 0)
+#define XGR_SDD_MISSING_MSR   (1 << 1)
+    int (*static_data_done)(unsigned int missing, void *data);
+
+    /* Called after a new checkpoint to suspend the guest. */
+    int (*suspend)(void *data);
+
+    /*
+     * Called after the secondary vm is ready to resume.
+     * Callback function resumes the guest & the device model,
+     * returns to xc_domain_restore.
+     */
+    int (*postcopy)(void *data);
+
+    /*
+     * A checkpoint record has been found in the stream.
+     * returns:
+     */
+#define XGR_CHECKPOINT_ERROR    0 /* Terminate processing */
+#define XGR_CHECKPOINT_SUCCESS  1 /* Continue reading more data from the stream */
+#define XGR_CHECKPOINT_FAILOVER 2 /* Failover and resume VM */
+    int (*checkpoint)(void *data);
+
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*wait_checkpoint)(void *data);
+
+    /*
+     * callback to send store gfn and console gfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(xen_pfn_t store_gfn, xen_pfn_t console_gfn,
+                            void *data);
+
+    /* to be provided as the last argument to each callback function */
+    void *data;
+};
+
+/**
+ * This function will restore a saved domain.
+ *
+ * Domain is restored in a suspended state ready to be unpaused.
+ *
+ * @param xch a handle to an open hypervisor interface
+ * @param io_fd the file descriptor to restore a domain from
+ * @param dom the id of the domain
+ * @param store_evtchn the xenstore event channel for this domain to use
+ * @param store_mfn filled with the gfn of the store page
+ * @param store_domid the backend domain for xenstore
+ * @param console_evtchn the console event channel for this domain to use
+ * @param console_mfn filled with the gfn of the console page
+ * @param console_domid the backend domain for xenconsole
+ * @param stream_type XC_STREAM_PLAIN if the far end of the stream is using
+ *        checkpointing
+ * @param callbacks non-NULL to receive a callback to restore toolstack
+ *        specific data
+ * @param send_back_fd Only used for XC_STREAM_COLO.  Contains backchannel to
+ *        the source side.
+ * @return 0 on success, -1 on failure
+ */
+int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
+                      unsigned int store_evtchn, unsigned long *store_mfn,
+                      uint32_t store_domid, unsigned int console_evtchn,
+                      unsigned long *console_mfn, uint32_t console_domid,
+                      xc_stream_type_t stream_type,
+                      struct restore_callbacks *callbacks, int send_back_fd);
+
+/**
+ * This function will create a domain for a paravirtualized Linux
+ * using file names pointing to kernel and ramdisk
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the id of the domain
+ * @parm mem_mb memory size in megabytes
+ * @parm image_name name of the kernel image file
+ * @parm ramdisk_name name of the ramdisk image file
+ * @parm cmdline command line string
+ * @parm flags domain creation flags
+ * @parm store_evtchn the store event channel for this domain to use
+ * @parm store_mfn returned with the mfn of the store page
+ * @parm console_evtchn the console event channel for this domain to use
+ * @parm conole_mfn returned with the mfn of the console page
+ * @return 0 on success, -1 on failure
+ */
+int xc_linux_build(xc_interface *xch,
+                   uint32_t domid,
+                   unsigned int mem_mb,
+                   const char *image_name,
+                   const char *ramdisk_name,
+                   const char *cmdline,
+                   const char *features,
+                   unsigned long flags,
+                   unsigned int store_evtchn,
+                   unsigned long *store_mfn,
+                   unsigned int console_evtchn,
+                   unsigned long *console_mfn);
+
+/*
+ * Sets *lockfd to -1.
+ * Has deallocated everything even on error.
+ */
+int xc_suspend_evtchn_release(xc_interface *xch,
+                              struct xenevtchn_handle *xce,
+                              uint32_t domid, int suspend_evtchn, int *lockfd);
+
+/**
+ * This function eats the initial notification.
+ * xce must not be used for anything else
+ * See xc_suspend_evtchn_init_sane re lockfd.
+ */
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch,
+                                     struct xenevtchn_handle *xce,
+                                     uint32_t domid, int port, int *lockfd);
+
+/* xce must not be used for anything else */
+int xc_await_suspend(xc_interface *xch, struct xenevtchn_handle *xce,
+                     int suspend_evtchn);
+
+/**
+ * The port will be signaled immediately after this call
+ * The caller should check the domain status and look for the next event
+ * On success, *lockfd will be set to >=0 and *lockfd must be preserved
+ * and fed to xc_suspend_evtchn_release.  (On error *lockfd is
+ * undefined and xc_suspend_evtchn_release is not allowed.)
+ */
+int xc_suspend_evtchn_init_sane(xc_interface *xch,
+                                struct xenevtchn_handle *xce,
+                                uint32_t domid, int port, int *lockfd);
+
+int xc_mark_page_online(xc_interface *xch, unsigned long start,
+                        unsigned long end, uint32_t *status);
+
+int xc_mark_page_offline(xc_interface *xch, unsigned long start,
+                          unsigned long end, uint32_t *status);
+
+int xc_query_page_offline_status(xc_interface *xch, unsigned long start,
+                                 unsigned long end, uint32_t *status);
+
+int xc_exchange_page(xc_interface *xch, uint32_t domid, xen_pfn_t mfn);
+
+
+/**
+ * Memory related information, such as PFN types, the P2M table,
+ * the guest word width and the guest page table levels.
+ */
+struct xc_domain_meminfo {
+    unsigned int pt_levels;
+    unsigned int guest_width;
+    xen_pfn_t *pfn_type;
+    xen_pfn_t *p2m_table;
+    unsigned long p2m_size;
+};
+
+int xc_map_domain_meminfo(xc_interface *xch, uint32_t domid,
+                          struct xc_domain_meminfo *minfo);
+
+int xc_unmap_domain_meminfo(xc_interface *xch, struct xc_domain_meminfo *mem);
+
+/**
+ * This function map m2p table
+ * @parm xch a handle to an open hypervisor interface
+ * @parm max_mfn the max pfn
+ * @parm prot the flags to map, such as read/write etc
+ * @parm mfn0 return the first mfn, can be NULL
+ * @return mapped m2p table on success, NULL on failure
+ */
+xen_pfn_t *xc_map_m2p(xc_interface *xch,
+                      unsigned long max_mfn,
+                      int prot,
+                      unsigned long *mfn0);
+#endif /* XENGUEST_H */
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
new file mode 100644
index 0000000000..0f24d6dd08
--- /dev/null
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -0,0 +1,665 @@
+/******************************************************************************
+ * xc_cpuid_x86.c
+ *
+ * Compute cpuid of a domain.
+ *
+ * Copyright (c) 2008, Citrix Systems, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <limits.h>
+#include "xc_private.h"
+#include "xc_bitops.h"
+#include <xen/hvm/params.h>
+#include <xen-tools/libs.h>
+
+enum {
+#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
+#include <xen/arch-x86/cpufeatureset.h>
+};
+
+#include <xen/asm/x86-vendors.h>
+
+#include <xen/lib/x86/cpu-policy.h>
+
+#define bitmaskof(idx)      (1u << ((idx) & 31))
+#define featureword_of(idx) ((idx) >> 5)
+
+int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps)
+{
+    DECLARE_SYSCTL;
+    int ret;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_levelling_caps;
+    ret = do_sysctl(xch, &sysctl);
+
+    if ( !ret )
+        *caps = sysctl.u.cpu_levelling_caps.caps;
+
+    return ret;
+}
+
+int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
+                          uint32_t *nr_features, uint32_t *featureset)
+{
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(featureset,
+                             *nr_features * sizeof(*featureset),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, featureset) )
+        return -1;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_featureset;
+    sysctl.u.cpu_featureset.index = index;
+    sysctl.u.cpu_featureset.nr_features = *nr_features;
+    set_xen_guest_handle(sysctl.u.cpu_featureset.features, featureset);
+
+    ret = do_sysctl(xch, &sysctl);
+
+    xc_hypercall_bounce_post(xch, featureset);
+
+    if ( !ret )
+        *nr_features = sysctl.u.cpu_featureset.nr_features;
+
+    return ret;
+}
+
+uint32_t xc_get_cpu_featureset_size(void)
+{
+    return FEATURESET_NR_ENTRIES;
+}
+
+const uint32_t *xc_get_static_cpu_featuremask(
+    enum xc_static_cpu_featuremask mask)
+{
+    static const uint32_t masks[][FEATURESET_NR_ENTRIES] = {
+#define MASK(x) [XC_FEATUREMASK_ ## x] = INIT_ ## x ## _FEATURES
+
+        MASK(KNOWN),
+        MASK(SPECIAL),
+        MASK(PV_MAX),
+        MASK(PV_DEF),
+        MASK(HVM_SHADOW_MAX),
+        MASK(HVM_SHADOW_DEF),
+        MASK(HVM_HAP_MAX),
+        MASK(HVM_HAP_DEF),
+
+#undef MASK
+    };
+
+    if ( (unsigned int)mask >= ARRAY_SIZE(masks) )
+        return NULL;
+
+    return masks[mask];
+}
+
+int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
+                           uint32_t *nr_msrs)
+{
+    struct xen_sysctl sysctl = {};
+    int ret;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
+
+    ret = do_sysctl(xch, &sysctl);
+
+    if ( !ret )
+    {
+        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+{
+    struct xen_sysctl sysctl = {};
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             *nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             *nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) ||
+         xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
+    sysctl.u.cpu_policy.index = index;
+    sysctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    set_xen_guest_handle(sysctl.u.cpu_policy.cpuid_policy, leaves);
+    sysctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    set_xen_guest_handle(sysctl.u.cpu_policy.msr_policy, msrs);
+
+    ret = do_sysctl(xch, &sysctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( !ret )
+    {
+        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+{
+    DECLARE_DOMCTL;
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             *nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             *nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) ||
+         xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_get_cpu_policy;
+    domctl.domain = domid;
+    domctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
+    domctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( !ret )
+    {
+        *nr_leaves = domctl.u.cpu_policy.nr_leaves;
+        *nr_msrs = domctl.u.cpu_policy.nr_msrs;
+    }
+
+    return ret;
+}
+
+int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid,
+                             uint32_t nr_leaves, xen_cpuid_leaf_t *leaves,
+                             uint32_t nr_msrs, xen_msr_entry_t *msrs,
+                             uint32_t *err_leaf_p, uint32_t *err_subleaf_p,
+                             uint32_t *err_msr_p)
+{
+    DECLARE_DOMCTL;
+    DECLARE_HYPERCALL_BOUNCE(leaves,
+                             nr_leaves * sizeof(*leaves),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    DECLARE_HYPERCALL_BOUNCE(msrs,
+                             nr_msrs * sizeof(*msrs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    int ret;
+
+    if ( err_leaf_p )
+        *err_leaf_p = -1;
+    if ( err_subleaf_p )
+        *err_subleaf_p = -1;
+    if ( err_msr_p )
+        *err_msr_p = -1;
+
+    if ( xc_hypercall_bounce_pre(xch, leaves) )
+        return -1;
+
+    if ( xc_hypercall_bounce_pre(xch, msrs) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_set_cpu_policy;
+    domctl.domain = domid;
+    domctl.u.cpu_policy.nr_leaves = nr_leaves;
+    set_xen_guest_handle(domctl.u.cpu_policy.cpuid_policy, leaves);
+    domctl.u.cpu_policy.nr_msrs = nr_msrs;
+    set_xen_guest_handle(domctl.u.cpu_policy.msr_policy, msrs);
+    domctl.u.cpu_policy.err_leaf = -1;
+    domctl.u.cpu_policy.err_subleaf = -1;
+    domctl.u.cpu_policy.err_msr = -1;
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, leaves);
+    xc_hypercall_bounce_post(xch, msrs);
+
+    if ( err_leaf_p )
+        *err_leaf_p = domctl.u.cpu_policy.err_leaf;
+    if ( err_subleaf_p )
+        *err_subleaf_p = domctl.u.cpu_policy.err_subleaf;
+    if ( err_msr_p )
+        *err_msr_p = domctl.u.cpu_policy.err_msr;
+
+    return ret;
+}
+
+static int compare_leaves(const void *l, const void *r)
+{
+    const xen_cpuid_leaf_t *lhs = l;
+    const xen_cpuid_leaf_t *rhs = r;
+
+    if ( lhs->leaf != rhs->leaf )
+        return lhs->leaf < rhs->leaf ? -1 : 1;
+
+    if ( lhs->subleaf != rhs->subleaf )
+        return lhs->subleaf < rhs->subleaf ? -1 : 1;
+
+    return 0;
+}
+
+static xen_cpuid_leaf_t *find_leaf(
+    xen_cpuid_leaf_t *leaves, unsigned int nr_leaves,
+    const struct xc_xend_cpuid *xend)
+{
+    const xen_cpuid_leaf_t key = { xend->leaf, xend->subleaf };
+
+    return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves);
+}
+
+static int xc_cpuid_xend_policy(
+    xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend)
+{
+    int rc;
+    xc_dominfo_t di;
+    unsigned int nr_leaves, nr_msrs;
+    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
+    /*
+     * Three full policies.  The host, domain max, and domain current for the
+     * domain type.
+     */
+    xen_cpuid_leaf_t *host = NULL, *max = NULL, *cur = NULL;
+    unsigned int nr_host, nr_max, nr_cur;
+
+    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
+         di.domid != domid )
+    {
+        ERROR("Failed to obtain d%d info", domid);
+        rc = -ESRCH;
+        goto fail;
+    }
+
+    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
+    if ( rc )
+    {
+        PERROR("Failed to obtain policy info size");
+        rc = -errno;
+        goto fail;
+    }
+
+    rc = -ENOMEM;
+    if ( (host = calloc(nr_leaves, sizeof(*host))) == NULL ||
+         (max  = calloc(nr_leaves, sizeof(*max)))  == NULL ||
+         (cur  = calloc(nr_leaves, sizeof(*cur)))  == NULL )
+    {
+        ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves);
+        goto fail;
+    }
+
+    /* Get the domain's current policy. */
+    nr_msrs = 0;
+    nr_cur = nr_leaves;
+    rc = xc_get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain d%d current policy", domid);
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Get the domain's max policy. */
+    nr_msrs = 0;
+    nr_max = nr_leaves;
+    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max
+                                              : XEN_SYSCTL_cpu_policy_pv_max,
+                                  &nr_max, max, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv");
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Get the host policy. */
+    nr_msrs = 0;
+    nr_host = nr_leaves;
+    rc = xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host,
+                                  &nr_host, host, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain host policy");
+        rc = -errno;
+        goto fail;
+    }
+
+    rc = -EINVAL;
+    for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend )
+    {
+        xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend);
+        const xen_cpuid_leaf_t *max_leaf = find_leaf(max, nr_max, xend);
+        const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend);
+
+        if ( cur_leaf == NULL || max_leaf == NULL || host_leaf == NULL )
+        {
+            ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->subleaf);
+            goto fail;
+        }
+
+        for ( unsigned int i = 0; i < ARRAY_SIZE(xend->policy); i++ )
+        {
+            uint32_t *cur_reg = &cur_leaf->a + i;
+            const uint32_t *max_reg = &max_leaf->a + i;
+            const uint32_t *host_reg = &host_leaf->a + i;
+
+            if ( xend->policy[i] == NULL )
+                continue;
+
+            for ( unsigned int j = 0; j < 32; j++ )
+            {
+                bool val;
+
+                if ( xend->policy[i][j] == '1' )
+                    val = true;
+                else if ( xend->policy[i][j] == '0' )
+                    val = false;
+                else if ( xend->policy[i][j] == 'x' )
+                    val = test_bit(31 - j, max_reg);
+                else if ( xend->policy[i][j] == 'k' ||
+                          xend->policy[i][j] == 's' )
+                    val = test_bit(31 - j, host_reg);
+                else
+                {
+                    ERROR("Bad character '%c' in policy[%d] string '%s'",
+                          xend->policy[i][j], i, xend->policy[i]);
+                    goto fail;
+                }
+
+                clear_bit(31 - j, cur_reg);
+                if ( val )
+                    set_bit(31 - j, cur_reg);
+            }
+        }
+    }
+
+    /* Feed the transformed currrent policy back up to Xen. */
+    rc = xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL,
+                                  &err_leaf, &err_subleaf, &err_msr);
+    if ( rc )
+    {
+        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
+               domid, err_leaf, err_subleaf, err_msr);
+        rc = -errno;
+        goto fail;
+    }
+
+    /* Success! */
+
+ fail:
+    free(cur);
+    free(max);
+    free(host);
+
+    return rc;
+}
+
+int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
+                          const uint32_t *featureset, unsigned int nr_features,
+                          bool pae,
+                          const struct xc_xend_cpuid *xend)
+{
+    int rc;
+    xc_dominfo_t di;
+    unsigned int i, nr_leaves, nr_msrs;
+    xen_cpuid_leaf_t *leaves = NULL;
+    struct cpuid_policy *p = NULL;
+    uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
+    uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {};
+    uint32_t len = ARRAY_SIZE(host_featureset);
+
+    if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
+         di.domid != domid )
+    {
+        ERROR("Failed to obtain d%d info", domid);
+        rc = -ESRCH;
+        goto out;
+    }
+
+    rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs);
+    if ( rc )
+    {
+        PERROR("Failed to obtain policy info size");
+        rc = -errno;
+        goto out;
+    }
+
+    rc = -ENOMEM;
+    if ( (leaves = calloc(nr_leaves, sizeof(*leaves))) == NULL ||
+         (p = calloc(1, sizeof(*p))) == NULL )
+        goto out;
+
+    /* Get the host policy. */
+    rc = xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host,
+                               &len, host_featureset);
+    if ( rc )
+    {
+        /* Tolerate "buffer too small", as we've got the bits we need. */
+        if ( errno == ENOBUFS )
+            rc = 0;
+        else
+        {
+            PERROR("Failed to obtain host featureset");
+            rc = -errno;
+            goto out;
+        }
+    }
+
+    /* Get the domain's default policy. */
+    nr_msrs = 0;
+    rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default
+                                              : XEN_SYSCTL_cpu_policy_pv_default,
+                                  &nr_leaves, leaves, &nr_msrs, NULL);
+    if ( rc )
+    {
+        PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv");
+        rc = -errno;
+        goto out;
+    }
+
+    rc = x86_cpuid_copy_from_buffer(p, leaves, nr_leaves,
+                                    &err_leaf, &err_subleaf);
+    if ( rc )
+    {
+        ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)",
+              err_leaf, err_subleaf, -rc, strerror(-rc));
+        goto out;
+    }
+
+    /*
+     * Account for feature which have been disabled by default since Xen 4.13,
+     * so migrated-in VM's don't risk seeing features disappearing.
+     */
+    if ( restore )
+    {
+        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
+
+        if ( di.hvm )
+        {
+            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
+        }
+    }
+
+    if ( featureset )
+    {
+        uint32_t disabled_features[FEATURESET_NR_ENTRIES],
+            feat[FEATURESET_NR_ENTRIES] = {};
+        static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
+        unsigned int i, b;
+
+        /*
+         * The user supplied featureset may be shorter or longer than
+         * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
+         * Longer is fine, so long as it only padded with zeros.
+         */
+        unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
+
+        /* Check for truncated set bits. */
+        rc = -EOPNOTSUPP;
+        for ( i = user_len; i < nr_features; ++i )
+            if ( featureset[i] != 0 )
+                goto out;
+
+        memcpy(feat, featureset, sizeof(*featureset) * user_len);
+
+        /* Disable deep dependencies of disabled features. */
+        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+            disabled_features[i] = ~feat[i] & deep_features[i];
+
+        for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
+        {
+            const uint32_t *dfs;
+
+            if ( !test_bit(b, disabled_features) ||
+                 !(dfs = x86_cpuid_lookup_deep_deps(b)) )
+                continue;
+
+            for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+            {
+                feat[i] &= ~dfs[i];
+                disabled_features[i] &= ~dfs[i];
+            }
+        }
+
+        cpuid_featureset_to_policy(feat, p);
+    }
+    else
+    {
+        if ( di.hvm )
+            p->basic.pae = pae;
+    }
+
+    if ( !di.hvm )
+    {
+        /*
+         * On hardware without CPUID Faulting, PV guests see real topology.
+         * As a consequence, they also need to see the host htt/cmp fields.
+         */
+        p->basic.htt       = test_bit(X86_FEATURE_HTT, host_featureset);
+        p->extd.cmp_legacy = test_bit(X86_FEATURE_CMP_LEGACY, host_featureset);
+    }
+    else
+    {
+        /*
+         * Topology for HVM guests is entirely controlled by Xen.  For now, we
+         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
+         */
+        p->basic.htt = true;
+        p->extd.cmp_legacy = false;
+
+        /*
+         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
+         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
+         * overflow.
+         */
+        if ( !(p->basic.lppp & 0x80) )
+            p->basic.lppp *= 2;
+
+        switch ( p->x86_vendor )
+        {
+        case X86_VENDOR_INTEL:
+            for ( i = 0; (p->cache.subleaf[i].type &&
+                          i < ARRAY_SIZE(p->cache.raw)); ++i )
+            {
+                p->cache.subleaf[i].cores_per_package =
+                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                p->cache.subleaf[i].threads_per_cache = 0;
+            }
+            break;
+
+        case X86_VENDOR_AMD:
+        case X86_VENDOR_HYGON:
+            /*
+             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
+             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
+             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
+             * - overflow,
+             * - going out of sync with leaf 1 EBX[23:16],
+             * - incrementing ApicIdCoreSize when it's zero (which changes the
+             *   meaning of bits 7:0).
+             *
+             * UPDATE: I addition to avoiding overflow, some
+             * proprietary operating systems have trouble with
+             * apic_id_size values greater than 7.  Limit the value to
+             * 7 for now.
+             */
+            if ( p->extd.nc < 0x7f )
+            {
+                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size < 0x7 )
+                    p->extd.apic_id_size++;
+
+                p->extd.nc = (p->extd.nc << 1) | 1;
+            }
+            break;
+        }
+
+        /*
+         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
+         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
+         * CPUID.  Xen will discard these bits if configuration hasn't been
+         * set for the domain.
+         */
+        p->extd.itsc = true;
+        p->basic.vmx = true;
+        p->extd.svm = true;
+    }
+
+    rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
+    if ( rc )
+    {
+        ERROR("Failed to serialise CPUID (%d = %s)", -rc, strerror(-rc));
+        goto out;
+    }
+
+    rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL,
+                                  &err_leaf, &err_subleaf, &err_msr);
+    if ( rc )
+    {
+        PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr %#x)",
+               domid, err_leaf, err_subleaf, err_msr);
+        rc = -errno;
+        goto out;
+    }
+
+    if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) )
+        goto out;
+
+    rc = 0;
+
+out:
+    free(p);
+    free(leaves);
+
+    return rc;
+}
diff --git a/tools/libs/guest/xg_dom_arm.c b/tools/libs/guest/xg_dom_arm.c
new file mode 100644
index 0000000000..3f66f1d890
--- /dev/null
+++ b/tools/libs/guest/xg_dom_arm.c
@@ -0,0 +1,552 @@
+/*
+ * Xen domain builder -- ARM
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2011, Citrix Systems
+ */
+#include <inttypes.h>
+#include <assert.h>
+
+#include <xen/xen.h>
+#include <xen/io/protocols.h>
+#include <xen-tools/libs.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#define NR_MAGIC_PAGES 4
+#define CONSOLE_PFN_OFFSET 0
+#define XENSTORE_PFN_OFFSET 1
+#define MEMACCESS_PFN_OFFSET 2
+#define VUART_PFN_OFFSET 3
+
+#define LPAE_SHIFT 9
+
+#define PFN_4K_SHIFT  (0)
+#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
+#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
+#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
+
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int alloc_magic_pages(struct xc_dom_image *dom)
+{
+    int rc, i;
+    const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
+    xen_pfn_t p2m[NR_MAGIC_PAGES];
+
+    BUILD_BUG_ON(NR_MAGIC_PAGES > GUEST_MAGIC_SIZE >> XC_PAGE_SHIFT);
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    for (i = 0; i < NR_MAGIC_PAGES; i++)
+        p2m[i] = base + i;
+
+    rc = xc_domain_populate_physmap_exact(
+            dom->xch, dom->guest_domid, NR_MAGIC_PAGES,
+            0, 0, p2m);
+    if ( rc < 0 )
+        return rc;
+
+    dom->console_pfn = base + CONSOLE_PFN_OFFSET;
+    dom->xenstore_pfn = base + XENSTORE_PFN_OFFSET;
+    dom->vuart_gfn = base + VUART_PFN_OFFSET;
+
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, base + MEMACCESS_PFN_OFFSET);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->vuart_gfn);
+
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
+            dom->console_pfn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
+            dom->xenstore_pfn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_MONITOR_RING_PFN,
+            base + MEMACCESS_PFN_OFFSET);
+    /* allocated by toolstack */
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN,
+            dom->console_evtchn);
+    xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN,
+            dom->xenstore_evtchn);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int start_info_arm(struct xc_dom_image *dom)
+{
+    DOMPRINTF_CALLED(dom->xch);
+    return 0;
+}
+
+static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
+{
+    DOMPRINTF_CALLED(dom->xch);
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int vcpu_arm32(struct xc_dom_image *dom)
+{
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
+    int rc;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc32 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
+    ctxt->user_regs.r0_usr = 0; /* SBZ */
+    /* Machine ID: We use DTB therefore no machine id */
+    ctxt->user_regs.r1_usr = 0xffffffff;
+    /* ATAGS/DTB: We currently require that the guest kernel to be
+     * using CONFIG_ARM_APPENDED_DTB. Ensure that r2 does not look
+     * like a valid pointer to a set of ATAGS or a DTB.
+     */
+    ctxt->user_regs.r2_usr = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+
+    ctxt->sctlr = SCTLR_GUEST_INIT;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_GUEST32_INIT;
+
+    ctxt->flags = VGCF_online;
+
+    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx32,
+           ctxt->user_regs.cpsr, ctxt->user_regs.pc32);
+
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
+}
+
+static int vcpu_arm64(struct xc_dom_image *dom)
+{
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
+    int rc;
+
+    DOMPRINTF_CALLED(dom->xch);
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc64 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm64/booting.txt. */
+    ctxt->user_regs.x0 = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+    ctxt->user_regs.x1 = 0;
+    ctxt->user_regs.x2 = 0;
+    ctxt->user_regs.x3 = 0;
+
+    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
+
+    ctxt->sctlr = SCTLR_GUEST_INIT;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_GUEST64_INIT;
+
+    ctxt->flags = VGCF_online;
+
+    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
+           ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
+
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int set_mode(xc_interface *xch, uint32_t domid, char *guest_type)
+{
+    static const struct {
+        char           *guest;
+        uint32_t        size;
+    } types[] = {
+        { "xen-3.0-aarch64", 64 },
+        { "xen-3.0-armv7l",  32 },
+    };
+    DECLARE_DOMCTL;
+    int i,rc;
+
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_set_address_size;
+    domctl.u.address_size.size = 0;
+
+    for ( i = 0; i < ARRAY_SIZE(types); i++ )
+        if ( !strcmp(types[i].guest, guest_type) )
+            domctl.u.address_size.size = types[i].size;
+    if ( domctl.u.address_size.size == 0 )
+    {
+        xc_dom_printf(xch, "%s: warning: unknown guest type %s",
+                      __FUNCTION__, guest_type);
+        return -EINVAL;
+    }
+
+    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
+                  guest_type, domctl.u.address_size.size);
+    rc = do_domctl(xch, &domctl);
+    if ( rc != 0 )
+        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
+                      __FUNCTION__, rc);
+    return rc;
+}
+
+/*  >0: success, *nr_pfns set to number actually populated
+ *   0: didn't try with this pfn shift (e.g. misaligned base etc)
+ *  <0: ERROR
+ */
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns,
+                             xen_pfn_t *extents)
+{
+    /* The mask for this level */
+    const uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    /* The shift, mask and next boundary for the level above this one */
+    const int next_shift = pfn_shift + LPAE_SHIFT;
+    const uint64_t next_mask = ((uint64_t)1<<next_shift)-1;
+    const xen_pfn_t next_boundary
+        = (base_pfn + ((uint64_t)1<<next_shift)) & ~next_mask;
+
+    int nr, i, count;
+    xen_pfn_t end_pfn = base_pfn + *nr_pfns;
+
+    /* No level zero super pages with current hardware */
+    if ( pfn_shift == PFN_512G_SHIFT )
+        return 0;
+
+    /* base is misaligned for this level */
+    if ( mask & base_pfn )
+        return 0;
+
+    /*
+     * If base is not aligned at the next level up then try and make
+     * it so for next time around.
+     */
+    if ( (base_pfn & next_mask) && end_pfn > next_boundary )
+        end_pfn = next_boundary;
+
+    count = ( end_pfn - base_pfn ) >> pfn_shift;
+
+    /* Nothing to allocate */
+    if ( !count )
+        return 0;
+
+    for ( i = 0 ; i < count ; i ++ )
+        extents[i] = base_pfn + (i<<pfn_shift);
+
+    nr = xc_domain_populate_physmap(dom->xch, dom->guest_domid, count,
+                                    pfn_shift, 0, extents);
+    if ( nr <= 0 ) return nr;
+    DOMPRINTF("%s: populated %#x/%#x entries with shift %d",
+              __FUNCTION__, nr, count, pfn_shift);
+
+    *nr_pfns = nr << pfn_shift;
+
+    return 1;
+}
+
+static int populate_guest_memory(struct xc_dom_image *dom,
+                                 xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
+{
+    int rc = 0;
+    xen_pfn_t allocsz, pfn, *extents;
+
+    extents = calloc(1024*1024,sizeof(xen_pfn_t));
+    if ( extents == NULL )
+    {
+        DOMPRINTF("%s: Unable to allocate extent array", __FUNCTION__);
+        return -1;
+    }
+
+    DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
+              __FUNCTION__,
+              (uint64_t)base_pfn << XC_PAGE_SHIFT,
+              (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
+              (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
+
+    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
+    {
+        allocsz = min_t(int, 1024*1024, nr_pfns - pfn);
+#if 0 /* Enable this to exercise/debug the code which tries to realign
+       * to a superpage boundary, by misaligning at the start. */
+        if ( pfn == 0 )
+        {
+            allocsz = 1;
+            rc = populate_one_size(dom, PFN_4K_SHIFT,
+                                   base_pfn + pfn, &allocsz, extents);
+            if (rc < 0) break;
+            if (rc > 0) continue;
+            /* Failed to allocate a single page? */
+            break;
+        }
+#endif
+
+        rc = populate_one_size(dom, PFN_512G_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_1G_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_2M_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc > 0 ) continue;
+
+        rc = populate_one_size(dom, PFN_4K_SHIFT,
+                               base_pfn + pfn, &allocsz, extents);
+        if ( rc < 0 ) break;
+        if ( rc == 0 )
+        {
+            DOMPRINTF("%s: Not enough RAM", __FUNCTION__);
+            errno = ENOMEM;
+            rc = -1;
+            goto out;
+        }
+    }
+
+out:
+    free(extents);
+    return rc < 0 ? rc : 0;
+}
+
+static int meminit(struct xc_dom_image *dom)
+{
+    int i, rc;
+    uint64_t modbase;
+
+    uint64_t ramsize = (uint64_t)dom->total_pages << XC_PAGE_SHIFT;
+
+    const uint64_t bankbase[] = GUEST_RAM_BANK_BASES;
+    const uint64_t bankmax[] = GUEST_RAM_BANK_SIZES;
+
+    /* Convenient */
+    const uint64_t kernbase = dom->kernel_seg.vstart;
+    const uint64_t kernend = ROUNDUP(dom->kernel_seg.vend, 21/*2MB*/);
+    const uint64_t kernsize = kernend - kernbase;
+    const uint64_t dtb_size = dom->devicetree_blob ?
+        ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
+    const uint64_t ramdisk_size = dom->modules[0].blob ?
+        ROUNDUP(dom->modules[0].size, XC_PAGE_SHIFT) : 0;
+    const uint64_t modsize = dtb_size + ramdisk_size;
+    const uint64_t ram128mb = bankbase[0] + (128<<20);
+
+    xen_pfn_t p2m_size;
+    uint64_t bank0end;
+
+    assert(dom->rambase_pfn << XC_PAGE_SHIFT == bankbase[0]);
+
+    if ( modsize + kernsize > bankmax[0] )
+    {
+        DOMPRINTF("%s: Not enough memory for the kernel+dtb+initrd",
+                  __FUNCTION__);
+        return -1;
+    }
+
+    if ( ramsize == 0 )
+    {
+        DOMPRINTF("%s: ram size is 0", __FUNCTION__);
+        return -1;
+    }
+
+    if ( ramsize > GUEST_RAM_MAX )
+    {
+        DOMPRINTF("%s: ram size is too large for guest address space: "
+                  "%"PRIx64" > %llx",
+                  __FUNCTION__, ramsize, GUEST_RAM_MAX);
+        return -1;
+    }
+
+    rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
+    if ( rc )
+        return rc;
+
+    for ( i = 0; ramsize && i < GUEST_RAM_BANKS; i++ )
+    {
+        uint64_t banksize = ramsize > bankmax[i] ? bankmax[i] : ramsize;
+
+        ramsize -= banksize;
+
+        p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT;
+
+        dom->rambank_size[i] = banksize >> XC_PAGE_SHIFT;
+    }
+
+    assert(dom->rambank_size[0] != 0);
+    assert(ramsize == 0); /* Too much RAM is rejected above */
+
+    dom->p2m_size = p2m_size;
+
+    /* setup initial p2m and allocate guest memory */
+    for ( i = 0; i < GUEST_RAM_BANKS && dom->rambank_size[i]; i++ )
+    {
+        if ((rc = populate_guest_memory(dom,
+                                        bankbase[i] >> XC_PAGE_SHIFT,
+                                        dom->rambank_size[i])))
+            return rc;
+    }
+
+    /*
+     * We try to place dtb+initrd at 128MB or if we have less RAM
+     * as high as possible. If there is no space then fallback to
+     * just before the kernel.
+     *
+     * If changing this then consider
+     * xen/arch/arm/kernel.c:place_modules as well.
+     */
+    bank0end = bankbase[0] + ((uint64_t)dom->rambank_size[0] << XC_PAGE_SHIFT);
+
+    if ( bank0end >= ram128mb + modsize && kernend < ram128mb )
+        modbase = ram128mb;
+    else if ( bank0end - modsize > kernend )
+        modbase = bank0end - modsize;
+    else if (kernbase - bankbase[0] > modsize )
+        modbase = kernbase - modsize;
+    else
+        return -1;
+
+    DOMPRINTF("%s: placing boot modules at 0x%" PRIx64, __FUNCTION__, modbase);
+
+    /*
+     * Must map DTB *after* initrd, to satisfy order of calls to
+     * xc_dom_alloc_segment in xc_dom_build_image, which must map
+     * things at monotonolically increasing addresses.
+     */
+    if ( ramdisk_size )
+    {
+        dom->modules[0].seg.vstart = modbase;
+        dom->modules[0].seg.vend = modbase + ramdisk_size;
+
+        DOMPRINTF("%s: ramdisk: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->modules[0].seg.vstart, dom->modules[0].seg.vend);
+
+        modbase += ramdisk_size;
+    }
+
+    if ( dtb_size )
+    {
+        dom->devicetree_seg.vstart = modbase;
+        dom->devicetree_seg.vend = modbase + dtb_size;
+
+        DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
+
+        modbase += dtb_size;
+    }
+
+    return 0;
+}
+
+bool xc_dom_translated(const struct xc_dom_image *dom)
+{
+    return true;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int bootearly(struct xc_dom_image *dom)
+{
+    DOMPRINTF("%s: doing nothing", __FUNCTION__);
+    return 0;
+}
+
+static int bootlate(struct xc_dom_image *dom)
+{
+    /* XXX
+     *   map shared info
+     *   map grant tables
+     *   setup shared info
+     */
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static struct xc_dom_arch xc_dom_32 = {
+    .guest_type = "xen-3.0-armv7l",
+    .native_protocol = XEN_IO_PROTO_ABI_ARM,
+    .page_shift = PAGE_SHIFT_ARM,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,
+    .start_info = start_info_arm,
+    .shared_info = shared_info_arm,
+    .vcpu = vcpu_arm32,
+    .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
+};
+
+static struct xc_dom_arch xc_dom_64 = {
+    .guest_type = "xen-3.0-aarch64",
+    .native_protocol = XEN_IO_PROTO_ABI_ARM,
+    .page_shift = PAGE_SHIFT_ARM,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,
+    .start_info = start_info_arm,
+    .shared_info = shared_info_arm,
+    .vcpu = vcpu_arm64,
+    .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
+};
+
+static void __init register_arch_hooks(void)
+{
+    xc_dom_register_arch_hooks(&xc_dom_32);
+    xc_dom_register_arch_hooks(&xc_dom_64);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libs/guest/xg_dom_armzimageloader.c b/tools/libs/guest/xg_dom_armzimageloader.c
new file mode 100644
index 0000000000..4246c8e5fa
--- /dev/null
+++ b/tools/libs/guest/xg_dom_armzimageloader.c
@@ -0,0 +1,271 @@
+/*
+ * Xen domain builder -- ARM zImage bits
+ *
+ * Parse and load ARM zImage kernel images.
+ *
+ * Copyright (C) 2012, Citrix Systems.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#include <arpa/inet.h> /* XXX ntohl is not the right function... */
+
+struct minimal_dtb_header {
+    uint32_t magic;
+    uint32_t total_size;
+    /* There are other fields but we don't use them yet. */
+};
+
+#define DTB_MAGIC 0xd00dfeed
+
+/* ------------------------------------------------------------ */
+/* 32-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE32_MAGIC_OFFSET 0x24
+#define ZIMAGE32_START_OFFSET 0x28
+#define ZIMAGE32_END_OFFSET   0x2c
+
+#define ZIMAGE32_MAGIC 0x016f2818
+
+static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
+{
+    uint32_t *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < 0x30 /*sizeof(struct setup_header)*/ )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage = (uint32_t *)dom->kernel_blob;
+    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
+{
+    uint32_t *zimage;
+    uint32_t start, entry_addr;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = (uint32_t *)dom->kernel_blob;
+
+    /* Do not load kernel at the very first RAM address */
+    v_start = rambase + 0x8000;
+
+    if ( dom->kernel_size > UINT64_MAX - v_start )
+    {
+        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_end = v_start + dom->kernel_size;
+
+    /*
+     * If start is invalid then the guest will start at some invalid
+     * address and crash, but this happens in guest context so doesn't
+     * concern us here.
+     */
+    start = zimage[ZIMAGE32_START_OFFSET/4];
+
+    if (start == 0)
+        entry_addr = v_start;
+    else
+        entry_addr = start;
+
+    /* find kernel segment */
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_end;
+
+    dom->parms.virt_entry = entry_addr;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-armv7l";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
+/* 64-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE64_MAGIC_V0 0x14000008
+#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
+
+/* linux/Documentation/arm64/booting.txt */
+struct zimage64_hdr {
+    uint32_t magic0;
+    uint32_t res0;
+    uint64_t text_offset;  /* Image load offset */
+    uint64_t res1;
+    uint64_t res2;
+    /* zImage V1 only from here */
+    uint64_t res3;
+    uint64_t res4;
+    uint64_t res5;
+    uint32_t magic1;
+    uint32_t res6;
+};
+static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < sizeof(*zimage) )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage =  dom->kernel_blob;
+    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
+         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = dom->kernel_blob;
+
+    if ( zimage->text_offset > UINT64_MAX - rambase )
+    {
+        DOMPRINTF("%s: kernel text offset is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_start = rambase + zimage->text_offset;
+
+    if ( dom->kernel_size > UINT64_MAX - v_start )
+    {
+        DOMPRINTF("%s: kernel is too large\n", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    v_end = v_start + dom->kernel_size;
+
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_end;
+
+    /* Call the kernel at offset 0 */
+    dom->parms.virt_entry = v_start;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-aarch64";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
+/* Common zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
+{
+    void *dst;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    dst = xc_dom_seg_to_ptr(dom, &dom->kernel_seg);
+    if ( dst == NULL )
+    {
+        DOMPRINTF("%s: xc_dom_seg_to_ptr(dom, &dom->kernel_seg) => NULL",
+                  __func__);
+        return -1;
+    }
+
+    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
+              __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
+    DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
+              __func__, dom->kernel_size, dom->kernel_blob, dst);
+
+    memcpy(dst, dom->kernel_blob, dom->kernel_size);
+
+    return 0;
+}
+
+static struct xc_dom_loader zimage32_loader = {
+    .name = "Linux zImage (ARM32)",
+    .probe = xc_dom_probe_zimage32_kernel,
+    .parser = xc_dom_parse_zimage32_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
+static struct xc_dom_loader zimage64_loader = {
+    .name = "Linux zImage (ARM64)",
+    .probe = xc_dom_probe_zimage64_kernel,
+    .parser = xc_dom_parse_zimage64_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
+static void __init register_loader(void)
+{
+    xc_dom_register_loader(&zimage32_loader);
+    xc_dom_register_loader(&zimage64_loader);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libs/guest/xg_dom_binloader.c b/tools/libs/guest/xg_dom_binloader.c
new file mode 100644
index 0000000000..870a921427
--- /dev/null
+++ b/tools/libs/guest/xg_dom_binloader.c
@@ -0,0 +1,329 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Some of the field descriptions were copied from "The Multiboot
+ * Specification", Copyright 1995, 96 Bryan Ford <baford@cs.utah.edu>,
+ * Erich Stefan Boleyn <erich@uruk.org> Copyright 1999, 2000, 2001, 2002
+ * Free Software Foundation, Inc.
+ */
+
+/******************************************************************************
+ *
+ * Loads simple binary images. It's like a .COM file in MS-DOS. No headers are
+ * present. The only requirement is that it must have a xen_bin_image table
+ * somewhere in the first 8192 bytes, starting on a 32-bit aligned address.
+ * Those familiar with the multiboot specification should recognize this, it's
+ * (almost) the same as the multiboot header.
+ * The layout of the xen_bin_image table is:
+ *
+ * Offset Type Name          Note
+ * 0      uint32_t  magic         required
+ * 4      uint32_t  flags         required
+ * 8      uint32_t  checksum      required
+ * 12     uint32_t  header_addr   required
+ * 16     uint32_t  load_addr     required
+ * 20     uint32_t  load_end_addr required
+ * 24     uint32_t  bss_end_addr  required
+ * 28     uint32_t  entry_addr    required
+ *
+ * - magic
+ *   Magic number identifying the table. For images to be loaded by Xen 3, the
+ *   magic value is 0x336ec578 ("xEn3" with the 0x80 bit of the "E" set).
+ * - flags
+ *   bit 0: indicates whether the image needs to be loaded on a page boundary
+ *   bit 1: reserved, must be 0 (the multiboot spec uses this bit to indicate
+ *          that memory info should be passed to the image)
+ *   bit 2: reserved, must be 0 (the multiboot spec uses this bit to indicate
+ *          that the bootloader should pass video mode info to the image)
+ *   bit 16: reserved, must be 1 (the multiboot spec uses this bit to indicate
+ *           that the values in the fields header_addr - entry_addr are
+ *           valid)
+ *   All other bits should be set to 0.
+ * - checksum
+ *   When added to "magic" and "flags", the resulting value should be 0.
+ * - header_addr
+ *   Contains the virtual address corresponding to the beginning of the
+ *   table - the memory location at which the magic value is supposed to be
+ *   loaded. This field serves to synchronize the mapping between OS image
+ *   offsets and virtual memory addresses.
+ * - load_addr
+ *   Contains the virtual address of the beginning of the text segment. The
+ *   offset in the OS image file at which to start loading is defined by the
+ *   offset at which the table was found, minus (header addr - load addr).
+ *   load addr must be less than or equal to header addr.
+ * - load_end_addr
+ *   Contains the virtual address of the end of the data segment.
+ *   (load_end_addr - load_addr) specifies how much data to load. This implies
+ *   that the text and data segments must be consecutive in the OS image. If
+ *   this field is zero, the domain builder assumes that the text and data
+ *   segments occupy the whole OS image file.
+ * - bss_end_addr
+ *   Contains the virtual address of the end of the bss segment. The domain
+ *   builder initializes this area to zero, and reserves the memory it occupies
+ *   to avoid placing boot modules and other data relevant to the loaded image
+ *   in that area. If this field is zero, the domain builder assumes that no bss
+ *   segment is present.
+ * - entry_addr
+ *   The virtual address at which to start execution of the loaded image.
+ *
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xenctrl_dom.h"
+
+#define round_pgup(_p)    (((_p)+(PAGE_SIZE_X86-1))&PAGE_MASK_X86)
+#define round_pgdown(_p)  ((_p)&PAGE_MASK_X86)
+
+struct xen_bin_image_table
+{
+    uint32_t magic;
+    uint32_t flags;
+    uint32_t checksum;
+    uint32_t header_addr;
+    uint32_t load_addr;
+    uint32_t load_end_addr;
+    uint32_t bss_end_addr;
+    uint32_t entry_addr;
+};
+
+#define XEN_MULTIBOOT_MAGIC3 0x336ec578
+
+#define XEN_MULTIBOOT_FLAG_ALIGN4K     0x00000001
+#define XEN_MULTIBOOT_FLAG_NEEDMEMINFO 0x00000002
+#define XEN_MULTIBOOT_FLAG_NEEDVIDINFO 0x00000004
+#define XEN_MULTIBOOT_FLAG_ADDRSVALID  0x00010000
+#define XEN_MULTIBOOT_FLAG_PAE_SHIFT   14
+#define XEN_MULTIBOOT_FLAG_PAE_MASK    (3 << XEN_MULTIBOOT_FLAG_PAE_SHIFT)
+
+/* Flags we test for */
+#define FLAGS_MASK     ((~ 0) & (~ XEN_MULTIBOOT_FLAG_ALIGN4K) & \
+    (~ XEN_MULTIBOOT_FLAG_PAE_MASK))
+#define FLAGS_REQUIRED XEN_MULTIBOOT_FLAG_ADDRSVALID
+
+/* --------------------------------------------------------------------- */
+
+static struct xen_bin_image_table *find_table(struct xc_dom_image *dom)
+{
+    struct xen_bin_image_table *table;
+    uint32_t *probe_ptr;
+    uint32_t *probe_end;
+
+    if ( dom->kernel_size < sizeof(*table) )
+        return NULL;
+    probe_ptr = dom->kernel_blob;
+    if ( dom->kernel_size > (8192 + sizeof(*table)) )
+        probe_end = dom->kernel_blob + 8192;
+    else
+        probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table);
+
+    for ( table = NULL; probe_ptr < probe_end; probe_ptr++ )
+    {
+        if ( *probe_ptr == XEN_MULTIBOOT_MAGIC3 )
+        {
+            table = (struct xen_bin_image_table *) probe_ptr;
+            /* Checksum correct? */
+            if ( (table->magic + table->flags + table->checksum) == 0 )
+                return table;
+        }
+    }
+    return NULL;
+}
+
+static int xc_dom_probe_bin_kernel(struct xc_dom_image *dom)
+{
+    return find_table(dom) ? 0 : -EINVAL;
+}
+
+static int xc_dom_parse_bin_kernel(struct xc_dom_image *dom)
+{
+    struct xen_bin_image_table *image_info;
+    char *image = dom->kernel_blob;
+    size_t image_size = dom->kernel_size;
+    uint32_t start_addr;
+    uint32_t load_end_addr;
+    uint32_t bss_end_addr;
+    uint32_t pae_flags;
+
+    image_info = find_table(dom);
+    if ( !image_info )
+        return -EINVAL;
+
+    DOMPRINTF("%s: multiboot header fields", __FUNCTION__);
+    DOMPRINTF("  flags:         0x%" PRIx32 "", image_info->flags);
+    DOMPRINTF("  header_addr:   0x%" PRIx32 "", image_info->header_addr);
+    DOMPRINTF("  load_addr:     0x%" PRIx32 "", image_info->load_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", image_info->load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", image_info->bss_end_addr);
+    DOMPRINTF("  entry_addr:    0x%" PRIx32 "", image_info->entry_addr);
+
+    /* Check the flags */
+    if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: xen_bin_image_table flags required "
+                     "0x%08" PRIx32 " found 0x%08" PRIx32 "",
+                     __FUNCTION__, FLAGS_REQUIRED, image_info->flags & FLAGS_MASK);
+        return -EINVAL;
+    }
+
+    /* Sanity check on the addresses */
+    if ( (image_info->header_addr < image_info->load_addr) ||
+         ((char *) image_info - image) <
+         (image_info->header_addr - image_info->load_addr) )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid header_addr.",
+                     __FUNCTION__);
+        return -EINVAL;
+    }
+
+    start_addr = image_info->header_addr - ((char *)image_info - image);
+    load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
+    bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
+
+    DOMPRINTF("%s: calculated addresses", __FUNCTION__);
+    DOMPRINTF("  start_addr:    0x%" PRIx32 "", start_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", bss_end_addr);
+
+    if ( (start_addr + image_size) < load_end_addr )
+    {


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMLr-0006RP-4w; Fri, 18 Sep 2020 19:47:23 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMLp-0006RF-I2
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:21 +0000
X-Inumbo-ID: 32a6f65a-a199-40e2-b164-3bb0c2d0c014
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 32a6f65a-a199-40e2-b164-3bb0c2d0c014;
 Fri, 18 Sep 2020 19:47:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mcW/NlmgcyhqiFj6S2lymvI/a4NavHV0/nJi6W+vG64=; b=3UiJMvLNaHerafEvrSJX9oYzLk
 B36eWOPNNjDvHIyhFtltcsCRI+WAkmhvfwlZGgFkr29Jv0SmpyBT9XaxU1oDjbgknRMS/pR/f2Bda
 17IHgVkR0zRri7o4ND9diLWF9rrSkhYrYSRsIAZkL3wYv45/CCzIRfzW/tbgyOrCz3Nk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLj-00078c-NP
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLj-0004Rh-MH
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: split libxenstore into new tools/libs/store
 directory
Message-Id: <E1kJMLj-0004Rh-MH@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit dd33fd2e81a0e83707cc203b974e501fa336590f
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:36 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenstore into new tools/libs/store directory
    
    There is no reason why libxenstore is not placed in the tools/libs
    directory.
    
    The common files between libxenstore and xenstored are kept in the
    tools/xenstore directory to be easily accessible by xenstore-stubdom
    which needs the xenstored files to be built.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                               |    7 +-
 stubdom/mini-os.mk                       |    2 +-
 tools/Makefile                           |    2 +-
 tools/Rules.mk                           |    5 -
 tools/libs/Makefile                      |    1 +
 tools/libs/store/Makefile                |   64 ++
 tools/libs/store/include/compat/xs.h     |    2 +
 tools/libs/store/include/compat/xs_lib.h |    2 +
 tools/libs/store/include/xenstore.h      |  290 ++++++
 tools/libs/store/libxenstore.map         |   49 +
 tools/libs/store/xs.c                    | 1473 ++++++++++++++++++++++++++++++
 tools/libs/uselibs.mk                    |    2 +
 tools/python/setup.py                    |    2 +-
 tools/xenstore/Makefile                  |   86 +-
 tools/xenstore/include/compat/xs.h       |    2 -
 tools/xenstore/include/compat/xs_lib.h   |    2 -
 tools/xenstore/include/xenstore.h        |  290 ------
 tools/xenstore/include/xenstore_lib.h    |   94 --
 tools/xenstore/xenstore_lib.h            |   94 ++
 tools/xenstore/xs.c                      | 1473 ------------------------------
 20 files changed, 1990 insertions(+), 1952 deletions(-)

diff --git a/.gitignore b/.gitignore
index eb637a98e9..1335034fd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,6 +128,12 @@ tools/libs/guest/xc_core.h
 tools/libs/guest/xc_core_arm.h
 tools/libs/guest/xc_core_x86.h
 tools/libs/guest/xc_private.h
+tools/libs/store/headers.chk
+tools/libs/store/list.h
+tools/libs/store/utils.h
+tools/libs/store/xenstore.pc
+tools/libs/store/xs_lib.c
+tools/libs/store/include/xenstore_lib.h
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -282,7 +288,6 @@ tools/xenstore/xenstore-control
 tools/xenstore/xenstore-ls
 tools/xenstore/xenstored
 tools/xenstore/xenstored_test
-tools/xenstore/xenstore.pc
 tools/xenstore/xs_tdb_dump
 tools/xentrace/xentrace_setsize
 tools/xentrace/tbctl
diff --git a/stubdom/mini-os.mk b/stubdom/mini-os.mk
index e1640a7cbc..420e9a8771 100644
--- a/stubdom/mini-os.mk
+++ b/stubdom/mini-os.mk
@@ -5,7 +5,7 @@
 # XEN_ROOT
 # MINIOS_TARGET_ARCH
 
-XENSTORE_CPPFLAGS = -isystem $(XEN_ROOT)/tools/xenstore/include
+XENSTORE_CPPFLAGS = -isystem $(XEN_ROOT)/tools/libs/store/include
 TOOLCORE_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toolcore
 TOOLLOG_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog
 EVTCHN_PATH = $(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn
diff --git a/tools/Makefile b/tools/Makefile
index f9b4012290..4a3646871c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -43,7 +43,7 @@ SUBDIRS-y += pygrub
 SUBDIRS-$(OCAML_TOOLS) += ocaml
 
 ifeq ($(CONFIG_RUMP),y)
-SUBDIRS-y := libs xenstore
+SUBDIRS-y := libs
 endif
 
 # For the sake of linking, set the sys-root
diff --git a/tools/Rules.mk b/tools/Rules.mk
index e17ac3ecc6..21aa8ea844 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -18,7 +18,6 @@ include $(XEN_ROOT)/tools/libs/uselibs.mk
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
-XEN_libxenstore    = $(XEN_ROOT)/tools/xenstore
 XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
 XEN_libxenvchan    = $(XEN_ROOT)/tools/libvchan
 
@@ -106,10 +105,6 @@ $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
 CFLAGS_libxenctrl += $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) -D__XEN_TOOLS__
 CFLAGS_libxenguest += $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory)
 
-CFLAGS_libxenstore = -I$(XEN_libxenstore)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenstore = $(SHLIB_libxentoolcore) $(SHLIB_libxenctrl)
-LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_libxenstore)/libxenstore$(libextension)
-SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_libxenstore)
 ifeq ($(CONFIG_Linux),y)
 LDLIBS_libxenstore += -ldl
 endif
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index f15c1688f7..62bd8f5292 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -12,6 +12,7 @@ SUBDIRS-y += devicemodel
 SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
+SUBDIRS-y += store
 
 ifeq ($(CONFIG_RUMP),y)
 SUBDIRS-y := toolcore
diff --git a/tools/libs/store/Makefile b/tools/libs/store/Makefile
new file mode 100644
index 0000000000..4da502646e
--- /dev/null
+++ b/tools/libs/store/Makefile
@@ -0,0 +1,64 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR = 3.0
+MINOR = 3
+
+ifeq ($(CONFIG_Linux),y)
+APPEND_LDFLAGS += -ldl
+endif
+
+SRCS-y   += xs_lib.c
+SRCS-y   += xs.c
+
+LIBHEADER = xenstore.h xenstore_lib.h
+
+include ../libs.mk
+
+# Include configure output (config.h)
+CFLAGS += -include $(XEN_ROOT)/tools/config.h
+CFLAGS += $(CFLAGS_libxentoolcore)
+CFLAGS += -DXEN_LIB_STORED="\"$(XEN_LIB_STORED)\""
+CFLAGS += -DXEN_RUN_STORED="\"$(XEN_RUN_STORED)\""
+
+LINK_FILES = xs_lib.c include/xenstore_lib.h list.h utils.h
+
+$(LIB_OBJS): $(LINK_FILES)
+
+$(LINK_FILES):
+	ln -sf $(XEN_ROOT)/tools/xenstore/$(notdir $@) $@
+
+xs.opic: CFLAGS += -DUSE_PTHREAD
+ifeq ($(CONFIG_Linux),y)
+xs.opic: CFLAGS += -DUSE_DLSYM
+else
+PKG_CONFIG_REMOVE += -ldl
+endif
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstore)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+.PHONY: install
+install: install-headers
+
+.PHONY: install-headers
+install-headers:
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)/xenstore-compat
+	$(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(includedir)/xenstore-compat/xs.h
+	$(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
+	ln -sf xenstore-compat/xs.h  $(DESTDIR)$(includedir)/xs.h
+	ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(includedir)/xs_lib.h
+
+.PHONY: uninstall
+uninstall: uninstall-headers
+
+.PHONY: uninstall-headers
+uninstall-headers:
+	rm -f $(DESTDIR)$(includedir)/xs_lib.h
+	rm -f $(DESTDIR)$(includedir)/xs.h
+	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
+	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs.h
+	if [ -d $(DESTDIR)$(includedir)/xenstore-compat ]; then \
+		rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/xenstore-compat; \
+	fi
diff --git a/tools/libs/store/include/compat/xs.h b/tools/libs/store/include/compat/xs.h
new file mode 100644
index 0000000000..99cf39bb1a
--- /dev/null
+++ b/tools/libs/store/include/compat/xs.h
@@ -0,0 +1,2 @@
+#warning xs.h is deprecated use xenstore.h instead
+#include <xenstore.h>
diff --git a/tools/libs/store/include/compat/xs_lib.h b/tools/libs/store/include/compat/xs_lib.h
new file mode 100644
index 0000000000..ad81b54c0e
--- /dev/null
+++ b/tools/libs/store/include/compat/xs_lib.h
@@ -0,0 +1,2 @@
+#warning xs_lib.h is deprecated use xenstore_lib.h instead
+#include <xenstore_lib.h>
diff --git a/tools/libs/store/include/xenstore.h b/tools/libs/store/include/xenstore.h
new file mode 100644
index 0000000000..25b31881c8
--- /dev/null
+++ b/tools/libs/store/include/xenstore.h
@@ -0,0 +1,290 @@
+/* 
+    Xen Store Daemon providing simple tree-like database.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef XENSTORE_H
+#define XENSTORE_H
+
+#include <xenstore_lib.h>
+
+#define XBT_NULL 0
+
+#define XS_OPEN_READONLY	(1UL<<0)
+#define XS_OPEN_SOCKETONLY      (1UL<<1)
+
+/*
+ * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no
+ * related watch events will be delivered via xs_read_watch.  But
+ * this relies on the couple token, subpath is unique.
+ *
+ * XS_UNWATCH_FILTER clear          XS_UNWATCH_FILTER set
+ *
+ * Even after xs_unwatch, "stale"   After xs_unwatch returns, no
+ * instances of the watch event     watch events with the same
+ * may be delivered.                token and with the same subpath
+ *                                  will be delivered.
+ *
+ * A path and a subpath can be      The application must avoid
+ * register with the same token.    registering a path (/foo/) and
+ *                                  a subpath (/foo/bar) with the
+ *                                  same path until a successful
+ *                                  xs_unwatch for the first watch
+ *                                  has returned.
+ */
+#define XS_UNWATCH_FILTER     (1UL<<2)
+
+struct xs_handle;
+typedef uint32_t xs_transaction_t;
+
+/* IMPORTANT: For details on xenstore protocol limits, see
+ * docs/misc/xenstore.txt in the Xen public source repository, and use the
+ * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h.
+ */
+
+/* On failure, these routines set errno. */
+
+/* Open a connection to the xs daemon.
+ * Attempts to make a connection over the socket interface,
+ * and if it fails, then over the  xenbus interface.
+ * Mode 0 specifies read-write access, XS_OPEN_READONLY for
+ * read-only access.
+ *
+ * * Connections made with xs_open(0) (which might be shared page or
+ *   socket based) are only guaranteed to work in the parent after
+ *   fork.
+ * * Connections made with xs_open(XS_OPEN_SOCKETONLY) will be usable
+ *   in either the parent or the child after fork, but not both.
+ * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
+ *   for xs_open(0).
+ * * XS_OPEN_READONLY has no bearing on any of this.
+ *
+ * Returns a handle or NULL.
+ */
+struct xs_handle *xs_open(unsigned long flags);
+
+/* Close the connection to the xs daemon. */
+void xs_close(struct xs_handle *xsh /* NULL ok */);
+
+/* Connect to the xs daemon.
+ * Returns a handle or NULL.
+ * Deprecated, please use xs_open(0) instead
+ */
+struct xs_handle *xs_daemon_open(void);
+struct xs_handle *xs_domain_open(void);
+
+/* Connect to the xs daemon (readonly for non-root clients).
+ * Returns a handle or NULL.
+ * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
+ */
+struct xs_handle *xs_daemon_open_readonly(void);
+
+/* Close the connection to the xs daemon.
+ * Deprecated, please use xs_close() instead
+ */
+void xs_daemon_close(struct xs_handle *);
+
+/* Throw away the connection to the xs daemon, for use after fork(). */
+void xs_daemon_destroy_postfork(struct xs_handle *);
+
+/* Get contents of a directory.
+ * Returns a malloced array: call free() on it after use.
+ * Num indicates size.
+ * Returns NULL on failure.
+ */
+char **xs_directory(struct xs_handle *h, xs_transaction_t t,
+		    const char *path, unsigned int *num);
+
+/* Get the value of a single file, nul terminated.
+ * Returns a malloced value: call free() on it after use.
+ * len indicates length in bytes, not including terminator.
+ * Returns NULL on failure.
+ */
+void *xs_read(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, unsigned int *len);
+
+/* Write the value of a single file.
+ * Returns false on failure.
+ */
+bool xs_write(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, const void *data, unsigned int len);
+
+/* Create a new directory.
+ * Returns false on failure, or success if it already exists.
+ */
+bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
+	      const char *path);
+
+/* Destroy a file or directory (and children).
+ * Returns false on failure, or if it doesn't exist.
+ */
+bool xs_rm(struct xs_handle *h, xs_transaction_t t,
+	   const char *path);
+
+/* Fake function which will always return false (required to let
+ * libxenstore remain at 3.0 version.
+ */
+bool xs_restrict(struct xs_handle *h, unsigned domid);
+
+/* Get permissions of node (first element is owner, first perms is "other").
+ * Returns malloced array, or NULL: call free() after use.
+ */
+struct xs_permissions *xs_get_permissions(struct xs_handle *h,
+					  xs_transaction_t t,
+					  const char *path, unsigned int *num);
+
+/* Set permissions of node (must be owner).  Returns false on failure.
+ *
+ * Domain 0 may read / write anywhere in the store, regardless of
+ * permission settings.
+ *
+ * Note:
+ * The perms array is a list of (domid, permissions) pairs. The first
+ * element in the list specifies the owner of the list, plus the flags
+ * for every domain not explicitly specified subsequently. The
+ * subsequent entries are normal capabilities.
+ *
+ * Example C code:
+ *
+ *  struct xs_permissions perms[2];
+ *
+ *  perms[0].id = dm_domid;
+ *  perms[0].perms = XS_PERM_NONE;
+ *  perms[1].id = guest_domid;
+ *  perms[1].perms = XS_PERM_READ;
+ *
+ * It means the owner of the path is domain $dm_domid (hence it always
+ * has read and write permission), all other domains (unless specified
+ * in subsequent pair) can neither read from nor write to that
+ * path. It then specifies domain $guest_domid can read from that
+ * path.
+ */
+bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t,
+			const char *path, struct xs_permissions *perms,
+			unsigned int num_perms);
+
+/* Watch a node for changes (poll on fd to detect, or call read_watch()).
+ * When the node (or any child) changes, fd will become readable.
+ * Token is returned when watch is read, to allow matching.
+ * Returns false on failure.
+ */
+bool xs_watch(struct xs_handle *h, const char *path, const char *token);
+
+/* Return the FD to poll on to see if a watch has fired. */
+int xs_fileno(struct xs_handle *h);
+
+/* Check for node changes.  On success, returns a non-NULL pointer ret
+ * such that ret[0] and ret[1] are valid C strings, namely the
+ * triggering path (see docs/misc/xenstore.txt) and the token (from
+ * xs_watch).  On error return value is NULL setting errno.
+ * 
+ * Callers should, after xs_fileno has become readable, repeatedly
+ * call xs_check_watch until it returns NULL and sets errno to EAGAIN.
+ * (If the fd became readable, xs_check_watch is allowed to make it no
+ * longer show up as readable even if future calls to xs_check_watch
+ * will return more watch events.)
+ *
+ * After the caller is finished with the returned information it
+ * should be freed all in one go with free(ret).
+ */
+char **xs_check_watch(struct xs_handle *h);
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array containing the path and token, or NULL.
+ * Use XS_WATCH_* to access these elements.
+ * Call free() after use.
+ */
+char **xs_read_watch(struct xs_handle *h, unsigned int *num);
+
+/* Remove a watch on a node: implicitly acks any outstanding watch.
+ * Returns false on failure (no watch on that node).
+ */
+bool xs_unwatch(struct xs_handle *h, const char *path, const char *token);
+
+/* Start a transaction: changes by others will not be seen during this
+ * transaction, and changes will not be visible to others until end.
+ * Returns NULL on failure.
+ */
+xs_transaction_t xs_transaction_start(struct xs_handle *h);
+
+/* End a transaction.
+ * If abandon is true, transaction is discarded instead of committed.
+ * Returns false on failure: if errno == EAGAIN, you have to restart
+ * transaction.
+ */
+bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
+			bool abort);
+
+/* Introduce a new domain.
+ * This tells the store daemon about a shared memory page, event channel and
+ * store path associated with a domain: the domain uses these to communicate.
+ */
+bool xs_introduce_domain(struct xs_handle *h,
+			 unsigned int domid,
+			 unsigned long mfn,
+                         unsigned int eventchn); 
+
+/* Set the target of a domain
+ * This tells the store daemon that a domain is targetting another one, so
+ * it should let it tinker with it.
+ */
+bool xs_set_target(struct xs_handle *h,
+		   unsigned int domid,
+		   unsigned int target);
+
+/* Resume a domain.
+ * Clear the shutdown flag for this domain in the store.
+ */
+bool xs_resume_domain(struct xs_handle *h, unsigned int domid);
+
+/* Release a domain.
+ * Tells the store domain to release the memory page to the domain.
+ */
+bool xs_release_domain(struct xs_handle *h, unsigned int domid);
+
+/* Query the home path of a domain.  Call free() after use.
+ */
+char *xs_get_domain_path(struct xs_handle *h, unsigned int domid);
+
+/* Returns true if child is either equal to parent, or a node underneath
+ * parent; or false otherwise.  Done by string comparison, so relative and
+ * absolute pathnames never in a parent/child relationship by this
+ * definition.  Cannot fail.
+ */
+bool xs_path_is_subpath(const char *parent, const char *child);
+
+/* Return whether the domain specified has been introduced to xenstored.
+ */
+bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid);
+
+char *xs_control_command(struct xs_handle *h, const char *cmd,
+			 void *data, unsigned int len);
+/* Deprecated: use xs_control_command() instead. */
+char *xs_debug_command(struct xs_handle *h, const char *cmd,
+		       void *data, unsigned int len);
+
+int xs_suspend_evtchn_port(int domid);
+#endif /* XENSTORE_H */
+
+/*
+ * Local variables:
+ *  mode: C
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff --git a/tools/libs/store/libxenstore.map b/tools/libs/store/libxenstore.map
new file mode 100644
index 0000000000..9854305a2c
--- /dev/null
+++ b/tools/libs/store/libxenstore.map
@@ -0,0 +1,49 @@
+VERS_3.0.3 {
+	global:
+		xs_open;
+		xs_close;
+		xs_daemon_open;
+		xs_domain_open;
+		xs_daemon_open_readonly;
+		xs_daemon_close;
+		xs_daemon_destroy_postfork;
+		xs_directory;
+		xs_read;
+		xs_write;
+		xs_mkdir;
+		xs_rm;
+		xs_restrict;
+		xs_get_permissions;
+		xs_set_permissions;
+		xs_watch;
+		xs_fileno;
+		xs_check_watch;
+		xs_read_watch;
+		xs_unwatch;
+		xs_transaction_start;
+		xs_transaction_end;
+		xs_introduce_domain;
+		xs_set_target;
+		xs_resume_domain;
+		xs_release_domain;
+		xs_get_domain_path;
+		xs_path_is_subpath;
+		xs_is_domain_introduced;
+		xs_control_command;
+		xs_debug_command;
+		xs_suspend_evtchn_port;
+		xs_daemon_rootdir;
+		xs_daemon_rundir;
+		xs_daemon_socket;
+		xs_daemon_socket_ro;
+		xs_domain_dev;
+		xs_daemon_tdb;
+		xs_write_all;
+		xs_strings_to_perms;
+		xs_perm_to_string;
+		xs_count_strings;
+		expanding_buffer_ensure;
+		sanitise_value;
+		unsanitise_value;
+	local: *; /* Do not expose anything by default */
+};
diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c
new file mode 100644
index 0000000000..aa1d24b8b9
--- /dev/null
+++ b/tools/libs/store/xs.c
@@ -0,0 +1,1473 @@
+/* 
+    Xen Store Daemon interface providing simple tree-like database.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <signal.h>
+#include <stdint.h>
+#include <errno.h>
+#include "xenstore.h"
+#include "list.h"
+#include "utils.h"
+
+#include <xentoolcore_internal.h>
+
+struct xs_stored_msg {
+	struct list_head list;
+	struct xsd_sockmsg hdr;
+	char *body;
+};
+
+#ifdef USE_PTHREAD
+
+#include <pthread.h>
+
+#ifdef USE_DLSYM
+#include <dlfcn.h>
+#endif
+
+struct xs_handle {
+	/* Communications channel to xenstore daemon. */
+	int fd;
+	Xentoolcore__Active_Handle tc_ah; /* for restrict */
+
+	/*
+         * A read thread which pulls messages off the comms channel and
+         * signals waiters.
+         */
+	pthread_t read_thr;
+	int read_thr_exists;
+
+	/*
+         * A list of fired watch messages, protected by a mutex. Users can
+         * wait on the conditional variable until a watch is pending.
+         */
+	struct list_head watch_list;
+	pthread_mutex_t watch_mutex;
+	pthread_cond_t watch_condvar;
+
+	/* Clients can select() on this pipe to wait for a watch to fire. */
+	int watch_pipe[2];
+	/* Filtering watch event in unwatch function? */
+	bool unwatch_filter;
+
+	/*
+         * A list of replies. Currently only one will ever be outstanding
+         * because we serialise requests. The requester can wait on the
+         * conditional variable for its response.
+         */
+	struct list_head reply_list;
+	pthread_mutex_t reply_mutex;
+	pthread_cond_t reply_condvar;
+
+	/* One request at a time. */
+	pthread_mutex_t request_mutex;
+
+	/* Lock discipline:
+	 *  Only holder of the request lock may write to h->fd.
+	 *  Only holder of the request lock may access read_thr_exists.
+	 *  If read_thr_exists==0, only holder of request lock may read h->fd;
+	 *  If read_thr_exists==1, only the read thread may read h->fd.
+	 *  Only holder of the reply lock may access reply_list.
+	 *  Only holder of the watch lock may access watch_list.
+	 * Lock hierarchy:
+	 *  The order in which to acquire locks is
+	 *     request_mutex
+	 *     reply_mutex
+	 *     watch_mutex
+	 */
+};
+
+#define mutex_lock(m)		pthread_mutex_lock(m)
+#define mutex_unlock(m)		pthread_mutex_unlock(m)
+#define condvar_signal(c)	pthread_cond_signal(c)
+#define condvar_wait(c,m)	pthread_cond_wait(c,m)
+#define cleanup_push(f, a)	\
+    pthread_cleanup_push((void (*)(void *))(f), (void *)(a))
+/*
+ * Some definitions of pthread_cleanup_pop() are a macro starting with an
+ * end-brace. GCC then complains if we immediately precede that with a label.
+ * Hence we insert a dummy statement to appease the compiler in this situation.
+ */
+#define cleanup_pop(run)        ((void)0); pthread_cleanup_pop(run)
+
+#define read_thread_exists(h)	(h->read_thr_exists)
+
+/* Because pthread_cleanup_p* are not available when USE_PTHREAD is
+ * disabled, use these macros which convert appropriately. */
+#define cleanup_push_heap(p)        cleanup_push(free, p)
+#define cleanup_pop_heap(run, p)    cleanup_pop((run))
+
+static void *read_thread(void *arg);
+
+#else /* !defined(USE_PTHREAD) */
+
+struct xs_handle {
+	int fd;
+	Xentoolcore__Active_Handle tc_ah; /* for restrict */
+	struct list_head reply_list;
+	struct list_head watch_list;
+	/* Clients can select() on this pipe to wait for a watch to fire. */
+	int watch_pipe[2];
+	/* Filtering watch event in unwatch function? */
+	bool unwatch_filter;
+};
+
+#define mutex_lock(m)		((void)0)
+#define mutex_unlock(m)		((void)0)
+#define condvar_signal(c)	((void)0)
+#define condvar_wait(c,m)	((void)0)
+#define cleanup_push(f, a)	((void)0)
+#define cleanup_pop(run)	((void)0)
+#define read_thread_exists(h)	(0)
+
+#define cleanup_push_heap(p)        ((void)0)
+#define cleanup_pop_heap(run, p)    do { if ((run)) free(p); } while(0)
+
+#endif
+
+static int read_message(struct xs_handle *h, int nonblocking);
+
+static bool setnonblock(int fd, int nonblock) {
+	int flags = fcntl(fd, F_GETFL);
+	if (flags == -1)
+		return false;
+
+	if (nonblock)
+		flags |= O_NONBLOCK;
+	else
+		flags &= ~O_NONBLOCK;
+
+	if (fcntl(fd, F_SETFL, flags) == -1)
+		return false;
+
+	return true;
+}
+
+int xs_fileno(struct xs_handle *h)
+{
+	char c = 0;
+
+	mutex_lock(&h->watch_mutex);
+
+	if ((h->watch_pipe[0] == -1) && (pipe(h->watch_pipe) != -1)) {
+		/* Kick things off if the watch list is already non-empty. */
+		if (!list_empty(&h->watch_list))
+			while (write(h->watch_pipe[1], &c, 1) != 1)
+				continue;
+	}
+
+	mutex_unlock(&h->watch_mutex);
+
+	return h->watch_pipe[0];
+}
+
+static int get_socket(const char *connect_to)
+{
+	struct sockaddr_un addr;
+	int sock, saved_errno, flags;
+
+	sock = socket(PF_UNIX, SOCK_STREAM, 0);
+	if (sock < 0)
+		return -1;
+
+	if ((flags = fcntl(sock, F_GETFD)) < 0)
+		goto error;
+	flags |= FD_CLOEXEC;
+	if (fcntl(sock, F_SETFD, flags) < 0)
+		goto error;
+
+	addr.sun_family = AF_UNIX;
+	if(strlen(connect_to) >= sizeof(addr.sun_path)) {
+		errno = EINVAL;
+		goto error;
+	}
+	strcpy(addr.sun_path, connect_to);
+
+	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
+		goto error;
+
+	return sock;
+
+error:
+	saved_errno = errno;
+	close(sock);
+	errno = saved_errno;
+	return -1;
+}
+
+static int get_dev(const char *connect_to)
+{
+	/* We cannot open read-only because requests are writes */
+	return open(connect_to, O_RDWR);
+}
+
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) {
+    struct xs_handle *h = CONTAINER_OF(ah, *h, tc_ah);
+    return xentoolcore__restrict_by_dup2_null(h->fd);
+}
+
+static struct xs_handle *get_handle(const char *connect_to)
+{
+	struct stat buf;
+	struct xs_handle *h = NULL;
+	int saved_errno;
+
+	h = malloc(sizeof(*h));
+	if (h == NULL)
+		goto err;
+
+	memset(h, 0, sizeof(*h));
+	h->fd = -1;
+
+	h->tc_ah.restrict_callback = all_restrict_cb;
+	xentoolcore__register_active_handle(&h->tc_ah);
+
+	if (stat(connect_to, &buf) != 0)
+		goto err;
+
+	if (S_ISSOCK(buf.st_mode))
+		h->fd = get_socket(connect_to);
+	else
+		h->fd = get_dev(connect_to);
+
+	if (h->fd == -1)
+		goto err;
+
+	INIT_LIST_HEAD(&h->reply_list);
+	INIT_LIST_HEAD(&h->watch_list);
+
+	/* Watch pipe is allocated on demand in xs_fileno(). */
+	h->watch_pipe[0] = h->watch_pipe[1] = -1;
+
+	h->unwatch_filter = false;
+
+#ifdef USE_PTHREAD
+	pthread_mutex_init(&h->watch_mutex, NULL);
+	pthread_cond_init(&h->watch_condvar, NULL);
+
+	pthread_mutex_init(&h->reply_mutex, NULL);
+	pthread_cond_init(&h->reply_condvar, NULL);
+
+	pthread_mutex_init(&h->request_mutex, NULL);
+#endif
+
+	return h;
+
+err:
+	saved_errno = errno;
+
+	if (h) {
+		xentoolcore__deregister_active_handle(&h->tc_ah);
+		if (h->fd >= 0)
+			close(h->fd);
+	}
+	free(h);
+
+	errno = saved_errno;
+	return NULL;
+}
+
+struct xs_handle *xs_daemon_open(void)
+{
+	return xs_open(0);
+}
+
+struct xs_handle *xs_daemon_open_readonly(void)
+{
+	return xs_open(XS_OPEN_READONLY);
+}
+
+struct xs_handle *xs_domain_open(void)
+{
+	return xs_open(0);
+}
+
+struct xs_handle *xs_open(unsigned long flags)
+{
+	struct xs_handle *xsh = NULL;
+
+	if (flags & XS_OPEN_READONLY)
+		xsh = get_handle(xs_daemon_socket_ro());
+	else
+		xsh = get_handle(xs_daemon_socket());
+
+	if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
+		xsh = get_handle(xs_domain_dev());
+
+	if (xsh && (flags & XS_UNWATCH_FILTER))
+		xsh->unwatch_filter = true;
+
+	return xsh;
+}
+
+static void close_free_msgs(struct xs_handle *h) {
+	struct xs_stored_msg *msg, *tmsg;
+
+	list_for_each_entry_safe(msg, tmsg, &h->reply_list, list) {
+		free(msg->body);
+		free(msg);
+	}
+
+	list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+		free(msg->body);
+		free(msg);
+	}
+}
+
+static void close_fds_free(struct xs_handle *h) {
+	if (h->watch_pipe[0] != -1) {
+		close(h->watch_pipe[0]);
+		close(h->watch_pipe[1]);
+	}
+
+	xentoolcore__deregister_active_handle(&h->tc_ah);
+        close(h->fd);
+        
+	free(h);
+}
+
+void xs_daemon_destroy_postfork(struct xs_handle *h)
+{
+        close_free_msgs(h);
+        close_fds_free(h);
+}
+
+void xs_daemon_close(struct xs_handle *h)
+{
+#ifdef USE_PTHREAD
+	if (h->read_thr_exists) {
+		pthread_cancel(h->read_thr);
+		pthread_join(h->read_thr, NULL);
+	}
+#endif
+
+	mutex_lock(&h->request_mutex);
+	mutex_lock(&h->reply_mutex);
+	mutex_lock(&h->watch_mutex);
+
+        close_free_msgs(h);
+
+	mutex_unlock(&h->request_mutex);
+	mutex_unlock(&h->reply_mutex);
+	mutex_unlock(&h->watch_mutex);
+
+        close_fds_free(h);
+}
+
+void xs_close(struct xs_handle* xsh)
+{
+	if (xsh)
+		xs_daemon_close(xsh);
+}
+
+static bool read_all(int fd, void *data, unsigned int len, int nonblocking)
+	/* With nonblocking, either reads either everything requested,
+	 * or nothing. */
+{
+	if (!len)
+		return true;
+
+	if (nonblocking && !setnonblock(fd, 1))
+		return false;
+
+	while (len) {
+		int done;
+
+		done = read(fd, data, len);
+		if (done < 0) {
+			if (errno == EINTR)
+				continue;
+			goto out_false;
+		}
+		if (done == 0) {
+			/* It closed fd on us?  EBADF is appropriate. */
+			errno = EBADF;
+			goto out_false;
+		}
+		data += done;
+		len -= done;
+
+		if (nonblocking) {
+			nonblocking = 0;
+			if (!setnonblock(fd, 0))
+				goto out_false;
+		}
+	}
+
+	return true;
+
+out_false:
+	if (nonblocking)
+		setnonblock(fd, 0);
+	return false;
+}
+
+#ifdef XSTEST
+#define read_all read_all_choice
+#define xs_write_all write_all_choice
+#endif
+
+static int get_error(const char *errorstring)
+{
+	unsigned int i;
+
+	for (i = 0; !streq(errorstring, xsd_errors[i].errstring); i++)
+		if (i == ARRAY_SIZE(xsd_errors) - 1)
+			return EINVAL;
+	return xsd_errors[i].errnum;
+}
+
+/* Adds extra nul terminator, because we generally (always?) hold strings. */
+static void *read_reply(
+	struct xs_handle *h, enum xsd_sockmsg_type *type, unsigned int *len)
+{
+	struct xs_stored_msg *msg;
+	char *body;
+	int read_from_thread;
+
+	read_from_thread = read_thread_exists(h);
+
+	/* Read from comms channel ourselves if there is no reader thread. */
+	if (!read_from_thread && (read_message(h, 0) == -1))
+		return NULL;
+
+	mutex_lock(&h->reply_mutex);
+#ifdef USE_PTHREAD
+	while (list_empty(&h->reply_list) && read_from_thread && h->fd != -1)
+		condvar_wait(&h->reply_condvar, &h->reply_mutex);
+#endif
+	if (list_empty(&h->reply_list)) {
+		mutex_unlock(&h->reply_mutex);
+		errno = EINVAL;
+		return NULL;
+	}
+	msg = list_top(&h->reply_list, struct xs_stored_msg, list);
+	list_del(&msg->list);
+	assert(list_empty(&h->reply_list));
+	mutex_unlock(&h->reply_mutex);
+
+	*type = msg->hdr.type;
+	if (len)
+		*len = msg->hdr.len;
+	body = msg->body;
+
+	free(msg);
+
+	return body;
+}
+
+/* Send message to xs, get malloc'ed reply.  NULL and set errno on error. */
+static void *xs_talkv(struct xs_handle *h, xs_transaction_t t,
+		      enum xsd_sockmsg_type type,
+		      const struct iovec *iovec,
+		      unsigned int num_vecs,
+		      unsigned int *len)
+{
+	struct xsd_sockmsg msg;
+	void *ret = NULL;
+	int saved_errno;
+	unsigned int i;
+	struct sigaction ignorepipe, oldact;
+
+	msg.tx_id = t;
+	msg.req_id = 0;
+	msg.type = type;
+	msg.len = 0;
+	for (i = 0; i < num_vecs; i++)
+		msg.len += iovec[i].iov_len;
+
+	if (msg.len > XENSTORE_PAYLOAD_MAX) {
+		errno = E2BIG;
+		return 0;
+	}
+
+	ignorepipe.sa_handler = SIG_IGN;
+	sigemptyset(&ignorepipe.sa_mask);
+	ignorepipe.sa_flags = 0;
+	sigaction(SIGPIPE, &ignorepipe, &oldact);
+
+	mutex_lock(&h->request_mutex);
+
+	if (!xs_write_all(h->fd, &msg, sizeof(msg)))
+		goto fail;
+
+	for (i = 0; i < num_vecs; i++)
+		if (!xs_write_all(h->fd, iovec[i].iov_base, iovec[i].iov_len))
+			goto fail;
+
+	ret = read_reply(h, &msg.type, len);
+	if (!ret)
+		goto fail;
+
+	mutex_unlock(&h->request_mutex);
+
+	sigaction(SIGPIPE, &oldact, NULL);
+	if (msg.type == XS_ERROR) {
+		saved_errno = get_error(ret);
+		free(ret);
+		errno = saved_errno;
+		return NULL;
+	}
+
+	if (msg.type != type) {
+		free(ret);
+		saved_errno = EBADF;
+		goto close_fd;
+	}
+	return ret;
+
+fail:
+	/* We're in a bad state, so close fd. */
+	saved_errno = errno;
+	mutex_unlock(&h->request_mutex);
+	sigaction(SIGPIPE, &oldact, NULL);
+close_fd:
+	close(h->fd);
+	h->fd = -1;
+	errno = saved_errno;
+	return NULL;
+}
+
+/* free(), but don't change errno. */
+static void free_no_errno(void *p)
+{
+	int saved_errno = errno;
+	free(p);
+	errno = saved_errno;
+}
+
+/* Simplified version of xs_talkv: single message. */
+static void *xs_single(struct xs_handle *h, xs_transaction_t t,
+		       enum xsd_sockmsg_type type,
+		       const char *string,
+		       unsigned int *len)
+{
+	struct iovec iovec;
+
+	iovec.iov_base = (void *)string;
+	iovec.iov_len = strlen(string) + 1;
+	return xs_talkv(h, t, type, &iovec, 1, len);
+}
+
+static bool xs_bool(char *reply)
+{
+	if (!reply)
+		return false;
+	free(reply);
+	return true;
+}
+
+static char **xs_directory_common(char *strings, unsigned int len,
+				  unsigned int *num)
+{
+	char *p, **ret;
+
+	/* Count the strings. */
+	*num = xs_count_strings(strings, len);
+
+	/* Transfer to one big alloc for easy freeing. */
+	ret = malloc(*num * sizeof(char *) + len);
+	if (!ret) {
+		free_no_errno(strings);
+		return NULL;
+	}
+	memcpy(&ret[*num], strings, len);
+	free_no_errno(strings);
+
+	strings = (char *)&ret[*num];
+	for (p = strings, *num = 0; p < strings + len; p += strlen(p) + 1)
+		ret[(*num)++] = p;
+	return ret;
+}
+
+static char **xs_directory_part(struct xs_handle *h, xs_transaction_t t,
+				const char *path, unsigned int *num)
+{
+	unsigned int off, result_len;
+	char gen[24], offstr[8];
+	struct iovec iovec[2];
+	char *result = NULL, *strings = NULL;
+
+	memset(gen, 0, sizeof(gen));
+	iovec[0].iov_base = (void *)path;
+	iovec[0].iov_len = strlen(path) + 1;
+
+	for (off = 0;;) {
+		snprintf(offstr, sizeof(offstr), "%u", off);
+		iovec[1].iov_base = (void *)offstr;
+		iovec[1].iov_len = strlen(offstr) + 1;
+		result = xs_talkv(h, t, XS_DIRECTORY_PART, iovec, 2,
+				  &result_len);
+
+		/* If XS_DIRECTORY_PART isn't supported return E2BIG. */
+		if (!result) {
+			if (errno == ENOSYS)
+				errno = E2BIG;
+			return NULL;
+		}
+
+		if (off) {
+			if (strcmp(gen, result)) {
+				free(result);
+				free(strings);
+				strings = NULL;
+				off = 0;
+				continue;
+			}
+		} else
+			strncpy(gen, result, sizeof(gen) - 1);
+
+		result_len -= strlen(result) + 1;
+		strings = realloc(strings, off + result_len);
+		memcpy(strings + off, result + strlen(result) + 1, result_len);
+		free(result);
+		off += result_len;
+
+		if (off <= 1 || strings[off - 2] == 0)
+			break;
+	}
+
+	if (off > 1)
+		off--;
+
+	return xs_directory_common(strings, off, num);
+}
+
+char **xs_directory(struct xs_handle *h, xs_transaction_t t,
+		    const char *path, unsigned int *num)
+{
+	char *strings;
+	unsigned int len;
+
+	strings = xs_single(h, t, XS_DIRECTORY, path, &len);
+	if (!strings) {
+		if (errno != E2BIG)
+			return NULL;
+		return xs_directory_part(h, t, path, num);
+	}
+
+	return xs_directory_common(strings, len, num);
+}
+
+/* Get the value of a single file, nul terminated.
+ * Returns a malloced value: call free() on it after use.
+ * len indicates length in bytes, not including the nul.
+ * Returns NULL on failure.
+ */
+void *xs_read(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, unsigned int *len)
+{
+	return xs_single(h, t, XS_READ, path, len);
+}
+
+/* Write the value of a single file.
+ * Returns false on failure.
+ */
+bool xs_write(struct xs_handle *h, xs_transaction_t t,
+	      const char *path, const void *data, unsigned int len)
+{
+	struct iovec iovec[2];
+
+	iovec[0].iov_base = (void *)path;
+	iovec[0].iov_len = strlen(path) + 1;
+	iovec[1].iov_base = (void *)data;
+	iovec[1].iov_len = len;
+
+	return xs_bool(xs_talkv(h, t, XS_WRITE, iovec,
+				ARRAY_SIZE(iovec), NULL));
+}
+
+/* Create a new directory.
+ * Returns false on failure, or success if it already exists.
+ */
+bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
+	      const char *path)
+{
+	return xs_bool(xs_single(h, t, XS_MKDIR, path, NULL));
+}
+
+/* Destroy a file or directory (directories must be empty).
+ * Returns false on failure, or success if it doesn't exist.
+ */
+bool xs_rm(struct xs_handle *h, xs_transaction_t t,
+	   const char *path)
+{
+	return xs_bool(xs_single(h, t, XS_RM, path, NULL));
+}
+
+/* Get permissions of node (first element is owner).
+ * Returns malloced array, or NULL: call free() after use.
+ */
+struct xs_permissions *xs_get_permissions(struct xs_handle *h,
+					  xs_transaction_t t,
+					  const char *path, unsigned int *num)
+{
+	char *strings;
+	unsigned int len;
+	struct xs_permissions *ret;
+
+	strings = xs_single(h, t, XS_GET_PERMS, path, &len);
+	if (!strings)
+		return NULL;
+
+	/* Count the strings: each one perms then domid. */
+	*num = xs_count_strings(strings, len);
+
+	/* Transfer to one big alloc for easy freeing. */
+	ret = malloc(*num * sizeof(struct xs_permissions));
+	if (!ret) {
+		free_no_errno(strings);
+		return NULL;
+	}
+
+	if (!xs_strings_to_perms(ret, *num, strings)) {
+		free_no_errno(ret);
+		ret = NULL;
+	}
+
+	free(strings);
+	return ret;
+}
+
+/* Set permissions of node (must be owner).
+ * Returns false on failure.
+ */
+bool xs_set_permissions(struct xs_handle *h,
+			xs_transaction_t t,
+			const char *path,
+			struct xs_permissions *perms,
+			unsigned int num_perms)
+{
+	unsigned int i;
+	struct iovec iov[1+num_perms];
+
+	iov[0].iov_base = (void *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	
+	for (i = 0; i < num_perms; i++) {
+		char buffer[MAX_STRLEN(unsigned int)+1];
+
+		if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
+			goto unwind;
+
+		iov[i+1].iov_base = strdup(buffer);
+		iov[i+1].iov_len = strlen(buffer) + 1;
+		if (!iov[i+1].iov_base)
+			goto unwind;
+	}
+
+	if (!xs_bool(xs_talkv(h, t, XS_SET_PERMS, iov, 1+num_perms, NULL)))
+		goto unwind;
+	for (i = 0; i < num_perms; i++)
+		free(iov[i+1].iov_base);
+	return true;
+
+unwind:
+	num_perms = i;
+	for (i = 0; i < num_perms; i++)
+		free_no_errno(iov[i+1].iov_base);
+	return false;
+}
+
+/* Always return false a functionality has been removed in Xen 4.9 */
+bool xs_restrict(struct xs_handle *h, unsigned domid)
+{
+	return false;
+}
+
+/* Watch a node for changes (poll on fd to detect, or call read_watch()).
+ * When the node (or any child) changes, fd will become readable.
+ * Token is returned when watch is read, to allow matching.
+ * Returns false on failure.
+ */
+bool xs_watch(struct xs_handle *h, const char *path, const char *token)
+{
+	struct iovec iov[2];
+
+#ifdef USE_PTHREAD
+#define DEFAULT_THREAD_STACKSIZE (16 * 1024)
+#define READ_THREAD_STACKSIZE 					\
+	((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? 	\
+	PTHREAD_STACK_MIN : DEFAULT_THREAD_STACKSIZE)
+
+	/* We dynamically create a reader thread on demand. */
+	mutex_lock(&h->request_mutex);
+	if (!h->read_thr_exists) {
+		sigset_t set, old_set;
+		pthread_attr_t attr;
+		static size_t stack_size;
+#ifdef USE_DLSYM
+		size_t (*getsz)(pthread_attr_t *attr);
+#endif
+
+		if (pthread_attr_init(&attr) != 0) {
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+		if (!stack_size) {
+#ifdef USE_DLSYM
+			getsz = dlsym(RTLD_DEFAULT, "__pthread_get_minstack");
+			if (getsz)
+				stack_size = getsz(&attr);
+#endif
+			if (stack_size < READ_THREAD_STACKSIZE)
+				stack_size = READ_THREAD_STACKSIZE;
+		}
+		if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
+			pthread_attr_destroy(&attr);
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+
+		sigfillset(&set);
+		pthread_sigmask(SIG_SETMASK, &set, &old_set);
+
+		if (pthread_create(&h->read_thr, &attr, read_thread, h) != 0) {
+			pthread_sigmask(SIG_SETMASK, &old_set, NULL);
+			pthread_attr_destroy(&attr);
+			mutex_unlock(&h->request_mutex);
+			return false;
+		}
+		h->read_thr_exists = 1;
+		pthread_sigmask(SIG_SETMASK, &old_set, NULL);
+		pthread_attr_destroy(&attr);
+	}
+	mutex_unlock(&h->request_mutex);
+#endif
+
+	iov[0].iov_base = (void *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	iov[1].iov_base = (void *)token;
+	iov[1].iov_len = strlen(token) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_WATCH, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+
+/* Clear the pipe token if there are no more pending watchs.
+ * We suppose the watch_mutex is already taken.
+ */
+static void xs_maybe_clear_watch_pipe(struct xs_handle *h)
+{
+	char c;
+
+	if (list_empty(&h->watch_list) && (h->watch_pipe[0] != -1))
+		while (read(h->watch_pipe[0], &c, 1) != 1)
+			continue;
+}
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array of two pointers: path and token, or NULL.
+ * Call free() after use.
+ */
+static char **read_watch_internal(struct xs_handle *h, unsigned int *num,
+				  int nonblocking)
+{
+	struct xs_stored_msg *msg;
+	char **ret, *strings;
+	unsigned int num_strings, i;
+
+	mutex_lock(&h->watch_mutex);
+
+#ifdef USE_PTHREAD
+	/* Wait on the condition variable for a watch to fire.
+	 * If the reader thread doesn't exist yet, then that's because
+	 * we haven't called xs_watch.	Presumably the application
+	 * will do so later; in the meantime we just block.
+	 */
+	while (list_empty(&h->watch_list) && h->fd != -1) {
+		if (nonblocking) {
+			mutex_unlock(&h->watch_mutex);
+			errno = EAGAIN;
+			return 0;
+		}
+		condvar_wait(&h->watch_condvar, &h->watch_mutex);
+	}
+#else /* !defined(USE_PTHREAD) */
+	/* Read from comms channel ourselves if there are no threads
+	 * and therefore no reader thread. */
+
+	assert(!read_thread_exists(h)); /* not threadsafe but worth a check */
+	if ((read_message(h, nonblocking) == -1))
+		return NULL;
+
+#endif /* !defined(USE_PTHREAD) */
+
+	if (list_empty(&h->watch_list)) {
+		mutex_unlock(&h->watch_mutex);
+		errno = EINVAL;
+		return NULL;
+	}
+	msg = list_top(&h->watch_list, struct xs_stored_msg, list);
+	list_del(&msg->list);
+
+	xs_maybe_clear_watch_pipe(h);
+	mutex_unlock(&h->watch_mutex);
+
+	assert(msg->hdr.type == XS_WATCH_EVENT);
+
+	strings     = msg->body;
+	num_strings = xs_count_strings(strings, msg->hdr.len);
+
+	ret = malloc(sizeof(char*) * num_strings + msg->hdr.len);
+	if (!ret) {
+		free_no_errno(strings);
+		free_no_errno(msg);
+		return NULL;
+	}
+
+	ret[0] = (char *)(ret + num_strings);
+	memcpy(ret[0], strings, msg->hdr.len);
+
+	free(strings);
+	free(msg);
+
+	for (i = 1; i < num_strings; i++)
+		ret[i] = ret[i - 1] + strlen(ret[i - 1]) + 1;
+
+	*num = num_strings;
+
+	return ret;
+}
+
+char **xs_check_watch(struct xs_handle *h)
+{
+	unsigned int num;
+	char **ret;
+	ret = read_watch_internal(h, &num, 1);
+	if (ret) assert(num >= 2);
+	return ret;
+}
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array of two pointers: path and token, or NULL.
+ * Call free() after use.
+ */
+char **xs_read_watch(struct xs_handle *h, unsigned int *num)
+{
+	return read_watch_internal(h, num, 0);
+}
+
+/* Remove a watch on a node.
+ * Returns false on failure (no watch on that node).
+ */
+bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)
+{
+	struct iovec iov[2];
+	struct xs_stored_msg *msg, *tmsg;
+	bool res;
+	char *s, *p;
+	unsigned int i;
+	char *l_token, *l_path;
+
+	iov[0].iov_base = (char *)path;
+	iov[0].iov_len = strlen(path) + 1;
+	iov[1].iov_base = (char *)token;
+	iov[1].iov_len = strlen(token) + 1;
+
+	res = xs_bool(xs_talkv(h, XBT_NULL, XS_UNWATCH, iov,
+			       ARRAY_SIZE(iov), NULL));
+
+	if (!h->unwatch_filter) /* Don't filter the watch list */
+		return res;
+
+
+	/* Filter the watch list to remove potential message */
+	mutex_lock(&h->watch_mutex);
+
+	if (list_empty(&h->watch_list)) {
+		mutex_unlock(&h->watch_mutex);
+		return res;
+	}
+
+	list_for_each_entry_safe(msg, tmsg, &h->watch_list, list) {
+		assert(msg->hdr.type == XS_WATCH_EVENT);
+
+		s = msg->body;
+
+		l_token = NULL;
+		l_path = NULL;
+
+		for (p = s, i = 0; p < msg->body + msg->hdr.len; p++) {
+			if (*p == '\0')
+			{
+				if (i == XS_WATCH_TOKEN)
+					l_token = s;
+				else if (i == XS_WATCH_PATH)
+					l_path = s;
+				i++;
+				s = p + 1;
+			}
+		}
+
+		if (l_token && !strcmp(token, l_token) &&
+		    l_path && xs_path_is_subpath(path, l_path)) {
+			list_del(&msg->list);
+			free(msg);
+		}
+	}
+
+	xs_maybe_clear_watch_pipe(h);
+
+	mutex_unlock(&h->watch_mutex);
+
+	return res;
+}
+
+/* Start a transaction: changes by others will not be seen during this
+ * transaction, and changes will not be visible to others until end.
+ * Returns XBT_NULL on failure.
+ */
+xs_transaction_t xs_transaction_start(struct xs_handle *h)
+{
+	char *id_str;
+	xs_transaction_t id;
+
+	id_str = xs_single(h, XBT_NULL, XS_TRANSACTION_START, "", NULL);
+	if (id_str == NULL)
+		return XBT_NULL;
+
+	id = strtoul(id_str, NULL, 0);
+	free(id_str);
+
+	return id;
+}
+
+/* End a transaction.
+ * If abandon is true, transaction is discarded instead of committed.
+ * Returns false on failure, which indicates an error: transactions will
+ * not fail spuriously.
+ */
+bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
+			bool abort)
+{
+	char abortstr[2];
+
+	if (abort)
+		strcpy(abortstr, "F");
+	else
+		strcpy(abortstr, "T");
+	
+	return xs_bool(xs_single(h, t, XS_TRANSACTION_END, abortstr, NULL));
+}
+
+/* Introduce a new domain.
+ * This tells the store daemon about a shared memory page and event channel
+ * associated with a domain: the domain uses these to communicate.
+ */
+bool xs_introduce_domain(struct xs_handle *h,
+			 unsigned int domid, unsigned long mfn,
+			 unsigned int eventchn)
+{
+	char domid_str[MAX_STRLEN(domid)];
+	char mfn_str[MAX_STRLEN(mfn)];
+	char eventchn_str[MAX_STRLEN(eventchn)];
+	struct iovec iov[3];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+	snprintf(mfn_str, sizeof(mfn_str), "%lu", mfn);
+	snprintf(eventchn_str, sizeof(eventchn_str), "%u", eventchn);
+
+	iov[0].iov_base = domid_str;
+	iov[0].iov_len = strlen(domid_str) + 1;
+	iov[1].iov_base = mfn_str;
+	iov[1].iov_len = strlen(mfn_str) + 1;
+	iov[2].iov_base = eventchn_str;
+	iov[2].iov_len = strlen(eventchn_str) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_INTRODUCE, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+bool xs_set_target(struct xs_handle *h,
+			 unsigned int domid, unsigned int target)
+{
+	char domid_str[MAX_STRLEN(domid)];
+	char target_str[MAX_STRLEN(target)];
+	struct iovec iov[2];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+	snprintf(target_str, sizeof(target_str), "%u", target);
+
+	iov[0].iov_base = domid_str;
+	iov[0].iov_len = strlen(domid_str) + 1;
+	iov[1].iov_base = target_str;
+	iov[1].iov_len = strlen(target_str) + 1;
+
+	return xs_bool(xs_talkv(h, XBT_NULL, XS_SET_TARGET, iov,
+				ARRAY_SIZE(iov), NULL));
+}
+
+static void * single_with_domid(struct xs_handle *h,
+				enum xsd_sockmsg_type type,
+				unsigned int domid)
+{
+	char domid_str[MAX_STRLEN(domid)];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+
+	return xs_single(h, XBT_NULL, type, domid_str, NULL);
+}
+
+bool xs_release_domain(struct xs_handle *h, unsigned int domid)
+{
+	return xs_bool(single_with_domid(h, XS_RELEASE, domid));
+}
+
+/* clear the shutdown bit for the given domain */
+bool xs_resume_domain(struct xs_handle *h, unsigned int domid)
+{
+	return xs_bool(single_with_domid(h, XS_RESUME, domid));
+}
+
+char *xs_get_domain_path(struct xs_handle *h, unsigned int domid)
+{
+	char domid_str[MAX_STRLEN(domid)];
+
+	snprintf(domid_str, sizeof(domid_str), "%u", domid);
+
+	return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
+}
+
+bool xs_path_is_subpath(const char *parent, const char *child)
+{
+        size_t childlen = strlen(child);
+        size_t parentlen = strlen(parent);
+
+	if (childlen < parentlen)
+		return false;
+
+	if (memcmp(child, parent, parentlen))
+		return false;
+
+	if (childlen > parentlen && child[parentlen] != '/')
+		return false;
+
+	return true;
+}
+
+bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid)
+{
+	char *domain = single_with_domid(h, XS_IS_DOMAIN_INTRODUCED, domid);
+	int rc = strcmp("F", domain);
+
+	free(domain);
+	return rc;
+}
+
+int xs_suspend_evtchn_port(int domid)
+{
+    char path[128];
+    char *portstr;
+    int port;
+    unsigned int plen;
+    struct xs_handle *xs;
+
+    xs = xs_daemon_open();
+    if (!xs)
+        return -1;
+
+    sprintf(path, "/local/domain/%d/device/suspend/event-channel", domid);
+    portstr = xs_read(xs, XBT_NULL, path, &plen);
+    xs_daemon_close(xs);
+
+    if (!portstr || !plen) {
+        port = -1;
+        goto out;
+    }
+
+    port = atoi(portstr);
+
+out:
+    free(portstr);
+    return port;
+}
+
+char *xs_control_command(struct xs_handle *h, const char *cmd,
+			 void *data, unsigned int len)
+{
+	struct iovec iov[2];
+
+	iov[0].iov_base = (void *)cmd;
+	iov[0].iov_len = strlen(cmd) + 1;
+	iov[1].iov_base = data;
+	iov[1].iov_len = len;
+
+	return xs_talkv(h, XBT_NULL, XS_CONTROL, iov,
+			ARRAY_SIZE(iov), NULL);
+}
+
+char *xs_debug_command(struct xs_handle *h, const char *cmd,
+		       void *data, unsigned int len)
+{
+	return xs_control_command(h, cmd, data, len);
+}
+
+static int read_message(struct xs_handle *h, int nonblocking)
+{
+	/* IMPORTANT: It is forbidden to call this function without
+	 * acquiring the request lock and checking that h->read_thr_exists
+	 * is false.  See "Lock discipline" in struct xs_handle, above. */
+
+	/* If nonblocking==1, this function will always read either
+	 * nothing, returning -1 and setting errno==EAGAIN, or we read
+	 * whole amount requested.  Ie as soon as we have the start of
+	 * the message we block until we get all of it.
+	 */
+         
+	struct xs_stored_msg *msg = NULL;
+	char *body = NULL;
+	int saved_errno = 0;
+	int ret = -1;
+
+	/* Allocate message structure and read the message header. */
+	msg = malloc(sizeof(*msg));
+	if (msg == NULL)
+		goto error;
+	cleanup_push_heap(msg);
+	if (!read_all(h->fd, &msg->hdr, sizeof(msg->hdr), nonblocking)) { /* Cancellation point */
+		saved_errno = errno;
+		goto error_freemsg;
+	}
+
+	/* Sanity check message body length. */
+	if (msg->hdr.len > XENSTORE_PAYLOAD_MAX) {
+		saved_errno = E2BIG;
+		goto error_freemsg;
+	}
+
+	/* Allocate and read the message body. */
+	body = msg->body = malloc(msg->hdr.len + 1);
+	if (body == NULL)
+		goto error_freemsg;
+	cleanup_push_heap(body);
+	if (!read_all(h->fd, body, msg->hdr.len, 0)) { /* Cancellation point */
+		saved_errno = errno;
+		goto error_freebody;
+	}
+
+	body[msg->hdr.len] = '\0';
+
+	if (msg->hdr.type == XS_WATCH_EVENT) {
+		mutex_lock(&h->watch_mutex);
+		cleanup_push(pthread_mutex_unlock, &h->watch_mutex);
+
+		/* Kick users out of their select() loop. */
+		if (list_empty(&h->watch_list) &&
+		    (h->watch_pipe[1] != -1))
+			while (write(h->watch_pipe[1], body, 1) != 1) /* Cancellation point */
+				continue;
+
+		list_add_tail(&msg->list, &h->watch_list);
+
+		condvar_signal(&h->watch_condvar);
+
+		cleanup_pop(1);
+	} else {
+		mutex_lock(&h->reply_mutex);
+
+		/* There should only ever be one response pending! */
+		if (!list_empty(&h->reply_list)) {
+			mutex_unlock(&h->reply_mutex);
+			saved_errno = EEXIST;
+			goto error_freebody;
+		}
+
+		list_add_tail(&msg->list, &h->reply_list);
+		condvar_signal(&h->reply_condvar);
+
+		mutex_unlock(&h->reply_mutex);
+	}
+
+	ret = 0;
+
+error_freebody:
+	cleanup_pop_heap(ret == -1, body);
+error_freemsg:
+	cleanup_pop_heap(ret == -1, msg);
+error:
+	errno = saved_errno;
+
+	return ret;
+}
+
+#ifdef USE_PTHREAD
+static void *read_thread(void *arg)
+{
+	struct xs_handle *h = arg;
+	int fd;
+
+	while (read_message(h, 0) != -1)
+		continue;
+
+	/* An error return from read_message leaves the socket in an undefined
+	 * state; we might have read only the header and not the message after
+	 * it, or (more commonly) the other end has closed the connection.
+	 * Since further communication is unsafe, close the socket.
+	 */
+	fd = h->fd;
+	h->fd = -1;
+	close(fd);
+
+	/* wake up all waiters */
+	pthread_mutex_lock(&h->reply_mutex);
+	pthread_cond_broadcast(&h->reply_condvar);
+	pthread_mutex_unlock(&h->reply_mutex);
+
+	pthread_mutex_lock(&h->watch_mutex);
+	pthread_cond_broadcast(&h->watch_condvar);
+	pthread_mutex_unlock(&h->watch_mutex);
+
+	return NULL;
+}
+#endif
+
+char *expanding_buffer_ensure(struct expanding_buffer *ebuf, int min_avail)
+{
+	int want;
+	char *got;
+
+	if (ebuf->avail >= min_avail)
+		return ebuf->buf;
+
+	if (min_avail >= INT_MAX/3)
+		return 0;
+
+	want = ebuf->avail + min_avail + 10;
+	got = realloc(ebuf->buf, want);
+	if (!got)
+		return 0;
+
+	ebuf->buf = got;
+	ebuf->avail = want;
+	return ebuf->buf;
+}
+
+char *sanitise_value(struct expanding_buffer *ebuf,
+		     const char *val, unsigned len)
+{
+	int used, remain, c;
+	unsigned char *ip;
+
+#define ADD(c) (ebuf->buf[used++] = (c))
+#define ADDF(f,c) (used += sprintf(ebuf->buf+used, (f), (c)))
+
+	assert(len < INT_MAX/5);
+
+	ip = (unsigned char *)val;
+	used = 0;
+	remain = len;
+
+	if (!expanding_buffer_ensure(ebuf, remain + 1))
+		return NULL;
+
+	while (remain-- > 0) {
+		c= *ip++;
+
+		if (c >= ' ' && c <= '~' && c != '\\') {
+			ADD(c);
+			continue;
+		}
+
+		if (!expanding_buffer_ensure(ebuf, used + remain + 5))
+			/* for "<used>\\nnn<remain>\0" */
+			return 0;
+
+		ADD('\\');
+		switch (c) {
+		case '\t':  ADD('t');   break;
+		case '\n':  ADD('n');   break;
+		case '\r':  ADD('r');   break;
+		case '\\':  ADD('\\');  break;
+		default:
+			if (c < 010) ADDF("%03o", c);
+			else         ADDF("x%02x", c);
+		}
+	}
+
+	ADD(0);
+	assert(used <= ebuf->avail);
+	return ebuf->buf;
+
+#undef ADD
+#undef ADDF
+}
+
+void unsanitise_value(char *out, unsigned *out_len_r, const char *in)
+{
+	const char *ip;
+	char *op;
+	unsigned c;
+	int n;
+
+	for (ip = in, op = out; (c = *ip++); *op++ = c) {
+		if (c == '\\') {
+			c = *ip++;
+
+#define GETF(f) do {					\
+			n = 0;				\
+			sscanf(ip, f "%n", &c, &n);	\
+			ip += n;			\
+		} while (0)
+
+			switch (c) {
+			case 't':              c= '\t';            break;
+			case 'n':              c= '\n';            break;
+			case 'r':              c= '\r';            break;
+			case '\\':             c= '\\';            break;
+			case 'x':                    GETF("%2x");  break;
+			case '0': case '4':
+			case '1': case '5':
+			case '2': case '6':
+			case '3': case '7':    --ip; GETF("%3o");  break;
+			case 0:                --ip;               break;
+			default:;
+			}
+#undef GETF
+		}
+	}
+
+	*op = 0;
+
+	if (out_len_r)
+		*out_len_r = op - out;
+}
+
+/*
+ * Local variables:
+ *  mode: C
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk
index 9619c576ba..a0fe0402ff 100644
--- a/tools/libs/uselibs.mk
+++ b/tools/libs/uselibs.mk
@@ -20,3 +20,5 @@ LIBS_LIBS += ctrl
 USELIBS_ctrl := toollog call evtchn gnttab foreignmemory devicemodel
 LIBS_LIBS += guest
 USELIBS_guest := evtchn ctrl
+LIBS_LIBS += store
+USELIBS_store := toolcore
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 24b284af39..8254464aff 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -11,7 +11,7 @@ PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
 PATH_LIBXENEVTCHN = XEN_ROOT + "/tools/libs/evtchn"
 PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
 PATH_LIBXL    = XEN_ROOT + "/tools/libxl"
-PATH_XENSTORE = XEN_ROOT + "/tools/xenstore"
+PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
 xc = Extension("xc",
                extra_compile_args = extra_compile_args,
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 574be8d15c..9a0f0d012d 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -34,17 +34,7 @@ XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o
 XENSTORED_OBJS += $(XENSTORED_OBJS_y)
 LDLIBS_xenstored += -lrt
 
-ifneq ($(XENSTORE_STATIC_CLIENTS),y)
-LIBXENSTORE := libxenstore.so
-else
-LIBXENSTORE := libxenstore.a
-xenstore xenstore-control: CFLAGS += -static
-endif
-
-ALL_TARGETS = libxenstore.a clients
-ifneq ($(nosharedlibs),y)
-ALL_TARGETS += libxenstore.so
-endif
+ALL_TARGETS = clients
 ifeq ($(XENSTORE_XENSTORED),y)
 ALL_TARGETS += xs_tdb_dump xenstored
 endif
@@ -87,64 +77,21 @@ xenstored.a: $(XENSTORED_OBJS)
 $(CLIENTS): xenstore
 	ln -f xenstore $@
 
-xenstore: xenstore_client.o $(LIBXENSTORE)
+xenstore: xenstore_client.o
 	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
-xenstore-control: xenstore_control.o $(LIBXENSTORE)
+xenstore-control: xenstore_control.o
 	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
 xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
 	$(CC) $^ $(LDFLAGS) -o $@ $(APPEND_LDFLAGS)
 
-libxenstore.so: libxenstore.so.$(MAJOR)
-	ln -sf $< $@
-libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
-	ln -sf $< $@
-
-xs.opic: CFLAGS += -DUSE_PTHREAD
-ifeq ($(CONFIG_Linux),y)
-xs.opic: CFLAGS += -DUSE_DLSYM
-libxenstore.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += -ldl
-PKG_CONFIG_LIBSPRIV := -ldl
-endif
-
-libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
-
-libxenstore.a: xs.o xs_lib.o
-	$(AR) rcs $@ $^
-
-PKG_CONFIG := xenstore.pc
-PKG_CONFIG_NAME := Xenstore
-PKG_CONFIG_DESC := The Xenstore library for Xen hypervisor
-PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
-PKG_CONFIG_USELIBS := $(SHLIB_libxenstore)
-PKG_CONFIG_LIB := xenstore
-PKG_CONFIG_REQPRIV := xenevtchn,xencontrol,xengnttab,xentoolcore
-
-ifneq ($(CONFIG_LIBXC_MINIOS),y)
-PKG_CONFIG_INST := $(PKG_CONFIG)
-$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
-$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
-$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
-endif
-
-PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
-
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstore)/include
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
-
-$(LIBXENSTORE): $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
-
 .PHONY: clean
 clean:
-	rm -f *.a *.o *.opic *.so* xenstored_probes.h
+	rm -f *.a *.o xenstored_probes.h
 	rm -f xenstored xs_random xs_stress xs_crashme
 	rm -f xs_tdb_dump xenstore-control init-xenstore-domain
 	rm -f xenstore $(CLIENTS)
-	rm -f xenstore.pc
 	$(RM) $(DEPS_RM)
 
 .PHONY: distclean
@@ -161,8 +108,6 @@ tarball: clean
 .PHONY: install
 install: all
 	$(INSTALL_DIR) $(DESTDIR)$(bindir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)/xenstore-compat
 ifeq ($(XENSTORE_XENSTORED),y)
 	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
 	$(INSTALL_DIR) $(DESTDIR)$(XEN_LIB_STORED)
@@ -173,32 +118,9 @@ endif
 	set -e ; for c in $(CLIENTS) ; do \
 		ln -f $(DESTDIR)$(bindir)/xenstore $(DESTDIR)$(bindir)/$${c} ; \
 	done
-	$(INSTALL_DIR) $(DESTDIR)$(libdir)
-	$(INSTALL_SHLIB) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
-	ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
-	ln -sf libxenstore.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenstore.so
-	$(INSTALL_DATA) libxenstore.a $(DESTDIR)$(libdir)
-	$(INSTALL_DATA) include/xenstore.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) include/xenstore_lib.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(includedir)/xenstore-compat/xs.h
-	$(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
-	ln -sf xenstore-compat/xs.h  $(DESTDIR)$(includedir)/xs.h
-	ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(includedir)/xs_lib.h
-	$(INSTALL_DATA) xenstore.pc $(DESTDIR)$(PKG_INSTALLDIR)
 
 .PHONY: uninstall
 uninstall:
-	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenstore.pc
-	rm -f $(DESTDIR)$(includedir)/xs_lib.h
-	rm -f $(DESTDIR)$(includedir)/xs.h
-	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
-	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs.h
-	rm -f $(DESTDIR)$(includedir)/xenstore_lib.h
-	rm -f $(DESTDIR)$(includedir)/xenstore.h
-	rm -f $(DESTDIR)$(libdir)/libxenstore.a
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
-	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR).$(MINOR)
 	rm -f $(addprefix $(DESTDIR)$(bindir)/, $(CLIENTS))
 	rm -f $(DESTDIR)$(bindir)/xenstore
 	rm -f $(DESTDIR)$(bindir)/xenstore-control
diff --git a/tools/xenstore/include/compat/xs.h b/tools/xenstore/include/compat/xs.h
deleted file mode 100644
index 99cf39bb1a..0000000000
--- a/tools/xenstore/include/compat/xs.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#warning xs.h is deprecated use xenstore.h instead
-#include <xenstore.h>
diff --git a/tools/xenstore/include/compat/xs_lib.h b/tools/xenstore/include/compat/xs_lib.h
deleted file mode 100644
index ad81b54c0e..0000000000
--- a/tools/xenstore/include/compat/xs_lib.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#warning xs_lib.h is deprecated use xenstore_lib.h instead
-#include <xenstore_lib.h>
diff --git a/tools/xenstore/include/xenstore.h b/tools/xenstore/include/xenstore.h
deleted file mode 100644
index 25b31881c8..0000000000
--- a/tools/xenstore/include/xenstore.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/* 
-    Xen Store Daemon providing simple tree-like database.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef XENSTORE_H
-#define XENSTORE_H
-
-#include <xenstore_lib.h>
-
-#define XBT_NULL 0
-
-#define XS_OPEN_READONLY	(1UL<<0)
-#define XS_OPEN_SOCKETONLY      (1UL<<1)
-
-/*
- * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no
- * related watch events will be delivered via xs_read_watch.  But
- * this relies on the couple token, subpath is unique.
- *
- * XS_UNWATCH_FILTER clear          XS_UNWATCH_FILTER set
- *
- * Even after xs_unwatch, "stale"   After xs_unwatch returns, no
- * instances of the watch event     watch events with the same
- * may be delivered.                token and with the same subpath
- *                                  will be delivered.
- *
- * A path and a subpath can be      The application must avoid
- * register with the same token.    registering a path (/foo/) and
- *                                  a subpath (/foo/bar) with the
- *                                  same path until a successful
- *                                  xs_unwatch for the first watch
- *                                  has returned.
- */
-#define XS_UNWATCH_FILTER     (1UL<<2)
-
-struct xs_handle;
-typedef uint32_t xs_transaction_t;
-
-/* IMPORTANT: For details on xenstore protocol limits, see
- * docs/misc/xenstore.txt in the Xen public source repository, and use the
- * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h.
- */
-
-/* On failure, these routines set errno. */
-
-/* Open a connection to the xs daemon.
- * Attempts to make a connection over the socket interface,
- * and if it fails, then over the  xenbus interface.
- * Mode 0 specifies read-write access, XS_OPEN_READONLY for
- * read-only access.
- *
- * * Connections made with xs_open(0) (which might be shared page or
- *   socket based) are only guaranteed to work in the parent after
- *   fork.
- * * Connections made with xs_open(XS_OPEN_SOCKETONLY) will be usable
- *   in either the parent or the child after fork, but not both.
- * * xs_daemon_open*() and xs_domain_open() are deprecated synonyms
- *   for xs_open(0).
- * * XS_OPEN_READONLY has no bearing on any of this.
- *
- * Returns a handle or NULL.
- */
-struct xs_handle *xs_open(unsigned long flags);
-
-/* Close the connection to the xs daemon. */
-void xs_close(struct xs_handle *xsh /* NULL ok */);
-
-/* Connect to the xs daemon.
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(0) instead
- */
-struct xs_handle *xs_daemon_open(void);
-struct xs_handle *xs_domain_open(void);
-
-/* Connect to the xs daemon (readonly for non-root clients).
- * Returns a handle or NULL.
- * Deprecated, please use xs_open(XS_OPEN_READONLY) instead
- */
-struct xs_handle *xs_daemon_open_readonly(void);
-
-/* Close the connection to the xs daemon.
- * Deprecated, please use xs_close() instead
- */
-void xs_daemon_close(struct xs_handle *);
-
-/* Throw away the connection to the xs daemon, for use after fork(). */
-void xs_daemon_destroy_postfork(struct xs_handle *);
-
-/* Get contents of a directory.
- * Returns a malloced array: call free() on it after use.
- * Num indicates size.
- * Returns NULL on failure.
- */
-char **xs_directory(struct xs_handle *h, xs_transaction_t t,
-		    const char *path, unsigned int *num);
-
-/* Get the value of a single file, nul terminated.
- * Returns a malloced value: call free() on it after use.
- * len indicates length in bytes, not including terminator.
- * Returns NULL on failure.
- */
-void *xs_read(struct xs_handle *h, xs_transaction_t t,
-	      const char *path, unsigned int *len);
-
-/* Write the value of a single file.
- * Returns false on failure.
- */
-bool xs_write(struct xs_handle *h, xs_transaction_t t,
-	      const char *path, const void *data, unsigned int len);
-
-/* Create a new directory.
- * Returns false on failure, or success if it already exists.
- */
-bool xs_mkdir(struct xs_handle *h, xs_transaction_t t,
-	      const char *path);
-
-/* Destroy a file or directory (and children).
- * Returns false on failure, or if it doesn't exist.
- */
-bool xs_rm(struct xs_handle *h, xs_transaction_t t,
-	   const char *path);
-
-/* Fake function which will always return false (required to let
- * libxenstore remain at 3.0 version.
- */
-bool xs_restrict(struct xs_handle *h, unsigned domid);
-
-/* Get permissions of node (first element is owner, first perms is "other").
- * Returns malloced array, or NULL: call free() after use.
- */
-struct xs_permissions *xs_get_permissions(struct xs_handle *h,
-					  xs_transaction_t t,
-					  const char *path, unsigned int *num);
-
-/* Set permissions of node (must be owner).  Returns false on failure.
- *
- * Domain 0 may read / write anywhere in the store, regardless of
- * permission settings.
- *
- * Note:
- * The perms array is a list of (domid, permissions) pairs. The first
- * element in the list specifies the owner of the list, plus the flags
- * for every domain not explicitly specified subsequently. The
- * subsequent entries are normal capabilities.
- *
- * Example C code:
- *
- *  struct xs_permissions perms[2];
- *
- *  perms[0].id = dm_domid;
- *  perms[0].perms = XS_PERM_NONE;
- *  perms[1].id = guest_domid;
- *  perms[1].perms = XS_PERM_READ;
- *
- * It means the owner of the path is domain $dm_domid (hence it always
- * has read and write permission), all other domains (unless specified
- * in subsequent pair) can neither read from nor write to that
- * path. It then specifies domain $guest_domid can read from that
- * path.
- */
-bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t,
-			const char *path, struct xs_permissions *perms,
-			unsigned int num_perms);
-
-/* Watch a node for changes (poll on fd to detect, or call read_watch()).
- * When the node (or any child) changes, fd will become readable.
- * Token is returned when watch is read, to allow matching.
- * Returns false on failure.
- */
-bool xs_watch(struct xs_handle *h, const char *path, const char *token);
-
-/* Return the FD to poll on to see if a watch has fired. */
-int xs_fileno(struct xs_handle *h);
-
-/* Check for node changes.  On success, returns a non-NULL pointer ret
- * such that ret[0] and ret[1] are valid C strings, namely the
- * triggering path (see docs/misc/xenstore.txt) and the token (from
- * xs_watch).  On error return value is NULL setting errno.
- * 
- * Callers should, after xs_fileno has become readable, repeatedly
- * call xs_check_watch until it returns NULL and sets errno to EAGAIN.
- * (If the fd became readable, xs_check_watch is allowed to make it no
- * longer show up as readable even if future calls to xs_check_watch
- * will return more watch events.)
- *
- * After the caller is finished with the returned information it
- * should be freed all in one go with free(ret).
- */
-char **xs_check_watch(struct xs_handle *h);
-
-/* Find out what node change was on (will block if nothing pending).
- * Returns array containing the path and token, or NULL.
- * Use XS_WATCH_* to access these elements.
- * Call free() after use.
- */
-char **xs_read_watch(struct xs_handle *h, unsigned int *num);
-
-/* Remove a watch on a node: implicitly acks any outstanding watch.
- * Returns false on failure (no watch on that node).
- */
-bool xs_unwatch(struct xs_handle *h, const char *path, const char *token);
-
-/* Start a transaction: changes by others will not be seen during this
- * transaction, and changes will not be visible to others until end.
- * Returns NULL on failure.
- */
-xs_transaction_t xs_transaction_start(struct xs_handle *h);
-
-/* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
- * Returns false on failure: if errno == EAGAIN, you have to restart
- * transaction.
- */
-bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t,
-			bool abort);
-
-/* Introduce a new domain.
- * This tells the store daemon about a shared memory page, event channel and
- * store path associated with a domain: the domain uses these to communicate.
- */
-bool xs_introduce_domain(struct xs_handle *h,
-			 unsigned int domid,
-			 unsigned long mfn,
-                         unsigned int eventchn); 
-
-/* Set the target of a domain
- * This tells the store daemon that a domain is targetting another one, so
- * it should let it tinker with it.
- */
-bool xs_set_target(struct xs_handle *h,
-		   unsigned int domid,
-		   unsigned int target);
-
-/* Resume a domain.
- * Clear the shutdown flag for this domain in the store.
- */
-bool xs_resume_domain(struct xs_handle *h, unsigned int domid);
-
-/* Release a domain.
- * Tells the store domain to release the memory page to the domain.
- */
-bool xs_release_domain(struct xs_handle *h, unsigned int domid);
-
-/* Query the home path of a domain.  Call free() after use.
- */
-char *xs_get_domain_path(struct xs_handle *h, unsigned int domid);
-
-/* Returns true if child is either equal to parent, or a node underneath
- * parent; or false otherwise.  Done by string comparison, so relative and
- * absolute pathnames never in a parent/child relationship by this
- * definition.  Cannot fail.
- */
-bool xs_path_is_subpath(const char *parent, const char *child);
-
-/* Return whether the domain specified has been introduced to xenstored.
- */
-bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid);
-
-char *xs_control_command(struct xs_handle *h, const char *cmd,
-			 void *data, unsigned int len);
-/* Deprecated: use xs_control_command() instead. */
-char *xs_debug_command(struct xs_handle *h, const char *cmd,
-		       void *data, unsigned int len);
-
-int xs_suspend_evtchn_port(int domid);
-#endif /* XENSTORE_H */
-
-/*
- * Local variables:
- *  mode: C
- *  c-file-style: "linux"
- *  indent-tabs-mode: t
- *  c-basic-offset: 8
- *  tab-width: 8
- * End:
- */
diff --git a/tools/xenstore/include/xenstore_lib.h b/tools/xenstore/include/xenstore_lib.h
deleted file mode 100644
index 0ffbae9eb5..0000000000
--- a/tools/xenstore/include/xenstore_lib.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 
-    Common routines between Xen store user library and daemon.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef XENSTORE_LIB_H
-#define XENSTORE_LIB_H
-
-#include <stddef.h>
-#include <stdbool.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdint.h>
-#include <xen/io/xs_wire.h>
-
-/* Bitmask of permissions. */
-enum xs_perm_type {
-	XS_PERM_NONE = 0,
-	XS_PERM_READ = 1,
-	XS_PERM_WRITE = 2,
-	/* Internal use. */
-	XS_PERM_ENOENT_OK = 4,
-	XS_PERM_OWNER = 8,
-};
-
-struct xs_permissions
-{
-	unsigned int id;
-	enum xs_perm_type perms;
-};
-
-/* Header of the node record in tdb. */
-struct xs_tdb_record_hdr {
-	uint64_t generation;
-	uint32_t num_perms;
-	uint32_t datalen;
-	uint32_t childlen;
-	struct xs_permissions perms[0];
-};
-
-/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
-#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
-
-/* Path for various daemon things: env vars can override. */
-const char *xs_daemon_rootdir(void);
-const char *xs_daemon_rundir(void);
-const char *xs_daemon_socket(void);
-const char *xs_daemon_socket_ro(void);
-const char *xs_domain_dev(void);
-const char *xs_daemon_tdb(void);
-
-/* Simple write function: loops for you. */
-bool xs_write_all(int fd, const void *data, unsigned int len);
-
-/* Convert strings to permissions.  False if a problem. */
-bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
-			 const char *strings);
-
-/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
-bool xs_perm_to_string(const struct xs_permissions *perm,
-                       char *buffer, size_t buf_len);
-
-/* Given a string and a length, count how many strings (nul terms). */
-unsigned int xs_count_strings(const char *strings, unsigned int len);
-
-/* Sanitising (quoting) possibly-binary strings. */
-struct expanding_buffer {
-	char *buf;
-	int avail;
-};
-
-/* Ensure that given expanding buffer has at least min_avail characters. */
-char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail);
-
-/* sanitise_value() may return NULL if malloc fails. */
-char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len);
-
-/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
-void unsanitise_value(char *out, unsigned *out_len_r, const char *in);
-
-#endif /* XENSTORE_LIB_H */
diff --git a/tools/xenstore/xenstore_lib.h b/tools/xenstore/xenstore_lib.h
new file mode 100644
index 0000000000..0ffbae9eb5
--- /dev/null
+++ b/tools/xenstore/xenstore_lib.h
@@ -0,0 +1,94 @@
+/* 
+    Common routines between Xen store user library and daemon.
+    Copyright (C) 2005 Rusty Russell IBM Corporation
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef XENSTORE_LIB_H
+#define XENSTORE_LIB_H
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdint.h>
+#include <xen/io/xs_wire.h>
+
+/* Bitmask of permissions. */
+enum xs_perm_type {
+	XS_PERM_NONE = 0,
+	XS_PERM_READ = 1,
+	XS_PERM_WRITE = 2,
+	/* Internal use. */
+	XS_PERM_ENOENT_OK = 4,
+	XS_PERM_OWNER = 8,
+};
+
+struct xs_permissions
+{
+	unsigned int id;
+	enum xs_perm_type perms;
+};
+
+/* Header of the node record in tdb. */
+struct xs_tdb_record_hdr {
+	uint64_t generation;
+	uint32_t num_perms;
+	uint32_t datalen;
+	uint32_t childlen;
+	struct xs_permissions perms[0];
+};
+
+/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
+#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
+
+/* Path for various daemon things: env vars can override. */
+const char *xs_daemon_rootdir(void);
+const char *xs_daemon_rundir(void);
+const char *xs_daemon_socket(void);
+const char *xs_daemon_socket_ro(void);
+const char *xs_domain_dev(void);
+const char *xs_daemon_tdb(void);
+
+/* Simple write function: loops for you. */
+bool xs_write_all(int fd, const void *data, unsigned int len);
+
+/* Convert strings to permissions.  False if a problem. */
+bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
+			 const char *strings);
+
+/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
+bool xs_perm_to_string(const struct xs_permissions *perm,
+                       char *buffer, size_t buf_len);
+
+/* Given a string and a length, count how many strings (nul terms). */
+unsigned int xs_count_strings(const char *strings, unsigned int len);
+
+/* Sanitising (quoting) possibly-binary strings. */
+struct expanding_buffer {
+	char *buf;
+	int avail;
+};
+
+/* Ensure that given expanding buffer has at least min_avail characters. */
+char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail);
+
+/* sanitise_value() may return NULL if malloc fails. */
+char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len);
+
+/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
+void unsanitise_value(char *out, unsigned *out_len_r, const char *in);
+
+#endif /* XENSTORE_LIB_H */
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
deleted file mode 100644
index aa1d24b8b9..0000000000
--- a/tools/xenstore/xs.c
+++ /dev/null
@@ -1,1473 +0,0 @@
-/* 
-    Xen Store Daemon interface providing simple tree-like database.
-    Copyright (C) 2005 Rusty Russell IBM Corporation
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#define _GNU_SOURCE
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdint.h>
-#include <errno.h>
-#include "xenstore.h"
-#include "list.h"
-#include "utils.h"
-
-#include <xentoolcore_internal.h>
-
-struct xs_stored_msg {
-	struct list_head list;
-	struct xsd_sockmsg hdr;
-	char *body;
-};
-
-#ifdef USE_PTHREAD
-
-#include <pthread.h>
-
-#ifdef USE_DLSYM
-#include <dlfcn.h>
-#endif
-
-struct xs_handle {
-	/* Communications channel to xenstore daemon. */
-	int fd;
-	Xentoolcore__Active_Handle tc_ah; /* for restrict */
-
-	/*
-         * A read thread which pulls messages off the comms channel and
-         * signals waiters.
-         */
-	pthread_t read_thr;
-	int read_thr_exists;
-
-	/*
-         * A list of fired watch messages, protected by a mutex. Users can
-         * wait on the conditional variable until a watch is pending.
-         */
-	struct list_head watch_list;
-	pthread_mutex_t watch_mutex;
-	pthread_cond_t watch_condvar;
-
-	/* Clients can select() on this pipe to wait for a watch to fire. */
-	int watch_pipe[2];
-	/* Filtering watch event in unwatch function? */
-	bool unwatch_filter;
-
-	/*
-         * A list of replies. Currently only one will ever be outstanding
-         * because we serialise requests. The requester can wait on the
-         * conditional variable for its response.
-         */
-	struct list_head reply_list;
-	pthread_mutex_t reply_mutex;
-	pthread_cond_t reply_condvar;
-
-	/* One request at a time. */
-	pthread_mutex_t request_mutex;
-
-	/* Lock discipline:
-	 *  Only holder of the request lock may write to h->fd.
-	 *  Only holder of the request lock may access read_thr_exists.
-	 *  If read_thr_exists==0, only holder of request lock may read h->fd;
-	 *  If read_thr_exists==1, only the read thread may read h->fd.
-	 *  Only holder of the reply lock may access reply_list.
-	 *  Only holder of the watch lock may access watch_list.
-	 * Lock hierarchy:
-	 *  The order in which to acquire locks is
-	 *     request_mutex
-	 *     reply_mutex
-	 *     watch_mutex
-	 */
-};
-
-#define mutex_lock(m)		pthread_mutex_lock(m)
-#define mutex_unlock(m)		pthread_mutex_unlock(m)
-#define condvar_signal(c)	pthread_cond_signal(c)
-#define condvar_wait(c,m)	pthread_cond_wait(c,m)
-#define cleanup_push(f, a)	\
-    pthread_cleanup_push((void (*)(void *))(f), (void *)(a))
-/*
- * Some definitions of pthread_cleanup_pop() are a macro starting with an
- * end-brace. GCC then complains if we immediately precede that with a label.
- * Hence we insert a dummy statement to appease the compiler in this situation.
- */
-#define cleanup_pop(run)        ((void)0); pthread_cleanup_pop(run)
-
-#define read_thread_exists(h)	(h->read_thr_exists)
-
-/* Because pthread_cleanup_p* are not available when USE_PTHREAD is
- * disabled, use these macros which convert appropriately. */
-#define cleanup_push_heap(p)        cleanup_push(free, p)
-#define cleanup_pop_heap(run, p)    cleanup_pop((run))
-
-static void *read_thread(void *arg);
-
-#else /* !defined(USE_PTHREAD) */
-
-struct xs_handle {
-	int fd;
-	Xentoolcore__Active_Handle tc_ah; /* for restrict */
-	struct list_head reply_list;
-	struct list_head watch_list;
-	/* Clients can select() on this pipe to wait for a watch to fire. */
-	int watch_pipe[2];
-	/* Filtering watch event in unwatch function? */
-	bool unwatch_filter;
-};
-
-#define mutex_lock(m)		((void)0)
-#define mutex_unlock(m)		((void)0)
-#define condvar_signal(c)	((void)0)
-#define condvar_wait(c,m)	((void)0)
-#define cleanup_push(f, a)	((void)0)
-#define cleanup_pop(run)	((void)0)
-#define read_thread_exists(h)	(0)
-
-#define cleanup_push_heap(p)        ((void)0)
-#define cleanup_pop_heap(run, p)    do { if ((run)) free(p); } while(0)
-
-#endif
-
-static int read_message(struct xs_handle *h, int nonblocking);
-
-static bool setnonblock(int fd, int nonblock) {
-	int flags = fcntl(fd, F_GETFL);
-	if (flags == -1)
-		return false;
-
-	if (nonblock)
-		flags |= O_NONBLOCK;
-	else
-		flags &= ~O_NONBLOCK;
-
-	if (fcntl(fd, F_SETFL, flags) == -1)
-		return false;
-
-	return true;
-}
-
-int xs_fileno(struct xs_handle *h)
-{
-	char c = 0;
-
-	mutex_lock(&h->watch_mutex);
-
-	if ((h->watch_pipe[0] == -1) && (pipe(h->watch_pipe) != -1)) {
-		/* Kick things off if the watch list is already non-empty. */
-		if (!list_empty(&h->watch_list))
-			while (write(h->watch_pipe[1], &c, 1) != 1)
-				continue;
-	}
-
-	mutex_unlock(&h->watch_mutex);
-
-	return h->watch_pipe[0];
-}
-
-static int get_socket(const char *connect_to)
-{
-	struct sockaddr_un addr;
-	int sock, saved_errno, flags;
-
-	sock = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (sock < 0)
-		return -1;
-
-	if ((flags = fcntl(sock, F_GETFD)) < 0)
-		goto error;
-	flags |= FD_CLOEXEC;
-	if (fcntl(sock, F_SETFD, flags) < 0)
-		goto error;
-
-	addr.sun_family = AF_UNIX;
-	if(strlen(connect_to) >= sizeof(addr.sun_path)) {
-		errno = EINVAL;
-		goto error;
-	}
-	strcpy(addr.sun_path, connect_to);
-
-	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
-		goto error;
-
-	return sock;
-
-error:
-	saved_errno = errno;
-	close(sock);
-	errno = saved_errno;
-	return -1;
-}
-
-static int get_dev(const char *connect_to)
-{
-	/* We cannot open read-only because requests are writes */
-	return open(connect_to, O_RDWR);
-}
-
-static int all_restrict_cb(Xentoolcore__Active_Handle *ah, domid_t domid) {
-    struct xs_handle *h = CONTAINER_OF(ah, *h, tc_ah);
-    return xentoolcore__restrict_by_dup2_null(h->fd);
-}
-
-static struct xs_handle *get_handle(const char *connect_to)
-{
-	struct stat buf;
-	struct xs_handle *h = NULL;
-	int saved_errno;
-
-	h = malloc(sizeof(*h));
-	if (h == NULL)
-		goto err;
-
-	memset(h, 0, sizeof(*h));
-	h->fd = -1;
-
-	h->tc_ah.restrict_callback = all_restrict_cb;
-	xentoolcore__register_active_handle(&h->tc_ah);
-
-	if (stat(connect_to, &buf) != 0)
-		goto err;
-
-	if (S_ISSOCK(buf.st_mode))
-		h->fd = get_socket(connect_to);
-	else
-		h->fd = get_dev(connect_to);
-
-	if (h->fd == -1)
-		goto err;
-
-	INIT_LIST_HEAD(&h->reply_list);
-	INIT_LIST_HEAD(&h->watch_list);
-
-	/* Watch pipe is allocated on demand in xs_fileno(). */
-	h->watch_pipe[0] = h->watch_pipe[1] = -1;
-
-	h->unwatch_filter = false;
-
-#ifdef USE_PTHREAD
-	pthread_mutex_init(&h->watch_mutex, NULL);
-	pthread_cond_init(&h->watch_condvar, NULL);
-
-	pthread_mutex_init(&h->reply_mutex, NULL);
-	pthread_cond_init(&h->reply_condvar, NULL);
-
-	pthread_mutex_init(&h->request_mutex, NULL);


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:33 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:33 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMM1-0006SX-9C; Fri, 18 Sep 2020 19:47:33 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMM0-0006SS-Ca
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:32 +0000
X-Inumbo-ID: 0a984abd-20e9-4d6c-a7d7-903e6b421be0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 0a984abd-20e9-4d6c-a7d7-903e6b421be0;
 Fri, 18 Sep 2020 19:47:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=9GEi4sJlShHw1YguHhUvD6Y1xaEBrPvV9SxPjg/reRA=; b=KwaYyDKyJ+frgVU0oU5Q6bmeMd
 ZTPjQ3kwEFSxQa9+LcqS+zQyqdhLzVpMeMQGTIPnzMdsfBOvvgkBdvlPfDZnMlB3Huona2Wsf5i0m
 Du4Y0QEBcmtp2WnOp76pfVeR5Jeg+JZQw5OrA4rmOMWAKWB25H+SdK/HnIPH4RRnX9ss=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLv-00078p-Db
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMLt-0004S8-QP
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: split libxenvchan into new tools/libs/vchan
 directory
Message-Id: <E1kJMLt-0004S8-QP@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8ab2429f1221ebae9fc8e72d8af205f3db93cde2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:37 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenvchan into new tools/libs/vchan directory
    
    There is no reason why libvchan is not placed in the tools/libs
    directory.
    
    At the same time move libxenvchan.h to a dedicated include directory
    in tools/libs/vchan in order to follow the same pattern as the other
    libraries in tools/libs.
    
    As tools/libvchan now contains no library any longer rename it to
    tools/vchan.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                             |   8 +-
 tools/Makefile                         |   2 +-
 tools/Rules.mk                         |   6 -
 tools/libs/Makefile                    |   1 +
 tools/libs/uselibs.mk                  |   2 +
 tools/libs/vchan/Makefile              |  20 ++
 tools/libs/vchan/include/libxenvchan.h | 176 +++++++++++
 tools/libs/vchan/init.c                | 461 ++++++++++++++++++++++++++++
 tools/libs/vchan/io.c                  | 388 ++++++++++++++++++++++++
 tools/libvchan/Makefile                | 100 -------
 tools/libvchan/init.c                  | 461 ----------------------------
 tools/libvchan/io.c                    | 388 ------------------------
 tools/libvchan/libxenvchan.h           | 176 -----------
 tools/libvchan/node-select.c           | 186 ------------
 tools/libvchan/node.c                  | 168 -----------
 tools/libvchan/vchan-socket-proxy.c    | 533 ---------------------------------
 tools/vchan/Makefile                   |  37 +++
 tools/vchan/node-select.c              | 186 ++++++++++++
 tools/vchan/node.c                     | 168 +++++++++++
 tools/vchan/vchan-socket-proxy.c       | 533 +++++++++++++++++++++++++++++++++
 20 files changed, 1978 insertions(+), 2022 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1335034fd3..364b09506b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -134,6 +134,9 @@ tools/libs/store/utils.h
 tools/libs/store/xenstore.pc
 tools/libs/store/xs_lib.c
 tools/libs/store/include/xenstore_lib.h
+tools/libs/vchan/headers.chk
+tools/libs/vchan/libxenvchan.map
+tools/libs/vchan/xenvchan.pc
 tools/console/xenconsole
 tools/console/xenconsoled
 tools/console/client/_paths.h
@@ -209,7 +212,6 @@ tools/include/xen/*
 tools/include/xen-xsm/*
 tools/include/xen-foreign/*.(c|h|size)
 tools/include/xen-foreign/checker
-tools/libvchan/xenvchan.pc
 tools/libxl/_libxl.api-for-check
 tools/libxl/*.api-ok
 tools/libxl/*.pc
@@ -389,8 +391,8 @@ tools/misc/xenhypfs
 tools/misc/xenwatchdogd
 tools/misc/xen-hvmcrash
 tools/misc/xen-lowmemd
-tools/libvchan/vchan-node[12]
-tools/libvchan/vchan-socket-proxy
+tools/vchan/vchan-node[12]
+tools/vchan/vchan-socket-proxy
 tools/ocaml/*/.ocamldep.make
 tools/ocaml/*/*.cm[ixao]
 tools/ocaml/*/*.cmxa
diff --git a/tools/Makefile b/tools/Makefile
index 4a3646871c..0db01707a4 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -20,7 +20,7 @@ SUBDIRS-y += xenmon
 SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
 SUBDIRS-y += libfsimage
-SUBDIRS-$(CONFIG_Linux) += libvchan
+SUBDIRS-$(CONFIG_Linux) += vchan
 
 # do not recurse in to a dir we are about to delete
 ifneq "$(MAKECMDGOALS)" "distclean"
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 21aa8ea844..5f17492a68 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -19,7 +19,6 @@ XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
 XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
-XEN_libxenvchan    = $(XEN_ROOT)/tools/libvchan
 
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
@@ -114,11 +113,6 @@ SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
 LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_libxenstat)/libxenstat$(libextension)
 SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_libxenstat)
 
-CFLAGS_libxenvchan = -I$(XEN_libxenvchan) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab)
-LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_libxenvchan)/libxenvchan$(libextension)
-SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_libxenvchan)
-
 ifeq ($(debug),y)
 # Disable optimizations
 CFLAGS += -O0 -fno-omit-frame-pointer
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 62bd8f5292..756d059ee7 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -13,6 +13,7 @@ SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 SUBDIRS-y += store
+SUBDIRS-$(CONFIG_Linux) += vchan
 
 ifeq ($(CONFIG_RUMP),y)
 SUBDIRS-y := toolcore
diff --git a/tools/libs/uselibs.mk b/tools/libs/uselibs.mk
index a0fe0402ff..edb4b34256 100644
--- a/tools/libs/uselibs.mk
+++ b/tools/libs/uselibs.mk
@@ -22,3 +22,5 @@ LIBS_LIBS += guest
 USELIBS_guest := evtchn ctrl
 LIBS_LIBS += store
 USELIBS_store := toolcore
+LIBS_LIBS += vchan
+USELIBS_vchan := toollog store gnttab evtchn
diff --git a/tools/libs/vchan/Makefile b/tools/libs/vchan/Makefile
new file mode 100644
index 0000000000..87ff608f45
--- /dev/null
+++ b/tools/libs/vchan/Makefile
@@ -0,0 +1,20 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += $(CFLAGS_libxenctrl)
+
+LIBHEADER := libxenvchan.h
+
+SRCS-y += init.c
+SRCS-y += io.c
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f libxenvchan.map
diff --git a/tools/libs/vchan/include/libxenvchan.h b/tools/libs/vchan/include/libxenvchan.h
new file mode 100644
index 0000000000..d6010b145d
--- /dev/null
+++ b/tools/libs/vchan/include/libxenvchan.h
@@ -0,0 +1,176 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
+ *  this code has been substantially rewritten to use the gntdev and gntalloc
+ *  devices instead of raw MFNs and map_foreign_range.
+ *
+ *  This is a library for inter-domain communication.  A standard Xen ring
+ *  buffer is used, with a datagram-based interface built on top.  The grant
+ *  reference and event channels are shared in XenStore under the path
+ *  /local/domain/<srv-id>/data/vchan/<cli-id>/<port>/{ring-ref,event-channel}
+ *
+ *  The ring.h macros define an asymmetric interface to a shared data structure
+ *  that assumes all rings reside in a single contiguous memory space. This is
+ *  not suitable for vchan because the interface to the ring is symmetric except
+ *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
+ *  size of the rings used in vchan are determined at execution time instead of
+ *  compile time, so the macros in ring.h cannot be used to access the rings.
+ */
+
+#include <xen/io/libxenvchan.h>
+#include <xen/xen.h>
+#include <xen/sys/evtchn.h>
+#include <xenevtchn.h>
+#include <xengnttab.h>
+
+/* Callers who don't care don't need to #include <xentoollog.h> */
+struct xentoollog_logger;
+
+struct libxenvchan_ring {
+	/* Pointer into the shared page. Offsets into buffer. */
+	struct ring_shared* shr;
+	/* ring data; may be its own shared page(s) depending on order */
+	void* buffer;
+	/**
+	 * The size of the ring is (1 << order); offsets wrap around when they
+	 * exceed this. This copy is required because we can't trust the order
+	 * in the shared page to remain constant.
+	 */
+	int order;
+};
+
+/**
+ * struct libxenvchan: control structure passed to all library calls
+ */
+struct libxenvchan {
+	/* Mapping handle for shared ring page */
+	union {
+		xengntshr_handle *gntshr; /* for server */
+		xengnttab_handle *gnttab; /* for client */
+	};
+	/* Pointer to shared ring page */
+	struct vchan_interface *ring;
+	/* event channel interface */
+	xenevtchn_handle *event;
+	uint32_t event_port;
+	/* informative flags: are we acting as server? */
+	int is_server:1;
+	/* true if server remains active when client closes (allows reconnection) */
+	int server_persist:1;
+	/* true if operations should block instead of returning 0 */
+	int blocking:1;
+	/* communication rings */
+	struct libxenvchan_ring read, write;
+};
+
+/**
+ * Set up a vchan, including granting pages
+ * @param logger Logger for libxc errors
+ * @param domain The peer domain that will be connecting
+ * @param xs_path Base xenstore path for storing ring/event data
+ * @param send_min The minimum size (in bytes) of the send ring (left)
+ * @param recv_min The minimum size (in bytes) of the receive ring (right)
+ * @return The structure, or NULL in case of an error
+ */
+struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path,
+                                            size_t read_min, size_t write_min);
+/**
+ * Connect to an existing vchan. Note: you can reconnect to an existing vchan
+ * safely, however no locking is performed, so you must prevent multiple clients
+ * from connecting to a single server.
+ *
+ * @param logger Logger for libxc errors
+ * @param domain The peer domain to connect to
+ * @param xs_path Base xenstore path for storing ring/event data
+ * @return The structure, or NULL in case of an error
+ */
+struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path);
+/**
+ * Close a vchan. This deallocates the vchan and attempts to free its
+ * resources. The other side is notified of the close, but can still read any
+ * data pending prior to the close.
+ */
+void libxenvchan_close(struct libxenvchan *ctrl);
+
+/**
+ * Packet-based receive: always reads exactly $size bytes.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data that was read
+ * @param size Size of the buffer and amount of data to read
+ * @return -1 on error, 0 if nonblocking and insufficient data is available, or $size
+ */
+int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size);
+/**
+ * Stream-based receive: reads as much data as possible.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data that was read
+ * @param size Size of the buffer
+ * @return -1 on error, otherwise the amount of data read (which may be zero if
+ *         the vchan is nonblocking)
+ */
+int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size);
+/**
+ * Packet-based send: send entire buffer if possible
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data to send
+ * @param size Size of the buffer and amount of data to send
+ * @return -1 on error, 0 if nonblocking and insufficient space is available, or $size
+ */
+int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size);
+/**
+ * Stream-based send: send as much data as possible.
+ * @param ctrl The vchan control structure
+ * @param data Buffer for data to send
+ * @param size Size of the buffer
+ * @return -1 on error, otherwise the amount of data sent (which may be zero if
+ *         the vchan is nonblocking)
+ */
+int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size);
+/**
+ * Waits for reads or writes to unblock, or for a close
+ */
+int libxenvchan_wait(struct libxenvchan *ctrl);
+/**
+ * Returns the event file descriptor for this vchan. When this FD is readable,
+ * libxenvchan_wait() will not block, and the state of the vchan has changed since
+ * the last invocation of libxenvchan_wait().
+ */
+int libxenvchan_fd_for_select(struct libxenvchan *ctrl);
+/**
+ * Query the state of the vchan shared page:
+ *  return 0 when one side has called libxenvchan_close() or crashed
+ *  return 1 when both sides are open
+ *  return 2 [server only] when no client has yet connected
+ */
+int libxenvchan_is_open(struct libxenvchan* ctrl);
+/** Amount of data ready to read, in bytes */
+int libxenvchan_data_ready(struct libxenvchan *ctrl);
+/** Amount of data it is possible to send without blocking */
+int libxenvchan_buffer_space(struct libxenvchan *ctrl);
diff --git a/tools/libs/vchan/init.c b/tools/libs/vchan/init.c
new file mode 100644
index 0000000000..ad4b64fbe3
--- /dev/null
+++ b/tools/libs/vchan/init.c
@@ -0,0 +1,461 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  This file contains the setup code used to establish the ring buffer.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/user.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <xenstore.h>
+#include <xen/xen.h>
+#include <xen/sys/evtchn.h>
+#include <xen/sys/gntalloc.h>
+#include <xen/sys/gntdev.h>
+#include <libxenvchan.h>
+
+#ifndef PAGE_SHIFT
+#define PAGE_SHIFT 12
+#endif
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+#define SMALL_RING_SHIFT 10
+#define LARGE_RING_SHIFT 11
+
+#define MAX_SMALL_RING (1 << SMALL_RING_SHIFT)
+#define SMALL_RING_OFFSET 1024
+#define MAX_LARGE_RING (1 << LARGE_RING_SHIFT)
+#define LARGE_RING_OFFSET 2048
+
+// if you go over this size, you'll have too many grants to fit in the shared page.
+#define MAX_RING_SHIFT 20
+#define MAX_RING_SIZE (1 << MAX_RING_SHIFT)
+
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define max(a,b) ((a > b) ? a : b)
+
+static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
+{
+	int pages_left = ctrl->read.order >= PAGE_SHIFT ? 1 << (ctrl->read.order - PAGE_SHIFT) : 0;
+	int pages_right = ctrl->write.order >= PAGE_SHIFT ? 1 << (ctrl->write.order - PAGE_SHIFT) : 0;
+	uint32_t ring_ref = -1;
+	void *ring;
+
+	ring = xengntshr_share_page_notify(ctrl->gntshr, domain,
+			&ring_ref, 1, offsetof(struct vchan_interface, srv_live),
+			ctrl->event_port);
+
+	if (!ring)
+		goto out;
+
+	memset(ring, 0, PAGE_SIZE);
+
+	ctrl->ring = ring;
+	ctrl->read.shr = &ctrl->ring->left;
+	ctrl->write.shr = &ctrl->ring->right;
+	ctrl->ring->left_order = ctrl->read.order;
+	ctrl->ring->right_order = ctrl->write.order;
+	ctrl->ring->cli_live = 2;
+	ctrl->ring->srv_live = 1;
+	ctrl->ring->cli_notify = VCHAN_NOTIFY_WRITE;
+
+	switch (ctrl->read.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
+			pages_left, ctrl->ring->grants, 1);
+		if (!ctrl->read.buffer)
+			goto out_ring;
+	}
+
+	switch (ctrl->write.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
+			pages_right, ctrl->ring->grants + pages_left, 1);
+		if (!ctrl->write.buffer)
+			goto out_unmap_left;
+	}
+
+out:
+	return ring_ref;
+out_unmap_left:
+	if (pages_left)
+		xengntshr_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left);
+out_ring:
+	xengntshr_unshare(ctrl->gntshr, ring, 1);
+	ring_ref = -1;
+	ctrl->ring = NULL;
+	ctrl->write.order = ctrl->read.order = 0;
+	goto out;
+}
+
+static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
+{
+	int rv = -1;
+	uint32_t *grants;
+
+	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
+		domain, ring_ref, PROT_READ|PROT_WRITE,
+		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
+
+	if (!ctrl->ring)
+		goto out;
+
+	ctrl->write.order = ctrl->ring->left_order;
+	ctrl->read.order = ctrl->ring->right_order;
+	ctrl->write.shr = &ctrl->ring->left;
+	ctrl->read.shr = &ctrl->ring->right;
+	if (ctrl->write.order < SMALL_RING_SHIFT || ctrl->write.order > MAX_RING_SHIFT)
+		goto out_unmap_ring;
+	if (ctrl->read.order < SMALL_RING_SHIFT || ctrl->read.order > MAX_RING_SHIFT)
+		goto out_unmap_ring;
+	if (ctrl->read.order == ctrl->write.order && ctrl->read.order < PAGE_SHIFT)
+		goto out_unmap_ring;
+
+	grants = ctrl->ring->grants;
+
+	switch (ctrl->write.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		{
+			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
+			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
+				pages_left, domain, grants, PROT_READ|PROT_WRITE);
+			if (!ctrl->write.buffer)
+				goto out_unmap_ring;
+			grants += pages_left;
+		}
+	}
+
+	switch (ctrl->read.order) {
+	case SMALL_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
+		break;
+	case LARGE_RING_SHIFT:
+		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
+		break;
+	default:
+		{
+			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
+			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
+				pages_right, domain, grants, PROT_READ);
+			if (!ctrl->read.buffer)
+				goto out_unmap_left;
+		}
+	}
+
+	rv = 0;
+ out:
+	return rv;
+ out_unmap_left:
+	if (ctrl->write.order >= PAGE_SHIFT)
+		xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer,
+		                1 << (ctrl->write.order - PAGE_SHIFT));
+ out_unmap_ring:
+	xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
+	ctrl->ring = 0;
+	ctrl->write.order = ctrl->read.order = 0;
+	rv = -1;
+	goto out;
+}
+
+static int init_evt_srv(struct libxenvchan *ctrl, int domain,
+                        struct xentoollog_logger *logger)
+{
+	xenevtchn_port_or_error_t port;
+
+	ctrl->event = xenevtchn_open(logger, 0);
+	if (!ctrl->event)
+		return -1;
+
+	port = xenevtchn_bind_unbound_port(ctrl->event, domain);
+	if (port < 0)
+		goto fail;
+	ctrl->event_port = port;
+
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
+		goto fail;
+
+	return 0;
+
+fail:
+	if (port >= 0)
+		xenevtchn_unbind(ctrl->event, port);
+
+	xenevtchn_close(ctrl->event);
+	ctrl->event = NULL;
+
+	return -1;
+}
+
+static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref)
+{
+	int ret = -1;
+	struct xs_handle *xs;
+	struct xs_permissions perms[2];
+	char buf[64];
+	char ref[16];
+	char* domid_str = NULL;
+	xs_transaction_t xs_trans = XBT_NULL;
+	xs = xs_domain_open();
+	if (!xs)
+		goto fail;
+	domid_str = xs_read(xs, 0, "domid", NULL);
+	if (!domid_str)
+		goto fail_xs_open;
+
+	// owner domain is us
+	perms[0].id = atoi(domid_str);
+	// permissions for domains not listed = none
+	perms[0].perms = XS_PERM_NONE;
+	// other domains
+	perms[1].id = domain;
+	perms[1].perms = XS_PERM_READ;
+
+retry_transaction:
+	xs_trans = xs_transaction_start(xs);
+	if (!xs_trans)
+		goto fail_xs_open;
+
+	snprintf(ref, sizeof ref, "%d", ring_ref);
+	snprintf(buf, sizeof buf, "%s/ring-ref", xs_base);
+	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+		goto fail_xs_open;
+	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+		goto fail_xs_open;
+
+	snprintf(ref, sizeof ref, "%d", ctrl->event_port);
+	snprintf(buf, sizeof buf, "%s/event-channel", xs_base);
+	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
+		goto fail_xs_open;
+	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
+		goto fail_xs_open;
+
+	if (!xs_transaction_end(xs, xs_trans, 0)) {
+		if (errno == EAGAIN)
+			goto retry_transaction;
+	} else {
+		ret = 0;
+	}
+ fail_xs_open:
+	free(domid_str);
+	xs_daemon_close(xs);
+ fail:
+	return ret;
+}
+
+static int min_order(size_t siz)
+{
+	int rv = PAGE_SHIFT;
+	while (siz > (1 << rv))
+		rv++;
+	return rv;
+}
+
+struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path,
+                                            size_t left_min, size_t right_min)
+{
+	struct libxenvchan *ctrl;
+	int ring_ref;
+	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
+		return 0;
+
+	ctrl = malloc(sizeof(*ctrl));
+	if (!ctrl)
+		return 0;
+
+	ctrl->ring = NULL;
+	ctrl->event = NULL;
+	ctrl->is_server = 1;
+	ctrl->server_persist = 0;
+
+	ctrl->read.order = min_order(left_min);
+	ctrl->write.order = min_order(right_min);
+
+	// if we can avoid allocating extra pages by using in-page rings, do so
+	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
+		ctrl->read.order = SMALL_RING_SHIFT;
+		ctrl->write.order = LARGE_RING_SHIFT;
+	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
+		ctrl->read.order = LARGE_RING_SHIFT;
+		ctrl->write.order = SMALL_RING_SHIFT;
+	} else if (left_min <= MAX_LARGE_RING) {
+		ctrl->read.order = LARGE_RING_SHIFT;
+	} else if (right_min <= MAX_LARGE_RING) {
+		ctrl->write.order = LARGE_RING_SHIFT;
+	}
+
+	ctrl->gntshr = xengntshr_open(logger, 0);
+	if (!ctrl->gntshr) {
+		free(ctrl);
+		return 0;
+	}
+
+	if (init_evt_srv(ctrl, domain, logger))
+		goto out;
+	ring_ref = init_gnt_srv(ctrl, domain);
+	if (ring_ref < 0)
+		goto out;
+	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
+		goto out;
+	return ctrl;
+out:
+	libxenvchan_close(ctrl);
+	return 0;
+}
+
+static int init_evt_cli(struct libxenvchan *ctrl, int domain,
+                        struct xentoollog_logger *logger)
+{
+	xenevtchn_port_or_error_t port;
+
+	ctrl->event = xenevtchn_open(logger, 0);
+	if (!ctrl->event)
+		return -1;
+
+	port = xenevtchn_bind_interdomain(ctrl->event,
+		domain, ctrl->event_port);
+	if (port < 0)
+		goto fail;
+	ctrl->event_port = port;
+
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
+		goto fail;
+
+	return 0;
+
+fail:
+	if (port >= 0)
+		xenevtchn_unbind(ctrl->event, port);
+
+	xenevtchn_close(ctrl->event);
+	ctrl->event = NULL;
+
+	return -1;
+}
+
+
+struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
+                                            int domain, const char* xs_path)
+{
+	struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan));
+	struct xs_handle *xs = NULL;
+	char buf[64];
+	char *ref;
+	int ring_ref;
+	unsigned int len;
+
+	if (!ctrl)
+		return 0;
+	ctrl->ring = NULL;
+	ctrl->event = NULL;
+	ctrl->gnttab = NULL;
+	ctrl->write.order = ctrl->read.order = 0;
+	ctrl->is_server = 0;
+
+	xs = xs_daemon_open();
+	if (!xs)
+		xs = xs_domain_open();
+	if (!xs)
+		goto fail;
+
+// find xenstore entry
+	snprintf(buf, sizeof buf, "%s/ring-ref", xs_path);
+	ref = xs_read(xs, 0, buf, &len);
+	if (!ref)
+		goto fail;
+	ring_ref = atoi(ref);
+	free(ref);
+	if (!ring_ref)
+		goto fail;
+	snprintf(buf, sizeof buf, "%s/event-channel", xs_path);
+	ref = xs_read(xs, 0, buf, &len);
+	if (!ref)
+		goto fail;
+	ctrl->event_port = atoi(ref);
+	free(ref);
+	if (!ctrl->event_port)
+		goto fail;
+
+	ctrl->gnttab = xengnttab_open(logger, 0);
+	if (!ctrl->gnttab)
+		goto fail;
+
+// set up event channel
+	if (init_evt_cli(ctrl, domain, logger))
+		goto fail;
+
+// set up shared page(s)
+	if (init_gnt_cli(ctrl, domain, ring_ref))
+		goto fail;
+
+	ctrl->ring->cli_live = 1;
+	ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE;
+
+	/* wake up the server */
+	xenevtchn_notify(ctrl->event, ctrl->event_port);
+
+ out:
+	if (xs)
+		xs_daemon_close(xs);
+	return ctrl;
+ fail:
+	libxenvchan_close(ctrl);
+	ctrl = NULL;
+	goto out;
+}
diff --git a/tools/libs/vchan/io.c b/tools/libs/vchan/io.c
new file mode 100644
index 0000000000..da303fbc01
--- /dev/null
+++ b/tools/libs/vchan/io.c
@@ -0,0 +1,388 @@
+/**
+ * @file
+ * @section AUTHORS
+ *
+ * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *
+ *  Authors:
+ *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
+ *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
+ *
+ * @section LICENSE
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @section DESCRIPTION
+ *
+ *  This file contains the communications interface built on the ring buffer.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/uio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <xenctrl.h>
+#include <libxenvchan.h>
+
+#ifndef PAGE_SHIFT
+#define PAGE_SHIFT 12
+#endif
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+
+static inline uint32_t rd_prod(struct libxenvchan *ctrl)
+{
+	return ctrl->read.shr->prod;
+}
+
+static inline uint32_t* _rd_cons(struct libxenvchan *ctrl)
+{
+	return &ctrl->read.shr->cons;
+}
+#define rd_cons(x) (*_rd_cons(x))
+
+static inline uint32_t* _wr_prod(struct libxenvchan *ctrl)
+{
+	return &ctrl->write.shr->prod;
+}
+#define wr_prod(x) (*_wr_prod(x))
+
+static inline uint32_t wr_cons(struct libxenvchan *ctrl)
+{
+	return ctrl->write.shr->cons;
+}
+
+static inline const void* rd_ring(struct libxenvchan *ctrl)
+{
+	return ctrl->read.buffer;
+}
+
+static inline void* wr_ring(struct libxenvchan *ctrl)
+{
+	return ctrl->write.buffer;
+}
+
+static inline uint32_t wr_ring_size(struct libxenvchan *ctrl)
+{
+	return (1 << ctrl->write.order);
+}
+
+static inline uint32_t rd_ring_size(struct libxenvchan *ctrl)
+{
+	return (1 << ctrl->read.order);
+}
+
+static inline void request_notify(struct libxenvchan *ctrl, uint8_t bit)
+{
+	uint8_t *notify = ctrl->is_server ? &ctrl->ring->cli_notify : &ctrl->ring->srv_notify;
+	__sync_or_and_fetch(notify, bit);
+	xen_mb(); /* post the request /before/ caller re-reads any indexes */
+}
+
+static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
+{
+	uint8_t *notify, prev;
+	xen_mb(); /* caller updates indexes /before/ we decode to notify */
+	notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify;
+	prev = __sync_fetch_and_and(notify, ~bit);
+	if (prev & bit)
+		return xenevtchn_notify(ctrl->event, ctrl->event_port);
+	else
+		return 0;
+}
+
+/*
+ * Get the amount of buffer space available, and do nothing about
+ * notifications.
+ */
+static inline int raw_get_data_ready(struct libxenvchan *ctrl)
+{
+	uint32_t ready = rd_prod(ctrl) - rd_cons(ctrl);
+	xen_mb(); /* Ensure 'ready' is read only once. */
+	if (ready > rd_ring_size(ctrl))
+		/* We have no way to return errors.  Locking up the ring is
+		 * better than the alternatives. */
+		return 0;
+	return ready;
+}
+
+/**
+ * Get the amount of buffer space available and enable notifications if needed.
+ */
+static inline int fast_get_data_ready(struct libxenvchan *ctrl, size_t request)
+{
+	int ready = raw_get_data_ready(ctrl);
+	if (ready >= request)
+		return ready;
+	/* We plan to consume all data; please tell us if you send more */
+	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
+	/*
+	 * If the writer moved rd_prod after our read but before request, we
+	 * will not get notified even though the actual amount of data ready is
+	 * above request. Reread rd_prod to cover this case.
+	 */
+	return raw_get_data_ready(ctrl);
+}
+
+int libxenvchan_data_ready(struct libxenvchan *ctrl)
+{
+	/* Since this value is being used outside libxenvchan, request notification
+	 * when it changes
+	 */
+	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
+	return raw_get_data_ready(ctrl);
+}
+
+/**
+ * Get the amount of buffer space available, and do nothing
+ * about notifications
+ */
+static inline int raw_get_buffer_space(struct libxenvchan *ctrl)
+{
+	uint32_t ready = wr_ring_size(ctrl) - (wr_prod(ctrl) - wr_cons(ctrl));
+	xen_mb(); /* Ensure 'ready' is read only once. */
+	if (ready > wr_ring_size(ctrl))
+		/* We have no way to return errors.  Locking up the ring is
+		 * better than the alternatives. */
+		return 0;
+	return ready;
+}
+
+/**
+ * Get the amount of buffer space available and enable notifications if needed.
+ */
+static inline int fast_get_buffer_space(struct libxenvchan *ctrl, size_t request)
+{
+	int ready = raw_get_buffer_space(ctrl);
+	if (ready >= request)
+		return ready;
+	/* We plan to fill the buffer; please tell us when you've read it */
+	request_notify(ctrl, VCHAN_NOTIFY_READ);
+	/*
+	 * If the reader moved wr_cons after our read but before request, we
+	 * will not get notified even though the actual amount of buffer space
+	 * is above request. Reread wr_cons to cover this case.
+	 */
+	return raw_get_buffer_space(ctrl);
+}
+
+int libxenvchan_buffer_space(struct libxenvchan *ctrl)
+{
+	/* Since this value is being used outside libxenvchan, request notification
+	 * when it changes
+	 */
+	request_notify(ctrl, VCHAN_NOTIFY_READ);
+	return raw_get_buffer_space(ctrl);
+}
+
+int libxenvchan_wait(struct libxenvchan *ctrl)
+{
+	int ret = xenevtchn_pending(ctrl->event);
+	if (ret < 0)
+		return -1;
+	xenevtchn_unmask(ctrl->event, ret);
+	return 0;
+}
+
+/**
+ * returns -1 on error, or size on success
+ *
+ * caller must have checked that enough space is available
+ */
+static int do_send(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int real_idx = wr_prod(ctrl) & (wr_ring_size(ctrl) - 1);
+	int avail_contig = wr_ring_size(ctrl) - real_idx;
+	if (avail_contig > size)
+		avail_contig = size;
+	xen_mb(); /* read indexes /then/ write data */
+	memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
+	if (avail_contig < size)
+	{
+		// we rolled across the end of the ring
+		memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
+	}
+	xen_wmb(); /* write data /then/ notify */
+	wr_prod(ctrl) += size;
+	if (send_notify(ctrl, VCHAN_NOTIFY_WRITE))
+		return -1;
+	return size;
+}
+
+/**
+ * returns 0 if no buffer space is available, -1 on error, or size on success
+ */
+int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int avail;
+	while (1) {
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		avail = fast_get_buffer_space(ctrl, size);
+		if (size <= avail)
+			return do_send(ctrl, data, size);
+		if (!ctrl->blocking)
+			return 0;
+		if (size > wr_ring_size(ctrl))
+			return -1;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size)
+{
+	int avail;
+	if (!libxenvchan_is_open(ctrl))
+		return -1;
+	if (ctrl->blocking) {
+		size_t pos = 0;
+		while (1) {
+			avail = fast_get_buffer_space(ctrl, size - pos);
+			if (pos + avail > size)
+				avail = size - pos;
+			if (avail)
+				pos += do_send(ctrl, data + pos, avail);
+			if (pos == size)
+				return pos;
+			if (libxenvchan_wait(ctrl))
+				return -1;
+			if (!libxenvchan_is_open(ctrl))
+				return -1;
+		}
+	} else {
+		avail = fast_get_buffer_space(ctrl, size);
+		if (size > avail)
+			size = avail;
+		if (size == 0)
+			return 0;
+		return do_send(ctrl, data, size);
+	}
+}
+
+/**
+ * returns -1 on error, or size on success
+ *
+ * caller must have checked that enough data is available
+ */
+static int do_recv(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	int real_idx = rd_cons(ctrl) & (rd_ring_size(ctrl) - 1);
+	int avail_contig = rd_ring_size(ctrl) - real_idx;
+	if (avail_contig > size)
+		avail_contig = size;
+	xen_rmb(); /* data read must happen /after/ rd_cons read */
+	memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
+	if (avail_contig < size)
+	{
+		// we rolled across the end of the ring
+		memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
+	}
+	xen_mb(); /* consume /then/ notify */
+	rd_cons(ctrl) += size;
+	if (send_notify(ctrl, VCHAN_NOTIFY_READ))
+		return -1;
+	return size;
+}
+
+/**
+ * reads exactly size bytes from the vchan.
+ * returns 0 if insufficient data is available, -1 on error, or size on success
+ */
+int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	while (1) {
+		int avail = fast_get_data_ready(ctrl, size);
+		if (size <= avail)
+			return do_recv(ctrl, data, size);
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		if (!ctrl->blocking)
+			return 0;
+		if (size > rd_ring_size(ctrl))
+			return -1;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size)
+{
+	while (1) {
+		int avail = fast_get_data_ready(ctrl, size);
+		if (avail && size > avail)
+			size = avail;
+		if (avail)
+			return do_recv(ctrl, data, size);
+		if (!libxenvchan_is_open(ctrl))
+			return -1;
+		if (!ctrl->blocking)
+			return 0;
+		if (libxenvchan_wait(ctrl))
+			return -1;
+	}
+}
+
+int libxenvchan_is_open(struct libxenvchan* ctrl)
+{
+	if (ctrl->is_server)
+		return ctrl->server_persist ? 1 : ctrl->ring->cli_live;
+	else
+		return ctrl->ring->srv_live;
+}
+
+int libxenvchan_fd_for_select(struct libxenvchan *ctrl)
+{
+	return xenevtchn_fd(ctrl->event);
+}
+
+void libxenvchan_close(struct libxenvchan *ctrl)
+{
+	if (!ctrl)
+		return;
+	if (ctrl->read.order >= PAGE_SHIFT)
+		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+	if (ctrl->write.order >= PAGE_SHIFT)
+		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+	if (ctrl->ring) {
+		if (ctrl->is_server) {
+			ctrl->ring->srv_live = 0;
+			xengntshr_unshare(ctrl->gntshr, ctrl->ring, 1);
+		} else {
+			ctrl->ring->cli_live = 0;
+			xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
+		}
+	}
+	if (ctrl->event) {
+		if (ctrl->ring)
+			xenevtchn_notify(ctrl->event, ctrl->event_port);
+		xenevtchn_close(ctrl->event);
+	}
+	if (ctrl->is_server) {
+		if (ctrl->gntshr)
+			xengntshr_close(ctrl->gntshr);
+	} else {
+		if (ctrl->gnttab)
+			xengnttab_close(ctrl->gnttab);
+	}
+	free(ctrl);
+}
diff --git a/tools/libvchan/Makefile b/tools/libvchan/Makefile
deleted file mode 100644
index e718447977..0000000000
--- a/tools/libvchan/Makefile
+++ /dev/null
@@ -1,100 +0,0 @@
-#
-# tools/libvchan/Makefile
-#
-
-XEN_ROOT = $(CURDIR)/../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-LIBVCHAN_OBJS = init.o io.o
-NODE_OBJS = node.o
-NODE2_OBJS = node-select.o
-
-LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS))
-LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) $(LDLIBS_libxenevtchn)
-$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-vchan-socket-proxy.o: CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) $(CFLAGS_libxengnttab) $(CFLAGS_libxenevtchn)
-
-MAJOR = 4.15
-MINOR = 0
-
-CFLAGS += -I../include -I.
-
-io.o io.opic: CFLAGS += $(CFLAGS_libxenctrl) # for xen_mb et al
-
-PKG_CONFIG := xenvchan.pc
-PKG_CONFIG_NAME := Xenvchan
-PKG_CONFIG_DESC := The Xenvchan library for Xen hypervisor
-PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
-PKG_CONFIG_USELIBS := $(SHLIB_libxenvchan)
-PKG_CONFIG_LIB := xenvchan
-PKG_CONFIG_REQPRIV := xentoollog,xenstore,xenevtchn,xengnttab
-
-ifneq ($(CONFIG_LIBXC_MINIOS),y)
-PKG_CONFIG_INST := $(PKG_CONFIG)
-$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
-$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
-$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
-endif
-
-PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
-
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
-$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
-
-.PHONY: all
-all: libxenvchan.so vchan-node1 vchan-node2 vchan-socket-proxy libxenvchan.a $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
-
-libxenvchan.so: libxenvchan.so.$(MAJOR)
-	ln -sf $< $@
-
-libxenvchan.so.$(MAJOR): libxenvchan.so.$(MAJOR).$(MINOR)
-	ln -sf $< $@
-
-libxenvchan.so.$(MAJOR).$(MINOR): $(LIBVCHAN_PIC_OBJS)
-	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenvchan.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBVCHAN_LIBS) $(APPEND_LDFLAGS)
-
-libxenvchan.a: $(LIBVCHAN_OBJS)
-	$(AR) rcs libxenvchan.a $^
-
-vchan-node1: $(NODE_OBJS) libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $(NODE_OBJS) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
-
-vchan-node2: $(NODE2_OBJS) libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $(NODE2_OBJS) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
-
-vchan-socket-proxy: vchan-socket-proxy.o libxenvchan.so
-	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenvchan) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(libdir)
-	$(INSTALL_DIR) $(DESTDIR)$(includedir)
-	$(INSTALL_DIR) $(DESTDIR)$(bindir)
-	$(INSTALL_PROG) libxenvchan.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
-	ln -sf libxenvchan.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR)
-	ln -sf libxenvchan.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenvchan.so
-	$(INSTALL_PROG) vchan-socket-proxy $(DESTDIR)$(bindir)
-	$(INSTALL_DATA) libxenvchan.h $(DESTDIR)$(includedir)
-	$(INSTALL_DATA) libxenvchan.a $(DESTDIR)$(libdir)
-	$(INSTALL_DATA) xenvchan.pc $(DESTDIR)$(PKG_INSTALLDIR)
-
-.PHONY: uninstall
-uninstall:
-	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenvchan.pc
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.a
-	rm -f $(DESTDIR)$(includedir)/libxenvchan.h
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR)
-	rm -f $(DESTDIR)$(libdir)/libxenvchan.so.$(MAJOR).$(MINOR)
-
-.PHONY: clean
-clean:
-	$(RM) -f *.o *.opic *.so* *.a vchan-node1 vchan-node2 $(DEPS_RM)
-	$(RM) -f xenvchan.pc
-
-distclean: clean
-
--include $(DEPS_INCLUDE)
diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c
deleted file mode 100644
index ad4b64fbe3..0000000000
--- a/tools/libvchan/init.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  This file contains the setup code used to establish the ring buffer.
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/user.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <xenstore.h>
-#include <xen/xen.h>
-#include <xen/sys/evtchn.h>
-#include <xen/sys/gntalloc.h>
-#include <xen/sys/gntdev.h>
-#include <libxenvchan.h>
-
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT 12
-#endif
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
-#define SMALL_RING_SHIFT 10
-#define LARGE_RING_SHIFT 11
-
-#define MAX_SMALL_RING (1 << SMALL_RING_SHIFT)
-#define SMALL_RING_OFFSET 1024
-#define MAX_LARGE_RING (1 << LARGE_RING_SHIFT)
-#define LARGE_RING_OFFSET 2048
-
-// if you go over this size, you'll have too many grants to fit in the shared page.
-#define MAX_RING_SHIFT 20
-#define MAX_RING_SIZE (1 << MAX_RING_SHIFT)
-
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-#define max(a,b) ((a > b) ? a : b)
-
-static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
-{
-	int pages_left = ctrl->read.order >= PAGE_SHIFT ? 1 << (ctrl->read.order - PAGE_SHIFT) : 0;
-	int pages_right = ctrl->write.order >= PAGE_SHIFT ? 1 << (ctrl->write.order - PAGE_SHIFT) : 0;
-	uint32_t ring_ref = -1;
-	void *ring;
-
-	ring = xengntshr_share_page_notify(ctrl->gntshr, domain,
-			&ring_ref, 1, offsetof(struct vchan_interface, srv_live),
-			ctrl->event_port);
-
-	if (!ring)
-		goto out;
-
-	memset(ring, 0, PAGE_SIZE);
-
-	ctrl->ring = ring;
-	ctrl->read.shr = &ctrl->ring->left;
-	ctrl->write.shr = &ctrl->ring->right;
-	ctrl->ring->left_order = ctrl->read.order;
-	ctrl->ring->right_order = ctrl->write.order;
-	ctrl->ring->cli_live = 2;
-	ctrl->ring->srv_live = 1;
-	ctrl->ring->cli_notify = VCHAN_NOTIFY_WRITE;
-
-	switch (ctrl->read.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
-			pages_left, ctrl->ring->grants, 1);
-		if (!ctrl->read.buffer)
-			goto out_ring;
-	}
-
-	switch (ctrl->write.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
-			pages_right, ctrl->ring->grants + pages_left, 1);
-		if (!ctrl->write.buffer)
-			goto out_unmap_left;
-	}
-
-out:
-	return ring_ref;
-out_unmap_left:
-	if (pages_left)
-		xengntshr_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left);
-out_ring:
-	xengntshr_unshare(ctrl->gntshr, ring, 1);
-	ring_ref = -1;
-	ctrl->ring = NULL;
-	ctrl->write.order = ctrl->read.order = 0;
-	goto out;
-}
-
-static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
-{
-	int rv = -1;
-	uint32_t *grants;
-
-	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
-		domain, ring_ref, PROT_READ|PROT_WRITE,
-		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
-
-	if (!ctrl->ring)
-		goto out;
-
-	ctrl->write.order = ctrl->ring->left_order;
-	ctrl->read.order = ctrl->ring->right_order;
-	ctrl->write.shr = &ctrl->ring->left;
-	ctrl->read.shr = &ctrl->ring->right;
-	if (ctrl->write.order < SMALL_RING_SHIFT || ctrl->write.order > MAX_RING_SHIFT)
-		goto out_unmap_ring;
-	if (ctrl->read.order < SMALL_RING_SHIFT || ctrl->read.order > MAX_RING_SHIFT)
-		goto out_unmap_ring;
-	if (ctrl->read.order == ctrl->write.order && ctrl->read.order < PAGE_SHIFT)
-		goto out_unmap_ring;
-
-	grants = ctrl->ring->grants;
-
-	switch (ctrl->write.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		{
-			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
-			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
-				pages_left, domain, grants, PROT_READ|PROT_WRITE);
-			if (!ctrl->write.buffer)
-				goto out_unmap_ring;
-			grants += pages_left;
-		}
-	}
-
-	switch (ctrl->read.order) {
-	case SMALL_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + SMALL_RING_OFFSET;
-		break;
-	case LARGE_RING_SHIFT:
-		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
-		break;
-	default:
-		{
-			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
-			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
-				pages_right, domain, grants, PROT_READ);
-			if (!ctrl->read.buffer)
-				goto out_unmap_left;
-		}
-	}
-
-	rv = 0;
- out:
-	return rv;
- out_unmap_left:
-	if (ctrl->write.order >= PAGE_SHIFT)
-		xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer,
-		                1 << (ctrl->write.order - PAGE_SHIFT));
- out_unmap_ring:
-	xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
-	ctrl->ring = 0;
-	ctrl->write.order = ctrl->read.order = 0;
-	rv = -1;
-	goto out;
-}
-
-static int init_evt_srv(struct libxenvchan *ctrl, int domain,
-                        struct xentoollog_logger *logger)
-{
-	xenevtchn_port_or_error_t port;
-
-	ctrl->event = xenevtchn_open(logger, 0);
-	if (!ctrl->event)
-		return -1;
-
-	port = xenevtchn_bind_unbound_port(ctrl->event, domain);
-	if (port < 0)
-		goto fail;
-	ctrl->event_port = port;
-
-	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
-		goto fail;
-
-	return 0;
-
-fail:
-	if (port >= 0)
-		xenevtchn_unbind(ctrl->event, port);
-
-	xenevtchn_close(ctrl->event);
-	ctrl->event = NULL;
-
-	return -1;
-}
-
-static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_base, int ring_ref)
-{
-	int ret = -1;
-	struct xs_handle *xs;
-	struct xs_permissions perms[2];
-	char buf[64];
-	char ref[16];
-	char* domid_str = NULL;
-	xs_transaction_t xs_trans = XBT_NULL;
-	xs = xs_domain_open();
-	if (!xs)
-		goto fail;
-	domid_str = xs_read(xs, 0, "domid", NULL);
-	if (!domid_str)
-		goto fail_xs_open;
-
-	// owner domain is us
-	perms[0].id = atoi(domid_str);
-	// permissions for domains not listed = none
-	perms[0].perms = XS_PERM_NONE;
-	// other domains
-	perms[1].id = domain;
-	perms[1].perms = XS_PERM_READ;
-
-retry_transaction:
-	xs_trans = xs_transaction_start(xs);
-	if (!xs_trans)
-		goto fail_xs_open;
-
-	snprintf(ref, sizeof ref, "%d", ring_ref);
-	snprintf(buf, sizeof buf, "%s/ring-ref", xs_base);
-	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
-		goto fail_xs_open;
-	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
-		goto fail_xs_open;
-
-	snprintf(ref, sizeof ref, "%d", ctrl->event_port);
-	snprintf(buf, sizeof buf, "%s/event-channel", xs_base);
-	if (!xs_write(xs, xs_trans, buf, ref, strlen(ref)))
-		goto fail_xs_open;
-	if (!xs_set_permissions(xs, xs_trans, buf, perms, 2))
-		goto fail_xs_open;
-
-	if (!xs_transaction_end(xs, xs_trans, 0)) {
-		if (errno == EAGAIN)
-			goto retry_transaction;
-	} else {
-		ret = 0;
-	}
- fail_xs_open:
-	free(domid_str);
-	xs_daemon_close(xs);
- fail:
-	return ret;
-}
-
-static int min_order(size_t siz)
-{
-	int rv = PAGE_SHIFT;
-	while (siz > (1 << rv))
-		rv++;
-	return rv;
-}
-
-struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path,
-                                            size_t left_min, size_t right_min)
-{
-	struct libxenvchan *ctrl;
-	int ring_ref;
-	if (left_min > MAX_RING_SIZE || right_min > MAX_RING_SIZE)
-		return 0;
-
-	ctrl = malloc(sizeof(*ctrl));
-	if (!ctrl)
-		return 0;
-
-	ctrl->ring = NULL;
-	ctrl->event = NULL;
-	ctrl->is_server = 1;
-	ctrl->server_persist = 0;
-
-	ctrl->read.order = min_order(left_min);
-	ctrl->write.order = min_order(right_min);
-
-	// if we can avoid allocating extra pages by using in-page rings, do so
-	if (left_min <= MAX_SMALL_RING && right_min <= MAX_LARGE_RING) {
-		ctrl->read.order = SMALL_RING_SHIFT;
-		ctrl->write.order = LARGE_RING_SHIFT;
-	} else if (left_min <= MAX_LARGE_RING && right_min <= MAX_SMALL_RING) {
-		ctrl->read.order = LARGE_RING_SHIFT;
-		ctrl->write.order = SMALL_RING_SHIFT;
-	} else if (left_min <= MAX_LARGE_RING) {
-		ctrl->read.order = LARGE_RING_SHIFT;
-	} else if (right_min <= MAX_LARGE_RING) {
-		ctrl->write.order = LARGE_RING_SHIFT;
-	}
-
-	ctrl->gntshr = xengntshr_open(logger, 0);
-	if (!ctrl->gntshr) {
-		free(ctrl);
-		return 0;
-	}
-
-	if (init_evt_srv(ctrl, domain, logger))
-		goto out;
-	ring_ref = init_gnt_srv(ctrl, domain);
-	if (ring_ref < 0)
-		goto out;
-	if (init_xs_srv(ctrl, domain, xs_path, ring_ref))
-		goto out;
-	return ctrl;
-out:
-	libxenvchan_close(ctrl);
-	return 0;
-}
-
-static int init_evt_cli(struct libxenvchan *ctrl, int domain,
-                        struct xentoollog_logger *logger)
-{
-	xenevtchn_port_or_error_t port;
-
-	ctrl->event = xenevtchn_open(logger, 0);
-	if (!ctrl->event)
-		return -1;
-
-	port = xenevtchn_bind_interdomain(ctrl->event,
-		domain, ctrl->event_port);
-	if (port < 0)
-		goto fail;
-	ctrl->event_port = port;
-
-	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
-		goto fail;
-
-	return 0;
-
-fail:
-	if (port >= 0)
-		xenevtchn_unbind(ctrl->event, port);
-
-	xenevtchn_close(ctrl->event);
-	ctrl->event = NULL;
-
-	return -1;
-}
-
-
-struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path)
-{
-	struct libxenvchan *ctrl = malloc(sizeof(struct libxenvchan));
-	struct xs_handle *xs = NULL;
-	char buf[64];
-	char *ref;
-	int ring_ref;
-	unsigned int len;
-
-	if (!ctrl)
-		return 0;
-	ctrl->ring = NULL;
-	ctrl->event = NULL;
-	ctrl->gnttab = NULL;
-	ctrl->write.order = ctrl->read.order = 0;
-	ctrl->is_server = 0;
-
-	xs = xs_daemon_open();
-	if (!xs)
-		xs = xs_domain_open();
-	if (!xs)
-		goto fail;
-
-// find xenstore entry
-	snprintf(buf, sizeof buf, "%s/ring-ref", xs_path);
-	ref = xs_read(xs, 0, buf, &len);
-	if (!ref)
-		goto fail;
-	ring_ref = atoi(ref);
-	free(ref);
-	if (!ring_ref)
-		goto fail;
-	snprintf(buf, sizeof buf, "%s/event-channel", xs_path);
-	ref = xs_read(xs, 0, buf, &len);
-	if (!ref)
-		goto fail;
-	ctrl->event_port = atoi(ref);
-	free(ref);
-	if (!ctrl->event_port)
-		goto fail;
-
-	ctrl->gnttab = xengnttab_open(logger, 0);
-	if (!ctrl->gnttab)
-		goto fail;
-
-// set up event channel
-	if (init_evt_cli(ctrl, domain, logger))
-		goto fail;
-
-// set up shared page(s)
-	if (init_gnt_cli(ctrl, domain, ring_ref))
-		goto fail;
-
-	ctrl->ring->cli_live = 1;
-	ctrl->ring->srv_notify = VCHAN_NOTIFY_WRITE;
-
-	/* wake up the server */
-	xenevtchn_notify(ctrl->event, ctrl->event_port);
-
- out:
-	if (xs)
-		xs_daemon_close(xs);
-	return ctrl;
- fail:
-	libxenvchan_close(ctrl);
-	ctrl = NULL;
-	goto out;
-}
diff --git a/tools/libvchan/io.c b/tools/libvchan/io.c
deleted file mode 100644
index da303fbc01..0000000000
--- a/tools/libvchan/io.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  This file contains the communications interface built on the ring buffer.
- */
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <xenctrl.h>
-#include <libxenvchan.h>
-
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT 12
-#endif
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
-
-static inline uint32_t rd_prod(struct libxenvchan *ctrl)
-{
-	return ctrl->read.shr->prod;
-}
-
-static inline uint32_t* _rd_cons(struct libxenvchan *ctrl)
-{
-	return &ctrl->read.shr->cons;
-}
-#define rd_cons(x) (*_rd_cons(x))
-
-static inline uint32_t* _wr_prod(struct libxenvchan *ctrl)
-{
-	return &ctrl->write.shr->prod;
-}
-#define wr_prod(x) (*_wr_prod(x))
-
-static inline uint32_t wr_cons(struct libxenvchan *ctrl)
-{
-	return ctrl->write.shr->cons;
-}
-
-static inline const void* rd_ring(struct libxenvchan *ctrl)
-{
-	return ctrl->read.buffer;
-}
-
-static inline void* wr_ring(struct libxenvchan *ctrl)
-{
-	return ctrl->write.buffer;
-}
-
-static inline uint32_t wr_ring_size(struct libxenvchan *ctrl)
-{
-	return (1 << ctrl->write.order);
-}
-
-static inline uint32_t rd_ring_size(struct libxenvchan *ctrl)
-{
-	return (1 << ctrl->read.order);
-}
-
-static inline void request_notify(struct libxenvchan *ctrl, uint8_t bit)
-{
-	uint8_t *notify = ctrl->is_server ? &ctrl->ring->cli_notify : &ctrl->ring->srv_notify;
-	__sync_or_and_fetch(notify, bit);
-	xen_mb(); /* post the request /before/ caller re-reads any indexes */
-}
-
-static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
-{
-	uint8_t *notify, prev;
-	xen_mb(); /* caller updates indexes /before/ we decode to notify */
-	notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify;
-	prev = __sync_fetch_and_and(notify, ~bit);
-	if (prev & bit)
-		return xenevtchn_notify(ctrl->event, ctrl->event_port);
-	else
-		return 0;
-}
-
-/*
- * Get the amount of buffer space available, and do nothing about
- * notifications.
- */
-static inline int raw_get_data_ready(struct libxenvchan *ctrl)
-{
-	uint32_t ready = rd_prod(ctrl) - rd_cons(ctrl);
-	xen_mb(); /* Ensure 'ready' is read only once. */
-	if (ready > rd_ring_size(ctrl))
-		/* We have no way to return errors.  Locking up the ring is
-		 * better than the alternatives. */
-		return 0;
-	return ready;
-}
-
-/**
- * Get the amount of buffer space available and enable notifications if needed.
- */
-static inline int fast_get_data_ready(struct libxenvchan *ctrl, size_t request)
-{
-	int ready = raw_get_data_ready(ctrl);
-	if (ready >= request)
-		return ready;
-	/* We plan to consume all data; please tell us if you send more */
-	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
-	/*
-	 * If the writer moved rd_prod after our read but before request, we
-	 * will not get notified even though the actual amount of data ready is
-	 * above request. Reread rd_prod to cover this case.
-	 */
-	return raw_get_data_ready(ctrl);
-}
-
-int libxenvchan_data_ready(struct libxenvchan *ctrl)
-{
-	/* Since this value is being used outside libxenvchan, request notification
-	 * when it changes
-	 */
-	request_notify(ctrl, VCHAN_NOTIFY_WRITE);
-	return raw_get_data_ready(ctrl);
-}
-
-/**
- * Get the amount of buffer space available, and do nothing
- * about notifications
- */
-static inline int raw_get_buffer_space(struct libxenvchan *ctrl)
-{
-	uint32_t ready = wr_ring_size(ctrl) - (wr_prod(ctrl) - wr_cons(ctrl));
-	xen_mb(); /* Ensure 'ready' is read only once. */
-	if (ready > wr_ring_size(ctrl))
-		/* We have no way to return errors.  Locking up the ring is
-		 * better than the alternatives. */
-		return 0;
-	return ready;
-}
-
-/**
- * Get the amount of buffer space available and enable notifications if needed.
- */
-static inline int fast_get_buffer_space(struct libxenvchan *ctrl, size_t request)
-{
-	int ready = raw_get_buffer_space(ctrl);
-	if (ready >= request)
-		return ready;
-	/* We plan to fill the buffer; please tell us when you've read it */
-	request_notify(ctrl, VCHAN_NOTIFY_READ);
-	/*
-	 * If the reader moved wr_cons after our read but before request, we
-	 * will not get notified even though the actual amount of buffer space
-	 * is above request. Reread wr_cons to cover this case.
-	 */
-	return raw_get_buffer_space(ctrl);
-}
-
-int libxenvchan_buffer_space(struct libxenvchan *ctrl)
-{
-	/* Since this value is being used outside libxenvchan, request notification
-	 * when it changes
-	 */
-	request_notify(ctrl, VCHAN_NOTIFY_READ);
-	return raw_get_buffer_space(ctrl);
-}
-
-int libxenvchan_wait(struct libxenvchan *ctrl)
-{
-	int ret = xenevtchn_pending(ctrl->event);
-	if (ret < 0)
-		return -1;
-	xenevtchn_unmask(ctrl->event, ret);
-	return 0;
-}
-
-/**
- * returns -1 on error, or size on success
- *
- * caller must have checked that enough space is available
- */
-static int do_send(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int real_idx = wr_prod(ctrl) & (wr_ring_size(ctrl) - 1);
-	int avail_contig = wr_ring_size(ctrl) - real_idx;
-	if (avail_contig > size)
-		avail_contig = size;
-	xen_mb(); /* read indexes /then/ write data */
-	memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
-	if (avail_contig < size)
-	{
-		// we rolled across the end of the ring
-		memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
-	}
-	xen_wmb(); /* write data /then/ notify */
-	wr_prod(ctrl) += size;
-	if (send_notify(ctrl, VCHAN_NOTIFY_WRITE))
-		return -1;
-	return size;
-}
-
-/**
- * returns 0 if no buffer space is available, -1 on error, or size on success
- */
-int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int avail;
-	while (1) {
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		avail = fast_get_buffer_space(ctrl, size);
-		if (size <= avail)
-			return do_send(ctrl, data, size);
-		if (!ctrl->blocking)
-			return 0;
-		if (size > wr_ring_size(ctrl))
-			return -1;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size)
-{
-	int avail;
-	if (!libxenvchan_is_open(ctrl))
-		return -1;
-	if (ctrl->blocking) {
-		size_t pos = 0;
-		while (1) {
-			avail = fast_get_buffer_space(ctrl, size - pos);
-			if (pos + avail > size)
-				avail = size - pos;
-			if (avail)
-				pos += do_send(ctrl, data + pos, avail);
-			if (pos == size)
-				return pos;
-			if (libxenvchan_wait(ctrl))
-				return -1;
-			if (!libxenvchan_is_open(ctrl))
-				return -1;
-		}
-	} else {
-		avail = fast_get_buffer_space(ctrl, size);
-		if (size > avail)
-			size = avail;
-		if (size == 0)
-			return 0;
-		return do_send(ctrl, data, size);
-	}
-}
-
-/**
- * returns -1 on error, or size on success
- *
- * caller must have checked that enough data is available
- */
-static int do_recv(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	int real_idx = rd_cons(ctrl) & (rd_ring_size(ctrl) - 1);
-	int avail_contig = rd_ring_size(ctrl) - real_idx;
-	if (avail_contig > size)
-		avail_contig = size;
-	xen_rmb(); /* data read must happen /after/ rd_cons read */
-	memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
-	if (avail_contig < size)
-	{
-		// we rolled across the end of the ring
-		memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
-	}
-	xen_mb(); /* consume /then/ notify */
-	rd_cons(ctrl) += size;
-	if (send_notify(ctrl, VCHAN_NOTIFY_READ))
-		return -1;
-	return size;
-}
-
-/**
- * reads exactly size bytes from the vchan.
- * returns 0 if insufficient data is available, -1 on error, or size on success
- */
-int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	while (1) {
-		int avail = fast_get_data_ready(ctrl, size);
-		if (size <= avail)
-			return do_recv(ctrl, data, size);
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		if (!ctrl->blocking)
-			return 0;
-		if (size > rd_ring_size(ctrl))
-			return -1;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size)
-{
-	while (1) {
-		int avail = fast_get_data_ready(ctrl, size);
-		if (avail && size > avail)
-			size = avail;
-		if (avail)
-			return do_recv(ctrl, data, size);
-		if (!libxenvchan_is_open(ctrl))
-			return -1;
-		if (!ctrl->blocking)
-			return 0;
-		if (libxenvchan_wait(ctrl))
-			return -1;
-	}
-}
-
-int libxenvchan_is_open(struct libxenvchan* ctrl)
-{
-	if (ctrl->is_server)
-		return ctrl->server_persist ? 1 : ctrl->ring->cli_live;
-	else
-		return ctrl->ring->srv_live;
-}
-
-int libxenvchan_fd_for_select(struct libxenvchan *ctrl)
-{
-	return xenevtchn_fd(ctrl->event);
-}
-
-void libxenvchan_close(struct libxenvchan *ctrl)
-{
-	if (!ctrl)
-		return;
-	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
-	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
-	if (ctrl->ring) {
-		if (ctrl->is_server) {
-			ctrl->ring->srv_live = 0;
-			xengntshr_unshare(ctrl->gntshr, ctrl->ring, 1);
-		} else {
-			ctrl->ring->cli_live = 0;
-			xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
-		}
-	}
-	if (ctrl->event) {
-		if (ctrl->ring)
-			xenevtchn_notify(ctrl->event, ctrl->event_port);
-		xenevtchn_close(ctrl->event);
-	}
-	if (ctrl->is_server) {
-		if (ctrl->gntshr)
-			xengntshr_close(ctrl->gntshr);
-	} else {
-		if (ctrl->gnttab)
-			xengnttab_close(ctrl->gnttab);
-	}
-	free(ctrl);
-}
diff --git a/tools/libvchan/libxenvchan.h b/tools/libvchan/libxenvchan.h
deleted file mode 100644
index d6010b145d..0000000000
--- a/tools/libvchan/libxenvchan.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
- *  this code has been substantially rewritten to use the gntdev and gntalloc
- *  devices instead of raw MFNs and map_foreign_range.
- *
- *  This is a library for inter-domain communication.  A standard Xen ring
- *  buffer is used, with a datagram-based interface built on top.  The grant
- *  reference and event channels are shared in XenStore under the path
- *  /local/domain/<srv-id>/data/vchan/<cli-id>/<port>/{ring-ref,event-channel}
- *
- *  The ring.h macros define an asymmetric interface to a shared data structure
- *  that assumes all rings reside in a single contiguous memory space. This is
- *  not suitable for vchan because the interface to the ring is symmetric except
- *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
- *  size of the rings used in vchan are determined at execution time instead of
- *  compile time, so the macros in ring.h cannot be used to access the rings.
- */
-
-#include <xen/io/libxenvchan.h>
-#include <xen/xen.h>
-#include <xen/sys/evtchn.h>
-#include <xenevtchn.h>
-#include <xengnttab.h>
-
-/* Callers who don't care don't need to #include <xentoollog.h> */
-struct xentoollog_logger;
-
-struct libxenvchan_ring {
-	/* Pointer into the shared page. Offsets into buffer. */
-	struct ring_shared* shr;
-	/* ring data; may be its own shared page(s) depending on order */
-	void* buffer;
-	/**
-	 * The size of the ring is (1 << order); offsets wrap around when they
-	 * exceed this. This copy is required because we can't trust the order
-	 * in the shared page to remain constant.
-	 */
-	int order;
-};
-
-/**
- * struct libxenvchan: control structure passed to all library calls
- */
-struct libxenvchan {
-	/* Mapping handle for shared ring page */
-	union {
-		xengntshr_handle *gntshr; /* for server */
-		xengnttab_handle *gnttab; /* for client */
-	};
-	/* Pointer to shared ring page */
-	struct vchan_interface *ring;
-	/* event channel interface */
-	xenevtchn_handle *event;
-	uint32_t event_port;
-	/* informative flags: are we acting as server? */
-	int is_server:1;
-	/* true if server remains active when client closes (allows reconnection) */
-	int server_persist:1;
-	/* true if operations should block instead of returning 0 */
-	int blocking:1;
-	/* communication rings */
-	struct libxenvchan_ring read, write;
-};
-
-/**
- * Set up a vchan, including granting pages
- * @param logger Logger for libxc errors
- * @param domain The peer domain that will be connecting
- * @param xs_path Base xenstore path for storing ring/event data
- * @param send_min The minimum size (in bytes) of the send ring (left)
- * @param recv_min The minimum size (in bytes) of the receive ring (right)
- * @return The structure, or NULL in case of an error
- */
-struct libxenvchan *libxenvchan_server_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path,
-                                            size_t read_min, size_t write_min);
-/**
- * Connect to an existing vchan. Note: you can reconnect to an existing vchan
- * safely, however no locking is performed, so you must prevent multiple clients
- * from connecting to a single server.
- *
- * @param logger Logger for libxc errors
- * @param domain The peer domain to connect to
- * @param xs_path Base xenstore path for storing ring/event data
- * @return The structure, or NULL in case of an error
- */
-struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,
-                                            int domain, const char* xs_path);
-/**
- * Close a vchan. This deallocates the vchan and attempts to free its
- * resources. The other side is notified of the close, but can still read any
- * data pending prior to the close.
- */
-void libxenvchan_close(struct libxenvchan *ctrl);
-
-/**
- * Packet-based receive: always reads exactly $size bytes.
- * @param ctrl The vchan control structure
- * @param data Buffer for data that was read
- * @param size Size of the buffer and amount of data to read
- * @return -1 on error, 0 if nonblocking and insufficient data is available, or $size
- */
-int libxenvchan_recv(struct libxenvchan *ctrl, void *data, size_t size);
-/**
- * Stream-based receive: reads as much data as possible.
- * @param ctrl The vchan control structure
- * @param data Buffer for data that was read
- * @param size Size of the buffer
- * @return -1 on error, otherwise the amount of data read (which may be zero if
- *         the vchan is nonblocking)
- */
-int libxenvchan_read(struct libxenvchan *ctrl, void *data, size_t size);
-/**
- * Packet-based send: send entire buffer if possible
- * @param ctrl The vchan control structure
- * @param data Buffer for data to send
- * @param size Size of the buffer and amount of data to send
- * @return -1 on error, 0 if nonblocking and insufficient space is available, or $size
- */
-int libxenvchan_send(struct libxenvchan *ctrl, const void *data, size_t size);
-/**
- * Stream-based send: send as much data as possible.
- * @param ctrl The vchan control structure
- * @param data Buffer for data to send
- * @param size Size of the buffer
- * @return -1 on error, otherwise the amount of data sent (which may be zero if
- *         the vchan is nonblocking)
- */
-int libxenvchan_write(struct libxenvchan *ctrl, const void *data, size_t size);
-/**
- * Waits for reads or writes to unblock, or for a close
- */
-int libxenvchan_wait(struct libxenvchan *ctrl);
-/**
- * Returns the event file descriptor for this vchan. When this FD is readable,
- * libxenvchan_wait() will not block, and the state of the vchan has changed since
- * the last invocation of libxenvchan_wait().
- */
-int libxenvchan_fd_for_select(struct libxenvchan *ctrl);
-/**
- * Query the state of the vchan shared page:
- *  return 0 when one side has called libxenvchan_close() or crashed
- *  return 1 when both sides are open
- *  return 2 [server only] when no client has yet connected
- */
-int libxenvchan_is_open(struct libxenvchan* ctrl);
-/** Amount of data ready to read, in bytes */
-int libxenvchan_data_ready(struct libxenvchan *ctrl);
-/** Amount of data it is possible to send without blocking */
-int libxenvchan_buffer_space(struct libxenvchan *ctrl);
diff --git a/tools/libvchan/node-select.c b/tools/libvchan/node-select.c
deleted file mode 100644
index 039464427a..0000000000
--- a/tools/libvchan/node-select.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a test program for libxenvchan.  Communications are bidirectional,
- * with either server (grant offeror) or client able to read and write.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <libxenvchan.h>
-
-static void usage(char** argv)
-{
-	fprintf(stderr, "usage:\n"
-		"\t%s [client|server] domainid nodepath [rbufsiz wbufsiz]\n",
-		argv[0]);
-	exit(1);
-}
-
-#define BUFSIZE 5000
-char inbuf[BUFSIZE];
-char outbuf[BUFSIZE];
-int insiz = 0;
-int outsiz = 0;
-struct libxenvchan *ctrl = 0;
-
-static void vchan_wr(void) {
-	int ret;
-
-	if (!insiz)
-		return;
-	ret = libxenvchan_write(ctrl, inbuf, insiz);
-	if (ret < 0) {
-		fprintf(stderr, "vchan write failed\n");
-		exit(1);
-	}
-	if (ret > 0) {
-		insiz -= ret;
-		memmove(inbuf, inbuf + ret, insiz);
-	}
-}
-
-static void stdout_wr(void) {
-	int ret;
-
-	if (!outsiz)
-		return;
-	ret = write(1, outbuf, outsiz);
-	if (ret < 0 && errno != EAGAIN)
-		exit(1);
-	if (ret > 0) {
-		outsiz -= ret;
-		memmove(outbuf, outbuf + ret, outsiz);
-	}
-}
-
-static int set_nonblocking(int fd, int nonblocking) {
-	int flags = fcntl(fd, F_GETFL);
-	if (flags == -1)
-		return -1;
-
-	if (nonblocking)
-		flags |= O_NONBLOCK;
-	else
-		flags &= ~O_NONBLOCK;
-
-	if (fcntl(fd, F_SETFL, flags) == -1)
-		return -1;
-
-	return 0;
-}
-
-/**
-    Simple libxenvchan application, both client and server.
-	Both sides may write and read, both from the libxenvchan and from 
-	stdin/stdout (just like netcat).
-*/
-
-int main(int argc, char **argv)
-{
-	int ret;
-	int libxenvchan_fd;
-	if (argc < 4 || argv[3][0] != '/')
-		usage(argv);
-	if (!strcmp(argv[1], "server")) {
-		int rsiz = argc > 4 ? atoi(argv[4]) : 0;
-		int wsiz = argc > 5 ? atoi(argv[5]) : 0;
-		ctrl = libxenvchan_server_init(NULL, atoi(argv[2]), argv[3], rsiz, wsiz);
-	} else if (!strcmp(argv[1], "client"))
-		ctrl = libxenvchan_client_init(NULL, atoi(argv[2]), argv[3]);
-	else
-		usage(argv);
-	if (!ctrl) {
-		perror("libxenvchan_*_init");
-		exit(1);
-	}
-
-	if (set_nonblocking(0, 1) || set_nonblocking(1, 1)) {
-		perror("set_nonblocking");
-		exit(1);
-	}
-
-	libxenvchan_fd = libxenvchan_fd_for_select(ctrl);
-	for (;;) {
-		fd_set rfds;
-		fd_set wfds;
-		FD_ZERO(&rfds);
-		FD_ZERO(&wfds);
-		if (insiz != BUFSIZE)
-			FD_SET(0, &rfds);
-		if (outsiz)
-			FD_SET(1, &wfds);
-		FD_SET(libxenvchan_fd, &rfds);
-		ret = select(libxenvchan_fd + 1, &rfds, &wfds, NULL, NULL);
-		if (ret < 0) {
-			perror("select");
-			exit(1);
-		}
-		if (FD_ISSET(0, &rfds)) {
-			ret = read(0, inbuf + insiz, BUFSIZE - insiz);
-			if (ret < 0 && errno != EAGAIN)
-				exit(1);
-			if (ret == 0) {
-				while (insiz) {
-					vchan_wr();
-					libxenvchan_wait(ctrl);
-				}
-				return 0;
-			}
-			if (ret)
-				insiz += ret;
-			vchan_wr();
-		}
-		if (FD_ISSET(libxenvchan_fd, &rfds)) {
-			libxenvchan_wait(ctrl);
-			vchan_wr();
-		}
-		if (FD_ISSET(1, &wfds))
-			stdout_wr();
-		while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) {
-			ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz);
-			if (ret < 0)
-				exit(1);
-			outsiz += ret;
-			stdout_wr();
-		}
-		if (!libxenvchan_is_open(ctrl)) {
-			if (set_nonblocking(1, 0)) {
-				perror("set_nonblocking");
-				exit(1);
-			}
-			while (outsiz)
-				stdout_wr();
-			return 0;
-		}
-	}
-}
diff --git a/tools/libvchan/node.c b/tools/libvchan/node.c
deleted file mode 100644
index f1638f013d..0000000000
--- a/tools/libvchan/node.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a test program for libxenvchan.  Communications are in one direction,
- * either server (grant offeror) to client or vice versa.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <libxenvchan.h>
-
-int libxenvchan_write_all(struct libxenvchan *ctrl, char *buf, int size)
-{
-	int written = 0;
-	int ret;
-	while (written < size) {
-		ret = libxenvchan_write(ctrl, buf + written, size - written);
-		if (ret <= 0) {
-			perror("write");
-			exit(1);
-		}
-		written += ret;
-	}
-	return size;
-}
-
-int write_all(int fd, char *buf, int size)
-{
-	int written = 0;
-	int ret;
-	while (written < size) {
-		ret = write(fd, buf + written, size - written);
-		if (ret <= 0) {
-			perror("write");
-			exit(1);
-		}
-		written += ret;
-	}
-	return size;
-}
-
-void usage(char** argv)
-{
-	fprintf(stderr, "usage:\n"
-		"%s [client|server] [read|write] domid nodepath\n", argv[0]);
-	exit(1);
-}
-
-#define BUFSIZE 5000
-char buf[BUFSIZE];
-void reader(struct libxenvchan *ctrl)
-{
-	int size;
-	for (;;) {
-		size = rand() % (BUFSIZE - 1) + 1;
-		size = libxenvchan_read(ctrl, buf, size);
-		fprintf(stderr, "#");
-		if (size < 0) {
-			perror("read vchan");
-			libxenvchan_close(ctrl);
-			exit(1);
-		}
-		size = write_all(1, buf, size);
-		if (size < 0) {
-			perror("stdout write");
-			exit(1);
-		}
-		if (size == 0) {
-			perror("write size=0?\n");
-			exit(1);
-		}
-	}
-}
-
-void writer(struct libxenvchan *ctrl)
-{
-	int size;
-	for (;;) {
-		size = rand() % (BUFSIZE - 1) + 1;
-		size = read(0, buf, size);
-		if (size < 0) {
-			perror("read stdin");
-			libxenvchan_close(ctrl);
-			exit(1);
-		}
-		if (size == 0)
-			break;
-		size = libxenvchan_write_all(ctrl, buf, size);
-		fprintf(stderr, "#");
-		if (size < 0) {
-			perror("vchan write");
-			exit(1);
-		}
-		if (size == 0) {
-			perror("write size=0?\n");
-			exit(1);
-		}
-	}
-}
-
-
-/**
-	Simple libxenvchan application, both client and server.
-	One side does writing, the other side does reading; both from
-	standard input/output fds.
-*/
-int main(int argc, char **argv)
-{
-	int seed = time(0);
-	struct libxenvchan *ctrl = 0;
-	int wr = 0;
-	if (argc < 4)
-		usage(argv);
-	if (!strcmp(argv[2], "read"))
-		wr = 0;
-	else if (!strcmp(argv[2], "write"))
-		wr = 1;
-	else
-		usage(argv);
-	if (!strcmp(argv[1], "server"))
-		ctrl = libxenvchan_server_init(NULL, atoi(argv[3]), argv[4], 0, 0);
-	else if (!strcmp(argv[1], "client"))
-		ctrl = libxenvchan_client_init(NULL, atoi(argv[3]), argv[4]);
-	else
-		usage(argv);
-	if (!ctrl) {
-		perror("libxenvchan_*_init");
-		exit(1);
-	}
-	ctrl->blocking = 1;
-
-	srand(seed);
-	fprintf(stderr, "seed=%d\n", seed);
-	if (wr)
-		writer(ctrl);
-	else
-		reader(ctrl);
-	libxenvchan_close(ctrl);
-	return 0;
-}
diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c
deleted file mode 100644
index e1d959c6d1..0000000000
--- a/tools/libvchan/vchan-socket-proxy.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/**
- * @file
- * @section AUTHORS
- *
- * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *
- *  Authors:
- *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
- *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
- *       Marek Marczykowski-Górecki  <marmarek@invisiblethingslab.com>
- *
- * @section LICENSE
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * @section DESCRIPTION
- *
- * This is a vchan to unix socket proxy. Vchan server is set, and on client
- * connection, local socket connection is established. Communication is bidirectional.
- * One client is served at a time, clients needs to coordinate this themselves.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <getopt.h>
-
-#include <xenstore.h>
-#include <xenctrl.h>
-#include <libxenvchan.h>
-
-static void usage(char** argv)
-{
-    fprintf(stderr, "usage:\n"
-        "\t%s [options] domainid nodepath [socket-path|file-no|-]\n"
-        "\n"
-        "options:\n"
-        "\t-m, --mode=client|server - vchan connection mode (client by default)\n"
-        "\t-s, --state-path=path - xenstore path where write \"running\" to \n"
-        "\t                        at startup\n"
-        "\t-v, --verbose - verbose logging\n"
-        "\n"
-        "client: client of a vchan connection, fourth parameter can be:\n"
-        "\tsocket-path: listen on a UNIX socket at this path and connect to vchan\n"
-        "\t             whenever new connection is accepted;\n"
-        "\t             handle multiple _subsequent_ connections, until terminated\n"
-        "\n"
-        "\tfile-no:     except open FD of a socket in listen mode;\n"
-        "\t             otherwise similar to socket-path\n"
-        "\n"
-        "\t-:           open vchan connection immediately and pass the data\n"
-        "\t             from stdin/stdout; terminate when vchan connection\n"
-        "\t             is closed\n"
-        "\n"
-        "server: server of a vchan connection, fourth parameter can be:\n"
-        "\tsocket-path: connect to this UNIX socket when new vchan connection\n"
-        "\t             is accepted;\n"
-        "\t             handle multiple _subsequent_ connections, until terminated\n"
-        "\n"
-        "\tfile-no:     pass data to/from this FD; terminate when vchan connection\n"
-        "\t             is closed\n"
-        "\n"
-        "\t-:           pass data to/from stdin/stdout; terminate when vchan\n"
-        "\t             connection is closed\n",
-        argv[0]);
-    exit(1);
-}
-
-#define BUFSIZE 8192
-char inbuf[BUFSIZE];
-char outbuf[BUFSIZE];
-int insiz = 0;
-int outsiz = 0;
-int verbose = 0;
-
-struct vchan_proxy_state {
-    struct libxenvchan *ctrl;
-    int output_fd;
-    int input_fd;
-};
-
-static void vchan_wr(struct libxenvchan *ctrl) {
-    int ret;
-
-    if (!insiz)
-        return;
-    ret = libxenvchan_write(ctrl, inbuf, insiz);
-    if (ret < 0) {
-        fprintf(stderr, "vchan write failed\n");
-        exit(1);
-    }
-    if (verbose)
-        fprintf(stderr, "wrote %d bytes to vchan\n", ret);
-    if (ret > 0) {
-        insiz -= ret;
-        memmove(inbuf, inbuf + ret, insiz);
-    }
-}
-
-static void socket_wr(int output_fd) {
-    int ret;
-
-    if (!outsiz)
-        return;
-    ret = write(output_fd, outbuf, outsiz);
-    if (ret < 0 && errno != EAGAIN)
-        exit(1);
-    if (ret > 0) {
-        outsiz -= ret;
-        memmove(outbuf, outbuf + ret, outsiz);
-    }
-}
-
-static int set_nonblocking(int fd, int nonblocking) {
-    int flags = fcntl(fd, F_GETFL);
-    if (flags == -1)
-        return -1;
-
-    if (nonblocking)
-        flags |= O_NONBLOCK;
-    else
-        flags &= ~O_NONBLOCK;
-
-    if (fcntl(fd, F_SETFL, flags) == -1)
-        return -1;
-
-    return 0;
-}
-
-static int connect_socket(const char *path_or_fd) {
-    int fd;
-    char *endptr;
-    struct sockaddr_un addr;
-
-    fd = strtoll(path_or_fd, &endptr, 0);
-    if (*endptr == '\0') {
-        set_nonblocking(fd, 1);
-        return fd;
-    }
-
-    if (strlen(path_or_fd) >= sizeof(addr.sun_path)) {
-        fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n",
-                path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path));
-        return -1;
-    }
-
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (fd == -1) {
-        perror("socket");
-        return -1;
-    }
-
-    addr.sun_family = AF_UNIX;
-    strcpy(addr.sun_path, path_or_fd);
-    if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        perror("connect");
-        close(fd);
-        return -1;
-    }
-
-    set_nonblocking(fd, 1);
-
-    return fd;
-}
-
-static int listen_socket(const char *path_or_fd) {
-    int fd;
-    char *endptr;
-    struct sockaddr_un addr;
-
-    fd = strtoll(path_or_fd, &endptr, 0);
-    if (*endptr == '\0') {
-        return fd;
-    }
-
-    if (strlen(path_or_fd) >= sizeof(addr.sun_path)) {
-        fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n",
-                path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path));
-        return -1;
-    }
-
-    /* if not a number, assume a socket path */
-    fd = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (fd == -1) {
-        perror("socket");
-        return -1;
-    }
-
-    addr.sun_family = AF_UNIX;
-    strcpy(addr.sun_path, path_or_fd);
-    if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        perror("bind");
-        close(fd);
-        return -1;
-    }
-    if (listen(fd, 5) != 0) {
-        perror("listen");
-        close(fd);
-        return -1;
-    }
-
-    return fd;
-}
-
-static struct libxenvchan *connect_vchan(int domid, const char *path) {
-    struct libxenvchan *ctrl = NULL;
-    struct xs_handle *xs = NULL;
-    xc_interface *xc = NULL;
-    xc_dominfo_t dominfo;
-    char **watch_ret;
-    unsigned int watch_num;
-    int ret;
-
-    xs = xs_open(XS_OPEN_READONLY);
-    if (!xs) {
-        perror("xs_open");
-        goto out;
-    }
-    xc = xc_interface_open(NULL, NULL, XC_OPENFLAG_NON_REENTRANT);
-    if (!xc) {
-        perror("xc_interface_open");
-        goto out;
-    }
-    /* wait for vchan server to create *path* */
-    if (!xs_watch(xs, path, "path")) {
-        fprintf(stderr, "xs_watch(%s) failed.\n", path);
-        goto out;
-    }
-    if (!xs_watch(xs, "@releaseDomain", "release")) {
-        fprintf(stderr, "xs_watch(@releaseDomain failed.\n");
-        goto out;
-    }
-
-    while ((watch_ret = xs_read_watch(xs, &watch_num))) {
-        /* don't care about exact which fired the watch */
-        free(watch_ret);
-        ctrl = libxenvchan_client_init(NULL, domid, path);
-        if (ctrl)
-            break;
-
-        ret = xc_domain_getinfo(xc, domid, 1, &dominfo);
-        /* break the loop if domain is definitely not there anymore, but
-         * continue if it is or the call failed (like EPERM) */
-        if (ret == -1 && errno == ESRCH)
-            break;
-        if (ret == 1 && (dominfo.domid != (uint32_t)domid || dominfo.dying))
-            break;
-    }
-
-out:
-    if (xc)
-        xc_interface_close(xc);
-    if (xs)
-        xs_close(xs);


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMD-0006Th-De; Fri, 18 Sep 2020 19:47:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMC-0006TZ-23
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:44 +0000
X-Inumbo-ID: f4fa7cfa-8589-4196-84a2-647b0c44f89f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f4fa7cfa-8589-4196-84a2-647b0c44f89f;
 Fri, 18 Sep 2020 19:47:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=aBXCyFgv1e1A2miz8UoqgWdNP/Bjjz+kg0b8v4CNT7w=; b=shTCQOAx9sh+xRs1UO3rC/qxjL
 G5AcjGY9UTSjdL7twO4fk46OpFqUTAwR6KXeko3lDhwq4JNfTLSEVnymfAMxLFWOJRN6vxcXIveUQ
 pYm1U0ywLJ+ykOZQXSyC6UXyc2gYeT9Tn9BONJbOxIOwwrIXIWjCnU3TClxyHdZMEwAI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMM5-000793-HX
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMM5-0004Sm-Gk
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: split libxenstat into new tools/libs/stat
 directory
Message-Id: <E1kJMM5-0004Sm-Gk@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6d0ec0539077943af6d02be2adc79766c7950132
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:38 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools: split libxenstat into new tools/libs/stat directory
    
    There is no reason why libxenstat is not placed in the tools/libs
    directory.
    
    At the same time move xenstat.h to a dedicated include directory
    in tools/libs/stat in order to follow the same pattern as the other
    libraries in tools/libs.
    
    As now xentop is the only left directory in xenstat move it directly
    under tools and get rid of tools/xenstat.
    
    Fix some missing prototype errors (add one prototype and make two
    functions static).
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 .gitignore                                         |    8 +-
 tools/Makefile                                     |    2 +-
 tools/Rules.mk                                     |    6 -
 tools/libs/Makefile                                |    1 +
 tools/libs/stat/COPYING                            |  509 ++++++++
 tools/libs/stat/Makefile                           |  132 ++
 tools/libs/stat/bindings/swig/perl/.empty          |    1 +
 tools/libs/stat/bindings/swig/python/.empty        |    1 +
 tools/libs/stat/bindings/swig/xenstat.i            |    8 +
 tools/libs/stat/include/xenstat.h                  |  197 +++
 tools/libs/stat/xenstat.c                          |  735 +++++++++++
 tools/libs/stat/xenstat_freebsd.c                  |   47 +
 tools/libs/stat/xenstat_linux.c                    |  496 ++++++++
 tools/libs/stat/xenstat_netbsd.c                   |   97 ++
 tools/libs/stat/xenstat_priv.h                     |  108 ++
 tools/libs/stat/xenstat_qmp.c                      |  446 +++++++
 tools/libs/stat/xenstat_solaris.c                  |  405 ++++++
 tools/libs/uselibs.mk                              |    2 +
 tools/xenstat/Makefile                             |   10 -
 tools/xenstat/libxenstat/COPYING                   |  509 --------
 tools/xenstat/libxenstat/Makefile                  |  195 ---
 tools/xenstat/libxenstat/bindings/swig/perl/.empty |    1 -
 .../xenstat/libxenstat/bindings/swig/python/.empty |    1 -
 tools/xenstat/libxenstat/bindings/swig/xenstat.i   |    8 -
 tools/xenstat/libxenstat/src/xenstat.c             |  735 -----------
 tools/xenstat/libxenstat/src/xenstat.h             |  194 ---
 tools/xenstat/libxenstat/src/xenstat_freebsd.c     |   47 -
 tools/xenstat/libxenstat/src/xenstat_linux.c       |  496 --------
 tools/xenstat/libxenstat/src/xenstat_netbsd.c      |   97 --
 tools/xenstat/libxenstat/src/xenstat_priv.h        |  108 --
 tools/xenstat/libxenstat/src/xenstat_qmp.c         |  446 -------
 tools/xenstat/libxenstat/src/xenstat_solaris.c     |  405 ------
 tools/xenstat/xentop/Makefile                      |   50 -
 tools/xenstat/xentop/TODO                          |   34 -
 tools/xenstat/xentop/xentop.c                      | 1346 --------------------
 tools/xentop/Makefile                              |   50 +
 tools/xentop/TODO                                  |   34 +
 tools/xentop/xentop.c                              | 1346 ++++++++++++++++++++
 38 files changed, 4621 insertions(+), 4692 deletions(-)

diff --git a/.gitignore b/.gitignore
index 364b09506b..5e8c47e2db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,6 +128,10 @@ tools/libs/guest/xc_core.h
 tools/libs/guest/xc_core_arm.h
 tools/libs/guest/xc_core_x86.h
 tools/libs/guest/xc_private.h
+tools/libs/stat/_paths.h
+tools/libs/stat/headers.chk
+tools/libs/stat/libxenstat.map
+tools/libs/stat/xenstat.pc
 tools/libs/store/headers.chk
 tools/libs/store/list.h
 tools/libs/store/utils.h
@@ -276,9 +280,6 @@ tools/xenmon/xentrace_setmask
 tools/xenmon/xenbaked
 tools/xenpaging/xenpaging
 tools/xenpmd/xenpmd
-tools/xenstat/libxenstat/src/_paths.h
-tools/xenstat/libxenstat/xenstat.pc
-tools/xenstat/xentop/xentop
 tools/xenstore/xenstore
 tools/xenstore/xenstore-chmod
 tools/xenstore/xenstore-exists
@@ -291,6 +292,7 @@ tools/xenstore/xenstore-ls
 tools/xenstore/xenstored
 tools/xenstore/xenstored_test
 tools/xenstore/xs_tdb_dump
+tools/xentop/xentop
 tools/xentrace/xentrace_setsize
 tools/xentrace/tbctl
 tools/xentrace/xenctx
diff --git a/tools/Makefile b/tools/Makefile
index 0db01707a4..ea69675cca 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -17,7 +17,7 @@ SUBDIRS-$(CONFIG_XCUTILS) += xcutils
 SUBDIRS-$(CONFIG_X86) += firmware
 SUBDIRS-y += console
 SUBDIRS-y += xenmon
-SUBDIRS-y += xenstat
+SUBDIRS-y += xentop
 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
 SUBDIRS-y += libfsimage
 SUBDIRS-$(CONFIG_Linux) += vchan
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 5f17492a68..4fd91fa444 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -18,7 +18,6 @@ include $(XEN_ROOT)/tools/libs/uselibs.mk
 XEN_libxenlight    = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
 XEN_libxlutil      = $(XEN_libxenlight)
-XEN_libxenstat     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
 
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
@@ -108,11 +107,6 @@ ifeq ($(CONFIG_Linux),y)
 LDLIBS_libxenstore += -ldl
 endif
 
-CFLAGS_libxenstat  = -I$(XEN_libxenstat)
-SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
-LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_libxenstat)/libxenstat$(libextension)
-SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_libxenstat)
-
 ifeq ($(debug),y)
 # Disable optimizations
 CFLAGS += -O0 -fno-omit-frame-pointer
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 756d059ee7..e8fcd59214 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -13,6 +13,7 @@ SUBDIRS-y += ctrl
 SUBDIRS-y += guest
 SUBDIRS-y += hypfs
 SUBDIRS-y += store
+SUBDIRS-y += stat
 SUBDIRS-$(CONFIG_Linux) += vchan
 
 ifeq ($(CONFIG_RUMP),y)
diff --git a/tools/libs/stat/COPYING b/tools/libs/stat/COPYING
new file mode 100644
index 0000000000..480e5f1876
--- /dev/null
+++ b/tools/libs/stat/COPYING
@@ -0,0 +1,509 @@
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+	51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard.  To achieve this, non-free programs must
+be allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at least
+    three years, to give the same user the materials specified in
+    Subsection 6a, above, for a charge no more than the cost of
+    performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James
+  Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/tools/libs/stat/Makefile b/tools/libs/stat/Makefile
new file mode 100644
index 0000000000..5463f5f7ca
--- /dev/null
+++ b/tools/libs/stat/Makefile
@@ -0,0 +1,132 @@
+# libxenstat: statistics-collection library for Xen
+# Copyright (C) International Business Machines Corp., 2005
+# Author: Josh Triplett <josh@kernel.org>
+# 
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(CFLAGS_xeninclude) -include $(XEN_ROOT)/tools/config.h
+
+SRCS-y += xenstat.c
+SRCS-y += xenstat_qmp.c
+SRCS-$(CONFIG_Linux) += xenstat_linux.c
+SRCS-$(CONFIG_SunOS) += xenstat_solaris.c
+SRCS-$(CONFIG_NetBSD) += xenstat_netbsd.c
+SRCS-$(CONFIG_FreeBSD) += xenstat_freebsd.c
+
+LDLIBS-y += -lyajl
+LDLIBS-$(CONFIG_SunOS) += -lkstat
+APPEND_LDFLAGS += $(LDLIBS-y)
+
+include $(XEN_ROOT)/tools/libs/libs.mk
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenstat)/include
+
+$(LIB_OBJS): _paths.h
+
+PYLIB=bindings/swig/python/_xenstat.so
+PYMOD=bindings/swig/python/xenstat.py
+PYSRC=bindings/swig/python/_xenstat.c
+PERLLIB=bindings/swig/perl/xenstat.so
+PERLMOD=bindings/swig/perl/xenstat.pm
+PERLSRC=bindings/swig/perl/xenstat.c
+BINDINGS=$(PYLIB) $(PYMOD) $(PERLLIB) $(PERLMOD)
+BINDINGSRC=$(PYSRC) $(PERLSRC)
+
+# The all-bindings target builds all the language bindings
+.PHONY: all-bindings
+all-bindings: perl-bindings python-bindings
+
+# The install-bindings target installs all the language bindings
+install-bindings: install-perl-bindings install-python-bindings
+
+.PHONY: uninstall-bindings
+uninstall-bindings: uninstall-perl-bindings uninstall-python-bindings
+
+$(BINDINGS): $(SHLIB) $(SHLIB_LINKS) include/xenstat.h
+
+SWIG_FLAGS=-module xenstat -Iinclude -I.
+
+# Python bindings
+PYTHON_VERSION=$(PYTHON:python%=%)
+PYTHON_FLAGS=-I/usr/include/python$(PYTHON_VERSION) -lpython$(PYTHON_VERSION)
+$(PYMOD): $(PYSRC)
+$(PYSRC): bindings/swig/xenstat.i
+	swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $<
+
+$(PYLIB): $(PYSRC)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
+
+python-bindings: $(PYLIB) $(PYMOD)
+
+pythonlibdir=$(prefix)/lib/python$(PYTHON_VERSION)/site-packages
+install-python-bindings: $(PYLIB) $(PYMOD)
+	$(INSTALL_PROG) $(PYLIB) $(DESTDIR)$(pythonlibdir)/_xenstat.so
+	$(INSTALL_PROG) $(PYMOD) $(DESTDIR)$(pythonlibdir)/xenstat.py
+
+.PHONY: uninstall-python-bindings
+uninstall-python-bindings:
+	rm -f $(DESTDIR)$(pythonlibdir)/_xenstat.so
+	rm -f $(DESTDIR)$(pythonlibdir)/xenstat.py
+
+ifeq ($(XENSTAT_PYTHON_BINDINGS),y)
+.PHONY: all
+all: python-bindings
+install: install-python-bindings
+uninstall: uninstall-python-bindings
+endif
+
+# Perl bindings
+PERL_FLAGS=`perl -MConfig -e 'print "$$Config{ccflags} -I$$Config{archlib}/CORE";'`
+$(PERLMOD): $(PERLSRC)
+$(PERLSRC): bindings/swig/xenstat.i
+	swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $<
+
+$(PERLLIB): $(PERLSRC)
+	$(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
+
+.PHONY: perl-bindings
+perl-bindings: $(PERLLIB) $(PERLMOD)
+
+.PHONY: install-perl-bindings
+perllibdir=$(prefix)/lib/perl5
+perlmoddir=$(prefix)/share/perl5
+install-perl-bindings: $(PERLLIB) $(PERLMOD)
+	$(INSTALL_PROG) $(PERLLIB) $(DESTDIR)$(perllibdir)/xenstat.so
+	$(INSTALL_PROG) $(PERLMOD) $(DESTDIR)$(perlmoddir)/xenstat.pm
+
+.PHONY: uninstall-perl-bindings
+uninstall-perl-bindings:
+	rm -f $(DESTDIR)$(perllibdir)/xenstat.so
+	rm -f $(DESTDIR)$(perlmoddir)/xenstat.pm
+
+ifeq ($(XENSTAT_PERL_BINDINGS),y)
+.PHONY: all
+all: perl-bindings
+
+.PHONY: install
+install: install-perl-bindings
+uninstall: uninstall-perl-bindings
+endif
+
+clean: cleanlocal
+
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f $(BINDINGS) $(BINDINGSRC) $(DEPS_RM) _paths.h
+	rm -f libxenstat.map
+
+-include $(DEPS_INCLUDE)
+
+genpath-target = $(call buildmakevars2header,_paths.h)
+$(eval $(genpath-target))
diff --git a/tools/libs/stat/bindings/swig/perl/.empty b/tools/libs/stat/bindings/swig/perl/.empty
new file mode 100644
index 0000000000..2a8dd4274d
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/perl/.empty
@@ -0,0 +1 @@
+This directory is empty; this file is included to prevent version control systems from removing the directory.
diff --git a/tools/libs/stat/bindings/swig/python/.empty b/tools/libs/stat/bindings/swig/python/.empty
new file mode 100644
index 0000000000..2a8dd4274d
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/python/.empty
@@ -0,0 +1 @@
+This directory is empty; this file is included to prevent version control systems from removing the directory.
diff --git a/tools/libs/stat/bindings/swig/xenstat.i b/tools/libs/stat/bindings/swig/xenstat.i
new file mode 100644
index 0000000000..d18fe0b155
--- /dev/null
+++ b/tools/libs/stat/bindings/swig/xenstat.i
@@ -0,0 +1,8 @@
+%module xenstat_swig
+%{
+/* Includes the header in the wrapper code */
+#include "xenstat.h"
+%}
+
+/* Parse the header file to generate wrappers */
+%include "xenstat.h"
diff --git a/tools/libs/stat/include/xenstat.h b/tools/libs/stat/include/xenstat.h
new file mode 100644
index 0000000000..c3b98909dd
--- /dev/null
+++ b/tools/libs/stat/include/xenstat.h
@@ -0,0 +1,197 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/* libxenstat API */
+
+#ifndef XENSTAT_H
+#define XENSTAT_H
+
+#include <stdbool.h>
+
+/* Opaque handles */
+typedef struct xenstat_handle xenstat_handle;
+typedef struct xenstat_domain xenstat_domain;
+typedef struct xenstat_node xenstat_node;
+typedef struct xenstat_vcpu xenstat_vcpu;
+typedef struct xenstat_network xenstat_network;
+typedef struct xenstat_vbd xenstat_vbd;
+
+/* Initialize the xenstat library.  Returns a handle to be used with
+ * subsequent calls to the xenstat library, or NULL if an error occurs. */
+xenstat_handle *xenstat_init(void);
+
+/* Release the handle to libxc, free resources, etc. */
+void xenstat_uninit(xenstat_handle * handle);
+
+/* Flags for types of information to collect in xenstat_get_node */
+#define XENSTAT_VCPU 0x1
+#define XENSTAT_NETWORK 0x2
+#define XENSTAT_XEN_VERSION 0x4
+#define XENSTAT_VBD 0x8
+#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK|XENSTAT_XEN_VERSION|XENSTAT_VBD)
+
+/* Get all available information about a node */
+xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags);
+
+/* Free the information */
+void xenstat_free_node(xenstat_node * node);
+
+/*
+ * Node functions - extract information from a xenstat_node
+ */
+
+/* Get information about the domain with the given domain ID */
+xenstat_domain *xenstat_node_domain(xenstat_node * node,
+				    unsigned int domid);
+
+/* Get the domain with the given index; used to loop over all domains. */
+xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
+					     unsigned index);
+
+/* Get xen version of the node */
+const char *xenstat_node_xen_version(xenstat_node * node);
+
+/* Get amount of total memory on a node */
+unsigned long long xenstat_node_tot_mem(xenstat_node * node);
+
+/* Get amount of free memory on a node */
+unsigned long long xenstat_node_free_mem(xenstat_node * node);
+
+/* Get amount of freeable memory on a node */
+long xenstat_node_freeable_mb(xenstat_node * node);
+
+/* Find the number of domains existing on a node */
+unsigned int xenstat_node_num_domains(xenstat_node * node);
+
+/* Find the number of CPUs existing on a node */
+unsigned int xenstat_node_num_cpus(xenstat_node * node);
+
+/* Get information about the CPU speed */
+unsigned long long xenstat_node_cpu_hz(xenstat_node * node);
+
+/*
+ * Domain functions - extract information from a xenstat_domain
+ */
+
+/* Get the domain ID for this domain */
+unsigned xenstat_domain_id(xenstat_domain * domain);
+
+/* Set the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain);
+
+/* Get information about how much CPU time has been used */
+unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain);
+
+/* Find the number of VCPUs allocated to a domain */
+unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain);
+
+/* Get the VCPU handle to obtain VCPU stats */
+xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain,
+				  unsigned int vcpu);
+
+/* Find the current memory reservation for this domain */
+unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain);
+
+/* Find the maximum memory reservation for this domain */
+unsigned long long xenstat_domain_max_mem(xenstat_domain * domain);
+
+/* Find the domain's SSID */
+unsigned int xenstat_domain_ssid(xenstat_domain * domain);
+
+/* Get domain states */
+unsigned int xenstat_domain_dying(xenstat_domain * domain);
+unsigned int xenstat_domain_crashed(xenstat_domain * domain);
+unsigned int xenstat_domain_shutdown(xenstat_domain * domain);
+unsigned int xenstat_domain_paused(xenstat_domain * domain);
+unsigned int xenstat_domain_blocked(xenstat_domain * domain);
+unsigned int xenstat_domain_running(xenstat_domain * domain);
+
+/* Get the number of networks for a given domain */
+unsigned int xenstat_domain_num_networks(xenstat_domain *);
+
+/* Get the network handle to obtain network stats */
+xenstat_network *xenstat_domain_network(xenstat_domain * domain,
+					unsigned int network);
+
+/* Get the number of VBDs for a given domain */
+unsigned int xenstat_domain_num_vbds(xenstat_domain *);
+
+/* Get the VBD handle to obtain VBD stats */
+xenstat_vbd *xenstat_domain_vbd(xenstat_domain * domain,
+				    unsigned int vbd);
+
+/*
+ * VCPU functions - extract information from a xenstat_vcpu
+ */
+
+/* Get VCPU usage */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu);
+unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu);
+
+
+/*
+ * Network functions - extract information from a xenstat_network
+ */
+
+/* Get the ID for this network */
+unsigned int xenstat_network_id(xenstat_network * network);
+
+/* Get the number of receive bytes for this network */
+unsigned long long xenstat_network_rbytes(xenstat_network * network);
+
+/* Get the number of receive packets for this network */
+unsigned long long xenstat_network_rpackets(xenstat_network * network);
+
+/* Get the number of receive errors for this network */
+unsigned long long xenstat_network_rerrs(xenstat_network * network);
+
+/* Get the number of receive drops for this network */
+unsigned long long xenstat_network_rdrop(xenstat_network * network);
+
+/* Get the number of transmit bytes for this network */
+unsigned long long xenstat_network_tbytes(xenstat_network * network);
+
+/* Get the number of transmit packets for this network */
+unsigned long long xenstat_network_tpackets(xenstat_network * network);
+
+/* Get the number of transmit errors for this network */
+unsigned long long xenstat_network_terrs(xenstat_network * network);
+
+/* Get the number of transmit drops for this network */
+unsigned long long xenstat_network_tdrop(xenstat_network * network);
+
+/*
+ * VBD functions - extract information from a xen_vbd
+ */
+
+/* Get the back driver type  for Virtual Block Device */
+unsigned int xenstat_vbd_type(xenstat_vbd * vbd);
+
+/* Get the device number for Virtual Block Device */
+unsigned int xenstat_vbd_dev(xenstat_vbd * vbd);
+
+/* Get the number of OO/RD/WR requests for vbd */
+unsigned long long xenstat_vbd_oo_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_rd_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_wr_reqs(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_rd_sects(xenstat_vbd * vbd);
+unsigned long long xenstat_vbd_wr_sects(xenstat_vbd * vbd);
+
+/* Returns error while getting stats (1 if error happened, 0 otherwise) */
+bool xenstat_vbd_error(xenstat_vbd * vbd);
+
+#endif /* XENSTAT_H */
diff --git a/tools/libs/stat/xenstat.c b/tools/libs/stat/xenstat.c
new file mode 100644
index 0000000000..6f93d4e982
--- /dev/null
+++ b/tools/libs/stat/xenstat.c
@@ -0,0 +1,735 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "xenstat_priv.h"
+
+/*
+ * Data-collection types
+ */
+/* Called to collect the information for the node and all the domains on
+ * it. When called, the domain information has already been collected. 
+ * Return status is 0 if fatal error occurs, 1 for success. Collectors
+ * may prune a domain from the list if it has been deleted between the
+ * time the list was setup and the time the colector is called */
+typedef int (*xenstat_collect_func)(xenstat_node * node);
+/* Called to free the information collected by the collect function.  The free
+ * function will only be called on a xenstat_node if that node includes
+ * information collected by the corresponding collector. */
+typedef void (*xenstat_free_func)(xenstat_node * node);
+/* Called to free any information stored in the handle.  Note the lack of a
+ * matching init function; the collect functions should initialize on first
+ * use.  Also, the uninit function must handle the case that the collector has
+ * never been initialized. */
+typedef void (*xenstat_uninit_func)(xenstat_handle * handle);
+typedef struct xenstat_collector {
+	unsigned int flag;
+	xenstat_collect_func collect;
+	xenstat_free_func free;
+	xenstat_uninit_func uninit;
+} xenstat_collector;
+
+static int  xenstat_collect_vcpus(xenstat_node * node);
+static int  xenstat_collect_xen_version(xenstat_node * node);
+static void xenstat_free_vcpus(xenstat_node * node);
+static void xenstat_free_networks(xenstat_node * node);
+static void xenstat_free_xen_version(xenstat_node * node);
+static void xenstat_free_vbds(xenstat_node * node);
+static void xenstat_uninit_vcpus(xenstat_handle * handle);
+static void xenstat_uninit_xen_version(xenstat_handle * handle);
+static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id);
+static void xenstat_prune_domain(xenstat_node *node, unsigned int entry);
+
+static xenstat_collector collectors[] = {
+	{ XENSTAT_VCPU, xenstat_collect_vcpus,
+	  xenstat_free_vcpus, xenstat_uninit_vcpus },
+	{ XENSTAT_NETWORK, xenstat_collect_networks,
+	  xenstat_free_networks, xenstat_uninit_networks },
+	{ XENSTAT_XEN_VERSION, xenstat_collect_xen_version,
+	  xenstat_free_xen_version, xenstat_uninit_xen_version },
+	{ XENSTAT_VBD, xenstat_collect_vbds,
+	  xenstat_free_vbds, xenstat_uninit_vbds }
+};
+
+#define NUM_COLLECTORS (sizeof(collectors)/sizeof(xenstat_collector))
+
+/*
+ * libxenstat API
+ */
+xenstat_handle *xenstat_init(void)
+{
+	xenstat_handle *handle;
+
+	handle = (xenstat_handle *) calloc(1, sizeof(xenstat_handle));
+	if (handle == NULL)
+		return NULL;
+
+#if defined(PAGESIZE)
+	handle->page_size = PAGESIZE;
+#elif defined(PAGE_SIZE)
+	handle->page_size = PAGE_SIZE;
+#else
+	handle->page_size = sysconf(_SC_PAGE_SIZE);
+	if (handle->page_size < 0) {
+		perror("Failed to retrieve page size.");
+		free(handle);
+		return NULL;
+	}
+#endif
+
+	handle->xc_handle = xc_interface_open(0,0,0);
+	if (!handle->xc_handle) {
+		perror("xc_interface_open");
+		free(handle);
+		return NULL;
+	}
+
+	handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
+	if (handle->xshandle == NULL) {
+		perror("unable to open xenstore");
+		xc_interface_close(handle->xc_handle);
+		free(handle);
+		return NULL;
+	}
+
+	return handle;
+}
+
+void xenstat_uninit(xenstat_handle * handle)
+{
+	unsigned int i;
+	if (handle) {
+		for (i = 0; i < NUM_COLLECTORS; i++)
+			collectors[i].uninit(handle);
+		xc_interface_close(handle->xc_handle);
+		xs_daemon_close(handle->xshandle);
+		free(handle->priv);
+		free(handle);
+	}
+}
+
+xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
+{
+#define DOMAIN_CHUNK_SIZE 256
+	xenstat_node *node;
+	xc_physinfo_t physinfo = { 0 };
+	xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
+	int new_domains;
+	unsigned int i;
+
+	/* Create the node */
+	node = (xenstat_node *) calloc(1, sizeof(xenstat_node));
+	if (node == NULL)
+		return NULL;
+
+	/* Store the handle in the node for later access */
+	node->handle = handle;
+
+	/* Get information about the physical system */
+	if (xc_physinfo(handle->xc_handle, &physinfo) < 0) {
+		free(node);
+		return NULL;
+	}
+
+
+	node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
+        node->num_cpus = physinfo.nr_cpus;
+	node->tot_mem = ((unsigned long long)physinfo.total_pages)
+	    * handle->page_size;
+	node->free_mem = ((unsigned long long)physinfo.free_pages)
+	    * handle->page_size;
+
+	node->freeable_mb = 0;
+	/* malloc(0) is not portable, so allocate a single domain.  This will
+	 * be resized below. */
+	node->domains = malloc(sizeof(xenstat_domain));
+	if (node->domains == NULL) {
+		free(node);
+		return NULL;
+	}
+
+	node->num_domains = 0;
+	do {
+		xenstat_domain *domain, *tmp;
+
+		new_domains = xc_domain_getinfolist(handle->xc_handle,
+						    node->num_domains, 
+						    DOMAIN_CHUNK_SIZE, 
+						    domaininfo);
+		if (new_domains < 0)
+			goto err;
+
+		tmp = realloc(node->domains,
+			      (node->num_domains + new_domains)
+			      * sizeof(xenstat_domain));
+		if (tmp == NULL)
+			goto err;
+
+		node->domains = tmp;
+
+		domain = node->domains + node->num_domains;
+
+		/* zero out newly allocated memory in case error occurs below */
+		memset(domain, 0, new_domains * sizeof(xenstat_domain));
+
+		for (i = 0; i < new_domains; i++) {
+			/* Fill in domain using domaininfo[i] */
+			domain->id = domaininfo[i].domain;
+			domain->name = xenstat_get_domain_name(handle, 
+							       domain->id);
+			if (domain->name == NULL) {
+				if (errno == ENOMEM) {
+					/* fatal error */
+					xenstat_free_node(node);
+					return NULL;
+				}
+				else {
+					/* failed to get name -- this means the
+					   domain is being destroyed so simply
+					   ignore this entry */
+					continue;
+				}
+			}
+			domain->state = domaininfo[i].flags;
+			domain->cpu_ns = domaininfo[i].cpu_time;
+			domain->num_vcpus = (domaininfo[i].max_vcpu_id+1);
+			domain->vcpus = NULL;
+			domain->cur_mem =
+			    ((unsigned long long)domaininfo[i].tot_pages)
+			    * handle->page_size;
+			domain->max_mem =
+			    domaininfo[i].max_pages == UINT_MAX
+			    ? (unsigned long long)-1
+			    : (unsigned long long)(domaininfo[i].max_pages
+						   * handle->page_size);
+			domain->ssid = domaininfo[i].ssidref;
+			domain->num_networks = 0;
+			domain->networks = NULL;
+			domain->num_vbds = 0;
+			domain->vbds = NULL;
+
+			domain++;
+			node->num_domains++;
+		}
+	} while (new_domains == DOMAIN_CHUNK_SIZE);
+
+
+	/* Run all the extra data collectors requested */
+	node->flags = 0;
+	for (i = 0; i < NUM_COLLECTORS; i++) {
+		if ((flags & collectors[i].flag) == collectors[i].flag) {
+			node->flags |= collectors[i].flag;
+			if(collectors[i].collect(node) == 0) {
+				xenstat_free_node(node);
+				return NULL;
+			}
+		}
+	}
+
+	return node;
+err:
+	free(node->domains);
+	free(node);
+	return NULL;
+}
+
+void xenstat_free_node(xenstat_node * node)
+{
+	int i;
+
+	if (node) {
+		if (node->domains) {
+			for (i = 0; i < node->num_domains; i++)
+				free(node->domains[i].name);
+
+			for (i = 0; i < NUM_COLLECTORS; i++)
+				if((node->flags & collectors[i].flag)
+				   == collectors[i].flag)
+					collectors[i].free(node);
+			free(node->domains);
+		}
+		free(node);
+	}
+}
+
+xenstat_domain *xenstat_node_domain(xenstat_node * node, unsigned int domid)
+{
+	unsigned int i;
+
+	/* FIXME: binary search */
+	/* Find the appropriate domain entry in the node struct. */
+	for (i = 0; i < node->num_domains; i++) {
+		if (node->domains[i].id == domid)
+			return &(node->domains[i]);
+	}
+	return NULL;
+}
+
+xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
+					     unsigned int index)
+{
+	if (index < node->num_domains)
+		return &(node->domains[index]);
+	return NULL;
+}
+
+const char *xenstat_node_xen_version(xenstat_node * node)
+{
+	return node->handle->xen_version;
+}
+
+unsigned long long xenstat_node_tot_mem(xenstat_node * node)
+{
+	return node->tot_mem;
+}
+
+unsigned long long xenstat_node_free_mem(xenstat_node * node)
+{
+	return node->free_mem;
+}
+
+long xenstat_node_freeable_mb(xenstat_node * node)
+{
+	return node->freeable_mb;
+}
+
+unsigned int xenstat_node_num_domains(xenstat_node * node)
+{
+	return node->num_domains;
+}
+
+unsigned int xenstat_node_num_cpus(xenstat_node * node)
+{
+	return node->num_cpus;
+}
+
+/* Get information about the CPU speed */
+unsigned long long xenstat_node_cpu_hz(xenstat_node * node)
+{
+	return node->cpu_hz;
+}
+
+/* Get the domain ID for this domain */
+unsigned xenstat_domain_id(xenstat_domain * domain)
+{
+	return domain->id;
+}
+
+/* Get the domain name for the domain */
+char *xenstat_domain_name(xenstat_domain * domain)
+{
+	return domain->name;
+}
+
+/* Get information about how much CPU time has been used */
+unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
+{
+	return domain->cpu_ns;
+}
+
+/* Find the number of VCPUs for a domain */
+unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain)
+{
+	return domain->num_vcpus;
+}
+
+xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain, unsigned int vcpu)
+{
+	if (vcpu < domain->num_vcpus)
+		return &(domain->vcpus[vcpu]);
+	return NULL;
+}
+
+/* Find the current memory reservation for this domain */
+unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain)
+{
+	return domain->cur_mem;
+}
+
+/* Find the maximum memory reservation for this domain */
+unsigned long long xenstat_domain_max_mem(xenstat_domain * domain)
+{
+	return domain->max_mem;
+}
+
+/* Find the domain's SSID */
+unsigned int xenstat_domain_ssid(xenstat_domain * domain)
+{
+	return domain->ssid;
+}
+
+/* Get domain states */
+unsigned int xenstat_domain_dying(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_dying) == XEN_DOMINF_dying;
+}
+
+unsigned int xenstat_domain_crashed(xenstat_domain * domain)
+{
+	return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+	    && (((domain->state >> XEN_DOMINF_shutdownshift)
+		 & XEN_DOMINF_shutdownmask) == SHUTDOWN_crash);
+}
+
+unsigned int xenstat_domain_shutdown(xenstat_domain * domain)
+{
+	return ((domain->state & XEN_DOMINF_shutdown) == XEN_DOMINF_shutdown)
+	    && (((domain->state >> XEN_DOMINF_shutdownshift)
+		 & XEN_DOMINF_shutdownmask) != SHUTDOWN_crash);
+}
+
+unsigned int xenstat_domain_paused(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_paused) == XEN_DOMINF_paused;
+}
+
+unsigned int xenstat_domain_blocked(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_blocked) == XEN_DOMINF_blocked;
+}
+
+unsigned int xenstat_domain_running(xenstat_domain * domain)
+{
+	return (domain->state & XEN_DOMINF_running) == XEN_DOMINF_running;
+}
+
+/* Get the number of networks for a given domain */
+unsigned int xenstat_domain_num_networks(xenstat_domain * domain)
+{
+	return domain->num_networks;
+}
+
+/* Get the network handle to obtain network stats */
+xenstat_network *xenstat_domain_network(xenstat_domain * domain,
+					unsigned int network)
+{
+	if (domain->networks && network < domain->num_networks)
+		return &(domain->networks[network]);
+	return NULL;
+}
+
+/* Get the number of VBDs for a given domain */
+unsigned int xenstat_domain_num_vbds(xenstat_domain * domain)
+{
+	return domain->num_vbds;
+}
+
+/* Get the VBD handle to obtain VBD stats */
+xenstat_vbd *xenstat_domain_vbd(xenstat_domain * domain,
+				unsigned int vbd)
+{
+	if (domain->vbds && vbd < domain->num_vbds)
+		return &(domain->vbds[vbd]);
+	return NULL;
+}
+
+/*
+ * VCPU functions
+ */
+/* Collect information about VCPUs */
+static int xenstat_collect_vcpus(xenstat_node * node)
+{
+	unsigned int i, vcpu, inc_index;
+
+	/* Fill in VCPU information */
+	for (i = 0; i < node->num_domains; i+=inc_index) {
+		inc_index = 1; /* default is to increment to next domain */
+
+		node->domains[i].vcpus = malloc(node->domains[i].num_vcpus
+						* sizeof(xenstat_vcpu));
+		if (node->domains[i].vcpus == NULL)
+			return 0;
+	
+		for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) {
+			/* FIXME: need to be using a more efficient mechanism*/
+			xc_vcpuinfo_t info;
+
+			if (xc_vcpu_getinfo(node->handle->xc_handle,
+					    node->domains[i].id, vcpu, &info) != 0) {
+				if (errno == ENOMEM) {
+					/* fatal error */ 
+					return 0;
+				}
+				else {
+					/* domain is in transition - remove
+					   from list */
+					xenstat_prune_domain(node, i);
+
+					/* remember not to increment index! */
+					inc_index = 0;
+					break;
+				}
+			}
+			else {
+				node->domains[i].vcpus[vcpu].online = info.online;
+				node->domains[i].vcpus[vcpu].ns = info.cpu_time;
+			}
+		}
+	}
+	return 1;
+}
+
+/* Free VCPU information */
+static void xenstat_free_vcpus(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].vcpus);
+}
+
+/* Free VCPU information in handle - nothing to do */
+static void xenstat_uninit_vcpus(xenstat_handle * handle)
+{
+}
+
+/* Get VCPU online status */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu)
+{
+	return vcpu->online;
+}
+
+/* Get VCPU usage */
+unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu)
+{
+	return vcpu->ns;
+}
+
+/*
+ * Network functions
+ */
+
+/* Free network information */
+static void xenstat_free_networks(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].networks);
+}
+
+/* Get the network ID */
+unsigned int xenstat_network_id(xenstat_network * network)
+{
+	return network->id;
+}
+
+/* Get the number of receive bytes */
+unsigned long long xenstat_network_rbytes(xenstat_network * network)
+{
+	return network->rbytes;
+}
+
+/* Get the number of receive packets */
+unsigned long long xenstat_network_rpackets(xenstat_network * network)
+{
+	return network->rpackets;
+}
+
+/* Get the number of receive errors */
+unsigned long long xenstat_network_rerrs(xenstat_network * network)
+{
+	return network->rerrs;
+}
+
+/* Get the number of receive drops */
+unsigned long long xenstat_network_rdrop(xenstat_network * network)
+{
+	return network->rdrop;
+}
+
+/* Get the number of transmit bytes */
+unsigned long long xenstat_network_tbytes(xenstat_network * network)
+{
+	return network->tbytes;
+}
+
+/* Get the number of transmit packets */
+unsigned long long xenstat_network_tpackets(xenstat_network * network)
+{
+	return network->tpackets;
+}
+
+/* Get the number of transmit errors */
+unsigned long long xenstat_network_terrs(xenstat_network * network)
+{
+	return network->terrs;
+}
+
+/* Get the number of transmit dropped packets */
+unsigned long long xenstat_network_tdrop(xenstat_network * network)
+{
+	return network->tdrop;
+}
+
+/*
+ * Xen version functions
+ */
+
+/* Collect Xen version information */
+static int xenstat_collect_xen_version(xenstat_node * node)
+{
+	long vnum = 0;
+	xen_extraversion_t version;
+
+	/* Collect Xen version information if not already collected */
+	if (node->handle->xen_version[0] == '\0') {
+		/* Get the Xen version number and extraversion string */
+		vnum = xc_version(node->handle->xc_handle,
+			XENVER_version, NULL);
+
+		if (vnum < 0)
+			return 0;
+
+		if (xc_version(node->handle->xc_handle, XENVER_extraversion,
+			&version) < 0)
+			return 0;
+		/* Format the version information as a string and store it */
+		snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
+			 ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, version);
+	}
+
+	return 1;
+}
+
+/* Free Xen version information in node - nothing to do */
+static void xenstat_free_xen_version(xenstat_node * node)
+{
+}
+
+/* Free Xen version information in handle - nothing to do */
+static void xenstat_uninit_xen_version(xenstat_handle * handle)
+{
+}
+
+/*
+ * VBD functions
+ */
+
+/* Save VBD information */
+xenstat_vbd *xenstat_save_vbd(xenstat_domain *domain, xenstat_vbd *vbd)
+{
+        xenstat_vbd *vbds = domain->vbds;
+
+        domain->num_vbds++;
+        domain->vbds = realloc(domain->vbds,
+                               domain->num_vbds *
+                               sizeof(xenstat_vbd));
+
+        if (domain->vbds == NULL) {
+                domain->num_vbds = 0;
+                free(vbds);
+        }
+        else {
+                domain->vbds[domain->num_vbds - 1] = *vbd;
+        }
+
+        return domain->vbds;
+}
+
+/* Free VBD information */
+static void xenstat_free_vbds(xenstat_node * node)
+{
+	unsigned int i;
+	for (i = 0; i < node->num_domains; i++)
+		free(node->domains[i].vbds);
+}
+
+/* Get the back driver type  for Virtual Block Device */
+unsigned int xenstat_vbd_type(xenstat_vbd * vbd)
+{
+	return vbd->back_type;
+}
+
+/* Get the major number of VBD device */
+unsigned int xenstat_vbd_dev(xenstat_vbd * vbd)
+{
+	return vbd->dev;
+}
+
+/* Get the number of OO(Out of) requests */
+unsigned long long xenstat_vbd_oo_reqs(xenstat_vbd * vbd)
+{
+	return vbd->oo_reqs;
+}
+
+/* Get the number of READ requests */
+unsigned long long xenstat_vbd_rd_reqs(xenstat_vbd * vbd)
+{
+	return vbd->rd_reqs;
+}
+
+/* Get the number of WRITE requests */
+unsigned long long xenstat_vbd_wr_reqs(xenstat_vbd * vbd)
+{
+	return vbd->wr_reqs;
+}
+
+/* Get the number of READ sectors */
+unsigned long long xenstat_vbd_rd_sects(xenstat_vbd * vbd)
+{
+	return vbd->rd_sects;
+}
+
+/* Get the number of WRITE sectors */
+unsigned long long xenstat_vbd_wr_sects(xenstat_vbd * vbd)
+{
+	return vbd->wr_sects;
+}
+
+/* Returns error while getting stats (1 if error happened, 0 otherwise) */
+bool xenstat_vbd_error(xenstat_vbd * vbd)
+{
+	return vbd->error;
+}
+
+static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id)
+{
+	char path[80];
+
+	snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id);
+
+	return xs_read(handle->xshandle, XBT_NULL, path, NULL);
+}
+
+/* Remove specified entry from list of domains */
+static void xenstat_prune_domain(xenstat_node *node, unsigned int entry)
+{
+	/* nothing to do if array is empty or entry is beyond end */
+	if (node->num_domains == 0 || entry >= node->num_domains)
+		return;
+
+	/* decrement count of domains */
+	node->num_domains--;
+
+	/* shift entries following specified entry up by one */
+	if (entry < node->num_domains) {
+		xenstat_domain *domain = &node->domains[entry];
+		memmove(domain,domain+1,(node->num_domains - entry) * sizeof(xenstat_domain) );
+	}
+
+	/* zero out original last entry from node -- not
+	   strictly necessary but safer! */
+	memset(&node->domains[node->num_domains], 0, sizeof(xenstat_domain)); 
+}
diff --git a/tools/libs/stat/xenstat_freebsd.c b/tools/libs/stat/xenstat_freebsd.c
new file mode 100644
index 0000000000..0c488dffac
--- /dev/null
+++ b/tools/libs/stat/xenstat_freebsd.c
@@ -0,0 +1,47 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josht@us.ibm.com>
+ *          Judy Fischbach <jfisch@us.ibm.com>
+ *          David Hendricks <dhendrix@us.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include "xenstat_priv.h"
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+
+	return 1;
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+}
diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
new file mode 100644
index 0000000000..793263f2b6
--- /dev/null
+++ b/tools/libs/stat/xenstat_linux.c
@@ -0,0 +1,496 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <regex.h>
+
+#include "xenstat_priv.h"
+
+#define SYSFS_VBD_PATH "/sys/bus/xen-backend/devices"
+
+struct priv_data {
+	FILE *procnetdev;
+	DIR *sysfsvbd;
+};
+
+static struct priv_data *
+get_priv_data(xenstat_handle *handle)
+{
+	if (handle->priv != NULL)
+		return handle->priv;
+
+	handle->priv = malloc(sizeof(struct priv_data));
+	if (handle->priv == NULL)
+		return (NULL);
+
+	((struct priv_data *)handle->priv)->procnetdev = NULL;
+	((struct priv_data *)handle->priv)->sysfsvbd = NULL;
+
+	return handle->priv;
+}
+
+/* Expected format of /proc/net/dev */
+static const char PROCNETDEV_HEADER[] =
+    "Inter-|   Receive                                                |"
+    "  Transmit\n"
+    " face |bytes    packets errs drop fifo frame compressed multicast|"
+    "bytes    packets errs drop fifo colls carrier compressed\n";
+
+/* We need to get the name of the bridge interface for use with bonding interfaces */
+/* Use excludeName parameter to avoid adding bridges we don't care about, eg. virbr0 */
+static void getBridge(char *excludeName, char *result, size_t resultLen)
+{
+	struct dirent *de;
+	DIR *d;
+
+	char tmp[512] = { 0 };
+
+	d = opendir("/sys/class/net");
+	while ((de = readdir(d)) != NULL) {
+		if ((strlen(de->d_name) > 0) && (de->d_name[0] != '.')
+			&& (strstr(de->d_name, excludeName) == NULL)) {
+				sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
+
+				if (access(tmp, F_OK) == 0) {
+					strncpy(result, de->d_name, resultLen - 1);
+					result[resultLen - 1] = 0;
+				}
+		}
+	}
+
+	closedir(d);
+}
+
+/* parseNetLine provides regular expression based parsing for lines from /proc/net/dev, all the */
+/* information are parsed but not all are used in our case, ie. for xenstat */
+static int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsigned long long *rxPackets,
+		unsigned long long *rxErrs, unsigned long long *rxDrops, unsigned long long *rxFifo,
+		unsigned long long *rxFrames, unsigned long long *rxComp, unsigned long long *rxMcast,
+		unsigned long long *txBytes, unsigned long long *txPackets, unsigned long long *txErrs,
+		unsigned long long *txDrops, unsigned long long *txFifo, unsigned long long *txColls,
+		unsigned long long *txCarrier, unsigned long long *txComp)
+{
+	/* Temporary/helper variables */
+	int ret;
+	char *tmp;
+	int i = 0, x = 0, col = 0;
+	regex_t r;
+	regmatch_t matches[19];
+	int num = 19;
+
+	/* Regular exception to parse all the information from /proc/net/dev line */
+	char *regex = "([^:]*):([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)"
+			"[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*"
+			"([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)[ ]*([^ ]*)";
+
+	/* Initialize all variables called has passed as non-NULL to zeros */
+	if (iface != NULL)
+		memset(iface, 0, sizeof(*iface));
+	if (rxBytes != NULL)
+		*rxBytes = 0;
+	if (rxPackets != NULL)
+		*rxPackets = 0;
+	if (rxErrs != NULL)
+		*rxErrs = 0;
+	if (rxDrops != NULL)
+		*rxDrops = 0;
+	if (rxFifo != NULL)
+		*rxFifo = 0;
+	if (rxFrames != NULL)
+		*rxFrames = 0;
+	if (rxPackets != NULL)
+		*rxPackets = 0;
+	if (rxComp != NULL)
+		*rxComp = 0;
+	if (txBytes != NULL)
+		*txBytes = 0;
+	if (txPackets != NULL)
+		*txPackets = 0;
+	if (txErrs != NULL)
+		*txErrs = 0;
+	if (txDrops != NULL)
+		*txDrops = 0;
+	if (txFifo != NULL)
+		*txFifo = 0;
+	if (txColls != NULL)
+		*txColls = 0;
+	if (txCarrier != NULL)
+		*txCarrier = 0;
+	if (txComp != NULL)
+		*txComp = 0;
+
+	if ((ret = regcomp(&r, regex, REG_EXTENDED))) {
+		regfree(&r);
+		return ret;
+	}
+
+	tmp = (char *)malloc( sizeof(char) );
+	if (regexec (&r, line, num, matches, REG_EXTENDED) == 0){
+		for (i = 1; i < num; i++) {
+			/* The expression matches are empty sometimes so we need to check it first */
+			if (matches[i].rm_eo - matches[i].rm_so > 0) {
+				/* Col variable contains current id of non-empty match */
+				col++;
+				tmp = (char *)realloc(tmp, (matches[i].rm_eo - 
+							matches[i].rm_so + 1) * sizeof(char));
+				for (x = matches[i].rm_so; x < matches[i].rm_eo; x++)
+					tmp[x - matches[i].rm_so] = line[x];
+
+				/* We populate all the fields from /proc/net/dev line */
+				if (i > 1) {
+					unsigned long long ullTmp = strtoull(tmp, NULL, 10);
+
+					switch (col) {
+						case 2: if (rxBytes != NULL)
+								*rxBytes = ullTmp;
+							break;
+						case 3: if (rxPackets != NULL)
+								*rxPackets = ullTmp;
+							break;
+						case 4: if (rxErrs != NULL)
+								*rxErrs = ullTmp;
+							break;
+						case 5: if (rxDrops != NULL)
+								*rxDrops = ullTmp;
+							break;
+						case 6: if (rxFifo != NULL)
+								*rxFifo = ullTmp;
+							break;
+						case 7: if (rxFrames != NULL)
+								*rxFrames = ullTmp;
+							break;
+						case 8: if (rxComp != NULL)
+								*rxComp = ullTmp;
+							break;
+						case 9: if (rxMcast != NULL)
+								*rxMcast = ullTmp;
+							break;
+						case 10: if (txBytes != NULL)
+								*txBytes = ullTmp;
+							break;
+						case 11: if (txPackets != NULL)
+								*txPackets = ullTmp;
+							break;
+						case 12: if (txErrs != NULL)
+								*txErrs = ullTmp;
+							break;
+						case 13: if (txDrops != NULL)
+								*txDrops = ullTmp;
+							break;
+						case 14: if (txFifo != NULL)
+								*txFifo = ullTmp;
+							break;
+						case 15: if (txColls != NULL)
+								*txColls = ullTmp;
+							break;
+						case 16: if (txCarrier != NULL)
+								*txCarrier = ullTmp;
+							break;
+						case 17: if (txComp != NULL)
+								*txComp = ullTmp;
+							break;
+					}
+				}
+				else
+				/* There were errors when parsing this directly in RE. strpbrk() helps */
+				if (iface != NULL) {
+					char *tmp2 = strpbrk(tmp, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+					if (tmp2 != NULL)
+						strcpy(iface, tmp2);
+				}
+
+				memset(tmp, 0, matches[i].rm_eo - matches[i].rm_so);
+			}
+		}
+	}
+
+	free(tmp);
+	regfree(&r);
+
+	return 0;
+}
+
+/* Find out the domid and network number given an interface name.
+ * Return 0 if the iface cannot be recognized as a Xen VIF. */
+static int get_iface_domid_network(const char *iface, unsigned int *domid_p, unsigned int *netid_p)
+{
+	char nodename_path[48];
+	FILE * nodename_file;
+	int ret;
+
+	snprintf(nodename_path, 48, "/sys/class/net/%s/device/nodename", iface);
+	nodename_file = fopen(nodename_path, "r");
+	if (nodename_file != NULL) {
+		ret = fscanf(nodename_file, "backend/vif/%u/%u", domid_p, netid_p);
+		fclose(nodename_file);
+		if (ret == 2)
+			return 1;
+	}
+
+	if (sscanf(iface, "vif%u.%u", domid_p, netid_p) == 2)
+		return 1;
+
+	return 0;
+}
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+	/* Helper variables for parseNetDevLine() function defined above */
+	int i;
+	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
+	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
+
+	struct priv_data *priv = get_priv_data(node->handle);
+
+	if (priv == NULL) {
+		perror("Allocation error");
+		return 0;
+	}
+
+	/* Open and validate /proc/net/dev if we haven't already */
+	if (priv->procnetdev == NULL) {
+		char header[sizeof(PROCNETDEV_HEADER)];
+		priv->procnetdev = fopen("/proc/net/dev", "r");
+		if (priv->procnetdev == NULL) {
+			perror("Error opening /proc/net/dev");
+			return 0;
+		}
+
+		/* Validate the format of /proc/net/dev */
+		if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
+			  priv->procnetdev) != 1) {
+			perror("Error reading /proc/net/dev header");
+			return 0;
+		}
+		header[sizeof(PROCNETDEV_HEADER) - 1] = '\0';
+		if (strcmp(header, PROCNETDEV_HEADER) != 0) {
+			fprintf(stderr,
+				"Unexpected /proc/net/dev format\n");
+			return 0;
+		}
+	}
+
+	/* Fill in networks */
+	/* FIXME: optimize this */
+	fseek(priv->procnetdev, sizeof(PROCNETDEV_HEADER) - 1,
+	      SEEK_SET);
+
+	/* We get the bridge devices for use with bonding interface to get bonding interface stats */
+	getBridge("vir", devBridge, sizeof(devBridge));
+	snprintf(devNoBridge, sizeof(devNoBridge), "p%s", devBridge);
+
+	while (fgets(line, 512, priv->procnetdev)) {
+		xenstat_domain *domain;
+		xenstat_network net;
+		unsigned int domid;
+
+		parseNetDevLine(line, iface, &rxBytes, &rxPackets, &rxErrs, &rxDrops, NULL, NULL, NULL,
+				NULL, &txBytes, &txPackets, &txErrs, &txDrops, NULL, NULL, NULL, NULL);
+
+		/* If the device parsed is network bridge and both tx & rx packets are zero, we are most */
+		/* likely using bonding so we alter the configuration for dom0 to have bridge stats */
+		if ((strstr(iface, devBridge) != NULL) &&
+		    (strstr(iface, devNoBridge) == NULL) &&
+		    ((domain = xenstat_node_domain(node, 0)) != NULL)) {
+			for (i = 0; i < domain->num_networks; i++) {
+				if ((domain->networks[i].id != 0) ||
+				    (domain->networks[i].tbytes != 0) ||
+				    (domain->networks[i].rbytes != 0))
+					continue;
+				domain->networks[i].tbytes = txBytes;
+				domain->networks[i].tpackets = txPackets;
+				domain->networks[i].terrs = txErrs;
+				domain->networks[i].tdrop = txDrops;
+				domain->networks[i].rbytes = rxBytes;
+				domain->networks[i].rpackets = rxPackets;
+				domain->networks[i].rerrs = rxErrs;
+				domain->networks[i].rdrop = rxDrops;
+			}
+		}
+		else /* Otherwise we need to preserve old behaviour */
+		if (get_iface_domid_network(iface, &domid, &net.id)) {
+
+			net.tbytes = txBytes;
+			net.tpackets = txPackets;
+			net.terrs = txErrs;
+			net.tdrop = txDrops;
+			net.rbytes = rxBytes;
+			net.rpackets = rxPackets;
+			net.rerrs = rxErrs;
+			net.rdrop = rxDrops;
+
+		/* FIXME: this does a search for the domid */
+		  domain = xenstat_node_domain(node, domid);
+		  if (domain == NULL) {
+			fprintf(stderr,
+				"Found interface vif%u.%u but domain %u"
+				" does not exist.\n", domid, net.id,
+				domid);
+			continue;
+		  }
+		  if (domain->networks == NULL) {
+			domain->num_networks = 1;
+			domain->networks = malloc(sizeof(xenstat_network));
+		  } else {
+			struct xenstat_network *tmp;
+			domain->num_networks++;
+			tmp = realloc(domain->networks,
+				      domain->num_networks *
+				      sizeof(xenstat_network));
+			if (tmp == NULL)
+				free(domain->networks);
+			domain->networks = tmp;
+		  }
+		  if (domain->networks == NULL)
+			return 0;
+		  domain->networks[domain->num_networks - 1] = net;
+          }
+        }
+
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->procnetdev != NULL)
+		fclose(priv->procnetdev);
+}
+
+static int read_attributes_vbd(const char *vbd_directory, const char *what, char *ret, int cap)
+{
+	static char file_name[80];
+	int fd, num_read;
+
+	snprintf(file_name, sizeof(file_name), "%s/%s/%s",
+		SYSFS_VBD_PATH, vbd_directory, what);
+	fd = open(file_name, O_RDONLY, 0);
+	if (fd==-1) return -1;
+	num_read = read(fd, ret, cap - 1);
+	close(fd);
+	if (num_read<=0) return -1;
+	ret[num_read] = '\0';
+	return num_read;
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+	struct dirent *dp;
+	struct priv_data *priv = get_priv_data(node->handle);
+
+	if (priv == NULL) {
+		perror("Allocation error");
+		return 0;
+	}
+
+	if (priv->sysfsvbd == NULL) {
+		priv->sysfsvbd = opendir(SYSFS_VBD_PATH);
+		if (priv->sysfsvbd == NULL) {
+			perror("Error opening " SYSFS_VBD_PATH);
+			return 0;
+		}
+	}
+
+	/* Get qdisk statistics */
+	read_attributes_qdisk(node);
+
+	rewinddir(priv->sysfsvbd);
+
+	for(dp = readdir(priv->sysfsvbd); dp != NULL ;
+	    dp = readdir(priv->sysfsvbd)) {
+		xenstat_domain *domain;
+		xenstat_vbd vbd;
+		unsigned int domid;
+		int ret;
+		char buf[256];
+
+		ret = sscanf(dp->d_name, "%3s-%u-%u", buf, &domid, &vbd.dev);
+		if (ret != 3)
+			continue;
+		if (!(strstr(buf, "vbd")) && !(strstr(buf, "tap")))
+			continue;
+
+		if (strcmp(buf,"vbd") == 0)
+			vbd.back_type = 1;
+		else if (strcmp(buf,"tap") == 0)
+			vbd.back_type = 2;
+		else
+			vbd.back_type = 0;
+
+		domain = xenstat_node_domain(node, domid);
+		if (domain == NULL) {
+			fprintf(stderr,
+				"Found interface %s-%u-%u but domain %u"
+				" does not exist.\n",
+				buf, domid, vbd.dev, domid);
+			continue;
+		}
+
+		if (vbd.back_type == 1 || vbd.back_type == 2)
+		{
+
+			vbd.error = 0;
+
+			if ((read_attributes_vbd(dp->d_name, "statistics/oo_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.oo_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/rd_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.rd_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/wr_req", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_reqs)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/rd_sect", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_sects)) != 1) ||
+				(read_attributes_vbd(dp->d_name, "statistics/wr_sect", buf, 256)<=0) ||
+				((ret = sscanf(buf, "%llu", &vbd.wr_sects)) != 1))
+			{
+				vbd.error = 1;
+			}
+		}
+		else
+		{
+			vbd.error = 1;
+		}
+		if ((xenstat_save_vbd(domain, &vbd)) == NULL) {
+			perror("Allocation error");
+			return 0;
+		}
+	}
+
+	return 1;	
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->sysfsvbd != NULL)
+		closedir(priv->sysfsvbd);
+}
diff --git a/tools/libs/stat/xenstat_netbsd.c b/tools/libs/stat/xenstat_netbsd.c
new file mode 100644
index 0000000000..6e9d6aee10
--- /dev/null
+++ b/tools/libs/stat/xenstat_netbsd.c
@@ -0,0 +1,97 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josht@us.ibm.com>
+ *          Judy Fischbach <jfisch@us.ibm.com>
+ *          David Hendricks <dhendrix@us.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "xenstat_priv.h"
+
+#define SYSFS_VBD_PATH "/sys/devices/xen-backend/"
+
+struct priv_data {
+	FILE *procnetdev;
+	DIR *sysfsvbd;
+};
+
+static struct priv_data *
+get_priv_data(xenstat_handle *handle)
+{
+	if (handle->priv != NULL)
+		return handle->priv;
+
+	handle->priv = malloc(sizeof(struct priv_data));
+	if (handle->priv == NULL)
+		return (NULL);
+
+	((struct priv_data *)handle->priv)->procnetdev = NULL;
+	((struct priv_data *)handle->priv)->sysfsvbd = NULL;
+
+	return handle->priv;
+}
+
+/* Expected format of /proc/net/dev */
+static const char PROCNETDEV_HEADER[] =
+    "Inter-|   Receive                                                |"
+    "  Transmit\n"
+    " face |bytes    packets errs drop fifo frame compressed multicast|"
+    "bytes    packets errs drop fifo colls carrier compressed\n";
+
+/* Collect information about networks */
+int xenstat_collect_networks(xenstat_node * node)
+{
+	/* XXX fixme: implement code to get stats from libkvm ! */
+	return 1;
+}
+
+/* Free network information in handle */
+void xenstat_uninit_networks(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->procnetdev != NULL)
+		fclose(priv->procnetdev);
+}
+
+static int read_attributes_vbd(const char *vbd_directory, const char *what, char *ret, int cap)
+{
+	/* XXX implement */
+	return 0;
+}
+
+/* Collect information about VBDs */
+int xenstat_collect_vbds(xenstat_node * node)
+{
+	return 1;	
+}
+
+/* Free VBD information in handle */
+void xenstat_uninit_vbds(xenstat_handle * handle)
+{
+	struct priv_data *priv = get_priv_data(handle);
+	if (priv != NULL && priv->sysfsvbd != NULL)
+		closedir(priv->sysfsvbd);
+}
diff --git a/tools/libs/stat/xenstat_priv.h b/tools/libs/stat/xenstat_priv.h
new file mode 100644
index 0000000000..4eb44a8ebb
--- /dev/null
+++ b/tools/libs/stat/xenstat_priv.h
@@ -0,0 +1,108 @@
+/* libxenstat: statistics-collection library for Xen
+ * Copyright (C) International Business Machines Corp., 2005
+ * Authors: Josh Triplett <josh@kernel.org>
+ *          Judy Fischbach <jfisch@cs.pdx.edu>
+ *          David Hendricks <cro_marmot@comcast.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef XENSTAT_PRIV_H
+#define XENSTAT_PRIV_H
+
+#include <sys/types.h>
+#include <xenstore.h>
+#include "xenstat.h"
+
+#include "xenctrl.h"
+
+#define SHORT_ASC_LEN 5                 /* length of 65535 */
+#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
+
+struct xenstat_handle {
+	xc_interface *xc_handle;
+	struct xs_handle *xshandle; /* xenstore handle */
+	int page_size;
+	void *priv;
+	char xen_version[VERSION_SIZE]; /* xen version running on this node */
+};
+
+struct xenstat_node {
+	xenstat_handle *handle;
+	unsigned int flags;
+	unsigned long long cpu_hz;
+	unsigned int num_cpus;
+	unsigned long long tot_mem;
+	unsigned long long free_mem;
+	unsigned int num_domains;
+	xenstat_domain *domains;	/* Array of length num_domains */
+	long freeable_mb;
+};
+
+struct xenstat_domain {
+	unsigned int id;
+	char *name;
+	unsigned int state;
+	unsigned long long cpu_ns;
+	unsigned int num_vcpus;		/* No. vcpus configured for domain */
+	xenstat_vcpu *vcpus;		/* Array of length num_vcpus */
+	unsigned long long cur_mem;	/* Current memory reservation */
+	unsigned long long max_mem;	/* Total memory allowed */
+	unsigned int ssid;
+	unsigned int num_networks;
+	xenstat_network *networks;	/* Array of length num_networks */
+	unsigned int num_vbds;
+	xenstat_vbd *vbds;
+};
+
+struct xenstat_vcpu {
+	unsigned int online;
+	unsigned long long ns;
+};
+
+struct xenstat_network {
+	unsigned int id;
+	/* Received */
+	unsigned long long rbytes;
+	unsigned long long rpackets;
+	unsigned long long rerrs;
+	unsigned long long rdrop;
+	/* Transmitted */
+	unsigned long long tbytes;
+	unsigned long long tpackets;
+	unsigned long long terrs;
+	unsigned long long tdrop;
+};
+
+struct xenstat_vbd {
+	unsigned int back_type;
+	unsigned int dev;
+	unsigned int error;
+	unsigned long long oo_reqs;
+	unsigned long long rd_reqs;
+	unsigned long long wr_reqs;
+	unsigned long long rd_sects;
+	unsigned long long wr_sects;
+};
+
+extern int xenstat_collect_networks(xenstat_node * node);
+extern void xenstat_uninit_networks(xenstat_handle * handle);
+extern int xenstat_collect_vbds(xenstat_node * node);
+extern void xenstat_uninit_vbds(xenstat_handle * handle);
+extern void read_attributes_qdisk(xenstat_node * node);
+extern xenstat_vbd *xenstat_save_vbd(xenstat_domain * domain, xenstat_vbd * vbd);
+
+#endif /* XENSTAT_PRIV_H */
diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c
new file mode 100644
index 0000000000..19b236e7b6
--- /dev/null
+++ b/tools/libs/stat/xenstat_qmp.c
@@ -0,0 +1,446 @@
+/* libxenstat: statistics-collection library for Xen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <poll.h>
+#include <sys/un.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <xenctrl.h>
+
+#include "xenstat_priv.h"
+#include "_paths.h"
+
+#ifdef HAVE_YAJL_YAJL_VERSION_H
+#  include <yajl/yajl_version.h>
+#endif
+
+/* YAJL version check */
+#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+#  define HAVE_YAJL_V2 1
+#endif
+
+#ifdef HAVE_YAJL_V2
+
+#include <yajl/yajl_tree.h>
+
+static unsigned char *qmp_query(int, char *);
+
+enum query_blockstats {
+    QMP_STATS_RETURN  = 0,
+    QMP_STATS_DEVICE  = 1,
+    QMP_STATS         = 2,
+    QMP_RD_BYTES      = 3,
+    QMP_WR_BYTES      = 4,
+    QMP_RD_OPERATIONS = 5,
+    QMP_WR_OPERATIONS = 6,
+};
+
+enum query_block {
+    QMP_BLOCK_RETURN  = 0,
+    QMP_BLOCK_DEVICE  = 1,
+    QMP_INSERTED      = 2,
+    QMP_FILE          = 3,
+};
+
+
+/* Given the qmp device name, get the image filename associated with it
+   QMP Syntax for querying block information:
+     In: { "execute": "query-block" }
+     Out: {"return": [{
+            "device": 'str, "locked": 'bool', "removable": bool,
+            "inserted": {
+              "iops_rd": 'int',
+              "image": {
+                "virtual-size": 'int', "filename": 'str', "cluster-size": 'int',
+                "format": 'str', "actual-size": 'int', "dirty-flag": 'bool'
+              },
+              "iops_wr": 'int', "ro": 'bool', "backing_file_depth": 'int',
+              "drv": 'str', "iops": 'int', "bps_wr": 'int', "encrypted": 'bool',
+              "bps": 'int', "bps_rd": 'int',
+              "file": 'str', "encryption_key_missing": 'bool'
+            },
+            "type": 'str'
+          }]}
+*/
+static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd)
+{
+	char *tmp, *file = NULL;
+	char *query_block_cmd = "{ \"execute\": \"query-block\" }";
+	static const char *const qblock[] = {
+		[ QMP_BLOCK_RETURN  ] = "return",
+		[ QMP_BLOCK_DEVICE  ] = "device",
+		[ QMP_INSERTED      ] = "inserted",
+		[ QMP_FILE          ] = "file",
+	};
+	const char *ptr[] = {0, 0};
+	unsigned char *qmp_stats;
+	yajl_val info, ret_obj, dev_obj, n;
+	int i;
+
+	if ((qmp_stats = qmp_query(qfd, query_block_cmd)) == NULL)
+		return NULL;
+
+	/* Use libyajl version 2.0.3 or newer for the tree parser feature with bug fixes */
+	info = yajl_tree_parse((char *)qmp_stats, NULL, 0);
+	free(qmp_stats);
+	if (info == NULL)
+		return NULL;
+
+	ptr[0] = qblock[QMP_BLOCK_RETURN]; /* "return" */
+	if ((ret_obj = yajl_tree_get(info, ptr, yajl_t_array)) == NULL)
+		goto done;
+
+	for (i=0; i<YAJL_GET_ARRAY(ret_obj)->len; i++) {
+		n = YAJL_GET_ARRAY(ret_obj)->values[i];
+
+		ptr[0] = qblock[QMP_BLOCK_DEVICE]; /* "device" */
+		if ((dev_obj = yajl_tree_get(n, ptr, yajl_t_any)) != NULL) {
+			tmp = YAJL_GET_STRING(dev_obj);
+			if (!tmp || strcmp(qmp_devname, tmp))
+				continue;
+		}
+		else
+			continue;
+
+		ptr[0] = qblock[QMP_INSERTED]; /* "inserted" */
+		n = yajl_tree_get(n, ptr, yajl_t_any);
+		if (n) {
+			ptr[0] = qblock[QMP_FILE]; /* "file" */
+			n = yajl_tree_get(n, ptr, yajl_t_any);
+			if (n && YAJL_IS_STRING(n)) {
+				tmp = YAJL_GET_STRING(n);
+				file = malloc(strlen(tmp)+1);
+				if (file != NULL)
+					strcpy(file, tmp);
+				goto done;
+			}
+		}
+	}
+done:
+	yajl_tree_free(info);
+	return file;
+}
+
+
+/* Given a QMP device name, lookup the associated xenstore qdisk device id */
+static void lookup_xenstore_devid(xenstat_node * node, unsigned int domid, char *qmp_devname,
+	int qfd, unsigned int *dev, unsigned int *sector_size)
+{
+	char **dev_ids, *tmp, *ptr, *image, path[80];
+	unsigned int num_dev_ids;
+	int i, devid;
+
+	/* Get all the qdisk dev IDs associated with the this VM */
+	snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i", domid);
+	dev_ids = xs_directory(node->handle->xshandle, XBT_NULL, path, &num_dev_ids);
+	if (dev_ids == NULL) {
+		return;
+	}
+
+	/* Get the filename of the image associated with this QMP device */
+	image = qmp_get_block_image(node, qmp_devname, qfd);
+	if (image == NULL) {
+		free(dev_ids);
+		return;
+	}
+
+	/* Look for a matching image in xenstore */
+	for (i=0; i<num_dev_ids; i++) {
+		devid = atoi(dev_ids[i]);
+		/* Get the xenstore name of the image */
+		snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i/%i/params", domid, devid);
+		if ((ptr = xs_read(node->handle->xshandle, XBT_NULL, path, NULL)) == NULL)
+			continue;
+
+		/* Get to actual path in string */
+		if ((tmp = strchr(ptr, '/')) == NULL)
+			tmp = ptr;
+		if (!strcmp(tmp,image)) {
+			*dev = devid;
+			free(ptr);
+
+			/* Get the xenstore sector size of the image while we're here */
+			snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i/%i/sector-size", domid, devid);
+			if ((ptr = xs_read(node->handle->xshandle, XBT_NULL, path, NULL)) != NULL) {
+				*sector_size = atoi((char *)ptr);
+				free(ptr);
+			}
+			break;
+		}
+		free(ptr);
+	}
+
+	free(image);
+	free(dev_ids);
+}
+
+/* Parse the stats buffer which contains I/O data for all the disks belonging to domid */
+static void qmp_parse_stats(xenstat_node *node, unsigned int domid, unsigned char *stats_buf, int qfd)
+{
+	char *qmp_devname;
+	static const char *const qstats[] = {
+		[ QMP_STATS_RETURN  ] = "return",
+		[ QMP_STATS_DEVICE  ] = "device",
+		[ QMP_STATS         ] = "stats",
+		[ QMP_RD_BYTES      ] = "rd_bytes",
+		[ QMP_WR_BYTES      ] = "wr_bytes",
+		[ QMP_RD_OPERATIONS ] = "rd_operations",
+		[ QMP_WR_OPERATIONS ] = "wr_operations",
+	};
+	const char *ptr[] = {0, 0};
+	yajl_val info, ret_obj, stats_obj, n;
+	xenstat_vbd vbd;
+	xenstat_domain *domain;
+	unsigned int sector_size = 512;
+	int i, j;
+
+	/* Use libyajl version 2.0.3 or newer for the tree parser feature */
+	if ((info = yajl_tree_parse((char *)stats_buf, NULL, 0)) == NULL)
+		return;
+
+	ptr[0] = qstats[QMP_STATS_RETURN]; /* "return" */
+	if ((ret_obj = yajl_tree_get(info, ptr, yajl_t_array)) == NULL)
+		goto done;
+
+	/* Array of devices */
+	for (i=0; i<YAJL_GET_ARRAY(ret_obj)->len; i++) {
+		memset(&vbd, 0, sizeof(xenstat_vbd));
+		qmp_devname = NULL;
+		stats_obj = YAJL_GET_ARRAY(ret_obj)->values[i];
+
+		ptr[0] = qstats[QMP_STATS_DEVICE]; /* "device" */
+		if ((n = yajl_tree_get(stats_obj, ptr, yajl_t_any)) != NULL)
+			qmp_devname = YAJL_GET_STRING(n);
+
+		ptr[0] = qstats[QMP_STATS]; /* "stats" */
+		stats_obj = yajl_tree_get(stats_obj, ptr, yajl_t_object);
+		if (stats_obj && YAJL_IS_OBJECT(stats_obj)) {
+			for (j=3; j<7; j++) {
+				ptr[0] = qstats[j];
+				n = yajl_tree_get(stats_obj, ptr, yajl_t_number);
+				if (n && YAJL_IS_NUMBER(n)) {
+					switch(j) {
+					case QMP_RD_BYTES: /* "rd_bytes" */
+						vbd.rd_sects = YAJL_GET_INTEGER(n) / sector_size;
+						break;
+					case QMP_WR_BYTES: /* "wr_bytes" */
+						vbd.wr_sects = YAJL_GET_INTEGER(n) / sector_size;
+						break;
+					case QMP_RD_OPERATIONS: /* "rd_operations" */
+						vbd.rd_reqs = YAJL_GET_INTEGER(n);
+						break;
+					case QMP_WR_OPERATIONS: /* "wr_operations" */
+						vbd.wr_reqs = YAJL_GET_INTEGER(n);
+						break;
+					}
+				}
+			}
+			/* With the QMP device name, lookup the xenstore qdisk device ID and set vdb.dev */
+			if (qmp_devname)
+				lookup_xenstore_devid(node, domid, qmp_devname, qfd, &vbd.dev, &sector_size);
+			if ((domain = xenstat_node_domain(node, domid)) == NULL)
+				continue;
+			if ((xenstat_save_vbd(domain, &vbd)) == NULL)
+				goto done;
+		}
+	}
+done:
+	yajl_tree_free(info);
+}
+
+/* Write a command via the QMP. Returns number of bytes written */
+static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
+{
+	size_t pos = 0;
+	ssize_t res;
+
+	while (cmd_len > pos) {
+		res = write(qfd, cmd + pos, cmd_len - pos);
+		switch (res) {
+		case -1:
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return 0;
+		case 0:
+			errno = EPIPE;
+			return pos;
+		default:
+			pos += (size_t)res;
+		}
+	}
+	return pos;
+}
+
+/* Read the data sent in response to a QMP execute query. Returns 1 for success */
+static int qmp_read(int qfd, unsigned char **qstats)
+{
+	unsigned char buf[1024], *ptr;
+	struct pollfd pfd[1];
+	int n, qsize = 0;
+
+	*qstats = NULL;
+	pfd[0].fd = qfd;
+	pfd[0].events = POLLIN;
+	while ((n = poll(pfd, 1, 10)) > 0) {
+		if (pfd[0].revents & POLLIN) {
+			if ((n = read(qfd, buf, sizeof(buf))) < 0) {
+				free(*qstats);
+				return 0;
+			}
+			ptr = realloc(*qstats, qsize+n+1);
+			if (ptr == NULL) {
+				free(*qstats);
+				return 0;
+			}
+			memcpy(&ptr[qsize], buf, n);
+			qsize += n;
+			ptr[qsize] = 0;
+			*qstats = ptr;
+		}
+	}
+	return 1;
+}
+
+/* With the given cmd, query QMP for requested data. Returns allocated buffer containing data or NULL */
+static unsigned char *qmp_query(int qfd, char *cmd)
+{
+	unsigned char *qstats = NULL;
+	int n;
+
+	n = strlen(cmd);
+	if (qmp_write(qfd, cmd, n) != n)
+		return NULL;
+	if (!qmp_read(qfd, &qstats))
+		return NULL;
+	return qstats;
+}
+
+/* Returns a socket connected to the QMP socket. Returns -1 on failure. */
+static int qmp_connect(char *path)
+{
+	struct sockaddr_un sun;
+	int s;
+
+	if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+		return -1;
+	(void)fcntl(s, F_SETFD, 1);
+
+	memset(&sun, 0, sizeof(struct sockaddr_un));
+	sun.sun_family = AF_UNIX;
+
+	if (strlen(path) >= sizeof(sun.sun_path)) {
+		close(s);
+		return -1;
+	}
+
+	strcpy(sun.sun_path, path);
+	if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+		close(s);
+		return -1;
+	}
+
+	return s;
+}
+
+/* Gather the qdisk statistics by querying QMP
+   Resources: http://wiki.qemu.org/QMP and qmp-commands.hx from the qemu code
+   QMP Syntax for entering command mode. This command must be issued before
+   issuing any other command:
+     In: {"execute": "qmp_capabilities"}
+     Out: {"return": {}}
+   QMP Syntax for querying block statistics:
+     In: { "execute": "query-blockstats" }
+     Out: {"return": [{
+            "device": 'str',
+            "parent": {
+              "stats": {
+                "flush_total_time_ns": 'int', "wr_highest_offset": 'int',
+                "wr_total_time_ns": 'int', "wr_bytes": 'int',
+                "rd_total_time_ns": 'int', "flush_operations": 'int',
+                "wr_operations": 'int', "rd_bytes": 'int', "rd_operations": 'int'
+              }
+            },
+            "stats": {
+              "flush_total_time_ns": 'int', "wr_highest_offset": 'int',
+              "wr_total_time_ns": 'int', "wr_bytes": 'int',
+              "rd_total_time_ns": 'int', "flush_operations": 'int',
+              "wr_operations": 'int', "rd_bytes": 'int', "rd_operations": 'int'
+            }
+          }]}
+*/
+static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain)
+{
+	char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }";
+	char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }";
+	unsigned char *qmp_stats, *val;
+	char path[80];
+	int qfd;
+
+	/* Verify that qdisk disks are used with this VM */
+	snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i", domain);
+	val = xs_read(node->handle->xshandle, XBT_NULL, path, NULL);
+	if (val == NULL)
+		return;
+	free(val);
+
+	/* Connect to this VMs QMP socket */
+	snprintf(path, sizeof(path), XEN_RUN_DIR "/qmp-libxenstat-%i", domain);
+	if ((qfd = qmp_connect(path)) < 0)
+		return;
+
+	/* First enable QMP capabilities so that we can query for data */
+	if ((qmp_stats = qmp_query(qfd, cmd_mode)) != NULL) {
+		free(qmp_stats);
+		/* Query QMP for this VMs blockstats */
+		qmp_stats = qmp_query(qfd, query_blockstats_cmd);
+		if (qmp_stats != NULL) {
+			qmp_parse_stats(node, domain, qmp_stats, qfd);
+			free(qmp_stats);
+		}
+	}
+	close(qfd);
+}
+
+void read_attributes_qdisk(xenstat_node * node)
+{
+	xc_domaininfo_t dominfo[1024];
+	int i, num_doms;
+	domid_t next_domid = 0;
+
+	for (;;) {
+		num_doms = xc_domain_getinfolist(node->handle->xc_handle,
+						 next_domid, 1024, dominfo);
+		if (num_doms <= 0)
+			return;
+
+		for (i = 0; i < num_doms; i++)
+			if (dominfo[i].domain > 0)
+				read_attributes_qdisk_dom(node, dominfo[i].domain);
+
+		next_domid = dominfo[num_doms - 1].domain + 1;
+	}
+}
+
+#else /* !HAVE_YAJL_V2 */
+
+/* Statistics gathering for qdisks requires at least yajl v2 */
+void read_attributes_qdisk(xenstat_node * node)
+{
+}
+
+#endif /* !HAVE_YAJL_V2 */


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:47:50 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:47:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMI-0006Uc-HO; Fri, 18 Sep 2020 19:47:50 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMH-0006TZ-0W
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:49 +0000
X-Inumbo-ID: 42060b00-10db-47c8-bc55-8f407fbba1fb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 42060b00-10db-47c8-bc55-8f407fbba1fb;
 Fri, 18 Sep 2020 19:47:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=+ibs14fCS3IMPosqULCLPV9GnAliTDv9sfuCTMxMNs8=; b=eGrSrFkU5q/G1IKAxeKVL7baO0
 3hkHTDui6jGU98oeCqamnv8uAjnROVC0RbnslrDEUbHTEzjjKvcaJkB1ewKwL3bGa3OnXUygTFZyk
 T48I5GdnLLaM4AUcU1IaE/YVh9wFKdMjWQBktJhXCQ2kZ2G5Vp16Ip/KxpW5HlpoN970=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMF-00079D-Kf
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMF-0004UE-Jy
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxl: fix dependencies of libxl tests
Message-Id: <E1kJMMF-0004UE-Jy@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3df903ec5270673bb3b3834e7b8387e85c2c73ef
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:39 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: fix dependencies of libxl tests
    
    Today building the libxl internal tests depends on libxlutil having
    been built, in spite of the tests not using any functionality of
    libxlutil. Fix this by dropping the dependency.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index b3815390f3..4fbd9ebbca 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -324,14 +324,14 @@ libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $(LIBXLU_OBJS) libxenlight.so
 libxlutil.a: $(LIBXLU_OBJS)
 	$(AR) rcs libxlutil.a $^
 
-test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
+test_%: test_%.o test_common.o libxenlight_test.so
 	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
-testidl: testidl.o libxlutil.so libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
+testidl: testidl.o libxenlight.so
+	$(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:00 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMS-0006WM-JA; Fri, 18 Sep 2020 19:48:00 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMQ-0006WA-Lc
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:58 +0000
X-Inumbo-ID: 58d4e58b-b01a-4846-bd08-9a650f17583e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 58d4e58b-b01a-4846-bd08-9a650f17583e;
 Fri, 18 Sep 2020 19:47:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=8ZswlbzCqfku2bt4+qmxMMPu9sRJZloqLCD3MX4X3oE=; b=pP6ftQBswCZQ3Ly1dlbC0JLK34
 J/CN4SkD1ngr5M0GA++JeGAhm0QkTlR5Z6MQZqkDr2sHA1n+K7dRxlk6CEAoGI4tzz99nZFHiPunI
 2ESBNforHqhcqk8kVu419LGYFZFMKtK2U0ID5rtus3MHaCNss3mXp6eCGw/6rhQenACc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMP-00079N-OH
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMP-0004Uw-NE
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:47:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxl: don't include libxl_osdeps.h from libxlutil
 sources
Message-Id: <E1kJMMP-0004Uw-NE@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:47:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e69a56bcf82fbbb80b159b6ba5c6982932678063
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:40 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: don't include libxl_osdeps.h from libxlutil sources
    
    There is no need for the sources of libxlutil to include libxl_osdeps.h
    as the only dependency is the leading
    
    #define _GNU_SOURCE
    
    in libxl_osdeps.h. So replace including libxl_osdeps.h by the needed
    define.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/libxlu_cfg.c    |  3 +--
 tools/libxl/libxlu_cfg_i.h  |  1 -
 tools/libxl/libxlu_disk.c   |  1 -
 tools/libxl/libxlu_disk_l.c | 14 +++++++-------
 tools/libxl/libxlu_disk_l.h |  8 ++++----
 tools/libxl/libxlu_disk_l.l |  2 +-
 tools/libxl/libxlu_pci.c    |  3 ++-
 tools/libxl/libxlu_vif.c    |  3 ++-
 8 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/tools/libxl/libxlu_cfg.c b/tools/libxl/libxlu_cfg.c
index f9e8aa2f3a..874f5abfb9 100644
--- a/tools/libxl/libxlu_cfg.c
+++ b/tools/libxl/libxlu_cfg.c
@@ -15,8 +15,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
 
 #include <limits.h>
 
diff --git a/tools/libxl/libxlu_cfg_i.h b/tools/libxl/libxlu_cfg_i.h
index 87b19df311..4217f5b28d 100644
--- a/tools/libxl/libxlu_cfg_i.h
+++ b/tools/libxl/libxlu_cfg_i.h
@@ -18,7 +18,6 @@
 #ifndef LIBXLU_CFG_I_H
 #define LIBXLU_CFG_I_H
 
-#include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxlu_internal.h"
 #include "libxlu_cfg_y.h"
 
diff --git a/tools/libxl/libxlu_disk.c b/tools/libxl/libxlu_disk.c
index 18fe386dbe..1de16a6a06 100644
--- a/tools/libxl/libxlu_disk.c
+++ b/tools/libxl/libxlu_disk.c
@@ -1,4 +1,3 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
 #include "libxlu_internal.h"
 #include "libxlu_disk_l.h"
 #include "libxlu_disk_i.h"
diff --git a/tools/libxl/libxlu_disk_l.c b/tools/libxl/libxlu_disk_l.c
index 05f7ac74a0..32d4b74b58 100644
--- a/tools/libxl/libxlu_disk_l.c
+++ b/tools/libxl/libxlu_disk_l.c
@@ -1,7 +1,7 @@
-#line 2 "libxlu_disk_l.c"
-#include "libxl_osdeps.h" /* must come before any other headers */
+#line 1 "libxlu_disk_l.c"
+#define _GNU_SOURCE
 
-#line 5 "libxlu_disk_l.c"
+#line 4 "libxlu_disk_l.c"
 
 #define  YY_INT_ALIGNED short int
 
@@ -1199,9 +1199,9 @@ static int vdev_and_devtype(DiskParseContext *dpc, char *str) {
 #undef DPC /* needs to be defined differently the actual lexer */
 #define DPC ((DiskParseContext*)yyextra)
 
-#line 1203 "libxlu_disk_l.c"
+#line 1202 "libxlu_disk_l.c"
 
-#line 1205 "libxlu_disk_l.c"
+#line 1204 "libxlu_disk_l.c"
 
 #define INITIAL 0
 #define LEXERR 1
@@ -1483,7 +1483,7 @@ YY_DECL
 #line 180 "libxlu_disk_l.l"
  /*----- the scanner rules which do the parsing -----*/
 
-#line 1487 "libxlu_disk_l.c"
+#line 1486 "libxlu_disk_l.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -1836,7 +1836,7 @@ YY_RULE_SETUP
 #line 291 "libxlu_disk_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1840 "libxlu_disk_l.c"
+#line 1839 "libxlu_disk_l.c"
 			case YY_STATE_EOF(INITIAL):
 			case YY_STATE_EOF(LEXERR):
 				yyterminate();
diff --git a/tools/libxl/libxlu_disk_l.h b/tools/libxl/libxlu_disk_l.h
index 54f4662d7a..6abeecf279 100644
--- a/tools/libxl/libxlu_disk_l.h
+++ b/tools/libxl/libxlu_disk_l.h
@@ -2,10 +2,10 @@
 #define xlu__disk_yyHEADER_H 1
 #define xlu__disk_yyIN_HEADER 1
 
-#line 6 "libxlu_disk_l.h"
-#include "libxl_osdeps.h" /* must come before any other headers */
+#line 5 "libxlu_disk_l.h"
+#define _GNU_SOURCE
 
-#line 9 "libxlu_disk_l.h"
+#line 8 "libxlu_disk_l.h"
 
 #define  YY_INT_ALIGNED short int
 
@@ -696,6 +696,6 @@ extern int yylex (yyscan_t yyscanner);
 
 #line 291 "libxlu_disk_l.l"
 
-#line 700 "libxlu_disk_l.h"
+#line 699 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l
index 7a46f4a30c..3bd639aab0 100644
--- a/tools/libxl/libxlu_disk_l.l
+++ b/tools/libxl/libxlu_disk_l.l
@@ -28,7 +28,7 @@
  */
 
 %top{
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
 }
 
 %{
diff --git a/tools/libxl/libxlu_pci.c b/tools/libxl/libxlu_pci.c
index e2709c5f89..12fc0b3a7f 100644
--- a/tools/libxl/libxlu_pci.c
+++ b/tools/libxl/libxlu_pci.c
@@ -1,4 +1,5 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
+
 #include "libxlu_internal.h"
 #include "libxlu_disk_l.h"
 #include "libxlu_disk_i.h"
diff --git a/tools/libxl/libxlu_vif.c b/tools/libxl/libxlu_vif.c
index 0665e624dc..ccf0cbdf57 100644
--- a/tools/libxl/libxlu_vif.c
+++ b/tools/libxl/libxlu_vif.c
@@ -1,4 +1,5 @@
-#include "libxl_osdeps.h" /* must come before any other headers */
+#define _GNU_SOURCE
+
 #include "libxlu_internal.h"
 
 static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$";
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:09 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMb-0006XL-Kq; Fri, 18 Sep 2020 19:48:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMa-0006XG-IR
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:08 +0000
X-Inumbo-ID: 0ef8e592-1eb2-4958-8968-4155135d867f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0ef8e592-1eb2-4958-8968-4155135d867f;
 Fri, 18 Sep 2020 19:48:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=+5wwhrKgA6i4BsmoaEt0KRmw+Tw6nUT3oLkZ+a/2zH4=; b=eFfGzZTo8z7+1OnzI6Pj7+SDJ3
 g2ATJ6PUnZDbbXRQhL9uequYX2onVOcSLPlh8CdKCh98006MOexci0KWri2j4Rz1nkyg4QQKMoKD0
 JPVm85H07V86QD/VFjCL4dCnr7ExYRZoyFs4aUN8oVDDG+ansTc3gy+HDJpXzddYh0nI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMZ-0007AS-Rb
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMZ-0004Vh-Qo
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxl: add missing items to clean target
Message-Id: <E1kJMMZ-0004Vh-Qo@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0ca1af64f1053ffbf0c7784f4ed13ec75aacb874
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:41 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: add missing items to clean target
    
    Some generated files are not removed by "make clean". Add them.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 4fbd9ebbca..51c4c22f22 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -370,8 +370,10 @@ clean:
 	$(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS_RM)
 	$(RM) -f _*.c *.pyc _paths.*.tmp _*.api-for-check
 	$(RM) -f testidl.c.new testidl.c *.api-ok
+	$(RM) -f $(TEST_PROGS)
 	$(RM) -f xenlight.pc
 	$(RM) -f xlutil.pc
+	$(RM) -rf __pycache__
 	$(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) clean
 
 distclean: clean
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:26 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMs-0006YY-Mr; Fri, 18 Sep 2020 19:48:26 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMr-0006YM-36
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:25 +0000
X-Inumbo-ID: 3d836a2d-4e30-48f4-8274-657f25fa510f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3d836a2d-4e30-48f4-8274-657f25fa510f;
 Fri, 18 Sep 2020 19:48:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=zlC1a69ThOfajl9APdb2up1qUJfjXW/adfkXgvbGb4I=; b=1YZcC2IZdLtGN6WU/h+zZlente
 MZ3FA+Uc3bU/qqeQplkyYavagvXaKMM/NdOCOH+bUyyUtMAUHwPDqIfsTPYssIhQlrDxZZnylvCI+
 D+GRA2A8zsoe+QLERfq4xUdhZFf2+dcL/n74/jwo4U3xe2j6Twwz2dOOs4FUzCeeTnRc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMj-0007Ah-Uf
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMj-0004WA-U1
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libxl: move xl parsing checks to tools/xl
Message-Id: <E1kJMMj-0004WA-U1@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 82651ae662f25ff845b7f0bb87fbf7550a509cd1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:42 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/libxl: move xl parsing checks to tools/xl
    
    check-xl-* scripts and data are not libxl- but xl-specific. Move them
    from tools/libxl/ to tools/xl/.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libxl/check-xl-disk-parse                 | 181 ---------------
 tools/libxl/check-xl-vcpupin-parse              | 294 ------------------------
 tools/libxl/check-xl-vcpupin-parse.data-example |  53 -----
 tools/libxl/check-xl-vif-parse                  | 213 -----------------
 tools/xl/check-xl-disk-parse                    | 181 +++++++++++++++
 tools/xl/check-xl-vcpupin-parse                 | 294 ++++++++++++++++++++++++
 tools/xl/check-xl-vcpupin-parse.data-example    |  53 +++++
 tools/xl/check-xl-vif-parse                     | 213 +++++++++++++++++
 8 files changed, 741 insertions(+), 741 deletions(-)

diff --git a/tools/libxl/check-xl-disk-parse b/tools/libxl/check-xl-disk-parse
deleted file mode 100755
index 643f4f4ecb..0000000000
--- a/tools/libxl/check-xl-disk-parse
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.:../libxc:../xenstore
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-disk-parse
-
-expected () {
-    cat >$fprefix.expected
-}
-
-failures=0
-
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N block-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    diff -u $fprefix.expected $fprefix.actual
-    diff_rc=$?
-    set -e
-    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-e=1
-
-
-#---------- test data ----------
-#
-# culled from docs/misc/xl-disk-configuration.txt
-
-expected </dev/null
-one $e foo
-
-expected <<END
-disk: {
-    "pdev_path": "/dev/vg/guest-volume",
-    "vdev": "hda",
-    "format": "raw",
-    "readwrite": 1
-}
-
-END
-one 0 /dev/vg/guest-volume,,hda
-one 0 /dev/vg/guest-volume,raw,hda,rw
-one 0 "format=raw, vdev=hda, access=rw, target=/dev/vg/guest-volume"
-one 0  format=raw  vdev=hda  access=rw  target=/dev/vg/guest-volume
-one 0 raw:/dev/vg/guest-volume,hda,w
-
-expected <<END
-disk: {
-    "pdev_path": "/root/image.iso",
-    "vdev": "hdc",
-    "format": "raw",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-END
-one 0 /root/image.iso,,hdc,cdrom
-one 0 /root/image.iso,,hdc,,cdrom
-one 0 /root/image.iso,raw,hdc,devtype=cdrom
-one 0 "format=raw, vdev=hdc, access=ro, devtype=cdrom, target=/root/image.iso"
-one 0  format=raw  vdev=hdc  access=ro  devtype=cdrom  target=/root/image.iso
-one 0 raw:/root/image.iso,hdc:cdrom,ro
-
-expected <<EOF
-disk: {
-    "pdev_path": "/dev/vg/guest-volume",
-    "vdev": "xvdb",
-    "backend": "phy",
-    "format": "raw",
-    "readwrite": 1
-}
-
-EOF
-one 0 backendtype=phy,vdev=xvdb,access=w,target=/dev/vg/guest-volume
-
-expected <<EOF
-disk: {
-    "pdev_path": "",
-    "vdev": "hdc",
-    "format": "empty",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-EOF
-one 0 devtype=cdrom,,,hdc
-one 0 ,,hdc:cdrom,r
-one 0 ,hdc:cdrom,r
-one 0 vdev=hdc,access=r,devtype=cdrom,target=
-one 0 ,empty,hdc:cdrom,r
-
-expected <<EOF
-disk: {
-    "vdev": "hdc",
-    "format": "empty",
-    "removable": 1,
-    "is_cdrom": 1
-}
-
-EOF
-one 0 vdev=hdc,access=r,devtype=cdrom,format=empty
-one 0 vdev=hdc,access=r,devtype=cdrom
-
-expected <<EOF
-disk: {
-    "pdev_path": "iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost",
-    "vdev": "xvda",
-    "format": "raw",
-    "script": "block-iscsi",
-    "readwrite": 1
-}
-
-EOF
-
-# http://backdrift.org/xen-block-iscsi-script-with-multipath-support
-one 0 iscsi:iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost,xvda,w
-one 0 vdev=xvda,access=w,script=block-iscsi,target=iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost
-
-expected <<EOF
-disk: {
-    "pdev_path": "app01",
-    "vdev": "hda",
-    "format": "raw",
-    "script": "block-drbd",
-    "readwrite": 1
-}
-
-EOF
-
-# http://lists.linbit.com/pipermail/drbd-user/2008-September/010221.html
-# http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html
-one 0 drbd:app01,hda,w
-
-expected <<END
-disk: {
-    "pdev_path": "/some/disk/image.raw",
-    "vdev": "hda",
-    "format": "raw",
-    "readwrite": 1,
-    "discard_enable": "True"
-}
-
-END
-one 0  discard vdev=hda target=/some/disk/image.raw
-one 0  discard vdev=hda target=/some/disk/image.raw
-
-expected <<END
-disk: {
-    "pdev_path": "/some/disk/image.iso",
-    "vdev": "hda",
-    "format": "raw",
-    "removable": 1,
-    "is_cdrom": 1,
-    "discard_enable": "False"
-}
-
-END
-one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
-
-complete
diff --git a/tools/libxl/check-xl-vcpupin-parse b/tools/libxl/check-xl-vcpupin-parse
deleted file mode 100755
index 21f8421ad0..0000000000
--- a/tools/libxl/check-xl-vcpupin-parse
+++ /dev/null
@@ -1,294 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.:../libxc:../xenstore:
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-vcpupin-parse
-outfile=check-xl-vcpupin-parse.data
-
-usage () {
-cat <<END
-usage: $0 [options]
-
-Tests various vcpu-pinning strings. If run without arguments acts
-as follows:
- - generates some test data and saves them in $outfile;
- - tests all the generated configurations (reading them back from
-   $outfile).
-
-An example of a test vector file is provided in ${outfile}-example.
-
-Options:
- -h         prints this message
- -r seed    uses seed for initializing the rundom number generator
-            (default: the script PID)
- -s string  tries using string as a vcpu pinning configuration and
-            reports whether that succeeds or not
- -o ofile   save the test data in ofile (default: $outfile)
- -i ifile   read test data from ifile
-END
-}
-
-expected () {
-    cat >$fprefix.expected
-}
-
-# by default, re-seed with our PID
-seed=$$
-failures=0
-
-# Execute one test and check the result against the provided
-# rc value and output
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N vcpu-pin 0 all "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    if [ $actual_rc != $expected_rc ]; then
-        diff -u $fprefix.expected $fprefix.actual
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-    set -e
-}
-
-# Write an entry in the test vector file. Format is as follows:
-#  test-string*expected-rc*expected-output
-write () {
-    printf "$1*$2*$3\n" >> $outfile
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-# Test a specific pinning string
-string () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N vcpu-pin 0 all "$@" &> /dev/null
-    actual_rc=$?
-    set -e
-
-    if [ $actual_rc != $expected_rc ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc)"
-    else
-        echo >&2 "test case \`$*' succeeded"
-    fi
-
-    exit 0
-}
-
-# Read a test vector file (provided as $1) line by line and
-# test all the entries it contains
-run ()
-{
-    while read line
-    do
-        if [ ${line:0:1} != '#' ]; then
-            test_string="`echo $line | cut -f1 -d'*'`"
-            exp_rc="`echo $line | cut -f2 -d'*'`"
-            exp_output="`echo $line | cut -f3 -d'*'`"
-
-            expected <<END
-$exp_output
-END
-            one $exp_rc "$test_string"
-        fi
-    done < $1
-
-    complete
-
-    exit 0
-}
-
-while getopts "hr:s:o:i:" option
-do
-    case $option in
-    h)
-        usage
-        exit 0
-        ;;
-    r)
-        seed=$OPTARG
-        ;;
-    s)
-        string 0 "$OPTARG"
-        ;;
-    o)
-        outfile=$OPTARG
-        ;;
-    i)
-        run $OPTARG
-        ;;
-    esac
-done
-
-#---------- test data ----------
-#
-nr_cpus=`xl info | grep nr_cpus | cut -f2 -d':'`
-nr_nodes=`xl info | grep nr_nodes | cut -f2 -d':'`
-nr_cpus_per_node=`xl info -n | sed '/cpu:/,/numa_info/!d' | head -n -1 | \
-    awk '{print $4}' | uniq -c | tail -1 | awk '{print $1}'`
-cat >$outfile <<END
-# WARNING: some of these tests are topology based tests.
-# Expect failures if the topology is not detected correctly
-# detected topology: $nr_cpus CPUs, $nr_nodes nodes, $nr_cpus_per_node CPUs per node.
-#
-# seed used for random number generation: seed=${seed}.
-#
-# Format is as follows:
-#  test-string*expected-return-code*expected-output
-#
-END
-
-# Re-seed the random number generator
-RANDOM=$seed
-
-echo "# Testing a wrong configuration" >> $outfile
-write foo 255 ""
-
-echo "# Testing the 'all' syntax" >> $outfile
-write "all" 0 "cpumap: all"
-write "nodes:all" 0 "cpumap: all"
-write "all,nodes:all" 0 "cpumap: all"
-write "all,^nodes:0,all" 0 "cpumap: all"
-
-echo "# Testing the empty cpumap case" >> $outfile
-write "^0" 0 "cpumap: none"
-
-echo "# A few attempts of pinning to just one random cpu" >> $outfile
-if [ $nr_cpus -gt 1 ]; then
-    for i in `seq 0 3`; do
-        cpu=$(($RANDOM % nr_cpus))
-        write "$cpu" 0 "cpumap: $cpu"
-    done
-fi
-
-echo "# A few attempts of pinning to all but one random cpu" >> $outfile
-if [ $nr_cpus -gt 2 ]; then
-    for i in `seq 0 3`; do
-        cpu=$(($RANDOM % nr_cpus))
-        if [ $cpu -eq 0 ]; then
-            expected_range="1-$((nr_cpus - 1))"
-        elif [ $cpu -eq 1 ]; then
-            expected_range="0,2-$((nr_cpus - 1))"
-        elif [ $cpu -eq $((nr_cpus - 2)) ]; then
-            expected_range="0-$((cpu - 1)),$((nr_cpus - 1))"
-        elif [ $cpu -eq $((nr_cpus - 1)) ]; then
-            expected_range="0-$((nr_cpus - 2))"
-        else
-            expected_range="0-$((cpu - 1)),$((cpu + 1))-$((nr_cpus - 1))"
-        fi
-        write "all,^$cpu" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a random range of cpus" >> $outfile
-if [ $nr_cpus -gt 2 ]; then
-    for i in `seq 0 3`; do
-        cpua=$(($RANDOM % nr_cpus))
-        range=$((nr_cpus - cpua))
-        cpub=$(($RANDOM % range))
-        cpubb=$((cpua + cpub))
-        if [ $cpua -eq $cpubb ]; then
-            expected_range="$cpua"
-        else
-            expected_range="$cpua-$cpubb"
-        fi
-        write "$expected_range" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to just one random node" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        write "nodes:$node" 0 "cpumap: $((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1)-1))"
-    done
-fi
-
-echo "# A few attempts of pinning to all but one random node" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        if [ $node -eq 0 ]; then
-            expected_range="$nr_cpus_per_node-$((nr_cpus - 1))"
-        elif [ $node -eq $((nr_nodes - 1)) ]; then
-            expected_range="0-$((nr_cpus - nr_cpus_per_node - 1))"
-        else
-            expected_range="0-$((nr_cpus_per_node*node-1)),$((nr_cpus_per_node*(node+1)))-$nr_cpus"
-        fi
-        write "all,^nodes:$node" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a random range of nodes" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        nodea=$(($RANDOM % nr_nodes))
-        range=$((nr_nodes - nodea))
-        nodeb=$(($RANDOM % range))
-        nodebb=$((nodea + nodeb))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        if [ $nodea -eq 0 ] && [ $nodebb -eq $((nr_nodes - 1)) ]; then
-            expected_range="all"
-        else
-            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodebb+1) - 1))"
-        fi
-        write "nodes:$nodea-$nodebb" 0 "cpumap: $expected_range"
-    done
-fi
-
-echo "# A few attempts of pinning to a node but excluding one random cpu" >> $outfile
-if [ $nr_nodes -gt 1 ]; then
-    for i in `seq 0 3`; do
-        node=$(($RANDOM % nr_nodes))
-        # this assumes that the first $nr_cpus_per_node (from cpu
-        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
-        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
-        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
-        # 1), etc. Expect failures if that is not the case.
-        cpu=$(($RANDOM % nr_cpus_per_node + nr_cpus_per_node*node))
-        if [ $cpu -eq $((nr_cpus_per_node*node)) ]; then
-            expected_range="$((nr_cpus_per_node*node + 1))-$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*node + 1)) ]; then
-            expected_range="$((nr_cpus_per_node*node)),$((nr_cpus_per_node*node + 2))-$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 2)) ]; then
-            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 3)),$((nr_cpus_per_node*(node+1) - 1))"
-        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 1)) ]; then
-            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 2))"
-        else
-            expected_range="$((nr_cpus_per_node*node))-$((cpu - 1)),$((cpu + 1))-$((nr_cpus_per_node*(node+1) - 1))"
-        fi
-        write "nodes:$node,^$cpu" 0 "cpumap: $expected_range"
-    done
-fi
-
-run $outfile
diff --git a/tools/libxl/check-xl-vcpupin-parse.data-example b/tools/libxl/check-xl-vcpupin-parse.data-example
deleted file mode 100644
index 4bbd5de76c..0000000000
--- a/tools/libxl/check-xl-vcpupin-parse.data-example
+++ /dev/null
@@ -1,53 +0,0 @@
-# WARNING: some of these tests are topology based tests.
-# Expect failures if the topology is not detected correctly
-# detected topology:  16 CPUs,  2 nodes, 8 CPUs per node.
-#
-# seed used for random number generation: seed=13328.
-#
-# Format is as follows:
-#  test-string*expected-return-code*expected-output
-#
-# Testing a wrong configuration
-foo*255*
-# Testing the 'all' syntax
-all*0*cpumap: all
-nodes:all*0*cpumap: all
-all,nodes:all*0*cpumap: all
-all,^nodes:0,all*0*cpumap: all
-# Testing the empty cpumap case
-^0*0*cpumap: none
-# A few attempts of pinning to just one random cpu
-0*0*cpumap: 0
-9*0*cpumap: 9
-6*0*cpumap: 6
-0*0*cpumap: 0
-# A few attempts of pinning to all but one random cpu
-all,^12*0*cpumap: 0-11,13-15
-all,^6*0*cpumap: 0-5,7-15
-all,^3*0*cpumap: 0-2,4-15
-all,^7*0*cpumap: 0-6,8-15
-# A few attempts of pinning to a random range of cpus
-13-15*0*cpumap: 13-15
-7*0*cpumap: 7
-3-5*0*cpumap: 3-5
-8-11*0*cpumap: 8-11
-# A few attempts of pinning to just one random node
-nodes:1*0*cpumap: 8-15
-nodes:0*0*cpumap: 0-7
-nodes:0*0*cpumap: 0-7
-nodes:0*0*cpumap: 0-7
-# A few attempts of pinning to all but one random node
-all,^nodes:0*0*cpumap: 8-15
-all,^nodes:1*0*cpumap: 0-7
-all,^nodes:1*0*cpumap: 0-7
-all,^nodes:0*0*cpumap: 8-15
-# A few attempts of pinning to a random range of nodes
-nodes:1-1*0*cpumap: 8-15
-nodes:1-1*0*cpumap: 8-15
-nodes:0-1*0*cpumap: all
-nodes:0-0*0*cpumap: 0-7
-# A few attempts of pinning to a node but excluding one random cpu
-nodes:1,^8*0*cpumap: 9-15
-nodes:0,^6*0*cpumap: 0-5,7
-nodes:1,^9*0*cpumap: 8,10-15
-nodes:0,^5*0*cpumap: 0-4,6-7
diff --git a/tools/libxl/check-xl-vif-parse b/tools/libxl/check-xl-vif-parse
deleted file mode 100755
index 02c6dbaeb6..0000000000
--- a/tools/libxl/check-xl-vif-parse
+++ /dev/null
@@ -1,213 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ -x ./xl ] ; then
-    export LD_LIBRARY_PATH=.
-    XL=./xl
-else
-    XL=xl
-fi
-
-fprefix=tmp.check-xl-vif-parse
-
-expected () {
-    cat >$fprefix.expected
-}
-
-failures=0
-
-one () {
-    expected_rc=$1; shift
-    printf "test case %s...\n" "$*"
-    set +e
-    ${XL} -N network-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
-    actual_rc=$?
-    diff -u $fprefix.expected $fprefix.actual
-    diff_rc=$?
-    set -e
-    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
-        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
-        failures=$(( $failures + 1 ))
-    fi
-}
-
-complete () {
-    if [ "$failures" = 0 ]; then
-        echo all ok.; exit 0
-    else
-        echo "$failures tests failed."; exit 1
-    fi
-}
-
-e=255
-
-
-#---------- test data ----------
-
-# test invalid vif config
-expected </dev/null
-one 1 foo
-
-# test invalid rate units
-expected </dev/null
-one $e rate=foo
-one $e rate=foo
-one $e rate=10MB
-one $e rate=10MB/m
-one $e rate=10ZB
-one $e rate=10ZB/s
-one $e rate=10ZB/m
-
-# test b/s and B/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100000,
-    "rate_interval_usecs": 50000
-}
-
-END
-
-one 0 rate=16000000b/s
-one 0 rate=16000000b/s@50ms
-one 0 rate=2000000B/s
-one 0 rate=2000000B/s@50ms
-
-# test Kb/s and KB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=16Kb/s
-one 0 rate=16Kb/s@50ms
-one 0 rate=2KB/s
-one 0 rate=2KB/s@50ms
-
-# test Mb/s and MB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 100000,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=16Mb/s
-one 0 rate=16Mb/s@50ms
-one 0 rate=2MB/s
-one 0 rate=2MB/s@50ms
-
-# test Gb/s and GB/s rate units
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 50000000,
-    "rate_interval_usecs": 50000
-}
-
-END
-one 0 rate=8Gb/s
-one 0 rate=8Gb/s@50ms
-one 0 rate=1GB/s
-one 0 rate=1GB/s@50ms
-
-# test rate overflow
-expected </dev/null
-one $e rate=4294967296b/s
-one $e rate=4294967296Kb/s
-one $e rate=4294967296Mb/s
-one $e rate=4294967296Gb/s
-
-# test rate underflow
-expected </dev/null
-one $e rate=0B/s
-
-# test invalid replenishment interval
-expected </dev/null
-one $e rate=10Mb/s@foo
-one $e rate=10Mb/s@10h
-one $e rate=10MB/s@foo
-one $e rate=10MB/s@10h
-
-# test replenishment interval in seconds
-expected <<END
-vif: {
-    "backend_domid": 0,
-    "devid": 0,
-    "mtu": 0,
-    "model": null,
-    "mac": "00:00:00:00:00:00",
-    "ip": null,
-    "bridge": null,
-    "ifname": null,
-    "script": null,
-    "nictype": null,
-    "rate_bytes_per_interval": 10000000,
-    "rate_interval_usecs": 1000000
-}
-
-END
-one 0 rate=80Mb/s@1s
-one 0 rate=10MB/s@1s
-
-# test replenishment interval overflow
-expected </dev/null
-one $e rate=1B/s@4294967296us
-one $e rate=1B/s@4294968ms
-one $e rate=1B/s@4295s
-
-# test replenishment interval underflow
-expected </dev/null
-one $e rate=1B/s@0us
-
-# test rate limiting resulting in overflow
-expected </dev/null
-one $e rate=4294967295GB/s@5us
-one $e rate=4296MB/s@4294s
-
-# test include of single '@'
-expected </dev/null
-one $e rate=@
-
-complete
diff --git a/tools/xl/check-xl-disk-parse b/tools/xl/check-xl-disk-parse
new file mode 100755
index 0000000000..643f4f4ecb
--- /dev/null
+++ b/tools/xl/check-xl-disk-parse
@@ -0,0 +1,181 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.:../libxc:../xenstore
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-disk-parse
+
+expected () {
+    cat >$fprefix.expected
+}
+
+failures=0
+
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N block-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    diff -u $fprefix.expected $fprefix.actual
+    diff_rc=$?
+    set -e
+    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+e=1
+
+
+#---------- test data ----------
+#
+# culled from docs/misc/xl-disk-configuration.txt
+
+expected </dev/null
+one $e foo
+
+expected <<END
+disk: {
+    "pdev_path": "/dev/vg/guest-volume",
+    "vdev": "hda",
+    "format": "raw",
+    "readwrite": 1
+}
+
+END
+one 0 /dev/vg/guest-volume,,hda
+one 0 /dev/vg/guest-volume,raw,hda,rw
+one 0 "format=raw, vdev=hda, access=rw, target=/dev/vg/guest-volume"
+one 0  format=raw  vdev=hda  access=rw  target=/dev/vg/guest-volume
+one 0 raw:/dev/vg/guest-volume,hda,w
+
+expected <<END
+disk: {
+    "pdev_path": "/root/image.iso",
+    "vdev": "hdc",
+    "format": "raw",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+END
+one 0 /root/image.iso,,hdc,cdrom
+one 0 /root/image.iso,,hdc,,cdrom
+one 0 /root/image.iso,raw,hdc,devtype=cdrom
+one 0 "format=raw, vdev=hdc, access=ro, devtype=cdrom, target=/root/image.iso"
+one 0  format=raw  vdev=hdc  access=ro  devtype=cdrom  target=/root/image.iso
+one 0 raw:/root/image.iso,hdc:cdrom,ro
+
+expected <<EOF
+disk: {
+    "pdev_path": "/dev/vg/guest-volume",
+    "vdev": "xvdb",
+    "backend": "phy",
+    "format": "raw",
+    "readwrite": 1
+}
+
+EOF
+one 0 backendtype=phy,vdev=xvdb,access=w,target=/dev/vg/guest-volume
+
+expected <<EOF
+disk: {
+    "pdev_path": "",
+    "vdev": "hdc",
+    "format": "empty",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+EOF
+one 0 devtype=cdrom,,,hdc
+one 0 ,,hdc:cdrom,r
+one 0 ,hdc:cdrom,r
+one 0 vdev=hdc,access=r,devtype=cdrom,target=
+one 0 ,empty,hdc:cdrom,r
+
+expected <<EOF
+disk: {
+    "vdev": "hdc",
+    "format": "empty",
+    "removable": 1,
+    "is_cdrom": 1
+}
+
+EOF
+one 0 vdev=hdc,access=r,devtype=cdrom,format=empty
+one 0 vdev=hdc,access=r,devtype=cdrom
+
+expected <<EOF
+disk: {
+    "pdev_path": "iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost",
+    "vdev": "xvda",
+    "format": "raw",
+    "script": "block-iscsi",
+    "readwrite": 1
+}
+
+EOF
+
+# http://backdrift.org/xen-block-iscsi-script-with-multipath-support
+one 0 iscsi:iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost,xvda,w
+one 0 vdev=xvda,access=w,script=block-iscsi,target=iqn.2001-05.com.equallogic:0-8a0906-23fe93404-c82797962054a96d-examplehost
+
+expected <<EOF
+disk: {
+    "pdev_path": "app01",
+    "vdev": "hda",
+    "format": "raw",
+    "script": "block-drbd",
+    "readwrite": 1
+}
+
+EOF
+
+# http://lists.linbit.com/pipermail/drbd-user/2008-September/010221.html
+# http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html
+one 0 drbd:app01,hda,w
+
+expected <<END
+disk: {
+    "pdev_path": "/some/disk/image.raw",
+    "vdev": "hda",
+    "format": "raw",
+    "readwrite": 1,
+    "discard_enable": "True"
+}
+
+END
+one 0  discard vdev=hda target=/some/disk/image.raw
+one 0  discard vdev=hda target=/some/disk/image.raw
+
+expected <<END
+disk: {
+    "pdev_path": "/some/disk/image.iso",
+    "vdev": "hda",
+    "format": "raw",
+    "removable": 1,
+    "is_cdrom": 1,
+    "discard_enable": "False"
+}
+
+END
+one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
+
+complete
diff --git a/tools/xl/check-xl-vcpupin-parse b/tools/xl/check-xl-vcpupin-parse
new file mode 100755
index 0000000000..21f8421ad0
--- /dev/null
+++ b/tools/xl/check-xl-vcpupin-parse
@@ -0,0 +1,294 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.:../libxc:../xenstore:
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-vcpupin-parse
+outfile=check-xl-vcpupin-parse.data
+
+usage () {
+cat <<END
+usage: $0 [options]
+
+Tests various vcpu-pinning strings. If run without arguments acts
+as follows:
+ - generates some test data and saves them in $outfile;
+ - tests all the generated configurations (reading them back from
+   $outfile).
+
+An example of a test vector file is provided in ${outfile}-example.
+
+Options:
+ -h         prints this message
+ -r seed    uses seed for initializing the rundom number generator
+            (default: the script PID)
+ -s string  tries using string as a vcpu pinning configuration and
+            reports whether that succeeds or not
+ -o ofile   save the test data in ofile (default: $outfile)
+ -i ifile   read test data from ifile
+END
+}
+
+expected () {
+    cat >$fprefix.expected
+}
+
+# by default, re-seed with our PID
+seed=$$
+failures=0
+
+# Execute one test and check the result against the provided
+# rc value and output
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N vcpu-pin 0 all "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    if [ $actual_rc != $expected_rc ]; then
+        diff -u $fprefix.expected $fprefix.actual
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+    set -e
+}
+
+# Write an entry in the test vector file. Format is as follows:
+#  test-string*expected-rc*expected-output
+write () {
+    printf "$1*$2*$3\n" >> $outfile
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+# Test a specific pinning string
+string () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N vcpu-pin 0 all "$@" &> /dev/null
+    actual_rc=$?
+    set -e
+
+    if [ $actual_rc != $expected_rc ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc)"
+    else
+        echo >&2 "test case \`$*' succeeded"
+    fi
+
+    exit 0
+}
+
+# Read a test vector file (provided as $1) line by line and
+# test all the entries it contains
+run ()
+{
+    while read line
+    do
+        if [ ${line:0:1} != '#' ]; then
+            test_string="`echo $line | cut -f1 -d'*'`"
+            exp_rc="`echo $line | cut -f2 -d'*'`"
+            exp_output="`echo $line | cut -f3 -d'*'`"
+
+            expected <<END
+$exp_output
+END
+            one $exp_rc "$test_string"
+        fi
+    done < $1
+
+    complete
+
+    exit 0
+}
+
+while getopts "hr:s:o:i:" option
+do
+    case $option in
+    h)
+        usage
+        exit 0
+        ;;
+    r)
+        seed=$OPTARG
+        ;;
+    s)
+        string 0 "$OPTARG"
+        ;;
+    o)
+        outfile=$OPTARG
+        ;;
+    i)
+        run $OPTARG
+        ;;
+    esac
+done
+
+#---------- test data ----------
+#
+nr_cpus=`xl info | grep nr_cpus | cut -f2 -d':'`
+nr_nodes=`xl info | grep nr_nodes | cut -f2 -d':'`
+nr_cpus_per_node=`xl info -n | sed '/cpu:/,/numa_info/!d' | head -n -1 | \
+    awk '{print $4}' | uniq -c | tail -1 | awk '{print $1}'`
+cat >$outfile <<END
+# WARNING: some of these tests are topology based tests.
+# Expect failures if the topology is not detected correctly
+# detected topology: $nr_cpus CPUs, $nr_nodes nodes, $nr_cpus_per_node CPUs per node.
+#
+# seed used for random number generation: seed=${seed}.
+#
+# Format is as follows:
+#  test-string*expected-return-code*expected-output
+#
+END
+
+# Re-seed the random number generator
+RANDOM=$seed
+
+echo "# Testing a wrong configuration" >> $outfile
+write foo 255 ""
+
+echo "# Testing the 'all' syntax" >> $outfile
+write "all" 0 "cpumap: all"
+write "nodes:all" 0 "cpumap: all"
+write "all,nodes:all" 0 "cpumap: all"
+write "all,^nodes:0,all" 0 "cpumap: all"
+
+echo "# Testing the empty cpumap case" >> $outfile
+write "^0" 0 "cpumap: none"
+
+echo "# A few attempts of pinning to just one random cpu" >> $outfile
+if [ $nr_cpus -gt 1 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        write "$cpu" 0 "cpumap: $cpu"
+    done
+fi
+
+echo "# A few attempts of pinning to all but one random cpu" >> $outfile
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        if [ $cpu -eq 0 ]; then
+            expected_range="1-$((nr_cpus - 1))"
+        elif [ $cpu -eq 1 ]; then
+            expected_range="0,2-$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 2)) ]; then
+            expected_range="0-$((cpu - 1)),$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 1)) ]; then
+            expected_range="0-$((nr_cpus - 2))"
+        else
+            expected_range="0-$((cpu - 1)),$((cpu + 1))-$((nr_cpus - 1))"
+        fi
+        write "all,^$cpu" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a random range of cpus" >> $outfile
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpua=$(($RANDOM % nr_cpus))
+        range=$((nr_cpus - cpua))
+        cpub=$(($RANDOM % range))
+        cpubb=$((cpua + cpub))
+        if [ $cpua -eq $cpubb ]; then
+            expected_range="$cpua"
+        else
+            expected_range="$cpua-$cpubb"
+        fi
+        write "$expected_range" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to just one random node" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        write "nodes:$node" 0 "cpumap: $((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1)-1))"
+    done
+fi
+
+echo "# A few attempts of pinning to all but one random node" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $node -eq 0 ]; then
+            expected_range="$nr_cpus_per_node-$((nr_cpus - 1))"
+        elif [ $node -eq $((nr_nodes - 1)) ]; then
+            expected_range="0-$((nr_cpus - nr_cpus_per_node - 1))"
+        else
+            expected_range="0-$((nr_cpus_per_node*node-1)),$((nr_cpus_per_node*(node+1)))-$nr_cpus"
+        fi
+        write "all,^nodes:$node" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a random range of nodes" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        nodea=$(($RANDOM % nr_nodes))
+        range=$((nr_nodes - nodea))
+        nodeb=$(($RANDOM % range))
+        nodebb=$((nodea + nodeb))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $nodea -eq 0 ] && [ $nodebb -eq $((nr_nodes - 1)) ]; then
+            expected_range="all"
+        else
+            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodebb+1) - 1))"
+        fi
+        write "nodes:$nodea-$nodebb" 0 "cpumap: $expected_range"
+    done
+fi
+
+echo "# A few attempts of pinning to a node but excluding one random cpu" >> $outfile
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        cpu=$(($RANDOM % nr_cpus_per_node + nr_cpus_per_node*node))
+        if [ $cpu -eq $((nr_cpus_per_node*node)) ]; then
+            expected_range="$((nr_cpus_per_node*node + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*node + 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node)),$((nr_cpus_per_node*node + 2))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 2)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 3)),$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 2))"
+        else
+            expected_range="$((nr_cpus_per_node*node))-$((cpu - 1)),$((cpu + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        fi
+        write "nodes:$node,^$cpu" 0 "cpumap: $expected_range"
+    done
+fi
+
+run $outfile
diff --git a/tools/xl/check-xl-vcpupin-parse.data-example b/tools/xl/check-xl-vcpupin-parse.data-example
new file mode 100644
index 0000000000..4bbd5de76c
--- /dev/null
+++ b/tools/xl/check-xl-vcpupin-parse.data-example
@@ -0,0 +1,53 @@
+# WARNING: some of these tests are topology based tests.
+# Expect failures if the topology is not detected correctly
+# detected topology:  16 CPUs,  2 nodes, 8 CPUs per node.
+#
+# seed used for random number generation: seed=13328.
+#
+# Format is as follows:
+#  test-string*expected-return-code*expected-output
+#
+# Testing a wrong configuration
+foo*255*
+# Testing the 'all' syntax
+all*0*cpumap: all
+nodes:all*0*cpumap: all
+all,nodes:all*0*cpumap: all
+all,^nodes:0,all*0*cpumap: all
+# Testing the empty cpumap case
+^0*0*cpumap: none
+# A few attempts of pinning to just one random cpu
+0*0*cpumap: 0
+9*0*cpumap: 9
+6*0*cpumap: 6
+0*0*cpumap: 0
+# A few attempts of pinning to all but one random cpu
+all,^12*0*cpumap: 0-11,13-15
+all,^6*0*cpumap: 0-5,7-15
+all,^3*0*cpumap: 0-2,4-15
+all,^7*0*cpumap: 0-6,8-15
+# A few attempts of pinning to a random range of cpus
+13-15*0*cpumap: 13-15
+7*0*cpumap: 7
+3-5*0*cpumap: 3-5
+8-11*0*cpumap: 8-11
+# A few attempts of pinning to just one random node
+nodes:1*0*cpumap: 8-15
+nodes:0*0*cpumap: 0-7
+nodes:0*0*cpumap: 0-7
+nodes:0*0*cpumap: 0-7
+# A few attempts of pinning to all but one random node
+all,^nodes:0*0*cpumap: 8-15
+all,^nodes:1*0*cpumap: 0-7
+all,^nodes:1*0*cpumap: 0-7
+all,^nodes:0*0*cpumap: 8-15
+# A few attempts of pinning to a random range of nodes
+nodes:1-1*0*cpumap: 8-15
+nodes:1-1*0*cpumap: 8-15
+nodes:0-1*0*cpumap: all
+nodes:0-0*0*cpumap: 0-7
+# A few attempts of pinning to a node but excluding one random cpu
+nodes:1,^8*0*cpumap: 9-15
+nodes:0,^6*0*cpumap: 0-5,7
+nodes:1,^9*0*cpumap: 8,10-15
+nodes:0,^5*0*cpumap: 0-4,6-7
diff --git a/tools/xl/check-xl-vif-parse b/tools/xl/check-xl-vif-parse
new file mode 100755
index 0000000000..02c6dbaeb6
--- /dev/null
+++ b/tools/xl/check-xl-vif-parse
@@ -0,0 +1,213 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-vif-parse
+
+expected () {
+    cat >$fprefix.expected
+}
+
+failures=0
+
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N network-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    diff -u $fprefix.expected $fprefix.actual
+    diff_rc=$?
+    set -e
+    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+e=255
+
+
+#---------- test data ----------
+
+# test invalid vif config
+expected </dev/null
+one 1 foo
+
+# test invalid rate units
+expected </dev/null
+one $e rate=foo
+one $e rate=foo
+one $e rate=10MB
+one $e rate=10MB/m
+one $e rate=10ZB
+one $e rate=10ZB/s
+one $e rate=10ZB/m
+
+# test b/s and B/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100000,
+    "rate_interval_usecs": 50000
+}
+
+END
+
+one 0 rate=16000000b/s
+one 0 rate=16000000b/s@50ms
+one 0 rate=2000000B/s
+one 0 rate=2000000B/s@50ms
+
+# test Kb/s and KB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=16Kb/s
+one 0 rate=16Kb/s@50ms
+one 0 rate=2KB/s
+one 0 rate=2KB/s@50ms
+
+# test Mb/s and MB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 100000,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=16Mb/s
+one 0 rate=16Mb/s@50ms
+one 0 rate=2MB/s
+one 0 rate=2MB/s@50ms
+
+# test Gb/s and GB/s rate units
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 50000000,
+    "rate_interval_usecs": 50000
+}
+
+END
+one 0 rate=8Gb/s
+one 0 rate=8Gb/s@50ms
+one 0 rate=1GB/s
+one 0 rate=1GB/s@50ms
+
+# test rate overflow
+expected </dev/null
+one $e rate=4294967296b/s
+one $e rate=4294967296Kb/s
+one $e rate=4294967296Mb/s
+one $e rate=4294967296Gb/s
+
+# test rate underflow
+expected </dev/null
+one $e rate=0B/s
+
+# test invalid replenishment interval
+expected </dev/null
+one $e rate=10Mb/s@foo
+one $e rate=10Mb/s@10h
+one $e rate=10MB/s@foo
+one $e rate=10MB/s@10h
+
+# test replenishment interval in seconds
+expected <<END
+vif: {
+    "backend_domid": 0,
+    "devid": 0,
+    "mtu": 0,
+    "model": null,
+    "mac": "00:00:00:00:00:00",
+    "ip": null,
+    "bridge": null,
+    "ifname": null,
+    "script": null,
+    "nictype": null,
+    "rate_bytes_per_interval": 10000000,
+    "rate_interval_usecs": 1000000
+}
+
+END
+one 0 rate=80Mb/s@1s
+one 0 rate=10MB/s@1s
+
+# test replenishment interval overflow
+expected </dev/null
+one $e rate=1B/s@4294967296us
+one $e rate=1B/s@4294968ms
+one $e rate=1B/s@4295s
+
+# test replenishment interval underflow
+expected </dev/null
+one $e rate=1B/s@0us
+
+# test rate limiting resulting in overflow
+expected </dev/null
+one $e rate=4294967295GB/s@5us
+one $e rate=4296MB/s@4294s
+
+# test include of single '@'
+expected </dev/null
+one $e rate=@
+
+complete
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMMw-0006ZM-QQ; Fri, 18 Sep 2020 19:48:30 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMMu-0006Z8-Q0
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:28 +0000
X-Inumbo-ID: 8516ad01-97cd-499d-9196-0e3fed43b386
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8516ad01-97cd-499d-9196-0e3fed43b386;
 Fri, 18 Sep 2020 19:48:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UrwORBxb9rUrH/FY5YOpZr3nNGJnAEtgIyBGbcR9z80=; b=qnoWAuEOhzUBE4K15M3DQjGOvN
 zF7s8GWE8PslhsTg785acoar/jxEUpKu9wfR60tLeCiFp6v2XkqwJ6vTl5NiR6c/dn+xcFJ1BGU5l
 r5CMWqaHGoda6Tp501iJCyj7UxSEvwfx6OmNyAobErFNxZ2X2TjM50SQ1GIGeaO5BqJI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMu-0007Ak-1c
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:28 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMMu-0004XK-0v
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:28 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/xl: don't assume libxl and libxlutil are in one
 directory
Message-Id: <E1kJMMu-0004XK-0v@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b72aa3968dd5e4f75dfd816db7fae067b07e3711
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Aug 28 17:07:43 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 10:57:25 2020 +0000

    tools/xl: don't assume libxl and libxlutil are in one directory
    
    Add the correct flags for both, libxenlight and libxlutil, when
    building xl.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xl/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index af4912e67a..407dd7554c 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -13,6 +13,7 @@ CFLAGS += $(PTHREAD_CFLAGS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
 CFLAGS_XL += $(CFLAGS_libxenlight)
+CFLAGS_XL += $(CFLAGS_libxlutil)
 CFLAGS_XL += -Wshadow
 
 XL_OBJS-$(CONFIG_X86) = xl_psr.o
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMN5-0006aX-Rr; Fri, 18 Sep 2020 19:48:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMN4-0006aP-Uc
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:38 +0000
X-Inumbo-ID: a13b2202-cae4-4435-a897-a8d5d2ddc3d6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a13b2202-cae4-4435-a897-a8d5d2ddc3d6;
 Fri, 18 Sep 2020 19:48:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=WArW4tzIYuXHnvMuLU9qna51i1el1b8HoIdRdAF8bMc=; b=u89wbiS/64aHYplpyPdBiW/zEW
 jvyNF0XXM36hLdyGD/qXL7QsYGNcRLCrw7M2JLTIPgD7EBvDuuYEw/xFLfgE7GVn/KccyG4T9s+Vf
 Ai6mB9gTzgSj8F+8c4MTsRMcOYjIeTF37/5PPSxQ60zEPcYpSITEsZ3UpoqAvTcLk5FM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMN4-0007Ay-7Y
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:38 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMN4-0004Y1-40
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:38 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] libxenguest: use bitmap_alloc
Message-Id: <E1kJMN4-0004Y1-40@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3cccdae45242dab27198b8e150be0c85acd5d3c9
Author:     Olaf Hering <olaf@aepfle.de>
AuthorDate: Wed Sep 9 11:06:37 2020 +0000
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 11:07:31 2020 +0000

    libxenguest: use bitmap_alloc
    
    Use existing helper to allocate a bitmap.
    
    Signed-off-by: Olaf Hering <olaf@aepfle.de>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
    [ wei: rebase to staging ]
    Signed-off-by: Wei Liu <wl@xen.org>
---
 tools/libs/guest/xg_sr_save.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c
index d74c72cba6..2ba7c3200c 100644
--- a/tools/libs/guest/xg_sr_save.c
+++ b/tools/libs/guest/xg_sr_save.c
@@ -809,7 +809,7 @@ static int setup(struct xc_sr_context *ctx)
         xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)));
     ctx->save.batch_pfns = malloc(MAX_BATCH_SIZE *
                                   sizeof(*ctx->save.batch_pfns));
-    ctx->save.deferred_pages = calloc(1, bitmap_size(ctx->save.p2m_size));
+    ctx->save.deferred_pages = bitmap_alloc(ctx->save.p2m_size);
 
     if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pages )
     {
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMNF-0006bd-TR; Fri, 18 Sep 2020 19:48:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMNF-0006bU-1S
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:49 +0000
X-Inumbo-ID: 87a86b04-19f9-4fac-9f7f-ff88c8c65753
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 87a86b04-19f9-4fac-9f7f-ff88c8c65753;
 Fri, 18 Sep 2020 19:48:48 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=kJLcWVrs5g4pOr1B2CeJFa6aXkO8IpA55xH6zVS4u8w=; b=JcCnNrAucKJ+c+7ChdPPnHjEqU
 0LCULrKLQsZOqZglWJEvaS9aj32HCB+12tH/Ab7F8GXV2jGVmFvFqlkQKQqL1xQhncd4mYveha/Ds
 H/zihpHLYytAxpixUwVMnGJ3+GyWzJfdHz78PR1ATJBeoseYnlY35qv3RcvfwQ5DF58U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNE-0007B7-BI
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:48 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNE-0004Yg-9n
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:48 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug: Fix hostname setting in vif-nat
Message-Id: <E1kJMNE-0004Yg-9n@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:48 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5499e0fc8082024bf7e2d0facd5c976e82105070
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Thu Aug 20 11:58:20 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:30 2020 +0000

    tools/hotplug: Fix hostname setting in vif-nat
    
    Setting the hostname is failing because the "$XENBUS_PATH/domain"
    doesn't exist anymore. To fix this we set it to dom$domid
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-nat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
index a76d9c784b..26144350b3 100644
--- a/tools/hotplug/Linux/vif-nat
+++ b/tools/hotplug/Linux/vif-nat
@@ -85,7 +85,7 @@ router_ip=$(routing_ip "$ip")
 # Split the given IP/bits pair.
 vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
 
-hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----')
+hostname=dom$domid
 if [ "$vifid" != "1" ]
 then
   hostname="$hostname-$vifid"
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:48:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:48:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMNP-0006cw-Uv; Fri, 18 Sep 2020 19:48:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMNP-0006co-Do
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:59 +0000
X-Inumbo-ID: cd6b3a87-7d1b-46ed-98b7-9bc677d8d993
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cd6b3a87-7d1b-46ed-98b7-9bc677d8d993;
 Fri, 18 Sep 2020 19:48:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=XYoDu0Her4EZKs2xqBbgFZMCico9hpcJT2RutepvlzY=; b=hzSFM7Y6yZ7e4VQukyWCJ+RWBW
 NtOl0wBPDbpk7VGvyRv6q278lbY8HJLnL6gM+SVxLqJ/mOXGpA1Kov35nDYcmvZWDIqoinlBSV5IC
 qTDmJuJQLOjumu0dtBPBGuA0bVxYzoj6HwKb8CjU7wfIFnsu8CTE50nbeMfPu3nok3+E=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNO-0007BG-Fx
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:58 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNO-0004ZC-De
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:48:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug: Extend dhcpd conf,
 init and arg files search
Message-Id: <E1kJMNO-0004ZC-De@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:48:58 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 17f80e7fc1e3bb49fc91794ef1b6e5a2f1b540cb
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Thu Aug 20 12:01:11 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:34 2020 +0000

    tools/hotplug: Extend dhcpd conf, init and arg files search
    
    Newer versions of the ISC dhcp server expect the dhcpd.conf file
    to be located at /etc/dhcp directory.
    
    Also, some distributions and Yocto based ones have these installation
    paths by default: /etc/init.d/{isc-dhcp-server,dhcp-server} and
    /etc/default/dhcp-server.
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/xen-network-common.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh
index 82ee70aab4..42fa704e8d 100644
--- a/tools/hotplug/Linux/xen-network-common.sh
+++ b/tools/hotplug/Linux/xen-network-common.sh
@@ -64,18 +64,18 @@ first_file()
 
 find_dhcpd_conf_file()
 {
-  first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
+  first_file -f /etc/dhcp/dhcpd.conf /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
 }
 
 
 find_dhcpd_init_file()
 {
-  first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
+  first_file -x /etc/init.d/{isc-dhcp-server,dhcp-server,dhcp3-server,dhcp,dhcpd}
 }
 
 find_dhcpd_arg_file()
 {
-  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp3-server
+  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp /etc/default/dhcp-server /etc/default/dhcp3-server
 }
 
 # configure interfaces which act as pure bridge ports:
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:49:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:49:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMNa-0006dm-0A; Fri, 18 Sep 2020 19:49:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMNZ-0006dg-Ea
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:09 +0000
X-Inumbo-ID: 7335dfd6-f6a1-4412-b447-45ab58496e2f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7335dfd6-f6a1-4412-b447-45ab58496e2f;
 Fri, 18 Sep 2020 19:49:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UVElpfgQdwYruZ8cC9C3HIeowguPc8HGmgAGPu8NTKQ=; b=dMlXQMevjjJKbqOqr0+29v2vgh
 5rG8tSiXRAQdwI5qO3pBKxB4u5sdxrwTzmcEHTwGDK6d1opVqmatm9msu0wxLHYDLk2P7lRcW7pZr
 WJ/JImbyHR1wuDoVzFuXJo+gC8wjmdxLvO5y6VNHus4FveIDBqrAESjePr61IzsozgTk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNY-0007C4-Jx
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNY-0004a2-II
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/hotplug: Fix dhcpd symlink removal in vif-nat
Message-Id: <E1kJMNY-0004a2-II@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:49:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6d2f1ebccdef655d64fbc3abc83db76c3de08cb1
Author:     Diego Sueiro <diego.sueiro@arm.com>
AuthorDate: Wed Sep 9 13:35:56 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 9 12:41:59 2020 +0000

    tools/hotplug: Fix dhcpd symlink removal in vif-nat
    
    Copy temp files used to add/remove dhcpd configurations to avoid
    replacing potential symlinks.
    
    If dhcp.conf is a symlink pointing to dhcp.conf.real, using 'mv'
    creates a new file dhcp.conf where cp will actually modify
    dhcp.conf.real instead of replacing the symlink with a real
    file.
    
    Using 'cp' prevents some mistakes where the user will actually
    continue to modify dhcp.conf.real where it would not be the one
    used anymore.
    
    Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/hotplug/Linux/vif-nat | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/tools/hotplug/Linux/vif-nat b/tools/hotplug/Linux/vif-nat
index 26144350b3..fd34afbb96 100644
--- a/tools/hotplug/Linux/vif-nat
+++ b/tools/hotplug/Linux/vif-nat
@@ -95,12 +95,11 @@ dhcparg_remove_entry()
 {
   local tmpfile=$(mktemp)
   sed -e "s/${dev} //" "$dhcpd_arg_file" >"$tmpfile"
-  if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
+  if ! diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
   then
-    rm "$tmpfile"
-  else
-    mv "$tmpfile" "$dhcpd_arg_file"
+    cp "$tmpfile" "$dhcpd_arg_file"
   fi
+  rm "$tmpfile"
 }
 
 dhcparg_add_entry()
@@ -109,11 +108,11 @@ dhcparg_add_entry()
   local tmpfile=$(mktemp)
   # handle Red Hat, SUSE, and Debian styles, with or without quotes
   sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"${dev} "'"/' \
-     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+     "$dhcpd_arg_file" >"$tmpfile" && cp "$tmpfile" "$dhcpd_arg_file"
   rm -f "$tmpfile"
 }
 
@@ -121,12 +120,11 @@ dhcp_remove_entry()
 {
   local tmpfile=$(mktemp)
   grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
-  if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
+  if ! diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
   then
-    rm "$tmpfile"
-  else
-    mv "$tmpfile" "$dhcpd_conf_file"
+    cp "$tmpfile" "$dhcpd_conf_file"
   fi
+  rm "$tmpfile"
   dhcparg_remove_entry
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:49:22 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:49:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMNl-0006eo-1j; Fri, 18 Sep 2020 19:49:21 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMNj-0006eb-RD
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:19 +0000
X-Inumbo-ID: 9cc94dcb-bff6-41d6-a7a2-cbfb438c1c90
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9cc94dcb-bff6-41d6-a7a2-cbfb438c1c90;
 Fri, 18 Sep 2020 19:49:18 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wCknBgq4GdkO/HDUVmoyMIkcoPVBiYWH+/QQaUKCKIA=; b=RcfJBjMFga4iTYOodNI1Kn15fs
 UdKgyA1UUtz0EJURM57vqLrVPmC29IgwQgJSMASyiO3OqRTgR4E4mD2mATqrddNHI3oUKXgl1bm2J
 7HtuYMOAdlilr309EOwcIqyuz7v6Lcw3CCB7nZfrFaa8zPQUWOMKMyiKejsvB1KFMVRk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNi-0007CE-ON
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:18 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNi-0004av-Mc
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Move stack_switch()/seg_segment_base() into
 PV-only files
Message-Id: <E1kJMNi-0004av-Mc@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:49:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a4c4b288069cf0c7285ec3d3efb1df0b46051d46
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Thu Sep 3 19:09:45 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Wed Sep 9 16:53:28 2020 +0100

    x86/pv: Move stack_switch()/seg_segment_base() into PV-only files
    
    So they are excluded from !CONFIG_PV builds.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/pv/misc-hypercalls.c | 101 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c          | 101 --------------------------------------
 2 files changed, 101 insertions(+), 101 deletions(-)

diff --git a/xen/arch/x86/pv/misc-hypercalls.c b/xen/arch/x86/pv/misc-hypercalls.c
index 136fa10c96..b353972e3d 100644
--- a/xen/arch/x86/pv/misc-hypercalls.c
+++ b/xen/arch/x86/pv/misc-hypercalls.c
@@ -171,6 +171,107 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
     return 0;
 }
 
+long do_stack_switch(unsigned long ss, unsigned long esp)
+{
+    fixup_guest_stack_selector(current->domain, ss);
+    current->arch.pv.kernel_ss = ss;
+    current->arch.pv.kernel_sp = esp;
+
+    return 0;
+}
+
+long do_set_segment_base(unsigned int which, unsigned long base)
+{
+    struct vcpu *v = current;
+    long ret = 0;
+
+    if ( is_pv_32bit_vcpu(v) )
+        return -ENOSYS; /* x86/64 only. */
+
+    switch ( which )
+    {
+    case SEGBASE_FS:
+        if ( is_canonical_address(base) )
+            wrfsbase(base);
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_USER:
+        if ( is_canonical_address(base) )
+        {
+            wrgsshadow(base);
+            v->arch.pv.gs_base_user = base;
+        }
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_KERNEL:
+        if ( is_canonical_address(base) )
+            wrgsbase(base);
+        else
+            ret = -EINVAL;
+        break;
+
+    case SEGBASE_GS_USER_SEL:
+    {
+        unsigned int sel = (uint16_t)base;
+
+        /*
+         * We wish to update the user %gs from the GDT/LDT.  Currently, the
+         * guest kernel's GS_BASE is in context.
+         */
+        asm volatile ( "swapgs" );
+
+        if ( sel > 3 )
+            /* Fix up RPL for non-NUL selectors. */
+            sel |= 3;
+        else if ( boot_cpu_data.x86_vendor &
+                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
+            /* Work around NUL segment behaviour on AMD hardware. */
+            asm volatile ( "mov %[sel], %%gs"
+                           :: [sel] "r" (FLAT_USER_DS32) );
+
+        /*
+         * Load the chosen selector, with fault handling.
+         *
+         * Errors ought to fail the hypercall, but that was never built in
+         * originally, and Linux will BUG() if this call fails.
+         *
+         * NUL the selector in the case of an error.  This too needs to deal
+         * with the AMD NUL segment behaviour, but it is already a slowpath in
+         * #GP context so perform the flat load unconditionally to avoid
+         * complicated logic.
+         *
+         * Anyone wanting to check for errors from this hypercall should
+         * re-read %gs and compare against the input.
+         */
+        asm volatile ( "1: mov %[sel], %%gs\n\t"
+                       ".section .fixup, \"ax\", @progbits\n\t"
+                       "2: mov %k[flat], %%gs\n\t"
+                       "   xor %[sel], %[sel]\n\t"
+                       "   jmp 1b\n\t"
+                       ".previous\n\t"
+                       _ASM_EXTABLE(1b, 2b)
+                       : [sel] "+r" (sel)
+                       : [flat] "r" (FLAT_USER_DS32) );
+
+        /* Update the cache of the inactive base, as read from the GDT/LDT. */
+        v->arch.pv.gs_base_user = rdgsbase();
+
+        asm volatile ( safe_swapgs );
+        break;
+    }
+
+    default:
+        ret = -EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index b69cf2dc4f..98581dfe5f 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1010,107 +1010,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
-long do_stack_switch(unsigned long ss, unsigned long esp)
-{
-    fixup_guest_stack_selector(current->domain, ss);
-    current->arch.pv.kernel_ss = ss;
-    current->arch.pv.kernel_sp = esp;
-    return 0;
-}
-
-long do_set_segment_base(unsigned int which, unsigned long base)
-{
-    struct vcpu *v = current;
-    long ret = 0;
-
-    if ( is_pv_32bit_vcpu(v) )
-        return -ENOSYS; /* x86/64 only. */
-
-    switch ( which )
-    {
-    case SEGBASE_FS:
-        if ( is_canonical_address(base) )
-            wrfsbase(base);
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_USER:
-        if ( is_canonical_address(base) )
-        {
-            wrgsshadow(base);
-            v->arch.pv.gs_base_user = base;
-        }
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_KERNEL:
-        if ( is_canonical_address(base) )
-            wrgsbase(base);
-        else
-            ret = -EINVAL;
-        break;
-
-    case SEGBASE_GS_USER_SEL:
-    {
-        unsigned int sel = (uint16_t)base;
-
-        /*
-         * We wish to update the user %gs from the GDT/LDT.  Currently, the
-         * guest kernel's GS_BASE is in context.
-         */
-        asm volatile ( "swapgs" );
-
-        if ( sel > 3 )
-            /* Fix up RPL for non-NUL selectors. */
-            sel |= 3;
-        else if ( boot_cpu_data.x86_vendor &
-                  (X86_VENDOR_AMD | X86_VENDOR_HYGON) )
-            /* Work around NUL segment behaviour on AMD hardware. */
-            asm volatile ( "mov %[sel], %%gs"
-                           :: [sel] "r" (FLAT_USER_DS32) );
-
-        /*
-         * Load the chosen selector, with fault handling.
-         *
-         * Errors ought to fail the hypercall, but that was never built in
-         * originally, and Linux will BUG() if this call fails.
-         *
-         * NUL the selector in the case of an error.  This too needs to deal
-         * with the AMD NUL segment behaviour, but it is already a slowpath in
-         * #GP context so perform the flat load unconditionally to avoid
-         * complicated logic.
-         *
-         * Anyone wanting to check for errors from this hypercall should
-         * re-read %gs and compare against the input.
-         */
-        asm volatile ( "1: mov %[sel], %%gs\n\t"
-                       ".section .fixup, \"ax\", @progbits\n\t"
-                       "2: mov %k[flat], %%gs\n\t"
-                       "   xor %[sel], %[sel]\n\t"
-                       "   jmp 1b\n\t"
-                       ".previous\n\t"
-                       _ASM_EXTABLE(1b, 2b)
-                       : [sel] "+r" (sel)
-                       : [flat] "r" (FLAT_USER_DS32) );
-
-        /* Update the cache of the inactive base, as read from the GDT/LDT. */
-        v->arch.pv.gs_base_user = rdgsbase();
-
-        asm volatile ( safe_swapgs );
-        break;
-    }
-
-    default:
-        ret = -EINVAL;
-        break;
-    }
-
-    return ret;
-}
-
-
 /* Returns TRUE if given descriptor is valid for GDT or LDT. */
 int check_descriptor(const struct domain *dom, seg_desc_t *d)
 {
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:49:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:49:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMNu-0006fj-3M; Fri, 18 Sep 2020 19:49:30 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMNt-0006fc-Kh
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:29 +0000
X-Inumbo-ID: 09ee3b94-ebb9-414a-afb6-dc0b793b98a7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 09ee3b94-ebb9-414a-afb6-dc0b793b98a7;
 Fri, 18 Sep 2020 19:49:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6ZsnZB1cZVl639ZCF+omUS9xe9shht5it3qLxlJ43W0=; b=LDDRzYB8oElrO9C+rDgsmnVg5P
 rcdW0Sd4IX6wL3//fgTCuleh1dAhmkvPOykdjtN87RtRO6Nhtku0mOTzeKbydow6DvsuOBEHNdEdF
 auUkec6t86WTz1PS8mbHYM71yvOxu7mLYefMOnjQ2OyzTOomPYCRnX6ErXdNRzAtvgWE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNs-0007CM-SX
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:28 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMNs-0004bP-Qi
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:28 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] lib: correct __moddi3() description
Message-Id: <E1kJMNs-0004bP-Qi@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:49:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 033b534be50b0c53cf32171e8b013df505758c13
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 9 17:55:41 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:55:41 2020 +0200

    lib: correct __moddi3() description
    
    The remainder of a division, when non-zero, is specified to always be of
    the same sign as the dividend. Bring a comment in line with the code it
    describes.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/common/lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/lib.c b/xen/common/lib.c
index 8ebec811b3..b2b799da44 100644
--- a/xen/common/lib.c
+++ b/xen/common/lib.c
@@ -390,7 +390,7 @@ u64 __umoddi3(u64 a, u64 b)
  *  11 %  5 =  1
  * -11 %  5 = -1
  *  11 % -5 =  1
- * -11 % -5 =  1
+ * -11 % -5 = -1
  */
 s64 __moddi3(s64 a, s64 b)
 {
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:49:41 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:49:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMO5-0006h1-6G; Fri, 18 Sep 2020 19:49:41 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMO4-0006gs-Ap
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:40 +0000
X-Inumbo-ID: def7a7ce-b02e-422f-822d-768d612117f4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id def7a7ce-b02e-422f-822d-768d612117f4;
 Fri, 18 Sep 2020 19:49:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=x52rIiuuhjeWBg2rZ/n58jTt4DGIthPTUNH3E1sPGUk=; b=OmnZw0SujUHYOggITYWB2mCDmb
 WIjv6iNfiLP/KCs2Bt/1ZZjRwGoGXvq9nZbDTMiTcw4AUNmCWHUO3yHosdrXTDiXqY4/iDInkPvc7
 zi/bc7NMwjpjmi6CAYmgBDQkyYoZuQ4pFEiir1iQeg0xv2k8ob2YOma1hn1jCPWcw0WI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMO3-0007CY-05
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:39 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMO2-0004dp-Us
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:38 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] hvmloader: indicate ACPI tables with "ACPI data" type in
 e820
Message-Id: <E1kJMO2-0004dp-Us@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:49:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8efa46516c5f4cf185c8df179812c185d3c27eb6
Author:     Igor Druzhinin <igor.druzhinin@citrix.com>
AuthorDate: Wed Sep 9 17:56:13 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:56:13 2020 +0200

    hvmloader: indicate ACPI tables with "ACPI data" type in e820
    
    Guest kernel does need to know in some cases where the tables are located
    to treat these regions properly. One example is kexec process where
    the first kernel needs to pass ACPI region locations to the second
    kernel which is now a requirement in Linux after 02a3e3cdb7f12 ("x86/boot:
    Parse SRAT table and count immovable memory regions") in order for kexec
    transition to actually work.
    
    That commit introduced accesses to XSDT and SRAT while the second kernel
    is still using kexec transition tables. The transition tables do not have
    e820 "reserved" regions mapped where those tables are located currently
    in a Xen guest. Instead "ACPI data" regions are mapped with the transition
    tables that was introduced by the following commit 6bbeb276b7 ("x86/kexec:
    Add the EFI system tables and ACPI tables to the ident map").
    
    Reserve 1MB (out of 16MB currently available) right after ACPI info page for
    ACPI tables exclusively but populate this region on demand and only indicate
    populated memory as "ACPI data" since according to ACPI spec that memory is
    reclaimable by the guest if necessary. That is close to how we treat
    the same ACPI data in PVH guests. 1MB should be enough for now but could be
    later extended if required.
    
    Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 tools/firmware/hvmloader/config.h    |  6 +++++-
 tools/firmware/hvmloader/e820.c      | 26 ++++++++++++++++++++++----
 tools/firmware/hvmloader/hvmloader.c |  3 ++-
 tools/firmware/hvmloader/pci.c       |  1 -
 tools/firmware/hvmloader/util.c      | 29 ++++++++++++++++++++++++++++-
 tools/firmware/hvmloader/util.h      |  2 ++
 6 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index d9b4713d63..844120bc87 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -2,6 +2,7 @@
 #define __HVMLOADER_CONFIG_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 
 enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
@@ -62,6 +63,8 @@ extern uint8_t ioapic_version;
 extern unsigned long pci_mem_start, pci_mem_end;
 extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 
+extern bool acpi_enabled;
+
 /* Memory map. */
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
@@ -71,7 +74,8 @@ extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 #define RESERVED_MEMBASE              0xFC000000
 /* NB. ACPI_INFO_PHYSICAL_ADDRESS *MUST* match definition in acpi/dsdt.asl! */
 #define ACPI_INFO_PHYSICAL_ADDRESS    0xFC000000
-#define RESERVED_MEMORY_DYNAMIC_START 0xFC001000
+#define ACPI_MEMORY_DYNAMIC_START     0xFC001000
+#define RESERVED_MEMORY_DYNAMIC_START 0xFC100000
 #define RESERVED_MEMORY_DYNAMIC_END   0xFE000000
 /*
  * GUEST_RESERVED: Physical address space reserved for guest use.
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 4d1c955a02..38bcf18b63 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -155,6 +155,9 @@ int build_e820_table(struct e820entry *e820,
 {
     unsigned int nr = 0, i, j;
     uint32_t low_mem_end = hvm_info->low_mem_pgend << PAGE_SHIFT;
+    unsigned long acpi_mem_end = acpi_enabled ?
+        ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated() << PAGE_SHIFT) :
+        RESERVED_MEMBASE;
 
     if ( !lowmem_reserved_base )
             lowmem_reserved_base = 0xA0000;
@@ -198,9 +201,24 @@ int build_e820_table(struct e820entry *e820,
     e820[nr].type = E820_RESERVED;
     nr++;
 
+    /*
+     * Mark populated reserved memory that contains ACPI tables as ACPI data.
+     * That should help the guest to treat it correctly later: e.g. pass to
+     * the next kernel on kexec or reclaim if necessary.
+     */
+
+    if ( acpi_enabled )
+    {
+        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].size = acpi_mem_end - RESERVED_MEMBASE;
+        e820[nr].type = E820_ACPI;
+        nr++;
+    }
+
     /*
      * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * This space starts right after ACPI region (to avoid creating a hole that
+     * might be accidentally occupied by MMIO) and extends to cover various
      * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
      *
      * If igd_opregion_pgbase we need to split the RESERVED region in two.
@@ -210,8 +228,8 @@ int build_e820_table(struct e820entry *e820,
     {
         uint32_t igd_opregion_base = igd_opregion_pgbase << PAGE_SHIFT;
 
-        e820[nr].addr = RESERVED_MEMBASE;
-        e820[nr].size = (uint32_t) igd_opregion_base - RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
+        e820[nr].size = igd_opregion_base - acpi_mem_end;
         e820[nr].type = E820_RESERVED;
         nr++;
 
@@ -227,7 +245,7 @@ int build_e820_table(struct e820entry *e820,
     }
     else
     {
-        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
         e820[nr].size = (uint32_t)-e820[nr].addr;
         e820[nr].type = E820_RESERVED;
         nr++;
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 598a226278..c58841e5b5 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -116,6 +116,8 @@ unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
 uint32_t ioapic_base_address = 0xfec00000;
 uint8_t ioapic_version;
 
+bool acpi_enabled;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -321,7 +323,6 @@ const struct hvm_modlist_entry *get_module_entry(
 int main(void)
 {
     const struct bios_config *bios;
-    int acpi_enabled;
     const struct hvm_modlist_entry *bios_module;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index dcd097a866..72f92d4450 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -28,7 +28,6 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
-#include <stdbool.h>
 
 unsigned long pci_mem_start = HVM_BELOW_4G_MMIO_START;
 unsigned long pci_mem_end = PCI_MEM_END;
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 0c3f2d24cd..7da144b0bb 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -871,10 +871,37 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static unsigned long acpi_alloc_up = ACPI_MEMORY_DYNAMIC_START - 1;
+
+unsigned long acpi_pages_allocated(void)
+{
+    return (acpi_alloc_up >> PAGE_SHIFT) -
+            ((ACPI_MEMORY_DYNAMIC_START - 1) >> PAGE_SHIFT);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
-    return mem_alloc(size, align);
+    unsigned long s, e;
+
+    /* Align to at least 16 bytes. */
+    if ( align < 16 )
+        align = 16;
+
+    s = (acpi_alloc_up + align) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON((e < s) || (e >= RESERVED_MEMORY_DYNAMIC_START));
+
+    while ( (acpi_alloc_up >> PAGE_SHIFT) != (e >> PAGE_SHIFT) )
+    {
+        acpi_alloc_up += PAGE_SIZE;
+        mem_hole_populate_ram(acpi_alloc_up >> PAGE_SHIFT, 1);
+    }
+
+    acpi_alloc_up = e;
+
+    return (void *)s;
 }
 
 static void acpi_mem_free(struct acpi_ctxt *ctxt,
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 7bca6418d2..31889de634 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -282,6 +282,8 @@ bool check_overlap(uint64_t start, uint64_t size,
 extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
 extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
 
+unsigned long acpi_pages_allocated(void);
+
 struct acpi_config;
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:49:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:49:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMOG-0006hz-7t; Fri, 18 Sep 2020 19:49:52 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMOE-0006hp-V7
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:50 +0000
X-Inumbo-ID: 59d2ab70-85d4-4234-9073-993747ce262a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 59d2ab70-85d4-4234-9073-993747ce262a;
 Fri, 18 Sep 2020 19:49:50 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=XwXb2ZIuxnrmcyV72g3w3r5uWn8Q/I1SYjW049mv8M0=; b=FbwtrDfTOJpCwVopv3fmzf88EZ
 rDA3gD9YQCRqFJ5rfjGiWk9vvCBbtSNt2nQ7rCDEt4xG5B82Au7wQu1D+Dy6DZshIrzQKZgV59xPW
 nA6diMbpcg/dRoPgnypyWCntp87aIcvV8+7K4I9z3GIB/50GV4EuNtzf8gDGcFiFDP2A=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOE-0007ED-1a
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:50 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOD-0004eQ-2M
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:49:50 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: drop use of prelink-efi_lto.o
Message-Id: <E1kJMOD-0004eQ-2M@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:49:49 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ba65a2ff688f1eb390b3f91fdfd09d799925f460
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 9 17:56:49 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 9 17:56:49 2020 +0200

    x86: drop use of prelink-efi_lto.o
    
    As of de94e8b4f996 ("x86/EFI: sanitize build logic") it is identical to
    prelink_lto.o.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/Makefile | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 1f279b6b2e..74152f2a0d 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -135,14 +135,11 @@ ifeq ($(CONFIG_LTO),y)
 prelink_lto.o: $(ALL_OBJS)
 	$(LD_LTO) -r -o $@ $^
 
-prelink-efi_lto.o: $(ALL_OBJS)
-	$(LD_LTO) -r -o $@ $^
-
 # Link it with all the binary objects
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y)
 	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
 else
 prelink.o: $(ALL_OBJS) $(EFI_OBJS-y)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMOQ-0006mn-9S; Fri, 18 Sep 2020 19:50:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMOP-0006ja-CP
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:01 +0000
X-Inumbo-ID: d4faf7a3-e574-41fd-afd3-611814263557
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d4faf7a3-e574-41fd-afd3-611814263557;
 Fri, 18 Sep 2020 19:50:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=c6f1kDBFUhrDxPzzmp1uNqhFU/5n7f/niwXRMqfxQVM=; b=cX1OJ5WQVoi0FXmXjQ2powyuzb
 PBpQEgat6nTnhiIYJfKCvSqR/x1X/32AUUf4/IpRYriuogYY3goatmeVa40DhYXxxCMTzfCWJVUfU
 C9zVhGdDPj+hnDzIVRLsFlcOUgonr8OTsl4igxsNgd8F5VZ0pmJ4NjrgSpNWlBDwyQLQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOO-0007EO-4o
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:00 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOO-0004f5-49
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:00 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: Move segment descriptor infrastructure into
 PV-only files
Message-Id: <E1kJMOO-0004f5-49@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:00 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 89002866bb6c6f26024f015820c8f52012f95cf2
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Thu Sep 3 19:28:15 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Wed Sep 9 17:57:26 2020 +0100

    x86/pv: Move segment descriptor infrastructure into PV-only files
    
    ... so all segment checking/adjustment logic is co-located.
    
    Perform some trivial style cleanup to check_descriptor() as it moves,
    converting types, and cleaning up trailing whitespace.
    
    In particular, this means that check_descriptor() is now excluded from
    !CONFIG_PV builds.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/mm.c                   |  17 ------
 xen/arch/x86/pv/descriptor-tables.c | 100 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/mm.c            |  87 -------------------------------
 xen/include/asm-x86/mm.h            |   2 -
 xen/include/asm-x86/pv/mm.h         |   2 +
 5 files changed, 102 insertions(+), 106 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 35ec0e11f6..56bf7add2b 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -585,23 +585,6 @@ const char __section(".bss.page_aligned.const") __aligned(PAGE_SIZE)
     zero_page[PAGE_SIZE];
 
 
-#ifdef CONFIG_PV
-static int validate_segdesc_page(struct page_info *page)
-{
-    const struct domain *owner = page_get_owner(page);
-    seg_desc_t *descs = __map_domain_page(page);
-    unsigned i;
-
-    for ( i = 0; i < 512; i++ )
-        if ( unlikely(!check_descriptor(owner, &descs[i])) )
-            break;
-
-    unmap_domain_page(descs);
-
-    return i == 512 ? 0 : -EINVAL;
-}
-#endif
-
 static int _get_page_type(struct page_info *page, unsigned long type,
                           bool preemptible);
 
diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c
index 3856128993..39c1a2311a 100644
--- a/xen/arch/x86/pv/descriptor-tables.c
+++ b/xen/arch/x86/pv/descriptor-tables.c
@@ -185,6 +185,106 @@ int compat_set_gdt(XEN_GUEST_HANDLE_PARAM(uint) frame_list,
     return ret;
 }
 
+static bool check_descriptor(const struct domain *dom, seg_desc_t *d)
+{
+    unsigned int a = d->a, b = d->b, cs, dpl;
+
+    /* A not-present descriptor will always fault, so is safe. */
+    if ( !(b & _SEGMENT_P) )
+        return true;
+
+    /* Check and fix up the DPL. */
+    dpl = (b >> 13) & 3;
+    __fixup_guest_selector(dom, dpl);
+    b = (b & ~_SEGMENT_DPL) | (dpl << 13);
+
+    /* All code and data segments are okay. No base/limit checking. */
+    if ( b & _SEGMENT_S )
+    {
+        if ( is_pv_32bit_domain(dom) )
+        {
+            unsigned long base, limit;
+
+            if ( b & _SEGMENT_L )
+                goto bad;
+
+            /*
+             * Older PAE Linux guests use segments which are limited to
+             * 0xf6800000. Extend these to allow access to the larger read-only
+             * M2P table available in 32on64 mode.
+             */
+            base = (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16);
+
+            limit = (b & 0xf0000) | (a & 0xffff);
+            limit++; /* We add one because limit is inclusive. */
+
+            if ( b & _SEGMENT_G )
+                limit <<= 12;
+
+            if ( (base == 0) && (limit > HYPERVISOR_COMPAT_VIRT_START(dom)) )
+            {
+                a |= 0x0000ffff;
+                b |= 0x000f0000;
+            }
+        }
+
+        goto good;
+    }
+
+    /* Invalid type 0 is harmless. It is used for 2nd half of a call gate. */
+    if ( (b & _SEGMENT_TYPE) == 0x000 )
+        return true;
+
+    /* Everything but a call gate is discarded here. */
+    if ( (b & _SEGMENT_TYPE) != 0xc00 )
+        goto bad;
+
+    /* Validate the target code selector. */
+    cs = a >> 16;
+    if ( !guest_gate_selector_okay(dom, cs) )
+        goto bad;
+    /*
+     * Force DPL to zero, causing a GP fault with its error code indicating
+     * the gate in use, allowing emulation. This is necessary because with
+     * native guests (kernel in ring 3) call gates cannot be used directly
+     * to transition from user to kernel mode (and whether a gate is used
+     * to enter the kernel can only be determined when the gate is being
+     * used), and with compat guests call gates cannot be used at all as
+     * there are only 64-bit ones.
+     * Store the original DPL in the selector's RPL field.
+     */
+    b &= ~_SEGMENT_DPL;
+    cs = (cs & ~3) | dpl;
+    a = (a & 0xffffU) | (cs << 16);
+
+    /* Reserved bits must be zero. */
+    if ( b & (is_pv_32bit_domain(dom) ? 0xe0 : 0xff) )
+        goto bad;
+
+ good:
+    d->a = a;
+    d->b = b;
+    return true;
+
+ bad:
+    return false;
+}
+
+int validate_segdesc_page(struct page_info *page)
+{
+    const struct domain *owner = page_get_owner(page);
+    seg_desc_t *descs = __map_domain_page(page);
+    unsigned i;
+
+    for ( i = 0; i < 512; i++ )
+        if ( unlikely(!check_descriptor(owner, &descs[i])) )
+            break;
+
+    unmap_domain_page(descs);
+
+    return i == 512 ? 0 : -EINVAL;
+}
+
 long do_update_descriptor(uint64_t gaddr, seg_desc_t d)
 {
     struct domain *currd = current->domain;
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 98581dfe5f..1f32062c15 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1010,93 +1010,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
-/* Returns TRUE if given descriptor is valid for GDT or LDT. */
-int check_descriptor(const struct domain *dom, seg_desc_t *d)
-{
-    u32 a = d->a, b = d->b;
-    u16 cs;
-    unsigned int dpl;
-
-    /* A not-present descriptor will always fault, so is safe. */
-    if ( !(b & _SEGMENT_P) ) 
-        return 1;
-
-    /* Check and fix up the DPL. */
-    dpl = (b >> 13) & 3;
-    __fixup_guest_selector(dom, dpl);
-    b = (b & ~_SEGMENT_DPL) | (dpl << 13);
-
-    /* All code and data segments are okay. No base/limit checking. */
-    if ( (b & _SEGMENT_S) )
-    {
-        if ( is_pv_32bit_domain(dom) )
-        {
-            unsigned long base, limit;
-
-            if ( b & _SEGMENT_L )
-                goto bad;
-
-            /*
-             * Older PAE Linux guests use segments which are limited to
-             * 0xf6800000. Extend these to allow access to the larger read-only
-             * M2P table available in 32on64 mode.
-             */
-            base = (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16);
-
-            limit = (b & 0xf0000) | (a & 0xffff);
-            limit++; /* We add one because limit is inclusive. */
-
-            if ( (b & _SEGMENT_G) )
-                limit <<= 12;
-
-            if ( (base == 0) && (limit > HYPERVISOR_COMPAT_VIRT_START(dom)) )
-            {
-                a |= 0x0000ffff;
-                b |= 0x000f0000;
-            }
-        }
-
-        goto good;
-    }
-
-    /* Invalid type 0 is harmless. It is used for 2nd half of a call gate. */
-    if ( (b & _SEGMENT_TYPE) == 0x000 )
-        return 1;
-
-    /* Everything but a call gate is discarded here. */
-    if ( (b & _SEGMENT_TYPE) != 0xc00 )
-        goto bad;
-
-    /* Validate the target code selector. */
-    cs = a >> 16;
-    if ( !guest_gate_selector_okay(dom, cs) )
-        goto bad;
-    /*
-     * Force DPL to zero, causing a GP fault with its error code indicating
-     * the gate in use, allowing emulation. This is necessary because with
-     * native guests (kernel in ring 3) call gates cannot be used directly
-     * to transition from user to kernel mode (and whether a gate is used
-     * to enter the kernel can only be determined when the gate is being
-     * used), and with compat guests call gates cannot be used at all as
-     * there are only 64-bit ones.
-     * Store the original DPL in the selector's RPL field.
-     */
-    b &= ~_SEGMENT_DPL;
-    cs = (cs & ~3) | dpl;
-    a = (a & 0xffffU) | (cs << 16);
-
-    /* Reserved bits must be zero. */
-    if ( b & (is_pv_32bit_domain(dom) ? 0xe0 : 0xff) )
-        goto bad;
-        
- good:
-    d->a = a;
-    d->b = b;
-    return 1;
- bad:
-    return 0;
-}
-
 int pagefault_by_memadd(unsigned long addr, struct cpu_user_regs *regs)
 {
     struct domain *d = current->domain;
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 632ece1cee..deeba75a1c 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -454,8 +454,6 @@ static inline int get_page_and_type(struct page_info *page,
     ASSERT(((_p)->count_info & PGC_count_mask) != 0);          \
     ASSERT(page_get_owner(_p) == (_d))
 
-int check_descriptor(const struct domain *d, seg_desc_t *desc);
-
 extern paddr_t mem_hotplug;
 
 /******************************************************************************
diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h
index 07a12d5c49..9983f8257c 100644
--- a/xen/include/asm-x86/pv/mm.h
+++ b/xen/include/asm-x86/pv/mm.h
@@ -32,6 +32,8 @@ void pv_destroy_gdt(struct vcpu *v);
 bool pv_map_ldt_shadow_page(unsigned int off);
 bool pv_destroy_ldt(struct vcpu *v);
 
+int validate_segdesc_page(struct page_info *page);
+
 #else
 
 #include <xen/errno.h>
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMOa-0007PW-Az; Fri, 18 Sep 2020 19:50:12 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMOZ-0007PJ-2Q
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:11 +0000
X-Inumbo-ID: 7a613fac-e231-42f4-8dec-eaa0abaa9d81
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7a613fac-e231-42f4-8dec-eaa0abaa9d81;
 Fri, 18 Sep 2020 19:50:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=n0akseYtcbPjFS261kQd3Hz4lg5hesRhw6mG+dUnW5w=; b=rje33nsqF3bBsUOkRIu1plWVhe
 ssrEE/M4Aujzj6R17Wh6y7Bv+sSWgczk2LIOJPVPY/rH5CawabFmaC2tMWA3muduof43BIW6eqW/d
 +j07twEORU4HnRfHO3eKNZJw42NKn9Mbq1L322yQrk1z8PXlkH2lC4+ykJqA6llOInC4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOY-0007FN-8w
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:10 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOY-0004fz-6y
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:10 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libs/guest: fix Makefile regarding zlib options
Message-Id: <E1kJMOY-0004fz-6y@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:10 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit cc13835377debe4e300c5f5f11f8f78920778c4e
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Thu Sep 10 17:42:10 2020 +0200
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Sep 10 20:27:00 2020 +0100

    tools/libs/guest: fix Makefile regarding zlib options
    
    When renaming the libxenguest sources to xg_*.c there was an omission
    in the Makefile when setting the zlib related define for the related
    sources. Fix that.
    
    Fixes: e3dd624e487c ("tools/libxc: move libxenguest to tools/libs/guest")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libs/guest/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libs/guest/Makefile b/tools/libs/guest/Makefile
index e53aeabd3e..f24732fbcd 100644
--- a/tools/libs/guest/Makefile
+++ b/tools/libs/guest/Makefile
@@ -94,8 +94,8 @@ else
 zlib-options = $(ZLIB)
 endif
 
-xc_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
-xc_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
+xg_dom_bzimageloader.o: CFLAGS += $(filter -D%,$(zlib-options))
+xg_dom_bzimageloader.opic: CFLAGS += $(filter -D%,$(zlib-options))
 
 LIBHEADER := xenguest.h
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMOl-0007R1-CW; Fri, 18 Sep 2020 19:50:23 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMOk-0007Qr-TN
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:22 +0000
X-Inumbo-ID: e915eaba-1e53-4930-9c70-28b988acc979
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e915eaba-1e53-4930-9c70-28b988acc979;
 Fri, 18 Sep 2020 19:50:20 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eFNNOXIK57WhqFWUQg5pH526Fq7G/+88uwGtoQcUKVk=; b=mws33ohCf1WuHi1mnLCt2r4hjF
 9zURNuFzPtQUwfcdMeNqqY2hijUDbAVrTSUQQB7IensnLfqZaFuaqp4vw5w4VCfyiHwaYSMrZPm1n
 xTZ0M2Fmw9L8U9K+7lv5bQ05St99loXQQe3QJXhJqEe4K/QYGWikOwTwZ3B5yRt+JRqk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOi-0007FV-Cf
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:20 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOi-0004ga-BG
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:20 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: guard against port I/O overlapping the RTC/CMOS
 range
Message-Id: <E1kJMOi-0004ga-BG@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:20 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 899316e02e0d1c9bfe65cca1b20f8140ee9c4d17
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:13:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:13:46 2020 +0200

    x86: guard against port I/O overlapping the RTC/CMOS range
    
    Since we intercept RTC/CMOS port accesses, let's do so consistently in
    all cases, i.e. also for e.g. a dword access to [006E,0071]. To avoid
    the risk of unintended impact on Dom0 code actually doing so (despite
    the belief that none ought to exist), also extend
    guest_io_{read,write}() to decompose accesses where some ports are
    allowed to be directly accessed and some aren't.
    
    While splitting out the new _guest_io_write() also
    - add ASSERT_UNREACHABLE(),
    - drop stray casts,
    - add blank lines.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/pv/emul-priv-op.c | 59 +++++++++++++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index a192160f84..c6fbf8f92d 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -210,7 +210,7 @@ static bool admin_io_okay(unsigned int port, unsigned int bytes,
         return false;
 
     /* We also never permit direct access to the RTC/CMOS registers. */
-    if ( ((port & ~1) == RTC_PORT(0)) )
+    if ( port <= RTC_PORT(1) && port + bytes > RTC_PORT(0) )
         return false;
 
     return ioports_access_permitted(d, port, port + bytes - 1);
@@ -297,6 +297,17 @@ static uint32_t guest_io_read(unsigned int port, unsigned int bytes,
             if ( pci_cfg_ok(currd, port & 3, size, NULL) )
                 sub_data = pci_conf_read(currd->arch.pci_cf8, port & 3, size);
         }
+        else if ( ioports_access_permitted(currd, port, port) )
+        {
+            if ( bytes > 1 && !(port & 1) &&
+                 ioports_access_permitted(currd, port, port + 1) )
+            {
+                sub_data = inw(port);
+                size = 2;
+            }
+            else
+                sub_data = inb(port);
+        }
 
         if ( size == 4 )
             return sub_data;
@@ -373,25 +384,36 @@ static int read_io(unsigned int port, unsigned int bytes,
     return X86EMUL_OKAY;
 }
 
+static void _guest_io_write(unsigned int port, unsigned int bytes,
+                            uint32_t data)
+{
+    switch ( bytes )
+    {
+    case 1:
+        outb(data, port);
+        if ( amd_acpi_c1e_quirk )
+            amd_check_disable_c1e(port, data);
+        break;
+
+    case 2:
+        outw(data, port);
+        break;
+
+    case 4:
+        outl(data, port);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
+    }
+}
+
 static void guest_io_write(unsigned int port, unsigned int bytes,
                            uint32_t data, struct domain *currd)
 {
     if ( admin_io_okay(port, bytes, currd) )
     {
-        switch ( bytes )
-        {
-        case 1:
-            outb((uint8_t)data, port);
-            if ( amd_acpi_c1e_quirk )
-                amd_check_disable_c1e(port, (uint8_t)data);
-            break;
-        case 2:
-            outw((uint16_t)data, port);
-            break;
-        case 4:
-            outl(data, port);
-            break;
-        }
+        _guest_io_write(port, bytes, data);
         return;
     }
 
@@ -420,6 +442,13 @@ static void guest_io_write(unsigned int port, unsigned int bytes,
             if ( pci_cfg_ok(currd, port & 3, size, &data) )
                 pci_conf_write(currd->arch.pci_cf8, port & 3, size, data);
         }
+        else if ( ioports_access_permitted(currd, port, port) )
+        {
+            if ( bytes > 1 && !(port & 1) &&
+                 ioports_access_permitted(currd, port, port + 1) )
+                size = 2;
+            _guest_io_write(port, size, data);
+        }
 
         if ( size == 4 )
             return;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMOu-0007S0-FU; Fri, 18 Sep 2020 19:50:32 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMOt-0007Rt-8v
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:31 +0000
X-Inumbo-ID: af25861d-60c0-48e6-831a-aa6db1e455ad
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id af25861d-60c0-48e6-831a-aa6db1e455ad;
 Fri, 18 Sep 2020 19:50:30 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7Im1NfAP0FbUW00/BbTxGy8zoRJbFaBzFTa5CNM4skk=; b=mPyRemQiiQP3fkBrccVnvA/R/q
 cl40LGQfPcgEYwNNFPJIcsf8YFou8jtG6hgB2OIzT5uK0Arptdgen80KL8quNKqZNjU/5huRjXIVC
 ldQRqN2Q9e71mAlKnrcXs7FA4b47mnWOBUu4nDBk+18dr59DFr3EtGDHZV3tXG8WjKkw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOs-0007Fl-Fa
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:30 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMOs-0004hH-Ey
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:30 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86: don't override INVALID_M2P_ENTRY with
 SHARED_M2P_ENTRY
Message-Id: <E1kJMOs-0004hH-Ey@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:30 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c9476c4ad72e8a1842d713c74843034c7ec6eb51
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:14:43 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:14:43 2020 +0200

    x86: don't override INVALID_M2P_ENTRY with SHARED_M2P_ENTRY
    
    While in most cases code ahead of the invocation of set_gpfn_from_mfn()
    deals with shared pages, at least in set_typed_p2m_entry() I can't spot
    such handling (it's entirely possible there's code missing there). Let's
    try to play safe and add an extra check.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/x86_64/mm.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 1f32062c15..0d1aadbfce 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1327,12 +1327,19 @@ destroy_frametable:
 
 void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
 {
-    const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
-    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
+    unsigned long entry = pfn;
 
     if ( unlikely(!machine_to_phys_mapping_valid) )
         return;
 
+    if ( entry != INVALID_M2P_ENTRY )
+    {
+        const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+
+        if ( d && (d == dom_cow) )
+            entry = SHARED_M2P_ENTRY;
+    }
+
     if ( opt_pv32 &&
          mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
         compat_machine_to_phys_mapping[mfn] = entry;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:42 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMP4-0007Sw-H3; Fri, 18 Sep 2020 19:50:42 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMP3-0007Sn-HE
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:41 +0000
X-Inumbo-ID: 132acb8d-79e9-455c-8fa6-6704f0a6be16
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 132acb8d-79e9-455c-8fa6-6704f0a6be16;
 Fri, 18 Sep 2020 19:50:40 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=yN1stnXjzSxYHFA5VebgRG5k3iA5Sq5fUKD2ysAYcW8=; b=gbLfnZC8vEE63P/IFaravedA1/
 5E7dZmtxTxNwuoLlB3qmwhbPbi3JW2zL0NZOza9dACdy0jM6iRETmQLiHBhlMKX6s8o+zsxvqw5Xo
 KbqKnsspqQvMI7obTrnRpe4qnRaEbWFaFh+0ET1pQPmjBdTW1+6b/kSrGqNTsHNU+BRs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMP2-0007Ft-Ir
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:40 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMP2-0004i7-I7
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:40 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/mm: do not mark IO regions as Xen heap
Message-Id: <E1kJMP2-0004i7-I7@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:40 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e5a1b6f0d2070c7a03f0f2cff5126a5fea94cc4d
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Fri Sep 11 14:15:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:15:26 2020 +0200

    x86/mm: do not mark IO regions as Xen heap
    
    arch_init_memory will treat all the gaps on the physical memory map
    between RAM regions as MMIO and use share_xen_page_with_guest in order
    to assign them to dom_io. This has the side effect of setting the Xen
    heap flag on such pages, and thus is_special_page would then return
    true which is an issue in epte_get_entry_emt because such pages will
    be forced to use write-back cache attributes.
    
    Fix this by introducing a new helper to assign the MMIO regions to
    dom_io without setting the Xen heap flag on the pages, so that
    is_special_page will return false and the pages won't be forced to use
    write-back cache attributes.
    
    Fixes: 81fd0d3ca4b2cd ('x86/hvm: simplify 'mmio_direct' check in epte_get_entry_emt()')
    Suggested-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/mm.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 56bf7add2b..42a6dc9ba4 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -271,6 +271,23 @@ static l4_pgentry_t __read_mostly split_l4e;
 #define root_pgt_pv_xen_slots ROOT_PAGETABLE_PV_XEN_SLOTS
 #endif
 
+/*
+ * Originally cloned from share_xen_page_with_guest(), just to avoid setting
+ * PGC_xen_heap on non-heap (typically) MMIO pages. Other pieces got dropped
+ * simply because they're not needed in this context.
+ */ 
+static void __init assign_io_page(struct page_info *page)
+{
+    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY);
+
+    /* The incremented type count pins as writable. */
+    page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
+
+    page_set_owner(page, dom_io);
+
+    page->count_info |= PGC_allocated | 1;
+}
+
 void __init arch_init_memory(void)
 {
     unsigned long i, pfn, rstart_pfn, rend_pfn, iostart_pfn, ioend_pfn;
@@ -291,7 +308,7 @@ void __init arch_init_memory(void)
      */
     BUG_ON(pvh_boot && trampoline_phys != 0x1000);
     for ( i = 0; i < 0x100; i++ )
-        share_xen_page_with_guest(mfn_to_page(_mfn(i)), dom_io, SHARE_rw);
+        assign_io_page(mfn_to_page(_mfn(i)));
 
     /* Any areas not specified as RAM by the e820 map are considered I/O. */
     for ( i = 0, pfn = 0; pfn < max_page; i++ )
@@ -332,7 +349,7 @@ void __init arch_init_memory(void)
             if ( !mfn_valid(_mfn(pfn)) )
                 continue;
 
-            share_xen_page_with_guest(mfn_to_page(_mfn(pfn)), dom_io, SHARE_rw);
+            assign_io_page(mfn_to_page(_mfn(pfn)));
         }
 
         /* Skip the RAM region. */
@@ -477,6 +494,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
 void share_xen_page_with_guest(struct page_info *page, struct domain *d,
                                enum XENSHARE_flags flags)
 {
+    ASSERT(d != dom_io); /* Should use assign_io_page(). */
+
     if ( page_get_owner(page) == d )
         return;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:50:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:50:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMPE-0007Vb-Ie; Fri, 18 Sep 2020 19:50:52 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMPD-0007VS-LD
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:51 +0000
X-Inumbo-ID: 1fbea169-5d7d-468e-9fd0-ea0032c53d4f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1fbea169-5d7d-468e-9fd0-ea0032c53d4f;
 Fri, 18 Sep 2020 19:50:50 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LFlBcnsWWwyAkx4dX7tiBxpS47/leP0bThZKwjL5LjY=; b=CHoLbjKqJcaqupcY0JOaHqoBps
 a5N0p/EaAdWA8WS4xs6sjOYpSJXtQPqxkEC4L28qcSP52VGCC8tbclR/mgnZCg52Qagr6jYUc/ZMm
 mlEhZlJNv/TbeN/5dqgIIR655et6po+xLwWWjqyP6HF5u9z3hAOE4PlpRpxUt7n9TaBc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPC-0007G4-Lu
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:50 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPC-0004iy-L7
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:50:50 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/PV: fold exit paths of ptwr_do_page_fault()
Message-Id: <E1kJMPC-0004iy-L7@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:50:50 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0fcfe9d95f8bb1d53cf68038f13bc3563020e8cd
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 14:16:14 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:16:14 2020 +0200

    x86/PV: fold exit paths of ptwr_do_page_fault()
    
    One less aspect to keep an eye on for things to stay in sync.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/pv/ro-page-fault.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c
index 0eedb70002..556ee7ca11 100644
--- a/xen/arch/x86/pv/ro-page-fault.c
+++ b/xen/arch/x86/pv/ro-page-fault.c
@@ -262,29 +262,23 @@ static int ptwr_do_page_fault(struct x86_emulate_ctxt *ctxt,
         .pte = pte,
     };
     struct page_info *page;
-    int rc;
+    int rc = X86EMUL_UNHANDLEABLE;
 
     page = get_page_from_mfn(l1e_get_mfn(pte), current->domain);
     if ( !page )
         return X86EMUL_UNHANDLEABLE;
 
-    if ( !page_lock(page) )
+    if ( page_lock(page) )
     {
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
-    }
+        if ( (page->u.inuse.type_info & PGT_type_mask) == PGT_l1_page_table )
+        {
+            ctxt->data = &ptwr_ctxt;
+            rc = x86_emulate(ctxt, &ptwr_emulate_ops);
+        }
 
-    if ( (page->u.inuse.type_info & PGT_type_mask) != PGT_l1_page_table )
-    {
         page_unlock(page);
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
     }
 
-    ctxt->data = &ptwr_ctxt;
-    rc = x86_emulate(ctxt, &ptwr_emulate_ops);
-
-    page_unlock(page);
     put_page(page);
 
     return rc;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMPO-0007XE-KF; Fri, 18 Sep 2020 19:51:02 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMPN-0007Wz-KB
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:01 +0000
X-Inumbo-ID: c1b0ee35-8117-4235-92f8-21f54523fd3d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id c1b0ee35-8117-4235-92f8-21f54523fd3d;
 Fri, 18 Sep 2020 19:51:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/GHEGPrm53uqadJQH5ZldMEsDpM5N5frU/I7gyxQ1Zs=; b=isAYg+IKAmJ8QTLs3MI/pCyIPF
 F0GAO6qaT+iZAxLgZT+PyQa7de8dbrC52XqxCUJCUtJChTO4GMWlvESXBue10uUJ01OUwUK2i6+Fp
 uGFDZuZilTFQEWGpqM9SaTmjuYV1xHqExQQF1M1pAL8N5Dn0LkIEw8mfvSSXoS5ndHLY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPM-0007GE-P9
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:00 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPM-0004jb-O3
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:00 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/hypfs: fix writing of custom parameter
Message-Id: <E1kJMPM-0004jb-O3@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:00 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b4e41b1750d550bf2b1ccf97ee46f4f682bdbb62
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Fri Sep 11 14:20:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Fri Sep 11 14:20:10 2020 +0200

    xen/hypfs: fix writing of custom parameter
    
    Today the maximum allowed data length for writing a hypfs node is
    tested in the generic hypfs_write() function. For custom runtime
    parameters this might be wrong, as the maximum allowed size is derived
    from the buffer holding the current setting, while there might be ways
    to set the parameter needing more characters than the minimal
    representation of that value.
    
    One example for this is the "ept" parameter. Its value buffer is sized
    to be able to hold the string "exec-sp=0" or "exec-sp=1", while it is
    allowed to use e.g. "no-exec-sp" or "exec-sp=yes" for setting it.
    
    Fix that by moving the length check one level down to the type
    specific write function.
    
    In order to avoid allocation of arbitrary sized buffers use a new
    MAX_PARAM_SIZE macro as an upper limit for custom writes. The value
    of MAX_PARAM_SIZE is the same as the limit in parse_params() for a
    single parameter.
    
    Fixes: a659d7cab9af ("xen: add runtime parameter access support to hypfs")
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/common/hypfs.c      | 11 +++++++----
 xen/common/kernel.c     |  2 +-
 xen/include/xen/param.h |  3 +++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c
index b74c228191..8e932b5cf9 100644
--- a/xen/common/hypfs.c
+++ b/xen/common/hypfs.c
@@ -297,7 +297,9 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
     int ret;
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
-    ASSERT(ulen <= leaf->e.max_size);
+
+    if ( ulen > leaf->e.max_size )
+        return -ENOSPC;
 
     if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
          leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
@@ -356,6 +358,10 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
 
+    /* Avoid oversized buffer allocation. */
+    if ( ulen > MAX_PARAM_SIZE )
+        return -ENOSPC;
+
     buf = xzalloc_array(char, ulen);
     if ( !buf )
         return -ENOMEM;
@@ -386,9 +392,6 @@ static int hypfs_write(struct hypfs_entry *entry,
 
     ASSERT(entry->max_size);
 
-    if ( ulen > entry->max_size )
-        return -ENOSPC;
-
     l = container_of(entry, struct hypfs_entry_leaf, e);
 
     return entry->write(l, uaddr, ulen);
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 9de07b7ac5..c3a943f077 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -57,7 +57,7 @@ static int assign_integer_param(const struct kernel_param *param, uint64_t val)
 static int parse_params(const char *cmdline, const struct kernel_param *start,
                         const struct kernel_param *end)
 {
-    char opt[128], *optval, *optkey, *q;
+    char opt[MAX_PARAM_SIZE], *optval, *optkey, *q;
     const char *p = cmdline, *key;
     const struct kernel_param *param;
     int rc, final_rc = 0;
diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h
index f4be944248..d0409d3a0e 100644
--- a/xen/include/xen/param.h
+++ b/xen/include/xen/param.h
@@ -26,6 +26,9 @@ struct kernel_param {
     } par;
 };
 
+/* Maximum length of a single parameter string. */
+#define MAX_PARAM_SIZE 128
+
 extern const struct kernel_param __setup_start[], __setup_end[];
 
 #define __param(att)      static const att \
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMPY-0007Ya-Lz; Fri, 18 Sep 2020 19:51:12 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMPX-0007YU-S9
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:11 +0000
X-Inumbo-ID: acf7915c-7d93-4b2a-a1ac-dd551ddecb56
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id acf7915c-7d93-4b2a-a1ac-dd551ddecb56;
 Fri, 18 Sep 2020 19:51:11 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=w3OWcp0nWMDURhfNLQOq4O4bE6t7hvWezi+BzgQp3L4=; b=FJWj5gFqegNiKEqd7pewfhv6I8
 vtUITQWpOtC2hHEH/wmGp6Y1+1Jx2WvP3+K68VE9BBD58dZUuE/kA+MJjuv63eCWEBqaUo+eDUp/1
 Q/5M29xPPony60q9ElTamvoZFr3yR1yQ996kuBg87kJT08JQpz/xtAhB1WzSyoGPipyk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPW-0007H4-Te
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:10 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPW-0004kV-RH
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:10 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/arm64: force gcc 10+ to always inline generic
 atomics helpers
Message-Id: <E1kJMPW-0004kV-RH@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:10 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5d45ecabe3c0b2097df623ab7b471f8915cfdde6
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Fri Sep 11 12:45:33 2020 +0200
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 11 13:36:27 2020 +0100

    xen/arm64: force gcc 10+ to always inline generic atomics helpers
    
    Recent versions of gcc (at least 10.x) will not inline generic atomics
    helpers by default. Instead they will expect the software to either link
    with libatomic.so or implement the helpers, which would result in
    
    undefined reference to `__aarch64_ldadd4_acq_rel'
    
    for us (not having any local implementation).
    
    To keep the previous behavior, force gcc to always inline the generic
    atomics helpers.
    
    Long term we probably want to avoid relying on gcc atomics helpers as
    this doesn't allow us to switch between LSE and LL/SC atomics.
    
    Suggested-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/arch.mk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/arch/arm/arch.mk b/xen/arch/arm/arch.mk
index c8186f5828..11caec86ba 100644
--- a/xen/arch/arm/arch.mk
+++ b/xen/arch/arm/arch.mk
@@ -12,6 +12,7 @@ CFLAGS-$(CONFIG_ARM_32) += -mcpu=cortex-a15
 
 CFLAGS-$(CONFIG_ARM_64) += -mcpu=generic
 CFLAGS-$(CONFIG_ARM_64) += -mgeneral-regs-only # No fp registers etc
+$(call cc-option-add,CFLAGS-$(CONFIG_ARM_64),CC,-mno-outline-atomics)
 
 ifneq ($(filter command line environment,$(origin CONFIG_EARLY_PRINTK)),)
     $(error You must use 'make menuconfig' to enable/disable early printk now)
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:23 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:23 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMPj-0007aA-Nq; Fri, 18 Sep 2020 19:51:23 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMPi-0007Zy-4D
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:22 +0000
X-Inumbo-ID: 148fdad7-056a-4bae-b8a9-c034324f5594
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 148fdad7-056a-4bae-b8a9-c034324f5594;
 Fri, 18 Sep 2020 19:51:21 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ER5P0yQhDb4mKc/TFQ2xPq167MX/cvC275htuOZDASo=; b=YslMV+Hnjl2hn3OjDytjQeHyOT
 0s522sODR3VMFmRvYfLepHqj9jsDrMwg839WQqHKdHEeN0vESddeaU4uOpqAuTu/wiZ2RlSon9aig
 N2Ns6ECAq/t5+sbyPO/MCNgbCpQw4cbiuvdruvwy/Ht0kpnuNz2HWM1d5nOrZATU1/QY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPh-0007HG-0g
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:21 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPh-0004lj-01
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:21 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/cpuid: Untangle Invariant TSC handling
Message-Id: <E1kJMPh-0004lj-01@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:21 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6c5fb129e88b9c06b5fd62a410163ebb8ef77ee6
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Feb 24 17:15:22 2020 +0000
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Fri Sep 11 18:17:59 2020 +0100

    tools/cpuid: Untangle Invariant TSC handling
    
    ITSC being visible to the guest is currently implicit with the toolstack
    unconditionally asking for it, and Xen clipping it based on the vTSC and/or
    XEN_DOMCTL_disable_migrate settings.
    
    This is problematic for several reasons.
    
    First, the implicit vTSC behaviour manifests as a real bug on migration to a
    host with a different frequency, with ITSC but without TSC scaling
    capabilities, whereby the ITSC feature becomes advertised to the guest.  ITSC
    will disappear again if the guest migrates to server with the same frequency
    as the original, or to one with TSC scaling support.
    
    Secondly, disallowing ITSC unless the guest doesn't migrate is conceptually
    wrong.  It is common to have migration pools of identical hardware, at which
    point the TSC frequency is nominally the same, and more modern hardware has
    TSC scaling support anyway.  In both cases, it is safe to advertise ITSC and
    migrate the guest.
    
    Remove all implicit logic in Xen, and make ITSC part of the max CPUID policies
    for guests.  Plumb an itsc parameter into xc_cpuid_apply_policy() and have
    libxl__cpuid_legacy() fill in the two cases where it can reasonably expect
    ITSC to be safe for the guest to see.  This retains the current side effect of
    enabling ITSC if the guest is marked as nomigrate.
    
    This is a behaviour change for TSC_MODE_NATIVE, where the ITSC will now
    reliably not appear, and for the case where the user explicitly requests ITSC,
    in which case it will appear even if the guest isn't marked as nomigrate.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Ian Jackson <Ian.Jackson@citrix.com>
---
 tools/libs/ctrl/include/xenctrl.h           |  4 ++--
 tools/libs/guest/xg_cpuid_x86.c             | 12 ++++++------
 tools/libxl/libxl_cpuid.c                   | 19 ++++++++++++++++++-
 xen/arch/x86/cpuid.c                        |  8 --------
 xen/arch/x86/time.c                         |  2 --
 xen/include/public/arch-x86/cpufeatureset.h |  2 +-
 6 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
index 4c89b7294c..0a921a95fa 100644
--- a/tools/libs/ctrl/include/xenctrl.h
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -1828,14 +1828,14 @@ struct xc_xend_cpuid {
  * cases, and the generated policy must be compatible with a 4.13.
  *
  * Either pass a full new @featureset (and @nr_features), or adjust individual
- * features (@pae).
+ * features (@pae, @itsc).
  *
  * Then (optionally) apply legacy XEND overrides (@xend) to the result.
  */
 int xc_cpuid_apply_policy(xc_interface *xch,
                           uint32_t domid, bool restore,
                           const uint32_t *featureset,
-                          unsigned int nr_features, bool pae,
+                          unsigned int nr_features, bool pae, bool itsc,
                           const struct xc_xend_cpuid *xend);
 int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
 int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 0f24d6dd08..dc50106975 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -427,7 +427,7 @@ static int xc_cpuid_xend_policy(
 
 int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
                           const uint32_t *featureset, unsigned int nr_features,
-                          bool pae,
+                          bool pae, bool itsc,
                           const struct xc_xend_cpuid *xend)
 {
     int rc;
@@ -556,6 +556,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
     }
     else
     {
+        p->extd.itsc = itsc;
+
         if ( di.hvm )
             p->basic.pae = pae;
     }
@@ -625,12 +627,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         }
 
         /*
-         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
-         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
-         * CPUID.  Xen will discard these bits if configuration hasn't been
-         * set for the domain.
+         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM
+         * to be reflected correctly in CPUID.  Xen will discard these bits if
+         * configuration hasn't been set for the domain.
          */
-        p->extd.itsc = true;
         p->basic.vmx = true;
         p->extd.svm = true;
     }
diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c
index 8b570b7e27..f54eb83a90 100644
--- a/tools/libxl/libxl_cpuid.c
+++ b/tools/libxl/libxl_cpuid.c
@@ -421,6 +421,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
                          libxl_domain_build_info *info)
 {
     bool pae = true;
+    bool itsc;
 
     /*
      * For PV guests, PAE is Xen-controlled (it is the 'p' that differentiates
@@ -435,7 +436,23 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
     if (info->type == LIBXL_DOMAIN_TYPE_HVM)
         pae = libxl_defbool_val(info->u.hvm.pae);
 
-    xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, pae, info->cpuid);
+    /*
+     * Advertising Invariant TSC to a guest means that the TSC frequency won't
+     * change at any point in the future.
+     *
+     * We do not have enough information about potential migration
+     * destinations to know whether advertising ITSC is safe, but if the guest
+     * isn't going to migrate, then the current hardware is all that matters.
+     *
+     * Alternatively, an internal property of vTSC is that the values read are
+     * invariant.  Advertise ITSC when we know the domain will have emualted
+     * TSC everywhere it goes.
+     */
+    itsc = (libxl_defbool_val(info->disable_migrate) ||
+            info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE);
+
+    xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0,
+                          pae, itsc, info->cpuid);
 }
 
 static const char *input_names[2] = { "leaf", "subleaf" };
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 4b424fac95..23425790e1 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -620,14 +620,6 @@ void recalculate_cpuid_policy(struct domain *d)
             __clear_bit(X86_FEATURE_SYSCALL, max_fs);
     }
 
-    /*
-     * ITSC is masked by default (so domains are safe to migrate), but a
-     * toolstack which has configured disable_migrate or vTSC for a domain may
-     * safely select it, and needs a way of doing so.
-     */
-    if ( cpu_has_itsc && (d->disable_migrate || d->arch.vtsc) )
-        __set_bit(X86_FEATURE_ITSC, max_fs);
-
     /*
      * On hardware with MSR_TSX_CTRL, the admin may have elected to disable
      * TSX and hide the feature bits.  Migrating-in VMs may have been booted
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 505e54ebd7..8938c0f435 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2448,8 +2448,6 @@ int tsc_set_info(struct domain *d,
         }
     }
 
-    recalculate_cpuid_policy(d);
-
     return 0;
 }
 
diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h
index fc733e64f6..abd18722ee 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -246,7 +246,7 @@ XEN_CPUFEATURE(MOVDIR64B,     6*32+28) /*a  MOVDIR64B instruction */
 XEN_CPUFEATURE(ENQCMD,        6*32+29) /*   ENQCMD{,S} instructions */
 
 /* AMD-defined CPU features, CPUID level 0x80000007.edx, word 7 */
-XEN_CPUFEATURE(ITSC,          7*32+ 8) /*   Invariant TSC */
+XEN_CPUFEATURE(ITSC,          7*32+ 8) /*a  Invariant TSC */
 XEN_CPUFEATURE(EFRO,          7*32+10) /*   APERF/MPERF Read Only interface */
 
 /* AMD-defined CPU features, CPUID level 0x80000008.ebx, word 8 */
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMPs-0007bI-Qp; Fri, 18 Sep 2020 19:51:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMPs-0007bB-2K
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:32 +0000
X-Inumbo-ID: b2bb9418-462a-4514-92be-2d9672ed12f0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b2bb9418-462a-4514-92be-2d9672ed12f0;
 Fri, 18 Sep 2020 19:51:31 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=AxNqtThaqdXVppZGygL1ETDjxQt6NZCESPXFTuASNek=; b=ovB6zWnZvYemgPAWfqajekDyjg
 HYrx8NVa+Woa19iEjNSb8JqlWWVH2nXxPMb74lBHdHPAQDiCB73Dt2kv/UXVF2WHOAgYWI4j09joU
 lLn/me4L1T5Ra27OeBy27++o8IzcKL0fPupGDhMd3pHxg22JktJfjitrxqi2IzsvY2A8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPr-0007HM-4g
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:31 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMPr-0004mi-3D
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:31 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libs/stat: fix broken build
Message-Id: <E1kJMPr-0004mi-3D@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:31 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c8099e48c3dbb8c7399551a265756ecf354eece2
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sat Sep 12 15:08:36 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:48:08 2020 +0000

    tools/libs/stat: fix broken build
    
    Making getBridge() static triggered a build error with some gcc versions:
    
    error: 'strncpy' output may be truncated copying 15 bytes from a string of
    length 255 [-Werror=stringop-truncation]
    
    Fix that by using a buffer with 256 bytes instead.
    
    Fixes: 6d0ec053907794 ("tools: split libxenstat into new tools/libs/stat directory")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/stat/xenstat_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index 793263f2b6..d2ee6fda64 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -78,7 +78,7 @@ static void getBridge(char *excludeName, char *result, size_t resultLen)
 				sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
 
 				if (access(tmp, F_OK) == 0) {
-					strncpy(result, de->d_name, resultLen - 1);
+					strncpy(result, de->d_name, resultLen);
 					result[resultLen - 1] = 0;
 				}
 		}
@@ -264,7 +264,7 @@ int xenstat_collect_networks(xenstat_node * node)
 {
 	/* Helper variables for parseNetDevLine() function defined above */
 	int i;
-	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
+	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
 	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
 
 	struct priv_data *priv = get_priv_data(node->handle);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:42 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:42 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQ2-0007cT-SO; Fri, 18 Sep 2020 19:51:42 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQ2-0007cK-0L
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:42 +0000
X-Inumbo-ID: 083297fe-c21f-4c5e-b343-31862e9ebe20
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 083297fe-c21f-4c5e-b343-31862e9ebe20;
 Fri, 18 Sep 2020 19:51:41 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=W0JNB8qaTNUDJjm1dPdxOsrrIaConJ3XVOO9Ss+DCt8=; b=iimb/47JLRfHj83+c7tMnjsguW
 CTfqxRtWKr8nKxlLEGOqs4vzaLS3S0A4G9VF/vKSaE/uG1zP9zYLJEZ8EX5OByEh7ZkDwplYetuCI
 YLPc9uVmd22qs1ARLYdVyuIwt6lfDVZCnXGkb79hMO4pbt6bQp15rzGM5Ay3WaNfyC7U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQ1-0007HT-7v
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:41 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQ1-0004nK-76
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:41 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/build: fix python xc bindings
Message-Id: <E1kJMQ1-0004nK-76@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:41 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ed7cbd55040fde693ab721d643e829f7218d51e1
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Sat Sep 12 15:58:07 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:48:26 2020 +0000

    tools/build: fix python xc bindings
    
    Commit 7c273ffdd0e91 ("tools/python: drop libxenguest from setup.py")
    was just wrong: there is one function from libxenguest used in the
    bindings, so readd the library again.
    
    While at it remove the unused PATH_LIBXL setting.
    
    Fixes: 7c273ffdd0e91 ("tools/python: drop libxenguest from setup.py")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
    Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/python/setup.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/python/setup.py b/tools/python/setup.py
index 8254464aff..1afe800479 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -10,7 +10,7 @@ PATH_XEN      = XEN_ROOT + "/tools/include"
 PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
 PATH_LIBXENEVTCHN = XEN_ROOT + "/tools/libs/evtchn"
 PATH_LIBXENCTRL = XEN_ROOT + "/tools/libs/ctrl"
-PATH_LIBXL    = XEN_ROOT + "/tools/libxl"
+PATH_LIBXENGUEST = XEN_ROOT + "/tools/libs/guest"
 PATH_XENSTORE = XEN_ROOT + "/tools/libs/store"
 
 xc = Extension("xc",
@@ -19,10 +19,11 @@ xc = Extension("xc",
                                       PATH_LIBXENTOOLLOG + "/include",
                                       PATH_LIBXENEVTCHN + "/include",
                                       PATH_LIBXENCTRL + "/include",
+                                      PATH_LIBXENGUEST + "/include",
                                       "xen/lowlevel/xc" ],
-               library_dirs       = [ PATH_LIBXENCTRL ],
-               libraries          = [ "xenctrl" ],
-               depends            = [ PATH_LIBXENCTRL + "/libxenctrl.so" ],
+               library_dirs       = [ PATH_LIBXENCTRL, PATH_LIBXENGUEST ],
+               libraries          = [ "xenctrl", "xenguest" ],
+               depends            = [ PATH_LIBXENCTRL + "/libxenctrl.so", PATH_LIBXENGUEST + "/libxenguest.so" ],
                extra_link_args    = [ "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:51:52 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:51:52 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQC-0007dR-U1; Fri, 18 Sep 2020 19:51:52 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQC-0007dL-3s
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:52 +0000
X-Inumbo-ID: 83b7f13f-08db-41fa-9f42-8074a5ac2593
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 83b7f13f-08db-41fa-9f42-8074a5ac2593;
 Fri, 18 Sep 2020 19:51:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=BD4GjyNSKGymNSx0P1uxVQh73C7XoFnpxMynm2da3cc=; b=gYQ9l3OAvhBjXQuY8c8iN78EP1
 fwtQDq5CeKr0JE43jLi1itRavVXxgQVQ0sdPovfCuIUJAgBKkXXINtJUIs79Rehq0j3YxZpddQk+H
 vy9OVvDbGXclA1dnKkEidc7zCJxCyf7ll4umdU8T7ii9VojAY7brv5o9YwZpqMGI3Qm0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQB-0007Hd-Ax
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:51 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQB-0004nq-A7
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:51:51 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/libs/vchan: Don't run the headers check
Message-Id: <E1kJMQB-0004nq-A7@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:51:51 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4f9a6165604b89da592860d9821b920eed79f5a2
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 10:24:19 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:49:15 2020 +0000

    tools/libs/vchan: Don't run the headers check
    
    There was never a headers check previously, and CentOS 6 can't cope with the
    anonymous union in struct libxenvchan.
    
      cc1: warnings being treated as errors
      ... tools/include/libxenvchan.h:75: error: declaration does not declare anything
      make[6]: *** [headers.chk] Error 1
    
    Fixes: 8ab2429f12 ("tools: split libxenvchan into new tools/libs/vchan directory")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/vchan/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libs/vchan/Makefile b/tools/libs/vchan/Makefile
index 87ff608f45..5e18d5b196 100644
--- a/tools/libs/vchan/Makefile
+++ b/tools/libs/vchan/Makefile
@@ -8,6 +8,8 @@ LIBHEADER := libxenvchan.h
 SRCS-y += init.c
 SRCS-y += io.c
 
+NO_HEADERS_CHK := y
+
 include $(XEN_ROOT)/tools/libs/libs.mk
 
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_libxenvchan)/include
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:04 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:04 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQN-0007f4-Vg; Fri, 18 Sep 2020 19:52:03 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQM-0007ex-Bu
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:02 +0000
X-Inumbo-ID: 4656d86c-cede-4e5d-91b5-eb42f31adb0d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4656d86c-cede-4e5d-91b5-eb42f31adb0d;
 Fri, 18 Sep 2020 19:52:01 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ouaf8Xpp7QZVT4YAWArFSErDcqG7TZgQwAw9p3eM5Ps=; b=ZT0DmfIdzYpcCEt06srpSpCO1+
 MMeymI8J5c+9Dt7Pv6DvFlXZZ73yyKWadL5R6zifiaYSdVjDo0/epTSjliqf+euwFtymGDCA480BJ
 fWqWVcnMV2edK2XmNAkvd37Hj5PTKIGVS2fb+tMYXLoYiXFRf24a01VjAKBeO1475FL0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQL-0007Hv-Dv
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:01 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQL-0004oP-D8
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:01 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools/Makefile: Drop the use of $(file ...)
Message-Id: <E1kJMQL-0004oP-D8@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:01 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d16467b18e0c0a77743c3111bed2a833a77fbfe7
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 10:24:20 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Mon Sep 14 09:49:18 2020 +0000

    tools/Makefile: Drop the use of $(file ...)
    
    It is only available in make 4.0 and later, and not for example in CentOS 7.
    
    Rewrite the logic to use echo and shell redirection, using a single capture
    group to avoid having 12 different processes in quick succession each
    appending one line to the file.
    
    Fixes: 52dbd6f07cea7a ("tools: generate pkg-config files from make variables")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Rules.mk | 52 ++++++++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 4fd91fa444..a71abb2e4f 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -186,29 +186,33 @@ $(PKG_CONFIG_DIR):
 	mkdir -p $(PKG_CONFIG_DIR)
 
 $(PKG_CONFIG_DIR)/%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk $(PKG_CONFIG_DIR)
-	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
-	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
-	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
-	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
-	$(file >>$@,)
-	$(file >>$@,Name: $(PKG_CONFIG_NAME))
-	$(file >>$@,Description: $(PKG_CONFIG_DESC))
-	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
-	$(file >>$@,Cflags: -I$${includedir} $(CFLAGS_xeninclude))
-	$(file >>$@,Libs: -L$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB))
-	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
-	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+	{ \
+	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
+	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
+	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
+	$(foreach var,$(PKG_CONFIG_VARS),echo $(var);) \
+	echo ""; \
+	echo "Name: $(PKG_CONFIG_NAME)"; \
+	echo "Description: $(PKG_CONFIG_DESC)"; \
+	echo "Version: $(PKG_CONFIG_VERSION)"; \
+	echo "Cflags: -I\$${includedir} $(CFLAGS_xeninclude)"; \
+	echo "Libs: -L\$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB)"; \
+	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
+	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
+	} > $@
 
 %.pc: Makefile $(XEN_ROOT)/tools/Rules.mk
-	$(file >$@,prefix=$(PKG_CONFIG_PREFIX))
-	$(file >>$@,includedir=$(PKG_CONFIG_INCDIR))
-	$(file >>$@,libdir=$(PKG_CONFIG_LIBDIR))
-	$(foreach var,$(PKG_CONFIG_VARS),$(file >>$@,$(var)))
-	$(file >>$@,)
-	$(file >>$@,Name: $(PKG_CONFIG_NAME))
-	$(file >>$@,Description: $(PKG_CONFIG_DESC))
-	$(file >>$@,Version: $(PKG_CONFIG_VERSION))
-	$(file >>$@,Cflags: -I$${includedir})
-	$(file >>$@,Libs: -L$${libdir} -l$(PKG_CONFIG_LIB))
-	$(file >>$@,Libs.private: $(PKG_CONFIG_LIBSPRIV))
-	$(file >>$@,Requires.private: $(PKG_CONFIG_REQPRIV))
+	{ \
+	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
+	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
+	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
+	$(foreach var,$(PKG_CONFIG_VARS),echo $(var);) \
+	echo ""; \
+	echo "Name: $(PKG_CONFIG_NAME)"; \
+	echo "Description: $(PKG_CONFIG_DESC)"; \
+	echo "Version: $(PKG_CONFIG_VERSION)"; \
+	echo "Cflags: -I\$${includedir}"; \
+	echo "Libs: -L\$${libdir} -l$(PKG_CONFIG_LIB)"; \
+	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
+	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
+	} > $@
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQY-0007g8-1I; Fri, 18 Sep 2020 19:52:14 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQW-0007fz-AY
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:12 +0000
X-Inumbo-ID: b1f3371d-0656-4769-a575-4c7aab3967ce
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b1f3371d-0656-4769-a575-4c7aab3967ce;
 Fri, 18 Sep 2020 19:52:11 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wmIENdHg3Kpcc6R7ab1qgzKFZFLMJVa+UmNpdz698+E=; b=tzb0cnoxHXDRKcD2o66ZMc2j5l
 kkgh9CBDLbB9g9OS4xA6R9pRJ6ji4QLIDfTv/TafY7YHE1OuKiLutZs8FU9J/Nj6s863P+DTpWonj
 N/K0nPeduHaAJVndF2v3zxzs1/u+VTeKa9h6DMSLgpR5IKr+0moBhX9m9btF42siKqa8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQV-0007In-H1
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:11 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQV-0004p8-GI
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:11 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] travis: Fix build with newer Qemu
Message-Id: <E1kJMQV-0004p8-GI@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:11 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fc4e79c3f77f4360064f3614e32557a105458bae
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Sep 14 14:21:01 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Mon Sep 14 16:37:30 2020 +0100

    travis: Fix build with newer Qemu
    
    Qemu requires a bleeding edge version of Python, not found in the current
    travis environment.  Skip building Qemu in that case.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 scripts/travis-build | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/travis-build b/scripts/travis-build
index 0cb15a89e4..84d74266a0 100755
--- a/scripts/travis-build
+++ b/scripts/travis-build
@@ -16,6 +16,11 @@ cfgargs+=("--disable-rombios")
 cfgargs+=("--enable-docs")
 cfgargs+=("--with-system-seabios=/usr/share/seabios/bios.bin")
 
+# Qemu requires Python 3.5 or later
+if ! type python3 || python3 -c "import sys; res = sys.version_info < (3, 5); exit(not(res))"; then
+    cfgargs+=("--with-system-qemu=/bin/false")
+fi
+
 if [[ "${XEN_TARGET_ARCH}" == "x86_64" ]]; then
     cfgargs+=("--enable-tools")
 else
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:24 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQi-0007hA-2s; Fri, 18 Sep 2020 19:52:24 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQg-0007h0-Su
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:22 +0000
X-Inumbo-ID: 68b9f850-ab8a-4687-8011-50bb264c87d1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 68b9f850-ab8a-4687-8011-50bb264c87d1;
 Fri, 18 Sep 2020 19:52:21 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=D9DJTqsp5+zpDK99vCSORFvi5oqWsgvNl3DYy+WUaMM=; b=TMWBmztE/kyPbk0eshyjT1yo3B
 S8pBXSg9wVXALHrL4PJCHzHt1IPOdAtPJgS2dYfm5EDi+CMOhjf8Vxhp3Vs1OvUTdfHk3nd2xDWul
 /Y5+mqmNEEC6dkOgxXAD0tvBZ82Ml9ZCjddOg8n0UHO39uRp2UgEh++FIPyEF5Y+EQzI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQf-0007Iz-KM
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:21 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQf-0004pi-Jf
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:21 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/HVM: more consistently set I/O completion
Message-Id: <E1kJMQf-0004pi-Jf@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:21 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b807cfe954b8d0d8852398b4c8a586d95d69a342
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 15 10:19:33 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:19:33 2020 +0200

    x86/HVM: more consistently set I/O completion
    
    Doing this just in hvm_emulate_one_insn() is not enough.
    hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
    insns requiring one or more continuations, and at least in principle
    hvm_emulate_one_mmio() could, too. Without proper setting of the field,
    handle_hvm_io_completion() will do nothing completion-wise, and in
    particular the missing re-invocation of the insn emulation paths will
    lead to emulation caching not getting disabled in due course, causing
    the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
    
    Reported-by: Don Slutz <don.slutz@gmail.com>
    
    Similar considerations go for the clearing of vio->mmio_access, which
    gets moved as well.
    
    Additionally all updating of vio->mmio_* now gets done dependent upon
    the new completion value, rather than hvm_ioreq_needs_completion()'s
    return value. This is because it is the completion chosen which controls
    what path will be taken when handling the completion, not the simple
    boolean return value. In particular, PIO completion doesn't involve
    going through the insn emulator, and hence emulator state ought to get
    cleared early (or it won't get cleared at all).
    
    The new logic, besides allowing for a caller override for the
    continuation type to be set (for VMX real mode emulation), will also
    avoid setting an MMIO completion when a simpler PIO one will do. This
    is a minor optimization only as a side effect - the behavior is strictly
    needed at least for hvm_ud_intercept(), as only memory accesses can
    successfully complete through handle_mmio(). Care of course needs to be
    taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
    the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
    whether the insn being emulated is a memory access, as this information
    is no longer easily available at the point where we want to consume it.
    
    Note that the presence of non-NULL .validate fields in the two ops
    structures in hvm_emulate_one_mmio() was really necessary even before
    the changes here: Without this, passing non-NULL as middle argument to
    hvm_emulate_init_once() is meaningless.
    
    The restrictions on when the #UD intercept gets actually enabled are why
    it was decided that this is not a security issue:
    - the "hvm_fep" option to enable its use is a debugging option only,
    - for the cross-vendor case is considered experimental, even if
      unfortunately SUPPORT.md doesn't have an explicit statement about
      this.
    The other two affected functions are
    - hvm_emulate_one_vm_event(), used for introspection,
    - hvm_emulate_one_mmio(), used for Dom0 only,
    which aren't qualifying this as needing an XSA either.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Don Slutz <don.slutz@gmail.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/emulate.c        | 51 ++++++++++++++++++++++++++++++---------
 xen/arch/x86/hvm/hvm.c            |  2 +-
 xen/arch/x86/hvm/io.c             | 11 +--------
 xen/arch/x86/hvm/vmx/realmode.c   |  6 +----
 xen/include/asm-x86/hvm/emulate.h |  5 +++-
 5 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 8b4e73ab06..24cf85fb4f 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1683,9 +1683,11 @@ static int hvmemul_validate(
     const struct x86_emulate_state *state,
     struct x86_emulate_ctxt *ctxt)
 {
-    const struct hvm_emulate_ctxt *hvmemul_ctxt =
+    struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
 
+    hvmemul_ctxt->is_mem_access = x86_insn_is_mem_access(state, ctxt);
+
     return !hvmemul_ctxt->validate || hvmemul_ctxt->validate(state, ctxt)
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
 }
@@ -2610,8 +2612,14 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
     .vmfunc        = hvmemul_vmfunc,
 };
 
+/*
+ * Note that passing HVMIO_no_completion into this function serves as kind
+ * of (but not fully) an "auto select completion" indicator.  When there's
+ * no completion needed, the passed in value will be ignored in any case.
+ */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
-    const struct x86_emulate_ops *ops)
+    const struct x86_emulate_ops *ops,
+    enum hvm_io_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
@@ -2642,16 +2650,31 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
         rc = X86EMUL_RETRY;
 
     if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+        completion = HVMIO_no_completion;
+    else if ( completion == HVMIO_no_completion )
+        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
+                                                   : HVMIO_pio_completion;
+
+    switch ( vio->io_completion = completion )
     {
+    case HVMIO_no_completion:
+    case HVMIO_pio_completion:
         vio->mmio_cache_count = 0;
         vio->mmio_insn_bytes = 0;
+        vio->mmio_access = (struct npfec){};
         hvmemul_cache_disable(curr);
-    }
-    else
-    {
+        break;
+
+    case HVMIO_mmio_completion:
+    case HVMIO_realmode_completion:
         BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
         vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
         memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
     }
 
     if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2692,9 +2715,10 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 }
 
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt)
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion)
 {
-    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops);
+    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
 
 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
@@ -2703,11 +2727,13 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmcfg_intercept_write,
+        .validate   = hvmemul_validate,
     };
     static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = {
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmio_ro_emulated_write,
+        .validate   = hvmemul_validate,
     };
     struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla };
     struct hvm_emulate_ctxt ctxt;
@@ -2727,8 +2753,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
     hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write,
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
-    rc = _hvm_emulate_one(&ctxt, ops);
-    switch ( rc )
+
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2755,7 +2781,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     switch ( kind )
     {
     case EMUL_KIND_NOWRITE:
-        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write);
+        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
+                              HVMIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
@@ -2776,7 +2803,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx);
+        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
     }
 
     switch ( rc )
@@ -2874,6 +2901,8 @@ void hvm_emulate_init_per_insn(
                                         pfec, NULL) == HVMTRANS_okay) ?
             sizeof(hvmemul_ctxt->insn_buf) : 0;
     }
+
+    hvmemul_ctxt->is_mem_access = false;
 }
 
 void hvm_emulate_writeback(
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index a9d1685549..32719b6d01 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3798,7 +3798,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt) )
+    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 724ab44a76..3e09d9b726 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -81,20 +81,11 @@ void send_invalidate_req(void)
 bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 {
     struct hvm_emulate_ctxt ctxt;
-    struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    rc = hvm_emulate_one(&ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_mmio_completion;
-    else
-        vio->mmio_access = (struct npfec){};
-
-    switch ( rc )
+    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c
index bdbd9cb921..768f01eb04 100644
--- a/xen/arch/x86/hvm/vmx/realmode.c
+++ b/xen/arch/x86/hvm/vmx/realmode.c
@@ -97,15 +97,11 @@ static void realmode_deliver_exception(
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_realmode_completion;
+    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
diff --git a/xen/include/asm-x86/hvm/emulate.h b/xen/include/asm-x86/hvm/emulate.h
index f40290945c..1620cc7b7a 100644
--- a/xen/include/asm-x86/hvm/emulate.h
+++ b/xen/include/asm-x86/hvm/emulate.h
@@ -48,6 +48,8 @@ struct hvm_emulate_ctxt {
 
     uint32_t intr_shadow;
 
+    bool is_mem_access;
+
     bool_t set_context;
 };
 
@@ -62,7 +64,8 @@ bool __nonnull(1, 2) hvm_emulate_one_insn(
     hvm_emulate_validate_t *validate,
     const char *descr);
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt);
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:34 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:34 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMQs-0007iJ-66; Fri, 18 Sep 2020 19:52:34 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMQq-0007i7-Q9
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:32 +0000
X-Inumbo-ID: 9b8ca0e3-0f91-4afb-b31c-373aef7e7db7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9b8ca0e3-0f91-4afb-b31c-373aef7e7db7;
 Fri, 18 Sep 2020 19:52:31 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wVXMHAaqGih0s7DfYcOsbg6XNj/26kJaFjeE2UFVG7c=; b=WtbOkq0jBueyhICUoaVXR9cluX
 oRf0Vf6caNTV78Ou9U9nmVodV5vmq7hbQX0EJABNHZOJbzGGPLeYALTSyj2h7KdiV7UiXuhlP45RL
 SapWeOKdqICrAcv0Yaf5KJsblyLKSAEAqVKjRZ1u03d6tt/gfZM9+YjEqmq88C/UfSso=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQp-0007J9-NH
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:31 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQp-0004qL-Mh
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:31 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] EFI: free unused boot mem in at least some cases
Message-Id: <E1kJMQp-0004qL-Mh@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:31 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a4cbe0f3b47656ea125922fd48d394731a0163fd
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 15 10:20:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:20:37 2020 +0200

    EFI: free unused boot mem in at least some cases
    
    Address at least the primary reason why 52bba67f8b87 ("efi/boot: Don't
    free ebmalloc area at all") was put in place: Make xen_in_range() aware
    of the freed range. This is in particular relevant for EFI-enabled
    builds not actually running on EFI, as the entire range will be unused
    in this case.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/efi/stub.c   |  6 ++++++
 xen/arch/x86/setup.c      | 26 +++++++++++++++++++++++---
 xen/arch/x86/tboot.c      | 12 ++++++++++++
 xen/common/efi/ebmalloc.c | 31 ++++++++++++++++++++++++++-----
 xen/include/xen/efi.h     |  1 +
 5 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index c578bffc71..0e01e7322b 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -52,6 +52,12 @@ bool efi_enabled(unsigned int feature)
 
 void __init efi_init_memory(void) { }
 
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
+{
+    *start = *end = (unsigned long)_end;
+    return false;
+}
+
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
 
 bool efi_rs_using_pgtables(void)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 4b15e067fa..44c04e2735 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -830,6 +830,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
     int i, j, e820_warn = 0, bytes = 0;
+    unsigned long eb_start, eb_end;
     bool acpi_boot_table_init_done = false, relocated = false;
     int ret;
     struct ns16550_defaults ns16550 = {
@@ -1145,7 +1146,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
         /*
          * This needs to remain in sync with xen_in_range() and the
-         * respective reserve_e820_ram() invocation below.
+         * respective reserve_e820_ram() invocation below. No need to
+         * query efi_boot_mem_unused() here, though.
          */
         mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
@@ -1417,8 +1419,18 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen\n");
 
+    /* FIXME: Putting a hole in .bss would shatter the large page mapping. */
+    if ( using_2M_mapping() )
+        efi_boot_mem_unused(NULL, NULL);
+
     /* This needs to remain in sync with xen_in_range(). */
-    reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
+    if ( efi_boot_mem_unused(&eb_start, &eb_end) )
+    {
+        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start));
+        reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end));
+    }
+    else
+        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1979,7 +1991,7 @@ int __hwdom_init xen_in_range(unsigned long mfn)
     paddr_t start, end;
     int i;
 
-    enum { region_s3, region_ro, region_rw, nr_regions };
+    enum { region_s3, region_ro, region_rw, region_bss, nr_regions };
     static struct {
         paddr_t s, e;
     } xen_regions[nr_regions] __hwdom_initdata;
@@ -2004,6 +2016,14 @@ int __hwdom_init xen_in_range(unsigned long mfn)
         /* hypervisor .data + .bss */
         xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
         xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
+        if ( efi_boot_mem_unused(&start, &end) )
+        {
+            ASSERT(__pa(start) >= xen_regions[region_rw].s);
+            ASSERT(__pa(end) <= xen_regions[region_rw].e);
+            xen_regions[region_rw].e = __pa(start);
+            xen_regions[region_bss].s = __pa(end);
+            xen_regions[region_bss].e = __pa(&__2M_rwdata_end);
+        }
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index e66b0940c4..aadcce591f 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -1,3 +1,4 @@
+#include <xen/efi.h>
 #include <xen/init.h>
 #include <xen/types.h>
 #include <xen/lib.h>
@@ -364,6 +365,8 @@ void tboot_shutdown(uint32_t shutdown_type)
     /* if this is S3 then set regions to MAC */
     if ( shutdown_type == TB_SHUTDOWN_S3 )
     {
+        unsigned long s, e;
+
         /*
          * Xen regions for tboot to MAC. This needs to remain in sync with
          * xen_in_range().
@@ -378,6 +381,15 @@ void tboot_shutdown(uint32_t shutdown_type)
         /* hypervisor .data + .bss */
         g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(&__2M_rwdata_start);
         g_tboot_shared->mac_regions[2].size = __2M_rwdata_end - __2M_rwdata_start;
+        if ( efi_boot_mem_unused(&s, &e) )
+        {
+            g_tboot_shared->mac_regions[2].size =
+                s - (unsigned long)__2M_rwdata_start;
+            g_tboot_shared->mac_regions[3].start = __pa(e);
+            g_tboot_shared->mac_regions[3].size =
+                (unsigned long)__2M_rwdata_end - e;
+            g_tboot_shared->num_mac_regions = 4;
+        }
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/common/efi/ebmalloc.c b/xen/common/efi/ebmalloc.c
index c65dbd946f..136838eb8e 100644
--- a/xen/common/efi/ebmalloc.c
+++ b/xen/common/efi/ebmalloc.c
@@ -1,5 +1,6 @@
 #include "efi.h"
 #include <xen/init.h>
+#include <xen/mm.h>
 
 #ifdef CONFIG_ARM
 /*
@@ -21,7 +22,7 @@
 
 static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
     ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __initdata ebmalloc_allocated;
+static unsigned long __read_mostly ebmalloc_allocated;
 
 /* EFI boot allocator. */
 void __init *ebmalloc(size_t size)
@@ -36,17 +37,37 @@ void __init *ebmalloc(size_t size)
     return ptr;
 }
 
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
+{
+    if ( !start && !end )
+    {
+        ebmalloc_allocated = sizeof(ebmalloc_mem);
+        return false;
+    }
+
+    *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
+    *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    return *start < *end;
+}
+
 void __init free_ebmalloc_unused_mem(void)
 {
-#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
     unsigned long start, end;
 
-    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
-    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+    if ( !efi_boot_mem_unused(&start, &end) )
+        return;
 
     destroy_xen_mappings(start, end);
+
+#ifdef CONFIG_X86
+    /*
+     * By reserving the space early in the E820 map, it gets freed way before
+     * we make it here. Don't free the range a 2nd time.
+     */
+#else
     init_xenheap_pages(__pa(start), __pa(end));
+#endif
 
     printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
-#endif
 }
diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h
index 44b7d3ec3a..94a7e547f9 100644
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -33,6 +33,7 @@ struct compat_pf_efi_runtime_call;
 
 bool efi_enabled(unsigned int feature);
 void efi_init_memory(void);
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end);
 bool efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
 void efi_halt_system(void);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:44 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMR2-0007jJ-7g; Fri, 18 Sep 2020 19:52:44 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMR0-0007j8-Vp
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:43 +0000
X-Inumbo-ID: 430a4290-911f-4736-b408-8f3343348c09
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 430a4290-911f-4736-b408-8f3343348c09;
 Fri, 18 Sep 2020 19:52:42 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=OmMEktuF2Si05k7CzSmsxmSuE4v9gkqkeWQrGjaeaGE=; b=5PhQOLWBuvsiYwkK55LTMsKO25
 yBI7Mop1jWgt1Cf4A3DLn3dA/PLraAs9OWDU0R7E33WwyE6bNLeqOFg+EmGQzQChEUA6wVIqLEmi4
 VdP6O/F8W13fdb4Cu+GgdHZUSBQGwbQvOsh6K+eN0VtqV4QzPhihWiQe2XqkdEKx+fgc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQz-0007JJ-QP
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:41 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMQz-0004qp-Pj
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:41 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: allow reading FEATURE_CONTROL MSR
Message-Id: <E1kJMQz-0004qp-Pj@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:41 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 39ab598c50a2b539f376adc363d684c2df6c8dd7
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 10:21:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 10:21:09 2020 +0200

    x86/pv: allow reading FEATURE_CONTROL MSR
    
    Linux PV guests will attempt to read the FEATURE_CONTROL MSR, so move
    the handling done in VMX code into guest_rdmsr as it can be shared
    between PV and HVM guests that way.
    
    Note that there's a slight behavior change and attempting to read the
    MSR when no features are available will result in a fault.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c |  8 +-------
 xen/arch/x86/msr.c         | 12 ++++++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index c4b40bf3cb..709ea149d1 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     case MSR_IA32_DEBUGCTLMSR:
         __vmread(GUEST_IA32_DEBUGCTL, msr_content);
         break;
-    case MSR_IA32_FEATURE_CONTROL:
-        *msr_content = IA32_FEATURE_CONTROL_LOCK;
-        if ( vmce_has_lmce(curr) )
-            *msr_content |= IA32_FEATURE_CONTROL_LMCE_ON;
-        if ( nestedhvm_enabled(curr->domain) )
-            *msr_content |= IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX;
-        break;
+
     case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:
         if ( !nvmx_msr_read_intercept(msr, msr_content) )
             goto gp_fault;
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 74bf7d9589..79fbb9e940 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -25,6 +25,7 @@
 #include <xen/sched.h>
 
 #include <asm/debugreg.h>
+#include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/viridian.h>
 #include <asm/msr.h>
 #include <asm/setup.h>
@@ -197,6 +198,17 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
         /* Not offered to guests. */
         goto gp_fault;
 
+    case MSR_IA32_FEATURE_CONTROL:
+        if ( !cp->basic.vmx && !vmce_has_lmce(v) )
+            goto gp_fault;
+
+        *val = IA32_FEATURE_CONTROL_LOCK;
+        if ( vmce_has_lmce(v) )
+            *val |= IA32_FEATURE_CONTROL_LMCE_ON;
+        if ( cp->basic.vmx )
+            *val |= IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX;
+        break;
+
     case MSR_IA32_PLATFORM_ID:
         if ( !(cp->x86_vendor & X86_VENDOR_INTEL) ||
              !(boot_cpu_data.x86_vendor & X86_VENDOR_INTEL) )
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:52:54 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:52:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMRC-0007kk-9H; Fri, 18 Sep 2020 19:52:54 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMRA-0007kA-Rn
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:52 +0000
X-Inumbo-ID: 9d586408-63d2-48bc-b0e7-722d3c28c093
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9d586408-63d2-48bc-b0e7-722d3c28c093;
 Fri, 18 Sep 2020 19:52:52 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=geWT6COSppUJ1/dqCPw5PX8NcPubstekyHZ2nBIBVg0=; b=NB22OydNLmF/KceDcJuQZ4bt91
 8ox5ab+V5SjJEB+4dONXpiva3gMEXxytQeurh6kvwgsXMv4wh0dJNTgGo0vIS549KPJja0AToEqb+
 8tnpb9JDFXyq9SELgorwJnZTarjyYJsMtm2LG7s0mIkWEgzPJzYgCotwRqBxdob12GgQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMR9-0007JP-Td
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:51 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMR9-0004rZ-So
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:52:51 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/svm: handle BU_CFG and BU_CFG2 with cases
Message-Id: <E1kJMR9-0004rZ-So@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:52:51 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8a31c255afab71f30f0fa1f8c7cef309aa2ec483
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 12:42:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:42:21 2020 +0200

    x86/svm: handle BU_CFG and BU_CFG2 with cases
    
    Move the special handling of reads to it's own switch case, and also
    add support for BU_CFG2. On the write side ignore writes if the MSR is
    readable, otherwise return a #GP.
    
    This is in preparation for changing the default MSR read/write
    behavior, which will instead return #GP on not explicitly handled
    cases.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 23b2a2aa17..e14c0cce30 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1861,6 +1861,30 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         *msr_content = 1ULL << 61; /* MC4_MISC.Locked */
         break;
 
+    case MSR_F10_BU_CFG:
+        if ( !rdmsr_safe(msr, *msr_content) )
+            break;
+
+        if ( boot_cpu_data.x86 == 0xf )
+        {
+            /*
+             * Win2k8 x64 reads this MSR on revF chips, where it wasn't
+             * publically available; it uses a magic constant in %rdi as a
+             * password, which we don't have in rdmsr_safe().  Since we'll
+             * throw a #GP for later writes, just use a plausible value here
+             * (the reset value from rev10h chips) if the real CPU didn't
+             * provide one.
+             */
+            *msr_content = 0x10200020;
+            break;
+        }
+        goto gpf;
+
+    case MSR_F10_BU_CFG2:
+        if ( rdmsr_safe(msr, *msr_content) )
+            goto gpf;
+        break;
+
     case MSR_IA32_EBC_FREQUENCY_ID:
         /*
          * This Intel-only register may be accessed if this HVM guest
@@ -1939,19 +1963,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     default:
         if ( rdmsr_safe(msr, *msr_content) == 0 )
             break;
-
-        if ( boot_cpu_data.x86 == 0xf && msr == MSR_F10_BU_CFG )
-        {
-            /* Win2k8 x64 reads this MSR on revF chips, where it
-             * wasn't publically available; it uses a magic constant
-             * in %rdi as a password, which we don't have in
-             * rdmsr_safe().  Since we'll ignore the later writes,
-             * just use a plausible value here (the reset value from
-             * rev10h chips) if the real CPU didn't provide one. */
-            *msr_content = 0x0000000010200020ull;
-            break;
-        }
-
         goto gpf;
     }
 
@@ -2107,6 +2118,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         nsvm->ns_msr_hsavepa = msr_content;
         break;
 
+    case MSR_F10_BU_CFG:
+    case MSR_F10_BU_CFG2:
+        if ( rdmsr_safe(msr, msr_content) )
+            goto gpf;
+        break;
+
     case MSR_AMD64_TSC_RATIO:
         if ( msr_content & TSC_RATIO_RSVD_BITS )
             goto gpf;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:53:04 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:53:04 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMRM-0007lp-At; Fri, 18 Sep 2020 19:53:04 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMRK-0007ld-PU
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:02 +0000
X-Inumbo-ID: d6e758f5-b999-41b7-8a30-be398b0fec07
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d6e758f5-b999-41b7-8a30-be398b0fec07;
 Fri, 18 Sep 2020 19:53:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Vsu+GBSZ7442WsR7dAHU9/4svIFqMtPeN4VGPItt28M=; b=jc+1zNxKCI+GnkiCI5iUladM3Q
 yeXOItlljqlEpOP5fEzEg4XQREVIy7T8uWH9PQrA9pZ01leyJMFQtjk4Vud4oeOxAV6plFkinCfGx
 NHcG+sQD9DXbAqBbU57w20hMTXla/AtsvUeWR/zs/PSjuPn3iwFdrCLvTRfsEqBIE684=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRK-0007Jm-0Z
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRJ-0004sA-Vx
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:01 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/pv: disallow access to unknown MSRs
Message-Id: <E1kJMRJ-0004sA-Vx@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:53:01 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 322ec7c89f6640ee2a99d1040b6f786cf04872cf
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 15 12:42:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:42:58 2020 +0200

    x86/pv: disallow access to unknown MSRs
    
    Change the catch-all behavior for MSR not explicitly handled. Instead
    of allow full read-access to the MSR space and silently dropping
    writes return an exception when the MSR is not explicitly handled.
    
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/pv/emul-priv-op.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index c6fbf8f92d..d793eed401 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -988,9 +988,10 @@ static int read_msr(unsigned int reg, uint64_t *val,
         }
         /* fall through */
     default:
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", reg);
+        break;
+
     normal:
-        /* Everyone can read the MSR space. */
-        /* gdprintk(XENLOG_WARNING, "Domain attempted RDMSR %08x\n", reg); */
         if ( rdmsr_safe(reg, *val) )
             break;
         return X86EMUL_OKAY;
@@ -1155,14 +1156,15 @@ static int write_msr(unsigned int reg, uint64_t val,
         }
         /* fall through */
     default:
-        if ( rdmsr_safe(reg, temp) )
-            break;
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 reg, val);
+        break;
 
-        if ( val != temp )
     invalid:
-            gdprintk(XENLOG_WARNING,
-                     "Domain attempted WRMSR %08x from 0x%016"PRIx64" to 0x%016"PRIx64"\n",
-                     reg, temp, val);
+        gdprintk(XENLOG_WARNING,
+                 "Domain attempted WRMSR 0x%08x from 0x%016"PRIx64" to 0x%016"PRIx64"\n",
+                 reg, temp, val);
         return X86EMUL_OKAY;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:53:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:53:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMRX-0007mr-CV; Fri, 18 Sep 2020 19:53:15 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMRV-0007mc-M0
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:13 +0000
X-Inumbo-ID: 4f99b46e-e3cb-42fa-a50d-1828ae0fac3b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4f99b46e-e3cb-42fa-a50d-1828ae0fac3b;
 Fri, 18 Sep 2020 19:53:12 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=pZVu83rUjYISNLW9NJ3SuSV+/nUwTWx0yzx2yOqVRBU=; b=Mwq/fg95L/p2u6r27cK1T5K2mz
 DsOcm6aqfHhI52jek25QtxApZ5hRkvcrnuvgOi+jr+47bPyuQPjT5FY46j6pmBNBB+00NoC0J8aCF
 SFGpmKJA+q76eD7U5LXdpqbH7hYgDUO0Udiai+glTi7xwHofLwbBLWuvTwAiyTZaA++g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRU-0007KO-Ms
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:12 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRU-0004st-3B
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/hvm: disallow access to unknown MSRs
Message-Id: <E1kJMRU-0004st-3B@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:53:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 84e848fd7a162f669cf8248ce502ca864f869447
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 15 12:43:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:43:32 2020 +0200

    x86/hvm: disallow access to unknown MSRs
    
    Change the catch-all behavior for MSR not explicitly handled. Instead
    of allow full read-access to the MSR space and silently dropping
    writes return an exception when the MSR is not explicitly handled.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    [remove rdmsr_safe from default case in svm_msr_read_intercept]
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/svm/svm.c | 10 ++++------
 xen/arch/x86/hvm/vmx/vmx.c | 16 ++++------------
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index e14c0cce30..136445972e 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1961,8 +1961,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         break;
 
     default:
-        if ( rdmsr_safe(msr, *msr_content) == 0 )
-            break;
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr);
         goto gpf;
     }
 
@@ -2147,10 +2146,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         break;
 
     default:
-        /* Match up with the RDMSR side; ultimately this should go away. */
-        if ( rdmsr_safe(msr, msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 msr, msr_content);
         goto gpf;
     }
 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 709ea149d1..a3aadce4d8 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3015,9 +3015,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
             break;
         }
 
-        if ( rdmsr_safe(msr, *msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING, "RDMSR 0x%08x unimplemented\n", msr);
         goto gp_fault;
     }
 
@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         __vmwrite(GUEST_IA32_DEBUGCTL, msr_content);
         break;
 
-    case MSR_IA32_FEATURE_CONTROL:
-    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
-        /* None of these MSRs are writeable. */
-        goto gp_fault;
-
     case MSR_IA32_MISC_ENABLE:
         /*
          * Silently drop writes that don't change the reported value: At least
@@ -3324,10 +3317,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
              is_last_branch_msr(msr) )
             break;
 
-        /* Match up with the RDMSR side; ultimately this should go away. */
-        if ( rdmsr_safe(msr, msr_content) == 0 )
-            break;
-
+        gdprintk(XENLOG_WARNING,
+                 "WRMSR 0x%08x val 0x%016"PRIx64" unimplemented\n",
+                 msr, msr_content);
         goto gp_fault;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:53:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:53:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMRh-0007o7-Fg; Fri, 18 Sep 2020 19:53:25 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMRf-0007nw-J5
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:23 +0000
X-Inumbo-ID: d172ea5f-65fb-434c-8579-7fa92b24abea
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d172ea5f-65fb-434c-8579-7fa92b24abea;
 Fri, 18 Sep 2020 19:53:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=SOZuwXKipEBtnRUWwCoNj3+pqfCrZulA2hDA+L6LhHU=; b=E/UiezYV65F3dmEhNeUXJYtDIl
 4/8zTmVBNXGNc4MJZ2f44YVbJeN/lNBtUfkhRnSS4jKzwVENosLSe/2DZfd6cmEmIQAsitIk85+N8
 38OYwvQ23ddV1VDT2AAO3UJ/Er3udjxnIkbU0r3M2FcXEA017MShjg+llBrjq5TQ6trQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRe-0007Kb-Pw
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:22 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRe-0004te-PJ
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:22 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/msr: drop compatibility #GP handling in guest_{rd,
 wr}msr()
Message-Id: <E1kJMRe-0004te-PJ@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:53:22 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 51526576219f122ec7ccfd55dea95afbca70d330
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 15 12:44:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 15 12:44:01 2020 +0200

    x86/msr: drop compatibility #GP handling in guest_{rd,wr}msr()
    
    Now that the main PV/HVM MSR handlers raise #GP for all unknown MSRs, there is
    no need to special case these MSRs any more.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msr.c | 46 ----------------------------------------------
 1 file changed, 46 deletions(-)

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 79fbb9e940..81b34fb212 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -175,29 +175,6 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
 
     switch ( msr )
     {
-    case MSR_AMD_PATCHLOADER:
-    case MSR_IA32_UCODE_WRITE:
-    case MSR_PRED_CMD:
-    case MSR_FLUSH_CMD:
-        /* Write-only */
-    case MSR_TEST_CTRL:
-    case MSR_CORE_CAPABILITIES:
-    case MSR_TSX_FORCE_ABORT:
-    case MSR_TSX_CTRL:
-    case MSR_MCU_OPT_CTRL:
-    case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7):
-    case MSR_U_CET:
-    case MSR_S_CET:
-    case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE:
-    case MSR_AMD64_LWP_CFG:
-    case MSR_AMD64_LWP_CBADDR:
-    case MSR_PPIN_CTL:
-    case MSR_PPIN:
-    case MSR_AMD_PPIN_CTL:
-    case MSR_AMD_PPIN:
-        /* Not offered to guests. */
-        goto gp_fault;
-
     case MSR_IA32_FEATURE_CONTROL:
         if ( !cp->basic.vmx && !vmce_has_lmce(v) )
             goto gp_fault;
@@ -364,29 +341,6 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
     {
         uint64_t rsvd;
 
-    case MSR_IA32_PLATFORM_ID:
-    case MSR_CORE_CAPABILITIES:
-    case MSR_INTEL_CORE_THREAD_COUNT:
-    case MSR_INTEL_PLATFORM_INFO:
-    case MSR_ARCH_CAPABILITIES:
-        /* Read-only */
-    case MSR_TEST_CTRL:
-    case MSR_TSX_FORCE_ABORT:
-    case MSR_TSX_CTRL:
-    case MSR_MCU_OPT_CTRL:
-    case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7):
-    case MSR_U_CET:
-    case MSR_S_CET:
-    case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE:
-    case MSR_AMD64_LWP_CFG:
-    case MSR_AMD64_LWP_CBADDR:
-    case MSR_PPIN_CTL:
-    case MSR_PPIN:
-    case MSR_AMD_PPIN_CTL:
-    case MSR_AMD_PPIN:
-        /* Not offered to guests. */
-        goto gp_fault;
-
     case MSR_AMD_PATCHLEVEL:
         BUILD_BUG_ON(MSR_IA32_UCODE_REV != MSR_AMD_PATCHLEVEL);
         /*
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:53:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:53:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMRr-0007p7-HJ; Fri, 18 Sep 2020 19:53:35 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMRq-0007ox-0j
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:34 +0000
X-Inumbo-ID: 15522f5f-2aa7-4cda-b880-5d58846d1e61
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 15522f5f-2aa7-4cda-b880-5d58846d1e61;
 Fri, 18 Sep 2020 19:53:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=CiJ5hZKtJ2pka5AwxvDX4xa65fNbwLTkzMZFWbJAi1g=; b=uxFixiUCSuKq8PN64NDzIHx1sM
 4l5emoa56SxtG2f53MEF5Xw62ySzLTuiRop330R3JFrE3lvdl6hkssW0o/HCBAyecOJLIsuRLqhmw
 XRTrDWS/Tq6OTW0v0j7BsyhnyIVGwR8uLFtNgE4TaBfPDP+UNsOTrlqjKiyHZbkc/F7U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRo-0007Kj-TE
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:32 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMRo-0004uC-SK
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:32 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] Revert "EFI: free unused boot mem in at least some cases"
Message-Id: <E1kJMRo-0004uC-SK@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:53:32 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 414d22cc092eab4a5b90d2ce594495733b07c77a
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 16 11:16:41 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 16 11:16:41 2020 +0200

    Revert "EFI: free unused boot mem in at least some cases"
    
    This reverts commit a4cbe0f3b47656ea125922fd48d394731a0163fd,
    which breaks PV shim in a not yet analyzed way.
---
 xen/arch/x86/efi/stub.c   |  6 ------
 xen/arch/x86/setup.c      | 26 +++-----------------------
 xen/arch/x86/tboot.c      | 12 ------------
 xen/common/efi/ebmalloc.c | 31 +++++--------------------------
 xen/include/xen/efi.h     |  1 -
 5 files changed, 8 insertions(+), 68 deletions(-)

diff --git a/xen/arch/x86/efi/stub.c b/xen/arch/x86/efi/stub.c
index 0e01e7322b..c578bffc71 100644
--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -52,12 +52,6 @@ bool efi_enabled(unsigned int feature)
 
 void __init efi_init_memory(void) { }
 
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
-{
-    *start = *end = (unsigned long)_end;
-    return false;
-}
-
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
 
 bool efi_rs_using_pgtables(void)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 44c04e2735..4b15e067fa 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -830,7 +830,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
     int i, j, e820_warn = 0, bytes = 0;
-    unsigned long eb_start, eb_end;
     bool acpi_boot_table_init_done = false, relocated = false;
     int ret;
     struct ns16550_defaults ns16550 = {
@@ -1146,8 +1145,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
         /*
          * This needs to remain in sync with xen_in_range() and the
-         * respective reserve_e820_ram() invocation below. No need to
-         * query efi_boot_mem_unused() here, though.
+         * respective reserve_e820_ram() invocation below.
          */
         mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
@@ -1419,18 +1417,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen\n");
 
-    /* FIXME: Putting a hole in .bss would shatter the large page mapping. */
-    if ( using_2M_mapping() )
-        efi_boot_mem_unused(NULL, NULL);
-
     /* This needs to remain in sync with xen_in_range(). */
-    if ( efi_boot_mem_unused(&eb_start, &eb_end) )
-    {
-        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start));
-        reserve_e820_ram(&boot_e820, __pa(eb_end), __pa(__2M_rwdata_end));
-    }
-    else
-        reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
+    reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1991,7 +1979,7 @@ int __hwdom_init xen_in_range(unsigned long mfn)
     paddr_t start, end;
     int i;
 
-    enum { region_s3, region_ro, region_rw, region_bss, nr_regions };
+    enum { region_s3, region_ro, region_rw, nr_regions };
     static struct {
         paddr_t s, e;
     } xen_regions[nr_regions] __hwdom_initdata;
@@ -2016,14 +2004,6 @@ int __hwdom_init xen_in_range(unsigned long mfn)
         /* hypervisor .data + .bss */
         xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
         xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
-        if ( efi_boot_mem_unused(&start, &end) )
-        {
-            ASSERT(__pa(start) >= xen_regions[region_rw].s);
-            ASSERT(__pa(end) <= xen_regions[region_rw].e);
-            xen_regions[region_rw].e = __pa(start);
-            xen_regions[region_bss].s = __pa(end);
-            xen_regions[region_bss].e = __pa(&__2M_rwdata_end);
-        }
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index aadcce591f..e66b0940c4 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -1,4 +1,3 @@
-#include <xen/efi.h>
 #include <xen/init.h>
 #include <xen/types.h>
 #include <xen/lib.h>
@@ -365,8 +364,6 @@ void tboot_shutdown(uint32_t shutdown_type)
     /* if this is S3 then set regions to MAC */
     if ( shutdown_type == TB_SHUTDOWN_S3 )
     {
-        unsigned long s, e;
-
         /*
          * Xen regions for tboot to MAC. This needs to remain in sync with
          * xen_in_range().
@@ -381,15 +378,6 @@ void tboot_shutdown(uint32_t shutdown_type)
         /* hypervisor .data + .bss */
         g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(&__2M_rwdata_start);
         g_tboot_shared->mac_regions[2].size = __2M_rwdata_end - __2M_rwdata_start;
-        if ( efi_boot_mem_unused(&s, &e) )
-        {
-            g_tboot_shared->mac_regions[2].size =
-                s - (unsigned long)__2M_rwdata_start;
-            g_tboot_shared->mac_regions[3].start = __pa(e);
-            g_tboot_shared->mac_regions[3].size =
-                (unsigned long)__2M_rwdata_end - e;
-            g_tboot_shared->num_mac_regions = 4;
-        }
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/common/efi/ebmalloc.c b/xen/common/efi/ebmalloc.c
index 136838eb8e..c65dbd946f 100644
--- a/xen/common/efi/ebmalloc.c
+++ b/xen/common/efi/ebmalloc.c
@@ -1,6 +1,5 @@
 #include "efi.h"
 #include <xen/init.h>
-#include <xen/mm.h>
 
 #ifdef CONFIG_ARM
 /*
@@ -22,7 +21,7 @@
 
 static char __section(".bss.page_aligned") __aligned(PAGE_SIZE)
     ebmalloc_mem[EBMALLOC_SIZE];
-static unsigned long __read_mostly ebmalloc_allocated;
+static unsigned long __initdata ebmalloc_allocated;
 
 /* EFI boot allocator. */
 void __init *ebmalloc(size_t size)
@@ -37,37 +36,17 @@ void __init *ebmalloc(size_t size)
     return ptr;
 }
 
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
-{
-    if ( !start && !end )
-    {
-        ebmalloc_allocated = sizeof(ebmalloc_mem);
-        return false;
-    }
-
-    *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
-    *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
-
-    return *start < *end;
-}
-
 void __init free_ebmalloc_unused_mem(void)
 {
+#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */
     unsigned long start, end;
 
-    if ( !efi_boot_mem_unused(&start, &end) )
-        return;
+    start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated);
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
 
     destroy_xen_mappings(start, end);
-
-#ifdef CONFIG_X86
-    /*
-     * By reserving the space early in the E820 map, it gets freed way before
-     * we make it here. Don't free the range a 2nd time.
-     */
-#else
     init_xenheap_pages(__pa(start), __pa(end));
-#endif
 
     printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10);
+#endif
 }
diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h
index 94a7e547f9..44b7d3ec3a 100644
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -33,7 +33,6 @@ struct compat_pf_efi_runtime_call;
 
 bool efi_enabled(unsigned int feature);
 void efi_init_memory(void);
-bool efi_boot_mem_unused(unsigned long *start, unsigned long *end);
 bool efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
 void efi_halt_system(void);
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Fri Sep 18 19:53:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Fri, 18 Sep 2020 19:53:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJMS4-0007qG-JA; Fri, 18 Sep 2020 19:53:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=S5oh=C3=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJMS3-0007qA-Kx
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:47 +0000
X-Inumbo-ID: 84c27ebc-eff6-46b9-853f-54a2c506e2be
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 84c27ebc-eff6-46b9-853f-54a2c506e2be;
 Fri, 18 Sep 2020 19:53:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Z5k3REOh3xf7XDM/CI2hebXG73ppUrBkdMFfD6YUzYY=; b=Beh1CxsOYuu3shwPZ1pOksADaD
 Dmd/Fz+9ZVXmTjGjIbW/FRia+kG3SQf9ogkzv+I9h8fe3L29W1DIHTVNy7N4giSeSFHbO6F9NLoqd
 PjHUuzD6IOfl2zN1ckoekYCHXRY2hZYsKFQT6WUPMOvIx3PdgTZ9Acwi8Gp8AqpmFzrw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMS2-0007Kw-7B
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJMS2-00052w-6S
 for xen-changelog@lists.xenproject.org; Fri, 18 Sep 2020 19:53:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] tools: Delete XEN_DOMCTL_disable_migrate
Message-Id: <E1kJMS2-00052w-6S@xenbits.xenproject.org>
Date: Fri, 18 Sep 2020 19:53:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit baa4d064e91b6d2bcfe400bdf71f83b961e4c28e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Feb 11 20:27:15 2020 +0000
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Fri Sep 18 20:40:52 2020 +0100

    tools: Delete XEN_DOMCTL_disable_migrate
    
    It is conceptually wrong for this information to exist in the hypervisor in
    the first place.  Only the toolstack is capable of correctly reasoning about
    the non-migrateability of guests.
    
    This hypercall has only ever existed to control the visibility of the
    Invariant TSC flag to the guest.  Now that we have properly disentanged that
    and moved ITSC into the guests CPUID policy, delete this hypercall.
    
    Furthermore, this fixes a corner case where Xen would override the toolstacks
    choice of ITSC for a xenstore stubdomain.  That said, init-xenstore-domain
    doesn't currently ask for ITSC, and MiniOS doesn't know what ITSC is either,
    so nothing actually changes in practice.
    
    Bump the DOMCTL_INTERFACE_VERSION for 4.15
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libs/ctrl/include/xenctrl.h   |  2 --
 tools/libs/ctrl/xc_domain.c         |  9 ---------
 tools/libxl/libxl_dom.c             |  6 ------
 tools/python/xen/lowlevel/xc/xc.c   | 21 ---------------------
 xen/arch/arm/domctl.c               |  4 ----
 xen/arch/x86/cpuid.c                |  3 ++-
 xen/arch/x86/domctl.c               |  5 -----
 xen/common/domain.c                 |  4 ----
 xen/include/public/domctl.h         | 10 ++--------
 xen/include/xen/sched.h             |  2 --
 xen/xsm/flask/hooks.c               |  1 -
 xen/xsm/flask/policy/access_vectors |  2 +-
 12 files changed, 5 insertions(+), 64 deletions(-)

diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
index 0a921a95fa..73e9535fc8 100644
--- a/tools/libs/ctrl/include/xenctrl.h
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -1351,8 +1351,6 @@ int xc_domain_get_tsc_info(xc_interface *xch,
                            uint32_t *gtsc_khz,
                            uint32_t *incarnation);
 
-int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid);
-
 int xc_domain_maximum_gpfn(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
 
 int xc_domain_nr_gpfns(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c
index 43fab50c06..e7cea4a17d 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -815,15 +815,6 @@ int xc_domain_set_time_offset(xc_interface *xch,
     return do_domctl(xch, &domctl);
 }
 
-int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid)
-{
-    DECLARE_DOMCTL;
-    domctl.cmd = XEN_DOMCTL_disable_migrate;
-    domctl.domain = domid;
-    domctl.u.disable_migrate.disable = 1;
-    return do_domctl(xch, &domctl);
-}
-
 int xc_domain_set_tsc_info(xc_interface *xch,
                            uint32_t domid,
                            uint32_t tsc_mode,
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index e2dca64aa1..597a6826d1 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -257,12 +257,6 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
         return ERROR_FAIL;
     }
 
-    if (libxl_defbool_val(d_config->b_info.disable_migrate) &&
-        xc_domain_disable_migrate(ctx->xch, domid) != 0) {
-        LOG(ERROR, "Couldn't set nomigrate");
-        return ERROR_FAIL;
-    }
-
     /*
      * Check if the domain has any CPU or node affinity already. If not, try
      * to build up the latter via automatic NUMA placement. In fact, in case
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 8c7b184f0b..ce123f0409 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -1469,20 +1469,6 @@ static PyObject *pyxc_domain_set_tsc_info(XcObject *self, PyObject *args)
     return zero;
 }
 
-static PyObject *pyxc_domain_disable_migrate(XcObject *self, PyObject *args)
-{
-    uint32_t dom;
-
-    if (!PyArg_ParseTuple(args, "i", &dom))
-        return NULL;
-
-    if (xc_domain_disable_migrate(self->xc_handle, dom) != 0)
-        return pyxc_error_to_exception(self->xc_handle);
-
-    Py_INCREF(zero);
-    return zero;
-}
-
 static PyObject *pyxc_domain_send_trigger(XcObject *self,
                                           PyObject *args,
                                           PyObject *kwds)
@@ -2306,13 +2292,6 @@ static PyMethodDef pyxc_methods[] = {
       "                   1=always emulate 2=never emulate\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
-    { "domain_disable_migrate",
-      (PyCFunction)pyxc_domain_disable_migrate,
-      METH_VARARGS, "\n"
-      "Marks domain as non-migratable AND non-restoreable\n"
-      " dom        [int]: Domain whose TSC mode is being set.\n"
-      "Returns: [int] 0 on success; -1 on error.\n" },
-
     { "domain_send_trigger",
       (PyCFunction)pyxc_domain_send_trigger,
       METH_VARARGS | METH_KEYWORDS, "\n"
diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 9da88b8c64..b7d27f37df 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -146,10 +146,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
         return 0;
     }
 
-    case XEN_DOMCTL_disable_migrate:
-        d->disable_migrate = domctl->u.disable_migrate.disable;
-        return 0;
-
     case XEN_DOMCTL_vuart_op:
     {
         int rc;
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 23425790e1..dde3e95284 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -708,7 +708,8 @@ int init_domain_cpuid_policy(struct domain *d)
     if ( !p )
         return -ENOMEM;
 
-    if ( d->disable_migrate )
+    /* The hardware domain can't migrate.  Give it ITSC if available. */
+    if ( is_hardware_domain(d) )
         p->extd.itsc = cpu_has_itsc;
 
     /*
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 7c644add92..2ee29a0f78 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -1277,11 +1277,6 @@ long arch_do_domctl(
 
         break;
 
-    case XEN_DOMCTL_disable_migrate:
-        d->disable_migrate = domctl->u.disable_migrate.disable;
-        recalculate_cpuid_policy(d);
-        break;
-
     case XEN_DOMCTL_get_cpu_policy:
         /* Process the CPUID leaves. */
         if ( guest_handle_is_null(domctl->u.cpu_policy.cpuid_policy) )
diff --git a/xen/common/domain.c b/xen/common/domain.c
index f0f9c62feb..61ffccde0c 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -371,7 +371,6 @@ struct domain *domain_create(domid_t domid,
         if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
             panic("The value of hardware_dom must be a valid domain ID\n");
 
-        d->disable_migrate = true;
         old_hwdom = hardware_domain;
         hardware_domain = d;
     }
@@ -452,9 +451,6 @@ struct domain *domain_create(domid_t domid,
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
-        if ( is_xenstore_domain(d) )
-            d->disable_migrate = true;
-
         d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
         d->irq_caps   = rangeset_new(d, "Interrupts", 0);
         if ( !d->iomem_caps || !d->irq_caps )
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 9464a9058a..5c5e55ebcb 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -38,7 +38,7 @@
 #include "hvm/save.h"
 #include "memory.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000012
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000013
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
@@ -730,11 +730,6 @@ struct xen_domctl_hvmcontext_partial {
     XEN_GUEST_HANDLE_64(uint8) buffer;  /* OUT: buffer to write record into */
 };
 
-/* XEN_DOMCTL_disable_migrate */
-struct xen_domctl_disable_migrate {
-    uint32_t disable; /* IN: 1: disable migration and restore */
-};
-
 
 /* XEN_DOMCTL_gettscinfo */
 /* XEN_DOMCTL_settscinfo */
@@ -1191,7 +1186,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_gethvmcontext_partial         55
 #define XEN_DOMCTL_vm_event_op                   56
 #define XEN_DOMCTL_mem_sharing_op                57
-#define XEN_DOMCTL_disable_migrate               58
+/* #define XEN_DOMCTL_disable_migrate            58 - Obsolete */
 #define XEN_DOMCTL_gettscinfo                    59
 #define XEN_DOMCTL_settscinfo                    60
 #define XEN_DOMCTL_getpageframeinfo3             61
@@ -1242,7 +1237,6 @@ struct xen_domctl {
         struct xen_domctl_ioport_permission ioport_permission;
         struct xen_domctl_hypercall_init    hypercall_init;
         struct xen_domctl_settimeoffset     settimeoffset;
-        struct xen_domctl_disable_migrate   disable_migrate;
         struct xen_domctl_tsc_info          tsc_info;
         struct xen_domctl_hvmcontext        hvmcontext;
         struct xen_domctl_hvmcontext_partial hvmcontext_partial;
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index ac53519d7f..e9ce43cc9a 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -401,8 +401,6 @@ struct domain
     bool             is_privileged;
     /* Can this guest access the Xen console? */
     bool             is_console;
-    /* Non-migratable and non-restoreable? */
-    bool             disable_migrate;
     /* Is this guest being debugged by dom0? */
     bool             debugger_attached;
     /*
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index a314bf85ce..fab5d30c3a 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -710,7 +710,6 @@ static int flask_domctl(struct domain *d, int cmd)
         return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SETDEBUGGING);
 
     case XEN_DOMCTL_subscribe:
-    case XEN_DOMCTL_disable_migrate:
         return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SET_MISC_INFO);
 
     case XEN_DOMCTL_set_virq_handler:
diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors
index b87c99ea98..fde5162c7e 100644
--- a/xen/xsm/flask/policy/access_vectors
+++ b/xen/xsm/flask/policy/access_vectors
@@ -176,7 +176,7 @@ class domain
     getpodtarget
 # XENMEM_set_pod_target
     setpodtarget
-# XEN_DOMCTL_subscribe, XEN_DOMCTL_disable_migrate
+# XEN_DOMCTL_subscribe
     set_misc_info
 # XEN_DOMCTL_set_virq_handler
     set_virq_handler
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Sun Sep 20 04:44:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 20 Sep 2020 04:44:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJrCo-0001lJ-UJ; Sun, 20 Sep 2020 04:44:06 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=VyqW=C5=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJrCn-0001lE-Tp
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:05 +0000
X-Inumbo-ID: a4bad89e-d909-41f0-815b-05c1068beedf
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a4bad89e-d909-41f0-815b-05c1068beedf;
 Sun, 20 Sep 2020 04:44:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=FTvvp351sZzt4VGoXobidGRSo9CMsQFzXAPoKti8QJE=; b=h9eaB+Y0TAdouid5IWeAa57+Nd
 XX3mDvQIc1z1IaFSRkC04lHL6Vz9njBccXYWdKxfKS2C8VawuO2P50s3FWz3mUyPftNjqq46c/wpQ
 LtJNqdV/jnIzw14R4xDiCeIN6/8KADy8qB9qLgYca2bh3B9KSwBFHTfSuFJGOR5TFVXc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrCk-0002ff-D3
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrCk-0007C6-AK
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/arm: Remove cmpxchg_local() and drop _mb from the
 other helpers
Message-Id: <E1kJrCk-0007C6-AK@xenbits.xenproject.org>
Date: Sun, 20 Sep 2020 04:44:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5a15c8a65f871d2d8bf4f0c01389f8fbb86455d3
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Fri Sep 11 17:06:21 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 18 17:33:01 2020 +0100

    xen/arm: Remove cmpxchg_local() and drop _mb from the other helpers
    
    The current set of helpers are quite confusing to follow as the naming
    is not very consistent.
    
    Given that cmpxchg_local() is not used in Xen, drop it completely.
    Furthermore, adopt a naming with _mb so all names are now consistent.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/include/asm-arm/arm32/cmpxchg.h | 31 +++++++-----------------------
 xen/include/asm-arm/arm64/cmpxchg.h | 38 +++++++++----------------------------
 xen/include/asm-arm/guest_atomics.h |  6 +++---
 3 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 0770f272ee..3ef1e5c632 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -112,23 +112,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
-                                                unsigned long old,
-                                                unsigned long new, int size)
-{
-	unsigned long ret;
-
-	smp_mb();
-	ret = __cmpxchg(ptr, old, new, size);
 	smp_mb();
 
-	return ret;
+	return old;
 }
 
 /*
@@ -141,11 +130,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -157,12 +146,6 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 }
 
 #define cmpxchg(ptr,o,n)						\
-	((__typeof__(*(ptr)))__cmpxchg_mb((ptr),			\
-					  (unsigned long)(o),		\
-					  (unsigned long)(n),		\
-					  sizeof(*(ptr))))
-
-#define cmpxchg_local(ptr,o,n)						\
 	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
 				       (unsigned long)(o),		\
 				       (unsigned long)(n),		\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index fc5c60f0bd..f4a8c1ccba 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -125,23 +125,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
-						unsigned long old,
-						unsigned long new, int size)
-{
-	unsigned long ret;
-
-	smp_mb();
-	ret = __cmpxchg(ptr, old, new, size);
 	smp_mb();
 
-	return ret;
+	return old;
 }
 
 /*
@@ -154,11 +143,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -173,17 +162,8 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 ({ \
 	__typeof__(*(ptr)) __ret; \
 	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg_mb((ptr), (unsigned long)(o), (unsigned long)(n), \
-			     sizeof(*(ptr))); \
-	__ret; \
-})
-
-#define cmpxchg_local(ptr, o, n) \
-({ \
-	__typeof__(*(ptr)) __ret; \
-	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg((ptr), (unsigned long)(o), \
-			  (unsigned long)(n), sizeof(*(ptr))); \
+		__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \
+			  sizeof(*(ptr))); \
 	__ret; \
 })
 
diff --git a/xen/include/asm-arm/guest_atomics.h b/xen/include/asm-arm/guest_atomics.h
index af27cc627b..20347849e5 100644
--- a/xen/include/asm-arm/guest_atomics.h
+++ b/xen/include/asm-arm/guest_atomics.h
@@ -96,14 +96,14 @@ static inline unsigned long __guest_cmpxchg(struct domain *d,
 
     perfc_incr(atomics_guest);
 
-    if ( __cmpxchg_mb_timeout(ptr, &oldval, new, size,
-                              this_cpu(guest_safe_atomic_max)) )
+    if ( __cmpxchg_timeout(ptr, &oldval, new, size,
+                           this_cpu(guest_safe_atomic_max)) )
         return oldval;
 
     perfc_incr(atomics_guest_paused);
 
     domain_pause_nosync(d);
-    oldval = __cmpxchg_mb(ptr, old, new, size);
+    oldval = __cmpxchg(ptr, old, new, size);
     domain_unpause(d);
 
     return oldval;
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Sun Sep 20 04:44:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 20 Sep 2020 04:44:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJrCw-0001lV-Vw; Sun, 20 Sep 2020 04:44:14 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=VyqW=C5=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJrCv-0001lQ-EX
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:13 +0000
X-Inumbo-ID: 64c3b93e-dcb1-4f34-82de-58b5c423f87e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 64c3b93e-dcb1-4f34-82de-58b5c423f87e;
 Sun, 20 Sep 2020 04:44:12 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=kRcVLscqCtFG7KYUXjsVj8XSgpHOf0EU9IKRFObpzu0=; b=gRsClKoQySwpBRdED4UiYkMsHm
 02FH/idoO0Vt7VetK6sX1Xgsh1qcv76xuGbh7hSBThLaoBJLZG+pfrMUAmijfNJheDzTCJYguwKFv
 OAHcOUeKlKZOaCGvEPIYD3bpu/9QtNF2JKI6BemdVS8fK0GUnsVzcP0lqHKcjl4u6oDE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrCu-0002fi-Gq
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:12 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrCu-0007DE-FP
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen: Introduce cmpxchg64() and guest_cmpxchg64()
Message-Id: <E1kJrCu-0007DE-FP@xenbits.xenproject.org>
Date: Sun, 20 Sep 2020 04:44:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c729d54331ffb05abe93ed2349377092f134fdbd
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Fri Sep 11 17:06:22 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Fri Sep 18 17:33:01 2020 +0100

    xen: Introduce cmpxchg64() and guest_cmpxchg64()
    
    The IOREQ code is using cmpxchg() with 64-bit value. At the moment, this
    is x86 code, but there is plan to make it common.
    
    To cater 32-bit arch, introduce two new helpers to deal with 64-bit
    cmpxchg().
    
    The Arm 32-bit implementation of cmpxchg64() is based on the __cmpxchg64
    in Linux v5.8 (arch/arm/include/asm/cmpxchg.h).
    
    Note that only guest_cmpxchg64() is introduced on x86 so far.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/include/asm-arm/arm32/cmpxchg.h | 68 +++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/arm64/cmpxchg.h |  5 +++
 xen/include/asm-arm/guest_atomics.h | 22 ++++++++++++
 xen/include/asm-x86/guest_atomics.h |  1 +
 4 files changed, 96 insertions(+)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 3ef1e5c632..b0bd1d8b68 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -87,6 +87,37 @@ __CMPXCHG_CASE(b, 1)
 __CMPXCHG_CASE(h, 2)
 __CMPXCHG_CASE( , 4)
 
+static inline bool __cmpxchg_case_8(volatile uint64_t *ptr,
+			 	    uint64_t *old,
+			 	    uint64_t new,
+			 	    bool timeout,
+				    unsigned int max_try)
+{
+	uint64_t oldval;
+	uint64_t res;
+
+	do {
+		asm volatile(
+		"	ldrexd		%1, %H1, [%3]\n"
+		"	teq		%1, %4\n"
+		"	teqeq		%H1, %H4\n"
+		"	movne		%0, #0\n"
+		"	movne		%H0, #0\n"
+		"	bne		2f\n"
+		"	strexd		%0, %5, %H5, [%3]\n"
+		"2:"
+		: "=&r" (res), "=&r" (oldval), "+Qo" (*ptr)
+		: "r" (ptr), "r" (*old), "r" (new)
+		: "memory", "cc");
+		if (!res)
+			break;
+	} while (!timeout || ((--max_try) > 0));
+
+	*old = oldval;
+
+	return !res;
+}
+
 static always_inline bool __int_cmpxchg(volatile void *ptr, unsigned long *old,
 					unsigned long new, int size,
 					bool timeout, unsigned int max_try)
@@ -145,11 +176,48 @@ static always_inline bool __cmpxchg_timeout(volatile void *ptr,
 	return ret;
 }
 
+/*
+ * The helper may fail to update the memory if the action takes too long.
+ *
+ * @old: On call the value pointed contains the expected old value. It will be
+ * updated to the actual old value.
+ * @max_try: Maximum number of iterations
+ *
+ * The helper will return true when the update has succeeded (i.e no
+ * timeout) and false if the update has failed.
+ */
+static always_inline bool __cmpxchg64_timeout(volatile uint64_t *ptr,
+					      uint64_t *old,
+					      uint64_t new,
+					      unsigned int max_try)
+{
+	bool ret;
+
+	smp_mb();
+	ret = __cmpxchg_case_8(ptr, old, new, true, max_try);
+	smp_mb();
+
+	return ret;
+}
+
 #define cmpxchg(ptr,o,n)						\
 	((__typeof__(*(ptr)))__cmpxchg((ptr),				\
 				       (unsigned long)(o),		\
 				       (unsigned long)(n),		\
 				       sizeof(*(ptr))))
+
+static inline uint64_t cmpxchg64(volatile uint64_t *ptr,
+				 uint64_t old,
+				 uint64_t new)
+{
+	smp_mb();
+	if (!__cmpxchg_case_8(ptr, &old, new, false, 0))
+		ASSERT_UNREACHABLE();
+	smp_mb();
+
+	return old;
+}
+
 #endif
 /*
  * Local variables:
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index f4a8c1ccba..10e4edc022 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -167,6 +167,11 @@ static always_inline bool __cmpxchg_timeout(volatile void *ptr,
 	__ret; \
 })
 
+#define cmpxchg64(ptr, o, n) cmpxchg(ptr, o, n)
+
+#define __cmpxchg64_timeout(ptr, old, new, max_try)	\
+	__cmpxchg_timeout(ptr, old, new, 8, max_try)
+
 #endif
 /*
  * Local variables:
diff --git a/xen/include/asm-arm/guest_atomics.h b/xen/include/asm-arm/guest_atomics.h
index 20347849e5..9e2e96d4ff 100644
--- a/xen/include/asm-arm/guest_atomics.h
+++ b/xen/include/asm-arm/guest_atomics.h
@@ -115,6 +115,28 @@ static inline unsigned long __guest_cmpxchg(struct domain *d,
                                          (unsigned long)(n),\
                                          sizeof (*(ptr))))
 
+static inline uint64_t guest_cmpxchg64(struct domain *d,
+                                       volatile uint64_t *ptr,
+                                       uint64_t old,
+                                       uint64_t new)
+{
+    uint64_t oldval = old;
+
+    perfc_incr(atomics_guest);
+
+    if ( __cmpxchg64_timeout(ptr, &oldval, new,
+                             this_cpu(guest_safe_atomic_max)) )
+        return oldval;
+
+    perfc_incr(atomics_guest_paused);
+
+    domain_pause_nosync(d);
+    oldval = cmpxchg64(ptr, old, new);
+    domain_unpause(d);
+
+    return oldval;
+}
+
 #endif /* _ARM_GUEST_ATOMICS_H */
 /*
  * Local variables:
diff --git a/xen/include/asm-x86/guest_atomics.h b/xen/include/asm-x86/guest_atomics.h
index 029417c8ff..c2dec0d650 100644
--- a/xen/include/asm-x86/guest_atomics.h
+++ b/xen/include/asm-x86/guest_atomics.h
@@ -20,6 +20,7 @@
     ((void)(d), test_and_change_bit(nr, p))
 
 #define guest_cmpxchg(d, ptr, o, n) ((void)(d), cmpxchg(ptr, o, n))
+#define guest_cmpxchg64 guest_cmpxchg
 
 #endif /* _X86_GUEST_ATOMICS_H */
 /*
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Sun Sep 20 04:44:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Sun, 20 Sep 2020 04:44:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kJrD7-0001mL-1Q; Sun, 20 Sep 2020 04:44:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=VyqW=C5=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kJrD5-0001m9-TO
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:23 +0000
X-Inumbo-ID: cd0b5f31-d0d2-410c-bf9a-7a8754ae5439
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cd0b5f31-d0d2-410c-bf9a-7a8754ae5439;
 Sun, 20 Sep 2020 04:44:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=M/5JVILqAKXDgEatMNcQQ1pflAtHl6/FaIRYd93UK4w=; b=QZTQbVgQkfaimKBZ286sVSYb+N
 rvnmGzum9WIGTyF4yODQSFqbvms4+d+DeQZMqhPEV396B+2JQBpL8fN8WbS1/UJLh/6jPxbaMXRTY
 p23bMYJS+7zd/DKUOYnRYVkoz25+DIXDwrz1rfOX+DzUnY9R9+9P5Y+xocbEPA3M8ljQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrD4-0002fo-Lq
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:22 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kJrD4-0007EK-K4
 for xen-changelog@lists.xenproject.org; Sun, 20 Sep 2020 04:44:22 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] tools: Delete XEN_DOMCTL_disable_migrate
Message-Id: <E1kJrD4-0007EK-K4@xenbits.xenproject.org>
Date: Sun, 20 Sep 2020 04:44:22 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit baa4d064e91b6d2bcfe400bdf71f83b961e4c28e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Feb 11 20:27:15 2020 +0000
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Fri Sep 18 20:40:52 2020 +0100

    tools: Delete XEN_DOMCTL_disable_migrate
    
    It is conceptually wrong for this information to exist in the hypervisor in
    the first place.  Only the toolstack is capable of correctly reasoning about
    the non-migrateability of guests.
    
    This hypercall has only ever existed to control the visibility of the
    Invariant TSC flag to the guest.  Now that we have properly disentanged that
    and moved ITSC into the guests CPUID policy, delete this hypercall.
    
    Furthermore, this fixes a corner case where Xen would override the toolstacks
    choice of ITSC for a xenstore stubdomain.  That said, init-xenstore-domain
    doesn't currently ask for ITSC, and MiniOS doesn't know what ITSC is either,
    so nothing actually changes in practice.
    
    Bump the DOMCTL_INTERFACE_VERSION for 4.15
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libs/ctrl/include/xenctrl.h   |  2 --
 tools/libs/ctrl/xc_domain.c         |  9 ---------
 tools/libxl/libxl_dom.c             |  6 ------
 tools/python/xen/lowlevel/xc/xc.c   | 21 ---------------------
 xen/arch/arm/domctl.c               |  4 ----
 xen/arch/x86/cpuid.c                |  3 ++-
 xen/arch/x86/domctl.c               |  5 -----
 xen/common/domain.c                 |  4 ----
 xen/include/public/domctl.h         | 10 ++--------
 xen/include/xen/sched.h             |  2 --
 xen/xsm/flask/hooks.c               |  1 -
 xen/xsm/flask/policy/access_vectors |  2 +-
 12 files changed, 5 insertions(+), 64 deletions(-)

diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
index 0a921a95fa..73e9535fc8 100644
--- a/tools/libs/ctrl/include/xenctrl.h
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -1351,8 +1351,6 @@ int xc_domain_get_tsc_info(xc_interface *xch,
                            uint32_t *gtsc_khz,
                            uint32_t *incarnation);
 
-int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid);
-
 int xc_domain_maximum_gpfn(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
 
 int xc_domain_nr_gpfns(xc_interface *xch, uint32_t domid, xen_pfn_t *gpfns);
diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c
index 43fab50c06..e7cea4a17d 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -815,15 +815,6 @@ int xc_domain_set_time_offset(xc_interface *xch,
     return do_domctl(xch, &domctl);
 }
 
-int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid)
-{
-    DECLARE_DOMCTL;
-    domctl.cmd = XEN_DOMCTL_disable_migrate;
-    domctl.domain = domid;
-    domctl.u.disable_migrate.disable = 1;
-    return do_domctl(xch, &domctl);
-}
-
 int xc_domain_set_tsc_info(xc_interface *xch,
                            uint32_t domid,
                            uint32_t tsc_mode,
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index e2dca64aa1..597a6826d1 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -257,12 +257,6 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
         return ERROR_FAIL;
     }
 
-    if (libxl_defbool_val(d_config->b_info.disable_migrate) &&
-        xc_domain_disable_migrate(ctx->xch, domid) != 0) {
-        LOG(ERROR, "Couldn't set nomigrate");
-        return ERROR_FAIL;
-    }
-
     /*
      * Check if the domain has any CPU or node affinity already. If not, try
      * to build up the latter via automatic NUMA placement. In fact, in case
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 8c7b184f0b..ce123f0409 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -1469,20 +1469,6 @@ static PyObject *pyxc_domain_set_tsc_info(XcObject *self, PyObject *args)
     return zero;
 }
 
-static PyObject *pyxc_domain_disable_migrate(XcObject *self, PyObject *args)
-{
-    uint32_t dom;
-
-    if (!PyArg_ParseTuple(args, "i", &dom))
-        return NULL;
-
-    if (xc_domain_disable_migrate(self->xc_handle, dom) != 0)
-        return pyxc_error_to_exception(self->xc_handle);
-
-    Py_INCREF(zero);
-    return zero;
-}
-
 static PyObject *pyxc_domain_send_trigger(XcObject *self,
                                           PyObject *args,
                                           PyObject *kwds)
@@ -2306,13 +2292,6 @@ static PyMethodDef pyxc_methods[] = {
       "                   1=always emulate 2=never emulate\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
-    { "domain_disable_migrate",
-      (PyCFunction)pyxc_domain_disable_migrate,
-      METH_VARARGS, "\n"
-      "Marks domain as non-migratable AND non-restoreable\n"
-      " dom        [int]: Domain whose TSC mode is being set.\n"
-      "Returns: [int] 0 on success; -1 on error.\n" },
-
     { "domain_send_trigger",
       (PyCFunction)pyxc_domain_send_trigger,
       METH_VARARGS | METH_KEYWORDS, "\n"
diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 9da88b8c64..b7d27f37df 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -146,10 +146,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
         return 0;
     }
 
-    case XEN_DOMCTL_disable_migrate:
-        d->disable_migrate = domctl->u.disable_migrate.disable;
-        return 0;
-
     case XEN_DOMCTL_vuart_op:
     {
         int rc;
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 23425790e1..dde3e95284 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -708,7 +708,8 @@ int init_domain_cpuid_policy(struct domain *d)
     if ( !p )
         return -ENOMEM;
 
-    if ( d->disable_migrate )
+    /* The hardware domain can't migrate.  Give it ITSC if available. */
+    if ( is_hardware_domain(d) )
         p->extd.itsc = cpu_has_itsc;
 
     /*
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 7c644add92..2ee29a0f78 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -1277,11 +1277,6 @@ long arch_do_domctl(
 
         break;
 
-    case XEN_DOMCTL_disable_migrate:
-        d->disable_migrate = domctl->u.disable_migrate.disable;
-        recalculate_cpuid_policy(d);
-        break;
-
     case XEN_DOMCTL_get_cpu_policy:
         /* Process the CPUID leaves. */
         if ( guest_handle_is_null(domctl->u.cpu_policy.cpuid_policy) )
diff --git a/xen/common/domain.c b/xen/common/domain.c
index f0f9c62feb..61ffccde0c 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -371,7 +371,6 @@ struct domain *domain_create(domid_t domid,
         if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
             panic("The value of hardware_dom must be a valid domain ID\n");
 
-        d->disable_migrate = true;
         old_hwdom = hardware_domain;
         hardware_domain = d;
     }
@@ -452,9 +451,6 @@ struct domain *domain_create(domid_t domid,
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
-        if ( is_xenstore_domain(d) )
-            d->disable_migrate = true;
-
         d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
         d->irq_caps   = rangeset_new(d, "Interrupts", 0);
         if ( !d->iomem_caps || !d->irq_caps )
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 9464a9058a..5c5e55ebcb 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -38,7 +38,7 @@
 #include "hvm/save.h"
 #include "memory.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000012
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000013
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
@@ -730,11 +730,6 @@ struct xen_domctl_hvmcontext_partial {
     XEN_GUEST_HANDLE_64(uint8) buffer;  /* OUT: buffer to write record into */
 };
 
-/* XEN_DOMCTL_disable_migrate */
-struct xen_domctl_disable_migrate {
-    uint32_t disable; /* IN: 1: disable migration and restore */
-};
-
 
 /* XEN_DOMCTL_gettscinfo */
 /* XEN_DOMCTL_settscinfo */
@@ -1191,7 +1186,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_gethvmcontext_partial         55
 #define XEN_DOMCTL_vm_event_op                   56
 #define XEN_DOMCTL_mem_sharing_op                57
-#define XEN_DOMCTL_disable_migrate               58
+/* #define XEN_DOMCTL_disable_migrate            58 - Obsolete */
 #define XEN_DOMCTL_gettscinfo                    59
 #define XEN_DOMCTL_settscinfo                    60
 #define XEN_DOMCTL_getpageframeinfo3             61
@@ -1242,7 +1237,6 @@ struct xen_domctl {
         struct xen_domctl_ioport_permission ioport_permission;
         struct xen_domctl_hypercall_init    hypercall_init;
         struct xen_domctl_settimeoffset     settimeoffset;
-        struct xen_domctl_disable_migrate   disable_migrate;
         struct xen_domctl_tsc_info          tsc_info;
         struct xen_domctl_hvmcontext        hvmcontext;
         struct xen_domctl_hvmcontext_partial hvmcontext_partial;
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index ac53519d7f..e9ce43cc9a 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -401,8 +401,6 @@ struct domain
     bool             is_privileged;
     /* Can this guest access the Xen console? */
     bool             is_console;
-    /* Non-migratable and non-restoreable? */
-    bool             disable_migrate;
     /* Is this guest being debugged by dom0? */
     bool             debugger_attached;
     /*
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index a314bf85ce..fab5d30c3a 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -710,7 +710,6 @@ static int flask_domctl(struct domain *d, int cmd)
         return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SETDEBUGGING);
 
     case XEN_DOMCTL_subscribe:
-    case XEN_DOMCTL_disable_migrate:
         return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__SET_MISC_INFO);
 
     case XEN_DOMCTL_set_virq_handler:
diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors
index b87c99ea98..fde5162c7e 100644
--- a/xen/xsm/flask/policy/access_vectors
+++ b/xen/xsm/flask/policy/access_vectors
@@ -176,7 +176,7 @@ class domain
     getpodtarget
 # XENMEM_set_pod_target
     setpodtarget
-# XEN_DOMCTL_subscribe, XEN_DOMCTL_disable_migrate
+# XEN_DOMCTL_subscribe
     set_misc_info
 # XEN_DOMCTL_set_virq_handler
     set_virq_handler
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 10:22:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 10:22:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKIxT-0001Hx-JD; Mon, 21 Sep 2020 10:22:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKIxS-0001Hs-Fr
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:06 +0000
X-Inumbo-ID: b63c101e-e02b-4247-90ad-4518edf70f76
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b63c101e-e02b-4247-90ad-4518edf70f76;
 Mon, 21 Sep 2020 10:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6A4nGFbi4I8SzvqSZKbwJDfLVx4exhxccMG84O9Yh9Q=; b=ImXaLWC5bgR58jTIXbxYArVCou
 bfGTaS2Z8xSLLRf37IlSVXsFrOs7GIcn8IDP3RpmzNvu3PFf6q0Dgx4/JLd4BX6BDF/27QbBJsCoa
 2CkN/r93pHeGDcmbxTrh+D0n86jQr0iJrXwnBfCE5+37bgLH1PfrwiFID/Sl3HKL/zBs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxQ-0006AL-Sq
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxQ-0001Rd-QZ
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] mm: adjust get_page()'s types
Message-Id: <E1kKIxQ-0001Rd-QZ@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 10:22:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 18063d6377fc40599e06ef9df5b5f0ea369ba83f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 21 12:10:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:10:26 2020 +0200

    mm: adjust get_page()'s types
    
    The passed in domain doesn't get altered and hence can be const. While
    modifying its prototype anyway, also switch to bool.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/mm.c    | 8 ++++----
 xen/arch/x86/mm.c    | 8 ++++----
 xen/include/xen/mm.h | 2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 9e2ff7c800..b4763d9a3d 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1560,17 +1560,17 @@ void put_page(struct page_info *page)
     }
 }
 
-int get_page(struct page_info *page, struct domain *domain)
+bool get_page(struct page_info *page, const struct domain *domain)
 {
-    struct domain *owner = page_get_owner_and_reference(page);
+    const struct domain *owner = page_get_owner_and_reference(page);
 
     if ( likely(owner == domain) )
-        return 1;
+        return true;
 
     if ( owner != NULL )
         put_page(page);
 
-    return 0;
+    return false;
 }
 
 /* Common code requires get_page_type and put_page_type.
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 42a6dc9ba4..2c13a2d8e7 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2510,12 +2510,12 @@ struct domain *page_get_owner_and_reference(struct page_info *page)
 }
 
 
-int get_page(struct page_info *page, struct domain *domain)
+bool get_page(struct page_info *page, const struct domain *domain)
 {
-    struct domain *owner = page_get_owner_and_reference(page);
+    const struct domain *owner = page_get_owner_and_reference(page);
 
     if ( likely(owner == domain) )
-        return 1;
+        return true;
 
     if ( !paging_mode_refcounts(domain) && !domain->is_dying )
         gprintk(XENLOG_INFO,
@@ -2526,7 +2526,7 @@ int get_page(struct page_info *page, struct domain *domain)
     if ( owner )
         put_page(page);
 
-    return 0;
+    return false;
 }
 
 /*
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 1061765bcd..4536a62940 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -151,7 +151,7 @@ TYPE_SAFE(unsigned long, pfn);
 struct page_info;
 
 void put_page(struct page_info *);
-int get_page(struct page_info *, struct domain *);
+bool get_page(struct page_info *, const struct domain *);
 struct domain *__must_check page_get_owner_and_reference(struct page_info *);
 
 /* Boot-time allocator. Turns into generic allocator after bootstrap. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 10:22:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 10:22:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKIxe-0001IZ-Kn; Mon, 21 Sep 2020 10:22:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKIxd-0001IR-9o
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:17 +0000
X-Inumbo-ID: 058eb4be-924b-4ce0-869e-b41d186218a2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 058eb4be-924b-4ce0-869e-b41d186218a2;
 Mon, 21 Sep 2020 10:22:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cGS2jMMcgixxidvqzU/fSsIGFhlcIzHRoH7qRSRZeWw=; b=TAdIejmGmXrjRK4Q5Z5N5UFOy9
 iW5SNX470iJi2SyoMSG3YN1isOjctxd2buRSVzgo1S/4mMTZTPjYnEwIZzLsRHkgA86fH9FS2Ji31
 HQ7XGHAmBcM88mzw94Go/JdH1hHZoHxSu2vleUIAAIy8Q69t63nJDFuQkAHC3XCGPH2I=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxb-0006AO-0q
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxa-0001SD-VO
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:14 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/svm: ignore accesses to EX_CFG
Message-Id: <E1kKIxa-0001SD-VO@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 10:22:14 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5164e44885252ae909977dd3b39c743544f3f5f0
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 21 12:11:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:11:38 2020 +0200

    x86/svm: ignore accesses to EX_CFG
    
    Windows 10 will try to unconditionally read (and possibly even adjust)
    EX_CFG on AMD hardware, despite it being documented only for Fam15 models
    0xh, and injecting a #GP fault will result in a panic:
    
    svm.c:1964:d5v0 RDMSR 0xc001102c unimplemented
    d5v0 VIRIDIAN CRASH: 7e ffffffffc0000096 fffff8054cbe5ffe fffffa0837a066e8 fffffa0837a05f30
    
    Return 0 when trying to read the MSR and drop writes.
    
    Fixes: 84e848fd7a16 ('x86/hvm: disallow access to unknown MSRs')
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c      | 2 ++
 xen/include/asm-x86/msr-index.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 136445972e..5037c0fe7d 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1942,6 +1942,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     case MSR_K8_TOP_MEM1:
     case MSR_K8_TOP_MEM2:
     case MSR_K8_VM_CR:
+    case MSR_AMD64_EX_CFG:
         *msr_content = 0;
         break;
 
@@ -2108,6 +2109,7 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
     case MSR_K8_TOP_MEM2:
     case MSR_K8_SYSCFG:
     case MSR_K8_VM_CR:
+    case MSR_AMD64_EX_CFG:
         /* ignore write. handle all bits as read-only. */
         break;
 
diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h
index 4fd54fb5c9..3e0c6c8476 100644
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -330,6 +330,7 @@
 #define MSR_AMD64_DC_CFG		0xc0011022
 #define MSR_AMD64_DE_CFG		0xc0011029
 #define AMD64_DE_CFG_LFENCE_SERIALISE	(_AC(1, ULL) << 1)
+#define MSR_AMD64_EX_CFG		0xc001102c
 
 #define MSR_AMD64_DR0_ADDRESS_MASK	0xc0011027
 #define MSR_AMD64_DR1_ADDRESS_MASK	0xc0011019
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 10:22:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 10:22:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKIxn-0001Jh-MJ; Mon, 21 Sep 2020 10:22:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKIxm-0001JW-3N
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:26 +0000
X-Inumbo-ID: 092905e2-92b2-4581-adc2-f6cf9731da07
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 092905e2-92b2-4581-adc2-f6cf9731da07;
 Mon, 21 Sep 2020 10:22:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=hlSOLnFFDwGM+PzlhrmaM/zaE33u7/f/8jYQDMoCxIA=; b=bVf841QqAcTzsN31C4jXnGG7tN
 r9RKa3Kt9bFZrECOJwfRTzhDEvmjIAMATqwQWL6bemLam3DQgxCcIhORxq4xngyMXEdnL+w4qEimr
 clKRxChIojI462Zt2iu0xJlTrpD+aUxioGSytslvOgE2c/MHMe3wnT6ABWF3TWFpQo/0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxl-0006AZ-3y
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKIxl-0001Sp-34
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 10:22:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] efi/boot: make file->ptr const void*
Message-Id: <E1kKIxl-0001Sp-34@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 10:22:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c7e3021a71fdb4f2d5dbad90ba83ce35bc21cda6
Author:     Trammell Hudson <hudson@trmm.net>
AuthorDate: Mon Sep 21 12:14:24 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:14:24 2020 +0200

    efi/boot: make file->ptr const void*
    
    Other than the config file parser that edits the image inplace,
    no other users of the file sections requires write access to the
    data.
    
    Signed-off-by: Trammell Hudson <hudson@trmm.net>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/efi/boot.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 4022a672c9..523fda41fd 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -41,7 +41,7 @@
 
 typedef EFI_STATUS
 (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) (
-    IN VOID *Buffer,
+    IN const VOID *Buffer,
     IN UINT32 Size);
 
 typedef struct {
@@ -104,7 +104,8 @@ struct file {
     UINTN size;
     union {
         EFI_PHYSICAL_ADDRESS addr;
-        void *ptr;
+        char *str;
+        const void *ptr;
     };
 };
 
@@ -592,7 +593,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
             efi_arch_handle_module(file, name, options);
         }
 
-        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
+        ret = FileHandle->Read(FileHandle, &file->size, file->str);
         if ( !EFI_ERROR(ret) && file->size != size )
             ret = EFI_ABORTED;
         if ( EFI_ERROR(ret) )
@@ -616,7 +617,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
 
 static void __init pre_parse(const struct file *cfg)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     bool start = true, comment = false;
 
     for ( ; ptr < end; ++ptr )
@@ -645,7 +646,7 @@ static void __init pre_parse(const struct file *cfg)
 static char *__init get_value(const struct file *cfg, const char *section,
                               const char *item)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     size_t slen = section ? strlen(section) : 0, ilen = strlen(item);
     bool match = !slen;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 16:22:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 16:22:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKOZs-0002Xm-IO; Mon, 21 Sep 2020 16:22:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKOZr-0002Xh-KK
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:07 +0000
X-Inumbo-ID: d124890b-ad08-43a6-911f-da1fabc7812d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d124890b-ad08-43a6-911f-da1fabc7812d;
 Mon, 21 Sep 2020 16:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=aQKqBG1+FBPyOhOuwQYW7gR9HRmHqSf2uivDmxA8aWw=; b=mdSv8FcOKtygfAHaaeXDUb9Iqs
 NgZX4k1hZPgfya7q6uPlc9Zzm/UsA88k+NOZh5dRVu6UWl5dqA9LWDylFO9ntr75naN+/MhZqPX0R
 wTM6savy1uWUt1GDU63SYLVfFBOuNHRhJVqV3+OXBfUq9T5EZpkwosRK/zqgYg2QSjQE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOZp-0005zv-NL
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOZp-0002Je-M8
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen: include xen/guest_access.h rather than
 asm/guest_access.h
Message-Id: <E1kKOZp-0002Je-M8@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 16:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6edcdb4e5716626b2206f2b627e57a38ad2c3f59
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 11:56:43 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen: include xen/guest_access.h rather than asm/guest_access.h
    
    Only a few places are actually including asm/guest_access.h. While this
    is fine today, a follow-up patch will want to move most of the helpers
    from asm/guest_access.h to xen/guest_access.h.
    
    To prepare the move, everyone should include xen/guest_access.h rather
    than asm/guest_access.h.
    
    Interestingly, asm-arm/guest_access.h includes xen/guest_access.h. The
    inclusion is now removed as no-one but the latter should include the
    former.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    Acked-by: Paul Durrant <paul@xen.org>
---
 xen/arch/arm/decode.c                | 2 +-
 xen/arch/arm/domain.c                | 2 +-
 xen/arch/arm/guest_walk.c            | 3 ++-
 xen/arch/arm/guestcopy.c             | 2 +-
 xen/arch/arm/kernel.c                | 2 +-
 xen/arch/arm/vgic-v3-its.c           | 2 +-
 xen/arch/x86/hvm/svm/svm.c           | 2 +-
 xen/arch/x86/hvm/viridian/viridian.c | 2 +-
 xen/arch/x86/hvm/vmx/vmx.c           | 2 +-
 xen/common/libelf/libelf-loader.c    | 2 +-
 xen/include/asm-arm/guest_access.h   | 1 -
 xen/lib/x86/private.h                | 2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c
index 144793c8ce..792c2e92a7 100644
--- a/xen/arch/arm/decode.c
+++ b/xen/arch/arm/decode.c
@@ -17,12 +17,12 @@
  * GNU General Public License for more details.
  */
 
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
 #include <xen/types.h>
 
 #include <asm/current.h>
-#include <asm/guest_access.h>
 
 #include "decode.h"
 
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 31169326b2..9258f6d3fa 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -12,6 +12,7 @@
 #include <xen/bitops.h>
 #include <xen/errno.h>
 #include <xen/grant_table.h>
+#include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <xen/init.h>
 #include <xen/lib.h>
@@ -26,7 +27,6 @@
 #include <asm/current.h>
 #include <asm/event.h>
 #include <asm/gic.h>
-#include <asm/guest_access.h>
 #include <asm/guest_atomics.h>
 #include <asm/irq.h>
 #include <asm/p2m.h>
diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index a1cdd7f4af..b4496c4c86 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -16,8 +16,9 @@
  */
 
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/sched.h>
-#include <asm/guest_access.h>
+
 #include <asm/guest_walk.h>
 #include <asm/short-desc.h>
 
diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
index c8023e2bca..32681606d8 100644
--- a/xen/arch/arm/guestcopy.c
+++ b/xen/arch/arm/guestcopy.c
@@ -1,10 +1,10 @@
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/mm.h>
 #include <xen/sched.h>
 
 #include <asm/current.h>
-#include <asm/guest_access.h>
 
 #define COPY_flush_dcache   (1U << 0)
 #define COPY_from_guest     (0U << 1)
diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
index f95fa392af..032923853f 100644
--- a/xen/arch/arm/kernel.c
+++ b/xen/arch/arm/kernel.c
@@ -5,6 +5,7 @@
  */
 #include <xen/domain_page.h>
 #include <xen/errno.h>
+#include <xen/guest_access.h>
 #include <xen/gunzip.h>
 #include <xen/init.h>
 #include <xen/lib.h>
@@ -14,7 +15,6 @@
 #include <xen/vmap.h>
 
 #include <asm/byteorder.h>
-#include <asm/guest_access.h>
 #include <asm/kernel.h>
 #include <asm/setup.h>
 
diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c
index 6e153c698d..58d939b85f 100644
--- a/xen/arch/arm/vgic-v3-its.c
+++ b/xen/arch/arm/vgic-v3-its.c
@@ -32,6 +32,7 @@
 #include <xen/bitops.h>
 #include <xen/config.h>
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/softirq.h>
@@ -39,7 +40,6 @@
 #include <xen/sched.h>
 #include <xen/sizes.h>
 #include <asm/current.h>
-#include <asm/guest_access.h>
 #include <asm/mmio.h>
 #include <asm/gic_v3_defs.h>
 #include <asm/gic_v3_its.h>
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 5037c0fe7d..fa9fca94e2 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -16,6 +16,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/guest_access.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/trace.h>
@@ -34,7 +35,6 @@
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
 #include <asm/amd.h>
-#include <asm/guest_access.h>
 #include <asm/debugreg.h>
 #include <asm/msr.h>
 #include <asm/i387.h>
diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c
index 977c1bc54f..dc7183a546 100644
--- a/xen/arch/x86/hvm/viridian/viridian.c
+++ b/xen/arch/x86/hvm/viridian/viridian.c
@@ -5,12 +5,12 @@
  * Hypervisor Top Level Functional Specification for more information.
  */
 
+#include <xen/guest_access.h>
 #include <xen/sched.h>
 #include <xen/version.h>
 #include <xen/hypercall.h>
 #include <xen/domain_page.h>
 #include <xen/param.h>
-#include <asm/guest_access.h>
 #include <asm/guest/hyperv-tlfs.h>
 #include <asm/paging.h>
 #include <asm/p2m.h>
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index a3aadce4d8..998f33fb03 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -15,6 +15,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/guest_access.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/param.h>
@@ -31,7 +32,6 @@
 #include <asm/regs.h>
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
-#include <asm/guest_access.h>
 #include <asm/debugreg.h>
 #include <asm/msr.h>
 #include <asm/p2m.h>
diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c
index 0f468727d0..629cc0d3e6 100644
--- a/xen/common/libelf/libelf-loader.c
+++ b/xen/common/libelf/libelf-loader.c
@@ -16,7 +16,7 @@
  */
 
 #ifdef __XEN__
-#include <asm/guest_access.h>
+#include <xen/guest_access.h>
 #endif
 
 #include "libelf-private.h"
diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h
index 31b9f03f00..b9a89c4955 100644
--- a/xen/include/asm-arm/guest_access.h
+++ b/xen/include/asm-arm/guest_access.h
@@ -1,7 +1,6 @@
 #ifndef __ASM_ARM_GUEST_ACCESS_H__
 #define __ASM_ARM_GUEST_ACCESS_H__
 
-#include <xen/guest_access.h>
 #include <xen/errno.h>
 #include <xen/sched.h>
 
diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h
index b793181464..2d53bd3ced 100644
--- a/xen/lib/x86/private.h
+++ b/xen/lib/x86/private.h
@@ -4,12 +4,12 @@
 #ifdef __XEN__
 
 #include <xen/bitops.h>
+#include <xen/guest_access.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
 #include <xen/nospec.h>
 #include <xen/types.h>
 
-#include <asm/guest_access.h>
 #include <asm/msr-index.h>
 
 #define copy_to_buffer_offset copy_to_guest_offset
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 16:22:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 16:22:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKOa3-0002YI-K1; Mon, 21 Sep 2020 16:22:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKOa2-0002YA-Cc
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:18 +0000
X-Inumbo-ID: dacde023-613a-4670-bd13-968c1dce28c5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id dacde023-613a-4670-bd13-968c1dce28c5;
 Mon, 21 Sep 2020 16:22:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IZaxdxVgk6R1cHEWs3TlW3abm7+kcnrAqZ6cVKVKZyo=; b=b7Yb7zYTckaVtc2HmZ6QEdI9am
 nvkZGcZMUuPqD2slfiM5s0uqzpqwZlhkQYZDWXEQaM19JIa9SZl7jEIap4z4M8j/pfU9wKJ1695YW
 nFeNCbS4WhTfBEapGi0cqJQoeF4guDTDDcnDyFayFcX8egSr2C/jtOhgtuLb/wOIp8Hc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOZz-0005zy-RD
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOZz-0002KE-Pi
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/guest_access: Consolidate guest access helpers in
 xen/guest_access.h
Message-Id: <E1kKOZz-0002KE-Pi@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 16:22:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5b619481becfc4681804ea7193a2ee42a50fd468
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 12:33:16 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen/guest_access: Consolidate guest access helpers in xen/guest_access.h
    
    Most of the helpers to access guest memory are implemented the same way
    on Arm and x86. The only differences are:
        - guest_handle_to_param(): while on x86 XEN_GUEST_HANDLE()
          and XEN_GUEST_HANDLE_PARAM() are the same, they are not on Arm. It
          is still fine to use the Arm implementation on x86.
        - __clear_guest_offset(): Interestingly the prototype does not match
          between the x86 and Arm. However, the Arm one is bogus. So the x86
          implementation can be used.
        - guest_handle{,_subrange}_okay(): They are validly differing
          because Arm is only supporting auto-translated guest and therefore
          handles are always valid.
    
    In the past, the ia64 and ppc64 port use a different model to access
    guest parameter. They have been long gone now.
    
    Given Xen currently only support 2 archictures, it is too soon to have a
    directory asm-generic as it is not possible to differentiate it with the
    existing directory xen/. If/When there is a 3rd port, we can decide to
    create the new directory if that new port decide to use a different way
    to access guest parameter.
    
    For now, consolidate it in xen/guest_access.h.
    
    While it would be possible to adjust the coding style at the same, this
    is left for a follow-up patch so 'diff' can be used to check the
    consolidation was done correctly.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sttabellini@kernel.org>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/include/asm-arm/guest_access.h | 114 -----------------------------------
 xen/include/asm-x86/guest_access.h | 108 ---------------------------------
 xen/include/xen/guest_access.h     | 119 +++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 222 deletions(-)

diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h
index b9a89c4955..53766386d3 100644
--- a/xen/include/asm-arm/guest_access.h
+++ b/xen/include/asm-arm/guest_access.h
@@ -23,88 +23,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,
 #define __raw_copy_from_guest raw_copy_from_guest
 #define __raw_clear_guest raw_clear_guest
 
-/* Remainder copied from x86 -- could be common? */
-
-/* Is the guest handle a NULL reference? */
-#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
-
-/* Offset the given guest handle into the array it refers to. */
-#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
-#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
-
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
-#define guest_handle_cast(hnd, type) ({         \
-    type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
-})
-
-/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
-#define guest_handle_to_param(hnd, type) ({                  \
-    typeof((hnd).p) _x = (hnd).p;                            \
-    XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
-    /* type checking: make sure that the pointers inside     \
-     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
-    (void)(&_x == &_y.p);                                    \
-    _y;                                                      \
-})
-
-#define guest_handle_for_field(hnd, type, fld)          \
-    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
-
-#define guest_handle_from_ptr(ptr, type)        \
-    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
-#define const_guest_handle_from_ptr(ptr, type)  \
-    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
-
-/*
- * Copy an array of objects to guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
-})
-
-/*
- * Clear an array of objects in guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                        \
-    raw_clear_guest(_d+(off), nr);             \
-})
-
-/*
- * Copy an array of objects from guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-/* Copy sub-field of a structure to guest context via a guest handle. */
-#define copy_field_to_guest(hnd, ptr, field) ({         \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
-})
-
-/* Copy sub-field of a structure from guest context via a guest handle. */
-#define copy_field_from_guest(ptr, hnd, field) ({       \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
-})
-
 /*
  * Pre-validate a guest handle.
  * Allows use of faster __copy_* functions.
@@ -113,38 +31,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,
 #define guest_handle_okay(hnd, nr) (1)
 #define guest_handle_subrange_okay(hnd, first, last) (1)
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
-})
-
-#define __clear_guest_offset(hnd, off, ptr, nr) ({      \
-    __raw_clear_guest(_d+(off), nr);  \
-})
-
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define __copy_field_to_guest(hnd, ptr, field) ({       \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
-})
-
-#define __copy_field_from_guest(ptr, hnd, field) ({     \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
-})
-
 #endif /* __ASM_ARM_GUEST_ACCESS_H__ */
 /*
  * Local variables:
diff --git a/xen/include/asm-x86/guest_access.h b/xen/include/asm-x86/guest_access.h
index 369676f31a..8f0e2c71f1 100644
--- a/xen/include/asm-x86/guest_access.h
+++ b/xen/include/asm-x86/guest_access.h
@@ -38,81 +38,6 @@
      clear_user_hvm((dst), (len)) :             \
      clear_user((dst), (len)))
 
-/* Is the guest handle a NULL reference? */
-#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
-
-/* Offset the given guest handle into the array it refers to. */
-#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
-#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
-
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
-#define guest_handle_cast(hnd, type) ({         \
-    type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
-})
-
-/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
-#define guest_handle_to_param(hnd, type) ({                  \
-    /* type checking: make sure that the pointers inside     \
-     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
-    (void)((typeof(&(hnd).p)) 0 ==                           \
-        (typeof(&((XEN_GUEST_HANDLE_PARAM(type)) {}).p)) 0); \
-    (hnd);                                                   \
-})
-
-#define guest_handle_for_field(hnd, type, fld)          \
-    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
-
-#define guest_handle_from_ptr(ptr, type)        \
-    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
-#define const_guest_handle_from_ptr(ptr, type)  \
-    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
-
-/*
- * Copy an array of objects to guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
-})
-
-/*
- * Copy an array of objects from guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                        \
-    raw_clear_guest(_d+(off), nr);             \
-})
-
-/* Copy sub-field of a structure to guest context via a guest handle. */
-#define copy_field_to_guest(hnd, ptr, field) ({         \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
-})
-
-/* Copy sub-field of a structure from guest context via a guest handle. */
-#define copy_field_from_guest(ptr, hnd, field) ({       \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
-})
-
 /*
  * Pre-validate a guest handle.
  * Allows use of faster __copy_* functions.
@@ -126,39 +51,6 @@
                      (last)-(first)+1,                  \
                      sizeof(*(hnd).p)))
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
-})
-
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define __clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                          \
-    __raw_clear_guest(_d+(off), nr);             \
-})
-
-#define __copy_field_to_guest(hnd, ptr, field) ({       \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
-})
-
-#define __copy_field_from_guest(ptr, hnd, field) ({     \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
-})
-
 #endif /* __ASM_X86_GUEST_ACCESS_H__ */
 
 /*
diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h
index 75103d30c8..6100a3e62a 100644
--- a/xen/include/xen/guest_access.h
+++ b/xen/include/xen/guest_access.h
@@ -11,6 +11,86 @@
 #include <xen/types.h>
 #include <public/xen.h>
 
+/* Is the guest handle a NULL reference? */
+#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
+
+/* Offset the given guest handle into the array it refers to. */
+#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
+
+/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
+ * to the specified type of XEN_GUEST_HANDLE_PARAM. */
+#define guest_handle_cast(hnd, type) ({         \
+    type *_x = (hnd).p;                         \
+    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
+})
+
+/* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
+#define guest_handle_to_param(hnd, type) ({                  \
+    typeof((hnd).p) _x = (hnd).p;                            \
+    XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
+    /* type checking: make sure that the pointers inside     \
+     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
+     * the same type, then return hnd */                     \
+    (void)(&_x == &_y.p);                                    \
+    _y;                                                      \
+})
+
+#define guest_handle_for_field(hnd, type, fld)          \
+    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
+
+#define guest_handle_from_ptr(ptr, type)        \
+    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
+#define const_guest_handle_from_ptr(ptr, type)  \
+    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
+
+/*
+ * Copy an array of objects to guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    /* Check that the handle is not for a const type */ \
+    void *__maybe_unused _t = (hnd).p;                  \
+    (void)((hnd).p == _s);                              \
+    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
+})
+
+/*
+ * Clear an array of objects in guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define clear_guest_offset(hnd, off, nr) ({    \
+    void *_d = (hnd).p;                        \
+    raw_clear_guest(_d+(off), nr);             \
+})
+
+/*
+ * Copy an array of objects from guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
+    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+})
+
+/* Copy sub-field of a structure to guest context via a guest handle. */
+#define copy_field_to_guest(hnd, ptr, field) ({         \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    (void)(&(hnd).p->field == _s);                      \
+    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
+})
+
+/* Copy sub-field of a structure from guest context via a guest handle. */
+#define copy_field_from_guest(ptr, hnd, field) ({       \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
+    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
+})
+
 #define copy_to_guest(hnd, ptr, nr)                     \
     copy_to_guest_offset(hnd, 0, ptr, nr)
 
@@ -20,6 +100,45 @@
 #define clear_guest(hnd, nr)                            \
     clear_guest_offset(hnd, 0, nr)
 
+/*
+ * The __copy_* functions should only be used after the guest handle has
+ * been pre-validated via guest_handle_okay() and
+ * guest_handle_subrange_okay().
+ */
+
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    /* Check that the handle is not for a const type */ \
+    void *__maybe_unused _t = (hnd).p;                  \
+    (void)((hnd).p == _s);                              \
+    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
+})
+
+#define __clear_guest_offset(hnd, off, nr) ({    \
+    void *_d = (hnd).p;                          \
+    __raw_clear_guest(_d + (off), nr);           \
+})
+
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
+    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+})
+
+#define __copy_field_to_guest(hnd, ptr, field) ({       \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    (void)(&(hnd).p->field == _s);                      \
+    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
+})
+
+#define __copy_field_from_guest(ptr, hnd, field) ({     \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
+    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
+})
+
 #define __copy_to_guest(hnd, ptr, nr)                   \
     __copy_to_guest_offset(hnd, 0, ptr, nr)
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 21 16:22:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 21 Sep 2020 16:22:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKOaC-0002ZB-LX; Mon, 21 Sep 2020 16:22:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=59sJ=C6=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKOaB-0002Z1-AE
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:27 +0000
X-Inumbo-ID: 5393ca98-2a51-4b0a-bd9d-5289af6f0262
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5393ca98-2a51-4b0a-bd9d-5289af6f0262;
 Mon, 21 Sep 2020 16:22:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=t8uNOUUdctuezK7LB7D18+oSI/rne9p/Xy1CIi6NvGc=; b=mydquypyDk4X6gp7Wc0iipu8UU
 JWpeVTpttDL+W3dB/W9056wTBUFG2RKrrWgW8kDVvlf3qpSyO6Y7I501WjPIt/phwOFkB3JAGSEJf
 6z2TBxG/iimrZMOM/1kXfNhFtIZ0MBAl+prgQz7rt/XICBRr7oJ8ye9YKkiEbC4342I4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOa9-000604-VZ
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKOa9-0002Ky-TZ
 for xen-changelog@lists.xenproject.org; Mon, 21 Sep 2020 16:22:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/guest_access: Improve coding style in
 xen/guest_access.h
Message-Id: <E1kKOa9-0002Ky-TZ@xenbits.xenproject.org>
Date: Mon, 21 Sep 2020 16:22:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d4ed1d4132f5825a795d5a78505811ecd2717b5e
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 12:35:28 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen/guest_access: Improve coding style in xen/guest_access.h
    
        * Add space before and after operator
        * Align \
        * Format comments
    
    No functional changes expected.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
 xen/include/xen/guest_access.h | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h
index 6100a3e62a..f9b94cf1f4 100644
--- a/xen/include/xen/guest_access.h
+++ b/xen/include/xen/guest_access.h
@@ -18,20 +18,24 @@
 #define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
 #define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
 
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
+/*
+ * Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
+ * to the specified type of XEN_GUEST_HANDLE_PARAM.
+ */
 #define guest_handle_cast(hnd, type) ({         \
     type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
+    (XEN_GUEST_HANDLE_PARAM(type)) { _x };      \
 })
 
 /* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
 #define guest_handle_to_param(hnd, type) ({                  \
     typeof((hnd).p) _x = (hnd).p;                            \
     XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
-    /* type checking: make sure that the pointers inside     \
+    /*                                                       \
+     * type checking: make sure that the pointers inside     \
      * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
+     * the same type, then return hnd.                       \
+     */                                                      \
     (void)(&_x == &_y.p);                                    \
     _y;                                                      \
 })
@@ -106,13 +110,13 @@
  * guest_handle_subrange_okay().
  */
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({        \
+    const typeof(*(ptr)) *_s = (ptr);                       \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;              \
+    /* Check that the handle is not for a const type */     \
+    void *__maybe_unused _t = (hnd).p;                      \
+    (void)((hnd).p == _s);                                  \
+    __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr));\
 })
 
 #define __clear_guest_offset(hnd, off, nr) ({    \
@@ -120,10 +124,10 @@
     __raw_clear_guest(_d + (off), nr);           \
 })
 
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({          \
+    const typeof(*(ptr)) *_s = (hnd).p;                         \
+    typeof(*(ptr)) *_d = (ptr);                                 \
+    __raw_copy_from_guest(_d, _s + (off), sizeof (*_d) * (nr)); \
 })
 
 #define __copy_field_to_guest(hnd, ptr, field) ({       \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY79-0006N7-U9; Tue, 22 Sep 2020 02:33:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY78-0006N1-G3
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:06 +0000
X-Inumbo-ID: 21b7cb15-9444-4017-be65-9f9343ff12e8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 21b7cb15-9444-4017-be65-9f9343ff12e8;
 Tue, 22 Sep 2020 02:33:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=8nlff+iDxG3NjgRll+WL6CCLLur5vPrZjNcFfB7zHDM=; b=x0lJSW0aYUg77QWcJc/Mg0Oe6l
 aO9+dg2Lxnwgv6GgJ02me6Q0reSlkFdL1fVxcOGrdhgcv1g8LIDILGmfHh0QCKGGFw07uGzxHn99l
 tJ2PI3it3slHeZxJmt3yHagzPKbnVp6CfjV7xwuJcE7f98/3BfR76Qey6h2RoQED4TWQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY77-0007xX-3k
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY77-0001If-18
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] arm: Add Neoverse N1 processor identification
Message-Id: <E1kKY77-0001If-18@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6ef4daddc78d48be1990046930456e707c44d9ca
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:38 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:25:17 2020 -0700

    arm: Add Neoverse N1 processor identification
    
    Add MIDR and CPU part numbers for Neoverse N1
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 3b418b33265402aab0cb1bf2b745a25724bae2d8)
---
 xen/include/asm-arm/processor.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
index aa642e3ab2..3ca67f8157 100644
--- a/xen/include/asm-arm/processor.h
+++ b/xen/include/asm-arm/processor.h
@@ -58,6 +58,7 @@
 #define ARM_CPU_PART_CORTEX_A73     0xD09
 #define ARM_CPU_PART_CORTEX_A75     0xD0A
 #define ARM_CPU_PART_CORTEX_A76     0xD0B
+#define ARM_CPU_PART_NEOVERSE_N1    0xD0C
 
 #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12)
 #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17)
@@ -68,6 +69,7 @@
 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
+#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
 
 /* MPIDR Multiprocessor Affinity Register */
 #define _MPIDR_UP           (30)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY7I-0006Nc-Ve; Tue, 22 Sep 2020 02:33:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY7I-0006NV-4a
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:16 +0000
X-Inumbo-ID: 4d282eae-b2f2-41ab-8c47-4ef5de13dd46
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4d282eae-b2f2-41ab-8c47-4ef5de13dd46;
 Tue, 22 Sep 2020 02:33:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=YGQsRUIebHDrASqHS1bAP6tPiu590PBGbOen5M6ry3g=; b=GWf4wNK63cUd/YmltM/6UpA0EA
 S1ftLs2GXId2aDrB9gTL8bLUTWUH1hb4JU7dHRLS99+EMAZQFkXoMpYTxownSmjV1B297U1C0l4kE
 aWtuEq0JjspVuCYUqgY5xIerJjxx99D8ufL4NwvIJVF7mjjkUMJrC3xg+fksPuG6nNNc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7H-0007y8-70
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7H-0001JF-5z
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/arm: Enable CPU Erratum 1165522 for Neoverse
Message-Id: <E1kKY7H-0001JF-5z@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4a0c174c17673590711358bdf89289eedcbe2837
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:39 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:25:23 2020 -0700

    xen/arm: Enable CPU Erratum 1165522 for Neoverse
    
    Enable CPU erratum of Speculative AT on the Neoverse N1 processor
    versions r0p0 to r2p0.
    Also Fix Cortex A76 Erratum string which had a wrong errata number.
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 858c0be8c2fa4125a0fa0acaa03ae730e5c7cb3c)
---
 xen/arch/arm/cpuerrata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index da72b02442..9f7169a6a6 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -475,9 +475,15 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .matches = has_ssbd_mitigation,
     },
 #endif
+    {
+        /* Neoverse r0p0 - r2p0 */
+        .desc = "ARM erratum 1165522",
+        .capability = ARM64_WORKAROUND_AT_SPECULATE,
+        MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 2 << MIDR_VARIANT_SHIFT),
+    },
     {
         /* Cortex-A76 r0p0 - r2p0 */
-        .desc = "ARM erratum 116522",
+        .desc = "ARM erratum 1165522",
         .capability = ARM64_WORKAROUND_AT_SPECULATE,
         MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT),
     },
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY7T-0006Oi-0u; Tue, 22 Sep 2020 02:33:27 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY7S-0006OW-0a
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:26 +0000
X-Inumbo-ID: 96c8c532-71d0-4c6d-9509-f4b017b7d5d2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 96c8c532-71d0-4c6d-9509-f4b017b7d5d2;
 Tue, 22 Sep 2020 02:33:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=w+XJYj/1nb/W4iCjbD7FcOdzMsEmDiTsYooGTW55Py4=; b=jZMyz+HCNjrI+4PlTzVffZrymq
 OMF52+RnnDyJ4/FXVa8+E1oQynV+QeVhIilZqleGuoJkVhxvQZsYxfzqkDR1NJFnf+oxdRPJLgZ5W
 e9GU0/N1sePAOd0gaApFSCsprZjH0ne+wv7bMPfzXpQvvEbWUHxoIGdXT7xZEKa11kTw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7R-0007yK-A5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7R-0001Jn-9A
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/arm: Update silicon-errata.txt with the
 Neovers AT erratum
Message-Id: <E1kKY7R-0001Jn-9A@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4fb1ad782dd170cac7a3868e5aba583c8abe38a0
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:25:30 2020 -0700

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    (cherry picked from commit 1814a626fb5811184eda64fe22f0055df4600211)
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY7e-0006QA-2Y; Tue, 22 Sep 2020 02:33:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY7c-0006Py-KI
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:36 +0000
X-Inumbo-ID: a7c5bdfe-1e81-4231-9f29-41367a78eed6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a7c5bdfe-1e81-4231-9f29-41367a78eed6;
 Tue, 22 Sep 2020 02:33:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eWm1qYl+dRayHkvCopg3OB0ZIomnBg17RchTCzejn/A=; b=v0IRMdKO7zpRwW7bObcKHdcwrb
 fRgsXX5HbXl6+StIaWBoclcONgXbXKQN6Xm01/0odFoRPPxTQh2Dsug9OhSzLR5aJdq0J+yqJiGGr
 w/wFoPaMS/mI+W86qCJEgsoZvpZGqlM0/yyq6zIj03zNAGrplEUcVpShzGQdEZiqBPZc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7b-0007yT-Di
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7b-0001KJ-CL
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kKY7b-0001KJ-CL@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit bd63ab538be07e96f9b594cd927fd7c4825b4436
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:25:36 2020 -0700

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 968bb86d04913f52d7678a842474f2a674a8b23e)
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index 9af5666628..6bff5ce131 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY7o-0006RC-44; Tue, 22 Sep 2020 02:33:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY7m-0006Qz-Ej
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:46 +0000
X-Inumbo-ID: b782ad13-6c71-4160-909c-6846f58a6ff7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b782ad13-6c71-4160-909c-6846f58a6ff7;
 Tue, 22 Sep 2020 02:33:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GpaWktRYXUTZYkWGVkbMMiRH7Xtvl7AankZmS++U2OM=; b=gH5wppjFxT+Aox8eTMUwhgiA6X
 2y6o3rirxhIblfHUfeh/VEJrYVVG2FSOGvn0LuWOj+NFoqgLxaBmh9p7aqebKTvDOsOMPxPLi49TJ
 KFNgPHteyJrKtkiQmQuEs5IasD7RwiF5vZwY2EivBEGXVpmSFrR0QWTe46L+QUpEdc98=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7l-0007ye-Gc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7l-0001L3-Fl
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/arm: cmpxchg: Add missing memory barriers in
 __cmpxchg_mb_timeout()
Message-Id: <E1kKY7l-0001L3-Fl@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit aa1d9a7dbfe07905f0b7218bcd433a513f762eb9
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Jul 29 14:50:37 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:25:43 2020 -0700

    xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()
    
    The function __cmpxchg_mb_timeout() was intended to have the same
    semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were
    not added when first implemented.
    
    There is no known issue with the existing callers, but the barriers are
    added given this is the expected semantics in Xen.
    
    The issue was introduced by XSA-295.
    
    Backport: 4.8+
    Fixes: 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    (cherry picked from commit d501ef90ae7f2a79130ea89acb3d6d1792972934)
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 49ca2a0d7a..0770f272ee 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index 5bc2e1f786..fc5c60f0bd 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:33:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:33:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY7y-0006Sm-5f; Tue, 22 Sep 2020 02:33:58 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY7x-0006Se-9U
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:57 +0000
X-Inumbo-ID: 7e348c3b-0b1b-404f-9833-8365e0252fc0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7e348c3b-0b1b-404f-9833-8365e0252fc0;
 Tue, 22 Sep 2020 02:33:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=X54ko3FU8CAiJYDq/hh18nBBRDL7UNnhtSGohIkmYpE=; b=PMUhip77ZRCyFRLD5tUmlCekNk
 1Zr2eNi8u2WLOWzN5ZdSbcB7uENw/s7mGX0GEmUPJtroZ7LP52/gsrDj3oemObCz/eDqYEb4eIf9y
 LMJ+GK3g/lq/NhDvw1pFS4jaSFFpM/2WdGH6W3PhFfG4WWMMui2sPELAYmLp38Rq2bs8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7w-0007ym-E5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY7w-0001MV-DG
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:33:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] arm: Add Neoverse N1 processor identification
Message-Id: <E1kKY7w-0001MV-DG@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:33:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 81564c40ead9781c30baf30cb4cf2fbf242a0818
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:38 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:27:58 2020 -0700

    arm: Add Neoverse N1 processor identification
    
    Add MIDR and CPU part numbers for Neoverse N1
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 3b418b33265402aab0cb1bf2b745a25724bae2d8)
---
 xen/include/asm-arm/processor.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
index 783f033813..04838fe6fc 100644
--- a/xen/include/asm-arm/processor.h
+++ b/xen/include/asm-arm/processor.h
@@ -53,6 +53,7 @@
 #define ARM_CPU_PART_CORTEX_A73     0xD09
 #define ARM_CPU_PART_CORTEX_A75     0xD0A
 #define ARM_CPU_PART_CORTEX_A76     0xD0B
+#define ARM_CPU_PART_NEOVERSE_N1    0xD0C
 
 #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12)
 #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17)
@@ -63,6 +64,7 @@
 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
+#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
 
 /* MPIDR Multiprocessor Affinity Register */
 #define _MPIDR_UP           (30)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:34:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:34:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY88-0006Tn-78; Tue, 22 Sep 2020 02:34:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY87-0006Td-AI
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:07 +0000
X-Inumbo-ID: 710f92bf-b3ab-4991-870a-a3adea415016
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 710f92bf-b3ab-4991-870a-a3adea415016;
 Tue, 22 Sep 2020 02:34:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Qp7MxWBq2WV2nsAUXsxWNQ5arJVUHgAK244127X/J+4=; b=oojR1lMohaQVEujN9hhNWTHLPz
 Vl1IN7fbmCtjbai1Hj9MlV9lIz9y88unjj5m08xZuJ3F0P5O5Ku3z0wx2zADIwBfHZ5yaUSYPbJeS
 GLzbm2s3zeGyFs/VRAEZoIYX0LIq0R1DQJo/ySdzi9hs5nb8AkWfUDpkS1RTH28oTlM8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY86-0007zA-HL
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY86-0001NV-GR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/arm: Enable CPU Erratum 1165522 for Neoverse
Message-Id: <E1kKY86-0001NV-GR@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:34:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 76d934929b6d91b886afbc45deaac95bfc90457a
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:39 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:03 2020 -0700

    xen/arm: Enable CPU Erratum 1165522 for Neoverse
    
    Enable CPU erratum of Speculative AT on the Neoverse N1 processor
    versions r0p0 to r2p0.
    Also Fix Cortex A76 Erratum string which had a wrong errata number.
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 858c0be8c2fa4125a0fa0acaa03ae730e5c7cb3c)
---
 xen/arch/arm/cpuerrata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index edbe789736..b254b98657 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -489,9 +489,15 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .matches = has_ssbd_mitigation,
     },
 #endif
+    {
+        /* Neoverse r0p0 - r2p0 */
+        .desc = "ARM erratum 1165522",
+        .capability = ARM64_WORKAROUND_AT_SPECULATE,
+        MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 2 << MIDR_VARIANT_SHIFT),
+    },
     {
         /* Cortex-A76 r0p0 - r2p0 */
-        .desc = "ARM erratum 116522",
+        .desc = "ARM erratum 1165522",
         .capability = ARM64_WORKAROUND_AT_SPECULATE,
         MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT),
     },
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:34:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:34:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY8J-0006Us-8f; Tue, 22 Sep 2020 02:34:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY8H-0006Uf-ID
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:17 +0000
X-Inumbo-ID: a12cfaae-2ae4-46a2-9f65-93bc3962e917
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a12cfaae-2ae4-46a2-9f65-93bc3962e917;
 Tue, 22 Sep 2020 02:34:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UivpBkCGCcvY5hdbpvRStD/A4J0PWCnh5xG8dVn+Clw=; b=6ruPUdK9255r88l1GTZm853MJ2
 rQdQ7VCfmel/SW5RJCBvgYm+X8loxN63LoeRDeVjPM/u0TDKAQJwpj+s1Zm9ZGkFBgsaMaIprlXyd
 RjrUPDh9ZcN2S4roVijFc4E1iZOhallGxpalTqf2HRkRdfHpVmr6CNUHYiwU3aSX1Emk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8G-0007zy-Kq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8G-0001Oa-JW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/arm: Update silicon-errata.txt with the
 Neovers AT erratum
Message-Id: <E1kKY8G-0001Oa-JW@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:34:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit caebaf3751e169af15f494bcbbdbfc0ae37648ba
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:07 2020 -0700

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    (cherry picked from commit 1814a626fb5811184eda64fe22f0055df4600211)
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:34:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:34:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY8S-0006Vy-BN; Tue, 22 Sep 2020 02:34:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY8R-0006Vp-Gf
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:27 +0000
X-Inumbo-ID: 49421b6c-d0e8-4648-ab08-1496898c4ebb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 49421b6c-d0e8-4648-ab08-1496898c4ebb;
 Tue, 22 Sep 2020 02:34:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=fbk2T/PceXclMW6Fg98nOR/4KyDXsRYgA33/GcCnd/0=; b=c14HUNoZr1gjPceAE9QK9yCPuJ
 Py0SY5/I+80W1/8SUKdjRb4x7BR4RNaTxk2qnmBzxnN6mX9XIlPFhR6C3OeIV3p9Xk+BxPD/9uOWU
 pgq7rvl/CzNIr8hKlstdpEopf4NvxRWxrP8XSZbQCQLF22bzgAkoO9dTVuxwN2/S5fVI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8Q-000807-Nf
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8Q-0001Pl-Mx
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kKY8Q-0001Pl-Mx@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:34:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a81e6557b9864e4288a63cbbbd3a6f98d3a74862
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:12 2020 -0700

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 968bb86d04913f52d7678a842474f2a674a8b23e)
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index a7b726d863..60e677d842 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 02:34:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 02:34:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKY8x-0006Xd-Dw; Tue, 22 Sep 2020 02:34:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKY8v-0006XY-Nj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:57 +0000
X-Inumbo-ID: 1b6463a3-b932-4fcb-8fdf-f7bf88063add
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1b6463a3-b932-4fcb-8fdf-f7bf88063add;
 Tue, 22 Sep 2020 02:34:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=HPBPqFnvDJ64hdVwom/5NebP9utbE6p1OPilK0nTg7A=; b=c2z2SPs2I9zu8Tmj4t8TlZwug0
 H5JKVGDFxoF2Xfvk1/gMXUPMY/Hg3T79AWwyBNKqXvl2VD7dPMnFxoIkR3fMQM3W4KI6KDFFihtr2
 odDnMfHUKhNMHmMREART/Hb/gIvItWY71g3iwe4AZn82amIbA4916MLzpNpJWM/IJuFs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8a-00080E-Qi
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKY8a-0001Qj-Pv
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 02:34:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/arm: cmpxchg: Add missing memory barriers in
 __cmpxchg_mb_timeout()
Message-Id: <E1kKY8a-0001Qj-Pv@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 02:34:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0446e3db13671032b05d19f6117d902f5c5c76fa
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Jul 29 14:50:37 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:23 2020 -0700

    xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()
    
    The function __cmpxchg_mb_timeout() was intended to have the same
    semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were
    not added when first implemented.
    
    There is no known issue with the existing callers, but the barriers are
    added given this is the expected semantics in Xen.
    
    The issue was introduced by XSA-295.
    
    Backport: 4.8+
    Fixes: 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    (cherry picked from commit d501ef90ae7f2a79130ea89acb3d6d1792972934)
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 49ca2a0d7a..0770f272ee 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index 5bc2e1f786..fc5c60f0bd 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 08:33:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 08:33:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKdjX-0006ER-MB; Tue, 22 Sep 2020 08:33:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKdjW-0006EE-Rs
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:06 +0000
X-Inumbo-ID: 1189fbbc-84d9-4784-b28b-d02df94cd83e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1189fbbc-84d9-4784-b28b-d02df94cd83e;
 Tue, 22 Sep 2020 08:33:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PJDHVmMSh0jYjBUynQXGVjCMAycOm4MssccPfuaVfPU=; b=QQnqE1u8EVwOHiRMxi82Lh1hSV
 e2c/UOoc1IFn5FillGFlNgwU9qPpWshD62npole5OgItYO/SxZk8b1VU0XdG6Munh4tjJ2P/K05nj
 HKiVm5PUtqm3l2zJ7Mk62BbChZopuTa35nFRd/KzEyIQTfxcJEa+PnutjQHFuN6JGMJE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjV-0000ON-7w
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjV-00083l-63
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] build: use if_changed more consistently (and correctly)
 for prelink*.o
Message-Id: <E1kKdjV-00083l-63@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 08:33:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit dd2cfba88c3d0e144ffec07c6b5b86e54a9d98a9
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 10:19:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 10:19:38 2020 +0200

    build: use if_changed more consistently (and correctly) for prelink*.o
    
    Switch to $(call if_changed,ld) where possible; presumably not doing so
    in e321576f4047 ("xen/build: start using if_changed") right away was an
    oversight, as it did for Arm in (just) one case. It failed to add
    prelink.o to $(targets), though, causing - judging from the observed
    behavior on x86 - undue rebuilds of the final binary (because of
    prelink.o getting rebuild for $(cmd_prelink.o) being empty, in turn
    because of .prelink.o.cmd not getting read) during "make install-xen".
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/Makefile |  4 +++-
 xen/arch/x86/Makefile | 18 ++++++++++--------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 51173d9712..296c5e68bb 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -95,12 +95,14 @@ prelink_lto.o: $(ALL_OBJS)
 
 # Link it with all the binary objects
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
-	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
+	$(call if_changed,ld)
 else
 prelink.o: $(ALL_OBJS) FORCE
 	$(call if_changed,ld)
 endif
 
+targets += prelink.o
+
 $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 74152f2a0d..9b368632fb 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -136,19 +136,21 @@ prelink_lto.o: $(ALL_OBJS)
 	$(LD_LTO) -r -o $@ $^
 
 # Link it with all the binary objects
-prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y)
-	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
+prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y) FORCE
+	$(call if_changed,ld)
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
-	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o FORCE
+	$(call if_changed,ld)
 else
-prelink.o: $(ALL_OBJS) $(EFI_OBJS-y)
-	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
+prelink.o: $(ALL_OBJS) $(EFI_OBJS-y) FORCE
+	$(call if_changed,ld)
 
-prelink-efi.o: $(ALL_OBJS)
-	$(LD) $(XEN_LDFLAGS) -r -o $@ $^
+prelink-efi.o: $(ALL_OBJS) FORCE
+	$(call if_changed,ld)
 endif
 
+targets += prelink.o prelink-efi.o
+
 $(TARGET)-syms: prelink.o xen.lds
 	$(LD) $(XEN_LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 08:33:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 08:33:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKdjh-0006Es-Nj; Tue, 22 Sep 2020 08:33:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKdjg-0006En-K0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:16 +0000
X-Inumbo-ID: 803b1f24-d16f-45ee-8aae-c38f2782cf2c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 803b1f24-d16f-45ee-8aae-c38f2782cf2c;
 Tue, 22 Sep 2020 08:33:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=bSejQ3+7tfCarXCyBXiNXyLMOmIpnN9ZZO3GsZuGklY=; b=oBKjQ6xMEE05v6fbXe9515vjYZ
 zTmEdzq8xKGObS3hbrIxVTXy8ymVw3RQJzaydDaX8XFI6r4tojcjLvg8Q36ue/S5AA8rAV9sGWeTK
 Q1Dc55/qP475Z4IP62OBIxVAio5wriX91HcRiGed0VJk6FF3KweDi3tSZcjOgS70zxYk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjf-0000OW-D2
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjf-00084P-AQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/iommu: convert VT-d code to use new page table
 allocator
Message-Id: <E1kKdjf-00084P-AQ@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 08:33:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3eef6d07d722e90624fa692cdb9b76ebb2555cce
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Sep 22 10:20:39 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 10:20:39 2020 +0200

    x86/iommu: convert VT-d code to use new page table allocator
    
    This patch converts the VT-d code to use the new IOMMU page table allocator
    function. This allows all the free-ing code to be removed (since it is now
    handled by the general x86 code) which reduces TLB and cache thrashing as well
    as shortening the code.
    
    The scope of the mapping_lock in intel_iommu_quarantine_init() has also been
    increased slightly; it should have always covered accesses to
    'arch.vtd.pgd_maddr'.
    
    NOTE: The common IOMMU needs a slight modification to avoid scheduling the
          cleanup tasklet if the free_page_table() method is not present (since
          the tasklet will unconditionally call it).
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/drivers/passthrough/iommu.c     |   6 ++-
 xen/drivers/passthrough/vtd/iommu.c | 101 +++++++++++++-----------------------
 2 files changed, 39 insertions(+), 68 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 1d644844ab..2b1db8022c 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -225,8 +225,10 @@ static void iommu_teardown(struct domain *d)
 {
     struct domain_iommu *hd = dom_iommu(d);
 
-    hd->platform_ops->teardown(d);
-    tasklet_schedule(&iommu_pt_cleanup_tasklet);
+    iommu_vcall(hd->platform_ops, teardown, d);
+
+    if ( hd->platform_ops->free_page_table )
+        tasklet_schedule(&iommu_pt_cleanup_tasklet);
 }
 
 void iommu_domain_destroy(struct domain *d)
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index 94e0455a4d..607e8b5e65 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -265,10 +265,15 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, u64 addr, int alloc)
 
     addr &= (((u64)1) << addr_width) - 1;
     ASSERT(spin_is_locked(&hd->arch.mapping_lock));
-    if ( !hd->arch.vtd.pgd_maddr &&
-         (!alloc ||
-          ((hd->arch.vtd.pgd_maddr = alloc_pgtable_maddr(1, hd->node)) == 0)) )
-        goto out;
+    if ( !hd->arch.vtd.pgd_maddr )
+    {
+        struct page_info *pg;
+
+        if ( !alloc || !(pg = iommu_alloc_pgtable(domain)) )
+            goto out;
+
+        hd->arch.vtd.pgd_maddr = page_to_maddr(pg);
+    }
 
     parent = (struct dma_pte *)map_vtd_domain_page(hd->arch.vtd.pgd_maddr);
     while ( level > 1 )
@@ -279,13 +284,16 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, u64 addr, int alloc)
         pte_maddr = dma_pte_addr(*pte);
         if ( !pte_maddr )
         {
+            struct page_info *pg;
+
             if ( !alloc )
                 break;
 
-            pte_maddr = alloc_pgtable_maddr(1, hd->node);
-            if ( !pte_maddr )
+            pg = iommu_alloc_pgtable(domain);
+            if ( !pg )
                 break;
 
+            pte_maddr = page_to_maddr(pg);
             dma_set_pte_addr(*pte, pte_maddr);
 
             /*
@@ -675,45 +683,6 @@ static void dma_pte_clear_one(struct domain *domain, uint64_t addr,
     unmap_vtd_domain_page(page);
 }
 
-static void iommu_free_pagetable(u64 pt_maddr, int level)
-{
-    struct page_info *pg = maddr_to_page(pt_maddr);
-
-    if ( pt_maddr == 0 )
-        return;
-
-    PFN_ORDER(pg) = level;
-    spin_lock(&iommu_pt_cleanup_lock);
-    page_list_add_tail(pg, &iommu_pt_cleanup_list);
-    spin_unlock(&iommu_pt_cleanup_lock);
-}
-
-static void iommu_free_page_table(struct page_info *pg)
-{
-    unsigned int i, next_level = PFN_ORDER(pg) - 1;
-    u64 pt_maddr = page_to_maddr(pg);
-    struct dma_pte *pt_vaddr, *pte;
-
-    PFN_ORDER(pg) = 0;
-    pt_vaddr = (struct dma_pte *)map_vtd_domain_page(pt_maddr);
-
-    for ( i = 0; i < PTE_NUM; i++ )
-    {
-        pte = &pt_vaddr[i];
-        if ( !dma_pte_present(*pte) )
-            continue;
-
-        if ( next_level >= 1 )
-            iommu_free_pagetable(dma_pte_addr(*pte), next_level);
-
-        dma_clear_pte(*pte);
-        iommu_sync_cache(pte, sizeof(struct dma_pte));
-    }
-
-    unmap_vtd_domain_page(pt_vaddr);
-    free_pgtable_maddr(pt_maddr);
-}
-
 static int iommu_set_root_entry(struct vtd_iommu *iommu)
 {
     u32 sts;
@@ -1748,16 +1717,7 @@ static void iommu_domain_teardown(struct domain *d)
         xfree(mrmrr);
     }
 
-    ASSERT(is_iommu_enabled(d));
-
-    if ( iommu_use_hap_pt(d) )
-        return;
-
-    spin_lock(&hd->arch.mapping_lock);
-    iommu_free_pagetable(hd->arch.vtd.pgd_maddr,
-                         agaw_to_level(hd->arch.vtd.agaw));
     hd->arch.vtd.pgd_maddr = 0;
-    spin_unlock(&hd->arch.mapping_lock);
 }
 
 static int __must_check intel_iommu_map_page(struct domain *d, dfn_t dfn,
@@ -2669,23 +2629,28 @@ static void vtd_dump_p2m_table(struct domain *d)
 static int __init intel_iommu_quarantine_init(struct domain *d)
 {
     struct domain_iommu *hd = dom_iommu(d);
+    struct page_info *pg;
     struct dma_pte *parent;
     unsigned int agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
     unsigned int level = agaw_to_level(agaw);
-    int rc;
+    int rc = 0;
+
+    spin_lock(&hd->arch.mapping_lock);
 
     if ( hd->arch.vtd.pgd_maddr )
     {
         ASSERT_UNREACHABLE();
-        return 0;
+        goto out;
     }
 
-    spin_lock(&hd->arch.mapping_lock);
+    pg = iommu_alloc_pgtable(d);
 
-    hd->arch.vtd.pgd_maddr = alloc_pgtable_maddr(1, hd->node);
-    if ( !hd->arch.vtd.pgd_maddr )
+    rc = -ENOMEM;
+    if ( !pg )
         goto out;
 
+    hd->arch.vtd.pgd_maddr = page_to_maddr(pg);
+
     parent = map_vtd_domain_page(hd->arch.vtd.pgd_maddr);
     while ( level )
     {
@@ -2697,10 +2662,12 @@ static int __init intel_iommu_quarantine_init(struct domain *d)
          * page table pages, and the resulting allocations are always
          * zeroed.
          */
-        maddr = alloc_pgtable_maddr(1, hd->node);
-        if ( !maddr )
-            break;
+        pg = iommu_alloc_pgtable(d);
+
+        if ( !pg )
+            goto out;
 
+        maddr = page_to_maddr(pg);
         for ( offset = 0; offset < PTE_NUM; offset++ )
         {
             struct dma_pte *pte = &parent[offset];
@@ -2716,13 +2683,16 @@ static int __init intel_iommu_quarantine_init(struct domain *d)
     }
     unmap_vtd_domain_page(parent);
 
+    rc = 0;
+
  out:
     spin_unlock(&hd->arch.mapping_lock);
 
-    rc = iommu_flush_iotlb_all(d);
+    if ( !rc )
+        rc = iommu_flush_iotlb_all(d);
 
-    /* Pages leaked in failure case */
-    return level ? -ENOMEM : rc;
+    /* Pages may be leaked in failure case */
+    return rc;
 }
 
 static struct iommu_ops __initdata vtd_ops = {
@@ -2737,7 +2707,6 @@ static struct iommu_ops __initdata vtd_ops = {
     .map_page = intel_iommu_map_page,
     .unmap_page = intel_iommu_unmap_page,
     .lookup_page = intel_iommu_lookup_page,
-    .free_page_table = iommu_free_page_table,
     .reassign_device = reassign_device_ownership,
     .get_device_group_id = intel_iommu_group_id,
     .enable_x2apic = intel_iommu_enable_eim,
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 08:33:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 08:33:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKdjs-0006Fw-PH; Tue, 22 Sep 2020 08:33:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKdjs-0006Fm-8Q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:28 +0000
X-Inumbo-ID: 9fb76b04-181d-4152-a1d9-ec1ac05d7632
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9fb76b04-181d-4152-a1d9-ec1ac05d7632;
 Tue, 22 Sep 2020 08:33:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GtB4+I3yzGeJ5nGlmbNHZBSsOYK4aIdmrp42W9gdkiw=; b=abe/KlCnQlDu37JgaSSB2JGLWf
 t5Iyv2rfPxt2AjOc/s+LVoZFZEPXhKfJEbk1WxdbVjKWoHveLa40M0Vuy2VXLxzzj7SAun6pge4qJ
 ldYwaHYJZ9WLduseMRctr1ZZZxRNslR1FIANvkLUFpAaCFug1BbxNzqvQJ6aLy7JdgC0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjp-0000P5-G5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjp-00085H-FE
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] iommu: remove unused iommu_ops method and tasklet
Message-Id: <E1kKdjp-00085H-FE@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 08:33:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b5622eb62793a826098fa0bd31787fad43ad99cc
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Sep 22 10:21:13 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 10:21:13 2020 +0200

    iommu: remove unused iommu_ops method and tasklet
    
    The VT-d and AMD IOMMU implementations both use the general x86 IOMMU page
    table allocator and ARM always shares page tables with CPU. Hence there is no
    need to retain the free_page_table() method or the tasklet which invokes it.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/drivers/passthrough/iommu.c | 25 -------------------------
 xen/include/xen/iommu.h         |  2 --
 2 files changed, 27 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 2b1db8022c..660dc5deb2 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -49,10 +49,6 @@ bool_t __read_mostly amd_iommu_perdev_intremap = 1;
 
 DEFINE_PER_CPU(bool_t, iommu_dont_flush_iotlb);
 
-DEFINE_SPINLOCK(iommu_pt_cleanup_lock);
-PAGE_LIST_HEAD(iommu_pt_cleanup_list);
-static struct tasklet iommu_pt_cleanup_tasklet;
-
 static int __init parse_iommu_param(const char *s)
 {
     const char *ss;
@@ -226,9 +222,6 @@ static void iommu_teardown(struct domain *d)
     struct domain_iommu *hd = dom_iommu(d);
 
     iommu_vcall(hd->platform_ops, teardown, d);
-
-    if ( hd->platform_ops->free_page_table )
-        tasklet_schedule(&iommu_pt_cleanup_tasklet);
 }
 
 void iommu_domain_destroy(struct domain *d)
@@ -368,23 +361,6 @@ int iommu_lookup_page(struct domain *d, dfn_t dfn, mfn_t *mfn,
     return iommu_call(hd->platform_ops, lookup_page, d, dfn, mfn, flags);
 }
 
-static void iommu_free_pagetables(void *unused)
-{
-    do {
-        struct page_info *pg;
-
-        spin_lock(&iommu_pt_cleanup_lock);
-        pg = page_list_remove_head(&iommu_pt_cleanup_list);
-        spin_unlock(&iommu_pt_cleanup_lock);
-        if ( !pg )
-            return;
-        iommu_vcall(iommu_get_ops(), free_page_table, pg);
-    } while ( !softirq_pending(smp_processor_id()) );
-
-    tasklet_schedule_on_cpu(&iommu_pt_cleanup_tasklet,
-                            cpumask_cycle(smp_processor_id(), &cpu_online_map));
-}
-
 int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsigned int page_count,
                       unsigned int flush_flags)
 {
@@ -508,7 +484,6 @@ int __init iommu_setup(void)
 #ifndef iommu_intremap
         printk("Interrupt remapping %sabled\n", iommu_intremap ? "en" : "dis");
 #endif
-        tasklet_init(&iommu_pt_cleanup_tasklet, iommu_free_pagetables, NULL);
     }
 
     return rc;
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 3272874958..1831dc66b0 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -263,8 +263,6 @@ struct iommu_ops {
     int __must_check (*lookup_page)(struct domain *d, dfn_t dfn, mfn_t *mfn,
                                     unsigned int *flags);
 
-    void (*free_page_table)(struct page_info *);
-
 #ifdef CONFIG_X86
     int (*enable_x2apic)(void);
     void (*disable_x2apic)(void);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 08:33:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 08:33:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKdk1-0006H3-Qn; Tue, 22 Sep 2020 08:33:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKdk0-0006Gt-Go
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:36 +0000
X-Inumbo-ID: 4276cc3c-e760-4019-824f-2ecc98b3fe92
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4276cc3c-e760-4019-824f-2ecc98b3fe92;
 Tue, 22 Sep 2020 08:33:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=jKi+s0H2EG2Qi/HkZ74TsRqjEUF3e7fjSKyC4hJTIKk=; b=65cfmtPaJgFWrPkn+uM94UpXkP
 +goD0zP/vZwVmwt6DuBaorSd8I+flC+bodviQZsC/ztJ1BA0olFkaHSScZQJpjRBA5Jy+s+27+MD8
 H4zwksATsYgl1OLli0ZqbnwyO1IMwvkIlreN3M4eXZ8E+OR9GZq/Lk9gidhRwOxvnKh4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjz-0000PF-Ji
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdjz-000866-IF
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] iommu: flush I/O TLB if iommu_map() or iommu_unmap()
 fail
Message-Id: <E1kKdjz-000866-IF@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 08:33:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0229adb138d732f579e80c96a032b19e692d6796
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Sep 22 10:21:55 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 10:21:55 2020 +0200

    iommu: flush I/O TLB if iommu_map() or iommu_unmap() fail
    
    This patch adds a full I/O TLB flush to the error paths of iommu_map() and
    iommu_unmap().
    
    Without this change callers need constructs such as:
    
    rc = iommu_map/unmap(...)
    err = iommu_flush(...)
    if ( !rc )
      rc = err;
    
    With this change, it can be simplified to:
    
    rc = iommu_map/unmap(...)
    if ( !rc )
      rc = iommu_flush(...)
    
    because, if the map or unmap fails the flush will be unnecessary. This saves
    a stack variable and generally makes the call sites tidier.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/drivers/passthrough/iommu.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 660dc5deb2..eb65631d59 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -274,6 +274,13 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
         break;
     }
 
+    /*
+     * Something went wrong so, if we were dealing with more than a single
+     * page, flush everything and clear flush flags.
+     */
+    if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) )
+        *flush_flags = 0;
+
     return rc;
 }
 
@@ -283,14 +290,8 @@ int iommu_legacy_map(struct domain *d, dfn_t dfn, mfn_t mfn,
     unsigned int flush_flags = 0;
     int rc = iommu_map(d, dfn, mfn, page_order, flags, &flush_flags);
 
-    if ( !this_cpu(iommu_dont_flush_iotlb) )
-    {
-        int err = iommu_iotlb_flush(d, dfn, (1u << page_order),
-                                    flush_flags);
-
-        if ( !rc )
-            rc = err;
-    }
+    if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
+        rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
 
     return rc;
 }
@@ -330,6 +331,13 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned int page_order,
         }
     }
 
+    /*
+     * Something went wrong so, if we were dealing with more than a single
+     * page, flush everything and clear flush flags.
+     */
+    if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) )
+        *flush_flags = 0;
+
     return rc;
 }
 
@@ -338,14 +346,8 @@ int iommu_legacy_unmap(struct domain *d, dfn_t dfn, unsigned int page_order)
     unsigned int flush_flags = 0;
     int rc = iommu_unmap(d, dfn, page_order, &flush_flags);
 
-    if ( !this_cpu(iommu_dont_flush_iotlb) )
-    {
-        int err = iommu_iotlb_flush(d, dfn, (1u << page_order),
-                                    flush_flags);
-
-        if ( !rc )
-            rc = err;
-    }
+    if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
+        rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
 
     return rc;
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 08:33:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 08:33:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKdkB-0006IT-Tv; Tue, 22 Sep 2020 08:33:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKdkB-0006IL-9y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:47 +0000
X-Inumbo-ID: f39db7d7-ecf1-4b73-9be5-3e54343da3d6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f39db7d7-ecf1-4b73-9be5-3e54343da3d6;
 Tue, 22 Sep 2020 08:33:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PzBJQZGkcrRrLR47Y2zvB1X6DpulGZ+Z5IPDU7DxBcA=; b=SKafZktb00JEr1Gk0FpsgGY3jy
 VOcaK+SZ9TKXbU3xHH9lhfdnYXaDNoD+2qA9teRDqesRm69nl4ET459ay+V6PiLag+ewDqJBp7QBD
 yajgIg7Ciyk0phyPLTeK9mfiKTqaFfT8klxcM2RvmZl2wUeShxJodb/mKHPvSw+PquVE=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdk9-0000PS-P2
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKdk9-00086i-NW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 08:33:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] iommu: make map and unmap take a page count,
 similar to flush
Message-Id: <E1kKdk9-00086i-NW@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 08:33:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 68a8aa5d7264dcb04b2c56fad24bdd5192fe5394
Author:     Paul Durrant <pdurrant@amazon.com>
AuthorDate: Tue Sep 22 10:22:30 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 10:22:30 2020 +0200

    iommu: make map and unmap take a page count, similar to flush
    
    At the moment iommu_map() and iommu_unmap() take a page order rather than a
    count, whereas iommu_iotlb_flush() takes a page count rather than an order.
    This patch makes them consistent with each other, opting for a page count since
    CPU page orders are not necessarily the same as those of an IOMMU.
    
    NOTE: The 'page_count' parameter is also made an unsigned long in all the
          aforementioned functions.
    
    Signed-off-by: Paul Durrant <pdurrant@amazon.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Julien Grall <julien@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/mm.c                        |  8 +++++---
 xen/arch/x86/mm/p2m-ept.c                |  6 +++---
 xen/arch/x86/mm/p2m-pt.c                 |  4 ++--
 xen/arch/x86/mm/p2m.c                    |  5 +++--
 xen/arch/x86/x86_64/mm.c                 |  4 ++--
 xen/common/grant_table.c                 |  6 +++---
 xen/drivers/passthrough/amd/iommu.h      |  2 +-
 xen/drivers/passthrough/amd/iommu_map.c  |  4 ++--
 xen/drivers/passthrough/arm/ipmmu-vmsa.c |  2 +-
 xen/drivers/passthrough/arm/smmu.c       |  2 +-
 xen/drivers/passthrough/iommu.c          | 35 +++++++++++++++-----------------
 xen/drivers/passthrough/vtd/iommu.c      |  4 ++--
 xen/drivers/passthrough/x86/iommu.c      |  2 +-
 xen/include/xen/iommu.h                  | 12 +++++------
 14 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 2c13a2d8e7..d1cfc8fb4a 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2441,7 +2441,7 @@ static int cleanup_page_mappings(struct page_info *page)
 
         if ( d && unlikely(need_iommu_pt_sync(d)) && is_pv_domain(d) )
         {
-            int rc2 = iommu_legacy_unmap(d, _dfn(mfn), PAGE_ORDER_4K);
+            int rc2 = iommu_legacy_unmap(d, _dfn(mfn), 1u << PAGE_ORDER_4K);
 
             if ( !rc )
                 rc = rc2;
@@ -2968,9 +2968,11 @@ static int _get_page_type(struct page_info *page, unsigned long type,
             mfn_t mfn = page_to_mfn(page);
 
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)), PAGE_ORDER_4K);
+                rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)),
+                                        1ul << PAGE_ORDER_4K);
             else
-                rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn, PAGE_ORDER_4K,
+                rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn,
+                                      1ul << PAGE_ORDER_4K,
                                       IOMMUF_readable | IOMMUF_writable);
 
             if ( unlikely(rc) )
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index b8154a7ecc..12cf38f6eb 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -843,14 +843,14 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_use_hap_pt(d) )
-            rc = iommu_iotlb_flush(d, _dfn(gfn), (1u << order),
+            rc = iommu_iotlb_flush(d, _dfn(gfn), 1ul << order,
                                    (iommu_flags ? IOMMU_FLUSHF_added : 0) |
                                    (vtd_pte_present ? IOMMU_FLUSHF_modified
                                                     : 0));
         else if ( need_iommu_pt_sync(d) )
             rc = iommu_flags ?
-                iommu_legacy_map(d, _dfn(gfn), mfn, order, iommu_flags) :
-                iommu_legacy_unmap(d, _dfn(gfn), order);
+                iommu_legacy_map(d, _dfn(gfn), mfn, 1ul << order, iommu_flags) :
+                iommu_legacy_unmap(d, _dfn(gfn), 1ul << order);
     }
 
     unmap_domain_page(table);
diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c
index badb26bc34..3af51be78e 100644
--- a/xen/arch/x86/mm/p2m-pt.c
+++ b/xen/arch/x86/mm/p2m-pt.c
@@ -679,9 +679,9 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,
     if ( need_iommu_pt_sync(p2m->domain) &&
          (iommu_old_flags != iommu_pte_flags || old_mfn != mfn_x(mfn)) )
         rc = iommu_pte_flags
-             ? iommu_legacy_map(d, _dfn(gfn), mfn, page_order,
+             ? iommu_legacy_map(d, _dfn(gfn), mfn, 1ul << page_order,
                                 iommu_pte_flags)
-             : iommu_legacy_unmap(d, _dfn(gfn), page_order);
+             : iommu_legacy_unmap(d, _dfn(gfn), 1ul << page_order);
 
     /*
      * Free old intermediate tables if necessary.  This has to be the
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index db7bde0230..928344be30 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -1352,7 +1352,8 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,
     {
         if ( !is_iommu_enabled(d) )
             return 0;
-        return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l), PAGE_ORDER_4K,
+        return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l),
+                                1ul << PAGE_ORDER_4K,
                                 IOMMUF_readable | IOMMUF_writable);
     }
 
@@ -1443,7 +1444,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)
     {
         if ( !is_iommu_enabled(d) )
             return 0;
-        return iommu_legacy_unmap(d, _dfn(gfn_l), PAGE_ORDER_4K);
+        return iommu_legacy_unmap(d, _dfn(gfn_l), 1ul << PAGE_ORDER_4K);
     }
 
     gfn_lock(p2m, gfn, 0);
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 0d1aadbfce..bce1561e1a 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1286,7 +1286,7 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     {
         for ( i = spfn; i < epfn; i++ )
             if ( iommu_legacy_map(hardware_domain, _dfn(i), _mfn(i),
-                                  PAGE_ORDER_4K,
+                                  1ul << PAGE_ORDER_4K,
                                   IOMMUF_readable | IOMMUF_writable) )
                 break;
         if ( i != epfn )
@@ -1294,7 +1294,7 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
             while (i-- > old_max)
                 /* If statement to satisfy __must_check. */
                 if ( iommu_legacy_unmap(hardware_domain, _dfn(i),
-                                        PAGE_ORDER_4K) )
+                                        1ul << PAGE_ORDER_4K) )
                     continue;
 
             goto destroy_m2p;
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 9f0cae52c0..a5d3ed8bda 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -1225,7 +1225,7 @@ map_grant_ref(
             kind = IOMMUF_readable;
         else
             kind = 0;
-        if ( kind && iommu_legacy_map(ld, _dfn(mfn_x(mfn)), mfn, 0, kind) )
+        if ( kind && iommu_legacy_map(ld, _dfn(mfn_x(mfn)), mfn, 1, kind) )
         {
             double_gt_unlock(lgt, rgt);
             rc = GNTST_general_error;
@@ -1479,9 +1479,9 @@ unmap_common(
 
         kind = mapkind(lgt, rd, op->mfn);
         if ( !kind )
-            err = iommu_legacy_unmap(ld, _dfn(mfn_x(op->mfn)), 0);
+            err = iommu_legacy_unmap(ld, _dfn(mfn_x(op->mfn)), 1);
         else if ( !(kind & MAPKIND_WRITE) )
-            err = iommu_legacy_map(ld, _dfn(mfn_x(op->mfn)), op->mfn, 0,
+            err = iommu_legacy_map(ld, _dfn(mfn_x(op->mfn)), op->mfn, 1,
                                    IOMMUF_readable);
 
         double_gt_unlock(lgt, rgt);
diff --git a/xen/drivers/passthrough/amd/iommu.h b/xen/drivers/passthrough/amd/iommu.h
index e2d174f3b4..f1f0415469 100644
--- a/xen/drivers/passthrough/amd/iommu.h
+++ b/xen/drivers/passthrough/amd/iommu.h
@@ -231,7 +231,7 @@ int amd_iommu_reserve_domain_unity_map(struct domain *domain,
                                        paddr_t phys_addr, unsigned long size,
                                        int iw, int ir);
 int __must_check amd_iommu_flush_iotlb_pages(struct domain *d, dfn_t dfn,
-                                             unsigned int page_count,
+                                             unsigned long page_count,
                                              unsigned int flush_flags);
 int __must_check amd_iommu_flush_iotlb_all(struct domain *d);
 
diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c
index 54b991294a..0cb948d114 100644
--- a/xen/drivers/passthrough/amd/iommu_map.c
+++ b/xen/drivers/passthrough/amd/iommu_map.c
@@ -351,7 +351,7 @@ int amd_iommu_unmap_page(struct domain *d, dfn_t dfn,
     return 0;
 }
 
-static unsigned long flush_count(unsigned long dfn, unsigned int page_count,
+static unsigned long flush_count(unsigned long dfn, unsigned long page_count,
                                  unsigned int order)
 {
     unsigned long start = dfn >> order;
@@ -362,7 +362,7 @@ static unsigned long flush_count(unsigned long dfn, unsigned int page_count,
 }
 
 int amd_iommu_flush_iotlb_pages(struct domain *d, dfn_t dfn,
-                                unsigned int page_count,
+                                unsigned long page_count,
                                 unsigned int flush_flags)
 {
     unsigned long dfn_l = dfn_x(dfn);
diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
index b2a65dfaaf..346165c3fa 100644
--- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
+++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
@@ -945,7 +945,7 @@ static int __must_check ipmmu_iotlb_flush_all(struct domain *d)
 }
 
 static int __must_check ipmmu_iotlb_flush(struct domain *d, dfn_t dfn,
-                                          unsigned int page_count,
+                                          unsigned long page_count,
                                           unsigned int flush_flags)
 {
     ASSERT(flush_flags);
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index 94662a8501..06f9bda47d 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -2534,7 +2534,7 @@ static int __must_check arm_smmu_iotlb_flush_all(struct domain *d)
 }
 
 static int __must_check arm_smmu_iotlb_flush(struct domain *d, dfn_t dfn,
-					     unsigned int page_count,
+					     unsigned long page_count,
 					     unsigned int flush_flags)
 {
 	ASSERT(flush_flags);
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index eb65631d59..87f9a857bb 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -235,7 +235,7 @@ void iommu_domain_destroy(struct domain *d)
 }
 
 int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
-              unsigned int page_order, unsigned int flags,
+              unsigned long page_count, unsigned int flags,
               unsigned int *flush_flags)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -245,10 +245,7 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
     if ( !is_iommu_enabled(d) )
         return 0;
 
-    ASSERT(IS_ALIGNED(dfn_x(dfn), (1ul << page_order)));
-    ASSERT(IS_ALIGNED(mfn_x(mfn), (1ul << page_order)));
-
-    for ( i = 0; i < (1ul << page_order); i++ )
+    for ( i = 0; i < page_count; i++ )
     {
         rc = iommu_call(hd->platform_ops, map_page, d, dfn_add(dfn, i),
                         mfn_add(mfn, i), flags, flush_flags);
@@ -278,25 +275,26 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
      * Something went wrong so, if we were dealing with more than a single
      * page, flush everything and clear flush flags.
      */
-    if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) )
+    if ( page_count > 1 && unlikely(rc) &&
+         !iommu_iotlb_flush_all(d, *flush_flags) )
         *flush_flags = 0;
 
     return rc;
 }
 
 int iommu_legacy_map(struct domain *d, dfn_t dfn, mfn_t mfn,
-                     unsigned int page_order, unsigned int flags)
+                     unsigned long page_count, unsigned int flags)
 {
     unsigned int flush_flags = 0;
-    int rc = iommu_map(d, dfn, mfn, page_order, flags, &flush_flags);
+    int rc = iommu_map(d, dfn, mfn, page_count, flags, &flush_flags);
 
     if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
-        rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
+        rc = iommu_iotlb_flush(d, dfn, page_count, flush_flags);
 
     return rc;
 }
 
-int iommu_unmap(struct domain *d, dfn_t dfn, unsigned int page_order,
+int iommu_unmap(struct domain *d, dfn_t dfn, unsigned long page_count,
                 unsigned int *flush_flags)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -306,9 +304,7 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned int page_order,
     if ( !is_iommu_enabled(d) )
         return 0;
 
-    ASSERT(IS_ALIGNED(dfn_x(dfn), (1ul << page_order)));
-
-    for ( i = 0; i < (1ul << page_order); i++ )
+    for ( i = 0; i < page_count; i++ )
     {
         int err = iommu_call(hd->platform_ops, unmap_page, d, dfn_add(dfn, i),
                              flush_flags);
@@ -335,19 +331,20 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned int page_order,
      * Something went wrong so, if we were dealing with more than a single
      * page, flush everything and clear flush flags.
      */
-    if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) )
+    if ( page_count > 1 && unlikely(rc) &&
+         !iommu_iotlb_flush_all(d, *flush_flags) )
         *flush_flags = 0;
 
     return rc;
 }
 
-int iommu_legacy_unmap(struct domain *d, dfn_t dfn, unsigned int page_order)
+int iommu_legacy_unmap(struct domain *d, dfn_t dfn, unsigned long page_count)
 {
     unsigned int flush_flags = 0;
-    int rc = iommu_unmap(d, dfn, page_order, &flush_flags);
+    int rc = iommu_unmap(d, dfn, page_count, &flush_flags);
 
     if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
-        rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
+        rc = iommu_iotlb_flush(d, dfn, page_count, flush_flags);
 
     return rc;
 }
@@ -363,7 +360,7 @@ int iommu_lookup_page(struct domain *d, dfn_t dfn, mfn_t *mfn,
     return iommu_call(hd->platform_ops, lookup_page, d, dfn, mfn, flags);
 }
 
-int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsigned int page_count,
+int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsigned long page_count,
                       unsigned int flush_flags)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -382,7 +379,7 @@ int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsigned int page_count,
     {
         if ( !d->is_shutting_down && printk_ratelimit() )
             printk(XENLOG_ERR
-                   "d%d: IOMMU IOTLB flush failed: %d, dfn %"PRI_dfn", page count %u flags %x\n",
+                   "d%d: IOMMU IOTLB flush failed: %d, dfn %"PRI_dfn", page count %lu flags %x\n",
                    d->domain_id, rc, dfn_x(dfn), page_count, flush_flags);
 
         if ( !is_hardware_domain(d) )
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index 607e8b5e65..68cf0e535a 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -584,7 +584,7 @@ static int __must_check iommu_flush_all(void)
 
 static int __must_check iommu_flush_iotlb(struct domain *d, dfn_t dfn,
                                           bool_t dma_old_pte_present,
-                                          unsigned int page_count)
+                                          unsigned long page_count)
 {
     struct domain_iommu *hd = dom_iommu(d);
     struct acpi_drhd_unit *drhd;
@@ -632,7 +632,7 @@ static int __must_check iommu_flush_iotlb(struct domain *d, dfn_t dfn,
 
 static int __must_check iommu_flush_iotlb_pages(struct domain *d,
                                                 dfn_t dfn,
-                                                unsigned int page_count,
+                                                unsigned long page_count,
                                                 unsigned int flush_flags)
 {
     ASSERT(page_count && !dfn_eq(dfn, INVALID_DFN));
diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c
index aea07e47c4..f17b1820f4 100644
--- a/xen/drivers/passthrough/x86/iommu.c
+++ b/xen/drivers/passthrough/x86/iommu.c
@@ -244,7 +244,7 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
         else if ( paging_mode_translate(d) )
             rc = set_identity_p2m_entry(d, pfn, p2m_access_rw, 0);
         else
-            rc = iommu_map(d, _dfn(pfn), _mfn(pfn), PAGE_ORDER_4K,
+            rc = iommu_map(d, _dfn(pfn), _mfn(pfn), 1ul << PAGE_ORDER_4K,
                            IOMMUF_readable | IOMMUF_writable, &flush_flags);
 
         if ( rc )
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 1831dc66b0..13f68dc93d 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -146,23 +146,23 @@ enum
 #define IOMMU_FLUSHF_modified (1u << _IOMMU_FLUSHF_modified)
 
 int __must_check iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
-                           unsigned int page_order, unsigned int flags,
+                           unsigned long page_count, unsigned int flags,
                            unsigned int *flush_flags);
 int __must_check iommu_unmap(struct domain *d, dfn_t dfn,
-                             unsigned int page_order,
+                             unsigned long page_count,
                              unsigned int *flush_flags);
 
 int __must_check iommu_legacy_map(struct domain *d, dfn_t dfn, mfn_t mfn,
-                                  unsigned int page_order,
+                                  unsigned long page_count,
                                   unsigned int flags);
 int __must_check iommu_legacy_unmap(struct domain *d, dfn_t dfn,
-                                    unsigned int page_order);
+                                    unsigned long page_count);
 
 int __must_check iommu_lookup_page(struct domain *d, dfn_t dfn, mfn_t *mfn,
                                    unsigned int *flags);
 
 int __must_check iommu_iotlb_flush(struct domain *d, dfn_t dfn,
-                                   unsigned int page_count,
+                                   unsigned long page_count,
                                    unsigned int flush_flags);
 int __must_check iommu_iotlb_flush_all(struct domain *d,
                                        unsigned int flush_flags);
@@ -281,7 +281,7 @@ struct iommu_ops {
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);
     int __must_check (*iotlb_flush)(struct domain *d, dfn_t dfn,
-                                    unsigned int page_count,
+                                    unsigned long page_count,
                                     unsigned int flush_flags);
     int __must_check (*iotlb_flush_all)(struct domain *d);
     int (*get_reserved_device_memory)(iommu_grdm_t *, void *);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKilF-0000WB-FH; Tue, 22 Sep 2020 13:55:13 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKilD-0000Vx-TL
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:12 +0000
X-Inumbo-ID: e45c8868-5622-4e5c-aee5-f51ecbd867e1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id e45c8868-5622-4e5c-aee5-f51ecbd867e1;
 Tue, 22 Sep 2020 13:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PihSD/rLhwZOqekftu7E/MDdzbmNTnFmmGTq2HoKtOY=; b=jL5P3NMjADskY8RGR14+VtRTcv
 2js/eU27XWUinXQ1HS0Yme209dsFOPsG22rH12wlJs1HZSKxxndj7Pj8G6jqw2l+ZKowoh8z/VOyM
 buCwoMZWGPxdN8VgGl+8uB6RCzWIkBjX0mhGZHfQRE1GnT2MNe0YTgMBgstGtHEA6KGY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKil8-0007KH-9i
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKil8-0006qM-8E
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Handle the Intel-specific MSR_MISC_ENABLE
 correctly
Message-Id: <E1kKil8-0006qM-8E@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e71301ecd50f2d3bd1b960bbf7dcf850d02e7e8a
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 15:46:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:46:21 2020 +0200

    x86/pv: Handle the Intel-specific MSR_MISC_ENABLE correctly
    
    This MSR doesn't exist on AMD hardware, and switching away from the safe
    functions in the common MSR path was an erroneous change.
    
    Partially revert the change.
    
    This is XSA-333.
    
    Fixes: 4fdc932b3cc ("x86/Intel: drop another 32-bit leftover")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/pv/emul-priv-op.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index d793eed401..61071ae03a 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -959,7 +959,8 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, *val);
+        if ( rdmsr_safe(reg, *val) )
+            break;
         *val = guest_misc_enable(*val);
         return X86EMUL_OKAY;
 
@@ -1102,7 +1103,8 @@ static int write_msr(unsigned int reg, uint64_t val,
         break;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, temp);
+        if ( rdmsr_safe(reg, temp) )
+            break;
         if ( val != guest_misc_enable(temp) )
             goto invalid;
         return X86EMUL_OKAY;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKilK-0000Wz-Gg; Tue, 22 Sep 2020 13:55:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKilJ-0000Wk-8Z
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:17 +0000
X-Inumbo-ID: 4298d791-68f7-4d30-9702-e0eb5f7c863a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4298d791-68f7-4d30-9702-e0eb5f7c863a;
 Tue, 22 Sep 2020 13:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6jjZYjh1YRLvD3CHAlvED+rgzC3wKiarUDLI/imG+qY=; b=SHEgaoJBq8PIgHCMMQt0KoEF9l
 awwk9Jh2ecRkZnBd1qPT+ewhf9YP5aDlSvXu9RSVWQI5Ks3gHCRo6b3lJIkSpw0uXcmf3Zr2sjC2h
 awO857YOCMRp5ClH9LjXYHtwl6MZ0trwr9F5VvCtjlcOkJTRGAv63jUmIP/XkEYUdnoM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilI-0007KK-ED
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilI-0006rA-Bz
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/memory: Don't skip the RCU unlock path in
 acquire_resource()
Message-Id: <E1kKilI-0006rA-Bz@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 42317dede5be4fe5be27c873f7a3f94d3bba98e0
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 15:46:49 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:46:49 2020 +0200

    xen/memory: Don't skip the RCU unlock path in acquire_resource()
    
    In the case that an HVM Stubdomain makes an XENMEM_acquire_resource hypercall,
    the FIXME path will bypass rcu_unlock_domain() on the way out of the function.
    
    Move the check to the start of the function.  This does change the behaviour
    of the get-size path for HVM Stubdomains, but that functionality is currently
    broken and unused anyway, as well as being quite useless to entities which
    can't actually map the resource anyway.
    
    This is XSA-334.
    
    Fixes: 83fa6552ce ("common: add a new mappable resource type: XENMEM_resource_grant_table")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/memory.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 714077c1e5..1bab0e80c2 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1058,6 +1058,14 @@ static int acquire_resource(
     xen_pfn_t mfn_list[32];
     int rc;
 
+    /*
+     * FIXME: Until foreign pages inserted into the P2M are properly
+     *        reference counted, it is unsafe to allow mapping of
+     *        resource pages unless the caller is the hardware domain.
+     */
+    if ( paging_mode_translate(currd) && !is_hardware_domain(currd) )
+        return -EACCES;
+
     if ( copy_from_guest(&xmar, arg, 1) )
         return -EFAULT;
 
@@ -1114,14 +1122,6 @@ static int acquire_resource(
         xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)];
         unsigned int i;
 
-        /*
-         * FIXME: Until foreign pages inserted into the P2M are properly
-         *        reference counted, it is unsafe to allow mapping of
-         *        resource pages unless the caller is the hardware domain.
-         */
-        if ( !is_hardware_domain(currd) )
-            return -EACCES;
-
         if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) )
             rc = -EFAULT;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKilV-0000YL-IP; Tue, 22 Sep 2020 13:55:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKilU-0000YB-DH
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:28 +0000
X-Inumbo-ID: 73e21514-f196-4e6f-bf22-1fc489a3e336
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 73e21514-f196-4e6f-bf22-1fc489a3e336;
 Tue, 22 Sep 2020 13:55:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=7bQwJAK7oR4jmDTGFiFg1jMl0YYOhlm9rdio0BRt0dI=; b=ULx0xmAPfKII4O+uRxXWuD4ryK
 lY4B+U34FqSTmLEqORpf624BgMXASoX0NkCdyICugBj3GV334SWBwKIeT0g0WQ5+l2eTRn+23CeEM
 4V+RgJpyTVRMnPxHoiTYufI6yVpmOmFpBlh16t1VmHWFg/gQMlsgjFlAdNJ11n3rgMEw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilS-0007KZ-I1
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilS-0006rv-Gg
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/vpt: fix race when migrating timers between vCPUs
Message-Id: <E1kKilS-0006rv-Gg@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8e76aef72820435e766c7f339ed36da33da90c40
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 15:47:19 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:47:19 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 81 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 32719b6d01..2dfda93e09 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -658,6 +658,8 @@ int hvm_domain_initialise(struct domain *d)
     /* need link to containing domain */
     d->arch.hvm.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index c68bbd1558..867deb4da5 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -153,23 +153,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm.tm_lock);
+    read_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -219,7 +228,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -227,7 +236,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -235,7 +244,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -248,7 +257,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -309,7 +318,7 @@ int pt_update_irq(struct vcpu *v)
     int irq, pt_vector = -1;
     bool level;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -339,7 +348,7 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
@@ -347,7 +356,7 @@ int pt_update_irq(struct vcpu *v)
     irq = earliest_pt->irq;
     level = earliest_pt->level;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -394,7 +403,7 @@ int pt_update_irq(struct vcpu *v)
                 time_cb *cb = NULL;
                 void *cb_priv;
 
-                spin_lock(&v->arch.hvm.tm_lock);
+                pt_vcpu_lock(v);
                 /* Make sure the timer is still on the list. */
                 list_for_each_entry ( pt, &v->arch.hvm.tm_list, list )
                     if ( pt == earliest_pt )
@@ -404,7 +413,7 @@ int pt_update_irq(struct vcpu *v)
                         cb_priv = pt->priv;
                         break;
                     }
-                spin_unlock(&v->arch.hvm.tm_lock);
+                pt_vcpu_unlock(v);
 
                 if ( cb != NULL )
                     cb(v, cb_priv);
@@ -441,12 +450,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -455,7 +464,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -466,12 +475,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -490,7 +499,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -540,7 +549,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -565,30 +574,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index f0e0eaec83..39d26cbda4 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -128,6 +128,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKile-0000ZY-K2; Tue, 22 Sep 2020 13:55:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKild-0000ZP-IS
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:37 +0000
X-Inumbo-ID: 20df581f-69ac-4ab2-9730-2af4603ee493
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 20df581f-69ac-4ab2-9730-2af4603ee493;
 Tue, 22 Sep 2020 13:55:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Vuv7rVYrMX42bMg0vtcEgtVyoDdI+/EJKFIdIWOT5pM=; b=CTbmmHRxu5lR97OPFHz92uDarN
 rsa343TlgMPaoyOTJcgOxoNpZW/3hpsIXNreXvFwl8hi6DUPJDuv5wEWxwc2889mUFAOF0WLu6xq5
 zf+T+Fu7S6qkR47outdRLDicKkjiU9UW4R/pvUx0m5JnDqYGUYZ9xuCFoMoJ8Lsp5FXs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilc-0007LA-LU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilc-0006sc-KG
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKilc-0006sc-KG@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit cb5e9730862ba0c99e81d3fbd8f65010707245e4
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 15:47:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:47:58 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 53 +----------------------------------------------------
 1 file changed, 1 insertion(+), 52 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 29e4351a49..9ff4beb5de 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -185,54 +185,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        uint16_t data;
-
-        msg->address_lo = pci_conf_read32(dev->sbdf,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(dev->sbdf,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -304,10 +256,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKilo-0000cB-Lb; Tue, 22 Sep 2020 13:55:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKiln-0000aM-TZ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:47 +0000
X-Inumbo-ID: 2e7319df-aced-4829-9bd1-b06ebd5b9154
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2e7319df-aced-4829-9bd1-b06ebd5b9154;
 Tue, 22 Sep 2020 13:55:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=qPciEQB+MEYi+ScpC9kgLkP/aB4yhAMM14Deqopf85o=; b=RL4YifxaHOPTmp22Fq4C9te6X3
 Y3WU/Gp5zC9XD8lvVimeI65OIIRMFZM8YCjpu6L2LcNx+RpfPHR+3dQXyjJhXfCYYr+Jwgwgx3PMH
 KG445gtHX7uzudKD5a49lKRxXPBo80mISe+0VQ5E6WM1QlxZBXi1u+fR3eGydUnN5Jto=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilm-0007LK-Ow
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilm-0006tG-Nd
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/MSI-X: restrict reading of table/PBA bases from BARs
Message-Id: <E1kKilm-0006tG-Nd@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit beb54596cfdaf15f6a86d7b1bf84ca8a0b9c6b9b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:48:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:48:26 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 9ff4beb5de..a899c43e8d 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -771,16 +771,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
     unsigned int pos = pci_find_cap_offset(seg, bus, slot, func,
                                            PCI_CAP_ID_MSIX);
 
@@ -822,43 +820,45 @@ static int msix_capability_init(struct pci_dev *dev,
 
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(dev->sbdf, msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
-    {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(dev->sbdf, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->table.first = PFN_DOWN(table_paddr);
         msix->table.last = PFN_DOWN(table_paddr +
@@ -877,7 +877,18 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(msix->nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
+    }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
+        xfree(entry);
+        return -ENODATA;
     }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      PAGE_OFFSET(table_offset & ~PCI_MSIX_BIRMASK);
 
     if ( entry )
     {
@@ -888,8 +899,15 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
+            pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
             xfree(entry);
             return idx;
         }
@@ -1072,9 +1090,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:55:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:55:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKily-0000dU-Ol; Tue, 22 Sep 2020 13:55:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKilx-0000dM-Nf
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:57 +0000
X-Inumbo-ID: ccc10cde-ae22-4b36-8658-431a53027303
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ccc10cde-ae22-4b36-8658-431a53027303;
 Tue, 22 Sep 2020 13:55:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=b/0wTnVAx90amfvF6YjKEvnGr9KSn2CK4BqXDyF7BL0=; b=wT4LrDw9Dw7hIhg5PmURm8cT2v
 RlV9PZM0k1wWSZ7Y4nZC3VGLAiQX9nNDlEVcFgjZF26oF528oGyHQ41VTrRlOgtSa5oNOwHTjlXk6
 WKMclJNcmfNxUBctrpKiWw7yJEDAfqMd12WAEgrr9GEAFpbfadl5JgLMujrMJ9Vi1z48=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilw-0007LY-Rt
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKilw-0006tl-R8
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:55:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: relax port_is_valid()
Message-Id: <E1kKilw-0006tl-R8@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:55:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e59ce972d1280c6c55065da822e0860845582053
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:48:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:48:52 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index a7798f6765..ce45298377 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,8 +107,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:56:09 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:56:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKim9-0000eg-QZ; Tue, 22 Sep 2020 13:56:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKim8-0000eV-1t
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:08 +0000
X-Inumbo-ID: 95c6840f-2c4d-420d-a424-eb0083992023
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 95c6840f-2c4d-420d-a424-eb0083992023;
 Tue, 22 Sep 2020 13:56:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=xtCzSs5nBapbS/Igzl8nDvT/3e2DV+BMhlcODvHpJsY=; b=groQ0I9kVNKXqn3pVD3Woucx2x
 5YbXVBMOG6eWei7oLwwBfqGD+BKJQsgBpOrikOE9UpVAdN4pFeZCjYhvP8n5uvRs3aHQ6UZLeUv+d
 9WpxZ0tAI4Q5RQBveNObQIUh4Wsed6bbD3CVXKawAqtRqi6YM+cPvbZN9cPt3RM43GGY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKim7-0007Lv-0S
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKim6-0006us-UO
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Avoid double exception injection
Message-Id: <E1kKim6-0006us-UO@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 910093d54fc758e7d69261b344fdc8da3a7bd81e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 15:49:19 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:49:19 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index c3e62f8734..73619f57ca 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -78,7 +78,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -352,7 +351,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 1e880eb9f6..71a00e846b 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -90,7 +90,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -512,6 +511,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:56:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:56:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKimJ-0000gN-SD; Tue, 22 Sep 2020 13:56:19 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKimI-0000gA-2K
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:18 +0000
X-Inumbo-ID: d6aa8b72-92bf-456a-a521-b2e6f1fbbf75
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d6aa8b72-92bf-456a-a521-b2e6f1fbbf75;
 Tue, 22 Sep 2020 13:56:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/+Bn8MuF4moN8Gi9P7QLi/YggCvfX0Tqw2ZM/695RvQ=; b=OlUV1PxQopUlAz2Cwew/yAgllR
 p4mcGCW2iZVC/kYAq2/kV/xJhq05xUqAZCZBznWPPp33UOScMDlhhLkVB7gEHFGqON0EPEPec5XS0
 AJpsc1BYd1eHJ9q/YzotacYXeCAcwALQcr1NHYDooYj5t6eJ/2gjgDKC1eS9tsuzQdbU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimH-0007M8-4o
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimH-0006vp-31
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKimH-0006vp-31@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 112992b05b2d2ca63f3c78eefe1cf8d192d7303a
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 15:49:40 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:49:40 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index a8d182b584..53c17bd354 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -178,6 +178,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index ce45298377..c35f4b23b6 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,7 +107,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:56:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:56:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKimT-0000hI-Tt; Tue, 22 Sep 2020 13:56:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKimS-0000hA-Cp
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:28 +0000
X-Inumbo-ID: b3c3f502-fb1f-4f32-9992-345b92afff03
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b3c3f502-fb1f-4f32-9992-345b92afff03;
 Tue, 22 Sep 2020 13:56:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=xnd4OuhF4TaBfvXlFm1sCs5AYymoXrs8miFfHDrFpjk=; b=P3srtkxVnUmx2FRAvKBOFr6NvD
 YhXBHS7KnEEoF0owiue16VeRWEFUA2LkXyFChal4mAAtv6hMTBeDC9OeF9JCqnED5H9XtuD17njDq
 jvcJemb0p3eRTcCpjPJds7iKZoBDyrDOFDGrypZPGWgN1nosDgNF8xNcbpHzAMmA5kMI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimR-0007MK-85
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimR-0006wj-7O
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKimR-0006wj-7O@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 62bcdc4edbf6d8c6e8a25544d48de22ccf75310d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:50:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:50:09 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/sched/core.c    | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 53c17bd354..08ffe0f063 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -151,7 +151,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1396,13 +1396,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 230f440f14..2f13d92128 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -478,7 +478,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -488,7 +488,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -546,6 +546,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -562,8 +564,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index cb49a8bc02..ab94d2ec3a 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -1428,7 +1428,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index c35f4b23b6..e1b299e8df 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -105,6 +105,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index e9ce43cc9a..33d716ef77 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -359,7 +359,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:56:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:56:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKimd-0000iO-VU; Tue, 22 Sep 2020 13:56:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKimc-0000iD-Dc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:38 +0000
X-Inumbo-ID: d1a75ceb-c647-4f04-8ed4-6ad6603083c6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d1a75ceb-c647-4f04-8ed4-6ad6603083c6;
 Tue, 22 Sep 2020 13:56:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=KwVbLFXoAqhtEyZv3e4N9yfgtQhdWaG7i4FezYjGzVg=; b=BrK8WcO2JJujtkcUk7V40HNh68
 zKWEqqfIGTVVNOy+Jr9Y201IGrFgvq9JCY0mqc49gHyYNoO7QDuXj/1e3VdQIykwbmEAOg8BJlHdA
 Nu2qjDnarw2xe3LwNvjkWtKHDYFAYMoVfnm3Xz4le3PL2NDK3aEudMHDSsubeirHeFWs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimb-0007N6-B7
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimb-0006xx-AK
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKimb-0006xx-AK@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8d385b247bca40ece40c9279391054bc98934325
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:50:55 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:50:55 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 08ffe0f063..6a566917b1 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -188,6 +188,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -211,11 +213,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -258,6 +275,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -351,6 +369,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -488,7 +507,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -536,6 +555,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1011,10 +1031,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1024,7 +1044,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1033,7 +1055,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1219,10 +1241,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1238,7 +1259,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1314,6 +1338,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
@@ -1340,6 +1365,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 33d716ef77..67fdabbec3 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -361,6 +361,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:56:50 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:56:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKimo-0000kZ-2A; Tue, 22 Sep 2020 13:56:50 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKimm-0000jY-OT
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:48 +0000
X-Inumbo-ID: e0ff485f-f59d-4d50-9e27-410fd87175a8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e0ff485f-f59d-4d50-9e27-410fd87175a8;
 Tue, 22 Sep 2020 13:56:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=x+vMMGwyeC35wNWfF3faJS19VaIlAOlUvoFp6+hwW8M=; b=E02Gn9q33bwXmDXkJnvV0590N3
 5Ap0CpaYS2pp3CokQVNdgYYqyFjpiLmNQnka7hfd4/XtuG+8OcxVmWjwW33Vba9p0+r3InN6OsB7D
 uASf8pIRJzmgCd+6Lwr7yXgpbXGRkLDTNOcpzHveAOIDKROZl9Znf5e6vJCMkGEfDmN4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKiml-0007NE-EA
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKiml-0006yd-DR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKiml-0006yd-DR@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c0ddc8634845aba50774add6e4b73fdaffc82656
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:51:28 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:51:28 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 6a566917b1..0e550e9c7a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -248,6 +248,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -263,14 +264,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -283,26 +284,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -312,6 +319,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -347,7 +355,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -364,7 +372,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -387,6 +395,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -424,14 +433,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -448,6 +457,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( domain_vcpu(d, vcpu) == NULL )
         return -ENOENT;
@@ -459,13 +469,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -509,6 +519,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -541,14 +552,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -569,6 +580,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -668,14 +680,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -683,9 +695,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -705,13 +717,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -746,7 +759,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1238,6 +1251,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1250,14 +1264,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1280,11 +1294,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1294,7 +1309,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:57:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:57:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKimz-0000mN-4O; Tue, 22 Sep 2020 13:57:01 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKimx-0000mF-6p
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:59 +0000
X-Inumbo-ID: 4a72fd3d-be94-484f-82f2-0090a8c4829d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4a72fd3d-be94-484f-82f2-0090a8c4829d;
 Tue, 22 Sep 2020 13:56:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=oycADzDyiG27NKUUBj/MHUUZpdSMUAxYkN8eF1F8tdM=; b=dfcMQ3Tapsq+I2CcRD+yQJQOAx
 NAGpZq+bdSzxvoiqPI66RbC6pWHFFUlCzN4EP+U9izI2TuEtNYNGt5O6iEBPrTeTzX+FshsKZxFpc
 9yaYjwR+1TajvryxoxkV8SdNDwxS1uVSH6rESChKHrxOA0PL5w1ht0NuxUb9XYxcxrIU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimv-0007NM-HR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKimv-0006zD-Gh
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:56:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: address races with evtchn_reset()
Message-Id: <E1kKimv-0006zD-Gh@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:56:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e045199c7c9c5433d7f1461a741ed539a75cbfad
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:51:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:51:52 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index a69937c840..93c4fb9a79 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2488,14 +2488,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i++];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("d%d:%3d(%c%c%c)%c",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       info->masked ? 'M' : '-',
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-',
                        i < action->nr_guests ? ',' : '\n');
             }
         }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 3a0525c209..9aef7a860a 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -660,8 +660,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 0e550e9c7a..878e4250ed 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -156,8 +156,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -774,6 +775,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -784,7 +786,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -813,7 +818,9 @@ void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -823,6 +830,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -837,7 +845,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1034,12 +1044,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1449,8 +1462,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 2f13d92128..68d0c7a632 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -296,23 +296,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 98a85233cb..5e09ede6d7 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline bool arch_virq_is_global(unsigned int virq)
     return true;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index e1b299e8df..bc9aa68650 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -133,6 +133,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -165,19 +183,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -193,38 +216,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -233,6 +285,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:57:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:57:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKin8-0000nJ-6E; Tue, 22 Sep 2020 13:57:10 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKin6-0000nB-KG
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:08 +0000
X-Inumbo-ID: 96182796-2cad-4115-b7a0-5e367c96507f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 96182796-2cad-4115-b7a0-5e367c96507f;
 Tue, 22 Sep 2020 13:57:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cMkKdm4EVvpDh3W1EIin5Fijgxhr1tGwZoJ0a1T3X9Y=; b=F9g44nE2dbRD+MgLL6o6w46y1m
 dGibo3kaEzYXC67+d9n9Uzvm/q4/2ID83IFUXmI3ycMwOfQ9RFYvcgztOnBmMD8tcr/j5TZmGJpCW
 isIRPQAcWS4eKGVontqojpZefe84aYH7gS3y7EVC0ggxTFV76CFQX8O+velPPsn5nFL0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKin5-0007Nk-Kr
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKin5-0006zy-Jw
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKin5-0006zy-Jw@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:57:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8fe7b5f9960f4d9ec46787af394d180c39c6b2db
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:52:36 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:52:36 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 61ffccde0c..216e5a1d4c 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -711,12 +711,14 @@ int domain_kill(struct domain *d)
             return domain_kill(d);
         d->is_dying = DOMDYING_dying;
         argo_destroy(d);
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         vnuma_destroy(d->vnuma);
         domain_set_outstanding_pages(d, 0);
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 878e4250ed..3b1fe423df 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1297,7 +1297,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1309,7 +1318,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1380,8 +1399,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1390,14 +1408,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 67fdabbec3..5343063d41 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -138,7 +138,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d, unsigned int max_port);
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 13:57:20 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 13:57:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKinI-0000p2-9A; Tue, 22 Sep 2020 13:57:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKinG-0000os-Sh
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:18 +0000
X-Inumbo-ID: 457865bf-d703-4a53-bbf3-293a51b30181
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 457865bf-d703-4a53-bbf3-293a51b30181;
 Tue, 22 Sep 2020 13:57:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=jrxE0tRVxPwuKqnesdO3JDL2b+YwA5ph3tQpRhwoJYQ=; b=5hbtrloCF7rO8bEEn38znuH4rr
 RNA0/2Qs319e1iPxRWcf9IfCYdp+w/mV74rxMs1vjxaF8AZU5c7Y21vzKiPdBfKwdBDY7YpuD/lQ7
 BOEw5u9gVndBEovC4rmQWydmL6eoxym2wJUFNxd0qRmRm2VTCxanfuQlZBwdEA0DMBQ4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKinF-0007Nu-O9
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKinF-00070k-NW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 13:57:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKinF-00070k-NW@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 13:57:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2785b2a9e04abc148e1c5259f4faee708ea356f4
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 15:53:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 15:53:10 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 216e5a1d4c..8cfa2e0b6b 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1141,7 +1141,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1155,7 +1155,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 5ac6e9c5ca..af044e2eda 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -477,12 +477,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 3b1fe423df..d2ee83bbbf 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1057,7 +1057,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1065,11 +1065,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1204,7 +1233,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1217,9 +1247,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 5c5e55ebcb..791f0a2592 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1154,7 +1154,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index 246ace4d19..73c9f38ce1 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index bc9aa68650..fa93a3684a 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -179,7 +179,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 5343063d41..d8ed83f869 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -371,6 +371,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -661,7 +663,7 @@ int domain_kill(struct domain *d);
 int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjBJ-0004lM-9A; Tue, 22 Sep 2020 14:22:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjBI-0004lB-D9
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:08 +0000
X-Inumbo-ID: 840b6666-dccc-47bf-bd43-4b37690a3b7b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 840b6666-dccc-47bf-bd43-4b37690a3b7b;
 Tue, 22 Sep 2020 14:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=09lBCvmQgvNR86gkj3lxF0HcWQhycjSCFQOASxBAV84=; b=qCXapjr4MW0AEFuERgpKc60IKR
 EIvlBvi+w5hBXjF3yzh+PqS05x0BE/XwWk+ZnXMfP1Gg9VH5wCgyYDYWLDOC1/S/RY8uffoX0uxh5
 MHczN82jXWtMSpXA3FY9zZTL5XPRAalYOPx4c6QaC8cw5jRVHZFi2HZ3pvOC/mwUpUQk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBG-00081R-7M
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBG-0000hO-5n
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/pv: Handle the Intel-specific MSR_MISC_ENABLE
 correctly
Message-Id: <E1kKjBG-0000hO-5n@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b04d6731eedd639e078e0f0d8147c6b156875ac3
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:09:36 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:09:36 2020 +0200

    x86/pv: Handle the Intel-specific MSR_MISC_ENABLE correctly
    
    This MSR doesn't exist on AMD hardware, and switching away from the safe
    functions in the common MSR path was an erroneous change.
    
    Partially revert the change.
    
    This is XSA-333.
    
    Fixes: 4fdc932b3cc ("x86/Intel: drop another 32-bit leftover")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/pv/emul-priv-op.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 7c21076dd0..85a9fd4767 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -913,7 +913,8 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, *val);
+        if ( rdmsr_safe(reg, *val) )
+            break;
         *val = guest_misc_enable(*val);
         return X86EMUL_OKAY;
 
@@ -1053,7 +1054,8 @@ static int write_msr(unsigned int reg, uint64_t val,
         break;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, temp);
+        if ( rdmsr_safe(reg, temp) )
+            break;
         if ( val != guest_misc_enable(temp) )
             goto invalid;
         return X86EMUL_OKAY;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjBS-0004nS-Aj; Tue, 22 Sep 2020 14:22:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjBR-0004nI-C0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:17 +0000
X-Inumbo-ID: 5048f544-dd1e-412b-924c-851113b1aa27
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5048f544-dd1e-412b-924c-851113b1aa27;
 Tue, 22 Sep 2020 14:22:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PzgPcVWxj8RyN3yUURquzOgFAdABn5bZZGoAavQlg2w=; b=kKTWtxsydqEJh1tr3Xq7T0OxIN
 HCEriyzDqZpgfJnHYEL8s2BDiGk8izomxsPwFwemNlD/xxoEk4Q8yL8pWqp7rlcwBexSbNkaK0BP7
 o/Ud1C4Gozy8OMRiScrc9rTknaA93KsEXR9RV2umSabIfFO4XBGY7Y+rvMGS3On5bRxQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBQ-00081U-AO
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBQ-0000i8-9Y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/memory: Don't skip the RCU unlock path in
 acquire_resource()
Message-Id: <E1kKjBQ-0000i8-9Y@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5eab5f0543e4f5fc52f7e2d823a29a6b1567fc16
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:09:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:09:59 2020 +0200

    xen/memory: Don't skip the RCU unlock path in acquire_resource()
    
    In the case that an HVM Stubdomain makes an XENMEM_acquire_resource hypercall,
    the FIXME path will bypass rcu_unlock_domain() on the way out of the function.
    
    Move the check to the start of the function.  This does change the behaviour
    of the get-size path for HVM Stubdomains, but that functionality is currently
    broken and unused anyway, as well as being quite useless to entities which
    can't actually map the resource anyway.
    
    This is XSA-334.
    
    Fixes: 83fa6552ce ("common: add a new mappable resource type: XENMEM_resource_grant_table")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/memory.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 714077c1e5..1bab0e80c2 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1058,6 +1058,14 @@ static int acquire_resource(
     xen_pfn_t mfn_list[32];
     int rc;
 
+    /*
+     * FIXME: Until foreign pages inserted into the P2M are properly
+     *        reference counted, it is unsafe to allow mapping of
+     *        resource pages unless the caller is the hardware domain.
+     */
+    if ( paging_mode_translate(currd) && !is_hardware_domain(currd) )
+        return -EACCES;
+
     if ( copy_from_guest(&xmar, arg, 1) )
         return -EFAULT;
 
@@ -1114,14 +1122,6 @@ static int acquire_resource(
         xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)];
         unsigned int i;
 
-        /*
-         * FIXME: Until foreign pages inserted into the P2M are properly
-         *        reference counted, it is unsafe to allow mapping of
-         *        resource pages unless the caller is the hardware domain.
-         */
-        if ( !is_hardware_domain(currd) )
-            return -EACCES;
-
         if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) )
             rc = -EFAULT;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjBd-0004qF-CK; Tue, 22 Sep 2020 14:22:29 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjBc-0004pr-4G
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:28 +0000
X-Inumbo-ID: 94d77f1c-172c-4049-a3c1-8794ade7819a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 94d77f1c-172c-4049-a3c1-8794ade7819a;
 Tue, 22 Sep 2020 14:22:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=zuF2QNHtF72xvPneC30hWi8SOp9f3gM7pxw2Ru6VbWU=; b=OGUiDvqplK8eXI9/cduc7zVKcv
 52iT0ANq0iQW3rIPxXvFytbYK/O0aYu6hhpJsUwQ6FSgzUCd2ccR8FjW1Q65Tavk9h7jCSO+tXw5d
 ECIVqQct96cW/NKcb3iP10aB/oNvekmFMWgCfaQ1hxo0aPAOOGUbbOxXtvb+ExZ3t0io=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBa-00081c-Dr
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBa-0000jA-Ct
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/vpt: fix race when migrating timers between
 vCPUs
Message-Id: <E1kKjBa-0000jA-Ct@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fc8200a6ad5248d8fb6b0fbf3f3dc80f29dfe0c7
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 16:10:37 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:10:37 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 81 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 5bb47583b3..f965ca3155 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -658,6 +658,8 @@ int hvm_domain_initialise(struct domain *d)
     /* need link to containing domain */
     d->arch.hvm.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index 47f2c2aa64..d64467b631 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -153,23 +153,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm.tm_lock);
+    read_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -219,7 +228,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -227,7 +236,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -235,7 +244,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -248,7 +257,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -309,7 +318,7 @@ int pt_update_irq(struct vcpu *v)
     int irq, pt_vector = -1;
     bool level;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -339,7 +348,7 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
@@ -347,7 +356,7 @@ int pt_update_irq(struct vcpu *v)
     irq = earliest_pt->irq;
     level = earliest_pt->level;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -394,7 +403,7 @@ int pt_update_irq(struct vcpu *v)
                 time_cb *cb = NULL;
                 void *cb_priv;
 
-                spin_lock(&v->arch.hvm.tm_lock);
+                pt_vcpu_lock(v);
                 /* Make sure the timer is still on the list. */
                 list_for_each_entry ( pt, &v->arch.hvm.tm_list, list )
                     if ( pt == earliest_pt )
@@ -404,7 +413,7 @@ int pt_update_irq(struct vcpu *v)
                         cb_priv = pt->priv;
                         break;
                     }
-                spin_unlock(&v->arch.hvm.tm_lock);
+                pt_vcpu_unlock(v);
 
                 if ( cb != NULL )
                     cb(v, cb_priv);
@@ -441,12 +450,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -455,7 +464,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -466,12 +475,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -490,7 +499,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -540,7 +549,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -565,30 +574,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index f0e0eaec83..39d26cbda4 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -128,6 +128,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjBm-0004rz-FQ; Tue, 22 Sep 2020 14:22:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjBl-0004ro-Is
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:37 +0000
X-Inumbo-ID: d2f2cb7e-2bf5-46ca-837f-438d47a27027
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d2f2cb7e-2bf5-46ca-837f-438d47a27027;
 Tue, 22 Sep 2020 14:22:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=xJ8/Pxcg23prXwzBjpIcSf5Ww6suvMWzAnbtUjANN94=; b=2gEF6tEfsjOHljfoKi3a753CNk
 mBawpD6sGHvq7Jq8e2t6/vKS6KCHODxojQrnVP9cJp+LBJijEwIPSiKV1RZvYEXeK3wEklKKOmL4w
 t+TZg3j3+gFgqO37h0s83dUCIoXjDvr2nBdHexoyu1R3kVoaimRVu9XMJJ2etdCel6P0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBk-00082S-IO
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBk-0000kN-GL
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKjBk-0000kN-GL@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5ad31525c9aeed6d3a349799fe491b5a7c678049
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 16:11:06 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:11:06 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 53 +----------------------------------------------------
 1 file changed, 1 insertion(+), 52 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 161ee60dbe..6a00bc9312 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -185,54 +185,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        uint16_t data;
-
-        msg->address_lo = pci_conf_read32(dev->sbdf,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(dev->sbdf,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -304,10 +256,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjBx-0004u9-H1; Tue, 22 Sep 2020 14:22:49 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjBv-0004tq-Qq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:47 +0000
X-Inumbo-ID: 9cc9d669-770a-47e2-9f6b-64451c5fe896
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9cc9d669-770a-47e2-9f6b-64451c5fe896;
 Tue, 22 Sep 2020 14:22:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=yKmT8CVZkPznvVXyiYBxfTV5FWuyzAYFnMqFA3uCtoA=; b=s+C3JANzPzpF8lTAeDEdl4U7fd
 q8Vq3tVwTZqvaZDnq/TlVsfs7hIyrS0ntLyqUe+C01uh8Pf5hOwEV/MRWq1SHqvepXZRqPQTYAJ2S
 hPZYUMeBOFt57dCzP9BFGMQ9CTkiI83hoop8YDvO5EiAI8LKvXAMRxqaWaZiT0j0Uc8c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBu-00082a-MR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjBu-0000l3-Kn
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/MSI-X: restrict reading of table/PBA bases
 from BARs
Message-Id: <E1kKjBu-0000l3-Kn@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0bc4177e6b0d7a98464913af95d3bfe4b59b7a2c
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:11:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:11:38 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 6a00bc9312..c8b0e5334f 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -771,16 +771,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
     unsigned int pos = pci_find_cap_offset(seg, bus, slot, func,
                                            PCI_CAP_ID_MSIX);
 
@@ -822,43 +820,45 @@ static int msix_capability_init(struct pci_dev *dev,
 
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(dev->sbdf, msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
-    {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(dev->sbdf, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->table.first = PFN_DOWN(table_paddr);
         msix->table.last = PFN_DOWN(table_paddr +
@@ -877,7 +877,18 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(msix->nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
+    }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
+        xfree(entry);
+        return -ENODATA;
     }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      PAGE_OFFSET(table_offset & ~PCI_MSIX_BIRMASK);
 
     if ( entry )
     {
@@ -888,8 +899,15 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
+            pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
             xfree(entry);
             return idx;
         }
@@ -1078,9 +1096,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:22:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:22:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjC7-0004vx-IS; Tue, 22 Sep 2020 14:22:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjC5-0004ve-Mj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:57 +0000
X-Inumbo-ID: 95ec8466-fe20-4152-ae0c-d91dcb20f790
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 95ec8466-fe20-4152-ae0c-d91dcb20f790;
 Tue, 22 Sep 2020 14:22:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=1D19Gwctj+/hVQpQqHPPCQWwyepOaFb2koTOIeT+Y24=; b=HzS0LzVnOvXiXSSVKHlACObSEg
 uN4yR7bo4rzqbDanTWQK5eZ599A6Egc8G1bxlwr/Sezhl04HZYQjuaUNkqixuG79y6SvFSS9Xp3KZ
 OL+XFLxuLH8Vq8jsbL17HAj6fGOoKiiXF8wxFOr/56eGT7IYDK7AmPbAQQ2ffPQ4XQko=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjC4-00082k-QH
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjC4-0000m1-Oh
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:22:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: relax port_is_valid()
Message-Id: <E1kKjC4-0000m1-Oh@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:22:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e417504febf4ef5cc3442ebaa00da1a5c7939b22
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:11:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:11:56 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index a7798f6765..ce45298377 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,8 +107,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:23:09 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:23:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjCH-0004xu-Ju; Tue, 22 Sep 2020 14:23:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjCG-0004xg-6t
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:08 +0000
X-Inumbo-ID: e3f09e32-60d7-486c-8c69-63be33dd936c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e3f09e32-60d7-486c-8c69-63be33dd936c;
 Tue, 22 Sep 2020 14:23:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rFN/NeAGPdcmI1YtAuhuHH10Fd5A3MGa3ejpBs5fCrs=; b=DHzeE5yxwlIxUnCZDZ4OJS6E70
 Wwkr/YqrJ46IJqea6zCqAL0AYBbG+DQWFGwe5K9BhhTHBbMqZ8Xl97FzY/ZsBo/UeRBetDYKcBz2+
 MgIQHajRwv1M6VHTdNAZyCd7u7PCfS3X6eVZINHC6Lhm2uQ6S1yCRDXmxaX3Bl+vQSHw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCE-000839-TQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCE-0000mk-SY
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/pv: Avoid double exception injection
Message-Id: <E1kKjCE-0000mk-SY@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit eb4a543a47df33038f4f6e915375ea898670c7dc
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:12:44 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:12:44 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index c3e62f8734..73619f57ca 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -78,7 +78,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -352,7 +351,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 1e880eb9f6..71a00e846b 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -90,7 +90,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -512,6 +511,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:23:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:23:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjCR-00050M-LZ; Tue, 22 Sep 2020 14:23:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjCP-000501-Vh
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:18 +0000
X-Inumbo-ID: 1659376f-c574-4598-86b4-592c14c84223
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1659376f-c574-4598-86b4-592c14c84223;
 Tue, 22 Sep 2020 14:23:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cxDXcWJu6Nli6/qUDOyt2jiUrncdKjg8Do0z+m2YE8c=; b=ZNzsc2EtPSL1zQjxfRuDxgoTS2
 xxNYop3JwZFAWoW0ZuH7h0z5sOtcGCbbeZ6hXthQx5IsAfULyEqwYWPYYyXuHjO0edNYly5DIy/oI
 b8ZMBDXHX+Yv7hCvWMzmV8XDTcdKW41/E9kO7VgrnG83piPX+YKQtczY4YsqZgcqzK2w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCP-00083K-18
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCO-0000o1-Va
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKjCO-0000o1-Va@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f5469067ee0260673ca1e554ff8888512a55ccfc
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 16:13:08 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:13:08 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index a8d182b584..53c17bd354 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -178,6 +178,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index ce45298377..c35f4b23b6 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,7 +107,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:23:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:23:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjCl-00053M-PG; Tue, 22 Sep 2020 14:23:39 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjCk-000539-Ca
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:38 +0000
X-Inumbo-ID: 53338662-d19a-4aa1-b9dd-75a836db2f15
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 53338662-d19a-4aa1-b9dd-75a836db2f15;
 Tue, 22 Sep 2020 14:23:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wMIhb5FrOQmXu0gxqZKomGHZe7pBXQGFU1+yVMMNpn0=; b=jq52Ew577I6/XoXfDEImo3syzy
 lfyvJqt6L2Rmmbg1VTsjEbwC3P5OlEGDKdYSczHE1/d53+8LvE/QbiWjJmHP86SIYyldU1O8mEEK7
 JDDM2XqAZS3EbAKOHTk96TrvhcOKeEyzKT0Yt3hjxTw2ofh0rdgqe5fcm2fiLMEif8O4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCj-000841-8j
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCj-0000qF-6w
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKjCj-0000qF-6w@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9b9fc8e391b6d5afa83f90271fdbd0e13871e841
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:14:22 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:14:22 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 08ffe0f063..6a566917b1 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -188,6 +188,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -211,11 +213,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -258,6 +275,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -351,6 +369,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -488,7 +507,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -536,6 +555,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1011,10 +1031,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1024,7 +1044,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1033,7 +1055,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1219,10 +1241,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1238,7 +1259,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1314,6 +1338,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
@@ -1340,6 +1365,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 545f2bdcd0..b9c70da4b0 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -361,6 +361,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:23:46 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:23:46 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjCs-00054H-Qj; Tue, 22 Sep 2020 14:23:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjCr-000547-9b
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:45 +0000
X-Inumbo-ID: 971335ec-8dd3-4fb8-a193-6c28874a0b0c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 971335ec-8dd3-4fb8-a193-6c28874a0b0c;
 Tue, 22 Sep 2020 14:23:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=9ZCE9B6gQJZqKWhpoIzlA5jclPLwX4+fyZWe9Yw1MwM=; b=LF5/c6cevUnh3XKEo6tA1vl1Yn
 D0tjIDCm0IvqhsrNJmGQvqt3UD18+UhrDELyLDCfNUS1L/BV7AyvTq6yDiHsx+kkA21k7A58bjfWb
 8KFBATCOo3YvX5lecX/4Qc3k4guU3KJF+UoQOhipE1srYYD4Axd2GuSEQVtE/1meVu3k=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCZ-00083S-4Q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:27 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCZ-0000pS-3j
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:27 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKjCZ-0000pS-3j@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:27 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b8c2efbe7b3e8fa5f0b0a3679afccd1204949070
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:13:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:13:34 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/sched/core.c    | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 53c17bd354..08ffe0f063 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -151,7 +151,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1396,13 +1396,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 230f440f14..2f13d92128 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -478,7 +478,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -488,7 +488,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -546,6 +546,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -562,8 +564,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index cb49a8bc02..ab94d2ec3a 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -1428,7 +1428,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index c35f4b23b6..e1b299e8df 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -105,6 +105,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index ac53519d7f..545f2bdcd0 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -359,7 +359,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:23:51 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:23:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjCx-00055G-S3; Tue, 22 Sep 2020 14:23:51 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjCw-000552-Gd
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:50 +0000
X-Inumbo-ID: 782c5047-9ef8-43e7-81e5-a49d0e1e37c8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 782c5047-9ef8-43e7-81e5-a49d0e1e37c8;
 Tue, 22 Sep 2020 14:23:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=uJYx+Fa4Qu8BUlxbUiBWpF1cGLlos3pRLTJOZYEe8pc=; b=zj2KgNKvSi3ZCq9NG1K+OxgRAQ
 JkYWk2TFLOyncZZeWaz69mTiTxuVOcgxx8BRFbbaw7evmS1d6KzgKOfHLl/zASohCSEIOq3J5eurS
 vnvnOg/oIWAZLfjliFQuVAjSBEdwp7g4FfRjx8TFKOpHiwKb6ekJ8Yz7SsO57pUUmmLk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCt-000849-Bt
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjCt-0000rI-B4
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKjCt-0000rI-B4@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2ee270e126458471b178ca1e5d7d8d0afc48be39
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:14:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:14:56 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 6a566917b1..0e550e9c7a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -248,6 +248,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -263,14 +264,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -283,26 +284,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -312,6 +319,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -347,7 +355,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -364,7 +372,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -387,6 +395,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -424,14 +433,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -448,6 +457,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( domain_vcpu(d, vcpu) == NULL )
         return -ENOENT;
@@ -459,13 +469,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -509,6 +519,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -541,14 +552,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -569,6 +580,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -668,14 +680,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -683,9 +695,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -705,13 +717,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -746,7 +759,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1238,6 +1251,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1250,14 +1264,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1280,11 +1294,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1294,7 +1309,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:24:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:24:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjD7-00056j-Th; Tue, 22 Sep 2020 14:24:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjD6-00056Y-Gi
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:00 +0000
X-Inumbo-ID: 908fd340-7b8d-44ac-b2d8-8d9a30067dd4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 908fd340-7b8d-44ac-b2d8-8d9a30067dd4;
 Tue, 22 Sep 2020 14:23:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=LThVv67Fr9dgeM5rfbyprqS/MTHeiQmCL78CxKnz37k=; b=wu2dKFCPROVgK+OPDL35Q39OrE
 X2b1HTfyuuBtjEHHqh0PA1MT5oOOzV61mzKZFqCaBP5nWK5Ik6wJMXEZ+3FpUz86omRj54UFaJjcF
 IFP+R3Tt815e/aa8VNHLRkhKsj4V7Jyu8tyn+kuL0jKOJpH0IZkA5b9judDja8VbsQO0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjD3-00084G-GG
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjD3-0000sm-FR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:23:57 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: address races with evtchn_reset()
Message-Id: <E1kKjD3-0000sm-FR@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:23:57 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ecc6428b7ea63a24e244f747e8568c0ccc03a6f8
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:15:14 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:15:14 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index a69937c840..93c4fb9a79 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2488,14 +2488,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i++];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("d%d:%3d(%c%c%c)%c",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       info->masked ? 'M' : '-',
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-',
                        i < action->nr_guests ? ',' : '\n');
             }
         }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 3a0525c209..9aef7a860a 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -660,8 +660,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 0e550e9c7a..878e4250ed 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -156,8 +156,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -774,6 +775,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -784,7 +786,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -813,7 +818,9 @@ void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -823,6 +830,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -837,7 +845,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1034,12 +1044,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1449,8 +1462,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 2f13d92128..68d0c7a632 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -296,23 +296,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 98a85233cb..5e09ede6d7 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline bool arch_virq_is_global(unsigned int virq)
     return true;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index e1b299e8df..bc9aa68650 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -133,6 +133,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -165,19 +183,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -193,38 +216,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -233,6 +285,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:24:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:24:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjDH-00057y-0s; Tue, 22 Sep 2020 14:24:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjDG-00056Y-FQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:10 +0000
X-Inumbo-ID: 83308e9c-4130-46f1-9929-3b7e3b8829b6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 83308e9c-4130-46f1-9929-3b7e3b8829b6;
 Tue, 22 Sep 2020 14:24:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=J19YIKErf5bSpyv4aJ+/0CHEwComd0eGr2vqxL0SY2s=; b=3J9qc9RMkWS7vaEigW8/cRxixj
 9aJBGVWmydiRZr+uBpbzI+iHR3IxP2UGupXjzHFI9Zl0kdJbZHGf41zsZXmcntmgJKhMWPyqeV19T
 FYIeWl7x3OOmll3iUCn7T9gbeXSsVYU2uKgFvnyepULYTwXAJQOgSqJzByeQA5jNwuEs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjDD-00084f-K3
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjDD-0000tf-J9
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKjDD-0000tf-J9@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:24:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 66cdf341428ae38f6426408a95de9830b5c9c83c
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:15:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:15:59 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index e9be05f1d0..364fcbabb2 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -715,12 +715,14 @@ int domain_kill(struct domain *d)
             return domain_kill(d);
         d->is_dying = DOMDYING_dying;
         argo_destroy(d);
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         vnuma_destroy(d->vnuma);
         domain_set_outstanding_pages(d, 0);
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 878e4250ed..3b1fe423df 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1297,7 +1297,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1309,7 +1318,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1380,8 +1399,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1390,14 +1408,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index b9c70da4b0..57d34b2205 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -138,7 +138,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d, unsigned int max_port);
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:24:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:24:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjDV-0005AA-2g; Tue, 22 Sep 2020 14:24:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjDT-00059g-RJ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:23 +0000
X-Inumbo-ID: a02416a2-9b74-437c-9d24-367d8bf95d41
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a02416a2-9b74-437c-9d24-367d8bf95d41;
 Tue, 22 Sep 2020 14:24:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=C4YLxwrvmB5ENZwBcXSKmTd4DUs6CekAqKpeaIlBAg0=; b=uDx8Uh+7MQzKwzsuR2rMqrKgyc
 ynh+p5VshtS5dU9teLrjanzlMjqdAa22Ier+VfQ7uX71sZ5pvwh3tW81+9o/bdOX60YeAu/qzbiZh
 IDbhTODd309jtJYgVPZwSbINMGgs69N12LbfhpDHPffXc6hBmUh7XhTikkkV0u8HDviI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjDN-00084m-Oi
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjDN-0000ub-NW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:24:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKjDN-0000ub-NW@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:24:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 03019c20b516be53ba0cd393f5291974a9a6c9a8
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:16:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:16:52 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 364fcbabb2..a275a35c4f 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1145,7 +1145,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1159,7 +1159,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index a69b3b59a8..2b25653b49 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -562,12 +562,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 3b1fe423df..d2ee83bbbf 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1057,7 +1057,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1065,11 +1065,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1204,7 +1233,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1217,9 +1247,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 59bdc28c89..f416722491 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1159,7 +1159,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index cfb7929fef..b896d8da2a 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index bc9aa68650..fa93a3684a 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -179,7 +179,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 57d34b2205..a0d87ef9d0 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -371,6 +371,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -663,7 +665,7 @@ int domain_kill(struct domain *d);
 int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:33:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:33:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjLv-0006XT-Bv; Tue, 22 Sep 2020 14:33:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjLu-0006XL-BE
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:06 +0000
X-Inumbo-ID: fb27d03d-d77a-4f75-ba1a-1a6dd19a2c70
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fb27d03d-d77a-4f75-ba1a-1a6dd19a2c70;
 Tue, 22 Sep 2020 14:33:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=gzovqe3VLnvEC7uyszenjjKv7TWdOnNAUb96nOldrvU=; b=juPm3rtDE/x/rAOC088HkniP+W
 GIEORZDDv8Nhdjjv31ynEtEo7SXiuXhM+UdKfIj+sf6npPBsbo/oMPxJ4NjKRQw08Fra0SYLvDQty
 8ES7xzLKRW5iWVNlWUPPUnS76EPtLAivIEp1qgi+e1y94/DSfykc1mJdWpyadZFGwk6c=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjLt-0008HK-Bp
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjLt-0001Xn-9u
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/pv: Handle the Intel-specific MSR_MISC_ENABLE
 correctly
Message-Id: <E1kKjLt-0001Xn-9u@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b98031951d19b9576a2200859bae86119c1e681c
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:20:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:20:09 2020 +0200

    x86/pv: Handle the Intel-specific MSR_MISC_ENABLE correctly
    
    This MSR doesn't exist on AMD hardware, and switching away from the safe
    functions in the common MSR path was an erroneous change.
    
    Partially revert the change.
    
    This is XSA-333.
    
    Fixes: 4fdc932b3cc ("x86/Intel: drop another 32-bit leftover")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/pv/emul-priv-op.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 9a5b3edfae..42258c6bf1 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -869,7 +869,8 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, *val);
+        if ( rdmsr_safe(reg, *val) )
+            break;
         *val = guest_misc_enable(*val);
         return X86EMUL_OKAY;
 
@@ -1009,7 +1010,8 @@ static int write_msr(unsigned int reg, uint64_t val,
         break;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, temp);
+        if ( rdmsr_safe(reg, temp) )
+            break;
         if ( val != guest_misc_enable(temp) )
             goto invalid;
         return X86EMUL_OKAY;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:33:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:33:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjM5-0006Z6-DX; Tue, 22 Sep 2020 14:33:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjM4-0006Yr-FC
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:16 +0000
X-Inumbo-ID: 5569f2c3-fe40-4631-bdf3-f46920521e48
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 5569f2c3-fe40-4631-bdf3-f46920521e48;
 Tue, 22 Sep 2020 14:33:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=13dkH4J3XtI177QyKzXrVBVu+A0Fvzd+B2Gcj3tSL58=; b=5Xq6rN5IStZv/U7zTieWNfWM4q
 cEjpfOgkuWKkQy4z/u+iI2YePQilIBp8kBqppBsWdMEVOu4SWlGlhAB9g1jjDgXIdJ+tqPGs+i6Ha
 dGBgkw9ebXxX6RZp2glR6Euqo4tVULX9KNeGFs+j7AoodUMLuKhW3T8TA55M5/WDZ2/8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjM3-0008He-Fq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjM3-0001Yn-Eg
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/memory: Don't skip the RCU unlock path in
 acquire_resource()
Message-Id: <E1kKjM3-0001Yn-Eg@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 286b3539b7e6af63c22c080c4dfe52c957e0c23f
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:20:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:20:46 2020 +0200

    xen/memory: Don't skip the RCU unlock path in acquire_resource()
    
    In the case that an HVM Stubdomain makes an XENMEM_acquire_resource hypercall,
    the FIXME path will bypass rcu_unlock_domain() on the way out of the function.
    
    Move the check to the start of the function.  This does change the behaviour
    of the get-size path for HVM Stubdomains, but that functionality is currently
    broken and unused anyway, as well as being quite useless to entities which
    can't actually map the resource anyway.
    
    This is XSA-334.
    
    Fixes: 83fa6552ce ("common: add a new mappable resource type: XENMEM_resource_grant_table")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/memory.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 3c085a0cd0..b2b6a775d9 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1057,6 +1057,14 @@ static int acquire_resource(
     xen_pfn_t mfn_list[32];
     int rc;
 
+    /*
+     * FIXME: Until foreign pages inserted into the P2M are properly
+     *        reference counted, it is unsafe to allow mapping of
+     *        resource pages unless the caller is the hardware domain.
+     */
+    if ( paging_mode_translate(currd) && !is_hardware_domain(currd) )
+        return -EACCES;
+
     if ( copy_from_guest(&xmar, arg, 1) )
         return -EFAULT;
 
@@ -1113,14 +1121,6 @@ static int acquire_resource(
         xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)];
         unsigned int i;
 
-        /*
-         * FIXME: Until foreign pages inserted into the P2M are properly
-         *        reference counted, it is unsafe to allow mapping of
-         *        resource pages unless the caller is the hardware domain.
-         */
-        if ( !is_hardware_domain(currd) )
-            return -EACCES;
-
         if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) )
             rc = -EFAULT;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:33:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:33:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjMG-0006cd-SE; Tue, 22 Sep 2020 14:33:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjME-0006c2-SO
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:26 +0000
X-Inumbo-ID: 47b9ebef-dd81-42f4-a4bf-4634e153b2b7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 47b9ebef-dd81-42f4-a4bf-4634e153b2b7;
 Tue, 22 Sep 2020 14:33:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=qZ3ywpOBFTr4+LLRnzSxBQdie3FUB6+FtAkV1SHHJkE=; b=H8ZTxKnAD83ExZx4zZSxT5PwyS
 lyxrmC9x/xXDxtrV61p552I9/MrfYh0SskfzBOw3NDKialJJF6m0u5P4ArKLt1XQ7R1rX9+Pb2mtR
 4w1ip6qzzQ1xqqXMmo/aZ6RUbZD+CP+dGfkcCJIzfVp1oufaCdyBMrKyuWqHEMPof1eQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMD-0008Hr-Ke
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMD-0001Ze-JW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/vpt: fix race when migrating timers between
 vCPUs
Message-Id: <E1kKjMD-0001Ze-JW@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 42fcdd42328f9819530f3f0350f9b851acc7c1a0
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 16:21:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:21:32 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 81 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 36380fcc92..704ac8b1bf 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -646,6 +646,8 @@ int hvm_domain_initialise(struct domain *d)
     /* need link to containing domain */
     d->arch.hvm.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index ecd25d7ad4..77b142406f 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -152,23 +152,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm.tm_lock);
+    read_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -218,7 +227,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -226,7 +235,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -234,7 +243,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -247,7 +256,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -308,7 +317,7 @@ int pt_update_irq(struct vcpu *v)
     int irq, pt_vector = -1;
     bool level;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -338,7 +347,7 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
@@ -346,7 +355,7 @@ int pt_update_irq(struct vcpu *v)
     irq = earliest_pt->irq;
     level = earliest_pt->level;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -393,7 +402,7 @@ int pt_update_irq(struct vcpu *v)
                 time_cb *cb = NULL;
                 void *cb_priv;
 
-                spin_lock(&v->arch.hvm.tm_lock);
+                pt_vcpu_lock(v);
                 /* Make sure the timer is still on the list. */
                 list_for_each_entry ( pt, &v->arch.hvm.tm_list, list )
                     if ( pt == earliest_pt )
@@ -403,7 +412,7 @@ int pt_update_irq(struct vcpu *v)
                         cb_priv = pt->priv;
                         break;
                     }
-                spin_unlock(&v->arch.hvm.tm_lock);
+                pt_vcpu_unlock(v);
 
                 if ( cb != NULL )
                     cb(v, cb_priv);
@@ -440,12 +449,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -454,7 +463,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -465,12 +474,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -489,7 +498,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -539,7 +548,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -564,30 +573,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 99169dd625..e2cdba4280 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -134,6 +134,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:33:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:33:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjMP-0006ef-V9; Tue, 22 Sep 2020 14:33:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjMO-0006eM-Hp
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:36 +0000
X-Inumbo-ID: def09c8c-0d42-437e-8e74-b1ad2bd24cba
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id def09c8c-0d42-437e-8e74-b1ad2bd24cba;
 Tue, 22 Sep 2020 14:33:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=kW+a+nnDMzUKib4Tb2+LCFXSBJE6rZer4OtBps9Alo4=; b=zFNDhN+yRv8gA4B7uRXP768FN3
 kGJeQw7aR4qdF7U8fm04A+J5cGCqEyAN8tvMbR0eZF23mQbIIWieNSf2azb1ZNPY98O6Wc3LGfeSg
 TDHpbEVAbksbMCntIEzTHXPQ7KSa6ITyvdV2JlzNAYTTfhvPHEBecPQ2zS97WfJBaCXw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMN-0008IT-O0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMN-0001aC-N4
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKjMN-0001aC-N4@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b7fcbe0150c7df1c0dc97853b46e1cf39f8d8ad9
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 16:22:08 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:22:08 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 53 +----------------------------------------------------
 1 file changed, 1 insertion(+), 52 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 54d13aecf7..2d02f8aa86 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -183,54 +183,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        uint16_t data;
-
-        msg->address_lo = pci_conf_read32(dev->sbdf,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(dev->sbdf,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(dev->sbdf, msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -302,10 +254,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:33:49 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:33:49 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjMb-0006hM-0R; Tue, 22 Sep 2020 14:33:49 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjMZ-0006gx-Ab
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:47 +0000
X-Inumbo-ID: 7e2178a1-40db-44f8-b917-38049d5685eb
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7e2178a1-40db-44f8-b917-38049d5685eb;
 Tue, 22 Sep 2020 14:33:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=QS+44kfqWQkR57R8Zcw8IJ47aIoPSwONfT5gO30jfHY=; b=5/+rIHoC/ISkecc5jGcEe3Ku0w
 4hGNx7/GLFuzaUvNchvTZWVRbBo0NmzLF6ISvDVWbqBMACITHTvBW4y9KiWeH8boBhItcBCm5xTPx
 PhC6Ti7RDAcgg/BMigLeVOKaM1SlOy3mr0rVI05SFtEcHC17r0W7BlGLt6C8L55OcnYg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMY-0008Ij-7I
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMX-0001bA-QE
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/MSI-X: restrict reading of table/PBA bases
 from BARs
Message-Id: <E1kKjMX-0001bA-QE@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f27980a3306416a056c5f27a1ea34fb749aada2b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:22:31 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:22:31 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 2d02f8aa86..c919920749 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -769,16 +769,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
     unsigned int pos = pci_find_cap_offset(seg, bus, slot, func,
                                            PCI_CAP_ID_MSIX);
 
@@ -820,43 +818,45 @@ static int msix_capability_init(struct pci_dev *dev,
 
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(dev->sbdf, msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
-    {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(dev->sbdf, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->table.first = PFN_DOWN(table_paddr);
         msix->table.last = PFN_DOWN(table_paddr +
@@ -875,7 +875,18 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(msix->nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
+    }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
+        xfree(entry);
+        return -ENODATA;
     }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      (table_offset & ~PCI_MSIX_BIRMASK & ~PAGE_MASK);
 
     if ( entry )
     {
@@ -886,8 +897,15 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
-            pci_conf_write16(dev->sbdf, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
+            pci_conf_write16(dev->sbdf, msix_control_reg(pos), control);
             xfree(entry);
             return idx;
         }
@@ -1076,9 +1094,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjMo-0006lX-J8; Tue, 22 Sep 2020 14:34:02 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjMn-0006gf-9P
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:01 +0000
X-Inumbo-ID: 911dc90f-1a96-4bdf-94f4-cb89bb0ced63
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 911dc90f-1a96-4bdf-94f4-cb89bb0ced63;
 Tue, 22 Sep 2020 14:33:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tM8ER1EVUoMlxPbxmgXi9SafG3sPcGVL1vdy0jLF46A=; b=4qzPUKiHDc04U1V5EAgRSj+27m
 Sn3tceVulB9koULqnBOYkfyAj3x0lEATfbcg9QksZ/36T4cTUft2abeYfbqP02KGHEtLJQw/c8fjC
 H4lxUAVxZ0+l6h9JDzoabJ1HALPL8O7eUgmUOjgZ6OYaXy2Tr/I6pBhwH6RwViqVNZwA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMi-0008Is-AJ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMi-0001by-9S
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:33:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: relax port_is_valid()
Message-Id: <E1kKjMi-0001by-9S@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:33:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit ae922b9fc203cc3907b4feed5f2d50783b7c32d5
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:22:55 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:22:55 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index a7798f6765..ce45298377 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,8 +107,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjMu-0006nY-KX; Tue, 22 Sep 2020 14:34:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjMt-0006n4-Ci
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:07 +0000
X-Inumbo-ID: 12b3cf9b-0616-4991-836a-ee1823bce228
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 12b3cf9b-0616-4991-836a-ee1823bce228;
 Tue, 22 Sep 2020 14:34:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=DSsLuZv9qtNyTZQZcM7+lBeBQULHXGQcfOEhbXiDkbM=; b=ULKmrNGCVdzkrJCENq6nUx8o6x
 cuEnERlQYnJtim5xrLNDMaAoq6mtgHUFNN571CZQXHdIHtqoSBqBEEnR1O02Y+tNyhTSt+iZzI5VX
 kHGa3Bn7uY94tsidlPbA0yIsup3L2/qg/VTTzrsqnatcrBUk3+N1154qfaoSZHI0VZvY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMs-0008JD-EA
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjMs-0001cw-Cp
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/pv: Avoid double exception injection
Message-Id: <E1kKjMs-0001cw-Cp@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0537543cc1f149bd2c2236a215d95a8b617ee097
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 16:23:35 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:23:35 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index 3cd375bd48..33ac552cac 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -78,7 +78,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -349,7 +348,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 24731eeb37..5ec5522e33 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -90,7 +90,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -495,6 +494,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjN4-0006rH-MS; Tue, 22 Sep 2020 14:34:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjN3-0006qt-Gu
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:17 +0000
X-Inumbo-ID: ab25b807-3c86-430d-b0c4-7db2d10b41a8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ab25b807-3c86-430d-b0c4-7db2d10b41a8;
 Tue, 22 Sep 2020 14:34:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0R+udjwQKWoPTNbAxA+dM+gek0/XDmKiSTk5yTlLl4I=; b=tz6esL4ukGR7e5ZXd6kCh83lBa
 6zSQvqVv7wX8A2ArL86nVpjdMSLhMWa/Dk6rAW3BPBfP8CrRUtPTCdBBdTlYpl6sQBz2UaTNvsHPD
 T594wwRWatvNxbWkNfJ7IG0tyCwGcumNADgsW0/zYHtvY96xyKF9fCiHEJ4S6p4L16F0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjN2-0008JN-Hk
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjN2-0001e8-Gb
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKjN2-0001e8-Gb@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5867a14ac1747d7411066d7fb2cf238658346ab0
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 16:23:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:23:59 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index a8d182b584..53c17bd354 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -178,6 +178,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index ce45298377..c35f4b23b6 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,7 +107,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjNE-0006uV-PX; Tue, 22 Sep 2020 14:34:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjND-0006uC-Pl
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:27 +0000
X-Inumbo-ID: 04f42071-3247-4efd-9cf5-a67610545c47
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 04f42071-3247-4efd-9cf5-a67610545c47;
 Tue, 22 Sep 2020 14:34:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=+UXaIdAhMSs9ABoikN6OMiuANcDJbhNlU1BksC8wL7E=; b=sDds2euAbOmkPhUSQHa1YXeFdX
 7NZa7on9iqsCbY/4h+ahKrJze3UW4tTIin4GSUt1PVpXFQo/538GImEOCrQaAf7gom5LuOdOw4wrb
 eTPeV7XjpwqKwaXOJ8k1Yzs61hkfDUt1cAfyXPqeVstX4uz7XbTzyQU2AdT2H1P4kzw4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNC-0008JV-LH
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNC-0001fV-KR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKjNC-0001fV-KR@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e1364e05f92d6c2f12cc77f100cea584354c66cb
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:24:29 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:24:29 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/schedule.c      | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 53c17bd354..08ffe0f063 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -151,7 +151,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1396,13 +1396,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 230f440f14..2f13d92128 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -478,7 +478,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -488,7 +488,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -546,6 +546,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -562,8 +564,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index ccc20ce040..6b1ae7bf8c 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1434,7 +1434,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index c35f4b23b6..e1b299e8df 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -105,6 +105,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 9f7bc69293..c93c6d8bc1 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -382,7 +382,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjNO-0006x4-R9; Tue, 22 Sep 2020 14:34:38 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjNN-0006wq-P2
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:37 +0000
X-Inumbo-ID: d07a51a2-19e8-4311-a984-00d9d61bc405
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d07a51a2-19e8-4311-a984-00d9d61bc405;
 Tue, 22 Sep 2020 14:34:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rNPcF2jXchFA8TFn4/3bDDXLHQgeccAt1F7Ecx797Gs=; b=GZBWQruNncyituAMIqm7bxVcv5
 iS/MfTf2BZF1lcIDyXiQjJkE2VUZxnDoMnWnEebROixCcpEUuf2berGEn2SctRs/w/9G+WwoFYAjs
 zfbNhOuaNnuZ5VtvT8BStRZ1uFdEABlsI/g8r0KIK/6AnPY14q5eM+Cu50+enK4/LTBk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNM-0008KC-OF
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNM-0001gm-NY
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKjNM-0001gm-NY@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a8122e991da70ac1ee9f88e34e003d2169a5b114
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:25:16 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:25:16 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 08ffe0f063..6a566917b1 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -188,6 +188,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -211,11 +213,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -258,6 +275,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -351,6 +369,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -488,7 +507,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -536,6 +555,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1011,10 +1031,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1024,7 +1044,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1033,7 +1055,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1219,10 +1241,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1238,7 +1259,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1314,6 +1338,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
@@ -1340,6 +1365,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index c93c6d8bc1..caa80e9051 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -384,6 +384,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjNY-0006zk-Sn; Tue, 22 Sep 2020 14:34:48 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjNX-0006zP-Vd
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:48 +0000
X-Inumbo-ID: 104dea79-726c-4285-b7aa-91e9358c3d52
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 104dea79-726c-4285-b7aa-91e9358c3d52;
 Tue, 22 Sep 2020 14:34:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=p5kaWeV6+kF3b+N2WU3x1KZpOPdO4qDiIGj8ci2oUbY=; b=2LzUvh/NunPQc8GhQuJelwpr+b
 2fTv51HYaHykCSPicfaA0fVfwO46i83Yk+OSfXhl+aRgDohKTBqpib4Pb3O40a+3m9NONk4TJ5PsZ
 l7eMhHJC3l1LraSi0LhPSrd21EMzAAfA5QgXtEzrj5SMArMECDYIvqyfPQ2AthVtegkk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNW-0008Lm-RM
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNW-0001j8-Qb
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKjNW-0001j8-Qb@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 21054297bf832d8eacd73dc428f55168522b0d86
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:26:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:26:01 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 6a566917b1..0e550e9c7a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -248,6 +248,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -263,14 +264,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -283,26 +284,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -312,6 +319,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -347,7 +355,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -364,7 +372,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -387,6 +395,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -424,14 +433,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -448,6 +457,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( domain_vcpu(d, vcpu) == NULL )
         return -ENOENT;
@@ -459,13 +469,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -509,6 +519,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -541,14 +552,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -569,6 +580,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -668,14 +680,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -683,9 +695,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -705,13 +717,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -746,7 +759,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1238,6 +1251,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1250,14 +1264,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1280,11 +1294,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1294,7 +1309,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:34:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:34:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjNj-00071s-Uf; Tue, 22 Sep 2020 14:34:59 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjNi-00071e-J6
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:58 +0000
X-Inumbo-ID: 4a58d6b9-02fc-4b85-a64d-a72fbf1a7045
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4a58d6b9-02fc-4b85-a64d-a72fbf1a7045;
 Tue, 22 Sep 2020 14:34:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=SdzsUM8XLLHDEbPya9uq9/+ZyVYZsfrB6fpRxwS0EKY=; b=D6tzkvi+bcKRAgIpjkQNoD/NAa
 ++PnOnxzJ9+zpP6Hp5psbc2sUe5hqS9BdbrCgmMZP/Y9D0Ccr0E0uVz67ugrLpE/Ai0upYYiRkAvV
 +mFbqoZvYTsM46djA0eY5OafF60CBzele/tJepXqfuJpLKZM7hL8QGcG/zf6/m+rpc0A=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNg-0008Lt-W0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNg-0001kK-V1
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:34:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: address races with evtchn_reset()
Message-Id: <E1kKjNg-0001kK-V1@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:34:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 43572a4cd97902ba0155b922a4d2e99fb945ec2b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:26:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:26:32 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index ed32318659..bb95583742 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2474,14 +2474,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i++];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("d%d:%3d(%c%c%c)%c",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       info->masked ? 'M' : '-',
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-',
                        i < action->nr_guests ? ',' : '\n');
             }
         }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index ac17533923..bbecbfa16f 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -660,8 +660,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 0e550e9c7a..878e4250ed 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -156,8 +156,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -774,6 +775,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -784,7 +786,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -813,7 +818,9 @@ void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -823,6 +830,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -837,7 +845,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1034,12 +1044,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1449,8 +1462,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 2f13d92128..68d0c7a632 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -296,23 +296,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 98a85233cb..5e09ede6d7 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline bool arch_virq_is_global(unsigned int virq)
     return true;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index e1b299e8df..bc9aa68650 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -133,6 +133,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -165,19 +183,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -193,38 +216,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -233,6 +285,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:35:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:35:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjNu-00073h-1b; Tue, 22 Sep 2020 14:35:10 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjNs-00073S-8I
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:08 +0000
X-Inumbo-ID: eca6d04a-e834-4530-8ff0-5a1ee0b96a2d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eca6d04a-e834-4530-8ff0-5a1ee0b96a2d;
 Tue, 22 Sep 2020 14:35:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=g1V8Hudc4wVjxT5yQ+Y4HGZ1OcmCGfqoR10meQq+8Qk=; b=umTECDqk4o4X7i7dOw1uvipkAN
 3oI4BS7aiI32M2W53//TFUOTZUQ+pIUtxZ7IdaWi53KxQ7YOtDcQJQ49aPI6tOfV7EhVgyoNkQ/4o
 L8zV2nhsYs5hAI8UYDrAMvibk/8ttj7yYyCb1/CTM3hulveeNHStZV+FMSdBTHBagOgw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNr-0008ME-5o
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjNr-0001lt-3h
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKjNr-0001lt-3h@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:35:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 54becf611dcc77f3f49eb8238a7c401eba7ca78b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:27:07 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:27:07 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 30b5f7f898..2ff6a79500 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -770,12 +770,14 @@ int domain_kill(struct domain *d)
             return domain_kill(d);
         d->is_dying = DOMDYING_dying;
         argo_destroy(d);
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         vnuma_destroy(d->vnuma);
         domain_set_outstanding_pages(d, 0);
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 878e4250ed..3b1fe423df 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1297,7 +1297,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1309,7 +1318,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1380,8 +1399,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1390,14 +1408,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index caa80e9051..b740cfdf9f 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -136,7 +136,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d, unsigned int max_port);
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 14:35:20 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 14:35:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKjO4-00075m-37; Tue, 22 Sep 2020 14:35:20 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKjO2-00075T-Gr
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:18 +0000
X-Inumbo-ID: 750eda44-6c40-4cd8-b062-dff77d44e604
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 750eda44-6c40-4cd8-b062-dff77d44e604;
 Tue, 22 Sep 2020 14:35:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=1Aqv/OteeBIv9WXKuBbmOxQzUvCH42cHVQMkDB5A2bg=; b=gluVq+cnIouySEKYjb7yf1cSe6
 7x7CBHb8DeXIGOOrhshPOsmDceK7w7WlVM6wlxW5XMw15fQNBX3EV9QN0/zwGl99bPJ3vnuhjpaUi
 tf4hXs2RilIxpoEbjw+MecBp5UrwSToH1EhxfNEPyLExMNqPpq2pMuMkHRNCPdfzMUxw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjO1-0008MM-A3
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKjO1-0001mz-9B
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 14:35:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKjO1-0001mz-9B@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 14:35:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b015fbe509188dca47b6c7102a934a7b9ced2a9e
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 16:28:08 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 16:28:08 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 2ff6a79500..e0dd88f0f4 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1214,7 +1214,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1228,7 +1228,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 03d0226039..7fe4f4a30c 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -572,12 +572,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 3b1fe423df..d2ee83bbbf 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1057,7 +1057,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1065,11 +1065,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1204,7 +1233,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1217,9 +1247,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index e313da499f..b957dc5a92 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1152,7 +1152,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index 44c549dd6b..a1949191c6 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index bc9aa68650..fa93a3684a 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -179,7 +179,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index b740cfdf9f..d6e27fc4b8 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -394,6 +394,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -663,7 +665,7 @@ int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 void domain_pause_for_debugger(void);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk7M-0004Ss-93; Tue, 22 Sep 2020 15:22:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk7L-0004Sn-3P
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:07 +0000
X-Inumbo-ID: b22c0898-c192-415f-b0de-de98328fdcfe
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b22c0898-c192-415f-b0de-de98328fdcfe;
 Tue, 22 Sep 2020 15:22:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wLjattfEfa4jYHRl0P/C81kOvwJDszNN7kDKe1qQJAw=; b=wHCuslpHf9G1ahgVd3/5p53mcD
 wEeIFdEHzsIHwOfsUTD7P4ip6Ba0B7p0FndV3Ypm7fIgVv0L916NdXIt+U7Zb+/HozS3AWO5xr5/+
 cNk0OqRWAmbYBRQiTA0dwztGhpllj0jy1GuJYxdPEARZCnmqqAs7ovaoK1VmhjqxITjw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7J-0000wu-MN
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7J-0005KV-Jg
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/pv: Handle the Intel-specific MSR_MISC_ENABLE
 correctly
Message-Id: <E1kKk7J-0005KV-Jg@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 320e7a7369245d4304ac822e67740a7ea147e7a2
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:04:22 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:04:22 2020 +0200

    x86/pv: Handle the Intel-specific MSR_MISC_ENABLE correctly
    
    This MSR doesn't exist on AMD hardware, and switching away from the safe
    functions in the common MSR path was an erroneous change.
    
    Partially revert the change.
    
    This is XSA-333.
    
    Fixes: 4fdc932b3cc ("x86/Intel: drop another 32-bit leftover")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/pv/emul-priv-op.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 5d4065333a..324a2334a2 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -892,7 +892,8 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, *val);
+        if ( rdmsr_safe(reg, *val) )
+            break;
         *val = guest_misc_enable(*val);
         return X86EMUL_OKAY;
 
@@ -1030,7 +1031,8 @@ static int write_msr(unsigned int reg, uint64_t val,
         break;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, temp);
+        if ( rdmsr_safe(reg, temp) )
+            break;
         if ( val != guest_misc_enable(temp) )
             goto invalid;
         return X86EMUL_OKAY;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk7V-0004U7-Ac; Tue, 22 Sep 2020 15:22:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk7V-0004TO-2c
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:17 +0000
X-Inumbo-ID: 9b1a28b3-cd8b-4024-b42a-ece8cd55e957
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9b1a28b3-cd8b-4024-b42a-ece8cd55e957;
 Tue, 22 Sep 2020 15:22:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=4aTBfF9ggAwKQSD9M4qUCREyrXdFSIwwDTHTtB1ZF6o=; b=gBuXr4EHg/wefyoWNjzAwhRY2k
 2yBIhcJDKfenYO/+Ty/1ULe2xoZNoLNozZYQClxPfHsx+wtnQs9qqrgyNpgT2dmIVZkkklYw1IGFg
 7nhJKtoXoEZVYbG5/SJUDs12h8HjGPGtwmwZNV488iojvajAb3RfHLcUDLq80ZYODZDc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7T-0000wx-Qd
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7T-0005L5-Oq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/memory: Don't skip the RCU unlock path in
 acquire_resource()
Message-Id: <E1kKk7T-0005L5-Oq@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8b8fff26f58de808deec4f51ed34069e6bf1618b
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:04:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:04:58 2020 +0200

    xen/memory: Don't skip the RCU unlock path in acquire_resource()
    
    In the case that an HVM Stubdomain makes an XENMEM_acquire_resource hypercall,
    the FIXME path will bypass rcu_unlock_domain() on the way out of the function.
    
    Move the check to the start of the function.  This does change the behaviour
    of the get-size path for HVM Stubdomains, but that functionality is currently
    broken and unused anyway, as well as being quite useless to entities which
    can't actually map the resource anyway.
    
    This is XSA-334.
    
    Fixes: 83fa6552ce ("common: add a new mappable resource type: XENMEM_resource_grant_table")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/memory.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index dbc06fb0bf..ff88ebb314 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -1059,6 +1059,14 @@ static int acquire_resource(
     xen_pfn_t mfn_list[32];
     int rc;
 
+    /*
+     * FIXME: Until foreign pages inserted into the P2M are properly
+     *        reference counted, it is unsafe to allow mapping of
+     *        resource pages unless the caller is the hardware domain.
+     */
+    if ( paging_mode_translate(currd) && !is_hardware_domain(currd) )
+        return -EACCES;
+
     if ( copy_from_guest(&xmar, arg, 1) )
         return -EFAULT;
 
@@ -1115,16 +1123,6 @@ static int acquire_resource(
         xen_pfn_t gfn_list[ARRAY_SIZE(mfn_list)];
         unsigned int i;
 
-        /*
-         * FIXME: Until foreign pages inserted into the P2M are properly
-         *        reference counted, it is unsafe to allow mapping of
-         *        non-caller-owned resource pages unless the caller is
-         *        the hardware domain.
-         */
-        if ( !(xmar.flags & XENMEM_rsrc_acq_caller_owned) &&
-             !is_hardware_domain(currd) )
-            return -EACCES;
-
         if ( copy_from_guest(gfn_list, xmar.frame_list, xmar.nr_frames) )
             rc = -EFAULT;
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk7g-0004VJ-CE; Tue, 22 Sep 2020 15:22:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk7f-0004VA-8m
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:27 +0000
X-Inumbo-ID: 4483d92c-2f73-40db-9a45-653bdbd3b263
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4483d92c-2f73-40db-9a45-653bdbd3b263;
 Tue, 22 Sep 2020 15:22:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=eXgdaMAlxvdQLlv4gS1NecY63/Gj54lbHyL+SXo2ja0=; b=l/gtDeJCV0uEfyf9e7E6K4/ADM
 2CkJPg8EITl1Ohuqkkw2b4tRVs9eCI2HREx1puJbHC1/IyxKpRGaezMCr5VGhOuvlSvdrQGtH1h7f
 KqMrVg7C6A6Gn8jUP3LBqnYs3Rtl3uhK1FdlUOKiCw8MuWLziLkFlo8QCqFfIBjpMDJQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7d-0000x5-UZ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7d-0005M6-TM
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/vpt: fix race when migrating timers between
 vCPUs
Message-Id: <E1kKk7d-0005M6-TM@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d28c52ee2aee0297062ee86c69f60a30b659c290
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:05:39 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:05:39 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 81 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index c87dfe6155..a98f7471b4 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -632,6 +632,8 @@ int hvm_domain_initialise(struct domain *d)
     /* need link to containing domain */
     d->arch.hvm.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index ecd25d7ad4..77b142406f 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -152,23 +152,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm.tm_lock);
+    read_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -218,7 +227,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -226,7 +235,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -234,7 +243,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -247,7 +256,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -308,7 +317,7 @@ int pt_update_irq(struct vcpu *v)
     int irq, pt_vector = -1;
     bool level;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -338,7 +347,7 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
@@ -346,7 +355,7 @@ int pt_update_irq(struct vcpu *v)
     irq = earliest_pt->irq;
     level = earliest_pt->level;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -393,7 +402,7 @@ int pt_update_irq(struct vcpu *v)
                 time_cb *cb = NULL;
                 void *cb_priv;
 
-                spin_lock(&v->arch.hvm.tm_lock);
+                pt_vcpu_lock(v);
                 /* Make sure the timer is still on the list. */
                 list_for_each_entry ( pt, &v->arch.hvm.tm_list, list )
                     if ( pt == earliest_pt )
@@ -403,7 +412,7 @@ int pt_update_irq(struct vcpu *v)
                         cb_priv = pt->priv;
                         break;
                     }
-                spin_unlock(&v->arch.hvm.tm_lock);
+                pt_vcpu_unlock(v);
 
                 if ( cb != NULL )
                     cb(v, cb_priv);
@@ -440,12 +449,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -454,7 +463,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -465,12 +474,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -489,7 +498,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&v->domain->arch.hvm.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -539,7 +548,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&v->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -564,30 +573,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 99169dd625..e2cdba4280 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -134,6 +134,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk7p-0004WS-FA; Tue, 22 Sep 2020 15:22:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk7o-0004WL-VU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:36 +0000
X-Inumbo-ID: 31d2016c-68a2-4934-9ff9-d6f4c50014df
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 31d2016c-68a2-4934-9ff9-d6f4c50014df;
 Tue, 22 Sep 2020 15:22:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=QS66hFR+DjfchIm8rifewegd2DbRaMvecbp9T3CcEr8=; b=X3KgU814ux7wVGuYScVVRl/lnI
 302PfWgyaBI6FNGb4LtzBrgsEwoqM1AnArfr+l/gS66kO+u2Wgj4wslXETq3exIrGaPJm0Gp4lzbv
 OcxTDR1beYAfSNNPCUQRPEKyDWQ+Z3yp9sb5i3JQ70Y4v36vWhhHewFQXRcjW/XZMju0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7o-0000xs-3k
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7o-0005Mj-0c
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKk7o-0005Mj-0c@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 76a0760f6c69f2b2c0c4239d269e21874fe56271
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:06:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:06:09 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 58 +-----------------------------------------------------
 1 file changed, 1 insertion(+), 57 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index efb4759ec5..d4958e2039 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -192,59 +192,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        u16 data, seg = dev->seg;
-        u8 bus = dev->bus;
-        u8 slot = PCI_SLOT(dev->devfn);
-        u8 func = PCI_FUNC(dev->devfn);
-
-        msg->address_lo = pci_conf_read32(seg, bus, slot, func,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(seg, bus, slot, func,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -322,10 +269,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk80-0004Xg-Gh; Tue, 22 Sep 2020 15:22:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk7z-0004XX-8m
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:47 +0000
X-Inumbo-ID: 954869af-16fb-4517-aed3-8dc3e79be73d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 954869af-16fb-4517-aed3-8dc3e79be73d;
 Tue, 22 Sep 2020 15:22:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=oSz3YwtC3S05+j/eR2B8n/Tn0C02C2NH9bAsNzRAHG8=; b=Cf1bhvKKTAxyQJDuZSM9sfrqVD
 zeZP+gzggO6Z0K9Tm4aqqlm/YeeeqeBnwYiuifRv7YztgbqdC9CQCebQ5p5Rylpv/sMILwfTdOkZk
 3T+kTBzQpV5T6qAJJSWfvjktpuxdyT19A9YCQOKdhG/gxhCDR9TrdXTBEmgVZLY01uu0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7y-0000xz-7f
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk7y-0005ND-67
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/MSI-X: restrict reading of table/PBA bases
 from BARs
Message-Id: <E1kKk7y-0005ND-67@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1dfd2e2f654fd93848767369a1705727d523b453
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:06:34 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:06:34 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 61 insertions(+), 36 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index d4958e2039..36153dc031 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -790,16 +790,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
 
     ASSERT(pcidevs_locked());
 
@@ -837,43 +835,45 @@ static int msix_capability_init(struct pci_dev *dev,
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(seg, bus, slot, func,
                                    msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
-    {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->nr_entries = nr_entries;
         msix->table.first = PFN_DOWN(table_paddr);
@@ -894,7 +894,19 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
     }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                         control);
+        xfree(entry);
+        return -ENODATA;
+    }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      (table_offset & ~PCI_MSIX_BIRMASK & ~PAGE_MASK);
 
     if ( entry )
     {
@@ -905,8 +917,16 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
             pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+                             control);
             xfree(entry);
             return idx;
         }
@@ -1102,9 +1122,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:22:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:22:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8A-0004Yf-IJ; Tue, 22 Sep 2020 15:22:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk89-0004YT-Dt
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:57 +0000
X-Inumbo-ID: 1a54b590-1bef-4caf-b0d7-e6ef0c355c72
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1a54b590-1bef-4caf-b0d7-e6ef0c355c72;
 Tue, 22 Sep 2020 15:22:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=QWwHA8zRuEfo2VYgBJk/7BnMMXQVQKUwJGIdRUAoRpg=; b=Jx/Szbj8VxmaK/Cki2HngRRpBv
 GF/Zu3BR9XDXm7GK6bgn0pdQ8aeTk/F9nNX8Bh26oR4vzqZctXJL901GeTcDd6QcBKZYZtAZ2YBAi
 vkBPw2OQsiqoeGT3STr6PzY8GZdc12+VYIYHO+euiwSUXfQPspNy97USrLhFM0mN+0Ss=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk88-0000y9-BM
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk88-0005OJ-9m
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:22:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: relax port_is_valid()
Message-Id: <E1kKk88-0005OJ-9m@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:22:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b2db00754fc39971bb0ff8a60c54ae8a58c3d473
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:06:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:06:59 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index a7798f6765..ce45298377 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,8 +107,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:08 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:08 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8K-0004Zo-Jp; Tue, 22 Sep 2020 15:23:08 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk8J-0004Ze-Kj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:07 +0000
X-Inumbo-ID: 6cf7b070-2f39-410e-8090-9c71bbc67bd1
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6cf7b070-2f39-410e-8090-9c71bbc67bd1;
 Tue, 22 Sep 2020 15:23:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=mm1CctqWphmr3FrGqwOai6lmtyZQhG2T+Uff34RgaO8=; b=Hva9iy5LkPX14Fum+tQe6LBi70
 69GunrLZxvWesF2N7ZaxvyJgNjARlxfBbDESFh2pmV3fcVgeD80nVTDqp4W9U3IB/qWEoCmDbt+o5
 9Zl0NmyFA2DFjkT5YWB42IGhBeL0I8O5A4oounbyVXWfQBAIfPtAIaF/rKm7dYMPhtdM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8I-0000ya-FU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8I-0005Pb-EC
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/pv: Avoid double exception injection
Message-Id: <E1kKk8I-0005Pb-EC@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3e039e12ecfdefbf3ecbc5a63052620a1fe51ad5
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:07:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:07:38 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index 175c2fe451..16c5a46e75 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -81,7 +81,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -352,7 +351,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index f9d64cca84..65229a1a68 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -93,7 +93,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -498,6 +497,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8U-0004bR-LW; Tue, 22 Sep 2020 15:23:18 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk8T-0004bD-VX
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:18 +0000
X-Inumbo-ID: 7849553b-ae55-452a-bb2a-5e3be81aa411
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 7849553b-ae55-452a-bb2a-5e3be81aa411;
 Tue, 22 Sep 2020 15:23:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IGvHg3H1h4lPLiRIcs5iigfnycFVWhwuQp/FGfal09U=; b=s4jKaNMrgVR2W3lKJ00zkhfjma
 7YMA82yBJRt8yidFs4DCzR0UwRoJNrNTyNHFYuy0abH0ulQhOdGskxKJ86WYkrz7vLAI+ZIpfg0bD
 wohBJSqsymq1dha38IOTz4Imz9ltSpYSCdBSPvTqaxEJHpC+tFJBB0Z7b2D3CTqxVJNM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8S-0000yn-If
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8S-0005QI-Hr
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKk8S-0005QI-Hr@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 253a1e64d30e09ae089a060e364a01b4d442d550
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 17:08:00 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:08:00 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index a8d182b584..53c17bd354 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -178,6 +178,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index ce45298377..c35f4b23b6 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -107,7 +107,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8e-0004cr-OL; Tue, 22 Sep 2020 15:23:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk8d-0004cj-Mv
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:27 +0000
X-Inumbo-ID: d75c690e-f6e5-4942-9558-ad952d647cd5
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d75c690e-f6e5-4942-9558-ad952d647cd5;
 Tue, 22 Sep 2020 15:23:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=YzfbAhOF1LVjTzZElEqH3fc2TXxk1DpjMh/yaSQCXSI=; b=mr98mMM7rSrc58RrPSeZGktJeJ
 mtSHUmsbJTkH6btFz91kZGywKyKXDKYLWqWRaaoJaQAeGfVkhWogq5rCUSrqRP5U6LSM2g3f8syf0
 g2EbklvUQjFl82vVfQ1p6H7VyLbBjkVscXpdSnAyf0slIPq9yLJa+xbGXq9bl235Ukno=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8c-0000yt-M0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8c-0005RC-LA
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKk8c-0005RC-LA@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit b8c9776986968bd1e90835df408f8bfc60640040
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:09:25 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:09:25 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/schedule.c      | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 53c17bd354..08ffe0f063 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -151,7 +151,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1396,13 +1396,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 230f440f14..2f13d92128 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -478,7 +478,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -488,7 +488,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -546,6 +546,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -562,8 +564,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 5f42c08076..5a09e68b9e 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1058,7 +1058,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index c35f4b23b6..e1b299e8df 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -105,6 +105,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index edee52dfe4..0dea5ecbf5 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -344,7 +344,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8o-0004dx-Pu; Tue, 22 Sep 2020 15:23:38 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk8n-0004do-Rg
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:37 +0000
X-Inumbo-ID: 68ea30a0-0e79-44f7-baf6-022b2edd7d14
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 68ea30a0-0e79-44f7-baf6-022b2edd7d14;
 Tue, 22 Sep 2020 15:23:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=QvGnXZ9uX7RNv26QZk2lybTaRTs38Bm9PDcN49sHOHg=; b=bE5PwEepIObjq9BXwXPkJ2cfHl
 xVfv3abGhyvVmfCxN+ztfUhTwoctMJJNLwW3Qs9OVR82vg7MBkCfWKfB4dJi+JpNsF5nZDWcUuX1q
 sD+zrpysrfpXkfOc+iMW8I8L33fNTF4rBe7n4Dpp0qtaDjOX4j3H1S5sMfH1ewU+dz3g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8m-0000zY-P3
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8m-0005SO-OH
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKk8m-0005SO-OH@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9dda47cb702ccb9663aec9c78ac3fdc3d4076b1c
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:09:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:09:59 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 08ffe0f063..6a566917b1 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -188,6 +188,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -211,11 +213,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -258,6 +275,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -351,6 +369,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -488,7 +507,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -536,6 +555,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1011,10 +1031,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1024,7 +1044,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1033,7 +1055,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1219,10 +1241,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1238,7 +1259,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1314,6 +1338,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
@@ -1340,6 +1365,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 0dea5ecbf5..8d0c817d7d 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -346,6 +346,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk8y-0004f5-Rf; Tue, 22 Sep 2020 15:23:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk8x-0004et-VU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:48 +0000
X-Inumbo-ID: 829ca9c4-7ca4-4227-b2c3-b8380df9d9e8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 829ca9c4-7ca4-4227-b2c3-b8380df9d9e8;
 Tue, 22 Sep 2020 15:23:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=L4ASYqQ4DoLBSWWAeu7/PwIzo5WRjcxBvhXkilT7eEk=; b=Ggd6MU1qVIEPP8bdVIKL/LSevM
 k6C5Xs/mOAI2K5quSGDhifofV6Exmrs63cF4uPaUHZ5nJl9TaO5IV2UbV7u52fFvN29UK8OYl8VKA
 mQ1jZ7E17j4MooS0eObKPQZO4cyD7hTTCCb1fXIBu1QdIRmJ9H9yyI+L2bIxs1/GjlBY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8w-0000zf-SD
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk8w-0005TI-RR
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKk8w-0005TI-RR@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9c2a02740f7f91543caa8fab6d2ab2bbc7c40742
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:10:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:10:32 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 6a566917b1..0e550e9c7a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -248,6 +248,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -263,14 +264,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -283,26 +284,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -312,6 +319,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -347,7 +355,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -364,7 +372,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -387,6 +395,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -424,14 +433,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -448,6 +457,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( domain_vcpu(d, vcpu) == NULL )
         return -ENOENT;
@@ -459,13 +469,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -509,6 +519,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -541,14 +552,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -569,6 +580,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -668,14 +680,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -683,9 +695,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -705,13 +717,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -746,7 +759,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1238,6 +1251,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1250,14 +1264,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1280,11 +1294,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1294,7 +1309,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:23:59 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:23:59 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk99-0004g5-TQ; Tue, 22 Sep 2020 15:23:59 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk98-0004ft-IW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:58 +0000
X-Inumbo-ID: 8fe459eb-1e77-42e1-8932-63156a083799
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8fe459eb-1e77-42e1-8932-63156a083799;
 Tue, 22 Sep 2020 15:23:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=vHY1GCugaBwHxud9tOTB1fn/SBJYJfiLe8fmC1bvg/0=; b=yfcwnboruRhYRSKks0o7hIb+YI
 pAgecYRZtZOgd2He9G5KJxS0raWd3wDcJaPkfI8jdn7uSkP2mTH/ybTYNWIKRfokOmIh12PgEkAFh
 tA4sp0II2dgAYs59DKYt8Q7J2gcC1MHu+vnyIAI73PxHX083qAEujag8G6DA4ve/eK7A=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk97-0000zn-09
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:57 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk96-0005Tz-Up
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:23:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: address races with evtchn_reset()
Message-Id: <E1kKk96-0005Tz-Up@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:23:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8e25d522a3fc236c0c7a02541e8071afa031386b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:11:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:11:01 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index ade659c3c2..f49ce8cf57 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2364,14 +2364,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; i++ )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("%u:%3d(%c%c%c)",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       (info->masked ? 'M' : '-'));
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-');
                 if ( i != action->nr_guests )
                     printk(",");
             }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 1501fc0632..91d44d6f1c 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -662,8 +662,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 0e550e9c7a..878e4250ed 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -156,8 +156,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -774,6 +775,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -784,7 +786,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -813,7 +818,9 @@ void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -823,6 +830,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -837,7 +845,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1034,12 +1044,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1449,8 +1462,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 2f13d92128..68d0c7a632 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -296,23 +296,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 2f6ea54bcb..f61d2f7adb 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline bool arch_virq_is_global(unsigned int virq)
     return true;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index e1b299e8df..bc9aa68650 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -133,6 +133,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -165,19 +183,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -193,38 +216,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -233,6 +285,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:24:09 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:24:09 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk9J-0004h6-0I; Tue, 22 Sep 2020 15:24:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk9I-0004gy-5t
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:08 +0000
X-Inumbo-ID: 1e9573d2-b0d7-4f52-8fe7-44a92699904a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1e9573d2-b0d7-4f52-8fe7-44a92699904a;
 Tue, 22 Sep 2020 15:24:07 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=UbQ7ejPJd2zzyieM+C9fGnGGpu9pUmNGMGTNbsiXWuE=; b=gx/KCxEUZfm/hd/hWDIEIe7fF/
 bbpbikq2/XVaMXGZ+NG6WJD6xW2FwxXOSb+OihTsG9BigM5sYImzgk4ugnXVIvP03I9fgwAGzbwcd
 rpS07RVPcROUhLFJhZli9CqPnPydeBH+ZLEAaeW4BElvbnNKaXKK7YE8YLFBPnuhfgu4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9H-00010C-3R
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:07 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9H-0005Ux-2f
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:07 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKk9H-0005Ux-2f@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:07 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2aa4864b8a25f2a4b3f2647dbf75abd88e3514ad
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:11:33 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:11:33 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 5f94651f11..8e44e88bc4 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -724,7 +724,6 @@ int domain_kill(struct domain *d)
             return domain_kill(d);
         d->is_dying = DOMDYING_dying;
         argo_destroy(d);
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         tmem_destroy(d->tmem_client);
         vnuma_destroy(d->vnuma);
@@ -732,6 +731,9 @@ int domain_kill(struct domain *d)
         d->tmem_client = NULL;
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 878e4250ed..3b1fe423df 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1297,7 +1297,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1309,7 +1318,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1380,8 +1399,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1390,14 +1408,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 8d0c817d7d..f70d990dbb 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -136,7 +136,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d, unsigned int max_port);
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:24:20 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:24:20 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk9U-0004iv-1u; Tue, 22 Sep 2020 15:24:20 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk9S-0004il-HQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:18 +0000
X-Inumbo-ID: a453be0a-efc9-4492-98f1-90c279e0c2c2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a453be0a-efc9-4492-98f1-90c279e0c2c2;
 Tue, 22 Sep 2020 15:24:17 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=N6meYS+bT/eIYjkG28wHrbGsIwnDDCM2Yc6+3RaaijA=; b=jQAHyd6wZxzdkEDfE9tF1n58ti
 v3FLASAxoYcs3WdOXMNMbyYMnr/6DhSH+PBvcpyuWfOhqQZcMVVhv+npzmlAFTNt+k1H0xVTLyNQd
 dlUx6yizJtSa1TvJ4mWL/+Htwl/TNB61bKL/atKB8gBnu2q67PQl/2/ZEQ0Lkk/+I5ns=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9R-00010M-6v
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:17 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9R-0005Vj-6D
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:17 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKk9R-0005Vj-6D@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit cfd61e688f9f1736ff0311f49040669f04ac1ea6
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:12:09 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:12:09 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 8e44e88bc4..ce8a9c6eee 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1170,7 +1170,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1184,7 +1184,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index e3c4be2b48..5eabf8d119 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -585,12 +585,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 3b1fe423df..d2ee83bbbf 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1057,7 +1057,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1065,11 +1065,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1204,7 +1233,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1217,9 +1247,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 01f142289e..d2ef00588f 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1144,7 +1144,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index 44c549dd6b..a1949191c6 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index bc9aa68650..fa93a3684a 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -179,7 +179,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index f70d990dbb..819f6ede2b 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -356,6 +356,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -628,7 +630,7 @@ int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 void domain_pause_for_debugger(void);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:24:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:24:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk9e-0004js-3Z; Tue, 22 Sep 2020 15:24:30 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk9d-0004ji-Bj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:29 +0000
X-Inumbo-ID: c16e75e9-7a41-4063-83f2-50e3cdf28368
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c16e75e9-7a41-4063-83f2-50e3cdf28368;
 Tue, 22 Sep 2020 15:24:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=FL86xsy3sHVJaSGhJOEHj33CETvL0VSx/CxCtQyDceo=; b=ravLAXKxpL1/75+V9uZME+Y//1
 YjlNPq/VAB4HRP+XvTsoEZTgvNEQ7GwkiOQoecx/6deCWRezz5yfACpsUquiqC+ymraweSoiywy17
 G1ANpMvdKyoXIY29N57kJVNrJMImChIFmGPXbInTbxEo3Eswgw/4iglqRDnMABlyFYB0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9c-00010Z-D0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:28 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9c-0005Yn-BU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:28 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] x86/pv: Handle the Intel-specific MSR_MISC_ENABLE
 correctly
Message-Id: <E1kKk9c-0005Yn-BU@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7129b9e7264b2e992845ba84a5d871a4ef6bab8b
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:15:39 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:15:39 2020 +0200

    x86/pv: Handle the Intel-specific MSR_MISC_ENABLE correctly
    
    This MSR doesn't exist on AMD hardware, and switching away from the safe
    functions in the common MSR path was an erroneous change.
    
    Partially revert the change.
    
    This is XSA-333.
    
    Fixes: 4fdc932b3cc ("x86/Intel: drop another 32-bit leftover")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Wei Liu <wl@xen.org>
---
 xen/arch/x86/pv/emul-priv-op.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index c23822c675..8120ded330 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -924,7 +924,8 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, *val);
+        if ( rdmsr_safe(reg, *val) )
+            break;
         *val = guest_misc_enable(*val);
         return X86EMUL_OKAY;
 
@@ -1079,7 +1080,8 @@ static int write_msr(unsigned int reg, uint64_t val,
         break;
 
     case MSR_IA32_MISC_ENABLE:
-        rdmsrl(reg, temp);
+        if ( rdmsr_safe(reg, temp) )
+            break;
         if ( val != guest_misc_enable(temp) )
             goto invalid;
         return X86EMUL_OKAY;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:24:41 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:24:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk9p-0004kx-59; Tue, 22 Sep 2020 15:24:41 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk9n-0004km-Mj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:39 +0000
X-Inumbo-ID: 7e2dd3dc-81c6-4a3a-af3b-26dd6efb8994
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7e2dd3dc-81c6-4a3a-af3b-26dd6efb8994;
 Tue, 22 Sep 2020 15:24:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=lADPSSJwuhJJT63C+COQ2NUgbxbk3wYiOkq4dCuxkjk=; b=RVIwZzN4EFavhNXQSY3CfVXZXm
 G6ao5frfbWfKogolTLUbfOLjAq4K5ZZpUaxaSLg1n1s9UoJlSK6KnVmlIZBuyAMMP/i2PM6eBoG/B
 W8H7+UX2sCNcmN0EyPqaP7SDJMb1kA8YKvAnfsIi8bd2VLcplDWlXgkqiZ6MIPbgsG+8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9m-00011L-GQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:38 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9m-0005b2-Fc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:38 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] x86/vpt: fix race when migrating timers between
 vCPUs
Message-Id: <E1kKk9m-0005b2-Fc@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7bf49839ec9bbde6206bbe9ceda958948c06dcfa
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:16:12 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:16:12 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 77 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index aa7d7476ed..07a412a829 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -627,6 +627,8 @@ int hvm_domain_initialise(struct domain *d)
     /* need link to containing domain */
     d->arch.hvm_domain.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm_domain.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index d5363caec7..721015ca7a 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -152,23 +152,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm_vcpu.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    read_unlock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm_vcpu.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -218,7 +227,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -226,7 +235,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -234,7 +243,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm_vcpu.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -247,7 +256,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -272,7 +281,7 @@ int pt_update_irq(struct vcpu *v)
     uint64_t max_lag;
     int irq, pt_vector = -1;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -300,14 +309,14 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
     earliest_pt->irq_issued = 1;
     irq = earliest_pt->irq;
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -377,12 +386,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -421,7 +430,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -432,12 +441,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm_vcpu.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -455,7 +464,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    write_lock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -504,7 +513,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    write_unlock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -529,30 +538,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm_vcpu.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 0eb5ff632e..ed8de96191 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -133,6 +133,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:24:51 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:24:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKk9z-0004mU-Hj; Tue, 22 Sep 2020 15:24:51 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKk9x-0004mA-HY
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:49 +0000
X-Inumbo-ID: 36cb0a04-cf08-4587-88f5-c8b55ca2754b
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 36cb0a04-cf08-4587-88f5-c8b55ca2754b;
 Tue, 22 Sep 2020 15:24:48 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=h65Y2WWMR1/TtsSUZwvoX9bMazQfXI8Cyfpo8ORApA0=; b=hTIwpkZsP/snsEASO6zNdvurZg
 zoAL588WtEMiMuSHUQcOPzYROsMmnsEgz8b8a6CW4wlZQSrCTH9RfziFRmFSJeErGbFQV7+f4c7V3
 Tl8Rzwdz8taGlwQXLYjpbxGzM/PqE3/06HDsf7SYaGyLO3nOPwdaU0Zno/MWacJxP+R8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9w-000132-Je
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:48 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKk9w-0005bv-Ir
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:48 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKk9w-0005bv-Ir@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:48 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2031bd3f421d4923679121092a414adfcea16a95
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:16:58 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:16:58 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 58 +-----------------------------------------------------
 1 file changed, 1 insertion(+), 57 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 2bec43e416..925ec710f4 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -192,59 +192,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        u16 data, seg = dev->seg;
-        u8 bus = dev->bus;
-        u8 slot = PCI_SLOT(dev->devfn);
-        u8 func = PCI_FUNC(dev->devfn);
-
-        msg->address_lo = pci_conf_read32(seg, bus, slot, func,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(seg, bus, slot, func,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -322,10 +269,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkA9-0004oE-JO; Tue, 22 Sep 2020 15:25:01 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkA7-0004nu-Qb
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:59 +0000
X-Inumbo-ID: 2d3cd680-6d43-443b-82af-78beadc91db4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2d3cd680-6d43-443b-82af-78beadc91db4;
 Tue, 22 Sep 2020 15:24:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=MSb1R4kcRBQFgWCVAC1AlhpsttVFX68x08sZJy6XVBM=; b=f1lj8IHN7KGKtCx0XNB1QlRKqG
 gtgUKO4yVQB1OdYHwqS932Lz1Uqq3yoaMFBO9VH0XVtye6X/bs4DwELopuxGkKkQ4FbjBDErzJddB
 JV70Qt89+z+7GZh3w9SWUvYDhNWEh+6tGthu8nzktNC8Zp6OUXJV2ommiWKYuW2kYcvk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkA6-00013D-Mc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:58 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkA6-0005ck-Ly
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:24:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] x86/MSI-X: restrict reading of table/PBA bases
 from BARs
Message-Id: <E1kKkA6-0005ck-Ly@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:24:58 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 2fe163d70f3ae88c10f50d70a50513e395326a77
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:17:47 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:17:47 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 61 insertions(+), 36 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 925ec710f4..5e5cf83c10 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -785,16 +785,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
 
     ASSERT(pcidevs_locked());
 
@@ -832,43 +830,45 @@ static int msix_capability_init(struct pci_dev *dev,
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(seg, bus, slot, func,
                                    msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
-    {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->nr_entries = nr_entries;
         msix->table.first = PFN_DOWN(table_paddr);
@@ -889,7 +889,19 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
     }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                         control);
+        xfree(entry);
+        return -ENODATA;
+    }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      (table_offset & ~PCI_MSIX_BIRMASK & ~PAGE_MASK);
 
     if ( entry )
     {
@@ -900,8 +912,16 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
             pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+                             control);
             xfree(entry);
             return idx;
         }
@@ -1083,9 +1103,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkAJ-0004pf-L2; Tue, 22 Sep 2020 15:25:11 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkAH-0004pS-NN
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:09 +0000
X-Inumbo-ID: 42f8e069-265b-48a6-b0f8-9a31c5106727
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 42f8e069-265b-48a6-b0f8-9a31c5106727;
 Tue, 22 Sep 2020 15:25:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=1XgTTiJLr0G9YvIxo7XO85d4m5ZCw8RGXMr0VAXwCSM=; b=FCyx6dVVvBnbb6XSxN6uLf888G
 MWfXiPALmuvCYk2TsNtcd2eNof1uDVsAVncDEI0iXX54lglEJljJWFoxsAEzOvMRTxZj3vQANpXcD
 WmWqjVzhAQDNxiq90GbNuFX50sWDtQkA4/EzykOArkbKmIZHUrZ+mpUC0WXVfxxnmVBs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAG-00013a-Pe
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAG-0005dg-Oq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: relax port_is_valid()
Message-Id: <E1kKkAG-0005dg-Oq@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7284bfab0506f3281343689d08ff4731fcbebaa6
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:18:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:18:21 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index b8152a9831..2006ba9252 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -99,8 +99,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:21 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:21 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkAT-0004ro-MT; Tue, 22 Sep 2020 15:25:21 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkAR-0004rS-P3
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:19 +0000
X-Inumbo-ID: a96f7c0e-8b3d-41ed-8944-c1159014805f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a96f7c0e-8b3d-41ed-8944-c1159014805f;
 Tue, 22 Sep 2020 15:25:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=+6XeDyxglnqrXQvPAn3zSIaMdDMXzYU98ZKQ3kFKkuc=; b=wcw5C3c1z/XJoC/IB0nJ+2zWXl
 /I/B5gEQXXTiXZjTYbM7YDYz5Ap1rgHa/3zQ6dJH7tn3KSq2xvmv0+91yqUAYwRjU9dXRG6VVSb18
 +f5sYeJwuDJo11Wf3NnbZeMkYA7Acxfso+kifjrdgX5PAqkDBQFnUZxMpPIDFUY5RV28=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAQ-00013k-Se
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:18 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAQ-0005eu-Rt
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:18 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] x86/pv: Avoid double exception injection
Message-Id: <E1kKkAQ-0005eu-Rt@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 9703a2fd74d91e29f6f913115a98c78426854305
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:18:57 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:18:57 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index f697e05a30..123c974e33 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -80,7 +80,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -349,7 +348,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 58054edf82..ace7e65eb7 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -81,7 +81,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -513,6 +512,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:30 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkAc-0004tM-OA; Tue, 22 Sep 2020 15:25:30 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkAb-0004tA-R1
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:29 +0000
X-Inumbo-ID: b8c9317a-fe57-416b-9780-aab5014150d6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b8c9317a-fe57-416b-9780-aab5014150d6;
 Tue, 22 Sep 2020 15:25:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=goJUi0bhSWiFOm2BQg4qW6rjKkxSM3uhZiVYxgfoPYU=; b=uGirI63a/S7I9Vrtp8iQy18GdL
 6/SCTcJmYjubQaSgGITioR6N4u3x1oP1GYJhCFmFey2lzr4tSKE3GmuRp2NhLuWhXs+gbTv8xPM7P
 uVb1xOtKmkKafOpuWm+fgR2cF2e/DEgao/Q6vuPMLpRMQUjhxC2HD0e36tWqQv6lhQ+4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAa-000140-W5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:28 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAa-0005gE-V5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:28 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKkAa-0005gE-V5@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 13f60bf98fcb3b5c5c216ee2ce536897d3a925d4
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 17:19:30 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:19:30 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index c692bd2175..399dc07211 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -178,6 +178,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 2006ba9252..70bd63423e 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -99,7 +99,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:40 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkAm-0004vH-RV; Tue, 22 Sep 2020 15:25:40 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkAm-0004v4-5M
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:40 +0000
X-Inumbo-ID: 51375eed-f8f2-4229-9a64-4136bd819aa4
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 51375eed-f8f2-4229-9a64-4136bd819aa4;
 Tue, 22 Sep 2020 15:25:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=muJDBPSIoX1mZC79q1KaikmEKSrT6R+f0ChjFWDgdLY=; b=vU0YLzNlCek+sALRENX43Dlaw1
 tPGgY4j95zQeAg93ETyC/UMiHEoiVzUDNpKcerzf0LgL9J4pWuAwPSKZqmjCRb6WVm9DMgf0zYoR7
 r1yXwRWQKTHaCALFpAZqHftDvDewxMmUBY+v0rzKB3W4XQWxJttI0mLDP3/BA/JbkTDY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAl-00014Z-4G
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:39 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAl-0005h8-2Q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:39 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKkAl-0005h8-2Q@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:39 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6e9de083d801104f50a78f5d8e872778a776c682
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:20:23 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:20:23 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/schedule.c      | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 399dc07211..efbba61558 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -151,7 +151,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1393,13 +1393,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 3f4c835518..397be25015 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -477,7 +477,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -487,7 +487,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -539,6 +539,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -555,8 +557,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index dd167cce76..adc6f3a238 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1054,7 +1054,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 70bd63423e..357347369e 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -97,6 +97,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index e79d5a36ca..56fe0e774d 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -343,7 +343,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:25:50 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:25:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkAw-0004yL-TJ; Tue, 22 Sep 2020 15:25:50 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkAw-0004yC-FB
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:50 +0000
X-Inumbo-ID: d0292376-e549-4fc2-96b5-9692959a63c8
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d0292376-e549-4fc2-96b5-9692959a63c8;
 Tue, 22 Sep 2020 15:25:49 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wAZUCpZH1YSBF+TiLLmQEQvh7xkVHy8tMMnOuXqySmw=; b=rh85C9nOSRcv6153uVtTM5yGh6
 cwewox9QmPuk3sdUjCuBQvaHJRMiPnnwpJWc1GS0ZJ6qr8azbHm73RyOVvBfUse+8qs1lwni67LYe
 x02pGq1im58wrCIJ++l9bpIpms7Un9AvKBNsDcmOAYIYG7IoKYD4Zq3wFUQtEO1D9vUM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAv-00014j-7c
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:49 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkAv-0005i0-6q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:49 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKkAv-0005i0-6q@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:49 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit cc1561a3a4e6c1b4125953703338c545ba6d14fb
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:20:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:20:56 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index efbba61558..258281ea88 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -188,6 +188,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -211,11 +213,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -258,6 +275,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -351,6 +369,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -484,7 +503,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -532,6 +551,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1005,10 +1025,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1018,7 +1038,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1027,7 +1049,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1213,10 +1235,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1232,7 +1253,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1308,6 +1332,7 @@ int evtchn_init(struct domain *d)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long,
@@ -1335,6 +1360,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 56fe0e774d..a8ebfe6d95 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -345,6 +345,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:26:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:26:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkB7-0004zs-Uu; Tue, 22 Sep 2020 15:26:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkB6-0004zY-ND
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:00 +0000
X-Inumbo-ID: 7ebc85ad-0314-4b7f-beb9-b54375aa6041
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 7ebc85ad-0314-4b7f-beb9-b54375aa6041;
 Tue, 22 Sep 2020 15:25:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=RKm9fTnwh8Hk9vuvxN0EWwuf+UuT3PSWWWr0UCSRmZI=; b=xptbjCguPjf9Ky457JyiZFBXxq
 acVKq5OsGWoEr3nj90f29JwguIkcrXCZKzjTvQOcBooFVsjLTAOBn6Vok2RihsseJgA5CQK2gCsqB
 W+Oy5C06Aabol6bJSXszlNPdkYpj+1mj3T5KohNbKYxGof6n0FYiAubVjK70A+QFwp1M=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkB5-00014v-Ae
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:59 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkB5-0005ir-9q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:25:59 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKkB5-0005ir-9q@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:25:59 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3def8466383ab5abd17f1436d085348c2994722b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:21:27 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:21:27 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 258281ea88..982af9d172 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -248,6 +248,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -263,14 +264,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -283,26 +284,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -312,6 +319,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -347,7 +355,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -364,7 +372,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -387,6 +395,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -419,14 +428,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -443,6 +452,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( (vcpu < 0) || (vcpu >= d->max_vcpus) ||
          (d->vcpu[vcpu] == NULL) )
@@ -455,13 +465,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -505,6 +515,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -537,14 +548,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -565,6 +576,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -664,14 +676,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -679,9 +691,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -701,13 +713,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -742,7 +755,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1232,6 +1245,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1244,14 +1258,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1274,11 +1288,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1288,7 +1303,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:26:12 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:26:12 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkBI-00051A-0L; Tue, 22 Sep 2020 15:26:12 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkBG-00050y-Vq
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:11 +0000
X-Inumbo-ID: 888c48d8-b013-4f95-8594-fc2c94b82840
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 888c48d8-b013-4f95-8594-fc2c94b82840;
 Tue, 22 Sep 2020 15:26:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ljxdYs+6+HJGIQ2V0okPxGEtE63zodC8hfcZ++e2Wjs=; b=aL58TGGKE0k8SnrVgyhrNBppGk
 rzKWMnq/WCqhy+/brqLVl/aYNKjF+y5YzmKmw3QfKzGz0hBjrc1JiG7jKAqnIhZu6sqDOBD+MSUuj
 0CmDwVALrEFXunmTX0TIFYLXpjWsdwYUaggxhzTgQVR9xNrsOW+pqHd8U2lGS7hkhltA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBF-00015P-Fj
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:09 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBF-0005km-De
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:09 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: address races with evtchn_reset()
Message-Id: <E1kKkBF-0005km-De@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:26:09 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 30b3f297603eebd7874ca3b5f9cbf7268b040046
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:22:00 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:22:00 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index 3bb2f5132b..9878486073 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2324,14 +2324,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; i++ )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("%u:%3d(%c%c%c)",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       (info->masked ? 'M' : '-'));
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-');
                 if ( i != action->nr_guests )
                     printk(",");
             }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index 353538447e..4b7d498c00 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -616,8 +616,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 982af9d172..753950b81a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -156,8 +156,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -770,6 +771,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -780,7 +782,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -809,7 +814,9 @@ static void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -819,6 +826,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -833,7 +841,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1028,12 +1038,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1446,8 +1459,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 397be25015..45c024739d 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -295,23 +295,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index 2f6ea54bcb..f61d2f7adb 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline bool arch_virq_is_global(unsigned int virq)
     return true;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 357347369e..26ad429520 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -125,6 +125,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -157,19 +175,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -185,38 +208,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -225,6 +277,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:26:22 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:26:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkBS-000536-3P; Tue, 22 Sep 2020 15:26:22 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkBQ-00052x-OU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:20 +0000
X-Inumbo-ID: 1a29026c-ef1e-48c6-82ae-098f3e5edce0
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1a29026c-ef1e-48c6-82ae-098f3e5edce0;
 Tue, 22 Sep 2020 15:26:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GVyaWyoIzuEDzddMXa2eY3S6yN5K0kx4VNkIY51N9Ao=; b=B76od1PeWjNl69+ieaNjdEvRgG
 AJRj2eVliJLh5UMxvEnIRQVCt6ZVTMKFO+2XiRSrCQoIufZ2FXKQFzxyBvsVkA2zFVknUubgCZi+g
 MpYM2/5j9/KKBwuGS17yrDq3XtHDAAsOiO8EGNxRWWKN7CLnEj1jOk7Lr2uQzav9TkMw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBP-00015e-Io
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBP-0005lm-ID
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKkBP-0005lm-ID@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:26:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3e565a9c603daebcf50e067c07aed7f0c4b2a6e0
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:22:28 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:22:28 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 2ddd7986c1..cacede4cf0 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -646,7 +646,6 @@ int domain_kill(struct domain *d)
         if ( d->is_dying != DOMDYING_alive )
             return domain_kill(d);
         d->is_dying = DOMDYING_dying;
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         tmem_destroy(d->tmem_client);
         vnuma_destroy(d->vnuma);
@@ -654,6 +653,9 @@ int domain_kill(struct domain *d)
         d->tmem_client = NULL;
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 753950b81a..52ba2b0c0c 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1291,7 +1291,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1303,7 +1312,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1375,8 +1394,7 @@ int evtchn_init(struct domain *d)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1385,14 +1403,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index a8ebfe6d95..46958de3d1 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -135,7 +135,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d); /* from domain_create */
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:26:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:26:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkBc-00054M-4x; Tue, 22 Sep 2020 15:26:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkBa-00054A-PP
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:30 +0000
X-Inumbo-ID: e02adc7e-874c-4171-9ad6-ee8643a8d037
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id e02adc7e-874c-4171-9ad6-ee8643a8d037;
 Tue, 22 Sep 2020 15:26:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=0IzVbPTE0GLVqD401ktezftmEl5XUgQrEorRZ6tGI5c=; b=T4jMyul76FMBlQdAIYjH97/Jic
 k2MbZ/OdJAhXLuB8U8MVUXu2Dq4oY0309kzOUwwJg+0GMWJ8erxnu6xob+Pvp6S8xDSFNOLE+2LuD
 14L773OVu9PReRCu+IV+/snrajaVpoEVy8bu/mczQgbsF43xnsG9dxk6D3er7oS2Wum8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBZ-00015q-M0
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:29 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkBZ-0005md-LD
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:26:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.11] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKkBZ-0005md-LD@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:26:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3263f257caf8e4465e9dca84a88fa0e68be74280
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:23:04 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:23:04 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index cacede4cf0..0a7f193e43 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1105,7 +1105,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1119,7 +1119,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 741d774cd1..f3b7d93a06 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -648,12 +648,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 52ba2b0c0c..a1f2af07c5 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1051,7 +1051,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1059,11 +1059,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1198,7 +1227,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1211,9 +1241,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 0ab9fa0f85..dd096b5f1e 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1121,7 +1121,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index 44c549dd6b..a1949191c6 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 26ad429520..87a4aade86 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -171,7 +171,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 46958de3d1..c0cc5d9336 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -355,6 +355,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -608,7 +610,7 @@ int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 void domain_pause_for_debugger(void);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.11


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:44:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:44:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkSe-0007Ay-Ri; Tue, 22 Sep 2020 15:44:08 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkSd-0007At-8Y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:07 +0000
X-Inumbo-ID: fd38162a-7a2e-4877-825f-3d6f2c14126c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id fd38162a-7a2e-4877-825f-3d6f2c14126c;
 Tue, 22 Sep 2020 15:44:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=HbnFMEbS90wVd9I/Ib4rQYzPCKCEbWmCXuF8BAkA+y8=; b=RGNRt4ZifNAhDmHAYSDUVeLEZN
 4U9B5UxRgZ9foVKN/mCLnUNQqpRqqEoyk7M4Ao1FegNGosHqXgIxv8namT02JQuMZ2q0qgO2v+133
 dOpMRe1Yh+ZCJKfQhP2N2N5YwmvazrKAaF2GSec0TZJA65Ct6GjCMrXNCLkQeSCG3vSQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSb-0001S8-Sn
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSb-0007TL-R5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] hvmloader: indicate ACPI tables with "ACPI data"
 type in e820
Message-Id: <E1kKkSb-0007TL-R5@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 43eceee913cc76e533233568ca9390be3d080578
Author:     Igor Druzhinin <igor.druzhinin@citrix.com>
AuthorDate: Tue Sep 22 17:37:42 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:37:42 2020 +0200

    hvmloader: indicate ACPI tables with "ACPI data" type in e820
    
    Guest kernel does need to know in some cases where the tables are located
    to treat these regions properly. One example is kexec process where
    the first kernel needs to pass ACPI region locations to the second
    kernel which is now a requirement in Linux after 02a3e3cdb7f12 ("x86/boot:
    Parse SRAT table and count immovable memory regions") in order for kexec
    transition to actually work.
    
    That commit introduced accesses to XSDT and SRAT while the second kernel
    is still using kexec transition tables. The transition tables do not have
    e820 "reserved" regions mapped where those tables are located currently
    in a Xen guest. Instead "ACPI data" regions are mapped with the transition
    tables that was introduced by the following commit 6bbeb276b7 ("x86/kexec:
    Add the EFI system tables and ACPI tables to the ident map").
    
    Reserve 1MB (out of 16MB currently available) right after ACPI info page for
    ACPI tables exclusively but populate this region on demand and only indicate
    populated memory as "ACPI data" since according to ACPI spec that memory is
    reclaimable by the guest if necessary. That is close to how we treat
    the same ACPI data in PVH guests. 1MB should be enough for now but could be
    later extended if required.
    
    Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: 8efa46516c5f4cf185c8df179812c185d3c27eb6
    master date: 2020-09-09 17:56:13 +0200
---
 tools/firmware/hvmloader/config.h    |  6 +++++-
 tools/firmware/hvmloader/e820.c      | 26 ++++++++++++++++++++++----
 tools/firmware/hvmloader/hvmloader.c |  3 ++-
 tools/firmware/hvmloader/pci.c       |  1 -
 tools/firmware/hvmloader/util.c      | 29 ++++++++++++++++++++++++++++-
 tools/firmware/hvmloader/util.h      |  2 ++
 6 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index d9b4713d63..844120bc87 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -2,6 +2,7 @@
 #define __HVMLOADER_CONFIG_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 
 enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
@@ -62,6 +63,8 @@ extern uint8_t ioapic_version;
 extern unsigned long pci_mem_start, pci_mem_end;
 extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 
+extern bool acpi_enabled;
+
 /* Memory map. */
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
@@ -71,7 +74,8 @@ extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 #define RESERVED_MEMBASE              0xFC000000
 /* NB. ACPI_INFO_PHYSICAL_ADDRESS *MUST* match definition in acpi/dsdt.asl! */
 #define ACPI_INFO_PHYSICAL_ADDRESS    0xFC000000
-#define RESERVED_MEMORY_DYNAMIC_START 0xFC001000
+#define ACPI_MEMORY_DYNAMIC_START     0xFC001000
+#define RESERVED_MEMORY_DYNAMIC_START 0xFC100000
 #define RESERVED_MEMORY_DYNAMIC_END   0xFE000000
 /*
  * GUEST_RESERVED: Physical address space reserved for guest use.
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 4d1c955a02..38bcf18b63 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -155,6 +155,9 @@ int build_e820_table(struct e820entry *e820,
 {
     unsigned int nr = 0, i, j;
     uint32_t low_mem_end = hvm_info->low_mem_pgend << PAGE_SHIFT;
+    unsigned long acpi_mem_end = acpi_enabled ?
+        ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated() << PAGE_SHIFT) :
+        RESERVED_MEMBASE;
 
     if ( !lowmem_reserved_base )
             lowmem_reserved_base = 0xA0000;
@@ -198,9 +201,24 @@ int build_e820_table(struct e820entry *e820,
     e820[nr].type = E820_RESERVED;
     nr++;
 
+    /*
+     * Mark populated reserved memory that contains ACPI tables as ACPI data.
+     * That should help the guest to treat it correctly later: e.g. pass to
+     * the next kernel on kexec or reclaim if necessary.
+     */
+
+    if ( acpi_enabled )
+    {
+        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].size = acpi_mem_end - RESERVED_MEMBASE;
+        e820[nr].type = E820_ACPI;
+        nr++;
+    }
+
     /*
      * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * This space starts right after ACPI region (to avoid creating a hole that
+     * might be accidentally occupied by MMIO) and extends to cover various
      * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
      *
      * If igd_opregion_pgbase we need to split the RESERVED region in two.
@@ -210,8 +228,8 @@ int build_e820_table(struct e820entry *e820,
     {
         uint32_t igd_opregion_base = igd_opregion_pgbase << PAGE_SHIFT;
 
-        e820[nr].addr = RESERVED_MEMBASE;
-        e820[nr].size = (uint32_t) igd_opregion_base - RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
+        e820[nr].size = igd_opregion_base - acpi_mem_end;
         e820[nr].type = E820_RESERVED;
         nr++;
 
@@ -227,7 +245,7 @@ int build_e820_table(struct e820entry *e820,
     }
     else
     {
-        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
         e820[nr].size = (uint32_t)-e820[nr].addr;
         e820[nr].type = E820_RESERVED;
         nr++;
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 598a226278..c58841e5b5 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -116,6 +116,8 @@ unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
 uint32_t ioapic_base_address = 0xfec00000;
 uint8_t ioapic_version;
 
+bool acpi_enabled;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -321,7 +323,6 @@ const struct hvm_modlist_entry *get_module_entry(
 int main(void)
 {
     const struct bios_config *bios;
-    int acpi_enabled;
     const struct hvm_modlist_entry *bios_module;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index dcd097a866..72f92d4450 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -28,7 +28,6 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
-#include <stdbool.h>
 
 unsigned long pci_mem_start = HVM_BELOW_4G_MMIO_START;
 unsigned long pci_mem_end = PCI_MEM_END;
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 0c3f2d24cd..7da144b0bb 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -871,10 +871,37 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static unsigned long acpi_alloc_up = ACPI_MEMORY_DYNAMIC_START - 1;
+
+unsigned long acpi_pages_allocated(void)
+{
+    return (acpi_alloc_up >> PAGE_SHIFT) -
+            ((ACPI_MEMORY_DYNAMIC_START - 1) >> PAGE_SHIFT);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
-    return mem_alloc(size, align);
+    unsigned long s, e;
+
+    /* Align to at least 16 bytes. */
+    if ( align < 16 )
+        align = 16;
+
+    s = (acpi_alloc_up + align) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON((e < s) || (e >= RESERVED_MEMORY_DYNAMIC_START));
+
+    while ( (acpi_alloc_up >> PAGE_SHIFT) != (e >> PAGE_SHIFT) )
+    {
+        acpi_alloc_up += PAGE_SIZE;
+        mem_hole_populate_ram(acpi_alloc_up >> PAGE_SHIFT, 1);
+    }
+
+    acpi_alloc_up = e;
+
+    return (void *)s;
 }
 
 static void acpi_mem_free(struct acpi_ctxt *ctxt,
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 7bca6418d2..31889de634 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -282,6 +282,8 @@ bool check_overlap(uint64_t start, uint64_t size,
 extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
 extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
 
+unsigned long acpi_pages_allocated(void);
+
 struct acpi_config;
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:44:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:44:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkSn-0007C9-TD; Tue, 22 Sep 2020 15:44:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkSm-0007BP-W6
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:17 +0000
X-Inumbo-ID: f8482ed5-30df-4be5-a4eb-31d4398c7568
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id f8482ed5-30df-4be5-a4eb-31d4398c7568;
 Tue, 22 Sep 2020 15:44:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tJjlw0eM4t5aVPKKKS0Z1AaHwZwXsi7nVC7jjGPkxck=; b=z7BgzkLDwLY6+b+KpzeSHANJtI
 2QzMotnWxRTX0zGzxyjTIpCFy1JxS7TYzMTsvBwPphwEFIFO5E5i69H9KFc97vs2sqNdpydh6xPzr
 a2jBVTpbAt4dq3pB/Fw73GODZqbwjMVIyzPsNKowxUOJz1s/O0vh6Q49S315Bhn2vBeU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSm-0001SE-2C
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSl-0007UJ-V8
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] xen/hypfs: fix writing of custom parameter
Message-Id: <E1kKkSl-0007UJ-V8@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 54789343ce51ef1595010b13e092863a50cb38ee
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Tue Sep 22 17:38:06 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:38:06 2020 +0200

    xen/hypfs: fix writing of custom parameter
    
    Today the maximum allowed data length for writing a hypfs node is
    tested in the generic hypfs_write() function. For custom runtime
    parameters this might be wrong, as the maximum allowed size is derived
    from the buffer holding the current setting, while there might be ways
    to set the parameter needing more characters than the minimal
    representation of that value.
    
    One example for this is the "ept" parameter. Its value buffer is sized
    to be able to hold the string "exec-sp=0" or "exec-sp=1", while it is
    allowed to use e.g. "no-exec-sp" or "exec-sp=yes" for setting it.
    
    Fix that by moving the length check one level down to the type
    specific write function.
    
    In order to avoid allocation of arbitrary sized buffers use a new
    MAX_PARAM_SIZE macro as an upper limit for custom writes. The value
    of MAX_PARAM_SIZE is the same as the limit in parse_params() for a
    single parameter.
    
    Fixes: a659d7cab9af ("xen: add runtime parameter access support to hypfs")
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    master commit: b4e41b1750d550bf2b1ccf97ee46f4f682bdbb62
    master date: 2020-09-11 14:20:10 +0200
---
 xen/common/hypfs.c      | 11 +++++++----
 xen/common/kernel.c     |  2 +-
 xen/include/xen/param.h |  3 +++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c
index b74c228191..8e932b5cf9 100644
--- a/xen/common/hypfs.c
+++ b/xen/common/hypfs.c
@@ -297,7 +297,9 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
     int ret;
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
-    ASSERT(ulen <= leaf->e.max_size);
+
+    if ( ulen > leaf->e.max_size )
+        return -ENOSPC;
 
     if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
          leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
@@ -356,6 +358,10 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
 
     ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
 
+    /* Avoid oversized buffer allocation. */
+    if ( ulen > MAX_PARAM_SIZE )
+        return -ENOSPC;
+
     buf = xzalloc_array(char, ulen);
     if ( !buf )
         return -ENOMEM;
@@ -386,9 +392,6 @@ static int hypfs_write(struct hypfs_entry *entry,
 
     ASSERT(entry->max_size);
 
-    if ( ulen > entry->max_size )
-        return -ENOSPC;
-
     l = container_of(entry, struct hypfs_entry_leaf, e);
 
     return entry->write(l, uaddr, ulen);
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 9de07b7ac5..c3a943f077 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -57,7 +57,7 @@ static int assign_integer_param(const struct kernel_param *param, uint64_t val)
 static int parse_params(const char *cmdline, const struct kernel_param *start,
                         const struct kernel_param *end)
 {
-    char opt[128], *optval, *optkey, *q;
+    char opt[MAX_PARAM_SIZE], *optval, *optkey, *q;
     const char *p = cmdline, *key;
     const struct kernel_param *param;
     int rc, final_rc = 0;
diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h
index c2fd075dd0..67ce6edf88 100644
--- a/xen/include/xen/param.h
+++ b/xen/include/xen/param.h
@@ -26,6 +26,9 @@ struct kernel_param {
     } par;
 };
 
+/* Maximum length of a single parameter string. */
+#define MAX_PARAM_SIZE 128
+
 extern const struct kernel_param __setup_start[], __setup_end[];
 
 #define __param(att)      static const att \
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:44:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:44:29 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkSy-0007Di-W9; Tue, 22 Sep 2020 15:44:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkSy-0007DY-08
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:28 +0000
X-Inumbo-ID: a9691cda-1573-4923-a737-caf3f0f7e09f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a9691cda-1573-4923-a737-caf3f0f7e09f;
 Tue, 22 Sep 2020 15:44:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=TOUuOEAJPSttRZA6hNwiM9SNAZgVukOmlcorSP+uy9Y=; b=Z3jzrw+DCMqICPtIZsNNOW7+sv
 qYIn4tpWk6rFhjIH+KieoffGvMnDqTg+u/AVxj5qHNZy3fTcCTTYyHKlK7uypJCZW0fTLvog+Dmr0
 otZmIyhwt0tHaI/5W0UKRS9z2Bf/lAbvYc6PwFxrKZEkJZ3lenMoBrDUQ1JZ86D4Fh08=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSw-0001SO-6e
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkSw-0007VB-4u
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.14] x86/HVM: more consistently set I/O completion
Message-Id: <E1kKkSw-0007VB-4u@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f37a1cf023b277d0d49323bf322ce3ff0c92262d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:39:05 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:39:05 2020 +0200

    x86/HVM: more consistently set I/O completion
    
    Doing this just in hvm_emulate_one_insn() is not enough.
    hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
    insns requiring one or more continuations, and at least in principle
    hvm_emulate_one_mmio() could, too. Without proper setting of the field,
    handle_hvm_io_completion() will do nothing completion-wise, and in
    particular the missing re-invocation of the insn emulation paths will
    lead to emulation caching not getting disabled in due course, causing
    the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
    
    Reported-by: Don Slutz <don.slutz@gmail.com>
    
    Similar considerations go for the clearing of vio->mmio_access, which
    gets moved as well.
    
    Additionally all updating of vio->mmio_* now gets done dependent upon
    the new completion value, rather than hvm_ioreq_needs_completion()'s
    return value. This is because it is the completion chosen which controls
    what path will be taken when handling the completion, not the simple
    boolean return value. In particular, PIO completion doesn't involve
    going through the insn emulator, and hence emulator state ought to get
    cleared early (or it won't get cleared at all).
    
    The new logic, besides allowing for a caller override for the
    continuation type to be set (for VMX real mode emulation), will also
    avoid setting an MMIO completion when a simpler PIO one will do. This
    is a minor optimization only as a side effect - the behavior is strictly
    needed at least for hvm_ud_intercept(), as only memory accesses can
    successfully complete through handle_mmio(). Care of course needs to be
    taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
    the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
    whether the insn being emulated is a memory access, as this information
    is no longer easily available at the point where we want to consume it.
    
    Note that the presence of non-NULL .validate fields in the two ops
    structures in hvm_emulate_one_mmio() was really necessary even before
    the changes here: Without this, passing non-NULL as middle argument to
    hvm_emulate_init_once() is meaningless.
    
    The restrictions on when the #UD intercept gets actually enabled are why
    it was decided that this is not a security issue:
    - the "hvm_fep" option to enable its use is a debugging option only,
    - for the cross-vendor case is considered experimental, even if
      unfortunately SUPPORT.md doesn't have an explicit statement about
      this.
    The other two affected functions are
    - hvm_emulate_one_vm_event(), used for introspection,
    - hvm_emulate_one_mmio(), used for Dom0 only,
    which aren't qualifying this as needing an XSA either.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Don Slutz <don.slutz@gmail.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    master commit: b807cfe954b8d0d8852398b4c8a586d95d69a342
    master date: 2020-09-15 10:19:33 +0200
---
 xen/arch/x86/hvm/emulate.c        | 51 ++++++++++++++++++++++++++++++---------
 xen/arch/x86/hvm/hvm.c            |  2 +-
 xen/arch/x86/hvm/io.c             | 11 +--------
 xen/arch/x86/hvm/vmx/realmode.c   |  6 +----
 xen/include/asm-x86/hvm/emulate.h |  5 +++-
 5 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 8b4e73ab06..24cf85fb4f 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1683,9 +1683,11 @@ static int hvmemul_validate(
     const struct x86_emulate_state *state,
     struct x86_emulate_ctxt *ctxt)
 {
-    const struct hvm_emulate_ctxt *hvmemul_ctxt =
+    struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
 
+    hvmemul_ctxt->is_mem_access = x86_insn_is_mem_access(state, ctxt);
+
     return !hvmemul_ctxt->validate || hvmemul_ctxt->validate(state, ctxt)
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
 }
@@ -2610,8 +2612,14 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
     .vmfunc        = hvmemul_vmfunc,
 };
 
+/*
+ * Note that passing HVMIO_no_completion into this function serves as kind
+ * of (but not fully) an "auto select completion" indicator.  When there's
+ * no completion needed, the passed in value will be ignored in any case.
+ */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
-    const struct x86_emulate_ops *ops)
+    const struct x86_emulate_ops *ops,
+    enum hvm_io_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
@@ -2642,16 +2650,31 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
         rc = X86EMUL_RETRY;
 
     if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+        completion = HVMIO_no_completion;
+    else if ( completion == HVMIO_no_completion )
+        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
+                                                   : HVMIO_pio_completion;
+
+    switch ( vio->io_completion = completion )
     {
+    case HVMIO_no_completion:
+    case HVMIO_pio_completion:
         vio->mmio_cache_count = 0;
         vio->mmio_insn_bytes = 0;
+        vio->mmio_access = (struct npfec){};
         hvmemul_cache_disable(curr);
-    }
-    else
-    {
+        break;
+
+    case HVMIO_mmio_completion:
+    case HVMIO_realmode_completion:
         BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
         vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
         memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
     }
 
     if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2692,9 +2715,10 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 }
 
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt)
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion)
 {
-    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops);
+    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
 
 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
@@ -2703,11 +2727,13 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmcfg_intercept_write,
+        .validate   = hvmemul_validate,
     };
     static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = {
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmio_ro_emulated_write,
+        .validate   = hvmemul_validate,
     };
     struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla };
     struct hvm_emulate_ctxt ctxt;
@@ -2727,8 +2753,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
     hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write,
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
-    rc = _hvm_emulate_one(&ctxt, ops);
-    switch ( rc )
+
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2755,7 +2781,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     switch ( kind )
     {
     case EMUL_KIND_NOWRITE:
-        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write);
+        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
+                              HVMIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
@@ -2776,7 +2803,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx);
+        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
     }
 
     switch ( rc )
@@ -2874,6 +2901,8 @@ void hvm_emulate_init_per_insn(
                                         pfec, NULL) == HVMTRANS_okay) ?
             sizeof(hvmemul_ctxt->insn_buf) : 0;
     }
+
+    hvmemul_ctxt->is_mem_access = false;
 }
 
 void hvm_emulate_writeback(
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index f965ca3155..3001e7442b 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3812,7 +3812,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt) )
+    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 724ab44a76..3e09d9b726 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -81,20 +81,11 @@ void send_invalidate_req(void)
 bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 {
     struct hvm_emulate_ctxt ctxt;
-    struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    rc = hvm_emulate_one(&ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_mmio_completion;
-    else
-        vio->mmio_access = (struct npfec){};
-
-    switch ( rc )
+    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c
index bdbd9cb921..768f01eb04 100644
--- a/xen/arch/x86/hvm/vmx/realmode.c
+++ b/xen/arch/x86/hvm/vmx/realmode.c
@@ -97,15 +97,11 @@ static void realmode_deliver_exception(
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_realmode_completion;
+    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
diff --git a/xen/include/asm-x86/hvm/emulate.h b/xen/include/asm-x86/hvm/emulate.h
index f40290945c..1620cc7b7a 100644
--- a/xen/include/asm-x86/hvm/emulate.h
+++ b/xen/include/asm-x86/hvm/emulate.h
@@ -48,6 +48,8 @@ struct hvm_emulate_ctxt {
 
     uint32_t intr_shadow;
 
+    bool is_mem_access;
+
     bool_t set_context;
 };
 
@@ -62,7 +64,8 @@ bool __nonnull(1, 2) hvm_emulate_one_insn(
     hvm_emulate_validate_t *validate,
     const char *descr);
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt);
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.14


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:44:40 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:44:40 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTA-0007Ei-1X; Tue, 22 Sep 2020 15:44:40 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkT8-0007EX-Ba
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:38 +0000
X-Inumbo-ID: 6c14fad5-fc9c-455c-b8fd-cac3c5ec1552
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6c14fad5-fc9c-455c-b8fd-cac3c5ec1552;
 Tue, 22 Sep 2020 15:44:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=MKMpTV5FFcVlZNM3eWL2n+X+O88SxNij2NQy4dlcrek=; b=U4Q7cCcieJGFAHx0CHC0HHm3pl
 1BSmrb6HfRvRX1TdfaQeBeXaneACUm6mxX3zTtjttTLMEB4gWEPa+9cFBXlJiVWhPzCwt2GW2hR1m
 hhOhl1kXCF6ZuKK6DIPY7Ad7KsDbSMIR5E93cLE1zPLt4f3vTBy/m2D+mCqbA4uXpTjs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkT7-0001TA-4D
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:37 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkT7-0007X6-2Y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:37 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] hvmloader: indicate ACPI tables with "ACPI data"
 type in e820
Message-Id: <E1kKkT7-0007X6-2Y@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f63b20a213ecaa672cf40b4627eb1eea9542cb58
Author:     Igor Druzhinin <igor.druzhinin@citrix.com>
AuthorDate: Tue Sep 22 17:40:36 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:40:36 2020 +0200

    hvmloader: indicate ACPI tables with "ACPI data" type in e820
    
    Guest kernel does need to know in some cases where the tables are located
    to treat these regions properly. One example is kexec process where
    the first kernel needs to pass ACPI region locations to the second
    kernel which is now a requirement in Linux after 02a3e3cdb7f12 ("x86/boot:
    Parse SRAT table and count immovable memory regions") in order for kexec
    transition to actually work.
    
    That commit introduced accesses to XSDT and SRAT while the second kernel
    is still using kexec transition tables. The transition tables do not have
    e820 "reserved" regions mapped where those tables are located currently
    in a Xen guest. Instead "ACPI data" regions are mapped with the transition
    tables that was introduced by the following commit 6bbeb276b7 ("x86/kexec:
    Add the EFI system tables and ACPI tables to the ident map").
    
    Reserve 1MB (out of 16MB currently available) right after ACPI info page for
    ACPI tables exclusively but populate this region on demand and only indicate
    populated memory as "ACPI data" since according to ACPI spec that memory is
    reclaimable by the guest if necessary. That is close to how we treat
    the same ACPI data in PVH guests. 1MB should be enough for now but could be
    later extended if required.
    
    Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: 8efa46516c5f4cf185c8df179812c185d3c27eb6
    master date: 2020-09-09 17:56:13 +0200
---
 tools/firmware/hvmloader/config.h    |  6 +++++-
 tools/firmware/hvmloader/e820.c      | 26 ++++++++++++++++++++++----
 tools/firmware/hvmloader/hvmloader.c |  3 ++-
 tools/firmware/hvmloader/pci.c       |  1 -
 tools/firmware/hvmloader/util.c      | 29 ++++++++++++++++++++++++++++-
 tools/firmware/hvmloader/util.h      |  2 ++
 6 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index d9b4713d63..844120bc87 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -2,6 +2,7 @@
 #define __HVMLOADER_CONFIG_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 
 enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
@@ -62,6 +63,8 @@ extern uint8_t ioapic_version;
 extern unsigned long pci_mem_start, pci_mem_end;
 extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 
+extern bool acpi_enabled;
+
 /* Memory map. */
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
@@ -71,7 +74,8 @@ extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 #define RESERVED_MEMBASE              0xFC000000
 /* NB. ACPI_INFO_PHYSICAL_ADDRESS *MUST* match definition in acpi/dsdt.asl! */
 #define ACPI_INFO_PHYSICAL_ADDRESS    0xFC000000
-#define RESERVED_MEMORY_DYNAMIC_START 0xFC001000
+#define ACPI_MEMORY_DYNAMIC_START     0xFC001000
+#define RESERVED_MEMORY_DYNAMIC_START 0xFC100000
 #define RESERVED_MEMORY_DYNAMIC_END   0xFE000000
 /*
  * GUEST_RESERVED: Physical address space reserved for guest use.
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 4d1c955a02..38bcf18b63 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -155,6 +155,9 @@ int build_e820_table(struct e820entry *e820,
 {
     unsigned int nr = 0, i, j;
     uint32_t low_mem_end = hvm_info->low_mem_pgend << PAGE_SHIFT;
+    unsigned long acpi_mem_end = acpi_enabled ?
+        ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated() << PAGE_SHIFT) :
+        RESERVED_MEMBASE;
 
     if ( !lowmem_reserved_base )
             lowmem_reserved_base = 0xA0000;
@@ -198,9 +201,24 @@ int build_e820_table(struct e820entry *e820,
     e820[nr].type = E820_RESERVED;
     nr++;
 
+    /*
+     * Mark populated reserved memory that contains ACPI tables as ACPI data.
+     * That should help the guest to treat it correctly later: e.g. pass to
+     * the next kernel on kexec or reclaim if necessary.
+     */
+
+    if ( acpi_enabled )
+    {
+        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].size = acpi_mem_end - RESERVED_MEMBASE;
+        e820[nr].type = E820_ACPI;
+        nr++;
+    }
+
     /*
      * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * This space starts right after ACPI region (to avoid creating a hole that
+     * might be accidentally occupied by MMIO) and extends to cover various
      * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
      *
      * If igd_opregion_pgbase we need to split the RESERVED region in two.
@@ -210,8 +228,8 @@ int build_e820_table(struct e820entry *e820,
     {
         uint32_t igd_opregion_base = igd_opregion_pgbase << PAGE_SHIFT;
 
-        e820[nr].addr = RESERVED_MEMBASE;
-        e820[nr].size = (uint32_t) igd_opregion_base - RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
+        e820[nr].size = igd_opregion_base - acpi_mem_end;
         e820[nr].type = E820_RESERVED;
         nr++;
 
@@ -227,7 +245,7 @@ int build_e820_table(struct e820entry *e820,
     }
     else
     {
-        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
         e820[nr].size = (uint32_t)-e820[nr].addr;
         e820[nr].type = E820_RESERVED;
         nr++;
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 598a226278..c58841e5b5 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -116,6 +116,8 @@ unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
 uint32_t ioapic_base_address = 0xfec00000;
 uint8_t ioapic_version;
 
+bool acpi_enabled;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -321,7 +323,6 @@ const struct hvm_modlist_entry *get_module_entry(
 int main(void)
 {
     const struct bios_config *bios;
-    int acpi_enabled;
     const struct hvm_modlist_entry *bios_module;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index dcd097a866..72f92d4450 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -28,7 +28,6 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
-#include <stdbool.h>
 
 unsigned long pci_mem_start = HVM_BELOW_4G_MMIO_START;
 unsigned long pci_mem_end = PCI_MEM_END;
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 0c3f2d24cd..7da144b0bb 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -871,10 +871,37 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static unsigned long acpi_alloc_up = ACPI_MEMORY_DYNAMIC_START - 1;
+
+unsigned long acpi_pages_allocated(void)
+{
+    return (acpi_alloc_up >> PAGE_SHIFT) -
+            ((ACPI_MEMORY_DYNAMIC_START - 1) >> PAGE_SHIFT);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
-    return mem_alloc(size, align);
+    unsigned long s, e;
+
+    /* Align to at least 16 bytes. */
+    if ( align < 16 )
+        align = 16;
+
+    s = (acpi_alloc_up + align) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON((e < s) || (e >= RESERVED_MEMORY_DYNAMIC_START));
+
+    while ( (acpi_alloc_up >> PAGE_SHIFT) != (e >> PAGE_SHIFT) )
+    {
+        acpi_alloc_up += PAGE_SIZE;
+        mem_hole_populate_ram(acpi_alloc_up >> PAGE_SHIFT, 1);
+    }
+
+    acpi_alloc_up = e;
+
+    return (void *)s;
 }
 
 static void acpi_mem_free(struct acpi_ctxt *ctxt,
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 7bca6418d2..31889de634 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -282,6 +282,8 @@ bool check_overlap(uint64_t start, uint64_t size,
 extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
 extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
 
+unsigned long acpi_pages_allocated(void);
+
 struct acpi_config;
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:44:50 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:44:50 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTK-0007Fg-3N; Tue, 22 Sep 2020 15:44:50 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkTI-0007FX-Kv
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:48 +0000
X-Inumbo-ID: 3bef6672-f28a-4184-9282-38a3ddc78547
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3bef6672-f28a-4184-9282-38a3ddc78547;
 Tue, 22 Sep 2020 15:44:47 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=O/AKOVUxziCQmmX+Iw4PORrfJeSD8Ksu7xUZYQWu/hA=; b=Y/bUYA0yLxr3LhODpLEm7eFR/G
 W4mOYBtLEf02SewE9bUbEVwAx1QnZ7ZEwAA4zEVt8Rmrh1rYmCN4NClgE83cSea60mohgS7mELvGO
 ziSUowp9Smt5/oFUnIw3qSc0LSdBbpYVRFBml8ujULSN5ScXapQ+n5h4Dgi7kBpSMKl8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTH-0001Ur-8H
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:47 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTH-0007YP-6r
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:47 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.13] x86/HVM: more consistently set I/O completion
Message-Id: <E1kKkTH-0007YP-6r@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 88f5b414ac0f8008c1e2b26f93c3d980120941f7
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:40:59 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:40:59 2020 +0200

    x86/HVM: more consistently set I/O completion
    
    Doing this just in hvm_emulate_one_insn() is not enough.
    hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
    insns requiring one or more continuations, and at least in principle
    hvm_emulate_one_mmio() could, too. Without proper setting of the field,
    handle_hvm_io_completion() will do nothing completion-wise, and in
    particular the missing re-invocation of the insn emulation paths will
    lead to emulation caching not getting disabled in due course, causing
    the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
    
    Reported-by: Don Slutz <don.slutz@gmail.com>
    
    Similar considerations go for the clearing of vio->mmio_access, which
    gets moved as well.
    
    Additionally all updating of vio->mmio_* now gets done dependent upon
    the new completion value, rather than hvm_ioreq_needs_completion()'s
    return value. This is because it is the completion chosen which controls
    what path will be taken when handling the completion, not the simple
    boolean return value. In particular, PIO completion doesn't involve
    going through the insn emulator, and hence emulator state ought to get
    cleared early (or it won't get cleared at all).
    
    The new logic, besides allowing for a caller override for the
    continuation type to be set (for VMX real mode emulation), will also
    avoid setting an MMIO completion when a simpler PIO one will do. This
    is a minor optimization only as a side effect - the behavior is strictly
    needed at least for hvm_ud_intercept(), as only memory accesses can
    successfully complete through handle_mmio(). Care of course needs to be
    taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
    the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
    whether the insn being emulated is a memory access, as this information
    is no longer easily available at the point where we want to consume it.
    
    Note that the presence of non-NULL .validate fields in the two ops
    structures in hvm_emulate_one_mmio() was really necessary even before
    the changes here: Without this, passing non-NULL as middle argument to
    hvm_emulate_init_once() is meaningless.
    
    The restrictions on when the #UD intercept gets actually enabled are why
    it was decided that this is not a security issue:
    - the "hvm_fep" option to enable its use is a debugging option only,
    - for the cross-vendor case is considered experimental, even if
      unfortunately SUPPORT.md doesn't have an explicit statement about
      this.
    The other two affected functions are
    - hvm_emulate_one_vm_event(), used for introspection,
    - hvm_emulate_one_mmio(), used for Dom0 only,
    which aren't qualifying this as needing an XSA either.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Don Slutz <don.slutz@gmail.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    master commit: b807cfe954b8d0d8852398b4c8a586d95d69a342
    master date: 2020-09-15 10:19:33 +0200
---
 xen/arch/x86/hvm/emulate.c        | 51 ++++++++++++++++++++++++++++++---------
 xen/arch/x86/hvm/hvm.c            |  2 +-
 xen/arch/x86/hvm/io.c             | 11 +--------
 xen/arch/x86/hvm/vmx/realmode.c   |  6 +----
 xen/include/asm-x86/hvm/emulate.h |  7 +++++-
 5 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 637034b6a1..f4620ff044 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1603,9 +1603,11 @@ static int hvmemul_validate(
     const struct x86_emulate_state *state,
     struct x86_emulate_ctxt *ctxt)
 {
-    const struct hvm_emulate_ctxt *hvmemul_ctxt =
+    struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
 
+    hvmemul_ctxt->is_mem_access = x86_insn_is_mem_access(state, ctxt);
+
     return !hvmemul_ctxt->validate || hvmemul_ctxt->validate(state, ctxt)
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
 }
@@ -2516,8 +2518,14 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
     .vmfunc        = hvmemul_vmfunc,
 };
 
+/*
+ * Note that passing HVMIO_no_completion into this function serves as kind
+ * of (but not fully) an "auto select completion" indicator.  When there's
+ * no completion needed, the passed in value will be ignored in any case.
+ */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
-    const struct x86_emulate_ops *ops)
+    const struct x86_emulate_ops *ops,
+    enum hvm_io_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
@@ -2535,15 +2543,30 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
         rc = X86EMUL_RETRY;
 
     if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+        completion = HVMIO_no_completion;
+    else if ( completion == HVMIO_no_completion )
+        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
+                                                   : HVMIO_pio_completion;
+
+    switch ( vio->io_completion = completion )
     {
+    case HVMIO_no_completion:
+    case HVMIO_pio_completion:
         vio->mmio_cache_count = 0;
         vio->mmio_insn_bytes = 0;
-    }
-    else
-    {
+        vio->mmio_access = (struct npfec){};
+        break;
+
+    case HVMIO_mmio_completion:
+    case HVMIO_realmode_completion:
         BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
         vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
         memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
     }
 
     if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2584,9 +2607,10 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 }
 
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt)
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion)
 {
-    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops);
+    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
 
 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
@@ -2595,11 +2619,13 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmcfg_intercept_write,
+        .validate   = hvmemul_validate,
     };
     static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = {
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmio_ro_emulated_write,
+        .validate   = hvmemul_validate,
     };
     struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla };
     struct hvm_emulate_ctxt ctxt;
@@ -2619,8 +2645,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
     hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write,
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
-    rc = _hvm_emulate_one(&ctxt, ops);
-    switch ( rc )
+
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2647,7 +2673,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     switch ( kind )
     {
     case EMUL_KIND_NOWRITE:
-        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write);
+        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
+                              HVMIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
@@ -2668,7 +2695,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx);
+        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
     }
 
     switch ( rc )
@@ -2765,6 +2792,8 @@ void hvm_emulate_init_per_insn(
         hvmemul_ctxt->insn_buf_bytes = insn_bytes;
         memcpy(hvmemul_ctxt->insn_buf, insn_buf, insn_bytes);
     }
+
+    hvmemul_ctxt->is_mem_access = false;
 }
 
 void hvm_emulate_writeback(
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 704ac8b1bf..d946d16335 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3792,7 +3792,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt) )
+    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 724ab44a76..3e09d9b726 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -81,20 +81,11 @@ void send_invalidate_req(void)
 bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 {
     struct hvm_emulate_ctxt ctxt;
-    struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    rc = hvm_emulate_one(&ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_mmio_completion;
-    else
-        vio->mmio_access = (struct npfec){};
-
-    switch ( rc )
+    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c
index bb0b4439df..b1d445923a 100644
--- a/xen/arch/x86/hvm/vmx/realmode.c
+++ b/xen/arch/x86/hvm/vmx/realmode.c
@@ -96,15 +96,11 @@ static void realmode_deliver_exception(
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_realmode_completion;
+    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
diff --git a/xen/include/asm-x86/hvm/emulate.h b/xen/include/asm-x86/hvm/emulate.h
index b39a1a0331..7d3e13d3c3 100644
--- a/xen/include/asm-x86/hvm/emulate.h
+++ b/xen/include/asm-x86/hvm/emulate.h
@@ -46,6 +46,8 @@ struct hvm_emulate_ctxt {
 
     uint32_t intr_shadow;
 
+    bool is_mem_access;
+
     bool_t set_context;
 };
 
@@ -56,11 +58,14 @@ enum emul_kind {
     EMUL_KIND_SET_CONTEXT_INSN
 };
 
+enum hvm_io_completion;
+
 bool __nonnull(1, 2) hvm_emulate_one_insn(
     hvm_emulate_validate_t *validate,
     const char *descr);
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt);
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTV-0007Gs-6c; Tue, 22 Sep 2020 15:45:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkTT-0007Gb-8i
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:59 +0000
X-Inumbo-ID: 8995ff46-639d-4433-8ac6-ba61a5fc8450
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 8995ff46-639d-4433-8ac6-ba61a5fc8450;
 Tue, 22 Sep 2020 15:44:58 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=SsB3+ojfJAZOE6uy04PjzcjRPXz7nHeGTMKXXcMaRX8=; b=4rgDmotR73aDx2EaIzwpxsM2FV
 MEaDK+xSZ8x2xZ5fWs310+AjJzqKe3a4P+ZpOrpN/gDEBr3FX9/3kEnSWDS1ZJnr6RaOETXEt9/73
 zQ1BJ98V3qm9MbQyizVLTk8CLAPEeoxrWl8XOV4j9AzxYpOJZUPdLGphtDqDk3HbKvXU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTS-0001V0-3H
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:58 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTS-0007ZT-2U
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:44:58 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] hvmloader: indicate ACPI tables with "ACPI data"
 type in e820
Message-Id: <E1kKkTS-0007ZT-2U@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:44:58 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0ca821f19799533f2e8b0dfce1ea4b44b686fe26
Author:     Igor Druzhinin <igor.druzhinin@citrix.com>
AuthorDate: Tue Sep 22 17:42:07 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:42:07 2020 +0200

    hvmloader: indicate ACPI tables with "ACPI data" type in e820
    
    Guest kernel does need to know in some cases where the tables are located
    to treat these regions properly. One example is kexec process where
    the first kernel needs to pass ACPI region locations to the second
    kernel which is now a requirement in Linux after 02a3e3cdb7f12 ("x86/boot:
    Parse SRAT table and count immovable memory regions") in order for kexec
    transition to actually work.
    
    That commit introduced accesses to XSDT and SRAT while the second kernel
    is still using kexec transition tables. The transition tables do not have
    e820 "reserved" regions mapped where those tables are located currently
    in a Xen guest. Instead "ACPI data" regions are mapped with the transition
    tables that was introduced by the following commit 6bbeb276b7 ("x86/kexec:
    Add the EFI system tables and ACPI tables to the ident map").
    
    Reserve 1MB (out of 16MB currently available) right after ACPI info page for
    ACPI tables exclusively but populate this region on demand and only indicate
    populated memory as "ACPI data" since according to ACPI spec that memory is
    reclaimable by the guest if necessary. That is close to how we treat
    the same ACPI data in PVH guests. 1MB should be enough for now but could be
    later extended if required.
    
    Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
    master commit: 8efa46516c5f4cf185c8df179812c185d3c27eb6
    master date: 2020-09-09 17:56:13 +0200
---
 tools/firmware/hvmloader/config.h    |  6 +++++-
 tools/firmware/hvmloader/e820.c      | 26 ++++++++++++++++++++++----
 tools/firmware/hvmloader/hvmloader.c |  3 ++-
 tools/firmware/hvmloader/pci.c       |  1 -
 tools/firmware/hvmloader/util.c      | 29 ++++++++++++++++++++++++++++-
 tools/firmware/hvmloader/util.h      |  2 ++
 6 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index d9b4713d63..844120bc87 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -2,6 +2,7 @@
 #define __HVMLOADER_CONFIG_H__
 
 #include <stdint.h>
+#include <stdbool.h>
 
 enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
@@ -62,6 +63,8 @@ extern uint8_t ioapic_version;
 extern unsigned long pci_mem_start, pci_mem_end;
 extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 
+extern bool acpi_enabled;
+
 /* Memory map. */
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
@@ -71,7 +74,8 @@ extern uint64_t pci_hi_mem_start, pci_hi_mem_end;
 #define RESERVED_MEMBASE              0xFC000000
 /* NB. ACPI_INFO_PHYSICAL_ADDRESS *MUST* match definition in acpi/dsdt.asl! */
 #define ACPI_INFO_PHYSICAL_ADDRESS    0xFC000000
-#define RESERVED_MEMORY_DYNAMIC_START 0xFC001000
+#define ACPI_MEMORY_DYNAMIC_START     0xFC001000
+#define RESERVED_MEMORY_DYNAMIC_START 0xFC100000
 #define RESERVED_MEMORY_DYNAMIC_END   0xFE000000
 /*
  * GUEST_RESERVED: Physical address space reserved for guest use.
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 4d1c955a02..38bcf18b63 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -155,6 +155,9 @@ int build_e820_table(struct e820entry *e820,
 {
     unsigned int nr = 0, i, j;
     uint32_t low_mem_end = hvm_info->low_mem_pgend << PAGE_SHIFT;
+    unsigned long acpi_mem_end = acpi_enabled ?
+        ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated() << PAGE_SHIFT) :
+        RESERVED_MEMBASE;
 
     if ( !lowmem_reserved_base )
             lowmem_reserved_base = 0xA0000;
@@ -198,9 +201,24 @@ int build_e820_table(struct e820entry *e820,
     e820[nr].type = E820_RESERVED;
     nr++;
 
+    /*
+     * Mark populated reserved memory that contains ACPI tables as ACPI data.
+     * That should help the guest to treat it correctly later: e.g. pass to
+     * the next kernel on kexec or reclaim if necessary.
+     */
+
+    if ( acpi_enabled )
+    {
+        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].size = acpi_mem_end - RESERVED_MEMBASE;
+        e820[nr].type = E820_ACPI;
+        nr++;
+    }
+
     /*
      * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * This space starts right after ACPI region (to avoid creating a hole that
+     * might be accidentally occupied by MMIO) and extends to cover various
      * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
      *
      * If igd_opregion_pgbase we need to split the RESERVED region in two.
@@ -210,8 +228,8 @@ int build_e820_table(struct e820entry *e820,
     {
         uint32_t igd_opregion_base = igd_opregion_pgbase << PAGE_SHIFT;
 
-        e820[nr].addr = RESERVED_MEMBASE;
-        e820[nr].size = (uint32_t) igd_opregion_base - RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
+        e820[nr].size = igd_opregion_base - acpi_mem_end;
         e820[nr].type = E820_RESERVED;
         nr++;
 
@@ -227,7 +245,7 @@ int build_e820_table(struct e820entry *e820,
     }
     else
     {
-        e820[nr].addr = RESERVED_MEMBASE;
+        e820[nr].addr = acpi_mem_end;
         e820[nr].size = (uint32_t)-e820[nr].addr;
         e820[nr].type = E820_RESERVED;
         nr++;
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index 598a226278..c58841e5b5 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -116,6 +116,8 @@ unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
 uint32_t ioapic_base_address = 0xfec00000;
 uint8_t ioapic_version;
 
+bool acpi_enabled;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -321,7 +323,6 @@ const struct hvm_modlist_entry *get_module_entry(
 int main(void)
 {
     const struct bios_config *bios;
-    int acpi_enabled;
     const struct hvm_modlist_entry *bios_module;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index dcd097a866..72f92d4450 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -28,7 +28,6 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/e820.h>
-#include <stdbool.h>
 
 unsigned long pci_mem_start = HVM_BELOW_4G_MMIO_START;
 unsigned long pci_mem_end = PCI_MEM_END;
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index 0c3f2d24cd..7da144b0bb 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -871,10 +871,37 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static unsigned long acpi_alloc_up = ACPI_MEMORY_DYNAMIC_START - 1;
+
+unsigned long acpi_pages_allocated(void)
+{
+    return (acpi_alloc_up >> PAGE_SHIFT) -
+            ((ACPI_MEMORY_DYNAMIC_START - 1) >> PAGE_SHIFT);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
-    return mem_alloc(size, align);
+    unsigned long s, e;
+
+    /* Align to at least 16 bytes. */
+    if ( align < 16 )
+        align = 16;
+
+    s = (acpi_alloc_up + align) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON((e < s) || (e >= RESERVED_MEMORY_DYNAMIC_START));
+
+    while ( (acpi_alloc_up >> PAGE_SHIFT) != (e >> PAGE_SHIFT) )
+    {
+        acpi_alloc_up += PAGE_SIZE;
+        mem_hole_populate_ram(acpi_alloc_up >> PAGE_SHIFT, 1);
+    }
+
+    acpi_alloc_up = e;
+
+    return (void *)s;
 }
 
 static void acpi_mem_free(struct acpi_ctxt *ctxt,
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 7bca6418d2..31889de634 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -282,6 +282,8 @@ bool check_overlap(uint64_t start, uint64_t size,
 extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
 extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
 
+unsigned long acpi_pages_allocated(void);
+
 struct acpi_config;
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTf-0007Hn-8P; Tue, 22 Sep 2020 15:45:11 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkTd-0007Ha-LY
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:09 +0000
X-Inumbo-ID: f1b2d04d-1db6-4350-9975-a504c446fe63
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f1b2d04d-1db6-4350-9975-a504c446fe63;
 Tue, 22 Sep 2020 15:45:08 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=GMDz3ARF5W0prPhwagODOng0DkK+8mhtfV8OjfJlW/I=; b=Hw9oYuCoOJUtg1J/SuINYE09hc
 leHJBiH5zOeXrUS6fqRLSeiZ8rO5jnWwHaTmkN+nUQIZ20h2RZZivmgcT+czMRRiy9DXSLALV1Sdz
 ZYgvgV9vw/oE/zYPcr6p/POdOBxzjLRY5FyWN4LyPj9o2qakozJyIg5zol1czO1AO1H0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTc-0001VX-74
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:08 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTc-0007aK-68
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:08 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.12] x86/HVM: more consistently set I/O completion
Message-Id: <E1kKkTc-0007aK-68@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0186e76a62f7409804c2e4785d5a11e7f82a7c52
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:42:27 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:42:27 2020 +0200

    x86/HVM: more consistently set I/O completion
    
    Doing this just in hvm_emulate_one_insn() is not enough.
    hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
    insns requiring one or more continuations, and at least in principle
    hvm_emulate_one_mmio() could, too. Without proper setting of the field,
    handle_hvm_io_completion() will do nothing completion-wise, and in
    particular the missing re-invocation of the insn emulation paths will
    lead to emulation caching not getting disabled in due course, causing
    the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
    
    Reported-by: Don Slutz <don.slutz@gmail.com>
    
    Similar considerations go for the clearing of vio->mmio_access, which
    gets moved as well.
    
    Additionally all updating of vio->mmio_* now gets done dependent upon
    the new completion value, rather than hvm_ioreq_needs_completion()'s
    return value. This is because it is the completion chosen which controls
    what path will be taken when handling the completion, not the simple
    boolean return value. In particular, PIO completion doesn't involve
    going through the insn emulator, and hence emulator state ought to get
    cleared early (or it won't get cleared at all).
    
    The new logic, besides allowing for a caller override for the
    continuation type to be set (for VMX real mode emulation), will also
    avoid setting an MMIO completion when a simpler PIO one will do. This
    is a minor optimization only as a side effect - the behavior is strictly
    needed at least for hvm_ud_intercept(), as only memory accesses can
    successfully complete through handle_mmio(). Care of course needs to be
    taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
    the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
    whether the insn being emulated is a memory access, as this information
    is no longer easily available at the point where we want to consume it.
    
    Note that the presence of non-NULL .validate fields in the two ops
    structures in hvm_emulate_one_mmio() was really necessary even before
    the changes here: Without this, passing non-NULL as middle argument to
    hvm_emulate_init_once() is meaningless.
    
    The restrictions on when the #UD intercept gets actually enabled are why
    it was decided that this is not a security issue:
    - the "hvm_fep" option to enable its use is a debugging option only,
    - for the cross-vendor case is considered experimental, even if
      unfortunately SUPPORT.md doesn't have an explicit statement about
      this.
    The other two affected functions are
    - hvm_emulate_one_vm_event(), used for introspection,
    - hvm_emulate_one_mmio(), used for Dom0 only,
    which aren't qualifying this as needing an XSA either.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Tested-by: Don Slutz <don.slutz@gmail.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
    master commit: b807cfe954b8d0d8852398b4c8a586d95d69a342
    master date: 2020-09-15 10:19:33 +0200
---
 xen/arch/x86/hvm/emulate.c        | 51 ++++++++++++++++++++++++++++++---------
 xen/arch/x86/hvm/hvm.c            |  2 +-
 xen/arch/x86/hvm/io.c             | 11 +--------
 xen/arch/x86/hvm/vmx/realmode.c   |  6 +----
 xen/include/asm-x86/hvm/emulate.h |  7 +++++-
 5 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index bfa3e1ad93..69e15c56b6 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -1577,9 +1577,11 @@ static int hvmemul_validate(
     const struct x86_emulate_state *state,
     struct x86_emulate_ctxt *ctxt)
 {
-    const struct hvm_emulate_ctxt *hvmemul_ctxt =
+    struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
 
+    hvmemul_ctxt->is_mem_access = x86_insn_is_mem_access(state, ctxt);
+
     return !hvmemul_ctxt->validate || hvmemul_ctxt->validate(state, ctxt)
            ? X86EMUL_OKAY : X86EMUL_UNHANDLEABLE;
 }
@@ -2395,8 +2397,14 @@ static const struct x86_emulate_ops hvm_emulate_ops_no_write = {
     .vmfunc        = hvmemul_vmfunc,
 };
 
+/*
+ * Note that passing HVMIO_no_completion into this function serves as kind
+ * of (but not fully) an "auto select completion" indicator.  When there's
+ * no completion needed, the passed in value will be ignored in any case.
+ */
 static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
-    const struct x86_emulate_ops *ops)
+    const struct x86_emulate_ops *ops,
+    enum hvm_io_completion completion)
 {
     const struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
     struct vcpu *curr = current;
@@ -2414,15 +2422,30 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
         rc = X86EMUL_RETRY;
 
     if ( !hvm_ioreq_needs_completion(&vio->io_req) )
+        completion = HVMIO_no_completion;
+    else if ( completion == HVMIO_no_completion )
+        completion = (vio->io_req.type != IOREQ_TYPE_PIO ||
+                      hvmemul_ctxt->is_mem_access) ? HVMIO_mmio_completion
+                                                   : HVMIO_pio_completion;
+
+    switch ( vio->io_completion = completion )
     {
+    case HVMIO_no_completion:
+    case HVMIO_pio_completion:
         vio->mmio_cache_count = 0;
         vio->mmio_insn_bytes = 0;
-    }
-    else
-    {
+        vio->mmio_access = (struct npfec){};
+        break;
+
+    case HVMIO_mmio_completion:
+    case HVMIO_realmode_completion:
         BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt->insn_buf));
         vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;
         memcpy(vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes);
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
     }
 
     if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2462,9 +2485,10 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,
 }
 
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt)
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion)
 {
-    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops);
+    return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion);
 }
 
 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
@@ -2473,12 +2497,14 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmcfg_intercept_write,
+        .validate   = hvmemul_validate,
         .cpuid      = hvmemul_cpuid,
     };
     static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = {
         .read       = x86emul_unhandleable_rw,
         .insn_fetch = hvmemul_insn_fetch,
         .write      = mmio_ro_emulated_write,
+        .validate   = hvmemul_validate,
         .cpuid      = hvmemul_cpuid,
     };
     struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla };
@@ -2499,8 +2525,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)
     hvm_emulate_init_once(&ctxt, x86_insn_is_mem_write,
                           guest_cpu_user_regs());
     ctxt.ctxt.data = &mmio_ro_ctxt;
-    rc = _hvm_emulate_one(&ctxt, ops);
-    switch ( rc )
+
+    switch ( rc = _hvm_emulate_one(&ctxt, ops, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
@@ -2527,7 +2553,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     switch ( kind )
     {
     case EMUL_KIND_NOWRITE:
-        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write);
+        rc = _hvm_emulate_one(&ctx, &hvm_emulate_ops_no_write,
+                              HVMIO_no_completion);
         break;
     case EMUL_KIND_SET_CONTEXT_INSN: {
         struct vcpu *curr = current;
@@ -2548,7 +2575,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,
     /* Fall-through */
     default:
         ctx.set_context = (kind == EMUL_KIND_SET_CONTEXT_DATA);
-        rc = hvm_emulate_one(&ctx);
+        rc = hvm_emulate_one(&ctx, HVMIO_no_completion);
     }
 
     switch ( rc )
@@ -2644,6 +2671,8 @@ void hvm_emulate_init_per_insn(
         hvmemul_ctxt->insn_buf_bytes = insn_bytes;
         memcpy(hvmemul_ctxt->insn_buf, insn_buf, insn_bytes);
     }
+
+    hvmemul_ctxt->is_mem_access = false;
 }
 
 void hvm_emulate_writeback(
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index a98f7471b4..4d170ca597 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3773,7 +3773,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
         return;
     }
 
-    switch ( hvm_emulate_one(&ctxt) )
+    switch ( hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
     case X86EMUL_UNIMPLEMENTED:
diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
index 724ab44a76..3e09d9b726 100644
--- a/xen/arch/x86/hvm/io.c
+++ b/xen/arch/x86/hvm/io.c
@@ -81,20 +81,11 @@ void send_invalidate_req(void)
 bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr)
 {
     struct hvm_emulate_ctxt ctxt;
-    struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     hvm_emulate_init_once(&ctxt, validate, guest_cpu_user_regs());
 
-    rc = hvm_emulate_one(&ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_mmio_completion;
-    else
-        vio->mmio_access = (struct npfec){};
-
-    switch ( rc )
+    switch ( rc = hvm_emulate_one(&ctxt, HVMIO_no_completion) )
     {
     case X86EMUL_UNHANDLEABLE:
         hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc);
diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c
index bb0b4439df..b1d445923a 100644
--- a/xen/arch/x86/hvm/vmx/realmode.c
+++ b/xen/arch/x86/hvm/vmx/realmode.c
@@ -96,15 +96,11 @@ static void realmode_deliver_exception(
 void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    struct hvm_vcpu_io *vio = &curr->arch.hvm.hvm_io;
     int rc;
 
     perfc_incr(realmode_emulations);
 
-    rc = hvm_emulate_one(hvmemul_ctxt);
-
-    if ( hvm_ioreq_needs_completion(&vio->io_req) )
-        vio->io_completion = HVMIO_realmode_completion;
+    rc = hvm_emulate_one(hvmemul_ctxt, HVMIO_realmode_completion);
 
     if ( rc == X86EMUL_UNHANDLEABLE )
     {
diff --git a/xen/include/asm-x86/hvm/emulate.h b/xen/include/asm-x86/hvm/emulate.h
index 26a01e83a4..240b39447b 100644
--- a/xen/include/asm-x86/hvm/emulate.h
+++ b/xen/include/asm-x86/hvm/emulate.h
@@ -46,6 +46,8 @@ struct hvm_emulate_ctxt {
 
     uint32_t intr_shadow;
 
+    bool is_mem_access;
+
     bool_t set_context;
 };
 
@@ -56,11 +58,14 @@ enum emul_kind {
     EMUL_KIND_SET_CONTEXT_INSN
 };
 
+enum hvm_io_completion;
+
 bool __nonnull(1, 2) hvm_emulate_one_insn(
     hvm_emulate_validate_t *validate,
     const char *descr);
 int hvm_emulate_one(
-    struct hvm_emulate_ctxt *hvmemul_ctxt);
+    struct hvm_emulate_ctxt *hvmemul_ctxt,
+    enum hvm_io_completion completion);
 void hvm_emulate_one_vm_event(enum emul_kind kind,
     unsigned int trapnr,
     unsigned int errcode);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:22 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTq-0007JI-AI; Tue, 22 Sep 2020 15:45:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkTo-0007J8-DC
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:20 +0000
X-Inumbo-ID: 3f440994-7ad2-400b-bb6c-39512cd01a3c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3f440994-7ad2-400b-bb6c-39512cd01a3c;
 Tue, 22 Sep 2020 15:45:19 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=6zWFb5lzrNPTE146lVq5OCew8WWBANgJ2Wz9Y+czbAY=; b=kPuGY5IktRV4T90mA0q7JmQzbQ
 Uc+P5ZEsopjnwacbn+OlR0Tsb6wBQY4CdTs+HbzIbYyRBG98zyhVHkU2Ca1A/+rX8oQDFfkPTa2c9
 TBtZeZui0g3m1RPh2KicC6RcBfNvfe+G+bb4Od2+qVeynP+ezFx1B+okWXibyiNoLHek=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTn-0001Ve-6y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTn-0007cc-5c
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] x86/vpt: fix race when migrating timers between
 vCPUs
Message-Id: <E1kKkTn-0007cc-5c@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4218b74d878574ac7724af4dbeeb3298c4053e90
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:27:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:27:52 2020 +0200

    x86/vpt: fix race when migrating timers between vCPUs
    
    The current vPT code will migrate the emulated timers between vCPUs
    (change the pt->vcpu field) while just holding the destination lock,
    either from create_periodic_time or pt_adjust_global_vcpu_target if
    the global target is adjusted. Changing the periodic_timer vCPU field
    in this way creates a race where a third party could grab the lock in
    the unlocked region of pt_adjust_global_vcpu_target (or before
    create_periodic_time performs the vcpu change) and then release the
    lock from a different vCPU, creating a locking imbalance.
    
    Introduce a per-domain rwlock in order to protect periodic_time
    migration between vCPU lists. Taking the lock in read mode prevents
    any timer from being migrated to a different vCPU, while taking it in
    write mode allows performing migration of timers across vCPUs. The
    per-vcpu locks are still used to protect all the other fields from the
    periodic_timer struct.
    
    Note that such migration shouldn't happen frequently, and hence
    there's no performance drop as a result of such locking.
    
    This is XSA-336.
    
    Reported-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Tested-by: Igor Druzhinin <igor.druzhinin@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/hvm.c        |  2 ++
 xen/arch/x86/hvm/vpt.c        | 77 +++++++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vpt.h |  7 ++++
 3 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 698ab63340..91a997c946 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -614,6 +614,8 @@ int hvm_domain_initialise(struct domain *d, unsigned long domcr_flags,
     /* need link to containing domain */
     d->arch.hvm_domain.pl_time->domain = d;
 
+    rwlock_init(&d->arch.hvm_domain.pl_time->pt_migrate);
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index 04e3c2e15b..5b83ca53b0 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -152,23 +152,32 @@ static int pt_irq_masked(struct periodic_time *pt)
     return 1;
 }
 
-static void pt_lock(struct periodic_time *pt)
+static void pt_vcpu_lock(struct vcpu *v)
 {
-    struct vcpu *v;
+    read_lock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
+    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+}
 
-    for ( ; ; )
-    {
-        v = pt->vcpu;
-        spin_lock(&v->arch.hvm_vcpu.tm_lock);
-        if ( likely(pt->vcpu == v) )
-            break;
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
-    }
+static void pt_vcpu_unlock(struct vcpu *v)
+{
+    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    read_unlock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
+}
+
+static void pt_lock(struct periodic_time *pt)
+{
+    /*
+     * We cannot use pt_vcpu_lock here, because we need to acquire the
+     * per-domain lock first and then (re-)fetch the value of pt->vcpu, or
+     * else we might be using a stale value of pt->vcpu.
+     */
+    read_lock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
+    spin_lock(&pt->vcpu->arch.hvm_vcpu.tm_lock);
 }
 
 static void pt_unlock(struct periodic_time *pt)
 {
-    spin_unlock(&pt->vcpu->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(pt->vcpu);
 }
 
 static void pt_process_missed_ticks(struct periodic_time *pt)
@@ -218,7 +227,7 @@ void pt_save_timer(struct vcpu *v)
     if ( v->pause_flags & VPF_blocked )
         return;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         if ( !pt->do_not_freeze )
@@ -226,7 +235,7 @@ void pt_save_timer(struct vcpu *v)
 
     pt_freeze_time(v);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void pt_restore_timer(struct vcpu *v)
@@ -234,7 +243,7 @@ void pt_restore_timer(struct vcpu *v)
     struct list_head *head = &v->arch.hvm_vcpu.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
     {
@@ -247,7 +256,7 @@ void pt_restore_timer(struct vcpu *v)
 
     pt_thaw_time(v);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 static void pt_timer_fn(void *data)
@@ -272,7 +281,7 @@ int pt_update_irq(struct vcpu *v)
     uint64_t max_lag;
     int irq, pt_vector = -1;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     earliest_pt = NULL;
     max_lag = -1ULL;
@@ -300,14 +309,14 @@ int pt_update_irq(struct vcpu *v)
 
     if ( earliest_pt == NULL )
     {
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+        pt_vcpu_unlock(v);
         return -1;
     }
 
     earliest_pt->irq_issued = 1;
     irq = earliest_pt->irq;
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 
     switch ( earliest_pt->source )
     {
@@ -377,12 +386,12 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     if ( intack.source == hvm_intsrc_vector )
         return;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     pt = is_pt_irq(v, intack);
     if ( pt == NULL )
     {
-        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+        pt_vcpu_unlock(v);
         return;
     }
 
@@ -421,7 +430,7 @@ void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
     cb = pt->cb;
     cb_priv = pt->priv;
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 
     if ( cb != NULL )
         cb(v, cb_priv);
@@ -432,12 +441,12 @@ void pt_migrate(struct vcpu *v)
     struct list_head *head = &v->arch.hvm_vcpu.tm_list;
     struct periodic_time *pt;
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_lock(v);
 
     list_for_each_entry ( pt, head, list )
         migrate_timer(&pt->timer, v->processor);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    pt_vcpu_unlock(v);
 }
 
 void create_periodic_time(
@@ -455,7 +464,7 @@ void create_periodic_time(
 
     destroy_periodic_time(pt);
 
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    write_lock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
 
     pt->pending_intr_nr = 0;
     pt->do_not_freeze = 0;
@@ -504,7 +513,7 @@ void create_periodic_time(
     init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
     set_timer(&pt->timer, pt->scheduled);
 
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    write_unlock(&v->domain->arch.hvm_domain.pl_time->pt_migrate);
 }
 
 void destroy_periodic_time(struct periodic_time *pt)
@@ -529,30 +538,20 @@ void destroy_periodic_time(struct periodic_time *pt)
 
 static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v)
 {
-    int on_list;
-
     ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic);
 
     if ( pt->vcpu == NULL )
         return;
 
-    pt_lock(pt);
-    on_list = pt->on_list;
-    if ( pt->on_list )
-        list_del(&pt->list);
-    pt->on_list = 0;
-    pt_unlock(pt);
-
-    spin_lock(&v->arch.hvm_vcpu.tm_lock);
+    write_lock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
     pt->vcpu = v;
-    if ( on_list )
+    if ( pt->on_list )
     {
-        pt->on_list = 1;
+        list_del(&pt->list);
         list_add(&pt->list, &v->arch.hvm_vcpu.tm_list);
-
         migrate_timer(&pt->timer, v->processor);
     }
-    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
+    write_unlock(&pt->vcpu->domain->arch.hvm_domain.pl_time->pt_migrate);
 }
 
 void pt_adjust_global_vcpu_target(struct vcpu *v)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 0eb5ff632e..ed8de96191 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -133,6 +133,13 @@ struct pl_time {    /* platform time */
     struct RTCState  vrtc;
     struct HPETState vhpet;
     struct PMTState  vpmt;
+    /*
+     * rwlock to prevent periodic_time vCPU migration. Take the lock in read
+     * mode in order to prevent the vcpu field of periodic_time from changing.
+     * Lock must be taken in write mode when changes to the vcpu field are
+     * performed, as it allows exclusive access to all the timers of a domain.
+     */
+    rwlock_t pt_migrate;
     /* guest_time = Xen sys time + stime_offset */
     int64_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:31 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkTz-0007KW-Da; Tue, 22 Sep 2020 15:45:31 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkTy-0007KM-6R
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:30 +0000
X-Inumbo-ID: 9b202385-3bb0-4976-9e79-c0434da82c7e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9b202385-3bb0-4976-9e79-c0434da82c7e;
 Tue, 22 Sep 2020 15:45:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=rnXgDKKsLrLiC8AL+UZmVTBzbs4AkH/RzQJ5f//c3OQ=; b=IlmuRvPcSEmVw1qaCWGh9MJVhA
 +MY6BqhdpJtAeHMM7fm4tZbPvsYtzO2C5a2e3jcNO+Xag37YjPrgnD9Gu+67jLsOMua5qWOueiqxH
 /cE6GPbom1/D+AaZBjHjytKMimM0dwRd3AOb0+DVS7KbOQoQkTrwjvI0IA3rYLXSuGIg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTx-0001Vs-AT
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:29 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkTx-0007dF-9M
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] x86/msi: get rid of read_msi_msg
Message-Id: <E1kKkTx-0007dF-9M@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 3d14937f4a6f1906f4883a59959ee5ba8aa2f388
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Tue Sep 22 17:28:49 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:28:49 2020 +0200

    x86/msi: get rid of read_msi_msg
    
    It's safer and faster to just use the cached last written
    (untranslated) MSI message stored in msi_desc for the single user that
    calls read_msi_msg.
    
    This also prevents relying on the data read from the device MSI
    registers in order to figure out the index into the IOMMU interrupt
    remapping table, which is not safe.
    
    This is part of XSA-337.
    
    Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 58 +-----------------------------------------------------
 1 file changed, 1 insertion(+), 57 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 475881ed89..8c5fac1f69 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -191,59 +191,6 @@ void msi_compose_msg(unsigned vector, const cpumask_t *cpu_mask, struct msi_msg
                 MSI_DATA_VECTOR(vector);
 }
 
-static bool read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
-{
-    switch ( entry->msi_attrib.type )
-    {
-    case PCI_CAP_ID_MSI:
-    {
-        struct pci_dev *dev = entry->dev;
-        int pos = entry->msi_attrib.pos;
-        u16 data, seg = dev->seg;
-        u8 bus = dev->bus;
-        u8 slot = PCI_SLOT(dev->devfn);
-        u8 func = PCI_FUNC(dev->devfn);
-
-        msg->address_lo = pci_conf_read32(seg, bus, slot, func,
-                                          msi_lower_address_reg(pos));
-        if ( entry->msi_attrib.is_64 )
-        {
-            msg->address_hi = pci_conf_read32(seg, bus, slot, func,
-                                              msi_upper_address_reg(pos));
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 1));
-        }
-        else
-        {
-            msg->address_hi = 0;
-            data = pci_conf_read16(seg, bus, slot, func,
-                                   msi_data_reg(pos, 0));
-        }
-        msg->data = data;
-        break;
-    }
-    case PCI_CAP_ID_MSIX:
-    {
-        void __iomem *base = entry->mask_base;
-
-        if ( unlikely(!msix_memory_decoded(entry->dev,
-                                           entry->msi_attrib.pos)) )
-            return false;
-        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
-        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
-        msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
-        break;
-    }
-    default:
-        BUG();
-    }
-
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(entry, msg);
-
-    return true;
-}
-
 static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
     entry->msg = *msg;
@@ -321,10 +268,7 @@ void set_msi_affinity(struct irq_desc *desc, const cpumask_t *mask)
 
     ASSERT(spin_is_locked(&desc->lock));
 
-    memset(&msg, 0, sizeof(msg));
-    if ( !read_msi_msg(msi_desc, &msg) )
-        return;
-
+    msg = msi_desc->msg;
     msg.data &= ~MSI_DATA_VECTOR_MASK;
     msg.data |= MSI_DATA_VECTOR(desc->arch.vector);
     msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:41 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkU9-0007Lj-FB; Tue, 22 Sep 2020 15:45:41 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkU8-0007LX-E5
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:40 +0000
X-Inumbo-ID: 127b4ae3-1ec5-4882-b828-6e6502a7045d
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 127b4ae3-1ec5-4882-b828-6e6502a7045d;
 Tue, 22 Sep 2020 15:45:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=trL0FYwlgikfQubQDy4OJyt/WUlyrzDHfU6fbWi+A00=; b=XYCmTTufxL8Eu3UlLism4AmOFO
 X9082WXWl58jvn97lgGL2FG2SATQbqHqA+VQnsGXqGAJZji6ASnbmBKE3wsUovjPd2UyIq3xpKANX
 jElmpsbnlOd4egYK0tMiXWCC+7rax+XjbkXsJJQJ14t2Z831FBaXNLxZavPEU95oqxVs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkU7-0001WT-DU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:39 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkU7-0007dw-Ci
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:39 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] x86/MSI-X: restrict reading of table/PBA bases
 from BARs
Message-Id: <E1kKkU7-0007dw-Ci@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:39 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 635ae1244a2a9f7a6b10ccec76fca58ac5ec2bc3
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:29:19 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:29:19 2020 +0200

    x86/MSI-X: restrict reading of table/PBA bases from BARs
    
    When assigned to less trusted or un-trusted guests, devices may change
    state behind our backs (they may e.g. get reset by means we may not know
    about). Therefore we should avoid reading BARs from hardware once a
    device is no longer owned by Dom0. Furthermore when we can't read a BAR,
    or when we read zero, we shouldn't instead use the caller provided
    address unless that caller can be trusted.
    
    Re-arrange the logic in msix_capability_init() such that only Dom0 (and
    only if the device isn't DomU-owned yet) or calls through
    PHYSDEVOP_prepare_msix will actually result in the reading of the
    respective BAR register(s). Additionally do so only as long as in-use
    table entries are known (note that invocation of PHYSDEVOP_prepare_msix
    counts as a "pseudo" entry). In all other uses the value already
    recorded will get used instead.
    
    Clear the recorded values in _pci_cleanup_msix() as well as on the one
    affected error path. (Adjust this error path to also avoid blindly
    disabling MSI-X when it was enabled on entry to the function.)
    
    While moving around variable declarations (in many cases to reduce their
    scopes), also adjust some of their types.
    
    This is part of XSA-337.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msi.c | 97 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 61 insertions(+), 36 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 8c5fac1f69..77fde75df7 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -785,16 +785,14 @@ static int msix_capability_init(struct pci_dev *dev,
 {
     struct arch_msix *msix = dev->msix;
     struct msi_desc *entry = NULL;
-    int vf;
     u16 control;
     u64 table_paddr;
     u32 table_offset;
-    u8 bir, pbus, pslot, pfunc;
     u16 seg = dev->seg;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
-    bool maskall = msix->host_maskall;
+    bool maskall = msix->host_maskall, zap_on_error = false;
 
     ASSERT(pcidevs_locked());
 
@@ -832,43 +830,45 @@ static int msix_capability_init(struct pci_dev *dev,
     /* Locate MSI-X table region */
     table_offset = pci_conf_read32(seg, bus, slot, func,
                                    msix_table_offset_reg(pos));
-    bir = (u8)(table_offset & PCI_MSIX_BIRMASK);
-    table_offset &= ~PCI_MSIX_BIRMASK;
-
-    if ( !dev->info.is_virtfn )
-    {
-        pbus = bus;
-        pslot = slot;
-        pfunc = func;
-        vf = -1;
-    }
-    else
+    if ( !msix->used_entries &&
+         (!msi ||
+          (is_hardware_domain(current->domain) &&
+           (dev->domain == current->domain || dev->domain == dom_io))) )
     {
-        pbus = dev->info.physfn.bus;
-        pslot = PCI_SLOT(dev->info.physfn.devfn);
-        pfunc = PCI_FUNC(dev->info.physfn.devfn);
-        vf = PCI_BDF2(dev->bus, dev->devfn);
-    }
+        unsigned int bir = table_offset & PCI_MSIX_BIRMASK, pbus, pslot, pfunc;
+        int vf;
+        paddr_t pba_paddr;
+        unsigned int pba_offset;
 
-    table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
-    WARN_ON(msi && msi->table_base != table_paddr);
-    if ( !table_paddr )
-    {
-        if ( !msi || !msi->table_base )
+        if ( !dev->info.is_virtfn )
         {
-            pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
-            xfree(entry);
-            return -ENXIO;
+            pbus = bus;
+            pslot = slot;
+            pfunc = func;
+            vf = -1;
+        }
+        else
+        {
+            pbus = dev->info.physfn.bus;
+            pslot = PCI_SLOT(dev->info.physfn.devfn);
+            pfunc = PCI_FUNC(dev->info.physfn.devfn);
+            vf = PCI_BDF2(dev->bus, dev->devfn);
         }
-        table_paddr = msi->table_base;
-    }
-    table_paddr += table_offset;
 
-    if ( !msix->used_entries )
-    {
-        u64 pba_paddr;
-        u32 pba_offset;
+        table_paddr = read_pci_mem_bar(seg, pbus, pslot, pfunc, bir, vf);
+        WARN_ON(msi && msi->table_base != table_paddr);
+        if ( !table_paddr )
+        {
+            if ( !msi || !msi->table_base )
+            {
+                pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                                 control & ~PCI_MSIX_FLAGS_ENABLE);
+                xfree(entry);
+                return -ENXIO;
+            }
+            table_paddr = msi->table_base;
+        }
+        table_paddr += table_offset & ~PCI_MSIX_BIRMASK;
 
         msix->nr_entries = nr_entries;
         msix->table.first = PFN_DOWN(table_paddr);
@@ -889,7 +889,19 @@ static int msix_capability_init(struct pci_dev *dev,
                                   BITS_TO_LONGS(nr_entries) - 1);
         WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first,
                                         msix->pba.last));
+
+        zap_on_error = true;
     }
+    else if ( !msix->table.first )
+    {
+        pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
+                         control);
+        xfree(entry);
+        return -ENODATA;
+    }
+    else
+        table_paddr = (msix->table.first << PAGE_SHIFT) +
+                      (table_offset & ~PCI_MSIX_BIRMASK & ~PAGE_MASK);
 
     if ( entry )
     {
@@ -900,8 +912,16 @@ static int msix_capability_init(struct pci_dev *dev,
 
         if ( idx < 0 )
         {
+            if ( zap_on_error )
+            {
+                msix->table.first = 0;
+                msix->pba.first = 0;
+
+                control &= ~PCI_MSIX_FLAGS_ENABLE;
+            }
+
             pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos),
-                             control & ~PCI_MSIX_FLAGS_ENABLE);
+                             control);
             xfree(entry);
             return idx;
         }
@@ -1085,9 +1105,14 @@ static void _pci_cleanup_msix(struct arch_msix *msix)
         if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first,
                                    msix->table.last) )
             WARN();
+        msix->table.first = 0;
+        msix->table.last = 0;
+
         if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first,
                                    msix->pba.last) )
             WARN();
+        msix->pba.first = 0;
+        msix->pba.last = 0;
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:45:51 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:45:51 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkUJ-0007OD-HP; Tue, 22 Sep 2020 15:45:51 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkUI-0007O3-EW
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:50 +0000
X-Inumbo-ID: 34345a20-642a-4bcc-b8e7-66b69d7d925e
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 34345a20-642a-4bcc-b8e7-66b69d7d925e;
 Tue, 22 Sep 2020 15:45:49 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=tI7JLx4JrwkiPjUuuIHB04PMcbYMHWxI9IE1CA4PP8Y=; b=B7eC7LjEdOYz714c7ZVPcj5iDW
 dZXqAKV1ni4eWi+gRCzI/dptyRJ4Na9d8yahB6xt2elcb78X3gSqHBcNhHqbIZdx9LrKN0/B+2TWB
 0jIxOVk2Du57HDIY/FmR3x0h6aALqTqERr9YP2AZ332m3U1j/tebKPYp9jPB+ptiXKLY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUH-0001We-GQ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:49 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUH-0007el-Ff
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:49 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: relax port_is_valid()
Message-Id: <E1kKkUH-0007el-Ff@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:49 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f85223f4af24ba11a575d599a2ca7adb238d4046
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:30:04 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:30:04 2020 +0200

    evtchn: relax port_is_valid()
    
    To avoid ports potentially becoming invalid behind the back of certain
    other functions (due to ->max_evtchn shrinking) because of
    - a guest invoking evtchn_reset() and from a 2nd vCPU opening new
      channels in parallel (see also XSA-343),
    - alloc_unbound_xen_event_channel() produced channels living above the
      2-level range (see also XSA-342),
    drop the max_evtchns check from port_is_valid(). For a port for which
    the function once returned "true", the returned value may not turn into
    "false" later on. The function's result may only depend on bounds which
    can only ever grow (which is the case for d->valid_evtchns).
    
    This also eliminates a false sense of safety, utilized by some of the
    users (see again XSA-343): Without a suitable lock held, d->max_evtchns
    may change at any time, and hence deducing that certain other operations
    are safe when port_is_valid() returned true is not legitimate. The
    opportunities to abuse this may get widened by the change here
    (depending on guest and host configuration), but will be taken care of
    by the other XSA.
    
    This is XSA-338.
    
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/include/xen/event.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index b8152a9831..2006ba9252 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -99,8 +99,6 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    if ( p >= d->max_evtchns )
-        return 0;
     return p < read_atomic(&d->valid_evtchns);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:01 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:01 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkUT-0007PH-J1; Tue, 22 Sep 2020 15:46:01 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkUT-0007P5-1s
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:01 +0000
X-Inumbo-ID: dcb1b375-d21f-4370-b837-8539e4b77e75
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id dcb1b375-d21f-4370-b837-8539e4b77e75;
 Tue, 22 Sep 2020 15:45:59 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=wzpMuCQ57DvFqyY9av7zbB0GbYyrKJWYvenN0WQL78I=; b=y8juHZMY1eq5JSBOAXJTCNDIFO
 Dkc4Ve8GnCdZ4/B0mht/a99sojGjyhzxHxo2DNw+SiDyRNURWLyidF9bW76gliypcq0BPG5fQevEB
 rcmTLRLtOnob+VsFQtmH2CdPQyznm+BcLKz8M9EAING4NJQV2CgmoDNpMjBi0sghhD50=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUR-0001Wm-MB
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:59 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUR-0007fZ-Id
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:45:59 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] x86/pv: Avoid double exception injection
Message-Id: <E1kKkUR-0007fZ-Id@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:45:59 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 540254011fa30ee43783f7850cf3d24d9477ca0d
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 17:31:31 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:31:31 2020 +0200

    x86/pv: Avoid double exception injection
    
    There is at least one path (SYSENTER with NT set, Xen converts to #GP) which
    ends up injecting the #GP fault twice, first in compat_sysenter(), and then a
    second time in compat_test_all_events(), due to the stale TBF_EXCEPTION left
    in TRAPBOUNCE_flags.
    
    The guest kernel sees the second fault first, which is a kernel level #GP
    pointing at the head of the #GP handler, and is therefore a userspace
    trigger-able DoS.
    
    This particular bug has bitten us several times before, so rearrange
    {compat_,}create_bounce_frame() to clobber TRAPBOUNCE on success, rather than
    leaving this task to one area of code which isn't used uniformly.
    
    Other scenarios which might result in a double injection (e.g. two calls
    directly to compat_create_bounce_frame) will now crash the guest, which is far
    more obvious than letting the kernel run with corrupt state.
    
    This is XSA-339
    
    Fixes: fdac9515607b ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 7 ++++++-
 xen/arch/x86/x86_64/entry.S        | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index 1c4cd795d2..2d0bc3a778 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -80,7 +80,6 @@ compat_process_softirqs:
         sti
 .Lcompat_bounce_exception:
         call  compat_create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   compat_test_all_events
 
 	ALIGN
@@ -357,7 +356,13 @@ __UNLIKELY_END(compat_bounce_null_selector)
         movl  %eax,UREGS_cs+8(%rsp)
         movl  TRAPBOUNCE_eip(%rdx),%eax
         movl  %eax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %ax,  TRAPBOUNCE_cs(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
+
 .section .fixup,"ax"
 .Lfx13:
         xorl  %edi,%edi
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index c163c31a60..5a35402341 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -81,7 +81,6 @@ process_softirqs:
         sti
 .Lbounce_exception:
         call  create_bounce_frame
-        movb  $0, TRAPBOUNCE_flags(%rdx)
         jmp   test_all_events
 
         ALIGN
@@ -509,6 +508,11 @@ UNLIKELY_START(z, create_bounce_frame_bad_bounce_ip)
         jmp   asm_domain_crash_synchronous  /* Does not return */
 __UNLIKELY_END(create_bounce_frame_bad_bounce_ip)
         movq  %rax,UREGS_rip+8(%rsp)
+
+        /* Trapbounce complete.  Clobber state to avoid an erroneous second injection. */
+        xor   %eax, %eax
+        mov   %rax, TRAPBOUNCE_eip(%rdx)
+        mov   %al,  TRAPBOUNCE_flags(%rdx)
         ret
 
         .pushsection .fixup, "ax", @progbits
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkUd-0007QR-Kj; Tue, 22 Sep 2020 15:46:11 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkUc-0007QH-Ku
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:10 +0000
X-Inumbo-ID: 41d176cd-0006-4c27-9c50-54579503b95a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 41d176cd-0006-4c27-9c50-54579503b95a;
 Tue, 22 Sep 2020 15:46:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/PKIcM+iZL455v1WveLogblP+2x2JITvCddntvhBWe0=; b=3Tpiin7lO2Vi4X0AT9wyUyBpKN
 N3UAQJyGXWZCt72l+okKilntFajSsaRQyzvFZpGzRxIL23TmL9qP3X97j+Xm9I6TEAwl4LhLPzFHB
 Dul7HYueaAZDuCcyXZqvB37MjJpfvLSXHo+BdmE8JK/s1duGmPjglKwqrwBHTNzfg9jM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUb-0001X9-PT
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:09 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUb-0007gg-Oc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:09 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] xen/evtchn: Add missing barriers when
 accessing/allocating an event channel
Message-Id: <E1kKkUb-0007gg-Oc@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:46:09 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit baf80b695da1ac6ad455535ddf9030fc288513ec
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 17:32:42 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:32:42 2020 +0200

    xen/evtchn: Add missing barriers when accessing/allocating an event channel
    
    While the allocation of a bucket is always performed with the per-domain
    lock, the bucket may be accessed without the lock taken (for instance, see
    evtchn_send()).
    
    Instead such sites relies on port_is_valid() to return a non-zero value
    when the port has a struct evtchn associated to it. The function will
    mostly check whether the port is less than d->valid_evtchns as all the
    buckets/event channels should be allocated up to that point.
    
    Unfortunately a compiler is free to re-order the assignment in
    evtchn_allocate_port() so it would be possible to have d->valid_evtchns
    updated before the new bucket has finish to allocate.
    
    Additionally on Arm, even if this was compiled "correctly", the
    processor can still re-order the memory access.
    
    Add a write memory barrier in the allocation side and a read memory
    barrier when the port is valid to prevent any re-ordering issue.
    
    This is XSA-340.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/event_channel.c |  7 +++++++
 xen/include/xen/event.h    | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 07ef45a140..82e42c7e32 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -185,6 +185,13 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
             return -ENOMEM;
         bucket_from_port(d, port) = chn;
 
+        /*
+         * d->valid_evtchns is used to check whether the bucket can be
+         * accessed without the per-domain lock. Therefore,
+         * d->valid_evtchns should be seen *after* the new bucket has
+         * been setup.
+         */
+        smp_wmb();
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 2006ba9252..70bd63423e 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -99,7 +99,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
-    return p < read_atomic(&d->valid_evtchns);
+    if ( p >= read_atomic(&d->valid_evtchns) )
+        return false;
+
+    /*
+     * The caller will usually access the event channel afterwards and
+     * may be done without taking the per-domain lock. The barrier is
+     * going in pair the smp_wmb() barrier in evtchn_allocate_port().
+     */
+    smp_rmb();
+
+    return true;
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:22 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkUo-0007SI-Nv; Tue, 22 Sep 2020 15:46:22 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkUn-0007S8-IK
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:21 +0000
X-Inumbo-ID: de3512fc-87c6-43ab-9025-9d774a9d0d3f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id de3512fc-87c6-43ab-9025-9d774a9d0d3f;
 Tue, 22 Sep 2020 15:46:20 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Rh9N7pB8P144Cjlux7Xetf34AIZ7HO8eTA0wkXz6GL4=; b=fARTwuxdtmxYj/7b0Ia8IeNy0u
 IbBK2feHz9iD8yKGwgOmR0oz32y48QIQ5Z5QZPmSJH/0jGS+6oXAMK7x+SWagCnMSHCesg9q7cuhB
 mwqQiY5kybYfBBtWRgUH6v5diNp2n6eEuyVsoW78MdOpisLzJ3Al2MXqHln9+RNPPUcs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUl-0001XN-T7
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:19 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUl-0007hH-SG
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:19 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn/x86: enforce correct upper limit for 32-bit
 guests
Message-Id: <E1kKkUl-0007hH-SG@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:46:19 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 8fac37e162bf8c146031583ddc2e7b6bda145f98
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:33:25 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:33:25 2020 +0200

    evtchn/x86: enforce correct upper limit for 32-bit guests
    
    The recording of d->max_evtchns in evtchn_2l_init(), in particular with
    the limited set of callers of the function, is insufficient. Neither for
    PV nor for HVM guests the bitness is known at domain_create() time, yet
    the upper bound in 2-level mode depends upon guest bitness. Recording
    too high a limit "allows" x86 32-bit domains to open not properly usable
    event channels, management of which (inside Xen) would then result in
    corruption of the shared info and vCPU info structures.
    
    Keep the upper limit dynamic for the 2-level case, introducing a helper
    function to retrieve the effective limit. This helper is now supposed to
    be private to the event channel code. The used in do_poll() and
    domain_dump_evtchn_info() weren't consistent with port uses elsewhere
    and hence get switched to port_is_valid().
    
    Furthermore FIFO mode's setup_ports() gets adjusted to loop only up to
    the prior ABI limit, rather than all the way up to the new one.
    
    Finally a word on the change to do_poll(): Accessing ->max_evtchns
    without holding a suitable lock was never safe, as it as well as
    ->evtchn_port_ops may change behind do_poll()'s back. Using
    port_is_valid() instead widens some the window for potential abuse,
    until we've dealt with the race altogether (see XSA-343).
    
    This is XSA-342.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Fixes: 48974e6ce52e ("evtchn: use a per-domain variable for the max number of event channels")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_2l.c      | 1 -
 xen/common/event_channel.c | 6 ++----
 xen/common/event_fifo.c    | 9 +++++----
 xen/common/schedule.c      | 2 +-
 xen/include/xen/event.h    | 6 ++++++
 xen/include/xen/sched.h    | 1 -
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index e1dbb860f4..a229d35271 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -103,7 +103,6 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =
 void evtchn_2l_init(struct domain *d)
 {
     d->evtchn_port_ops = &evtchn_port_ops_2l;
-    d->max_evtchns = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 }
 
 /*
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 82e42c7e32..916fe19ec5 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -158,7 +158,7 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)
 
 int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 {
-    if ( port > d->max_evtchn_port || port >= d->max_evtchns )
+    if ( port > d->max_evtchn_port || port >= max_evtchns(d) )
         return -ENOSPC;
 
     if ( port_is_valid(d, port) )
@@ -1401,13 +1401,11 @@ static void domain_dump_evtchn_info(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    for ( port = 1; port < d->max_evtchns; ++port )
+    for ( port = 1; port_is_valid(d, port); ++port )
     {
         const struct evtchn *chn;
         char *ssid;
 
-        if ( !port_is_valid(d, port) )
-            continue;
         chn = evtchn_from_port(d, port);
         if ( chn->state == ECS_FREE )
             continue;
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 3f4c835518..397be25015 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -477,7 +477,7 @@ static void cleanup_event_array(struct domain *d)
     d->evtchn_fifo = NULL;
 }
 
-static void setup_ports(struct domain *d)
+static void setup_ports(struct domain *d, unsigned int prev_evtchns)
 {
     unsigned int port;
 
@@ -487,7 +487,7 @@ static void setup_ports(struct domain *d)
      * - save its pending state.
      * - set default priority.
      */
-    for ( port = 1; port < d->max_evtchns; port++ )
+    for ( port = 1; port < prev_evtchns; port++ )
     {
         struct evtchn *evtchn;
 
@@ -539,6 +539,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
     if ( !d->evtchn_fifo )
     {
         struct vcpu *vcb;
+        /* Latch the value before it changes during setup_event_array(). */
+        unsigned int prev_evtchns = max_evtchns(d);
 
         for_each_vcpu ( d, vcb ) {
             rc = setup_control_block(vcb);
@@ -555,8 +557,7 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control)
             goto error;
 
         d->evtchn_port_ops = &evtchn_port_ops_fifo;
-        d->max_evtchns = EVTCHN_FIFO_NR_CHANNELS;
-        setup_ports(d);
+        setup_ports(d, prev_evtchns);
     }
     else
         rc = map_control_block(v, gfn, offset);
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index f21c3e5a64..820126d82e 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -1002,7 +1002,7 @@ static long do_poll(struct sched_poll *sched_poll)
             goto out;
 
         rc = -EINVAL;
-        if ( port >= d->max_evtchns )
+        if ( !port_is_valid(d, port) )
             goto out;
 
         rc = 0;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 70bd63423e..357347369e 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -97,6 +97,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);
 #define bucket_from_port(d, p) \
     ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET])
 
+static inline unsigned int max_evtchns(const struct domain *d)
+{
+    return d->evtchn_fifo ? EVTCHN_FIFO_NR_CHANNELS
+                          : BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
+}
+
 static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= read_atomic(&d->valid_evtchns) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index eaa83dc97e..fb52bd1ab5 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -336,7 +336,6 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;     /* number supported by ABI */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:32 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:32 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkUy-0007TG-PV; Tue, 22 Sep 2020 15:46:32 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkUx-0007T6-Fc
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:31 +0000
X-Inumbo-ID: 73d99d8d-cd53-4114-910a-ab9f1b5c5f8a
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 73d99d8d-cd53-4114-910a-ab9f1b5c5f8a;
 Tue, 22 Sep 2020 15:46:30 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=imPabJB1EihXiJM8RGN2k/Ht5bQX6ioNRGREvFb30aQ=; b=Ket9lrCxwQkzWO0XSUnm8XdH3F
 b5hYkYJyhvrQEGm32c+j0xYhe8/MA+ebC5I/bQmJ2FZYGTdTS61APReZXc4dvIvxt+iz8BtkcqgWz
 gVS/Lc88voob64t3uKSF7B/FFY83iOlME6L19nfaGuHTrLi9IeloV6QdWLBbf4aitWmk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUw-0001XV-0A
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:30 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkUv-0007iB-VU
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:29 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: evtchn_reset() shouldn't succeed with
 still-open ports
Message-Id: <E1kKkUv-0007iB-VU@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:46:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7f0793a428cf6f38495e4e728b0346220250e57c
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:33:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:33:56 2020 +0200

    evtchn: evtchn_reset() shouldn't succeed with still-open ports
    
    While the function closes all ports, it does so without holding any
    lock, and hence racing requests may be issued causing new ports to get
    opened. This would have been problematic in particular if such a newly
    opened port had a port number above the new implementation limit (i.e.
    when switching from FIFO to 2-level) after the reset, as prior to
    "evtchn: relax port_is_valid()" this could have led to e.g.
    evtchn_close()'s "BUG_ON(!port_is_valid(d2, port2))" to trigger.
    
    Introduce a counter of active ports and check that it's (still) no
    larger then the number of Xen internally used ones after obtaining the
    necessary lock in evtchn_reset().
    
    As to the access model of the new {active,xen}_evtchns fields - while
    all writes get done using write_atomic(), reads ought to use
    read_atomic() only when outside of a suitably locked region.
    
    Note that as of now evtchn_bind_virq() and evtchn_bind_ipi() don't have
    a need to call check_free_port().
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 39 +++++++++++++++++++++++++++++++++------
 xen/include/xen/sched.h    | 10 ++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 916fe19ec5..f1aa3dbc5f 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -195,6 +195,8 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
         write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
     }
 
+    write_atomic(&d->active_evtchns, d->active_evtchns + 1);
+
     return 0;
 }
 
@@ -218,11 +220,26 @@ static int get_free_port(struct domain *d)
     return -ENOSPC;
 }
 
+/*
+ * Check whether a port is still marked free, and if so update the domain
+ * counter accordingly.  To be used on function exit paths.
+ */
+static void check_free_port(struct domain *d, evtchn_port_t port)
+{
+    if ( port_is_valid(d, port) &&
+         evtchn_from_port(d, port)->state == ECS_FREE )
+        write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+}
+
 void evtchn_free(struct domain *d, struct evtchn *chn)
 {
     /* Clear pending event to avoid unexpected behavior on re-bind. */
     evtchn_port_clear_pending(d, chn);
 
+    if ( consumer_is_xen(chn) )
+        write_atomic(&d->xen_evtchns, d->xen_evtchns - 1);
+    write_atomic(&d->active_evtchns, d->active_evtchns - 1);
+
     /* Reset binding to vcpu0 when the channel is freed. */
     chn->state          = ECS_FREE;
     chn->notify_vcpu_id = 0;
@@ -265,6 +282,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     alloc->port = port;
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
     rcu_unlock_domain(d);
 
@@ -358,6 +376,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     bind->local_port = lport;
 
  out:
+    check_free_port(ld, lport);
     spin_unlock(&ld->event_lock);
     if ( ld != rd )
         spin_unlock(&rd->event_lock);
@@ -491,7 +510,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct domain *d = current->domain;
     struct vcpu   *v = d->vcpu[0];
     struct pirq   *info;
-    int            port, pirq = bind->pirq;
+    int            port = 0, pirq = bind->pirq;
     long           rc;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
@@ -539,6 +558,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     arch_evtchn_bind_pirq(d, pirq);
 
  out:
+    check_free_port(d, port);
     spin_unlock(&d->event_lock);
 
     return rc;
@@ -1013,10 +1033,10 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-
 int evtchn_reset(struct domain *d)
 {
     unsigned int i;
+    int rc = 0;
 
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
@@ -1026,7 +1046,9 @@ int evtchn_reset(struct domain *d)
 
     spin_lock(&d->event_lock);
 
-    if ( d->evtchn_fifo )
+    if ( d->active_evtchns > d->xen_evtchns )
+        rc = -EAGAIN;
+    else if ( d->evtchn_fifo )
     {
         /* Switching back to 2-level ABI. */
         evtchn_fifo_destroy(d);
@@ -1035,7 +1057,7 @@ int evtchn_reset(struct domain *d)
 
     spin_unlock(&d->event_lock);
 
-    return 0;
+    return rc;
 }
 
 static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)
@@ -1221,10 +1243,9 @@ int alloc_unbound_xen_event_channel(
 
     spin_lock(&ld->event_lock);
 
-    rc = get_free_port(ld);
+    port = rc = get_free_port(ld);
     if ( rc < 0 )
         goto out;
-    port = rc;
     chn = evtchn_from_port(ld, port);
 
     rc = xsm_evtchn_unbound(XSM_TARGET, ld, chn, remote_domid);
@@ -1240,7 +1261,10 @@ int alloc_unbound_xen_event_channel(
 
     spin_unlock(&chn->lock);
 
+    write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
+
  out:
+    check_free_port(ld, port);
     spin_unlock(&ld->event_lock);
 
     return rc < 0 ? rc : port;
@@ -1316,6 +1340,7 @@ int evtchn_init(struct domain *d)
         return -EINVAL;
     }
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
+    write_atomic(&d->active_evtchns, 0);
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     d->poll_mask = xzalloc_array(unsigned long,
@@ -1343,6 +1368,8 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         evtchn_close(d, i, 0);
 
+    ASSERT(!d->active_evtchns);
+
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index fb52bd1ab5..f919b6b97a 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -338,6 +338,16 @@ struct domain
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
     unsigned int     max_evtchn_port; /* max permitted port number */
     unsigned int     valid_evtchns;   /* number of allocated event channels */
+    /*
+     * Number of in-use event channels.  Writers should use write_atomic().
+     * Readers need to use read_atomic() only when not holding event_lock.
+     */
+    unsigned int     active_evtchns;
+    /*
+     * Number of event channels used internally by Xen (not subject to
+     * EVTCHNOP_reset).  Read/write access like for active_evtchns.
+     */
+    unsigned int     xen_evtchns;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:41 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:41 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkV7-0007UJ-R1; Tue, 22 Sep 2020 15:46:41 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkV7-0007UC-7n
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:41 +0000
X-Inumbo-ID: 44e10adc-8cfc-4927-b183-52479cfa7965
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 44e10adc-8cfc-4927-b183-52479cfa7965;
 Tue, 22 Sep 2020 15:46:40 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=uicieWW4qycbLIdCMk0MLuWKYB6WwrWWdQiq3Vogqj4=; b=wg2XrYlNl1u0nMvx1DYucOQrCS
 /daYNv0OaZAhMe5ABslpu2UxespsJUpgGz2nwK4qZH3t/rKEPS1DZSjPltDsfpV91TNCw3fSknIrd
 Ab0B3s/xrnHwQEBku8U330h9ibX7y7iAeJEYLS3qVKuTBcsy5xewJ/nBmoHX9hF7e4qs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkV6-0001YH-3H
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:40 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkV6-0007j4-2a
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:40 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: convert per-channel lock to be IRQ-safe
Message-Id: <E1kKkV6-0007j4-2a@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:46:40 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit e081568d86b8a9dd09b34c8339f039b2bb78206b
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:34:30 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:34:30 2020 +0200

    evtchn: convert per-channel lock to be IRQ-safe
    
    ... in order for send_guest_{global,vcpu}_virq() to be able to make use
    of it.
    
    This is part of XSA-343.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/event_channel.c | 73 ++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index f1aa3dbc5f..cc0c90c7ee 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -255,6 +255,7 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     int            port;
     domid_t        dom = alloc->dom;
     long           rc;
+    unsigned long  flags;
 
     d = rcu_lock_domain_by_any_id(dom);
     if ( d == NULL )
@@ -270,14 +271,14 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     if ( (chn->u.unbound.remote_domid = alloc->remote_dom) == DOMID_SELF )
         chn->u.unbound.remote_domid = current->domain->domain_id;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     alloc->port = port;
 
@@ -290,26 +291,32 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 }
 
 
-static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn)
+static unsigned long double_evtchn_lock(struct evtchn *lchn,
+                                        struct evtchn *rchn)
 {
-    if ( lchn < rchn )
+    unsigned long flags;
+
+    if ( lchn <= rchn )
     {
-        spin_lock(&lchn->lock);
-        spin_lock(&rchn->lock);
+        spin_lock_irqsave(&lchn->lock, flags);
+        if ( lchn != rchn )
+            spin_lock(&rchn->lock);
     }
     else
     {
-        if ( lchn != rchn )
-            spin_lock(&rchn->lock);
+        spin_lock_irqsave(&rchn->lock, flags);
         spin_lock(&lchn->lock);
     }
+
+    return flags;
 }
 
-static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)
+static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn,
+                                 unsigned long flags)
 {
-    spin_unlock(&lchn->lock);
     if ( lchn != rchn )
-        spin_unlock(&rchn->lock);
+        spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&rchn->lock, flags);
 }
 
 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
@@ -319,6 +326,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     int            lport, rport = bind->remote_port;
     domid_t        rdom = bind->remote_dom;
     long           rc;
+    unsigned long  flags;
 
     if ( rdom == DOMID_SELF )
         rdom = current->domain->domain_id;
@@ -354,7 +362,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
     if ( rc )
         goto out;
 
-    double_evtchn_lock(lchn, rchn);
+    flags = double_evtchn_lock(lchn, rchn);
 
     lchn->u.interdomain.remote_dom  = rd;
     lchn->u.interdomain.remote_port = rport;
@@ -371,7 +379,7 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
      */
     evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);
 
-    double_evtchn_unlock(lchn, rchn);
+    double_evtchn_unlock(lchn, rchn, flags);
 
     bind->local_port = lport;
 
@@ -394,6 +402,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     struct domain *d = current->domain;
     int            virq = bind->virq, vcpu = bind->vcpu;
     int            rc = 0;
+    unsigned long  flags;
 
     if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
         return -EINVAL;
@@ -426,14 +435,14 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_VIRQ;
     chn->notify_vcpu_id = vcpu;
     chn->u.virq         = virq;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     v->virq_to_evtchn[virq] = bind->port = port;
 
@@ -450,6 +459,7 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
     struct domain *d = current->domain;
     int            port, vcpu = bind->vcpu;
     long           rc = 0;
+    unsigned long  flags;
 
     if ( (vcpu < 0) || (vcpu >= d->max_vcpus) ||
          (d->vcpu[vcpu] == NULL) )
@@ -462,13 +472,13 @@ static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind)
 
     chn = evtchn_from_port(d, port);
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state          = ECS_IPI;
     chn->notify_vcpu_id = vcpu;
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -512,6 +522,7 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
     struct pirq   *info;
     int            port = 0, pirq = bind->pirq;
     long           rc;
+    unsigned long  flags;
 
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
@@ -544,14 +555,14 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
         goto out;
     }
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state  = ECS_PIRQ;
     chn->u.pirq.irq = pirq;
     link_pirq_port(port, chn, v);
     evtchn_port_init(d, chn);
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     bind->port = port;
 
@@ -572,6 +583,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     struct evtchn *chn1, *chn2;
     int            port2;
     long           rc = 0;
+    unsigned long  flags;
 
  again:
     spin_lock(&d1->event_lock);
@@ -671,14 +683,14 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG_ON(chn2->state != ECS_INTERDOMAIN);
         BUG_ON(chn2->u.interdomain.remote_dom != d1);
 
-        double_evtchn_lock(chn1, chn2);
+        flags = double_evtchn_lock(chn1, chn2);
 
         evtchn_free(d1, chn1);
 
         chn2->state = ECS_UNBOUND;
         chn2->u.unbound.remote_domid = d1->domain_id;
 
-        double_evtchn_unlock(chn1, chn2);
+        double_evtchn_unlock(chn1, chn2, flags);
 
         goto out;
 
@@ -686,9 +698,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
         BUG();
     }
 
-    spin_lock(&chn1->lock);
+    spin_lock_irqsave(&chn1->lock, flags);
     evtchn_free(d1, chn1);
-    spin_unlock(&chn1->lock);
+    spin_unlock_irqrestore(&chn1->lock, flags);
 
  out:
     if ( d2 != NULL )
@@ -708,13 +720,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     struct evtchn *lchn, *rchn;
     struct domain *rd;
     int            rport, ret = 0;
+    unsigned long  flags;
 
     if ( !port_is_valid(ld, lport) )
         return -EINVAL;
 
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     /* Guest cannot send via a Xen-attached event channel. */
     if ( unlikely(consumer_is_xen(lchn)) )
@@ -749,7 +762,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)
     }
 
 out:
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 
     return ret;
 }
@@ -1240,6 +1253,7 @@ int alloc_unbound_xen_event_channel(
 {
     struct evtchn *chn;
     int            port, rc;
+    unsigned long  flags;
 
     spin_lock(&ld->event_lock);
 
@@ -1252,14 +1266,14 @@ int alloc_unbound_xen_event_channel(
     if ( rc )
         goto out;
 
-    spin_lock(&chn->lock);
+    spin_lock_irqsave(&chn->lock, flags);
 
     chn->state = ECS_UNBOUND;
     chn->xen_consumer = get_xen_consumer(notification_fn);
     chn->notify_vcpu_id = lvcpu;
     chn->u.unbound.remote_domid = remote_domid;
 
-    spin_unlock(&chn->lock);
+    spin_unlock_irqrestore(&chn->lock, flags);
 
     write_atomic(&ld->xen_evtchns, ld->xen_evtchns + 1);
 
@@ -1282,11 +1296,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 {
     struct evtchn *lchn, *rchn;
     struct domain *rd;
+    unsigned long flags;
 
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
 
-    spin_lock(&lchn->lock);
+    spin_lock_irqsave(&lchn->lock, flags);
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
@@ -1296,7 +1311,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
     }
 
-    spin_unlock(&lchn->lock);
+    spin_unlock_irqrestore(&lchn->lock, flags);
 }
 
 void evtchn_check_pollers(struct domain *d, unsigned int port)
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:46:54 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:46:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkVK-0007VS-Sw; Tue, 22 Sep 2020 15:46:54 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkVJ-0007VL-HB
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:53 +0000
X-Inumbo-ID: beee5e2a-011b-487c-9525-55499cf887af
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id beee5e2a-011b-487c-9525-55499cf887af;
 Tue, 22 Sep 2020 15:46:50 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=yDMnYvTu/FNJ28H/1rRQwQy7LHduSsvgBYBcqs7nunA=; b=ux7ZwEP2wJOgSNhMvrDGwCxHY9
 VKwuYljgIens/dcDr6r4kkntrOA2pOyildF5XfNVJ3D/0vyXYtT3tabde45FjAjR+AB5qwYybXJV1
 a7xjwdq9VXvFI5qT0TRUsT9GT06PxflHptFD31iGXR3fwv6ap8dB7j/fAHCsY4z3hx9E=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVG-0001YO-6W
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:50 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVG-0007jg-5q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:46:50 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: address races with evtchn_reset()
Message-Id: <E1kKkVG-0007jg-5q@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:46:50 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 83b7f04a4b59d578660d2dd9ca33ef8192019b42
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:34:52 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:34:52 2020 +0200

    evtchn: address races with evtchn_reset()
    
    Neither d->evtchn_port_ops nor max_evtchns(d) may be used in an entirely
    lock-less manner, as both may change by a racing evtchn_reset(). In the
    common case, at least one of the domain's event lock or the per-channel
    lock needs to be held. In the specific case of the inter-domain sending
    by evtchn_send() and notify_via_xen_event_channel() holding the other
    side's per-channel lock is sufficient, as the channel can't change state
    without both per-channel locks held. Without such a channel changing
    state, evtchn_reset() can't complete successfully.
    
    Lock-free accesses continue to be permitted for the shim (calling some
    otherwise internal event channel functions), as this happens while the
    domain is in effectively single-threaded mode. Special care also needs
    taking for the shim's marking of in-use ports as ECS_RESERVED (allowing
    use of such ports in the shim case is okay because switching into and
    hence also out of FIFO mode is impossihble there).
    
    As a side effect, certain operations on Xen bound event channels which
    were mistakenly permitted so far (e.g. unmask or poll) will be refused
    now.
    
    This is part of XSA-343.
    
    Reported-by: Julien Grall <jgrall@amazon.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/x86/irq.c          | 18 +++++++---
 xen/arch/x86/pv/shim.c      |  3 ++
 xen/common/event_2l.c       |  8 +++--
 xen/common/event_channel.c  | 23 ++++++++++---
 xen/common/event_fifo.c     | 15 ++++----
 xen/include/asm-x86/event.h |  6 ++++
 xen/include/xen/event.h     | 84 +++++++++++++++++++++++++++++++++++++--------
 7 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index 0d5253009f..01a678b5e2 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2323,14 +2323,24 @@ static void dump_irqs(unsigned char key)
 
             for ( i = 0; i < action->nr_guests; i++ )
             {
+                struct evtchn *evtchn;
+                unsigned int pending = 2, masked = 2;
+
                 d = action->guest[i];
                 pirq = domain_irq_to_pirq(d, irq);
                 info = pirq_info(d, pirq);
+                evtchn = evtchn_from_port(d, info->evtchn);
+                local_irq_disable();
+                if ( spin_trylock(&evtchn->lock) )
+                {
+                    pending = evtchn_is_pending(d, evtchn);
+                    masked = evtchn_is_masked(d, evtchn);
+                    spin_unlock(&evtchn->lock);
+                }
+                local_irq_enable();
                 printk("%u:%3d(%c%c%c)",
-                       d->domain_id, pirq,
-                       evtchn_port_is_pending(d, info->evtchn) ? 'P' : '-',
-                       evtchn_port_is_masked(d, info->evtchn) ? 'M' : '-',
-                       (info->masked ? 'M' : '-'));
+                       d->domain_id, pirq, "-P?"[pending],
+                       "-M?"[masked], info->masked ? 'M' : '-');
                 if ( i != action->nr_guests )
                     printk(",");
             }
diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c
index eb1ee7d3c4..973b2c31e4 100644
--- a/xen/arch/x86/pv/shim.c
+++ b/xen/arch/x86/pv/shim.c
@@ -603,8 +603,11 @@ void pv_shim_inject_evtchn(unsigned int port)
     if ( port_is_valid(guest, port) )
     {
         struct evtchn *chn = evtchn_from_port(guest, port);
+        unsigned long flags;
 
+        spin_lock_irqsave(&chn->lock, flags);
         evtchn_port_set_pending(guest, chn->notify_vcpu_id, chn);
+        spin_unlock_irqrestore(&chn->lock, flags);
     }
 }
 
diff --git a/xen/common/event_2l.c b/xen/common/event_2l.c
index a229d35271..083d04be3c 100644
--- a/xen/common/event_2l.c
+++ b/xen/common/event_2l.c
@@ -63,8 +63,10 @@ static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn)
     }
 }
 
-static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_pending(const struct domain *d,
+                                 const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
@@ -72,8 +74,10 @@ static bool evtchn_2l_is_pending(const struct domain *d, evtchn_port_t port)
             guest_test_bit(d, port, &shared_info(d, evtchn_pending)));
 }
 
-static bool evtchn_2l_is_masked(const struct domain *d, evtchn_port_t port)
+static bool evtchn_2l_is_masked(const struct domain *d,
+                                const struct evtchn *evtchn)
 {
+    evtchn_port_t port = evtchn->port;
     unsigned int max_ports = BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d);
 
     ASSERT(port < max_ports);
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index cc0c90c7ee..9bc9a61a0e 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -163,8 +163,9 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_t port)
 
     if ( port_is_valid(d, port) )
     {
-        if ( evtchn_from_port(d, port)->state != ECS_FREE ||
-             evtchn_port_is_busy(d, port) )
+        const struct evtchn *chn = evtchn_from_port(d, port);
+
+        if ( chn->state != ECS_FREE || evtchn_is_busy(d, chn) )
             return -EBUSY;
     }
     else
@@ -777,6 +778,7 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     unsigned long flags;
     int port;
     struct domain *d;
+    struct evtchn *chn;
 
     ASSERT(!virq_is_global(virq));
 
@@ -787,7 +789,10 @@ void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
         goto out;
 
     d = v->domain;
-    evtchn_port_set_pending(d, v->vcpu_id, evtchn_from_port(d, port));
+    chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
+    evtchn_port_set_pending(d, v->vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -816,7 +821,9 @@ static void send_guest_global_virq(struct domain *d, uint32_t virq)
         goto out;
 
     chn = evtchn_from_port(d, port);
+    spin_lock(&chn->lock);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock(&chn->lock);
 
  out:
     spin_unlock_irqrestore(&v->virq_lock, flags);
@@ -826,6 +833,7 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
 {
     int port;
     struct evtchn *chn;
+    unsigned long flags;
 
     /*
      * PV guests: It should not be possible to race with __evtchn_close(). The
@@ -840,7 +848,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)
     }
 
     chn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&chn->lock, flags);
     evtchn_port_set_pending(d, chn->notify_vcpu_id, chn);
+    spin_unlock_irqrestore(&chn->lock, flags);
 }
 
 static struct domain *global_virq_handlers[NR_VIRQS] __read_mostly;
@@ -1036,12 +1046,15 @@ int evtchn_unmask(unsigned int port)
 {
     struct domain *d = current->domain;
     struct evtchn *evtchn;
+    unsigned long flags;
 
     if ( unlikely(!port_is_valid(d, port)) )
         return -EINVAL;
 
     evtchn = evtchn_from_port(d, port);
+    spin_lock_irqsave(&evtchn->lock, flags);
     evtchn_port_unmask(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
 
     return 0;
 }
@@ -1454,8 +1467,8 @@ static void domain_dump_evtchn_info(struct domain *d)
 
         printk("    %4u [%d/%d/",
                port,
-               evtchn_port_is_pending(d, port),
-               evtchn_port_is_masked(d, port));
+               evtchn_is_pending(d, chn),
+               evtchn_is_masked(d, chn));
         evtchn_port_print_state(d, chn);
         printk("]: s=%d n=%d x=%d",
                chn->state, chn->notify_vcpu_id, chn->xen_consumer);
diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index 397be25015..45c024739d 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -295,23 +295,26 @@ static void evtchn_fifo_unmask(struct domain *d, struct evtchn *evtchn)
         evtchn_fifo_set_pending(v, evtchn);
 }
 
-static bool evtchn_fifo_is_pending(const struct domain *d, evtchn_port_t port)
+static bool evtchn_fifo_is_pending(const struct domain *d,
+                                   const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_PENDING, word);
 }
 
-static bool_t evtchn_fifo_is_masked(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return !word || guest_test_bit(d, EVTCHN_FIFO_MASKED, word);
 }
 
-static bool_t evtchn_fifo_is_busy(const struct domain *d, evtchn_port_t port)
+static bool_t evtchn_fifo_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
-    const event_word_t *word = evtchn_fifo_word_from_port(d, port);
+    const event_word_t *word = evtchn_fifo_word_from_port(d, evtchn->port);
 
     return word && guest_test_bit(d, EVTCHN_FIFO_LINKED, word);
 }
diff --git a/xen/include/asm-x86/event.h b/xen/include/asm-x86/event.h
index a91599d0ec..717c1fd2e6 100644
--- a/xen/include/asm-x86/event.h
+++ b/xen/include/asm-x86/event.h
@@ -47,4 +47,10 @@ static inline int arch_virq_is_global(uint32_t virq)
     return 1;
 }
 
+#ifdef CONFIG_PV_SHIM
+# include <asm/pv/shim.h>
+# define arch_evtchn_is_special(chn) \
+             (pv_shim && (chn)->port && (chn)->state == ECS_RESERVED)
+#endif
+
 #endif
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 357347369e..26ad429520 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -125,6 +125,24 @@ static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
     return bucket_from_port(d, p) + (p % EVTCHNS_PER_BUCKET);
 }
 
+/*
+ * "usable" as in "by a guest", i.e. Xen consumed channels are assumed to be
+ * taken care of separately where used for Xen's internal purposes.
+ */
+static bool evtchn_usable(const struct evtchn *evtchn)
+{
+    if ( evtchn->xen_consumer )
+        return false;
+
+#ifdef arch_evtchn_is_special
+    if ( arch_evtchn_is_special(evtchn) )
+        return true;
+#endif
+
+    BUILD_BUG_ON(ECS_FREE > ECS_RESERVED);
+    return evtchn->state > ECS_RESERVED;
+}
+
 /* Wait on a Xen-attached event channel. */
 #define wait_on_xen_event_channel(port, condition)                      \
     do {                                                                \
@@ -157,19 +175,24 @@ int evtchn_reset(struct domain *d);
 
 /*
  * Low-level event channel port ops.
+ *
+ * All hooks have to be called with a lock held which prevents the channel
+ * from changing state. This may be the domain event lock, the per-channel
+ * lock, or in the case of sending interdomain events also the other side's
+ * per-channel lock. Exceptions apply in certain cases for the PV shim.
  */
 struct evtchn_port_ops {
     void (*init)(struct domain *d, struct evtchn *evtchn);
     void (*set_pending)(struct vcpu *v, struct evtchn *evtchn);
     void (*clear_pending)(struct domain *d, struct evtchn *evtchn);
     void (*unmask)(struct domain *d, struct evtchn *evtchn);
-    bool (*is_pending)(const struct domain *d, evtchn_port_t port);
-    bool (*is_masked)(const struct domain *d, evtchn_port_t port);
+    bool (*is_pending)(const struct domain *d, const struct evtchn *evtchn);
+    bool (*is_masked)(const struct domain *d, const struct evtchn *evtchn);
     /*
      * Is the port unavailable because it's still being cleaned up
      * after being closed?
      */
-    bool (*is_busy)(const struct domain *d, evtchn_port_t port);
+    bool (*is_busy)(const struct domain *d, const struct evtchn *evtchn);
     int (*set_priority)(struct domain *d, struct evtchn *evtchn,
                         unsigned int priority);
     void (*print_state)(struct domain *d, const struct evtchn *evtchn);
@@ -185,38 +208,67 @@ static inline void evtchn_port_set_pending(struct domain *d,
                                            unsigned int vcpu_id,
                                            struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->set_pending(d->vcpu[vcpu_id], evtchn);
 }
 
 static inline void evtchn_port_clear_pending(struct domain *d,
                                              struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->clear_pending(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->clear_pending(d, evtchn);
 }
 
 static inline void evtchn_port_unmask(struct domain *d,
                                       struct evtchn *evtchn)
 {
-    d->evtchn_port_ops->unmask(d, evtchn);
+    if ( evtchn_usable(evtchn) )
+        d->evtchn_port_ops->unmask(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(const struct domain *d,
-                                          evtchn_port_t port)
+static inline bool evtchn_is_pending(const struct domain *d,
+                                     const struct evtchn *evtchn)
 {
-    return d->evtchn_port_ops->is_pending(d, port);
+    return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_masked(const struct domain *d,
-                                         evtchn_port_t port)
+static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
 {
-    return d->evtchn_port_ops->is_masked(d, port);
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_pending(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
+}
+
+static inline bool evtchn_is_masked(const struct domain *d,
+                                    const struct evtchn *evtchn)
+{
+    return !evtchn_usable(evtchn) || d->evtchn_port_ops->is_masked(d, evtchn);
+}
+
+static inline bool evtchn_port_is_masked(struct domain *d, evtchn_port_t port)
+{
+    struct evtchn *evtchn = evtchn_from_port(d, port);
+    bool rc;
+    unsigned long flags;
+
+    spin_lock_irqsave(&evtchn->lock, flags);
+    rc = evtchn_is_masked(d, evtchn);
+    spin_unlock_irqrestore(&evtchn->lock, flags);
+
+    return rc;
 }
 
-static inline bool evtchn_port_is_busy(const struct domain *d,
-                                       evtchn_port_t port)
+static inline bool evtchn_is_busy(const struct domain *d,
+                                  const struct evtchn *evtchn)
 {
     return d->evtchn_port_ops->is_busy &&
-           d->evtchn_port_ops->is_busy(d, port);
+           d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
 static inline int evtchn_port_set_priority(struct domain *d,
@@ -225,6 +277,8 @@ static inline int evtchn_port_set_priority(struct domain *d,
 {
     if ( !d->evtchn_port_ops->set_priority )
         return -ENOSYS;
+    if ( !evtchn_usable(evtchn) )
+        return -EACCES;
     return d->evtchn_port_ops->set_priority(d, evtchn, priority);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:47:02 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:47:02 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkVR-0007WL-W7; Tue, 22 Sep 2020 15:47:01 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkVR-0007WF-7E
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:01 +0000
X-Inumbo-ID: 83b00d66-c776-4a26-8b76-e0c2a6e25f93
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 83b00d66-c776-4a26-8b76-e0c2a6e25f93;
 Tue, 22 Sep 2020 15:47:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=65Q8YjgiykQzSYX4cZMpYdKoCSEP8V1uGGMfXSjT7NA=; b=ib6dG5zLpAHFYDFZ9xaZm1Q1L2
 SDmwKU0yihp4eqGmEuU4q0tTsQTicRTsAdxyFG2KiAZN05JMQ6S7cqiIcwJIJeD4qnuhBoGSfo9Sk
 ehx3uU/jHnrNXp/HXsorGl6d7wdJRQtZQhahUmVBIRmeB/lOF6O8ofClqhsuhDLk6JKA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVQ-0001YW-9g
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:00 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVQ-0007kT-8y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:00 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: arrange for preemption in evtchn_destroy()
Message-Id: <E1kKkVQ-0007kT-8y@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:47:00 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f2befb6839818f1dbb2e2f5e3a8075bcaf563778
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:35:15 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:35:15 2020 +0200

    evtchn: arrange for preemption in evtchn_destroy()
    
    Especially closing of fully established interdomain channels can take
    quite some time, due to the locking involved. Therefore we shouldn't
    assume we can clean up still active ports all in one go. Besides adding
    the necessary preemption check, also avoid pointlessly starting from
    (or now really ending at) 0; 1 is the lowest numbered port which may
    need closing.
    
    Since we're now reducing ->valid_evtchns, free_xen_event_channel(),
    and (at least to be on the safe side) notify_via_xen_event_channel()
    need to cope with attempts to close / unbind from / send through already
    closed (and no longer valid, as per port_is_valid()) ports.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c        |  4 +++-
 xen/common/event_channel.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 xen/include/xen/sched.h    |  2 +-
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 15529d768b..8833261357 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -626,7 +626,6 @@ int domain_kill(struct domain *d)
         domain_pause(d);
         d->is_dying = DOMDYING_dying;
         spin_barrier(&d->domain_lock);
-        evtchn_destroy(d);
         gnttab_release_mappings(d);
         tmem_destroy(d->tmem_client);
         vnuma_destroy(d->vnuma);
@@ -634,6 +633,9 @@ int domain_kill(struct domain *d)
         d->tmem_client = NULL;
         /* fallthrough */
     case DOMDYING_dying:
+        rc = evtchn_destroy(d);
+        if ( rc )
+            break;
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
             break;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 9bc9a61a0e..aca5e85c59 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1299,7 +1299,16 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    BUG_ON(!port_is_valid(d, port));
+    if ( !port_is_valid(d, port) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        BUG_ON(!d->is_dying);
+        return;
+    }
 
     evtchn_close(d, port, 0);
 }
@@ -1311,7 +1320,17 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
     struct domain *rd;
     unsigned long flags;
 
-    ASSERT(port_is_valid(ld, lport));
+    if ( !port_is_valid(ld, lport) )
+    {
+        /*
+         * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing
+         * with the spin_barrier() and BUG_ON() in evtchn_destroy().
+         */
+        smp_rmb();
+        ASSERT(ld->is_dying);
+        return;
+    }
+
     lchn = evtchn_from_port(ld, lport);
 
     spin_lock_irqsave(&lchn->lock, flags);
@@ -1383,8 +1402,7 @@ int evtchn_init(struct domain *d)
     return 0;
 }
 
-
-void evtchn_destroy(struct domain *d)
+int evtchn_destroy(struct domain *d)
 {
     unsigned int i;
 
@@ -1393,14 +1411,29 @@ void evtchn_destroy(struct domain *d)
     spin_barrier(&d->event_lock);
 
     /* Close all existing event channels. */
-    for ( i = 0; port_is_valid(d, i); i++ )
+    for ( i = d->valid_evtchns; --i; )
+    {
         evtchn_close(d, i, 0);
 
+        /*
+         * Avoid preempting when called from domain_create()'s error path,
+         * and don't check too often (choice of frequency is arbitrary).
+         */
+        if ( i && !(i & 0x3f) && d->is_dying != DOMDYING_dead &&
+             hypercall_preempt_check() )
+        {
+            write_atomic(&d->valid_evtchns, i);
+            return -ERESTART;
+        }
+    }
+
     ASSERT(!d->active_evtchns);
 
     clear_global_virq_handlers(d);
 
     evtchn_fifo_destroy(d);
+
+    return 0;
 }
 
 
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index f919b6b97a..707e655ecc 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -134,7 +134,7 @@ struct evtchn
 } __attribute__((aligned(64)));
 
 int  evtchn_init(struct domain *d); /* from domain_create */
-void evtchn_destroy(struct domain *d); /* from domain_kill */
+int  evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
 struct waitqueue_vcpu;
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 15:47:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 15:47:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKkVd-0007Xb-1V; Tue, 22 Sep 2020 15:47:13 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKkVb-0007XS-J4
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:11 +0000
X-Inumbo-ID: 1f52c3cd-8bb0-4a53-b1ca-7506c2cf0418
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1f52c3cd-8bb0-4a53-b1ca-7506c2cf0418;
 Tue, 22 Sep 2020 15:47:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=NbzsyIcUjTdYzXWDFBwcWh/1wcultANdj1zbZHVkW2U=; b=m9CaKiIafe5eV7dSrFUy7ZbZVb
 8a9wWfdA/ScTYqEMmKKEI0m/A3a7Vy9FZW4yNyJciDOx7G5CfzkPFP/QfLBKFU13SvOaMp6DwokOw
 o1irYYekm5MmjfEdN1hx0aKXckdyr5M6Tah6SBRzc1kjYCf7otCGdT/A0rZSsu3duoQo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVa-0001Yw-Cp
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:10 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKkVa-0007l6-C4
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 15:47:10 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging-4.10] evtchn: arrange for preemption in evtchn_reset()
Message-Id: <E1kKkVa-0007l6-C4@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 15:47:10 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f58caa40cd8c2a3dbed705d90b6a22facc281afb
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 22 17:35:56 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 22 17:35:56 2020 +0200

    evtchn: arrange for preemption in evtchn_reset()
    
    Like for evtchn_destroy() looping over all possible event channels to
    close them can take a significant amount of time. Unlike done there, we
    can't alter domain properties (i.e. d->valid_evtchns) here. Borrow, in a
    lightweight form, the paging domctl continuation concept, redirecting
    the continuations to different sub-ops. Just like there this is to be
    able to allow for predictable overall results of the involved sub-ops:
    Racing requests should either complete or be refused.
    
    Note that a domain can't interfere with an already started (by a remote
    domain) reset, due to being paused. It can prevent a remote reset from
    happening by leaving a reset unfinished, but that's only going to affect
    itself.
    
    This is part of XSA-344.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/common/domain.c                |  4 ++--
 xen/common/domctl.c                | 12 ++++++++++-
 xen/common/event_channel.c         | 42 ++++++++++++++++++++++++++++++++++----
 xen/include/public/domctl.h        |  5 ++++-
 xen/include/public/event_channel.h |  3 +++
 xen/include/xen/event.h            |  2 +-
 xen/include/xen/sched.h            |  4 +++-
 7 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 8833261357..b187fbb220 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1086,7 +1086,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
-int domain_soft_reset(struct domain *d)
+int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
     int rc;
@@ -1100,7 +1100,7 @@ int domain_soft_reset(struct domain *d)
         }
     spin_unlock(&d->shutdown_lock);
 
-    rc = evtchn_reset(d);
+    rc = evtchn_reset(d, resuming);
     if ( rc )
         return rc;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index a70f4b46f8..f66fbbc110 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -666,12 +666,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     }
 
     case XEN_DOMCTL_soft_reset:
+    case XEN_DOMCTL_soft_reset_cont:
         if ( d == current->domain ) /* no domain_pause() */
         {
             ret = -EINVAL;
             break;
         }
-        ret = domain_soft_reset(d);
+        ret = domain_soft_reset(d, op->cmd == XEN_DOMCTL_soft_reset_cont);
+        if ( ret == -ERESTART )
+        {
+            op->cmd = XEN_DOMCTL_soft_reset_cont;
+            if ( !__copy_field_to_guest(u_domctl, op, cmd) )
+                ret = hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                    "h", u_domctl);
+            else
+                ret = -EFAULT;
+        }
         break;
 
     case XEN_DOMCTL_destroydomain:
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index aca5e85c59..b41096a65f 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1059,7 +1059,7 @@ int evtchn_unmask(unsigned int port)
     return 0;
 }
 
-int evtchn_reset(struct domain *d)
+int evtchn_reset(struct domain *d, bool resuming)
 {
     unsigned int i;
     int rc = 0;
@@ -1067,11 +1067,40 @@ int evtchn_reset(struct domain *d)
     if ( d != current->domain && !d->controller_pause_count )
         return -EINVAL;
 
-    for ( i = 0; port_is_valid(d, i); i++ )
+    spin_lock(&d->event_lock);
+
+    /*
+     * If we are resuming, then start where we stopped. Otherwise, check
+     * that a reset operation is not already in progress, and if none is,
+     * record that this is now the case.
+     */
+    i = resuming ? d->next_evtchn : !d->next_evtchn;
+    if ( i > d->next_evtchn )
+        d->next_evtchn = i;
+
+    spin_unlock(&d->event_lock);
+
+    if ( !i )
+        return -EBUSY;
+
+    for ( ; port_is_valid(d, i); i++ )
+    {
         evtchn_close(d, i, 1);
 
+        /* NB: Choice of frequency is arbitrary. */
+        if ( !(i & 0x3f) && hypercall_preempt_check() )
+        {
+            spin_lock(&d->event_lock);
+            d->next_evtchn = i;
+            spin_unlock(&d->event_lock);
+            return -ERESTART;
+        }
+    }
+
     spin_lock(&d->event_lock);
 
+    d->next_evtchn = 0;
+
     if ( d->active_evtchns > d->xen_evtchns )
         rc = -EAGAIN;
     else if ( d->evtchn_fifo )
@@ -1206,7 +1235,8 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
-    case EVTCHNOP_reset: {
+    case EVTCHNOP_reset:
+    case EVTCHNOP_reset_cont: {
         struct evtchn_reset reset;
         struct domain *d;
 
@@ -1219,9 +1249,13 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         rc = xsm_evtchn_reset(XSM_TARGET, current->domain, d);
         if ( !rc )
-            rc = evtchn_reset(d);
+            rc = evtchn_reset(d, cmd == EVTCHNOP_reset_cont);
 
         rcu_unlock_domain(d);
+
+        if ( rc == -ERESTART )
+            rc = hypercall_create_continuation(__HYPERVISOR_event_channel_op,
+                                               "ih", EVTCHNOP_reset_cont, arg);
         break;
     }
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 463f8cc420..1ad0a2353e 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1130,7 +1130,10 @@ struct xen_domctl {
 #define XEN_DOMCTL_iomem_permission              20
 #define XEN_DOMCTL_ioport_permission             21
 #define XEN_DOMCTL_hypercall_init                22
-#define XEN_DOMCTL_arch_setup                    23 /* Obsolete IA64 only */
+#ifdef __XEN__
+/* #define XEN_DOMCTL_arch_setup                 23 Obsolete IA64 only */
+#define XEN_DOMCTL_soft_reset_cont               23
+#endif
 #define XEN_DOMCTL_settimeoffset                 24
 #define XEN_DOMCTL_getvcpuaffinity               25
 #define XEN_DOMCTL_real_mode_area                26 /* Obsolete PPC only */
diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_channel.h
index 44c549dd6b..a1949191c6 100644
--- a/xen/include/public/event_channel.h
+++ b/xen/include/public/event_channel.h
@@ -74,6 +74,9 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#ifdef __XEN__
+#define EVTCHNOP_reset_cont      14
+#endif
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 26ad429520..87a4aade86 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -171,7 +171,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port);
 void evtchn_2l_init(struct domain *d);
 
 /* Close all event channels and reset to 2-level ABI. */
-int evtchn_reset(struct domain *d);
+int evtchn_reset(struct domain *d, bool resuming);
 
 /*
  * Low-level event channel port ops.
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 707e655ecc..0a13b81c21 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -348,6 +348,8 @@ struct domain
      * EVTCHNOP_reset).  Read/write access like for active_evtchns.
      */
     unsigned int     xen_evtchns;
+    /* Port to resume from in evtchn_reset(), when in a continuation. */
+    unsigned int     next_evtchn;
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
@@ -616,7 +618,7 @@ int domain_shutdown(struct domain *d, u8 reason);
 void domain_resume(struct domain *d);
 void domain_pause_for_debugger(void);
 
-int domain_soft_reset(struct domain *d);
+int domain_soft_reset(struct domain *d, bool resuming);
 
 int vcpu_start_shutdown_deferral(struct vcpu *v);
 void vcpu_end_shutdown_deferral(struct vcpu *v);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 16:33:10 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 16:33:10 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKlE1-0004vi-Ox; Tue, 22 Sep 2020 16:33:05 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKlE0-0004vb-A8
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:04 +0000
X-Inumbo-ID: eb4c76cd-7d31-48ed-a8ea-2a08ee154b08
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eb4c76cd-7d31-48ed-a8ea-2a08ee154b08;
 Tue, 22 Sep 2020 16:33:02 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=uQfZfQDThDdR3uGWZ/OcMIy3caTTz8lCkt1enj11WXY=; b=uDlt6DrtnRU/QOvsN2xyF7770T
 pH0e9AV+noY1420ZkNY6kJB8+CLAFBufZhHNALJCzGnw4egusghVcYz/yyuH2H68eCyiit07IfrN9
 q8rdHIziSBdYXSzAfaI+RrAy0gS7n8M9Zrbxh09KBtbKY9uhqx3lYZVpiszUfQhCMGVk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlDy-00033X-Ja
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:02 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlDy-0002OY-Gs
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:02 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] arm: Add Neoverse N1 processor identification
Message-Id: <E1kKlDy-0002OY-Gs@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 16:33:02 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 81564c40ead9781c30baf30cb4cf2fbf242a0818
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:38 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:27:58 2020 -0700

    arm: Add Neoverse N1 processor identification
    
    Add MIDR and CPU part numbers for Neoverse N1
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 3b418b33265402aab0cb1bf2b745a25724bae2d8)
---
 xen/include/asm-arm/processor.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
index 783f033813..04838fe6fc 100644
--- a/xen/include/asm-arm/processor.h
+++ b/xen/include/asm-arm/processor.h
@@ -53,6 +53,7 @@
 #define ARM_CPU_PART_CORTEX_A73     0xD09
 #define ARM_CPU_PART_CORTEX_A75     0xD0A
 #define ARM_CPU_PART_CORTEX_A76     0xD0B
+#define ARM_CPU_PART_NEOVERSE_N1    0xD0C
 
 #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12)
 #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17)
@@ -63,6 +64,7 @@
 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
+#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
 
 /* MPIDR Multiprocessor Affinity Register */
 #define _MPIDR_UP           (30)
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 16:33:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 16:33:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKlEB-0004wL-QT; Tue, 22 Sep 2020 16:33:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKlEA-0004wD-Ak
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:14 +0000
X-Inumbo-ID: 0c3bddad-0121-4ffe-97f8-7f185e55259c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 0c3bddad-0121-4ffe-97f8-7f185e55259c;
 Tue, 22 Sep 2020 16:33:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Szee/sWbz4eZiMnESseJxA2MOik8L/u44gogro5uoqY=; b=OLqieUmDkn5E3dFPGWVN/lgdPc
 C6ThXNrEc4tQit6np91IOrEQqRgtFqjg6lMZvACO9pPp6bhVj47tLj48IaOS1JqaChzOt8SHIrShS
 0LZj2Fe1DQapHSHtGF1ZLeSNfN8s7ENiPB0rVC29nQotpQrYKVddgF5dRHsUgPXO0icw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlE8-00033b-V1
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:12 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlE8-0002PQ-Lz
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:12 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] xen/arm: Enable CPU Erratum 1165522 for Neoverse
Message-Id: <E1kKlE8-0002PQ-Lz@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 16:33:12 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 76d934929b6d91b886afbc45deaac95bfc90457a
Author:     Bertrand Marquis <bertrand.marquis@arm.com>
AuthorDate: Tue Aug 18 14:47:39 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:03 2020 -0700

    xen/arm: Enable CPU Erratum 1165522 for Neoverse
    
    Enable CPU erratum of Speculative AT on the Neoverse N1 processor
    versions r0p0 to r2p0.
    Also Fix Cortex A76 Erratum string which had a wrong errata number.
    
    Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 858c0be8c2fa4125a0fa0acaa03ae730e5c7cb3c)
---
 xen/arch/arm/cpuerrata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c
index edbe789736..b254b98657 100644
--- a/xen/arch/arm/cpuerrata.c
+++ b/xen/arch/arm/cpuerrata.c
@@ -489,9 +489,15 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .matches = has_ssbd_mitigation,
     },
 #endif
+    {
+        /* Neoverse r0p0 - r2p0 */
+        .desc = "ARM erratum 1165522",
+        .capability = ARM64_WORKAROUND_AT_SPECULATE,
+        MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 2 << MIDR_VARIANT_SHIFT),
+    },
     {
         /* Cortex-A76 r0p0 - r2p0 */
-        .desc = "ARM erratum 116522",
+        .desc = "ARM erratum 1165522",
         .capability = ARM64_WORKAROUND_AT_SPECULATE,
         MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT),
     },
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 16:33:24 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 16:33:24 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKlEK-0004xp-S3; Tue, 22 Sep 2020 16:33:24 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKlEJ-0004xg-VM
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:23 +0000
X-Inumbo-ID: cf65752e-2ba2-4e90-9b3b-9a4994377f39
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id cf65752e-2ba2-4e90-9b3b-9a4994377f39;
 Tue, 22 Sep 2020 16:33:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=cnJrc6LfjonJzlYO9fFGdyRMf3pRRHImprW3jEd8Nmo=; b=nMLRE+Bbf9Jwi5OPfWqBTpHxWd
 OZUYI/96mnYeOy0KIwbrjpZId//1y0V4wJQQS7+r+fMTEb8E0YO45LBqOTQYxM33PPIO6ThWEs5Y3
 V4JObiK4m49qqcoyUVrvQ5Vm6dFymgEna8AmNuGac1B3i5sB+j1wRearLBoth7lEi8R8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlEJ-00033r-3Q
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlEJ-0002Q7-0y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] xen/arm: Update silicon-errata.txt with the Neovers
 AT erratum
Message-Id: <E1kKlEJ-0002Q7-0y@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 16:33:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit caebaf3751e169af15f494bcbbdbfc0ae37648ba
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Aug 25 18:38:10 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:07 2020 -0700

    xen/arm: Update silicon-errata.txt with the Neovers AT erratum
    
    Commit 858c0be8c2fa "xen/arm: Enable CPU Erratum 1165522 for Neoverse"
    added a new erratum but forgot to update silicon-errata.txt.
    
    Update the file accordingly to keep track of errata workaround in Xen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    (cherry picked from commit 1814a626fb5811184eda64fe22f0055df4600211)
---
 docs/misc/arm/silicon-errata.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt
index 11e5a9dcec..e15d0923e9 100644
--- a/docs/misc/arm/silicon-errata.txt
+++ b/docs/misc/arm/silicon-errata.txt
@@ -51,4 +51,5 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
+| ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 16:33:35 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 16:33:35 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKlEV-0004zj-6C; Tue, 22 Sep 2020 16:33:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKlEU-0004zQ-5y
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:34 +0000
X-Inumbo-ID: 52982233-6fbf-4aa8-b357-b5a9defd1c72
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 52982233-6fbf-4aa8-b357-b5a9defd1c72;
 Tue, 22 Sep 2020 16:33:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=MkkWIYq7ENuTYLW2QXvtz2/PrThcEHOu5WH0yTCdciY=; b=Q+NEJO8JjhQPaQBYQbsdNpW/vq
 8Fr6WYRssOCBiTMjo3Jdz1k01StErM1Gk25pSSQrCUQxBQCGvJp3syogrgNnbMGGOmxOG0m8/E916
 6dtEAHM8ydeoKMVgaNrw1rtCh7lOHDGAOtMQd/r9N88zTWYhdRFu6fk8Mw0IavBbuqH8=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlET-000341-8D
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlET-0002Qm-5b
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] xen/arm: Missing N1/A76/A75 FP registers in vCPU
 context switch
Message-Id: <E1kKlET-0002Qm-5b@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 16:33:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a81e6557b9864e4288a63cbbbd3a6f98d3a74862
Author:     Wei Chen <wei.chen@arm.com>
AuthorDate: Fri Aug 28 02:34:03 2020 +0000
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:12 2020 -0700

    xen/arm: Missing N1/A76/A75 FP registers in vCPU context switch
    
    Xen has cpu_has_fp/cpu_has_simd to detect whether the CPU supports
    FP/SIMD or not. But currently, these two MACROs only consider value 0
    of ID_AA64PFR0_EL1.FP/SIMD as FP/SIMD features enabled. But for CPUs
    that support FP/SIMD and half-precision floating-point arithmetic, the
    ID_AA64PFR0_EL1.FP/SIMD are 1 (see Arm ARM DDI0487F.b, D13.2.64).
    For these CPUs, xen will treat them as no FP/SIMD support, the
    vfp_save/restore_state will not take effect.
    
    From the TRM documents of Cortex-A75/A76/N1, we know these CPUs support
    basic Advanced SIMD/FP and half-precision floating-point arithmetic. In
    this case, on N1/A76/A75 platforms, Xen will always miss the floating
    pointer registers save/restore. If different vCPUs are running on the
    same pCPU, the floating pointer registers will be corrupted randomly.
    
    This patch fixes Xen on these new cores.
    
    Signed-off-by: Wei Chen <wei.chen@arm.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    (cherry picked from commit 968bb86d04913f52d7678a842474f2a674a8b23e)
---
 xen/include/asm-arm/cpufeature.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index a7b726d863..60e677d842 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -13,8 +13,8 @@
 #define cpu_has_el2_64    (boot_cpu_feature64(el2) >= 1)
 #define cpu_has_el3_32    (boot_cpu_feature64(el3) == 2)
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
-#define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
-#define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_fp        (boot_cpu_feature64(fp) < 8)
+#define cpu_has_simd      (boot_cpu_feature64(simd) < 8)
 #define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Tue Sep 22 16:33:45 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 22 Sep 2020 16:33:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKlEf-00051W-93; Tue, 22 Sep 2020 16:33:45 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=BH3M=C7=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKlEe-00051E-5e
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:44 +0000
X-Inumbo-ID: b7746a66-4d8c-40ac-86e3-0eee642af6e2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id b7746a66-4d8c-40ac-86e3-0eee642af6e2;
 Tue, 22 Sep 2020 16:33:43 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=c97EMyDuHSMSf+6B5vQMAjX/7xn3SgsqRDc9MpdFRUk=; b=trvJnwAQE4cTv3w8je/JRK1qae
 wMQYdLqP1kavdQT25jFX7KsP9gKsuFfiTKgMa35d8cH/pqJm5b4IEjJKVRcbC04upIcU/lQpMJq/Q
 np0Gd1DRtrkG/0BTyOkU2lJoayO6ObhCTB2qzcX31MHnl+Y3igIZk4H/AMGMNUr2qsh4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlEd-00034c-BD
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKlEd-0002RO-AJ
 for xen-changelog@lists.xenproject.org; Tue, 22 Sep 2020 16:33:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen stable-4.12] xen/arm: cmpxchg: Add missing memory barriers in
 __cmpxchg_mb_timeout()
Message-Id: <E1kKlEd-0002RO-AJ@xenbits.xenproject.org>
Date: Tue, 22 Sep 2020 16:33:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 0446e3db13671032b05d19f6117d902f5c5c76fa
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Jul 29 14:50:37 2020 +0100
Commit:     Stefano Stabellini <sstabellini@kernel.org>
CommitDate: Mon Sep 14 17:28:23 2020 -0700

    xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()
    
    The function __cmpxchg_mb_timeout() was intended to have the same
    semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were
    not added when first implemented.
    
    There is no known issue with the existing callers, but the barriers are
    added given this is the expected semantics in Xen.
    
    The issue was introduced by XSA-295.
    
    Backport: 4.8+
    Fixes: 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    (cherry picked from commit d501ef90ae7f2a79130ea89acb3d6d1792972934)
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 49ca2a0d7a..0770f272ee 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index 5bc2e1f786..fc5c60f0bd 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.12


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:15 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:15 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxkD-0004rD-Ic; Wed, 23 Sep 2020 05:55:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkB-0004r8-Q2
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:07 +0000
X-Inumbo-ID: f1038a07-217d-4894-b199-6b20ce7e77b3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f1038a07-217d-4894-b199-6b20ce7e77b3;
 Wed, 23 Sep 2020 05:55:03 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=ZX1ML8ugO4fLRttYZlwSiiia8mOR7PBX4hOclrSVQEQ=; b=LeBN+oLCkikF4tMEMAw4d93c8S
 gKy4fuVLBm4eQoLHt2za9eQ3DnfUA3YxHP/HeCnigptEzMl6mhSYovbV1YlU6fUdzksG6G8vUxo1P
 GJBIK6/sba2Ul5pmShacbM+gotZyuIm2mfgUPNN2DD9vCOGZ6BSonkb0bI1Gle32w1sM=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxk7-00011B-CF
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:03 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxk7-0006d6-B3
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:03 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] mm: adjust get_page()'s types
Message-Id: <E1kKxk7-0006d6-B3@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:03 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 18063d6377fc40599e06ef9df5b5f0ea369ba83f
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 21 12:10:26 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:10:26 2020 +0200

    mm: adjust get_page()'s types
    
    The passed in domain doesn't get altered and hence can be const. While
    modifying its prototype anyway, also switch to bool.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/mm.c    | 8 ++++----
 xen/arch/x86/mm.c    | 8 ++++----
 xen/include/xen/mm.h | 2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 9e2ff7c800..b4763d9a3d 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1560,17 +1560,17 @@ void put_page(struct page_info *page)
     }
 }
 
-int get_page(struct page_info *page, struct domain *domain)
+bool get_page(struct page_info *page, const struct domain *domain)
 {
-    struct domain *owner = page_get_owner_and_reference(page);
+    const struct domain *owner = page_get_owner_and_reference(page);
 
     if ( likely(owner == domain) )
-        return 1;
+        return true;
 
     if ( owner != NULL )
         put_page(page);
 
-    return 0;
+    return false;
 }
 
 /* Common code requires get_page_type and put_page_type.
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 42a6dc9ba4..2c13a2d8e7 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2510,12 +2510,12 @@ struct domain *page_get_owner_and_reference(struct page_info *page)
 }
 
 
-int get_page(struct page_info *page, struct domain *domain)
+bool get_page(struct page_info *page, const struct domain *domain)
 {
-    struct domain *owner = page_get_owner_and_reference(page);
+    const struct domain *owner = page_get_owner_and_reference(page);
 
     if ( likely(owner == domain) )
-        return 1;
+        return true;
 
     if ( !paging_mode_refcounts(domain) && !domain->is_dying )
         gprintk(XENLOG_INFO,
@@ -2526,7 +2526,7 @@ int get_page(struct page_info *page, struct domain *domain)
     if ( owner )
         put_page(page);
 
-    return 0;
+    return false;
 }
 
 /*
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 1061765bcd..4536a62940 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -151,7 +151,7 @@ TYPE_SAFE(unsigned long, pfn);
 struct page_info;
 
 void put_page(struct page_info *);
-int get_page(struct page_info *, struct domain *);
+bool get_page(struct page_info *, const struct domain *);
 struct domain *__must_check page_get_owner_and_reference(struct page_info *);
 
 /* Boot-time allocator. Turns into generic allocator after bootstrap. */
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxkK-0004rh-K4; Wed, 23 Sep 2020 05:55:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkI-0004rN-P5
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:14 +0000
X-Inumbo-ID: a8c3f497-9c0c-411b-abf7-b7ff09f14181
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a8c3f497-9c0c-411b-abf7-b7ff09f14181;
 Wed, 23 Sep 2020 05:55:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=EUB4gTOkjudosLIY78sCklM83x0APpg8aTX6ODEvuzY=; b=5foVwhVC+B/QaigIP6nxUBdntb
 2pVrqOxPofsobeG+ktVu0qr7JKpKRDX2PWJ7z4SD+1ITrh9xiUEFp4OEAMPPjyMS1SYdkJj/DWutt
 po0nmxiOX1f4ewq/rk6HMYeZnA54ggjQ2ZC8zcs06H/hFp3QWT3QBcE0134gVhePR3jQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkH-00011E-HA
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:13 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkH-0006dk-Eu
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:13 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] x86/svm: ignore accesses to EX_CFG
Message-Id: <E1kKxkH-0006dk-Eu@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:13 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5164e44885252ae909977dd3b39c743544f3f5f0
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 21 12:11:38 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:11:38 2020 +0200

    x86/svm: ignore accesses to EX_CFG
    
    Windows 10 will try to unconditionally read (and possibly even adjust)
    EX_CFG on AMD hardware, despite it being documented only for Fam15 models
    0xh, and injecting a #GP fault will result in a panic:
    
    svm.c:1964:d5v0 RDMSR 0xc001102c unimplemented
    d5v0 VIRIDIAN CRASH: 7e ffffffffc0000096 fffff8054cbe5ffe fffffa0837a066e8 fffffa0837a05f30
    
    Return 0 when trying to read the MSR and drop writes.
    
    Fixes: 84e848fd7a16 ('x86/hvm: disallow access to unknown MSRs')
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/hvm/svm/svm.c      | 2 ++
 xen/include/asm-x86/msr-index.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 136445972e..5037c0fe7d 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1942,6 +1942,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     case MSR_K8_TOP_MEM1:
     case MSR_K8_TOP_MEM2:
     case MSR_K8_VM_CR:
+    case MSR_AMD64_EX_CFG:
         *msr_content = 0;
         break;
 
@@ -2108,6 +2109,7 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)
     case MSR_K8_TOP_MEM2:
     case MSR_K8_SYSCFG:
     case MSR_K8_VM_CR:
+    case MSR_AMD64_EX_CFG:
         /* ignore write. handle all bits as read-only. */
         break;
 
diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h
index 4fd54fb5c9..3e0c6c8476 100644
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -330,6 +330,7 @@
 #define MSR_AMD64_DC_CFG		0xc0011022
 #define MSR_AMD64_DE_CFG		0xc0011029
 #define AMD64_DE_CFG_LFENCE_SERIALISE	(_AC(1, ULL) << 1)
+#define MSR_AMD64_EX_CFG		0xc001102c
 
 #define MSR_AMD64_DR0_ADDRESS_MASK	0xc0011027
 #define MSR_AMD64_DR1_ADDRESS_MASK	0xc0011019
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:25 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:25 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxkT-0004sv-Li; Wed, 23 Sep 2020 05:55:25 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkS-0004sm-IB
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:24 +0000
X-Inumbo-ID: b018332a-21bd-49a8-818f-9644c7d6e729
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b018332a-21bd-49a8-818f-9644c7d6e729;
 Wed, 23 Sep 2020 05:55:23 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=nHUE7HVskec5KXLfPwnBrvtGGnYrLRgjPlxy7WEBf10=; b=apIjMJ/P1EwNvS3fWU2vm+z5KS
 BWLuAYRkdi7UHSYeo/TUR3C81Ie63x6O3P2MzN9d6dbHp2LD70tv4wwCti0iLrXbCtQ1n6BJSr0mg
 BI8MwiXtXKOaiLq2zNX1MMBPoVjsmi0Ep3ER+PnfXfajsuga9lkJGhrSnMwfOOenQSEc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkR-00011N-LU
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:23 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkR-0006eS-JY
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:23 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] efi/boot: make file->ptr const void*
Message-Id: <E1kKxkR-0006eS-JY@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:23 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c7e3021a71fdb4f2d5dbad90ba83ce35bc21cda6
Author:     Trammell Hudson <hudson@trmm.net>
AuthorDate: Mon Sep 21 12:14:24 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 21 12:14:24 2020 +0200

    efi/boot: make file->ptr const void*
    
    Other than the config file parser that edits the image inplace,
    no other users of the file sections requires write access to the
    data.
    
    Signed-off-by: Trammell Hudson <hudson@trmm.net>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/efi/boot.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 4022a672c9..523fda41fd 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -41,7 +41,7 @@
 
 typedef EFI_STATUS
 (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) (
-    IN VOID *Buffer,
+    IN const VOID *Buffer,
     IN UINT32 Size);
 
 typedef struct {
@@ -104,7 +104,8 @@ struct file {
     UINTN size;
     union {
         EFI_PHYSICAL_ADDRESS addr;
-        void *ptr;
+        char *str;
+        const void *ptr;
     };
 };
 
@@ -592,7 +593,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
             efi_arch_handle_module(file, name, options);
         }
 
-        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
+        ret = FileHandle->Read(FileHandle, &file->size, file->str);
         if ( !EFI_ERROR(ret) && file->size != size )
             ret = EFI_ABORTED;
         if ( EFI_ERROR(ret) )
@@ -616,7 +617,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
 
 static void __init pre_parse(const struct file *cfg)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     bool start = true, comment = false;
 
     for ( ; ptr < end; ++ptr )
@@ -645,7 +646,7 @@ static void __init pre_parse(const struct file *cfg)
 static char *__init get_value(const struct file *cfg, const char *section,
                               const char *item)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     size_t slen = section ? strlen(section) : 0, ilen = strlen(item);
     bool match = !slen;
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:36 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:36 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxke-0004uJ-ND; Wed, 23 Sep 2020 05:55:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkd-0004u9-1k
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:35 +0000
X-Inumbo-ID: 4517e22a-de4b-4f9e-bdd3-c1fbe4d268a3
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 4517e22a-de4b-4f9e-bdd3-c1fbe4d268a3;
 Wed, 23 Sep 2020 05:55:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Zi9bTNVVWsEPPkw9+6B3qOW2gMYV1lz4aTBpxM1s+2k=; b=ZceO7WMER4TM3+yQd01C3rtIwI
 dtqwc1ivTAYK5a6e+rhsek+OvXBV2ahVc+ViqIRhxNJqZb7oBf0dRHnJMTEcJ67yVNqOpVfx6Y9tW
 ed+JGWczr/wQ+ZGaYY/nJVFskDbILt2idE0A/0hJqcs1KgzZk84pVay8T1eV0R2yAXi4=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkb-00011e-QJ
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:33 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkb-0006fA-O6
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:33 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen: include xen/guest_access.h rather than
 asm/guest_access.h
Message-Id: <E1kKxkb-0006fA-O6@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:33 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 6edcdb4e5716626b2206f2b627e57a38ad2c3f59
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 11:56:43 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen: include xen/guest_access.h rather than asm/guest_access.h
    
    Only a few places are actually including asm/guest_access.h. While this
    is fine today, a follow-up patch will want to move most of the helpers
    from asm/guest_access.h to xen/guest_access.h.
    
    To prepare the move, everyone should include xen/guest_access.h rather
    than asm/guest_access.h.
    
    Interestingly, asm-arm/guest_access.h includes xen/guest_access.h. The
    inclusion is now removed as no-one but the latter should include the
    former.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    Acked-by: Paul Durrant <paul@xen.org>
---
 xen/arch/arm/decode.c                | 2 +-
 xen/arch/arm/domain.c                | 2 +-
 xen/arch/arm/guest_walk.c            | 3 ++-
 xen/arch/arm/guestcopy.c             | 2 +-
 xen/arch/arm/kernel.c                | 2 +-
 xen/arch/arm/vgic-v3-its.c           | 2 +-
 xen/arch/x86/hvm/svm/svm.c           | 2 +-
 xen/arch/x86/hvm/viridian/viridian.c | 2 +-
 xen/arch/x86/hvm/vmx/vmx.c           | 2 +-
 xen/common/libelf/libelf-loader.c    | 2 +-
 xen/include/asm-arm/guest_access.h   | 1 -
 xen/lib/x86/private.h                | 2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c
index 144793c8ce..792c2e92a7 100644
--- a/xen/arch/arm/decode.c
+++ b/xen/arch/arm/decode.c
@@ -17,12 +17,12 @@
  * GNU General Public License for more details.
  */
 
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
 #include <xen/types.h>
 
 #include <asm/current.h>
-#include <asm/guest_access.h>
 
 #include "decode.h"
 
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 31169326b2..9258f6d3fa 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -12,6 +12,7 @@
 #include <xen/bitops.h>
 #include <xen/errno.h>
 #include <xen/grant_table.h>
+#include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <xen/init.h>
 #include <xen/lib.h>
@@ -26,7 +27,6 @@
 #include <asm/current.h>
 #include <asm/event.h>
 #include <asm/gic.h>
-#include <asm/guest_access.h>
 #include <asm/guest_atomics.h>
 #include <asm/irq.h>
 #include <asm/p2m.h>
diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index a1cdd7f4af..b4496c4c86 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -16,8 +16,9 @@
  */
 
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/sched.h>
-#include <asm/guest_access.h>
+
 #include <asm/guest_walk.h>
 #include <asm/short-desc.h>
 
diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
index c8023e2bca..32681606d8 100644
--- a/xen/arch/arm/guestcopy.c
+++ b/xen/arch/arm/guestcopy.c
@@ -1,10 +1,10 @@
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/mm.h>
 #include <xen/sched.h>
 
 #include <asm/current.h>
-#include <asm/guest_access.h>
 
 #define COPY_flush_dcache   (1U << 0)
 #define COPY_from_guest     (0U << 1)
diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
index f95fa392af..032923853f 100644
--- a/xen/arch/arm/kernel.c
+++ b/xen/arch/arm/kernel.c
@@ -5,6 +5,7 @@
  */
 #include <xen/domain_page.h>
 #include <xen/errno.h>
+#include <xen/guest_access.h>
 #include <xen/gunzip.h>
 #include <xen/init.h>
 #include <xen/lib.h>
@@ -14,7 +15,6 @@
 #include <xen/vmap.h>
 
 #include <asm/byteorder.h>
-#include <asm/guest_access.h>
 #include <asm/kernel.h>
 #include <asm/setup.h>
 
diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c
index 6e153c698d..58d939b85f 100644
--- a/xen/arch/arm/vgic-v3-its.c
+++ b/xen/arch/arm/vgic-v3-its.c
@@ -32,6 +32,7 @@
 #include <xen/bitops.h>
 #include <xen/config.h>
 #include <xen/domain_page.h>
+#include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/init.h>
 #include <xen/softirq.h>
@@ -39,7 +40,6 @@
 #include <xen/sched.h>
 #include <xen/sizes.h>
 #include <asm/current.h>
-#include <asm/guest_access.h>
 #include <asm/mmio.h>
 #include <asm/gic_v3_defs.h>
 #include <asm/gic_v3_its.h>
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 5037c0fe7d..fa9fca94e2 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -16,6 +16,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/guest_access.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/trace.h>
@@ -34,7 +35,6 @@
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
 #include <asm/amd.h>
-#include <asm/guest_access.h>
 #include <asm/debugreg.h>
 #include <asm/msr.h>
 #include <asm/i387.h>
diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c
index 977c1bc54f..dc7183a546 100644
--- a/xen/arch/x86/hvm/viridian/viridian.c
+++ b/xen/arch/x86/hvm/viridian/viridian.c
@@ -5,12 +5,12 @@
  * Hypervisor Top Level Functional Specification for more information.
  */
 
+#include <xen/guest_access.h>
 #include <xen/sched.h>
 #include <xen/version.h>
 #include <xen/hypercall.h>
 #include <xen/domain_page.h>
 #include <xen/param.h>
-#include <asm/guest_access.h>
 #include <asm/guest/hyperv-tlfs.h>
 #include <asm/paging.h>
 #include <asm/p2m.h>
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index a3aadce4d8..998f33fb03 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -15,6 +15,7 @@
  * this program; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <xen/guest_access.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/param.h>
@@ -31,7 +32,6 @@
 #include <asm/regs.h>
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
-#include <asm/guest_access.h>
 #include <asm/debugreg.h>
 #include <asm/msr.h>
 #include <asm/p2m.h>
diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c
index 0f468727d0..629cc0d3e6 100644
--- a/xen/common/libelf/libelf-loader.c
+++ b/xen/common/libelf/libelf-loader.c
@@ -16,7 +16,7 @@
  */
 
 #ifdef __XEN__
-#include <asm/guest_access.h>
+#include <xen/guest_access.h>
 #endif
 
 #include "libelf-private.h"
diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h
index 31b9f03f00..b9a89c4955 100644
--- a/xen/include/asm-arm/guest_access.h
+++ b/xen/include/asm-arm/guest_access.h
@@ -1,7 +1,6 @@
 #ifndef __ASM_ARM_GUEST_ACCESS_H__
 #define __ASM_ARM_GUEST_ACCESS_H__
 
-#include <xen/guest_access.h>
 #include <xen/errno.h>
 #include <xen/sched.h>
 
diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h
index b793181464..2d53bd3ced 100644
--- a/xen/lib/x86/private.h
+++ b/xen/lib/x86/private.h
@@ -4,12 +4,12 @@
 #ifdef __XEN__
 
 #include <xen/bitops.h>
+#include <xen/guest_access.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
 #include <xen/nospec.h>
 #include <xen/types.h>
 
-#include <asm/guest_access.h>
 #include <asm/msr-index.h>
 
 #define copy_to_buffer_offset copy_to_guest_offset
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxkp-0004xC-Ow; Wed, 23 Sep 2020 05:55:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkn-0004wG-RH
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:45 +0000
X-Inumbo-ID: 7bfd163f-1869-450b-a6d1-5ce77e493f90
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 7bfd163f-1869-450b-a6d1-5ce77e493f90;
 Wed, 23 Sep 2020 05:55:44 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=P9lgVTzuvASzKOiHhk/KFEhR5YoJ0MH/0JTbYkrt0cM=; b=SFMwxZqsHNlumsriq2O/FLusrC
 l+Lak3NwqzCNVbrjydX7ApthQXZM8QmIGQFX65wiEjA/Afntj+U9iDF8d7QYI2+1/DTCRWTKVXjw0
 YHBvfS+Qk1IT41yBT7vQTN//vY0GGB+hUXwlP0fZBZBvLKXtWym1t6PAEZVQD+crmVi0=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkl-00011o-U7
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:43 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkl-0006fr-SX
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:43 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/guest_access: Consolidate guest access helpers in
 xen/guest_access.h
Message-Id: <E1kKxkl-0006fr-SX@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:43 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5b619481becfc4681804ea7193a2ee42a50fd468
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 12:33:16 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen/guest_access: Consolidate guest access helpers in xen/guest_access.h
    
    Most of the helpers to access guest memory are implemented the same way
    on Arm and x86. The only differences are:
        - guest_handle_to_param(): while on x86 XEN_GUEST_HANDLE()
          and XEN_GUEST_HANDLE_PARAM() are the same, they are not on Arm. It
          is still fine to use the Arm implementation on x86.
        - __clear_guest_offset(): Interestingly the prototype does not match
          between the x86 and Arm. However, the Arm one is bogus. So the x86
          implementation can be used.
        - guest_handle{,_subrange}_okay(): They are validly differing
          because Arm is only supporting auto-translated guest and therefore
          handles are always valid.
    
    In the past, the ia64 and ppc64 port use a different model to access
    guest parameter. They have been long gone now.
    
    Given Xen currently only support 2 archictures, it is too soon to have a
    directory asm-generic as it is not possible to differentiate it with the
    existing directory xen/. If/When there is a 3rd port, we can decide to
    create the new directory if that new port decide to use a different way
    to access guest parameter.
    
    For now, consolidate it in xen/guest_access.h.
    
    While it would be possible to adjust the coding style at the same, this
    is left for a follow-up patch so 'diff' can be used to check the
    consolidation was done correctly.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Stefano Stabellini <sttabellini@kernel.org>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/include/asm-arm/guest_access.h | 114 -----------------------------------
 xen/include/asm-x86/guest_access.h | 108 ---------------------------------
 xen/include/xen/guest_access.h     | 119 +++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 222 deletions(-)

diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h
index b9a89c4955..53766386d3 100644
--- a/xen/include/asm-arm/guest_access.h
+++ b/xen/include/asm-arm/guest_access.h
@@ -23,88 +23,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,
 #define __raw_copy_from_guest raw_copy_from_guest
 #define __raw_clear_guest raw_clear_guest
 
-/* Remainder copied from x86 -- could be common? */
-
-/* Is the guest handle a NULL reference? */
-#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
-
-/* Offset the given guest handle into the array it refers to. */
-#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
-#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
-
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
-#define guest_handle_cast(hnd, type) ({         \
-    type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
-})
-
-/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
-#define guest_handle_to_param(hnd, type) ({                  \
-    typeof((hnd).p) _x = (hnd).p;                            \
-    XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
-    /* type checking: make sure that the pointers inside     \
-     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
-    (void)(&_x == &_y.p);                                    \
-    _y;                                                      \
-})
-
-#define guest_handle_for_field(hnd, type, fld)          \
-    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
-
-#define guest_handle_from_ptr(ptr, type)        \
-    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
-#define const_guest_handle_from_ptr(ptr, type)  \
-    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
-
-/*
- * Copy an array of objects to guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
-})
-
-/*
- * Clear an array of objects in guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                        \
-    raw_clear_guest(_d+(off), nr);             \
-})
-
-/*
- * Copy an array of objects from guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-/* Copy sub-field of a structure to guest context via a guest handle. */
-#define copy_field_to_guest(hnd, ptr, field) ({         \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
-})
-
-/* Copy sub-field of a structure from guest context via a guest handle. */
-#define copy_field_from_guest(ptr, hnd, field) ({       \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
-})
-
 /*
  * Pre-validate a guest handle.
  * Allows use of faster __copy_* functions.
@@ -113,38 +31,6 @@ int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf,
 #define guest_handle_okay(hnd, nr) (1)
 #define guest_handle_subrange_okay(hnd, first, last) (1)
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
-})
-
-#define __clear_guest_offset(hnd, off, ptr, nr) ({      \
-    __raw_clear_guest(_d+(off), nr);  \
-})
-
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define __copy_field_to_guest(hnd, ptr, field) ({       \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
-})
-
-#define __copy_field_from_guest(ptr, hnd, field) ({     \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
-})
-
 #endif /* __ASM_ARM_GUEST_ACCESS_H__ */
 /*
  * Local variables:
diff --git a/xen/include/asm-x86/guest_access.h b/xen/include/asm-x86/guest_access.h
index 369676f31a..8f0e2c71f1 100644
--- a/xen/include/asm-x86/guest_access.h
+++ b/xen/include/asm-x86/guest_access.h
@@ -38,81 +38,6 @@
      clear_user_hvm((dst), (len)) :             \
      clear_user((dst), (len)))
 
-/* Is the guest handle a NULL reference? */
-#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
-
-/* Offset the given guest handle into the array it refers to. */
-#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
-#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
-
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
-#define guest_handle_cast(hnd, type) ({         \
-    type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
-})
-
-/* Convert a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
-#define guest_handle_to_param(hnd, type) ({                  \
-    /* type checking: make sure that the pointers inside     \
-     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
-    (void)((typeof(&(hnd).p)) 0 ==                           \
-        (typeof(&((XEN_GUEST_HANDLE_PARAM(type)) {}).p)) 0); \
-    (hnd);                                                   \
-})
-
-#define guest_handle_for_field(hnd, type, fld)          \
-    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
-
-#define guest_handle_from_ptr(ptr, type)        \
-    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
-#define const_guest_handle_from_ptr(ptr, type)  \
-    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
-
-/*
- * Copy an array of objects to guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
-})
-
-/*
- * Copy an array of objects from guest context via a guest handle,
- * specifying an offset into the guest array.
- */
-#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                        \
-    raw_clear_guest(_d+(off), nr);             \
-})
-
-/* Copy sub-field of a structure to guest context via a guest handle. */
-#define copy_field_to_guest(hnd, ptr, field) ({         \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
-})
-
-/* Copy sub-field of a structure from guest context via a guest handle. */
-#define copy_field_from_guest(ptr, hnd, field) ({       \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
-})
-
 /*
  * Pre-validate a guest handle.
  * Allows use of faster __copy_* functions.
@@ -126,39 +51,6 @@
                      (last)-(first)+1,                  \
                      sizeof(*(hnd).p)))
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
-})
-
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
-})
-
-#define __clear_guest_offset(hnd, off, nr) ({    \
-    void *_d = (hnd).p;                          \
-    __raw_clear_guest(_d+(off), nr);             \
-})
-
-#define __copy_field_to_guest(hnd, ptr, field) ({       \
-    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
-    void *_d = &(hnd).p->field;                         \
-    (void)(&(hnd).p->field == _s);                      \
-    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
-})
-
-#define __copy_field_from_guest(ptr, hnd, field) ({     \
-    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _d = &(ptr)->field;           \
-    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
-})
-
 #endif /* __ASM_X86_GUEST_ACCESS_H__ */
 
 /*
diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h
index 75103d30c8..6100a3e62a 100644
--- a/xen/include/xen/guest_access.h
+++ b/xen/include/xen/guest_access.h
@@ -11,6 +11,86 @@
 #include <xen/types.h>
 #include <public/xen.h>
 
+/* Is the guest handle a NULL reference? */
+#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
+
+/* Offset the given guest handle into the array it refers to. */
+#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+#define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
+
+/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
+ * to the specified type of XEN_GUEST_HANDLE_PARAM. */
+#define guest_handle_cast(hnd, type) ({         \
+    type *_x = (hnd).p;                         \
+    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
+})
+
+/* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
+#define guest_handle_to_param(hnd, type) ({                  \
+    typeof((hnd).p) _x = (hnd).p;                            \
+    XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
+    /* type checking: make sure that the pointers inside     \
+     * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
+     * the same type, then return hnd */                     \
+    (void)(&_x == &_y.p);                                    \
+    _y;                                                      \
+})
+
+#define guest_handle_for_field(hnd, type, fld)          \
+    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
+
+#define guest_handle_from_ptr(ptr, type)        \
+    ((XEN_GUEST_HANDLE_PARAM(type)) { (type *)ptr })
+#define const_guest_handle_from_ptr(ptr, type)  \
+    ((XEN_GUEST_HANDLE_PARAM(const_##type)) { (const type *)ptr })
+
+/*
+ * Copy an array of objects to guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    /* Check that the handle is not for a const type */ \
+    void *__maybe_unused _t = (hnd).p;                  \
+    (void)((hnd).p == _s);                              \
+    raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));  \
+})
+
+/*
+ * Clear an array of objects in guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define clear_guest_offset(hnd, off, nr) ({    \
+    void *_d = (hnd).p;                        \
+    raw_clear_guest(_d+(off), nr);             \
+})
+
+/*
+ * Copy an array of objects from guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
+    raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+})
+
+/* Copy sub-field of a structure to guest context via a guest handle. */
+#define copy_field_to_guest(hnd, ptr, field) ({         \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    (void)(&(hnd).p->field == _s);                      \
+    raw_copy_to_guest(_d, _s, sizeof(*_s));             \
+})
+
+/* Copy sub-field of a structure from guest context via a guest handle. */
+#define copy_field_from_guest(ptr, hnd, field) ({       \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
+    raw_copy_from_guest(_d, _s, sizeof(*_d));           \
+})
+
 #define copy_to_guest(hnd, ptr, nr)                     \
     copy_to_guest_offset(hnd, 0, ptr, nr)
 
@@ -20,6 +100,45 @@
 #define clear_guest(hnd, nr)                            \
     clear_guest_offset(hnd, 0, nr)
 
+/*
+ * The __copy_* functions should only be used after the guest handle has
+ * been pre-validated via guest_handle_okay() and
+ * guest_handle_subrange_okay().
+ */
+
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    /* Check that the handle is not for a const type */ \
+    void *__maybe_unused _t = (hnd).p;                  \
+    (void)((hnd).p == _s);                              \
+    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
+})
+
+#define __clear_guest_offset(hnd, off, nr) ({    \
+    void *_d = (hnd).p;                          \
+    __raw_clear_guest(_d + (off), nr);           \
+})
+
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
+    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+})
+
+#define __copy_field_to_guest(hnd, ptr, field) ({       \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    (void)(&(hnd).p->field == _s);                      \
+    __raw_copy_to_guest(_d, _s, sizeof(*_s));           \
+})
+
+#define __copy_field_from_guest(ptr, hnd, field) ({     \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
+    __raw_copy_from_guest(_d, _s, sizeof(*_d));         \
+})
+
 #define __copy_to_guest(hnd, ptr, nr)                   \
     __copy_to_guest_offset(hnd, 0, ptr, nr)
 
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 05:55:56 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 05:55:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kKxky-0004yN-S5; Wed, 23 Sep 2020 05:55:56 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kKxkw-0004yB-TD
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:54 +0000
X-Inumbo-ID: 90524761-617e-4b22-81bb-6eff4270f226
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 90524761-617e-4b22-81bb-6eff4270f226;
 Wed, 23 Sep 2020 05:55:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=kQCMlKETEudIDO2QQ1DFupF9cJt/PumUL3Gf51rSALU=; b=ulEHWIRx2zoMf8noV4nCUVWi7p
 D5wnsnYMsca4B7BiIY5fUnbZV1Kwb+QHUQWvy8tBNX18qkysnuIfM8eb1NAwfIxeErXzYJ6Wc0JCH
 puBAd5F4PC+4GOhh6nWmqR1qq0oJGM+LSkCl+WOv8pKPZc5nJVe25Zfy6h1MtXkyQyhQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkw-00011z-10
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:54 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kKxkw-0006ga-07
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 05:55:54 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen master] xen/guest_access: Improve coding style in
 xen/guest_access.h
Message-Id: <E1kKxkw-0006ga-07@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 05:55:54 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit d4ed1d4132f5825a795d5a78505811ecd2717b5e
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Sat Apr 4 12:35:28 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 21 17:09:11 2020 +0100

    xen/guest_access: Improve coding style in xen/guest_access.h
    
        * Add space before and after operator
        * Align \
        * Format comments
    
    No functional changes expected.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
 xen/include/xen/guest_access.h | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h
index 6100a3e62a..f9b94cf1f4 100644
--- a/xen/include/xen/guest_access.h
+++ b/xen/include/xen/guest_access.h
@@ -18,20 +18,24 @@
 #define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
 #define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
 
-/* Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
- * to the specified type of XEN_GUEST_HANDLE_PARAM. */
+/*
+ * Cast a guest handle (either XEN_GUEST_HANDLE or XEN_GUEST_HANDLE_PARAM)
+ * to the specified type of XEN_GUEST_HANDLE_PARAM.
+ */
 #define guest_handle_cast(hnd, type) ({         \
     type *_x = (hnd).p;                         \
-    (XEN_GUEST_HANDLE_PARAM(type)) { _x };            \
+    (XEN_GUEST_HANDLE_PARAM(type)) { _x };      \
 })
 
 /* Cast a XEN_GUEST_HANDLE to XEN_GUEST_HANDLE_PARAM */
 #define guest_handle_to_param(hnd, type) ({                  \
     typeof((hnd).p) _x = (hnd).p;                            \
     XEN_GUEST_HANDLE_PARAM(type) _y = { _x };                \
-    /* type checking: make sure that the pointers inside     \
+    /*                                                       \
+     * type checking: make sure that the pointers inside     \
      * XEN_GUEST_HANDLE and XEN_GUEST_HANDLE_PARAM are of    \
-     * the same type, then return hnd */                     \
+     * the same type, then return hnd.                       \
+     */                                                      \
     (void)(&_x == &_y.p);                                    \
     _y;                                                      \
 })
@@ -106,13 +110,13 @@
  * guest_handle_subrange_okay().
  */
 
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(*(ptr)) *_s = (ptr);                   \
-    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
-    /* Check that the handle is not for a const type */ \
-    void *__maybe_unused _t = (hnd).p;                  \
-    (void)((hnd).p == _s);                              \
-    __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({        \
+    const typeof(*(ptr)) *_s = (ptr);                       \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;              \
+    /* Check that the handle is not for a const type */     \
+    void *__maybe_unused _t = (hnd).p;                      \
+    (void)((hnd).p == _s);                                  \
+    __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr));\
 })
 
 #define __clear_guest_offset(hnd, off, nr) ({    \
@@ -120,10 +124,10 @@
     __raw_clear_guest(_d + (off), nr);           \
 })
 
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(*(ptr)) *_s = (hnd).p;                 \
-    typeof(*(ptr)) *_d = (ptr);                         \
-    __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({          \
+    const typeof(*(ptr)) *_s = (hnd).p;                         \
+    typeof(*(ptr)) *_d = (ptr);                                 \
+    __raw_copy_from_guest(_d, _s + (off), sizeof (*_d) * (nr)); \
 })
 
 #define __copy_field_to_guest(hnd, ptr, field) ({       \
--
generated by git-patchbot for /home/xen/git/xen.git#master


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 08:33:11 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 08:33:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kL0D4-0003rd-Ss; Wed, 23 Sep 2020 08:33:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kL0D3-0003rX-VJ
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:05 +0000
X-Inumbo-ID: 6180cd17-fd5d-4526-a205-a65cce993a32
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 6180cd17-fd5d-4526-a205-a65cce993a32;
 Wed, 23 Sep 2020 08:33:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=/RqKK+TUOwkagmJVLIV+VVXV6/BWD8t/HQsXPh4b0kg=; b=yBa/S3RGWAvEfV26ai8Lt5buYy
 Gfv5YSS7f+FOS04d3iaZj8OwFijAA7Jgp+RQXVdJHl+q19KUlJagoPe60GKRo5dgokwcDyikgsuSG
 SWzNWzVMTJmXIdNHLp43S4OxIcXyV212OYCEDLIZBb+SywCaUtwagmZac7H9lQEmtMHg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kL0D2-0004sz-U7
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:04 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kL0D2-000132-SN
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] SUPPORT.md: Update status of Renesas IPMMU-VMSA (Arm)
Message-Id: <E1kL0D2-000132-SN@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 08:33:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit a6732807d335239fc29bd953538affc458bcc197
Author:     Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
AuthorDate: Sat Sep 19 20:21:22 2020 +0300
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Wed Sep 23 09:16:20 2020 +0100

    SUPPORT.md: Update status of Renesas IPMMU-VMSA (Arm)
    
    Mark Renesas IPMMU-VMSA as "Supported, not security supported"
    and remove dependencies on CONFIG_EXPERT.
    
    We can't treat the IOMMU driver as "Supported" since the device
    passthrough feature is not security supported on Arm today.
    
    Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 SUPPORT.md                      | 2 +-
 xen/arch/arm/platforms/Kconfig  | 2 +-
 xen/drivers/passthrough/Kconfig | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/SUPPORT.md b/SUPPORT.md
index 1479055c45..25987ec1df 100644
--- a/SUPPORT.md
+++ b/SUPPORT.md
@@ -64,7 +64,7 @@ supported in this document.
     Status, Intel VT-d: Supported
     Status, ARM SMMUv1: Supported
     Status, ARM SMMUv2: Supported
-    Status, Renesas IPMMU-VMSA: Tech Preview
+    Status, Renesas IPMMU-VMSA: Supported, not security supported
 
 ### ARM/GICv3 ITS
 
diff --git a/xen/arch/arm/platforms/Kconfig b/xen/arch/arm/platforms/Kconfig
index 4bb73190e7..c93a6b2756 100644
--- a/xen/arch/arm/platforms/Kconfig
+++ b/xen/arch/arm/platforms/Kconfig
@@ -25,7 +25,7 @@ config RCAR3
 	bool "Renesas RCar3 support"
 	depends on ARM_64
 	select HAS_SCIF
-	select IPMMU_VMSA if EXPERT
+	select IPMMU_VMSA
 	---help---
 	Enable all the required drivers for Renesas RCar3
 
diff --git a/xen/drivers/passthrough/Kconfig b/xen/drivers/passthrough/Kconfig
index 73f4ad89ec..0036007ec4 100644
--- a/xen/drivers/passthrough/Kconfig
+++ b/xen/drivers/passthrough/Kconfig
@@ -14,7 +14,7 @@ config ARM_SMMU
 	  ARM SMMU architecture.
 
 config IPMMU_VMSA
-	bool "Renesas IPMMU-VMSA found in R-Car Gen3 SoCs" if EXPERT
+	bool "Renesas IPMMU-VMSA found in R-Car Gen3 SoCs"
 	depends on ARM_64
 	---help---
 	  Support for implementations of the Renesas IPMMU-VMSA found
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 23 08:33:16 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 23 Sep 2020 08:33:16 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kL0DE-0003sc-UV; Wed, 23 Sep 2020 08:33:16 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Tp40=DA=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kL0DE-0003sW-Lz
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:16 +0000
X-Inumbo-ID: 9f1c9ec1-ebc0-4769-96fb-3f5dcc54f35c
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 9f1c9ec1-ebc0-4769-96fb-3f5dcc54f35c;
 Wed, 23 Sep 2020 08:33:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=g2b4pSS82X+IwHcLPVCdn2/aq9y1drfSC32l5N++PUs=; b=r/EepozKwSKICgPhytRnZl4+O/
 YtgmQsV0Lba4HbZDQbP8rXPYQxbCmAh8xAuysdlEmIddotWxTqF2iyhUXmTzNHe2/B6qKP1BZqA1I
 +VcvyYmV8CJ0Y14RjTzOwx2uLOJrAbIObW5ClgdgccWE0WKLLOXqWjRvDX264LHlS9IQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kL0DD-0004tE-0w
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kL0DD-00013j-04
 for xen-changelog@lists.xenproject.org; Wed, 23 Sep 2020 08:33:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: bootfdt: Ignore empty memory bank
Message-Id: <E1kL0DD-00013j-04@xenbits.xenproject.org>
Date: Wed, 23 Sep 2020 08:33:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5a37207df52066efefe419c677b089a654d37afc
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Fri Sep 18 18:11:16 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Wed Sep 23 09:30:01 2020 +0100

    xen/arm: bootfdt: Ignore empty memory bank
    
    At the moment, Xen will stop processing the Device Tree if a memory
    bank is empty (size == 0).
    
    Unfortunately, some of the Device Tree (such as on Colibri imx8qxp)
    may contain such a bank. This means Xen will not be able to boot
    properly.
    
    Relax the check to just ignore the banks. FWIW this also seems to be the
    behavior adopted by Linux.
    
    Reported-by: Daniel Wagner <Daniel.Wagner2@itk-engineering.de>
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/arch/arm/bootfdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
index 08fb59f4e7..dcff512648 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/arch/arm/bootfdt.c
@@ -163,8 +163,9 @@ static int __init process_memory_node(const void *fdt, int node,
     for ( i = 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ )
     {
         device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
+        /* Some DT may describe empty bank, ignore them */
         if ( !size )
-            return -EINVAL;
+            continue;
         mem->bank[mem->nr_banks].start = start;
         mem->bank[mem->nr_banks].size = size;
         mem->nr_banks++;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Thu Sep 24 20:11:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Thu, 24 Sep 2020 20:11:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kLXaB-0004D0-Df; Thu, 24 Sep 2020 20:11:11 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Iby/=DB=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kLXa9-0004B3-TF
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:09 +0000
X-Inumbo-ID: a0349e88-f6c4-4d0f-9873-9a9d5920d585
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a0349e88-f6c4-4d0f-9873-9a9d5920d585;
 Thu, 24 Sep 2020 20:11:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=jEIDev4lI5Xuo/dd0eMtVQ9dvrzGCeYhV8BNp9IhdFQ=; b=FAqcMzRJwjcBUeEQ+fUgsBDv4z
 5RoPlg0gTQV5X0Hq+sWPVaaavGCxQ4yAWQzVjpudcQjGvHmIF2m3nessYjArulzNNyWit7IwY7fKE
 FFVXYhN0BsZgNlgXSGIDA4LYdkFWTuj1DsGxJ8pDRj9bGr57T8agpko01+XvSqgFCWHc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXa5-00080y-Qh
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXa5-0006Og-PB
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/msi: Fold pci_conf_write16() calls in
 write_msi_msg()
Message-Id: <E1kLXa5-0006Og-PB@xenbits.xenproject.org>
Date: Thu, 24 Sep 2020 20:11:05 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit af3c913f03b5f9eab15b168ef87cde80f9addc6e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 22 20:05:22 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Sep 24 21:02:35 2020 +0100

    x86/msi: Fold pci_conf_write16() calls in write_msi_msg()
    
    In addition, this removes the unqualified 0/1 passed to msi_data_reg()
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/msi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index a899c43e8d..5febc0ea4b 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -214,13 +214,10 @@ static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
         pci_conf_write32(dev->sbdf, msi_lower_address_reg(pos),
                          msg->address_lo);
         if ( entry->msi_attrib.is_64 )
-        {
             pci_conf_write32(dev->sbdf, msi_upper_address_reg(pos),
                              msg->address_hi);
-            pci_conf_write16(dev->sbdf, msi_data_reg(pos, 1), msg->data);
-        }
-        else
-            pci_conf_write16(dev->sbdf, msi_data_reg(pos, 0), msg->data);
+        pci_conf_write16(dev->sbdf, msi_data_reg(pos, entry->msi_attrib.is_64),
+                         msg->data);
         break;
     }
     case PCI_CAP_ID_MSIX:
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Thu Sep 24 20:11:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Thu, 24 Sep 2020 20:11:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kLXaI-0004DR-FE; Thu, 24 Sep 2020 20:11:18 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Iby/=DB=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kLXaH-0004D9-Bw
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:17 +0000
X-Inumbo-ID: 3dd5e792-5e6d-48af-a762-fa6f67d25752
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3dd5e792-5e6d-48af-a762-fa6f67d25752;
 Thu, 24 Sep 2020 20:11:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=84KDIXjuJ3DO8SKWltenVV1IkWNiLUHFQz/ed+HMwTI=; b=Ip5RBU7cDGwupCtlu+0yKzLZN0
 BMTaa62uoToy+CRP6ziu3BlMofra0olFWUKLmKbrDIMy0Omg4z3ofc4W2DZTO/IDAiHuFVXDacpry
 QG1QGRLnflfbX6CVOaSaQ7Tn4X82HWEzjeS9mvV9TCBMFqYABu7GiW04poG/1qiJYkhg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXaF-00081C-Vz
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXaF-0006PF-TA
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Don't deliver #GP for a SYSENTER with NT set
Message-Id: <E1kLXaF-0006PF-TA@xenbits.xenproject.org>
Date: Thu, 24 Sep 2020 20:11:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 61d4a04349895edc5a5868274b906ba61ef24f47
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Jun 26 14:56:23 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Sep 24 21:02:35 2020 +0100

    x86/pv: Don't deliver #GP for a SYSENTER with NT set
    
    It is a matter of guest kernel policy what to do with offending userspace, and
    terminating said userspace may not be the action chosen.
    
    Linux explicitly tolerates this case.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Fixes: fdac951560 ("x86: clear EFLAGS.NT in SYSENTER entry path")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/entry.S | 1 -
 1 file changed, 1 deletion(-)

diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 71a00e846b..44a110b9c8 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -313,7 +313,6 @@ UNLIKELY_START(nz, sysenter_nt_set)
         pushfq
         andl  $~X86_EFLAGS_NT,(%rsp)
         popfq
-        xorl  %eax,%eax
 UNLIKELY_END(sysenter_nt_set)
         testq %rax,%rax
         leal  (,%rcx,TBF_INTERRUPT),%ecx
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Thu Sep 24 20:11:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Thu, 24 Sep 2020 20:11:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kLXaS-0004EW-Gf; Thu, 24 Sep 2020 20:11:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Iby/=DB=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kLXaR-0004EI-5a
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:27 +0000
X-Inumbo-ID: 45aa306e-aef8-4059-8ab8-24cf41f6fe25
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 45aa306e-aef8-4059-8ab8-24cf41f6fe25;
 Thu, 24 Sep 2020 20:11:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=Qc106RCEocUROoQEfqGpyROWO0icP+yakTkQ7RFiZ2k=; b=Xl8mtvSyBl8SY16IlOa0xz4Q/r
 6Sc+3SNhz9tMurbXMJt91G4/K7n+w02iOzs7BtptuqCWQbA2QDDW7OGy1RboEitSw6OErewR5s8XB
 fgFQAddaX/MS2X6GUchUFojV0dRX4lisNeGfsVDcds2jA4jprUXJUgQq01YxGofIBliQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXaQ-00081M-5F
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kLXaQ-0006Px-2D
 for xen-changelog@lists.xenproject.org; Thu, 24 Sep 2020 20:11:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/pv: Don't clobber NT on return-to-guest
Message-Id: <E1kLXaQ-0006Px-2D@xenbits.xenproject.org>
Date: Thu, 24 Sep 2020 20:11:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5bcac985498ed83d89666959175ca9c9ed561ae1
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Mon Jun 29 11:32:37 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Thu Sep 24 21:02:35 2020 +0100

    x86/pv: Don't clobber NT on return-to-guest
    
    A 64bit IRET can restore NT - the faulting case is when NT is set in the live
    flags.  This change had an unintended consequence of causing the NT flag to
    spontaneously disappear from guest context whenever a interrupt/exception
    occurred.
    
    In combination with a SYSENTER which sets both TF and NT, Xen's handling of
    the #DB exceptions clears NT before it is even recorded suitably in the guest
    kernel's view of what userspace was doing.
    
    Reported-by: Andy Lutomirski <luto@kernel.org>
    Fixes: 0e47f92b0 ("x86: force EFLAGS.IF on when exiting to PV guests")
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/x86_64/compat/entry.S | 2 +-
 xen/arch/x86/x86_64/entry.S        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index 73619f57ca..3b2136b272 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -119,7 +119,7 @@ compat_process_trap:
 /* %rbx: struct vcpu, interrupts disabled */
 ENTRY(compat_restore_all_guest)
         ASSERT_INTERRUPTS_DISABLED
-        mov   $~(X86_EFLAGS_IOPL|X86_EFLAGS_NT|X86_EFLAGS_VM),%r11d
+        mov   $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), %r11d
         and   UREGS_eflags(%rsp),%r11d
 
 .macro alt_cr4_pv32
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 44a110b9c8..000eb9722b 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -182,7 +182,7 @@ restore_all_guest:
         jz    iret_exit_to_guest
 
         movq  24(%rsp),%r11           # RFLAGS
-        andq  $~(X86_EFLAGS_IOPL|X86_EFLAGS_NT|X86_EFLAGS_VM),%r11
+        andq  $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), %r11
         orq   $X86_EFLAGS_IF,%r11
 
         /* Don't use SYSRET path if the return address is not canonical. */
@@ -213,7 +213,7 @@ restore_all_guest:
         movq  8(%rsp), %rcx           # RIP
 /* No special register assumptions. */
 iret_exit_to_guest:
-        andl  $~(X86_EFLAGS_IOPL|X86_EFLAGS_NT|X86_EFLAGS_VM),24(%rsp)
+        andl  $~(X86_EFLAGS_IOPL | X86_EFLAGS_VM), 24(%rsp)
         orl   $X86_EFLAGS_IF,24(%rsp)
         addq  $8,%rsp
 .Lft0:  iretq
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 08:44:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 08:44:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMolV-0007uF-41; Mon, 28 Sep 2020 08:44:09 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMolU-0007ty-A9
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:08 +0000
X-Inumbo-ID: ac2b5ed7-092f-433d-85dc-bad422f68fdc
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ac2b5ed7-092f-433d-85dc-bad422f68fdc;
 Mon, 28 Sep 2020 08:44:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=PCkWMCh3wHYqWDUOnaQmRMDk0U5l2siYzLdgCzlfsLA=; b=4B1ZVZ/ChzzV/vaWk4BQGrvkAR
 8yD/h/F+Kd8u3/C8CyKO0P1H9vRJ4NPelzrJdZVANOBXroEOPHrLdbbJBEbN+aOL9dmGmbL9gz2hI
 Ki9c+Xsky1OW5JITUrl6V6wlpOTfU9LeZB+tqwFt2i+e5ecz2qOrHBLf+kCO3noOWYdg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolR-0005vB-0T
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolQ-0005Rn-Vc
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:04 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] EFI: some easy constification
Message-Id: <E1kMolQ-0005Rn-Vc@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 08:44:04 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 643e2f3cbb3b607f3365b230f439845e9bf113b0
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 28 10:39:47 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 28 10:39:47 2020 +0200

    EFI: some easy constification
    
    Inspired by some of Trammell's suggestions, this harvests some low
    hanging fruit, without needing to be concerned about the definitions of
    the EFI interfaces themselves.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Wei Liu <wl@xen.org>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/arch/arm/efi/efi-boot.h | 7 ++++---
 xen/arch/x86/efi/efi-boot.h | 7 ++++---
 xen/common/efi/boot.c       | 6 +++---
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 6527cb0bdf..27dd0b1a94 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -420,7 +420,7 @@ static void __init efi_arch_memory_setup(void)
 
 static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
                                            CHAR16 *cmdline_options,
-                                           char *cfgfile_options)
+                                           const char *cfgfile_options)
 {
     union string name;
     char *buf;
@@ -481,8 +481,9 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
     efi_bs->FreePool(buf);
 }
 
-static void __init efi_arch_handle_module(struct file *file, const CHAR16 *name,
-                                          char *options)
+static void __init efi_arch_handle_module(const struct file *file,
+                                          const CHAR16 *name,
+                                          const char *options)
 {
     int node;
     int chosen;
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 7188c9a551..eef3f52789 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -294,7 +294,7 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *sect
 
 static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
                                            CHAR16 *cmdline_options,
-                                           char *cfgfile_options)
+                                           const char *cfgfile_options)
 {
     union string name;
 
@@ -635,8 +635,9 @@ static void __init efi_arch_memory_setup(void)
 #undef l2_4G_offset
 }
 
-static void __init efi_arch_handle_module(struct file *file, const CHAR16 *name,
-                                          char *options)
+static void __init efi_arch_handle_module(const struct file *file,
+                                          const CHAR16 *name,
+                                          const char *options)
 {
     union string local_name;
     void *ptr;
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 523fda41fd..157fe0e8c5 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -120,7 +120,7 @@ static char *split_string(char *s);
 static CHAR16 *s2w(union string *str);
 static char *w2s(const union string *str);
 static bool read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                      struct file *file, char *options);
+                      struct file *file, const char *options);
 static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 static bool match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
@@ -540,7 +540,7 @@ static char * __init split_string(char *s)
 }
 
 static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                             struct file *file, char *options)
+                             struct file *file, const char *options)
 {
     EFI_FILE_HANDLE FileHandle = NULL;
     UINT64 size;
@@ -1101,7 +1101,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
     bool base_video = false;
-    char *option_str;
+    const char *option_str;
     bool use_cfg_file;
 
     __set_bit(EFI_BOOT, &efi_flags);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 08:44:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 08:44:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMold-0007uu-5V; Mon, 28 Sep 2020 08:44:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMolc-0007ul-0O
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:16 +0000
X-Inumbo-ID: 3dbd0c6c-b5ee-43b8-b34b-91d265cb508f
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 3dbd0c6c-b5ee-43b8-b34b-91d265cb508f;
 Mon, 28 Sep 2020 08:44:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=F3YBLfrHeRmsAkJdlIMmYDFiWyrUn7gx2bKyEP9iQew=; b=r03BxCjOnfg+E/RgsHEa48zFOH
 7VsZbLuUEKZQrWIN+9KchGRSRP5VbVmMxSFTKFHGW/NJgb6nsQKl8uu+Ueeng6CniILAcKYyYPDBX
 H5L8gBgi/KivF+yk8WY8v0+X8Cww5k8lbukgpgP7xIGBmI9/Ivx/vhXoU5ZHvtCyhnOQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolb-0005vs-43
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolb-0005T6-2g
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] common/Kconfig: sort HAS_*
Message-Id: <E1kMolb-0005T6-2g@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 08:44:15 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit fe41405f5ee650d3fe39105cf59193b1494cdcdc
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Mon Sep 28 10:40:53 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 28 10:40:53 2020 +0200

    common/Kconfig: sort HAS_*
    
    Later additions look to have been put at the end, with MEM_ACCESS*
    somewhere in the middle. Re-sort this part of the file, in the hope that
    future additions will be made noticing the intentions here.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
---
 xen/common/Kconfig | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 15e3b79ff5..3e2cf25088 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -34,16 +34,11 @@ config HAS_EX_TABLE
 config HAS_FAST_MULTIPLY
 	bool
 
-config MEM_ACCESS_ALWAYS_ON
+config HAS_IOPORTS
 	bool
 
-config MEM_ACCESS
-	def_bool MEM_ACCESS_ALWAYS_ON
-	prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON
-	---help---
-
-	  Framework to configure memory access types for guests and receive
-	  related events in userspace.
+config HAS_KEXEC
+	bool
 
 config HAS_MEM_PAGING
 	bool
@@ -51,17 +46,22 @@ config HAS_MEM_PAGING
 config HAS_PDX
 	bool
 
-config HAS_UBSAN
+config HAS_SCHED_GRANULARITY
 	bool
 
-config HAS_KEXEC
+config HAS_UBSAN
 	bool
 
-config HAS_IOPORTS
+config MEM_ACCESS_ALWAYS_ON
 	bool
 
-config HAS_SCHED_GRANULARITY
-	bool
+config MEM_ACCESS
+	def_bool MEM_ACCESS_ALWAYS_ON
+	prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON
+	---help---
+
+	  Framework to configure memory access types for guests and receive
+	  related events in userspace.
 
 config NEEDS_LIBELF
 	bool
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 08:44:27 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 08:44:27 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMoln-0007wP-77; Mon, 28 Sep 2020 08:44:27 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMolm-0007wD-3n
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:26 +0000
X-Inumbo-ID: a32129f6-72b3-4e2d-8c8c-06e773740218
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a32129f6-72b3-4e2d-8c8c-06e773740218;
 Mon, 28 Sep 2020 08:44:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=irkkanvmimafwj5TpSdhp1YY008wtcIXVq/0T1g+Z48=; b=Vz3bHji0ooDOJNnwWDJ3j6CRkq
 haO67wDL9Swu0sy+BPyAGr1qsZcr7cDakc7BQ+A5WP7ZzBafGX+4gx9L11prKXzBe7i9ck56/Q7ef
 MZYKlLLF2w6jmSM+oQ85saGMNEs90CQZ1SWhMeBYTGBGw0AfURBNjUGl3Za4I7j1PQ5Q=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMoll-0005w6-7U
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMoll-0005UE-6S
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/hpet: remove hpet_msi_read
Message-Id: <E1kMoll-0005UE-6S@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 08:44:25 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f9ffd20f946c0315937f85d2f124a9bc4be49473
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 28 10:41:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 28 10:41:48 2020 +0200

    x86/hpet: remove hpet_msi_read
    
    It's dead code, even more now that read_msi_msg has been removed.
    
    Suggested-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/hpet.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c
index 154c67423b..a55e68e6f7 100644
--- a/xen/arch/x86/hpet.c
+++ b/xen/arch/x86/hpet.c
@@ -268,16 +268,6 @@ static int hpet_msi_write(struct hpet_event_channel *ch, struct msi_msg *msg)
     return 0;
 }
 
-static void __maybe_unused
-hpet_msi_read(struct hpet_event_channel *ch, struct msi_msg *msg)
-{
-    msg->data = hpet_read32(HPET_Tn_ROUTE(ch->idx));
-    msg->address_lo = hpet_read32(HPET_Tn_ROUTE(ch->idx) + 4);
-    msg->address_hi = MSI_ADDR_BASE_HI;
-    if ( iommu_intremap )
-        iommu_read_msi_from_ire(&ch->msi, msg);
-}
-
 static unsigned int hpet_msi_startup(struct irq_desc *desc)
 {
     hpet_msi_unmask(desc);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 08:44:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 08:44:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMolx-0007xi-8m; Mon, 28 Sep 2020 08:44:37 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMolw-0007xW-HH
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:36 +0000
X-Inumbo-ID: a4b10822-2973-44d3-a37e-0d3195fd8522
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id a4b10822-2973-44d3-a37e-0d3195fd8522;
 Mon, 28 Sep 2020 08:44:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=C7WZQd6MsdQiUDVoR0xH1dG9VJX1zfkjREeNxkd8xOE=; b=KkoqoVMYIWzWjKUECx305VIlzh
 qMiS/kT3PIBfKeyOQ21/HEkY3D3Ci9gV6zD2rVtDF6n+toyyA/0B3ROEvWGbW6Zng0QwnDCoxnSJQ
 JBIcC8+nMLzxdU7Q9JnRx/eUM+BO3a+ev4L4yt5jlTGldYbzkRp6kRdqZVnxDeqWdmoY=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolv-0005wD-BE
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMolv-0005Vd-9y
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/iommu: remove code to fetch MSI message from remap
 table
Message-Id: <E1kMolv-0005Vd-9y@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 08:44:35 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 28fb8cf323dd93f59a9c851c93ba9b79de8b1c4e
Author:     Roger Pau Monné <roger.pau@citrix.com>
AuthorDate: Mon Sep 28 10:42:29 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 28 10:42:29 2020 +0200

    x86/iommu: remove code to fetch MSI message from remap table
    
    Remove the code to compose a MSI message based on the information from
    the MSI registers and the data in the interrupt remapping table.
    Since the removal of read_msi_msg and its user there's no longer a
    need for such code, as the last written (untranslated) MSI message is
    cached internally by Xen.
    
    Suggested-by: Jan Beulich <jbeulich@suse.com>
    Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/drivers/passthrough/amd/iommu.h         |  2 -
 xen/drivers/passthrough/amd/iommu_intr.c    | 41 ----------------
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  1 -
 xen/drivers/passthrough/pci.c               |  7 ---
 xen/drivers/passthrough/vtd/extern.h        |  1 -
 xen/drivers/passthrough/vtd/intremap.c      | 76 -----------------------------
 xen/drivers/passthrough/vtd/iommu.c         |  1 -
 xen/include/xen/iommu.h                     |  1 -
 8 files changed, 130 deletions(-)

diff --git a/xen/drivers/passthrough/amd/iommu.h b/xen/drivers/passthrough/amd/iommu.h
index f1f0415469..28a44ceb85 100644
--- a/xen/drivers/passthrough/amd/iommu.h
+++ b/xen/drivers/passthrough/amd/iommu.h
@@ -277,8 +277,6 @@ unsigned int amd_iommu_read_ioapic_from_ire(
     unsigned int apic, unsigned int reg);
 int amd_iommu_msi_msg_update_ire(
     struct msi_desc *msi_desc, struct msi_msg *msg);
-void amd_iommu_read_msi_from_ire(
-    struct msi_desc *msi_desc, struct msi_msg *msg);
 int amd_setup_hpet_msi(struct msi_desc *msi_desc);
 void amd_iommu_dump_intremap_tables(unsigned char key);
 
diff --git a/xen/drivers/passthrough/amd/iommu_intr.c b/xen/drivers/passthrough/amd/iommu_intr.c
index 0adee53fb8..d78bb209bc 100644
--- a/xen/drivers/passthrough/amd/iommu_intr.c
+++ b/xen/drivers/passthrough/amd/iommu_intr.c
@@ -659,47 +659,6 @@ int amd_iommu_msi_msg_update_ire(
     return rc;
 }
 
-void amd_iommu_read_msi_from_ire(
-    struct msi_desc *msi_desc, struct msi_msg *msg)
-{
-    unsigned int offset = msg->data & (INTREMAP_MAX_ENTRIES - 1);
-    const struct pci_dev *pdev = msi_desc->dev;
-    u16 bdf = pdev ? PCI_BDF2(pdev->bus, pdev->devfn) : hpet_sbdf.bdf;
-    u16 seg = pdev ? pdev->seg : hpet_sbdf.seg;
-    const struct amd_iommu *iommu = _find_iommu_for_device(seg, bdf);
-    union irte_ptr entry;
-
-    if ( IS_ERR_OR_NULL(iommu) )
-        return;
-
-    entry = get_intremap_entry(iommu, get_dma_requestor_id(seg, bdf), offset);
-
-    if ( msi_desc->msi_attrib.type == PCI_CAP_ID_MSI )
-    {
-        int nr = msi_desc->msi_attrib.entry_nr;
-
-        ASSERT(!(offset & (msi_desc[-nr].msi.nvec - 1)));
-        offset |= nr;
-    }
-
-    msg->data &= ~(INTREMAP_MAX_ENTRIES - 1);
-    /* The IntType fields match for both formats. */
-    msg->data |= MASK_INSR(entry.ptr32->flds.int_type,
-                           MSI_DATA_DELIVERY_MODE_MASK);
-    if ( iommu->ctrl.ga_en )
-    {
-        msg->data |= MASK_INSR(entry.ptr128->full.vector,
-                               MSI_DATA_VECTOR_MASK);
-        msg->dest32 = get_full_dest(entry.ptr128);
-    }
-    else
-    {
-        msg->data |= MASK_INSR(entry.ptr32->flds.vector,
-                               MSI_DATA_VECTOR_MASK);
-        msg->dest32 = entry.ptr32->flds.dest;
-    }
-}
-
 int amd_iommu_free_intremap_table(
     const struct amd_iommu *iommu, struct ivrs_mappings *ivrs_mapping,
     uint16_t bdf)
diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c
index 3390c22cf3..304363f5d2 100644
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -572,7 +572,6 @@ static const struct iommu_ops __initconstrel _iommu_ops = {
     .update_ire_from_apic = amd_iommu_ioapic_update_ire,
     .update_ire_from_msi = amd_iommu_msi_msg_update_ire,
     .read_apic_from_ire = amd_iommu_read_ioapic_from_ire,
-    .read_msi_from_ire = amd_iommu_read_msi_from_ire,
     .setup_hpet_msi = amd_setup_hpet_msi,
     .adjust_irq_affinities = iov_adjust_irq_affinities,
     .suspend = amd_iommu_suspend,
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index e54974bcb0..b035067975 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -1382,13 +1382,6 @@ int iommu_update_ire_from_msi(
            ? iommu_call(&iommu_ops, update_ire_from_msi, msi_desc, msg) : 0;
 }
 
-void iommu_read_msi_from_ire(
-    struct msi_desc *msi_desc, struct msi_msg *msg)
-{
-    if ( iommu_intremap )
-        iommu_vcall(&iommu_ops, read_msi_from_ire, msi_desc, msg);
-}
-
 static int iommu_add_device(struct pci_dev *pdev)
 {
     const struct domain_iommu *hd;
diff --git a/xen/drivers/passthrough/vtd/extern.h b/xen/drivers/passthrough/vtd/extern.h
index ada3c3098c..ad6c5f907b 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -85,7 +85,6 @@ void io_apic_write_remap_rte(unsigned int apic,
 
 struct msi_desc;
 struct msi_msg;
-void msi_msg_read_remap_rte(struct msi_desc *, struct msi_msg *);
 int msi_msg_write_remap_rte(struct msi_desc *, struct msi_msg *);
 
 int intel_setup_hpet_msi(struct msi_desc *);
diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrough/vtd/intremap.c
index 0d2a9d78de..d0f70d90eb 100644
--- a/xen/drivers/passthrough/vtd/intremap.c
+++ b/xen/drivers/passthrough/vtd/intremap.c
@@ -532,68 +532,6 @@ static void set_msi_source_id(struct pci_dev *pdev, struct iremap_entry *ire)
    }
 }
 
-static int remap_entry_to_msi_msg(
-    struct vtd_iommu *iommu, struct msi_msg *msg, unsigned int index)
-{
-    struct iremap_entry *iremap_entry = NULL, *iremap_entries;
-    struct msi_msg_remap_entry *remap_rte;
-    unsigned long flags;
-
-    remap_rte = (struct msi_msg_remap_entry *) msg;
-    index += (remap_rte->address_lo.index_15 << 15) |
-             remap_rte->address_lo.index_0_14;
-
-    if ( index >= IREMAP_ENTRY_NR )
-    {
-        dprintk(XENLOG_ERR VTDPREFIX,
-                "MSI index (%d) for remap table is invalid\n",
-                index);
-        return -EFAULT;
-    }
-
-    spin_lock_irqsave(&iommu->intremap.lock, flags);
-
-    GET_IREMAP_ENTRY(iommu->intremap.maddr, index,
-                     iremap_entries, iremap_entry);
-
-    if ( iremap_entry->val == 0 )
-    {
-        dprintk(XENLOG_ERR VTDPREFIX,
-                "MSI index (%d) has an empty entry\n",
-                index);
-        unmap_vtd_domain_page(iremap_entries);
-        spin_unlock_irqrestore(&iommu->intremap.lock, flags);
-        return -EFAULT;
-    }
-
-    msg->address_hi = MSI_ADDR_BASE_HI;
-    msg->address_lo =
-        MSI_ADDR_BASE_LO |
-        ((iremap_entry->remap.dm == 0) ?
-            MSI_ADDR_DESTMODE_PHYS:
-            MSI_ADDR_DESTMODE_LOGIC) |
-        ((iremap_entry->remap.dlm != dest_LowestPrio) ?
-            MSI_ADDR_REDIRECTION_CPU:
-            MSI_ADDR_REDIRECTION_LOWPRI);
-    if ( x2apic_enabled )
-        msg->dest32 = iremap_entry->remap.dst;
-    else
-        msg->dest32 = (iremap_entry->remap.dst >> 8) & 0xff;
-    msg->address_lo |= MSI_ADDR_DEST_ID(msg->dest32);
-
-    msg->data =
-        MSI_DATA_TRIGGER_EDGE |
-        MSI_DATA_LEVEL_ASSERT |
-        ((iremap_entry->remap.dlm != dest_LowestPrio) ?
-            MSI_DATA_DELIVERY_FIXED:
-            MSI_DATA_DELIVERY_LOWPRI) |
-        iremap_entry->remap.vector;
-
-    unmap_vtd_domain_page(iremap_entries);
-    spin_unlock_irqrestore(&iommu->intremap.lock, flags);
-    return 0;
-}
-
 static int msi_msg_to_remap_entry(
     struct vtd_iommu *iommu, struct pci_dev *pdev,
     struct msi_desc *msi_desc, struct msi_msg *msg)
@@ -701,20 +639,6 @@ static int msi_msg_to_remap_entry(
     return 0;
 }
 
-void msi_msg_read_remap_rte(
-    struct msi_desc *msi_desc, struct msi_msg *msg)
-{
-    struct pci_dev *pdev = msi_desc->dev;
-    struct acpi_drhd_unit *drhd = NULL;
-
-    drhd = pdev ? acpi_find_matched_drhd_unit(pdev)
-                : hpet_to_drhd(msi_desc->hpet_id);
-    if ( drhd )
-        remap_entry_to_msi_msg(drhd->iommu, msg,
-                               msi_desc->msi_attrib.type == PCI_CAP_ID_MSI
-                               ? msi_desc->msi_attrib.entry_nr : 0);
-}
-
 int msi_msg_write_remap_rte(
     struct msi_desc *msi_desc, struct msi_msg *msg)
 {
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index 68cf0e535a..f6c4021fd6 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -2714,7 +2714,6 @@ static struct iommu_ops __initdata vtd_ops = {
     .update_ire_from_apic = io_apic_write_remap_rte,
     .update_ire_from_msi = msi_msg_write_remap_rte,
     .read_apic_from_ire = io_apic_read_remap_rte,
-    .read_msi_from_ire = msi_msg_read_remap_rte,
     .setup_hpet_msi = intel_setup_hpet_msi,
     .adjust_irq_affinities = adjust_vtd_irq_affinities,
     .suspend = vtd_suspend,
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 13f68dc93d..191021870f 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -194,7 +194,6 @@ struct msi_desc;
 struct msi_msg;
 
 int iommu_update_ire_from_msi(struct msi_desc *msi_desc, struct msi_msg *msg);
-void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);
 
 #define PT_IRQ_TIME_OUT MILLISECS(8)
 #endif /* HAS_PCI */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 08:44:47 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 08:44:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMom7-0007yo-AI; Mon, 28 Sep 2020 08:44:47 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMom6-0007yf-CI
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:46 +0000
X-Inumbo-ID: d97b5fc4-aeef-4139-a2dc-dbb1a336f9d7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id d97b5fc4-aeef-4139-a2dc-dbb1a336f9d7;
 Mon, 28 Sep 2020 08:44:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=v2kMBEwCNbphaz05NthbgD2MoWDdfF1f4Yq6/O/tXQE=; b=OQ1PhBZWMI1eRUAY8zT0yZ1kmp
 58ATW0w6bHNHkudFq3ooI8b069YtHCj9zIuQwiftCaoxwBDbqoKHDfM9x2kQo57vhYnxdeSVyRxmJ
 Sklz08NB6Gizxm99CrKsVgUjMKvvPaxpMrY0MQ3T8yrX9gxdwraiwRzGraAnFmsRIeHc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMom5-0005xs-Dz
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMom5-0005Xx-DM
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 08:44:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/S3: fix shadow stack resume path
Message-Id: <E1kMom5-0005Xx-DM@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 08:44:45 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 4bdbf746ac9152e70f264f87db4472707da805ce
Author:     Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
AuthorDate: Mon Sep 28 10:43:10 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Mon Sep 28 10:43:10 2020 +0200

    x86/S3: fix shadow stack resume path
    
    Fix the resume path to load the shadow stack pointer from saved_ssp (not
    saved_rsp), to match what suspend path does.
    
    Fixes: 633ecc4a7cb2 ("x86/S3: Save and restore Shadow Stack configuration")
    Backport: 4.14
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/acpi/wakeup_prot.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/acpi/wakeup_prot.S b/xen/arch/x86/acpi/wakeup_prot.S
index a2c41c4f3f..c6b3fcc93d 100644
--- a/xen/arch/x86/acpi/wakeup_prot.S
+++ b/xen/arch/x86/acpi/wakeup_prot.S
@@ -69,7 +69,7 @@ ENTRY(s3_resume)
          * so SETSSBSY will successfully load a value useful for us, then
          * reset MSR_PL0_SSP to its usual value and pop the temporary token.
          */
-        mov     saved_rsp(%rip), %rdi
+        mov     saved_ssp(%rip), %rdi
         cmpq    $1, %rdi
         je      .L_shstk_done
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 17:55:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 17:55:18 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMxMj-0005RH-L1; Mon, 28 Sep 2020 17:55:09 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMxMi-0005RC-9b
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:08 +0000
X-Inumbo-ID: 592b496b-a0f4-4d92-a22b-aaf636d17955
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 592b496b-a0f4-4d92-a22b-aaf636d17955;
 Mon, 28 Sep 2020 17:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=p1/+gETEIOtFykRGJWBAD0df4x4xnH6eLceQyLs6Hiw=; b=B/AlnH4Fb0gymd1tPGCWkLCxU5
 UPY8eWZeaLX/VxItfvkbCqpWvV55TkSXMzFOwobJ6hKFV+8VpUZKGm2S93VHZHBeqVU/TRKX+dZ0s
 +PUcLZeU6MLvHlyeaR3u0ydP/H+Dc1Tcz+x+yntONDWsf3smrRc9TioBXq63gWV0ZH2M=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMxMg-0001Hc-2x
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMxMg-0005If-03
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] xen/arm: sched: Ensure the vCPU context is seen before
 vcpu_pause() returns
Message-Id: <E1kMxMg-0005If-03@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 17:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit f6790389613cd54775ece6575013a679572b46b3
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Tue Sep 22 20:31:04 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 28 18:42:54 2020 +0100

    xen/arm: sched: Ensure the vCPU context is seen before vcpu_pause() returns
    
    Some callers of vcpu_pause() will expect to access the latest vcpu
    context when the function returns (see XENDOMCTL_{set,get}vcpucontext}.
    
    However, the latest vCPU context can only be observed after
    v->is_running has been observed to be false.
    
    As there is no memory barrier instruction generated, a processor could
    try to speculatively access the vCPU context before it was observed.
    
    To prevent the corruption of the vCPU context, we need to insert a
    memory barrier instruction after v->is_running is observed and before
    the context is accessed. This barrier is added in sync_vcpu_execstate()
    as it seems to be the place where we expect the synchronization to
    happen.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 xen/arch/arm/domain.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 9258f6d3fa..3b37f899b9 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -371,7 +371,20 @@ void sync_local_execstate(void)
 
 void sync_vcpu_execstate(struct vcpu *v)
 {
-    /* Nothing to do -- no lazy switching */
+    /*
+     * We don't support lazy switching.
+     *
+     * However the context may have been saved from a remote pCPU so we
+     * need a barrier to ensure it is observed before continuing.
+     *
+     * Per vcpu_context_saved(), the context can be observed when
+     * v->is_running is false (the caller should check it before calling
+     * this function).
+     *
+     * Note this is a full barrier to also prevent update of the context
+     * to happen before it was observed.
+     */
+    smp_mb();
 }
 
 #define NEXT_ARG(fmt, args)                                                 \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Mon Sep 28 17:55:19 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Mon, 28 Sep 2020 17:55:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kMxMt-0005Rg-MW; Mon, 28 Sep 2020 17:55:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=o0zF=DF=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kMxMs-0005RQ-C7
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:18 +0000
X-Inumbo-ID: 37a24252-4300-48c4-bbc0-a2ae71d55384
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 37a24252-4300-48c4-bbc0-a2ae71d55384;
 Mon, 28 Sep 2020 17:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=SQ3YhazhoT3vDZsMTC9QACV9zKljzHa7Bjq5rxBRaJU=; b=i60QwR7ipXz/eHvPk0wEQE/DDF
 LyfivkzAeiNj8sKn+diAS7vNRKBKlooXTDlxmWkUNaoebHxrvmxOhDTNa8Mktbvrr6xsIpKkGzf6/
 pPjh2p5LR36lGQ/Q0ZV7vFQ9VTQ3PRfmxn9qeFXhaixpq1Gp4Ly//RJdZ2e8UeDoJ7kg=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMxMq-0001Hf-HO
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kMxMq-0005JP-5P
 for xen-changelog@lists.xenproject.org; Mon, 28 Sep 2020 17:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] SUPPORT.MD: Clarify the support state for the Arm
 SMMUv{1, 2} drivers
Message-Id: <E1kMxMq-0005JP-5P@xenbits.xenproject.org>
Date: Mon, 28 Sep 2020 17:55:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 28804c0ce9fde36feec04ad7f57b2683875da8a0
Author:     Julien Grall <jgrall@amazon.com>
AuthorDate: Wed Sep 23 09:28:32 2020 +0100
Commit:     Julien Grall <jgrall@amazon.com>
CommitDate: Mon Sep 28 18:44:48 2020 +0100

    SUPPORT.MD: Clarify the support state for the Arm SMMUv{1, 2} drivers
    
    SMMUv{1, 2} are both marked as security supported, so we would
    technically have to issue an XSA for any IOMMU security bug.
    
    However, at the moment, device passthrough is not security supported
    on Arm and there is no plan to change that in the next few months.
    
    Therefore, mark Arm SMMUv{1, 2} as supported but not security supported.
    
    Signed-off-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
    Acked-by: Stefano Stabellini <sstabellini@kernel.org>
---
 SUPPORT.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/SUPPORT.md b/SUPPORT.md
index 25987ec1df..f35943a432 100644
--- a/SUPPORT.md
+++ b/SUPPORT.md
@@ -62,8 +62,8 @@ supported in this document.
 
     Status, AMD IOMMU: Supported
     Status, Intel VT-d: Supported
-    Status, ARM SMMUv1: Supported
-    Status, ARM SMMUv2: Supported
+    Status, ARM SMMUv1: Supported, not security supported
+    Status, ARM SMMUv2: Supported, not security supported
     Status, Renesas IPMMU-VMSA: Supported, not security supported
 
 ### ARM/GICv3 ITS
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:14 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBPf-0002ER-Te; Tue, 29 Sep 2020 08:55:07 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBPf-0002Dt-BY
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:07 +0000
X-Inumbo-ID: f64cad02-1f58-4353-bdad-61a38fa26554
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id f64cad02-1f58-4353-bdad-61a38fa26554;
 Tue, 29 Sep 2020 08:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=F6clIYf+uPCRQrg7SRVzmlzEm6gKQJFHqOwYHwy/0Pc=; b=Pq1BxXf+Cqg64VODLxnDu92gCc
 nCYdWFqFyjAtj7G2Q32dNu7ZFwFQA+06SJRr+uFzc2w25KoKpz8DZq9x7a5mX6jETdJhMh9ByMj0d
 5fqkIc5EgcmgekuvYBh+tiBSDbuztJVQ4IpPHzpN+48C8d8muFYWcHQHjXlr3JAIM7jw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPe-0005T5-4n
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:06 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPe-0008Cn-2W
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:06 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86: introduce read_sregs() to allow storing to memory
 directly
Message-Id: <E1kNBPe-0008Cn-2W@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:06 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 32a9ecca23b87db659c19fa5fc23c40309ba68ed
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:50:27 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:50:27 2020 +0200

    x86: introduce read_sregs() to allow storing to memory directly
    
    When storing all (data) segment registers in one go, prefer writing the
    selector values directly to memory (as opposed to read_sreg()).
    
    Also move the single register variant into the regs.h, dropping the
    unecessary "volatile" from the asm() (there are no hidden side effects).
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/domain.c        |  5 +----
 xen/arch/x86/x86_64/traps.c  |  5 +----
 xen/include/asm-x86/regs.h   | 14 ++++++++++++++
 xen/include/asm-x86/system.h |  6 ------
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index e8e91cf080..4273d272e7 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1703,10 +1703,7 @@ static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
 
-    regs->ds = read_sreg(ds);
-    regs->es = read_sreg(es);
-    regs->fs = read_sreg(fs);
-    regs->gs = read_sreg(gs);
+    read_sregs(regs);
 
     if ( !is_pv_32bit_vcpu(v) )
     {
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index 93af0c5e87..fd049c5e14 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -43,10 +43,7 @@ static void read_registers(struct cpu_user_regs *regs, unsigned long crs[8])
     crs[2] = read_cr2();
     crs[3] = read_cr3();
     crs[4] = read_cr4();
-    regs->ds = read_sreg(ds);
-    regs->es = read_sreg(es);
-    regs->fs = read_sreg(fs);
-    regs->gs = read_sreg(gs);
+    read_sregs(regs);
     crs[5] = rdfsbase();
     crs[6] = rdgsbase();
     crs[7] = rdgsshadow();
diff --git a/xen/include/asm-x86/regs.h b/xen/include/asm-x86/regs.h
index dc00b854e3..8d984ea388 100644
--- a/xen/include/asm-x86/regs.h
+++ b/xen/include/asm-x86/regs.h
@@ -15,4 +15,18 @@
     (diff == 0);                                                              \
 })
 
+#define read_sreg(name) ({                           \
+    unsigned int __sel;                              \
+    asm ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \
+    __sel;                                           \
+})
+
+static inline void read_sregs(struct cpu_user_regs *regs)
+{
+    asm ( "mov %%ds, %0" : "=m" (regs->ds) );
+    asm ( "mov %%es, %0" : "=m" (regs->es) );
+    asm ( "mov %%fs, %0" : "=m" (regs->fs) );
+    asm ( "mov %%gs, %0" : "=m" (regs->gs) );
+}
+
 #endif /* __X86_REGS_H__ */
diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h
index 7e5891f3df..45c183bd10 100644
--- a/xen/include/asm-x86/system.h
+++ b/xen/include/asm-x86/system.h
@@ -5,12 +5,6 @@
 #include <xen/bitops.h>
 #include <asm/processor.h>
 
-#define read_sreg(name)                                         \
-({  unsigned int __sel;                                         \
-    asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) );   \
-    __sel;                                                      \
-})
-
 static inline void wbinvd(void)
 {
     asm volatile ( "wbinvd" ::: "memory" );
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:17 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBPp-0002FW-VK; Tue, 29 Sep 2020 08:55:17 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBPp-0002FP-IK
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:17 +0000
X-Inumbo-ID: 25941b1f-ebc7-4e02-af0e-2855a89f0a39
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 25941b1f-ebc7-4e02-af0e-2855a89f0a39;
 Tue, 29 Sep 2020 08:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=IyaYKex6kgETd11DZyDK/DaFDp4klrtJ1/aaNgT5jXQ=; b=sNmXahwwkHBMCMA7opDDLOjW3O
 dCz37T+LPbNZhHkVmXDNJagBkWVIWkEYGW9tVllAhFp7RHroh4gZPqauUIeIdAKGsw9Wh1i/25RTk
 WCzFtXkbtzcoEBSNv4l+SYj6aI5C3i+PCtA45D2/Bv8vtmuChoSOzPBu6yIeuH0wR/5g=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPo-0005TD-9W
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPo-0008DX-6u
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/ELF: don't open-code read_sreg()
Message-Id: <E1kNBPo-0008DX-6u@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:16 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 5be4ce01d0fe412230da6825f98cf08a6b4094fe
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:51:12 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:51:12 2020 +0200

    x86/ELF: don't open-code read_sreg()
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/elf.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/elf.h b/xen/include/asm-x86/x86_64/elf.h
index 174c9dffba..09b286422d 100644
--- a/xen/include/asm-x86/x86_64/elf.h
+++ b/xen/include/asm-x86/x86_64/elf.h
@@ -1,6 +1,8 @@
 #ifndef __X86_64_ELF_H__
 #define __X86_64_ELF_H__
 
+#include <asm/regs.h>
+
 typedef struct {
     unsigned long r15;
     unsigned long r14;
@@ -53,16 +55,16 @@ static inline void elf_core_save_regs(ELF_Gregset *core_regs,
     asm volatile("movq %%rdi,%0" : "=m"(core_regs->rdi));
     /* orig_rax not filled in for now */
     core_regs->rip = (unsigned long)elf_core_save_regs;
-    asm volatile("movl %%cs, %%eax;" :"=a"(core_regs->cs));
+    core_regs->cs = read_sreg(cs);
     asm volatile("pushfq; popq %0" :"=m"(core_regs->rflags));
     asm volatile("movq %%rsp,%0" : "=m"(core_regs->rsp));
-    asm volatile("movl %%ss, %%eax;" :"=a"(core_regs->ss));
+    core_regs->ss = read_sreg(ss);
     /* thread_fs not filled in for now */
     /* thread_gs not filled in for now */
-    asm volatile("movl %%ds, %%eax;" :"=a"(core_regs->ds));
-    asm volatile("movl %%es, %%eax;" :"=a"(core_regs->es));
-    asm volatile("movl %%fs, %%eax;" :"=a"(core_regs->fs));
-    asm volatile("movl %%gs, %%eax;" :"=a"(core_regs->gs));
+    core_regs->ds = read_sreg(ds);
+    core_regs->es = read_sreg(es);
+    core_regs->fs = read_sreg(fs);
+    core_regs->gs = read_sreg(gs);
 
     asm volatile("mov %%cr0, %0" : "=r" (tmp) : );
     xen_core_regs->cr0 = tmp;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBQ0-0002Gw-0r; Tue, 29 Sep 2020 08:55:28 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBPz-0002Gm-BL
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:27 +0000
X-Inumbo-ID: 3c2d76b9-dd54-47f8-a921-af411b81c8d7
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 3c2d76b9-dd54-47f8-a921-af411b81c8d7;
 Tue, 29 Sep 2020 08:55:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=irjfF0tGjqo5Ip/xv5fS1YCOZe4SH8Mo1MKCF/5rgFw=; b=GQinlkerQI1DTWuLkPEqnkcQsJ
 MN3jxVGi9c9QEd0TevEYYws6eAqXbny7A/sYpRIcGFsD4Vp5OlIUcq75/uKiYlzqjK2qIemCOrkNW
 n5FK2cCpVCoxarmev9BuXqiV40HNEyReFW+QbDqfJMcue80vRiFK2zYVI2nY6ACyGSVc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPy-0005TR-D6
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBPy-0008ER-Bf
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/ELF: don't store function pointer in
 elf_core_save_regs()
Message-Id: <E1kNBPy-0008ER-Bf@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 1e15dcfbaef6ef5b1cdba73408be6bd9dfc27fe9
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:51:54 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:51:54 2020 +0200

    x86/ELF: don't store function pointer in elf_core_save_regs()
    
    This keeps at least gcc 10 from generating a separate function instance
    in common/kexec.o alongside the inlining of the function in its sole
    caller. I also think putting the address of the actual code storing the
    registers is a better indication to consumers than that of an otherwise
    unreferenced function.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/elf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/include/asm-x86/x86_64/elf.h b/xen/include/asm-x86/x86_64/elf.h
index 09b286422d..43c9cf3a3f 100644
--- a/xen/include/asm-x86/x86_64/elf.h
+++ b/xen/include/asm-x86/x86_64/elf.h
@@ -54,7 +54,7 @@ static inline void elf_core_save_regs(ELF_Gregset *core_regs,
     asm volatile("movq %%rsi,%0" : "=m"(core_regs->rsi));
     asm volatile("movq %%rdi,%0" : "=m"(core_regs->rdi));
     /* orig_rax not filled in for now */
-    core_regs->rip = (unsigned long)elf_core_save_regs;
+    asm ( "call 0f; 0: popq %0" : "=m" (core_regs->rip) );
     core_regs->cs = read_sreg(cs);
     asm volatile("pushfq; popq %0" :"=m"(core_regs->rflags));
     asm volatile("movq %%rsp,%0" : "=m"(core_regs->rsp));
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:39 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:39 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBQB-0002IU-2W; Tue, 29 Sep 2020 08:55:39 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBQ9-0002IK-PE
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:37 +0000
X-Inumbo-ID: eb6cbf77-0946-4a0d-a801-38a5021827a6
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id eb6cbf77-0946-4a0d-a801-38a5021827a6;
 Tue, 29 Sep 2020 08:55:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=2WAyuz+ccnu9+d3g5mdHLQBexV8AdYGld1jvWIoTwXg=; b=hRyzWqwYSM5UlcskTBs7OlOto2
 tAwABFMUHx5BYu9hFTJadXwhjLG8GhCLtZPNXSJForkjMUkyuZ/q+stVKAnNX7t/BKoSF2kEvqsea
 QRUu9M/YMGeQWwCJ7UZQ/UyRNKZ/PIL/rpNvz/eCKNQdWj/hw6xYNBc5we/GRhbBPm9Y=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQ8-0005Ta-H7
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQ8-0008FP-FG
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/ELF: also record FS/GS bases in elf_core_save_regs()
Message-Id: <E1kNBQ8-0008FP-FG@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:36 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit c8b2488a817b3aedbb10fad72d9d41911f40eb17
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:52:32 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:52:32 2020 +0200

    x86/ELF: also record FS/GS bases in elf_core_save_regs()
    
    No idea why this wasn't done before.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/elf.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/elf.h b/xen/include/asm-x86/x86_64/elf.h
index 43c9cf3a3f..f9c2789b7e 100644
--- a/xen/include/asm-x86/x86_64/elf.h
+++ b/xen/include/asm-x86/x86_64/elf.h
@@ -1,6 +1,7 @@
 #ifndef __X86_64_ELF_H__
 #define __X86_64_ELF_H__
 
+#include <asm/msr.h>
 #include <asm/regs.h>
 
 typedef struct {
@@ -59,8 +60,8 @@ static inline void elf_core_save_regs(ELF_Gregset *core_regs,
     asm volatile("pushfq; popq %0" :"=m"(core_regs->rflags));
     asm volatile("movq %%rsp,%0" : "=m"(core_regs->rsp));
     core_regs->ss = read_sreg(ss);
-    /* thread_fs not filled in for now */
-    /* thread_gs not filled in for now */
+    rdmsrl(MSR_FS_BASE, core_regs->thread_fs);
+    rdmsrl(MSR_GS_BASE, core_regs->thread_gs);
     core_regs->ds = read_sreg(ds);
     core_regs->es = read_sreg(es);
     core_regs->fs = read_sreg(fs);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:48 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBQK-0002Kt-41; Tue, 29 Sep 2020 08:55:48 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBQJ-0002Kn-Ft
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:47 +0000
X-Inumbo-ID: b1281a1c-c61b-4320-baa7-e8b1ae2701bc
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b1281a1c-c61b-4320-baa7-e8b1ae2701bc;
 Tue, 29 Sep 2020 08:55:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=i/FFHcg6Hm2+KJOqV/AhJEzVremafFSKadNGq/2NU6E=; b=HGCrkdH683ehIRiWYrwqHgq+Q8
 KDBKX1drxRqwMwxLMTZnis4umayPcPO2AYK8Cq10MR3bQsaHHMRwDzHnadM7kkQpeUtGSoTvZmiXG
 e44QpDB8f3skhoABttXGuYWWCzUUPHAN17L9hxbM7V8xXNn1YsCsIGckfcpA34RV/K8w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQI-0005Tk-Ke
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQI-0008GD-JG
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/ELF: eliminate pointless local variable from
 elf_core_save_regs()
Message-Id: <E1kNBQI-0008GD-JG@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 7c6084c1f37dff3fcc4edbf080d16dec676f55fb
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:53:13 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:53:13 2020 +0200

    x86/ELF: eliminate pointless local variable from elf_core_save_regs()
    
    We can just as well specify the CRn structure fields directly in the
    asm()s, just like done for all other ones.
    
    Also drop the unecessary "volatile" from the asm()-s: There are no
    relevant hidden side effects.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/elf.h | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/elf.h b/xen/include/asm-x86/x86_64/elf.h
index f9c2789b7e..0d5fce515a 100644
--- a/xen/include/asm-x86/x86_64/elf.h
+++ b/xen/include/asm-x86/x86_64/elf.h
@@ -37,8 +37,6 @@ typedef struct {
 static inline void elf_core_save_regs(ELF_Gregset *core_regs, 
                                       crash_xen_core_t *xen_core_regs)
 {
-    unsigned long tmp;
-
     asm volatile("movq %%r15,%0" : "=m"(core_regs->r15));
     asm volatile("movq %%r14,%0" : "=m"(core_regs->r14));
     asm volatile("movq %%r13,%0" : "=m"(core_regs->r13));
@@ -67,17 +65,10 @@ static inline void elf_core_save_regs(ELF_Gregset *core_regs,
     core_regs->fs = read_sreg(fs);
     core_regs->gs = read_sreg(gs);
 
-    asm volatile("mov %%cr0, %0" : "=r" (tmp) : );
-    xen_core_regs->cr0 = tmp;
-
-    asm volatile("mov %%cr2, %0" : "=r" (tmp) : );
-    xen_core_regs->cr2 = tmp;
-
-    asm volatile("mov %%cr3, %0" : "=r" (tmp) : );
-    xen_core_regs->cr3 = tmp;
-
-    asm volatile("mov %%cr4, %0" : "=r" (tmp) : );
-    xen_core_regs->cr4 = tmp;
+    asm ( "mov %%cr0, %0" : "=r" (xen_core_regs->cr0) );
+    asm ( "mov %%cr2, %0" : "=r" (xen_core_regs->cr2) );
+    asm ( "mov %%cr3, %0" : "=r" (xen_core_regs->cr3) );
+    asm ( "mov %%cr4, %0" : "=r" (xen_core_regs->cr4) );
 }
 
 #endif /* __X86_64_ELF_H__ */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 08:55:58 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 08:55:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNBQU-0002MJ-7A; Tue, 29 Sep 2020 08:55:58 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNBQT-0002MC-Lp
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:57 +0000
X-Inumbo-ID: 2fb21795-767a-4aa9-9187-80921eee6ae2
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 2fb21795-767a-4aa9-9187-80921eee6ae2;
 Tue, 29 Sep 2020 08:55:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
 s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
 bh=XAixd0qQd1pk9HWpqUVbl1DwlRb8GGuUCENX6VJtsLY=; b=fKip1ihzMcUUKpP7q28pX8TVcH
 5D2OEkd84cCPN3rUZZDyt9Vt5Tdhp35U7XuWp0QIISysYxnAazUl2xTSSXitUz0adiJcTzOwLdwxj
 L1TXDWKmJcHHPVtX/CfUp8bMKbNaa0Qlh9AZcPg5RcYG9/I6O9YSEthE+yJdkz69YiVw=;
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQS-0005UP-Og
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:56 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNBQS-0008H2-Mn
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 08:55:56 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Subject: [xen staging] x86/ELF: drop unnecessary volatile from asm()-s in
 elf_core_save_regs()
Message-Id: <E1kNBQS-0008H2-Mn@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 08:55:56 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Reply-To: xen-devel@lists.xenproject.org
Errors-To: xen-changelog-bounces@lists.xenproject.org
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>

commit 358d57d411ee759a5a9dbf367179a9ac37faf0b3
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Tue Sep 29 10:53:54 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Tue Sep 29 10:53:54 2020 +0200

    x86/ELF: drop unnecessary volatile from asm()-s in elf_core_save_regs()
    
    There are no hidden side effects here.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/include/asm-x86/x86_64/elf.h | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/xen/include/asm-x86/x86_64/elf.h b/xen/include/asm-x86/x86_64/elf.h
index 0d5fce515a..00227e0e12 100644
--- a/xen/include/asm-x86/x86_64/elf.h
+++ b/xen/include/asm-x86/x86_64/elf.h
@@ -37,26 +37,27 @@ typedef struct {
 static inline void elf_core_save_regs(ELF_Gregset *core_regs, 
                                       crash_xen_core_t *xen_core_regs)
 {
-    asm volatile("movq %%r15,%0" : "=m"(core_regs->r15));
-    asm volatile("movq %%r14,%0" : "=m"(core_regs->r14));
-    asm volatile("movq %%r13,%0" : "=m"(core_regs->r13));
-    asm volatile("movq %%r12,%0" : "=m"(core_regs->r12));
-    asm volatile("movq %%rbp,%0" : "=m"(core_regs->rbp));
-    asm volatile("movq %%rbx,%0" : "=m"(core_regs->rbx));
-    asm volatile("movq %%r11,%0" : "=m"(core_regs->r11));
-    asm volatile("movq %%r10,%0" : "=m"(core_regs->r10));
-    asm volatile("movq %%r9,%0" : "=m"(core_regs->r9));
-    asm volatile("movq %%r8,%0" : "=m"(core_regs->r8));
-    asm volatile("movq %%rax,%0" : "=m"(core_regs->rax));
-    asm volatile("movq %%rcx,%0" : "=m"(core_regs->rcx));
-    asm volatile("movq %%rdx,%0" : "=m"(core_regs->rdx));
-    asm volatile("movq %%rsi,%0" : "=m"(core_regs->rsi));
-    asm volatile("movq %%rdi,%0" : "=m"(core_regs->rdi));
+    asm ( "movq %%r15, %0" : "=m" (core_regs->r15) );
+    asm ( "movq %%r14, %0" : "=m" (core_regs->r14) );
+    asm ( "movq %%r13, %0" : "=m" (core_regs->r13) );
+    asm ( "movq %%r12, %0" : "=m" (core_regs->r12) );
+    asm ( "movq %%rbp, %0" : "=m" (core_regs->rbp) );
+    asm ( "movq %%rbx, %0" : "=m" (core_regs->rbx) );
+    asm ( "movq %%r11, %0" : "=m" (core_regs->r11) );
+    asm ( "movq %%r10, %0" : "=m" (core_regs->r10) );
+    asm ( "movq %%r9, %0" : "=m" (core_regs->r9) );
+    asm ( "movq %%r8, %0" : "=m" (core_regs->r8) );
+    asm ( "movq %%rax, %0" : "=m" (core_regs->rax) );
+    asm ( "movq %%rcx, %0" : "=m" (core_regs->rcx) );
+    asm ( "movq %%rdx, %0" : "=m" (core_regs->rdx) );
+    asm ( "movq %%rsi, %0" : "=m" (core_regs->rsi) );
+    asm ( "movq %%rdi, %0" : "=m" (core_regs->rdi) );
+
     /* orig_rax not filled in for now */
     asm ( "call 0f; 0: popq %0" : "=m" (core_regs->rip) );
     core_regs->cs = read_sreg(cs);
-    asm volatile("pushfq; popq %0" :"=m"(core_regs->rflags));
-    asm volatile("movq %%rsp,%0" : "=m"(core_regs->rsp));
+    asm ( "pushfq; popq %0" : "=m" (core_regs->rflags) );
+    asm ( "movq %%rsp, %0" : "=m" (core_regs->rsp) );
     core_regs->ss = read_sreg(ss);
     rdmsrl(MSR_FS_BASE, core_regs->thread_fs);
     rdmsrl(MSR_GS_BASE, core_regs->thread_gs);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 12:55:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 12:55:14 +0000
Received: from list by lists.xenproject.org with outflank-mailman.191.425 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNF9w-0002Ew-M6; Tue, 29 Sep 2020 12:55:08 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 191.425; Tue, 29 Sep 2020 12:55:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNF9w-0002Eo-J7; Tue, 29 Sep 2020 12:55:08 +0000
Received: by outflank-mailman (input) for mailman id 191;
 Tue, 29 Sep 2020 12:55:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNF9v-0002Ej-IZ
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:07 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 4cd87618-bb80-41b9-b4e4-2d1ecd939544;
 Tue, 29 Sep 2020 12:55:06 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNF9t-0002C7-W5
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNF9t-0002BV-UD
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNF9v-0002Ej-IZ
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:07 +0000
X-Inumbo-ID: 4cd87618-bb80-41b9-b4e4-2d1ecd939544
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 4cd87618-bb80-41b9-b4e4-2d1ecd939544;
	Tue, 29 Sep 2020 12:55:06 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=gGP3poTE7yAx7CbVm9VfeiOBcleMzriY/YbaoZBcaYU=; b=Q0BOSVcb06SjBnvWh+dojiDgln
	6C2/mCeNrixLGq+qBAuqIqcBuPZgHAW5iKVi4B/vxZvDXupoMp617oA4AfJvu1m8SiHDDnnhzRiAR
	fno5weR/51hGQ/SgssAajVYJlBx4xFUQUCDRpsgbzldj+nIfUKtWu7v9/ysmSMcFNt9U=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNF9t-0002C7-W5
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNF9t-0002BV-UD
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] x86/asm: Rename FS/GS base helpers
Message-Id: <E1kNF9t-0002BV-UD@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 12:55:05 +0000

commit b18b8801d0457881282b9dde46ca1100bd5e6476
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 29 13:46:13 2020 +0100

    x86/asm: Rename FS/GS base helpers
    
    They are currently named after the FSGSBASE instructions, but are not thin
    wrappers around said instructions, and therefore do not accurately reflect the
    logic they perform, especially when it comes to functioning safely in non
    FSGSBASE context.
    
    Rename them to {read,write}_{fs,gs}_base() to avoid confusion.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/domain.c             | 10 +++++-----
 xen/arch/x86/hvm/vmx/vmx.c        |  8 ++++----
 xen/arch/x86/pv/domain.c          |  2 +-
 xen/arch/x86/pv/emul-priv-op.c    | 14 +++++++-------
 xen/arch/x86/pv/misc-hypercalls.c |  8 ++++----
 xen/arch/x86/x86_64/traps.c       |  6 +++---
 xen/include/asm-x86/msr.h         | 12 ++++++------
 7 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 4273d272e7..1cc85f4ab9 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1581,9 +1581,9 @@ static void load_segments(struct vcpu *n)
 
     if ( !fs_gs_done && !compat )
     {
-        wrfsbase(n->arch.pv.fs_base);
-        wrgsshadow(n->arch.pv.gs_base_kernel);
-        wrgsbase(n->arch.pv.gs_base_user);
+        write_fs_base(n->arch.pv.fs_base);
+        write_gs_shadow(n->arch.pv.gs_base_kernel);
+        write_gs_base(n->arch.pv.gs_base_user);
 
         /* If in kernel mode then switch the GS bases around. */
         if ( (n->arch.flags & TF_kernel_mode) )
@@ -1707,9 +1707,9 @@ static void save_segments(struct vcpu *v)
 
     if ( !is_pv_32bit_vcpu(v) )
     {
-        unsigned long gs_base = rdgsbase();
+        unsigned long gs_base = read_gs_base();
 
-        v->arch.pv.fs_base = rdfsbase();
+        v->arch.pv.fs_base = read_fs_base();
         if ( v->arch.flags & TF_kernel_mode )
             v->arch.pv.gs_base_kernel = gs_base;
         else
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 998f33fb03..95d109f962 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -512,12 +512,12 @@ static void vmx_save_guest_msrs(struct vcpu *v)
      * We cannot cache SHADOW_GS_BASE while the VCPU runs, as it can
      * be updated at any time via SWAPGS, which we cannot trap.
      */
-    v->arch.hvm.vmx.shadow_gs = rdgsshadow();
+    v->arch.hvm.vmx.shadow_gs = read_gs_shadow();
 }
 
 static void vmx_restore_guest_msrs(struct vcpu *v)
 {
-    wrgsshadow(v->arch.hvm.vmx.shadow_gs);
+    write_gs_shadow(v->arch.hvm.vmx.shadow_gs);
     wrmsrl(MSR_STAR,           v->arch.hvm.vmx.star);
     wrmsrl(MSR_LSTAR,          v->arch.hvm.vmx.lstar);
     wrmsrl(MSR_SYSCALL_MASK,   v->arch.hvm.vmx.sfmask);
@@ -2958,7 +2958,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         break;
 
     case MSR_SHADOW_GS_BASE:
-        *msr_content = rdgsshadow();
+        *msr_content = read_gs_shadow();
         break;
 
     case MSR_STAR:
@@ -3182,7 +3182,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         else if ( msr == MSR_GS_BASE )
             __vmwrite(GUEST_GS_BASE, msr_content);
         else
-            wrgsshadow(msr_content);
+            write_gs_shadow(msr_content);
 
         break;
 
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 44e4ea2582..663e76c773 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -452,7 +452,7 @@ void toggle_guest_mode(struct vcpu *v)
      * Update the cached value of the GS base about to become inactive, as a
      * subsequent context switch won't bother re-reading it.
      */
-    gs_base = rdgsbase();
+    gs_base = read_gs_base();
     if ( v->arch.flags & TF_kernel_mode )
         v->arch.pv.gs_base_kernel = gs_base;
     else
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 61071ae03a..6be72efb5e 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -540,10 +540,10 @@ static int read_segment(enum x86_segment seg,
             reg->base = 0;
             break;
         case x86_seg_fs:
-            reg->base = rdfsbase();
+            reg->base = read_fs_base();
             break;
         case x86_seg_gs:
-            reg->base = rdgsbase();
+            reg->base = read_gs_base();
             break;
         }
 
@@ -900,13 +900,13 @@ static int read_msr(unsigned int reg, uint64_t *val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = rdfsbase();
+        *val = read_fs_base();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) )
             break;
-        *val = rdgsbase();
+        *val = read_gs_base();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
@@ -1024,19 +1024,19 @@ static int write_msr(unsigned int reg, uint64_t val,
     case MSR_FS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
-        wrfsbase(val);
+        write_fs_base(val);
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
-        wrgsbase(val);
+        write_gs_base(val);
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
         if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
             break;
-        wrgsshadow(val);
+        write_gs_shadow(val);
         curr->arch.pv.gs_base_user = val;
         return X86EMUL_OKAY;
 
diff --git a/xen/arch/x86/pv/misc-hypercalls.c b/xen/arch/x86/pv/misc-hypercalls.c
index b353972e3d..3a4e4aa460 100644
--- a/xen/arch/x86/pv/misc-hypercalls.c
+++ b/xen/arch/x86/pv/misc-hypercalls.c
@@ -192,7 +192,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     {
     case SEGBASE_FS:
         if ( is_canonical_address(base) )
-            wrfsbase(base);
+            write_fs_base(base);
         else
             ret = -EINVAL;
         break;
@@ -200,7 +200,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
     case SEGBASE_GS_USER:
         if ( is_canonical_address(base) )
         {
-            wrgsshadow(base);
+            write_gs_shadow(base);
             v->arch.pv.gs_base_user = base;
         }
         else
@@ -209,7 +209,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
 
     case SEGBASE_GS_KERNEL:
         if ( is_canonical_address(base) )
-            wrgsbase(base);
+            write_gs_base(base);
         else
             ret = -EINVAL;
         break;
@@ -258,7 +258,7 @@ long do_set_segment_base(unsigned int which, unsigned long base)
                        : [flat] "r" (FLAT_USER_DS32) );
 
         /* Update the cache of the inactive base, as read from the GDT/LDT. */
-        v->arch.pv.gs_base_user = rdgsbase();
+        v->arch.pv.gs_base_user = read_gs_base();
 
         asm volatile ( safe_swapgs );
         break;
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index fd049c5e14..b1ef40a846 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -44,9 +44,9 @@ static void read_registers(struct cpu_user_regs *regs, unsigned long crs[8])
     crs[3] = read_cr3();
     crs[4] = read_cr4();
     read_sregs(regs);
-    crs[5] = rdfsbase();
-    crs[6] = rdgsbase();
-    crs[7] = rdgsshadow();
+    crs[5] = read_fs_base();
+    crs[6] = read_gs_base();
+    crs[7] = read_gs_shadow();
 }
 
 static void _show_registers(
diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h
index 5c44c79600..5e141ac5a5 100644
--- a/xen/include/asm-x86/msr.h
+++ b/xen/include/asm-x86/msr.h
@@ -156,7 +156,7 @@ static inline unsigned long __rdgsbase(void)
     return base;
 }
 
-static inline unsigned long rdfsbase(void)
+static inline unsigned long read_fs_base(void)
 {
     unsigned long base;
 
@@ -168,7 +168,7 @@ static inline unsigned long rdfsbase(void)
     return base;
 }
 
-static inline unsigned long rdgsbase(void)
+static inline unsigned long read_gs_base(void)
 {
     unsigned long base;
 
@@ -180,7 +180,7 @@ static inline unsigned long rdgsbase(void)
     return base;
 }
 
-static inline unsigned long rdgsshadow(void)
+static inline unsigned long read_gs_shadow(void)
 {
     unsigned long base;
 
@@ -196,7 +196,7 @@ static inline unsigned long rdgsshadow(void)
     return base;
 }
 
-static inline void wrfsbase(unsigned long base)
+static inline void write_fs_base(unsigned long base)
 {
     if ( read_cr4() & X86_CR4_FSGSBASE )
 #ifdef HAVE_AS_FSGSBASE
@@ -208,7 +208,7 @@ static inline void wrfsbase(unsigned long base)
         wrmsrl(MSR_FS_BASE, base);
 }
 
-static inline void wrgsbase(unsigned long base)
+static inline void write_gs_base(unsigned long base)
 {
     if ( read_cr4() & X86_CR4_FSGSBASE )
 #ifdef HAVE_AS_FSGSBASE
@@ -220,7 +220,7 @@ static inline void wrgsbase(unsigned long base)
         wrmsrl(MSR_GS_BASE, base);
 }
 
-static inline void wrgsshadow(unsigned long base)
+static inline void write_gs_shadow(unsigned long base)
 {
     if ( read_cr4() & X86_CR4_FSGSBASE )
     {
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 12:55:18 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 12:55:18 +0000
Received: from list by lists.xenproject.org with outflank-mailman.192.429 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFA6-0002Fm-NU; Tue, 29 Sep 2020 12:55:18 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 192.429; Tue, 29 Sep 2020 12:55:18 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFA6-0002Fe-Kd; Tue, 29 Sep 2020 12:55:18 +0000
Received: by outflank-mailman (input) for mailman id 192;
 Tue, 29 Sep 2020 12:55:17 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNFA5-0002FX-OM
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:17 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 39e2f20b-f490-4b3e-a577-ead428709ed3;
 Tue, 29 Sep 2020 12:55:16 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFA4-0002CA-7v
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFA4-0002CE-2B
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:16 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNFA5-0002FX-OM
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:17 +0000
X-Inumbo-ID: 39e2f20b-f490-4b3e-a577-ead428709ed3
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id 39e2f20b-f490-4b3e-a577-ead428709ed3;
	Tue, 29 Sep 2020 12:55:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=MDgGBkcBP9MCWTII3NMirt2vPX+ufw10JnCLEdvGTq0=; b=lHeK88wzwlC3QjMPc1WCaoEDXE
	f8nLONYSZB7csVm8x3qBeT2Setf/VJyjo2B1Zo67OEZoz712YwvygUKlt19idG4pu3W/AU2Wrk0sk
	5WB+o1tXSTvVq0JJ7MPA8MQy6Pwl02WEJqX7WK30tIhjWQ2QwXjLzPdBJHoz3GeCENkA=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFA4-0002CA-7v
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:16 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFA4-0002CE-2B
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:16 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] x86/asm: Split __wr{fs,gs}base() out of write_{fs,gs}_base()
Message-Id: <E1kNFA4-0002CE-2B@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 12:55:16 +0000

commit ecc9553a12cb14537c851bca43a9f55f23eb6bf0
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 29 13:46:13 2020 +0100

    x86/asm: Split __wr{fs,gs}base() out of write_{fs,gs}_base()
    
    To match the read side which is already split out.  A future change will want
    to use them.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Jan Beulich <jbeulich@suse.com>
---
 xen/include/asm-x86/msr.h | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h
index 5e141ac5a5..16f95e7344 100644
--- a/xen/include/asm-x86/msr.h
+++ b/xen/include/asm-x86/msr.h
@@ -156,6 +156,24 @@ static inline unsigned long __rdgsbase(void)
     return base;
 }
 
+static inline void __wrfsbase(unsigned long base)
+{
+#ifdef HAVE_AS_FSGSBASE
+    asm volatile ( "wrfsbase %0" :: "r" (base) );
+#else
+    asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
+#endif
+}
+
+static inline void __wrgsbase(unsigned long base)
+{
+#ifdef HAVE_AS_FSGSBASE
+    asm volatile ( "wrgsbase %0" :: "r" (base) );
+#else
+    asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
+#endif
+}
+
 static inline unsigned long read_fs_base(void)
 {
     unsigned long base;
@@ -199,11 +217,7 @@ static inline unsigned long read_gs_shadow(void)
 static inline void write_fs_base(unsigned long base)
 {
     if ( read_cr4() & X86_CR4_FSGSBASE )
-#ifdef HAVE_AS_FSGSBASE
-        asm volatile ( "wrfsbase %0" :: "r" (base) );
-#else
-        asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) );
-#endif
+        __wrfsbase(base);
     else
         wrmsrl(MSR_FS_BASE, base);
 }
@@ -211,11 +225,7 @@ static inline void write_fs_base(unsigned long base)
 static inline void write_gs_base(unsigned long base)
 {
     if ( read_cr4() & X86_CR4_FSGSBASE )
-#ifdef HAVE_AS_FSGSBASE
-        asm volatile ( "wrgsbase %0" :: "r" (base) );
-#else
-        asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) );
-#endif
+        __wrgsbase(base);
     else
         wrmsrl(MSR_GS_BASE, base);
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 12:55:28 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 12:55:28 +0000
Received: from list by lists.xenproject.org with outflank-mailman.193.433 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAG-0002HI-P3; Tue, 29 Sep 2020 12:55:28 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 193.433; Tue, 29 Sep 2020 12:55:28 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAG-0002HA-MA; Tue, 29 Sep 2020 12:55:28 +0000
Received: by outflank-mailman (input) for mailman id 193;
 Tue, 29 Sep 2020 12:55:27 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNFAF-0002H1-QY
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:27 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 5e9d51d1-f970-4f2e-ad42-16bc9363d7d8;
 Tue, 29 Sep 2020 12:55:26 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAE-0002CT-C1
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAE-0002D2-AH
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:26 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNFAF-0002H1-QY
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:27 +0000
X-Inumbo-ID: 5e9d51d1-f970-4f2e-ad42-16bc9363d7d8
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id 5e9d51d1-f970-4f2e-ad42-16bc9363d7d8;
	Tue, 29 Sep 2020 12:55:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=AdrWaSGySbahkrf66nb5GRBt74elLb5g7lkP1pchE5E=; b=QFQWf7bUeBLndX3E+nZ9f7dWVg
	ahHwyH0NH2Kbj75QME2pH837/7+zcRlTS//qfrFy1anbBWuXNG7DnK3lZSquVnnvLJwcqnqqqG7eK
	HaE96/bBEoK28KLjcOlH7TDbwhzFuPb2FM6HeB06ipH1vK/aGLTWyWaAkfCsFDdmkYtc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAE-0002CT-C1
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:26 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAE-0002D2-AH
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:26 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] x86/pv: Optimise prefetching in svm_load_segs()
Message-Id: <E1kNFAE-0002D2-AH@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 12:55:26 +0000

commit fca8d65d94939e05f7eff147358e58ffeb424e6e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 8 18:53:25 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 29 13:46:13 2020 +0100

    x86/pv: Optimise prefetching in svm_load_segs()
    
    Split into two functions.  Passing a load of zeros in results in unnecessary
    caller setup code.
    
    Update the prefetching comment to note that the main point is the TLB fill.
    
    Reorder the writes in svm_load_segs() to access the VMCB fields in ascending
    order, which gets better next-line prefetch behaviour out of hardware.  Update
    the prefetch instruction to match.
    
    The net delta is:
    
      add/remove: 1/0 grow/shrink: 0/2 up/down: 38/-39 (-1)
      Function                                     old     new   delta
      svm_load_segs_prefetch                         -      38     +38
      __context_switch                             967     951     -16
      svm_load_segs                                291     268     -23
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c             |  2 +-
 xen/arch/x86/hvm/svm/svm.c        | 43 ++++++++++++++++++++-------------------
 xen/include/asm-x86/hvm/svm/svm.h |  5 +++--
 3 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 1cc85f4ab9..5ce11cebf8 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1925,7 +1925,7 @@ static void __context_switch(void)
     /* Prefetch the VMCB if we expect to use it later in the context switch */
     if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
          !is_idle_domain(nd) )
-        svm_load_segs(0, 0, 0, 0, 0);
+        svm_load_segs_prefetch();
 #endif
 
     if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index fa9fca94e2..9b65445577 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1520,6 +1520,19 @@ static void svm_init_erratum_383(const struct cpuinfo_x86 *c)
 }
 
 #ifdef CONFIG_PV
+void svm_load_segs_prefetch(void)
+{
+    const struct vmcb_struct *vmcb = this_cpu(host_vmcb_va);
+
+    if ( vmcb )
+        /*
+         * The main reason for this prefetch is for the TLB fill.  Use the
+         * opportunity to fetch the lowest address used, to get the best
+         * behaviour out of hardware's next-line prefetcher.
+         */
+        prefetchw(&vmcb->fs);
+}
+
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
                    unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow)
@@ -1530,17 +1543,15 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
     if ( unlikely(!vmcb) )
         return false;
 
-    if ( !ldt_base )
-    {
-        /*
-         * The actual structure field used here was arbitrarily chosen.
-         * Empirically it doesn't seem to matter much which element is used,
-         * and a clear explanation of the otherwise poor performance has not
-         * been found/provided so far.
-         */
-        prefetchw(&vmcb->ldtr);
-        return true;
-    }
+    vmcb->fs.sel = 0;
+    vmcb->fs.attr = 0;
+    vmcb->fs.limit = 0;
+    vmcb->fs.base = fs_base;
+
+    vmcb->gs.sel = 0;
+    vmcb->gs.attr = 0;
+    vmcb->gs.limit = 0;
+    vmcb->gs.base = gs_base;
 
     if ( likely(!ldt_ents) )
         memset(&vmcb->ldtr, 0, sizeof(vmcb->ldtr));
@@ -1558,16 +1569,6 @@ bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
         vmcb->ldtr.base = ldt_base;
     }
 
-    vmcb->fs.sel = 0;
-    vmcb->fs.attr = 0;
-    vmcb->fs.limit = 0;
-    vmcb->fs.base = fs_base;
-
-    vmcb->gs.sel = 0;
-    vmcb->gs.attr = 0;
-    vmcb->gs.limit = 0;
-    vmcb->gs.base = gs_base;
-
     vmcb->kerngsbase = gs_shadow;
 
     svm_vmload_pa(per_cpu(host_vmcb, cpu));
diff --git a/xen/include/asm-x86/hvm/svm/svm.h b/xen/include/asm-x86/hvm/svm/svm.h
index 2310878e41..faeca40174 100644
--- a/xen/include/asm-x86/hvm/svm/svm.h
+++ b/xen/include/asm-x86/hvm/svm/svm.h
@@ -50,12 +50,13 @@ void __update_guest_eip(struct cpu_user_regs *regs, unsigned int inst_len);
 void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
 
 /*
- * PV context switch helper. Calls with zero ldt_base request a prefetch of
- * the VMCB area to be loaded from, instead of an actual load of state.
+ * PV context switch helpers.  Prefetching the VMCB area itself has been shown
+ * to be useful for performance.
  *
  * Must only be used for NUL FS/GS, as the segment attributes/limits are not
  * read from the GDT/LDT.
  */
+void svm_load_segs_prefetch(void);
 bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
                    unsigned long fs_base, unsigned long gs_base,
                    unsigned long gs_shadow);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 12:55:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 12:55:38 +0000
Received: from list by lists.xenproject.org with outflank-mailman.194.436 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAQ-0002J6-RA; Tue, 29 Sep 2020 12:55:38 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 194.436; Tue, 29 Sep 2020 12:55:38 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAQ-0002J0-Nc; Tue, 29 Sep 2020 12:55:38 +0000
Received: by outflank-mailman (input) for mailman id 194;
 Tue, 29 Sep 2020 12:55:37 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNFAP-0002IR-OL
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:37 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id ba39101c-df81-4b1c-8632-eb134c8fa00a;
 Tue, 29 Sep 2020 12:55:36 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAO-0002Cb-Fg
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAO-0002Du-Eb
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNFAP-0002IR-OL
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:37 +0000
X-Inumbo-ID: ba39101c-df81-4b1c-8632-eb134c8fa00a
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id ba39101c-df81-4b1c-8632-eb134c8fa00a;
	Tue, 29 Sep 2020 12:55:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=mg4DvmzCTcAyTa9eXT+Mj5Yd+7W4/GadCZOyjLG2ivg=; b=x+OytU3Rq5qpgnuSw/vJMvf+pG
	WfHlsZHjNOxh6fDYJeZZNJvHenC11pbtm5op0nsHE/+vmLnv/p/Ok+QiKpne3ZtDxOWwONM+7dnAA
	fA75pFLnqThIv7GvL4p4enqt/eW3NfeyJLAzAIir3J+Ie4sk3/MDT2MQ0Yiud/g8udUo=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAO-0002Cb-Fg
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:36 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAO-0002Du-Eb
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:36 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] x86/pv: Optimise to the segment context switching paths
Message-Id: <E1kNFAO-0002Du-Eb@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 12:55:36 +0000

commit cbe69ba3e8e0499fac73cb91caebb8732e08f577
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Aug 11 16:05:06 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 29 13:46:13 2020 +0100

    x86/pv: Optimise to the segment context switching paths
    
    Opencode the fs/gs helpers, as the optimiser is unable to rearrange the logic
    down to a single X86_CR4_FSGSBASE check.  This removes several jumps and
    creates bigger basic blocks.
    
    In load_segments(), optimise GS base handling substantially.  The call to
    svm_load_segs() already needs gsb/gss the correct way around, so hoist the
    logic for the later path to use it as well.  Swapping the inputs in GPRs is
    far more efficient than using SWAPGS.
    
    Previously, there was optionally one SWAPGS from the user/kernel mode check,
    two SWAPGS's in write_gs_shadow() and two WRGSBASE's.  Updates to GS (4 or 5
    here) in quick succession stall all contemporary pipelines repeatedly.  (Intel
    Core/Xeon pipelines have segment register renaming[1], so can continue to
    speculatively execute with one GS update in flight.  Other pipelines cannot
    have two updates in flight concurrently, and must stall dispatch of the second
    until the first has retired.)
    
    Rewrite the logic to have exactly two WRGSBASEs and one SWAPGS, which removes
    two stalles all contemporary processors.
    
    Although modest, the resulting delta is:
    
      add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106 (-106)
      Function                                     old     new   delta
      paravirt_ctxt_switch_from                    235     198     -37
      context_switch                              3582    3513     -69
    
    in a common path.
    
    [1] https://software.intel.com/security-software-guidance/insights/deep-dive-intel-analysis-speculative-behavior-swapgs-and-segment-registers
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/domain.c | 59 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 5ce11cebf8..7e16d49bfd 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1537,6 +1537,7 @@ arch_do_vcpu_op(
 static void load_segments(struct vcpu *n)
 {
     struct cpu_user_regs *uregs = &n->arch.user_regs;
+    unsigned long gsb = 0, gss = 0;
     bool compat = is_pv_32bit_vcpu(n);
     bool all_segs_okay = true, fs_gs_done = false;
 
@@ -1556,18 +1557,25 @@ static void load_segments(struct vcpu *n)
                    : [ok] "+r" (all_segs_okay)          \
                    : [_val] "rm" (val) )
 
-#ifdef CONFIG_HVM
-    if ( cpu_has_svm && !compat && (uregs->fs | uregs->gs) <= 3 )
+    if ( !compat )
     {
-        unsigned long gsb = n->arch.flags & TF_kernel_mode
-            ? n->arch.pv.gs_base_kernel : n->arch.pv.gs_base_user;
-        unsigned long gss = n->arch.flags & TF_kernel_mode
-            ? n->arch.pv.gs_base_user : n->arch.pv.gs_base_kernel;
+        gsb = n->arch.pv.gs_base_kernel;
+        gss = n->arch.pv.gs_base_user;
 
-        fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
-                                   n->arch.pv.fs_base, gsb, gss);
-    }
+        /*
+         * Figure out which way around gsb/gss want to be.  gsb needs to be
+         * the active context, and gss needs to be the inactive context.
+         */
+        if ( !(n->arch.flags & TF_kernel_mode) )
+            SWAP(gsb, gss);
+
+#ifdef CONFIG_HVM
+        if ( cpu_has_svm && (uregs->fs | uregs->gs) <= 3 )
+            fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n),
+                                       n->arch.pv.fs_base, gsb, gss);
 #endif
+    }
+
     if ( !fs_gs_done )
     {
         load_LDT(n);
@@ -1581,13 +1589,19 @@ static void load_segments(struct vcpu *n)
 
     if ( !fs_gs_done && !compat )
     {
-        write_fs_base(n->arch.pv.fs_base);
-        write_gs_shadow(n->arch.pv.gs_base_kernel);
-        write_gs_base(n->arch.pv.gs_base_user);
-
-        /* If in kernel mode then switch the GS bases around. */
-        if ( (n->arch.flags & TF_kernel_mode) )
+        if ( read_cr4() & X86_CR4_FSGSBASE )
+        {
+            __wrgsbase(gss);
+            __wrfsbase(n->arch.pv.fs_base);
             asm volatile ( "swapgs" );
+            __wrgsbase(gsb);
+        }
+        else
+        {
+            wrmsrl(MSR_FS_BASE, n->arch.pv.fs_base);
+            wrmsrl(MSR_GS_BASE, gsb);
+            wrmsrl(MSR_SHADOW_GS_BASE, gss);
+        }
     }
 
     if ( unlikely(!all_segs_okay) )
@@ -1707,9 +1721,20 @@ static void save_segments(struct vcpu *v)
 
     if ( !is_pv_32bit_vcpu(v) )
     {
-        unsigned long gs_base = read_gs_base();
+        unsigned long fs_base, gs_base;
+
+        if ( read_cr4() & X86_CR4_FSGSBASE )
+        {
+            fs_base = __rdfsbase();
+            gs_base = __rdgsbase();
+        }
+        else
+        {
+            rdmsrl(MSR_FS_BASE, fs_base);
+            rdmsrl(MSR_GS_BASE, gs_base);
+        }
 
-        v->arch.pv.fs_base = read_fs_base();
+        v->arch.pv.fs_base = fs_base;
         if ( v->arch.flags & TF_kernel_mode )
             v->arch.pv.gs_base_kernel = gs_base;
         else
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Tue Sep 29 12:55:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Tue, 29 Sep 2020 12:55:48 +0000
Received: from list by lists.xenproject.org with outflank-mailman.195.441 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAa-0002M5-UC; Tue, 29 Sep 2020 12:55:48 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 195.441; Tue, 29 Sep 2020 12:55:48 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNFAa-0002Lx-Qn; Tue, 29 Sep 2020 12:55:48 +0000
Received: by outflank-mailman (input) for mailman id 195;
 Tue, 29 Sep 2020 12:55:47 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNFAZ-0002Lo-DZ
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:47 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 11ea72e9-46ae-4b1c-aedc-0aad4b8c0e93;
 Tue, 29 Sep 2020 12:55:46 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAY-0002Cj-Io
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNFAY-0002F5-Hs
 for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=2IVA=DG=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNFAZ-0002Lo-DZ
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:47 +0000
X-Inumbo-ID: 11ea72e9-46ae-4b1c-aedc-0aad4b8c0e93
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 11ea72e9-46ae-4b1c-aedc-0aad4b8c0e93;
	Tue, 29 Sep 2020 12:55:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=xOCcnJKqs3c6NRQ6PuokbznRIZk9Du7x7KP2TTul79Q=; b=2KhqX1PrR4hWysHbNSMUSf0cFU
	RooX43xIMi+2/4yUXfNFwpuu6goWYRdh3TAVzGc6ZwnEjFrgFjuEigwhlwWgxtbTAME4zRbeNyG0n
	OcIBpDYUJis6dAAnE/glCKOMTKf2VOIPq3nYZW0dVOMHvixNJrzS8VoPnUc5KTesbMNQ=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAY-0002Cj-Io
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:46 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNFAY-0002F5-Hs
	for xen-changelog@lists.xenproject.org; Tue, 29 Sep 2020 12:55:46 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] x86/pv: Simplify emulation for the 64bit base MSRs
Message-Id: <E1kNFAY-0002F5-Hs@xenbits.xenproject.org>
Date: Tue, 29 Sep 2020 12:55:46 +0000

commit 5dba8c2f23049aa68b777a9e7e9f76c12dd00012
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Fri Sep 4 15:25:09 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Tue Sep 29 13:46:13 2020 +0100

    x86/pv: Simplify emulation for the 64bit base MSRs
    
    is_pv_32bit_domain() is an expensive predicate, but isn't used for speculative
    safety in this case.  Swap to checking the Long Mode bit in the CPUID policy,
    which is the architecturally correct behaviour.
    
    is_canonical_address() is currently moderately simple, but it will become more
    complicated when 5-level support is added.  Rearrange write_msr() to collapse
    the common checks.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/pv/emul-priv-op.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 6be72efb5e..7cc16d6eda 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -877,6 +877,7 @@ static int read_msr(unsigned int reg, uint64_t *val,
 {
     struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
+    const struct cpuid_policy *cp = currd->arch.cpuid;
     bool vpmu_msr = false;
     int ret;
 
@@ -898,19 +899,19 @@ static int read_msr(unsigned int reg, uint64_t *val,
         return X86EMUL_OKAY;
 
     case MSR_FS_BASE:
-        if ( is_pv_32bit_domain(currd) )
+        if ( !cp->extd.lm )
             break;
         *val = read_fs_base();
         return X86EMUL_OKAY;
 
     case MSR_GS_BASE:
-        if ( is_pv_32bit_domain(currd) )
+        if ( !cp->extd.lm )
             break;
         *val = read_gs_base();
         return X86EMUL_OKAY;
 
     case MSR_SHADOW_GS_BASE:
-        if ( is_pv_32bit_domain(currd) )
+        if ( !cp->extd.lm )
             break;
         *val = curr->arch.pv.gs_base_user;
         return X86EMUL_OKAY;
@@ -1006,6 +1007,7 @@ static int write_msr(unsigned int reg, uint64_t val,
 {
     struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
+    const struct cpuid_policy *cp = currd->arch.cpuid;
     bool vpmu_msr = false;
     int ret;
 
@@ -1022,22 +1024,22 @@ static int write_msr(unsigned int reg, uint64_t val,
         uint64_t temp;
 
     case MSR_FS_BASE:
-        if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
-            break;
-        write_fs_base(val);
-        return X86EMUL_OKAY;
-
     case MSR_GS_BASE:
-        if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
-            break;
-        write_gs_base(val);
-        return X86EMUL_OKAY;
-
     case MSR_SHADOW_GS_BASE:
-        if ( is_pv_32bit_domain(currd) || !is_canonical_address(val) )
+        if ( !cp->extd.lm || !is_canonical_address(val) )
             break;
-        write_gs_shadow(val);
-        curr->arch.pv.gs_base_user = val;
+
+        if ( reg == MSR_FS_BASE )
+            write_fs_base(val);
+        else if ( reg == MSR_GS_BASE )
+            write_gs_base(val);
+        else if ( reg == MSR_SHADOW_GS_BASE )
+        {
+            write_gs_shadow(val);
+            curr->arch.pv.gs_base_user = val;
+        }
+        else
+            ASSERT_UNREACHABLE();
         return X86EMUL_OKAY;
 
     case MSR_EFER:
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 07:22:14 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 07:22:14 +0000
Received: from list by lists.xenproject.org with outflank-mailman.448.1385 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRE-0004sX-QC; Wed, 30 Sep 2020 07:22:08 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 448.1385; Wed, 30 Sep 2020 07:22:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRE-0004sP-NI; Wed, 30 Sep 2020 07:22:08 +0000
Received: by outflank-mailman (input) for mailman id 448;
 Wed, 30 Sep 2020 07:22:07 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNWRD-0004rt-40
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:07 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 51573198-f7f5-4156-b134-fa5cee7eb3d3;
 Wed, 30 Sep 2020 07:22:05 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRB-0002Pg-4Y
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRB-0005w1-2I
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNWRD-0004rt-40
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:07 +0000
X-Inumbo-ID: 51573198-f7f5-4156-b134-fa5cee7eb3d3
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 51573198-f7f5-4156-b134-fa5cee7eb3d3;
	Wed, 30 Sep 2020 07:22:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=Qw+cYjMKoA9NMREWBH0VGfHnoAgl1dkVo5CcZutCHkE=; b=FgJoCEw3ZfdqR49TriDbkD7y01
	BEyxT5RESU6AqisEkOYkDPUkhsAOjxp3CDuIAWwYpHQXMpdow1G+SE71f60PFQOk9SCtxT/1fX/9m
	YbylBEcj4etg++jfAGzvsxaUFcMGdxxgOmrppm3p8O7qLxNLABXip0TErVan3ysKYWBI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRB-0002Pg-4Y
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRB-0005w1-2I
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] evtchn: refuse EVTCHNOP_status for Xen-bound event channels
Message-Id: <E1kNWRB-0005w1-2I@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 07:22:05 +0000

commit f60ab5337f968e2f10c639ab59db7afb0fe4f7c3
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 30 09:10:01 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 30 09:10:01 2020 +0200

    evtchn: refuse EVTCHNOP_status for Xen-bound event channels
    
    Callers have no business knowing the state of the Xen end of an event
    channel.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Paul Durrant <Paul@xen.org>
---
 xen/common/event_channel.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index d2ee83bbbf..49cb318b81 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -933,6 +933,11 @@ int evtchn_status(evtchn_status_t *status)
     }
 
     chn = evtchn_from_port(d, port);
+    if ( consumer_is_xen(chn) )
+    {
+        rc = -EACCES;
+        goto out;
+    }
 
     rc = xsm_evtchn_status(XSM_TARGET, d, chn);
     if ( rc )
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 07:22:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 07:22:17 +0000
Received: from list by lists.xenproject.org with outflank-mailman.449.1388 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRN-0004tL-Rj; Wed, 30 Sep 2020 07:22:17 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 449.1388; Wed, 30 Sep 2020 07:22:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRN-0004tD-Ok; Wed, 30 Sep 2020 07:22:17 +0000
Received: by outflank-mailman (input) for mailman id 449;
 Wed, 30 Sep 2020 07:22:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNWRM-0004t3-9i
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:16 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 1b816e54-10e6-4afb-a146-f813b1c32539;
 Wed, 30 Sep 2020 07:22:15 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRL-0002Pj-AA
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRL-0005wb-6z
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNWRM-0004t3-9i
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:16 +0000
X-Inumbo-ID: 1b816e54-10e6-4afb-a146-f813b1c32539
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 1b816e54-10e6-4afb-a146-f813b1c32539;
	Wed, 30 Sep 2020 07:22:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=LSMX+8yqw+NTRvGhibib4EfnZ2KggqZTaXgDj+fn7Gw=; b=BPdStS/6KUP15J6auGYNqX+1HB
	ZvwEVaS0H0ev2Rp7mSPR0nGyoQyjWCUN/Ndpq1Nqv/F1IIun8X6oCx6pzckd3DwxW6QQIxJjYWPU4
	MGn4aZrD6nyueKypISV9Y3lncUpS0QmjmmTjjCRBC8RIvlFEtzIJdfBc2LcUmtTs5FgU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRL-0002Pj-AA
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRL-0005wb-6z
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] evtchn/sched: reject poll requests for unusable ports
Message-Id: <E1kNWRL-0005wb-6z@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 07:22:15 +0000

commit d4bfa0c78f48e6562667f8e9c898a548be633d77
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 30 09:10:46 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 30 09:10:46 2020 +0200

    evtchn/sched: reject poll requests for unusable ports
    
    Before and after XSA-342 there has been an asymmetry in how not really
    usable ports get treated in do_poll(): Ones beyond a certain boundary
    (max_evtchns originally, valid_evtchns subsequently) did get refused
    with -EINVAL, while lower ones were accepted despite there potentially
    being no way to wake the vCPU again from its polling state. Arrange to
    also honor evtchn_usable() output in the decision.
    
    Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Dario Faggioli <dfaggioli@suse.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
---
 xen/common/sched/core.c | 12 ++++++------
 xen/include/xen/event.h | 32 +++++++++++++++++++-------------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index ab94d2ec3a..ed973e90ec 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -1427,13 +1427,13 @@ static long do_poll(struct sched_poll *sched_poll)
         if ( __copy_from_guest_offset(&port, sched_poll->ports, i, 1) )
             goto out;
 
-        rc = -EINVAL;
-        if ( !port_is_valid(d, port) )
-            goto out;
-
-        rc = 0;
-        if ( evtchn_port_is_pending(d, port) )
+        rc = evtchn_port_poll(d, port);
+        if ( rc )
+        {
+            if ( rc > 0 )
+                rc = 0;
             goto out;
+        }
     }
 
     if ( sched_poll->nr_ports == 1 )
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index fa93a3684a..509d3ae861 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -240,19 +240,6 @@ static inline bool evtchn_is_pending(const struct domain *d,
     return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn);
 }
 
-static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port)
-{
-    struct evtchn *evtchn = evtchn_from_port(d, port);
-    bool rc;
-    unsigned long flags;
-
-    spin_lock_irqsave(&evtchn->lock, flags);
-    rc = evtchn_is_pending(d, evtchn);
-    spin_unlock_irqrestore(&evtchn->lock, flags);
-
-    return rc;
-}
-
 static inline bool evtchn_is_masked(const struct domain *d,
                                     const struct evtchn *evtchn)
 {
@@ -279,6 +266,25 @@ static inline bool evtchn_is_busy(const struct domain *d,
            d->evtchn_port_ops->is_busy(d, evtchn);
 }
 
+/* Returns negative errno, zero for not pending, or positive for pending. */
+static inline int evtchn_port_poll(struct domain *d, evtchn_port_t port)
+{
+    int rc = -EINVAL;
+
+    if ( port_is_valid(d, port) )
+    {
+        struct evtchn *evtchn = evtchn_from_port(d, port);
+        unsigned long flags;
+
+        spin_lock_irqsave(&evtchn->lock, flags);
+        if ( evtchn_usable(evtchn) )
+            rc = evtchn_is_pending(d, evtchn);
+        spin_unlock_irqrestore(&evtchn->lock, flags);
+    }
+
+    return rc;
+}
+
 static inline int evtchn_port_set_priority(struct domain *d,
                                            struct evtchn *evtchn,
                                            unsigned int priority)
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 07:22:29 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 07:22:29 +0000
Received: from list by lists.xenproject.org with outflank-mailman.450.1393 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRZ-0004uy-Tf; Wed, 30 Sep 2020 07:22:29 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 450.1393; Wed, 30 Sep 2020 07:22:29 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRZ-0004uq-QJ; Wed, 30 Sep 2020 07:22:29 +0000
Received: by outflank-mailman (input) for mailman id 450;
 Wed, 30 Sep 2020 07:22:28 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNWRY-0004ud-Ou
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:28 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 1cd7ae2d-4523-4788-a8ca-7d7d147e1302;
 Wed, 30 Sep 2020 07:22:25 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRV-0002Pu-Do
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRV-0005xH-CE
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:25 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNWRY-0004ud-Ou
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:28 +0000
X-Inumbo-ID: 1cd7ae2d-4523-4788-a8ca-7d7d147e1302
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id 1cd7ae2d-4523-4788-a8ca-7d7d147e1302;
	Wed, 30 Sep 2020 07:22:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=keqgLLm3F6X9mAwzzfdWNFDISFSpkYU+HUvsgf0iUkI=; b=uhagS0TSCO1aSBCCMHc4nb2xz8
	6UKC5tfdajS9sR6GG+tsk/9DuXo8YoJjwTHSDcDeYn4A8dMrZs70UuRz6NPHajixBUEB8FmomOcOX
	wfCPizuAWeeMMoPYVxIDOk9WWjOW0A0lgipq8JxR87iihgGfOBXmOoppkwdKJWGScniI=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRV-0002Pu-Do
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRV-0005xH-CE
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] evtchn: don't bypass unlinking pIRQ when closing port
Message-Id: <E1kNWRV-0005xH-CE@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 07:22:25 +0000

commit e301a706eb679a0246cf98324958deb3781c886a
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 30 09:11:48 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 30 09:11:48 2020 +0200

    evtchn: don't bypass unlinking pIRQ when closing port
    
    There's no other path causing a terminal unlink_pirq_port() to be called
    (evtchn_bind_vcpu() relinks it right away) and hence _if_ pirq can
    indeed be NULL when closing the port, list corruption would occur when
    bypassing the unlink (unless the structure never gets linked again). As
    we can't come here after evtchn_destroy() anymore, (late) domain
    destruction also isn't a reason for a possible exception, and hence the
    only alternative looks to be that the check was pointless in the first
    place. While I haven't observed the case, from code inspection I'm far
    from sure I can exclude this being possible, so it feels more safe to
    re-arrange the code instead.
    
    Fixes: c24536b636f2 ("replace d->nr_pirqs sized arrays with radix tree")
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
---
 xen/common/event_channel.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 49cb318b81..161cbb77d2 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -614,17 +614,18 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
     case ECS_PIRQ: {
         struct pirq *pirq = pirq_info(d1, chn1->u.pirq.irq);
 
-        if ( !pirq )
-            break;
-        if ( !is_hvm_domain(d1) )
-            pirq_guest_unbind(d1, pirq);
-        pirq->evtchn = 0;
-        pirq_cleanup_check(pirq, d1);
-        unlink_pirq_port(chn1, d1->vcpu[chn1->notify_vcpu_id]);
+        if ( pirq )
+        {
+            if ( !is_hvm_domain(d1) )
+                pirq_guest_unbind(d1, pirq);
+            pirq->evtchn = 0;
+            pirq_cleanup_check(pirq, d1);
 #ifdef CONFIG_X86
-        if ( is_hvm_domain(d1) && domain_pirq_to_irq(d1, pirq->pirq) > 0 )
-            unmap_domain_pirq_emuirq(d1, pirq->pirq);
+            if ( is_hvm_domain(d1) && domain_pirq_to_irq(d1, pirq->pirq) > 0 )
+                unmap_domain_pirq_emuirq(d1, pirq->pirq);
 #endif
+        }
+        unlink_pirq_port(chn1, d1->vcpu[chn1->notify_vcpu_id]);
         break;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 07:22:38 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 07:22:38 +0000
Received: from list by lists.xenproject.org with outflank-mailman.451.1397 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRh-0004w3-VS; Wed, 30 Sep 2020 07:22:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 451.1397; Wed, 30 Sep 2020 07:22:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRh-0004vv-Rl; Wed, 30 Sep 2020 07:22:37 +0000
Received: by outflank-mailman (input) for mailman id 451;
 Wed, 30 Sep 2020 07:22:36 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNWRg-0004vl-9U
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:36 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cd35b81b-2712-4e66-aeaf-653e02c347f8;
 Wed, 30 Sep 2020 07:22:35 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRf-0002QS-Gv
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRf-0005xx-G1
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:35 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNWRg-0004vl-9U
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:36 +0000
X-Inumbo-ID: cd35b81b-2712-4e66-aeaf-653e02c347f8
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id cd35b81b-2712-4e66-aeaf-653e02c347f8;
	Wed, 30 Sep 2020 07:22:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=FauhMd/xPLNYGLNpEN0Ob5WrCNKJ2HFy0Pu6J3IFDqI=; b=lBSAfwpNQsB4A9Zigq2GVXRCzW
	j+HcZBqgT99zLnod2SkLFOTr4BgViihB39135HqVmvijBC4LsZybSU4OWv35RwNXbi4r/1pAjz62W
	5pTpOqoj6NLIe7Z9dMJe6SZimFCdXk8ORaXJuwHZss8s8xqiGEz/fUflQI3f0jq0iB1A=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRf-0002QS-Gv
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRf-0005xx-G1
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] evtchn: ECS_CLOSED => ECS_FREE
Message-Id: <E1kNWRf-0005xx-G1@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 07:22:35 +0000

commit d72d6153be68f45e8f1c1b9e025cbfa625bbef6d
Author:     Jan Beulich <jbeulich@suse.com>
AuthorDate: Wed Sep 30 09:12:21 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 30 09:12:21 2020 +0200

    evtchn: ECS_CLOSED => ECS_FREE
    
    There's no ECS_CLOSED; correct a comment naming it.
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Julien Grall <jgrall@amazon.com>
    Reviewed-by: Paul Durrant <paul@xen.org>
---
 xen/common/event_channel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 161cbb77d2..2412e63204 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -668,7 +668,7 @@ int evtchn_close(struct domain *d1, int port1, bool guest)
              * We can only get here if the port was closed and re-bound after
              * unlocking d1 but before locking d2 above. We could retry but
              * it is easier to return the same error as if we had seen the
-             * port in ECS_CLOSED. It must have passed through that state for
+             * port in ECS_FREE. It must have passed through that state for
              * us to end up here, so it's a valid error to return.
              */
             rc = -EINVAL;
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 07:22:48 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 07:22:48 +0000
Received: from list by lists.xenproject.org with outflank-mailman.452.1401 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRs-0004xN-09; Wed, 30 Sep 2020 07:22:48 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 452.1401; Wed, 30 Sep 2020 07:22:47 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNWRr-0004xF-TM; Wed, 30 Sep 2020 07:22:47 +0000
Received: by outflank-mailman (input) for mailman id 452;
 Wed, 30 Sep 2020 07:22:46 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNWRq-0004x6-HI
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:46 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id 6e60d14c-54d1-45df-876b-c2e16d4444d4;
 Wed, 30 Sep 2020 07:22:45 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRp-0002Qa-Jz
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNWRp-0005ym-J2
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:45 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNWRq-0004x6-HI
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:46 +0000
X-Inumbo-ID: 6e60d14c-54d1-45df-876b-c2e16d4444d4
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id 6e60d14c-54d1-45df-876b-c2e16d4444d4;
	Wed, 30 Sep 2020 07:22:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=A5uUX6FuK5bE+FlOA+aWniTuC16GiidtD6x7O+gjunU=; b=flL7VQtNKRIStIZjIdbyJ8OJJQ
	jt9Wf8xMCbPHZi3SD/pXGlRoaVBqCrPzm2RGSg49dn/4N/7iofyoBWgtblGQTiKobjHTYOVdvrmKU
	WVSqXYIgolG1cUtlNlU5QRXuupun1Rr+YbCEknFplrD/wvGNN+pisjrfewh/zrLN/jWc=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRp-0002Qa-Jz
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNWRp-0005ym-J2
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 07:22:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] efi/boot: wrap PrintStr/PrintErr to allow const CHAR16* arguments
Message-Id: <E1kNWRp-0005ym-J2@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 07:22:45 +0000

commit c73952831f0fc63a984e0d07dff1d20f8617b81f
Author:     Trammell Hudson <hudson@trmm.net>
AuthorDate: Wed Sep 30 09:14:18 2020 +0200
Commit:     Jan Beulich <jbeulich@suse.com>
CommitDate: Wed Sep 30 09:14:18 2020 +0200

    efi/boot: wrap PrintStr/PrintErr to allow const CHAR16* arguments
    
    This patch wraps the EFI OutputString() method so that they can be
    called with const arguments.  The OutputString method does not modify
    its argument, although the prototype is missing const, so it is necssary
    to cast away the const when calling it.
    
    Signed-off-by: Trammell Hudson <hudson@trmm.net>
    Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/efi/boot.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 157fe0e8c5..8123523194 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -150,10 +150,17 @@ static struct file __initdata cfg;
 static struct file __initdata kernel;
 static struct file __initdata ramdisk;
 static struct file __initdata xsm;
-static CHAR16 __initdata newline[] = L"\r\n";
+static const CHAR16 __initconst newline[] = L"\r\n";
 
-#define PrintStr(s) StdOut->OutputString(StdOut, s)
-#define PrintErr(s) StdErr->OutputString(StdErr, s)
+static void __init PrintStr(const CHAR16 *s)
+{
+    StdOut->OutputString(StdOut, (CHAR16 *)s );
+}
+
+static void __init PrintErr(const CHAR16 *s)
+{
+    StdErr->OutputString(StdErr, (CHAR16 *)s );
+}
 
 /*
  * Include architecture specific implementation here, which references the
@@ -274,7 +281,7 @@ static bool __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
 void __init noreturn blexit(const CHAR16 *str)
 {
     if ( str )
-        PrintStr((CHAR16 *)str);
+        PrintStr(str);
     PrintStr(newline);
 
     if ( !efi_bs )
@@ -315,7 +322,7 @@ static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
     EFI_STATUS ErrIdx = ErrCode & ~EFI_ERROR_MASK;
 
     StdOut = StdErr;
-    PrintErr((CHAR16 *)mesg);
+    PrintErr(mesg);
     PrintErr(L": ");
 
     if( (ErrIdx < ARRAY_SIZE(ErrCodeToStr)) && ErrCodeToStr[ErrIdx] )
@@ -545,7 +552,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     EFI_FILE_HANDLE FileHandle = NULL;
     UINT64 size;
     EFI_STATUS ret;
-    CHAR16 *what = NULL;
+    const CHAR16 *what = NULL;
 
     if ( !name )
         PrintErrMesg(L"No filename", EFI_OUT_OF_RESOURCES);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 15:55:13 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 15:55:13 +0000
Received: from list by lists.xenproject.org with outflank-mailman.830.2841 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRg-0002rn-KZ; Wed, 30 Sep 2020 15:55:08 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 830.2841; Wed, 30 Sep 2020 15:55:08 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRg-0002rX-EU; Wed, 30 Sep 2020 15:55:08 +0000
Received: by outflank-mailman (input) for mailman id 830;
 Wed, 30 Sep 2020 15:55:06 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNeRe-0002qJ-Ik
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:06 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 69200521-10c8-4f5c-85e0-1f2e780d8f89;
 Wed, 30 Sep 2020 15:55:05 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRd-0005XD-5U
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRd-0007yR-3X
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:05 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNeRe-0002qJ-Ik
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:06 +0000
X-Inumbo-ID: 69200521-10c8-4f5c-85e0-1f2e780d8f89
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 69200521-10c8-4f5c-85e0-1f2e780d8f89;
	Wed, 30 Sep 2020 15:55:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=Le0yqc+/DTbiu0nP7SPQdZEpv1QjyE/Gz/OYPrf/qvo=; b=vqFhgZJ+5ckzU0MBYmATlScU1g
	2vSjcLRT1+BIZ6jZlKkAJABjB09Fpv6wmNOYaJw+OhqzPq36LpXhZd8al0yzOvEw54rc51t3ttqjO
	Nvv/wUn2zJgeXQ9tQIEviveT5sh1x/xr9E3YhxInP+bIyYCYrAw31qKzaW8Tgs486ahk=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRd-0005XD-5U
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:05 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRd-0007yR-3X
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:05 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] tools/libxc: report malloc errors in writev_exact
Message-Id: <E1kNeRd-0007yR-3X@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 15:55:05 +0000

commit 0d8d289af7a679c028462c4ed5d98586f9ef9648
Author:     Olaf Hering <olaf@aepfle.de>
AuthorDate: Wed Sep 23 08:48:40 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 30 15:06:38 2020 +0000

    tools/libxc: report malloc errors in writev_exact
    
    The caller of writev_exact should be notified about malloc errors
    when dealing with partial writes.
    
    Signed-off-by: Olaf Hering <olaf@aepfle.de>
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/ctrl/xc_private.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c
index 8af96b1b7e..3fab94f9c0 100644
--- a/tools/libs/ctrl/xc_private.c
+++ b/tools/libs/ctrl/xc_private.c
@@ -721,6 +721,7 @@ int writev_exact(int fd, const struct iovec *iov, int iovcnt)
                     if ( !local_iov )
                     {
                         saved_errno = ENOMEM;
+                        rc = -1;
                         goto out;
                     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 15:55:17 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 15:55:17 +0000
Received: from list by lists.xenproject.org with outflank-mailman.831.2850 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRp-0002ub-J7; Wed, 30 Sep 2020 15:55:17 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 831.2850; Wed, 30 Sep 2020 15:55:17 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRp-0002uV-Fx; Wed, 30 Sep 2020 15:55:17 +0000
Received: by outflank-mailman (input) for mailman id 831;
 Wed, 30 Sep 2020 15:55:16 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNeRo-0002uA-5k
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:16 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 18535b14-445d-4e70-93f7-19194fa73698;
 Wed, 30 Sep 2020 15:55:15 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRn-0005XM-8g
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRn-0007zC-7c
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:15 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNeRo-0002uA-5k
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:16 +0000
X-Inumbo-ID: 18535b14-445d-4e70-93f7-19194fa73698
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 18535b14-445d-4e70-93f7-19194fa73698;
	Wed, 30 Sep 2020 15:55:15 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=xXhbKa7hgLxnKOvW9Qsm2mRkMCt/UGJuphTnri69HMY=; b=dw0wAd2pygShJvzwQHLu5TGbBn
	iEoVX99X8OKCMULOAqLaN3ZN1GQ7WeNMXllvIHINX72dfONSrlO37qgN+7XTFpQpLq8udRbWlrzIe
	N11Dbs2z3FUawEhwwpekEQlqaJFLw1hquzrrSeQLZNwdbKnNWE9GZvkn1bwjD0C+aBIU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRn-0005XM-8g
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:15 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRn-0007zC-7c
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:15 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] tools: Fix configure of upstream QEMU
Message-Id: <E1kNeRn-0007zC-7c@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 15:55:15 +0000

commit 27de84d3ae462bd8311c8267c642ec95afdcf47c
Author:     Anthony PERARD <anthony.perard@citrix.com>
AuthorDate: Wed Sep 23 12:03:23 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 30 15:08:17 2020 +0000

    tools: Fix configure of upstream QEMU
    
    QEMU as recently switch its build system to use meson and the
    ./configure step with meson is more restrictive that the step used to
    be, most installation path wants to be within prefix, otherwise we
    have this error message:
    
        ERROR: The value of the 'datadir' option is '/usr/share/qemu-xen' which must be a subdir of the prefix '/usr/lib/xen'.
    
    In order to workaround the limitation, we will set prefix to the same
    one as for the rest of Xen installation, and set all the other paths.
    
    For reference, a thread in qemu-devel:
        "configure with datadir outside of --prefix fails with meson"
        https://lore.kernel.org/qemu-devel/20200918133012.GH2024@perard.uk.xensource.com/t/
    
    And an issue in meson:
        "artificial limitation of directories (forced to be in prefix)"
        https://github.com/mesonbuild/meson/issues/2561
    
    Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
    Tested-by: Paul Durrant <paul@xen.org>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/Makefile b/tools/Makefile
index ea69675cca..c1eba22c0c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -237,7 +237,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 	$$source/configure --enable-xen --target-list=i386-softmmu \
 		$(QEMU_XEN_ENABLE_DEBUG) \
 		$$enable_trace_backend \
-		--prefix=$(LIBEXEC) \
+		--prefix=$(prefix) \
 		--libdir=$(LIBEXEC_LIB) \
 		--includedir=$(LIBEXEC_INC) \
 		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
@@ -249,6 +249,10 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
 		--localstatedir=$(localstatedir) \
+		--docdir=$(LIBEXEC)/share/doc \
+		--mandir=$(LIBEXEC)/share/man \
+		--libexecdir=$(LIBEXEC)/libexec \
+		--firmwarepath=$(LIBEXEC)/share/qemu-firmware \
 		--disable-kvm \
 		--disable-docs \
 		--disable-guest-agent \
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 15:55:26 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 15:55:26 +0000
Received: from list by lists.xenproject.org with outflank-mailman.832.2856 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRy-0002yD-Kr; Wed, 30 Sep 2020 15:55:26 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 832.2856; Wed, 30 Sep 2020 15:55:26 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeRy-0002y4-HJ; Wed, 30 Sep 2020 15:55:26 +0000
Received: by outflank-mailman (input) for mailman id 832;
 Wed, 30 Sep 2020 15:55:26 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNeRy-0002xu-8s
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:26 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 790e40a1-df30-4403-a74b-fe6cc3bca4a3;
 Wed, 30 Sep 2020 15:55:25 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRx-0005XZ-Bd
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeRx-0007zg-Ao
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:25 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNeRy-0002xu-8s
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:26 +0000
X-Inumbo-ID: 790e40a1-df30-4403-a74b-fe6cc3bca4a3
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id 790e40a1-df30-4403-a74b-fe6cc3bca4a3;
	Wed, 30 Sep 2020 15:55:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=0B7dVPwSARehN4XfzH3T0v5UHg5iPNH0IqQ20UpM4rg=; b=rqg+TevQb6g1wCTawuI0jruvqt
	FbRVn7spQ8hk7ENsZyQN4sib8GuUVe4DCkG3KZ3luCKYDMEHF3tWhwWJJyRKEMYPqyWZ4mtQOoJgx
	KY8gCnD3D58+thJ3xCWHCS4m/OF3KjkkS5vUSfsoJqbCCspV71lFM5/wjsFtb2cRZJ6w=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRx-0005XZ-Bd
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:25 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeRx-0007zg-Ao
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:25 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] libxc/bitops: increase potential size of bitmaps
Message-Id: <E1kNeRx-0007zg-Ao@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 15:55:25 +0000

commit 50a5215f30e964a6f16165ab57925ca39f31a849
Author:     Olaf Hering <olaf@aepfle.de>
AuthorDate: Thu Sep 24 20:08:43 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 30 15:10:26 2020 +0000

    libxc/bitops: increase potential size of bitmaps
    
    If the bitmap is used to represent domU pages, the amount of memory is
    limited to 8TB due to the 32bit value. Adjust the code to use 64bit
    values as input. All callers already use some form of 64bit as input,
    so no further adjustment is required.
    
    Signed-off-by: Olaf Hering <olaf@aepfle.de>
    Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/ctrl/xc_bitops.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index 0951e8267d..3d3a09772a 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -14,52 +14,52 @@
 #define BITMAP_SHIFT(_nr) ((_nr) % 8)
 
 /* calculate required space for number of bytes needed to hold nr_bits */
-static inline int bitmap_size(int nr_bits)
+static inline unsigned long bitmap_size(unsigned long nr_bits)
 {
     return (nr_bits + 7) / 8;
 }
 
-static inline void *bitmap_alloc(int nr_bits)
+static inline void *bitmap_alloc(unsigned long nr_bits)
 {
     return calloc(1, bitmap_size(nr_bits));
 }
 
-static inline void bitmap_set(void *addr, int nr_bits)
+static inline void bitmap_set(void *addr, unsigned long nr_bits)
 {
     memset(addr, 0xff, bitmap_size(nr_bits));
 }
 
-static inline void bitmap_clear(void *addr, int nr_bits)
+static inline void bitmap_clear(void *addr, unsigned long nr_bits)
 {
     memset(addr, 0, bitmap_size(nr_bits));
 }
 
-static inline int test_bit(int nr, const void *_addr)
+static inline int test_bit(unsigned long nr, const void *_addr)
 {
     const char *addr = _addr;
     return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
 }
 
-static inline void clear_bit(int nr, void *_addr)
+static inline void clear_bit(unsigned long nr, void *_addr)
 {
     char *addr = _addr;
     BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr));
 }
 
-static inline void set_bit(int nr, void *_addr)
+static inline void set_bit(unsigned long nr, void *_addr)
 {
     char *addr = _addr;
     BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr));
 }
 
-static inline int test_and_clear_bit(int nr, void *addr)
+static inline int test_and_clear_bit(unsigned long nr, void *addr)
 {
     int oldbit = test_bit(nr, addr);
     clear_bit(nr, addr);
     return oldbit;
 }
 
-static inline int test_and_set_bit(int nr, void *addr)
+static inline int test_and_set_bit(unsigned long nr, void *addr)
 {
     int oldbit = test_bit(nr, addr);
     set_bit(nr, addr);
@@ -67,11 +67,11 @@ static inline int test_and_set_bit(int nr, void *addr)
 }
 
 static inline void bitmap_or(void *_dst, const void *_other,
-                             int nr_bits)
+                             unsigned long nr_bits)
 {
     char *dst = _dst;
     const char *other = _other;
-    int i;
+    unsigned long i;
     for ( i = 0; i < bitmap_size(nr_bits); ++i )
         dst[i] |= other[i];
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 15:55:37 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 15:55:37 +0000
Received: from list by lists.xenproject.org with outflank-mailman.833.2858 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeS9-00030d-Lz; Wed, 30 Sep 2020 15:55:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 833.2858; Wed, 30 Sep 2020 15:55:37 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeS9-00030Y-Iv; Wed, 30 Sep 2020 15:55:37 +0000
Received: by outflank-mailman (input) for mailman id 833;
 Wed, 30 Sep 2020 15:55:36 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]
 helo=us1-amaz-eas2.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNeS8-00030K-Mo
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:36 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
 id c02b1614-63a5-460b-909e-dd75ed89e7c0;
 Wed, 30 Sep 2020 15:55:35 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeS7-0005Xi-Ek
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeS7-00080J-E1
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:35 +0000
Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNeS8-00030K-Mo
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:36 +0000
X-Inumbo-ID: c02b1614-63a5-460b-909e-dd75ed89e7c0
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS
	id c02b1614-63a5-460b-909e-dd75ed89e7c0;
	Wed, 30 Sep 2020 15:55:35 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=aURuB1x01ZaUKH9pfYsfRv2E+0tLe0gz4+RWh7F9EcY=; b=Khm/TUEeiLqM+KSfF2zt6nTDvR
	AkRtwRcHbcUbus+hkIxSCas7xEkt8Od/gNIciwq5yf4ao7/S+Ggh77xd6PcgMVd3ru8wxTzB8+rVZ
	5jIVme93dm9qBkcVjakaTdcyLmw6LwJjEIFmTwawr46R5vDNwK2GR1epRwoeAuU6EOCU=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeS7-0005Xi-Ek
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:35 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeS7-00080J-E1
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:35 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] tools/cpuid: Plumb nested_virt down into xc_cpuid_apply_policy()
Message-Id: <E1kNeS7-00080J-E1@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 15:55:35 +0000

commit bfcc97c08c2258316d1cd92c23a441d97ad6ff4e
Author:     Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Tue Sep 29 14:48:52 2020 +0100
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 30 15:18:08 2020 +0000

    tools/cpuid: Plumb nested_virt down into xc_cpuid_apply_policy()
    
    Nested Virt is the final special case in legacy CPUID handling.  Pass the
    (poorly named) nested_hvm setting down into xc_cpuid_apply_policy() to break
    the semantic dependency on HVM_PARAM_NESTEDHVM.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/libs/ctrl/include/xenctrl.h |  4 ++--
 tools/libs/guest/xg_cpuid_x86.c   | 14 +++++---------
 tools/libxl/libxl_cpuid.c         |  3 ++-
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xenctrl.h
index 73e9535fc8..ba70bec9c4 100644
--- a/tools/libs/ctrl/include/xenctrl.h
+++ b/tools/libs/ctrl/include/xenctrl.h
@@ -1826,7 +1826,7 @@ struct xc_xend_cpuid {
  * cases, and the generated policy must be compatible with a 4.13.
  *
  * Either pass a full new @featureset (and @nr_features), or adjust individual
- * features (@pae, @itsc).
+ * features (@pae, @itsc, @nested_virt).
  *
  * Then (optionally) apply legacy XEND overrides (@xend) to the result.
  */
@@ -1834,7 +1834,7 @@ int xc_cpuid_apply_policy(xc_interface *xch,
                           uint32_t domid, bool restore,
                           const uint32_t *featureset,
                           unsigned int nr_features, bool pae, bool itsc,
-                          const struct xc_xend_cpuid *xend);
+                          bool nested_virt, const struct xc_xend_cpuid *xend);
 int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
 int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
                         xc_cpumap_t cpumap, unsigned int nr_cpus);
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index dc50106975..aae6931a11 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -427,7 +427,7 @@ static int xc_cpuid_xend_policy(
 
 int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
                           const uint32_t *featureset, unsigned int nr_features,
-                          bool pae, bool itsc,
+                          bool pae, bool itsc, bool nested_virt,
                           const struct xc_xend_cpuid *xend)
 {
     int rc;
@@ -559,7 +559,11 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         p->extd.itsc = itsc;
 
         if ( di.hvm )
+        {
             p->basic.pae = pae;
+            p->basic.vmx = nested_virt;
+            p->extd.svm = nested_virt;
+        }
     }
 
     if ( !di.hvm )
@@ -625,14 +629,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
             }
             break;
         }
-
-        /*
-         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM
-         * to be reflected correctly in CPUID.  Xen will discard these bits if
-         * configuration hasn't been set for the domain.
-         */
-        p->basic.vmx = true;
-        p->extd.svm = true;
     }
 
     rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c
index f54eb83a90..08e85dcffb 100644
--- a/tools/libxl/libxl_cpuid.c
+++ b/tools/libxl/libxl_cpuid.c
@@ -422,6 +422,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
 {
     bool pae = true;
     bool itsc;
+    bool nested_virt = libxl_defbool_val(info->nested_hvm);
 
     /*
      * For PV guests, PAE is Xen-controlled (it is the 'p' that differentiates
@@ -452,7 +453,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
             info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE);
 
     xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0,
-                          pae, itsc, info->cpuid);
+                          pae, itsc, nested_virt, info->cpuid);
 }
 
 static const char *input_names[2] = { "leaf", "subleaf" };
--
generated by git-patchbot for /home/xen/git/xen.git#staging


From xen-changelog-bounces@lists.xenproject.org Wed Sep 30 15:55:46 2020
Return-path: <xen-changelog-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xen.org
Delivery-date: Wed, 30 Sep 2020 15:55:46 +0000
Received: from list by lists.xenproject.org with outflank-mailman.834.2863 (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeSI-00032F-Nr; Wed, 30 Sep 2020 15:55:46 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 834.2863; Wed, 30 Sep 2020 15:55:46 +0000
X-BeenThere: xen-changelog@lists.xenproject.org
List-Id: "Change log for Mercurial \(receive only\)"
 <xen-changelog.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:xen-changelog@lists.xenproject.org>
List-Help: <mailto:xen-changelog-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/xen-changelog>, 
 <mailto:xen-changelog-request@lists.xenproject.org?subject=subscribe>
Errors-To: xen-changelog-bounces@lists.xenproject.org
Precedence: list
Sender: "Xen-changelog" <xen-changelog-bounces@lists.xenproject.org>
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <xen-changelog-bounces@lists.xenproject.org>)
	id 1kNeSI-000327-Kh; Wed, 30 Sep 2020 15:55:46 +0000
Received: by outflank-mailman (input) for mailman id 834;
 Wed, 30 Sep 2020 15:55:46 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
 id 1kNeSI-000320-BT
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:46 +0000
Received: from mail.xenproject.org (unknown [104.130.215.37])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id a13f0019-c6c2-45b2-aff1-f2ef76a3dbd8;
 Wed, 30 Sep 2020 15:55:45 +0000 (UTC)
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeSH-0005YP-I2
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
 (envelope-from <ian.jackson@eu.citrix.com>) id 1kNeSH-000817-Gy
 for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:45 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <SRS0=jh25=DH=eu.citrix.com=ian.jackson@srs-us1.protection.inumbo.net>)
	id 1kNeSI-000320-BT
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:46 +0000
X-Inumbo-ID: a13f0019-c6c2-45b2-aff1-f2ef76a3dbd8
Received: from mail.xenproject.org (unknown [104.130.215.37])
	by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
	id a13f0019-c6c2-45b2-aff1-f2ef76a3dbd8;
	Wed, 30 Sep 2020 15:55:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Date:Message-Id:Subject:Reply-To:To:From;
	bh=WsPJiO70I6iGhIT03xot9WgfXyg3QZkOsqDZjukuh1I=; b=zAXIWuxhOogHQ2yxo3NBFTFfuv
	Ken2CQSy2J/GXuPmfKPy6Cz4bTjTLGYe/P2V/Pq56yIoQI15hkhk2XUDON0h+5zLG5cMX0VeM4yRJ
	CjgpblEm2rJEvM07Ww95ThG6GkN+1XzW8ORIA2iQMeCya1qPE5B5VA5SBqeMCAH+2OWs=;
Received: from xenbits.xenproject.org ([104.239.192.120])
	by mail.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeSH-0005YP-I2
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:45 +0000
Received: from xen by xenbits.xenproject.org with local (Exim 4.92)
	(envelope-from <ian.jackson@eu.citrix.com>)
	id 1kNeSH-000817-Gy
	for xen-changelog@lists.xenproject.org; Wed, 30 Sep 2020 15:55:45 +0000
From: patchbot@xen.org
To: xen-changelog@lists.xenproject.org
Reply-To: xen-devel@lists.xenproject.org
Subject: [xen staging] tools/xenstore: set maximum number of grants needed
Message-Id: <E1kNeSH-000817-Gy@xenbits.xenproject.org>
Date: Wed, 30 Sep 2020 15:55:45 +0000

commit 11852c7bb070a18c3708b4c001772a23e7d4fc27
Author:     Juergen Gross <jgross@suse.com>
AuthorDate: Thu Sep 24 16:36:48 2020 +0200
Commit:     Wei Liu <wl@xen.org>
CommitDate: Wed Sep 30 15:34:50 2020 +0000

    tools/xenstore: set maximum number of grants needed
    
    When running as a stubdom Xenstore should set the maximum number of
    grants needed via a call of xengnttab_set_max_grants(), as otherwise
    the number of domains which can be supported will be 128 only (the
    default number of grants supported by Mini-OS).
    
    We use one grant per domain so the theoretical maximum number is
    DOMID_FIRST_RESERVED.
    
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Acked-by: Wei Liu <wl@xen.org>
---
 tools/xenstore/xenstored_domain.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 06359503f0..0d5495745b 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -631,6 +631,12 @@ void domain_init(void)
 	if (*xgt_handle == NULL)
 		barf_perror("Failed to open connection to gnttab");
 
+	/*
+	 * Allow max number of domains for mappings. We allow one grant per
+	 * domain so the theoretical maximum is DOMID_FIRST_RESERVED.
+	 */
+	xengnttab_set_max_grants(*xgt_handle, DOMID_FIRST_RESERVED);
+
 	talloc_set_destructor(xgt_handle, close_xgt_handle);
 
 	xce_handle = xenevtchn_open(NULL, 0);
--
generated by git-patchbot for /home/xen/git/xen.git#staging


