linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself
       [not found] <20210908194243.238523-1-wei.liu@kernel.org>
@ 2021-09-08 19:42 ` Wei Liu
  2021-09-09  5:38   ` Vitaly Kuznetsov
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Liu @ 2021-09-08 19:42 UTC (permalink / raw)
  To: Linux on Hyper-V List
  Cc: Michael Kelley, kys, haiyangz, decui, sthemmin, Wei Liu,
	Arnd Bergmann, open list:GENERIC INCLUDE/ASM HEADER FILES,
	open list

This is a new variant which removes `self' cpu from the vpset. It will
be used in Hyper-V enlightened IPI code.

Signed-off-by: Wei Liu <wei.liu@kernel.org>
---
Provide a new variant instead of adding a new parameter because it makes
it easier to backport -- we don't need to fix the users of
cpumask_to_vpset.
---
 include/asm-generic/mshyperv.h | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index 9a000ba2bb75..d89690ee95aa 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -184,10 +184,12 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)
 	return hv_vp_index[cpu_number];
 }
 
-static inline int cpumask_to_vpset(struct hv_vpset *vpset,
-				    const struct cpumask *cpus)
+static inline int cpumask_to_vpset_ex(struct hv_vpset *vpset,
+				    const struct cpumask *cpus,
+				    bool exclude_self)
 {
 	int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
+	int this_cpu = smp_processor_id();
 
 	/* valid_bank_mask can represent up to 64 banks */
 	if (hv_max_vp_index / 64 >= 64)
@@ -205,6 +207,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
 	 * Some banks may end up being empty but this is acceptable.
 	 */
 	for_each_cpu(cpu, cpus) {
+		if (exclude_self && cpu == this_cpu)
+			continue;
 		vcpu = hv_cpu_number_to_vp_number(cpu);
 		if (vcpu == VP_INVAL)
 			return -1;
@@ -219,6 +223,18 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
 	return nr_bank;
 }
 
+static inline int cpumask_to_vpset(struct hv_vpset *vpset,
+				    const struct cpumask *cpus)
+{
+	return cpumask_to_vpset_ex(vpset, cpus, false);
+}
+
+static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset,
+				    const struct cpumask *cpus)
+{
+	return cpumask_to_vpset_ex(vpset, cpus, true);
+}
+
 void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);
 bool hv_is_hyperv_initialized(void);
 bool hv_is_hibernation_supported(void);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself
  2021-09-08 19:42 ` [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself Wei Liu
@ 2021-09-09  5:38   ` Vitaly Kuznetsov
  2021-09-09 10:25     ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-09  5:38 UTC (permalink / raw)
  To: Wei Liu, Linux on Hyper-V List
  Cc: Michael Kelley, kys, haiyangz, decui, sthemmin, Wei Liu,
	Arnd Bergmann, open list:GENERIC INCLUDE/ASM HEADER FILES,
	open list

Wei Liu <wei.liu@kernel.org> writes:

> This is a new variant which removes `self' cpu from the vpset. It will
> be used in Hyper-V enlightened IPI code.
>
> Signed-off-by: Wei Liu <wei.liu@kernel.org>
> ---
> Provide a new variant instead of adding a new parameter because it makes
> it easier to backport -- we don't need to fix the users of
> cpumask_to_vpset.
> ---
>  include/asm-generic/mshyperv.h | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index 9a000ba2bb75..d89690ee95aa 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -184,10 +184,12 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)
>  	return hv_vp_index[cpu_number];
>  }
>  
> -static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> -				    const struct cpumask *cpus)
> +static inline int cpumask_to_vpset_ex(struct hv_vpset *vpset,

I'd suggest to avoid '_ex' suffix as we use it for 'extended hypercalls'
(e.g. __send_ipi_mask_ex). Assuming nobody needs to call
cpumask_to_vpset_ex() directly, should we just go with
__cpumask_to_vpset() instead?

> +				    const struct cpumask *cpus,
> +				    bool exclude_self)
>  {
>  	int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
> +	int this_cpu = smp_processor_id();
>  
>  	/* valid_bank_mask can represent up to 64 banks */
>  	if (hv_max_vp_index / 64 >= 64)
> @@ -205,6 +207,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
>  	 * Some banks may end up being empty but this is acceptable.
>  	 */
>  	for_each_cpu(cpu, cpus) {
> +		if (exclude_self && cpu == this_cpu)
> +			continue;
>  		vcpu = hv_cpu_number_to_vp_number(cpu);
>  		if (vcpu == VP_INVAL)
>  			return -1;
> @@ -219,6 +223,18 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
>  	return nr_bank;
>  }
>  
> +static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> +				    const struct cpumask *cpus)
> +{
> +	return cpumask_to_vpset_ex(vpset, cpus, false);
> +}
> +
> +static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset,
> +				    const struct cpumask *cpus)
> +{
> +	return cpumask_to_vpset_ex(vpset, cpus, true);


We need to make sure this is called with preemption disabled. We
could've just swapped smp_processor_id() for get_cpu() in
cpumask_to_vpset_ex() but this is hardly a solution: we can get
preempted right after put_cpu() so it's really the caller of this
function which needs to be protected.

TL;DR: I suggest we add 'WARN_ON_ONCE(preemptible());' or something like
this here to catch wrong usage.

> +}
> +
>  void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);
>  bool hv_is_hyperv_initialized(void);
>  bool hv_is_hibernation_supported(void);

