Skip to content

Commit 7f0c667

Browse files
PrachotanReddyjarkkojs
authored andcommitted
tpm_crb_ffa: handle tpm busy return code
Platforms supporting direct message request v2 [1] can support secure partitions that support multiple services. For CRB over FF-A interface, if the firmware TPM or TPM service [1] shares its Secure Partition (SP) with another service, message requests may fail with a -EBUSY error. To handle this, replace the single check and call with a retry loop that attempts the TPM message send operation until it succeeds or a configurable timeout is reached. Implement a _try_send_receive function to do a single send/receive and modify the existing send_receive to add this retry loop. The retry mechanism introduces a module parameter (`busy_timeout_ms`, default: 2000ms) to control how long to keep retrying on -EBUSY responses. Between retries, the code waits briefly (50-100 microseconds) to avoid busy-waiting and handling TPM BUSY conditions more gracefully. The parameter can be modified at run-time as such: echo 3000 | tee /sys/module/tpm_crb_ffa/parameters/busy_timeout_ms This changes the timeout from the default 2000ms to 3000ms. [1] TPM Service Command Response Buffer Interface Over FF-A https://developer.arm.com/documentation/den0138/latest/ Signed-off-by: Prachotan Bathi <prachotan.bathi@arm.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 586dafc commit 7f0c667

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,6 +7214,14 @@
72147214
causing a major performance hit, and the space where
72157215
machines are deployed is by other means guarded.
72167216

7217+
tpm_crb_ffa.busy_timeout_ms= [ARM64,TPM]
7218+
Maximum time in milliseconds to retry sending a message
7219+
to the TPM service before giving up. This parameter controls
7220+
how long the system will continue retrying when the TPM
7221+
service is busy.
7222+
Format: <unsigned int>
7223+
Default: 2000 (2 seconds)
7224+
72177225
tpm_suspend_pcr=[HW,TPM]
72187226
Format: integer pcr id
72197227
Specify that at suspend time, the tpm driver

drivers/char/tpm/tpm_crb_ffa.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
#define pr_fmt(fmt) "CRB_FFA: " fmt
1111

1212
#include <linux/arm_ffa.h>
13+
#include <linux/delay.h>
14+
#include <linux/moduleparam.h>
1315
#include "tpm_crb_ffa.h"
1416

17+
static unsigned int busy_timeout_ms = 2000;
18+
19+
module_param(busy_timeout_ms, uint, 0644);
20+
MODULE_PARM_DESC(busy_timeout_ms,
21+
"Maximum time in ms to retry before giving up on busy");
22+
1523
/* TPM service function status codes */
1624
#define CRB_FFA_OK 0x05000001
1725
#define CRB_FFA_OK_RESULTS_RETURNED 0x05000002
@@ -189,17 +197,13 @@ int tpm_crb_ffa_init(void)
189197
}
190198
EXPORT_SYMBOL_GPL(tpm_crb_ffa_init);
191199

192-
static int __tpm_crb_ffa_send_receive(unsigned long func_id,
193-
unsigned long a0,
194-
unsigned long a1,
195-
unsigned long a2)
200+
static int __tpm_crb_ffa_try_send_receive(unsigned long func_id,
201+
unsigned long a0, unsigned long a1,
202+
unsigned long a2)
196203
{
197204
const struct ffa_msg_ops *msg_ops;
198205
int ret;
199206

200-
if (!tpm_crb_ffa)
201-
return -ENOENT;
202-
203207
msg_ops = tpm_crb_ffa->ffa_dev->ops->msg_ops;
204208

205209
if (ffa_partition_supports_direct_req2_recv(tpm_crb_ffa->ffa_dev)) {
@@ -225,6 +229,33 @@ static int __tpm_crb_ffa_send_receive(unsigned long func_id,
225229
ret = tpm_crb_ffa_to_linux_errno(tpm_crb_ffa->direct_msg_data.data1);
226230
}
227231

232+
return ret;
233+
}
234+
235+
static int __tpm_crb_ffa_send_receive(unsigned long func_id, unsigned long a0,
236+
unsigned long a1, unsigned long a2)
237+
{
238+
ktime_t start, stop;
239+
int ret;
240+
241+
if (!tpm_crb_ffa)
242+
return -ENOENT;
243+
244+
start = ktime_get();
245+
stop = ktime_add(start, ms_to_ktime(busy_timeout_ms));
246+
247+
for (;;) {
248+
ret = __tpm_crb_ffa_try_send_receive(func_id, a0, a1, a2);
249+
if (ret != -EBUSY)
250+
break;
251+
252+
usleep_range(50, 100);
253+
if (ktime_after(ktime_get(), stop)) {
254+
dev_warn(&tpm_crb_ffa->ffa_dev->dev,
255+
"Busy retry timed out\n");
256+
break;
257+
}
258+
}
228259

229260
return ret;
230261
}

0 commit comments

Comments
 (0)