Skip to content

Commit 086c161

Browse files
committed
Merge branch 'update-coding-style-and-check-alloc_frag'
Haiyang Zhang says: ==================== 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. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 8e8e47d + df18f2d commit 086c161

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
553553
va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
554554
if (!va)
555555
goto error;
556+
557+
page = virt_to_head_page(va);
558+
/* Check if the frag falls back to single page */
559+
if (compound_order(page) <
560+
get_order(mpc->rxbpre_alloc_size)) {
561+
put_page(page);
562+
goto error;
563+
}
556564
} else {
557565
page = dev_alloc_page();
558566
if (!page)
@@ -563,7 +571,6 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
563571

564572
da = dma_map_single(dev, va + mpc->rxbpre_headroom,
565573
mpc->rxbpre_datasize, DMA_FROM_DEVICE);
566-
567574
if (dma_mapping_error(dev, da)) {
568575
put_page(virt_to_head_page(va));
569576
goto error;
@@ -1505,6 +1512,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
15051512

15061513
if (!va)
15071514
return NULL;
1515+
1516+
page = virt_to_head_page(va);
1517+
/* Check if the frag falls back to single page */
1518+
if (compound_order(page) < get_order(rxq->alloc_size)) {
1519+
put_page(page);
1520+
return NULL;
1521+
}
15081522
} else {
15091523
page = dev_alloc_page();
15101524
if (!page)
@@ -1515,7 +1529,6 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
15151529

15161530
*da = dma_map_single(dev, va + rxq->headroom, rxq->datasize,
15171531
DMA_FROM_DEVICE);
1518-
15191532
if (dma_mapping_error(dev, *da)) {
15201533
put_page(virt_to_head_page(va));
15211534
return NULL;
@@ -1525,14 +1538,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
15251538
}
15261539

15271540
/* Allocate frag for rx buffer, and save the old buf */
1528-
static void mana_refill_rxoob(struct device *dev, struct mana_rxq *rxq,
1529-
struct mana_recv_buf_oob *rxoob, void **old_buf)
1541+
static void mana_refill_rx_oob(struct device *dev, struct mana_rxq *rxq,
1542+
struct mana_recv_buf_oob *rxoob, void **old_buf)
15301543
{
15311544
dma_addr_t da;
15321545
void *va;
15331546

15341547
va = mana_get_rxfrag(rxq, dev, &da, true);
1535-
15361548
if (!va)
15371549
return;
15381550

@@ -1597,7 +1609,7 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq,
15971609
rxbuf_oob = &rxq->rx_oobs[curr];
15981610
WARN_ON_ONCE(rxbuf_oob->wqe_inf.wqe_size_in_bu != 1);
15991611

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

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

0 commit comments

Comments
 (0)