2023-04-21 17:08:39

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH net-next, 0/2] Update coding style and check alloc_frag

Follow up patches for the jumbo frame support.

As suggested by Jakub Kicinski, update coding style, and check napi_alloc_frag
for possible fallback to single pages.

Haiyang Zhang (2):
net: mana: Rename mana_refill_rxoob and remove some empty lines
net: mana: Check if netdev/napi_alloc_frag returns single page

drivers/net/ethernet/microsoft/mana/mana_en.c | 24 ++++++++++++++-----
1 file changed, 18 insertions(+), 6 deletions(-)

--
2.25.1


2023-04-21 17:09:00

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH net-next, 1/2] net: mana: Rename mana_refill_rxoob and remove some empty lines

Rename mana_refill_rxoob for naming consistency.
And remove some empty lines between function call and error
checking.

Signed-off-by: Haiyang Zhang <[email protected]>
---
drivers/net/ethernet/microsoft/mana/mana_en.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index cabecbfa1102..db2887e25714 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -563,7 +563,6 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)

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;
@@ -1515,7 +1514,6 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,

*da = dma_map_single(dev, va + rxq->headroom, rxq->datasize,
DMA_FROM_DEVICE);
-
if (dma_mapping_error(dev, *da)) {
put_page(virt_to_head_page(va));
return NULL;
@@ -1525,14 +1523,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
}

/* 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)
+static void mana_refill_rx_oob(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;

@@ -1597,7 +1594,7 @@ 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);

- mana_refill_rxoob(dev, rxq, rxbuf_oob, &old_buf);
+ mana_refill_rx_oob(dev, rxq, rxbuf_oob, &old_buf);

/* Unsuccessful refill will have old_buf == NULL.
* In this case, mana_rx_skb() will drop the packet.
--
2.25.1

2023-04-21 17:09:09

by Haiyang Zhang

[permalink] [raw]
Subject: [PATCH net-next, 2/2] net: mana: Check if netdev/napi_alloc_frag returns single page

netdev/napi_alloc_frag() may fall back to single page which is smaller
than the requested size.
Add error checking to avoid memory overwritten.

Signed-off-by: Haiyang Zhang <[email protected]>
---
drivers/net/ethernet/microsoft/mana/mana_en.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index db2887e25714..06d6292e09b3 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -553,6 +553,14 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
if (!va)
goto error;
+
+ page = virt_to_head_page(va);
+ /* Check if the frag falls back to single page */
+ if (compound_order(page) <
+ get_order(mpc->rxbpre_alloc_size)) {
+ put_page(page);
+ goto error;
+ }
} else {
page = dev_alloc_page();
if (!page)
@@ -1504,6 +1512,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,

if (!va)
return NULL;
+
+ page = virt_to_head_page(va);
+ /* Check if the frag falls back to single page */
+ if (compound_order(page) < get_order(rxq->alloc_size)) {
+ put_page(page);
+ return NULL;
+ }
} else {
page = dev_alloc_page();
if (!page)
--
2.25.1

2023-04-25 01:18:20

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next, 0/2] Update coding style and check alloc_frag

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <[email protected]>:

On Fri, 21 Apr 2023 10:06:56 -0700 you wrote:
> Follow up patches for the jumbo frame support.
>
> As suggested by Jakub Kicinski, update coding style, and check napi_alloc_frag
> for possible fallback to single pages.
>
> Haiyang Zhang (2):
> net: mana: Rename mana_refill_rxoob and remove some empty lines
> net: mana: Check if netdev/napi_alloc_frag returns single page
>
> [...]

Here is the summary with links:
- [net-next,1/2] net: mana: Rename mana_refill_rxoob and remove some empty lines
https://git.kernel.org/netdev/net-next/c/5c74064f43c2
- [net-next,2/2] net: mana: Check if netdev/napi_alloc_frag returns single page
https://git.kernel.org/netdev/net-next/c/df18f2da302f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


2023-04-25 01:22:59

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next, 0/2] Update coding style and check alloc_frag

On Fri, 21 Apr 2023 10:06:56 -0700 Haiyang Zhang wrote:
> Follow up patches for the jumbo frame support.
>
> As suggested by Jakub Kicinski, update coding style, and check napi_alloc_frag
> for possible fallback to single pages.

Thanks for following up!