-- 
Vitaly


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself
  2021-09-09  5:38   ` Vitaly Kuznetsov
@ 2021-09-09 10:25     ` Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2021-09-09 10:25 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: Wei Liu, Linux on Hyper-V List, Michael Kelley, kys, haiyangz,
	decui, sthemmin, Arnd Bergmann,
	open list:GENERIC INCLUDE/ASM HEADER FILES, open list

On Thu, Sep 09, 2021 at 07:38:28AM +0200, Vitaly Kuznetsov wrote:
> Wei Liu <wei.liu@kernel.org> writes:
> 
> > This is a new variant which removes `self' cpu from the vpset. It will
> > be used in Hyper-V enlightened IPI code.
> >
> > Signed-off-by: Wei Liu <wei.liu@kernel.org>
> > ---
> > Provide a new variant instead of adding a new parameter because it makes
> > it easier to backport -- we don't need to fix the users of
> > cpumask_to_vpset.
> > ---
> >  include/asm-generic/mshyperv.h | 20 ++++++++++++++++++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> > index 9a000ba2bb75..d89690ee95aa 100644
> > --- a/include/asm-generic/mshyperv.h
> > +++ b/include/asm-generic/mshyperv.h
> > @@ -184,10 +184,12 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)
> >  	return hv_vp_index[cpu_number];
> >  }
> >  
> > -static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> > -				    const struct cpumask *cpus)
> > +static inline int cpumask_to_vpset_ex(struct hv_vpset *vpset,
> 
> I'd suggest to avoid '_ex' suffix as we use it for 'extended hypercalls'
> (e.g. __send_ipi_mask_ex). Assuming nobody needs to call
> cpumask_to_vpset_ex() directly, should we just go with
> __cpumask_to_vpset() instead?

Sure. I'm not too fussed about the name.

I will wait a bit for other people to express their opinions.

> 
> > +				    const struct cpumask *cpus,
> > +				    bool exclude_self)
> >  {
> >  	int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
> > +	int this_cpu = smp_processor_id();
> >  
> >  	/* valid_bank_mask can represent up to 64 banks */
> >  	if (hv_max_vp_index / 64 >= 64)
> > @@ -205,6 +207,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> >  	 * Some banks may end up being empty but this is acceptable.
> >  	 */
> >  	for_each_cpu(cpu, cpus) {
> > +		if (exclude_self && cpu == this_cpu)
> > +			continue;
> >  		vcpu = hv_cpu_number_to_vp_number(cpu);
> >  		if (vcpu == VP_INVAL)
> >  			return -1;
> > @@ -219,6 +223,18 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> >  	return nr_bank;
> >  }
> >  
> > +static inline int cpumask_to_vpset(struct hv_vpset *vpset,
> > +				    const struct cpumask *cpus)
> > +{
> > +	return cpumask_to_vpset_ex(vpset, cpus, false);
> > +}
> > +
> > +static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset,
> > +				    const struct cpumask *cpus)
> > +{
> > +	return cpumask_to_vpset_ex(vpset, cpus, true);
> 
> 
> We need to make sure this is called with preemption disabled. We
> could've just swapped smp_processor_id() for get_cpu() in
> cpumask_to_vpset_ex() but this is hardly a solution: we can get
> preempted right after put_cpu() so it's really the caller of this
> function which needs to be protected.
> 
> TL;DR: I suggest we add 'WARN_ON_ONCE(preemptible());' or something like
> this here to catch wrong usage.

Good suggestion. I can add this check to the noself variant. Or if
people prefer, this check can also be moved into the leaf helper.

Wei.

> 
> > +}
> > +
> >  void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);
> >  bool hv_is_hyperv_initialized(void);
> >  bool hv_is_hibernation_supported(void);
> 
> -- 
> Vitaly
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-09 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210908194243.238523-1-wei.liu@kernel.org>
2021-09-08 19:42 ` [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself Wei Liu
2021-09-09  5:38   ` Vitaly Kuznetsov
2021-09-09 10:25     ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).