xen/smp: Support NULL IPI function pointers
PATCH 1/1 xen/smp: Support NULL IPI function pointers
There are several cases where the act of interrupting a remote processor has the required side effect. Explicitly allow NULL function pointers so the calling code doesn't have to provide a stub implementation.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
The wait parameter is a little weird. It serves double duty and will confirm that the IPI has been taken. All it does is let you control whether you also wait for the handler to complete first. As such, it is effectively useless with a stub function.
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else if() and adding a 3rd cpumask_clear_cpu() into the confusion which is this logic.
--- xen/arch/x86/mm/hap/hap.c | 11 +---------- xen/arch/x86/mm/p2m-ept.c | 11 ++--------- xen/common/smp.c | 4 ++++ 3 files changed, 7 insertions(+), 19 deletions(-)
xen/arch/x86/mm/hap/hap.c +1 -10
@@ -696,15 +696,6 @@ static void hap_update_cr3(struct vcpu *v, int do_locking, bool noflush)hvm_update_guest_cr3 (v, noflush); } -/* -* Dummy function to use with on_selected_cpus in order to trigger a vmexit on -* selected pCPUs. When the VM resumes execution it will get a new ASID/VPID -* and thus a clean TLB. -*/ -static void dummy_flush (void *data) -{ -} -static bool flush_tlb (bool (*flush_vcpu)(void *ctxt,struct vcpu *v),void *ctxt) {
@@ -737,7 +728,7 @@ static bool flush_tlb(bool (*flush_vcpu)(void *ctxt, struct vcpu *v),* not currently running will already be flushed when scheduled because of * the ASID tickle done in the loop above. */ -on_selected_cpus (mask, dummy_flush,NULL ,0 ); +on_selected_cpus (mask,NULL ,NULL ,0 );return true; }
xen/arch/x86/mm/p2m-ept.c +2 -9
@@ -1236,14 +1236,6 @@ static void ept_memory_type_changed(struct p2m_domain *p2m)ept_sync_domain (p2m); } -static void __ept_sync_domain (void *info) -{ -/* -* The invalidation will be done before VMENTER (see -* vmx_vmenter_helper()). -*/ -} -static void ept_sync_domain_prepare (struct p2m_domain *p2m) {struct domain *d = p2m->domain;
@@ -1269,7 +1261,8 @@ static void ept_sync_domain_prepare(struct p2m_domain *p2m)static void ept_sync_domain_mask (struct p2m_domain *p2m,const cpumask_t *mask) { -on_selected_cpus (mask, __ept_sync_domain, p2m,1 ); +/* Invalidation will be done in vmx_vmenter_helper(). */ +on_selected_cpus (mask,NULL ,NULL ,1 ); }void ept_sync_domain (struct p2m_domain *p2m)
xen/common/smp.c +4 -0
@@ -87,10 +87,14 @@ void smp_call_function_interrupt(void)irq_enter (); +if (unlikely (!func) ) + goto no_func; +if ( call_data.wait ) { (*func)(info);smp_mb (); + no_func:cpumask_clear_cpu (cpu, &call_data.selected); }else
Signature · 1 line
2.11.0
Hi Andrew,
Quoted 91 lines · Andrew Cooper
There are several cases where the act of interrupting a remote processor has the required side effect. Explicitly allow NULL function pointers so the calling code doesn't have to provide a stub implementation.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>The wait parameter is a little weird. It serves double duty and will confirm that the IPI has been taken. All it does is let you control whether you also wait for the handler to complete first. As such, it is effectively useless with a stub function.
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()into the confusion which is this logic.--- xen/arch/x86/mm/hap/hap.c | 11 +---------- xen/arch/x86/mm/p2m-ept.c | 11 ++--------- xen/common/smp.c | 4 ++++ 3 files changed, 7 insertions(+), 19 deletions(-)xen/arch/x86/mm/hap/hap.c +1
-10@@ -696,15 +696,6 @@ static void hap_update_cr3(struct vcpu *v, int do_locking, bool noflush)hvm_update_guest_cr3 (v, noflush); } -/* -* Dummy function to use with on_selected_cpus in order to trigger a vmexit on -* selected pCPUs. When the VM resumes execution it will get a new ASID/VPID -* and thus a clean TLB. -*/ -static void dummy_flush (void *data) -{ -} -static bool flush_tlb (bool (*flush_vcpu)(void *ctxt,struct vcpu *v),void *ctxt) {@@ -737,7 +728,7 @@ static bool flush_tlb(bool (*flush_vcpu)(void *ctxt, struct vcpu *v),* not currently running will already be flushed when scheduled because of * the ASID tickle done in the loop above. */ -on_selected_cpus (mask, dummy_flush,NULL ,0 ); +on_selected_cpus (mask,NULL ,NULL ,0 );return true; }xen/arch/x86/mm/p2m-ept.c +2
-9@@ -1236,14 +1236,6 @@ static void ept_memory_type_changed(struct p2m_domain *p2m)ept_sync_domain (p2m); } -static void __ept_sync_domain (void *info) -{ -/* -* The invalidation will be done before VMENTER (see -* vmx_vmenter_helper()). -*/ -} -static void ept_sync_domain_prepare (struct p2m_domain *p2m) {struct domain *d = p2m->domain;@@ -1269,7 +1261,8 @@ static void ept_sync_domain_prepare(struct p2m_domain *p2m)static void ept_sync_domain_mask (struct p2m_domain *p2m,const cpumask_t *mask) { -on_selected_cpus (mask, __ept_sync_domain, p2m,1 ); +/* Invalidation will be done in vmx_vmenter_helper(). */ +on_selected_cpus (mask,NULL ,NULL ,1 ); }void ept_sync_domain (struct p2m_domain *p2m)xen/common/smp.c +1
-0@@ -87,10 +87,14 @@ void smp_call_function_interrupt(void)irq_enter (); +if (unlikely (!func) )
xen/common/smp.c void smp_call_function_interrupt(void) · line 100
Quoted 10 lines
xen/common/smp.c +3
-0+ goto no_func; +if ( call_data.wait ) { (*func)(info);smp_mb (); + no_func:cpumask_clear_cpu (cpu, &call_data.selected); }else
Why only apply to call_data.wait non-zero case?
Is it because func will not be NULL when call_data.wait is zero?
Quoted 1 line
Quoted 7 lines · Wei Chen
Quoted 6 lines · Andrew Cooper
xen/common/smp.c +0
-0@@ -87,10 +87,14 @@ void smp_call_function_interrupt(void)irq_enter ();
Quoted 14 lines
xen/common/smp.c void smp_call_function_interrupt(void) · line 100
Quoted 11 lines
xen/common/smp.c +4
-0+if (unlikely (!func) ) + goto no_func; +if ( call_data.wait ) { (*func)(info);smp_mb (); + no_func:cpumask_clear_cpu (cpu, &call_data.selected); }else Why only apply to call_data.wait non-zero case?
Is it because func will not be NULL when call_data.wait is zero?
No. call_data.wait is irrelevant when no function is to be called. If you look at the "else" branch, all that would be needed there is again just the cpumask_clear_cpu() invocation. Hence easiest to wire it like Andrew did (leaving aside my personal dislike of goto).
Jan
Quoted 106 lines · Wei Chen
Hi Andrew,
Quoted 103 lines · Andrew Cooper
There are several cases where the act of interrupting a remote processor has
the required side effect. Explicitly allow NULL function pointers so the
calling code doesn't have to provide a stub implementation.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>The wait parameter is a little weird. It serves double duty and will confirm
that the IPI has been taken. All it does is let you control whether you also
wait for the handler to complete first. As such, it is effectively useless
with a stub function.I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()
into the confusion which is this logic.
---
xen/arch/x86/mm/hap/hap.c| 11 +----------xen/arch/x86/mm/p2m-ept.c| 11 ++--------- xen/common/smp.c | 4 ++++3 files changed, 7 insertions(+), 19 deletions(-)xen/arch/x86/mm/hap/hap.c +0
-0@@ -696,15 +696,6 @@ static void hap_update_cr3(struct vcpu *v, int do_locking, bool noflush) hvm_update_guest_cr3(v, noflush); }-/*
- * Dummy function to use withon_selected_cpusin order to trigger a vmexit on
- * selected pCPUs. When the VM resumes execution it will get a new ASID/VPID
- * and thus a clean TLB.
- */xen/arch/x86/mm/hap/hap.c +0
-4-static void dummy_flush (void *data) -{ -} -static bool
flush_tlb(bool (*flush_vcpu)(void *ctxt, struct vcpu *v), void *ctxt)
{xen/arch/x86/mm/hap/hap.c +0
-0@@ -737,7 +728,7 @@ static bool flush_tlb(bool (*flush_vcpu)(void *ctxt, struct vcpu *v), * not currently running will already be flushed when scheduledbecause of
* the ASID tickle done in the loop above. */
-on_selected_cpus(mask, dummy_flush, NULL, 0); +on_selected_cpus(mask, NULL, NULL, 0); return true;
}xen/arch/x86/mm/p2m-ept.c +0
-7@@ -1236,14 +1236,6 @@ static void ept_memory_type_changed(struct p2m_domain *p2m) ept_sync_domain(p2m); } -static void __ept_sync_domain(void *info) -{ - /* -* The invalidation will be done before VMENTER (see -* vmx_vmenter_helper()). -*/ -} - static void ept_sync_domain_prepare(struct p2m_domain *p2m) {struct domain *d =
p2m->domain;xen/arch/x86/mm/p2m-ept.c +0
-0@@ -1269,7 +1261,8 @@ static void ept_sync_domain_prepare(struct p2m_domain *p2m)static void
ept_sync_domain_mask(struct p2m_domain *p2m, const cpumask_t *mask)
{
-on_selected_cpus(mask, __ept_sync_domain, p2m, 1); + /* Invalidation will be done invmx_vmenter_helper(). */ +on_selected_cpus(mask, NULL, NULL, 1);
}
voidept_sync_domain(struct p2m_domain *p2m)xen/common/smp.c +2
-0@@ -87,10 +87,14 @@ void smp_call_function_interrupt(void) irq_enter(); + if ( unlikely(!func) ) + goto no_func; + if ( call_data.wait ) { (*func)(info);
Quoted 8 lines
Quoted 5 lines
xen/common/smp.c +1
-0smp_mb(); + no_func: cpumask_clear_cpu(cpu, &call_data.selected); }else
Why only apply to call_data.wait non-zero case?
Is it because func will not be NULL when call_data.wait is zero?
This was explicitly discussed:
Quoted 8 lines
The wait parameter is a little weird. It serves double duty and will confirm
that the IPI has been taken. All it does is let you control whether you also
wait for the handler to complete first. As such, it is effectively useless
with a stub function.
Quoted 4 lines
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()
into the confusion which is this logic.
~Andrew
Quoted 10 lines · Andrew Cooper
There are several cases where the act of interrupting a remote processor has the required side effect. Explicitly allow NULL function pointers so the calling code doesn't have to provide a stub implementation.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
Quoted 8 lines
The wait parameter is a little weird. It serves double duty and will confirm that the IPI has been taken. All it does is let you control whether you also wait for the handler to complete first. As such, it is effectively useless with a stub function.
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()into the confusion which is this logic.
I can accept this, albeit personally I would have preferred the extra if() over the goto.
Jan
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
There are several cases where the act of interrupting a remote processor has the required side effect. Explicitly allow NULL function pointers so the calling code doesn't have to provide a stub implementation.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>The wait parameter is a little weird. It serves double duty and will confirm that the IPI has been taken. All it does is let you control whether you also wait for the handler to complete first. As such, it is effectively useless with a stub function.
Quoted 5 lines
Quoted 3 lines
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()into the confusion which is this logic.I can accept this, albeit personally I would have preferred the extra
if()over the goto.
Just so it's been posted. This is what the if/else looks like:
xen/common/smp.c +0 -0
@@ -87,7 +87,11 @@ void smp_call_function_interrupt(void)
irq_enter();
- if ( call_data.wait )
+ if ( unlikely(!func) )
+ {
+ cpumask_clear_cpu(cpu, &call_data.selected); + }
+ else if ( call_data.wait )
{
(*func)(info);
smp_mb();
GCC does manage to fold this into the goto version presented originally.
If everyone else thinks this version is clearer to read then I'll go with it.
~Andrew
Hi Andrew,
Quoted 61 lines
-----Original Message-----
From: Andrew Cooper <[email protected]>
Sent: 2021年11月18日 18:35
To: Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Chen <[email protected]>
Cc: Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; Xen- devel <[email protected]>
Subject: Re: [PATCH] xen/smp: Support NULL IPI function pointersQuoted 2 lines · Jan Beulich
Quoted 1 line · Andrew Cooper
There are several cases where the act of interrupting a remote
processor has
Quoted 1 line
Quoted 1 line
the required side effect. Explicitly allow NULL function pointers so
the
Quoted 9 lines
Quoted 9 lines
calling code doesn't have to provide a stub implementation.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>The wait parameter is a little weird. It serves double duty and will
confirm
Quoted 1 line
Quoted 1 line
that the IPI has been taken. All it does is let you control whether
you also
Quoted 1 line
Quoted 1 line
wait for the handler to complete first. As such, it is effectively
useless
Quoted 3 lines
Quoted 3 lines
with a stub function.
I don't particularly like folding into the .wait() path like that, but
I
Quoted 1 line
Quoted 1 line
dislike it less than an if()/else
if()and adding a 3rd
cpumask_clear_cpu()Quoted 2 lines
Quoted 1 line
into the confusion which is this logic.
I can accept this, albeit personally I would have preferred the extra
if()Quoted 1 line
over the goto.
Just so it's been posted. This is what the if/else looks like:
xen/common/smp.c +5
-1@@ -87,7 +87,11 @@ void smp_call_function_interrupt(void) irq_enter(); - if ( call_data.wait ) + if ( unlikely(!func) ) + { + cpumask_clear_cpu(cpu, &call_data.selected); + } + else if ( call_data.wait ) { (*func)(info); smp_mb();
Quoted 4 lines
GCC does manage to fold this into the goto version presented originally.
If everyone else thinks this version is clearer to read then I'll go with it.
This version is much clearer to read. But if there will be some code comments in goto version to make it easy to read. I am ok for either.
Quoted 2 lines
~Andrew
Quoted 48 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
There are several cases where the act of interrupting a remote processor has the required side effect. Explicitly allow NULL function pointers so the calling code doesn't have to provide a stub implementation.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>The wait parameter is a little weird. It serves double duty and will confirm that the IPI has been taken. All it does is let you control whether you also wait for the handler to complete first. As such, it is effectively useless with a stub function.
Quoted 5 lines
Quoted 3 lines
I don't particularly like folding into the .wait() path like that, but I dislike it less than an if()/else
if()and adding a 3rdcpumask_clear_cpu()into the confusion which is this logic.I can accept this, albeit personally I would have preferred the extra
if()over the goto.Just so it's been posted. This is what the if/else looks like:
xen/common/smp.c +5
-1@@ -87,7 +87,11 @@ void smp_call_function_interrupt(void)irq_enter (); -if ( call_data.wait ) +if (unlikely (!func) ) + { +cpumask_clear_cpu (cpu, &call_data.selected); + } +else if ( call_data.wait ) { (*func)(info);smp_mb ();
Quoted 4 lines
GCC does manage to fold this into the goto version presented originally.
If everyone else thinks this version is clearer to read then I'll go with it.
Hi Andrew,
I would vote for the long version if it’s not a problem.
Cheers,
Luca
Quoted 2 lines
~Andrew