Skip to contentSkip to conversation

Introduce CONFIG_DOMCTL

PATCH In review Penny Zheng 3 participants 40 messages Aug 3, 2025 – Aug 15, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

cover Introduce CONFIG_DOMCTL

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. Each hypercall has a separate option to keep configuration flexible.

Options to disable hypercalls:
- sysctl
- domctl
- hvm
- physdev
- platform

This patch serie is only focusing on introducing CONFIG_DOMCTL. Different options 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_SYSCTL, 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])

Penny Zheng (25):
xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE
xen/x86: consolidate vram tracking support
xen/x86: complement PG_log_dirty wrapping
xen: consolidate CONFIG_VM_EVENT
xen: introduce CONFIG_DOMCTL
xen/domctl: provide stub for domctl_lock_{acquire,release} xen/domctl: wrap around XEN_DOMCTL_pausedomain xen/domctl: wrap around XEN_DOMCTL_soft_reset
xen/domctl: wrap around XEN_DOMCTL_destroydomain xen/domctl: wrap around XEN_DOMCTL_setnodeaffinity xen/domctl: wrap around XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity} xen/domctl: wrap around XEN_DOMCTL_scheduler_op xen/domctl: wrap around XEN_DOMCTL_getvcpucontext xen/domctl: wrap around XEN_DOMCTL_{irq_permission,iomem_permission} xen/domctl: wrap around XEN_DOMCTL_settimeoffset xen/domctl: wrap around XEN_DOMCTL_set_target
xen: add stub for XEN_DOMCTL_getdomaininfo
xen/domctl: wrap around XEN_DOMCTL_set_access_required
xen: make CONFIG_VM_EVENT depend on DOMCTL
xen/domctl: wrap around XEN_DOMCTL_set_virq_handler xen/domctl: wrap aound iommu-related domctl op xen/domctl: wrap around XEN_DOMCTL_{get,set}_paging_mempool_size xen/x86: make CONFIG_X86_PSR depend on SYSCTL || DOMCTL xen/domctl: wrap around arch-specific domctl op xen/domctl: wrap around domctl hypercall

 xen/arch/arm/arm32/Makefile                 |  2 +-
 xen/arch/arm/arm64/Makefile                 |  2 +-
 xen/arch/arm/domain.c                       |  5 ++
 xen/arch/arm/include/asm/tee/tee.h          |  2 +
 xen/arch/arm/mem_access.c                   |  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                        |  6 ++
 xen/arch/riscv/stubs.c                      |  2 +
 xen/arch/x86/Kconfig                        |  1 +
 xen/arch/x86/Makefile                       |  4 +-
 xen/arch/x86/configs/pvshim_defconfig       |  1 +
 xen/arch/x86/domain.c                       |  4 ++
 xen/arch/x86/domctl.c                       |  4 ++
 xen/arch/x86/emul-i8254.c                   |  2 +
 xen/arch/x86/gdbsx.c                        |  4 ++
 xen/arch/x86/hvm/Makefile                   |  4 +-
 xen/arch/x86/hvm/hvm.c                      |  4 ++
 xen/arch/x86/hvm/pmtimer.c                  |  2 +
 xen/arch/x86/hvm/save.c                     |  2 +
 xen/arch/x86/hvm/svm/svm.c                  |  8 +++
 xen/arch/x86/hvm/vmx/vmx.c                  | 16 +++++
 xen/arch/x86/include/asm/hvm/hvm.h          | 22 +++++++
 xen/arch/x86/include/asm/hvm/monitor.h      | 65 ++++++++++++++++++++-
 xen/arch/x86/include/asm/hvm/vm_event.h     |  4 ++
 xen/arch/x86/include/asm/hypercall.h        |  2 +
 xen/arch/x86/include/asm/mem_access.h       |  9 +++
 xen/arch/x86/include/asm/monitor.h          | 15 +++++
 xen/arch/x86/include/asm/p2m.h              |  8 ++-
 xen/arch/x86/include/asm/paging.h           | 34 +++++------
 xen/arch/x86/mm/hap/hap.c                   | 38 ++++++++++++
 xen/arch/x86/mm/mem_access.c                |  2 +
 xen/arch/x86/mm/mem_paging.c                |  2 +
 xen/arch/x86/mm/mem_sharing.c               |  4 ++
 xen/arch/x86/mm/p2m-pod.c                   |  2 +
 xen/arch/x86/mm/p2m.c                       |  2 +
 xen/arch/x86/mm/paging.c                    | 36 ++----------
 xen/arch/x86/mm/shadow/common.c             |  8 +++
 xen/arch/x86/mm/shadow/none.c               |  4 ++
 xen/arch/x86/psr.c                          | 18 ------
 xen/arch/x86/time.c                         |  2 +
 xen/common/Kconfig                          |  9 ++-
 xen/common/Makefile                         |  5 +-
 xen/common/argo.c                           |  2 +
 xen/common/device-tree/device-tree.c        |  2 +
 xen/common/domain.c                         | 10 ++++
 xen/common/event_channel.c                  |  2 +
 xen/common/grant_table.c                    |  2 +
 xen/common/sched/arinc653.c                 |  2 +
 xen/common/sched/core.c                     |  6 ++
 xen/common/sched/credit.c                   |  4 ++
 xen/common/sched/credit2.c                  |  4 ++
 xen/common/sched/private.h                  |  4 ++
 xen/common/sched/rt.c                       |  4 ++
 xen/common/vm_event.c                       |  2 +
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  8 +++
 xen/drivers/passthrough/arm/ipmmu-vmsa.c    |  6 ++
 xen/drivers/passthrough/arm/smmu-v3.c       |  4 ++
 xen/drivers/passthrough/arm/smmu.c          |  4 ++
 xen/drivers/passthrough/device_tree.c       |  6 ++
 xen/drivers/passthrough/iommu.c             |  2 +
 xen/drivers/passthrough/pci.c               |  6 ++
 xen/drivers/passthrough/vtd/iommu.c         |  6 ++
 xen/include/hypercall-defs.c                | 10 +++-
 xen/include/xen/domain.h                    | 18 ++++--
 xen/include/xen/mem_access.h                | 36 +++++++++++-
 xen/include/xen/monitor.h                   |  8 ++-
 xen/include/xen/vm_event.h                  | 24 +++++++-
 xen/include/xsm/dummy.h                     |  2 +
 xen/include/xsm/xsm.h                       | 40 ++++++++++---
 xen/lib/x86/Makefile                        |  2 +-
 xen/xsm/dummy.c                             | 16 ++++-
 xen/xsm/flask/hooks.c                       | 36 +++++++++---
 77 files changed, 550 insertions(+), 118 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/25 xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail.
