linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu@kernel.org>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Wei Liu <wei.liu@kernel.org>,
	Michael Kelley <mikelley@microsoft.com>,
	kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com,
	sthemmin@microsoft.com,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" 
	<linux-kernel@vger.kernel.org>,
	Linux on Hyper-V List <linux-hyperv@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself
Date: Wed, 6 Oct 2021 11:39:13 +0000	[thread overview]
Message-ID: <20211006113913.c2ubc7bokgokoc6q@liuwe-devbox-debian-v2> (raw)
In-Reply-To: <87k0ir63au.fsf@vitty.brq.redhat.com>

Hi Thomas and Vitaly

Sorry for the late reply. I was buried in my other work.

On Tue, Oct 05, 2021 at 02:53:29PM +0200, Vitaly Kuznetsov wrote:
> Thomas Gleixner <tglx@linutronix.de> writes:
> 
> > Wei!
> >
> 
> Not Wei here but I don't see the question answered on the mailing list
> so let me give my thoughts.
> 
> > On Fri, Sep 10 2021 at 18:57, Wei Liu wrote:
> >> -static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector)
> >> +static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector,
> >> +		bool exclude_self)
> >>  {
> >>  	struct hv_send_ipi_ex **arg;
> >>  	struct hv_send_ipi_ex *ipi_arg;
> >> @@ -123,7 +124,10 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector)
> >>  
> >>  	if (!cpumask_equal(mask, cpu_present_mask)) {
> >
> > Not part of that patch, but is checking cpu_present_mask correct here?
> > If so then this really lacks a comment for the casual reader.
> 
> It seems it *was* correct prior to 'exclude_self': the idea is that for
> everything but 'cpu_present_mask' we use HV_GENERIC_SET_SPARSE_4K
> format, for 'cpu_present_mask' we just use 'all' (HV_GENERIC_SET_ALL)
> to avoid specifying individual CPUs. 

Yes, that's the intent.

It was correct before because cpumask would have been filtered to
exclude "self" when it came to this function.

> 
> >
> >>  		ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
> >> -		nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask);
> >> +		if (exclude_self)
> >> +			nr_bank = cpumask_to_vpset_noself(&(ipi_arg->vp_set), mask);
> >> +		else
> >> +			nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask);
> >>  	}
> >
> > But, what happens in the case that mask == cpu_present_mask and
> > exclude_self == true?
> >
> > AFAICT it ends up sending the IPI to all CPUs including self:
> >
> > 	if (!nr_bank)
> > 		ipi_arg->vp_set.format = HV_GENERIC_SET_ALL;
> >
> > Not entirely correct, right?
> 
> It's not, I think we need something like (completely untested) 
> 
> diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
> index 32a1ad356c18..80b7660208e4 100644
> --- a/arch/x86/hyperv/hv_apic.c
> +++ b/arch/x86/hyperv/hv_apic.c
> @@ -122,17 +122,17 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector,
>         ipi_arg->reserved = 0;
>         ipi_arg->vp_set.valid_bank_mask = 0;
>  
> -       if (!cpumask_equal(mask, cpu_present_mask)) {
> +       if (!cpumask_equal(mask, cpu_present_mask) || exclude_self) {
>                 ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
>                 if (exclude_self)
>                         nr_bank = cpumask_to_vpset_noself(&(ipi_arg->vp_set), mask);
>                 else
>                         nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask);
> -       }
> -       if (nr_bank < 0)
> -               goto ipi_mask_ex_done;
> -       if (!nr_bank)
> +               if (nr_bank =< 0)
> +                       goto ipi_mask_ex_done;
> +       } else {
>                 ipi_arg->vp_set.format = HV_GENERIC_SET_ALL;
> +       }
>  
>         status = hv_do_rep_hypercall(HVCALL_SEND_IPI_EX, 0, nr_bank,
>                               ipi_arg, NULL);
> 
> here. Wei, I can test and send this out if you're not on it already.
> 

Please turn this into a patch and send it out. Thank you so much for
looking into it.

Wei.

> -- 
> Vitaly
> 

  reply	other threads:[~2021-10-06 11:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 18:57 [PATCH v2 0/2] Remove on-stack cpumask in hv_apic.c Wei Liu
2021-09-10 18:57 ` [PATCH v2 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself Wei Liu
2021-09-11 15:06   ` Michael Kelley
2021-09-10 18:57 ` [PATCH v2 2/2] x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself Wei Liu
2021-09-11 15:09   ` Michael Kelley
2021-09-11 15:24     ` Wei Liu
2021-09-26 22:03   ` Thomas Gleixner
2021-10-05 12:53     ` Vitaly Kuznetsov
2021-10-06 11:39       ` Wei Liu [this message]
2021-09-13 10:19 ` [PATCH v2 0/2] Remove on-stack cpumask in hv_apic.c Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211006113913.c2ubc7bokgokoc6q@liuwe-devbox-debian-v2 \
    --to=wei.liu@kernel.org \
    --cc=bp@alien8.de \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=mingo@redhat.com \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH v2 2/2] x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).