x86: CPUID and MSR policy marshalling support
v2 cover x86: CPUID and MSR policy marshalling support
This series introduces libx86, a small shared library between the hypervisor and libxc, and hypercalls to get full CPUID/MSR policies. Future work will implement XEN_DOMCTL_set_cpumsr_policy, after the auditing and comparison logic is sorted.
In the meantime, the data marshalling logic is in a suitable state for review.
This series is based on staging, and can be found in git form here:
http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/cpuid-marshal-v2
There are many changes from v1. See individual patches for details.
Andrew Cooper (6):
x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl
libx86: Introduce libx86/cpuid.h
libx86: Introduce libx86/msr.h and share msr_policy with userspace
libx86: Introduce a helper to serialise cpuid_policy objects
libx86: Introduce a helper to deserialise cpuid_policy objects
x86: Introduce struct cpu_policy to refer to a group of individual policies
Roger Pau Monné (5):
libx86: generate cpuid-autogen.h in the libx86 include dir
libx86: Share struct cpuid_policy with userspace
libx86: introduce a libx86 shared library
libx86: Introduce a helper to serialise msr_policy objects
libx86: introduce a helper to deserialise msr_policy objects
Sergey Dyasli (2):
x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
.gitignore | 2 +-
tools/include/Makefile | 5 +
tools/include/xen-tools/libs.h | 8 +
tools/libxc/Makefile | 15 +-
tools/libxc/include/xenctrl.h | 10 +-
tools/libxc/xc_cpuid_x86.c | 112 +++++++++++---
tools/misc/xen-cpuid.c | 133 +++++++++++++++-
tools/xenstore/xenstored_core.h | 2 -
xen/arch/x86/cpu/common.c | 2 +-
xen/arch/x86/cpuid.c | 32 +---
xen/arch/x86/domctl.c | 34 +++++
xen/arch/x86/sysctl.c | 98 ++++++++++++
xen/arch/x86/x86_emulate/x86_emulate.h | 7 +-
xen/common/Makefile | 1 +
xen/common/libx86/Makefile | 2 +
xen/common/libx86/cpuid.c | 228 ++++++++++++++++++++++++++++
xen/common/libx86/msr.c | 107 +++++++++++++
xen/common/libx86/private.h | 73 +++++++++
xen/include/Makefile | 11 +-
xen/include/asm-x86/cpufeatures.h | 2 +-
xen/include/asm-x86/cpuid.h | 228 +---------------------------
xen/include/asm-x86/msr.h | 28 +---
xen/include/public/arch-x86/xen.h | 18 +++
xen/include/public/domctl.h | 18 +++
xen/include/public/sysctl.h | 37 +++++
xen/include/xen/libx86/Makefile | 8 +
xen/include/xen/libx86/cpu-policy.h | 24 +++
xen/include/{asm-x86 => xen/libx86}/cpuid.h | 107 ++++++-------
xen/include/xen/libx86/msr.h | 65 ++++++++
xen/xsm/flask/hooks.c | 2 +
xen/xsm/flask/policy/access_vectors | 3 +-
31 files changed, 1036 insertions(+), 386 deletions(-)
create mode 100644 xen/common/libx86/Makefile
create mode 100644 xen/common/libx86/cpuid.c
create mode 100644 xen/common/libx86/msr.c
create mode 100644 xen/common/libx86/private.h
create mode 100644 xen/include/xen/libx86/Makefile
create mode 100644 xen/include/xen/libx86/cpu-policy.h
copy xen/include/{asm-x86 => xen/libx86}/cpuid.h (77%)
create mode 100644 xen/include/xen/libx86/msr.hSignature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/13 x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl
More than the bottom two bits are now defined, and the MSR policy work has shown that using non-architectural representations turns out to be problematic for more than just asm code. As the architectural representation is the expected default, we don't need to justify why we are using it.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
New in v2
--- xen/include/asm-x86/msr.h | 5 ----- 1 file changed, 5 deletions(-)
xen/include/asm-x86/msr.h +0 -5
@@ -287,11 +287,6 @@ struct vcpu_msrs {/* 0x00000048 - MSR_SPEC_CTRL */ struct { -/* -* Only the bottom two bits are defined, so no need to waste space -* with uint64_t at the moment, but use uint32_t for the convenience -* of the assembly code. -*/ uint32_t raw; } spec_ctrl;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/13] x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
More than the bottom two bits are now defined, and the MSR policy work has shown that using non-architectural representations turns out to be problematic
for more than just asm code. As the architectural representation is the expected default, we don't need to justify why we are using it.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/13] x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl
In reply to Andrew CooperQuoted 4 lines · Andrew Cooper
More than the bottom two bits are now defined, and the MSR policy work has shown that using non-architectural representations turns out to be problematic for more than just asm code. As the architectural representation is the expected default, we don't need to justify why we are using it.
If that's indeed the architectural representation shouldn't you use a uint64_t instead?
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 01/13] x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl
Quoted 7 lines · Roger Pau Monné
Quoted 4 lines · Andrew Cooper
More than the bottom two bits are now defined, and the MSR policy work has shown that using non-architectural representations turns out to be problematic for more than just asm code. As the architectural representation is the expected default, we don't need to justify why we are using it.
If that's indeed the architectural representation shouldn't you use a
uint64_tinstead?
For MSR_SPEC_CTRL specifically, it makes a meaningful difference in the complexity of the asm, but in general, there no point wasting space storing 32 bits of 0's when we don't need to.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/13 libx86: Introduce libx86/cpuid.h
In reply to Andrew CooperBegin to untangle the header dependency tangle by moving definition of struct cpuid_leaf out of x86_emulate.h into the new cpuid.h.
Additionally, plumb the header through to libxc. This is technically a redundant include at this point, but it helps build-test the later changes, and will be used eventually.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
Note concerning the positioning of libx86. It turns out after trying to move it elsewhere that the movement is prohibitive because of the way Xen headers are included by the tools.
For now, this is consistent with the other libs, and we can move it in the future after some hygene has been applied to the build system.
--- tools/include/Makefile | 1 + tools/libxc/xc_cpuid_x86.c | 2 ++ xen/arch/x86/x86_emulate/x86_emulate.h | 7 ++----- xen/include/asm-x86/cpuid.h | 4 +++- xen/include/xen/libx86/cpuid.h | 20 ++++++++++++++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 xen/include/xen/libx86/cpuid.h
tools/include/Makefile +1 -0
@@ -23,6 +23,7 @@ xen/.dir: ln -sf $(XEN_ROOT)/xen/include/acpi acpi ifeq ($(CONFIG_X86),y) ln -sf $(XEN_ROOT)/xen/include/asm-x86 xen/asm + ln -sf $(XEN_ROOT)/xen/include/xen/libx86 xen/libx86 endif touch $@
tools/libxc/xc_cpuid_x86.c +2 -0
@@ -33,6 +33,8 @@ enum { };#include "_xc_cpuid_autogen.h" +#include <xen/libx86/cpuid.h> +#define bitmaskof (idx) (1u << ((idx) & 31))#define featureword_of (idx) ((idx) >> 5)#define clear_feature (idx, dst) ((dst) &= ~bitmaskof(idx))
xen/arch/x86/x86_emulate/x86_emulate.h +2 -5
@@ -23,6 +23,8 @@#ifndef __X86_EMULATE_H__#define __X86_EMULATE_H__ +#include <xen/libx86/cpuid.h> +#define MAX_INST_LEN 15#if defined(__i386__)
@@ -172,11 +174,6 @@ enum x86_emulate_fpu_type { X86EMUL_FPU_none }; -struct cpuid_leaf -{ -uint32_t a, b, c, d; -}; -struct x86_emulate_state ;/*
xen/include/asm-x86/cpuid.h +3 -1
@@ -18,7 +18,9 @@#ifndef __ASSEMBLY__#include <xen/types.h> #include <xen/kernel.h> -#include <asm/x86_emulate.h> + +#include <xen/libx86/cpuid.h> +#include <public/sysctl.h> extern const uint32_t known_features[FSCAPINTS ];
xen/include/xen/libx86/cpuid.h new file +20 -0
@@ -0,0 +1,20 @@ +/* Common data structures and functions consumed by hypervisor and toolstack */ +#ifndef XEN_LIBX86_CPUID_H +#define XEN_LIBX86_CPUID_H + +struct cpuid_leaf +{ +uint32_t a, b, c, d; +}; + +#endif /* !XEN_LIBX86_CPUID_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 02/13] libx86: Introduce libx86/cpuid.h
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
Begin to untangle the header dependency tangle by moving definition of struct
cpuid_leafout ofx86_emulate.hinto the newcpuid.h.Additionally, plumb the header through to libxc. This is technically a redundant include at this point, but it helps build-test the later changes, and will be used eventually.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
Quoted 3 lines
Note concerning the positioning of libx86. It turns out after trying to move it elsewhere that the movement is prohibitive because of the way Xen headers are included by the tools.
If there's really something preventing it to be placed better, then I'm certainly willing to give my ack here, but I'd like to have a more clear understanding of what issue(s) you are talking about above.
Quoted 2 lines
For now, this is consistent with the other libs, and we can move it in the future after some hygene has been applied to the build system.
After all even better to avoid code churn resulting from such extra movement.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 02/13] libx86: Introduce libx86/cpuid.h
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
Begin to untangle the header dependency tangle by moving definition of struct
cpuid_leafout ofx86_emulate.hinto the newcpuid.h.Additionally, plumb the header through to libxc. This is technically a redundant include at this point, but it helps build-test the later changes, and will be used eventually.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
Quoted 6 lines
Quoted 3 lines
Note concerning the positioning of libx86. It turns out after trying to move it elsewhere that the movement is prohibitive because of the way Xen headers are included by the tools.
If there's really something preventing it to be placed better, then I'm certainly willing to give my ack here, but I'd like to have a more clear understanding of what issue(s) you are talking about above.
It is better explained in the context of the following patch.
Moving to asm-x86/libx86/ breaks the autogen safety because the entire tree hierarchy is made available with a single directory symlink.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 02/13] libx86: Introduce libx86/cpuid.h
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 12:22, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
Begin to untangle the header dependency tangle by moving definition of struct
cpuid_leafout ofx86_emulate.hinto the newcpuid.h.Additionally, plumb the header through to libxc. This is technically a redundant include at this point, but it helps build-test the later changes, and will be used eventually.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Wei Liu <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>Note concerning the positioning of libx86. It turns out after trying to move it elsewhere that the movement is prohibitive because of the way Xen headers are included by the tools.
Quoted 8 lines
Quoted 3 lines
If there's really something preventing it to be placed better, then I'm certainly willing to give my ack here, but I'd like to have a more clear understanding of what issue(s) you are talking about above.
It is better explained in the context of the following patch.
Moving to asm-x86/libx86/ breaks the autogen safety because the entire tree hierarchy is made available with a single directory symlink.
But there was never talk of asm-x86/libx86/. Options discussed were top level lib/x86/ and include/x86/, or xen/lib/x86/ and xen/include/libx86/ (or close derivatives thereof).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/13 libx86: generate cpuid-autogen.h in the libx86 include dir
In reply to Andrew CooperFrom: Roger Pau Monné <[email protected]>
This avoids all users needing to opencode local generation of the file.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rewrite from scratch
--- .gitignore | 2 +- tools/include/Makefile | 6 +++++- tools/libxc/Makefile | 9 --------- tools/libxc/xc_cpuid_x86.c | 1 - xen/include/Makefile | 11 +++++------ xen/include/asm-x86/cpufeatures.h | 2 +- xen/include/xen/libx86/Makefile | 8 ++++++++ xen/include/xen/libx86/cpuid.h | 2 ++ 8 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 xen/include/xen/libx86/Makefile
.gitignore +1 -1
@@ -311,7 +311,6 @@ xen/arch/*/efi/runtime.c xen/include/headers*.chk xen/include/asm xen/include/asm-*/asm-offsets.h -xen/include/asm-x86/cpuid-autogen.h xen/include/compat/* xen/include/config/ xen/include/generated/
@@ -319,6 +318,7 @@ xen/include/public/public xen/include/xen/*.new xen/include/xen/acm_policy.h xen/include/xen/compile.h +xen/include/xen/libx86/cpuid-autogen.h xen/test/livepatch/config.h xen/test/livepatch/xen_bye_world.livepatch xen/test/livepatch/xen_hello_world.livepatch
tools/include/Makefile +5 -1
@@ -23,7 +23,11 @@ xen/.dir: ln -sf $(XEN_ROOT)/xen/include/acpi acpi ifeq ($(CONFIG_X86),y) ln -sf $(XEN_ROOT)/xen/include/asm-x86 xen/asm - ln -sf $(XEN_ROOT)/xen/include/xen/libx86 xen/libx86 + mkdir -p xen/libx86 + for f in $(filter-out %autogen.h,$(patsubst $(XEN_ROOT)/xen/include/xen/libx86/%,%,Makefile $(wildcard $(XEN_ROOT)/xen/include/xen/libx86/*.h))); do \ + ln -sf $(XEN_ROOT)/xen/include/xen/libx86/$$f xen/libx86/$$f; \ + done + $(MAKE) -C xen/libx86 all XEN_ROOT=$(XEN_ROOT) endif touch $@
tools/libxc/Makefile +0 -9
@@ -147,15 +147,6 @@ $(eval $(genpath-target)) xc_private.h: _paths.h -ifeq ($(CONFIG_X86),y) - -_xc_cpuid_autogen.h: $(XEN_ROOT)/xen/include/public/arch-x86/cpufeatureset.h $(XEN_ROOT)/xen/tools/gen-cpuid.py - $(PYTHON) $(XEN_ROOT)/xen/tools/gen-cpuid.py -i $^ -o [email protected] - $(call move-if-changed,[email protected],$@) - -build: _xc_cpuid_autogen.h -endif - $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): xc_private.h
tools/libxc/xc_cpuid_x86.c +0 -1
@@ -31,7 +31,6 @@ enum {#define XEN_CPUFEATURE (name, value) X86_FEATURE_##name = value,#include <xen/arch-x86/cpufeatureset.h> }; -#include "_xc_cpuid_autogen.h" #include <xen/libx86/cpuid.h>
xen/include/Makefile +5 -6
@@ -141,14 +141,13 @@ headers++.chk: $(PUBLIC_HEADERS) Makefile endif ifeq ($(XEN_TARGET_ARCH),x86_64) +.PHONY: libx86-all +libx86-all: + $(MAKE) -C xen/libx86 all -$(BASEDIR)/include/asm-x86/cpuid-autogen.h: $(BASEDIR)/include/public/arch-x86/cpufeatureset.h $(BASEDIR)/tools/gen-cpuid.py FORCE - $(PYTHON) $(BASEDIR)/tools/gen-cpuid.py -i $< -o [email protected] - $(call move-if-changed,[email protected],$@) - -all: $(BASEDIR)/include/asm-x86/cpuid-autogen.h +all: libx86-all endif clean:: rm -rf compat config generated headers*.chk - rm -f $(BASEDIR)/include/asm-x86/cpuid-autogen.h + rm -f $(BASEDIR)/include/xen/libx86/cpuid-autogen.h
xen/include/asm-x86/cpufeatures.h +1 -1
@@ -2,7 +2,7 @@* Explicitly intended for multiple inclusion. */ -#include <asm/cpuid-autogen.h> +#include <xen/libx86/cpuid-autogen.h> #define FSCAPINTS FEATURESET_NR_ENTRIES
xen/include/xen/libx86/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +include $(XEN_ROOT)/Config.mk + +.PHONY: all +all: cpuid-autogen.h + +cpuid-autogen.h: $(XEN_ROOT)/xen/include/public/arch-x86/cpufeatureset.h $(XEN_ROOT)/xen/tools/gen-cpuid.py + $(PYTHON) $(XEN_ROOT)/xen/tools/gen-cpuid.py -i $< -o [email protected] + $(call move-if-changed,[email protected],$@)
xen/include/xen/libx86/cpuid.h +2 -0
@@ -2,6 +2,8 @@ #ifndef XEN_LIBX86_CPUID_H #define XEN_LIBX86_CPUID_H +#include <xen/libx86/cpuid-autogen.h> + struct cpuid_leaf { uint32_t a, b, c, d;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 03/13] libx86: generate cpuid-autogen.h in the libx86 include dir
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
From: Roger Pau Monné <[email protected]>
This avoids all users needing to opencode local generation of the file.
Signed-off-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/13 libx86: Share struct cpuid_policy with userspace
In reply to Andrew CooperFrom: Roger Pau Monné <[email protected]>
Both Xen and the toolstack have need of the same logic when it comes to manipulation and checking of the CPUID and MSR values offered to guests. To that end, libx86 is being introduced to allow Xen and the toolstack to share a single implementation, rather than duplicating the logic.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Move MAX() into xen-tools/libs.h
* Expand commit message.
--- tools/include/xen-tools/libs.h | 4 + xen/include/asm-x86/cpuid.h | 219 ----------------------------------------- xen/include/xen/libx86/cpuid.h | 219 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+), 219 deletions(-)
tools/include/xen-tools/libs.h +4 -0
@@ -13,4 +13,8 @@#define ARRAY_SIZE (a) (sizeof(a) / sizeof(*a))#endif +#ifndef MAX +#define MAX (x, y) ((x) > (y) ? (x) : (y)) +#endif +#endif /* __XEN_TOOLS_LIBS__ */
xen/include/asm-x86/cpuid.h +0 -219
231 lines not on this page · raw message
xen/include/xen/libx86/cpuid.h +219 -0
230 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace
tools/include/xen-tools/libs.h line 18
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
tools/include/xen-tools/libs.h +3
-0@@ -13,4 +13,8 @@#define ARRAY_SIZE (a) (sizeof(a) / sizeof(*a))#endif +#ifndef MAX +#define MAX (x, y) ((x) > (y) ? (x) : (y)) +#endif
I find asymmetries like this odd: There should then also be MIN() imo.
Quoted 4 lines
tools/include/xen-tools/libs.h +4
-0+static inline void cpuid_featureset_to_policy ( +const uint32_t fs[FEATURESET_NR_ENTRIES ],struct cpuid_policy *p) +{ + p->basic._1d = fs[FEATURESET_1d];
tools/include/xen-tools/libs.h
Quoted 10 lines
tools/include/xen-tools/libs.h +10
-0+ p->basic._1c = fs[FEATURESET_1c]; + p->extd.e1d = fs[FEATURESET_e1d]; + p->extd.e1c = fs[FEATURESET_e1c]; + p->xstate.Da1 = fs[FEATURESET_Da1]; + p->feat._7b0 = fs[FEATURESET_7b0]; + p->feat._7c0 = fs[FEATURESET_7c0]; + p->extd.e7d = fs[FEATURESET_e7d]; + p->extd.e8b = fs[FEATURESET_e8b]; + p->feat._7d0 = fs[FEATURESET_7d0]; +}
I realize this is only code movement, but since you didn't answer the question raised on the Intel Process Trace thread (v2 03/10) yet, I'll raise it here again: Shouldn't other fields of p be set to zero here?
Irrespective of both items (i.e. with or without them addressed)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace
Quoted 11 lines · Jan Beulich
tools/include/xen-tools/libs.h line 18
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
tools/include/xen-tools/libs.h +3
-0@@ -13,4 +13,8 @@#define ARRAY_SIZE (a) (sizeof(a) / sizeof(*a))#endif +#ifndef MAX +#define MAX (x, y) ((x) > (y) ? (x) : (y)) +#endif I find asymmetries like this odd: There should then also be
MIN()imo.
Patch 7, where it is first used.
Quoted 10 lines
Quoted 10 lines
tools/include/xen-tools/libs.h +9
-0+static inline void cpuid_featureset_to_policy ( +const uint32_t fs[FEATURESET_NR_ENTRIES ],struct cpuid_policy *p) +{ + p->basic._1d = fs[FEATURESET_1d]; + p->basic._1c = fs[FEATURESET_1c]; + p->extd.e1d = fs[FEATURESET_e1d]; + p->extd.e1c = fs[FEATURESET_e1c]; + p->xstate.Da1 = fs[FEATURESET_Da1]; + p->feat._7b0 = fs[FEATURESET_7b0];
Quoted 8 lines
tools/include/xen-tools/libs.h
Quoted 5 lines
tools/include/xen-tools/libs.h +5
-0+ p->feat._7c0 = fs[FEATURESET_7c0]; + p->extd.e7d = fs[FEATURESET_e7d]; + p->extd.e8b = fs[FEATURESET_e8b]; + p->feat._7d0 = fs[FEATURESET_7d0]; +}I realize this is only code movement, but since you didn't answer the question raised on the Intel Process Trace thread (v2 03/10) yet, I'll raise it here again: Shouldn't other fields of p be set to zero here?
No - why should it?
(In fact, it very deliberately does not, and changing this will break all of the policy derivation logic.)
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:51, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/include/xen/libx86/cpuid.h +9
-0+static inline void cpuid_featureset_to_policy ( +const uint32_t fs[FEATURESET_NR_ENTRIES ],struct cpuid_policy *p) +{ + p->basic._1d = fs[FEATURESET_1d]; + p->basic._1c = fs[FEATURESET_1c]; + p->extd.e1d = fs[FEATURESET_e1d]; + p->extd.e1c = fs[FEATURESET_e1c]; + p->xstate.Da1 = fs[FEATURESET_Da1]; + p->feat._7b0 = fs[FEATURESET_7b0];Quoted 8 lines
xen/include/xen/libx86/cpuid.h line 229
Quoted 5 lines
xen/include/xen/libx86/cpuid.h +5
-0+ p->feat._7c0 = fs[FEATURESET_7c0]; + p->extd.e7d = fs[FEATURESET_e7d]; + p->extd.e8b = fs[FEATURESET_e8b]; + p->feat._7d0 = fs[FEATURESET_7d0]; +}I realize this is only code movement, but since you didn't answer the question raised on the Intel Process Trace thread (v2 03/10) yet, I'll raise it here again: Shouldn't other fields of p be set to zero here?
Quoted 4 lines
No - why should it?
(In fact, it very deliberately does not, and changing this will break all of the policy derivation logic.)
Did you look at the context in which I've raised the question originally? I did in particular ask about this effectively still being a form of black listing (I said "white listing" there by mistake), just taking leaf 6 (and Intel hardware) as example. guest_cpuid() takes whatever is there in the policy, and update_domain_cpuid_info() does nothing either. It was my understanding that with the switch to the new model we're now strictly while listing features. Luwei's patch would extend the un-audited handing through to RDT and SGX leaves.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:51, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/include/xen/libx86/cpuid.h +4
-0+static inline void cpuid_featureset_to_policy ( +const uint32_t fs[FEATURESET_NR_ENTRIES ],struct cpuid_policy *p) +{ + p->basic._1d = fs[FEATURESET_1d];xen/include/xen/libx86/cpuid.h line 229
Quoted 10 lines
xen/include/xen/libx86/cpuid.h +10
-0+ p->basic._1c = fs[FEATURESET_1c]; + p->extd.e1d = fs[FEATURESET_e1d]; + p->extd.e1c = fs[FEATURESET_e1c]; + p->xstate.Da1 = fs[FEATURESET_Da1]; + p->feat._7b0 = fs[FEATURESET_7b0]; + p->feat._7c0 = fs[FEATURESET_7c0]; + p->extd.e7d = fs[FEATURESET_e7d]; + p->extd.e8b = fs[FEATURESET_e8b]; + p->feat._7d0 = fs[FEATURESET_7d0]; +}I realize this is only code movement, but since you didn't answer the question raised on the Intel Process Trace thread (v2 03/10) yet, I'll raise it here again: Shouldn't other fields of p be set to zero here?
Quoted 5 lines
Quoted 4 lines
No - why should it?
(In fact, it very deliberately does not, and changing this will break all of the policy derivation logic.)
Did you look at the context in which I've raised the question originally?
Yes, but I still don't understand what prompted the question.
There is not a single use of caller cpuid_featureset_to_policy() where zeroing the rest of the policy would be an appropriate or reasonable thing to do.
Quoted 4 lines
I did in particular ask about this effectively still being a form of black listing (I said "white listing" there by mistake), just taking leaf 6 (and Intel hardware) as example.
guest_cpuid()takes whatever is there in the policy, andupdate_domain_cpuid_info()does nothing either.
See the head of recalculate_misc() which unilaterally zeroes that leaf, irrespective of toolstack settings.
Quoted 3 lines
It was my understanding that with the switch to the new model we're now strictly while listing features. Luwei's patch would extend the un-audited handing through to RDT and SGX leaves.
That is one reason why I won't ack the patch in that shape. But as I'm currently rewriting this logic for a different reason, explaining the correct steps to extend MAX_*_LEAF will cause unnecessary work for Luwei as the implementation is about to change under his feet.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 12:16, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:51, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/include/xen/libx86/cpuid.h +4
-0+static inline void cpuid_featureset_to_policy ( +const uint32_t fs[FEATURESET_NR_ENTRIES ],struct cpuid_policy *p) +{ + p->basic._1d = fs[FEATURESET_1d];xen/include/xen/libx86/cpuid.h line 229
Quoted 10 lines
xen/include/xen/libx86/cpuid.h +10
-0+ p->basic._1c = fs[FEATURESET_1c]; + p->extd.e1d = fs[FEATURESET_e1d]; + p->extd.e1c = fs[FEATURESET_e1c]; + p->xstate.Da1 = fs[FEATURESET_Da1]; + p->feat._7b0 = fs[FEATURESET_7b0]; + p->feat._7c0 = fs[FEATURESET_7c0]; + p->extd.e7d = fs[FEATURESET_e7d]; + p->extd.e8b = fs[FEATURESET_e8b]; + p->feat._7d0 = fs[FEATURESET_7d0]; +}I realize this is only code movement, but since you didn't answer the question raised on the Intel Process Trace thread (v2 03/10) yet, I'll raise it here again: Shouldn't other fields of p be set to zero here?
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
No - why should it?
(In fact, it very deliberately does not, and changing this will break all of the policy derivation logic.)
Did you look at the context in which I've raised the question originally?
Yes, but I still don't understand what prompted the question.
The introduction of (further) intermediate leaves without any handling.
Quoted 7 lines
Quoted 4 lines
I did in particular ask about this effectively still being a form of black listing (I said "white listing" there by mistake), just taking leaf 6 (and Intel hardware) as example.
guest_cpuid()takes whatever is there in the policy, andupdate_domain_cpuid_info()does nothing either.See the head of
recalculate_misc()which unilaterally zeroes that leaf, irrespective of toolstack settings.
Ah, I see - irrespective of its young age things are already sufficiently much scattered around so one won't always easily spot the necessary pieces.
Quoted 8 lines
Quoted 3 lines
It was my understanding that with the switch to the new model we're now strictly while listing features. Luwei's patch would extend the un-audited handing through to RDT and SGX leaves.
That is one reason why I won't ack the patch in that shape. But as I'm currently rewriting this logic for a different reason, explaining the correct steps to extend MAX_*_LEAF will cause unnecessary work for Luwei as the implementation is about to change under his feet.
Well, okay then.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 5/13 libx86: introduce a libx86 shared library
In reply to Andrew CooperFrom: Roger Pau Monné <[email protected]>
Move x86_cpuid_lookup_deep_deps() into the shared library, removing the individual copies from the hypervisor and libxc respectively.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rename libx86-private.h to just private.h
* Only vpath libx86 for CONFIG_X86 builds of libxc
--- tools/libxc/Makefile | 6 ++++++ tools/libxc/include/xenctrl.h | 1 - tools/libxc/xc_cpuid_x86.c | 29 +--------------------------- xen/arch/x86/cpu/common.c | 2 +- xen/arch/x86/cpuid.c | 32 +----------------------------- xen/common/Makefile | 1 + xen/common/libx86/Makefile | 1 + xen/common/libx86/cpuid.c | 44 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 38 ++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/cpuid.h | 2 -- xen/include/xen/libx86/cpuid.h | 2 ++ 11 files changed, 95 insertions(+), 63 deletions(-) create mode 100644 xen/common/libx86/Makefile create mode 100644 xen/common/libx86/cpuid.c create mode 100644 xen/common/libx86/private.h
tools/libxc/Makefile +6 -0
@@ -80,6 +80,12 @@ GUEST_SRCS-y += $(ELF_SRCS-y) $(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign +ifeq ($(CONFIG_X86),y) # Add libx86 to the build +vpath %.c ../../xen/common/libx86 + +GUEST_SRCS-y += cpuid.c +endif + # new domain builder GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c GUEST_SRCS-y += xc_dom_elfloader.c
tools/libxc/include/xenctrl.h +0 -1
@@ -2564,7 +2564,6 @@ enum xc_static_cpu_featuremask { XC_FEATUREMASK_DEEP_FEATURES, };const uint32_t *xc_get_static_cpu_featuremask (enum xc_static_cpu_featuremask ); -const uint32_t *xc_get_feature_deep_deps (uint32_t feature);#endif
tools/libxc/xc_cpuid_x86.c +1 -28
@@ -131,33 +131,6 @@ const uint32_t *xc_get_static_cpu_featuremask( } } -const uint32_t *xc_get_feature_deep_deps (uint32_t feature) -{ -static const struct { -uint32_t feature; -uint32_t fs[FEATURESET_NR_ENTRIES ]; - } deep_deps[] =INIT_DEEP_DEPS ; - -unsigned int start =0 , end =ARRAY_SIZE (deep_deps); - -BUILD_BUG_ON (ARRAY_SIZE (deep_deps) !=NR_DEEP_DEPS ); - -/* deep_deps[] is sorted. Perform a binary search. */ -while ( start < end ) - { -unsigned int mid = start + ((end - start) /2 ); - -if ( deep_deps[mid].feature > feature ) - end = mid; -else if ( deep_deps[mid].feature < feature ) - start = mid +1 ; -else -return deep_deps[mid].fs; - } - -return NULL ; -} -struct cpuid_domain_info { enum
@@ -677,7 +650,7 @@ static void sanitise_featureset(struct cpuid_domain_info *info)const uint32_t *dfs;if ( !test_bit (b, disabled_features) || - !(dfs =xc_get_feature_deep_deps (b)) ) + !(dfs =x86_cpuid_lookup_deep_deps (b)) )continue ;for ( i =0 ; i <ARRAY_SIZE (disabled_features); ++i )
xen/arch/x86/cpu/common.c +1 -1
@@ -62,7 +62,7 @@ void __init setup_clear_cpu_cap(unsigned int cap) __builtin_return_address(0), cap);__clear_bit (cap, boot_cpu_data.x86_capability); - dfs =lookup_deep_deps (cap); + dfs =x86_cpuid_lookup_deep_deps (cap);if (!dfs)return ;
xen/arch/x86/cpuid.c +1 -31
@@ -97,7 +97,7 @@ static void sanitise_featureset(uint32_t *fs)for_each_set_bit (i, (void *)disabled_features,sizeof (disabled_features) *8 ) { -const uint32_t *dfs =lookup_deep_deps (i); +const uint32_t *dfs =x86_cpuid_lookup_deep_deps (i);unsigned int j;ASSERT (dfs);/* deep_features[] should guarentee this. */
@@ -544,36 +544,6 @@ bool recheck_cpu_features(unsigned int cpu)return okay; } -const uint32_t *lookup_deep_deps (uint32_t feature) -{ -static const struct { -uint32_t feature; -uint32_t fs[FSCAPINTS ]; - } deep_deps[] =INIT_DEEP_DEPS ; -unsigned int start =0 , end =ARRAY_SIZE (deep_deps); - -BUILD_BUG_ON (ARRAY_SIZE (deep_deps) !=NR_DEEP_DEPS ); - -/* Fast early exit. */ -if ( !test_bit (feature, deep_features) ) -return NULL ; - -/* deep_deps[] is sorted. Perform a binary search. */ -while ( start < end ) - { -unsigned int mid = start + ((end - start) /2 ); - -if ( deep_deps[mid].feature > feature ) - end = mid; -else if ( deep_deps[mid].feature < feature ) - start = mid +1 ; -else -return deep_deps[mid].fs; - } - -return NULL ; -} -void recalculate_cpuid_policy (struct domain *d) {struct cpuid_policy *p = d->arch.cpuid;
xen/common/Makefile +1 -0
@@ -80,3 +80,4 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt +subdir-$(CONFIG_X86) += libx86
xen/common/libx86/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += cpuid.o
xen/common/libx86/cpuid.c new file +44 -0
44 lines not on this page · raw message
xen/common/libx86/private.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef XEN_LIBX86_PRIVATE_H +#define XEN_LIBX86_PRIVATE_H + +#ifdef __XEN__ + +#include <xen/bitops.h> +#include <xen/kernel.h> +#include <xen/lib.h> +#include <xen/types.h> + +#else + +#include <inttypes.h> +#include <stdbool.h> +#include <stddef.h> + +#include <xen-tools/libs.h> + +static inline bool test_bit (unsigned int bit,const void *vaddr) +{ +const char *addr = vaddr; + +return addr[bit /8 ] & (1u << (bit %8 )); +} + +#endif /* __XEN__ */ + +#endif /* XEN_LIBX86_PRIVATE_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/cpuid.h +0 -2
@@ -17,8 +17,6 @@ extern const uint32_t special_features[FSCAPINTS];void init_guest_cpuid (void ); -const uint32_t *lookup_deep_deps (uint32_t feature); -/* * Expected levelling capabilities (given cpuid vendor/family information), * and levelling capabilities actually available (given MSR probing).
xen/include/xen/libx86/cpuid.h +2 -0
@@ -228,6 +228,8 @@ static inline void cpuid_featureset_to_policy( p->feat._7d0 = fs[FEATURESET_7d0]; } +const uint32_t *x86_cpuid_lookup_deep_deps (uint32_t feature); +#endif /* !XEN_LIBX86_CPUID_H */ /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 05/13] libx86: introduce a libx86 shared library
Quoted 7 lines · Andrew Cooper
From: Roger Pau Monné <[email protected]>
Move
x86_cpuid_lookup_deep_deps()into the shared library, removing the individual copies from the hypervisor and libxc respectively.Signed-off-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 05/13] libx86: introduce a libx86 shared library
In reply to Andrew CooperQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
tools/libxc/Makefile | 6 ++++++ tools/libxc/include/xenctrl.h | 1 - tools/libxc/xc_cpuid_x86.c | 29 +--------------------------- xen/arch/x86/cpu/common.c | 2 +- xen/arch/x86/cpuid.c | 32 +----------------------------- xen/common/Makefile | 1 + xen/common/libx86/Makefile | 1 + xen/common/libx86/cpuid.c | 44 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 38 ++++++++++++++++++++++++++++++++++++
I can certainly accept libx86 headers to live in xen/include/xen/libx86/ for now if the suggested better places cause trouble, but xen/common/ is what its name says - common (i.e. architecture independent) code. This wants to go into lib/x86 or xen/lib/x86 or some such, or in the worst case under xen/arch/x86/, the more that I doubt the same issue as with the header files applies here.
Quoted 17 lines
xen/common/libx86/private.h new file +14
-0@@ -0,0 +1,38 @@ +#ifndef XEN_LIBX86_PRIVATE_H +#define XEN_LIBX86_PRIVATE_H + +#ifdef __XEN__ + +#include <xen/bitops.h> +#include <xen/kernel.h> +#include <xen/lib.h> +#include <xen/types.h> + +#else + +#include <inttypes.h> +#include <stdbool.h>
xen/common/libx86/private.h line 24
Quoted 10 lines
xen/common/libx86/private.h new file +10
-0+#include <stddef.h> + +#include <xen-tools/libs.h> + +static inline bool test_bit (unsigned int bit,const void *vaddr) +{ +const char *addr = vaddr; + +return addr[bit /8 ] & (1u << (bit %8 )); +}
There's nowhere in the tools that this could be taken from? xc_bitops.h has one - couldn't this be lifted to xen-tools/libs.h?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 05/13] libx86: introduce a libx86 shared library
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
tools/libxc/Makefile | 6 ++++++ tools/libxc/include/xenctrl.h | 1 - tools/libxc/xc_cpuid_x86.c | 29 +--------------------------- xen/arch/x86/cpu/common.c | 2 +- xen/arch/x86/cpuid.c | 32 +----------------------------- xen/common/Makefile | 1 + xen/common/libx86/Makefile | 1 + xen/common/libx86/cpuid.c | 44 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 38 ++++++++++++++++++++++++++++++++++++
Quoted 6 lines
I can certainly accept libx86 headers to live in xen/include/xen/libx86/ for now if the suggested better places cause trouble, but xen/common/ is what its name says - common (i.e. architecture independent) code. This wants to go into lib/x86 or xen/lib/x86 or some such, or in the worst case under xen/arch/x86/, the more that I doubt the same issue as with the header files applies here.
The C files are trivial to move in comparison to the header files. All that needs changing is the single vpath in libxc's build.
I'll move the C files into xen/lib/x86/
Quoted 22 lines
Quoted 22 lines
xen/common/libx86/private.h new file +18
-0@@ -0,0 +1,38 @@ +#ifndef XEN_LIBX86_PRIVATE_H +#define XEN_LIBX86_PRIVATE_H + +#ifdef __XEN__ + +#include <xen/bitops.h> +#include <xen/kernel.h> +#include <xen/lib.h> +#include <xen/types.h> + +#else + +#include <inttypes.h> +#include <stdbool.h> +#include <stddef.h> + +#include <xen-tools/libs.h> +
Quoted 8 lines
xen/common/libx86/private.h line 24
Quoted 6 lines
xen/common/libx86/private.h new file +6
-0+static inline bool test_bit (unsigned int bit,const void *vaddr) +{ +const char *addr = vaddr; + +return addr[bit /8 ] & (1u << (bit %8 )); +}There's nowhere in the tools that this could be taken from?
xc_bitops.hhas one - couldn't this be lifted toxen-tools/libs.h?
There are already 2 different copies in tools, with different APIs, and adding this into xen-tools/libs.h broke the build in more complicated ways than I have time to fix at this point.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [PATCH v2 05/13] libx86: introduce a libx86 shared library
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 12:35, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
tools/libxc/Makefile | 6 ++++++ tools/libxc/include/xenctrl.h | 1 - tools/libxc/xc_cpuid_x86.c | 29 +--------------------------- xen/arch/x86/cpu/common.c | 2 +- xen/arch/x86/cpuid.c | 32 +----------------------------- xen/common/Makefile | 1 + xen/common/libx86/Makefile | 1 + xen/common/libx86/cpuid.c | 44++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
Quoted 1 line
xen/common/libx86/private.h | 38 ++++++++++++++++++++++++++++++++++++I can certainly accept libx86 headers to live in xen/include/xen/libx86/ for now if the suggested better places cause trouble, but xen/common/ is what its name says - common (i.e. architecture independent) code. This wants to go into lib/x86 or xen/lib/x86 or some such, or in the worst case under xen/arch/x86/, the more that I doubt the same issue as with the header files applies here.
Quoted 4 lines
The C files are trivial to move in comparison to the header files. All that needs changing is the single vpath in libxc's build.
I'll move the C files into xen/lib/x86/
Thanks, and with that then
Quoted 30 lines
Quoted 21 lines
Quoted 21 lines
xen/common/libx86/private.h new file +18
-0@@ -0,0 +1,38 @@ +#ifndef XEN_LIBX86_PRIVATE_H +#define XEN_LIBX86_PRIVATE_H + +#ifdef __XEN__ + +#include <xen/bitops.h> +#include <xen/kernel.h> +#include <xen/lib.h> +#include <xen/types.h> + +#else + +#include <inttypes.h> +#include <stdbool.h> +#include <stddef.h> + +#include <xen-tools/libs.h> +Quoted 8 lines
xen/common/libx86/private.h line 24
Quoted 6 lines
xen/common/libx86/private.h new file +6
-0+static inline bool test_bit (unsigned int bit,const void *vaddr) +{ +const char *addr = vaddr; + +return addr[bit /8 ] & (1u << (bit %8 )); +}There's nowhere in the tools that this could be taken from?
xc_bitops.hhas one - couldn't this be lifted toxen-tools/libs.h?
Quoted 3 lines
There are already 2 different copies in tools, with different APIs, and adding this into
xen-tools/libs.hbroke the build in more complicated ways than I have time to fix at this point.
Oh, ouch.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/13 libx86: Introduce libx86/msr.h and share msr_policy with userspace
In reply to Andrew CooperTo facilitate the shared Xen and toolstack code in libx86, struct msr_policy needs to be available in the same way as struct cpuid_policy.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rebase over the msr_{domain,vcpu}_policy rename
* Don't move vcpu_msrs into libx86
--- tools/libxc/xc_cpuid_x86.c | 1 + xen/include/asm-x86/msr.h | 23 +++-------------------- xen/include/xen/libx86/msr.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 xen/include/xen/libx86/msr.h
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -33,6 +33,7 @@ enum { };#include <xen/libx86/cpuid.h> +#include <xen/libx86/msr.h> #define bitmaskof (idx) (1u << ((idx) & 31))#define featureword_of (idx) ((idx) >> 5)
xen/include/asm-x86/msr.h +3 -20
@@ -8,6 +8,9 @@#include <xen/types.h> #include <xen/percpu.h> #include <xen/errno.h> + +#include <xen/libx86/msr.h> +#include <asm/asm_defns.h> #include <asm/cpufeature.h>
@@ -257,26 +260,6 @@ static inline void wrmsr_tsc_aux(uint32_t val) } } -/* MSR policy object for shared per-domain MSRs */ -struct msr_policy -{ -/* -* 0x000000ce - MSR_INTEL_PLATFORM_INFO -* -* This MSR is non-architectural, but for simplicy we allow it to be read -* unconditionally. CPUID Faulting support can be fully emulated for HVM -* guests so can be offered unconditionally, while support for PV guests -* is dependent on real hardware support. -*/ -union { -uint32_t raw; -struct { - uint32_t :31; -bool cpuid_faulting:1 ; - }; - } plaform_info; -}; -extern struct msr_policy raw_msr_policy, host_msr_policy, hvm_max_msr_policy,
xen/include/xen/libx86/msr.h new file +35 -0
@@ -0,0 +1,35 @@ +/* Common data structures and functions consumed by hypervisor and toolstack */ +#ifndef XEN_LIBX86_MSR_H +#define XEN_LIBX86_MSR_H + +/* MSR policy object for shared per-domain MSRs */ +struct msr_policy +{ +/* +* 0x000000ce - MSR_INTEL_PLATFORM_INFO +* +* This MSR is non-architectural, but for simplicy we allow it to be read +* unconditionally. CPUID Faulting support can be fully emulated for HVM +* guests so can be offered unconditionally, while support for PV guests +* is dependent on real hardware support. +*/ +union { +uint32_t raw; +struct { + uint32_t :31; +bool cpuid_faulting:1 ; + }; + } plaform_info; +}; + +#endif /* !XEN_LIBX86_MSR_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 06/13] libx86: Introduce libx86/msr.h and share msr_policy with userspace
Quoted 5 lines · Andrew Cooper
To facilitate the shared Xen and toolstack code in libx86, struct
msr_policyneeds to be available in the same way as structcpuid_policy.Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 06/13] libx86: Introduce libx86/msr.h and share msr_policy with userspace
In reply to Andrew CooperQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
To facilitate the shared Xen and toolstack code in libx86, struct
msr_policyneeds to be available in the same way as structcpuid_policy.Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 7/13 libx86: Introduce a helper to serialise cpuid_policy objects
In reply to Andrew CooperThe serialised form is made up of the leaf, subleaf and data tuple. As this is the architectural form, it is expected not to change going forwards.
The serialisation of the Xen/Viridian leaves isn't fully implemented yet. It is just enough to be bug-compatible with the current DOMCTL_set_cpuid behaviour, but needs further hypervisor work before the toolstack can sensibly control these values.
x86_cpuid_copy_to_buffer() is implemented using Xen's regular copy_to_guest primitives, with an API-compatible memcpy() is used for the libxc half of the build.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Move MIN() into xen-tools/libs.h.
* Leave a TODO for the Xen/Viridian leaf infrastructure, and update the commit message.
* Rewrite copy_to_buffer_offset() to avoid multiple evaluation of its parameters.
* Change to an array typedef for constness reasons
--- tools/include/xen-tools/libs.h | 4 ++ tools/xenstore/xenstored_core.h | 2 - xen/common/libx86/cpuid.c | 90 +++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 18 ++++++++ xen/include/public/arch-x86/xen.h | 11 +++++ xen/include/xen/libx86/cpuid.h | 30 +++++++++++++ 6 files changed, 153 insertions(+), 2 deletions(-)
tools/include/xen-tools/libs.h +4 -0
@@ -17,4 +17,8 @@#define MAX (x, y) ((x) > (y) ? (x) : (y))#endif +#ifndef MIN +#define MIN (x, y) ((x) < (y) ? (x) : (y)) +#endif +#endif /* __XEN_TOOLS_LIBS__ */
tools/xenstore/xenstored_core.h +0 -2
@@ -37,8 +37,6 @@/* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */ #define DEFAULT_BUFFER_SIZE 16 -#define MIN (a, b) (((a) < (b))? (a) : (b)) -typedef int32_t wrl_creditt ;#define WRL_CREDIT_MAX (1000*1000*1000)/* ^ satisfies non-overflow condition for wrl_xfer_credit */
xen/common/libx86/cpuid.c +90 -0
96 lines not on this page · raw message
xen/common/libx86/private.h +18 -0
@@ -8,8 +8,13 @@#include <xen/lib.h> #include <xen/types.h> +#include <asm/guest_access.h> + +#define copy_to_buffer_offset copy_to_guest_offset +#else +#include <errno.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h>
@@ -23,6 +28,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)return addr[bit /8 ] & (1u << (bit %8 )); } +/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset (dst, index, src, nr) \ +({ \ + const typeof(*(dst)) *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; \ +}) +#endif /* __XEN__ */ #endif /* XEN_LIBX86_PRIVATE_H */
xen/include/public/arch-x86/xen.h +11 -0
@@ -314,6 +314,17 @@ struct xen_arch_domainconfig {#define XEN_ACPI_GPE0_CPUHP_BIT 2#endif +/* +* Representations of architectural CPUID information. Used as the +* serialised version of Xen's internal representation. +*/ +typedef struct xen_cpuid_leaf { +#define XEN_CPUID_NO_SUBLEAF 0xffffffffu +uint32_t leaf, subleaf; +uint32_t a, b, c, d; +}xen_cpuid_leaf_t ; +DEFINE_XEN_GUEST_HANDLE (xen_cpuid_leaf_t); +#endif /* !__ASSEMBLY__ */ /*
xen/include/xen/libx86/cpuid.h +30 -0
@@ -30,6 +30,19 @@ struct cpuid_leaf#define CPUID_GUEST_NR_EXTD MAX(CPUID_GUEST_NR_EXTD_INTEL, \ CPUID_GUEST_NR_EXTD_AMD) +/* +* Maximum number of leaves a struct cpuid_policy turns into when serialised +* for interaction with the toolstack. (Sum of all leaves in each union, less +* the entries in basic which sub-unions hang off of.) +*/ +#define CPUID_MAX_SERIALISED_LEAVES \ + (CPUID_GUEST_NR_BASIC + \ + CPUID_GUEST_NR_FEAT - !!CPUID_GUEST_NR_FEAT + \ + CPUID_GUEST_NR_CACHE - !!CPUID_GUEST_NR_CACHE + \ + CPUID_GUEST_NR_TOPO - !!CPUID_GUEST_NR_TOPO + \ + CPUID_GUEST_NR_XSTATE - !!CPUID_GUEST_NR_XSTATE + \ + CPUID_GUEST_NR_EXTD + 2 /* hv_limit and hv2_limit */ ) + struct cpuid_policy {#define DECL_BITFIELD (word) _DECL_BITFIELD(FEATURESET_ ## word)
@@ -230,6 +243,23 @@ static inline void cpuid_featureset_to_policy(const uint32_t *x86_cpuid_lookup_deep_deps (uint32_t feature); +#ifdef __XEN__ +#include <public/arch-x86/xen.h> +typedef XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t)cpuid_leaf_buffer_t ; +#else +#include <xen/arch-x86/xen.h> +typedef xen_cpuid_leaf_t cpuid_leaf_buffer_t []; +#endif + +/* +* Serialise a cpuid_policy object into an array. Writes at most +* CPUID_MAX_SERIALISED_LEAVES. On success, nr_entries_p is updated with the +* actual number of leaves written. +*/ +int x86_cpuid_copy_to_buffer (const struct cpuid_policy *p, +cpuid_leaf_buffer_t leaves, +uint32_t *nr_entries_p); +#endif /* !XEN_LIBX86_CPUID_H */ /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 34
Quoted 12 lines · Andrew Cooper
xen/common/libx86/private.h +5
-0+#include <errno.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -23,6 +28,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)return addr[bit /8 ] & (1u << (bit %8 )); } +/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset (dst, index, src, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \
I think you mean typeof(*(src)) here?
Otherwise:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:18, <[email protected]> wrote:
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void
Quoted 5 lines · Andrew Cooper
xen/common/libx86/private.h +1
-0+#include <errno.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -23,6 +28,19 @@ static inline bool test_bit(unsigned int bit, const void*vaddr)
Quoted 3 lines
xen/common/libx86/private.h +0
-0return addr[bit /8 ] & (1u << (bit %8 )); }
Quoted 6 lines
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 34
Quoted 4 lines
xen/common/libx86/private.h +4
-0+/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset (dst, index, src, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \I think you mean typeof(*(src)) here?
To follow copy_to_guest_offset()'s model there's more needed here, I think: dst and src want to point to similar type objects / arrays (i.e. the macro wants to enforce this).
I also notice that some of the now-local-variables are now pointlessly parenthesized.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:18, <[email protected]> wrote:
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void
Quoted 5 lines · Andrew Cooper
xen/common/libx86/private.h +1
-0+#include <errno.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -23,6 +28,19 @@ static inline bool test_bit(unsigned int bit, const void*vaddr)
Quoted 3 lines
xen/common/libx86/private.h +0
-0return addr[bit /8 ] & (1u << (bit %8 )); }
Quoted 8 lines
Quoted 5 lines
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 34
Quoted 4 lines
xen/common/libx86/private.h +4
-0+/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset (dst, index, src, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \I think you mean typeof(*(src)) here?
To follow copy_to_guest_offset()'s model there's more needed here, I think: dst and src want to point to similar type objects / arrays (i.e. the macro wants to enforce this).
This wrapper needs to be just enough to compile for userspace. It doesn't need all the features and misfeatures of the hypervisor implementation.
Remember that the code gets compiled twice, so there is no chance of errors actually slipping in.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 12:39, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 11:18, <[email protected]> wrote:
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void
Quoted 5 lines · Andrew Cooper
xen/common/libx86/private.h +1
-0+#include <errno.h> #include <inttypes.h> #include <stdbool.h> #include <stddef.h> @@ -23,6 +28,19 @@ static inline bool test_bit(unsigned int bit, const void*vaddr)
Quoted 3 lines
xen/common/libx86/private.h +0
-0return addr[bit /8 ] & (1u << (bit %8 )); }Quoted 8 lines
Quoted 5 lines
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 34
Quoted 4 lines
xen/common/libx86/private.h +4
-0+/* memcpy(), but with copy_to_guest_offset()'s API. */ +#define copy_to_buffer_offset (dst, index, src, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \I think you mean typeof(*(src)) here?
To follow copy_to_guest_offset()'s model there's more needed here, I think: dst and src want to point to similar type objects / arrays (i.e. the macro wants to enforce this).
Quoted 6 lines
This wrapper needs to be just enough to compile for userspace. It doesn't need all the features and misfeatures of the hypervisor implementation.
Remember that the code gets compiled twice, so there is no chance of errors actually slipping in.
Well, yes, people would certainly be expected to test both parts of the build before submitting a change. But someone focusing on the hypervisor might not always re-build the tools after each step (or respectively vice versa), yet it would be nice if an issue was noticable right away even when doing just one of the two builds.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
In reply to Andrew CooperQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/cpuid.c +7
-0+int x86_cpuid_copy_to_buffer (const struct cpuid_policy *p, +cpuid_leaf_buffer_t leaves, +uint32_t *nr_entries_p) +{ +const uint32_t nr_entries = *nr_entries_p; +uint32_t curr_entry =0 , leaf, subleaf; +
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 76
Quoted 10 lines
xen/common/libx86/cpuid.c +10
-0+#define COPY_LEAF (l, s, data) \ + ({ int ret; \ + if ( (ret = copy_leaf_to_buffer( \ + l, s, data, leaves, &curr_entry, nr_entries)) ) \ + return ret; \ + }) + +/* Basic leaves. */ +for ( leaf =0 ; leaf <=MIN (p->basic.max_leaf, +ARRAY_SIZE (p->basic.raw) -1 ); ++leaf )
Here and ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 82
Quoted 6 lines
xen/common/libx86/cpuid.c +6
-0+ { +switch ( leaf ) + { +case 0x4 : +for ( subleaf =0 ; subleaf <ARRAY_SIZE (p->cache.raw); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->cache.raw[subleaf]);
... here ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 89
Quoted 7 lines
xen/common/libx86/cpuid.c +7
-0+break ; + +case 0x7 : +for ( subleaf =0 ; + subleaf <=MIN (p->feat.max_subleaf, +ARRAY_SIZE (p->feat.raw) -1 ); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->feat.raw[subleaf]);
... but even more importantly here I wonder whether some form(s) of for_each_...() wouldn't be helpful to introduce: Such constructs are a prime source of future copy-and-past mistakes, perhaps just missing a single of the distinguishing field names. If there was exactly one instance of those field names, that risk would imo be much reduced.
For example (completely untested)
#define for_each_subleaf(which, limit) \
for ( subleaf = 0; subleaf <= MIN(limit, ARRAY_SIZE(p->which.raw) - 1); ++subleaf )
COPY_LEAF(leaf, subleaf, p->which.raw[subleaf]);albeit I realize that the specification of "limit" would then still require an open-coded use of "which", and I have no good idea how to avoid it.
Other than the hope for some improvement there (and if nothing half way reasonable turns up, then that'll too be fine for now) there's only the previously given comment on copy_to_buffer_offset() here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
Quoted 43 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/cpuid.c +7
-0+int x86_cpuid_copy_to_buffer (const struct cpuid_policy *p, +cpuid_leaf_buffer_t leaves, +uint32_t *nr_entries_p) +{ +const uint32_t nr_entries = *nr_entries_p; +uint32_t curr_entry =0 , leaf, subleaf; +xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 76
Quoted 10 lines
xen/common/libx86/cpuid.c +10
-0+#define COPY_LEAF (l, s, data) \ + ({ int ret; \ + if ( (ret = copy_leaf_to_buffer( \ + l, s, data, leaves, &curr_entry, nr_entries)) ) \ + return ret; \ + }) + +/* Basic leaves. */ +for ( leaf =0 ; leaf <=MIN (p->basic.max_leaf, +ARRAY_SIZE (p->basic.raw) -1 ); ++leaf )Here and ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 82
Quoted 6 lines
xen/common/libx86/cpuid.c +6
-0+ { +switch ( leaf ) + { +case 0x4 : +for ( subleaf =0 ; subleaf <ARRAY_SIZE (p->cache.raw); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->cache.raw[subleaf]);... here ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 89
Quoted 7 lines
xen/common/libx86/cpuid.c +7
-0+break ; + +case 0x7 : +for ( subleaf =0 ; + subleaf <=MIN (p->feat.max_subleaf, +ARRAY_SIZE (p->feat.raw) -1 ); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->feat.raw[subleaf]);... but even more importantly here I wonder whether some form(s) of for_each_...() wouldn't be helpful to introduce: Such constructs are a prime source of future copy-and-past mistakes, perhaps just missing a single of the distinguishing field names. If there was exactly one instance of those field names, that risk would imo be much reduced.
For example (completely untested)
Quoted 7 lines
#define for_each_subleaf(which, limit) \ for ( subleaf = 0; subleaf <= MIN(limit, ARRAY_SIZE(p->which.raw) - 1); ++subleaf ) COPY_LEAF(leaf, subleaf, p->which.raw[subleaf]);albeit I realize that the specification of "limit" would then still require an open-coded use of "which", and I have no good idea how to avoid it.
This pattern shows up in several locations, but in addition to the problems you've found here, such a construct would be even harder for p->extd.max_leaf which has to account for truncating the top bits out of the limit.
I already tried, and failed, to come up with a reasonable way to encapsulate this. The CPUID leaves aren't actually as consistent as they appear at a first glance.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects
Quoted 50 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 12:02, <[email protected]> wrote:
Quoted 41 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/cpuid.c +7
-0+int x86_cpuid_copy_to_buffer (const struct cpuid_policy *p, +cpuid_leaf_buffer_t leaves, +uint32_t *nr_entries_p) +{ +const uint32_t nr_entries = *nr_entries_p; +uint32_t curr_entry =0 , leaf, subleaf; +xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 76
Quoted 10 lines
xen/common/libx86/cpuid.c +10
-0+#define COPY_LEAF (l, s, data) \ + ({ int ret; \ + if ( (ret = copy_leaf_to_buffer( \ + l, s, data, leaves, &curr_entry, nr_entries)) ) \ + return ret; \ + }) + +/* Basic leaves. */ +for ( leaf =0 ; leaf <=MIN (p->basic.max_leaf, +ARRAY_SIZE (p->basic.raw) -1 ); ++leaf )Here and ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 82
Quoted 6 lines
xen/common/libx86/cpuid.c +6
-0+ { +switch ( leaf ) + { +case 0x4 : +for ( subleaf =0 ; subleaf <ARRAY_SIZE (p->cache.raw); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->cache.raw[subleaf]);... here ...
xen/common/libx86/cpuid.c const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) · line 89
Quoted 7 lines
xen/common/libx86/cpuid.c +7
-0+break ; + +case 0x7 : +for ( subleaf =0 ; + subleaf <=MIN (p->feat.max_subleaf, +ARRAY_SIZE (p->feat.raw) -1 ); ++subleaf ) +COPY_LEAF (leaf, subleaf, &p->feat.raw[subleaf]);... but even more importantly here I wonder whether some form(s) of for_each_...() wouldn't be helpful to introduce: Such constructs are a prime source of future copy-and-past mistakes, perhaps just missing a single of the distinguishing field names. If there was exactly one instance of those field names, that risk would imo be much reduced.
Quoted 4 lines
For example (completely untested)
#define for_each_subleaf(which, limit) \ for ( subleaf = 0; subleaf <= MIN(limit, ARRAY_SIZE(p->which.raw) - 1);++subleaf )
Quoted 2 lines
COPY_LEAF(leaf, subleaf, p->which.raw[subleaf]);
Quoted 8 lines
Quoted 3 lines
albeit I realize that the specification of "limit" would then still require an open-coded use of "which", and I have no good idea how to avoid it.
This pattern shows up in several locations, but in addition to the problems you've found here, such a construct would be even harder for
p->extd.max_leafwhich has to account for truncating the top bits out of the limit.
Dropping the top bits could be done universally, e.g. by AND-ing the leaf with 0xffff.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 8/13 libx86: Introduce a helper to serialise msr_policy objects
In reply to Andrew CooperFrom: Roger Pau Monné <[email protected]>
As with CPUID, an architectural form is used for representing the MSR data. It is expected not to change moving forwards, but does have a 32 bit field (currently reserved) which can be used compatibly if needs be.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rebase over the msr_{domain,vcpu}_policy rename
* Only serialise msr_policy
* Change to an array typedef for constness reasons
--- tools/libxc/Makefile | 2 +- xen/common/libx86/Makefile | 1 + xen/common/libx86/msr.c | 56 +++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 3 +++ xen/include/public/arch-x86/xen.h | 9 ++++++- xen/include/xen/libx86/msr.h | 20 ++++++++++++++ 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 xen/common/libx86/msr.c
tools/libxc/Makefile +1 -1
@@ -83,7 +83,7 @@ $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign ifeq ($(CONFIG_X86),y) # Add libx86 to the build vpath %.c ../../xen/common/libx86 -GUEST_SRCS-y += cpuid.c +GUEST_SRCS-y += cpuid.c msr.c endif # new domain builder
xen/common/libx86/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += cpuid.o +obj-y += msr.o
xen/common/libx86/msr.c new file +56 -0
56 lines not on this page · raw message
xen/common/libx86/private.h +3 -0
@@ -9,6 +9,7 @@#include <xen/types.h> #include <asm/guest_access.h> +#include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset
@@ -19,6 +20,8 @@#include <stdbool.h> #include <stddef.h> +#include <xen/asm/msr-index.h> +#include <xen-tools/libs.h> static inline bool test_bit (unsigned int bit,const void *vaddr)
xen/include/public/arch-x86/xen.h +8 -1
@@ -315,7 +315,7 @@ struct xen_arch_domainconfig {#endif /* -* Representations of architectural CPUID information. Used as the +* Representations of architectural CPUID and MSR information. Used as the * serialised version of Xen's internal representation. */ typedef struct xen_cpuid_leaf {
@@ -325,6 +325,13 @@ typedef struct xen_cpuid_leaf { } xen_cpuid_leaf_t;DEFINE_XEN_GUEST_HANDLE (xen_cpuid_leaf_t); +typedef struct xen_msr_entry { +uint32_t idx; +uint32_t flags;/* Reserved MBZ. */ +uint64_t val; +}xen_msr_entry_t ; +DEFINE_XEN_GUEST_HANDLE (xen_msr_entry_t); +#endif /* !__ASSEMBLY__ */ /*
xen/include/xen/libx86/msr.h +20 -0
@@ -2,6 +2,9 @@#ifndef XEN_LIBX86_MSR_H #define XEN_LIBX86_MSR_H +/* Maximum number of MSRs written when serialising msr_domain_policy. */ +#define MSR_MAX_SERIALISED_ENTRIES 1 +/* MSR policy object for shared per-domain MSRs */ struct msr_policy {
@@ -22,6 +25,23 @@ struct msr_policy } plaform_info; }; +#ifdef __XEN__ +#include <public/arch-x86/xen.h> +typedef XEN_GUEST_HANDLE_64 (xen_msr_entry_t)msr_entry_buffer_t ; +#else +#include <xen/arch-x86/xen.h> +typedef xen_msr_entry_t msr_entry_buffer_t []; +#endif + +/* +* Serialise a msr_policy object into an array. Writes at most +* MSR_MAX_SERIALISED_ENTRIES. Returns -ENOBUFS if the buffer array is too +* short. On success, nr_entries_p is updated with the actual number of +* leaves written. +*/ +int x86_msr_copy_to_buffer (const struct msr_policy *p, +msr_entry_buffer_t msrs,uint32_t *nr_entries_p); +#endif /* !XEN_LIBX86_MSR_H */ /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 08/13] libx86: Introduce a helper to serialise msr_policy objects
Quoted 9 lines · Andrew Cooper
From: Roger Pau Monné <[email protected]>
As with CPUID, an architectural form is used for representing the MSR data. It is expected not to change moving forwards, but does have a 32 bit field (currently reserved) which can be used compatibly if needs be.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 08/13] libx86: Introduce a helper to serialise msr_policy objects
In reply to Andrew CooperQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
From: Roger Pau Monné <[email protected]>
As with CPUID, an architectural form is used for representing the MSR data. It is expected not to change moving forwards, but does have a 32 bit field (currently reserved) which can be used compatibly if needs be.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 9/13 libx86: Introduce a helper to deserialise cpuid_policy objects
In reply to Andrew CooperAs with the serialise side, Xen's copy_from_guest API is used, with a compatibility wrapper for the userspace build.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rewrite copy_from_buffer_offset() to avoid multiple evaluation of its arguments.
* Expand boundary justifications.
--- xen/common/libx86/cpuid.c | 94 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 14 +++++++ xen/include/xen/libx86/cpuid.h | 11 +++++ 3 files changed, 119 insertions(+)
xen/common/libx86/cpuid.c +94 -0
@@ -123,6 +123,100 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,return 0 ; } +int x86_cpuid_copy_from_buffer (struct cpuid_policy *p, +const cpuid_leaf_buffer_t leaves, +uint32_t nr_leaves,uint32_t *err_leaf, +uint32_t *err_subleaf) +{ +unsigned int i; +xen_cpuid_leaf_t data; +struct cpuid_leaf *l = (void *)&data.a; + +/* +* A well formed caller is expected pass an array with leaves in order, +* and without any repetitions. However, due to per-vendor differences, +* and in the case of upgrade or levelled scenarios, we typically expect +* fewer than MAX leaves to be passed. +* +* Detecting repeated entries is prohibitively complicated, so we don't +* bother. That said, one way or another if more than MAX leaves are +* passed, something is wrong. +*/ +if ( nr_leaves >CPUID_MAX_SERIALISED_LEAVES ) +return -E2BIG ; + +for ( i =0 ; i < nr_leaves; ++i ) + { +if (copy_from_buffer_offset (&data, leaves, i,1 ) ) +return -EFAULT ; + +switch ( data.leaf ) + { + case 0 ... ARRAY_SIZE(p->basic.raw) - 1: +switch ( data.leaf ) + { +case 0x4 : +if ( data.subleaf >=ARRAY_SIZE (p->cache.raw) ) + goto out_of_range; + + p->cache.raw[data.subleaf] = *l; +break ; + +case 0x7 : +if ( data.subleaf >=ARRAY_SIZE (p->feat.raw) ) + goto out_of_range; + + p->feat.raw[data.subleaf] = *l; +break ; + +case 0xb : +if ( data.subleaf >=ARRAY_SIZE (p->topo.raw) ) + goto out_of_range; + + p->topo.raw[data.subleaf] = *l; +break ; + +case 0xd : +if ( data.subleaf >=ARRAY_SIZE (p->xstate.raw) ) + goto out_of_range; + + p->xstate.raw[data.leaf] = *l; +break ; + +default : + p->basic.raw[data.leaf] = *l; +break ; + } +break ; + +case 0x40000000 : + p->hv_limit = l->a; +break ; + +case 0x40000100 : + p->hv2_limit = l->a; +break ; + + case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1: + p->extd.raw[data.leaf &0xffff ] = *l; +break ; + +default : + goto out_of_range; + } + } + +return 0 ; + + out_of_range: +if ( err_leaf ) + *err_leaf = data.leaf; +if ( err_subleaf ) + *err_subleaf = data.subleaf; + +return -ERANGE ; +} +/* * Local variables: * mode: C
xen/common/libx86/private.h +14 -0
@@ -12,6 +12,7 @@#include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset +#define copy_from_buffer_offset copy_from_guest_offset#else
@@ -44,6 +45,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)0 ; \ }) +/* memcpy(), but with copy_from_guest_offset()'s API. */ +#define copy_from_buffer_offset (dst, src, index, nr) \ +({ \ + const typeof(*(dst)) *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_LIBX86_PRIVATE_H */
xen/include/xen/libx86/cpuid.h +11 -0
@@ -260,6 +260,17 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,cpuid_leaf_buffer_t leaves, uint32_t *nr_entries_p); +/* +* Copy CPUID data from a buffer, filling in a cpuid_policy object. Performs +* boudary checking of the incomming leaves before filling the appropriate +* policy unions, but no content validation is performed. On an error, the +* optional err_* pointers may help identify where the issue lies. +*/ +int x86_cpuid_copy_from_buffer (struct cpuid_policy *p, +const cpuid_leaf_buffer_t leaves, +uint32_t nr_leaves,uint32_t *err_leaf, +uint32_t *err_subleaf); +#endif /* !XEN_LIBX86_CPUID_H */ /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 09/13] libx86: Introduce a helper to deserialise cpuid_policy objects
Quoted 48 lines · Andrew Cooper
As with the serialise side, Xen's
copy_from_guestAPI is used, with a compatibility wrapper for the userspace build.Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>v2:
* Rewritecopy_from_buffer_offset()to avoid multiple evaluation of its arguments.
* Expand boundary justifications.--- xen/common/libx86/cpuid.c | 94 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 14 +++++++ xen/include/xen/libx86/cpuid.h | 11 +++++ 3 files changed, 119 insertions(+)xen/common/libx86/cpuid.c +1
-0@@ -123,6 +123,100 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,return 0 ; } +/* * Local variables: * mode: C xen/common/libx86/private.h +1
-0@@ -12,6 +12,7 @@#include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset +#define copy_from_buffer_offset copy_from_guest_offset#else
xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 51
Quoted 7 lines
xen/common/libx86/private.h +4
-0@@ -44,6 +45,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)0 ; \ }) +/* memcpy(), but with copy_from_guest_offset()'s API. */ +#define copy_from_buffer_offset (dst, src, index, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \
Same issue as previous patch here. Also enforcing dst_ and src_ are of the same type would be good.
Otherwise:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 09/13] libx86: Introduce a helper to deserialise cpuid_policy objects
Quoted 59 lines · Wei Liu
Quoted 48 lines · Andrew Cooper
As with the serialise side, Xen's
copy_from_guestAPI is used, with a compatibility wrapper for the userspace build.Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>v2:
* Rewritecopy_from_buffer_offset()to avoid multiple evaluation of its arguments.
* Expand boundary justifications.--- xen/common/libx86/cpuid.c | 94 ++++++++++++++++++++++++++++++++++++++++++ xen/common/libx86/private.h | 14 +++++++ xen/include/xen/libx86/cpuid.h | 11 +++++ 3 files changed, 119 insertions(+)xen/common/libx86/cpuid.c +1
-0@@ -123,6 +123,100 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,return 0 ; } +/* * Local variables: * mode: C xen/common/libx86/private.h +1
-0@@ -12,6 +12,7 @@#include <asm/msr-index.h> #define copy_to_buffer_offset copy_to_guest_offset +#define copy_from_buffer_offset copy_from_guest_offset#else xen/common/libx86/private.h static inline bool test_bit(unsigned int bit, const void *vaddr) · line 51
Quoted 7 lines
xen/common/libx86/private.h +4
-0@@ -44,6 +45,19 @@ static inline bool test_bit(unsigned int bit, const void *vaddr)0 ; \ }) +/* memcpy(), but with copy_from_guest_offset()'s API. */ +#define copy_from_buffer_offset (dst, src, index, nr) \ +({ \ + const typeof(*(dst)) *src_ = (src); \Same issue as previous patch here. Also enforcing
dst_andsrc_are of the same type would be good.
Quoted 3 lines
Otherwise:
Reviewed-by Wei Liu <[email protected]>
The use of dst *is* the enforcement of them being the same type.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 10/13 libx86: introduce a helper to deserialise msr_policy objects
In reply to Andrew CooperFrom: Roger Pau Monné <[email protected]>
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Rebase over the msr_{domain,vcpu}_policy rename
* Only deserialse msr_policy
* Expand boundary justifications
--- xen/common/libx86/msr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/libx86/msr.h | 10 +++++++++ 2 files changed, 61 insertions(+)
xen/common/libx86/msr.c +51 -0
@@ -45,6 +45,57 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,return 0 ; } +int x86_msr_copy_from_buffer (struct msr_policy *p, +const msr_entry_buffer_t msrs,uint32_t nr_msrs, +uint32_t *err_msr) +{ +unsigned int i; +xen_msr_entry_t data; + +/* +* A well formed caller is expected pass an array with entries in order, +* and without any repetitions. However, due to per-vendor differences, +* and in the case of upgrade or levelled scenarios, we typically expect +* fewer than MAX entries to be passed. +* +* Detecting repeated entries is prohibitively complicated, so we don't +* bother. That said, one way or another if more than MAX entries are +* passed, something is wrong. +*/ +if ( nr_msrs >MSR_MAX_SERIALISED_ENTRIES ) +return -E2BIG ; + +for ( i =0 ; i < nr_msrs; i++ ) + { +if (copy_from_buffer_offset (&data, msrs, i,1 ) ) +return -EFAULT ; + +if ( data.flags )/* .flags MBZ */ + goto err; + +switch ( data.idx ) + { +case MSR_INTEL_PLATFORM_INFO : +if ( data.val > ~0u ) + goto err; + + p->plaform_info.raw = data.val; +break ; + +default : + goto err; + } + } + +return 0 ; + + err: +if ( err_msr ) + *err_msr = data.idx; + +return -EINVAL ; +} +/* * Local variables: * mode: C
xen/include/xen/libx86/msr.h +10 -0
@@ -42,6 +42,16 @@ typedef xen_msr_entry_t msr_entry_buffer_t[];int x86_msr_copy_to_buffer (const struct msr_policy *p,msr_entry_buffer_t msrs,uint32_t *nr_entries_p); +/* +* Copy MSR data from a buffer, filling an msr_policy object. MSR indicies +* are checked for being in range, but no content validation is performed for +* in-range MSRs. On an error, the optional err_* pointer may help identify +* where the issue lies. +*/ +int x86_msr_copy_from_buffer (struct msr_policy *dp, +const msr_entry_buffer_t msrs,uint32_t nr_msrs, +uint32_t *err_msr); +#endif /* !XEN_LIBX86_MSR_H */ /*
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
Quoted 5 lines · Andrew Cooper
From: Roger Pau Monné <[email protected]>
Signed-off-by Sergey Dyasli <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
In reply to Andrew CooperQuoted 29 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/msr.c +22
-0@@ -45,6 +45,57 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,return 0 ; } +int x86_msr_copy_from_buffer (struct msr_policy *p, +const msr_entry_buffer_t msrs,uint32_t nr_msrs, +uint32_t *err_msr) +{ +unsigned int i; +xen_msr_entry_t data; + +/* +* A well formed caller is expected pass an array with entries in order, +* and without any repetitions. However, due to per-vendor differences, +* and in the case of upgrade or levelled scenarios, we typically expect +* fewer than MAX entries to be passed. +* +* Detecting repeated entries is prohibitively complicated, so we don't +* bother. That said, one way or another if more than MAX entries are +* passed, something is wrong. +*/ +if ( nr_msrs >MSR_MAX_SERIALISED_ENTRIES ) +return -E2BIG ; + +for ( i =0 ; i < nr_msrs; i++ ) + {
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 79
Quoted 10 lines
xen/common/libx86/msr.c +10
-0+if (copy_from_buffer_offset (&data, msrs, i,1 ) ) +return -EFAULT ; + +if ( data.flags )/* .flags MBZ */ + goto err; + +switch ( data.idx ) + { +case MSR_INTEL_PLATFORM_INFO : +if ( data.val > ~0u )
I suppose this is to guard against truncation. I think it would be more obvious (and future proof) if you used (typeof(p->plaform_info.raw))~0, or an intermediate variable of that type, or data.val >> (sizeof(p->plaform_info.raw) * 8), some of which would likely even trigger a compiler warning once the policy field was grown to uint64_t.
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 82
Quoted 3 lines
xen/common/libx86/msr.c +3
-0+ goto err; + + p->plaform_info.raw = data.val;
No other sanity checking? If the implication is that the policy stored into isn't an instance attached to a domain (but some intermediate object), and sanity checking is going to be done later, then storing and then comparing the values would perhaps be even more obvious an approach above.
The intentions here are hard to judge, because both this function and its CPUID counterpart appear to remain unused by the end of the series.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
Quoted 34 lines · Jan Beulich
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/msr.c +27
-0@@ -45,6 +45,57 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,return 0 ; } +int x86_msr_copy_from_buffer (struct msr_policy *p, +const msr_entry_buffer_t msrs,uint32_t nr_msrs, +uint32_t *err_msr) +{ +unsigned int i; +xen_msr_entry_t data; + +/* +* A well formed caller is expected pass an array with entries in order, +* and without any repetitions. However, due to per-vendor differences, +* and in the case of upgrade or levelled scenarios, we typically expect +* fewer than MAX entries to be passed. +* +* Detecting repeated entries is prohibitively complicated, so we don't +* bother. That said, one way or another if more than MAX entries are +* passed, something is wrong. +*/ +if ( nr_msrs >MSR_MAX_SERIALISED_ENTRIES ) +return -E2BIG ; + +for ( i =0 ; i < nr_msrs; i++ ) + { +if (copy_from_buffer_offset (&data, msrs, i,1 ) ) +return -EFAULT ; + +if ( data.flags )/* .flags MBZ */ + goto err;
Quoted 8 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 79
Quoted 5 lines
xen/common/libx86/msr.c +5
-0+ +switch ( data.idx ) + { +case MSR_INTEL_PLATFORM_INFO : +if ( data.val > ~0u )I suppose this is to guard against truncation. I think it would be more obvious (and future proof) if you used (typeof(p->plaform_info.raw))~0,
ITYM ~((typeof(p->plaform_info.raw)0) ...
Quoted 4 lines
or an intermediate variable
of that type, or data.val >> (sizeof(p->plaform_info.raw)* 8), some of which would likely even trigger a compiler warning once the policy field was grown touint64_t.
... but this is probably better.
Quoted 5 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 82
Quoted 4 lines
xen/common/libx86/msr.c +3
-0+ goto err; + + p->plaform_info.raw = data.val;No other sanity checking?
Correct. This is a data marshalling function, not an auditing function.
The auditing functions are also needed for in-place modification to an existing policy.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 12:17, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 49
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/common/libx86/msr.c +2
-0@@ -45,6 +45,57 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p,return 0 ; } +int x86_msr_copy_from_buffer (struct msr_policy *p, + const msr_entry_buffer_t msrs, uint32_t
nr_msrs,Quoted 7 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p,
Quoted 7 lines
xen/common/libx86/msr.c +7
-0+ uint32_t *err_msr) +{ +unsigned int i; +xen_msr_entry_t data; + +/* +* A well formed caller is expected pass an array with entries in order,
Quoted 1 line
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 57
Quoted 1 line
xen/common/libx86/msr.c +1
-0+* and without any repetitions. However, due to per-vendor differences,
Quoted 1 line
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 58
Quoted 1 line
xen/common/libx86/msr.c +1
-0+* and in the case of upgrade or levelled scenarios, we typically expect
Quoted 16 lines
Quoted 16 lines
xen/common/libx86/msr.c +16
-0+* fewer than MAX entries to be passed. +* +* Detecting repeated entries is prohibitively complicated, so we don't +* bother. That said, one way or another if more than MAX entries are +* passed, something is wrong. +*/ +if ( nr_msrs >MSR_MAX_SERIALISED_ENTRIES ) +return -E2BIG ; + +for ( i =0 ; i < nr_msrs; i++ ) + { +if (copy_from_buffer_offset (&data, msrs, i,1 ) ) +return -EFAULT ; + +if ( data.flags )/* .flags MBZ */ + goto err;Quoted 8 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 79
Quoted 5 lines
xen/common/libx86/msr.c +5
-0+ +switch ( data.idx ) + { +case MSR_INTEL_PLATFORM_INFO : +if ( data.val > ~0u )I suppose this is to guard against truncation. I think it would be more obvious (and future proof) if you used (typeof(p->plaform_info.raw))~0,
Quoted 1 line
ITYM ~((typeof(p->plaform_info.raw)0) ...
Both have the same effect afaict, due to ~0 being signed int.
Quoted 11 lines
Quoted 4 lines
or an intermediate variable
of that type, or data.val >> (sizeof(p->plaform_info.raw)* 8), some of which would likely even trigger a compiler warning once the policy field was grown touint64_t.... but this is probably better.
Quoted 4 lines
Quoted 4 lines
xen/common/libx86/msr.c +3
-0+ goto err; + + p->plaform_info.raw = data.val;
Quoted 6 lines
Quoted 1 line
No other sanity checking?
Correct. This is a data marshalling function, not an auditing function.
The auditing functions are also needed for in-place modification to an existing policy.
Right, but the primary problem with understanding whether the lack of checking here is a problem is the lack of a caller of this function. As I think I did say in the earlier reply - it matters quite a bit where p points.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
Quoted 10 lines · Jan Beulich
Quoted 8 lines
Quoted 4 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 82
Quoted 3 lines
xen/common/libx86/msr.c +3
-0+ goto err; + + p->plaform_info.raw = data.val;No other sanity checking?
Correct. This is a data marshalling function, not an auditing function.
The auditing functions are also needed for in-place modification to an existing policy.
Right, but the primary problem with understanding whether the lack of checking here is a problem is the lack of a caller of this function.
The reason there is no caller is because you objected to my stub implementation in v1.
This marshalling support is currently blocking other work, which is why I've split it out, to allow development to continue in parallel.
Quoted 2 lines
As I think I did say in the earlier reply - it matters quite a bit where p points.
No - it doesn't. This is a function to convert data between two binary representations, as is explained by its documentation.
Auditing the contents of the data would a) need to happen in combination with a cpuid_policy object, and b) would be a layering violation.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 18:06, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 8 lines
Quoted 4 lines
xen/common/libx86/msr.c int x86_msr_copy_to_buffer(const struct msr_policy *p, · line 82
Quoted 3 lines
xen/common/libx86/msr.c +3
-0+ goto err; + + p->plaform_info.raw = data.val;No other sanity checking?
Correct. This is a data marshalling function, not an auditing function.
The auditing functions are also needed for in-place modification to an existing policy.
Right, but the primary problem with understanding whether the lack of checking here is a problem is the lack of a caller of this function.
The reason there is no caller is because you objected to my stub implementation in v1.
This marshalling support is currently blocking other work, which is why I've split it out, to allow development to continue in parallel.
Quoted 8 lines
Quoted 2 lines
As I think I did say in the earlier reply - it matters quite a bit where p points.
No - it doesn't. This is a function to convert data between two binary representations, as is explained by its documentation.
Auditing the contents of the data would a) need to happen in combination with a
cpuid_policyobject, and b) would be a layering violation.
I understand what you mean, but that wasn't my point. If p was the policy of a live domain, blindly putting something in there without auditing would (a) make unrolling in case of error impossible and (b) would transiently show too wide a policy to the guest. Yes, you mean to disallow policy updates once a guest was started, but this again is not visible here. As in so many other cases - introducing functions without callers is problematic.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 11/13 x86: Introduce struct cpu_policy to refer to a group of individual policies
In reply to Andrew CooperThis is prep work for the following patch - please refer to it as well.
When auditing and manipulating policies, it is necessary to do so with a complete set of policies, due to the interdependences of the contents. A containing structure like this will allow for clearer APIs and code.
As a first user, this structure is convenient for the mapping used by XEN_SYSCTL_get_cpu_policy (implemented in the next patch), and for auditing (later when XEN_DOMCTL_set_cpu_policy is implemented).
At this point, the distinction between *_max and *_default is introduced into the ABI. For now, *_default is mapped to *_max, but future development work will result in *_default being a logical subset of *_max.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Ian Jackson <[email protected]>
v2:
* Drop __read_mostly from MSR declarations. Fixes clang build.
* s/policy_group/cpu_policy/g s/cpumsr_policy/cpu_policy/g
* Rebase over the msr_{domain,vcpu}_policy rename
* Don't include vcpu_msrs in the cpu_policy
--- xen/arch/x86/sysctl.c | 27 +++++++++++++++++++++++++++ xen/include/asm-x86/cpuid.h | 3 +++ xen/include/public/sysctl.h | 20 ++++++++++++++++++++ xen/include/xen/libx86/cpu-policy.h | 24 ++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 xen/include/xen/libx86/cpu-policy.h
xen/arch/x86/sysctl.c +27 -0
@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = { + [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +}; +struct l3_cache_info {int ret;unsigned long size;
xen/include/asm-x86/cpuid.h +3 -0
@@ -8,6 +8,7 @@#include <xen/types.h> #include <xen/kernel.h> +#include <xen/libx86/cpu-policy.h> #include <xen/libx86/cpuid.h> #include <public/sysctl.h>
@@ -50,6 +51,8 @@ extern struct cpuidmasks cpuidmask_defaults;extern struct cpuid_policy raw_cpuid_policy, host_cpuid_policy, pv_max_cpuid_policy, hvm_max_cpuid_policy; +extern const struct cpu_policy system_policies[]; +/* Check that all previously present features are still available. */ bool recheck_cpu_features (unsigned int cpu);
xen/include/public/sysctl.h +20 -0
@@ -1063,6 +1063,26 @@ struct xen_sysctl_set_parameter {uint16_t pad[3 ];/* IN: MUST be zero. */ }; +#if defined(__i386__) || defined(__x86_64__) +/* +* XEN_SYSCTL_get_cpu_policy (x86 specific) +* +* Return information about CPUID and MSR policies available on this host. +* - Raw: The real H/W values. +* - Host: The values Xen is using, (after command line overrides, etc). +* - Max_*: Maximum set of features a PV or HVM guest can use. Includes +* experimental features outside of security support. +* - Default_*: Default set of features a PV or HVM guest can use. This is +* the security supported set. +*/ +#define XEN_SYSCTL_cpu_policy_raw 0 +#define XEN_SYSCTL_cpu_policy_host 1 +#define XEN_SYSCTL_cpu_policy_pv_max 2 +#define XEN_SYSCTL_cpu_policy_hvm_max 3 +#define XEN_SYSCTL_cpu_policy_pv_default 4 +#define XEN_SYSCTL_cpu_policy_hvm_default 5 +#endif +struct xen_sysctl {uint32_t cmd;#define XEN_SYSCTL_readconsole 1
xen/include/xen/libx86/cpu-policy.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Common data structures and functions consumed by hypervisor and toolstack */ +#ifndef XEN_LIBX86_POLICIES_H +#define XEN_LIBX86_POLICIES_H + +#include <xen/libx86/cpuid.h> +#include <xen/libx86/msr.h> + +struct cpu_policy +{ +struct cpuid_policy *cpuid; +struct msr_policy *msr; +}; + +#endif /* !XEN_LIBX86_POLICIES_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
Quoted 10 lines · Andrew Cooper
This is prep work for the following patch - please refer to it as well.
When auditing and manipulating policies, it is necessary to do so with a complete set of policies, due to the interdependences of the contents. A containing structure like this will allow for clearer APIs and code.
As a first user, this structure is convenient for the mapping used by
XEN_SYSCTL_get_cpu_policy(implemented in the next patch), and for auditing (later whenXEN_DOMCTL_set_cpu_policyis implemented).
Quoted 5 lines
At this point, the distinction between
*_maxand*_defaultis introduced into the ABI. For now,*_defaultis mapped to*_max, but future development work will result in*_defaultbeing a logical subset of*_max.Signed-off-by Andrew Cooper <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
In reply to Andrew CooperQuoted 10 lines · Andrew Cooper
This is prep work for the following patch - please refer to it as well.
When auditing and manipulating policies, it is necessary to do so with a complete set of policies, due to the interdependences of the contents. A containing structure like this will allow for clearer APIs and code.
As a first user, this structure is convenient for the mapping used by
XEN_SYSCTL_get_cpu_policy(implemented in the next patch), and for auditing (later whenXEN_DOMCTL_set_cpu_policyis implemented).
Quoted 5 lines
At this point, the distinction between
*_maxand*_defaultis introduced into the ABI. For now,*_defaultis mapped to*_max, but future development work will result in*_defaultbeing a logical subset of*_max.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
In reply to Andrew Cooperxen/arch/x86/sysctl.c line 34
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +1
-0@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = {
By the end of the series the array remains unused outside this source file. I'd appreciate if it was made extern only when actually needed, not the least because ...
Quoted 15 lines
xen/arch/x86/sysctl.c +15
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy,
xen/arch/x86/sysctl.c line 59
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +};
... this does not make obvious (without consulting sysctl.h) that there are now holes (and hence hidden NULL pointers); this is perhaps already undesirable with the user of this array that the next patch adds.
With "static" added and the "extern" dropped from the header
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
Quoted 37 lines · Jan Beulich
xen/arch/x86/sysctl.c line 34
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +1
-0@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = {By the end of the series the array remains unused outside this source file. I'd appreciate if it was made extern only when actually needed, not the least because ...
Quoted 15 lines
xen/arch/x86/sysctl.c +15
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy,xen/arch/x86/sysctl.c line 59
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +};
Quoted 4 lines
... this does not make obvious (without consulting
sysctl.h) that there are now holes (and hence hidden NULL pointers); this is perhaps already undesirable with the user of this array that the next patch adds.
What holes? There shouldn't be any, and gdb confirms my expectations:
(gdb) p/x system_policies
$1 = {{cpuid = 0xffff82d080474a80, msr = 0xffff82d080475960}, {cpuid = 0xffff82d080474340, msr = 0xffff82d08047595c}, {cpuid = 0xffff82d080473c00, msr = 0xffff82d080475954}, {cpuid = 0xffff82d0804734c0, msr = 0xffff82d080475958}, {cpuid = 0xffff82d080473c00, msr = 0xffff82d080475954}, {cpuid = 0xffff82d0804734c0, msr = 0xffff82d080475958}}
Quoted 3 lines
With "static" added and the "extern" dropped from the header
Acked-by Jan Beulich <[email protected]>
I'm not going to waste even more time by committing something which is wrong, and having to undo it again in a later patch.
The user, DOMCTL_set_cpu_policy, is deferred from this series because it is still under development, but there is absolutely no question that this array needs to be externally accessible.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
Quoted 46 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 14:16, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
xen/arch/x86/sysctl.c line 34
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +1
-0@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = {By the end of the series the array remains unused outside this source file. I'd appreciate if it was made extern only when actually needed, not the least because ...
Quoted 15 lines
xen/arch/x86/sysctl.c +15
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy,xen/arch/x86/sysctl.c line 59
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +};Quoted 4 lines
... this does not make obvious (without consulting
sysctl.h) that there are now holes (and hence hidden NULL pointers); this is perhaps already undesirable with the user of this array that the next patch adds.What holes? There shouldn't be any, and gdb confirms my expectations:
Quoted 7 lines
(gdb) p/x
system_policies
$1 = {{cpuid =0xffff82d080474a80, msr =0xffff82d080475960}, {cpuid =0xffff82d080474340, msr =0xffff82d08047595c}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}}
I didn't say there are holes, I've said "does not make obvious". For example, it is not unreasonable to imagine for the XEN_SYSCTL_cpu_policy_* values to start at 1 rather than zero, in which case there would be two hidden NULLs at the start of the array.
Quoted 9 lines
Quoted 2 lines
With "static" added and the "extern" dropped from the header
Acked-by Jan Beulich <[email protected]>I'm not going to waste even more time by committing something which is wrong, and having to undo it again in a later patch.
The user,
DOMCTL_set_cpu_policy, is deferred from this series because it is still under development, but there is absolutely no question that this array needs to be externally accessible.
Well, maybe I should have phrased this differently: I'm unconvinced sysctl.c is the right place for this to live. Granted neither cpuid.c nor msr.c are any better.
In the end the point of wanting things static for as long as they need to be so is such that reviewers can notice when something gains wider use. I fully accept that the "set" operation will want access to the array, but we can't demand of other contributors to avoid needlessly making symbols global and at the same time behave differently ourselves. My ack stands without the requested adjustment if this goes in together with the patch implementing "set".
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
Quoted 45 lines · Jan Beulich
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 14:16, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
xen/arch/x86/sysctl.c line 34
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +1
-0@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = {By the end of the series the array remains unused outside this source file. I'd appreciate if it was made extern only when actually needed, not the least because ...
Quoted 15 lines
xen/arch/x86/sysctl.c +15
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy,xen/arch/x86/sysctl.c line 59
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +};Quoted 4 lines
... this does not make obvious (without consulting
sysctl.h) that there are now holes (and hence hidden NULL pointers); this is perhaps already undesirable with the user of this array that the next patch adds.What holes? There shouldn't be any, and gdb confirms my expectations:
Quoted 8 lines
Quoted 7 lines
(gdb) p/x
system_policies
$1 = {{cpuid =0xffff82d080474a80, msr =0xffff82d080475960}, {cpuid =0xffff82d080474340, msr =0xffff82d08047595c}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}}I didn't say there are holes, I've said "does not make obvious".
You did, but I guess what you meant to write was "... are no holes" rather "... are now holes".
Quoted 4 lines
For example, it is not unreasonable to imagine for the XEN_SYSCTL_cpu_policy_* values to start at 1 rather than zero, in which case there would be two hidden NULLs at the start of the array.
Why does this matter? We have similar patterns elsewhere, and the array cannot reasonably be used without the symbolic names (as it is really an unordered set happening to be layed out in array form).
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
With "static" added and the "extern" dropped from the header
Acked-by Jan Beulich <[email protected]>I'm not going to waste even more time by committing something which is wrong, and having to undo it again in a later patch.
Quoted 6 lines
Quoted 3 lines
The user,
DOMCTL_set_cpu_policy, is deferred from this series because it is still under development, but there is absolutely no question that this array needs to be externally accessible.Well, maybe I should have phrased this differently: I'm unconvinced
sysctl.cis the right place for this to live. Granted neithercpuid.cnormsr.care any better.
If you can suggest a better place then I'm all ears, but it has to live somewhere and here was the least-bad option I could come up with.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 15:15, <[email protected]> wrote:
Quoted 52 lines · Jan Beulich
Quoted 52 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 14:16, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
xen/arch/x86/sysctl.c line 34
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +1
-0@@ -31,6 +31,33 @@#include <asm/psr.h> #include <asm/cpuid.h> +const struct cpu_policy system_policies[] = {By the end of the series the array remains unused outside this source file. I'd appreciate if it was made extern only when actually needed, not the least because ...
Quoted 15 lines
xen/arch/x86/sysctl.c +15
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = { + &raw_cpuid_policy, + &raw_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_host ] = { + &host_cpuid_policy, + &host_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_pv_max ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_max ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy,xen/arch/x86/sysctl.c line 59
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ }, + [ XEN_SYSCTL_cpu_policy_pv_default ] = { + &pv_max_cpuid_policy, + &pv_max_msr_policy, + }, + [ XEN_SYSCTL_cpu_policy_hvm_default ] = { + &hvm_max_cpuid_policy, + &hvm_max_msr_policy, + }, +};Quoted 4 lines
... this does not make obvious (without consulting
sysctl.h) that there are now holes (and hence hidden NULL pointers); this is perhaps already undesirable with the user of this array that the next patch adds.What holes? There shouldn't be any, and gdb confirms my expectations:
(gdb) p/x
system_policies
$1 = {{cpuid =0xffff82d080474a80, msr =0xffff82d080475960}, {cpuid =0xffff82d080474340, msr =0xffff82d08047595c}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}, {cpuid =0xffff82d080473c00, msr =0xffff82d080475954}, {cpuid =0xffff82d0804734c0, msr =0xffff82d080475958}}
Quoted 4 lines
Quoted 1 line
I didn't say there are holes, I've said "does not make obvious".
You did, but I guess what you meant to write was "... are no holes" rather "... are now holes".
Oops.
Quoted 8 lines
Quoted 4 lines
For example, it is not unreasonable to imagine for the XEN_SYSCTL_cpu_policy_* values to start at 1 rather than zero, in which case there would be two hidden NULLs at the start of the array.
Why does this matter? We have similar patterns elsewhere, and the array cannot reasonably be used without the symbolic names (as it is really an unordered set happening to be layed out in array form).
It was you even more than me who was worried about NULL pointers sitting in random places, waiting to be de-referenced. Besides the obvious reference by symbolic, there are clearly other ways to index into this array, not to mention someone setting up a loop over it. Anyway - I can live with it being the way it is, and I've given the ack.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 12/13 x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
In reply to Andrew CooperFrom: Sergey Dyasli <[email protected]>
Provide a SYSCTL for the toolstack to obtain complete system CPUID and MSR policy information.
For the XSM side of things, this subop is closely related to {phys,cputopo,numa}info, so shares the physinfo access vector.
Extend the xen-cpuid utility to be able to dump the system policies. An example output is:
Xen reports there are maximum 113 leaves and 3 MSRs Raw policy: 93 leaves, 3 MSRs
CPUID:
leaf subleaf -> eax ebx ecx edx
00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
00000001:ffffffff -> 000306c3:00100800:7ffafbff:bfebfbff
00000002:ffffffff -> 76036301:00f0b5ff:00000000:00c10000
00000004:00000000 -> 1c004121:01c0003f:0000003f:00000000
00000004:00000001 -> 1c004122:01c0003f:0000003f:00000000
00000004:00000002 -> 1c004143:01c0003f:000001ff:00000000
00000004:00000003 -> 1c03c163:03c0003f:00001fff:00000006
00000005:ffffffff -> 00000040:00000040:00000003:00042120
00000006:ffffffff -> 00000077:00000002:00000009:00000000
00000007:00000000 -> 00000000:000027ab:00000000:9c000000
0000000a:ffffffff -> 07300403:00000000:00000000:00000603
0000000b:00000000 -> 00000001:00000002:00000100:00000000
0000000b:00000001 -> 00000004:00000008:00000201:00000000
0000000d:00000000 -> 00000007:00000340:00000340:00000000
0000000d:00000001 -> 00000001:00000000:00000000:00000000
0000000d:00000002 -> 00000100:00000240:00000000:00000000
80000000:ffffffff -> 80000008:00000000:00000000:00000000
80000001:ffffffff -> 00000000:00000000:00000021:2c100800
80000002:ffffffff -> 65746e49:2952286c:6f655820:2952286e
80000003:ffffffff -> 55504320:2d334520:30343231:20337620
80000004:ffffffff -> 2e332040:48473034:0000007a:00000000
80000006:ffffffff -> 00000000:00000000:01006040:00000000
80000007:ffffffff -> 00000000:00000000:00000000:00000100
80000008:ffffffff -> 00003027:00000000:00000000:00000000
MSRs:
index -> value
000000ce -> 0000000080000000---
CC: Jan Beulich <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Daniel De Graaf <[email protected]>
v2:
* Avoid introducing a Spectre V1 gadget
--- tools/libxc/include/xenctrl.h | 6 +++ tools/libxc/xc_cpuid_x86.c | 59 +++++++++++++++++++++++++ tools/misc/xen-cpuid.c | 87 +++++++++++++++++++++++++++++++++++-- xen/arch/x86/sysctl.c | 71 ++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 17 ++++++++ xen/xsm/flask/hooks.c | 1 + xen/xsm/flask/policy/access_vectors | 2 +- 7 files changed, 239 insertions(+), 4 deletions(-)
tools/libxc/include/xenctrl.h +6 -0
@@ -2553,6 +2553,12 @@ int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);int xc_get_cpu_featureset (xc_interface *xch,uint32_t index,uint32_t *nr_features,uint32_t *featureset); +int xc_get_cpu_policy_size (xc_interface *xch,uint32_t *nr_leaves, +uint32_t *nr_msrs); +int xc_get_system_cpu_policy (xc_interface *xch,uint32_t index, +uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves, +uint32_t *nr_msrs,xen_msr_entry_t *msrs); +uint32_t xc_get_cpu_featureset_size (void );enum xc_static_cpu_featuremask {
tools/libxc/xc_cpuid_x86.c +59 -0
65 lines not on this page · raw message
tools/misc/xen-cpuid.c +84 -3
116 lines not on this page · raw message
xen/arch/x86/sysctl.c +71 -0
83 lines not on this page · raw message
xen/include/public/sysctl.h +17 -0
@@ -1075,12 +1075,25 @@ struct xen_sysctl_set_parameter {* - Default_*: Default set of features a PV or HVM guest can use. This is * the security supported set. */ +struct xen_sysctl_cpu_policy {#define XEN_SYSCTL_cpu_policy_raw 0#define XEN_SYSCTL_cpu_policy_host 1#define XEN_SYSCTL_cpu_policy_pv_max 2#define XEN_SYSCTL_cpu_policy_hvm_max 3#define XEN_SYSCTL_cpu_policy_pv_default 4#define XEN_SYSCTL_cpu_policy_hvm_default 5 +uint32_t index;/* IN: Which policy to query? */ +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy', or the maximum number of leaves +* if the guest handle is NULL. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_policy', or the maximum number of MSRs if +* the guest handle is NULL. */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* OUT: */ +}; +typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t ; +DEFINE_XEN_GUEST_HANDLE (xen_sysctl_cpu_policy_t);#endif struct xen_sysctl {
@@ -1112,6 +1125,7 @@ struct xen_sysctl {#define XEN_SYSCTL_get_cpu_featureset 26#define XEN_SYSCTL_livepatch_op 27#define XEN_SYSCTL_set_parameter 28 +#define XEN_SYSCTL_get_cpu_policy 29uint32_t interface_version;/* XEN_SYSCTL_INTERFACE_VERSION */ union {struct xen_sysctl_readconsole readconsole;
@@ -1141,6 +1155,9 @@ struct xen_sysctl {struct xen_sysctl_cpu_featureset cpu_featureset;struct xen_sysctl_livepatch_op livepatch;struct xen_sysctl_set_parameter set_parameter; +#if defined(__i386__) || defined(__x86_64__) +struct xen_sysctl_cpu_policy cpu_policy; +#endif uint8_t pad[128 ]; } u; };
xen/xsm/flask/hooks.c +1 -0
@@ -801,6 +801,7 @@ static int flask_sysctl(int cmd)case XEN_SYSCTL_cputopoinfo:case XEN_SYSCTL_numainfo:case XEN_SYSCTL_pcitopoinfo: +case XEN_SYSCTL_get_cpu_policy:return domain_has_xen (current->domain,XEN__PHYSINFO );case XEN_SYSCTL_psr_cmt_op:
xen/xsm/flask/policy/access_vectors +1 -1
@@ -28,7 +28,7 @@ class xen # XENPF_microcode_update microcode # XEN_SYSCTL_physinfo, XEN_SYSCTL_cputopoinfo, XEN_SYSCTL_numainfo -# XEN_SYSCTL_pcitopoinfo +# XEN_SYSCTL_pcitopoinfo, XEN_SYSCTL_get_cpu_policy physinfo # XENPF_platform_quirk quirk
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
tools/libxc/include/xenctrl.h int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); · line 2556
Quoted 9 lines · Andrew Cooper
tools/libxc/include/xenctrl.h +1
-0@@ -2553,6 +2553,12 @@ int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);int xc_get_cpu_featureset (xc_interface *xch,uint32_t index,uint32_t *nr_features,uint32_t *featureset); +int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,
Nit: I would do s/nr_leaves/nr_cpuid_leaves/.
Quoted 8 lines
tools/libxc/include/xenctrl.h +8
-0+int xc_get_system_cpu_policy (xc_interface *xch,uint32_t index, +uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves, +uint32_t *nr_msrs,xen_msr_entry_t *msrs) +{ +struct xen_sysctl sysctl = {}; +DECLARE_HYPERCALL_BOUNCE (leaves, + *nr_leaves *sizeof (*leaves), +XC_HYPERCALL_BUFFER_BOUNCE_OUT );
tools/libxc/include/xenctrl.h int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
Quoted 10 lines
tools/libxc/include/xenctrl.h +10
-0+DECLARE_HYPERCALL_BOUNCE (msrs, + *nr_msrs *sizeof (*msrs), +XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +int ret; + +if (xc_hypercall_bounce_pre (xch, leaves) ) +return -1 ; + +if (xc_hypercall_bounce_pre (xch, msrs) ) +return -1 ;
You can join both in a single if:
if ( xc_hypercall_bounce_pre(xch, leaves) ||
xc_hypercall_bounce_pre(xch, msrs) )
return -1;
tools/libxc/include/xenctrl.h
Quoted 7 lines
tools/libxc/include/xenctrl.h +7
-0+ + sysctl.cmd = XEN_SYSCTL_get_cpu_policy; + sysctl.u.cpu_policy.index = index; + sysctl.u.cpu_policy.nr_leaves = *nr_leaves; +set_xen_guest_handle (sysctl.u.cpu_policy.cpuid_policy, leaves); + sysctl.u.cpu_policy.nr_msrs = *nr_msrs; +set_xen_guest_handle (sysctl.u.cpu_policy.msr_policy, msrs);
sysctl can be initialized at declaration time instead of zeroing it and then setting the fields:
struct xen_sysctl sysctl = {
.cmd = XEN_SYSCTL_get_cpu_policy;
.u.cpu_policy.index = index;
.u.cpu_policy.nr_leaves = *nr_leaves;
...
};Quoted 8 lines
tools/libxc/include/xenctrl.h +3
-1@@ -344,7 +377,55 @@ int main(int argc, char **argv) mode =MODE_INTERPRET ; } -if ( mode ==MODE_INFO || mode ==MODE_DETAIL ) +if ( mode ==MODE_POLICY ) + { +static const char *const sys_policies[] = {
tools/libxc/include/xenctrl.h int main(int argc, char **argv) · line 392
Quoted 10 lines
tools/libxc/include/xenctrl.h +10
-0+ [ XEN_SYSCTL_cpu_policy_raw ] = "Raw", + [ XEN_SYSCTL_cpu_policy_host ] = "Host", + [ XEN_SYSCTL_cpu_policy_pv_max ] = "PV Max", + [ XEN_SYSCTL_cpu_policy_hvm_max ] = "HVM Max", + [ XEN_SYSCTL_cpu_policy_pv_default ] = "PV Default", + [ XEN_SYSCTL_cpu_policy_hvm_default ] ="HVM Default" , + }; + xen_cpuid_leaf_t *leaves; +xen_msr_entry_t *msrs; +uint32_t pol, max_leaves, max_msrs;
pol could be a plain unsigned int, and named i.
Quoted 38 lines
tools/libxc/include/xenctrl.h +34
-0@@ -322,6 +323,76 @@ long arch_do_sysctl(break ; } +case XEN_SYSCTL_get_cpu_policy: + { +const struct cpu_policy *policy; + +/* Bad policy index? */ +if ( sysctl->u.cpu_policy.index >=ARRAY_SIZE (system_policies) ) + { + ret = -EINVAL ; +break ; + } + policy = &system_policies[ +array_index_nospec (sysctl->u.cpu_policy.index, +ARRAY_SIZE (system_policies))]; + +/* Request for maximum number of leaves/MSRs? */ +if (guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { + sysctl->u.cpu_policy.nr_leaves =CPUID_MAX_SERIALISED_LEAVES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + } + } +if (guest_handle_is_null (sysctl->u.cpu_policy.msr_policy) ) + { + sysctl->u.cpu_policy.nr_msrs =MSR_MAX_SERIALISED_ENTRIES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + }
tools/libxc/include/xenctrl.h long arch_do_sysctl( · line 369
Quoted 10 lines
tools/libxc/include/xenctrl.h +10
-0+ } + +/* Serialise the information the caller wants. */ +if ( !guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { +if ( (ret =x86_cpuid_copy_to_buffer ( + policy->cpuid, + sysctl->u.cpu_policy.cpuid_policy, + &sysctl->u.cpu_policy.nr_leaves)) ) +break ;
You could have this better aligned by first assigning the result value to ret and then checking for errors.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
Quoted 11 lines · Roger Pau Monné
tools/libxc/xc_cpuid_x86.c const uint32_t *xc_get_static_cpu_featuremask( · line 178
Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +7
-0+ + sysctl.cmd = XEN_SYSCTL_get_cpu_policy; + sysctl.u.cpu_policy.index = index; + sysctl.u.cpu_policy.nr_leaves = *nr_leaves; +set_xen_guest_handle (sysctl.u.cpu_policy.cpuid_policy, leaves); + sysctl.u.cpu_policy.nr_msrs = *nr_msrs; +set_xen_guest_handle (sysctl.u.cpu_policy.msr_policy, msrs);sysctl can be initialized at declaration time instead of zeroing it and then setting the fields:
Quoted 6 lines
struct xen_sysctl sysctl = {
.cmd = XEN_SYSCTL_get_cpu_policy;
.u.cpu_policy.index = index;
.u.cpu_policy.nr_leaves = *nr_leaves;
...
};This doesn't compile in a CentOS 6 era GCC. It can't cope with initialisers of anonymous unions, and is the reason why a lot of the toolstack logic is in the form presented in this patch, rather than the cleaner option you present.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 12:58, <[email protected]> wrote:
Quoted 11 lines · Roger Pau Monné
tools/libxc/xc_cpuid_x86.c const uint32_t *xc_get_static_cpu_featuremask( · line 178
Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +7
-0+ + sysctl.cmd = XEN_SYSCTL_get_cpu_policy; + sysctl.u.cpu_policy.index = index; + sysctl.u.cpu_policy.nr_leaves = *nr_leaves; +set_xen_guest_handle (sysctl.u.cpu_policy.cpuid_policy, leaves); + sysctl.u.cpu_policy.nr_msrs = *nr_msrs; +set_xen_guest_handle (sysctl.u.cpu_policy.msr_policy, msrs);sysctl can be initialized at declaration time instead of zeroing it and then setting the fields:
Quoted 6 lines
struct xen_sysctl sysctl = { .cmd = XEN_SYSCTL_get_cpu_policy; .u.cpu_policy.index = index; .u.cpu_policy.nr_leaves = *nr_leaves; ... };
Quoted 4 lines
This doesn't compile in a CentOS 6 era GCC. It can't cope with initialisers of anonymous unions, and is the reason why a lot of the toolstack logic is in the form presented in this patch, rather than the cleaner option you present.
But where's the anonymous union here? Such shouldn't be used in the public headers anyway.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
In reply to Andrew CooperQuoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +14
-0@@ -322,6 +323,76 @@ long arch_do_sysctl(break ; } +case XEN_SYSCTL_get_cpu_policy: + { +const struct cpu_policy *policy; + +/* Bad policy index? */ +if ( sysctl->u.cpu_policy.index >=ARRAY_SIZE (system_policies) ) + { + ret = -EINVAL ; +break ; + } + policy = &system_policies[ +array_index_nospec (sysctl->u.cpu_policy.index, +ARRAY_SIZE (system_policies))]; +
xen/arch/x86/sysctl.c long arch_do_sysctl( · line 349
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+/* Request for maximum number of leaves/MSRs? */ +if (guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { + sysctl->u.cpu_policy.nr_leaves =CPUID_MAX_SERIALISED_LEAVES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }
Could I talk you into avoiding the redundancy here and fold this copying with ...
Quoted 17 lines
xen/arch/x86/sysctl.c +17
-0+ } +if (guest_handle_is_null (sysctl->u.cpu_policy.msr_policy) ) + { + sysctl->u.cpu_policy.nr_msrs =MSR_MAX_SERIALISED_ENTRIES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + } + } + +/* Serialise the information the caller wants. */ + if ( !guest_handle_is_null(sysctl->u.cpu_policy.cpuid_policy) ) + { + if ( (ret = x86_cpuid_copy_to_buffer( + policy->cpuid,
xen/arch/x86/sysctl.c long arch_do_sysctl( · line 376
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+ sysctl->u.cpu_policy.cpuid_policy, + &sysctl->u.cpu_policy.nr_leaves)) ) + break; + +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }
... this (and the MSR ones respectively), by moving both out of and past their outer if()-s? This would the also call for two if/else-if pairs instead of four if()-s.
Quoted 12 lines
xen/include/public/sysctl.h +1
-0@@ -1075,12 +1075,25 @@ struct xen_sysctl_set_parameter {* - Default_*: Default set of features a PV or HVM guest can use. This is * the security supported set. */ +struct xen_sysctl_cpu_policy {#define XEN_SYSCTL_cpu_policy_raw 0#define XEN_SYSCTL_cpu_policy_host 1#define XEN_SYSCTL_cpu_policy_pv_max 2#define XEN_SYSCTL_cpu_policy_hvm_max 3#define XEN_SYSCTL_cpu_policy_pv_default 4
xen/include/public/sysctl.h struct xen_sysctl_set_parameter { · line 1093
Quoted 10 lines
xen/include/public/sysctl.h +9
-0#define XEN_SYSCTL_cpu_policy_hvm_default 5 +uint32_t index;/* IN: Which policy to query? */ +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy', or the maximum number of leaves +* if the guest handle is NULL. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_policy', or the maximum number of MSRs if +* the guest handle is NULL. */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* OUT: */
Stray colons in the comments?
I'm also not overly happy to see there's still no explicit padding here. I know you dislike it, but I think as long as we have no better replacement to the interface versioning, we should at least try to limit the number of bumps it needs, and that calls for making padding explicit, zeroing it for output and checking it to be zero when input, so that the field can be assigned meaning subsequently. Otherwise why did we tell others to add explicit padding over the last so many years, without you voicing your opinion to the contrary?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
Quoted 54 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +14
-0@@ -322,6 +323,76 @@ long arch_do_sysctl(break ; } +case XEN_SYSCTL_get_cpu_policy: + { +const struct cpu_policy *policy; + +/* Bad policy index? */ +if ( sysctl->u.cpu_policy.index >=ARRAY_SIZE (system_policies) ) + { + ret = -EINVAL ; +break ; + } + policy = &system_policies[ +array_index_nospec (sysctl->u.cpu_policy.index, +ARRAY_SIZE (system_policies))]; +xen/arch/x86/sysctl.c long arch_do_sysctl( · line 349
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+/* Request for maximum number of leaves/MSRs? */ +if (guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { + sysctl->u.cpu_policy.nr_leaves =CPUID_MAX_SERIALISED_LEAVES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }Could I talk you into avoiding the redundancy here and fold this copying with ...
Quoted 22 lines
xen/arch/x86/sysctl.c +22
-0+ } +if (guest_handle_is_null (sysctl->u.cpu_policy.msr_policy) ) + { + sysctl->u.cpu_policy.nr_msrs =MSR_MAX_SERIALISED_ENTRIES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + } + } + +/* Serialise the information the caller wants. */ +if ( !guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { +if ( (ret =x86_cpuid_copy_to_buffer ( + policy->cpuid, + sysctl->u.cpu_policy.cpuid_policy, + &sysctl->u.cpu_policy.nr_leaves)) ) +break ; + + if ( __copy_field_to_guest(u_sysctl, sysctl,
Quoted 8 lines
xen/arch/x86/sysctl.c long arch_do_sysctl( · line 349
Quoted 5 lines
xen/arch/x86/sysctl.c +5
-0+ u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }... this (and the MSR ones respectively), by moving both out of and past their outer if()-s? This would the also call for two if/else-if pairs instead of four if()-s.
I
Quoted 25 lines
Quoted 13 lines
xen/include/public/sysctl.h +1
-0@@ -1075,12 +1075,25 @@ struct xen_sysctl_set_parameter {* - Default_*: Default set of features a PV or HVM guest can use. This is * the security supported set. */ +struct xen_sysctl_cpu_policy {#define XEN_SYSCTL_cpu_policy_raw 0#define XEN_SYSCTL_cpu_policy_host 1#define XEN_SYSCTL_cpu_policy_pv_max 2#define XEN_SYSCTL_cpu_policy_hvm_max 3#define XEN_SYSCTL_cpu_policy_pv_default 4xen/include/public/sysctl.h struct xen_sysctl_set_parameter { · line 1093
Quoted 10 lines
xen/include/public/sysctl.h +9
-0#define XEN_SYSCTL_cpu_policy_hvm_default 5 +uint32_t index;/* IN: Which policy to query? */ +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy', or the maximum number of leaves +* if the guest handle is NULL. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_policy', or the maximum number of MSRs if +* the guest handle is NULL. */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* OUT: */ Stray colons in the comments?
Quoted 8 lines
I'm also not overly happy to see there's still no explicit padding here. I know you dislike it, but I think as long as we have no better replacement to the interface versioning, we should at least try to limit the number of bumps it needs, and that calls for making padding explicit, zeroing it for output and checking it to be zero when input, so that the field can be assigned meaning subsequently. Otherwise why did we tell others to add explicit padding over the last so many years, without you voicing your opinion to the contrary?
I've never (knowingly) requested padding in the unstable interface. I've certainly requested rearrangements for better packing, and requested padding for bits of the stable ABI.
The sysctl structure itself is full of holes, and this is not an appropriate time or place to be making partial changes to the ABI.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy
Quoted 65 lines
Quoted 1 line
Quoted 1 line · On 17.07.18 at 18:50, <[email protected]> wrote:
Quoted 54 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/sysctl.c +14
-0@@ -322,6 +323,76 @@ long arch_do_sysctl(break ; } +case XEN_SYSCTL_get_cpu_policy: + { +const struct cpu_policy *policy; + +/* Bad policy index? */ +if ( sysctl->u.cpu_policy.index >=ARRAY_SIZE (system_policies) ) + { + ret = -EINVAL ; +break ; + } + policy = &system_policies[ +array_index_nospec (sysctl->u.cpu_policy.index, +ARRAY_SIZE (system_policies))]; +xen/arch/x86/sysctl.c long arch_do_sysctl( · line 349
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+/* Request for maximum number of leaves/MSRs? */ +if (guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { + sysctl->u.cpu_policy.nr_leaves =CPUID_MAX_SERIALISED_LEAVES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }Could I talk you into avoiding the redundancy here and fold this copying with ...
Quoted 22 lines
xen/arch/x86/sysctl.c +22
-0+ } +if (guest_handle_is_null (sysctl->u.cpu_policy.msr_policy) ) + { + sysctl->u.cpu_policy.nr_msrs =MSR_MAX_SERIALISED_ENTRIES ; +if (__copy_field_to_guest (u_sysctl, sysctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + } + } + +/* Serialise the information the caller wants. */ +if ( !guest_handle_is_null (sysctl->u.cpu_policy.cpuid_policy) ) + { +if ( (ret =x86_cpuid_copy_to_buffer ( + policy->cpuid, + sysctl->u.cpu_policy.cpuid_policy, + &sysctl->u.cpu_policy.nr_leaves)) ) +break ; + + if ( __copy_field_to_guest(u_sysctl, sysctl,Quoted 8 lines
xen/arch/x86/sysctl.c long arch_do_sysctl( · line 349
Quoted 5 lines
xen/arch/x86/sysctl.c +5
-0+ u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + }... this (and the MSR ones respectively), by moving both out of and past their outer if()-s? This would the also call for two if/else-if pairs instead of four if()-s.
Quoted 1 line
I
???
Quoted 33 lines
Quoted 24 lines
Quoted 12 lines
xen/include/public/sysctl.h +1
-0@@ -1075,12 +1075,25 @@ struct xen_sysctl_set_parameter {* - Default_*: Default set of features a PV or HVM guest can use. This is * the security supported set. */ +struct xen_sysctl_cpu_policy {#define XEN_SYSCTL_cpu_policy_raw 0#define XEN_SYSCTL_cpu_policy_host 1#define XEN_SYSCTL_cpu_policy_pv_max 2#define XEN_SYSCTL_cpu_policy_hvm_max 3#define XEN_SYSCTL_cpu_policy_pv_default 4xen/include/public/sysctl.h struct xen_sysctl_set_parameter { · line 1093
Quoted 10 lines
xen/include/public/sysctl.h +9
-0#define XEN_SYSCTL_cpu_policy_hvm_default 5 +uint32_t index;/* IN: Which policy to query? */ +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy', or the maximum number of leaves +* if the guest handle is NULL. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_policy', or the maximum number of MSRs if +* the guest handle is NULL. */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* OUT: */ Stray colons in the comments?
Quoted 8 lines
I'm also not overly happy to see there's still no explicit padding here. I know you dislike it, but I think as long as we have no better replacement to the interface versioning, we should at least try to limit the number of bumps it needs, and that calls for making padding explicit, zeroing it for output and checking it to be zero when input, so that the field can be assigned meaning subsequently. Otherwise why did we tell others to add explicit padding over the last so many years, without you voicing your opinion to the contrary?
Quoted 3 lines
I've never (knowingly) requested padding in the unstable interface. I've certainly requested rearrangements for better packing, and requested padding for bits of the stable ABI.
I don't recall you requesting such, indeed, but I also don't recall you objecting to me (and iirc also a few others) doing so.
Quoted 2 lines
The sysctl structure itself is full of holes, and this is not an appropriate time or place to be making partial changes to the ABI.
Well, I'm not going to insist, since as you say it's inconsistent at present anyway. But we'll want to settle on one of the other model for new additions, and then consider converting existing ones accordingly.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 13/13 x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
In reply to Andrew CooperFrom: Sergey Dyasli <[email protected]>
This finally (after literally years of work!) marks the point where the toolstack can ask the hypervisor for the current CPUID configuration of a specific domain.
Also extend xen-cpuid's --policy mode to be able to take a domid and dump a specific domains CPUID and MSR policy.
---
CC: Jan Beulich <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Sergey Dyasli <[email protected]>
CC: Daniel De Graaf <[email protected]>
--- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_cpuid_x86.c | 40 +++++++++++++++++++++++ tools/misc/xen-cpuid.c | 64 +++++++++++++++++++++++++++++++------ xen/arch/x86/domctl.c | 34 ++++++++++++++++++++ xen/include/public/domctl.h | 18 +++++++++++ xen/xsm/flask/hooks.c | 1 + xen/xsm/flask/policy/access_vectors | 1 + 7 files changed, 152 insertions(+), 9 deletions(-)
tools/libxc/include/xenctrl.h +3 -0
@@ -2558,6 +2558,9 @@ int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves,int xc_get_system_cpu_policy (xc_interface *xch,uint32_t index,uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves,uint32_t *nr_msrs,xen_msr_entry_t *msrs); +int xc_get_domain_cpu_policy (xc_interface *xch,uint32_t domid, +uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves, +uint32_t *nr_msrs,xen_msr_entry_t *msrs);uint32_t xc_get_cpu_featureset_size (void );
tools/libxc/xc_cpuid_x86.c +40 -0
@@ -191,6 +191,46 @@ int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index,return ret; } +int xc_get_domain_cpu_policy (xc_interface *xch,uint32_t domid, +uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves, +uint32_t *nr_msrs,xen_msr_entry_t *msrs) +{ +DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BOUNCE (leaves, + *nr_leaves *sizeof (*leaves), +XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +DECLARE_HYPERCALL_BOUNCE (msrs, + *nr_msrs *sizeof (*msrs), +XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +int ret; + +if (xc_hypercall_bounce_pre (xch, leaves) ) +return -1 ; + +if (xc_hypercall_bounce_pre (xch, msrs) ) +return -1 ; + + domctl.cmd = XEN_DOMCTL_get_cpu_policy; + domctl.domain = domid; + domctl.u.cpu_policy.nr_leaves = *nr_leaves; +set_xen_guest_handle (domctl.u.cpu_policy.cpuid_policy, leaves); + domctl.u.cpu_policy.nr_msrs = *nr_msrs; +set_xen_guest_handle (domctl.u.cpu_policy.msr_policy, msrs); + + ret =do_domctl (xch, &domctl); + +xc_hypercall_bounce_post (xch, leaves); +xc_hypercall_bounce_post (xch, msrs); + +if ( !ret ) + { + *nr_leaves = domctl.u.cpu_policy.nr_leaves; + *nr_msrs = domctl.u.cpu_policy.nr_msrs; + } + +return ret; +} +struct cpuid_domain_info { enum
tools/misc/xen-cpuid.c +55 -9
114 lines not on this page · raw message
xen/arch/x86/domctl.c +34 -0
@@ -1523,6 +1523,40 @@ long arch_do_domctl(recalculate_cpuid_policy (d);break ; +case XEN_DOMCTL_get_cpu_policy: +if ( !guest_handle_is_null (domctl->u.cpu_policy.cpuid_policy) ) + { +if ( (ret =x86_cpuid_copy_to_buffer ( + d->arch.cpuid, + domctl->u.cpu_policy.cpuid_policy, + &domctl->u.cpu_policy.nr_leaves)) ) +break ; + +if (__copy_field_to_guest (u_domctl, domctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + } + } + +if ( !guest_handle_is_null (domctl->u.cpu_policy.msr_policy) ) + { +if ( (ret =x86_msr_copy_to_buffer ( + d->arch.msr, + domctl->u.cpu_policy.msr_policy, + &domctl->u.cpu_policy.nr_msrs)) ) +break ; + +if (__copy_field_to_guest (u_domctl, domctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + } + } +break ; +default : ret =iommu_do_domctl (domctl, d, u_domctl);break ;
xen/include/public/domctl.h +18 -0
@@ -635,6 +635,22 @@ struct xen_domctl_cpuid {uint32_t ecx; uint32_t edx; }; + +/* +* XEN_SYSCTL_{get,set}_cpu_policy (x86 specific) +* +* Query or set the CPUID and MSR policies for a specific domain. +*/ +struct xen_domctl_cpu_policy { +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy'. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_domain_policy' */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* IN/OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* IN/OUT: */ +}; +typedef struct xen_domctl_cpu_policy xen_domctl_cpu_policy_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_cpu_policy_t);#endif /*
@@ -1174,6 +1190,7 @@ struct xen_domctl {#define XEN_DOMCTL_soft_reset 79#define XEN_DOMCTL_set_gnttab_limits 80#define XEN_DOMCTL_vuart_op 81 +#define XEN_DOMCTL_get_cpu_policy 82#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1218,6 +1235,7 @@ struct xen_domctl {struct xen_domctl_mem_sharing_op mem_sharing_op;#if defined(__i386__) || defined(__x86_64__)struct xen_domctl_cpuid cpuid; +struct xen_domctl_cpu_policy cpu_policy;struct xen_domctl_vcpuextstate vcpuextstate;struct xen_domctl_vcpu_msrs vcpu_msrs;#endif
xen/xsm/flask/hooks.c +1 -0
@@ -717,6 +717,7 @@ static int flask_domctl(struct domain *d, int cmd)return current_has_perm (d,SECCLASS_DOMAIN ,DOMAIN__SET_VIRQ_HANDLER );case XEN_DOMCTL_set_cpuid: +case XEN_DOMCTL_get_cpu_policy:return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__SET_CPUID );case XEN_DOMCTL_gettscinfo:
xen/xsm/flask/policy/access_vectors +1 -0
@@ -213,6 +213,7 @@ class domain2 # target = the new target domain set_as_target # XEN_DOMCTL_set_cpuid +# XEN_DOMCTL_get_cpu_policy set_cpuid # XEN_DOMCTL_gettscinfo gettsc
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
Quoted 8 lines · Andrew Cooper
tools/libxc/xc_cpuid_x86.c +8
-0+int xc_get_domain_cpu_policy (xc_interface *xch,uint32_t domid, +uint32_t *nr_leaves,xen_cpuid_leaf_t *leaves, +uint32_t *nr_msrs,xen_msr_entry_t *msrs) +{ +DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BOUNCE (leaves, + *nr_leaves *sizeof (*leaves), +XC_HYPERCALL_BUFFER_BOUNCE_OUT );
tools/libxc/xc_cpuid_x86.c int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, · line 211
Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +10
-0+DECLARE_HYPERCALL_BOUNCE (msrs, + *nr_msrs *sizeof (*msrs), +XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +int ret; + +if (xc_hypercall_bounce_pre (xch, leaves) ) +return -1 ; + +if (xc_hypercall_bounce_pre (xch, msrs) ) +return -1 ;
The ifs can be joined into a single one.
tools/libxc/xc_cpuid_x86.c int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, · line 218
Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +6
-0+ domctl.cmd = XEN_DOMCTL_get_cpu_policy; + domctl.domain = domid; + domctl.u.cpu_policy.nr_leaves = *nr_leaves; +set_xen_guest_handle (domctl.u.cpu_policy.cpuid_policy, leaves); + domctl.u.cpu_policy.nr_msrs = *nr_msrs; +set_xen_guest_handle (domctl.u.cpu_policy.msr_policy, msrs);
The fields can be set at declaration time, leaving just the _handle calls here.
Quoted 31 lines
tools/libxc/xc_cpuid_x86.c +14
-0+ ret =do_domctl (xch, &domctl); + +xc_hypercall_bounce_post (xch, leaves); +xc_hypercall_bounce_post (xch, msrs); + +if ( !ret ) + { + *nr_leaves = domctl.u.cpu_policy.nr_leaves; + *nr_msrs = domctl.u.cpu_policy.nr_msrs; + } + +return ret; +} +struct cpuid_domain_info { enumtools/misc/xen-cpuid.c +2
-0@@ -3,6 +3,8 @@#include <err.h> #include <getopt.h> #include <string.h> +#include <errno.h> +#include <limits.h> #include <xenctrl.h>
tools/misc/xen-cpuid.c int main(int argc, char **argv) · line 314
Quoted 4 lines
tools/misc/xen-cpuid.c +1
-0@@ -309,11 +311,13 @@ int main(int argc, char **argv) {enum {MODE_UNKNOWN ,MODE_INFO ,MODE_DETAIL ,MODE_INTERPRET ,MODE_POLICY } mode =MODE_UNKNOWN ; +int domid =-1 ;
Using domid_t and DOMID_INVALID would be better IMO.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
Quoted 7 lines · Roger Pau Monné
tools/misc/xen-cpuid.c int main(int argc, char **argv) · line 314
Quoted 5 lines · Andrew Cooper
tools/misc/xen-cpuid.c +1
-0@@ -309,11 +311,13 @@ int main(int argc, char **argv) {enum {MODE_UNKNOWN ,MODE_INFO ,MODE_DETAIL ,MODE_INTERPRET ,MODE_POLICY } mode =MODE_UNKNOWN ; +int domid =-1 ;Using
domid_tandDOMID_INVALIDwould be better IMO.
Please see 5b42c82f5584ca8b0e169c6de1b6d81214ea07f2 for why domid_t is unusable in toolstack code.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
In reply to Andrew CooperQuoted 30 lines
Quoted 1 line
Quoted 1 line · On 13.07.18 at 22:03, <[email protected]> wrote:
xen/arch/x86/domctl.c +23
-0@@ -1523,6 +1523,40 @@ long arch_do_domctl(recalculate_cpuid_policy (d);break ; +case XEN_DOMCTL_get_cpu_policy: +if ( !guest_handle_is_null (domctl->u.cpu_policy.cpuid_policy) ) + { +if ( (ret =x86_cpuid_copy_to_buffer ( + d->arch.cpuid, + domctl->u.cpu_policy.cpuid_policy, + &domctl->u.cpu_policy.nr_leaves)) ) +break ; + +if (__copy_field_to_guest (u_domctl, domctl, + u.cpu_policy.nr_leaves) ) + { + ret = -EFAULT ; +break ; + } + } + +if ( !guest_handle_is_null (domctl->u.cpu_policy.msr_policy) ) + { +if ( (ret =x86_msr_copy_to_buffer ( + d->arch.msr, + domctl->u.cpu_policy.msr_policy, + &domctl->u.cpu_policy.nr_msrs)) )
xen/arch/x86/domctl.c long arch_do_domctl( · line 1558
Quoted 10 lines
xen/arch/x86/domctl.c +10
-0+break ; + +if (__copy_field_to_guest (u_domctl, domctl, + u.cpu_policy.nr_msrs) ) + { + ret = -EFAULT ; +break ; + } + } +break ;
Am I getting it right that the array sizing here is supposed to be done based on the sysctl output? That's probably okay because we expect callers to use libxc, but it doesn't make for a very consistent interface (set).
Quoted 9 lines
xen/include/public/domctl.h +3
-0@@ -635,6 +635,22 @@ struct xen_domctl_cpuid {uint32_t ecx;uint32_t edx; }; + +/* +* XEN_SYSCTL_{get,set}_cpu_policy (x86 specific)
xen/include/public/domctl.h struct xen_domctl_cpuid { · line 650
Quoted 10 lines
xen/include/public/domctl.h +10
-0+* +* Query or set the CPUID and MSR policies for a specific domain. +*/ +struct xen_domctl_cpu_policy { +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy'. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_domain_policy' */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* IN/OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* IN/OUT: */
Stray colons again in the comments? With them dropped, and despite the remark above
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
In reply to Andrew CooperQuoted 12 lines · Andrew Cooper
From: Sergey Dyasli <[email protected]>
This finally (after literally years of work!) marks the point where the toolstack can ask the hypervisor for the current CPUID configuration of a specific domain.
Also extend xen-cpuid's --policy mode to be able to take a domid and dump a specific domains CPUID and MSR policy.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>---
xen/include/public/domctl.h struct xen_domctl_cpuid { · line 642
Quoted 5 lines
xen/include/public/domctl.h +5
-0+ +/* +* XEN_SYSCTL_{get,set}_cpu_policy (x86 specific) +* +* Query or set the CPUID and MSR policies for a specific domain.
Setting policies isn't introduced in this series. The comments here should be aligned with what have been implemented.
Thanks
Chao
Quoted 11 lines
+ */
xen/include/public/domctl.h +10
-0+struct xen_domctl_cpu_policy { +uint32_t nr_leaves;/* IN/OUT: Number of leaves in/written to +* 'cpuid_policy'. */ +uint32_t nr_msrs;/* IN/OUT: Number of MSRs in/written to +* 'msr_domain_policy' */ +XEN_GUEST_HANDLE_64 (xen_cpuid_leaf_t) cpuid_policy;/* IN/OUT: */ +XEN_GUEST_HANDLE_64 (xen_msr_entry_t) msr_policy;/* IN/OUT: */ +}; +typedef struct xen_domctl_cpu_policy xen_domctl_cpu_policy_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_cpu_policy_t);
Quoted 2 lines
#endif
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy
In reply to Andrew CooperQuoted 11 lines · Andrew Cooper
From: Sergey Dyasli <[email protected]>
This finally (after literally years of work!) marks the point where the toolstack can ask the hypervisor for the current CPUID configuration of a specific domain.
Also extend xen-cpuid's --policy mode to be able to take a domid and dump a specific domains CPUID and MSR policy.
Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Sergey Dyasli <[email protected]>
Since this is a read operation, it should have a new access vector (probably get_cpuid) instead of sitting under set_cpuid so that it is possible to allow viewing the policy without allowing it to be changed (useful for migration out, introspection, or duplicating the settings on a now-protected domain).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Andrew Cooper
This series introduces libx86, a small shared library between the hypervisor and libxc, and hypercalls to get full CPUID/MSR policies. Future work will implement
XEN_DOMCTL_set_cpumsr_policy, after the auditing and comparison logic is sorted.In the meantime, the data marshalling logic is in a suitable state for review.
Hi, Andrew:
Glad to see your CPUID series. I noticed that this series doesn't include things like, setting policies, removing a long-standing issue - vAPIC ID is hard-coded to "2 * vcpu_id", and vCPU topology. Will you post patches for them? If yes, are they intended to be merged in Xen 4.12?
Thanks
Chao
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel