domctl: Avoid taking domctl lock for certain ops used during migration
cover domctl: Avoid taking domctl lock for certain ops used during migration
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Ross Lagerwall (2):
domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
xen/arch/x86/domctl.c | 4 ++++ xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
It does not have side effects and is protected from concurrent changes by the P2M read lock therefore skip taking the domctl lock.
--- xen/arch/x86/domctl.c | 4 ++++ xen/common/domctl.c | 1 + 2 files changed, 5 insertions(+)
xen/arch/x86/domctl.c +4 -0
@@ -301,6 +301,10 @@ long arch_do_domctl(/* Games to allow this code block to handle a compat guest. */ void __user *guest_handle = domctl->u.getpageframeinfo3.array.p; + ret =xsm_domctl (XSM_OTHER , d, domctl); +if ( ret ) +break ; +if (unlikely (num >1024 ) ||unlikely (num != domctl->u.getpageframeinfo3.num) ) {
xen/common/domctl.c +1 -0
@@ -555,6 +555,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)case XEN_DOMCTL_gsi_permission:case XEN_DOMCTL_bind_pt_irq:case XEN_DOMCTL_unbind_pt_irq: +case XEN_DOMCTL_getpageframeinfo3: ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly;
Signature · 1 line
2.53.0
Re: [PATCH v1 1/2] domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
Quoted 4 lines · Ross Lagerwall
It does not have side effects and is protected from concurrent changes by the P2M read lock therefore skip taking the domctl lock.
Signed-off-by Ross Lagerwall <[email protected]>
Thanks, Roger.
Re: [PATCH v1 1/2] domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
In reply to Ross LagerwallQuoted 29 lines · Ross Lagerwall
It does not have side effects and is protected from concurrent changes by the P2M read lock therefore skip taking the domctl lock.
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/domctl.c | 4 ++++ xen/common/domctl.c | 1 + 2 files changed, 5 insertions(+)xen/arch/x86/domctl.c +4
-0@@ -301,6 +301,10 @@ long arch_do_domctl(/* Games to allow this code block to handle a compat guest. */ void __user *guest_handle = domctl->u.getpageframeinfo3.array.p; + ret =xsm_domctl (XSM_OTHER , d, domctl); +if ( ret ) +break ; +if (unlikely (num >1024 ) ||unlikely (num != domctl->u.getpageframeinfo3.num) ) {xen/common/domctl.c +0
-0
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 561
Quoted 7 lines
xen/common/domctl.c +1
-0@@ -555,6 +555,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)case XEN_DOMCTL_gsi_permission:case XEN_DOMCTL_bind_pt_irq:case XEN_DOMCTL_unbind_pt_irq: +case XEN_DOMCTL_getpageframeinfo3: ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly;
I would respectfully ask to be mindful when XSM hooks are being manipulated in a patch that a review from an XSM maintainer should be sought before committing a patch. In this case case the change itself is good, though I would have liked the opportunity to comment that the commit message should have had some explanation on the xsm change.
V/r,
Daniel P. Smith
Re: [PATCH v1 1/2] domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
Quoted 32 lines · Daniel P. Smith
Quoted 31 lines · Ross Lagerwall
It does not have side effects and is protected from concurrent changes by the P2M read lock therefore skip taking the domctl lock.
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/domctl.c | 4 ++++ xen/common/domctl.c | 1 + 2 files changed, 5 insertions(+)xen/arch/x86/domctl.c +4
-0@@ -301,6 +301,10 @@ long arch_do_domctl(/* Games to allow this code block to handle a compat guest. */ void __user *guest_handle = domctl->u.getpageframeinfo3.array.p; + ret =xsm_domctl (XSM_OTHER , d, domctl); +if ( ret ) +break ; +if (unlikely (num >1024 ) ||unlikely (num != domctl->u.getpageframeinfo3.num) ) {xen/common/domctl.c +0
-0@@ -555,6 +555,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)case XEN_DOMCTL_gsi_permission:case XEN_DOMCTL_bind_pt_irq:case XEN_DOMCTL_unbind_pt_irq:
Quoted 8 lines
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 560
Quoted 3 lines
xen/common/domctl.c +1
-0+case XEN_DOMCTL_getpageframeinfo3: ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly;I would respectfully ask to be mindful when XSM hooks are being manipulated in a patch that a review from an XSM maintainer should be sought before committing a patch. In this case case the change itself is good, though I would have liked the opportunity to comment that the commit message should have had some explanation on the xsm change.
I've already replied to 2/2, but would like to re-instate my apology here so it doesn't seem like this went unnoticed:
Sorry, this was already picked up in a rush to get it into 4.22 and I didn't realize it was missing an XSM maintainer Ack. That's entirely my fault, there was no intention to bypass or overrule your opinion.
Regards, Roger.
Re: [PATCH v1 1/2] domctl: Handle XEN_DOMCTL_getpageframeinfo3 without the domctl lock
Quoted 42 lines · Roger Pau Monné
Quoted 32 lines · Daniel P. Smith
Quoted 31 lines · Ross Lagerwall
It does not have side effects and is protected from concurrent changes by the P2M read lock therefore skip taking the domctl lock.
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/domctl.c | 4 ++++ xen/common/domctl.c | 1 + 2 files changed, 5 insertions(+)xen/arch/x86/domctl.c +4
-0@@ -301,6 +301,10 @@ long arch_do_domctl(/* Games to allow this code block to handle a compat guest. */ void __user *guest_handle = domctl->u.getpageframeinfo3.array.p; + ret =xsm_domctl (XSM_OTHER , d, domctl); +if ( ret ) +break ; +if (unlikely (num >1024 ) ||unlikely (num != domctl->u.getpageframeinfo3.num) ) {xen/common/domctl.c +0
-0@@ -555,6 +555,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)case XEN_DOMCTL_gsi_permission:case XEN_DOMCTL_bind_pt_irq:case XEN_DOMCTL_unbind_pt_irq:Quoted 8 lines
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 560
Quoted 3 lines
xen/common/domctl.c +1
-0+case XEN_DOMCTL_getpageframeinfo3: ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly;I would respectfully ask to be mindful when XSM hooks are being manipulated in a patch that a review from an XSM maintainer should be sought before committing a patch. In this case case the change itself is good, though I would have liked the opportunity to comment that the commit message should have had some explanation on the xsm change.
Quoted 6 lines
I've already replied to 2/2, but would like to re-instate my apology here so it doesn't seem like this went unnoticed:
Sorry, this was already picked up in a rush to get it into 4.22 and I didn't realize it was missing an XSM maintainer Ack. That's entirely my fault, there was no intention to bypass or overrule your opinion.
No worries, thank you for the apologies.
.
PATCH 2/2 domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
In reply to Ross LagerwallHandle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
* hvm_mapped_guest_frames_mark_dirty() - The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.
* domain_pause() - The toolstack cannot unpause the domain while in paging_log_dirty_op() because the toolstack's pause/unpause ops have a separate ref count.
* p2m_flush_hardware_cached_dirty() - This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.
* log_dirty.ops->clean() - If the callback is hap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback is sh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.
* domain_unpause() - Same as the earlier domain_pause().
--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)
xen/arch/x86/mm/paging.c +6 -2
@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;
xen/common/domctl.c +12 -0
@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op); +if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;default :/* Everything else handled further down. */ break ;
Signature · 1 line
2.53.0
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
Quoted 17 lines · Ross Lagerwall
Handle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
*
hvm_mapped_guest_frames_mark_dirty()- The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.*
domain_pause()- The toolstack cannot unpause the domain while inpaging_log_dirty_op()because the toolstack's pause/unpause ops have a separate ref count.*
p2m_flush_hardware_cached_dirty()- This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.
Quoted 6 lines
*
log_dirty.ops->clean()- If the callback ishap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback issh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.*
domain_unpause()- Same as the earlierdomain_pause().
You could join both into a single domain_{,un}pause() bullet point.
Quoted 2 lines
Signed-off-by Ross Lagerwall <[email protected]>
Quoted 37 lines
--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +6
-2@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;xen/common/domctl.c +2
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: + if ( op->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_CLEAN ||
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 573
Quoted 10 lines
xen/common/domctl.c +10
-0+ op->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op); +if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;
Newline, and I would use break rather than fallthrough, if further cases are added below you don't what to fallthrough, and there's nothing to do in the default case anyway.
See for example how this is similar to XEN_DOMCTL_vm_event_op which also handles some sub-ops without a lock and uses a break instead of a fallthrough.
FWIW, I would also put the XEN_DOMCTL_shadow_op case after XEN_DOMCTL_get_device_group and ahead of the XEN_DOMCTL_ioport_permission block, but that's just my taste.
Thanks, Roger.
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
Quoted 67 lines · Roger Pau Monné
Quoted 17 lines · Ross Lagerwall
Handle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
*
hvm_mapped_guest_frames_mark_dirty()- The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.*
domain_pause()- The toolstack cannot unpause the domain while inpaging_log_dirty_op()because the toolstack's pause/unpause ops have a separate ref count.*
p2m_flush_hardware_cached_dirty()- This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.Quoted 6 lines
*
log_dirty.ops->clean()- If the callback ishap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback issh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.*
domain_unpause()- Same as the earlierdomain_pause().You could join both into a single domain_{,un}pause() bullet point.
Quoted 2 lines
Signed-off-by Ross Lagerwall <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Quoted 35 lines
--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +6
-2@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;xen/common/domctl.c +0
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly;
Quoted 16 lines
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 573
Quoted 12 lines
xen/common/domctl.c +12
-0+case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op); +if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;Newline, and I would use break rather than fallthrough, if further cases are added below you don't what to fallthrough, and there's nothing to do in the default case anyway.
Yes, not sure what I was thinking here. break makes far more sense.
Can this adjustment be done when committing?
Quoted 8 lines
See for example how this is similar to
XEN_DOMCTL_vm_event_opwhich also handles some sub-ops without a lock and uses a break instead of a fallthrough.FWIW, I would also put the
XEN_DOMCTL_shadow_opcase afterXEN_DOMCTL_get_device_groupand ahead of theXEN_DOMCTL_ioport_permissionblock, but that's just my taste.
I don't have a preference here, either is fine.
Thanks,
Ross
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
In reply to Ross LagerwallQuoted 17 lines · Ross Lagerwall
Handle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
*
hvm_mapped_guest_frames_mark_dirty()- The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.*
domain_pause()- The toolstack cannot unpause the domain while inpaging_log_dirty_op()because the toolstack's pause/unpause ops have a separate ref count.*
p2m_flush_hardware_cached_dirty()- This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.
Quoted 6 lines
*
log_dirty.ops->clean()- If the callback ishap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback issh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.*
domain_unpause()- Same as the earlierdomain_pause().
Please add a comment that that xsm check is to continue protecting the sub-ops with XS_PRIV.
Quoted 41 lines
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +6
-2@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;xen/common/domctl.c +5
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op);
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 576
Quoted 10 lines
xen/common/domctl.c +7
-0+if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;default :/* Everything else handled further down. */ break ;
After commit message change,
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
Quoted 81 lines · Daniel P. Smith
Quoted 17 lines · Ross Lagerwall
Handle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
*
hvm_mapped_guest_frames_mark_dirty()- The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.*
domain_pause()- The toolstack cannot unpause the domain while inpaging_log_dirty_op()because the toolstack's pause/unpause ops have a separate ref count.*
p2m_flush_hardware_cached_dirty()- This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.Quoted 6 lines
*
log_dirty.ops->clean()- If the callback ishap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback issh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.*
domain_unpause()- Same as the earlierdomain_pause().Please add a comment that that xsm check is to continue protecting the sub-ops with
XS_PRIV.Quoted 39 lines
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +6
-2@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;xen/common/domctl.c +5
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op);xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 575
Quoted 10 lines
xen/common/domctl.c +7
-0+if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;default :/* Everything else handled further down. */ break ;After commit message change,
Quoted 1 line
Acked-by Daniel P. Smith <[email protected]>
Sorry, this was already picked up in a rush to get it into 4.22 and I didn't realize it was missing an XSM maintainer Ack. That's entirely my fault, there was no intention to bypass or overrule your opinion.
Given it's already committed, and there are no objections aside from the commit message adjustment my preference would be to leave it alone.
Regards, Roger.
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
Quoted 82 lines · Roger Pau Monné
Quoted 81 lines · Daniel P. Smith
Quoted 17 lines · Ross Lagerwall
Handle XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} without taking the domctl lock. This is safe because for these subops, the paging lock is mostly held which prevents it from operating concurrently on the same domain. There are some parts that are called without the paging lock held:
*
hvm_mapped_guest_frames_mark_dirty()- The function itself takes a spinlock so is protected from concurrent calls. In any case, it will mark all the pages dirty as required.*
domain_pause()- The toolstack cannot unpause the domain while inpaging_log_dirty_op()because the toolstack's pause/unpause ops have a separate ref count.*
p2m_flush_hardware_cached_dirty()- This is called elsewhere without the domctl lock held so holding it wouldn't achieve anything. It should be fine as long as it is called at least once.Quoted 6 lines
*
log_dirty.ops->clean()- If the callback ishap_clean_dirty_bitmap(), then it will hold the p2m lock while modifying the table. If the callback issh_clean_dirty_bitmap(), it will hold the paging lock while modifying the table. In both cases, this is OK.*
domain_unpause()- Same as the earlierdomain_pause().Please add a comment that that xsm check is to continue protecting the sub-ops with
XS_PRIV.Quoted 39 lines
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)xen/arch/x86/mm/paging.c +6
-2@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ); + +if ( !lock ||domctl_lock_acquire () ) { ret =paging_domctl (d, &op.u.shadow_op, u_domctl,1 ); -domctl_lock_release (); +if ( lock ) +domctl_lock_release (); }else ret = -ERESTART ;xen/common/domctl.c +5
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op);xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 575
Quoted 10 lines
xen/common/domctl.c +7
-0+if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;default :/* Everything else handled further down. */ break ;After commit message change,
Quoted 5 lines
Quoted 1 line
Acked-by Daniel P. Smith <[email protected]>Sorry, this was already picked up in a rush to get it into 4.22 and I didn't realize it was missing an XSM maintainer Ack. That's entirely my fault, there was no intention to bypass or overrule your opinion.
I fully understand and take no offense.
Quoted 3 lines
Given it's already committed, and there are no objections aside from the commit message adjustment my preference would be to leave it alone.
Hmm, I saw patch 1 but not patch 2. Sorry for the extra noise.
v/r,
dps
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
In reply to Ross Lagerwallxen/arch/x86/mm/paging.c long do_paging_domctl_cont( · line 750
Quoted 9 lines · Ross Lagerwall
xen/arch/x86/mm/paging.c +2
-1@@ -746,11 +746,15 @@ long do_paging_domctl_cont( ret =xsm_domctl (XSM_OTHER , d, &op);if ( !ret ) { -if (domctl_lock_acquire () ) +bool lock = !(op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op.u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK );
I realize this has been committed already, yet I'd still like to mention that I never really understood why expressions like this (with a negation which can easily be avoided:
bool lock = op.u.shadow_op.op != XEN_DOMCTL_SHADOW_OP_CLEAN &&
op.u.shadow_op.op != XEN_DOMCTL_SHADOW_OP_PEEK;) would be used. Personally I consider such hampering readability. And no, the other expression (in do_domctl()) being
if ( op->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_CLEAN ||
op->u.shadow_op.op == XEN_DOMCTL_SHADOW_OP_PEEK )imo doesn't justify that either: While in the patch they're close together and hence the analogy can be easily spotted, in the ultimate source files the two expressions are far apart.
Jan
Re: [PATCH v1 2/2] domctl: Handle some of XEN_DOMCTL_shadow_op without the domctl lock
In reply to Ross LagerwallQuoted 11 lines · Ross Lagerwall
xen/common/domctl.c +5
-0@@ -559,6 +559,18 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) ret =arch_do_domctl (op, d, u_domctl); goto domctl_out_unlock_domonly; +case XEN_DOMCTL_shadow_op: +if ( op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_CLEAN || + op->u.shadow_op.op ==XEN_DOMCTL_SHADOW_OP_PEEK ) + { + ret =xsm_domctl (XSM_OTHER , d, op);
xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 576
Quoted 10 lines
xen/common/domctl.c +7
-0+if ( ret ) + goto domctl_out_unlock_domonly; + + ret =arch_do_domctl (op, d, u_domctl); + goto domctl_out_unlock_domonly; + } + fallthrough;default :/* Everything else handled further down. */ break ;
I understand this did already go in as is, yet I have to admit I'm surprised that it was ack-ed in this shape. For "domctl: handle XEN_DOMCTL_getvcpuinfo without acquiring domctl lock" [1] it was specifically requested that I introduce yet another switch(), to limit the number of xsm_domctl() call sites. IOW I think subsequently this case block wants moving into the new switch() that the referenced patch introduces.
Jan
[1] https://lists.xen.org/archives/html/xen-devel/2026-06/msg00857.html
Quoted 14 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Quoted 9 lines
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock
domctl: Handle some ofXEN_DOMCTL_shadow_opwithout the domctl lockxen/arch/x86/domctl.c | 4 ++++ xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
I'd like to request inclusion of this in 4.22 since it fixes a real customer issue we have observed and would have been posted some time ago but was delayed to avoid drawing attention to and colliding with XSA-492.
Thanks,
Ross
Quoted 25 lines · Ross Lagerwall
Quoted 14 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Quoted 9 lines
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock
domctl: Handle some ofXEN_DOMCTL_shadow_opwithout the domctl lockxen/arch/x86/domctl.c | 4 ++++
xen/arch/x86/mm/paging.c| 8 ++++++--
xen/common/domctl.c | 13 +++++++++++++3 files changed, 23 insertions(+), 2 deletions(-)
Quoted 4 lines
I'd like to request inclusion of this in 4.22 since it fixes a real customer issue we have observed and would have been posted some time ago but was delayed to avoid drawing attention to and colliding with XSA-492.
Considering this and performance improvements it would be really nice to have in in 4.22:
Thanks.
~ Oleksii
Quoted 5 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
Does "xl vcpu-list" involve ...
Quoted 11 lines
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock
... XEN_DOMCTL_getpageframeinfo3?
Jan
Quoted 7 lines
domctl: Handle some of
XEN_DOMCTL_shadow_opwithout the domctl lockxen/arch/x86/domctl.c | 4 ++++ xen/arch/x86/mm/paging.c | 8 ++++++-- xen/common/domctl.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
Does "xl vcpu-list" involve ...
Quoted 7 lines
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Quoted 7 lines
Quoted 4 lines
Thanks
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock...
XEN_DOMCTL_getpageframeinfo3?
No, but "xl vcpu-list" takes the domctl lock and this contends with XEN_DOMCTL_getpageframeinfo3 and XEN_DOMCTL_shadow_op taking the domctl lock which are called frequently by the migration process(es).
Various other operations were slow due to the domctl lock contention but "xl vcpu-list" was the most obviously visible example.
Ross
Quoted 19 lines · Ross Lagerwall
Quoted 18 lines · Jan Beulich
Quoted 5 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
Does "xl vcpu-list" involve ...
Quoted 9 lines
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock...
XEN_DOMCTL_getpageframeinfo3?No, but "xl vcpu-list" takes the domctl lock
If this is still the case after XSA-492, then maybe the follow-ups I have pending to post will eliminate (or at least reduce) this. I don't think that's 4.22 material, though.
Quoted 6 lines
and this contends with
XEN_DOMCTL_getpageframeinfo3andXEN_DOMCTL_shadow_optaking the domctl lock which are called frequently by the migration process(es).Various other operations were slow due to the domctl lock contention but "xl vcpu-list" was the most obviously visible example.
I see.
Jan
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Ross Lagerwall
Quoted 21 lines · Jan Beulich
Quoted 5 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
Does "xl vcpu-list" involve ...
Quoted 11 lines
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Thanks
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
...
XEN_DOMCTL_getpageframeinfo3?No, but "xl vcpu-list" takes the domctl lock
If this is still the case after XSA-492, then maybe the follow-ups I have pending to post will eliminate (or at least reduce) this. I don't think that's 4.22 material, though.
Yes, AFAICT "xl vcpu-list" calls XEN_DOMCTL_getvcpuinfo and XEN_DOMCTL_getvcpuaffinity for each domain and both of these still take the domctl lock.
Ross
Quoted 29 lines · Ross Lagerwall
Quoted 28 lines · Jan Beulich
Quoted 26 lines · Ross Lagerwall
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Ross Lagerwall
When performing multiple migrations in parallel, the domctl lock may become extremely contended:
* Operations like "xl vcpu-list" were observed to take in excess of 20s to execute.
Does "xl vcpu-list" involve ...
Quoted 7 lines
* The "clean" shadow op may pause the domain, restart with a continuation and then become blocked on the domctl lock, causing VM downtime in excess of 20 seconds.
These issues can be fixed by not holding the domctl for the frequently called operations during migration.
Quoted 7 lines
Quoted 4 lines
Thanks
Ross Lagerwall (2):
domctl: HandleXEN_DOMCTL_getpageframeinfo3without the domctl lock...
XEN_DOMCTL_getpageframeinfo3?No, but "xl vcpu-list" takes the domctl lock
Quoted 7 lines
Quoted 3 lines
If this is still the case after XSA-492, then maybe the follow-ups I have pending to post will eliminate (or at least reduce) this. I don't think that's 4.22 material, though.
Yes, AFAICT "xl vcpu-list" calls
XEN_DOMCTL_getvcpuinfoandXEN_DOMCTL_getvcpuaffinityfor each domain and both of these still take the domctl lock.
XEN_DOMCTL_getvcpuinfo is taken care of by my to-be-posted follow-on. XEN_DOMCTL_[gs]etvcpuaffinity first need to have their own locking added, before their handling can be moved out.
Jan