Re: [PATCH v2 3/3] x86: avoid building COMPAT code when !HVM && !PV32

2021-04-08 Thread Jan Beulich
On 06.04.2021 16:02, Jan Beulich wrote:
> --- a/xen/include/xen/compat.h
> +++ b/xen/include/xen/compat.h
> @@ -5,10 +5,11 @@
>  #ifndef __XEN_COMPAT_H__
>  #define __XEN_COMPAT_H__
>  
> -#ifdef CONFIG_COMPAT
> -
>  #include 
>  #include 
> +
> +#ifdef CONFIG_COMPAT
> +
>  #include 
>  
>  #define __DEFINE_COMPAT_HANDLE(name, type) \

As I've just noticed this breaks the Arm build, for the lack of
asm/compat.h there. I'll be folding in the hunks below; an alternative
would be to require every arch to have a (perhaps empty) compat.h,
which seems less desirable to me.

Jan

--- unstable.orig/xen/arch/x86/Kconfig
+++ unstable/xen/arch/x86/Kconfig
@@ -9,6 +9,7 @@ config X86
select ARCH_SUPPORTS_INT128
select CORE_PARKING
select HAS_ALTERNATIVE
+   select HAS_COMPAT
select HAS_CPUFREQ
select HAS_EHCI
select HAS_EX_TABLE
--- unstable.orig/xen/common/Kconfig
+++ unstable/xen/common/Kconfig
@@ -25,6 +25,9 @@ config GRANT_TABLE
 config HAS_ALTERNATIVE
bool
 
+config HAS_COMPAT
+   bool
+
 config HAS_DEVICE_TREE
bool
 
--- unstable.orig/xen/include/xen/compat.h
+++ unstable/xen/include/xen/compat.h
@@ -6,7 +6,9 @@
 #define __XEN_COMPAT_H__
 
 #include 
+#ifdef CONFIG_HAS_COMPAT
 #include 
+#endif
 
 #ifdef CONFIG_COMPAT
 



Re: [PATCH v2 3/3] x86: avoid building COMPAT code when !HVM && !PV32

2021-04-06 Thread Wei Liu
On Tue, Apr 06, 2021 at 04:02:08PM +0200, Jan Beulich wrote:
> It was probably a mistake to, over time, drop various CONFIG_COMPAT
> conditionals from x86-specific code, as we now have a build
> configuration again where we'd prefer this to be unset. Arrange for
> CONFIG_COMPAT to actually be off in this case, dealing with fallout.
> 
> Signed-off-by: Jan Beulich 

Reviewed-by: Wei Liu 



[PATCH v2 3/3] x86: avoid building COMPAT code when !HVM && !PV32

2021-04-06 Thread Jan Beulich
It was probably a mistake to, over time, drop various CONFIG_COMPAT
conditionals from x86-specific code, as we now have a build
configuration again where we'd prefer this to be unset. Arrange for
CONFIG_COMPAT to actually be off in this case, dealing with fallout.

Signed-off-by: Jan Beulich 
---
v2: New.

--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -6,7 +6,6 @@ config X86
select ACPI
select ACPI_LEGACY_TABLES_LOOKUP
select ARCH_SUPPORTS_INT128
-   select COMPAT
select CORE_PARKING
select HAS_ALTERNATIVE
select HAS_CPUFREQ
@@ -57,6 +56,7 @@ config PV32
bool "Support for 32bit PV guests"
depends on PV
default y
+   select COMPAT
---help---
  The 32bit PV ABI uses Ring1, an area of the x86 architecture which
  was deprecated and mostly removed in the AMD64 spec.  As a result,
@@ -91,6 +91,7 @@ config PV_LINEAR_PT
 
 config HVM
def_bool !PV_SHIM_EXCLUSIVE
+   select COMPAT
select IOREQ_SERVER
prompt "HVM support"
---help---
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -50,7 +50,8 @@ obj-y += nmi.o
 obj-y += numa.o
 obj-y += pci.o
 obj-y += percpu.o
-obj-y += physdev.o x86_64/physdev.o
+obj-y += physdev.o
+obj-$(CONFIG_COMPAT) += x86_64/physdev.o
 obj-y += psr.o
 obj-y += setup.o
 obj-y += shutdown.o
@@ -72,7 +73,8 @@ obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
 obj-y += domctl.o