To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation
Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Fixes 568f806cba4c ("xen/x86: remove "depends on !PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

---
 xen/arch/x86/Makefile        | 2 +-
 xen/common/Makefile          | 5 +----
 xen/include/hypercall-defs.c | 6 +-----
 xen/include/xen/domain.h     | 4 ----
 4 files changed, 3 insertions(+), 14 deletions(-)
xen/arch/x86/Makefile +1 -1
index 5aab30a0c4..7676d7cdd8 100644
@@ -28,6 +28,7 @@ obj-y += delay.o
 obj-y += desc.o
 obj-bin-y += dmi_scan.init.o
 obj-y += domain.o
+obj-y += domctl.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain_page.o
 obj-y += e820.o
@@ -79,7 +80,6 @@ obj-y += vm_event.o
 obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-y += domctl.o
 obj-y += platform_hypercall.o
 obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 endif
xen/common/Makefile +1 -4
index c316957fcb..756ddf52c3 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-y += domctl.o
 obj-y += event_2l.o
 obj-y += event_channel.o
 obj-$(CONFIG_EVTCHN_FIFO) += event_fifo.o
@@ -69,10 +70,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-y += domctl.o
-endif
-
 extra-y := symbols-dummy.o
 
 obj-$(CONFIG_COVERAGE) += coverage/
xen/include/hypercall-defs.c +1 -5
index c1081d87a2..a2f2a7fa75 100644
@@ -197,9 +197,9 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #ifdef CONFIG_SYSCTL
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
 paging_domctl_cont(xen_domctl_t *u_domctl)
+#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
 #ifdef CONFIG_HVM
@@ -278,9 +278,7 @@ hvm_op                             do       do       do       do       do
 #ifdef CONFIG_SYSCTL
 sysctl                             do       do       do       do       do
 #endif
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do
-#endif
 #ifdef CONFIG_KEXEC
 kexec_op                           compat   do       -        -        -
 #endif
@@ -296,8 +294,6 @@ dm_op                              compat   do       compat   do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
 paging_domctl_cont                 do       do       do       do       -
-#endif
 
 #endif /* !CPPCHECK */
xen/include/xen/domain.h +0 -4
index e10baf2615..33dd90357c 100644
@@ -182,11 +182,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
#2 lore raw

Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 11 lines · Penny Zheng

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail.
To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation
Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Quoted 6 lines
Fixes 568f806cba4c ("xen/x86: remove "depends on !PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

And you've run this through a full round of testing this time, in isolation?

Jan

#3 lore raw

RE: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

[Public]

Quoted 32 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:43 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 11 lines · Penny Zheng

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail. To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Quoted 7 lines
Fixes 568f806cba4c ("xen/x86: remove "depends on

!PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

Quoted 2 lines

And you've run this through a full round of testing this time, in isolation?

This commit shall be committed together with "xen/x86: complement PG_log_dirty wrapping", (I've added in change log, idk why it didn't get delivered in the mail list in the last). As PG_log_dirty is disabled on PV mode, paging_domctl() will still have "undefined reference" on PV mode, which gets fixed in "xen/x86: complement PG_log_dirty wrapping". I thought it better sits there. If it doesn't comply with the commit policy, I'll move according fix here.

Quoted 1 line

Jan

#4 lore raw

Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 34 lines · Zheng

[Public]

Quoted 32 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:43 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 18 lines · Penny Zheng

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail. To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Fixes 568f806cba4c ("xen/x86: remove "depends on

!PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

Quoted 3 lines
Quoted 1 line

And you've run this through a full round of testing this time, in isolation?

This commit shall be committed together with "xen/x86: complement PG_log_dirty wrapping", (I've added in change log, idk why it didn't get delivered in the mail list in the last).

And "committed together" still means the two at least build okay independently (i.e. allowing the build-each-commit job to succeed)?

As to the missing indication thereof in the submission: Patch 01 has a revlog, so if anything was missing there you must have added it some other way. But the cover letter is lacking that information as well. (As indicated earlier, to increase the chance of such a remark actually being noticed, it's best put in both places.)

Quoted 2 lines

As PG_log_dirty is disabled on PV mode, paging_domctl() will still have "undefined reference" on PV mode, which gets fixed in "xen/x86: complement PG_log_dirty wrapping". I thought it better sits there. If it doesn't comply with the commit policy, I'll move according fix here.

Let me post a pair of patches dealing with part of the problem, in an imo (longer term) more desirable way.

Jan

Reviewed-by
#5 lore raw

Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 48 lines · Jan Beulich
Quoted 34 lines · Zheng

[Public]

Quoted 32 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:43 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 18 lines · Penny Zheng

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail. To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Fixes 568f806cba4c ("xen/x86: remove "depends on

!PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

Quoted 3 lines
Quoted 1 line

And you've run this through a full round of testing this time, in isolation?

This commit shall be committed together with "xen/x86: complement PG_log_dirty wrapping", (I've added in change log, idk why it didn't get delivered in the mail list in the last).

And "committed together" still means the two at least build okay independently (i.e. allowing the build-each-commit job to succeed)?

As to the missing indication thereof in the submission: Patch 01 has a revlog, so if anything was missing there you must have added it some other way. But the cover letter is lacking that information as well. (As indicated earlier, to increase the chance of such a remark actually being noticed, it's best put in both places.)

Quoted 5 lines
Quoted 2 lines

As PG_log_dirty is disabled on PV mode, paging_domctl() will still have "undefined reference" on PV mode, which gets fixed in "xen/x86: complement PG_log_dirty wrapping". I thought it better sits there. If it doesn't comply with the commit policy, I'll move according fix here.

Let me post a pair of patches dealing with part of the problem, in an imo (longer term) more desirable way.

With this patch https://marc.info/?l=xen-devel&m=175438069103017
committed, can we go ahead with this patch, to resolve the outstanding build problem?

#6 lore raw

Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Jan Beulich
Quoted 34 lines · Zheng

[Public]

Quoted 32 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:43 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 18 lines · Penny Zheng

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail. To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of CONFIG_DOMCTL.

Fixes 568f806cba4c ("xen/x86: remove "depends on

!PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

Quoted 3 lines
Quoted 1 line

And you've run this through a full round of testing this time, in isolation?

This commit shall be committed together with "xen/x86: complement PG_log_dirty wrapping", (I've added in change log, idk why it didn't get delivered in the mail list in the last).

And "committed together" still means the two at least build okay independently (i.e. allowing the build-each-commit job to succeed)?

As to the missing indication thereof in the submission: Patch 01 has a revlog, so if anything was missing there you must have added it some other way. But the cover letter is lacking that information as well. (As indicated earlier, to increase the chance of such a remark actually being noticed, it's best put in both places.)

Quoted 2 lines

As PG_log_dirty is disabled on PV mode, paging_domctl() will still have "undefined reference" on PV mode, which gets fixed in "xen/x86: complement PG_log_dirty wrapping". I thought it better sits there. If it doesn't comply with the commit policy, I'll move according fix here.

Quoted 6 lines
Quoted 2 lines

Let me post a pair of patches dealing with part of the problem, in an imo (longer term) more desirable way.

With this patch https://marc.info/?l=xen-devel&m=175438069103017
committed, can we go ahead with this patch, to resolve the outstanding build problem?

It first needs re-basing, I expect. There were also other anomalies, like a requirement to commit together with another patch.

Jan

#7 lore raw

RE: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

[Public]

Quoted 74 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, August 15, 2025 4:12 PM
To: Stefano Stabellini <[email protected]>
Cc: Penny, Zheng <[email protected]>; Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

Quoted 18 lines · Stefano Stabellini
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Zheng

[Public]

Quoted 14 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:43 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v1 01/25] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE

On 03.08.2025 11:47, Penny Zheng wrote:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

In order to fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in hvm.c being built, but domctl.c not being built, which leaves a few functions, like domctl_lock_acquire/release() undefined, causing linking to fail. To fix that, we intend to move domctl.o out of the PV_SHIM_EXCLUSIVE Makefile /hypercall-defs section, with this adjustment, we also need to release redundant vnuma_destroy() stub definition and paging_domctl hypercall-defs from PV_SHIM_EXCLUSIVE guardian, to not break compilation Above change will leave dead code in the shim binary temporarily and will be fixed with the introduction of

CONFIG_DOMCTL.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Fixes 568f806cba4c ("xen/x86: remove "depends on

!PV_SHIM_EXCLUSIVE"")

---
v1 -> v2:
- remove paging_domctl hypercall-defs

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

And you've run this through a full round of testing this time, in isolation?

This commit shall be committed together with "xen/x86: complement

PG_log_dirty wrapping", (I've added in change log, idk why it didn't get delivered in the mail list in the last).

Quoted 11 lines
Quoted 11 lines

And "committed together" still means the two at least build okay independently (i.e. allowing the build-each-commit job to succeed)?

As to the missing indication thereof in the submission: Patch 01 has a revlog, so if anything was missing there you must have added it some other way. But the cover letter is lacking that information as well. (As indicated earlier, to increase the chance of such a remark actually being noticed, it's best put in both places.)

Quoted 1 line

As PG_log_dirty is disabled on PV mode, paging_domctl() will still have

"undefined reference" on PV mode, which gets fixed in "xen/x86: complement PG_log_dirty wrapping". I thought it better sits there.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

If it doesn't comply with the commit policy, I'll move according fix here.

Let me post a pair of patches dealing with part of the problem, in an imo (longer term) more desirable way.

Quoted 7 lines
Quoted 3 lines

With this patch https://marc.info/?l=xen-devel&m=175438069103017
committed, can we go ahead with this patch, to resolve the outstanding build problem?

It first needs re-basing, I expect. There were also other anomalies, like a requirement to commit together with another patch.

I've prepared this commit only on the basis of https://marc.info/?l=xen-devel&m=175438069103017 , and also with it, I think another patch "xen/x86: complement PG_log_dirty wrapping" required to commit together is also no longer needed.

Quoted 1 line

Jan

#8 lore raw

PATCH 2/25 xen/x86: consolidate vram tracking support

In reply to Penny Zheng

Flag PG_log_dirty is for paging log dirty support, not vram tracking support. However data structure sh_dirty_vram{} and function paging_log_dirty_range() designed for vram tracking support, are guarded with PG_log_dirty. We release both from PG_log_dirty, and also move paging_log_dirty_range() into hap.c, to make it static.

---
 xen/arch/x86/include/asm/paging.h | 32 +++++++++++++------------------
 xen/arch/x86/mm/hap/hap.c         | 32 +++++++++++++++++++++++++++++++
 xen/arch/x86/mm/paging.c          | 32 -------------------------------
 3 files changed, 45 insertions(+), 51 deletions(-)
xen/arch/x86/include/asm/paging.h +13 -19
index 8a2a0af408..173a569610 100644
@@ -133,13 +133,20 @@ struct paging_mode {
     (DIV_ROUND_UP(PADDR_BITS - PAGE_SHIFT - (PAGE_SHIFT + 3), \
                   PAGE_SHIFT - ilog2(sizeof(mfn_t))) + 1)
 
-#if PG_log_dirty
+#ifdef CONFIG_HVM
+/* VRAM dirty tracking support */
+struct sh_dirty_vram {
+    unsigned long begin_pfn;
+    unsigned long end_pfn;
+#ifdef CONFIG_SHADOW_PAGING
+    paddr_t *sl1ma;
+    uint8_t *dirty_bitmap;
+    s_time_t last_dirty;
+#endif
+};
+#endif
 
-/* get the dirty bitmap for a specific range of pfns */
-void paging_log_dirty_range(struct domain *d,
-                            unsigned long begin_pfn,
-                            unsigned long nr,
-                            uint8_t *dirty_bitmap);
+#if PG_log_dirty
 
 /* log dirty initialization */
 void paging_log_dirty_init(struct domain *d, const struct log_dirty_ops *ops);
@@ -171,19 +178,6 @@ bool paging_mfn_is_dirty(const struct domain *d, mfn_t gmfn);
 #define L4_LOGDIRTY_IDX(pfn) ((pfn_x(pfn) >> (PAGE_SHIFT + 3 + PAGETABLE_ORDER * 2)) & \
                               (LOGDIRTY_NODE_ENTRIES-1))
 
-#ifdef CONFIG_HVM
-/* VRAM dirty tracking support */
-struct sh_dirty_vram {
-    unsigned long begin_pfn;
-    unsigned long end_pfn;
-#ifdef CONFIG_SHADOW_PAGING
-    paddr_t *sl1ma;
-    uint8_t *dirty_bitmap;
-    s_time_t last_dirty;
-#endif
-};
-#endif
-
 #else /* !PG_log_dirty */
 
 static inline void paging_log_dirty_init(struct domain *d,
xen/arch/x86/mm/hap/hap.c +32 -0
index ec5043a8aa..668a233923 100644
@@ -36,6 +36,38 @@
 /*          HAP VRAM TRACKING SUPPORT           */
 /************************************************/
 
+#ifdef CONFIG_HVM
+static void paging_log_dirty_range(struct domain *d,
+                                   unsigned long begin_pfn,
+                                   unsigned long nr,
+                                   uint8_t *dirty_bitmap)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int i;
+    unsigned long pfn;
+
+    /*
+     * Set l1e entries of P2M table to be read-only.
+     *
+     * On first write, it page faults, its entry is changed to read-write,
+     * and on retry the write succeeds.
+     *
+     * We populate dirty_bitmap by looking for entries that have been
+     * switched to read-write.
+     */
+
+    p2m_lock(p2m);
+
+    for ( i = 0, pfn = begin_pfn; pfn < begin_pfn + nr; i++, pfn++ )
+        if ( !p2m_change_type_one(d, pfn, p2m_ram_rw, p2m_ram_logdirty) )
+            dirty_bitmap[i >> 3] |= (1 << (i & 7));
+
+    p2m_unlock(p2m);
+
+    guest_flush_tlb_mask(d, d->dirty_cpumask);
+}
+#endif /* CONFIG_HVM */
+
 /*
  * hap_track_dirty_vram()
  * Create the domain's dv_dirty_vram struct on demand.
xen/arch/x86/mm/paging.c +0 -32
index c77f4c1dac..1216a181c3 100644
@@ -583,38 +583,6 @@ static int paging_log_dirty_op(struct domain *d,
     return rv;
 }
 
-#ifdef CONFIG_HVM
-void paging_log_dirty_range(struct domain *d,
-                           unsigned long begin_pfn,
-                           unsigned long nr,
-                           uint8_t *dirty_bitmap)
-{
-    struct p2m_domain *p2m = p2m_get_hostp2m(d);
-    int i;
-    unsigned long pfn;
-
-    /*
-     * Set l1e entries of P2M table to be read-only.
-     *
-     * On first write, it page faults, its entry is changed to read-write,
-     * and on retry the write succeeds.
-     *
-     * We populate dirty_bitmap by looking for entries that have been
-     * switched to read-write.
-     */
-
-    p2m_lock(p2m);
-
-    for ( i = 0, pfn = begin_pfn; pfn < begin_pfn + nr; i++, pfn++ )
-        if ( !p2m_change_type_one(d, pfn, p2m_ram_rw, p2m_ram_logdirty) )
-            dirty_bitmap[i >> 3] |= (1 << (i & 7));
-
-    p2m_unlock(p2m);
-
-    guest_flush_tlb_mask(d, d->dirty_cpumask);
-}
-#endif
-
 /*
  * Callers must supply log_dirty_ops for the log dirty code to call. This
  * function usually is invoked when paging is enabled. Check shadow_enable()
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v1 02/25] xen/x86: consolidate vram tracking support

Quoted 3 lines · Penny Zheng

Flag PG_log_dirty is for paging log dirty support, not vram tracking support. However data structure sh_dirty_vram{} and function paging_log_dirty_range() designed for vram tracking support, are guarded with PG_log_dirty.

The struct decl is guarded by both, which is fine, merely a bit redundant. I'm okay with moving it if that helps elsewhere.

Quoted 2 lines

We release both from PG_log_dirty, and also move paging_log_dirty_range() into hap.c, to make it static.

This, I think, wants doing separately. paging.c isn't quite a correct home for it, yes, but neither is hap/hap.c. This is noticeable first and foremost from ...

Quoted 17 lines
xen/arch/x86/mm/hap/hap.c +11 -0
@@ -36,6 +36,38 @@
 /*          HAP VRAM TRACKING SUPPORT           */
 /************************************************/
 
+#ifdef CONFIG_HVM
+static void paging_log_dirty_range(struct domain *d,
+                                   unsigned long begin_pfn,
+                                   unsigned long nr,
+                                   uint8_t *dirty_bitmap)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+    int i;
+    unsigned long pfn;
+
+    /*

xen/arch/x86/mm/hap/hap.c line 59

Quoted 10 lines
xen/arch/x86/mm/hap/hap.c +10 -0
+     * Set l1e entries of P2M table to be read-only.
+     *
+     * On first write, it page faults, its entry is changed to read-write,
+     * and on retry the write succeeds.
+     *
+     * We populate dirty_bitmap by looking for entries that have been
+     * switched to read-write.
+     */
+
+    p2m_lock(p2m);

... the lock it uses. This function really wants to move to p2m.c imo, and be suitably renamed (s/paging_/p2m_/). While there please also consider switching i to unsigned int.

xen/arch/x86/mm/hap/hap.c line 69

Quoted 9 lines
xen/arch/x86/mm/hap/hap.c +9 -0
+    for ( i = 0, pfn = begin_pfn; pfn < begin_pfn + nr; i++, pfn++ )
+        if ( !p2m_change_type_one(d, pfn, p2m_ram_rw, p2m_ram_logdirty) )
+            dirty_bitmap[i >> 3] |= (1 << (i & 7));
+
+    p2m_unlock(p2m);
+
+    guest_flush_tlb_mask(d, d->dirty_cpumask);
+}
+#endif /* CONFIG_HVM */

This #ifdef / #endif isn't needed. Neither when it lives in hap/hap.c (the parent dir's Makefile has

obj-$(CONFIG_HVM) += hap/

) nor when in p2m.c. The function then still not being non-static is acceptable; it living where it logically belongs is more important imo.

Jan

#10 lore raw

PATCH 3/25 xen/x86: complement PG_log_dirty wrapping

In reply to Penny Zheng

We have PG_log_dirty flag to wrap codes about paging log-dirty support. The main entry is paging_domctl(), and tracking its call chain, the following functions needs wrapping too:
- xsm_shadow_control
- hvm_mapped_guest_frames_mark_dirty
- hap_domctl
- shadow_domctl
- shadow_test_disable
- shadow_one_bit_disable
- shadow_test_enable
- shadow_get_allocation
- log_dirty_ops.enable
- hap_enable_log_dirty
- sh_enable_log_dirty
- _toggle_log_dirty
- log_dirty_ops.disable
- hap_disable_log_dirty
- sh_disable_log_dirty
- log_dirty_ops.clean
- hap_clean_dirty_bitmap
- sh_clean_dirty_bitmap
- _clean_dirty_bitmap
Wrap paging_domctl hypercall-defs with PG_log_dirty and release PG_log_dirty from PV_SHIM_EXCLUSIVE, as PV_SHIM_EXCLUSIVE will be cleaned up in the future.

---
 xen/arch/x86/domctl.c                | 4 ++++
 xen/arch/x86/hvm/hvm.c               | 2 ++
 xen/arch/x86/include/asm/hypercall.h | 2 ++
 xen/arch/x86/include/asm/paging.h    | 2 +-
 xen/arch/x86/mm/hap/hap.c            | 6 ++++++
 xen/arch/x86/mm/shadow/common.c      | 8 ++++++++
 xen/arch/x86/mm/shadow/none.c        | 4 ++++
 xen/include/hypercall-defs.c         | 4 ++++
 xen/include/xsm/xsm.h                | 4 ++++
 xen/xsm/dummy.c                      | 2 ++
 xen/xsm/flask/hooks.c                | 4 ++++
 11 files changed, 41 insertions(+), 1 deletion(-)
xen/arch/x86/domctl.c +4 -0
index 3044f706de..156c74e07a 100644
@@ -213,10 +213,14 @@ long arch_do_domctl(
     {
 
     case XEN_DOMCTL_shadow_op:
+#if PG_log_dirty
         ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
         if ( ret == -ERESTART )
             return hypercall_create_continuation(
                        __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
+#else
+        ret = -EOPNOTSUPP;
+#endif /* PG_log_dirty */
         copyback = true;
         break;
 
xen/arch/x86/hvm/hvm.c +2 -0
index cb8ecd050d..ea97815deb 100644
@@ -2831,6 +2831,7 @@ void hvm_unmap_guest_frame(void *p, bool permanent)
     put_page(page);
 }
 
+#if PG_log_dirty
 void hvm_mapped_guest_frames_mark_dirty(struct domain *d)
 {
     struct hvm_write_map *track;
@@ -2840,6 +2841,7 @@ void hvm_mapped_guest_frames_mark_dirty(struct domain *d)
         paging_mark_dirty(d, page_to_mfn(track->page));
     spin_unlock(&d->arch.hvm.write_map.lock);
 }
+#endif /* PG_log_dirty */
 
 static void *hvm_map_entry(unsigned long va, bool *writable)
 {
xen/arch/x86/include/asm/hypercall.h +2 -0
index f6e9e2313b..fac93527ce 100644
@@ -16,7 +16,9 @@
 #include <public/arch-x86/xen-mca.h> /* for do_mca */
 #include <asm/paging.h>
 
+#if PG_log_dirty
 #define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+#endif
 
 #ifdef CONFIG_PV
 void pv_hypercall(struct cpu_user_regs *regs);
xen/arch/x86/include/asm/paging.h +1 -1
index 173a569610..956b83215c 100644
@@ -55,7 +55,7 @@
 #define PG_translate   0
 #define PG_external    0
 #endif
-#if defined(CONFIG_HVM) || !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+#if defined(CONFIG_HVM)
 /* Enable log dirty mode */
 #define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
xen/arch/x86/mm/hap/hap.c +6 -0
index 668a233923..ccbc9128dd 100644
@@ -189,6 +189,7 @@ out:
     return rc;
 }
 
+#if PG_log_dirty
 /************************************************/
 /*            HAP LOG DIRTY SUPPORT             */
 /************************************************/
@@ -254,6 +255,7 @@ static void cf_check hap_clean_dirty_bitmap(struct domain *d)
     p2m_change_entry_type_global(d, p2m_ram_rw, p2m_ram_logdirty);
     guest_flush_tlb_mask(d, d->dirty_cpumask);
 }
+#endif /* PG_log_dirty */
 
 /************************************************/
 /*             HAP SUPPORT FUNCTIONS            */
@@ -468,9 +470,11 @@ static bool cf_check flush_tlb(const unsigned long *vcpu_bitmap);
 void hap_domain_init(struct domain *d)
 {
     static const struct log_dirty_ops hap_ops = {
+#if PG_log_dirty
         .enable  = hap_enable_log_dirty,
         .disable = hap_disable_log_dirty,
         .clean   = hap_clean_dirty_bitmap,
+#endif
     };
 
     /* Use HAP logdirty mechanism. */
@@ -662,6 +666,7 @@ out:
     paging_unlock(d);
 }
 
+#if PG_log_dirty
 int hap_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
@@ -692,6 +697,7 @@ int hap_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
         return -EINVAL;
     }
 }
+#endif /* PG_log_dirty */
 
 static const struct paging_mode hap_paging_real_mode;
 static const struct paging_mode hap_paging_protected_mode;
xen/arch/x86/mm/shadow/common.c +8 -0
index 0176e33bc9..f678e7b149 100644
@@ -69,9 +69,11 @@ const uint8_t sh_type_to_size[] = {
 
 DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags);
 
+#if PG_log_dirty
 static int cf_check sh_enable_log_dirty(struct domain *);
 static int cf_check sh_disable_log_dirty(struct domain *);
 static void cf_check sh_clean_dirty_bitmap(struct domain *);
+#endif
 
 static void cf_check shadow_update_paging_modes(struct vcpu *);
 
@@ -80,9 +82,11 @@ static void cf_check shadow_update_paging_modes(struct vcpu *);
 int shadow_domain_init(struct domain *d)
 {
     static const struct log_dirty_ops sh_ops = {
+#if PG_log_dirty
         .enable  = sh_enable_log_dirty,
         .disable = sh_disable_log_dirty,
         .clean   = sh_clean_dirty_bitmap,
+#endif
     };
 
     INIT_PAGE_LIST_HEAD(&d->arch.paging.shadow.pinned_shadows);
@@ -1414,6 +1418,7 @@ int shadow_set_allocation(struct domain *d, unsigned int pages, bool *preempted)
     return 0;
 }
 
+#if PG_log_dirty
 /* Return the size of the shadow pool, rounded up to the nearest MB */
 static unsigned int shadow_get_allocation(struct domain *d)
 {
@@ -1422,6 +1427,7 @@ static unsigned int shadow_get_allocation(struct domain *d)
     return ((pg >> (20 - PAGE_SHIFT))
             + ((pg & ((1 << (20 - PAGE_SHIFT)) - 1)) ? 1 : 0));
 }
+#endif /* PG_log_dirty */
 
 /**************************************************************************/
 /* Hash table for storing the guest->shadow mappings.
@@ -2958,6 +2964,7 @@ static int shadow_one_bit_enable(struct domain *d, u32 mode)
     return 0;
 }
 
+#if PG_log_dirty
 static int shadow_one_bit_disable(struct domain *d, u32 mode)
 /* Turn off a single shadow mode feature */
 {
@@ -3158,6 +3165,7 @@ int shadow_domctl(struct domain *d,
     }
 }
 
+#endif /* PG_log_dirty */
 
 /**************************************************************************/
 /* Auditing shadow tables */
xen/arch/x86/mm/shadow/none.c +4 -0
index 2a4005a795..6c6971b458 100644
@@ -1,6 +1,7 @@
 #include <xen/mm.h>
 #include <asm/shadow.h>
 
+#if PG_log_dirty
 static int cf_check _toggle_log_dirty(struct domain *d)
 {
     ASSERT(is_pv_domain(d));
@@ -11,6 +12,7 @@ static void cf_check _clean_dirty_bitmap(struct domain *d)
 {
     ASSERT(is_pv_domain(d));
 }
+#endif /* PG_log_dirty */
 
 static void cf_check _update_paging_modes(struct vcpu *v)
 {
@@ -21,9 +23,11 @@ int shadow_domain_init(struct domain *d)
 {
     /* For HVM set up pointers for safety, then fail. */
     static const struct log_dirty_ops sh_none_ops = {
+#if PG_log_dirty
         .enable  = _toggle_log_dirty,
         .disable = _toggle_log_dirty,
         .clean   = _clean_dirty_bitmap,
+#endif
     };
 
     paging_log_dirty_init(d, &sh_none_ops);
xen/include/hypercall-defs.c +4 -0
index a2f2a7fa75..c70f745ac2 100644
@@ -198,7 +198,9 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
 domctl(xen_domctl_t *u_domctl)
+#if PG_log_dirty
 paging_domctl_cont(xen_domctl_t *u_domctl)
+#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
@@ -294,6 +296,8 @@ dm_op                              compat   do       compat   do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
+#if PG_log_dirty
 paging_domctl_cont                 do       do       do       do       -
+#endif
 
 #endif /* !CPPCHECK */
xen/include/xsm/xsm.h +4 -0
index 9a23d2827c..dad69905c9 100644
@@ -173,7 +173,9 @@ struct xsm_ops {
 
 #ifdef CONFIG_X86
     int (*do_mca)(void);
+#if PG_log_dirty
     int (*shadow_control)(struct domain *d, uint32_t op);
+#endif
     int (*mem_sharing_op)(struct domain *d, struct domain *cd, int op);
     int (*apic)(struct domain *d, int cmd);
     int (*machine_memory_map)(void);
@@ -687,11 +689,13 @@ static inline int xsm_do_mca(xsm_default_t def)
     return alternative_call(xsm_ops.do_mca);
 }
 
+#if PG_log_dirty
 static inline int xsm_shadow_control(
     xsm_default_t def, struct domain *d, uint32_t op)
 {
     return alternative_call(xsm_ops.shadow_control, d, op);
 }
+#endif
 
 static inline int xsm_mem_sharing_op(
     xsm_default_t def, struct domain *d, struct domain *cd, int op)
xen/xsm/dummy.c +2 -0
index 8b7e01b506..8a893c6eee 100644
@@ -132,7 +132,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .platform_op                   = xsm_platform_op,
 #ifdef CONFIG_X86
     .do_mca                        = xsm_do_mca,
+#if PG_log_dirty
     .shadow_control                = xsm_shadow_control,
+#endif
     .mem_sharing_op                = xsm_mem_sharing_op,
     .apic                          = xsm_apic,
     .machine_memory_map            = xsm_machine_memory_map,
xen/xsm/flask/hooks.c +4 -0
index b0308e1b26..0382182f94 100644
@@ -1605,6 +1605,7 @@ static int cf_check flask_do_mca(void)
     return domain_has_xen(current->domain, XEN__MCA_OP);
 }
 
+#if PG_log_dirty
 static int cf_check flask_shadow_control(struct domain *d, uint32_t op)
 {
     uint32_t perm;
@@ -1631,6 +1632,7 @@ static int cf_check flask_shadow_control(struct domain *d, uint32_t op)
 
     return current_has_perm(d, SECCLASS_SHADOW, perm);
 }
+#endif /* PG_log_dirty */
 
 struct ioport_has_perm_data {
     uint32_t ssid;
@@ -2003,7 +2005,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .platform_op = flask_platform_op,
 #ifdef CONFIG_X86
     .do_mca = flask_do_mca,
+#if PG_log_dirty
     .shadow_control = flask_shadow_control,
+#endif
     .mem_sharing_op = flask_mem_sharing_op,
     .apic = flask_apic,
     .machine_memory_map = flask_machine_memory_map,
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v1 03/25] xen/x86: complement PG_log_dirty wrapping

Quoted 2 lines · Penny Zheng

We have PG_log_dirty flag to wrap codes about paging log-dirty support. The main entry is paging_domctl(),

Yet paging_domctl() serves other paging modes, too. In fact for the shim PG_SH_forced is actually a mode that could plausibly come into use (even if not by way of a toolstack requesting it). It was previously indicated that it was wrong for SHADOW_PAGING to be forced off in shim-exclusive mode. No patch ever surfaced, but that may want sorting before any new boundaries are to be drawn. In fact, ...

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

Quoted 10 lines
xen/arch/x86/include/asm/paging.h +1 -1
@@ -55,7 +55,7 @@
 #define PG_translate   0
 #define PG_external    0
 #endif
-#if defined(CONFIG_HVM) || !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+#if defined(CONFIG_HVM)
 /* Enable log dirty mode */
 #define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)

... the conditional here likely wants to become

#if defined(CONFIG_HVM) || defined(CONFIG_SHADOW_PAGING)

instead. This might actually be a far more isolated change then, still moving you in the direction that you want (I think).

Quoted 11 lines
xen/arch/x86/mm/hap/hap.c +1 -0
@@ -189,6 +189,7 @@ out:
     return rc;
 }
 
+#if PG_log_dirty
 /************************************************/
 /*            HAP LOG DIRTY SUPPORT             */
 /************************************************/

xen/arch/x86/mm/hap/hap.c static void cf_check hap_clean_dirty_bitmap(struct domain *d) · line 258

Quoted 4 lines
xen/arch/x86/mm/hap/hap.c +1 -0
@@ -254,6 +255,7 @@ static void cf_check hap_clean_dirty_bitmap(struct domain *d)
     p2m_change_entry_type_global(d, p2m_ram_rw, p2m_ram_logdirty);
     guest_flush_tlb_mask(d, d->dirty_cpumask);
 }
+#endif /* PG_log_dirty */

Please also don't go overboard with #ifdef-ary: Files built for HVM=y only don't need these, as HVM=y implies non-zero PG_log_dirty. But maybe, with the other change that I outlined, you won't even need all of this anymore.

Jan

#12 lore raw

Re: [PATCH v1 03/25] xen/x86: complement PG_log_dirty wrapping

In reply to Penny Zheng
Quoted 13 lines · Penny Zheng
xen/include/hypercall-defs.c +2 -0
@@ -198,7 +198,9 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
 domctl(xen_domctl_t *u_domctl)
+#if PG_log_dirty
 paging_domctl_cont(xen_domctl_t *u_domctl)
+#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif

xen/include/hypercall-defs.c dm_op compat do compat do do · line 301

Quoted 6 lines
xen/include/hypercall-defs.c +2 -0
@@ -294,6 +296,8 @@ dm_op                              compat   do       compat   do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
+#if PG_log_dirty
 paging_domctl_cont                 do       do       do       do       -
+#endif

While putting together my pair of patches, I figured that using PG_log_dirty here is wrong. asm/paging.h isn't (and cannot easily be) included, and hence the compiler will consider PG_log_dirty uniformly 0, no matter what .config holds.

Jan

#13 lore raw

PATCH 4/25 xen: consolidate CONFIG_VM_EVENT

In reply to Penny Zheng

File hvm/vm_event.c and x86/vm_event.c are the extend to vm_event handling routines, and its compilation shall be guarded by CONFIG_VM_EVENT too. Futhermore, features about monitor_op and memory access are both based on vm event subsystem, so monitor.o/mem_access.o shall be wrapped under CONFIG_VM_EVENT.

Although CONFIG_VM_EVENT is forcibly enabled on x86, we could disable it through disabling CONFIG_DOMCTL in the future.
In consequence, a few functions, like the ones defined in hvm/monitor.h, needs stub to pass compilation when CONFIG_VM_EVENT=n. Remove the CONFIG_VM_EVENT wrapper for "#include <asm/mem_access.h>", as we need declaration there to pass compilation when CONFIG_VM_EVENT=n

The following functions are developed on the basis of vm event framework, or only invoked by vm_event.c/monitor.c/mem_access.c, so they all shall be wrapped with CONFIG_VM_EVENT:
- hvm_toggle_singlestep
- hvm_fast_singlestep
- p2m_mem_paging_drop_page
- p2m_mem_paging_populate_page
- p2m_mem_paging_resume
- hvm_enable_msr_interception
- hvm_function_table.enable_msr_interception
- hvm_has_set_descriptor_access_existing
- hvm_function_table.set_descriptor_access_existing
- xsm_vm_event_control

---
 xen/arch/ppc/stubs.c                    |  2 +
 xen/arch/x86/Makefile                   |  2 +-
 xen/arch/x86/hvm/Makefile               |  4 +-
 xen/arch/x86/hvm/hvm.c                  |  2 +
 xen/arch/x86/hvm/svm/svm.c              |  8 +++
 xen/arch/x86/hvm/vmx/vmx.c              | 10 ++++
 xen/arch/x86/include/asm/hvm/hvm.h      | 10 ++++
 xen/arch/x86/include/asm/hvm/monitor.h  | 65 ++++++++++++++++++++++++-
 xen/arch/x86/include/asm/hvm/vm_event.h |  4 ++
 xen/arch/x86/include/asm/mem_access.h   |  9 ++++
 xen/arch/x86/include/asm/monitor.h      | 15 ++++++
 xen/arch/x86/include/asm/p2m.h          |  6 +++
 xen/arch/x86/mm/mem_paging.c            |  2 +
 xen/include/xen/mem_access.h            | 36 ++++++++++++--
 xen/include/xen/monitor.h               |  8 ++-
 xen/include/xen/vm_event.h              | 24 ++++++++-
 xen/include/xsm/xsm.h                   |  4 +-
 xen/xsm/dummy.c                         |  2 +-
 xen/xsm/flask/hooks.c                   |  4 +-
 19 files changed, 200 insertions(+), 17 deletions(-)
xen/arch/ppc/stubs.c +2 -0
index 671e71aa0a..4679cf9360 100644
@@ -60,6 +60,7 @@ void vcpu_show_execution_state(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_VM_EVENT
 /* vm_event.c */
 
 void vm_event_fill_regs(vm_event_request_t *req)
@@ -76,6 +77,7 @@ void vm_event_monitor_next_interrupt(struct vcpu *v)
 {
     /* Not supported on PPC. */
 }
+#endif /* CONFIG_VM_EVENT */
 
 /* domctl.c */
 void arch_get_domain_info(const struct domain *d,
xen/arch/x86/Makefile +1 -1
index 7676d7cdd8..17f0e1dbc9 100644
@@ -76,7 +76,7 @@ obj-y += usercopy.o
 obj-y += x86_emulate.o
 obj-$(CONFIG_TBOOT) += tboot.o
 obj-y += hpet.o
-obj-y += vm_event.o
+obj-$(CONFIG_VM_EVENT) += vm_event.o
 obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
xen/arch/x86/hvm/Makefile +2 -2
index 6ec2c8f2db..952db00dd7 100644
@@ -16,7 +16,7 @@ obj-y += io.o
 obj-y += ioreq.o
 obj-y += irq.o
 obj-y += mmio.o
-obj-y += monitor.o
+obj-$(CONFIG_VM_EVENT) += monitor.o
 obj-y += mtrr.o
 obj-y += nestedhvm.o
 obj-y += pmtimer.o
@@ -26,7 +26,7 @@ obj-y += save.o
 obj-y += stdvga.o
 obj-y += vioapic.o
 obj-y += vlapic.o
-obj-y += vm_event.o
+obj-$(CONFIG_VM_EVENT) += vm_event.o
 obj-y += vmsi.o
 obj-y += vpic.o
 obj-y += vpt.o
xen/arch/x86/hvm/hvm.c +2 -0
index ea97815deb..f464f401aa 100644
@@ -5251,6 +5251,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op)
     return rc;
 }
 
+#ifdef CONFIG_VM_EVENT
 void hvm_toggle_singlestep(struct vcpu *v)
 {
     ASSERT(atomic_read(&v->pause_count));
@@ -5275,6 +5276,7 @@ void hvm_fast_singlestep(struct vcpu *v, uint16_t p2midx)
     v->arch.hvm.fast_single_step.enabled = true;
     v->arch.hvm.fast_single_step.p2midx = p2midx;
 }
+#endif /* CONFIG_VM_EVENT */
 
 /*
  * Segment caches in VMCB/VMCS are inconsistent about which bits are checked,
xen/arch/x86/hvm/svm/svm.c +8 -0
index fce750ca1f..d71f499986 100644
@@ -297,6 +297,7 @@ void svm_intercept_msr(struct vcpu *v, uint32_t msr, int flags)
         __clear_bit(msr * 2 + 1, msr_bit);
 }
 
+#ifdef CONFIG_VM_EVENT
 static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr)
 {
     struct vcpu *v;
@@ -304,6 +305,7 @@ static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr)
     for_each_vcpu ( d, v )
         svm_intercept_msr(v, msr, MSR_INTERCEPT_WRITE);
 }
+#endif /* CONFIG_VM_EVENT */
 
 static void svm_save_dr(struct vcpu *v)
 {
@@ -824,6 +826,7 @@ static void cf_check svm_set_rdtsc_exiting(struct vcpu *v, bool enable)
     vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
+#ifdef CONFIG_VM_EVENT
 static void cf_check svm_set_descriptor_access_exiting(
     struct vcpu *v, bool enable)
 {
@@ -841,6 +844,7 @@ static void cf_check svm_set_descriptor_access_exiting(
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
 }
+#endif /* CONFIG_VM_EVENT */
 
 static unsigned int cf_check svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
 {
@@ -2455,9 +2459,13 @@ static struct hvm_function_table __initdata_cf_clobber svm_function_table = {
     .fpu_dirty_intercept  = svm_fpu_dirty_intercept,
     .msr_read_intercept   = svm_msr_read_intercept,
     .msr_write_intercept  = svm_msr_write_intercept,
+#ifdef CONFIG_VM_EVENT
     .enable_msr_interception = svm_enable_msr_interception,
+#endif
     .set_rdtsc_exiting    = svm_set_rdtsc_exiting,
+#ifdef CONFIG_VM_EVENT
     .set_descriptor_access_exiting = svm_set_descriptor_access_exiting,
+#endif
     .get_insn_bytes       = svm_get_insn_bytes,
 
     .nhvm_vcpu_initialise = nsvm_vcpu_initialise,
xen/arch/x86/hvm/vmx/vmx.c +10 -0
index cb82d52ef0..9e4ad864fa 100644
@@ -1515,6 +1515,7 @@ static void cf_check vmx_set_rdtsc_exiting(struct vcpu *v, bool enable)
     vmx_vmcs_exit(v);
 }
 
+#ifdef CONFIG_VM_EVENT
 static void cf_check vmx_set_descriptor_access_exiting(
     struct vcpu *v, bool enable)
 {
@@ -1529,6 +1530,7 @@ static void cf_check vmx_set_descriptor_access_exiting(
     vmx_update_secondary_exec_control(v);
     vmx_vmcs_exit(v);
 }
+#endif /* CONFIG_VM_EVENT */
 
 static void cf_check vmx_init_hypercall_page(void *p)
 {
@@ -2408,6 +2410,7 @@ static void cf_check vmx_handle_eoi(uint8_t vector, int isr)
         printk_once(XENLOG_WARNING "EOI for %02x but SVI=%02x\n", vector, old_svi);
 }
 
+#ifdef CONFIG_VM_EVENT
 static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t msr)
 {
     struct vcpu *v;
@@ -2415,6 +2418,7 @@ static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t msr)
     for_each_vcpu ( d, v )
         vmx_set_msr_intercept(v, msr, VMX_MSR_W);
 }
+#endif /* CONFIG_VM_EVENT */
 
 static void cf_check vmx_vcpu_update_eptp(struct vcpu *v)
 {
@@ -2862,7 +2866,9 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = {
     .nhvm_domain_relinquish_resources = nvmx_domain_relinquish_resources,
     .update_vlapic_mode = vmx_vlapic_msr_changed,
     .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m,
+#ifdef CONFIG_VM_EVENT
     .enable_msr_interception = vmx_enable_msr_interception,
+#endif
     .altp2m_vcpu_update_p2m = vmx_vcpu_update_eptp,
     .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve,
     .altp2m_vcpu_emulate_ve = vmx_vcpu_emulate_ve,
@@ -3068,9 +3074,11 @@ const struct hvm_function_table * __init start_vmx(void)
 
     vmx_function_table.caps.singlestep = cpu_has_monitor_trap_flag;
 
+#ifdef CONFIG_VM_EVENT
     if ( cpu_has_vmx_dt_exiting )
         vmx_function_table.set_descriptor_access_exiting =
             vmx_set_descriptor_access_exiting;
+#endif
 
     /*
      * Do not enable EPT when (!cpu_has_vmx_pat), to prevent security hole
@@ -3141,8 +3149,10 @@ void __init vmx_fill_funcs(void)
     if ( !cpu_has_xen_ibt )
         return;
 
+#ifdef CONFIG_VM_EVENT
     vmx_function_table.set_descriptor_access_exiting =
         vmx_set_descriptor_access_exiting;
+#endif
 
     vmx_function_table.update_eoi_exit_bitmap = vmx_update_eoi_exit_bitmap;
     vmx_function_table.process_isr            = vmx_process_isr;
xen/arch/x86/include/asm/hvm/hvm.h +10 -0
index bf8bc2e100..bd53fcf155 100644
@@ -191,7 +191,9 @@ struct hvm_function_table {
     void (*handle_cd)(struct vcpu *v, unsigned long value);
     void (*set_info_guest)(struct vcpu *v);
     void (*set_rdtsc_exiting)(struct vcpu *v, bool enable);
+#ifdef CONFIG_VM_EVENT
     void (*set_descriptor_access_exiting)(struct vcpu *v, bool enable);
+#endif
 
     /* Nested HVM */
     int (*nhvm_vcpu_initialise)(struct vcpu *v);
@@ -223,7 +225,9 @@ struct hvm_function_table {
                                 paddr_t *L1_gpa, unsigned int *page_order,
                                 uint8_t *p2m_acc, struct npfec npfec);
 
+#ifdef CONFIG_VM_EVENT
     void (*enable_msr_interception)(struct domain *d, uint32_t msr);
+#endif
 
     /* Alternate p2m */
     void (*altp2m_vcpu_update_p2m)(struct vcpu *v);
@@ -430,10 +434,12 @@ static inline bool using_svm(void)
 
 #define hvm_long_mode_active(v) (!!((v)->arch.hvm.guest_efer & EFER_LMA))
 
+#ifdef CONFIG_VM_EVENT
 static inline bool hvm_has_set_descriptor_access_exiting(void)
 {
     return hvm_funcs.set_descriptor_access_exiting;
 }
+#endif /* CONFIG_VM_EVENT */
 
 static inline void hvm_domain_creation_finished(struct domain *d)
 {
@@ -680,10 +686,12 @@ static inline int nhvm_hap_walk_L1_p2m(
         v, L2_gpa, L1_gpa, page_order, p2m_acc, npfec);
 }
 
+#ifdef CONFIG_VM_EVENT
 static inline void hvm_enable_msr_interception(struct domain *d, uint32_t msr)
 {
     alternative_vcall(hvm_funcs.enable_msr_interception, d, msr);
 }
+#endif /* CONFIG_VM_EVENT */
 
 static inline bool hvm_is_singlestep_supported(void)
 {
@@ -923,10 +931,12 @@ static inline void hvm_inject_hw_exception(unsigned int vector, int errcode)
     ASSERT_UNREACHABLE();
 }
 
+#ifdef CONFIG_VM_EVENT
 static inline bool hvm_has_set_descriptor_access_exiting(void)
 {
     return false;
 }
+#endif /* CONFIG_VM_EVENT */
 
 static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool reset)
 {
xen/arch/x86/include/asm/hvm/monitor.h +63 -2

83 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/vm_event.h +4 -0
index 506a85c774..1628230182 100644
@@ -8,7 +8,11 @@
 #ifndef __ASM_X86_HVM_VM_EVENT_H__
 #define __ASM_X86_HVM_VM_EVENT_H__
 
+#ifdef CONFIG_VM_EVENT
 void hvm_vm_event_do_resume(struct vcpu *v);
+#else
+static inline void hvm_vm_event_do_resume(struct vcpu *v) {}
+#endif /* CONFIG_VM_EVENT */
 
 #endif /* __ASM_X86_HVM_VM_EVENT_H__ */
 
xen/arch/x86/include/asm/mem_access.h +9 -0
index 1a52a10322..c786116310 100644
@@ -14,6 +14,7 @@
 #ifndef __ASM_X86_MEM_ACCESS_H__
 #define __ASM_X86_MEM_ACCESS_H__
 
+#ifdef CONFIG_VM_EVENT
 /*
  * Setup vm_event request based on the access (gla is -1ull if not available).
  * Handles the rw2rx conversion. Boolean return value indicates if event type
@@ -25,6 +26,14 @@
 bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
                           struct npfec npfec,
                           struct vm_event_st **req_ptr);
+#else
+static inline bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
+                                        struct npfec npfec,
+                                        struct vm_event_st **req_ptr)
+{
+    return false;
+}
+#endif /* CONFIG_VM_EVENT */
 
 /* Check for emulation and mark vcpu for skipping one instruction
  * upon rescheduling if required. */
xen/arch/x86/include/asm/monitor.h +15 -0
index 3c64d8258f..815de8fda2 100644
@@ -71,6 +71,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
     return rc;
 }
 
+#ifdef CONFIG_VM_EVENT
 static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
 {
     uint32_t capabilities = 0;
@@ -102,6 +103,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
 
     return capabilities;
 }
+#else
+static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
+{
+    ASSERT_UNREACHABLE();
+    return 0;
+}
+#endif /* CONFIG_VM_EVENT */
 
 int arch_monitor_domctl_event(struct domain *d,
                               struct xen_domctl_monitor_op *mop);
@@ -123,7 +131,14 @@ static inline void arch_monitor_cleanup_domain(struct domain *d) {}
 
 #endif
 
+#ifdef CONFIG_VM_EVENT
 bool monitored_msr(const struct domain *d, u32 msr);
+#else
+static inline bool monitored_msr(const struct domain *d, u32 msr)
+{
+    return false;
+}
+#endif
 bool monitored_msr_onchangeonly(const struct domain *d, u32 msr);
 
 #endif /* __ASM_X86_MONITOR_H__ */
xen/arch/x86/include/asm/p2m.h +6 -0
index 58b56e575e..9c92f67443 100644
@@ -775,10 +775,16 @@ static inline int relinquish_p2m_mapping(struct domain *d)
 /* Modify p2m table for shared gfn */
 int set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 
+#ifdef CONFIG_VM_EVENT
 /* Tell xenpaging to drop a paged out frame */
 void p2m_mem_paging_drop_page(struct domain *d, gfn_t gfn, p2m_type_t p2mt);
 /* Start populating a paged out frame */
 void p2m_mem_paging_populate(struct domain *d, gfn_t gfn);
+#else
+static inline void p2m_mem_paging_drop_page(struct domain *d, gfn_t gfn,
+                                            p2m_type_t p2mt) {}
+static inline void p2m_mem_paging_populate(struct domain *d, gfn_t gfn) {}
+#endif /* CONFIG_VM_EVENT */
 /* Resume normal operation (in case a domain was paused) */
 struct vm_event_st;
 void p2m_mem_paging_resume(struct domain *d, struct vm_event_st *rsp);
xen/arch/x86/mm/mem_paging.c +2 -0
index ac8d34ffa0..636c0533b3 100644
@@ -15,6 +15,7 @@
 
 #include "mm-locks.h"
 
+#ifdef CONFIG_VM_EVENT
 /*
  * p2m_mem_paging_drop_page - Tell pager to drop its reference to a paged page
  * @d: guest domain
@@ -186,6 +187,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp)
         gfn_unlock(p2m, gfn, 0);
     }
 }
+#endif /* CONFIG_VM_EVENT */
 
 /*
  * nominate - Mark a guest page as to-be-paged-out
xen/include/xen/mem_access.h +33 -3
index 4de651038d..e9aaa7b321 100644
@@ -33,9 +33,7 @@
  */
 struct vm_event_st;
 
-#ifdef CONFIG_VM_EVENT
 #include <asm/mem_access.h>
-#endif
 
 /*
  * Additional access types, which are used to further restrict
@@ -73,6 +71,7 @@ typedef enum {
     /* NOTE: Assumed to be only 4 bits right now on x86. */
 } p2m_access_t;
 
+#ifdef CONFIG_VM_EVENT
 struct p2m_domain;
 bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m,
                                  xenmem_access_t xaccess,
@@ -99,10 +98,41 @@ long p2m_set_mem_access_multi(struct domain *d,
 int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access,
                        unsigned int altp2m_idx);
 
-#ifdef CONFIG_VM_EVENT
 int mem_access_memop(unsigned long cmd,
                      XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg);
 #else
+struct p2m_domain;
+static inline bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m,
+                                               xenmem_access_t xaccess,
+                                               p2m_access_t *paccess)
+{
+    return false;
+}
+
+static inline long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
+                                      uint32_t start, uint32_t mask,
+                                      xenmem_access_t access,
+                                      unsigned int altp2m_idx)
+{
+    return -EOPNOTSUPP;
+}
+
+static inline long p2m_set_mem_access_multi(struct domain *d,
+                            const XEN_GUEST_HANDLE(const_uint64) pfn_list,
+                            const XEN_GUEST_HANDLE(const_uint8) access_list,
+                            uint32_t nr, uint32_t start, uint32_t mask,
+                            unsigned int altp2m_idx)
+{
+    return -EOPNOTSUPP;
+}
+
+static inline int p2m_get_mem_access(struct domain *d, gfn_t gfn,
+                                     xenmem_access_t *access,
+                                     unsigned int altp2m_idx)
+{
+    return -EOPNOTSUPP;
+}
+
 static inline
 int mem_access_memop(unsigned long cmd,
                      XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg)
xen/include/xen/monitor.h +6 -2
index c086c4390c..1b7984909e 100644
@@ -30,6 +30,7 @@ struct xen_domctl_monitor_op;
 #ifdef CONFIG_VM_EVENT
 int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop);
 void monitor_guest_request(void);
+int monitor_traps(struct vcpu *v, bool sync, vm_event_request_t *req);
 #else /* !CONFIG_VM_EVENT */
 static inline int monitor_domctl(struct domain *d,
                                  struct xen_domctl_monitor_op *mop)
@@ -37,8 +38,11 @@ static inline int monitor_domctl(struct domain *d,
     return -EOPNOTSUPP;
 }
 static inline void monitor_guest_request(void) {}
+static inline int monitor_traps(struct vcpu *v, bool sync,
+                                vm_event_request_t *req)
+{
+    return -EOPNOTSUPP;
+}
 #endif /* !CONFIG_VM_EVENT */
 
-int monitor_traps(struct vcpu *v, bool sync, vm_event_request_t *req);
-
 #endif /* __XEN_MONITOR_H__ */
xen/include/xen/vm_event.h +22 -2
index 27d0c74216..4b3d0d15ec 100644
@@ -50,6 +50,7 @@ struct vm_event_domain
     unsigned int last_vcpu_wake_up;
 };
 
+#ifdef CONFIG_VM_EVENT
 /* Returns whether a ring has been set up */
 bool vm_event_check_ring(struct vm_event_domain *ved);
 
@@ -68,6 +69,20 @@ bool vm_event_check_ring(struct vm_event_domain *ved);
  */
 int __vm_event_claim_slot(struct domain *d, struct vm_event_domain *ved,
                           bool allow_sleep);
+#else
+static inline bool vm_event_check_ring(struct vm_event_domain *ved)
+{
+    return false;
+}
+
+static inline int __vm_event_claim_slot(struct domain *d,
+                                        struct vm_event_domain *ved,
+                                        bool allow_sleep)
+{
+    return -EOPNOTSUPP;
+}
+#endif /* CONFIG_VM_EVENT */
+
 static inline int vm_event_claim_slot(struct domain *d,
                                       struct vm_event_domain *ved)
 {
@@ -82,23 +97,28 @@ static inline int vm_event_claim_slot_nosleep(struct domain *d,
 
 void vm_event_cancel_slot(struct domain *d, struct vm_event_domain *ved);
 
+#ifdef CONFIG_VM_EVENT
 void vm_event_put_request(struct domain *d, struct vm_event_domain *ved,
                           vm_event_request_t *req);
 
-#ifdef CONFIG_VM_EVENT
 /* Clean up on domain destruction */
 void vm_event_cleanup(struct domain *d);
 int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec);
+
+void vm_event_vcpu_pause(struct vcpu *v);
 #else /* !CONFIG_VM_EVENT */
+static inline void vm_event_put_request(struct domain *d,
+                                        struct vm_event_domain *ved,
+                                        vm_event_request_t *req) {}
 static inline void vm_event_cleanup(struct domain *d) {}
 static inline int vm_event_domctl(struct domain *d,
                                   struct xen_domctl_vm_event_op *vec)
 {
     return -EOPNOTSUPP;
 }
+static inline void vm_event_vcpu_pause(struct vcpu *v) {};
 #endif /* !CONFIG_VM_EVENT */
 
-void vm_event_vcpu_pause(struct vcpu *v);
 void vm_event_vcpu_unpause(struct vcpu *v);
 
 void vm_event_fill_regs(vm_event_request_t *req);
xen/include/xsm/xsm.h +2 -2
index dad69905c9..7c61f27366 100644
@@ -155,9 +155,9 @@ struct xsm_ops {
     int (*hvm_altp2mhvm_op)(struct domain *d, uint64_t mode, uint32_t op);
     int (*get_vnumainfo)(struct domain *d);
 
+#ifdef CONFIG_VM_EVENT
     int (*vm_event_control)(struct domain *d, int mode, int op);
 
-#ifdef CONFIG_VM_EVENT
     int (*mem_access)(struct domain *d);
 #endif
 
@@ -651,13 +651,13 @@ static inline int xsm_get_vnumainfo(xsm_default_t def, struct domain *d)
     return alternative_call(xsm_ops.get_vnumainfo, d);
 }
 
+#ifdef CONFIG_VM_EVENT
 static inline int xsm_vm_event_control(
     xsm_default_t def, struct domain *d, int mode, int op)
 {
     return alternative_call(xsm_ops.vm_event_control, d, mode, op);
 }
 
-#ifdef CONFIG_VM_EVENT
 static inline int xsm_mem_access(xsm_default_t def, struct domain *d)
 {
     return alternative_call(xsm_ops.mem_access, d);
xen/xsm/dummy.c +1 -1
index 8a893c6eee..6f8b06b45f 100644
@@ -115,9 +115,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .remove_from_physmap           = xsm_remove_from_physmap,
     .map_gmfn_foreign              = xsm_map_gmfn_foreign,
 
+#ifdef CONFIG_VM_EVENT
     .vm_event_control              = xsm_vm_event_control,
 
-#ifdef CONFIG_VM_EVENT
     .mem_access                    = xsm_mem_access,
 #endif
 
xen/xsm/flask/hooks.c +2 -2
index 0382182f94..fd7aea460f 100644
@@ -1365,12 +1365,12 @@ static int cf_check flask_hvm_altp2mhvm_op(struct domain *d, uint64_t mode, uint
     return current_has_perm(d, SECCLASS_HVM, HVM__ALTP2MHVM_OP);
 }
 
+#ifdef CONFIG_VM_EVENT
 static int cf_check flask_vm_event_control(struct domain *d, int mode, int op)
 {
     return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__VM_EVENT);
 }
 
-#ifdef CONFIG_VM_EVENT
 static int cf_check flask_mem_access(struct domain *d)
 {
     return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__MEM_ACCESS);
@@ -1969,9 +1969,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .do_xsm_op = do_flask_op,
     .get_vnumainfo = flask_get_vnumainfo,
 
+#ifdef CONFIG_VM_EVENT
     .vm_event_control = flask_vm_event_control,
 
-#ifdef CONFIG_VM_EVENT
     .mem_access = flask_mem_access,
 #endif
 
Signature · 1 line
2.34.1
#14 lore raw

Re: [PATCH v1 04/25] xen: consolidate CONFIG_VM_EVENT

Quoted 41 lines · Penny Zheng

File hvm/vm_event.c and x86/vm_event.c are the extend to vm_event handling routines, and its compilation shall be guarded by CONFIG_VM_EVENT too. Futhermore, features about monitor_op and memory access are both based on vm event subsystem, so monitor.o/mem_access.o shall be wrapped under CONFIG_VM_EVENT.

Although CONFIG_VM_EVENT is forcibly enabled on x86, we could disable it through disabling CONFIG_DOMCTL in the future.
In consequence, a few functions, like the ones defined in hvm/monitor.h, needs stub to pass compilation when CONFIG_VM_EVENT=n. Remove the CONFIG_VM_EVENT wrapper for "#include <asm/mem_access.h>", as we need declaration there to pass compilation when CONFIG_VM_EVENT=n

The following functions are developed on the basis of vm event framework, or only invoked by vm_event.c/monitor.c/mem_access.c, so they all shall be wrapped with CONFIG_VM_EVENT:
- hvm_toggle_singlestep
- hvm_fast_singlestep
- p2m_mem_paging_drop_page
- p2m_mem_paging_populate_page
- p2m_mem_paging_resume
- hvm_enable_msr_interception
- hvm_function_table.enable_msr_interception
- hvm_has_set_descriptor_access_existing
- hvm_function_table.set_descriptor_access_existing
- xsm_vm_event_control

---
 xen/arch/ppc/stubs.c                    |  2 +
 xen/arch/x86/Makefile                   |  2 +-
 xen/arch/x86/hvm/Makefile               |  4 +-
 xen/arch/x86/hvm/hvm.c                  |  2 +
 xen/arch/x86/hvm/svm/svm.c              |  8 +++
 xen/arch/x86/hvm/vmx/vmx.c              | 10 ++++
 xen/arch/x86/include/asm/hvm/hvm.h      | 10 ++++
 xen/arch/x86/include/asm/hvm/monitor.h  | 65 ++++++++++++++++++++++++-
 xen/arch/x86/include/asm/hvm/vm_event.h |  4 ++
 xen/arch/x86/include/asm/mem_access.h   |  9 ++++
 xen/arch/x86/include/asm/monitor.h      | 15 ++++++
 xen/arch/x86/include/asm/p2m.h          |  6 +++
Quoted 8 lines
 xen/arch/x86/mm/mem_paging.c            |  2 +
 xen/include/xen/mem_access.h            | 36 ++++++++++++--
 xen/include/xen/monitor.h               |  8 ++-
 xen/include/xen/vm_event.h              | 24 ++++++++-
 xen/include/xsm/xsm.h                   |  4 +-
 xen/xsm/dummy.c                         |  2 +-
 xen/xsm/flask/hooks.c                   |  4 +-
 19 files changed, 200 insertions(+), 17 deletions(-)

Overall it looks like the patch could be split some. E.g. the XSM changes look as if they could go separately.

Quoted 11 lines
xen/arch/ppc/stubs.c +1 -0
@@ -60,6 +60,7 @@ void vcpu_show_execution_state(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_VM_EVENT
 /* vm_event.c */
 
 void vm_event_fill_regs(vm_event_request_t *req)

xen/arch/ppc/stubs.c void vm_event_monitor_next_interrupt(struct vcpu *v) · line 80

Quoted 4 lines
xen/arch/ppc/stubs.c +1 -0
@@ -76,6 +77,7 @@ void vm_event_monitor_next_interrupt(struct vcpu *v)
 {
     /* Not supported on PPC. */
 }
+#endif /* CONFIG_VM_EVENT */

Is this really needed? I wouldn't bother editing stubs.c files unless really necessary.

Quoted 11 lines
xen/arch/x86/include/asm/monitor.h +1 -0
@@ -71,6 +71,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
     return rc;
 }
 
+#ifdef CONFIG_VM_EVENT
 static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
 {
     uint32_t capabilities = 0;

xen/arch/x86/include/asm/monitor.h static inline uint32_t arch_monitor_get_capabilities(struct domain *d) · line 111

Quoted 9 lines
xen/arch/x86/include/asm/monitor.h +6 -0
@@ -102,6 +103,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
 
     return capabilities;
 }
+#else
+static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
+{
+    ASSERT_UNREACHABLE();
+    return 0;
+}

Instead of this, a mere declaration (with no definition) would make a possible problem known at build time, rather than only at runtime.

Quoted 4 lines
xen/arch/x86/include/asm/p2m.h +0 -0
@@ -775,10 +775,16 @@ static inline int relinquish_p2m_mapping(struct domain *d)
 /* Modify p2m table for shared gfn */

xen/arch/x86/include/asm/p2m.h static inline int relinquish_p2m_mapping(struct domain *d) · line 785

Quoted 10 lines
xen/arch/x86/include/asm/p2m.h +4 -0
 int set_shared_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 
+#ifdef CONFIG_VM_EVENT
 /* Tell xenpaging to drop a paged out frame */
 void p2m_mem_paging_drop_page(struct domain *d, gfn_t gfn, p2m_type_t p2mt);
 /* Start populating a paged out frame */
 void p2m_mem_paging_populate(struct domain *d, gfn_t gfn);
+#else
+static inline void p2m_mem_paging_drop_page(struct domain *d, gfn_t gfn,
+                                            p2m_type_t p2mt) {}

This, I think, isn't needed. p2m_is_paging() is already short-circuited into 0 / false when MEM_PAGING=n (implying VM_EVENT=n in your supposed future configuration, so the call site is being DCE-ed, and hence the declaration that was already there will suffice.

Quoted 11 lines
xen/arch/x86/mm/mem_paging.c +1 -0
@@ -15,6 +15,7 @@
 
 #include "mm-locks.h"
 
+#ifdef CONFIG_VM_EVENT
 /*
  * p2m_mem_paging_drop_page - Tell pager to drop its reference to a paged page
  * @d: guest domain

xen/arch/x86/mm/mem_paging.c void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp) · line 190

Quoted 4 lines
xen/arch/x86/mm/mem_paging.c +1 -0
@@ -186,6 +187,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp)
         gfn_unlock(p2m, gfn, 0);
     }
 }
+#endif /* CONFIG_VM_EVENT */

As per the previous remark: Why would this be needed? We already have

obj-$(CONFIG_MEM_PAGING) += mem_paging.o

in the corresponding Makefile.

xen/include/xen/mem_access.h line 38

Quoted 9 lines
xen/include/xen/mem_access.h +0 -2
@@ -33,9 +33,7 @@
  */
 struct vm_event_st;
 
-#ifdef CONFIG_VM_EVENT
 #include <asm/mem_access.h>
-#endif

Why?

Quoted 9 lines
xen/include/xen/mem_access.h +1 -0
@@ -73,6 +71,7 @@ typedef enum {
     /* NOTE: Assumed to be only 4 bits right now on x86. */
 } p2m_access_t;
 
+#ifdef CONFIG_VM_EVENT
 struct p2m_domain;
 bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m,
                                  xenmem_access_t xaccess,

xen/include/xen/mem_access.h long p2m_set_mem_access_multi(struct domain *d, · line 104

Quoted 8 lines
xen/include/xen/mem_access.h +1 -1
@@ -99,10 +98,41 @@ long p2m_set_mem_access_multi(struct domain *d,
 int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access,
                        unsigned int altp2m_idx);
 
-#ifdef CONFIG_VM_EVENT
 int mem_access_memop(unsigned long cmd,
                      XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg);
 #else
+struct p2m_domain;

No point in duplicating this; just move it ahead of the #ifdef.

Jan

#15 lore raw

PATCH 5/25 xen: introduce CONFIG_DOMCTL

In reply to Penny Zheng

We introduce a new Kconfig CONFIG_DOMCTL, which shall only be disabled on some dom0less systems or PV shim on x86, to reduce Xen footprint.

Making DOMCTL without prompt is transient and it will be adjusted in the final patch. And the consequence of introducing "CONFIG_DOMCTL=y" in .config file generated from pvshim_defconfig is transient too, which will also be adjusted in the final patch.

---
 xen/common/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
xen/common/Kconfig +4 -0
index 16936418a6..bf1850c154 100644
@@ -627,6 +627,10 @@ config SYSCTL
 	  This option shall only be disabled on some dom0less systems, or
 	  PV shim on x86, to reduce Xen footprint.
 
+config DOMCTL
+	bool "Enable domctl hypercall"
+	def_bool y
+
 endmenu
 
 config PM_OP
Signature · 1 line
2.34.1
#16 lore raw

Re: [PATCH v1 05/25] xen: introduce CONFIG_DOMCTL

xen/common/Kconfig config SYSCTL · line 633

Quoted 10 lines · Penny Zheng
xen/common/Kconfig +4 -0
@@ -627,6 +627,10 @@ config SYSCTL
 	  This option shall only be disabled on some dom0less systems, or
 	  PV shim on x86, to reduce Xen footprint.
 
+config DOMCTL
+	bool "Enable domctl hypercall"
+	def_bool y
+

Just to re-iterate - we don't think we want things to be this fine-grained. (As an aside, nit: "bool" and "def_bool" are partly redundant with one another.)

Jan

#17 lore raw

RE: [PATCH v1 05/25] xen: introduce CONFIG_DOMCTL

[Public]

Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:41 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v1 05/25] xen: introduce CONFIG_DOMCTL

Quoted 6 lines · Penny Zheng
xen/common/Kconfig +0 -0
@@ -627,6 +627,10 @@ config SYSCTL
      This option shall only be disabled on some dom0less systems, or
      PV shim on x86, to reduce Xen footprint.
 
Quoted 9 lines

xen/common/Kconfig config SYSCTL · line 633

Quoted 4 lines
xen/common/Kconfig +4 -0
+config DOMCTL
+   bool "Enable domctl hypercall"
+   def_bool y
+

Just to re-iterate - we don't think we want things to be this fine-grained. (As an aside, nit: "bool" and "def_bool" are partly redundant with one another.)

Are we suggesting to use one Kconfig, maybe like CONFIG_XENCTL(not a good choice, just popping in my head...), to wrap all scenarios, including sysctl-op, domctl-op, jiqian's platform-op, etc ? In which case, maybe we still submit commits(or features) serie by serie, more easy to review, but only when all is completed, we make this Kconfig as an selectable option ?

Quoted 1 line

Jan

#18 lore raw

Re: [PATCH v1 05/25] xen: introduce CONFIG_DOMCTL

Quoted 30 lines · Zheng

[Public]

Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 3:41 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v1 05/25] xen: introduce CONFIG_DOMCTL

Quoted 6 lines · Penny Zheng
xen/common/Kconfig +0 -0
@@ -627,6 +627,10 @@ config SYSCTL
      This option shall only be disabled on some dom0less systems, or
      PV shim on x86, to reduce Xen footprint.
 
Quoted 9 lines

xen/common/Kconfig config SYSCTL · line 633

Quoted 4 lines
xen/common/Kconfig +4 -0
+config DOMCTL
+   bool "Enable domctl hypercall"
+   def_bool y
+

Just to re-iterate - we don't think we want things to be this fine-grained. (As an aside, nit: "bool" and "def_bool" are partly redundant with one another.)

Quoted 1 line

Are we suggesting to use one Kconfig, maybe like CONFIG_XENCTL(not a good choice, just popping in my head...), to wrap all scenarios, including sysctl-op, domctl-op, jiqian's platform-op, etc ?

Yes, that's the thought that was circulated, and that I had hoped Stefano would have conveyed.

Quoted 1 line

In which case, maybe we still submit commits(or features) serie by serie, more easy to review, but only when all is completed, we make this Kconfig as an selectable option ?

Likely the best route, but that may then mean stepping back a little on SYSCTL, before trying to deal with SYSCTL and maybe PLATFORM_OP (albeit I raised further reservations there).

Jan

#19 lore raw

PATCH 6/25 xen/domctl: provide stub for domctl_lock_{acquire,release}

In reply to Penny Zheng

With DOMCTL=n, we need to provide stub for domctl_lock_{acquire,release}(), as it may be invoked by hvm_set_param() in x86 PV shim mode. Although PV_SHIM_EXCLUSIVE and HVM shall not be both enabled, randconfig stands little chance to make it happen.

---
 xen/include/xen/domain.h | 9 +++++++++
 1 file changed, 9 insertions(+)
xen/include/xen/domain.h +9 -0
index 33dd90357c..b45ac91760 100644
@@ -148,8 +148,17 @@ void arch_dump_domain_info(struct domain *d);
 
 int arch_vcpu_reset(struct vcpu *v);
 
+#ifdef CONFIG_DOMCTL
 bool domctl_lock_acquire(void);
 void domctl_lock_release(void);
+#else
+static inline bool domctl_lock_acquire(void)
+{
+    return false;
+}
+
+static inline void domctl_lock_release(void) {}
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Continue the current hypercall via func(data) on specified cpu.
Signature · 1 line
2.34.1
#20 lore raw

PATCH 7/25 xen/domctl: wrap around XEN_DOMCTL_pausedomain

In reply to Penny Zheng

Function domain_pause_by_systemcontroller() is responsible for XEN_DOMCTL_pausedomain domctl-op, and shall be wrapped around with CONFIG_DOMCTL

---
 xen/common/domain.c | 2 ++
 1 file changed, 2 insertions(+)
xen/common/domain.c +2 -0
index 5241a1629e..e20fe2d40d 100644
@@ -1598,10 +1598,12 @@ static int _domain_pause_by_systemcontroller(struct domain *d, bool sync)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 int domain_pause_by_systemcontroller(struct domain *d)
 {
     return _domain_pause_by_systemcontroller(d, true /* sync */);
 }
+#endif /* CONFIG_DOMCTL */
 
 int domain_pause_by_systemcontroller_nosync(struct domain *d)
 {
Signature · 1 line
2.34.1
#21 lore raw

PATCH 8/25 xen/domctl: wrap around XEN_DOMCTL_soft_reset

In reply to Penny Zheng

Function domain_soft_reset() is responsible for domain soft reset, tracking its calling chain, and the following functions could also be wrapped:
- grant_table_warn_active_grants()
- argo_soft_reset()
- arch_domain_soft_reset()
- domain_resume(), another usage is in XEN_DOMCTL_resumedomain domctl-op.

---
 xen/arch/arm/domain.c    | 2 ++
 xen/arch/ppc/stubs.c     | 2 ++
 xen/arch/riscv/stubs.c   | 2 ++
 xen/arch/x86/domain.c    | 2 ++
 xen/common/argo.c        | 2 ++
 xen/common/domain.c      | 4 ++++
 xen/common/grant_table.c | 2 ++
 7 files changed, 16 insertions(+)
xen/arch/arm/domain.c +2 -0
index 310c578909..4124d201d1 100644
@@ -870,10 +870,12 @@ void arch_domain_unpause(struct domain *d)
 {
 }
 
+#ifdef CONFIG_DOMCTL
 int arch_domain_soft_reset(struct domain *d)
 {
     return -ENOSYS;
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_domain_creation_finished(struct domain *d)
 {
xen/arch/ppc/stubs.c +2 -0
index 4679cf9360..b2b97c6eb7 100644
@@ -236,10 +236,12 @@ void arch_domain_unpause(struct domain *d)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_DOMCTL
 int arch_domain_soft_reset(struct domain *d)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_domain_creation_finished(struct domain *d)
 {
xen/arch/riscv/stubs.c +2 -0
index 8918cebf35..4f817bfe83 100644
@@ -208,10 +208,12 @@ void arch_domain_unpause(struct domain *d)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_DOMCTL
 int arch_domain_soft_reset(struct domain *d)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_domain_creation_finished(struct domain *d)
 {
xen/arch/x86/domain.c +2 -0
index 56c3816187..13ccaf1c79 100644
@@ -1001,6 +1001,7 @@ void arch_domain_unpause(struct domain *d)
         viridian_time_domain_thaw(d);
 }
 
+#ifdef CONFIG_DOMCTL
 int arch_domain_soft_reset(struct domain *d)
 {
     struct page_info *page = virt_to_page(d->shared_info), *new_page;
@@ -1102,6 +1103,7 @@ int arch_domain_soft_reset(struct domain *d)
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_domain_creation_finished(struct domain *d)
 {
xen/common/argo.c +2 -0
index cbe8911a43..932f9fde9b 100644
@@ -2351,6 +2351,7 @@ argo_destroy(struct domain *d)
     write_unlock(&L1_global_argo_rwlock);
 }
 
+#ifdef CONFIG_DOMCTL
 void
 argo_soft_reset(struct domain *d)
 {
@@ -2374,3 +2375,4 @@ argo_soft_reset(struct domain *d)
 
     write_unlock(&L1_global_argo_rwlock);
 }
+#endif /* CONFIG_DOMCTL */
xen/common/domain.c +4 -0
index e20fe2d40d..604217d782 100644
@@ -1343,6 +1343,7 @@ int domain_shutdown(struct domain *d, u8 reason)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 void domain_resume(struct domain *d)
 {
     struct vcpu *v;
@@ -1369,6 +1370,7 @@ void domain_resume(struct domain *d)
 
     domain_unpause(d);
 }
+#endif /* CONFIG_DOMCTL */
 
 int vcpu_start_shutdown_deferral(struct vcpu *v)
 {
@@ -1681,6 +1683,7 @@ void domain_unpause_except_self(struct domain *d)
         domain_unpause(d);
 }
 
+#ifdef CONFIG_DOMCTL
 int domain_soft_reset(struct domain *d, bool resuming)
 {
     struct vcpu *v;
@@ -1718,6 +1721,7 @@ int domain_soft_reset(struct domain *d, bool resuming)
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 int vcpu_reset(struct vcpu *v)
 {
xen/common/grant_table.c +2 -0
index cf131c43a1..bfb199be7f 100644
@@ -3962,6 +3962,7 @@ int gnttab_release_mappings(struct domain *d)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 void grant_table_warn_active_grants(struct domain *d)
 {
     struct grant_table *gt = d->grant_table;
@@ -4006,6 +4007,7 @@ void grant_table_warn_active_grants(struct domain *d)
 
 #undef WARN_GRANT_MAX
 }
+#endif /* CONFIG_DOMCTL */
 
 void
 grant_table_destroy(
Signature · 1 line
2.34.1
#22 lore raw

PATCH 9/25 xen/domctl: wrap around XEN_DOMCTL_destroydomain

In reply to Penny Zheng

Function domain_kill() is responsible for killing domain and relinquish domain-held resources. Tracking its calling chain, the following functions shall also be wrapped:
- domain_relinquish_resource
- pci_release_device
- relinquish_shared_pages
- 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
- vm_event_cleanup

---
 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/x86/domain.c                 | 2 ++
 xen/arch/x86/emul-i8254.c             | 2 ++
 xen/arch/x86/mm/mem_sharing.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/common/vm_event.c                 | 2 ++
 xen/drivers/passthrough/device_tree.c | 2 ++
 xen/drivers/passthrough/pci.c         | 2 ++
 18 files changed, 43 insertions(+)
xen/arch/arm/domain.c +3 -0
index 4124d201d1..e55ff966d2 100644
@@ -990,6 +990,7 @@ int arch_vcpu_reset(struct vcpu *v)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 static int relinquish_memory(struct domain *d, struct page_list_head *list)
 {
     struct page_info *page, *tmp;
@@ -1135,6 +1136,8 @@ int domain_relinquish_resources(struct domain *d)
 
 #undef PROGRESS
 
+#endif /* CONFIG_DOMCTL */
+
 void arch_dump_domain_info(struct domain *d)
 {
     p2m_dump_info(d);
xen/arch/arm/include/asm/tee/tee.h +2 -0
index 0169fd746b..dc08e7e0ba 100644
@@ -40,12 +40,14 @@ struct tee_mediator_ops {
     int (*domain_teardown)(struct domain *d);
     void (*free_domain_ctx)(struct domain *d);
 
+#ifdef CONFIG_DOMCTL
     /*
      * 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..4b13867fa2 100644
@@ -1243,6 +1243,7 @@ static void p2m_invalidate_table(struct p2m_domain *p2m, mfn_t mfn)
     p2m->need_flush = true;
 }
 
+#ifdef CONFIG_DOMCTL
 /*
  * 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_DOMCTL */
 
 /*
  * Invalidate all entries in the root page-tables. This is
@@ -1556,6 +1558,7 @@ int p2m_init(struct domain *d)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 /*
  * 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_DOMCTL */
 
 /*
  * Clean & invalidate RAM associated to the guest vCPU.
xen/arch/arm/mpu/p2m.c +2 -0
index f7fb58ab6a..e8c5665ab9 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_DOMCTL
 int relinquish_p2m_mapping(struct domain *d)
 {
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 void p2m_domain_creation_finished(struct domain *d) {}
 
xen/arch/arm/tee/ffa.c +4 -0
index 3bbdd7168a..bb9b50932c 100644
@@ -434,10 +434,12 @@ static void ffa_free_domain_ctx(struct domain *d)
     XFREE(d->arch.tee);
 }
 
+#ifdef CONFIG_DOMCTL
 static int ffa_relinquish_resources(struct domain *d)
 {
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static void ffa_init_secondary(void)
 {
@@ -559,7 +561,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_DOMCTL
     .relinquish_resources = ffa_relinquish_resources,
+#endif
     .handle_call = ffa_handle_call,
 };
 
xen/arch/arm/tee/optee.c +4 -0
index 5151bd90ed..8d91df4e23 100644
@@ -632,6 +632,7 @@ static void free_optee_shm_buf_pg_list(struct optee_domain *ctx,
                  cookie);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 #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_DOMCTL
     .relinquish_resources = optee_relinquish_resources,
+#endif
     .handle_call = optee_handle_call,
 };
 
xen/arch/arm/tee/tee.c +2 -0
index 3f65e45a78..c97b19cd6f 100644
@@ -60,6 +60,7 @@ int tee_domain_teardown(struct domain *d)
     return cur_mediator->ops->domain_teardown(d);
 }
 
+#ifdef CONFIG_DOMCTL
 int tee_relinquish_resources(struct domain *d)
 {
     if ( !cur_mediator )
@@ -67,6 +68,7 @@ int tee_relinquish_resources(struct domain *d)
 
     return cur_mediator->ops->relinquish_resources(d);
 }
+#endif /* CONFIG_DOMCTL */
 
 uint16_t tee_get_type(void)
 {
xen/arch/ppc/stubs.c +2 -0
index b2b97c6eb7..0d8563f11f 100644
@@ -263,10 +263,12 @@ int arch_vcpu_reset(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
+#ifdef CONFIG_DOMCTL
 int domain_relinquish_resources(struct domain *d)
 {
     BUG_ON("unimplemented");
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_dump_domain_info(struct domain *d)
 {
xen/arch/x86/domain.c +2 -0
index 13ccaf1c79..a0d650cb86 100644
@@ -2235,6 +2235,7 @@ void sync_vcpu_execstate(struct vcpu *v)
            read_atomic(&v->dirty_cpu) != dirty_cpu);
 }
 
+#ifdef CONFIG_DOMCTL
 static int relinquish_memory(
     struct domain *d, struct page_list_head *list, unsigned long type)
 {
@@ -2559,6 +2560,7 @@ int domain_relinquish_resources(struct domain *d)
 
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_dump_domain_info(struct domain *d)
 {
xen/arch/x86/emul-i8254.c +2 -0
index 144aa168a3..bb9718bb97 100644
@@ -651,6 +651,7 @@ void pit_init(struct domain *d)
     pit_reset(d);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/mm/mem_sharing.c +2 -0
index da28266ef0..7858565429 100644
@@ -1391,6 +1391,7 @@ int __mem_sharing_unshare_page(struct domain *d,
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 int relinquish_shared_pages(struct domain *d)
 {
     int rc = 0;
@@ -1447,6 +1448,7 @@ int relinquish_shared_pages(struct domain *d)
     p2m_unlock(p2m);
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int range_share(struct domain *d, struct domain *cd,
                        struct mem_sharing_op_range *range)
xen/arch/x86/mm/p2m-pod.c +2 -0
index 05633fe2ac..98a846bb55 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_DOMCTL
 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_DOMCTL */
 
 int
 p2m_pod_offline_or_broken_hit(struct page_info *p)
xen/arch/x86/mm/p2m.c +2 -0
index b9a7c2dc53..c2840131ad 100644
@@ -2088,6 +2088,7 @@ int xenmem_add_to_physmap_one(
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 /*
  * Remove foreign mappings from the p2m, as that drops the page reference taken
  * when mapped.
@@ -2151,6 +2152,7 @@ int relinquish_p2m_mapping(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/mm/paging.c +2 -0
index 1216a181c3..3da99ad371 100644
@@ -768,6 +768,7 @@ void paging_vcpu_teardown(struct vcpu *v)
         shadow_vcpu_teardown(v);
 }
 
+#ifdef CONFIG_DOMCTL
 /* 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_DOMCTL */
 
 /* 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 604217d782..be722c9f09 100644
@@ -1222,6 +1222,7 @@ int rcu_lock_live_remote_domain_by_id(domid_t dom, struct domain **d)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 int domain_kill(struct domain *d)
 {
     int rc = 0;
@@ -1272,6 +1273,7 @@ int domain_kill(struct domain *d)
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 
 void __domain_crash(struct domain *d)
xen/common/vm_event.c +2 -0
index 1666ff615f..102745117e 100644
@@ -559,6 +559,7 @@ static void cf_check mem_sharing_notification(struct vcpu *v, unsigned int port)
 }
 #endif
 
+#ifdef CONFIG_DOMCTL
 /* Clean up on domain destruction */
 void vm_event_cleanup(struct domain *d)
 {
@@ -589,6 +590,7 @@ void vm_event_cleanup(struct domain *d)
     }
 #endif
 }
+#endif /* CONFIG_DOMCTL */
 
 int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
 {
xen/drivers/passthrough/device_tree.c +2 -0
index f5850a2607..704910de3d 100644
@@ -108,6 +108,7 @@ int iommu_dt_domain_init(struct domain *d)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 int iommu_release_dt_devices(struct domain *d)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -136,6 +137,7 @@ int iommu_release_dt_devices(struct domain *d)
 
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int iommu_dt_xlate(struct device *dev,
                           const struct dt_phandle_args *iommu_spec,
xen/drivers/passthrough/pci.c +2 -0
index 3edcfa8a04..41638b71d6 100644
@@ -945,6 +945,7 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus,
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 int pci_release_devices(struct domain *d)
 {
     int combined_ret;
@@ -1003,6 +1004,7 @@ int pci_release_devices(struct domain *d)
 
     return combined_ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 #define PCI_CLASS_BRIDGE_HOST    0x0600
 #define PCI_CLASS_BRIDGE_PCI     0x0604
Signature · 1 line
2.34.1
#23 lore raw

PATCH 10/25 xen/domctl: wrap around XEN_DOMCTL_setnodeaffinity

In reply to Penny Zheng

Function domain_set_node_affinity() is responsible for XEN_DOMCTL_setnodeaffinity domctl-op, and shall be wrapped with CONFIG_DOMCTL

---
 xen/common/domain.c | 2 ++
 1 file changed, 2 insertions(+)
xen/common/domain.c +2 -0
index be722c9f09..22313d761b 100644
@@ -1097,6 +1097,7 @@ void __init setup_system_domains(void)
 #endif
 }
 
+#ifdef CONFIG_DOMCTL
 int domain_set_node_affinity(struct domain *d, const nodemask_t *affinity)
 {
     /* Being disjoint with the system is just wrong. */
@@ -1125,6 +1126,7 @@ out:
 
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 /* rcu_read_lock(&domlist_read_lock) must be held. */
 static struct domain *domid_to_domain(domid_t dom)
Signature · 1 line
2.34.1
#24 lore raw

PATCH 11/25 xen/domctl: wrap around XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity}

In reply to Penny Zheng

Function vcpu_affinity_domctl() is responsible for XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity} domctl-op, tracking its calling chain, the following function shall be wrapped too:
- vcpu_set_soft_affinity

---
 xen/common/sched/core.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/common/sched/core.c +4 -0
index 2ab4313517..14f27fe70f 100644
@@ -1402,10 +1402,12 @@ int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity)
     return vcpu_set_affinity(v, affinity, v->sched_unit->cpu_hard_affinity);
 }
 
+#ifdef CONFIG_DOMCTL
 static int vcpu_set_soft_affinity(struct vcpu *v, const cpumask_t *affinity)
 {
     return vcpu_set_affinity(v, affinity, v->sched_unit->cpu_soft_affinity);
 }
+#endif /* CONFIG_DOMCTL */
 
 /* Block the currently-executing domain until a pertinent event occurs. */
 void vcpu_block(void)
@@ -1693,6 +1695,7 @@ int vcpuaffinity_params_invalid(const struct xen_domctl_vcpuaffinity *vcpuaff)
             guest_handle_is_null(vcpuaff->cpumap_soft.bitmap));
 }
 
+#ifdef CONFIG_DOMCTL
 int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
                          struct xen_domctl_vcpuaffinity *vcpuaff)
 {
@@ -1802,6 +1805,7 @@ int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 bool alloc_affinity_masks(struct affinity_masks *affinity)
 {
Signature · 1 line
2.34.1
#25 lore raw

PATCH 12/25 xen/domctl: wrap around XEN_DOMCTL_scheduler_op

In reply to Penny Zheng

Function sched_adjust() is responsible for XEN_DOMCTL_scheduler_op domctl-op. Tracing its calling chain, the following functions shall be wrapped too:
- xsm_domctl_scheduler_op()
- sched_adjust_dom()
- scheduler-specific .adjust() callback

---
 xen/common/sched/arinc653.c | 2 ++
 xen/common/sched/core.c     | 2 ++
 xen/common/sched/credit.c   | 4 ++++
 xen/common/sched/credit2.c  | 4 ++++
 xen/common/sched/private.h  | 4 ++++
 xen/common/sched/rt.c       | 4 ++++
 xen/include/xsm/xsm.h       | 4 ++++
 xen/xsm/dummy.c             | 2 ++
 xen/xsm/flask/hooks.c       | 4 ++++
 9 files changed, 30 insertions(+)
xen/common/sched/arinc653.c +2 -0
index 8a4f4259d8..e73b0256a6 100644
@@ -735,7 +735,9 @@ static const struct scheduler sched_arinc653_def = {
 
     .switch_sched   = a653_switch_sched,
 
+#ifdef CONFIG_DOMCTL
     .adjust         = NULL,
+#endif
 #ifdef CONFIG_SYSCTL
     .adjust_global  = a653sched_adjust_global,
 #endif
xen/common/sched/core.c +2 -0
index 14f27fe70f..896178b32f 100644
@@ -2080,6 +2080,7 @@ int scheduler_id(void)
 }
 #endif
 
+#ifdef CONFIG_DOMCTL
 /* Adjust scheduling parameter for a given domain. */
 long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
 {
@@ -2114,6 +2115,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 #ifdef CONFIG_SYSCTL
 long sched_adjust_global(struct xen_sysctl_scheduler_op *op)
xen/common/sched/credit.c +4 -0
index 6dcf6b2c8b..fff1af063e 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_DOMCTL
 static int cf_check
 csched_dom_cntl(
     const struct scheduler *ops,
@@ -1227,6 +1228,7 @@ csched_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static void cf_check
 csched_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -2288,7 +2290,9 @@ static const struct scheduler sched_credit_def = {
     .wake           = csched_unit_wake,
     .yield          = csched_unit_yield,
 
+#ifdef CONFIG_DOMCTL
     .adjust         = csched_dom_cntl,
+#endif
     .adjust_affinity= csched_aff_cntl,
 #ifdef CONFIG_SYSCTL
     .adjust_global  = csched_sys_cntl,
xen/common/sched/credit2.c +4 -0
index 75316d42b7..51784d9aab 100644
@@ -2909,6 +2909,7 @@ static void cf_check csched2_unit_migrate(
         sched_set_res(unit, get_sched_res(new_cpu));
 }
 
+#ifdef CONFIG_DOMCTL
 static int cf_check
 csched2_dom_cntl(
     const struct scheduler *ops,
@@ -3114,6 +3115,7 @@ csched2_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static void cf_check
 csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -4246,7 +4248,9 @@ static const struct scheduler sched_credit2_def = {
     .wake           = csched2_unit_wake,
     .yield          = csched2_unit_yield,
 
+#ifdef CONFIG_DOMCTL
     .adjust         = csched2_dom_cntl,
+#endif
     .adjust_affinity= csched2_aff_cntl,
 #ifdef CONFIG_SYSCTL
     .adjust_global  = csched2_sys_cntl,
xen/common/sched/private.h +4 -0
index d6884550cd..b8841c9308 100644
@@ -349,9 +349,11 @@ struct scheduler {
     void         (*migrate)        (const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     unsigned int new_cpu);
+#ifdef CONFIG_DOMCTL
     int          (*adjust)         (const struct scheduler *ops,
                                     struct domain *d,
                                     struct xen_domctl_scheduler_op *op);
+#endif
     void         (*adjust_affinity)(const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     const struct cpumask *hard,
@@ -506,11 +508,13 @@ static inline void sched_adjust_affinity(const struct scheduler *s,
         s->adjust_affinity(s, unit, hard, soft);
 }
 
+#ifdef CONFIG_DOMCTL
 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;
 }
+#endif
 
 #ifdef CONFIG_SYSCTL
 static inline int sched_adjust_cpupool(const struct scheduler *s,
xen/common/sched/rt.c +4 -0
index 7b1f64a779..fd677b4f09 100644
@@ -1362,6 +1362,7 @@ out:
     unit_schedule_unlock_irq(lock, unit);
 }
 
+#ifdef CONFIG_DOMCTL
 /*
  * set/get each unit info of each domain
  */
@@ -1471,6 +1472,7 @@ rt_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * 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_DOMCTL
     .adjust         = rt_dom_cntl,
+#endif
 
     .pick_resource  = rt_res_pick,
     .do_schedule    = rt_schedule,
xen/include/xsm/xsm.h +4 -0
index 7c61f27366..6444f0677b 100644
@@ -56,7 +56,9 @@ struct xsm_ops {
                                 struct xen_domctl_getdomaininfo *info);
     int (*domain_create)(struct domain *d, uint32_t ssidref);
     int (*getdomaininfo)(struct domain *d);
+#ifdef CONFIG_DOMCTL
     int (*domctl_scheduler_op)(struct domain *d, int op);
+#endif
 #ifdef CONFIG_SYSCTL
     int (*sysctl_scheduler_op)(int op);
 #endif
@@ -242,11 +244,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_DOMCTL
 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);
 }
+#endif
 
 #ifdef CONFIG_SYSCTL
 static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
xen/xsm/dummy.c +2 -0
index 6f8b06b45f..b8a9b581b7 100644
@@ -18,7 +18,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .security_domaininfo           = xsm_security_domaininfo,
     .domain_create                 = xsm_domain_create,
     .getdomaininfo                 = xsm_getdomaininfo,
+#ifdef CONFIG_DOMCTL
     .domctl_scheduler_op           = xsm_domctl_scheduler_op,
+#endif
 #ifdef CONFIG_SYSCTL
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
 #endif
xen/xsm/flask/hooks.c +4 -0
index fd7aea460f..55da0a5ff7 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_DOMCTL
 static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
 {
     switch ( op )
@@ -625,6 +626,7 @@ static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
         return avc_unknown_permission("domctl_scheduler_op", op);
     }
 }
+#endif /* CONFIG_DOMCTL */
 
 #ifdef CONFIG_SYSCTL
 static int cf_check flask_sysctl_scheduler_op(int op)
@@ -1890,7 +1892,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .security_domaininfo = flask_security_domaininfo,
     .domain_create = flask_domain_create,
     .getdomaininfo = flask_getdomaininfo,
+#ifdef CONFIG_DOMCTL
     .domctl_scheduler_op = flask_domctl_scheduler_op,
+#endif
 #ifdef CONFIG_SYSCTL
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
 #endif
Signature · 1 line
2.34.1
#26 lore raw

PATCH 13/25 xen/domctl: wrap around XEN_DOMCTL_getvcpucontext

In reply to Penny Zheng

Arch-specific function arch_get_info_guest() is responsible for XEN_DOMCTL_getvcpucontext domctl-op, and shall be wrapped

---
 xen/arch/arm/domctl.c | 2 ++
 xen/arch/x86/domctl.c | 2 ++
 2 files changed, 4 insertions(+)
xen/arch/arm/domctl.c +2 -0
index ad914c915f..d508ee2880 100644
@@ -184,6 +184,7 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
     }
 }
 
+#ifdef CONFIG_DOMCTL
 void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
 {
     struct vcpu_guest_context *ctxt = c.nat;
@@ -199,6 +200,7 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !test_bit(_VPF_down, &v->pause_flags) )
         ctxt->flags |= VGCF_online;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/domctl.c +2 -0
index 156c74e07a..29f9db89a1 100644
@@ -1367,6 +1367,7 @@ long arch_do_domctl(
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 #ifdef CONFIG_COMPAT
 #define xen_vcpu_guest_context vcpu_guest_context
 #define fpu_ctxt fpu_ctxt.x
@@ -1525,6 +1526,7 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     c(vm_assist = d->vm_assist);
 #undef c
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
Signature · 1 line
2.34.1
#27 lore raw

PATCH 14/25 xen/domctl: wrap around XEN_DOMCTL_{irq_permission,iomem_permission}

In reply to Penny Zheng

The following functions are invoked only under XEN_DOMCTL_{irq_permission,iomem_permission} domctl-op, and shall be wrapped:
- xsm_irq_permission
- 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 12792c3a43..55521c012b 100644
@@ -556,6 +556,7 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
     return xsm_default_action(action, current->domain, d);
 }
 
+#ifdef CONFIG_DOMCTL
 static XSM_INLINE int cf_check xsm_irq_permission(
     XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
 {
@@ -569,6 +570,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_DOMCTL */
 
 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 6444f0677b..1759d49aaa 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_DOMCTL
     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,
@@ -511,6 +513,7 @@ static inline int xsm_unbind_pt_irq(
     return alternative_call(xsm_ops.unbind_pt_irq, d, bind);
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int xsm_irq_permission(
     xsm_default_t def, struct domain *d, int pirq, uint8_t allow)
 {
@@ -522,6 +525,7 @@ static inline int xsm_iomem_permission(
 {
     return alternative_call(xsm_ops.iomem_permission, d, s, e, allow);
 }
+#endif /* CONFIG_DOMCTL */
 
 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 b8a9b581b7..2798425de2 100644
@@ -75,8 +75,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_DOMCTL
     .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 55da0a5ff7..8361cf94f9 100644
@@ -1113,12 +1113,14 @@ static int cf_check flask_unbind_pt_irq(
     return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 struct iomem_has_perm_data {
     uint32_t ssid;
@@ -1949,8 +1951,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_DOMCTL
     .irq_permission = flask_irq_permission,
     .iomem_permission = flask_iomem_permission,
+#endif
     .iomem_mapping = flask_iomem_mapping,
     .pci_config_permission = flask_pci_config_permission,
 
Signature · 1 line
2.34.1
#28 lore raw

PATCH 15/25 xen/domctl: wrap around XEN_DOMCTL_settimeoffset

In reply to Penny Zheng

Arch-specific domain_set_time_offset() is responisble for XEN_DOMCTL_settimeoffset domctl-op, and shall be wrapped.

---
 xen/arch/arm/time.c | 2 ++
 xen/arch/x86/time.c | 2 ++
 2 files changed, 4 insertions(+)
xen/arch/arm/time.c +2 -0
index e74d30d258..5955c7ce7a 100644
@@ -365,12 +365,14 @@ void force_update_vcpu_system_time(struct vcpu *v)
     update_vcpu_system_time(v);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 static int cpu_time_callback(struct notifier_block *nfb,
                              unsigned long action,
xen/arch/x86/time.c +2 -0
index 59129f419d..c1411be64e 100644
@@ -1841,6 +1841,7 @@ static void update_domain_rtc(void)
     rcu_read_unlock(&domlist_read_lock);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 int cpu_frequency_change(u64 freq)
 {
Signature · 1 line
2.34.1
#29 lore raw

PATCH 16/25 xen/domctl: wrap around XEN_DOMCTL_set_target

In reply to Penny Zheng

Function xsm_set_target() is only invoked under XEN_DOMCTL_set_target domctl-op, and shall be wrapped.

---
 xen/include/xsm/xsm.h | 4 ++++
 xen/xsm/dummy.c       | 2 ++
 xen/xsm/flask/hooks.c | 4 ++++
 3 files changed, 10 insertions(+)
xen/include/xsm/xsm.h +4 -0
index 1759d49aaa..55f8d0903e 100644
@@ -62,7 +62,9 @@ struct xsm_ops {
 #ifdef CONFIG_SYSCTL
     int (*sysctl_scheduler_op)(int op);
 #endif
+#ifdef CONFIG_DOMCTL
     int (*set_target)(struct domain *d, struct domain *e);
+#endif
     int (*domctl)(struct domain *d, unsigned int cmd, uint32_t ssidref);
     int (*sysctl)(int cmd);
     int (*readconsole)(uint32_t clear);
@@ -261,11 +263,13 @@ static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
 }
 #endif
 
+#ifdef CONFIG_DOMCTL
 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
 
 static inline int xsm_domctl(xsm_default_t def, struct domain *d,
                              unsigned int cmd, uint32_t ssidref)
xen/xsm/dummy.c +2 -0
index 2798425de2..cd5358dd1e 100644
@@ -24,7 +24,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
 #ifdef CONFIG_SYSCTL
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
 #endif
+#ifdef CONFIG_DOMCTL
     .set_target                    = xsm_set_target,
+#endif
     .domctl                        = xsm_domctl,
 #ifdef CONFIG_SYSCTL
     .sysctl                        = xsm_sysctl,
xen/xsm/flask/hooks.c +4 -0
index 8361cf94f9..2975d2906f 100644
@@ -645,6 +645,7 @@ static int cf_check flask_sysctl_scheduler_op(int op)
 }
 #endif /* CONFIG_SYSCTL */
 
+#ifdef CONFIG_DOMCTL
 static int cf_check flask_set_target(struct domain *d, struct domain *t)
 {
     int rc;
@@ -668,6 +669,7 @@ static int cf_check flask_set_target(struct domain *d, struct domain *t)
                                  &dsec->target_sid);
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
                                  uint32_t ssidref)
@@ -1900,7 +1902,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
 #ifdef CONFIG_SYSCTL
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
 #endif
+#ifdef CONFIG_DOMCTL
     .set_target = flask_set_target,
+#endif
     .domctl = flask_domctl,
 #ifdef CONFIG_SYSCTL
     .sysctl = flask_sysctl,
Signature · 1 line
2.34.1
#30 lore raw

PATCH 17/25 xen: add stub for XEN_DOMCTL_getdomaininfo

In reply to Penny Zheng

Function getdomaininfo() is designed for XEN_DOMCTL_getdomaininfo domctl-op to get per-domain info in userspace, so it shall be guarded with CONFIG_DOMCTL. We need to provide stub for getdomaininfo(), as it still could be invoked by XEN_SYSCTL_getdomaininfolist sysctl-op when CONFIG_DOMCTL=n. The same logic goes for xsm_getdomaininfo() too.

---
 xen/include/xen/domain.h | 5 +++++
 xen/include/xsm/xsm.h    | 6 +++++-
 xen/xsm/dummy.c          | 2 +-
 xen/xsm/flask/hooks.c    | 4 ++--
 4 files changed, 13 insertions(+), 4 deletions(-)
xen/include/xen/domain.h +5 -0
index b45ac91760..55befdb256 100644
@@ -31,8 +31,13 @@ int vcpu_up(struct vcpu *v);
 
 void setup_system_domains(void);
 
+#ifdef CONFIG_DOMCTL
 struct xen_domctl_getdomaininfo;
 void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info);
+#else
+static inline void getdomaininfo(struct domain *d,
+                                 struct xen_domctl_getdomaininfo *info) {}
+#endif /* CONFIG_DOMCTL */
 void arch_get_domain_info(const struct domain *d,
                           struct xen_domctl_getdomaininfo *info);
 
xen/include/xsm/xsm.h +5 -1
index 55f8d0903e..db98496869 100644
@@ -55,8 +55,8 @@ struct xsm_ops {
     void (*security_domaininfo)(struct domain *d,
                                 struct xen_domctl_getdomaininfo *info);
     int (*domain_create)(struct domain *d, uint32_t ssidref);
-    int (*getdomaininfo)(struct domain *d);
 #ifdef CONFIG_DOMCTL
+    int (*getdomaininfo)(struct domain *d);
     int (*domctl_scheduler_op)(struct domain *d, int op);
 #endif
 #ifdef CONFIG_SYSCTL
@@ -240,7 +240,11 @@ static inline int xsm_domain_create(
 
 static inline int xsm_getdomaininfo(xsm_default_t def, struct domain *d)
 {
+#ifdef CONFIG_DOMCTL
     return alternative_call(xsm_ops.getdomaininfo, d);
+#else
+    return -EOPNOTSUPP;
+#endif
 }
 
 static inline int xsm_get_domain_state(xsm_default_t def, struct domain *d)
xen/xsm/dummy.c +1 -1
index cd5358dd1e..b7eb061e9b 100644
@@ -17,8 +17,8 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .set_system_active             = xsm_set_system_active,
     .security_domaininfo           = xsm_security_domaininfo,
     .domain_create                 = xsm_domain_create,
-    .getdomaininfo                 = xsm_getdomaininfo,
 #ifdef CONFIG_DOMCTL
+    .getdomaininfo                 = xsm_getdomaininfo,
     .domctl_scheduler_op           = xsm_domctl_scheduler_op,
 #endif
 #ifdef CONFIG_SYSCTL
xen/xsm/flask/hooks.c +2 -2
index 2975d2906f..9f829aa53b 100644
@@ -604,12 +604,12 @@ static int cf_check flask_domain_create(struct domain *d, uint32_t ssidref)
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 static int cf_check flask_getdomaininfo(struct domain *d)
 {
     return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__GETDOMAININFO);
 }
 
-#ifdef CONFIG_DOMCTL
 static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
 {
     switch ( op )
@@ -1895,8 +1895,8 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .set_system_active = flask_set_system_active,
     .security_domaininfo = flask_security_domaininfo,
     .domain_create = flask_domain_create,
-    .getdomaininfo = flask_getdomaininfo,
 #ifdef CONFIG_DOMCTL
+    .getdomaininfo = flask_getdomaininfo,
     .domctl_scheduler_op = flask_domctl_scheduler_op,
 #endif
 #ifdef CONFIG_SYSCTL
Signature · 1 line
2.34.1
#31 lore raw

PATCH 18/25 xen/domctl: wrap around XEN_DOMCTL_set_access_required

In reply to Penny Zheng

Arch-specific arch_p2m_set_access_required() is reponsible for XEN_DOMCTL_set_access_required domctl-op, and shall be wrapped.

---
 xen/arch/arm/mem_access.c    | 2 ++
 xen/arch/x86/mm/mem_access.c | 2 ++
 2 files changed, 4 insertions(+)
xen/arch/arm/mem_access.c +2 -0
index 2af92bb402..e205b6be8f 100644
@@ -450,11 +450,13 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn,
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 void arch_p2m_set_access_required(struct domain *d, bool access_required)
 {
     ASSERT(atomic_read(&d->pause_count));
     p2m_get_hostp2m(d)->access_required = access_required;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/mm/mem_access.c +2 -0
index 21b5b7ecda..de694c16e9 100644
@@ -480,6 +480,7 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access,
     return _p2m_get_mem_access(p2m, gfn, access);
 }
 
+#ifdef CONFIG_DOMCTL
 void arch_p2m_set_access_required(struct domain *d, bool access_required)
 {
     ASSERT(atomic_read(&d->pause_count));
@@ -498,6 +499,7 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required)
         }
     }
 }
+#endif /* CONFIG_DOMCTL */
 
 bool p2m_mem_access_sanity_check(const struct domain *d)
 {
Signature · 1 line
2.34.1
#32 lore raw

PATCH 19/25 xen: make CONFIG_VM_EVENT depend on DOMCTL

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_DOMCTL

---
 xen/common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/Kconfig +1 -1
index bf1850c154..24a7b83af9 100644
@@ -145,7 +145,7 @@ config MEM_ACCESS_ALWAYS_ON
 config VM_EVENT
 	def_bool MEM_ACCESS_ALWAYS_ON
 	prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON
-	depends on HVM
+	depends on HVM && DOMCTL
 	help
 
 	  Framework to configure memory access types for guests and receive
Signature · 1 line
2.34.1
#33 lore raw

PATCH 20/25 xen/domctl: wrap around XEN_DOMCTL_set_virq_handler

In reply to Penny Zheng

Function set_global_virq_handler() is reponsible for XEN_DOMCTL_set_virq_handler domctl-op, and shall be wrapped.

---
 xen/common/event_channel.c | 2 ++
 1 file changed, 2 insertions(+)
xen/common/event_channel.c +2 -0
index 67700b050a..e11b677cac 100644
@@ -1006,6 +1006,7 @@ void send_global_virq(uint32_t virq)
     send_guest_domain_virq(get_global_virq_handler(virq), virq);
 }
 
+#ifdef CONFIG_DOMCTL
 int set_global_virq_handler(struct domain *d, uint32_t virq)
 {
     struct domain *old, *hdl;
@@ -1068,6 +1069,7 @@ int set_global_virq_handler(struct domain *d, uint32_t virq)
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static void clear_global_virq_handlers(struct domain *d)
 {
Signature · 1 line
2.34.1
#34 lore raw

PATCH 21/25 xen/domctl: wrap aound iommu-related domctl op

In reply to Penny Zheng

Function iommu_do_domctl() is the main entry for all iommu-related domctl-op. Tracking its calling chaining, the following functions shall all be wrapped:
- iommu_do_pci_domctl
- xsm_get_device_group
- iommu_get_device_group
- amd_iommu_group_id/intel_iommu_group_id
- xsm_assign_device
- device_assigned
- assign_device
- intel_iommu_assign_device/amd_iommu_assign_devic
- xsm_deassign_device
- deassign_device
- reassign_device_ownership/reassign_device
- iommu_do_dt_domctl
- xsm_assign_dtdevice
- xsm_deassign_dtdevice
- iommu_deassign_dt_device
- arm_smmu_reassign_dev/arm_smmu_reassign_dev
- ipmmu_reassign_dev
- ipmmu_deassign_dev
- ipmmu_detach_dev
- dt_find_node_by_gpath

---
 xen/common/device-tree/device-tree.c        |  2 ++
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  8 ++++++++
 xen/drivers/passthrough/arm/ipmmu-vmsa.c    |  6 ++++++
 xen/drivers/passthrough/arm/smmu-v3.c       |  4 ++++
 xen/drivers/passthrough/arm/smmu.c          |  4 ++++
 xen/drivers/passthrough/device_tree.c       |  4 ++++
 xen/drivers/passthrough/iommu.c             |  2 ++
 xen/drivers/passthrough/pci.c               |  6 +++++-
 xen/drivers/passthrough/vtd/iommu.c         |  6 ++++++
 xen/include/xsm/xsm.h                       | 12 ++++++------
 xen/xsm/dummy.c                             |  4 ++--
 xen/xsm/flask/hooks.c                       | 12 ++++++------
 12 files changed, 55 insertions(+), 15 deletions(-)
xen/common/device-tree/device-tree.c +2 -0
index 0b5375f151..4ce6dce2ea 100644
@@ -371,6 +371,7 @@ struct dt_device_node *dt_find_node_by_path_from(struct dt_device_node *from,
     return np;
 }
 
+#ifdef CONFIG_DOMCTL
 int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
                           struct dt_device_node **node)
 {
@@ -386,6 +387,7 @@ int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
 
     return (*node == NULL) ? -ESRCH : 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 struct dt_device_node *dt_find_node_by_alias(const char *alias)
 {
xen/drivers/passthrough/amd/pci_amd_iommu.c +8 -0
index 3a14770855..869d2bc3a2 100644
@@ -461,6 +461,7 @@ static void amd_iommu_disable_domain_device(const struct domain *domain,
         spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
+#ifdef CONFIG_DOMCTL
 static int cf_check reassign_device(
     struct domain *source, struct domain *target, u8 devfn,
     struct pci_dev *pdev)
@@ -550,6 +551,7 @@ static int cf_check amd_iommu_assign_device(
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static void cf_check amd_iommu_clear_root_pgtable(struct domain *d)
 {
@@ -698,12 +700,14 @@ static int cf_check amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev)
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 #include <asm/io_apic.h>
 
@@ -772,14 +776,18 @@ 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,
+#ifdef CONFIG_DOMCTL
     .assign_device  = amd_iommu_assign_device,
+#endif
     .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_DOMCTL
     .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/arm/ipmmu-vmsa.c +6 -0
index dac0dd6d46..719f0a11cc 100644
@@ -726,6 +726,7 @@ static int ipmmu_attach_device(struct ipmmu_vmsa_domain *domain,
     return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 static void ipmmu_detach_device(struct ipmmu_vmsa_domain *domain,
                                 struct device *dev)
 {
@@ -735,6 +736,7 @@ static void ipmmu_detach_device(struct ipmmu_vmsa_domain *domain,
     for ( i = 0; i < fwspec->num_ids; ++i )
         ipmmu_utlb_disable(domain, fwspec->ids[i]);
 }
+#endif /* CONFIG_DOMCTL */
 
 static int ipmmu_init_platform_device(struct device *dev,
                                       const struct dt_phandle_args *args)
@@ -1209,6 +1211,7 @@ out:
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 static int ipmmu_deassign_device(struct domain *d, struct device *dev)
 {
     struct ipmmu_vmsa_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
@@ -1264,6 +1267,7 @@ static int ipmmu_reassign_device(struct domain *s, struct domain *t,
 
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int ipmmu_dt_xlate(struct device *dev,
                           const struct dt_phandle_args *spec)
@@ -1367,7 +1371,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_DOMCTL
     .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 +4 -0
index 5e9e3e048e..d3028d859e 100644
@@ -2780,6 +2780,7 @@ static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn, struct device
 	return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,
 				u8 devfn,  struct device *dev)
 {
@@ -2807,6 +2808,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,
 
 	return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int arm_smmu_iommu_xen_domain_init(struct domain *d)
 {
@@ -2843,7 +2845,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_DOMCTL
 	.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 +4 -0
index 22d306d0cb..f1d85ae91f 100644
@@ -2891,6 +2891,7 @@ static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn,
 	return 0;
 }
 
+#ifdef CONFIG_DOMCTL
 static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,
 				 u8 devfn,  struct device *dev)
 {
@@ -2918,6 +2919,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,
 
 	return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int arm_smmu_iommu_domain_init(struct domain *d)
 {
@@ -2956,7 +2958,9 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
     .teardown = arm_smmu_iommu_domain_teardown,
     .iotlb_flush = arm_smmu_iotlb_flush,
     .assign_device = arm_smmu_assign_dev,
+#ifdef CONFIG_DOMCTL
     .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_generic,
xen/drivers/passthrough/device_tree.c +4 -0
index 704910de3d..225aae2f29 100644
@@ -59,6 +59,7 @@ fail:
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev)
 {
     const struct domain_iommu *hd = dom_iommu(d);
@@ -86,6 +87,7 @@ fail:
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 static bool iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev)
 {
@@ -320,6 +322,7 @@ int iommu_add_dt_device(struct dt_device_node *np)
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
@@ -431,3 +434,4 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
xen/drivers/passthrough/iommu.c +2 -0
index c9425d6971..5035eb6e53 100644
@@ -625,6 +625,7 @@ void iommu_resume(void)
         iommu_vcall(iommu_get_ops(), resume);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 void iommu_crash_shutdown(void)
 {
xen/drivers/passthrough/pci.c +5 -1
index 41638b71d6..176c7502d6 100644
@@ -877,6 +877,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn)
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 /* Caller should hold the pcidevs_lock */
 static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus,
                            uint8_t devfn)
@@ -945,7 +946,6 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus,
     return ret;
 }
 
-#ifdef CONFIG_DOMCTL
 int pci_release_devices(struct domain *d)
 {
     int combined_ret;
@@ -1483,6 +1483,7 @@ static int iommu_remove_device(struct pci_dev *pdev)
     return iommu_call(hd->platform_ops, remove_device, devfn, pci_to_dev(pdev));
 }
 
+#ifdef CONFIG_DOMCTL
 static int device_assigned(u16 seg, u8 bus, u8 devfn)
 {
     struct pci_dev *pdev;
@@ -1646,6 +1647,7 @@ static int iommu_get_device_group(
 
     return i;
 }
+#endif /* CONFIG_DOMCTL */
 
 void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev)
 {
@@ -1671,6 +1673,7 @@ void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev)
     pcidevs_unlock();
 }
 
+#ifdef CONFIG_DOMCTL
 int iommu_do_pci_domctl(
     struct xen_domctl *domctl, struct domain *d,
     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
@@ -1804,6 +1807,7 @@ int iommu_do_pci_domctl(
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 struct segment_iter {
     int (*handler)(struct pci_dev *pdev, void *arg);
xen/drivers/passthrough/vtd/iommu.c +6 -0
index c55f02c97e..e9c074a649 100644
@@ -2731,6 +2731,7 @@ static int __init cf_check vtd_setup(void)
     return ret;
 }
 
+#ifdef CONFIG_DOMCTL
 static int cf_check reassign_device_ownership(
     struct domain *source,
     struct domain *target,
@@ -2926,6 +2927,7 @@ static int cf_check intel_iommu_group_id(u16 seg, u8 bus, u8 devfn)
 
     return PCI_BDF(bus, devfn);
 }
+#endif /* CONFIG_DOMCTL */
 
 static int __must_check cf_check vtd_suspend(void)
 {
@@ -3234,14 +3236,18 @@ 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,
+#ifdef CONFIG_DOMCTL
     .assign_device  = intel_iommu_assign_device,
+#endif
     .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_DOMCTL
     .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/xsm/xsm.h +6 -6
index db98496869..6bbf3df702 100644
@@ -127,13 +127,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_HAS_PCI) && defined(CONFIG_DOMCTL)
     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
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY) && defined(CONFIG_DOMCTL)
     int (*assign_dtdevice)(struct domain *d, const char *dtpath);
     int (*deassign_dtdevice)(struct domain *d, const char *dtpath);
 #endif
@@ -548,7 +548,7 @@ 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_HAS_PCI) && defined(CONFIG_DOMCTL)
 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);
@@ -565,9 +565,9 @@ static inline int xsm_deassign_device(
 {
     return alternative_call(xsm_ops.deassign_device, d, machine_bdf);
 }
-#endif /* HAS_PASSTHROUGH && HAS_PCI) */
+#endif /* HAS_PASSTHROUGH && HAS_PCI && DOMCTL */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY) && defined(CONFIG_DOMCTL)
 static inline int xsm_assign_dtdevice(
     xsm_default_t def, struct domain *d, const char *dtpath)
 {
@@ -580,7 +580,7 @@ static inline int xsm_deassign_dtdevice(
     return alternative_call(xsm_ops.deassign_dtdevice, d, dtpath);
 }
 
-#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY */
+#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY && DOMCTL */
 
 static inline int xsm_resource_plug_pci(xsm_default_t def, uint32_t machine_bdf)
 {
xen/xsm/dummy.c +2 -2
index b7eb061e9b..b5174e610b 100644
@@ -85,13 +85,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_HAS_PCI) && defined(CONFIG_DOMCTL)
     .get_device_group              = xsm_get_device_group,
     .assign_device                 = xsm_assign_device,
     .deassign_device               = xsm_deassign_device,
 #endif
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY) && defined(CONFIG_DOMCTL)
     .assign_dtdevice               = xsm_assign_dtdevice,
     .deassign_dtdevice             = xsm_deassign_dtdevice,
 #endif
xen/xsm/flask/hooks.c +6 -6
index 9f829aa53b..254e1323e5 100644
@@ -1397,7 +1397,7 @@ 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_HAS_PCI) && defined(CONFIG_DOMCTL)
 static int cf_check flask_get_device_group(uint32_t machine_bdf)
 {
     uint32_t rsid;
@@ -1468,9 +1468,9 @@ 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 /* HAS_PASSTHROUGH && HAS_PCI && DOMCTL */
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY) && defined(CONFIG_DOMCTL)
 static int flask_test_assign_dtdevice(const char *dtpath)
 {
     uint32_t rsid;
@@ -1531,7 +1531,7 @@ 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 /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY && DOMCTL */
 
 static int cf_check flask_platform_op(uint32_t op)
 {
@@ -2003,13 +2003,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_HAS_PCI) && defined(CONFIG_DOMCTL)
     .get_device_group = flask_get_device_group,
     .assign_device = flask_assign_device,
     .deassign_device = flask_deassign_device,
 #endif
 
-#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY)
+#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE_DISCOVERY) && defined(CONFIG_DOMCTL)
     .assign_dtdevice = flask_assign_dtdevice,
     .deassign_dtdevice = flask_deassign_dtdevice,
 #endif
Signature · 1 line
2.34.1
#35 lore raw

PATCH 22/25 xen/domctl: wrap around XEN_DOMCTL_{get,set}_paging_mempool_size

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.

---
 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 4b13867fa2..878ce205e2 100644
@@ -58,12 +58,14 @@ static void p2m_free_page(struct domain *d, struct page_info *pg)
     }
 }
 
+#ifdef CONFIG_DOMCTL
 /* 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_DOMCTL */
 
 /*
  * 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_DOMCTL
 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_DOMCTL */
 
 int p2m_teardown_allocation(struct domain *d)
 {
xen/arch/x86/mm/paging.c +2 -0
index 3da99ad371..e6eff60df1 100644
@@ -955,6 +955,7 @@ int __init paging_set_allocation(struct domain *d, unsigned int pages,
 }
 #endif
 
+#ifdef CONFIG_DOMCTL
 int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)
 {
     unsigned long pages;
@@ -997,6 +998,7 @@ int arch_set_paging_mempool_size(struct domain *d, uint64_t size)
 
     return preempted ? -ERESTART : rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
Signature · 1 line
2.34.1
#36 lore raw

PATCH 23/25 xen/x86: make CONFIG_X86_PSR depend on SYSCTL || DOMCTL

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 SYSCTL or DOMCTL. with this change, we could remove SYSCTL-wrapping in psr.c

---
 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 a45ce106e2..691edf8926 100644
@@ -187,6 +187,7 @@ config TBOOT
 config X86_PSR
 	bool "Platform Shared Resource support" if EXPERT
 	default INTEL
+	depends on SYSCTL || DOMCTL
 	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 499d320e61..5815a35335 100644
@@ -133,11 +133,9 @@ static const struct feat_props {
      */
     enum psr_type alt_type;
 
-#ifdef CONFIG_SYSCTL
     /* 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);
@@ -420,7 +418,6 @@ static bool mba_init_feature(const struct cpuid_leaf *regs,
     return true;
 }
 
-#ifdef CONFIG_SYSCTL
 static bool cf_check cat_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
 {
@@ -433,7 +430,6 @@ static bool cf_check cat_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
 
 /* L3 CAT props */
 static void cf_check l3_cat_write_msr(
@@ -446,14 +442,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_SYSCTL
     .get_feat_info = cat_get_feat_info,
-#endif
     .write_msr = l3_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_SYSCTL
 /* L3 CDP props */
 static bool cf_check l3_cdp_get_feat_info(
     const struct feat_node *feat, uint32_t data[], uint32_t array_len)
@@ -465,7 +458,6 @@ static bool cf_check l3_cdp_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
 
 static void cf_check l3_cdp_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -481,9 +473,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
     .get_feat_info = l3_cdp_get_feat_info,
-#endif
     .write_msr = l3_cdp_write_msr,
     .sanitize = cat_check_cbm,
 };
@@ -499,14 +489,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_SYSCTL
     .get_feat_info = cat_get_feat_info,
-#endif
     .write_msr = l2_cat_write_msr,
     .sanitize = cat_check_cbm,
 };
 
-#ifdef CONFIG_SYSCTL
 /* MBA props */
 static bool cf_check mba_get_feat_info(
     const struct feat_node *feat, uint32_t data[], unsigned int array_len)
@@ -521,7 +508,6 @@ static bool cf_check mba_get_feat_info(
 
     return true;
 }
-#endif /* CONFIG_SYSCTL */
 
 static void cf_check mba_write_msr(
     unsigned int cos, uint32_t val, enum psr_type type)
@@ -559,9 +545,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
     .get_feat_info = mba_get_feat_info,
-#endif
     .write_msr = mba_write_msr,
     .sanitize = mba_sanitize_thrtl,
 };
@@ -824,7 +808,6 @@ static struct psr_socket_info *get_socket_info(unsigned int socket)
     return socket_info + socket;
 }
 
-#ifdef CONFIG_SYSCTL
 int psr_get_info(unsigned int socket, enum psr_type type,
                  uint32_t data[], unsigned int array_len)
 {
@@ -856,7 +839,6 @@ int psr_get_info(unsigned int socket, enum psr_type type,
 
     return -EINVAL;
 }
-#endif /* CONFIG_SYSCTL */
 
 int psr_get_val(struct domain *d, unsigned int socket,
                 uint32_t *val, enum psr_type type)
Signature · 1 line
2.34.1
#37 lore raw

PATCH 24/25 xen/domctl: wrap around arch-specific domctl op

In reply to Penny Zheng

Function arch_do_domctl() is responsible for arch-specific domctl-op, and the following functions shall be wrapped:
- xsm_domctl
For x86:
- hvm_save_one
- hvm_acpi_power_button
- hvm_acpi_sleep_button
- xsm_{bind,unbind}_pt_irq
- xsm_ioport_permission
- xsm_ioport_mapping
- hvm_debug_op
- mem_sharing_domctl
- make P2M_AUDIT depend on CONFIG_DOMCTL
- make PG_log_dirty depend on CONFIG_DOMCTL
- gdbsx_domctl
- gdbsx_guest_meminfo
- dgb_rw_guest_mem
- dbg_hvm_va2mfn
- dbg_pv_va2mfn
- make policy.o depend on CONFIG_DOMCTL
- do_vmtrace_op
- hvm_vmtrace_control
- hvm_funcs.vmtrace_control
- hvm_vmtrace_get_option
- hvm_funcs.vmtrace_get_option
- hvm_vmtrace_set_option
- hvm_funcs.vmtrace_set_option
For ARM:
- subarch_do_domctl

Also, remove all #ifdef CONFIG_DOMCTL-s in arch-specific domctl.c, as we put the guardian in Makefile for the whole file.

---
 xen/arch/arm/arm32/Makefile        |  2 +-
 xen/arch/arm/arm64/Makefile        |  2 +-
 xen/arch/arm/domctl.c              |  2 --
 xen/arch/x86/Makefile              |  2 +-
 xen/arch/x86/domctl.c              |  2 --
 xen/arch/x86/gdbsx.c               |  4 ++++
 xen/arch/x86/hvm/hvm.c             |  2 +-
 xen/arch/x86/hvm/pmtimer.c         |  2 ++
 xen/arch/x86/hvm/save.c            |  2 ++
 xen/arch/x86/hvm/vmx/vmx.c         |  6 ++++++
 xen/arch/x86/include/asm/hvm/hvm.h | 12 ++++++++++++
 xen/arch/x86/include/asm/p2m.h     |  2 +-
 xen/arch/x86/include/asm/paging.h  |  2 +-
 xen/arch/x86/mm/mem_sharing.c      |  2 ++
 xen/include/xsm/xsm.h              | 12 ++++++++----
 xen/lib/x86/Makefile               |  2 +-
 xen/xsm/dummy.c                    |  6 ++++--
 xen/xsm/flask/hooks.c              | 12 ++++++++----
 18 files changed, 55 insertions(+), 21 deletions(-)
xen/arch/arm/arm32/Makefile +1 -1
index 531168f58a..384aaea398 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_DOMCTL) += domctl.o
 obj-y += domain.o
 obj-y += entry.o
 obj-y += head.o
xen/arch/arm/arm64/Makefile +1 -1
index 6491c5350b..f2f547df9a 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_DOMCTL) += domctl.o
 obj-y += domain.o
 obj-y += entry.o
 obj-y += head.o
xen/arch/arm/domctl.c +0 -2
index d508ee2880..ad914c915f 100644
@@ -184,7 +184,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
     }
 }
 
-#ifdef CONFIG_DOMCTL
 void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
 {
     struct vcpu_guest_context *ctxt = c.nat;
@@ -200,7 +199,6 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     if ( !test_bit(_VPF_down, &v->pause_flags) )
         ctxt->flags |= VGCF_online;
 }
-#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/Makefile +1 -1
index 17f0e1dbc9..c48759650c 100644
@@ -28,7 +28,7 @@ obj-y += delay.o
 obj-y += desc.o
 obj-bin-y += dmi_scan.init.o
 obj-y += domain.o
-obj-y += domctl.o
+obj-$(CONFIG_DOMCTL) += domctl.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain_page.o
 obj-y += e820.o
xen/arch/x86/domctl.c +0 -2
index 29f9db89a1..156c74e07a 100644
@@ -1367,7 +1367,6 @@ long arch_do_domctl(
     return ret;
 }
 
-#ifdef CONFIG_DOMCTL
 #ifdef CONFIG_COMPAT
 #define xen_vcpu_guest_context vcpu_guest_context
 #define fpu_ctxt fpu_ctxt.x
@@ -1526,7 +1525,6 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
     c(vm_assist = d->vm_assist);
 #undef c
 }
-#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/gdbsx.c +4 -0
index 21442f5dff..df1a3ce9fb 100644
@@ -23,6 +23,7 @@
 #include <asm/gdbsx.h>
 #include <asm/p2m.h>
 
+#ifdef CONFIG_DOMCTL
 typedef unsigned long dbgva_t;
 typedef unsigned char dbgbyte_t;
 
@@ -166,6 +167,7 @@ static int gdbsx_guest_mem_io(
 
     return iop->remain ? -EFAULT : 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 void domain_pause_for_debugger(void)
 {
@@ -179,6 +181,7 @@ void domain_pause_for_debugger(void)
         send_global_virq(VIRQ_DEBUGGER);
 }
 
+#ifdef CONFIG_DOMCTL
 int gdbsx_domctl(struct domain *d, struct xen_domctl *domctl, bool *copyback)
 {
     struct vcpu *v;
@@ -245,6 +248,7 @@ int gdbsx_domctl(struct domain *d, struct xen_domctl *domctl, bool *copyback)
 
     return ret;
 }
+#endif /* CONFIG_DOMCTL */
 
 /*
  * Local variables:
xen/arch/x86/hvm/hvm.c +1 -1
index f464f401aa..aca1e5ba69 100644
@@ -5212,6 +5212,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 int hvm_debug_op(struct vcpu *v, int32_t op)
 {
     int rc = 0;
@@ -5251,7 +5252,6 @@ int hvm_debug_op(struct vcpu *v, int32_t op)
     return rc;
 }
 
-#ifdef CONFIG_VM_EVENT
 void hvm_toggle_singlestep(struct vcpu *v)
 {
     ASSERT(atomic_read(&v->pause_count));
xen/arch/x86/hvm/pmtimer.c +2 -0
index 87a7a01c9f..e4d0f001ff 100644
@@ -56,6 +56,7 @@ static void pmt_update_sci(PMTState *s)
         hvm_isa_irq_deassert(s->vcpu->domain, SCI_IRQ);
 }
 
+#ifdef CONFIG_DOMCTL
 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_DOMCTL */
 
 /* Set the correct value in the timer, accounting for time elapsed
  * since the last time we did that. */
xen/arch/x86/hvm/save.c +2 -0
index 8ab6405706..ffaf731ddc 100644
@@ -121,6 +121,7 @@ size_t hvm_save_size(struct domain *d)
     return sz;
 }
 
+#ifdef CONFIG_DOMCTL
 /*
  * Extract a single instance of a save record, by marshalling all records of
  * that type and copying out the one we need.
@@ -195,6 +196,7 @@ int hvm_save_one(struct domain *d, unsigned int typecode, unsigned int instance,
     xfree(ctxt.data);
     return rv;
 }
+#endif /* CONFIG_DOMCTL */
 
 int hvm_save(struct domain *d, hvm_domain_context_t *h)
 {
xen/arch/x86/hvm/vmx/vmx.c +6 -0
index 9e4ad864fa..f562ab90b6 100644
@@ -2577,6 +2577,7 @@ static bool cf_check vmx_get_pending_event(
     (RTIT_STATUS_FILTER_EN | RTIT_STATUS_CONTEXT_EN | RTIT_STATUS_TRIGGER_EN | \
      RTIT_STATUS_ERROR | RTIT_STATUS_STOPPED)
 
+#ifdef CONFIG_DOMCTL
 static int cf_check vmtrace_get_option(
     struct vcpu *v, uint64_t key, uint64_t *output)
 {
@@ -2685,6 +2686,7 @@ static int cf_check vmtrace_control(struct vcpu *v, bool enable, bool reset)
 
     return 0;
 }
+#endif /* CONFIG_DOMCTL */
 
 static int cf_check vmtrace_output_position(struct vcpu *v, uint64_t *pos)
 {
@@ -2873,10 +2875,14 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = {
     .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve,
     .altp2m_vcpu_emulate_ve = vmx_vcpu_emulate_ve,
     .altp2m_vcpu_emulate_vmfunc = vmx_vcpu_emulate_vmfunc,
+#ifdef CONFIG_DOMCTL
     .vmtrace_control = vmtrace_control,
+#endif
     .vmtrace_output_position = vmtrace_output_position,
+#ifdef CONFIG_DOMCTL
     .vmtrace_set_option = vmtrace_set_option,
     .vmtrace_get_option = vmtrace_get_option,
+#endif
     .vmtrace_reset = vmtrace_reset,
 
     .get_reg = vmx_get_reg,
xen/arch/x86/include/asm/hvm/hvm.h +12 -0
index bd53fcf155..dd106bac42 100644
@@ -236,10 +236,14 @@ struct hvm_function_table {
     int (*altp2m_vcpu_emulate_vmfunc)(const struct cpu_user_regs *regs);
 
     /* vmtrace */
+#ifdef CONFIG_DOMCTL
     int (*vmtrace_control)(struct vcpu *v, bool enable, bool reset);
+#endif
     int (*vmtrace_output_position)(struct vcpu *v, uint64_t *pos);
+#ifdef CONFIG_DOMCTL
     int (*vmtrace_set_option)(struct vcpu *v, uint64_t key, uint64_t value);
     int (*vmtrace_get_option)(struct vcpu *v, uint64_t key, uint64_t *value);
+#endif
     int (*vmtrace_reset)(struct vcpu *v);
 
     uint64_t (*get_reg)(struct vcpu *v, unsigned int reg);
@@ -740,6 +744,7 @@ static inline bool altp2m_vcpu_emulate_ve(struct vcpu *v)
     return false;
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool reset)
 {
     if ( hvm_funcs.vmtrace_control )
@@ -747,6 +752,7 @@ static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool reset)
 
     return -EOPNOTSUPP;
 }
+#endif
 
 /* Returns -errno, or a boolean of whether tracing is currently active. */
 static inline int hvm_vmtrace_output_position(struct vcpu *v, uint64_t *pos)
@@ -757,6 +763,7 @@ static inline int hvm_vmtrace_output_position(struct vcpu *v, uint64_t *pos)
     return -EOPNOTSUPP;
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int hvm_vmtrace_set_option(
     struct vcpu *v, uint64_t key, uint64_t value)
 {
@@ -774,6 +781,7 @@ static inline int hvm_vmtrace_get_option(
 
     return -EOPNOTSUPP;
 }
+#endif
 
 static inline int hvm_vmtrace_reset(struct vcpu *v)
 {
@@ -938,16 +946,19 @@ static inline bool hvm_has_set_descriptor_access_exiting(void)
 }
 #endif /* CONFIG_VM_EVENT */
 
+#ifdef CONFIG_DOMCTL
 static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool reset)
 {
     return -EOPNOTSUPP;
 }
+#endif
 
 static inline int hvm_vmtrace_output_position(struct vcpu *v, uint64_t *pos)
 {
     return -EOPNOTSUPP;
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int hvm_vmtrace_set_option(
     struct vcpu *v, uint64_t key, uint64_t value)
 {
@@ -959,6 +970,7 @@ static inline int hvm_vmtrace_get_option(
 {
     return -EOPNOTSUPP;
 }
+#endif /* CONFIG_DOMCTL */
 
 static inline uint64_t hvm_get_reg(struct vcpu *v, unsigned int reg)
 {
xen/arch/x86/include/asm/p2m.h +1 -1
index 9c92f67443..e20c1a0d4a 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_DOMCTL)
 #define P2M_AUDIT     1
 #else
 #define P2M_AUDIT     0
xen/arch/x86/include/asm/paging.h +1 -1
index 956b83215c..c35ef44fff 100644
@@ -55,7 +55,7 @@
 #define PG_translate   0
 #define PG_external    0
 #endif
-#if defined(CONFIG_HVM)
+#if defined(CONFIG_HVM) && defined(CONFIG_DOMCTL)
 /* Enable log dirty mode */
 #define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
xen/arch/x86/mm/mem_sharing.c +2 -0
index 7858565429..74706da2f9 100644
@@ -2317,6 +2317,7 @@ out:
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec)
 {
     int rc;
@@ -2334,6 +2335,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_domctl_mem_sharing_op *mec)
 
     return rc;
 }
+#endif /* CONFIG_DOMCTL */
 
 void arch_dump_shared_mem_info(void)
 {
xen/include/xsm/xsm.h +8 -4
index 6bbf3df702..86a1aa5d06 100644
@@ -64,8 +64,8 @@ struct xsm_ops {
 #endif
 #ifdef CONFIG_DOMCTL
     int (*set_target)(struct domain *d, struct domain *e);
-#endif
     int (*domctl)(struct domain *d, unsigned int cmd, uint32_t ssidref);
+#endif
     int (*sysctl)(int cmd);
     int (*readconsole)(uint32_t clear);
 
@@ -115,9 +115,9 @@ struct xsm_ops {
     int (*map_domain_irq)(struct domain *d, int irq, const void *data);
     int (*unmap_domain_pirq)(struct domain *d);
     int (*unmap_domain_irq)(struct domain *d, int irq, const void *data);
+#ifdef CONFIG_DOMCTL
     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_DOMCTL
     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);
@@ -196,10 +196,12 @@ struct xsm_ops {
     int (*update_va_mapping)(struct domain *d, struct domain *f,
                              l1_pgentry_t pte);
     int (*priv_mapping)(struct domain *d, struct domain *t);
+#ifdef CONFIG_DOMCTL
     int (*ioport_permission)(struct domain *d, uint32_t s, uint32_t e,
                              uint8_t allow);
     int (*ioport_mapping)(struct domain *d, uint32_t s, uint32_t e,
                           uint8_t allow);
+#endif
     int (*pmu_op)(struct domain *d, unsigned int op);
 #endif
     int (*dm_op)(struct domain *d);
@@ -273,13 +275,13 @@ static inline int xsm_set_target(
 {
     return alternative_call(xsm_ops.set_target, d, e);
 }
-#endif
 
 static inline int xsm_domctl(xsm_default_t def, struct domain *d,
                              unsigned int cmd, uint32_t ssidref)
 {
     return alternative_call(xsm_ops.domctl, d, cmd, ssidref);
 }
+#endif /* CONFIG_DOMCTL */
 
 static inline int xsm_sysctl(xsm_default_t def, int cmd)
 {
@@ -509,6 +511,7 @@ static inline int xsm_unmap_domain_irq(
     return alternative_call(xsm_ops.unmap_domain_irq, d, irq, data);
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int xsm_bind_pt_irq(
     xsm_default_t def, struct domain *d, struct xen_domctl_bind_pt_irq *bind)
 {
@@ -521,7 +524,6 @@ static inline int xsm_unbind_pt_irq(
     return alternative_call(xsm_ops.unbind_pt_irq, d, bind);
 }
 
-#ifdef CONFIG_DOMCTL
 static inline int xsm_irq_permission(
     xsm_default_t def, struct domain *d, int pirq, uint8_t allow)
 {
@@ -759,6 +761,7 @@ static inline int xsm_priv_mapping(
     return alternative_call(xsm_ops.priv_mapping, d, t);
 }
 
+#ifdef CONFIG_DOMCTL
 static inline int xsm_ioport_permission(
     xsm_default_t def, struct domain *d, uint32_t s, uint32_t e, uint8_t allow)
 {
@@ -770,6 +773,7 @@ static inline int xsm_ioport_mapping(
 {
     return alternative_call(xsm_ops.ioport_mapping, d, s, e, allow);
 }
+#endif /* CONFIG_DOMCTL */
 
 static inline int xsm_pmu_op(
     xsm_default_t def, struct domain *d, unsigned int op)
xen/lib/x86/Makefile +1 -1
index 780ea05db1..77f2831e84 100644
@@ -1,3 +1,3 @@
 obj-y += cpuid.o
 obj-y += msr.o
-obj-y += policy.o
+obj-$(CONFIG_DOMCTL) += policy.o
xen/xsm/dummy.c +4 -2
index b5174e610b..04b9b4e579 100644
@@ -26,8 +26,8 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
 #endif
 #ifdef CONFIG_DOMCTL
     .set_target                    = xsm_set_target,
-#endif
     .domctl                        = xsm_domctl,
+#endif
 #ifdef CONFIG_SYSCTL
     .sysctl                        = xsm_sysctl,
     .readconsole                   = xsm_readconsole,
@@ -75,9 +75,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .map_domain_irq                = xsm_map_domain_irq,
     .unmap_domain_pirq             = xsm_unmap_domain_pirq,
     .unmap_domain_irq              = xsm_unmap_domain_irq,
+#ifdef CONFIG_DOMCTL
     .bind_pt_irq                   = xsm_bind_pt_irq,
     .unbind_pt_irq                 = xsm_unbind_pt_irq,
-#ifdef CONFIG_DOMCTL
     .irq_permission                = xsm_irq_permission,
     .iomem_permission              = xsm_iomem_permission,
 #endif
@@ -149,8 +149,10 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .mmuext_op                     = xsm_mmuext_op,
     .update_va_mapping             = xsm_update_va_mapping,
     .priv_mapping                  = xsm_priv_mapping,
+#ifdef CONFIG_DOMCTL
     .ioport_permission             = xsm_ioport_permission,
     .ioport_mapping                = xsm_ioport_mapping,
+#endif
     .pmu_op                        = xsm_pmu_op,
 #endif
     .dm_op                         = xsm_dm_op,
xen/xsm/flask/hooks.c +8 -4
index 254e1323e5..00c4ac94e6 100644
@@ -669,7 +669,6 @@ static int cf_check flask_set_target(struct domain *d, struct domain *t)
                                  &dsec->target_sid);
     return rc;
 }
-#endif /* CONFIG_DOMCTL */
 
 static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
                                  uint32_t ssidref)
@@ -861,6 +860,7 @@ static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
         return avc_unknown_permission("domctl", cmd);
     }
 }
+#endif /* CONFIG_DOMCTL */
 
 #ifdef CONFIG_SYSCTL
 static int cf_check flask_sysctl(int cmd)
@@ -1082,6 +1082,7 @@ static int cf_check flask_unmap_domain_irq(
     return rc;
 }
 
+#ifdef CONFIG_DOMCTL
 static int cf_check flask_bind_pt_irq(
     struct domain *d, struct xen_domctl_bind_pt_irq *bind)
 {
@@ -1115,7 +1116,6 @@ static int cf_check flask_unbind_pt_irq(
     return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE);
 }
 
-#ifdef CONFIG_DOMCTL
 static int cf_check flask_irq_permission(
     struct domain *d, int pirq, uint8_t access)
 {
@@ -1640,6 +1640,7 @@ static int cf_check flask_shadow_control(struct domain *d, uint32_t op)
 }
 #endif /* PG_log_dirty */
 
+#ifdef CONFIG_DOMCTL
 struct ioport_has_perm_data {
     uint32_t ssid;
     uint32_t dsid;
@@ -1695,6 +1696,7 @@ static int cf_check flask_ioport_mapping(
 {
     return flask_ioport_permission(d, start, end, access);
 }
+#endif /* CONFIG_DOMCTL */
 
 static int cf_check flask_mem_sharing_op(
     struct domain *d, struct domain *cd, int op)
@@ -1904,8 +1906,8 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
 #endif
 #ifdef CONFIG_DOMCTL
     .set_target = flask_set_target,
-#endif
     .domctl = flask_domctl,
+#endif
 #ifdef CONFIG_SYSCTL
     .sysctl = flask_sysctl,
     .readconsole = flask_readconsole,
@@ -1953,9 +1955,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .map_domain_irq = flask_map_domain_irq,
     .unmap_domain_pirq = flask_unmap_domain_pirq,
     .unmap_domain_irq = flask_unmap_domain_irq,
+#ifdef CONFIG_DOMCTL
     .bind_pt_irq = flask_bind_pt_irq,
     .unbind_pt_irq = flask_unbind_pt_irq,
-#ifdef CONFIG_DOMCTL
     .irq_permission = flask_irq_permission,
     .iomem_permission = flask_iomem_permission,
 #endif
@@ -2028,8 +2030,10 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .mmuext_op = flask_mmuext_op,
     .update_va_mapping = flask_update_va_mapping,
     .priv_mapping = flask_priv_mapping,
+#ifdef CONFIG_DOMCTL
     .ioport_permission = flask_ioport_permission,
     .ioport_mapping = flask_ioport_mapping,
+#endif
     .pmu_op = flask_pmu_op,
 #endif
     .dm_op = flask_dm_op,
Signature · 1 line
2.34.1
#38 lore raw

PATCH 25/25 xen/domctl: wrap around domctl hypercall

In reply to Penny Zheng

Wrap domctl hypercall def and domctl.o with CONFIG_DOMCTL
We need to make DOMCTL with prompt back, add help info and set default value as y. We shall at least provide "# CONFIG_DOMCTL is not set" in preset configs for PV shim on x86.

---
 xen/arch/x86/configs/pvshim_defconfig | 1 +
 xen/common/Kconfig                    | 5 ++++-
 xen/common/Makefile                   | 2 +-
 xen/include/hypercall-defs.c          | 4 ++++
 4 files changed, 10 insertions(+), 2 deletions(-)
xen/arch/x86/configs/pvshim_defconfig +1 -0
index c58c29adb0..c100b84fa8 100644
@@ -25,3 +25,4 @@ CONFIG_EXPERT=y
 # CONFIG_DEBUG is not set
 # CONFIG_GDBSX is not set
 # CONFIG_SYSCTL is not set
+# CONFIG_DOMCTL is not set
xen/common/Kconfig +4 -1
index 24a7b83af9..31db3d448b 100644
@@ -629,7 +629,10 @@ config SYSCTL
 
 config DOMCTL
 	bool "Enable domctl hypercall"
-	def_bool y
+	default y
+	help
+	  This option shall only be disabled on some dom0less systems, or
+	  PV shim on x86, to reduce Xen footprint.
 
 endmenu
 
xen/common/Makefile +1 -1
index 756ddf52c3..fc83a45b60 100644
@@ -11,7 +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-y += domctl.o
+obj-$(CONFIG_DOMCTL) += domctl.o
 obj-y += event_2l.o
 obj-y += event_channel.o
 obj-$(CONFIG_EVTCHN_FIFO) += event_fifo.o
xen/include/hypercall-defs.c +4 -0
index c70f745ac2..ccc38e5e22 100644
@@ -197,7 +197,9 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #ifdef CONFIG_SYSCTL
 sysctl(xen_sysctl_t *u_sysctl)
 #endif
+#ifdef CONFIG_DOMCTL
 domctl(xen_domctl_t *u_domctl)
+#endif
 #if PG_log_dirty
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
@@ -280,7 +282,9 @@ hvm_op                             do       do       do       do       do
 #ifdef CONFIG_SYSCTL
 sysctl                             do       do       do       do       do
 #endif
+#ifdef CONFIG_DOMCTL
 domctl                             do       do       do       do       do
+#endif
 #ifdef CONFIG_KEXEC
 kexec_op                           compat   do       -        -        -
 #endif
Signature · 1 line
2.34.1
#39 lore raw
In reply to Penny Zheng
Quoted 41 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. Each hypercall has a separate option to keep configuration flexible.

Options to disable hypercalls:
- sysctl
- domctl
- hvm
- physdev
- platform

This patch serie is only focusing on introducing CONFIG_DOMCTL. Different options 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_SYSCTL, 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])

Penny Zheng (25):
xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE
xen/x86: consolidate vram tracking support
xen/x86: complement PG_log_dirty wrapping
xen: consolidate CONFIG_VM_EVENT
xen: introduce CONFIG_DOMCTL
xen/domctl: provide stub for domctl_lock_{acquire,release} xen/domctl: wrap around XEN_DOMCTL_pausedomain xen/domctl: wrap around XEN_DOMCTL_soft_reset
xen/domctl: wrap around XEN_DOMCTL_destroydomain xen/domctl: wrap around XEN_DOMCTL_setnodeaffinity xen/domctl: wrap around XEN_DOMCTL_{getvcpuaffinity,setvcpuaffinity} xen/domctl: wrap around XEN_DOMCTL_scheduler_op xen/domctl: wrap around XEN_DOMCTL_getvcpucontext xen/domctl: wrap around XEN_DOMCTL_{irq_permission,iomem_permission} xen/domctl: wrap around XEN_DOMCTL_settimeoffset xen/domctl: wrap around XEN_DOMCTL_set_target
xen: add stub for XEN_DOMCTL_getdomaininfo

Quoted 8 lines

xen/domctl: wrap around XEN_DOMCTL_set_access_required
xen: make CONFIG_VM_EVENT depend on DOMCTL xen/domctl: wrap around XEN_DOMCTL_set_virq_handler xen/domctl: wrap aound iommu-related domctl op xen/domctl: wrap around XEN_DOMCTL_{get,set}_paging_mempool_size xen/x86: make CONFIG_X86_PSR depend on SYSCTL || DOMCTL xen/domctl: wrap around arch-specific domctl op xen/domctl: wrap around domctl hypercall

Hmm, I should have remembered to Cc you on this [1] reply of mine to Jiqian. It applies here as well.

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2025-07/msg01884.html