Skip to contentSkip to conversation

x86: move more stuff to lib/

PATCH In review Jan Beulich 3 participants 6 messages Dec 16, 2025 – Dec 17, 2025

lore
Share & tools
lore
#0 lore raw

v3 cover x86: move more stuff to lib/

1: move / split usercopy.c to / into arch-specific library 2: move mem{cpy,set}.S to arch-specific library
3: move {clear_,copy_,scrub-}page.S to arch-specific library

Jan

#1 lore raw

PATCH v3 1/3 x86: move / split usercopy.c to / into arch-specific library

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.

---
v3: Retain xen/sched.h #include.

---
 xen/arch/x86/Makefile                         |  4 ----
 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, 26 insertions(+), 14 deletions(-)
 rename xen/arch/x86/{usercopy.c => lib/copy-guest.c} (94%)
 create mode 100644 xen/arch/x86/lib/copy-unsafe.c
xen/arch/x86/Makefile +0 -4
index 61e2293a467e..dfb258d7ac1c 100644
@@ -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
@@ -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 .
-
 ifneq ($(CONFIG_HVM),y)
 $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label
 endif
xen/arch/x86/lib/Makefile +2 -0
index ddf7e19bdc1d..8fe2dfd88553 100644
@@ -1 +1,3 @@
+lib-y += copy-guest.o
+lib-y += copy-unsafe.o
 lib-y += generic-hweightl.o
xen/arch/x86/lib/copy-guest.c renamed from xen/arch/x86/usercopy.c +2 -10
similarity index 94%
rename from xen/arch/x86/usercopy.c
rename to xen/arch/x86/lib/copy-guest.c
index a24b52cc66c1..73284b3f14be 100644
@@ -1,4 +1,4 @@
-/* 
+/*
  * User address space access functions.
  *
  * Copyright 1997 Andi Kleen <[email protected]>
@@ -6,8 +6,8 @@
  * Copyright 2002 Andi Kleen <[email protected]>
  */
 
-#include <xen/lib.h>
 #include <xen/sched.h>
+
 #include <asm/uaccess.h>
 
 #ifndef GUARD
@@ -139,14 +139,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) */
 
 /*
xen/arch/x86/lib/copy-unsafe.c new file +22 -0
new file mode 100644
index 000000000000..a51500370fb1
@@ -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:
+ */
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] x86: move / split usercopy.c to / into arch-specific library

Hi Jan,

Quoted 93 lines · Jan Beulich

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.

---
v3: Retain xen/sched.h #include.

---
  xen/arch/x86/Makefile                         |  4 ----
  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, 26 insertions(+), 14 deletions(-)

rename xen/arch/x86/{usercopy.c => lib/copy-guest.c} (94%) create mode 100644 xen/arch/x86/lib/copy-unsafe.c

xen/arch/x86/Makefile +0 -4
index 61e2293a467e..dfb258d7ac1c 100644
@@ -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
@@ -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 .
-
  ifneq ($(CONFIG_HVM),y)
  $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label
  endif
xen/arch/x86/lib/Makefile +2 -0
index ddf7e19bdc1d..8fe2dfd88553 100644
@@ -1 +1,3 @@
+lib-y += copy-guest.o
+lib-y += copy-unsafe.o
  lib-y += generic-hweightl.o
xen/arch/x86/lib/copy-guest.c renamed from xen/arch/x86/usercopy.c +2 -10
similarity index 94%
rename from xen/arch/x86/usercopy.c
rename to xen/arch/x86/lib/copy-guest.c
index a24b52cc66c1..73284b3f14be 100644
@@ -1,4 +1,4 @@
-/*
+/*
   * User address space access functions.
   *
   * Copyright 1997 Andi Kleen <[email protected]>
@@ -6,8 +6,8 @@
   * Copyright 2002 Andi Kleen <[email protected]>
   */
 
-#include <xen/lib.h>
  #include <xen/sched.h>
+
  #include <asm/uaccess.h>
 
  #ifndef GUARD
@@ -139,14 +139,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) */
 
  /*
xen/arch/x86/lib/copy-unsafe.c new file +2 -0
new file mode 100644
index 000000000000..a51500370fb1
@@ -0,0 +1,22 @@
+/*
+ * "Unsafe" access functions.

xen/arch/x86/lib/copy-unsafe.c line 12

Quoted 10 lines
xen/arch/x86/lib/copy-unsafe.c new file +10 -0
+ */
+
+#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"

Thank you for doing this.

Signature · 2 lines
Best regards,
-grygorii
#3 lore raw

PATCH v3 2/3 x86: move mem{cpy,set}.S to arch-specific library

In reply to Jan Beulich

If not these, what else are library functions.

---
v3: New.

