From: Ratheesh Kannoth <rkannoth@marvell.com>
To: Simon Horman <horms@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<sgoutham@marvell.com>, <davem@davemloft.net>,
<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
<donald.hunter@gmail.com>, <jiri@resnulli.us>,
<chuck.lever@oracle.com>, <matttbe@kernel.org>,
<cjubran@nvidia.com>, <shshitrit@nvidia.com>,
<dtatulea@nvidia.com>, <tariqt@nvidia.com>
Subject: Re: [PATCH v7 net-next 5/5] octeontx2-af: npc: Support for custom KPU profile from filesystem
Date: Wed, 25 Mar 2026 08:44:30 +0530 [thread overview]
Message-ID: <acNTFn5pjllT6C2G@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260324163621.GC111839@horms.kernel.org>
On 2026-03-24 at 22:06:21, Simon Horman (horms@kernel.org) wrote:
> >
> > for (kpu = 0; kpu < fw->kpus; kpu++) {
> > fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset);
> > - if (fw_kpu->entries > KPU_MAX_CST_ENT)
> > - dev_warn(rvu->dev,
> > - "Too many custom entries on KPU%d: %d > %d\n",
> > - kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
> > - entries = min(fw_kpu->entries, KPU_MAX_CST_ENT);
> > - cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
> > - offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
> > + if (!from_fs) {
> > + if (fw_kpu->entries > KPU_MAX_CST_ENT)
> > + dev_warn(rvu->dev,
> > + "Too many custom entries on KPU%d: %d > %d\n",
> > + kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
> > + entries = min(fw_kpu->entries, KPU_MAX_CST_ENT);
> > + cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
> > + offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
> > + action = (struct npc_kpu_profile_action *)(fw->data + offset);
> > + offset += fw_kpu->entries * sizeof(*action);
> > + if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
> > + dev_warn(rvu->dev,
> > + "Profile size mismatch on KPU%i parsing.\n",
> > + kpu + 1);
> > + return -EINVAL;
> > + }
> > + for (entry = 0; entry < entries; entry++) {
> > + profile->kpu[kpu].cam[entry] = cam[entry];
> > + profile->kpu[kpu].action[entry] = action[entry];
> > + }
> > + continue;
> > + }
>
> Effectively the code below is the else arm of the condition above.
> I would suggest that moving the contents of both arms into helpers
> would lead to a cleaner implementation.
>
> > +
> > + entries = min(fw_kpu->entries, rvu->hw->npc_kpu_entries);
> > + dev_info(rvu->dev,
> > + "Loading %u entries on KPU%d\n", entries, kpu);
> > +
> > + cam2 = (struct npc_kpu_profile_cam2 *)fw_kpu->data;
> > + offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam2);
> > action = (struct npc_kpu_profile_action *)(fw->data + offset);
> > offset += fw_kpu->entries * sizeof(*action);
> > if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
> > dev_warn(rvu->dev,
> > - "Profile size mismatch on KPU%i parsing.\n",
> > + "profile size mismatch on kpu%i parsing.\n",
> > kpu + 1);
> > return -EINVAL;
> > }
> > +
> > + profile->kpu[kpu].cam_entries2 = entries;
> > + profile->kpu[kpu].action_entries2 = entries;
> > + ret = npc_alloc_kpu_cam2_n_action2(rvu, kpu, entries);
> > + if (ret) {
> > + dev_warn(rvu->dev,
> > + "profile entry allocation failed for kpu=%d for %d entries\n",
> > + kpu, entries);
> > + return -EINVAL;
> > + }
> > +
> > for (entry = 0; entry < entries; entry++) {
> > - profile->kpu[kpu].cam[entry] = cam[entry];
> > - profile->kpu[kpu].action[entry] = action[entry];
> > + profile->kpu[kpu].cam2[entry] = cam2[entry];
> > + profile->kpu[kpu].action2[entry] = action[entry];
> > }
>
> Perhaps it applies to the existing code as well. But I think
> the new code to handle parsing images read from the file system
> could benefit from bounds checking. Basically passing in the length
> of the firmware image as an argument and ensuring that data beyond
> that length isn't accessed.
This is already done in both arms of the code.
if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
dev_warn(rvu->dev,
"Profile size mismatch on KPU%i parsing.\n",
"profile size mismatch on kpu%i parsing.\n",
kpu + 1);
return -EINVAL;
>
next prev parent reply other threads:[~2026-03-25 3:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 3:51 [PATCH v7 net-next 0/5] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-03-23 3:51 ` [PATCH v7 net-next 1/5] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-03-23 3:51 ` [PATCH v7 net-next 2/5] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-03-24 16:09 ` Simon Horman
2026-03-23 3:51 ` [PATCH v7 net-next 3/5] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-03-23 3:51 ` [PATCH v7 net-next 4/5] octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries Ratheesh Kannoth
2026-03-23 3:51 ` [PATCH v7 net-next 5/5] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-03-24 16:36 ` Simon Horman
2026-03-25 3:14 ` Ratheesh Kannoth [this message]
2026-03-25 16:42 ` Simon Horman
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=acNTFn5pjllT6C2G@rkannoth-OptiPlex-7090 \
--to=rkannoth@marvell.com \
--cc=chuck.lever@oracle.com \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matttbe@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgoutham@marvell.com \
--cc=shshitrit@nvidia.com \
--cc=tariqt@nvidia.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