2023-04-12 21:20:05

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH V3,net-next, 0/4] net: mana: Add support for jumbo frame

The set adds support for jumbo frame,
with some optimization for the RX path.


Haiyang Zhang (4):
net: mana: Use napi_build_skb in RX path
net: mana: Refactor RX buffer allocation code to prepare for various MTU
net: mana: Enable RX path to handle various MTU sizes
net: mana: Add support for jumbo frame

.../net/ethernet/microsoft/mana/mana_bpf.c | 22 +-
drivers/net/ethernet/microsoft/mana/mana_en.c | 383 ++++++++++++++----
include/net/mana/gdma.h | 4 +
include/net/mana/mana.h | 27 +-
4 files changed, 346 insertions(+), 90 deletions(-)

--
2.25.1


2023-04-12 21:20:33

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

Move out common buffer allocation code from mana_process_rx_cqe() and
mana_alloc_rx_wqe() to helper functions.
Refactor related variables so they can be changed in one place, and buffer
sizes are in sync.

Signed-off-by: Haiyang Zhang <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
V3:
Refectored to multiple patches for readability. Suggested by Jacob Keller.

V2:
Refectored to multiple patches for readability. Suggested by Yunsheng Lin.

---
drivers/net/ethernet/microsoft/mana/mana_en.c | 154 ++++++++++--------
include/net/mana/mana.h | 6 +-
2 files changed, 91 insertions(+), 69 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 112c642dc89b..911954ff84ee 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -1282,14 +1282,64 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
u64_stats_update_end(&rx_stats->syncp);

drop:
- WARN_ON_ONCE(rxq->xdp_save_page);
- rxq->xdp_save_page = virt_to_page(buf_va);
+ WARN_ON_ONCE(rxq->xdp_save_va);
+ /* Save for reuse */
+ rxq->xdp_save_va = buf_va;

++ndev->stats.rx_dropped;

return;
}

