eth: mpnic: initial support for Meta Platforms NIC
Subsystems (4)
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.
---
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 | 321 ++++++ drivers/net/ethernet/meta/mpnic/mpnic_init.c | 553 ++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_irq.c | 64 ++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 181 +++ 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 | 1398 ++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 147 +++ 12 files changed, 2982 insertions(+)
---
base-commit: 6598456d72e48d779445bfec8f72114747f8b8d7
change-id: 20260918-linux-mpnic-8fa318d530fa
Best regards,
Signature · 1 line
Daniel Zahka <[email protected]>
PATCH 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 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] mpnic: Missing PCI BAR size validation causing OOB MMIO access --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mpnic: Missing PCI BAR size validation causing OOB MMIO access
--
commit 04a97e4905a47ed1a317515fbb919eef32a497b2
Author: Daniel Zahka <[email protected]>
eth: mpnic: add scaffolding for Meta Platforms NIC
This commit adds the initial bare PCI driver scaffolding for the Meta Platforms Network Interface Controller. It introduces basic MMIO read/write operations and PCI device registration.
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]
Could this unconditionally read at a large offset (~16.5MB) regardless of the actual mapped BAR size? If a device (or an attacker via hotplug/virtualization) presents a smaller BAR, wouldn't this cause an out-of-bounds MMIO access and potentially a kernel page fault?
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 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c new file +5
-0+static int mpnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +void __iomem *uc_addr0; +struct mpnic_dev *mpd; +int err;
[ ... ]
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]
Does this code map the PCI BAR without first validating that the resource length is large enough to cover the expected register offsets? Should this validate pci_resource_len(pdev, 0) before mapping to ensure that accesses like MPNIC_BDQ_SPARE remain within bounds?
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
PATCH 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.
--- drivers/net/ethernet/meta/mpnic/Makefile | 1 + drivers/net/ethernet/meta/mpnic/mpnic.h | 9 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 165 ++++++++ drivers/net/ethernet/meta/mpnic/mpnic_init.c | 553 +++++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 8 + 5 files changed, 736 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 +165 -0
177 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +553 -0
553 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 2/8] eth: mpnic: add register init for the device
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] pci: missing pci_resource_len() check in mpnic_probe() allows OOB MMIO access --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pci: missing pci_resource_len() check in mpnic_probe() allows OOB MMIO access --
commit 647e9ec73143ec855da6fd69e03902213d836df8
Author: Mohsin Bashir <[email protected]>
eth: mpnic: add register init for the device
This commit adds one-time register initialization for the mpnic device during the probe process. It covers static configurations and pulses for zeroizing on-chip SRAMs.
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +0
-0
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_init.c line 468
Quoted 11 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +11
-0+static void mpnic_ro_init (struct mpnic_dev *mpd) +{ +u64 attr = mpd->relaxed_ord ?MPNIC_OB_ATTR_RO :0 ; + +mpnic_wr64 (mpd,MPNIC_OB_ATTR_TDE_H , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_TDE_P , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_TDF , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_RBP_HPQ , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_RBP_PPQ , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_RDE_H , attr); +mpnic_wr64 (mpd,MPNIC_OB_ATTR_RDE_P , attr);
[Severity: High]
Can this write out of bounds of the mapped MMIO region if the PCI BAR is unexpectedly small?
This function accesses MPNIC_OB_ATTR_RDE_P, which is at offset 0x2680068. This requires the mapped region to be at least ~40MB.
Earlier in the initialization path, mpnic_probe() maps the PCI BAR via pcim_iomap_region() without verifying if pci_resource_len() covers these expected MMIO registers.
If a malicious or spoofed PCI device (e.g., connected via Thunderbolt) advertises an artificially small BAR, the driver will map this short length but unconditionally write to offsets far beyond the mapped boundary here. This could cause an immediate page fault and system crash upon device connection.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH net-next 2/8] eth: mpnic: add register init for the device
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: 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).
- [High] pci: missing pci_resource_len() check in mpnic_probe() allows OOB MMIO access
- [Medium] The 1 MiB Tx buffer is split between MAC and BMC differently in TXB and in TQS.
--
eth: mpnic: add register init for the device
This commit adds one-time CSR initialization to mpnic_probe() through a new mpnic_dev_init(). It programs the TXB, RXB, TQS, descriptor SRAM, AXI and relaxed ordering settings, starts the on-chip SRAM initializations and polls until they complete.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +0
-0@@ -0,0 +1,553 @@
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +7
-0+/* A total of 1 MiB worth of Tx credits is available, in units of 128 B. +* The BMC gets a guaranteed share of them whether or not the host is +* routing anything its way, everything else goes to MAC TC0. +*/ +#define MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL 800 +#define MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL \ + (SZ_1M / 128 - 2 * MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL)
[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +6
-0+/* The 1 MiB Tx buffer is partitioned between the MAC and the BMC in units +* of 1 KiB. The BMC portion is fixed at 100 KB. +*/ +#define MPNIC_TQS_GLBL_TXB_CRDT_BMC 100 +#define MPNIC_TQS_GLBL_TXB_CRDT_MAC (SZ_1M / SZ_1K - \ + MPNIC_TQS_GLBL_TXB_CRDT_BMC)
[ ... ]
Quoted 15 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +15
-0+static void mpnic_txb_init (struct mpnic_dev *mpd) +{ +int i; + +mpnic_wr64 (mpd,MPNIC_TXB_BMC ,MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL ); + +/* Zero the private credits of every traffic class, then hand the +* unreserved ones to MAC TC0. +*/ +for (i =0 ; i <MPNIC_TXB_P0_CNT ; i++) +mpnic_wr64 (mpd,MPNIC_TXB_P0 (i),0 ); +mpnic_wr64 (mpd,MPNIC_TXB_P0 (MPNIC_TXB_TC_IDX_MAC_0 ), +MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL ); +mpnic_wr64 (mpd,MPNIC_TXB_P0 (MPNIC_TXB_TC_IDX_BMC ), +MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL );
[ ... ]
Quoted 2 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +2
-0+static void mpnic_tqs_init (struct mpnic_dev *mpd) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_init.c line 347
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +10
-0+/* Only port 0 is used. A single traffic class is in use as well, so +* give all of the Tx buffer credits to TC0. +*/ +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_P0_0 , +FIELD_PREP (MPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0 , +MPNIC_TQS_GLBL_TXB_CRDT_MAC )); +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_P0_1 ,0 ); +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_BMC , +FIELD_PREP (MPNIC_TQS_GLBL_BMC_TXB_MAX_CRDTS , +MPNIC_TQS_GLBL_TXB_CRDT_BMC ));
[Severity: Medium]
Do TXB and TQS split the 1 MiB Tx buffer the same way?
On the TXB side, mpnic_txb_init() writes MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL (800 x 128 B = 100 KiB) to both MPNIC_TXB_BMC and MPNIC_TXB_P0(MPNIC_TXB_TC_IDX_BMC). MAC TC0 then gets:
SZ_1M / 128 - 2 * 800 = 6592 credits = 824 KiB
On the TQS side, mpnic_tqs_init() programsMPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0 with:
SZ_1M / SZ_1K - 100 = 924 (1 KiB units) = 924 KiB
That lets the scheduler use 100 KiB more for TC0 than TXB reserved as TC0 private credit.
Suppose TXB_MAX_CRDTS limits how much data the scheduler can have outstanding in the TC0 TXB pool. Could a Tx burst that fills TC0 then overrun the pool once the Tx datapath is running?
If the BMC only needs a single 100 KiB share, as the TQS comment says, does the "2 *" in MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL leave 100 KiB of Tx buffer unused?
The TXB comment says "everything else goes to MAC TC0", but the code subtracts the BMC share twice, so the two don't match either.
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 121
Quoted 10 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; +return 0 ; err_free_mpd:
[Severity: High]mpnic_dev_init() reaches much further into BAR 0 than anything the driver touched before. Before this patch, the furthest access was MPNIC_BDQ_SPARE in mpnic_rd64(). Now the TXB, RXB, RPC, ROF, TOF and PEMO_WRAPPER blocks are all programmed.
The highest one is MPNIC_OB_ATTR_RDE_P in mpnic_ro_init(). It is 0x9a001a in u32 units, so the writeq() lands at byte offset 0x2680068. BAR 0 therefore has to be at least ~38.5 MiB for this sequence to stay inside the mapping.
mpnic_probe() maps BAR 0 with pcim_iomap_region(), which accepts whatever length the device advertised. Nothing checks pci_resource_len(pdev, 0) against the register file the driver is about to use. mpnic_wr64() and mpnic_rd64() only test that uc_addr0 is non-NULL, then add the register index unconditionally.
Suppose a device presents a BAR 0 smaller than that. It could be a misconfigured board, or something spoofing this ID behind Thunderbolt/USB4. Won't the first out-of-range writeq() in mpnic_dev_init() fault on an unmapped address during probe, or scribble over whatever happens to be mapped after the BAR?
Could mpnic_probe() reject the device with -ENODEV before calling mpnic_dev_init() when pci_resource_len(pdev, 0) is too small? Does the hardware have a documented BAR 0 size that could serve as the bound? That seems better than deriving one from the highest CSR currently defined in mpnic_csr.h, which will keep moving as more blocks are added.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 2/8] eth: mpnic: add register init for the device
Quoted 108 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] pci: missing
pci_resource_len()check inmpnic_probe()allows OOB MMIO access
- [Medium] The 1 MiB Tx buffer is split between MAC and BMC differently in TXB and in TQS.--
eth: mpnic: add register init for the device
This commit adds one-time CSR initialization to
mpnic_probe()through a newmpnic_dev_init(). It programs the TXB, RXB, TQS, descriptor SRAM, AXI and relaxed ordering settings, starts the on-chip SRAM initializations and polls until they complete.Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +0
-0@@ -0,0 +1,553 @@[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +7
-0+/* A total of 1 MiB worth of Tx credits is available, in units of 128 B. +* The BMC gets a guaranteed share of them whether or not the host is +* routing anything its way, everything else goes to MAC TC0. +*/ +#define MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL 800 +#define MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL \ + (SZ_1M / 128 - 2 * MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL)[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +6
-0+/* The 1 MiB Tx buffer is partitioned between the MAC and the BMC in units +* of 1 KiB. The BMC portion is fixed at 100 KB. +*/ +#define MPNIC_TQS_GLBL_TXB_CRDT_BMC 100 +#define MPNIC_TQS_GLBL_TXB_CRDT_MAC (SZ_1M / SZ_1K - \ + MPNIC_TQS_GLBL_TXB_CRDT_BMC)[ ... ]
Quoted 15 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +15
-0+static void mpnic_txb_init (struct mpnic_dev *mpd) +{ +int i; + +mpnic_wr64 (mpd,MPNIC_TXB_BMC ,MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL ); + +/* Zero the private credits of every traffic class, then hand the +* unreserved ones to MAC TC0. +*/ +for (i =0 ; i <MPNIC_TXB_P0_CNT ; i++) +mpnic_wr64 (mpd,MPNIC_TXB_P0 (i),0 ); +mpnic_wr64 (mpd,MPNIC_TXB_P0 (MPNIC_TXB_TC_IDX_MAC_0 ), +MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VAL ); +mpnic_wr64 (mpd,MPNIC_TXB_P0 (MPNIC_TXB_TC_IDX_BMC ), +MPNIC_TXB_BMC_PVT_CRDT_INIT_VAL );[ ... ]
Quoted 2 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +2
-0+static void mpnic_tqs_init (struct mpnic_dev *mpd) +{[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_init.c line 347
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_init.c new file +10
-0+/* Only port 0 is used. A single traffic class is in use as well, so +* give all of the Tx buffer credits to TC0. +*/ +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_P0_0 , +FIELD_PREP (MPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0 , +MPNIC_TQS_GLBL_TXB_CRDT_MAC )); +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_P0_1 ,0 ); +mpnic_wr64 (mpd,MPNIC_TQS_GLBL_BMC , +FIELD_PREP (MPNIC_TQS_GLBL_BMC_TXB_MAX_CRDTS , +MPNIC_TQS_GLBL_TXB_CRDT_BMC ));[Severity: Medium]
Do TXB and TQS split the 1 MiB Tx buffer the same way?On the TXB side,
mpnic_txb_init()writesMPNIC_TXB_BMC_PVT_CRDT_INIT_VAL(800 x 128 B = 100 KiB) to bothMPNIC_TXB_BMCandMPNIC_TXB_P0(MPNIC_TXB_TC_IDX_BMC). MAC TC0 then gets:
SZ_1M/ 128 - 2 * 800 = 6592 credits = 824 KiBOn the TQS side,
mpnic_tqs_init()programsMPNIC_TQS_GLBL_P0_0_TXB_MAX_CRDTS_0with:
SZ_1M/SZ_1K- 100 = 924 (1 KiB units) = 924 KiBThat lets the scheduler use 100 KiB more for TC0 than TXB reserved as TC0 private credit.
Suppose
TXB_MAX_CRDTSlimits how much data the scheduler can have outstanding in the TC0 TXB pool. Could a Tx burst that fills TC0 then overrun the pool once the Tx datapath is running?
Quoted 8 lines
If the BMC only needs a single 100 KiB share, as the TQS comment says, does the "2 *" in
MPNIC_TXB_P0_MAC_PVT_CRDT_INIT_VALleave 100 KiB of Tx buffer unused?The TXB comment says "everything else goes to MAC TC0", but the code subtracts the BMC share twice, so the two don't match either.
[ ... ]
Will fix in v2.
Quoted 40 lines
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_pci.c static int mpnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 121
Quoted 10 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; +return 0 ; err_free_mpd:[Severity: High]
mpnic_dev_init()reaches much further into BAR 0 than anything the driver touched before. Before this patch, the furthest access wasMPNIC_BDQ_SPAREinmpnic_rd64(). Now the TXB, RXB, RPC, ROF, TOF andPEMO_WRAPPERblocks are all programmed.The highest one is
MPNIC_OB_ATTR_RDE_Pinmpnic_ro_init(). It is0x9a001ain u32 units, so thewriteq()lands at byte offset0x2680068. BAR 0 therefore has to be at least ~38.5 MiB for this sequence to stay inside the mapping.
mpnic_probe()maps BAR 0 withpcim_iomap_region(), which accepts whatever length the device advertised. Nothing checkspci_resource_len(pdev, 0)against the register file the driver is about to use.mpnic_wr64()andmpnic_rd64()only test thatuc_addr0is non-NULL, then add the register index unconditionally.Suppose a device presents a BAR 0 smaller than that. It could be a misconfigured board, or something spoofing this ID behind Thunderbolt/USB4. Won't the first out-of-range
writeq()inmpnic_dev_init()fault on an unmapped address during probe, or scribble over whatever happens to be mapped after the BAR?
Quoted 6 lines
Could
mpnic_probe()reject the device with-ENODEVbefore callingmpnic_dev_init()whenpci_resource_len(pdev, 0)is too small? Does the hardware have a documented BAR 0 size that could serve as the bound? That seems better than deriving one from the highest CSR currently defined inmpnic_csr.h, which will keep moving as more blocks are added.
I don't believe this is necessary. It doesn't seem that common in pci based network drivers. In our case, the bar size is static. It will always be 64MiB for this pci device id.
pw-bot: cr
Jakub Kicinski
maintainerRe: [PATCH net-next 2/8] eth: mpnic: add register init for the device
Quoted 3 lines · On Thu, 24 Sep 2026 12:16:33 -0400 Daniel Zahka wrote:
I don't believe this is necessary. It doesn't seem that common in pci based network drivers. In our case, the bar size is static. It will always be 64MiB for this pci device id.
Yes, we trust PCIe devices to not be malicious and/or mangled. I need to update the prompts :S
PATCH 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
PATCH 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.
--- 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 | 496 +++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 80 ++++ 5 files changed, 626 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
@@ -16,6 +16,13 @@#define MPNIC_TWD_L2_HLEN DESC_GENMASK(5, 0)#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)
@@ -29,6 +36,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 +496 -0
496 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 4/8] eth: mpnic: implement Tx queue allocation and cleanup
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] eth: mpnic: TOCTOU IOMMU bypass when unmapping Tx descriptors - [High] eth: mpnic: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] eth: mpnic: TOCTOU IOMMU bypass when unmapping Tx descriptors
- [High] eth: mpnic: missing bounds check on hardware completion head
--
commit 154e61c52ca2706a8f945c1575f31b7f328f5529
Author: Daniel Zahka <[email protected]>
eth: mpnic: implement Tx queue allocation and cleanup
Queues 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.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +5
-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),
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 67
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +10
-0+ 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 ); +}
[Severity: Critical]
Can a malicious PCIe device corrupt host memory by rewriting these descriptors?
During Tx completion, the DMA address and length are read directly from the device-accessible descriptor ring in mpnic_clean_twq0() and passed to dma_unmap_single() and dma_unmap_page() here. Because the descriptor memory is coherent DMA memory, the device could change the addresses between submission and completion, bypassing IOMMU protections.
Could we store the DMA metadata in host-private memory (like the tx_buf array) instead of reading it back from the 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 84
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 a malfunctioning or malicious device to cause a NULL pointer dereference here?
The loop boundary clean_desc is calculated from the untrusted hw_head without validating it against the software-maintained tail that tracks actually submitted descriptors. If the hardware reports an out-of-bounds hw_head, the loop will access unpopulated slots in ring->tx_buf, returning a NULL skb that gets immediately dereferenced.
Quoted 22 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +22
-0+if (desc_cnt > clean_desc) +break ; + + ring->tx_buf[head] =NULL ; + + clean_desc -= desc_cnt; + +/* Step over the metadata descriptor */ + 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--) { +mpnic_unmap_page_twd (nv->dev, &ring->desc[head]); + head++; + head &= ring->size_mask; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net-next 4/8] eth: mpnic: implement Tx queue allocation and cleanup
In reply to Daniel ZahkaThank 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] Cached doorbell pointers let queue-head MMIO writes reach BAR0 after the driver has marked the device as gone.
- [Low] Concern (baseline: rejected): mpnic_alloc_ring_desc() stores count - 1 into the u16 ring->size_mask (line 334) without checking…
- [Low] Concern (baseline: rejected): mpnic_clean_tcq() takes HEAD0 from the device-written completion descriptor (line 163) and passes it…
--
eth: mpnic: implement Tx queue allocation and cleanup
This adds the Tx ring structures and allocates queue triads per NAPI vector, along with their descriptor memory and interrupts. It also adds Tx completion processing, where one completion reports a work queue head and can release many packets. Nothing enables the queues in hardware yet.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0@@ -0,0 +1,496 @@
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 139
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: Low]
Can this doorbell write still reach BAR0 after the driver has marked the device as gone?
mpnic_alloc_napi_vector() reads mpd->uc_addr0 once and stores raw BAR0 addresses in the rings:
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);When mpnic_rd64() sees all-ones reads, mpnic_mmio_err() in mpnic_pci.c clears only the accessor pointer:
WRITE_ONCE(mpd->uc_addr0, NULL);
BAR0 stays mapped through pcim_iomap_region(). mpnic_wr64() checks for the NULL pointer, but mpnic_commit_cq_head() always writes through cmpl->doorbell.
So suppose one mpnic_poll() run still has unprocessed completions that were posted before the failure. The TCQ head doorbell write goes out, while the mpnic_nv_irq_rearm() write through mpnic_wr64() is dropped.
The scaffolding commit says that once the device is gone, no further accesses reach the bus. Should that also cover the doorbells?
Later in the series, mpnic_tx_doorbell() and __mpnic_bdq_commit_tail() use the same cached-pointer pattern. Would a mpnic_present() check help in those places and here?
The comment in mpnic_alloc_napi_vector() already says the doorbells cannot notice the window going away, and fbnic does the same thing. The practical effect is probably limited to posted writes to a dead link.
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +3
-0+static void mpnic_clean_tcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int napi_budget) +{
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +7
-0+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);
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 178
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +5
-0+ cmpl->head = head; + +if (head0 >=0 ) +mpnic_clean_twq0 (nv, napi_budget, &qt->sub0, false, head0); +}
[Severity: Low]
This isn't a bug with a conforming device, but head0 comes straight from the completion descriptor the device writes. It goes to mpnic_clean_twq0() without any check against sub0.tail.
If the device ever reported a head past the posted tail, mpnic_clean_twq0() would reach an empty slot and dereference NULL:
struct sk_buff *skb = ring->tx_buf[head];
...
desc_cnt = MPNIC_XMIT_CB(skb)->desc_count;The completion walk loop is also not bounded by the NAPI budget. In practice the device cannot post past the CQ head, and that head is only committed after the loop.
Stale entries from an earlier bringup do not look reachable. The descriptor memory is freshly zeroed by dma_alloc_coherent(), the head and tail are reset to 0 later in the series, and at head 0 the expected DONE bit is 1.
Would a cheap sanity check on head0, or a NULL check on skb, be worth adding as hardening?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +3
-0+static int mpnic_alloc_ring_desc (struct mpnic_net *mpn, +struct mpnic_ring *ring,u32 count) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 335
Quoted 2 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +2
-0+ ring->size_mask = count -1 ; + ring->size = size;
[Severity: Low]
This isn't a bug with the current callers, but count is a u32 while ring->size_mask is a u16 in struct mpnic_ring. Nothing here checks that count is a non-zero power of two no larger than 65536.
This cannot be reached today. The only caller passes mpn->txq_size, which is only ever set to MPNIC_TXQ_SIZE_DEFAULT (1024), and there is no set_ringparam path.
If a runtime ring size setter is added later, a count that is zero, not a power of two, or above 65536 would break the masked indexes in mpnic_clean_twq0() and mpnic_clean_tcq().
Would a WARN_ON_ONCE() or an explicit check here be worthwhile?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 4/8] eth: mpnic: implement Tx queue allocation and cleanup
Quoted 70 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] Cached doorbell pointers let queue-head MMIO writes reach BAR0 after the driver has marked the device as gone.
- [Low] Concern (baseline: rejected):mpnic_alloc_ring_desc()storescount - 1into the u16ring->size_mask(line 334) without checking…
- [Low] Concern (baseline: rejected):mpnic_clean_tcq()takes HEAD0 from the device-written completion descriptor (line 163) and passes it…--
eth: mpnic: implement Tx queue allocation and cleanup
This adds the Tx ring structures and allocates queue triads per NAPI vector, along with their descriptor memory and interrupts. It also adds Tx completion processing, where one completion reports a work queue head and can release many packets. Nothing enables the queues in hardware yet.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +0
-0@@ -0,0 +1,496 @@[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 139
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: Low]
Can this doorbell write still reach BAR0 after the driver has marked the device as gone?
mpnic_alloc_napi_vector()readsmpd->uc_addr0once and stores raw BAR0 addresses in the rings: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);When
mpnic_rd64()sees all-ones reads,mpnic_mmio_err()inmpnic_pci.cclears only the accessor pointer:WRITE_ONCE(mpd->uc_addr0, NULL);BAR0 stays mapped through
pcim_iomap_region().mpnic_wr64()checks for the NULL pointer, butmpnic_commit_cq_head()always writes throughcmpl->doorbell.So suppose one
mpnic_poll()run still has unprocessed completions that were posted before the failure. The TCQ head doorbell write goes out, while thempnic_nv_irq_rearm()write throughmpnic_wr64()is dropped.The scaffolding commit says that once the device is gone, no further accesses reach the bus. Should that also cover the doorbells?
Quoted 8 lines
Later in the series,
mpnic_tx_doorbell()and__mpnic_bdq_commit_tail()use the same cached-pointer pattern. Would ampnic_present()check help in those places and here?The comment in
mpnic_alloc_napi_vector()already says the doorbells cannot notice the window going away, and fbnic does the same thing. The practical effect is probably limited to posted writes to a dead link.
The observation is correct, but this is by design. Won't fix. If we lose the device, we can let these writes get dropped by the bus instead of trying to stop them.
Quoted 16 lines
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +3
-0+static void mpnic_clean_tcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int napi_budget) +{[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +7
-0+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);[ ... ]
Quoted 11 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 178
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +5
-0+ cmpl->head = head; + +if (head0 >=0 ) +mpnic_clean_twq0 (nv, napi_budget, &qt->sub0, false, head0); +}[Severity: Low]
This isn't a bug with a conforming device, but head0 comes straight from the completion descriptor the device writes. It goes tompnic_clean_twq0()without any check against sub0.tail.
In this case, and in general, we do not perform this type of hardening against completion fields written by the device. We trust its outputs for things like offsets into buffers, rings, etc.
Quoted 27 lines
If the device ever reported a head past the posted tail,
mpnic_clean_twq0()would reach an empty slot and dereference NULL:struct sk_buff *skb = ring->tx_buf[head]; ... desc_cnt = MPNIC_XMIT_CB(skb)->desc_count;The completion walk loop is also not bounded by the NAPI budget. In practice the device cannot post past the CQ head, and that head is only committed after the loop.
Stale entries from an earlier bringup do not look reachable. The descriptor memory is freshly zeroed by
dma_alloc_coherent(), the head and tail are reset to 0 later in the series, and at head 0 the expected DONE bit is 1.Would a cheap sanity check on head0, or a NULL check on skb, be worth adding as hardening?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +3
-0+static int mpnic_alloc_ring_desc (struct mpnic_net *mpn, +struct mpnic_ring *ring,u32 count) +{[ ... ]
Quoted 8 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c line 335
Quoted 2 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c new file +2
-0+ ring->size_mask = count -1 ; + ring->size = size;[Severity: Low]
This isn't a bug with the current callers, but count is a u32 whilering->size_maskis a u16 in structmpnic_ring. Nothing here checks that count is a non-zero power of two no larger than 65536.
Ack, but won't fix. When ethool is implemented, caller will have the responsibility of ensuring these.
Quoted 9 lines
This cannot be reached today. The only caller passes
mpn->txq_size, which is only ever set toMPNIC_TXQ_SIZE_DEFAULT(1024), and there is noset_ringparampath.If a runtime ring size setter is added later, a count that is zero, not a power of two, or above 65536 would break the masked indexes in
mpnic_clean_twq0()andmpnic_clean_tcq().Would a
WARN_ON_ONCE()or an explicit check here be worthwhile?
PATCH 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
@@ -37,11 +37,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 */
@@ -51,6 +66,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 */
@@ -84,6 +104,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 */
@@ -101,6 +123,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 */
@@ -136,10 +160,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 5/8] eth: mpnic: start and stop the Tx HW queues
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] eth: mpnic: hardware pipeline deadlock from incorrect teardown sequence - [High] eth: mpnic: DMA…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] eth: mpnic: hardware pipeline deadlock from incorrect teardown sequence
- [High] eth: mpnic: DMA use-after-free due to ignored queue idle timeout --
commit f74c6bf4e3ce87eee577108084c59c43728d6d01
Author: Daniel Zahka <[email protected]>
eth: mpnic: start and stop the Tx HW queues
This patch points the hardware at the descriptor rings and provides functions for turning the Tx queues on and off. Teardown waits for the DMA engines to go idle before the ring memory can be freed.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-0@@ -460,6 +461,180 @@ void mpnic_reset_netif_queues(struct mpnic_net *mpn) } } +static void mpnic_enable_twq (struct mpnic_dev *mpd,struct mpnic_ring *twq)
[ ... ]
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+void mpnic_enable (struct mpnic_net *mpn) +{ +struct mpnic_dev *mpd = mpn->mpd; +int i, j; + +for (i =0 ; i < mpn->num_napi; i++) {
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 520
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) { +mpnic_enable_twq (mpd, &nv->qt[j].sub0); +mpnic_enable_tcq (mpd, nv, &nv->qt[j].cmpl); + } + } + +mpnic_wrfl (mpd); +}
[Severity: High]
Does enabling the Transmit Work Queue (TWQ) before the Transmit Completion Queue (TCQ) allow in-flight descriptors to complete against a disabled TCQ?
Could we swap the initialization order in mpnic_enable so the TCQ is ready before the hardware picks up new work?
Quoted 21 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +21
-0+static void mpnic_disable_twq (struct mpnic_dev *mpd,struct mpnic_ring *txr) +{ +u64 twq_ctl =mpnic_rd64 (mpd,MPNIC_TWQ_CTL (txr->q_idx,0 )); + + twq_ctl &= ~MPNIC_TWQ_CTL_ENABLE ; +mpnic_wr64 (mpd,MPNIC_TWQ_CTL (txr->q_idx,0 ), twq_ctl); +} + +static void mpnic_disable_tcq (struct mpnic_dev *mpd,struct mpnic_ring *txr) +{ +mpnic_wr64 (mpd,MPNIC_TCQ_CTL (txr->q_idx),0 ); +mpnic_wr64 (mpd,MPNIC_TIM_INTR_MASK (txr->q_idx), +MPNIC_TIM_INTR_MASK_MASK ); +} + +void mpnic_disable (struct mpnic_net *mpn) +{ +struct mpnic_dev *mpd = mpn->mpd; +int i, j; + +for (i =0 ; i < mpn->num_napi; i++) {
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 552
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+struct mpnic_napi_vector *nv = mpn->napi[i]; + +for (j =0 ; j < nv->txt_count; j++) { +mpnic_disable_twq (mpd, &nv->qt[j].sub0); +mpnic_disable_tcq (mpd, &nv->qt[j].cmpl); + } + } + +mpnic_wrfl (mpd); +}
[Severity: High]
Does shutting down the TCQ concurrently with the TWQ stall the hardware pipeline during teardown?
If the TWQ is disabled, packets already in the pipeline still need to be completed. By disabling the TCQ immediately in mpnic_disable, the DMA engine (TDE) is blocked from writing completions to host memory.
Will this prevent the pipeline from ever reaching an idle state, guaranteeing that the subsequent wait for idle queues times out? Should we disable the TWQ, wait for the pipeline to drain, and then disable the TCQ?
[ ... ]
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 616
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 returning void here prevent callers from handling hardware wedges safely?
If the 500ms timeout is reached in read_poll_timeout(), mpnic_wait_all_queues_idle logs an error but the caller will unconditionally proceed to free the DMA-mapped descriptor rings.
Could freeing this memory while the DMA engine is still active cause a DMA use-after-free, leading to IOMMU faults or memory corruption? Should this function return the error so callers can either leak the memory or issue a hard device reset if the device fails to idle?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net-next 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: 0 · Medium: 2 · 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] mpnic_wait_all_queues_idle() (drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:599) returns void.
- [Medium] mpnic_non_idle_queues() (mpnic_txrx.c:569-570) counts a block as idle when every idle register reads ~0ULL.
--
eth: mpnic: start and stop the Tx HW queues
This commit programs the Tx work and completion queue base addresses and sizes into the hardware, and adds helpers to enable and disable the Tx queues. It also adds mpnic_wait_all_queues_idle(), which polls the idle bitmaps of the TWQ, TQS, TDE and TCQ blocks so that teardown can wait for the DMA engines before the rings are freed.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+static u32 mpnic_non_idle_queues (struct mpnic_dev *mpd, +const struct mpnic_idle_regs *regs, +unsigned int nregs) +{
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 573
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+u32 non_idle_bitmap =0 ; +unsigned int i, j; + +for (i =0 ; i < nregs; i++) { +for (j =0 ; j < regs[i].reg_cnt; j++) { +if (mpnic_rd64 (mpd, regs[i].reg_base +2 * j) != + ~0ULL ) { + non_idle_bitmap |=BIT (i); +break ; + }
[Severity: Medium]
Could this report a device that can't be reached as idle? The idle test here is ~0ULL, and mpnic_rd64() returns that same value once CSR access has been disabled:
drivers/net/ethernet/meta/mpnic/mpnic_pci.c:mpnic_rd64() {
u32 __iomem *csr = READ_ONCE(mpd->uc_addr0);
...
if (!csr)
return ~0ULL;
...
mpnic_mmio_err(mpd, reg);
return ~0ULL;
}mpnic_wr64() also drops writes silently in that state:
if (csr) writeq(val, csr + reg);
After mpnic_mmio_err() clears uc_addr0, the writes in mpnic_disable() that clear MPNIC_TWQ_CTL_ENABLE and MPNIC_TCQ_CTL never reach the device. On the first poll, mpnic_wait_all_queues_idle() then sees all four blocks as idle and returns without a timeout. The caller can't tell a confirmed idle state apart from an unreadable device, so it goes on to free the rings.
mpnic_mmio_err() logs "awaiting reset", which suggests the device may be recoverable rather than gone. Suppose the device can still bus-master after two all-ones reads in a row, for example after a transient MMIO failure. Could its still-enabled queues then DMA into ring memory that has already been freed?
[ ... ]
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 616
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: Medium]
What happens to the rings when this poll times out? The -ETIMEDOUT in err is only passed to mpnic_idle_dump() for logging and then dropped. Because the function returns void, no caller can act on the timeout.
The commit message says:
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.
Later in the series, though, mpnic_stop() runs the teardown with no condition between the steps:
mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);
After a timeout, mpnic_flush() calls mpnic_clean_twq0() with qt->sub0.tail. That unmaps every pending TWD and frees the in-flight skbs. mpnic_free_ring_resources() then calls dma_free_coherent() on the TWQ and TCQ descriptor rings, whose addresses mpnic_enable_twq() and mpnic_enable_tcq() handed to the hardware.
If a block is still busy after 500 ms, can the device still read the freed skb data and descriptors? Can it write completions into the freed TCQ memory?
The final version of the series (the "eth: mpnic: add basic Rx handling" commit) still returns void and still frees unconditionally. It also adds the Rx HPQ/PPQ/RCQ blocks to this wait, which would expose the Rx rings and page pool pages the same way.
Should mpnic_wait_all_queues_idle() return the error? Teardown could then avoid freeing memory the device may still be using.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 5/8] eth: mpnic: start and stop the Tx HW queues
Quoted 76 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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]
mpnic_wait_all_queues_idle()(drivers/net/ethernet/meta/mpnic/mpnic_txrx.c:599) returns void.
- [Medium]mpnic_non_idle_queues()(mpnic_txrx.c:569-570) counts a block as idle when every idle register reads ~0ULL.--
eth: mpnic: start and stop the Tx HW queues
This commit programs the Tx work and completion queue base addresses and sizes into the hardware, and adds helpers to enable and disable the Tx queues. It also adds
mpnic_wait_all_queues_idle(), which polls the idle bitmaps of the TWQ, TQS, TDE and TCQ blocks so that teardown can wait for the DMA engines before the rings are freed.Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+static u32 mpnic_non_idle_queues (struct mpnic_dev *mpd, +const struct mpnic_idle_regs *regs, +unsigned int nregs) +{drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_reset_netif_queues(struct mpnic_net *mpn) · line 573
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+u32 non_idle_bitmap =0 ; +unsigned int i, j; + +for (i =0 ; i < nregs; i++) { +for (j =0 ; j < regs[i].reg_cnt; j++) { +if (mpnic_rd64 (mpd, regs[i].reg_base +2 * j) != + ~0ULL ) { + non_idle_bitmap |=BIT (i); +break ; + }[Severity: Medium]
Could this report a device that can't be reached as idle? The idle test here is ~0ULL, andmpnic_rd64()returns that same value once CSR access has been disabled:drivers/net/ethernet/meta/mpnic/mpnic_pci.c:mpnic_rd64() { u32 __iomem *csr = READ_ONCE(mpd->uc_addr0); ... if (!csr) return ~0ULL; ... mpnic_mmio_err(mpd, reg); return ~0ULL; }
mpnic_wr64()also drops writes silently in that state:if (csr) writeq(val, csr + reg);After
mpnic_mmio_err()clearsuc_addr0, the writes inmpnic_disable()that clearMPNIC_TWQ_CTL_ENABLEandMPNIC_TCQ_CTLnever reach the device. On the first poll,mpnic_wait_all_queues_idle()then sees all four blocks as idle and returns without a timeout. The caller can't tell a confirmed idle state apart from an unreadable device, so it goes on to free the rings.
Quoted 6 lines
mpnic_mmio_err()logs "awaiting reset", which suggests the device may be recoverable rather than gone. Suppose the device can still bus-master after two all-ones reads in a row, for example after a transient MMIO failure. Could its still-enabled queues then DMA into ring memory that has already been freed?
Won't fix. Our assumption is that losing the device is not a transient failure mode, and will require a PCI reset (not implemented yet), or re probing the device.
Quoted 50 lines
Quoted 9 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 616
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: Medium]
What happens to the rings when this poll times out? The-ETIMEDOUTin err is only passed tompnic_idle_dump()for logging and then dropped. Because the function returns void, no caller can act on the timeout.The commit message says:
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.
Later in the series, though,
mpnic_stop()runs the teardown with no condition between the steps:mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);After a timeout,
mpnic_flush()callsmpnic_clean_twq0()withqt->sub0.tail. That unmaps every pending TWD and frees the in-flight skbs.mpnic_free_ring_resources()then callsdma_free_coherent()on the TWQ and TCQ descriptor rings, whose addressesmpnic_enable_twq()andmpnic_enable_tcq()handed to the hardware.If a block is still busy after 500 ms, can the device still read the freed skb data and descriptors? Can it write completions into the freed TCQ memory?
Quoted 7 lines
The final version of the series (the "eth: mpnic: add basic Rx handling" commit) still returns void and still frees unconditionally. It also adds the Rx HPQ/PPQ/RCQ blocks to this wait, which would expose the Rx rings and page pool pages the same way.
Should
mpnic_wait_all_queues_idle()return the error? Teardown could then avoid freeing memory the device may still be using.
Won't fix. If the device is not reporting idle, I think something like this could be possible with respect to stray DMAs, but I'm not sure what we can do other than leaking the memory. Also, the device would be in somewhat of an unknown state, so all bets are off anyway.
PATCH 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.
--- 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 | 176 +++++++++++++++++++++++++ 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, 377 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
@@ -15,6 +15,13 @@/* Transmit Work Descriptor Format */ #define MPNIC_TWD_L2_HLEN DESC_GENMASK(5, 0)#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 +176 -0
176 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 6/8] eth: mpnic: add a netdevice and basic Tx handling
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: mpnic: invalid dma_map_single() with size 0 for completely paged SKBs --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: mpnic: invalid dma_map_single() with size 0 for completely paged SKBs --
commit 8d7cf250060d2193a80aa7f55598e2da19bf8165
Author: Daniel Zahka <[email protected]>
eth: mpnic: add a netdevice and basic Tx handling
This commit registers the mpnic network interface and implements basic transmit handling, including doorbell logic and descriptor mapping.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 15 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +11
-0@@ -67,6 +92,138 @@ static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE); } +static bool +mpnic_tx_map (struct mpnic_ring *ring,struct sk_buff *skb,__le64 *meta) +{ +struct device *dev = skb->dev->dev.parent; +unsigned int tail = ring->tail, first; +unsigned int size, data_len; +skb_frag_t *frag; +dma_addr_t dma; +__le64 *twd; + + tail++;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd) · line 115
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+ tail &= ring->size_mask; + first = tail; + + size =skb_headlen (skb); + data_len = skb->data_len; + +if (size >FIELD_MAX (MPNIC_TWD_LEN )) + goto err_dma; + + dma =dma_map_single (dev, skb->data, size,DMA_TO_DEVICE );
[Severity: High]
Does this code map a zero-length region if the skb is completely paged?
If a completely paged skb is transmitted (for example, from an af_packet socket) where the total length is large enough to bypass padding but skb_headlen(skb) is 0, size will be 0 here.
Calling dma_map_single() with a size of 0 violates the DMA API contract and triggers a WARN_ON_ONCE. It also submits a 0-length data descriptor to the device, which might stall the transmit queue or crash the firmware.
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+ +for (frag = &skb_shinfo (skb)->frags[0 ];; frag++) { + twd = &ring->desc[tail];
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH net-next 6/8] eth: mpnic: add a netdevice and basic Tx handling
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: 0 · Medium: 3 · 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] mpnic_open() (drivers/net/ethernet/meta/mpnic/mpnic_netdev.c) can succeed and show a dead device as up.
- [Medium] The new ndo_stop, mpnic_stop() in drivers/net/ethernet/meta/mpnic/mpnic_netdev.c, reclaims DMA memory…
- [Medium] No TX traffic or drops are ever accounted.
--
eth: mpnic: add a netdevice and basic Tx handling
This patch registers a netdev for the mpnic driver and adds ndo_open and ndo_stop. It also adds a basic transmit path that builds one metadata descriptor plus address/length descriptors per skb, defers doorbells for xmit_more bursts, and flushes the deferred doorbell when a packet is dropped. mpnic_mmio_err() now detaches the netdev when MMIO fails.
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +0
-0@@ -0,0 +1,176 @@
[ ... ]
Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +14
-0+static int mpnic_open (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); +int err; + + err =mpnic_alloc_napi_vectors (mpn); +if (err) +return err; + + err =mpnic_alloc_resources (mpn); +if (err) + goto err_free_napi_vectors; + + err =mpnic_set_netif_queues (mpn);
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 37
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +10
-0+if (err) + goto err_free_resources; + +mpnic_enable (mpn); +mpnic_napi_enable (mpn); + +netif_tx_wake_all_queues (netdev); +netif_carrier_on (netdev); + +return 0 ;
[Severity: Medium]
Can mpnic_open() return success for a device that has just been detached?
mpnic_enable() and mpnic_napi_enable() both end with mpnic_wrfl(), which is mpnic_rd64(mpd, MPNIC_BDQ_SPARE). If that read returns all ones, the confirmation read is skipped because reg == MPNIC_BDQ_SPARE. As a result, mpnic_mmio_err() runs. With this patch that handler now does:
/* Tell the stack the device has lost its PCIe link */ if (mpd->netdev) netif_device_detach(mpd->netdev);
__dev_open() has already set __LINK_STATE_START before calling ndo_open. netif_running() is therefore true, and the detach stops all tx queues. mpnic_open() then continues without checking anything:
mpnic_open()
mpnic_enable()
mpnic_wrfl()->mpnic_rd64()->mpnic_mmio_err()
netif_device_detach()->netif_tx_stop_all_queues()
mpnic_napi_enable()
netif_tx_wake_all_queues()
netif_carrier_on()
return 0netif_tx_wake_queue() does not check whether the device is present. So the queues are awake again, carrier is on and IFF_UP gets set, while __LINK_STATE_PRESENT is clear and uc_addr0 is NULL.
mpnic_xmit_frame() doesn't check presence either. It keeps filling descriptors and calling writeq() on the cached ring->doorbell. No completions come back, and dev_watchdog skips non-present devices, so no tx timeout fires either.
Would it make sense to check mpnic_present() or netif_device_present() after the enable steps, and unwind if the check fails?
Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +14
-0+ +err_free_resources: +mpnic_free_resources (mpn); +err_free_napi_vectors: +mpnic_free_napi_vectors (mpn); +return err; +} + +static int mpnic_stop (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); + +netif_carrier_off (netdev); +
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 61
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +10
-0+mpnic_napi_disable (mpn); +netif_tx_disable (netdev); + +mpnic_disable (mpn); +mpnic_wait_all_queues_idle (mpn->mpd); +mpnic_flush (mpn); + +mpnic_reset_netif_queues (mpn); +mpnic_free_resources (mpn); +mpnic_free_napi_vectors (mpn);
[Severity: Medium]
What happens here if mpnic_wait_all_queues_idle() times out? It returns void and only logs the failure:
mpnic_wait_all_queues_idle() {
...
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 always carries on with:
mpnic_flush()
mpnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail)
unmaps and frees every outstanding skb
mpnic_free_resources()->mpnic_free_ring_resources()
dma_free_coherent() on the TWQ and TCQ rings
If a Tx block (TWQ/TQS/TDE/TCQ) is still busy after 500 ms, can the device read from unmapped skb pages or write completions into freed coherent memory? The TCQ is only disabled by writing TCQ_CTL = 0.
This path has no fallback: no flush retry, no function reset, no clearing of bus mastering. For comparison, fbnic calls fbnic_tx_flush() and polls again before giving up.
A related case: if an earlier MMIO failure already cleared uc_addr0, mpnic_disable() skips all its writes, and mpnic_rd64() returns ~0 for every idle register. Does the wait then report idle straight away, so the rings are freed even though the queues were never disabled?
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +3
-0+ +return 0 ; +}
[ ... ]
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 218
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]
Are these drops counted anywhere?
Both drop paths return NETDEV_TX_OK without calling dev_core_stats_tx_dropped_inc() or updating any other counter:
- err_drop, when skb_put_padto() fails
- err_free, when mpnic_tx_map() fails on a DMA mapping error or an oversized head or fragment
The only trace is the rate-limited netdev_err() on the DMA path.
There is also no stats path in general. mpnic_netdev_ops has no .ndo_get_stats64 or .ndo_get_stats, and netdev->stats is never updated. mpnic_clean_twq0() passes its totals only to BQL, through netif_txq_completed_wake().
Won't ip -s link then show tx_packets, tx_bytes and tx_dropped as 0 on an interface that is transmitting and dropping packets?
The struct net_device_ops statistics comment in include/linux/netdevice.h says drivers must implement one of the supported statistics mechanisms. This still seems to be the case at the end of the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 6/8] eth: mpnic: add a netdevice and basic Tx handling
Quoted 91 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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]
mpnic_open()(drivers/net/ethernet/meta/mpnic/mpnic_netdev.c) can succeed and show a dead device as up.
- [Medium] The newndo_stop,mpnic_stop()indrivers/net/ethernet/meta/mpnic/mpnic_netdev.c, reclaims DMA memory…
- [Medium] No TX traffic or drops are ever accounted.--
eth: mpnic: add a netdevice and basic Tx handling
This patch registers a netdev for the mpnic driver and adds
ndo_openandndo_stop. It also adds a basic transmit path that builds one metadata descriptor plus address/length descriptors per skb, defers doorbells forxmit_morebursts, and flushes the deferred doorbell when a packet is dropped.mpnic_mmio_err()now detaches the netdev when MMIO fails.Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +0
-0@@ -0,0 +1,176 @@[ ... ]
Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +14
-0+static int mpnic_open (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); +int err; + + err =mpnic_alloc_napi_vectors (mpn); +if (err) +return err; + + err =mpnic_alloc_resources (mpn); +if (err) + goto err_free_napi_vectors; + + err =mpnic_set_netif_queues (mpn);drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 37
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +10
-0+if (err) + goto err_free_resources; + +mpnic_enable (mpn); +mpnic_napi_enable (mpn); + +netif_tx_wake_all_queues (netdev); +netif_carrier_on (netdev); + +return 0 ;[Severity: Medium]
Canmpnic_open()return success for a device that has just been detached?
mpnic_enable()andmpnic_napi_enable()both end withmpnic_wrfl(), which ismpnic_rd64(mpd, MPNIC_BDQ_SPARE). If that read returns all ones, the confirmation read is skipped because reg ==MPNIC_BDQ_SPARE. As a result,mpnic_mmio_err()runs. With this patch that handler now does:/* Tell the stack the device has lost its PCIe link */ if (mpd->netdev) netif_device_detach(mpd->netdev);
__dev_open()has already set__LINK_STATE_STARTbefore callingndo_open.netif_running()is therefore true, and the detach stops all tx queues.mpnic_open()then continues without checking anything:
mpnic_open()mpnic_enable() mpnic_wrfl()->mpnic_rd64()->mpnic_mmio_err() netif_device_detach()->netif_tx_stop_all_queues() mpnic_napi_enable() netif_tx_wake_all_queues() netif_carrier_on() return 0
netif_tx_wake_queue()does not check whether the device is present. So the queues are awake again, carrier is on andIFF_UPgets set, while__LINK_STATE_PRESENTis clear anduc_addr0is NULL.
Quoted 8 lines
mpnic_xmit_frame()doesn't check presence either. It keeps filling descriptors and callingwriteq()on the cachedring->doorbell. No completions come back, anddev_watchdogskips non-present devices, so no tx timeout fires either.Would it make sense to check
mpnic_present()ornetif_device_present()after the enable steps, and unwind if the check fails?
I don't think so. Losing the device here should be benign, and will require a reset, or the device to be re probed.
Quoted 51 lines
Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +14
-0+ +err_free_resources: +mpnic_free_resources (mpn); +err_free_napi_vectors: +mpnic_free_napi_vectors (mpn); +return err; +} + +static int mpnic_stop (struct net_device *netdev) +{ +struct mpnic_net *mpn =netdev_priv (netdev); + +netif_carrier_off (netdev); +drivers/net/ethernet/meta/mpnic/mpnic_netdev.c line 61
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +10
-0+mpnic_napi_disable (mpn); +netif_tx_disable (netdev); + +mpnic_disable (mpn); +mpnic_wait_all_queues_idle (mpn->mpd); +mpnic_flush (mpn); + +mpnic_reset_netif_queues (mpn); +mpnic_free_resources (mpn); +mpnic_free_napi_vectors (mpn);[Severity: Medium]
What happens here ifmpnic_wait_all_queues_idle()times out? It returns void and only logs the failure:mpnic_wait_all_queues_idle() { ... 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 always carries on with:
mpnic_flush()
mpnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail)
unmaps and frees every outstanding skb
mpnic_free_resources()->mpnic_free_ring_resources()
dma_free_coherent()on the TWQ and TCQ ringsIf a Tx block (TWQ/TQS/TDE/TCQ) is still busy after 500 ms, can the device read from unmapped skb pages or write completions into freed coherent memory? The TCQ is only disabled by writing
TCQ_CTL= 0.
Quoted 9 lines
This path has no fallback: no flush retry, no function reset, no clearing of bus mastering. For comparison, fbnic calls
fbnic_tx_flush()and polls again before giving up.A related case: if an earlier MMIO failure already cleared
uc_addr0,mpnic_disable()skips all its writes, andmpnic_rd64()returns ~0 for every idle register. Does the wait then report idle straight away, so the rings are freed even though the queues were never disabled?
This was addressed in prior patch.
Quoted 42 lines
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c new file +3
-0+ +return 0 ; +}[ ... ]
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 218
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]
Are these drops counted anywhere?
Quoted 2 lines
Both drop paths return
NETDEV_TX_OKwithout callingdev_core_stats_tx_dropped_inc()or updating any other counter:
doesn't sound like dev_core_stats_tx_dropped_inc() is supposed to be used in drivers.
Quoted 12 lines
-
err_drop, whenskb_put_padto()fails
-err_free, whenmpnic_tx_map()fails on a DMA mapping error or an oversized head or fragmentThe only trace is the rate-limited
netdev_err()on the DMA path.There is also no stats path in general.
mpnic_netdev_opshas no .ndo_get_stats64 or .ndo_get_stats, andnetdev->statsis never updated.mpnic_clean_twq0()passes its totals only to BQL, throughnetif_txq_completed_wake().
Quoted 6 lines
Won't ip -s link then show
tx_packets,tx_bytesandtx_droppedas 0 on an interface that is transmitting and dropping packets?The struct
net_device_opsstatistics comment ininclude/linux/netdevice.hsays drivers must implement one of the supported statistics mechanisms. This still seems to be the case at the end of the series.
Stats are planned as the next series.
PATCH 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.
--- drivers/net/ethernet/meta/Kconfig | 1 + drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 67 ++++ drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 5 + drivers/net/ethernet/meta/mpnic/mpnic_netdev.h | 5 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 451 +++++++++++++++++++++++-- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 72 +++- 6 files changed, 557 insertions(+), 44 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 +5 -0
@@ -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 ;
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 +415 -36
590 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +64 -8
115 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next 7/8] eth: mpnic: implement Rx queue allocation and cleanup
Thank 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: 0 · Medium: 1 · 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 Rx engines are added to an idle wait whose timeout is only logged, and teardown then frees memory the device writes into.
- [Low] The two comments about Rx buffer batching disagree with each other and with the code.
--
eth: mpnic: implement Rx queue allocation and cleanup
This adds the Rx side of the mpnic queue triad: a header buffer queue and a payload buffer queue, both fed from one page pool per triad, plus an Rx completion queue. Buffers are posted to the device in batches, and the device is set up to leave XDP headroom and skb_shared_info tailroom. Teardown releases any partially assembled frame and the buffers still posted.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0@@ -335,6 +336,109 @@ static void mpnic_clean_tcq(struct mpnic_napi_vector *nv,
[ ... ]
Quoted 30 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +30
-0+/* Descriptors are only handed to the device in whole batches, so the slot +* the device is working on and everything up to the next batch boundary +* stay untouched while it does. +*/ +static unsigned int mpnic_bdq_desc_unused (struct mpnic_ring *bdq) +{ +return (ALIGN_DOWN (bdq->head -1 ,MPNIC_BDQ_BATCH_SIZE ) - bdq->tail) & + bdq->size_mask; +} + +static unsigned int __mpnic_fill_bdq (struct mpnic_ring *bdq) +{ +unsigned int i = bdq->tail; +unsigned int count; + +for (count =mpnic_bdq_desc_unused (bdq); count; count--) { +struct page *page; + + page =page_pool_dev_alloc_pages (bdq->page_pool); +if (!page) +break ; + + bdq->rx_buf[i] = page; +mpnic_bd_prep (bdq, i, page); + + i++; + i &= bdq->size_mask; + } + +return i;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_clean_tcq(struct mpnic_napi_vector *nv, · line 388
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+} + +static void __mpnic_bdq_commit_tail (struct mpnic_ring *bdq,unsigned int tail) +{ +if (bdq->tail != tail) { + bdq->tail = tail; + +writeq (tail, bdq->doorbell); + } +}
[Severity: Low]
This isn't a bug, but is the comment on mpnic_bdq_desc_unused() accurate?
__mpnic_fill_bdq() stops as soon as page_pool_dev_alloc_pages() returns NULL. __mpnic_bdq_commit_tail() then writes that tail to the doorbell, so a tail that is not on a 64 descriptor boundary can reach the device. In that case descriptors are not handed over in whole batches.
It also looks like the slot at head - 1 stays untouched because of the "head - 1" term. Whole-batch posting is not what protects it. The ALIGN_DOWN only holds back up to 63 more slots that have already been consumed.
The comment on MPNIC_BDQ_BATCH_SIZE in mpnic_txrx.h gives a different reason for batching:
* doorbell. The device consumes whatever the doorbell points at, this is
* purely to keep the driver from writing the CSR for every descriptor.
Could the two comments be made consistent with each other and with what the refill code actually does?
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) · line 1089
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -760,6 +1081,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;
[Severity: Medium]
What happens in mpnic_stop() if one of the new Rx engines is still busy when this wait times out?
mpnic_wait_all_queues_idle() returns void. It only logs on timeout:
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 keeps tearing down:
mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);
mpnic_flush()->mpnic_clean_bdq() hands every posted HPQ/PPQ page back to the pool with page_pool_put_full_page(). After that, mpnic_free_resources()->mpnic_free_nv_resources()-> mpnic_free_rx_qt_resources() frees the RCQ ring with dma_free_coherent() and calls page_pool_destroy(), which unmaps and frees the pages.
The earlier commit "eth: mpnic: start and stop the Tx HW queues" says disabling a queue "only stops the device picking up new work, it does not tell us that the work already fetched has been retired". If so, a DMA_FROM_DEVICE write could still be in flight after a timeout. Examples are descriptors the prefetcher has already fetched, or a frame the RDE is partway through.
Could such a write land in RCQ memory or Rx pages that have already been unmapped and possibly reused? That would cause an IOMMU fault, or silent memory corruption on systems without an IOMMU. Before this patch, no device-written Rx buffers were covered by this best-effort wait.
Whether this can happen depends on whether a non-idle Rx engine can still complete DMA after the timeout. fbnic_down() follows the same ordering. Would it make sense to return the timeout to mpnic_stop() and avoid freeing device-writable memory (or reset the device first) when the queues never go idle?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 7/8] eth: mpnic: implement Rx queue allocation and cleanup
Quoted 154 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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 Rx engines are added to an idle wait whose timeout is only logged, and teardown then frees memory the device writes into.
- [Low] The two comments about Rx buffer batching disagree with each other and with the code.--
eth: mpnic: implement Rx queue allocation and cleanup
This adds the Rx side of the mpnic queue triad: a header buffer queue and a payload buffer queue, both fed from one page pool per triad, plus an Rx completion queue. Buffers are posted to the device in batches, and the device is set up to leave XDP headroom and
skb_shared_infotailroom. Teardown releases any partially assembled frame and the buffers still posted.Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0[ ... ]
Quoted 1 line
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0@@ -335,6 +336,109 @@ static void mpnic_clean_tcq(struct mpnic_napi_vector *nv,[ ... ]
Quoted 30 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +30
-0+/* Descriptors are only handed to the device in whole batches, so the slot +* the device is working on and everything up to the next batch boundary +* stay untouched while it does. +*/ +static unsigned int mpnic_bdq_desc_unused (struct mpnic_ring *bdq) +{ +return (ALIGN_DOWN (bdq->head -1 ,MPNIC_BDQ_BATCH_SIZE ) - bdq->tail) & + bdq->size_mask; +} + +static unsigned int __mpnic_fill_bdq (struct mpnic_ring *bdq) +{ +unsigned int i = bdq->tail; +unsigned int count; + +for (count =mpnic_bdq_desc_unused (bdq); count; count--) { +struct page *page; + + page =page_pool_dev_alloc_pages (bdq->page_pool); +if (!page) +break ; + + bdq->rx_buf[i] = page; +mpnic_bd_prep (bdq, i, page); + + i++; + i &= bdq->size_mask; + } + +return i;drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_clean_tcq(struct mpnic_napi_vector *nv, · line 388
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+} + +static void __mpnic_bdq_commit_tail (struct mpnic_ring *bdq,unsigned int tail) +{ +if (bdq->tail != tail) { + bdq->tail = tail; + +writeq (tail, bdq->doorbell); + } +}[Severity: Low]
This isn't a bug, but is the comment onmpnic_bdq_desc_unused()accurate?
__mpnic_fill_bdq()stops as soon aspage_pool_dev_alloc_pages()returns NULL.__mpnic_bdq_commit_tail()then writes that tail to the doorbell, so a tail that is not on a 64 descriptor boundary can reach the device. In that case descriptors are not handed over in whole batches.It also looks like the slot at head - 1 stays untouched because of the "head - 1" term. Whole-batch posting is not what protects it. The
ALIGN_DOWNonly holds back up to 63 more slots that have already been consumed.The comment on
MPNIC_BDQ_BATCH_SIZEinmpnic_txrx.hgives a different reason for batching:* doorbell. The device consumes whatever the doorbell points at, this is
* purely to keep the driver from writing the CSR for every descriptor.Could the two comments be made consistent with each other and with what the refill code actually does?
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd) · line 1089
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -760,6 +1081,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;[Severity: Medium]
What happens inmpnic_stop()if one of the new Rx engines is still busy when this wait times out?
mpnic_wait_all_queues_idle()returns void. It only logs on timeout: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 keeps tearing down:mpnic_disable(mpn); mpnic_wait_all_queues_idle(mpn->mpd); mpnic_flush(mpn); mpnic_reset_netif_queues(mpn); mpnic_free_resources(mpn);mpnic_flush()->mpnic_clean_bdq() hands every posted HPQ/PPQ page back to the pool with
page_pool_put_full_page(). After that, mpnic_free_resources()->mpnic_free_nv_resources()->mpnic_free_rx_qt_resources()frees the RCQ ring withdma_free_coherent()and callspage_pool_destroy(), which unmaps and frees the pages.The earlier commit "eth: mpnic: start and stop the Tx HW queues" says disabling a queue "only stops the device picking up new work, it does not tell us that the work already fetched has been retired". If so, a
DMA_FROM_DEVICEwrite could still be in flight after a timeout. Examples are descriptors the prefetcher has already fetched, or a frame the RDE is partway through.Could such a write land in RCQ memory or Rx pages that have already been unmapped and possibly reused? That would cause an IOMMU fault, or silent memory corruption on systems without an IOMMU. Before this patch, no device-written Rx buffers were covered by this best-effort wait.
Quoted 6 lines
Whether this can happen depends on whether a non-idle Rx engine can still complete DMA after the timeout.
fbnic_down()follows the same ordering. Would it make sense to return the timeout tompnic_stop()and avoid freeing device-writable memory (or reset the device first) when the queues never go idle?
Same complaint addressed already.
PATCH 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.
--- drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 7 + drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 205 ++++++++++++++++++++++++++- drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 14 +- 3 files changed, 213 insertions(+), 13 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +7 -0
@@ -131,6 +131,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 */
@@ -140,6 +144,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 -7
262 lines not on this page · raw message
drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +8 -6
@@ -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
@@ -61,15 +67,11 @@ struct mpnic_pg_ctxt {u32 idx; }; -struct mpnic_pkt_ctxt { -struct xdp_buff buff; -u32 data_truesize; -}; -struct mpnic_rcq_state { -struct mpnic_pkt_ctxt pkt; +struct xdp_buff pkt;struct mpnic_pg_ctxt hdr;struct mpnic_pg_ctxt payld; +bool add_frag_failed; };struct mpnic_ring {
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next 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: unbounded NAPI budget in mpnic_poll causes fairness violation - [High] net: mpnic…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net: mpnic: unbounded NAPI budget in mpnic_poll causes fairness violation
- [High] net: mpnic: missing descriptor sequence validation causes NULL pointer dereference
- [Medium] net: mpnic: direct DMA sync on page pool buffers breaks memory providers --
commit a0a26aee27284ff3d767cd871801499330442f84
Author: Daniel Zahka <[email protected]>
eth: mpnic: add basic Rx handling
This commit introduces basic receive handling for the mpnic driver. It assembles frames using completion descriptors, merging contiguous payload fragments, and utilizes a batched page reference strategy to manage xdp_buff allocations.
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+static void +mpnic_pkt_prepare (struct mpnic_napi_vector *nv,u64 rcd, +struct mpnic_rcq_state *state,struct mpnic_q_triad *qt) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 490
Quoted 6 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-0+/* Short-cut the end calculation if the page is fully consumed */ + pg_end = fin ?page_size (page) :mpnic_hdr_pg_end (pg_off, len); + frame_sz = pg_end - pg_start; + +dma_sync_single_range_for_cpu (nv->dev,page_pool_get_dma_addr (page), + pg_start, frame_sz,DMA_FROM_DEVICE );
[Severity: Medium]
Does this break the abstraction for memory providers like dmabuf? Using dma_sync_single_range_for_cpu() directly on page pool buffers bypasses the standard page pool synchronization hooks like page_pool_dma_sync_for_cpu() or page_pool_dma_sync_netmem_for_cpu().
Quoted 13 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +13
-0+ +xdp_init_buff (buff, frame_sz, &qt->xdp_rxq); +xdp_prepare_buff (buff,page_address (page) + pg_start, + pg_off - pg_start, len, true); +net_prefetch (buff->data); + + state->add_frag_failed = false; +} + +static void +mpnic_add_rx_frag (struct mpnic_napi_vector *nv,u64 rcd, +struct mpnic_rcq_state *state,struct mpnic_q_triad *qt) +{
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 518
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+ truesz = (fin ?page_size (page) :ALIGN (pg_off + len,128 )) - pg_off; + +dma_sync_single_range_for_cpu (nv->dev,page_pool_get_dma_addr (page), + pg_off, truesz,DMA_FROM_DEVICE );
[Severity: Medium]
Similarly here, does direct use of dma_sync_single_range_for_cpu() on the payload fragments circumvent the required page pool wrappers?
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 521
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+ +if (!xdp_buff_add_frag (buff,page_to_netmem (page), pg_off, len, + truesz)) {
[Severity: High]
Can a malformed descriptor sequence crash the kernel here?
If the hardware delivers a payload (PAY_AL) descriptor before a header (HDR_AL) descriptor, mpnic_pkt_prepare() won't be called, so the buffer won't be properly initialized. The data_hard_start field would remain NULL, causing xdp_buff_add_frag() to compute an invalid pointer for the skb_shared_info.
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +4
-0+ state->payld.pagecnt_bias++; + state->add_frag_failed = true; + } +}
[ ... ]
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0+static int mpnic_clean_rcq (struct mpnic_napi_vector *nv, +struct mpnic_q_triad *qt,int budget) +{
[ ... ]
Quoted 16 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +16
-0+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 (nv, 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 589
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+case MPNIC_RCD_TYPE_PAY_AL : +mpnic_add_rx_frag (nv, rcd, state, qt); +break ; +case MPNIC_RCD_TYPE_META : { +struct sk_buff *skb =NULL ; + +if (likely (!(rcd & +MPNIC_RCD_META_UNCORRECTABLE_ERR_MASK ) && + !state->add_frag_failed)) + skb =xdp_build_skb_from_buff (&state->pkt);
[Severity: High]
If a metadata (META) descriptor is received before any header descriptor (HDR_AL), could xdp_build_skb_from_buff() also attempt to operate on an uninitialized state->pkt and dereference a NULL data_hard_start?
Quoted 11 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +11
-0+ +if (likely (skb)) +napi_gro_receive (&nv->napi, skb); +else +mpnic_put_pkt_buff (&state->pkt, true); + + state->pkt.data_hard_start =NULL ; + packets++; +break ; + } + }
[ ... ]
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 630
Quoted 13 lines
static int
mpnic_poll(struct napi_struct *napi, int budget){drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-1struct mpnic_napi_vector *nv =container_of (napi, struct mpnic_napi_vector, napi); -int i; +int i, j, work_done =0 ;for (i =0 ; i < nv->txt_count; i++)mpnic_clean_tcq (nv, &nv->qt[i], budget); +for (j =0 ; j < nv->rxt_count; j++, i++) + work_done +=mpnic_clean_rcq (nv, &nv->qt[i], budget);
[Severity: High]
Does this allow the total work done to dramatically exceed the NAPI limit?
The full budget is unconditionally passed to every RX queue without dividing or subtracting the work already done. A NAPI vector with multiple RX queues handling a burst could process nv->rxt_count * budget packets, potentially defeating softirq fairness mechanisms and causing high system latency.
Quoted 14 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +6
-2+for (i =0 ; i < nv->txt_count; i++)mpnic_commit_cq_head (&nv->qt[i].cmpl); -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); -return 0 ; +return work_done; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH net-next 8/8] eth: mpnic: add basic Rx handling
In reply to Daniel ZahkaThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · 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] net: mpnic: missing descriptor sequence validation causes NULL pointer dereference
- [Medium] mpnic_poll() calls mpnic_clean_rcq() even when budget is 0.
- [Medium] When page_pool_dev_alloc_pages() returns NULL, __mpnic_fill_bdq() stops refilling and returns the partial tail.
- [Medium] mpnic_pkt_prepare() re-initialises state->pkt with xdp_init_buff()/xdp_prepare_buff() without checking whether a frame is…
- [Medium] mpnic_page_pool_get() indexes ring->rx_buf[idx] with idx = FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd), an 18-bit device-written field…
- [Medium] The device-supplied completion fields BUFF_OFF (16 bits) and BUFF_LEN (14 bits) are never checked against page_size(page),…
--
eth: mpnic: add basic Rx handling
This adds Rx completion processing to mpnic. A frame is assembled into an xdp_buff from a header descriptor, one descriptor per payload page and a closing metadata descriptor, and then handed to the stack. Page references are taken in batches per page instead of once per frame.
Quoted 15 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0@@ -402,6 +402,34 @@ static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt)__mpnic_bdq_commit_tail (&qt->sub1, ppq_i); } +/* Take one of the references batched on the page at @idx. If the device +* has moved on to a new page, first drop the unused references left on +* the previous one. +*/ +static struct page * +mpnic_page_pool_get (struct mpnic_pg_ctxt *pg_ctxt,struct mpnic_ring *ring, +u32 idx)
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) · line 421
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+{ +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]
Can idx index past the end of ring->rx_buf[] here?
idx comes straight from the completion descriptor:
unsigned int pg_idx = FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd);
MPNIC_RCD_AL_BUFF_ID is an 18-bit field (DESC_GENMASK(33, 16)). rx_buf[] is sized by hpq_size/ppq_size, which is 256 entries by default.
Both callers mask the value only when they update head:
qt->sub0.head = (pg_idx + 1) & qt->sub0.size_mask;
If the device reports a BUFF_ID at or above the ring size, the pointer read from past the end of rx_buf[] is written through by page_pool_fragment_page(). It is then passed to page_address(), used for the DMA sync and attached to the skb.
A conforming device only echoes IDs the driver posted, so hitting this needs buggy firmware or an untrusted device. Would it make sense to mask idx with ring->size_mask before the lookup?
[ ... ]
Quoted 17 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +12
-1@@ -414,9 +442,90 @@ static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) } } -static void mpnic_put_pkt_buff (struct mpnic_pkt_ctxt *ctxt,bool napi) +static unsigned int mpnic_hdr_pg_start (unsigned int pg_off) +{ +/* The headroom of the first header may be larger than +* MPNIC_RX_HROOM due to alignment. So account for that by just +* making the page offset 0 if we are starting at the first header. +*/ +if (ALIGN (MPNIC_RX_HROOM ,128 ) >MPNIC_RX_HROOM && + pg_off ==ALIGN (MPNIC_RX_HROOM ,128 )) +return 0 ; + +return pg_off -MPNIC_RX_HROOM ; +}
[ ... ]
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+static void +mpnic_pkt_prepare (struct mpnic_napi_vector *nv,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); +unsigned int frame_sz, pg_start, pg_end; +struct xdp_buff *buff = &state->pkt;
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 487
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+struct page *page; + + pg_start =mpnic_hdr_pg_start (pg_off); + + page =mpnic_page_pool_get (&state->hdr, &qt->sub0, pg_idx); + qt->sub0.head = (pg_idx +1 ) & qt->sub0.size_mask; + +/* Short-cut the end calculation if the page is fully consumed */ + pg_end = fin ?page_size (page) :mpnic_hdr_pg_end (pg_off, len); + frame_sz = pg_end - pg_start;
[Severity: High]
What happens if a PAY_AL or META descriptor reaches this switch without a header descriptor opening the frame first?
In that case state->pkt.data_hard_start is NULL. Either the previous META cleared it, or no header has been seen since the queue was enabled. Nothing on the PAY_AL or META paths checks for this.
For PAY_AL, mpnic_add_rx_frag() first takes a reference through mpnic_page_pool_get(). It then calls xdp_buff_add_frag(), which finds skb_shared_info through xdp_get_shared_info_from_buff(), computed from data_hard_start + frame_sz. With data_hard_start NULL, and frame_sz and flags left over from the previous frame, the frag is written through a wild pointer near address zero.
For META, the build path runs unless the error bit or add_frag_failed is set. add_frag_failed may also be stale from the previous frame. xdp_build_skb_from_buff() then calls napi_build_skb() with a NULL data_hard_start. On a queue that has never seen a header, xdp->rxq may also be unset when rxq->mem.type is read. mpnic_put_pkt_buff() already copes with a NULL data_hard_start, but it only runs after the build path has failed.
As with the other descriptor trust issues above, a conforming device should always open a frame with a header descriptor, so reaching this needs buggy or untrusted firmware. The result is a host crash rather than a dropped frame, though.
Would it make sense to check state->pkt.data_hard_start in the PAY_AL and META cases and drop the descriptor when no frame is being assembled? On the PAY_AL path that would also mean returning the reference taken by mpnic_page_pool_get(), the same way the xdp_buff_add_frag() failure path does.
[Severity: Medium]
Should BUFF_OFF and BUFF_LEN from the completion be range checked before they are used here?
Neither value is checked against page_size(page), MPNIC_RX_HROOM or MPNIC_RX_TROOM:
- mpnic_hdr_pg_start() returns pg_off - MPNIC_RX_HROOM as an unsigned value, so it wraps if pg_off is below the headroom.
- mpnic_hdr_pg_end() can return an end past the page, and frame_sz = pg_end - pg_start can wrap. After that, xdp_build_skb_from_buff()->napi_build_skb(data_hard_start, frame_sz) would place and zero skb_shared_info outside the page.
- In mpnic_add_rx_frag(), truesz underflows when fin is set and pg_off is larger than the page:
truesz = (fin ? page_size(page) : ALIGN(pg_off + len, 128)) - pg_off;
The frag [pg_off, pg_off + len) is also attached with no check that it stays inside the page, which would expose adjacent memory through the skb.
The dma_sync_single_range_for_cpu() calls use the same unchecked ranges.
A conforming device honours the headroom and tailroom programmed in mpnic_set_rde_cfg() and stays within the page size, so hitting this needs buggy or untrusted hardware.
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 494
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0+ +dma_sync_single_range_for_cpu (nv->dev,page_pool_get_dma_addr (page), + pg_start, frame_sz,DMA_FROM_DEVICE ); + +xdp_init_buff (buff, frame_sz, &qt->xdp_rxq); +xdp_prepare_buff (buff,page_address (page) + pg_start, + pg_off - pg_start, len, true);
[Severity: Medium]
What happens here to a frame that is still being assembled when a new header descriptor arrives?
mpnic_clean_rcq() calls mpnic_pkt_prepare() for every header descriptor. It does not check whether state->pkt.data_hard_start is still set by an earlier frame that never got its META descriptor:
case MPNIC_RCD_TYPE_HDR_AL:
if (FIELD_GET(MPNIC_RCD_HDR_SUBTYPE, rcd) ==
MPNIC_RCD_HDR_SUBTYPE_HDR)
mpnic_pkt_prepare(nv, rcd, state, qt);In that case xdp_init_buff() clears buff->flags and xdp_prepare_buff() replaces data_hard_start. The old frame's header page reference from mpnic_page_pool_get() and its frag references from xdp_buff_add_frag() can no longer be reached.
The META path and mpnic_flush() cannot release them either, because mpnic_flush() only calls mpnic_put_pkt_buff() on the current state->pkt. Could the page pool pages leak here, leaving page_pool_destroy() waiting forever on inflight pages?
The code does not show whether the hardware can produce HDR, [PAY_AL ...], HDR without a META in between. fbnic has a WARN_ON_ONCE(pkt->buff.data_hard_start) for this case. Would a similar check here, plus releasing the old frame, make sense?
[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -439,23 +548,97 @@ 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 1 line
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-0+while (packets < budget) {
[ ... ]
Quoted 11 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) { struct mpnic_napi_vector *nv = container_of(napi,
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 630
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-1struct mpnic_napi_vector, napi); -int i; +int i, j, work_done =0 ;for (i =0 ; i < nv->txt_count; i++)mpnic_clean_tcq (nv, &nv->qt[i], budget); +for (j =0 ; j < nv->rxt_count; j++, i++) + work_done +=mpnic_clean_rcq (nv, &nv->qt[i], budget);
[Severity: Medium]
Is it safe to do the Rx side of the poll when budget is 0?
netpoll calls napi->poll(napi, 0) via netpoll_poll_dev()->poll_napi()->poll_one_napi(), and netconsole can reach that path from any context. With budget 0 the descriptor loop in mpnic_clean_rcq() is skipped, but the refill still runs:
mpnic_clean_rcq()
mpnic_fill_qt_bdqs()
__mpnic_fill_bdq()
page_pool_dev_alloc_pages()The allocation happens whenever mpnic_bdq_desc_unused() is non-zero, for example after an earlier allocation failure.
Documentation/networking/napi.rst says "Rx specific APIs like page pool or XDP cannot be used at all when budget is 0".
The page_pool allocation fast path, __page_pool_get_cached(), and page_pool_refill_alloc_cache() access pool->alloc.cache and the ptr_ring consumer side without taking a lock.
The pool was created with .napi = &nv->napi. That means page_pool_napi_local() allows direct recycling into alloc.cache from softirq on the NAPI's list_owner CPU, and netpoll's poll_owner does not exclude that.
Could this corrupt alloc.cache or the ring and hand out the same page twice? Skipping Rx cleaning and refill when budget is 0 would avoid it.
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 639
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-1+for (i =0 ; i < nv->txt_count; i++)mpnic_commit_cq_head (&nv->qt[i].cmpl); -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]
Can Rx stop for good after a run of allocation failures?
When page_pool_dev_alloc_pages() returns NULL, __mpnic_fill_bdq() just stops:
page = page_pool_dev_alloc_pages(bdq->page_pool);
if (!page)
break;mpnic_clean_rcq() returns only the packet count. So whenever work_done < budget, mpnic_poll() completes NAPI and rearms the IRQ, even if the refill did not succeed.
If allocations keep failing, successive polls can drain HPQ/PPQ until no buffers are posted. The device then has nothing to DMA into and raises no Rx interrupts. The only napi_schedule() in the driver is in mpnic_msix_clean_rings().
Rx would then stay stopped after memory is available again, until a Tx completion on the same vector triggers a poll or the interface is taken down and up. Should the poll stay scheduled, or set up a retry, when the BDQs could not be refilled?
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-1-return 0 ; +return work_done; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922-linux-mpnic-v1-0-236844f53072%40gmail.com
Re: [PATCH net-next 8/8] eth: mpnic: add basic Rx handling
Quoted 52 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · 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] net: mpnic: missing descriptor sequence validation causes NULL pointer dereference
- [Medium]mpnic_poll()callsmpnic_clean_rcq()even when budget is 0.
- [Medium] Whenpage_pool_dev_alloc_pages()returns NULL,__mpnic_fill_bdq()stops refilling and returns the partial tail.
- [Medium]mpnic_pkt_prepare()re-initialisesstate->pktwith xdp_init_buff()/xdp_prepare_buff() without checking whether a frame is…
- [Medium]mpnic_page_pool_get()indexes ring->rx_buf[idx] with idx =FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd), an 18-bit device-written field…
- [Medium] The device-supplied completion fieldsBUFF_OFF(16 bits) andBUFF_LEN(14 bits) are never checked against page_size(page),…--
eth: mpnic: add basic Rx handling
This adds Rx completion processing to mpnic. A frame is assembled into an
xdp_bufffrom a header descriptor, one descriptor per payload page and a closing metadata descriptor, and then handed to the stack. Page references are taken in batches per page instead of once per frame.Quoted 20 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +12
-0@@ -402,6 +402,34 @@ static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt)__mpnic_bdq_commit_tail (&qt->sub1, ppq_i); } +/* Take one of the references batched on the page at @idx. If the device +* has moved on to a new page, first drop the unused references left on +* the previous one. +*/ +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 &&
Quoted 9 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_fill_qt_bdqs(struct mpnic_q_triad *qt) · line 421
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-0+ !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]
Can idx index past the end of ring->rx_buf[] here?
Like I mentioned about the head field in the tx completion descriptor, we don't harden against device produced completion fields like this.
Quoted 91 lines
idx comes straight from the completion descriptor:
unsigned int pg_idx = FIELD_GET(MPNIC_RCD_AL_BUFF_ID, rcd);
MPNIC_RCD_AL_BUFF_IDis an 18-bit field (DESC_GENMASK(33, 16)). rx_buf[] is sized by hpq_size/ppq_size, which is 256 entries by default.Both callers mask the value only when they update head:
qt->sub0.head = (pg_idx + 1) & qt->sub0.size_mask;If the device reports a
BUFF_IDat or above the ring size, the pointer read from past the end of rx_buf[] is written through bypage_pool_fragment_page(). It is then passed topage_address(), used for the DMA sync and attached to the skb.A conforming device only echoes IDs the driver posted, so hitting this needs buggy firmware or an untrusted device. Would it make sense to mask idx with
ring->size_maskbefore the lookup?[ ... ]
Quoted 17 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +12
-1@@ -414,9 +442,90 @@ static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) } } -static void mpnic_put_pkt_buff (struct mpnic_pkt_ctxt *ctxt,bool napi) +static unsigned int mpnic_hdr_pg_start (unsigned int pg_off) +{ +/* The headroom of the first header may be larger than +* MPNIC_RX_HROOM due to alignment. So account for that by just +* making the page offset 0 if we are starting at the first header. +*/ +if (ALIGN (MPNIC_RX_HROOM ,128 ) >MPNIC_RX_HROOM && + pg_off ==ALIGN (MPNIC_RX_HROOM ,128 )) +return 0 ; + +return pg_off -MPNIC_RX_HROOM ; +}[ ... ]
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+static void +mpnic_pkt_prepare (struct mpnic_napi_vector *nv,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); +unsigned int frame_sz, pg_start, pg_end; +struct xdp_buff *buff = &state->pkt;drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 487
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +10
-0+struct page *page; + + pg_start =mpnic_hdr_pg_start (pg_off); + + page =mpnic_page_pool_get (&state->hdr, &qt->sub0, pg_idx); + qt->sub0.head = (pg_idx +1 ) & qt->sub0.size_mask; + +/* Short-cut the end calculation if the page is fully consumed */ + pg_end = fin ?page_size (page) :mpnic_hdr_pg_end (pg_off, len); + frame_sz = pg_end - pg_start;[Severity: High]
What happens if aPAY_ALor META descriptor reaches this switch without a header descriptor opening the frame first?In that case
state->pkt.data_hard_startis NULL. Either the previous META cleared it, or no header has been seen since the queue was enabled. Nothing on thePAY_ALor META paths checks for this.For
PAY_AL,mpnic_add_rx_frag()first takes a reference throughmpnic_page_pool_get(). It then callsxdp_buff_add_frag(), which findsskb_shared_infothroughxdp_get_shared_info_from_buff(), computed fromdata_hard_start+frame_sz. Withdata_hard_startNULL, andframe_szand flags left over from the previous frame, the frag is written through a wild pointer near address zero.For META, the build path runs unless the error bit or
add_frag_failedis set.add_frag_failedmay also be stale from the previous frame.xdp_build_skb_from_buff()then callsnapi_build_skb()with a NULLdata_hard_start. On a queue that has never seen a header,xdp->rxqmay also be unset whenrxq->mem.typeis read.mpnic_put_pkt_buff()already copes with a NULLdata_hard_start, but it only runs after the build path has failed.As with the other descriptor trust issues above, a conforming device should always open a frame with a header descriptor, so reaching this needs buggy or untrusted firmware. The result is a host crash rather than a dropped frame, though.
Quoted 6 lines
Would it make sense to check
state->pkt.data_hard_startin thePAY_ALand META cases and drop the descriptor when no frame is being assembled? On thePAY_ALpath that would also mean returning the reference taken bympnic_page_pool_get(), the same way thexdp_buff_add_frag()failure path does.
We trust the descriptor stream to be sequenced correctly.
Quoted 4 lines
[Severity: Medium]
ShouldBUFF_OFFandBUFF_LENfrom the completion be range checked before they are used here?
Won't fix.
Quoted 52 lines
Neither value is checked against
page_size(page),MPNIC_RX_HROOMorMPNIC_RX_TROOM:-
mpnic_hdr_pg_start()returnspg_off-MPNIC_RX_HROOMas an unsigned value, so it wraps ifpg_offis below the headroom.-
mpnic_hdr_pg_end()can return an end past the page, andframe_sz=pg_end-pg_startcan wrap. After that, xdp_build_skb_from_buff()->napi_build_skb(data_hard_start,frame_sz) would place and zeroskb_shared_infooutside the page.- In
mpnic_add_rx_frag(), truesz underflows when fin is set andpg_offis larger than the page:truesz = (fin ? page_size(page) : ALIGN(pg_off + len, 128)) - pg_off;The frag [
pg_off,pg_off+ len) is also attached with no check that it stays inside the page, which would expose adjacent memory through the skb.The
dma_sync_single_range_for_cpu()calls use the same unchecked ranges.A conforming device honours the headroom and tailroom programmed in
mpnic_set_rde_cfg()and stays within the page size, so hitting this needs buggy or untrusted hardware.drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_flush_pg_ctxt(struct mpnic_pg_ctxt *ctxt, bool napi) · line 494
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +7
-0+ +dma_sync_single_range_for_cpu (nv->dev,page_pool_get_dma_addr (page), + pg_start, frame_sz,DMA_FROM_DEVICE ); + +xdp_init_buff (buff, frame_sz, &qt->xdp_rxq); +xdp_prepare_buff (buff,page_address (page) + pg_start, + pg_off - pg_start, len, true);[Severity: Medium]
What happens here to a frame that is still being assembled when a new header descriptor arrives?
mpnic_clean_rcq()callsmpnic_pkt_prepare()for every header descriptor. It does not check whetherstate->pkt.data_hard_startis still set by an earlier frame that never got its META descriptor:case MPNIC_RCD_TYPE_HDR_AL: if (FIELD_GET(MPNIC_RCD_HDR_SUBTYPE, rcd) == MPNIC_RCD_HDR_SUBTYPE_HDR) mpnic_pkt_prepare(nv, rcd, state, qt);In that case
xdp_init_buff()clearsbuff->flagsandxdp_prepare_buff()replacesdata_hard_start. The old frame's header page reference frommpnic_page_pool_get()and its frag references fromxdp_buff_add_frag()can no longer be reached.
Quoted 7 lines
The META path and
mpnic_flush()cannot release them either, becausempnic_flush()only callsmpnic_put_pkt_buff()on the currentstate->pkt. Could the page pool pages leak here, leavingpage_pool_destroy()waiting forever on inflight pages?The code does not show whether the hardware can produce HDR, [
PAY_AL...], HDR without a META in between. fbnic has a
We trust that the hw cannot produce this sequence.
Quoted 35 lines
WARN_ON_ONCE(pkt->buff.data_hard_start)for this case. Would a similar check here, plus releasing the old frame, make sense?[ ... ]
Quoted 7 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +3
-0@@ -439,23 +548,97 @@ 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 1 line
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-0+while (packets < budget) {[ ... ]
Quoted 16 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +9
-1+ 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) {struct mpnic_napi_vector *nv =container_of (napi, struct mpnic_napi_vector, napi); -int i; +int i, j, work_done =0 ;
Quoted 9 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 630
Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +2
-0for (i =0 ; i < nv->txt_count; i++)mpnic_clean_tcq (nv, &nv->qt[i], budget); +for (j =0 ; j < nv->rxt_count; j++, i++) + work_done +=mpnic_clean_rcq (nv, &nv->qt[i], budget);[Severity: Medium]
Is it safe to do the Rx side of the poll when budget is 0?
Will address in v2.
Quoted 58 lines
netpoll calls
napi->poll(napi, 0)via netpoll_poll_dev()->poll_napi()->poll_one_napi(), and netconsole can reach that path from any context. With budget 0 the descriptor loop inmpnic_clean_rcq()is skipped, but the refill still runs:
mpnic_clean_rcq()
mpnic_fill_qt_bdqs()__mpnic_fill_bdq() page_pool_dev_alloc_pages()The allocation happens whenever
mpnic_bdq_desc_unused()is non-zero, for example after an earlier allocation failure.
Documentation/networking/napi.rstsays "Rx specific APIs like page pool or XDP cannot be used at all when budget is 0".The
page_poolallocation fast path,__page_pool_get_cached(), andpage_pool_refill_alloc_cache()accesspool->alloc.cacheand theptr_ringconsumer side without taking a lock.The pool was created with .napi =
&nv->napi. That meanspage_pool_napi_local()allows direct recycling into alloc.cache from softirq on the NAPI'slist_ownerCPU, and netpoll'spoll_ownerdoes not exclude that.Could this corrupt alloc.cache or the ring and hand out the same page twice? Skipping Rx cleaning and refill when budget is 0 would avoid it.
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c static void mpnic_put_pkt_buff(struct mpnic_pkt_ctxt *ctxt, bool napi) · line 639
Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +5
-1+for (i =0 ; i < nv->txt_count; i++)mpnic_commit_cq_head (&nv->qt[i].cmpl); -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]
Can Rx stop for good after a run of allocation failures?When
page_pool_dev_alloc_pages()returns NULL,__mpnic_fill_bdq()just stops:page = page_pool_dev_alloc_pages(bdq->page_pool); if (!page) break;
mpnic_clean_rcq()returns only the packet count. So wheneverwork_done< budget,mpnic_poll()completes NAPI and rearms the IRQ, even if the refill did not succeed.If allocations keep failing, successive polls can drain HPQ/PPQ until no buffers are posted. The device then has nothing to DMA into and raises no Rx interrupts. The only
napi_schedule()in the driver is inmpnic_msix_clean_rings().
Quoted 5 lines
Rx would then stay stopped after memory is available again, until a Tx completion on the same vector triggers a poll or the interface is taken down and up. Should the poll stay scheduled, or set up a retry, when the BDQs could not be refilled?
This will be addressed in v2. napi depletion check was improperly left out of this posting.
Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +1
-1-return 0 ; +return work_done; }[ ... ]