igb: fix igb_msix_other() handling for PREEMPT_RT
Subsystems (4)
cover igb: fix igb_msix_other() handling for PREEMPT_RT
This is the second attempt at fixing the behavior of igb_msix_other() for PREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].
The initial approach proposed converting vfs_lock to a raw_spinlock, a minor change intended to make it safe. However, it became evident that igb_rcv_msg_from_vf() invokes kcalloc with GFP_ATOMIC, which is unsafe in interrupt context on PREEMPT_RT systems.
To address this, the solution involves splitting igb_msg_task() into two parts:
* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.
To accommodate this, vfs_lock has been restructured into a double
lock: a spinlock_t and a raw_spinlock_t. In the revised design:
* igb_disable_sriov() locks both spinlocks.
* Each part of igb_msg_task() locks the appropriate spinlock for its execution context.
It is worth noting that the double lock mechanism is only active under PREEMPT_RT. For non-PREEMPT_RT builds, the additional raw_spinlock_t field is ommited.
If the extra raw_spinlock_t field can be tolerated under !PREEMPT_RT (even though it remains unused), we can eliminate the need for #ifdefs and simplify the code structure.
I will be on vacation from December 7th to Christmas and will address review comments upon my return.
If possible, I kindly request the Intel team to perform smoke tests on both stock and realtime kernels to catch any potential issues with this patch series.
Cheers,
Wander
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Wander Lairson Costa (4):
igb: narrow scope of vfs_lock in SR-IOV cleanup
igb: introduce raw vfs_lock to igb_adapter
igb: split igb_msg_task()
igb: fix igb_msix_other() handling for PREEMPT_RT
drivers/net/ethernet/intel/igb/igb.h | 4 + drivers/net/ethernet/intel/igb/igb_main.c | 160 +++++++++++++++++++--- 2 files changed, 148 insertions(+), 16 deletions(-)
Signature · 1 line
2.47.0
PATCH 1/4 igb: narrow scope of vfs_lock in SR-IOV cleanup
The adapter->vfs_lock currently protects critical sections shared between igb_disable_sriov() and igb_msg_task(). Since igb_msg_task() — which is invoked solely by the igb_msix_other() ISR—only proceeds when adapter->vfs_allocated_count > 0, we can reduce the lock scope further.
By moving the assignment adapter->vfs_allocated_count = 0 to the start of the cleanup code in igb_disable_sriov(), we can restrict the spinlock protection solely to this assignment. This change removes kfree() calls from within the locked section, simplifying lock management.
Once kfree() is outside the vfs_lock scope, it becomes possible to safely convert vfs_lock to a raw_spin_lock.
--- drivers/net/ethernet/intel/igb/igb_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +2 -2
@@ -3708,12 +3708,12 @@ static int igb_disable_sriov(struct pci_dev *pdev, bool reinit)msleep (500 ); }spin_lock_irqsave (&adapter->vfs_lock, flags); + adapter->vfs_allocated_count =0 ; +spin_unlock_irqrestore (&adapter->vfs_lock, flags);kfree (adapter->vf_mac_list); adapter->vf_mac_list =NULL ;kfree (adapter->vf_data); adapter->vf_data =NULL ; - adapter->vfs_allocated_count =0 ; -spin_unlock_irqrestore (&adapter->vfs_lock, flags);wr32 (E1000_IOVCTL ,E1000_IOVCTL_REUSE_VFQ );wrfl ();msleep (100 );
Signature · 1 line
2.47.0
PATCH 2/4 igb: introduce raw vfs_lock to igb_adapter
In reply to Wander Lairson CostaThis change adds a raw_spinlock for the vfs_lock to the igb_adapter structure, enabling its use in both interrupt and preemptible contexts. This is essential for upcoming modifications to split igb_msg_task() into interrupt-safe and preemptible-safe parts.
The motivation for this change stems from the need to modify igb_msix_other() to run in interrupt context under PREEMPT_RT. Currently, igb_msg_task() contains a code path that invokes kcalloc() with the GFP_ATOMIC flag. However, on PREEMPT_RT, GFP_ATOMIC is not honored, making it unsafe to call allocation functions in interrupt context. By introducing this raw spinlock, we can safely acquire the lock in both contexts, paving the way for the necessary restructuring of igb_msg_task().
--- drivers/net/ethernet/intel/igb/igb.h | 4 ++ drivers/net/ethernet/intel/igb/igb_main.c | 51 ++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +4 -0
@@ -666,6 +666,10 @@ struct igb_adapter {struct vf_mac_filter *vf_mac_list;/* lock for VF resources */ spinlock_t vfs_lock; +#ifdef CONFIG_PREEMPT_RT +/* Used to lock VFS in interrupt context under PREEMPT_RT */ +raw_spinlock_t raw_vfs_lock; +#endif };/* flags controlling PTP/1588 function */
drivers/net/ethernet/intel/igb/igb_main.c +46 -5
82 lines not on this page · raw message
Signature · 1 line
2.47.0
PATCH 3/4 igb: split igb_msg_task()
In reply to Wander Lairson CostaFrom the perspective of PREEMPT_RT, igb_msg_task() invokes functions that are a mix of IRQ-safe and non-IRQ-safe operations.
To address this, we separate igb_msg_task() into distinct IRQ-safe and preemptible-safe components. This is a preparatory step for upcoming commits, where the igb_msix_other interrupt handler will be split into IRQ and threaded handlers, each invoking the appropriate part of the newly divided igb_msg_task().
--- drivers/net/ethernet/intel/igb/igb_main.c | 88 +++++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +81 -7
@@ -149,6 +149,8 @@ static int igb_vlan_rx_kill_vid(struct net_device *, __be16, u16);static void igb_restore_vlan (struct igb_adapter *);static void igb_rar_set_index (struct igb_adapter *,u32 );static void igb_ping_all_vfs (struct igb_adapter *); +static void igb_msg_task_irq_safe (struct igb_adapter *adapter); +static void igb_msg_task_preemptible_safe (struct igb_adapter *adapter);static void igb_msg_task (struct igb_adapter *);static void igb_vmm_control (struct igb_adapter *);static int igb_set_vf_mac (struct igb_adapter *,int ,unsigned char *);
@@ -3681,6 +3683,30 @@ static __always_inline void vfs_unlock_irqrestore(struct igb_adapter *adapter,raw_spin_unlock_irqrestore (&adapter->raw_vfs_lock, flags);spin_unlock_irqrestore (&adapter->vfs_lock, flags); } + +static __always_inline void vfs_spin_lock_irqsave(struct igb_adapter *adapter, +unsigned long *flags) +{ +spin_lock_irqsave (&adapter->vfs_lock, *flags); +} + +static __always_inline void vfs_spin_unlock_irqrestore(struct igb_adapter *adapter, +unsigned long flags) +{ +spin_unlock_irqrestore (&adapter->vfs_lock, flags); +} + +static __always_inline void vfs_raw_spin_lock_irqsave(struct igb_adapter *adapter, +unsigned long *flags) +{ +raw_spin_lock_irqsave (&adapter->raw_vfs_lock, *flags); +} + +static __always_inline void vfs_raw_spin_unlock_irqrestore(struct igb_adapter *adapter, +unsigned long flags) +{ +raw_spin_unlock_irqrestore (&adapter->raw_vfs_lock, flags); +}#else static __always_inline void vfs_lock_init(struct igb_adapter *adapter) {
@@ -3696,6 +3722,30 @@ static __always_inline void vfs_unlock_irqrestore(struct igb_adapter *adapter, u {spin_unlock_irqrestore (&adapter->vfs_lock, flags); } + +static __always_inline void vfs_spin_lock_irqsave(struct igb_adapter *adapter, +unsigned long *flags) +{ +spin_lock_irqsave (&adapter->vfs_lock, *flags); +} + +static __always_inline void vfs_spin_unlock_irqrestore(struct igb_adapter *adapter, +unsigned long flags) +{ +spin_unlock_irqrestore (&adapter->vfs_lock, flags); +} + +static __always_inline void vfs_raw_spin_lock_irqsave(struct igb_adapter *adapter, +unsigned long *flags) +{ +spin_lock_irqsave (&adapter->vfs_lock, *flags); +} + +static __always_inline void vfs_raw_spin_unlock_irqrestore(struct igb_adapter *adapter, +unsigned long flags) +{ +spin_unlock_irqrestore (&adapter->vfs_lock, flags); +}#endif #ifdef CONFIG_PCI_IOV
@@ -8070,27 +8120,51 @@ static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)igb_unlock_mbx (hw, vf); } -static void igb_msg_task (struct igb_adapter *adapter) +/* +* Note: the split of irq and preempible safe parts of igb_msg_task() +* only makes sense under PREEMPT_RT. +* The root cause of igb_rcv_msg_from_vf() is not IRQ safe is because +* it calls kcalloc with GFP_ATOMIC, but GFP_ATOMIC is not IRQ safe +* in PREEMPT_RT. +*/ +static void igb_msg_task_irq_safe (struct igb_adapter *adapter) {struct e1000_hw *hw = &adapter->hw;unsigned long flags;u32 vf; -vfs_lock_irqsave (adapter, &flags); +vfs_raw_spin_lock_irqsave (adapter, &flags);for (vf =0 ; vf < adapter->vfs_allocated_count; vf++) {/* process any reset requests */ if (!igb_check_for_rst (hw, vf))igb_vf_reset_event (adapter, vf); -/* process any messages pending */ -if (!igb_check_for_msg (hw, vf)) -igb_rcv_msg_from_vf (adapter, vf); -/* process any acks */ if (!igb_check_for_ack (hw, vf))igb_rcv_ack_from_vf (adapter, vf); } -vfs_unlock_irqrestore (adapter, flags); +vfs_raw_spin_unlock_irqrestore (adapter, flags); +} + +static void igb_msg_task_preemptible_safe (struct igb_adapter *adapter) +{ +struct e1000_hw *hw = &adapter->hw; +unsigned long flags; +u32 vf; + +vfs_spin_lock_irqsave (adapter, &flags); +for (vf =0 ; vf < adapter->vfs_allocated_count; vf++) { +/* process any messages pending */ +if (!igb_check_for_msg (hw, vf)) +igb_rcv_msg_from_vf (adapter, vf); + } +vfs_spin_unlock_irqrestore (adapter, flags); +} + +static __always_inline void igb_msg_task(struct igb_adapter *adapter) +{ +igb_msg_task_irq_safe (adapter); +igb_msg_task_preemptible_safe (adapter); }/**
Signature · 1 line
2.47.0
PATCH 4/4 igb: fix igb_msix_other() handling for PREEMPT_RT
In reply to Wander Lairson CostaDuring testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the PREEMPT_RT variant. Investigation revealed that e1000_write_posted_mbx returns an error due to the lack of an ACK from e1000_poll_for_ack.
The underlying issue arises from the fact that IRQs are threaded by default under PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled by igb_msix_other must be processed before e1000_poll_for_ack times out. However, e1000_write_posted_mbx is called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure of e1000_write_posted_mbx.
Commit 338c4d3902fe ("igb: Disable threaded IRQ for igb_msix_other") forced the ISR to run in a non-threaded context. However, Sebastian observed that some functions called within the ISR acquire locks that may sleep.
In the previous two patches, we managed to make igb_msg_mask() safe to call from an interrupt context.
In this commit, we move most of the ISR handling to an interrupt context, leaving non IRQ safe code to be called from the thread context under PREEMPT_RT.
Reproducer:
ipaddr_vlan=3
nic_test=ens14f0
vf=${nic_test}v0 # The main testing steps:
while true; do
ip link set ${nic_test} mtu 1500
ip link set ${vf} mtu 1500
ip link set $vf up
# 3. set vlan and ip for VF
ip link set ${nic_test} vf 0 vlan ${ipaddr_vlan} ip addr add 172.30.${ipaddr_vlan}.1/24 dev ${vf} ip addr add 2021:db8:${ipaddr_vlan}::1/64 dev ${vf} # 4. check the link state for VF and PF
ip link show ${nic_test}
if ! ip link show $vf | grep 'state UP'; then
echo 'Error found'
break
fi
ip link set $vf down
done
You can also reproduce it more reliably by setting nr_cpus=1 in the kernel command line.
--- drivers/net/ethernet/intel/igb/igb_main.c | 35 ++++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +24 -11
@@ -131,6 +131,7 @@ static void igb_set_uta(struct igb_adapter *adapter, bool set);static irqreturn_t igb_intr (int irq,void *);static irqreturn_t igb_intr_msi (int irq,void *);static irqreturn_t igb_msix_other (int irq,void *); +static irqreturn_t igb_msix_other_threaded (int irq,void *);static irqreturn_t igb_msix_ring (int irq,void *);#ifdef CONFIG_IGB_DCA static void igb_update_dca (struct igb_q_vector *);
@@ -151,7 +152,6 @@ static void igb_rar_set_index(struct igb_adapter *, u32);static void igb_ping_all_vfs (struct igb_adapter *);static void igb_msg_task_irq_safe (struct igb_adapter *adapter);static void igb_msg_task_preemptible_safe (struct igb_adapter *adapter); -static void igb_msg_task (struct igb_adapter *);static void igb_vmm_control (struct igb_adapter *);static int igb_set_vf_mac (struct igb_adapter *,int ,unsigned char *);static void igb_flush_mac_table (struct igb_adapter *);
@@ -908,8 +908,9 @@ static int igb_request_msix(struct igb_adapter *adapter)struct net_device *netdev = adapter->netdev;int i, err =0 , vector =0 , free_vector =0 ; - err =request_irq (adapter->msix_entries[vector].vector, - igb_msix_other,0 , netdev->name, adapter); + err =request_threaded_irq (adapter->msix_entries[vector].vector, + igb_msix_other, igb_msix_other_threaded, +IRQF_NO_THREAD , netdev->name, adapter);if (err) goto err_out;
@@ -7113,9 +7114,27 @@ static irqreturn_t igb_msix_other(int irq, void *data)igb_check_wvbr (adapter); } -/* Check for a mailbox event */ +/* Check for a mailbox event (interrupt safe part) */ if (icr &E1000_ICR_VMMB ) -igb_msg_task (adapter); +igb_msg_task_irq_safe (adapter); + + adapter->test_icr = icr; + +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) +return igb_msix_other_threaded (irq, data); + +return IRQ_WAKE_THREAD ; +} + +static irqreturn_t igb_msix_other_threaded (int irq,void *data) +{ +struct igb_adapter *adapter = data; +struct e1000_hw *hw = &adapter->hw; +u32 icr = adapter->test_icr; + +/* Check for a mailbox event (preempible safe part) */ +if (icr &E1000_ICR_VMMB ) +igb_msg_task_preemptible_safe (adapter);if (icr &E1000_ICR_LSC ) { hw->mac.get_link_status =1 ;
@@ -8161,12 +8180,6 @@ static void igb_msg_task_preemptible_safe(struct igb_adapter *adapter)vfs_spin_unlock_irqrestore (adapter, flags); } -static __always_inline void igb_msg_task(struct igb_adapter *adapter) -{ -igb_msg_task_irq_safe (adapter); -igb_msg_task_preemptible_safe (adapter); -} -/** * igb_set_uta - Set unicast filter table address * @adapter: board private structure
Signature · 1 line
2.47.0
Quoted 52 lines · Wander Lairson Costa
This is the second attempt at fixing the behavior of
igb_msix_other()forPREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].The initial approach proposed converting
vfs_lockto araw_spinlock, a minor change intended to make it safe. However, it became evident thatigb_rcv_msg_from_vf()invokes kcalloc withGFP_ATOMIC, which is unsafe in interrupt context onPREEMPT_RTsystems.To address this, the solution involves splitting
igb_msg_task()into two parts:* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.To accommodate this,
vfs_lockhas been restructured into a double
lock: aspinlock_tand araw_spinlock_t. In the revised design:*
igb_disable_sriov()locks both spinlocks.
* Each part ofigb_msg_task()locks the appropriate spinlock for its execution context.It is worth noting that the double lock mechanism is only active under
PREEMPT_RT. For non-PREEMPT_RT builds, the additionalraw_spinlock_tfield is ommited.If the extra
raw_spinlock_tfield can be tolerated under !PREEMPT_RT (even though it remains unused), we can eliminate the need for #ifdefs and simplify the code structure.I will be on vacation from December 7th to Christmas and will address review comments upon my return.
If possible, I kindly request the Intel team to perform smoke tests on both stock and realtime kernels to catch any potential issues with this patch series.
Cheers,
Wander[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/Wander Lairson Costa (4):
igb: narrow scope ofvfs_lockin SR-IOV cleanup
igb: introduce rawvfs_locktoigb_adapter
igb: splitigb_msg_task()
igb: fixigb_msix_other()handling forPREEMPT_RT
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb.h | 4 + drivers/net/ethernet/intel/igb/igb_main.c | 160 +++++++++++++++++++--- 2 files changed, 148 insertions(+), 16 deletions(-)--
2.47.0
I had requested Red Hat Network QA to run regression tests on this, and they recently reported that no issues were found.
RE: [Intel-wired-lan] [PATCH iwl-net 1/4] igb: narrow scope of vfs_lock in SR-IOV cleanup
In reply to Wander Lairson Costadrivers/net/ethernet/intel/igb/igb_main.c static int igb_disable_sriov(struct pci_dev *pdev,
Quoted 43 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Wander Lairson Costa
Sent: Wednesday, December 4, 2024 12:42 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; Clark Williams <[email protected]>; Steven Rostedt <[email protected]>; Auke Kok <[email protected]>; Jeff Garzik <[email protected]>; moderated list:INTEL ETHERNET DRIVERS <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>; open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT <[email protected]>
Cc: Wander Lairson Costa <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 1/4] igb: narrow scope ofvfs_lockin SR- IOV cleanupThe
adapter->vfs_lockcurrently protects critical sections shared betweenigb_disable_sriov()andigb_msg_task(). Sinceigb_msg_task()— which is invoked solely by theigb_msix_other()ISR—only proceeds whenadapter->vfs_allocated_count> 0, we can reduce the lock scope further.By moving the assignment
adapter->vfs_allocated_count= 0 to the start of the cleanup code inigb_disable_sriov(), we can restrict the spinlock protection solely to this assignment. This change removeskfree()calls from within the locked section, simplifying lock management.Once
kfree()is outside thevfs_lockscope, it becomes possible to safely convertvfs_lockto araw_spin_lock.Signed-off-by Wander Lairson Costa <[email protected]>--- drivers/net/ethernet/intel/igb/igb_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/igb_main.c +0
-0@@ -3708,12 +3708,12 @@ static int igb_disable_sriov(struct pci_dev *pdev,
RE: [Intel-wired-lan] [PATCH iwl-net 2/4] igb: introduce raw vfs_lock to igb_adapter
In reply to Wander Lairson Costadrivers/net/ethernet/intel/igb/igb.h struct igb_adapter {
Quoted 46 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Wander Lairson Costa
Sent: Wednesday, December 4, 2024 12:42 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; Clark Williams <[email protected]>; Steven Rostedt <[email protected]>; Jeff Garzik <[email protected]>; Auke Kok <[email protected]>; moderated list:INTEL ETHERNET DRIVERS <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>; open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT <[email protected]>
Cc: Wander Lairson Costa <[email protected]>; Clark Williams <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 2/4] igb: introduce rawvfs_locktoigb_adapterThis change adds a
raw_spinlockfor thevfs_lockto theigb_adapterstructure, enabling its use in both interrupt and preemptible contexts. This is essential for upcoming modifications to splitigb_msg_task()into interrupt-safe and preemptible-safe parts.The motivation for this change stems from the need to modify
igb_msix_other()to run in interrupt context underPREEMPT_RT. Currently,igb_msg_task()contains a code path that invokeskcalloc()with theGFP_ATOMICflag. However, onPREEMPT_RT,GFP_ATOMICis not honored, making it unsafe to call allocation functions in interrupt context. By introducing this raw spinlock, we can safely acquire the lock in both contexts, paving the way for the necessary restructuring ofigb_msg_task().Signed-off-by Wander Lairson Costa <[email protected]>Suggested-by Clark Williams <[email protected]>--- drivers/net/ethernet/intel/igb/igb.h | 4 ++ drivers/net/ethernet/intel/igb/igb_main.c | 51 ++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/igb/igb.h +0
-0@@ -666,6 +666,10 @@ struct igb_adapter {
RE: [Intel-wired-lan] [PATCH iwl-net 3/4] igb: split igb_msg_task()
In reply to Wander Lairson Costadrivers/net/ethernet/intel/igb/igb_main.c static int igb_vlan_rx_kill_vid(struct net_device *,
Quoted 37 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Wander Lairson Costa
Sent: Wednesday, December 4, 2024 12:42 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; Clark Williams <[email protected]>; Steven Rostedt <[email protected]>; Auke Kok <[email protected]>; Jeff Garzik <[email protected]>; moderated list:INTEL ETHERNET DRIVERS <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>; open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT <[email protected]>
Cc: Wander Lairson Costa <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 3/4] igb: splitigb_msg_task()From the perspective of
PREEMPT_RT,igb_msg_task()invokes functions that are a mix of IRQ-safe and non-IRQ-safe operations.To address this, we separate
igb_msg_task()into distinct IRQ-safe and preemptible-safe components. This is a preparatory step for upcoming commits, where theigb_msix_otherinterrupt handler will be split into IRQ and threaded handlers, each invoking the appropriate part of the newly dividedigb_msg_task().Signed-off-by Wander Lairson Costa <[email protected]>--- drivers/net/ethernet/intel/igb/igb_main.c | 88 +++++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-)drivers/net/ethernet/intel/igb/igb_main.c +0
-0@@ -149,6 +149,8 @@ static int igb_vlan_rx_kill_vid(struct net_device *,
drivers/net/ethernet/intel/igb/igb_main.c static void igb_set_uta(struct igb_adapter *adapter, bool
Quoted 80 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Wander Lairson Costa
Sent: Wednesday, December 4, 2024 12:42 PM
To: Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; Clark Williams <[email protected]>; Steven Rostedt <[email protected]>; Auke Kok <[email protected]>; Jeff Garzik <[email protected]>; moderated list:INTEL ETHERNET DRIVERS <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>; open list:Real-time Linux (PREEMPT_RT):Keyword:PREEMPT_RT <[email protected]>
Cc: Wander Lairson Costa <[email protected]>; Yuying Ma <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net 4/4] igb: fixigb_msix_other()handling forPREEMPT_RTDuring testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the
PREEMPT_RTvariant. Investigation revealed thate1000_write_posted_mbxreturns an error due to the lack of an ACK frome1000_poll_for_ack.The underlying issue arises from the fact that IRQs are threaded by default under
PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled byigb_msix_othermust be processed beforee1000_poll_for_acktimes out. However,e1000_write_posted_mbxis called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure ofe1000_write_posted_mbx.Commit
338c4d3902fe("igb: Disable threaded IRQ forigb_msix_other") forced the ISR to run in a non-threaded context. However, Sebastian observed that some functions called within the ISR acquire locks that may sleep.In the previous two patches, we managed to make
igb_msg_mask()safe to call from an interrupt context.In this commit, we move most of the ISR handling to an interrupt context, leaving non IRQ safe code to be called from the thread context under
PREEMPT_RT.Reproducer:
ipaddr_vlan=3
nic_test=ens14f0
vf=${nic_test}v0 # The main testing steps:
while true; do
ip link set ${nic_test} mtu 1500
ip link set ${vf} mtu 1500
ip link set $vf up
# 3. set vlan and ip for VF
ip link set ${nic_test} vf 0 vlan ${ipaddr_vlan} ip addr add 172.30.${ipaddr_vlan}.1/24 dev ${vf} ip addr add 2021:db8:${ipaddr_vlan}::1/64 dev ${vf} # 4. check the link state for VF and PF
ip link show ${nic_test}
if ! ip link show $vf | grep 'state UP'; then
echo 'Error found'
break
fi
ip link set $vf down
doneYou can also reproduce it more reliably by setting nr_cpus=1 in the kernel command line.
Fixes 9d5c824399de ("igb: PCI-Express 82575 Gigabit Ethernet driver")Signed-off-by Wander Lairson Costa <[email protected]>Reported-by Yuying Ma <[email protected]>--- drivers/net/ethernet/intel/igb/igb_main.c | 35 ++++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-)drivers/net/ethernet/intel/igb/igb_main.c +0
-0@@ -131,6 +131,7 @@ static void igb_set_uta(struct igb_adapter *adapter, bool
Sebastian Andrzej Siewior
maintainerQuoted 15 lines · Wander Lairson Costa
This is the second attempt at fixing the behavior of
igb_msix_other()forPREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].The initial approach proposed converting
vfs_lockto araw_spinlock, a minor change intended to make it safe. However, it became evident thatigb_rcv_msg_from_vf()invokes kcalloc withGFP_ATOMIC, which is unsafe in interrupt context onPREEMPT_RTsystems.To address this, the solution involves splitting
igb_msg_task()into two parts:* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.
Quoted 6 lines
To accommodate this,
vfs_lockhas been restructured into a double
lock: aspinlock_tand araw_spinlock_t. In the revised design:*
igb_disable_sriov()locks both spinlocks.
* Each part ofigb_msg_task()locks the appropriate spinlock for its execution context.
- Is this limited to PREEMPT_RT or does it also occur on PREEMPT systems with threadirqs? And if this is PREEMPT_RT only, why?
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
Quoted 2 lines
Cheers,
Wander
Sebastian
Quoted 19 lines · Sebastian Andrzej Siewior
Quoted 18 lines · Wander Lairson Costa
This is the second attempt at fixing the behavior of
igb_msix_other()forPREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].The initial approach proposed converting
vfs_lockto araw_spinlock, a minor change intended to make it safe. However, it became evident thatigb_rcv_msg_from_vf()invokes kcalloc withGFP_ATOMIC, which is unsafe in interrupt context onPREEMPT_RTsystems.To address this, the solution involves splitting
igb_msg_task()into two parts:* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.To accommodate this,
vfs_lockhas been restructured into a double
lock: aspinlock_tand araw_spinlock_t. In the revised design:
Quoted 6 lines
Quoted 3 lines
*
igb_disable_sriov()locks both spinlocks.
* Each part ofigb_msg_task()locks the appropriate spinlock for its execution context.- Is this limited to
PREEMPT_RTor does it also occur on PREEMPT systems with threadirqs? And if this isPREEMPT_RTonly, why?
PREEMPT systems configured to use threadirqs should be affected as well, although I never tested with this configuration. Honestly, until now I wasn't aware of the possibility of a non PREEMPT_RT kernel with threaded IRQs by default.
Quoted 6 lines
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
I explained the root cause of the issue in the last commit. Maybe I should have added the explanation to the cover letter as well. Anyway, here is a partial verbatim copy of it:
"During testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the PREEMPT_RT variant. Investigation revealed that e1000_write_posted_mbx returns an error due to the lack of an ACK from e1000_poll_for_ack.
The underlying issue arises from the fact that IRQs are threaded by default under PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled by igb_msix_other must be processed before e1000_poll_for_ack times out. However, e1000_write_posted_mbx is called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure of e1000_write_posted_mbx."
The call chain from igb_msg_task():
igb_msg_task
igb_rcv_msg_from_vf
igb_set_vf_multicasts
igb_set_rx_mode
igb_write_mc_addr_list
kmalloc
Cannot happen from interrupt context under PREEMPT_RT. So this part of the interrupt handler is deferred to a threaded IRQ handler.
Quoted 5 lines
Quoted 2 lines
Cheers,
WanderSebastian
Sebastian Andrzej Siewior
maintainerQuoted 24 lines · Wander Lairson Costa
Quoted 23 lines · Sebastian Andrzej Siewior
Quoted 21 lines · Wander Lairson Costa
This is the second attempt at fixing the behavior of
igb_msix_other()forPREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].The initial approach proposed converting
vfs_lockto araw_spinlock, a minor change intended to make it safe. However, it became evident thatigb_rcv_msg_from_vf()invokes kcalloc withGFP_ATOMIC, which is unsafe in interrupt context onPREEMPT_RTsystems.To address this, the solution involves splitting
igb_msg_task()into two parts:* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.To accommodate this,
vfs_lockhas been restructured into a double
lock: aspinlock_tand araw_spinlock_t. In the revised design:*
igb_disable_sriov()locks both spinlocks.
* Each part ofigb_msg_task()locks the appropriate spinlock for its execution context.
Quoted 6 lines
Quoted 2 lines
- Is this limited to
PREEMPT_RTor does it also occur on PREEMPT systems with threadirqs? And if this isPREEMPT_RTonly, why?PREEMPT systems configured to use threadirqs should be affected as well, although I never tested with this configuration. Honestly, until now I wasn't aware of the possibility of a non
PREEMPT_RTkernel with threaded IRQs by default.
If the issue is indeed the use of threaded interrupts then the fix should not be limited to be PREEMPT_RT only.
Quoted 10 lines
Quoted 5 lines
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
I explained the root cause of the issue in the last commit. Maybe I should have added the explanation to the cover letter as well. Anyway, here is a partial verbatim copy of it:
Quoted 5 lines
"During testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the
PREEMPT_RTvariant. Investigation revealed thate1000_write_posted_mbxreturns an error due to the lack of an ACK frome1000_poll_for_ack.
That ACK would have come if it would poll longer?
Quoted 7 lines
The underlying issue arises from the fact that IRQs are threaded by default under
PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled byigb_msix_othermust be processed beforee1000_poll_for_acktimes out. However,e1000_write_posted_mbxis called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure ofe1000_write_posted_mbx."
Where is this disabled preemption coming from? This should be one of the ops.write_posted() calls, right? I've been looking around and don't see anything obvious.
Couldn't you wait for an event instead of polling?
Quoted 9 lines
The call chain from
igb_msg_task():
igb_msg_task
igb_rcv_msg_from_vf
igb_set_vf_multicasts
igb_set_rx_mode
igb_write_mc_addr_list
kmalloc
Quoted 5 lines
Cannot happen from interrupt context under
PREEMPT_RT. So this part of the interrupt handler is deferred to a threaded IRQ handler.Quoted 2 lines
Quoted 2 lines
Cheers,
Wander
Sebastian
Quoted 29 lines · Sebastian Andrzej Siewior
Quoted 27 lines · Wander Lairson Costa
Quoted 25 lines · Sebastian Andrzej Siewior
Quoted 15 lines · Wander Lairson Costa
This is the second attempt at fixing the behavior of
igb_msix_other()forPREEMPT_RT. The previous attempt [1] was reverted [2] following concerns raised by Sebastian [3].The initial approach proposed converting
vfs_lockto araw_spinlock, a minor change intended to make it safe. However, it became evident thatigb_rcv_msg_from_vf()invokes kcalloc withGFP_ATOMIC, which is unsafe in interrupt context onPREEMPT_RTsystems.To address this, the solution involves splitting
igb_msg_task()into two parts:* One part invoked from the IRQ context.
* Another part called from the threaded interrupt handler.Quoted 6 lines
To accommodate this,
vfs_lockhas been restructured into a double
lock: aspinlock_tand araw_spinlock_t. In the revised design:*
igb_disable_sriov()locks both spinlocks.
* Each part ofigb_msg_task()locks the appropriate spinlock for its execution context.- Is this limited to
PREEMPT_RTor does it also occur on PREEMPT systems with threadirqs? And if this isPREEMPT_RTonly, why?
Quoted 7 lines
Quoted 3 lines
PREEMPT systems configured to use threadirqs should be affected as well, although I never tested with this configuration. Honestly, until now I wasn't aware of the possibility of a non
PREEMPT_RTkernel with threaded IRQs by default.If the issue is indeed the use of threaded interrupts then the fix should not be limited to be
PREEMPT_RTonly.
Although I was not aware of this scenario, the patch should work for it as well, as I am forcing it to run in interrupt context. I will test it to confirm.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
I explained the root cause of the issue in the last commit. Maybe I should have added the explanation to the cover letter as well. Anyway, here is a partial verbatim copy of it:
Quoted 8 lines
Quoted 5 lines
"During testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the
PREEMPT_RTvariant. Investigation revealed thate1000_write_posted_mbxreturns an error due to the lack of an ACK frome1000_poll_for_ack.That ACK would have come if it would poll longer?
No, the service wouldn't be serviced while polling.
Quoted 11 lines
Quoted 7 lines
The underlying issue arises from the fact that IRQs are threaded by default under
PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled byigb_msix_othermust be processed beforee1000_poll_for_acktimes out. However,e1000_write_posted_mbxis called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure ofe1000_write_posted_mbx."Where is this disabled preemption coming from? This should be one of the
ops.write_posted()calls, right? I've been looking around and don't see anything obvious.
I don't remember if I found the answer by looking at the code or by looking at the ftrace flags.
I am currently on sick leave with covid. I can check it when I come back.
Quoted 19 lines
Couldn't you wait for an event instead of polling?
Quoted 9 lines
The call chain from
igb_msg_task():
igb_msg_task
igb_rcv_msg_from_vf
igb_set_vf_multicasts
igb_set_rx_mode
igb_write_mc_addr_list
kmallocQuoted 5 lines
Cannot happen from interrupt context under
PREEMPT_RT. So this part of the interrupt handler is deferred to a threaded IRQ handler.Quoted 2 lines
Quoted 2 lines
Cheers,
WanderSebastian
Sebastian Andrzej Siewior
maintainerQuoted 5 lines · Wander Lairson Costa
Quoted 3 lines
If the issue is indeed the use of threaded interrupts then the fix should not be limited to be
PREEMPT_RTonly.Although I was not aware of this scenario, the patch should work for it as well, as I am forcing it to run in interrupt context. I will test it to confirm.
If I remember correctly there were "ifdef preempt_rt" things in it.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 5 lines
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
I explained the root cause of the issue in the last commit. Maybe I should have added the explanation to the cover letter as well. Anyway, here is a partial verbatim copy of it:
"During testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the
PREEMPT_RTvariant. Investigation revealed thate1000_write_posted_mbxreturns an error due to the lack of an ACK frome1000_poll_for_ack.
Quoted 3 lines
Quoted 2 lines
That ACK would have come if it would poll longer?
No, the service wouldn't be serviced while polling.
Hmm.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
The underlying issue arises from the fact that IRQs are threaded by default under
PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled byigb_msix_othermust be processed beforee1000_poll_for_acktimes out. However,e1000_write_posted_mbxis called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure ofe1000_write_posted_mbx."
Quoted 7 lines
Quoted 3 lines
Where is this disabled preemption coming from? This should be one of the
ops.write_posted()calls, right? I've been looking around and don't see anything obvious.I don't remember if I found the answer by looking at the code or by looking at the ftrace flags.
I am currently on sick leave with covid. I can check it when I come back.
Don't worry, get better first. I'm kind of off myself. I'm not sure if I have the hardware needed to setup so I can look at it…
Sebastian
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Wander Lairson Costa
Quoted 3 lines
If the issue is indeed the use of threaded interrupts then the fix should not be limited to be
PREEMPT_RTonly.Although I was not aware of this scenario, the patch should work for it as well, as I am forcing it to run in interrupt context. I will test it to confirm.
I tested with the stock kernel with threadirqs and the problem does show up. Applying the patches the issue is gone.
Quoted 2 lines
If I remember correctly there were "ifdef
preempt_rt" things in it.
That exists only to handle the case in which part in which the ISR needs to partially run in thread context (because the piece of code calling kmalloc), so I need an sleeping lock for that. For non-PREEMPT_RT, we don't have this constrain.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
- What causes the failure? I see you reworked into two parts to behave similar to what happens without threaded interrupts. There is still no explanation for it. Is there a timing limit or was there another register operation which removed the mailbox message?
I explained the root cause of the issue in the last commit. Maybe I should have added the explanation to the cover letter as well. Anyway, here is a partial verbatim copy of it:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
"During testing of SR-IOV, Red Hat QE encountered an issue where the ip link up command intermittently fails for the igbvf interfaces when using the
PREEMPT_RTvariant. Investigation revealed thate1000_write_posted_mbxreturns an error due to the lack of an ACK frome1000_poll_for_ack.That ACK would have come if it would poll longer?
No, the poll happens while preemption is disabled.
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
No, the service wouldn't be serviced while polling.
s/service/interrupt/. Since we can't sleep at this context, there is no way to wait for an event.
Quoted 17 lines
Hmm.
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
The underlying issue arises from the fact that IRQs are threaded by default under
PREEMPT_RT. While the exact hardware details are not available, it appears that the IRQ handled byigb_msix_othermust be processed beforee1000_poll_for_acktimes out. However,e1000_write_posted_mbxis called with preemption disabled, leading to a scenario where the IRQ is serviced only after the failure ofe1000_write_posted_mbx."Where is this disabled preemption coming from? This should be one of the
ops.write_posted()calls, right? I've been looking around and don't see anything obvious.
Quoted 7 lines
Quoted 3 lines
I don't remember if I found the answer by looking at the code or by looking at the ftrace flags.
I am currently on sick leave with covid. I can check it when I come back.Don't worry, get better first. I'm kind of off myself. I'm not sure if I have the hardware needed to setup so I can look at it…
The reason of why you didn't find is because the interrupt in the igb driver is triggered inside the igbvf code. igbvf_reset() calls spin_lock_bh() [1], although in the cases I found it was already called with preemption disabled from process_one_work() (workqueue) and netlink_sendmsg().
Here is an ftrace log for the failure case:
kworker/-86 0...1 85.381866: function: igbvf_reset kworker/-86 0...2 85.381866: function: e1000_reset_hw_vf kworker/-86 0...2 85.381867: function: e1000_check_for_rst_vf kworker/-86 0...2 85.381868: function: e1000_write_posted_mbx kworker/-86 0...2 85.381868: function: e1000_write_mbx_vf kworker/-86 0...2 85.381870: function: e1000_check_for_ack_vf // repeats for 2000 lines ... kworker/-86 0.N.2 86.393782: function: e1000_read_posted_mbx kworker/-86 0.N.2 86.398606: function: e1000_init_hw_vf kworker/-86 0.N.2 86.398606: function: e1000_rar_set_vf kworker/-86 0.N.2 86.398606: function: e1000_write_posted_mbx irq/65-e-1287 0d..1 86.398609: function: igb_msix_other irq/65-e-1287 0d..1 86.398609: function: igb_rd32 irq/65-e-1287 0d..2 86.398610: function: igb_check_for_rst irq/65-e-1287 0d..2 86.398610: function: igb_check_for_rst_pf irq/65-e-1287 0d..2 86.398610: function: igb_rd32 irq/65-e-1287 0d..2 86.398611: function: igb_check_for_msg irq/65-e-1287 0d..2 86.398611: function: igb_check_for_msg_pf irq/65-e-1287 0d..2 86.398611: function: igb_rd32 irq/65-e-1287 0d..2 86.398612: function: igb_rcv_msg_from_vf irq/65-e-1287 0d..2 86.398612: function: igb_read_mbx irq/65-e-1287 0d..2 86.398612: function: igb_read_mbx_pf irq/65-e-1287 0d..2 86.398612: function: igb_obtain_mbx_lock_pf irq/65-e-1287 0d..2 86.398612: function: igb_rd32
Notice the interrupt handler only executes after e1000_write_posted() returns. And here it is for the sucessful case:
ip-5603 0...1 1884.710747: function: igbvf_reset
ip-5603 0...2 1884.710754: function: e1000_reset_hw_vf
ip-5603 0...2 1884.710755: function: e1000_check_for_rst_vf
ip-5603 0...2 1884.710756: function: e1000_write_posted_mbx
ip-5603 0...2 1884.710756: function: e1000_write_mbx_vf
ip-5603 0...2 1884.710758: function: e1000_check_for_ack_vf
ip-5603 0d.h2 1884.710760: function: igb_msix_other
ip-5603 0d.h2 1884.710760: function: igb_rd32
ip-5603 0d.h3 1884.710761: function: igb_check_for_rst
ip-5603 0d.h3 1884.710761: function: igb_check_for_rst_pf
ip-5603 0d.h3 1884.710761: function: igb_rd32
ip-5603 0d.h3 1884.710762: function: igb_check_for_msg
ip-5603 0d.h3 1884.710762: function: igb_check_for_msg_pf
ip-5603 0d.h3 1884.710762: function: igb_rd32
ip-5603 0d.h3 1884.710763: function: igb_rcv_msg_from_vf
ip-5603 0d.h3 1884.710763: function: igb_read_mbx
ip-5603 0d.h3 1884.710763: function: igb_read_mbx_pf
ip-5603 0d.h3 1884.710763: function: igb_obtain_mbx_lock_pf
ip-5603 0d.h3 1884.710763: function: igb_rd32The ISR executes immediately fater e1000_write_mbx_vf().
[1] https://elixir.bootlin.com/linux/v6.12.6/source/drivers/net/ethernet/intel/igbvf/netdev.c#L1522
Quoted 2 lines
Sebastian