Skip to contentSkip to conversation

Disable domctl-op via CONFIG_MGMT_HYPERCALLS

PATCH In review Penny Zheng 4 participants 40 messages Dec 12, 2025 – Dec 18, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

v5 cover Disable domctl-op via CONFIG_MGMT_HYPERCALLS

It can be beneficial for some dom0less systems to further reduce Xen footprint via disabling some hypercalls handling code, which may not to be used & required in such systems.
We are introducing a new single Kconfig CONFIG_MGMT_HYPERCALLS to manage such hypercalls.

We are trying to disable hypercalls in the following aspects:
- sysctl
- domctl
- hvm
- physdev
- platform
This patch serie is only focusing on domctl-op. Different aspects will be covered in different patch serie.

Features, like VM event, or paging log-dirty support, which fully rely on domctl-op, will be wrapped with CONFIG_MGMT_HYPERCALLS, to reduce Xen footprint as much as possible.

It is derived from Stefano Stabellini's commit "xen: introduce kconfig options to disable hypercalls"(
https://lore.kernel.org/xen-devel/[email protected])
---
This patch serie is based on "[PATCH v3 0/7] consolidate vm event subsystem"
---
The following commits are prerequisite, and could be committed independently:
- xen/xsm: remove redundant flask_iomem_mapping()
- xen/x86: library-fy cpuid-releated functions
- xen/arm: move dt_find_node_by_gpath() to passthrough/device_tree.c
- xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_HYPERCALLS
---
Penny Zheng (24):
xen/xsm: remove redundant flask_iomem_mapping()
xen/x86: library-fy cpuid-releated functions
xen/arm: move dt_find_node_by_gpath() to passthrough/device_tree.c xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_HYPERCALLS xen/domctl: make MGMT_HYPERCALLS transiently def_bool xen/vm_event: make VM_EVENT depend on CONFIG_MGMT_HYPERCALLS xen/domctl: consolidate domain.c towards MGMT_HYPERCALLS xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS xen/domctl: wrap domain_kill() with CONFIG_MGMT_HYPERCALLS xen/domctl: wrap vcpu_affinity_domctl() with CONFIG_MGMT_HYPERCALLS xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS xen/xsm: wrap xsm_irq{,iomem}_permission with CONFIG_MGMT_HYPERCALLS xen/domctl: wrap arch-specific domain_set_time_offset() with
CONFIG_MGMT_HYPERCALLS
xen/domctl: wrap xsm_set_target() with CONFIG_MGMT_HYPERCALLS xen/domctl: wrap pci-subset iommu-related domctl op with
CONFIG_MGMT_HYPERCALLS
xen/domctl: wrap device-tree-subset iommu-related domctl op with
CONFIG_MGMT_HYPERCALLS
xen/domctl: wrap iommu-related domctl op with CONFIG_MGMT_HYPERCALLS xen/domctl: wrap arch_{get,set}_paging_mempool_size() with
CONFIG_MGMT_HYPERCALLS
xen/domctl: make CONFIG_X86_PSR depend on CONFIG_MGMT_HYPERCALLS xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS xen/arm: wrap arm-specific domctl-op with CONFIG_MGMT_HYPERCALLS x86/hvm: domctl_lock synchronization only when MGMT_HYPERCALLS=y xen/domctl: wrap common/domctl.c with CONFIG_MGMT_HYPERCALLS
xen: decouple PV_SHIM_EXCLUSIVE and MGMT_HYPERCALLS

 tools/fuzz/cpu-policy/Makefile               |   4 +-
 tools/fuzz/x86_instruction_emulator/Makefile |  11 +-
 tools/libs/guest/Makefile.common             |   4 +-
 tools/tests/cpu-policy/Makefile              |   3 +-
 tools/tests/x86_emulator/Makefile            |   3 +-
 xen/Kconfig.debug                            |   3 +-
 xen/arch/arm/Kconfig                         |   2 +-
 xen/arch/arm/Makefile                        |   4 +-
 xen/arch/arm/arm32/Makefile                  |   2 +-
 xen/arch/arm/arm64/Makefile                  |   2 +-
 xen/arch/arm/domain.c                        |   3 +
 xen/arch/arm/include/asm/tee/tee.h           |   2 +
 xen/arch/arm/mmu/p2m.c                       |   8 +
 xen/arch/arm/mpu/p2m.c                       |   2 +
 xen/arch/arm/tee/ffa.c                       |   4 +
 xen/arch/arm/tee/optee.c                     |   4 +
 xen/arch/arm/tee/tee.c                       |   2 +
 xen/arch/arm/time.c                          |   2 +
 xen/arch/ppc/stubs.c                         |   2 +
 xen/arch/riscv/stubs.c                       |   8 +-
 xen/arch/x86/Kconfig                         |   1 +
 xen/arch/x86/Makefile                        |   4 +-
 xen/arch/x86/configs/pvshim_defconfig        |   2 +-
 xen/arch/x86/domain.c                        |   2 +
 xen/arch/x86/domctl.c                        |   2 +-
 xen/arch/x86/emul-i8254.c                    |   2 +
 xen/arch/x86/hvm/Kconfig                     |   2 +
 xen/arch/x86/hvm/hvm.c                       |   7 +-
 xen/arch/x86/hvm/pmtimer.c                   |   2 +
 xen/arch/x86/include/asm/p2m.h               |   2 +-
 xen/arch/x86/include/asm/paging.h            |   3 +-
 xen/arch/x86/mm/p2m-pod.c                    |   2 +
 xen/arch/x86/mm/p2m.c                        |   2 +
 xen/arch/x86/mm/paging.c                     |   4 +
 xen/arch/x86/psr.c                           |  18 --
 xen/arch/x86/time.c                          |   2 +
 xen/common/Kconfig                           |  28 +-
 xen/common/Makefile                          |   6 +-
 xen/common/device-tree/device-tree.c         |  16 --
 xen/common/domain.c                          | 116 ++++----
 xen/common/page_alloc.c                      |   8 +-
 xen/common/perfc.c                           |   4 +-
 xen/common/sched/arinc653.c                  |  11 +-
 xen/common/sched/core.c                      |   8 +-
 xen/common/sched/cpupool.c                   |  16 +-
 xen/common/sched/credit.c                    |  10 +-
 xen/common/sched/credit2.c                   |  10 +-
 xen/common/sched/private.h                   |  10 +-
 xen/common/sched/rt.c                        |   4 +
 xen/common/spinlock.c                        |   4 +-
 xen/drivers/char/console.c                   |   4 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c  |  20 +-
 xen/drivers/passthrough/arm/ipmmu-vmsa.c     |  26 +-
 xen/drivers/passthrough/arm/smmu-v3.c        |   6 +
 xen/drivers/passthrough/arm/smmu.c           |  55 ++--
 xen/drivers/passthrough/device_tree.c        | 136 +++++----
 xen/drivers/passthrough/iommu.c              |   2 +
 xen/drivers/passthrough/pci.c                |  52 ++--
 xen/drivers/passthrough/vtd/iommu.c          |   6 +-
 xen/include/hypercall-defs.c                 |  14 +-
 xen/include/xen/device_tree.h                |  13 -
 xen/include/xen/domain.h                     |   4 -
 xen/include/xen/iommu.h                      |   2 +
 xen/include/xsm/dummy.h                      |  22 +-
 xen/include/xsm/xsm.h                        |  52 ++--
 xen/lib/Makefile                             |   5 +
 xen/lib/x86/Makefile                         |   4 +-
 xen/lib/x86/cpuid-cp2buf.c                   | 123 ++++++++
 xen/lib/x86/cpuid-cpfrbuf.c                  | 129 +++++++++
 xen/lib/x86/cpuid.c                          | 286 -------------------
 xen/lib/x86/cpupolicy-clr.c                  |  73 +++++
 xen/xsm/dummy.c                              |  20 +-
 xen/xsm/flask/hooks.c                        |  55 ++--
 73 files changed, 827 insertions(+), 665 deletions(-)
 create mode 100644 xen/lib/x86/cpuid-cp2buf.c
 create mode 100644 xen/lib/x86/cpuid-cpfrbuf.c
 create mode 100644 xen/lib/x86/cpupolicy-clr.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/24 xen/xsm: remove redundant flask_iomem_mapping()

xsm_iomem_mapping() in flask policy seems redundant, as it only provides an extra call layer by calling flask_iomem_permission(). It also has benefit of making a cf_check disappearing too.

---
v2 -> v3:
- new commit
---
v4 -> v5:
- only folding redundant xsm_iomem_mapping() implementation

---
 xen/xsm/flask/hooks.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
xen/xsm/flask/hooks.c +1 -6
index 9f3915617c..a43cd361a2 100644
@@ -1167,11 +1167,6 @@ static int cf_check flask_iomem_permission(
     return security_iterate_iomem_sids(start, end, _iomem_has_perm, &data);
 }
 
-static int cf_check flask_iomem_mapping(struct domain *d, uint64_t start, uint64_t end, uint8_t access)
-{
-    return flask_iomem_permission(d, start, end, access);
-}
-
 static int cf_check flask_pci_config_permission(
     struct domain *d, uint32_t machine_bdf, uint16_t start, uint16_t end,
     uint8_t access)
@@ -1945,7 +1940,7 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .unbind_pt_irq = flask_unbind_pt_irq,
     .irq_permission = flask_irq_permission,
     .iomem_permission = flask_iomem_permission,
-    .iomem_mapping = flask_iomem_mapping,
+    .iomem_mapping = flask_iomem_permission,
     .pci_config_permission = flask_pci_config_permission,
 
     .resource_plug_core = flask_resource_plug_core,
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/24 xen/x86: library-fy cpuid-releated functions

In reply to Penny Zheng

There are some cpuid library functions only referenced in XEN_DOMCTL-case, and shall be wrapped with CONFIG_MGMT_HYPERCALLS later, otherwise they will become unreachable when MGMT_HYPERCALLS=n, and hence violate Misra 2.1
For file cpupolicy-clr.c to contain cpupolicy clearing library function:
- x86_cpu_policy_clear_out_of_range_leaves
- zero_leaves
For file cpuid-cp2buf.c to contain cpuid copy-to-buffer library function:
- x86_cpuid_copy_to_buffer
- copy_leaf_to_buffer
For file cpuid-cpfrbuf.c to contain cpuid copy-from-buffer library function:
- x86_cpuid_copy_from_buffer
Sunmmerize all needed cpuid-library object file under a new variable CPUID_OBJS in Makefile.

---
v4 -> v5:
- library-fy cpuid-releated functions

---
 tools/fuzz/cpu-policy/Makefile               |   4 +-
 tools/fuzz/x86_instruction_emulator/Makefile |  11 +-
 tools/libs/guest/Makefile.common             |   4 +-
 tools/tests/cpu-policy/Makefile              |   3 +-
 tools/tests/x86_emulator/Makefile            |   3 +-
 xen/lib/Makefile                             |   5 +
 xen/lib/x86/cpuid-cp2buf.c                   | 123 ++++++++
 xen/lib/x86/cpuid-cpfrbuf.c                  | 129 +++++++++
 xen/lib/x86/cpuid.c                          | 286 -------------------
 xen/lib/x86/cpupolicy-clr.c                  |  73 +++++
 10 files changed, 346 insertions(+), 295 deletions(-)
 create mode 100644 xen/lib/x86/cpuid-cp2buf.c
 create mode 100644 xen/lib/x86/cpuid-cpfrbuf.c
 create mode 100644 xen/lib/x86/cpupolicy-clr.c
tools/fuzz/cpu-policy/Makefile +3 -1
index 6e7743e0aa..543d265e62 100644
@@ -22,7 +22,9 @@ CFLAGS += $(APPEND_CFLAGS) -Og
 
 vpath %.c ../../../xen/lib/x86
 
-afl-policy-fuzzer: afl-policy-fuzzer.o msr.o cpuid.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+afl-policy-fuzzer: afl-policy-fuzzer.o msr.o $(CPUID_OBJS)
+
 	$(CC) $(CFLAGS) $^ -o $@
 
 -include $(DEPS_INCLUDE)
tools/fuzz/x86_instruction_emulator/Makefile +6 -5
index 459743f4d9..7a0ca79db8 100644
@@ -25,7 +25,8 @@ x86_emulate/%.h: x86_emulate ;
 	ln -nsf $< $@
 
 CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -iquote .
-cpuid.o: CFLAGS += -iquote $(XEN_ROOT)/xen/lib/x86
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+$(CPUID_OBJS): CFLAGS += -iquote $(XEN_ROOT)/xen/lib/x86
 
 GCOV_FLAGS := --coverage
 %-cov.o: %.c
@@ -49,16 +50,16 @@ $(filter x86_emulate/%.o,$(OBJS)): x86_emulate/%.o: x86_emulate/%.c $(private.h)
 $(patsubst %.o,%-cov.o,$(filter x86_emulate/%.o,$(OBJS))): x86_emulate/%-cov.o: x86_emulate/%.c $(private.h)
 	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) $(GCOV_FLAGS) -c -o $@ $< $(APPEND_CFLAGS)
 
-x86-insn-fuzzer.a: $(OBJS) cpuid.o
+x86-insn-fuzzer.a: $(OBJS) $(CPUID_OBJS)
 	$(AR) rc $@ $^
 
-afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
+afl-harness: afl-harness.o $(OBJS) $(CPUID_OBJS) wrappers.o
 	$(CC) $(CFLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
-afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
+afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) $(CPUID_OBJS) wrappers.o
 	$(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
-libfuzzer-harness: $(OBJS) cpuid.o wrappers.o
+libfuzzer-harness: $(OBJS) $(CPUID_OBJS) wrappers.o
 	$(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
 # Common targets
tools/libs/guest/Makefile.common +3 -1
index a026a2f662..7dee6c0e0b 100644
@@ -35,7 +35,9 @@ OBJS-y += $(LIBELF_OBJS)
 ifeq ($(CONFIG_X86),y) # Add libx86 to the build
 vpath %.c ../../../xen/lib/x86
 
-OBJS-y                 += cpuid.o msr.o policy.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+OBJS-y                 += $(CPUID_OBJS)
+OBJS-y                 += msr.o policy.o
 endif
 
 # new domain builder
tools/tests/cpu-policy/Makefile +2 -1
index 24f87e2eca..f99a8b3ea2 100644
@@ -46,7 +46,8 @@ vpath %.c ../../../xen/lib/x86
 
 %.o: Makefile
 
-test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+test-cpu-policy: test-cpu-policy.o msr.o $(CPUID_OBJS) policy.o
 	$(CC) $^ -o $@ $(LDFLAGS)
 
 -include $(DEPS_INCLUDE)
tools/tests/x86_emulator/Makefile +2 -1
index 3e02580a35..2f2bf933d3 100644
@@ -248,7 +248,8 @@ xop.h avx512f.h avx512fp16.h: simd-fma.c
 
 endif # 32-bit override
 
-OBJS := x86-emulate.o cpuid.o test_x86_emulator.o evex-disp8.o predicates.o wrappers.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+OBJS := x86-emulate.o $(CPUID_OBJS) test_x86_emulator.o evex-disp8.o predicates.o wrappers.o
 OBJS += x86_emulate/0f01.o x86_emulate/0fae.o x86_emulate/0fc7.o
 OBJS += x86_emulate/blk.o x86_emulate/decode.o x86_emulate/fpu.o x86_emulate/util.o
 
xen/lib/Makefile +5 -0
index efca830d92..9b3e03a511 100644
@@ -45,3 +45,8 @@ lib-$(CONFIG_X86) += xxhash64.o
 lib32-y := divmod.o
 lib32-$(CONFIG_64BIT) :=
 lib-y += $(lib32-y)
+
+libx86-y := x86/cpuid-cp2buf.o
+libx86-y += x86/cpuid-cpfrbuf.o
+libx86-y += x86/cpupolicy-clr.o
+lib-$(CONFIG_X86) += $(libx86-y)
xen/lib/x86/cpuid-cp2buf.c new file +123 -0

123 lines not on this page · raw message

xen/lib/x86/cpuid-cpfrbuf.c new file +129 -0

129 lines not on this page · raw message

xen/lib/x86/cpuid.c +0 -286

304 lines not on this page · raw message

xen/lib/x86/cpupolicy-clr.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v5 02/24] xen/x86: library-fy cpuid-releated functions

Quoted 4 lines · Penny Zheng

There are some cpuid library functions only referenced in XEN_DOMCTL-case, and shall be wrapped with CONFIG_MGMT_HYPERCALLS later, otherwise they will become unreachable when MGMT_HYPERCALLS=n, and hence violate Misra 2.1

At this point of the series there's no MGMT_HYPERCALLS yet (see also my reply to the cover letter).

Quoted 16 lines

For file cpupolicy-clr.c to contain cpupolicy clearing library function:
- x86_cpu_policy_clear_out_of_range_leaves
- zero_leaves
For file cpuid-cp2buf.c to contain cpuid copy-to-buffer library function:
- x86_cpuid_copy_to_buffer
- copy_leaf_to_buffer
For file cpuid-cpfrbuf.c to contain cpuid copy-from-buffer library function:
- x86_cpuid_copy_from_buffer
Sunmmerize all needed cpuid-library object file under a new variable CPUID_OBJS in Makefile.

---
v4 -> v5:
- library-fy cpuid-releated functions

Quoted 15 lines
---
 tools/fuzz/cpu-policy/Makefile               |   4 +-
 tools/fuzz/x86_instruction_emulator/Makefile |  11 +-
 tools/libs/guest/Makefile.common             |   4 +-
 tools/tests/cpu-policy/Makefile              |   3 +-
 tools/tests/x86_emulator/Makefile            |   3 +-
 xen/lib/Makefile                             |   5 +
 xen/lib/x86/cpuid-cp2buf.c                   | 123 ++++++++
 xen/lib/x86/cpuid-cpfrbuf.c                  | 129 +++++++++
 xen/lib/x86/cpuid.c                          | 286 -------------------
 xen/lib/x86/cpupolicy-clr.c                  |  73 +++++
 10 files changed, 346 insertions(+), 295 deletions(-)
 create mode 100644 xen/lib/x86/cpuid-cp2buf.c
 create mode 100644 xen/lib/x86/cpuid-cpfrbuf.c
 create mode 100644 xen/lib/x86/cpupolicy-clr.c

This looks to be doing at least three things in one go. If all of them would be simple (including them being a reasonably small diff), that may be fine. But the diffstat above says otherwise, so I may I ask that this be split in three, maybe even four pieces (one per function moving to a new file, and maybe one doing prep work in the Makefile-s touched)?

The filenames also aren't very descriptive. cp-from-buffer.c, cp-to-buffer.c, and cp-clear.c maybe? Albeit the last one is where I'm the least convinced that splitting out and making a library function is actually a good idea. Note how I also didn't mention that function as a possible candidate for library- fying. I'll try to not forget to bring this up with the x86 maintainers later in the day.

tools/libs/guest/Makefile.common OBJS-y += $(LIBELF_OBJS) · line 41

Quoted 11 lines
tools/libs/guest/Makefile.common +3 -1
@@ -35,7 +35,9 @@ OBJS-y += $(LIBELF_OBJS)
 ifeq ($(CONFIG_X86),y) # Add libx86 to the build
 vpath %.c ../../../xen/lib/x86
 
-OBJS-y                 += cpuid.o msr.o policy.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o
+OBJS-y                 += $(CPUID_OBJS)
+OBJS-y                 += msr.o policy.o
 endif

Why the mismatched padding on the := line?

xen/lib/Makefile lib-$(CONFIG_X86) += xxhash64.o · line 52

Quoted 11 lines
xen/lib/Makefile +5 -0
@@ -45,3 +45,8 @@ lib-$(CONFIG_X86) += xxhash64.o
 lib32-y := divmod.o
 lib32-$(CONFIG_64BIT) :=
 lib-y += $(lib32-y)
+
+libx86-y := x86/cpuid-cp2buf.o
+libx86-y += x86/cpuid-cpfrbuf.o
+libx86-y += x86/cpupolicy-clr.o
+lib-$(CONFIG_X86) += $(libx86-y)

Why the intermediate libx86-y? And why is this not being done in xen/lib/x86/Makefile anyway?

Jan

#4 lore raw

Re: [PATCH v5 02/24] xen/x86: library-fy cpuid-releated functions

Quoted 47 lines · Jan Beulich
Quoted 4 lines · Penny Zheng

There are some cpuid library functions only referenced in XEN_DOMCTL-case, and shall be wrapped with CONFIG_MGMT_HYPERCALLS later, otherwise they will become unreachable when MGMT_HYPERCALLS=n, and hence violate Misra 2.1

At this point of the series there's no MGMT_HYPERCALLS yet (see also my reply to the cover letter).

Quoted 16 lines

For file cpupolicy-clr.c to contain cpupolicy clearing library function:
- x86_cpu_policy_clear_out_of_range_leaves
- zero_leaves
For file cpuid-cp2buf.c to contain cpuid copy-to-buffer library function:
- x86_cpuid_copy_to_buffer
- copy_leaf_to_buffer
For file cpuid-cpfrbuf.c to contain cpuid copy-from-buffer library function:
- x86_cpuid_copy_from_buffer
Sunmmerize all needed cpuid-library object file under a new variable CPUID_OBJS in Makefile.

---
v4 -> v5:
- library-fy cpuid-releated functions

Quoted 15 lines
---
 tools/fuzz/cpu-policy/Makefile               |   4 +-
 tools/fuzz/x86_instruction_emulator/Makefile |  11 +-
 tools/libs/guest/Makefile.common             |   4 +-
 tools/tests/cpu-policy/Makefile              |   3 +-
 tools/tests/x86_emulator/Makefile            |   3 +-
 xen/lib/Makefile                             |   5 +
 xen/lib/x86/cpuid-cp2buf.c                   | 123 ++++++++
 xen/lib/x86/cpuid-cpfrbuf.c                  | 129 +++++++++
 xen/lib/x86/cpuid.c                          | 286 -------------------
 xen/lib/x86/cpupolicy-clr.c                  |  73 +++++
 10 files changed, 346 insertions(+), 295 deletions(-)
 create mode 100644 xen/lib/x86/cpuid-cp2buf.c
 create mode 100644 xen/lib/x86/cpuid-cpfrbuf.c
 create mode 100644 xen/lib/x86/cpupolicy-clr.c

This looks to be doing at least three things in one go. If all of them would be simple (including them being a reasonably small diff), that may be fine. But the diffstat above says otherwise, so I may I ask that this be split in three, maybe even four pieces (one per function moving to a new file, and maybe one doing prep work in the Makefile-s touched)?

Quoted 6 lines

The filenames also aren't very descriptive. cp-from-buffer.c, cp-to-buffer.c, and cp-clear.c maybe? Albeit the last one is where I'm the least convinced that splitting out and making a library function is actually a good idea. Note how I also didn't mention that function as a possible candidate for library- fying. I'll try to not forget to bring this up with the x86 maintainers later in the day.

Having discussed this, we thought we might as well aim for proper library fication (longer term, i.e. not something we'd ask you to do). Therefore splitting by function is generally okay, but the filenames really want to be sufficiently descriptive. For x86_cpu_policy_clear_out_of_range_leaves() this may very well mean cp-clear-out-of-range-leaves.c (not sure whether shortening to e.g. cp-clear-oor-leaves.c would make sense).

Jan

#5 lore raw

Re: [PATCH v5 02/24] xen/x86: library-fy cpuid-releated functions

In reply to Penny Zheng

tools/fuzz/cpu-policy/Makefile CFLAGS += $(APPEND_CFLAGS) -Og · line 25

Quoted 8 lines · Penny Zheng
tools/fuzz/cpu-policy/Makefile +1 -1
@@ -22,7 +22,9 @@ CFLAGS += $(APPEND_CFLAGS) -Og
 
 vpath %.c ../../../xen/lib/x86
 
-afl-policy-fuzzer: afl-policy-fuzzer.o msr.o cpuid.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o

While I agree all three are needed here, ...

tools/fuzz/x86_instruction_emulator/Makefile x86_emulate/%.h: x86_emulate ; · line 28

Quoted 8 lines
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -25,7 +25,8 @@ x86_emulate/%.h: x86_emulate ;
 	ln -nsf $< $@
 
 CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -iquote .
-cpuid.o: CFLAGS += -iquote $(XEN_ROOT)/xen/lib/x86
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o

... none of them look to be needed e.g. here, and ...

tools/libs/guest/Makefile.common OBJS-y += $(LIBELF_OBJS) · line 38

Quoted 8 lines
tools/libs/guest/Makefile.common +1 -1
@@ -35,7 +35,9 @@ OBJS-y += $(LIBELF_OBJS)
 ifeq ($(CONFIG_X86),y) # Add libx86 to the build
 vpath %.c ../../../xen/lib/x86
 
-OBJS-y                 += cpuid.o msr.o policy.o
+CPUID_OBJS := cpuid.o cpuid-cp2buf.o cpuid-cpfrbuf.o cpupolicy-clr.o

... only two of them look to be needed e.g. here.

Reason I was looking here again is that while talking of the split with the other x86 maintainers, we also discussed the option of moving what is being split out underneath xen/arch/x86/lib/. The way that may want doing, to some degree, depends on whether all "interested" parties want all the functions, which clearly isn't the case.

Jan

#6 lore raw

PATCH v5 3/24 xen/arm: move dt_find_node_by_gpath() to passthrough/device_tree.c

In reply to Penny Zheng

The common/device-tree/device-tree.c contains generic unflatten DT helpers API, while dt_find_node_by_gpath() is specific for domctl (iommu) processing. We move this function into drivers\passthrough\device_tree.c and make it static, as it is used only there now.

---
v4 -> v5:
- new commit

---
 xen/common/device-tree/device-tree.c  | 16 ---------------
 xen/drivers/passthrough/device_tree.c | 28 +++++++++++++++++++++++++++
 xen/include/xen/device_tree.h         | 13 -------------
 3 files changed, 28 insertions(+), 29 deletions(-)
xen/common/device-tree/device-tree.c +0 -16
index 0b5375f151..d6cf417e94 100644
@@ -371,22 +371,6 @@ struct dt_device_node *dt_find_node_by_path_from(struct dt_device_node *from,
     return np;
 }
 
-int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
-                          struct dt_device_node **node)
-{
-    char *path;
-
-    path = safe_copy_string_from_guest(u_path, u_plen, PAGE_SIZE);
-    if ( IS_ERR(path) )
-        return PTR_ERR(path);
-
-    *node = dt_find_node_by_path(path);
-
-    xfree(path);
-
-    return (*node == NULL) ? -ESRCH : 0;
-}
-
 struct dt_device_node *dt_find_node_by_alias(const char *alias)
 {
     const struct dt_alias_prop *app;
xen/drivers/passthrough/device_tree.c +28 -0
index f5850a2607..eb0c233977 100644
@@ -16,6 +16,7 @@
  */
 
 #include <xen/device_tree.h>
+#include <xen/err.h>
 #include <xen/guest_access.h>
 #include <xen/iommu.h>
 #include <xen/lib.h>
@@ -318,6 +319,33 @@ int iommu_add_dt_device(struct dt_device_node *np)
     return rc;
 }
 
+/*
+ * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the
+ * path from the guest
+ *
+ * @u_path: Xen Guest handle to the buffer containing the path
+ * @u_plen: Length of the buffer
+ * @node: TODO
+ *
+ * Return 0 if succeed otherwise -errno
+ */
+static int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path,
+                                 uint32_t u_plen,
+                                 struct dt_device_node **node)
+{
+    char *path;
+
+    path = safe_copy_string_from_guest(u_path, u_plen, PAGE_SIZE);
+    if ( IS_ERR(path) )
+        return PTR_ERR(path);
+
+    *node = dt_find_node_by_path(path);
+
+    xfree(path);
+
+    return (*node == NULL) ? -ESRCH : 0;
+}
+
 int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
xen/include/xen/device_tree.h +0 -13
index 06d7643622..241f269b57 100644
@@ -550,19 +550,6 @@ static inline struct dt_device_node *dt_find_node_by_path(const char *path)
     return dt_find_node_by_path_from(dt_host, path);
 }
 
