Skip to content

Commit 1ab7470

Browse files
committed
crypto: ccp - Add support for getting security attributes on some older systems
JIRA: https://issues.redhat.com/browse/RHEL-85131 Upstream Status: merged into the linux.git commit 82f9327 Author: Mario Limonciello <[email protected]> Date: Tue May 28 16:07:11 2024 -0500 crypto: ccp - Add support for getting security attributes on some older systems Older systems will not populate the security attributes in the capabilities register. The PSP on these systems, however, does have a command to get the security attributes. Use this command during ccp startup to populate the attributes if they're missing. Closes: fwupd/fwupd#5284 Closes: fwupd/fwupd#5675 Closes: fwupd/fwupd#6253 Closes: fwupd/fwupd#7280 Closes: fwupd/fwupd#6323 Closes: fwupd/fwupd#5433 Signed-off-by: Mario Limonciello <[email protected]> Acked-by: Tom Lendacky <[email protected]> Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: Vladis Dronov <[email protected]>
1 parent de27c7d commit 1ab7470

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

drivers/crypto/ccp/hsti.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#include "psp-dev.h"
1313
#include "hsti.h"
1414

15+
#define PSP_CAPABILITY_PSP_SECURITY_OFFSET 8
16+
17+
struct hsti_request {
18+
struct psp_req_buffer_hdr header;
19+
u32 hsti;
20+
} __packed;
21+
1522
#define security_attribute_show(name) \
1623
static ssize_t name##_show(struct device *d, struct device_attribute *attr, \
1724
char *buf) \
@@ -66,3 +73,51 @@ struct attribute_group psp_security_attr_group = {
6673
.attrs = psp_security_attrs,
6774
.is_visible = psp_security_is_visible,
6875
};
76+
77+
static int psp_poulate_hsti(struct psp_device *psp)
78+
{
79+
struct hsti_request *req;
80+
int ret;
81+
82+
/* Are the security attributes already reported? */
83+
if (psp->capability.security_reporting)
84+
return 0;
85+
86+
/* Allocate command-response buffer */
87+
req = kzalloc(sizeof(*req), GFP_KERNEL | __GFP_ZERO);
88+
if (!req)
89+
return -ENOMEM;
90+
91+
req->header.payload_size = sizeof(req);
92+
93+
ret = psp_send_platform_access_msg(PSP_CMD_HSTI_QUERY, (struct psp_request *)req);
94+
if (ret)
95+
goto out;
96+
97+
if (req->header.status != 0) {
98+
dev_dbg(psp->dev, "failed to populate HSTI state: %d\n", req->header.status);
99+
ret = -EINVAL;
100+
goto out;
101+
}
102+
103+
psp->capability.security_reporting = 1;
104+
psp->capability.raw |= req->hsti << PSP_CAPABILITY_PSP_SECURITY_OFFSET;
105+
106+
out:
107+
kfree(req);
108+
109+
return ret;
110+
}
111+
112+
int psp_init_hsti(struct psp_device *psp)
113+
{
114+
int ret;
115+
116+
if (PSP_FEATURE(psp, HSTI)) {
117+
ret = psp_poulate_hsti(psp);
118+
if (ret)
119+
return ret;
120+
}
121+
122+
return 0;
123+
}

drivers/crypto/ccp/hsti.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
extern struct attribute_group psp_security_attr_group;
1414

15+
int psp_init_hsti(struct psp_device *psp);
16+
1517
#endif /* __HSTI_H */

drivers/crypto/ccp/psp-dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ static int psp_init(struct psp_device *psp)
220220
return ret;
221221
}
222222

223+
/* HSTI uses platform access on some systems. */
224+
ret = psp_init_hsti(psp);
225+
if (ret)
226+
return ret;
227+
223228
return 0;
224229
}
225230

drivers/crypto/ccp/psp-dev.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ void psp_clear_sev_irq_handler(struct psp_device *psp);
7878

7979
struct psp_device *psp_get_master_device(void);
8080

81-
#define PSP_CAPABILITY_PSP_SECURITY_OFFSET 8
82-
8381
/**
8482
* enum psp_cmd - PSP mailbox commands
8583
* @PSP_CMD_TEE_RING_INIT: Initialize TEE ring buffer

drivers/crypto/ccp/sp-dev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define CACHE_WB_NO_ALLOC 0xb7
3030

3131
#define PLATFORM_FEATURE_DBC 0x1
32+
#define PLATFORM_FEATURE_HSTI 0x2
3233

3334
#define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat)
3435

drivers/crypto/ccp/sp-pci.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,12 @@ static const struct psp_vdata pspv1 = {
397397

398398
static const struct psp_vdata pspv2 = {
399399
.sev = &sevv2,
400+
.platform_access = &pa_v1,
400401
.bootloader_info_reg = 0x109ec, /* C2PMSG_59 */
401402
.feature_reg = 0x109fc, /* C2PMSG_63 */
402403
.inten_reg = 0x10690, /* P2CMSG_INTEN */
403404
.intsts_reg = 0x10694, /* P2CMSG_INTSTS */
405+
.platform_features = PLATFORM_FEATURE_HSTI,
404406
};
405407

406408
static const struct psp_vdata pspv3 = {
@@ -413,7 +415,8 @@ static const struct psp_vdata pspv3 = {
413415
.feature_reg = 0x109fc, /* C2PMSG_63 */
414416
.inten_reg = 0x10690, /* P2CMSG_INTEN */
415417
.intsts_reg = 0x10694, /* P2CMSG_INTSTS */
416-
.platform_features = PLATFORM_FEATURE_DBC,
418+
.platform_features = PLATFORM_FEATURE_DBC |
419+
PLATFORM_FEATURE_HSTI,
417420
};
418421

419422
static const struct psp_vdata pspv4 = {

include/linux/psp-platform-access.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
enum psp_platform_access_msg {
99
PSP_CMD_NONE = 0x0,
10+
PSP_CMD_HSTI_QUERY = 0x14,
1011
PSP_I2C_REQ_BUS_CMD = 0x64,
1112
PSP_DYNAMIC_BOOST_GET_NONCE,
1213
PSP_DYNAMIC_BOOST_SET_UID,

0 commit comments

Comments
 (0)