From patchwork Tue Feb 4 07:53:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFE94C0218F for ; Tue, 4 Feb 2025 07:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DxWY7Ul6uBA+JZibfqvkkI14zABpBAm/jf7bUpt/zrA=; b=a00FhwP9W+0ZRf kCn5Awk8CPFSDcKY+QElRamarDHdexg4Op+1uMhew/MkSEdoVbXgC2zG1v2BTzh0F8nMhgSzzHR7u Sf//oai4qVkF5GPbXAPjW08vXrodP5A2PcGdP7fp9umwy1SH+xKr6ohn435uUKdsjRA1C6VDsi/XY BwW7xYiineNxJCDzmpNFdMs/pKGwNI5Njt4V8uQMwjsPBgmnYAUd/FMv/waEc6bTwCBp5RuYoh4ul 55qTiflQsiifle1VMzIBjNYAp6w5c0m/qMLMfLUFgFFND/o+IU7c+2yEZyNmjeHsLeqgAIcDxEz9M DE8JaYU3GBWQVfmUPL+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDnF-0000000HT9p-0xor; Tue, 04 Feb 2025 07:56:25 +0000 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDlS-0000000HSdC-17Qs for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:54:35 +0000 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-7b6e9586b82so465611885a.1 for ; Mon, 03 Feb 2025 23:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655673; x=1739260473; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CBfvQ3kWrJIo4ZX2fO574K2xNLHLI8xt5fD3UcZCgGE=; b=ZewnfPTku3rCxGEHONcgHgVdlOXBApzQmxEgCdc7X2pN4L+zzCTmgJ6A6DfxN66cnM xll4xX31GJj0G27vYQs/GWseBlJanFSR+d32AKE+hll0cAXTt0vDRzo1kpmWspSyslhA RTRvBJdeS0BNJ7nkpBvPhDak+dD4IGLRuZB8BjodsPkaj89vKG6V1+HjpRe1K29/bCMJ qpWVKM6Hw9eoaN3eNeHFwrD50SmwakTuCtMxCcijayu7BrVVVCJjhwSmYMH8pbfwTr2m dZz0uXa1rriyNloe7dVBMRkrPpk2uDh3oYb08KpCDo27TPIz68/Bijy6bVa9iqJFHHCu SflA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655673; x=1739260473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CBfvQ3kWrJIo4ZX2fO574K2xNLHLI8xt5fD3UcZCgGE=; b=Ys0ubQzFDK/XfpQnk+jjnCy3ZR+I62k1dU19lPdW6iAXbUYNW5+KS20bDKH9z4LQyc oY4jHaBOydxPwFsLPJMMpEjAmvM7dTIqwOMt1XClWfp08Thh41xuHUu5AJmtYe+rQIxv VHMOBLhwci50kV/7dZ5T6fVorC2v51yr4n4idOapiCPAzphQewLmsCeFFh+NsrbENIxU 5OxSElnQSzVVhi83rWG48Ha7nR8ztAVMBs8Nuewfb1LKB7bL/84SFKJcMjsjtHniJrCC QizLefV+n1q6cJO0O8zOYpmxcJs7V+YujYjWyWNM7NIRlsKPQ+0efKwQvczGzAnPnVsO Fe5w== X-Forwarded-Encrypted: i=1; AJvYcCVL38/1lxjvPGihJul9xx2B2APTUyM55zFDtNohw+kJw2dIo/tWaFbxZmvM47Lc3R2KHcVgpp7MF5TfbQ==@lists.infradead.org X-Gm-Message-State: AOJu0YywEChUS7uKn/7/+cgrb3zHVblOHrTDJSL7VTYf/V87cvMclfYs 8zudENHY0jneRfsweGQ+pKGB8mSxsAX8umzSCoNtmaX+7vBTLeQD/tpufzGzMOQ= X-Gm-Gg: ASbGncs8kKiBsLOiisMPVuWpU0wQYxZUrZtC40jaGZKZiCiqgCCiGWNgxoLZVkPQVaL cSaMl/0JJOK4DyUJ4r9jvTaiMVs+BG8Xs/ib6JyK1pKYjWAi0A5CIQghOC/vDBr4fCkTDtz1Cmf gU1WSvnwghR93ljPXaK+/gyodcRooFFApaZlgS0L51pAwzr+3R6shkA6O5P0D0xI0q07YhMXtc+ Oaxeht5RDYJpuB1jfDhXq2qeR3u3KqIlp6ZDSCqoJ1mJrq5m5g0UsjIMNSpasaosXItGWj3K9Pb CmhL4c32PA3lQSCJgl6pFYlX0ixHyw7R01QZWD/iGYXrgN+J6bYwZ+g= X-Google-Smtp-Source: AGHT+IE1kHVojceFVzcf2jbW9XOHhUZiDggCrSxIzTiwYNG5RUoAlilnWj5uEbIRStQ4m23HHT45hg== X-Received: by 2002:a05:620a:4093:b0:7b6:d1e1:a22e with SMTP id af79cd13be357-7bffcd43a1cmr3525668485a.29.1738655673185; Mon, 03 Feb 2025 23:54:33 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:32 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 01/10] irqchip/riscv-imsic: Handle non-atomic MSI updates for device Date: Tue, 4 Feb 2025 13:23:56 +0530 Message-ID: <20250204075405.824721-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235434_308263_D2749E7D X-CRM114-Status: GOOD ( 20.74 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Device having non-atomic MSI update might see an intermediate state when changing target IMSIC vector from one CPU to another. To handle such intermediate device state, update MSI address and MSI data through separate MSI writes to the device. Fixes: 027e125acdba ("irqchip/riscv-imsic: Add device MSI domain support for platform devices") Suggested-by: Thomas Gleixner Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-early.c | 8 +++- drivers/irqchip/irq-riscv-imsic-platform.c | 27 ++++++++++++ drivers/irqchip/irq-riscv-imsic-state.c | 50 ++++++++++++++-------- drivers/irqchip/irq-riscv-imsic-state.h | 2 +- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-riscv-imsic-early.c index c5c2e6929a2f..73a93ce8668f 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -77,6 +77,12 @@ static void imsic_handle_irq(struct irq_desc *desc) struct imsic_vector *vec; unsigned long local_id; + /* + * First process pending IMSIC vector enable, disable and movement + * on the current CPU. + */ + imsic_local_sync_all(false); + chained_irq_enter(chip, desc); while ((local_id = csr_swap(CSR_TOPEI, 0))) { @@ -120,7 +126,7 @@ static int imsic_starting_cpu(unsigned int cpu) * Interrupts identities might have been enabled/disabled while * this CPU was not running so sync-up local enable/disable state. */ - imsic_local_sync_all(); + imsic_local_sync_all(true); /* Enable local interrupt delivery */ imsic_local_delivery(true); diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index c708780e8760..b44eb0b3990b 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -97,6 +97,7 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask { struct imsic_vector *old_vec, *new_vec; struct irq_data *pd = d->parent_data; + struct imsic_vector tmp_vec; old_vec = irq_data_get_irq_chip_data(pd); if (WARN_ON(!old_vec)) @@ -115,6 +116,32 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask if (!new_vec) return -ENOSPC; + /* + * Device having non-atomic MSI update might see an intermediate + * state when changing target IMSIC vector from one CPU to another. + * + * To avoid losing interrupt to some intermediate state, do the + * following (just like x86 APIC): + * + * 1) First write a temporary IMSIC vector to the device which + * has MSI address same as the old IMSIC vector but MSI data + * matches the new IMSIC vector. + * + * 2) Next write the new IMSIC vector to the device. + * + * Based on the above, the __imsic_local_sync() must check both + * old MSI data and new MSI data on the old CPU for pending + */ + + if (new_vec->local_id != old_vec->local_id) { + /* Setup temporary vector */ + tmp_vec.cpu = old_vec->cpu; + tmp_vec.local_id = new_vec->local_id; + + /* Point device to the temporary vector */ + imsic_msi_update_msg(d, &tmp_vec); + } + /* Point device to the new vector */ imsic_msi_update_msg(d, new_vec); diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index b97e6cd89ed7..a8645084bd8f 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -126,21 +126,21 @@ void __imsic_eix_update(unsigned long base_id, unsigned long num_id, bool pend, static void __imsic_local_sync(struct imsic_local_priv *lpriv) { - struct imsic_local_config *mlocal; - struct imsic_vector *vec, *mvec; + struct imsic_local_config *tlocal, *mlocal; + struct imsic_vector *vec, *tvec, *mvec; int i; lockdep_assert_held(&lpriv->lock); for_each_set_bit(i, lpriv->dirty_bitmap, imsic->global.nr_ids + 1) { if (!i || i == IMSIC_IPI_ID) - goto skip; + continue; vec = &lpriv->vectors[i]; if (READ_ONCE(vec->enable)) - __imsic_id_set_enable(i); + __imsic_id_set_enable(vec->local_id); else - __imsic_id_clear_enable(i); + __imsic_id_clear_enable(vec->local_id); /* * If the ID was being moved to a new ID on some other CPU @@ -151,26 +151,47 @@ static void __imsic_local_sync(struct imsic_local_priv *lpriv) mvec = READ_ONCE(vec->move); WRITE_ONCE(vec->move, NULL); if (mvec && mvec != vec) { - if (__imsic_id_read_clear_pending(i)) { + /* + * Device having non-atomic MSI update might see an + * intermediate state so check both old ID and new ID + * for pending interrupts. + * + * For details, refer imsic_irq_set_affinity(). + */ + + tvec = vec->local_id == mvec->local_id ? + NULL : &lpriv->vectors[mvec->local_id]; + if (tvec && __imsic_id_read_clear_pending(tvec->local_id)) { + /* Retrigger temporary vector if it was already in-use */ + if (READ_ONCE(tvec->enable)) { + tlocal = per_cpu_ptr(imsic->global.local, tvec->cpu); + writel_relaxed(tvec->local_id, tlocal->msi_va); + } + mlocal = per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va); } - imsic_vector_free(&lpriv->vectors[i]); + if (__imsic_id_read_clear_pending(vec->local_id)) { + mlocal = per_cpu_ptr(imsic->global.local, mvec->cpu); + writel_relaxed(mvec->local_id, mlocal->msi_va); + } + + imsic_vector_free(vec); } -skip: - bitmap_clear(lpriv->dirty_bitmap, i, 1); + bitmap_clear(lpriv->dirty_bitmap, vec->local_id, 1); } } -void imsic_local_sync_all(void) +void imsic_local_sync_all(bool force_all) { struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv); unsigned long flags; raw_spin_lock_irqsave(&lpriv->lock, flags); - bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); + if (force_all) + bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); __imsic_local_sync(lpriv); raw_spin_unlock_irqrestore(&lpriv->lock, flags); } @@ -190,12 +211,7 @@ void imsic_local_delivery(bool enable) #ifdef CONFIG_SMP static void imsic_local_timer_callback(struct timer_list *timer) { - struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv); - unsigned long flags; - - raw_spin_lock_irqsave(&lpriv->lock, flags); - __imsic_local_sync(lpriv); - raw_spin_unlock_irqrestore(&lpriv->lock, flags); + imsic_local_sync_all(false); } static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned int cpu) diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-riscv-imsic-state.h index 391e44280827..8fae6c99b019 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -74,7 +74,7 @@ static inline void __imsic_id_clear_enable(unsigned long id) __imsic_eix_update(id, 1, false, false); } -void imsic_local_sync_all(void); +void imsic_local_sync_all(bool force_all); void imsic_local_delivery(bool enable); void imsic_vector_mask(struct imsic_vector *vec); From patchwork Tue Feb 4 07:53:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89C07C0218F for ; Tue, 4 Feb 2025 07:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WlZP8SZYetYktHDMy89E58QpaLzD7a5abBH6Ap8cJUQ=; b=e8/TBNleOL6Hlh pjfrwJpqwhM3vaVLlb4ujRk9IqdBricyQo7wqyMTu0eEOFTkV+oQW6UXUmTE3sHZmJZOgLIvSqley 9eEdXBYbna7ij54w24UZFvu1yNVvwb6hG/NfMpbi74GZ2rwR7l7R5sNLCH4oewIQX72IRPd0f1G65 bQeKijpD3WtLH/LaXCGj8K17BIQx+HUDriXeaaKpMwViD+IDgw/rSQiQKERRhcArWk7568N+uscwI Cv+gvrTdJ6uAjrdWD0lo08ox04EkAvg9ugsqXS5iI1uTGP6zQPRx3H1tyNl1tuc2qF3QZIgz0McwX 8K12iiF3+WJ3Qe//jYZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDoa-0000000HTRb-2Vom; Tue, 04 Feb 2025 07:57:48 +0000 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDla-0000000HSfP-48IY for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:54:44 +0000 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7bcf33f698dso507511185a.2 for ; Mon, 03 Feb 2025 23:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655682; x=1739260482; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=IvfDHndm+2ptkSAJSiv0oYYloOh2HHDkSaqqxiA0C2k82BFsp3WNZMN0DNZqfVFbW0 tLzQabRASb3l4EVRI0bA//k5YwLA1lnRLvNLiqepfTc4Opgh3qzYcjHORBRrzxpWL6c0 KI4bTlWtrKJ6jQcQDeLqRC2QFgpNXQgyxOt0tr5LkGME31ss2TDVlIfEKfyyDuTbvr38 33UAOV7bE9Y2GEnDTw8Uk7nW/upQDieU0d7q7AexbVEGuDVoLccveKm5u2XoEOigfjFj Iym16v3QPMWuOaLOQmgkXPIr4P3PWa1BXuytEY0TsR+miSi2HI+UNOTwH/meWP4UMTPl 1Y9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655682; x=1739260482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=q6ASjto2dv+Zr0eIxCH6jpMOHsULVinvxyqEQgNRrdCjp8DF1HPAypGhNlXjc9BgRL hm9HTi8wgOYy19NW9BaUC+YLTEzAenQWtqLMKImP/bumdwrE64FSiSHDQ19dnISgZNEj j/YszSJTQldOrPbFooLMeOsP33rSOwykNgh80vQfMP4/KhD8tSyyWzauAU8JW1BEkSW+ pXEhH7g8kaVol60Ojewbz/XyZX6xCqGHY3LYBrAD+zy0b44U9Gr3h6v5KpK7VQ0jIST4 37fFIXOjtHnBQNDBNOfheEtLLnbNzGP6zAo8T1xDSQi3uOH2MadxJ4kMhWoiKZgFPn2I cwWg== X-Forwarded-Encrypted: i=1; AJvYcCVtMdsVkp//nG6a6JDQUM1KmOPU7TVrG/WrR3nVeBrGIeXIAUXdk2M0XXpZFoqptNSUlMv9SfOz0YzUNw==@lists.infradead.org X-Gm-Message-State: AOJu0YyPYrdXBB9cQHZ4Q2RKszeAWPts4mhsU2LqjHE89nTEqO2mpXdA f6P7pDi7/kfqMc4BO7J5k96sMmKRmCdZmjYCE6iqUqGZf//bgY8XIhwDk08WrNU= X-Gm-Gg: ASbGncv8F+yEK333B7MCY5Tzll0nKpyWvlWLoWaR/eklzlHcIgptFPKmc8cIB5v/hSr UVGTC9B+zl9UmFIkNk8cVt92r9/RG6WIywrMoE8aMzyT2ujMKYMkK7YoV+EMVMVHJDP5UQlHdbE E1HY6HXqPIX5fkZX5t7vXKOFnBSH3VqrCdi0+N0VePCcmCMqxgTdJMZlkiEl9KrsVrS1fHzNj8Q 2TG08JiTsTjRqUbrtwvjC9syWRoEcx4rgKR3r7JpS5MsKHseBSpctz8hXXquXUmgZZzl5FPp8oG TriLUJBd2Qq5Z1JQlpYS2GtZlGT3zN+QcvbhpVOKnUI+YJfLMC1xQxA= X-Google-Smtp-Source: AGHT+IEhdMB+vtxDJGF7LVgqcjkCxx8rRK71YEAfpN/qTx2NMyGfi0QyTUHVXR86sg4Wl/xvt3qxrw== X-Received: by 2002:a05:620a:278e:b0:7b7:2de:6fd3 with SMTP id af79cd13be357-7bffcc3cdfamr3041523085a.0.1738655681635; Mon, 03 Feb 2025 23:54:41 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:41 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 02/10] irqchip/irq-msi-lib: Optionally set default irq_eoi/irq_ack Date: Tue, 4 Feb 2025 13:23:57 +0530 Message-ID: <20250204075405.824721-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235443_037021_4665AFBF X-CRM114-Status: GOOD ( 16.69 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Thomas Gleixner Introduce chip_flags in struct msi_parent_ops. This allows msi_lib_init_dev_msi_info() set default irq_eoi/irq_ack callbacks only when the corresponding flags are set in the chip_flags. Signed-off-by: Thomas Gleixner Signed-off-by: Anup Patel --- drivers/irqchip/irq-gic-v2m.c | 1 + drivers/irqchip/irq-imx-mu-msi.c | 1 + drivers/irqchip/irq-msi-lib.c | 11 ++++++----- drivers/irqchip/irq-mvebu-gicp.c | 1 + drivers/irqchip/irq-mvebu-odmi.c | 1 + drivers/irqchip/irq-mvebu-sei.c | 1 + include/linux/msi.h | 11 +++++++++++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-gic-v2m.c b/drivers/irqchip/irq-gic-v2m.c index be35c5349986..1e3476c335ca 100644 --- a/drivers/irqchip/irq-gic-v2m.c +++ b/drivers/irqchip/irq-gic-v2m.c @@ -255,6 +255,7 @@ static void __init gicv2m_teardown(void) static struct msi_parent_ops gicv2m_msi_parent_ops = { .supported_flags = GICV2M_MSI_FLAGS_SUPPORTED, .required_flags = GICV2M_MSI_FLAGS_REQUIRED, + .chip_flags = MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token = DOMAIN_BUS_NEXUS, .bus_select_mask = MATCH_PCI_MSI | MATCH_PLATFORM_MSI, .prefix = "GICv2m-", diff --git a/drivers/irqchip/irq-imx-mu-msi.c b/drivers/irqchip/irq-imx-mu-msi.c index 4342a21de1eb..69aacdfc8bef 100644 --- a/drivers/irqchip/irq-imx-mu-msi.c +++ b/drivers/irqchip/irq-imx-mu-msi.c @@ -214,6 +214,7 @@ static void imx_mu_msi_irq_handler(struct irq_desc *desc) static const struct msi_parent_ops imx_mu_msi_parent_ops = { .supported_flags = IMX_MU_MSI_FLAGS_SUPPORTED, .required_flags = IMX_MU_MSI_FLAGS_REQUIRED, + .chip_flags = MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token = DOMAIN_BUS_NEXUS, .bus_select_mask = MATCH_PLATFORM_MSI, .prefix = "MU-MSI-", diff --git a/drivers/irqchip/irq-msi-lib.c b/drivers/irqchip/irq-msi-lib.c index d8e29fc0d406..51464c6257f3 100644 --- a/drivers/irqchip/irq-msi-lib.c +++ b/drivers/irqchip/irq-msi-lib.c @@ -28,6 +28,7 @@ bool msi_lib_init_dev_msi_info(struct device *dev, struct irq_domain *domain, struct msi_domain_info *info) { const struct msi_parent_ops *pops = real_parent->msi_parent_ops; + struct irq_chip *chip = info->chip; u32 required_flags; /* Parent ops available? */ @@ -92,10 +93,10 @@ bool msi_lib_init_dev_msi_info(struct device *dev, struct irq_domain *domain, info->flags |= required_flags; /* Chip updates for all child bus types */ - if (!info->chip->irq_eoi) - info->chip->irq_eoi = irq_chip_eoi_parent; - if (!info->chip->irq_ack) - info->chip->irq_ack = irq_chip_ack_parent; + if (!chip->irq_eoi && (pops->chip_flags & MSI_CHIP_FLAG_SET_EOI)) + chip->irq_eoi = irq_chip_eoi_parent; + if (!chip->irq_ack && (pops->chip_flags & MSI_CHIP_FLAG_SET_ACK)) + chip->irq_ack = irq_chip_ack_parent; /* * The device MSI domain can never have a set affinity callback. It @@ -105,7 +106,7 @@ bool msi_lib_init_dev_msi_info(struct device *dev, struct irq_domain *domain, * device MSI domain aside of mask/unmask which is provided e.g. by * PCI/MSI device domains. */ - info->chip->irq_set_affinity = msi_domain_set_affinity; + chip->irq_set_affinity = msi_domain_set_affinity; return true; } EXPORT_SYMBOL_GPL(msi_lib_init_dev_msi_info); diff --git a/drivers/irqchip/irq-mvebu-gicp.c b/drivers/irqchip/irq-mvebu-gicp.c index 2b6183919ea4..d67f93f6d750 100644 --- a/drivers/irqchip/irq-mvebu-gicp.c +++ b/drivers/irqchip/irq-mvebu-gicp.c @@ -161,6 +161,7 @@ static const struct irq_domain_ops gicp_domain_ops = { static const struct msi_parent_ops gicp_msi_parent_ops = { .supported_flags = GICP_MSI_FLAGS_SUPPORTED, .required_flags = GICP_MSI_FLAGS_REQUIRED, + .chip_flags = MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token = DOMAIN_BUS_GENERIC_MSI, .bus_select_mask = MATCH_PLATFORM_MSI, .prefix = "GICP-", diff --git a/drivers/irqchip/irq-mvebu-odmi.c b/drivers/irqchip/irq-mvebu-odmi.c index ff19bfd258dc..28f7e81df94f 100644 --- a/drivers/irqchip/irq-mvebu-odmi.c +++ b/drivers/irqchip/irq-mvebu-odmi.c @@ -157,6 +157,7 @@ static const struct irq_domain_ops odmi_domain_ops = { static const struct msi_parent_ops odmi_msi_parent_ops = { .supported_flags = ODMI_MSI_FLAGS_SUPPORTED, .required_flags = ODMI_MSI_FLAGS_REQUIRED, + .chip_flags = MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token = DOMAIN_BUS_GENERIC_MSI, .bus_select_mask = MATCH_PLATFORM_MSI, .prefix = "ODMI-", diff --git a/drivers/irqchip/irq-mvebu-sei.c b/drivers/irqchip/irq-mvebu-sei.c index 065166ab5dbc..ebd4a9014e8d 100644 --- a/drivers/irqchip/irq-mvebu-sei.c +++ b/drivers/irqchip/irq-mvebu-sei.c @@ -356,6 +356,7 @@ static void mvebu_sei_reset(struct mvebu_sei *sei) static const struct msi_parent_ops sei_msi_parent_ops = { .supported_flags = SEI_MSI_FLAGS_SUPPORTED, .required_flags = SEI_MSI_FLAGS_REQUIRED, + .chip_flags = MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_mask = MATCH_PLATFORM_MSI, .bus_select_token = DOMAIN_BUS_GENERIC_MSI, .prefix = "SEI-", diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00e..9abef442c146 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -558,11 +558,21 @@ enum { MSI_FLAG_NO_AFFINITY = (1 << 21), }; +/* + * Flags for msi_parent_ops::chip_flags + */ +enum { + MSI_CHIP_FLAG_SET_EOI = (1 << 0), + MSI_CHIP_FLAG_SET_ACK = (1 << 1), +}; + /** * struct msi_parent_ops - MSI parent domain callbacks and configuration info * * @supported_flags: Required: The supported MSI flags of the parent domain * @required_flags: Optional: The required MSI flags of the parent MSI domain + * @chip_flags: Optional: Select MSI chip callbacks to update with defaults + * in msi_lib_init_dev_msi_info(). * @bus_select_token: Optional: The bus token of the real parent domain for * irq_domain::select() * @bus_select_mask: Optional: A mask of supported BUS_DOMAINs for @@ -575,6 +585,7 @@ enum { struct msi_parent_ops { u32 supported_flags; u32 required_flags; + u32 chip_flags; u32 bus_select_token; u32 bus_select_mask; const char *prefix; From patchwork Tue Feb 4 07:53:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26375C02193 for ; Tue, 4 Feb 2025 07:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0of8vmMgsAPA/oC5M6T/vmwBB7PBmpRHztC3sxy2hio=; b=MHPL7KPvihZRql 37qniSQsqRgBeyQfivemjQYnbKTKKxlJvLy4PcRLQtPU31XLEoKKazNM85RsYfpLx0j2YpqLyrFtx nlexbsRI6v1gZuXj4t75Unztsy05HFhgYvHvllCL/HjRdGxQIi4FWoHaz6XcXSdu3yvGsuWKjzcwz dxyVnHgU6aP9O0Z/aKAwsLgWiYVRn+O67mo1b48ForDTL3RfOTq36ma0ywt9cuCKZ3Zs02oARiGre 2rUXFmrOJfOEFEPp81tTsd65HTXD2DtmZ2tZW7aMxler0WjkKManXgt6hyQ1+A+eYL1pv1Cs5ctzv g310l6aYb/dpAVKxsrTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDpv-0000000HTei-3V7p; Tue, 04 Feb 2025 07:59:11 +0000 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDll-0000000HSha-0txn for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:54:54 +0000 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7b6ed9ed5b9so888115185a.2 for ; Mon, 03 Feb 2025 23:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655692; x=1739260492; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+XpbAvyCPU7XjesnTrNMuPwq8s0Ofi62LAN8USKi2As=; b=EdQSY7Li/3xErwyTKc5KPO1Hj882zI46VS6rdyOThYd+KcqT/+TSjk2tx0Z0kq78AK jhYeO2jM8vyGUXBnFt+PJQYsgGFzkAHjDRRdiwfHk+E3apCS6Jz4+Ri46EzGK0ndJNfT xW6kfj75fyTWJqypzFm7glZuuYRKue3nFeePEMsL1oEQXQPau7wZ9Kjn+HuWVIbDqRH7 85o1Q7hNP/sTRBiMLIjNI0HQp9sj3jcXdYDNIKhCkcYSbGZUNYJ9ZUou1LFU27d0KD6B CsG7kVhuBE+S4T2qKD9QbNyLf2ubweD5trnPww89O99Yu+TkVumIfXEFGwPFvBh6H8EV /zOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655692; x=1739260492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+XpbAvyCPU7XjesnTrNMuPwq8s0Ofi62LAN8USKi2As=; b=kFXKh/JJihhtv2fySiLHj6uq5OhrfDstYoySkRCtgRq5g0K1Gdc4QqOxqpvoNlL7br Bamk8V3Pc4gMEeepm9y36bvNGTEiBfyCFAC+lk6AqbsNBS1+LYbdan6n6v8R0wkif8qo oAEvsEIjgwwXQIBFbhdp8+da06G8QtLuskdpCi66xVQb2wElZ+vNJ1gz2STSrp07jWNt VjeArzNEDmFLP+QVZt4DurLVXMElc+JC3hnY32DkT2Wm7GtUVo5GYRAgfPuz/7/O0ucd +3gGK5Dc+oY6V/FxifwE8piIokew8HW1AMs09AGiR2UiUFRRoJLwHdAvXFejU35SPaiC 7H1w== X-Forwarded-Encrypted: i=1; AJvYcCW+zMqeIWEEg6xBAuXlgird8vMdQvJTyAbR3IHl+ue5/6ohEJVMxKyQo2nveCMyt/1tGyKjStzMKzdhyA==@lists.infradead.org X-Gm-Message-State: AOJu0Yxj5+4BTJLik8ixeYGLagZ19FXBBqbM0dsIxnPQEmHmV8u4qi7K BAGcpHJ5KbJh7YqRKYNIhUuBJU1UeaNy2dpmk5AiuyEEK7cUJMiHKlUiv2+zCk8= X-Gm-Gg: ASbGncutedsJvh7KdMxKE6z030lc9WeqhPqkEsug5o7OccRqnqpg75WoGsxiRkTbLHW TGabKUejgS6dMvsnnuT3rApZk7YBfZqin84XsPS0wc7/Ix1SDxV9mIp/z0nOyjIvBTyOuwTlNMt tK7ar2yd+tGda6TajqKfdDLsI1E7x+5lnnB5jG9OiH9Jy54rMaMkgMa9jR8z4/L3rXOikzGhBRg hlXkmYNG5Py6AMOlEyIWp3yViKwt0EQEd448Q2LfG7AI/5BENhTRb7XkyIAImeRlmGF7ACmU/ru XA0d8LTobBbfbt/PX8a9JqQ81lokjxzf4qWbJSTC9lsHicUCZTnIjyY= X-Google-Smtp-Source: AGHT+IE555JYDjxayJP3hHqE1TDj1cVPpWMaeaM/3WguRaZQLIT7OdX0Wc2dai4BACH0ZbT7vjefxQ== X-Received: by 2002:a05:620a:8395:b0:7b6:6e59:2864 with SMTP id af79cd13be357-7bffcd726edmr3656909985a.43.1738655691894; Mon, 03 Feb 2025 23:54:51 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:51 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 03/10] irqchip/riscv-imsic: Set irq_set_affinity for IMSIC base Date: Tue, 4 Feb 2025 13:23:58 +0530 Message-ID: <20250204075405.824721-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235453_273836_291A3B40 X-CRM114-Status: GOOD ( 13.69 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Andrew Jones Instead of using imsic_irq_set_affinity() for leaf MSI domains, use imsic_irq_set_affinity() for the non-leaf IMSIC base domain and use irq_chip_set_affinity_parent() for leaf MSI domains. Signed-off-by: Andrew Jones Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index b44eb0b3990b..dc6f63f657e4 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -96,10 +96,9 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; - struct irq_data *pd = d->parent_data; struct imsic_vector tmp_vec; - old_vec = irq_data_get_irq_chip_data(pd); + old_vec = irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) return -ENOENT; @@ -139,17 +138,17 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask tmp_vec.local_id = new_vec->local_id; /* Point device to the temporary vector */ - imsic_msi_update_msg(d, &tmp_vec); + imsic_msi_update_msg(irq_get_irq_data(d->irq), &tmp_vec); } /* Point device to the new vector */ - imsic_msi_update_msg(d, new_vec); + imsic_msi_update_msg(irq_get_irq_data(d->irq), new_vec); /* Update irq descriptors with the new vector */ - pd->chip_data = new_vec; + d->chip_data = new_vec; - /* Update effective affinity of parent irq data */ - irq_data_update_effective_affinity(pd, cpumask_of(new_vec->cpu)); + /* Update effective affinity */ + irq_data_update_effective_affinity(d, cpumask_of(new_vec->cpu)); /* Move state of the old vector to the new vector */ imsic_vector_move(old_vec, new_vec); @@ -162,6 +161,9 @@ static struct irq_chip imsic_irq_base_chip = { .name = "IMSIC", .irq_mask = imsic_irq_mask, .irq_unmask = imsic_irq_unmask, +#ifdef CONFIG_SMP + .irq_set_affinity = imsic_irq_set_affinity, +#endif .irq_retrigger = imsic_irq_retrigger, .irq_compose_msi_msg = imsic_irq_compose_msg, .flags = IRQCHIP_SKIP_SET_WAKE | @@ -272,7 +274,7 @@ static bool imsic_init_dev_msi_info(struct device *dev, if (WARN_ON_ONCE(domain != real_parent)) return false; #ifdef CONFIG_SMP - info->chip->irq_set_affinity = imsic_irq_set_affinity; + info->chip->irq_set_affinity = irq_chip_set_affinity_parent; #endif break; default: From patchwork Tue Feb 4 07:53:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BD32C0218F for ; Tue, 4 Feb 2025 08:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XBv2U+c5IvPwO2C8LUTxhlcPAj/YnqmQrKSTAwUrHa8=; b=e80es8z54ieTCG nk1jNvMdWY/ZMyHnUsNJK+pnJmjZp97I77kpBddEgACc1bY+E3+32btQ70mUyMBbRL0tlOmLIJmYC cncgpB7kZmO72gdNNlEd9KZtuPCHJPYiTm9fGYsggoyxeSYq9t4QnbglsKlPdYoRPsMbEpTVqgiGE nft6n9jFgl0Zd8Ymp9NmytRCJwpvUQH6AuJuW4oBSOrbNtQPCbeme+WCfnNCscKPOmFZQPdquVA1I E4T/5MsAhBJbEN5m8as3loBxCcIdbfYL8gQWfatru+VLvbi54eOTXoFhxhwa1yd1/ZLgOIpokCMbc jF8U6tWlvlnRqJMPDKSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDsZ-0000000HTzj-37XH; Tue, 04 Feb 2025 08:01:55 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDlu-0000000HSke-23dH for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:03 +0000 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7be6fdeee35so833565485a.1 for ; Mon, 03 Feb 2025 23:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655701; x=1739260501; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zt4BUR1O09akAiE35kyzRFyQQsTBDdGx/Mpea27bkKs=; b=luop/B/7+rMbcP8IvWJeVoxA50+3qyBC0u/9POCIKbeIX2P9jh0+4ZgtEhfW2zXsQS bgJ67rrTyHMSXTLU/Wiq0HPG4QVPQt4uZfh4SFFHSm9gmW8Z9i/fV1INx3nN6WjuIcnp OKEyeicXr9a6mhi0niFM3FKVJ187gOywUvC8kUaTuIxOAyFCVPPSlStfYKRR3fwvKKnu ZgA/3UVNkoqitzZQhGEfbv6JdSeDSxGtKdTLO+Y1x+AaYEkSZw5fgmY5pp3sSDYNze6M m5Z5aogCXIoMrWuTGq5tDbWN6hh6MNeuZD7ecTpG5e/j4YSXhP4VvOgo17sH8nUwxyRb rj/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655701; x=1739260501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zt4BUR1O09akAiE35kyzRFyQQsTBDdGx/Mpea27bkKs=; b=YKNqNl9nu4ysuY6AAxECnHqMfojN1544R4GxwQLi047tKgplYXhMhdssEmXvqreQZg u2vgdg5EYuBmUra0864ymUsMYz7/8MNdXZPFWQBpXNFn7MR+y86YdMsbXLWOqqYnFv+6 +w0+XOYPQZ37nPQ4qmrZewtPI+Cb7XUKUuxcsAhPhgr3zSINUtf0TCsYexwXNBTHrmrR nPIwKUGVOe4oNpe6ZROyTmmkD0rPkX4avcIfL6nkRq2ZBWf8XPbMYILVCHhY1BS4OGwt KiOBF4A3UsAmHynLg0oTGLZsqnwCtnukA3G77lJd9cP2Q7xo05vvTSM9n+AmmJLNTAdK pEpw== X-Forwarded-Encrypted: i=1; AJvYcCVF1lRnS/wY8NxhroOrLFCzx0DDT1i2YOTIXg7+f0hlCVlPfvl9vD5Ko1o9vVnFaxVYVvsc7KOHKxnzGg==@lists.infradead.org X-Gm-Message-State: AOJu0Yx9+o8wtj+Zxd2YRc8L7TwopGYiANGcYptrxdEAzZMVAYD2vzQv iB6rYJJIgJH7Fb4TWQ1oPRKmfbUaj9PnH3MUoa2eD09Yq5ca+9fholizrzIQToo= X-Gm-Gg: ASbGncsCMSIDOLb966V/fEv5EUO6EM0wOdyTkpdFC7cDxPeEziK9Welim+fBHn87/K2 QEp/ufa/TIn0Juy4wFUQM1e/36VMVWSoASY3jnZr/R3OUZCWeQt2hJqHFmI4XhjjgwkDF7r+MXV 7DdLtpt42rNzpVPGQWVRxO1gCthqn1aF9j0/QGkJAl324KxSJwGfBKbMh++XBqhaWs62Jupg51g PbI6pHsjKQeDeRfNwHp0SabOiHe3wkiZZPGPL4rztZ1GlrK4sYDX8fn+8wX7Bbux9ywlYRcBHiD C1ZtIJnYCLrvAdN0gfDlrynHuNVaWElT+ejLadijYXqxnk+FMfQoAmY= X-Google-Smtp-Source: AGHT+IEHo/ibp+o6qeQRlJusLW8jVVXpZtzwcNrNItHHxjlGS/8JBTsdvSnSG8vOxPC1otd04HpYwA== X-Received: by 2002:a05:620a:240a:b0:7be:3965:7452 with SMTP id af79cd13be357-7bffcd06b08mr4023625385a.32.1738655701483; Mon, 03 Feb 2025 23:55:01 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:01 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 04/10] irqchip/riscv-imsic: Move to common MSI lib Date: Tue, 4 Feb 2025 13:23:59 +0530 Message-ID: <20250204075405.824721-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235502_544968_A8699578 X-CRM114-Status: GOOD ( 16.41 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Thomas Gleixner Simplify the leaf MSI domain handling in the RISC-V IMSIC driver by using msi_lib_init_dev_msi_info() and msi_lib_irq_domain_select() provided by common MSI lib. Signed-off-by: Thomas Gleixner Signed-off-by: Andrew Jones Signed-off-by: Anup Patel --- drivers/irqchip/Kconfig | 8 +- drivers/irqchip/irq-riscv-imsic-platform.c | 114 +-------------------- 2 files changed, 6 insertions(+), 116 deletions(-) diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index be063bfb50c4..bc3f12af2dc7 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -589,13 +589,7 @@ config RISCV_IMSIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_MATRIX_ALLOCATOR select GENERIC_MSI_IRQ - -config RISCV_IMSIC_PCI - bool - depends on RISCV_IMSIC - depends on PCI - depends on PCI_MSI - default RISCV_IMSIC + select IRQ_MSI_LIB config SIFIVE_PLIC bool diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index dc6f63f657e4..2fab20d2ce3e 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -20,6 +20,7 @@ #include #include +#include "irq-msi-lib.h" #include "irq-riscv-imsic-state.h" static bool imsic_cpu_page_phys(unsigned int cpu, unsigned int guest_index, @@ -201,22 +202,6 @@ static void imsic_irq_domain_free(struct irq_domain *domain, unsigned int virq, irq_domain_free_irqs_parent(domain, virq, nr_irqs); } -static int imsic_irq_domain_select(struct irq_domain *domain, struct irq_fwspec *fwspec, - enum irq_domain_bus_token bus_token) -{ - const struct msi_parent_ops *ops = domain->msi_parent_ops; - u32 busmask = BIT(bus_token); - - if (fwspec->fwnode != domain->fwnode || fwspec->param_count != 0) - return 0; - - /* Handle pure domain searches */ - if (bus_token == ops->bus_select_token) - return 1; - - return !!(ops->bus_select_mask & busmask); -} - #ifdef CONFIG_GENERIC_IRQ_DEBUGFS static void imsic_irq_debug_show(struct seq_file *m, struct irq_domain *d, struct irq_data *irqd, int ind) @@ -233,110 +218,21 @@ static void imsic_irq_debug_show(struct seq_file *m, struct irq_domain *d, static const struct irq_domain_ops imsic_base_domain_ops = { .alloc = imsic_irq_domain_alloc, .free = imsic_irq_domain_free, - .select = imsic_irq_domain_select, + .select = msi_lib_irq_domain_select, #ifdef CONFIG_GENERIC_IRQ_DEBUGFS .debug_show = imsic_irq_debug_show, #endif }; -#ifdef CONFIG_RISCV_IMSIC_PCI - -static void imsic_pci_mask_irq(struct irq_data *d) -{ - pci_msi_mask_irq(d); - irq_chip_mask_parent(d); -} - -static void imsic_pci_unmask_irq(struct irq_data *d) -{ - irq_chip_unmask_parent(d); - pci_msi_unmask_irq(d); -} - -#define MATCH_PCI_MSI BIT(DOMAIN_BUS_PCI_MSI) - -#else - -#define MATCH_PCI_MSI 0 - -#endif - -static bool imsic_init_dev_msi_info(struct device *dev, - struct irq_domain *domain, - struct irq_domain *real_parent, - struct msi_domain_info *info) -{ - const struct msi_parent_ops *pops = real_parent->msi_parent_ops; - - /* MSI parent domain specific settings */ - switch (real_parent->bus_token) { - case DOMAIN_BUS_NEXUS: - if (WARN_ON_ONCE(domain != real_parent)) - return false; -#ifdef CONFIG_SMP - info->chip->irq_set_affinity = irq_chip_set_affinity_parent; -#endif - break; - default: - WARN_ON_ONCE(1); - return false; - } - - /* Is the target supported? */ - switch (info->bus_token) { -#ifdef CONFIG_RISCV_IMSIC_PCI - case DOMAIN_BUS_PCI_DEVICE_MSI: - case DOMAIN_BUS_PCI_DEVICE_MSIX: - info->chip->irq_mask = imsic_pci_mask_irq; - info->chip->irq_unmask = imsic_pci_unmask_irq; - break; -#endif - case DOMAIN_BUS_DEVICE_MSI: - /* - * Per-device MSI should never have any MSI feature bits - * set. It's sole purpose is to create a dumb interrupt - * chip which has a device specific irq_write_msi_msg() - * callback. - */ - if (WARN_ON_ONCE(info->flags)) - return false; - - /* Core managed MSI descriptors */ - info->flags |= MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS | - MSI_FLAG_FREE_MSI_DESCS; - break; - case DOMAIN_BUS_WIRED_TO_MSI: - break; - default: - WARN_ON_ONCE(1); - return false; - } - - /* Use hierarchial chip operations re-trigger */ - info->chip->irq_retrigger = irq_chip_retrigger_hierarchy; - - /* - * Mask out the domain specific MSI feature flags which are not - * supported by the real parent. - */ - info->flags &= pops->supported_flags; - - /* Enforce the required flags */ - info->flags |= pops->required_flags; - - return true; -} - -#define MATCH_PLATFORM_MSI BIT(DOMAIN_BUS_PLATFORM_MSI) - static const struct msi_parent_ops imsic_msi_parent_ops = { .supported_flags = MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags = MSI_FLAG_USE_DEF_DOM_OPS | - MSI_FLAG_USE_DEF_CHIP_OPS, + MSI_FLAG_USE_DEF_CHIP_OPS | + MSI_FLAG_PCI_MSI_MASK_PARENT, .bus_select_token = DOMAIN_BUS_NEXUS, .bus_select_mask = MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info = imsic_init_dev_msi_info, + .init_dev_msi_info = msi_lib_init_dev_msi_info, }; int imsic_irqdomain_init(void) From patchwork Tue Feb 4 07:54:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3698C0218F for ; Tue, 4 Feb 2025 08:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6v3rCrAC9Tc9WC5bpmjJ6SnsLvxn/j3fkS4MH5jVyLE=; b=lvxV0pV1Xz+Hxq Gs9287OberUr43qNCUPePp2R90D/+uhaYY/Iksxwz1PnOlxIkABeAiTs9h4I+h9/UusH8SzGhFPXj soD0iuWNvvSjApgdzQf+WG6rWICd9jis6Y8tIl1uvHORCjNjK9V5aQSBgV7j4LtnJgY+zpDea9F9T 0RNoHyqvpkfihXL1Oq4WbyEDkUFAjXIAJr/GDJ1QdN8BwujljzPvoqRo+IcJ6jx2HEBr6wTQYfDZE vk3cVJ61eG2VwKz+0/1xq7F3fftfhTDlrH97s7fVK+02Usp7UdJnHvXURD7pDTJ92hs/0iylr4pLI KzZEGmaD++sZ0Zm6KYBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDtu-0000000HUCp-0GGK; Tue, 04 Feb 2025 08:03:18 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDm5-0000000HSoW-1C4x for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:14 +0000 Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7b98a2e3b3eso290201085a.2 for ; Mon, 03 Feb 2025 23:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655712; x=1739260512; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zXz6fvQA0XjFVpb2cpM8OodOs5mmbZEn6PcelI8ZWow=; b=nCXhPJS129mXHl8LjkLJpQXnN8qDONxJoosT4r1dWpAiKa1481PWWHbN08LAcHvg8d 1XCr6BHQsm5sheBCweuxVrHfCuzlnamFtZ0LiGIulmQf1+LqXDSH5s8+dDHZqZGfeZTi S1ZZqLE62xs7k0spvAWWiNG0ozXkdloTzOCLpBRW7VggQXgQgwsa/McVCpN/F+DxHmD3 N4OQAST+PTn42lxEN2JgX6SMImpQdxUbuLHEswnWBWjdeBy2hjeHhaTLO79JE+3BQAyA iksg9asm3egzT8Jd0NuQnzg7xz7WDRhX6rfoAFiAAd6RgrkGnA1Ctr1EPQncR2E4Vat7 lw7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655712; x=1739260512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zXz6fvQA0XjFVpb2cpM8OodOs5mmbZEn6PcelI8ZWow=; b=jbQ5/82eDbl9utBS62YPwwb6ARbrj+5mF0L8fXgkJf1M5fUctJ/Pib4eJbG4bxYfhH sC7Ml7B8EZ1Qm+dNRq5I33VptoQOYwHtZSguUMx6zGCgScdVIW14Dr+NrJczUpah9LCQ upkrZQOLiZb3ZT/vEBQwkU/HWrF15sMN/iWfntu+tnby2whKIa2rymH6DW4wFUj13UZ7 s7n0/eZQdhPxprPKljcy3Y2dmcNQRR/u7N7tW/e7Y0b3c+yDtunFYe5iwaLMMGKLD4Xv PX7LctiuspNaM9nb5D6+QSsWjsdsoPBnk5crOW71hUxErjpugyVivSMtbw5PjieX/2H1 GIeg== X-Forwarded-Encrypted: i=1; AJvYcCXwzuqR8XzwFlW8DBsdh8iBRbWdrgS41pJ9xJ+fmagabAeGqFYWP7AviKqvDKveJx2gNh+I2sXUmuX5jg==@lists.infradead.org X-Gm-Message-State: AOJu0YylkieaFtFkvFoXwQZZcV28n55aSQgeDnkjru12qcQLzautq5xt h13ErU62mlNPnyebr1jw4mdGcFCyI2JKaKBQCbdlh6X1T1xDYg/HHm6vXowiiWc= X-Gm-Gg: ASbGncv3+U20rzubVQGtpKcxuS4z36EwjF3Pzo6rtvrbDbjGfnJSUoYXiGY5GrJ1EVV da/lDGe0ZBimcwCbHMe/mA9ij8ldhrL3POfQjnXSBcITrN/IxhwuwZatR434DeK4lbYovJgb1ID VyITBAODE28lO4/n0gECNh9ITpQMlNu/w8kBcXcOrA332/huOcDfL2Dtd8JyXh3wGVJG1HYnShQ zAxWwfWYWiNN+IWtuG54CnShjFa8J9xmDFWsXudY1QhbM91gx2MeeWGX9QkbDA9c+Q56fTdJHLn 9dE/kqL99OALNX8C2I4KmHR0+aLXGMVERZumq4qbGOh8ZnZqTs9D8xI= X-Google-Smtp-Source: AGHT+IEygJlzRE1f+LllQAS/xZozPVCC5zlNa0cJxT7IbmhuAFZYxlHSMSOoINty/Bxd6fyVjhK48w== X-Received: by 2002:a05:620a:2b8a:b0:7b6:6c6f:fb5c with SMTP id af79cd13be357-7bffcce52e1mr3541223185a.15.1738655711939; Mon, 03 Feb 2025 23:55:11 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:10 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 05/10] genirq: Introduce common irq_force_complete_move() implementation Date: Tue, 4 Feb 2025 13:24:00 +0530 Message-ID: <20250204075405.824721-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235513_323073_8266E554 X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The GENERIC_PENDING_IRQ requires an arch specific implementation of irq_force_complete_move(). At the moment, only x86 implements this but for RISC-V the irq_force_complete_move() is only needed when RISC-V IMSIC driver is in use and not needed otherwise. To address the above, introduce common weak implementation of the irq_force_complete_move() which lets irqchip do the actual irq_force_complete_move(). Signed-off-by: Anup Patel --- include/linux/irq.h | 5 +++++ kernel/irq/migration.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/irq.h b/include/linux/irq.h index 8daa17f0107a..1884fa4ec9b5 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -486,6 +486,7 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d) * @ipi_send_mask: send an IPI to destination cpus in cpumask * @irq_nmi_setup: function called from core code before enabling an NMI * @irq_nmi_teardown: function called from core code after disabling an NMI + * @irq_force_complete_move: optional function to force complete pending irq move * @flags: chip specific flags */ struct irq_chip { @@ -537,6 +538,10 @@ struct irq_chip { int (*irq_nmi_setup)(struct irq_data *data); void (*irq_nmi_teardown)(struct irq_data *data); +#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ) + void (*irq_force_complete_move)(struct irq_data *data); +#endif + unsigned long flags; }; diff --git a/kernel/irq/migration.c b/kernel/irq/migration.c index eb150afd671f..2920024475a3 100644 --- a/kernel/irq/migration.c +++ b/kernel/irq/migration.c @@ -5,6 +5,15 @@ #include "internals.h" +void __weak irq_force_complete_move(struct irq_desc *desc) +{ + struct irq_data *d = irq_desc_get_irq_data(desc); + struct irq_chip *chip = irq_data_get_irq_chip(d); + + if (chip && chip->irq_force_complete_move) + chip->irq_force_complete_move(d); +} + /** * irq_fixup_move_pending - Cleanup irq move pending from a dying CPU * @desc: Interrupt descriptor to clean up From patchwork Tue Feb 4 07:54:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 627EEC0218F for ; Tue, 4 Feb 2025 08:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V37SBZb5WAC0QITnhI3G2cAobVhQUoIQPrwS4FNbPcY=; b=5CZoNMV33+y90b XaEC0oNial0zqSHO4uPE1w6SQ85nvBTN1FYkU9W46FSW05FoGrmIWuZ82WHd0JblxaUazYPeTe5Wh yIOZp4JxHvnR91ysXONBo6sKldJt8JoJ0XNEJyotEuXowh3kV0QZMRDtCOkXf0TU6DaaCpBH8YZKi 5WzNbAiwX/WOOkuafQ/IfaBD4Dvsy2f6T7ESqGXaHC1yGlyNACUCf4GvvYLVG+d+6GT6jzXqF/TPw GVUOZxc1Q9hbSp9v9mEUihHWtgXL6y93XZVF+aMUfAy0u5VHkzepkrugw5rVmNI+jCtm8EnazEwjv /x3RCh9R5QUFDA2yUzlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDvD-0000000HUMD-0zkp; Tue, 04 Feb 2025 08:04:39 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDmE-0000000HSsR-3MXj for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:24 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b6ed0de64aso455749285a.0 for ; Mon, 03 Feb 2025 23:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655722; x=1739260522; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZnRpk/p9sKuCOyv2KZjNLOO6T+xrx1m13lZc/9SNpSQ=; b=HGWb5V3LuorlC20A3R8l9dP9WR75SIUcCEu8BruGb6sQRGYIGKOfOd7OADt/ecQYKN zrnr++AXTDjgtm4GyOWMko9jAjsVsXz6fDk6Ef5xEN/9zM3+rfPmEj/xejXJX/q3lEHK pJVPoocqNdH67T42Sv01n1E7YLe/kEzqykjwGtTkRi7B6x+9pCgUi4N5L0dP0c07BHYM PoQH6ONbl0ojMHCUhCp3GHwwIc2OI9whUhMXCQah4gVRHH8n1GiDwXNo8xqAyF7ehy/C K1lEktCbe3nWB1/by8DFJ/jW6YMS820JVyAksCF27P6ODAGdgaKti+yezLQO8mW9HZBI jADQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655722; x=1739260522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZnRpk/p9sKuCOyv2KZjNLOO6T+xrx1m13lZc/9SNpSQ=; b=A7APJOSBvadntc3BYww9CsXuzbvv2xH9Wp8lzxWTpxxIkpk7cH6Og6h+JpGXez5P03 CAYoNE4UODTLkxh7BHTC7ptarPeCh354Sg8CMLprjTKzxpYXehT/ii3Hzu7Sl941CRuH MWQmAsMaILEEvo/USJB4uzd0RJPqgAtQ31DoBjDvztSf0ev4vB2ZH51eotvTdCm9trVt wWQTxVtJaNLpUplJ5MwpzHq6PtcYEhG7oke8rMGsZgpFc0oAAQxR7RpgQ6nHWD046+y7 sWcPt5XwGXvm/blfCNyZsOFbBYoEEkl/FOo7LprEHzR4cSYqiwfj75UAPrYQGSa21zH+ u5kA== X-Forwarded-Encrypted: i=1; AJvYcCWEa1pxONjWk67pp1QkQlGu8C9TH4npywVIQX5bNzqn+Wb+Umyp0V9cCGZZ0i5qimNbsydCxGIC6rvHvQ==@lists.infradead.org X-Gm-Message-State: AOJu0YzBH9tk9yDPuPN2g16OjpcK1PAxiLudBwtec+stplKw+Myl3Efj vdT5S9Y7yw3zthMGfPEWJML6EfJ/kbZj5+iSwhLLlrs3CgklAswGVRQqoEgZFKU= X-Gm-Gg: ASbGncumu1kGdI45zvDzCCKooO7CLMqCwyPkokdwKokJEn4Jp8IKl3u1N/rJVmIfhpF yIF7fCgoqlLXOO8WXdBNMk/8Fwd/rqr/TCEmO4b2jXZKjlqxuEfgQEx15Gm5pZN+2diYKO4RkqO Cv19haus3WoEd8H3AEy4gvQ4HKN52ohC/4V8qCL6P/nce+Ly05iSfAeNb3RqeXaRyyJwJO/g5Mr 8dTpBQzqag65JyfgqiPDmC2wH78cKrqvKWJFR1WTceNWASAkfZCzaLC+wmpm2H9YC9p1Ksjj52s 4BACRD7ObZvYeD9A90WF1nIy0yC0mDtxAsy0rqo8Z5nzrEBImzswYWo= X-Google-Smtp-Source: AGHT+IHxtxKg5RW+0tra7ErqT2l5lv/l4qXvXUJ8U9uiGwIl5QtJCesqdAm7TRDDQSFPGUYW4TnQ4g== X-Received: by 2002:a05:620a:1993:b0:7b6:d710:22ad with SMTP id af79cd13be357-7c02eca3a0amr362876885a.27.1738655721837; Mon, 03 Feb 2025 23:55:21 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:20 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 06/10] RISC-V: Enable GENERIC_PENDING_IRQ and GENERIC_PENDING_IRQ_CHIPFLAGS Date: Tue, 4 Feb 2025 13:24:01 +0530 Message-ID: <20250204075405.824721-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235522_854243_368A3C8B X-CRM114-Status: UNSURE ( 8.35 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Enable GENERIC_PENDING_IRQ and GENERIC_PENDING_IRQ_CHIPFLAGS for RISC-V so that RISC-V irqchips can support delayed irq mirgration in the interrupt context. Signed-off-by: Anup Patel --- arch/riscv/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7612c52e9b1e..3c19e6ca832d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -111,6 +111,8 @@ config RISCV select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_LIB_DEVMEM_IS_ALLOWED + select GENERIC_PENDING_IRQ if SMP + select GENERIC_PENDING_IRQ_CHIPFLAGS if SMP select GENERIC_PCI_IOMAP select GENERIC_PTDUMP if MMU select GENERIC_SCHED_CLOCK From patchwork Tue Feb 4 07:54:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E917BC02193 for ; Tue, 4 Feb 2025 08:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qp79TkmU1OZ/y8s+i/2I+Srkam9aebvDVagGYOak4GQ=; b=lXt8XKfjGNAIpd PUZpA1eNmyyfbl3YuYKWQGaafg5ro2wI8PebxWplIW9uCoTNS/TLxmmSJKLjCTBhyWWJGXR7cx/6m y/TkYWVD1k36UUPLGbfgWy49zD1Am/rQfoTTL2nS87zyt+kkgniHZrVIZttOWsmPXyzOGuyxDtsMD NzAhmXcjeEVbeTV8yNm4RLTEiHdOzGah+ihVkOFLbF8Fn80T0mTLlZe98xj8f3TBKVy9Kpqgm8ZXh p5uQO9PkrpNed/YRWnxFBQmtv7ROM5zXR0gGSC/ujWJEpIF1uyZlG3csM2UbPX/CQHE1fXgCkWnBk cSv0MBRfPQ0FiLNP0F7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDwW-0000000HUWw-2G2r; Tue, 04 Feb 2025 08:06:00 +0000 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDmP-0000000HSvd-2DXs for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:34 +0000 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-7b6f19a6c04so499053685a.0 for ; Mon, 03 Feb 2025 23:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655732; x=1739260532; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X8Q8DUzarAwU1aGXfCPKakOOrYWe0j2UtGXEc/s+csU=; b=XlsBqJcd5EjPD4RRmwwmKjPRki0mszugQqTUh1bqaDfz51xktF9FFdzRDohZYQBw2n r/++sSkuuN83tBMha5no0Hn0BbmN63xwuevhYu3veglT/gGv5ltgNnbL2GAgpcg9BeeE KlkUOv8/DM81LXO3zToUJjK42RXfS5A4Mer+bjVt9Nd92jWC5ElGjCLXxkxutgh5/rND YZHXFF7GM99Y2EHWD47Ucv+29ReVVgGkhdgv+x7h8J5wHoYg3hlM0pp/p+Yf/rh/zA0C P0BhpWNviGACk08kMIUsuEXwlzoz5tG+31hOXcaNCM+pxPpxTVHFJz7xe+pvbq46wE4h Axdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655732; x=1739260532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X8Q8DUzarAwU1aGXfCPKakOOrYWe0j2UtGXEc/s+csU=; b=W/nqauAXKF7OPdiQT/FAI914eTB8Q44KXT/4pUksoya1Og2D1sb+TP4HOeKCHjlrtx Mn+eqirwSrLAMyOztNutgfzETAKbINChuD6SlUvU71gFWFJd1h/wn5CzR4+F5LLqRZm3 lRyTwkMWov9H662xMVu31LMgcsqRMYhh8b/B+79R4GIqsK3ahvgakgvYoue9+rFoisZg GeFcJt4J9/vXDmx2tAc9erx30cULLISU5r0ohyiXxxKBX3zzaWuYqnNA/QfcKhzmZ4Gx SKht0P2SBaiCJHlgnHVMTe8jDhsk8oZM79fRwWuXSSGdxKCMf1LdcGpW06J9AmcqKdWM kHRQ== X-Forwarded-Encrypted: i=1; AJvYcCWbLenPvSg2D5jXVe5oLliKNlIXk0/BCj/YpHDu8MHusB8AHtyUUNsXgjCIoN2QxyDUbGVeaBLQS9OpzQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yzq/gEBvxEHXQmmE3O6qkWbr0HjZ7meOo9fB3sZhRzixJZVgrdD 6zUnyH5NYOIrSLCmq0HIy/OlL4DgBSYPIY282sV6zsthOyevCqyf/j7ukeAvaMs= X-Gm-Gg: ASbGncv3wE7MPUOS9ACi3Wmj70cHuPyPglBr5vKDFBe0OASb2CQt866mx1HlZ65oW/1 o89cBlCfjbXtPDhUSDrJXhGlCNI07F7BtBgbbXx/6C+EKEQlcXnAjFjqXhAeobRGa7FRsDFPrm8 rw2HbfSd2FMz8YzldMzglwvWXK9KRzAvs+pPCiphYQXj53M20+Tp9Dsr9svRzl1zGKgaWzp7tAy sTiIaZRGOl0JaOZ7kGKIlBx13eBMUs/jxBhVIYgcmwtNWHHmTJ9DKQk++yRjBDWUKpRyonocq+U /lh7mOI7QfjIi015fvB2f7eXSSUhZt7mNmPJOaLXoz5kaF9XK276f9A= X-Google-Smtp-Source: AGHT+IFDcS298QZ7UQVAAQCilUqOgCz6Qta0EEYLJBdOtJFQz2jTcrmA1MOx3CQyyowlvRaOrsJYyg== X-Received: by 2002:a05:620a:471e:b0:7b6:d8aa:7ef8 with SMTP id af79cd13be357-7bffcd8cdd2mr3753349985a.37.1738655732192; Mon, 03 Feb 2025 23:55:32 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:30 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 07/10] irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector Date: Tue, 4 Feb 2025 13:24:02 +0530 Message-ID: <20250204075405.824721-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235533_566086_6F9B8E80 X-CRM114-Status: GOOD ( 22.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, there is only one "move" pointer in the struct imsic_vector so during vector movement the old vector points to the new vector and new vector points to itself. To support force cleanup of old vector, add separate "move_next" and "move_prev" pointers in the struct imsic_vector where during vector movement the "move_next" pointer of the old vector points to the new vector and the "move_prev" pointer of the new vector points to the old vector. Both "move_next" pointers are cleared separately by __imsic_local_sync() on the old and new CPUs respectively. Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-state.c | 77 +++++++++++++++++++------ drivers/irqchip/irq-riscv-imsic-state.h | 5 +- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index a8645084bd8f..649012cc47a8 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -124,10 +124,11 @@ void __imsic_eix_update(unsigned long base_id, unsigned long num_id, bool pend, } } -static void __imsic_local_sync(struct imsic_local_priv *lpriv) +static bool __imsic_local_sync(struct imsic_local_priv *lpriv) { struct imsic_local_config *tlocal, *mlocal; struct imsic_vector *vec, *tvec, *mvec; + bool ret = true; int i; lockdep_assert_held(&lpriv->lock); @@ -142,15 +143,33 @@ static void __imsic_local_sync(struct imsic_local_priv *lpriv) else __imsic_id_clear_enable(vec->local_id); + /* + * If the ID was being moved from an existing ID on some + * other CPU then we clear the pervious vector pointer + * only after the movement is complete. + */ + mvec = READ_ONCE(vec->move_prev); + if (mvec) { + /* + * If the old IMSIC vector has not been updated then + * try again in the next sync-up call. + */ + if (READ_ONCE(mvec->move_next)) { + ret = false; + continue; + } + + WRITE_ONCE(vec->move_prev, NULL); + } + /* * If the ID was being moved to a new ID on some other CPU * then we can get a MSI during the movement so check the * ID pending bit and re-trigger the new ID on other CPU * using MMIO write. */ - mvec = READ_ONCE(vec->move); - WRITE_ONCE(vec->move, NULL); - if (mvec && mvec != vec) { + mvec = READ_ONCE(vec->move_next); + if (mvec) { /* * Device having non-atomic MSI update might see an * intermediate state so check both old ID and new ID @@ -177,22 +196,44 @@ static void __imsic_local_sync(struct imsic_local_priv *lpriv) writel_relaxed(mvec->local_id, mlocal->msi_va); } + WRITE_ONCE(vec->move_next, NULL); imsic_vector_free(vec); } bitmap_clear(lpriv->dirty_bitmap, vec->local_id, 1); } + + return ret; } +#ifdef CONFIG_SMP +static void __imsic_local_timer_start(struct imsic_local_priv *lpriv) +{ + lockdep_assert_held(&lpriv->lock); + + if (!timer_pending(&lpriv->timer)) { + lpriv->timer.expires = jiffies + 1; + add_timer_on(&lpriv->timer, smp_processor_id()); + } +} +#else +static inline void __imsic_local_timer_start(struct imsic_local_priv *lpriv) +{ +} +#endif + void imsic_local_sync_all(bool force_all) { struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv); unsigned long flags; raw_spin_lock_irqsave(&lpriv->lock, flags); + if (force_all) bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); - __imsic_local_sync(lpriv); + if (!__imsic_local_sync(lpriv)) + __imsic_local_timer_start(lpriv); + raw_spin_unlock_irqrestore(&lpriv->lock, flags); } @@ -232,14 +273,11 @@ static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned int cpu */ if (cpu_online(cpu)) { if (cpu == smp_processor_id()) { - __imsic_local_sync(lpriv); - return; + if (__imsic_local_sync(lpriv)) + return; } - if (!timer_pending(&lpriv->timer)) { - lpriv->timer.expires = jiffies + 1; - add_timer_on(&lpriv->timer, cpu); - } + __imsic_local_timer_start(lpriv); } } #else @@ -294,8 +332,9 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } -static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struct imsic_vector *vec, - bool new_enable, struct imsic_vector *new_move) +static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, + struct imsic_vector *vec, bool is_old_vec, + bool new_enable, struct imsic_vector *move_vec) { unsigned long flags; bool enabled; @@ -305,7 +344,10 @@ static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struct imsi /* Update enable and move details */ enabled = READ_ONCE(vec->enable); WRITE_ONCE(vec->enable, new_enable); - WRITE_ONCE(vec->move, new_move); + if (is_old_vec) + WRITE_ONCE(vec->move_next, move_vec); + else + WRITE_ONCE(vec->move_prev, move_vec); /* Mark the vector as dirty and synchronize */ bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1); @@ -338,8 +380,8 @@ void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *new_ve * interrupt on the old vector while device was being moved * to the new vector. */ - enabled = imsic_vector_move_update(old_lpriv, old_vec, false, new_vec); - imsic_vector_move_update(new_lpriv, new_vec, enabled, new_vec); + enabled = imsic_vector_move_update(old_lpriv, old_vec, true, false, new_vec); + imsic_vector_move_update(new_lpriv, new_vec, false, enabled, old_vec); } #ifdef CONFIG_GENERIC_IRQ_DEBUGFS @@ -402,7 +444,8 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct cpumask vec = &lpriv->vectors[local_id]; vec->hwirq = hwirq; vec->enable = false; - vec->move = NULL; + vec->move_next = NULL; + vec->move_prev = NULL; return vec; } diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-riscv-imsic-state.h index 8fae6c99b019..f02842b84ed5 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -23,7 +23,8 @@ struct imsic_vector { unsigned int hwirq; /* Details accessed using local lock held */ bool enable; - struct imsic_vector *move; + struct imsic_vector *move_next; + struct imsic_vector *move_prev; }; struct imsic_local_priv { @@ -87,7 +88,7 @@ static inline bool imsic_vector_isenabled(struct imsic_vector *vec) static inline struct imsic_vector *imsic_vector_get_move(struct imsic_vector *vec) { - return READ_ONCE(vec->move); + return READ_ONCE(vec->move_prev); } void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *new_vec); From patchwork Tue Feb 4 07:54:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 861DBC0218F for ; Tue, 4 Feb 2025 08:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=67ohOJeSZG/NXXzIwwN/ASpmTvB2nxIFnVcsIVrxbE8=; b=FJBvht8CdDbbpk Pflq++buWrxK5nHXL/cgY54HNaxvAJT30SJk0PpCpmxyNPQwdB7up//6gzEpAULAEql1yPJcd5j/G mv9TZ3w7cLfX0NMQKeeUMtQTbZ+IT296C8hZOVv6EhrvhyDMn6oaRc5YRD1zUCK4NdBj2wpTUoZKC o2D8n+aPfDaugUP0mPR+3nCySdtAb8kbGrbr6OEg13Ru0EcXhCm3DNzQqcZkWwXiEmoHsZGkv67PV bk+S6AuclHkkZoEr3ajGITLxVyAJaUL4+P8E7DHmxrZAhrnDokgBj0il+5CX2wNZDK58jsL80hqTv K2ddBkGJG0OHQgp6bF3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDxp-0000000HUjC-2xX7; Tue, 04 Feb 2025 08:07:21 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDmZ-0000000HSyT-1ULK for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:45 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b6e9db19c8so477630385a.3 for ; Mon, 03 Feb 2025 23:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655742; x=1739260542; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2spJ1HnVniz9PCwrjRYFNbVUb3mNe4Ef/XoJaqLNwpE=; b=HXJfyv5xapJ+Ikt5B/RWtR/uLRKbjWPUmLN1P5EEPF3bmE5zZq2wgaOPC6P6yn7zgf Sz5fxQPiGGh5av6dzh8sBJSqbpg2+hLxJVkGnAHRo3oxyIcXBg4/j/4HCnIAdmnlPYHs N05HyiJGtSRt+HW54/99web4Lo1HEnaV/INy4eh1H+S0sonxJYZ60vtIWhbtTLq0HE/2 aARhpwTsKp5QVVhQckF1SMGpjy+qBrZSr3qIu37Np1DAX7JWfnPHKOy9eCO+PWDnESKT EPHalTl8xM2FXkhzBfEjo/wHBOdgk+RXJuKIZq/WSC89Y+OIV3R24CVme52u8YEE4O9L ltPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655742; x=1739260542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2spJ1HnVniz9PCwrjRYFNbVUb3mNe4Ef/XoJaqLNwpE=; b=uJPvt/cpnu7c5zugEVewbvyATCy6CYIK61zYsnW/PUcOKMYDa6EFb5MlI9Q8aYMFOV OZBrQgJMThT3NQpUFODWl2f9XMDpgTwvUOhLPYkxXjrqvf0fefTPFwhvbJCBBEMgeg+w buhW6pnp3Pp2vqSR6B6i6gupTv2ksJbtW9svm6WcMOjN0J+4lRdVRIWvue60zEi8Qf8F witaChQJNYApPlukzS6hPIzUiftcm+rYEgS7SxeADqmqlpdIP7yQwClXfxEz8k/+/cCY Pp4W5umOuxkog+9j4t2K7y0wAdmduS22koyscjzvElbSyuDCm0ydlB3FsDHX1xee63l+ Yrng== X-Forwarded-Encrypted: i=1; AJvYcCXwpwqx6FMvOUBYBrkdsfsuDqCX164DWdfeArvp1wfbxVg9ni9x38BPCTgjsQbaVTy6eRXyVprpaW0F1A==@lists.infradead.org X-Gm-Message-State: AOJu0YyJna+qugHzP1whpXBOsHF4v7OVnRXaLfydhMgVODuwqgic/88S wbimcT3yQktliSp55OvuBxCA9ZNWp4snhfQ80GCPYOTyDBqxvRPD3C66U/SdM5mckcGxRMZnY8y fq4I= X-Gm-Gg: ASbGncto3oc+CJssZ//LzRcvwKn1LU74UO4wcIc8WyEmHhdgZVHDctPd8TRTBe7qImP 5oAJcdgajF+GS9kYi9pxBzrCJHTHcwvY/dMPt0jgHURiYMRbypVq5LeD/8E/vSRDAjaGreDvmw0 euIakql6hEGMBTrfWH6lhlvLYAQHu7Y/yBMhOj4ILHxweyAFReC11d7Awwy5SrJroou7yXiWg10 x1u2dk2rTS2MAYSOxvxv0/g/BClnjFRCSznuuUzrmI5aEcq04qlhFMi/rHPS5LMhhSq5q6kBBwg /Kwk8n09hTRSmNVhxblECaExds2ixmeovh1iIv1lqTePpl3yNtmwe0Q= X-Google-Smtp-Source: AGHT+IH3PInyMoZqyc0SRTAjhuFIMbhus6lgn+l4uL8MxLHlStsGNic2bJF7E2l/TEt5N03Sy8JF7A== X-Received: by 2002:a05:620a:4382:b0:7b1:56f0:e09f with SMTP id af79cd13be357-7bffcda14b6mr4536316585a.54.1738655742363; Mon, 03 Feb 2025 23:55:42 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:41 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 08/10] irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC Date: Tue, 4 Feb 2025 13:24:03 +0530 Message-ID: <20250204075405.824721-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235543_391066_656A0C20 X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Implement irq_force_complete_move() for IMSIC driver so that in-flight vector movements on a CPU can be cleaned-up when the CPU goes down. Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 32 ++++++++++++++++++++++ drivers/irqchip/irq-riscv-imsic-state.c | 17 ++++++++++++ drivers/irqchip/irq-riscv-imsic-state.h | 1 + 3 files changed, 50 insertions(+) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index 2fab20d2ce3e..fae47b8ccf73 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -156,6 +156,37 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask return IRQ_SET_MASK_OK_DONE; } + +static void imsic_irq_force_complete_move(struct irq_data *d) +{ + struct imsic_vector *mvec, *vec = irq_data_get_irq_chip_data(d); + unsigned int cpu = smp_processor_id(); + + if (WARN_ON(!vec)) + return; + + /* Do nothing if there is no in-flight move */ + mvec = imsic_vector_get_move(vec); + if (!mvec) + return; + + /* Do nothing if the old IMSIC vector does not belong to current CPU */ + if (mvec->cpu != cpu) + return; + + /* + * The best we can do is force cleanup the old IMSIC vector. + * + * The challenges over here are same as x86 vector domain so + * refer to the comments in irq_force_complete_move() function + * implemented at arch/x86/kernel/apic/vector.c. + */ + + /* Force cleanup in-flight move */ + pr_info("IRQ fixup: irq %d move in progress, old vector cpu %d local_id %d\n", + d->irq, mvec->cpu, mvec->local_id); + imsic_vector_force_move_cleanup(vec); +} #endif static struct irq_chip imsic_irq_base_chip = { @@ -164,6 +195,7 @@ static struct irq_chip imsic_irq_base_chip = { .irq_unmask = imsic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity = imsic_irq_set_affinity, + .irq_force_complete_move = imsic_irq_force_complete_move, #endif .irq_retrigger = imsic_irq_retrigger, .irq_compose_msi_msg = imsic_irq_compose_msg, diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index 649012cc47a8..54773c27c411 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -332,6 +332,23 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } +void imsic_vector_force_move_cleanup(struct imsic_vector *vec) +{ + struct imsic_local_priv *lpriv; + struct imsic_vector *mvec; + unsigned long flags; + + lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu); + raw_spin_lock_irqsave(&lpriv->lock, flags); + + mvec = READ_ONCE(vec->move_prev); + WRITE_ONCE(vec->move_prev, NULL); + if (mvec) + imsic_vector_free(mvec); + + raw_spin_unlock_irqrestore(&lpriv->lock, flags); +} + static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struct imsic_vector *vec, bool is_old_vec, bool new_enable, struct imsic_vector *move_vec) diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-riscv-imsic-state.h index f02842b84ed5..19dea0c77738 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -91,6 +91,7 @@ static inline struct imsic_vector *imsic_vector_get_move(struct imsic_vector *ve return READ_ONCE(vec->move_prev); } +void imsic_vector_force_move_cleanup(struct imsic_vector *vec); void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *new_vec); struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned int local_id); From patchwork Tue Feb 4 07:54:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76A99C0218F for ; Tue, 4 Feb 2025 08:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x2GEAc2lz6irBN0E+56JNTFzlyId7oZxwwvKPU5+m0k=; b=Nc1PwmY7pfZN50 29hWp5eu1iyMNVxrKIDclO1S9a3Yd+OaDVFfDoh9BX760oDbBDrIxuqTw9rD4+zV9p569YPXm9Yc0 g0mVLooHuj6fk7HAHAVW9f0JKBjJ/KaxcQy9i9NpPZm4KQBjD6TDRzM4hWhtzJgyqrFcAecql2T+1 nBfUL7H+5JeI8dtOtkeaPK4EnTWaCRfc2y/poHCgKSPnXn0rg3a0aqRAApzIhpAEupxopScaeN89T YIIS7ad/d8w/tMwHTx0Zygk1JpKYvfLXMUfirTW8Sk5rrllF8xUnhmdPuZKRoCV2rFhA+Lucim8GQ XSnKL8Bs6SjZJwA2p7fw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDzA-0000000HUx6-053T; Tue, 04 Feb 2025 08:08:44 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDmj-0000000HT21-10nI for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:55:55 +0000 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-7bcf32a6582so466921185a.1 for ; Mon, 03 Feb 2025 23:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655752; x=1739260552; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3gEwcaDf3FiyZX0vTyT/9XCNNLKunHvBb/ApGbPO13I=; b=BAJ8CwJ/DVmyUhEdQNSQBTJZTBech1LS87zix86GEM+PzkX/mDXV9X80yhmciEsiJL BCocVTNDlHXlNftUoB2QYbctLVsMkxKlHGBK+XyaEW1CrCsHccPW0/Os2nkgOk8NULzp 2xYCNo/h3k8IfS6PBGg/+KCdKunZltt4YNSKEoz7lrxne5XmUe8fk9VL+GMV4G66N8yT yjOwL1mqarTdCyuRR85UFus5iFeclUtcvjI6jr9trgoE3VOgmnQVxb4wEIlQzfwEWi+Z U8GSymW9Ucws40LbmiK0X9Z5wGu+DFvNnKCh8P/eEIT8oj2I1u17FEaSp9nJRzV32zOo OUWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655752; x=1739260552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3gEwcaDf3FiyZX0vTyT/9XCNNLKunHvBb/ApGbPO13I=; b=P0y9FBnEviInMqJ5THtlacSkvR/Fx0sKIwAbweq+uhfYEJu7eeXfyf0zC0te5CHWdB OU8Ueir3vZwc0okIESgmdNwPJN1gl8q0EgVgk/9087HPltB+rL8FjuwtNeNn1yL+R0Ef ZoptikLolG0H1sLKoOJ6lPVhYUgh1h9UVWZv4SZKjLSx4/cKqK/1jS2tq29ArVT7sqqa j7zze0ncwQ69GDGKcNNbepN4z3To/IIRZ9IrOV02hV7sUd0gtOVw/IU+7CFScQDUQQA9 5YSJv9snmInaBwcEQN/yoGTo548TQJtlSiAufL7OdPPZckJrRE4rmWbleqUjLXxF5yqE GxCg== X-Forwarded-Encrypted: i=1; AJvYcCU3LFLJEeKwG0PqGPHQfFoQxDifNTViadTHe/t4ocmKCk/CI6f9y6pANy/l/B2AMRREW2A94FhbXTBcZg==@lists.infradead.org X-Gm-Message-State: AOJu0YyvAUuuZrGqE/gk23GbryN+fpAdVLPlKSulocCZ94oekAg18l5P fY71ONcZBZeqzJvz0zuIvrJHvflj9HXyCDdNykLz8jW5BiDB6Lb9wIED6wGrQIs= X-Gm-Gg: ASbGncvL55HYWQt0jSa7fyBWNPb9bw/FL2tXd0XFAp57uaUoTkiWWXmAO1q8ksqbYHd npmK8sO7F1kuuPzDr0GcUmECUjJ572qYghCogzyLl4oU00gAr6LbZaS3TUvEoio3NEPHHjyclfo 58iPVRnOr7jL+a2XGWAGjhllgh4SivlR0sZm/S7YAB/scOmveQWuyU9EnpgLC1SflqF+4YIYHPn 9PWXI4B6TLb+CSv8jW4JCzQuQFFWHivLt1BTCpeEmWISfUNLyRX8g2OFz3uMxUTzthL3JBmB8DK lRiMmsy9Q6vIxIqdIV1/N6zxDoAts3ly+ebuND3nTyOgZNgH3Z8gJOA= X-Google-Smtp-Source: AGHT+IE1kqeyReImTVJHGW5IDLgtzpBSrI2/ZE4aOj+o6f7vrc3hrNQAxAn/RUr7v38bA4d+4LAZBQ== X-Received: by 2002:a05:620a:2992:b0:7b9:a387:3cd8 with SMTP id af79cd13be357-7bffcd956e1mr2941465585a.42.1738655751905; Mon, 03 Feb 2025 23:55:51 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:51 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 09/10] irqchip/riscv-imsic: Replace hwirq with irq in the IMSIC vector Date: Tue, 4 Feb 2025 13:24:04 +0530 Message-ID: <20250204075405.824721-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235553_275017_6281FDD9 X-CRM114-Status: GOOD ( 16.44 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, the imsic_handle_irq() uses generic_handle_domain_irq() to handle the irq which internally has an extra step of resolving hwirq using domain. This extra step can be avoided by replacing hwirq with irq in the IMSIC vector and directly calling generic_handle_irq(). Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-early.c | 6 ++---- drivers/irqchip/irq-riscv-imsic-platform.c | 2 +- drivers/irqchip/irq-riscv-imsic-state.c | 8 ++++---- drivers/irqchip/irq-riscv-imsic-state.h | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-riscv-imsic-early.c index 73a93ce8668f..0c94ce8ce580 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -73,7 +73,7 @@ static int __init imsic_ipi_domain_init(void) { return 0; } static void imsic_handle_irq(struct irq_desc *desc) { struct irq_chip *chip = irq_desc_get_chip(desc); - int err, cpu = smp_processor_id(); + int cpu = smp_processor_id(); struct imsic_vector *vec; unsigned long local_id; @@ -103,9 +103,7 @@ static void imsic_handle_irq(struct irq_desc *desc) continue; } - err = generic_handle_domain_irq(imsic->base_domain, vec->hwirq); - if (unlikely(err)) - pr_warn_ratelimited("hwirq 0x%x mapping not found\n", vec->hwirq); + generic_handle_irq(vec->irq); } chained_irq_exit(chip, desc); diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index fae47b8ccf73..e6c81718ba78 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -112,7 +112,7 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask return -EBUSY; /* Get a new vector on the desired set of CPUs */ - new_vec = imsic_vector_alloc(old_vec->hwirq, mask_val); + new_vec = imsic_vector_alloc(old_vec->irq, mask_val); if (!new_vec) return -ENOSPC; diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index 54773c27c411..e70f497a9326 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -443,7 +443,7 @@ struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned int l return &lpriv->vectors[local_id]; } -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct cpumask *mask) +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpumask *mask) { struct imsic_vector *vec = NULL; struct imsic_local_priv *lpriv; @@ -459,7 +459,7 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct cpumask lpriv = per_cpu_ptr(imsic->lpriv, cpu); vec = &lpriv->vectors[local_id]; - vec->hwirq = hwirq; + vec->irq = irq; vec->enable = false; vec->move_next = NULL; vec->move_prev = NULL; @@ -472,7 +472,7 @@ void imsic_vector_free(struct imsic_vector *vec) unsigned long flags; raw_spin_lock_irqsave(&imsic->matrix_lock, flags); - vec->hwirq = UINT_MAX; + vec->irq = 0; irq_matrix_free(imsic->matrix, vec->cpu, vec->local_id, false); raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags); } @@ -531,7 +531,7 @@ static int __init imsic_local_init(void) vec = &lpriv->vectors[i]; vec->cpu = cpu; vec->local_id = i; - vec->hwirq = UINT_MAX; + vec->irq = 0; } } diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-riscv-imsic-state.h index 19dea0c77738..3202ffa4e849 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -20,7 +20,7 @@ struct imsic_vector { unsigned int cpu; unsigned int local_id; /* Details saved by driver in the vector */ - unsigned int hwirq; + unsigned int irq; /* Details accessed using local lock held */ bool enable; struct imsic_vector *move_next; @@ -96,7 +96,7 @@ void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *new_ve struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned int local_id); -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct cpumask *mask); +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpumask *mask); void imsic_vector_free(struct imsic_vector *vector); void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec, int ind); From patchwork Tue Feb 4 07:54:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13958772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2387EC02197 for ; Tue, 4 Feb 2025 08:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BERYYEdjvaLK8gKdO7RKdtx7EENt2M7IUO4qC18oixA=; b=R5nZbb0/dYJK82 I9OXx9uDb/5hUDagrFY7pll9oHn5rO+ixWYnP29PDALbo0xzYII4ea2QqWh7TL0Ci1kV4JShWgELr wTO4sHt8gk9+O0rZbwExrXqqM/xbS9bFkOg2hJV3crz2VnQ3gSZAbH4acT4Ots0mSFCGsoAM5mEgr Ws6N0t1/34C1/C3pThj56tZqSJGH+8GQn//Z/3IZR8SJE5ZmLXKw1HmOzphZjFleIEzT8Ogo/kHNi +cdP09Rb2iRcS27ZJtUmtZLT9QCGOw95GgmGszDWjbFipco8XtDB3uzHN6KM57ceIQIJgTlPd/irc oxqjH2xs7/d0IfygxSPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDzA-0000000HUxM-2d8O; Tue, 04 Feb 2025 08:08:44 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDmr-0000000HT5J-40cd for linux-riscv@lists.infradead.org; Tue, 04 Feb 2025 07:56:03 +0000 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-7b702c3c021so507740385a.3 for ; Mon, 03 Feb 2025 23:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655761; x=1739260561; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6MADFF5SwXkzmIBLKmDVwps1qS+gME3ryVy0pflkh7M=; b=j4P7OOWCnze8L1Xes5hSunclSvSbEUl1Z9Qb4Dgo6OYXsgqzo5R27iUMT4y5YNk0HR 2bMDH5nONDRTgDr1jk5xTC7o7zsChVb68eBvqfe1Ir82P7nkeEUv9HRkIErKm5wybwIb 6Mi4le7ZG8wiWibQw+AQIiv5hXlotFu/UoXtAnrVJFoJVJDAwVwFFfd6lLexUsbM40tl PRzOS7Sjipd89y9UkxJazznWkvMkNAyt8VA0NODw+vDLbxk//QoqE1pwVCe+//gMATLn E6XaCXXzattrlVj3z7OxBrIB0e5fgUGtrOxIQKVQnqEUIYZmwino5DBpHIvlnplpEFbj AATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655761; x=1739260561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6MADFF5SwXkzmIBLKmDVwps1qS+gME3ryVy0pflkh7M=; b=PGDnbH6ueb3uRGl80I5X0uGQJchriVJpRGQQJlsUJc6PxhEwVhv3G0uvacmXuTi7sC D2XReY0VVSuAsIGehBAawEZ6UnQQu04nvz6rDEFutqztV5iZEiS6j4AT8wFW8CIXxjid EsnxVeqojTQN9fY8AtreK0lohaun0pRIw42SPbd98ukhJd3IBJ4EVC4tVnz1raUKuAbP ufDULwCNjKRn6JsC3o3lrzubOMVRDz2OXp4H93oIWxIhtI4iohv11Gm1Hrs6AfP5I1Te +I2rNXk3j+/ruMhVD5ha/PeBkenKlXffgWV0SbreEwNjv1N/ULqBH0MgvPII7bGscpfY k5Cw== X-Forwarded-Encrypted: i=1; AJvYcCWSqZhm5ajDFDJ171WKlQaBScLezfUnv690YsOnnag/+WoxHzyccWZHhAmfnuZikuzOJrb3VRRSn96hPw==@lists.infradead.org X-Gm-Message-State: AOJu0YyIK63yrLu80wMZp/363SR5E02OKA6rsHIwdI2eu9NYj77N1Z6D F5OdLSuaQJ5jD+mKNHjs/mLVHEwFz3BBeqzbHQJC6DpPA0nk6S05LCjGwVwrlC0= X-Gm-Gg: ASbGncvUbx0w5FRZ4Zq+aV5zqWVLJuvYcFE85zGmIwCr3941EPlv8KPQ/ZBGFg+IDxf 2TIiu8FRhVy452VLTnTUpLGpduIgecTiB2hjJyIpBndAbn5KlmTQdflaaPrFPJsVFnNri8ySBNS 0Bde9vF/o5UZrhvAiXjagJ4qwQyB+UwQVug5rO1mPsiFDVLt4H5QMz2oJQvY+15aRHG8Llw98KZ CzzcP1B9oVNqpEgeA4MwfbBY9oMcByUiWiQpVQ6QR9LusJVtn1ZBxPRxdf5/De/eQsDj0UBotu7 fW3s12czZBh6GpJ/v3MnMHu/gHjbbdkSRyBZaNSd/NABUnzBi0BO7UU= X-Google-Smtp-Source: AGHT+IF7prdvtKiSyJ0NFqTW4MBl378F96libEZvgvmb2g4BOpM5Yj9BonZGCkzjTLLgOdYhNcWtUA== X-Received: by 2002:a05:620a:8427:b0:7c0:a2:e68a with SMTP id af79cd13be357-7c000a2e980mr2573236785a.30.1738655761078; Mon, 03 Feb 2025 23:56:01 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:56:00 -0800 (PST) From: Anup Patel To: Thomas Gleixner Subject: [PATCH v3 10/10] irqchip/riscv-imsic: Use IRQCHIP_MOVE_DEFERRED flag for PCI devices Date: Tue, 4 Feb 2025 13:24:05 +0530 Message-ID: <20250204075405.824721-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250203_235601_998398_02E69B72 X-CRM114-Status: GOOD ( 23.80 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Andrew Lunn , imx@lists.linux.dev, Marc Zyngier , Sascha Hauer , Atish Patra , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Pengutronix Kernel Team , Paul Walmsley , Anup Patel , Andrew Jones , Shawn Guo , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Devices (such as PCI) which have non-atomic MSI update should migrate irq in the interrupt-context so use IRQCHIP_MOVE_DEFERRED flag for corresponding irqchips. The use of IRQCHIP_MOVE_DEFERRED further simplifies IMSIC vector movement as follows: 1) No need to handle the intermediate state seen by devices with non-atomic MSI update because imsic_irq_set_affinity() is called in the interrupt-context with interrupt masked. 2) No need to check temporary vector when completing vector movement on the old CPU in __imsic_local_sync(). 3) No need to call imsic_local_sync_all() from imsic_handle_irq() Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 74 ++++++++++++++-------- drivers/irqchip/irq-riscv-imsic-state.c | 25 +------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index e6c81718ba78..eac7f358bbba 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -64,6 +64,11 @@ static int imsic_irq_retrigger(struct irq_data *d) return 0; } +static void imsic_irq_ack(struct irq_data *d) +{ + irq_move_irq(d); +} + static void imsic_irq_compose_vector_msg(struct imsic_vector *vec, struct msi_msg *msg) { phys_addr_t msi_addr; @@ -97,7 +102,20 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; - struct imsic_vector tmp_vec; + + /* + * Requirements for the downstream irqdomains (or devices): + * + * 1) Downstream irqdomains (or devices) with atomic MSI update can + * happily do imsic_irq_set_affinity() in the process-context on + * any CPU so the irqchip of such irqdomains must not set the + * IRQCHIP_MOVE_DEFERRED flag. + * + * 2) Downstream irqdomains (or devices) with non-atomic MSI update + * must do imsic_irq_set_affinity() in the interrupt-context upon + * next interrupt so the irqchip of such irqdomains must set the + * IRQCHIP_MOVE_DEFERRED flag. + */ old_vec = irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) @@ -117,31 +135,13 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask return -ENOSPC; /* - * Device having non-atomic MSI update might see an intermediate - * state when changing target IMSIC vector from one CPU to another. - * - * To avoid losing interrupt to some intermediate state, do the - * following (just like x86 APIC): - * - * 1) First write a temporary IMSIC vector to the device which - * has MSI address same as the old IMSIC vector but MSI data - * matches the new IMSIC vector. - * - * 2) Next write the new IMSIC vector to the device. - * - * Based on the above, the __imsic_local_sync() must check both - * old MSI data and new MSI data on the old CPU for pending + * Downstream irqdomains (or devices) with non-atomic MSI update + * may see an intermediate state when changing target IMSIC vector + * from one CPU to another but using the IRQCHIP_MOVE_DEFERRED + * flag this is taken care because imsic_irq_set_affinity() is + * called in the interrupt-context with interrupt masked. */ - if (new_vec->local_id != old_vec->local_id) { - /* Setup temporary vector */ - tmp_vec.cpu = old_vec->cpu; - tmp_vec.local_id = new_vec->local_id; - - /* Point device to the temporary vector */ - imsic_msi_update_msg(irq_get_irq_data(d->irq), &tmp_vec); - } - /* Point device to the new vector */ imsic_msi_update_msg(irq_get_irq_data(d->irq), new_vec); @@ -198,6 +198,7 @@ static struct irq_chip imsic_irq_base_chip = { .irq_force_complete_move = imsic_irq_force_complete_move, #endif .irq_retrigger = imsic_irq_retrigger, + .irq_ack = imsic_irq_ack, .irq_compose_msi_msg = imsic_irq_compose_msg, .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, @@ -217,7 +218,7 @@ static int imsic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, return -ENOSPC; irq_domain_set_info(domain, virq, virq, &imsic_irq_base_chip, vec, - handle_simple_irq, NULL, NULL); + handle_edge_irq, NULL, NULL); irq_set_noprobe(virq); irq_set_affinity(virq, cpu_online_mask); irq_data_update_effective_affinity(irq_get_irq_data(virq), cpumask_of(vec->cpu)); @@ -256,15 +257,36 @@ static const struct irq_domain_ops imsic_base_domain_ops = { #endif }; +static bool imsic_init_dev_msi_info(struct device *dev, + struct irq_domain *domain, + struct irq_domain *real_parent, + struct msi_domain_info *info) +{ + if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info)) + return false; + + switch (info->bus_token) { + case DOMAIN_BUS_PCI_DEVICE_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSIX: + info->chip->flags |= IRQCHIP_MOVE_DEFERRED; + break; + default: + break; + } + + return true; +} + static const struct msi_parent_ops imsic_msi_parent_ops = { .supported_flags = MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_PCI_MSI_MASK_PARENT, + .chip_flags = MSI_CHIP_FLAG_SET_ACK, .bus_select_token = DOMAIN_BUS_NEXUS, .bus_select_mask = MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info = msi_lib_init_dev_msi_info, + .init_dev_msi_info = imsic_init_dev_msi_info, }; int imsic_irqdomain_init(void) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c index e70f497a9326..f9b2cec72ff2 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -126,8 +126,8 @@ void __imsic_eix_update(unsigned long base_id, unsigned long num_id, bool pend, static bool __imsic_local_sync(struct imsic_local_priv *lpriv) { - struct imsic_local_config *tlocal, *mlocal; - struct imsic_vector *vec, *tvec, *mvec; + struct imsic_local_config *mlocal; + struct imsic_vector *vec, *mvec; bool ret = true; int i; @@ -170,27 +170,6 @@ static bool __imsic_local_sync(struct imsic_local_priv *lpriv) */ mvec = READ_ONCE(vec->move_next); if (mvec) { - /* - * Device having non-atomic MSI update might see an - * intermediate state so check both old ID and new ID - * for pending interrupts. - * - * For details, refer imsic_irq_set_affinity(). - */ - - tvec = vec->local_id == mvec->local_id ? - NULL : &lpriv->vectors[mvec->local_id]; - if (tvec && __imsic_id_read_clear_pending(tvec->local_id)) { - /* Retrigger temporary vector if it was already in-use */ - if (READ_ONCE(tvec->enable)) { - tlocal = per_cpu_ptr(imsic->global.local, tvec->cpu); - writel_relaxed(tvec->local_id, tlocal->msi_va); - } - - mlocal = per_cpu_ptr(imsic->global.local, mvec->cpu); - writel_relaxed(mvec->local_id, mlocal->msi_va); - } - if (__imsic_id_read_clear_pending(vec->local_id)) { mlocal = per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va);