-/**
- * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the
- * path from the guest
- *
- * @u_path: Xen Guest handle to the buffer containing the path
- * @u_plen: Length of the buffer
- * @node: TODO
- *
- * Return 0 if succeed otherwise -errno
- */
-int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
-                          struct dt_device_node **node);
-
 /**
  * dt_get_parent - Get a node's parent if any
  * @node: Node to get parent
Signature · 1 line
2.34.1
#7 lore raw

PATCH v5 4/24 xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Rename all the CONFIG_SYSCTL into CONFIG_MGMT_HYPERCALLS to help provide a single option to manage all unnecessary hypercalls, including sysctl, domctl, etc, in dom0less system and PV shim mode, which could also make it easier to support randconfigs.
While doing the replacement, we fix some bugs on xsm system:
- wrap the whole xsm function to avoid bringing unreachable codes when MGMT_DOMCTL=n
- add missing wrapping in include/xsm/dummy.h

---
 xen/Kconfig.debug                     |  2 +-
 xen/arch/arm/Makefile                 |  2 +-
 xen/arch/riscv/stubs.c                |  4 ++--
 xen/arch/x86/Makefile                 |  2 +-
 xen/arch/x86/configs/pvshim_defconfig |  2 +-
 xen/arch/x86/psr.c                    | 26 +++++++++++++-------------
 xen/common/Kconfig                    | 15 ++++++++-------
 xen/common/Makefile                   |  2 +-
 xen/common/page_alloc.c               |  8 ++++----
 xen/common/perfc.c                    |  4 ++--
 xen/common/sched/arinc653.c           | 10 +++++-----
 xen/common/sched/core.c               |  6 +++---
 xen/common/sched/cpupool.c            | 16 ++++++++--------
 xen/common/sched/credit.c             |  6 +++---
 xen/common/sched/credit2.c            |  6 +++---
 xen/common/sched/private.h            |  4 ++--
 xen/common/spinlock.c                 |  4 ++--
 xen/drivers/char/console.c            |  4 ++--
 xen/include/hypercall-defs.c          |  4 ++--
 xen/include/xsm/dummy.h               |  6 ++++++
 xen/include/xsm/xsm.h                 | 24 +++++++++---------------
 xen/xsm/dummy.c                       |  6 +++---
 xen/xsm/flask/hooks.c                 | 22 +++++++++++-----------
 23 files changed, 93 insertions(+), 92 deletions(-)
xen/Kconfig.debug +1 -1
index d900d926c5..a69615cd63 100644
@@ -37,7 +37,7 @@ config SELF_TESTS
 
 config COVERAGE
 	bool "Code coverage support"
-	depends on SYSCTL && !LIVEPATCH
+	depends on MGMT_HYPERCALLS && !LIVEPATCH
 	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS if !ENFORCE_UNIQUE_SYMBOLS
 	help
 	  Enable code coverage support.
xen/arch/arm/Makefile +1 -1
index 7494a0f926..069e2c532e 100644
@@ -51,7 +51,7 @@ obj-y += setup.o
 obj-y += shutdown.o
 obj-y += smp.o
 obj-y += smpboot.o
-obj-$(CONFIG_SYSCTL) += sysctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += sysctl.o
 obj-y += time.o
 obj-y += traps.o
 obj-y += vcpreg.o
xen/arch/riscv/stubs.c +2 -2
index fe7d85ee1d..cb19a83280 100644
@@ -267,7 +267,7 @@ unsigned long raw_copy_from_guest(void *to, const void __user *from,
     BUG_ON("unimplemented");
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* sysctl.c */
 
 long arch_do_sysctl(struct xen_sysctl *sysctl,
@@ -280,7 +280,7 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
 {
     BUG_ON("unimplemented");
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* p2m.c */
 
xen/arch/x86/Makefile +1 -1
index 66ce5ad3d7..1e2ce8e72c 100644
@@ -67,7 +67,7 @@ obj-y += smpboot.o
 obj-y += spec_ctrl.o
 obj-y += srat.o
 obj-y += string.o
-obj-$(CONFIG_SYSCTL) += sysctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += sysctl.o
 obj-y += time.o
 obj-y += traps-setup.o
 obj-y += traps.o
xen/arch/x86/configs/pvshim_defconfig +1 -1
index 24f4e4857d..d1db94df78 100644
@@ -25,4 +25,4 @@ CONFIG_PDX_NONE=y
 # CONFIG_INTEL_IOMMU is not set
 # CONFIG_DEBUG is not set
 # CONFIG_GDBSX is not set
-# CONFIG_SYSCTL is not set
+# CONFIG_MGMT_HYPERCALLS is not set
xen/arch/x86/psr.c +13 -13
index cce7020868..80ce5804b4 100644
@@ -135,7 +135,7 @@ static const struct feat_props {
      */
     enum psr_type alt_type;
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     /* get_feat_info is used to return feature HW info through sysctl. */
     bool (*get_feat_info)(const struct feat_node *feat,
                           uint32_t data[], unsigned int array_len);
@@ -422,7 +422,7 @@ static bool mba_init_feature(const struct cpuid_leaf *regs,
     return true;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static bool cf_check cat_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
 {
@@ -435,7 +435,7 @@ static bool cf_check cat_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* L3 CAT props */
 static void cf_check l3_cat_write_msr(
@@ -448,14 +448,14 @@ static const struct feat_props l3_cat_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_L3_CBM,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = cat_get_feat_info,
 #endif
     .write_msr = l3_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* L3 CDP props */
 static bool cf_check l3_cdp_get_feat_info(
     const struct feat_node *feat, uint32_t data[], uint32_t array_len)
@@ -467,7 +467,7 @@ static bool cf_check l3_cdp_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check l3_cdp_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -483,7 +483,7 @@ static const struct feat_props l3_cdp_props = {
     .type[0] = PSR_TYPE_L3_DATA,
     .type[1] = PSR_TYPE_L3_CODE,
     .alt_type = PSR_TYPE_L3_CBM,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = l3_cdp_get_feat_info,
 #endif
     .write_msr = l3_cdp_write_msr,
@@ -501,14 +501,14 @@ static const struct feat_props l2_cat_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_L2_CBM,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = cat_get_feat_info,
 #endif
     .write_msr = l2_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* MBA props */
 static bool cf_check mba_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
@@ -523,7 +523,7 @@ static bool cf_check mba_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check mba_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -561,7 +561,7 @@ static const struct feat_props mba_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_MBA_THRTL,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = mba_get_feat_info,
 #endif
     .write_msr = mba_write_msr,
@@ -826,7 +826,7 @@ static struct psr_socket_info *get_socket_info(unsigned int socket)
     return socket_info + socket;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 int psr_get_info(unsigned int socket, enum psr_type type,
                  uint32_t data[], unsigned int array_len)
 {
@@ -858,7 +858,7 @@ int psr_get_info(unsigned int socket, enum psr_type type,
 
     return -EINVAL;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int psr_get_val(struct domain *d, unsigned int socket,
                 uint32_t *val, enum psr_type type)
xen/common/Kconfig +8 -7
index 218ac3d549..6709c3c95c 100644
@@ -508,7 +508,7 @@ config CRYPTO
 config LIVEPATCH
 	bool "Live patching support"
 	default X86
-	depends on "$(XEN_HAS_BUILD_ID)" = "y" && SYSCTL && HAS_VMAP
+	depends on "$(XEN_HAS_BUILD_ID)" = "y" && MGMT_HYPERCALLS && HAS_VMAP
 	select CC_SPLIT_SECTIONS
 	help
 	  Allows a running Xen hypervisor to be dynamically patched using
@@ -600,7 +600,7 @@ config DTB_FILE
 config TRACEBUFFER
 	bool "Enable tracing infrastructure" if EXPERT
 	default y
-	depends on SYSCTL
+	depends on MGMT_HYPERCALLS
 	help
 	  Enable tracing infrastructure and pre-defined tracepoints within Xen.
 	  This will allow live information about Xen's execution and performance
@@ -651,19 +651,20 @@ config SYSTEM_SUSPEND
 menu "Supported hypercall interfaces"
 	visible if EXPERT
 
-config SYSCTL
-	bool "Enable sysctl hypercall"
+config MGMT_HYPERCALLS
+	bool "Enable privileged hypercalls for system management"
 	depends on !PV_SHIM_EXCLUSIVE
 	default y
 	help
 	  This option shall only be disabled on some dom0less systems, or
-	  PV shim on x86, to reduce Xen footprint.
+	  PV shim on x86, to reduce Xen footprint via managing unnessary
+	  hypercalls, like sysctl, etc.
 
 endmenu
 
 config PM_OP
 	bool "Enable Performance Management Operation"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && HAS_CPUFREQ && MGMT_HYPERCALLS
 	default y
 	help
 	  This option shall enable userspace performance management control
@@ -671,7 +672,7 @@ config PM_OP
 
 config PM_STATS
 	bool "Enable Performance Management Statistics"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && HAS_CPUFREQ && MGMT_HYPERCALLS
 	default y
 	help
 	  Enable collection of performance management statistics to aid in
xen/common/Makefile +1 -1
index 8486c0b510..4353ea59a4 100644
@@ -51,7 +51,7 @@ obj-y += spinlock.o
 obj-$(CONFIG_STACK_PROTECTOR) += stack-protector.o
 obj-y += stop_machine.o
 obj-y += symbols.o
-obj-$(CONFIG_SYSCTL) += sysctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += sysctl.o
 obj-y += tasklet.o
 obj-y += time.o
 obj-y += timer.o
xen/common/page_alloc.c +4 -4
index 1f67b88a89..26615d1e97 100644
@@ -602,7 +602,7 @@ out:
     return ret;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages)
 {
     spin_lock(&heap_lock);
@@ -610,7 +610,7 @@ void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages)
     *free_pages = avail_heap_pages(MEMZONE_XEN + 1, NR_ZONES - 1, -1);
     spin_unlock(&heap_lock);
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static bool __read_mostly first_node_initialised;
 #ifndef CONFIG_SEPARATE_XENHEAP
@@ -1788,7 +1788,7 @@ int offline_page(mfn_t mfn, int broken, uint32_t *status)
     return 0;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * Online the memory.
  *   The caller should make sure end_pfn <= max_page,
@@ -1873,7 +1873,7 @@ int query_page_offline(mfn_t mfn, uint32_t *status)
 
     return 0;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * This function should only be called with valid pages from the same NUMA
xen/common/perfc.c +2 -2
index 0f3b89af2c..97a94ef1fc 100644
@@ -149,7 +149,7 @@ void cf_check perfc_reset(unsigned char key)
     }
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static struct xen_sysctl_perfc_desc perfc_d[NR_PERFCTRS];
 static xen_sysctl_perfc_val_t *perfc_vals;
 static unsigned int      perfc_nbr_vals;
@@ -266,7 +266,7 @@ int perfc_control(struct xen_sysctl_perfc_op *pc)
 
     return rc;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Local variables:
xen/common/sched/arinc653.c +5 -5
index 8a4f4259d8..7d6c40d800 100644
@@ -220,7 +220,7 @@ static void update_schedule_units(const struct scheduler *ops)
                       SCHED_PRIV(ops)->schedule[i].unit_id);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /**
  * This function is called by the adjust_global scheduler hook to put
  * in place a new ARINC653 schedule.
@@ -335,7 +335,7 @@ arinc653_sched_get(
 
     return 0;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /**************************************************************************
  * Scheduler callback functions                                           *
@@ -661,7 +661,7 @@ a653_switch_sched(struct scheduler *new_ops, unsigned int cpu,
     return &sr->_lock;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /**
  * Xen scheduler callback function to perform a global (not domain-specific)
  * adjustment. It is used by the ARINC 653 scheduler to put in place a new
@@ -701,7 +701,7 @@ a653sched_adjust_global(const struct scheduler *ops,
 
     return rc;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /**
  * This structure defines our scheduler for Xen.
@@ -736,7 +736,7 @@ static const struct scheduler sched_arinc653_def = {
     .switch_sched   = a653_switch_sched,
 
     .adjust         = NULL,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = a653sched_adjust_global,
 #endif
 
xen/common/sched/core.c +3 -3
index ec2448cfa1..88150432c3 100644
@@ -2064,7 +2064,7 @@ long do_set_timer_op(s_time_t timeout)
     return 0;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* scheduler_id - fetch ID of current scheduler */
 int scheduler_id(void)
 {
@@ -2107,7 +2107,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     return ret;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 long sched_adjust_global(struct xen_sysctl_scheduler_op *op)
 {
     struct cpupool *pool;
@@ -2136,7 +2136,7 @@ long sched_adjust_global(struct xen_sysctl_scheduler_op *op)
 
     return rc;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void vcpu_periodic_timer_work_locked(struct vcpu *v)
 {
xen/common/sched/cpupool.c +8 -8
index f5459c2779..51ba3cb43d 100644
@@ -241,12 +241,12 @@ struct cpupool *cpupool_get_by_id(unsigned int poolid)
     return __cpupool_get_by_id(poolid, true);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static struct cpupool *cpupool_get_next_by_id(unsigned int poolid)
 {
     return __cpupool_get_by_id(poolid, false);
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void cpupool_put(struct cpupool *pool)
 {
@@ -354,7 +354,7 @@ static struct cpupool *cpupool_create(unsigned int poolid,
 
     return ERR_PTR(ret);
 }
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * destroys the given cpupool
  * returns 0 on success, 1 else
@@ -382,7 +382,7 @@ static int cpupool_destroy(struct cpupool *c)
     debugtrace_printk("cpupool_destroy(pool=%u)\n", c->cpupool_id);
     return 0;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Move domain to another cpupool
@@ -572,7 +572,7 @@ static int cpupool_unassign_cpu_start(struct cpupool *c, unsigned int cpu)
     return ret;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static long cf_check cpupool_unassign_cpu_helper(void *info)
 {
     struct cpupool *c = info;
@@ -638,7 +638,7 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu)
     }
     return continue_hypercall_on_cpu(work_cpu, cpupool_unassign_cpu_helper, c);
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * add a new domain to a cpupool
@@ -816,7 +816,7 @@ static void cpupool_cpu_remove_forced(unsigned int cpu)
     rcu_read_unlock(&sched_res_rculock);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * do cpupool related sysctl operations
  */
@@ -982,7 +982,7 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op)
 
     return ret;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 unsigned int cpupool_get_id(const struct domain *d)
 {
xen/common/sched/credit.c +3 -3
index e9a91d11c3..e8fef6fb51 100644
@@ -1256,7 +1256,7 @@ __csched_set_tslice(struct csched_private *prv, unsigned int timeslice_ms)
     prv->credit = prv->credits_per_tslice * prv->ncpus;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check
 csched_sys_cntl(const struct scheduler *ops,
                         struct xen_sysctl_scheduler_op *sc)
@@ -1299,7 +1299,7 @@ csched_sys_cntl(const struct scheduler *ops,
     out:
     return rc;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void *cf_check
 csched_alloc_domdata(const struct scheduler *ops, struct domain *dom)
@@ -2290,7 +2290,7 @@ static const struct scheduler sched_credit_def = {
 
     .adjust         = csched_dom_cntl,
     .adjust_affinity= csched_aff_cntl,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = csched_sys_cntl,
 #endif
 
xen/common/sched/credit2.c +3 -3
index 75316d42b7..307e63ebd8 100644
@@ -3131,7 +3131,7 @@ csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
         __clear_bit(__CSFLAG_pinned, &svc->flags);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check csched2_sys_cntl(
     const struct scheduler *ops, struct xen_sysctl_scheduler_op *sc)
 {
@@ -3163,7 +3163,7 @@ static int cf_check csched2_sys_cntl(
 
     return 0;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void *cf_check
 csched2_alloc_domdata(const struct scheduler *ops, struct domain *dom)
@@ -4248,7 +4248,7 @@ static const struct scheduler sched_credit2_def = {
 
     .adjust         = csched2_dom_cntl,
     .adjust_affinity= csched2_aff_cntl,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = csched2_sys_cntl,
 #endif
 
xen/common/sched/private.h +2 -2
index d6884550cd..b7ff67200b 100644
@@ -356,7 +356,7 @@ struct scheduler {
                                     struct sched_unit *unit,
                                     const struct cpumask *hard,
                                     const struct cpumask *soft);
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     int          (*adjust_global)  (const struct scheduler *ops,
                                     struct xen_sysctl_scheduler_op *sc);
 #endif
@@ -512,7 +512,7 @@ static inline int sched_adjust_dom(const struct scheduler *s, struct domain *d,
     return s->adjust ? s->adjust(s, d, op) : 0;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int sched_adjust_cpupool(const struct scheduler *s,
                                        struct xen_sysctl_scheduler_op *op)
 {
xen/common/spinlock.c +2 -2
index 0389293b09..9d08159615 100644
@@ -690,7 +690,7 @@ void cf_check spinlock_profile_reset(unsigned char key)
     spinlock_profile_iterate(spinlock_profile_reset_elem, NULL);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 typedef struct {
     struct xen_sysctl_lockprof_op *pc;
     int                      rc;
@@ -750,7 +750,7 @@ int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc)
 
     return rc;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void _lock_profile_register_struct(
     int32_t type, struct lock_profile_qhead *qhead, int32_t idx)
xen/drivers/char/console.c +2 -2
index a996051035..baed7121c3 100644
@@ -371,7 +371,7 @@ static void conring_puts(const char *str, size_t len)
         conringc = conringp - conring_size;
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 long read_console_ring(struct xen_sysctl_readconsole *op)
 {
     XEN_GUEST_HANDLE_PARAM(char) str;
@@ -414,7 +414,7 @@ long read_console_ring(struct xen_sysctl_readconsole *op)
 
     return 0;
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 
 /*
xen/include/hypercall-defs.c +2 -2
index cef08eeec1..4840de805b 100644
@@ -194,7 +194,7 @@ kexec_op(unsigned long op, void *uarg)
 #ifdef CONFIG_IOREQ_SERVER
 dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #endif
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
@@ -277,7 +277,7 @@ physdev_op                         compat   do       hvm      hvm      do_arm
 #ifdef CONFIG_HVM
 hvm_op                             do       do       do       do       do
 #endif
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 sysctl                             do       do       do       do       do
 #endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
xen/include/xsm/dummy.h +6 -0
index e801dbcdba..df8d737c18 100644
@@ -148,11 +148,13 @@ static XSM_INLINE int cf_check xsm_domctl_scheduler_op(
     return xsm_default_action(action, current->domain, d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_sysctl_scheduler_op(XSM_DEFAULT_ARG int cmd)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, NULL);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_set_target(
     XSM_DEFAULT_ARG struct domain *d, struct domain *e)
@@ -180,6 +182,7 @@ static XSM_INLINE int cf_check xsm_domctl(
     }
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_sysctl(XSM_DEFAULT_ARG int cmd)
 {
     XSM_ASSERT_ACTION(XSM_PRIV);
@@ -191,6 +194,7 @@ static XSM_INLINE int cf_check xsm_readconsole(XSM_DEFAULT_ARG uint32_t clear)
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, NULL);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_alloc_security_domain(struct domain *d)
 {
@@ -485,11 +489,13 @@ static XSM_INLINE int cf_check xsm_resource_setup_misc(XSM_DEFAULT_VOID)
     return xsm_default_action(action, current->domain, NULL);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_page_offline(XSM_DEFAULT_ARG uint32_t cmd)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, NULL);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_hypfs_op(XSM_DEFAULT_VOID)
 {
xen/include/xsm/xsm.h +9 -15
index 2d831d7745..d20d4ae657 100644
@@ -57,13 +57,15 @@ struct xsm_ops {
     int (*domain_create)(struct domain *d, uint32_t ssidref);
     int (*getdomaininfo)(struct domain *d);
     int (*domctl_scheduler_op)(struct domain *d, int op);
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     int (*sysctl_scheduler_op)(int op);
 #endif
     int (*set_target)(struct domain *d, struct domain *e);
     int (*domctl)(struct domain *d, unsigned int cmd, uint32_t ssidref);
+#ifdef CONFIG_MGMT_HYPERCALLS
     int (*sysctl)(int cmd);
     int (*readconsole)(uint32_t clear);
+#endif
 
     int (*evtchn_unbound)(struct domain *d, struct evtchn *chn, domid_t id2);
     int (*evtchn_interdomain)(struct domain *d1, struct evtchn *chn1,
@@ -140,7 +142,7 @@ struct xsm_ops {
     int (*resource_setup_gsi)(int gsi);
     int (*resource_setup_misc)(void);
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     int (*page_offline)(uint32_t cmd);
 #endif
     int (*hypfs_op)(void);
@@ -246,7 +248,7 @@ static inline int xsm_domctl_scheduler_op(
     return alternative_call(xsm_ops.domctl_scheduler_op, d, cmd);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
 {
     return alternative_call(xsm_ops.sysctl_scheduler_op, cmd);
@@ -265,23 +267,17 @@ static inline int xsm_domctl(xsm_default_t def, struct domain *d,
     return alternative_call(xsm_ops.domctl, d, cmd, ssidref);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_sysctl(xsm_default_t def, int cmd)
 {
-#ifdef CONFIG_SYSCTL
     return alternative_call(xsm_ops.sysctl, cmd);
-#else
-    return -EOPNOTSUPP;
-#endif
 }
 
 static inline int xsm_readconsole(xsm_default_t def, uint32_t clear)
 {
-#ifdef CONFIG_SYSCTL
     return alternative_call(xsm_ops.readconsole, clear);
-#else
-    return -EOPNOTSUPP;
-#endif
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline int xsm_evtchn_unbound(
     xsm_default_t def, struct domain *d1, struct evtchn *chn, domid_t id2)
@@ -601,14 +597,12 @@ static inline int xsm_resource_setup_misc(xsm_default_t def)
     return alternative_call(xsm_ops.resource_setup_misc);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_page_offline(xsm_default_t def, uint32_t cmd)
 {
-#ifdef CONFIG_SYSCTL
     return alternative_call(xsm_ops.page_offline, cmd);
-#else
-    return -EOPNOTSUPP;
-#endif
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline int xsm_hypfs_op(xsm_default_t def)
 {
xen/xsm/dummy.c +3 -3
index 96dc82ac2e..2c70b979d6 100644
@@ -19,12 +19,12 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .domain_create                 = xsm_domain_create,
     .getdomaininfo                 = xsm_getdomaininfo,
     .domctl_scheduler_op           = xsm_domctl_scheduler_op,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
 #endif
     .set_target                    = xsm_set_target,
     .domctl                        = xsm_domctl,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl                        = xsm_sysctl,
     .readconsole                   = xsm_readconsole,
 #endif
@@ -98,7 +98,7 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .resource_setup_gsi            = xsm_resource_setup_gsi,
     .resource_setup_misc           = xsm_resource_setup_misc,
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .page_offline                  = xsm_page_offline,
 #endif
     .hypfs_op                      = xsm_hypfs_op,
xen/xsm/flask/hooks.c +11 -11
index a43cd361a2..490823913e 100644
@@ -626,7 +626,7 @@ static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
     }
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_sysctl_scheduler_op(int op)
 {
     switch ( op )
@@ -641,7 +641,7 @@ static int cf_check flask_sysctl_scheduler_op(int op)
         return avc_unknown_permission("sysctl_scheduler_op", op);
     }
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int cf_check flask_set_target(struct domain *d, struct domain *t)
 {
@@ -858,7 +858,7 @@ static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
     }
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_sysctl(int cmd)
 {
     switch ( cmd )
@@ -946,7 +946,7 @@ static int cf_check flask_readconsole(uint32_t clear)
 
     return domain_has_xen(current->domain, perms);
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline uint32_t resource_to_perm(uint8_t access)
 {
@@ -1203,12 +1203,12 @@ static int cf_check flask_resource_unplug_core(void)
     return avc_current_has_perm(SECINITSID_DOMXEN, SECCLASS_RESOURCE, RESOURCE__UNPLUG, NULL);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int flask_resource_use_core(void)
 {
     return avc_current_has_perm(SECINITSID_DOMXEN, SECCLASS_RESOURCE, RESOURCE__USE, NULL);
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int cf_check flask_resource_plug_pci(uint32_t machine_bdf)
 {
@@ -1273,7 +1273,7 @@ static int cf_check flask_resource_setup_misc(void)
     return avc_current_has_perm(SECINITSID_XEN, SECCLASS_RESOURCE, RESOURCE__SETUP, NULL);
 }
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int cf_check flask_page_offline(uint32_t cmd)
 {
     switch ( cmd )
@@ -1288,7 +1288,7 @@ static inline int cf_check flask_page_offline(uint32_t cmd)
         return avc_unknown_permission("page_offline", cmd);
     }
 }
-#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline int cf_check flask_hypfs_op(void)
 {
@@ -1884,12 +1884,12 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .domain_create = flask_domain_create,
     .getdomaininfo = flask_getdomaininfo,
     .domctl_scheduler_op = flask_domctl_scheduler_op,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
 #endif
     .set_target = flask_set_target,
     .domctl = flask_domctl,
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl = flask_sysctl,
     .readconsole = flask_readconsole,
 #endif
@@ -1951,7 +1951,7 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .resource_setup_gsi = flask_resource_setup_gsi,
     .resource_setup_misc = flask_resource_setup_misc,
 
-#ifdef CONFIG_SYSCTL
+#ifdef CONFIG_MGMT_HYPERCALLS
     .page_offline = flask_page_offline,
 #endif
     .hypfs_op = flask_hypfs_op,
Signature · 1 line
2.34.1
#8 lore raw

PATCH v5 5/24 xen/domctl: make MGMT_HYPERCALLS transiently def_bool

In reply to Penny Zheng

In order to asist in reviewing/developing disabling domctl-op patch serie, we will transiently make MGMT_HYPERCALLS def_bool. And it will become optional at the last of domctl-op patch serie, where common/domctl.o's building as a whole becomes dependent upon that setting.

---
v2 -> v3:
- new commit
---
v4 -> v5:
- Remove "bool xxx" is to actually remove prompt

---
 xen/common/Kconfig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/common/Kconfig +1 -2
index 6709c3c95c..7f7ed62f78 100644
@@ -652,9 +652,8 @@ menu "Supported hypercall interfaces"
 	visible if EXPERT
 
 config MGMT_HYPERCALLS
-	bool "Enable privileged hypercalls for system management"
+	def_bool y
 	depends on !PV_SHIM_EXCLUSIVE
-	default y
 	help
 	  This option shall only be disabled on some dom0less systems, or
 	  PV shim on x86, to reduce Xen footprint via managing unnessary
Signature · 1 line
2.34.1
#9 lore raw

PATCH v5 6/24 xen/vm_event: make VM_EVENT depend on CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

VM event could only be enabled/disabled via vm_event domctl-op, so CONFIG_VM_EVENT shall depend on CONFIG_MGMT_HYPERCALLS

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"

---
 xen/common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/Kconfig +1 -1
index 7f7ed62f78..2914508a8f 100644
@@ -175,7 +175,7 @@ config LIBFDT
 
 config VM_EVENT
 	bool "Memory Access and VM events"
-	depends on HVM
+	depends on HVM && MGMT_HYPERCALLS
 	default X86
 	help
 
Signature · 1 line
2.34.1
#10 lore raw

PATCH v5 7/24 xen/domctl: consolidate domain.c towards MGMT_HYPERCALLS

In reply to Penny Zheng

The following functions, scattered in common/domain.c, and are only referenced and responsible for domctl-op:
- domain_pause_by_systemcontroller
- domain_resume
- domain_set_node_affinity
So they shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1.
Move them together to avoid scattering #ifdef. And add a leading blank before label to conform to ./CODING_STYLE.

---
v3 - v4:
- combine commit "xen/domctl: wrap domain_pause_by_systemcontroller() with MGMT_HYPERCALLS", "xen/domctl: wrap domain_resume() with CONFIG_MGMT_HYPERCALLS", and "xen/domctl: wrap domain_set_node_affinity() with CONFIG_MGMT_HYPERCALLS"
---
v4 -> v5:
- coding format correction and title refinement

---
 xen/common/domain.c | 114 ++++++++++++++++++++++----------------------
 1 file changed, 58 insertions(+), 56 deletions(-)
xen/common/domain.c +58 -56
index 93c71bc766..f24f3675aa 100644
@@ -1125,35 +1125,6 @@ void __init setup_system_domains(void)
 #endif
 }
 
-int domain_set_node_affinity(struct domain *d, const nodemask_t *affinity)
-{
-    /* Being disjoint with the system is just wrong. */
-    if ( !nodes_intersects(*affinity, node_online_map) )
-        return -EINVAL;
-
-    spin_lock(&d->node_affinity_lock);
-
-    /*
-     * Being/becoming explicitly affine to all nodes is not particularly
-     * useful. Let's take it as the `reset node affinity` command.
-     */
-    if ( nodes_full(*affinity) )
-    {
-        d->auto_node_affinity = 1;
-        goto out;
-    }
-
-    d->auto_node_affinity = 0;
-    d->node_affinity = *affinity;
-
-out:
-    spin_unlock(&d->node_affinity_lock);
-
-    domain_update_node_affinity(d);
-
-    return 0;
-}
-
 /* rcu_read_lock(&domlist_read_lock) must be held. */
 static struct domain *domid_to_domain(domid_t dom)
 {
@@ -1371,33 +1342,6 @@ int domain_shutdown(struct domain *d, u8 reason)
     return 0;
 }
 
-void domain_resume(struct domain *d)
-{
-    struct vcpu *v;
-
-    /*
-     * Some code paths assume that shutdown status does not get reset under
-     * their feet (e.g., some assertions make this assumption).
-     */
-    domain_pause(d);
-
-    spin_lock(&d->shutdown_lock);
-
-    d->is_shutting_down = d->is_shut_down = 0;
-    d->shutdown_code = SHUTDOWN_CODE_INVALID;
-
-    for_each_vcpu ( d, v )
-    {
-        if ( v->paused_for_shutdown )
-            vcpu_unpause(v);
-        v->paused_for_shutdown = 0;
-    }
-
-    spin_unlock(&d->shutdown_lock);
-
-    domain_unpause(d);
-}
-
 int vcpu_start_shutdown_deferral(struct vcpu *v)
 {
     if ( v->defer_shutdown )
@@ -1626,10 +1570,68 @@ static int _domain_pause_by_systemcontroller(struct domain *d, bool sync)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
+int domain_set_node_affinity(struct domain *d, const nodemask_t *affinity)
+{
+    /* Being disjoint with the system is just wrong. */
+    if ( !nodes_intersects(*affinity, node_online_map) )
+        return -EINVAL;
+
+    spin_lock(&d->node_affinity_lock);
+
+    /*
+     * Being/becoming explicitly affine to all nodes is not particularly
+     * useful. Let's take it as the `reset node affinity` command.
+     */
+    if ( nodes_full(*affinity) )
+    {
+        d->auto_node_affinity = 1;
+        goto out;
+    }
+
+    d->auto_node_affinity = 0;
+    d->node_affinity = *affinity;
+
+ out:
+    spin_unlock(&d->node_affinity_lock);
+
+    domain_update_node_affinity(d);
+
+    return 0;
+}
+
+void domain_resume(struct domain *d)
+{
+    struct vcpu *v;
+
+    /*
+     * Some code paths assume that shutdown status does not get reset under
+     * their feet (e.g., some assertions make this assumption).
+     */
+    domain_pause(d);
+
+    spin_lock(&d->shutdown_lock);
+
+    d->is_shutting_down = d->is_shut_down = 0;
+    d->shutdown_code = SHUTDOWN_CODE_INVALID;
+
+    for_each_vcpu ( d, v )
+    {
+        if ( v->paused_for_shutdown )
+            vcpu_unpause(v);
+        v->paused_for_shutdown = 0;
+    }
+
+    spin_unlock(&d->shutdown_lock);
+
+    domain_unpause(d);
+}
+
 int domain_pause_by_systemcontroller(struct domain *d)
 {
     return _domain_pause_by_systemcontroller(d, true /* sync */);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int domain_pause_by_systemcontroller_nosync(struct domain *d)
 {
Signature · 1 line
2.34.1
#11 lore raw

PATCH v5 8/24 xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS

In reply to Penny Zheng

The enabling bit (d->arch.hvm.mem_sharing.enabled) for memory sharing could only be enabled via domctl-op, so we shall make memory sharing feature depend on MGMT_HYPERCALLS.

---
v3 -> v4:
- new commit

---
 xen/arch/x86/hvm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/Kconfig +1 -0
index 25eb3e374f..df9bea65b0 100644
@@ -79,5 +79,6 @@ config MEM_PAGING
 config MEM_SHARING
 	bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED
 	depends on INTEL_VMX
+	depends on MGMT_HYPERCALLS
 
 endif
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v5 08/24] xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS

Quoted 5 lines · Penny Zheng

The enabling bit (d->arch.hvm.mem_sharing.enabled) for memory sharing could only be enabled via domctl-op, so we shall make memory sharing feature depend on MGMT_HYPERCALLS.

Tamas,

this is something that rather you should ack (or reject). (Penny, you would have wanted to Cc Tamas here right away, no matter what F: entries in ./MAINTAINERS would say.)

Thanks, Jan

Quoted 9 lines
xen/arch/x86/hvm/Kconfig +1 -0
@@ -79,5 +79,6 @@ config MEM_PAGING
 config MEM_SHARING
 	bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED
 	depends on INTEL_VMX
+	depends on MGMT_HYPERCALLS
 
 endif
#13 lore raw

Re: [PATCH v5 08/24] xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS

Quoted 7 lines · Jan Beulich
Quoted 5 lines · Penny Zheng

The enabling bit (d->arch.hvm.mem_sharing.enabled) for memory sharing could only be enabled via domctl-op, so we shall make memory sharing feature depend on MGMT_HYPERCALLS.

Quoted 8 lines

Tamas,

this is something that rather you should ack (or reject). (Penny, you would have wanted to Cc Tamas here right away, no matter what F: entries in ./MAINTAINERS would say.)

Thanks, Jan

Thanks, seems fine to me.

Tamas

#14 lore raw

RE: [PATCH v5 08/24] xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS

[Public]

Quoted 13 lines

-----Original Message-----
From: Tamas K Lengyel <[email protected]>
Sent: Saturday, December 13, 2025 8:21 AM
To: Jan Beulich <[email protected]>
Cc: Penny, Zheng <[email protected]>; Huang, Ray <[email protected]>; [email protected]; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 08/24] xen/mem_sharing: make memory sharing depend on MGMT_HYPERCALLS

Quoted 1 line · Jan Beulich
Quoted 8 lines
Quoted 6 lines · Penny Zheng
Quoted 5 lines

The enabling bit (d->arch.hvm.mem_sharing.enabled) for memory sharing could only be enabled via domctl-op, so we shall make memory sharing feature depend on MGMT_HYPERCALLS.

Thx

Quoted 13 lines
Quoted 9 lines

Tamas,

this is something that rather you should ack (or reject). (Penny, you would have wanted to Cc Tamas here right away, no matter what F:
entries in ./MAINTAINERS would say.)

Thanks, Jan

Thanks, seems fine to me.

Tamas

#15 lore raw

PATCH v5 9/24 xen/domctl: wrap domain_kill() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function domain_kill() is responsible for killing domain and relinquish domain-held resources. and it is only invoked under XEN_DOMCTL_destroydomain-case. So it shall be wrapped with CONFIG_MGMT_HYPERCALLS.
Tracking its calling chain, the following functions could also be wrapped with CONFIG_MGMT_HYPERCALLS:
- domain_relinquish_resource
- pci_release_device
- paging_teardown
- p2m_pod_empty_cache
- relinquish_memory
- pit_deinit
- iommu_release_dt_devices
- tee_relinquish_resources
- ffa_relinquish_resources/optee_relinquish_resources
- relinquish_p2m_mapping
- p2m_clear_root_pages
Otherwise all these functions will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1.
The reason why {arch_}domain_teardown() is not wrapped is that it is also used on the failure path of domain_create(). And the exclusion of paging_final_teardown() is blocked by domain_destroy(), which will be triggered when d->refcnt equals zero.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_destroydomain-case transiently
---
v2 -> v3:
- add back stub wrapping in ppc/riscv
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around XEN_DOMCTL_destroydomain-case
---
v3 -> v4:
- remove diff in mem_sharing.c
- add description for some functions to aid review

---
 xen/arch/arm/domain.c                 | 3 +++
 xen/arch/arm/include/asm/tee/tee.h    | 2 ++
 xen/arch/arm/mmu/p2m.c                | 4 ++++
 xen/arch/arm/mpu/p2m.c                | 2 ++
 xen/arch/arm/tee/ffa.c                | 4 ++++
 xen/arch/arm/tee/optee.c              | 4 ++++
 xen/arch/arm/tee/tee.c                | 2 ++
 xen/arch/ppc/stubs.c                  | 2 ++
 xen/arch/riscv/stubs.c                | 2 ++
 xen/arch/x86/domain.c                 | 2 ++
 xen/arch/x86/emul-i8254.c             | 2 ++
 xen/arch/x86/mm/p2m-pod.c             | 2 ++
 xen/arch/x86/mm/p2m.c                 | 2 ++
 xen/arch/x86/mm/paging.c              | 2 ++
 xen/common/domain.c                   | 2 ++
 xen/drivers/passthrough/device_tree.c | 2 ++
 xen/drivers/passthrough/pci.c         | 2 ++
 17 files changed, 41 insertions(+)
xen/arch/arm/domain.c +3 -0
index 47973f99d9..049cc8923b 100644
@@ -959,6 +959,7 @@ int arch_vcpu_reset(struct vcpu *v)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int relinquish_memory(struct domain *d, struct page_list_head *list)
 {
     struct page_info *page, *tmp;
@@ -1110,6 +1111,8 @@ int domain_relinquish_resources(struct domain *d)
 
 #undef PROGRESS
 
+#endif /* CONFIG_MGMT_HYPERCALLS */
+
 void arch_dump_domain_info(struct domain *d)
 {
     p2m_dump_info(d);
xen/arch/arm/include/asm/tee/tee.h +2 -0
index 15d664e28d..f4187c5dc3 100644
@@ -40,12 +40,14 @@ struct tee_mediator_ops {
     int (*domain_teardown)(struct domain *d);
     void (*free_domain_ctx)(struct domain *d);
 
+#ifdef CONFIG_MGMT_HYPERCALLS
     /*
      * Called during domain destruction to relinquish resources used
      * by mediator itself. This function can return -ERESTART to indicate
      * that it does not finished work and should be called again.
      */
     int (*relinquish_resources)(struct domain *d);
+#endif
 
     /* Handle SMCCC call for current domain. */
     bool (*handle_call)(struct cpu_user_regs *regs);
xen/arch/arm/mmu/p2m.c +4 -0
index 51abf3504f..30d6071e91 100644
@@ -1243,6 +1243,7 @@ static void p2m_invalidate_table(struct p2m_domain *p2m, mfn_t mfn)
     p2m->need_flush = true;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * The domain will not be scheduled anymore, so in theory we should
  * not need to flush the TLBs. Do it for safety purpose.
@@ -1262,6 +1263,7 @@ void p2m_clear_root_pages(struct p2m_domain *p2m)
 
     p2m_write_unlock(p2m);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Invalidate all entries in the root page-tables. This is
@@ -1556,6 +1558,7 @@ int p2m_init(struct domain *d)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * The function will go through the p2m and remove page reference when it
  * is required. The mapping will be removed from the p2m.
@@ -1626,6 +1629,7 @@ int relinquish_p2m_mapping(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Clean & invalidate RAM associated to the guest vCPU.
xen/arch/arm/mpu/p2m.c +2 -0
index f7fb58ab6a..c44297a9e3 100644
@@ -57,10 +57,12 @@ bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn)
 
 void p2m_flush_vm(struct vcpu *v) {}
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int relinquish_p2m_mapping(struct domain *d)
 {
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void p2m_domain_creation_finished(struct domain *d) {}
 
xen/arch/arm/tee/ffa.c +4 -0
index 1d0239cf69..f9ba9b60bf 100644
@@ -469,10 +469,12 @@ static void ffa_free_domain_ctx(struct domain *d)
     XFREE(d->arch.tee);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int ffa_relinquish_resources(struct domain *d)
 {
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void ffa_init_secondary(void)
 {
@@ -623,7 +625,9 @@ static const struct tee_mediator_ops ffa_ops =
     .domain_init = ffa_domain_init,
     .domain_teardown = ffa_domain_teardown,
     .free_domain_ctx = ffa_free_domain_ctx,
+#ifdef CONFIG_MGMT_HYPERCALLS
     .relinquish_resources = ffa_relinquish_resources,
+#endif
     .handle_call = ffa_handle_call,
 };
 
xen/arch/arm/tee/optee.c +4 -0
index 5151bd90ed..1ed0fd231d 100644
@@ -632,6 +632,7 @@ static void free_optee_shm_buf_pg_list(struct optee_domain *ctx,
                  cookie);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int optee_relinquish_resources(struct domain *d)
 {
     struct arm_smccc_res resp;
@@ -693,6 +694,7 @@ static int optee_relinquish_resources(struct domain *d)
 
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 #define PAGELIST_ENTRIES_PER_PAGE                       \
     ((OPTEE_MSG_NONCONTIG_PAGE_SIZE / sizeof(u64)) - 1)
@@ -1727,7 +1729,9 @@ static const struct tee_mediator_ops optee_ops =
     .probe = optee_probe,
     .domain_init = optee_domain_init,
     .domain_teardown = optee_domain_teardown,
+#ifdef CONFIG_MGMT_HYPERCALLS
     .relinquish_resources = optee_relinquish_resources,
+#endif
     .handle_call = optee_handle_call,
 };
 
xen/arch/arm/tee/tee.c +2 -0
index 8501443c8e..a8e160700f 100644
@@ -65,6 +65,7 @@ int tee_domain_teardown(struct domain *d)
     return cur_mediator->ops->domain_teardown(d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int tee_relinquish_resources(struct domain *d)
 {
     if ( !cur_mediator )
@@ -72,6 +73,7 @@ int tee_relinquish_resources(struct domain *d)
 
     return cur_mediator->ops->relinquish_resources(d);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 uint16_t tee_get_type(void)
 {
xen/arch/ppc/stubs.c +2 -0
index 9953ea1c6c..4d03a927ee 100644
@@ -229,10 +229,12 @@ int arch_vcpu_reset(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int domain_relinquish_resources(struct domain *d)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void arch_dump_domain_info(struct domain *d)
 {
xen/arch/riscv/stubs.c +2 -0
index cb19a83280..c2e6af2c43 100644
@@ -203,10 +203,12 @@ int arch_vcpu_reset(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int domain_relinquish_resources(struct domain *d)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void arch_dump_domain_info(struct domain *d)
 {
xen/arch/x86/domain.c +2 -0
index 5e37bfbd17..b103301d7a 100644
@@ -2289,6 +2289,7 @@ void sync_vcpu_execstate(struct vcpu *v)
            read_atomic(&v->dirty_cpu) != dirty_cpu);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int relinquish_memory(
     struct domain *d, struct page_list_head *list, unsigned long type)
 {
@@ -2613,6 +2614,7 @@ int domain_relinquish_resources(struct domain *d)
 
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void arch_dump_domain_info(struct domain *d)
 {
xen/arch/x86/emul-i8254.c +2 -0
index 144aa168a3..f106ab794c 100644
@@ -651,6 +651,7 @@ void pit_init(struct domain *d)
     pit_reset(d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void pit_deinit(struct domain *d)
 {
     PITState *pit = domain_vpit(d);
@@ -664,6 +665,7 @@ void pit_deinit(struct domain *d)
         destroy_periodic_time(&pit->pt0);
     }
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Local variables:
xen/arch/x86/mm/p2m-pod.c +2 -0
index 05633fe2ac..4e915808f4 100644
@@ -366,6 +366,7 @@ void p2m_pod_get_mem_target(const struct domain *d, xen_pod_target_t *target)
     pod_unlock(p2m);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int p2m_pod_empty_cache(struct domain *d)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
@@ -409,6 +410,7 @@ int p2m_pod_empty_cache(struct domain *d)
     unlock_page_alloc(p2m);
     return p2m->pod.count ? -ERESTART : 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int
 p2m_pod_offline_or_broken_hit(struct page_info *p)
xen/arch/x86/mm/p2m.c +2 -0
index 2763f9a6be..a5db8e6d4a 100644
@@ -2097,6 +2097,7 @@ int xenmem_add_to_physmap_one(
     return rc;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * Remove foreign mappings from the p2m, as that drops the page reference taken
  * when mapped.
@@ -2160,6 +2161,7 @@ int relinquish_p2m_mapping(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void p2m_log_dirty_range(struct domain *d, unsigned long begin_pfn,
                          unsigned long nr, uint8_t *dirty_bitmap)
xen/arch/x86/mm/paging.c +2 -0
index 65455a6867..116389d4e9 100644
@@ -768,6 +768,7 @@ void paging_vcpu_teardown(struct vcpu *v)
         shadow_vcpu_teardown(v);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* Call when destroying a domain */
 int paging_teardown(struct domain *d)
 {
@@ -794,6 +795,7 @@ int paging_teardown(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* Call once all of the references to the domain have gone away */
 void paging_final_teardown(struct domain *d)
xen/common/domain.c +2 -0
index f24f3675aa..6819494649 100644
@@ -1221,6 +1221,7 @@ int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int domain_kill(struct domain *d)
 {
     int rc = 0;
@@ -1271,6 +1272,7 @@ int domain_kill(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 
 void __domain_crash(struct domain *d)
xen/drivers/passthrough/device_tree.c +2 -0
index eb0c233977..bdbae0f8bf 100644
@@ -109,6 +109,7 @@ int iommu_dt_domain_init(struct domain *d)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int iommu_release_dt_devices(struct domain *d)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -137,6 +138,7 @@ int iommu_release_dt_devices(struct domain *d)
 
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int iommu_dt_xlate(struct device *dev,
                           const struct dt_phandle_args *iommu_spec,
xen/drivers/passthrough/pci.c +2 -0
index 52c22fa50c..422e45f5a6 100644
@@ -946,6 +946,7 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus,
     return ret;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int pci_release_devices(struct domain *d)
 {
     int combined_ret;
@@ -1004,6 +1005,7 @@ int pci_release_devices(struct domain *d)
 
     return combined_ret;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 #define PCI_CLASS_BRIDGE_HOST    0x0600
 #define PCI_CLASS_BRIDGE_PCI     0x0604
Signature · 1 line
2.34.1
#16 lore raw

PATCH v5 10/24 xen/domctl: wrap vcpu_affinity_domctl() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function vcpu_affinity_domctl() is responsible for XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity} domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1. Tracking its calling chain, vcpuaffinity_params_invalid() also needs wrapping too

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity}-case transiently
---
v2 -> v3:
- adapt to changes of "remove vcpu_set_soft_affinity()"
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity}-case
---
v3 -> v4
- wrap vcpuaffinity_params_invalid()

---
 xen/common/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)
xen/common/sched/core.c +2 -0
index 88150432c3..83e34e7c05 100644
@@ -1678,6 +1678,7 @@ int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reason)
     return ret;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline
 int vcpuaffinity_params_invalid(const struct xen_domctl_vcpuaffinity *vcpuaff)
 {
@@ -1798,6 +1799,7 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
 
     return ret;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 bool alloc_affinity_masks(struct affinity_masks *affinity)
 {
Signature · 1 line
2.34.1
Reviewed-by on v5 10/24
#17 lore raw

Re: [PATCH v5 10/24] xen/domctl: wrap vcpu_affinity_domctl() with CONFIG_MGMT_HYPERCALLS

Quoted 8 lines · Penny Zheng

Function vcpu_affinity_domctl() is responsible for XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity} domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1. Tracking its calling chain, vcpuaffinity_params_invalid() also needs wrapping too

Juergen

#18 lore raw

PATCH v5 11/24 xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function sched_adjust() is responsible for XEN_DOMCTL_scheduler_op domctl-op, so it could be wrapped with CONFIG_MGMT_HYPERCALLS.
Tracing its calling chain, the following functions shall be wrapped with CONFIG_MGMT_HYPERCALLS too:
- sched_adjust_dom()
- scheduler-specific .adjust() callback
- xsm_sysctl_scheduler_op()
Otherwise all these functions will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_scheduler_op-case transiently
---
v2 -> v3
- add missing wrapping in xsm/dummy.h
- move and get away with just a single #ifdef
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around XEN_DOMCTL_scheduler_op-case

---
 xen/common/sched/arinc653.c | 1 -
 xen/common/sched/core.c     | 2 --
 xen/common/sched/credit.c   | 4 +++-
 xen/common/sched/credit2.c  | 4 +++-
 xen/common/sched/private.h  | 8 ++++----
 xen/common/sched/rt.c       | 4 ++++
 xen/include/xsm/dummy.h     | 2 ++
 xen/include/xsm/xsm.h       | 4 ++--
 xen/xsm/dummy.c             | 2 +-
 xen/xsm/flask/hooks.c       | 4 ++--
 10 files changed, 21 insertions(+), 14 deletions(-)
xen/common/sched/arinc653.c +0 -1
index 7d6c40d800..5a6f8c8642 100644
@@ -735,7 +735,6 @@ static const struct scheduler sched_arinc653_def = {
 
     .switch_sched   = a653_switch_sched,
 
-    .adjust         = NULL,
 #ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = a653sched_adjust_global,
 #endif
xen/common/sched/core.c +0 -2
index 83e34e7c05..0943cb1e97 100644
@@ -2072,7 +2072,6 @@ int scheduler_id(void)
 {
     return operations.sched_id;
 }
-#endif
 
 /* Adjust scheduling parameter for a given domain. */
 long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
@@ -2109,7 +2108,6 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     return ret;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 long sched_adjust_global(struct xen_sysctl_scheduler_op *op)
 {
     struct cpupool *pool;
xen/common/sched/credit.c +3 -1
index e8fef6fb51..54a4def362 100644
@@ -1183,6 +1183,7 @@ csched_unit_yield(const struct scheduler *ops, struct sched_unit *unit)
     set_bit(CSCHED_FLAG_UNIT_YIELD, &svc->flags);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check
 csched_dom_cntl(
     const struct scheduler *ops,
@@ -1227,6 +1228,7 @@ csched_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check
 csched_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -2288,9 +2290,9 @@ static const struct scheduler sched_credit_def = {
     .wake           = csched_unit_wake,
     .yield          = csched_unit_yield,
 
-    .adjust         = csched_dom_cntl,
     .adjust_affinity= csched_aff_cntl,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .adjust         = csched_dom_cntl,
     .adjust_global  = csched_sys_cntl,
 #endif
 
xen/common/sched/credit2.c +3 -1
index 307e63ebd8..b73dd3c548 100644
@@ -2909,6 +2909,7 @@ static void cf_check csched2_unit_migrate(
         sched_set_res(unit, get_sched_res(new_cpu));
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check
 csched2_dom_cntl(
     const struct scheduler *ops,
@@ -3114,6 +3115,7 @@ csched2_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check
 csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -4246,9 +4248,9 @@ static const struct scheduler sched_credit2_def = {
     .wake           = csched2_unit_wake,
     .yield          = csched2_unit_yield,
 
-    .adjust         = csched2_dom_cntl,
     .adjust_affinity= csched2_aff_cntl,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .adjust         = csched2_dom_cntl,
     .adjust_global  = csched2_sys_cntl,
 #endif
 
xen/common/sched/private.h +4 -4
index b7ff67200b..3b35002c5d 100644
@@ -349,14 +349,14 @@ struct scheduler {
     void         (*migrate)        (const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     unsigned int new_cpu);
-    int          (*adjust)         (const struct scheduler *ops,
-                                    struct domain *d,
-                                    struct xen_domctl_scheduler_op *op);
     void         (*adjust_affinity)(const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     const struct cpumask *hard,
                                     const struct cpumask *soft);
 #ifdef CONFIG_MGMT_HYPERCALLS
+    int          (*adjust)         (const struct scheduler *ops,
+                                    struct domain *d,
+                                    struct xen_domctl_scheduler_op *op);
     int          (*adjust_global)  (const struct scheduler *ops,
                                     struct xen_sysctl_scheduler_op *sc);
 #endif
@@ -506,13 +506,13 @@ static inline void sched_adjust_affinity(const struct scheduler *s,
         s->adjust_affinity(s, unit, hard, soft);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int sched_adjust_dom(const struct scheduler *s, struct domain *d,
                                    struct xen_domctl_scheduler_op *op)
 {
     return s->adjust ? s->adjust(s, d, op) : 0;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int sched_adjust_cpupool(const struct scheduler *s,
                                        struct xen_sysctl_scheduler_op *op)
 {
xen/common/sched/rt.c +4 -0
index 7b1f64a779..a42040b259 100644
@@ -1362,6 +1362,7 @@ out:
     unit_schedule_unlock_irq(lock, unit);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * set/get each unit info of each domain
  */
@@ -1471,6 +1472,7 @@ rt_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * The replenishment timer handler picks units
@@ -1572,7 +1574,9 @@ static const struct scheduler sched_rtds_def = {
     .insert_unit    = rt_unit_insert,
     .remove_unit    = rt_unit_remove,
 
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust         = rt_dom_cntl,
+#endif
 
     .pick_resource  = rt_res_pick,
     .do_schedule    = rt_schedule,
xen/include/xsm/dummy.h +2 -0
index df8d737c18..6e8a6a2858 100644
@@ -141,12 +141,14 @@ static XSM_INLINE int cf_check xsm_getdomaininfo(
     return xsm_default_action(action, current->domain, d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_domctl_scheduler_op(
     XSM_DEFAULT_ARG struct domain *d, int cmd)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 #ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_sysctl_scheduler_op(XSM_DEFAULT_ARG int cmd)
xen/include/xsm/xsm.h +2 -2
index d20d4ae657..b3bec66e7e 100644
@@ -56,8 +56,8 @@ struct xsm_ops {
                                 struct xen_domctl_getdomaininfo *info);
     int (*domain_create)(struct domain *d, uint32_t ssidref);
     int (*getdomaininfo)(struct domain *d);
-    int (*domctl_scheduler_op)(struct domain *d, int op);
 #ifdef CONFIG_MGMT_HYPERCALLS
+    int (*domctl_scheduler_op)(struct domain *d, int op);
     int (*sysctl_scheduler_op)(int op);
 #endif
     int (*set_target)(struct domain *d, struct domain *e);
@@ -242,13 +242,13 @@ static inline int xsm_get_domain_state(xsm_default_t def, struct domain *d)
     return alternative_call(xsm_ops.get_domain_state, d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_domctl_scheduler_op(
     xsm_default_t def, struct domain *d, int cmd)
 {
     return alternative_call(xsm_ops.domctl_scheduler_op, d, cmd);
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
 {
     return alternative_call(xsm_ops.sysctl_scheduler_op, cmd);
xen/xsm/dummy.c +1 -1
index 2c70b979d6..2c878999a3 100644
@@ -18,8 +18,8 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .security_domaininfo           = xsm_security_domaininfo,
     .domain_create                 = xsm_domain_create,
     .getdomaininfo                 = xsm_getdomaininfo,
-    .domctl_scheduler_op           = xsm_domctl_scheduler_op,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .domctl_scheduler_op           = xsm_domctl_scheduler_op,
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
 #endif
     .set_target                    = xsm_set_target,
xen/xsm/flask/hooks.c +2 -2
index 490823913e..669b04f8ea 100644
@@ -609,6 +609,7 @@ static int cf_check flask_getdomaininfo(struct domain *d)
     return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__GETDOMAININFO);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
 {
     switch ( op )
@@ -626,7 +627,6 @@ static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
     }
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_sysctl_scheduler_op(int op)
 {
     switch ( op )
@@ -1883,8 +1883,8 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .security_domaininfo = flask_security_domaininfo,
     .domain_create = flask_domain_create,
     .getdomaininfo = flask_getdomaininfo,
-    .domctl_scheduler_op = flask_domctl_scheduler_op,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .domctl_scheduler_op = flask_domctl_scheduler_op,
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
 #endif
     .set_target = flask_set_target,
Signature · 1 line
2.34.1
#19 lore raw

PATCH v5 12/24 xen/xsm: wrap xsm_irq{,iomem}_permission with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function xsm_irq{,iomem}_permission() is invoked only under XEN_DOMCTL_irq{,iomem}_permission domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreanchable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1.
In flask policy, flask_iomem_permission() is also invoked for xsm_iomem_mapping(), which is needed in vpci support. So we shall exclude wrapping for flask_iomem_permission()

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
---
v2 -> v3
- add missing wrapping in xsm/dummy.h
- adapt to the commit of "remove redundant xsm_iomem_mapping()"
- address "violating Misra rule 2.1" in commit message
---
v4 -> v5:
- include changes for xsm_iomem_permission()

---
 xen/include/xsm/dummy.h | 2 ++
 xen/include/xsm/xsm.h   | 4 ++++
 xen/xsm/dummy.c         | 2 ++
 xen/xsm/flask/hooks.c   | 4 ++++
 4 files changed, 12 insertions(+)
xen/include/xsm/dummy.h +2 -0
index 6e8a6a2858..535de82f62 100644
@@ -564,6 +564,7 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
     return xsm_default_action(action, current->domain, d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_irq_permission(
     XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
 {
@@ -577,6 +578,7 @@ static XSM_INLINE int cf_check xsm_iomem_permission(
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_iomem_mapping(
     XSM_DEFAULT_ARG struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
xen/include/xsm/xsm.h +4 -0
index b3bec66e7e..786cfd7ac4 100644
@@ -115,9 +115,11 @@ struct xsm_ops {
     int (*unmap_domain_irq)(struct domain *d, int irq, const void *data);
     int (*bind_pt_irq)(struct domain *d, struct xen_domctl_bind_pt_irq *bind);
     int (*unbind_pt_irq)(struct domain *d, struct xen_domctl_bind_pt_irq *bind);
+#ifdef CONFIG_MGMT_HYPERCALLS
     int (*irq_permission)(struct domain *d, int pirq, uint8_t allow);
     int (*iomem_permission)(struct domain *d, uint64_t s, uint64_t e,
                             uint8_t allow);
+#endif
     int (*iomem_mapping)(struct domain *d, uint64_t s, uint64_t e,
                          uint8_t allow);
     int (*pci_config_permission)(struct domain *d, uint32_t machine_bdf,
@@ -501,6 +503,7 @@ static inline int xsm_unbind_pt_irq(
     return alternative_call(xsm_ops.unbind_pt_irq, d, bind);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_irq_permission(
     xsm_default_t def, struct domain *d, int pirq, uint8_t allow)
 {
@@ -512,6 +515,7 @@ static inline int xsm_iomem_permission(
 {
     return alternative_call(xsm_ops.iomem_permission, d, s, e, allow);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline int xsm_iomem_mapping(
     xsm_default_t def, struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
xen/xsm/dummy.c +2 -0
index 2c878999a3..b216894579 100644
@@ -73,8 +73,10 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .unmap_domain_irq              = xsm_unmap_domain_irq,
     .bind_pt_irq                   = xsm_bind_pt_irq,
     .unbind_pt_irq                 = xsm_unbind_pt_irq,
+#ifdef CONFIG_MGMT_HYPERCALLS
     .irq_permission                = xsm_irq_permission,
     .iomem_permission              = xsm_iomem_permission,
+#endif
     .iomem_mapping                 = xsm_iomem_mapping,
     .pci_config_permission         = xsm_pci_config_permission,
     .get_vnumainfo                 = xsm_get_vnumainfo,
xen/xsm/flask/hooks.c +4 -0
index 669b04f8ea..d480009142 100644
@@ -1111,12 +1111,14 @@ static int cf_check flask_unbind_pt_irq(
     return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_irq_permission(
     struct domain *d, int pirq, uint8_t access)
 {
     /* the PIRQ number is not useful; real IRQ is checked during mapping */
     return current_has_perm(d, SECCLASS_RESOURCE, resource_to_perm(access));
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 struct iomem_has_perm_data {
     uint32_t ssid;
@@ -1938,8 +1940,10 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .unmap_domain_irq = flask_unmap_domain_irq,
     .bind_pt_irq = flask_bind_pt_irq,
     .unbind_pt_irq = flask_unbind_pt_irq,
+#ifdef CONFIG_MGMT_HYPERCALLS
     .irq_permission = flask_irq_permission,
     .iomem_permission = flask_iomem_permission,
+#endif
     .iomem_mapping = flask_iomem_permission,
     .pci_config_permission = flask_pci_config_permission,
 
Signature · 1 line
2.34.1
#20 lore raw

PATCH v5 13/24 xen/domctl: wrap arch-specific domain_set_time_offset() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Arch-specific domain_set_time_offset() is responisble for XEN_DOMCTL_settimeoffset domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_settimeoffset-case transiently
---
v2 -> v3:
- add back stub wrapping for riscv
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around XEN_DOMCTL_settimeoffset-case

---
 xen/arch/arm/time.c    | 2 ++
 xen/arch/riscv/stubs.c | 2 ++
 xen/arch/x86/time.c    | 2 ++
 3 files changed, 6 insertions(+)
xen/arch/arm/time.c +2 -0
index 3710eab109..a40b233f9d 100644
@@ -378,12 +378,14 @@ void force_update_vcpu_system_time(struct vcpu *v)
     update_vcpu_system_time(v);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
 {
     d->time_offset.seconds = time_offset_seconds;
     d->time_offset.set = true;
     /* XXX update guest visible wallclock time */
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int cpu_time_callback(struct notifier_block *nfb,
                              unsigned long action,
xen/arch/riscv/stubs.c +2 -0
index c2e6af2c43..a8a0b4156a 100644
@@ -31,10 +31,12 @@ void send_timer_event(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* domctl.c */
 
xen/arch/x86/time.c +2 -0
index ece9ae0b34..8ba2dd9395 100644
@@ -1841,6 +1841,7 @@ static void update_domain_rtc(void)
     rcu_read_unlock(&domlist_read_lock);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
 {
     d->time_offset.seconds = time_offset_seconds;
@@ -1849,6 +1850,7 @@ void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
         rtc_update_clock(d);
     update_domain_wallclock_time(d);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int cpu_frequency_change(u64 freq)
 {
Signature · 1 line
2.34.1
#21 lore raw

PATCH v5 14/24 xen/domctl: wrap xsm_set_target() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function xsm_set_target() is only invoked under XEN_DOMCTL_set_target domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra 2.1.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
---
v2 -> v3
- wrap the whole inline function xsm_set_target()
- add missing wrapping in xsm/dummy.h
- address "violating Misra rule 2.1" in commit message

---
 xen/include/xsm/dummy.h | 2 ++
 xen/include/xsm/xsm.h   | 4 +++-
 xen/xsm/dummy.c         | 2 +-
 xen/xsm/flask/hooks.c   | 4 ++--
 4 files changed, 8 insertions(+), 4 deletions(-)
xen/include/xsm/dummy.h +2 -0
index 535de82f62..92291ac9e5 100644
@@ -158,12 +158,14 @@ static XSM_INLINE int cf_check xsm_sysctl_scheduler_op(XSM_DEFAULT_ARG int cmd)
 }
 #endif /* CONFIG_MGMT_HYPERCALLS */
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static XSM_INLINE int cf_check xsm_set_target(
     XSM_DEFAULT_ARG struct domain *d, struct domain *e)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, NULL);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_domctl(
     XSM_DEFAULT_ARG struct domain *d, unsigned int cmd, uint32_t ssidref)
xen/include/xsm/xsm.h +3 -1
index 786cfd7ac4..b76eb22429 100644
@@ -59,8 +59,8 @@ struct xsm_ops {
 #ifdef CONFIG_MGMT_HYPERCALLS
     int (*domctl_scheduler_op)(struct domain *d, int op);
     int (*sysctl_scheduler_op)(int op);
-#endif
     int (*set_target)(struct domain *d, struct domain *e);
+#endif
     int (*domctl)(struct domain *d, unsigned int cmd, uint32_t ssidref);
 #ifdef CONFIG_MGMT_HYPERCALLS
     int (*sysctl)(int cmd);
@@ -257,11 +257,13 @@ static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
 }
 #endif
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_set_target(
     xsm_default_t def, struct domain *d, struct domain *e)
 {
     return alternative_call(xsm_ops.set_target, d, e);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static inline int xsm_domctl(xsm_default_t def, struct domain *d,
                              unsigned int cmd, uint32_t ssidref)
xen/xsm/dummy.c +1 -1
index b216894579..f6986dd2bb 100644
@@ -21,8 +21,8 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
 #ifdef CONFIG_MGMT_HYPERCALLS
     .domctl_scheduler_op           = xsm_domctl_scheduler_op,
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
-#endif
     .set_target                    = xsm_set_target,
+#endif
     .domctl                        = xsm_domctl,
 #ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl                        = xsm_sysctl,
xen/xsm/flask/hooks.c +2 -2
index d480009142..9c1298697c 100644
@@ -641,7 +641,6 @@ static int cf_check flask_sysctl_scheduler_op(int op)
         return avc_unknown_permission("sysctl_scheduler_op", op);
     }
 }
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int cf_check flask_set_target(struct domain *d, struct domain *t)
 {
@@ -666,6 +665,7 @@ static int cf_check flask_set_target(struct domain *d, struct domain *t)
                                  &dsec->target_sid);
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
                                  uint32_t ssidref)
@@ -1888,8 +1888,8 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
 #ifdef CONFIG_MGMT_HYPERCALLS
     .domctl_scheduler_op = flask_domctl_scheduler_op,
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
-#endif
     .set_target = flask_set_target,
+#endif
     .domctl = flask_domctl,
 #ifdef CONFIG_MGMT_HYPERCALLS
     .sysctl = flask_sysctl,
Signature · 1 line
2.34.1
#22 lore raw

PATCH v5 15/24 xen/domctl: wrap pci-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function iommu_do_pci_domctl() is the main entry for pci-subset iommu-related domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Tracking its calling chain, the following functions shall all be wrapped with CONFIG_MGMT_HYPERCALLS:
- iommu_do_pci_domctl
- iommu_get_device_group
- xsm_get_device_group
- iommu_ops.get_device_group_id
- amd_iommu_group_id/intel_iommu_group_id
- device_assigned
- xsm_assign_device
- assign_device
- iommu_ops.assign_device
- intel_iommu_assign_device/amd_iommu_assign_device
- xsm_deassign_device
- deassign_device
- iommu_ops.reassign_device
- reassign_device_ownership/reassign_device
Otherwise all the functions will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1

The PCI-part in ARM, (regarding codes under HAS_PCI), will be taken care of later when guarding PCI_PASSTHROUGH with MGMT_HYPERCALLS, as the Kconfig select chain in ARM is as follows:
HAS_VPCI_GUEST_SUPPORT if PCI_PASSTHROUGH -> HAS_VPCI -> HAS_PCI So making PCI_PASSTHROUGH depend on MGMT_HYPERCALLS will recursively leading HAS_PCI depend on MGMT_HYPERCALLS too in ARM.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_assign_device{test_assign_device,deassign_device, get_device_group}-case transiently
---
v2 -> v3:
- make PCI_PASSTHROUGH(, then HAS_VPCI_GUEST_SUPPORT) depend on MGMT_HYPERCALLS
- add wrapping for iommu_remove_dt_device/iommu_dt_device_is_assigned_locked/ arm_smmu_detach_dev/arm_smmu_domain_remove_master
- fold commit
"xen/xsm: wrap xsm-iommu-related functions with CONFIG_MGMT_HYPERCALLS" in
- fix overly long #ifdef
- add missing wrapping in xsm/dummy.h
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping of XEN_DOMCTL_assign_device{test_assign_device,deassign_device,get_device_group}-case
---
v3 -> v4:
- move codes to wrap with a single #ifdef
- split into PCI related subset and DT subset
---
v4 -> v5:
- Hook .get_device_group_id should be properly dealt with in xen/iommu.h right away
- Add description for how PCI-part will be dealt in ARM

---
 xen/drivers/passthrough/amd/pci_amd_iommu.c | 20 ++++----
 xen/drivers/passthrough/pci.c               | 52 +++++++++++----------
 xen/drivers/passthrough/vtd/iommu.c         |  6 ++-
 xen/include/xen/iommu.h                     |  2 +
 xen/include/xsm/dummy.h                     |  6 ++-
 xen/include/xsm/xsm.h                       | 12 +++--
 xen/xsm/dummy.c                             |  6 ++-
 xen/xsm/flask/hooks.c                       | 12 +++--
 8 files changed, 70 insertions(+), 46 deletions(-)
xen/drivers/passthrough/amd/pci_amd_iommu.c +12 -8
index 3a14770855..576b36af92 100644
@@ -461,6 +461,7 @@ static void amd_iommu_disable_domain_device(const struct domain *domain,
         spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check reassign_device(
     struct domain *source, struct domain *target, u8 devfn,
     struct pci_dev *pdev)
@@ -551,6 +552,14 @@ static int cf_check amd_iommu_assign_device(
     return rc;
 }
 
+static int cf_check amd_iommu_group_id(u16 seg, u8 bus, u8 devfn)
+{
+    unsigned int bdf = PCI_BDF(bus, devfn);
+
+    return (bdf < ivrs_bdf_entries) ? get_dma_requestor_id(seg, bdf) : bdf;
+}
+#endif /* CONFIG_MGMT_HYPERCALLS */
+
 static void cf_check amd_iommu_clear_root_pgtable(struct domain *d)
 {
     struct domain_iommu *hd = dom_iommu(d);
@@ -698,13 +707,6 @@ static int cf_check amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev)
     return 0;
 }
 
-static int cf_check amd_iommu_group_id(u16 seg, u8 bus, u8 devfn)
-{
-    unsigned int bdf = PCI_BDF(bus, devfn);
-
-    return (bdf < ivrs_bdf_entries) ? get_dma_requestor_id(seg, bdf) : bdf;
-}
-
 #include <asm/io_apic.h>
 
 static void amd_dump_page_table_level(struct page_info *pg, int level,
@@ -772,14 +774,16 @@ static const struct iommu_ops __initconst_cf_clobber _iommu_ops = {
     .quarantine_init = amd_iommu_quarantine_init,
     .add_device = amd_iommu_add_device,
     .remove_device = amd_iommu_remove_device,
-    .assign_device  = amd_iommu_assign_device,
     .teardown = amd_iommu_domain_destroy,
     .clear_root_pgtable = amd_iommu_clear_root_pgtable,
     .map_page = amd_iommu_map_page,
     .unmap_page = amd_iommu_unmap_page,
     .iotlb_flush = amd_iommu_flush_iotlb_pages,
+#ifdef CONFIG_MGMT_HYPERCALLS
+    .assign_device  = amd_iommu_assign_device,
     .reassign_device = reassign_device,
     .get_device_group_id = amd_iommu_group_id,
+#endif
     .enable_x2apic = iov_enable_xt,
     .update_ire_from_apic = amd_iommu_ioapic_update_ire,
     .update_ire_from_msi = amd_iommu_msi_msg_update_ire,
xen/drivers/passthrough/pci.c +27 -25

82 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.c +5 -1
index 90f36ac22b..ad2e657bca 100644
@@ -2742,6 +2742,7 @@ static int __init cf_check vtd_setup(void)
     return ret;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check reassign_device_ownership(
     struct domain *source,
     struct domain *target,
@@ -2937,6 +2938,7 @@ static int cf_check intel_iommu_group_id(u16 seg, u8 bus, u8 devfn)
 
     return PCI_BDF(bus, devfn);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int __must_check cf_check vtd_suspend(void)
 {
@@ -3245,14 +3247,16 @@ static const struct iommu_ops __initconst_cf_clobber vtd_ops = {
     .add_device = intel_iommu_add_device,
     .enable_device = intel_iommu_enable_device,
     .remove_device = intel_iommu_remove_device,
-    .assign_device  = intel_iommu_assign_device,
     .teardown = iommu_domain_teardown,
     .clear_root_pgtable = iommu_clear_root_pgtable,
     .map_page = intel_iommu_map_page,
     .unmap_page = intel_iommu_unmap_page,
     .lookup_page = intel_iommu_lookup_page,
+#ifdef CONFIG_MGMT_HYPERCALLS
+    .assign_device  = intel_iommu_assign_device,
     .reassign_device = reassign_device_ownership,
     .get_device_group_id = intel_iommu_group_id,
+#endif
     .enable_x2apic = intel_iommu_enable_eim,
     .disable_x2apic = intel_iommu_disable_eim,
     .update_ire_from_apic = io_apic_write_remap_rte,
xen/include/xen/iommu.h +2 -0
index 37c4a1dc82..6ca4190eb9 100644
@@ -333,9 +333,11 @@ struct iommu_ops {
                          uint32_t flag);
     int (*reassign_device)(struct domain *s, struct domain *t,
                            uint8_t devfn, device_t *dev);
+#ifdef CONFIG_MGMT_HYPERCALLS
 #ifdef CONFIG_HAS_PCI
     int (*get_device_group_id)(uint16_t seg, uint8_t bus, uint8_t devfn);
 #endif /* HAS_PCI */
+#endif /* MGMT_HYPERCALLS */
 
     void (*teardown)(struct domain *d);
 
xen/include/xsm/dummy.h +4 -2
index 92291ac9e5..07d69e3725 100644
@@ -407,7 +407,8 @@ static XSM_INLINE int cf_check xsm_get_vnumainfo(
     return xsm_default_action(action, current->domain, d);
 }
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
 static XSM_INLINE int cf_check xsm_get_device_group(
     XSM_DEFAULT_ARG uint32_t machine_bdf)
 {
@@ -429,7 +430,8 @@ static XSM_INLINE int cf_check xsm_deassign_device(
     return xsm_default_action(action, current->domain, d);
 }
 
-#endif /* HAS_PASSTHROUGH && HAS_PCI */
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
 static XSM_INLINE int cf_check xsm_assign_dtdevice(
xen/include/xsm/xsm.h +8 -4
index b76eb22429..b331e81f9d 100644
@@ -125,11 +125,13 @@ struct xsm_ops {
     int (*pci_config_permission)(struct domain *d, uint32_t machine_bdf,
                                  uint16_t start, uint16_t end, uint8_t access);
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
     int (*get_device_group)(uint32_t machine_bdf);
     int (*assign_device)(struct domain *d, uint32_t machine_bdf);
     int (*deassign_device)(struct domain *d, uint32_t machine_bdf);
-#endif
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
     int (*assign_dtdevice)(struct domain *d, const char *dtpath);
@@ -532,7 +534,8 @@ static inline int xsm_pci_config_permission(
     return alternative_call(xsm_ops.pci_config_permission, d, machine_bdf, start, end, access);
 }
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
 static inline int xsm_get_device_group(xsm_default_t def, uint32_t machine_bdf)
 {
     return alternative_call(xsm_ops.get_device_group, machine_bdf);
@@ -549,7 +552,8 @@ static inline int xsm_deassign_device(
 {
     return alternative_call(xsm_ops.deassign_device, d, machine_bdf);
 }
-#endif /* HAS_PASSTHROUGH && HAS_PCI) */
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
 static inline int xsm_assign_dtdevice(
xen/xsm/dummy.c +4 -2
index f6986dd2bb..c693e77a7d 100644
@@ -81,11 +81,13 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .pci_config_permission         = xsm_pci_config_permission,
     .get_vnumainfo                 = xsm_get_vnumainfo,
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
     .get_device_group              = xsm_get_device_group,
     .assign_device                 = xsm_assign_device,
     .deassign_device               = xsm_deassign_device,
-#endif
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
     .assign_dtdevice               = xsm_assign_dtdevice,
xen/xsm/flask/hooks.c +8 -4
index 9c1298697c..c772f79e16 100644
@@ -1388,7 +1388,8 @@ static int cf_check flask_mem_sharing(struct domain *d)
 }
 #endif
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
 static int cf_check flask_get_device_group(uint32_t machine_bdf)
 {
     uint32_t rsid;
@@ -1459,7 +1460,8 @@ static int cf_check flask_deassign_device(
 
     return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE, NULL);
 }
-#endif /* HAS_PASSTHROUGH && HAS_PCI */
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
 static int flask_test_assign_dtdevice(const char *dtpath)
@@ -1988,11 +1990,13 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .remove_from_physmap = flask_remove_from_physmap,
     .map_gmfn_foreign = flask_map_gmfn_foreign,
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_MGMT_HYPERCALLS)
+#ifdef CONFIG_HAS_PCI
     .get_device_group = flask_get_device_group,
     .assign_device = flask_assign_device,
     .deassign_device = flask_deassign_device,
-#endif
+#endif /* CONFIG_HAS_PCI */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
     .assign_dtdevice = flask_assign_dtdevice,
Signature · 1 line
2.34.1
#23 lore raw

Re: [PATCH v5 15/24] xen/domctl: wrap pci-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

xen/include/xen/iommu.h struct iommu_ops { · line 340

Quoted 11 lines · Penny Zheng
xen/include/xen/iommu.h +2 -0
@@ -333,9 +333,11 @@ struct iommu_ops {
                          uint32_t flag);
     int (*reassign_device)(struct domain *s, struct domain *t,
                            uint8_t devfn, device_t *dev);
+#ifdef CONFIG_MGMT_HYPERCALLS
 #ifdef CONFIG_HAS_PCI
     int (*get_device_group_id)(uint16_t seg, uint8_t bus, uint8_t devfn);
 #endif /* HAS_PCI */
+#endif /* MGMT_HYPERCALLS */

I remain concerned of the former two hooks staying around for x86, despite them now being NULL when !MGMT_HYPERCALLS. Imo, to play safe, they will want to be guarded (transiently) with

#if defined(CONFIG_MGMT_HYPERCALLS) || defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)

Jan

#24 lore raw

Re: [PATCH v5 15/24] xen/domctl: wrap pci-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

Quoted 17 lines · Jan Beulich

xen/include/xen/iommu.h struct iommu_ops { · line 340

Quoted 11 lines · Penny Zheng
xen/include/xen/iommu.h +2 -0
@@ -333,9 +333,11 @@ struct iommu_ops {
                          uint32_t flag);
     int (*reassign_device)(struct domain *s, struct domain *t,
                            uint8_t devfn, device_t *dev);
+#ifdef CONFIG_MGMT_HYPERCALLS
 #ifdef CONFIG_HAS_PCI
     int (*get_device_group_id)(uint16_t seg, uint8_t bus, uint8_t devfn);
 #endif /* HAS_PCI */
+#endif /* MGMT_HYPERCALLS */

I remain concerned of the former two hooks staying around for x86, despite them now being NULL when !MGMT_HYPERCALLS. Imo, to play safe, they will want to be guarded (transiently) with

Quoted 1 line

#if defined(CONFIG_MGMT_HYPERCALLS) || defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)

Looking at the next patch - not just transiently. The .assign_device hook stays present there (for presumably a good reason), yet for x86 it shouldn't exist anymore when !MGMT_HYPERCALLS.

Jan

#25 lore raw

PATCH v5 16/24 xen/domctl: wrap device-tree-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function iommu_do_dt_domctl() is the main entry for all device-tree-subset iommu-related domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Tracking its calling chain, the following functions shall all be wrapped with CONFIG_MGMT_HYPERCALLS:
- make PCI_PASSTHROUGH depend on MGMT_HYPERCALLS
- iommu_do_dt_domctl
- xsm_assign_dtdevice
- xsm_deassign_dtdevice
- iommu_deassign_dt_device
- arm_smmu_reassign_dev
- arm_smmu_deassign_dev
- arm_smmu_detach_dev
- arm_smmu_domain_remove_master
- ipmmu_reassign_device
- ipmmu_deassign_device
- ipmmu_detach_device
- iommu_remove_dt_device
- iommu_dt_device_is_assigned_locked
- dt_find_node_by_gpath
Otherwise all the functions will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1
Move codes closer to avoid scattering #ifdef

---
v3 -> v4
- split into PCI related subset and DT subset
- Move codes closer to avoid scattering #ifdef
---
v4 -> v5:
- wrap arm_smmu_deassign_dev() declaration with MGMT_HYPERCALLS
- zap the hooks in xen/iommu.h right away

---
 xen/arch/arm/Kconfig                     |   2 +-
 xen/drivers/passthrough/arm/ipmmu-vmsa.c |  26 +++---
 xen/drivers/passthrough/arm/smmu-v3.c    |   6 ++
 xen/drivers/passthrough/arm/smmu.c       |  55 ++++++------
 xen/drivers/passthrough/device_tree.c    | 108 ++++++++++++-----------
 xen/include/xen/iommu.h                  |   2 +-
 xen/include/xsm/dummy.h                  |   6 +-
 xen/include/xsm/xsm.h                    |  12 +--
 xen/xsm/dummy.c                          |   6 +-
 xen/xsm/flask/hooks.c                    |  12 +--
 10 files changed, 127 insertions(+), 108 deletions(-)
xen/arch/arm/Kconfig +1 -1
index cf6af68299..5a5d7810c8 100644
@@ -270,7 +270,7 @@ source "arch/arm/firmware/Kconfig"
 
 config PCI_PASSTHROUGH
 	bool "PCI passthrough" if EXPERT
-	depends on ARM_64 && HAS_PASSTHROUGH
+	depends on ARM_64 && HAS_PASSTHROUGH && MGMT_HYPERCALLS
 	help
 	  This option enables PCI device passthrough
 
xen/drivers/passthrough/arm/ipmmu-vmsa.c +16 -10
index ea9fa9ddf3..b1fc14bc32 100644
@@ -739,16 +739,6 @@ static int ipmmu_attach_device(struct ipmmu_vmsa_domain *domain,
     return 0;
 }
 
-static void ipmmu_detach_device(struct ipmmu_vmsa_domain *domain,
-                                struct device *dev)
-{
-    struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
-    unsigned int i;
-
-    for ( i = 0; i < fwspec->num_ids; ++i )
-        ipmmu_utlb_disable(domain, fwspec->ids[i]);
-}
-
 static int ipmmu_init_platform_device(struct device *dev,
                                       const struct dt_phandle_args *args)
 {
@@ -1138,7 +1128,9 @@ static void ipmmu_free_root_domain(struct ipmmu_vmsa_domain *domain)
     xfree(domain);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int ipmmu_deassign_device(struct domain *d, struct device *dev);
+#endif
 
 static int ipmmu_assign_device(struct domain *d, u8 devfn, struct device *dev,
                                uint32_t flag)
@@ -1254,6 +1246,17 @@ out:
     return ret;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
+static void ipmmu_detach_device(struct ipmmu_vmsa_domain *domain,
+                                struct device *dev)
+{
+    struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+    unsigned int i;
+
+    for ( i = 0; i < fwspec->num_ids; ++i )
+        ipmmu_utlb_disable(domain, fwspec->ids[i]);
+}
+
 static int ipmmu_deassign_device(struct domain *d, struct device *dev)
 {
     struct ipmmu_vmsa_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -1309,6 +1312,7 @@ static int ipmmu_reassign_device(struct domain *s, struct domain *t,
 
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int ipmmu_dt_xlate(struct device *dev,
                           const struct dt_phandle_args *spec)
@@ -1487,7 +1491,9 @@ static const struct iommu_ops ipmmu_iommu_ops =
     .teardown        = ipmmu_iommu_domain_teardown,
     .iotlb_flush     = ipmmu_iotlb_flush,
     .assign_device   = ipmmu_assign_device,
+#ifdef CONFIG_MGMT_HYPERCALLS
     .reassign_device = ipmmu_reassign_device,
+#endif
     .map_page        = arm_iommu_map_page,
     .unmap_page      = arm_iommu_unmap_page,
     .dt_xlate        = ipmmu_dt_xlate,
xen/drivers/passthrough/arm/smmu-v3.c +6 -0
index bf153227db..1d85341e72 100644
@@ -1490,8 +1490,10 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid)
 static struct arm_smmu_device *arm_smmu_get_by_dev(const struct device *dev);
 static int arm_smmu_assign_dev(struct domain *d, u8 devfn, struct device *dev,
 			       u32 flag);
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn,
 				 struct device *dev);
+#endif
 
 static int arm_smmu_add_device(u8 devfn, struct device *dev)
 {
@@ -2759,6 +2761,7 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn, struct device *dev)
 {
 	struct iommu_domain *io_domain = arm_smmu_get_domain(d, dev);
@@ -2826,6 +2829,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,
 
 	return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static int arm_smmu_iommu_xen_domain_init(struct domain *d)
 {
@@ -2862,7 +2866,9 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
 	.teardown		= arm_smmu_iommu_xen_domain_teardown,
 	.iotlb_flush		= arm_smmu_iotlb_flush,
 	.assign_device		= arm_smmu_assign_dev,
+#ifdef CONFIG_MGMT_HYPERCALLS
 	.reassign_device	= arm_smmu_reassign_dev,
+#endif
 	.map_page		= arm_iommu_map_page,
 	.unmap_page		= arm_iommu_unmap_page,
 	.dt_xlate		= arm_smmu_dt_xlate,
xen/drivers/passthrough/arm/smmu.c +30 -25

94 lines not on this page · raw message

xen/drivers/passthrough/device_tree.c +55 -53

135 lines not on this page · raw message

xen/include/xen/iommu.h +1 -1
index 6ca4190eb9..e5e9f98201 100644
@@ -331,9 +331,9 @@ struct iommu_ops {
     int (*remove_device)(uint8_t devfn, device_t *dev);
     int (*assign_device)(struct domain *d, uint8_t devfn, device_t *dev,
                          uint32_t flag);
+#ifdef CONFIG_MGMT_HYPERCALLS
     int (*reassign_device)(struct domain *s, struct domain *t,
                            uint8_t devfn, device_t *dev);
-#ifdef CONFIG_MGMT_HYPERCALLS
 #ifdef CONFIG_HAS_PCI
     int (*get_device_group_id)(uint16_t seg, uint8_t bus, uint8_t devfn);
 #endif /* HAS_PCI */
xen/include/xsm/dummy.h +3 -3
index 07d69e3725..90fe741fb4 100644
@@ -431,9 +431,8 @@ static XSM_INLINE int cf_check xsm_deassign_device(
 }
 
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
 static XSM_INLINE int cf_check xsm_assign_dtdevice(
     XSM_DEFAULT_ARG struct domain *d, const char *dtpath)
 {
@@ -448,7 +447,8 @@ static XSM_INLINE int cf_check xsm_deassign_dtdevice(
     return xsm_default_action(action, current->domain, d);
 }
 
-#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY */
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 static XSM_INLINE int cf_check xsm_resource_plug_core(XSM_DEFAULT_VOID)
 {
xen/include/xsm/xsm.h +6 -6
index b331e81f9d..90349d02c2 100644
@@ -131,12 +131,12 @@ struct xsm_ops {
     int (*assign_device)(struct domain *d, uint32_t machine_bdf);
     int (*deassign_device)(struct domain *d, uint32_t machine_bdf);
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
     int (*assign_dtdevice)(struct domain *d, const char *dtpath);
     int (*deassign_dtdevice)(struct domain *d, const char *dtpath);
-#endif
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
     int (*resource_plug_core)(void);
     int (*resource_unplug_core)(void);
@@ -553,9 +553,8 @@ static inline int xsm_deassign_device(
     return alternative_call(xsm_ops.deassign_device, d, machine_bdf);
 }
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
 static inline int xsm_assign_dtdevice(
     xsm_default_t def, struct domain *d, const char *dtpath)
 {
@@ -568,7 +567,8 @@ static inline int xsm_deassign_dtdevice(
     return alternative_call(xsm_ops.deassign_dtdevice, d, dtpath);
 }
 
-#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY */
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 static inline int xsm_resource_plug_pci(xsm_default_t def, uint32_t machine_bdf)
 {
xen/xsm/dummy.c +3 -3
index c693e77a7d..1ac4f719ad 100644
@@ -87,12 +87,12 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .assign_device                 = xsm_assign_device,
     .deassign_device               = xsm_deassign_device,
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
     .assign_dtdevice               = xsm_assign_dtdevice,
     .deassign_dtdevice             = xsm_deassign_dtdevice,
-#endif
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
     .resource_plug_core            = xsm_resource_plug_core,
     .resource_unplug_core          = xsm_resource_unplug_core,
xen/xsm/flask/hooks.c +6 -6
index c772f79e16..9c800b574e 100644
@@ -1461,9 +1461,8 @@ static int cf_check flask_deassign_device(
     return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE, NULL);
 }
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
 static int flask_test_assign_dtdevice(const char *dtpath)
 {
     uint32_t rsid;
@@ -1524,7 +1523,8 @@ static int cf_check flask_deassign_dtdevice(
     return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE,
                                 NULL);
 }
-#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY */
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
 static int cf_check flask_platform_op(uint32_t op)
 {
@@ -1996,12 +1996,12 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .assign_device = flask_assign_device,
     .deassign_device = flask_deassign_device,
 #endif /* CONFIG_HAS_PCI */
-#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#ifdef CONFIG_HAS_DEVICE_TREE_DISCOVERY
     .assign_dtdevice = flask_assign_dtdevice,
     .deassign_dtdevice = flask_deassign_dtdevice,
-#endif
+#endif /* CONFIG_HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && MGMT_HYPERCALLS */
 
     .platform_op = flask_platform_op,
 #ifdef CONFIG_X86
Signature · 1 line
2.34.1
Acked-by on v5 16/24
#26 lore raw

Re: [PATCH v5 16/24] xen/domctl: wrap device-tree-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

Quoted 23 lines · Penny Zheng

Function iommu_do_dt_domctl() is the main entry for all device-tree-subset iommu-related domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Tracking its calling chain, the following functions shall all be wrapped with CONFIG_MGMT_HYPERCALLS:
- make PCI_PASSTHROUGH depend on MGMT_HYPERCALLS
- iommu_do_dt_domctl
- xsm_assign_dtdevice
- xsm_deassign_dtdevice
- iommu_deassign_dt_device
- arm_smmu_reassign_dev
- arm_smmu_deassign_dev
- arm_smmu_detach_dev
- arm_smmu_domain_remove_master
- ipmmu_reassign_device
- ipmmu_deassign_device
- ipmmu_detach_device
- iommu_remove_dt_device
- iommu_dt_device_is_assigned_locked
- dt_find_node_by_gpath
Otherwise all the functions will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1
Move codes closer to avoid scattering #ifdef

Quoted 1 line
#27 lore raw

PATCH v5 17/24 xen/domctl: wrap iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function iommu_do_domctl() is the main entry for all iommu-related domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS.
Otherwise it will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1

---
v3 -> v4:
- new commit
---
v4 -> v5:
- fix typo

---
 xen/drivers/passthrough/iommu.c | 2 ++
 1 file changed, 2 insertions(+)
xen/drivers/passthrough/iommu.c +2 -0
index c9425d6971..8812e38174 100644
@@ -625,6 +625,7 @@ void iommu_resume(void)
         iommu_vcall(iommu_get_ops(), resume);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int iommu_do_domctl(
     struct xen_domctl *domctl, struct domain *d,
     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
@@ -645,6 +646,7 @@ int iommu_do_domctl(
 
     return ret;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 void iommu_crash_shutdown(void)
 {
Signature · 1 line
2.34.1
Acked-by on v5 17/24
#28 lore raw

Re: [PATCH v5 17/24] xen/domctl: wrap iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

Quoted 6 lines · Penny Zheng

Function iommu_do_domctl() is the main entry for all iommu-related domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS.
Otherwise it will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1

#29 lore raw

PATCH v5 18/24 xen/domctl: wrap arch_{get,set}_paging_mempool_size() with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Arch-specific arch_{get,set}_paging_mempool_size() is responsible for XEN_DOMCTL_{get,set}_paging_mempool_size domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS. Otherwise it will become unreachable codes when MGMT_HYPERCALLS=n, and hence violating Misra 2.1.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_{get,set}_paging_mempool_size-case transiently
---
v2 -> v3
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around XEN_DOMCTL_{get,set}_paging_mempool_size-case

---
 xen/arch/arm/mmu/p2m.c   | 4 ++++
 xen/arch/x86/mm/paging.c | 2 ++
 2 files changed, 6 insertions(+)
xen/arch/arm/mmu/p2m.c +4 -0
index 30d6071e91..4caa5844e4 100644
@@ -58,12 +58,14 @@ static void p2m_free_page(struct domain *d, struct page_info *pg)
     }
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /* Return the size of the pool, in bytes. */
 int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
 {
     *size = (uint64_t)ACCESS_ONCE(d->arch.paging.p2m_total_pages) << PAGE_SHIFT;
     return 0;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Set the pool of pages to the required number of pages.
@@ -122,6 +124,7 @@ int p2m_set_allocation(struct domain *d, unsigned long pages, bool *preempted)
     return 0;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
 {
     unsigned long pages = size >> PAGE_SHIFT;
@@ -140,6 +143,7 @@ int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int p2m_teardown_allocation(struct domain *d)
 {
xen/arch/x86/mm/paging.c +2 -0
index 116389d4e9..c6e3996093 100644
@@ -949,6 +949,7 @@ int __init paging_set_allocation(struct domain *d, unsigned int pages,
 }
 #endif
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
 {
     unsigned long pages;
@@ -991,6 +992,7 @@ int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
 
     return preempted ? -ERESTART : rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * Local variables:
Signature · 1 line
2.34.1
#30 lore raw

PATCH v5 19/24 xen/domctl: make CONFIG_X86_PSR depend on CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Users control/monitor Intel Platform Shared Resource (PSR) through related domctl-op or sysctl-op, so CONFIG_X86_PSR can be put under MGMT_HYPERCALLS. With this change, we could remove MGMT_HYPERCALLS-wrapping in psr.c.

---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"

---
 xen/arch/x86/Kconfig |  1 +
 xen/arch/x86/psr.c   | 18 ------------------
 2 files changed, 1 insertion(+), 18 deletions(-)
xen/arch/x86/Kconfig +1 -0
index c808c989fc..8368c6ecf0 100644
@@ -191,6 +191,7 @@ config TBOOT
 config X86_PSR
 	bool "Platform Shared Resource support" if EXPERT
 	default INTEL
+	depends on MGMT_HYPERCALLS
 	help
 	  Support of Platform Shared Resource technology, which is basis for
 	  monitoring and control of resources like cache and memory bandwidth.
xen/arch/x86/psr.c +0 -18
index 80ce5804b4..4f2c2d0042 100644
@@ -135,11 +135,9 @@ static const struct feat_props {
      */
     enum psr_type alt_type;
 
-#ifdef CONFIG_MGMT_HYPERCALLS
     /* get_feat_info is used to return feature HW info through sysctl. */
     bool (*get_feat_info)(const struct feat_node *feat,
                           uint32_t data[], unsigned int array_len);
-#endif
 
     /* write_msr is used to write out feature MSR register. */
     void (*write_msr)(unsigned int cos, uint32_t val, enum psr_type type);
@@ -422,7 +420,6 @@ static bool mba_init_feature(const struct cpuid_leaf *regs,
     return true;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static bool cf_check cat_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
 {
@@ -435,7 +432,6 @@ static bool cf_check cat_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* L3 CAT props */
 static void cf_check l3_cat_write_msr(
@@ -448,14 +444,11 @@ static const struct feat_props l3_cat_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_L3_CBM,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = cat_get_feat_info,
-#endif
     .write_msr = l3_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 /* L3 CDP props */
 static bool cf_check l3_cdp_get_feat_info(
     const struct feat_node *feat, uint32_t data[], uint32_t array_len)
@@ -467,7 +460,6 @@ static bool cf_check l3_cdp_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check l3_cdp_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -483,9 +475,7 @@ static const struct feat_props l3_cdp_props = {
     .type[0] = PSR_TYPE_L3_DATA,
     .type[1] = PSR_TYPE_L3_CODE,
     .alt_type = PSR_TYPE_L3_CBM,
-#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = l3_cdp_get_feat_info,
-#endif
     .write_msr = l3_cdp_write_msr,
     .sanitize = cat_check_cbm,
 };
@@ -501,14 +491,11 @@ static const struct feat_props l2_cat_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_L2_CBM,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = cat_get_feat_info,
-#endif
     .write_msr = l2_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 /* MBA props */
 static bool cf_check mba_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
@@ -523,7 +510,6 @@ static bool cf_check mba_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check mba_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -561,9 +547,7 @@ static const struct feat_props mba_props = {
     .cos_num = 1,
     .type[0] = PSR_TYPE_MBA_THRTL,
     .alt_type = PSR_TYPE_UNKNOWN,
-#ifdef CONFIG_MGMT_HYPERCALLS
     .get_feat_info = mba_get_feat_info,
-#endif
     .write_msr = mba_write_msr,
     .sanitize = mba_sanitize_thrtl,
 };
@@ -826,7 +810,6 @@ static struct psr_socket_info *get_socket_info(unsigned int socket)
     return socket_info + socket;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 int psr_get_info(unsigned int socket, enum psr_type type,
                  uint32_t data[], unsigned int array_len)
 {
@@ -858,7 +841,6 @@ int psr_get_info(unsigned int socket, enum psr_type type,
 
     return -EINVAL;
 }
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
 int psr_get_val(struct domain *d, unsigned int socket,
                 uint32_t *val, enum psr_type type)
Signature · 1 line
2.34.1
#31 lore raw

PATCH v5 20/24 xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function arch_do_domctl() is responsible for arch-specific domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS
We focus on x86 implementation here only. Tracking its calling chain and the following functions shall be wrapped with CONFIG_MGMT_HYPERCALLS too. Otherwise they will all become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra Rule 2.1.
- hvm_acpi_power_button
- hvm_acpi_sleep_button
- hvm_debug_op
- make P2M_AUDIT depend on CONFIG_MGMT_HYPERCALLS
- make PG_log_dirty depend on CONFIG_MGMT_HYPERCALLS
- make policy.o/msr.o depend on CONFIG_MGMT_HYPERCALLS
- make cpuid-cp2buf.o/cpuid-cpfrbuf.o/cpupolicy-clr.o depend on CONFIG_MGMT_HYPERCALLS
- make HAS_SOFT_RESET depend on CONFIG_MGMT_HYPERCALLS
- make VMTRACE depend on CONFIG_MGMT_HYPERCALLS
- paging_domctl_cont
We put the guardian in Makefile for the arch-specific domctl.o compilation.

---
v1 -> v2:
- split out xsm parts
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap default-case and arch_get_domain_info() transiently
---
v2 -> v3:
- add missing guardian in arm/Makefile
- cover RTIT_CTL{,STATUS}_MASK #define-s
- add missing guardian for .vmtrace_output_position
- guard the whole static inline function
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around default-case and arch_get_domain_info()
---
v3 -> v4:
- make HAS_SOFT_RESET depend on CONFIG_MGMT_HYPERCALLS
- make VMTRACE depend on CONFIG_MGMT_HYPERCALLS
- seperate depends on condition for future convenience
- split arch-specific domctl-op into x86 and arm
---
v4 -> v5:
- do not undo imply and add "depends on MGMT_HYPERCALLS" in option
- use IS_ENABLED(...) to avoid too long line
- move paging_domctl_cont hypercall-def closer to avoid scattering #ifdef

---
 xen/Kconfig.debug                 | 1 +
 xen/arch/x86/Makefile             | 2 +-
 xen/arch/x86/hvm/Kconfig          | 1 +
 xen/arch/x86/hvm/hvm.c            | 2 ++
 xen/arch/x86/hvm/pmtimer.c        | 2 ++
 xen/arch/x86/include/asm/p2m.h    | 2 +-
 xen/arch/x86/include/asm/paging.h | 3 ++-
 xen/common/Kconfig                | 1 +
 xen/include/hypercall-defs.c      | 8 ++++----
 xen/lib/Makefile                  | 6 +++---
 xen/lib/x86/Makefile              | 4 ++--
 11 files changed, 20 insertions(+), 12 deletions(-)
xen/Kconfig.debug +1 -0
index a69615cd63..c078c6bf2e 100644
@@ -15,6 +15,7 @@ if DEBUG || EXPERT
 
 config GDBSX
 	bool "Guest debugging with gdbsx"
+	depends on MGMT_HYPERCALLS
 	depends on X86
 	default y
 	help
xen/arch/x86/Makefile +1 -1
index 1e2ce8e72c..d389787bb3 100644
@@ -80,7 +80,7 @@ obj-$(CONFIG_VM_EVENT) += vm_event.o
 obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += platform_hypercall.o
 obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 endif
xen/arch/x86/hvm/Kconfig +1 -0
index df9bea65b0..1989808810 100644
@@ -54,6 +54,7 @@ config HVM_FEP
 config ALTP2M
 	bool "Alternate P2M support" if EXPERT
 	depends on INTEL_VMX
+	depends on MGMT_HYPERCALLS
 	default y
 	help
 	  Alternate-p2m allows a guest to manage multiple p2m guest physical
xen/arch/x86/hvm/hvm.c +2 -0
index 5d297fb42a..ce75fb7839 100644
@@ -5208,6 +5208,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int hvm_debug_op(struct vcpu *v, int32_t op)
 {
     int rc = 0;
@@ -5250,6 +5251,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 #ifdef CONFIG_VM_EVENT
 void hvm_toggle_singlestep(struct vcpu *v)
xen/arch/x86/hvm/pmtimer.c +2 -0
index 87a7a01c9f..f080f7561d 100644
@@ -56,6 +56,7 @@ static void pmt_update_sci(PMTState *s)
         hvm_isa_irq_deassert(s->vcpu->domain, SCI_IRQ);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void hvm_acpi_power_button(struct domain *d)
 {
     PMTState *s = &d->arch.hvm.pl_time->vpmt;
@@ -81,6 +82,7 @@ void hvm_acpi_sleep_button(struct domain *d)
     pmt_update_sci(s);
     spin_unlock(&s->lock);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* Set the correct value in the timer, accounting for time elapsed
  * since the last time we did that. */
xen/arch/x86/include/asm/p2m.h +1 -1
index 9016e88411..3574e2eecd 100644
@@ -20,7 +20,7 @@
 #include <asm/page.h>    /* for pagetable_t */
 
 /* Debugging and auditing of the P2M code? */
-#if !defined(NDEBUG) && defined(CONFIG_HVM)
+#if !defined(NDEBUG) && defined(CONFIG_HVM) && defined(CONFIG_MGMT_HYPERCALLS)
 #define P2M_AUDIT     1
 #else
 #define P2M_AUDIT     0
xen/arch/x86/include/asm/paging.h +2 -1
index 0c06b0a7a8..b95d80e75a 100644
@@ -57,7 +57,8 @@
 #endif
 #if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 /* Enable log dirty mode */
-#define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
+#define PG_log_dirty   IS_ENABLED(CONFIG_MGMT_HYPERCALLS) &&                \
+                        (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
 #define PG_log_dirty   0
 #endif
xen/common/Kconfig +1 -0
index 2914508a8f..64023703ae 100644
@@ -157,6 +157,7 @@ config HAS_SCHED_GRANULARITY
 
 config HAS_SOFT_RESET
 	bool
+	depends on MGMT_HYPERCALLS
 
 config HAS_STACK_PROTECTOR
 	bool
xen/include/hypercall-defs.c +4 -4
index 4840de805b..a08e80ed59 100644
@@ -196,10 +196,10 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl(xen_sysctl_t *u_sysctl)
-#endif
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
+#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
 platform_op(xen_platform_op_t *u_xenpf_op)
@@ -279,6 +279,9 @@ hvm_op                             do       do       do       do       do
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl                             do       do       do       do       do
+#if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+paging_domctl_cont                 do       do       do       do       -
+#endif
 #endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do
@@ -298,8 +301,5 @@ dm_op                              compat   do       compat   do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
-#if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
-paging_domctl_cont                 do       do       do       do       -
-#endif
 
 #endif /* !CPPCHECK */
xen/lib/Makefile +3 -3
index 9b3e03a511..26c6a0de33 100644
@@ -46,7 +46,7 @@ lib32-y := divmod.o
 lib32-$(CONFIG_64BIT) :=
 lib-y += $(lib32-y)
 
-libx86-y := x86/cpuid-cp2buf.o
-libx86-y += x86/cpuid-cpfrbuf.o
-libx86-y += x86/cpupolicy-clr.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) := x86/cpuid-cp2buf.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) += x86/cpuid-cpfrbuf.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) += x86/cpupolicy-clr.o
 lib-$(CONFIG_X86) += $(libx86-y)
xen/lib/x86/Makefile +2 -2
index 780ea05db1..89fb4bba27 100644
@@ -1,3 +1,3 @@
 obj-y += cpuid.o
-obj-y += msr.o
-obj-y += policy.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += msr.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += policy.o
Signature · 1 line
2.34.1
#32 lore raw

Re: [PATCH v5 20/24] xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS

xen/arch/x86/include/asm/paging.h line 61

Quoted 9 lines · Penny Zheng
xen/arch/x86/include/asm/paging.h +2 -1
@@ -57,7 +57,8 @@
 #endif
 #if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 /* Enable log dirty mode */
-#define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
+#define PG_log_dirty   IS_ENABLED(CONFIG_MGMT_HYPERCALLS) &&                \
+                        (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)

This needs wrapping in parentheses, at which point indentation of the 2nd line will then also be correct.

xen/include/hypercall-defs.c dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs) · line 202

Quoted 11 lines
xen/include/hypercall-defs.c +1 -1
@@ -196,10 +196,10 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl(xen_sysctl_t *u_sysctl)
-#endif
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
+#endif

/* CONFIG_MGMT_HYPERCALLS */ please (as soon as #if-s nest or there's other complexity).

xen/include/hypercall-defs.c hvm_op do do do do do · line 287

Quoted 10 lines
xen/include/hypercall-defs.c +3 -0
@@ -279,6 +279,9 @@ hvm_op                             do       do       do       do       do
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl                             do       do       do       do       do
+#if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+paging_domctl_cont                 do       do       do       do       -
+#endif
 #endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do

Hmm, paging_domctl_cont ahead of domctl isn't very nice. Of course much depends on how all of this will look by the end of the series.

Jan

#33 lore raw

Re: [PATCH v5 20/24] xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng
Quoted 4 lines · Penny Zheng

---
v4 -> v5:
- do not undo imply and add "depends on MGMT_HYPERCALLS" in option
- use IS_ENABLED(...) to avoid too long line

Coming back to this patch when looking at patch 24, I have to add: I don't understand this. We ...

xen/arch/x86/include/asm/paging.h line 64

Quoted 12 lines
xen/arch/x86/include/asm/paging.h +2 -1
@@ -57,7 +57,8 @@
 #endif
 #if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 /* Enable log dirty mode */
-#define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
+#define PG_log_dirty   IS_ENABLED(CONFIG_MGMT_HYPERCALLS) &&                \
+                        (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
 #define PG_log_dirty   0
 #endif

... already have an #if here, so mixing #if and IS_ENABLED() doesn't look like a good idea to me. To deal with the line length issue, all you need to do is split the line:

#if defined(CONFIG_PAGING) && defined(CONFIG_MGMT_HYPERCALLS) && \
!defined(CONFIG_PV_SHIM_EXCLUSIVE)

. The alternative could be

#define PG_log_dirty   (IS_ENABLED(CONFIG_PAGING) &&             \
                        IS_ENABLED(CONFIG_MGMT_HYPERCALLS) &&    \
                        !IS_ENABLED(CONFIG_PV_SHIM_EXCLUSIVE) && \
                        (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift))

, just that then PG_log_dirty likely can't be used in #if anymore (see the related comment on patch 24 that I'm in the process of writing).

Jan

#34 lore raw

PATCH v5 21/24 xen/arm: wrap arm-specific domctl-op with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Function arch_do_domctl() is responsible for arch-specific domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS
Guard arm-specific domctl.o compilation with CONFIG_MGMT_HYPERCALLS. Otherwise the whole file will become unreachable when MGMT_HYPERCALLS=n, and hence violating Misra Rule 2.1.

---
v3 -> v4:
- split arch-specific domctl-op into x86 and arm

---
 xen/arch/arm/Makefile       | 2 +-
 xen/arch/arm/arm32/Makefile | 2 +-
 xen/arch/arm/arm64/Makefile | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/arm/Makefile +1 -1
index 069e2c532e..91ac4d6e32 100644
@@ -20,7 +20,7 @@ obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-build.init.o
 obj-y += domain.o
 obj-y += domain_build.init.o
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-y += efi/
 obj-y += gic.o
xen/arch/arm/arm32/Makefile +1 -1
index 531168f58a..f8cbf14211 100644
@@ -4,7 +4,7 @@ obj-$(CONFIG_MPU) += mpu/
 
 obj-y += cache.o
 obj-$(CONFIG_EARLY_PRINTK) += debug.o
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += domain.o
 obj-y += entry.o
 obj-y += head.o
xen/arch/arm/arm64/Makefile +1 -1
index 6491c5350b..6b77a15abe 100644
@@ -6,7 +6,7 @@ obj-y += cache.o
 obj-y += cpufeature.o
 obj-$(CONFIG_HARDEN_BRANCH_PREDICTOR) += bpi.o
 obj-$(CONFIG_EARLY_PRINTK) += debug.o
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += domain.o
 obj-y += entry.o
 obj-y += head.o
Signature · 1 line
2.34.1
#35 lore raw

PATCH v5 22/24 x86/hvm: domctl_lock synchronization only when MGMT_HYPERCALLS=y

In reply to Penny Zheng

Helper domctl_lock_{acquire,release}() is domctl_lock, which HVM_PARAM_IDENT_PT uses to ensure synchronization on potential domctl-op altering guest state. So it is only needed when MGMT_HYPERCALLS=y.

---
v3 -> v4:
- new commit
---
v4 -> v5:
- refine title and commit message

---
 xen/arch/x86/hvm/hvm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/hvm.c +3 -2
index ce75fb7839..b52dd8f1c4 100644
@@ -4272,7 +4272,7 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
          * the domctl_lock.
          */
         rc = -ERESTART;
-        if ( !domctl_lock_acquire() )
+        if ( IS_ENABLED(CONFIG_MGMT_HYPERCALLS) && !domctl_lock_acquire() )
             break;
 
         rc = 0;
@@ -4282,7 +4282,8 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
             paging_update_cr3(v, false);
         domain_unpause(d);
 
-        domctl_lock_release();
+        if ( IS_ENABLED(CONFIG_MGMT_HYPERCALLS) )
+            domctl_lock_release();
         break;
     case HVM_PARAM_DM_DOMAIN:
         /* The only value this should ever be set to is DOMID_SELF */
Signature · 1 line
2.34.1
#36 lore raw

PATCH v5 23/24 xen/domctl: wrap common/domctl.c with CONFIG_MGMT_HYPERCALLS

In reply to Penny Zheng

Wrap domctl hypercall def and domctl.o with CONFIG_MGMT_HYPERCALLS. Make CONFIG_MGMT_HYPERCALLS optional and expand help message

---
v1 -> v2:
- remove stub in common/domctl.c
- combine the original commit of "xen/domctl: provide stub for domctl_lock_{acquire,release}"
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
---
v2 -> v3:
- add pitfall warnning in Kconfig help
---
v3 -> v4:
- refine help message
---
- change to "say Y" to keep consistent
- add back default y

---
 xen/common/Kconfig           | 16 ++++++++++++----
 xen/common/Makefile          |  2 +-
 xen/include/hypercall-defs.c |  6 ++++--
 3 files changed, 17 insertions(+), 7 deletions(-)
xen/common/Kconfig +12 -4
index 64023703ae..d59e108652 100644
@@ -653,12 +653,20 @@ menu "Supported hypercall interfaces"
 	visible if EXPERT
 
 config MGMT_HYPERCALLS
-	def_bool y
+	bool "Enable privileged hypercalls for system management"
 	depends on !PV_SHIM_EXCLUSIVE
+	default y
 	help
-	  This option shall only be disabled on some dom0less systems, or
-	  PV shim on x86, to reduce Xen footprint via managing unnessary
-	  hypercalls, like sysctl, etc.
+	  Management hypercalls provide the means for dom0 to manage the
+	  overall Xen system and other domains, including sysctl, domctl, etc.
+	  In a dom0less or pv-shim build, they can be omitted to cut down
+	  on the Xen binary's size. However, this comes at the loss of
+	  significant runtime functionality.
+	  So be cautious to disable it, as admins will face missing a few basic
+	  hypercalls like listdomains, getdomaininfo, etc, hence leading to
+	  have an impact on device-passthrough and DM.
+
+	  Unless you know what you are doing, say Y.
 
 endmenu
 
xen/common/Makefile +1 -1
index 4353ea59a4..9f59f141a8 100644
@@ -71,7 +71,7 @@ obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo un
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 endif
 
 obj-$(CONFIG_COVERAGE) += coverage/
xen/include/hypercall-defs.c +4 -2
index a08e80ed59..c9ee5de99e 100644
@@ -199,9 +199,11 @@ sysctl(xen_sysctl_t *u_sysctl)
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
-#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
+#endif
+#endif
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
 #ifdef CONFIG_HVM
@@ -282,10 +284,10 @@ sysctl                             do       do       do       do       do
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont                 do       do       do       do       -
 #endif
-#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do
 #endif
+#endif
 #ifdef CONFIG_KEXEC
 kexec_op                           compat   do       -        -        -
 #endif
Signature · 1 line
2.34.1
#37 lore raw

PATCH v5 24/24 xen: decouple PV_SHIM_EXCLUSIVE and MGMT_HYPERCALLS

In reply to Penny Zheng

We try to decouple PV_SHIM_EXCLUSIVE and MGMT_HYPERCALLS, including getting rid of "depends on !PV_SHIM_EXCLUSIVE" (and related Makefile constructs) regarding features guarded under MGMT_HYPERCALLS.
There is little possibility that random config may pick MGMT_HYPERCALLS=y and PV_SHIM_EXCLUSIVE=y, so we need to add !defined(CONFIG_PV_SHIM_EXCLUSIVE) constriction on paging_domctl() under XEN_DOMCTL_shadow_op-case to avoid undefined error.

---
v3 -> v4:
- new commit
---
v4 -> v5:
- Remove unrelated changes on CONFIG_HVM
- add !defined(CONFIG_PV_SHIM_EXCLUSIVE) constriction on paging_domctl() under XEN_DOMCTL_shadow_op-case
- refine title and commit message

---
 xen/arch/x86/Makefile        | 2 +-
 xen/arch/x86/domctl.c        | 2 +-
 xen/common/Kconfig           | 1 -
 xen/common/Makefile          | 4 +---
 xen/include/hypercall-defs.c | 4 ----
 xen/include/xen/domain.h     | 4 ----
 6 files changed, 3 insertions(+), 14 deletions(-)
xen/arch/x86/Makefile +1 -1
index d389787bb3..03650049ce 100644
@@ -31,6 +31,7 @@ obj-bin-y += dmi_scan.init.o
 obj-y += domain.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain_page.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += e820.o
 obj-y += emul-i8254.o
 obj-y += extable.o
@@ -80,7 +81,6 @@ obj-$(CONFIG_VM_EVENT) += vm_event.o
 obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += platform_hypercall.o
 obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 endif
xen/arch/x86/domctl.c +1 -1
index 6153e3c07e..235fd3b60f 100644
@@ -216,7 +216,7 @@ long arch_do_domctl(
     {
 
     case XEN_DOMCTL_shadow_op:
-#ifdef CONFIG_PAGING
+#if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
         ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
         if ( ret == -ERESTART )
             return hypercall_create_continuation(
xen/common/Kconfig +0 -1
index d59e108652..f57a5f00a3 100644
@@ -654,7 +654,6 @@ menu "Supported hypercall interfaces"
 
 config MGMT_HYPERCALLS
 	bool "Enable privileged hypercalls for system management"
-	depends on !PV_SHIM_EXCLUSIVE
 	default y
 	help
 	  Management hypercalls provide the means for dom0 to manage the
xen/common/Makefile +1 -3
index 9f59f141a8..a0b0705f72 100644
@@ -11,6 +11,7 @@ obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
 obj-$(CONFIG_DEVICE_TREE_PARSE) += device-tree/
 obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-y += domain.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += domid.o
 obj-y += event_2l.o
 obj-y += event_channel.o
@@ -70,9 +71,6 @@ obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo un
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
-ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
-endif
 
 obj-$(CONFIG_COVERAGE) += coverage/
 obj-y += sched/
xen/include/hypercall-defs.c +0 -4
index c9ee5de99e..e7209f8b63 100644
@@ -199,10 +199,8 @@ sysctl(xen_sysctl_t *u_sysctl)
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
 #endif
-#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
@@ -284,10 +282,8 @@ sysctl                             do       do       do       do       do
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont                 do       do       do       do       -
 #endif
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do
 #endif
-#endif
 #ifdef CONFIG_KEXEC
 kexec_op                           compat   do       -        -        -
 #endif
xen/include/xen/domain.h +0 -4
index 8aab05ae93..11d2505420 100644
@@ -185,11 +185,7 @@ struct vnuma_info {
     struct xen_vmemrange *vmemrange;
 };
 
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 void vnuma_destroy(struct vnuma_info *vnuma);
-#else
-static inline void vnuma_destroy(struct vnuma_info *vnuma) { ASSERT(!vnuma); }
-#endif
 
 extern bool vmtrace_available;
 
Signature · 1 line
2.34.1
#38 lore raw

Re: [PATCH v5 24/24] xen: decouple PV_SHIM_EXCLUSIVE and MGMT_HYPERCALLS

xen/arch/x86/domctl.c long arch_do_domctl( · line 222

Quoted 11 lines · Penny Zheng
xen/arch/x86/domctl.c +1 -1
@@ -216,7 +216,7 @@ long arch_do_domctl(
     {
 
     case XEN_DOMCTL_shadow_op:
-#ifdef CONFIG_PAGING
+#if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
         ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
         if ( ret == -ERESTART )
             return hypercall_create_continuation(

This, in the end, is open-coded PG_log_dirty afaict. Question then is why not use PG_log_dirty here. If there is a good reason not to, it may want spelling out in at least the description, maybe even a code comment here.

Quoted 11 lines
xen/common/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
 obj-$(CONFIG_DEVICE_TREE_PARSE) += device-tree/
 obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-y += domain.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += domid.o
 obj-y += event_2l.o
 obj-y += event_channel.o

xen/common/Makefile obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo un · line 76

Quoted 9 lines
xen/common/Makefile +0 -3
@@ -70,9 +71,6 @@ obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo un
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o xlat.o)
 
-ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
-endif
 
 obj-$(CONFIG_COVERAGE) += coverage/
 obj-y += sched/

Nit: One of the two blank lines then wants to also go away.

Jan

#39 lore raw
In reply to Penny Zheng
Quoted 28 lines · Penny Zheng

It can be beneficial for some dom0less systems to further reduce Xen footprint via disabling some hypercalls handling code, which may not to be used & required in such systems.
We are introducing a new single Kconfig CONFIG_MGMT_HYPERCALLS to manage such hypercalls.

We are trying to disable hypercalls in the following aspects:
- sysctl
- domctl
- hvm
- physdev
- platform
This patch serie is only focusing on domctl-op. Different aspects will be covered in different patch serie.

Features, like VM event, or paging log-dirty support, which fully rely on domctl-op, will be wrapped with CONFIG_MGMT_HYPERCALLS, to reduce Xen footprint as much as possible.

It is derived from Stefano Stabellini's commit "xen: introduce kconfig options to disable hypercalls"(
https://lore.kernel.org/xen-devel/[email protected])
---
This patch serie is based on "[PATCH v3 0/7] consolidate vm event subsystem"
---
The following commits are prerequisite, and could be committed independently:
- xen/xsm: remove redundant flask_iomem_mapping()
- xen/x86: library-fy cpuid-releated functions

Quoted 8 lines

- xen/arm: move dt_find_node_by_gpath() to passthrough/device_tree.c
- xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_HYPERCALLS
---
Penny Zheng (24):
xen/xsm: remove redundant flask_iomem_mapping() xen/x86: library-fy cpuid-releated functions
xen/arm: move dt_find_node_by_gpath() to passthrough/device_tree.c xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_HYPERCALLS

From past discussion I would have concluded that this is what wants doing first. Is there a reason this isn't the first patch (and hence it's unclear whether it could go in as soon as you managed to chase the - apparently - one missing ack)?

As to missing ack-s - may I once again point out that it is on you to chase them? (Daniel, first and foremost to you: Hint, hint.)

Jan