Re: [PATCH v7 net-next 5/5] octeontx2-af: npc: Support for custom KPU profile from filesystem
From: Ratheesh Kannoth
Date: Tue Mar 24 2026 - 23:16:18 EST
On 2026-03-24 at 22:06:21, Simon Horman (horms@xxxxxxxxxx) 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;
>