Skip to content

Commit dcc85e1

Browse files
TaeheeYoogregkh
authored andcommitted
net: sfc: add missing xdp queue reinitialization
[ Upstream commit 059a47f ] After rx/tx ring buffer size is changed, kernel panic occurs when it acts XDP_TX or XDP_REDIRECT. When tx/rx ring buffer size is changed(ethtool -G), sfc driver reallocates and reinitializes rx and tx queues and their buffer (tx_queue->buffer). But it misses reinitializing xdp queues(efx->xdp_tx_queues). So, while it is acting XDP_TX or XDP_REDIRECT, it uses the uninitialized tx_queue->buffer. A new function efx_set_xdp_channels() is separated from efx_set_channels() to handle only xdp queues. Splat looks like: BUG: kernel NULL pointer dereference, address: 000000000000002a #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: 0002 [#4] PREEMPT SMP NOPTI RIP: 0010:efx_tx_map_chunk+0x54/0x90 [sfc] CPU: 2 PID: 0 Comm: swapper/2 Tainted: G D 5.17.0+ #55 e8beeee8289528f11357029357cf Code: 48 8b 8d a8 01 00 00 48 8d 14 52 4c 8d 2c d0 44 89 e0 48 85 c9 74 0e 44 89 e2 4c 89 f6 48 80 RSP: 0018:ffff92f121e45c60 EFLAGS: 00010297 RIP: 0010:efx_tx_map_chunk+0x54/0x90 [sfc] RAX: 0000000000000040 RBX: ffff92ea506895c0 RCX: ffffffffc0330870 RDX: 0000000000000001 RSI: 00000001139b10ce RDI: ffff92ea506895c0 RBP: ffffffffc0358a80 R08: 00000001139b110d R09: 0000000000000000 R10: 0000000000000001 R11: ffff92ea414c0088 R12: 0000000000000040 R13: 0000000000000018 R14: 00000001139b10ce R15: ffff92ea506895c0 FS: 0000000000000000(0000) GS:ffff92f121ec0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 Code: 48 8b 8d a8 01 00 00 48 8d 14 52 4c 8d 2c d0 44 89 e0 48 85 c9 74 0e 44 89 e2 4c 89 f6 48 80 CR2: 000000000000002a CR3: 00000003e6810004 CR4: 00000000007706e0 RSP: 0018:ffff92f121e85c60 EFLAGS: 00010297 PKRU: 55555554 RAX: 0000000000000040 RBX: ffff92ea50689700 RCX: ffffffffc0330870 RDX: 0000000000000001 RSI: 00000001145a90ce RDI: ffff92ea50689700 RBP: ffffffffc0358a80 R08: 00000001145a910d R09: 0000000000000000 R10: 0000000000000001 R11: ffff92ea414c0088 R12: 0000000000000040 R13: 0000000000000018 R14: 00000001145a90ce R15: ffff92ea50689700 FS: 0000000000000000(0000) GS:ffff92f121e80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000000002a CR3: 00000003e6810005 CR4: 00000000007706e0 PKRU: 55555554 Call Trace: <IRQ> efx_xdp_tx_buffers+0x12b/0x3d0 [sfc 84c94b8e32d44d296c17e10a634d3ad454de4ba5] __efx_rx_packet+0x5c3/0x930 [sfc 84c94b8e32d44d296c17e10a634d3ad454de4ba5] efx_rx_packet+0x28c/0x2e0 [sfc 84c94b8e32d44d296c17e10a634d3ad454de4ba5] efx_ef10_ev_process+0x5f8/0xf40 [sfc 84c94b8e32d44d296c17e10a634d3ad454de4ba5] ? enqueue_task_fair+0x95/0x550 efx_poll+0xc4/0x360 [sfc 84c94b8e32d44d296c17e10a634d3ad454de4ba5] Fixes: 3990a8f ("sfc: allocate channels for XDP tx queues") Signed-off-by: Taehee Yoo <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 4881647 commit dcc85e1

File tree

1 file changed

+81
-65
lines changed

1 file changed

+81
-65
lines changed

drivers/net/ethernet/sfc/efx_channels.c

Lines changed: 81 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,85 @@ void efx_remove_channels(struct efx_nic *efx)
764764
kfree(efx->xdp_tx_queues);
765765
}
766766