+static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
+ dma_addr_t *da, bool is_napi)
+{
+ struct page *page;
+ void *va;
+
+ /* Reuse XDP dropped page if available */
+ if (rxq->xdp_save_va) {
+ va = rxq->xdp_save_va;
+ rxq->xdp_save_va = NULL;
+ } else {
+ page = dev_alloc_page();
+ if (!page)
+ return NULL;
+
+ va = page_to_virt(page);
+ }
+
+ *da = dma_map_single(dev, va + XDP_PACKET_HEADROOM, rxq->datasize,
+ DMA_FROM_DEVICE);
+
+ if (dma_mapping_error(dev, *da)) {
+ put_page(virt_to_head_page(va));
+ return NULL;
+ }
+
+ return va;
+}
+
+/* Allocate frag for rx buffer, and save the old buf */
+static void mana_refill_rxoob(struct device *dev, struct mana_rxq *rxq,
+ struct mana_recv_buf_oob *rxoob, void **old_buf)
+{
+ dma_addr_t da;
+ void *va;
+
+ va = mana_get_rxfrag(rxq, dev, &da, true);
+
+ if (!va)
+ return;
+
+ dma_unmap_single(dev, rxoob->sgl[0].address, rxq->datasize,
+ DMA_FROM_DEVICE);
+ *old_buf = rxoob->buf_va;
+
+ rxoob->buf_va = va;
+ rxoob->sgl[0].address = da;
+}
+
static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,
struct gdma_comp *cqe)
{
@@ -1299,10 +1349,8 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,
struct mana_recv_buf_oob *rxbuf_oob;
struct mana_port_context *apc;
struct device *dev = gc->dev;
- void *new_buf, *old_buf;
- struct page *new_page;
+ void *old_buf = NULL;
u32 curr, pktlen;
- dma_addr_t da;

apc = netdev_priv(ndev);

@@ -1345,40 +1393,11 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,
rxbuf_oob = &rxq->rx_oobs[curr];
WARN_ON_ONCE(rxbuf_oob->wqe_inf.wqe_size_in_bu != 1);

- /* Reuse XDP dropped page if available */
- if (rxq->xdp_save_page) {
- new_page = rxq->xdp_save_page;
- rxq->xdp_save_page = NULL;
- } else {
- new_page = alloc_page(GFP_ATOMIC);
- }
-
- if (new_page) {
- da = dma_map_page(dev, new_page, XDP_PACKET_HEADROOM, rxq->datasize,
- DMA_FROM_DEVICE);
-
- if (dma_mapping_error(dev, da)) {
- __free_page(new_page);
- new_page = NULL;
- }
- }
-
- new_buf = new_page ? page_to_virt(new_page) : NULL;
-
- if (new_buf) {
- dma_unmap_page(dev, rxbuf_oob->buf_dma_addr, rxq->datasize,
- DMA_FROM_DEVICE);
-
- old_buf = rxbuf_oob->buf_va;
-
- /* refresh the rxbuf_oob with the new page */
- rxbuf_oob->buf_va = new_buf;
- rxbuf_oob->buf_dma_addr = da;
- rxbuf_oob->sgl[0].address = rxbuf_oob->buf_dma_addr;
- } else {
- old_buf = NULL; /* drop the packet if no memory */
- }
+ mana_refill_rxoob(dev, rxq, rxbuf_oob, &old_buf);

+ /* Unsuccessful refill will have old_buf == NULL.
+ * In this case, mana_rx_skb() will drop the packet.
+ */
mana_rx_skb(old_buf, oob, rxq);

drop:
@@ -1659,8 +1678,8 @@ static void mana_destroy_rxq(struct mana_port_context *apc,

mana_deinit_cq(apc, &rxq->rx_cq);

- if (rxq->xdp_save_page)
- __free_page(rxq->xdp_save_page);
+ if (rxq->xdp_save_va)
+ put_page(virt_to_head_page(rxq->xdp_save_va));

for (i = 0; i < rxq->num_rx_buf; i++) {
rx_oob = &rxq->rx_oobs[i];
@@ -1668,10 +1687,10 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
if (!rx_oob->buf_va)
continue;

- dma_unmap_page(dev, rx_oob->buf_dma_addr, rxq->datasize,
- DMA_FROM_DEVICE);
+ dma_unmap_single(dev, rx_oob->sgl[0].address,
+ rx_oob->sgl[0].size, DMA_FROM_DEVICE);

- free_page((unsigned long)rx_oob->buf_va);
+ put_page(virt_to_head_page(rx_oob->buf_va));
rx_oob->buf_va = NULL;
}

@@ -1681,6 +1700,26 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
kfree(rxq);
}

+static int mana_fill_rx_oob(struct mana_recv_buf_oob *rx_oob, u32 mem_key,
+ struct mana_rxq *rxq, struct device *dev)
+{
+ dma_addr_t da;
+ void *va;
+
+ va = mana_get_rxfrag(rxq, dev, &da, false);
+
+ if (!va)
+ return -ENOMEM;
+
+ rx_oob->buf_va = va;
+
+ rx_oob->sgl[0].address = da;
+ rx_oob->sgl[0].size = rxq->datasize;
+ rx_oob->sgl[0].mem_key = mem_key;
+
+ return 0;
+}
+
#define MANA_WQE_HEADER_SIZE 16
#define MANA_WQE_SGE_SIZE 16

@@ -1690,9 +1729,8 @@ static int mana_alloc_rx_wqe(struct mana_port_context *apc,
struct gdma_context *gc = apc->ac->gdma_dev->gdma_context;
struct mana_recv_buf_oob *rx_oob;
struct device *dev = gc->dev;
- struct page *page;
- dma_addr_t da;
u32 buf_idx;
+ int ret;

WARN_ON(rxq->datasize == 0 || rxq->datasize > PAGE_SIZE);

@@ -1703,25 +1741,12 @@ static int mana_alloc_rx_wqe(struct mana_port_context *apc,
rx_oob = &rxq->rx_oobs[buf_idx];
memset(rx_oob, 0, sizeof(*rx_oob));

- page = alloc_page(GFP_KERNEL);
- if (!page)
- return -ENOMEM;
-
- da = dma_map_page(dev, page, XDP_PACKET_HEADROOM, rxq->datasize,
- DMA_FROM_DEVICE);
-
- if (dma_mapping_error(dev, da)) {
- __free_page(page);
- return -ENOMEM;
- }
-
- rx_oob->buf_va = page_to_virt(page);
- rx_oob->buf_dma_addr = da;
-
rx_oob->num_sge = 1;
- rx_oob->sgl[0].address = rx_oob->buf_dma_addr;
- rx_oob->sgl[0].size = rxq->datasize;
- rx_oob->sgl[0].mem_key = apc->ac->gdma_dev->gpa_mkey;
+
+ ret = mana_fill_rx_oob(rx_oob, apc->ac->gdma_dev->gpa_mkey, rxq,
+ dev);
+ if (ret)
+ return ret;

rx_oob->wqe_req.sgl = rx_oob->sgl;
rx_oob->wqe_req.num_sge = rx_oob->num_sge;
@@ -1780,9 +1805,10 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
rxq->ndev = ndev;
rxq->num_rx_buf = RX_BUFFERS_PER_QUEUE;
rxq->rxq_idx = rxq_idx;
- rxq->datasize = ALIGN(MAX_FRAME_SIZE, 64);
rxq->rxobj = INVALID_MANA_HANDLE;

+ rxq->datasize = ALIGN(ETH_FRAME_LEN, 64);
+
err = mana_alloc_rx_wqe(apc, rxq, &rq_size, &cq_size);
if (err)
goto out;
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index bb11a6535d80..037bcabf6b98 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -36,9 +36,6 @@ enum TRI_STATE {

#define COMP_ENTRY_SIZE 64

-#define ADAPTER_MTU_SIZE 1500
-#define MAX_FRAME_SIZE (ADAPTER_MTU_SIZE + 14)
-
#define RX_BUFFERS_PER_QUEUE 512

#define MAX_SEND_BUFFERS_PER_QUEUE 256
@@ -282,7 +279,6 @@ struct mana_recv_buf_oob {
struct gdma_wqe_request wqe_req;

void *buf_va;
- dma_addr_t buf_dma_addr;

/* SGL of the buffer going to be sent has part of the work request. */
u32 num_sge;
@@ -322,7 +318,7 @@ struct mana_rxq {

struct bpf_prog __rcu *bpf_prog;
struct xdp_rxq_info xdp_rxq;
- struct page *xdp_save_page;
+ void *xdp_save_va; /* for reusing */
bool xdp_flush;
int xdp_rc; /* XDP redirect return code */

--
2.25.1

2023-04-12 21:20:37

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle various MTU sizes

Update RX data path to allocate and use RX queue DMA buffers with
proper size based on potentially various MTU sizes.

Signed-off-by: Haiyang Zhang <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
V3:
Refectored to multiple patches for readability. Suggested by Jacob Keller.

V2:
Refectored to multiple patches for readability. Suggested by Yunsheng Lin.

---
drivers/net/ethernet/microsoft/mana/mana_en.c | 38 ++++++++++++++-----
include/net/mana/mana.h | 7 ++++
2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 911954ff84ee..8e7fa6e9c3b5 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -1185,10 +1185,10 @@ static void mana_post_pkt_rxq(struct mana_rxq *rxq)
WARN_ON_ONCE(recv_buf_oob->wqe_inf.wqe_size_in_bu != 1);
}

-static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len,
- struct xdp_buff *xdp)
+static struct sk_buff *mana_build_skb(struct mana_rxq *rxq, void *buf_va,
+ uint pkt_len, struct xdp_buff *xdp)
{
- struct sk_buff *skb = napi_build_skb(buf_va, PAGE_SIZE);
+ struct sk_buff *skb = napi_build_skb(buf_va, rxq->alloc_size);

if (!skb)
return NULL;
@@ -1196,11 +1196,12 @@ static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len,
if (xdp->data_hard_start) {
skb_reserve(skb, xdp->data - xdp->data_hard_start);
skb_put(skb, xdp->data_end - xdp->data);
- } else {
- skb_reserve(skb, XDP_PACKET_HEADROOM);
- skb_put(skb, pkt_len);
+ return skb;
}

+ skb_reserve(skb, rxq->headroom);
+ skb_put(skb, pkt_len);
+
return skb;
}

@@ -1233,7 +1234,7 @@ static void mana_rx_skb(void *buf_va, struct mana_rxcomp_oob *cqe,
if (act != XDP_PASS && act != XDP_TX)
goto drop_xdp;

- skb = mana_build_skb(buf_va, pkt_len, &xdp);
+ skb = mana_build_skb(rxq, buf_va, pkt_len, &xdp);

if (!skb)
goto drop;
@@ -1301,6 +1302,14 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
if (rxq->xdp_save_va) {
va = rxq->xdp_save_va;
rxq->xdp_save_va = NULL;
+ } else if (rxq->alloc_size > PAGE_SIZE) {
+ if (is_napi)
+ va = napi_alloc_frag(rxq->alloc_size);
+ else
+ va = netdev_alloc_frag(rxq->alloc_size);
+
+ if (!va)
+ return NULL;
} else {
page = dev_alloc_page();
if (!page)
@@ -1309,7 +1318,7 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
va = page_to_virt(page);
}

- *da = dma_map_single(dev, va + XDP_PACKET_HEADROOM, rxq->datasize,
+ *da = dma_map_single(dev, va + rxq->headroom, rxq->datasize,
DMA_FROM_DEVICE);

if (dma_mapping_error(dev, *da)) {
@@ -1732,7 +1741,7 @@ static int mana_alloc_rx_wqe(struct mana_port_context *apc,
u32 buf_idx;
int ret;

- WARN_ON(rxq->datasize == 0 || rxq->datasize > PAGE_SIZE);
+ WARN_ON(rxq->datasize == 0);

*rxq_size = 0;
*cq_size = 0;
@@ -1788,6 +1797,7 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
struct gdma_dev *gd = apc->ac->gdma_dev;
struct mana_obj_spec wq_spec;
struct mana_obj_spec cq_spec;
+ unsigned int mtu = ndev->mtu;
struct gdma_queue_spec spec;
struct mana_cq *cq = NULL;
struct gdma_context *gc;
@@ -1807,7 +1817,15 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
rxq->rxq_idx = rxq_idx;
rxq->rxobj = INVALID_MANA_HANDLE;

- rxq->datasize = ALIGN(ETH_FRAME_LEN, 64);
+ rxq->datasize = ALIGN(mtu + ETH_HLEN, 64);
+
+ if (mtu > MANA_XDP_MTU_MAX) {
+ rxq->alloc_size = mtu + MANA_RXBUF_PAD;
+ rxq->headroom = 0;
+ } else {
+ rxq->alloc_size = mtu + MANA_RXBUF_PAD + XDP_PACKET_HEADROOM;
+ rxq->headroom = XDP_PACKET_HEADROOM;
+ }

err = mana_alloc_rx_wqe(apc, rxq, &rq_size, &cq_size);
if (err)
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index 037bcabf6b98..fee99d704281 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -291,6 +291,11 @@ struct mana_recv_buf_oob {
struct gdma_posted_wqe_info wqe_inf;
};

+#define MANA_RXBUF_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) \
+ + ETH_HLEN)
+
+#define MANA_XDP_MTU_MAX (PAGE_SIZE - MANA_RXBUF_PAD - XDP_PACKET_HEADROOM)
+
struct mana_rxq {
struct gdma_queue *gdma_rq;
/* Cache the gdma receive queue id */
@@ -300,6 +305,8 @@ struct mana_rxq {
u32 rxq_idx;

u32 datasize;
+ u32 alloc_size;
+ u32 headroom;

mana_handle_t rxobj;

--
2.25.1

2023-04-12 21:21:00

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH V3,net-next, 4/4] net: mana: Add support for jumbo frame

During probe, get the hardware-allowed max MTU by querying the device
configuration. Users can select MTU up to the device limit.
When XDP is in use, limit MTU settings so the buffer size is within
one page. And, when MTU is set to a too large value, XDP is not allowed
to run.
Also, to prevent changing MTU fails, and leaves the NIC in a bad state,
pre-allocate all buffers before starting the change. So in low memory
condition, it will return error, without affecting the NIC.

Signed-off-by: Haiyang Zhang <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
V2:
Refectored to multiple patches for readability. Suggested by Yunsheng Lin.

Added pre-allocation of buffers to avoid changing MTU fails in a bad state.
Suggested by Leon Romanovsky, Francois Romieu.

---
.../net/ethernet/microsoft/mana/mana_bpf.c | 22 +-
drivers/net/ethernet/microsoft/mana/mana_en.c | 217 ++++++++++++++++--
include/net/mana/gdma.h | 4 +
include/net/mana/mana.h | 14 ++
4 files changed, 233 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
index 3caea631229c..23b1521c0df9 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
@@ -133,12 +133,6 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq,
return act;
}

-static unsigned int mana_xdp_fraglen(unsigned int len)
-{
- return SKB_DATA_ALIGN(len) +
- SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
-}
-
struct bpf_prog *mana_xdp_get(struct mana_port_context *apc)
{
ASSERT_RTNL();
@@ -179,17 +173,18 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
{
struct mana_port_context *apc = netdev_priv(ndev);
struct bpf_prog *old_prog;
- int buf_max;
+ struct gdma_context *gc;
+
+ gc = apc->ac->gdma_dev->gdma_context;

old_prog = mana_xdp_get(apc);

if (!old_prog && !prog)
return 0;

- buf_max = XDP_PACKET_HEADROOM + mana_xdp_fraglen(ndev->mtu + ETH_HLEN);
- if (prog && buf_max > PAGE_SIZE) {
- netdev_err(ndev, "XDP: mtu:%u too large, buf_max:%u\n",
- ndev->mtu, buf_max);
+ if (prog && ndev->mtu > MANA_XDP_MTU_MAX) {
+ netdev_err(ndev, "XDP: mtu:%u too large, mtu_max:%lu\n",
+ ndev->mtu, MANA_XDP_MTU_MAX);
NL_SET_ERR_MSG_MOD(extack, "XDP: mtu too large");

return -EOPNOTSUPP;
@@ -206,6 +201,11 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
if (apc->port_is_up)
mana_chn_setxdp(apc, prog);

+ if (prog)
+ ndev->max_mtu = MANA_XDP_MTU_MAX;
+ else
+ ndev->max_mtu = gc->adapter_mtu - ETH_HLEN;
+
return 0;
}

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 8e7fa6e9c3b5..cabecbfa1102 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -427,6 +427,192 @@ static u16 mana_select_queue(struct net_device *ndev, struct sk_buff *skb,
return txq;
}

+/* Release pre-allocated RX buffers */
+static void mana_pre_dealloc_rxbufs(struct mana_port_context *mpc)
+{
+ struct device *dev;
+ int i;
+
+ dev = mpc->ac->gdma_dev->gdma_context->dev;
+
+ if (!mpc->rxbufs_pre)
+ goto out1;
+
+ if (!mpc->das_pre)
+ goto out2;
+
+ while (mpc->rxbpre_total) {
+ i = --mpc->rxbpre_total;
+ dma_unmap_single(dev, mpc->das_pre[i], mpc->rxbpre_datasize,
+ DMA_FROM_DEVICE);
+ put_page(virt_to_head_page(mpc->rxbufs_pre[i]));
+ }
+
+ kfree(mpc->das_pre);
+ mpc->das_pre = NULL;
+
+out2:
+ kfree(mpc->rxbufs_pre);
+ mpc->rxbufs_pre = NULL;
+
+out1:
+ mpc->rxbpre_datasize = 0;
+ mpc->rxbpre_alloc_size = 0;
+ mpc->rxbpre_headroom = 0;
+}
+
+/* Get a buffer from the pre-allocated RX buffers */
+static void *mana_get_rxbuf_pre(struct mana_rxq *rxq, dma_addr_t *da)
+{
+ struct net_device *ndev = rxq->ndev;
+ struct mana_port_context *mpc;
+ void *va;
+
+ mpc = netdev_priv(ndev);
+
+ if (!mpc->rxbufs_pre || !mpc->das_pre || !mpc->rxbpre_total) {
+ netdev_err(ndev, "No RX pre-allocated bufs\n");
+ return NULL;
+ }
+
+ /* Check sizes to catch unexpected coding error */
+ if (mpc->rxbpre_datasize != rxq->datasize) {
+ netdev_err(ndev, "rxbpre_datasize mismatch: %u: %u\n",
+ mpc->rxbpre_datasize, rxq->datasize);
+ return NULL;
+ }
+
+ if (mpc->rxbpre_alloc_size != rxq->alloc_size) {
+ netdev_err(ndev, "rxbpre_alloc_size mismatch: %u: %u\n",
+ mpc->rxbpre_alloc_size, rxq->alloc_size);
+ return NULL;
+ }
+
+ if (mpc->rxbpre_headroom != rxq->headroom) {
+ netdev_err(ndev, "rxbpre_headroom mismatch: %u: %u\n",
+ mpc->rxbpre_headroom, rxq->headroom);
+ return NULL;
+ }
+
+ mpc->rxbpre_total--;
+
+ *da = mpc->das_pre[mpc->rxbpre_total];
+ va = mpc->rxbufs_pre[mpc->rxbpre_total];
+ mpc->rxbufs_pre[mpc->rxbpre_total] = NULL;
+
+ /* Deallocate the array after all buffers are gone */
+ if (!mpc->rxbpre_total)
+ mana_pre_dealloc_rxbufs(mpc);
+
+ return va;
+}
+
+/* Get RX buffer's data size, alloc size, XDP headroom based on MTU */
+static void mana_get_rxbuf_cfg(int mtu, u32 *datasize, u32 *alloc_size,
+ u32 *headroom)
+{
+ if (mtu > MANA_XDP_MTU_MAX)
+ *headroom = 0; /* no support for XDP */
+ else
+ *headroom = XDP_PACKET_HEADROOM;
+
+ *alloc_size = mtu + MANA_RXBUF_PAD + *headroom;
+
+ *datasize = ALIGN(mtu + ETH_HLEN, MANA_RX_DATA_ALIGN);
+}
+
+static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
+{
+ struct device *dev;
+ struct page *page;
+ dma_addr_t da;
+ int num_rxb;
+ void *va;
+ int i;
+
+ mana_get_rxbuf_cfg(new_mtu, &mpc->rxbpre_datasize,
+ &mpc->rxbpre_alloc_size, &mpc->rxbpre_headroom);
+
+ dev = mpc->ac->gdma_dev->gdma_context->dev;
+
+ num_rxb = mpc->num_queues * RX_BUFFERS_PER_QUEUE;
+
+ WARN(mpc->rxbufs_pre, "mana rxbufs_pre exists\n");
+ mpc->rxbufs_pre = kmalloc_array(num_rxb, sizeof(void *), GFP_KERNEL);
+ if (!mpc->rxbufs_pre)
+ goto error;
+
+ mpc->das_pre = kmalloc_array(num_rxb, sizeof(dma_addr_t), GFP_KERNEL);
+ if (!mpc->das_pre)
+ goto error;
+
+ mpc->rxbpre_total = 0;
+
+ for (i = 0; i < num_rxb; i++) {
+ if (mpc->rxbpre_alloc_size > PAGE_SIZE) {
+ va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
+ if (!va)
+ goto error;
+ } else {
+ page = dev_alloc_page();
+ if (!page)
+ goto error;
+
+ va = page_to_virt(page);
+ }
+
+ da = dma_map_single(dev, va + mpc->rxbpre_headroom,
+ mpc->rxbpre_datasize, DMA_FROM_DEVICE);
+
+ if (dma_mapping_error(dev, da)) {
+ put_page(virt_to_head_page(va));
+ goto error;
+ }
+
+ mpc->rxbufs_pre[i] = va;
+ mpc->das_pre[i] = da;
+ mpc->rxbpre_total = i + 1;
+ }
+
+ return 0;
+
+error:
+ mana_pre_dealloc_rxbufs(mpc);
+ return -ENOMEM;
+}
+
+static int mana_change_mtu(struct net_device *ndev, int new_mtu)
+{
+ struct mana_port_context *mpc = netdev_priv(ndev);
+ unsigned int old_mtu = ndev->mtu;
+ int err;
+
+ /* Pre-allocate buffers to prevent failure in mana_attach later */
+ err = mana_pre_alloc_rxbufs(mpc, new_mtu);
+ if (err) {
+ netdev_err(ndev, "Insufficient memory for new MTU\n");
+ return err;
+ }
+
+ err = mana_detach(ndev, false);
+ if (err) {
+ netdev_err(ndev, "mana_detach failed: %d\n", err);
+ goto out;
+ }
+
+ ndev->mtu = new_mtu;
+
+ err = mana_attach(ndev);
+ if (err) {
+ netdev_err(ndev, "mana_attach failed: %d\n", err);
+ ndev->mtu = old_mtu;
+ }
+
+out:
+ mana_pre_dealloc_rxbufs(mpc);
+ return err;
+}
+
static const struct net_device_ops mana_devops = {
.ndo_open = mana_open,
.ndo_stop = mana_close,
@@ -436,6 +622,7 @@ static const struct net_device_ops mana_devops = {
.ndo_get_stats64 = mana_get_stats64,
.ndo_bpf = mana_bpf,
.ndo_xdp_xmit = mana_xdp_xmit,
+ .ndo_change_mtu = mana_change_mtu,
};

static void mana_cleanup_port_context(struct mana_port_context *apc)
@@ -625,6 +812,9 @@ static int mana_query_device_cfg(struct mana_context *ac, u32 proto_major_ver,

mana_gd_init_req_hdr(&req.hdr, MANA_QUERY_DEV_CONFIG,
sizeof(req), sizeof(resp));
+
+ req.hdr.resp.msg_version = GDMA_MESSAGE_V2;
+
req.proto_major_ver = proto_major_ver;
req.proto_minor_ver = proto_minor_ver;
req.proto_micro_ver = proto_micro_ver;
@@ -647,6 +837,11 @@ static int mana_query_device_cfg(struct mana_context *ac, u32 proto_major_ver,

*max_num_vports = resp.max_num_vports;

+ if (resp.hdr.response.msg_version == GDMA_MESSAGE_V2)
+ gc->adapter_mtu = resp.adapter_mtu;
+ else
+ gc->adapter_mtu = ETH_FRAME_LEN;
+
return 0;
}

@@ -1712,10 +1907,14 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
static int mana_fill_rx_oob(struct mana_recv_buf_oob *rx_oob, u32 mem_key,
struct mana_rxq *rxq, struct device *dev)
{
+ struct mana_port_context *mpc = netdev_priv(rxq->ndev);
dma_addr_t da;
void *va;

- va = mana_get_rxfrag(rxq, dev, &da, false);
+ if (mpc->rxbufs_pre)
+ va = mana_get_rxbuf_pre(rxq, &da);
+ else
+ va = mana_get_rxfrag(rxq, dev, &da, false);

if (!va)
return -ENOMEM;
@@ -1797,7 +1996,6 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
struct gdma_dev *gd = apc->ac->gdma_dev;
struct mana_obj_spec wq_spec;
struct mana_obj_spec cq_spec;
- unsigned int mtu = ndev->mtu;
struct gdma_queue_spec spec;
struct mana_cq *cq = NULL;
struct gdma_context *gc;
@@ -1817,15 +2015,8 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
rxq->rxq_idx = rxq_idx;
rxq->rxobj = INVALID_MANA_HANDLE;

- rxq->datasize = ALIGN(mtu + ETH_HLEN, 64);
-
- if (mtu > MANA_XDP_MTU_MAX) {
- rxq->alloc_size = mtu + MANA_RXBUF_PAD;
- rxq->headroom = 0;
- } else {
- rxq->alloc_size = mtu + MANA_RXBUF_PAD + XDP_PACKET_HEADROOM;
- rxq->headroom = XDP_PACKET_HEADROOM;
- }
+ mana_get_rxbuf_cfg(ndev->mtu, &rxq->datasize, &rxq->alloc_size,
+ &rxq->headroom);

err = mana_alloc_rx_wqe(apc, rxq, &rq_size, &cq_size);
if (err)
@@ -2238,8 +2429,8 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
ndev->netdev_ops = &mana_devops;
ndev->ethtool_ops = &mana_ethtool_ops;
ndev->mtu = ETH_DATA_LEN;
- ndev->max_mtu = ndev->mtu;
- ndev->min_mtu = ndev->mtu;
+ ndev->max_mtu = gc->adapter_mtu - ETH_HLEN;
+ ndev->min_mtu = ETH_MIN_MTU;
ndev->needed_headroom = MANA_HEADROOM;
ndev->dev_port = port_idx;
SET_NETDEV_DEV(ndev, gc->dev);
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index 56189e4252da..96c120160f15 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -145,6 +145,7 @@ struct gdma_general_req {
}; /* HW DATA */

#define GDMA_MESSAGE_V1 1
+#define GDMA_MESSAGE_V2 2

struct gdma_general_resp {
struct gdma_resp_hdr hdr;
@@ -354,6 +355,9 @@ struct gdma_context {
struct gdma_resource msix_resource;
struct gdma_irq_context *irq_contexts;

+ /* L2 MTU */
+ u16 adapter_mtu;
+
/* This maps a CQ index to the queue structure. */
unsigned int max_num_cqs;
struct gdma_queue **cq_table;
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index fee99d704281..cd386aa7c7cc 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -37,6 +37,7 @@ enum TRI_STATE {
#define COMP_ENTRY_SIZE 64

#define RX_BUFFERS_PER_QUEUE 512
+#define MANA_RX_DATA_ALIGN 64

#define MAX_SEND_BUFFERS_PER_QUEUE 256

@@ -390,6 +391,14 @@ struct mana_port_context {
/* This points to an array of num_queues of RQ pointers. */
struct mana_rxq **rxqs;

+ /* pre-allocated rx buffer array */
+ void **rxbufs_pre;
+ dma_addr_t *das_pre;
+ int rxbpre_total;
+ u32 rxbpre_datasize;
+ u32 rxbpre_alloc_size;
+ u32 rxbpre_headroom;
+
struct bpf_prog *bpf_prog;

/* Create num_queues EQs, SQs, SQ-CQs, RQs and RQ-CQs, respectively. */
@@ -489,6 +498,11 @@ struct mana_query_device_cfg_resp {
u16 max_num_vports;
u16 reserved;
u32 max_num_eqs;
+
+ /* response v2: */
+ u16 adapter_mtu;
+ u16 reserved2;
+ u32 reserved3;
}; /* HW DATA */

/* Query vPort Configuration */
--
2.25.1

2023-04-12 21:21:05

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH V3,net-next, 1/4] net: mana: Use napi_build_skb in RX path

Use napi_build_skb() instead of build_skb() to take advantage of the
NAPI percpu caches to obtain skbuff_head.

Signed-off-by: Haiyang Zhang <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
drivers/net/ethernet/microsoft/mana/mana_en.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 492474b4d8aa..112c642dc89b 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -1188,7 +1188,7 @@ static void mana_post_pkt_rxq(struct mana_rxq *rxq)
static struct sk_buff *mana_build_skb(void *buf_va, uint pkt_len,
struct xdp_buff *xdp)
{
- struct sk_buff *skb = build_skb(buf_va, PAGE_SIZE);
+ struct sk_buff *skb = napi_build_skb(buf_va, PAGE_SIZE);

if (!skb)
return NULL;
--
2.25.1

2023-04-13 13:07:37

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Wed, Apr 12, 2023 at 02:16:01PM -0700, Haiyang Zhang wrote:
> Move out common buffer allocation code from mana_process_rx_cqe() and
> mana_alloc_rx_wqe() to helper functions.
> Refactor related variables so they can be changed in one place, and buffer
> sizes are in sync.
>
> Signed-off-by: Haiyang Zhang <[email protected]>
> Reviewed-by: Jesse Brandeburg <[email protected]>
> ---
> V3:
> Refectored to multiple patches for readability. Suggested by Jacob Keller.
>
> V2:
> Refectored to multiple patches for readability. Suggested by Yunsheng Lin.
>
> ---
> drivers/net/ethernet/microsoft/mana/mana_en.c | 154 ++++++++++--------
> include/net/mana/mana.h | 6 +-
> 2 files changed, 91 insertions(+), 69 deletions(-)

<...>

> +static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
> + dma_addr_t *da, bool is_napi)
> +{
> + struct page *page;
> + void *va;
> +
> + /* Reuse XDP dropped page if available */
> + if (rxq->xdp_save_va) {
> + va = rxq->xdp_save_va;
> + rxq->xdp_save_va = NULL;
> + } else {
> + page = dev_alloc_page();

Documentation/networking/page_pool.rst
10 Basic use involves replacing alloc_pages() calls with the
11 page_pool_alloc_pages() call. Drivers should use page_pool_dev_alloc_pages()
12 replacing dev_alloc_pages().

General question, is this sentence applicable to all new code or only
for XDP related paths?

Thanks

2023-04-13 14:14:38

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU



> -----Original Message-----
> From: Leon Romanovsky <[email protected]>
> Sent: Thursday, April 13, 2023 9:04 AM
> To: Haiyang Zhang <[email protected]>
> Cc: [email protected]; [email protected]; Dexuan Cui
> <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> <[email protected]>; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; Long Li <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Ajay Sharma <[email protected]>;
> [email protected]; [email protected]
> Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation
> code to prepare for various MTU
>
> On Wed, Apr 12, 2023 at 02:16:01PM -0700, Haiyang Zhang wrote:
> > Move out common buffer allocation code from mana_process_rx_cqe() and
> > mana_alloc_rx_wqe() to helper functions.
> > Refactor related variables so they can be changed in one place, and buffer
> > sizes are in sync.
> >
> > Signed-off-by: Haiyang Zhang <[email protected]>
> > Reviewed-by: Jesse Brandeburg <[email protected]>
> > ---
> > V3:
> > Refectored to multiple patches for readability. Suggested by Jacob Keller.
> >
> > V2:
> > Refectored to multiple patches for readability. Suggested by Yunsheng Lin.
> >
> > ---
> > drivers/net/ethernet/microsoft/mana/mana_en.c | 154 ++++++++++-------
> -
> > include/net/mana/mana.h | 6 +-
> > 2 files changed, 91 insertions(+), 69 deletions(-)
>
> <...>
>
> > +static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
> > + dma_addr_t *da, bool is_napi)
> > +{
> > + struct page *page;
> > + void *va;
> > +
> > + /* Reuse XDP dropped page if available */
> > + if (rxq->xdp_save_va) {
> > + va = rxq->xdp_save_va;
> > + rxq->xdp_save_va = NULL;
> > + } else {
> > + page = dev_alloc_page();
>
> Documentation/networking/page_pool.rst
> 10 Basic use involves replacing alloc_pages() calls with the
> 11 page_pool_alloc_pages() call. Drivers should use
> page_pool_dev_alloc_pages()
> 12 replacing dev_alloc_pages().
>
> General question, is this sentence applicable to all new code or only
> for XDP related paths?

Quote from the context before that sentence --

=============
Page Pool API
=============
The page_pool allocator is optimized for the XDP mode that uses one frame
per-page, but it can fallback on the regular page allocator APIs.
Basic use involves replacing alloc_pages() calls with the
page_pool_alloc_pages() call. Drivers should use page_pool_dev_alloc_pages()
replacing dev_alloc_pages().

--unquote

So the page pool is optimized for the XDP, and that sentence is applicable to drivers
that have set up page pool for XDP optimization.
static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool) //need a pool been set up

Back to our mana driver, we don't have page pool setup yet. (will consider in the future)
So we cannot call page_pool_dev_alloc_pages(pool) in this place yet.

Thanks,
- Haiyang

2023-04-13 16:37:15

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Thu, Apr 13, 2023 at 02:03:50PM +0000, Haiyang Zhang wrote:
>
>
> > -----Original Message-----
> > From: Leon Romanovsky <[email protected]>
> > Sent: Thursday, April 13, 2023 9:04 AM
> > To: Haiyang Zhang <[email protected]>
> > Cc: [email protected]; [email protected]; Dexuan Cui
> > <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> > <[email protected]>; [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected]; Long Li <[email protected]>;
> > [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; Ajay Sharma <[email protected]>;
> > [email protected]; [email protected]
> > Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation
> > code to prepare for various MTU
> >
> > On Wed, Apr 12, 2023 at 02:16:01PM -0700, Haiyang Zhang wrote:
> > > Move out common buffer allocation code from mana_process_rx_cqe() and
> > > mana_alloc_rx_wqe() to helper functions.
> > > Refactor related variables so they can be changed in one place, and buffer
> > > sizes are in sync.
> > >
> > > Signed-off-by: Haiyang Zhang <[email protected]>
> > > Reviewed-by: Jesse Brandeburg <[email protected]>
> > > ---
> > > V3:
> > > Refectored to multiple patches for readability. Suggested by Jacob Keller.
> > >
> > > V2:
> > > Refectored to multiple patches for readability. Suggested by Yunsheng Lin.
> > >
> > > ---
> > > drivers/net/ethernet/microsoft/mana/mana_en.c | 154 ++++++++++-------
> > -
> > > include/net/mana/mana.h | 6 +-
> > > 2 files changed, 91 insertions(+), 69 deletions(-)
> >
> > <...>
> >
> > > +static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
> > > + dma_addr_t *da, bool is_napi)
> > > +{
> > > + struct page *page;
> > > + void *va;
> > > +
> > > + /* Reuse XDP dropped page if available */
> > > + if (rxq->xdp_save_va) {
> > > + va = rxq->xdp_save_va;
> > > + rxq->xdp_save_va = NULL;
> > > + } else {
> > > + page = dev_alloc_page();
> >
> > Documentation/networking/page_pool.rst
> > 10 Basic use involves replacing alloc_pages() calls with the
> > 11 page_pool_alloc_pages() call. Drivers should use
> > page_pool_dev_alloc_pages()
> > 12 replacing dev_alloc_pages().
> >
> > General question, is this sentence applicable to all new code or only
> > for XDP related paths?
>
> Quote from the context before that sentence --
>
> =============
> Page Pool API
> =============
> The page_pool allocator is optimized for the XDP mode that uses one frame
> per-page, but it can fallback on the regular page allocator APIs.
> Basic use involves replacing alloc_pages() calls with the
> page_pool_alloc_pages() call. Drivers should use page_pool_dev_alloc_pages()
> replacing dev_alloc_pages().
>
> --unquote
>
> So the page pool is optimized for the XDP, and that sentence is applicable to drivers
> that have set up page pool for XDP optimization.

"but it can fallback on the regular page allocator APIs."

> static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool) //need a pool been set up
>
> Back to our mana driver, we don't have page pool setup yet. (will consider in the future)
> So we cannot call page_pool_dev_alloc_pages(pool) in this place yet.

ok, thanks

>
> Thanks,
> - Haiyang
>

2023-04-13 16:48:21

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Thu, 13 Apr 2023 19:30:59 +0300 Leon Romanovsky wrote:
> > So the page pool is optimized for the XDP, and that sentence is applicable to drivers
> > that have set up page pool for XDP optimization.
>
> "but it can fallback on the regular page allocator APIs."

The XDP thing is historic AFAIU, page_pool has been expanded to cover
all uses cases, and is "just better" (tm) than using page allocator
directly. Maybe we should update the doc.

2023-04-13 17:03:50

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Thu, Apr 13, 2023 at 09:40:03AM -0700, Jakub Kicinski wrote:
> On Thu, 13 Apr 2023 19:30:59 +0300 Leon Romanovsky wrote:
> > > So the page pool is optimized for the XDP, and that sentence is applicable to drivers
> > > that have set up page pool for XDP optimization.
> >
> > "but it can fallback on the regular page allocator APIs."
>
> The XDP thing is historic AFAIU, page_pool has been expanded to cover
> all uses cases, and is "just better" (tm) than using page allocator
> directly. Maybe we should update the doc.

The last sentence is always true :)

2023-04-13 17:05:18

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Thu, 13 Apr 2023 19:59:29 +0300 Leon Romanovsky wrote:
>> Maybe we should update the doc.
>
> The last sentence is always true :)

Yeah, I felt bad when writing it :)

2023-04-15 02:06:48

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU

On Wed, 12 Apr 2023 14:16:01 -0700 Haiyang Zhang wrote:
> +/* Allocate frag for rx buffer, and save the old buf */
> +static void mana_refill_rxoob(struct device *dev, struct mana_rxq *rxq,

The fill function is spelled with a _ between rx and oob,
please be consistent.

> + struct mana_recv_buf_oob *rxoob, void **old_buf)
> +{
> + dma_addr_t da;
> + void *va;
> +
> + va = mana_get_rxfrag(rxq, dev, &da, true);
> +

no empty lines between function call and error check.
Please fix this in all the code this patch set is touching.

> + if (!va)
> + return;

2023-04-15 02:38:49

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 0/4] net: mana: Add support for jumbo frame

On Wed, 12 Apr 2023 14:15:59 -0700 Haiyang Zhang wrote:
> The set adds support for jumbo frame,
> with some optimization for the RX path.

Looks like this patch set got silently applied and is already
in net-next :( Please address my feedback with follow up patches.

2023-04-15 02:39:11

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle various MTU sizes

On Wed, 12 Apr 2023 14:16:02 -0700 Haiyang Zhang wrote:
> + } else if (rxq->alloc_size > PAGE_SIZE) {
> + if (is_napi)
> + va = napi_alloc_frag(rxq->alloc_size);

Allocating frag larger than a page is not safe.
Frag allocator falls back to allocating single pages, doesn't it?

2023-04-15 14:14:49

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation code to prepare for various MTU



> -----Original Message-----
> From: Jakub Kicinski <[email protected]>
> Sent: Friday, April 14, 2023 10:05 PM
> To: Haiyang Zhang <[email protected]>
> Cc: [email protected]; [email protected]; Dexuan Cui
> <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> <[email protected]>; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; Long Li <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Ajay Sharma <[email protected]>;
> [email protected]; [email protected]
> Subject: Re: [PATCH V3,net-next, 2/4] net: mana: Refactor RX buffer allocation
> code to prepare for various MTU
>
> On Wed, 12 Apr 2023 14:16:01 -0700 Haiyang Zhang wrote:
> > +/* Allocate frag for rx buffer, and save the old buf */
> > +static void mana_refill_rxoob(struct device *dev, struct mana_rxq *rxq,
>
> The fill function is spelled with a _ between rx and oob,
> please be consistent.

Will do.
>
> > + struct mana_recv_buf_oob *rxoob, void
> **old_buf)
> > +{
> > + dma_addr_t da;
> > + void *va;
> > +
> > + va = mana_get_rxfrag(rxq, dev, &da, true);
> > +
>
> no empty lines between function call and error check.
> Please fix this in all the code this patch set is touching.

Sure. Since the patch set is accepted, I will fix the empty lines
in a new patch.

Thanks,
- Haiyang

2023-04-15 14:19:20

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH V3,net-next, 0/4] net: mana: Add support for jumbo frame



> -----Original Message-----
> From: Jakub Kicinski <[email protected]>
> Sent: Friday, April 14, 2023 10:08 PM
> To: Haiyang Zhang <[email protected]>
> Cc: [email protected]; [email protected]; Dexuan Cui
> <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> <[email protected]>; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; Long Li <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Ajay Sharma <[email protected]>;
> [email protected]; [email protected]
> Subject: Re: [PATCH V3,net-next, 0/4] net: mana: Add support for jumbo
> frame
>
> On Wed, 12 Apr 2023 14:15:59 -0700 Haiyang Zhang wrote:
> > The set adds support for jumbo frame,
> > with some optimization for the RX path.
>
> Looks like this patch set got silently applied and is already
> in net-next :( Please address my feedback with follow up patches.

Will do. Thanks.

2023-04-15 14:32:30

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle various MTU sizes



> -----Original Message-----
> From: Jakub Kicinski <[email protected]>
> Sent: Friday, April 14, 2023 10:06 PM
> To: Haiyang Zhang <[email protected]>
> Cc: [email protected]; [email protected]; Dexuan Cui
> <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> <[email protected]>; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; Long Li <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Ajay Sharma <[email protected]>;
> [email protected]; [email protected]
> Subject: Re: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle
> various MTU sizes
>
> On Wed, 12 Apr 2023 14:16:02 -0700 Haiyang Zhang wrote:
> > + } else if (rxq->alloc_size > PAGE_SIZE) {
> > + if (is_napi)
> > + va = napi_alloc_frag(rxq->alloc_size);
>
> Allocating frag larger than a page is not safe.

I saw other drivers doing this - use napi_alloc_frag for size bigger than a page.
And it returns compound page. Why it's not safe? Should we use other allocator
when need compound pages?

> Frag allocator falls back to allocating single pages, doesn't it?

Actually I checked it. Compound page is still returned for size smaller than PAGE_SIZE,
so I used single page allocation for that.

Thanks,
- Haiyang

2023-04-17 18:05:17

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle various MTU sizes

On Sat, 15 Apr 2023 14:25:29 +0000 Haiyang Zhang wrote:
> > Allocating frag larger than a page is not safe.
>
> I saw other drivers doing this - use napi_alloc_frag for size bigger than a page.
> And it returns compound page. Why it's not safe? Should we use other allocator
> when need compound pages?

I believe so. There was a thread about this within the last year.
Someone was trying to fix the page frag allocator to not fall back
to order 0 pages in case of failure if requested size is > PAGE_SIZE.
But there was push back and folks were saying that it's simply not
a case supported by the frag allocator. ????️

> > Frag allocator falls back to allocating single pages, doesn't it?
>
> Actually I checked it. Compound page is still returned for size smaller than PAGE_SIZE,
> so I used single page allocation for that.

https://elixir.bootlin.com/linux/v6.3-rc6/source/mm/page_alloc.c#L5723

Jumbo frames should really be supported as scatter transfers,
if possible.

2023-04-17 19:57:42

by Haiyang Zhang

[permalink] [raw]
Subject: RE: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle various MTU sizes



> -----Original Message-----
> From: Jakub Kicinski <[email protected]>
> Sent: Monday, April 17, 2023 1:52 PM
> To: Haiyang Zhang <[email protected]>
> Cc: [email protected]; [email protected]; Dexuan Cui
> <[email protected]>; KY Srinivasan <[email protected]>; Paul Rosswurm
> <[email protected]>; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; Long Li <[email protected]>;
> [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; Ajay Sharma <[email protected]>;
> [email protected]; [email protected]
> Subject: Re: [PATCH V3,net-next, 3/4] net: mana: Enable RX path to handle
> various MTU sizes
>
> On Sat, 15 Apr 2023 14:25:29 +0000 Haiyang Zhang wrote:
> > > Allocating frag larger than a page is not safe.
> >
> > I saw other drivers doing this - use napi_alloc_frag for size bigger than a
> page.
> > And it returns compound page. Why it's not safe? Should we use other
> allocator
> > when need compound pages?
>
> I believe so. There was a thread about this within the last year.
> Someone was trying to fix the page frag allocator to not fall back
> to order 0 pages in case of failure if requested size is > PAGE_SIZE.
> But there was push back and folks were saying that it's simply not
> a case supported by the frag allocator. ????️

Thanks, I will use other allocator for compound pages.

>
> > > Frag allocator falls back to allocating single pages, doesn't it?
> >
> > Actually I checked it. Compound page is still returned for size smaller than
> PAGE_SIZE,
> > so I used single page allocation for that.
>
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir
> .bootlin.com%2Flinux%2Fv6.3-
> rc6%2Fsource%2Fmm%2Fpage_alloc.c%23L5723&data=05%7C01%7Chaiyan
> gz%40microsoft.com%7C00ca9f15ae314a4aa2ee08db3f6c8699%7C72f988
> bf86f141af91ab2d7cd011db47%7C1%7C0%7C638173507608724670%7C
> Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJB
> TiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=87QqFbWrxU
> BMtqYpC397nlQxOJfU7lkt2%2FKAOGUjzjw%3D&reserved=0
>
> Jumbo frames should really be supported as scatter transfers,
> if possible.

Our HW has much bigger overhead for scatter transfer on RX, so I use compound
Page.

Thanks,
- Haiyang