Enable MSI affinity support for dwc PCI
Subsystems (6)
v3 cover Enable MSI affinity support for dwc PCI
Various attempts have been made so far to support CPU affinity control for (de)multiplexed interrupts. Some examples are [1] and [2]. That work was centered around the idea to control the parent interrupt's CPU affinity, since the child interrupt handler runs in the context of the parent interrupt handler, on whatever CPU it was triggered.
This is a new attempt based on a different approach. Instead of touching the parent interrupt's CPU affinity, the child interrupt is allowed to freely change its affinity setting, independently of the parent. If the interrupt handler happens to be triggered on an "incompatible" CPU (a CPU that's not part of the child interrupt's affinity mask), the handler is redirected and runs in IRQ work context on a "compatible" CPU. This is a direct follow up to the (unsubmitted) patches that Thomas Gleixner proposed in [3].
The first patch adds support for interrupt redirection to the IRQ core, without making any functional change to irqchip drivers. The other two patches modify the dwc PCI core driver to enable interrupt redirection using the new infrastructure added in the first patch.
Thomas, however, I made a small design change to your original patches. Instead of keeping track of the parent interrupt's affinity setting (or rather the first CPU in its affinity mask) and attempting to pick the same CPU for the child (as the target CPU) if possible, I just check if the child handler fires on a CPU that's part of its affinity mask (which is already stored anyway). As an optimization for the case when the current CPU is *not* part of the mask and the handler needs to be redirected, I pre-calculate and store the first CPU in the mask, at the time when the child affinity is set. In my opinion, this is simpler and cleaner, at the expense of a cpumask_test_cpu() call on the fast path, because:
- It no longer needs to keep track of the parent interrupt's affinity setting.
- If the parent interrupt can run on more than one CPU, the child can also run on any of those CPUs without being redirected (in case the child's affinity mask is the same as the parent's or a superset).
[1] https://lore.kernel.org/all/20220502102137.764606ee@thinkpad/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/linux-pci/878qpg4o4t.ffs@tglx/
---
Changes in v3:
- Use an Originally-by tag (instead of Signed-off-by) to attribute initial authorship to Thomas Gleixner <[email protected]>.
- All changes below are related to patch 1. Patches 2 and 3 are unchanged, since they received no review comments in v2.
- Rename fallback_cpu to target_cpu to make it less confusing.
- Make a stub for demux_redirect_remote() for the !CONFIG_SMP case.
- Move all redirection code from generic_handle_demux_domain_irq() to demux_redirect_remote(), including locking desc->lock.
- Add a short comment to explain cpumask_test_cpu(smp_processor_id(), m).
- Add a comment to explain why calling irq_work_queue_on() inside demux_redirect_remote() is safe w.r.t. CPU unplugging.
- Move the synchronize_irqwork() call from __synchronize_hardirq() to __synchronize_irq(), since it can sleep.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Fix compile errors on configurations where CONFIG_SMP is disabled
- Link to v1: https://lore.kernel.org/all/[email protected]/
---
Radu Rendec (3):
genirq: Add interrupt redirection infrastructure
PCI: dwc: Code cleanup
PCI: dwc: Enable MSI affinity support
.../pci/controller/dwc/pcie-designware-host.c | 127 ++++++++---------- drivers/pci/controller/dwc/pcie-designware.h | 7 +- include/linux/irq.h | 10 ++ include/linux/irqdesc.h | 17 ++- kernel/irq/chip.c | 22 ++- kernel/irq/irqdesc.c | 86 +++++++++++- kernel/irq/manage.c | 15 ++- 7 files changed, 204 insertions(+), 80 deletions(-)
Signature · 1 line
2.51.1
PATCH v3 1/3 genirq: Add interrupt redirection infrastructure
Add infrastructure to redirect interrupt handler execution to a different CPU when the current CPU is not part of the interrupt's CPU affinity mask.
This is primarily aimed at (de)multiplexed interrupts, where the child interrupt handler runs in the context of the parent interrupt handler, and therefore CPU affinity control for the child interrupt is typically not available.
With the new infrastructure, the child interrupt is allowed to freely change its affinity setting, independently of the parent. If the interrupt handler happens to be triggered on an "incompatible" CPU (a CPU that's not part of the child interrupt's affinity mask), the handler is redirected and runs in IRQ work context on a "compatible" CPU.
No functional change is being made to any existing irqchip driver, and irqchip drivers must be explicitly modified to use the newly added infrastructure to support interrupt redirection.
--- include/linux/irq.h | 10 +++++ include/linux/irqdesc.h | 17 +++++++- kernel/irq/chip.c | 22 ++++++++++- kernel/irq/irqdesc.c | 86 ++++++++++++++++++++++++++++++++++++++++- kernel/irq/manage.c | 15 ++++++- 5 files changed, 144 insertions(+), 6 deletions(-)
include/linux/irq.h +10 -0
@@ -459,6 +459,8 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)* checks against the supplied affinity mask are not * required. This is used for CPU hotplug where the * target CPU is not yet set in the cpu_online_mask. +* @irq_pre_redirect: Optional function to be invoked before redirecting +* an interrupt via irq_work. Called only on CONFIG_SMP. * @irq_retrigger: resend an IRQ to the CPU * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ * @irq_set_wake: enable/disable power-management wake-on of an IRQ
@@ -503,6 +505,7 @@ struct irq_chip {void (*irq_eoi)(struct irq_data *data);int (*irq_set_affinity)(struct irq_data *data,const struct cpumask *dest,bool force); +void (*irq_pre_redirect)(struct irq_data *data);int (*irq_retrigger)(struct irq_data *data);int (*irq_set_type)(struct irq_data *data,unsigned int flow_type);int (*irq_set_wake)(struct irq_data *data,unsigned int on);
@@ -688,6 +691,13 @@ extern int irq_chip_set_vcpu_affinity_parent(struct irq_data *data,extern int irq_chip_set_type_parent (struct irq_data *data,unsigned int type);extern int irq_chip_request_resources_parent (struct irq_data *data);extern void irq_chip_release_resources_parent (struct irq_data *data); +#ifdef CONFIG_SMP +void irq_chip_pre_redirect_parent (struct irq_data *data); +#endif +#endif + +#ifdef CONFIG_SMP +int irq_chip_redirect_set_affinity (struct irq_data *data,const struct cpumask *dest,bool force);#endif /* Disable or mask interrupts during a kernel kexec */
include/linux/irqdesc.h +16 -1
@@ -2,9 +2,10 @@#ifndef _LINUX_IRQDESC_H#define _LINUX_IRQDESC_H -#include <linux/rcupdate.h> +#include <linux/irq_work.h> #include <linux/kobject.h> #include <linux/mutex.h> +#include <linux/rcupdate.h> /* * Core internal functions to deal with irq descriptors
@@ -29,6 +30,17 @@ struct irqstat {#endif }; +/** +* struct irq_redirect - interrupt redirection metadata +* @work: HARD work item for handler execution on a different cpu +* @target_cpu: cpu to run irq handler on in case the current cpu is not part +* of the irq affinity mask +*/ +struct irq_redirect { +struct irq_work work; +unsigned int target_cpu; +}; +/** * struct irq_desc - interrupt descriptor * @irq_common_data: per irq and chip data passed down to chip functions
@@ -46,6 +58,7 @@ struct irqstat {* @threads_handled: stats field for deferred spurious detection of threaded handlers * @threads_handled_last: comparator field for deferred spurious detection of threaded handlers * @lock: locking for SMP +* @redirect: Facility for redirecting interrupts via irq_work * @affinity_hint: hint to user space for preferred irq affinity * @affinity_notify: context for notification of affinity changes * @pending_mask: pending rebalanced interrupts
@@ -84,6 +97,7 @@ struct irq_desc {struct cpumask *percpu_enabled;const struct cpumask *percpu_affinity;#ifdef CONFIG_SMP +struct irq_redirect redirect;const struct cpumask *affinity_hint;struct irq_affinity_notify *affinity_notify;#ifdef CONFIG_GENERIC_PENDING_IRQ
@@ -186,6 +200,7 @@ int generic_handle_irq_safe(unsigned int irq);int generic_handle_domain_irq (struct irq_domain *domain,unsigned int hwirq);int generic_handle_domain_irq_safe (struct irq_domain *domain,unsigned int hwirq);int generic_handle_domain_nmi (struct irq_domain *domain,unsigned int hwirq); +bool generic_handle_demux_domain_irq (struct irq_domain *domain,unsigned int hwirq);#endif /* Test to see if a driver has successfully requested an irq */
kernel/irq/chip.c +21 -1
@@ -1143,7 +1143,7 @@ void irq_cpu_offline(void) }#endif -#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY +#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY #ifdef CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS /**
@@ -1215,6 +1215,15 @@ EXPORT_SYMBOL_GPL(handle_fasteoi_mask_irq);#endif /* CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS */ +#ifdef CONFIG_SMP +void irq_chip_pre_redirect_parent (struct irq_data *data) +{ + data = data->parent_data; + data->chip->irq_pre_redirect (data); +} +EXPORT_SYMBOL_GPL (irq_chip_pre_redirect_parent); +#endif +/** * irq_chip_set_parent_state - set the state of a parent interrupt. *
@@ -1497,6 +1506,17 @@ void irq_chip_release_resources_parent(struct irq_data *data) data->chip->irq_release_resources(data); }EXPORT_SYMBOL_GPL (irq_chip_release_resources_parent); +#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ + +#ifdef CONFIG_SMP +int irq_chip_redirect_set_affinity (struct irq_data *data,const struct cpumask *dest,bool force) +{ +struct irq_redirect *redir = &irq_data_to_desc (data)->redirect; + +WRITE_ONCE (redir->target_cpu,cpumask_first (dest)); +return IRQ_SET_MASK_OK ; +} +EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif /**
kernel/irq/irqdesc.c +84 -2
104 lines not on this page · raw message
kernel/irq/manage.c +13 -2
@@ -35,6 +35,16 @@ static int __init setup_forced_irqthreads(char *arg)early_param ("threadirqs" , setup_forced_irqthreads);#endif +#ifdef CONFIG_SMP +static inline void synchronize_irqwork (struct irq_desc *desc) +{ +/* Synchronize pending or on the fly redirect work */ +irq_work_sync (&desc->redirect.work); +} +#else +static inline void synchronize_irqwork (struct irq_desc *desc) { } +#endif +static int __irq_get_irqchip_state (struct irq_data *d,enum irqchip_irq_state which,bool *state);static void __synchronize_hardirq (struct irq_desc *desc,bool sync_chip)
@@ -107,7 +117,9 @@ EXPORT_SYMBOL(synchronize_hardirq);static void __synchronize_irq (struct irq_desc *desc) { +synchronize_irqwork (desc);__synchronize_hardirq (desc, true); +/* * We made sure that no hardirq handler is running. Now verify that no * threaded handlers are active.
@@ -217,8 +229,7 @@ static inline void irq_validate_effective_affinity(struct irq_data *data) { } static DEFINE_PER_CPU(struct cpumask, __tmp_mask); -int irq_do_set_affinity (struct irq_data *data,const struct cpumask *mask, -bool force) +int irq_do_set_affinity (struct irq_data *data,const struct cpumask *mask,bool force) {struct cpumask *tmp_mask =this_cpu_ptr (&__tmp_mask);struct irq_desc *desc =irq_data_to_desc (data);
Signature · 1 line
2.51.1
[tip: irq/msi] genirq: Add interrupt redirection infrastructure
The following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: fcc1d0dabdb65ca069f77e5b76d3b20277be4a15 Gitweb: https://git.kernel.org/tip/fcc1d0dabdb65ca069f77e5b76d3b20277be4a15 Author: Radu Rendec <[email protected]> AuthorDate: Fri, 28 Nov 2025 16:20:53 -05:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00
genirq: Add interrupt redirection infrastructure
Add infrastructure to redirect interrupt handler execution to a different CPU when the current CPU is not part of the interrupt's CPU affinity mask.
This is primarily aimed at (de)multiplexed interrupts, where the child interrupt handler runs in the context of the parent interrupt handler, and therefore CPU affinity control for the child interrupt is typically not available.
With the new infrastructure, the child interrupt is allowed to freely change its affinity setting, independently of the parent. If the interrupt handler happens to be triggered on an "incompatible" CPU (a CPU that's not part of the child interrupt's affinity mask), the handler is redirected and runs in IRQ work context on a "compatible" CPU.
No functional change is being made to any existing irqchip driver, and irqchip drivers must be explicitly modified to use the newly added infrastructure to support interrupt redirection.
--- include/linux/irq.h | 10 +++++- include/linux/irqdesc.h | 17 +++++++- kernel/irq/chip.c | 22 +++++++++- kernel/irq/irqdesc.c | 86 +++++++++++++++++++++++++++++++++++++++- kernel/irq/manage.c | 15 ++++++- 5 files changed, 144 insertions(+), 6 deletions(-)
include/linux/irq.h +10 -0
@@ -459,6 +459,8 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)* checks against the supplied affinity mask are not * required. This is used for CPU hotplug where the * target CPU is not yet set in the cpu_online_mask. +* @irq_pre_redirect: Optional function to be invoked before redirecting +* an interrupt via irq_work. Called only on CONFIG_SMP. * @irq_retrigger: resend an IRQ to the CPU * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ * @irq_set_wake: enable/disable power-management wake-on of an IRQ
@@ -503,6 +505,7 @@ struct irq_chip {void (*irq_eoi)(struct irq_data *data);int (*irq_set_affinity)(struct irq_data *data,const struct cpumask *dest,bool force); +void (*irq_pre_redirect)(struct irq_data *data);int (*irq_retrigger)(struct irq_data *data);int (*irq_set_type)(struct irq_data *data,unsigned int flow_type);int (*irq_set_wake)(struct irq_data *data,unsigned int on);
@@ -687,6 +690,13 @@ extern int irq_chip_set_vcpu_affinity_parent(struct irq_data *data,extern int irq_chip_set_type_parent (struct irq_data *data,unsigned int type);extern int irq_chip_request_resources_parent (struct irq_data *data);extern void irq_chip_release_resources_parent (struct irq_data *data); +#ifdef CONFIG_SMP +void irq_chip_pre_redirect_parent (struct irq_data *data); +#endif +#endif + +#ifdef CONFIG_SMP +int irq_chip_redirect_set_affinity (struct irq_data *data,const struct cpumask *dest,bool force);#endif /* Disable or mask interrupts during a kernel kexec */
include/linux/irqdesc.h +16 -1
@@ -2,9 +2,10 @@#ifndef _LINUX_IRQDESC_H#define _LINUX_IRQDESC_H -#include <linux/rcupdate.h> +#include <linux/irq_work.h> #include <linux/kobject.h> #include <linux/mutex.h> +#include <linux/rcupdate.h> /* * Core internal functions to deal with irq descriptors
@@ -30,6 +31,17 @@ struct irqstat { };/** +* struct irq_redirect - interrupt redirection metadata +* @work: Harg irq_work item for handler execution on a different CPU +* @target_cpu: CPU to run irq handler on in case the current CPU is not part +* of the irq affinity mask +*/ +struct irq_redirect { +struct irq_work work; +unsigned int target_cpu; +}; + +/** * struct irq_desc - interrupt descriptor * @irq_common_data: per irq and chip data passed down to chip functions * @kstat_irqs: irq stats per cpu
@@ -46,6 +58,7 @@ struct irqstat {* @threads_handled: stats field for deferred spurious detection of threaded handlers * @threads_handled_last: comparator field for deferred spurious detection of threaded handlers * @lock: locking for SMP +* @redirect: Facility for redirecting interrupts via irq_work * @affinity_hint: hint to user space for preferred irq affinity * @affinity_notify: context for notification of affinity changes * @pending_mask: pending rebalanced interrupts
@@ -83,6 +96,7 @@ struct irq_desc {raw_spinlock_t lock;struct cpumask *percpu_enabled;#ifdef CONFIG_SMP +struct irq_redirect redirect;const struct cpumask *affinity_hint;struct irq_affinity_notify *affinity_notify;#ifdef CONFIG_GENERIC_PENDING_IRQ
@@ -185,6 +199,7 @@ int generic_handle_irq_safe(unsigned int irq);int generic_handle_domain_irq (struct irq_domain *domain,irq_hw_number_t hwirq);int generic_handle_domain_irq_safe (struct irq_domain *domain,irq_hw_number_t hwirq);int generic_handle_domain_nmi (struct irq_domain *domain,irq_hw_number_t hwirq); +bool generic_handle_demux_domain_irq (struct irq_domain *domain,irq_hw_number_t hwirq);#endif /* Test to see if a driver has successfully requested an irq */
kernel/irq/chip.c +21 -1
@@ -1122,7 +1122,7 @@ void irq_cpu_offline(void) }#endif -#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY +#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY #ifdef CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS /**
@@ -1194,6 +1194,15 @@ EXPORT_SYMBOL_GPL(handle_fasteoi_mask_irq);#endif /* CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS */ +#ifdef CONFIG_SMP +void irq_chip_pre_redirect_parent (struct irq_data *data) +{ + data = data->parent_data; + data->chip->irq_pre_redirect (data); +} +EXPORT_SYMBOL_GPL (irq_chip_pre_redirect_parent); +#endif +/** * irq_chip_set_parent_state - set the state of a parent interrupt. *
@@ -1476,6 +1485,17 @@ void irq_chip_release_resources_parent(struct irq_data *data) data->chip->irq_release_resources(data); }EXPORT_SYMBOL_GPL (irq_chip_release_resources_parent); +#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ + +#ifdef CONFIG_SMP +int irq_chip_redirect_set_affinity (struct irq_data *data,const struct cpumask *dest,bool force) +{ +struct irq_redirect *redir = &irq_data_to_desc (data)->redirect; + +WRITE_ONCE (redir->target_cpu,cpumask_first (dest)); +return IRQ_SET_MASK_OK ; +} +EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif /**
kernel/irq/irqdesc.c +84 -2
104 lines not on this page · raw message
kernel/irq/manage.c +13 -2
@@ -35,6 +35,16 @@ static int __init setup_forced_irqthreads(char *arg)early_param ("threadirqs" , setup_forced_irqthreads);#endif +#ifdef CONFIG_SMP +static inline void synchronize_irqwork (struct irq_desc *desc) +{ +/* Synchronize pending or on the fly redirect work */ +irq_work_sync (&desc->redirect.work); +} +#else +static inline void synchronize_irqwork (struct irq_desc *desc) { } +#endif +static int __irq_get_irqchip_state (struct irq_data *d,enum irqchip_irq_state which,bool *state);static void __synchronize_hardirq (struct irq_desc *desc,bool sync_chip)
@@ -107,7 +117,9 @@ EXPORT_SYMBOL(synchronize_hardirq);static void __synchronize_irq (struct irq_desc *desc) { +synchronize_irqwork (desc);__synchronize_hardirq (desc, true); +/* * We made sure that no hardirq handler is running. Now verify that no * threaded handlers are active.
@@ -217,8 +229,7 @@ static inline void irq_validate_effective_affinity(struct irq_data *data) { } static DEFINE_PER_CPU(struct cpumask, __tmp_mask); -int irq_do_set_affinity (struct irq_data *data,const struct cpumask *mask, -bool force) +int irq_do_set_affinity (struct irq_data *data,const struct cpumask *mask,bool force) {struct cpumask *tmp_mask =this_cpu_ptr (&__tmp_mask);struct irq_desc *desc =irq_data_to_desc (data);
PATCH v3 2/3 PCI: dwc: Code cleanup
In reply to Radu RendecCode cleanup with no functional changes. These changes were originally made by Thomas Gleixner (see Link tag below) in a patch that was never submitted as is. Other parts of that patch were eventually submitted as commit 8e717112caf3 ("PCI: dwc: Switch to msi_create_parent_irq_domain()") and the remaining parts are the code cleanup changes in this patch.
Summary of changes:
- Use guard()/scoped_guard() instead of open-coded lock/unlock.
- Return void in a few functions whose return value is never used.
- Simplify dw_handle_msi_irq() by using for_each_set_bit().
One notable deviation from the original patch is that I reverted back to a simple 1 by 1 iteration over the controllers inside dw_handle_msi_irq. The reason is that with the original changes, the IRQ offset was calculated incorrectly.
This patch also prepares the ground for the next patch in the series, which enables MSI affinity support, and was originally part of that same series that Thomas Gleixner prepared.
--- .../pci/controller/dwc/pcie-designware-host.c | 98 ++++++------------- drivers/pci/controller/dwc/pcie-designware.h | 7 +- 2 files changed, 34 insertions(+), 71 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +32 -66
@@ -46,35 +46,25 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { };/* MSI int handler */ -irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp) +void dw_handle_msi_irq (struct dw_pcie_rp *pp) { -int i, pos; -unsigned long val; -u32 status, num_ctrls; -irqreturn_t ret =IRQ_NONE ;struct dw_pcie *pci =to_dw_pcie_from_pp (pp); +unsigned int i, num_ctrls; num_ctrls = pp->num_vectors /MAX_MSI_IRQS_PER_CTRL ;for (i =0 ; i < num_ctrls; i++) { - status =dw_pcie_readl_dbi (pci,PCIE_MSI_INTR0_STATUS + - (i *MSI_REG_CTRL_BLOCK_SIZE )); +unsigned int reg_off = i *MSI_REG_CTRL_BLOCK_SIZE ; +unsigned int irq_off = i *MAX_MSI_IRQS_PER_CTRL ; +unsigned long status, pos; + + status =dw_pcie_readl_dbi (pci,PCIE_MSI_INTR0_STATUS + reg_off);if (!status)continue ; - ret =IRQ_HANDLED ; - val = status; - pos =0 ; -while ((pos =find_next_bit (&val,MAX_MSI_IRQS_PER_CTRL , - pos)) !=MAX_MSI_IRQS_PER_CTRL ) { -generic_handle_domain_irq (pp->irq_domain, - (i *MAX_MSI_IRQS_PER_CTRL ) + - pos); - pos++; - } +for_each_set_bit (pos, &status,MAX_MSI_IRQS_PER_CTRL ) +generic_handle_domain_irq (pp->irq_domain, irq_off + pos); } - -return ret; }/* Chained MSI interrupt service routine */
@@ -95,13 +85,10 @@ static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg) {struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp); -u64 msi_target; - - msi_target = (u64 )pp->msi_data; +u64 msi_target = (u64 )pp->msi_data; msg->address_lo =lower_32_bits (msi_target); msg->address_hi =upper_32_bits (msi_target); - msg->data = d->hwirq; dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n",
@@ -113,18 +100,14 @@ static void dw_pci_bottom_mask(struct irq_data *d)struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp);unsigned int res, bit, ctrl; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); +guard (raw_spinlock)(&pp->lock); ctrl = d->hwirq /MAX_MSI_IRQS_PER_CTRL ; res = ctrl *MSI_REG_CTRL_BLOCK_SIZE ; bit = d->hwirq %MAX_MSI_IRQS_PER_CTRL ; pp->irq_mask[ctrl] |=BIT (bit);dw_pcie_writel_dbi (pci,PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); - -raw_spin_unlock_irqrestore (&pp->lock, flags); }static void dw_pci_bottom_unmask (struct irq_data *d)
@@ -132,18 +115,14 @@ static void dw_pci_bottom_unmask(struct irq_data *d)struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp);unsigned int res, bit, ctrl; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); +guard (raw_spinlock)(&pp->lock); ctrl = d->hwirq /MAX_MSI_IRQS_PER_CTRL ; res = ctrl *MSI_REG_CTRL_BLOCK_SIZE ; bit = d->hwirq %MAX_MSI_IRQS_PER_CTRL ; pp->irq_mask[ctrl] &= ~BIT (bit);dw_pcie_writel_dbi (pci,PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); - -raw_spin_unlock_irqrestore (&pp->lock, flags); }static void dw_pci_bottom_ack (struct irq_data *d)
@@ -160,54 +139,42 @@ static void dw_pci_bottom_ack(struct irq_data *d) }static struct irq_chip dw_pci_msi_bottom_irq_chip = { - .name ="DWPCI-MSI" , - .irq_ack = dw_pci_bottom_ack, - .irq_compose_msi_msg = dw_pci_setup_msi_msg, - .irq_mask = dw_pci_bottom_mask, - .irq_unmask = dw_pci_bottom_unmask, + .name ="DWPCI-MSI" , + .irq_ack = dw_pci_bottom_ack, + .irq_compose_msi_msg = dw_pci_setup_msi_msg, + .irq_mask = dw_pci_bottom_mask, + .irq_unmask = dw_pci_bottom_unmask, }; -static int dw_pcie_irq_domain_alloc (struct irq_domain *domain, -unsigned int virq,unsigned int nr_irqs, -void *args) +static int dw_pcie_irq_domain_alloc (struct irq_domain *domain,unsigned int virq, +unsigned int nr_irqs,void *args) {struct dw_pcie_rp *pp = domain->host_data; -unsigned long flags; -u32 i;int bit; -raw_spin_lock_irqsave (&pp->lock, flags); - - bit =bitmap_find_free_region (pp->msi_irq_in_use, pp->num_vectors, -order_base_2 (nr_irqs)); - -raw_spin_unlock_irqrestore (&pp->lock, flags); + scoped_guard (raw_spinlock_irq, &pp->lock) { + bit =bitmap_find_free_region (pp->msi_irq_in_use, pp->num_vectors, +order_base_2 (nr_irqs)); + }if (bit <0 )return -ENOSPC ; -for (i =0 ; i < nr_irqs; i++) -irq_domain_set_info (domain, virq + i, bit + i, - pp->msi_irq_chip, - pp, handle_edge_irq, -NULL ,NULL ); - +for (unsigned int i =0 ; i < nr_irqs; i++) { +irq_domain_set_info (domain, virq + i, bit + i, pp->msi_irq_chip, + pp, handle_edge_irq,NULL ,NULL ); + }return 0 ; } -static void dw_pcie_irq_domain_free (struct irq_domain *domain, -unsigned int virq,unsigned int nr_irqs) +static void dw_pcie_irq_domain_free (struct irq_domain *domain,unsigned int virq, +unsigned int nr_irqs) {struct irq_data *d =irq_domain_get_irq_data (domain, virq);struct dw_pcie_rp *pp = domain->host_data; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); -bitmap_release_region (pp->msi_irq_in_use, d->hwirq, -order_base_2 (nr_irqs)); - -raw_spin_unlock_irqrestore (&pp->lock, flags); +guard (raw_spinlock_irq)(&pp->lock); +bitmap_release_region (pp->msi_irq_in_use, d->hwirq,order_base_2 (nr_irqs)); }static const struct irq_domain_ops dw_pcie_msi_domain_ops = {
@@ -240,8 +207,7 @@ void dw_pcie_free_msi(struct dw_pcie_rp *pp)for (ctrl =0 ; ctrl <MAX_MSI_CTRLS ; ctrl++) {if (pp->msi_irq[ctrl] >0 ) -irq_set_chained_handler_and_data (pp->msi_irq[ctrl], -NULL ,NULL ); +irq_set_chained_handler_and_data (pp->msi_irq[ctrl],NULL ,NULL ); }irq_domain_remove (pp->irq_domain);
drivers/pci/controller/dwc/pcie-designware.h +2 -5
@@ -802,7 +802,7 @@ static inline enum dw_pcie_ltssm dw_pcie_get_ltssm(struct dw_pcie *pci)#ifdef CONFIG_PCIE_DW_HOST int dw_pcie_suspend_noirq (struct dw_pcie *pci);int dw_pcie_resume_noirq (struct dw_pcie *pci); -irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp); +void dw_handle_msi_irq (struct dw_pcie_rp *pp);void dw_pcie_msi_init (struct dw_pcie_rp *pp);int dw_pcie_msi_host_init (struct dw_pcie_rp *pp);void dw_pcie_free_msi (struct dw_pcie_rp *pp);
@@ -823,10 +823,7 @@ static inline int dw_pcie_resume_noirq(struct dw_pcie *pci)return 0 ; } -static inline irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp) -{ -return IRQ_NONE ; -} +static inline void dw_handle_msi_irq (struct dw_pcie_rp *pp) { }static inline void dw_pcie_msi_init (struct dw_pcie_rp *pp) { }
Signature · 1 line
2.51.1
[tip: irq/msi] PCI: dwc: Code cleanup
The following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: f1875091a01dd634ff5f8b6fc57ab874f755c415 Gitweb: https://git.kernel.org/tip/f1875091a01dd634ff5f8b6fc57ab874f755c415 Author: Radu Rendec <[email protected]> AuthorDate: Fri, 28 Nov 2025 16:20:54 -05:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00
PCI: dwc: Code cleanup
Code cleanup with no functional changes. These changes were originally made by Thomas Gleixner (see Link tag below) in a patch that was never submitted as is. Other parts of that patch were eventually submitted as commit 8e717112caf3 ("PCI: dwc: Switch to msi_create_parent_irq_domain()") and the remaining parts are the code cleanup changes:
- Use guard()/scoped_guard() instead of open-coded lock/unlock.
- Return void in a few functions whose return value is never used.
- Simplify dw_handle_msi_irq() by using for_each_set_bit().
One notable deviation from the original patch is that it reverts back to a simple 1 by 1 iteration over the controllers inside dw_handle_msi_irq. The reason is that with the original changes, the IRQ offset was calculated incorrectly.
This prepares the ground for enabling MSI affinity support, which was originally part of that same series that Thomas Gleixner prepared.
--- drivers/pci/controller/dwc/pcie-designware-host.c | 98 ++++---------- drivers/pci/controller/dwc/pcie-designware.h | 7 +- 2 files changed, 34 insertions(+), 71 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +32 -66
@@ -46,35 +46,25 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { };/* MSI int handler */ -irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp) +void dw_handle_msi_irq (struct dw_pcie_rp *pp) { -int i, pos; -unsigned long val; -u32 status, num_ctrls; -irqreturn_t ret =IRQ_NONE ;struct dw_pcie *pci =to_dw_pcie_from_pp (pp); +unsigned int i, num_ctrls; num_ctrls = pp->num_vectors /MAX_MSI_IRQS_PER_CTRL ;for (i =0 ; i < num_ctrls; i++) { - status =dw_pcie_readl_dbi (pci,PCIE_MSI_INTR0_STATUS + - (i *MSI_REG_CTRL_BLOCK_SIZE )); +unsigned int reg_off = i *MSI_REG_CTRL_BLOCK_SIZE ; +unsigned int irq_off = i *MAX_MSI_IRQS_PER_CTRL ; +unsigned long status, pos; + + status =dw_pcie_readl_dbi (pci,PCIE_MSI_INTR0_STATUS + reg_off);if (!status)continue ; - ret =IRQ_HANDLED ; - val = status; - pos =0 ; -while ((pos =find_next_bit (&val,MAX_MSI_IRQS_PER_CTRL , - pos)) !=MAX_MSI_IRQS_PER_CTRL ) { -generic_handle_domain_irq (pp->irq_domain, - (i *MAX_MSI_IRQS_PER_CTRL ) + - pos); - pos++; - } +for_each_set_bit (pos, &status,MAX_MSI_IRQS_PER_CTRL ) +generic_handle_domain_irq (pp->irq_domain, irq_off + pos); } - -return ret; }/* Chained MSI interrupt service routine */
@@ -95,13 +85,10 @@ static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg) {struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp); -u64 msi_target; - - msi_target = (u64 )pp->msi_data; +u64 msi_target = (u64 )pp->msi_data; msg->address_lo =lower_32_bits (msi_target); msg->address_hi =upper_32_bits (msi_target); - msg->data = d->hwirq; dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n",
@@ -113,18 +100,14 @@ static void dw_pci_bottom_mask(struct irq_data *d)struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp);unsigned int res, bit, ctrl; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); +guard (raw_spinlock)(&pp->lock); ctrl = d->hwirq /MAX_MSI_IRQS_PER_CTRL ; res = ctrl *MSI_REG_CTRL_BLOCK_SIZE ; bit = d->hwirq %MAX_MSI_IRQS_PER_CTRL ; pp->irq_mask[ctrl] |=BIT (bit);dw_pcie_writel_dbi (pci,PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); - -raw_spin_unlock_irqrestore (&pp->lock, flags); }static void dw_pci_bottom_unmask (struct irq_data *d)
@@ -132,18 +115,14 @@ static void dw_pci_bottom_unmask(struct irq_data *d)struct dw_pcie_rp *pp =irq_data_get_irq_chip_data (d);struct dw_pcie *pci =to_dw_pcie_from_pp (pp);unsigned int res, bit, ctrl; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); +guard (raw_spinlock)(&pp->lock); ctrl = d->hwirq /MAX_MSI_IRQS_PER_CTRL ; res = ctrl *MSI_REG_CTRL_BLOCK_SIZE ; bit = d->hwirq %MAX_MSI_IRQS_PER_CTRL ; pp->irq_mask[ctrl] &= ~BIT (bit);dw_pcie_writel_dbi (pci,PCIE_MSI_INTR0_MASK + res, pp->irq_mask[ctrl]); - -raw_spin_unlock_irqrestore (&pp->lock, flags); }static void dw_pci_bottom_ack (struct irq_data *d)
@@ -160,54 +139,42 @@ static void dw_pci_bottom_ack(struct irq_data *d) }static struct irq_chip dw_pci_msi_bottom_irq_chip = { - .name ="DWPCI-MSI" , - .irq_ack = dw_pci_bottom_ack, - .irq_compose_msi_msg = dw_pci_setup_msi_msg, - .irq_mask = dw_pci_bottom_mask, - .irq_unmask = dw_pci_bottom_unmask, + .name ="DWPCI-MSI" , + .irq_ack = dw_pci_bottom_ack, + .irq_compose_msi_msg = dw_pci_setup_msi_msg, + .irq_mask = dw_pci_bottom_mask, + .irq_unmask = dw_pci_bottom_unmask, }; -static int dw_pcie_irq_domain_alloc (struct irq_domain *domain, -unsigned int virq,unsigned int nr_irqs, -void *args) +static int dw_pcie_irq_domain_alloc (struct irq_domain *domain,unsigned int virq, +unsigned int nr_irqs,void *args) {struct dw_pcie_rp *pp = domain->host_data; -unsigned long flags; -u32 i;int bit; -raw_spin_lock_irqsave (&pp->lock, flags); - - bit =bitmap_find_free_region (pp->msi_irq_in_use, pp->num_vectors, -order_base_2 (nr_irqs)); - -raw_spin_unlock_irqrestore (&pp->lock, flags); + scoped_guard (raw_spinlock_irq, &pp->lock) { + bit =bitmap_find_free_region (pp->msi_irq_in_use, pp->num_vectors, +order_base_2 (nr_irqs)); + }if (bit <0 )return -ENOSPC ; -for (i =0 ; i < nr_irqs; i++) -irq_domain_set_info (domain, virq + i, bit + i, - pp->msi_irq_chip, - pp, handle_edge_irq, -NULL ,NULL ); - +for (unsigned int i =0 ; i < nr_irqs; i++) { +irq_domain_set_info (domain, virq + i, bit + i, pp->msi_irq_chip, + pp, handle_edge_irq,NULL ,NULL ); + }return 0 ; } -static void dw_pcie_irq_domain_free (struct irq_domain *domain, -unsigned int virq,unsigned int nr_irqs) +static void dw_pcie_irq_domain_free (struct irq_domain *domain,unsigned int virq, +unsigned int nr_irqs) {struct irq_data *d =irq_domain_get_irq_data (domain, virq);struct dw_pcie_rp *pp = domain->host_data; -unsigned long flags; - -raw_spin_lock_irqsave (&pp->lock, flags); -bitmap_release_region (pp->msi_irq_in_use, d->hwirq, -order_base_2 (nr_irqs)); - -raw_spin_unlock_irqrestore (&pp->lock, flags); +guard (raw_spinlock_irq)(&pp->lock); +bitmap_release_region (pp->msi_irq_in_use, d->hwirq,order_base_2 (nr_irqs)); }static const struct irq_domain_ops dw_pcie_msi_domain_ops = {
@@ -241,8 +208,7 @@ void dw_pcie_free_msi(struct dw_pcie_rp *pp)for (ctrl =0 ; ctrl <MAX_MSI_CTRLS ; ctrl++) {if (pp->msi_irq[ctrl] >0 ) -irq_set_chained_handler_and_data (pp->msi_irq[ctrl], -NULL ,NULL ); +irq_set_chained_handler_and_data (pp->msi_irq[ctrl],NULL ,NULL ); }irq_domain_remove (pp->irq_domain);
drivers/pci/controller/dwc/pcie-designware.h +2 -5
@@ -821,7 +821,7 @@ static inline enum dw_pcie_ltssm dw_pcie_get_ltssm(struct dw_pcie *pci)#ifdef CONFIG_PCIE_DW_HOST int dw_pcie_suspend_noirq (struct dw_pcie *pci);int dw_pcie_resume_noirq (struct dw_pcie *pci); -irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp); +void dw_handle_msi_irq (struct dw_pcie_rp *pp);void dw_pcie_msi_init (struct dw_pcie_rp *pp);int dw_pcie_msi_host_init (struct dw_pcie_rp *pp);void dw_pcie_free_msi (struct dw_pcie_rp *pp);
@@ -842,10 +842,7 @@ static inline int dw_pcie_resume_noirq(struct dw_pcie *pci)return 0 ; } -static inline irqreturn_t dw_handle_msi_irq (struct dw_pcie_rp *pp) -{ -return IRQ_NONE ; -} +static inline void dw_handle_msi_irq (struct dw_pcie_rp *pp) { }static inline void dw_pcie_msi_init (struct dw_pcie_rp *pp) { }
PATCH v3 3/3 PCI: dwc: Enable MSI affinity support
In reply to Radu RendecLeverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
--- .../pci/controller/dwc/pcie-designware-host.c | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +28 -5
@@ -26,9 +26,27 @@ static struct pci_ops dw_pcie_ops;static struct pci_ops dw_pcie_ecam_ops;static struct pci_ops dw_child_pcie_ops; +#ifdef CONFIG_SMP +static void dw_irq_noop (struct irq_data *d) { } +#endif + +static bool dw_pcie_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; + +#ifdef CONFIG_SMP + info->chip->irq_ack = dw_irq_noop; + info->chip->irq_pre_redirect = irq_chip_pre_redirect_parent; +#else + info->chip->irq_ack = irq_chip_ack_parent; +#endif +return true; +} +#define DW_PCIE_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ MSI_FLAG_USE_DEF_CHIP_OPS | \ - MSI_FLAG_NO_AFFINITY | \ MSI_FLAG_PCI_MSI_MASK_PARENT)#define DW_PCIE_MSI_FLAGS_SUPPORTED (MSI_FLAG_MULTI_PCI_MSI | \ MSI_FLAG_PCI_MSIX | \
@@ -40,9 +58,8 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { .required_flags = DW_PCIE_MSI_FLAGS_REQUIRED, .supported_flags = DW_PCIE_MSI_FLAGS_SUPPORTED, .bus_select_token = DOMAIN_BUS_PCI_MSI, - .chip_flags = MSI_CHIP_FLAG_SET_ACK, .prefix = "DW-", - .init_dev_msi_info = msi_lib_init_dev_msi_info, + .init_dev_msi_info = dw_pcie_init_dev_msi_info, };/* MSI int handler */
@@ -63,7 +80,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)continue ;for_each_set_bit (pos, &status,MAX_MSI_IRQS_PER_CTRL ) -generic_handle_domain_irq (pp->irq_domain, irq_off + pos); +generic_handle_demux_domain_irq (pp->irq_domain, irq_off + pos); } }
@@ -140,10 +157,16 @@ static void dw_pci_bottom_ack(struct irq_data *d)static struct irq_chip dw_pci_msi_bottom_irq_chip = { .name ="DWPCI-MSI" , - .irq_ack = dw_pci_bottom_ack, .irq_compose_msi_msg = dw_pci_setup_msi_msg, .irq_mask = dw_pci_bottom_mask, .irq_unmask = dw_pci_bottom_unmask, +#ifdef CONFIG_SMP + .irq_ack = dw_irq_noop, + .irq_pre_redirect = dw_pci_bottom_ack, + .irq_set_affinity = irq_chip_redirect_set_affinity, +#else + .irq_ack = dw_pci_bottom_ack, +#endif }; static int dw_pcie_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
Signature · 1 line
2.51.1
[tip: irq/msi] PCI: dwc: Enable MSI affinity support
The following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: eaf290c404f7c39f23292e9ce83b8b5b51ab598a Gitweb: https://git.kernel.org/tip/eaf290c404f7c39f23292e9ce83b8b5b51ab598a Author: Radu Rendec <[email protected]> AuthorDate: Fri, 28 Nov 2025 16:20:55 -05:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00
PCI: dwc: Enable MSI affinity support
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
--- drivers/pci/controller/dwc/pcie-designware-host.c | 33 +++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +28 -5
@@ -26,9 +26,27 @@ static struct pci_ops dw_pcie_ops;static struct pci_ops dw_pcie_ecam_ops;static struct pci_ops dw_child_pcie_ops; +#ifdef CONFIG_SMP +static void dw_irq_noop (struct irq_data *d) { } +#endif + +static bool dw_pcie_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; + +#ifdef CONFIG_SMP + info->chip->irq_ack = dw_irq_noop; + info->chip->irq_pre_redirect = irq_chip_pre_redirect_parent; +#else + info->chip->irq_ack = irq_chip_ack_parent; +#endif +return true; +} +#define DW_PCIE_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ MSI_FLAG_USE_DEF_CHIP_OPS | \ - MSI_FLAG_NO_AFFINITY | \ MSI_FLAG_PCI_MSI_MASK_PARENT)#define DW_PCIE_MSI_FLAGS_SUPPORTED (MSI_FLAG_MULTI_PCI_MSI | \ MSI_FLAG_PCI_MSIX | \
@@ -40,9 +58,8 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { .required_flags = DW_PCIE_MSI_FLAGS_REQUIRED, .supported_flags = DW_PCIE_MSI_FLAGS_SUPPORTED, .bus_select_token = DOMAIN_BUS_PCI_MSI, - .chip_flags = MSI_CHIP_FLAG_SET_ACK, .prefix = "DW-", - .init_dev_msi_info = msi_lib_init_dev_msi_info, + .init_dev_msi_info = dw_pcie_init_dev_msi_info, };/* MSI int handler */
@@ -63,7 +80,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)continue ;for_each_set_bit (pos, &status,MAX_MSI_IRQS_PER_CTRL ) -generic_handle_domain_irq (pp->irq_domain, irq_off + pos); +generic_handle_demux_domain_irq (pp->irq_domain, irq_off + pos); } }
@@ -140,10 +157,16 @@ static void dw_pci_bottom_ack(struct irq_data *d)static struct irq_chip dw_pci_msi_bottom_irq_chip = { .name ="DWPCI-MSI" , - .irq_ack = dw_pci_bottom_ack, .irq_compose_msi_msg = dw_pci_setup_msi_msg, .irq_mask = dw_pci_bottom_mask, .irq_unmask = dw_pci_bottom_unmask, +#ifdef CONFIG_SMP + .irq_ack = dw_irq_noop, + .irq_pre_redirect = dw_pci_bottom_ack, + .irq_set_affinity = irq_chip_redirect_set_affinity, +#else + .irq_ack = dw_pci_bottom_ack, +#endif }; static int dw_pcie_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
Jon Hunter
maintainerRe: [tip: irq/msi] PCI: dwc: Enable MSI affinity support
Hi Radu,
Quoted 20 lines · On 15/12/2025 21:34, tip-bot2 for Radu Rendec wrote:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: eaf290c404f7c39f23292e9ce83b8b5b51ab598a Gitweb: https://git.kernel.org/tip/eaf290c404f7c39f23292e9ce83b8b5b51ab598a Author: Radu Rendec <[email protected]> AuthorDate: Fri, 28 Nov 2025 16:20:55 -05:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00PCI: dwc: Enable MSI affinity support
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Quoted 5 lines
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>
With next-20260105 I am observing the following warning on the Tegra194 Jetson AGX platform ...
WARNING KERN genirq: irq_chip DW-PCI-MSI-0001:01:00.0 did not update
eff. affinity mask of irq 171
Bisect is point to this commit. This platform is using the driver drivers/pci/controller/dwc/pcie-tegra194.c. Is there some default affinity that we should be setting to avoid this warning?
Thanks
Jon
Signature · 1 line
nvpublic
Re: [tip: irq/msi] PCI: dwc: Enable MSI affinity support
Hi Jon,
Quoted 31 lines · Jon Hunter
Quoted 20 lines · On 15/12/2025 21:34, tip-bot2 for Radu Rendec wrote:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID:
eaf290c404f7c39f23292e9ce83b8b5b51ab598a
Gitweb: https://git.kernel.org/tip/eaf290c404f7c39f23292e9ce83b8b5b51ab598a
Author: Radu Rendec <[email protected]>
AuthorDate: Fri, 28 Nov 2025 16:20:55 -05:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00PCI: dwc: Enable MSI affinity support
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Quoted 5 lines
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>With next-20260105 I am observing the following warning on the Tegra194 Jetson AGX platform ...
Quoted 6 lines
WARNING KERN genirq:
irq_chipDW-PCI-MSI-0001:01:00.0 did not update eff. affinity mask of irq 171Bisect is point to this commit. This platform is using the driver
drivers/pci/controller/dwc/pcie-tegra194.c. Is there some default affinity that we should be setting to avoid this warning?
Before that patch, affinity control wasn't even possible for PCI MSIs exposed by the dw_pci drivers. Without having looked at the code yet, I suspect it's just because now that affinity control is enabled, something tries to use it.
I don't think you should set some default affinity. By default, the PCI MSIs should be affine to all available CPUs, and that warning shouldn't happen in the first place. Let me test on Jetson AGX and see what's going on. I'll update the thread with my findings, hopefully later today.
Signature · 2 lines
Thanks, Radu
Re: [tip: irq/msi] PCI: dwc: Enable MSI affinity support
Hi Jon,
Quoted 44 lines · Radu Rendec
Quoted 31 lines · Jon Hunter
Quoted 20 lines · On 15/12/2025 21:34, tip-bot2 for Radu Rendec wrote:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID:
eaf290c404f7c39f23292e9ce83b8b5b51ab598a
Gitweb: https://git.kernel.org/tip/eaf290c404f7c39f23292e9ce83b8b5b51ab598a
Author: Radu Rendec <[email protected]>
AuthorDate: Fri, 28 Nov 2025 16:20:55 -05:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Mon, 15 Dec 2025 22:30:48 +01:00PCI: dwc: Enable MSI affinity support
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Quoted 5 lines
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>With next-20260105 I am observing the following warning on the Tegra194 Jetson AGX platform ...
Quoted 6 lines
WARNING KERN genirq:
irq_chipDW-PCI-MSI-0001:01:00.0 did not update eff. affinity mask of irq 171Bisect is point to this commit. This platform is using the driver
drivers/pci/controller/dwc/pcie-tegra194.c. Is there some default affinity that we should be setting to avoid this warning?Before that patch, affinity control wasn't even possible for PCI MSIs exposed by the
dw_pcidrivers. Without having looked at the code yet, I suspect it's just because now that affinity control is enabled, something tries to use it.
Quoted 5 lines
I don't think you should set some default affinity. By default, the PCI MSIs should be affine to all available CPUs, and that warning shouldn't happen in the first place. Let me test on Jetson AGX and see what's going on. I'll update the thread with my findings, hopefully later today.
I looked at the code and tested, and the problem is that the effective affinity mask is not updated for interrupt redirection. The bug is not in this patch, but the previous one in the series [1], which adds the interrupt redirection framework.
The warning is actually triggered when the MSI is set up. This is the top part of the relevant stack trace:
irq_do_set_affinity+0x28c/0x300 (P) irq_setup_affinity+0x130/0x208 irq_startup+0x118/0x170 __setup_irq+0x5b0/0x6a0 request_threaded_irq+0xb8/0x180 devm_request_threaded_irq+0x88/0x150 rtw_pci_probe+0x1e8/0x370 [rtw88_pci]
I don't immediately see an easy way to fix it for the generic case because the affinity of the demultiplexing IRQ (the "parent" IRQ) can change after the affinity of the demultiplexed IRQ (the "child" IRQ) has been set up. But since dw_pcie is currently the only user of the interrupt redirection infrastructure, and it sets up the demultiplexing IRQ as a chained IRQ, there is no way its affinity can change other than CPU hot(un)plug. And in this particular case, something as simple as will work:
kernel/irq/chip.c +4 -1
@@ -1512,8 +1512,11 @@ EXPORT_SYMBOL_GPL(irq_chip_release_resources_parent);int irq_chip_redirect_set_affinity (struct irq_data *data,const struct cpumask *dest,bool force) {struct irq_redirect *redir = &irq_data_to_desc (data)->redirect; +unsigned int target_cpu =cpumask_first (dest); + +WRITE_ONCE (redir->target_cpu, target_cpu); +irq_data_update_effective_affinity (data,cpumask_of (target_cpu)); -WRITE_ONCE (redir->target_cpu,cpumask_first (dest));return IRQ_SET_MASK_OK ; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);
I will send this as a proper patch tomorrow, and it will fix the immediate problem and buy some time for a more elaborate fix for the generic case. Meanwhile, thanks a lot for finding/reporting this!
[1] https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Best regards, Radu
Jon Hunter
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
In reply to Radu RendecHi Radu,
Quoted 77 lines · Radu Rendec
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>--- .../pci/controller/dwc/pcie-designware-host.c | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +21
-5@@ -26,9 +26,27 @@ static struct pci_ops dw_pcie_ops;static struct pci_ops dw_pcie_ecam_ops;static struct pci_ops dw_child_pcie_ops; +#ifdef CONFIG_SMP +static void dw_irq_noop (struct irq_data *d) { } +#endif + +static bool dw_pcie_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; + +#ifdef CONFIG_SMP + info->chip->irq_ack = dw_irq_noop; + info->chip->irq_pre_redirect = irq_chip_pre_redirect_parent; +#else + info->chip->irq_ack = irq_chip_ack_parent; +#endif +return true; +} +#define DW_PCIE_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ MSI_FLAG_USE_DEF_CHIP_OPS | \ - MSI_FLAG_NO_AFFINITY | \ MSI_FLAG_PCI_MSI_MASK_PARENT)#define DW_PCIE_MSI_FLAGS_SUPPORTED (MSI_FLAG_MULTI_PCI_MSI | \ MSI_FLAG_PCI_MSIX | \@@ -40,9 +58,8 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { .required_flags = DW_PCIE_MSI_FLAGS_REQUIRED, .supported_flags = DW_PCIE_MSI_FLAGS_SUPPORTED, .bus_select_token = DOMAIN_BUS_PCI_MSI, - .chip_flags = MSI_CHIP_FLAG_SET_ACK, .prefix = "DW-", - .init_dev_msi_info = msi_lib_init_dev_msi_info, + .init_dev_msi_info = dw_pcie_init_dev_msi_info, };/* MSI int handler */ @@ -63,7 +80,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)continue ;for_each_set_bit (pos, &status,MAX_MSI_IRQS_PER_CTRL ) -generic_handle_domain_irq (pp->irq_domain, irq_off + pos); +generic_handle_demux_domain_irq (pp->irq_domain, irq_off + pos); } }@@ -140,10 +157,16 @@ static void dw_pci_bottom_ack(struct irq_data *d)static struct irq_chip dw_pci_msi_bottom_irq_chip = { .name ="DWPCI-MSI" , - .irq_ack = dw_pci_bottom_ack, .irq_compose_msi_msg = dw_pci_setup_msi_msg, .irq_mask = dw_pci_bottom_mask, .irq_unmask = dw_pci_bottom_unmask,
drivers/pci/controller/dwc/pcie-designware-host.c static void dw_pci_bottom_ack(struct irq_data *d) · line 172
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +7
-0+#ifdef CONFIG_SMP + .irq_ack = dw_irq_noop, + .irq_pre_redirect = dw_pci_bottom_ack, + .irq_set_affinity = irq_chip_redirect_set_affinity, +#else + .irq_ack = dw_pci_bottom_ack, +#endif }; static int dw_pcie_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
I am seeing another issue with this patch. On the Tegra194 AGX Xavier platform suspend is failing and reverting this patch fixes the problem.
Unfortunately the logs don't tell me much. In a bad case I see ...
PM: suspend entry (deep)
Filesystems sync: 0.000 seconds
Freezing user space processes
Freezing user space processes completed (elapsed 0.002 seconds) OOM killer disabled.
Freezing remaining freezable tasks
Freezing remaining freezable tasks completed (elapsed 0.001 seconds) tegra-xusb 3610000.usb: Firmware timestamp: 2020-09-11 16:55:03 UTC dwc-eth-dwmac 2490000.ethernet eth0: Link is Down tegra194-pcie 14100000.pcie: Link didn't transition to L2 state Disabling non-boot CPUs ...
It appears to hang here. In a good case I see ...
PM: suspend entry (deep)
Filesystems sync: 0.000 seconds
Freezing user space processes
Freezing user space processes completed (elapsed 0.002 seconds) OOM killer disabled.
Freezing remaining freezable tasks
Freezing remaining freezable tasks completed (elapsed 0.001 seconds) tegra-xusb 3610000.usb: Firmware timestamp: 2020-09-11 16:55:03 UTC dwc-eth-dwmac 2490000.ethernet eth0: Link is Down tegra194-pcie 14100000.pcie: Link didn't transition to L2 state Disabling non-boot CPUs ...
psci: CPU7 killed (polled 0 ms)
psci: CPU6 killed (polled 4 ms)
psci: CPU5 killed (polled 0 ms)
psci: CPU4 killed (polled 4 ms)
psci: CPU3 killed (polled 4 ms)
psci: CPU2 killed (polled 0 ms)
psci: CPU1 killed (polled 0 ms)
...
Enabling non-boot CPUs ... (resume starts)
So it looks like it is hanging when disabling the non-boot CPUs. So far it only appears to happen on Tegra194.
Let me know if you have any suggestions.
Thanks
Jon
Signature · 1 line
nvpublic
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Jon,
Quoted 130 lines · Jon Hunter
Quoted 84 lines · Radu Rendec
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>---
.../pci/controller/dwc/pcie-designware-host.c| 33 ++++++++++++++++---1 file changed, 28 insertions(+), 5 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +0
-0@@ -26,9 +26,27 @@ static struct pci_ops dw_pcie_ops; static struct pci_ops dw_pcie_ecam_ops; static struct pci_ops dw_child_pcie_ops;drivers/pci/controller/dwc/pcie-designware-host.c +19
-0+#ifdef CONFIG_SMP +static void dw_irq_noop (struct irq_data *d) { } +#endif + +static bool dw_pcie_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; + +#ifdef CONFIG_SMP + info->chip->irq_ack = dw_irq_noop; + info->chip->irq_pre_redirect = irq_chip_pre_redirect_parent; +#else + info->chip->irq_ack = irq_chip_ack_parent; +#endif +return true; +} +#define
DW_PCIE_MSI_FLAGS_REQUIRED(MSI_FLAG_USE_DEF_DOM_OPS| \
MSI_FLAG_USE_DEF_CHIP_OPS| \
-MSI_FLAG_NO_AFFINITY| \
MSI_FLAG_PCI_MSI_MASK_PARENT)
#defineDW_PCIE_MSI_FLAGS_SUPPORTED(MSI_FLAG_MULTI_PCI_MSI| \
MSI_FLAG_PCI_MSIX| \drivers/pci/controller/dwc/pcie-designware-host.c +1
-2@@ -40,9 +58,8 @@ static const struct msi_parent_ops dw_pcie_msi_parent_ops = { .required_flags = DW_PCIE_MSI_FLAGS_REQUIRED, .supported_flags = DW_PCIE_MSI_FLAGS_SUPPORTED, .bus_select_token = DOMAIN_BUS_PCI_MSI, - .chip_flags = MSI_CHIP_FLAG_SET_ACK, .prefix = "DW-", - .init_dev_msi_info = msi_lib_init_dev_msi_info, + .init_dev_msi_info = dw_pcie_init_dev_msi_info, };
/* MSI int handler */drivers/pci/controller/dwc/pcie-designware-host.c +0
-0@@ -63,7 +80,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp) continue;
for_each_set_bit(pos, &status, MAX_MSI_IRQS_PER_CTRL)
-generic_handle_domain_irq(pp->irq_domain, irq_off + pos);
+generic_handle_demux_domain_irq(pp->irq_domain, irq_off + pos); }
}drivers/pci/controller/dwc/pcie-designware-host.c +0
-0@@ -140,10 +157,16 @@ static void dw_pci_bottom_ack(struct irq_data *d)
static structirq_chipdw_pci_msi_bottom_irq_chip= { .name = "DWPCI-MSI",
- .irq_ack =dw_pci_bottom_ack, .irq_compose_msi_msg =dw_pci_setup_msi_msg, .irq_mask =dw_pci_bottom_mask,
.irq_unmask =dw_pci_bottom_unmask,drivers/pci/controller/dwc/pcie-designware-host.c +7
-0+#ifdef CONFIG_SMP + .irq_ack = dw_irq_noop, + .irq_pre_redirect = dw_pci_bottom_ack, + .irq_set_affinity = irq_chip_redirect_set_affinity, +#else + .irq_ack = dw_pci_bottom_ack, +#endif Quoted 3 lines
};
static int dw_pcie_irq_domain_alloc(structirq_domain*domain, unsigned int virq,I am seeing another issue with this patch. On the Tegra194 AGX Xavier platform suspend is failing and reverting this patch fixes the problem.
Unfortunately the logs don't tell me much. In a bad case I see ...
PM: suspend entry (deep)
Filesystems sync: 0.000 seconds
Freezing user space processes
Freezing user space processes completed (elapsed 0.002 seconds) OOM killer disabled.
Freezing remaining freezable tasks
Freezing remaining freezable tasks completed (elapsed 0.001 seconds) tegra-xusb 3610000.usb: Firmware timestamp: 2020-09-11 16:55:03 UTC dwc-eth-dwmac 2490000.ethernet eth0: Link is Down tegra194-pcie 14100000.pcie: Link didn't transition to L2 state Disabling non-boot CPUs ...It appears to hang here. In a good case I see ...
PM: suspend entry (deep)
Filesystems sync: 0.000 seconds
Freezing user space processes
Freezing user space processes completed (elapsed 0.002 seconds) OOM killer disabled.
Freezing remaining freezable tasks
Freezing remaining freezable tasks completed (elapsed 0.001 seconds) tegra-xusb 3610000.usb: Firmware timestamp: 2020-09-11 16:55:03 UTC dwc-eth-dwmac 2490000.ethernet eth0: Link is Down tegra194-pcie 14100000.pcie: Link didn't transition to L2 state Disabling non-boot CPUs ...
psci: CPU7 killed (polled 0 ms)
psci: CPU6 killed (polled 4 ms)
psci: CPU5 killed (polled 0 ms)
psci: CPU4 killed (polled 4 ms)
psci: CPU3 killed (polled 4 ms)
psci: CPU2 killed (polled 0 ms)
psci: CPU1 killed (polled 0 ms)
...
Enabling non-boot CPUs ... (resume starts)
Quoted 4 lines
So it looks like it is hanging when disabling the non-boot CPUs. So far it only appears to happen on Tegra194.
Let me know if you have any suggestions.
Ouch. I'm afraid this is going to be much harder to figure out than the previous one, especially since I can't get access easily to a board to test on. I will try to reserve a board and reproduce the bug.
Meanwhile, if you (or someone else in your team) can spare a few cycles, could you please try to reproduce the bug again with the debug patch below applied, and a few other changes:
* enable debug messages in kernel/irq/cpuhotplug.c;
* save the contents of /proc/interrupts to a file before suspending;
* add "no_console_suspend" to the kernel command line (although it looks like you already have it).
It will be much more verbose during suspend but hopefully we can at least figure out how far along it goes and how it's related to the MSI affinity configuration.
Thanks,
Radu
---
kernel/irq/chip.c +2 -0
@@ -1492,6 +1492,8 @@ int irq_chip_redirect_set_affinity(struct irq_data *data, const struct cpumask * {struct irq_redirect *redir = &irq_data_to_desc (data)->redirect; +pr_info ("%s: irq %u mask 0x%*pb\n" , __func__, data->irq,cpumask_pr_args (dest)); +WRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest);
kernel/irq/cpuhotplug.c +2 -0
@@ -59,6 +59,8 @@ static bool migrate_one_irq(struct irq_desc *desc)bool brokeaff = false;int err; +pr_info ("%s: irq %u cpu %u\n" , __func__, d->irq,smp_processor_id ()); +/* * IRQ chip might be already torn down, but the irq descriptor is * still in the radix tree. Also if the chip has no affinity setter,
kernel/stop_machine.c +1 -0
@@ -227,6 +227,7 @@ static int multi_cpu_stop(void *data)stop_machine_yield (cpumask); newstate =READ_ONCE (msdata->state);if (newstate != curstate) { +pr_info ("%s: cpu %d entering state %d\n" , __func__, cpu, newstate); curstate = newstate;switch (curstate) {case MULTI_STOP_DISABLE_IRQ :
Jon Hunter
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
On 20/01/2026 22:30, Radu Rendec wrote:
...
Quoted 17 lines
Quoted 4 lines
So it looks like it is hanging when disabling the non-boot CPUs. So far it only appears to happen on Tegra194.
Let me know if you have any suggestions.
Ouch. I'm afraid this is going to be much harder to figure out than the previous one, especially since I can't get access easily to a board to test on. I will try to reserve a board and reproduce the bug.
Meanwhile, if you (or someone else in your team) can spare a few cycles, could you please try to reproduce the bug again with the debug patch below applied, and a few other changes:
* enable debug messages inkernel/irq/cpuhotplug.c;
* save the contents of/proc/interruptsto a file before suspending;
* add "no_console_suspend" to the kernel command line (although it looks like you already have it).
Quoted 3 lines
It will be much more verbose during suspend but hopefully we can at least figure out how far along it goes and how it's related to the MSI affinity configuration.
Thanks. I have dumped the boot log with the prints here:
And the dump of /proc/interrupts here:
Looks like the last thing I see entering suspend is ...
irq_chip_redirect_set_affinity: irq 162 mask 0x7f
That appears to be a PCIe interrupt. Let me know if there are more tests I can run.
Cheers
Jon
Signature · 1 line
nvpublic
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Jon,
Quoted 33 lines · Jon Hunter
On 20/01/2026 22:30, Radu Rendec wrote:
...
Quoted 17 lines
Quoted 4 lines
So it looks like it is hanging when disabling the non-boot CPUs. So far it only appears to happen on Tegra194.
Let me know if you have any suggestions.
Ouch. I'm afraid this is going to be much harder to figure out than the previous one, especially since I can't get access easily to a board to test on. I will try to reserve a board and reproduce the bug.
Meanwhile, if you (or someone else in your team) can spare a few cycles, could you please try to reproduce the bug again with the debug patch below applied, and a few other changes:
* enable debug messages inkernel/irq/cpuhotplug.c;
* save the contents of/proc/interruptsto a file before suspending;
* add "no_console_suspend" to the kernel command line (although it looks like you already have it).Quoted 3 lines
It will be much more verbose during suspend but hopefully we can at least figure out how far along it goes and how it's related to the MSI affinity configuration.
Thanks. I have dumped the boot log with the prints here:
And the dump of
/proc/interruptshere:
Quoted 8 lines
Looks like the last thing I see entering suspend is ...
irq_chip_redirect_set_affinity: irq 162 mask0x7fThat appears to be a PCIe interrupt. Let me know if there are more tests I can run.
Thanks very much for running the test and for the logs. The good news is good ol' printk debugging seems to be working, and the last message in the log is indeed related to dw-pci irq affinity control, which is what the patch touches. So we're on to something. The bad news is I can't yet figure out what's wrong.
The CPUs are taken offline one by one, starting with CPU 7. The code in question runs on the dying CPU, and with hardware interrupts disabled on all CPUs. The (simplified) call stack looks like this:
irq_migrate_all_off_this_cpu
for_each_active_irq
migrate_one_irq
irq_do_set_affinity
irq_chip_redirect_set_affinity (via chip->irq_set_affinity)The debug patch I gave you adds:
* a printk to irq_chip_redirect_set_affinity (which is very small)
* a printk at the beginning of migrate_one_irq
Also, the call to irq_do_set_affinity is almost the last thing that happens in migrate_one_irq, and that for_each_active_irq loop is quite small too. So, there isn't much happening between the printk in irq_chip_redirect_set_affinity for the msi irq (which we do see in the log) and the printk in migrate_one_irq for the next irq (which we don't see).
My first thought is to add more printk's between those two and narrow down the spot where it gets stuck.
I think the fastest way to debug it is if I can test myself. I tried to reproduce the issue on a Jetson AGX Orin, and I couldn't. By the way, how often does it hang? e.g., out of say 10 suspend attempts, how many fail?
I do have access to a Jetson Xavier NX (in theory) but it looks like there's a lab issue with that board, which hopefully gets sorted out tomorrow. If I can't get a hold of that board (or can't reproduce the problem on it), I may ask you to try a few other things. In any case, I'll update this thread again either tomorrow or (more likely) early next week.
Signature · 2 lines
Thanks, Radu
Jon Hunter
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
On 22/01/2026 23:31, Radu Rendec wrote:
...
Quoted 27 lines
Thanks very much for running the test and for the logs. The good news is good ol' printk debugging seems to be working, and the last message in the log is indeed related to dw-pci irq affinity control, which is what the patch touches. So we're on to something. The bad news is I can't yet figure out what's wrong.
The CPUs are taken offline one by one, starting with CPU 7. The code in question runs on the dying CPU, and with hardware interrupts disabled on all CPUs. The (simplified) call stack looks like this:
irq_migrate_all_off_this_cpu
for_each_active_irqmigrate_one_irq irq_do_set_affinity irq_chip_redirect_set_affinity (via chip->irq_set_affinity)The debug patch I gave you adds:
* a printk toirq_chip_redirect_set_affinity(which is very small)
* a printk at the beginning ofmigrate_one_irqAlso, the call to
irq_do_set_affinityis almost the last thing that happens inmigrate_one_irq, and thatfor_each_active_irqloop is quite small too. So, there isn't much happening between the printk inirq_chip_redirect_set_affinityfor the msi irq (which we do see in the log) and the printk inmigrate_one_irqfor the next irq (which we don't see).
Quoted 7 lines
My first thought is to add more printk's between those two and narrow down the spot where it gets stuck.
I think the fastest way to debug it is if I can test myself. I tried to reproduce the issue on a Jetson AGX Orin, and I couldn't. By the way, how often does it hang? e.g., out of say 10 suspend attempts, how many fail?
For Jetson AGX Xavier it fails on the first suspend attempt.
Quoted 6 lines
I do have access to a Jetson Xavier NX (in theory) but it looks like there's a lab issue with that board, which hopefully gets sorted out tomorrow. If I can't get a hold of that board (or can't reproduce the problem on it), I may ask you to try a few other things. In any case, I'll update this thread again either tomorrow or (more likely) early next week.
Weirdly I don't see this with Jetson Xavier NX. However, could be worth trying but you may wish to revert this change [0] because it is causing other issues for Jetson Xavier NX.
Jon
[0] https://lore.kernel.org/linux-tegra/[email protected]/
Signature · 1 line
nvpublic
Thomas Gleixner
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
In reply to Radu RendecQuoted 14 lines · Radu Rendec
The CPUs are taken offline one by one, starting with CPU 7. The code in question runs on the dying CPU, and with hardware interrupts disabled on all CPUs. The (simplified) call stack looks like this:
irq_migrate_all_off_this_cpu
for_each_active_irqmigrate_one_irq irq_do_set_affinity irq_chip_redirect_set_affinity (via chip->irq_set_affinity)The debug patch I gave you adds:
* a printk toirq_chip_redirect_set_affinity(which is very small)
* a printk at the beginning ofmigrate_one_irq
Quoted 6 lines
Also, the call to
irq_do_set_affinityis almost the last thing that happens inmigrate_one_irq, and thatfor_each_active_irqloop is quite small too. So, there isn't much happening between the printk inirq_chip_redirect_set_affinityfor the msi irq (which we do see in the log) and the printk inmigrate_one_irqfor the next irq (which we don't see).
This doesn't make any sense at all. irq_chip_redirect_set_affinity() is only accessing interrupt descriptor associated memory and the new redirection CPU is the same as the previous one as the mask changes from 0xff to 0x7f and therefore cpumask_first() yields 0 in both cases.
According to the provided dmesg, this happens on linux-next.
Jon, can you please validate that this happens as well on
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/msi
Thanks
tglx
Jon Hunter
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Thomas,
Quoted 27 lines · Thomas Gleixner
Quoted 14 lines · Radu Rendec
The CPUs are taken offline one by one, starting with CPU 7. The code in question runs on the dying CPU, and with hardware interrupts disabled on all CPUs. The (simplified) call stack looks like this:
irq_migrate_all_off_this_cpu
for_each_active_irqmigrate_one_irq irq_do_set_affinity irq_chip_redirect_set_affinity (via chip->irq_set_affinity)The debug patch I gave you adds:
* a printk toirq_chip_redirect_set_affinity(which is very small)
* a printk at the beginning ofmigrate_one_irqQuoted 6 lines
Also, the call to
irq_do_set_affinityis almost the last thing that happens inmigrate_one_irq, and thatfor_each_active_irqloop is quite small too. So, there isn't much happening between the printk inirq_chip_redirect_set_affinityfor the msi irq (which we do see in the log) and the printk inmigrate_one_irqfor the next irq (which we don't see).This doesn't make any sense at all.
irq_chip_redirect_set_affinity()is only accessing interrupt descriptor associated memory and the new redirection CPU is the same as the previous one as the mask changes from0xffto0x7fand thereforecpumask_first()yields 0 in both cases.
Quoted 5 lines
According to the provided dmesg, this happens on linux-next.
Jon, can you please validate that this happens as well on
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitirq/msi
I tried this branch and I see suspend failing with that branch too. If I revert this change on top of your branch or -next, I don't see any problems.
Thanks
Jon
Signature · 1 line
nvpublic
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Jon,
Quoted 30 lines · Jon Hunter
Quoted 29 lines · Thomas Gleixner
Quoted 14 lines · Radu Rendec
The CPUs are taken offline one by one, starting with CPU 7. The code in question runs on the dying CPU, and with hardware interrupts disabled on all CPUs. The (simplified) call stack looks like this:
irq_migrate_all_off_this_cpu
for_each_active_irq
migrate_one_irq
irq_do_set_affinity
irq_chip_redirect_set_affinity(viachip->irq_set_affinity)The debug patch I gave you adds:
* a printk toirq_chip_redirect_set_affinity(which is very small)
* a printk at the beginning ofmigrate_one_irqQuoted 6 lines
Also, the call to
irq_do_set_affinityis almost the last thing that happens inmigrate_one_irq, and thatfor_each_active_irqloop is quite small too. So, there isn't much happening between the printk inirq_chip_redirect_set_affinityfor the msi irq (which we do see in the log) and the printk inmigrate_one_irqfor the next irq (which we don't see).This doesn't make any sense at all.
irq_chip_redirect_set_affinity()is only accessing interrupt descriptor associated memory and the new redirection CPU is the same as the previous one as the mask changes from0xffto0x7fand thereforecpumask_first()yields 0 in both cases.According to the provided dmesg, this happens on linux-next.
Quoted 8 lines
Quoted 3 lines
Jon, can you please validate that this happens as well on
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitirq/msiI tried this branch and I see suspend failing with that branch too. If I revert this change on top of your branch or -next, I don't see any problems.
The closest hardware I have access to is Jetson Xavier NX, and you already mentioned you couldn't reproduce the issue there (and it looks like I can't even get a hold of that board anyway). So I'm going to ask you to test a few more things for me.
Can you please apply the patch below on top of the previous one I sent? The suspect is the spinlock lock in irq_migrate_all_off_this_cpu(), although I can't think of any reason why it shouldn't be free. But I don't have any better idea, and I would like to narrow down the spot where hotplug gets stuck.
kernel/irq/cpuhotplug.c +2 -0
@@ -178,9 +178,11 @@ void irq_migrate_all_off_this_cpu(void)for_each_active_irq (irq) {bool affinity_broken; +pr_info ("%s: irq %u\n" , __func__, irq); desc =irq_to_desc (irq); scoped_guard(raw_spinlock, &desc->lock) { affinity_broken =migrate_one_irq (desc); +pr_info ("%s: migrate_one_irq -> %u\n" , __func__, affinity_broken);if (affinity_broken && desc->affinity_notify)irq_affinity_schedule_notify_work (desc); }
Signature · 2 lines
Thanks, Radu
Thomas Gleixner
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Quoted 15 lines · Radu Rendec
Quoted 8 lines · Jon Hunter
Quoted 3 lines
Jon, can you please validate that this happens as well on
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitirq/msiI tried this branch and I see suspend failing with that branch too. If I revert this change on top of your branch or -next, I don't see any problems.
The closest hardware I have access to is Jetson Xavier NX, and you already mentioned you couldn't reproduce the issue there (and it looks like I can't even get a hold of that board anyway). So I'm going to ask you to test a few more things for me.
Quoted 5 lines
Can you please apply the patch below on top of the previous one I sent? The suspect is the spinlock lock in
irq_migrate_all_off_this_cpu(), although I can't think of any reason why it shouldn't be free. But I don't have any better idea, and I would like to narrow down the spot where hotplug gets stuck.
Can we please take a step back and think about what is actually different when this change is in effect instead of halluzinating about completely unrelated spinlocks?
Without this change the interrupt is ignored in the hotplug migration because it has MSI_FLAG_NO_AFFINITY set.
Now with this new magic in place the following happens:
migrate_one_irq()
...
irq_do_set_affinity()
chip->irq_set_affinity() // --> msi_domain_set_affinity()
parent->chip->irq_set_affinity() // --> irq_chip_redirect_set_affinity()
update target_cpu/effective mask; // Benign
...
irq_chip_write_msi_msg() // --> pci_msi_domain_write_msg()I'm pretty sure that this write screws things up because the devices/busses are already frozen. It simply hangs there.
Usually this is prevented by this check in pci_msi_domain_write_msg():
if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev))
do_nothing();
else ...As the boot log contains this:
[ 44.101151] tegra194-pcie 14100000.pcie: Link didn't transition to L2 state [ 44.110764] Disabling non-boot CPUs ...
... I suspect that there is some weirdness going on with this PCIe controller which subsequently screws up the check.
The below untested hack should confirm that theory.
Thanks,
tglx
---
kernel/irq/msi.c +5 -1
@@ -672,7 +672,11 @@ int msi_domain_set_affinity(struct irq_dif (ret >=0 && ret !=IRQ_SET_MASK_OK_DONE ) {BUG_ON (irq_chip_compose_msi_msg (irq_data, msg));msi_check_level (irq_data->domain, msg); -irq_chip_write_msi_msg (irq_data, msg); +// Hack alert +struct irq_desc *desc =irq_data_to_desc (irq_data); + +if (!(desc->istate &IRQS_SUSPENDED )) +irq_chip_write_msi_msg (irq_data, msg); }return ret;
Thomas Gleixner
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Quoted 1 line · Thomas Gleixner
The below untested hack should confirm that theory.
Actually looking at it deeper the solution is trivial because in this case writing the MSI message to the device is not required when the affinity changes because the message does not change. It is set once via msi_domain_activate() and stays the same for the life time of the interrupt.
So the below prevents the invocation of irq_chip_write_msi_msg() in msi_domain_set_affinity(), but I would recommend to investigate the actual underlying problem nevertheless:
It is going to roar its ugly head at some other place sooner than later as there are tons of other places which guard against pci_dev::current_state != PCI_D0.
Thanks,
tglx
---
kernel/irq/chip.c +1 -1
@@ -1495,7 +1495,7 @@ int irq_chip_redirect_set_affinity(strucWRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest); - return IRQ_SET_MASK_OK; + return IRQ_SET_MASK_OK_DONE; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Thomas,
Quoted 25 lines · Thomas Gleixner
Quoted 1 line · Thomas Gleixner
The below untested hack should confirm that theory.
Actually looking at it deeper the solution is trivial because in this case writing the MSI message to the device is not required when the affinity changes because the message does not change. It is set once via
msi_domain_activate()and stays the same for the life time of the interrupt.So the below prevents the invocation of
irq_chip_write_msi_msg()inmsi_domain_set_affinity(), but I would recommend to investigate the actual underlying problem nevertheless:It is going to roar its ugly head at some other place sooner than later as there are tons of other places which guard against
pci_dev::current_state!=PCI_D0.Thanks,
tglx
---
kernel/irq/chip.c int irq_chip_redirect_set_affinity(struc · line 1501
Quoted 8 lines
kernel/irq/chip.c +1
-1@@ -1495,7 +1495,7 @@ int irq_chip_redirect_set_affinity(strucWRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest); - return IRQ_SET_MASK_OK; + return IRQ_SET_MASK_OK_DONE; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif
Yes that does fix it!
Thanks!
Jon
Signature · 1 line
nvpublic
Thomas Gleixner
maintainerPATCH 1/1 genirq/redirect: Prevent writing MSI message on affinity change
The interrupts which are handled by the redirection infrastructure provide a irq_set_affinity() callback, which solely determines the target CPU for redirection via irq_work and und updates the effective affinity mask.
Contrary to regular MSI interrupts this affinity setting does not change the underlying interrupt message as the message is only created at setup time to deliver to the demultiplexing interrupt.
Therefore the message write in msi_domain_set_affinity() is a pointless exercise. In principle the write is harmless, but a Tegra system exposes a full system hang during suspend due to that write.
It's unclear why the check for the PCI device state PCI_D0 in pci_msi_domain_write_msg(), which prevents the actual hardware access if a device is powered down state, fails on this particular system, but that's a different problem which needs to be investigated by the Tegra experts.
The irq_set_affinity() callback can advise msi_domain_set_affinity() not to write the MSI message by returning IRQ_SET_MASK_OK_DONE instead of IRQ_SET_MASK_OK. Do exactly that.
Just to make it clear again:
This is not a correctness issue of the redirection code as returning IRQ_SET_MASK_OK in that context is completely correct. From the core code point of view this is solely a optimization to avoid an redundant hardware write.
As a byproduct it papers over the underlying problem on the Tegra platform, which fails to put the PCIe device[s] out of PCI_D0 despite the fact that the devices and busses have been shut down. The redirect infrastructure just unearthed the underlying issue, which is prone to happen in quite some other code paths which use the PCI_D0 check to prevent hardware access to powered down devices.
This therefore has neither a 'Fixes:' nor a 'Closes:' tag associated as the underlying problem, which is outside the scope of the interrupt code, is still unresolved.
--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/chip.c +1 -1
@@ -1495,7 +1495,7 @@ int irq_chip_redirect_set_affinity(strucWRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest); - return IRQ_SET_MASK_OK; + return IRQ_SET_MASK_OK_DONE; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif
[tip: irq/msi] genirq/redirect: Prevent writing MSI message on affinity change
The following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 37f9d5026cd78fbe80a124edbbadab382b26545f Gitweb: https://git.kernel.org/tip/37f9d5026cd78fbe80a124edbbadab382b26545f Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 27 Jan 2026 22:30:16 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 29 Jan 2026 23:49:55 +01:00
genirq/redirect: Prevent writing MSI message on affinity change
The interrupts which are handled by the redirection infrastructure provide a irq_set_affinity() callback, which solely determines the target CPU for redirection via irq_work and und updates the effective affinity mask.
Contrary to regular MSI interrupts this affinity setting does not change the underlying interrupt message as the message is only created at setup time to deliver to the demultiplexing interrupt.
Therefore the message write in msi_domain_set_affinity() is a pointless exercise. In principle the write is harmless, but a Tegra system exposes a full system hang during suspend due to that write.
It's unclear why the check for the PCI device state PCI_D0 in pci_msi_domain_write_msg(), which prevents the actual hardware access if a device is in powered down state, fails on this particular system, but that's a different problem which needs to be investigated by the Tegra experts.
The irq_set_affinity() callback can advise msi_domain_set_affinity() not to write the MSI message by returning IRQ_SET_MASK_OK_DONE instead of IRQ_SET_MASK_OK. Do exactly that.
Just to make it clear again:
This is not a correctness issue of the redirection code as returning IRQ_SET_MASK_OK in that context is completely correct. From the core code point of view this is solely a optimization to avoid an redundant hardware write.
As a byproduct it papers over the underlying problem on the Tegra platform, which fails to put the PCIe device[s] out of PCI_D0 despite the fact that the devices and busses have been shut down. The redirect infrastructure just unearthed the underlying issue, which is prone to happen in quite some other code paths which use the PCI_D0 check to prevent hardware access to powered down devices.
This therefore has neither a 'Fixes:' nor a 'Closes:' tag associated as the underlying problem, which is outside the scope of the interrupt code, is still unresolved.
--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/chip.c +1 -1
@@ -1495,7 +1495,7 @@ int irq_chip_redirect_set_affinity(struct irq_data *data, const struct cpumask *WRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest); - return IRQ_SET_MASK_OK; + return IRQ_SET_MASK_OK_DONE; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
In reply to Jon HunterHi,
Do we have plan to land this feature upstream ?
Thanks
Quoted 48 lines · Jon Hunter
Hi Thomas,
Quoted 25 lines · Thomas Gleixner
Quoted 1 line · Thomas Gleixner
The below untested hack should confirm that theory.
Actually looking at it deeper the solution is trivial because in this case writing the MSI message to the device is not required when the affinity changes because the message does not change. It is set once via
msi_domain_activate()and stays the same for the life time of the interrupt.So the below prevents the invocation of
irq_chip_write_msi_msg()inmsi_domain_set_affinity(), but I would recommend to investigate the actual underlying problem nevertheless:It is going to roar its ugly head at some other place sooner than later as there are tons of other places which guard against
pci_dev::current_state!=PCI_D0.Thanks,
tglx
---kernel/irq/chip.c int irq_chip_redirect_set_affinity(struc · line 1501
Quoted 8 lines
kernel/irq/chip.c +1
-1@@ -1495,7 +1495,7 @@ int irq_chip_redirect_set_affinity(strucWRITE_ONCE (redir->target_cpu,cpumask_first (dest));irq_data_update_effective_affinity (data, dest); - return IRQ_SET_MASK_OK; + return IRQ_SET_MASK_OK_DONE; }EXPORT_SYMBOL_GPL (irq_chip_redirect_set_affinity);#endif Yes that does fix it!
Tested-by Jon Hunter <[email protected]>Thanks!
Jon--
nvpublic
Thomas Gleixner
maintainerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
On Thu, Mar 26 2026 at 11:48, Tsai Sung-Fu wrote:
Please do not top post and trim your replies as documented.
Quoted 1 line
Do we have plan to land this feature upstream ?
# cd linux # git log v6.19.. drivers/pci/controller/dwc/pcie-designware-host.c
Thanks,
tglx
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
In reply to Radu RendecHi Radu,
Quoted 5 lines · Radu Rendec
Leverage the interrupt redirection infrastructure to enable CPU affinity support for MSI interrupts. Since the parent interrupt affinity cannot be changed, affinity control for the child interrupt (MSI) is achieved by redirecting the handler to run in IRQ work context on the target CPU.
Quoted 7 lines
This patch was originally prepared by Thomas Gleixner (see Link tag below) in a patch series that was never submitted as is, and only parts of that series have made it upstream so far.
Originally-by Thomas Gleixner <[email protected]>Signed-off-by Radu Rendec <[email protected]>
I've been trying to bisect a suspend/resume regression on a Qualcomm SC7280 laptop (using arch/arm64/boot/dts/qcom/sc7280-herobrine-crd.dts), and unfortunately, it bisects to this:
eaf290c404f7c39f23292e9ce83b8b5b51ab598a is the first bad commit commit eaf290c404f7c39f23292e9ce83b8b5b51ab598a
Author: Radu Rendec <[email protected]> Date: Fri Nov 28 16:20:55 2025 -0500
PCI: dwc: Enable MSI affinity support
See the failure below [1]. Unfortunately, the logs don't give me an immediate lead.
It fails similarly on v7.1-r1 and v7.1-rc4, so even though I know there were a few bugfixes to the IRQ-redirect stuff already, I don't think they help my case.
I'll see if I can learn anything more here on my own, but I figured I'd report it in case you have any thoughts or leads I should investigate.
Regards,
Brian
[1]
[ 58.229764] Enabling non-boot CPUs ... [ 58.234065] Detected VIPT I-cache on CPU1 [ 58.234121] GICv3: CPU1: found redistributor 100 region 0:0x0000000017a80000 [ 58.234171] CPU1: Booted secondary processor 0x0000000100 [0x412fd050] [ 58.235038] CPU1 is up [ 58.255764] Detected VIPT I-cache on CPU2 [ 58.255801] GICv3: CPU2: found redistributor 200 region 0:0x0000000017aa0000 [ 58.255837] CPU2: Booted secondary processor 0x0000000200 [0x412fd050] [ 58.256394] CPU2 is up [ 58.277119] Detected VIPT I-cache on CPU3 [ 58.277155] GICv3: CPU3: found redistributor 300 region 0:0x0000000017ac0000 [ 58.277191] CPU3: Booted secondary processor 0x0000000300 [0x412fd050] [ 58.277824] CPU3 is up [ 58.299086] Detected PIPT I-cache on CPU4 [ 58.299104] GICv3: CPU4: found redistributor 400 region 0:0x0000000017ae0000 [ 58.299124] CPU4: Booted secondary processor 0x0000000400 [0x411fd411] [ 58.299437] CPU4 is up [ 58.320186] Detected PIPT I-cache on CPU5 [ 58.320205] GICv3: CPU5: found redistributor 500 region 0:0x0000000017b00000 [ 58.320224] CPU5: Booted secondary processor 0x0000000500 [0x411fd411] [ 58.320513] CPU5 is up [ 58.341154] Detected PIPT I-cache on CPU6 [ 58.341173] GICv3: CPU6: found redistributor 600 region 0:0x0000000017b20000 [ 58.341193] CPU6: Booted secondary processor 0x0000000600 [0x411fd411] [ 58.341481] CPU6 is up [ 58.362167] Detected PIPT I-cache on CPU7 [ 58.362186] GICv3: CPU7: found redistributor 700 region 0:0x0000000017b40000 [ 58.362206] CPU7: Booted secondary processor 0x0000000700 [0x411fd411] [ 58.362532] CPU7 is up [ 58.384442] nvme 0001:01:00.0: Unable to change power state from unknown to D0, device inaccessible [ 59.243847] onboard-usb-dev 4-1: reset high-speed USB device number 2 using xhci-hcd [ 59.492243] onboard-usb-dev 5-1: reset SuperSpeed USB device number 2 using xhci-hcd [ 68.875606] nvme 0001:01:00.0: PM: **** DPM device timeout **** [ 68.881728] Call trace: [ 68.884266] __switch_to+0x16c/0x188 (T) [ 68.888331] __schedule+0x7c4/0x98c [ 68.891939] schedule+0x38/0x60 [ 68.895196] schedule_timeout+0xf8/0x120 [ 68.899254] io_schedule_timeout+0x2c/0x4c [ 68.903481] __wait_for_common+0xd4/0x168 [ 68.907621] wait_for_completion_io_timeout+0x28/0x34 [ 68.912832] blk_execute_rq+0x138/0x164 [ 68.916792] nvme_execute_rq+0x20/0x54 [ 68.920665] __nvme_submit_sync_cmd+0xe0/0x128 [ 68.925258] nvme_features.isra.0+0x88/0xd4 [ 68.929580] nvme_set_features+0x34/0x40 [ 68.933638] nvme_resume+0x68/0x88 [ 68.937158] pci_pm_resume+0x88/0xfc [ 68.940849] dpm_run_callback+0x6c/0xec [ 68.944811] device_resume+0x194/0x270 [ 68.948683] async_resume+0x28/0x3c [ 68.952289] async_run_entry_fn+0x40/0x104 [ 68.956515] process_scheduled_works+0x210/0x320 [ 68.961277] worker_thread+0x14c/0x1ec [ 68.965147] kthread+0x154/0x1b8 [ 68.968486] ret_from_fork+0x10/0x20 [ 68.972192] Kernel panic - not syncing: nvme 0001:01:00.0: unrecoverable failure
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
(Updating Radu's email; dropping another bouncing email)
Quoted 2 lines · Brian Norris
I'll see if I can learn anything more here on my own, but I figured I'd report it in case you have any thoughts or leads I should investigate.
In an hour or two of poking, all I've learned so far is that the problem also seems to go away if I:
(a) add a few dump_stack() and other noisy logs to a few key places (for now, __pci_write_msi_msg(), pci_power_up() failures, and irq_chip_redirect_set_affinity() -- I think __pci_write_msi_msg() was the most significant, possibly because it produced the most log text) and
(b) leave a 115200 baud UART kernel console running.
(This is on a sample size of 20+ suspend cycles, whereas previous bisection would fail 100%.)
It then reappers when I quiet the kernel logging a bit with dmesg -n3.
I think that simply tells me that there's some timing issue or race condition involved.
Brian
Radu Rendec
reviewerRe: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Brian,
Quoted 1 line · Brian Norris
(Updating Radu's email; dropping another bouncing email)
Thanks for doing that! Obviously, I no longer have access to the email address that was used to post the patch, and I was lazy in setting up scripts that follow the mailing lists to catch messages that are addressed to me directly but using old email addresses.
Quoted 3 lines · Brian Norris
Quoted 2 lines
I'll see if I can learn anything more here on my own, but I figured I'd report it in case you have any thoughts or leads I should investigate.
Thanks for reporting it! I do not have any thoughts or leads yet, but I do plan to look at it during the next few days and hopefully come up with something. I also apologize for the slowness in my replies.
Quoted 11 lines
In an hour or two of poking, all I've learned so far is that the problem also seems to go away if I:
(a) add a few
dump_stack()and other noisy logs to a few key places (for now,__pci_write_msi_msg(),pci_power_up()failures, andirq_chip_redirect_set_affinity()-- I think__pci_write_msi_msg()was the most significant, possibly because it produced the most log text) and(b) leave a 115200 baud UART kernel console running.
Quoted 7 lines
(This is on a sample size of 20+ suspend cycles, whereas previous bisection would fail 100%.)
It then reappers when I quiet the kernel logging a bit with
dmesg -n3.I think that simply tells me that there's some timing issue or race condition involved.
That's very useful! Interrupts are migrated on suspend to the main CPU and then migrated back on resume, and the ordering and synchronization around that is tricky. The stack trace in your previous message tells me that the nvme driver is waiting for IO completion, which is normally signaled by an interrupt, except that interrupt never arrives.
With my patch included, the demultiplexed interrupt (the nvme interrupt in this case) has an opportunity to be migrated during suspend/resume, whereas previously it did not. That's one more moving part, and I'll have to look closer at the code and think what could go wrong. I agree it's likely a race condition or a timing issue because it works with that extra logging, which adds small delays as a side effect.
Regards,
Radu
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Hi Radu,
Quoted 7 lines · Radu Rendec
Quoted 1 line · Brian Norris
(Updating Radu's email; dropping another bouncing email)
Thanks for doing that! Obviously, I no longer have access to the email address that was used to post the patch, and I was lazy in setting up scripts that follow the mailing lists to catch messages that are addressed to me directly but using old email addresses.
No worries. The email bounce notified me rather quickly, and in the end, you saw this within a few hours of first report anyway :)
Quoted 7 lines
Quoted 3 lines · Brian Norris
Quoted 2 lines
I'll see if I can learn anything more here on my own, but I figured I'd report it in case you have any thoughts or leads I should investigate.
Thanks for reporting it! I do not have any thoughts or leads yet, but I do plan to look at it during the next few days and hopefully come up with something. I also apologize for the slowness in my replies.
I'm only getting occasional time to spend on this too, so I'm a bit slow as well.
Quoted 16 lines
Quoted 16 lines
In an hour or two of poking, all I've learned so far is that the problem also seems to go away if I:
(a) add a few
dump_stack()and other noisy logs to a few key places (for now,__pci_write_msi_msg(),pci_power_up()failures, andirq_chip_redirect_set_affinity()-- I think__pci_write_msi_msg()was the most significant, possibly because it produced the most log text) and(b) leave a 115200 baud UART kernel console running.
(This is on a sample size of 20+ suspend cycles, whereas previous bisection would fail 100%.)
It then reappers when I quiet the kernel logging a bit with
dmesg -n3.
Quoted 8 lines
Quoted 2 lines
I think that simply tells me that there's some timing issue or race condition involved.
That's very useful! Interrupts are migrated on suspend to the main CPU and then migrated back on resume, and the ordering and synchronization around that is tricky. The stack trace in your previous message tells me that the nvme driver is waiting for IO completion, which is normally signaled by an interrupt, except that interrupt never arrives.
That's true. But the first failure is:
nvme 0001:01:00.0: Unable to change power state from unknown to D0, device inaccessible
That means the PCI config read of the PM status register is returning all-0xff, so we're not really able to guarantee the NVMe PCIe device has powered back up at all. In my experience, that's indicative that the PCIe link has failed in some way, or the root complex is otherwise misbehaving. If the link is not functional, we won't receive any NVMe MSIs.
I still can't explain what about this patch is causing a PCIe link failure though.
Quoted 6 lines
With my patch included, the demultiplexed interrupt (the nvme interrupt in this case) has an opportunity to be migrated during suspend/resume, whereas previously it did not. That's one more moving part, and I'll have to look closer at the code and think what could go wrong. I agree it's likely a race condition or a timing issue because it works with that extra logging, which adds small delays as a side effect.
I also tried hot-unplugging all non-boot CPUs before suspending the system:
for i in /sys/devices/system/cpu/cpu{1,2,3,4,5,6,7}/online; do echo 1 > $i; done echo +10 > /sys/class/rtc/rtc0/wakealarm
echo mem > /sys/power/state
I believe that means all the affinity/migration will occur while the system is fully online, so we're less likely to run into power management race conditions. In this test, NVMe is still functional after the first step (CPU offline), but it still fails after suspend-to-mem.
This seems to tell me the irq_set_affinity()/migration process isn't really what's killing things, but something else.
Brian
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Quoted 3 lines · Brian Norris
This seems to tell me the irq_set_affinity()/migration process isn't really what's killing things, but something else.
Hello Brian,
Perhaps a long-shot, but have you tried to apply:
https://lore.kernel.org/linux-pci/[email protected]/
to see if it helps your problem?
https://lore.kernel.org/linux-pci/r247uuc7ilkhn65vcbsaoxhgypif37lj3r3mvb7ooqqdg55vnm@vx3ip6klg6ha/
also seems to mention a recent PSCI fix:
https://lore.kernel.org/all/[email protected]/
Which also sounds somewhat related.
Kind regards,
Niklas
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
(CC a few more)
Hi Niklas,
Quoted 9 lines · Niklas Cassel
Quoted 3 lines · Brian Norris
This seems to tell me the irq_set_affinity()/migration process isn't really what's killing things, but something else.
Hello Brian,
Perhaps a long-shot, but have you tried to apply:
https://lore.kernel.org/linux-pci/[email protected]/
For the record, that's:
[PATCH v2 0/4] PCI: Introduce pci_suspend_retains_context() API
Quoted 1 line
to see if it helps your problem?
It also seemed like a long-shot, but I tried it and it does resolve my problems. Maybe I can provide a Tested-by there.
Quoted 3 lines
https://lore.kernel.org/linux-pci/r247uuc7ilkhn65vcbsaoxhgypif37lj3r3mvb7ooqqdg55vnm@vx3ip6klg6ha/
also seems to mention a recent PSCI fix:
https://lore.kernel.org/all/[email protected]/
That's:
[PATCH] firmware: psci: Set pm_set_resume/suspend_via_firmware() for SYSTEM_SUSPEND
Quoted 1 line
Which also sounds somewhat related.
Yes, that looks somewhat related. I tried it, and it seems to resolve my issue as well.
It looks like Mani suggests both patch sets are valid proposals, although solving slightly different variations depending on the Qualcomm firmware in question? But the PSCI patch looks like it's stuck in /dev/null. Dunno if a Tested-by would help there too?
I'm also perplexed at why:
1) those patches claim that NVMe wasn't really working on Qcom systems before, and yet the laptop in question was working fine before v7.0; and
2) this bisected to commit eaf290c404f7 ("PCI: dwc: Enable MSI affinity support").
Anyway, thanks for the pointers.
Brian
Re: [PATCH v3 3/3] PCI: dwc: Enable MSI affinity support
Quoted 16 lines · Brian Norris
Quoted 2 lines
Perhaps a long-shot, but have you tried to apply:
https://lore.kernel.org/linux-pci/[email protected]/For the record, that's:
[PATCH v2 0/4] PCI: Introduce
pci_suspend_retains_context()APIQuoted 1 line
to see if it helps your problem?
It also seemed like a long-shot, but I tried it and it does resolve my problems. Maybe I can provide a Tested-by there.
Quoted 3 lines
https://lore.kernel.org/linux-pci/r247uuc7ilkhn65vcbsaoxhgypif37lj3r3mvb7ooqqdg55vnm@vx3ip6klg6ha/
also seems to mention a recent PSCI fix:
https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
That's:
[PATCH] firmware: psci: Set pm_set_resume/suspend_via_firmware() forSYSTEM_SUSPENDQuoted 1 line
Which also sounds somewhat related.
Yes, that looks somewhat related. I tried it, and it seems to resolve my issue as well.
Oh, nice, I see that this was already applied to pci/next for v7.2. I had already tested pci/next, but as luck would have it, I had pulled it a day before Bjorn Helgaas applied the series.
I can't imagine this is a linux-stable candidate though, as it appears to be a bit more of a "new feature" thing. I'm still stuck wondering how this showed up as a regression for me.
Brian