Re: [PATCH v3] tpm: loongson: reject an undersized DMA window
From: Qunqin Zhao
Date: Fri Dec 04 2026 - 02:48:00 EST
在 2026/12/3 10:23, Fang Xieyan 写道:
> Hi Qunqin,
>
> The automated review raised a coupling concern: if TPM_BUFSIZE is ever
> raised above the hardware's per-engine window size (currently 4096 for
> dmam_size = 64 KiB / 16), the probe check would reject working hardware.
>
> Two possible directions:
>
> A) Keep the probe-time rejection as-is (v3). Simple, and correct as
> long as buffer_size >= TPM_BUFSIZE holds on all supported platforms.
As commit 1e41cfc5549c notes: TPM_BUFSIZE may need to be increased
again in the future, which may create compatibility issues with firmware.
Let's go with the approach below.
> B) Move the buffer_size bound to recv-time instead, so the driver
> adapts to whatever window the firmware provides without coupling
> to TPM_BUFSIZE:
>
> if (data_len > tpm_engine->buffer_size)
> return -EIO;
Furthermore, I propose passing `buffer_size` into the hardware to avoid
this situation and make returning `-EIO` justified. as follows:
@@ -12,7 +12,8 @@ struct tpm_loongson_cmd {
u32 cmd_id;
u32 data_off;
u32 data_len;
- u32 pad[5];
+ u32 buffer_size;
+ u32 pad[4];
};
static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
@@ -61,6 +62,7 @@ static int tpm_loongson_probe(struct platform_device *pdev)
cmd = tpm_engine->command;
cmd->cmd_id = SE_CMD_TPM;
cmd->data_off = tpm_engine->buffer_off;
+ cmd->buffer_size = tpm_engine->buffer_size;
chip = tpmm_chip_alloc(dev, &tpm_loongson_ops);
if (IS_ERR(chip))
Qunqin,
Thanks.
>
> Probe stays unconditional.
>
> Do you have a preference? Happy to send v4 either way.