eth: mpnic: initial support for Meta Platforms NIC
Subsystems (4)
v2 cover eth: mpnic: initial support for Meta Platforms NIC
Meta Platforms NIC is the second-generation NIC from Meta. There are quite a few high-level similarities to fbnic, but all of the CSRs and descriptors have been reshuffled, and new features have been added. Since the device is sufficiently different from fbnic, and the design of our FW is minimal, we have decided a separate driver is appropriate.
Major new features compared to fbnic will take a while to land. This series includes only the bare-bones Tx/Rx datapath.
Our high-level patch sequence and plan for the upcoming series is:
1. Core datapath (this series)
2. Basic offloads, RSS, and counters
3. Firmware mailbox support
4. Base ethtool operations
This patch series was prepared in part with these LLM prompts:
https://github.com/kuba-moo/ai-prompts/blob/main/driver-upstreaming-prompts.md
The prompts were used to distill our fully-featured OOT driver into this minimal Tx/Rx capable upstream driver. We then performed human review on the output to create this posting. Jakub has made the prompts public in case people would like to take a look.
---
Changes in v2:
- eth: mpnic: add register init for the device
- derive the TQS TXB credit limits from the TXB private credit config
- program the BMC to MAC XOFF threshold (TXB_THRESHOLDS_P0[16])
instead of the host to BMC one, and drop the now unused MPNIC_TXB_BMC_THRESH
- drop L2_HLEN from the default TWD, it only matters for csum/LSO
- eth: mpnic: implement Tx queue allocation and cleanup
- add mpnic_nv_irq_trigger()
- eth: mpnic: add a netdevice and basic Tx handling
- trim the real Tx queue count before register_netdev()
- eth: mpnic: implement Rx queue allocation and cleanup
- drop an inaccurate comment on mpnic_bdq_desc_unused()
- drop the unused data_truesize field from struct mpnic_pkt_ctxt
- trim the real Rx queue count before register_netdev() too
- eth: mpnic: add basic Rx handling
- skip Rx cleaning and BDQ refill when polled with a budget of 0 (netpoll), page pool must not be used in that context
- keep struct mpnic_pkt_ctxt instead of replacing it with a bare xdp_buff, and move add_frag_failed into it
- give each Rx queue only the NAPI budget left over by the previous
ones instead of the full budget
- sync Rx buffers for the CPU with page_pool_dma_sync_for_cpu() instead of dma_sync_single_range_for_cpu()
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Daniel Zahka (7):
eth: mpnic: add scaffolding for Meta Platforms NIC
eth: mpnic: allocate MSI-X vectors
eth: mpnic: implement Tx queue allocation and cleanup
eth: mpnic: start and stop the Tx HW queues
eth: mpnic: add a netdevice and basic Tx handling
eth: mpnic: implement Rx queue allocation and cleanup
eth: mpnic: add basic Rx handling
Mohsin Bashir (1):
eth: mpnic: add register init for the device
drivers/net/ethernet/meta/Kconfig | 13 + drivers/net/ethernet/meta/Makefile | 1 + drivers/net/ethernet/meta/mpnic/Makefile | 16 + drivers/net/ethernet/meta/mpnic/mpnic.h | 66 ++ drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 319 ++++++ drivers/net/ethernet/meta/mpnic/mpnic_init.c | 556 ++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_irq.c | 64 ++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 186 ++++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 35 + drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 187 ++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 1395 ++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 151 +++ 12 files changed, 2989 insertions(+)
---
base-commit: 42a9fb3382fc2573e92f41d203b095d9a372cfc9
change-id: 20260918-linux-mpnic-8fa318d530fa
Best regards,
Signature · 1 line
Daniel Zahka <[email protected]>
PATCH v2 1/8 eth: mpnic: add scaffolding for Meta Platforms NIC
MPNIC is the next network interface controller designed by Meta. Create a bare PCI driver for it. Subsequent changes will flesh it out.
Registers live in BAR0 and are addressed as an array of 32 bit words, which is why the CSR indices are a quarter of the byte offset. Most of the register file is only accessible as 64 bit, so that is the only accessor added here.
If a read returns all ones, a second read to an unused register with reset value 0 is performed to determine if the device is gone. If the device is gone, the mapped BAR0 pointer is cleared, so no further accesses reach the bus.
For now, if mpnic_mmio_err() clears mpd->uc_addr0, nothing will reassign it. The user will have to unbind and rebind the driver. Future series will reset uc_addr0 from pci error handlers.
In addition to being used as a 0 value reference CSR, MPNIC_BDQ_SPARE is also used to perform write flushes, because it can be read without producing side effects.
---
Note: not including an mpnic.rst at this point by design. That will be introduced when the driver actually exposes user-visible statistics or configuration options.
--- drivers/net/ethernet/meta/Kconfig | 12 +++ drivers/net/ethernet/meta/Makefile | 1 + drivers/net/ethernet/meta/mpnic/Makefile | 12 +++ drivers/net/ethernet/meta/mpnic/mpnic.h | 40 ++++++++ drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 24 +++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 147 ++++++++++++++++++++++++++++ 6 files changed, 236 insertions(+)
drivers/net/ethernet/meta/Kconfig +12 -0
@@ -35,4 +35,16 @@ config FBNIC To compile this driver as a module, choose M here. The module will be called fbnic. MSI-X interrupt support is required. +config MPNIC + tristate "Meta Platforms Network Interface Controller" + depends on 64BIT || COMPILE_TEST + depends on !S390 + depends on PCI_MSI + help + This driver supports the Meta Platforms Network Interface + Controller. + + To compile this driver as a module, choose M here. The module + will be called mpnic. + endif # NET_VENDOR_META
drivers/net/ethernet/meta/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_FBNIC) += fbnic/ +obj-$(CONFIG_MPNIC) += mpnic/
drivers/net/ethernet/meta/mpnic/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) Meta Platforms, Inc. and affiliates. + +# +# Makefile for the Meta(R) Platforms Network Interface Controller +# + +obj-$(CONFIG_MPNIC) += mpnic.o + +mpnic-y := \ + mpnic_pci.o \ +# End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_H_ +#define _MPNIC_H_ + +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/types.h> + +#include "mpnic_csr.h" + +#define MPNIC_DRV_NAME "mpnic" + +struct mpnic_dev { +struct device *dev; + +u32 __iomem *uc_addr0; +}; + +u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg); + +static inline void mpnic_wr64 (struct mpnic_dev *mpd,u32 reg,u64 val) +{ +u32 __iomem *csr =READ_ONCE (mpd->uc_addr0); + +if (csr) +writeq (val, csr + reg); +} + +static inline void mpnic_wrfl (struct mpnic_dev *mpd) +{ +mpnic_rd64 (mpd,MPNIC_BDQ_SPARE ); +} + +static inline bool mpnic_present (struct mpnic_dev *mpd) +{ +return !!READ_ONCE (mpd->uc_addr0); +} + +#endif /* _MPNIC_H_ */
drivers/net/ethernet/meta/mpnic/mpnic_csr.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_CSR_H_ +#define _MPNIC_CSR_H_ + +#include <linux/bits.h> + +#define CSR_BIT (nr) BIT_ULL(nr) +#define CSR_GENMASK (h, l) GENMASK_ULL(h, l) + +/* Register Definitions +* +* The register file is addressed as an array of le32, so the byte address of +* a register is 4 times the index below. Each register is listed with its +* name, index and byte address. +* +* Name Index Address +*****************************************************************************/ + +/* NIC_CORE_RBP_HP_GLBL */ +#define MPNIC_BDQ_SPARE 0x42013e/* 0x10804f8 */ + +#endif /* _MPNIC_CSR_H_ */
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 1/8] eth: mpnic: add scaffolding for Meta Platforms NIC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] eth: mpnic: missing PCI BAR0 length validation leads to out-of-bounds MMIO access --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] eth: mpnic: missing PCI BAR0 length validation leads to out-of-bounds MMIO access --
commit 716880959e1661559f15c4ddde5849a4394122ac
Author: Daniel Zahka <[email protected]>
eth: mpnic: add scaffolding for Meta Platforms NIC
This commit introduces a bare PCI driver for the Meta Platforms Network Interface Controller (MPNIC). It maps BAR0 and provides basic 64-bit MMIO accessors with a fallback check to detect removed devices.
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic.h new file +0
-0
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic.h line 27
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic.h new file +6
-0+static inline void mpnic_wr64 (struct mpnic_dev *mpd,u32 reg,u64 val) +{ +u32 __iomem *csr =READ_ONCE (mpd->uc_addr0); + +if (csr) +writeq (val, csr + reg);
[Severity: High]
Does this blind pointer arithmetic risk out-of-bounds MMIO writes?
The generic accessor lacks bounds checking on reg, which could result in writing past the end of the mapped BAR.
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +8
-0+u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg) +{ +u32 __iomem *csr =READ_ONCE (mpd->uc_addr0); +u64 value; + +if (!csr) +return ~0ULL ; +
drivers/net/ethernet/meta/mpnic/mpnic_pci.c line 42
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +10
-0+ value =readq (csr + reg); + +/* If any bits are 0 value should be valid */ +if (~value) +return value; + +/* All ones can be a valid value, so confirm against a register +* which never reads that way on a live device. +*/ +if (reg !=MPNIC_BDQ_SPARE && ~readq (csr +MPNIC_BDQ_SPARE ))
[Severity: High]
Can this fallback check cause a kernel panic if a malicious or spoofed PCIe device advertises a small BAR0?
This unconditionally reads from MPNIC_BDQ_SPARE (index 0x42013e, byte offset 0x10804F8). If the mapped BAR is smaller than ~17.3MB, reading from this hardcoded offset will crash the kernel.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +6
-0+return value; + +mpnic_mmio_err (mpd, reg); + +return ~0ULL ; +}
[ ... ]
Quoted 2 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +2
-0+static int mpnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_pci.c line 99
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +5
-0+ mpd =mpnic_alloc (pdev); +if (!mpd) +return -ENOMEM ; + + uc_addr0 =pcim_iomap_region (pdev,0 ,MPNIC_DRV_NAME );
[Severity: High]
Should we verify the device-provided BAR length before mapping it here?
BAR0 is mapped without checking if pci_resource_len(pdev, 0) is large enough to encompass the driver's register layout. An attacker plugging in untrusted hardware could advertise a small BAR0 (e.g., 4KB) and return all-ones to an initial read. This would force the driver to read from csr + MPNIC_BDQ_SPARE and crash the system.
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +7
-0+if (IS_ERR (uc_addr0)) { + err =PTR_ERR (uc_addr0); +dev_err (&pdev->dev,"Mapping the register file failed: %d\n" , + err); + goto err_free_mpd; + } + mpd->uc_addr0 = uc_addr0;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net-next v2 1/8] eth: mpnic: add scaffolding for Meta Platforms NIC
In reply to Daniel ZahkaThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] eth: mpnic: missing PCI BAR0 length validation leads to out-of- bounds MMIO access
--
Quoted 142 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +137
-0@@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> +#include <linux/types.h> + +#include "mpnic.h" + +#define PCI_DEVICE_ID_META_MPNIC 0x0014 + +static void mpnic_mmio_err (struct mpnic_dev *mpd,u32 reg) +{ +/* Hardware is giving us all 1's reads, assume it is gone */ +WRITE_ONCE (mpd->uc_addr0,NULL ); + +dev_err (mpd->dev, +"Failed read (idx 0x%x AKA addr 0x%x), disabled CSR access, awaiting reset\n" , + reg, reg <<2 ); +} + +u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg) +{ +u32 __iomem *csr =READ_ONCE (mpd->uc_addr0); +u64 value; + +if (!csr) +return ~0ULL ; + + value =readq (csr + reg); + +/* If any bits are 0 value should be valid */ +if (~value) +return value; + +/* All ones can be a valid value, so confirm against a register +* which never reads that way on a live device. +*/ +if (reg !=MPNIC_BDQ_SPARE && ~readq (csr +MPNIC_BDQ_SPARE )) +return value; + +mpnic_mmio_err (mpd, reg); + +return ~0ULL ; +} + +static struct mpnic_dev *mpnic_alloc (struct pci_dev *pdev) +{ +struct mpnic_dev *mpd; + + mpd =kzalloc_obj (*mpd); +if (!mpd) +return NULL ; + +pci_set_drvdata (pdev, mpd); + mpd->dev = &pdev->dev; + +return mpd; +} + +/** +* mpnic_probe - Device initialization routine +* @pdev: PCI device information struct +* @ent: entry in mpnic_pci_tbl +* +* Return: 0 on success, negative on failure +**/ +static int mpnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +void __iomem *uc_addr0; +struct mpnic_dev *mpd; +int err; + +if (pdev->error_state != pci_channel_io_normal) { +dev_err (&pdev->dev, +"PCI device still in an error state. Unable to load...\n" ); +return -EIO ; + } + + err =pcim_enable_device (pdev); +if (err) { +dev_err (&pdev->dev,"PCI enable device failed: %d\n" , err); +return err; + } + + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (46 )); +if (err) { +dev_err (&pdev->dev,"DMA configuration failed: %d\n" , err); +return err; + } + + mpd =mpnic_alloc (pdev); +if (!mpd) +return -ENOMEM ; + + uc_addr0 =pcim_iomap_region (pdev,0 ,MPNIC_DRV_NAME ); +if (IS_ERR (uc_addr0)) { + err =PTR_ERR (uc_addr0); +dev_err (&pdev->dev,"Mapping the register file failed: %d\n" , + err); + goto err_free_mpd; + } + mpd->uc_addr0 = uc_addr0; + +pci_set_master (pdev); +pci_save_state (pdev); + +return 0 ; + +err_free_mpd: +kfree (mpd); + +return err; +} + +/** +* mpnic_remove - Device removal routine +* @pdev: PCI device information struct +**/ +static void mpnic_remove (struct pci_dev *pdev) +{ +struct mpnic_dev *mpd =pci_get_drvdata (pdev); + +kfree (mpd); +} + +static const struct pci_device_id mpnic_pci_tbl[] = { + {PCI_VDEVICE (META ,PCI_DEVICE_ID_META_MPNIC ) }, +/* required last entry */ + {} +}; +MODULE_DEVICE_TABLE (pci, mpnic_pci_tbl); + +static struct pci_driver mpnic_driver = {
drivers/net/ethernet/meta/mpnic/mpnic_pci.c line 147
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +10
-0+ .name = MPNIC_DRV_NAME, + .id_table = mpnic_pci_tbl, + .probe = mpnic_probe, + .remove = mpnic_remove, +}; + +module_pci_driver (mpnic_driver); + +MODULE_DESCRIPTION ("Meta Platforms Network Interface Controller" ); +MODULE_LICENSE ("GPL" );
[Severity: High]mpnic_probe() maps BAR0 with pcim_iomap_region() but never checks pci_resource_len(pdev, 0) against the register file size the driver expects. pcim_iomap_region() maps whatever length the device advertises. A device exposing a small BAR0, including a spoofed one behind Thunderbolt, ends up with a mapping much shorter than the CSR indices in mpnic_csr.h assume.
mpnic_rd64() and mpnic_wr64() compute csr + reg with no bounds check. The all-ones fallback in mpnic_rd64() also unconditionally does a readq() at csr + MPNIC_BDQ_SPARE. That is byte offset 0x10804f8, roughly 16.5MiB into the BAR.
Nothing calls the accessors in this patch yet. Once the follow-ups start touching CSRs from probe, a short BAR plus a single all-ones read would run past the end of the ioremap. That would fault, or hit whatever else happens to be mapped there.
Could you reject the device in probe when BAR0 is too small to hold the register file? For example, compare pci_resource_len(pdev, 0) with the end of the highest CSR the driver touches (at least MPNIC_BDQ_SPARE * 4 + 8) and fail with -ENODEV. What is the architected size of BAR0 on this device?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 1/8] eth: mpnic: add scaffolding for Meta Platforms NIC
Quoted 187 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] eth: mpnic: missing PCI BAR0 length validation leads to out-of- bounds MMIO access
--
Quoted 142 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +137
-0@@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include <linux/dma-mapping.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> +#include <linux/types.h> + +#include "mpnic.h" + +#define PCI_DEVICE_ID_META_MPNIC 0x0014 + +static void mpnic_mmio_err (struct mpnic_dev *mpd,u32 reg) +{ +/* Hardware is giving us all 1's reads, assume it is gone */ +WRITE_ONCE (mpd->uc_addr0,NULL ); + +dev_err (mpd->dev, +"Failed read (idx 0x%x AKA addr 0x%x), disabled CSR access, awaiting reset\n" , + reg, reg <<2 ); +} + +u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg) +{ +u32 __iomem *csr =READ_ONCE (mpd->uc_addr0); +u64 value; + +if (!csr) +return ~0ULL ; + + value =readq (csr + reg); + +/* If any bits are 0 value should be valid */ +if (~value) +return value; + +/* All ones can be a valid value, so confirm against a register +* which never reads that way on a live device. +*/ +if (reg !=MPNIC_BDQ_SPARE && ~readq (csr +MPNIC_BDQ_SPARE )) +return value; + +mpnic_mmio_err (mpd, reg); + +return ~0ULL ; +} + +static struct mpnic_dev *mpnic_alloc (struct pci_dev *pdev) +{ +struct mpnic_dev *mpd; + + mpd =kzalloc_obj (*mpd); +if (!mpd) +return NULL ; + +pci_set_drvdata (pdev, mpd); + mpd->dev = &pdev->dev; + +return mpd; +} + +/** +* mpnic_probe - Device initialization routine +* @pdev: PCI device information struct +* @ent: entry in mpnic_pci_tbl +* +* Return: 0 on success, negative on failure +**/ +static int mpnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +void __iomem *uc_addr0; +struct mpnic_dev *mpd; +int err; + +if (pdev->error_state != pci_channel_io_normal) { +dev_err (&pdev->dev, +"PCI device still in an error state. Unable to load...\n" ); +return -EIO ; + } + + err =pcim_enable_device (pdev); +if (err) { +dev_err (&pdev->dev,"PCI enable device failed: %d\n" , err); +return err; + } + + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (46 )); +if (err) { +dev_err (&pdev->dev,"DMA configuration failed: %d\n" , err); +return err; + } + + mpd =mpnic_alloc (pdev); +if (!mpd) +return -ENOMEM ; + + uc_addr0 =pcim_iomap_region (pdev,0 ,MPNIC_DRV_NAME ); +if (IS_ERR (uc_addr0)) { + err =PTR_ERR (uc_addr0); +dev_err (&pdev->dev,"Mapping the register file failed: %d\n" , + err); + goto err_free_mpd; + } + mpd->uc_addr0 = uc_addr0; + +pci_set_master (pdev); +pci_save_state (pdev); + +return 0 ; + +err_free_mpd: +kfree (mpd); + +return err; +} + +/** +* mpnic_remove - Device removal routine +* @pdev: PCI device information struct +**/ +static void mpnic_remove (struct pci_dev *pdev) +{ +struct mpnic_dev *mpd =pci_get_drvdata (pdev); + +kfree (mpd); +} + +static const struct pci_device_id mpnic_pci_tbl[] = { + {PCI_VDEVICE (META ,PCI_DEVICE_ID_META_MPNIC ) }, +/* required last entry */ + {} +}; +MODULE_DEVICE_TABLE (pci, mpnic_pci_tbl); + +static struct pci_driver mpnic_driver = {drivers/net/ethernet/meta/mpnic/mpnic_pci.c line 147
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +10
-0+ .name = MPNIC_DRV_NAME, + .id_table = mpnic_pci_tbl, + .probe = mpnic_probe, + .remove = mpnic_remove, +}; + +module_pci_driver (mpnic_driver); + +MODULE_DESCRIPTION ("Meta Platforms Network Interface Controller" ); +MODULE_LICENSE ("GPL" );[Severity: High]
mpnic_probe()maps BAR0 withpcim_iomap_region()but never checkspci_resource_len(pdev, 0)against the register file size the driver expects.pcim_iomap_region()maps whatever length the device advertises. A device exposing a small BAR0, including a spoofed one behind Thunderbolt, ends up with a mapping much shorter than the CSR indices inmpnic_csr.hassume.
mpnic_rd64()andmpnic_wr64()compute csr + reg with no bounds check. The all-ones fallback inmpnic_rd64()also unconditionally does areadq()at csr +MPNIC_BDQ_SPARE. That is byte offset0x10804f8, roughly 16.5MiB into the BAR.Nothing calls the accessors in this patch yet. Once the follow-ups start touching CSRs from probe, a short BAR plus a single all-ones read would run past the end of the ioremap. That would fault, or hit whatever else happens to be mapped there.
Quoted 5 lines
Could you reject the device in probe when BAR0 is too small to hold the register file? For example, compare
pci_resource_len(pdev, 0)with the end of the highest CSR the driver touches (at leastMPNIC_BDQ_SPARE* 4 + 8) and fail with-ENODEV. What is the architected size of BAR0 on this device?
This complaint was addressed in v1. For a pci device, we are assuming a malicious or spoofed device is out of scope.
PATCH v2 2/8 eth: mpnic: add register init for the device
In reply to Daniel ZahkaFrom: Mohsin Bashir <[email protected]>
Perform one time register initialization during mpnic_probe(). These CSR settings are either static configs that only need to be set once, or pulses for zeroizing on chip SRAMs, which also only need to be done once.
This initialization is idempotent and does not require any matching deinitialization in the remove path. We can unbind and re-bind the driver and perform the same initialization without problems.
---
v2:
- derive the TQS TXB credit limits from the TXB private credit config
- program the BMC to MAC XOFF threshold (TXB_THRESHOLDS_P0[16]) instead of the host to BMC one, and drop the now unused MPNIC_TXB_BMC_THRESH
- drop L2_HLEN from the default TWD, it only matters for csum/LSO
--- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 9 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 163 ++++++++ drivers/net/ethernet/meta/mpnic/mpnic_init.c | 556 +++++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 8 + 5 files changed, 737 insertions(+)
drivers/net/ethernet/meta/mpnic/Makefile +1 -0
@@ -8,5 +8,6 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ + mpnic_init.o \ mpnic_pci.o \ # End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic.h +9 -0
@@ -11,14 +11,23 @@#define MPNIC_DRV_NAME "mpnic" +#define MPNIC_MAX_TXQS 1024u +#define MPNIC_MAX_RXQS 1024u +struct mpnic_dev {struct device *dev;u32 __iomem *uc_addr0; + +u32 mps; +u32 readrq; +u8 relaxed_ord; };u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg); +int mpnic_dev_init (struct mpnic_dev *mpd); +static inline void mpnic_wr64 (struct mpnic_dev *mpd,u32 reg,u64 val) {u32 __iomem *csr =READ_ONCE (mpd->uc_addr0);
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +163 -0
175 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +556 -0
556 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +8 -0
@@ -58,6 +58,10 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev)pci_set_drvdata (pdev, mpd); mpd->dev = &pdev->dev; + mpd->mps =pcie_get_mps (pdev); + mpd->readrq =pcie_get_readrq (pdev); + mpd->relaxed_ord =pcie_relaxed_ordering_enabled (pdev); +return mpd; }
@@ -108,6 +112,10 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_master (pdev);pci_save_state (pdev); + err =mpnic_dev_init (mpd); +if (err) + goto err_free_mpd; +return 0 ; err_free_mpd:
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 2/8] eth: mpnic: add register init for the device
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] mpnic_dev_init() writes BAR0 CSRs up to MPNIC_OB_ATTR_RDE_P (dword 0x9a001a, byte 0x2680068 + 8, about 38.5 MiB into BAR0), and…
--
eth: mpnic: add register init for the device
This commit adds one-time CSR initialization to mpnic_probe() through a new mpnic_dev_init() in mpnic_init.c. The new code sets static TXB, RXB, TQS, AXI and relaxed-ordering configuration. It also starts SRAM zeroing on several blocks and polls until that finishes.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_pci.c static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 118
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +4
-0@@ -108,6 +112,10 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_master (pdev);pci_save_state (pdev); + err =mpnic_dev_init (mpd); +if (err) + goto err_free_mpd; +
[Severity: Low]
Should mpnic_probe() check the size of BAR0 before mpnic_dev_init() runs?
mpnic_probe() maps BAR0 with pcim_iomap_region() but never compares pci_resource_len(pdev, 0) with the highest CSR offset the driver uses. Neither mpnic_wr64() nor mpnic_rd64() puts an upper limit on reg:
if (csr)
writeq(val, csr + reg);The highest register mpnic_dev_init() writes is MPNIC_OB_ATTR_RDE_P, from mpnic_ro_init(). Its byte offset is 0x2680068, about 38.5 MiB into BAR0. mpnic_desc_sram_init() also issues 4096 writeq() calls at offsets computed from the loop index:
for (i = 0; i < MPNIC_MAX_TXQS * 2; i++)
mpnic_wr64(mpd, MPNIC_TDF_DESC_CFG(i), ...);A device that matches the PCI ID but reports a smaller BAR0 would make these accesses land outside the ioremap'd region during probe.
The PCI core normally trusts BAR sizes reported by the device, and fbnic maps its BARs without a length check too. So this would be defensive hardening rather than a fix for a known failure. Would a check against the largest CSR offset in mpnic_probe() be worth adding?
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0return 0 ; err_free_mpd:
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 2/8] eth: mpnic: add register init for the device
Quoted 52 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low]
mpnic_dev_init()writes BAR0 CSRs up toMPNIC_OB_ATTR_RDE_P(dword0x9a001a, byte0x2680068+ 8, about 38.5 MiB into BAR0), and…--
eth: mpnic: add register init for the device
This commit adds one-time CSR initialization to
mpnic_probe()through a newmpnic_dev_init()inmpnic_init.c. The new code sets static TXB, RXB, TQS, AXI and relaxed-ordering configuration. It also starts SRAM zeroing on several blocks and polls until that finishes.Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_pci.c static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 118
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +4
-0@@ -108,6 +112,10 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_master (pdev);pci_save_state (pdev); + err =mpnic_dev_init (mpd); +if (err) + goto err_free_mpd; +[Severity: Low]
Shouldmpnic_probe()check the size of BAR0 beforempnic_dev_init()runs?
mpnic_probe()maps BAR0 withpcim_iomap_region()but never comparespci_resource_len(pdev, 0)with the highest CSR offset the driver uses. Neithermpnic_wr64()normpnic_rd64()puts an upper limit on reg:if (csr) writeq(val, csr + reg);The highest register
mpnic_dev_init()writes isMPNIC_OB_ATTR_RDE_P, frommpnic_ro_init(). Its byte offset is0x2680068, about 38.5 MiB into BAR0.mpnic_desc_sram_init()also issues 4096writeq()calls at offsets computed from the loop index:for (i = 0; i < MPNIC_MAX_TXQS * 2; i++) mpnic_wr64(mpd, MPNIC_TDF_DESC_CFG(i), ...);
Quoted 11 lines
A device that matches the PCI ID but reports a smaller BAR0 would make these accesses land outside the ioremap'd region during probe.
The PCI core normally trusts BAR sizes reported by the device, and fbnic maps its BARs without a length check too. So this would be defensive hardening rather than a fix for a known failure. Would a check against the largest CSR offset in
mpnic_probe()be worth adding?Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0return 0 ; err_free_mpd:
These are in the range of our 64MiB BAR0.
PATCH v2 3/8 eth: mpnic: allocate MSI-X vectors
In reply to Daniel ZahkaRequest one vector for FW generated interrupts and then one vector per CPU to use for the completion queues. Nothing requests a handler yet, that comes with the NAPI vectors.
--- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 15 +++++++ drivers/net/ethernet/meta/mpnic/mpnic_irq.c | 64 +++++++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 9 +++- 4 files changed, 88 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/mpnic/Makefile +1 -0
@@ -9,5 +9,6 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ mpnic_init.o \ + mpnic_irq.o \ mpnic_pci.o \ # End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic.h +15 -0
@@ -4,6 +4,7 @@#ifndef _MPNIC_H_#define _MPNIC_H_ +#include <linux/interrupt.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/types.h>
@@ -14,11 +15,19 @@#define MPNIC_MAX_TXQS 1024u#define MPNIC_MAX_RXQS 1024u +/* misc IRQ entries are allocated before the completion queue IRQs */ +enum { +MPNIC_FW_MSIX_ENTRY , +MPNIC_NON_NAPI_VECTORS +}; +struct mpnic_dev {struct device *dev;u32 __iomem *uc_addr0; +u16 num_irqs; +u32 mps;u32 readrq;u8 relaxed_ord;
@@ -28,6 +37,12 @@ u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg);int mpnic_dev_init (struct mpnic_dev *mpd); +int mpnic_request_irq (struct mpnic_dev *mpd,int nr,irq_handler_t handler, +unsigned long flags,const char *name,void *data); +void mpnic_free_irq (struct mpnic_dev *mpd,int nr,void *data); +void mpnic_free_irqs (struct mpnic_dev *mpd); +int mpnic_alloc_irqs (struct mpnic_dev *mpd); +static inline void mpnic_wr64 (struct mpnic_dev *mpd,u32 reg,u64 val) {u32 __iomem *csr =READ_ONCE (mpd->uc_addr0);
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +64 -0
64 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +8 -1
@@ -112,12 +112,18 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_master (pdev);pci_save_state (pdev); - err =mpnic_dev_init (mpd); + err =mpnic_alloc_irqs (mpd);if (err) goto err_free_mpd; + err =mpnic_dev_init (mpd); +if (err) + goto err_free_irqs; +return 0 ; +err_free_irqs: +mpnic_free_irqs (mpd); err_free_mpd:kfree (mpd);
@@ -132,6 +138,7 @@ static void mpnic_remove(struct pci_dev *pdev) {struct mpnic_dev *mpd =pci_get_drvdata (pdev); +mpnic_free_irqs (mpd);kfree (mpd); }
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 3/8] eth: mpnic: allocate MSI-X vectors
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The driver frees its MSI-X vectors both by hand and through devres.
--
eth: mpnic: allocate MSI-X vectors
This commit adds mpnic_irq.c, which allocates one MSI-X vector for FW interrupts and one vector per online CPU for the completion queues. The allocation happens in mpnic_probe(). The vectors are freed on the probe error path and in mpnic_remove().
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +0
-0
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_irq.c line 40
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +7
-0+void mpnic_free_irqs (struct mpnic_dev *mpd) +{ +struct pci_dev *pdev =to_pci_dev (mpd->dev); + + mpd->num_irqs =0 ; +pci_free_irq_vectors (pdev); +}
[Severity: Low]
Is it safe to call pci_free_irq_vectors() here when mpnic_probe() enables the device with pcim_enable_device()?
pcim_enable_device() sets pdev->is_managed. Because of that, pci_alloc_irq_vectors() in mpnic_alloc_irqs() ends up in pcim_setup_msi_release():
drivers/pci/msi/msi.c:pcim_setup_msi_release() {
...
if (!pci_is_managed(dev) || dev->is_msi_managed)
return 0;
ret = devm_add_action(&dev->dev, pcim_msi_release, dev);
...
}The kernel-doc for pci_free_irq_vectors() says not to do this:
* WARNING: Do not call this function if the device has been enabled
* with pcim_enable_device(). In that case, IRQ vectors are automatically
* managed via pcim_msi_release() and calling pci_free_irq_vectors() can
* lead to double-free issues.
With this patch, both the err_free_irqs path in mpnic_probe() and mpnic_remove() call mpnic_free_irqs()->pci_free_irq_vectors(). Devres then runs pcim_msi_release()->pci_free_irq_vectors() a second time.
Today the second call does nothing, because pci_disable_msix() returns early when !dev->msix_enabled. That makes it an internal guard, though, not part of the API contract. The TODO in pcim_setup_msi_release() also says the implicit managed mode is slated for removal.
The pattern is still present at the end of the series.
Could the driver pick one owner for the vectors? It could drop the manual pci_free_irq_vectors() and let devres free them. Or it could stop relying on the implicit managed mode, so the explicit free is the only one.
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +3
-0+ +int mpnic_alloc_irqs (struct mpnic_dev *mpd) +{
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0@@ -112,12 +112,18 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
[ ... ]
Quoted 12 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +3
-0+err_free_irqs: +mpnic_free_irqs (mpd); err_free_mpd:kfree (mpd);@@ -132,6 +138,7 @@ static void mpnic_remove(struct pci_dev *pdev) {struct mpnic_dev *mpd =pci_get_drvdata (pdev); +mpnic_free_irqs (mpd);kfree (mpd); }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 3/8] eth: mpnic: allocate MSI-X vectors
Quoted 58 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The driver frees its MSI-X vectors both by hand and through devres.
--
eth: mpnic: allocate MSI-X vectors
This commit adds
mpnic_irq.c, which allocates one MSI-X vector for FW interrupts and one vector per online CPU for the completion queues. The allocation happens inmpnic_probe(). The vectors are freed on the probe error path and inmpnic_remove().Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +0
-0[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_irq.c line 40
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +7
-0+void mpnic_free_irqs (struct mpnic_dev *mpd) +{ +struct pci_dev *pdev =to_pci_dev (mpd->dev); + + mpd->num_irqs =0 ; +pci_free_irq_vectors (pdev); +}[Severity: Low]
Is it safe to callpci_free_irq_vectors()here whenmpnic_probe()enables the device withpcim_enable_device()?
pcim_enable_device()setspdev->is_managed. Because of that,pci_alloc_irq_vectors()inmpnic_alloc_irqs()ends up inpcim_setup_msi_release():drivers/pci/msi/msi.c:pcim_setup_msi_release() { ... if (!pci_is_managed(dev) || dev->is_msi_managed) return 0; ret = devm_add_action(&dev->dev, pcim_msi_release, dev); ... }The kernel-doc for
pci_free_irq_vectors()says not to do this:* WARNING: Do not call this function if the device has been enabled
* withpcim_enable_device(). In that case, IRQ vectors are automatically
* managed viapcim_msi_release()and callingpci_free_irq_vectors()can
* lead to double-free issues.
Quoted 9 lines
With this patch, both the
err_free_irqspath inmpnic_probe()andmpnic_remove()call mpnic_free_irqs()->pci_free_irq_vectors(). Devres then runs pcim_msi_release()->pci_free_irq_vectors() a second time.Today the second call does nothing, because
pci_disable_msix()returns early when !dev->msix_enabled. That makes it an internal guard, though, not part of the API contract. The TODO inpcim_setup_msi_release()also says the implicit managed mode is slated for removal.
For these two reasons (second call idempotent, msix auto enrollment in devrez slated for removal), I think it is ok to keep as is. Let me know if that is a problem.
Quoted 32 lines
The pattern is still present at the end of the series.
Could the driver pick one owner for the vectors? It could drop the manual
pci_free_irq_vectors()and let devres free them. Or it could stop relying on the implicit managed mode, so the explicit free is the only one.Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_irq.c new file +3
-0+ +int mpnic_alloc_irqs (struct mpnic_dev *mpd) +{[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +0
-0@@ -112,12 +112,18 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)[ ... ]
Quoted 12 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +3
-0+err_free_irqs: +mpnic_free_irqs (mpd); err_free_mpd:kfree (mpd);@@ -132,6 +138,7 @@ static void mpnic_remove(struct pci_dev *pdev) {struct mpnic_dev *mpd =pci_get_drvdata (pdev); +mpnic_free_irqs (mpd);kfree (mpd); }
PATCH v2 4/8 eth: mpnic: implement Tx queue allocation and cleanup
In reply to Daniel ZahkaQueues come in triads of two work queues and one completion queue. The Tx triad only uses the first work queue for now, the second one will be used for the XDP ring later.
Add the ring structures, the per NAPI vector allocation of triads, descriptor memory and interrupts, and the completion processing. The completion queue does not report one entry per packet, it reports a work queue head, so a single completion can release many packets.
Nothing enables the queues in hardware or submits anything to them yet, that comes with the next two changes.
---
v2:
- add mpnic_nv_irq_trigger()
--- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 23 ++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 26 ++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 495 +++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 80 ++++ 5 files changed, 625 insertions(+)
drivers/net/ethernet/meta/mpnic/Makefile +1 -0
@@ -11,4 +11,5 @@ mpnic-y := \ mpnic_init.o \ mpnic_irq.o \ mpnic_pci.o \ + mpnic_txrx.o \ # End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +23 -0
@@ -15,6 +15,13 @@/* Transmit Work Descriptor Format */ #define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37) +#define MPNIC_TWD_ADDR DESC_GENMASK(45, 0) +#define MPNIC_TWD_LEN DESC_GENMASK(63, 48) + +/* Tx Completion Descriptor Format */ +#define MPNIC_TCD_TYPE0_HEAD0 DESC_GENMASK(15, 0) +#define MPNIC_TCD_DONE DESC_BIT(63) +/* Common fields for all DESC_CFG CSRs */ #define MPNIC_DESC_CFG_NUM_DESCS CSR_GENMASK(2, 0)#define MPNIC_DESC_CFG_START_ADDR CSR_GENMASK(19, 8)
@@ -28,6 +35,22 @@* Name Index Address *****************************************************************************/ +/* NIC_CORE_TDF */ +#define MPNIC_TWQ_TAIL (i, j) (0x4 + 1024 * (i) + 2 * (j)) +/* 0x10 */ + +/* NIC_CORE_TCM */ +#define MPNIC_TCQ_HEAD (i) (0x8e + 1024 * (i))/* 0x238 */ + +/* NIC_CORE_TIM */ +#define MPNIC_TIM_CTL1 (i) (0xc0 + 1024 * (i))/* 0x300 */ +#define MPNIC_TIM_CTL1_UPD_IGN_LONG_EVENT_CNT CSR_BIT(48) +#define MPNIC_TIM_CTL1_UPD_IGN_LONG_TIME_CNT CSR_BIT(49) +#define MPNIC_TIM_CTL1_UPD_IGN_SHORT_TIME_CNT CSR_BIT(50) +#define MPNIC_TIM_CTL1_MASK CSR_BIT(51) +#define MPNIC_TIM_CTL1_MASK_EN CSR_BIT(52) +#define MPNIC_TIM_CTL1_TRIGGER CSR_BIT(53) +/* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_BDQ_GLBL_CTL0 0x420080/* 0x1080200 */ #define MPNIC_BDQ_GLBL_CTL0_MAX_REQ_SIZE CSR_GENMASK(26, 18)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#ifndef _MPNIC_NETDEV_H_ +#define _MPNIC_NETDEV_H_ + +#include <linux/types.h> + +#include "mpnic.h" +#include "mpnic_txrx.h" + +struct mpnic_net { +struct mpnic_ring *tx[MPNIC_MAX_TXQS ]; + +struct mpnic_napi_vector *napi[MPNIC_MAX_NAPI_VECTORS ]; + +struct net_device *netdev; +struct mpnic_dev *mpd; + +u32 txq_size; + +u16 num_napi; +u16 num_tx_queues; +}; + +#endif /* _MPNIC_NETDEV_H_ */
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +495 -0
495 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 4/8] eth: mpnic: implement Tx queue allocation and cleanup
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] net: mpnic: trusting DMA parameters from device-accessible ring - [High] net: mpnic: missing…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] net: mpnic: trusting DMA parameters from device-accessible ring
- [High] net: mpnic: missing bounds check on hardware completion head causes NULL deref
- [High] net: mpnic: integer underflow in desc_cnt causes massive out-of-bounds unmaps
- [High] net: mpnic: missing memory barrier before completion queue doorbell --
commit 92d64496d6b2ec052301fad8882b705af9c36a85
Author: Daniel Zahka <[email protected]>
eth: mpnic: implement Tx queue allocation and cleanup
This commit introduces the allocation and cleanup of the Tx queues for the mpnic driver. It sets up triads of work and completion queues per NAPI vector, along with their descriptor memory, interrupts, and completion processing.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 66
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +7
-0+static void mpnic_unmap_single_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_single (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +}
[Severity: Critical]
Does this code rely on untrusted DMA parameters?
The descriptor ring memory is device-accessible. If a malicious or buggy PCIe device overwrites the address and length fields after submission, it could trick the host into unmapping arbitrary kernel or IOMMU memory. Should the driver store DMA mapping state in host-only software memory instead?
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 74
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +8
-0+ +static void mpnic_unmap_page_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_page (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +}
[Severity: Critical]
Similar to mpnic_unmap_single_twd(), does this code safely handle potentially spoofed DMA parameters from the hardware ring?
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +7
-0+ +static void mpnic_clean_twq0 (struct mpnic_napi_vector *nv,int napi_budget, +struct mpnic_ring *ring,bool discard, +unsigned int hw_head) +{ +u64 total_bytes =0 , total_packets =0 ; +unsigned int head = ring->head;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 91
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+struct netdev_queue *txq; +unsigned int clean_desc; + + clean_desc = (hw_head - head) & ring->size_mask; + +while (clean_desc) { +struct sk_buff *skb = ring->tx_buf[head]; +unsigned int desc_cnt; + + desc_cnt =MPNIC_XMIT_CB (skb)->desc_count;
[Severity: High]
Is it possible for hw_head to be spoofed by the device, causing an out-of-bounds access?
If the completion queue reports an out-of-bounds hw_head, clean_desc might cover unpopulated slots in the ring buffer. This would result in accessing ring->tx_buf[head] which is NULL, leading to a NULL pointer dereference when accessing MPNIC_XMIT_CB(skb)->desc_count. Should the number of completed descriptors be validated against the number of pending descriptors?
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +8
-0+if (desc_cnt > clean_desc) +break ; + + ring->tx_buf[head] =NULL ; + + clean_desc -= desc_cnt; + +/* Step over the metadata descriptor */
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 109
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+ head++; + head &= ring->size_mask; + desc_cnt--; + +mpnic_unmap_single_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + desc_cnt--; + +while (desc_cnt--) {
[Severity: High]
Can desc_cnt underflow here if desc_cnt is less than 2?
If the completion head is advanced by a malicious device to cover a packet currently being built (where desc_cnt might be 0), the unconditional double decrement will underflow desc_cnt to a massive unsigned value. This would cause the subsequent loop to execute millions of times with out-of-bounds ring indices and out-of-bounds DMA unmaps.
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+mpnic_unmap_page_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + } + + total_bytes +=MPNIC_XMIT_CB (skb)->bytecount; + total_packets++; + +napi_consume_skb (skb, napi_budget); + }
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 146
Quoted 12 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +12
-0+static void mpnic_commit_cq_head (struct mpnic_ring *cmpl) +{ +u32 head = cmpl->head; + +/* The tail shadows the last value written to the doorbell, so a +* completion queue which has not moved costs no MMIO write. +*/ +if (cmpl->tail != head) { + cmpl->tail = head; +writeq (head & cmpl->size_mask, cmpl->doorbell); + } +}
[Severity: High]
Does this MMIO write to the doorbell require a memory barrier to guarantee prior descriptor reads are complete?
On weakly ordered architectures like ARM64, writeq() only provides a Store-Store barrier (wmb()). Without a read-store barrier (like rmb() or dma_rmb()), prior memory loads could be reordered after the doorbell write, potentially allowing the hardware to overwrite descriptors while the CPU is still reading them.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net-next v2 4/8] eth: mpnic: implement Tx queue allocation and cleanup
In reply to Daniel ZahkaThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] net: mpnic: missing bounds check on hardware completion head causes NULL deref
- [High] net: mpnic: integer underflow in desc_cnt causes massive out-of- bounds unmaps
- [Low] struct mpnic_ring::deferred_meta is documented as '-1 if the doorbell is in sync with the tail', yet at this commit the rings come…
--
eth: mpnic: implement Tx queue allocation and cleanup
This adds the Tx ring structures and the per-NAPI-vector allocation of queue triads, descriptor memory and interrupts. It also adds completion processing, where a single completion reports a work queue head and can release many packets. The queues are not yet enabled in hardware.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0@@ -0,0 +1,495 @@
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 243
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +6
-0+static void mpnic_ring_init (struct mpnic_ring *ring,u32 __iomem *doorbell, +int q_idx) +{ + ring->doorbell = doorbell; + ring->q_idx = q_idx; +}
[Severity: Low]
This isn't a bug at this point in the series, but the struct mpnic_ring comment in mpnic_txrx.h describes deferred_meta like this:
/* TWQ only, index of the metadata descriptor of the last packet * placed in the ring without ringing the doorbell, -1 if the * doorbell is in sync with the tail. */ s32 deferred_meta;
mpnic_alloc_napi_vector() gets the rings from kzalloc_flex(), and mpnic_ring_init() never sets deferred_meta. So the field starts at 0, not -1.
Would it make sense to set deferred_meta to -1 in mpnic_ring_init(), so the field matches its comment from the start?
Nothing reads deferred_meta in this commit. The later patch "eth: mpnic:
start and stop the Tx HW queues" adds mpnic_enable_twq(), which sets tail and head to 0 and deferred_meta to -1 on every enable. In mpnic_open() that runs before mpnic_napi_enable() and netif_tx_wake_all_queues(), so this only affects the intermediate state of the series.
[ ... ]
Quoted 100 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +99
-0@@ -0,0 +1,495 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include <linux/bitfield.h> +#include <linux/dma-mapping.h> +#include <linux/pci.h> +#include <linux/slab.h> + +#include "mpnic.h" +#include "mpnic_netdev.h" +#include "mpnic_txrx.h" + +struct mpnic_xmit_cb { +u32 bytecount; +u8 desc_count; +}; + +#define MPNIC_XMIT_CB (__skb) ((struct mpnic_xmit_cb *)((__skb)->cb)) + +/* Leave the interrupt moderation counters alone when arming or masking */ +#define MPNIC_TIM_PARAM_CFG_PRESERVE_MASK \ + (MPNIC_TIM_CTL1_UPD_IGN_LONG_EVENT_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_LONG_TIME_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_SHORT_TIME_CNT) + +static void mpnic_nv_irq_disable (struct mpnic_napi_vector *nv) +{ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | +MPNIC_TIM_CTL1_MASK_EN |MPNIC_TIM_CTL1_MASK ); +} + +static void mpnic_nv_irq_rearm (struct mpnic_napi_vector *nv) +{ +/* Rearming a single queue on a given IRQ rearms all the other +* queues mapped to the same IRQ. +*/ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK |MPNIC_TIM_CTL1_MASK_EN ); +} + +static void mpnic_nv_irq_trigger (struct mpnic_napi_vector *nv) +{ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | +MPNIC_TIM_CTL1_MASK_EN |MPNIC_TIM_CTL1_TRIGGER ); +} + +static unsigned int mpnic_desc_unused (struct mpnic_ring *ring) +{ +return (ring->head - ring->tail -1 ) & ring->size_mask; +} + +static struct netdev_queue *mpnic_txring_txq (const struct net_device *dev, +const struct mpnic_ring *ring) +{ +return netdev_get_tx_queue (dev, ring->q_idx); +} + +static void mpnic_unmap_single_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_single (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +} + +static void mpnic_unmap_page_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_page (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +} + +static void mpnic_clean_twq0 (struct mpnic_napi_vector *nv,int napi_budget, +struct mpnic_ring *ring,bool discard, +unsigned int hw_head) +{ +u64 total_bytes =0 , total_packets =0 ; +unsigned int head = ring->head; +struct netdev_queue *txq; +unsigned int clean_desc; + + clean_desc = (hw_head - head) & ring->size_mask; + +while (clean_desc) { +struct sk_buff *skb = ring->tx_buf[head]; +unsigned int desc_cnt; + + desc_cnt =MPNIC_XMIT_CB (skb)->desc_count; +if (desc_cnt > clean_desc) +break ; + + ring->tx_buf[head] =NULL ; + + clean_desc -= desc_cnt; + +/* Step over the metadata descriptor */
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 109
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+ head++; + head &= ring->size_mask; + desc_cnt--; + +mpnic_unmap_single_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + desc_cnt--; + +while (desc_cnt--) {
[Severity: High]
What happens here if desc_count is 0 or 1? desc_cnt is an unsigned int, and it is decremented twice unconditionally before the frag loop:
once for the metadata descriptor and once for the head descriptor.
With desc_count == 0 the desc_cnt > clean_desc check passes and clean_desc is left unchanged. The second decrement then wraps desc_cnt around to UINT_MAX. The frag loop calls mpnic_unmap_page_twd() about four billion times, walking round and round the ring. Each call hands whatever address and length it finds to dma_unmap_page() from softirq context.
With desc_count == 1, mpnic_unmap_single_twd() is already applied to the following slot, which does not belong to this packet. The same wrap happens after that.
desc_count lives in skb->cb and is only written by the xmit path added later in the series. This relies on every skb in tx_buf carrying a sane count. It also relies on hw_head never covering a packet whose descriptors are still being written. A device reporting a head that runs ahead of what was posted is enough to get here.
Would it make sense to reject desc_cnt < 2 with a WARN_ON_ONCE() before stepping over the metadata descriptor? Possibly desc_cnt > MPNIC_MAX_SKB_DESC should be rejected as well.
Quoted 376 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +376
-0+mpnic_unmap_page_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + } + + total_bytes +=MPNIC_XMIT_CB (skb)->bytecount; + total_packets++; + +napi_consume_skb (skb, napi_budget); + } + +if (!total_bytes) +return ; + + ring->head = head; + +if (discard) +return ; + + txq =mpnic_txring_txq (nv->napi.dev, ring); +netif_txq_completed_wake (txq, total_packets, total_bytes, +mpnic_desc_unused (ring), +MPNIC_TX_DESC_WAKEUP ); +} + +static void mpnic_commit_cq_head (struct mpnic_ring *cmpl) +{ +u32 head = cmpl->head; + +/* The tail shadows the last value written to the doorbell, so a +* completion queue which has not moved costs no MMIO write. +*/ +if (cmpl->tail != head) { + cmpl->tail = head; +writeq (head & cmpl->size_mask, cmpl->doorbell); + } +} + +static void mpnic_clean_tcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int napi_budget) +{ +struct mpnic_ring *cmpl = &qt->cmpl; +__le64 *raw_tcd, done; +u32 head = cmpl->head; +s32 head0 =-1 ; + + done = (head & (cmpl->size_mask +1 )) ?0 :cpu_to_le64 (MPNIC_TCD_DONE ); + raw_tcd = &cmpl->desc[head & cmpl->size_mask]; + +/* Walk the completion queue collecting the heads reported by NIC. +* Only the first work queue is enabled and no packet asks for a +* timestamp, so every completion is a plain head update and the +* descriptor type does not have to be decoded. +*/ +while ((*raw_tcd &cpu_to_le64 (MPNIC_TCD_DONE )) == done) { +u64 tcd; + +dma_rmb (); + + tcd =le64_to_cpu (*raw_tcd); + head0 =FIELD_GET (MPNIC_TCD_TYPE0_HEAD0 , tcd); + + raw_tcd++; + head++; + +if (unlikely (!(head & cmpl->size_mask))) { + done ^=cpu_to_le64 (MPNIC_TCD_DONE ); + raw_tcd = &cmpl->desc[0 ]; + } + } + + cmpl->head = head; + +if (head0 >=0 ) +mpnic_clean_twq0 (nv, napi_budget, &qt->sub0, false, head0); +} + +static int mpnic_poll (struct napi_struct *napi,int budget) +{ +struct mpnic_napi_vector *nv =container_of (napi, + struct mpnic_napi_vector, + napi); +int i; + +for (i =0 ; i < nv->txt_count; i++) +mpnic_clean_tcq (nv, &nv->qt[i], budget); + +for (i =0 ; i < nv->txt_count; i++) +mpnic_commit_cq_head (&nv->qt[i].cmpl); + +if (likely (napi_complete_done (napi,0 ))) +mpnic_nv_irq_rearm (nv); + +return 0 ; +} + +static irqreturn_t mpnic_msix_clean_rings (int __always_unused irq,void *data) +{ +struct mpnic_napi_vector *nv = data; + +napi_schedule_irqoff (&nv->napi); + +return IRQ_HANDLED ; +} + +static void mpnic_free_napi_vector (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i; + +for (i =0 ; i < nv->txt_count; i++) + mpn->tx[nv->qt[i].sub0.q_idx] =NULL ; + +mpnic_free_irq (nv->mpd, nv->v_idx, nv); +netif_napi_del_locked (&nv->napi); + mpn->napi[nv->v_idx -MPNIC_NON_NAPI_VECTORS ] =NULL ; +kfree (nv); +} + +void mpnic_free_napi_vectors (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) +if (mpn->napi[i]) +mpnic_free_napi_vector (mpn, mpn->napi[i]); +} + +static void mpnic_ring_init (struct mpnic_ring *ring,u32 __iomem *doorbell, +int q_idx) +{ + ring->doorbell = doorbell; + ring->q_idx = q_idx; +} + +static int mpnic_alloc_napi_vector (struct mpnic_dev *mpd, +struct mpnic_net *mpn,unsigned int idx) +{ +u32 __iomem *uc_addr =READ_ONCE (mpd->uc_addr0); +struct mpnic_napi_vector *nv; +int err; + +/* Doorbells are plain pointers into the register window, they have +* no way of noticing that it went away. +*/ +if (!uc_addr) +return -EIO ; + + nv =kzalloc_flex (*nv, qt,1 ); +if (!nv) +return -ENOMEM ; + + nv->txt_count =1 ; + nv->mpd = mpd; + nv->dev = mpd->dev; + nv->v_idx = idx +MPNIC_NON_NAPI_VECTORS ; + + mpn->napi[idx] = nv; +netif_napi_add_config_locked (mpn->netdev, &nv->napi, mpnic_poll, idx); +netif_napi_set_irq_locked (&nv->napi, +pci_irq_vector (to_pci_dev (mpd->dev), + nv->v_idx)); + +snprintf (nv->name,sizeof (nv->name),"%s-TxRx-%u" , + mpn->netdev->name, idx); + + err =mpnic_request_irq (mpd, nv->v_idx, mpnic_msix_clean_rings,0 , + nv->name, nv); +if (err) + goto err_napi_del; + +mpnic_ring_init (&nv->qt[0 ].sub0, &uc_addr[MPNIC_TWQ_TAIL (idx,0 )], idx); +mpnic_ring_init (&nv->qt[0 ].cmpl, &uc_addr[MPNIC_TCQ_HEAD (idx)], idx); + mpn->tx[idx] = &nv->qt[0 ].sub0; + +return 0 ; + +err_napi_del: +netif_napi_del_locked (&nv->napi); + mpn->napi[idx] =NULL ; +kfree (nv); +return err; +} + +int mpnic_alloc_napi_vectors (struct mpnic_net *mpn) +{ +unsigned int i; +int err; + +for (i =0 ; i < mpn->num_napi; i++) { + err =mpnic_alloc_napi_vector (mpn->mpd, mpn, i); +if (err) + goto err_free_vectors; + } + +return 0 ; + +err_free_vectors: +mpnic_free_napi_vectors (mpn); + +return err; +} + +static void mpnic_free_ring_resources (struct device *dev, +struct mpnic_ring *ring) +{ +kvfree (ring->tx_buf); + ring->tx_buf =NULL ; + +/* If size is not set there are no descriptors present */ +if (!ring->size) +return ; + +dma_free_coherent (dev, ring->size, ring->desc, ring->dma); + ring->size_mask =0 ; + ring->size =0 ; +} + +static int mpnic_alloc_ring_desc (struct mpnic_net *mpn, +struct mpnic_ring *ring,u32 count) +{ +struct device *dev = mpn->netdev->dev.parent; +size_t size; + + size =ALIGN (array_size (sizeof (*ring->desc), count),4096 ); + + ring->desc =dma_alloc_coherent (dev, size, &ring->dma, +GFP_KERNEL | __GFP_NOWARN); +if (!ring->desc) +return -ENOMEM ; + + ring->size_mask = count -1 ; + ring->size = size; + +return 0 ; +} + +static void mpnic_free_tx_qt_resources (struct mpnic_net *mpn, +struct mpnic_q_triad *qt) +{ +struct device *dev = mpn->netdev->dev.parent; + +mpnic_free_ring_resources (dev, &qt->cmpl); +mpnic_free_ring_resources (dev, &qt->sub0); +} + +static int mpnic_alloc_tx_qt_resources (struct mpnic_net *mpn, +struct mpnic_q_triad *qt) +{ +int err; + + err =mpnic_alloc_ring_desc (mpn, &qt->sub0, mpn->txq_size); +if (err) +return err; + + qt->sub0.tx_buf =kvzalloc_objs (*qt->sub0.tx_buf, mpn->txq_size, +GFP_KERNEL | __GFP_NOWARN); +if (!qt->sub0.tx_buf) { + err = -ENOMEM ; + goto err_free_qt; + } + + err =mpnic_alloc_ring_desc (mpn, &qt->cmpl, mpn->txq_size); +if (err) + goto err_free_qt; + +return 0 ; + +err_free_qt: +mpnic_free_tx_qt_resources (mpn, qt); +return err; +} + +static void mpnic_free_nv_resources (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i; + +for (i =0 ; i < nv->txt_count; i++) +mpnic_free_tx_qt_resources (mpn, &nv->qt[i]); +} + +static int mpnic_alloc_nv_resources (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i, err; + +for (i =0 ; i < nv->txt_count; i++) { + err =mpnic_alloc_tx_qt_resources (mpn, &nv->qt[i]); +if (err) + goto err_free_qt_resources; + } + +return 0 ; + +err_free_qt_resources: +while (i--) +mpnic_free_tx_qt_resources (mpn, &nv->qt[i]); +return err; +} + +void mpnic_free_resources (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) +mpnic_free_nv_resources (mpn, mpn->napi[i]); +} + +int mpnic_alloc_resources (struct mpnic_net *mpn) +{ +int i, err; + +for (i =0 ; i < mpn->num_napi; i++) { + err =mpnic_alloc_nv_resources (mpn, mpn->napi[i]); +if (err) + goto err_free_resources; + } + +return 0 ; + +err_free_resources: +while (i--) +mpnic_free_nv_resources (mpn, mpn->napi[i]); + +return err; +} + +int mpnic_set_netif_queues (struct mpnic_net *mpn) +{ +int i, j, err; + + err =netif_set_real_num_tx_queues (mpn->netdev, mpn->num_tx_queues); +if (err) +return err; + +for (i =0 ; i < mpn->num_napi; i++) { +struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) +netif_queue_set_napi (mpn->netdev, nv->qt[j].sub0.q_idx, +NETDEV_QUEUE_TYPE_TX , &nv->napi); + } + +return 0 ; +} + +void mpnic_reset_netif_queues (struct mpnic_net *mpn) +{ +int i, j; + +for (i =0 ; i < mpn->num_napi; i++) { +struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) +netif_queue_set_napi (mpn->netdev, nv->qt[j].sub0.q_idx, +NETDEV_QUEUE_TYPE_TX ,NULL ); + } +} + +void mpnic_napi_disable (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) { +napi_disable_locked (&mpn->napi[i]->napi); + +mpnic_nv_irq_disable (mpn->napi[i]); + } +} + +void mpnic_napi_enable (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++)
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 495
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+napi_enable_locked (&mpn->napi[i]->napi); + +/* Force the first interrupt on each vector to guarantee that any +* completions posted during bringup are processed. +*/ +for (i =0 ; i < mpn->num_napi; i++) +mpnic_nv_irq_trigger (mpn->napi[i]); + +mpnic_wrfl (mpn->mpd); +}
[Severity: High]
Is hw_head used here without any check against what was actually posted? It comes straight from the TCD read in mpnic_clean_tcq(), and clean_desc is derived only from its distance to ring->head. It is never compared with ring->tail.
The device could report a head beyond the last descriptor the driver posted, for example through a firmware bug or a completion type that mpnic_clean_tcq() does not decode. clean_desc then covers slots that were never filled. tx_buf comes from kvzalloc_objs(), and only the metadata slot of each packet holds an skb. So ring->tx_buf[head] is NULL there, and MPNIC_XMIT_CB(skb)->desc_count dereferences a NULL pointer from NAPI context.
Could clean_desc be clamped to the number of in-flight descriptors, i.e. (ring->tail - head) & ring->size_mask? Alternatively, could the loop bail out with a WARN_ON_ONCE() when it finds an empty tx_buf slot? Ignoring a bogus completion seems preferable to taking the host down.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 4/8] eth: mpnic: implement Tx queue allocation and cleanup
Quoted 57 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] net: mpnic: missing bounds check on hardware completion head causes NULL deref
- [High] net: mpnic: integer underflow indesc_cntcauses massive out-of- bounds unmaps
- [Low] structmpnic_ring::deferred_metais documented as '-1 if the doorbell is in sync with the tail', yet at this commit the rings come…--
eth: mpnic: implement Tx queue allocation and cleanup
This adds the Tx ring structures and the per-NAPI-vector allocation of queue triads, descriptor memory and interrupts. It also adds completion processing, where a single completion reports a work queue head and can release many packets. The queues are not yet enabled in hardware.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0@@ -0,0 +1,495 @@[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 243
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +6
-0+static void mpnic_ring_init (struct mpnic_ring *ring,u32 __iomem *doorbell, +int q_idx) +{ + ring->doorbell = doorbell; + ring->q_idx = q_idx; +}[Severity: Low]
This isn't a bug at this point in the series, but the structmpnic_ringcomment inmpnic_txrx.hdescribesdeferred_metalike this:/* TWQ only, index of the metadata descriptor of the last packet * placed in the ring without ringing the doorbell, -1 if the * doorbell is in sync with the tail. */ s32 deferred_meta;
mpnic_alloc_napi_vector()gets the rings fromkzalloc_flex(), andmpnic_ring_init()never setsdeferred_meta. So the field starts at 0, not -1.
Quoted 9 lines
Would it make sense to set
deferred_metato -1 inmpnic_ring_init(), so the field matches its comment from the start?Nothing reads
deferred_metain this commit. The later patch "eth: mpnic:
start and stop the Tx HW queues" addsmpnic_enable_twq(), which sets tail and head to 0 anddeferred_metato -1 on every enable. Inmpnic_open()that runs beforempnic_napi_enable()andnetif_tx_wake_all_queues(), so this only affects the intermediate state of the series.
Hmm, I guess the comment is slightly ahead of the implementation (next patch)... I suppose introducing deferred_meta later would probably be the solution, but to me that would be a bit out of place, given the other ring fields are really initialized in that next patch.
Quoted 135 lines
[ ... ]
Quoted 100 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +99
-0@@ -0,0 +1,495 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include <linux/bitfield.h> +#include <linux/dma-mapping.h> +#include <linux/pci.h> +#include <linux/slab.h> + +#include "mpnic.h" +#include "mpnic_netdev.h" +#include "mpnic_txrx.h" + +struct mpnic_xmit_cb { +u32 bytecount; +u8 desc_count; +}; + +#define MPNIC_XMIT_CB (__skb) ((struct mpnic_xmit_cb *)((__skb)->cb)) + +/* Leave the interrupt moderation counters alone when arming or masking */ +#define MPNIC_TIM_PARAM_CFG_PRESERVE_MASK \ + (MPNIC_TIM_CTL1_UPD_IGN_LONG_EVENT_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_LONG_TIME_CNT | \ + MPNIC_TIM_CTL1_UPD_IGN_SHORT_TIME_CNT) + +static void mpnic_nv_irq_disable (struct mpnic_napi_vector *nv) +{ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | +MPNIC_TIM_CTL1_MASK_EN |MPNIC_TIM_CTL1_MASK ); +} + +static void mpnic_nv_irq_rearm (struct mpnic_napi_vector *nv) +{ +/* Rearming a single queue on a given IRQ rearms all the other +* queues mapped to the same IRQ. +*/ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK |MPNIC_TIM_CTL1_MASK_EN ); +} + +static void mpnic_nv_irq_trigger (struct mpnic_napi_vector *nv) +{ +mpnic_wr64 (nv->mpd,MPNIC_TIM_CTL1 (nv->qt[0 ].cmpl.q_idx), +MPNIC_TIM_PARAM_CFG_PRESERVE_MASK | +MPNIC_TIM_CTL1_MASK_EN |MPNIC_TIM_CTL1_TRIGGER ); +} + +static unsigned int mpnic_desc_unused (struct mpnic_ring *ring) +{ +return (ring->head - ring->tail -1 ) & ring->size_mask; +} + +static struct netdev_queue *mpnic_txring_txq (const struct net_device *dev, +const struct mpnic_ring *ring) +{ +return netdev_get_tx_queue (dev, ring->q_idx); +} + +static void mpnic_unmap_single_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_single (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +} + +static void mpnic_unmap_page_twd (struct device *dev,__le64 *twd) +{ +u64 raw_twd =le64_to_cpu (*twd); + +dma_unmap_page (dev,FIELD_GET (MPNIC_TWD_ADDR , raw_twd), +FIELD_GET (MPNIC_TWD_LEN , raw_twd),DMA_TO_DEVICE ); +} + +static void mpnic_clean_twq0 (struct mpnic_napi_vector *nv,int napi_budget, +struct mpnic_ring *ring,bool discard, +unsigned int hw_head) +{ +u64 total_bytes =0 , total_packets =0 ; +unsigned int head = ring->head; +struct netdev_queue *txq; +unsigned int clean_desc; + + clean_desc = (hw_head - head) & ring->size_mask; + +while (clean_desc) { +struct sk_buff *skb = ring->tx_buf[head]; +unsigned int desc_cnt; + + desc_cnt =MPNIC_XMIT_CB (skb)->desc_count; +if (desc_cnt > clean_desc) +break ; + + ring->tx_buf[head] =NULL ; + + clean_desc -= desc_cnt; + +/* Step over the metadata descriptor */ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 109
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+ head++; + head &= ring->size_mask; + desc_cnt--; + +mpnic_unmap_single_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + desc_cnt--; + +while (desc_cnt--) {[Severity: High]
What happens here ifdesc_countis 0 or 1?desc_cntis an unsigned int, and it is decremented twice unconditionally before the frag loop:
once for the metadata descriptor and once for the head descriptor.With
desc_count== 0 thedesc_cnt>clean_desccheck passes andclean_descis left unchanged. The second decrement then wrapsdesc_cntaround toUINT_MAX. The frag loop callsmpnic_unmap_page_twd()about four billion times, walking round and round the ring. Each call hands whatever address and length it finds todma_unmap_page()from softirq context.With
desc_count== 1,mpnic_unmap_single_twd()is already applied to the following slot, which does not belong to this packet. The same wrap happens after that.
desc_countlives inskb->cband is only written by the xmit path added later in the series. This relies on every skb intx_bufcarrying a sane count. It also relies onhw_headnever covering a packet whose descriptors are still being written. A device reporting a head that runs ahead of what was posted is enough to get here.
Quoted 4 lines
Would it make sense to reject
desc_cnt< 2 with aWARN_ON_ONCE()before stepping over the metadata descriptor? Possiblydesc_cnt>MPNIC_MAX_SKB_DESCshould be rejected as well.
Not reachable. We control the desc_count that is put into the control block on xmit. We know that we allocate a primary metadata desc and at least one dma mapped region for the skb head.
Quoted 401 lines
Quoted 376 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +376
-0+mpnic_unmap_page_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + } + + total_bytes +=MPNIC_XMIT_CB (skb)->bytecount; + total_packets++; + +napi_consume_skb (skb, napi_budget); + } + +if (!total_bytes) +return ; + + ring->head = head; + +if (discard) +return ; + + txq =mpnic_txring_txq (nv->napi.dev, ring); +netif_txq_completed_wake (txq, total_packets, total_bytes, +mpnic_desc_unused (ring), +MPNIC_TX_DESC_WAKEUP ); +} + +static void mpnic_commit_cq_head (struct mpnic_ring *cmpl) +{ +u32 head = cmpl->head; + +/* The tail shadows the last value written to the doorbell, so a +* completion queue which has not moved costs no MMIO write. +*/ +if (cmpl->tail != head) { + cmpl->tail = head; +writeq (head & cmpl->size_mask, cmpl->doorbell); + } +} + +static void mpnic_clean_tcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int napi_budget) +{ +struct mpnic_ring *cmpl = &qt->cmpl; +__le64 *raw_tcd, done; +u32 head = cmpl->head; +s32 head0 =-1 ; + + done = (head & (cmpl->size_mask +1 )) ?0 :cpu_to_le64 (MPNIC_TCD_DONE ); + raw_tcd = &cmpl->desc[head & cmpl->size_mask]; + +/* Walk the completion queue collecting the heads reported by NIC. +* Only the first work queue is enabled and no packet asks for a +* timestamp, so every completion is a plain head update and the +* descriptor type does not have to be decoded. +*/ +while ((*raw_tcd &cpu_to_le64 (MPNIC_TCD_DONE )) == done) { +u64 tcd; + +dma_rmb (); + + tcd =le64_to_cpu (*raw_tcd); + head0 =FIELD_GET (MPNIC_TCD_TYPE0_HEAD0 , tcd); + + raw_tcd++; + head++; + +if (unlikely (!(head & cmpl->size_mask))) { + done ^=cpu_to_le64 (MPNIC_TCD_DONE ); + raw_tcd = &cmpl->desc[0 ]; + } + } + + cmpl->head = head; + +if (head0 >=0 ) +mpnic_clean_twq0 (nv, napi_budget, &qt->sub0, false, head0); +} + +static int mpnic_poll (struct napi_struct *napi,int budget) +{ +struct mpnic_napi_vector *nv =container_of (napi, + struct mpnic_napi_vector, + napi); +int i; + +for (i =0 ; i < nv->txt_count; i++) +mpnic_clean_tcq (nv, &nv->qt[i], budget); + +for (i =0 ; i < nv->txt_count; i++) +mpnic_commit_cq_head (&nv->qt[i].cmpl); + +if (likely (napi_complete_done (napi,0 ))) +mpnic_nv_irq_rearm (nv); + +return 0 ; +} + +static irqreturn_t mpnic_msix_clean_rings (int __always_unused irq,void *data) +{ +struct mpnic_napi_vector *nv = data; + +napi_schedule_irqoff (&nv->napi); + +return IRQ_HANDLED ; +} + +static void mpnic_free_napi_vector (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i; + +for (i =0 ; i < nv->txt_count; i++) + mpn->tx[nv->qt[i].sub0.q_idx] =NULL ; + +mpnic_free_irq (nv->mpd, nv->v_idx, nv); +netif_napi_del_locked (&nv->napi); + mpn->napi[nv->v_idx -MPNIC_NON_NAPI_VECTORS ] =NULL ; +kfree (nv); +} + +void mpnic_free_napi_vectors (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) +if (mpn->napi[i]) +mpnic_free_napi_vector (mpn, mpn->napi[i]); +} + +static void mpnic_ring_init (struct mpnic_ring *ring,u32 __iomem *doorbell, +int q_idx) +{ + ring->doorbell = doorbell; + ring->q_idx = q_idx; +} + +static int mpnic_alloc_napi_vector (struct mpnic_dev *mpd, +struct mpnic_net *mpn,unsigned int idx) +{ +u32 __iomem *uc_addr =READ_ONCE (mpd->uc_addr0); +struct mpnic_napi_vector *nv; +int err; + +/* Doorbells are plain pointers into the register window, they have +* no way of noticing that it went away. +*/ +if (!uc_addr) +return -EIO ; + + nv =kzalloc_flex (*nv, qt,1 ); +if (!nv) +return -ENOMEM ; + + nv->txt_count =1 ; + nv->mpd = mpd; + nv->dev = mpd->dev; + nv->v_idx = idx +MPNIC_NON_NAPI_VECTORS ; + + mpn->napi[idx] = nv; +netif_napi_add_config_locked (mpn->netdev, &nv->napi, mpnic_poll, idx); +netif_napi_set_irq_locked (&nv->napi, +pci_irq_vector (to_pci_dev (mpd->dev), + nv->v_idx)); + +snprintf (nv->name,sizeof (nv->name),"%s-TxRx-%u" , + mpn->netdev->name, idx); + + err =mpnic_request_irq (mpd, nv->v_idx, mpnic_msix_clean_rings,0 , + nv->name, nv); +if (err) + goto err_napi_del; + +mpnic_ring_init (&nv->qt[0 ].sub0, &uc_addr[MPNIC_TWQ_TAIL (idx,0 )], idx); +mpnic_ring_init (&nv->qt[0 ].cmpl, &uc_addr[MPNIC_TCQ_HEAD (idx)], idx); + mpn->tx[idx] = &nv->qt[0 ].sub0; + +return 0 ; + +err_napi_del: +netif_napi_del_locked (&nv->napi); + mpn->napi[idx] =NULL ; +kfree (nv); +return err; +} + +int mpnic_alloc_napi_vectors (struct mpnic_net *mpn) +{ +unsigned int i; +int err; + +for (i =0 ; i < mpn->num_napi; i++) { + err =mpnic_alloc_napi_vector (mpn->mpd, mpn, i); +if (err) + goto err_free_vectors; + } + +return 0 ; + +err_free_vectors: +mpnic_free_napi_vectors (mpn); + +return err; +} + +static void mpnic_free_ring_resources (struct device *dev, +struct mpnic_ring *ring) +{ +kvfree (ring->tx_buf); + ring->tx_buf =NULL ; + +/* If size is not set there are no descriptors present */ +if (!ring->size) +return ; + +dma_free_coherent (dev, ring->size, ring->desc, ring->dma); + ring->size_mask =0 ; + ring->size =0 ; +} + +static int mpnic_alloc_ring_desc (struct mpnic_net *mpn, +struct mpnic_ring *ring,u32 count) +{ +struct device *dev = mpn->netdev->dev.parent; +size_t size; + + size =ALIGN (array_size (sizeof (*ring->desc), count),4096 ); + + ring->desc =dma_alloc_coherent (dev, size, &ring->dma, +GFP_KERNEL | __GFP_NOWARN); +if (!ring->desc) +return -ENOMEM ; + + ring->size_mask = count -1 ; + ring->size = size; + +return 0 ; +} + +static void mpnic_free_tx_qt_resources (struct mpnic_net *mpn, +struct mpnic_q_triad *qt) +{ +struct device *dev = mpn->netdev->dev.parent; + +mpnic_free_ring_resources (dev, &qt->cmpl); +mpnic_free_ring_resources (dev, &qt->sub0); +} + +static int mpnic_alloc_tx_qt_resources (struct mpnic_net *mpn, +struct mpnic_q_triad *qt) +{ +int err; + + err =mpnic_alloc_ring_desc (mpn, &qt->sub0, mpn->txq_size); +if (err) +return err; + + qt->sub0.tx_buf =kvzalloc_objs (*qt->sub0.tx_buf, mpn->txq_size, +GFP_KERNEL | __GFP_NOWARN); +if (!qt->sub0.tx_buf) { + err = -ENOMEM ; + goto err_free_qt; + } + + err =mpnic_alloc_ring_desc (mpn, &qt->cmpl, mpn->txq_size); +if (err) + goto err_free_qt; + +return 0 ; + +err_free_qt: +mpnic_free_tx_qt_resources (mpn, qt); +return err; +} + +static void mpnic_free_nv_resources (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i; + +for (i =0 ; i < nv->txt_count; i++) +mpnic_free_tx_qt_resources (mpn, &nv->qt[i]); +} + +static int mpnic_alloc_nv_resources (struct mpnic_net *mpn, +struct mpnic_napi_vector *nv) +{ +int i, err; + +for (i =0 ; i < nv->txt_count; i++) { + err =mpnic_alloc_tx_qt_resources (mpn, &nv->qt[i]); +if (err) + goto err_free_qt_resources; + } + +return 0 ; + +err_free_qt_resources: +while (i--) +mpnic_free_tx_qt_resources (mpn, &nv->qt[i]); +return err; +} + +void mpnic_free_resources (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) +mpnic_free_nv_resources (mpn, mpn->napi[i]); +} + +int mpnic_alloc_resources (struct mpnic_net *mpn) +{ +int i, err; + +for (i =0 ; i < mpn->num_napi; i++) { + err =mpnic_alloc_nv_resources (mpn, mpn->napi[i]); +if (err) + goto err_free_resources; + } + +return 0 ; + +err_free_resources: +while (i--) +mpnic_free_nv_resources (mpn, mpn->napi[i]); + +return err; +} + +int mpnic_set_netif_queues (struct mpnic_net *mpn) +{ +int i, j, err; + + err =netif_set_real_num_tx_queues (mpn->netdev, mpn->num_tx_queues); +if (err) +return err; + +for (i =0 ; i < mpn->num_napi; i++) { +struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) +netif_queue_set_napi (mpn->netdev, nv->qt[j].sub0.q_idx, +NETDEV_QUEUE_TYPE_TX , &nv->napi); + } + +return 0 ; +} + +void mpnic_reset_netif_queues (struct mpnic_net *mpn) +{ +int i, j; + +for (i =0 ; i < mpn->num_napi; i++) { +struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) +netif_queue_set_napi (mpn->netdev, nv->qt[j].sub0.q_idx, +NETDEV_QUEUE_TYPE_TX ,NULL ); + } +} + +void mpnic_napi_disable (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++) { +napi_disable_locked (&mpn->napi[i]->napi); + +mpnic_nv_irq_disable (mpn->napi[i]); + } +} + +void mpnic_napi_enable (struct mpnic_net *mpn) +{ +int i; + +for (i =0 ; i < mpn->num_napi; i++)drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 495
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+napi_enable_locked (&mpn->napi[i]->napi); + +/* Force the first interrupt on each vector to guarantee that any +* completions posted during bringup are processed. +*/ +for (i =0 ; i < mpn->num_napi; i++) +mpnic_nv_irq_trigger (mpn->napi[i]); + +mpnic_wrfl (mpn->mpd); +}[Severity: High]
Ishw_headused here without any check against what was actually posted? It comes straight from the TCD read inmpnic_clean_tcq(), andclean_descis derived only from its distance toring->head. It is never compared withring->tail.The device could report a head beyond the last descriptor the driver posted, for example through a firmware bug or a completion type that
mpnic_clean_tcq()does not decode.clean_descthen covers slots that were never filled.tx_bufcomes fromkvzalloc_objs(), and only the metadata slot of each packet holds an skb. So ring->tx_buf[head] is NULL there, and MPNIC_XMIT_CB(skb)->desc_count dereferences a NULL pointer from NAPI context.
Quoted 5 lines
Could
clean_descbe clamped to the number of in-flight descriptors, i.e. (ring->tail- head) &ring->size_mask? Alternatively, could the loop bail out with aWARN_ON_ONCE()when it finds an emptytx_bufslot? Ignoring a bogus completion seems preferable to taking the host down.
We trust the device to fill out this completion field correctly.
PATCH v2 5/8 eth: mpnic: start and stop the Tx HW queues
In reply to Daniel ZahkaPoint the hardware at the descriptor rings and provide functions for turning the Tx queues on and off.
Teardown has to wait for the DMA engines to go idle before the ring memory can be freed: disabling a queue only stops the device picking up new work, it does not tell us that the work already fetched has been retired. Each block exposes an idle bitmap per queue, and every one of the four blocks a packet passes through on its way out has to report idle before the descriptors are safe to free.
--- drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 28 +++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 175 +++++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 4 + 3 files changed, 207 insertions(+)
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +28 -0
@@ -36,11 +36,26 @@*****************************************************************************/ /* NIC_CORE_TDF */ +#define MPNIC_TWQ_CTL (i, j) (0x0 + 1024 * (i) + 2 * (j)) +/* 0x0 */ +#define MPNIC_TWQ_CTL_RESET CSR_BIT(0) +#define MPNIC_TWQ_CTL_ENABLE CSR_BIT(1)#define MPNIC_TWQ_TAIL (i, j) (0x4 + 1024 * (i) + 2 * (j))/* 0x10 */ +#define MPNIC_TWQ_SIZE (i, j) (0x10 + 1024 * (i) + 2 * (j)) +/* 0x40 */ +#define MPNIC_TWQ_SIZE_SIZE CSR_GENMASK(3, 0) +#define MPNIC_TWQ_BASE_ADDR (i, j) (0x1c + 1024 * (i) + 2 * (j)) +/* 0x70 */ /* NIC_CORE_TCM */ +#define MPNIC_TCQ_CTL (i) (0x80 + 1024 * (i))/* 0x200 */ +#define MPNIC_TCQ_CTL_RESET CSR_BIT(0) +#define MPNIC_TCQ_CTL_ENABLE CSR_BIT(1) +#define MPNIC_TCQ_BASE_ADDR (i) (0x86 + 1024 * (i))/* 0x218 */ #define MPNIC_TCQ_HEAD (i) (0x8e + 1024 * (i))/* 0x238 */ +#define MPNIC_TCQ_SIZE (i) (0x94 + 1024 * (i))/* 0x250 */ +#define MPNIC_TCQ_SIZE_SIZE CSR_GENMASK(4, 0)/* NIC_CORE_TIM */ #define MPNIC_TIM_CTL1 (i) (0xc0 + 1024 * (i))/* 0x300 */
@@ -50,6 +65,11 @@#define MPNIC_TIM_CTL1_MASK CSR_BIT(51)#define MPNIC_TIM_CTL1_MASK_EN CSR_BIT(52)#define MPNIC_TIM_CTL1_TRIGGER CSR_BIT(53) +#define MPNIC_TIM_INTR_MASK (i) (0xc8 + 1024 * (i))/* 0x320 */ +#define MPNIC_TIM_INTR_MASK_MASK CSR_BIT(0) + +/* NIC_CORE_TIM_PRV */ +#define MPNIC_TIM_CTL (i) (0x100100 + 1024 * (i))/* 0x400400 */ /* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_BDQ_GLBL_CTL0 0x420080/* 0x1080200 */
@@ -83,6 +103,8 @@#define MPNIC_RNI_RCM_CTL 0x427004/* 0x109c010 */ /* NIC_CORE_TDF_GLBL */ +#define MPNIC_TWQ_IDLE (i) (0x428042 + 2 * (i))/* 0x10a0108 */ +#define MPNIC_TWQ_IDLE_CNT 32#define MPNIC_TWQ_DEF_PRI_TWD 0x428082/* 0x10a0208 */ #define MPNIC_TDF_MEM_INIT_REQ 0x42813a/* 0x10a04e8 */ #define MPNIC_TDF_MEM_INIT_DONE 0x42813c/* 0x10a04f0 */
@@ -100,6 +122,8 @@#define MPNIC_TQS_SLOWDOWN_CTL_ENABLE CSR_BIT(6)#define MPNIC_TQS_MTU_CTL0 0x42a030/* 0x10a80c0 */ #define MPNIC_TQS_MTU_CTL1 0x42a032/* 0x10a80c8 */ +#define MPNIC_TQS_IDLE (i) (0x42a040 + 2 * (i))/* 0x10a8100 */ +#define MPNIC_TQS_IDLE_CNT 32#define MPNIC_TQS_SET_P0_MAP0 (i) (0x42a082 + 2 * (i))/* 0x10a8208 */ #define MPNIC_TQS_SET_P0_MAP1 (i) (0x42a092 + 2 * (i))/* 0x10a8248 */ #define MPNIC_TQS_GLBL_SHAPING 0x42a108/* 0x10a8420 */
@@ -135,10 +159,14 @@#define MPNIC_TQS_PORT_CTL (i) (0x42a1e4 + 2 * (i))/* 0x10a8790 */ /* NIC_CORE_TDE_GLBL */ +#define MPNIC_TDE_IDLE (i) (0x42b000 + 2 * (i))/* 0x10ac000 */ +#define MPNIC_TDE_IDLE_CNT 32#define MPNIC_TDE_MEM_INIT_REQ 0x42b1ee/* 0x10ac7b8 */ #define MPNIC_TDE_MEM_INIT_DONE 0x42b1f0/* 0x10ac7c0 */ /* NIC_CORE_TCM_GLBL */ +#define MPNIC_TCQ_IDLE (i) (0x42c09e + 2 * (i))/* 0x10b0278 */ +#define MPNIC_TCQ_IDLE_CNT 16#define MPNIC_TCM_MEM_INIT_REQ 0x42c0be/* 0x10b02f8 */ #define MPNIC_TCM_MEM_INIT_DONE 0x42c0c0/* 0x10b0300 */
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +175 -0
187 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +4 -0
@@ -76,5 +76,9 @@ int mpnic_set_netif_queues(struct mpnic_net *mpn);void mpnic_reset_netif_queues (struct mpnic_net *mpn);void mpnic_napi_enable (struct mpnic_net *mpn);void mpnic_napi_disable (struct mpnic_net *mpn); +void mpnic_enable (struct mpnic_net *mpn); +void mpnic_disable (struct mpnic_net *mpn); +void mpnic_wait_all_queues_idle (struct mpnic_dev *mpd); +void mpnic_flush (struct mpnic_net *mpn);#endif /* _MPNIC_TXRX_H_ */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 5/8] eth: mpnic: start and stop the Tx HW queues
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] eth: mpnic: swallowed queue idle timeout allows DMA UAF --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] eth: mpnic: swallowed queue idle timeout allows DMA UAF
--
commit 9b058fd2b1d09b6f8ce72863ddb8a3c9c658d5a3
Author: Daniel Zahka <[email protected]>
eth: mpnic: start and stop the Tx HW queues
This commit adds the routines to start and stop the transmit hardware queues for the mpnic device. It provides functions to point the hardware at the descriptor rings and wait for the DMA engines to become idle during teardown.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0+void mpnic_wait_all_queues_idle (struct mpnic_dev *mpd) +{ +static const struct mpnic_idle_regs queues[] = { + {MPNIC_TWQ_IDLE (0 ),MPNIC_TWQ_IDLE_CNT ,"TWQ" }, + {MPNIC_TQS_IDLE (0 ),MPNIC_TQS_IDLE_CNT ,"TQS" }, + {MPNIC_TDE_IDLE (0 ),MPNIC_TDE_IDLE_CNT ,"TDE" }, + {MPNIC_TCQ_IDLE (0 ),MPNIC_TCQ_IDLE_CNT ,"TCQ" },
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 622
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ }; +u32 non_idle_bitmap; +int err; + + err =read_poll_timeout (mpnic_non_idle_queues, non_idle_bitmap, + !non_idle_bitmap,20 ,500000 , false, mpd, + queues,ARRAY_SIZE (queues)); +if (err) +mpnic_idle_dump (mpd, queues,ARRAY_SIZE (queues), + non_idle_bitmap, err);
[Severity: High]
Does this code silently ignore the timeout from read_poll_timeout()?
If the hardware is stalled or under heavy load, read_poll_timeout() times out after 500ms. Because mpnic_wait_all_queues_idle() returns void, it logs the error but hides it from the caller during interface teardown.
Could the caller blindly proceed to free the ring memory back to the page allocator while the active hardware is still performing DMA transfers into it, causing a DMA use-after-free?
Should the error be propagated so the driver can leak the memory or trigger a hardware reset rather than risking memory corruption?
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+} + +void mpnic_flush (struct mpnic_net *mpn)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net-next v2 5/8] eth: mpnic: start and stop the Tx HW queues
In reply to Daniel ZahkaThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] mpnic_wait_all_queues_idle() returns void and drops the -ETIMEDOUT from read_poll_timeout().
- [Low] mpnic_enable_twq() writes fls(size_mask) & MPNIC_TWQ_SIZE_SIZE (a 4-bit field), and mpnic_enable_tcq() writes the same exponent into…
--
eth: mpnic: start and stop the Tx HW queues
This commit writes the Tx work queue and completion queue base addresses and sizes into the hardware. It adds mpnic_enable() and mpnic_disable() to turn the Tx queues on and off. It also adds mpnic_wait_all_queues_idle(), which polls the TWQ, TQS, TDE and TCQ idle bitmaps, and mpnic_flush(), which throws away any Tx work left in the rings.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0@@ -467,6 +468,180 @@ void mpnic_reset_netif_queues(struct mpnic_net *mpn) } } +static void mpnic_enable_twq (struct mpnic_dev *mpd,struct mpnic_ring *twq) +{ +u32 log_size =fls (twq->size_mask); +u32 i = twq->q_idx;
[ ... ]
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+/* Store descriptor ring address and size */ +mpnic_wr64 (mpd,MPNIC_TWQ_BASE_ADDR (i,0 ), twq->dma); +mpnic_wr64 (mpd,MPNIC_TWQ_SIZE (i,0 ), log_size &MPNIC_TWQ_SIZE_SIZE );
[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+static void mpnic_enable_tcq (struct mpnic_dev *mpd, +struct mpnic_napi_vector *nv, +struct mpnic_ring *tcq) +{ +u32 log_size =fls (tcq->size_mask); +u32 i = tcq->q_idx;
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 503
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+/* Store descriptor ring address and size */ +mpnic_wr64 (mpd,MPNIC_TCQ_BASE_ADDR (i), tcq->dma); +mpnic_wr64 (mpd,MPNIC_TCQ_SIZE (i), log_size &MPNIC_TCQ_SIZE_SIZE );
[Severity: Low]
This isn't a bug with the current fixed 1024-entry rings, but mpnic_enable_twq() and mpnic_enable_tcq() mask the same exponent with fields of different widths in mpnic_csr.h:
#define MPNIC_TWQ_SIZE_SIZE CSR_GENMASK(3, 0) #define MPNIC_TCQ_SIZE_SIZE CSR_GENMASK(4, 0)
For a 64K-entry ring (fls() == 16), TWQ_SIZE would get 0 and TCQ_SIZE would get 16. Is this the intended encoding for each register?
fbnic has a comment for the 4-bit form: "Write lower 4 bits of log size as 64K ring size is 0". Would a similar comment help here?
[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+void mpnic_wait_all_queues_idle (struct mpnic_dev *mpd) +{ +static const struct mpnic_idle_regs queues[] = { + {MPNIC_TWQ_IDLE (0 ),MPNIC_TWQ_IDLE_CNT ,"TWQ" }, + {MPNIC_TQS_IDLE (0 ),MPNIC_TQS_IDLE_CNT ,"TQS" }, + {MPNIC_TDE_IDLE (0 ),MPNIC_TDE_IDLE_CNT ,"TDE" }, + {MPNIC_TCQ_IDLE (0 ),MPNIC_TCQ_IDLE_CNT ,"TCQ" }, + };
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 623
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+u32 non_idle_bitmap; +int err; + + err =read_poll_timeout (mpnic_non_idle_queues, non_idle_bitmap, + !non_idle_bitmap,20 ,500000 , false, mpd, + queues,ARRAY_SIZE (queues)); +if (err) +mpnic_idle_dump (mpd, queues,ARRAY_SIZE (queues), + non_idle_bitmap, err); +}
[Severity: High]
What happens to the Tx rings if this poll times out?
The commit message says every block "has to report idle before the descriptors are safe to free". However, the -ETIMEDOUT from read_poll_timeout() is only logged. mpnic_wait_all_queues_idle() returns void, so a caller can't tell a timeout apart from a clean drain.
mpnic_stop() is added later in the series, in "eth: mpnic: add a netdevice and basic Tx handling". It carries on whatever the result:
mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);
mpnic_disable_twq() and mpnic_disable_tcq() only clear the enable bits. TWQ_BASE_ADDR and TCQ_BASE_ADDR still point at the rings.
After a timeout, mpnic_flush()->mpnic_clean_twq0(..., true, tail) unmaps the in-flight Tx buffers and consumes their skbs. Then mpnic_free_ring_resources() calls dma_free_coherent() on the TWQ and TCQ descriptor memory.
Could a Tx engine that is still busy then fetch descriptors or payload from freed memory and put it on the wire? Could the TCM write completion descriptors into memory that now belongs to another user?
fbnic_wait_all_queues_idle() handles the same case differently. It turns on Tx drop through fbnic_tx_flush(), polls again, and returns an int. Would something similar be needed here? At minimum, could the error be returned so the caller can avoid freeing the rings?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 5/8] eth: mpnic: start and stop the Tx HW queues
Quoted 68 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High]
mpnic_wait_all_queues_idle()returns void and drops the-ETIMEDOUTfromread_poll_timeout().
- [Low]mpnic_enable_twq()writesfls(size_mask)&MPNIC_TWQ_SIZE_SIZE(a 4-bit field), andmpnic_enable_tcq()writes the same exponent into…--
eth: mpnic: start and stop the Tx HW queues
This commit writes the Tx work queue and completion queue base addresses and sizes into the hardware. It adds
mpnic_enable()andmpnic_disable()to turn the Tx queues on and off. It also addsmpnic_wait_all_queues_idle(), which polls the TWQ, TQS, TDE and TCQ idle bitmaps, andmpnic_flush(), which throws away any Tx work left in the rings.Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0@@ -467,6 +468,180 @@ void mpnic_reset_netif_queues(struct mpnic_net *mpn) } } +static void mpnic_enable_twq (struct mpnic_dev *mpd,struct mpnic_ring *twq) +{ +u32 log_size =fls (twq->size_mask); +u32 i = twq->q_idx;[ ... ]
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+/* Store descriptor ring address and size */ +mpnic_wr64 (mpd,MPNIC_TWQ_BASE_ADDR (i,0 ), twq->dma); +mpnic_wr64 (mpd,MPNIC_TWQ_SIZE (i,0 ), log_size &MPNIC_TWQ_SIZE_SIZE );[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+static void mpnic_enable_tcq (struct mpnic_dev *mpd, +struct mpnic_napi_vector *nv, +struct mpnic_ring *tcq) +{ +u32 log_size =fls (tcq->size_mask); +u32 i = tcq->q_idx;[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 503
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+/* Store descriptor ring address and size */ +mpnic_wr64 (mpd,MPNIC_TCQ_BASE_ADDR (i), tcq->dma); +mpnic_wr64 (mpd,MPNIC_TCQ_SIZE (i), log_size &MPNIC_TCQ_SIZE_SIZE );[Severity: Low]
This isn't a bug with the current fixed 1024-entry rings, butmpnic_enable_twq()andmpnic_enable_tcq()mask the same exponent with fields of different widths inmpnic_csr.h:
Quoted 6 lines
#define MPNIC_TWQ_SIZE_SIZE CSR_GENMASK(3, 0) #define MPNIC_TCQ_SIZE_SIZE CSR_GENMASK(4, 0)For a 64K-entry ring (
fls()== 16),TWQ_SIZEwould get 0 andTCQ_SIZEwould get 16. Is this the intended encoding for each register?
The code is correct. TWQ has a max ring size of 64k, and that has an encoding of 0 (like fbnic). TCQ actually supports rings as large as 256k, but it does not have/need the 0 encoding for that, as there is an extra bit in the size field.
Quoted 50 lines
fbnic has a comment for the 4-bit form: "Write lower 4 bits of log size as 64K ring size is 0". Would a similar comment help here?
[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+void mpnic_wait_all_queues_idle (struct mpnic_dev *mpd) +{ +static const struct mpnic_idle_regs queues[] = { + {MPNIC_TWQ_IDLE (0 ),MPNIC_TWQ_IDLE_CNT ,"TWQ" }, + {MPNIC_TQS_IDLE (0 ),MPNIC_TQS_IDLE_CNT ,"TQS" }, + {MPNIC_TDE_IDLE (0 ),MPNIC_TDE_IDLE_CNT ,"TDE" }, + {MPNIC_TCQ_IDLE (0 ),MPNIC_TCQ_IDLE_CNT ,"TCQ" }, + };drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 623
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+u32 non_idle_bitmap; +int err; + + err =read_poll_timeout (mpnic_non_idle_queues, non_idle_bitmap, + !non_idle_bitmap,20 ,500000 , false, mpd, + queues,ARRAY_SIZE (queues)); +if (err) +mpnic_idle_dump (mpd, queues,ARRAY_SIZE (queues), + non_idle_bitmap, err); +}[Severity: High]
What happens to the Tx rings if this poll times out?The commit message says every block "has to report idle before the descriptors are safe to free". However, the
-ETIMEDOUTfromread_poll_timeout()is only logged.mpnic_wait_all_queues_idle()returns void, so a caller can't tell a timeout apart from a clean drain.
mpnic_stop()is added later in the series, in "eth: mpnic: add a netdevice and basic Tx handling". It carries on whatever the result:mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);
mpnic_disable_twq()andmpnic_disable_tcq()only clear the enable bits.TWQ_BASE_ADDRandTCQ_BASE_ADDRstill point at the rings.After a timeout, mpnic_flush()->mpnic_clean_twq0(..., true, tail) unmaps the in-flight Tx buffers and consumes their skbs. Then
mpnic_free_ring_resources()callsdma_free_coherent()on the TWQ and TCQ descriptor memory.
Quoted 8 lines
Could a Tx engine that is still busy then fetch descriptors or payload from freed memory and put it on the wire? Could the TCM write completion descriptors into memory that now belongs to another user?
fbnic_wait_all_queues_idle()handles the same case differently. It turns on Tx drop throughfbnic_tx_flush(), polls again, and returns an int. Would something similar be needed here? At minimum, could the error be returned so the caller can avoid freeing the rings?
This was addressed many times in the v1 sashiko review.
PATCH v2 6/8 eth: mpnic: add a netdevice and basic Tx handling
In reply to Daniel ZahkaRegister the network interface and let it transmit skbs.
The typical TWQ descriptor sequence for an skb is: 1 primary metadata, followed by 0 or more non-last address + length (A/L) descriptors, terminated by an always present last A/L descriptor.
The device does not write a Tx completion unless it is requested in the primary metadata desc. The xmit path sets this bit when the stack does not report netdev_xmit_more(). This can create a problem if the last packet in a burst is dropped by the driver. To deal with that case, the driver latches the last metadata for which a completion was not requested, and uses this to request a completion and flush queued packets when one is dropped.
There is no link state yet, so carrier follows the administrative state.
---
v2:
- trim the real Tx queue count before register_netdev()
--- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 2 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 7 + drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 180 +++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 4 + drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 25 ++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 157 +++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 5 + 8 files changed, 381 insertions(+)
drivers/net/ethernet/meta/mpnic/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_MPNIC) += mpnic.o mpnic-y := \ mpnic_init.o \ mpnic_irq.o \ + mpnic_netdev.o \ mpnic_pci.o \ mpnic_txrx.o \ # End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic.h +2 -0
@@ -23,11 +23,13 @@ enum {struct mpnic_dev {struct device *dev; +struct net_device *netdev;u32 __iomem *uc_addr0;u16 num_irqs; +u64 dsn;u32 mps;u32 readrq;u8 relaxed_ord;
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +7 -0
@@ -14,6 +14,13 @@/* Transmit Work Descriptor Format */ #define MPNIC_TWD_FLAG_REQ_COMPLETION DESC_BIT(37) +#define MPNIC_TWD_FLAG_DEST_MAC DESC_BIT(43) +#define MPNIC_TWD_TYPE DESC_GENMASK(47, 46) +enum { +MPNIC_TWD_TYPE_META =0 , +MPNIC_TWD_TYPE_AL =2 , +MPNIC_TWD_TYPE_LAST_AL =3 , +};#define MPNIC_TWD_ADDR DESC_GENMASK(45, 0)#define MPNIC_TWD_LEN DESC_GENMASK(63, 48)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +180 -0
180 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +4 -0
@@ -23,4 +23,8 @@ struct mpnic_net { u16 num_tx_queues; }; +struct net_device *mpnic_netdev_alloc (struct mpnic_dev *mpd); +void mpnic_netdev_free (struct mpnic_dev *mpd); +int mpnic_netdev_register (struct net_device *netdev); +#endif /* _MPNIC_NETDEV_H_ */
drivers/net/ethernet/meta/mpnic/mpnic_pci.c +25 -0
@@ -4,11 +4,13 @@#include <linux/dma-mapping.h> #include <linux/err.h> #include <linux/module.h> +#include <linux/netdevice.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/types.h> #include "mpnic.h" +#include "mpnic_netdev.h" #define PCI_DEVICE_ID_META_MPNIC 0x0014
@@ -20,6 +22,10 @@ static void mpnic_mmio_err(struct mpnic_dev *mpd, u32 reg)dev_err (mpd->dev,"Failed read (idx 0x%x AKA addr 0x%x), disabled CSR access, awaiting reset\n" , reg, reg <<2 ); + +/* Tell the stack the device has lost its PCIe link */ +if (mpd->netdev) +netif_device_detach (mpd->netdev); }u64 mpnic_rd64 (struct mpnic_dev *mpd,u32 reg)
@@ -58,6 +64,7 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev)pci_set_drvdata (pdev, mpd); mpd->dev = &pdev->dev; + mpd->dsn =pci_get_dsn (pdev); mpd->mps =pcie_get_mps (pdev); mpd->readrq =pcie_get_readrq (pdev); mpd->relaxed_ord =pcie_relaxed_ordering_enabled (pdev);
@@ -74,6 +81,7 @@ static struct mpnic_dev *mpnic_alloc(struct pci_dev *pdev)**/ static int mpnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) { +struct net_device *netdev;void __iomem *uc_addr0;struct mpnic_dev *mpd;int err;
@@ -120,8 +128,23 @@ static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (err) goto err_free_irqs; + netdev =mpnic_netdev_alloc (mpd); +if (!netdev) { +dev_err (&pdev->dev,"Netdev allocation failed\n" ); + err = -ENOMEM ; + goto err_free_irqs; + } + + err =mpnic_netdev_register (netdev); +if (err) { +dev_err (&pdev->dev,"Netdev registration failed: %d\n" , err); + goto err_free_netdev; + } +return 0 ; +err_free_netdev: +mpnic_netdev_free (mpd); err_free_irqs:mpnic_free_irqs (mpd); err_free_mpd:
@@ -138,6 +161,8 @@ static void mpnic_remove(struct pci_dev *pdev) {struct mpnic_dev *mpd =pci_get_drvdata (pdev); +unregister_netdev (mpd->netdev); +mpnic_netdev_free (mpd);mpnic_free_irqs (mpd);kfree (mpd); }
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +157 -0
175 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +5 -0
@@ -26,6 +26,10 @@ struct mpnic_net;#define MPNIC_MAX_NAPI_VECTORS 1024u +#define MPNIC_TXQ_SIZE_DEFAULT 1024 + +#define MPNIC_MAX_JUMBO_FRAME_SIZE 9742 +struct mpnic_ring {void **tx_buf;/* Packets outstanding in a TWQ */
@@ -68,6 +72,7 @@ struct mpnic_napi_vector {struct mpnic_q_triad qt[]; }; +netdev_tx_t mpnic_xmit_frame (struct sk_buff *skb,struct net_device *dev);int mpnic_alloc_napi_vectors (struct mpnic_net *mpn);void mpnic_free_napi_vectors (struct mpnic_net *mpn);int mpnic_alloc_resources (struct mpnic_net *mpn);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 6/8] eth: mpnic: add a netdevice and basic Tx handling
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The netdev registered by this patch has no statistics reporting, and Tx drops are not counted anywhere.
- [Medium] mpnic_open() undoes the netif_device_detach() that this patch adds to mpnic_mmio_err(), and reports success on a dead device.
- [Low] Concern: mpnic_netdev_alloc() calls alloc_etherdev_mq(sizeof(*mpn), MPNIC_MAX_RXQS), which leaves…
--
eth: mpnic: add a netdevice and basic Tx handling
This commit registers the mpnic network interface and adds a transmit path. Each skb gets a metadata descriptor followed by address/length descriptors. A completion is requested only when xmit_more is not set. The index of the deferred metadata descriptor is latched, so that dropping a packet can still ring the doorbell for packets already queued.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +0
-0@@ -0,0 +1,180 @@
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +5
-0+static int mpnic_open (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); +int err; +
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 37
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +7
-0+mpnic_enable (mpn); +mpnic_napi_enable (mpn); + +netif_tx_wake_all_queues (netdev); +netif_carrier_on (netdev); + +return 0 ;
[Severity: Medium]
Can this undo the netif_device_detach() that this patch adds to mpnic_mmio_err(), and report a successful open on a dead device?
Suppose the device goes away while the interface is down. mpnic_enable() ends with mpnic_wrfl(), which reads MPNIC_BDQ_SPARE. If that read returns all ones, mpnic_mmio_err() clears uc_addr0 and calls netif_device_detach().
__dev_open() has already set __LINK_STATE_START before calling ndo_open. So the detach clears __LINK_STATE_PRESENT and stops the Tx queues:
__dev_open()
set_bit(__LINK_STATE_START, &dev->state)
mpnic_open()
mpnic_enable()
mpnic_wrfl()
mpnic_rd64(mpd, MPNIC_BDQ_SPARE)
mpnic_mmio_err()
netif_device_detach()
mpnic_napi_enable()
netif_tx_wake_all_queues()
netif_carrier_on()
return 0
mpnic_open() then wakes every queue again, turns the carrier on and returns 0. The interface ends up IFF_UP, with carrier and awake Tx queues, while it is marked not present.
Would mpnic_xmit_frame() then keep mapping skbs and writing to the cached ring->doorbell until the ring fills, with nothing ever completing? The dev watchdog would not fire either, because it requires netif_device_present().
mpnic_netdev_register() checks mpnic_present() before register_netdev() for this same reason. Does mpnic_open() need a similar check after enabling the device, so it can unwind and return an error?
The version of mpnic_open() at the end of the series only adds mpnic_fill(), so it seems to behave the same way.
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 97
Quoted 9 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +9
-0+struct net_device *mpnic_netdev_alloc (struct mpnic_dev *mpd) +{ +struct net_device *netdev; +struct mpnic_net *mpn; +unsigned int queues; + + netdev =alloc_etherdev_mq (sizeof (*mpn),MPNIC_MAX_RXQS ); +if (!netdev) +return NULL ;
[Severity: Low]alloc_etherdev_mq() uses MPNIC_MAX_RXQS for both the Tx and the Rx queue count. Only the Tx count is trimmed later, in mpnic_netdev_register():
err = netif_set_real_num_tx_queues(netdev, mpn->num_tx_queues);
Doesn't that leave real_num_rx_queues at 1024 at this commit? Sysfs and netlink would then list 1024 rx-N queues that have nothing behind them.
This looks resolved later in the series by "eth: mpnic: add basic Rx handling". There, mpnic_netdev_register() and mpnic_set_netif_queues() switch to netif_set_real_num_queues() with num_rx_queues.
There is also a smaller point. The Tx queue count comes from MPNIC_MAX_RXQS, but mpn->tx[] in struct mpnic_net is sized by MPNIC_MAX_TXQS. Both are 1024u today, so the mpn->tx[skb_get_queue_mapping(skb)] lookup in mpnic_xmit_frame() cannot overflow.
Would alloc_etherdev_mqs() with MPNIC_MAX_TXQS and MPNIC_MAX_RXQS express the intent more precisely?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+static netdev_tx_t mpnic_xmit_frame_ring (struct sk_buff *skb, +struct mpnic_ring *ring) +{ +__le64 *meta = &ring->desc[ring->tail]; +u32 tail = ring->tail; + +if (skb_put_padto (skb,MPNIC_MIN_FRAME_LEN )) + goto err_drop;
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+if (mpnic_tx_map (ring, skb, meta)) + goto err_free; + +return NETDEV_TX_OK ;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) · line 225
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ +err_free: +dev_kfree_skb_any (skb); + ring->tx_buf[tail] =NULL ; + ring->tail = tail; +err_drop: +mpnic_tx_flush_doorbell (ring); + +return NETDEV_TX_OK ; +}
[Severity: Medium]
Should these drop paths count the dropped skb somewhere?
- A skb_put_padto() failure goes to err_drop with no log and no counter.
- An mpnic_tx_map() failure (oversized head or frag, or dma_mapping_error()) only logs a rate-limited netdev_err() before dev_kfree_skb_any().
Neither path calls dev_core_stats_tx_dropped_inc() or updates any counter.
More broadly, mpnic_netdev_ops only provides ndo_open, ndo_stop, ndo_validate_addr and ndo_start_xmit:
- There is no ndo_get_stats64.
- pcpu_stat_type is not set.
- dev->stats is never updated.
The per-packet totals in mpnic_clean_twq0() only go to netif_txq_completed_wake() for BQL.
Won't dev_get_stats() report zero for tx_packets, tx_bytes and tx_dropped while traffic is flowing? The last patch in the series, "eth: mpnic: add basic Rx handling", still doesn't add a stats callback.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 6/8] eth: mpnic: add a netdevice and basic Tx handling
Quoted 87 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The netdev registered by this patch has no statistics reporting, and Tx drops are not counted anywhere.
- [Medium]mpnic_open()undoes thenetif_device_detach()that this patch adds tompnic_mmio_err(), and reports success on a dead device.
- [Low] Concern:mpnic_netdev_alloc()callsalloc_etherdev_mq(sizeof(*mpn), MPNIC_MAX_RXQS), which leaves…--
eth: mpnic: add a netdevice and basic Tx handling
This commit registers the mpnic network interface and adds a transmit path. Each skb gets a metadata descriptor followed by address/length descriptors. A completion is requested only when
xmit_moreis not set. The index of the deferred metadata descriptor is latched, so that dropping a packet can still ring the doorbell for packets already queued.Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +0
-0@@ -0,0 +1,180 @@[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +5
-0+static int mpnic_open (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); +int err; +[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 37
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +7
-0+mpnic_enable (mpn); +mpnic_napi_enable (mpn); + +netif_tx_wake_all_queues (netdev); +netif_carrier_on (netdev); + +return 0 ;[Severity: Medium]
Can this undo thenetif_device_detach()that this patch adds tompnic_mmio_err(), and report a successful open on a dead device?Suppose the device goes away while the interface is down.
mpnic_enable()ends withmpnic_wrfl(), which readsMPNIC_BDQ_SPARE. If that read returns all ones,mpnic_mmio_err()clearsuc_addr0and callsnetif_device_detach().
__dev_open()has already set__LINK_STATE_STARTbefore callingndo_open. So the detach clears__LINK_STATE_PRESENTand stops the Tx queues:
__dev_open()
set_bit(__LINK_STATE_START, &dev->state)
mpnic_open()
mpnic_enable()
mpnic_wrfl()
mpnic_rd64(mpd, MPNIC_BDQ_SPARE)
mpnic_mmio_err()
netif_device_detach()
mpnic_napi_enable()
netif_tx_wake_all_queues()
netif_carrier_on()
return 0
mpnic_open()then wakes every queue again, turns the carrier on and returns 0. The interface ends upIFF_UP, with carrier and awake Tx queues, while it is marked not present.Would
mpnic_xmit_frame()then keep mapping skbs and writing to the cachedring->doorbelluntil the ring fills, with nothing ever completing? The dev watchdog would not fire either, because it requiresnetif_device_present().
Quoted 8 lines
mpnic_netdev_register()checksmpnic_present()beforeregister_netdev()for this same reason. Doesmpnic_open()need a similar check after enabling the device, so it can unwind and return an error?The version of
mpnic_open()at the end of the series only addsmpnic_fill(), so it seems to behave the same way.[ ... ]
See my reply in v1: https://lore.kernel.org/all/[email protected]/
Quoted 24 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 97
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +9
-0+struct net_device *mpnic_netdev_alloc (struct mpnic_dev *mpd) +{ +struct net_device *netdev; +struct mpnic_net *mpn; +unsigned int queues; + + netdev =alloc_etherdev_mq (sizeof (*mpn),MPNIC_MAX_RXQS ); +if (!netdev) +return NULL ;[Severity: Low]
alloc_etherdev_mq()usesMPNIC_MAX_RXQSfor both the Tx and the Rx queue count. Only the Tx count is trimmed later, inmpnic_netdev_register():err = netif_set_real_num_tx_queues(netdev, mpn->num_tx_queues);Doesn't that leave
real_num_rx_queuesat 1024 at this commit? Sysfs and netlink would then list 1024 rx-N queues that have nothing behind them.This looks resolved later in the series by "eth: mpnic: add basic Rx handling". There,
mpnic_netdev_register()andmpnic_set_netif_queues()switch tonetif_set_real_num_queues()withnum_rx_queues.
Quoted 9 lines
There is also a smaller point. The Tx queue count comes from
MPNIC_MAX_RXQS, but mpn->tx[] in structmpnic_netis sized byMPNIC_MAX_TXQS. Both are 1024u today, so the mpn->tx[skb_get_queue_mapping(skb)] lookup inmpnic_xmit_frame()cannot overflow.Would
alloc_etherdev_mqs()withMPNIC_MAX_TXQSandMPNIC_MAX_RXQSexpress the intent more precisely?
Like you said the real rx queues half is set in the commit that allocates rx queues. Don't think this needs to change here.
1024 is the right count to use for both tx and rx. The Tx triads have a second submission queue for future use with xdp, but that should not be registered as a real tx queue.
Quoted 52 lines
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+static netdev_tx_t mpnic_xmit_frame_ring (struct sk_buff *skb, +struct mpnic_ring *ring) +{ +__le64 *meta = &ring->desc[ring->tail]; +u32 tail = ring->tail; + +if (skb_put_padto (skb,MPNIC_MIN_FRAME_LEN )) + goto err_drop;[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+if (mpnic_tx_map (ring, skb, meta)) + goto err_free; + +return NETDEV_TX_OK ;drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) · line 225
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ +err_free: +dev_kfree_skb_any (skb); + ring->tx_buf[tail] =NULL ; + ring->tail = tail; +err_drop: +mpnic_tx_flush_doorbell (ring); + +return NETDEV_TX_OK ; +}[Severity: Medium]
Should these drop paths count the dropped skb somewhere?- A
skb_put_padto()failure goes toerr_dropwith no log and no counter.
- Anmpnic_tx_map()failure (oversized head or frag, ordma_mapping_error()) only logs a rate-limitednetdev_err()beforedev_kfree_skb_any().Neither path calls
dev_core_stats_tx_dropped_inc()or updates any counter.More broadly,
mpnic_netdev_opsonly providesndo_open,ndo_stop,ndo_validate_addrandndo_start_xmit:- There is no
ndo_get_stats64.
-pcpu_stat_typeis not set.
-dev->statsis never updated.
Quoted 6 lines
The per-packet totals in
mpnic_clean_twq0()only go tonetif_txq_completed_wake()for BQL.Won't
dev_get_stats()report zero fortx_packets,tx_bytesandtx_droppedwhile traffic is flowing? The last patch in the series, "eth: mpnic: add basic Rx handling", still doesn't add a stats callback.
Stats coming in subsequent series.
PATCH v2 7/8 eth: mpnic: implement Rx queue allocation and cleanup
In reply to Daniel ZahkaThe Rx side of a queue triad is a header queue, a payload queue and a completion queue. With HDS not active yet, frames are split between the two buffer queues at a fixed header boundary: everything up to 1536 bytes lands in the header page, the rest goes to the payload page. Small frames therefore never touch the payload queue, and several of them share one header page.
The device is set to leave headroom and tailroom for XDP and skb_shared_info respectively.
Both queues draw from one page pool per triad and post buffer descriptors to the device in batches.
Even though we do not support XDP yet, use the XDP APIs for tracking pre-skb buffers. The XDP buffer handling helpers save us from reimplementing the same logic in the driver.
---
v2:
- drop an inaccurate comment on mpnic_bdq_desc_unused()
- drop the unused data_truesize field from struct mpnic_pkt_ctxt
- trim the real Rx queue count before register_netdev() too
--- drivers/net/ethernet/meta/Kconfig | 1 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 67 ++++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 8 +- drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 5 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 447 +++++++++++++++++++++++-- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 71 +++- 6 files changed, 554 insertions(+), 45 deletions(-)
drivers/net/ethernet/meta/Kconfig +1 -0
@@ -40,6 +40,7 @@ config MPNIC depends on 64BIT || COMPILE_TEST depends on !S390 depends on PCI_MSI + select PAGE_POOL help This driver supports the Meta Platforms Network Interface Controller.
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +67 -0
89 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +7 -1
@@ -29,6 +29,7 @@ static int mpnic_open(struct net_device *netdev) goto err_free_resources;mpnic_enable (mpn); +mpnic_fill (mpn);mpnic_napi_enable (mpn);netif_tx_wake_all_queues (netdev);
@@ -107,10 +108,14 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd) mpn->mpd = mpd; mpn->txq_size =MPNIC_TXQ_SIZE_DEFAULT ; + mpn->hpq_size =MPNIC_HPQ_SIZE_DEFAULT ; + mpn->ppq_size =MPNIC_PPQ_SIZE_DEFAULT ; + mpn->rcq_size =MPNIC_RCQ_SIZE_DEFAULT ; queues =min (netif_get_num_default_rss_queues (), mpd->num_irqs -MPNIC_NON_NAPI_VECTORS ); mpn->num_tx_queues = queues; + mpn->num_rx_queues = queues; mpn->num_napi = queues; netdev->features |=NETIF_F_SG ;
@@ -165,7 +170,8 @@ int mpnic_netdev_register(struct net_device *netdev)ether_addr_copy (netdev->perm_addr, addr);eth_hw_addr_set (netdev, addr); - err =netif_set_real_num_tx_queues (netdev, mpn->num_tx_queues); + err =netif_set_real_num_queues (netdev, mpn->num_tx_queues, + mpn->num_rx_queues);if (err)return err;
drivers/net/ethernet/meta/mpnic/mpnic_netdev.h +5 -0
@@ -11,6 +11,7 @@struct mpnic_net {struct mpnic_ring *tx[MPNIC_MAX_TXQS ]; +struct mpnic_ring *rx[MPNIC_MAX_RXQS ];struct mpnic_napi_vector *napi[MPNIC_MAX_NAPI_VECTORS ];
@@ -18,9 +19,13 @@ struct mpnic_net {struct mpnic_dev *mpd;u32 txq_size; +u32 hpq_size; +u32 ppq_size; +u32 rcq_size;u16 num_napi;u16 num_tx_queues; +u16 num_rx_queues; };struct net_device *mpnic_netdev_alloc (struct mpnic_dev *mpd);
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +411 -36
586 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +63 -8
114 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 7/8] eth: mpnic: implement Rx queue allocation and cleanup
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In mpnic_stop() (drivers/net/ethernet/meta/mpnic/mpnic_netdev.c), Rx teardown frees…
--
eth: mpnic: implement Rx queue allocation and cleanup
This commit adds the Rx side of the mpnic queue triad: a header buffer queue, a payload buffer queue and a completion queue. All three share one page pool per triad. It also adds the enable/disable, fill and flush paths, and adds the HPQ, PPQ and RCQ blocks to the idle wait done on teardown.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 12 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -767,6 +1084,9 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) { MPNIC_TQS_IDLE(0), MPNIC_TQS_IDLE_CNT, "TQS" }, { MPNIC_TDE_IDLE(0), MPNIC_TDE_IDLE_CNT, "TDE" }, { MPNIC_TCQ_IDLE(0), MPNIC_TCQ_IDLE_CNT, "TCQ" }, + { MPNIC_HPQ_IDLE(0), MPNIC_HPQ_IDLE_CNT, "HPQ" }, + { MPNIC_PPQ_IDLE(0), MPNIC_PPQ_IDLE_CNT, "PPQ" }, + { MPNIC_RCQ_IDLE(0), MPNIC_RCQ_IDLE_CNT, "RCQ" }, };u32 non_idle_bitmap;int err;@@ -779,15 +1099,31 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) non_idle_bitmap, err);
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) · line 1109
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0} +static void mpnic_clean_bdq (struct mpnic_ring *bdq) +{ +unsigned int head = bdq->head; + +while (head != bdq->tail) { +struct page *page = bdq->rx_buf[head]; + +page_pool_put_full_page (page->pp, page, false);
[Severity: Medium]
What happens to these Rx buffers if the idle poll times out? mpnic_wait_all_queues_idle() returns void. On timeout it only logs:
err = read_poll_timeout(mpnic_non_idle_queues, non_idle_bitmap, !non_idle_bitmap, 20, 500000, false, mpd, queues, ARRAY_SIZE(queues)); if (err) mpnic_idle_dump(mpd, queues, ARRAY_SIZE(queues), non_idle_bitmap, err);
mpnic_stop() then carries on with teardown either way:
mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);
Two things happen after that:
- mpnic_flush()->mpnic_clean_bdq() gives every page still posted in [head, tail) back to the page pool.
- mpnic_free_resources()->mpnic_free_rx_qt_resources() frees the HPQ, PPQ and RCQ descriptor rings with dma_free_coherent(), then calls page_pool_destroy().
Before this patch, the same timeout-and-continue path only covered Tx, where the device reads host memory. Now there are DMA_FROM_DEVICE page pool buffers and an RCQ that the device writes to.
If the device has not quiesced when the poll gives up, could it write frame data into freed or reused pages, or write completions into the freed RCQ ring?
Separately, the earlier commit "eth: mpnic: start and stop the Tx HW queues" says every block a packet passes through must report idle before memory is safe to free. The Rx idle table here covers HPQ, PPQ and RCQ, but it has no Rx DMA engine entry to match TDE on the Tx side. The only RDE registers defined are CFG, CTL and the MEM_INIT ones.
Does RCQ reporting idle guarantee that the RDE has no writes in flight? If not, should an RDE idle entry be polled here as well?
This code is still the same at the end of the series, in "eth: mpnic:
add basic Rx handling".
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0+ + head++; + head &= bdq->size_mask; + } + + bdq->head = head; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 7/8] eth: mpnic: implement Rx queue allocation and cleanup
Quoted 102 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In
mpnic_stop()(drivers/net/ethernet/meta/mpnic/mpnic_netdev.c), Rx teardown frees…--
eth: mpnic: implement Rx queue allocation and cleanup
This commit adds the Rx side of the mpnic queue triad: a header buffer queue, a payload buffer queue and a completion queue. All three share one page pool per triad. It also adds the enable/disable, fill and flush paths, and adds the HPQ, PPQ and RCQ blocks to the idle wait done on teardown.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0[ ... ]
Quoted 12 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -767,6 +1084,9 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) { MPNIC_TQS_IDLE(0), MPNIC_TQS_IDLE_CNT, "TQS" }, { MPNIC_TDE_IDLE(0), MPNIC_TDE_IDLE_CNT, "TDE" }, { MPNIC_TCQ_IDLE(0), MPNIC_TCQ_IDLE_CNT, "TCQ" }, + { MPNIC_HPQ_IDLE(0), MPNIC_HPQ_IDLE_CNT, "HPQ" }, + { MPNIC_PPQ_IDLE(0), MPNIC_PPQ_IDLE_CNT, "PPQ" }, + { MPNIC_RCQ_IDLE(0), MPNIC_RCQ_IDLE_CNT, "RCQ" }, };u32 non_idle_bitmap;int err;@@ -779,15 +1099,31 @@ void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) non_idle_bitmap, err);drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) · line 1109
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0} +static void mpnic_clean_bdq (struct mpnic_ring *bdq) +{ +unsigned int head = bdq->head; + +while (head != bdq->tail) { +struct page *page = bdq->rx_buf[head]; + +page_pool_put_full_page (page->pp, page, false);[Severity: Medium]
What happens to these Rx buffers if the idle poll times out?mpnic_wait_all_queues_idle()returns void. On timeout it only logs:err = read_poll_timeout(mpnic_non_idle_queues, non_idle_bitmap, !non_idle_bitmap, 20, 500000, false, mpd, queues, ARRAY_SIZE(queues)); if (err) mpnic_idle_dump(mpd, queues, ARRAY_SIZE(queues), non_idle_bitmap, err);
mpnic_stop()then carries on with teardown either way:mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);Two things happen after that:
- mpnic_flush()->mpnic_clean_bdq() gives every page still posted in [head, tail) back to the page pool.
- mpnic_free_resources()->mpnic_free_rx_qt_resources() frees the HPQ, PPQ and RCQ descriptor rings withdma_free_coherent(), then callspage_pool_destroy().Before this patch, the same timeout-and-continue path only covered Tx, where the device reads host memory. Now there are
DMA_FROM_DEVICEpage pool buffers and an RCQ that the device writes to.If the device has not quiesced when the poll gives up, could it write frame data into freed or reused pages, or write completions into the freed RCQ ring?
Separately, the earlier commit "eth: mpnic: start and stop the Tx HW queues" says every block a packet passes through must report idle before memory is safe to free. The Rx idle table here covers HPQ, PPQ and RCQ, but it has no Rx DMA engine entry to match TDE on the Tx side. The only RDE registers defined are CFG, CTL and the
MEM_INITones.Does RCQ reporting idle guarantee that the RDE has no writes in flight? If not, should an RDE idle entry be polled here as well?
This code is still the same at the end of the series, in "eth: mpnic:
add basic Rx handling".
Quoted 9 lines
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0+ + head++; + head &= bdq->size_mask; + } + + bdq->head = head; +}[ ... ]
Same feedback addressed in v1 series.
PATCH v2 8/8 eth: mpnic: add basic Rx handling
In reply to Daniel ZahkaA frame arrives as a run of completion descriptors: one header address/length descriptor, one address/length descriptor per payload page, and a metadata descriptor that closes the frame. The frame is assembled in an xdp_buff as the descriptors come in and handed to the stack when the metadata descriptor arrives.
A page holds several frames, so rather than taking a reference per frame the driver takes a batch of references when it starts handing the page out and returns whatever is left over once the device moves on to the next one. Payload fragments that turn out to be contiguous within one page are merged so that a frame spread over a page does not eat one skb fragment slot per descriptor.
---
v2:
- skip Rx cleaning and BDQ refill when polled with a budget of 0 (netpoll), page pool must not be used in that context
- keep struct mpnic_pkt_ctxt instead of replacing it with a bare xdp_buff, and move add_frag_failed into it
- give each Rx queue only the NAPI budget left over by the previous ones instead of the full budget
- sync Rx buffers for the CPU with page_pool_dma_sync_for_cpu() instead of dma_sync_single_range_for_cpu()
--- drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 7 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 203 ++++++++++++++++++++++++++- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 7 + 3 files changed, 212 insertions(+), 5 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +7 -0
@@ -130,6 +130,10 @@ enum {#define MPNIC_RCQ_SIZE (i) (0x294 + 1024 * (i))/* 0xa50 */ #define MPNIC_RCQ_SIZE_SIZE CSR_GENMASK(4, 0) +/* NIC_CORE_RIM */ +#define MPNIC_RIM_INTR_MASK (i) (0x2c8 + 1024 * (i))/* 0xb20 */ +#define MPNIC_RIM_INTR_MASK_MASK CSR_BIT(0) +/* NIC_CORE_TIM_PRV */ #define MPNIC_TIM_CTL (i) (0x100100 + 1024 * (i))/* 0x400400 */
@@ -139,6 +143,9 @@ enum {#define MPNIC_RDE_CFG_MIN_HEAD_ROOM CSR_GENMASK(18, 10)#define MPNIC_RDE_CFG_MAX_HEADER_BYTES CSR_GENMASK(45, 32) +/* NIC_CORE_RIM_PRV */ +#define MPNIC_RIM_CTL (i) (0x100280 + 1024 * (i))/* 0x400a00 */ +/* NIC_CORE_RBP_HP_GLBL */ #define MPNIC_HPQ_IDLE (i) (0x420000 + 2 * (i))/* 0x1080000 */ #define MPNIC_HPQ_IDLE_CNT 16
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +198 -5
259 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +7 -0
@@ -50,6 +50,12 @@ struct mpnic_net;/* Headers longer than this are split off into the payload queue */ #define MPNIC_RX_MAX_HDR 1536 +/* A page is handed out to many packets, each of which takes one reference. +* Rather than a locked increment per packet the driver takes a batch of +* references up front and returns whatever is left when the page is done. +*/ +#define MPNIC_PAGECNT_BIAS_MAX (PAGE_SIZE + 1) +#define MPNIC_MAX_JUMBO_FRAME_SIZE 9742/* The page a buffer descriptor queue is currently handing out. Records
@@ -63,6 +69,7 @@ struct mpnic_pg_ctxt {struct mpnic_pkt_ctxt {struct xdp_buff buff; +bool add_frag_failed; };struct mpnic_rcq_state {
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v2 8/8] eth: mpnic: add basic Rx handling
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net: mpnic: rx starvation in mpnic_poll due to sequential queue processing - [Medium] net: mpnic…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: mpnic: rx starvation in mpnic_poll due to sequential queue processing
- [Medium] net: mpnic: NULL pointer dereference on META descriptor without HDR
- [Medium] net: mpnic: NULL pointer dereference on PAY descriptor without HDR --
commit a3920f68fea82b63522bdc2a1f1ed39c3a9d052a
Author: Daniel Zahka <[email protected]>
eth: mpnic: add basic Rx handling
A frame arrives as a run of completion descriptors: one header address/length descriptor, one address/length descriptor per payload page, and a metadata descriptor that closes the frame. The frame is assembled in an xdp_buff as the descriptors come in and handed to the stack when the metadata descriptor arrives.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 11 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +11
-0+static void +mpnic_add_rx_frag (u64 rcd,struct mpnic_rcq_state *state, +struct mpnic_q_triad *qt) +{ +unsigned int pg_off =FIELD_GET (MPNIC_RCD_AL_BUFF_OFF , rcd); +unsigned int pg_idx =FIELD_GET (MPNIC_RCD_AL_BUFF_ID , rcd); +unsigned int len =FIELD_GET (MPNIC_RCD_AL_BUFF_LEN , rcd); +bool fin =FIELD_GET (MPNIC_RCD_AL_PAGE_FIN , rcd); +struct xdp_buff *buff = &state->pkt.buff; +unsigned int truesz; +struct page *page;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 523
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ + page =mpnic_page_pool_get (&state->payld, &qt->sub1, pg_idx); + qt->sub1.head = (pg_idx +1 ) & qt->sub1.size_mask; + + truesz = (fin ?page_size (page) :ALIGN (pg_off + len,128 )) - pg_off; + +page_pool_dma_sync_for_cpu (qt->sub1.page_pool, page, pg_off, truesz); + +if (!xdp_buff_add_frag (buff,page_to_netmem (page), pg_off, len, + truesz)) {
[Severity: Medium]
Will this crash if a PAY_AL descriptor arrives before a HDR_AL descriptor?
If the hardware delivers a malformed sequence or drops a descriptor, state->pkt.buff.data_hard_start might be NULL here. The call to xdp_buff_add_frag() would then calculate the skb_shared_info pointer relative to NULL minus SKB_DATA_ALIGN. Writing to sinfo->nr_frags at this invalid memory address would cause an immediate page fault.
Is there a missing check to verify an active frame was properly started?
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+ state->payld.pagecnt_bias++; + state->pkt.add_frag_failed = true; + } +}
[ ... ]
Quoted 29 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +29
-0+static int mpnic_clean_rcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int budget) +{ +struct mpnic_ring *rcq = &qt->cmpl; +struct mpnic_rcq_state *state; +unsigned int packets =0 ; +__le64 *raw_rcd, done; +u32 head = rcq->head; + + done = (head & (rcq->size_mask +1 )) ?0 :cpu_to_le64 (MPNIC_RCD_DONE ); + raw_rcd = &rcq->desc[head & rcq->size_mask]; + state = rcq->state; + +while (packets < budget) { +u64 rcd; + +if ((*raw_rcd &cpu_to_le64 (MPNIC_RCD_DONE )) != done) +break ; + +dma_rmb (); + + rcd =le64_to_cpu (*raw_rcd); + +switch (FIELD_GET (MPNIC_RCD_TYPE , rcd)) { +case MPNIC_RCD_TYPE_HDR_AL : +if (FIELD_GET (MPNIC_RCD_HDR_SUBTYPE , rcd) == +MPNIC_RCD_HDR_SUBTYPE_HDR ) +mpnic_pkt_prepare (rcd, state, qt); +break ;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 592
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+case MPNIC_RCD_TYPE_PAY_AL : +mpnic_add_rx_frag (rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_META : { +struct sk_buff *skb =NULL ; + +if (likely (!(rcd & +MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK ) && + !state->pkt.add_frag_failed)) + skb =xdp_build_skb_from_buff (&state->pkt.buff);
[Severity: Medium]
Could this trigger a NULL pointer dereference when accessing unmapped memory?
If no preceding MPNIC_RCD_TYPE_HDR_AL descriptor was received for the frame, state->pkt.buff.data_hard_start remains NULL. The driver then blindly calls xdp_build_skb_from_buff(), passing the uninitialized buffer to napi_build_skb(NULL, 0). The core network stack passes NULL to ksize(), which returns 0, leading to an integer underflow when subtracting SKB_DATA_ALIGN. The resulting pointer is memset, causing an immediate crash.
Should we validate that a valid header descriptor was previously received to initialize the buffer before attempting to build the SKB?
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-0+ +if (likely (skb)) +napi_gro_receive (&nv->napi, skb); +else +mpnic_put_pkt_buff (&state->pkt, true);
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-0+static int mpnic_poll (struct napi_struct *napi,int budget) +{ +struct mpnic_napi_vector *nv =container_of (napi, + struct mpnic_napi_vector, + napi);
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 635
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-1-int i; +int i, j, work_done =0 ;for (i =0 ; i < nv->txt_count; i++)mpnic_clean_tcq (nv, &nv->qt[i], budget); +if (likely (budget)) +for (j =0 ; j < nv->rxt_count; j++, i++) + work_done +=mpnic_clean_rcq (nv, &nv->qt[i], + budget - work_done);
[Severity: High]
Can this permanently bias NAPI budget allocation and starve higher-indexed Rx queues?
The loop unconditionally starts at index 0 and passes the remaining NAPI budget (budget - work_done) to each subsequent queue. If the first queue continuously exhausts the entire budget under heavy load, budget - work_done becomes 0 for the remaining queues.
Because the loop does not remember its position across NAPI poll cycles, it will always restart at queue 0, permanently starving higher-indexed queues. Could a high rate of traffic to the first queue cause a complete denial of service for flows hashed to other queues on the same NAPI vector?
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-0+for (i =0 ; i < nv->txt_count; i++)mpnic_commit_cq_head (&nv->qt[i].cmpl);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH net-next v2 8/8] eth: mpnic: add basic Rx handling
In reply to Daniel ZahkaThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Rx buffer queues can starve for good after a page allocation failure.
- [Medium] mpnic_clean_rcq() never checks that a frame is in progress before handling a descriptor.
- [Medium] mpnic_page_pool_get() indexes ring->rx_buf[idx] with the raw 18-bit MPNIC_RCD_AL_BUFF_ID from the completion descriptor (up to…
- [Medium] The descriptor fields BUFF_OFF (16 bits) and BUFF_LEN (14 bits) are used without range checks to build the skb head, frame_sz,…
--
eth: mpnic: add basic Rx handling
This commit adds Rx completion processing to the mpnic driver. Each frame is built in an xdp_buff from three kinds of descriptor: a header descriptor, one payload descriptor per page and a closing metadata descriptor. The frame is then passed to GRO, and pages are shared between frames using a batched page_pool reference bias.
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0@@ -405,6 +405,34 @@ static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt)
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) · line 424
Quoted 13 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +13
-0+static struct page * +mpnic_page_pool_get (struct mpnic_pg_ctxt *pg_ctxt,struct mpnic_ring *ring, +u32 idx) +{ +struct page *page = pg_ctxt->page; + +if (unlikely (pg_ctxt->idx != idx)) { +if (pg_ctxt->pagecnt_bias && + !page_pool_unref_page (page, pg_ctxt->pagecnt_bias)) +page_pool_put_unrefed_page (page->pp, page,-1 , true); + + page = ring->rx_buf[idx]; +page_pool_fragment_page (page,MPNIC_PAGECNT_BIAS_MAX );
[Severity: Medium]
Here idx is the raw MPNIC_RCD_AL_BUFF_ID field from the completion descriptor. mpnic_pkt_prepare() and mpnic_add_rx_frag() pass it through unchanged. The field is 18 bits wide (up to 262143), but rx_buf[] only has hpq_size/ppq_size entries (256 by default).
Could a bad buffer ID from the device read past the end of rx_buf[]? page_pool_fragment_page() would then write pp_ref_count through whatever pointer it found there.
An in-range ID for a slot the device already completed seems like it would also reset the refcount of a page that in-flight skbs still own.
mpnic_bd_prep() only posts IDs in [0, size_mask], so this needs a faulty or misbehaving device. Would it be worth masking idx with ring->size_mask, or rejecting IDs that are out of range?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +2
-0@@ -417,6 +445,87 @@ static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) } } +static unsigned int mpnic_hdr_pg_start (unsigned int pg_off) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 459
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+if (ALIGN (MPNIC_RX_HROOM ,128 ) >MPNIC_RX_HROOM && + pg_off ==ALIGN (MPNIC_RX_HROOM ,128 )) +return 0 ; + +return pg_off -MPNIC_RX_HROOM ; +}
[Severity: Medium]
If the device reports a BUFF_OFF smaller than MPNIC_RX_HROOM, does this unsigned subtraction wrap around and produce a huge pg_start?
The BUFF_OFF (16 bits) and BUFF_LEN (14 bits) fields are used without range checks in a few other places:
- mpnic_hdr_pg_end() can return values well beyond PAGE_SIZE. These feed frame_sz in mpnic_pkt_prepare(), which decides where skb_shared_info is written.
- With fin set and pg_off larger than page_size(page), frame_sz in mpnic_pkt_prepare() and truesz in mpnic_add_rx_frag() both underflow.
- In mpnic_add_rx_frag(), a payload frag with pg_off + len past page_size(page) would expose adjacent memory to the stack.
The same values also set the page_pool_dma_sync_for_cpu() ranges.
A device that follows the configured HROOM/TROOM/MAX_HEADER_BYTES layout should not produce these values. Would a sanity check against page_size(page) still be worth adding?
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -442,23 +551,99 @@ static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi)page_pool_put_full_page (page->pp, page, napi); } +static int mpnic_clean_rcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int budget) +{
[ ... ]
Quoted 13 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +13
-0+switch (FIELD_GET (MPNIC_RCD_TYPE , rcd)) { +case MPNIC_RCD_TYPE_HDR_AL : +if (FIELD_GET (MPNIC_RCD_HDR_SUBTYPE , rcd) == +MPNIC_RCD_HDR_SUBTYPE_HDR ) +mpnic_pkt_prepare (rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_PAY_AL : +mpnic_add_rx_frag (rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_META : { +struct sk_buff *skb =NULL ; + + if (likely(!(rcd &
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 599
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) && + !state->pkt.add_frag_failed)) + skb =xdp_build_skb_from_buff (&state->pkt.buff); + +if (likely (skb)) +napi_gro_receive (&nv->napi, skb); +else +mpnic_put_pkt_buff (&state->pkt, true); + + state->pkt.buff.data_hard_start =NULL ;
[Severity: Medium]
Nothing checks that a frame is in progress before a PAY_AL or META descriptor is handled. state->pkt.buff.data_hard_start is zero at start and is set back to NULL after every META.
Suppose a PAY_AL arrives without a preceding HDR descriptor. mpnic_add_rx_frag() then calls xdp_buff_add_frag(), which writes to skb_shared_info at an address based on a NULL data_hard_start and a stale frame_sz.
A META in the same state would take the success branch:
mpnic_clean_rcq()
xdp_build_skb_from_buff()
napi_build_skb(NULL, frame_sz)
Only the error path, mpnic_put_pkt_buff(), checks data_hard_start.
Can either of these cause a NULL pointer dereference in NAPI context?
HDR_AL descriptors whose subtype is not MPNIC_RCD_HDR_SUBTYPE_HDR are skipped silently, so a frame that starts that way would hit the same path.
The opposite case is also possible. mpnic_pkt_prepare() overwrites state->pkt.buff without releasing the page_pool references of an unfinished frame. Could that leak pages and stall page_pool_destroy()?
fbnic_pkt_prepare() has a WARN_ON_ONCE(xdp->data_hard_start) at this point, and mpnic_pkt_prepare() drops it. Would it make sense to keep it?
All of this needs the device to break the HDR, PAY_AL*, META ordering.
[ ... ]
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+ rcq->head = head; + +/* Allocate buffers, force dma_wmb(), and then start writing tails */ +mpnic_fill_qt_bdqs (qt); + +return packets; +} +static int mpnic_poll (struct napi_struct *napi,int budget) {
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 644
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-1-if (likely (napi_complete_done (napi,0 ))) +if (work_done >= budget) +return budget; + +if (likely (napi_complete_done (napi, work_done)))mpnic_nv_irq_rearm (nv);
[Severity: Medium]mpnic_clean_rcq() is the only runtime caller of mpnic_fill_qt_bdqs(). __mpnic_fill_bdq() simply stops when the page pool allocation fails:
page = page_pool_dev_alloc_pages(bdq->page_pool); if (!page) break;
The shortfall is never reported back, because mpnic_clean_rcq() only returns the packet count. mpnic_poll() then completes NAPI and re-arms the IRQ anyway.
Say the allocation fails while the device has no posted buffers left, or fewer than the 16-descriptor HPQ/PPQ drop threshold. The device then drops incoming frames without writing any RCQ completions. What would schedule NAPI again in that case?
There doesn't seem to be a timer, a service task, a forced IRQ trigger, or a return of the full budget to retry the refill. The only mpnic_nv_irq_trigger() call is in mpnic_napi_enable(). The only way out seems to be a Tx completion on the same vector.
Could a receive-mostly queue stay stuck until the interface is brought down and up again?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e%40gmail.com
Re: [PATCH net-next v2 8/8] eth: mpnic: add basic Rx handling
Quoted 62 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Rx buffer queues can starve for good after a page allocation failure.
- [Medium]mpnic_clean_rcq()never checks that a frame is in progress before handling a descriptor.
- [Medium]mpnic_page_pool_get()indexes ring->rx_buf[idx] with the raw 18-bitMPNIC_RCD_AL_BUFF_IDfrom the completion descriptor (up to…
- [Medium] The descriptor fieldsBUFF_OFF(16 bits) andBUFF_LEN(14 bits) are used without range checks to build the skb head, frame_sz,…--
eth: mpnic: add basic Rx handling
This commit adds Rx completion processing to the mpnic driver. Each frame is built in an
xdp_bufffrom three kinds of descriptor: a header descriptor, one payload descriptor per page and a closing metadata descriptor. The frame is then passed to GRO, and pages are shared between frames using a batchedpage_poolreference bias.Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0@@ -405,6 +405,34 @@ static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt)[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) · line 424
Quoted 13 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +13
-0+static struct page * +mpnic_page_pool_get (struct mpnic_pg_ctxt *pg_ctxt,struct mpnic_ring *ring, +u32 idx) +{ +struct page *page = pg_ctxt->page; + +if (unlikely (pg_ctxt->idx != idx)) { +if (pg_ctxt->pagecnt_bias && + !page_pool_unref_page (page, pg_ctxt->pagecnt_bias)) +page_pool_put_unrefed_page (page->pp, page,-1 , true); + + page = ring->rx_buf[idx]; +page_pool_fragment_page (page,MPNIC_PAGECNT_BIAS_MAX );[Severity: Medium]
Here idx is the rawMPNIC_RCD_AL_BUFF_IDfield from the completion descriptor.mpnic_pkt_prepare()andmpnic_add_rx_frag()pass it through unchanged. The field is 18 bits wide (up to 262143), but rx_buf[] only has hpq_size/ppq_size entries (256 by default).Could a bad buffer ID from the device read past the end of rx_buf[]?
page_pool_fragment_page()would then writepp_ref_countthrough whatever pointer it found there.
Quoted 7 lines
An in-range ID for a slot the device already completed seems like it would also reset the refcount of a page that in-flight skbs still own.
mpnic_bd_prep()only posts IDs in [0,size_mask], so this needs a faulty or misbehaving device. Would it be worth masking idx withring->size_mask, or rejecting IDs that are out of range?
Comment addressed in v1.
Quoted 32 lines
[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +2
-0@@ -417,6 +445,87 @@ static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) } } +static unsigned int mpnic_hdr_pg_start (unsigned int pg_off) +{[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 459
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+if (ALIGN (MPNIC_RX_HROOM ,128 ) >MPNIC_RX_HROOM && + pg_off ==ALIGN (MPNIC_RX_HROOM ,128 )) +return 0 ; + +return pg_off -MPNIC_RX_HROOM ; +}[Severity: Medium]
If the device reports aBUFF_OFFsmaller thanMPNIC_RX_HROOM, does this unsigned subtraction wrap around and produce a hugepg_start?The
BUFF_OFF(16 bits) andBUFF_LEN(14 bits) fields are used without range checks in a few other places:-
mpnic_hdr_pg_end()can return values well beyondPAGE_SIZE. These feedframe_szinmpnic_pkt_prepare(), which decides whereskb_shared_infois written.- With fin set and
pg_offlarger thanpage_size(page),frame_szinmpnic_pkt_prepare()and truesz inmpnic_add_rx_frag()both underflow.
Quoted 9 lines
- In
mpnic_add_rx_frag(), a payload frag withpg_off+ len pastpage_size(page)would expose adjacent memory to the stack.The same values also set the
page_pool_dma_sync_for_cpu()ranges.A device that follows the configured HROOM/TROOM/MAX_HEADER_BYTES layout should not produce these values. Would a sanity check against
page_size(page)still be worth adding?
We trust the offset field written by the device.
Quoted 60 lines
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -442,23 +551,99 @@ static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi)page_pool_put_full_page (page->pp, page, napi); } +static int mpnic_clean_rcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int budget) +{[ ... ]
Quoted 13 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +13
-0+switch (FIELD_GET (MPNIC_RCD_TYPE , rcd)) { +case MPNIC_RCD_TYPE_HDR_AL : +if (FIELD_GET (MPNIC_RCD_HDR_SUBTYPE , rcd) == +MPNIC_RCD_HDR_SUBTYPE_HDR ) +mpnic_pkt_prepare (rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_PAY_AL : +mpnic_add_rx_frag (rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_META : { +struct sk_buff *skb =NULL ; + + if (likely(!(rcd &drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 599
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK) && + !state->pkt.add_frag_failed)) + skb =xdp_build_skb_from_buff (&state->pkt.buff); + +if (likely (skb)) +napi_gro_receive (&nv->napi, skb); +else +mpnic_put_pkt_buff (&state->pkt, true); + + state->pkt.buff.data_hard_start =NULL ;[Severity: Medium]
Nothing checks that a frame is in progress before aPAY_ALor META descriptor is handled.state->pkt.buff.data_hard_startis zero at start and is set back to NULL after every META.Suppose a
PAY_ALarrives without a preceding HDR descriptor.mpnic_add_rx_frag()then callsxdp_buff_add_frag(), which writes toskb_shared_infoat an address based on a NULLdata_hard_startand a staleframe_sz.A META in the same state would take the success branch:
mpnic_clean_rcq()
xdp_build_skb_from_buff()
napi_build_skb(NULL, frame_sz)Only the error path,
mpnic_put_pkt_buff(), checksdata_hard_start.Can either of these cause a NULL pointer dereference in NAPI context?
HDR_ALdescriptors whose subtype is notMPNIC_RCD_HDR_SUBTYPE_HDRare skipped silently, so a frame that starts that way would hit the same path.
Quoted 9 lines
The opposite case is also possible.
mpnic_pkt_prepare()overwritesstate->pkt.buffwithout releasing thepage_poolreferences of an unfinished frame. Could that leak pages and stallpage_pool_destroy()?
fbnic_pkt_prepare()has aWARN_ON_ONCE(xdp->data_hard_start)at this point, andmpnic_pkt_prepare()drops it. Would it make sense to keep it?All of this needs the device to break the HDR, PAY_AL*, META ordering.
Same comment responded to in v1.
Quoted 44 lines
[ ... ]
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +8
-0+ rcq->head = head; + +/* Allocate buffers, force dma_wmb(), and then start writing tails */ +mpnic_fill_qt_bdqs (qt); + +return packets; +} +static int mpnic_poll (struct napi_struct *napi,int budget) {[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 644
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-1-if (likely (napi_complete_done (napi,0 ))) +if (work_done >= budget) +return budget; + +if (likely (napi_complete_done (napi, work_done)))mpnic_nv_irq_rearm (nv);[Severity: Medium]
mpnic_clean_rcq()is the only runtime caller ofmpnic_fill_qt_bdqs().__mpnic_fill_bdq()simply stops when the page pool allocation fails:page = page_pool_dev_alloc_pages(bdq->page_pool); if (!page) break;The shortfall is never reported back, because
mpnic_clean_rcq()only returns the packet count.mpnic_poll()then completes NAPI and re-arms the IRQ anyway.Say the allocation fails while the device has no posted buffers left, or fewer than the 16-descriptor HPQ/PPQ drop threshold. The device then drops incoming frames without writing any RCQ completions. What would schedule NAPI again in that case?
There doesn't seem to be a timer, a service task, a forced IRQ trigger, or a return of the full budget to retry the refill. The only
mpnic_nv_irq_trigger()call is inmpnic_napi_enable(). The only way out seems to be a Tx completion on the same vector.
Quoted 4 lines
Could a receive-mostly queue stay stuck until the interface is brought down and up again?
[ ... ]
Valid. We prefer to address this in a small follow up series.
Re: [PATCH net-next v2 8/8] eth: mpnic: add basic Rx handling
Quoted 1 line · On Mon, 28 Sep 2026 11:17:42 -0400 Daniel Zahka wrote:
Valid. We prefer to address this in a small follow up series.
To avoid misunderstandings - the Rx stall watchdog is intentionally deferred to a later series which introduces the service task. We were trying to keep the initial driver under 3k LoC for feasibility of human review.
Quoted 42 lines · Daniel Zahka
Meta Platforms NIC is the second-generation NIC from Meta. There are quite a few high-level similarities to fbnic, but all of the CSRs and descriptors have been reshuffled, and new features have been added. Since the device is sufficiently different from fbnic, and the design of our FW is minimal, we have decided a separate driver is appropriate.
Major new features compared to fbnic will take a while to land. This series includes only the bare-bones Tx/Rx datapath.
Our high-level patch sequence and plan for the upcoming series is:
1. Core datapath (this series)
2. Basic offloads, RSS, and counters
3. Firmware mailbox support
4. Base ethtool operationsThis patch series was prepared in part with these LLM prompts:
https://github.com/kuba-moo/ai-prompts/blob/main/driver-upstreaming-prompts.mdThe prompts were used to distill our fully-featured OOT driver into this minimal Tx/Rx capable upstream driver. We then performed human review on the output to create this posting. Jakub has made the prompts public in case people would like to take a look.
Signed-off-by Daniel Zahka <[email protected]>---
Changes in v2:
- eth: mpnic: add register init for the device
- derive the TQS TXB credit limits from the TXB private credit config
- program the BMC to MAC XOFF threshold (TXB_THRESHOLDS_P0[16]) instead of the host to BMC one, and drop the now unusedMPNIC_TXB_BMC_THRESH
- dropL2_HLENfrom the default TWD, it only matters for csum/LSO
- eth: mpnic: implement Tx queue allocation and cleanup
- addmpnic_nv_irq_trigger()
- eth: mpnic: add a netdevice and basic Tx handling
- trim the real Tx queue count beforeregister_netdev()
- eth: mpnic: implement Rx queue allocation and cleanup
- drop an inaccurate comment onmpnic_bdq_desc_unused()
- drop the unuseddata_truesizefield from structmpnic_pkt_ctxt
- trim the real Rx queue count beforeregister_netdev()too
- eth: mpnic: add basic Rx handling
- skip Rx cleaning and BDQ refill when polled with a budget of 0
Quoted 9 lines
(netpoll), page pool must not be used in that context
- keep structmpnic_pkt_ctxtinstead of replacing it with a barexdp_buff, and moveadd_frag_failedinto it
- give each Rx queue only the NAPI budget left over by the previous
ones instead of the full budget
- sync Rx buffers for the CPU withpage_pool_dma_sync_for_cpu()instead ofdma_sync_single_range_for_cpu()
- Link to v1: https://lore.kernel.org/r/[email protected]
Just so it doesn't get lost over all of back and forth with sashiko. My view on the series is that I don't see any issues requiring a v3. Until other feedback comes along, I will not post a v3.
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Thu, 24 Sep 2026 17:35:13 -0700 you wrote:
Meta Platforms NIC is the second-generation NIC from Meta. There are quite a few high-level similarities to fbnic, but all of the CSRs and descriptors have been reshuffled, and new features have been added. Since the device is sufficiently different from fbnic, and the design of our FW is minimal, we have decided a separate driver is appropriate.
Major new features compared to fbnic will take a while to land. This series includes only the bare-bones Tx/Rx datapath.
[...]
Here is the summary with links:
- [net-next,v2,1/8] eth: mpnic: add scaffolding for Meta Platforms NIC
https://git.kernel.org/netdev/net-next/c/3251a68930f8 - [net-next,v2,2/8] eth: mpnic: add register init for the device https://git.kernel.org/netdev/net-next/c/cda700bcb236 - [net-next,v2,3/8] eth: mpnic: allocate MSI-X vectors https://git.kernel.org/netdev/net-next/c/2cf67a269224 - [net-next,v2,4/8] eth: mpnic: implement Tx queue allocation and cleanup https://git.kernel.org/netdev/net-next/c/3d4e4ad43aa4 - [net-next,v2,5/8] eth: mpnic: start and stop the Tx HW queues https://git.kernel.org/netdev/net-next/c/bd7ce2b2afea - [net-next,v2,6/8] eth: mpnic: add a netdevice and basic Tx handling https://git.kernel.org/netdev/net-next/c/1b8d005bd334 - [net-next,v2,7/8] eth: mpnic: implement Rx queue allocation and cleanup https://git.kernel.org/netdev/net-next/c/4b26e9cdad78 - [net-next,v2,8/8] eth: mpnic: add basic Rx handling https://git.kernel.org/netdev/net-next/c/a9a9bb541614
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html