From: Ratheesh Kannoth <rkannoth@marvell.com>
To: <linux-kernel@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
<netdev@vger.kernel.org>, <oss-drivers@corigine.com>
Cc: <akiyano@amazon.com>, <andrew+netdev@lunn.ch>,
<anthony.l.nguyen@intel.com>, <arkadiusz.kubalewski@intel.com>,
<brett.creeley@amd.com>, <darinzon@amazon.com>,
<davem@davemloft.net>, <donald.hunter@gmail.com>,
<edumazet@google.com>, <horms@kernel.org>, <idosch@nvidia.com>,
<ivecera@redhat.com>, <jiri@resnulli.us>, <kuba@kernel.org>,
<leon@kernel.org>, <mbloch@nvidia.com>,
<michael.chan@broadcom.com>, <pabeni@redhat.com>,
<pavan.chebbi@broadcom.com>, <petrm@nvidia.com>,
<Prathosh.Satish@microchip.com>, <przemyslaw.kitszel@intel.com>,
<saeedm@nvidia.com>, <sgoutham@marvell.com>, <tariqt@nvidia.com>,
<vadim.fedorenko@linux.dev>
Subject: Re: [PATCH v15 net-next 7/9] octeontx2-af: npc: Support for custom KPU profile from filesystem
Date: Thu, 21 May 2026 09:04:51 +0530 [thread overview]
Message-ID: <ag59W0c15nolHV5A@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260520020939.1457231-8-rkannoth@marvell.com>
On 2026-05-20 at 07:39:37, Ratheesh Kannoth (rkannoth@marvell.com) wrote:
> Flashing updated firmware on deployed devices is cumbersome. Provide a
> mechanism to load a custom KPU (Key Parse Unit) profile directly from
> the filesystem at module load time.
>
>> -static int npc_apply_custom_kpu(struct rvu *rvu,
>> - struct npc_kpu_profile_adapter *profile)
>> +static int npc_alloc_kpu_cam2_n_action2(struct rvu *rvu, int kpu_num,
>> + int num_entries)
>> +{
>> + struct npc_kpu_profile_adapter *adapter = &rvu->kpu;
>> + struct npc_kpu_profile *kpu;
>> +
>> + kpu = &adapter->kpu[kpu_num];
>> +
>> + kpu->cam2 = devm_kcalloc(rvu->dev, num_entries,
>> + sizeof(*kpu->cam2), GFP_KERNEL);
>Since npc_prepare_default_kpu() sets adapter->kpu to point to the global
>static array npc_kpu_profiles, does this allocate device-managed memory
>and store it in a global structure?
>If a custom filesystem profile is loaded, devm_kcalloc() will associate the
>allocation with the current rvu->dev. When the device is unbound, the memory
>is freed but the global npc_kpu_profiles array retains dangling pointers.
>Could this lead to a use-after-free or cross-device corruption if multiple
>RVU devices are probed?
The RVU Admin Function (AF) is a singleton
hardware block within the SoC architecture. There is structurally only a
single instance of this device probed per system, precluding any risk of cross-
device pointer corruption or multi-instance allocation conflicts.
Since there is a 1:1 mapping between the rvu->dev instance
and the global hardware profile structures, the lifespan of the devm-allocated
memory is structurally bound to the lifespan of the entire driver module. The
pointers inside the global array are only populated upon a successful probe
of this unique instance and are discarded if the block is unbound, preventing
nominal use-after-free conditions.
>This is a pre-existing issue, but modifying kpu->cam2 and kpu->action2, or
>copying custom entries directly into kpu->cam and kpu->action, mutates the
>default global npc_kpu_profiles array in-place. Does this inadvertently
>affect other RVU devices that might be relying on the default profile?
The driver operates under distinct state
machines for profile initialization. If a custom profile is successfully
loaded from filesystem, the driver diverts from and entirely
bypasses the default global 'npc_kpu_profiles' array path.
n-place mutations to 'kpu->cam2' and
'kpu->action2' occur strictly within the context of a dynamically allocated
custom adapter profile. Because custom profiles instantiate independent memory
buffers.
> +static int npc_apply_custom_kpu_from_fw(struct rvu *rvu,
>> + struct npc_kpu_profile_adapter *profile)
>> {
>> size_t hdr_sz = sizeof(struct npc_kpu_profile_fwdata), offset = 0;
>> + const struct npc_kpu_profile_fwdata *fw;
>> struct npc_kpu_profile_action *action;
>> - struct npc_kpu_profile_fwdata *fw;
>> struct npc_kpu_profile_cam *cam;
>> struct npc_kpu_fwdata *fw_kpu;
>> - int entries;
>> - u16 kpu, entry;
>> + int entries, entry, kpu;
>>
>> - if (is_cn20k(rvu->pdev))
>> - return npc_cn20k_apply_custom_kpu(rvu, profile);
>> + fw = rvu->kpu_fwdata;
>> +
>> + for (kpu = 0; kpu < fw->kpus; kpu++) {
>> + if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
>> + dev_warn(rvu->dev,
>> + "Profile size mismatch on KPU%i parsing\n",
>> + kpu + 1);
>> + return -EINVAL;
>> + }
>> +
>> + fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset);
>> + if (fw_kpu->entries < 0) {
>This is a pre-existing issue, but is the bounds check here sufficient to
>prevent out-of-bounds memory accesses?
>The check validates that hdr_sz + offset fits within rvu->kpu_fwdata_sz,
>but it doesn't include the size of the fw_kpu structure itself.
>If the remaining firmware buffer exactly equals offset, wouldn't reading
>fw_kpu->entries access memory past the end of the firmware buffer?
This is a legacy code issue and will fix as part of a follow up patch to net tree.
>> + struct npc_kpu_profile_adapter *profile,
>> + bool from_fs, int *fw_kpus)
>> +{
>> + size_t hdr_sz = sizeof(struct npc_kpu_profile_fwdata);
>> + const struct npc_kpu_profile_fwdata *fw;
>> + struct npc_kpu_profile_fwdata *sfw;
>[ ... ]
>> + *fw_kpus = fw->kpus;
>> +
>> + sfw = devm_kcalloc(rvu->dev, 1, sizeof(*sfw), GFP_KERNEL);
>> + if (!sfw)
>> + return -ENOMEM;
>> +
>> + memcpy(sfw, fw, sizeof(*sfw));
>Is it safe to use standard memcpy() here when fw could be an I/O memory
>pointer?
>When the KPU profile is loaded from the firmware database, fw points
>directly to an __iomem mapping via ioremap_wc(). On ARM64 architectures,
>using standard memcpy() on device memory can cause unaligned or wide
>SIMD/NEON load instructions, resulting in a Synchronous Abort and kernel
>panic.
>Should this code use memcpy_fromio() instead to handle the device memory
>safely?
>> +
>> profile->custom = 1;
>> - profile->name = fw->name;
>> + profile->name = sfw->name;
>> profile->version = le64_to_cpu(fw->version);
>> - profile->mcam_kex_prfl.mkex = &fw->mkex;
>> - profile->lt_def = &fw->lt_def;
>[ ... ]
The 'fw' pointer references a standard
system memory shadow buffer allocated via the firmware subsystem interface
(e.g., request_firmware), not a direct MMIO or __iomem mapped peripheral
region.
next prev parent reply other threads:[~2026-05-21 3:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 2:09 [PATCH v15 net-next 0/9] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 1/9] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 2/9] net/mlx5e: Reduce stack use reading PCIe congestion thresholds Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 3/9] devlink: pass param values by pointer Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 4/9] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 5/9] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-05-21 3:31 ` Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 6/9] octeontx2: cn20k: Coordinate default rules with NIX LF lifecycle Ratheesh Kannoth
2026-05-21 3:33 ` Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 7/9] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-05-21 3:34 ` Ratheesh Kannoth [this message]
2026-05-20 2:09 ` [PATCH v15 net-next 8/9] octeontx2: cn20k: Respect NPC MCAM X2/X4 profile in flows and DFT alloc Ratheesh Kannoth
2026-05-21 3:37 ` Ratheesh Kannoth
2026-05-20 2:09 ` [PATCH v15 net-next 9/9] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically Ratheesh Kannoth
2026-05-21 3:38 ` Ratheesh Kannoth
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=ag59W0c15nolHV5A@rkannoth-OptiPlex-7090 \
--to=rkannoth@marvell.com \
--cc=Prathosh.Satish@microchip.com \
--cc=akiyano@amazon.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=arkadiusz.kubalewski@intel.com \
--cc=brett.creeley@amd.com \
--cc=darinzon@amazon.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ivecera@redhat.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@corigine.com \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=petrm@nvidia.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=saeedm@nvidia.com \
--cc=sgoutham@marvell.com \
--cc=tariqt@nvidia.com \
--cc=vadim.fedorenko@linux.dev \
/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