hsti.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * AMD Secure Processor device driver, security attributes
  4. *
  5. * Copyright (C) 2023-2024 Advanced Micro Devices, Inc.
  6. *
  7. * Author: Mario Limonciello <mario.limonciello@amd.com>
  8. */
  9. #include <linux/device.h>
  10. #include "psp-dev.h"
  11. #include "hsti.h"
  12. #define PSP_CAPABILITY_PSP_SECURITY_OFFSET 8
  13. struct hsti_request {
  14. struct psp_req_buffer_hdr header;
  15. u32 hsti;
  16. } __packed;
  17. #define security_attribute_show(name) \
  18. static ssize_t name##_show(struct device *d, struct device_attribute *attr, \
  19. char *buf) \
  20. { \
  21. struct sp_device *sp = dev_get_drvdata(d); \
  22. struct psp_device *psp = sp->psp_data; \
  23. return sysfs_emit(buf, "%d\n", psp->capability.name); \
  24. }
  25. security_attribute_show(fused_part)
  26. static DEVICE_ATTR_RO(fused_part);
  27. security_attribute_show(debug_lock_on)
  28. static DEVICE_ATTR_RO(debug_lock_on);
  29. security_attribute_show(tsme_status)
  30. static DEVICE_ATTR_RO(tsme_status);
  31. security_attribute_show(anti_rollback_status)
  32. static DEVICE_ATTR_RO(anti_rollback_status);
  33. security_attribute_show(rpmc_production_enabled)
  34. static DEVICE_ATTR_RO(rpmc_production_enabled);
  35. security_attribute_show(rpmc_spirom_available)
  36. static DEVICE_ATTR_RO(rpmc_spirom_available);
  37. security_attribute_show(hsp_tpm_available)
  38. static DEVICE_ATTR_RO(hsp_tpm_available);
  39. security_attribute_show(rom_armor_enforced)
  40. static DEVICE_ATTR_RO(rom_armor_enforced);
  41. static struct attribute *psp_security_attrs[] = {
  42. &dev_attr_fused_part.attr,
  43. &dev_attr_debug_lock_on.attr,
  44. &dev_attr_tsme_status.attr,
  45. &dev_attr_anti_rollback_status.attr,
  46. &dev_attr_rpmc_production_enabled.attr,
  47. &dev_attr_rpmc_spirom_available.attr,
  48. &dev_attr_hsp_tpm_available.attr,
  49. &dev_attr_rom_armor_enforced.attr,
  50. NULL
  51. };
  52. static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
  53. {
  54. struct device *dev = kobj_to_dev(kobj);
  55. struct sp_device *sp = dev_get_drvdata(dev);
  56. struct psp_device *psp = sp->psp_data;
  57. if (psp && psp->capability.security_reporting)
  58. return 0444;
  59. return 0;
  60. }
  61. struct attribute_group psp_security_attr_group = {
  62. .attrs = psp_security_attrs,
  63. .is_visible = psp_security_is_visible,
  64. };
  65. static int psp_poulate_hsti(struct psp_device *psp)
  66. {
  67. struct hsti_request *req;
  68. int ret;
  69. /* Are the security attributes already reported? */
  70. if (psp->capability.security_reporting)
  71. return 0;
  72. /* Allocate command-response buffer */
  73. req = kzalloc(sizeof(*req), GFP_KERNEL | __GFP_ZERO);
  74. if (!req)
  75. return -ENOMEM;
  76. req->header.payload_size = sizeof(req);
  77. ret = psp_send_platform_access_msg(PSP_CMD_HSTI_QUERY, (struct psp_request *)req);
  78. if (ret)
  79. goto out;
  80. if (req->header.status != 0) {
  81. dev_dbg(psp->dev, "failed to populate HSTI state: %d\n", req->header.status);
  82. ret = -EINVAL;
  83. goto out;
  84. }
  85. psp->capability.security_reporting = 1;
  86. psp->capability.raw |= req->hsti << PSP_CAPABILITY_PSP_SECURITY_OFFSET;
  87. out:
  88. kfree(req);
  89. return ret;
  90. }
  91. int psp_init_hsti(struct psp_device *psp)
  92. {
  93. int ret;
  94. if (PSP_FEATURE(psp, HSTI)) {
  95. ret = psp_poulate_hsti(psp);
  96. if (ret)
  97. return ret;
  98. }
  99. /*
  100. * At this stage, if security information hasn't been populated by
  101. * either the PSP or by the driver through the platform command,
  102. * then there is nothing more to do.
  103. */
  104. if (!psp->capability.security_reporting)
  105. return 0;
  106. if (psp->capability.tsme_status) {
  107. if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
  108. dev_notice(psp->dev, "psp: Both TSME and SME are active, SME is unnecessary when TSME is active.\n");
  109. else
  110. dev_notice(psp->dev, "psp: TSME enabled\n");
  111. }
  112. return 0;
  113. }