From: "Rao, Nikhil" <nikhirao@amd.com>
To: Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, brett.creeley@amd.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, eric.joyner@amd.com,
nikhil.rao@amd.com
Subject: Re: [PATCH v4 5/6] pds_core: add host backed memory support for firmware
Date: Mon, 15 Jun 2026 13:07:40 -0700 [thread overview]
Message-ID: <e5c3a2f0-4104-4e3b-a85e-a6899f662169@amd.com> (raw)
In-Reply-To: <20260615161929.780699-2-horms@kernel.org>
On 6/15/2026 9:19 AM, Simon Horman wrote:
> This is an AI-generated review of your patch. The human sending this
> email has considered the AI review valid, or at least plausible.
> Full review at:https://sashiko.dev
> ---
> pds_core: add host backed memory support for firmware
>
> This commit adds support for host-backed DMA memory to provide additional
> memory for firmware control plane components on newer AMD/Pensando cards.
>
>> diff --git a/drivers/net/ethernet/amd/pds_core/core.c b/drivers/net/ethernet/amd/pds_core/core.c
>> index 705cab7b07273..d1695ca95440c 100644
>> --- a/drivers/net/ethernet/amd/pds_core/core.c
>> +++ b/drivers/net/ethernet/amd/pds_core/core.c
> [ ... ]
>
>> @@ -658,3 +660,161 @@ void pdsc_health_thread(struct work_struct *work)
>> out_unlock:
>> mutex_unlock(&pdsc->config_lock);
>> }
>> +
>> +static void pdsc_host_mem_del_one(struct pdsc *pdsc, u16 tag, u8 reason)
>> +{
>> + union pds_core_dev_comp comp = {};
>> + union pds_core_dev_cmd cmd = {
>> + .host_mem.opcode = PDS_CORE_CMD_HOST_MEM,
>> + .host_mem.oper = PDS_CORE_HOST_MEM_DEL,
>> + .host_mem.tag = cpu_to_le16(tag),
>> + .host_mem.reason = reason,
>> + };
> [ ... ]
>
>> + hm->pa = dma_map_page(pdsc->dev, hm->pg, 0, hm->size,
>> + DMA_BIDIRECTIONAL);
>> + if (dma_mapping_error(pdsc->dev, hm->pa)) {
>> + dev_err(pdsc->dev, "dma map failed for tag %d size %d\n",
>> + hm->tag, hm->size);
>> + __free_pages(hm->pg, hm->order);
>> + hm->pg = NULL;
>> + err = -EIO;
>> + goto err_del;
>> + }
>> +
>> + /* Track this allocation so pdsc_host_mem_free() can clean it up */
>> + pdsc->num_host_mem_reqs++;
>> +
>> + memset(&cmd, 0, sizeof(cmd));
>> + memset(&comp, 0, sizeof(comp));
>> + cmd.host_mem.opcode = PDS_CORE_CMD_HOST_MEM;
>> + cmd.host_mem.oper = PDS_CORE_HOST_MEM_ADD;
>> + cmd.host_mem.tag = cpu_to_le16(hm->tag);
>> + cmd.host_mem.size = cpu_to_le32(hm->size);
>> + cmd.host_mem.buf_pa = cpu_to_le64(hm->pa);
>> +
>> + dev_dbg(pdsc->dev, "Sending devcmd for mem add tag %d size %d pa %pad\n",
>> + hm->tag, hm->size, &hm->pa);
>> + err = pdsc_devcmd(pdsc, &cmd, &comp, pdsc->devcmd_timeout);
>> + if (err || comp.status != PDS_RC_SUCCESS) {
>> + dev_err(pdsc->dev, "mem add failed err %d status %d for tag %d\n",
>> + err, comp.status, hm->tag);
>> + err = err ? err : -EIO;
>> + goto err_del;
>> + }
>> + dev_dbg(pdsc->dev, "mem add completed for tag %d\n", hm->tag);
>> +
>> + return 0;
>> +
>> +err_del:
>> + /* After MEM_QUERY succeeds, firmware expects MEM_ADD or MEM_DEL */
>> + pdsc_host_mem_del_one(pdsc, hm->tag, PDS_RC_ENOMEM);
>> + return err;
> [Severity: Medium]
> Does this leave the failed memory allocation mapped and wasted for the
> lifetime of the driver?
>
> Because pdsc->num_host_mem_reqs is incremented before sending the MEM_ADD
> command, jumping to the err_del label here skips the DMA unmap and page free
> steps. The failed request is tracked and will eventually be cleaned up by
> pdsc_host_mem_free() during device teardown.
>
> However, the caller pdsc_start() ignores the failure, so the driver operates
> normally while potentially tying up to 4MB of DMA-mapped memory until unload
> or reset.
This is intentional. In the timeout case, firmware could still be
accessing the memory (slow response, not actual failure). Freeing
immediately could cause firmware to DMA into freed memory. The memory
is freed at teardown regardless of MEM_ADD result.
>
>> +}
> [ ... ]
>
>> +void pdsc_host_mem_free(struct pdsc *pdsc)
>> +{
>> + int i;
>> +
>> + if (!pdsc->host_mem_reqs)
>> + return;
>> +
>> + for (i = 0; i < pdsc->num_host_mem_reqs; i++) {
>> + dma_unmap_page(pdsc->dev, pdsc->host_mem_reqs[i].pa,
>> + pdsc->host_mem_reqs[i].size,
>> + DMA_BIDIRECTIONAL);
>> + __free_pages(pdsc->host_mem_reqs[i].pg,
>> + pdsc->host_mem_reqs[i].order);
>> + }
> [Severity: Critical]
> Is there a missing notification to the firmware that this memory is being
> unmapped?
>
> This loop unmaps the DMA regions and frees the pages, but it doesn't send a
> PDS_CORE_HOST_MEM_DEL command. >
> For physical functions, pdsc_devcmd_reset() runs before this during
> teardown, which might clear hardware state. However, virtual functions
> explicitly bypass the reset in pdsc_teardown():
>
> pdsc_teardown() {
> if (!pdsc->pdev->is_virtfn)
> pdsc_devcmd_reset(pdsc);
> ...
>
> If a virtual function uses host memory, skipping the MEM_DEL command means
> the firmware could be completely unaware the buffers were returned to the
> OS. Could this lead to the device performing DMA into freed memory and
> causing memory corruption or IOMMU faults?
>
>> +
>> + kfree(pdsc->host_mem_reqs);
>> + pdsc->host_mem_reqs = NULL;
>> + pdsc->num_host_mem_reqs = 0;
>> +}
For PFs: pdsc_devcmd_reset() runs before pdsc_host_mem_free() in
teardown. The reset clears all firmware state including host memory
state, so individual MEM_DEL commands are not needed.
For VFs: They never allocate host memory. VF init path (pdsc_init_vf())
doesn't call pdsc_setup() or pdsc_start(). pdsc_host_mem_add() is only
called from pdsc_start() in pdsc_init_pf().
Thanks,
Nikhil
next prev parent reply other threads:[~2026-06-15 20:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-14 5:00 [PATCH net-next v4 0/6] pds_core: Add PLDM firmware update and host backed memory support Nikhil P. Rao
2026-06-14 5:00 ` [PATCH v4 1/6] pds_core: add support for quiet devcmd failures Nikhil P. Rao
2026-06-15 15:34 ` Simon Horman
2026-06-15 15:37 ` Simon Horman
2026-06-15 18:53 ` Rao, Nikhil
2026-06-14 5:00 ` [PATCH v4 2/6] pds_core: add support for identity version 2 Nikhil P. Rao
2026-06-14 5:00 ` [PATCH v4 3/6] pds_core: add PLDM firmware update support via devlink flash Nikhil P. Rao
2026-06-15 15:36 ` Simon Horman
2026-06-15 19:04 ` Rao, Nikhil
2026-06-14 5:00 ` [PATCH v4 4/6] pds_core: add PLDM component info display Nikhil P. Rao
2026-06-15 16:08 ` Simon Horman
2026-06-15 19:58 ` Rao, Nikhil
2026-06-14 5:00 ` [PATCH v4 5/6] pds_core: add host backed memory support for firmware Nikhil P. Rao
2026-06-15 16:19 ` Simon Horman
2026-06-15 20:07 ` Rao, Nikhil [this message]
2026-06-14 5:00 ` [PATCH v4 6/6] pds_core: add debugfs support for host backed memory Nikhil P. Rao
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=e5c3a2f0-4104-4e3b-a85e-a6899f662169@amd.com \
--to=nikhirao@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.joyner@amd.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nikhil.rao@amd.com \
--cc=pabeni@redhat.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