Skip to content

Commit 7259eb7

Browse files
mhaimovskiogabbay
authored andcommitted
accel/habanalabs/gaudi2: add signed dev info uAPI
User will provide a nonce via the INFO ioctl, and will retrieve the signed device info generated using given nonce. Signed-off-by: Moti Haimovski <mhaimovski@habana.ai> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
1 parent 5bc155c commit 7259eb7

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

drivers/accel/habanalabs/common/firmware_if.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,14 @@ int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_in
32443244
HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC);
32453245
}
32463246

3247+
int hl_fw_get_dev_info_signed(struct hl_device *hdev,
3248+
struct cpucp_dev_info_signed *dev_info_signed, u32 nonce)
3249+
{
3250+
return hl_fw_get_sec_attest_data(hdev, CPUCP_PACKET_INFO_SIGNED_GET, dev_info_signed,
3251+
sizeof(struct cpucp_dev_info_signed), nonce,
3252+
HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC);
3253+
}
3254+
32473255
int hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,
32483256
dma_addr_t buff, u32 *size)
32493257
{

drivers/accel/habanalabs/common/habanalabs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,6 +3964,8 @@ long hl_fw_get_max_power(struct hl_device *hdev);
39643964
void hl_fw_set_max_power(struct hl_device *hdev);
39653965
int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,
39663966
u32 nonce);
3967+
int hl_fw_get_dev_info_signed(struct hl_device *hdev,
3968+
struct cpucp_dev_info_signed *dev_info_signed, u32 nonce);
39673969
int hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);
39683970
int hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);
39693971
int hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);

drivers/accel/habanalabs/common/habanalabs_ioctl.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include <asm/msr.h>
2121

22+
/* make sure there is space for all the signed info */
23+
static_assert(sizeof(struct cpucp_info) <= SEC_DEV_INFO_BUF_SZ);
24+
2225
static u32 hl_debug_struct_size[HL_DEBUG_OP_TIMESTAMP + 1] = {
2326
[HL_DEBUG_OP_ETR] = sizeof(struct hl_debug_params_etr),
2427
[HL_DEBUG_OP_ETF] = sizeof(struct hl_debug_params_etf),
@@ -719,6 +722,53 @@ static int sec_attest_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
719722
return rc;
720723
}
721724

