The file wasn't correctly named for our purposes anyway. Split it into its
"guest" and "unsafe" parts, thus allowing the latter to not be linked in
at all (for presently having no caller). The building of the "guest" part
can then (later) become conditional upon PV=y.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
xen/arch/x86/Makefile | 1 -
xen/arch/x86/lib/Makefile | 2 ++
xen/arch/x86/{usercopy.c => lib/copy-guest.c} | 12 +---------
xen/arch/x86/lib/copy-unsafe.c | 22 +++++++++++++++++++
4 files changed, 25 insertions(+), 12 deletions(-)
rename xen/arch/x86/{usercopy.c => lib/copy-guest.c} (94%)
create mode 100644 xen/arch/x86/lib/copy-unsafe.c
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 61e2293a467e..76540d77e55f 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -72,7 +72,6 @@ obj-y += time.o
obj-y += traps-setup.o
obj-y += traps.o
obj-$(CONFIG_INTEL) += tsx.o
-obj-y += usercopy.o
obj-y += x86_emulate.o
obj-$(CONFIG_TBOOT) += tboot.o
obj-y += hpet.o
diff --git a/xen/arch/x86/lib/Makefile b/xen/arch/x86/lib/Makefile
index ddf7e19bdc1d..8fe2dfd88553 100644
--- a/xen/arch/x86/lib/Makefile
+++ b/xen/arch/x86/lib/Makefile
@@ -1 +1,3 @@
+lib-y += copy-guest.o
+lib-y += copy-unsafe.o
lib-y += generic-hweightl.o
diff --git a/xen/arch/x86/usercopy.c b/xen/arch/x86/lib/copy-guest.c
similarity index 94%
rename from xen/arch/x86/usercopy.c
rename to xen/arch/x86/lib/copy-guest.c
index a24b52cc66c1..25eeb35427e2 100644
--- a/xen/arch/x86/usercopy.c
+++ b/xen/arch/x86/lib/copy-guest.c
@@ -1,4 +1,4 @@
-/*
+/*
* User address space access functions.
*
* Copyright 1997 Andi Kleen <ak@muc.de>
@@ -6,8 +6,6 @@
* Copyright 2002 Andi Kleen <ak@suse.de>
*/
-#include <xen/lib.h>
-#include <xen/sched.h>
#include <asm/uaccess.h>
#ifndef GUARD
@@ -139,14 +137,6 @@ unsigned int copy_from_guest_pv(void *to, const void __user *from,
return n;
}
-# undef GUARD
-# define GUARD UA_DROP
-# define copy_to_guest_ll copy_to_unsafe_ll
-# define copy_from_guest_ll copy_from_unsafe_ll
-# undef __user
-# define __user
-# include __FILE__
-
#endif /* GUARD(1) */
/*
diff --git a/xen/arch/x86/lib/copy-unsafe.c b/xen/arch/x86/lib/copy-unsafe.c
new file mode 100644
index 000000000000..a51500370fb1
--- /dev/null
+++ b/xen/arch/x86/lib/copy-unsafe.c
@@ -0,0 +1,22 @@
+/*
+ * "Unsafe" access functions.
+ */
+
+#include <asm/uaccess.h>
+
+#define GUARD UA_DROP
+#define copy_to_guest_ll copy_to_unsafe_ll
+#define copy_from_guest_ll copy_from_unsafe_ll
+#undef __user
+#define __user
+#include "copy-guest.c"
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.48.2
On 26/11/2025 1:24 pm, Jan Beulich wrote: > diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile > index 61e2293a467e..76540d77e55f 100644 > --- a/xen/arch/x86/Makefile > +++ b/xen/arch/x86/Makefile > @@ -72,7 +72,6 @@ obj-y += time.o > obj-y += traps-setup.o > obj-y += traps.o > obj-$(CONFIG_INTEL) += tsx.o > -obj-y += usercopy.o > obj-y += x86_emulate.o > obj-$(CONFIG_TBOOT) += tboot.o > obj-y += hpet.o There's # Allows usercopy.c to include itself $(obj)/usercopy.o: CFLAGS-y += -iquote . which looks like it wants moving too. But, given that this presumably compiles, doesn't it mean we've got a search path problem anyway? ~Andrew
On 26.11.2025 14:56, Andrew Cooper wrote: > On 26/11/2025 1:24 pm, Jan Beulich wrote: >> diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile >> index 61e2293a467e..76540d77e55f 100644 >> --- a/xen/arch/x86/Makefile >> +++ b/xen/arch/x86/Makefile >> @@ -72,7 +72,6 @@ obj-y += time.o >> obj-y += traps-setup.o >> obj-y += traps.o >> obj-$(CONFIG_INTEL) += tsx.o >> -obj-y += usercopy.o >> obj-y += x86_emulate.o >> obj-$(CONFIG_TBOOT) += tboot.o >> obj-y += hpet.o > > There's > > # Allows usercopy.c to include itself > $(obj)/usercopy.o: CFLAGS-y += -iquote . > > which looks like it wants moving too. It doesn't need moving, and I apparently sent a stale patch. This hunk is simply missing: @@ -93,9 +92,6 @@ hostprogs-y += efi/mkreloc $(obj)/efi/mkreloc: HOSTCFLAGS += -I$(srctree)/include -# Allows usercopy.c to include itself -$(obj)/usercopy.o: CFLAGS-y += -iquote . - $(obj)/x86_emulate.o: CFLAGS-y += -Os ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label > But, given that this presumably compiles, doesn't it mean we've got a > search path problem anyway? Iirc the need for the piece above was because of using __FILE__ with #include, which now we don't anymore. Or maybe it was a leftover altogether. Anyway, I don't see there being a search path problem, as #include "..." (as used now) would better always work. Jan
© 2016 - 2025 Red Hat, Inc.