Skip to content

Commit 1e53834

Browse files
pskajewxkuba-moo
authored andcommitted
ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero
It is possible to disable VFs while the PF driver is processing requests from the VF driver. This can result in a panic. BUG: unable to handle kernel paging request at 000000000000106c PGD 0 P4D 0 Oops: 0000 [#1] SMP NOPTI CPU: 8 PID: 0 Comm: swapper/8 Kdump: loaded Tainted: G I --------- - Hardware name: Dell Inc. PowerEdge R740/06WXJT, BIOS 2.8.2 08/27/2020 RIP: 0010:ixgbe_msg_task+0x4c8/0x1690 [ixgbe] Code: 00 00 48 8d 04 40 48 c1 e0 05 89 7c 24 24 89 fd 48 89 44 24 10 83 ff 01 0f 84 b8 04 00 00 4c 8b 64 24 10 4d 03 a5 48 22 00 00 <41> 80 7c 24 4c 00 0f 84 8a 03 00 00 0f b7 c7 83 f8 08 0f 84 8f 0a RSP: 0018:ffffb337869f8df8 EFLAGS: 00010002 RAX: 0000000000001020 RBX: 0000000000000000 RCX: 000000000000002b RDX: 0000000000000002 RSI: 0000000000000008 RDI: 0000000000000006 RBP: 0000000000000006 R08: 0000000000000002 R09: 0000000000029780 R10: 00006957d8f42832 R11: 0000000000000000 R12: 0000000000001020 R13: ffff8a00e8978ac0 R14: 000000000000002b R15: ffff8a00e8979c80 FS: 0000000000000000(0000) GS:ffff8a07dfd00000(0000) knlGS:00000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000000106c CR3: 0000000063e10004 CR4: 00000000007726e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: <IRQ> ? ttwu_do_wakeup+0x19/0x140 ? try_to_wake_up+0x1cd/0x550 ? ixgbevf_update_xcast_mode+0x71/0xc0 [ixgbevf] ixgbe_msix_other+0x17e/0x310 [ixgbe] __handle_irq_event_percpu+0x40/0x180 handle_irq_event_percpu+0x30/0x80 handle_irq_event+0x36/0x53 handle_edge_irq+0x82/0x190 handle_irq+0x1c/0x30 do_IRQ+0x49/0xd0 common_interrupt+0xf/0xf This can be eventually be reproduced with the following script: while : do echo 63 > /sys/class/net/<devname>/device/sriov_numvfs sleep 1 echo 0 > /sys/class/net/<devname>/device/sriov_numvfs sleep 1 done Add lock when disabling SR-IOV to prevent process VF mailbox communication. Fixes: d773d13 ("ixgbe: Fix memory leak when SR-IOV VFs are direct assigned") Signed-off-by: Piotr Skajewski <[email protected]> Tested-by: Marek Szlosek <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f838a63 commit 1e53834

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ struct ixgbe_adapter {
779779
#ifdef CONFIG_IXGBE_IPSEC
780780
struct ixgbe_ipsec *ipsec;
781781
#endif /* CONFIG_IXGBE_IPSEC */
782+
spinlock_t vfs_lock;
782783
};
783784

784785
static inline int ixgbe_determine_xdp_q_idx(int cpu)

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,6 +6403,9 @@ static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
64036403
/* n-tuple support exists, always init our spinlock */
64046404
spin_lock_init(&adapter->fdir_perfect_lock);
64056405

6406+
/* init spinlock to avoid concurrency of VF resources */
6407+
spin_lock_init(&adapter->vfs_lock);
6408+
64066409
#ifdef CONFIG_IXGBE_DCB
64076410
ixgbe_init_dcb(adapter);
64086411
#endif

drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,13 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, unsigned int max_vfs)
205205
int ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
206206
{
207207
unsigned int num_vfs = adapter->num_vfs, vf;
208+
unsigned long flags;
208209
int rss;
209210

211+
spin_lock_irqsave(&adapter->vfs_lock, flags);
210212
/* set num VFs to 0 to prevent access to vfinfo */
211213
adapter->num_vfs = 0;
214+
spin_unlock_irqrestore(&adapter->vfs_lock, flags);
212215

213216
/* put the reference to all of the vf devices */
214217
for (vf = 0; vf < num_vfs; ++vf) {
@@ -1355,8 +1358,10 @@ static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf)
13551358
void ixgbe_msg_task(struct ixgbe_adapter *adapter)
13561359
{
13571360
struct ixgbe_hw *hw = &adapter->hw;
1361+
unsigned long flags;
13581362
u32 vf;
13591363

1364+
spin_lock_irqsave(&adapter->vfs_lock, flags);
13601365
for (vf = 0; vf < adapter->num_vfs; vf++) {
13611366
/* process any reset requests */
13621367
if (!ixgbe_check_for_rst(hw, vf))
@@ -1370,6 +1375,7 @@ void ixgbe_msg_task(struct ixgbe_adapter *adapter)
13701375
if (!ixgbe_check_for_ack(hw, vf))
13711376
ixgbe_rcv_ack_from_vf(adapter, vf);
13721377
}
1378+
spin_unlock_irqrestore(&adapter->vfs_lock, flags);
13731379
}
13741380

13751381
static inline void ixgbe_ping_vf(struct ixgbe_adapter *adapter, int vf)

0 commit comments

Comments
 (0)