Netdev List
 help / color / mirror / Atom feed
From: Ratheesh Kannoth <rkannoth@marvell.com>
To: <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<donald.hunter@gmail.com>, <edumazet@google.com>,
	<horms@kernel.org>, <jiri@resnulli.us>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <sgoutham@marvell.com>
Subject: Re: [PATCH v17 net-next 8/8] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically.
Date: Tue, 2 Jun 2026 09:50:35 +0530	[thread overview]
Message-ID: <ah5aE-oDgy7BzYEc@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260601025844.865865-9-rkannoth@marvell.com>

On 2026-06-01 at 08:28:43, Ratheesh Kannoth (rkannoth@marvell.com) wrote:
> Replace the file-scope static npc_priv with a kcalloc'd struct filled
> from hardware bank/subbank geometry at init (num_banks is no longer a
> const compile-time constant; drop init_done and use a non-NULL
> npc_priv pointer for liveness). Thread npc_priv_get() / pointer access
> through the CN20K NPC code paths, extend teardown to kfree the root
> struct on failure and in npc_cn20k_deinit, and adjust MCAM section
> setup to use the discovered subbank count.

>>  static int npc_mcam_dstats_show(struct seq_file *s, void *unused)
>>  {
>>  	struct npc_priv_t *npc_priv;
>>  	int blkaddr, pf, mcam_idx;
>[ ... ]
>>  	npc_priv = npc_priv_get();
>>  	rvu = s->private;
>>  	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
>>  	if (blkaddr < 0)
>>  		return 0;
>>
>>  	mutex_lock(&stats_lock);
>>  	seq_puts(s, "idx\tpfunc\tstats\n");
>> -	for (int bank = npc_priv.num_banks - 1; bank >= 0; bank--) {
>> -		for (int idx = npc_priv.bank_depth - 1; idx >= 0; idx--) {
>> +	for (int bank = npc_priv->num_banks - 1; bank >= 0; bank--) {
>> +		for (int idx = npc_priv->bank_depth - 1; idx >= 0; idx--) {
>Could this unconditionally dereference a NULL pointer if debugfs is read
>after initialization fails? Since npc_priv is no longer a static structure,
>reading from it without checking for NULL will cause a crash here.

if memory allocation fails, debugfs entry wont be created in npc_cn20k_debugfs_init()

>  int npc_cn20k_ref_idx_alloc(struct rvu *rvu, int pcifunc, int key_type,
>>  			    int prio, u16 *mcam_idx, int ref, int limit,
>>  			    bool contig, int count, bool virt)
>>  {
>>  	bool defrag_candidate = false;
>>  	int i, eidx, rc, bd;
>>  	bool ref_valid;
>>  	u16 vidx;
>>
>> -	bd = npc_priv.bank_depth;
>> +	bd = npc_priv->bank_depth;
>Does this function also need a NULL check for npc_priv before dereferencing
>it? If the NPC block fails to initialize, this will crash immediately upon
>entry.
No. if npc_priv allocation fails, probe() itself will fail.

>>  int rvu_mbox_handler_npc_get_pfl_info(struct rvu *rvu, struct msg_req *req,
>>  				      struct npc_get_pfl_info_rsp *rsp)
>>  {
>>  	if (!is_cn20k(rvu->pdev)) {
>>  		dev_err(rvu->dev, "Mbox support is only for cn20k\n");
>>  		return -EOPNOTSUPP;
>>  	}
>>
>> -	rsp->kw_type = npc_priv.kw;
>> -	rsp->x4_slots = npc_priv.bank_depth;
>> +	rsp->kw_type = npc_priv->kw;
>> +	rsp->x4_slots = npc_priv->bank_depth;
>>  	return 0;
>>  }
>If the NPC block is disabled or fails to initialize, npc_priv will remain
>NULL. Since this mailbox handler doesn't check for NULL before dereferencing,
>will this cause a kernel panic when triggered by a VF? Previously, reading
>from the static structure safely yielded zeroes.
>
If the NPC block is disabled or fails to initialize, rvu af probe() itself will fail.

>>  int rvu_mbox_handler_npc_get_pfl_info(struct rvu *rvu, struct msg_req *req,
>>  				      struct npc_get_pfl_info_rsp *rsp)
>>  {
>>  	if (!is_cn20k(rvu->pdev)) {
>>  		dev_err(rvu->dev, "Mbox support is only for cn20k\n");
>>  		return -EOPNOTSUPP;
>>  	}
>>
>> -	rsp->kw_type = npc_priv.kw;
>> -	rsp->x4_slots = npc_priv.bank_depth;
>> +	rsp->kw_type = npc_priv->kw;
>> +	rsp->x4_slots = npc_priv->bank_depth;
>>  	return 0;
>>  }
>If the NPC block is disabled or fails to initialize, npc_priv will remain
>NULL. Since this mailbox handler doesn't check for NULL before dereferencing,
>will this cause a kernel panic when triggered by a VF? Previously, reading
>from the static structure safely yielded zeroes.
There is only one AF device per system, so this case won't happen

      reply	other threads:[~2026-06-02  4:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01  2:58 [PATCH v17 net-next 0/8] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 1/8] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 2/8] devlink: heap-allocate param fill buffers in devlink_nl_param_fill Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 3/8] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-06-02  3:44   ` Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 4/8] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-06-02  4:06   ` Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 5/8] octeontx2: cn20k: Coordinate default rules with NIX LF lifecycle Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 6/8] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-06-02  4:13   ` Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 7/8] octeontx2: cn20k: Respect NPC MCAM X2/X4 profile in flows and DFT alloc Ratheesh Kannoth
2026-06-01  2:58 ` [PATCH v17 net-next 8/8] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically Ratheesh Kannoth
2026-06-02  4:20   ` Ratheesh Kannoth [this message]

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=ah5aE-oDgy7BzYEc@rkannoth-OptiPlex-7090 \
    --to=rkannoth@marvell.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgoutham@marvell.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