From nobody Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 8682B2063D8 for ; Tue, 4 Feb 2025 07:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655676; cv=none; b=WZOOCz3WYwuqfR6OShHFqufnoYnD1XBjI//rPvLtaRYC/au4r0MV1ecrpRKphHw5QATk6l5mywydJI1mv/eZAAf6R1F9eORwXOgl7aZt9ZdIJayMCca3HObTnGJxSR3IjGNJ2s1CllbI0oCxjg/OK0iTHtzKU9nhHbbL10CF6Lo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655676; c=relaxed/simple; bh=AjbhMTp1aGsIYrzh3IEvyIDO76drMFMoCVTh2CxsqAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z14WVw0Hc8+f3XzSJV78t8dRIW50mnzhyWKdOK8UBvC65MeXTVouRMraq6T9rfZeJLZLRxLui1daKrlptudJm2LwhmB1Gs4ecnRYVXwH+MEGBs/aV44MGUWbslWboWzwMmOkRQs6POLhm2jp2fXKCJVjw/coXZ445OL7HnIqORE= 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=oieigB6q; arc=none smtp.client-ip=209.85.222.178 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="oieigB6q" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b6f95d2eafso554449985a.3 for ; Mon, 03 Feb 2025 23:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655673; x=1739260473; darn=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=oieigB6qc6Set+h7oknfwE3PBiBKiPX2rXFlnxCPDIDl3uzfiV6LpP056usb/l/TN7 EcGcWoVT7nK7RH0CowvDb7CqHlcjvN1b56OlSQD4fEf1ngPxtKZ8tHBSoJk6s+fWPmxH qkhbSQyhOPdQgg/eDERcd8wDhm23qtulSKQuRa3T1TZGqbO1zwjECQoZWiVZboQderEf +0Ah8axwYNOuHYpE+t0lEf8IOQS3mieLwDauK3NJ1B8RJDB1Hnei6fCurJEk83kYSkhv C9RJjVEUfGA5Ok3sskRUtbSnXApndCp7encBqGnKhFcqfTeM9HIlpJIcVYQWxoFwzv53 8/hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655673; x=1739260473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CBfvQ3kWrJIo4ZX2fO574K2xNLHLI8xt5fD3UcZCgGE=; b=LaJX4Zo2f5Plke2F3z544G8gMxzVD7Ga3pS7NqLDbEZP73yp4UAMl4TIaXI9eKXgad UfiSeyO2pZF+KdI8mAJqARX80KjNXG1u85U/Aes6VMPMUR5eRINPkJOs1nDD7OAwePbC XRqtMQFlQyH0K/Icy++HXxJT9drAtuSDR5Azs5ZKBSMqc5N1UBPlPm6oIlR9AfKsDNms U+liOR1aHe4aZi8G/nAq1BUfYcnFs3/r0lpXjZjJ3SkHpcwlUYI+ZtDwUK8a5oOndKnJ M4Pjx2bjidR4lXMeqTan83EYgQ+WVAyWjtOYVgHS0VeO53ZRRDepjypMAaeS4fLoHWte t/iw== X-Forwarded-Encrypted: i=1; AJvYcCUK7E3q3RvMSRLLMcgQWGqS/v06/2X4c7kNicAzKU8l/ylCbae4WR9Av9TSjZbsUh/PTjxAWNQbiHjsBvY=@vger.kernel.org X-Gm-Message-State: AOJu0YwuR0oVmvLb+v/XCbt2ICyFFUG6UJnXD6KRXHHRgR4HADGHU87q VnlbgYSGpvyeVEd39NGiJE1KwkcqYtxNmQoxjdDBW2oqKHb5ePqrGUk4ZFiXiOo= X-Gm-Gg: ASbGncvLISG2LIqywRkAtgLDKQxVewqAdNjFBly1Vw7Fn7YPPtmUr6l05ukKE2x1xQg aSqsPra7JhElDZ+wetojH5rMDoM4z5OtfEBEf5s/6P3+uru1f7nYHs+/2qzBzQ1os4uHvzJ+tQv TxILPVaW/jjC9ga4WmJwGxmeo8DWYDWeEAOv7/PEMR7gShAkKh1II1v6CrxxZCvXjatCI9ZMxYo ojJBnn71cDd7k55Ve94ge2qZ9Q7D9bDzSxZ3haGuUAuUABkw4Qjw5tl1HSF4eeYeHNCmfSYuYYm ikZgrwgrHOKMVnK7Mln2sCg2E2EcT0geG0Hf4osyt1JK7Kw5FAtMU+U= X-Google-Smtp-Source: AGHT+IE1kHVojceFVzcf2jbW9XOHhUZiDggCrSxIzTiwYNG5RUoAlilnWj5uEbIRStQ4m23HHT45hg== X-Received: by 2002:a05:620a:4093:b0:7b6:d1e1:a22e with SMTP id af79cd13be357-7bffcd43a1cmr3525668485a.29.1738655673185; Mon, 03 Feb 2025 23:54:33 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:32 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 01/10] irqchip/riscv-imsic: Handle non-atomic MSI updates for device Date: Tue, 4 Feb 2025 13:23:56 +0530 Message-ID: <20250204075405.824721-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.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 E16332066C2 for ; Tue, 4 Feb 2025 07:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655684; cv=none; b=mHFOK9LAAFenDFf1fc5XAx1PlB15hO//gbqa1HiMRP7a0knl1llNYsQ1VzxM3Dz4BcEX+PQtPlwAkIsVkguzmGunm6IkrW9Ot3Kk/dsiPAd2rQ2ADCrAbc/VUhvgSs4V7mVXF6/zY4weiJI7X6AH+oVPDH7WAqUczs6vnmIbdVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655684; c=relaxed/simple; bh=GQ6h6qnifBeRvwI5lbrzx5DePz9FG/7AwYjLLcTRLyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gvr9MN0JyvCNhoujN7BAzll1ex/Fy4oBHi0tKZLAjcqu6x/0e5VODTohLx7apGo6Ai0GMDn5CUKeeWDRfbClTZQH4+8VwAOGL/oE8HIH0BkfsDwGuyEBfW7uuwCTE/Nt1wSlrn6li6LC6EN6fA5BJvsXP8ykNE847GOdAG/uu6c= 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=EO29P91Q; arc=none smtp.client-ip=209.85.222.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="EO29P91Q" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7be8f281714so472420785a.1 for ; Mon, 03 Feb 2025 23:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655682; x=1739260482; darn=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=EO29P91QA63DYCtsi8wInhhpySP5x01bNaX9mdBeGmKnElvTBIaRdwY5Jj0dTl9OB6 hMbCIAH8CwFGZ8+JzTacV3xraYfoXXbafTdsVQvjbH635bqOzPUXApoSHKt0+wrcz6sk kNw0NiH0wj7DtyhBhSKqUxiRhC7kLEyEXsJChV8arT/ou3jm/bapHAulhCWUF9hcH71z 30KC7RLGQwM1u3aq5wHh7XuLMl0ROLZzY5aL1FR2IzrED35zSgTFION7vIJMrgT+5u1O rGQyQ7MRfgK26GKLBImj9Ic5jsID84NDdM8Ydwx9x5rOJXQWeiAlqj+byvsqAgRFGjtZ jZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655682; x=1739260482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=ts0H86zpsyHyhp7+eEql4BgqRqt88eLwMRaLqzlYoz8KzCI5RBXeRclGP1CduOPScR CSwmKLybwbLqp9DDfCIgt4D6FWXwoeKJh/ndEFwRwpoG+1u0m7RgbNFK5SnJATRPkD5x uc4jmGn3OZ5eWKXKbGTU0N9LqZrmEYlfSLQ99MS2tZ8PskNOqukMcIc5NjveyGUQ6GKU 2L6v0Q8zzihlYFAaDaSrYc5VJ6YawXj+d0t/P75tYyAjHtDBN7cdFMknLUaZ1UX6rjrT XLKTww/vPppUGgy6K3h6/e3kEU6nw67jCtj9cdLjGHeh33/VAhzXx5BnBHD1PGS7DLDT rcHA== X-Forwarded-Encrypted: i=1; AJvYcCUCqDBrOascEVhxcppAU7wQyckJOjIhN9BEZoM/kXsb0j/jdlFDsdhlLADfy3ET/oZTHByqZeQyzYwWItg=@vger.kernel.org X-Gm-Message-State: AOJu0YxYiNe8nTTOe63FU6JKeEkF5nm+WirrhlHtWPtoUnCjYbnmbIEm 3Hx32yWRrrhxI10sVlSF9/MgRdlbrwX4++KU546gbmySwUsajj5Mv0qNTrnYHx4= X-Gm-Gg: ASbGncvxm83G/pdkkkmnBVH5LqCglCmYJfBINt+w31E49GIXgD3sbG4Ebr4WdBIJy6a inOqCb8lU0OF3l5ng52uANrnYBsbYQcKELvG6mvhtv7t7VzQbr8+QtD5dgyY2KvgWyCB2jv+lxS FhKrxU/xdPh+sTacRLvpKajbunwGdv0uA9Ua87NEWTBwRGuRaj7Sm1U2lv6wkQKDaA/7egXj41A XmxSOvSxX77I6UEzKuB2agoC94ZzwGLi9yxonZ6vIfubuX70ImL4XLNY7/2fZ3Z3wKVe5nwLQNy wSkX7KgQ3E9fh4DZqKzelrB+D1Tzvs+8571E872VQhgzblDk2sw2Ock= X-Google-Smtp-Source: AGHT+IEhdMB+vtxDJGF7LVgqcjkCxx8rRK71YEAfpN/qTx2NMyGfi0QyTUHVXR86sg4Wl/xvt3qxrw== X-Received: by 2002:a05:620a:278e:b0:7b7:2de:6fd3 with SMTP id af79cd13be357-7bffcc3cdfamr3041523085a.0.1738655681635; Mon, 03 Feb 2025 23:54:41 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:41 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 02/10] irqchip/irq-msi-lib: Optionally set default irq_eoi/irq_ack Date: Tue, 4 Feb 2025 13:23:57 +0530 Message-ID: <20250204075405.824721-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 2EAD22063F0 for ; Tue, 4 Feb 2025 07:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655694; cv=none; b=BMm19AYSfqDwNTIOmzUi38v8f+tCG13j1UK/qyoBUfX9e7wAVYoKaJHsAxmNjzSBxoWXflMGBAEpj1bLqoVnixsQ0Gputc3WgCL5JxXdk7iYnIRZcPtO5LP8WprQLX6erdJLZRqVsZMs+lWjAiOt0m+YTVmDgUCWzb0Q4WAZgdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655694; c=relaxed/simple; bh=PcKCiIKJzPJB4OrlTg224bcO8uJZAUgM9GlGe6uz0Po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FXI9E7IoUAUIkHY6foiaKt73Oi+NISsCGfPFLjMUHUsqiP3LrYffiAgm+NjPz0NGHtWSWwYMFnYYmAGinBpWTrzC2ukq4oZ90uRhN5INWnZEd4ePtLP9T6CHi6H+icqvwNUBlHtGnJiG/mi/qP2CsRkJvUiNnrcV3xvxybyIuu8= 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=gakhzPml; arc=none smtp.client-ip=209.85.222.177 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="gakhzPml" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7be6fdeee35so833546685a.1 for ; Mon, 03 Feb 2025 23:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655692; x=1739260492; darn=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=gakhzPmlkxzdpKmpKYn7PqqSCcwvKhXDFhCObnBDLqnSEU5l50yrhLegoqDLKciDOH KZUiDfHFbtgE91G6teRdH+4CysCR/gyuKgOFyMdXC63f5qyMcnwaiVmKrEk4xNd04Adk xCToE1Rv4P8Z4qt+0WLTwcry2eYEYRaMi9E9WRzIYqhUX97T+YKqPguFH47OQTayV8V2 7AZ8IjIj2iCScRFx4HzEZCPIpB3JAuHGvCAWIjFYMu0NDxjz5f2Z9U6GK+VQDxhLmHuH 5uffKdFhF6o7VwtETDSMgk26jr/OW9jurzHokjG71teEt9gNKEHZUCpZMPLzu+9Qaz99 W9Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655692; x=1739260492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+XpbAvyCPU7XjesnTrNMuPwq8s0Ofi62LAN8USKi2As=; b=Wz82HZbrs/ZhOnIw8fdVVa+WiDavltD6uvUPeVYQEG/BZ5fui11DOGHEVJQM508mg3 mXJaSwzpchHIB5RQCbu/+iYP+0vK1wr5+vWPEYGik40ow4ybW8RwbR2KtpLnqadbraMw vRj3nv6zUPpcH8qBQqgbcfn8Y3tbsYJg/JKvZdGn7aNBaT/bWULjz59/CgTsM7O+rmEt +7fb+toNBku5MCpXwipt1oXmYfW/iqCVLPXE5Ib8POUh26om75CFF4p0OfkJnk5PSUr5 xg6h0E2PFgLtu8xxVR+SMn8o/G0Ts4SByK5bLT4hahiyDpRMD+jQAD8DBsJylBMnEN8x BR3A== X-Forwarded-Encrypted: i=1; AJvYcCUXYOOXrtfjayvCIoE3555CxZu/33BY6DckkIK8soMbEV84UJqLRP8wf/J+4YP/8QG/jnuv9B7jXB+DJ/s=@vger.kernel.org X-Gm-Message-State: AOJu0YyrDumTuOFZlAcTsZ5OpPc2F28ExjDhNOE3cEDixoGuNMS9PiYH ADd98Nc5ddnSEdlsWNjQL7YuBp1ATSh7vv5twFcMwUSo+5evrvO8FIEN/Lo5mzE= X-Gm-Gg: ASbGnctw2md1EgW/FsEGrXR8XrcZJJROQR7W8eV3MVZDz5Kt1bawZVv+xxbT0kvV1RD EnzX3q8CmC5uYJIe6/F99hzkK3FeeKK0TvgziJRTtO0+f4qbiqT87MpZhEc08kAZCbevRkAON9s CMtfPjTNyLDs+bXQzXyZ7UqljIRzZjUSHPiK0mGp5z7gPxgQtlX6RbQlFw62u1Xgajv9hqySA8M pIEIBjROARvMnvijdrcZBhaEBZQ7AmPeeaAxZA/mNrfgr5Qhll4nkyXZ2A0JPp3WLHTuCsQd+eI O1F6s7518qqSLC1jSNYEa2Cd3bgLNhUehyfh3RcBWtO1aZAin6RLKZc= X-Google-Smtp-Source: AGHT+IE555JYDjxayJP3hHqE1TDj1cVPpWMaeaM/3WguRaZQLIT7OdX0Wc2dai4BACH0ZbT7vjefxQ== X-Received: by 2002:a05:620a:8395:b0:7b6:6e59:2864 with SMTP id af79cd13be357-7bffcd726edmr3656909985a.43.1738655691894; Mon, 03 Feb 2025 23:54:51 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:54:51 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 03/10] irqchip/riscv-imsic: Set irq_set_affinity for IMSIC base Date: Tue, 4 Feb 2025 13:23:58 +0530 Message-ID: <20250204075405.824721-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 055E02066CB for ; Tue, 4 Feb 2025 07:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655705; cv=none; b=VPsELqbNMkRHAZAwJuVFP+3QoOZ7aC0vftpiNwVMr5ld4YBr5rzzMBZ6uAJALO7LBht/cIKDsaszM2DyeTgtT6Xm6jdvp61uzzx83lHV2owpXJUPZtmKLj4YGpXBneHv8rHCQpIIhv0Es4oPWUswlZVt+Nvq36GUnlLdn1elMPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655705; c=relaxed/simple; bh=7gJvPid3DXWBaccKmSGjzDBxql86EbMZzc8CNdQfv6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HnkK62MHJ0eKsvuGjl0mYuDy3PZk01R19u0FQVD1+JY8CN9LyOOjhJFCQQ+khBMzucaMkcG1poKDJ5gQUVqf5Gyl3deFYQ7f3dV/YfHLzJjhSTymrkMlefgHY17t52nBxKrsccVuQVRcLlKSg14v9la8ngBbtYc3qQ27zE4AZWo= 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=TqhXKk8Z; arc=none smtp.client-ip=209.85.222.175 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="TqhXKk8Z" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b6edb82f85so781548185a.3 for ; Mon, 03 Feb 2025 23:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655701; x=1739260501; darn=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=zt4BUR1O09akAiE35kyzRFyQQsTBDdGx/Mpea27bkKs=; b=TqhXKk8ZmjzO0exmvbn6ft+3bO+lynt7U3P+AtHsFqkrnDZc+pH8JZSeiCp6Kg1xdn EjKeG7sQAn5urAdJXhwufHKgzYiTk6gmnTQdVAreaMwWBcnxIzYcdRJC5gh/NA/GK4Tm yPWXIojtaFKxP8FH4QNPIJ25cbFmuDO5iq8pnqglVYkGMvnlIyQrr48FhAy+/DXlM79Y iK9SatUDnbyxHHOxpYfRdYljIE6+HnaPuBdLnJo50DR83lhQRTUmiCkkcV9PHuIuuWke FWBNulrYkrTOf8ehbBp+26rfHBxFxjZN6N9cNUPP2zXg3ZbISmFyU2IsV2fu8lg8uw3G cO7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655701; x=1739260501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zt4BUR1O09akAiE35kyzRFyQQsTBDdGx/Mpea27bkKs=; b=OJb8nkA2PdoQIVCZz6aj7Y+ZMyzIZTZTnjLmjiY9CuIkzvCv1UlCmXOLbR5DjkRsfV O6p4WcY2taAd1HxlsBqgWOYRtAN7CA4En/hWAS2Bq9qz6M+QS2Vr47fHtoS5tBPin9be nCm+3qAeSnphhJj3jYc0n1YMwDKyc1GWjA8Nh5V9sjPsn8wTNOaPQxboN44aNeG6A3jh N20sdKsP4DN0Pq4Oj73tEFiNUedzYGYDz5Cr2voGITxMP3y+dvMNrPRVBdp4i7spX0SZ cHzZpAWNATMqwV4I2p2aebK28ZkDG0WwqpEk8js6DrGz6MDzwvnjvtfUE1VpZM2BJb0D URTw== X-Forwarded-Encrypted: i=1; AJvYcCWigXnsG5wOI0REkcRgq+fxkh2XAk/yn6IcFwQuP08Xju1r/PNf2G7wZrfq7BdEqg0Wl1RIWDnkkvjDkZY=@vger.kernel.org X-Gm-Message-State: AOJu0YzeCJ7D+9MyOhGHxccPuoCOdJaAs+mutTnmWdBY3AEbRH4XSEOp 12xTau43b/r0Lci+mPWSQkYagPG0Y9OrWywAXGN75q9azuNUnzeExL/ITv3Qmv8= X-Gm-Gg: ASbGncvpyXRLEAyV8SsXxZkXqR0cSK084M7OURD+IOefmIG9ViY4ipTa5WQVHPIYNZW x+Tis9wg/OQZzjechcnGGDneiBRoTOoh7rFhP03sbCFBbvFeUABUNhIJQ78F2T8PCsllSqgCuo0 IhGF6+ShJMi2L9V1/uRqV1ZnqL1c9xaX9W9YFX9BTVhY01rw7cWa/uVcZHdLRLo7mFmma9t7YPs 1McJVoW3ELYUuqRzULsZUVVW6CD4ny40lcQTLn+36wB/nfOmR+XpUvgMj9cBGu626bZ26gkK85I m+AntE1YcMVslX4jcCYIg6npRvdAsQsg7pmv1Fq7OWqa6PHcKgaWzl0= X-Google-Smtp-Source: AGHT+IEHo/ibp+o6qeQRlJusLW8jVVXpZtzwcNrNItHHxjlGS/8JBTsdvSnSG8vOxPC1otd04HpYwA== X-Received: by 2002:a05:620a:240a:b0:7be:3965:7452 with SMTP id af79cd13be357-7bffcd06b08mr4023625385a.32.1738655701483; Mon, 03 Feb 2025 23:55:01 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:01 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 04/10] irqchip/riscv-imsic: Move to common MSI lib Date: Tue, 4 Feb 2025 13:23:59 +0530 Message-ID: <20250204075405.824721-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 be063bfb50c4..bc3f12af2dc7 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -589,13 +589,7 @@ config RISCV_IMSIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_MATRIX_ALLOCATOR select GENERIC_MSI_IRQ - -config RISCV_IMSIC_PCI - bool - depends on RISCV_IMSIC - depends on PCI - depends on PCI_MSI - default RISCV_IMSIC + select IRQ_MSI_LIB =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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 2D7F12063E9 for ; Tue, 4 Feb 2025 07:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655714; cv=none; b=h6oxMiOER4n01wzJ8rp5LkZKiqjcGlO3GTLnjZ1/fA1JXkoYd6Lcd9gc/Aw32eDLO/hS1GDJPhtXCPMmMFsh9JqJQm0fIGCvzTWRYQy+Eb2vlHU6oDeyKA4tsN2ElocwLumcY+OKuM7zopXPxUx1XnF6FMBKexd1N6N+evtmCac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655714; c=relaxed/simple; bh=3zBJABDp2VjAHeAkIM6CLZBnc4fskYwTWZG6ia7OHWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oI23B6Off1s5Y5inxSPWasGq8mkIUjos+TaKOXv00U8f1YyDglWvF2C8HDX4ajA0Wj9kG1D7ibIO/jr9qKtia6o6aRi/56CPjRywhUyzHres8gi5mvZGLZPdbt9Z05xMY3jMnOusZk1V6WxejBUP9bBALZYWm2tfXdKGrhKUzvU= 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=dv98Ue6E; arc=none smtp.client-ip=209.85.222.176 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="dv98Ue6E" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7be8f28172dso263998885a.3 for ; Mon, 03 Feb 2025 23:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655712; x=1739260512; darn=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=zXz6fvQA0XjFVpb2cpM8OodOs5mmbZEn6PcelI8ZWow=; b=dv98Ue6EoIyi2Zku5MIDRZGlF091ZXCQnNv5Didp3fQkaLgTUIvIvJSRTPNJAwcS3W OAY+NxXgSe7JsF1DhCSMZfK+vAcXqlNrmMiyA/5cZMLxGZvp5bJ9J32xSEh3Euk1gwtX l+V9b9fXdSux3/cRohVtj5eGOukEduoaX5MPGJua/qmuWHxmOTSsawwfh7IyYNPMJkRK aDo/4/huRiZlslOI8VU8Y3FkCIgNmfss93x2W04cDLru62n3BVcOXMAkK1RuaC+AlmCu eyeYhgjV6b3f2PcwICQcT4Tt0BwFQsrEzfKl96gYYf6yOsI5nEHM9JlLcn2zwlCXvV6s kbOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655712; x=1739260512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zXz6fvQA0XjFVpb2cpM8OodOs5mmbZEn6PcelI8ZWow=; b=vHGgUxt4hiSk4+O4CnM4l5exHgtBAnIM9lYUAQHwMUl++W0itQC8T290ypyWpmNOxc TcoqQMUXg2tiaQCeRlRPxDow+jKb4V48u2cneGa7Cqsj4lgP7rSK2lrX8ImC4GObfZdg 543Bte2jDUHVvwgz0huANf9lm/ySwZ8dKOBVSfkb9JxPLgsRJlpS+ZcgA61BEJ3SkuFO BYaEHI+9nf0dLId7PABTyY/lhwjG0YkgCNSL20VkZEHvavIutKHZ+SQIrR95kxMr2ZNo NSvURTwk7g4Rkuy3yo8pf3/j8ni69hSFOLBGa2jF9d46E/v3GsHhRuJwaA31lCCy9sGJ Nlqg== X-Forwarded-Encrypted: i=1; AJvYcCUiEUfYr6b82hMO0tKKVA7Sn33Sb7EZ8fblo7qPBwXC/qjD8dN+wx789MpLRyvg8ZNi5/CQBb448BKQYiY=@vger.kernel.org X-Gm-Message-State: AOJu0YyUjhsgoNdEhVPSSbU9M5HixMZPCoNJiur9Gy0gANFeWCUjFJSB mKKJvZheglKErCvKAI8PjzHZ0ftb2mjMp/oN0asgxClb6/NU3tCdahYxxpoS19I= X-Gm-Gg: ASbGncvBAe7Q8a6PsHg65hgfh8gmg9slKxDZZwV+PiPewy980kwSYn9a6qTIf/SICQf tdoWRsyipoJW9bW+SzdHIwhd9D3ABZ8jEwXDlP7SPZz4yLCdKhd6O4CgsrTTUfPIZ84b9zkmr8G oPE3o8uWnrYmlq2CmybdJYrWuez2xhOOg0F5wn7wNPXNtWcOJicSBeoSC9SsfOa9U/8vgT5ZoE6 M4j9lmY7JpweKpSxBmUT//getpg7CaI/wKdpBEjZUFpUq3dCsr22M/sH0jXNqBrwr1VNOgeDm9S VyOD2vW7HTVvUj9MQv/q0kT7fJdZexcGmqR2MOWeDmJ2detu08dO5JI= X-Google-Smtp-Source: AGHT+IEygJlzRE1f+LllQAS/xZozPVCC5zlNa0cJxT7IbmhuAFZYxlHSMSOoINty/Bxd6fyVjhK48w== X-Received: by 2002:a05:620a:2b8a:b0:7b6:6c6f:fb5c with SMTP id af79cd13be357-7bffcce52e1mr3541223185a.15.1738655711939; Mon, 03 Feb 2025 23:55:11 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:10 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 05/10] genirq: Introduce common irq_force_complete_move() implementation Date: Tue, 4 Feb 2025 13:24:00 +0530 Message-ID: <20250204075405.824721-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 8daa17f0107a..1884fa4ec9b5 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -486,6 +486,7 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_= data *d) * @ipi_send_mask: send an IPI to destination cpus in cpumask * @irq_nmi_setup: function called from core code before enabling an NMI * @irq_nmi_teardown: function called from core code after disabling an NMI + * @irq_force_complete_move: optional function to force complete pending i= rq move * @flags: chip specific flags */ struct irq_chip { @@ -537,6 +538,10 @@ struct irq_chip { int (*irq_nmi_setup)(struct irq_data *data); void (*irq_nmi_teardown)(struct irq_data *data); =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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 1C4DE2066FE for ; Tue, 4 Feb 2025 07:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655724; cv=none; b=YJrfaMAvznANj/T8xyuexYqFoVF9fQomIV/KyuDQ06KFijAa0fZORf5ivU07e0YLES+L7DhVKDtTdGweCQXkZKCNCgXzm8TOPIL881BdwG/0yGAlyfZP6K6rtNJ+lfEepxGjUZBUZ4ULnvwV4k2LjUYok8fJEhHwD7AfxJhR2EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655724; c=relaxed/simple; bh=uce9NaG1FpS3X23DOslrodjhhQ3oLE1kQr7yQKAxN+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cP/sYQBs/zRreqj9wt2Tfo72eKNIxRnn7M4MPRo6W9zo3uuo4sMJzb/kNQnk+tVE2+X0hx/61d7j6OqPQQ3zZiOVMsKlIWQBpVblTXI1a9IMsP5aGzcApC8YrFXZ1y/RwjRrH+c4PHCJoQLwrXnM44MBSX5+GktH+OQONIEnPMo= 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=jHQc80fp; arc=none smtp.client-ip=209.85.222.181 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="jHQc80fp" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b6ed0de64aso455749185a.0 for ; Mon, 03 Feb 2025 23:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655722; x=1739260522; darn=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=ZnRpk/p9sKuCOyv2KZjNLOO6T+xrx1m13lZc/9SNpSQ=; b=jHQc80fpw/d/7vsisayfgMG+sMq4/UNkThpSj5mpoAcOe8S6yN6oLbdhxKrh3JHq8z dQPptIoeIWMR7oUAtMszlP4303UJdv65vPPhvfi0wfCQm1ICH3bGu4lPTMHwB8Lln5wo 51UlHgpwr/aXGfbl66zs6fle7t0Ka2sOcYJgqm+XlnhdkawIsG22FLHbj78xIL0CY+9t BB5nJe/YBF6LJoddvD4PyvYr8REnTpJsgLt1U4QPP1u7+lsqYTW7fh8zV1lzce8C3zEx Afmuyx+EKJGeBSH7QO2I6wggF6WwWRZvoFdBNsulf0fFmuubdNXK4GHhNW5GPj6r2uU8 qQnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655722; x=1739260522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZnRpk/p9sKuCOyv2KZjNLOO6T+xrx1m13lZc/9SNpSQ=; b=Yra2ftcXhcWiBp4RF1DavEX1EeNIdhwm3Kc6MADB7Pk7wCYb4W0FQ4lg/+jsJNONiL Qj2OSFIbT3HB9cLta5B77PH7TVZduO566OEvujjTgfwoA1sXWvsAHAjXgf7p/WbNavm+ CRDVQTKn2ZPbC1jskS9Rz4AciFF5F1VeVqb/P/4cHmDHZ0fswKxPsoqe8XsCFVYJrdJb QIzAV0+fR1qisOgmUuzBsFNS29+mAD4BhFOWfG8/PDL86b+smWNYI+Bgqas4UXWzrk/+ bC3YfKyPLeAxj/+BfJ9x9Qm88Lv6L1Lne8vRthKgMM0Kd0SxqWfdppvsajSVB7W51XL3 ESuQ== X-Forwarded-Encrypted: i=1; AJvYcCUAeaGGjgUw5IXUJkNaoBxO8qsKTl+D1fIZNOTgz8AcWG3XDY256H7loN/OnOoR4stdaQO7xBFrcRJDqi4=@vger.kernel.org X-Gm-Message-State: AOJu0YyoHWx7lb55l0gI5n2/S2ZHGlF+jhp6+uibruc3Hw+kI0Oui+yU JnjDk1P0zVIKy3Nvr0ZR6goeFT4Lc3rOzvNu1S2bcL3nkZTHyNgj4r/Kr8lF4cI= X-Gm-Gg: ASbGncszLIDL5fcQcCbGlVt952+vKdYBSP88W2pwAw2zqFai0uw+dFRGLSiN0VW+IPS GN0xdFUC20pYtoyvEpTwYDfUpF1Gz5dW4RxEfKNSIs8KMIiNCHJQ0M6WS1jVcz56w6uYKABsjZi vAaoR4trYYHSmXONyqdSHjB5QsGDcU5uWftVxFQO9T6kZAVuGZWKKFIi95i44GUdtmmH1xruPen WRC8M2WzhX06pty+8XoJNV8eoq1zetJXcAVRejW4SJBKUoQmOvSmJ05FgROZSJAWyS4+dG/jMcQ b+Tcr22bazAjXq5C4sP7nKxKar0pexjByXzBXpymIlo2Zj4lE4J5NN4= X-Google-Smtp-Source: AGHT+IHxtxKg5RW+0tra7ErqT2l5lv/l4qXvXUJ8U9uiGwIl5QtJCesqdAm7TRDDQSFPGUYW4TnQ4g== X-Received: by 2002:a05:620a:1993:b0:7b6:d710:22ad with SMTP id af79cd13be357-7c02eca3a0amr362876885a.27.1738655721837; Mon, 03 Feb 2025 23:55:21 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:20 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 06/10] RISC-V: Enable GENERIC_PENDING_IRQ and GENERIC_PENDING_IRQ_CHIPFLAGS Date: Tue, 4 Feb 2025 13:24:01 +0530 Message-ID: <20250204075405.824721-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 7612c52e9b1e..3c19e6ca832d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -111,6 +111,8 @@ config RISCV select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_LIB_DEVMEM_IS_ALLOWED + select GENERIC_PENDING_IRQ if SMP + select GENERIC_PENDING_IRQ_CHIPFLAGS if SMP select GENERIC_PCI_IOMAP select GENERIC_PTDUMP if MMU select GENERIC_SCHED_CLOCK --=20 2.43.0 From nobody Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.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 5117B205E3B for ; Tue, 4 Feb 2025 07:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655735; cv=none; b=d747+ztQ8CHEafXe6b7rffvRM48X9LVhzO4aGhFIjOFFFpnaLlBQHWXMZhAF5MBS8d46WysWk5Kz49j3h93CAAtLd1FszSgaDPw2lfiaaN33zve5ddHkDe+P7XtWoXYoAWLhFwTFVnOmsLI0X5eCOXVuSlEIevh8RiwHB2hweo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655735; c=relaxed/simple; bh=uNWzr1J0Ha05ieHOgplN4kk9HTW+DP3E7gk28HLXYhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UxcgS+ealh9dYhK3rQpwvtH5EN097E3U+fiUn8jULyTHIGQ+m9getpP6ScZjqMbz0Bb3GNxh37VBGNyDVh00KNfE9Op6RiR7tD/xqhQ15mRiH/9qXk3O7IHg7u0iFmEhzTVUZtdF+l04ZBkjiyaKtCLsNwXmPcGC2fdYcAdi88M= 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=Y14srWgw; arc=none smtp.client-ip=209.85.222.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="Y14srWgw" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7be8efa231aso533861785a.2 for ; Mon, 03 Feb 2025 23:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655732; x=1739260532; darn=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=X8Q8DUzarAwU1aGXfCPKakOOrYWe0j2UtGXEc/s+csU=; b=Y14srWgwp0kjOpA+iSzNH+AIVT0MgZAzrmskWR3AahZ1KpGVSWTSrVz//mvwLux8UM /Sdbhgtuk9qvDfpbRx+foroxX/exXMamxJdBJAcj/LLZxSAaNDc3+/V+sFBxyGobex9U NU0SiGOxZV9txZ3B1IVRBjhbWm7mfFqFBn4j9CyMVOl4uAXtQsyvdhZ2/0boLIvB1tox x9qiD8VWielk61ZUy3CAX5IZiwLHTb0OjtrBWA/PSlo60AzCWxnMQRGimDy3PTsXIYt/ JdrK6VqGGIGljMnDuUdW+XoLp5ww7zA8toFTJNGd3A6GwySbtJfRYEGebpeZ6QrE3MsQ UQ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655732; x=1739260532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X8Q8DUzarAwU1aGXfCPKakOOrYWe0j2UtGXEc/s+csU=; b=A5h8TFZE1PyMaPuDftwWcRDW/7zIfTnQ/lpDPTzQEjihewNvvzoQRDL4xAJ1kFQHyn qvo9eLqMl2gMqsoSXjAM3M0z7h4Cf9mXY3tzHqXO63ZEiy13FDj7uIQxVJVli8u0kkQm VQH6HuIZTRuHJ1eB2aX6gl6O5je0cat3TjPn4p9JpSB+iydC6ScFCvFj/06Mihw8lE1Q YfbIJVbODudqRq/0t2YvxiGMo4O7FewT0BcPLa4POZLUhceY2XPJ99WE/FVTepK5Fz8t agesKJZTBXGXRmdc7ARuimnRtaYPPP9HrEHYCDn+KrMHtckfwWAHWoJDhOmAN9fAzYMJ c44Q== X-Forwarded-Encrypted: i=1; AJvYcCU7KZTbqg8vykBHQrXQupw0+zeVx4SYgdxGBPH3JsIlV87yTMhEbwP7emWi78JygoVYi3iGudT579k+/Mw=@vger.kernel.org X-Gm-Message-State: AOJu0YzYlpu2GY6n/UXD/t8IuAdlrj3kuwsblLNL7YPRR21eYRiTuBlD 356ia/3Wgpj5BVePACH7MfJojKbDt//1YYfpucbh8BTsr1N3lVUmJnIGEiPktAs= X-Gm-Gg: ASbGncvaYV4GJI5fwLQmHvRruT8pJisBGmW8psQb06rGomG4VjqDWr9goh/Rm71I9oS tqNkWhi7UtZNo2ksyFr76Nju4qp3ozLP/5w71viSx0/oI5dei+BWHt6Mo55zyIVTsuMo9xsAN4h GLOjDWN2Sv/OkX1WfSZo6oTZLikPU6tuAjCR0WG45OfklIyXK3OSUDLOQ9a4gtKUbkDMJHllGFY nD//llptnCLudnAWrr9x1rgwAirG7hxZwhZ/TYPId/osNGbxH/fRbAHd+hIEVpzE0AMCQ7liCjn /Ls8cePgQGoJSXkR5go9LdQXku2pxS2xe58YCO080TFw4cVK2v4NGlI= X-Google-Smtp-Source: AGHT+IFDcS298QZ7UQVAAQCilUqOgCz6Qta0EEYLJBdOtJFQz2jTcrmA1MOx3CQyyowlvRaOrsJYyg== X-Received: by 2002:a05:620a:471e:b0:7b6:d8aa:7ef8 with SMTP id af79cd13be357-7bffcd8cdd2mr3753349985a.37.1738655732192; Mon, 03 Feb 2025 23:55:32 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:30 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 07/10] irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector Date: Tue, 4 Feb 2025 13:24:02 +0530 Message-ID: <20250204075405.824721-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 | 77 +++++++++++++++++++------ drivers/irqchip/irq-riscv-imsic-state.h | 5 +- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index a8645084bd8f..649012cc47a8 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -124,10 +124,11 @@ void __imsic_eix_update(unsigned long base_id, 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,22 +196,44 @@ 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 +#ifdef CONFIG_SMP +static void __imsic_local_timer_start(struct imsic_local_priv *lpriv) +{ + lockdep_assert_held(&lpriv->lock); + + if (!timer_pending(&lpriv->timer)) { + lpriv->timer.expires =3D jiffies + 1; + add_timer_on(&lpriv->timer, smp_processor_id()); + } +} +#else +static inline void __imsic_local_timer_start(struct imsic_local_priv *lpri= v) +{ +} +#endif + 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); + if (force_all) bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); - __imsic_local_sync(lpriv); + if (!__imsic_local_sync(lpriv)) + __imsic_local_timer_start(lpriv); + raw_spin_unlock_irqrestore(&lpriv->lock, flags); } =20 @@ -232,14 +273,11 @@ static void __imsic_remote_sync(struct imsic_local_pr= iv *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)) { - lpriv->timer.expires =3D jiffies + 1; - add_timer_on(&lpriv->timer, cpu); - } + __imsic_local_timer_start(lpriv); } } #else @@ -294,8 +332,9 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =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 +344,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 +380,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 +444,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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 83E102066F5 for ; Tue, 4 Feb 2025 07:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655745; cv=none; b=t9LINi4gh3v0ZmmnlBF+d5IkcvxAANNBYYzIaMBJ4iI+vA2l88IGQV4wviwaUHUsh4WWe563ub1cghonYaxdW1Mroo8JhdAGoNcDfaTqSImxjJgddKSJGvGNPVv+OfFLScHijblQ1yKN7R6lwYb9tPdv3E1o9RfFSjvfoT/jDnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655745; c=relaxed/simple; bh=Ml7O27y247NCehftSqvlxz3dmlGKg5+3Av1RR28gVzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QmA49BIjrJ7yRUirpPh8juesV+GOygXBQdk5n97Vh3fXIeCTdz1Mir3ponNrj7Y3Yq6diUsEBPYmTPOnxynzRDP16UhVhvxKpfIGllgtlnRUo/zimx98voKhxo8dmhSTk323UE8UMyscqAp4g4NxF1oIpL4zMdM8vW9m57gQqEg= 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=Loch76NE; arc=none smtp.client-ip=209.85.222.178 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="Loch76NE" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b6e5ee6ac7so473124985a.0 for ; Mon, 03 Feb 2025 23:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655742; x=1739260542; darn=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=2spJ1HnVniz9PCwrjRYFNbVUb3mNe4Ef/XoJaqLNwpE=; b=Loch76NEYUEltoOitvcFhUlfDSE24H8fL08wG77vlDwD/8LchtbTLgqsaH6iGNtMbB rfFH1glfjP1fXPoHlHuU5U/1KLCDhJvs2bXufGGArh22Tt+J9wiisL/BI2u/POaBGixr VrEf4PRAAI6ijugR2Hx1O6DFwaQB/aycCR63smMhG7k0Big/3tn4hU68dk7HaN3rbXIa 9g1vDlhid8oY4AfvBWgG8Fi0fvNqXRJokgvLK6+uuzl2rerq/Zk7rOkhnVA2kbdPsWjU fJ8IXbdGyWxx5yKZVF2uhez3E5PcFd/QxSDXKVlabnEN9x5fo/JswehB6SH3WUCh6xdX sqbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655742; x=1739260542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2spJ1HnVniz9PCwrjRYFNbVUb3mNe4Ef/XoJaqLNwpE=; b=QhYS4wdlje6rsX96jqki72XK/4ddWcPWKlE7dMjdz9aWFxQj4R+uEr3+BCzk/Knd3V wRjXIU9H6VhIB/mrAGssPBv4rVrfVgsiL2CFov8StFfO5rcZrZuelmB8LQs+aR1b201C BYIDy5a1fgP5RxQRS1Gn7V/ZKf7RRhShyl5x/3PNvfchG8JuAqcHwMrMVTXfckodQzqM 0OoPdaO41xqFK6QhcTagGkVJdcOjR/IDPUEWMRa4W29emBeEHVR6gLARPGpqoJpdoARN EE+nzvjxKDFg6iET55OiMzC9YXAAlkK5LGz4qgDjTqNySSqKnTLxPa1J8CMsjNBLjtWH gN4g== X-Forwarded-Encrypted: i=1; AJvYcCXhu1HPfPKzXSTSOq9RLvqFMB9XsTMT2mIl1yWUQIrtbeh6W+aX/PEQS6fFioYs6iHcddjHb+Yb5UDI6xo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0li4wFsw2FTRwpG/y4cHYnygocosVytzymUPcVceqDvZJrJPb hUXimGxHPdZB5bL+1Ag+oGTJjTjY2682khLbatLVKlxevG/A6Sstjjzc3gxYSbU= X-Gm-Gg: ASbGnctbLFMmOtAOoqNfWisa/v/LfoVjQSTd75TjJiPDkRe4iyIRomRCprirVan0DPD IV8cwEpf5VNduauulFsF7ejGgLONZT2RNot7KCxtfdP90iwfSqK8F2LMreiP3dJO/ulRiD3Oh4w ksNI0R95YaJWBgtyer2vdh5Y6dO1Mvl4+vCUjsxX5m4kczl0k6kdamr3qCAejoaawZNIGvrPLQD t6KvrvM6yJLjwL0YJ6NuXwzRz3Vsri36KOpM+HA/GgwQYgIaOEOe3lUNH8A+0FoHi6JJHwXjXKh ryVs7f/R2GUc/dKjOfjKJga48bVx5vBbbAChyqqU1ul7c4D0X9veBOM= X-Google-Smtp-Source: AGHT+IH3PInyMoZqyc0SRTAjhuFIMbhus6lgn+l4uL8MxLHlStsGNic2bJF7E2l/TEt5N03Sy8JF7A== X-Received: by 2002:a05:620a:4382:b0:7b1:56f0:e09f with SMTP id af79cd13be357-7bffcda14b6mr4536316585a.54.1738655742363; Mon, 03 Feb 2025 23:55:42 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:41 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 08/10] irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC Date: Tue, 4 Feb 2025 13:24:03 +0530 Message-ID: <20250204075405.824721-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 649012cc47a8..54773c27c411 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -332,6 +332,23 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 04FFF2063D8 for ; Tue, 4 Feb 2025 07:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655754; cv=none; b=VE97j7uUiXrmPlv82Q+bafqsB0CNo0H3IC/vI8M4Kb8PLRoaGq/ccT7X69EEUZ09pgs2fUeuIeaFvmSbGJRgMeBRKZ7sobHvrnVffzyU2wacud2dtBaKj1FpvJnw/GC4DmJ4BbyZ/jJo5rzGeMada8KBCtOSNHjEvWl7L6Qoxqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655754; c=relaxed/simple; bh=moLyNyX8E1Yk5kbVo+RP2IIS9y4p4D50KKC39sIwWNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQsvDgY1uK4K7YvQ6VwTqRXHuDtvAzUISKm0IjeELrw/2oaDwDUwsBKB8VI1q1LlrM4sRQzwb+EAp/C/PToe4qlwfXUdpwwI5KJpQKLkUwrxPpUav/U1U4t/wojHsmznYrn4i/QISsMy9xFdIO4tvTayjZgMq8ASCW9tzcbuu64= 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=SidjJ22+; arc=none smtp.client-ip=209.85.222.178 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="SidjJ22+" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7bcf32a6582so466921085a.1 for ; Mon, 03 Feb 2025 23:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655752; x=1739260552; darn=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=3gEwcaDf3FiyZX0vTyT/9XCNNLKunHvBb/ApGbPO13I=; b=SidjJ22+Gpag0g6GXhC/w4vC6XHvw2LHXbX4ZF7eossvh/NnPkG8yAOvRvpAfVS/0g ccq84iwM2T+LOi+9MKdqR7p5Scmz5m/EqiWaSPCg4ZQFKCmiiylGaAkx7+lYBG4Yy/xv U2uzu7FnP8ALyIhP4+VSSFJaWtR/+U68C2x0IUylF4UMkuATx1g9uF5FD+YC+UCpXoQU bk2eBEs9iNybiLIwOWraj8ytU3UMxzZW/6skQMeAOoHvLTrzmXWU41wxojxQHbUtTnJ2 DSAjsfhSRSqacPavK6sVvGJUdXSUDQ/c41O7TcNKZeD1UuCgOVt7KUAePd04c+yx1kat kkjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655752; x=1739260552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3gEwcaDf3FiyZX0vTyT/9XCNNLKunHvBb/ApGbPO13I=; b=v6x2GAw9/ZrmpK3lwYWrrU4xiKXr1OiOEsRvg9Z9ttJMtJFexJNimGtS7be1+i7PEG nl9zIruQ04T+Tzwz6TG17LojMaZnJLcjMlQbU29NNU2ChdmcHgYg+RtN19DD86S3yBKu 7JQrsviHIeatMDMQZjKgZhCmfJ26moTYNSbmjWjdxltt0s9NgJaGp1swDcQ0/9QgniYC WG+qBoPFYMzGWYTgMc1q0qID+GLV16HTt2HeMM/sVtpjiVn4YqI0tbKb+4G7x0kG8apn FBNuOOKlFcdHa8tcQXAumm0BzwQ/+7JSK4mzFTXV5pskMERv9B0l+DgT8cG3/s4yvyok +kbA== X-Forwarded-Encrypted: i=1; AJvYcCUYmPYbDy934egZluXGNsxEvRC+WwwBmR8wsHnwW6UqxwD41bXnYca0P9xHKR6k/pep6mKtrVMpXrKp1sk=@vger.kernel.org X-Gm-Message-State: AOJu0YyjdhRP04jV5lbOqGkYluz988bYlsFIvMHB1GEH05tgD7Sljnwx /8yAcsdwCOdGO/oflAO8PnlTGFCelh1B/pLaJmap6oDqr/zrKYVZu5N/qK2gFHggBCunmYwstYk a7GQ= X-Gm-Gg: ASbGncvoWqAZ2xgt52XmGrkKWSAwcP33Ss9FUqZ3DTfqYaajcLIROU6nmX/nJtbv4N2 bWWsB9l3Q+wkLHG79PiFOQbt69PsI3voojv/XJSQRk1gwfVMRiQ0cUyErjVyKEG2oXfV7+HeXj6 JlyvwNz8lW+uToLwRUhjo8YHGJJFpZlFyUub8EtTUd8yiy0P/1/M0/XxLf+7Mcxkng0wrW4plVK YwUdty4V2jXNLWllbftBnJL2O40B595ytcz4yU0JrSwj6QSLNcoEcQu2rHxFA4I2aPOIXeU6g2g Vm8LdxkRYM93VQfZF14Z7BT/SDRUSUGXjpXjmFFEh5KlTo0R949TGnw= X-Google-Smtp-Source: AGHT+IE1kqeyReImTVJHGW5IDLgtzpBSrI2/ZE4aOj+o6f7vrc3hrNQAxAn/RUr7v38bA4d+4LAZBQ== X-Received: by 2002:a05:620a:2992:b0:7b9:a387:3cd8 with SMTP id af79cd13be357-7bffcd956e1mr2941465585a.42.1738655751905; Mon, 03 Feb 2025 23:55:51 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:55:51 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 09/10] irqchip/riscv-imsic: Replace hwirq with irq in the IMSIC vector Date: Tue, 4 Feb 2025 13:24:04 +0530 Message-ID: <20250204075405.824721-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 54773c27c411..e70f497a9326 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -443,7 +443,7 @@ struct imsic_vector *imsic_vector_from_local_id(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; @@ -459,7 +459,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; @@ -472,7 +472,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); } @@ -531,7 +531,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 Sun Dec 14 06:23:25 2025 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 48D422063F0 for ; Tue, 4 Feb 2025 07:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655765; cv=none; b=H0dyuCuJcMHjSXyyKzik/9rUO/yimYS+3Pc8dhI54C2ZMILQJlpb+kMkZ4Qht28H8cc621EnWExifO0KX7GMRVXR6nS1dqFFYqr6yT/zZoXkWa71Si5W/nlwD9Hi2R0YtXipVcsM8WmYSAPM4YxVyD7FpVpzeHveLES693T+h08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738655765; c=relaxed/simple; bh=6xkXk113SKzH+HghpDpklZ4GMsdI6UuIpAuY82dZFHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ttKCIv+IewkyfB7PpcHtRVKnAKfWO3BTUzMTcdASFkWwvr4B9ia8z6BNfGjW1N309tA8Kp5PHyBGnsmGXLapCvN7f7qjpOo5E/MruIDbUwnEWTDLNmKXR68FdaoaJVutNb20lDs/nRqyDBI7gZ2mH6R6BfZbA3Gwe2Z7bAN+hoU= 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=oIYssSo7; arc=none smtp.client-ip=209.85.222.176 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="oIYssSo7" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b9bc648736so514869885a.1 for ; Mon, 03 Feb 2025 23:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1738655761; x=1739260561; 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=6MADFF5SwXkzmIBLKmDVwps1qS+gME3ryVy0pflkh7M=; b=oIYssSo7jzQQyIScTqtyJRxNFg4tCN/VREVYL8+KSuo7gnjWF5kbU/oyjWOyOnrLM/ mux24MkFiP8F8n8TOZ4egU7pOGvcY14bMqIBAZGo0nP84JaZvXj9oMhiNcwpRaeuR6LJ iQcs3869tRGnHtm5h+uiN0CGPeZosaZ5Rtcd+ir3HP4kalU5z2+C7Ym35KQsXMnqVSwh 8ThnEKJliuOjzJzi4B/CXcVYBT5IhfWCCHYOA3sCivBtEbS5zIZz/3aTnKibTazSByJc gaOmVreEpnNtRTEQ1fBv8YdmFOa2qsiNNZeu5KKd2LetJHzMlVmc660p6FDK7lNdYrEU g6Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738655761; x=1739260561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6MADFF5SwXkzmIBLKmDVwps1qS+gME3ryVy0pflkh7M=; b=lhd3bsmXEzZq8Hg+tRoVpT+l1QL1trE7oCFNbRuogvc4zQI09RBpn5xTHpzgMa8+d1 e8AkAV8T8GY/c4mm3otG9ZpIzCmcVPHf5EkTTgmEx4CL2/C0bPWO/YGc3sBXdH1YTcj3 2YyTmXx6c+Tc1G3d1eIeC//CZflk6LI9OxgVhh2HIzQQXTm6e2YJWQfGKU8koyo0B6Ng pVwbXGFZtsMiysc2AGaEoPdmikdcEwsz1iOdyEY3n4WHYYSGM2XQqfraZhcCrJjMc3T7 93DooytpVQe/nu322jYWfnxLIBxgJvVGbMs1MUOEnhQ2ZvYu9E4vyBfJb8je3Iue2iBW YR2Q== X-Forwarded-Encrypted: i=1; AJvYcCXwMeqgzu+jLhKSelxo+LNO1Mtm7Tl4aq4r3zkW5vcXMiGeR3IOgTvP4bpmO1A78TjD9lhevQD+YIlyfRA=@vger.kernel.org X-Gm-Message-State: AOJu0YyU4Ke4X2gVChBpYMj+xa2OTM3+1HRGfa9RfZJwy8RHOGopoJmw 8CiVWnZo9jvrkDdtdFuD8SrzRIldJSjmkPDLtuWVFvxmzAeqJPlLBDS1GXNwFwc= X-Gm-Gg: ASbGnctPCaGoHCBZ9L6ebwvVyfGN+cHeGAltaSqJ1USfxRU/TIGn6LFN72RaThwTKIP uH66LkIxsD5pNcegkA+N7W5Df5FrGB8zD7b7fttW00fEuauF6bg3ElXjAMfruQ3Hh3UqUyWE5yw yqsAZLfbQfz+HO/LxoK67zsqWRK1he0WykXYgRAyyyI5t4Ci9wtzv4Xow8G+4f8AbouoetZxpMG oSxv2pcV8uGr5RKf+9crSdEZ53rfSrWAgqoJFGOcNmagDr1af3sQVzPkY0OZqjAmil3cEQ4oDkg J7ZVz71G5fLom9mqoaou+/jhWqIkyJu06GMBFsSm7IywyCvA9lEAuAc= X-Google-Smtp-Source: AGHT+IF7prdvtKiSyJ0NFqTW4MBl378F96libEZvgvmb2g4BOpM5Yj9BonZGCkzjTLLgOdYhNcWtUA== X-Received: by 2002:a05:620a:8427:b0:7c0:a2:e68a with SMTP id af79cd13be357-7c000a2e980mr2573236785a.30.1738655761078; Mon, 03 Feb 2025 23:56:01 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c00a8d05ddsm613373185a.39.2025.02.03.23.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 23:56:00 -0800 (PST) From: Anup Patel To: Thomas Gleixner Cc: Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v3 10/10] irqchip/riscv-imsic: Use IRQCHIP_MOVE_DEFERRED flag for PCI devices Date: Tue, 4 Feb 2025 13:24:05 +0530 Message-ID: <20250204075405.824721-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204075405.824721-1-apatel@ventanamicro.com> References: <20250204075405.824721-1-apatel@ventanamicro.com> 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 e70f497a9326..f9b2cec72ff2 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -126,8 +126,8 @@ void __imsic_eix_update(unsigned long base_id, unsigned= long num_id, bool pend, =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