767+
static int efx_set_xdp_tx_queue(struct efx_nic *efx, int xdp_queue_number,
768+
struct efx_tx_queue *tx_queue)
769+
{
770+
if (xdp_queue_number >= efx->xdp_tx_queue_count)
771+
return -EINVAL;
772+
773+
netif_dbg(efx, drv, efx->net_dev,
774+
"Channel %u TXQ %u is XDP %u, HW %u\n",
775+
tx_queue->channel->channel, tx_queue->label,
776+
xdp_queue_number, tx_queue->queue);
777+
efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
778+
return 0;
779+
}
780+
781+
static void efx_set_xdp_channels(struct efx_nic *efx)
782+
{
783+
struct efx_tx_queue *tx_queue;
784+
struct efx_channel *channel;
785+
unsigned int next_queue = 0;
786+
int xdp_queue_number = 0;
787+
int rc;
788+
789+
/* We need to mark which channels really have RX and TX
790+
* queues, and adjust the TX queue numbers if we have separate
791+
* RX-only and TX-only channels.
792+
*/
793+
efx_for_each_channel(channel, efx) {
794+
if (channel->channel < efx->tx_channel_offset)
795+
continue;
796+
797+
if (efx_channel_is_xdp_tx(channel)) {
798+
efx_for_each_channel_tx_queue(tx_queue, channel) {
799+
tx_queue->queue = next_queue++;
800+
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
801+
tx_queue);
802+
if (rc == 0)
803+
xdp_queue_number++;
804+
}
805+
} else {
806+
efx_for_each_channel_tx_queue(tx_queue, channel) {
807+
tx_queue->queue = next_queue++;
808+
netif_dbg(efx, drv, efx->net_dev,
809+
"Channel %u TXQ %u is HW %u\n",
810+
channel->channel, tx_queue->label,
811+
tx_queue->queue);
812+
}
813+
814+
/* If XDP is borrowing queues from net stack, it must
815+
* use the queue with no csum offload, which is the
816+
* first one of the channel
817+
* (note: tx_queue_by_type is not initialized yet)
818+
*/
819+
if (efx->xdp_txq_queues_mode ==
820+
EFX_XDP_TX_QUEUES_BORROWED) {
821+
tx_queue = &channel->tx_queue[0];
822+
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
823+
tx_queue);
824+
if (rc == 0)
825+
xdp_queue_number++;
826+
}
827+
}
828+
}
829+
WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
830+
xdp_queue_number != efx->xdp_tx_queue_count);
831+
WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
832+
xdp_queue_number > efx->xdp_tx_queue_count);
833+
834+
/* If we have more CPUs than assigned XDP TX queues, assign the already
835+
* existing queues to the exceeding CPUs
836+
*/
837+
next_queue = 0;
838+
while (xdp_queue_number < efx->xdp_tx_queue_count) {
839+
tx_queue = efx->xdp_tx_queues[next_queue++];
840+
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
841+
if (rc == 0)
842+
xdp_queue_number++;
843+
}
844+
}
845+
767846
int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
768847
{
769848
struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
@@ -835,6 +914,7 @@ int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
835914
efx_init_napi_channel(efx->channel[i]);
836915
}
837916

917+
efx_set_xdp_channels(efx);
838918
out:
839919
/* Destroy unused channel structures */
840920
for (i = 0; i < efx->n_channels; i++) {
@@ -867,26 +947,9 @@ int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
867947
goto out;
868948
}
869949

870-
static inline int
871-
efx_set_xdp_tx_queue(struct efx_nic *efx, int xdp_queue_number,
872-
struct efx_tx_queue *tx_queue)
873-
{
874-
if (xdp_queue_number >= efx->xdp_tx_queue_count)
875-
return -EINVAL;
876-
877-
netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is XDP %u, HW %u\n",
878-
tx_queue->channel->channel, tx_queue->label,
879-
xdp_queue_number, tx_queue->queue);
880-
efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
881-
return 0;
882-
}
883-
884950
int efx_set_channels(struct efx_nic *efx)
885951
{
886-
struct efx_tx_queue *tx_queue;
887952
struct efx_channel *channel;
888-
unsigned int next_queue = 0;
889-
int xdp_queue_number;
890953
int rc;
891954

892955
efx->tx_channel_offset =
@@ -904,61 +967,14 @@ int efx_set_channels(struct efx_nic *efx)
904967
return -ENOMEM;
905968
}
906969

907-
/* We need to mark which channels really have RX and TX
908-
* queues, and adjust the TX queue numbers if we have separate
909-
* RX-only and TX-only channels.
910-
*/
911-
xdp_queue_number = 0;
912970
efx_for_each_channel(channel, efx) {
913971
if (channel->channel < efx->n_rx_channels)
914972
channel->rx_queue.core_index = channel->channel;
915973
else
916974
channel->rx_queue.core_index = -1;
917-
918-
if (channel->channel >= efx->tx_channel_offset) {
919-
if (efx_channel_is_xdp_tx(channel)) {
920-
efx_for_each_channel_tx_queue(tx_queue, channel) {
921-
tx_queue->queue = next_queue++;
922-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
923-
if (rc == 0)
924-
xdp_queue_number++;
925-
}
926-
} else {
927-
efx_for_each_channel_tx_queue(tx_queue, channel) {
928-
tx_queue->queue = next_queue++;
929-
netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is HW %u\n",
930-
channel->channel, tx_queue->label,
931-
tx_queue->queue);
932-
}
933-
934-
/* If XDP is borrowing queues from net stack, it must use the queue
935-
* with no csum offload, which is the first one of the channel
936-
* (note: channel->tx_queue_by_type is not initialized yet)
937-
*/
938-
if (efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_BORROWED) {
939-
tx_queue = &channel->tx_queue[0];
940-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
941-
if (rc == 0)
942-
xdp_queue_number++;
943-
}
944-
}
945-
}
946975
}
947-
WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
948-
xdp_queue_number != efx->xdp_tx_queue_count);
949-
WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
950-
xdp_queue_number > efx->xdp_tx_queue_count);
951976

952-
/* If we have more CPUs than assigned XDP TX queues, assign the already
953-
* existing queues to the exceeding CPUs
954-
*/
955-
next_queue = 0;
956-
while (xdp_queue_number < efx->xdp_tx_queue_count) {
957-
tx_queue = efx->xdp_tx_queues[next_queue++];
958-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
959-
if (rc == 0)
960-
xdp_queue_number++;
961-
}
977+
efx_set_xdp_channels(efx);
962978

963979
rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
964980
if (rc)

0 commit comments

Comments
 (0)