|
19 | 19 |
|
20 | 20 | #include <asm/msr.h> |
21 | 21 |
|
| 22 | +/* make sure there is space for all the signed info */ |
| 23 | +static_assert(sizeof(struct cpucp_info) <= SEC_DEV_INFO_BUF_SZ); |
| 24 | + |
22 | 25 | static u32 hl_debug_struct_size[HL_DEBUG_OP_TIMESTAMP + 1] = { |
23 | 26 | [HL_DEBUG_OP_ETR] = sizeof(struct hl_debug_params_etr), |
24 | 27 | [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) |
719 | 722 | return rc; |
720 | 723 | } |
721 | 724 |
|
| 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 | + |
722 | 772 | static int eventfd_register(struct hl_fpriv *hpriv, struct hl_info_args *args) |
723 | 773 | { |
724 | 774 | int rc; |
@@ -1089,6 +1139,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data, |
1089 | 1139 | case HL_INFO_FW_GENERIC_REQ: |
1090 | 1140 | return send_fw_generic_request(hdev, args); |
1091 | 1141 |
|
| 1142 | + case HL_INFO_DEV_SIGNED: |
| 1143 | + return dev_info_signed(hpriv, args); |
| 1144 | + |
1092 | 1145 | default: |
1093 | 1146 | dev_err(dev, "Invalid request %d\n", args->op); |
1094 | 1147 | rc = -EINVAL; |
|
0 commit comments