x86/cpu-policy: librarify copy-in/-out
v2 cover x86/cpu-policy: librarify copy-in/-out
1: move CPU policy library code
2: split out copy-in/-out functions
Jan
PATCH v2 1/2 x86/cpu-policy: move CPU policy library code
... to a dedicated subdir of x86's private lib/ sub-tree.
For the CPU policy harnesses and libxenguest use $(lib-y) as set by the new Makefile.common, whereas for the emulator harnesses stick to building just cpuid.o for the time being.
---
v2: New.
---
tools/fuzz/cpu-policy/Makefile | 7 +++++--
tools/fuzz/x86_instruction_emulator/Makefile | 2 +-
tools/libs/guest/Makefile.common | 7 +++++--
tools/tests/cpu-policy/Makefile | 7 +++++--
tools/tests/x86_emulator/Makefile | 2 +-
xen/arch/x86/arch.mk | 1 +
xen/arch/x86/lib/Makefile | 2 ++
xen/arch/x86/lib/cpu-policy/Makefile | 1 +
xen/arch/x86/lib/cpu-policy/Makefile.common | 3 +++
xen/{lib/x86 => arch/x86/lib/cpu-policy}/cpuid.c | 0
xen/{lib/x86 => arch/x86/lib/cpu-policy}/msr.c | 0
xen/{lib/x86 => arch/x86/lib/cpu-policy}/policy.c | 0
xen/{lib/x86 => arch/x86/lib/cpu-policy}/private.h | 0
xen/lib/Makefile | 2 --
xen/lib/x86/Makefile | 3 ---
15 files changed, 24 insertions(+), 13 deletions(-)
create mode 100644 xen/arch/x86/lib/cpu-policy/Makefile
create mode 100644 xen/arch/x86/lib/cpu-policy/Makefile.common
rename xen/{lib/x86 => arch/x86/lib/cpu-policy}/cpuid.c (100%)
rename xen/{lib/x86 => arch/x86/lib/cpu-policy}/msr.c (100%)
rename xen/{lib/x86 => arch/x86/lib/cpu-policy}/policy.c (100%)
rename xen/{lib/x86 => arch/x86/lib/cpu-policy}/private.h (100%)
delete mode 100644 xen/lib/x86/Makefiletools/fuzz/cpu-policy/Makefile +5 -2
@@ -20,9 +20,12 @@ install: all CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ CFLAGS += $(APPEND_CFLAGS) -Og -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy -afl-policy-fuzzer: afl-policy-fuzzer.o msr.o cpuid.o +lib-y := +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common + +afl-policy-fuzzer: afl-policy-fuzzer.o $(lib-y) $(CC) $(CFLAGS) $^ -o $@ -include $(DEPS_INCLUDE)
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -21,7 +21,7 @@ vpath %.h ../../tests/x86_emulator CFLAGS += -iquote ../../tests/x86_emulator # Add libx86 to the build -vpath %.c $(XEN_ROOT)/xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy x86_emulate: mkdir -p $@
tools/libs/guest/Makefile.common +5 -2
@@ -33,9 +33,12 @@ LIBELF_OBJS += libelf-dominfo.o OBJS-y += $(LIBELF_OBJS) ifeq ($(CONFIG_X86),y) # Add libx86 to the build -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy -OBJS-y += cpuid.o msr.o policy.o +lib-y := +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common + +OBJS-y += $(lib-y) endif # new domain builder
tools/tests/cpu-policy/Makefile +5 -2
@@ -42,11 +42,14 @@ CFLAGS += $(APPEND_CFLAGS) LDFLAGS += $(APPEND_LDFLAGS) -vpath %.c ../../../xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy + +lib-y := +include $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy/Makefile.common %.o: Makefile -test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o +test-cpu-policy: test-cpu-policy.o $(lib-y) $(CC) $^ -o $@ $(LDFLAGS) -include $(DEPS_INCLUDE)
tools/tests/x86_emulator/Makefile +1 -1
@@ -17,7 +17,7 @@ vpath x86_emulate/%.h $(XEN_ROOT)/xen/arch/x86 HOSTCFLAGS += -iquote $(XEN_ROOT)/xen/arch/x86 # Add libx86 to the build -vpath %.c $(XEN_ROOT)/xen/lib/x86 +vpath %.c $(XEN_ROOT)/xen/arch/x86/lib/cpu-policy CFLAGS += $(CFLAGS_xeninclude)
xen/arch/x86/arch.mk +1 -0
@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000 ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.a CFLAGS += -DXEN_IMG_OFFSET=$(XEN_IMG_OFFSET)
xen/arch/x86/lib/Makefile +2 -0
@@ -6,3 +6,5 @@ lib-y += generic-hweightl.o lib-y += memcpy.o lib-y += memset.o lib-y += scrub-page.o + +obj-y += cpu-policy/
xen/arch/x86/lib/cpu-policy/Makefile new file +1 -0
@@ -0,0 +1 @@ +include $(srcdir)/Makefile.common
xen/arch/x86/lib/cpu-policy/Makefile.common new file +3 -0
@@ -0,0 +1,3 @@ +lib-y += cpuid.o +lib-y += msr.o +lib-y += policy.o
xen/arch/x86/lib/cpu-policy/cpuid.c renamed from xen/lib/x86/cpuid.c +0 -0
xen/arch/x86/lib/cpu-policy/msr.c renamed from xen/lib/x86/msr.c +0 -0
xen/arch/x86/lib/cpu-policy/policy.c renamed from xen/lib/x86/policy.c +0 -0
xen/arch/x86/lib/cpu-policy/private.h renamed from xen/lib/x86/private.h +0 -0
xen/lib/Makefile +0 -2
@@ -1,5 +1,3 @@ -obj-$(CONFIG_X86) += x86/ - lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o
xen/lib/x86/Makefile deleted +0 -3
@@ -1,3 +0,0 @@ -obj-y += cpuid.o -obj-y += msr.o -obj-y += policy.o
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
xen/arch/x86/arch.mk line 7
Quoted 9 lines · Jan Beulich
xen/arch/x86/arch.mk +1
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000 ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.a
This wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
~Andrew
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000
Quoted 4 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.
Jan
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000
Quoted 7 lines
Quoted 3 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in
arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.
I agree that we don't have the explicit ordering requirement that we have with arch/x86/lib/lib.a.
But, it still reads as bogus to be putting arch/x86/lib/cpu-policy/lib.a in the non-ARCH list.
What difference is there having this a little earlier in the linker arguments? Nothing AFAICT.
~Andrew
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 18 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000Quoted 7 lines
Quoted 3 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in
arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.
Quoted 8 lines
I agree that we don't have the explicit ordering requirement that we have with
arch/x86/lib/lib.a.But, it still reads as bogus to be putting
arch/x86/lib/cpu-policy/lib.ain the non-ARCH list.What difference is there having this a little earlier in the linker arguments? Nothing AFAICT.
Indeed. The sole reason why I'd prefer things as presented is that putting stuff in ARCH_LIBS should imo be the special case (i.e. requiring a special reason), while putting things in ALL_LIBS should be the default.
Jan
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000Quoted 7 lines
Quoted 3 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in
arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.I agree that we don't have the explicit ordering requirement that we have with
arch/x86/lib/lib.a.But, it still reads as bogus to be putting
arch/x86/lib/cpu-policy/lib.ain the non-ARCH list.
Quoted 6 lines
Quoted 2 lines
What difference is there having this a little earlier in the linker arguments? Nothing AFAICT.
Indeed. The sole reason why I'd prefer things as presented is that putting stuff in
ARCH_LIBSshould imo be the special case (i.e. requiring a special reason), while putting things inALL_LIBSshould be the default.
I agree with Andrew that it feels weird that arch/x86/lib/lib.a is placed in ARCH_LIBS-y and arch/x86/lib/cpu-policy/lib.a is placed in ALL_LIBS-y. If we want to do it that way it needs a comment explaining why they are placed in different list, otherwise it seems like a typo on first sight, and it's likely to confuse people in the future.
Thanks, Roger.
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 33 lines · Roger Pau Monné
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000Quoted 7 lines
Quoted 3 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in
arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.I agree that we don't have the explicit ordering requirement that we have with
arch/x86/lib/lib.a.But, it still reads as bogus to be putting
arch/x86/lib/cpu-policy/lib.ain the non-ARCH list.Quoted 6 lines
Quoted 2 lines
What difference is there having this a little earlier in the linker arguments? Nothing AFAICT.
Indeed. The sole reason why I'd prefer things as presented is that putting stuff in
ARCH_LIBSshould imo be the special case (i.e. requiring a special reason), while putting things inALL_LIBSshould be the default.
Quoted 6 lines
I agree with Andrew that it feels weird that
arch/x86/lib/lib.ais placed in ARCH_LIBS-y andarch/x86/lib/cpu-policy/lib.ais placed in ALL_LIBS-y. If we want to do it that way it needs a comment explaining why they are placed in different list, otherwise it seems like a typo on first sight, and it's likely to confuse people in the future.
Well, I'll (reluctantly) change then.
Jan
Re: [PATCH v2 1/2] x86/cpu-policy: move CPU policy library code
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Roger Pau Monné
Quoted 29 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
xen/arch/x86/arch.mk +0
-0@@ -4,6 +4,7 @@ export XEN_IMG_OFFSET := 0x200000Quoted 7 lines
Quoted 3 lines
xen/arch/x86/arch.mk line 7
Quoted 2 lines
xen/arch/x86/arch.mk +1
-0ARCH_LIBS-y += arch/x86/lib/lib.a +ALL_LIBS-y += arch/x86/lib/cpu-policy/lib.aThis wants to extend ARCH_LIBS-y surely? Is this a rebasing oversight?
No, this was deliberate. The functions here are different from those in
arch/x86/lib/lib.a. We don't need to fear collision with "common code" ones. Hence I preferred to use the more "normal" placement into what's passed to the linker.Quoted 8 lines
I agree that we don't have the explicit ordering requirement that we have with
arch/x86/lib/lib.a.But, it still reads as bogus to be putting
arch/x86/lib/cpu-policy/lib.ain the non-ARCH list.What difference is there having this a little earlier in the linker arguments? Nothing AFAICT.
Indeed. The sole reason why I'd prefer things as presented is that putting stuff in
ARCH_LIBSshould imo be the special case (i.e. requiring a special reason), while putting things inALL_LIBSshould be the default.
Quoted 7 lines
Quoted 6 lines
I agree with Andrew that it feels weird that
arch/x86/lib/lib.ais placed in ARCH_LIBS-y andarch/x86/lib/cpu-policy/lib.ais placed in ALL_LIBS-y. If we want to do it that way it needs a comment explaining why they are placed in different list, otherwise it seems like a typo on first sight, and it's likely to confuse people in the future.Well, I'll (reluctantly) change then.
Thanks. With that done, Reviewed-by: Andrew Cooper <[email protected]>
PATCH v2 2/2 x86/cpu-policy: split out copy-in/-out functions
In reply to Jan BeulichThis is to aid with MGMT_HYPERCALL work, leaving the functions potentially unreferenced (which Misra dislikes). By moving them to separate archive members, the linker simply will not pick them up when not needed.
As the CPUID and MSR ones are always used together, put the "from" and "to" variants of each together in one file respectively.
---
v2: Re-base over moving of the entire directory.
--- xen/arch/x86/lib/cpu-policy/Makefile.common | 3 +- .../x86/lib/cpu-policy/copy-from-buffer.c | 238 ++++++++++++++++++ xen/arch/x86/lib/cpu-policy/copy-to-buffer.c | 204 +++++++++++++++ xen/arch/x86/lib/cpu-policy/cpuid.c | 226 ----------------- xen/arch/x86/lib/cpu-policy/msr.c | 130 ---------- xen/arch/x86/lib/cpu-policy/private.h | 31 --- 6 files changed, 444 insertions(+), 388 deletions(-) create mode 100644 xen/arch/x86/lib/cpu-policy/copy-from-buffer.c create mode 100644 xen/arch/x86/lib/cpu-policy/copy-to-buffer.c delete mode 100644 xen/arch/x86/lib/cpu-policy/msr.c
xen/arch/x86/lib/cpu-policy/Makefile.common +2 -1
@@ -1,3 +1,4 @@ +lib-y += copy-from-buffer.o +lib-y += copy-to-buffer.o lib-y += cpuid.o -lib-y += msr.o lib-y += policy.o
xen/arch/x86/lib/cpu-policy/copy-from-buffer.c new file +238 -0
238 lines not on this page · raw message
xen/arch/x86/lib/cpu-policy/copy-to-buffer.c new file +204 -0
204 lines not on this page · raw message
xen/arch/x86/lib/cpu-policy/cpuid.c +0 -226
232 lines not on this page · raw message
xen/arch/x86/lib/cpu-policy/msr.c deleted +0 -130
130 lines not on this page · raw message
xen/arch/x86/lib/cpu-policy/private.h +0 -31
@@ -12,9 +12,6 @@#include <asm/msr.h> -#define copy_to_buffer_offset copy_to_guest_offset -#define copy_from_buffer_offset copy_from_guest_offset -#else #include <errno.h>
@@ -35,34 +32,6 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)return addr[bit /8 ] & (1u << (bit %8 )); } -#define array_access_nospec (a, i) (a)[(i)] - -/* memcpy(), but with copy_to_guest_offset()'s API. */ -#define copy_to_buffer_offset (dst, index, src, nr) \ -({ \ - const typeof(*(src)) *src_ = (src); \ - typeof(*(dst)) *dst_ = (dst); \ - typeof(index) index_ = (index); \ - typeof(nr) nr_ = (nr), i_; \ - \ - for ( i_ = 0; i_ < nr_; i_++ ) \ - dst_[index_ + i_] = src_[i_]; \ - 0; \ -}) - -/* memcpy(), but with copy_from_guest_offset()'s API. */ -#define copy_from_buffer_offset (dst, src, index, nr) \ -({ \ - const typeof(*(src)) *src_ = (src); \ - typeof(*(dst)) *dst_ = (dst); \ - typeof(index) index_ = (index); \ - typeof(nr) nr_ = (nr), i_; \ - \ - for ( i_ = 0; i_ < nr_; i_++ ) \ - dst_[i_] = src_[index_ + i_]; \ - 0; \ -}) -#endif /* __XEN__ */ #endif /* XEN_LIB_X86_PRIVATE_H */
Re: [PATCH v2 2/2] x86/cpu-policy: split out copy-in/-out functions
Quoted 8 lines · Jan Beulich
This is to aid with
MGMT_HYPERCALLwork, leaving the functions potentially unreferenced (which Misra dislikes). By moving them to separate archive members, the linker simply will not pick them up when not needed.As the CPUID and MSR ones are always used together, put the "from" and "to" variants of each together in one file respectively.
Signed-off-by Jan Beulich <[email protected]>