From patchwork Wed Feb 26 12:38:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11406423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 790F6138D for ; Wed, 26 Feb 2020 12:40:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5573E21927 for ; Wed, 26 Feb 2020 12:40:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Mwu5Dht7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5573E21927 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vxw-0001IN-Vd; Wed, 26 Feb 2020 12:39:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6vxv-0001II-Mk for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 12:39:03 +0000 X-Inumbo-ID: f7be3d38-5894-11ea-aba8-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f7be3d38-5894-11ea-aba8-bc764e2007e4; Wed, 26 Feb 2020 12:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582720743; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiWcA33JFD6YAqhIOQ2+0XkzWGnPZy8SwGRnFCFPNmM=; b=Mwu5Dht7IrVf+FMcyaA3ylSWn6VACMub92xxvDEhnIYQTYvFptI8L0f4 f447RJT8ygNCV4aSuh5crO75PieA8gJ0Vzo3v00Ui8m13tv0bJU9ISdBl 7c4p6wfD+ys29BSDEZTtXiEOLBNmruYgt9ZW6Mb2cKMXNlj7c1gBInfyf c=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: o0W6PQmgv0v5hWIQFtkMVxQfHnJ2s+0k3aHvo4TB2dKvgmJFlYG8bxSa53NfEATM7Nr+JBvZsz KbAhAQVp3K2AJbkiykE7nTi6ru7nOngIxVF5HJWczADtNDfyQ39fk9OKN/2VtR4md2V2x3/AAk b1AidZTjRwAW/uMcGt2g3ctgGnY/Q3YpLqC1OE8laqDzAgsrnE3L7VX89o8PDJIgQoUioVyxuq VQs67wPlUMRq0IXACvYC97yEWYRd9tJMYXCiQZ7NWAuIZ8FQIr0vi/MaY2yevwemTMbbClNFoH ctM= X-SBRS: 2.7 X-MesageID: 13040800 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,488,1574139600"; d="scan'208";a="13040800" From: Roger Pau Monne To: Date: Wed, 26 Feb 2020 13:38:44 +0100 Message-ID: <20200226123844.29519-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226121921.28627-5-roger.pau@citrix.com> References: <20200226121921.28627-5-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 4/4] x86/smp: do not use scratch_cpumask when in interrupt or exception context X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Sander Eikelenboom , Wei Liu , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Using scratch_cpumask in send_IPI_mask is not safe in IRQ or exception context because it can nest, and hence send_IPI_mask could be overwriting another user scratch cpumask data when used in such contexts. Instead introduce a new cpumask to be used by send_IPI_mask, and disable interrupts while using it. Fallback to not using the scratch cpumask (and hence not attemping to optimize IPI sending by using a shorthand) when in IRQ or exception context. Note that the scratch cpumask cannot be used when non-maskable interrupts are being serviced (NMI or #MC) and hence fallback to not using the shorthand in that case, like it was done previously. Fixes: 5500d265a2a8 ('x86/smp: use APIC ALLBUT destination shorthand when possible') Reported-by: Sander Eikelenboom Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v4: - Add _handler suffix to in_nmi/in_mce calls. Changes since v3: - Do not use a dedicated cpumask, and instead prevent usage when in IRQ context. Changes since v2: - Fallback to the previous IPI sending mechanism in #MC or #NMI context. Changes since v1: - Don't use the shorthand when in #MC or #NMI context. --- xen/arch/x86/smp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 55d08c9d52..0461812cf6 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -69,6 +69,18 @@ void send_IPI_mask(const cpumask_t *mask, int vector) bool cpus_locked = false; cpumask_t *scratch = this_cpu(scratch_cpumask); + if ( in_irq() || in_mce_handler() || in_nmi_handler() ) + { + /* + * When in IRQ, NMI or #MC context fallback to the old (and simpler) + * IPI sending routine, and avoid doing any performance optimizations + * (like using a shorthand) in order to avoid using the scratch + * cpumask which cannot be used in interrupt context. + */ + alternative_vcall(genapic.send_IPI_mask, mask, vector); + return; + } + /* * This can only be safely used when no CPU hotplug or unplug operations * are taking place, there are no offline CPUs (unless those have been