Skip to content

Commit 15cb9a2

Browse files
committed
Merge tag 'tpmdd-next-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen: "This contains a new driver: a TPM FF-A driver. FF comes from Firmware Framework, and A comes from Arm's A-profile. FF-A is essentially a standard mechanism to communicate with TrustZone apps such as TPM. Other than that, this includes a pile of fixes and small improvments" * tag 'tpmdd-next-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm: Make chip->{status,cancel,req_canceled} opt MAINTAINERS: TPM DEVICE DRIVER: add missing includes tpm: End any active auth session before shutdown Documentation: tpm: Add documentation for the CRB FF-A interface tpm_crb: Add support for the ARM FF-A start method ACPICA: Add start method for ARM FF-A tpm_crb: Clean-up and refactor check for idle support tpm_crb: ffa_tpm: Implement driver compliant to CRB over FF-A tpm/tpm_ftpm_tee: fix struct ftpm_tee_private documentation tpm, tpm_tis: Workaround failed command reception on Infineon devices tpm, tpm_tis: Fix timeout handling when waiting for TPM status tpm: Convert warn to dbg in tpm2_start_auth_session() tpm: Lazily flush auth session when getting random data tpm: ftpm_tee: remove incorrect of_match_ptr annotation tpm: do not start chip while suspended
2 parents f8a4eba + 980a573 commit 15cb9a2

File tree

18 files changed

+590
-58
lines changed

18 files changed

+590
-58
lines changed

Documentation/security/tpm/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Trusted Platform Module documentation
1010
tpm_vtpm_proxy
1111
xen-tpmfront
1212
tpm_ftpm_tee
13+
tpm_ffa_crb
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
========================
4+
TPM CRB over FF-A Driver
5+
========================
6+
7+
The TPM Command Response Buffer (CRB) interface is a standard TPM interface
8+
defined in the TCG PC Client Platform TPM Profile (PTP) Specification [1]_.
9+
The CRB provides a structured set of control registers a client uses when
10+
interacting with a TPM as well as a data buffer for storing TPM commands and
11+
responses. A CRB interface can be implemented in:
12+
13+
- hardware registers in a discrete TPM chip
14+
15+
- in memory for a TPM running in isolated environment where shared memory
16+
allows a client to interact with the TPM
17+
18+
The Firmware Framework for Arm A-profile (FF-A) [2]_ is a specification
19+
that defines interfaces and protocols for the following purposes:
20+
21+
- Compartmentalize firmware into software partitions that run in the Arm
22+
Secure world environment (also know as TrustZone)
23+
24+
- Provide a standard interface for software components in the Non-secure
25+
state, for example OS and Hypervisors, to communicate with this firmware.
26+
27+
A TPM can be implemented as an FF-A secure service. This could be a firmware
28+
TPM or could potentially be a TPM service that acts as a proxy to a discrete
29+
TPM chip. An FF-A based TPM abstracts hardware details (e.g. bus controller
30+
and chip selects) away from the OS and can protect locality 4 from access
31+
by an OS. The TCG-defined CRB interface is used by clients to interact
32+
with the TPM service.
33+
34+
The Arm TPM Service Command Response Buffer Interface Over FF-A [3]_
35+
specification defines FF-A messages that can be used by a client to signal
36+
when updates have been made to the CRB.
37+
38+
How the Linux CRB driver interacts with FF-A is summarized below:
39+
40+
- The tpm_crb_ffa driver registers with the FF-A subsystem in the kernel
41+
with an architected TPM service UUID defined in the CRB over FF-A spec.
42+
43+
- If a TPM service is discovered by FF-A, the probe() function in the
44+
tpm_crb_ffa driver runs, and the driver initializes.
45+
46+
- The probing and initialization of the Linux CRB driver is triggered
47+
by the discovery of a TPM advertised via ACPI. The CRB driver can
48+
detect the type of TPM through the ACPI 'start' method. The start
49+
method for Arm FF-A was defined in TCG ACPI v1.4 [4]_.
50+
51+
- When the CRB driver performs its normal functions such as signaling 'start'
52+
and locality request/relinquish it invokes the tpm_crb_ffa_start() funnction
53+
in the tpm_crb_ffa driver which handles the FF-A messaging to the TPM.
54+
55+
References
56+
==========
57+
58+
.. [1] **TCG PC Client Platform TPM Profile (PTP) Specification**
59+
https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profile-ptp-specification/
60+
.. [2] **Arm Firmware Framework for Arm A-profile (FF-A)**
61+
https://developer.arm.com/documentation/den0077/latest/
62+
.. [3] **Arm TPM Service Command Response Buffer Interface Over FF-A**
63+
https://developer.arm.com/documentation/den0138/latest/
64+
.. [4] **TCG ACPI Specification**
65+
https://trustedcomputinggroup.org/resource/tcg-acpi-specification/

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24187,6 +24187,8 @@ Q: https://patchwork.kernel.org/project/linux-integrity/list/
2418724187
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git
2418824188
F: Documentation/devicetree/bindings/tpm/
2418924189
F: drivers/char/tpm/
24190+
F: include/linux/tpm*.h
24191+
F: include/uapi/linux/vtpm_proxy.h
2419024192
F: tools/testing/selftests/tpm2/
2419124193

