Skip to content

Commit b8c46bc

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 104dea5 commit b8c46bc

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
@@ -763,6 +763,85 @@ void efx_remove_channels(struct efx_nic *efx)
763763
kfree(efx->xdp_tx_queues);
764764
}
765765

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

919+
efx_set_xdp_channels(efx);
840920
out:
841921
/* Destroy unused channel structures */
842922
for (i = 0; i < efx->n_channels; i++) {
@@ -872,26 +952,9 @@ int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
872952
goto out;
873953
}
874954

875-
static inline int
876-
efx_set_xdp_tx_queue(struct efx_nic *efx, int xdp_queue_number,
877-
struct efx_tx_queue *tx_queue)
878-
{
879-
if (xdp_queue_number >= efx->xdp_tx_queue_count)
880-
return -EINVAL;
881-
882-
netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is XDP %u, HW %u\n",
883-
tx_queue->channel->channel, tx_queue->label,
884-
xdp_queue_number, tx_queue->queue);
885-
efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
886-
return 0;
887-
}
888-
889955
int efx_set_channels(struct efx_nic *efx)
890956
{
891-
struct efx_tx_queue *tx_queue;
892957
struct efx_channel *channel;
893-
unsigned int next_queue = 0;
894-
int xdp_queue_number;
895958
int rc;
896959

897960
efx->tx_channel_offset =
@@ -909,61 +972,14 @@ int efx_set_channels(struct efx_nic *efx)
909972
return -ENOMEM;
910973
}
911974

912-
/* We need to mark which channels really have RX and TX
913-
* queues, and adjust the TX queue numbers if we have separate
914-
* RX-only and TX-only channels.
915-
*/
916-
xdp_queue_number = 0;
917975
efx_for_each_channel(channel, efx) {
918976
if (channel->channel < efx->n_rx_channels)
919977
channel->rx_queue.core_index = channel->channel;
920978
else
921979
channel->rx_queue.core_index = -1;
922-
923-
if (channel->channel >= efx->tx_channel_offset) {
924-
if (efx_channel_is_xdp_tx(channel)) {
925-
efx_for_each_channel_tx_queue(tx_queue, channel) {
926-
tx_queue->queue = next_queue++;
927-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
928-
if (rc == 0)
929-
xdp_queue_number++;
930-
}
931-
} else {
932-
efx_for_each_channel_tx_queue(tx_queue, channel) {
933-
tx_queue->queue = next_queue++;
934-
netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is HW %u\n",
935-
channel->channel, tx_queue->label,
936-
tx_queue->queue);
937-
}
938-
939-
/* If XDP is borrowing queues from net stack, it must use the queue
940-
* with no csum offload, which is the first one of the channel
941-
* (note: channel->tx_queue_by_type is not initialized yet)
942-
*/
943-
if (efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_BORROWED) {
944-
tx_queue = &channel->tx_queue[0];
945-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
946-
if (rc == 0)
947-
xdp_queue_number++;
948-
}
949-
}
950-
}
951980
}
952-
WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
953-
xdp_queue_number != efx->xdp_tx_queue_count);
954-
WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
955-
xdp_queue_number > efx->xdp_tx_queue_count);
956981

957-
/* If we have more CPUs than assigned XDP TX queues, assign the already
958-
* existing queues to the exceeding CPUs
959-
*/
960-
next_queue = 0;
961-
while (xdp_queue_number < efx->xdp_tx_queue_count) {
962-
tx_queue = efx->xdp_tx_queues[next_queue++];
963-
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
964-
if (rc == 0)
965-
xdp_queue_number++;
966-
}
982+
efx_set_xdp_channels(efx);
967983

968984
rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
969985
if (rc)

0 commit comments

Comments
 (0)