From nobody Thu May 2 22:01:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1579254854; cv=none; d=zohomail.com; s=zohoarc; b=cXDd/vKyGD3zFWzm/FO22ns6EFgYHjQolQisb4637ugufi1yDWBhIHBbhGOa96vsKtk+tPi5l433bhyvqEvW1CSRzP1K/vNv6dr0pZULJalhOHQwmwd6PaJ9CdwUP1D7XM9h+be5Tz8ncGkKLGlcBpn4s0C9GMuoJM2EKoJ5grw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579254854; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d2EvT98fLf/enm0VkmAO8XyQPADdYD2VO1FnrrJvS40=; b=fKj2nMKKHYktsfCr/NOwHLXFbhhZQFs1mEyW981VZ9Hf4Mp2gEyvANDRB0kn1nVMhsUNOtGa1u7ONRgNL/jDUR967TDXI1jlOMNJi3UxQZjPTcbCT/d/wAPQgPjaBySEBqBU7MePRSRE6Tkg8semi/2PAn4k2nn9++DoG1xS7yQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579254854890722.11902510922; Fri, 17 Jan 2020 01:54:14 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isOJe-0007wh-Mu; Fri, 17 Jan 2020 09:53:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isOJe-0007wJ-1q for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 09:53:22 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2f4fce75-390f-11ea-8893-12813bfff9fa; Fri, 17 Jan 2020 09:53:17 +0000 (UTC) X-Inumbo-ID: 2f4fce75-390f-11ea-8893-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579254796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wCaqkTQfHuawSxD/a+i/CF+r398ZASYyosYNgEikdi4=; b=S7/CPnytuCFdEBcgR0XFTkTN+gc1aCrtfEar4ZPtszs44BlOII0TeHnR QgBhAIWyW1jgG8Otltu8E7rYqN7wxK5iBszeiVfVT7g42dal5t8qSWvjq 4Uu+kPC4I00zrGpEHk/M0Z8xFO/oD8yxMQAirlsQz9jJ5txqxmwwADDBY s=; Authentication-Results: esa5.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 (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: WxY2CF6E7/S6n8CFNBmwpvPxRicy06PPK6B21XKpUjHaWxNiiduwWOTY42/4cvgFljdWlyxjyj X/OY1akIoHsm7m/hTx/MML6+vs3tW0kjNsXwd8YrbO++aAv9muFwnwXYNrRj3q4fULoEXK409e KE38gxm2Ht98+H9vlSea8g1hE7qEQkfsOZ+vP+a7HUxlm5/5ELjeyEjokM17PTzbsyFkt3l6/+ 4rSpKi9mrotZt6rxDZ2nwEgzM/Dm6foLjHRcWAkxV2HLwOfgJv9fRYahX0+J+fRsyqzSFcCYnH E5Q= X-SBRS: 2.7 X-MesageID: 11430779 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,329,1574139600"; d="scan'208";a="11430779" From: Roger Pau Monne To: Date: Fri, 17 Jan 2020 10:52:50 +0100 Message-ID: <20200117095251.42668-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200117095251.42668-1-roger.pau@citrix.com> References: <20200117095251.42668-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 1/2] x86/smp: move and clean APIC helpers 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 , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Move __prepare_ICR{2}, apic_wait_icr_idle and __default_send_IPI_shortcut to the top of the file, since they will be used by send_IPI_mask in future changes. While there, take the opportunity to remove the leading underscores, drop the inline attribute, drop the default prefix from the shorthand helper, change the return type of the prepare helpers to unsigned and do some minor style cleanups. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v2: - New in this version. --- xen/arch/x86/smp.c | 83 ++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index c8e5913e47..c14f304c09 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -23,6 +23,40 @@ #include #include =20 +/* Helper functions to prepare APIC register values. */ +static unsigned int prepare_ICR(unsigned int shortcut, int vector) +{ + return APIC_DM_FIXED | shortcut | vector; +} + +static unsigned int prepare_ICR2(unsigned int mask) +{ + return SET_xAPIC_DEST_FIELD(mask); +} + +void apic_wait_icr_idle(void) +{ + if ( x2apic_enabled ) + return; + + while ( apic_read(APIC_ICR) & APIC_ICR_BUSY ) + cpu_relax(); +} + +/* Helper for sending APIC IPIs using a shorthand. */ +static void send_IPI_shortcut(unsigned int shortcut, int vector, + unsigned int dest) +{ + unsigned int cfg; + + /* Wait for idle. */ + apic_wait_icr_idle(); + /* Prepare target chip field. */ + cfg =3D prepare_ICR(shortcut, vector) | dest; + /* Send the IPI. The write to APIC_ICR fires this off. */ + apic_write(APIC_ICR, cfg); +} + /* * send_IPI_mask(cpumask, vector): sends @vector IPI to CPUs in @cpumask, * excluding the local CPU. @cpumask may be empty. @@ -80,48 +114,9 @@ void send_IPI_self(int vector) * The following functions deal with sending IPIs between CPUs. */ =20 -static inline int __prepare_ICR (unsigned int shortcut, int vector) -{ - return APIC_DM_FIXED | shortcut | vector; -} - -static inline int __prepare_ICR2 (unsigned int mask) -{ - return SET_xAPIC_DEST_FIELD(mask); -} - -void apic_wait_icr_idle(void) -{ - if ( x2apic_enabled ) - return; - - while ( apic_read( APIC_ICR ) & APIC_ICR_BUSY ) - cpu_relax(); -} - -static void __default_send_IPI_shortcut(unsigned int shortcut, int vector, - unsigned int dest) -{ - unsigned int cfg; - - /* - * Wait for idle. - */ - apic_wait_icr_idle(); - - /* - * prepare target chip field - */ - cfg =3D __prepare_ICR(shortcut, vector) | dest; - /* - * Send the IPI. The write to APIC_ICR fires this off. - */ - apic_write(APIC_ICR, cfg); -} - void send_IPI_self_legacy(uint8_t vector) { - __default_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL= ); + send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL); } =20 void send_IPI_mask_flat(const cpumask_t *cpumask, int vector) @@ -145,13 +140,13 @@ void send_IPI_mask_flat(const cpumask_t *cpumask, int= vector) /* * prepare target chip field */ - cfg =3D __prepare_ICR2(mask); + cfg =3D prepare_ICR2(mask); apic_write(APIC_ICR2, cfg); =20 /* * program the ICR */ - cfg =3D __prepare_ICR(0, vector) | APIC_DEST_LOGICAL; + cfg =3D prepare_ICR(0, vector) | APIC_DEST_LOGICAL; =20 /* * Send the IPI. The write to APIC_ICR fires this off. @@ -181,13 +176,13 @@ void send_IPI_mask_phys(const cpumask_t *mask, int ve= ctor) /* * prepare target chip field */ - cfg =3D __prepare_ICR2(cpu_physical_id(query_cpu)); + cfg =3D prepare_ICR2(cpu_physical_id(query_cpu)); apic_write(APIC_ICR2, cfg); =20 /* * program the ICR */ - cfg =3D __prepare_ICR(0, vector) | APIC_DEST_PHYSICAL; + cfg =3D prepare_ICR(0, vector) | APIC_DEST_PHYSICAL; =20 /* * Send the IPI. The write to APIC_ICR fires this off. --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 22:01:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1579254854; cv=none; d=zohomail.com; s=zohoarc; b=KEi1rTkCdrzOBZ1cq4VvHp1b9KWRCf0osecqf9id9JMblCGull97McIIf6oT0uSD0lmA+r6fOyw9usvrbM++kWH6jdtsjNb1nSZdBwQsx1nQiXT7+cR2XZgvP/t2k+3IO6mDRrdTri3h9paMapy2ROKOERABAjds6c/yyVGlF7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579254854; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RnxZZXCC9fhUH7vU/5RDzKm6P0xyCa2A4B3m0gzx0SI=; b=cJv89AyD+jwSutisFoE1p4MvPbFf5Jasa7qq/N1tN1HDSmt9KjGXCIW0S68k/KuxghHiZyOCHjcOKhTIlmdLj6ZvjPLAhvA+ZxgkQsOWRVoxNNsN45DzD7gHUoICv3nHkMhy49sgW39QTHBxhkUMSC9npdr8sWz/unEAICsJquo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579254854445699.746142903011; Fri, 17 Jan 2020 01:54:14 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isOJe-0007wO-8M; Fri, 17 Jan 2020 09:53:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isOJc-0007wB-L7 for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 09:53:20 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2bf54448-390f-11ea-ac27-bc764e2007e4; Fri, 17 Jan 2020 09:53:11 +0000 (UTC) X-Inumbo-ID: 2bf54448-390f-11ea-ac27-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579254792; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WhPBB69xep1GhCBpi8waPHJJQh98/pZSWJtkDQg2gqw=; b=JHjU0d9ziycbt+sxZF/HzhBs0VI83FuMSoUsxSuL0xkUEyfFJqtboAP+ cl6mx7M+WGUq3B7uuDUtdyHKqcBi2AVrEGYZF9TnTXlIuvHoKfpxqVTvY N0tOzi/bUCctDpiM0YfIJ1lCGWQM4p3jTO5qH6CImD8Ys1VmJfLvUoGvl 0=; 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 (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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: zbCzLEykIRxG1QygBBg+iLiRYtk8EfVeVznPPuem8a4pqob3doiQmoUCNNvQtHdsssZQ85oDtF TMNGTwPUeCiFikzxHM59froP0ChDnXLD+cYmHjeIJDoeKQPKJaJ4bod5VMuTb4KHxyXpIAxNRv 7D4WetZKa8ROykbtxSveU9oge6bdFHTMkPoPz/3sGpFH6COYhNzofgHupr8X45AygaWA6DbfeQ E/KN82SvKkQiWX1NEFKeAaOkx+kyQYFpsCFnKKpBH4rqSWvdlbS5LqCvKjGUU84ElINotVJTAZ ADo= X-SBRS: 2.7 X-MesageID: 11078567 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,329,1574139600"; d="scan'208";a="11078567" From: Roger Pau Monne To: Date: Fri, 17 Jan 2020 10:52:51 +0100 Message-ID: <20200117095251.42668-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200117095251.42668-1-roger.pau@citrix.com> References: <20200117095251.42668-1-roger.pau@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 2/2] x86/smp: use APIC ALLBUT destination shorthand when possible 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 , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) If the IPI destination mask matches the mask of online CPUs use the APIC ALLBUT destination shorthand in order to send an IPI to all CPUs on the system except the current one. This can only be safely used when no CPU hotplug or unplug operations are taking place, no offline CPUs or those have been onlined and parked, all CPUs in the system have been accounted for (ie: the number of CPUs doesn't exceed NR_CPUS and APIC IDs are below MAX_APICS) and there's no possibility of CPU hotplug (ie: no disabled CPUs have been reported by the firmware tables). This is specially beneficial when using the PV shim, since using the shorthand avoids performing an APIC register write (or multiple ones if using xAPIC mode) for each destination when doing a global TLB flush. The lock time of flush_lock on a 32 vCPU guest using the shim in x2APIC mode without the shorthand is: Global lock flush_lock: addr=3Dffff82d0804b21c0, lockval=3Df602f602, not lo= cked lock:228455938(79406065573135), block:205908580(556416605761539) Average lock time: 347577ns While the same guest using the shorthand: Global lock flush_lock: addr=3Dffff82d0804b41c0, lockval=3Dd9c4d9bc, cpu=3D= 12 lock:1890775(416719148054), block:1663958(2500161282949) Average lock time: 220395ns Approximately a 1/3 improvement in the lock time. Note that this requires locking the CPU maps (get_cpu_maps) which uses a trylock. This is currently safe as all users of cpu_add_remove_lock do a trylock, but will need reevaluating if non-trylock users appear. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v2: - Place the code moment in a pre-patch. - Rename cpu_overflow to unaccounted_cpus (leaving it as a bool). - Make disabled_cpus non-init and non-static (and mark it read_mostly). - Prevent using the shorthand if there are disabled CPU slots. - Cope correctly with send_IPI_mask getting passed an empty mask. - Reword comment about shorthand usage in send_IPI_mask. Changes since v1: - Move the shorthand logic to send_IPI_mask. - Check interrupts are enabled before trying to get the cpu maps lock. - Move __prepare_ICR and __default_send_IPI_shortcut. --- xen/arch/x86/acpi/boot.c | 1 + xen/arch/x86/mpparse.c | 7 ++++++- xen/arch/x86/smp.c | 35 ++++++++++++++++++++++++++++++++++- xen/include/asm-x86/smp.h | 3 +++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c index 15542a9bdf..afc6ed9d99 100644 --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -103,6 +103,7 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, = const unsigned long end) processor->lapic_flags & ACPI_MADT_ENABLED ? KERN_WARNING "WARNING: " : KERN_INFO, processor->local_apic_id, processor->uid); + unaccounted_cpus =3D true; /* * Must not return an error here, to prevent * acpi_table_parse_entries() from terminating early. diff --git a/xen/arch/x86/mpparse.c b/xen/arch/x86/mpparse.c index f057d9162f..d532575fee 100644 --- a/xen/arch/x86/mpparse.c +++ b/xen/arch/x86/mpparse.c @@ -61,11 +61,14 @@ unsigned int __read_mostly boot_cpu_physical_apicid =3D= BAD_APICID; =20 /* Internal processor count */ static unsigned int num_processors; -static unsigned int __initdata disabled_cpus; +unsigned int __read_mostly disabled_cpus; =20 /* Bitmask of physically existing CPUs */ physid_mask_t phys_cpu_present_map; =20 +/* Record whether CPUs haven't been added due to overflows. */ +bool __read_mostly unaccounted_cpus; + void __init set_nr_cpu_ids(unsigned int max_cpus) { unsigned int tot_cpus =3D num_processors + disabled_cpus; @@ -160,6 +163,7 @@ static int MP_processor_info_x(struct mpc_config_proces= sor *m, printk_once(XENLOG_WARNING "WARNING: NR_CPUS limit of %u reached - ignoring further processors= \n", nr_cpu_ids); + unaccounted_cpus =3D true; return -ENOSPC; } =20 @@ -167,6 +171,7 @@ static int MP_processor_info_x(struct mpc_config_proces= sor *m, && genapic.name =3D=3D apic_default.name) { printk_once(XENLOG_WARNING "WARNING: CPUs limit of 8 reached - ignoring futher processors\n"); + unaccounted_cpus =3D true; return -ENOSPC; } =20 diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index c14f304c09..65eb7cbda8 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -8,6 +8,7 @@ * later. */ =20 +#include #include #include #include @@ -64,7 +65,39 @@ static void send_IPI_shortcut(unsigned int shortcut, int= vector, =20 void send_IPI_mask(const cpumask_t *mask, int vector) { - alternative_vcall(genapic.send_IPI_mask, mask, vector); + bool cpus_locked =3D false; + cpumask_t *scratch =3D this_cpu(scratch_cpumask); + + /* + * This can only be safely used when no CPU hotplug or unplug operatio= ns + * are taking place, there are no offline CPUs (unless those have been + * onlined and parked), there are no disabled CPUs and all possible CP= Us in + * the system have been accounted for. + */ + if ( system_state > SYS_STATE_smp_boot && + !unaccounted_cpus && !disabled_cpus && + /* NB: get_cpu_maps lock requires enabled interrupts. */ + local_irq_is_enabled() && (cpus_locked =3D get_cpu_maps()) && + (park_offline_cpus || + cpumask_equal(&cpu_online_map, &cpu_present_map)) ) + cpumask_or(scratch, mask, cpumask_of(smp_processor_id())); + else + { + if ( cpus_locked ) + { + put_cpu_maps(); + cpus_locked =3D false; + } + cpumask_clear(scratch); + } + + if ( cpumask_equal(scratch, &cpu_online_map) ) + send_IPI_shortcut(APIC_DEST_ALLBUT, vector, APIC_DEST_PHYSICAL); + else + alternative_vcall(genapic.send_IPI_mask, mask, vector); + + if ( cpus_locked ) + put_cpu_maps(); } =20 void send_IPI_self(int vector) diff --git a/xen/include/asm-x86/smp.h b/xen/include/asm-x86/smp.h index dbeed2fd41..1aa55d41e1 100644 --- a/xen/include/asm-x86/smp.h +++ b/xen/include/asm-x86/smp.h @@ -84,6 +84,9 @@ extern cpumask_t **socket_cpumask; #define get_cpu_current(cpu) \ (get_cpu_info_from_stack((unsigned long)stack_base[cpu])->current_vcpu) =20 +extern unsigned int disabled_cpus; +extern bool unaccounted_cpus; + #endif /* !__ASSEMBLY__ */ =20 #endif --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel