From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45FA11A01C3 for ; Sat, 14 Dec 2024 17:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197174; cv=none; b=siOf+HDJAMydWCuBf2Jb6FvklXs1zz+wxy7JtUNJjwxU4gqZ9X/pr95toYjSp73lyOAjSeEvtajpU78QIw/uSNeaLXv6kPuDj//u9rHM/ZWHqqZLGreNBgDcMv939ZtgbNfP7gtTBnRVgJjVvGvB65l6z+UEhJVErQg8VuRoTqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197174; c=relaxed/simple; bh=AjbhMTp1aGsIYrzh3IEvyIDO76drMFMoCVTh2CxsqAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QK+tN5xJEJ640JllrQwxwhiZiLFoIBz9sqsQwM6yIRRvuB2YwNq42WyGqLjyZPOWnE4RYlH1K1254Lp++35aruy81R3YQ3/9Ko0N1OlOsrtA2z2rRLhsu7lgtUoX8vUkKdvNOFzjp7hqW6gTuwmMfFp/IUzHkfaxCeM/4lS70lE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=oOOMCvLc; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="oOOMCvLc" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2efa856e4a4so1965655a91.0 for ; Sat, 14 Dec 2024 09:26:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197172; x=1734801972; darn=vger.kernel.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=oOOMCvLcVOBma1klJHjQ79q6oTk3wV2YREnsTmPzeZQkz1KXorbk62zaJO7QUfqj1E X9lJE1W1UBBzjrddZTvr6jKgwk/4/JSedHWT3pvCShCegep3F2YXhZyDiq67uIk44qYT xv7P2e5LiFq3aZ+7W7bZaoyvT+zU6HsBaXOmSlkmVWkQbayVmt9qj9OhdvjW8iL8q0HV OWdklbOWrlZ7VDiCZ112URuQdUZPNxaRK4lnJaRVP/5uiqp/UNfaXVfrS5wILpfQo83D ntk22amYgJey9JkUrfowk9wfBloZf924hGQslZDDkwnvnK9m76w13Vw7/CtkAbHASDbq UHBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197172; x=1734801972; 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=skSlj89SPhWfzucf7E8+OnOOo5KWMkCcMfRam7U/IHMEub4A61lqaRacZpjIKyoMiX N861CHf7mJooJIJvoX7wxue+NsqsJsGsoza1aq7kL2eZ5lo6pXvjaiL3DuUNti+vk+nO Z1t6EdgZCGeLtMj+/zffxTEa7ixEaRuY93ILBTidPFjCugssGUuH5VNF2quZK5JUjxFg VNqK/RcJTXeGwVwZNpmhUXjlRPDSEgLVQRoUK1dN2S981GEx6POPjXdPOFICvvqTNJQN DbIx0hxYgvNvDdP0iyrqQzxFnX+5TjeCdUjFow5/Lg77tR93vIHs9q80PT8FMnMKWtUr VW7Q== X-Forwarded-Encrypted: i=1; AJvYcCVq9Llsli7e/8/QNWsUC/Mw1+GY8JHL+azLuSjp8ddxb3jDrMNRnIpwRcYSEHK9aoPklEBEipxK+0bylzE=@vger.kernel.org X-Gm-Message-State: AOJu0YyoeTdzfyfPwm3qDdUPu5cCO/4X00p7o7nPVUwSKJGCdzAPgqYY lVIWIZFMpfkTDNEUtVtmeaNOqD8Dt47Rt8+wrTkbvVGMRVs0jXhyiCpDGu7y3rY= X-Gm-Gg: ASbGncvvSkKlcaU1dwq9lhw2RdDgWHtlorhCkJctsNFYbqOUgu9eWauN502GB1ltN6R Dx5HcTbE5XfOMTjq9jQtvoyzHfT2qWelzTt/iuYli82Y8+PO6sETqp70xcbRZP2609xsvjAYdAZ 5+Fsr4sB7qot1sdO1sLcKXwO5VN+C41TiMTXcrTL7P2DNlCHGTHYlwL1emG3/xns49z/k/qeCoO tSp9dHFyeWWebF15m1K2EqYmJxkD4BGX0wy9fT3C1sx25zKAn5GuuUWrGMTl1p4XVZ3c1ZsnS+s Pb6Moz7YgQKpbF4= X-Google-Smtp-Source: AGHT+IHTs9Samt1nUdMUjND/qbDSnn282FzLK2X5JD8ULRiRDj00BeL2dfgDijLQRIK8XWPNIoxzrQ== X-Received: by 2002:a17:90b:180b:b0:2ee:dd9b:e402 with SMTP id 98e67ed59e1d1-2f28fb6efa6mr13056275a91.12.1734197172388; Sat, 14 Dec 2024 09:26:12 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:11 -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 v2 01/11] irqchip/riscv-imsic: Handle non-atomic MSI updates for device Date: Sat, 14 Dec 2024 22:55:39 +0530 Message-ID: <20241214172549.8842-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 fo= r 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; =20 + /* + * First process pending IMSIC vector enable, disable and movement + * on the current CPU. + */ + imsic_local_sync_all(false); + chained_irq_enter(chip, desc); =20 while ((local_id =3D 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); =20 /* Enable local interrupt delivery */ imsic_local_delivery(true); diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-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, con= st struct cpumask *mask { struct imsic_vector *old_vec, *new_vec; struct irq_data *pd =3D d->parent_data; + struct imsic_vector tmp_vec; =20 old_vec =3D 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; =20 + /* + * 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 !=3D old_vec->local_id) { + /* Setup temporary vector */ + tmp_vec.cpu =3D old_vec->cpu; + tmp_vec.local_id =3D 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); =20 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, unsign= ed long num_id, bool pend, =20 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; =20 lockdep_assert_held(&lpriv->lock); =20 for_each_set_bit(i, lpriv->dirty_bitmap, imsic->global.nr_ids + 1) { if (!i || i =3D=3D IMSIC_IPI_ID) - goto skip; + continue; vec =3D &lpriv->vectors[i]; =20 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); =20 /* * 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_pri= v *lpriv) mvec =3D READ_ONCE(vec->move); WRITE_ONCE(vec->move, NULL); if (mvec && mvec !=3D 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 =3D vec->local_id =3D=3D 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 =3D per_cpu_ptr(imsic->global.local, tvec->cpu); + writel_relaxed(tvec->local_id, tlocal->msi_va); + } + mlocal =3D per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va); } =20 - imsic_vector_free(&lpriv->vectors[i]); + if (__imsic_id_read_clear_pending(vec->local_id)) { + mlocal =3D per_cpu_ptr(imsic->global.local, mvec->cpu); + writel_relaxed(mvec->local_id, mlocal->msi_va); + } + + imsic_vector_free(vec); } =20 -skip: - bitmap_clear(lpriv->dirty_bitmap, i, 1); + bitmap_clear(lpriv->dirty_bitmap, vec->local_id, 1); } } =20 -void imsic_local_sync_all(void) +void imsic_local_sync_all(bool force_all) { struct imsic_local_priv *lpriv =3D this_cpu_ptr(imsic->lpriv); unsigned long flags; =20 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 =3D 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); } =20 static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned i= nt 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); } =20 -void imsic_local_sync_all(void); +void imsic_local_sync_all(bool force_all); void imsic_local_delivery(bool enable); =20 void imsic_vector_mask(struct imsic_vector *vec); --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 738E61A01C3 for ; Sat, 14 Dec 2024 17:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197181; cv=none; b=j83QiWAL38fefXEcAjMcOrAv8/uDqBjAKsFplJDOOmW2J/9fe1p+fqmqXEuqc01XuXPZm/jxEGeKB/yRd3eEwo58rXvRM+Xglh/St4ByPiYrAuTXT+wBMX+PRNWZ6u1XHoSO3SR0tHiaLOc+1rcsHIMSYJls6wfSBtenF0nOLRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197181; c=relaxed/simple; bh=GQ6h6qnifBeRvwI5lbrzx5DePz9FG/7AwYjLLcTRLyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SeYmOET2LvglBy6d67xMKRH+qPwdLgg4XbtorPl3aYmlQpZMqtB44EdX85/WmqZVWQ309gsH2Fvg/SIB0cU8bg9zOIhaDOA2JZPKpmZftWmWt5obhSpXc9TrVh9U1cLbcR4JQ5h/HXyo/s+DraMUf0Iq6zuskqUhrYQNRncYMQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=VtprQ0CX; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="VtprQ0CX" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2efd81c7ca4so1871566a91.2 for ; Sat, 14 Dec 2024 09:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197179; x=1734801979; darn=vger.kernel.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=VtprQ0CXEYo7ZlkJHQqN11GD4Lml6JmOrpm+IYHHWIwhW+8Qusmw6EqZKMUD+xfGMz p//YWJLg5JrKyw6u1PnKNvbj1ZFLakshXHqyRScw45rfyL9crK4aYpCEkLSIUG+zsged wbi9fkmXrNR5w8/gdaKJvXXmrCSR1iidrxxqP+NRl/0ClQV0VThX0tie37REqyiQ8ypd pP4Y+RAih4JK3/QWqkym51QSEjg7rZps6/q9yvoxPPS+Nja2MOzm6oy9y7CRNxhkgqRe VfpgiaQwGqyKja2Uh0OB8WZJ+Uz5U8jkzU/YoSmUx1BHR0dvpX5CIuwTCTWW4FPqvCS5 cqIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197179; x=1734801979; 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=fRgi9Gre4/Y8Ge2vt2QhwGkNyE/l1pQuPkNy+OUjuuwys8yDmjRTt5wqwW8yt708hU IRhGWA4yWmnTYeVTOSSrzWm9MrGxgGz8Jjk/YTfE757wYsDmLuMZXBD8D1ksp2Xtz3uI Ryg+yc45kYCMIiWIdpT1WAnzqoJPBg9H/Vp2ycVNbEQVKlHc07pRSfqYmSRmKqx6S0UP R9GQqPRbthhV/B64Wx1gX0yLTcLtkYurtBItt8FP8c4ZuXSz6EKiKrs/Kru8HLtITmzt Df9ZLVQySoR7JehHY0ii0yJhkGPlnXxC9kTGnjmnClLlOMga/i+PT3N8V2HXVu5OJ5QF is0A== X-Forwarded-Encrypted: i=1; AJvYcCUZcuKupzATSbUnnjXBbsMyE/MzS9AENV8+3ZgvTy3rmjqN6XEArsn4NcjFgf0CjombblzRBVR9flxq9K4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywohd/vDvso46bWOjZLO1QSowxDnM0S13PC+bWtHq4ubjqFn8G4 pirLG+HQiCFSr/Gfsx+wgPs2nmJaUzNL0yYyv6mBfnZ+Po0dcpVNFb/XLpNdSyM= X-Gm-Gg: ASbGncvcebrkToWsN4D7CapzXYYtzyRz2831xG4+H/O+rjBthSHwJnp2n0giK5AX97D UlWFkHKaRHst7hkCzd+gfiq99uvz4vPI+71L819hH16E7jpPx97/4gS1sO1S06ww+qmF0G4L99A YzR3GtC4e5BpAx9qh/GyXu9SfSOYicxFJuuAZQ776kSpSuAjaKtamI8nrYG753NOdAE+zmU/6kW 4e7WvNbueqpdmyQ2Qmy5pnsgMLzvDIsiynCIbkUl/271xf04RxbByi1FzmJ68oGVH9sXNEdpjK5 qFhLTQqIS6i/GZE= X-Google-Smtp-Source: AGHT+IG/WGdOL5hzTQ/uQVNfvqxiM0q/u2T5n/4NTjrqHoQ7a33gOPCRMyAXNIWVjXMp94uGcfUDkA== X-Received: by 2002:a17:90b:1d8e:b0:2ee:aa95:6de9 with SMTP id 98e67ed59e1d1-2f2904a8b08mr10590547a91.33.1734197178822; Sat, 14 Dec 2024 09:26:18 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:18 -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 v2 02/11] irqchip/irq-msi-lib: Optionally set default irq_eoi/irq_ack Date: Sat, 14 Dec 2024 22:55:40 +0530 Message-ID: <20241214172549.8842-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D { .supported_flags =3D GICV2M_MSI_FLAGS_SUPPORTED, .required_flags =3D GICV2M_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, .prefix =3D "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 *des= c) static const struct msi_parent_ops imx_mu_msi_parent_ops =3D { .supported_flags =3D IMX_MU_MSI_FLAGS_SUPPORTED, .required_flags =3D IMX_MU_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "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 =3D real_parent->msi_parent_ops; + struct irq_chip *chip =3D info->chip; u32 required_flags; =20 /* Parent ops available? */ @@ -92,10 +93,10 @@ bool msi_lib_init_dev_msi_info(struct device *dev, stru= ct irq_domain *domain, info->flags |=3D required_flags; =20 /* Chip updates for all child bus types */ - if (!info->chip->irq_eoi) - info->chip->irq_eoi =3D irq_chip_eoi_parent; - if (!info->chip->irq_ack) - info->chip->irq_ack =3D irq_chip_ack_parent; + if (!chip->irq_eoi && (pops->chip_flags & MSI_CHIP_FLAG_SET_EOI)) + chip->irq_eoi =3D irq_chip_eoi_parent; + if (!chip->irq_ack && (pops->chip_flags & MSI_CHIP_FLAG_SET_ACK)) + chip->irq_ack =3D irq_chip_ack_parent; =20 /* * 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, stru= ct 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 =3D msi_domain_set_affinity; + chip->irq_set_affinity =3D 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-g= icp.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 =3D { static const struct msi_parent_ops gicp_msi_parent_ops =3D { .supported_flags =3D GICP_MSI_FLAGS_SUPPORTED, .required_flags =3D GICP_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "GICP-", diff --git a/drivers/irqchip/irq-mvebu-odmi.c b/drivers/irqchip/irq-mvebu-o= dmi.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 =3D { static const struct msi_parent_ops odmi_msi_parent_ops =3D { .supported_flags =3D ODMI_MSI_FLAGS_SUPPORTED, .required_flags =3D ODMI_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "ODMI-", diff --git a/drivers/irqchip/irq-mvebu-sei.c b/drivers/irqchip/irq-mvebu-se= i.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 =3D { .supported_flags =3D SEI_MSI_FLAGS_SUPPORTED, .required_flags =3D SEI_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_mask =3D MATCH_PLATFORM_MSI, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .prefix =3D "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 =3D (1 << 21), }; =20 +/* + * Flags for msi_parent_ops::chip_flags + */ +enum { + MSI_CHIP_FLAG_SET_EOI =3D (1 << 0), + MSI_CHIP_FLAG_SET_ACK =3D (1 << 1), +}; + /** * struct msi_parent_ops - MSI parent domain callbacks and configuration i= nfo * * @supported_flags: Required: The supported MSI flags of the parent domain * @required_flags: Optional: The required MSI flags of the parent MSI dom= ain + * @chip_flags: Optional: Select MSI chip callbacks to update with defaul= ts + * 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; --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CC3B19A2B0 for ; Sat, 14 Dec 2024 17:26:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197189; cv=none; b=Ax54K2t2HUQt7BZZgztO4v1IMgJihY4MfA/3NfQCEf3c6QZdRruzHm1m2we6FFbSpO3DLjksnLHbXTuYVFGnSDEEb6hTvyo1A2UFnh4+1VZFQOwlAv0DulZYjbv8qZ2geg08QwbPFpmnTXaLCXvSEwTurndTCjC3VZnwWYvvVXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197189; c=relaxed/simple; bh=PcKCiIKJzPJB4OrlTg224bcO8uJZAUgM9GlGe6uz0Po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t0UDOx6YWvTx8Y4IB9UOT2EylqaeVktULyY+2lBzYa/knZfQrJPvIdOOtItcJZb26u7ZTirGpbWxkkdF6pQ1CG2QeYJ3HWucDZz3BYVflO/5wHbmYUwp908PGo3BNgRnP5O0Rqo6sVBc3Ura6vBhcc1BU+EfAq0LpArPPvwQN38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=l+FhfqXr; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="l+FhfqXr" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-728ea1e0bdbso2122478b3a.0 for ; Sat, 14 Dec 2024 09:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197185; x=1734801985; darn=vger.kernel.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=l+FhfqXrdSVOkd0QUMyXkVFU7REXilQ834IoPlRLR5Ehr/MMZjDAPxG5qytbVfXamv sacRrXnLDmwALuZv2k9El4FMewyK52fzUi26umhkmSWBHSJu1O2dvZu9rowaDqgX57Tv dkxTptxHQfWORWWMeF9s6VyeHLX1T5dA2jsKKiNnvhxnr5bVLPitwS+Yya1Aa5ld/iMh 7lRbiwATQy8fIzw3eGT63sq9HK+UHiVyrU+fd6ceUm2d6+K9ivmi4ZLsITJZcdJPeUmZ oM2v59Q/8CZg0+CBMJH4WoN4ZqtJErbQugts952o4g9g6RGxCZai8+iH2i0ss3I8ep9e lObQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197185; x=1734801985; 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=hATQf1ZG6DX64SlsAwB6H/aSriPOBouR1/1A8IT2O/ElYdHo0wFo/xUGpptFYMtxWp rYTgytjkx4RIiy7hcHeYaj4FtLQzG7bmN54gGeBCatSXwaS2/Y6nFm1mnm81FQPP3ZSA oq3JcS2cIK9aG+1DMNb6QLlHFI87oXDmkVgHGbPZfyQ50oUdDfndhOafcLchNMJBnDpe ynpf1arQMz86X08hGM7uh8UVyEK3602dFooeo4CatNvTefcGPtGKgCqqW8fV4j89/8Lj VbbycYpsvW8qWI+SzpdcsylGo/swSOSaNzMQCohiNZHdhYjvjMHM79+FOo7FJxdbLp/b y6Yw== X-Forwarded-Encrypted: i=1; AJvYcCUmYS1X6X8Q8YGDIXLLVV1PTzC4FnsxpbcpfXct3j8rlGdBIE3FffTxbBD2LYT9g8u/6gZtxpYLEYmn+x0=@vger.kernel.org X-Gm-Message-State: AOJu0YzrxyIYAhiBejIIVHGeEr7H4vmfyVZ9clCxX2HIFP+WBljwC86H 4wwdCoKCL9SX+Yzj+YeJvYpDl3l0KCAq5249tOLZAgnT2wVu92592D6NlZ/CJ5Y= X-Gm-Gg: ASbGncvdPRxJvJWJa2x5huE2wPU7lA5HYGlgQ9kovZqlxuCmrziFaxXEwhxfH3dcUyr nxnztXCVMhcyZ326k43116QSjCyC+G7pOWPEhuebx7ezHkmhhUlGIwCdXcezukPhxTW4nwtPimm 6/2/IMv7ZxjaOUG8cFOFLOs8t0iwurRbqshFCDtNlM7FZWRVhEUE5+o1V+PlVMhj6vqWHpRVraX QksU+zxWtsdB+h2wlOD1sWBCgj8LaUoKB/7ROeHB7uZu78kJtzSedzCtkWrYz9d0aORCfC6a0AO zu0O585NUvdOrrc= X-Google-Smtp-Source: AGHT+IE1SPKm+gzJ6VGXDJy+q7RKdAC9iquVy8ivXNUGMyZxEqe5AtUA6j7vJ+xaqDvjxeC/PzggwA== X-Received: by 2002:a17:90b:3c02:b0:2ee:5958:86d with SMTP id 98e67ed59e1d1-2f28fb6764amr10436246a91.9.1734197185565; Sat, 14 Dec 2024 09:26:25 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:25 -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 v2 03/11] irqchip/riscv-imsic: Set irq_set_affinity for IMSIC base Date: Sat, 14 Dec 2024 22:55:41 +0530 Message-ID: <20241214172549.8842-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/i= rq-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, co= nst struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; - struct irq_data *pd =3D d->parent_data; struct imsic_vector tmp_vec; =20 - old_vec =3D irq_data_get_irq_chip_data(pd); + old_vec =3D irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) return -ENOENT; =20 @@ -139,17 +138,17 @@ static int imsic_irq_set_affinity(struct irq_data *d,= const struct cpumask *mask tmp_vec.local_id =3D new_vec->local_id; =20 /* 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); } =20 /* 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); =20 /* Update irq descriptors with the new vector */ - pd->chip_data =3D new_vec; + d->chip_data =3D new_vec; =20 - /* 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)); =20 /* 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 =3D { .name =3D "IMSIC", .irq_mask =3D imsic_irq_mask, .irq_unmask =3D imsic_irq_unmask, +#ifdef CONFIG_SMP + .irq_set_affinity =3D imsic_irq_set_affinity, +#endif .irq_retrigger =3D imsic_irq_retrigger, .irq_compose_msi_msg =3D imsic_irq_compose_msg, .flags =3D IRQCHIP_SKIP_SET_WAKE | @@ -272,7 +274,7 @@ static bool imsic_init_dev_msi_info(struct device *dev, if (WARN_ON_ONCE(domain !=3D real_parent)) return false; #ifdef CONFIG_SMP - info->chip->irq_set_affinity =3D imsic_irq_set_affinity; + info->chip->irq_set_affinity =3D irq_chip_set_affinity_parent; #endif break; default: --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63E9F19A2B0 for ; Sat, 14 Dec 2024 17:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197194; cv=none; b=QNIKf6sK0Im3FzyycHXeP5wpT66WhX/xZTKm+Y3RgtxJ3el9/JolO2Qk9jPevzmOvkffMzWs16Cq/Z1m3yMPh7JHcEseCkDJiXxCgeHtB7UIBVzBoDpOa9ycVRHmcmd8wtV2umWeYJeHXoZOfWKur1JrnMY5iJOemeZ351ZVsQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197194; c=relaxed/simple; bh=Mfh/oKVyV/v62tUmOG9j432HyhjKXncy+MsddMkaJpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o6CCjfJy/0QSL0aNsXUayh4pCWtEH2T52bQY4sCs+NELmZqRoAhjw3BL14aZneVVS4CxHX6VUyB24H9uLV3t3xblOQQVvbPuBC8dtHpwdYtSykDvWXhrpl9gpdQBqWjaXFyshJmZKQ78h/LFpM1eAsUMllwv4myLF8nPwW0D04k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=Yzbs6lUF; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Yzbs6lUF" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ee50ffcf14so3084852a91.0 for ; Sat, 14 Dec 2024 09:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197193; x=1734801993; darn=vger.kernel.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=WTMHZPsDjixID3LZgZypNI5zerTGwhJ3oNH3JU/CG6w=; b=Yzbs6lUFltKMt/QaYfH66ZTlMnbXxkZaLtXcoz7XpRQ5bVsjRws+9GTKr014n13tzq Geh+wq0x1i3zlusju7pHVaZzQnNR1u8hCIt9XK+G4kLQl3fWEbwU0NzTH+lB386OL0iz 7IX26MYFYZDL1QCpv07lv88KVh6ypjXaL/l8uuc1jgFwKJi0sRtPiZXSH4D+1hL24Et7 BHooeAdHefdYN4vf8d+XrnS+vhrRH3lRyjvl9qlfQoysjAaiLmxVyX1ESGjDpPVH8Tee VV2ZFGvbjP5/e4cI1/BeFdXCFhKfrUCcJL1f9b48x7EIkg9W+TLouxXlpHYILTRC73ir Zcdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197193; x=1734801993; 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=WTMHZPsDjixID3LZgZypNI5zerTGwhJ3oNH3JU/CG6w=; b=UzRGCWYW/aK2ofsiDUi1kSrwfz7PURUXhdOrOgWXH3abCs/2F3gIrZrM4SYcokJAYe /5iXrXW1pc/RXELpk4Kd5AlzY3VoQnWDdtqnJIRG5ZJFCZr6wmdTv5Y3C5wN/eKpUyYm uEj4d+KOpOc69pXK2BleARigDTpn4mwT+WJeQQPzZSlLI2yuzQrBl3yo7MXlSil+Nb7T TCTATF6ORhsm3yymD0Q9PLUsQ31izUXsLFbCv4aY0ZGVFoEdAnz9mIk9+UoLlihvZgTY vLWxTRIZqcRH+325ZBiAPs0ryUU4xinyKmtT7bCraivp0xnlxIUrRDnsf0vIoKm7ZTAw q6iA== X-Forwarded-Encrypted: i=1; AJvYcCVPAcRhFVH8aJbE5rrOcEQ3Kojt6/RYIj2zjtRskCOZFU7QZ+RETC4BigIMBk0bqLj6hXF+MBoRN3qZCDs=@vger.kernel.org X-Gm-Message-State: AOJu0YxprhSsQMfDAfptcGO2zvPT1Ydwt7sxEbWI5M9TmdXF8109+Rza 2oyDOPvvgrm3+0PM78edf28TtGtLc1nKTqNXCCaetBgrK7bdn5qWsgwLZBKJ2maUAVGGbdi2Xwk K X-Gm-Gg: ASbGnctX0hdMnMCTTVOhCrJofZZC2V6GyNLm+aZgSphylFQA0rzV+N72ZcGnafKPn8o qyYBhW6odytfJ5gqwnly2PWql3GxxhxJ1xSlAxfbCuizkfepEpGX6ZtnRR6jZsXzGMrfDs94dGQ mfdb7X6obj8UVzopf0nlX5yNa45OenjfJptLbbBkvO9Se21jWtyWanQxxp67vi0ktVTi2tN/Nx4 LKSIZ/21Uw9CQs20wuEDUwQwOxmpcU9/KGF/7Nf98X2WuRhu/7HWBtbN2d+JnztXJanKVhpcjM4 SveZcapQ57ijFSE= X-Google-Smtp-Source: AGHT+IH7cEjTQcM+udD/U5XRPprvWKA6NBoe1GlzDD6yjgsEVTNKRYALRcnCyPJucGTbfWHoFFxtSg== X-Received: by 2002:a17:90b:4d05:b0:2ef:ad27:7c1a with SMTP id 98e67ed59e1d1-2f13ab74905mr16256697a91.2.1734197192577; Sat, 14 Dec 2024 09:26:32 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26: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 v2 04/11] irqchip/riscv-imsic: Move to common MSI lib Date: Sat, 14 Dec 2024 22:55:42 +0530 Message-ID: <20241214172549.8842-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 55d7122121e2..6b767b8c974f 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -587,13 +587,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 =20 config SIFIVE_PLIC bool diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-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 =20 +#include "irq-msi-lib.h" #include "irq-riscv-imsic-state.h" =20 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 *d= omain, unsigned int virq, irq_domain_free_irqs_parent(domain, virq, nr_irqs); } =20 -static int imsic_irq_domain_select(struct irq_domain *domain, struct irq_f= wspec *fwspec, - enum irq_domain_bus_token bus_token) -{ - const struct msi_parent_ops *ops =3D domain->msi_parent_ops; - u32 busmask =3D BIT(bus_token); - - if (fwspec->fwnode !=3D domain->fwnode || fwspec->param_count !=3D 0) - return 0; - - /* Handle pure domain searches */ - if (bus_token =3D=3D 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 =3D { .alloc =3D imsic_irq_domain_alloc, .free =3D imsic_irq_domain_free, - .select =3D imsic_irq_domain_select, + .select =3D msi_lib_irq_domain_select, #ifdef CONFIG_GENERIC_IRQ_DEBUGFS .debug_show =3D imsic_irq_debug_show, #endif }; =20 -#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 =3D real_parent->msi_parent_ops; - - /* MSI parent domain specific settings */ - switch (real_parent->bus_token) { - case DOMAIN_BUS_NEXUS: - if (WARN_ON_ONCE(domain !=3D real_parent)) - return false; -#ifdef CONFIG_SMP - info->chip->irq_set_affinity =3D 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 =3D imsic_pci_mask_irq; - info->chip->irq_unmask =3D 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 |=3D 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 =3D irq_chip_retrigger_hierarchy; - - /* - * Mask out the domain specific MSI feature flags which are not - * supported by the real parent. - */ - info->flags &=3D pops->supported_flags; - - /* Enforce the required flags */ - info->flags |=3D pops->required_flags; - - return true; -} - -#define MATCH_PLATFORM_MSI BIT(DOMAIN_BUS_PLATFORM_MSI) - static const struct msi_parent_ops imsic_msi_parent_ops =3D { .supported_flags =3D MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags =3D 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 =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info =3D imsic_init_dev_msi_info, + .init_dev_msi_info =3D msi_lib_init_dev_msi_info, }; =20 int imsic_irqdomain_init(void) --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D65F19A2B0 for ; Sat, 14 Dec 2024 17:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197201; cv=none; b=eA5XYUVA6GoB+ckWvAOJbb7AHgtLI8Qlx9yV7KKQnFBNNujH6cM6hU1rZyrNh1rYNblOLW0LWuIoSvqp4avf7RoRGbTnW4rq6mr6L6Kho1mFwj3VnaVKoyT2i6sxU06aUXwH8eq9laEmk9R0xZdMsi91yMizmgmnp2UUWggOxnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197201; c=relaxed/simple; bh=6PIAjGaZKQwEt/EjBHyszo+wahqk5t1wsyFIUnbE8YI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MW38z1lKng4u6Kycd2NIx7KNczT6kxo6aW4DKi0NGrPzewKGuINtIxfTPI7b4Mw3cjBTWzeHpYNcnvzChlu47zsUVbYfH/0r2b5YtZ7RD8Qgz5DK5Ppy/yIaeCOfasNKMlFTeyfN7Vzxm3tb6/Ls7Ww/ryNDYV84dUKOXM4pGQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=U3eLcTQr; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="U3eLcTQr" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7ea8de14848so1566145a12.2 for ; Sat, 14 Dec 2024 09:26:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197199; x=1734801999; darn=vger.kernel.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=u6payGCmGMW/0vjHgpi/115tsc+b1yXaj6IL2K0q/xw=; b=U3eLcTQrfxzBR1KNMvEpzH/0wtO8gw8YG/rRa3ohfJbxVNQk04+fD0L+hyNxMOxLS8 850hysopa4gV//GGNVIHQLFQptWNWbsCHhKVfln97EF2i+atuzw6dvAmf4RQxbp/PlNE LW0wFrsXVC74dMxklcQxm7OSRp/96dlKG7R84qUOiyT9z5zDMbcI6kqlfnuSHT870E5U ma1DJewotlemKzovmjCQ/XDSbB1LG4VE4ZNDaqjEJ6v28OfUS5xTQD2amS398JtJl79E tYXRXerye1BLf38BUtv71uq2odJ10DOrvrieYv5ZcBlncRiabYWHp9sv2HwZIrZeoaDC awgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197199; x=1734801999; 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=u6payGCmGMW/0vjHgpi/115tsc+b1yXaj6IL2K0q/xw=; b=XP+hK4FThf3ocDRIJFyebJkZr9Llak6bVl8kN/zm6+E0lIWUGzuMRq8VeqWHcp1MNj MIcaJ4ITFx/nCPV5/x6cBa0YRpCJV5q/oYCLC5AUrq7K13jiY09H1c7NY/hwPVM6Xvxv edZ7zteGlC2yDJa+bEDgyixNTxeNfq5WJjJlhG1qLU0eGfIJ5cXyW0ThX164UTAkNzDo 2zpJrNcx+GkHKchTh4neplNUTHA8Y6+TusxEbbGP7+xkxZvoa+SHIrVWf/k5xwrPtUgG b8N/9GTkM2vttRZ31tWtTtWuBDklxnZFTmeccvWtXNYe9y9wtZsmFF37dQj3QjQRvABO QZ7w== X-Forwarded-Encrypted: i=1; AJvYcCWsPld2PzGFPXxtfBTOTaqQ+5ByQb2Q2JEmmj7v6Bf5ca5KIdmyEWEDvgMcfJxI4molObz8VmwBVW1E/Ak=@vger.kernel.org X-Gm-Message-State: AOJu0YyTVMFQPB17CJaK7D0GuK3dohm1xlMXQwj4iiXep45be7uaS/kX E9ZwYKGddCzxSVRsIjKijQK9o+iYEILSdP6/7j5TsxhKvWIf2YTzlUI2r7qdeOc= X-Gm-Gg: ASbGncsdDMRIdlntDezHuj+usLkhDMStqTxPsxHGD02RMPsYnURoVv1k5x49zFK0PK6 Fwb8lmuBGphqpLyeDLE8sORvLNaQG0J4L+JJKMIESq+8KQezhtobptIFJ/8yofrEwlZIh5EMQq7 GGPB814R6E4YSjt7gPsHMF61kff3LD40er1rZbB5o/YKfOqrxAYpUsYUlfo1xG2jBYQPk07F3+7 o0x/6N/SFTXgZgxgGrX+4Ed1nTN3nkuaCfhdYeuNOVihiA8c8qTHrm5CwwYU53wNrFdB+H5d3Tu drvDqUhjKed5+8o= X-Google-Smtp-Source: AGHT+IE4G8tF4t4tobhDLydlOHpy74mKHnjdVddbrMVpE78sNcz73JzvON/bt8jZjW3R+eaoP7P0Vw== X-Received: by 2002:a17:90b:2242:b0:2ee:ba0c:1726 with SMTP id 98e67ed59e1d1-2f2901b253dmr8940041a91.34.1734197199504; Sat, 14 Dec 2024 09:26:39 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:39 -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 v2 05/11] genirq: Introduce kconfig option GENERIC_PENDING_IRQ_CHIPFLAGS Date: Sat, 14 Dec 2024 22:55:43 +0530 Message-ID: <20241214172549.8842-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Introduce kconfig option GENERIC_PENDING_IRQ_CHIPFLAGS which allows irq core to set IRQD_MOVE_PCNTXT flag based on IRQCHIP_MOVE_DEFERRED flag. This kconfig option will help architectures such as x86 and RISC-V to mark top-level irqchip instances where irqs can't be moved in the process context. Signed-off-by: Thomas Gleixner Signed-off-by: Anup Patel --- include/linux/irq.h | 10 ++++++++++ kernel/irq/Kconfig | 4 ++++ kernel/irq/chip.c | 39 ++++++++++++++++++++++++++++++++++++--- kernel/irq/irqdomain.c | 1 + 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index fa711f80957b..b689c8fe8d60 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -567,6 +567,7 @@ struct irq_chip { * in the suspend path if they are in d= isabled state * IRQCHIP_AFFINITY_PRE_STARTUP: Default affinity update before start= up * IRQCHIP_IMMUTABLE: Don't ever change anything in this chip + * IRQCHIP_MOVE_DEFERRED: Move the interrupt in actual interru= pt context */ enum { IRQCHIP_SET_TYPE_MASKED =3D (1 << 0), @@ -581,6 +582,7 @@ enum { IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND =3D (1 << 9), IRQCHIP_AFFINITY_PRE_STARTUP =3D (1 << 10), IRQCHIP_IMMUTABLE =3D (1 << 11), + IRQCHIP_MOVE_DEFERRED =3D (1 << 12), }; =20 #include @@ -634,6 +636,14 @@ static inline void irq_move_masked_irq(struct irq_data= *data) { } static inline void irq_force_complete_move(struct irq_desc *desc) { } #endif =20 +#if defined(CONFIG_GENERIC_PENDING_IRQ_CHIPFLAGS) +void irq_update_pcntxt_flag(unsigned int irq, const struct irq_chip *chip); +#else +static inline void irq_update_pcntxt_flag(unsigned int irq, const struct i= rq_chip *chip) +{ +} +#endif + extern int no_irq_affinity; =20 #ifdef CONFIG_HARDIRQS_SW_RESEND diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig index 529adb1f5859..6d85a47fbf41 100644 --- a/kernel/irq/Kconfig +++ b/kernel/irq/Kconfig @@ -31,6 +31,10 @@ config GENERIC_IRQ_EFFECTIVE_AFF_MASK config GENERIC_PENDING_IRQ bool =20 +# Deduce delayed migration from top-level interrupt chip flags +config GENERIC_PENDING_IRQ_CHIPFLAGS + bool + # Support for generic irq migrating off cpu before the cpu is offline. config GENERIC_IRQ_MIGRATION bool diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 271e9139de77..623959a24464 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -33,6 +33,33 @@ struct irqaction chained_action =3D { .handler =3D bad_chained_irq, }; =20 +#ifdef CONFIG_GENERIC_PENDING_IRQ_CHIPFLAGS +static void __irq_update_pcntxt_flag(struct irq_desc *desc, + const struct irq_chip *chip) +{ + if (chip) { + if (chip->flags & IRQCHIP_MOVE_DEFERRED) + irqd_clear(&desc->irq_data, IRQD_MOVE_PCNTXT); + else + irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT); + } +} + +void irq_update_pcntxt_flag(unsigned int irq, const struct irq_chip *chip) +{ + unsigned long flags; + struct irq_desc *desc =3D irq_get_desc_lock(irq, &flags, 0); + + __irq_update_pcntxt_flag(desc, chip); + irq_put_desc_unlock(desc, flags); +} +#else +static inline void __irq_update_pcntxt_flag(struct irq_desc *desc, + const struct irq_chip *chip) +{ +} +#endif + /** * irq_set_chip - set the irq chip for an irq * @irq: irq number @@ -47,6 +74,7 @@ int irq_set_chip(unsigned int irq, const struct irq_chip = *chip) return -EINVAL; =20 desc->irq_data.chip =3D (struct irq_chip *)(chip ?: &no_irq_chip); + __irq_update_pcntxt_flag(desc, chip); irq_put_desc_unlock(desc, flags); /* * For !CONFIG_SPARSE_IRQ make the irq show up in @@ -1114,16 +1142,21 @@ void irq_modify_status(unsigned int irq, unsigned l= ong clr, unsigned long set) trigger =3D irqd_get_trigger_type(&desc->irq_data); =20 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU | - IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT); + IRQD_TRIGGER_MASK | IRQD_LEVEL); if (irq_settings_has_no_balance_set(desc)) irqd_set(&desc->irq_data, IRQD_NO_BALANCING); if (irq_settings_is_per_cpu(desc)) irqd_set(&desc->irq_data, IRQD_PER_CPU); - if (irq_settings_can_move_pcntxt(desc)) - irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT); if (irq_settings_is_level(desc)) irqd_set(&desc->irq_data, IRQD_LEVEL); =20 + /* Keep this around until x86 is converted over */ + if (!IS_ENABLED(CONFIG_GENERIC_PENDING_IRQ_CHIPFLAGS)) { + irqd_clear(&desc->irq_data, IRQD_MOVE_PCNTXT); + if (irq_settings_can_move_pcntxt(desc)) + irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT); + } + tmp =3D irq_settings_get_trigger_mask(desc); if (tmp !=3D IRQ_TYPE_NONE) trigger =3D tmp; diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index ec6d8e72d980..ec5fc1d8cebe 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1508,6 +1508,7 @@ int irq_domain_set_hwirq_and_chip(struct irq_domain *= domain, unsigned int virq, irq_data->hwirq =3D hwirq; irq_data->chip =3D (struct irq_chip *)(chip ? chip : &no_irq_chip); irq_data->chip_data =3D chip_data; + irq_update_pcntxt_flag(virq, chip); =20 return 0; } --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DD6C1A8F80 for ; Sat, 14 Dec 2024 17:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197208; cv=none; b=uwdRXFuzq/lmSlyNHKk91ll4RAli88+Rt7KYEQfqUqxzRn1S9kk+biq/iGrS3aNcAlcoEr7D1kbzQjM1fPx2cm3CHG6BbNvplm8MI/LTGsOMI1WGpHuJA+NniTJ9+9UtNxGyFExDoKli64uhvGPInrCNrd23un4HeeI2223WRlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197208; c=relaxed/simple; bh=KQvgHMf4mn/NJ5Xhw6rUHo6j+G4++aBmhNInEZUS85A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RSNXVP+v2NqgZyjQLLNote34tuL/3uYjAoJQTvbS+9CeAYBMJQkng3bg9VxyuUc+y5U0rhexTnwFFoNFunxA5rrYjad/aAJxtYziA1DRK9t02zAqMXpSPKzWx7rRBNxwJOwKR3VIjFt3OcKGioWMzZr5A8pWob/tb9Tqp08YhXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=d3DgLXZe; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="d3DgLXZe" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2164b1f05caso26267355ad.3 for ; Sat, 14 Dec 2024 09:26:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197207; x=1734802007; darn=vger.kernel.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=nBJthI+mqNYzorludLEAXvfiuDja+LCnD6djvnBek6Y=; b=d3DgLXZew7K5QBclQ/cD4nFeStj8kh5eg8R+odpkIxGz4dz0rZwxoegej0l1UyWcN3 fXBpLC3wuTvnoqcQ3HvAoVBLtcSrQp0IWFQ6c3qcaRXteWaUH5u2d6o8bD7pe6mFlY5F pllPV52jlH+UKjWs3ReSLm1bhIlJyWWDb4YqCJ7w2/0sObNro51axkAylCYAwE3Za5EL SoWZE7eRQFzRLJBmOLhOVKqWQZx5SH0GjXBsaWfpLcUdfxZEwaY38zj9MCF8ELOCkFIB ebGjCFh4I561go/VS1r7bI9TvwBZ3hoR3RqQ/BC0QkBFlgxK3UWjPzl2xa+8V/d40Hkh vOOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197207; x=1734802007; 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=nBJthI+mqNYzorludLEAXvfiuDja+LCnD6djvnBek6Y=; b=bc6T6U4Y9Sl52UVlCARJRxXeCumsKT2y5w/jx/LoOvhgTgqFPzDHQa+1Y7SHxLOpz1 fEY6fBTvmqQvQsQjfN8woe7KWN6/vmPjboqVO7AducbZWL3f6dnypcm4DByQvKQOkX08 WI4wckseBjkB8jEdQtk6i9p7jvZlDqeZ2s6BQakHYa3I/PXUnRaK85EoDOdGJrqw2byz QSqWkzlLNtmH+96FK5cFBqQHmTgNzg8gz1TnjJ1Tq345yN24VAUvMabEUt+plhGCSTTu LyxmPDSlBUobqLPT0gjq4oEKUIqbjJ2GW9OzL+tmo/53YomwJIOZAFH11QAnN7l8YWN3 k2eA== X-Forwarded-Encrypted: i=1; AJvYcCXovZ/E7k06nc5Bv0iZvpS6szVH7w94v9jCi3ueavDUZD6KJgtwb5P9g+dU4t2qRtLyI8c/i3VBqaI2TNw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzy0BTgNtc8D6kzjScRPhIv8CRUL6PXWLjjA80VVoS+t/WC9TVo X+TCkJlxnxEv3MV3A84UmsbwIyRO0xCFOyewyJWqcEwcGSyoDXOj2h2yxP0QG6o= X-Gm-Gg: ASbGncuP0AOeEuXgETOxuIcqbQC+oTryl3lH6tqjd5pnb4yzPHgvEgBBF/mXz9tifwo LIkpKLBHbn8vE/XXRxp/SL9UNilW6SFmsC44XeGNPZCLdzUhuV5Adc9tnyLCX5wfo67S5E/5fKA NcOkWzXOoIjAsK9gcdgi+CZvYkKAjUZ/8zf5B5Mkq+VQz1OrBPtE2PGVHzB8hMifKQeolgn8jOm BpSUn7gFrSjb30uuaL8HDx+sfXdvbFgkXeRaRbkEjAM9zolFxuUzNi7n6UIO9pn+lyZfML8MV8a H2j+XL8hVSauT8Q= X-Google-Smtp-Source: AGHT+IHWMVLk7VAHEJKffclkR/GgfiztR1cE76mj+f0onDTerIF7KBl2vajNkAVkEerHi9sn/JzVIA== X-Received: by 2002:a17:902:ccd0:b0:216:3466:7414 with SMTP id d9443c01a7336-21892a41a9dmr113376145ad.44.1734197206669; Sat, 14 Dec 2024 09:26:46 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:46 -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 v2 06/11] genirq: Introduce common irq_force_complete_move() implementation Date: Sat, 14 Dec 2024 22:55:44 +0530 Message-ID: <20241214172549.8842-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 b689c8fe8d60..509c0ee4ef38 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -496,6 +496,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 i= rq move * @flags: chip specific flags */ struct irq_chip { @@ -547,6 +548,10 @@ struct irq_chip { int (*irq_nmi_setup)(struct irq_data *data); void (*irq_nmi_teardown)(struct irq_data *data); =20 +#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ) + void (*irq_force_complete_move)(struct irq_data *data); +#endif + unsigned long flags; }; =20 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 @@ =20 #include "internals.h" =20 +void __weak irq_force_complete_move(struct irq_desc *desc) +{ + struct irq_data *d =3D irq_desc_get_irq_data(desc); + struct irq_chip *chip =3D 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 --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4BDD1A8F9C for ; Sat, 14 Dec 2024 17:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197215; cv=none; b=ouCcnKY7J8g1kdY62hDZSKGCrirEJpUawIr/W1mxxqZbUtLnI8Rjp0A9UZp382BqtBhBJDpY1ohE/8ZiSD+Rt9l6C8TyQoaMJe5pq1H62xLID9G5ewtxSshKr5Qb+elbxVrm7dqleH4BiX/ANE66Vnu/c4GftJdN05EZDOFw3NQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197215; c=relaxed/simple; bh=aE+CJCpUn5kUAnEgYyEV3gtDvbC5Svv8OP258wfgmN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LVeCrURO8m7Pi4RFYu3BWBhTExqzGOGRea56OPz7NHxNOOX9w00Vr42U+7YFpAPlwdP+KZB4HC2kPNxfXbGMKyA8TEgh+twznBC7MXLlgPupMe64MxF0Roqt9smFALI9jeBZQ6g1gYVw8g+mkcc+8MrblIti/hKq4h7F8tY6JzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=ploH3Zt7; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="ploH3Zt7" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-216426b0865so24514105ad.0 for ; Sat, 14 Dec 2024 09:26:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197213; x=1734802013; darn=vger.kernel.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=yE+w0neHmk87dMRt+p213gF5rtqgAWN6iext8wGVFRM=; b=ploH3Zt7irmUPLOxQPo4cihjIN1TWCyNc2pBk2qBlMuPYrbgvM49tsdxwmnCngUYa+ brQsa+409wy3YDm/MRXMS+1yv4DUHf8iFkZgNtMAyXV4RVggtCY9wcYRH0oCdXVPTMT7 AWIB9R3hG0LT1CDPyxaWBP5XvtwmVQZxp475ntaktjJMs5Q05AbaizN7U5xyVbYQCVxQ WTeV0pO58YUaQwOZJY+IU1WX7JsKGhqSwJxWOIMimKAtaEvWSw6gSrgiXDR1AP/cL5do aJ7xKKQSEh2Dt9CIlMeMw4XZhNgkB8KRzY3PRIBOBSpmjRiWOKay/FzxFVVZbp1+nh7d pSxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197213; x=1734802013; 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=yE+w0neHmk87dMRt+p213gF5rtqgAWN6iext8wGVFRM=; b=Gi43Mxk8i83EKbWlH1qSGh+qKCbLuJflxH9dhDTYvVpqQ/PZpikrpPd1jZwebOm3rP ms9fZPdIFNegYkN66lfipzWjNGyVe6XVbsFHdi+yY3a06ZzuU2LxWqty6Ah9KGQ/VqYu 5omVgyJIHPGF3Drtc5EqKDG9VmAFcqM15aHmvqmo/eVBIVXybJlsu6LZluDH0XaNyXOn Wj/fZgTPkmv6fqIK5l93sHBMD4u3+c0HI5y8Mp9R1Fo2fIhYcmeCuZsMXezhJS5MENwt J08p4dI90umMpHkTtuhypWTaMP4tXilEzTT+O9XyTaN3eIa53xo8MySi+GrtOXCnKbsb F2cA== X-Forwarded-Encrypted: i=1; AJvYcCWWujm6902V0o8iB3AnX+c1YdFTmq8Zr/1kUPV1NrdFUAcQT+1uaWvmcwoMH92nLfLuJEfSzoIX/IsH13o=@vger.kernel.org X-Gm-Message-State: AOJu0YzbXf++VRZdaV5n2pnajUsdJRn5nzQg7r3hA7IC4SCmVEAQcOp9 vqEBHqZWdNmE14D9X82QhVzhSpTIBpJo116j4r0HDUTyO57lreuo8oK9492B5uruvoO/gJohUNC M X-Gm-Gg: ASbGncuU/JHwxJzo/315ZG8Wd+Iro1BgFOWwt27+LfHbXjSk7oTQw6bRlV5FjNM/nFd ZeLtawd2zyWjySBJl2z7/Q2SFOBLDxRvtQWDBkkn2ThQLWFmT2PoHhVnrD1fn8Czznae6ZW1rNN X8mBlCt+oe6uwPpYeyRLWbuzfV7P1rhP4Rc5e1heo4Wa9VKYxheKVAm+NsL5tBBLPpILKzpjvWJ hu/z30ruSZ7SPK7igRpGeUKFaCpEfrUyY2SrsbK/Pl0FtIKiusHxGsND8t8uVtptveSgLAVy3vg 1Djo2Uv/Muz7ygE= X-Google-Smtp-Source: AGHT+IFHcRze2J0M8hyBJEZA/NeT8/eZWD7tT0rfNtTykqj4Jc1ZWMZrjfrUoQxfR7mhTVQoKpV61g== X-Received: by 2002:a17:902:e545:b0:216:30f9:93d4 with SMTP id d9443c01a7336-2189298bbf7mr99837005ad.8.1734197213088; Sat, 14 Dec 2024 09:26:53 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:52 -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 v2 07/11] RISC-V: Enable GENERIC_PENDING_IRQ and GENERIC_PENDING_IRQ_CHIPFLAGS Date: Sat, 14 Dec 2024 22:55:45 +0530 Message-ID: <20241214172549.8842-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 d4a7ca0388c0..adc878f029fb 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -110,6 +110,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 --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E68771A8F9C for ; Sat, 14 Dec 2024 17:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197223; cv=none; b=eG/KeFwDwI3yDpS63V5cGW1Sx608s6fgoS7PciYNDx5TbMGf3drjc50eeXidWL8+WkOl2SyyUgHXy2hLsQVN6FBnD8TWP9Vna+tRIhs/RVgvXo8Y+mAgAciyRZSBL2rS1/apzB5LcD6BuVp15OmiVkKCR5kecmZv1obC6gm1lhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197223; c=relaxed/simple; bh=0ljoGbT/LRu6wccIGReKAg8EOuGxkwBf9UmQIRwMDWw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cbdtkzdh86P4R6u7q46KVEVLRyoXspi4Ia4cpmGlKMvG9x0XUrQU9EgvstATCb/qkcaQB1R0uUSwFRJ7tQERLpugyaVIqgPPLyyJZyt6OaRap+N4J693YQJkmIlDsSVeSX0xUiyGDvdSVlM4dnKnfzvuoVtb9WtEG6ZDWJyZu9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=OvOE5bLe; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="OvOE5bLe" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ee74291415so1871190a91.3 for ; Sat, 14 Dec 2024 09:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197220; x=1734802020; darn=vger.kernel.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=qKWIt7ITp/X88ndEH7it4rZ1geXjjPOabq3XOqds9DM=; b=OvOE5bLe/eGNyQJCMTRKgX3GUi+jkh0YZTDsSDnLjZlzFV7Ie2duFePdEjPVgbIgBB 6t6Ts8yMUh7Wdw6pvNhxirxS6bTWXifstv4FoFGZK6Odh3FJuXDGPAsHPFqlVHyM6Pkh /4HhISNxYGuGyEPnRa1PbAKI/LC3vZz81HWfuvPjD04Xm5yqHZ0SDrcyQ7L5tCkIrI9n 8r+DfFIBjNKNAr08cD5wUVUqtvsgXvflFiw3s4U+haW0k63TB6+n0vAdH22XlW9DEC4l UsbE52MOWYxaQ0Ka0sPbt8/rX7XL5GT7wJCobYSZE6Lr43LYpkr4b3vVvt1mBoecV+v1 emVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197220; x=1734802020; 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=qKWIt7ITp/X88ndEH7it4rZ1geXjjPOabq3XOqds9DM=; b=DuPpWAQKPBb6R8np2u3yYL+hJIWqub8A+mPPP8diSF9wy5Qn6G6yPNHNZ8OfNlgNO7 mXTkbsIM7oFy2oXm37QDKweq6L340xoo/9YM1g6Vd0++2MujKtRSv+Wd/TawxExpl9gj j95dwx8NO9D+mRpHDL6Fig3lNVlGl7sI7fyIY2R1+zj31fGiaXlg0AwLa3m5ol2EfiHI v5F71jPsNJgNYGd85J5kuVqHpkt5Dy7MHE2CmPo11PuMj+OLZ205wPH8NGWB6kC4GK9/ qKljBwE2Y4wI29ymu0G81cOF+m8UuF1XJuy+GU6S6H7HIR5IFSTT4Qu3ceC8m+Fjof42 Vssg== X-Forwarded-Encrypted: i=1; AJvYcCVjqDNgr75Pi8AcZNeHqm5bu5ei9tvaUXDycTS9QdZjry5lODc4tjiuPnQHjzBAINYIyuIuNQV+xs7TENY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+XYbgzeuFthWhuUyL1z3wXjeNHwl72198EzGOvKRGvbo4v0T8 72jCo2R5l1zXSzc+vNadG/TOl4Q1LANL5MoeyowqE1YnOJNsX+4IAELxNoAjxLQ= X-Gm-Gg: ASbGncsWS+M/fMmcfoYe7XIKwliYUdaIbTQeCG2G+p9kNWMCt1jnbkb+755eIsGLUuC xY6OrV3qBWveZZwWMp7aSWYFeBMFXddnqG8yLSS6EJtb3TxIkxxK+i2THbgSgSA3PX2g54QkVyE l/UQis0tBvTdlN1q1QOg3a1V2gmU1lCtdz1/QmtzOGSJb+oxLuzOOa2TZiC1s79JFHd5PEa4O1W tE03XUqvb2o8A6DsZGXGPfQYvTzwNMhEx3NPxDsuVMEHVUhdMSct9FEE5QfMU/Yk8Kj/eN6PMbD XLv9SAQHvsU3shQ= X-Google-Smtp-Source: AGHT+IGQwf+KWHUKDSuNXTV8W8BsAm/unz0Vds64eL7itxYSGgZbtZcUWjgcYwS8LtLhLbggFNNyJA== X-Received: by 2002:a17:90b:5112:b0:2ea:4c4f:bd20 with SMTP id 98e67ed59e1d1-2f2904a724dmr9248924a91.32.1734197220158; Sat, 14 Dec 2024 09:27:00 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:26:59 -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 v2 08/11] irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector Date: Sat, 14 Dec 2024 22:55:46 +0530 Message-ID: <20241214172549.8842-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 60 +++++++++++++++++++------ drivers/irqchip/irq-riscv-imsic-state.h | 5 ++- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index a8645084bd8f..da49a160ea09 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, unsign= ed long num_id, bool pend, } } =20 -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 =3D true; int i; =20 lockdep_assert_held(&lpriv->lock); @@ -142,15 +143,33 @@ static void __imsic_local_sync(struct imsic_local_pri= v *lpriv) else __imsic_id_clear_enable(vec->local_id); =20 + /* + * 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 =3D 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 =3D 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 =3D READ_ONCE(vec->move); - WRITE_ONCE(vec->move, NULL); - if (mvec && mvec !=3D vec) { + mvec =3D 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,11 +196,14 @@ static void __imsic_local_sync(struct imsic_local_pri= v *lpriv) writel_relaxed(mvec->local_id, mlocal->msi_va); } =20 + WRITE_ONCE(vec->move_next, NULL); imsic_vector_free(vec); } =20 bitmap_clear(lpriv->dirty_bitmap, vec->local_id, 1); } + + return ret; } =20 void imsic_local_sync_all(bool force_all) @@ -190,9 +212,16 @@ void imsic_local_sync_all(bool force_all) unsigned long flags; =20 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)) { + if (!timer_pending(&lpriv->timer)) { + lpriv->timer.expires =3D jiffies + 1; + add_timer_on(&lpriv->timer, smp_processor_id()); + } + } + raw_spin_unlock_irqrestore(&lpriv->lock, flags); } =20 @@ -232,8 +261,8 @@ static void __imsic_remote_sync(struct imsic_local_priv= *lpriv, unsigned int cpu */ if (cpu_online(cpu)) { if (cpu =3D=3D smp_processor_id()) { - __imsic_local_sync(lpriv); - return; + if (__imsic_local_sync(lpriv)) + return; } =20 if (!timer_pending(&lpriv->timer)) { @@ -294,8 +323,9 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =20 -static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struc= t 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 +335,10 @@ static bool imsic_vector_move_update(struct imsic_loca= l_priv *lpriv, struct imsi /* Update enable and move details */ enabled =3D 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); =20 /* Mark the vector as dirty and synchronize */ bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1); @@ -338,8 +371,8 @@ void imsic_vector_move(struct imsic_vector *old_vec, st= ruct imsic_vector *new_ve * interrupt on the old vector while device was being moved * to the new vector. */ - enabled =3D imsic_vector_move_update(old_lpriv, old_vec, false, new_vec); - imsic_vector_move_update(new_lpriv, new_vec, enabled, new_vec); + enabled =3D imsic_vector_move_update(old_lpriv, old_vec, true, false, new= _vec); + imsic_vector_move_update(new_lpriv, new_vec, false, enabled, old_vec); } =20 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS @@ -402,7 +435,8 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hw= irq, const struct cpumask vec =3D &lpriv->vectors[local_id]; vec->hwirq =3D hwirq; vec->enable =3D false; - vec->move =3D NULL; + vec->move_next =3D NULL; + vec->move_prev =3D NULL; =20 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; }; =20 struct imsic_local_priv { @@ -87,7 +88,7 @@ static inline bool imsic_vector_isenabled(struct imsic_ve= ctor *vec) =20 static inline struct imsic_vector *imsic_vector_get_move(struct imsic_vect= or *vec) { - return READ_ONCE(vec->move); + return READ_ONCE(vec->move_prev); } =20 void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *= new_vec); --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 072671B394C for ; Sat, 14 Dec 2024 17:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197229; cv=none; b=I9TPcFNFpP3SqZet39EU3XNfUCF1fX37NRvuAij+tcg9UFuVgN5NuPa2+lwsn8pFNOZzp/SAIHuGEn79XJS/VxB9SEmAWXMiLQB8qqd6el8E+tRk+GXKyj8sNMRwgeiOrqaR3WR3zrW4f+uEzj5mZL0O3M7Ec+5CPNQo5DoA8FA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197229; c=relaxed/simple; bh=ZmZx+N5nuIhjnt8Ku3H4Aa5bBD/jkRAUPw+E2i+2ziU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvnUn2ZnKn5zFdDWt1o/MowwKvTLN07sxNSqsoq9TzFzUYu/RbhFlO8CnRCgRNfUUnsynSnrLLJM1r4S5wvwTom882aIgg0tz7Fp4Ghun7AYkeyUtZULZEeOTvZZnWwThRIEJ4op8W4oj/bUkOqO1KkmBo0z+u/smtzA51FzEHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=c1rijWmo; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="c1rijWmo" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2ee67e9287fso2462019a91.0 for ; Sat, 14 Dec 2024 09:27:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197227; x=1734802027; darn=vger.kernel.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=K8c4bSx6OeCafE/EjjWkj4NBjcuAlryx7NpTdvjZLKQ=; b=c1rijWmo73SjEJEgsDg/sXWShtIL0EtCgYRIfTJQ5pYRFSD3nvMf9Nd8irP4P2M3sY 6EP96SHKDQ0w7biXQxybt21x7w72rN0AqF+SxF6P6clSQ2c07/Mp238wNF7To/uXAIlB ExfoxXSc/N4qVR9zO9aTRASDBpsHN91/tAIAs/8LOEp3Grvg41AHsHcl/8emVWk2TME1 heAFDzXFSBf5E4fHQrsK3sLYHldg1bo8PA+sKbxtyKMKJpUEO1JZBywjlMOzSbwxzCMg H8wTxWKL++cFr8VCrJWAi1ppLNxqxOLNlbMTbTS3eljtTl9soSq3/aIO8DbwOfotOGQE l9cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197227; x=1734802027; 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=K8c4bSx6OeCafE/EjjWkj4NBjcuAlryx7NpTdvjZLKQ=; b=UtiS3f8bSuDr1ZMPHqFSkAmMcRN4ubF2evxsuZv7VnWX35zbF0EECAcdyP3RByUr1Y v/2483r3mCnIhKBu3TEGDEpGsMGc1D6Q7rw+JwNhfOXkIaTOaKhjTVTaJk/MA4WXSdlY ocrXR4/duN1mo7CbwYmyp+6tXNl+vUtIZJwf7icWT/taFcmtxUHrEZxPATEdMjSt+mIS QArTxfExjnMIk2VZA9pu3iaITthN+VRpR21n+2tsVbpAa3ZqzLT8xZcbH+umxY1UnMFp o5jJc4Q+3dSbQZZPwvz1W+yEsq3OTGRFpdOcVx+PVKWXlQ+049TK2aHb7TF7h3CqRfHH XCWQ== X-Forwarded-Encrypted: i=1; AJvYcCXOrv3dCuhVHZgHi5cdsHhqnTTGl5L1aopEs/IaAcLUa8hKlt5KIPBl9TOwLgg9N7FlDoPvUEZ+zZky8Ic=@vger.kernel.org X-Gm-Message-State: AOJu0YyFAm2w4zXtO7q9OCywk3/N1xWP5D6X/cJH3NK5s0fD+hmd1L2v znW43LoQ1kDW/1zRjavT/vT7WSElJCuv2K8nwMGcsceO+GYGXemIvizb5NekJ+Q= X-Gm-Gg: ASbGncuuW6/nb47ubvcq5MPJWB1B9nLklcy7vygtslVm2eUn0Yd8LfPRoJ5y8FyfYdl rHUh3XDPkjEvM1somiF7pRkHsj0PUl1WfPZ3p4yqec3MSRyYQWUkcXwytVsi0cJ/Mo+iV8aMLkq CAjKPaXWzG4fx4paSjBAXnqrlITiFpkQ5kKV/Cf8M3SKxB4GSPVAPI1LvrhEU4ifL7b+rmqmCbL j35M2ttxyrXjMSo21b8YQGxQm8cZP/D1YLSNnuZFRGyldhX1Bb5zyvFoPWriVaIbyiGGGIKcobT uVMP7WYUXj7iOR4= X-Google-Smtp-Source: AGHT+IHUcfTVYGQvMkfUU7jHBszvrCcnJgKMrSzxBafo9cGQC89Lrd4GQaGCXdK1f1d1ktL3gp5V1w== X-Received: by 2002:a17:90b:4a4f:b0:2ee:9902:18b4 with SMTP id 98e67ed59e1d1-2f2900a9878mr10311790a91.27.1734197227250; Sat, 14 Dec 2024 09:27:07 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:27:06 -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 v2 09/11] irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC Date: Sat, 14 Dec 2024 22:55:47 +0530 Message-ID: <20241214172549.8842-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/i= rq-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 =20 return IRQ_SET_MASK_OK_DONE; } + +static void imsic_irq_force_complete_move(struct irq_data *d) +{ + struct imsic_vector *mvec, *vec =3D irq_data_get_irq_chip_data(d); + unsigned int cpu =3D smp_processor_id(); + + if (WARN_ON(!vec)) + return; + + /* Do nothing if there is no in-flight move */ + mvec =3D imsic_vector_get_move(vec); + if (!mvec) + return; + + /* Do nothing if the old IMSIC vector does not belong to current CPU */ + if (mvec->cpu !=3D 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 =20 static struct irq_chip imsic_irq_base_chip =3D { @@ -164,6 +195,7 @@ static struct irq_chip imsic_irq_base_chip =3D { .irq_unmask =3D imsic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity =3D imsic_irq_set_affinity, + .irq_force_complete_move =3D imsic_irq_force_complete_move, #endif .irq_retrigger =3D imsic_irq_retrigger, .irq_compose_msi_msg =3D imsic_irq_compose_msg, diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index da49a160ea09..c915a5cf4187 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -323,6 +323,23 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =20 +void imsic_vector_force_move_cleanup(struct imsic_vector *vec) +{ + struct imsic_local_priv *lpriv; + struct imsic_vector *mvec; + unsigned long flags; + + lpriv =3D per_cpu_ptr(imsic->lpriv, vec->cpu); + raw_spin_lock_irqsave(&lpriv->lock, flags); + + mvec =3D 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); } =20 +void imsic_vector_force_move_cleanup(struct imsic_vector *vec); void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *= new_vec); =20 struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned= int local_id); --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEC5E1AC429 for ; Sat, 14 Dec 2024 17:27:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197236; cv=none; b=V6ke3QjeUZ7uX/p0D8oI1IDV+iYv84nH1Vv44zfNpQ8lSxdWi06Yfa1qMSsOTy7e+B8rPmplkVRXwU5tPRebSYqGjYTk7BV7cZ5vLH55Tfb30tLy1rOGk7rNSET/ZDkoudFas//96hUcU5OX6+nHrH6+lzcqCPRt5m7UCTiY0Nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197236; c=relaxed/simple; bh=rcWXudtubpY/LSH8y20isvvWa3ivWgmUdiDIzyRLaJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eOnOVqIFvaokQCF7U+ubnQWmlfY4XakPftU+4cZxszQi75XbP02bWruJByuqHal3hpXCbiX31fadm+pepm9s8DRT9nfScuhOUaEuAZfUHEU2kpWUiZSNGvJoHxVypvfiQioZ17ubfpmhdH3PSdHdxAmaHtoOpephM0lfbx6hoPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=L/WpQJKV; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="L/WpQJKV" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2efded08c79so1919805a91.0 for ; Sat, 14 Dec 2024 09:27:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197234; x=1734802034; darn=vger.kernel.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=EP+pJC86HytY47PbI5sMBg+o5TFAFMoqjjekp4WBZSk=; b=L/WpQJKVwRCMzuBpUIPkpyuxxiQvlsDAzHCIKFAn8RRm+0kqZLakdH6iqjOHyAZbrE v3kwJM0Bvy/fgA1X5WnSwiYdQknQLVbd0SGs7tAAiDHFfqB0U+/UVPFG7Cx06FqTbbmY urw5WPxUEVp/AfvIP/owoTY7P9D5vrzz5x5EizCC3actuJUF/ZydOEewGlZMtxTo7FUv zBGl5cLYUe//2LIWrH6+VnyBvA4ThjEDiYJmWYd2OrLQP+ZHwCcGVYom0L02Mt6PYZhv sw7aKkXarYcQ6bnXWLR3nY0ALnrbDMFPFnJii3/8COfNF3gT8RluCwtopfsxa286RKAp BoLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197234; x=1734802034; 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=EP+pJC86HytY47PbI5sMBg+o5TFAFMoqjjekp4WBZSk=; b=kxhdj0pjYdTlj6JaiWsaIhzwMFA3kPAhQwczjRHVDxct2ja6SvkNrcb3lkiafVwikx v3QVV36W4kMLkuq3rvjCdKF5EQKpO9afvL8ljhDh7ThxMWWQoosgYsqnt23J2OGtjXGA m2M3mnIfyuc6nEUHsTD9ID+rlSV7UDBWMmYsaYJ5amE3flm7sIDggXCJqIl+/+tNQBzV I3NuvaAhhHLfHwUJUenWLa8XgbEwbIveO+EF1sqqvFYIgV+11DpFoiEZ10qt5BpBafI+ ynXImEdTpY23unoI6Y0JUovZD3IGz++OQvucjvnSwu7tLm+/gBSkYMg2UmG3GIaT9oh6 4jzQ== X-Forwarded-Encrypted: i=1; AJvYcCWEKdMAPZZplHWu1cVTtm8Fxhyy+SvXakG6D1h6LiddzNYhrmV3y5/NTqfHtnyhqAdDrh0EXX1zq5KH/f8=@vger.kernel.org X-Gm-Message-State: AOJu0YxlYiRN/FN/Kzur+dMMGHPWnWPdME+hQMVsgGbc/tRssy71J8Vx 7YwuPkI1IwwgoWua1MHmz67uaI+eNqVP2SuaX9xRpM0R5mhefLAW4dDttSXsFJU= X-Gm-Gg: ASbGnctunNhC5ziHf40wQueZnhHc8uZu1NccZIlQkX0AT7iN5lCd9981vrN0aAIDise lraVG/4Y5utA/6gzLuWUoGquuCWidgEPI+h2M1cOVCo/rWJFs4lA2RrTlcTgj9tfUMfeFkyI1NE p/5KO5SqzPfLKcC2TWmDPBjlAWfl2qN3mIjxPRg9vCCGXXaOUQILMnQdbttexCNRPYzx1MS4qa9 uLi/uIuisy553X5m15ZL4QsRAyhM+OJC9cZZmPb4vk8AF8L1fLP2VSghmPFLRhaWPa901tSB/h1 UBGE1KhWrI52Oh8= X-Google-Smtp-Source: AGHT+IEViE/EyOEoU9avO8xOUuGHIK7Nu4di+ccQuUelW0qrSBcAUC23H6R13dSAPO44yc0spDyzYw== X-Received: by 2002:a17:90a:ec84:b0:2ee:f80c:6889 with SMTP id 98e67ed59e1d1-2f290dbce03mr10584296a91.33.1734197234199; Sat, 14 Dec 2024 09:27:14 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:27:13 -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 v2 10/11] irqchip/riscv-imsic: Replace hwirq with irq in the IMSIC vector Date: Sat, 14 Dec 2024 22:55:48 +0530 Message-ID: <20241214172549.8842-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D irq_desc_get_chip(desc); - int err, cpu =3D smp_processor_id(); + int cpu =3D smp_processor_id(); struct imsic_vector *vec; unsigned long local_id; =20 @@ -103,9 +103,7 @@ static void imsic_handle_irq(struct irq_desc *desc) continue; } =20 - err =3D 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); } =20 chained_irq_exit(chip, desc); diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-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, c= onst struct cpumask *mask return -EBUSY; =20 /* Get a new vector on the desired set of CPUs */ - new_vec =3D imsic_vector_alloc(old_vec->hwirq, mask_val); + new_vec =3D imsic_vector_alloc(old_vec->irq, mask_val); if (!new_vec) return -ENOSPC; =20 diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index c915a5cf4187..aca769d915bf 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -434,7 +434,7 @@ struct imsic_vector *imsic_vector_from_local_id(unsigne= d int cpu, unsigned int l return &lpriv->vectors[local_id]; } =20 -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct c= pumask *mask) +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpu= mask *mask) { struct imsic_vector *vec =3D NULL; struct imsic_local_priv *lpriv; @@ -450,7 +450,7 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hw= irq, const struct cpumask =20 lpriv =3D per_cpu_ptr(imsic->lpriv, cpu); vec =3D &lpriv->vectors[local_id]; - vec->hwirq =3D hwirq; + vec->irq =3D irq; vec->enable =3D false; vec->move_next =3D NULL; vec->move_prev =3D NULL; @@ -463,7 +463,7 @@ void imsic_vector_free(struct imsic_vector *vec) unsigned long flags; =20 raw_spin_lock_irqsave(&imsic->matrix_lock, flags); - vec->hwirq =3D UINT_MAX; + vec->irq =3D 0; irq_matrix_free(imsic->matrix, vec->cpu, vec->local_id, false); raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags); } @@ -522,7 +522,7 @@ static int __init imsic_local_init(void) vec =3D &lpriv->vectors[i]; vec->cpu =3D cpu; vec->local_id =3D i; - vec->hwirq =3D UINT_MAX; + vec->irq =3D 0; } } =20 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, stru= ct imsic_vector *new_ve =20 struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned= int local_id); =20 -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct c= pumask *mask); +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpu= mask *mask); void imsic_vector_free(struct imsic_vector *vector); =20 void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec,= int ind); --=20 2.43.0 From nobody Wed Dec 17 16:14:10 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71DA81A8F6B for ; Sat, 14 Dec 2024 17:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197243; cv=none; b=BM6refxZIfEMMwm77lZ3FgrSq1rabXDANzDABPb2G/QiwXpwV/M4C0LS53SOgwH+kbriU2TOpjdmdgZWN1C/scPyJvXif2mcRLwlHqnzasuVq3OhpFB1PT0YZYKNcPBpqiZNbK5B7NqO8XqIpxUVLlMdIDbvZ/5ivo7Wd2GHeR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734197243; c=relaxed/simple; bh=y8LyhxLnr8gL59ez8smjdkMSejl79VB7Tc2egqGrEC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dY2WThnjyvSBOkoUgGvUGpqiybd8RtlO+H8QVf3IE7py82rQuoLUIRzI08ywqfBLFbA+4QKxHgpVM1tgT5oAZEDmVFHpXjElL53wehvn1nBpnCAxIj7eQnrMZdXYKKzGAeGguT/Q18HZnGQnoqwTXYIkzdMe8GWZgnSGvnjGPOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=dJ2yIitq; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="dJ2yIitq" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2163dc5155fso24614145ad.0 for ; Sat, 14 Dec 2024 09:27:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734197241; x=1734802041; darn=vger.kernel.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=Q91PIdpY0ToxJxjWetgT5wSgNIKHhdsWJzKO3onxaMI=; b=dJ2yIitqwdqTpVAHBuU07bw2Zy2Jd2eAFyVmuyzfZ8IWrfhmVuWcjXKpOmUEfyQHMZ a4na4YOoPmd/G1gqpszkqqzN47jCUCjbuv2kVY8RcLy5DBYZJBbbl/7mtJZl/GEQ1Xf4 kIzVTc76uGGSTZFnSlZkLQTikzIkWRmEtx5H252ExoqXOx1WGzWMZ1vTHh7/+J0L7Ili DjnPD4yWmolQKVrY0YYUNXaTIwKmDnl6r3AiZvfVwMxQZiUgwqZ2bpKb2Wr1phHz3AXB ozpnkVy0SpsCXBHM40b/+0IDC/SnO4qU3gr4XdptVlv3oLuCPBj7IpCfJgzTkowxFVH+ BE9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734197241; x=1734802041; 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=Q91PIdpY0ToxJxjWetgT5wSgNIKHhdsWJzKO3onxaMI=; b=QwaU8xejheg96dev6JQYJS7Qj+n6IvI9KXJU/tm8CD6eYe1pCj/q7SG0ssTleiWJhX Ehv8jZor3HpJPJQotqW+YKMcOILXXxih8QCJVw8fELgWJrLJNZQ55ad4lOs5jm7t2Tmj ZBhwLh1HIf6ua/YE1sDK2alDbrGhCyNxeFCVhAkhjj5ZLan8haSu1MhnooaePJtyYsXe 9AXpVgQqMHYpW+SdV95ChOqDedqd23Fw+6sPzxY2ZNKGpsco7VPouowOY2OgNxbVkQw1 +wMobGROXLMIHxjYx7PnkDEmTDaYxjI1mLT3HF8BIvq3s5Q8ofHkyczbuHw3TgTlFhIe hmdg== X-Forwarded-Encrypted: i=1; AJvYcCXB7OQJnR6A6rJZiXtCWNvZ+adpOkXuH4piiGmNHx/7d2jOzzEO15aCCbkCC5mQgepAUdMOK4gU8z1w5Xc=@vger.kernel.org X-Gm-Message-State: AOJu0YzM5fgNxhk61EP/YSHG8ovx65LdHTK7lNdvZ0+Z3NEK/2dkQtzD sPTWAXsMrhUIUdJxkxPf6iNaBiqxRCJQjvsCAz6Wdsa66P9c6R6AYnWC8ObRQFo= X-Gm-Gg: ASbGncv4YFgU10J5OQJQUJdtgmyMi5KxLkLWXjOR6DjBhSjVvdq+20gHcXm70upDcd8 actVdkC7DuAsx3gjrFaB7xgFi90x5Bi2r82XSA1zZDye0vnu5c56/DmOO/aLcrX8o9fncqWzJXS yJh8uASB2+Ui/uyr45vtyIspPBskvqF89RMBIYUruJGz68I90f9OrY35zCJK5NXllbO66sN3GsP OwNwwTYsL7Zb5AfOnSIargTdTBJt1J4KqZpqi/P9xOINHT1LJiN4f7q7Ua1jpBa0yOEFBGD0T9U 5yluC6AZtpqzKBE= X-Google-Smtp-Source: AGHT+IHMsJ5YCvABWOrU64w2NgYzPATagi+l1J7ESIDXSbMnwGULGsvQOBHQ97Lfbn1IK/p1gbun3A== X-Received: by 2002:a17:902:ecc1:b0:216:46f4:7e30 with SMTP id d9443c01a7336-21892a42024mr107832805ad.43.1734197240770; Sat, 14 Dec 2024 09:27:20 -0800 (PST) Received: from localhost.localdomain ([223.185.132.246]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm5049811a91.41.2024.12.14.09.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 09:27: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 v2 11/11] irqchip/riscv-imsic: Use IRQCHIP_MOVE_DEFERRED flag for PCI devices Date: Sat, 14 Dec 2024 22:55:49 +0530 Message-ID: <20241214172549.8842-12-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241214172549.8842-1-apatel@ventanamicro.com> References: <20241214172549.8842-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/i= rq-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; } =20 +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, c= onst 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. + */ =20 old_vec =3D 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; =20 /* - * 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. */ =20 - if (new_vec->local_id !=3D old_vec->local_id) { - /* Setup temporary vector */ - tmp_vec.cpu =3D old_vec->cpu; - tmp_vec.local_id =3D 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); =20 @@ -198,6 +198,7 @@ static struct irq_chip imsic_irq_base_chip =3D { .irq_force_complete_move =3D imsic_irq_force_complete_move, #endif .irq_retrigger =3D imsic_irq_retrigger, + .irq_ack =3D imsic_irq_ack, .irq_compose_msi_msg =3D imsic_irq_compose_msg, .flags =3D IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, @@ -217,7 +218,7 @@ static int imsic_irq_domain_alloc(struct irq_domain *do= main, unsigned int virq, return -ENOSPC; =20 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 =3D { #endif }; =20 +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 |=3D IRQCHIP_MOVE_DEFERRED; + break; + default: + break; + } + + return true; +} + static const struct msi_parent_ops imsic_msi_parent_ops =3D { .supported_flags =3D MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags =3D MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_PCI_MSI_MASK_PARENT, + .chip_flags =3D MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info =3D msi_lib_init_dev_msi_info, + .init_dev_msi_info =3D imsic_init_dev_msi_info, }; =20 int imsic_irqdomain_init(void) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index aca769d915bf..c7649fb6bbe6 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, =20 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 =3D true; int i; =20 @@ -170,27 +170,6 @@ static bool __imsic_local_sync(struct imsic_local_priv= *lpriv) */ mvec =3D 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 =3D vec->local_id =3D=3D 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 =3D per_cpu_ptr(imsic->global.local, tvec->cpu); - writel_relaxed(tvec->local_id, tlocal->msi_va); - } - - mlocal =3D 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 =3D per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va); --=20 2.43.0