mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: illusion.wang@nebula-matrix.com
Cc: dimon.zhao@nebula-matrix.com, alvin.wang@nebula-matrix.com,
	sam.chen@nebula-matrix.com, netdev@vger.kernel.org,
	kuba@kernel.org, andrew+netdev@lunn.ch, pabeni@redhat.com,
	edumazet@google.com, horms@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v35 net-next 3/8] net/nebula-matrix: add intr resource implementation
Date: Mon, 23 Nov 2026 12:52:02 +0000	[thread overview]
Message-ID: <179543832271.3135.13613851022028576414@kernel.org> (raw)
In-Reply-To: <20261119113530.32107-4-illusion.wang@nebula-matrix.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The init scrub in nbl_intr_setup_mgt() invalidates only
  FUNCTION_MSIX_MAP.
- [Low] The commit message and the new nbl_probe() comment (nbl_main.c,
  "...Bus Master Enable, which the PCI core cleared on the way into this…
- [Low] At this commit, nbl_res_intr_cfg_msix_map(),
  nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq()…
- [Low] The header comment of nbl_intr_setup_mgt() justifies scrubbing
  only NBL_MAX_PF (8) FUNCTION_MSIX_MAP entries by saying the table "is…
- [Low] Two comments state as a safety invariant that nbl_intr_mgt_stop()
  is the only place a coherent MSI-X map table is freed.
- [Low] The public entry points load res_mgt->intr_mgt with a plain load
  and no lock, then call mutex_lock() on it.

--

net/nebula-matrix: add intr resource implementation

This adds an nbl_interrupt module that manages the chip-internal MSI-X
vector index space. For the control PF it programs the FUNCTION_MSIX_MAP,
PADPT_HOST_MSIX_INFO and HOST_MSIX_FID_TABLE registers. It also scrubs
stale FUNCTION_MSIX_MAP entries at init, moves pci_set_master() after
nbl_core_init(), and moves pci_clear_master() before nbl_core_remove().

> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> index fa5b88e8c70fc..f7cdb0fecf442 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c

[ ... ]

> @@ -136,6 +150,148 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
>  	*eth_map = FIELD_GET(NBL_FW_BOARD_DW6_ETH_BITMAP_MASK, data);
>  }
>  
> +/*
> + * nbl_hw_set_mailbox_irq - read-modify-write NBL_MAILBOX_QINFO_MAP_REG_ARR
> + *
> + * The full RMW sequence is wrapped by reg_lock, so concurrent register
> + * access from different CPUs is already serialized safely.
> + * nbl_hw_cfg_mailbox_qinfo() programs the BDF fields during control-PF
> + * init and clears MSIX_IDX/MSIX_IDX_VALID at the same time (they survive
> + * kexec/forced unload without FLR), so mailbox MSIX routing for a PF
> + * starts disarmed at init and is armed only by an explicit en_msix=true
> + * call here.
> + */

[Severity: Low]
Is this comment accurate at this commit? As far as I can tell,
nbl_hw_cfg_mailbox_qinfo() has no caller yet. So nothing clears
MSIX_IDX/MSIX_IDX_VALID during control-PF init, and the only scrub this
patch adds, in nbl_intr_setup_mgt(), covers FUNCTION_MSIX_MAP and nothing
else.

Later patches in the series fix this. "net/nebula-matrix: add common/ctrl
dev init/remove operation" makes nbl_dev_init() call
nbl_dev_setup_chan_qinfo() -> cfg_chan_qinfo_map_table() ->
nbl_hw_cfg_mailbox_qinfo() for every active PF. "net/nebula-matrix: add
chip-wide hardware init/deinit implementation" adds
nbl_hw_clear_stale_status() for the kexec case.

Could the comment be worded so it is true at this point in the series, or
say that the caller comes in a later patch?

[ ... ]

> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
> new file mode 100644
> index 0000000000000..9e5376d21d0f8
> --- /dev/null
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c

[ ... ]

> + * Those are bus-master reads tagged with the control PF's BDF, so
> + * pci_clear_master() is the only other lever.  The only place a table is
> + * freed is nbl_intr_mgt_stop(), which nbl_remove() reaches through
> + * nbl_core_remove(), after it has cleared bus mastering.  That is what
> + * makes the final free safe: the device cannot start a new fetch, and
> + * this window covers the ones already in flight.
> + */
> +static void nbl_intr_quiesce_wait(void)
> +{
> +	usleep_range(NBL_MSIX_DMA_SYNC_MIN_US, NBL_MSIX_DMA_SYNC_MAX_US);
> +}

