From: "Malladi, Meghana" <m-malladi@ti.com>
To: Jesper Dangaard Brouer <hawk@kernel.org>,
<dan.carpenter@linaro.org>, <john.fastabend@gmail.com>,
<daniel@iogearbox.net>, <ast@kernel.org>, <pabeni@redhat.com>,
<kuba@kernel.org>, <edumazet@google.com>, <davem@davemloft.net>,
<andrew+netdev@lunn.ch>
Cc: <bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>,
<srk@ti.com>, Vignesh Raghavendra <vigneshr@ti.com>,
Roger Quadros <rogerq@kernel.org>, <danishanwar@ti.com>
Subject: Re: [PATCH net 4/4] net: ti: icssg-prueth: Fix kernel panic during concurrent Tx queue access
Date: Fri, 2 May 2025 14:37:49 +0530 [thread overview]
Message-ID: <f6434e4a-c37c-41dc-91b4-0cc2d33730ba@ti.com> (raw)
In-Reply-To: <074a9a19-9050-44dd-a0bf-536ae8318da2@kernel.org>
Hi Jesper,
On 5/2/2025 12:44 PM, Jesper Dangaard Brouer wrote:
>
>
> On 28/04/2025 14.04, Meghana Malladi wrote:
>> Add __netif_tx_lock() to ensure that only one packet is being
>> transmitted at a time to avoid race conditions in the netif_txq
>> struct and prevent packet data corruption. Failing to do so causes
>> kernel panic with the following error:
>>
>> [ 2184.746764] ------------[ cut here ]------------
>> [ 2184.751412] kernel BUG at lib/dynamic_queue_limits.c:99!
>> [ 2184.756728] Internal error: Oops - BUG: 00000000f2000800 [#1]
>> PREEMPT SMP
>>
>> logs: https://gist.github.com/
>> MeghanaMalladiTI/9c7aa5fc3b7fb03f87c74aad487956e9
>>
>> The lock is acquired before calling emac_xmit_xdp_frame() and released
>> after the
>> call returns. This ensures that the TX queue is protected from
>> concurrent access
>> during the transmission of XDP frames.
>>
>> Fixes: 62aa3246f462 ("net: ti: icssg-prueth: Add XDP support")
>> Signed-off-by: Meghana Malladi <m-malladi@ti.com>
>> ---
>> drivers/net/ethernet/ti/icssg/icssg_common.c | 7 ++++++-
>> drivers/net/ethernet/ti/icssg/icssg_prueth.c | 7 ++++++-
>> 2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/
>> net/ethernet/ti/icssg/icssg_common.c
>> index a120ff6fec8f..e509b6ff81e7 100644
>> --- a/drivers/net/ethernet/ti/icssg/icssg_common.c
>> +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c
>> @@ -660,6 +660,8 @@ static u32 emac_run_xdp(struct prueth_emac *emac,
>> struct xdp_buff *xdp,
>> struct page *page, u32 *len)
>> {
>> struct net_device *ndev = emac->ndev;
>> + struct netdev_queue *netif_txq;
>> + int cpu = smp_processor_id();
>> struct bpf_prog *xdp_prog;
>> struct xdp_frame *xdpf;
>> u32 pkt_len = *len;
>> @@ -679,8 +681,11 @@ static u32 emac_run_xdp(struct prueth_emac *emac,
>> struct xdp_buff *xdp,
>> goto drop;
>> }
>> - q_idx = smp_processor_id() % emac->tx_ch_num;
>> + q_idx = cpu % emac->tx_ch_num;
>> + netif_txq = netdev_get_tx_queue(ndev, q_idx);
>> + __netif_tx_lock(netif_txq, cpu);
>> result = emac_xmit_xdp_frame(emac, xdpf, page, q_idx);
>> + __netif_tx_unlock(netif_txq);
>> if (result == ICSSG_XDP_CONSUMED) {
>> ndev->stats.tx_dropped++;
>> goto drop;
>> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/
>> net/ethernet/ti/icssg/icssg_prueth.c
>> index ee35fecf61e7..b31060e7f698 100644
>> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
>> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
>> @@ -1075,20 +1075,25 @@ static int emac_xdp_xmit(struct net_device
>> *dev, int n, struct xdp_frame **frame
>> {
>> struct prueth_emac *emac = netdev_priv(dev);
>> struct net_device *ndev = emac->ndev;
>> + struct netdev_queue *netif_txq;
>> + int cpu = smp_processor_id();
>> struct xdp_frame *xdpf;
>> unsigned int q_idx;
>> int nxmit = 0;
>> u32 err;
>> int i;
>> - q_idx = smp_processor_id() % emac->tx_ch_num;
>> + q_idx = cpu % emac->tx_ch_num;
>> + netif_txq = netdev_get_tx_queue(ndev, q_idx);
>> if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
>> return -EINVAL;
>> for (i = 0; i < n; i++) {
>> xdpf = frames[i];
>> + __netif_tx_lock(netif_txq, cpu);
>> err = emac_xmit_xdp_frame(emac, xdpf, NULL, q_idx);
>> + __netif_tx_unlock(netif_txq);
>
> Why are you taking and releasing this lock in a loop?
>
> XDP gain performance by sending a batch of 'n' packets.
> This approach looks like a performance killer.
>
Yes, I agree with you. This wasn't the intended change. Thank you for
pointing this out. The lock and unlock should happen outside the loop.
Will fix this in v2.
>
>> if (err != ICSSG_XDP_TX) {
>> ndev->stats.tx_dropped++;
>> break;
>
>
--
Thanks,
Meghana Malladi
next prev parent reply other threads:[~2025-05-02 9:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 12:04 [PATCH net 0/4] Bug fixes from XDP patch series Meghana Malladi
2025-04-28 12:04 ` [PATCH net 1/4] net: ti: icssg-prueth: Set XDP feature flags for ndev Meghana Malladi
2025-04-28 12:04 ` [PATCH net 2/4] net: ti: icssg-prueth: Report BQL before sending XDP packets Meghana Malladi
2025-05-01 14:53 ` Jakub Kicinski
2025-05-02 6:18 ` Malladi, Meghana
2025-04-28 12:04 ` [PATCH net 3/4] net: ti: icssg-prueth: Fix race condition for traffic from different network sockets Meghana Malladi
2025-05-01 14:56 ` Jakub Kicinski
2025-05-02 9:31 ` Malladi, Meghana
2025-04-28 12:04 ` [PATCH net 4/4] net: ti: icssg-prueth: Fix kernel panic during concurrent Tx queue access Meghana Malladi
2025-05-02 7:14 ` Jesper Dangaard Brouer
2025-05-02 9:07 ` Malladi, Meghana [this message]
2025-05-02 7:16 ` [PATCH net 0/4] Bug fixes from XDP patch series Jesper Dangaard Brouer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6434e4a-c37c-41dc-91b4-0cc2d33730ba@ti.com \
--to=m-malladi@ti.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=daniel@iogearbox.net \
--cc=danishanwar@ti.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rogerq@kernel.org \
--cc=srk@ti.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).