From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org,
jhack@hpe.com
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next v3 04/10] RDMA/rxe: Extend rxe_init_packet() to support frags
Date: Thu, 27 Jul 2023 15:01:23 -0500 [thread overview]
Message-ID: <20230727200128.65947-5-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20230727200128.65947-1-rpearsonhpe@gmail.com>
Add a subroutine rxe_can_use_sg() to determine if a packet is
a candidate for a fragmented skb. Add a global variable rxe_use_sg
to control whether to support nonlinear skbs. Modify rxe_init_packet()
to test if the packet should use a fragmented skb. Fixup calls to
rxe_init_packet() to use the new API but disable creating nonlinear
skbs for now.
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
drivers/infiniband/sw/rxe/rxe.c | 5 +++
drivers/infiniband/sw/rxe/rxe.h | 3 ++
drivers/infiniband/sw/rxe/rxe_loc.h | 4 +-
drivers/infiniband/sw/rxe/rxe_net.c | 58 ++++++++++++++++++++++++++--
drivers/infiniband/sw/rxe/rxe_req.c | 4 +-
drivers/infiniband/sw/rxe/rxe_resp.c | 4 +-
6 files changed, 66 insertions(+), 12 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c
index 6b55c595f8f8..800e8c0d437d 100644
--- a/drivers/infiniband/sw/rxe/rxe.c
+++ b/drivers/infiniband/sw/rxe/rxe.c
@@ -13,6 +13,11 @@ MODULE_AUTHOR("Bob Pearson, Frank Zago, John Groves, Kamal Heib");
MODULE_DESCRIPTION("Soft RDMA transport");
MODULE_LICENSE("Dual BSD/GPL");
+/* if true allow using fragmented skbs */
+bool rxe_use_sg;
+module_param_named(use_sg, rxe_use_sg, bool, 0444);
+MODULE_PARM_DESC(use_sg, "Support skb frags; default false");
+
/* free resources for a rxe device all objects created for this device must
* have been destroyed
*/
diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h
index 077e3ad8f39a..b334eda62c36 100644
--- a/drivers/infiniband/sw/rxe/rxe.h
+++ b/drivers/infiniband/sw/rxe/rxe.h
@@ -30,6 +30,9 @@
#include "rxe_verbs.h"
#include "rxe_loc.h"
+/* if true allow using fragmented skbs */
+extern bool rxe_use_sg;
+
/*
* Version 1 and Version 2 are identical on 64 bit machines, but on 32 bit
* machines Version 2 has a different struct layout.
diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index fad853199b4d..96b1fb79610a 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -97,8 +97,8 @@ struct rxe_mw *rxe_lookup_mw(struct rxe_qp *qp, int access, u32 rkey);
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,
- struct rxe_pkt_info *pkt);
+struct sk_buff *rxe_init_packet(struct rxe_qp *qp, struct rxe_av *av,
+ struct rxe_pkt_info *pkt, bool *is_frag);
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,
diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c
index 94e347a7f386..c44ef39010f1 100644
--- a/drivers/infiniband/sw/rxe/rxe_net.c
+++ b/drivers/infiniband/sw/rxe/rxe_net.c
@@ -510,12 +510,47 @@ int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
return err;
}
-struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
- struct rxe_pkt_info *pkt)
+/**
+ * rxe_can_use_sg() - determine if packet is a candidate for fragmenting
+ * @rxe: the rxe device
+ * @pkt: packet info
+ *
+ * Limit to packets with:
+ * rxe_use_sg set
+ * ndev supports SG
+ *
+ * Returns: true if conditions are met else 0
+ */
+static bool rxe_can_use_sg(struct rxe_qp *qp, struct rxe_pkt_info *pkt)
+{
+ struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
+
+ return (rxe_use_sg && (rxe->ndev->features & NETIF_F_SG));
+}
+
+/* must be big enough to hold MAC+IPV6+UDP+ROCE headers */
+#define RXE_MIN_SKB_SIZE (256)
+
+/**
+ * rxe_init_packet - allocate and initialize a new skb
+ * @qp: the queue pair
+ * @av: remote address vector
+ * @pkt: packet info
+ * @frag: optional return value for fragmented skb
+ * on call if frag == NULL do not use fragmented skb
+ * on return if not NULL set *frag to 1
+ * if packet will be fragmented else 0
+ *
+ * Returns: an skb on success else NULL
+ */
+struct sk_buff *rxe_init_packet(struct rxe_qp *qp, struct rxe_av *av,
+ struct rxe_pkt_info *pkt, bool *frag)
{
+ struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
unsigned int hdr_len;
struct sk_buff *skb = NULL;
struct net_device *ndev = rxe->ndev;
+ int skb_size;
if (av->network_type == RXE_NETWORK_TYPE_IPV4)
hdr_len = ETH_HLEN + sizeof(struct udphdr) +
@@ -524,8 +559,18 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
hdr_len = ETH_HLEN + sizeof(struct udphdr) +
sizeof(struct ipv6hdr);
- skb = alloc_skb(pkt->paylen + hdr_len + LL_RESERVED_SPACE(ndev),
- GFP_ATOMIC);
+ skb_size = LL_RESERVED_SPACE(ndev) + hdr_len + pkt->paylen;
+ if (frag) {
+ if (rxe_can_use_sg(qp, pkt) &&
+ (skb_size > RXE_MIN_SKB_SIZE)) {
+ skb_size = RXE_MIN_SKB_SIZE;
+ *frag = true;
+ } else {
+ *frag = false;
+ }
+ }
+
+ skb = alloc_skb(skb_size, GFP_ATOMIC);
if (unlikely(!skb))
goto out;
@@ -539,6 +584,11 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
else
skb->protocol = htons(ETH_P_IPV6);
+ if (frag && *frag)
+ pkt->hdr = skb_put(skb, rxe_opcode[pkt->opcode].length);
+ else
+ pkt->hdr = skb_put(skb, pkt->paylen);
+
out:
return skb;
}
diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
index 525e704c12c2..491360fef346 100644
--- a/drivers/infiniband/sw/rxe/rxe_req.c
+++ b/drivers/infiniband/sw/rxe/rxe_req.c
@@ -369,14 +369,12 @@ static struct sk_buff *rxe_init_req_packet(struct rxe_qp *qp,
pkt->pad + RXE_ICRC_SIZE;
/* init skb */
- skb = rxe_init_packet(rxe, av, pkt);
+ skb = rxe_init_packet(qp, av, pkt, NULL);
if (unlikely(!skb)) {
err = -ENOMEM;
goto err_out;
}
- pkt->hdr = skb_put(skb, pkt->paylen);
-
/* init roce headers */
rxe_init_roce_hdrs(qp, wqe, pkt);
diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
index a6c1d67ad943..254f2eab8d20 100644
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -788,12 +788,10 @@ static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp,
ack->paylen = rxe_opcode[opcode].length + payload +
ack->pad + RXE_ICRC_SIZE;
- skb = rxe_init_packet(rxe, &qp->pri_av, ack);
+ skb = rxe_init_packet(qp, &qp->pri_av, ack, NULL);
if (!skb)
return NULL;
- ack->hdr = skb_put(skb, ack->paylen);
-
bth_init(ack, opcode, 0, 0, ack->pad, IB_DEFAULT_PKEY_FULL,
qp->attr.dest_qp_num, 0, psn);
--
2.39.2
next prev parent reply other threads:[~2023-07-27 20:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 20:01 [PATCH for-next v3 00/10] RDMA/rxe: Implement support for nonlinear packets Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 01/10] RDMA/rxe: Add sg fragment ops Bob Pearson
2023-07-28 1:07 ` Zhu Yanjun
2023-07-28 1:49 ` Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 02/10] RDMA/rxe: Extend rxe_mr_copy to support skb frags Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 03/10] RDMA/rxe: Extend copy_data " Bob Pearson
2023-07-27 20:01 ` Bob Pearson [this message]
2023-07-27 20:01 ` [PATCH for-next v3 05/10] RDMA/rxe: Extend rxe_icrc.c to support frags Bob Pearson
2023-07-28 14:20 ` Zhu Yanjun
2023-07-28 14:49 ` Bob Pearson
2023-07-28 23:39 ` Zhu Yanjun
2023-07-27 20:01 ` [PATCH for-next v3 06/10] RDMA/rxe: Extend rxe_init_req_packet() for frags Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 07/10] RDMA/rxe: Extend response packets " Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 08/10] RDMA/rxe: Extend send/write_data_in() " Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 09/10] RDMA/rxe: Extend do_read() in rxe_comp.c " Bob Pearson
2023-07-27 20:01 ` [PATCH for-next v3 10/10] RDMA/rxe: Enable sg code in rxe Bob Pearson
2023-08-15 19:07 ` Jason Gunthorpe
2023-07-28 0:40 ` [PATCH for-next v3 00/10] RDMA/rxe: Implement support for nonlinear packets Zhu Yanjun
2023-07-28 1:54 ` Bob Pearson
2023-08-15 19:08 ` Jason Gunthorpe
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=20230727200128.65947-5-rpearsonhpe@gmail.com \
--to=rpearsonhpe@gmail.com \
--cc=jgg@nvidia.com \
--cc=jhack@hpe.com \
--cc=linux-rdma@vger.kernel.org \
--cc=zyjzyj2000@gmail.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