---
 xen/arch/x86/Makefile           | 2 --
 xen/arch/x86/lib/Makefile       | 2 ++
 xen/arch/x86/{ => lib}/memcpy.S | 0
 xen/arch/x86/{ => lib}/memset.S | 0
 4 files changed, 2 insertions(+), 2 deletions(-)
 rename xen/arch/x86/{ => lib}/memcpy.S (100%)
 rename xen/arch/x86/{ => lib}/memset.S (100%)
xen/arch/x86/Makefile +0 -2
index dfb258d7ac1c..43117c88e59d 100644
@@ -48,8 +48,6 @@ obj-$(CONFIG_RETURN_THUNK) += indirect-thunk.o
 obj-$(CONFIG_PV) += ioport_emulate.o
 obj-y += irq.o
 obj-$(CONFIG_KEXEC) += machine_kexec.o
-obj-y += memcpy.o
-obj-y += memset.o
 obj-y += mm.o x86_64/mm.o
 obj-$(CONFIG_VM_EVENT) += monitor.o
 obj-y += mpparse.o
xen/arch/x86/lib/Makefile +2 -0
index 8fe2dfd88553..a5169f5e19c1 100644
@@ -1,3 +1,5 @@
 lib-y += copy-guest.o
 lib-y += copy-unsafe.o
 lib-y += generic-hweightl.o
+lib-y += memcpy.o
+lib-y += memset.o
xen/arch/x86/lib/memcpy.S renamed from xen/arch/x86/memcpy.S +0 -0
similarity index 100%
rename from xen/arch/x86/memcpy.S
rename to xen/arch/x86/lib/memcpy.S
xen/arch/x86/lib/memset.S renamed from xen/arch/x86/memset.S +0 -0
similarity index 100%
rename from xen/arch/x86/memset.S
rename to xen/arch/x86/lib/memset.S
#4 lore raw

PATCH v3 3/3 x86: move {clear_,copy_,scrub-}page.S to arch-specific library

In reply to Jan Beulich

These are pretty similar to the standard library memset() / memcpy().

Switch to building scrub-page.S unconditionally; the linker will simply not pick it up when not needed.

---
v3: New.
---
While moving I noticed that the files here have .file at the top, while mem{cpy,set}.S don't. There not being any static symbols, likely we could omit the directives here, too? Or should mem{cpy,set}.S gain them?

---
 xen/arch/x86/Makefile                           | 3 ---
 xen/arch/x86/lib/Makefile                       | 3 +++
 xen/arch/x86/{clear_page.S => lib/clear-page.S} | 0
 xen/arch/x86/{copy_page.S => lib/copy-page.S}   | 0
 xen/arch/x86/{ => lib}/scrub-page.S             | 0
 5 files changed, 3 insertions(+), 3 deletions(-)
 rename xen/arch/x86/{clear_page.S => lib/clear-page.S} (100%)
 rename xen/arch/x86/{copy_page.S => lib/copy-page.S} (100%)
 rename xen/arch/x86/{ => lib}/scrub-page.S (100%)
xen/arch/x86/Makefile +0 -3
index 43117c88e59d..1fc651146f10 100644
@@ -17,8 +17,6 @@ obj-y += apic.o
 obj-y += bhb-thunk.o
 obj-y += bitops.o
 obj-bin-y += bzimage.init.o
-obj-bin-y += clear_page.o
-obj-bin-y += copy_page.o
 obj-y += cpu-policy.o
 obj-y += cpuid.o
 obj-$(CONFIG_PV) += compat.o
@@ -57,7 +55,6 @@ obj-y += pci.o
 obj-y += physdev.o
 obj-$(CONFIG_COMPAT) += x86_64/physdev.o
 obj-$(CONFIG_X86_PSR) += psr.o
-obj-bin-$(CONFIG_DEBUG) += scrub-page.o
 obj-y += setup.o
 obj-y += shutdown.o
 obj-y += smp.o
xen/arch/x86/lib/Makefile +3 -0
index a5169f5e19c1..b9a65c662a56 100644
@@ -1,5 +1,8 @@
+lib-y += clear-page.o
 lib-y += copy-guest.o
+lib-y += copy-page.o
 lib-y += copy-unsafe.o
 lib-y += generic-hweightl.o
 lib-y += memcpy.o
 lib-y += memset.o
+lib-y += scrub-page.o
xen/arch/x86/lib/clear-page.S renamed from xen/arch/x86/clear_page.S +0 -0
similarity index 100%
rename from xen/arch/x86/clear_page.S
rename to xen/arch/x86/lib/clear-page.S
xen/arch/x86/lib/copy-page.S renamed from xen/arch/x86/copy_page.S +0 -0
similarity index 100%
rename from xen/arch/x86/copy_page.S
rename to xen/arch/x86/lib/copy-page.S
xen/arch/x86/lib/scrub-page.S renamed from xen/arch/x86/scrub-page.S +0 -0
similarity index 100%
rename from xen/arch/x86/scrub-page.S
rename to xen/arch/x86/lib/scrub-page.S