From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: weimin xiong <15927021679@163.com>,
linux-rdma@vger.kernel.org,
"yanjun.zhu@linux.dev" <yanjun.zhu@linux.dev>
Cc: jgg@nvidia.com, xiongweimin <xiongweimin@kylinos.cn>
Subject: Re: [PATCH] RDMA/rxe: Hold netdev reference for transmit skbs
Date: Mon, 13 Jul 2026 17:02:23 -0700 [thread overview]
Message-ID: <c7cc0866-9d54-4909-9d22-7b6ddfb9096e@linux.dev> (raw)
In-Reply-To: <20260713100309.101189-1-15927021679@163.com>
在 2026/7/13 3:03, weimin xiong 写道:
> From: xiongweimin <xiongweimin@kylinos.cn>
>
> rxe_init_packet() assigns skb->dev from an RCU-protected GID attribute
> without holding a netdev reference. If the netdev is unregistered before
> the skb is freed, subsequent accesses to skb->dev are unsafe.
>
> Hold a reference with dev_hold() when the skb is initialized and release
> it from the transmit destructor or via rxe_put_skb() on error paths.
>
> Signed-off-by: xiongweimin <xiongweimin@kylinos.cn>
This commit can not be applied in linux kernel upstream cleanly.
The logic of holding a netdev reference to guarantee memory safety
(preventing Use-After-Free) is correct. But, this introduces the classic
risk of blocking netdev unregistration if an skb is leaked or held
indefinitely.
To mitigate this and ensure clean netdev unregistration:
Ensure the driver properly handles `NETDEV_UNREGISTER` notifications by
immediately flushing all QPs/TX queues to release pending skbs under
unregistration events.
So please modify this commit to apply this commit on linux upstream.
Zhu Yanjun
> Cc: linux-rdma@vger.kernel.org
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> ---
>
> --- a/drivers/infiniband/sw/rxe/rxe_loc.h
> +++ b/drivers/infiniband/sw/rxe/rxe_loc.h
> @@ -95,6 +95,7 @@ void rxe_mw_cleanup(struct rxe_pool_elem *elem);
> /* rxe_net.c */
> struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
> int paylen, struct rxe_pkt_info *pkt);
> +void rxe_put_skb(struct sk_buff *skb);
> int rxe_prepare(struct rxe_av *av, struct rxe_pkt_info *pkt,
> struct sk_buff *skb);
> int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
> --- a/drivers/infiniband/sw/rxe/rxe_net.c
> +++ b/drivers/infiniband/sw/rxe/rxe_net.c
> @@ -355,6 +355,16 @@ static void rxe_skb_tx_dtor(struct sk_buff *skb)
>
> rxe_put(qp);
> sock_put(skb->sk);
> + if (skb->dev) {
> + dev_put(skb->dev);
> + skb->dev = NULL;
> + }
> +}
> +
> +void rxe_put_skb(struct sk_buff *skb)
> +{
> + if (skb->dev)
> + dev_put(skb->dev);
> + kfree_skb(skb);
> }
>
> static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)
> @@ -441,7 +451,7 @@ int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
> goto done;
>
> drop:
> - kfree_skb(skb);
> + rxe_put_skb(skb);
> err = 0;
> done:
> return err;
> @@ -486,8 +496,8 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
>
> skb_reserve(skb, hdr_len + LL_RESERVED_SPACE(ndev));
>
> - /* FIXME: hold reference to this netdev until life of this skb. */
> + dev_hold(ndev);
> skb->dev = ndev;
> rcu_read_unlock();
>
> --- a/drivers/infiniband/sw/rxe/rxe_req.c
> +++ b/drivers/infiniband/sw/rxe/rxe_req.c
> @@ -793,7 +793,7 @@ next_wqe:
> wqe->status = IB_WC_LOC_PROT_ERR;
> else
> wqe->status = IB_WC_LOC_QP_OP_ERR;
> - kfree_skb(skb);
> + rxe_put_skb(skb);
> if (ah)
> rxe_put(ah);
> goto err;
> --- a/drivers/infiniband/sw/rxe/rxe_resp.c
> +++ b/drivers/infiniband/sw/rxe/rxe_resp.c
> @@ -817,7 +817,7 @@ static struct sk_buff *copy_data(struct rxe_qp *qp,
>
> err = rxe_prepare(&qp->pri_av, ack, skb);
> if (err) {
> - kfree_skb(skb);
> + rxe_put_skb(skb);
> return NULL;
> }
>
> @@ -945,7 +945,7 @@ static enum resp_states read(struct rxe_qp *qp,
> err = rxe_mr_copy(mr, res->read.va, payload_addr(&ack_pkt),
> payload, RXE_FROM_MR_OBJ);
> if (err) {
> - kfree_skb(skb);
> + rxe_put_skb(skb);
> state = RESPST_ERR_RKEY_VIOLATION;
> goto err_out;
> }
>
next prev parent reply other threads:[~2026-07-14 0:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 10:03 [PATCH] RDMA/rxe: Hold netdev reference for transmit skbs weimin xiong
2026-07-14 0:02 ` Zhu Yanjun [this message]
2026-07-14 1:55 ` [PATCH v2] " weimin xiong
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=c7cc0866-9d54-4909-9d22-7b6ddfb9096e@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=15927021679@163.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=xiongweimin@kylinos.cn \
/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