Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2776929rdh; Mon, 30 Oct 2023 07:27:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHps2yk95Xz2fj2e9kFrzt1SR2nLptVcXJOiPz/nGqoe909RSX9v4tpH7jKPoCoMOAVLoE9 X-Received: by 2002:a05:6a20:e11e:b0:12c:2dc7:74bc with SMTP id kr30-20020a056a20e11e00b0012c2dc774bcmr14761233pzb.46.1698676062054; Mon, 30 Oct 2023 07:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698676062; cv=none; d=google.com; s=arc-20160816; b=n6lsZAP9NuQP5YZY89cXW3bW66QpYelOOaEnGwE7jGFBwYwi6sSq7B3w0yyKESx//9 IMnWbhGEQECiWoHpJx6k2OGpsGihYGKATO2JXf5qRIoDmKWs2rtdY0ZT63su6HjbG3Qd QqTYhmGPqoZxR+CXznrtEsvZLgNV3eAxFegg16jUuAC/g4pe5UHo4EDoPCx4KS27OkKf MqntY8H7DoRMYURV3OFuBeo6o44dk5w0bYhMhHS/s2DZUa2DV4ll+WiC5KM0b95hbmls bXM6/DgXrPrH9W/SSwmcDZFnJDmsIkeRk8+iR3hQyLfhmKqlsSLZcNM12uzW4Yp7zRyd cOGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+x62jf5ZiMaBeXCGaTeI3fAeetzVsKKIlwH9XbYi/Wk=; fh=FNTYlbiwaGAtUvAsPoqeIJwk9DqSwQVYtSJQ6N5H59g=; b=rC0dquQ7N2GdUoAWcfTLHLbk4g2hsKgfYEqWwu20xjxSsuhi3Yz6Ua3Tfc6ZZayryp 78GKd2IEHSRYDtKRn/MRRkSeyOyvJst9Pydw4Sqf5WteemoJ/lelCA4MEU+iFZ+rtGjA /MV9Q3x9lxAR37Vmy2uxS5MqBOAwuG4tloaA/0NilUywhCwR1Mo69BE5OvNemsHhnypr xpDB1cXW1fzmWpzSUYt94FZQZSz1Qaf1FFXgBs51wbNycVnQ8KfH+UWJPTfhS7GnlzZE YgvBLlPdBJ3KES7LUFCM/U8D41kvn4+kN2/YjlE2qkivZG0hILjRWQOkLsFHmNOJeUan SnBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=DVFbhplY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c20-20020a056a000ad400b006c0fe409cafsi2066881pfl.153.2023.10.30.07.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 07:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=DVFbhplY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2EF13805DC2C; Mon, 30 Oct 2023 07:27:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233371AbjJ3O1k (ORCPT + 99 others); Mon, 30 Oct 2023 10:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233375AbjJ3O1j (ORCPT ); Mon, 30 Oct 2023 10:27:39 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FE1F5 for ; Mon, 30 Oct 2023 07:27:35 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1AB471FF07; Mon, 30 Oct 2023 14:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1698676054; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+x62jf5ZiMaBeXCGaTeI3fAeetzVsKKIlwH9XbYi/Wk=; b=DVFbhplYczx0rCQjxOvC9F63FeFl9OHZE7xQlGzpqBW0G7Msl6Bylf1AyraSQmEocHrYIh ppCCeVfnXGjDCYZ3hTKI397EhbDm222zDQWg+DtpbWN/rvvhX/wM4T6jNQ55qBgpg7+XIm V+0arNif/gGSK5kvLKV7DzQ+XySO2QE= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DBD17138F8; Mon, 30 Oct 2023 14:27:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4y9JNFW9P2VkQgAAMHmgww (envelope-from ); Mon, 30 Oct 2023 14:27:33 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, David Woodhouse Subject: [PATCH] xen/events: avoid using info_for_irq() in xen_send_IPI_one() Date: Mon, 30 Oct 2023 15:27:32 +0100 Message-Id: <20231030142732.1702-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 07:27:41 -0700 (PDT) xen_send_IPI_one() is being used by cpuhp_report_idle_dead() after it calls rcu_report_dead(), meaning that any RCU usage by xen_send_IPI_one() is a bad idea. Unfortunately xen_send_IPI_one() is using notify_remote_via_irq() today, which is using irq_get_chip_data() via info_for_irq(). And irq_get_chip_data() in turn is using a maple-tree lookup requiring RCU. Avoid this problem by caching the ipi event channels in another percpu variable, allowing the use notify_remote_via_evtchn() in xen_send_IPI_one(). Fixes: 721255b9826b ("genirq: Use a maple tree for interrupt descriptor management") Reported-by: David Woodhouse Signed-off-by: Juergen Gross Tested-by: David Woodhouse --- drivers/xen/events/events_base.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c index 1b2136fe0fa5..2cf0c2b69386 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -164,6 +164,8 @@ static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1}; /* IRQ <-> IPI mapping */ static DEFINE_PER_CPU(int [XEN_NR_IPIS], ipi_to_irq) = {[0 ... XEN_NR_IPIS-1] = -1}; +/* Cache for IPI event channels - needed for hot cpu unplug (avoid RCU usage). */ +static DEFINE_PER_CPU(evtchn_port_t [XEN_NR_IPIS], ipi_to_evtchn) = {[0 ... XEN_NR_IPIS-1] = 0}; /* Event channel distribution data */ static atomic_t channels_on_cpu[NR_CPUS]; @@ -366,6 +368,7 @@ static int xen_irq_info_ipi_setup(unsigned cpu, info->u.ipi = ipi; per_cpu(ipi_to_irq, cpu)[ipi] = irq; + per_cpu(ipi_to_evtchn, cpu)[ipi] = evtchn; return xen_irq_info_common_setup(info, irq, IRQT_IPI, evtchn, 0); } @@ -981,6 +984,7 @@ static void __unbind_from_irq(unsigned int irq) break; case IRQT_IPI: per_cpu(ipi_to_irq, cpu)[ipi_from_irq(irq)] = -1; + per_cpu(ipi_to_evtchn, cpu)[ipi_from_irq(irq)] = 0; break; case IRQT_EVTCHN: dev = info->u.interdomain; @@ -1631,7 +1635,7 @@ EXPORT_SYMBOL_GPL(evtchn_put); void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector) { - int irq; + evtchn_port_t evtchn; #ifdef CONFIG_X86 if (unlikely(vector == XEN_NMI_VECTOR)) { @@ -1642,9 +1646,9 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector) return; } #endif - irq = per_cpu(ipi_to_irq, cpu)[vector]; - BUG_ON(irq < 0); - notify_remote_via_irq(irq); + evtchn = per_cpu(ipi_to_evtchn, cpu)[vector]; + BUG_ON(evtchn == 0); + notify_remote_via_evtchn(evtchn); } struct evtchn_loop_ctrl { -- 2.35.3