xenhost support
Subsystems (13)
cover xenhost support
Hi all,
This is an RFC for xenhost support, outlined here by Juergen here:
https://lkml.org/lkml/2019/4/8/67.
The high level idea is to provide an abstraction of the Xen communication interface, as a xenhost_t.
xenhost_t expose ops for communication between the guest and Xen (hypercall, cpuid, shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning), and these can differ based on the kind of underlying Xen: regular, local, and nested.
(Since this abstraction is largely about guest -- xenhost communication, no ops are needed for timer, clock, sched, memory (MMU, P2M), VCPU mgmt. etc.)
Xenhost use-cases:
Regular-Xen: the standard Xen interface presented to a guest, specifically for comunication between Lx-guest and Lx-Xen.
Local-Xen: a Xen like interface which runs in the same address space as the guest (dom0). This, can act as the default xenhost.
The major ways it differs from a regular Xen interface is in presenting a different hypercall interface (call instead of a syscall/vmcall), and in an inability to do grant-mappings: since local-Xen exists in the same address space as Xen, there's no way for it to cheaply change the physical page that a GFN maps to (assuming no P2M tables.)
Nested-Xen: this channel is to Xen, one level removed: from L1-guest to L0-Xen. The use case is that we want L0-dom0-backends to talk to L1-dom0-frontend drivers which can then present PV devices which can in-turn be used by the L1-dom0-backend drivers as raw underlying devices. The interfaces themselves, broadly remain similar.
Note: L0-Xen, L1-Xen represent Xen running at that nesting level and L0-guest, L1-guest represent guests that are children of Xen at that nesting level. Lx, represents any level.
Patches 1-7,
"x86/xen: add xenhost_t interface"
"x86/xen: cpuid support in xenhost_t"
"x86/xen: make hypercall_page generic"
"x86/xen: hypercall support for xenhost_t"
"x86/xen: add feature support in xenhost_t"
"x86/xen: add shared_info support to xenhost_t"
"x86/xen: make vcpu_info part of xenhost_t"
abstract out interfaces that setup hypercalls/cpuid/shared_info/vcpu_info etc.
Patch 8, "x86/xen: irq/upcall handling with multiple xenhosts" sets up the upcall and pv_irq ops based on vcpu_info.
Patch 9, "xen/evtchn: support evtchn in xenhost_t" adds xenhost based evtchn support for evtchn_2l.
Patches 10 and 16, "xen/balloon: support ballooning in xenhost_t" and "xen/grant-table: host_addr fixup in mapping on xenhost_r0" implement support from GNTTABOP_map_grant_ref for xenhosts of type xenhost_r0 (xenhost local.)
Patch 12, "xen/xenbus: support xenbus frontend/backend with xenhost_t" makes xenbus so that both its frontend and backend can be bootstrapped separately via separate xenhosts.
Remaining patches, 11, 13, 14, 15:
"xen/grant-table: make grant-table xenhost aware" "drivers/xen: gnttab, evtchn, xenbus API changes" "xen/blk: gnttab, evtchn, xenbus API changes" "xen/net: gnttab, evtchn, xenbus API changes"
are mostly mechanical changes for APIs that now take xenhost_t * as parameter.
The code itself is RFC quality, and is mostly meant to get feedback before proceeding further. Also note that the FIFO logic and some Xen drivers (input, pciback, scsi etc) are mostly unchanged, so will not build.
Please take a look.
Thanks
Ankur
Ankur Arora (16):
x86/xen: add xenhost_t interface
x86/xen: cpuid support in xenhost_t
x86/xen: make hypercall_page generic
x86/xen: hypercall support for xenhost_t x86/xen: add feature support in xenhost_t x86/xen: add shared_info support to xenhost_t x86/xen: make vcpu_info part of xenhost_t x86/xen: irq/upcall handling with multiple xenhosts xen/evtchn: support evtchn in xenhost_t xen/balloon: support ballooning in xenhost_t xen/grant-table: make grant-table xenhost aware xen/xenbus: support xenbus frontend/backend with xenhost_t drivers/xen: gnttab, evtchn, xenbus API changes xen/blk: gnttab, evtchn, xenbus API changes xen/net: gnttab, evtchn, xenbus API changes xen/grant-table: host_addr fixup in mapping on xenhost_r0
arch/x86/include/asm/xen/hypercall.h | 239 +++++--- arch/x86/include/asm/xen/hypervisor.h | 3 +- arch/x86/pci/xen.c | 18 +- arch/x86/xen/Makefile | 3 +- arch/x86/xen/enlighten.c | 101 ++-- arch/x86/xen/enlighten_hvm.c | 185 ++++-- arch/x86/xen/enlighten_pv.c | 144 ++++- arch/x86/xen/enlighten_pvh.c | 25 +- arch/x86/xen/grant-table.c | 71 ++- arch/x86/xen/irq.c | 75 ++- arch/x86/xen/mmu_pv.c | 6 +- arch/x86/xen/p2m.c | 24 +- arch/x86/xen/pci-swiotlb-xen.c | 1 + arch/x86/xen/setup.c | 1 + arch/x86/xen/smp.c | 25 +- arch/x86/xen/smp_hvm.c | 17 +- arch/x86/xen/smp_pv.c | 27 +- arch/x86/xen/suspend_hvm.c | 6 +- arch/x86/xen/suspend_pv.c | 14 +- arch/x86/xen/time.c | 32 +- arch/x86/xen/xen-asm_32.S | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- arch/x86/xen/xen-head.S | 11 +- arch/x86/xen/xen-ops.h | 8 +- arch/x86/xen/xenhost.c | 102 ++++ drivers/block/xen-blkback/blkback.c | 56 +- drivers/block/xen-blkback/common.h | 2 +- drivers/block/xen-blkback/xenbus.c | 65 +-- drivers/block/xen-blkfront.c | 105 ++-- drivers/input/misc/xen-kbdfront.c | 2 +- drivers/net/xen-netback/hash.c | 7 +- drivers/net/xen-netback/interface.c | 15 +- drivers/net/xen-netback/netback.c | 11 +- drivers/net/xen-netback/rx.c | 3 +- drivers/net/xen-netback/xenbus.c | 81 +-- drivers/net/xen-netfront.c | 122 ++-- drivers/pci/xen-pcifront.c | 6 +- drivers/tty/hvc/hvc_xen.c | 2 +- drivers/xen/acpi.c | 2 + drivers/xen/balloon.c | 21 +- drivers/xen/cpu_hotplug.c | 16 +- drivers/xen/events/Makefile | 1 - drivers/xen/events/events_2l.c | 198 +++---- drivers/xen/events/events_base.c | 381 +++++++------ drivers/xen/events/events_fifo.c | 4 +- drivers/xen/events/events_internal.h | 78 +-- drivers/xen/evtchn.c | 24 +- drivers/xen/fallback.c | 9 +- drivers/xen/features.c | 33 +- drivers/xen/gntalloc.c | 21 +- drivers/xen/gntdev.c | 26 +- drivers/xen/grant-table.c | 632 ++++++++++++--------- drivers/xen/manage.c | 37 +- drivers/xen/mcelog.c | 2 +- drivers/xen/pcpu.c | 2 +- drivers/xen/platform-pci.c | 12 +- drivers/xen/preempt.c | 1 + drivers/xen/privcmd.c | 5 +- drivers/xen/sys-hypervisor.c | 14 +- drivers/xen/time.c | 4 +- drivers/xen/xen-balloon.c | 16 +- drivers/xen/xen-pciback/xenbus.c | 2 +- drivers/xen/xen-scsiback.c | 5 +- drivers/xen/xen-selfballoon.c | 2 + drivers/xen/xenbus/xenbus.h | 45 +- drivers/xen/xenbus/xenbus_client.c | 40 +- drivers/xen/xenbus/xenbus_comms.c | 121 ++-- drivers/xen/xenbus/xenbus_dev_backend.c | 30 +- drivers/xen/xenbus/xenbus_dev_frontend.c | 22 +- drivers/xen/xenbus/xenbus_probe.c | 247 +++++--- drivers/xen/xenbus/xenbus_probe_backend.c | 20 +- drivers/xen/xenbus/xenbus_probe_frontend.c | 66 ++- drivers/xen/xenbus/xenbus_xs.c | 192 ++++--- drivers/xen/xenfs/xenstored.c | 7 +- drivers/xen/xlate_mmu.c | 4 +- include/xen/balloon.h | 4 +- include/xen/events.h | 45 +- include/xen/features.h | 17 +- include/xen/grant_table.h | 83 +-- include/xen/xen-ops.h | 10 +- include/xen/xen.h | 3 + include/xen/xenbus.h | 54 +- include/xen/xenhost.h | 302 ++++++++++ 83 files changed, 2826 insertions(+), 1653 deletions(-) create mode 100644 arch/x86/xen/xenhost.c create mode 100644 include/xen/xenhost.h
Signature · 1 line
2.20.1
RFC PATCH 1/16 x86/xen: add xenhost_t interface
Add xenhost_t which will serve as an abstraction over Xen interfaces. It co-exists with the PV/HVM/PVH abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to capture mechanisms for communication with Xen so we could have different types of underlying Xen: regular, local, and nested.
Also add xenhost_register() and stub registration in the various guest types.
--- arch/x86/xen/Makefile | 1 + arch/x86/xen/enlighten_hvm.c | 13 +++++ arch/x86/xen/enlighten_pv.c | 16 ++++++ arch/x86/xen/enlighten_pvh.c | 12 +++++ arch/x86/xen/xenhost.c | 75 ++++++++++++++++++++++++++++ include/xen/xen.h | 3 ++ include/xen/xenhost.h | 95 ++++++++++++++++++++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 arch/x86/xen/xenhost.c create mode 100644 include/xen/xenhost.h
arch/x86/xen/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-y += mmu.o obj-y += time.o obj-y += grant-table.o obj-y += suspend.o +obj-y += xenhost.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_XEN_PVHVM) += mmu_hvm.o
arch/x86/xen/enlighten_hvm.c +13 -0
@@ -5,6 +5,7 @@#include <linux/kexec.h> #include <linux/memblock.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h> #include <xen/interface/memory.h>
@@ -82,6 +83,12 @@ static void __init xen_hvm_init_mem_mapping(void)xen_vcpu_info_reset (0 ); } +xenhost_ops_t xh_hvm_ops = { +}; + +xenhost_ops_t xh_hvm_nested_ops = { +}; +static void __init init_hvm_pv_info (void ) {int major, minor;
@@ -179,6 +186,12 @@ static void __init xen_hvm_guest_init(void) {if (xen_pv_domain ())return ; +/* +* We need only xenhost_r1 for HVM guests since they cannot be +* driver domain (?) or dom0. +*/ +if (!xen_pvh_domain ()) +xenhost_register (xenhost_r1, &xh_hvm_ops);init_hvm_pv_info ();
arch/x86/xen/enlighten_pv.c +16 -0
@@ -36,6 +36,7 @@#include <xen/xen.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/interface/physdev.h>
@@ -1188,6 +1189,12 @@ static void __init xen_dom0_set_legacy_features(void) x86_platform.legacy.rtc =1 ; } +xenhost_ops_t xh_pv_ops = { +}; + +xenhost_ops_t xh_pv_nested_ops = { +}; +/* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) {
@@ -1198,6 +1205,15 @@ asmlinkage __visible void __init xen_start_kernel(void)if (!xen_start_info)return ; +xenhost_register (xenhost_r1, &xh_pv_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_pv_nested_ops); + xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags;
arch/x86/xen/enlighten_pvh.c +12 -0
@@ -8,6 +8,7 @@#include <asm/e820/api.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <asm/xen/interface.h> #include <asm/xen/hypercall.h>
@@ -21,11 +22,22 @@*/ bool xen_pvh __attribute__((section(".data"))) = 0; +extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops; +void __init xen_pvh_init (void ) {u32 msr;u64 pfn; +xenhost_register (xenhost_r1, &xh_hvm_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_hvm_nested_ops); + xen_pvh =1 ; xen_start_flags = pvh_start_info.flags;
arch/x86/xen/xenhost.c new file +75 -0
75 lines not on this page · raw message
include/xen/xen.h +3 -0
@@ -42,6 +42,9 @@ extern struct hvm_start_info pvh_start_info;#define xen_initial_domain () (0)#endif /* CONFIG_XEN_DOM0 */ +#define xen_driver_domain () xen_initial_domain() +#define xen_nested () 0 +struct bio_vec ;bool xen_biovec_phys_mergeable (const struct bio_vec *vec1,const struct bio_vec *vec2);
include/xen/xenhost.h new file +95 -0
95 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 1/16 x86/xen: add xenhost_t interface
In reply to Ankur AroraAdd xenhost_t which will serve as an abstraction over Xen interfaces. It co-exists with the PV/HVM/PVH abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to capture mechanisms for communication with Xen so we could have different types of underlying Xen: regular, local, and nested.
Also add xenhost_register() and stub registration in the various guest types.
--- arch/x86/xen/Makefile | 1 + arch/x86/xen/enlighten_hvm.c | 13 +++++ arch/x86/xen/enlighten_pv.c | 16 ++++++ arch/x86/xen/enlighten_pvh.c | 12 +++++ arch/x86/xen/xenhost.c | 75 ++++++++++++++++++++++++++++ include/xen/xen.h | 3 ++ include/xen/xenhost.h | 95 ++++++++++++++++++++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 arch/x86/xen/xenhost.c create mode 100644 include/xen/xenhost.h
arch/x86/xen/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-y += mmu.o obj-y += time.o obj-y += grant-table.o obj-y += suspend.o +obj-y += xenhost.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_XEN_PVHVM) += mmu_hvm.o
arch/x86/xen/enlighten_hvm.c +13 -0
@@ -5,6 +5,7 @@#include <linux/kexec.h> #include <linux/memblock.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h> #include <xen/interface/memory.h>
@@ -82,6 +83,12 @@ static void __init xen_hvm_init_mem_mapping(void)xen_vcpu_info_reset (0 ); } +xenhost_ops_t xh_hvm_ops = { +}; + +xenhost_ops_t xh_hvm_nested_ops = { +}; +static void __init init_hvm_pv_info (void ) {int major, minor;
@@ -179,6 +186,12 @@ static void __init xen_hvm_guest_init(void) {if (xen_pv_domain ())return ; +/* +* We need only xenhost_r1 for HVM guests since they cannot be +* driver domain (?) or dom0. +*/ +if (!xen_pvh_domain ()) +xenhost_register (xenhost_r1, &xh_hvm_ops);init_hvm_pv_info ();
arch/x86/xen/enlighten_pv.c +16 -0
@@ -36,6 +36,7 @@#include <xen/xen.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/interface/physdev.h>
@@ -1188,6 +1189,12 @@ static void __init xen_dom0_set_legacy_features(void) x86_platform.legacy.rtc =1 ; } +xenhost_ops_t xh_pv_ops = { +}; + +xenhost_ops_t xh_pv_nested_ops = { +}; +/* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) {
@@ -1198,6 +1205,15 @@ asmlinkage __visible void __init xen_start_kernel(void)if (!xen_start_info)return ; +xenhost_register (xenhost_r1, &xh_pv_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_pv_nested_ops); + xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags;
arch/x86/xen/enlighten_pvh.c +12 -0
@@ -8,6 +8,7 @@#include <asm/e820/api.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <asm/xen/interface.h> #include <asm/xen/hypercall.h>
@@ -21,11 +22,22 @@*/ bool xen_pvh __attribute__((section(".data"))) = 0; +extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops; +void __init xen_pvh_init (void ) {u32 msr;u64 pfn; +xenhost_register (xenhost_r1, &xh_hvm_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_hvm_nested_ops); + xen_pvh =1 ; xen_start_flags = pvh_start_info.flags;
arch/x86/xen/xenhost.c new file +75 -0
75 lines not on this page · raw message
include/xen/xen.h +3 -0
@@ -42,6 +42,9 @@ extern struct hvm_start_info pvh_start_info;#define xen_initial_domain () (0)#endif /* CONFIG_XEN_DOM0 */ +#define xen_driver_domain () xen_initial_domain() +#define xen_nested () 0 +struct bio_vec ;bool xen_biovec_phys_mergeable (const struct bio_vec *vec1,const struct bio_vec *vec2);
include/xen/xenhost.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.20.1
Juergen Gross
maintainerRe: [RFC PATCH 01/16] x86/xen: add xenhost_t interface
Quoted 60 lines · Ankur Arora
Add
xenhost_twhich will serve as an abstraction over Xen interfaces. It co-exists with the PV/HVM/PVH abstractions (x86_init,hypervisor_x86,pv_opsetc) and is meant to capture mechanisms for communication with Xen so we could have different types of underlying Xen: regular, local, and nested.Also add
xenhost_register()and stub registration in the various guest types.Signed-off-by Ankur Arora <[email protected]>--- arch/x86/xen/Makefile | 1 + arch/x86/xen/enlighten_hvm.c | 13 +++++ arch/x86/xen/enlighten_pv.c | 16 ++++++ arch/x86/xen/enlighten_pvh.c | 12 +++++ arch/x86/xen/xenhost.c | 75 ++++++++++++++++++++++++++++ include/xen/xen.h | 3 ++ include/xen/xenhost.h | 95 ++++++++++++++++++++++++++++++++++++ 7 files changed, 215 insertions(+)create mode 100644
arch/x86/xen/xenhost.c
create mode 100644include/xen/xenhost.harch/x86/xen/Makefile +1
-0@@ -18,6 +18,7 @@ obj-y += mmu.o obj-y += time.o obj-y += grant-table.o obj-y += suspend.o +obj-y += xenhost.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_XEN_PVHVM) += mmu_hvm.oarch/x86/xen/enlighten_hvm.c +7
-0@@ -5,6 +5,7 @@#include <linux/kexec.h> #include <linux/memblock.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h> #include <xen/interface/memory.h> @@ -82,6 +83,12 @@ static void __init xen_hvm_init_mem_mapping(void)xen_vcpu_info_reset (0 ); } +xenhost_ops_t xh_hvm_ops = { +}; + +xenhost_ops_t xh_hvm_nested_ops = { +}; +static void __init init_hvm_pv_info (void ) {int major, minor;
arch/x86/xen/enlighten_hvm.c static void __init xen_hvm_guest_init(void) · line 191
Quoted 6 lines
arch/x86/xen/enlighten_hvm.c +3
-0@@ -179,6 +186,12 @@ static void __init xen_hvm_guest_init(void) {if (xen_pv_domain ())return ; +/* +* We need only xenhost_r1 for HVM guests since they cannot be +* driver domain (?) or dom0.
I think even HVM guests could (in theory) be driver domains.
Quoted 33 lines
arch/x86/xen/enlighten_hvm.c +3
-0+*/ +if (!xen_pvh_domain ()) +xenhost_register (xenhost_r1, &xh_hvm_ops);init_hvm_pv_info ();arch/x86/xen/enlighten_pv.c +7
-0@@ -36,6 +36,7 @@#include <xen/xen.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/interface/physdev.h> @@ -1188,6 +1189,12 @@ static void __init xen_dom0_set_legacy_features(void) x86_platform.legacy.rtc =1 ; } +xenhost_ops_t xh_pv_ops = { +}; + +xenhost_ops_t xh_pv_nested_ops = { +}; +/* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) {@@ -1198,6 +1205,15 @@ asmlinkage __visible void __init xen_start_kernel(void)if (!xen_start_info)
arch/x86/xen/enlighten_pv.c asmlinkage __visible void __init xen_start_kernel(void) · line 1215
Quoted 10 lines
arch/x86/xen/enlighten_pv.c +8
-0return ; +xenhost_register (xenhost_r1, &xh_pv_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_pv_nested_ops);
I don't think a driver domain other than dom0 "knows" this in the beginning. It will need to register xenhost_r2 in case it learns about a pv device from L0 hypervisor.
Quoted 155 lines
arch/x86/xen/enlighten_pv.c +1
-0+ xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags;arch/x86/xen/enlighten_pvh.c +12
-0@@ -8,6 +8,7 @@#include <asm/e820/api.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <asm/xen/interface.h> #include <asm/xen/hypercall.h> @@ -21,11 +22,22 @@*/ bool xen_pvh __attribute__((section(".data"))) = 0; +extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops; +void __init xen_pvh_init (void ) {u32 msr;u64 pfn; +xenhost_register (xenhost_r1, &xh_hvm_ops); + +/* +* Detect in some implementation defined manner whether this is +* nested or not. +*/ +if (xen_driver_domain () &&xen_nested ()) +xenhost_register (xenhost_r2, &xh_hvm_nested_ops); + xen_pvh =1 ; xen_start_flags = pvh_start_info.flags;arch/x86/xen/xenhost.c new file +75
-0@@ -0,0 +1,75 @@ +#include <linux/types.h> +#include <linux/bug.h> +#include <xen/xen.h> +#include <xen/xenhost.h> + +xenhost_t xenhosts[2 ]; +/* +* xh_default: interface to the regular hypervisor. xenhost_type is xenhost_r0 +* or xenhost_r1. +* +* xh_remote: interface to remote hypervisor. Needed for PV driver support on +* L1-dom0/driver-domain for nested Xen. xenhost_type is xenhost_r2. +*/ +xenhost_t *xh_default = (xenhost_t *) &xenhosts[0 ]; +xenhost_t *xh_remote = (xenhost_t *) &xenhosts[1 ]; + +/* +* Exported for use of for_each_xenhost(). +*/ +EXPORT_SYMBOL_GPL (xenhosts); + +/* +* Some places refer directly to a specific type of xenhost. +* This might be better as a macro though. +*/ +EXPORT_SYMBOL_GPL (xh_default); +EXPORT_SYMBOL_GPL (xh_remote); + +void xenhost_register (enum xenhost_type type,xenhost_ops_t *ops) +{ +switch (type) { +case xenhost_r0: +case xenhost_r1: +BUG_ON (xh_default->type != xenhost_invalid); + + xh_default->type = type; + xh_default->ops = ops; +break ; +case xenhost_r2: +BUG_ON (xh_remote->type != xenhost_invalid); + +/* +* We should have a default xenhost by the +* time xh_remote is registered. +*/ +BUG_ON (!xh_default); + + xh_remote->type = type; + xh_remote->ops = ops; +break ; +default : +BUG (); + } +} + +/* +* __xenhost_unregister: expected to be called only if there's an +* error early in the init. +*/ +void __xenhost_unregister (enum xenhost_type type) +{ +switch (type) { +case xenhost_r0: +case xenhost_r1: + xh_default->type = xenhost_invalid; + xh_default->ops =NULL ; +break ; +case xenhost_r2: + xh_remote->type = xenhost_invalid; + xh_remote->ops =NULL ; +break ; +default : +BUG (); + } +}include/xen/xen.h +3
-0@@ -42,6 +42,9 @@ extern struct hvm_start_info pvh_start_info;#define xen_initial_domain () (0)#endif /* CONFIG_XEN_DOM0 */ +#define xen_driver_domain () xen_initial_domain() +#define xen_nested () 0 +struct bio_vec ;bool xen_biovec_phys_mergeable (const struct bio_vec *vec1,const struct bio_vec *vec2);include/xen/xenhost.h new file +15
-0@@ -0,0 +1,95 @@ +#ifndef __XENHOST_H +#define __XENHOST_H + +/* +* Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/PVH +* abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to +* expose ops for communication between the guest and Xen (hypercall, cpuid, +* shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning), +* so these could differ based on the kind of underlying Xen: regular, local, +* and nested. +* +* Any call-sites which initiate communication with the hypervisor take +* xenhost_t * as a parameter and use the appropriate xenhost interface. +* +* Note, that the init for the nested xenhost (in the nested dom0 case,
include/xen/xenhost.h line 25
Quoted 10 lines
include/xen/xenhost.h new file +10
-0+* there are two) happens for each operation alongside the default xenhost +* (which remains similar to the one now) and is not deferred for later. +* This allows us to piggy-back on the non-trivial sequencing, inter-locking +* logic in the init of the default xenhost. +*/ + +/* +* xenhost_type: specifies the controlling Xen interface. The notation, +* xenhost_r0, xenhost_r1, xenhost_r2 is meant to invoke hypervisor distance +* from the guest.
This naming makes it hard to correlate the different things: In the nested case xenhost_r2 means L0 hypervisor, same as in the non-nested case xenhost_r1 does.
What about: xenhost_local (instead xenhost_r0), xenhost_direct (instead xenhost_r1) and xenhost_nested (instead xenhost_r2). Or you use an integer to denote the distance enabling even deeper nesting levels (at least in theory).
Quoted 41 lines
include/xen/xenhost.h new file +41
-0+* +* Note that the distance is relative, and so does not identify a specific +* hypervisor, just the role played by the interface: so, instance for L0-guest +* xenhost_r1 would be L0-Xen and for an L1-guest, L1-Xen. +*/ +enum xenhost_type { + xenhost_invalid =0 , +/* +* xenhost_r1: the guest's frontend or backend drivers talking +* to a hypervisor one level removed. +* This is the ordinary, non-nested configuration as well as for the +* typical nested frontends and backends. +* +* The corresponding xenhost_t would continue to use the current +* interfaces, via a redirection layer. +*/ + xenhost_r1, + +/* +* xenhost_r2: frontend drivers communicating with a hypervisor two +* levels removed: so L1-dom0-frontends communicating with L0-Xen. +* +* This is the nested-Xen configuration: L1-dom0-frontend drivers can +* now talk to L0-dom0-backend drivers via a separate xenhost_t. +*/ + xenhost_r2, + +/* +* Local/Co-located case: backend drivers now run in the same address +* space as the hypervisor. The driver model remains same as +* xenhost_r1, but with slightly different interfaces. +* +* Any frontend guests of this hypervisor will continue to be +* xenhost_r1. +*/ + xenhost_r0, +}; + +struct xenhost_ops ; + +typedef struct {
include/xen/xenhost.h line 76
Quoted 10 lines
include/xen/xenhost.h new file +10
-0+enum xenhost_type type; + +struct xenhost_ops *ops; +} xenhost_t; + +typedef struct xenhost_ops { +}xenhost_ops_t ; + +extern xenhost_t *xh_default, *xh_remote; +extern xenhost_t xenhosts[2 ];
Use a max nesting level define here and ...
Quoted 7 lines
include/xen/xenhost.h new file +7
-0+ +/* +* xenhost_register(): is called early in the guest's xen-init, after it detects +* in some implementation defined manner what kind of underlying xenhost or +* xenhosts exist. +* Specifies the type of xenhost being registered and the ops for that. +*/
include/xen/xenhost.h line 93
Quoted 10 lines
include/xen/xenhost.h new file +10
-0+void xenhost_register (enum xenhost_type type,xenhost_ops_t *ops); +void __xenhost_unregister (enum xenhost_type type); + + +/* +* Convoluted interface so we can do this without adding a loop counter. +*/ +#define for_each_xenhost (xh) \ + for ((xh) = (xenhost_t **) &xenhosts[0]; \ + (((xh) - (xenhost_t **)&xenhosts) < 2) && (*xh)->type != xenhost_invalid; (xh)++)
... here, too.
include/xen/xenhost.h line 95
Quoted 3 lines
include/xen/xenhost.h new file +2
-0+ +#endif /* __XENHOST_H */
Juergen
Re: [RFC PATCH 01/16] x86/xen: add xenhost_t interface
Quoted 102 lines · Juergen Gross
Quoted 57 lines · Ankur Arora
Add
xenhost_twhich will serve as an abstraction over Xen interfaces. It co-exists with the PV/HVM/PVH abstractions (x86_init,hypervisor_x86,pv_opsetc) and is meant to capture mechanisms for communication with Xen so we could have different types of underlying Xen: regular, local, and nested.Also add
xenhost_register()and stub registration in the various guest types.Signed-off-by Ankur Arora <[email protected]>---
arch/x86/xen/Makefile | 1 +arch/x86/xen/enlighten_hvm.c| 13 +++++ arch/x86/xen/enlighten_pv.c | 16 ++++++arch/x86/xen/enlighten_pvh.c| 12 +++++ arch/x86/xen/xenhost.c | 75 ++++++++++++++++++++++++++++ include/xen/xen.h | 3 ++
include/xen/xenhost.h | 95 ++++++++++++++++++++++++++++++++++++7 files changed, 215 insertions(+)create mode 100644
arch/x86/xen/xenhost.c
create mode 100644include/xen/xenhost.harch/x86/xen/Makefile +0
-0@@ -18,6 +18,7 @@ obj-y += mmu.oobj-y += time.o
obj-y += grant-table.o obj-y += suspend.o
+obj-y += xenhost.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_XEN_PVHVM) += mmu_hvm.oarch/x86/xen/enlighten_hvm.c +7
-0@@ -5,6 +5,7 @@ #include <linux/kexec.h> #include <linux/memblock.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h> #include <xen/interface/memory.h>@@ -82,6 +83,12 @@ static void __init xen_hvm_init_mem_mapping(void) xen_vcpu_info_reset(0); } +xenhost_ops_t xh_hvm_ops = { +}; + +xenhost_ops_t xh_hvm_nested_ops = { +}; + static void __init init_hvm_pv_info(void) { int major, minor;arch/x86/xen/enlighten_hvm.c static void __init xen_hvm_guest_init(void) · line 191
Quoted 6 lines
arch/x86/xen/enlighten_hvm.c +3
-0@@ -179,6 +186,12 @@ static void __init xen_hvm_guest_init(void) { if (xen_pv_domain()) return; + /* +* We need only xenhost_r1 for HVM guests since they cannot be +* driver domain (?) or dom0. I think even HVM guests could (in theory) be driver domains.
Quoted 35 lines
arch/x86/xen/enlighten_hvm.c +3
-0+*/ + if (!xen_pvh_domain()) + xenhost_register(xenhost_r1, &xh_hvm_ops); init_hvm_pv_info();arch/x86/xen/enlighten_pv.c +10
-0@@ -36,6 +36,7 @@ #include <xen/xen.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/interface/physdev.h>@@ -1188,6 +1189,12 @@ static void __initxen_dom0_set_legacy_features (void ) x86_platform.legacy.rtc = 1; } +xenhost_ops_t xh_pv_ops = { +}; + +xenhost_ops_t xh_pv_nested_ops = { +}; + /* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) {@@ -1198,6 +1205,15 @@ asmlinkage __visible void __init xen_start_kernel(void) if (!xen_start_info) return; + xenhost_register(xenhost_r1, &xh_pv_ops); + + /*
Quoted 8 lines
arch/x86/xen/enlighten_pv.c asmlinkage __visible void __init xen_start_kernel(void) · line 1215
Quoted 5 lines
arch/x86/xen/enlighten_pv.c +5
-0+* Detect in some implementation defined manner whether this is +* nested or not. +*/ + if (xen_driver_domain() && xen_nested()) + xenhost_register(xenhost_r2, &xh_pv_nested_ops);I don't think a driver domain other than dom0 "knows" this in the beginning. It will need to register
xenhost_r2
Right. No point in needlessly registrating as xenhost_r2 without needing to handle any xenhost_r2 devices.
Quoted 1 line
in case it learns about a pv device from L0 hypervisor.
What's the mechanism you are thinking of, for this? I'm guessing this PV device notification could arrive at an arbitrary point in time after the system has booted.
The earlier reason for my assumption that the driver-domain would "know" this at boot, was because it seemed to me that we would need to setup hypercall/shared_info/vcpu_info.
Given that we don't need cpuid/hypercall/shared_info, the remaining few look like they could be made dynamically callable with a bit of refactoring:
- vcpu_info: the registration logic (xen_vcpu_setup() and friends) seems straight-forwardly adaptable to be called dynamically for xenhost_r2. Places where we touch the vcpu_info bits (xen_irq_ops) also seem fine.
- evtchn: xenhost_r2 should only need interdomain evtchns, so should be easy to defer to until we get a xenhost_r2 device.
- grant-table/xenbus: the xenhost_r2 logic (in the current patchset) expects to be inited at core_initcall and postcore_initcall respectively. Again, doesn't
Quoted 164 lines
Quoted 164 lines
arch/x86/xen/enlighten_pv.c +1
-0+ xen_domain_type = XEN_PV_DOMAIN; xen_start_flags = xen_start_info->flags;arch/x86/xen/enlighten_pvh.c +12
-0@@ -8,6 +8,7 @@ #include <asm/e820/api.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <asm/xen/interface.h> #include <asm/xen/hypercall.h>@@ -21,11 +22,22 @@*/ bool xen_pvh __attribute__((section(".data"))) = 0; +extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops; + void __init xen_pvh_init(void) { u32 msr; u64 pfn; + xenhost_register(xenhost_r1, &xh_hvm_ops); + + /* + * Detect in some implementation defined manner whether this is + * nested or not. + */ + if (xen_driver_domain() && xen_nested()) + xenhost_register(xenhost_r2, &xh_hvm_nested_ops); + xen_pvh = 1; xen_start_flags = pvh_start_info.flags;arch/x86/xen/xenhost.c new file +8
-0@@ -0,0 +1,75 @@ +#include <linux/types.h> +#include <linux/bug.h> +#include <xen/xen.h> +#include <xen/xenhost.h> + +xenhost_t xenhosts[2 ]; +/* +* xh_default: interface to the regular hypervisor. xenhost_type is
xenhost_r0
+ * orxenhost_r1.
+ *
+ *xh_remote: interface to remote hypervisor. Needed for PV driver support on
+ * L1-dom0/driver-domain for nested Xen.xenhost_typeisxenhost_r2.
+ */arch/x86/xen/xenhost.c new file +62
-0+xenhost_t *xh_default = (xenhost_t *) &xenhosts[0 ]; +xenhost_t *xh_remote = (xenhost_t *) &xenhosts[1 ]; + +/* +* Exported for use of for_each_xenhost(). +*/ +EXPORT_SYMBOL_GPL (xenhosts); + +/* +* Some places refer directly to a specific type of xenhost. +* This might be better as a macro though. +*/ +EXPORT_SYMBOL_GPL (xh_default); +EXPORT_SYMBOL_GPL (xh_remote); + +void xenhost_register (enum xenhost_type type,xenhost_ops_t *ops) +{ + switch (type) { + case xenhost_r0: + case xenhost_r1: + BUG_ON(xh_default->type != xenhost_invalid); + + xh_default->type = type; + xh_default->ops = ops; + break; + case xenhost_r2: + BUG_ON(xh_remote->type != xenhost_invalid); + + /* + * We should have a default xenhost by the + * time xh_remote is registered. + */ + BUG_ON(!xh_default); + + xh_remote->type = type; + xh_remote->ops = ops; + break; + default: + BUG(); + } +} + +/* +* __xenhost_unregister: expected to be called only if there's an +* error early in the init. +*/ +void __xenhost_unregister (enum xenhost_type type) +{ + switch (type) { + case xenhost_r0: + case xenhost_r1: + xh_default->type = xenhost_invalid; + xh_default->ops = NULL; + break; + case xenhost_r2: + xh_remote->type = xenhost_invalid; + xh_remote->ops = NULL; + break; + default: + BUG(); + } +}include/xen/xen.h +3
-0@@ -42,6 +42,9 @@ extern struct hvm_start_info pvh_start_info; #define xen_initial_domain() (0) #endif /* CONFIG_XEN_DOM0 */ +#define xen_driver_domain () xen_initial_domain() +#define xen_nested () 0 + struct bio_vec; bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, const struct bio_vec *vec2);include/xen/xenhost.h new file +5
-0@@ -0,0 +1,95 @@ +#ifndef __XENHOST_H +#define __XENHOST_H + +/* +* Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/PVH
+ * abstractions (x86_init,hypervisor_x86,pv_opsetc) and is meant to
+ * expose ops for communication between the guest and Xen (hypercall, cpuid,
+ * shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning),
+ * so these could differ based on the kind of underlying Xen:
regular, local,
+ * and nested.
+ *
+ * Any call-sites which initiate communication with the hypervisor take
+ *xenhost_t* as a parameter and use the appropriate xenhost interface.
+ *
+ * Note, that the init for the nested xenhost (in the nested dom0 case,
+ * there are two) happens for each operation alongside the default xenhost
+ * (which remains similar to the one now) and is not deferred for later.
+ * This allows us to piggy-back on the non-trivial sequencing, inter-locking
+ * logic in the init of the default xenhost.
+ */include/xen/xenhost.h new file +2
-0+ +/*
Quoted 8 lines
Quoted 4 lines
+ *
xenhost_type: specifies the controlling Xen interface. The notation,
+ *xenhost_r0,xenhost_r1,xenhost_r2is meant to invoke hypervisor distance
+ * from the guest.This naming makes it hard to correlate the different things: In the nested case
xenhost_r2means L0 hypervisor, same as in the non-nested casexenhost_r1does.
Agreed.
Quoted 5 lines
What about:
xenhost_local(insteadxenhost_r0),xenhost_direct(insteadxenhost_r1) andxenhost_nested(insteadxenhost_r2). Or you use an integer to denote the distance enabling even deeper nesting levels (at least in theory).
These are clearer. Will change.
Quoted 73 lines
Quoted 46 lines
+ *
+ * Note that the distance is relative, and so does not identify a specific
+ * hypervisor, just the role played by the interface: so, instance for L0-guest
+ *xenhost_r1would be L0-Xen and for an L1-guest, L1-Xen.
+ */include/xen/xenhost.h new file +18
-0+enum xenhost_type { + xenhost_invalid = 0, + /* + * xenhost_r1: the guest's frontend or backend drivers talking + * to a hypervisor one level removed. + * This is the ordinary, non-nested configuration as well as for the + * typical nested frontends and backends. + * + * The corresponding xenhost_t would continue to use the current + * interfaces, via a redirection layer. + */ + xenhost_r1, + + /* + * xenhost_r2: frontend drivers communicating with a hypervisor two + * levels removed: so L1-dom0-frontends communicating with L0-Xen. + * + * This is the nested-Xen configuration: L1-dom0-frontend driverscan
+ * now talk to L0-dom0-backend drivers via a separatexenhost_t. + */
+xenhost_r2,
+
+ /*
+ * Local/Co-located case: backend drivers now run in the same address
+ * space as the hypervisor. The driver model remains same as + *xenhost_r1, but with slightly different interfaces. + *
+ * Any frontend guests of this hypervisor will continue to be + *xenhost_r1.
+ */
+xenhost_r0,include/xen/xenhost.h new file +5
-0+}; + +struct xenhost_ops ; + +typedef struct {include/xen/xenhost.h line 76
Quoted 10 lines
include/xen/xenhost.h new file +10
-0+ enum xenhost_type type; + + struct xenhost_ops *ops; +} xenhost_t; + +typedef struct xenhost_ops { +}xenhost_ops_t ; + +extern xenhost_t *xh_default, *xh_remote; +extern xenhost_t xenhosts[2 ];Use a max nesting level define here and ...
Quoted 14 lines
include/xen/xenhost.h new file +3
-0+ +/* +* xenhost_register(): is called early in the guest's xen-init, after it detects
+ * in some implementation defined manner what kind of underlying xenhost or
+ * xenhosts exist.
+ * Specifies the type of xenhost being registered and the ops for that.
+ */include/xen/xenhost.h new file +5
-0+void xenhost_register (enum xenhost_type type,xenhost_ops_t *ops); +void __xenhost_unregister (enum xenhost_type type); + + +/*
Quoted 8 lines
Quoted 6 lines
+ * Convoluted interface so we can do this without adding a loop counter.
+ */
+#definefor_each_xenhost(xh)\
+ for ((xh) = (xenhost_t**) &xenhosts[0]; \
+ (((xh) - (xenhost_t**)&xenhosts) < 2) && (*xh)->type !=xenhost_invalid; (xh)++)... here, too.
Sure.
Ankur
Quoted 7 lines
include/xen/xenhost.h
Quoted 4 lines
include/xen/xenhost.h new file +2
-0+ +#endif /* __XENHOST_H */ Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 01/16] x86/xen: add xenhost_t interface
Quoted 111 lines · Ankur Arora
Quoted 102 lines · Juergen Gross
Quoted 57 lines · Ankur Arora
Add
xenhost_twhich will serve as an abstraction over Xen interfaces. It co-exists with the PV/HVM/PVH abstractions (x86_init,hypervisor_x86,pv_opsetc) and is meant to capture mechanisms for communication with Xen so we could have different types of underlying Xen: regular, local, and nested.Also add
xenhost_register()and stub registration in the various guest types.Signed-off-by Ankur Arora <[email protected]>---
arch/x86/xen/Makefile | 1 +arch/x86/xen/enlighten_hvm.c| 13 +++++ arch/x86/xen/enlighten_pv.c | 16 ++++++arch/x86/xen/enlighten_pvh.c| 12 +++++ arch/x86/xen/xenhost.c | 75 ++++++++++++++++++++++++++++ include/xen/xen.h | 3 ++
include/xen/xenhost.h | 95 ++++++++++++++++++++++++++++++++++++7 files changed, 215 insertions(+)create mode 100644
arch/x86/xen/xenhost.c
create mode 100644include/xen/xenhost.harch/x86/xen/Makefile +0
-0@@ -18,6 +18,7 @@ obj-y += mmu.oobj-y += time.o
obj-y += grant-table.o obj-y += suspend.o
+obj-y += xenhost.o obj-$(CONFIG_XEN_PVHVM) += enlighten_hvm.o obj-$(CONFIG_XEN_PVHVM) += mmu_hvm.oarch/x86/xen/enlighten_hvm.c +7
-0@@ -5,6 +5,7 @@ #include <linux/kexec.h> #include <linux/memblock.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h> #include <xen/interface/memory.h>@@ -82,6 +83,12 @@ static void __init xen_hvm_init_mem_mapping(void) xen_vcpu_info_reset(0); } +xenhost_ops_t xh_hvm_ops = { +}; + +xenhost_ops_t xh_hvm_nested_ops = { +}; + static void __init init_hvm_pv_info(void) { int major, minor;arch/x86/xen/enlighten_hvm.c static void __init xen_hvm_guest_init(void) · line 191
Quoted 6 lines
arch/x86/xen/enlighten_hvm.c +3
-0@@ -179,6 +186,12 @@ static void __init xen_hvm_guest_init(void) { if (xen_pv_domain()) return; + /* +* We need only xenhost_r1 for HVM guests since they cannot be +* driver domain (?) or dom0. I think even HVM guests could (in theory) be driver domains.
Quoted 35 lines
arch/x86/xen/enlighten_hvm.c +3
-0+*/ + if (!xen_pvh_domain()) + xenhost_register(xenhost_r1, &xh_hvm_ops); init_hvm_pv_info();arch/x86/xen/enlighten_pv.c +10
-0@@ -36,6 +36,7 @@ #include <xen/xen.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/interface/physdev.h>@@ -1188,6 +1189,12 @@ static void __initxen_dom0_set_legacy_features (void ) x86_platform.legacy.rtc = 1; } +xenhost_ops_t xh_pv_ops = { +}; + +xenhost_ops_t xh_pv_nested_ops = { +}; + /* First C function to be called on Xen boot */ asmlinkage __visible void __init xen_start_kernel(void) {@@ -1198,6 +1205,15 @@ asmlinkage __visible void __init xen_start_kernel(void) if (!xen_start_info) return; + xenhost_register(xenhost_r1, &xh_pv_ops); + + /*Quoted 8 lines
arch/x86/xen/enlighten_pv.c asmlinkage __visible void __init xen_start_kernel(void) · line 1215
Quoted 5 lines
arch/x86/xen/enlighten_pv.c +5
-0+* Detect in some implementation defined manner whether this is +* nested or not. +*/ + if (xen_driver_domain() && xen_nested()) + xenhost_register(xenhost_r2, &xh_pv_nested_ops);I don't think a driver domain other than dom0 "knows" this in the beginning. It will need to register
xenhost_r2
Quoted 7 lines
Right. No point in needlessly registrating as
xenhost_r2without needing to handle anyxenhost_r2devices.Quoted 1 line
in case it learns about a pv device from L0 hypervisor.
What's the mechanism you are thinking of, for this? I'm guessing this PV device notification could arrive at an arbitrary point in time after the system has booted.
I'm not sure yet how this should be handled.
Maybe an easy solution would be the presence of a Xen PCI device passed through from L1 hypervisor to L1 dom0. OTOH this would preclude nested Xen for L1 hypervisor running in PVH mode. And for L1 driver domains this would need either a shared PCI device or multiple Xen PCI devices or something new.
There is a design session planned for this topic at the Xen developer summit in July.
Juergen
RFC PATCH 2/16 x86/xen: cpuid support in xenhost_t
In reply to Ankur Aroraxen_cpuid_base() is used to probe and setup features early in a guest's lifetime.
We want this to behave differently depending on xenhost->type: for instance, local xenhosts cannot intercept the cpuid instruction at all.
Add op (*cpuid_base)() in xenhost_ops_t.
--- arch/x86/include/asm/xen/hypervisor.h | 2 +- arch/x86/pci/xen.c | 2 +- arch/x86/xen/enlighten_hvm.c | 7 +++++-- arch/x86/xen/enlighten_pv.c | 16 +++++++++++++++- arch/x86/xen/enlighten_pvh.c | 4 ++++ drivers/tty/hvc/hvc_xen.c | 2 +- drivers/xen/grant-table.c | 3 ++- drivers/xen/xenbus/xenbus_xs.c | 3 ++- include/xen/xenhost.h | 21 +++++++++++++++++++++ 9 files changed, 52 insertions(+), 8 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +1 -1
@@ -53,7 +53,7 @@ static inline bool xen_x2apic_para_available(void)#else static inline bool xen_x2apic_para_available (void ) { -return (xen_cpuid_base () !=0 ); +return (xen_cpuid_base (NULL ) !=0 ); }#endif
arch/x86/pci/xen.c +1 -1
@@ -431,7 +431,7 @@ void __init xen_msi_init(void)* event channels for MSI handling and instead use regular * APIC processing */ -uint32_t eax =cpuid_eax (xen_cpuid_base () +4 ); +uint32_t eax =cpuid_eax (xenhost_cpuid_base (xh_default) +4 );if (((eax &XEN_HVM_CPUID_X2APIC_VIRT ) && x2apic_mode) || ((eax &XEN_HVM_CPUID_APIC_ACCESS_VIRT ) &&boot_cpu_has (X86_FEATURE_APIC )))
arch/x86/xen/enlighten_hvm.c +5 -2
@@ -83,7 +83,10 @@ static void __init xen_hvm_init_mem_mapping(void)xen_vcpu_info_reset (0 ); } +extern uint32_t xen_pv_cpuid_base (xenhost_t *xh); +xenhost_ops_t xh_hvm_ops = { + .cpuid_base = xen_pv_cpuid_base, };xenhost_ops_t xh_hvm_nested_ops = {
@@ -94,7 +97,7 @@ static void __init init_hvm_pv_info(void)int major, minor;uint32_t eax, ebx, ecx, edx, base; - base =xen_cpuid_base (); + base =xenhost_cpuid_base (xh_default); eax =cpuid_eax (base +1 ); major = eax >>16 ;
@@ -250,7 +253,7 @@ static uint32_t __init xen_platform_hvm(void)if (xen_pv_domain () || xen_nopv)return 0 ; -return xen_cpuid_base (); +return xenhost_cpuid_base (xh_default); }static __init void xen_hvm_guest_late_init (void )
arch/x86/xen/enlighten_pv.c +15 -1
@@ -1189,10 +1189,23 @@ static void __init xen_dom0_set_legacy_features(void) x86_platform.legacy.rtc =1 ; } +uint32_t xen_pv_cpuid_base (xenhost_t *xh) +{ +return hypervisor_cpuid_base ("XenVMMXenVMM" ,2 ); +} + +uint32_t xen_pv_nested_cpuid_base (xenhost_t *xh) +{ +return hypervisor_cpuid_base ("XenVMMXenVMM" , +2 /* nested specific leaf? */ ); +} +xenhost_ops_t xh_pv_ops = { + .cpuid_base = xen_pv_cpuid_base, };xenhost_ops_t xh_pv_nested_ops = { + .cpuid_base = xen_pv_nested_cpuid_base, };/* First C function to be called on Xen boot */
@@ -1469,7 +1482,8 @@ static int xen_cpu_dead_pv(unsigned int cpu)static uint32_t __init xen_platform_pv (void ) {if (xen_pv_domain ()) -return xen_cpuid_base (); +/* xenhost is setup in xen_start_kernel. */ +return xenhost_cpuid_base (xh_default);return 0 ; }
arch/x86/xen/enlighten_pvh.c +4 -0
@@ -29,6 +29,10 @@ void __init xen_pvh_init(void)u32 msr;u64 pfn; +/* +* Note: we have already called xen_cpuid_base() in +* hypervisor_specific_init() +*/ xenhost_register (xenhost_r1, &xh_hvm_ops);/*
drivers/tty/hvc/hvc_xen.c +1 -1
@@ -595,7 +595,7 @@ console_initcall(xen_cons_init);#ifdef CONFIG_X86 static void xen_hvm_early_write (uint32_t vtermno,const char *str,int len) { -if (xen_cpuid_base ()) +if (xen_cpuid_base (xh_default))outsb (0xe9 , str, len); }#else
drivers/xen/grant-table.c +2 -1
@@ -50,6 +50,7 @@#endif #include <xen/xen.h> +#include <xen/xenhost.h> #include <xen/interface/xen.h> #include <xen/page.h> #include <xen/grant_table.h>
@@ -1318,7 +1319,7 @@ static bool gnttab_need_v2(void)uint32_t base, width;if (xen_pv_domain ()) { - base =xen_cpuid_base (); + base =xenhost_cpuid_base (xh_default);if (cpuid_eax (base) <5 )return false;/* Information not available, use V1. */ width = cpuid_ebx(base + 5) &
drivers/xen/xenbus/xenbus_xs.c +2 -1
@@ -49,6 +49,7 @@#include <asm/xen/hypervisor.h> #include <xen/xenbus.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include "xenbus.h" /*
@@ -722,7 +723,7 @@ static bool xen_strict_xenbus_quirk(void)#ifdef CONFIG_X86 uint32_t eax, ebx, ecx, edx, base; - base =xen_cpuid_base (); + base =xenhost_cpuid_base (xh_default);cpuid (base +1 , &eax, &ebx, &ecx, &edx);if ((eax >>16 ) <4 )
include/xen/xenhost.h +21 -0
@@ -1,6 +1,9 @@#ifndef __XENHOST_H#define __XENHOST_H +#include <xen/interface/features.h> +#include <xen/interface/xen.h> +#include <asm/xen/hypervisor.h> /* * Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/PVH * abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to
@@ -70,6 +73,16 @@ typedef struct { } xenhost_t;typedef struct xenhost_ops { +/* +* xen_cpuid is used to probe features early. +* xenhost_r0: +* Implementation could not use cpuid at all: it's difficult to +* intercept cpuid instruction locally. +* xenhost_r1: +* xenhost_r2: +* Separate cpuid-leafs? +*/ +uint32_t (*cpuid_base)(xenhost_t *xenhost); }xenhost_ops_t ;extern xenhost_t *xh_default, *xh_remote;
@@ -92,4 +105,12 @@ void __xenhost_unregister(enum xenhost_type type);for ((xh) = (xenhost_t **) &xenhosts[0 ]; \ (((xh) - (xenhost_t **)&xenhosts) <2 ) && (*xh)->type != xenhost_invalid; (xh)++) +static inline uint32_t xenhost_cpuid_base(xenhost_t *xh) +{ +if (xh) +return (xh->ops->cpuid_base)(xh); +else +return xen_cpuid_base (); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 02/16] x86/xen: cpuid support in xenhost_t
Quoted 9 lines · Ankur Arora
xen_cpuid_base()is used to probe and setup features early in a guest's lifetime.We want this to behave differently depending on
xenhost->type: for instance, local xenhosts cannot intercept the cpuid instruction at all.Add op (*cpuid_base)() in
xenhost_ops_t.Signed-off-by Ankur Arora <[email protected]>
What is the real layout of hypervisor nesting here?
When Xen is at L0, all HVM guests get working CPUID faulting to combat this problem, because CPUID faulting can be fully emulated even on older Intel hardware, and AMD hardware.
It is a far cleaner way of fixing the problem.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 3/16 x86/xen: make hypercall_page generic
In reply to Ankur AroraMake hypercall_page a generic interface which can be implemented by other hypervisors. With this change, hypercall_page now points to the newly introduced xen_hypercall_page which is seeded by Xen, or to one that is filled in by a different hypervisor.
--- arch/x86/include/asm/xen/hypercall.h | 12 +++++++----- arch/x86/xen/enlighten.c | 1 + arch/x86/xen/enlighten_hvm.c | 3 ++- arch/x86/xen/enlighten_pv.c | 1 + arch/x86/xen/enlighten_pvh.c | 3 ++- arch/x86/xen/xen-asm_32.S | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- arch/x86/xen/xen-head.S | 8 ++++---- 8 files changed, 19 insertions(+), 13 deletions(-)
arch/x86/include/asm/xen/hypercall.h +7 -5
@@ -86,11 +86,13 @@ struct xen_dm_op_buf;* there aren't more than 5 arguments...) */ -extern struct {char _entry[32 ]; } hypercall_page[]; +struct hypercall_entry {char _entry[32 ]; }; +extern struct hypercall_entry xen_hypercall_page[128 ]; +extern struct hypercall_entry *hypercall_page; -#define __HYPERCALL "call hypercall_page+%c[offset]" +#define __HYPERCALL CALL_NOSPEC#define __HYPERCALL_ENTRY (x) \ - [offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0])) + [thunk_target] "0" (hypercall_page + __HYPERVISOR_##x)#ifdef CONFIG_X86_32 #define __HYPERCALL_RETREG "eax"
@@ -116,7 +118,7 @@ extern struct { char _entry[32]; } hypercall_page[]; registerunsigned long __arg4 asm (__HYPERCALL_ARG4REG ) = __arg4; \ registerunsigned long __arg5 asm (__HYPERCALL_ARG5REG ) = __arg5; -#define __HYPERCALL_0PARAM "=r" (__res), ASM_CALL_CONSTRAINT +#define __HYPERCALL_0PARAM "=&r" (__res), ASM_CALL_CONSTRAINT#define __HYPERCALL_1PARAM __HYPERCALL_0PARAM, "+r" (__arg1)#define __HYPERCALL_2PARAM __HYPERCALL_1PARAM, "+r" (__arg2)#define __HYPERCALL_3PARAM __HYPERCALL_2PARAM, "+r" (__arg3)
@@ -208,7 +210,7 @@ xen_single_call(unsigned int call, asmvolatile (CALL_NOSPEC : __HYPERCALL_5PARAM - : [thunk_target] "a" (&hypercall_page[call]) + : [thunk_target] "0" (hypercall_page + call) : __HYPERCALL_CLOBBER5);return (long )__res;
arch/x86/xen/enlighten.c +1 -0
@@ -20,6 +20,7 @@#include "smp.h" #include "pmu.h" +struct hypercall_entry *hypercall_page;EXPORT_SYMBOL_GPL (hypercall_page);/*
arch/x86/xen/enlighten_hvm.c +2 -1
@@ -115,8 +115,9 @@ static void __init init_hvm_pv_info(void) pv_info.name ="Xen HVM" ; msr =cpuid_ebx (base +2 ); - pfn =__pa (hypercall_page); + pfn =__pa (xen_hypercall_page);wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + hypercall_page = xen_hypercall_page; }xen_setup_features ();
arch/x86/xen/enlighten_pv.c +1 -0
@@ -1217,6 +1217,7 @@ asmlinkage __visible void __init xen_start_kernel(void)if (!xen_start_info)return ; + hypercall_page = xen_hypercall_page;xenhost_register (xenhost_r1, &xh_pv_ops);
arch/x86/xen/enlighten_pvh.c +2 -1
@@ -46,8 +46,9 @@ void __init xen_pvh_init(void) xen_start_flags = pvh_start_info.flags; msr =cpuid_ebx (xen_cpuid_base () +2 ); - pfn =__pa (hypercall_page); + pfn =__pa (xen_hypercall_page);wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + hypercall_page = xen_hypercall_page; }void __init mem_map_via_hcall (struct boot_params *boot_params_p)
arch/x86/xen/xen-asm_32.S +1 -1
@@ -121,7 +121,7 @@ xen_iret_end_crit: hyper_iret: /* put this out of line since its very rarely used */ - jmp hypercall_page + __HYPERVISOR_iret * 32 + jmp xen_hypercall_page + __HYPERVISOR_iret * 32 .globl xen_iret_start_crit, xen_iret_end_crit
arch/x86/xen/xen-asm_64.S +1 -1
@@ -70,7 +70,7 @@ ENTRY(xen_early_idt_handler_array) END(xen_early_idt_handler_array) __FINIT -hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 +hypercall_iret = xen_hypercall_page + __HYPERVISOR_iret * 32 /* * Xen64 iret frame: *
arch/x86/xen/xen-head.S +4 -4
@@ -58,18 +58,18 @@ END(startup_xen) .pushsection .text .balign PAGE_SIZE -ENTRY(hypercall_page) +ENTRY(xen_hypercall_page) .rept (PAGE_SIZE / 32) UNWIND_HINT_EMPTY .skip 32 .endr #define HYPERCALL(n) \ - .equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \ + .equ xen_hypercall_##n, xen_hypercall_page + __HYPERVISOR_##n * 32; \ .type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32 #include <asm/xen-hypercalls.h> #undef HYPERCALL -END(hypercall_page) +END(xen_hypercall_page) .popsection ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "linux")
@@ -85,7 +85,7 @@ END(hypercall_page) #ifdef CONFIG_XEN_PV ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR startup_xen) #endif - ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page) + ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR xen_hypercall_page) ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .ascii "!writable_page_tables|pae_pgdir_above_4gb") ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES,
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 3/16 x86/xen: make hypercall_page generic
In reply to Ankur AroraMake hypercall_page a generic interface which can be implemented by other hypervisors. With this change, hypercall_page now points to the newly introduced xen_hypercall_page which is seeded by Xen, or to one that is filled in by a different hypervisor.
--- arch/x86/include/asm/xen/hypercall.h | 12 +++++++----- arch/x86/xen/enlighten.c | 1 + arch/x86/xen/enlighten_hvm.c | 3 ++- arch/x86/xen/enlighten_pv.c | 1 + arch/x86/xen/enlighten_pvh.c | 3 ++- arch/x86/xen/xen-asm_32.S | 2 +- arch/x86/xen/xen-asm_64.S | 2 +- arch/x86/xen/xen-head.S | 8 ++++---- 8 files changed, 19 insertions(+), 13 deletions(-)
arch/x86/include/asm/xen/hypercall.h +7 -5
@@ -86,11 +86,13 @@ struct xen_dm_op_buf;* there aren't more than 5 arguments...) */ -extern struct {char _entry[32 ]; } hypercall_page[]; +struct hypercall_entry {char _entry[32 ]; }; +extern struct hypercall_entry xen_hypercall_page[128 ]; +extern struct hypercall_entry *hypercall_page; -#define __HYPERCALL "call hypercall_page+%c[offset]" +#define __HYPERCALL CALL_NOSPEC#define __HYPERCALL_ENTRY (x) \ - [offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0])) + [thunk_target] "0" (hypercall_page + __HYPERVISOR_##x)#ifdef CONFIG_X86_32 #define __HYPERCALL_RETREG "eax"
@@ -116,7 +118,7 @@ extern struct { char _entry[32]; } hypercall_page[]; registerunsigned long __arg4 asm (__HYPERCALL_ARG4REG ) = __arg4; \ registerunsigned long __arg5 asm (__HYPERCALL_ARG5REG ) = __arg5; -#define __HYPERCALL_0PARAM "=r" (__res), ASM_CALL_CONSTRAINT +#define __HYPERCALL_0PARAM "=&r" (__res), ASM_CALL_CONSTRAINT#define __HYPERCALL_1PARAM __HYPERCALL_0PARAM, "+r" (__arg1)#define __HYPERCALL_2PARAM __HYPERCALL_1PARAM, "+r" (__arg2)#define __HYPERCALL_3PARAM __HYPERCALL_2PARAM, "+r" (__arg3)
@@ -208,7 +210,7 @@ xen_single_call(unsigned int call, asmvolatile (CALL_NOSPEC : __HYPERCALL_5PARAM - : [thunk_target] "a" (&hypercall_page[call]) + : [thunk_target] "0" (hypercall_page + call) : __HYPERCALL_CLOBBER5);return (long )__res;
arch/x86/xen/enlighten.c +1 -0
@@ -20,6 +20,7 @@#include "smp.h" #include "pmu.h" +struct hypercall_entry *hypercall_page;EXPORT_SYMBOL_GPL (hypercall_page);/*
arch/x86/xen/enlighten_hvm.c +2 -1
@@ -115,8 +115,9 @@ static void __init init_hvm_pv_info(void) pv_info.name ="Xen HVM" ; msr =cpuid_ebx (base +2 ); - pfn =__pa (hypercall_page); + pfn =__pa (xen_hypercall_page);wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + hypercall_page = xen_hypercall_page; }xen_setup_features ();
arch/x86/xen/enlighten_pv.c +1 -0
@@ -1217,6 +1217,7 @@ asmlinkage __visible void __init xen_start_kernel(void)if (!xen_start_info)return ; + hypercall_page = xen_hypercall_page;xenhost_register (xenhost_r1, &xh_pv_ops);
arch/x86/xen/enlighten_pvh.c +2 -1
@@ -46,8 +46,9 @@ void __init xen_pvh_init(void) xen_start_flags = pvh_start_info.flags; msr =cpuid_ebx (xen_cpuid_base () +2 ); - pfn =__pa (hypercall_page); + pfn =__pa (xen_hypercall_page);wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + hypercall_page = xen_hypercall_page; }void __init mem_map_via_hcall (struct boot_params *boot_params_p)
arch/x86/xen/xen-asm_32.S +1 -1
@@ -121,7 +121,7 @@ xen_iret_end_crit: hyper_iret: /* put this out of line since its very rarely used */ - jmp hypercall_page + __HYPERVISOR_iret * 32 + jmp xen_hypercall_page + __HYPERVISOR_iret * 32 .globl xen_iret_start_crit, xen_iret_end_crit
arch/x86/xen/xen-asm_64.S +1 -1
@@ -70,7 +70,7 @@ ENTRY(xen_early_idt_handler_array) END(xen_early_idt_handler_array) __FINIT -hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 +hypercall_iret = xen_hypercall_page + __HYPERVISOR_iret * 32 /* * Xen64 iret frame: *
arch/x86/xen/xen-head.S +4 -4
@@ -58,18 +58,18 @@ END(startup_xen) .pushsection .text .balign PAGE_SIZE -ENTRY(hypercall_page) +ENTRY(xen_hypercall_page) .rept (PAGE_SIZE / 32) UNWIND_HINT_EMPTY .skip 32 .endr #define HYPERCALL(n) \ - .equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \ + .equ xen_hypercall_##n, xen_hypercall_page + __HYPERVISOR_##n * 32; \ .type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32 #include <asm/xen-hypercalls.h> #undef HYPERCALL -END(hypercall_page) +END(xen_hypercall_page) .popsection ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "linux")
@@ -85,7 +85,7 @@ END(hypercall_page) #ifdef CONFIG_XEN_PV ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR startup_xen) #endif - ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page) + ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR xen_hypercall_page) ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .ascii "!writable_page_tables|pae_pgdir_above_4gb") ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES,
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 4/16 x86/xen: hypercall support for xenhost_t
In reply to Ankur AroraAllow for different hypercall implementations for different xenhost types. Nested xenhost, which has two underlying xenhosts, can use both simultaneously.
The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x A new macro (hypervisor_*) takes xenhost_t * as a parameter and does the right thing.
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.
--- arch/x86/include/asm/xen/hypercall.h | 233 ++++++++++++++++++--------- arch/x86/xen/enlighten.c | 3 - arch/x86/xen/enlighten_hvm.c | 23 ++- arch/x86/xen/enlighten_pv.c | 13 +- arch/x86/xen/enlighten_pvh.c | 9 +- arch/x86/xen/xen-head.S | 3 + drivers/xen/fallback.c | 8 +- include/xen/xenhost.h | 23 +++ 8 files changed, 218 insertions(+), 97 deletions(-)
arch/x86/include/asm/xen/hypercall.h +157 -76
@@ -51,6 +51,7 @@#include <xen/interface/physdev.h> #include <xen/interface/platform.h> #include <xen/interface/xen-mca.h> +#include <xen/xenhost.h> struct xen_dm_op_buf ;
@@ -88,11 +89,11 @@ struct xen_dm_op_buf;struct hypercall_entry {char _entry[32 ]; };extern struct hypercall_entry xen_hypercall_page[128 ]; -extern struct hypercall_entry *hypercall_page; +extern struct hypercall_entry xen_hypercall_page2[128 ];#define __HYPERCALL CALL_NOSPEC -#define __HYPERCALL_ENTRY (x) \ - [thunk_target] "0" (hypercall_page + __HYPERVISOR_##x) +#define __HYPERCALL_ENTRY (xh, x) \ + [thunk_target] "0" (xh->hypercall_page + __HYPERVISOR_##x)#ifdef CONFIG_X86_32 #define __HYPERCALL_RETREG "eax"
@@ -144,57 +145,57 @@ extern struct hypercall_entry *hypercall_page;#define __HYPERCALL_CLOBBER1 __HYPERCALL_CLOBBER2, __HYPERCALL_ARG2REG#define __HYPERCALL_CLOBBER0 __HYPERCALL_CLOBBER1, __HYPERCALL_ARG1REG -#define _hypercall0 (type, name) \ +#define _hypercall0 (xh, type, name) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_0ARG(); \ asm volatile (__HYPERCALL \ : __HYPERCALL_0PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER0); \ (type)__res; \ }) -#define _hypercall1 (type, name, a1) \ +#define _hypercall1 (xh, type, name, a1) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_1ARG(a1); \ asm volatile (__HYPERCALL \ : __HYPERCALL_1PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER1); \ (type)__res; \ }) -#define _hypercall2 (type, name, a1, a2) \ +#define _hypercall2 (xh, type, name, a1, a2) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_2ARG(a1, a2); \ asm volatile (__HYPERCALL \ : __HYPERCALL_2PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER2); \ (type)__res; \ }) -#define _hypercall3 (type, name, a1, a2, a3) \ +#define _hypercall3 (xh, type, name, a1, a2, a3) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_3ARG(a1, a2, a3); \ asm volatile (__HYPERCALL \ : __HYPERCALL_3PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER3); \ (type)__res; \ }) -#define _hypercall4 (type, name, a1, a2, a3, a4) \ +#define _hypercall4 (xh, type, name, a1, a2, a3, a4) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_4ARG(a1, a2, a3, a4); \ asm volatile (__HYPERCALL \ : __HYPERCALL_4PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER4); \ (type)__res; \ })
@@ -210,7 +211,7 @@ xen_single_call(unsigned int call, asmvolatile (CALL_NOSPEC : __HYPERCALL_5PARAM - : [thunk_target] "0" (hypercall_page + call) + : [thunk_target] "0" (xh_default->hypercall_page + call) : __HYPERCALL_CLOBBER5);return (long )__res;
@@ -232,170 +233,235 @@ privcmd_call(unsigned int call, }static inline int -HYPERVISOR_set_trap_table (struct trap_info *table) +hypervisor_set_trap_table (xenhost_t *xh,struct trap_info *table) { -return _hypercall1 (int, set_trap_table, table); +return _hypercall1 (xh, int, set_trap_table, table); } +#define HYPERVISOR_set_trap_table (table) \ + hypervisor_set_trap_table(xh_default, table) +static inline int -HYPERVISOR_mmu_update (struct mmu_update *req,int count, +hypervisor_mmu_update (xenhost_t *xh,struct mmu_update *req,int count,int *success_count,domid_t domid) { -return _hypercall4 (int, mmu_update, req, count, success_count, domid); +return _hypercall4 (xh, int, mmu_update, req, count, success_count, domid); } +#define HYPERVISOR_mmu_update (req, count, success_count, domid) \ + hypervisor_mmu_update(xh_default, req, count, success_count, domid)static inline int -HYPERVISOR_mmuext_op (struct mmuext_op *op,int count, +hypervisor_mmuext_op (xenhost_t *xh,struct mmuext_op *op,int count,int *success_count,domid_t domid) { -return _hypercall4 (int, mmuext_op, op, count, success_count, domid); +return _hypercall4 (xh, int, mmuext_op, op, count, success_count, domid); } +#define HYPERVISOR_mmuext_op (op, count, success_count, domid) \ + hypervisor_mmuext_op(xh_default, op, count, success_count, domid) +static inline int -HYPERVISOR_set_gdt (unsigned long *frame_list,int entries) +hypervisor_set_gdt (xenhost_t *xh,unsigned long *frame_list,int entries) { -return _hypercall2 (int, set_gdt, frame_list, entries); +return _hypercall2 (xh, int, set_gdt, frame_list, entries); } +#define HYPERVISOR_set_gdt (frame_list, entries) \ + hypervisor_set_gdt(xh_default, frame_list, entries) +static inline int -HYPERVISOR_callback_op (int cmd,void *arg) +hypervisor_callback_op (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, callback_op, cmd, arg); +return _hypercall2 (xh, int, callback_op, cmd, arg); } +#define HYPERVISOR_callback_op (cmd, arg) \ + hypervisor_callback_op(xh_default, cmd, arg) +static inline int -HYPERVISOR_sched_op (int cmd,void *arg) +hypervisor_sched_op (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, sched_op, cmd, arg); +return _hypercall2 (xh, int, sched_op, cmd, arg); } +#define HYPERVISOR_sched_op (cmd, arg) \ + hypervisor_sched_op(xh_default, cmd, arg) +static inline long -HYPERVISOR_set_timer_op (u64 timeout) +hypervisor_set_timer_op (xenhost_t *xh,u64 timeout) {unsigned long timeout_hi = (unsigned long )(timeout>>32 );unsigned long timeout_lo = (unsigned long )timeout; -return _hypercall2 (long, set_timer_op, timeout_lo, timeout_hi); +return _hypercall2 (xh, long, set_timer_op, timeout_lo, timeout_hi); } +#define HYPERVISOR_set_timer_op (timeout) \ + hypervisor_set_timer_op(xh_default, timeout) +static inline int -HYPERVISOR_mca (struct xen_mc *mc_op) +hypervisor_mca (xenhost_t *xh,struct xen_mc *mc_op) { mc_op->interface_version =XEN_MCA_INTERFACE_VERSION ; -return _hypercall1 (int, mca, mc_op); +return _hypercall1 (xh, int, mca, mc_op); } +#define HYPERVISOR_mca (mc_op) \ + hypervisor_mca(xh_default, mc_op) +static inline int -HYPERVISOR_platform_op (struct xen_platform_op *op) +hypervisor_platform_op (xenhost_t *xh,struct xen_platform_op *op) { op->interface_version =XENPF_INTERFACE_VERSION ; -return _hypercall1 (int, platform_op, op); +return _hypercall1 (xh, int, platform_op, op); } +#define HYPERVISOR_platform_op (op) \ + hypervisor_platform_op(xh_default, op) +static inline int -HYPERVISOR_set_debugreg (int reg,unsigned long value) +hypervisor_set_debugreg (xenhost_t *xh,int reg,unsigned long value) { -return _hypercall2 (int, set_debugreg, reg, value); +return _hypercall2 (xh, int, set_debugreg, reg, value); } +#define HYPERVISOR_set_debugreg (reg, value) \ + hypervisor_set_debugreg(xh_default, reg, value) +static inline unsigned long -HYPERVISOR_get_debugreg (int reg) +hypervisor_get_debugreg (xenhost_t *xh,int reg) { - return _hypercall1(unsigned long, get_debugreg, reg); + return _hypercall1(xh, unsigned long, get_debugreg, reg); } +#define HYPERVISOR_get_debugreg (reg) \ + hypervisor_get_debugreg(xh_default, reg)static inline int -HYPERVISOR_update_descriptor (u64 ma,u64 desc) +hypervisor_update_descriptor (xenhost_t *xh,u64 ma,u64 desc) {if (sizeof (u64) ==sizeof (long )) -return _hypercall2 (int, update_descriptor, ma, desc); -return _hypercall4 (int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); +return _hypercall2 (xh, int, update_descriptor, ma, desc); +return _hypercall4 (xh, int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); } +#define HYPERVISOR_update_descriptor (ma, desc) \ + hypervisor_update_descriptor(xh_default, ma, desc) +static inline long -HYPERVISOR_memory_op (unsigned int cmd,void *arg) +hypervisor_memory_op (xenhost_t *xh,unsigned int cmd,void *arg) { -return _hypercall2 (long, memory_op, cmd, arg); +return _hypercall2 (xh, long, memory_op, cmd, arg); } +#define HYPERVISOR_memory_op (cmd, arg) \ + hypervisor_memory_op(xh_default, cmd, arg) \ +static inline int -HYPERVISOR_multicall (void *call_list,uint32_t nr_calls) +hypervisor_multicall (xenhost_t *xh,void *call_list,uint32_t nr_calls) { -return _hypercall2 (int, multicall, call_list, nr_calls); +return _hypercall2 (xh, int, multicall, call_list, nr_calls); } +#define HYPERVISOR_multicall (call_list, nr_calls) \ + hypervisor_multicall(xh_default, call_list, nr_calls) +static inline int -HYPERVISOR_update_va_mapping (unsigned long va,pte_t new_val, +hypervisor_update_va_mapping (xenhost_t *xh,unsigned long va,pte_t new_val,unsigned long flags) {if (sizeof (new_val) ==sizeof (long )) -return _hypercall3 (int, update_va_mapping, va, +return _hypercall3 (xh, int, update_va_mapping, va, new_val.pte, flags);else -return _hypercall4 (int, update_va_mapping, va, +return _hypercall4 (xh, int, update_va_mapping, va, new_val.pte, new_val.pte >>32 , flags); } -extern int __must_check xen_event_channel_op_compat (int ,void *); + +#define HYPERVISOR_update_va_mapping (va, new_val, flags) \ + hypervisor_update_va_mapping(xh_default, va, new_val, flags) + +extern int __must_check xen_event_channel_op_compat (xenhost_t *xh,int ,void *);static inline int -HYPERVISOR_event_channel_op (int cmd,void *arg) +hypervisor_event_channel_op (xenhost_t *xh,int cmd,void *arg) { -int rc =_hypercall2 (int, event_channel_op, cmd, arg); +int rc =_hypercall2 (xh, int, event_channel_op, cmd, arg);if (unlikely (rc == -ENOSYS )) - rc =xen_event_channel_op_compat (cmd, arg); + rc =xen_event_channel_op_compat (xh, cmd, arg);return rc; } +#define HYPERVISOR_event_channel_op (cmd, arg) \ + hypervisor_event_channel_op(xh_default, cmd, arg) +static inline int -HYPERVISOR_xen_version (int cmd,void *arg) +hypervisor_xen_version (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, xen_version, cmd, arg); +return _hypercall2 (xh, int, xen_version, cmd, arg); } +#define HYPERVISOR_xen_version (cmd, arg) \ + hypervisor_xen_version(xh_default, cmd, arg) +static inline int -HYPERVISOR_console_io (int cmd,int count,char *str) +hypervisor_console_io (xenhost_t *xh,int cmd,int count,char *str) { -return _hypercall3 (int, console_io, cmd, count, str); +return _hypercall3 (xh, int, console_io, cmd, count, str); } +#define HYPERVISOR_console_io (cmd, count, str) \ + hypervisor_console_io(xh_default, cmd, count, str) -extern int __must_check xen_physdev_op_compat (int ,void *); +extern int __must_check xen_physdev_op_compat (xenhost_t *xh,int ,void *);static inline int -HYPERVISOR_physdev_op (int cmd,void *arg) +hypervisor_physdev_op (xenhost_t *xh,int cmd,void *arg) { -int rc =_hypercall2 (int, physdev_op, cmd, arg); +int rc =_hypercall2 (xh, int, physdev_op, cmd, arg);if (unlikely (rc == -ENOSYS )) - rc =xen_physdev_op_compat (cmd, arg); + rc =xen_physdev_op_compat (xh, cmd, arg);return rc; } +#define HYPERVISOR_physdev_op (cmd, arg) \ + hypervisor_physdev_op(xh_default, cmd, arg)static inline int -HYPERVISOR_grant_table_op (unsigned int cmd,void *uop,unsigned int count) +hypervisor_grant_table_op (xenhost_t *xh,unsigned int cmd,void *uop,unsigned int count) { -return _hypercall3 (int, grant_table_op, cmd, uop, count); +return _hypercall3 (xh, int, grant_table_op, cmd, uop, count); } +#define HYPERVISOR_grant_table_op (cmd, uop, count) \ + hypervisor_grant_table_op(xh_default, cmd, uop, count) +static inline int -HYPERVISOR_vm_assist (unsigned int cmd,unsigned int type) +hypervisor_vm_assist (xenhost_t *xh,unsigned int cmd,unsigned int type) { -return _hypercall2 (int, vm_assist, cmd, type); +return _hypercall2 (xh, int, vm_assist, cmd, type); } +#define HYPERVISOR_vm_assist (cmd, type) \ + hypervisor_vm_assist(xh_default, cmd, type) +static inline int -HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args) +hypervisor_vcpu_op (xenhost_t *xh,int cmd,int vcpuid,void *extra_args) { -return _hypercall3 (int, vcpu_op, cmd, vcpuid, extra_args); +return _hypercall3 (xh, int, vcpu_op, cmd, vcpuid, extra_args); } +#define HYPERVISOR_vcpu_op (cmd, vcpuid, extra_args) \ + hypervisor_vcpu_op(xh_default, cmd, vcpuid, extra_args) +#ifdef CONFIG_X86_64 static inline int -HYPERVISOR_set_segment_base (int reg,unsigned long value) +hypervisor_set_segment_base (xenhost_t *xh,int reg,unsigned long value) { -return _hypercall2 (int, set_segment_base, reg, value); +return _hypercall2 (xh, int, set_segment_base, reg, value); } +#define HYPERVISOR_set_segment_base (reg, value) \ + hypervisor_set_segment_base(xh_default, reg, value)#endif static inline int -HYPERVISOR_suspend (unsigned long start_info_mfn) +hypervisor_suspend (xenhost_t *xh,unsigned long start_info_mfn) {struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
@@ -405,38 +471,53 @@ HYPERVISOR_suspend(unsigned long start_info_mfn)* hypercall calling convention this is the third hypercall * argument, which is start_info_mfn here. */ -return _hypercall3 (int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn); +return _hypercall3 (xh, int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn); } +#define HYPERVISOR_suspend (start_info_mfn) \ + hypervisor_suspend(xh_default, start_info_mfn)static inline unsigned long __must_check -HYPERVISOR_hvm_op (int op,void *arg) +hypervisor_hvm_op (xenhost_t *xh,int op,void *arg) { - return _hypercall2(unsigned long, hvm_op, op, arg); + return _hypercall2(xh, unsigned long, hvm_op, op, arg); } +#define HYPERVISOR_hvm_op (op, arg) \ + hypervisor_hvm_op(xh_default, op, arg) +static inline int -HYPERVISOR_tmem_op ( +hypervisor_tmem_op ( +xenhost_t *xh,struct tmem_op *op) { -return _hypercall1 (int, tmem_op, op); +return _hypercall1 (xh, int, tmem_op, op); } +#define HYPERVISOR_tmem_op (op) \ + hypervisor_tmem_op(xh_default, op) +static inline int -HYPERVISOR_xenpmu_op (unsigned int op,void *arg) +hypervisor_xenpmu_op (xenhost_t *xh,unsigned int op,void *arg) { -return _hypercall2 (int, xenpmu_op, op, arg); +return _hypercall2 (xh, int, xenpmu_op, op, arg); } +#define HYPERVISOR_xenpmu_op (op, arg) \ + hypervisor_xenpmu_op(xh_default, op, arg) +static inline int -HYPERVISOR_dm_op ( +hypervisor_dm_op ( +xenhost_t *xh,domid_t dom,unsigned int nr_bufs,struct xen_dm_op_buf *bufs) {int ret;stac (); - ret =_hypercall3 (int, dm_op, dom, nr_bufs, bufs); + ret =_hypercall3 (xh, int, dm_op, dom, nr_bufs, bufs);clac ();return ret; } +#define HYPERVISOR_dm_op (dom, nr_bufs, bufs) \ + hypervisor_dm_op(xh_default, dom, nr_bufs, bufs)static inline void MULTI_fpu_taskswitch (struct multicall_entry *mcl,int set)
arch/x86/xen/enlighten.c +0 -3
@@ -20,9 +20,6 @@#include "smp.h" #include "pmu.h" -struct hypercall_entry *hypercall_page; -EXPORT_SYMBOL_GPL (hypercall_page); -/* * Pointer to the xen_vcpu_info structure or * &HYPERVISOR_shared_info->vcpu_info[cpu]. See xen_hvm_init_shared_info
arch/x86/xen/enlighten_hvm.c +16 -7
@@ -85,8 +85,20 @@ static void __init xen_hvm_init_mem_mapping(void)extern uint32_t xen_pv_cpuid_base (xenhost_t *xh); +void xen_hvm_setup_hypercall_page (xenhost_t *xh) +{ +u32 msr; +u64 pfn; + + msr =cpuid_ebx (xenhost_cpuid_base (xh) +2 ); + pfn =__pa (xen_hypercall_page); +wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + xh->hypercall_page = xen_hypercall_page; +} +xenhost_ops_t xh_hvm_ops = { .cpuid_base = xen_pv_cpuid_base, + .setup_hypercall_page = xen_hvm_setup_hypercall_page, };xenhost_ops_t xh_hvm_nested_ops = {
@@ -96,6 +108,7 @@ static void __init init_hvm_pv_info(void) {int major, minor;uint32_t eax, ebx, ecx, edx, base; +xenhost_t **xh; base =xenhost_cpuid_base (xh_default); eax =cpuid_eax (base +1 );
@@ -110,14 +123,10 @@ static void __init init_hvm_pv_info(void)if (xen_pvh_domain ()) pv_info.name ="Xen PVH" ;else { -u64 pfn; -uint32_t msr; - pv_info.name ="Xen HVM" ; - msr =cpuid_ebx (base +2 ); - pfn =__pa (xen_hypercall_page); -wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); - hypercall_page = xen_hypercall_page; + +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); }xen_setup_features ();
arch/x86/xen/enlighten_pv.c +12 -1
@@ -1200,12 +1200,20 @@ uint32_t xen_pv_nested_cpuid_base(xenhost_t *xh) 2 /* nested specific leaf? */); } +static void xen_pv_setup_hypercall_page (xenhost_t *xh) +{ + xh->hypercall_page = xen_hypercall_page; +} +xenhost_ops_t xh_pv_ops = { .cpuid_base = xen_pv_cpuid_base, + + .setup_hypercall_page = xen_pv_setup_hypercall_page, };xenhost_ops_t xh_pv_nested_ops = { .cpuid_base = xen_pv_nested_cpuid_base, + .setup_hypercall_page =NULL , };/* First C function to be called on Xen boot */
@@ -1213,11 +1221,11 @@ asmlinkage __visible void __init xen_start_kernel(void) {struct physdev_set_iopl set_iopl;unsigned long initrd_start =0 ; +xenhost_t **xh;int rc;if (!xen_start_info)return ; - hypercall_page = xen_hypercall_page;xenhost_register (xenhost_r1, &xh_pv_ops);
@@ -1228,6 +1236,9 @@ asmlinkage __visible void __init xen_start_kernel(void)if (xen_driver_domain () &&xen_nested ())xenhost_register (xenhost_r2, &xh_pv_nested_ops); +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); + xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags;
arch/x86/xen/enlighten_pvh.c +3 -6
@@ -26,8 +26,7 @@ extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops;void __init xen_pvh_init (void ) { -u32 msr; -u64 pfn; +xenhost_t **xh;/* * Note: we have already called xen_cpuid_base() in
@@ -45,10 +44,8 @@ void __init xen_pvh_init(void) xen_pvh =1 ; xen_start_flags = pvh_start_info.flags; - msr =cpuid_ebx (xen_cpuid_base () +2 ); - pfn =__pa (xen_hypercall_page); -wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); - hypercall_page = xen_hypercall_page; +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); }void __init mem_map_via_hcall (struct boot_params *boot_params_p)
arch/x86/xen/xen-head.S +3 -0
@@ -70,6 +70,9 @@ ENTRY(xen_hypercall_page) #include <asm/xen-hypercalls.h> #undef HYPERCALL END(xen_hypercall_page) +/* + * Add xen_hypercall_page2 for remote xenhost? + */ .popsection ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "linux")
drivers/xen/fallback.c +4 -4
@@ -5,14 +5,14 @@#include <asm/hypervisor.h> #include <asm/xen/hypercall.h> -int xen_event_channel_op_compat (int cmd,void *arg) +int xen_event_channel_op_compat (xenhost_t *xh,int cmd,void *arg) {struct evtchn_op op;int rc; op.cmd = cmd;memcpy (&op.u, arg,sizeof (op.u)); - rc =_hypercall1 (int, event_channel_op_compat, &op); + rc =_hypercall1 (xh, int, event_channel_op_compat, &op);switch (cmd) {case EVTCHNOP_close:
@@ -44,14 +44,14 @@ int xen_event_channel_op_compat(int cmd, void *arg) }EXPORT_SYMBOL_GPL (xen_event_channel_op_compat); -int xen_physdev_op_compat (int cmd,void *arg) +int xen_physdev_op_compat (xenhost_t *xh,int cmd,void *arg) {struct physdev_op op;int rc; op.cmd = cmd;memcpy (&op.u, arg,sizeof (op.u)); - rc =_hypercall1 (int, physdev_op_compat, &op); + rc =_hypercall1 (xh, int, physdev_op_compat, &op);switch (cmd) {case PHYSDEVOP_IRQ_UNMASK_NOTIFY :
include/xen/xenhost.h +23 -0
@@ -70,6 +70,8 @@ typedef struct {enum xenhost_type type;struct xenhost_ops *ops; + +struct hypercall_entry *hypercall_page; } xenhost_t; typedef struct xenhost_ops {
@@ -83,6 +85,22 @@ typedef struct xenhost_ops {* Separate cpuid-leafs? */ uint32_t (*cpuid_base)(xenhost_t *xenhost); + +/* +* Hypercall page is setup as the first thing once the PV/PVH/PVHVM +* code detects that it is selected. The first use is in +* xen_setup_features(). +* +* PV/PVH/PVHVM set this up in different ways: hypervisor takes +* care of this for PV, PVH and PVHVM use xen_cpuid. +* +* xenhost_r0: point hypercall_page to external hypercall_page. +* xenhost_r1: what we do now. +* xenhost_r2: hypercall interface that bypasses L1-Xen to go from +* L1-guest to L0-Xen. The interface would allow L0-Xen to be able +* to decide which particular L1-guest was the caller. +*/ +void (*setup_hypercall_page)(xenhost_t *xenhost); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -113,4 +131,9 @@ static inline uint32_t xenhost_cpuid_base(xenhost_t *xh) return xen_cpuid_base(); } +static inline void xenhost_setup_hypercall_page (xenhost_t *xh) +{ + (xh->ops->setup_hypercall_page)(xh); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 4/16 x86/xen: hypercall support for xenhost_t
In reply to Ankur AroraAllow for different hypercall implementations for different xenhost types. Nested xenhost, which has two underlying xenhosts, can use both simultaneously.
The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x A new macro (hypervisor_*) takes xenhost_t * as a parameter and does the right thing.
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.
--- arch/x86/include/asm/xen/hypercall.h | 233 ++++++++++++++++++--------- arch/x86/xen/enlighten.c | 3 - arch/x86/xen/enlighten_hvm.c | 23 ++- arch/x86/xen/enlighten_pv.c | 13 +- arch/x86/xen/enlighten_pvh.c | 9 +- arch/x86/xen/xen-head.S | 3 + drivers/xen/fallback.c | 8 +- include/xen/xenhost.h | 23 +++ 8 files changed, 218 insertions(+), 97 deletions(-)
arch/x86/include/asm/xen/hypercall.h +157 -76
@@ -51,6 +51,7 @@#include <xen/interface/physdev.h> #include <xen/interface/platform.h> #include <xen/interface/xen-mca.h> +#include <xen/xenhost.h> struct xen_dm_op_buf ;
@@ -88,11 +89,11 @@ struct xen_dm_op_buf;struct hypercall_entry {char _entry[32 ]; };extern struct hypercall_entry xen_hypercall_page[128 ]; -extern struct hypercall_entry *hypercall_page; +extern struct hypercall_entry xen_hypercall_page2[128 ];#define __HYPERCALL CALL_NOSPEC -#define __HYPERCALL_ENTRY (x) \ - [thunk_target] "0" (hypercall_page + __HYPERVISOR_##x) +#define __HYPERCALL_ENTRY (xh, x) \ + [thunk_target] "0" (xh->hypercall_page + __HYPERVISOR_##x)#ifdef CONFIG_X86_32 #define __HYPERCALL_RETREG "eax"
@@ -144,57 +145,57 @@ extern struct hypercall_entry *hypercall_page;#define __HYPERCALL_CLOBBER1 __HYPERCALL_CLOBBER2, __HYPERCALL_ARG2REG#define __HYPERCALL_CLOBBER0 __HYPERCALL_CLOBBER1, __HYPERCALL_ARG1REG -#define _hypercall0 (type, name) \ +#define _hypercall0 (xh, type, name) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_0ARG(); \ asm volatile (__HYPERCALL \ : __HYPERCALL_0PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER0); \ (type)__res; \ }) -#define _hypercall1 (type, name, a1) \ +#define _hypercall1 (xh, type, name, a1) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_1ARG(a1); \ asm volatile (__HYPERCALL \ : __HYPERCALL_1PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER1); \ (type)__res; \ }) -#define _hypercall2 (type, name, a1, a2) \ +#define _hypercall2 (xh, type, name, a1, a2) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_2ARG(a1, a2); \ asm volatile (__HYPERCALL \ : __HYPERCALL_2PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER2); \ (type)__res; \ }) -#define _hypercall3 (type, name, a1, a2, a3) \ +#define _hypercall3 (xh, type, name, a1, a2, a3) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_3ARG(a1, a2, a3); \ asm volatile (__HYPERCALL \ : __HYPERCALL_3PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER3); \ (type)__res; \ }) -#define _hypercall4 (type, name, a1, a2, a3, a4) \ +#define _hypercall4 (xh, type, name, a1, a2, a3, a4) \ ({ \ __HYPERCALL_DECLS; \ __HYPERCALL_4ARG(a1, a2, a3, a4); \ asm volatile (__HYPERCALL \ : __HYPERCALL_4PARAM \ - : __HYPERCALL_ENTRY(name) \ + : __HYPERCALL_ENTRY(xh, name) \ : __HYPERCALL_CLOBBER4); \ (type)__res; \ })
@@ -210,7 +211,7 @@ xen_single_call(unsigned int call, asmvolatile (CALL_NOSPEC : __HYPERCALL_5PARAM - : [thunk_target] "0" (hypercall_page + call) + : [thunk_target] "0" (xh_default->hypercall_page + call) : __HYPERCALL_CLOBBER5);return (long )__res;
@@ -232,170 +233,235 @@ privcmd_call(unsigned int call, }static inline int -HYPERVISOR_set_trap_table (struct trap_info *table) +hypervisor_set_trap_table (xenhost_t *xh,struct trap_info *table) { -return _hypercall1 (int, set_trap_table, table); +return _hypercall1 (xh, int, set_trap_table, table); } +#define HYPERVISOR_set_trap_table (table) \ + hypervisor_set_trap_table(xh_default, table) +static inline int -HYPERVISOR_mmu_update (struct mmu_update *req,int count, +hypervisor_mmu_update (xenhost_t *xh,struct mmu_update *req,int count,int *success_count,domid_t domid) { -return _hypercall4 (int, mmu_update, req, count, success_count, domid); +return _hypercall4 (xh, int, mmu_update, req, count, success_count, domid); } +#define HYPERVISOR_mmu_update (req, count, success_count, domid) \ + hypervisor_mmu_update(xh_default, req, count, success_count, domid)static inline int -HYPERVISOR_mmuext_op (struct mmuext_op *op,int count, +hypervisor_mmuext_op (xenhost_t *xh,struct mmuext_op *op,int count,int *success_count,domid_t domid) { -return _hypercall4 (int, mmuext_op, op, count, success_count, domid); +return _hypercall4 (xh, int, mmuext_op, op, count, success_count, domid); } +#define HYPERVISOR_mmuext_op (op, count, success_count, domid) \ + hypervisor_mmuext_op(xh_default, op, count, success_count, domid) +static inline int -HYPERVISOR_set_gdt (unsigned long *frame_list,int entries) +hypervisor_set_gdt (xenhost_t *xh,unsigned long *frame_list,int entries) { -return _hypercall2 (int, set_gdt, frame_list, entries); +return _hypercall2 (xh, int, set_gdt, frame_list, entries); } +#define HYPERVISOR_set_gdt (frame_list, entries) \ + hypervisor_set_gdt(xh_default, frame_list, entries) +static inline int -HYPERVISOR_callback_op (int cmd,void *arg) +hypervisor_callback_op (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, callback_op, cmd, arg); +return _hypercall2 (xh, int, callback_op, cmd, arg); } +#define HYPERVISOR_callback_op (cmd, arg) \ + hypervisor_callback_op(xh_default, cmd, arg) +static inline int -HYPERVISOR_sched_op (int cmd,void *arg) +hypervisor_sched_op (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, sched_op, cmd, arg); +return _hypercall2 (xh, int, sched_op, cmd, arg); } +#define HYPERVISOR_sched_op (cmd, arg) \ + hypervisor_sched_op(xh_default, cmd, arg) +static inline long -HYPERVISOR_set_timer_op (u64 timeout) +hypervisor_set_timer_op (xenhost_t *xh,u64 timeout) {unsigned long timeout_hi = (unsigned long )(timeout>>32 );unsigned long timeout_lo = (unsigned long )timeout; -return _hypercall2 (long, set_timer_op, timeout_lo, timeout_hi); +return _hypercall2 (xh, long, set_timer_op, timeout_lo, timeout_hi); } +#define HYPERVISOR_set_timer_op (timeout) \ + hypervisor_set_timer_op(xh_default, timeout) +static inline int -HYPERVISOR_mca (struct xen_mc *mc_op) +hypervisor_mca (xenhost_t *xh,struct xen_mc *mc_op) { mc_op->interface_version =XEN_MCA_INTERFACE_VERSION ; -return _hypercall1 (int, mca, mc_op); +return _hypercall1 (xh, int, mca, mc_op); } +#define HYPERVISOR_mca (mc_op) \ + hypervisor_mca(xh_default, mc_op) +static inline int -HYPERVISOR_platform_op (struct xen_platform_op *op) +hypervisor_platform_op (xenhost_t *xh,struct xen_platform_op *op) { op->interface_version =XENPF_INTERFACE_VERSION ; -return _hypercall1 (int, platform_op, op); +return _hypercall1 (xh, int, platform_op, op); } +#define HYPERVISOR_platform_op (op) \ + hypervisor_platform_op(xh_default, op) +static inline int -HYPERVISOR_set_debugreg (int reg,unsigned long value) +hypervisor_set_debugreg (xenhost_t *xh,int reg,unsigned long value) { -return _hypercall2 (int, set_debugreg, reg, value); +return _hypercall2 (xh, int, set_debugreg, reg, value); } +#define HYPERVISOR_set_debugreg (reg, value) \ + hypervisor_set_debugreg(xh_default, reg, value) +static inline unsigned long -HYPERVISOR_get_debugreg (int reg) +hypervisor_get_debugreg (xenhost_t *xh,int reg) { - return _hypercall1(unsigned long, get_debugreg, reg); + return _hypercall1(xh, unsigned long, get_debugreg, reg); } +#define HYPERVISOR_get_debugreg (reg) \ + hypervisor_get_debugreg(xh_default, reg)static inline int -HYPERVISOR_update_descriptor (u64 ma,u64 desc) +hypervisor_update_descriptor (xenhost_t *xh,u64 ma,u64 desc) {if (sizeof (u64) ==sizeof (long )) -return _hypercall2 (int, update_descriptor, ma, desc); -return _hypercall4 (int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); +return _hypercall2 (xh, int, update_descriptor, ma, desc); +return _hypercall4 (xh, int, update_descriptor, ma, ma>>32 , desc, desc>>32 ); } +#define HYPERVISOR_update_descriptor (ma, desc) \ + hypervisor_update_descriptor(xh_default, ma, desc) +static inline long -HYPERVISOR_memory_op (unsigned int cmd,void *arg) +hypervisor_memory_op (xenhost_t *xh,unsigned int cmd,void *arg) { -return _hypercall2 (long, memory_op, cmd, arg); +return _hypercall2 (xh, long, memory_op, cmd, arg); } +#define HYPERVISOR_memory_op (cmd, arg) \ + hypervisor_memory_op(xh_default, cmd, arg) \ +static inline int -HYPERVISOR_multicall (void *call_list,uint32_t nr_calls) +hypervisor_multicall (xenhost_t *xh,void *call_list,uint32_t nr_calls) { -return _hypercall2 (int, multicall, call_list, nr_calls); +return _hypercall2 (xh, int, multicall, call_list, nr_calls); } +#define HYPERVISOR_multicall (call_list, nr_calls) \ + hypervisor_multicall(xh_default, call_list, nr_calls) +static inline int -HYPERVISOR_update_va_mapping (unsigned long va,pte_t new_val, +hypervisor_update_va_mapping (xenhost_t *xh,unsigned long va,pte_t new_val,unsigned long flags) {if (sizeof (new_val) ==sizeof (long )) -return _hypercall3 (int, update_va_mapping, va, +return _hypercall3 (xh, int, update_va_mapping, va, new_val.pte, flags);else -return _hypercall4 (int, update_va_mapping, va, +return _hypercall4 (xh, int, update_va_mapping, va, new_val.pte, new_val.pte >>32 , flags); } -extern int __must_check xen_event_channel_op_compat (int ,void *); + +#define HYPERVISOR_update_va_mapping (va, new_val, flags) \ + hypervisor_update_va_mapping(xh_default, va, new_val, flags) + +extern int __must_check xen_event_channel_op_compat (xenhost_t *xh,int ,void *);static inline int -HYPERVISOR_event_channel_op (int cmd,void *arg) +hypervisor_event_channel_op (xenhost_t *xh,int cmd,void *arg) { -int rc =_hypercall2 (int, event_channel_op, cmd, arg); +int rc =_hypercall2 (xh, int, event_channel_op, cmd, arg);if (unlikely (rc == -ENOSYS )) - rc =xen_event_channel_op_compat (cmd, arg); + rc =xen_event_channel_op_compat (xh, cmd, arg);return rc; } +#define HYPERVISOR_event_channel_op (cmd, arg) \ + hypervisor_event_channel_op(xh_default, cmd, arg) +static inline int -HYPERVISOR_xen_version (int cmd,void *arg) +hypervisor_xen_version (xenhost_t *xh,int cmd,void *arg) { -return _hypercall2 (int, xen_version, cmd, arg); +return _hypercall2 (xh, int, xen_version, cmd, arg); } +#define HYPERVISOR_xen_version (cmd, arg) \ + hypervisor_xen_version(xh_default, cmd, arg) +static inline int -HYPERVISOR_console_io (int cmd,int count,char *str) +hypervisor_console_io (xenhost_t *xh,int cmd,int count,char *str) { -return _hypercall3 (int, console_io, cmd, count, str); +return _hypercall3 (xh, int, console_io, cmd, count, str); } +#define HYPERVISOR_console_io (cmd, count, str) \ + hypervisor_console_io(xh_default, cmd, count, str) -extern int __must_check xen_physdev_op_compat (int ,void *); +extern int __must_check xen_physdev_op_compat (xenhost_t *xh,int ,void *);static inline int -HYPERVISOR_physdev_op (int cmd,void *arg) +hypervisor_physdev_op (xenhost_t *xh,int cmd,void *arg) { -int rc =_hypercall2 (int, physdev_op, cmd, arg); +int rc =_hypercall2 (xh, int, physdev_op, cmd, arg);if (unlikely (rc == -ENOSYS )) - rc =xen_physdev_op_compat (cmd, arg); + rc =xen_physdev_op_compat (xh, cmd, arg);return rc; } +#define HYPERVISOR_physdev_op (cmd, arg) \ + hypervisor_physdev_op(xh_default, cmd, arg)static inline int -HYPERVISOR_grant_table_op (unsigned int cmd,void *uop,unsigned int count) +hypervisor_grant_table_op (xenhost_t *xh,unsigned int cmd,void *uop,unsigned int count) { -return _hypercall3 (int, grant_table_op, cmd, uop, count); +return _hypercall3 (xh, int, grant_table_op, cmd, uop, count); } +#define HYPERVISOR_grant_table_op (cmd, uop, count) \ + hypervisor_grant_table_op(xh_default, cmd, uop, count) +static inline int -HYPERVISOR_vm_assist (unsigned int cmd,unsigned int type) +hypervisor_vm_assist (xenhost_t *xh,unsigned int cmd,unsigned int type) { -return _hypercall2 (int, vm_assist, cmd, type); +return _hypercall2 (xh, int, vm_assist, cmd, type); } +#define HYPERVISOR_vm_assist (cmd, type) \ + hypervisor_vm_assist(xh_default, cmd, type) +static inline int -HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args) +hypervisor_vcpu_op (xenhost_t *xh,int cmd,int vcpuid,void *extra_args) { -return _hypercall3 (int, vcpu_op, cmd, vcpuid, extra_args); +return _hypercall3 (xh, int, vcpu_op, cmd, vcpuid, extra_args); } +#define HYPERVISOR_vcpu_op (cmd, vcpuid, extra_args) \ + hypervisor_vcpu_op(xh_default, cmd, vcpuid, extra_args) +#ifdef CONFIG_X86_64 static inline int -HYPERVISOR_set_segment_base (int reg,unsigned long value) +hypervisor_set_segment_base (xenhost_t *xh,int reg,unsigned long value) { -return _hypercall2 (int, set_segment_base, reg, value); +return _hypercall2 (xh, int, set_segment_base, reg, value); } +#define HYPERVISOR_set_segment_base (reg, value) \ + hypervisor_set_segment_base(xh_default, reg, value)#endif static inline int -HYPERVISOR_suspend (unsigned long start_info_mfn) +hypervisor_suspend (xenhost_t *xh,unsigned long start_info_mfn) {struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
@@ -405,38 +471,53 @@ HYPERVISOR_suspend(unsigned long start_info_mfn)* hypercall calling convention this is the third hypercall * argument, which is start_info_mfn here. */ -return _hypercall3 (int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn); +return _hypercall3 (xh, int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn); } +#define HYPERVISOR_suspend (start_info_mfn) \ + hypervisor_suspend(xh_default, start_info_mfn)static inline unsigned long __must_check -HYPERVISOR_hvm_op (int op,void *arg) +hypervisor_hvm_op (xenhost_t *xh,int op,void *arg) { - return _hypercall2(unsigned long, hvm_op, op, arg); + return _hypercall2(xh, unsigned long, hvm_op, op, arg); } +#define HYPERVISOR_hvm_op (op, arg) \ + hypervisor_hvm_op(xh_default, op, arg) +static inline int -HYPERVISOR_tmem_op ( +hypervisor_tmem_op ( +xenhost_t *xh,struct tmem_op *op) { -return _hypercall1 (int, tmem_op, op); +return _hypercall1 (xh, int, tmem_op, op); } +#define HYPERVISOR_tmem_op (op) \ + hypervisor_tmem_op(xh_default, op) +static inline int -HYPERVISOR_xenpmu_op (unsigned int op,void *arg) +hypervisor_xenpmu_op (xenhost_t *xh,unsigned int op,void *arg) { -return _hypercall2 (int, xenpmu_op, op, arg); +return _hypercall2 (xh, int, xenpmu_op, op, arg); } +#define HYPERVISOR_xenpmu_op (op, arg) \ + hypervisor_xenpmu_op(xh_default, op, arg) +static inline int -HYPERVISOR_dm_op ( +hypervisor_dm_op ( +xenhost_t *xh,domid_t dom,unsigned int nr_bufs,struct xen_dm_op_buf *bufs) {int ret;stac (); - ret =_hypercall3 (int, dm_op, dom, nr_bufs, bufs); + ret =_hypercall3 (xh, int, dm_op, dom, nr_bufs, bufs);clac ();return ret; } +#define HYPERVISOR_dm_op (dom, nr_bufs, bufs) \ + hypervisor_dm_op(xh_default, dom, nr_bufs, bufs)static inline void MULTI_fpu_taskswitch (struct multicall_entry *mcl,int set)
arch/x86/xen/enlighten.c +0 -3
@@ -20,9 +20,6 @@#include "smp.h" #include "pmu.h" -struct hypercall_entry *hypercall_page; -EXPORT_SYMBOL_GPL (hypercall_page); -/* * Pointer to the xen_vcpu_info structure or * &HYPERVISOR_shared_info->vcpu_info[cpu]. See xen_hvm_init_shared_info
arch/x86/xen/enlighten_hvm.c +16 -7
@@ -85,8 +85,20 @@ static void __init xen_hvm_init_mem_mapping(void)extern uint32_t xen_pv_cpuid_base (xenhost_t *xh); +void xen_hvm_setup_hypercall_page (xenhost_t *xh) +{ +u32 msr; +u64 pfn; + + msr =cpuid_ebx (xenhost_cpuid_base (xh) +2 ); + pfn =__pa (xen_hypercall_page); +wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + xh->hypercall_page = xen_hypercall_page; +} +xenhost_ops_t xh_hvm_ops = { .cpuid_base = xen_pv_cpuid_base, + .setup_hypercall_page = xen_hvm_setup_hypercall_page, };xenhost_ops_t xh_hvm_nested_ops = {
@@ -96,6 +108,7 @@ static void __init init_hvm_pv_info(void) {int major, minor;uint32_t eax, ebx, ecx, edx, base; +xenhost_t **xh; base =xenhost_cpuid_base (xh_default); eax =cpuid_eax (base +1 );
@@ -110,14 +123,10 @@ static void __init init_hvm_pv_info(void)if (xen_pvh_domain ()) pv_info.name ="Xen PVH" ;else { -u64 pfn; -uint32_t msr; - pv_info.name ="Xen HVM" ; - msr =cpuid_ebx (base +2 ); - pfn =__pa (xen_hypercall_page); -wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); - hypercall_page = xen_hypercall_page; + +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); }xen_setup_features ();
arch/x86/xen/enlighten_pv.c +12 -1
@@ -1200,12 +1200,20 @@ uint32_t xen_pv_nested_cpuid_base(xenhost_t *xh) 2 /* nested specific leaf? */); } +static void xen_pv_setup_hypercall_page (xenhost_t *xh) +{ + xh->hypercall_page = xen_hypercall_page; +} +xenhost_ops_t xh_pv_ops = { .cpuid_base = xen_pv_cpuid_base, + + .setup_hypercall_page = xen_pv_setup_hypercall_page, };xenhost_ops_t xh_pv_nested_ops = { .cpuid_base = xen_pv_nested_cpuid_base, + .setup_hypercall_page =NULL , };/* First C function to be called on Xen boot */
@@ -1213,11 +1221,11 @@ asmlinkage __visible void __init xen_start_kernel(void) {struct physdev_set_iopl set_iopl;unsigned long initrd_start =0 ; +xenhost_t **xh;int rc;if (!xen_start_info)return ; - hypercall_page = xen_hypercall_page;xenhost_register (xenhost_r1, &xh_pv_ops);
@@ -1228,6 +1236,9 @@ asmlinkage __visible void __init xen_start_kernel(void)if (xen_driver_domain () &&xen_nested ())xenhost_register (xenhost_r2, &xh_pv_nested_ops); +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); + xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags;
arch/x86/xen/enlighten_pvh.c +3 -6
@@ -26,8 +26,7 @@ extern xenhost_ops_t xh_hvm_ops, xh_hvm_nested_ops;void __init xen_pvh_init (void ) { -u32 msr; -u64 pfn; +xenhost_t **xh;/* * Note: we have already called xen_cpuid_base() in
@@ -45,10 +44,8 @@ void __init xen_pvh_init(void) xen_pvh =1 ; xen_start_flags = pvh_start_info.flags; - msr =cpuid_ebx (xen_cpuid_base () +2 ); - pfn =__pa (xen_hypercall_page); -wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); - hypercall_page = xen_hypercall_page; +for_each_xenhost (xh) +xenhost_setup_hypercall_page (*xh); }void __init mem_map_via_hcall (struct boot_params *boot_params_p)
arch/x86/xen/xen-head.S +3 -0
@@ -70,6 +70,9 @@ ENTRY(xen_hypercall_page) #include <asm/xen-hypercalls.h> #undef HYPERCALL END(xen_hypercall_page) +/* + * Add xen_hypercall_page2 for remote xenhost? + */ .popsection ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "linux")
drivers/xen/fallback.c +4 -4
@@ -5,14 +5,14 @@#include <asm/hypervisor.h> #include <asm/xen/hypercall.h> -int xen_event_channel_op_compat (int cmd,void *arg) +int xen_event_channel_op_compat (xenhost_t *xh,int cmd,void *arg) {struct evtchn_op op;int rc; op.cmd = cmd;memcpy (&op.u, arg,sizeof (op.u)); - rc =_hypercall1 (int, event_channel_op_compat, &op); + rc =_hypercall1 (xh, int, event_channel_op_compat, &op);switch (cmd) {case EVTCHNOP_close:
@@ -44,14 +44,14 @@ int xen_event_channel_op_compat(int cmd, void *arg) }EXPORT_SYMBOL_GPL (xen_event_channel_op_compat); -int xen_physdev_op_compat (int cmd,void *arg) +int xen_physdev_op_compat (xenhost_t *xh,int cmd,void *arg) {struct physdev_op op;int rc; op.cmd = cmd;memcpy (&op.u, arg,sizeof (op.u)); - rc =_hypercall1 (int, physdev_op_compat, &op); + rc =_hypercall1 (xh, int, physdev_op_compat, &op);switch (cmd) {case PHYSDEVOP_IRQ_UNMASK_NOTIFY :
include/xen/xenhost.h +23 -0
@@ -70,6 +70,8 @@ typedef struct {enum xenhost_type type;struct xenhost_ops *ops; + +struct hypercall_entry *hypercall_page; } xenhost_t; typedef struct xenhost_ops {
@@ -83,6 +85,22 @@ typedef struct xenhost_ops {* Separate cpuid-leafs? */ uint32_t (*cpuid_base)(xenhost_t *xenhost); + +/* +* Hypercall page is setup as the first thing once the PV/PVH/PVHVM +* code detects that it is selected. The first use is in +* xen_setup_features(). +* +* PV/PVH/PVHVM set this up in different ways: hypervisor takes +* care of this for PV, PVH and PVHVM use xen_cpuid. +* +* xenhost_r0: point hypercall_page to external hypercall_page. +* xenhost_r1: what we do now. +* xenhost_r2: hypercall interface that bypasses L1-Xen to go from +* L1-guest to L0-Xen. The interface would allow L0-Xen to be able +* to decide which particular L1-guest was the caller. +*/ +void (*setup_hypercall_page)(xenhost_t *xenhost); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -113,4 +131,9 @@ static inline uint32_t xenhost_cpuid_base(xenhost_t *xh) return xen_cpuid_base(); } +static inline void xenhost_setup_hypercall_page (xenhost_t *xh) +{ + (xh->ops->setup_hypercall_page)(xh); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [RFC PATCH 04/16] x86/xen: hypercall support for xenhost_t
Quoted 8 lines · Ankur Arora
Allow for different hypercall implementations for different xenhost types. Nested xenhost, which has two underlying xenhosts, can use both simultaneously.
The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x A new macro (hypervisor_*) takes
xenhost_t* as a parameter and does the right thing.
Quoted 5 lines
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.Signed-off-by Ankur Arora <[email protected]>
Again, what is the hypervisor nesting and/or guest layout here?
I can't think of any case where a single piece of software can legitimately have two hypercall pages, because if it has one working one, it is by definition a guest, and therefore not privileged enough to use the outer one.
~Andrew
Re: [Xen-devel] [RFC PATCH 04/16] x86/xen: hypercall support for xenhost_t
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Ankur Arora
Allow for different hypercall implementations for different xenhost types. Nested xenhost, which has two underlying xenhosts, can use both simultaneously.
The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x A new macro (hypervisor_*) takes
xenhost_t* as a parameter and does the right thing.
Quoted 7 lines
Quoted 5 lines
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.Signed-off-by Ankur Arora <[email protected]>Again, what is the hypervisor nesting and/or guest layout here?
Two hypervisors, L0 and L1, and the guest is a child of the L1 hypervisor but could have PV devices attached to both L0 and L1 hypervisors.
Quoted 5 lines
I can't think of any case where a single piece of software can legitimately have two hypercall pages, because if it has one working one, it is by definition a guest, and therefore not privileged enough to use the outer one.
Depending on which hypercall page is used, the hypercall would (eventually) land in the corresponding hypervisor.
Juergen elsewhere pointed out proxying hypercalls is a better approach, so I'm not really considering this any more but, given this layout, and assuming that the hypercall pages could be encoded differently would it still not work?
Ankur
Quoted 8 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [Xen-devel] [RFC PATCH 04/16] x86/xen: hypercall support for xenhost_t
Quoted 26 lines · Ankur Arora
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Ankur Arora
Allow for different hypercall implementations for different xenhost types. Nested xenhost, which has two underlying xenhosts, can use both simultaneously.
The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x A new macro (hypervisor_*) takes
xenhost_t* as a parameter and does the right thing.Quoted 7 lines
Quoted 5 lines
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.Signed-off-by Ankur Arora <[email protected]>Again, what is the hypervisor nesting and/or guest layout here?
Two hypervisors, L0 and L1, and the guest is a child of the L1 hypervisor but could have PV devices attached to both L0 and L1 hypervisors.
Quoted 5 lines
I can't think of any case where a single piece of software can legitimately have two hypercall pages, because if it has one working one, it is by definition a guest, and therefore not privileged enough to use the outer one.
Quoted 7 lines
Depending on which hypercall page is used, the hypercall would (eventually) land in the corresponding hypervisor.
Juergen elsewhere pointed out proxying hypercalls is a better approach, so I'm not really considering this any more but, given this layout, and assuming that the hypercall pages could be encoded differently would it still not work?
Hypercalls might work, but it is a bad idea and a violation of layering to let a L1 guest issue hypercalls to L0 hypervisor, as those hypercalls could influence other L1 guests and even the L1 hypervisor.
Hmm, thinking more about it, I even doubt those hypercalls could work in all cases: when issued from a L1 PV guest the hypercalls would seem to be issued from user mode for the L0 hypervisor, and this is not allowed.
Juergen
Re: [Xen-devel] [RFC PATCH 04/16] x86/xen: hypercall support for xenhost_t
Quoted 40 lines · Juergen Gross
Quoted 31 lines · Ankur Arora
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Ankur Arora
Allow for different hypercall implementations for different xenhost types.
Nested xenhost, which has two underlying xenhosts, can use both simultaneously.The hypercall macros (HYPERVISOR_*) implicitly use the default xenhost.x
A new macro (hypervisor_*) takesxenhost_t* as a parameter and does the
right thing.Quoted 8 lines
Quoted 6 lines
TODO:
- Multicalls for now assume the default xenhost
- xen_hypercall_* symbols are only generated for the default xenhost.Signed-off-by Ankur Arora <[email protected]>Again, what is the hypervisor nesting and/or guest layout here?
Two hypervisors, L0 and L1, and the guest is a child of the L1 hypervisor but could have PV devices attached to both L0 and L1 hypervisors.
Quoted 6 lines
I can't think of any case where a single piece of software can legitimately have two hypercall pages, because if it has one working one, it is by definition a guest, and therefore not privileged enough to
use the outer one.Quoted 7 lines
Depending on which hypercall page is used, the hypercall would (eventually) land in the corresponding hypervisor.
Juergen elsewhere pointed out proxying hypercalls is a better approach, so I'm not really considering this any more but, given this layout, and assuming that the hypercall pages could be encoded differently would it still not work?
Quoted 7 lines
Hypercalls might work, but it is a bad idea and a violation of layering to let a L1 guest issue hypercalls to L0 hypervisor, as those hypercalls could influence other L1 guests and even the L1 hypervisor.
Hmm, thinking more about it, I even doubt those hypercalls could work in all cases: when issued from a L1 PV guest the hypercalls would seem to be issued from user mode for the L0 hypervisor, and this is not allowed.
That is exactly the point I was trying to make.
If L2 is an HVM guest, then both its hypercall pages will be using VMCALL/VMMCALL which will end up making hypercalls to L1, rather than having one go to L0.
If L2 is a PV guest, then one hypercall page will be SYSCALL/INT 82 which will go to L1, and one will be VMCALL/VMMCALL which goes to L0, but L0 will see it from ring1/ring3 and reject the hypercall.
However you nest the system, every guest only has a single occurrence of "supervisor software", so only has a single context that will be tolerated to make hypercalls by the next hypervisor up.
~Andrew
RFC PATCH 5/16 x86/xen: add feature support in xenhost_t
In reply to Ankur AroraWith nested xenhosts, both the xenhosts could have different supported xen_features. Add support for probing both.
In addition, validate that features are compatible across xenhosts.
For runtime feature checking, the code uses xen_feature() with the default xenhost. This should be good enough because we do feature validation early which guarantees that the features of interest are compatible. Features not of interest, are related to MMU, clock, pirq, etc where the interface to L0-Xen should not matter.
--- arch/x86/xen/enlighten_hvm.c | 15 +++++++++++---- arch/x86/xen/enlighten_pv.c | 14 ++++++++++---- drivers/xen/features.c | 33 +++++++++++++++++++++++++++------ include/xen/features.h | 17 ++++++++++++++--- include/xen/xenhost.h | 10 ++++++++++ 5 files changed, 72 insertions(+), 17 deletions(-)
arch/x86/xen/enlighten_hvm.c +11 -4
@@ -119,17 +119,24 @@ static void __init init_hvm_pv_info(void) xen_domain_type =XEN_HVM_DOMAIN ; -/* PVH set up hypercall page in xen_prepare_pvh(). */ if (xen_pvh_domain ()) pv_info.name ="Xen PVH" ; -else { +else pv_info.name ="Xen HVM" ; -for_each_xenhost (xh) +for_each_xenhost (xh) { +/* PVH set up hypercall page in xen_prepare_pvh(). */ +if (!xen_pvh_domain ())xenhost_setup_hypercall_page (*xh); +xen_setup_features (*xh); } -xen_setup_features (); +/* +* Check if features are compatible across L1-Xen and L0-Xen; +* If not, get rid of xenhost_r2. +*/ +if (xen_validate_features () == false) +__xenhost_unregister (xenhost_r2);cpuid (base +4 , &eax, &ebx, &ecx, &edx);if (eax &XEN_HVM_CPUID_VCPU_ID_PRESENT )
arch/x86/xen/enlighten_pv.c +10 -4
@@ -1236,13 +1236,19 @@ asmlinkage __visible void __init xen_start_kernel(void)if (xen_driver_domain () &&xen_nested ())xenhost_register (xenhost_r2, &xh_pv_nested_ops); -for_each_xenhost (xh) -xenhost_setup_hypercall_page (*xh); - xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags; -xen_setup_features (); +for_each_xenhost (xh) { +xenhost_setup_hypercall_page (*xh); +xen_setup_features (*xh); + } +/* +* Check if features are compatible across L1-Xen and L0-Xen; +* If not, get rid of xenhost_r2. +*/ +if (xen_validate_features () == false) +__xenhost_unregister (xenhost_r2);/* Install Xen paravirt ops */ pv_info = xen_info;
drivers/xen/features.c +27 -6
@@ -15,19 +15,40 @@#include <xen/interface/version.h> #include <xen/features.h> -u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ; -EXPORT_SYMBOL_GPL (xen_features); - -void xen_setup_features (void ) +void xen_setup_features (xenhost_t *xh) {struct xen_feature_info fi;int i, j;for (i =0 ; i <XENFEAT_NR_SUBMAPS ; i++) { fi.submap_idx = i; -if (HYPERVISOR_xen_version (XENVER_get_features, &fi) <0 ) +if (hypervisor_xen_version (xh, XENVER_get_features, &fi) <0 )break ;for (j =0 ; j <32 ; j++) - xen_features[i *32 + j] = !!(fi.submap &1 <<j); + xh->features[i *32 + j] = !!(fi.submap &1 <<j); } } + +bool xen_validate_features (void ) +{ +int fail =0 ; + +if (xh_default && xh_remote) { +/* +* Check xh_default->features and xh_remote->features for +* compatibility. Relevant features should be compatible +* or we are asking for trouble. +*/ + fail +=__xen_feature (xh_default, XENFEAT_auto_translated_physmap) != +__xen_feature (xh_remote, XENFEAT_auto_translated_physmap); + +/* We would like callbacks via hvm_callback_vector. */ + fail +=__xen_feature (xh_default, XENFEAT_hvm_callback_vector) ==0 ; + fail +=__xen_feature (xh_remote, XENFEAT_hvm_callback_vector) ==0 ; + +if (fail) +return false; + } + +return fail ? false : true; +}
include/xen/features.h +14 -3
@@ -11,14 +11,25 @@#define __XEN_FEATURES_H__#include <xen/interface/features.h> +#include <xen/xenhost.h> -void xen_setup_features (void ); +void xen_setup_features (xenhost_t *xh); -extern u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]; +bool xen_validate_features (void ); +static inline int __xen_feature (xenhost_t *xh,int flag) +{ +return xh->features[flag]; +} + +/* +* We've validated the features that need to be common for both xenhost_r1 and +* xenhost_r2 (XENFEAT_hvm_callback_vector, XENFEAT_auto_translated_physmap.) +* Most of the other features should be only needed for the default xenhost. +*/ static inline int xen_feature (int flag) { -return xen_features[flag]; +return __xen_feature (xh_default, flag); }#endif /* __ASM_XEN_FEATURES_H__ */
include/xen/xenhost.h +10 -0
@@ -4,6 +4,7 @@#include <xen/interface/features.h> #include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> +/* * Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/PVH * abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to
@@ -72,6 +73,15 @@ typedef struct {struct xenhost_ops *ops;struct hypercall_entry *hypercall_page; + +/* +* Not clear if we need to draw features from two different +* hypervisors. There is one feature that seems might be necessary: +* XENFEAT_hvm_callback_vector. +* Ensuring support in both L1-Xen and L0-Xen means that L0-Xen can +* bounce callbacks via L1-Xen. +*/ +u8 features[XENFEAT_NR_SUBMAPS *32 ]; } xenhost_t; typedef struct xenhost_ops {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 5/16 x86/xen: add feature support in xenhost_t
In reply to Ankur AroraWith nested xenhosts, both the xenhosts could have different supported xen_features. Add support for probing both.
In addition, validate that features are compatible across xenhosts.
For runtime feature checking, the code uses xen_feature() with the default xenhost. This should be good enough because we do feature validation early which guarantees that the features of interest are compatible. Features not of interest, are related to MMU, clock, pirq, etc where the interface to L0-Xen should not matter.
--- arch/x86/xen/enlighten_hvm.c | 15 +++++++++++---- arch/x86/xen/enlighten_pv.c | 14 ++++++++++---- drivers/xen/features.c | 33 +++++++++++++++++++++++++++------ include/xen/features.h | 17 ++++++++++++++--- include/xen/xenhost.h | 10 ++++++++++ 5 files changed, 72 insertions(+), 17 deletions(-)
arch/x86/xen/enlighten_hvm.c +11 -4
@@ -119,17 +119,24 @@ static void __init init_hvm_pv_info(void) xen_domain_type =XEN_HVM_DOMAIN ; -/* PVH set up hypercall page in xen_prepare_pvh(). */ if (xen_pvh_domain ()) pv_info.name ="Xen PVH" ; -else { +else pv_info.name ="Xen HVM" ; -for_each_xenhost (xh) +for_each_xenhost (xh) { +/* PVH set up hypercall page in xen_prepare_pvh(). */ +if (!xen_pvh_domain ())xenhost_setup_hypercall_page (*xh); +xen_setup_features (*xh); } -xen_setup_features (); +/* +* Check if features are compatible across L1-Xen and L0-Xen; +* If not, get rid of xenhost_r2. +*/ +if (xen_validate_features () == false) +__xenhost_unregister (xenhost_r2);cpuid (base +4 , &eax, &ebx, &ecx, &edx);if (eax &XEN_HVM_CPUID_VCPU_ID_PRESENT )
arch/x86/xen/enlighten_pv.c +10 -4
@@ -1236,13 +1236,19 @@ asmlinkage __visible void __init xen_start_kernel(void)if (xen_driver_domain () &&xen_nested ())xenhost_register (xenhost_r2, &xh_pv_nested_ops); -for_each_xenhost (xh) -xenhost_setup_hypercall_page (*xh); - xen_domain_type =XEN_PV_DOMAIN ; xen_start_flags = xen_start_info->flags; -xen_setup_features (); +for_each_xenhost (xh) { +xenhost_setup_hypercall_page (*xh); +xen_setup_features (*xh); + } +/* +* Check if features are compatible across L1-Xen and L0-Xen; +* If not, get rid of xenhost_r2. +*/ +if (xen_validate_features () == false) +__xenhost_unregister (xenhost_r2);/* Install Xen paravirt ops */ pv_info = xen_info;
drivers/xen/features.c +27 -6
@@ -15,19 +15,40 @@#include <xen/interface/version.h> #include <xen/features.h> -u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ; -EXPORT_SYMBOL_GPL (xen_features); - -void xen_setup_features (void ) +void xen_setup_features (xenhost_t *xh) {struct xen_feature_info fi;int i, j;for (i =0 ; i <XENFEAT_NR_SUBMAPS ; i++) { fi.submap_idx = i; -if (HYPERVISOR_xen_version (XENVER_get_features, &fi) <0 ) +if (hypervisor_xen_version (xh, XENVER_get_features, &fi) <0 )break ;for (j =0 ; j <32 ; j++) - xen_features[i *32 + j] = !!(fi.submap &1 <<j); + xh->features[i *32 + j] = !!(fi.submap &1 <<j); } } + +bool xen_validate_features (void ) +{ +int fail =0 ; + +if (xh_default && xh_remote) { +/* +* Check xh_default->features and xh_remote->features for +* compatibility. Relevant features should be compatible +* or we are asking for trouble. +*/ + fail +=__xen_feature (xh_default, XENFEAT_auto_translated_physmap) != +__xen_feature (xh_remote, XENFEAT_auto_translated_physmap); + +/* We would like callbacks via hvm_callback_vector. */ + fail +=__xen_feature (xh_default, XENFEAT_hvm_callback_vector) ==0 ; + fail +=__xen_feature (xh_remote, XENFEAT_hvm_callback_vector) ==0 ; + +if (fail) +return false; + } + +return fail ? false : true; +}
include/xen/features.h +14 -3
@@ -11,14 +11,25 @@#define __XEN_FEATURES_H__#include <xen/interface/features.h> +#include <xen/xenhost.h> -void xen_setup_features (void ); +void xen_setup_features (xenhost_t *xh); -extern u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]; +bool xen_validate_features (void ); +static inline int __xen_feature (xenhost_t *xh,int flag) +{ +return xh->features[flag]; +} + +/* +* We've validated the features that need to be common for both xenhost_r1 and +* xenhost_r2 (XENFEAT_hvm_callback_vector, XENFEAT_auto_translated_physmap.) +* Most of the other features should be only needed for the default xenhost. +*/ static inline int xen_feature (int flag) { -return xen_features[flag]; +return __xen_feature (xh_default, flag); }#endif /* __ASM_XEN_FEATURES_H__ */
include/xen/xenhost.h +10 -0
@@ -4,6 +4,7 @@#include <xen/interface/features.h> #include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> +/* * Xenhost abstracts out the Xen interface. It co-exists with the PV/HVM/PVH * abstractions (x86_init, hypervisor_x86, pv_ops etc) and is meant to
@@ -72,6 +73,15 @@ typedef struct {struct xenhost_ops *ops;struct hypercall_entry *hypercall_page; + +/* +* Not clear if we need to draw features from two different +* hypervisors. There is one feature that seems might be necessary: +* XENFEAT_hvm_callback_vector. +* Ensuring support in both L1-Xen and L0-Xen means that L0-Xen can +* bounce callbacks via L1-Xen. +*/ +u8 features[XENFEAT_NR_SUBMAPS *32 ]; } xenhost_t; typedef struct xenhost_ops {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 6/16 x86/xen: add shared_info support to xenhost_t
In reply to Ankur AroraHYPERVISOR_shared_info is used for irq/evtchn communication between the guest and the host. Abstract out the setup/reset in xenhost_t such that nested configurations can use both xenhosts simultaneously.
In addition to irq/evtchn communication, shared_info is also used for pvclock and p2m related state. For both of those, remote xenhost is not of interest so we only use the default xenhost.
--- arch/x86/include/asm/xen/hypervisor.h | 1 - arch/x86/xen/enlighten.c | 10 ++----- arch/x86/xen/enlighten_hvm.c | 38 +++++++++++++++++--------- arch/x86/xen/enlighten_pv.c | 28 ++++++++++++++++--- arch/x86/xen/p2m.c | 24 ++++++++--------- arch/x86/xen/suspend_hvm.c | 6 ++++- arch/x86/xen/suspend_pv.c | 14 +++++----- arch/x86/xen/time.c | 4 +-- arch/x86/xen/xen-ops.h | 2 -- arch/x86/xen/xenhost.c | 13 ++++++++- drivers/xen/events/events_2l.c | 16 +++++------ include/xen/xenhost.h | 39 +++++++++++++++++++++++++++ 12 files changed, 138 insertions(+), 57 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +0 -1
@@ -33,7 +33,6 @@#ifndef _ASM_X86_XEN_HYPERVISOR_H#define _ASM_X86_XEN_HYPERVISOR_H -extern struct shared_info *HYPERVISOR_shared_info;extern struct start_info *xen_start_info;#include <asm/processor.h>
arch/x86/xen/enlighten.c +2 -8
@@ -72,12 +72,6 @@ EXPORT_SYMBOL_GPL(xen_have_vector_callback); uint32_t xen_start_flags __attribute__((section(".data"))) = 0;EXPORT_SYMBOL (xen_start_flags); -/* -* Point at some empty memory to start with. We map the real shared_info -* page as soon as fixmap is up and running. -*/ -struct shared_info *HYPERVISOR_shared_info = &xen_dummy_shared_info; -/* * Flag to determine whether vcpu info placement is available on all * VCPUs. We assume it is to start with, and then set it to zero on
@@ -187,7 +181,7 @@ void xen_vcpu_info_reset(int cpu) {if (xen_vcpu_nr (cpu) <MAX_VIRT_CPUS ) {per_cpu (xen_vcpu, cpu) = - &HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (cpu)]; + &xh_default->HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (cpu)]; }else {/* Set to NULL so that if somebody accesses it we get an OOPS */ per_cpu (xen_vcpu, cpu) =NULL ;
@@ -200,7 +194,7 @@ int xen_vcpu_setup(int cpu)int err;struct vcpu_info *vcpup; -BUG_ON (HYPERVISOR_shared_info == &xen_dummy_shared_info); +BUG_ON (xh_default->HYPERVISOR_shared_info == &xen_dummy_shared_info);/* * This path is called on PVHVM at bootup (xen_hvm_smp_prepare_boot_cpu)
arch/x86/xen/enlighten_hvm.c +26 -12
@@ -26,21 +26,25 @@#include "mmu.h" #include "smp.h" -static unsigned long shared_info_pfn; - -void xen_hvm_init_shared_info (void ) +static void xen_hvm_init_shared_info (xenhost_t *xh) {struct xen_add_to_physmap xatp; xatp.domid =DOMID_SELF ; xatp.idx =0 ; xatp.space = XENMAPSPACE_shared_info; - xatp.gpfn = shared_info_pfn; -if (HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp)) + xatp.gpfn = xh->shared_info_pfn; +if (hypervisor_memory_op (xh, XENMEM_add_to_physmap, &xatp))BUG (); } -static void __init reserve_shared_info (void ) +static void xen_hvm_reset_shared_info (xenhost_t *xh) +{ +early_memunmap (xh->HYPERVISOR_shared_info,PAGE_SIZE ); + xh->HYPERVISOR_shared_info =__va (PFN_PHYS (xh->shared_info_pfn)); +} + +static void __init reserve_shared_info (xenhost_t *xh) {u64 pa;
@@ -58,16 +62,18 @@ static void __init reserve_shared_info(void) pa += PAGE_SIZE) ; - shared_info_pfn =PHYS_PFN (pa); + xh->shared_info_pfn =PHYS_PFN (pa);memblock_reserve (pa,PAGE_SIZE ); - HYPERVISOR_shared_info =early_memremap (pa,PAGE_SIZE ); + xh->HYPERVISOR_shared_info =early_memremap (pa,PAGE_SIZE ); }static void __init xen_hvm_init_mem_mapping (void ) { -early_memunmap (HYPERVISOR_shared_info,PAGE_SIZE ); - HYPERVISOR_shared_info =__va (PFN_PHYS (shared_info_pfn)); +xenhost_t **xh; + +for_each_xenhost (xh) +xenhost_reset_shared_info (*xh);/* * The virtual address of the shared_info page has changed, so
@@ -79,6 +85,7 @@ static void __init xen_hvm_init_mem_mapping(void)* * It is, in any case, bad to have a stale vcpu_info pointer * so reset it now. +* For now, this uses xh_default implictly. */ xen_vcpu_info_reset (0 ); }
@@ -99,6 +106,8 @@ void xen_hvm_setup_hypercall_page(xenhost_t *xh)xenhost_ops_t xh_hvm_ops = { .cpuid_base = xen_pv_cpuid_base, .setup_hypercall_page = xen_hvm_setup_hypercall_page, + .setup_shared_info = xen_hvm_init_shared_info, + .reset_shared_info = xen_hvm_reset_shared_info, };xenhost_ops_t xh_hvm_nested_ops = {
@@ -204,6 +213,8 @@ static int xen_cpu_dead_hvm(unsigned int cpu)static void __init xen_hvm_guest_init (void ) { +xenhost_t **xh; +if (xen_pv_domain ())return ;/*
@@ -215,13 +226,16 @@ static void __init xen_hvm_guest_init(void)init_hvm_pv_info (); -reserve_shared_info (); -xen_hvm_init_shared_info (); +for_each_xenhost (xh) { +reserve_shared_info (*xh); +xenhost_setup_shared_info (*xh); + }/* * xen_vcpu is a pointer to the vcpu_info struct in the shared_info * page, we use it in the event channel upcall and in some pvclock * related functions. +* For now, this uses xh_default implictly. */ xen_vcpu_info_reset (0 );
arch/x86/xen/enlighten_pv.c +24 -4
@@ -122,12 +122,15 @@ static void __init xen_banner(void)static void __init xen_pv_init_platform (void ) { +xenhost_t **xh; +populate_extra_pte (fix_to_virt (FIX_PARAVIRT_BOOTMAP )); -set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); - HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);/* xen clock uses per-cpu vcpu_info, need to init it for boot cpu */ +/* For now this uses xh_default implicitly. */ xen_vcpu_info_reset (0 );/* pvclock is in shared info area */
@@ -1109,10 +1112,10 @@ static unsigned char xen_get_nmi_reason(void)/* Construct a value which looks like it came from port 0x61. */ if (test_bit (_XEN_NMIREASON_io_error, - &HYPERVISOR_shared_info->arch.nmi_reason)) + &xh_default->HYPERVISOR_shared_info->arch.nmi_reason)) reason |=NMI_REASON_IOCHK ;if (test_bit (_XEN_NMIREASON_pci_serr, - &HYPERVISOR_shared_info->arch.nmi_reason)) + &xh_default->HYPERVISOR_shared_info->arch.nmi_reason)) reason |=NMI_REASON_SERR ;return reason;
@@ -1205,10 +1208,27 @@ static void xen_pv_setup_hypercall_page(xenhost_t *xh) xh->hypercall_page = xen_hypercall_page; } +static void xen_pv_setup_shared_info (xenhost_t *xh) +{ +set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); + xh->HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +} + +static void xen_pv_reset_shared_info (xenhost_t *xh) +{ + xh->HYPERVISOR_shared_info = &xen_dummy_shared_info; +if (hypervisor_update_va_mapping (xh,fix_to_virt (FIX_PARAVIRT_BOOTMAP ), +__pte_ma (0 ),0 )) +BUG (); +} +xenhost_ops_t xh_pv_ops = { .cpuid_base = xen_pv_cpuid_base, .setup_hypercall_page = xen_pv_setup_hypercall_page, + + .setup_shared_info = xen_pv_setup_shared_info, + .reset_shared_info = xen_pv_reset_shared_info, };xenhost_ops_t xh_pv_nested_ops = {
arch/x86/xen/p2m.c +12 -12
@@ -270,17 +270,17 @@ void __ref xen_build_mfn_list_list(void)void xen_setup_mfn_list_list (void ) { -BUG_ON (HYPERVISOR_shared_info == &xen_dummy_shared_info); +BUG_ON (xh_default->HYPERVISOR_shared_info == &xen_dummy_shared_info);if (xen_start_info->flags &SIF_VIRT_P2M_4TOOLS ) - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL ; + xh_default->HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL ;else - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = + xh_default->HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =virt_to_mfn (p2m_top_mfn); - HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; - HYPERVISOR_shared_info->arch.p2m_generation =0 ; - HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long )xen_p2m_addr; - HYPERVISOR_shared_info->arch.p2m_cr3 = + xh_default->HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation =0 ; + xh_default->HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long )xen_p2m_addr; + xh_default->HYPERVISOR_shared_info->arch.p2m_cr3 =xen_pfn_to_cr3 (virt_to_mfn (swapper_pg_dir)); }
@@ -496,12 +496,12 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg) ptechk =lookup_address (vaddr, &level);if (ptechk == pte_pg) { - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;wmb ();/* Tools are synchronizing via p2m_generation. */ set_pmd (pmdp,__pmd (__pa (pte_newpg[i]) | _KERNPG_TABLE));wmb ();/* Tools are synchronizing via p2m_generation. */ - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++; pte_newpg[i] =NULL ; }
@@ -597,12 +597,12 @@ int xen_alloc_p2m_entry(unsigned long pfn)spin_lock_irqsave (&p2m_update_lock, flags);if (pte_pfn (*ptep) == p2m_pfn) { - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;wmb ();/* Tools are synchronizing via p2m_generation. */ set_pte (ptep,pfn_pte (PFN_DOWN (__pa (p2m)),PAGE_KERNEL ));wmb ();/* Tools are synchronizing via p2m_generation. */ - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;if (mid_mfn) mid_mfn[p2m_mid_index (pfn)] =virt_to_mfn (p2m); p2m =NULL ;
@@ -617,7 +617,7 @@ int xen_alloc_p2m_entry(unsigned long pfn)/* Expanded the p2m? */ if (pfn > xen_p2m_last_pfn) { xen_p2m_last_pfn = pfn; - HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; + xh_default->HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; }return 0 ;
arch/x86/xen/suspend_hvm.c +5 -1
@@ -2,6 +2,7 @@#include <linux/types.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/interface/features.h>
@@ -10,7 +11,10 @@void xen_hvm_post_suspend (int suspend_cancelled) {if (!suspend_cancelled) { -xen_hvm_init_shared_info (); +xenhost_t **xh; + +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);xen_vcpu_restore (); }xen_callback_vector ();
arch/x86/xen/suspend_pv.c +8 -6
@@ -10,6 +10,8 @@void xen_pv_pre_suspend (void ) { +xenhost_t **xh; +xen_mm_pin_all (); xen_start_info->store_mfn =mfn_to_pfn (xen_start_info->store_mfn);
@@ -18,17 +20,17 @@ void xen_pv_pre_suspend(void)BUG_ON (!irqs_disabled ()); - HYPERVISOR_shared_info = &xen_dummy_shared_info; -if (HYPERVISOR_update_va_mapping (fix_to_virt (FIX_PARAVIRT_BOOTMAP ), -__pte_ma (0 ),0 )) -BUG (); +for_each_xenhost (xh) +xenhost_reset_shared_info (*xh); }void xen_pv_post_suspend (int suspend_cancelled) { +xenhost_t **xh; +xen_build_mfn_list_list (); -set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); - HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);xen_setup_mfn_list_list ();if (suspend_cancelled) {
arch/x86/xen/time.c +2 -2
@@ -37,7 +37,7 @@ static u64 xen_sched_clock_offset __read_mostly;static unsigned long xen_tsc_khz (void ) {struct pvclock_vcpu_time_info *info = - &HYPERVISOR_shared_info->vcpu_info[0 ].time; + &xh_default->HYPERVISOR_shared_info->vcpu_info[0 ].time;return pvclock_tsc_khz (info); }
@@ -66,7 +66,7 @@ static u64 xen_sched_clock(void)static void xen_read_wallclock (struct timespec64 *ts) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;struct pvclock_wall_clock *wall_clock = &(s->wc);struct pvclock_vcpu_time_info *vcpu_time;
arch/x86/xen/xen-ops.h +0 -2
@@ -28,7 +28,6 @@ DECLARE_PER_CPU(unsigned long, xen_current_cr3);extern struct start_info *xen_start_info;extern struct shared_info xen_dummy_shared_info; -extern struct shared_info *HYPERVISOR_shared_info;void xen_setup_mfn_list_list (void );void xen_build_mfn_list_list (void );
@@ -56,7 +55,6 @@ void xen_enable_syscall(void);void xen_vcpu_restore (void );void xen_callback_vector (void ); -void xen_hvm_init_shared_info (void );void xen_unplug_emulated_devices (void );void __init xen_build_dynamic_phys_to_machine (void );
arch/x86/xen/xenhost.c +12 -1
@@ -2,8 +2,19 @@#include <linux/bug.h> #include <xen/xen.h> #include <xen/xenhost.h> +#include "xen-ops.h" -xenhost_t xenhosts[2 ]; +/* +* Point at some empty memory to start with. On PV, we map the real shared_info +* page as soon as fixmap is up and running and PVH* doesn't use this. +*/ +xenhost_t xenhosts[2 ] = { +/* +* We should probably have two separate dummy shared_info pages. +*/ + [0 ].HYPERVISOR_shared_info = &xen_dummy_shared_info, + [1 ].HYPERVISOR_shared_info = &xen_dummy_shared_info, +};/* * xh_default: interface to the regular hypervisor. xenhost_type is xenhost_r0 * or xenhost_r1.
drivers/xen/events/events_2l.c +8 -8
@@ -55,37 +55,37 @@ static void evtchn_2l_bind_to_cpu(struct irq_info *info, unsigned cpu)static void evtchn_2l_clear_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_clear_bit (port,BM (&s->evtchn_pending[0 ])); }static void evtchn_2l_set_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_set_bit (port,BM (&s->evtchn_pending[0 ])); }static bool evtchn_2l_is_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;return sync_test_bit (port,BM (&s->evtchn_pending[0 ])); }static bool evtchn_2l_test_and_set_mask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;return sync_test_and_set_bit (port,BM (&s->evtchn_mask[0 ])); }static void evtchn_2l_mask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_set_bit (port,BM (&s->evtchn_mask[0 ])); }static void evtchn_2l_unmask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;unsigned int cpu =get_cpu ();int do_hypercall =0 , evtchn_pending =0 ;
@@ -167,7 +167,7 @@ static void evtchn_2l_handle_events(unsigned cpu)int start_word_idx, start_bit_idx;int word_idx, bit_idx;int i; -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;struct vcpu_info *vcpu_info =__this_cpu_read (xen_vcpu);/* Timer interrupt has highest priority. */
@@ -264,7 +264,7 @@ static void evtchn_2l_handle_events(unsigned cpu)irqreturn_t xen_debug_interrupt (int irq,void *dev_id) { -struct shared_info *sh = HYPERVISOR_shared_info; +struct shared_info *sh = xh_default->HYPERVISOR_shared_info;int cpu =smp_processor_id ();xen_ulong_t *cpu_evtchn =per_cpu (cpu_evtchn_mask, cpu);int i;
include/xen/xenhost.h +39 -0
@@ -82,6 +82,14 @@ typedef struct {* bounce callbacks via L1-Xen. */ u8 features[XENFEAT_NR_SUBMAPS *32 ]; + +/* +* shared-info to communicate with this xenhost instance. +*/ +struct { +struct shared_info *HYPERVISOR_shared_info; +unsigned long shared_info_pfn; + }; } xenhost_t; typedef struct xenhost_ops {
@@ -111,6 +119,26 @@ typedef struct xenhost_ops {* to decide which particular L1-guest was the caller. */ void (*setup_hypercall_page)(xenhost_t *xenhost); + +/* +* shared_info: needed before vcpu-info setup. +* +* Needed early because Xen needs it for irq_disable() and such. +* On PV first a dummy_shared_info is setup which eventually gets +* switched to the real one so this needs to support switching +* xenhost. +* +* Reset for PV is done differently from HVM, so provide a +* separate interface. +* +* xenhost_r0: point xenhost->HYPERVISOR_shared_info to a +* newly allocated shared_info page. +* xenhost_r1: similar to what we do now. +* xenhost_r2: new remote hypercall to setup a shared_info page. +* This is where we would now handle L0-Xen irq/evtchns. +*/ +void (*setup_shared_info)(xenhost_t *xenhost); +void (*reset_shared_info)(xenhost_t *xenhost); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -146,4 +174,15 @@ static inline void xenhost_setup_hypercall_page(xenhost_t *xh) (xh->ops->setup_hypercall_page)(xh); } + +static inline void xenhost_setup_shared_info (xenhost_t *xh) +{ + (xh->ops->setup_shared_info)(xh); +} + +static inline void xenhost_reset_shared_info (xenhost_t *xh) +{ + (xh->ops->reset_shared_info)(xh); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 6/16 x86/xen: add shared_info support to xenhost_t
In reply to Ankur AroraHYPERVISOR_shared_info is used for irq/evtchn communication between the guest and the host. Abstract out the setup/reset in xenhost_t such that nested configurations can use both xenhosts simultaneously.
In addition to irq/evtchn communication, shared_info is also used for pvclock and p2m related state. For both of those, remote xenhost is not of interest so we only use the default xenhost.
--- arch/x86/include/asm/xen/hypervisor.h | 1 - arch/x86/xen/enlighten.c | 10 ++----- arch/x86/xen/enlighten_hvm.c | 38 +++++++++++++++++--------- arch/x86/xen/enlighten_pv.c | 28 ++++++++++++++++--- arch/x86/xen/p2m.c | 24 ++++++++--------- arch/x86/xen/suspend_hvm.c | 6 ++++- arch/x86/xen/suspend_pv.c | 14 +++++----- arch/x86/xen/time.c | 4 +-- arch/x86/xen/xen-ops.h | 2 -- arch/x86/xen/xenhost.c | 13 ++++++++- drivers/xen/events/events_2l.c | 16 +++++------ include/xen/xenhost.h | 39 +++++++++++++++++++++++++++ 12 files changed, 138 insertions(+), 57 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +0 -1
@@ -33,7 +33,6 @@#ifndef _ASM_X86_XEN_HYPERVISOR_H#define _ASM_X86_XEN_HYPERVISOR_H -extern struct shared_info *HYPERVISOR_shared_info;extern struct start_info *xen_start_info;#include <asm/processor.h>
arch/x86/xen/enlighten.c +2 -8
@@ -72,12 +72,6 @@ EXPORT_SYMBOL_GPL(xen_have_vector_callback); uint32_t xen_start_flags __attribute__((section(".data"))) = 0;EXPORT_SYMBOL (xen_start_flags); -/* -* Point at some empty memory to start with. We map the real shared_info -* page as soon as fixmap is up and running. -*/ -struct shared_info *HYPERVISOR_shared_info = &xen_dummy_shared_info; -/* * Flag to determine whether vcpu info placement is available on all * VCPUs. We assume it is to start with, and then set it to zero on
@@ -187,7 +181,7 @@ void xen_vcpu_info_reset(int cpu) {if (xen_vcpu_nr (cpu) <MAX_VIRT_CPUS ) {per_cpu (xen_vcpu, cpu) = - &HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (cpu)]; + &xh_default->HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (cpu)]; }else {/* Set to NULL so that if somebody accesses it we get an OOPS */ per_cpu (xen_vcpu, cpu) =NULL ;
@@ -200,7 +194,7 @@ int xen_vcpu_setup(int cpu)int err;struct vcpu_info *vcpup; -BUG_ON (HYPERVISOR_shared_info == &xen_dummy_shared_info); +BUG_ON (xh_default->HYPERVISOR_shared_info == &xen_dummy_shared_info);/* * This path is called on PVHVM at bootup (xen_hvm_smp_prepare_boot_cpu)
arch/x86/xen/enlighten_hvm.c +26 -12
@@ -26,21 +26,25 @@#include "mmu.h" #include "smp.h" -static unsigned long shared_info_pfn; - -void xen_hvm_init_shared_info (void ) +static void xen_hvm_init_shared_info (xenhost_t *xh) {struct xen_add_to_physmap xatp; xatp.domid =DOMID_SELF ; xatp.idx =0 ; xatp.space = XENMAPSPACE_shared_info; - xatp.gpfn = shared_info_pfn; -if (HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp)) + xatp.gpfn = xh->shared_info_pfn; +if (hypervisor_memory_op (xh, XENMEM_add_to_physmap, &xatp))BUG (); } -static void __init reserve_shared_info (void ) +static void xen_hvm_reset_shared_info (xenhost_t *xh) +{ +early_memunmap (xh->HYPERVISOR_shared_info,PAGE_SIZE ); + xh->HYPERVISOR_shared_info =__va (PFN_PHYS (xh->shared_info_pfn)); +} + +static void __init reserve_shared_info (xenhost_t *xh) {u64 pa;
@@ -58,16 +62,18 @@ static void __init reserve_shared_info(void) pa += PAGE_SIZE) ; - shared_info_pfn =PHYS_PFN (pa); + xh->shared_info_pfn =PHYS_PFN (pa);memblock_reserve (pa,PAGE_SIZE ); - HYPERVISOR_shared_info =early_memremap (pa,PAGE_SIZE ); + xh->HYPERVISOR_shared_info =early_memremap (pa,PAGE_SIZE ); }static void __init xen_hvm_init_mem_mapping (void ) { -early_memunmap (HYPERVISOR_shared_info,PAGE_SIZE ); - HYPERVISOR_shared_info =__va (PFN_PHYS (shared_info_pfn)); +xenhost_t **xh; + +for_each_xenhost (xh) +xenhost_reset_shared_info (*xh);/* * The virtual address of the shared_info page has changed, so
@@ -79,6 +85,7 @@ static void __init xen_hvm_init_mem_mapping(void)* * It is, in any case, bad to have a stale vcpu_info pointer * so reset it now. +* For now, this uses xh_default implictly. */ xen_vcpu_info_reset (0 ); }
@@ -99,6 +106,8 @@ void xen_hvm_setup_hypercall_page(xenhost_t *xh)xenhost_ops_t xh_hvm_ops = { .cpuid_base = xen_pv_cpuid_base, .setup_hypercall_page = xen_hvm_setup_hypercall_page, + .setup_shared_info = xen_hvm_init_shared_info, + .reset_shared_info = xen_hvm_reset_shared_info, };xenhost_ops_t xh_hvm_nested_ops = {
@@ -204,6 +213,8 @@ static int xen_cpu_dead_hvm(unsigned int cpu)static void __init xen_hvm_guest_init (void ) { +xenhost_t **xh; +if (xen_pv_domain ())return ;/*
@@ -215,13 +226,16 @@ static void __init xen_hvm_guest_init(void)init_hvm_pv_info (); -reserve_shared_info (); -xen_hvm_init_shared_info (); +for_each_xenhost (xh) { +reserve_shared_info (*xh); +xenhost_setup_shared_info (*xh); + }/* * xen_vcpu is a pointer to the vcpu_info struct in the shared_info * page, we use it in the event channel upcall and in some pvclock * related functions. +* For now, this uses xh_default implictly. */ xen_vcpu_info_reset (0 );
arch/x86/xen/enlighten_pv.c +24 -4
@@ -122,12 +122,15 @@ static void __init xen_banner(void)static void __init xen_pv_init_platform (void ) { +xenhost_t **xh; +populate_extra_pte (fix_to_virt (FIX_PARAVIRT_BOOTMAP )); -set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); - HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);/* xen clock uses per-cpu vcpu_info, need to init it for boot cpu */ +/* For now this uses xh_default implicitly. */ xen_vcpu_info_reset (0 );/* pvclock is in shared info area */
@@ -1109,10 +1112,10 @@ static unsigned char xen_get_nmi_reason(void)/* Construct a value which looks like it came from port 0x61. */ if (test_bit (_XEN_NMIREASON_io_error, - &HYPERVISOR_shared_info->arch.nmi_reason)) + &xh_default->HYPERVISOR_shared_info->arch.nmi_reason)) reason |=NMI_REASON_IOCHK ;if (test_bit (_XEN_NMIREASON_pci_serr, - &HYPERVISOR_shared_info->arch.nmi_reason)) + &xh_default->HYPERVISOR_shared_info->arch.nmi_reason)) reason |=NMI_REASON_SERR ;return reason;
@@ -1205,10 +1208,27 @@ static void xen_pv_setup_hypercall_page(xenhost_t *xh) xh->hypercall_page = xen_hypercall_page; } +static void xen_pv_setup_shared_info (xenhost_t *xh) +{ +set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); + xh->HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +} + +static void xen_pv_reset_shared_info (xenhost_t *xh) +{ + xh->HYPERVISOR_shared_info = &xen_dummy_shared_info; +if (hypervisor_update_va_mapping (xh,fix_to_virt (FIX_PARAVIRT_BOOTMAP ), +__pte_ma (0 ),0 )) +BUG (); +} +xenhost_ops_t xh_pv_ops = { .cpuid_base = xen_pv_cpuid_base, .setup_hypercall_page = xen_pv_setup_hypercall_page, + + .setup_shared_info = xen_pv_setup_shared_info, + .reset_shared_info = xen_pv_reset_shared_info, };xenhost_ops_t xh_pv_nested_ops = {
arch/x86/xen/p2m.c +12 -12
@@ -270,17 +270,17 @@ void __ref xen_build_mfn_list_list(void)void xen_setup_mfn_list_list (void ) { -BUG_ON (HYPERVISOR_shared_info == &xen_dummy_shared_info); +BUG_ON (xh_default->HYPERVISOR_shared_info == &xen_dummy_shared_info);if (xen_start_info->flags &SIF_VIRT_P2M_4TOOLS ) - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL ; + xh_default->HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = ~0UL ;else - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = + xh_default->HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =virt_to_mfn (p2m_top_mfn); - HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; - HYPERVISOR_shared_info->arch.p2m_generation =0 ; - HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long )xen_p2m_addr; - HYPERVISOR_shared_info->arch.p2m_cr3 = + xh_default->HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation =0 ; + xh_default->HYPERVISOR_shared_info->arch.p2m_vaddr = (unsigned long )xen_p2m_addr; + xh_default->HYPERVISOR_shared_info->arch.p2m_cr3 =xen_pfn_to_cr3 (virt_to_mfn (swapper_pg_dir)); }
@@ -496,12 +496,12 @@ static pte_t *alloc_p2m_pmd(unsigned long addr, pte_t *pte_pg) ptechk =lookup_address (vaddr, &level);if (ptechk == pte_pg) { - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;wmb ();/* Tools are synchronizing via p2m_generation. */ set_pmd (pmdp,__pmd (__pa (pte_newpg[i]) | _KERNPG_TABLE));wmb ();/* Tools are synchronizing via p2m_generation. */ - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++; pte_newpg[i] =NULL ; }
@@ -597,12 +597,12 @@ int xen_alloc_p2m_entry(unsigned long pfn)spin_lock_irqsave (&p2m_update_lock, flags);if (pte_pfn (*ptep) == p2m_pfn) { - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;wmb ();/* Tools are synchronizing via p2m_generation. */ set_pte (ptep,pfn_pte (PFN_DOWN (__pa (p2m)),PAGE_KERNEL ));wmb ();/* Tools are synchronizing via p2m_generation. */ - HYPERVISOR_shared_info->arch.p2m_generation++; + xh_default->HYPERVISOR_shared_info->arch.p2m_generation++;if (mid_mfn) mid_mfn[p2m_mid_index (pfn)] =virt_to_mfn (p2m); p2m =NULL ;
@@ -617,7 +617,7 @@ int xen_alloc_p2m_entry(unsigned long pfn)/* Expanded the p2m? */ if (pfn > xen_p2m_last_pfn) { xen_p2m_last_pfn = pfn; - HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; + xh_default->HYPERVISOR_shared_info->arch.max_pfn = xen_p2m_last_pfn; }return 0 ;
arch/x86/xen/suspend_hvm.c +5 -1
@@ -2,6 +2,7 @@#include <linux/types.h> #include <xen/xen.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/interface/features.h>
@@ -10,7 +11,10 @@void xen_hvm_post_suspend (int suspend_cancelled) {if (!suspend_cancelled) { -xen_hvm_init_shared_info (); +xenhost_t **xh; + +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);xen_vcpu_restore (); }xen_callback_vector ();
arch/x86/xen/suspend_pv.c +8 -6
@@ -10,6 +10,8 @@void xen_pv_pre_suspend (void ) { +xenhost_t **xh; +xen_mm_pin_all (); xen_start_info->store_mfn =mfn_to_pfn (xen_start_info->store_mfn);
@@ -18,17 +20,17 @@ void xen_pv_pre_suspend(void)BUG_ON (!irqs_disabled ()); - HYPERVISOR_shared_info = &xen_dummy_shared_info; -if (HYPERVISOR_update_va_mapping (fix_to_virt (FIX_PARAVIRT_BOOTMAP ), -__pte_ma (0 ),0 )) -BUG (); +for_each_xenhost (xh) +xenhost_reset_shared_info (*xh); }void xen_pv_post_suspend (int suspend_cancelled) { +xenhost_t **xh; +xen_build_mfn_list_list (); -set_fixmap (FIX_PARAVIRT_BOOTMAP , xen_start_info->shared_info); - HYPERVISOR_shared_info = (void *)fix_to_virt (FIX_PARAVIRT_BOOTMAP ); +for_each_xenhost (xh) +xenhost_setup_shared_info (*xh);xen_setup_mfn_list_list ();if (suspend_cancelled) {
arch/x86/xen/time.c +2 -2
@@ -37,7 +37,7 @@ static u64 xen_sched_clock_offset __read_mostly;static unsigned long xen_tsc_khz (void ) {struct pvclock_vcpu_time_info *info = - &HYPERVISOR_shared_info->vcpu_info[0 ].time; + &xh_default->HYPERVISOR_shared_info->vcpu_info[0 ].time;return pvclock_tsc_khz (info); }
@@ -66,7 +66,7 @@ static u64 xen_sched_clock(void)static void xen_read_wallclock (struct timespec64 *ts) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;struct pvclock_wall_clock *wall_clock = &(s->wc);struct pvclock_vcpu_time_info *vcpu_time;
arch/x86/xen/xen-ops.h +0 -2
@@ -28,7 +28,6 @@ DECLARE_PER_CPU(unsigned long, xen_current_cr3);extern struct start_info *xen_start_info;extern struct shared_info xen_dummy_shared_info; -extern struct shared_info *HYPERVISOR_shared_info;void xen_setup_mfn_list_list (void );void xen_build_mfn_list_list (void );
@@ -56,7 +55,6 @@ void xen_enable_syscall(void);void xen_vcpu_restore (void );void xen_callback_vector (void ); -void xen_hvm_init_shared_info (void );void xen_unplug_emulated_devices (void );void __init xen_build_dynamic_phys_to_machine (void );
arch/x86/xen/xenhost.c +12 -1
@@ -2,8 +2,19 @@#include <linux/bug.h> #include <xen/xen.h> #include <xen/xenhost.h> +#include "xen-ops.h" -xenhost_t xenhosts[2 ]; +/* +* Point at some empty memory to start with. On PV, we map the real shared_info +* page as soon as fixmap is up and running and PVH* doesn't use this. +*/ +xenhost_t xenhosts[2 ] = { +/* +* We should probably have two separate dummy shared_info pages. +*/ + [0 ].HYPERVISOR_shared_info = &xen_dummy_shared_info, + [1 ].HYPERVISOR_shared_info = &xen_dummy_shared_info, +};/* * xh_default: interface to the regular hypervisor. xenhost_type is xenhost_r0 * or xenhost_r1.
drivers/xen/events/events_2l.c +8 -8
@@ -55,37 +55,37 @@ static void evtchn_2l_bind_to_cpu(struct irq_info *info, unsigned cpu)static void evtchn_2l_clear_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_clear_bit (port,BM (&s->evtchn_pending[0 ])); }static void evtchn_2l_set_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_set_bit (port,BM (&s->evtchn_pending[0 ])); }static bool evtchn_2l_is_pending (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;return sync_test_bit (port,BM (&s->evtchn_pending[0 ])); }static bool evtchn_2l_test_and_set_mask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;return sync_test_and_set_bit (port,BM (&s->evtchn_mask[0 ])); }static void evtchn_2l_mask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;sync_set_bit (port,BM (&s->evtchn_mask[0 ])); }static void evtchn_2l_unmask (unsigned port) { -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;unsigned int cpu =get_cpu ();int do_hypercall =0 , evtchn_pending =0 ;
@@ -167,7 +167,7 @@ static void evtchn_2l_handle_events(unsigned cpu)int start_word_idx, start_bit_idx;int word_idx, bit_idx;int i; -struct shared_info *s = HYPERVISOR_shared_info; +struct shared_info *s = xh_default->HYPERVISOR_shared_info;struct vcpu_info *vcpu_info =__this_cpu_read (xen_vcpu);/* Timer interrupt has highest priority. */
@@ -264,7 +264,7 @@ static void evtchn_2l_handle_events(unsigned cpu)irqreturn_t xen_debug_interrupt (int irq,void *dev_id) { -struct shared_info *sh = HYPERVISOR_shared_info; +struct shared_info *sh = xh_default->HYPERVISOR_shared_info;int cpu =smp_processor_id ();xen_ulong_t *cpu_evtchn =per_cpu (cpu_evtchn_mask, cpu);int i;
include/xen/xenhost.h +39 -0
@@ -82,6 +82,14 @@ typedef struct {* bounce callbacks via L1-Xen. */ u8 features[XENFEAT_NR_SUBMAPS *32 ]; + +/* +* shared-info to communicate with this xenhost instance. +*/ +struct { +struct shared_info *HYPERVISOR_shared_info; +unsigned long shared_info_pfn; + }; } xenhost_t; typedef struct xenhost_ops {
@@ -111,6 +119,26 @@ typedef struct xenhost_ops {* to decide which particular L1-guest was the caller. */ void (*setup_hypercall_page)(xenhost_t *xenhost); + +/* +* shared_info: needed before vcpu-info setup. +* +* Needed early because Xen needs it for irq_disable() and such. +* On PV first a dummy_shared_info is setup which eventually gets +* switched to the real one so this needs to support switching +* xenhost. +* +* Reset for PV is done differently from HVM, so provide a +* separate interface. +* +* xenhost_r0: point xenhost->HYPERVISOR_shared_info to a +* newly allocated shared_info page. +* xenhost_r1: similar to what we do now. +* xenhost_r2: new remote hypercall to setup a shared_info page. +* This is where we would now handle L0-Xen irq/evtchns. +*/ +void (*setup_shared_info)(xenhost_t *xenhost); +void (*reset_shared_info)(xenhost_t *xenhost); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -146,4 +174,15 @@ static inline void xenhost_setup_hypercall_page(xenhost_t *xh) (xh->ops->setup_hypercall_page)(xh); } + +static inline void xenhost_setup_shared_info (xenhost_t *xh) +{ + (xh->ops->setup_shared_info)(xh); +} + +static inline void xenhost_reset_shared_info (xenhost_t *xh) +{ + (xh->ops->reset_shared_info)(xh); +} +#endif /* __XENHOST_H */
Signature · 1 line
2.20.1
Juergen Gross
maintainerRe: [RFC PATCH 06/16] x86/xen: add shared_info support to xenhost_t
Quoted 3 lines · Ankur Arora
HYPERVISOR_shared_infois used for irq/evtchn communication between the guest and the host. Abstract out the setup/reset inxenhost_tsuch that nested configurations can use both xenhosts simultaneously.
I have mixed feelings about this patch. Most of the shared_info stuff we don't need for the nested case. In the end only the event channels might be interesting, but we obviously want them not for all vcpus of the L1 hypervisor, but for those of the current guest.
So I think just drop that patch for now. We can dig it out later in case nesting wants it again.
Juergen
Re: [RFC PATCH 06/16] x86/xen: add shared_info support to xenhost_t
Quoted 9 lines · Juergen Gross
Quoted 3 lines · Ankur Arora
HYPERVISOR_shared_infois used for irq/evtchn communication between the guest and the host. Abstract out the setup/reset inxenhost_tsuch that nested configurations can use both xenhosts simultaneously.I have mixed feelings about this patch. Most of the
shared_infostuff we don't need for the nested case. In the end only the event channels might be interesting, but we obviously want them not for all vcpus of the L1 hypervisor, but for those of the current guest.
Agreed about the mixed feelings part. shared_info does feel far too heavy to drag along just for the event-channel state. Infact, on thinking a bit more, a better abstraction for nested event-channels would have been as an extension to the primary xenhost's event-channel bits.
(The nested upcalls also go via the primary xenhost in patch-8.)
Ankur
Quoted 5 lines
So I think just drop that patch for now. We can dig it out later in case > nesting wants it again.
Juergen
RFC PATCH 7/16 x86/xen: make vcpu_info part of xenhost_t
In reply to Ankur AroraAbstract out xen_vcpu_id probing via (*probe_vcpu_id)(). Once that is availab,e the vcpu_info registration happens via the VCPUOP hypercall.
Note that for the nested case, there are two vcpu_ids, and two vcpu_info areas, one each for the default xenhost and the remote xenhost. The vcpu_info is used via pv_irq_ops, and evtchn signaling.
The other VCPUOP hypercalls are used for management (and scheduling) which is expected to be done purely in the default hypervisor. However, scheduling of L1-guest does imply L0-Xen-vcpu_info switching, which might mean that the remote hypervisor needs some visibility into related events/hypercalls in the default hypervisor.
TODO:
- percpu data structures for xen_vcpu
--- arch/x86/xen/enlighten.c | 93 +++++++++++++------------------- arch/x86/xen/enlighten_hvm.c | 87 ++++++++++++++++++------------ arch/x86/xen/enlighten_pv.c | 60 ++++++++++++++------- arch/x86/xen/enlighten_pvh.c | 3 +- arch/x86/xen/irq.c | 10 ++-- arch/x86/xen/mmu_pv.c | 6 +-- arch/x86/xen/pci-swiotlb-xen.c | 1 + arch/x86/xen/setup.c | 1 + arch/x86/xen/smp.c | 9 +++- arch/x86/xen/smp_hvm.c | 17 +++--- arch/x86/xen/smp_pv.c | 12 ++--- arch/x86/xen/time.c | 23 ++++---- arch/x86/xen/xen-ops.h | 5 +- drivers/xen/events/events_base.c | 14 ++--- drivers/xen/events/events_fifo.c | 2 +- drivers/xen/evtchn.c | 2 +- drivers/xen/time.c | 2 +- include/xen/xen-ops.h | 7 +-- include/xen/xenhost.h | 47 ++++++++++++++++ 19 files changed, 240 insertions(+), 161 deletions(-)
arch/x86/xen/enlighten.c +38 -55
@@ -20,35 +20,6 @@#include "smp.h" #include "pmu.h" -/* -* Pointer to the xen_vcpu_info structure or -* &HYPERVISOR_shared_info->vcpu_info[cpu]. See xen_hvm_init_shared_info -* and xen_vcpu_setup for details. By default it points to share_info->vcpu_info -* but if the hypervisor supports VCPUOP_register_vcpu_info then it can point -* to xen_vcpu_info. The pointer is used in __xen_evtchn_do_upcall to -* acknowledge pending events. -* Also more subtly it is used by the patched version of irq enable/disable -* e.g. xen_irq_enable_direct and xen_iret in PV mode. -* -* The desire to be able to do those mask/unmask operations as a single -* instruction by using the per-cpu offset held in %gs is the real reason -* vcpu info is in a per-cpu pointer and the original reason for this -* hypercall. -* -*/ -DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu); - -/* -* Per CPU pages used if hypervisor supports VCPUOP_register_vcpu_info -* hypercall. This can be used both in PV and PVHVM mode. The structure -* overrides the default per_cpu(xen_vcpu, cpu) value. -*/ -DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); - -/* Linux <-> Xen vCPU id mapping */ -DEFINE_PER_CPU (uint32_t, xen_vcpu_id); -EXPORT_PER_CPU_SYMBOL (xen_vcpu_id); -enum xen_domain_type xen_domain_type =XEN_NATIVE ;EXPORT_SYMBOL_GPL (xen_domain_type);
@@ -112,12 +83,12 @@ int xen_cpuhp_setup(int (*cpu_up_prepare_cb)(unsigned int),return rc >=0 ?0 : rc; } -static int xen_vcpu_setup_restore (int cpu) +static int xen_vcpu_setup_restore (xenhost_t *xh,int cpu) {int rc =0 ;/* Any per_cpu(xen_vcpu) is stale, so reset it */ -xen_vcpu_info_reset (cpu); +xen_vcpu_info_reset (xh, cpu);/* * For PVH and PVHVM, setup online VCPUs only. The rest will
@@ -125,7 +96,7 @@ static int xen_vcpu_setup_restore(int cpu)*/ if (xen_pv_domain () || (xen_hvm_domain () &&cpu_online (cpu))) { - rc =xen_vcpu_setup (cpu); + rc =xen_vcpu_setup (xh, cpu); }return rc;
@@ -138,30 +109,42 @@ static int xen_vcpu_setup_restore(int cpu)*/ void xen_vcpu_restore (void ) { -int cpu, rc; +int cpu, rc =0 ; +/* +* VCPU management is primarily the responsibility of xh_default and +* xh_remote only needs VCPUOP_register_vcpu_info. +* So, we do VPUOP_down and VCPUOP_up only on xh_default. +* +* (Currently, however, VCPUOP_register_vcpu_info is allowed only +* on VCPUs that are self or down, so we might need a new model +* there.) +*/ for_each_possible_cpu (cpu) {bool other_cpu = (cpu !=smp_processor_id ());bool is_up; +xenhost_t **xh; -if (xen_vcpu_nr (cpu) ==XEN_VCPU_ID_INVALID ) +if (xen_vcpu_nr (xh_default, cpu) ==XEN_VCPU_ID_INVALID )continue ;/* Only Xen 4.5 and higher support this. */ is_up =HYPERVISOR_vcpu_op (VCPUOP_is_up, -xen_vcpu_nr (cpu),NULL ) >0 ; +xen_vcpu_nr (xh_default, cpu),NULL ) >0 ;if (other_cpu && is_up && -HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (cpu),NULL )) +HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (xh_default, cpu),NULL ))BUG ();if (xen_pv_domain () ||xen_feature (XENFEAT_hvm_safe_pvclock))xen_setup_runstate_info (cpu); - rc =xen_vcpu_setup_restore (cpu); -if (rc) -pr_emerg_once ("vcpu restore failed for cpu=%d err=%d. " -"System will hang.\n" , cpu, rc); +for_each_xenhost (xh) { + rc =xen_vcpu_setup_restore (*xh, cpu); +if (rc) +pr_emerg_once ("vcpu restore failed for cpu=%d err=%d. " +"System will hang.\n" , cpu, rc); + }/* * In case xen_vcpu_setup_restore() fails, do not bring up the * VCPU. This helps us avoid the resulting OOPS when the VCPU
@@ -172,29 +155,29 @@ void xen_vcpu_restore(void)* VCPUs to come up. */ if (other_cpu && is_up && (rc ==0 ) && -HYPERVISOR_vcpu_op (VCPUOP_up,xen_vcpu_nr (cpu),NULL )) +HYPERVISOR_vcpu_op (VCPUOP_up,xen_vcpu_nr (xh_default, cpu),NULL ))BUG (); } } -void xen_vcpu_info_reset (int cpu) +void xen_vcpu_info_reset (xenhost_t *xh,int cpu) { -if (xen_vcpu_nr (cpu) <MAX_VIRT_CPUS ) { -per_cpu (xen_vcpu, cpu) = - &xh_default->HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (cpu)]; +if (xen_vcpu_nr (xh, cpu) <MAX_VIRT_CPUS ) { + xh->xen_vcpu[cpu] = + &xh->HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr (xh, cpu)]; }else {/* Set to NULL so that if somebody accesses it we get an OOPS */ -per_cpu (xen_vcpu, cpu) =NULL ; + xh->xen_vcpu[cpu] =NULL ; } } -int xen_vcpu_setup (int cpu) +int xen_vcpu_setup (xenhost_t *xh,int cpu) {struct vcpu_register_vcpu_info info;int err;struct vcpu_info *vcpup; -BUG_ON (xh_default->HYPERVISOR_shared_info == &xen_dummy_shared_info); +BUG_ON (xh->HYPERVISOR_shared_info == &xen_dummy_shared_info);/* * This path is called on PVHVM at bootup (xen_hvm_smp_prepare_boot_cpu)
@@ -208,12 +191,12 @@ int xen_vcpu_setup(int cpu)* use this function. */ if (xen_hvm_domain ()) { -if (per_cpu (xen_vcpu, cpu) == &per_cpu (xen_vcpu_info, cpu)) +if (xh->xen_vcpu[cpu] == &xh->xen_vcpu_info[cpu])return 0 ; }if (xen_have_vcpu_info_placement) { - vcpup = &per_cpu (xen_vcpu_info, cpu); + vcpup = &xh->xen_vcpu_info[cpu]; info.mfn =arbitrary_virt_to_mfn (vcpup); info.offset =offset_in_page (vcpup);
@@ -227,8 +210,8 @@ int xen_vcpu_setup(int cpu)* hypercall does not allow to over-write info.mfn and * info.offset. */ - err =HYPERVISOR_vcpu_op (VCPUOP_register_vcpu_info, -xen_vcpu_nr (cpu), &info); + err =hypervisor_vcpu_op (xh, VCPUOP_register_vcpu_info, +xen_vcpu_nr (xh, cpu), &info);if (err) { pr_warn_once("register_vcpu_info failed: cpu=%d err=%d\n",
@@ -239,14 +222,14 @@ int xen_vcpu_setup(int cpu)* This cpu is using the registered vcpu info, even if * later ones fail to. */ -per_cpu (xen_vcpu, cpu) = vcpup; + xh->xen_vcpu[cpu] = vcpup; } }if (!xen_have_vcpu_info_placement) -xen_vcpu_info_reset (cpu); +xen_vcpu_info_reset (xh, cpu); -return ((per_cpu (xen_vcpu, cpu) ==NULL ) ? -ENODEV :0 ); +return ((xh->xen_vcpu[cpu] ==NULL ) ? -ENODEV :0 ); }void xen_reboot (int reason)
arch/x86/xen/enlighten_hvm.c +53 -34
144 lines not on this page · raw message
arch/x86/xen/enlighten_pv.c +40 -20
127 lines not on this page · raw message
arch/x86/xen/enlighten_pvh.c +2 -1
@@ -2,13 +2,14 @@#include <linux/acpi.h> #include <xen/hvc-console.h> +#include <xen/interface/xen.h> #include <asm/io_apic.h> #include <asm/hypervisor.h> #include <asm/e820/api.h> -#include <xen/xen.h> #include <xen/xenhost.h> +#include <xen/xen.h> #include <asm/xen/interface.h> #include <asm/xen/hypercall.h>
arch/x86/xen/irq.c +5 -5
@@ -29,7 +29,7 @@ asmlinkage __visible unsigned long xen_save_fl(void)struct vcpu_info *vcpu;unsigned long flags; - vcpu =this_cpu_read (xen_vcpu); + vcpu = xh_default->xen_vcpu[smp_processor_id ()];/* flag has opposite sense of mask */ flags = !vcpu->evtchn_upcall_mask;
@@ -51,7 +51,7 @@ __visible void xen_restore_fl(unsigned long flags)/* See xen_irq_enable() for why preemption must be disabled. */ preempt_disable (); - vcpu =this_cpu_read (xen_vcpu); + vcpu = xh_default->xen_vcpu[smp_processor_id ()]; vcpu->evtchn_upcall_mask = flags;if (flags ==0 ) {
@@ -70,7 +70,7 @@ asmlinkage __visible void xen_irq_disable(void)make sure we're don't switch CPUs between getting the vcpu pointer and updating the mask. */ preempt_disable (); -this_cpu_read (xen_vcpu)->evtchn_upcall_mask =1 ; + xh_default->xen_vcpu[smp_processor_id ()]->evtchn_upcall_mask =1 ;preempt_enable_no_resched (); }PV_CALLEE_SAVE_REGS_THUNK (xen_irq_disable);
@@ -86,7 +86,7 @@ asmlinkage __visible void xen_irq_enable(void)*/ preempt_disable (); - vcpu =this_cpu_read (xen_vcpu); + vcpu = xh_default->xen_vcpu[smp_processor_id ()]; vcpu->evtchn_upcall_mask =0 ;/* Doesn't matter if we get preempted here, because any
@@ -111,7 +111,7 @@ static void xen_halt(void) {if (irqs_disabled ())HYPERVISOR_vcpu_op (VCPUOP_down, -xen_vcpu_nr (smp_processor_id ()),NULL ); +xen_vcpu_nr (xh_default,smp_processor_id ()),NULL );else xen_safe_halt (); }
arch/x86/xen/mmu_pv.c +3 -3
@@ -1304,17 +1304,17 @@ static void __init xen_pagetable_init(void) }static void xen_write_cr2 (unsigned long cr2) { -this_cpu_read (xen_vcpu)->arch.cr2 = cr2; + xh_default->xen_vcpu[smp_processor_id ()]->arch.cr2 = cr2; }static unsigned long xen_read_cr2 (void ) { -return this_cpu_read (xen_vcpu)->arch.cr2; +return xh_default->xen_vcpu[smp_processor_id ()]->arch.cr2; }unsigned long xen_read_cr2_direct (void ) { -return this_cpu_read (xen_vcpu_info.arch.cr2); +return xh_default->xen_vcpu_info[smp_processor_id ()].arch.cr2; } static noinline void xen_flush_tlb(void)
arch/x86/xen/pci-swiotlb-xen.c +1 -0
@@ -4,6 +4,7 @@#include <linux/dma-mapping.h> #include <linux/pci.h> +#include <xen/interface/xen.h> #include <xen/swiotlb-xen.h> #include <asm/xen/hypervisor.h>
arch/x86/xen/setup.c +1 -0
@@ -19,6 +19,7 @@#include <asm/setup.h> #include <asm/acpi.h> #include <asm/numa.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
arch/x86/xen/smp.c +7 -2
@@ -6,6 +6,7 @@#include <linux/percpu.h> #include <xen/events.h> +#include <xen/xenhost.h> #include <xen/hvc-console.h> #include "xen-ops.h"
@@ -129,7 +130,10 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)return ;for_each_online_cpu (cpu) { -if (xen_vcpu_nr (cpu) <MAX_VIRT_CPUS ) +xenhost_t **xh; + +if ((xen_vcpu_nr (xh_default, cpu) <MAX_VIRT_CPUS ) && + (!xh_remote || (xen_vcpu_nr (xh_remote, cpu) <MAX_VIRT_CPUS )))continue ; rc =cpu_down (cpu);
@@ -138,7 +142,8 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)/* * Reset vcpu_info so this cpu cannot be onlined again. */ -xen_vcpu_info_reset (cpu); +for_each_xenhost (xh) +xen_vcpu_info_reset (*xh, cpu); count++; }else { pr_warn("%s: failed to bring CPU %d down, error %d\n",
arch/x86/xen/smp_hvm.c +11 -6
@@ -9,6 +9,7 @@static void __init xen_hvm_smp_prepare_boot_cpu (void ) { +xenhost_t **xh;BUG_ON (smp_processor_id () !=0 );native_smp_prepare_boot_cpu ();
@@ -16,7 +17,8 @@ static void __init xen_hvm_smp_prepare_boot_cpu(void)* Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info * in xen_cpu_up_prepare_hvm(). */ -xen_vcpu_setup (0 ); +for_each_xenhost (xh) +xen_vcpu_setup (*xh,0 );/* * The alternative logic (which patches the unlock/lock) runs before
@@ -29,6 +31,7 @@ static void __init xen_hvm_smp_prepare_boot_cpu(void)static void __init xen_hvm_smp_prepare_cpus (unsigned int max_cpus) { +xenhost_t **xh;int cpu;native_smp_prepare_cpus (max_cpus);
@@ -36,12 +39,14 @@ static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)xen_init_lock_cpu (0 ); -for_each_possible_cpu (cpu) { -if (cpu ==0 ) -continue ; +for_each_xenhost (xh) { +for_each_possible_cpu (cpu) { +if (cpu ==0 ) +continue ; -/* Set default vcpu_id to make sure that we don't use cpu-0's */ -per_cpu (xen_vcpu_id, cpu) =XEN_VCPU_ID_INVALID ; +/* Set default vcpu_id to make sure that we don't use cpu-0's */ + (*xh)->xen_vcpu_id[cpu] =XEN_VCPU_ID_INVALID ; + } } }
arch/x86/xen/smp_pv.c +6 -6
@@ -350,7 +350,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)per_cpu (xen_cr3, cpu) =__pa (swapper_pg_dir); ctxt->ctrlreg[3 ] =xen_pfn_to_cr3 (virt_to_gfn (swapper_pg_dir)); -if (HYPERVISOR_vcpu_op (VCPUOP_initialise,xen_vcpu_nr (cpu), ctxt)) +if (HYPERVISOR_vcpu_op (VCPUOP_initialise,xen_vcpu_nr (xh_default, cpu), ctxt))BUG ();kfree (ctxt);
@@ -374,7 +374,7 @@ static int xen_pv_cpu_up(unsigned int cpu, struct task_struct *idle)return rc;/* make sure interrupts start blocked */ -per_cpu (xen_vcpu, cpu)->evtchn_upcall_mask =1 ; + xh_default->xen_vcpu[cpu]->evtchn_upcall_mask =1 ; rc =cpu_initialize_context (cpu, idle);if (rc)
@@ -382,7 +382,7 @@ static int xen_pv_cpu_up(unsigned int cpu, struct task_struct *idle)xen_pmu_init (cpu); - rc =HYPERVISOR_vcpu_op (VCPUOP_up,xen_vcpu_nr (cpu),NULL ); + rc =HYPERVISOR_vcpu_op (VCPUOP_up,xen_vcpu_nr (xh_default, cpu),NULL );BUG_ON (rc);while (cpu_report_state (cpu) !=CPU_ONLINE )
@@ -407,7 +407,7 @@ static int xen_pv_cpu_disable(void)static void xen_pv_cpu_die (unsigned int cpu) {while (HYPERVISOR_vcpu_op (VCPUOP_is_up, -xen_vcpu_nr (cpu),NULL )) { +xen_vcpu_nr (xh_default, cpu),NULL )) {__set_current_state (TASK_UNINTERRUPTIBLE );schedule_timeout (HZ /10 ); }
@@ -423,7 +423,7 @@ static void xen_pv_cpu_die(unsigned int cpu)static void xen_pv_play_dead (void )/* used only with HOTPLUG_CPU */ {play_dead_common (); -HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (smp_processor_id ()),NULL ); +HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (xh_default,smp_processor_id ()),NULL );cpu_bringup ();/* * commit 4b0c0f294 (tick: Cleanup NOHZ per cpu data on cpu down)
@@ -464,7 +464,7 @@ static void stop_self(void *v)set_cpu_online (cpu, false); -HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (cpu),NULL ); +HYPERVISOR_vcpu_op (VCPUOP_down,xen_vcpu_nr (xh_default, cpu),NULL );BUG (); }
arch/x86/xen/time.c +12 -11
@@ -18,12 +18,12 @@#include <linux/timekeeper_internal.h> #include <asm/pvclock.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/events.h> #include <xen/features.h> -#include <xen/interface/xen.h> #include <xen/interface/vcpu.h> #include "xen-ops.h"
@@ -48,7 +48,7 @@ static u64 xen_clocksource_read(void)u64 ret;preempt_disable_notrace (); - src = &__this_cpu_read (xen_vcpu)->time; + src = &xh_default->xen_vcpu[smp_processor_id ()]->time; ret =pvclock_clocksource_read (src);preempt_enable_notrace ();return ret;
@@ -70,9 +70,10 @@ static void xen_read_wallclock(struct timespec64 *ts)struct pvclock_wall_clock *wall_clock = &(s->wc);struct pvclock_vcpu_time_info *vcpu_time; - vcpu_time = &get_cpu_var (xen_vcpu)->time; +preempt_disable_notrace (); + vcpu_time = &xh_default->xen_vcpu[smp_processor_id ()]->time;pvclock_read_wallclock (wall_clock, vcpu_time, ts); -put_cpu_var (xen_vcpu); +preempt_enable_notrace (); }static void xen_get_wallclock (struct timespec64 *now)
@@ -233,9 +234,9 @@ static int xen_vcpuop_shutdown(struct clock_event_device *evt) {int cpu =smp_processor_id (); -if (HYPERVISOR_vcpu_op (VCPUOP_stop_singleshot_timer,xen_vcpu_nr (cpu), +if (HYPERVISOR_vcpu_op (VCPUOP_stop_singleshot_timer,xen_vcpu_nr (xh_default, cpu),NULL ) || -HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (cpu), +HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (xh_default, cpu),NULL ))BUG ();
@@ -246,7 +247,7 @@ static int xen_vcpuop_set_oneshot(struct clock_event_device *evt) {int cpu =smp_processor_id (); -if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (cpu), +if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (xh_default, cpu),NULL ))BUG ();
@@ -266,7 +267,7 @@ static int xen_vcpuop_set_next_event(unsigned long delta,/* Get an event anyway, even if the timeout is already expired */ single.flags =0 ; - ret =HYPERVISOR_vcpu_op (VCPUOP_set_singleshot_timer,xen_vcpu_nr (cpu), + ret =HYPERVISOR_vcpu_op (VCPUOP_set_singleshot_timer,xen_vcpu_nr (xh_default, cpu), &single);BUG_ON (ret !=0 );
@@ -366,7 +367,7 @@ void xen_timer_resume(void)for_each_online_cpu (cpu) {if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer, -xen_vcpu_nr (cpu),NULL )) +xen_vcpu_nr (xh_default, cpu),NULL ))BUG (); } }
@@ -482,7 +483,7 @@ static void __init xen_time_init(void)clocksource_register_hz (&xen_clocksource,NSEC_PER_SEC ); -if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (cpu), +if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer,xen_vcpu_nr (xh_default, cpu),NULL ) ==0 ) {/* Successfully turned off 100Hz tick, so we have the vcpuop-based timer interface */
@@ -500,7 +501,7 @@ static void __init xen_time_init(void)* We check ahead on the primary time info if this * bit is supported hence speeding up Xen clocksource. */ - pvti = &__this_cpu_read (xen_vcpu)->time; + pvti = &xh_default->xen_vcpu[smp_processor_id ()]->time;if (pvti->flags &PVCLOCK_TSC_STABLE_BIT ) {pvclock_set_flags (PVCLOCK_TSC_STABLE_BIT );xen_setup_vsyscall_time_info ();
arch/x86/xen/xen-ops.h +2 -3
@@ -22,7 +22,6 @@ extern void *xen_initial_gdt;struct trap_info ;void xen_copy_trap_info (struct trap_info *traps); -DECLARE_PER_CPU(struct vcpu_info, xen_vcpu_info); DECLARE_PER_CPU(unsigned long, xen_cr3); DECLARE_PER_CPU(unsigned long, xen_current_cr3);
@@ -76,8 +75,8 @@ bool xen_vcpu_stolen(int vcpu);extern int xen_have_vcpu_info_placement; -int xen_vcpu_setup (int cpu); -void xen_vcpu_info_reset (int cpu); +int xen_vcpu_setup (xenhost_t *xh,int cpu); +void xen_vcpu_info_reset (xenhost_t *xh,int cpu);void xen_setup_vcpu_info_placement (void );#ifdef CONFIG_SMP
drivers/xen/events/events_base.c +7 -7
@@ -884,7 +884,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)irq_set_chip_and_handler_name (irq, &xen_percpu_chip, handle_percpu_irq,"ipi" ); - bind_ipi.vcpu =xen_vcpu_nr (cpu); + bind_ipi.vcpu =xen_vcpu_nr (xh_default, cpu);if (HYPERVISOR_event_channel_op (EVTCHNOP_bind_ipi, &bind_ipi) !=0 )BUG ();
@@ -937,7 +937,7 @@ static int find_virq(unsigned int virq, unsigned int cpu)continue ;if (status.status != EVTCHNSTAT_virq)continue ; -if (status.u.virq == virq && status.vcpu ==xen_vcpu_nr (cpu)) { +if (status.u.virq == virq && status.vcpu ==xen_vcpu_nr (xh_default, cpu)) { rc = port;break ; }
@@ -980,7 +980,7 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu) handle_edge_irq, "virq"); bind_virq.virq = virq; - bind_virq.vcpu =xen_vcpu_nr (cpu); + bind_virq.vcpu =xen_vcpu_nr (xh_default, cpu); ret =HYPERVISOR_event_channel_op (EVTCHNOP_bind_virq, &bind_virq);if (ret ==0 )
@@ -1200,7 +1200,7 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)#ifdef CONFIG_X86 if (unlikely (vector ==XEN_NMI_VECTOR )) { -int rc =HYPERVISOR_vcpu_op (VCPUOP_send_nmi,xen_vcpu_nr (cpu), +int rc =HYPERVISOR_vcpu_op (VCPUOP_send_nmi,xen_vcpu_nr (xh_default, cpu),NULL );if (rc <0 )printk (KERN_WARNING "Sending nmi to CPU%d failed (rc:%d)\n" , cpu, rc);
@@ -1306,7 +1306,7 @@ int xen_rebind_evtchn_to_cpu(int evtchn, unsigned tcpu)/* Send future instances of this interrupt to other vcpu. */ bind_vcpu.port = evtchn; - bind_vcpu.vcpu =xen_vcpu_nr (tcpu); + bind_vcpu.vcpu =xen_vcpu_nr (xh_default, tcpu);/* * Mask the event while changing the VCPU binding to prevent
@@ -1451,7 +1451,7 @@ static void restore_cpu_virqs(unsigned int cpu)/* Get a new binding from Xen. */ bind_virq.virq = virq; - bind_virq.vcpu =xen_vcpu_nr (cpu); + bind_virq.vcpu =xen_vcpu_nr (xh_default, cpu);if (HYPERVISOR_event_channel_op (EVTCHNOP_bind_virq, &bind_virq) !=0 )BUG ();
@@ -1475,7 +1475,7 @@ static void restore_cpu_ipis(unsigned int cpu)BUG_ON (ipi_from_irq (irq) != ipi);/* Get a new binding from Xen. */ - bind_ipi.vcpu =xen_vcpu_nr (cpu); + bind_ipi.vcpu =xen_vcpu_nr (xh_default, cpu);if (HYPERVISOR_event_channel_op (EVTCHNOP_bind_ipi, &bind_ipi) !=0 )BUG ();
drivers/xen/events/events_fifo.c +1 -1
@@ -113,7 +113,7 @@ static int init_control_block(int cpu, init_control.control_gfn =virt_to_gfn (control_block); init_control.offset =0 ; - init_control.vcpu =xen_vcpu_nr (cpu); + init_control.vcpu =xen_vcpu_nr (xh_default, cpu);return HYPERVISOR_event_channel_op (EVTCHNOP_init_control, &init_control); }
drivers/xen/evtchn.c +1 -1
@@ -475,7 +475,7 @@ static long evtchn_ioctl(struct file *file,break ; bind_virq.virq = bind.virq; - bind_virq.vcpu =xen_vcpu_nr (0 ); + bind_virq.vcpu =xen_vcpu_nr (xh_default,0 ); rc =HYPERVISOR_event_channel_op (EVTCHNOP_bind_virq, &bind_virq);if (rc !=0 )
drivers/xen/time.c +1 -1
@@ -164,7 +164,7 @@ void xen_setup_runstate_info(int cpu) area.addr.v = &per_cpu (xen_runstate, cpu);if (HYPERVISOR_vcpu_op (VCPUOP_register_runstate_memory_area, -xen_vcpu_nr (cpu), &area)) +xen_vcpu_nr (xh_default, cpu), &area))BUG (); }
include/xen/xen-ops.h +2 -5
@@ -9,12 +9,9 @@#include <asm/xen/interface.h> #include <xen/interface/vcpu.h> -DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu); - -DECLARE_PER_CPU (uint32_t, xen_vcpu_id); -static inline uint32_t xen_vcpu_nr (int cpu) +static inline uint32_t xen_vcpu_nr (xenhost_t *xh,int cpu) { -return per_cpu (xen_vcpu_id, cpu); +return xh->xen_vcpu_id[cpu]; }#define XEN_VCPU_ID_INVALID U32_MAX
include/xen/xenhost.h +47 -0
63 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 07/16] x86/xen: make vcpu_info part of xenhost_t
Quoted 7 lines · Ankur Arora
Abstract out
xen_vcpu_idprobing via (*probe_vcpu_id)(). Once that is availab,e thevcpu_inforegistration happens via the VCPUOP hypercall.Note that for the nested case, there are two
vcpu_ids, and twovcpu_infoareas, one each for the default xenhost and the remote xenhost. Thevcpu_infois used viapv_irq_ops, and evtchn signaling.
Quoted 5 lines
The other VCPUOP hypercalls are used for management (and scheduling) which is expected to be done purely in the default hypervisor. However, scheduling of L1-guest does imply L0-Xen-vcpu_info switching, which might mean that the remote hypervisor needs some visibility into related events/hypercalls in the default hypervisor.
Another candidate for dropping due to layering violation, I guess.
Juergen
Re: [RFC PATCH 07/16] x86/xen: make vcpu_info part of xenhost_t
Quoted 8 lines · Juergen Gross
Quoted 7 lines · Ankur Arora
Abstract out
xen_vcpu_idprobing via (*probe_vcpu_id)(). Once that is availab,e thevcpu_inforegistration happens via the VCPUOP hypercall.Note that for the nested case, there are two
vcpu_ids, and twovcpu_infoareas, one each for the default xenhost and the remote xenhost. Thevcpu_infois used viapv_irq_ops, and evtchn signaling.
Quoted 7 lines
Quoted 5 lines
The other VCPUOP hypercalls are used for management (and scheduling) which is expected to be done purely in the default hypervisor. However, scheduling of L1-guest does imply L0-Xen-vcpu_info switching, which might mean that the remote hypervisor needs some visibility into related events/hypercalls in the default hypervisor.
Another candidate for dropping due to layering violation, I guess.
Yeah, a more narrowly tailored interface, where perhaps the L1-Xen maps events for L0-Xen makes sense.
Also, just realized that given that L0-Xen has no control over scheduling of L1-Xen's guests (some of which it might want to send events to), it makes sense for L1-Xen to have some state for guest evtchns which pertain to L0-Xen.
Ankur
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 8/16 x86/xen: irq/upcall handling with multiple xenhosts
In reply to Ankur AroraFor configurations with multiple xenhosts, we need to handle events generated from multiple xenhosts.
Having more than one upcall handler might be quite hairy, and it would be simpler if the callback from L0-Xen could be bounced via L1-Xen. This will also mean simpler pv_irq_ops code because now the IF flag maps onto the xh_default->vcpu_info->evtchn_upcall_mask.
However, we still update the xh_remote->vcpu_info->evtchn_upcall_mask on a best effort basis to minimize unnecessary work in remote xenhost.
TODO:
- direct pv_ops.irq are disabled.
--- arch/x86/xen/Makefile | 2 +- arch/x86/xen/enlighten_pv.c | 4 ++- arch/x86/xen/irq.c | 69 +++++++++++++++++++++++++++++-------- arch/x86/xen/smp_pv.c | 11 ++++++ 4 files changed, 70 insertions(+), 16 deletions(-)
arch/x86/xen/Makefile +1 -1
@@ -34,7 +34,7 @@ obj-$(CONFIG_XEN_PV) += enlighten_pv.o obj-$(CONFIG_XEN_PV) += mmu_pv.o obj-$(CONFIG_XEN_PV) += irq.o obj-$(CONFIG_XEN_PV) += multicalls.o -obj-$(CONFIG_XEN_PV) += xen-asm.o +obj-n += xen-asm.o obj-$(CONFIG_XEN_PV) += xen-asm_$(BITS).o obj-$(CONFIG_XEN_PVH) += enlighten_pvh.o
arch/x86/xen/enlighten_pv.c +3 -1
@@ -996,8 +996,9 @@ void __init xen_setup_vcpu_info_placement(void)* xen_vcpu_setup managed to place the vcpu_info within the * percpu area for all cpus, so make use of it. */ +#if 0 +/* Disable direct access for now. */ if (xen_have_vcpu_info_placement && false) { -/* Disable direct access until we have proper pcpu data structures. */ pv_ops.irq.save_fl =__PV_IS_CALLEE_SAVE (xen_save_fl_direct); pv_ops.irq.restore_fl =__PV_IS_CALLEE_SAVE (xen_restore_fl_direct);
@@ -1007,6 +1008,7 @@ void __init xen_setup_vcpu_info_placement(void)__PV_IS_CALLEE_SAVE (xen_irq_enable_direct); pv_ops.mmu.read_cr2 = xen_read_cr2_direct; } +#endif } static const struct pv_info xen_info __initconst = {
arch/x86/xen/irq.c +55 -14
129 lines not on this page · raw message
arch/x86/xen/smp_pv.c +11 -0
@@ -343,6 +343,17 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)#else ctxt->gs_base_kernel =per_cpu_offset (cpu);#endif +/* +* We setup an upcall handler only for the default xenhost. The remote +* xenhost will generate evtchn events, but an additional callback would be +* quite hairy, since we would have VCPU state initialised in multiple +* hypervisors and issues like re-entrancy of upcalls. +* +* It would be simpler if the callback from L0-Xen could be bounced +* bounced via L1-Xen. This also simplifies the pv_irq_ops code +* because now the CPU's IF processing only needs to happen on +* xh_default->vcpu_info. +*/ ctxt->event_callback_eip = (unsigned long )xen_hypervisor_callback; ctxt->failsafe_callback_eip =
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 8/16 x86/xen: irq/upcall handling with multiple xenhosts
In reply to Ankur AroraFor configurations with multiple xenhosts, we need to handle events generated from multiple xenhosts.
Having more than one upcall handler might be quite hairy, and it would be simpler if the callback from L0-Xen could be bounced via L1-Xen. This will also mean simpler pv_irq_ops code because now the IF flag maps onto the xh_default->vcpu_info->evtchn_upcall_mask.
However, we still update the xh_remote->vcpu_info->evtchn_upcall_mask on a best effort basis to minimize unnecessary work in remote xenhost.
TODO:
- direct pv_ops.irq are disabled.
--- arch/x86/xen/Makefile | 2 +- arch/x86/xen/enlighten_pv.c | 4 ++- arch/x86/xen/irq.c | 69 +++++++++++++++++++++++++++++-------- arch/x86/xen/smp_pv.c | 11 ++++++ 4 files changed, 70 insertions(+), 16 deletions(-)
arch/x86/xen/Makefile +1 -1
@@ -34,7 +34,7 @@ obj-$(CONFIG_XEN_PV) += enlighten_pv.o obj-$(CONFIG_XEN_PV) += mmu_pv.o obj-$(CONFIG_XEN_PV) += irq.o obj-$(CONFIG_XEN_PV) += multicalls.o -obj-$(CONFIG_XEN_PV) += xen-asm.o +obj-n += xen-asm.o obj-$(CONFIG_XEN_PV) += xen-asm_$(BITS).o obj-$(CONFIG_XEN_PVH) += enlighten_pvh.o
arch/x86/xen/enlighten_pv.c +3 -1
@@ -996,8 +996,9 @@ void __init xen_setup_vcpu_info_placement(void)* xen_vcpu_setup managed to place the vcpu_info within the * percpu area for all cpus, so make use of it. */ +#if 0 +/* Disable direct access for now. */ if (xen_have_vcpu_info_placement && false) { -/* Disable direct access until we have proper pcpu data structures. */ pv_ops.irq.save_fl =__PV_IS_CALLEE_SAVE (xen_save_fl_direct); pv_ops.irq.restore_fl =__PV_IS_CALLEE_SAVE (xen_restore_fl_direct);
@@ -1007,6 +1008,7 @@ void __init xen_setup_vcpu_info_placement(void)__PV_IS_CALLEE_SAVE (xen_irq_enable_direct); pv_ops.mmu.read_cr2 = xen_read_cr2_direct; } +#endif } static const struct pv_info xen_info __initconst = {
arch/x86/xen/irq.c +55 -14
129 lines not on this page · raw message
arch/x86/xen/smp_pv.c +11 -0
@@ -343,6 +343,17 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)#else ctxt->gs_base_kernel =per_cpu_offset (cpu);#endif +/* +* We setup an upcall handler only for the default xenhost. The remote +* xenhost will generate evtchn events, but an additional callback would be +* quite hairy, since we would have VCPU state initialised in multiple +* hypervisors and issues like re-entrancy of upcalls. +* +* It would be simpler if the callback from L0-Xen could be bounced +* bounced via L1-Xen. This also simplifies the pv_irq_ops code +* because now the CPU's IF processing only needs to happen on +* xh_default->vcpu_info. +*/ ctxt->event_callback_eip = (unsigned long )xen_hypervisor_callback; ctxt->failsafe_callback_eip =
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 08/16] x86/xen: irq/upcall handling with multiple xenhosts
Quoted 10 lines · Ankur Arora
For configurations with multiple xenhosts, we need to handle events generated from multiple xenhosts.
Having more than one upcall handler might be quite hairy, and it would be simpler if the callback from L0-Xen could be bounced via L1-Xen. This will also mean simpler
pv_irq_opscode because now the IF flag maps onto thexh_default->vcpu_info->evtchn_upcall_mask.However, we still update the
xh_remote->vcpu_info->evtchn_upcall_maskon a best effort basis to minimize unnecessary work in remote xenhost.
This is another design decision yet to be taken.
My current prefernce is L1 Xen mapping events from L0 to L1 guest events.
Juergen
RFC PATCH 9/16 xen/evtchn: support evtchn in xenhost_t
In reply to Ankur AroraLargely mechanical patch that adds a new param, xenhost_t * to the evtchn interfaces. The evtchn port instead of being domain unique, is now scoped to xenhost_t.
As part of upcall handling we now look at all the xenhosts and, for evtchn_2l, the xenhost's shared_info and vcpu_info. Other than this event handling is largley unchanged.
Note that the IPI, timer, VIRQ, FUNCTION, PMU etc vectors remain attached to xh_default. Only interdomain evtchns are allowable as xh_remote.
TODO:
- to minimize the changes, evtchn FIFO is disabled for now.
--- arch/x86/pci/xen.c | 16 +- arch/x86/xen/enlighten_hvm.c | 2 +- arch/x86/xen/irq.c | 2 +- arch/x86/xen/smp.c | 16 +- arch/x86/xen/smp_pv.c | 4 +- arch/x86/xen/time.c | 5 +- arch/x86/xen/xen-ops.h | 1 + arch/x86/xen/xenhost.c | 16 + drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 2 +- drivers/input/misc/xen-kbdfront.c | 2 +- drivers/net/xen-netback/interface.c | 8 +- drivers/net/xen-netfront.c | 6 +- drivers/pci/xen-pcifront.c | 2 +- drivers/xen/acpi.c | 2 + drivers/xen/balloon.c | 2 +- drivers/xen/events/Makefile | 1 - drivers/xen/events/events_2l.c | 188 +++++----- drivers/xen/events/events_base.c | 379 ++++++++++++--------- drivers/xen/events/events_fifo.c | 2 +- drivers/xen/events/events_internal.h | 78 ++--- drivers/xen/evtchn.c | 22 +- drivers/xen/fallback.c | 1 + drivers/xen/gntalloc.c | 8 +- drivers/xen/gntdev.c | 8 +- drivers/xen/mcelog.c | 2 +- drivers/xen/pcpu.c | 2 +- drivers/xen/preempt.c | 1 + drivers/xen/privcmd.c | 1 + drivers/xen/sys-hypervisor.c | 2 +- drivers/xen/time.c | 2 +- drivers/xen/xen-pciback/xenbus.c | 2 +- drivers/xen/xen-scsiback.c | 5 +- drivers/xen/xenbus/xenbus_client.c | 2 +- drivers/xen/xenbus/xenbus_comms.c | 6 +- drivers/xen/xenbus/xenbus_probe.c | 1 + drivers/xen/xenbus/xenbus_probe_backend.c | 1 + drivers/xen/xenbus/xenbus_probe_frontend.c | 1 + drivers/xen/xenbus/xenbus_xs.c | 1 + include/xen/events.h | 45 +-- include/xen/xenhost.h | 17 + 41 files changed, 483 insertions(+), 383 deletions(-)
arch/x86/pci/xen.c +9 -7
@@ -19,6 +19,8 @@#include <asm/pci_x86.h> #include <asm/xen/hypervisor.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h>
@@ -46,7 +48,7 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev)if (gsi <nr_legacy_irqs ()) share =0 ; - rc =xen_bind_pirq_gsi_to_irq (gsi, pirq, share,"pcifront" ); + rc =xen_bind_pirq_gsi_to_irq (xh_default, gsi, pirq, share,"pcifront" );if (rc <0 ) {dev_warn (&dev->dev,"Xen PCI: failed to bind GSI%d (PIRQ%d) to IRQ: %d\n" , gsi, pirq, rc);
@@ -96,7 +98,7 @@ static int xen_register_pirq(u32 gsi, int gsi_override, int triggering,if (gsi_override >=0 ) gsi = gsi_override; - irq =xen_bind_pirq_gsi_to_irq (gsi, map_irq.pirq, shareable, name); + irq =xen_bind_pirq_gsi_to_irq (xh_default, gsi, map_irq.pirq, shareable, name);if (irq <0 ) goto out;
@@ -180,7 +182,7 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) goto error; i =0 ;for_each_pci_msi_entry (msidesc, dev) { - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, v[i], + irq = xen_bind_pirq_msi_to_irq(xh_default, dev, msidesc, v[i], (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "pcifront-msi-x" :
@@ -234,7 +236,7 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)return 1 ;for_each_pci_msi_entry (msidesc, dev) { - pirq =xen_allocate_pirq_msi (dev, msidesc); + pirq =xen_allocate_pirq_msi (xh_default, dev, msidesc);if (pirq <0 ) { irq = -ENODEV ; goto error;
@@ -242,7 +244,7 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)xen_msi_compose_msg (dev, pirq, &msg);__pci_write_msi_msg (msidesc, &msg);dev_dbg (&dev->dev,"xen: msi bound to pirq=%d\n" , pirq); - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, pirq, + irq = xen_bind_pirq_msi_to_irq(xh_default, dev, msidesc, pirq, (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "msi-x" : "msi",
@@ -337,7 +339,7 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) goto out; } - ret =xen_bind_pirq_msi_to_irq (dev, msidesc, map_irq.pirq, + ret =xen_bind_pirq_msi_to_irq (xh_default, dev, msidesc, map_irq.pirq, (type ==PCI_CAP_ID_MSI ) ? nvec :1 , (type ==PCI_CAP_ID_MSIX ) ?"msi-x" :"msi" , domid);
@@ -496,7 +498,7 @@ int __init pci_xen_initial_domain(void) }if (0 == nr_ioapics) {for (irq =0 ; irq <nr_legacy_irqs (); irq++) -xen_bind_pirq_gsi_to_irq (irq, irq,0 ,"xt-pic" ); +xen_bind_pirq_gsi_to_irq (xh_default, irq, irq,0 ,"xt-pic" ); }return 0 ; }
arch/x86/xen/enlighten_hvm.c +1 -1
@@ -266,7 +266,7 @@ static void __init xen_hvm_guest_init(void)xen_hvm_smp_init ();WARN_ON (xen_cpuhp_setup (xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));xen_unplug_emulated_devices (); - x86_init.irqs.intr_init = xen_init_IRQ; + x86_init.irqs.intr_init = xenhost_init_IRQ;xen_hvm_init_time_ops ();xen_hvm_init_mmu_ops ();
arch/x86/xen/irq.c +1 -1
@@ -170,5 +170,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {void __init xen_init_irq_ops (void ) { pv_ops.irq = xen_irq_ops; - x86_init.irqs.intr_init = xen_init_IRQ; + x86_init.irqs.intr_init = xenhost_init_IRQ; }
arch/x86/xen/smp.c +8 -8
@@ -66,7 +66,7 @@ int xen_smp_intr_init(unsigned int cpu)char *resched_name, *callfunc_name, *debug_name; resched_name =kasprintf (GFP_KERNEL ,"resched%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_RESCHEDULE_VECTOR, cpu, xen_reschedule_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -78,7 +78,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_resched_irq, cpu).name = resched_name; callfunc_name =kasprintf (GFP_KERNEL ,"callfunc%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_CALL_FUNCTION_VECTOR, cpu, xen_call_function_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -90,7 +90,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_callfunc_irq, cpu).name = callfunc_name; debug_name =kasprintf (GFP_KERNEL ,"debug%d" , cpu); - rc =bind_virq_to_irqhandler (VIRQ_DEBUG , cpu, xen_debug_interrupt, + rc =bind_virq_to_irqhandler (xh_default,VIRQ_DEBUG , cpu, xen_debug_interrupt,IRQF_PERCPU |IRQF_NOBALANCING , debug_name,NULL );if (rc <0 )
@@ -99,7 +99,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_debug_irq, cpu).name = debug_name; callfunc_name =kasprintf (GFP_KERNEL ,"callfuncsingle%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_CALL_FUNCTION_SINGLE_VECTOR, cpu, xen_call_function_single_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -155,7 +155,7 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)void xen_smp_send_reschedule (int cpu) { -xen_send_IPI_one (cpu,XEN_RESCHEDULE_VECTOR ); +xen_send_IPI_one (xh_default, cpu,XEN_RESCHEDULE_VECTOR ); } static void __xen_send_IPI_mask(const struct cpumask *mask,
@@ -164,7 +164,7 @@ static void __xen_send_IPI_mask(const struct cpumask *mask,unsigned cpu;for_each_cpu_and (cpu, mask, cpu_online_mask) -xen_send_IPI_one (cpu, vector); +xen_send_IPI_one (xh_default, cpu, vector); }void xen_smp_send_call_function_ipi (const struct cpumask *mask)
@@ -242,7 +242,7 @@ void xen_send_IPI_self(int vector)int xen_vector =xen_map_vector (vector);if (xen_vector >=0 ) -xen_send_IPI_one (smp_processor_id (), xen_vector); +xen_send_IPI_one (xh_default,smp_processor_id (), xen_vector); } void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
@@ -259,7 +259,7 @@ void xen_send_IPI_mask_allbutself(const struct cpumask *mask,if (this_cpu == cpu)continue ; -xen_send_IPI_one (cpu, xen_vector); +xen_send_IPI_one (xh_default, cpu, xen_vector); } }
arch/x86/xen/smp_pv.c +2 -2
@@ -116,7 +116,7 @@ int xen_smp_intr_init_pv(unsigned int cpu)char *callfunc_name, *pmu_name; callfunc_name =kasprintf (GFP_KERNEL ,"irqwork%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_IRQ_WORK_VECTOR, cpu, xen_irq_work_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -129,7 +129,7 @@ int xen_smp_intr_init_pv(unsigned int cpu)if (is_xen_pmu (cpu)) { pmu_name =kasprintf (GFP_KERNEL ,"pmu%d" , cpu); - rc =bind_virq_to_irqhandler (VIRQ_XENPMU , cpu, + rc =bind_virq_to_irqhandler (xh_default,VIRQ_XENPMU , cpu, xen_pmu_irq_handler,IRQF_PERCPU |IRQF_NOBALANCING , pmu_name,NULL );
arch/x86/xen/time.c +3 -2
@@ -340,11 +340,12 @@ void xen_setup_timer(int cpu)snprintf (xevt->name,sizeof (xevt->name),"timer%d" , cpu); - irq =bind_virq_to_irqhandler (VIRQ_TIMER , cpu, xen_timer_interrupt, + irq =bind_virq_to_irqhandler (xh_default, +VIRQ_TIMER , cpu, xen_timer_interrupt,IRQF_PERCPU |IRQF_NOBALANCING |IRQF_TIMER |IRQF_FORCE_RESUME |IRQF_EARLY_RESUME , xevt->name,NULL ); - (void )xen_set_irq_priority (irq,XEN_IRQ_PRIORITY_MAX ); + (void )xen_set_irq_priority (xh_default, irq,XEN_IRQ_PRIORITY_MAX );memcpy (evt, xen_clockevent,sizeof (*evt));
arch/x86/xen/xen-ops.h +1 -0
@@ -78,6 +78,7 @@ extern int xen_have_vcpu_info_placement;int xen_vcpu_setup (xenhost_t *xh,int cpu);void xen_vcpu_info_reset (xenhost_t *xh,int cpu);void xen_setup_vcpu_info_placement (void ); +void xenhost_init_IRQ (void );#ifdef CONFIG_SMP void xen_smp_init (void );
arch/x86/xen/xenhost.c +16 -0
@@ -2,6 +2,7 @@#include <linux/bug.h> #include <xen/xen.h> #include <xen/xenhost.h> +#include <xen/events.h> #include "xen-ops.h" /*
@@ -84,3 +85,18 @@ void __xenhost_unregister(enum xenhost_type type)BUG (); } } + +void xenhost_init_IRQ (void ) +{ +xenhost_t **xh; +/* +* xenhost_init_IRQ is called via x86_init.irq.intr_init(). +* For xenhost_r1 and xenhost_r2, the underlying state is +* ready so we can go ahead and init both the variants. +* +* xenhost_r0, might be implemented via a loadable module +* so that would do this initialization explicitly. +*/ +for_each_xenhost (xh) +xen_init_IRQ (*xh); +}
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -228,7 +228,7 @@ static int xen_blkif_map(struct xen_blkif_ring *ring, grant_ref_t *gref,BUG (); } - err =bind_interdomain_evtchn_to_irqhandler (blkif->domid, evtchn, + err =bind_interdomain_evtchn_to_irqhandler (xh_default, blkif->domid, evtchn, xen_blkif_be_int,0 ,"blkif-backend" , ring);if (err <0 ) {
drivers/block/xen-blkfront.c +1 -1
@@ -1700,7 +1700,7 @@ static int setup_blkring(struct xenbus_device *dev,if (err) goto fail; - err =bind_evtchn_to_irqhandler (rinfo->evtchn, blkif_interrupt,0 , + err =bind_evtchn_to_irqhandler (xh_default, rinfo->evtchn, blkif_interrupt,0 ,"blkif" , rinfo);if (err <=0 ) { xenbus_dev_fatal(dev, err,
drivers/input/misc/xen-kbdfront.c +1 -1
@@ -435,7 +435,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, ret =xenbus_alloc_evtchn (dev, &evtchn);if (ret) goto error_grant; - ret =bind_evtchn_to_irqhandler (evtchn, input_handler, + ret =bind_evtchn_to_irqhandler (xh_default, evtchn, input_handler,0 , dev->devicetype, info);if (ret <0 ) {xenbus_dev_fatal (dev, ret,"bind_evtchn_to_irqhandler" );
drivers/net/xen-netback/interface.c +4 -4
@@ -588,7 +588,7 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref, shared = (struct xen_netif_ctrl_sring *)addr;BACK_RING_INIT (&vif->ctrl, shared,XEN_PAGE_SIZE ); - err =bind_interdomain_evtchn_to_irq (vif->domid, evtchn); + err =bind_interdomain_evtchn_to_irq (xh_default, vif->domid, evtchn);if (err <0 ) goto err_unmap;
@@ -646,7 +646,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,if (tx_evtchn == rx_evtchn) {/* feature-split-event-channels == 0 */ - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, tx_evtchn, xenvif_interrupt,0 , queue->name, queue);if (err <0 )
@@ -657,7 +657,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,/* feature-split-event-channels == 1 */ snprintf (queue->tx_irq_name,sizeof (queue->tx_irq_name),"%s-tx" , queue->name); - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, tx_evtchn, xenvif_tx_interrupt,0 , queue->tx_irq_name, queue);if (err <0 )
@@ -667,7 +667,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,snprintf (queue->rx_irq_name,sizeof (queue->rx_irq_name),"%s-rx" , queue->name); - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, rx_evtchn, xenvif_rx_interrupt,0 , queue->rx_irq_name, queue);if (err <0 )
drivers/net/xen-netfront.c +3 -3
@@ -1468,7 +1468,7 @@ static int setup_netfront_single(struct netfront_queue *queue)if (err <0 ) goto fail; - err =bind_evtchn_to_irqhandler (queue->tx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->tx_evtchn, xennet_interrupt,0 , queue->info->netdev->name, queue);if (err <0 )
@@ -1498,7 +1498,7 @@ static int setup_netfront_split(struct netfront_queue *queue)snprintf (queue->tx_irq_name,sizeof (queue->tx_irq_name),"%s-tx" , queue->name); - err =bind_evtchn_to_irqhandler (queue->tx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->tx_evtchn, xennet_tx_interrupt,0 , queue->tx_irq_name, queue);if (err <0 )
@@ -1507,7 +1507,7 @@ static int setup_netfront_split(struct netfront_queue *queue)snprintf (queue->rx_irq_name,sizeof (queue->rx_irq_name),"%s-rx" , queue->name); - err =bind_evtchn_to_irqhandler (queue->rx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->rx_evtchn, xennet_rx_interrupt,0 , queue->rx_irq_name, queue);if (err <0 )
drivers/pci/xen-pcifront.c +1 -1
@@ -800,7 +800,7 @@ static int pcifront_publish_info(struct pcifront_device *pdev)if (err) goto out; - err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, + err =bind_evtchn_to_irqhandler (xh_default, pdev->evtchn, pcifront_handler_aer,0 ,"pcifront" , pdev);if (err <0 )
drivers/xen/acpi.c +2 -0
@@ -30,6 +30,8 @@* IN THE SOFTWARE. */ +#include <linux/types.h> +#include <xen/interface/xen.h> #include <xen/acpi.h> #include <xen/interface/platform.h> #include <asm/xen/hypercall.h>
drivers/xen/balloon.c +1 -1
@@ -62,11 +62,11 @@#include <asm/pgtable.h> #include <asm/tlb.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/xen.h> -#include <xen/interface/xen.h> #include <xen/interface/memory.h> #include <xen/balloon.h> #include <xen/features.h>
drivers/xen/events/Makefile +0 -1
@@ -2,4 +2,3 @@ obj-y += events.o events-y += events_base.o events-y += events_2l.o -events-y += events_fifo.o
drivers/xen/events/events_2l.c +97 -91
334 lines not on this page · raw message
drivers/xen/events/events_base.c +211 -168
1,095 lines not on this page · raw message
drivers/xen/events/events_fifo.c +1 -1
@@ -324,7 +324,7 @@ static void consume_one_event(unsigned cpu, q->head[priority] = head; } -static void __evtchn_fifo_handle_events (unsigned cpu,bool drop) +static void __evtchn_fifo_handle_events (xenhost_t *xh,unsigned cpu,bool drop) {struct evtchn_fifo_control_block *control_block;unsigned long ready;
drivers/xen/events/events_internal.h +40 -38
146 lines not on this page · raw message
drivers/xen/evtchn.c +11 -11
@@ -292,7 +292,7 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf, evtchn =find_evtchn (u, port);if (evtchn && !evtchn->enabled) { evtchn->enabled = true; -enable_irq (irq_from_evtchn (port)); +enable_irq (irq_from_evtchn (xh_default, port)); } }
@@ -392,18 +392,18 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)if (rc <0 ) goto err; - rc =bind_evtchn_to_irqhandler (port, evtchn_interrupt,0 , + rc =bind_evtchn_to_irqhandler (xh_default, port, evtchn_interrupt,0 , u->name, evtchn);if (rc <0 ) goto err; - rc =evtchn_make_refcounted (port); + rc =evtchn_make_refcounted (xh_default, port);return rc; err:/* bind failed, should close the port now */ close.port = port; -if (HYPERVISOR_event_channel_op (EVTCHNOP_close, &close) !=0 ) +if (hypervisor_event_channel_op (xh_default, EVTCHNOP_close, &close) !=0 )BUG ();del_evtchn (u, evtchn);return rc;
@@ -412,7 +412,7 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)static void evtchn_unbind_from_user (struct per_user_data *u,struct user_evtchn *evtchn) { -int irq =irq_from_evtchn (evtchn->port); +int irq =irq_from_evtchn (xh_default, evtchn->port);BUG_ON (irq <0 );
@@ -429,7 +429,7 @@ static void evtchn_bind_interdom_next_vcpu(int evtchn)struct irq_desc *desc;unsigned long flags; - irq =irq_from_evtchn (evtchn); + irq =irq_from_evtchn (xh_default, evtchn); desc =irq_to_desc (irq);if (!desc)
@@ -447,7 +447,7 @@ static void evtchn_bind_interdom_next_vcpu(int evtchn)this_cpu_write (bind_last_selected_cpu, selected_cpu);/* unmask expects irqs to be disabled */ -xen_rebind_evtchn_to_cpu (evtchn, selected_cpu); +xen_rebind_evtchn_to_cpu (xh_default, evtchn, selected_cpu);raw_spin_unlock_irqrestore (&desc->lock, flags); }
@@ -549,7 +549,7 @@ static long evtchn_ioctl(struct file *file,break ; rc = -EINVAL ; -if (unbind.port >=xen_evtchn_nr_channels ()) +if (unbind.port >=xen_evtchn_nr_channels (xh_default))break ; rc = -ENOTCONN ;
@@ -557,7 +557,7 @@ static long evtchn_ioctl(struct file *file,if (!evtchn)break ; -disable_irq (irq_from_evtchn (unbind.port)); +disable_irq (irq_from_evtchn (xh_default, unbind.port));evtchn_unbind_from_user (u, evtchn); rc =0 ;break ;
@@ -574,7 +574,7 @@ static long evtchn_ioctl(struct file *file, rc = -ENOTCONN ; evtchn =find_evtchn (u, notify.port);if (evtchn) { -notify_remote_via_evtchn (notify.port); +notify_remote_via_evtchn (xh_default, notify.port); rc =0 ; }break ;
@@ -676,7 +676,7 @@ static int evtchn_release(struct inode *inode, struct file *filp)struct user_evtchn *evtchn; evtchn = rb_entry(node, struct user_evtchn, node); -disable_irq (irq_from_evtchn (evtchn->port)); +disable_irq (irq_from_evtchn (xh_default, evtchn->port));evtchn_unbind_from_user (u, evtchn); }
drivers/xen/fallback.c +1 -0
@@ -2,6 +2,7 @@#include <linux/string.h> #include <linux/bug.h> #include <linux/export.h> +#include <xen/interface/xen.h> #include <asm/hypervisor.h> #include <asm/xen/hypercall.h>
drivers/xen/gntalloc.c +4 -4
@@ -189,8 +189,8 @@ static void __del_gref(struct gntalloc_gref *gref)kunmap (gref->page); }if (gref->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) { -notify_remote_via_evtchn (gref->notify.event); -evtchn_put (gref->notify.event); +notify_remote_via_evtchn (xh_default, gref->notify.event); +evtchn_put (xh_default, gref->notify.event); } gref->notify.flags =0 ;
@@ -418,14 +418,14 @@ static long gntalloc_ioctl_unmap_notify(struct gntalloc_file_private_data *priv,* reference to that event channel. */ if (op.action &UNMAP_NOTIFY_SEND_EVENT ) { -if (evtchn_get (op.event_channel_port)) { +if (evtchn_get (xh_default, op.event_channel_port)) { rc = -EINVAL ; goto unlock_out; } }if (gref->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) -evtchn_put (gref->notify.event); +evtchn_put (xh_default, gref->notify.event); gref->notify.flags = op.action; gref->notify.pgoff = pgoff;
drivers/xen/gntdev.c +4 -4
@@ -247,8 +247,8 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)atomic_sub (map->count, &pages_mapped);if (map->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) { -notify_remote_via_evtchn (map->notify.event); -evtchn_put (map->notify.event); +notify_remote_via_evtchn (xh_default, map->notify.event); +evtchn_put (xh_default, map->notify.event); }if (populate_freeable_maps && priv) {
@@ -790,7 +790,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u)* reference to that event channel. */ if (op.action &UNMAP_NOTIFY_SEND_EVENT ) { -if (evtchn_get (op.event_channel_port)) +if (evtchn_get (xh_default, op.event_channel_port))return -EINVAL ; }
@@ -829,7 +829,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u)/* Drop the reference to the event channel we did not save in the map */ if (out_flags &UNMAP_NOTIFY_SEND_EVENT ) -evtchn_put (out_event); +evtchn_put (xh_default, out_event);return rc; }
drivers/xen/mcelog.c +1 -1
@@ -378,7 +378,7 @@ static int bind_virq_for_mce(void)return ret; } - ret =bind_virq_to_irqhandler (VIRQ_MCA ,0 , + ret =bind_virq_to_irqhandler (xh_default,VIRQ_MCA ,0 , xen_mce_interrupt,0 ,"mce" ,NULL );if (ret <0 ) {pr_err ("Failed to bind virq\n" );
drivers/xen/pcpu.c +1 -1
@@ -387,7 +387,7 @@ static int __init xen_pcpu_init(void)if (!xen_initial_domain ())return -ENODEV ; - irq =bind_virq_to_irqhandler (VIRQ_PCPU_STATE ,0 , + irq =bind_virq_to_irqhandler (xh_default,VIRQ_PCPU_STATE ,0 , xen_pcpu_interrupt,0 ,"xen-pcpu" ,NULL );if (irq <0 ) {
drivers/xen/preempt.c +1 -0
@@ -10,6 +10,7 @@*/ #include <linux/sched.h> +#include <xen/interface/xen.h> #include <xen/xen-ops.h> #ifndef CONFIG_PREEMPT
drivers/xen/privcmd.c +1 -0
@@ -27,6 +27,7 @@#include <asm/pgalloc.h> #include <asm/pgtable.h> #include <asm/tlb.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
drivers/xen/sys-hypervisor.c +1 -1
@@ -13,12 +13,12 @@#include <linux/kobject.h> #include <linux/err.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/xen.h> #include <xen/xenbus.h> -#include <xen/interface/xen.h> #include <xen/interface/version.h> #ifdef CONFIG_XEN_HAVE_VPMU #include <xen/interface/xenpmu.h>
drivers/xen/time.c +1 -1
@@ -8,13 +8,13 @@#include <linux/gfp.h> #include <linux/slab.h> +#include <xen/interface/xen.h> #include <asm/paravirt.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/events.h> #include <xen/features.h> -#include <xen/interface/xen.h> #include <xen/interface/vcpu.h> #include <xen/xen-ops.h>
drivers/xen/xen-pciback/xenbus.c +1 -1
@@ -123,7 +123,7 @@ static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref, pdev->sh_info = vaddr; - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, pdev->xdev->otherend_id, remote_evtchn, xen_pcibk_handle_event,0 ,DRV_NAME , pdev);if (err <0 ) {
drivers/xen/xen-scsiback.c +3 -2
@@ -54,8 +54,9 @@#include <target/target_core_base.h> #include <target/target_core_fabric.h> + +#include <xen/interface/xen.h> #include <asm/hypervisor.h> -#include <xen/xen.h> #include <xen/balloon.h> #include <xen/events.h>
@@ -829,7 +830,7 @@ static int scsiback_init_sring(struct vscsibk_info *info, grant_ref_t ring_ref, sring = (struct vscsiif_sring *)area;BACK_RING_INIT (&info->ring, sring,PAGE_SIZE ); - err =bind_interdomain_evtchn_to_irq (info->domid, evtchn); + err =bind_interdomain_evtchn_to_irq (xh_default, info->domid, evtchn);if (err <0 ) goto unmap_page;
drivers/xen/xenbus/xenbus_client.c +1 -1
@@ -36,9 +36,9 @@#include <linux/spinlock.h> #include <linux/vmalloc.h> #include <linux/export.h> -#include <asm/xen/hypervisor.h> #include <xen/page.h> #include <xen/interface/xen.h> +#include <asm/xen/hypervisor.h> #include <xen/interface/event_channel.h> #include <xen/balloon.h> #include <xen/events.h>
drivers/xen/xenbus/xenbus_comms.c +3 -3
@@ -151,7 +151,7 @@ static int xb_write(const void *data, unsigned int len)/* Implies mb(): other side will see the updated producer. */ if (prod <= intf->req_cons) -notify_remote_via_evtchn (xen_store_evtchn); +notify_remote_via_evtchn (xh_default, xen_store_evtchn); }return bytes;
@@ -204,7 +204,7 @@ static int xb_read(void *data, unsigned int len)/* Implies mb(): other side will see the updated consumer. */ if (intf->rsp_prod - cons >=XENSTORE_RING_SIZE ) -notify_remote_via_evtchn (xen_store_evtchn); +notify_remote_via_evtchn (xh_default, xen_store_evtchn); }return bytes;
@@ -461,7 +461,7 @@ int xb_init_comms(void) }else {int err; - err =bind_evtchn_to_irqhandler (xen_store_evtchn, wake_waiting, + err =bind_evtchn_to_irqhandler (xh_default, xen_store_evtchn, wake_waiting,0 ,"xenbus" , &xb_waitq);if (err <0 ) {pr_err ("request irq failed %i\n" , err);
drivers/xen/xenbus/xenbus_probe.c +1 -0
@@ -52,6 +52,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xen.h>
drivers/xen/xenbus/xenbus_probe_backend.c +1 -0
@@ -48,6 +48,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/hypervisor.h> #include <xen/xenbus.h>
drivers/xen/xenbus/xenbus_probe_frontend.c +1 -0
@@ -19,6 +19,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xenbus.h> #include <xen/events.h>
drivers/xen/xenbus/xenbus_xs.c +1 -0
@@ -46,6 +46,7 @@#include <linux/reboot.h> #include <linux/rwsem.h> #include <linux/mutex.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xenbus.h> #include <xen/xen.h>
include/xen/events.h +24 -21
100 lines not on this page · raw message
include/xen/xenhost.h +17 -0
@@ -112,6 +112,23 @@ typedef struct {*/ uint32_t xen_vcpu_id[NR_CPUS ]; }; + +/* +* evtchn: get init'd via x86_init.irqs.intr_init (xen_init_IRQ()). +* +* The common functionality for xenhost_* provided by xen_init_IRQ() +* is the mapping between evtchn <-> irq. +* +* For all three of xenhost_r0/r1 and r2, post-init the evtchn logic +* should just work using the evtchn_to_irq mapping and the vcpu_info, +* shared_info state. +* (Plus some state private to evtchn_2l/evtchn_fifo which for now +* is defined locally.) +*/ +struct { +const struct evtchn_ops *evtchn_ops; +int **evtchn_to_irq; + }; } xenhost_t; typedef struct xenhost_ops {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 9/16 xen/evtchn: support evtchn in xenhost_t
In reply to Ankur AroraLargely mechanical patch that adds a new param, xenhost_t * to the evtchn interfaces. The evtchn port instead of being domain unique, is now scoped to xenhost_t.
As part of upcall handling we now look at all the xenhosts and, for evtchn_2l, the xenhost's shared_info and vcpu_info. Other than this event handling is largley unchanged.
Note that the IPI, timer, VIRQ, FUNCTION, PMU etc vectors remain attached to xh_default. Only interdomain evtchns are allowable as xh_remote.
TODO:
- to minimize the changes, evtchn FIFO is disabled for now.
--- arch/x86/pci/xen.c | 16 +- arch/x86/xen/enlighten_hvm.c | 2 +- arch/x86/xen/irq.c | 2 +- arch/x86/xen/smp.c | 16 +- arch/x86/xen/smp_pv.c | 4 +- arch/x86/xen/time.c | 5 +- arch/x86/xen/xen-ops.h | 1 + arch/x86/xen/xenhost.c | 16 + drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 2 +- drivers/input/misc/xen-kbdfront.c | 2 +- drivers/net/xen-netback/interface.c | 8 +- drivers/net/xen-netfront.c | 6 +- drivers/pci/xen-pcifront.c | 2 +- drivers/xen/acpi.c | 2 + drivers/xen/balloon.c | 2 +- drivers/xen/events/Makefile | 1 - drivers/xen/events/events_2l.c | 188 +++++----- drivers/xen/events/events_base.c | 379 ++++++++++++--------- drivers/xen/events/events_fifo.c | 2 +- drivers/xen/events/events_internal.h | 78 ++--- drivers/xen/evtchn.c | 22 +- drivers/xen/fallback.c | 1 + drivers/xen/gntalloc.c | 8 +- drivers/xen/gntdev.c | 8 +- drivers/xen/mcelog.c | 2 +- drivers/xen/pcpu.c | 2 +- drivers/xen/preempt.c | 1 + drivers/xen/privcmd.c | 1 + drivers/xen/sys-hypervisor.c | 2 +- drivers/xen/time.c | 2 +- drivers/xen/xen-pciback/xenbus.c | 2 +- drivers/xen/xen-scsiback.c | 5 +- drivers/xen/xenbus/xenbus_client.c | 2 +- drivers/xen/xenbus/xenbus_comms.c | 6 +- drivers/xen/xenbus/xenbus_probe.c | 1 + drivers/xen/xenbus/xenbus_probe_backend.c | 1 + drivers/xen/xenbus/xenbus_probe_frontend.c | 1 + drivers/xen/xenbus/xenbus_xs.c | 1 + include/xen/events.h | 45 +-- include/xen/xenhost.h | 17 + 41 files changed, 483 insertions(+), 383 deletions(-)
arch/x86/pci/xen.c +9 -7
@@ -19,6 +19,8 @@#include <asm/pci_x86.h> #include <asm/xen/hypervisor.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/features.h> #include <xen/events.h>
@@ -46,7 +48,7 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev)if (gsi <nr_legacy_irqs ()) share =0 ; - rc =xen_bind_pirq_gsi_to_irq (gsi, pirq, share,"pcifront" ); + rc =xen_bind_pirq_gsi_to_irq (xh_default, gsi, pirq, share,"pcifront" );if (rc <0 ) {dev_warn (&dev->dev,"Xen PCI: failed to bind GSI%d (PIRQ%d) to IRQ: %d\n" , gsi, pirq, rc);
@@ -96,7 +98,7 @@ static int xen_register_pirq(u32 gsi, int gsi_override, int triggering,if (gsi_override >=0 ) gsi = gsi_override; - irq =xen_bind_pirq_gsi_to_irq (gsi, map_irq.pirq, shareable, name); + irq =xen_bind_pirq_gsi_to_irq (xh_default, gsi, map_irq.pirq, shareable, name);if (irq <0 ) goto out;
@@ -180,7 +182,7 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) goto error; i =0 ;for_each_pci_msi_entry (msidesc, dev) { - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, v[i], + irq = xen_bind_pirq_msi_to_irq(xh_default, dev, msidesc, v[i], (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "pcifront-msi-x" :
@@ -234,7 +236,7 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)return 1 ;for_each_pci_msi_entry (msidesc, dev) { - pirq =xen_allocate_pirq_msi (dev, msidesc); + pirq =xen_allocate_pirq_msi (xh_default, dev, msidesc);if (pirq <0 ) { irq = -ENODEV ; goto error;
@@ -242,7 +244,7 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)xen_msi_compose_msg (dev, pirq, &msg);__pci_write_msi_msg (msidesc, &msg);dev_dbg (&dev->dev,"xen: msi bound to pirq=%d\n" , pirq); - irq = xen_bind_pirq_msi_to_irq(dev, msidesc, pirq, + irq = xen_bind_pirq_msi_to_irq(xh_default, dev, msidesc, pirq, (type == PCI_CAP_ID_MSI) ? nvec : 1, (type == PCI_CAP_ID_MSIX) ? "msi-x" : "msi",
@@ -337,7 +339,7 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) goto out; } - ret =xen_bind_pirq_msi_to_irq (dev, msidesc, map_irq.pirq, + ret =xen_bind_pirq_msi_to_irq (xh_default, dev, msidesc, map_irq.pirq, (type ==PCI_CAP_ID_MSI ) ? nvec :1 , (type ==PCI_CAP_ID_MSIX ) ?"msi-x" :"msi" , domid);
@@ -496,7 +498,7 @@ int __init pci_xen_initial_domain(void) }if (0 == nr_ioapics) {for (irq =0 ; irq <nr_legacy_irqs (); irq++) -xen_bind_pirq_gsi_to_irq (irq, irq,0 ,"xt-pic" ); +xen_bind_pirq_gsi_to_irq (xh_default, irq, irq,0 ,"xt-pic" ); }return 0 ; }
arch/x86/xen/enlighten_hvm.c +1 -1
@@ -266,7 +266,7 @@ static void __init xen_hvm_guest_init(void)xen_hvm_smp_init ();WARN_ON (xen_cpuhp_setup (xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));xen_unplug_emulated_devices (); - x86_init.irqs.intr_init = xen_init_IRQ; + x86_init.irqs.intr_init = xenhost_init_IRQ;xen_hvm_init_time_ops ();xen_hvm_init_mmu_ops ();
arch/x86/xen/irq.c +1 -1
@@ -170,5 +170,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {void __init xen_init_irq_ops (void ) { pv_ops.irq = xen_irq_ops; - x86_init.irqs.intr_init = xen_init_IRQ; + x86_init.irqs.intr_init = xenhost_init_IRQ; }
arch/x86/xen/smp.c +8 -8
@@ -66,7 +66,7 @@ int xen_smp_intr_init(unsigned int cpu)char *resched_name, *callfunc_name, *debug_name; resched_name =kasprintf (GFP_KERNEL ,"resched%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_RESCHEDULE_VECTOR, cpu, xen_reschedule_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -78,7 +78,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_resched_irq, cpu).name = resched_name; callfunc_name =kasprintf (GFP_KERNEL ,"callfunc%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_CALL_FUNCTION_VECTOR, cpu, xen_call_function_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -90,7 +90,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_callfunc_irq, cpu).name = callfunc_name; debug_name =kasprintf (GFP_KERNEL ,"debug%d" , cpu); - rc =bind_virq_to_irqhandler (VIRQ_DEBUG , cpu, xen_debug_interrupt, + rc =bind_virq_to_irqhandler (xh_default,VIRQ_DEBUG , cpu, xen_debug_interrupt,IRQF_PERCPU |IRQF_NOBALANCING , debug_name,NULL );if (rc <0 )
@@ -99,7 +99,7 @@ int xen_smp_intr_init(unsigned int cpu)per_cpu (xen_debug_irq, cpu).name = debug_name; callfunc_name =kasprintf (GFP_KERNEL ,"callfuncsingle%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_CALL_FUNCTION_SINGLE_VECTOR, cpu, xen_call_function_single_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -155,7 +155,7 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)void xen_smp_send_reschedule (int cpu) { -xen_send_IPI_one (cpu,XEN_RESCHEDULE_VECTOR ); +xen_send_IPI_one (xh_default, cpu,XEN_RESCHEDULE_VECTOR ); } static void __xen_send_IPI_mask(const struct cpumask *mask,
@@ -164,7 +164,7 @@ static void __xen_send_IPI_mask(const struct cpumask *mask,unsigned cpu;for_each_cpu_and (cpu, mask, cpu_online_mask) -xen_send_IPI_one (cpu, vector); +xen_send_IPI_one (xh_default, cpu, vector); }void xen_smp_send_call_function_ipi (const struct cpumask *mask)
@@ -242,7 +242,7 @@ void xen_send_IPI_self(int vector)int xen_vector =xen_map_vector (vector);if (xen_vector >=0 ) -xen_send_IPI_one (smp_processor_id (), xen_vector); +xen_send_IPI_one (xh_default,smp_processor_id (), xen_vector); } void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
@@ -259,7 +259,7 @@ void xen_send_IPI_mask_allbutself(const struct cpumask *mask,if (this_cpu == cpu)continue ; -xen_send_IPI_one (cpu, xen_vector); +xen_send_IPI_one (xh_default, cpu, xen_vector); } }
arch/x86/xen/smp_pv.c +2 -2
@@ -116,7 +116,7 @@ int xen_smp_intr_init_pv(unsigned int cpu)char *callfunc_name, *pmu_name; callfunc_name =kasprintf (GFP_KERNEL ,"irqwork%d" , cpu); - rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR, + rc = bind_ipi_to_irqhandler(xh_default, XEN_IRQ_WORK_VECTOR, cpu, xen_irq_work_interrupt, IRQF_PERCPU|IRQF_NOBALANCING,
@@ -129,7 +129,7 @@ int xen_smp_intr_init_pv(unsigned int cpu)if (is_xen_pmu (cpu)) { pmu_name =kasprintf (GFP_KERNEL ,"pmu%d" , cpu); - rc =bind_virq_to_irqhandler (VIRQ_XENPMU , cpu, + rc =bind_virq_to_irqhandler (xh_default,VIRQ_XENPMU , cpu, xen_pmu_irq_handler,IRQF_PERCPU |IRQF_NOBALANCING , pmu_name,NULL );
arch/x86/xen/time.c +3 -2
@@ -340,11 +340,12 @@ void xen_setup_timer(int cpu)snprintf (xevt->name,sizeof (xevt->name),"timer%d" , cpu); - irq =bind_virq_to_irqhandler (VIRQ_TIMER , cpu, xen_timer_interrupt, + irq =bind_virq_to_irqhandler (xh_default, +VIRQ_TIMER , cpu, xen_timer_interrupt,IRQF_PERCPU |IRQF_NOBALANCING |IRQF_TIMER |IRQF_FORCE_RESUME |IRQF_EARLY_RESUME , xevt->name,NULL ); - (void )xen_set_irq_priority (irq,XEN_IRQ_PRIORITY_MAX ); + (void )xen_set_irq_priority (xh_default, irq,XEN_IRQ_PRIORITY_MAX );memcpy (evt, xen_clockevent,sizeof (*evt));
arch/x86/xen/xen-ops.h +1 -0
@@ -78,6 +78,7 @@ extern int xen_have_vcpu_info_placement;int xen_vcpu_setup (xenhost_t *xh,int cpu);void xen_vcpu_info_reset (xenhost_t *xh,int cpu);void xen_setup_vcpu_info_placement (void ); +void xenhost_init_IRQ (void );#ifdef CONFIG_SMP void xen_smp_init (void );
arch/x86/xen/xenhost.c +16 -0
@@ -2,6 +2,7 @@#include <linux/bug.h> #include <xen/xen.h> #include <xen/xenhost.h> +#include <xen/events.h> #include "xen-ops.h" /*
@@ -84,3 +85,18 @@ void __xenhost_unregister(enum xenhost_type type)BUG (); } } + +void xenhost_init_IRQ (void ) +{ +xenhost_t **xh; +/* +* xenhost_init_IRQ is called via x86_init.irq.intr_init(). +* For xenhost_r1 and xenhost_r2, the underlying state is +* ready so we can go ahead and init both the variants. +* +* xenhost_r0, might be implemented via a loadable module +* so that would do this initialization explicitly. +*/ +for_each_xenhost (xh) +xen_init_IRQ (*xh); +}
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -228,7 +228,7 @@ static int xen_blkif_map(struct xen_blkif_ring *ring, grant_ref_t *gref,BUG (); } - err =bind_interdomain_evtchn_to_irqhandler (blkif->domid, evtchn, + err =bind_interdomain_evtchn_to_irqhandler (xh_default, blkif->domid, evtchn, xen_blkif_be_int,0 ,"blkif-backend" , ring);if (err <0 ) {
drivers/block/xen-blkfront.c +1 -1
@@ -1700,7 +1700,7 @@ static int setup_blkring(struct xenbus_device *dev,if (err) goto fail; - err =bind_evtchn_to_irqhandler (rinfo->evtchn, blkif_interrupt,0 , + err =bind_evtchn_to_irqhandler (xh_default, rinfo->evtchn, blkif_interrupt,0 ,"blkif" , rinfo);if (err <=0 ) { xenbus_dev_fatal(dev, err,
drivers/input/misc/xen-kbdfront.c +1 -1
@@ -435,7 +435,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev, ret =xenbus_alloc_evtchn (dev, &evtchn);if (ret) goto error_grant; - ret =bind_evtchn_to_irqhandler (evtchn, input_handler, + ret =bind_evtchn_to_irqhandler (xh_default, evtchn, input_handler,0 , dev->devicetype, info);if (ret <0 ) {xenbus_dev_fatal (dev, ret,"bind_evtchn_to_irqhandler" );
drivers/net/xen-netback/interface.c +4 -4
@@ -588,7 +588,7 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t ring_ref, shared = (struct xen_netif_ctrl_sring *)addr;BACK_RING_INIT (&vif->ctrl, shared,XEN_PAGE_SIZE ); - err =bind_interdomain_evtchn_to_irq (vif->domid, evtchn); + err =bind_interdomain_evtchn_to_irq (xh_default, vif->domid, evtchn);if (err <0 ) goto err_unmap;
@@ -646,7 +646,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,if (tx_evtchn == rx_evtchn) {/* feature-split-event-channels == 0 */ - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, tx_evtchn, xenvif_interrupt,0 , queue->name, queue);if (err <0 )
@@ -657,7 +657,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,/* feature-split-event-channels == 1 */ snprintf (queue->tx_irq_name,sizeof (queue->tx_irq_name),"%s-tx" , queue->name); - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, tx_evtchn, xenvif_tx_interrupt,0 , queue->tx_irq_name, queue);if (err <0 )
@@ -667,7 +667,7 @@ int xenvif_connect_data(struct xenvif_queue *queue,snprintf (queue->rx_irq_name,sizeof (queue->rx_irq_name),"%s-rx" , queue->name); - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, queue->vif->domid, rx_evtchn, xenvif_rx_interrupt,0 , queue->rx_irq_name, queue);if (err <0 )
drivers/net/xen-netfront.c +3 -3
@@ -1468,7 +1468,7 @@ static int setup_netfront_single(struct netfront_queue *queue)if (err <0 ) goto fail; - err =bind_evtchn_to_irqhandler (queue->tx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->tx_evtchn, xennet_interrupt,0 , queue->info->netdev->name, queue);if (err <0 )
@@ -1498,7 +1498,7 @@ static int setup_netfront_split(struct netfront_queue *queue)snprintf (queue->tx_irq_name,sizeof (queue->tx_irq_name),"%s-tx" , queue->name); - err =bind_evtchn_to_irqhandler (queue->tx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->tx_evtchn, xennet_tx_interrupt,0 , queue->tx_irq_name, queue);if (err <0 )
@@ -1507,7 +1507,7 @@ static int setup_netfront_split(struct netfront_queue *queue)snprintf (queue->rx_irq_name,sizeof (queue->rx_irq_name),"%s-rx" , queue->name); - err =bind_evtchn_to_irqhandler (queue->rx_evtchn, + err =bind_evtchn_to_irqhandler (xh_default, queue->rx_evtchn, xennet_rx_interrupt,0 , queue->rx_irq_name, queue);if (err <0 )
drivers/pci/xen-pcifront.c +1 -1
@@ -800,7 +800,7 @@ static int pcifront_publish_info(struct pcifront_device *pdev)if (err) goto out; - err =bind_evtchn_to_irqhandler (pdev->evtchn, pcifront_handler_aer, + err =bind_evtchn_to_irqhandler (xh_default, pdev->evtchn, pcifront_handler_aer,0 ,"pcifront" , pdev);if (err <0 )
drivers/xen/acpi.c +2 -0
@@ -30,6 +30,8 @@* IN THE SOFTWARE. */ +#include <linux/types.h> +#include <xen/interface/xen.h> #include <xen/acpi.h> #include <xen/interface/platform.h> #include <asm/xen/hypercall.h>
drivers/xen/balloon.c +1 -1
@@ -62,11 +62,11 @@#include <asm/pgtable.h> #include <asm/tlb.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/xen.h> -#include <xen/interface/xen.h> #include <xen/interface/memory.h> #include <xen/balloon.h> #include <xen/features.h>
drivers/xen/events/Makefile +0 -1
@@ -2,4 +2,3 @@ obj-y += events.o events-y += events_base.o events-y += events_2l.o -events-y += events_fifo.o
drivers/xen/events/events_2l.c +97 -91
334 lines not on this page · raw message
drivers/xen/events/events_base.c +211 -168
1,095 lines not on this page · raw message
drivers/xen/events/events_fifo.c +1 -1
@@ -324,7 +324,7 @@ static void consume_one_event(unsigned cpu, q->head[priority] = head; } -static void __evtchn_fifo_handle_events (unsigned cpu,bool drop) +static void __evtchn_fifo_handle_events (xenhost_t *xh,unsigned cpu,bool drop) {struct evtchn_fifo_control_block *control_block;unsigned long ready;
drivers/xen/events/events_internal.h +40 -38
146 lines not on this page · raw message
drivers/xen/evtchn.c +11 -11
@@ -292,7 +292,7 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf, evtchn =find_evtchn (u, port);if (evtchn && !evtchn->enabled) { evtchn->enabled = true; -enable_irq (irq_from_evtchn (port)); +enable_irq (irq_from_evtchn (xh_default, port)); } }
@@ -392,18 +392,18 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)if (rc <0 ) goto err; - rc =bind_evtchn_to_irqhandler (port, evtchn_interrupt,0 , + rc =bind_evtchn_to_irqhandler (xh_default, port, evtchn_interrupt,0 , u->name, evtchn);if (rc <0 ) goto err; - rc =evtchn_make_refcounted (port); + rc =evtchn_make_refcounted (xh_default, port);return rc; err:/* bind failed, should close the port now */ close.port = port; -if (HYPERVISOR_event_channel_op (EVTCHNOP_close, &close) !=0 ) +if (hypervisor_event_channel_op (xh_default, EVTCHNOP_close, &close) !=0 )BUG ();del_evtchn (u, evtchn);return rc;
@@ -412,7 +412,7 @@ static int evtchn_bind_to_user(struct per_user_data *u, int port)static void evtchn_unbind_from_user (struct per_user_data *u,struct user_evtchn *evtchn) { -int irq =irq_from_evtchn (evtchn->port); +int irq =irq_from_evtchn (xh_default, evtchn->port);BUG_ON (irq <0 );
@@ -429,7 +429,7 @@ static void evtchn_bind_interdom_next_vcpu(int evtchn)struct irq_desc *desc;unsigned long flags; - irq =irq_from_evtchn (evtchn); + irq =irq_from_evtchn (xh_default, evtchn); desc =irq_to_desc (irq);if (!desc)
@@ -447,7 +447,7 @@ static void evtchn_bind_interdom_next_vcpu(int evtchn)this_cpu_write (bind_last_selected_cpu, selected_cpu);/* unmask expects irqs to be disabled */ -xen_rebind_evtchn_to_cpu (evtchn, selected_cpu); +xen_rebind_evtchn_to_cpu (xh_default, evtchn, selected_cpu);raw_spin_unlock_irqrestore (&desc->lock, flags); }
@@ -549,7 +549,7 @@ static long evtchn_ioctl(struct file *file,break ; rc = -EINVAL ; -if (unbind.port >=xen_evtchn_nr_channels ()) +if (unbind.port >=xen_evtchn_nr_channels (xh_default))break ; rc = -ENOTCONN ;
@@ -557,7 +557,7 @@ static long evtchn_ioctl(struct file *file,if (!evtchn)break ; -disable_irq (irq_from_evtchn (unbind.port)); +disable_irq (irq_from_evtchn (xh_default, unbind.port));evtchn_unbind_from_user (u, evtchn); rc =0 ;break ;
@@ -574,7 +574,7 @@ static long evtchn_ioctl(struct file *file, rc = -ENOTCONN ; evtchn =find_evtchn (u, notify.port);if (evtchn) { -notify_remote_via_evtchn (notify.port); +notify_remote_via_evtchn (xh_default, notify.port); rc =0 ; }break ;
@@ -676,7 +676,7 @@ static int evtchn_release(struct inode *inode, struct file *filp)struct user_evtchn *evtchn; evtchn = rb_entry(node, struct user_evtchn, node); -disable_irq (irq_from_evtchn (evtchn->port)); +disable_irq (irq_from_evtchn (xh_default, evtchn->port));evtchn_unbind_from_user (u, evtchn); }
drivers/xen/fallback.c +1 -0
@@ -2,6 +2,7 @@#include <linux/string.h> #include <linux/bug.h> #include <linux/export.h> +#include <xen/interface/xen.h> #include <asm/hypervisor.h> #include <asm/xen/hypercall.h>
drivers/xen/gntalloc.c +4 -4
@@ -189,8 +189,8 @@ static void __del_gref(struct gntalloc_gref *gref)kunmap (gref->page); }if (gref->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) { -notify_remote_via_evtchn (gref->notify.event); -evtchn_put (gref->notify.event); +notify_remote_via_evtchn (xh_default, gref->notify.event); +evtchn_put (xh_default, gref->notify.event); } gref->notify.flags =0 ;
@@ -418,14 +418,14 @@ static long gntalloc_ioctl_unmap_notify(struct gntalloc_file_private_data *priv,* reference to that event channel. */ if (op.action &UNMAP_NOTIFY_SEND_EVENT ) { -if (evtchn_get (op.event_channel_port)) { +if (evtchn_get (xh_default, op.event_channel_port)) { rc = -EINVAL ; goto unlock_out; } }if (gref->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) -evtchn_put (gref->notify.event); +evtchn_put (xh_default, gref->notify.event); gref->notify.flags = op.action; gref->notify.pgoff = pgoff;
drivers/xen/gntdev.c +4 -4
@@ -247,8 +247,8 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)atomic_sub (map->count, &pages_mapped);if (map->notify.flags &UNMAP_NOTIFY_SEND_EVENT ) { -notify_remote_via_evtchn (map->notify.event); -evtchn_put (map->notify.event); +notify_remote_via_evtchn (xh_default, map->notify.event); +evtchn_put (xh_default, map->notify.event); }if (populate_freeable_maps && priv) {
@@ -790,7 +790,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u)* reference to that event channel. */ if (op.action &UNMAP_NOTIFY_SEND_EVENT ) { -if (evtchn_get (op.event_channel_port)) +if (evtchn_get (xh_default, op.event_channel_port))return -EINVAL ; }
@@ -829,7 +829,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u)/* Drop the reference to the event channel we did not save in the map */ if (out_flags &UNMAP_NOTIFY_SEND_EVENT ) -evtchn_put (out_event); +evtchn_put (xh_default, out_event);return rc; }
drivers/xen/mcelog.c +1 -1
@@ -378,7 +378,7 @@ static int bind_virq_for_mce(void)return ret; } - ret =bind_virq_to_irqhandler (VIRQ_MCA ,0 , + ret =bind_virq_to_irqhandler (xh_default,VIRQ_MCA ,0 , xen_mce_interrupt,0 ,"mce" ,NULL );if (ret <0 ) {pr_err ("Failed to bind virq\n" );
drivers/xen/pcpu.c +1 -1
@@ -387,7 +387,7 @@ static int __init xen_pcpu_init(void)if (!xen_initial_domain ())return -ENODEV ; - irq =bind_virq_to_irqhandler (VIRQ_PCPU_STATE ,0 , + irq =bind_virq_to_irqhandler (xh_default,VIRQ_PCPU_STATE ,0 , xen_pcpu_interrupt,0 ,"xen-pcpu" ,NULL );if (irq <0 ) {
drivers/xen/preempt.c +1 -0
@@ -10,6 +10,7 @@*/ #include <linux/sched.h> +#include <xen/interface/xen.h> #include <xen/xen-ops.h> #ifndef CONFIG_PREEMPT
drivers/xen/privcmd.c +1 -0
@@ -27,6 +27,7 @@#include <asm/pgalloc.h> #include <asm/pgtable.h> #include <asm/tlb.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
drivers/xen/sys-hypervisor.c +1 -1
@@ -13,12 +13,12 @@#include <linux/kobject.h> #include <linux/err.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/xen.h> #include <xen/xenbus.h> -#include <xen/interface/xen.h> #include <xen/interface/version.h> #ifdef CONFIG_XEN_HAVE_VPMU #include <xen/interface/xenpmu.h>
drivers/xen/time.c +1 -1
@@ -8,13 +8,13 @@#include <linux/gfp.h> #include <linux/slab.h> +#include <xen/interface/xen.h> #include <asm/paravirt.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> #include <xen/events.h> #include <xen/features.h> -#include <xen/interface/xen.h> #include <xen/interface/vcpu.h> #include <xen/xen-ops.h>
drivers/xen/xen-pciback/xenbus.c +1 -1
@@ -123,7 +123,7 @@ static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref, pdev->sh_info = vaddr; - err =bind_interdomain_evtchn_to_irqhandler ( + err =bind_interdomain_evtchn_to_irqhandler (xh_default, pdev->xdev->otherend_id, remote_evtchn, xen_pcibk_handle_event,0 ,DRV_NAME , pdev);if (err <0 ) {
drivers/xen/xen-scsiback.c +3 -2
@@ -54,8 +54,9 @@#include <target/target_core_base.h> #include <target/target_core_fabric.h> + +#include <xen/interface/xen.h> #include <asm/hypervisor.h> -#include <xen/xen.h> #include <xen/balloon.h> #include <xen/events.h>
@@ -829,7 +830,7 @@ static int scsiback_init_sring(struct vscsibk_info *info, grant_ref_t ring_ref, sring = (struct vscsiif_sring *)area;BACK_RING_INIT (&info->ring, sring,PAGE_SIZE ); - err =bind_interdomain_evtchn_to_irq (info->domid, evtchn); + err =bind_interdomain_evtchn_to_irq (xh_default, info->domid, evtchn);if (err <0 ) goto unmap_page;
drivers/xen/xenbus/xenbus_client.c +1 -1
@@ -36,9 +36,9 @@#include <linux/spinlock.h> #include <linux/vmalloc.h> #include <linux/export.h> -#include <asm/xen/hypervisor.h> #include <xen/page.h> #include <xen/interface/xen.h> +#include <asm/xen/hypervisor.h> #include <xen/interface/event_channel.h> #include <xen/balloon.h> #include <xen/events.h>
drivers/xen/xenbus/xenbus_comms.c +3 -3
@@ -151,7 +151,7 @@ static int xb_write(const void *data, unsigned int len)/* Implies mb(): other side will see the updated producer. */ if (prod <= intf->req_cons) -notify_remote_via_evtchn (xen_store_evtchn); +notify_remote_via_evtchn (xh_default, xen_store_evtchn); }return bytes;
@@ -204,7 +204,7 @@ static int xb_read(void *data, unsigned int len)/* Implies mb(): other side will see the updated consumer. */ if (intf->rsp_prod - cons >=XENSTORE_RING_SIZE ) -notify_remote_via_evtchn (xen_store_evtchn); +notify_remote_via_evtchn (xh_default, xen_store_evtchn); }return bytes;
@@ -461,7 +461,7 @@ int xb_init_comms(void) }else {int err; - err =bind_evtchn_to_irqhandler (xen_store_evtchn, wake_waiting, + err =bind_evtchn_to_irqhandler (xh_default, xen_store_evtchn, wake_waiting,0 ,"xenbus" , &xb_waitq);if (err <0 ) {pr_err ("request irq failed %i\n" , err);
drivers/xen/xenbus/xenbus_probe.c +1 -0
@@ -52,6 +52,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xen.h>
drivers/xen/xenbus/xenbus_probe_backend.c +1 -0
@@ -48,6 +48,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <asm/hypervisor.h> #include <xen/xenbus.h>
drivers/xen/xenbus/xenbus_probe_frontend.c +1 -0
@@ -19,6 +19,7 @@#include <asm/page.h> #include <asm/pgtable.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xenbus.h> #include <xen/events.h>
drivers/xen/xenbus/xenbus_xs.c +1 -0
@@ -46,6 +46,7 @@#include <linux/reboot.h> #include <linux/rwsem.h> #include <linux/mutex.h> +#include <xen/interface/xen.h> #include <asm/xen/hypervisor.h> #include <xen/xenbus.h> #include <xen/xen.h>
include/xen/events.h +24 -21
100 lines not on this page · raw message
include/xen/xenhost.h +17 -0
@@ -112,6 +112,23 @@ typedef struct {*/ uint32_t xen_vcpu_id[NR_CPUS ]; }; + +/* +* evtchn: get init'd via x86_init.irqs.intr_init (xen_init_IRQ()). +* +* The common functionality for xenhost_* provided by xen_init_IRQ() +* is the mapping between evtchn <-> irq. +* +* For all three of xenhost_r0/r1 and r2, post-init the evtchn logic +* should just work using the evtchn_to_irq mapping and the vcpu_info, +* shared_info state. +* (Plus some state private to evtchn_2l/evtchn_fifo which for now +* is defined locally.) +*/ +struct { +const struct evtchn_ops *evtchn_ops; +int **evtchn_to_irq; + }; } xenhost_t; typedef struct xenhost_ops {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 09/16] xen/evtchn: support evtchn in xenhost_t
Quoted 11 lines · Ankur Arora
Largely mechanical patch that adds a new param,
xenhost_t* to the evtchn interfaces. The evtchn port instead of being domain unique, is now scoped toxenhost_t.As part of upcall handling we now look at all the xenhosts and, for
evtchn_2l, the xenhost'sshared_infoandvcpu_info. Other than this event handling is largley unchanged.Note that the IPI, timer, VIRQ, FUNCTION, PMU etc vectors remain attached to
xh_default. Only interdomain evtchns are allowable asxh_remote.
I'd do only the interface changes for now (including evtchn FIFO).
The main difference will be how to call the hypervisor for sending an event (either direct or via a passthrough-hypercall).
Juergen
Re: [RFC PATCH 09/16] xen/evtchn: support evtchn in xenhost_t
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Ankur Arora
Largely mechanical patch that adds a new param,
xenhost_t* to the evtchn interfaces. The evtchn port instead of being domain unique, is now scoped toxenhost_t.As part of upcall handling we now look at all the xenhosts and, for
evtchn_2l, the xenhost'sshared_infoandvcpu_info. Other than this event handling is largley unchanged.
Quoted 5 lines
Quoted 3 lines
Note that the IPI, timer, VIRQ, FUNCTION, PMU etc vectors remain attached to
xh_default. Only interdomain evtchns are allowable asxh_remote.I'd do only the interface changes for now (including evtchn FIFO).
Looking at this patch again, it seems to me that it would be best to limit the interface change (to take the xenhost_t * parameter) only to bind_interdomain_*. That also happily limits the change to the drivers/ subtree.
Quoted 3 lines
The main difference will be how to call the hypervisor for sending an event (either direct or via a passthrough-hypercall).
Yeah, though, this would depend on how the evtchns are mapped (if it's
the L1-Xen which is responsible for mapping the evtchn on behalf of the L0-Xen, then notify_remote_via_evtchn() could just stay the same.) Still, I'll add a send interface (perhaps just an inline function) to
the xenhost interface for this.
Ankur
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 10/16 xen/balloon: support ballooning in xenhost_t
In reply to Ankur AroraXen ballooning uses hollow struct pages (with the underlying GFNs being populated/unpopulated via hypercalls) which are used by the grant logic to map grants from other domains.
This patch allows the default xenhost to provide an alternate ballooning allocation mechanism. This is expected to be useful for local xenhosts (type xenhost_r0) because unlike Xen, where there is an external hypervisor which can change the memory underneath a GFN, that is not possible when the hypervisor is running in the same address space as the entity doing the ballooning.
--- arch/x86/xen/enlighten_hvm.c | 7 +++++++ arch/x86/xen/enlighten_pv.c | 8 ++++++++ drivers/xen/balloon.c | 19 ++++++++++++++++--- drivers/xen/grant-table.c | 4 ++-- drivers/xen/privcmd.c | 4 ++-- drivers/xen/xen-selfballoon.c | 2 ++ drivers/xen/xenbus/xenbus_client.c | 6 +++--- drivers/xen/xlate_mmu.c | 4 ++-- include/xen/balloon.h | 4 ++-- include/xen/xenhost.h | 19 +++++++++++++++++++ 10 files changed, 63 insertions(+), 14 deletions(-)
arch/x86/xen/enlighten_hvm.c +7 -0
@@ -130,9 +130,16 @@ xenhost_ops_t xh_hvm_ops = { .setup_shared_info = xen_hvm_init_shared_info, .reset_shared_info = xen_hvm_reset_shared_info, .probe_vcpu_id = xen_hvm_probe_vcpu_id, + +/* We just use the default method of ballooning. */ + .alloc_ballooned_pages = NULL, + .free_ballooned_pages = NULL, };xenhost_ops_t xh_hvm_nested_ops = { +/* Nested xenhosts, are disallowed ballooning */ + .alloc_ballooned_pages =NULL , + .free_ballooned_pages =NULL , };static void __init init_hvm_pv_info (void )
arch/x86/xen/enlighten_pv.c +8 -0
@@ -1247,11 +1247,19 @@ xenhost_ops_t xh_pv_ops = { .reset_shared_info = xen_pv_reset_shared_info, .probe_vcpu_id = xen_pv_probe_vcpu_id, + +/* We just use the default method of ballooning. */ + .alloc_ballooned_pages = NULL, + .free_ballooned_pages = NULL, };xenhost_ops_t xh_pv_nested_ops = { .cpuid_base = xen_pv_nested_cpuid_base, .setup_hypercall_page =NULL , + +/* Nested xenhosts, are disallowed ballooning */ + .alloc_ballooned_pages =NULL , + .free_ballooned_pages =NULL , };/* First C function to be called on Xen boot */
drivers/xen/balloon.c +16 -3
@@ -63,6 +63,7 @@#include <asm/tlb.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -583,12 +584,21 @@ static int add_ballooned_pages(int nr_pages)* @pages: pages returned * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages (int nr_pages,struct page **pages) +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) {int pgno =0 ;struct page *page;int ret; +/* +* xenmem transactions for remote xenhost are disallowed. +*/ +if (xh->type == xenhost_r2) +return -EINVAL ; + +if (xh->ops->alloc_ballooned_pages) +return xh->ops->alloc_ballooned_pages (xh, nr_pages, pages); +mutex_lock (&balloon_mutex); balloon_stats.target_unpopulated += nr_pages;
@@ -620,7 +630,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)return 0 ; out_undo:mutex_unlock (&balloon_mutex); -free_xenballooned_pages (pgno, pages); +free_xenballooned_pages (xh, pgno, pages);return ret; }EXPORT_SYMBOL (alloc_xenballooned_pages);
@@ -630,10 +640,13 @@ EXPORT_SYMBOL(alloc_xenballooned_pages);* @nr_pages: Number of pages * @pages: pages to return */ -void free_xenballooned_pages (int nr_pages,struct page **pages) +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) {int i; +if (xh->ops->free_ballooned_pages) +return xh->ops->free_ballooned_pages (xh, nr_pages, pages); +mutex_lock (&balloon_mutex);for (i =0 ; i < nr_pages; i++) {
drivers/xen/grant-table.c +2 -2
@@ -804,7 +804,7 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) {int ret; - ret =alloc_xenballooned_pages (nr_pages, pages); + ret =alloc_xenballooned_pages (xh_default, nr_pages, pages);if (ret <0 )return ret;
@@ -839,7 +839,7 @@ EXPORT_SYMBOL_GPL(gnttab_pages_clear_private);void gnttab_free_pages (int nr_pages,struct page **pages) {gnttab_pages_clear_private (nr_pages, pages); -free_xenballooned_pages (nr_pages, pages); +free_xenballooned_pages (xh_default, nr_pages, pages); }EXPORT_SYMBOL_GPL (gnttab_free_pages);
drivers/xen/privcmd.c +2 -2
@@ -427,7 +427,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs)if (pages ==NULL )return -ENOMEM ; - rc =alloc_xenballooned_pages (numpgs, pages); + rc =alloc_xenballooned_pages (xh_default, numpgs, pages);if (rc !=0 ) {pr_warn ("%s Could not alloc %d pfns rc:%d\n" , __func__, numpgs, rc);
@@ -928,7 +928,7 @@ static void privcmd_close(struct vm_area_struct *vma) rc =xen_unmap_domain_gfn_range (vma, numgfns, pages);if (rc ==0 ) -free_xenballooned_pages (numpgs, pages); +free_xenballooned_pages (xh_default, numpgs, pages);else pr_crit ("unable to unmap MFN range: leaking %d pages. rc=%d\n" , numpgs, rc);
drivers/xen/xen-selfballoon.c +2 -0
@@ -74,6 +74,8 @@#include <linux/mman.h> #include <linux/workqueue.h> #include <linux/device.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/balloon.h> #include <xen/tmem.h> #include <xen/xen.h>
drivers/xen/xenbus/xenbus_client.c +3 -3
@@ -563,7 +563,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,if (!node)return -ENOMEM ; - err =alloc_xenballooned_pages (nr_pages, node->hvm.pages); + err =alloc_xenballooned_pages (xh_default, nr_pages, node->hvm.pages);if (err) goto out_err;
@@ -602,7 +602,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, addr, nr_pages); out_free_ballooned_pages:if (!leaked) -free_xenballooned_pages (nr_pages, node->hvm.pages); +free_xenballooned_pages (xh_default, nr_pages, node->hvm.pages); out_err:kfree (node);return err;
@@ -849,7 +849,7 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr) info.addrs);if (!rv) {vunmap (vaddr); -free_xenballooned_pages (nr_pages, node->hvm.pages); +free_xenballooned_pages (xh_default, nr_pages, node->hvm.pages); }else WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, nr_pages);
drivers/xen/xlate_mmu.c +2 -2
@@ -233,7 +233,7 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,kfree (pages);return -ENOMEM ; } - rc =alloc_xenballooned_pages (nr_pages, pages); + rc =alloc_xenballooned_pages (xh_default, nr_pages, pages);if (rc) {pr_warn ("%s Couldn't balloon alloc %ld pages rc:%d\n" , __func__, nr_pages, rc);
@@ -250,7 +250,7 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,if (!vaddr) {pr_warn ("%s Couldn't map %ld pages rc:%d\n" , __func__, nr_pages, rc); -free_xenballooned_pages (nr_pages, pages); +free_xenballooned_pages (xh_default, nr_pages, pages);kfree (pages);kfree (pfns);return -ENOMEM ;
include/xen/balloon.h +2 -2
@@ -24,8 +24,8 @@ extern struct balloon_stats balloon_stats;void balloon_set_new_target (unsigned long target); -int alloc_xenballooned_pages (int nr_pages,struct page **pages); -void free_xenballooned_pages (int nr_pages,struct page **pages); +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages); +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages);struct device ;#ifdef CONFIG_XEN_SELFBALLOONING
include/xen/xenhost.h +19 -0
@@ -198,6 +198,25 @@ typedef struct xenhost_ops {* get accessed via pv_ops.irq.* and the evtchn logic. */ void (*probe_vcpu_id)(xenhost_t *xenhost,int cpu); + +/* +* We only want to do ballooning with the default xenhost -- two +* hypervisors managing a guest's memory is unlikely to lead anywhere +* good and xenballooned frames obtained from the default xenhost can +* be just as well populated by the remote xenhost (which is what we +* will need it for.) +* +* xenhost_r1: unchanged from before. +* xenhost_r2: disallowed. +* xenhost_r0: for a local xenhost, unlike Xen, there's no external entity +* which can remap pages, so the balloon alocation here just returns page-0. +* When the allocated page is used (in GNTTABOP_map_grant_ref), we fix this +* up by returning the correct page. +*/ + +int (*alloc_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); +void (*free_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); + } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 10/16 xen/balloon: support ballooning in xenhost_t
In reply to Ankur AroraXen ballooning uses hollow struct pages (with the underlying GFNs being populated/unpopulated via hypercalls) which are used by the grant logic to map grants from other domains.
This patch allows the default xenhost to provide an alternate ballooning allocation mechanism. This is expected to be useful for local xenhosts (type xenhost_r0) because unlike Xen, where there is an external hypervisor which can change the memory underneath a GFN, that is not possible when the hypervisor is running in the same address space as the entity doing the ballooning.
--- arch/x86/xen/enlighten_hvm.c | 7 +++++++ arch/x86/xen/enlighten_pv.c | 8 ++++++++ drivers/xen/balloon.c | 19 ++++++++++++++++--- drivers/xen/grant-table.c | 4 ++-- drivers/xen/privcmd.c | 4 ++-- drivers/xen/xen-selfballoon.c | 2 ++ drivers/xen/xenbus/xenbus_client.c | 6 +++--- drivers/xen/xlate_mmu.c | 4 ++-- include/xen/balloon.h | 4 ++-- include/xen/xenhost.h | 19 +++++++++++++++++++ 10 files changed, 63 insertions(+), 14 deletions(-)
arch/x86/xen/enlighten_hvm.c +7 -0
@@ -130,9 +130,16 @@ xenhost_ops_t xh_hvm_ops = { .setup_shared_info = xen_hvm_init_shared_info, .reset_shared_info = xen_hvm_reset_shared_info, .probe_vcpu_id = xen_hvm_probe_vcpu_id, + +/* We just use the default method of ballooning. */ + .alloc_ballooned_pages = NULL, + .free_ballooned_pages = NULL, };xenhost_ops_t xh_hvm_nested_ops = { +/* Nested xenhosts, are disallowed ballooning */ + .alloc_ballooned_pages =NULL , + .free_ballooned_pages =NULL , };static void __init init_hvm_pv_info (void )
arch/x86/xen/enlighten_pv.c +8 -0
@@ -1247,11 +1247,19 @@ xenhost_ops_t xh_pv_ops = { .reset_shared_info = xen_pv_reset_shared_info, .probe_vcpu_id = xen_pv_probe_vcpu_id, + +/* We just use the default method of ballooning. */ + .alloc_ballooned_pages = NULL, + .free_ballooned_pages = NULL, };xenhost_ops_t xh_pv_nested_ops = { .cpuid_base = xen_pv_nested_cpuid_base, .setup_hypercall_page =NULL , + +/* Nested xenhosts, are disallowed ballooning */ + .alloc_ballooned_pages =NULL , + .free_ballooned_pages =NULL , };/* First C function to be called on Xen boot */
drivers/xen/balloon.c +16 -3
@@ -63,6 +63,7 @@#include <asm/tlb.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -583,12 +584,21 @@ static int add_ballooned_pages(int nr_pages)* @pages: pages returned * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages (int nr_pages,struct page **pages) +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) {int pgno =0 ;struct page *page;int ret; +/* +* xenmem transactions for remote xenhost are disallowed. +*/ +if (xh->type == xenhost_r2) +return -EINVAL ; + +if (xh->ops->alloc_ballooned_pages) +return xh->ops->alloc_ballooned_pages (xh, nr_pages, pages); +mutex_lock (&balloon_mutex); balloon_stats.target_unpopulated += nr_pages;
@@ -620,7 +630,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)return 0 ; out_undo:mutex_unlock (&balloon_mutex); -free_xenballooned_pages (pgno, pages); +free_xenballooned_pages (xh, pgno, pages);return ret; }EXPORT_SYMBOL (alloc_xenballooned_pages);
@@ -630,10 +640,13 @@ EXPORT_SYMBOL(alloc_xenballooned_pages);* @nr_pages: Number of pages * @pages: pages to return */ -void free_xenballooned_pages (int nr_pages,struct page **pages) +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) {int i; +if (xh->ops->free_ballooned_pages) +return xh->ops->free_ballooned_pages (xh, nr_pages, pages); +mutex_lock (&balloon_mutex);for (i =0 ; i < nr_pages; i++) {
drivers/xen/grant-table.c +2 -2
@@ -804,7 +804,7 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages) {int ret; - ret =alloc_xenballooned_pages (nr_pages, pages); + ret =alloc_xenballooned_pages (xh_default, nr_pages, pages);if (ret <0 )return ret;
@@ -839,7 +839,7 @@ EXPORT_SYMBOL_GPL(gnttab_pages_clear_private);void gnttab_free_pages (int nr_pages,struct page **pages) {gnttab_pages_clear_private (nr_pages, pages); -free_xenballooned_pages (nr_pages, pages); +free_xenballooned_pages (xh_default, nr_pages, pages); }EXPORT_SYMBOL_GPL (gnttab_free_pages);
drivers/xen/privcmd.c +2 -2
@@ -427,7 +427,7 @@ static int alloc_empty_pages(struct vm_area_struct *vma, int numpgs)if (pages ==NULL )return -ENOMEM ; - rc =alloc_xenballooned_pages (numpgs, pages); + rc =alloc_xenballooned_pages (xh_default, numpgs, pages);if (rc !=0 ) {pr_warn ("%s Could not alloc %d pfns rc:%d\n" , __func__, numpgs, rc);
@@ -928,7 +928,7 @@ static void privcmd_close(struct vm_area_struct *vma) rc =xen_unmap_domain_gfn_range (vma, numgfns, pages);if (rc ==0 ) -free_xenballooned_pages (numpgs, pages); +free_xenballooned_pages (xh_default, numpgs, pages);else pr_crit ("unable to unmap MFN range: leaking %d pages. rc=%d\n" , numpgs, rc);
drivers/xen/xen-selfballoon.c +2 -0
@@ -74,6 +74,8 @@#include <linux/mman.h> #include <linux/workqueue.h> #include <linux/device.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/balloon.h> #include <xen/tmem.h> #include <xen/xen.h>
drivers/xen/xenbus/xenbus_client.c +3 -3
@@ -563,7 +563,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,if (!node)return -ENOMEM ; - err =alloc_xenballooned_pages (nr_pages, node->hvm.pages); + err =alloc_xenballooned_pages (xh_default, nr_pages, node->hvm.pages);if (err) goto out_err;
@@ -602,7 +602,7 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, addr, nr_pages); out_free_ballooned_pages:if (!leaked) -free_xenballooned_pages (nr_pages, node->hvm.pages); +free_xenballooned_pages (xh_default, nr_pages, node->hvm.pages); out_err:kfree (node);return err;
@@ -849,7 +849,7 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr) info.addrs);if (!rv) {vunmap (vaddr); -free_xenballooned_pages (nr_pages, node->hvm.pages); +free_xenballooned_pages (xh_default, nr_pages, node->hvm.pages); }else WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, nr_pages);
drivers/xen/xlate_mmu.c +2 -2
@@ -233,7 +233,7 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,kfree (pages);return -ENOMEM ; } - rc =alloc_xenballooned_pages (nr_pages, pages); + rc =alloc_xenballooned_pages (xh_default, nr_pages, pages);if (rc) {pr_warn ("%s Couldn't balloon alloc %ld pages rc:%d\n" , __func__, nr_pages, rc);
@@ -250,7 +250,7 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,if (!vaddr) {pr_warn ("%s Couldn't map %ld pages rc:%d\n" , __func__, nr_pages, rc); -free_xenballooned_pages (nr_pages, pages); +free_xenballooned_pages (xh_default, nr_pages, pages);kfree (pages);kfree (pfns);return -ENOMEM ;
include/xen/balloon.h +2 -2
@@ -24,8 +24,8 @@ extern struct balloon_stats balloon_stats;void balloon_set_new_target (unsigned long target); -int alloc_xenballooned_pages (int nr_pages,struct page **pages); -void free_xenballooned_pages (int nr_pages,struct page **pages); +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages); +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages);struct device ;#ifdef CONFIG_XEN_SELFBALLOONING
include/xen/xenhost.h +19 -0
@@ -198,6 +198,25 @@ typedef struct xenhost_ops {* get accessed via pv_ops.irq.* and the evtchn logic. */ void (*probe_vcpu_id)(xenhost_t *xenhost,int cpu); + +/* +* We only want to do ballooning with the default xenhost -- two +* hypervisors managing a guest's memory is unlikely to lead anywhere +* good and xenballooned frames obtained from the default xenhost can +* be just as well populated by the remote xenhost (which is what we +* will need it for.) +* +* xenhost_r1: unchanged from before. +* xenhost_r2: disallowed. +* xenhost_r0: for a local xenhost, unlike Xen, there's no external entity +* which can remap pages, so the balloon alocation here just returns page-0. +* When the allocated page is used (in GNTTABOP_map_grant_ref), we fix this +* up by returning the correct page. +*/ + +int (*alloc_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); +void (*free_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); + } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
Signature · 1 line
2.20.1
Juergen Gross
maintainerRe: [RFC PATCH 10/16] xen/balloon: support ballooning in xenhost_t
Quoted 45 lines · Ankur Arora
Xen ballooning uses hollow struct pages (with the underlying GFNs being populated/unpopulated via hypercalls) which are used by the grant logic to map grants from other domains.
This patch allows the default xenhost to provide an alternate ballooning allocation mechanism. This is expected to be useful for local xenhosts (type
xenhost_r0) because unlike Xen, where there is an external hypervisor which can change the memory underneath a GFN, that is not possible when the hypervisor is running in the same address space as the entity doing the ballooning.Co-developed-by Ankur Arora <[email protected]>Signed-off-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/x86/xen/enlighten_hvm.c | 7 +++++++ arch/x86/xen/enlighten_pv.c | 8 ++++++++ drivers/xen/balloon.c | 19 ++++++++++++++++--- drivers/xen/grant-table.c | 4 ++-- drivers/xen/privcmd.c | 4 ++-- drivers/xen/xen-selfballoon.c | 2 ++ drivers/xen/xenbus/xenbus_client.c | 6 +++--- drivers/xen/xlate_mmu.c | 4 ++-- include/xen/balloon.h | 4 ++-- include/xen/xenhost.h | 19 +++++++++++++++++++ 10 files changed, 63 insertions(+), 14 deletions(-)drivers/xen/balloon.c +2
-1@@ -63,6 +63,7 @@#include <asm/tlb.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h> @@ -583,12 +584,21 @@ static int add_ballooned_pages(int nr_pages)* @pages: pages returned * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages (int nr_pages,struct page **pages) +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages)
drivers/xen/balloon.c static int add_ballooned_pages(int nr_pages) · line 597
Quoted 10 lines
drivers/xen/balloon.c +5
-0{int pgno =0 ;struct page *page;int ret; +/* +* xenmem transactions for remote xenhost are disallowed. +*/ +if (xh->type == xenhost_r2) +return -EINVAL ;
Why don't you set a dummy function returning -EINVAL into the xenhost_r2 structure instead?
drivers/xen/balloon.c static int add_ballooned_pages(int nr_pages) · line 601
Quoted 4 lines
drivers/xen/balloon.c +4
-0+ +if (xh->ops->alloc_ballooned_pages) +return xh->ops->alloc_ballooned_pages (xh, nr_pages, pages); +
Please make alloc_xenballooned_pages() an inline wrapper and use the current implmentaion as the default. This avoids another if ().
Quoted 14 lines
drivers/xen/balloon.c +1
-1mutex_lock (&balloon_mutex); balloon_stats.target_unpopulated += nr_pages;@@ -620,7 +630,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)return 0 ; out_undo:mutex_unlock (&balloon_mutex); -free_xenballooned_pages (pgno, pages); +free_xenballooned_pages (xh, pgno, pages);return ret; }EXPORT_SYMBOL (alloc_xenballooned_pages);@@ -630,10 +640,13 @@ EXPORT_SYMBOL(alloc_xenballooned_pages);* @nr_pages: Number of pages
drivers/xen/balloon.c EXPORT_SYMBOL(alloc_xenballooned_pages); · line 649
Quoted 10 lines
drivers/xen/balloon.c +4
-1* @pages: pages to return */ -void free_xenballooned_pages (int nr_pages,struct page **pages) +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) {int i; +if (xh->ops->free_ballooned_pages) +return xh->ops->free_ballooned_pages (xh, nr_pages, pages); +
Same again: please use an inline wrapper.
Juergen
Re: [RFC PATCH 10/16] xen/balloon: support ballooning in xenhost_t
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Ankur Arora
Xen ballooning uses hollow struct pages (with the underlying GFNs being populated/unpopulated via hypercalls) which are used by the grant logic to map grants from other domains.
This patch allows the default xenhost to provide an alternate ballooning allocation mechanism. This is expected to be useful for local xenhosts (type
xenhost_r0) because unlike Xen, where there is an external hypervisor which can change the memory underneath a GFN, that is not possible when the hypervisor is running in the same address space as the entity doing the ballooning.Co-developed-by Ankur Arora <[email protected]>Signed-off-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>---
arch/x86/xen/enlighten_hvm.c | 7 +++++++ arch/x86/xen/enlighten_pv.c | 8 ++++++++ drivers/xen/balloon.c | 19 ++++++++++++++++--- drivers/xen/grant-table.c | 4 ++-- drivers/xen/privcmd.c | 4 ++-- drivers/xen/xen-selfballoon.c | 2 ++drivers/xen/xenbus/xenbus_client.c| 6 +++--- drivers/xen/xlate_mmu.c | 4 ++-- include/xen/balloon.h | 4 ++-- include/xen/xenhost.h | 19 +++++++++++++++++++10 files changed, 63 insertions(+), 14 deletions(-)drivers/xen/balloon.c +2
-1@@ -63,6 +63,7 @@ #include <asm/tlb.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>@@ -583,12 +584,21 @@ static int add_ballooned_pages(int nr_pages)* @pages: pages returned * @return 0 on success, error otherwise */ -int alloc_xenballooned_pages(int nr_pages, struct page **pages) +int alloc_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) { int pgno = 0; struct page *page; int ret;
Quoted 8 lines
drivers/xen/balloon.c static int add_ballooned_pages(int nr_pages) · line 597
Quoted 5 lines
drivers/xen/balloon.c +5
-0+ /* + * xenmem transactions for remote xenhost are disallowed. + */ + if (xh->type == xenhost_r2) + return -EINVAL;Why don't you set a dummy function returning
-EINVALinto thexenhost_r2structure instead?
Will do. And, same for the two comments below.
Ankur
Quoted 38 lines
drivers/xen/balloon.c static int add_ballooned_pages(int nr_pages) · line 601
Quoted 5 lines
drivers/xen/balloon.c +4
-0+ + if (xh->ops->alloc_ballooned_pages) + return xh->ops->alloc_ballooned_pages(xh, nr_pages, pages); +Please make
alloc_xenballooned_pages()an inline wrapper and use the current implmentaion as the default. This avoids another if ().Quoted 14 lines
drivers/xen/balloon.c +0
-0mutex_lock(&balloon_mutex); balloon_stats.target_unpopulated += nr_pages;@@ -620,7 +630,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) return 0;
out_undo:
mutex_unlock(&balloon_mutex);
-free_xenballooned_pages(pgno, pages);
+free_xenballooned_pages(xh, pgno, pages);
return ret;
}
EXPORT_SYMBOL(alloc_xenballooned_pages);drivers/xen/balloon.c +0
-0@@ -630,10 +640,13 @@ EXPORT_SYMBOL(alloc_xenballooned_pages); * @nr_pages: Number of pagesdrivers/xen/balloon.c EXPORT_SYMBOL(alloc_xenballooned_pages); · line 649
Quoted 10 lines
drivers/xen/balloon.c +4
-1* @pages: pages to return */ -void free_xenballooned_pages(int nr_pages, struct page **pages) +void free_xenballooned_pages (xenhost_t *xh,int nr_pages,struct page **pages) { int i; + if (xh->ops->free_ballooned_pages) + return xh->ops->free_ballooned_pages(xh, nr_pages, pages); +Same again: please use an inline wrapper.
Juergen
RFC PATCH 11/16 xen/grant-table: make grant-table xenhost aware
In reply to Ankur AroraLargely mechanical changes: the exported grant table symbols now take xenhost_t * as a parameter. Also, move the grant table global state inside xenhost_t.
If there's more than one xenhost, then initialize both.
--- arch/x86/xen/grant-table.c | 71 +++-- drivers/xen/grant-table.c | 611 +++++++++++++++++++++---------------- include/xen/grant_table.h | 72 ++--- include/xen/xenhost.h | 11 + 4 files changed, 443 insertions(+), 322 deletions(-)
arch/x86/xen/grant-table.c +45 -26
@@ -23,48 +23,54 @@#include <asm/pgtable.h> -static struct gnttab_vm_area { +struct gnttab_vm_area {struct vm_struct *area;pte_t **ptes; -} gnttab_shared_vm_area, gnttab_status_vm_area; +}; -int arch_gnttab_map_shared (unsigned long *frames,unsigned long nr_gframes, -unsigned long max_nr_gframes, -void **__shared) +int arch_gnttab_map_shared (xenhost_t *xh,unsigned long *frames, +unsigned long nr_gframes, +unsigned long max_nr_gframes, +void **__shared) {void *shared = *__shared;unsigned long addr;unsigned long i;if (shared ==NULL ) - *__shared = shared = gnttab_shared_vm_area.area->addr; + *__shared = shared = ((struct gnttab_vm_area *) + xh->gnttab_shared_vm_area)->area->addr; addr = (unsigned long )shared;for (i =0 ; i < nr_gframes; i++) { -set_pte_at (&init_mm, addr, gnttab_shared_vm_area.ptes[i], -mfn_pte (frames[i],PAGE_KERNEL )); +set_pte_at (&init_mm, addr, + ((struct gnttab_vm_area *) xh->gnttab_shared_vm_area)->ptes[i], +mfn_pte (frames[i],PAGE_KERNEL )); addr +=PAGE_SIZE ; }return 0 ; } -int arch_gnttab_map_status (uint64_t *frames,unsigned long nr_gframes, -unsigned long max_nr_gframes, -grant_status_t **__shared) +int arch_gnttab_map_status (xenhost_t *xh,uint64_t *frames, +unsigned long nr_gframes, +unsigned long max_nr_gframes, +grant_status_t **__shared) {grant_status_t *shared = *__shared;unsigned long addr;unsigned long i;if (shared ==NULL ) - *__shared = shared = gnttab_status_vm_area.area->addr; + *__shared = shared = ((struct gnttab_vm_area *) + xh->gnttab_status_vm_area)->area->addr; addr = (unsigned long )shared;for (i =0 ; i < nr_gframes; i++) { -set_pte_at (&init_mm, addr, gnttab_status_vm_area.ptes[i], +set_pte_at (&init_mm, addr, ((struct gnttab_vm_area *) + xh->gnttab_status_vm_area)->ptes[i],mfn_pte (frames[i],PAGE_KERNEL )); addr +=PAGE_SIZE ; }
@@ -72,16 +78,17 @@ int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,return 0 ; } -void arch_gnttab_unmap (void *shared,unsigned long nr_gframes) +void arch_gnttab_unmap (xenhost_t *xh,void *shared,unsigned long nr_gframes) {pte_t **ptes;unsigned long addr;unsigned long i; -if (shared == gnttab_status_vm_area.area->addr) - ptes = gnttab_status_vm_area.ptes; +if (shared == ((struct gnttab_vm_area *) + xh->gnttab_status_vm_area)->area->addr) + ptes = ((struct gnttab_vm_area *) xh->gnttab_status_vm_area)->ptes;else - ptes = gnttab_shared_vm_area.ptes; + ptes = ((struct gnttab_vm_area *) xh->gnttab_shared_vm_area)->ptes; addr = (unsigned long )shared;
@@ -112,14 +119,15 @@ static void arch_gnttab_vfree(struct gnttab_vm_area *area)kfree (area->ptes); } -int arch_gnttab_init (unsigned long nr_shared,unsigned long nr_status) +int arch_gnttab_init (xenhost_t *xh,unsigned long nr_shared,unsigned long nr_status) {int ret;if (!xen_pv_domain ())return 0 ; - ret =arch_gnttab_valloc (&gnttab_shared_vm_area, nr_shared); + ret =arch_gnttab_valloc ((struct gnttab_vm_area *) + xh->gnttab_shared_vm_area, nr_shared);if (ret <0 )return ret;
@@ -127,13 +135,15 @@ int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)* Always allocate the space for the status frames in case * we're migrated to a host with V2 support. */ - ret =arch_gnttab_valloc (&gnttab_status_vm_area, nr_status); + ret =arch_gnttab_valloc ((struct gnttab_vm_area *) + xh->gnttab_status_vm_area, nr_status);if (ret <0 ) goto err;return 0 ; err: -arch_gnttab_vfree (&gnttab_shared_vm_area); +arch_gnttab_vfree ((struct gnttab_vm_area *) + xh->gnttab_shared_vm_area);return -ENOMEM ; }
@@ -142,16 +152,25 @@ int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)#include <xen/xen-ops.h> static int __init xen_pvh_gnttab_setup (void ) { +xenhost_t **xh; +int err; +if (!xen_pvh_domain ())return -ENODEV ; - xen_auto_xlat_grant_frames.count =gnttab_max_grant_frames (); +for_each_xenhost (xh) { +struct grant_frames *gf = (struct grant_frames *) (*xh)->auto_xlat_grant_frames; -return xen_xlate_map_ballooned_pages (&xen_auto_xlat_grant_frames.pfn, - &xen_auto_xlat_grant_frames.vaddr, - xen_auto_xlat_grant_frames.count); + gf->count =gnttab_max_grant_frames (*xh); + + err =xen_xlate_map_ballooned_pages (&gf->pfn, &gf->vaddr, gf->count); +if (err) +return err; + } + +return 0 ; }/* Call it _before_ __gnttab_init as we need to initialize the -* xen_auto_xlat_grant_frames first. */ +* auto_xlat_grant_frames first. */ core_initcall (xen_pvh_gnttab_setup);#endif
drivers/xen/grant-table.c +351 -260
1,323 lines not on this page · raw message
include/xen/grant_table.h +36 -36
161 lines not on this page · raw message
include/xen/xenhost.h +11 -0
@@ -129,6 +129,17 @@ typedef struct {const struct evtchn_ops *evtchn_ops;int **evtchn_to_irq; }; + +/* grant table private state */ +struct { +/* private to drivers/xen/grant-table.c */ +void *gnttab_private; + +/* x86/xen/grant-table.c */ +void *gnttab_shared_vm_area; +void *gnttab_status_vm_area; +void *auto_xlat_grant_frames; + }; } xenhost_t; typedef struct xenhost_ops {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 11/16] xen/grant-table: make grant-table xenhost aware
Quoted 22 lines · Ankur Arora
Largely mechanical changes: the exported grant table symbols now take
xenhost_t* as a parameter. Also, move the grant table global state insidexenhost_t.If there's more than one xenhost, then initialize both.
Signed-off-by Ankur Arora <[email protected]>--- arch/x86/xen/grant-table.c | 71 +++-- drivers/xen/grant-table.c | 611 +++++++++++++++++++++---------------- include/xen/grant_table.h | 72 ++--- include/xen/xenhost.h | 11 + 4 files changed, 443 insertions(+), 322 deletions(-)include/xen/xenhost.h +0
-0@@ -129,6 +129,17 @@ typedef struct {const struct evtchn_ops *evtchn_ops;int **evtchn_to_irq; };
include/xen/xenhost.h typedef struct { · line 141
Quoted 10 lines
include/xen/xenhost.h +10
-0+ +/* grant table private state */ +struct { +/* private to drivers/xen/grant-table.c */ +void *gnttab_private; + +/* x86/xen/grant-table.c */ +void *gnttab_shared_vm_area; +void *gnttab_status_vm_area; +void *auto_xlat_grant_frames;
Please use proper types here instead of void *. This avoids lots of casts. It is okay to just add anonymous struct definitions and keep the real struct layout local to grant table code.
Juergen
Re: [RFC PATCH 11/16] xen/grant-table: make grant-table xenhost aware
Quoted 29 lines · Juergen Gross
Quoted 28 lines · Ankur Arora
Largely mechanical changes: the exported grant table symbols now take
xenhost_t* as a parameter. Also, move the grant table global state insidexenhost_t.If there's more than one xenhost, then initialize both.
Signed-off-by Ankur Arora <[email protected]>---
arch/x86/xen/grant-table.c| 71 +++-- drivers/xen/grant-table.c | 611 +++++++++++++++++++++---------------- include/xen/grant_table.h | 72 ++--- include/xen/xenhost.h | 11 +4 files changed, 443 insertions(+), 322 deletions(-)include/xen/xenhost.h +6
-0@@ -129,6 +129,17 @@ typedef struct { const struct evtchn_ops *evtchn_ops; int **evtchn_to_irq; }; + + /* grant table private state */ + struct { + /* private to drivers/xen/grant-table.c */ + void *gnttab_private; +
Quoted 8 lines
include/xen/xenhost.h typedef struct { · line 141
Quoted 4 lines
include/xen/xenhost.h +4
-0+ /* x86/xen/grant-table.c */ + void *gnttab_shared_vm_area; + void *gnttab_status_vm_area; + void *auto_xlat_grant_frames;Please use proper types here instead of void *. This avoids lots of casts. It is okay to just add anonymous struct definitions and keep the real struct layout local to grant table code.
Will fix.
Ankur
Quoted 3 lines
Juergen
RFC PATCH 12/16 xen/xenbus: support xenbus frontend/backend with xenhost_t
In reply to Ankur AroraAs part of xenbus init, both frontend, backend interfaces need to talk on the correct xenbus. This might be a local xenstore (backend) or might be a XS_PV/XS_HVM interface (frontend) which needs to talk over xenbus with the remote xenstored. We bootstrap all of these with evtchn/gfn parameters from (*setup_xs)().
Given this we can do appropriate device discovery (in case of frontend) and device connectivity for the backend.
Once done, we stash the xenhost_t * in xen_bus_type, xenbus_device or xenbus_watch and then the frontend and backend devices implicitly use the correct interface.
The rest of patch is just changing the interfaces where needed.
--- drivers/block/xen-blkback/blkback.c | 10 +- drivers/net/xen-netfront.c | 14 +- drivers/pci/xen-pcifront.c | 4 +- drivers/xen/cpu_hotplug.c | 4 +- drivers/xen/manage.c | 28 +-- drivers/xen/xen-balloon.c | 8 +- drivers/xen/xenbus/xenbus.h | 45 ++-- drivers/xen/xenbus/xenbus_client.c | 32 +-- drivers/xen/xenbus/xenbus_comms.c | 121 +++++----- drivers/xen/xenbus/xenbus_dev_backend.c | 30 ++- drivers/xen/xenbus/xenbus_dev_frontend.c | 22 +- drivers/xen/xenbus/xenbus_probe.c | 246 +++++++++++++-------- drivers/xen/xenbus/xenbus_probe_backend.c | 19 +- drivers/xen/xenbus/xenbus_probe_frontend.c | 65 +++--- drivers/xen/xenbus/xenbus_xs.c | 188 +++++++++------- include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 54 +++-- include/xen/xenhost.h | 20 ++ 18 files changed, 536 insertions(+), 377 deletions(-)
drivers/block/xen-blkback/blkback.c +5 -5
@@ -541,12 +541,12 @@ static void xen_vbd_resize(struct xen_blkif *blkif)pr_info ("VBD Resize: new size %llu\n" , new_size); vbd->size = new_size; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (dev->xh, &xbt);if (err) {pr_warn ("Error starting transaction\n" );return ; } - err =xenbus_printf (xbt, dev->nodename,"sectors" ,"%llu" , + err =xenbus_printf (dev->xh, xbt, dev->nodename,"sectors" ,"%llu" , (unsigned long long )vbd_sz (vbd));if (err) {pr_warn ("Error writing new size\n" );
@@ -557,20 +557,20 @@ static void xen_vbd_resize(struct xen_blkif *blkif)* the front-end. If the current state is "connected" the * front-end will get the new size information online. */ - err =xenbus_printf (xbt, dev->nodename,"state" ,"%d" , dev->state); + err =xenbus_printf (dev->xh, xbt, dev->nodename,"state" ,"%d" , dev->state);if (err) {pr_warn ("Error writing the state\n" ); goto abort; } - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (dev->xh, xbt,0 );if (err == -EAGAIN ) goto again;if (err)pr_warn ("Error ending transaction\n" );return ; abort: -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (dev->xh, xbt,1 ); }/*
drivers/net/xen-netfront.c +7 -7
@@ -1336,9 +1336,9 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)xenbus_switch_state (dev, XenbusStateInitialising);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) != +xenbus_read_driver_state (dev, dev->otherend) != XenbusStateClosed && -xenbus_read_driver_state (dev->otherend) != +xenbus_read_driver_state (dev, dev->otherend) != XenbusStateUnknown);return netdev;
@@ -2145,19 +2145,19 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); -if (xenbus_read_driver_state (dev->otherend) != XenbusStateClosed) { +if (xenbus_read_driver_state (dev, dev->otherend) != XenbusStateClosed) {xenbus_switch_state (dev, XenbusStateClosing);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateClosing || -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateUnknown);xenbus_switch_state (dev, XenbusStateClosed);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateClosed || -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateUnknown); }
drivers/pci/xen-pcifront.c +2 -2
@@ -860,7 +860,7 @@ static int pcifront_try_connect(struct pcifront_device *pdev)/* Only connect once */ -if (xenbus_read_driver_state (pdev->xdev->nodename) != +if (xenbus_read_driver_state (pdev->xdev, pdev->xdev->nodename) != XenbusStateInitialised) goto out;
@@ -871,7 +871,7 @@ static int pcifront_try_connect(struct pcifront_device *pdev) goto out; } - err =xenbus_scanf (XBT_NIL , pdev->xdev->otherend, + err =xenbus_scanf (pdev->xdev->xh,XBT_NIL , pdev->xdev->otherend,"root_num" ,"%d" , &num_roots);if (err == -ENOENT ) { xenbus_dev_error(pdev->xdev, err,
drivers/xen/cpu_hotplug.c +2 -2
@@ -37,7 +37,7 @@ static int vcpu_online(unsigned int cpu)char dir[16 ], state[16 ];sprintf (dir,"cpu/%u" , cpu); - err =xenbus_scanf (XBT_NIL , dir,"availability" ,"%15s" , state); + err =xenbus_scanf (xh_default,XBT_NIL , dir,"availability" ,"%15s" , state);if (err !=1 ) {if (!xen_initial_domain ())pr_err ("Unable to read cpu state\n" );
@@ -90,7 +90,7 @@ static int setup_cpu_watcher(struct notifier_block *notifier, .node = "cpu", .callback = handle_vcpu_hotplug_event}; - (void )register_xenbus_watch (&cpu_watch); + (void )register_xenbus_watch (xh_default, &cpu_watch);for_each_possible_cpu (cpu) {if (vcpu_online (cpu) ==0 ) {
drivers/xen/manage.c +14 -14
@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch,return ; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (xh_default, &xbt);if (err)return ; - str = (char *)xenbus_read (xbt,"control" ,"shutdown" ,NULL ); + str = (char *)xenbus_read (xh_default, xbt,"control" ,"shutdown" ,NULL );/* Ignore read errors and empty reads. */ if (XENBUS_IS_ERR_READ (str)) { -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; }
@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch,/* Only acknowledge commands which we are prepared to handle. */ if (idx <ARRAY_SIZE (shutdown_handlers)) -xenbus_write (xbt,"control" ,"shutdown" ,"" ); +xenbus_write (xh_default, xbt,"control" ,"shutdown" ,"" ); - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (xh_default, xbt,0 );if (err == -EAGAIN ) {kfree (str); goto again;
@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,int err; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (xh_default, &xbt);if (err)return ; - err =xenbus_scanf (xbt,"control" ,"sysrq" ,"%c" , &sysrq_key); + err =xenbus_scanf (xh_default, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key);if (err <0 ) {/* * The Xenstore watch fires directly after registering it and
@@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,if (err != -ENOENT && err != -ERANGE )pr_err ("Error %d reading sysrq code in control/sysrq\n" , err); -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; }if (sysrq_key !='\0' ) { - err =xenbus_printf (xbt,"control" ,"sysrq" ,"%c" ,'\0' ); + err =xenbus_printf (xh_default, xbt,"control" ,"sysrq" ,"%c" ,'\0' );if (err) {pr_err ("%s: Error %d writing sysrq in control/sysrq\n" , __func__, err); -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; } } - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (xh_default, xbt,0 );if (err == -EAGAIN ) goto again;
@@ -331,7 +331,7 @@ static int setup_shutdown_watcher(void)#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))char node[FEATURE_PATH_SIZE ]; - err =register_xenbus_watch (&shutdown_watch); + err =register_xenbus_watch (xh_default, &shutdown_watch);if (err) {pr_err ("Failed to set shutdown watcher\n" );return err;
@@ -339,7 +339,7 @@ static int setup_shutdown_watcher(void)#ifdef CONFIG_MAGIC_SYSRQ - err =register_xenbus_watch (&sysrq_watch); + err =register_xenbus_watch (xh_default, &sysrq_watch);if (err) {pr_err ("Failed to set sysrq watcher\n" );return err;
@@ -351,7 +351,7 @@ static int setup_shutdown_watcher(void)continue ;snprintf (node,FEATURE_PATH_SIZE ,"feature-%s" , shutdown_handlers[idx].command); - err =xenbus_printf (XBT_NIL ,"control" , node,"%u" ,1 ); + err =xenbus_printf (xh_default,XBT_NIL ,"control" , node,"%u" ,1 );if (err) {pr_err ("%s: Error %d writing %s\n" , __func__, err, node);
drivers/xen/xen-balloon.c +4 -4
@@ -63,7 +63,7 @@ static void watch_target(struct xenbus_watch *watch,static bool watch_fired;static long target_diff; - err =xenbus_scanf (XBT_NIL ,"memory" ,"target" ,"%llu" , &new_target); + err =xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"target" ,"%llu" , &new_target);if (err !=1 ) {/* This is ok (for domain0 at least) - so just return */ return ;
@@ -77,9 +77,9 @@ static void watch_target(struct xenbus_watch *watch,if (!watch_fired) { watch_fired = true; -if ((xenbus_scanf (XBT_NIL ,"memory" ,"static-max" , +if ((xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"static-max" ,"%llu" , &static_max) ==1 ) || - (xenbus_scanf (XBT_NIL ,"memory" ,"memory_static_max" , + (xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"memory_static_max" ,"%llu" , &static_max) ==1 )) static_max >>=PAGE_SHIFT -10 ;else
@@ -103,7 +103,7 @@ static int balloon_init_watcher(struct notifier_block *notifier, {int err; - err =register_xenbus_watch (&target_watch); + err =register_xenbus_watch (xh_default, &target_watch);if (err)pr_err ("Failed to set balloon watcher\n" );
drivers/xen/xenbus/xenbus.h +30 -15
77 lines not on this page · raw message
drivers/xen/xenbus/xenbus_client.c +16 -16
@@ -122,7 +122,7 @@ int xenbus_watch_path(struct xenbus_device *dev, const char *path, watch->node = path; watch->callback = callback; - err =register_xenbus_watch (watch); + err =register_xenbus_watch (dev->xh, watch);if (err) { watch->node =NULL ;
@@ -206,17 +206,17 @@ __xenbus_switch_state(struct xenbus_device *dev, again: abort =1 ; - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (dev->xh, &xbt);if (err) {xenbus_switch_fatal (dev, depth, err,"starting transaction" );return 0 ; } - err =xenbus_scanf (xbt, dev->nodename,"state" ,"%d" , ¤t_state); + err =xenbus_scanf (dev->xh, xbt, dev->nodename,"state" ,"%d" , ¤t_state);if (err !=1 ) goto abort; - err =xenbus_printf (xbt, dev->nodename,"state" ,"%d" , state); + err =xenbus_printf (dev->xh, xbt, dev->nodename,"state" ,"%d" , state);if (err) {xenbus_switch_fatal (dev, depth, err,"writing new state" ); goto abort;
@@ -224,7 +224,7 @@ __xenbus_switch_state(struct xenbus_device *dev, abort =0 ; abort: - err =xenbus_transaction_end (xbt, abort); + err =xenbus_transaction_end (dev->xh, xbt, abort);if (err) {if (err == -EAGAIN && !abort) goto again;
@@ -279,7 +279,7 @@ static void xenbus_va_dev_error(struct xenbus_device *dev, int err, path_buffer =kasprintf (GFP_KERNEL ,"error/%s" , dev->nodename);if (path_buffer) -xenbus_write (XBT_NIL , path_buffer,"error" , printf_buffer); +xenbus_write (dev->xh,XBT_NIL , path_buffer,"error" , printf_buffer);kfree (printf_buffer);kfree (path_buffer);
@@ -363,7 +363,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,int i, j;for (i =0 ; i < nr_pages; i++) { - err =gnttab_grant_foreign_access (dev->otherend_id, + err =gnttab_grant_foreign_access (dev->xh, dev->otherend_id,virt_to_gfn (vaddr),0 );if (err <0 ) { xenbus_dev_fatal(dev, err,
@@ -379,7 +379,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr, fail:for (j =0 ; j < i; j++) -gnttab_end_foreign_access_ref (grefs[j],0 ); +gnttab_end_foreign_access_ref (dev->xh, grefs[j],0 );return err; }EXPORT_SYMBOL_GPL (xenbus_grant_ring);
@@ -399,7 +399,7 @@ int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port) alloc_unbound.dom =DOMID_SELF ; alloc_unbound.remote_dom = dev->otherend_id; - err =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, + err =hypervisor_event_channel_op (dev->xh, EVTCHNOP_alloc_unbound, &alloc_unbound);if (err)xenbus_dev_fatal (dev, err,"allocating event channel" );
@@ -421,7 +421,7 @@ int xenbus_free_evtchn(struct xenbus_device *dev, int port) close.port = port; - err =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + err =hypervisor_event_channel_op (dev->xh, EVTCHNOP_close, &close);if (err)xenbus_dev_error (dev, err,"freeing event channel %d" , port);
@@ -478,7 +478,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev, handles[i] =INVALID_GRANT_HANDLE ; } -gnttab_batch_map (map, i); +gnttab_batch_map (dev->xh, map, i);for (i =0 ; i < nr_grefs; i++) {if (map[i].status != GNTST_okay) {
@@ -503,7 +503,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev, } } -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, j)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, j))BUG (); *leaked = false;
@@ -761,7 +761,7 @@ static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr) unmap[i].handle = node->handles[i]; } -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, i)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, i))BUG (); err = GNTST_okay;
@@ -884,7 +884,7 @@ int xenbus_unmap_ring(struct xenbus_device *dev,gnttab_set_unmap_op (&unmap[i], vaddrs[i], GNTMAP_host_map, handles[i]); -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, i)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, i))BUG (); err = GNTST_okay;
@@ -910,10 +910,10 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring);* Return the state of the driver rooted at the given store path, or * XenbusStateUnknown if no state can be read. */ -enum xenbus_state xenbus_read_driver_state (const char *path) +enum xenbus_state xenbus_read_driver_state (struct xenbus_device *dev,const char *path) {enum xenbus_state result; -int err =xenbus_gather (XBT_NIL , path,"state" ,"%d" , &result,NULL ); +int err =xenbus_gather (dev->xh,XBT_NIL , path,"state" ,"%d" , &result,NULL );if (err) result = XenbusStateUnknown;
drivers/xen/xenbus/xenbus_comms.c +60 -61
300 lines not on this page · raw message
drivers/xen/xenbus/xenbus_dev_backend.c +20 -10
@@ -19,6 +19,8 @@#include "xenbus.h" +static xenhost_t *xh; +static int xenbus_backend_open (struct inode *inode,struct file *filp) {if (!capable (CAP_SYS_ADMIN ))
@@ -31,6 +33,7 @@ static long xenbus_alloc(domid_t domid) {struct evtchn_alloc_unbound arg;int err = -EEXIST ; +struct xenstore_private *xs =xs_priv (xh);xs_suspend ();
@@ -44,23 +47,23 @@ static long xenbus_alloc(domid_t domid)* unnecessarily complex for the intended use where xenstored is only * started once - so return -EEXIST if it's already running. */ -if (xenstored_ready) +if (xs->xenstored_ready) goto out_err; -gnttab_grant_foreign_access_ref (GNTTAB_RESERVED_XENSTORE , domid, -virt_to_gfn (xen_store_interface),0 /* writable */ ); +gnttab_grant_foreign_access_ref (xh,GNTTAB_RESERVED_XENSTORE , domid, +virt_to_gfn (xs->store_interface),0 /* writable */ ); arg.dom =DOMID_SELF ; arg.remote_dom = domid; - err =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, &arg); + err =hypervisor_event_channel_op (xh, EVTCHNOP_alloc_unbound, &arg);if (err) goto out_err; -if (xen_store_evtchn >0 ) -xb_deinit_comms (); +if (xs->store_evtchn >0 ) +xb_deinit_comms (xh); - xen_store_evtchn = arg.port; + xs->store_evtchn = arg.port;xs_resume ();
@@ -74,13 +77,15 @@ static long xenbus_alloc(domid_t domid)static long xenbus_backend_ioctl (struct file *file,unsigned int cmd,unsigned long data) { +struct xenstore_private *xs =xs_priv (xh); +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;switch (cmd) {case IOCTL_XENBUS_BACKEND_EVTCHN : -if (xen_store_evtchn >0 ) -return xen_store_evtchn; +if (xs->store_evtchn >0 ) +return xs->store_evtchn;return -ENODEV ;case IOCTL_XENBUS_BACKEND_SETUP :return xenbus_alloc (data);
@@ -92,6 +97,7 @@ static long xenbus_backend_ioctl(struct file *file, unsigned int cmd,static int xenbus_backend_mmap (struct file *file,struct vm_area_struct *vma) {size_t size = vma->vm_end - vma->vm_start; +struct xenstore_private *xs =xs_priv (xh);if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -100,7 +106,7 @@ static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ;if (remap_pfn_range (vma, vma->vm_start, -virt_to_pfn (xen_store_interface), +virt_to_pfn (xs->store_interface), size, vma->vm_page_prot))return -EAGAIN ;
@@ -125,6 +131,10 @@ static int __init xenbus_backend_init(void)if (!xen_initial_domain ())return -ENODEV ; +/* +* Backends shouldn't have any truck with the remote xenhost. +*/ + xh = xh_default; err =misc_register (&xenbus_backend_dev);if (err)
drivers/xen/xenbus/xenbus_dev_frontend.c +16 -6
@@ -58,10 +58,14 @@#include <xen/xenbus.h> #include <xen/xen.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include "xenbus.h" +static xenhost_t *xh; +/* * An element of a list of outstanding transactions, for which we're * still waiting a reply.
@@ -312,13 +316,13 @@ static void xenbus_file_free(struct kref *kref)*/ list_for_each_entry_safe (trans, tmp, &u->transactions, list) { -xenbus_transaction_end (trans->handle,1 ); +xenbus_transaction_end (xh, trans->handle,1 );list_del (&trans->list);kfree (trans); }list_for_each_entry_safe (watch, tmp_watch, &u->watches, list) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch); }
@@ -450,7 +454,7 @@ static int xenbus_write_transaction(unsigned msg_type, (!strcmp(msg->body, "T") || !strcmp(msg->body, "F"))))return xenbus_command_reply (u,XS_ERROR ,"EINVAL" ); - rc =xenbus_dev_request_and_reply (&msg->hdr, u); + rc =xenbus_dev_request_and_reply (xh, &msg->hdr, u);if (rc && trans) {list_del (&trans->list);kfree (trans);
@@ -489,7 +493,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) watch->watch.callback = watch_fired; watch->dev_data = u; - err =register_xenbus_watch (&watch->watch); + err =register_xenbus_watch (xh, &watch->watch);if (err) {free_watch_adapter (watch); rc = err;
@@ -500,7 +504,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)list_for_each_entry (watch, &u->watches, list) {if (!strcmp (watch->token, token) && !strcmp (watch->watch.node, path)) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch);break ;
@@ -618,8 +622,9 @@ static ssize_t xenbus_file_write(struct file *filp,static int xenbus_file_open (struct inode *inode,struct file *filp) {struct xenbus_file_priv *u; +struct xenstore_private *xs =xs_priv (xh); -if (xen_store_evtchn ==0 ) +if (xs->store_evtchn ==0 )return -ENOENT ;nonseekable_open (inode, filp);
@@ -687,6 +692,11 @@ static int __init xenbus_init(void)if (!xen_domain ())return -ENODEV ; +if (xen_driver_domain () &&xen_nested ()) + xh = xh_remote; +else + xh = xh_default; + err =misc_register (&xenbus_dev);if (err)pr_err ("Could not register xenbus frontend device\n" );
drivers/xen/xenbus/xenbus_probe.c +153 -93
401 lines not on this page · raw message
drivers/xen/xenbus/xenbus_probe_backend.c +12 -7
@@ -57,7 +57,8 @@#include "xenbus.h" /* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */ -static int backend_bus_id (char bus_id[XEN_BUS_ID_SIZE ],const char *nodename) +static int backend_bus_id (struct xen_bus_type *bus,char bus_id[XEN_BUS_ID_SIZE ], +const char *nodename) {int domid, err;const char *devid, *type, *frontend;
@@ -73,14 +74,14 @@ static int backend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) devid =strrchr (nodename,'/' ) +1 ; - err =xenbus_gather (XBT_NIL , nodename,"frontend-id" ,"%i" , &domid, + err =xenbus_gather (bus->xh,XBT_NIL , nodename,"frontend-id" ,"%i" , &domid,"frontend" ,NULL , &frontend,NULL );if (err)return err;if (strlen (frontend) ==0 ) err = -ERANGE ; -if (!err && !xenbus_exists (XBT_NIL , frontend,"" )) +if (!err && !xenbus_exists (bus->xh,XBT_NIL , frontend,"" )) err = -ENOENT ;kfree (frontend);
@@ -165,7 +166,7 @@ static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type,if (!nodename)return -ENOMEM ; - dir =xenbus_directory (XBT_NIL , nodename,"" , &dir_n); + dir =xenbus_directory (bus->xh,XBT_NIL , nodename,"" , &dir_n);if (IS_ERR (dir)) {kfree (nodename);return PTR_ERR (dir);
@@ -189,6 +190,7 @@ static void frontend_changed(struct xenbus_watch *watch,static struct xen_bus_type xenbus_backend = { .root ="backend" , + .xh =NULL ,/* Filled at xenbus_probe_backend_init() */ .levels =3 ,/* backend/type/<frontend>/<id> */ .get_bus_id = backend_bus_id, .probe = xenbus_probe_backend,
@@ -224,7 +226,7 @@ static int read_frontend_details(struct xenbus_device *xendev)int xenbus_dev_is_online (struct xenbus_device *dev) { -return !!xenbus_read_unsigned (dev->nodename,"online" ,0 ); +return !!xenbus_read_unsigned (dev->xh, dev->nodename,"online" ,0 ); }EXPORT_SYMBOL_GPL (xenbus_dev_is_online);
@@ -244,7 +246,7 @@ static int backend_probe_and_watch(struct notifier_block *notifier, {/* Enumerate devices in xenstore and watch for changes. */ xenbus_probe_devices (&xenbus_backend); -register_xenbus_watch (&be_watch); +register_xenbus_watch (xenbus_backend.xh,&be_watch);return NOTIFY_DONE ; }
@@ -258,12 +260,15 @@ static int __init xenbus_probe_backend_init(void)DPRINTK ("" ); +/* Backends always talk to default xenhost */ + xenbus_backend.xh = xh_default; +/* Register ourselves with the kernel bus subsystem */ err =bus_register (&xenbus_backend.bus);if (err)return err; -register_xenstore_notifier (&xenstore_notifier); +register_xenstore_notifier (xenbus_backend.xh, &xenstore_notifier);return 0 ; }
drivers/xen/xenbus/xenbus_probe_frontend.c +39 -26
180 lines not on this page · raw message
drivers/xen/xenbus/xenbus_xs.c +102 -86
554 lines not on this page · raw message
include/xen/xen-ops.h +3 -0
@@ -204,6 +204,9 @@ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,int xen_xlate_map_ballooned_pages (xen_pfn_t **pfns,void **vaddr,unsigned long nr_grant_frames); +int xen_hvm_setup_xs (xenhost_t *xh); +int xen_pv_setup_xs (xenhost_t *xh); +bool xen_running_on_version_or_later (unsigned int major,unsigned int minor);efi_status_t xen_efi_get_time (efi_time_t *tm,efi_time_cap_t *tc);
include/xen/xenbus.h +31 -23
121 lines not on this page · raw message
include/xen/xenhost.h +20 -0
@@ -140,6 +140,9 @@ typedef struct {void *gnttab_status_vm_area;void *auto_xlat_grant_frames; }; + +/* xenstore private state */ +void *xenstore_private; } xenhost_t; typedef struct xenhost_ops {
@@ -228,6 +231,17 @@ typedef struct xenhost_ops {int (*alloc_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages);void (*free_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); +/* +* xenbus: as part of xenbus-init, frontend/backend need to talk to the +* correct xenbus. This might be a local xenstore (backend) or might +* be a XS_PV/XS_HVM interface (frontend). We bootstrap these with +* evtchn/gfn parameters from (*setup_xs)(). +* +* Once done, stash the xenhost_t * in xen_bus_type, xenbus_device or +* xenbus_watch and then the frontend and backend devices implicitly +* use the correct interface. +*/ +int (*setup_xs)(xenhost_t *xh); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -279,4 +293,10 @@ static inline void xenhost_probe_vcpu_id(xenhost_t *xh, int cpu) (xh->ops->probe_vcpu_id)(xh, cpu); } +static inline void xenhost_setup_xs (xenhost_t *xh) +{ +if (xh) + (xh->ops->setup_xs)(xh); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 12/16 xen/xenbus: support xenbus frontend/backend with xenhost_t
In reply to Ankur AroraAs part of xenbus init, both frontend, backend interfaces need to talk on the correct xenbus. This might be a local xenstore (backend) or might be a XS_PV/XS_HVM interface (frontend) which needs to talk over xenbus with the remote xenstored. We bootstrap all of these with evtchn/gfn parameters from (*setup_xs)().
Given this we can do appropriate device discovery (in case of frontend) and device connectivity for the backend.
Once done, we stash the xenhost_t * in xen_bus_type, xenbus_device or xenbus_watch and then the frontend and backend devices implicitly use the correct interface.
The rest of patch is just changing the interfaces where needed.
--- drivers/block/xen-blkback/blkback.c | 10 +- drivers/net/xen-netfront.c | 14 +- drivers/pci/xen-pcifront.c | 4 +- drivers/xen/cpu_hotplug.c | 4 +- drivers/xen/manage.c | 28 +-- drivers/xen/xen-balloon.c | 8 +- drivers/xen/xenbus/xenbus.h | 45 ++-- drivers/xen/xenbus/xenbus_client.c | 32 +-- drivers/xen/xenbus/xenbus_comms.c | 121 +++++----- drivers/xen/xenbus/xenbus_dev_backend.c | 30 ++- drivers/xen/xenbus/xenbus_dev_frontend.c | 22 +- drivers/xen/xenbus/xenbus_probe.c | 246 +++++++++++++-------- drivers/xen/xenbus/xenbus_probe_backend.c | 19 +- drivers/xen/xenbus/xenbus_probe_frontend.c | 65 +++--- drivers/xen/xenbus/xenbus_xs.c | 188 +++++++++------- include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 54 +++-- include/xen/xenhost.h | 20 ++ 18 files changed, 536 insertions(+), 377 deletions(-)
drivers/block/xen-blkback/blkback.c +5 -5
@@ -541,12 +541,12 @@ static void xen_vbd_resize(struct xen_blkif *blkif)pr_info ("VBD Resize: new size %llu\n" , new_size); vbd->size = new_size; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (dev->xh, &xbt);if (err) {pr_warn ("Error starting transaction\n" );return ; } - err =xenbus_printf (xbt, dev->nodename,"sectors" ,"%llu" , + err =xenbus_printf (dev->xh, xbt, dev->nodename,"sectors" ,"%llu" , (unsigned long long )vbd_sz (vbd));if (err) {pr_warn ("Error writing new size\n" );
@@ -557,20 +557,20 @@ static void xen_vbd_resize(struct xen_blkif *blkif)* the front-end. If the current state is "connected" the * front-end will get the new size information online. */ - err =xenbus_printf (xbt, dev->nodename,"state" ,"%d" , dev->state); + err =xenbus_printf (dev->xh, xbt, dev->nodename,"state" ,"%d" , dev->state);if (err) {pr_warn ("Error writing the state\n" ); goto abort; } - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (dev->xh, xbt,0 );if (err == -EAGAIN ) goto again;if (err)pr_warn ("Error ending transaction\n" );return ; abort: -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (dev->xh, xbt,1 ); }/*
drivers/net/xen-netfront.c +7 -7
@@ -1336,9 +1336,9 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)xenbus_switch_state (dev, XenbusStateInitialising);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) != +xenbus_read_driver_state (dev, dev->otherend) != XenbusStateClosed && -xenbus_read_driver_state (dev->otherend) != +xenbus_read_driver_state (dev, dev->otherend) != XenbusStateUnknown);return netdev;
@@ -2145,19 +2145,19 @@ static int xennet_remove(struct xenbus_device *dev)dev_dbg (&dev->dev,"%s\n" , dev->nodename); -if (xenbus_read_driver_state (dev->otherend) != XenbusStateClosed) { +if (xenbus_read_driver_state (dev, dev->otherend) != XenbusStateClosed) {xenbus_switch_state (dev, XenbusStateClosing);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateClosing || -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateUnknown);xenbus_switch_state (dev, XenbusStateClosed);wait_event (module_wq, -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateClosed || -xenbus_read_driver_state (dev->otherend) == +xenbus_read_driver_state (dev, dev->otherend) == XenbusStateUnknown); }
drivers/pci/xen-pcifront.c +2 -2
@@ -860,7 +860,7 @@ static int pcifront_try_connect(struct pcifront_device *pdev)/* Only connect once */ -if (xenbus_read_driver_state (pdev->xdev->nodename) != +if (xenbus_read_driver_state (pdev->xdev, pdev->xdev->nodename) != XenbusStateInitialised) goto out;
@@ -871,7 +871,7 @@ static int pcifront_try_connect(struct pcifront_device *pdev) goto out; } - err =xenbus_scanf (XBT_NIL , pdev->xdev->otherend, + err =xenbus_scanf (pdev->xdev->xh,XBT_NIL , pdev->xdev->otherend,"root_num" ,"%d" , &num_roots);if (err == -ENOENT ) { xenbus_dev_error(pdev->xdev, err,
drivers/xen/cpu_hotplug.c +2 -2
@@ -37,7 +37,7 @@ static int vcpu_online(unsigned int cpu)char dir[16 ], state[16 ];sprintf (dir,"cpu/%u" , cpu); - err =xenbus_scanf (XBT_NIL , dir,"availability" ,"%15s" , state); + err =xenbus_scanf (xh_default,XBT_NIL , dir,"availability" ,"%15s" , state);if (err !=1 ) {if (!xen_initial_domain ())pr_err ("Unable to read cpu state\n" );
@@ -90,7 +90,7 @@ static int setup_cpu_watcher(struct notifier_block *notifier, .node = "cpu", .callback = handle_vcpu_hotplug_event}; - (void )register_xenbus_watch (&cpu_watch); + (void )register_xenbus_watch (xh_default, &cpu_watch);for_each_possible_cpu (cpu) {if (vcpu_online (cpu) ==0 ) {
drivers/xen/manage.c +14 -14
@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch,return ; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (xh_default, &xbt);if (err)return ; - str = (char *)xenbus_read (xbt,"control" ,"shutdown" ,NULL ); + str = (char *)xenbus_read (xh_default, xbt,"control" ,"shutdown" ,NULL );/* Ignore read errors and empty reads. */ if (XENBUS_IS_ERR_READ (str)) { -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; }
@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch,/* Only acknowledge commands which we are prepared to handle. */ if (idx <ARRAY_SIZE (shutdown_handlers)) -xenbus_write (xbt,"control" ,"shutdown" ,"" ); +xenbus_write (xh_default, xbt,"control" ,"shutdown" ,"" ); - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (xh_default, xbt,0 );if (err == -EAGAIN ) {kfree (str); goto again;
@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,int err; again: - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (xh_default, &xbt);if (err)return ; - err =xenbus_scanf (xbt,"control" ,"sysrq" ,"%c" , &sysrq_key); + err =xenbus_scanf (xh_default, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key);if (err <0 ) {/* * The Xenstore watch fires directly after registering it and
@@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,if (err != -ENOENT && err != -ERANGE )pr_err ("Error %d reading sysrq code in control/sysrq\n" , err); -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; }if (sysrq_key !='\0' ) { - err =xenbus_printf (xbt,"control" ,"sysrq" ,"%c" ,'\0' ); + err =xenbus_printf (xh_default, xbt,"control" ,"sysrq" ,"%c" ,'\0' );if (err) {pr_err ("%s: Error %d writing sysrq in control/sysrq\n" , __func__, err); -xenbus_transaction_end (xbt,1 ); +xenbus_transaction_end (xh_default, xbt,1 );return ; } } - err =xenbus_transaction_end (xbt,0 ); + err =xenbus_transaction_end (xh_default, xbt,0 );if (err == -EAGAIN ) goto again;
@@ -331,7 +331,7 @@ static int setup_shutdown_watcher(void)#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))char node[FEATURE_PATH_SIZE ]; - err =register_xenbus_watch (&shutdown_watch); + err =register_xenbus_watch (xh_default, &shutdown_watch);if (err) {pr_err ("Failed to set shutdown watcher\n" );return err;
@@ -339,7 +339,7 @@ static int setup_shutdown_watcher(void)#ifdef CONFIG_MAGIC_SYSRQ - err =register_xenbus_watch (&sysrq_watch); + err =register_xenbus_watch (xh_default, &sysrq_watch);if (err) {pr_err ("Failed to set sysrq watcher\n" );return err;
@@ -351,7 +351,7 @@ static int setup_shutdown_watcher(void)continue ;snprintf (node,FEATURE_PATH_SIZE ,"feature-%s" , shutdown_handlers[idx].command); - err =xenbus_printf (XBT_NIL ,"control" , node,"%u" ,1 ); + err =xenbus_printf (xh_default,XBT_NIL ,"control" , node,"%u" ,1 );if (err) {pr_err ("%s: Error %d writing %s\n" , __func__, err, node);
drivers/xen/xen-balloon.c +4 -4
@@ -63,7 +63,7 @@ static void watch_target(struct xenbus_watch *watch,static bool watch_fired;static long target_diff; - err =xenbus_scanf (XBT_NIL ,"memory" ,"target" ,"%llu" , &new_target); + err =xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"target" ,"%llu" , &new_target);if (err !=1 ) {/* This is ok (for domain0 at least) - so just return */ return ;
@@ -77,9 +77,9 @@ static void watch_target(struct xenbus_watch *watch,if (!watch_fired) { watch_fired = true; -if ((xenbus_scanf (XBT_NIL ,"memory" ,"static-max" , +if ((xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"static-max" ,"%llu" , &static_max) ==1 ) || - (xenbus_scanf (XBT_NIL ,"memory" ,"memory_static_max" , + (xenbus_scanf (xh_default,XBT_NIL ,"memory" ,"memory_static_max" ,"%llu" , &static_max) ==1 )) static_max >>=PAGE_SHIFT -10 ;else
@@ -103,7 +103,7 @@ static int balloon_init_watcher(struct notifier_block *notifier, {int err; - err =register_xenbus_watch (&target_watch); + err =register_xenbus_watch (xh_default, &target_watch);if (err)pr_err ("Failed to set balloon watcher\n" );
drivers/xen/xenbus/xenbus.h +30 -15
77 lines not on this page · raw message
drivers/xen/xenbus/xenbus_client.c +16 -16
@@ -122,7 +122,7 @@ int xenbus_watch_path(struct xenbus_device *dev, const char *path, watch->node = path; watch->callback = callback; - err =register_xenbus_watch (watch); + err =register_xenbus_watch (dev->xh, watch);if (err) { watch->node =NULL ;
@@ -206,17 +206,17 @@ __xenbus_switch_state(struct xenbus_device *dev, again: abort =1 ; - err =xenbus_transaction_start (&xbt); + err =xenbus_transaction_start (dev->xh, &xbt);if (err) {xenbus_switch_fatal (dev, depth, err,"starting transaction" );return 0 ; } - err =xenbus_scanf (xbt, dev->nodename,"state" ,"%d" , ¤t_state); + err =xenbus_scanf (dev->xh, xbt, dev->nodename,"state" ,"%d" , ¤t_state);if (err !=1 ) goto abort; - err =xenbus_printf (xbt, dev->nodename,"state" ,"%d" , state); + err =xenbus_printf (dev->xh, xbt, dev->nodename,"state" ,"%d" , state);if (err) {xenbus_switch_fatal (dev, depth, err,"writing new state" ); goto abort;
@@ -224,7 +224,7 @@ __xenbus_switch_state(struct xenbus_device *dev, abort =0 ; abort: - err =xenbus_transaction_end (xbt, abort); + err =xenbus_transaction_end (dev->xh, xbt, abort);if (err) {if (err == -EAGAIN && !abort) goto again;
@@ -279,7 +279,7 @@ static void xenbus_va_dev_error(struct xenbus_device *dev, int err, path_buffer =kasprintf (GFP_KERNEL ,"error/%s" , dev->nodename);if (path_buffer) -xenbus_write (XBT_NIL , path_buffer,"error" , printf_buffer); +xenbus_write (dev->xh,XBT_NIL , path_buffer,"error" , printf_buffer);kfree (printf_buffer);kfree (path_buffer);
@@ -363,7 +363,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,int i, j;for (i =0 ; i < nr_pages; i++) { - err =gnttab_grant_foreign_access (dev->otherend_id, + err =gnttab_grant_foreign_access (dev->xh, dev->otherend_id,virt_to_gfn (vaddr),0 );if (err <0 ) { xenbus_dev_fatal(dev, err,
@@ -379,7 +379,7 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr, fail:for (j =0 ; j < i; j++) -gnttab_end_foreign_access_ref (grefs[j],0 ); +gnttab_end_foreign_access_ref (dev->xh, grefs[j],0 );return err; }EXPORT_SYMBOL_GPL (xenbus_grant_ring);
@@ -399,7 +399,7 @@ int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port) alloc_unbound.dom =DOMID_SELF ; alloc_unbound.remote_dom = dev->otherend_id; - err =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, + err =hypervisor_event_channel_op (dev->xh, EVTCHNOP_alloc_unbound, &alloc_unbound);if (err)xenbus_dev_fatal (dev, err,"allocating event channel" );
@@ -421,7 +421,7 @@ int xenbus_free_evtchn(struct xenbus_device *dev, int port) close.port = port; - err =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + err =hypervisor_event_channel_op (dev->xh, EVTCHNOP_close, &close);if (err)xenbus_dev_error (dev, err,"freeing event channel %d" , port);
@@ -478,7 +478,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev, handles[i] =INVALID_GRANT_HANDLE ; } -gnttab_batch_map (map, i); +gnttab_batch_map (dev->xh, map, i);for (i =0 ; i < nr_grefs; i++) {if (map[i].status != GNTST_okay) {
@@ -503,7 +503,7 @@ static int __xenbus_map_ring(struct xenbus_device *dev, } } -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, j)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, j))BUG (); *leaked = false;
@@ -761,7 +761,7 @@ static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr) unmap[i].handle = node->handles[i]; } -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, i)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, i))BUG (); err = GNTST_okay;
@@ -884,7 +884,7 @@ int xenbus_unmap_ring(struct xenbus_device *dev,gnttab_set_unmap_op (&unmap[i], vaddrs[i], GNTMAP_host_map, handles[i]); -if (HYPERVISOR_grant_table_op (GNTTABOP_unmap_grant_ref, unmap, i)) +if (hypervisor_grant_table_op (dev->xh, GNTTABOP_unmap_grant_ref, unmap, i))BUG (); err = GNTST_okay;
@@ -910,10 +910,10 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring);* Return the state of the driver rooted at the given store path, or * XenbusStateUnknown if no state can be read. */ -enum xenbus_state xenbus_read_driver_state (const char *path) +enum xenbus_state xenbus_read_driver_state (struct xenbus_device *dev,const char *path) {enum xenbus_state result; -int err =xenbus_gather (XBT_NIL , path,"state" ,"%d" , &result,NULL ); +int err =xenbus_gather (dev->xh,XBT_NIL , path,"state" ,"%d" , &result,NULL );if (err) result = XenbusStateUnknown;
drivers/xen/xenbus/xenbus_comms.c +60 -61
300 lines not on this page · raw message
drivers/xen/xenbus/xenbus_dev_backend.c +20 -10
@@ -19,6 +19,8 @@#include "xenbus.h" +static xenhost_t *xh; +static int xenbus_backend_open (struct inode *inode,struct file *filp) {if (!capable (CAP_SYS_ADMIN ))
@@ -31,6 +33,7 @@ static long xenbus_alloc(domid_t domid) {struct evtchn_alloc_unbound arg;int err = -EEXIST ; +struct xenstore_private *xs =xs_priv (xh);xs_suspend ();
@@ -44,23 +47,23 @@ static long xenbus_alloc(domid_t domid)* unnecessarily complex for the intended use where xenstored is only * started once - so return -EEXIST if it's already running. */ -if (xenstored_ready) +if (xs->xenstored_ready) goto out_err; -gnttab_grant_foreign_access_ref (GNTTAB_RESERVED_XENSTORE , domid, -virt_to_gfn (xen_store_interface),0 /* writable */ ); +gnttab_grant_foreign_access_ref (xh,GNTTAB_RESERVED_XENSTORE , domid, +virt_to_gfn (xs->store_interface),0 /* writable */ ); arg.dom =DOMID_SELF ; arg.remote_dom = domid; - err =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, &arg); + err =hypervisor_event_channel_op (xh, EVTCHNOP_alloc_unbound, &arg);if (err) goto out_err; -if (xen_store_evtchn >0 ) -xb_deinit_comms (); +if (xs->store_evtchn >0 ) +xb_deinit_comms (xh); - xen_store_evtchn = arg.port; + xs->store_evtchn = arg.port;xs_resume ();
@@ -74,13 +77,15 @@ static long xenbus_alloc(domid_t domid)static long xenbus_backend_ioctl (struct file *file,unsigned int cmd,unsigned long data) { +struct xenstore_private *xs =xs_priv (xh); +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;switch (cmd) {case IOCTL_XENBUS_BACKEND_EVTCHN : -if (xen_store_evtchn >0 ) -return xen_store_evtchn; +if (xs->store_evtchn >0 ) +return xs->store_evtchn;return -ENODEV ;case IOCTL_XENBUS_BACKEND_SETUP :return xenbus_alloc (data);
@@ -92,6 +97,7 @@ static long xenbus_backend_ioctl(struct file *file, unsigned int cmd,static int xenbus_backend_mmap (struct file *file,struct vm_area_struct *vma) {size_t size = vma->vm_end - vma->vm_start; +struct xenstore_private *xs =xs_priv (xh);if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -100,7 +106,7 @@ static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ;if (remap_pfn_range (vma, vma->vm_start, -virt_to_pfn (xen_store_interface), +virt_to_pfn (xs->store_interface), size, vma->vm_page_prot))return -EAGAIN ;
@@ -125,6 +131,10 @@ static int __init xenbus_backend_init(void)if (!xen_initial_domain ())return -ENODEV ; +/* +* Backends shouldn't have any truck with the remote xenhost. +*/ + xh = xh_default; err =misc_register (&xenbus_backend_dev);if (err)
drivers/xen/xenbus/xenbus_dev_frontend.c +16 -6
@@ -58,10 +58,14 @@#include <xen/xenbus.h> #include <xen/xen.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include "xenbus.h" +static xenhost_t *xh; +/* * An element of a list of outstanding transactions, for which we're * still waiting a reply.
@@ -312,13 +316,13 @@ static void xenbus_file_free(struct kref *kref)*/ list_for_each_entry_safe (trans, tmp, &u->transactions, list) { -xenbus_transaction_end (trans->handle,1 ); +xenbus_transaction_end (xh, trans->handle,1 );list_del (&trans->list);kfree (trans); }list_for_each_entry_safe (watch, tmp_watch, &u->watches, list) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch); }
@@ -450,7 +454,7 @@ static int xenbus_write_transaction(unsigned msg_type, (!strcmp(msg->body, "T") || !strcmp(msg->body, "F"))))return xenbus_command_reply (u,XS_ERROR ,"EINVAL" ); - rc =xenbus_dev_request_and_reply (&msg->hdr, u); + rc =xenbus_dev_request_and_reply (xh, &msg->hdr, u);if (rc && trans) {list_del (&trans->list);kfree (trans);
@@ -489,7 +493,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) watch->watch.callback = watch_fired; watch->dev_data = u; - err =register_xenbus_watch (&watch->watch); + err =register_xenbus_watch (xh, &watch->watch);if (err) {free_watch_adapter (watch); rc = err;
@@ -500,7 +504,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)list_for_each_entry (watch, &u->watches, list) {if (!strcmp (watch->token, token) && !strcmp (watch->watch.node, path)) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch);break ;
@@ -618,8 +622,9 @@ static ssize_t xenbus_file_write(struct file *filp,static int xenbus_file_open (struct inode *inode,struct file *filp) {struct xenbus_file_priv *u; +struct xenstore_private *xs =xs_priv (xh); -if (xen_store_evtchn ==0 ) +if (xs->store_evtchn ==0 )return -ENOENT ;nonseekable_open (inode, filp);
@@ -687,6 +692,11 @@ static int __init xenbus_init(void)if (!xen_domain ())return -ENODEV ; +if (xen_driver_domain () &&xen_nested ()) + xh = xh_remote; +else + xh = xh_default; + err =misc_register (&xenbus_dev);if (err)pr_err ("Could not register xenbus frontend device\n" );
drivers/xen/xenbus/xenbus_probe.c +153 -93
401 lines not on this page · raw message
drivers/xen/xenbus/xenbus_probe_backend.c +12 -7
@@ -57,7 +57,8 @@#include "xenbus.h" /* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */ -static int backend_bus_id (char bus_id[XEN_BUS_ID_SIZE ],const char *nodename) +static int backend_bus_id (struct xen_bus_type *bus,char bus_id[XEN_BUS_ID_SIZE ], +const char *nodename) {int domid, err;const char *devid, *type, *frontend;
@@ -73,14 +74,14 @@ static int backend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) devid =strrchr (nodename,'/' ) +1 ; - err =xenbus_gather (XBT_NIL , nodename,"frontend-id" ,"%i" , &domid, + err =xenbus_gather (bus->xh,XBT_NIL , nodename,"frontend-id" ,"%i" , &domid,"frontend" ,NULL , &frontend,NULL );if (err)return err;if (strlen (frontend) ==0 ) err = -ERANGE ; -if (!err && !xenbus_exists (XBT_NIL , frontend,"" )) +if (!err && !xenbus_exists (bus->xh,XBT_NIL , frontend,"" )) err = -ENOENT ;kfree (frontend);
@@ -165,7 +166,7 @@ static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type,if (!nodename)return -ENOMEM ; - dir =xenbus_directory (XBT_NIL , nodename,"" , &dir_n); + dir =xenbus_directory (bus->xh,XBT_NIL , nodename,"" , &dir_n);if (IS_ERR (dir)) {kfree (nodename);return PTR_ERR (dir);
@@ -189,6 +190,7 @@ static void frontend_changed(struct xenbus_watch *watch,static struct xen_bus_type xenbus_backend = { .root ="backend" , + .xh =NULL ,/* Filled at xenbus_probe_backend_init() */ .levels =3 ,/* backend/type/<frontend>/<id> */ .get_bus_id = backend_bus_id, .probe = xenbus_probe_backend,
@@ -224,7 +226,7 @@ static int read_frontend_details(struct xenbus_device *xendev)int xenbus_dev_is_online (struct xenbus_device *dev) { -return !!xenbus_read_unsigned (dev->nodename,"online" ,0 ); +return !!xenbus_read_unsigned (dev->xh, dev->nodename,"online" ,0 ); }EXPORT_SYMBOL_GPL (xenbus_dev_is_online);
@@ -244,7 +246,7 @@ static int backend_probe_and_watch(struct notifier_block *notifier, {/* Enumerate devices in xenstore and watch for changes. */ xenbus_probe_devices (&xenbus_backend); -register_xenbus_watch (&be_watch); +register_xenbus_watch (xenbus_backend.xh,&be_watch);return NOTIFY_DONE ; }
@@ -258,12 +260,15 @@ static int __init xenbus_probe_backend_init(void)DPRINTK ("" ); +/* Backends always talk to default xenhost */ + xenbus_backend.xh = xh_default; +/* Register ourselves with the kernel bus subsystem */ err =bus_register (&xenbus_backend.bus);if (err)return err; -register_xenstore_notifier (&xenstore_notifier); +register_xenstore_notifier (xenbus_backend.xh, &xenstore_notifier);return 0 ; }
drivers/xen/xenbus/xenbus_probe_frontend.c +39 -26
180 lines not on this page · raw message
drivers/xen/xenbus/xenbus_xs.c +102 -86
554 lines not on this page · raw message
include/xen/xen-ops.h +3 -0
@@ -204,6 +204,9 @@ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,int xen_xlate_map_ballooned_pages (xen_pfn_t **pfns,void **vaddr,unsigned long nr_grant_frames); +int xen_hvm_setup_xs (xenhost_t *xh); +int xen_pv_setup_xs (xenhost_t *xh); +bool xen_running_on_version_or_later (unsigned int major,unsigned int minor);efi_status_t xen_efi_get_time (efi_time_t *tm,efi_time_cap_t *tc);
include/xen/xenbus.h +31 -23
121 lines not on this page · raw message
include/xen/xenhost.h +20 -0
@@ -140,6 +140,9 @@ typedef struct {void *gnttab_status_vm_area;void *auto_xlat_grant_frames; }; + +/* xenstore private state */ +void *xenstore_private; } xenhost_t; typedef struct xenhost_ops {
@@ -228,6 +231,17 @@ typedef struct xenhost_ops {int (*alloc_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages);void (*free_ballooned_pages)(xenhost_t *xh,int nr_pages,struct page **pages); +/* +* xenbus: as part of xenbus-init, frontend/backend need to talk to the +* correct xenbus. This might be a local xenstore (backend) or might +* be a XS_PV/XS_HVM interface (frontend). We bootstrap these with +* evtchn/gfn parameters from (*setup_xs)(). +* +* Once done, stash the xenhost_t * in xen_bus_type, xenbus_device or +* xenbus_watch and then the frontend and backend devices implicitly +* use the correct interface. +*/ +int (*setup_xs)(xenhost_t *xh); } xenhost_ops_t;extern xenhost_t *xh_default, *xh_remote;
@@ -279,4 +293,10 @@ static inline void xenhost_probe_vcpu_id(xenhost_t *xh, int cpu) (xh->ops->probe_vcpu_id)(xh, cpu); } +static inline void xenhost_setup_xs (xenhost_t *xh) +{ +if (xh) + (xh->ops->setup_xs)(xh); +} +#endif /* __XENHOST_H */
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 12/16] xen/xenbus: support xenbus frontend/backend with xenhost_t
Quoted 110 lines · Ankur Arora
As part of xenbus init, both frontend, backend interfaces need to talk on the correct xenbus. This might be a local xenstore (backend) or might be a XS_PV/XS_HVM interface (frontend) which needs to talk over xenbus with the remote xenstored. We bootstrap all of these with evtchn/gfn parameters from (*setup_xs)().
Given this we can do appropriate device discovery (in case of frontend) and device connectivity for the backend.
Once done, we stash thexenhost_t* inxen_bus_type,xenbus_deviceorxenbus_watchand then the frontend and backend devices implicitly use the correct interface.The rest of patch is just changing the interfaces where needed.
Signed-off-by Ankur Arora <[email protected]>--- drivers/block/xen-blkback/blkback.c | 10 +- drivers/net/xen-netfront.c | 14 +- drivers/pci/xen-pcifront.c | 4 +- drivers/xen/cpu_hotplug.c | 4 +- drivers/xen/manage.c | 28 +-- drivers/xen/xen-balloon.c | 8 +- drivers/xen/xenbus/xenbus.h | 45 ++-- drivers/xen/xenbus/xenbus_client.c | 32 +-- drivers/xen/xenbus/xenbus_comms.c | 121 +++++----- drivers/xen/xenbus/xenbus_dev_backend.c | 30 ++- drivers/xen/xenbus/xenbus_dev_frontend.c | 22 +- drivers/xen/xenbus/xenbus_probe.c | 246 +++++++++++++-------- drivers/xen/xenbus/xenbus_probe_backend.c | 19 +- drivers/xen/xenbus/xenbus_probe_frontend.c | 65 +++--- drivers/xen/xenbus/xenbus_xs.c | 188 +++++++++------- include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 54 +++-- include/xen/xenhost.h | 20 ++ 18 files changed, 536 insertions(+), 377 deletions(-)drivers/xen/xenbus/xenbus_dev_frontend.c +11
-6@@ -58,10 +58,14 @@#include <xen/xenbus.h> #include <xen/xen.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include "xenbus.h" +static xenhost_t *xh; +/* * An element of a list of outstanding transactions, for which we're * still waiting a reply. @@ -312,13 +316,13 @@ static void xenbus_file_free(struct kref *kref)*/ list_for_each_entry_safe (trans, tmp, &u->transactions, list) { -xenbus_transaction_end (trans->handle,1 ); +xenbus_transaction_end (xh, trans->handle,1 );list_del (&trans->list);kfree (trans); }list_for_each_entry_safe (watch, tmp_watch, &u->watches, list) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch); }@@ -450,7 +454,7 @@ static int xenbus_write_transaction(unsigned msg_type, (!strcmp(msg->body, "T") || !strcmp(msg->body, "F"))))return xenbus_command_reply (u,XS_ERROR ,"EINVAL" ); - rc =xenbus_dev_request_and_reply (&msg->hdr, u); + rc =xenbus_dev_request_and_reply (xh, &msg->hdr, u);if (rc && trans) {list_del (&trans->list);kfree (trans);@@ -489,7 +493,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) watch->watch.callback = watch_fired; watch->dev_data = u; - err =register_xenbus_watch (&watch->watch); + err =register_xenbus_watch (xh, &watch->watch);if (err) {free_watch_adapter (watch); rc = err;@@ -500,7 +504,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)list_for_each_entry (watch, &u->watches, list) {if (!strcmp (watch->token, token) && !strcmp (watch->watch.node, path)) { -unregister_xenbus_watch (&watch->watch); +unregister_xenbus_watch (xh, &watch->watch);list_del (&watch->list);free_watch_adapter (watch);break ;@@ -618,8 +622,9 @@ static ssize_t xenbus_file_write(struct file *filp,static int xenbus_file_open (struct inode *inode,struct file *filp) {struct xenbus_file_priv *u; +struct xenstore_private *xs =xs_priv (xh); -if (xen_store_evtchn ==0 ) +if (xs->store_evtchn ==0 )return -ENOENT ;nonseekable_open (inode, filp);
drivers/xen/xenbus/xenbus_dev_frontend.c static int __init xenbus_init(void) · line 698
Quoted 7 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +4
-0@@ -687,6 +692,11 @@ static int __init xenbus_init(void)if (!xen_domain ())return -ENODEV ; +if (xen_driver_domain () &&xen_nested ()) + xh = xh_remote; +else + xh = xh_default;
This precludes any mixed use of L0 and L1 frontends. With this move you make it impossible to e.g. use a driver domain for networking in L1 with a L1-local PV disk, or pygrub in L1 dom0.
Juergen
Re: [RFC PATCH 12/16] xen/xenbus: support xenbus frontend/backend with xenhost_t
Quoted 107 lines · Juergen Gross
Quoted 106 lines · Ankur Arora
As part of xenbus init, both frontend, backend interfaces need to talk on the correct xenbus. This might be a local xenstore (backend) or might be a XS_PV/XS_HVM interface (frontend) which needs to talk over xenbus with the remote xenstored. We bootstrap all of these with evtchn/gfn parameters from (*setup_xs)().
Given this we can do appropriate device discovery (in case of frontend) and device connectivity for the backend.
Once done, we stash thexenhost_t* inxen_bus_type,xenbus_deviceorxenbus_watchand then the frontend and backend devices implicitly use the correct interface.The rest of patch is just changing the interfaces where needed.
Signed-off-by Ankur Arora <[email protected]>---
drivers/block/xen-blkback/blkback.c | 10 +- drivers/net/xen-netfront.c | 14 +- drivers/pci/xen-pcifront.c | 4 +- drivers/xen/cpu_hotplug.c | 4 +- drivers/xen/manage.c | 28 +-- drivers/xen/xen-balloon.c | 8 +- drivers/xen/xenbus/xenbus.h | 45 ++-- drivers/xen/xenbus/xenbus_client.c | 32 +-- drivers/xen/xenbus/xenbus_comms.c | 121 +++++----- drivers/xen/xenbus/xenbus_dev_backend.c | 30 ++- drivers/xen/xenbus/xenbus_dev_frontend.c | 22 +- drivers/xen/xenbus/xenbus_probe.c | 246 +++++++++++++-------- drivers/xen/xenbus/xenbus_probe_backend.c | 19 +-drivers/xen/xenbus/xenbus_probe_frontend.c| 65 +++--- drivers/xen/xenbus/xenbus_xs.c | 188 +++++++++------- include/xen/xen-ops.h | 3 + include/xen/xenbus.h | 54 +++-- include/xen/xenhost.h | 20 ++18 files changed, 536 insertions(+), 377 deletions(-)drivers/xen/xenbus/xenbus_dev_frontend.c +8
-4@@ -58,10 +58,14 @@ #include <xen/xenbus.h> #include <xen/xen.h> +#include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include "xenbus.h" +static xenhost_t *xh; + /** An element of a list of outstanding transactions, for which we're * still waiting a reply. @@ -312,13 +316,13 @@ static void xenbus_file_free(struct kref *kref)*/ list_for_each_entry_safe(trans, tmp, &u->transactions, list) { - xenbus_transaction_end(trans->handle, 1); + xenbus_transaction_end(xh, trans->handle, 1); list_del(&trans->list); kfree(trans); } list_for_each_entry_safe(watch, tmp_watch, &u->watches, list) { - unregister_xenbus_watch(&watch->watch); + unregister_xenbus_watch(xh, &watch->watch); list_del(&watch->list); free_watch_adapter(watch); }@@ -450,7 +454,7 @@ static int xenbus_write_transaction(unsigned msg_type, (!strcmp(msg->body, "T") || !strcmp(msg->body, "F")))) return xenbus_command_reply(u, XS_ERROR, "EINVAL"); - rc = xenbus_dev_request_and_reply(&msg->hdr, u); + rc = xenbus_dev_request_and_reply(xh, &msg->hdr, u); if (rc && trans) { list_del(&trans->list); kfree(trans);@@ -489,7 +493,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) watch->watch.callback = watch_fired; watch->dev_data = u; - err = register_xenbus_watch(&watch->watch); + err = register_xenbus_watch(xh, &watch->watch); if (err) { free_watch_adapter(watch); rc = err;@@ -500,7 +504,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) list_for_each_entry(watch, &u->watches, list) {if (!strcmp(watch->token, token) && !strcmp(watch->watch.node, path)) { -
unregister_xenbus_watch(&watch->watch); +unregister_xenbus_watch(xh, &watch->watch);list_del(&watch->list);free_watch_adapter(watch); break;drivers/xen/xenbus/xenbus_dev_frontend.c +2
-1@@ -618,8 +622,9 @@ static ssize_t xenbus_file_write(struct file *filp, static int xenbus_file_open(struct inode *inode, struct file *filp) { struct xenbus_file_priv *u; + struct xenstore_private *xs = xs_priv(xh); - if (xen_store_evtchn == 0) + if (xs->store_evtchn == 0) return -ENOENT; nonseekable_open(inode, filp);@@ -687,6 +692,11 @@ static int __init xenbus_init(void) if (!xen_domain()) return -ENODEV;
Quoted 8 lines
drivers/xen/xenbus/xenbus_dev_frontend.c static int __init xenbus_init(void) · line 698
Quoted 4 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +4
-0+ if (xen_driver_domain() && xen_nested()) + xh = xh_remote; + else + xh = xh_default;This precludes any mixed use of L0 and L1 frontends. With this move you make it impossible to e.g. use a driver domain for networking in L1 with a L1-local PV disk, or pygrub in L1 dom0.
Ah, yes. I hadn't thought about that case.
Let me see how I can rework this interface.
Ankur
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 13/16 drivers/xen: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraMechanical changes, now most of these calls take xenhost_t * as parameter.
--- drivers/xen/cpu_hotplug.c | 14 ++++++------- drivers/xen/gntalloc.c | 13 ++++++++---- drivers/xen/gntdev.c | 16 +++++++++++---- drivers/xen/manage.c | 37 ++++++++++++++++++----------------- drivers/xen/platform-pci.c | 12 +++++++----- drivers/xen/sys-hypervisor.c | 12 ++++++++---- drivers/xen/xen-balloon.c | 10 +++++++--- drivers/xen/xenfs/xenstored.c | 7 ++++--- 8 files changed, 73 insertions(+), 48 deletions(-)
drivers/xen/cpu_hotplug.c +7 -7
@@ -31,13 +31,13 @@ static void disable_hotplug_cpu(int cpu)unlock_device_hotplug (); } -static int vcpu_online (unsigned int cpu) +static int vcpu_online (xenhost_t *xh,unsigned int cpu) {int err;char dir[16 ], state[16 ];sprintf (dir,"cpu/%u" , cpu); - err =xenbus_scanf (xh_default,XBT_NIL , dir,"availability" ,"%15s" , state); + err =xenbus_scanf (xh,XBT_NIL , dir,"availability" ,"%15s" , state);if (err !=1 ) {if (!xen_initial_domain ())pr_err ("Unable to read cpu state\n" );
@@ -52,12 +52,12 @@ static int vcpu_online(unsigned int cpu)pr_err ("unknown state(%s) on CPU%d\n" , state, cpu);return -EINVAL ; } -static void vcpu_hotplug (unsigned int cpu) +static void vcpu_hotplug (xenhost_t *xh,unsigned int cpu) {if (!cpu_possible (cpu))return ; -switch (vcpu_online (cpu)) { +switch (vcpu_online (xh, cpu)) {case 1 :enable_hotplug_cpu (cpu);break ;
@@ -78,7 +78,7 @@ static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, cpustr =strstr (path,"cpu/" );if (cpustr !=NULL ) {sscanf (cpustr,"cpu/%u" , &cpu); -vcpu_hotplug (cpu); +vcpu_hotplug (watch->xh, cpu); } }
@@ -93,7 +93,7 @@ static int setup_cpu_watcher(struct notifier_block *notifier, (void )register_xenbus_watch (xh_default, &cpu_watch);for_each_possible_cpu (cpu) { -if (vcpu_online (cpu) ==0 ) { +if (vcpu_online (cpu_watch.xh, cpu) ==0 ) { (void )cpu_down (cpu);set_cpu_present (cpu, false); }
@@ -114,7 +114,7 @@ static int __init setup_vcpu_hotplug_event(void)#endif return -ENODEV ; -register_xenstore_notifier (&xsn_cpu); +register_xenstore_notifier (xh_default, &xsn_cpu);return 0 ; }
drivers/xen/gntalloc.c +9 -4
@@ -79,6 +79,8 @@ static LIST_HEAD(gref_list);static DEFINE_MUTEX (gref_mutex);static int gref_size; +static xenhost_t *xh; +struct notify_info {uint16_t pgoff:12 ;/* Bits 0-11: Offset of the byte to clear */ uint16_t flags:2 ;/* Bits 12-13: Unmap notification flags */
@@ -144,7 +146,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op, }/* Grant foreign access to the page. */ - rc =gnttab_grant_foreign_access (op->domid, + rc =gnttab_grant_foreign_access (xh, op->domid,xen_page_to_gfn (gref->page), readonly);if (rc <0 )
@@ -196,13 +198,13 @@ static void __del_gref(struct gntalloc_gref *gref) gref->notify.flags =0 ;if (gref->gref_id) { -if (gnttab_query_foreign_access (gref->gref_id)) +if (gnttab_query_foreign_access (xh, gref->gref_id))return ; -if (!gnttab_end_foreign_access_ref (gref->gref_id,0 )) +if (!gnttab_end_foreign_access_ref (xh, gref->gref_id,0 ))return ; -gnttab_free_grant_reference (gref->gref_id); +gnttab_free_grant_reference (xh, gref->gref_id); } gref_size--;
@@ -586,6 +588,9 @@ static int __init gntalloc_init(void)if (!xen_domain ())return -ENODEV ; +/* Limit to default xenhost for now. */ + xh = xh_default; + err =misc_register (&gntalloc_miscdev);if (err !=0 ) {pr_err ("Could not register misc gntalloc device\n" );
drivers/xen/gntdev.c +12 -4
@@ -67,6 +67,8 @@ static atomic_t pages_mapped = ATOMIC_INIT(0);static int use_ptemod;#define populate_freeable_maps use_ptemod +static xenhost_t *xh; +static int unmap_grant_pages (struct gntdev_grant_map *map,int offset,int pages);
@@ -114,7 +116,7 @@ static void gntdev_free_map(struct gntdev_grant_map *map) } else#endif if (map->pages) -gnttab_free_pages (map->count, map->pages); +gnttab_free_pages (xh, map->count, map->pages);#ifdef CONFIG_XEN_GRANT_DMA_ALLOC kfree (map->frames);
@@ -183,7 +185,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, add->dma_bus_addr = args.dev_bus_addr; } else#endif -if (gnttab_alloc_pages (count, add->pages)) +if (gnttab_alloc_pages (xh, count, add->pages)) goto err;for (i =0 ; i < count; i++) {
@@ -339,7 +341,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map) }pr_debug ("map %d+%d\n" , map->index, map->count); - err =gnttab_map_refs (map->map_ops, use_ptemod ? map->kmap_ops :NULL , + err =gnttab_map_refs (xh, map->map_ops, use_ptemod ? map->kmap_ops :NULL , map->pages, map->count);if (err)return err;
@@ -385,6 +387,7 @@ static int __unmap_grant_pages(struct gntdev_grant_map *map, int offset, unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset :NULL ; unmap_data.pages = map->pages + offset; unmap_data.count = pages; + unmap_data.xh = xh; err =gnttab_unmap_refs_sync (&unmap_data);if (err)
@@ -877,7 +880,7 @@ static int gntdev_copy(struct gntdev_copy_batch *batch) {unsigned int i; -gnttab_batch_copy (batch->ops, batch->nr_ops); +gnttab_batch_copy (xh, batch->ops, batch->nr_ops);gntdev_put_pages (batch);/*
@@ -1210,8 +1213,13 @@ static int __init gntdev_init(void)if (!xen_domain ())return -ENODEV ; +/* +* Use for mappings grants related to the default xenhost. +*/ + xh = xh_default; use_ptemod = !xen_feature (XENFEAT_auto_translated_physmap); + err =misc_register (&gntdev_miscdev);if (err !=0 ) {pr_err ("Could not register gntdev device\n" );
drivers/xen/manage.c +19 -18
@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch,return ; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - str = (char *)xenbus_read (xh_default, xbt,"control" ,"shutdown" ,NULL ); + str = (char *)xenbus_read (watch->xh, xbt,"control" ,"shutdown" ,NULL );/* Ignore read errors and empty reads. */ if (XENBUS_IS_ERR_READ (str)) { -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }
@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch,/* Only acknowledge commands which we are prepared to handle. */ if (idx <ARRAY_SIZE (shutdown_handlers)) -xenbus_write (xh_default, xbt,"control" ,"shutdown" ,"" ); +xenbus_write (watch->xh, xbt,"control" ,"shutdown" ,"" ); - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) {kfree (str); goto again;
@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,int err; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - err =xenbus_scanf (xh_default, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key); + err =xenbus_scanf (watch->xh, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key);if (err <0 ) {/* * The Xenstore watch fires directly after registering it and
@@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,if (err != -ENOENT && err != -ERANGE )pr_err ("Error %d reading sysrq code in control/sysrq\n" , err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }if (sysrq_key !='\0' ) { - err =xenbus_printf (xh_default, xbt,"control" ,"sysrq" ,"%c" ,'\0' ); + err =xenbus_printf (watch->xh, xbt,"control" ,"sysrq" ,"%c" ,'\0' );if (err) {pr_err ("%s: Error %d writing sysrq in control/sysrq\n" , __func__, err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; } } - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) goto again;
@@ -324,14 +324,14 @@ static struct notifier_block xen_reboot_nb = { .notifier_call = poweroff_nb, }; -static int setup_shutdown_watcher (void ) +static int setup_shutdown_watcher (xenhost_t *xh) {int err;int idx;#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))char node[FEATURE_PATH_SIZE ]; - err =register_xenbus_watch (xh_default, &shutdown_watch); + err =register_xenbus_watch (xh, &shutdown_watch);if (err) {pr_err ("Failed to set shutdown watcher\n" );return err;
@@ -339,7 +339,7 @@ static int setup_shutdown_watcher(void)#ifdef CONFIG_MAGIC_SYSRQ - err =register_xenbus_watch (xh_default, &sysrq_watch); + err =register_xenbus_watch (xh, &sysrq_watch);if (err) {pr_err ("Failed to set sysrq watcher\n" );return err;
@@ -351,7 +351,7 @@ static int setup_shutdown_watcher(void)continue ;snprintf (node,FEATURE_PATH_SIZE ,"feature-%s" , shutdown_handlers[idx].command); - err =xenbus_printf (xh_default,XBT_NIL ,"control" , node,"%u" ,1 ); + err =xenbus_printf (xh,XBT_NIL ,"control" , node,"%u" ,1 );if (err) {pr_err ("%s: Error %d writing %s\n" , __func__, err, node);
@@ -364,9 +364,9 @@ static int setup_shutdown_watcher(void)static int shutdown_event (struct notifier_block *notifier,unsigned long event, -void *data) +void *xh) { -setup_shutdown_watcher (); +setup_shutdown_watcher ((xenhost_t *) xh);return NOTIFY_DONE ; }
@@ -378,7 +378,8 @@ int xen_setup_shutdown_event(void)if (!xen_domain ())return -ENODEV ; -register_xenstore_notifier (&xenstore_notifier); + +register_xenstore_notifier (xh_default, &xenstore_notifier);register_reboot_notifier (&xen_reboot_nb);return 0 ;
drivers/xen/platform-pci.c +7 -5
@@ -154,18 +154,20 @@ static int platform_pci_probe(struct pci_dev *pdev, } } - max_nr_gframes =gnttab_max_grant_frames (); + max_nr_gframes =gnttab_max_grant_frames (xh_default); grant_frames =alloc_xen_mmio (PAGE_SIZE * max_nr_gframes); - ret =gnttab_setup_auto_xlat_frames (grant_frames); + ret =gnttab_setup_auto_xlat_frames (xh_default, grant_frames);if (ret) goto out; - ret =gnttab_init (); + +/* HVM only, we don't need xh_remote */ + ret =gnttab_init (xh_default);if (ret) goto grant_out; -xenbus_probe (NULL ); +__xenbus_probe (xh_default->xenstore_private);return 0 ; grant_out: -gnttab_free_auto_xlat_frames (); +gnttab_free_auto_xlat_frames (xh_default); out:pci_release_region (pdev,0 ); mem_out:
drivers/xen/sys-hypervisor.c +8 -4
@@ -14,6 +14,7 @@#include <linux/err.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -141,15 +142,15 @@ static ssize_t uuid_show_fallback(struct hyp_sysfs_attr *attr, char *buffer) {char *vm, *val;int ret; -extern int xenstored_ready; +/* Disable for now: xenstored_ready is private to xenbus if (!xenstored_ready) -return -EBUSY ; +return -EBUSY;*/ - vm =xenbus_read (XBT_NIL ,"vm" ,"" ,NULL ); + vm =xenbus_read (xh_default,XBT_NIL ,"vm" ,"" ,NULL );if (IS_ERR (vm))return PTR_ERR (vm); - val =xenbus_read (XBT_NIL , vm,"uuid" ,NULL ); + val =xenbus_read (xh_default,XBT_NIL , vm,"uuid" ,NULL );kfree (vm);if (IS_ERR (val))return PTR_ERR (val);
@@ -602,6 +603,9 @@ static struct kobj_type hyp_sysfs_kobj_type = { .sysfs_ops = &hyp_sysfs_ops, }; +/* +* For now, default xenhost only. +*/ static int __init hypervisor_subsys_init (void ) {if (!xen_domain ())
drivers/xen/xen-balloon.c +7 -3
@@ -40,6 +40,7 @@#include <xen/xen.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/balloon.h> #include <xen/xenbus.h> #include <xen/features.h>
@@ -99,11 +100,11 @@ static struct xenbus_watch target_watch = {static int balloon_init_watcher (struct notifier_block *notifier,unsigned long event, -void *data) +void *xh) {int err; - err =register_xenbus_watch (xh_default, &target_watch); + err =register_xenbus_watch (xh, &target_watch);if (err)pr_err ("Failed to set balloon watcher\n" );
@@ -120,7 +121,10 @@ void xen_balloon_init(void)register_xen_selfballooning (&balloon_dev); -register_xenstore_notifier (&xenstore_notifier); +/* +* ballooning is only concerned with the default xenhost. +*/ +register_xenstore_notifier (xh_default, &xenstore_notifier); }EXPORT_SYMBOL_GPL (xen_balloon_init);
drivers/xen/xenfs/xenstored.c +4 -3
@@ -8,6 +8,7 @@#include <xen/xenbus.h> #include "xenfs.h" +#include "../xenbus/xenbus.h" /* FIXME */ static ssize_t xsd_read (struct file *file,char __user *buf,size_t size,loff_t *off)
@@ -25,7 +26,7 @@ static int xsd_release(struct inode *inode, struct file *file)static int xsd_kva_open (struct inode *inode,struct file *file) { file->private_data = (void *)kasprintf (GFP_KERNEL ,"0x%p" , - xen_store_interface); +xs_priv (xh_default)->store_interface);if (!file->private_data)return -ENOMEM ;return 0 ;
@@ -39,7 +40,7 @@ static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ;if (remap_pfn_range (vma, vma->vm_start, -virt_to_pfn (xen_store_interface), +virt_to_pfn (xs_priv (xh_default)->store_interface), size, vma->vm_page_prot))return -EAGAIN ;
@@ -56,7 +57,7 @@ const struct file_operations xsd_kva_file_ops = {static int xsd_port_open (struct inode *inode,struct file *file) { file->private_data = (void *)kasprintf (GFP_KERNEL ,"%d" , - xen_store_evtchn); +xs_priv (xh_default)->store_evtchn);if (!file->private_data)return -ENOMEM ;return 0 ;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 13/16 drivers/xen: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraMechanical changes, now most of these calls take xenhost_t * as parameter.
--- drivers/xen/cpu_hotplug.c | 14 ++++++------- drivers/xen/gntalloc.c | 13 ++++++++---- drivers/xen/gntdev.c | 16 +++++++++++---- drivers/xen/manage.c | 37 ++++++++++++++++++----------------- drivers/xen/platform-pci.c | 12 +++++++----- drivers/xen/sys-hypervisor.c | 12 ++++++++---- drivers/xen/xen-balloon.c | 10 +++++++--- drivers/xen/xenfs/xenstored.c | 7 ++++--- 8 files changed, 73 insertions(+), 48 deletions(-)
drivers/xen/cpu_hotplug.c +7 -7
@@ -31,13 +31,13 @@ static void disable_hotplug_cpu(int cpu)unlock_device_hotplug (); } -static int vcpu_online (unsigned int cpu) +static int vcpu_online (xenhost_t *xh,unsigned int cpu) {int err;char dir[16 ], state[16 ];sprintf (dir,"cpu/%u" , cpu); - err =xenbus_scanf (xh_default,XBT_NIL , dir,"availability" ,"%15s" , state); + err =xenbus_scanf (xh,XBT_NIL , dir,"availability" ,"%15s" , state);if (err !=1 ) {if (!xen_initial_domain ())pr_err ("Unable to read cpu state\n" );
@@ -52,12 +52,12 @@ static int vcpu_online(unsigned int cpu)pr_err ("unknown state(%s) on CPU%d\n" , state, cpu);return -EINVAL ; } -static void vcpu_hotplug (unsigned int cpu) +static void vcpu_hotplug (xenhost_t *xh,unsigned int cpu) {if (!cpu_possible (cpu))return ; -switch (vcpu_online (cpu)) { +switch (vcpu_online (xh, cpu)) {case 1 :enable_hotplug_cpu (cpu);break ;
@@ -78,7 +78,7 @@ static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, cpustr =strstr (path,"cpu/" );if (cpustr !=NULL ) {sscanf (cpustr,"cpu/%u" , &cpu); -vcpu_hotplug (cpu); +vcpu_hotplug (watch->xh, cpu); } }
@@ -93,7 +93,7 @@ static int setup_cpu_watcher(struct notifier_block *notifier, (void )register_xenbus_watch (xh_default, &cpu_watch);for_each_possible_cpu (cpu) { -if (vcpu_online (cpu) ==0 ) { +if (vcpu_online (cpu_watch.xh, cpu) ==0 ) { (void )cpu_down (cpu);set_cpu_present (cpu, false); }
@@ -114,7 +114,7 @@ static int __init setup_vcpu_hotplug_event(void)#endif return -ENODEV ; -register_xenstore_notifier (&xsn_cpu); +register_xenstore_notifier (xh_default, &xsn_cpu);return 0 ; }
drivers/xen/gntalloc.c +9 -4
@@ -79,6 +79,8 @@ static LIST_HEAD(gref_list);static DEFINE_MUTEX (gref_mutex);static int gref_size; +static xenhost_t *xh; +struct notify_info {uint16_t pgoff:12 ;/* Bits 0-11: Offset of the byte to clear */ uint16_t flags:2 ;/* Bits 12-13: Unmap notification flags */
@@ -144,7 +146,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op, }/* Grant foreign access to the page. */ - rc =gnttab_grant_foreign_access (op->domid, + rc =gnttab_grant_foreign_access (xh, op->domid,xen_page_to_gfn (gref->page), readonly);if (rc <0 )
@@ -196,13 +198,13 @@ static void __del_gref(struct gntalloc_gref *gref) gref->notify.flags =0 ;if (gref->gref_id) { -if (gnttab_query_foreign_access (gref->gref_id)) +if (gnttab_query_foreign_access (xh, gref->gref_id))return ; -if (!gnttab_end_foreign_access_ref (gref->gref_id,0 )) +if (!gnttab_end_foreign_access_ref (xh, gref->gref_id,0 ))return ; -gnttab_free_grant_reference (gref->gref_id); +gnttab_free_grant_reference (xh, gref->gref_id); } gref_size--;
@@ -586,6 +588,9 @@ static int __init gntalloc_init(void)if (!xen_domain ())return -ENODEV ; +/* Limit to default xenhost for now. */ + xh = xh_default; + err =misc_register (&gntalloc_miscdev);if (err !=0 ) {pr_err ("Could not register misc gntalloc device\n" );
drivers/xen/gntdev.c +12 -4
@@ -67,6 +67,8 @@ static atomic_t pages_mapped = ATOMIC_INIT(0);static int use_ptemod;#define populate_freeable_maps use_ptemod +static xenhost_t *xh; +static int unmap_grant_pages (struct gntdev_grant_map *map,int offset,int pages);
@@ -114,7 +116,7 @@ static void gntdev_free_map(struct gntdev_grant_map *map) } else#endif if (map->pages) -gnttab_free_pages (map->count, map->pages); +gnttab_free_pages (xh, map->count, map->pages);#ifdef CONFIG_XEN_GRANT_DMA_ALLOC kfree (map->frames);
@@ -183,7 +185,7 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, add->dma_bus_addr = args.dev_bus_addr; } else#endif -if (gnttab_alloc_pages (count, add->pages)) +if (gnttab_alloc_pages (xh, count, add->pages)) goto err;for (i =0 ; i < count; i++) {
@@ -339,7 +341,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map) }pr_debug ("map %d+%d\n" , map->index, map->count); - err =gnttab_map_refs (map->map_ops, use_ptemod ? map->kmap_ops :NULL , + err =gnttab_map_refs (xh, map->map_ops, use_ptemod ? map->kmap_ops :NULL , map->pages, map->count);if (err)return err;
@@ -385,6 +387,7 @@ static int __unmap_grant_pages(struct gntdev_grant_map *map, int offset, unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset :NULL ; unmap_data.pages = map->pages + offset; unmap_data.count = pages; + unmap_data.xh = xh; err =gnttab_unmap_refs_sync (&unmap_data);if (err)
@@ -877,7 +880,7 @@ static int gntdev_copy(struct gntdev_copy_batch *batch) {unsigned int i; -gnttab_batch_copy (batch->ops, batch->nr_ops); +gnttab_batch_copy (xh, batch->ops, batch->nr_ops);gntdev_put_pages (batch);/*
@@ -1210,8 +1213,13 @@ static int __init gntdev_init(void)if (!xen_domain ())return -ENODEV ; +/* +* Use for mappings grants related to the default xenhost. +*/ + xh = xh_default; use_ptemod = !xen_feature (XENFEAT_auto_translated_physmap); + err =misc_register (&gntdev_miscdev);if (err !=0 ) {pr_err ("Could not register gntdev device\n" );
drivers/xen/manage.c +19 -18
@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch,return ; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - str = (char *)xenbus_read (xh_default, xbt,"control" ,"shutdown" ,NULL ); + str = (char *)xenbus_read (watch->xh, xbt,"control" ,"shutdown" ,NULL );/* Ignore read errors and empty reads. */ if (XENBUS_IS_ERR_READ (str)) { -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }
@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch,/* Only acknowledge commands which we are prepared to handle. */ if (idx <ARRAY_SIZE (shutdown_handlers)) -xenbus_write (xh_default, xbt,"control" ,"shutdown" ,"" ); +xenbus_write (watch->xh, xbt,"control" ,"shutdown" ,"" ); - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) {kfree (str); goto again;
@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,int err; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - err =xenbus_scanf (xh_default, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key); + err =xenbus_scanf (watch->xh, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key);if (err <0 ) {/* * The Xenstore watch fires directly after registering it and
@@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,if (err != -ENOENT && err != -ERANGE )pr_err ("Error %d reading sysrq code in control/sysrq\n" , err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }if (sysrq_key !='\0' ) { - err =xenbus_printf (xh_default, xbt,"control" ,"sysrq" ,"%c" ,'\0' ); + err =xenbus_printf (watch->xh, xbt,"control" ,"sysrq" ,"%c" ,'\0' );if (err) {pr_err ("%s: Error %d writing sysrq in control/sysrq\n" , __func__, err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; } } - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) goto again;
@@ -324,14 +324,14 @@ static struct notifier_block xen_reboot_nb = { .notifier_call = poweroff_nb, }; -static int setup_shutdown_watcher (void ) +static int setup_shutdown_watcher (xenhost_t *xh) {int err;int idx;#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))char node[FEATURE_PATH_SIZE ]; - err =register_xenbus_watch (xh_default, &shutdown_watch); + err =register_xenbus_watch (xh, &shutdown_watch);if (err) {pr_err ("Failed to set shutdown watcher\n" );return err;
@@ -339,7 +339,7 @@ static int setup_shutdown_watcher(void)#ifdef CONFIG_MAGIC_SYSRQ - err =register_xenbus_watch (xh_default, &sysrq_watch); + err =register_xenbus_watch (xh, &sysrq_watch);if (err) {pr_err ("Failed to set sysrq watcher\n" );return err;
@@ -351,7 +351,7 @@ static int setup_shutdown_watcher(void)continue ;snprintf (node,FEATURE_PATH_SIZE ,"feature-%s" , shutdown_handlers[idx].command); - err =xenbus_printf (xh_default,XBT_NIL ,"control" , node,"%u" ,1 ); + err =xenbus_printf (xh,XBT_NIL ,"control" , node,"%u" ,1 );if (err) {pr_err ("%s: Error %d writing %s\n" , __func__, err, node);
@@ -364,9 +364,9 @@ static int setup_shutdown_watcher(void)static int shutdown_event (struct notifier_block *notifier,unsigned long event, -void *data) +void *xh) { -setup_shutdown_watcher (); +setup_shutdown_watcher ((xenhost_t *) xh);return NOTIFY_DONE ; }
@@ -378,7 +378,8 @@ int xen_setup_shutdown_event(void)if (!xen_domain ())return -ENODEV ; -register_xenstore_notifier (&xenstore_notifier); + +register_xenstore_notifier (xh_default, &xenstore_notifier);register_reboot_notifier (&xen_reboot_nb);return 0 ;
drivers/xen/platform-pci.c +7 -5
@@ -154,18 +154,20 @@ static int platform_pci_probe(struct pci_dev *pdev, } } - max_nr_gframes =gnttab_max_grant_frames (); + max_nr_gframes =gnttab_max_grant_frames (xh_default); grant_frames =alloc_xen_mmio (PAGE_SIZE * max_nr_gframes); - ret =gnttab_setup_auto_xlat_frames (grant_frames); + ret =gnttab_setup_auto_xlat_frames (xh_default, grant_frames);if (ret) goto out; - ret =gnttab_init (); + +/* HVM only, we don't need xh_remote */ + ret =gnttab_init (xh_default);if (ret) goto grant_out; -xenbus_probe (NULL ); +__xenbus_probe (xh_default->xenstore_private);return 0 ; grant_out: -gnttab_free_auto_xlat_frames (); +gnttab_free_auto_xlat_frames (xh_default); out:pci_release_region (pdev,0 ); mem_out:
drivers/xen/sys-hypervisor.c +8 -4
@@ -14,6 +14,7 @@#include <linux/err.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <asm/xen/hypervisor.h> #include <asm/xen/hypercall.h>
@@ -141,15 +142,15 @@ static ssize_t uuid_show_fallback(struct hyp_sysfs_attr *attr, char *buffer) {char *vm, *val;int ret; -extern int xenstored_ready; +/* Disable for now: xenstored_ready is private to xenbus if (!xenstored_ready) -return -EBUSY ; +return -EBUSY;*/ - vm =xenbus_read (XBT_NIL ,"vm" ,"" ,NULL ); + vm =xenbus_read (xh_default,XBT_NIL ,"vm" ,"" ,NULL );if (IS_ERR (vm))return PTR_ERR (vm); - val =xenbus_read (XBT_NIL , vm,"uuid" ,NULL ); + val =xenbus_read (xh_default,XBT_NIL , vm,"uuid" ,NULL );kfree (vm);if (IS_ERR (val))return PTR_ERR (val);
@@ -602,6 +603,9 @@ static struct kobj_type hyp_sysfs_kobj_type = { .sysfs_ops = &hyp_sysfs_ops, }; +/* +* For now, default xenhost only. +*/ static int __init hypervisor_subsys_init (void ) {if (!xen_domain ())
drivers/xen/xen-balloon.c +7 -3
@@ -40,6 +40,7 @@#include <xen/xen.h> #include <xen/interface/xen.h> +#include <xen/xenhost.h> #include <xen/balloon.h> #include <xen/xenbus.h> #include <xen/features.h>
@@ -99,11 +100,11 @@ static struct xenbus_watch target_watch = {static int balloon_init_watcher (struct notifier_block *notifier,unsigned long event, -void *data) +void *xh) {int err; - err =register_xenbus_watch (xh_default, &target_watch); + err =register_xenbus_watch (xh, &target_watch);if (err)pr_err ("Failed to set balloon watcher\n" );
@@ -120,7 +121,10 @@ void xen_balloon_init(void)register_xen_selfballooning (&balloon_dev); -register_xenstore_notifier (&xenstore_notifier); +/* +* ballooning is only concerned with the default xenhost. +*/ +register_xenstore_notifier (xh_default, &xenstore_notifier); }EXPORT_SYMBOL_GPL (xen_balloon_init);
drivers/xen/xenfs/xenstored.c +4 -3
@@ -8,6 +8,7 @@#include <xen/xenbus.h> #include "xenfs.h" +#include "../xenbus/xenbus.h" /* FIXME */ static ssize_t xsd_read (struct file *file,char __user *buf,size_t size,loff_t *off)
@@ -25,7 +26,7 @@ static int xsd_release(struct inode *inode, struct file *file)static int xsd_kva_open (struct inode *inode,struct file *file) { file->private_data = (void *)kasprintf (GFP_KERNEL ,"0x%p" , - xen_store_interface); +xs_priv (xh_default)->store_interface);if (!file->private_data)return -ENOMEM ;return 0 ;
@@ -39,7 +40,7 @@ static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)return -EINVAL ;if (remap_pfn_range (vma, vma->vm_start, -virt_to_pfn (xen_store_interface), +virt_to_pfn (xs_priv (xh_default)->store_interface), size, vma->vm_page_prot))return -EAGAIN ;
@@ -56,7 +57,7 @@ const struct file_operations xsd_kva_file_ops = {static int xsd_port_open (struct inode *inode,struct file *file) { file->private_data = (void *)kasprintf (GFP_KERNEL ,"%d" , - xen_store_evtchn); +xs_priv (xh_default)->store_evtchn);if (!file->private_data)return -ENOMEM ;return 0 ;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 13/16] drivers/xen: gnttab, evtchn, xenbus API changes
Quoted 21 lines · Ankur Arora
Mechanical changes, now most of these calls take
xenhost_t* as parameter.Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- drivers/xen/cpu_hotplug.c | 14 ++++++------- drivers/xen/gntalloc.c | 13 ++++++++---- drivers/xen/gntdev.c | 16 +++++++++++---- drivers/xen/manage.c | 37 ++++++++++++++++++----------------- drivers/xen/platform-pci.c | 12 +++++++----- drivers/xen/sys-hypervisor.c | 12 ++++++++---- drivers/xen/xen-balloon.c | 10 +++++++--- drivers/xen/xenfs/xenstored.c | 7 ++++--- 8 files changed, 73 insertions(+), 48 deletions(-)drivers/xen/cpu_hotplug.c +0
-0
drivers/xen/cpu_hotplug.c static void disable_hotplug_cpu(int cpu) · line 34
Quoted 5 lines
drivers/xen/cpu_hotplug.c +1
-1@@ -31,13 +31,13 @@ static void disable_hotplug_cpu(int cpu)unlock_device_hotplug (); } -static int vcpu_online (unsigned int cpu) +static int vcpu_online (xenhost_t *xh,unsigned int cpu)
Do we really need xenhost for cpu on/offlinig?
Quoted 74 lines
drivers/xen/manage.c +11
-11@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch,return ; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - str = (char *)xenbus_read (xh_default, xbt,"control" ,"shutdown" ,NULL ); + str = (char *)xenbus_read (watch->xh, xbt,"control" ,"shutdown" ,NULL );/* Ignore read errors and empty reads. */ if (XENBUS_IS_ERR_READ (str)) { -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch,/* Only acknowledge commands which we are prepared to handle. */ if (idx <ARRAY_SIZE (shutdown_handlers)) -xenbus_write (xh_default, xbt,"control" ,"shutdown" ,"" ); +xenbus_write (watch->xh, xbt,"control" ,"shutdown" ,"" ); - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) {kfree (str); goto again;@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,int err; again: - err =xenbus_transaction_start (xh_default, &xbt); + err =xenbus_transaction_start (watch->xh, &xbt);if (err)return ; - err =xenbus_scanf (xh_default, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key); + err =xenbus_scanf (watch->xh, xbt,"control" ,"sysrq" ,"%c" , &sysrq_key);if (err <0 ) {/* * The Xenstore watch fires directly after registering it and @@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path,if (err != -ENOENT && err != -ERANGE )pr_err ("Error %d reading sysrq code in control/sysrq\n" , err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; }if (sysrq_key !='\0' ) { - err =xenbus_printf (xh_default, xbt,"control" ,"sysrq" ,"%c" ,'\0' ); + err =xenbus_printf (watch->xh, xbt,"control" ,"sysrq" ,"%c" ,'\0' );if (err) {pr_err ("%s: Error %d writing sysrq in control/sysrq\n" , __func__, err); -xenbus_transaction_end (xh_default, xbt,1 ); +xenbus_transaction_end (watch->xh, xbt,1 );return ; } } - err =xenbus_transaction_end (xh_default, xbt,0 ); + err =xenbus_transaction_end (watch->xh, xbt,0 );if (err == -EAGAIN ) goto again;
drivers/xen/manage.c static struct notifier_block xen_reboot_nb = { · line 327
Quoted 5 lines
drivers/xen/manage.c +1
-1@@ -324,14 +324,14 @@ static struct notifier_block xen_reboot_nb = { .notifier_call = poweroff_nb, }; -static int setup_shutdown_watcher (void ) +static int setup_shutdown_watcher (xenhost_t *xh)
I think shutdown is purely local, too.
Juergen
Re: [RFC PATCH 13/16] drivers/xen: gnttab, evtchn, xenbus API changes
Quoted 17 lines · Juergen Gross
Quoted 16 lines · Ankur Arora
Mechanical changes, now most of these calls take
xenhost_t* as parameter.Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>---
drivers/xen/cpu_hotplug.c | 14 ++++++------- drivers/xen/gntalloc.c | 13 ++++++++---- drivers/xen/gntdev.c | 16 +++++++++++---- drivers/xen/manage.c | 37 ++++++++++++++++++----------------- drivers/xen/platform-pci.c | 12 +++++++----- drivers/xen/sys-hypervisor.c | 12 ++++++++---- drivers/xen/xen-balloon.c | 10 +++++++---drivers/xen/xenfs/xenstored.c| 7 ++++---8 files changed, 73 insertions(+), 48 deletions(-)
Quoted 11 lines
drivers/xen/cpu_hotplug.c static void disable_hotplug_cpu(int cpu) · line 33
Quoted 9 lines
drivers/xen/cpu_hotplug.c +1
-1@@ -31,13 +31,13 @@ static void disable_hotplug_cpu(int cpu) unlock_device_hotplug(); } -static int vcpu_online (unsigned int cpu) +static int vcpu_online (xenhost_t *xh,unsigned int cpu)Do we really need xenhost for cpu on/offlinig?
I was in two minds about this. We only need it for the xenbus interfaces which could very well have been just xh_default.
However, the xenhost is part of the xenbus_watch state, so I thought it is easier to percolate that down instead of adding xh_default all over the place.
Quoted 74 lines
Quoted 74 lines
drivers/xen/manage.c +0
-0@@ -227,14 +227,14 @@ static void shutdown_handler(struct xenbus_watch *watch, return;again:
- err =xenbus_transaction_start(xh_default, &xbt);
+ err =xenbus_transaction_start(watch->xh, &xbt);
if (err)
return;
- str = (char *)xenbus_read(xh_default, xbt, "control", "shutdown", NULL);
+ str = (char *)xenbus_read(watch->xh, xbt, "control", "shutdown", NULL);
/* Ignore read errors and empty reads. */
if (XENBUS_IS_ERR_READ(str)) {
-xenbus_transaction_end(xh_default, xbt, 1);
+xenbus_transaction_end(watch->xh, xbt, 1);
return;
}drivers/xen/manage.c +2
-2@@ -245,9 +245,9 @@ static void shutdown_handler(struct xenbus_watch *watch, /* Only acknowledge commands which we are prepared to handle. */ if (idx < ARRAY_SIZE(shutdown_handlers)) - xenbus_write(xh_default, xbt, "control", "shutdown", ""); + xenbus_write(watch->xh, xbt, "control", "shutdown", ""); - err = xenbus_transaction_end(xh_default, xbt, 0); + err = xenbus_transaction_end(watch->xh, xbt, 0); if (err == -EAGAIN) { kfree(str); goto again;@@ -272,10 +272,10 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path, int err;again:
- err =xenbus_transaction_start(xh_default, &xbt);
+ err =xenbus_transaction_start(watch->xh, &xbt);
if (err)
return;
- err =xenbus_scanf(xh_default, xbt, "control", "sysrq", "%c", &sysrq_key);
+ err =xenbus_scanf(watch->xh, xbt, "control", "sysrq", "%c", &sysrq_key);
if (err < 0) {
/*
* The Xenstore watch fires directly after registering it anddrivers/xen/manage.c +4
-4@@ -287,21 +287,21 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *path, if (err != -ENOENT && err != -ERANGE) pr_err("Error %d reading sysrq code in control/sysrq\n", err); - xenbus_transaction_end(xh_default, xbt, 1); + xenbus_transaction_end(watch->xh, xbt, 1); return; } if (sysrq_key != '\0') { - err = xenbus_printf(xh_default, xbt, "control", "sysrq", "%c", '\0'); + err = xenbus_printf(watch->xh, xbt, "control", "sysrq", "%c",'\0' ); if (err) { pr_err("%s: Error %d writing sysrq in control/sysrq\n", __func__, err); - xenbus_transaction_end(xh_default, xbt, 1); + xenbus_transaction_end(watch->xh, xbt, 1); return; } } - err = xenbus_transaction_end(xh_default, xbt, 0); + err = xenbus_transaction_end(watch->xh, xbt, 0); if (err == -EAGAIN)
Quoted 8 lines
drivers/xen/manage.c static struct notifier_block xen_reboot_nb = { · line 326
Quoted 6 lines
drivers/xen/manage.c +1
-1goto again;@@ -324,14 +324,14 @@ static struct notifier_block xen_reboot_nb = { .notifier_call = poweroff_nb, }; -static int setup_shutdown_watcher (void ) +static int setup_shutdown_watcher (xenhost_t *xh)I think shutdown is purely local, too.
Yes, I introduced xenhost for the same reason as above.
I agree that either of these cases (and similar others) have no use for the concept of xenhost. Do you think it makes sense for these to pass NULL instead and the underlying interface would just assume xh_default.
Ankur
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 14/16 xen/blk: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraFor the most part, we now pass xenhost_t * as a parameter.
--- drivers/block/xen-blkback/blkback.c | 34 +++++---- drivers/block/xen-blkback/common.h | 2 +- drivers/block/xen-blkback/xenbus.c | 63 ++++++++--------- drivers/block/xen-blkfront.c | 103 +++++++++++++++------------- 4 files changed, 107 insertions(+), 95 deletions(-)
drivers/block/xen-blkback/blkback.c +20 -14
@@ -142,7 +142,7 @@ static inline bool persistent_gnt_timeout(struct persistent_gnt *persistent_gnt) HZ * xen_blkif_pgrant_timeout); } -static inline int get_free_page (struct xen_blkif_ring *ring,struct page **page) +static inline int get_free_page (xenhost_t *xh,struct xen_blkif_ring *ring,struct page **page) {unsigned long flags;
@@ -150,7 +150,7 @@ static inline int get_free_page(struct xen_blkif_ring *ring, struct page **page)if (list_empty (&ring->free_pages)) {BUG_ON (ring->free_pages_num !=0 );spin_unlock_irqrestore (&ring->free_pages_lock, flags); -return gnttab_alloc_pages (1 , page); +return gnttab_alloc_pages (xh,1 , page); }BUG_ON (ring->free_pages_num ==0 ); page[0] = list_first_entry(&ring->free_pages, struct page, lru);
@@ -174,7 +174,7 @@ static inline void put_free_pages(struct xen_blkif_ring *ring, struct page **pagspin_unlock_irqrestore (&ring->free_pages_lock, flags); } -static inline void shrink_free_pagepool (struct xen_blkif_ring *ring,int num) +static inline void shrink_free_pagepool (xenhost_t *xh,struct xen_blkif_ring *ring,int num) {/* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ struct page *page[NUM_BATCH_FREE_PAGES ];
@@ -190,14 +190,14 @@ static inline void shrink_free_pagepool(struct xen_blkif_ring *ring, int num) ring->free_pages_num--;if (++num_pages ==NUM_BATCH_FREE_PAGES ) {spin_unlock_irqrestore (&ring->free_pages_lock, flags); -gnttab_free_pages (num_pages, page); +gnttab_free_pages (xh, num_pages, page);spin_lock_irqsave (&ring->free_pages_lock, flags); num_pages =0 ; } }spin_unlock_irqrestore (&ring->free_pages_lock, flags);if (num_pages !=0 ) -gnttab_free_pages (num_pages, page); +gnttab_free_pages (xh, num_pages, page); }#define vaddr (page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))
@@ -301,8 +301,8 @@ static void put_persistent_gnt(struct xen_blkif_ring *ring,atomic_dec (&ring->persistent_gnt_in_use); } -static void free_persistent_gnts (struct xen_blkif_ring *ring,struct rb_root *root, -unsigned int num) +static void free_persistent_gnts (xenhost_t *xh,struct xen_blkif_ring *ring, +struct rb_root *root,unsigned int num) {struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST ];
@@ -314,6 +314,7 @@ static void free_persistent_gnts(struct xen_blkif_ring *ring, struct rb_root *ro unmap_data.pages = pages; unmap_data.unmap_ops = unmap; unmap_data.kunmap_ops =NULL ; + unmap_data.xh = xh; foreach_grant_safe(persistent_gnt, n, root, node) { BUG_ON(persistent_gnt->handle ==
@@ -351,10 +352,12 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)int segs_to_unmap =0 ;struct xen_blkif_ring *ring =container_of (work,typeof (*ring), persistent_purge_work);struct gntab_unmap_queue_data unmap_data; +struct xenbus_device *dev =xen_blkbk_xenbus (ring->blkif->be); unmap_data.pages = pages; unmap_data.unmap_ops = unmap; unmap_data.kunmap_ops =NULL ; + unmap_data.xh = dev->xh;while (!list_empty (&ring->persistent_purge_list)) { persistent_gnt = list_first_entry(&ring->persistent_purge_list,
@@ -615,6 +618,7 @@ int xen_blkif_schedule(void *arg)struct xen_vbd *vbd = &blkif->vbd;unsigned long timeout;int ret; +struct xenbus_device *dev =xen_blkbk_xenbus (blkif->be);set_freezable ();while (!kthread_should_stop ()) {
@@ -657,7 +661,7 @@ int xen_blkif_schedule(void *arg) }/* Shrink if we have more than xen_blkif_max_buffer_pages */ -shrink_free_pagepool (ring, xen_blkif_max_buffer_pages); +shrink_free_pagepool (dev->xh, ring, xen_blkif_max_buffer_pages);if (log_stats &&time_after (jiffies, ring->st_print))print_stats (ring);
@@ -677,18 +681,18 @@ int xen_blkif_schedule(void *arg)/* * Remove persistent grants and empty the pool of free pages */ -void xen_blkbk_free_caches (struct xen_blkif_ring *ring) +void xen_blkbk_free_caches (xenhost_t *xh,struct xen_blkif_ring *ring) {/* Free all persistent grant pages */ if (!RB_EMPTY_ROOT (&ring->persistent_gnts)) -free_persistent_gnts (ring, &ring->persistent_gnts, +free_persistent_gnts (xh, ring, &ring->persistent_gnts, ring->persistent_gnt_c);BUG_ON (!RB_EMPTY_ROOT (&ring->persistent_gnts)); ring->persistent_gnt_c =0 ;/* Since we are shutting down remove all pages from the buffer */ -shrink_free_pagepool (ring,0 /* All */ ); +shrink_free_pagepool (xh, ring,0 /* All */ ); } static unsigned int xen_blkbk_unmap_prepare(
@@ -784,6 +788,7 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring,struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST ];unsigned int invcount =0 ; +struct xenbus_device *dev =xen_blkbk_xenbus (ring->blkif->be);int ret;while (num) {
@@ -792,7 +797,7 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring, invcount =xen_blkbk_unmap_prepare (ring, pages, batch, unmap, unmap_pages);if (invcount) { - ret =gnttab_unmap_refs (unmap,NULL , unmap_pages, invcount); + ret =gnttab_unmap_refs (dev->xh, unmap,NULL , unmap_pages, invcount);BUG_ON (ret);put_free_pages (ring, unmap_pages, invcount); }
@@ -815,6 +820,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,int last_map =0 , map_until =0 ;int use_persistent_gnts;struct xen_blkif *blkif = ring->blkif; +struct xenbus_device *dev =xen_blkbk_xenbus (blkif->be);/* function call */ use_persistent_gnts = (blkif->vbd.feature_gnt_persistent);
@@ -841,7 +847,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, pages[i]->page = persistent_gnt->page; pages[i]->persistent_gnt = persistent_gnt; }else { -if (get_free_page (ring, &pages[i]->page)) +if (get_free_page (dev->xh, ring, &pages[i]->page)) goto out_of_memory; addr =vaddr (pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page;
@@ -859,7 +865,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, }if (segs_to_map) { - ret =gnttab_map_refs (map,NULL , pages_to_gnt, segs_to_map); + ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, segs_to_map);BUG_ON (ret); }
drivers/block/xen-blkback/common.h +1 -1
@@ -382,7 +382,7 @@ int xen_blkif_xenbus_init(void);irqreturn_t xen_blkif_be_int (int irq,void *dev_id);int xen_blkif_schedule (void *arg);int xen_blkif_purge_persistent (void *arg); -void xen_blkbk_free_caches (struct xen_blkif_ring *ring); +void xen_blkbk_free_caches (xenhost_t *xh,struct xen_blkif_ring *ring);int xen_blkbk_flush_diskcache (struct xenbus_transaction xbt,struct backend_info *be,int state);
drivers/block/xen-blkback/xenbus.c +32 -31
247 lines not on this page · raw message
drivers/block/xen-blkfront.c +54 -49
366 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 14/16 xen/blk: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraFor the most part, we now pass xenhost_t * as a parameter.
--- drivers/block/xen-blkback/blkback.c | 34 +++++---- drivers/block/xen-blkback/common.h | 2 +- drivers/block/xen-blkback/xenbus.c | 63 ++++++++--------- drivers/block/xen-blkfront.c | 103 +++++++++++++++------------- 4 files changed, 107 insertions(+), 95 deletions(-)
drivers/block/xen-blkback/blkback.c +20 -14
@@ -142,7 +142,7 @@ static inline bool persistent_gnt_timeout(struct persistent_gnt *persistent_gnt) HZ * xen_blkif_pgrant_timeout); } -static inline int get_free_page (struct xen_blkif_ring *ring,struct page **page) +static inline int get_free_page (xenhost_t *xh,struct xen_blkif_ring *ring,struct page **page) {unsigned long flags;
@@ -150,7 +150,7 @@ static inline int get_free_page(struct xen_blkif_ring *ring, struct page **page)if (list_empty (&ring->free_pages)) {BUG_ON (ring->free_pages_num !=0 );spin_unlock_irqrestore (&ring->free_pages_lock, flags); -return gnttab_alloc_pages (1 , page); +return gnttab_alloc_pages (xh,1 , page); }BUG_ON (ring->free_pages_num ==0 ); page[0] = list_first_entry(&ring->free_pages, struct page, lru);
@@ -174,7 +174,7 @@ static inline void put_free_pages(struct xen_blkif_ring *ring, struct page **pagspin_unlock_irqrestore (&ring->free_pages_lock, flags); } -static inline void shrink_free_pagepool (struct xen_blkif_ring *ring,int num) +static inline void shrink_free_pagepool (xenhost_t *xh,struct xen_blkif_ring *ring,int num) {/* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ struct page *page[NUM_BATCH_FREE_PAGES ];
@@ -190,14 +190,14 @@ static inline void shrink_free_pagepool(struct xen_blkif_ring *ring, int num) ring->free_pages_num--;if (++num_pages ==NUM_BATCH_FREE_PAGES ) {spin_unlock_irqrestore (&ring->free_pages_lock, flags); -gnttab_free_pages (num_pages, page); +gnttab_free_pages (xh, num_pages, page);spin_lock_irqsave (&ring->free_pages_lock, flags); num_pages =0 ; } }spin_unlock_irqrestore (&ring->free_pages_lock, flags);if (num_pages !=0 ) -gnttab_free_pages (num_pages, page); +gnttab_free_pages (xh, num_pages, page); }#define vaddr (page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))
@@ -301,8 +301,8 @@ static void put_persistent_gnt(struct xen_blkif_ring *ring,atomic_dec (&ring->persistent_gnt_in_use); } -static void free_persistent_gnts (struct xen_blkif_ring *ring,struct rb_root *root, -unsigned int num) +static void free_persistent_gnts (xenhost_t *xh,struct xen_blkif_ring *ring, +struct rb_root *root,unsigned int num) {struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST ];
@@ -314,6 +314,7 @@ static void free_persistent_gnts(struct xen_blkif_ring *ring, struct rb_root *ro unmap_data.pages = pages; unmap_data.unmap_ops = unmap; unmap_data.kunmap_ops =NULL ; + unmap_data.xh = xh; foreach_grant_safe(persistent_gnt, n, root, node) { BUG_ON(persistent_gnt->handle ==
@@ -351,10 +352,12 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)int segs_to_unmap =0 ;struct xen_blkif_ring *ring =container_of (work,typeof (*ring), persistent_purge_work);struct gntab_unmap_queue_data unmap_data; +struct xenbus_device *dev =xen_blkbk_xenbus (ring->blkif->be); unmap_data.pages = pages; unmap_data.unmap_ops = unmap; unmap_data.kunmap_ops =NULL ; + unmap_data.xh = dev->xh;while (!list_empty (&ring->persistent_purge_list)) { persistent_gnt = list_first_entry(&ring->persistent_purge_list,
@@ -615,6 +618,7 @@ int xen_blkif_schedule(void *arg)struct xen_vbd *vbd = &blkif->vbd;unsigned long timeout;int ret; +struct xenbus_device *dev =xen_blkbk_xenbus (blkif->be);set_freezable ();while (!kthread_should_stop ()) {
@@ -657,7 +661,7 @@ int xen_blkif_schedule(void *arg) }/* Shrink if we have more than xen_blkif_max_buffer_pages */ -shrink_free_pagepool (ring, xen_blkif_max_buffer_pages); +shrink_free_pagepool (dev->xh, ring, xen_blkif_max_buffer_pages);if (log_stats &&time_after (jiffies, ring->st_print))print_stats (ring);
@@ -677,18 +681,18 @@ int xen_blkif_schedule(void *arg)/* * Remove persistent grants and empty the pool of free pages */ -void xen_blkbk_free_caches (struct xen_blkif_ring *ring) +void xen_blkbk_free_caches (xenhost_t *xh,struct xen_blkif_ring *ring) {/* Free all persistent grant pages */ if (!RB_EMPTY_ROOT (&ring->persistent_gnts)) -free_persistent_gnts (ring, &ring->persistent_gnts, +free_persistent_gnts (xh, ring, &ring->persistent_gnts, ring->persistent_gnt_c);BUG_ON (!RB_EMPTY_ROOT (&ring->persistent_gnts)); ring->persistent_gnt_c =0 ;/* Since we are shutting down remove all pages from the buffer */ -shrink_free_pagepool (ring,0 /* All */ ); +shrink_free_pagepool (xh, ring,0 /* All */ ); } static unsigned int xen_blkbk_unmap_prepare(
@@ -784,6 +788,7 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring,struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST ];unsigned int invcount =0 ; +struct xenbus_device *dev =xen_blkbk_xenbus (ring->blkif->be);int ret;while (num) {
@@ -792,7 +797,7 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring, invcount =xen_blkbk_unmap_prepare (ring, pages, batch, unmap, unmap_pages);if (invcount) { - ret =gnttab_unmap_refs (unmap,NULL , unmap_pages, invcount); + ret =gnttab_unmap_refs (dev->xh, unmap,NULL , unmap_pages, invcount);BUG_ON (ret);put_free_pages (ring, unmap_pages, invcount); }
@@ -815,6 +820,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,int last_map =0 , map_until =0 ;int use_persistent_gnts;struct xen_blkif *blkif = ring->blkif; +struct xenbus_device *dev =xen_blkbk_xenbus (blkif->be);/* function call */ use_persistent_gnts = (blkif->vbd.feature_gnt_persistent);
@@ -841,7 +847,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, pages[i]->page = persistent_gnt->page; pages[i]->persistent_gnt = persistent_gnt; }else { -if (get_free_page (ring, &pages[i]->page)) +if (get_free_page (dev->xh, ring, &pages[i]->page)) goto out_of_memory; addr =vaddr (pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page;
@@ -859,7 +865,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, }if (segs_to_map) { - ret =gnttab_map_refs (map,NULL , pages_to_gnt, segs_to_map); + ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, segs_to_map);BUG_ON (ret); }
drivers/block/xen-blkback/common.h +1 -1
@@ -382,7 +382,7 @@ int xen_blkif_xenbus_init(void);irqreturn_t xen_blkif_be_int (int irq,void *dev_id);int xen_blkif_schedule (void *arg);int xen_blkif_purge_persistent (void *arg); -void xen_blkbk_free_caches (struct xen_blkif_ring *ring); +void xen_blkbk_free_caches (xenhost_t *xh,struct xen_blkif_ring *ring);int xen_blkbk_flush_diskcache (struct xenbus_transaction xbt,struct backend_info *be,int state);
drivers/block/xen-blkback/xenbus.c +32 -31
247 lines not on this page · raw message
drivers/block/xen-blkfront.c +54 -49
366 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 14/16] xen/blk: gnttab, evtchn, xenbus API changes
Quoted 4 lines · Ankur Arora
For the most part, we now pass
xenhost_t* as a parameter.Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>
I don't see how this can be a patch on its own.
The only way to be able to use a patch for each driver would be to keep the original grant-, event- and xenbus-interfaces and add the new ones taking xenhost * with a new name. The original interfaces could then use xenhost_default and you can switch them to the new interfaces one by one. The last patch could then remove the old interfaces when there is no user left.
Juergen
Re: [RFC PATCH 14/16] xen/blk: gnttab, evtchn, xenbus API changes
Quoted 7 lines · Juergen Gross
Quoted 4 lines · Ankur Arora
For the most part, we now pass
xenhost_t* as a parameter.Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>I don't see how this can be a patch on its own.
Yes, the reason this was separate was that given this was an RFC, I didn't want to pollute the logic page with lots of mechanical changes.
Quoted 7 lines
The only way to be able to use a patch for each driver would be to keep the original grant-, event- and xenbus-interfaces and add the new ones taking xenhost * with a new name. The original interfaces could then use
xenhost_defaultand you can switch them to the new interfaces one by one. The last patch could then remove the old interfaces when there is no user left.
Yes, this makes sense.
Ankur
Quoted 3 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 15/16 xen/net: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraFor the most part, we now pass xenhost_t * as parameter.
--- drivers/net/xen-netback/hash.c | 7 +- drivers/net/xen-netback/interface.c | 7 +- drivers/net/xen-netback/netback.c | 11 +-- drivers/net/xen-netback/rx.c | 3 +- drivers/net/xen-netback/xenbus.c | 81 +++++++++++----------- drivers/net/xen-netfront.c | 102 +++++++++++++++------------- 6 files changed, 117 insertions(+), 94 deletions(-)
drivers/net/xen-netback/hash.c +5 -2
@@ -289,6 +289,8 @@ u32 xenvif_set_hash_flags(struct xenvif *vif, u32 flags)u32 xenvif_set_hash_key (struct xenvif *vif,u32 gref,u32 len) {u8 *key = vif->hash.key; +struct xenbus_device *dev =xenvif_to_xenbus_device (vif); +struct gnttab_copy copy_op = { .source.u.ref = gref, .source.domid = vif->domid,
@@ -303,7 +305,7 @@ u32 xenvif_set_hash_key(struct xenvif *vif, u32 gref, u32 len)return XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER ;if (copy_op.len !=0 ) { -gnttab_batch_copy (©_op,1 ); +gnttab_batch_copy (dev->xh, ©_op,1 );if (copy_op.status != GNTST_okay)return XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER ;
@@ -334,6 +336,7 @@ u32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, u32 off) {u32 *mapping = vif->hash.mapping[!vif->hash.mapping_sel]; +struct xenbus_device *dev =xenvif_to_xenbus_device (vif);unsigned int nr =1 ;struct gnttab_copy copy_op[2 ] = {{ .source.u.ref = gref,
@@ -363,7 +366,7 @@ u32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, vif->hash.size * sizeof(*mapping));if (copy_op[0 ].len !=0 ) { -gnttab_batch_copy (copy_op, nr); +gnttab_batch_copy (dev->xh, copy_op, nr);if (copy_op[0 ].status != GNTST_okay || copy_op[nr -1 ].status != GNTST_okay)
drivers/net/xen-netback/interface.c +5 -2
@@ -519,6 +519,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,int xenvif_init_queue (struct xenvif_queue *queue) {int err, i; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); queue->credit_bytes = queue->remaining_credit = ~0UL ; queue->credit_usec =0UL ;
@@ -542,7 +543,7 @@ int xenvif_init_queue(struct xenvif_queue *queue)* better enable it. The long term solution would be to use just a * bunch of valid page descriptors, without dependency on ballooning */ - err =gnttab_alloc_pages (MAX_PENDING_REQS , + err =gnttab_alloc_pages (dev->xh,MAX_PENDING_REQS , queue->mmap_pages);if (err) {netdev_err (queue->vif->dev,"Could not reserve mmap_pages\n" );
@@ -790,7 +791,9 @@ void xenvif_disconnect_ctrl(struct xenvif *vif)*/ void xenvif_deinit_queue (struct xenvif_queue *queue) { -gnttab_free_pages (MAX_PENDING_REQS , queue->mmap_pages); +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); + +gnttab_free_pages (dev->xh,MAX_PENDING_REQS , queue->mmap_pages); }void xenvif_free (struct xenvif *vif)
drivers/net/xen-netback/netback.c +7 -4
@@ -1244,6 +1244,7 @@ static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)pending_ring_idx_t dc, dp;u16 pending_idx, pending_idx_release[MAX_PENDING_REQS ];unsigned int i =0 ; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); dc = queue->dealloc_cons; gop = queue->tx_unmap_ops;
@@ -1280,7 +1281,7 @@ static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)if (gop - queue->tx_unmap_ops >0 ) {int ret; - ret =gnttab_unmap_refs (queue->tx_unmap_ops, + ret =gnttab_unmap_refs (dev->xh, queue->tx_unmap_ops,NULL , queue->pages_to_unmap, gop - queue->tx_unmap_ops);
@@ -1310,6 +1311,7 @@ int xenvif_tx_action(struct xenvif_queue *queue, int budget) {unsigned nr_mops, nr_cops =0 ;int work_done, ret; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif);if (unlikely (!tx_work_todo (queue)))return 0 ;
@@ -1319,9 +1321,9 @@ int xenvif_tx_action(struct xenvif_queue *queue, int budget)if (nr_cops ==0 )return 0 ; -gnttab_batch_copy (queue->tx_copy_ops, nr_cops); +gnttab_batch_copy (dev->xh, queue->tx_copy_ops, nr_cops);if (nr_mops !=0 ) { - ret =gnttab_map_refs (queue->tx_map_ops, + ret =gnttab_map_refs (dev->xh, queue->tx_map_ops,NULL , queue->pages_to_map, nr_mops);
@@ -1391,6 +1393,7 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx) {int ret;struct gnttab_unmap_grant_ref tx_unmap_op; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); gnttab_set_unmap_op(&tx_unmap_op, idx_to_kaddr(queue, pending_idx),
@@ -1398,7 +1401,7 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx) queue->grant_tx_handle[pending_idx]);xenvif_grant_handle_reset (queue, pending_idx); - ret =gnttab_unmap_refs (&tx_unmap_op,NULL , + ret =gnttab_unmap_refs (dev->xh, &tx_unmap_op,NULL , &queue->mmap_pages[pending_idx],1 );if (ret) { netdev_err(queue->vif->dev,
drivers/net/xen-netback/rx.c +2 -1
@@ -134,8 +134,9 @@ static void xenvif_rx_copy_flush(struct xenvif_queue *queue) {unsigned int i;int notify; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); -gnttab_batch_copy (queue->rx_copy.op, queue->rx_copy.num); +gnttab_batch_copy (dev->xh, queue->rx_copy.op, queue->rx_copy.num);for (i =0 ; i < queue->rx_copy.num; i++) {struct gnttab_copy *op;
drivers/net/xen-netback/xenbus.c +42 -39
294 lines not on this page · raw message
drivers/net/xen-netfront.c +56 -46
371 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 15/16 xen/net: gnttab, evtchn, xenbus API changes
In reply to Ankur AroraFor the most part, we now pass xenhost_t * as parameter.
--- drivers/net/xen-netback/hash.c | 7 +- drivers/net/xen-netback/interface.c | 7 +- drivers/net/xen-netback/netback.c | 11 +-- drivers/net/xen-netback/rx.c | 3 +- drivers/net/xen-netback/xenbus.c | 81 +++++++++++----------- drivers/net/xen-netfront.c | 102 +++++++++++++++------------- 6 files changed, 117 insertions(+), 94 deletions(-)
drivers/net/xen-netback/hash.c +5 -2
@@ -289,6 +289,8 @@ u32 xenvif_set_hash_flags(struct xenvif *vif, u32 flags)u32 xenvif_set_hash_key (struct xenvif *vif,u32 gref,u32 len) {u8 *key = vif->hash.key; +struct xenbus_device *dev =xenvif_to_xenbus_device (vif); +struct gnttab_copy copy_op = { .source.u.ref = gref, .source.domid = vif->domid,
@@ -303,7 +305,7 @@ u32 xenvif_set_hash_key(struct xenvif *vif, u32 gref, u32 len)return XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER ;if (copy_op.len !=0 ) { -gnttab_batch_copy (©_op,1 ); +gnttab_batch_copy (dev->xh, ©_op,1 );if (copy_op.status != GNTST_okay)return XEN_NETIF_CTRL_STATUS_INVALID_PARAMETER ;
@@ -334,6 +336,7 @@ u32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, u32 off) {u32 *mapping = vif->hash.mapping[!vif->hash.mapping_sel]; +struct xenbus_device *dev =xenvif_to_xenbus_device (vif);unsigned int nr =1 ;struct gnttab_copy copy_op[2 ] = {{ .source.u.ref = gref,
@@ -363,7 +366,7 @@ u32 xenvif_set_hash_mapping(struct xenvif *vif, u32 gref, u32 len, vif->hash.size * sizeof(*mapping));if (copy_op[0 ].len !=0 ) { -gnttab_batch_copy (copy_op, nr); +gnttab_batch_copy (dev->xh, copy_op, nr);if (copy_op[0 ].status != GNTST_okay || copy_op[nr -1 ].status != GNTST_okay)
drivers/net/xen-netback/interface.c +5 -2
@@ -519,6 +519,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,int xenvif_init_queue (struct xenvif_queue *queue) {int err, i; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); queue->credit_bytes = queue->remaining_credit = ~0UL ; queue->credit_usec =0UL ;
@@ -542,7 +543,7 @@ int xenvif_init_queue(struct xenvif_queue *queue)* better enable it. The long term solution would be to use just a * bunch of valid page descriptors, without dependency on ballooning */ - err =gnttab_alloc_pages (MAX_PENDING_REQS , + err =gnttab_alloc_pages (dev->xh,MAX_PENDING_REQS , queue->mmap_pages);if (err) {netdev_err (queue->vif->dev,"Could not reserve mmap_pages\n" );
@@ -790,7 +791,9 @@ void xenvif_disconnect_ctrl(struct xenvif *vif)*/ void xenvif_deinit_queue (struct xenvif_queue *queue) { -gnttab_free_pages (MAX_PENDING_REQS , queue->mmap_pages); +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); + +gnttab_free_pages (dev->xh,MAX_PENDING_REQS , queue->mmap_pages); }void xenvif_free (struct xenvif *vif)
drivers/net/xen-netback/netback.c +7 -4
@@ -1244,6 +1244,7 @@ static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)pending_ring_idx_t dc, dp;u16 pending_idx, pending_idx_release[MAX_PENDING_REQS ];unsigned int i =0 ; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); dc = queue->dealloc_cons; gop = queue->tx_unmap_ops;
@@ -1280,7 +1281,7 @@ static inline void xenvif_tx_dealloc_action(struct xenvif_queue *queue)if (gop - queue->tx_unmap_ops >0 ) {int ret; - ret =gnttab_unmap_refs (queue->tx_unmap_ops, + ret =gnttab_unmap_refs (dev->xh, queue->tx_unmap_ops,NULL , queue->pages_to_unmap, gop - queue->tx_unmap_ops);
@@ -1310,6 +1311,7 @@ int xenvif_tx_action(struct xenvif_queue *queue, int budget) {unsigned nr_mops, nr_cops =0 ;int work_done, ret; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif);if (unlikely (!tx_work_todo (queue)))return 0 ;
@@ -1319,9 +1321,9 @@ int xenvif_tx_action(struct xenvif_queue *queue, int budget)if (nr_cops ==0 )return 0 ; -gnttab_batch_copy (queue->tx_copy_ops, nr_cops); +gnttab_batch_copy (dev->xh, queue->tx_copy_ops, nr_cops);if (nr_mops !=0 ) { - ret =gnttab_map_refs (queue->tx_map_ops, + ret =gnttab_map_refs (dev->xh, queue->tx_map_ops,NULL , queue->pages_to_map, nr_mops);
@@ -1391,6 +1393,7 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx) {int ret;struct gnttab_unmap_grant_ref tx_unmap_op; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); gnttab_set_unmap_op(&tx_unmap_op, idx_to_kaddr(queue, pending_idx),
@@ -1398,7 +1401,7 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx) queue->grant_tx_handle[pending_idx]);xenvif_grant_handle_reset (queue, pending_idx); - ret =gnttab_unmap_refs (&tx_unmap_op,NULL , + ret =gnttab_unmap_refs (dev->xh, &tx_unmap_op,NULL , &queue->mmap_pages[pending_idx],1 );if (ret) { netdev_err(queue->vif->dev,
drivers/net/xen-netback/rx.c +2 -1
@@ -134,8 +134,9 @@ static void xenvif_rx_copy_flush(struct xenvif_queue *queue) {unsigned int i;int notify; +struct xenbus_device *dev =xenvif_to_xenbus_device (queue->vif); -gnttab_batch_copy (queue->rx_copy.op, queue->rx_copy.num); +gnttab_batch_copy (dev->xh, queue->rx_copy.op, queue->rx_copy.num);for (i =0 ; i < queue->rx_copy.num; i++) {struct gnttab_copy *op;
drivers/net/xen-netback/xenbus.c +42 -39
294 lines not on this page · raw message
drivers/net/xen-netfront.c +56 -46
371 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerRe: [RFC PATCH 15/16] xen/net: gnttab, evtchn, xenbus API changes
Quoted 4 lines · Ankur Arora
For the most part, we now pass
xenhost_t* as parameter.Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>
Same as previous patch.
Juergen
RFC PATCH 16/16 xen/grant-table: host_addr fixup in mapping on xenhost_r0
In reply to Ankur AroraXenhost type xenhost_r0 does not support standard GNTTABOP_map_grant_ref semantics (map a gref onto a specified host_addr). That's because since the hypervisor is local (same address space as the caller of GNTTABOP_map_grant_ref), there is no external entity that could map an arbitrary page underneath an arbitrary address.
To handle this, the GNTTABOP_map_grant_ref hypercall on xenhost_r0 treats the host_addr as an OUT parameter instead of IN and expects the gnttab_map_refs() and similar to fixup any state that caches the value of host_addr from before the hypercall.
Accordingly gnttab_map_refs() now adds two parameters, a fixup function and a pointer to cached maps to fixup:
int gnttab_map_refs(xenhost_t *xh, struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
- struct page **pages, unsigned int count) + struct page **pages, gnttab_map_fixup_t map_fixup_fn, + void **map_fixup[], unsigned int count)
The reason we use a fixup function and not an additional mapping op in the xenhost_t is because, depending on the caller, what we are fixing might be different: blkback, netback for instance cache host_addr in via a struct page *, while __xenbus_map_ring() caches a phys_addr.
This patch fixes up xen-blkback and xen-gntdev drivers.
TODO:
- also rewrite gnttab_batch_map() and __xenbus_map_ring().
- modify xen-netback, scsiback, pciback etc
--- drivers/block/xen-blkback/blkback.c | 14 +++++++++++++- drivers/xen/gntdev.c | 2 +- drivers/xen/grant-table.c | 20 ++++++++++++++------ include/xen/grant_table.h | 11 ++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-)
drivers/block/xen-blkback/blkback.c +13 -1
@@ -806,11 +806,18 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring, } } +static void blkbk_map_fixup (uint64_t host_addr,void **fixup) +{ +struct page **pg = (struct page **)fixup; + *pg =virt_to_page (host_addr); +} +static int xen_blkbk_map (struct xen_blkif_ring *ring,struct grant_page *pages[],int num,bool ro) {struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST ]; +struct page **map_fixup[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *pages_to_gnt[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct persistent_gnt *persistent_gnt =NULL ;phys_addr_t addr =0 ;
@@ -858,6 +865,9 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,gnttab_set_map_op (&map[segs_to_map++], addr, flags, pages[i]->gref, blkif->domid); + +if (gnttab_map_fixup (dev->xh)) + map_fixup[i] = &pages[i]->page; } map_until = i +1 ;if (segs_to_map ==BLKIF_MAX_SEGMENTS_PER_REQUEST )
@@ -865,7 +875,9 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, }if (segs_to_map) { - ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, segs_to_map); + ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, +gnttab_map_fixup (dev->xh) ? blkbk_map_fixup :NULL , + (void ***) map_fixup, segs_to_map);BUG_ON (ret); }
drivers/xen/gntdev.c +1 -1
@@ -342,7 +342,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)pr_debug ("map %d+%d\n" , map->index, map->count); err =gnttab_map_refs (xh, map->map_ops, use_ptemod ? map->kmap_ops :NULL , - map->pages, map->count); + map->pages,NULL ,NULL , map->count);if (err)return err;
drivers/xen/grant-table.c +14 -6
@@ -1084,7 +1084,8 @@ void gnttab_foreach_grant(struct page **pages,int gnttab_map_refs (xenhost_t *xh,struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops, -struct page **pages,unsigned int count) +struct page **pages,gnttab_map_fixup_t map_fixup_fn, +void **map_fixup[],unsigned int count) {int i, ret;
@@ -1096,12 +1097,19 @@ int gnttab_map_refs(xenhost_t *xh, struct gnttab_map_grant_ref *map_ops,switch (map_ops[i].status) {case GNTST_okay: { -struct xen_page_foreign *foreign; +if (!gnttab_map_fixup (xh)) { +struct xen_page_foreign *foreign; -SetPageForeign (pages[i]); - foreign =xen_page_foreign (pages[i]); - foreign->domid = map_ops[i].dom; - foreign->gref = map_ops[i].ref; +SetPageForeign (pages[i]); + foreign =xen_page_foreign (pages[i]); + foreign->domid = map_ops[i].dom; + foreign->gref = map_ops[i].ref; + }else { + pages[i] =virt_to_page (map_ops[i].host_addr); + +if (map_fixup_fn) +map_fixup_fn (map_ops[i].host_addr, map_fixup[i]); + }break ; }
include/xen/grant_table.h +10 -1
@@ -219,9 +219,18 @@ int gnttab_dma_free_pages(xenhost_t *xh, struct gnttab_dma_alloc_args *args);int gnttab_pages_set_private (int nr_pages,struct page **pages);void gnttab_pages_clear_private (int nr_pages,struct page **pages); +static inline bool +gnttab_map_fixup (xenhost_t *xh) +{ +return xh->type == xenhost_r0; +} + +typedef void (*gnttab_map_fixup_t )(uint64_t host_addr,void **map_fixup); +int gnttab_map_refs (xenhost_t *xh,struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops, -struct page **pages,unsigned int count); +struct page **pages,gnttab_map_fixup_t map_fixup_fn, +void **map_fixup[],unsigned int count);int gnttab_unmap_refs (xenhost_t *xh,struct gnttab_unmap_grant_ref *unmap_ops,struct gnttab_unmap_grant_ref *kunmap_ops,struct page **pages,unsigned int count);
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
RFC PATCH 16/16 xen/grant-table: host_addr fixup in mapping on xenhost_r0
In reply to Ankur AroraXenhost type xenhost_r0 does not support standard GNTTABOP_map_grant_ref semantics (map a gref onto a specified host_addr). That's because since the hypervisor is local (same address space as the caller of GNTTABOP_map_grant_ref), there is no external entity that could map an arbitrary page underneath an arbitrary address.
To handle this, the GNTTABOP_map_grant_ref hypercall on xenhost_r0 treats the host_addr as an OUT parameter instead of IN and expects the gnttab_map_refs() and similar to fixup any state that caches the value of host_addr from before the hypercall.
Accordingly gnttab_map_refs() now adds two parameters, a fixup function and a pointer to cached maps to fixup:
int gnttab_map_refs(xenhost_t *xh, struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
- struct page **pages, unsigned int count) + struct page **pages, gnttab_map_fixup_t map_fixup_fn, + void **map_fixup[], unsigned int count)
The reason we use a fixup function and not an additional mapping op in the xenhost_t is because, depending on the caller, what we are fixing might be different: blkback, netback for instance cache host_addr in via a struct page *, while __xenbus_map_ring() caches a phys_addr.
This patch fixes up xen-blkback and xen-gntdev drivers.
TODO:
- also rewrite gnttab_batch_map() and __xenbus_map_ring().
- modify xen-netback, scsiback, pciback etc
--- drivers/block/xen-blkback/blkback.c | 14 +++++++++++++- drivers/xen/gntdev.c | 2 +- drivers/xen/grant-table.c | 20 ++++++++++++++------ include/xen/grant_table.h | 11 ++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-)
drivers/block/xen-blkback/blkback.c +13 -1
@@ -806,11 +806,18 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring, } } +static void blkbk_map_fixup (uint64_t host_addr,void **fixup) +{ +struct page **pg = (struct page **)fixup; + *pg =virt_to_page (host_addr); +} +static int xen_blkbk_map (struct xen_blkif_ring *ring,struct grant_page *pages[],int num,bool ro) {struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST ]; +struct page **map_fixup[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct page *pages_to_gnt[BLKIF_MAX_SEGMENTS_PER_REQUEST ];struct persistent_gnt *persistent_gnt =NULL ;phys_addr_t addr =0 ;
@@ -858,6 +865,9 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,gnttab_set_map_op (&map[segs_to_map++], addr, flags, pages[i]->gref, blkif->domid); + +if (gnttab_map_fixup (dev->xh)) + map_fixup[i] = &pages[i]->page; } map_until = i +1 ;if (segs_to_map ==BLKIF_MAX_SEGMENTS_PER_REQUEST )
@@ -865,7 +875,9 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, }if (segs_to_map) { - ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, segs_to_map); + ret =gnttab_map_refs (dev->xh, map,NULL , pages_to_gnt, +gnttab_map_fixup (dev->xh) ? blkbk_map_fixup :NULL , + (void ***) map_fixup, segs_to_map);BUG_ON (ret); }
drivers/xen/gntdev.c +1 -1
@@ -342,7 +342,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)pr_debug ("map %d+%d\n" , map->index, map->count); err =gnttab_map_refs (xh, map->map_ops, use_ptemod ? map->kmap_ops :NULL , - map->pages, map->count); + map->pages,NULL ,NULL , map->count);if (err)return err;
drivers/xen/grant-table.c +14 -6
@@ -1084,7 +1084,8 @@ void gnttab_foreach_grant(struct page **pages,int gnttab_map_refs (xenhost_t *xh,struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops, -struct page **pages,unsigned int count) +struct page **pages,gnttab_map_fixup_t map_fixup_fn, +void **map_fixup[],unsigned int count) {int i, ret;
@@ -1096,12 +1097,19 @@ int gnttab_map_refs(xenhost_t *xh, struct gnttab_map_grant_ref *map_ops,switch (map_ops[i].status) {case GNTST_okay: { -struct xen_page_foreign *foreign; +if (!gnttab_map_fixup (xh)) { +struct xen_page_foreign *foreign; -SetPageForeign (pages[i]); - foreign =xen_page_foreign (pages[i]); - foreign->domid = map_ops[i].dom; - foreign->gref = map_ops[i].ref; +SetPageForeign (pages[i]); + foreign =xen_page_foreign (pages[i]); + foreign->domid = map_ops[i].dom; + foreign->gref = map_ops[i].ref; + }else { + pages[i] =virt_to_page (map_ops[i].host_addr); + +if (map_fixup_fn) +map_fixup_fn (map_ops[i].host_addr, map_fixup[i]); + }break ; }
include/xen/grant_table.h +10 -1
@@ -219,9 +219,18 @@ int gnttab_dma_free_pages(xenhost_t *xh, struct gnttab_dma_alloc_args *args);int gnttab_pages_set_private (int nr_pages,struct page **pages);void gnttab_pages_clear_private (int nr_pages,struct page **pages); +static inline bool +gnttab_map_fixup (xenhost_t *xh) +{ +return xh->type == xenhost_r0; +} + +typedef void (*gnttab_map_fixup_t )(uint64_t host_addr,void **map_fixup); +int gnttab_map_refs (xenhost_t *xh,struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops, -struct page **pages,unsigned int count); +struct page **pages,gnttab_map_fixup_t map_fixup_fn, +void **map_fixup[],unsigned int count);int gnttab_unmap_refs (xenhost_t *xh,struct gnttab_unmap_grant_ref *unmap_ops,struct gnttab_unmap_grant_ref *kunmap_ops,struct page **pages,unsigned int count);
Signature · 1 line
2.20.1
Juergen Gross
maintainerRe: [RFC PATCH 16/16] xen/grant-table: host_addr fixup in mapping on xenhost_r0
Quoted 24 lines · Ankur Arora
Xenhost type
xenhost_r0does not support standardGNTTABOP_map_grant_refsemantics (map a gref onto a specifiedhost_addr). That's because since the hypervisor is local (same address space as the caller ofGNTTABOP_map_grant_ref), there is no external entity that could map an arbitrary page underneath an arbitrary address.To handle this, the
GNTTABOP_map_grant_refhypercall onxenhost_r0treats thehost_addras an OUT parameter instead of IN and expects thegnttab_map_refs()and similar to fixup any state that caches the value ofhost_addrfrom before the hypercall.Accordingly
gnttab_map_refs()now adds two parameters, a fixup function and a pointer to cached maps to fixup:
int gnttab_map_refs(xenhost_t *xh, structgnttab_map_grant_ref*map_ops,
structgnttab_map_grant_ref*kmap_ops,drivers/xen/grant-table.c +2
-1- struct page **pages, unsigned int count) + struct page **pages, gnttab_map_fixup_t map_fixup_fn, + void **map_fixup[], unsigned int count)The reason we use a fixup function and not an additional mapping op in the
xenhost_tis because, depending on the caller, what we are fixing might be different: blkback, netback for instance cachehost_addrin via a struct page *, while__xenbus_map_ring()caches aphys_addr.
Quoted 8 lines
This patch fixes up xen-blkback and xen-gntdev drivers.
TODO:
- also rewritegnttab_batch_map()and__xenbus_map_ring().
- modify xen-netback, scsiback, pciback etcCo-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>
Without seeing the __xenbus_map_ring() modification it is impossible to do a proper review of this patch.
Juergen
Re: [RFC PATCH 16/16] xen/grant-table: host_addr fixup in mapping on xenhost_r0
Quoted 31 lines · Juergen Gross
Quoted 30 lines · Ankur Arora
Xenhost type
xenhost_r0does not support standardGNTTABOP_map_grant_refsemantics (map a gref onto a specifiedhost_addr). That's because since the hypervisor is local (same address space as the caller ofGNTTABOP_map_grant_ref), there is no external entity that could map an arbitrary page underneath an arbitrary address.To handle this, the
GNTTABOP_map_grant_refhypercall onxenhost_r0treats thehost_addras an OUT parameter instead of IN and expects thegnttab_map_refs()and similar to fixup any state that caches the value ofhost_addrfrom before the hypercall.Accordingly
gnttab_map_refs()now adds two parameters, a fixup function and a pointer to cached maps to fixup:
int gnttab_map_refs(xenhost_t *xh, structgnttab_map_grant_ref*map_ops, structgnttab_map_grant_ref*kmap_ops,
- struct page **pages, unsigned int count)
+ struct page **pages,gnttab_map_fixup_tmap_fixup_fn, + void **map_fixup[], unsigned int count)The reason we use a fixup function and not an additional mapping op in the
xenhost_tis because, depending on the caller, what we are fixing might be different: blkback, netback for instance cachehost_addrin via a struct page *, while__xenbus_map_ring()caches aphys_addr.This patch fixes up xen-blkback and xen-gntdev drivers.
TODO:
- also rewritegnttab_batch_map()and__xenbus_map_ring().
- modify xen-netback, scsiback, pciback etc
Quoted 5 lines
Quoted 2 lines
Co-developed-by Joao Martins <[email protected]>Signed-off-by Ankur Arora <[email protected]>Without seeing the
__xenbus_map_ring()modification it is impossible to do a proper review of this patch.
Will do in v2.
Ankur
Quoted 3 lines
Juergen
Juergen Gross
maintainerQuoted 4 lines · Ankur Arora
Hi all,
This is an RFC for xenhost support, outlined here by Juergen here:
https://lkml.org/lkml/2019/4/8/67.
First: thanks for all the effort you've put into this series!
Quoted 7 lines
The high level idea is to provide an abstraction of the Xen communication interface, as a
xenhost_t.
xenhost_texpose ops for communication between the guest and Xen (hypercall, cpuid, shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning), and these can differ based on the kind of underlying Xen: regular, local, and nested.
I'm not sure we need to abstract away hypercalls and cpuid. I believe in case of nested Xen all contacts to the L0 hypervisor should be done via the L1 hypervisor. So we might need to issue some kind of passthrough hypercall when e.g. granting a page to L0 dom0, but this should be handled via the grant abstraction (events should be similar).
So IMO we should drop patches 2-5.
Quoted 61 lines
(Since this abstraction is largely about guest -- xenhost communication, no ops are needed for timer, clock, sched, memory (MMU, P2M), VCPU mgmt. etc.)
Xenhost use-cases:
Regular-Xen: the standard Xen interface presented to a guest, specifically for comunication between Lx-guest and Lx-Xen.
Local-Xen: a Xen like interface which runs in the same address space as the guest (dom0). This, can act as the default xenhost.
The major ways it differs from a regular Xen interface is in presenting a different hypercall interface (call instead of a syscall/vmcall), and in an inability to do grant-mappings: since local-Xen exists in the same address space as Xen, there's no way for it to cheaply change the physical page that a GFN maps to (assuming no P2M tables.)
Nested-Xen: this channel is to Xen, one level removed: from L1-guest to L0-Xen. The use case is that we want L0-dom0-backends to talk to L1-dom0-frontend drivers which can then present PV devices which can in-turn be used by the L1-dom0-backend drivers as raw underlying devices. The interfaces themselves, broadly remain similar.
Note: L0-Xen, L1-Xen represent Xen running at that nesting level and L0-guest, L1-guest represent guests that are children of Xen at that nesting level. Lx, represents any level.
Patches 1-7,
"x86/xen: addxenhost_tinterface"
"x86/xen: cpuid support inxenhost_t"
"x86/xen: makehypercall_pagegeneric"
"x86/xen: hypercall support forxenhost_t"
"x86/xen: add feature support inxenhost_t"
"x86/xen: addshared_infosupport toxenhost_t"
"x86/xen: makevcpu_infopart ofxenhost_t"
abstract out interfaces that setup hypercalls/cpuid/shared_info/vcpu_info etc.Patch 8, "x86/xen: irq/upcall handling with multiple xenhosts" sets up the upcall and
pv_irqops based onvcpu_info.Patch 9, "xen/evtchn: support evtchn in
xenhost_t" adds xenhost based evtchn support forevtchn_2l.Patches 10 and 16, "xen/balloon: support ballooning in
xenhost_t" and "xen/grant-table:host_addrfixup in mapping onxenhost_r0" implement support fromGNTTABOP_map_grant_reffor xenhosts of typexenhost_r0(xenhost local.)Patch 12, "xen/xenbus: support xenbus frontend/backend with
xenhost_t" makes xenbus so that both its frontend and backend can be bootstrapped separately via separate xenhosts.Remaining patches, 11, 13, 14, 15:
"xen/grant-table: make grant-table xenhost aware" "drivers/xen: gnttab, evtchn, xenbus API changes" "xen/blk: gnttab, evtchn, xenbus API changes" "xen/net: gnttab, evtchn, xenbus API changes"
are mostly mechanical changes for APIs that now takexenhost_t* as parameter.
Quoted 6 lines
The code itself is RFC quality, and is mostly meant to get feedback before proceeding further. Also note that the FIFO logic and some Xen drivers (input, pciback, scsi etc) are mostly unchanged, so will not build.
Please take a look.
Juergen
Quoted 16 lines · Juergen Gross
Quoted 4 lines · Ankur Arora
Hi all,
This is an RFC for xenhost support, outlined here by Juergen here:
https://lkml.org/lkml/2019/4/8/67.First: thanks for all the effort you've put into this series!
Quoted 7 lines
The high level idea is to provide an abstraction of the Xen communication interface, as a
xenhost_t.
xenhost_texpose ops for communication between the guest and Xen (hypercall, cpuid, shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning), and these can differ based on the kind of underlying Xen: regular, local, and nested.
Quoted 6 lines
I'm not sure we need to abstract away hypercalls and cpuid. I believe in case of nested Xen all contacts to the L0 hypervisor should be done via the L1 hypervisor. So we might need to issue some kind of passthrough hypercall when e.g. granting a page to L0 dom0, but this should be handled via the grant abstraction (events should be similar).
Just to be clear: By "kind of passthrough hypercall" you mean (e.g. for every access/modify of grant table frames) you would proxy hypercall to L0 Xen via L1 Xen?
Quoted 68 lines
So IMO we should drop patches 2-5.
Quoted 66 lines
(Since this abstraction is largely about guest -- xenhost communication, no ops are needed for timer, clock, sched, memory (MMU, P2M), VCPU mgmt. etc.)
Xenhost use-cases:
Regular-Xen: the standard Xen interface presented to a guest, specifically for comunication between Lx-guest and Lx-Xen.
Local-Xen: a Xen like interface which runs in the same address space as the guest (dom0). This, can act as the default xenhost.
The major ways it differs from a regular Xen interface is in presenting a different hypercall interface (call instead of a syscall/vmcall), and in an inability to do grant-mappings: since local-Xen exists in the same address space as Xen, there's no way for it to cheaply change the physical page that a GFN maps to (assuming no P2M tables.)
Nested-Xen: this channel is to Xen, one level removed: from L1-guest to L0-Xen. The use case is that we want L0-dom0-backends to talk to L1-dom0-frontend drivers which can then present PV devices which can in-turn be used by the L1-dom0-backend drivers as raw underlying devices. The interfaces themselves, broadly remain similar.
Note: L0-Xen, L1-Xen represent Xen running at that nesting level and L0-guest, L1-guest represent guests that are children of Xen at that nesting level. Lx, represents any level.
Patches 1-7,
"x86/xen: addxenhost_tinterface"
"x86/xen: cpuid support inxenhost_t"
"x86/xen: makehypercall_pagegeneric"
"x86/xen: hypercall support forxenhost_t"
"x86/xen: add feature support inxenhost_t"
"x86/xen: addshared_infosupport toxenhost_t"
"x86/xen: makevcpu_infopart ofxenhost_t"
abstract out interfaces that setup hypercalls/cpuid/shared_info/vcpu_info etc.Patch 8, "x86/xen: irq/upcall handling with multiple xenhosts" sets up the upcall and
pv_irqops based onvcpu_info.Patch 9, "xen/evtchn: support evtchn in
xenhost_t" adds xenhost based evtchn support forevtchn_2l.Patches 10 and 16, "xen/balloon: support ballooning in
xenhost_t" and "xen/grant-table:host_addrfixup in mapping onxenhost_r0" implement support fromGNTTABOP_map_grant_reffor xenhosts of typexenhost_r0(xenhost local.)Patch 12, "xen/xenbus: support xenbus frontend/backend with
xenhost_t" makes xenbus so that both its frontend and backend can be bootstrapped separately via separate xenhosts.Remaining patches, 11, 13, 14, 15:
"xen/grant-table: make grant-table xenhost aware" "drivers/xen: gnttab, evtchn, xenbus API changes" "xen/blk: gnttab, evtchn, xenbus API changes" "xen/net: gnttab, evtchn, xenbus API changes"
are mostly mechanical changes for APIs that now takexenhost_t* as parameter.The code itself is RFC quality, and is mostly meant to get feedback before proceeding further. Also note that the FIFO logic and some Xen drivers (input, pciback, scsi etc) are mostly unchanged, so will not build.
Quoted 5 lines
Quoted 1 line
Please take a look.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross
maintainerQuoted 17 lines · Joao Martins
Quoted 16 lines · Juergen Gross
Quoted 4 lines · Ankur Arora
Hi all,
This is an RFC for xenhost support, outlined here by Juergen here:
https://lkml.org/lkml/2019/4/8/67.First: thanks for all the effort you've put into this series!
Quoted 7 lines
The high level idea is to provide an abstraction of the Xen communication interface, as a
xenhost_t.
xenhost_texpose ops for communication between the guest and Xen (hypercall, cpuid, shared_info/vcpu_info, evtchn, grant-table and on top of those, xenbus, ballooning), and these can differ based on the kind of underlying Xen: regular, local, and nested.
Quoted 8 lines
Quoted 6 lines
I'm not sure we need to abstract away hypercalls and cpuid. I believe in case of nested Xen all contacts to the L0 hypervisor should be done via the L1 hypervisor. So we might need to issue some kind of passthrough hypercall when e.g. granting a page to L0 dom0, but this should be handled via the grant abstraction (events should be similar).
Just to be clear: By "kind of passthrough hypercall" you mean (e.g. for every access/modify of grant table frames) you would proxy hypercall to L0 Xen via L1 Xen?
It might be possible to spare some hypercalls by directly writing to grant frames mapped into L1 dom0, but in general you are right.
Juergen