[Severity: Low]
This isn't a bug, but is "The only place a table is freed is
nbl_intr_mgt_stop()" accurate? The release_vecs_unlock error path in
nbl_res_intr_cfg_msix_map() frees the table too:

	if (tbl_alloc) {
		dma_free_coherent(dev, official_tbl->size,
				  official_tbl->base_addr,
				  official_tbl->dma);

That free is safe today. tbl_alloc is only set on a first configuration,
and every goto release_vecs_unlock comes before cfg_msix_map(valid=true)
is called. The free loop in nbl_intr_mgt_stop() makes the same claim
("so this is the only place they are released").

Could both comments mention the error-path free of a table that was never
armed? Neither comment changes by the end of the series.

[ ... ]

> +/**
> + * nbl_res_intr_cfg_msix_map - allocate & program MSI-X mapping table

[ ... ]

> + * not maximum, concurrent use: a reconfigure of the same or a smaller
> + * size still fails with -EAGAIN when the pool is nearly exhausted.  The
> + * in-tree caller asks for one non-net vector per PF, far below
> + * NBL_MAX_OTHER_INTERRUPT.

[Severity: Low]
Which in-tree caller does this mean? At this commit,
nbl_res_intr_cfg_msix_map(), nbl_res_intr_destroy_msix_map() and
nbl_res_intr_set_mailbox_irq() have no callers. That means the
reconfiguration and teardown paths cannot be reached yet.

The new comment in nbl_res_remove_leonis() has the same problem:

	 * does not mean their entries are gone: a destroy_msix_map RPC
	 * that timed out leaves the control PF owning that function's map

That RPC is only added later.

Later patches add the callers: "net/nebula-matrix: dispatch: add mailbox
RPCs for msix map, mailbox irq and vsi/eth id" and "net/nebula-matrix:
add common dev start/stop operation". The kernel-doc is then updated to
name nbl_dev_cfg_msix_map().

Could these comments avoid describing callers that do not exist yet at
this point in the series?

[ ... ]

> +/*
> + * Reset the software state and invalidate every function's hardware MSI-X
> + * map entry once.  The chip-internal tables (FUNCTION_MSIX_MAP,
> + * PADPT_HOST_MSIX_INFO, HOST_MSIX_FID_TABLE) can survive a kexec or a
> + * forced unload without FLR and there is no .shutdown callback to scrub
> + * them.  Only FUNCTION_MSIX_MAP is scrubbed here: it is indexed by the
> + * 3-bit PCI function number (NBL_FUNCTION_MSIX_MAP_FUNCTION_MASK), so the
> + * NBL_MAX_PF (8) entries are every entry the pcompleter can select - the
> + * 10-bit FID mask belongs to HOST_MSIX_FID_TABLE, a separate table
> + * indexed by FID.  One register write each, after which the pcompleter
> + * can no longer fetch a stale table that points into memory this kernel
> + * may have reallocated.  The INFO/FID tables are indexed by global vector
> + * id and are not cleared; instead a map entry is always invalidated by
> + * nbl_res_intr_cfg_msix_map() and by the teardown paths before it is
> + * armed for a new configuration.

[Severity: Low]
Does the register layout support this reason for scrubbing only
NBL_MAX_PF entries?

NBL_FUNCTION_MSIX_MAP_FUNCTION_MASK is a field in data[2] of an entry.
nbl_res_intr_cfg_msix_map() writes the control PF's own common->function
into it for every func_id. The table index is func_id, through
NBL_PCOMPLETER_FUNCTION_MSIX_MAP(i).

nbl_hw_cfg_msix_info() indexes HOST_MSIX_FID_TABLE by global vector id:

	nbl_hw_wr_regs(hw_mgt,
		       NBL_PCOMPLETER_HOST_MSIX_FID_TABLE(interrupt_id),
		       &host_msix_fid, sizeof(host_msix_fid));

This comment says the same a few lines further down ("The INFO/FID tables
are indexed by global vector id"). The 10-bit FID field of that table
holds func_id. struct nbl_interrupt_mgt describes func_intr_res[] as
indexed by the "raw hardware function id", and that range includes VFs.

How many entries does FUNCTION_MSIX_MAP actually have? If it has more
than 8, can stale VALID entries for func_id >= 8 survive this scrub?
Either way, could the comment be corrected? It is still the same at the
end of the series.

[ ... ]

> +	/*
> +	 * Unpublish last.  Readers do not synchronize on intr_mgt->lock,
> +	 * so this only has to happen after every hardware access and
> +	 * every free above; a caller that latched the pointer earlier is
> +	 * rejected by the stopping latch.
> +	 */
> +	res_mgt->intr_mgt = NULL;
> +	mutex_unlock(&intr_mgt->lock);
> +}

