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: 13958750 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 1D7D3C0218F for ; Tue, 4 Feb 2025 07:57:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CBfvQ3kWrJIo4ZX2fO574K2xNLHLI8xt5fD3UcZCgGE=; b=XxwxwVSWIKX40hIjTUGgu7xKSk Q5F6iL+b2jPzHAwn2330/CZoXOs9lv0Od1GUWz9XI0K9+oXL1tqZDn+LLwOcJfBHWuoEU9QCs6oOz Bam52yUyaLrOX1LyBjSSBp0V1Od7lf3kYs9h8D5FrznfZLmF26S6D5ZTST2mEV/cmanYlS7C+KHp6 HTV+zgEZ4jsDy+SUUgXoafkUAaiPUsRgMZdLz718PM2HGSwj/u02gVAL2Pdh1MHLNaMTmAbstswYU L1X1zbocEhgfLhC6aIA4IlXv+noks7wFQs0su06TKSsemUSxUqe0drprhqD0t10mZpWapMLkHP7U0 JoV/UFvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDoa-0000000HTRL-0J2f; Tue, 04 Feb 2025 07:57:48 +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 1tfDlS-0000000HSdD-2n5t for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:54:35 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b6fc3e9e4aso482097885a.2 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=dPGi+9Bc/paoGRgkizawhMLJrllFPfGdc7fYMZe2NyGhN+2Knb7ZHqYOK7xkJENHNw HrEJimPbaF+BQlUCXV2Iu0PTpj7SzYFGpqJErBv90AxulaZNtlKKaEfgpC8sLDn+2l2p GrwPeb3LvkrOrFd8ghdGgFysDv4eXg1oTdg/ozKVEKigZ0iVLOXWgXCiExOeKGLahf/d i1pZaA+H9XlBIo1nfaZA80ESv0zJTKTO7D422bgw0wakBu9TlaPToUwbsJKoGQEGdmpc wqW+Lz6fKXyi5FhO0jQRD2nzYunrLTdgClrY4R5jLYpLQN9v1jSsFvpha3HUfFDrTIly EQEg== X-Forwarded-Encrypted: i=1; AJvYcCXhbcdtPsVPBZ9EQEOxWhv4im6KhKG8NZ5CAlj4V1LwwWL6iKg3t7Tr0sNW7TCWhId4V2NXOfWXkQoDYbPZpP9Y@lists.infradead.org X-Gm-Message-State: AOJu0YzXCxJ5RHjgkfQvN1v2tdOhMs8fk6bxq+asUjdTOxj7+A8fRypb w4c91I4Z5sw+jBWrnCy9Eop0KbCRj3IETXG827VXPD2WdklKKMizCLpaisFmTBg= X-Gm-Gg: ASbGncubP7s+K/SQgAwVmhwzmWEBPtPIGYivqq6S0iZZJL0d/x5gb3iVc17SobfA8Pb me8b5DcA+k/jQv2BDIv8837fv0pEhXga3B5VkorjA8knb0xp/dRfgRF3zdVrYUgBAtbB/dDpmrS 88wyKrpV4qAdQUu0vJT+ybn4Q1eLsCCQDLU2JmYv9DbkiTHiNNcbt5hlynsZMOnBNYgnDS9A/Vh T9lEtOqvAVs9kr8sxzHVzD+dxy7jL9wqMvqkf4ynwW1ObSjBzRnItaMyrgEb0XhadE1z2L1fulJ UVYoz9g07OdQthLw6CEaf2+i26c+rdeydM971lZJKy4v5PoFhxt4yZY= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_701319_9570B61B X-CRM114-Status: GOOD ( 22.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958751 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 B6001C02193 for ; Tue, 4 Feb 2025 07:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=Q0rLII2VAHwTTGqkCn+sVK4wKo hNVDOOXXaQvrRXwrBP8sF+mlpy58OYPLnY3pfr6/hTj14fO5E+D9LM9qBxHgi7ad18+zHl4SRhyCP Kcp7FQgpegd7t3BTB4FCT/s0hvNoO1gn0ppKjUC9zSmLMAEIm4eqjJ3/pOezwbE+Ocdo10gJiAJSO oe1rJlcXzX7Fu+ea5yCqW5keo7RruYNOddAV470PfTFi+Rqxim1LDZ+HN0hN8zax+ciBjGqop2JW5 /ZPxZ3jm5SAnS9Zre+PPKPZhOU0Fv0ZI1Z/96yfz85r3GEXZIrgVHzmgMct/jSKhF7NvLNvIht9G0 gZSewyew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDpv-0000000HTeS-1Ge7; Tue, 04 Feb 2025 07:59:11 +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-0000000HSfQ-48Bl for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:54:45 +0000 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7b6e9db19c8so477581785a.3 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=XaGPI9y5WtDaMxdMYPUMLaG6E0CV1QhBhaMcRLsSQ52Vg0/XuiVSeh8TEJA3/A4A7k 8s6IyRgtrvRwmLUCMbQzPgQzwxAklo0RJV3tt/eMEC4+8wPw4shihxdplWRKb+0upNx0 6AYg9Nd+sf4x6T+MjVzE1cP0Pr7A9RSmxuhWi1lq7E0q9fIlbrUIIXRHZhcPIxrcML/N XinSK5inJ28ZiGhyOM5kXBSqnu6daeGQHTeN37IJZPGFPGoVP/x5fQfUMN93ds8KioGN RECxJfLplXlCygsoV694pCNaZD97mp1Ecok8I4PZ/C85Wcxb9/IrwcnuBScXaJISbX9Y /C8g== X-Forwarded-Encrypted: i=1; AJvYcCVbLhku3HFL+g+l8sBca1t+5yszWgG6lyM8BE2eZ5SO0n4d3M0SliUINzOoLntTda3Tt66NWaMYUC7tRaTT2Rz2@lists.infradead.org X-Gm-Message-State: AOJu0YycS39zhLhHPUxc0L36cJg+UiTOm0Z14lihmLXfIfJiLz+4RsAd Q8dqRBwn3Oj8UnpHkHTbiFfEc6BsEJefI0nA9Kqv9SQYJPsL5sNl90qZ2gZT5Nm+VZKhxGMuimE BZ74= X-Gm-Gg: ASbGnctkGak4Y/id19OdAYQD0IXKib9hGh9mD5Ddr5u13mJPIl5PKpkJLG8XxrvmjDi EJqhcq+iLz8ICOSUn4z34XbFtJ8CZ7KasD425Az3DEwOyleawLYcZi7uSc27E1irEEY6K4HzoxT wxeGNbyao7rjkPvazw8L1ISHrOtfMxDxanhNwOYb/UKlj08TMFU3NHW/prTNTMzfxKYikPU2erp WrnML4MIyT0R2RtkjHX6gz6kYVasSg3Lk5fd1XBJMZkSkBtwITyL+AJZs8+NZtBKQyPT5vFvRRH xTaanLkFKkqhdJjzGTkZXFJOzuvLTBBDCSwkbFDcbQ5eHE1RxSdx8xg= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_034297_FB06CE5A X-CRM114-Status: GOOD ( 18.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958756 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 9F6ADC0218F for ; Tue, 4 Feb 2025 08:00: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+XpbAvyCPU7XjesnTrNMuPwq8s0Ofi62LAN8USKi2As=; b=GMHM0d4x5An4cNvcz9bp1g/m/A 5Xn5MtZ/9K8QMstzfx7jX6K91kBAuZFqtYRS03DJL3uKE6A/MK5vcBGQ0y76/nwXU6ow/0/Jglgwf V9bK1w/mpHycNDYRAoNN6S/tLX+1OPedzAmEgxk9GcAq3mTS0oP18eDCTT8KpP4wsHfO/L9+PRZ2n +PQXup/zCxJESwpAosx3rl0roDNaDRR6OkQlBol+lz8lSCPSb8RZbNWUfo+A6YyjLn8KuxDK5ZbC1 mGCM6/1P8RelaSBhpHk3b0JMFN3KilhO2nQ25lU4t0OzyDUEmkyxX9dd+R1cq49dMadeVJc7Hv0XF NSRPDeWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDrE-0000000HTsm-2OY5; Tue, 04 Feb 2025 08:00:32 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDll-0000000HShZ-0u2u for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:54:54 +0000 Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-7b6edb82f85so781530985a.3 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=xDCsuEScirjA56sWhiHRFN/5966oItpPSR2JkMTE49RMIWtRFSMjtiSmh5Rp9Tq9+/ MDwS6Wu/pGkZtRyN9Kk2y4bKVtXN5cYcKjUdC0jjKu0sImzvKcj0zPFpwNEFs3ipZrjp 4S7btwSpM8r6XAC20THhIWTr2DpzwBBp8ILda5gpPm9xxHIcjggSc6wRsHwFbFO8JUpO 357nScXWsIHrEd6xhF+NULxQs4IhndD+pUiGwNBXWgzyEkneeVbAUYgR4Sv4ODOKF+gA MwK11cl1Ia4ayemFL/kLQD42pWm9/26KVhZpes5u6wZaChrfuHmpHx8/t8NzaLxqY3Oi vmwg== X-Forwarded-Encrypted: i=1; AJvYcCVssyFMCzSrmWil9NqCeY0D7Wv9PSupNc3S8TcExXLP2NGMw1jnxx7gr91rrqPyI5KGxDgQn6ZD4oYTfCf9nQUk@lists.infradead.org X-Gm-Message-State: AOJu0YxsJdDoTbZ/0iwcoC5f5hCHciAZ9HOr3v2Ejxl45hnj6RYsOIwy qdmcMkE3YkF9c/qZHbCfRLSwjimFbrlfifXbVq4AsahMoivlXTTd/3gPPBWxDLE= X-Gm-Gg: ASbGnctk1lHVKXpjdgDQUr7xzMTwySTqZNhm5bUQwe6fkZAD5NXzBxJstkOxzZY9MMD YziMxK0vf/9dpXA7zPkO6tKSFn9wf70trFDwAvvF2NmKRuRzqN1ok2Dal74zNBnjlMTAwsy1OeU 8KkvxKJFl2VaeyNbyjr6HWqi/A4UAEp4un+e1K9WaBTCEdwyz8otXg1E7WGvSH7xLmFeyAkBgmX tcux8AOv/QP8NILXWiryhUEqHzWo0q7fDd3wFly/cTxZzWH/yfFgH/SwreulhKC6agdyLoO/X0N o6v1Brx6OSnq0K6tGZQML9SEVvdy3D1F+yqM7aS6uztV8zjHhlQCBMY= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_278182_2D6C185B X-CRM114-Status: GOOD ( 15.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958757 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 776CBC0218F for ; Tue, 4 Feb 2025 08:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zt4BUR1O09akAiE35kyzRFyQQsTBDdGx/Mpea27bkKs=; b=fac5rYGh7Xrmmf00zL9XvEaxC0 2MP6YP+DKDKDQDKeM2Ek4hiyIamTqIhHooMb1Ew11H7a/6IpubLAzNWWk5sti20RyGKaEfOyD7X+9 yCcBbU1u2tuUVGGdeufHnnNghEO+PXxwV19rk0diQy/pRMTUcceuGkEIjsEpv40IGROctVwTetext 3DrqYub/X0hzcF9JZMyNL+I7P+DTYjvtUBEPTch+qfS2cJ2SUk0EJMda7L05aar2flL8FMgjGKQWE +Nh4W3Zx/+Y9ho+4+GzhPZxdpsKVS1KR78VEa7XTw4gF+hWhCf5DnjDjSibv1mrNYOf/Bkc+XvzhN DUzBNang==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDsZ-0000000HTzL-0rHm; Tue, 04 Feb 2025 08:01:55 +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 1tfDlu-0000000HSkd-25DJ for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:03 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b6ed9ed5b9so888128085a.2 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=v6eCc/gEXanyKd/9b881ehVvLxVnyXdDvW6RuHUFHVL9IQN8r/SrzSBFzp1LN6WiYD Lb8LUVbTSC1FWuER1RmicIhPyz22WlSZ7yClFX5l0TYrL471nhpflw58YVph3rsVaWD8 MZE05CoT8zMqo/lIRcztwYRJ+mkB25RCB8JY+n6HcqwH1K0uJAnut+XSKE8eaW5fpLrX 1ZIm5r4KBsaI4+/M3Cmrf4LVXIatnk6POq0ksHqIOxQ4UiJdRONqXItVUPzJ8eS05aOK 7cyTyvW5z0JUSXc2U1bYxPbXPS81Md9GIsjcBv7oYoS9A5847WQOi9qYOd8oTVz9/31s 5EEA== X-Forwarded-Encrypted: i=1; AJvYcCUkjNPeYUFvkmMGhcEJjRsPcT0ysDEwYWaYLH1tEwbBqZIXZpth/+yUD0AKEUaZI5c3k0FMyTM3CL3bd2igpQt+@lists.infradead.org X-Gm-Message-State: AOJu0Ywl377Hkp/WdTiJerX1KPYsPIm9mA7prUlRUM9CpotpqIBabw4d wQ90jjuUS/yLkRo7PRuCcMYoDnU4OjOEbIhmfxOyfNMBdTJdWDa6930Y/Sho/Bs= X-Gm-Gg: ASbGnct3D5TCkZyOsNzDAxq1z73neh/HHd2Dt0i1XfqHd3iS1L5YAjN/2J3oKNVKPij 3cwbf8CZ3ORn1iDFB9zdeRDNg2mQYMqC9IdOfhFUe3mS0RV/PmSUE5FTdoIqoKIvFJAepiQG1Zr av1Sg1bZHp+cooxYKQYl/811GsgKoaCoAkjLjCZWfd6gM7dk/jos/D7J5FlsMjvyHn8P/qLyRq1 dJ/Uj+yp5fEjNUVjasoE6bsjKTh0+Bc+AN5sip3of/GOdmPSB3NkSAwgmHv/HbfQwjlLW8JyHYT 02T6hgprxJqj83PuabCs/Tu7T6Lum2wJosflJf5YEJL3CdbudaIhrBY= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_539257_00B1BC7C X-CRM114-Status: GOOD ( 17.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958758 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 B7254C0218F for ; Tue, 4 Feb 2025 08:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zXz6fvQA0XjFVpb2cpM8OodOs5mmbZEn6PcelI8ZWow=; b=Nk4UOg9dnTXi+t4GQB5jwLvzfc I1dxgRpVO0QaDQKAac2jaF/mMHbMDej1koF0Ue8A5UoawVfTfD4f79GJs0j33rO9EJhu+DSqTTJBt f/g4s1pFO19i0VGQeT3SdUPUuJRyuagXt3LZW92HuSZvacR3JogpKfN7ZrQPnxPwPRR+0qnA0trqa eqmnsevyz7W/ql4X+/a1YKq6vVBDhRLcU5hGsC+E7eWwEHs4dKDTRjwW9M57GPlBGPsvumfhTd8qS Q84bVBc3ZCZTZFCOdns751Ns7V2kHNvv7PH94J0LRn/CnwNCpge2OzLFRwfmn2ZLaLbNLJ4AzKS84 XcnMlwzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDtt-0000000HUCZ-2CV6; Tue, 04 Feb 2025 08:03:17 +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 1tfDm4-0000000HSoV-3Z2m for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:13 +0000 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7be8f28172dso263998785a.3 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=kxaIk51IZwE70q1tVZdfg1+sMc5rvbcqelmi+LeZd2m7vaIxeLMSHkVBhTQ9kelA86 TBziEgePT7jQgmZerAWzE1/86t0qJFddGv+AMQKNj27TBl2SyCwDsMylYtAywIdP9Ucn 6FqYOu8UkXb5LmJFq5sxHDJSgcLkzdSb4XIg8ErMY48E/FsSrN/HyiqAZZuxZ/lkEgGR F7RTd/DiIM47sR7y4ryhiLAc0zg+xYfZLjx1itIe5eQTTF1efM8kxoerfTow0JsAFmhY I/Gf00XZiIM8yzaZguZSTmhvysdeU2lWs9eYYq/u2LM64aSbuhRv6eEOcx+PqIQv3lMn hS5g== X-Forwarded-Encrypted: i=1; AJvYcCXWw9Hp/LcdHR7wEwxzriZKnQ0fDSNAmYX2dKpJKWeD7Ec8mXTQRf9ge/7VQ2/OrsbTifcBzgKibLhNfsYFDWVo@lists.infradead.org X-Gm-Message-State: AOJu0Yxxgy5QjRcOiugVBx2pq08bZ5oxiXG5W48OYMv/n0lFvGTqSxXP xhs3BIte8/CI3KGBWVwPKT2RExI6jqkHylMGL1YZFm3LVa65W234QSNU+UXnKzY= X-Gm-Gg: ASbGncuLHDAu6BR93eERM4u4J2yFJORPGEdJBPJBWbC6YA5llOfDyYxDehaEMO05V3N STqbjCmz3B0QEH4WrdstNru7l4g25TbkJMPSXhcM4GXYj2Qxo5PVFT2kQ3V6PLz05vEDSkUuEjC 6J+Ee+eTo1GYLBSmPDAn+nPJqMOJlKBldAbeeGVMjscwmlPA//yb+MDXggeqXAM8Mh3twyUvE9K s+0LT72Zzx5RWvygPnPnVGJf7Ux+j6+aW8ZFrHNcBztaH7BbsnVfNDBEMvK8Hl61aTEKTTB9AOn tbucPjFoVDs9ai1F7UG5p/zs9sirG8pcXLHkPqapibzV2uHaheuKqdM= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_235512_894602_C1E3B07E X-CRM114-Status: GOOD ( 12.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958765 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 73E46C02193 for ; Tue, 4 Feb 2025 08:04: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZnRpk/p9sKuCOyv2KZjNLOO6T+xrx1m13lZc/9SNpSQ=; b=jlFnXJ9bP3WMPRKgb5Oe/JP+mZ gq1WbOSvkmoMrD6uJIZBFPbRQJQf9+t3MRS+x6ndB4mei7ggaOua6eRq8uwL2J6HKfBeEd3HjEfEw 1yzrLZIV13x+3ks5VrdEnXak9rCKdfCuKlMN943QIfZ85wcM4ymo0cGhcxZ2wtGvuucMRSZXiWvqG X4At3f4lGLRorUhpiJ4YhkAVziYPQFJ98PYtefdvdGkNBSOqnNsZDSIg1XG2hgqEpY9ESdkmbfhLz YuCHSF8J0PQZQFgwVp0HxLmX3u2WjR/K644ztvt45cX3FlesjMO4Y/qRvntrcsQI5A3jeRH39//gm 9ZBsSPuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDvC-0000000HULx-2zjV; Tue, 04 Feb 2025 08:04:38 +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-0000000HSsS-3McW for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:23 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b6ef047e9bso473351585a.1 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=by7HrI6LdWFGv/Ank43XkEjEq834ErFAHKa3K7kV9wdWUWbA5NCZDA9HxUXHznRY5h KAXaMW0skv1qmktnfVWWpaacDeylh+bs9Hgq5OMaHUo+lGWFd0rYTllvFsqghI6upVKz kBfm/IFBvUfi7zn1gJTazQLQa8hf8/Uf7565aFcvTXUEpY6dwrnoKtvzfwvQsyY06Zk5 2oNO3L/R57dhdjmDNw4McnYMnLtXqpQCggBfke6Rk5EPoXFNNWVzBLdiVlDqoQCTSfMv +IKIjV5Dn1dBd45zyEW3V3bL+yeC2KkLimYJ2zn0Ldr97J2JF+RmNhQdg+A2NaMTiyor tYlA== X-Forwarded-Encrypted: i=1; AJvYcCWSSiLYhk5Qbiuhs/SPN+9QPYiL2LA9CbEMLrL+V3lbkVLFRauoCtKH4DaNB1ITfPZ0z0jxbfNj+pmFwmJ8vZdb@lists.infradead.org X-Gm-Message-State: AOJu0YxK7X2SasR0VKsEyYWJLOsWWn58L9IqCdoK8VC+CzoThpYNvVVG UWHozmiu5oSIw7a0FVS+09jnWEnlL7HOl6HIMawfOfOWMVnpE4P3UfXg8y3xvXE= X-Gm-Gg: ASbGncsYA6aZWZit10bgp855cHh5wXx/EANG24sM8ycbj7u7L4rlSYyTScZiIck0F30 1VJiBRuoY2d6sJcssuDKvHJ3nWbgsY5JRytdRnexZusxldo4v2TNac+IOz90oVtLkmKWm/MDtPo Gb37XROe9PJiWtVhPSdqlXT1aIXHUloBwLexcM1KaHsJfbSuyuObJbRGrQodyQAOkxCHbRVWA62 Pck/jhptkqh3wmPDtSzSg+CxYeO1hVHPtx7imNxjiMWtu/5gKH+A1/3E6of2MPEHqC6fY95JU4Q c8QihIncPlbwaT8cTW2pyJSuWy5dU0Fubcn68XUfGn/3kqdRw9fbDeM= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_847331_F89C015C X-CRM114-Status: UNSURE ( 9.87 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958766 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 B935AC0218F for ; Tue, 4 Feb 2025 08:06:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=X8Q8DUzarAwU1aGXfCPKakOOrYWe0j2UtGXEc/s+csU=; b=v0KAoZo7sZFYIqMrFkGIUrOY++ z6irGXC4Cw84PY7uoLuMCjCVy0lQAwjAgN3ZzYijitunYV+9yoydeXsT2v1dLerx87tWI6rTyWmFl 5pO4Mri4LejjOCOGMWMsHsIaw9WoAum/jPZ7fz5SlTrTiGQX7b0zmHxCYB0fjOIyBAC7MEfVP/wKj 08+wMpW8Q9XmUFJmZwwthOwn7rWHlOQicw7ElN0C72nky6DD5HgOd1Q6pvnXUABW9miBCRbsP6xo4 3Yu4KZlzbUmz5n12jHFsVMuSYSN7KNPtiQFzDWEhgWiRBbwMjKDGlss0h2koMdhGACbyusNDxUVCg BKwk79ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDwV-0000000HUWr-464q; Tue, 04 Feb 2025 08:05:59 +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 1tfDmP-0000000HSve-0nTB for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:34 +0000 Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7be3f230436so471536885a.3 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=B5L0XGEjcBL20meBfUbN3GtP7IEhqB/8JE1JC0LeRpSBIJWBgjLlkgO5WkFVQYmlo+ phKOBk02mWP0IP1fNcNq2fxtAX3rU452k2YR32daeFsoon8WCzXUoZaGQz1lBZetow+i 9EpX+xKQTYGAh5ysqZPUSsZ+YWIWpdlb2fBPKafeQDk36IpZaPFm9yensohbXTFeDNvo e/+0tve4RSJFMk1Mpf+hUVVcuZ86+Lwyhn6O8q2zCvBVwJrcvCcm/jloy1lvHojSG+MY kSpeTjIxnYMLzUkiuGrJJS5uHqjGOwaUG9Ik8uzjO86HRXpAHCG/r2BmAA9L5tP2IdyS kKjg== X-Forwarded-Encrypted: i=1; AJvYcCWr3ZvfLGolqBx5QhhBIenzAcMug/OaTmQB644Off8YPO+gsv9tLKtR3yQU+Y6CGjZSDuz8kju9Yv/DQg/ft5dY@lists.infradead.org X-Gm-Message-State: AOJu0YxRfYx2gux9RCUfopZ8E4XOJPJzzza6F9y/oU54qqA/qV27uKTK R+djYePINnT5p3q9OhMknRTlpdTPXbxbzcW1SDAlEGGoqGCgdTciLV1j7Ba2o/E= X-Gm-Gg: ASbGncuiG7natuq8H1+33yaYgfXAOuFpNuzkAx5rOLYuNvgmWCx6xWkK8DnI6N7WzvQ A/9uF64Hjo68kA+j1DP3lM+HtL1wUrZ6omPNaDJXhV/JQIQIqqb5cqXh6n2DmkVJKBfGz3mSGNC as+vt0VfNTeC7gcnOOWiezl/p3vZBKdr1ZRC2wJKeI/qXKcsJXePob/N3zLRfAdsR45XWYNAcZJ iTs2Gr0lrTi+0V0ykSUiL2H0OiMMIWUTLB4CNyN7HGDMekwQIEdZS1kryevdxCM7Buz2SKSuKob /36QrB6OmTNoQdvPvhpmUjzUkQlBTGnWdVcDnxkk+CrTo0ByIW3x1xg= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_231284_57168AE8 X-CRM114-Status: GOOD ( 23.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958767 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 488D9C0218F for ; Tue, 4 Feb 2025 08:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2spJ1HnVniz9PCwrjRYFNbVUb3mNe4Ef/XoJaqLNwpE=; b=H13xdnd2iHNGtGoYRCIGBi9TSR YxO7StWAi/mtE/jxjukJkRYNn51nCm21z+EqZX75MrEPqxBViDVEPduczXHf+TwGH8dv8ovBWbia8 QQGvK4GIKJIVveu0MEHrZYT6jkNuWqO7QHWCyTZLQloWohbUkpqNT1p98LbHa9PJHNTCFMqvuw6r5 T98vrbLdmsbhOJZQ6VA1kYt6mlgTw1bvBsVjNFU0MyuJoOJ9ThI2HsDre7vm0Y385SKbnk1psamL3 W7nIT37gFnpuKFkE73W0AMCQVUgeKX8lT6OdrpaoaS0HX03Akkr3aSaZvlit6wmq3AgZoBZfjnYAb WrWp7w+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDxp-0000000HUiw-0qNP; Tue, 04 Feb 2025 08:07:21 +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 1tfDmZ-0000000HSyS-1Gdy for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:44 +0000 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-7b6e9db19c8so477630285a.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=InliGrvVcwXKFZ8n6Cw6pvj8NPe26ZgVVfVm4U73olIsEaqZII59h2iwnbkJBC8f45 Ojvd/T7fJzITnug/JbtQtESijzSSHjkuEHU4x/hDGDgd7MkYDTn2i8oSCA3gOxoNw9x0 LEnwPuTm1wwR52TZfElqNzX3aWVPo81FzC/8Qs4iMERS09phkX2GanNVtD/j0PVXGnFc vr1tBgBnPVldyjsyWyJN1E5gSwZEJfOJU9FKzWow8mHuTaoCX5FAJoqgW/2qOKP2PcIC v5v3W14Zuz+VRytDTqIDUh8IhR47C6KA8y0FAAIexcEgBcAN3eEEiRp/VQz/udzDOMfB jgCg== X-Forwarded-Encrypted: i=1; AJvYcCXlW6ktsK435F//dL05zVdW05fWs+B00bTbxSqQfXffP2UsRx5kS02I3DEYjrFrKdF7FSclrIo0vyqL/sv6JAY3@lists.infradead.org X-Gm-Message-State: AOJu0YxFjS3ZFDW0THKD7v8+5+GQC5tL2ZKOKzy+nAjr3yCSSLBq7YxK r+Mhvr1hzgpeb6BiOFuilrDYai3ZuZO0eRm2gJBpFvz/TA8jhdS18DWyoUYT8fg= X-Gm-Gg: ASbGnctfAEEvOE+ugkDNv1rFzl2oHQ/hDTrqp+Ni7m20J030jYpoOId0mFfYsnCb9MR OwLkFM8mttJ2tibyCRD6aMYX9bhDE285LHqn5eSsyhwNXL7p1aTejYdG1VCNc3/iLhb3QQSPKx8 r0ebrGsGNwTv71AnPVXIPmmgap0iWHOeuybV9ra66eVnz2CTR/8xnqWdVeigQobT2+dFYAPQaUI t1MmSkqzdL3nA60qiVPcB8gy9GY6/MgbWL4Jdwd477UTCGvHGSq1lf1HAuSpNNQBrl0/2c23rD5 5dXxxqmxbA/oCXPf1qQV1SuN9K/uidbbAMY0OGv/HjojleFAKSD042c= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_343130_FD9EF01B X-CRM114-Status: GOOD ( 15.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958768 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 796DEC0218F for ; Tue, 4 Feb 2025 08:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3gEwcaDf3FiyZX0vTyT/9XCNNLKunHvBb/ApGbPO13I=; b=U6GU8NNBvibZFemHcwXAoeEWsP GeP2tSghyEmqg7OE3NWAOPtmbSysjfD+0R9wrekqLKETvh5/hMQZkrPe+WtXcy+Etc5fmQpDWVC66 23GhWFcsPqfSsa4dBhkHpeOs+gsWj1SeRpaSmEnZa3UHocya7lbdfpkqkzRSNBSe6OfggiGCdy8Kq 0CtivUHkb0QEMZmeXF5GR7xTDNznGeYCcgNUXVVtQF8uogdo+GDXPGiJcCIc0TFV33NvjFFhVtCvV zf23vJZ8MnOa3EMehuzUBnDefwMthbKi/+yDtsBXucwkB6r1xJbuhWnJDLbLxaGcx8v5EMEjpAnA6 7XJ1Ik6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfDz9-0000000HUwp-24iR; Tue, 04 Feb 2025 08:08:43 +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 1tfDmi-0000000HT22-3mEq for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:55:54 +0000 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-7b8618be68bso518313585a.3 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=xTOalZgXGa2bXT2YWPTYbA+YdtF8is+PUYhBvzXQ2tEhf0bxmaMA7UaFEqFPJGtsTm 8PMP1AQQ85OJkPwTojhMn5wRtk0sSRbFlcK4D7Ac2G8vbmoDxVKvtLeI6Pq1SZ2DtzCO 9H8Ycbu8o8fMQ3grS4xdeJtvn/FtnnSj1GsevhrPSXKgPwowtuE2nRBGOOSasDlF2t0v BF3dbL30NNNFPbmsCwutQClC+iDetjCt5ePsivO6Sc7egZjn8+5Nt6MFsnyaL1JNfugh sAFSwjhW4QcukO9Tg0syd7p/aJq6sZBE1DTvx1hixtPSk5GSyp2mUm7bG46SegUHa7wi b1RA== X-Forwarded-Encrypted: i=1; AJvYcCVKjpK1rQZyzC8Z+TJ83/Lqtmj/vWAty3nEocxMacxazj5nS0lr0NrN2Dp06z/usMCK3ovHMa6O4rc4fVxGJDSg@lists.infradead.org X-Gm-Message-State: AOJu0YykqMiobDTkLdRamL1zP/wAdHTOUG25NwTtZ0e9+ubqVNB8Pvf6 iMt1ObTesLooPY+jMi7A5PYpzb9J/XKZU66t+RkzlHmCxpMrNBxdKjTOD/scIDM= X-Gm-Gg: ASbGncspcOby40jYe1efFAzctJK9/j4r8DwY/EvKh3IQZQtgv1YdkmHXKQtVEDPZWSU +iV2nPYUvuM17e8RtGgE4s5EmKiZyzEdLYu1U8uQB0HUuS05IMiaWRCqLYPVQGOquhnXGvIrSTH izl1r6lLST4Q8GNsDV0/H0oA2quObxfDzVPPtoDAz7sIbEpKcTqw4wqLY6XC+/zW8S7d6QFPy+7 E2+OJnOOGMJNY8hg9Z72RHZa+lXwc1wgDkiZxDCb94lquos4Cq3t+dOdvNR35dYsJApiwufYdai aMIDucvHxBYHBVQsnTUKzPLNa+zXkE1z6nm0G+jfPe4x40T15x7gKgc= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_235552_940476_FB5654DC X-CRM114-Status: GOOD ( 17.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 13958774 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 AA8F8C0218F for ; Tue, 4 Feb 2025 08:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6MADFF5SwXkzmIBLKmDVwps1qS+gME3ryVy0pflkh7M=; b=CKijM7TtwuzrBoFabpevhBi6MI AgoZ6qDLnXSzFauZvofOVm7jH4dwyMiuUgqn8Ja8+AJhAsmzbncRE0URCWh1JX3Ejsj9z9HfHdUaD Ww33sJtQEiUaD7WDdVzz8K+zfUtEBGaGfHDbY+LLJGqDmW/qIv4GEdD0sYzEOD8J9jZ1rcYH239ZV kayD8Sl77ubhL6opVqkbHuAZoy7dG4v004gf7uE0uj6dyuPrdZ48W+6+OtwWpJdPn3CIzbDOErCMh SNSYbWmhtqB884afuGziMKe88+mvfxPwppAW3KzyK9QncpM0gCh1UObdMaVNHNJZdbyjP59EEVyIN 2JuQUe7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tfE0S-0000000HVBy-1HcW; Tue, 04 Feb 2025 08:10:04 +0000 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tfDms-0000000HT5I-1sdk for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2025 07:56:03 +0000 Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-7b6f0afda3fso667733385a.2 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=dnGq+MbdMkXrbRYfaGrMb03RPxOqTDiLWZwgPcK0rPGSHlTI4i7FTEyOWnBl57tSY9 3RXB1H2ipqrIsK1Uck7Ko6Kvf9tsJlmP7G5REuoL19pbqPGmdWSxlMsuOVraTX8HHoPZ YYp49aW0XDG76zPREPkqluqBBSd1471gLFXb9/cgDOu0zn2wrnZpqWTclSdv8EX0dmkq 2UQXfu/zLLBwEb+nCBnkOAi/iEfXLu0ZOdLjl5OcsVKzowzVUEDIOxLN4C0K4gVjYoy2 jZUSaXt7QJTwuUK5qiL77EejoNrmhs+zCvTYW5BeQihw+IWB/VNVKwymHmWxKM0hEWgo vDMg== X-Forwarded-Encrypted: i=1; AJvYcCUDkDAu7z0pTEPf1NT4wh92AB2Qr19PawcamjyEA3z0aJARmN0I03vMpcxrHYHeVuiQIrikvYWl3mqJUPy5HyHW@lists.infradead.org X-Gm-Message-State: AOJu0YzwqydGyeG7AeyI+g01obQz9tx7Yb/K1t6haJTHGGLp372CS3/X W79Z8Bmjc5iC1XkUbH7zLoCxgTIC0OdP4dM0rnZHhnWXbJir939s7q5XtXYcXdE= X-Gm-Gg: ASbGncviEC9wFytu6H/9JDhEZvCYbw1a9f6dgCK1dFGy5yq9l1VO5HEG1VnLIcba2zc ZT0X043Y4+P+RlT8YbvnpAVd++ePe3r535C82khKBNbQKYro0ZmSDKBO22ESj65fgGdNtZqFKw0 q5F2+pcuzmBl/7tIWv9/CBNZXBylyKWREtfJWdLmH6dsQaLOwOCwe7TtlawsQDZii7nxoZilHwl iDLuMfO5f22vk5ICyw1At3l8lNHq9Ikui6m0LvauKFjzkCsK3gQFWrlwfJTvuuwUy764XEDl+vV +zFn1t1xLDRSr2oCiyoboPFAVU6PpmprYsklsLDFaTAtqsPaSg3M4Sk= 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 Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel 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_235602_481974_23EDF160 X-CRM114-Status: GOOD ( 25.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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);