-obj-y += platform_hypercall.o x86_64/platform_hypercall.o
+obj-y += platform_hypercall.o
+obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 obj-y += sysctl.o
 endif
 
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1291,6 +1291,8 @@ static void x86_mc_mceinject(void *data)
 #error BITS_PER_LONG definition absent
 #endif
 
+# ifdef CONFIG_COMPAT
+
 # include 
 
 # define xen_mcinfo_msr  mcinfo_msr
@@ -1343,6 +1345,11 @@ CHECK_mcinfo_recovery;
 # undef xen_page_offline_action
 # undef xen_mcinfo_recovery
 
+# else
+#  define compat_handle_is_null(h) true
+#  define copy_to_compat(h, p, n)  true /* really (-EFAULT), but gcc chokes */
+# endif /* CONFIG_COMPAT */
+
 /* Machine Check Architecture Hypercall */
 long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 {
@@ -1351,11 +1358,15 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_m
 struct vcpu *v = current;
 union {
 struct xen_mc_fetch *nat;
+#ifdef CONFIG_COMPAT
 struct compat_mc_fetch *cmp;
+#endif
 } mc_fetch;
 union {
 struct xen_mc_physcpuinfo *nat;
+#ifdef CONFIG_COMPAT
 struct compat_mc_physcpuinfo *cmp;
+#endif
 } mc_physcpuinfo;
 uint32_t flags, cmdflags;
 int nlcpu;
--- a/xen/arch/x86/cpu/vpmu.c
+++ b/xen/arch/x86/cpu/vpmu.c
@@ -39,10 +39,12 @@
 #include 
 #include 
 
+#ifdef CONFIG_COMPAT
 #include 
 CHECK_pmu_cntr_pair;
 CHECK_pmu_data;
 CHECK_pmu_params;
+#endif
 
 static unsigned int __read_mostly opt_vpmu_enabled;
 unsigned int __read_mostly vpmu_mode = XENPMU_MODE_OFF;
@@ -232,6 +234,7 @@ void vpmu_do_interrupt(struct cpu_user_r
 domid = sampled->domain->domain_id;
 
 /* Store appropriate registers in xenpmu_data */
+#ifdef CONFIG_COMPAT
 /* FIXME: 32-bit PVH should go here as well */
 if ( is_pv_32bit_vcpu(sampling) )
 {
@@ -254,6 +257,7 @@ void vpmu_do_interrupt(struct cpu_user_r
 *flags |= PMU_SAMPLE_USER;
 }
 else
+#endif
 {
 struct xen_pmu_regs *r = &vpmu->xenpmu_data->pmu.r.regs;
 
@@ -448,7 +452,9 @@ static int vpmu_arch_initialise(struct v
 BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ);
 BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ);
 BUILD_BUG_ON(sizeof(struct xen_pmu_regs) > XENPMU_REGS_PAD_SZ);
+#ifdef CONFIG_COMPAT
 BUILD_BUG_ON(sizeof(struct compat_pmu_regs) > XENPMU_REGS_PAD_SZ);
+#endif
 
 ASSERT(!(vpmu->flags & ~VPMU_AVAILABLE) && !vpmu->context);
 
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -64,7 +64,9 @@
 #include 
 #include 
 #include 
+#ifdef CONFIG_COMPAT
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -1020,11 +1022,13 @@ void arch_domain_creation_finished(struc
 hvm_domain_creation_finished(d);
 }
 
+#ifdef CONFIG_COMPAT
 #define xen_vcpu_guest_context vcpu_guest_context
 #define fpu_ctxt fpu_ctxt.x
 CHECK_FIELD_(struct, vcpu_guest_context, fpu_ctxt);
 #undef fpu_ctxt
 #undef xen_vcpu_guest_context
+#endif
 
 /* Called by XEN_DOMCTL_setvcpucontext and VCPUOP_initialise. */
 int arch_set_info_guest(
@@ -1045,7 +1049,11 @@ int arch_set_info_guest(
  * we expect the tools to DTRT even in compat-mode callers. */
 compat = is_pv_32bit_domain(d);
 
+#ifdef CONFIG_COMPAT
 #define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))
+#else
+#define c(fld) (c.nat->fld)
+#endif
 flags = c(flags);
 
 if ( is_pv_domain(d) )
@@ -1078,6 +1086,7 @@ int arch_set_info_guest(
 if