[Severity: Low]
The public entry points read this pointer with a plain load and without
the lock:

	struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt;

It is cleared here with a plain store, and devres frees the object after
remove(). Could an in-flight caller reload a NULL pointer, or use
intr_mgt after devres has freed it?

Looking at the rest of the series, there is no concurrent reader. The
only asynchronous callers are the RPC responders, which run from
clean_mbx_task. nbl_remove() -> nbl_core_stop() cancels that work. Then
nbl_core_remove() -> nbl_dev_remove() -> nbl_dev_remove_common_dev() ->
nbl_chan_teardown_queue() joins it with cancel_work_sync(). Only after
that does nbl_res_remove_leonis() -> nbl_intr_mgt_stop() run. The local
callers run on the probe/remove thread, and the device links unbind the
sibling PFs first.

If that ordering is the real guarantee, would it be clearer to state in
the struct nbl_resource_mgt comment that there are no concurrent readers,
or to use READ_ONCE()/WRITE_ONCE()?

> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
> index 8f7a07242d412..f50ace6ccb5c9 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
> @@ -261,20 +261,32 @@ static int nbl_probe(struct pci_dev *pdev,
>  	/* never return fail when DMA_BIT_MASK(64) */
>  	dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
>  
> -	pci_set_master(pdev);
> -
> +	/*
> +	 * Bus mastering is enabled only after nbl_core_init() returns.
> +	 *
> +	 * FUNCTION_MSIX_MAP survives a kexec or a forced unload without
> +	 * FLR and there is no .shutdown callback to scrub it, so at this
> +	 * point every map entry left VALID by a previous kernel still
> +	 * holds a DMA address that this kernel has already reallocated.
> +	 * Those entries tag their table fetches as bus-master reads, and
> +	 * the only thing standing between such a fetch and a read of
> +	 * reused memory is Bus Master Enable, which the PCI core cleared
> +	 * on the way into this kernel.  nbl_intr_setup_mgt() invalidates

[Severity: Low]
Does the PCI core always clear Bus Master Enable before the new kernel
runs? pci_device_shutdown() calls pci_clear_master() only when
kexec_in_progress is set. A crash kexec (kdump) does not run
device_shutdown() at all. In that case the device enters the dump kernel
with bus mastering still on, and it can fetch the stale FUNCTION_MSIX_MAP
tables before nbl_probe() runs the scrub.

The comment in nbl_intr_setup_mgt() makes the same claim:

	 * This is the scrub that makes it safe to enable bus mastering:
	 * nbl_probe() calls it with bus mastering still disabled, so no
	 * new fetch can start while these entries are still VALID.

So does the commit message:

  "nbl_probe() now leaves bus mastering disabled until nbl_core_init()
  has returned, so this scrub runs before the device can issue a single
  fetch against a stale VALID entry"

The practical impact looks small. The dump kernel runs inside the
crashkernel reservation, so it will not have reused the first kernel's
coherent tables.

Could the comments and the commit message be limited to the orderly kexec
case? The .shutdown callback that the comments say is missing would cover
kdump. The end of the series still has no .shutdown, and this comment is
unchanged.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com

  reply	other threads:[~2026-11-23 12:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 11:35 [PATCH v35 net-next 0/8] nbl driver for Nebulamatrix NICs illusion.wang
2026-11-19 11:35 ` [PATCH v35 net-next 1/8] net/nebula-matrix: add channel layer illusion.wang
2026-11-23 12:51   ` netdev-bot+sashiko
2026-11-19 11:35 ` [PATCH v35 net-next 2/8] net/nebula-matrix: add common resource implementation illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko
2026-11-19 11:35 ` [PATCH v35 net-next 3/8] net/nebula-matrix: add intr " illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko [this message]
2026-11-19 11:35 ` [PATCH v35 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko
2026-11-19 11:35 ` [PATCH v35 net-next 5/8] net/nebula-matrix: dispatch: add control-level routing core infrastructure illusion.wang
2026-11-19 11:35 ` [PATCH v35 net-next 6/8] net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko
2026-11-19 11:35 ` [PATCH v35 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove operation illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko
2026-11-19 11:35 ` [PATCH v35 net-next 8/8] net/nebula-matrix: add common dev start/stop operation illusion.wang
2026-11-23 12:52   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179543832271.3135.13613851022028576414@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alvin.wang@nebula-matrix.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=dimon.zhao@nebula-matrix.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=illusion.wang@nebula-matrix.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sam.chen@nebula-matrix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®