2419224194
TPS546D24 DRIVER

drivers/char/tpm/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ config TCG_CRB
210210
from within Linux. To compile this driver as a module, choose
211211
M here; the module will be called tpm_crb.
212212

213+
config TCG_ARM_CRB_FFA
214+
tristate "TPM CRB over Arm FF-A Transport"
215+
depends on ARM_FFA_TRANSPORT && TCG_CRB
216+
default TCG_CRB
217+
help
218+
If the Arm FF-A transport is used to access the TPM say Yes.
219+
To compile this driver as a module, choose M here; the module
220+
will be called tpm_crb_ffa.
221+
213222
config TCG_VTPM_PROXY
214223
tristate "VTPM Proxy Interface"
215224
depends on TCG_TPM

drivers/char/tpm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
4242
obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/
4343
obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
4444
obj-$(CONFIG_TCG_CRB) += tpm_crb.o
45+
obj-$(CONFIG_TCG_ARM_CRB_FFA) += tpm_crb_ffa.o
4546
obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
4647
obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o

drivers/char/tpm/tpm-chip.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ int tpm_try_get_ops(struct tpm_chip *chip)
168168
goto out_ops;
169169

170170
mutex_lock(&chip->tpm_mutex);
171+
172+
/* tmp_chip_start may issue IO that is denied while suspended */
173+
if (chip->flags & TPM_CHIP_FLAG_SUSPENDED)
174+
goto out_lock;
175+
171176
rc = tpm_chip_start(chip);
172177
if (rc)
173178
goto out_lock;
@@ -300,6 +305,7 @@ int tpm_class_shutdown(struct device *dev)
300305
down_write(&chip->ops_sem);
301306
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
302307
if (!tpm_chip_start(chip)) {
308+
tpm2_end_auth_session(chip);
303309
tpm2_shutdown(chip, TPM2_SU_CLEAR);
304310
tpm_chip_stop(chip);
305311
}

drivers/char/tpm/tpm-interface.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
5858
}
5959
EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
6060

61+
static void tpm_chip_cancel(struct tpm_chip *chip)
62+
{
63+
if (!chip->ops->cancel)
64+
return;
65+
66+
chip->ops->cancel(chip);
67+
}
68+
69+
static u8 tpm_chip_status(struct tpm_chip *chip)
70+
{
71+
if (!chip->ops->status)
72+
return 0;
73+
74+
return chip->ops->status(chip);
75+
}
76+
77+
static bool tpm_chip_req_canceled(struct tpm_chip *chip, u8 status)
78+
{
79+
if (!chip->ops->req_canceled)
80+
return false;
81+
82+
return chip->ops->req_canceled(chip, status);
83+
}
84+
6185
static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
6286
{
6387
struct tpm_header *header = buf;
@@ -104,12 +128,12 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
104128

105129
stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
106130
do {
107-
u8 status = chip->ops->status(chip);
131+
u8 status = tpm_chip_status(chip);
108132
if ((status & chip->ops->req_complete_mask) ==
109133
chip->ops->req_complete_val)
110134
goto out_recv;
111135

112-
if (chip->ops->req_canceled(chip, status)) {
136+
if (tpm_chip_req_canceled(chip, status)) {
113137
dev_err(&chip->dev, "Operation Canceled\n");
114138
return -ECANCELED;
115139
}
@@ -118,7 +142,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)
118142
rmb();
119143
} while (time_before(jiffies, stop));
120144

121-
chip->ops->cancel(chip);
145+
tpm_chip_cancel(chip);
122146
dev_err(&chip->dev, "Operation Timed out\n");
123147
return -ETIME;
124148

@@ -445,18 +469,11 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
445469
if (!chip)
446470
return -ENODEV;
447471

448-
/* Give back zero bytes, as TPM chip has not yet fully resumed: */
449-
if (chip->flags & TPM_CHIP_FLAG_SUSPENDED) {
450-
rc = 0;
451-
goto out;
452-
}
453-
454472
if (chip->flags & TPM_CHIP_FLAG_TPM2)
455473
rc = tpm2_get_random(chip, out, max);
456474
else
457475
rc = tpm1_get_random(chip, out, max);
458476

459-
out:
460477
tpm_put_ops(chip);
461478
return rc;
462479
}

drivers/char/tpm/tpm2-cmd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
359359
} while (retries-- && total < max);
360360

361361
tpm_buf_destroy(&buf);
362-
tpm2_end_auth_session(chip);
363362

364363
return total ? total : -EIO;
365364
out:

drivers/char/tpm/tpm2-sessions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
982982
int rc;
983983

984984
if (chip->auth) {
985-
dev_warn_once(&chip->dev, "auth session is active\n");
985+
dev_dbg_once(&chip->dev, "auth session is active\n");
986986
return 0;
987987
}
988988

0 commit comments

Comments
 (0)