725+
static int dev_info_signed(struct hl_fpriv *hpriv, struct hl_info_args *args)
726+
{
727+
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
728+
struct cpucp_dev_info_signed *dev_info_signed;
729+
struct hl_info_signed *info;
730+
u32 max_size = args->return_size;
731+
int rc;
732+
733+
if ((!max_size) || (!out))
734+
return -EINVAL;
735+
736+
dev_info_signed = kzalloc(sizeof(*dev_info_signed), GFP_KERNEL);
737+
if (!dev_info_signed)
738+
return -ENOMEM;
739+
740+
info = kzalloc(sizeof(*info), GFP_KERNEL);
741+
if (!info) {
742+
rc = -ENOMEM;
743+
goto free_dev_info_signed;
744+
}
745+
746+
rc = hl_fw_get_dev_info_signed(hpriv->hdev,
747+
dev_info_signed, args->sec_attest_nonce);
748+
if (rc)
749+
goto free_info;
750+
751+
info->nonce = le32_to_cpu(dev_info_signed->nonce);
752+
info->info_sig_len = dev_info_signed->info_sig_len;
753+
info->pub_data_len = le16_to_cpu(dev_info_signed->pub_data_len);
754+
info->certificate_len = le16_to_cpu(dev_info_signed->certificate_len);
755+
info->dev_info_len = sizeof(struct cpucp_info);
756+
memcpy(&info->info_sig, &dev_info_signed->info_sig, sizeof(info->info_sig));
757+
memcpy(&info->public_data, &dev_info_signed->public_data, sizeof(info->public_data));
758+
memcpy(&info->certificate, &dev_info_signed->certificate, sizeof(info->certificate));
759+
memcpy(&info->dev_info, &dev_info_signed->info, info->dev_info_len);
760+
761+
rc = copy_to_user(out, info, min_t(size_t, max_size, sizeof(*info))) ? -EFAULT : 0;
762+
763+
free_info:
764+
kfree(info);
765+
free_dev_info_signed:
766+
kfree(dev_info_signed);
767+
768+
return rc;
769+
}
770+
771+
722772
static int eventfd_register(struct hl_fpriv *hpriv, struct hl_info_args *args)
723773
{
724774
int rc;
@@ -1089,6 +1139,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
10891139
case HL_INFO_FW_GENERIC_REQ:
10901140
return send_fw_generic_request(hdev, args);
10911141

1142+
case HL_INFO_DEV_SIGNED:
1143+
return dev_info_signed(hpriv, args);
1144+
10921145
default:
10931146
dev_err(dev, "Invalid request %d\n", args->op);
10941147
rc = -EINVAL;

include/linux/habanalabs/cpucp_if.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ enum pq_init_status {
659659
* number (nonce) provided by the host to prevent replay attacks.
660660
* public key and certificate also provided as part of the FW response.
661661
*
662+
* CPUCP_PACKET_INFO_SIGNED_GET -
663+
* Get the device information signed by the Trusted Platform device.
664+
* device info data is also hashed with some unique number (nonce) provided
665+
* by the host to prevent replay attacks. public key and certificate also
666+
* provided as part of the FW response.
667+
*
662668
* CPUCP_PACKET_MONITOR_DUMP_GET -
663669
* Get monitors registers dump from the CpuCP kernel.
664670
* The CPU will put the registers dump in the a buffer allocated by the driver
@@ -733,7 +739,7 @@ enum cpucp_packet_id {
733739
CPUCP_PACKET_ENGINE_CORE_ASID_SET, /* internal */
734740
CPUCP_PACKET_RESERVED2, /* not used */
735741
CPUCP_PACKET_SEC_ATTEST_GET, /* internal */
736-
CPUCP_PACKET_RESERVED3, /* not used */
742+
CPUCP_PACKET_INFO_SIGNED_GET, /* internal */
737743
CPUCP_PACKET_RESERVED4, /* not used */
738744
CPUCP_PACKET_MONITOR_DUMP_GET, /* debugfs */
739745
CPUCP_PACKET_RESERVED5, /* not used */

include/uapi/drm/habanalabs_accel.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ enum hl_server_type {
846846
#define HL_INFO_HW_ERR_EVENT 36
847847
#define HL_INFO_FW_ERR_EVENT 37
848848
#define HL_INFO_USER_ENGINE_ERR_EVENT 38
849+
#define HL_INFO_DEV_SIGNED 40
849850

850851
#define HL_INFO_VERSION_MAX_LEN 128
851852
#define HL_INFO_CARD_NAME_MAX_LEN 16
@@ -1256,6 +1257,7 @@ struct hl_info_dev_memalloc_page_sizes {
12561257
#define SEC_SIGNATURE_BUF_SZ 255 /* (256 - 1) 1 byte used for size */
12571258
#define SEC_PUB_DATA_BUF_SZ 510 /* (512 - 2) 2 bytes used for size */
12581259
#define SEC_CERTIFICATE_BUF_SZ 2046 /* (2048 - 2) 2 bytes used for size */
1260+
#define SEC_DEV_INFO_BUF_SZ 5120
12591261

12601262
/*
12611263
* struct hl_info_sec_attest - attestation report of the boot
@@ -1290,6 +1292,32 @@ struct hl_info_sec_attest {
12901292
__u8 pad0[2];
12911293
};
12921294

1295+
/*
1296+
* struct hl_info_signed - device information signed by a secured device.
1297+
* @nonce: number only used once. random number provided by host. this also passed to the quote
1298+
* command as a qualifying data.
1299+
* @pub_data_len: length of the public data (bytes)
1300+
* @certificate_len: length of the certificate (bytes)
1301+
* @info_sig_len: length of the attestation signature (bytes)
1302+
* @public_data: public key info signed info data (outPublic + name + qualifiedName)
1303+
* @certificate: certificate for the signing key
1304+
* @info_sig: signature of the info + nonce data.
1305+
* @dev_info_len: length of device info (bytes)
1306+
* @dev_info: device info as byte array.
1307+
*/
1308+
struct hl_info_signed {
1309+
__u32 nonce;
1310+
__u16 pub_data_len;
1311+
__u16 certificate_len;
1312+
__u8 info_sig_len;
1313+
__u8 public_data[SEC_PUB_DATA_BUF_SZ];
1314+
__u8 certificate[SEC_CERTIFICATE_BUF_SZ];
1315+
__u8 info_sig[SEC_SIGNATURE_BUF_SZ];
1316+
__u16 dev_info_len;
1317+
__u8 dev_info[SEC_DEV_INFO_BUF_SZ];
1318+
__u8 pad[2];
1319+
};
1320+
12931321
/**
12941322
* struct hl_page_fault_info - page fault information.
12951323
* @timestamp: timestamp of page fault.

0 commit comments

Comments
 (0)