xen/domctl: make domctl_lock generic
PATCH 1/1 xen/domctl: make domctl_lock generic
Not only domctl-op could do foreign updates to guest state, some hypercall, like HVMOP_set_param, could also do, and they all need domctl_lock for syncronization.
Later, we will introduce CONFIG_DOMCTL to wrap domctl.c. In order to continue using domctl_lock when CONFIG_DOMCTL not defined, we'd like to move domctl_lock_acquire/release() out of domctl.c, and into more common space, domain.c
The movement could also 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 domctl_lock_acquire/release() undefined, causing linking to fail.
--- xen/common/domain.c | 29 +++++++++++++++++++++++++++++ xen/common/domctl.c | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-)
xen/common/domain.c +29 -0
@@ -66,6 +66,35 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +static DEFINE_SPINLOCK (domctl_lock); + +bool domctl_lock_acquire (void ) +{ +/* +* Caller may try to pause its own VCPUs. We must prevent deadlock +* against other non-domctl routines which try to do the same. +*/ +if ( !spin_trylock (¤t->domain->hypercall_deadlock_mutex) ) +return 0 ; + +/* +* Trylock here is paranoia if we have multiple privileged domains. Then +* we could have one domain trying to pause another which is spinning +* on domctl_lock -- results in deadlock. +*/ +if (spin_trylock (&domctl_lock) ) +return 1 ; + +spin_unlock (¤t->domain->hypercall_deadlock_mutex); +return 0 ; +} + +void domctl_lock_release (void ) +{ +spin_unlock (&domctl_lock); +spin_unlock (¤t->domain->hypercall_deadlock_mutex); +} +/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc.
xen/common/domctl.c +0 -29
@@ -35,8 +35,6 @@#include <public/domctl.h> #include <xsm/xsm.h> -static DEFINE_SPINLOCK (domctl_lock); -static int nodemask_to_xenctl_bitmap (struct xenctl_bitmap *xenctl_nodemap,const nodemask_t *nodemask) {
@@ -65,33 +63,6 @@ static inline int is_free_domid(domid_t dom)return 0 ; } -bool domctl_lock_acquire (void ) -{ -/* -* Caller may try to pause its own VCPUs. We must prevent deadlock -* against other non-domctl routines which try to do the same. -*/ -if ( !spin_trylock (¤t->domain->hypercall_deadlock_mutex) ) -return 0 ; - -/* -* Trylock here is paranoia if we have multiple privileged domains. Then -* we could have one domain trying to pause another which is spinning -* on domctl_lock -- results in deadlock. -*/ -if (spin_trylock (&domctl_lock) ) -return 1 ; - -spin_unlock (¤t->domain->hypercall_deadlock_mutex); -return 0 ; -} - -void domctl_lock_release (void ) -{ -spin_unlock (&domctl_lock); -spin_unlock (¤t->domain->hypercall_deadlock_mutex); -} -void vnuma_destroy (struct vnuma_info *vnuma) {if ( vnuma )
Signature · 1 line
2.34.1
Quoted 3 lines · Penny Zheng
Not only domctl-op could do foreign updates to guest state, some hypercall, like
HVMOP_set_param, could also do, and they all needdomctl_lockfor syncronization.
What's "all" here? HVMOP_set_param is the sole such case, and hence - aiui - it uses the domctl lock only to lock out actual domctl-s. Of which there are not going to be any with DOMCTL=n, ...
Quoted 4 lines
Later, we will introduce
CONFIG_DOMCTLto wrapdomctl.c. In order to continue usingdomctl_lockwhenCONFIG_DOMCTLnot defined, we'd like to move domctl_lock_acquire/release() out ofdomctl.c, and into more common space,domain.c
... as you indicate is where we're going to move to as a possibility. Hence the domctl lock is meaningless without DOMCTL=y. At which point moving it out of domctl.c is the wrong course of action. With DOMCTL=n, we'll rather need stub domctl_lock_{acquire,release}(), which then likely would do nothing (or alternatively "#ifdef CONFIG_DOMCTL" could be put around the two uses in hvm_set_param()).
Quoted 4 lines
The movement could also fix CI error of a randconfig picking both PV_SHIM_EXCLUSIVE=y and HVM=y results in
hvm.cbeing built, butdomctl.cnot being built, which leaves domctl_lock_acquire/release() undefined, causing linking to fail.
If the work towards DOMCTL as a Kconfig control can't be progressed pretty quickly (and I don't expect that to be much faster than the SYSCTL work), then I expect our prime option (apart from reverting the earlier change) is to accept a bunch of dead code in the shim binary again, by moving domctl.o out of the PV_SHIM_EXCLUSIVE common/Makefile section as well (plus whatever other adjustments are necessary to undo that earlier dead code elimination).
Jan