Vixen: A PV-in-HVM shim
v2 cover Vixen: A PV-in-HVM shim
From: Anthony Liguori <[email protected]>
CVE-2017-5754 is problematic for paravirtualized x86 domUs because it appears to be very difficult to isolate the hypervisor's page tables from PV domUs while maintaining ABI compatibility. Instead of trying to make a KPTI-like approach work for Xen PV, it seems reasonable to run a copy of Xen within an HVM (or PVH) domU to provide backwards compatibility with guests as mentioned in XSA-254 [1].
This patch series adds a new mode to Xen called Vixen (Virtualized Xen) which provides a PV-compatible interface while gaining CVE-2017-5754 protection for the host provided by hardware virtualization. Vixen supports running a single unprivileged PV domain (a dom1) that is constructed by the dom0 domain builder.
Please note the Xen page table configuration fundamental to the current PV ABI makes it impossible for an operating system to mitigate CVE-2017-5754 through mechanisms like Kernel Page Table Isolation (KPTI). In order for an operating system to mitigate CVE-2017-5754 it must run directly in a HVM or PVH domU.
This series is very similar to the PVH series posted by Wei and we have been discussing how to merge efforts. We were hoping to have more time to work this out. I am posting this because I'm fairly confident that this series is complete (all PV instances in EC2 are using this) and others might find it useful. I also wanted to have more of a discussion about the best way to merge and some of the differences in designs.
This series is also available at:
git clone https://github.com/aliguori/xen.git vixen-upstream-v2
Changelog:
v1 -> v2
- fix ARM build
- add vixen_domid command line parameter
- make version pass through optional
- pull in p2m mapping fix from sidewinder
- panic if dom0_construct_pv fails
- #defines for the vendor/device id of platform device
- coding style for event channel polling
- reserve even more in the e820 table based on hvm_info_table
- moved shared info to special page range
- make grant table frames come from special page range
- refactor grant tables to use single dispatch function
Not in this version:
- Avoiding vixen domain == hardware domain
Regards,
Anthony Liguori
[1] https://xenbits.xen.org/xsa/advisory-254.html
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/23 ---- x86/Kconfig: Options for Xen and PVH support
From: Andrew Cooper <[email protected]>
--- xen/arch/x86/Kconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
xen/arch/x86/Kconfig +17 -0
@@ -117,6 +117,23 @@ config TBOOT Technology (TXT) If unsure, say Y. + +config XEN_GUEST + def_bool y + prompt "Xen Guest" + ---help--- + Support for Xen detecting when it is running under Xen. + + If unsure, say Y. + +config PVH_GUEST + def_bool n + prompt "PVH Guest" + depends on XEN_GUEST + ---help--- + Support booting using the PVH ABI. + + If unsure, say N. endmenu source "common/Kconfig"
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/23 x86/entry: Probe for Xen early during boot
In reply to Anthony LiguoriFrom: Andrew Cooper <[email protected]>
---
v1 -> v2
- ARM stubs
--- xen/arch/x86/Makefile | 1 + xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/xen.c | 75 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 4 +++ xen/include/asm-arm/guest.h | 22 ++++++++++++ xen/include/asm-x86/guest.h | 34 +++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 47 ++++++++++++++++++++++++++ 7 files changed, 184 insertions(+) create mode 100644 xen/arch/x86/guest/Makefile create mode 100644 xen/arch/x86/guest/xen.c create mode 100644 xen/include/asm-arm/guest.h create mode 100644 xen/include/asm-x86/guest.h create mode 100644 xen/include/asm-x86/guest/xen.h
xen/arch/x86/Makefile +1 -0
@@ -1,6 +1,7 @@ subdir-y += acpi subdir-y += cpu subdir-y += genapic +subdir-$(CONFIG_XEN_GUEST) += guest subdir-$(CONFIG_HVM) += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile
xen/arch/x86/guest/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += xen.o
xen/arch/x86/guest/xen.c new file +75 -0
75 lines not on this page · raw message
xen/arch/x86/setup.c +4 -0
@@ -51,6 +51,8 @@#include <asm/alternative.h> #include <asm/mc146818rtc.h> #include <asm/cpuid.h> +#include <asm/guest.h> +#include <public/arch-x86/cpuid.h> /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp;
@@ -704,6 +706,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); +probe_hypervisor (); +parse_video_info ();rdmsrl (MSR_EFER ,this_cpu (efer));
xen/include/asm-arm/guest.h new file +22 -0
@@ -0,0 +1,22 @@ +/****************************************************************************** +* include/asm-x86/guest.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2018 Amazon.com, Inc. or its affiliates. +*/ + +#ifndef __ARM_GUEST_H__ +#define __ARM_GUEST_H__ + +#endif
xen/include/asm-x86/guest.h new file +34 -0
@@ -0,0 +1,34 @@ +/****************************************************************************** +* asm-x86/guest.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#ifndef __X86_GUEST_H__ +#define __X86_GUEST_H__ + +#include <asm/guest/xen.h> + +#endif /* __X86_GUEST_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/guest/xen.h new file +47 -0
47 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/23 x86/guest: Hypercall support
In reply to Anthony LiguoriFrom: Andrew Cooper <[email protected]>
--- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hypercall_page.S | 79 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/xen.c | 5 ++ xen/arch/x86/xen.lds.S | 1 + xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypercall.h | 92 +++++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 xen/arch/x86/guest/hypercall_page.S create mode 100644 xen/include/asm-x86/guest/hypercall.h
xen/arch/x86/guest/Makefile +1 -0
@@ -1 +1,2 @@ +obj-y += hypercall_page.o obj-y += xen.o
xen/arch/x86/guest/hypercall_page.S new file +79 -0
79 lines not on this page · raw message
xen/arch/x86/guest/xen.c +5 -0
@@ -22,6 +22,7 @@#include <xen/types.h> #include <asm/guest.h> +#include <asm/msr.h> #include <asm/processor.h> #include <public/arch-x86/cpuid.h>
@@ -29,6 +30,7 @@bool xen_guest;static uint32_t xen_cpuid_base; +extern char hypercall_page[];static void __init find_xen_leaves (void ) {
@@ -61,6 +63,9 @@ void __init probe_hypervisor(void)if ( !xen_cpuid_base )return ; +/* Fill the hypercall page. */ +wrmsrl (cpuid_ebx (xen_cpuid_base +2 ),__pa (hypercall_page)); + xen_guest = true; }
xen/arch/x86/xen.lds.S +1 -0
@@ -59,6 +59,7 @@ SECTIONS .text : { _stext = .; /* Text and read-only data */ *(.text) + *(.text.page_aligned) *(.text.cold) *(.text.unlikely) *(.fixup)
xen/include/asm-x86/guest.h +1 -0
@@ -19,6 +19,7 @@#ifndef __X86_GUEST_H__#define __X86_GUEST_H__ +#include <asm/guest/hypercall.h> #include <asm/guest/xen.h> #endif /* __X86_GUEST_H__ */
xen/include/asm-x86/guest/hypercall.h new file +92 -0
92 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/23 x86: Don't use potentially incorrect CPUID values for topology information
In reply to Anthony LiguoriFrom: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."
And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/cpu/common.c +2 -2
@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {
@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;break ; }
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
Quoted 12 lines · Anthony Liguori
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."
Quoted 7 lines
And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>
fix the 1 to 1u on commit.
Quoted 19 lines
--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {
xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 495
Quoted 9 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;break ; }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
In reply to Anthony LiguoriAnthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {
xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;
On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to core_level_siblings == 16 and therefore x86_max_cores == 8. If read from ebx like before this change and what Linux is still doing [1] it reads core_level_siblings == 8 (as expected?).
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
Quoted 3 lines
xen/arch/x86/cpu/common.c +0
-0break ; }
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
Quoted 53 lines · Simon Gaiser
Anthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to
core_level_siblings== 16 and thereforex86_max_cores== 8. If read from ebx like before this change and what Linux is still doing [1] it readscore_level_siblings== 8 (as expected?).
Quoted 5 lines
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
The only use of the variable in question is in this statement:
c->x86_max_cores = (core_level_siblings / c->x86_num_siblings);
Note the "max" in the name. This is how many _could_ be there, not how many _are_ there, aiui.
Jan
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
Jan Beulich:
Quoted 60 lines · Simon Gaiser
Quoted 53 lines
Anthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to
core_level_siblings== 16 and thereforex86_max_cores== 8. If read from ebx like before this change and what Linux is still doing [1] it readscore_level_siblings== 8 (as expected?).Quoted 5 lines
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
Quoted 6 lines
The only use of the variable in question is in this statement:
c->x86_max_cores = (core_level_siblings / c->x86_num_siblings);Note the "max" in the name. This is how many _could_ be there, not how many _are_ there, aiui.
I'm indeed not quite sure on the intended semantic, hence the question (although it's not clear to me what case that "could" would cover here).
It doesn't have to be identical but Linux says for it's version of the variable:
The number of cores in a package. This information is retrieved via CPUID.
And if I look at it's usage in set_nr_sockets in Xen:
nr_sockets = last_physid(phys_cpu_present_map)
/ boot_cpu_data.x86_max_cores
/ boot_cpu_data.x86_num_siblings + 1;It seems to be also be used in this meaning. At least on my test system I get last_physid == 7 (as I would have expected for 8 logical cpus). So dividing this by the 4 (number of cores) and 2 (threads per core) is what I think was intended here.
Simon
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
Quoted 63 lines · Simon Gaiser
Jan Beulich:
Quoted 62 lines · Simon Gaiser
Quoted 53 lines
Anthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to
core_level_siblings== 16 and thereforex86_max_cores== 8. If read from ebx like before this change and what Linux is still doing [1] it readscore_level_siblings== 8 (as expected?).Quoted 5 lines
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
The only use of the variable in question is in this statement:
Quoted 7 lines
Quoted 4 lines
c->x86_max_cores = (core_level_siblings / c->x86_num_siblings);Note the "max" in the name. This is how many _could_ be there, not how many _are_ there, aiui.
I'm indeed not quite sure on the intended semantic, hence the question (although it's not clear to me what case that "could" would cover here).
"Could" covers for a number of reasons why APIC IDs may not be contiguous. Consider a 6-code system: The APIC IDs need to cover for at least 8 there.
Quoted 11 lines
It doesn't have to be identical but Linux says for it's version of the variable:
The number of cores in a package. This information is retrieved via CPUID.
And if I look at it's usage in
set_nr_socketsin Xen:nr_sockets = last_physid(phys_cpu_present_map) / boot_cpu_data.x86_max_cores / boot_cpu_data.x86_num_siblings + 1;
This validly uses the field in the "max" sense, not in the "actual" one.
Quoted 4 lines
It seems to be also be used in this meaning. At least on my test system I get
last_physid== 7 (as I would have expected for 8 logical cpus). So dividing this by the 4 (number of cores) and 2 (threads per core) is what I think was intended here.
Would you mind providing raw data from your system: Both the raw CPUID output for the leaf/leaves of interest here and the APIC IDs of all threads?
Jan
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
Jan Beulich:
Quoted 81 lines · Simon Gaiser
Quoted 63 lines
Jan Beulich:
Quoted 62 lines · Simon Gaiser
Quoted 53 lines
Anthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to
core_level_siblings== 16 and thereforex86_max_cores== 8. If read from ebx like before this change and what Linux is still doing [1] it readscore_level_siblings== 8 (as expected?).Quoted 5 lines
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
The only use of the variable in question is in this statement:
Quoted 7 lines
Quoted 4 lines
c->x86_max_cores = (core_level_siblings / c->x86_num_siblings);Note the "max" in the name. This is how many _could_ be there, not how many _are_ there, aiui.
I'm indeed not quite sure on the intended semantic, hence the question (although it's not clear to me what case that "could" would cover here).
"Could" covers for a number of reasons why APIC IDs may not be contiguous. Consider a 6-code system: The APIC IDs need to cover for at least 8 there.
Quoted 6 lines
It doesn't have to be identical but Linux says for it's version of the variable:
The number of cores in a package. This information is retrieved via CPUID.
Quoted 7 lines
Quoted 5 lines
And if I look at it's usage in
set_nr_socketsin Xen:nr_sockets = last_physid(phys_cpu_present_map) / boot_cpu_data.x86_max_cores / boot_cpu_data.x86_num_siblings + 1;This validly uses the field in the "max" sense, not in the "actual" one.
I see, both cases cover APIC IDs not just numbers of logical CPUs. Thanks for the explanation and the pointer from Andrew in his response.
I just had noticed the, to me, unexpected value, while debugging something. But based on this explanation things are actually working as intended here. (The actual problem I was looking for it turned out to be [1].)
Quoted 8 lines
Quoted 4 lines
It seems to be also be used in this meaning. At least on my test system I get
last_physid== 7 (as I would have expected for 8 logical cpus). So dividing this by the 4 (number of cores) and 2 (threads per core) is what I think was intended here.Would you mind providing raw data from your system: Both the raw CPUID output for the leaf/leaves of interest here and the APIC IDs of all threads?
Sure:
From attached patch:
(XEN) dbg smp_processor_id() = 0
(XEN) dbg get_apic_id() = 0
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0
(XEN) dbg smp_processor_id() = 1
(XEN) dbg get_apic_id() = 1
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x1 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x1
(XEN) dbg smp_processor_id() = 2
(XEN) dbg get_apic_id() = 2
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x2 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x2
(XEN) dbg smp_processor_id() = 3
(XEN) dbg get_apic_id() = 3
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x3 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x3
(XEN) dbg smp_processor_id() = 4
(XEN) dbg get_apic_id() = 4
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x4 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x4
(XEN) dbg smp_processor_id() = 5
(XEN) dbg get_apic_id() = 5
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x5 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x5
(XEN) dbg smp_processor_id() = 6
(XEN) dbg get_apic_id() = 6
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x6 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x6
(XEN) dbg smp_processor_id() = 7
(XEN) dbg get_apic_id() = 7
(XEN) dbg cpuid_count(0xb, SMT_LEVEL) = 0x1, 0x2, 0x100, 0x7 (XEN) dbg cpuid_count(0xb, 0x1) = 0x4, 0x8, 0x201, 0x7
From the MADT table:
[02Ch 0044 1] Subtable Type : 00 [Processor Local APIC] [02Dh 0045 1] Length : 08 [02Eh 0046 1] Processor ID : 00 [02Fh 0047 1] Local Apic ID : 00 [030h 0048 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[034h 0052 1] Subtable Type : 00 [Processor Local APIC] [035h 0053 1] Length : 08 [036h 0054 1] Processor ID : 01 [037h 0055 1] Local Apic ID : 02 [038h 0056 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[03Ch 0060 1] Subtable Type : 00 [Processor Local APIC] [03Dh 0061 1] Length : 08 [03Eh 0062 1] Processor ID : 02 [03Fh 0063 1] Local Apic ID : 04 [040h 0064 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[044h 0068 1] Subtable Type : 00 [Processor Local APIC] [045h 0069 1] Length : 08 [046h 0070 1] Processor ID : 03 [047h 0071 1] Local Apic ID : 06 [048h 0072 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[04Ch 0076 1] Subtable Type : 00 [Processor Local APIC] [04Dh 0077 1] Length : 08 [04Eh 0078 1] Processor ID : 04 [04Fh 0079 1] Local Apic ID : 01 [050h 0080 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[054h 0084 1] Subtable Type : 00 [Processor Local APIC] [055h 0085 1] Length : 08 [056h 0086 1] Processor ID : 05 [057h 0087 1] Local Apic ID : 03 [058h 0088 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[05Ch 0092 1] Subtable Type : 00 [Processor Local APIC] [05Dh 0093 1] Length : 08 [05Eh 0094 1] Processor ID : 06 [05Fh 0095 1] Local Apic ID : 05 [060h 0096 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[064h 0100 1] Subtable Type : 00 [Processor Local APIC] [065h 0101 1] Length : 08 [066h 0102 1] Processor ID : 07 [067h 0103 1] Local Apic ID : 07 [068h 0104 4] Flags (decoded below) : 00000001
Processor Enabled : 1
Runtime Online Capable : 0
[06Ch 0108 1] Subtable Type : 00 [Processor Local APIC] [06Dh 0109 1] Length : 08 [06Eh 0110 1] Processor ID : 08 [06Fh 0111 1] Local Apic ID : FF [070h 0112 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[074h 0116 1] Subtable Type : 00 [Processor Local APIC] [075h 0117 1] Length : 08 [076h 0118 1] Processor ID : 09 [077h 0119 1] Local Apic ID : FF [078h 0120 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[07Ch 0124 1] Subtable Type : 00 [Processor Local APIC] [07Dh 0125 1] Length : 08 [07Eh 0126 1] Processor ID : 0A [07Fh 0127 1] Local Apic ID : FF [080h 0128 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[084h 0132 1] Subtable Type : 00 [Processor Local APIC] [085h 0133 1] Length : 08 [086h 0134 1] Processor ID : 0B [087h 0135 1] Local Apic ID : FF [088h 0136 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[08Ch 0140 1] Subtable Type : 00 [Processor Local APIC] [08Dh 0141 1] Length : 08 [08Eh 0142 1] Processor ID : 0C [08Fh 0143 1] Local Apic ID : FF [090h 0144 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[094h 0148 1] Subtable Type : 00 [Processor Local APIC] [095h 0149 1] Length : 08 [096h 0150 1] Processor ID : 0D [097h 0151 1] Local Apic ID : FF [098h 0152 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[09Ch 0156 1] Subtable Type : 00 [Processor Local APIC] [09Dh 0157 1] Length : 08 [09Eh 0158 1] Processor ID : 0E [09Fh 0159 1] Local Apic ID : FF [0A0h 0160 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
[0A4h 0164 1] Subtable Type : 00 [Processor Local APIC] [0A5h 0165 1] Length : 08 [0A6h 0166 1] Processor ID : 0F [0A7h 0167 1] Local Apic ID : FF [0A8h 0168 4] Flags (decoded below) : 00000000
Processor Enabled : 0
Runtime Online Capable : 0
If you wanted something else or need more, just let me know.
Simon
xen/arch/x86/cpu/common.c +5 -0
@@ -624,7 +624,11 @@ bool detect_extended_topology(struct cpuinfo_x86 *c)if ( c->cpuid_level <0xb )return false; +printk ("dbg smp_processor_id() = %u\n" ,smp_processor_id ()); +printk ("dbg get_apic_id() = %u\n" ,get_apic_id ()); +cpuid_count (0xb ,SMT_LEVEL , &eax, &ebx, &ecx, &edx); +printk ("dbg cpuid_count(0xb, SMT_LEVEL) = %#x, %#x, %#x, %#x\n" , eax, ebx, ecx, edx);/* Check if the cpuid leaf 0xb is actually implemented */ if ( ebx ==0 || (LEAFB_SUBTYPE (ecx) !=SMT_TYPE ) )
@@ -641,6 +645,7 @@ bool detect_extended_topology(struct cpuinfo_x86 *c) sub_index =1 ; do { cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx); + printk("dbg cpuid_count(0xb, %#x) = %#x, %#x, %#x, %#x\n", sub_index, eax, ebx, ecx, edx); /* Check for the Core type in the implemented sub leaves */ if ( LEAFB_SUBTYPE(ecx) == CORE_TYPE ) {
Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information
In reply to Simon GaiserQuoted 52 lines · Simon Gaiser
Anthony Liguori:
Quoted 38 lines
From: Jan H. Schönherr <[email protected]>
Intel says for CPUID leaf 0Bh:
"Software must not use EBX[15:0] to enumerate processor
topology of the system. This value in this field (EBX[15:0]) is only intended for display/diagnostic purposes. The actual number of logical processors available to BIOS/OS/Applications may be different from the value of EBX[15:0], depending on software and platform hardware configurations."And yet, we're using them to derive the number cores in a package and the number of siblings in a core.
Derive the number of siblings and cores from EAX instead, which is intended for that.
Signed-off-by Jan H. Schönherr <[email protected]>--- xen/arch/x86/cpu/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/cpu/common.c +1
-1@@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c) initial_apicid = edx;/* Populate HT related information from sub-leaf level 0 */ - core_level_siblings = c->x86_num_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width = ht_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings = c->x86_num_siblings =1 << ht_mask_width; sub_index =1 ; do {xen/arch/x86/cpu/common.c void detect_extended_topology(struct cpuinfo_x86 *c) · line 492
Quoted 6 lines
xen/arch/x86/cpu/common.c +1
-1@@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)/* Check for the Core type in the implemented sub leaves */ if (LEAFB_SUBTYPE (ecx) ==CORE_TYPE ) { - core_level_siblings =LEVEL_MAX_SIBLINGS (ebx); core_plus_mask_width =BITS_SHIFT_NEXT_LEVEL (eax); + core_level_siblings =1 << core_plus_mask_width;On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on I noticed that this changes leads to
core_level_siblings== 16 and thereforex86_max_cores== 8. If read from ebx like before this change and what Linux is still doing [1] it readscore_level_siblings== 8 (as expected?).
Quoted 7 lines
What's the expected semantic here? If it's to derive the actual number of siblings (and therefore cores) in a package as the commit message suggest, the new code can't work even ignoring the example from my test system. It will always produce powers of 2, so can't get it right on a system with, say, 6 cores.
Topology is broken in many subtle ways, including bits Xen inherited from Linux.
As it happens, Thomas is working on the Linux side right now, and it's been quite an effort...
https://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git/log/?h=x86/topo-full
In some copious free time I'll be ste^W borrowing this. It comes with a negative diffstat too.
~Andrew
PATCH v2 5/23 char: optionally redirect {, g}printk output to QEMU debug log
In reply to Anthony LiguoriFrom: Matt Wilson <[email protected]>
When using Vixen, it is helpful to get the Xen messages in a separate channel than the console output. Add an option to output to the QEMU backdoor logging port.
---
v1 -> v2
- #ifdef for !x86_64
--- xen/drivers/char/console.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +32 -3
@@ -85,6 +85,11 @@ static int __read_mostly sercon_handle = -1;static DEFINE_SPINLOCK (console_lock); +/* send all printk output to QEMU debug log. Input does not change, +* nor does dom0 output. +*/ +static bool_t __read_mostly qemu_debug = false; +/* * To control the amount of printing, thresholds are added. * These thresholds correspond to the XENLOG logging levels.
@@ -560,14 +565,36 @@ long do_console_io(int cmd, int count, XEN_GUEST_HANDLE_PARAM(char) buffer)static bool_t console_locks_busted; +#if defined(__x86_64__) +static void qemu_putstr (const char *str) +{ +char c; +while ( (c = *str++) !='\0' ) + { +outb (c,0x12 ); + } +} +#else +static void qemu_putstr (const char *str) +{ +} +#endif +static void __putstr (const char *str) {ASSERT (spin_is_locked (&console_lock)); -sercon_puts (str); -video_puts (str); +if ( qemu_debug ) + { +qemu_putstr (str); + } +else + { +sercon_puts (str); +video_puts (str); -conring_puts (str); +conring_puts (str); + }if ( !console_locks_busted )tasklet_schedule (¬ify_dom0_con_ring_tasklet);
@@ -762,6 +789,8 @@ void __init console_init_preirq(void) p++;if ( !strncmp (p,"vga" ,3 ) )video_init (); +else if ( !strncmp (p,"qemu" ,4 ) ) + qemu_debug = true;else if ( !strncmp (p,"none" ,4 ) )continue ;else if ( (sh =serial_parse_handle (p)) >=0 )
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 05/23] char: optionally redirect {, g}printk output to QEMU debug log
Quoted 7 lines · Anthony Liguori
From: Matt Wilson <[email protected]>
When using Vixen, it is helpful to get the Xen messages in a separate channel than the console output. Add an option to output to the QEMU backdoor logging port.
Signed-off-by Matt Wilson <[email protected]>
I think this should be merged with or built on top of one of the patches in pv-in-pvh shim series that adds console and magic debug port output.
I will see what I can do.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/23 console: do not print banner if below info log threshold
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Only print the banner if the log threshold is at least info.
For Vixen guests, we want the console output to be exactly what the PV guest would show on it's own. That means the inner Xen banner can potentially break automation that assumes a specific type of console output.
--- xen/drivers/char/console.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +6 -3
@@ -812,9 +812,12 @@ void __init console_init_preirq(void)serial_set_rx_handler (sercon_handle, serial_rx);/* HELLO WORLD --- start-of-day banner text. */ -spin_lock (&console_lock); -__putstr (xen_banner ()); -spin_unlock (&console_lock); +if (2 < xenlog_lower_thresh ) { +/* Only display at XENLOG_INFO level */ +spin_lock (&console_lock); +__putstr (xen_banner ()); +spin_unlock (&console_lock); + } printk("Xen version %d.%d%s (%s@%s) (%s) debug=%c " gcov_string " %s\n", xen_major_version(), xen_minor_version(), xen_extra_version(), xen_compile_by(), xen_compile_domain(),
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 06/23] console: do not print banner if below info log threshold
Quoted 8 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
Only print the banner if the log threshold is at least info.
For Vixen guests, we want the console output to be exactly what the PV guest would show on it's own. That means the inner Xen banner can potentially break automation that assumes a specific type of console output.
:-)
Quoted 12 lines
Signed-off-by Anthony Liguori <[email protected]>--- xen/drivers/char/console.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)xen/drivers/char/console.c +0
-0
xen/drivers/char/console.c void __init console_init_preirq(void) · line 815
Quoted 7 lines
xen/drivers/char/console.c +1
-3@@ -812,9 +812,12 @@ void __init console_init_preirq(void)serial_set_rx_handler (sercon_handle, serial_rx);/* HELLO WORLD --- start-of-day banner text. */ -spin_lock (&console_lock); -__putstr (xen_banner ()); -spin_unlock (&console_lock); +if (2 < xenlog_lower_thresh ) {
This should become a tunable (command line option?) instead of being hardcoded.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 7/23 vixen: introduce is_vixen() to allow altering behavior
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Vixen (Virtualized Xen) is a paravirtual mode of Xen where paravirtual I/O is passed through from the parent hypervisor all the way through the dom0 guest. The dom0 guest is also deprivileged and renumbered to give the appearance that it is running as a normal PV guest.
---
v1 -> v2
- ARM stubs
--- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/vixen.c | 30 +++++++++++++++ xen/include/asm-arm/guest/vixen.h | 81 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/vixen.h | 73 +++++++++++++++++++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 xen/arch/x86/guest/vixen.c create mode 100644 xen/include/asm-arm/guest/vixen.h create mode 100644 xen/include/asm-x86/guest/vixen.h
xen/arch/x86/guest/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y += hypercall_page.o obj-y += xen.o +obj-y += vixen.o
xen/arch/x86/guest/vixen.c new file +30 -0
@@ -0,0 +1,30 @@ +/****************************************************************************** +* arch/x86/guest/vixen.c +* +* Support for detecting and running under Xen HVM. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. +*/ + +#include <asm/guest/vixen.h> + +static int in_vixen; + +bool is_vixen (void ) +{ +return in_vixen >0 ; +} +
xen/include/asm-arm/guest/vixen.h new file +81 -0
81 lines not on this page · raw message
xen/include/asm-x86/guest/vixen.h new file +73 -0
73 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/23] vixen: introduce is_vixen() to allow altering behavior
Quoted 10 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
Vixen (Virtualized Xen) is a paravirtual mode of Xen where paravirtual I/O is passed through from the parent hypervisor all the way through the dom0 guest. The dom0 guest is also deprivileged and renumbered to give the appearance that it is running as a normal PV guest.
Signed-off-by Anthony Liguori <[email protected]>+
[...]
Quoted 4 lines
xen/include/asm-arm/guest/vixen.h new file +4
-0+static inline bool is_vixen (void ) +{ +return false; +}
xen/include/asm-arm/guest/vixen.h line 79
Quoted 10 lines
xen/include/asm-arm/guest/vixen.h new file +10
-0+ +static inline bool vixen_has_per_cpu_notifications (void ) +{ +return false; +} + +static inline bool vixen_ring_process (uint16_t port) +{ +return false; +}
AFAICT only these are vixen specific. The rest can be merged with pv-in-pvh code.
I'm not sure why they are needed yet. If I can figure that out later I will ask questions here.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 8/23 vixen: allow dom0 to be created with a domid != 0
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Some older guests special case domid=0 instead of checking the shared info flags so in order to get PV drivers loaded properly, we need to make the guest always appear with a domid != 0.
While the Vixen domain is the hardware domain, we don't want it to behave that way so we also modify the is_hardware_domain() check.
---
v1 -> v2
- allow vixen domain id to be overridden via the Xen command line
--- xen/arch/x86/dom0_build.c | 2 +- xen/arch/x86/guest/vixen.c | 7 +++++++ xen/arch/x86/setup.c | 2 +- xen/common/domain.c | 4 ++-- xen/include/asm-arm/guest/vixen.h | 5 +++++ xen/include/asm-x86/guest/vixen.h | 2 ++ xen/include/xen/sched.h | 6 +++++- 7 files changed, 23 insertions(+), 5 deletions(-)
xen/arch/x86/dom0_build.c +1 -1
@@ -469,7 +469,7 @@ int __init construct_dom0(struct domain *d, const module_t *image,int rc;/* Sanity! */ -BUG_ON (d->domain_id !=0 ); +BUG_ON (d->domain_id != dom0_domid);BUG_ON (d->vcpu[0 ] ==NULL );BUG_ON (d->vcpu[0 ]->is_initialised);
xen/arch/x86/guest/vixen.c +7 -0
@@ -22,9 +22,16 @@#include <asm/guest/vixen.h> static int in_vixen; +static int vixen_domid =1 ; + +integer_param ("vixen_domid" , vixen_domid);bool is_vixen (void ) {return in_vixen >0 ; } +int vixen_get_domid (void ) +{ +return vixen_domid; +}
xen/arch/x86/setup.c +1 -1
@@ -1591,7 +1591,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Create initial domain 0. */ - dom0 =domain_create (0 , domcr_flags,0 , &config); + dom0 =domain_create (dom0_domid, domcr_flags,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" );
xen/common/domain.c +2 -2
@@ -202,7 +202,7 @@ static int late_hwdom_init(struct domain *d)struct domain *dom0;int rv; -if ( d != hardware_domain || d->domain_id ==0 ) +if ( d != hardware_domain || d->domain_id == dom0_domid )return 0 ; rv =xsm_init_hardware_domain (XSM_HOOK , d);
@@ -310,7 +310,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,else d->guest_type = guest_type_pv; -if ( domid ==0 || domid == hardware_domid ) +if ( domid == dom0_domid || domid == hardware_domid ) {if ( hardware_domid <0 || hardware_domid >=DOMID_FIRST_RESERVED )panic ("The value of hardware_dom must be a valid domain ID" );
xen/include/asm-arm/guest/vixen.h +5 -0
@@ -78,4 +78,9 @@ static inline bool vixen_ring_process(uint16_t port) return false; } +static inline int vixen_get_domid (void ) +{ +return 0 ; +} +#endif
xen/include/asm-x86/guest/vixen.h +2 -0
@@ -70,4 +70,6 @@ HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)bool is_vixen (void ); +int vixen_get_domid (void ); +#endif
xen/include/xen/sched.h +5 -1
@@ -27,6 +27,8 @@#include <public/vcpu.h> #include <public/vm_event.h> #include <public/event_channel.h> +#include <asm/guest.h> +#include <asm/guest/vixen.h> #ifdef CONFIG_COMPAT #include <compat/vcpu.h>
@@ -54,6 +56,8 @@ extern domid_t hardware_domid;#define hardware_domid 0#endif +#define dom0_domid (is_vixen() ? vixen_get_domid() : 0) +#ifndef CONFIG_COMPAT #define BITS_PER_EVTCHN_WORD (d) BITS_PER_XEN_ULONG#else
@@ -873,7 +877,7 @@ void watchdog_domain_destroy(struct domain *d);* (that is, this would not be suitable for a driver domain) * - There is never a reason to deny the hardware domain access to this */ -#define is_hardware_domain (_d) ((_d) == hardware_domain) +#define is_hardware_domain (_d) (!is_vixen() && ((_d) == hardware_domain))/* This check is for functionality specific to a control domain */ #define is_control_domain (_d) ((_d)->is_privileged)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 08/23] vixen: allow dom0 to be created with a domid != 0
Quoted 6 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
Some older guests special case domid=0 instead of checking the shared info flags so in order to get PV drivers loaded properly, we need to make the guest always appear with a domid != 0.
Quoted 8 lines
While the Vixen domain is the hardware domain, we don't want it to behave that way so we also modify the
is_hardware_domain()check.Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- allow vixen domain id to be overridden via the Xen command line
This patch will can be broken up into two:
1. A patch that modifies is_hardware_domain.
2. A patch that adds the domid command line option.
But I think the first patch is not required because the pv-in-pvh shim works fine even if the guest is not hardware domain.
Please don't do any real work yet -- we need to agree on the things in the my reply to the cover letter first.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 9/23 vixen: modify the e820 table to advertise HVM special pages as RAM
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
In order to be able to assign the Xenstore page into the Vixen guest, we need struct page_info's to exist. We do this by modifying the e820 table early in boot and then using the badpages handling to prevent these pages from being added to the xenheap.
Since these pages exist in a somewhat weird state in Xen, we need to relax permission checking too in order to be able to assign them to the guest.
---
v1 -> v2
- lay the ground work to use hvm_info_table to determine range
--- xen/arch/x86/e820.c | 11 +++++++++++ xen/arch/x86/guest/vixen.c | 9 +++++++++ xen/arch/x86/mm.c | 3 ++- xen/common/page_alloc.c | 7 +++++++ xen/include/asm-x86/guest/vixen.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)
xen/arch/x86/e820.c +11 -0
@@ -9,6 +9,7 @@#include <asm/processor.h> #include <asm/mtrr.h> #include <asm/msr.h> +#include <asm/guest/vixen.h> /* * opt_mem: Limit maximum address of physical RAM.
@@ -698,6 +699,16 @@ unsigned long __init init_e820(const char *str, struct e820map *raw)print_e820_memory_map (raw->map, raw->nr_map); } +if (is_vixen () ) + { +unsigned long start_pfn, end_pfn; + +vixen_get_reserved_mem (&start_pfn, &end_pfn); + +/* Pretend that passed through special pages are RAM */ +e820_change_range_type (raw, start_pfn <<XEN_PAGE_SHIFT , + end_pfn <<XEN_PAGE_SHIFT ,E820_RESERVED ,E820_RAM ); + }machine_specific_memory_setup (raw);printk ("%s RAM map:\n" , str);
xen/arch/x86/guest/vixen.c +9 -0
@@ -23,6 +23,7 @@static int in_vixen;static int vixen_domid =1 ; +static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;integer_param ("vixen_domid" , vixen_domid);
@@ -35,3 +36,11 @@ int vixen_get_domid(void) {return vixen_domid; } + +void vixen_get_reserved_mem (unsigned long *start_pfn,unsigned long *end_pfn) +{ + *start_pfn = vixen_reserved_mem_pgstart >>XEN_PAGE_SHIFT ; + +/* This is part of the Xen ABI */ + *end_pfn =0x100000 ; +}
xen/arch/x86/mm.c +2 -1
@@ -122,6 +122,7 @@#include <asm/fixmap.h> #include <asm/io_apic.h> #include <asm/pci.h> +#include <asm/guest.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h>
@@ -945,7 +946,7 @@ get_page_from_l1e(case 0 :break ;case 1 : -if ( !is_hardware_domain (l1e_owner) ) +if ( !is_vixen () && !is_hardware_domain (l1e_owner) )break ;/* fallthrough */ case -1 :
xen/common/page_alloc.c +7 -0
@@ -303,6 +303,13 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) badpage++; } } + +if (is_vixen () ) { +unsigned long start_pfn, end_pfn; + +vixen_get_reserved_mem (&start_pfn, &end_pfn); +bootmem_region_zap (start_pfn, end_pfn); + }#endif /* Check new pages against the bad-page list. */
xen/include/asm-x86/guest/vixen.h +2 -0
@@ -72,4 +72,6 @@ bool is_vixen(void);int vixen_get_domid (void ); +void vixen_get_reserved_mem (unsigned long *start_pfn,unsigned long *end_pfn); +#endif
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 09/23] vixen: modify the e820 table to advertise HVM special pages as RAM
Quoted 1 line · Anthony Liguori
From: Anthony Liguori <[email protected]>
..snip.
xen/arch/x86/guest/vixen.c line 26
Quoted 9 lines
xen/arch/x86/guest/vixen.c +1
-0@@ -23,6 +23,7 @@static int in_vixen;static int vixen_domid =1 ; +static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;
This is interesting. Would it make sense to have this be auto-detected? Or a boot parameter to over-write?
xen/arch/x86/guest/vixen.c int vixen_get_domid(void) · line 44
Quoted 13 lines
xen/arch/x86/guest/vixen.c +6
-0integer_param ("vixen_domid" , vixen_domid);@@ -35,3 +36,11 @@ int vixen_get_domid(void) {return vixen_domid; } + +void vixen_get_reserved_mem (unsigned long *start_pfn,unsigned long *end_pfn) +{ + *start_pfn = vixen_reserved_mem_pgstart >>XEN_PAGE_SHIFT ; + +/* This is part of the Xen ABI */
.. which one :-) ?
xen/arch/x86/guest/vixen.c int vixen_get_domid(void) · line 46
Quoted 2 lines
xen/arch/x86/guest/vixen.c +2
-0+ *end_pfn =0x100000 ; +}
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 09/23] vixen: modify the e820 table to advertise HVM special pages as RAM
Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Anthony Liguori
From: Anthony Liguori <[email protected]>
..snip.
Quoted 6 lines
xen/arch/x86/guest/vixen.c +0
-0@@ -23,6 +23,7 @@
Quoted 6 lines
xen/arch/x86/guest/vixen.c line 26
Quoted 3 lines
xen/arch/x86/guest/vixen.c +1
-0static int in_vixen;static int vixen_domid =1 ; +static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;This is interesting. Would it make sense to have this be auto-detected? Or a boot parameter to over-write?
This is done in a later patch (the one that sets up event channels).
It cannot be done here because we don't have enough infrastructure.
Quoted 14 lines
xen/arch/x86/guest/vixen.c int vixen_get_domid(void) · line 44
Quoted 12 lines
xen/arch/x86/guest/vixen.c +6
-0integer_param ("vixen_domid" , vixen_domid);@@ -35,3 +36,11 @@ int vixen_get_domid(void) {return vixen_domid; } + +void vixen_get_reserved_mem (unsigned long *start_pfn,unsigned long *end_pfn) +{ + *start_pfn = vixen_reserved_mem_pgstart >>XEN_PAGE_SHIFT ; + +/* This is part of the Xen ABI */ .. which one :-) ?
include/public/hvm/hvm_info_table.h. See the comment around reserved_mem_pgstart.
Regards,
Anthony Liguori
Quoted 7 lines
xen/arch/x86/guest/vixen.c int vixen_get_domid(void) · line 46
Quoted 2 lines
xen/arch/x86/guest/vixen.c +2
-0+ *end_pfn =0x100000 ; +}_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 10/23 vixen: do not permit access to physical IRQs if in Vixen mode
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Our intention is for the Vixen guest to be deprivileged so we need to avoid permitting access to each IRQ even though it is technically the hardware domain.
--- xen/arch/x86/irq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/irq.c +2 -1
@@ -25,6 +25,7 @@#include <asm/flushtlb.h> #include <asm/mach-generic/mach_apic.h> #include <public/physdev.h> +#include <asm/guest/vixen.h> static int parse_irq_vector_map_param (const char *s);
@@ -190,7 +191,7 @@ int create_irq(nodeid_t node) desc->arch.used =IRQ_UNUSED ; irq = ret; } -else if ( hardware_domain ) +else if ( !is_vixen () && hardware_domain ) { ret =irq_permit_access (hardware_domain, irq);if ( ret )
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 11/23 vixen: early initialization of Vixen including shared_info mapping
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
We split initialization of Vixen into two parts. The first part just detects the presence of an HVM hypervisor so that we can figure out whether to modify the e820 table.
The later initialization is used to actually map the shared_info structure from the parent hypervisor into Xen.
---
v1 -> v2
- allow disabling vixen by specifying vixen_domid=-1 on command line
- use hvm_info_table for reserved region if still valid
- use reserved region for shared_info instead of BSS
--- xen/arch/x86/guest/vixen.c | 76 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 5 +++ xen/include/asm-x86/guest/vixen.h | 4 +++ 3 files changed, 85 insertions(+)
xen/arch/x86/guest/vixen.c +76 -0
@@ -20,13 +20,89 @@*/ #include <asm/guest/vixen.h> +#include <public/version.h> +#include <public/hvm/hvm_info_table.h> + +#define X86_HVM_END_SPECIAL_REGION 0xff000u + +#define SHARED_INFO_PFN (X86_HVM_END_SPECIAL_REGION + 0)static int in_vixen;static int vixen_domid =1 ;static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ; +static shared_info_t *global_si;integer_param ("vixen_domid" , vixen_domid); +void __init init_vixen (void ) +{ +int major, minor, version; +struct hvm_info_table *hvm_info; + +if ( !xen_guest ) + { +printk ("Disabling Vixen because we are not running under Xen\n" ); + in_vixen =-1 ; +return ; + } + +if ( vixen_domid <0 ) + { +printk ("Disabling Vixen due to user request\n" ); + in_vixen =-1 ; +return ; + } + + version =HYPERVISOR_xen_version (XENVER_version,NULL ); + major = version >>16 ; + minor = version &0xffff ; + +printk ("Vixen running under Xen %d.%d\n" , major, minor); + + hvm_info =maddr_to_virt (HVM_INFO_PADDR ); +if (strncmp (hvm_info->signature,"HVM INFO" ,8 ) ==0 && + hvm_info->length >=sizeof (struct hvm_info_table ) && + hvm_info->length < (PAGE_SIZE -HVM_INFO_OFFSET ) ) + { +uint8_t sum; +uint32_t i; + +for ( i =0 , sum =0 ; i < hvm_info->length; i++ ) + sum += ((uint8_t *)hvm_info)[i]; + +if ( sum ==0 ) + { + vixen_reserved_mem_pgstart = hvm_info->reserved_mem_pgstart <<XEN_PAGE_SHIFT ; + } + } + + in_vixen =1 ; +} + +void __init early_vixen_init (void ) +{ +struct xen_add_to_physmap xatp; +long rc; + +if ( !is_vixen () ) +return ; + + global_si =mfn_to_virt (SHARED_INFO_PFN ); + +/* Setup our own shared info area */ + xatp.domid =DOMID_SELF ; + xatp.idx =0 ; + xatp.space = XENMAPSPACE_shared_info; + xatp.gpfn =virt_to_mfn (global_si); + + rc =HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp); +if ( rc <0 ) +printk ("Setting shared info page failed: %ld\n" , rc); + +memset (&global_si->native.evtchn_mask[0 ],0x00 , +sizeof (global_si->native.evtchn_mask)); +} +bool is_vixen (void ) {return in_vixen >0 ;
xen/arch/x86/setup.c +5 -0
@@ -869,6 +869,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)else panic ("Bootloader provided no memory information." ); +/* Vixen must be initialized before init_e820() */ +init_vixen (); +/* Sanitise the raw E820 map to produce a final clean version. */ max_page = raw_max_page =init_e820 (memmap_type, &e820_raw);
@@ -1516,6 +1519,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)rcu_init (); +early_vixen_init (); +early_time_init ();arch_init_memory ();
xen/include/asm-x86/guest/vixen.h +4 -0
@@ -74,4 +74,8 @@ int vixen_get_domid(void);void vixen_get_reserved_mem (unsigned long *start_pfn,unsigned long *end_pfn); +void __init init_vixen (void ); + +void __init early_vixen_init (void ); +#endif
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 12/23 vixen: paravirtualization TSC frequency calculation
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Otherwise when time sharing a physical CPU, the calculation can be bogus resulting in time drift for the guest due to improper frequency within pvclock.
--- xen/arch/x86/guest/vixen.c | 22 ++++++++++++++++++++++ xen/arch/x86/time.c | 9 ++++++++- xen/include/asm-x86/guest/vixen.h | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-)
xen/arch/x86/guest/vixen.c +22 -0
@@ -120,3 +120,25 @@ void vixen_get_reserved_mem(unsigned long *start_pfn, unsigned long *end_pfn)/* This is part of the Xen ABI */ *end_pfn =0x100000 ; } + +u64 vixen_get_cpu_freq (void ) +{ +volatile vcpu_time_info_t *timep = &global_si->native.vcpu_info[0 ].time; +vcpu_time_info_t time; +uint32_t version; +u64 imm; + +do { + version = timep->version; +rmb (); + time = *timep; + }while ((version &1 ) || version != time.version); + + imm = (1000000000ULL <<32 ) / time.tsc_to_system_mul; + +if (time.tsc_shift <0 ) { +return imm << -time.tsc_shift; + }else { +return imm >> time.tsc_shift; + } +}
xen/arch/x86/time.c +8 -1
@@ -36,6 +36,7 @@#include <io_ports.h> #include <asm/setup.h> /* for early_time_init */ #include <public/arch-x86/cpuid.h> +#include <asm/guest/vixen.h> /* opt_clocksource: Force clocksource to one of: pit, hpet, acpi. */ static char __initdata opt_clocksource[10 ];
@@ -1687,6 +1688,12 @@ void __init early_time_init(void)preinit_pit (); tmp =init_platform_timer (); + +/* We cannot trust calibrated values when running under +* a hypervisor. */ +if (is_vixen () ) + tmp =vixen_get_cpu_freq (); + plt_tsc.frequency = tmp;set_time_scale (&t->tsc_scale, tmp);
@@ -2014,7 +2021,7 @@ void tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nsec, uint32_t gtsc_khz, uint32_t incarnation) { - if ( is_idle_domain(d) || is_hardware_domain(d) ) + if ( is_idle_domain(d) || is_vixen() || is_hardware_domain(d) ) { d->arch.vtsc = 0;return ;
xen/include/asm-x86/guest/vixen.h +2 -0
@@ -78,4 +78,6 @@ void __init init_vixen(void);void __init early_vixen_init (void ); +u64 vixen_get_cpu_freq (void ); +#endif
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/23] vixen: paravirtualization TSC frequency calculation
Quoted 6 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
Otherwise when time sharing a physical CPU, the calculation can be bogus resulting in time drift for the guest due to improper frequency within pvclock.
What clock source is vixen using? What about using the xen pvclock source patch in the pv-in-pvh shim series?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 13/23 vixen: Use SCHEDOP_shutdown to shutdown the machine
In reply to Anthony LiguoriFrom: Jan H. Schönherr <[email protected]>
While the hwdom_shutdown() is able to reboot the system, it fails to properly power it off. With SCHEDOP_shutdown, we delegate the problem.
--- xen/common/domain.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
xen/common/domain.c +14 -0
@@ -42,6 +42,7 @@#include <xen/trace.h> #include <xen/tmem.h> #include <asm/setup.h> +#include <asm/guest/vixen.h> /* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */
@@ -693,6 +694,17 @@ void __domain_crash_synchronous(void) } +static void vixen_shutdown (u8 reason) +{ +struct sched_shutdown sched_shutdown = { .reason = reason }; + +if (!opt_noreboot) +HYPERVISOR_sched_op (SCHEDOP_shutdown, &sched_shutdown); + +/* Fallback, in case the hypercall fails */ +hwdom_shutdown (reason); +} +void domain_shutdown (struct domain *d,u8 reason) {struct vcpu *v;
@@ -703,6 +715,8 @@ void domain_shutdown(struct domain *d, u8 reason) d->shutdown_code = reason; reason = d->shutdown_code; +if (is_vixen () ) +vixen_shutdown (reason);if (is_hardware_domain (d) )hwdom_shutdown (reason);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/23] vixen: Use SCHEDOP_shutdown to shutdown the machine
Quoted 23 lines · Anthony Liguori
From: Jan H. Schönherr <[email protected]>
While the
hwdom_shutdown()is able to reboot the system, it fails to properly power it off. WithSCHEDOP_shutdown, we delegate the problem.Signed-off-by Jan H. Schönherr <[email protected]>--- xen/common/domain.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)xen/common/domain.c +1
-0@@ -42,6 +42,7 @@#include <xen/trace.h> #include <xen/tmem.h> #include <asm/setup.h> +#include <asm/guest/vixen.h> /* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */
xen/common/domain.c void __domain_crash_synchronous(void) · line 701
Quoted 8 lines
xen/common/domain.c +5
-0@@ -693,6 +694,17 @@ void __domain_crash_synchronous(void) } +static void vixen_shutdown (u8 reason) +{ +struct sched_shutdown sched_shutdown = { .reason = reason }; + +if (!opt_noreboot)
Forgot the spaces around it..
(Not that this matters that much).
Quoted 26 lines
xen/common/domain.c +8
-0+HYPERVISOR_sched_op (SCHEDOP_shutdown, &sched_shutdown); + +/* Fallback, in case the hypercall fails */ +hwdom_shutdown (reason); +} +void domain_shutdown (struct domain *d,u8 reason) {struct vcpu *v;@@ -703,6 +715,8 @@ void domain_shutdown(struct domain *d, u8 reason) d->shutdown_code = reason; reason = d->shutdown_code; +if (is_vixen () ) +vixen_shutdown (reason);if (is_hardware_domain (d) )hwdom_shutdown (reason);Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/23] vixen: Use SCHEDOP_shutdown to shutdown the machine
Quoted 27 lines · Konrad Rzeszutek Wilk
Quoted 26 lines · Anthony Liguori
From: Jan H. Schönherr <[email protected]>
While the
hwdom_shutdown()is able to reboot the system, it fails to properly power it off. WithSCHEDOP_shutdown, we delegate the problem.Signed-off-by Jan H. Schönherr <[email protected]>--- xen/common/domain.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)xen/common/domain.c +1
-0@@ -42,6 +42,7 @@#include <xen/trace.h> #include <xen/tmem.h> #include <asm/setup.h> +#include <asm/guest/vixen.h> /* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */ @@ -693,6 +694,17 @@ void __domain_crash_synchronous(void) }
Quoted 8 lines
xen/common/domain.c void __domain_crash_synchronous(void) · line 701
Quoted 5 lines
xen/common/domain.c +5
-0+static void vixen_shutdown (u8 reason) +{ +struct sched_shutdown sched_shutdown = { .reason = reason }; + +if (!opt_noreboot)Forgot the spaces around it..
(Not that this matters that much).
Blarg, I will take a pass through all of the patches and scrub them.
Regards,
Anthony Liguori
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 14/23 vixen: forward VCPUOP_register_runstate_memory_area to outer Xen
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
This allows for proper accounting of steal time within the guest.
--- xen/common/domain.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/common/domain.c +6 -0
@@ -1414,6 +1414,12 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)if ( !guest_handle_okay (area.addr.h,1 ) )break ; +if (is_vixen () ) { + rc =HYPERVISOR_vcpu_op (VCPUOP_register_runstate_memory_area, + vcpuid, &area); +break ; + } + rc =0 ;runstate_guest (v) = area.addr.h;
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 15/23 vixen: pass through version hypercalls to parent Xen
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
This is necessary to trigger event channel upcalls but it is also useful to passthrough the full version information such that the guest believes it is running on the parent Xen.
---
v1 -> v2
- don't pass through version by default
- introduce vixen_ptver parameter to enable version passthrough.
--- xen/arch/x86/guest/vixen.c | 7 +++ xen/common/kernel.c | 89 +++++++++++++++++++++++++++++++++------ xen/include/asm-arm/guest/vixen.h | 5 +++ xen/include/asm-x86/guest/vixen.h | 2 + 4 files changed, 91 insertions(+), 12 deletions(-)
xen/arch/x86/guest/vixen.c +7 -0
@@ -31,8 +31,10 @@ static int in_vixen;static int vixen_domid =1 ;static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;static shared_info_t *global_si; +static bool vixen_ptver;integer_param ("vixen_domid" , vixen_domid); +boolean_param ("vixen_ptver" , vixen_ptver);void __init init_vixen (void ) {
@@ -142,3 +144,8 @@ u64 vixen_get_cpu_freq(void)return imm >> time.tsc_shift; } } + +bool vixen_passthru_version (void ) +{ +return is_vixen () && vixen_ptver; +}
xen/common/kernel.c +77 -12
133 lines not on this page · raw message
xen/include/asm-arm/guest/vixen.h +5 -0
@@ -83,4 +83,9 @@ static inline int vixen_get_domid(void) return 0; } +static bool vixen_passthru_version (void ) +{ +return false; +} +#endif
xen/include/asm-x86/guest/vixen.h +2 -0
@@ -80,4 +80,6 @@ void __init early_vixen_init(void);u64 vixen_get_cpu_freq (void ); +bool vixen_passthru_version (void ); +#endif
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 15/23] vixen: pass through version hypercalls to parent Xen
Quoted 24 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
This is necessary to trigger event channel upcalls but it is also useful to passthrough the full version information such that the guest believes it is running on the parent Xen.
Signed-off-by Matt Wilson <[email protected]>Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- don't pass through version by default
- introducevixen_ptverparameter to enable version passthrough.--- xen/arch/x86/guest/vixen.c | 7 +++ xen/common/kernel.c | 89 +++++++++++++++++++++++++++++++++------ xen/include/asm-arm/guest/vixen.h | 5 +++ xen/include/asm-x86/guest/vixen.h | 2 + 4 files changed, 91 insertions(+), 12 deletions(-)xen/arch/x86/guest/vixen.c +0
-0
xen/arch/x86/guest/vixen.c static int in_vixen; · line 37
Quoted 7 lines
xen/arch/x86/guest/vixen.c +2
-0@@ -31,8 +31,10 @@ static int in_vixen;static int vixen_domid =1 ;static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;static shared_info_t *global_si; +static bool vixen_ptver;integer_param ("vixen_domid" , vixen_domid); +boolean_param ("vixen_ptver" , vixen_ptver);
Would it make sense to have a custom parameter function that would be called 'vixen' and have all of those in it?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 15/23] vixen: pass through version hypercalls to parent Xen
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
This is necessary to trigger event channel upcalls but it is also useful to passthrough the full version information such that the guest believes it is running on the parent Xen.
Signed-off-by Matt Wilson <[email protected]>Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- don't pass through version by default
- introducevixen_ptverparameter to enable version passthrough.--- xen/arch/x86/guest/vixen.c | 7 +++ xen/common/kernel.c | 89 +++++++++++++++++++++++++++++++++------ xen/include/asm-arm/guest/vixen.h | 5 +++ xen/include/asm-x86/guest/vixen.h | 2 + 4 files changed, 91 insertions(+), 12 deletions(-)xen/arch/x86/guest/vixen.c +1
-0@@ -31,8 +31,10 @@ static int in_vixen;static int vixen_domid =1 ;static uint32_t vixen_reserved_mem_pgstart =0xfeff0000 ;static shared_info_t *global_si; +static bool vixen_ptver;
Quoted 5 lines
xen/arch/x86/guest/vixen.c static int in_vixen; · line 37
Quoted 2 lines
xen/arch/x86/guest/vixen.c +1
-0integer_param ("vixen_domid" , vixen_domid); +boolean_param ("vixen_ptver" , vixen_ptver);Would it make sense to have a custom parameter function that would be called 'vixen' and have all of those in it?
Can you give an example? I'm not sure what you mean.
Regards,
Anthony Liguori
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 15/23] vixen: pass through version hypercalls to parent Xen
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
integer_param("vixen_domid", vixen_domid);
+boolean_param("vixen_ptver",vixen_ptver);Would it make sense to have a custom parameter function that would be called 'vixen' and have all of those in it?
Can you give an example? I'm not sure what you mean.
Andrew's bti= handling for example.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 16/23 vixen: pass grant table operations through to the outer Xen
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
The grant table is a region of guest memory that contains GMFNs which in PV are MFNs but are PFNs in HVM. Since a Vixen guest MFN is an HVM PFN, we can pass this table directly through to the outer Xen which cuts down considerably on overhead.
We do not forward most of the hypercalls since we only intend on Vixen to be used for normal guests, not driver domains.
---
v1 -> v2
- move to using reserved memory space for grant table instead of heap
- use a dispatch function instead of modifying all calls
--- xen/arch/x86/guest/vixen.c | 4 ++ xen/common/grant_table.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+)
xen/arch/x86/guest/vixen.c +4 -0
@@ -22,10 +22,14 @@#include <asm/guest/vixen.h> #include <public/version.h> #include <public/hvm/hvm_info_table.h> +#include <xen/grant_table.h> + +#define PCI_DEVICE_ID_XENSOURCE_PLATFORM 0x0001#define X86_HVM_END_SPECIAL_REGION 0xff000u#define SHARED_INFO_PFN (X86_HVM_END_SPECIAL_REGION + 0) +#define GRANT_TABLE_PFN_0 (X86_HVM_END_SPECIAL_REGION + 1)static int in_vixen;static int vixen_domid =1 ;
xen/common/grant_table.c +101 -0
131 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 16/23] vixen: pass grant table operations through to the outer Xen
Quoted 20 lines · Anthony Liguori
static long
xen/common/grant_table.c +19
-0+vixen_gnttab_setup_table ( + XEN_GUEST_HANDLE_PARAM(gnttab_setup_table_t) uop, unsigned int count) +{ + long rc; + +struct gnttab_setup_table op; +xen_pfn_t *frame_list =NULL ; +XEN_GUEST_HANDLE (xen_pfn_t) old_frame_list; + +if ( count !=1 ) +return -EINVAL ; + +if (unlikely (copy_from_guest (&op, uop,1 ) !=0 ) ) + { +gdprintk (XENLOG_INFO ,"Fault while reading gnttab_setup_table_t.\n" ); +return -EFAULT ; + } + +if ( op.nr_frames >0 ) {
xen/common/grant_table.c grant_table_init(struct domain *d, struct grant_table *gt, · line 1833
Quoted 10 lines
xen/common/grant_table.c +10
-0+ frame_list =xzalloc_array (xen_pfn_t, op.nr_frames); +if ( frame_list ==NULL ) +return -ENOMEM ; + } + + old_frame_list = op.frame_list; + op.frame_list.p = frame_list; + + rc =HYPERVISOR_grant_table_op (GNTTABOP_setup_table, &op, count); + op.frame_list = old_frame_list;
Are you sure this works? HVM based guests need to use XENMAPSPACE_grant_table so that they map the grant table somewhere in the p2m.
My comment was the other way around: you can ditch the GNTTABOP_setup_table call, but you need to keep the XENMAPSPACE_grant_table one.
xen/common/grant_table.c do_grant_table_op( · line 3426
Quoted 9 lines
long
do_grant_table_op(
unsigned int cmd,XEN_GUEST_HANDLE_PARAM(void)uop, unsigned int count)xen/common/grant_table.c +2
-0@@ -3324,6 +3422,9 @@ do_grant_table_op(if ( (cmd &=GNTTABOP_CMD_MASK ) != GNTTABOP_cache_flush && opaque_in )return -EINVAL ; +if (is_vixen () ) +return vixen_do_grant_table_op (cmd, uop, count);
You seem to be missing the compat code.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 17/23 vixen: setup infrastructure to receive event channel notifications
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
This patch registers an interrupt handler using either an INTx interrupt from the platform PCI device, CALLBACK_IRQ vector delivery, or evtchn_upcall_vector depending on what the parent hypervisor supports.
The event channel polling code comes from Linux but uses the internal infrastructure for delivery.
Finally, this infrastructure has to be initialized per-VCPU so hook the appropriate place for that.
---
v1 -> v2
- coding style
- introduce #defines for the PCI vendor and device id
- initialize grant table memory space
--- xen/arch/x86/domain.c | 3 + xen/arch/x86/guest/vixen.c | 302 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 3 + xen/include/asm-x86/guest/vixen.h | 6 + xen/include/xen/pci_ids.h | 2 + 5 files changed, 316 insertions(+)
xen/arch/x86/domain.c +3 -0
@@ -1147,6 +1147,9 @@ int arch_set_info_guest(update_cr3 (v); +if (is_vixen () ) +vixen_vcpu_initialize (v); + out:if ( flags & VGCF_online )clear_bit (_VPF_down, &v->pause_flags);
xen/arch/x86/guest/vixen.c +302 -0
317 lines not on this page · raw message
xen/arch/x86/setup.c +3 -0
@@ -1603,6 +1603,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) dom0->is_privileged =1 ; dom0->target =NULL ; +if (is_vixen () ) +vixen_transform (dom0); +/* Grab the DOM0 command line. */ cmdline = (char *)(mod[0 ].string ?__va (mod[0 ].string) :NULL );if ( (cmdline !=NULL ) || (kextra !=NULL ) )
xen/include/asm-x86/guest/vixen.h +6 -0
@@ -82,4 +82,10 @@ u64 vixen_get_cpu_freq(void);bool vixen_passthru_version (void ); +bool vixen_has_per_cpu_notifications (void ); + +void vixen_vcpu_initialize (struct vcpu *v); + +void __init vixen_transform (struct domain *dom0); +#endif
xen/include/xen/pci_ids.h +2 -0
@@ -9,3 +9,5 @@#define PCI_VENDOR_ID_BROADCOM 0x14e4#define PCI_VENDOR_ID_INTEL 0x8086 + +#define PCI_VENDOR_ID_XENSOURCE 0x5853
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 18/23 vixen: Introduce ECS_PROXY for event channel proxying
In reply to Anthony LiguoriFrom: Jan H. Schönherr <[email protected]>
Previously, we would keep proxied event channels as ECS_INTERDOMAIN channel around. This works for most things, but has the problem that EVTCHNOP_status is broken, and that EVTCHNOP_close does not mark an event channel as free.
Introduce a separate ECS_PROXY to denote event channels that are forwarded to the hypervisor we're running under.
This makes the code more readable in many places.
--- xen/common/event_channel.c | 87 ++++++++++++++++++++++++++++++++++++++++------ xen/include/xen/event.h | 3 ++ xen/include/xen/sched.h | 1 + 3 files changed, 81 insertions(+), 10 deletions(-)
xen/common/event_channel.c +77 -10
@@ -30,6 +30,7 @@#include <public/xen.h> #include <public/event_channel.h> #include <xsm/xsm.h> +#include <asm/guest/vixen.h> #define ERROR_EXIT (_errno) \ do { \
@@ -156,25 +157,25 @@ static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket)xfree (bucket); } -static int get_free_port (struct domain *d) +static int allocate_port (struct domain *d,int port) {struct evtchn *chn;struct evtchn **grp; -int port;if ( d->is_dying )return -EINVAL ; -for ( port =0 ;port_is_valid (d, port); port++ ) +if (port_is_valid (d, port) ) {if ( port > d->max_evtchn_port )return -ENOSPC ;if (evtchn_from_port (d, port)->state ==ECS_FREE && !evtchn_port_is_busy (d, port) )return port; +return -EINVAL ; } -if ( port == d->max_evtchns || port > d->max_evtchn_port ) +if ( port >= d->max_evtchns || port > d->max_evtchn_port )return -ENOSPC ;if ( !group_from_port (d, port) )
@@ -185,16 +186,59 @@ static int get_free_port(struct domain *d)group_from_port (d, port) = grp; } - chn =alloc_evtchn_bucket (d, port); -if ( !chn ) -return -ENOMEM ; -bucket_from_port (d, port) = chn; +while ( d->valid_evtchns <= port ) + { + chn =alloc_evtchn_bucket (d, d->valid_evtchns); +if ( !chn ) +return -ENOMEM ; +bucket_from_port (d, d->valid_evtchns) = chn; -write_atomic (&d->valid_evtchns, d->valid_evtchns +EVTCHNS_PER_BUCKET ); +write_atomic (&d->valid_evtchns, d->valid_evtchns +EVTCHNS_PER_BUCKET ); + }return port; } +static int get_free_port (struct domain *d) +{ +int port; + +for ( port =0 ;port_is_valid (d, port); port++ ) + { +if ( port > d->max_evtchn_port ) +return -ENOSPC ; +if (evtchn_from_port (d, port)->state ==ECS_FREE + && !evtchn_port_is_busy (d, port) ) +break ; + } + +return allocate_port (d, port); +} + +int evtchn_alloc_proxy (struct domain *d,int port,u8 ecs) +{ +struct evtchn *chn; +int rc; + +if ( !is_vixen () ) +return -ENOSYS ; + + rc =allocate_port (d, port); +if ( rc <0 ) +return rc; + + chn =evtchn_from_port (d, port); +spin_lock (&chn->lock); + chn->state =ECS_PROXY ; +evtchn_port_init (d, chn); + +if ( ecs ==ECS_INTERDOMAIN ) +evtchn_port_set_pending (d, chn->notify_vcpu_id, chn); +spin_unlock (&chn->lock); + +return 0 ; +} +static void free_evtchn (struct domain *d,struct evtchn *chn) {/* Clear pending event to avoid unexpected behavior on re-bind. */
@@ -628,6 +672,9 @@ static long evtchn_close(struct domain *d1, int port1, bool_t guest) goto out; +case ECS_PROXY : +break ; +default :BUG (); }
@@ -690,6 +737,14 @@ int evtchn_send(struct domain *ld, unsigned int lport)case ECS_UNBOUND :/* silently drop the notification */ break ; +case ECS_PROXY : + ret = -EINVAL ; +if (is_vixen () ) + { +struct evtchn_send send = { .port = lport }; + ret =HYPERVISOR_event_channel_op (EVTCHNOP_send, &send); + } +break ;default : ret = -EINVAL ; }
@@ -892,6 +947,10 @@ static long evtchn_status(evtchn_status_t *status)case ECS_IPI : status->status = EVTCHNSTAT_ipi;break ; +case ECS_PROXY : +BUG_ON (!is_vixen ()); + rc =HYPERVISOR_event_channel_op (EVTCHNOP_status, status); +break ;default :BUG (); }
@@ -944,6 +1003,14 @@ long evtchn_bind_vcpu(unsigned int port, unsigned int vcpu_id)case ECS_INTERDOMAIN : chn->notify_vcpu_id = vcpu_id;break ; +case ECS_PROXY : +if (is_vixen () &&vixen_has_per_cpu_notifications () ) + { +struct evtchn_bind_vcpu bind = { .port = port, .vcpu = vcpu_id }; +HYPERVISOR_event_channel_op (EVTCHNOP_bind_vcpu, &bind); + } + chn->notify_vcpu_id = vcpu_id; +break ;case ECS_PIRQ :if ( chn->notify_vcpu_id == vcpu_id )break ;
@@ -1276,7 +1343,7 @@ int evtchn_init(struct domain *d) d->valid_evtchns =EVTCHNS_PER_BUCKET ;spin_lock_init_prof (d, event_lock); -if (get_free_port (d) !=0 ) +if (allocate_port (d,0 ) !=0 ) {free_evtchn_bucket (d, d->evtchn);return -EINVAL ;
xen/include/xen/event.h +3 -0
@@ -71,6 +71,9 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);/* Inject an event channel notification into the guest */ void arch_evtchn_inject (struct vcpu *v); +/* Allocate a specific event channel as proxy. */ +int evtchn_alloc_proxy (struct domain *d,int port,u8 ecs); +/* * Internal event channel object storage. *
xen/include/xen/sched.h +1 -0
@@ -93,6 +93,7 @@ struct evtchn#define ECS_PIRQ 4/* Channel is bound to a physical IRQ line. */ #define ECS_VIRQ 5/* Channel is bound to a virtual IRQ line. */ #define ECS_IPI 6/* Channel is bound to a virtual IPI line. */ +#define ECS_PROXY 7/* Channel is proxied to parent hypervisor. */ u8 state;/* ECS_* */ u8 xen_consumer:XEN_CONSUMER_BITS; /* Consumer in Xen if nonzero */ u8 pending:1;
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 19/23 vixen: Fix Vixen adaptation of send_global_virq()
In reply to Anthony LiguoriFrom: Jan H. Schönherr <[email protected]>
The function originally did the following unconditionally:
send_guest_global_virq(global_virq_handlers[virq] ?: hardware_domain, virq);
The new variant should reflect the non-Vixen case correctly.
--- xen/common/event_channel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
xen/common/event_channel.c +4 -1
@@ -840,7 +840,10 @@ void send_global_virq(uint32_t virq)ASSERT (virq <NR_VIRQS );ASSERT (virq_is_global (virq)); -send_guest_global_virq (global_virq_handlers[virq] ?: hardware_domain, virq); +if ( global_virq_handlers[virq] ) +send_guest_global_virq (global_virq_handlers[virq], virq); +else if ( !is_vixen () ) +send_guest_global_virq (hardware_domain, virq); }int set_global_virq_handler (struct domain *d,uint32_t virq)
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 20/23 vixen: event channel passthrough support
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
For Vixen, we do not want to pass through all event channel operations as HVM guests do not have nearly as many event channel interactions as PV and on older versions of Xen, there is no reliable way to wake up an event channel on VCPU != 0 leading to a variety of deadlocks.
By only forwarding interdomain and unbound event channel operations, we can avoid this problem since these can always be bound to VCPU 0 on older versions of Xen HVM. On newer versions of Xen, we allow the event channels to be bound to the VCPU requested by the inner guest.
To ensure that we keep everything in sync, all event channels end up allocating an unbound event channel in the parent Xen and we rely on the parent Xen to owner the event channel address space.
--- xen/common/event_channel.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
xen/common/event_channel.c +81 -0
@@ -199,10 +199,34 @@ static int allocate_port(struct domain *d, int port)return port; } +static int vixen_get_free_port (struct domain *d) +{ +int rc; +struct evtchn_alloc_unbound unbound = { .dom =DOMID_SELF , + .remote_dom =DOMID_SELF }; + + rc =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, &unbound); +if ( rc ) +return rc; + + rc =allocate_port (d, unbound.port); +if ( rc <0 ) + { +struct evtchn_close close = { .port = unbound.port }; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +printk ("Vixen: failed to allocate event channel %d => %d\n" , + unbound.port, rc); + } +return rc; +} +static int get_free_port (struct domain *d) {int port; +if (is_vixen () ) +return vixen_get_free_port (d); +for ( port =0 ;port_is_valid (d, port); port++ ) {if ( port > d->max_evtchn_port )
@@ -252,6 +276,11 @@ static void free_evtchn(struct domain *d, struct evtchn *chn)xsm_evtchn_close_post (chn); } +static bool is_loopback (domid_t ldom,domid_t rdom) +{ +return ldom ==DOMID_SELF && rdom ==DOMID_SELF ; +} +static long evtchn_alloc_unbound (evtchn_alloc_unbound_t *alloc) {struct evtchn *chn;
@@ -266,6 +295,23 @@ static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)spin_lock (&d->event_lock); +if (is_vixen () && !is_loopback (alloc->dom, alloc->remote_dom) ) { + rc =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, alloc); +if ( rc ) + goto out; + + rc =evtchn_alloc_proxy (d, alloc->port,ECS_UNBOUND ); +if ( rc ) + { +struct evtchn_close close = { .port = alloc->port }; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +printk ("Vixen: failed to reserve unbound event channel %d => %ld\n" , + alloc->port, rc); + } + + goto out; + } +if ( (port =get_free_port (d)) <0 )ERROR_EXIT_DOM (port, d); chn =evtchn_from_port (d, port);
@@ -315,6 +361,27 @@ static void double_evtchn_unlock(struct evtchn *lchn, struct evtchn *rchn)spin_unlock (&rchn->lock); } +static long vixen_evtchn_bind_interdomain (evtchn_bind_interdomain_t *bind) +{ +struct domain *d = current->domain; +long rc; + + rc =HYPERVISOR_event_channel_op (EVTCHNOP_bind_interdomain, bind); +if ( rc ) +return rc; + + rc =evtchn_alloc_proxy (d, bind->local_port,ECS_INTERDOMAIN ); +if ( rc ) + { +struct evtchn_close close = { .port = bind->local_port }; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +printk ("Vixen: failed to reserve inter-domain event channel %d => %ld\n" , + bind->local_port, rc); + } + +return rc; +} +static long evtchn_bind_interdomain (evtchn_bind_interdomain_t *bind) {struct evtchn *lchn, *rchn;
@@ -323,6 +390,9 @@ static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)domid_t rdom = bind->remote_dom;long rc; +if (is_vixen () && !is_loopback (DOMID_SELF , bind->remote_dom) ) +return vixen_evtchn_bind_interdomain (bind); +if ( rdom ==DOMID_SELF ) rdom = current->domain->domain_id;
@@ -581,6 +651,13 @@ static long evtchn_close(struct domain *d1, int port1, bool_t guest) goto out; } +if (is_vixen () ) { +struct evtchn_close close = { .port = port1 }; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +if (rc !=0 ) + goto out; + } +switch ( chn1->state ) {case ECS_FREE :
@@ -1215,6 +1292,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case EVTCHNOP_init_control: {struct evtchn_init_control init_control; + +if (is_vixen () ) +return -ENOSYS ; +if (copy_from_guest (&init_control, arg,1 ) !=0 )return -EFAULT ; rc =evtchn_fifo_init_control (&init_control);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 21/23 vixen: provide Xencons implementation
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
Our initial approach exposed the console ring directly to guests which worked well except for the fact that very old versions of Xen did not support console ring for HVM guests. It also proved to be complicated from a management tool perspective since both the serial console and the paravirt console for HVM guests produced output.
Having a simple xencons implementation helps simplify using Vixen as a management tool no longer needs to care about whether or not this mode is enabled.
In order to output to the console without the '(Xen)' adornment, we introduce a new entry point into the console code too.
--- xen/arch/x86/guest/vixen.c | 41 +++++++++++++++++++++++++++++++++++++++ xen/common/event_channel.c | 5 ++++- xen/drivers/char/console.c | 16 +++++++++++++++ xen/include/asm-x86/guest/vixen.h | 2 ++ xen/include/xen/lib.h | 1 + 5 files changed, 64 insertions(+), 1 deletion(-)
xen/arch/x86/guest/vixen.c +41 -0
@@ -26,6 +26,7 @@#include <xen/event.h> #include <asm/apic.h> #include <xen/pci_ids.h> +#include <public/io/console.h> #define PCI_DEVICE_ID_XENSOURCE_PLATFORM 0x0001
@@ -43,6 +44,9 @@ static bool vixen_per_cpu_notifications = true;static uint8_t vixen_evtchn_vector;static bool vixen_needs_apic_ack = true;struct irqaction vixen_irqaction; +static volatile struct xencons_interface *vixen_xencons_iface; +static uint16_t vixen_xencons_port; +static spinlock_t vixen_xencons_lock;integer_param ("vixen_domid" , vixen_domid);boolean_param ("vixen_ptver" , vixen_ptver);
@@ -89,6 +93,8 @@ void __init init_vixen(void) } } +spin_lock_init (&vixen_xencons_lock); + in_vixen =1 ; }
@@ -304,6 +310,41 @@ static void vixen_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)vixen_upcall (smp_processor_id ()); } +bool vixen_ring_process (uint16_t port) +{ +volatile struct xencons_interface *r = vixen_xencons_iface; +char buffer[128 ]; +size_t n; + +if (r ==NULL || port != vixen_xencons_port) { +return false; + } + +spin_lock (&vixen_xencons_lock); + + n =0 ; +while (r->out_prod != r->out_cons) { +char ch = r->out[MASK_XENCONS_IDX (r->out_cons, r->out)]; +if (n ==sizeof (buffer) -1 ) { + buffer[n] =0 ; +guest_puts (hardware_domain, buffer); + n =0 ; + } + buffer[n++] = ch; +rmb (); + r->out_cons++; + } + +if (n) { + buffer[n] =0 ; +guest_puts (hardware_domain, buffer); + } + +spin_unlock (&vixen_xencons_lock); + +return true; +} +static int hvm_set_parameter (int idx,uint64_t value) {struct xen_hvm_param xhv;
xen/common/event_channel.c +4 -1
@@ -1241,7 +1241,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)struct evtchn_send send;if (copy_from_guest (&send, arg,1 ) !=0 )return -EFAULT ; - rc =evtchn_send (current->domain, send.port); +if (vixen_ring_process (send.port) ) + rc =0 ; +else + rc =evtchn_send (current->domain, send.port);break ; }
xen/drivers/char/console.c +16 -0
@@ -775,6 +775,22 @@ void guest_printk(const struct domain *d, const char *fmt, ...)va_end (args); } +void guest_puts (const struct domain *d,const char *kbuf) +{ +spin_lock_irq (&console_lock); + +sercon_puts (kbuf); +video_puts (kbuf); + +if ( opt_console_to_ring ) + { +conring_puts (kbuf); +tasklet_schedule (¬ify_dom0_con_ring_tasklet); + } + +spin_unlock_irq (&console_lock); +} +void __init console_init_preirq (void ) {char *p;
xen/include/asm-x86/guest/vixen.h +2 -0
@@ -88,4 +88,6 @@ void vixen_vcpu_initialize(struct vcpu *v);void __init vixen_transform (struct domain *dom0); +bool vixen_ring_process (uint16_t port); +#endif
xen/include/xen/lib.h +1 -0
@@ -92,6 +92,7 @@ extern void printk(const char *format, ...) __attribute__ ((format (printf, 1, 2)));extern void guest_printk (const struct domain *d,const char *format, ...) __attribute__ ((format (printf,2 ,3 ))); +extern void guest_puts (const struct domain *d,const char *message);extern void noreturnpanic (const char *format, ...) __attribute__ ((format (printf,1 ,2 ))); extern long vm_assist(struct domain *, unsigned int cmd, unsigned int type,
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 22/23 vixen: dom0 builder support
In reply to Anthony LiguoriFrom: Anthony Liguori <[email protected]>
The dom0 builder requires a number of modifications in order to be able to launch unprivileged guests. The console and store pages must be mapped in a specific location within the guest's initial page table.
We also have to setup the start info to be what's expected for unprivileged guests and supress the normal logic to give dom0 increased permissions.
We have to pass around the console and store pages which involves touching a number of places including the PVH builder.
---
v1 -> v2
- panic in the event of errors
--- xen/arch/x86/dom0_build.c | 7 +++- xen/arch/x86/guest/vixen.c | 64 +++++++++++++++++++++++++++++++- xen/arch/x86/hvm/dom0_build.c | 4 +- xen/arch/x86/pv/dom0_build.c | 77 ++++++++++++++++++++++++++++++++++----- xen/arch/x86/setup.c | 12 +++++- xen/include/asm-x86/dom0_build.h | 8 +++- xen/include/asm-x86/guest/vixen.h | 5 ++- xen/include/asm-x86/setup.h | 4 +- 8 files changed, 161 insertions(+), 20 deletions(-)
xen/arch/x86/dom0_build.c +5 -2
@@ -464,7 +464,9 @@ int __init dom0_setup_permissions(struct domain *d)int __init construct_dom0 (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd,void *(*bootstrap_map)(const module_t *), -char *cmdline) +char *cmdline, +xen_pfn_t store_mfn,uint32_t store_evtchn, +xen_pfn_t console_mfn,uint32_t console_evtchn) {int rc;
@@ -484,7 +486,8 @@ int __init construct_dom0(struct domain *d, const module_t *image,#endif rc = (is_hvm_domain (d) ? dom0_construct_pvh : dom0_construct_pv) - (d, image, image_headroom, initrd, bootstrap_map, cmdline); + (d, image, image_headroom, initrd, bootstrap_map, cmdline, + store_mfn, store_evtchn, console_mfn, console_evtchn);if ( rc )return rc;
xen/arch/x86/guest/vixen.c +63 -1
79 lines not on this page · raw message
xen/arch/x86/hvm/dom0_build.c +3 -1
@@ -1064,7 +1064,9 @@ int __init dom0_construct_pvh(struct domain *d, const module_t *image,unsigned long image_headroom, module_t *initrd, void *(*bootstrap_map)(const module_t *), - char *cmdline) + char *cmdline, + xen_pfn_t store_mfn, uint32_t store_evtchn, + xen_pfn_t console_mfn, uint32_t console_evtchn) { paddr_t entry, start_info;int rc;
xen/arch/x86/pv/dom0_build.c +67 -10
143 lines not on this page · raw message
xen/arch/x86/setup.c +10 -2
@@ -663,6 +663,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) .stop_bits = 1 };struct xen_arch_domainconfig config = { .emulation_flags =0 }; +xen_pfn_t store_mfn =0 , console_mfn =0 ; +uint32_t store_evtchn =0 , console_evtchn =0 ;/* Critical region without IDT or TSS. Any fault is deadly! */
@@ -1595,6 +1597,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) config.emulation_flags =XEN_X86_EMU_LAPIC |XEN_X86_EMU_IOAPIC ; } +if (is_vixen () ) + config.emulation_flags =XEN_X86_EMU_PIT ; +/* Create initial domain 0. */ dom0 =domain_create (dom0_domid, domcr_flags,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )
@@ -1604,7 +1609,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) dom0->target =NULL ;if (is_vixen () ) -vixen_transform (dom0); +vixen_transform (dom0, &store_mfn, &store_evtchn, + &console_mfn, &console_evtchn);/* Grab the DOM0 command line. */ cmdline = (char *)(mod[0 ].string ?__va (mod[0 ].string) :NULL );
@@ -1667,7 +1673,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if (construct_dom0 (dom0, mod, modules_headroom, (initrdidx >0 ) && (initrdidx < mbi->mods_count) ? mod + initrdidx :NULL , - bootstrap_map, cmdline) !=0 ) + bootstrap_map, cmdline, + store_mfn, store_evtchn, + console_mfn, console_evtchn) !=0 )panic ("Could not set up DOM0 guest OS" );if ( cpu_has_smap )
xen/include/asm-x86/dom0_build.h +6 -2
@@ -18,13 +18,17 @@ int dom0_construct_pv(struct domain *d, const module_t *image,unsigned long image_headroom, module_t *initrd, void *(*bootstrap_map)(const module_t *), - char *cmdline); + char *cmdline, + xen_pfn_t store_mfn, uint32_t store_evtchn, + xen_pfn_t console_mfn, uint32_t console_evtchn);int dom0_construct_pvh (struct domain *d,const module_t *image,unsigned long image_headroom,module_t *initrd,void *(*bootstrap_map)(const module_t *), -char *cmdline); +char *cmdline, +xen_pfn_t store_mfn,uint32_t store_evtchn, +xen_pfn_t console_mfn,uint32_t console_evtchn);unsigned long dom0_paging_pages (const struct domain *d,unsigned long nr_pages);
xen/include/asm-x86/guest/vixen.h +4 -1
@@ -86,7 +86,10 @@ bool vixen_has_per_cpu_notifications(void);void vixen_vcpu_initialize (struct vcpu *v); -void __init vixen_transform (struct domain *dom0); +void __init +vixen_transform (struct domain *dom0, +xen_pfn_t *pstore_mfn,uint32_t *pstore_evtchn, +xen_pfn_t *pconsole_mfn,uint32_t *pconsole_evtchn);bool vixen_ring_process (uint16_t port);
xen/include/asm-x86/setup.h +3 -1
@@ -39,7 +39,9 @@ int construct_dom0( const module_t *kernel, unsigned long kernel_headroom, module_t *initrd, void *(*bootstrap_map)(const module_t *), - char *cmdline); + char *cmdline, + xen_pfn_t store_mfn, uint32_t store_evtchn, + xen_pfn_t console_mfn, uint32_t console_evtchn);void setup_io_bitmap (struct domain *d);unsigned long initial_images_nrpages (nodeid_t node);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 23/23 vixen: use default position for the m2p mappings
In reply to Anthony LiguoriFrom: Roger Pau Monne <[email protected]>
When running a 32bit kernel as Dom0 on a 64bit hypervisor the hypervisor will try to shrink the hypervisor hole to the minimum needed, and thus requires the Dom0 to use XENMEM_machphys_mapping in order to fetch the position of the start of the hypervisor virtual mappings.
Disable this feature when running as a PV shim, since some DomU kernels don't implemented XENMEM_machphys_mapping and break if the m2p doesn't begin at the default address.
NB: support for the XENMEM_machphys_mapping was added in Linux by commit 7e7750.
---
v1 -> v2
- adapted for Vixen
--- xen/arch/x86/pv/dom0_build.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/pv/dom0_build.c +2 -1
@@ -398,7 +398,8 @@ int __init dom0_construct_pv(struct domain *d,if ( parms.pae ==XEN_PAE_EXTCR3 )set_bit (VMASST_TYPE_pae_extended_cr3, &d->vm_assist); -if ( (parms.virt_hv_start_low !=UNSET_ADDR ) &&elf_32bit (&elf) ) +if ( !is_vixen () && (parms.virt_hv_start_low !=UNSET_ADDR ) && +elf_32bit (&elf) ) {unsigned long mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ; value = (parms.virt_hv_start_low + mask) & ~mask;
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
CVE-2017-5754 is problematic for paravirtualized x86 domUs because it appears to be very difficult to isolate the hypervisor's page tables from PV domUs while maintaining ABI compatibility. Instead of trying to make a KPTI-like approach work for Xen PV, it seems reasonable to run a copy of Xen within an HVM (or PVH) domU to provide backwards compatibility with guests as mentioned in XSA-254 [1].
This patch series adds a new mode to Xen called Vixen (Virtualized Xen) which provides a PV-compatible interface while gaining CVE-2017-5754 protection for the host provided by hardware virtualization. Vixen supports running a single unprivileged PV domain (a dom1) that is constructed by the dom0 domain builder.
Please note the Xen page table configuration fundamental to the current PV ABI makes it impossible for an operating system to mitigate CVE-2017-5754 through mechanisms like Kernel Page Table Isolation (KPTI). In order for an operating system to mitigate CVE-2017-5754 it must run directly in a HVM or PVH domU.
This series is very similar to the PVH series posted by Wei and we have been discussing how to merge efforts. We were hoping to have more time to work this out. I am posting this because I'm fairly confident that this series is complete (all PV instances in EC2 are using this) and others might find it useful. I also wanted to have more of a discussion about the best way to merge and some of the differences in designs.
Quoted 3 lines
This series is also available at:
git clone https://github.com/aliguori/xen.git vixen-upstream-v2
You have a typo in the name of the branch. It is vixen-upstrea-v2 on github. :-)
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 30 lines · Wei Liu
Quoted 29 lines · Anthony Liguori
From: Anthony Liguori <[email protected]>
CVE-2017-5754 is problematic for paravirtualized x86 domUs because it appears to be very difficult to isolate the hypervisor's page tables from PV domUs while maintaining ABI compatibility. Instead of trying to make a KPTI-like approach work for Xen PV, it seems reasonable to run a copy of Xen within an HVM (or PVH) domU to provide backwards compatibility with guests as mentioned in XSA-254 [1].
This patch series adds a new mode to Xen called Vixen (Virtualized Xen) which provides a PV-compatible interface while gaining CVE-2017-5754 protection for the host provided by hardware virtualization. Vixen supports running a single unprivileged PV domain (a dom1) that is constructed by the dom0 domain builder.
Please note the Xen page table configuration fundamental to the current PV ABI makes it impossible for an operating system to mitigate CVE-2017-5754 through mechanisms like Kernel Page Table Isolation (KPTI). In order for an operating system to mitigate CVE-2017-5754 it must run directly in a HVM or PVH domU.
This series is very similar to the PVH series posted by Wei and we have been discussing how to merge efforts. We were hoping to have more time to work this out. I am posting this because I'm fairly confident that this series is complete (all PV instances in EC2 are using this) and others might find it useful. I also wanted to have more of a discussion about the best way to merge and some of the differences in designs.
Quoted 6 lines
Quoted 3 lines
This series is also available at:
git clone https://github.com/aliguori/xen.git vixen-upstream-v2
You have a typo in the name of the branch. It is vixen-upstrea-v2 on github. :-)
Fixed :-D
Regards,
Anthony Liguori
Quoted 6 lines
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel