linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Kelley <mikelley@microsoft.com>
To: vkuznets <vkuznets@redhat.com>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
	Wei Liu <wei.liu@kernel.org>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	KY Srinivasan <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Dexuan Cui <decui@microsoft.com>
Subject: RE: [PATCH] x86/hyperv: Avoid erroneously sending IPI to 'self'
Date: Wed, 6 Oct 2021 15:15:22 +0000	[thread overview]
Message-ID: <MWHPR21MB1593E25D205903BC583C395AD7B09@MWHPR21MB1593.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20211006125016.941616-1-vkuznets@redhat.com>

From: Vitaly Kuznetsov <vkuznets@redhat.com> Sent: Wednesday, October 6, 2021 5:50 AM
> 
> __send_ipi_mask_ex() uses an optimization: when the target CPU mask is
> equal to 'cpu_present_mask' it uses 'HV_GENERIC_SET_ALL' format to avoid
> converting the specified cpumask to VP_SET. This case was overlooked when
> 'exclude_self' parameter was added. As the result, a spurious IPI to
> 'self' can be send.
> 
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Fixes: dfb5c1e12c28 ("x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself")
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
> index 32a1ad356c18..db2d92fb44da 100644
> --- a/arch/x86/hyperv/hv_apic.c
> +++ b/arch/x86/hyperv/hv_apic.c
> @@ -122,17 +122,27 @@ 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)) {
> +	/*
> +	 * Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET
> +	 * when the IPI is sent to all currently present CPUs.
> +	 */
> +	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)
> +
> +		/*
> +		 * 'nr_bank <= 0' means some CPUs in cpumask can't be
> +		 * represented in VP_SET. Return an error and fall back to
> +		 * native (architectural) method of sending IPIs.
> +		 */
> +		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);
> --
> 2.31.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 12:50 [PATCH] x86/hyperv: Avoid erroneously sending IPI to 'self' Vitaly Kuznetsov
2021-10-06 15:15 ` Michael Kelley [this message]
2021-10-06 15:55   ` 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=MWHPR21MB1593E25D205903BC583C395AD7B09@MWHPR21MB1593.namprd21.prod.outlook.com \
    --to=mikelley@microsoft.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).