History

cxl/memdev: Only show sanitize sysfs files when supported

If the device does not support Sanitize or Secure Erase commands, hide the respective sysfs interfaces such that the operation can never be attempted. In order to be generic, keep track of the enabled security commands found in the CEL - the driver does not support Security Passthrough.

Davidlohr Bueso committed 3 years ago

Commit ad64f591 parent 3de8cd24 files · +82 −3Browse files

Unified · Split

4 files
  1. Documentation/ABI/testing/sysfs-bus-cxl +4 −2
  2. drivers/cxl/core/mbox.c +44 −1
  3. drivers/cxl/core/memdev.c +19 −0
  4. drivers/cxl/cxlmem.h +15 −0
Documentation/ABI/testing/sysfs-bus-cxl+4−2
@@ -86,7 +86,8 @@ Description: · 85 unmodified lines
86 HPA ranges. This permits avoiding explicit global CPU cache86 HPA ranges. This permits avoiding explicit global CPU cache
87 management, relying instead for it to be done when a region87 management, relying instead for it to be done when a region
88 transitions between software programmed and hardware committed88 transitions between software programmed and hardware committed
89 states.89 states. If this file is not present, then there is no hardware
90 support for the operation.
90 91
91 92
92What /sys/bus/cxl/devices/memX/security/erase93What /sys/bus/cxl/devices/memX/security/erase
@@ -101,7 +102,8 @@ Description: · 8 unmodified lines
101 HPA ranges. This permits avoiding explicit global CPU cache102 HPA ranges. This permits avoiding explicit global CPU cache
102 management, relying instead for it to be done when a region103 management, relying instead for it to be done when a region
103 transitions between software programmed and hardware committed104 transitions between software programmed and hardware committed
104 states.105 states. If this file is not present, then there is no hardware
106 support for the operation.
105 107
106 108
107What: /sys/bus/cxl/devices/memX/firmware/109What: /sys/bus/cxl/devices/memX/firmware/
drivers/cxl/core/mbox.c+44−1
@@ -121,6 +121,45 @@ static bool cxl_is_security_command(u16 opcode) · 120 unmodified lines
121 return false;121 return false;
122}122}
123 123
124static void cxl_set_security_cmd_enabled(struct cxl_security_state *security,
125 u16 opcode)
126{
127 switch (opcode) {
128 case CXL_MBOX_OP_SANITIZE:
129 set_bit(CXL_SEC_ENABLED_SANITIZE, security->enabled_cmds);
130 break;
131 case CXL_MBOX_OP_SECURE_ERASE:
132 set_bit(CXL_SEC_ENABLED_SECURE_ERASE,
133 security->enabled_cmds);
134 break;
135 case CXL_MBOX_OP_GET_SECURITY_STATE:
136 set_bit(CXL_SEC_ENABLED_GET_SECURITY_STATE,
137 security->enabled_cmds);
138 break;
139 case CXL_MBOX_OP_SET_PASSPHRASE:
140 set_bit(CXL_SEC_ENABLED_SET_PASSPHRASE,
141 security->enabled_cmds);
142 break;
143 case CXL_MBOX_OP_DISABLE_PASSPHRASE:
144 set_bit(CXL_SEC_ENABLED_DISABLE_PASSPHRASE,
145 security->enabled_cmds);
146 break;
147 case CXL_MBOX_OP_UNLOCK:
148 set_bit(CXL_SEC_ENABLED_UNLOCK, security->enabled_cmds);
149 break;
150 case CXL_MBOX_OP_FREEZE_SECURITY:
151 set_bit(CXL_SEC_ENABLED_FREEZE_SECURITY,
152 security->enabled_cmds);
153 break;
154 case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE:
155 set_bit(CXL_SEC_ENABLED_PASSPHRASE_SECURE_ERASE,
156 security->enabled_cmds);
157 break;
158 default:
159 break;
160 }
161}
162
124static bool cxl_is_poison_command(u16 opcode)163static bool cxl_is_poison_command(u16 opcode)
125{164{
126#define CXL_MBOX_OP_POISON_CMDS 0x43165#define CXL_MBOX_OP_POISON_CMDS 0x43
@@ -677,7 +716,8 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · 550 unmodified lines
677 u16 opcode = le16_to_cpu(cel_entry[i].opcode);716 u16 opcode = le16_to_cpu(cel_entry[i].opcode);
678 struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);717 struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
679 718
680 if (!cmd && !cxl_is_poison_command(opcode)) {719 if (!cmd && (!cxl_is_poison_command(opcode) ||
720 !cxl_is_security_command(opcode))) {
681 dev_dbg(dev,721 dev_dbg(dev,
682 "Opcode 0x%04x unsupported by driver\n", opcode);722 "Opcode 0x%04x unsupported by driver\n", opcode);
683 continue;723 continue;
@@ -689,6 +729,9 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · 5 unmodified lines
689 if (cxl_is_poison_command(opcode))729 if (cxl_is_poison_command(opcode))
690 cxl_set_poison_cmd_enabled(&mds->poison, opcode);730 cxl_set_poison_cmd_enabled(&mds->poison, opcode);
691 731
732 if (cxl_is_security_command(opcode))
733 cxl_set_security_cmd_enabled(&mds->security, opcode);
734
692 dev_dbg(dev, "Opcode 0x%04x enabled\n", opcode);735 dev_dbg(dev, "Opcode 0x%04x enabled\n", opcode);
693 }736 }
694}737}
drivers/cxl/core/memdev.c+19−0
@@ -477,9 +477,28 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = { · 476 unmodified lines
477 .attrs = cxl_memdev_pmem_attributes,477 .attrs = cxl_memdev_pmem_attributes,
478};478};
479 479
480static umode_t cxl_memdev_security_visible(struct kobject *kobj,
481 struct attribute *a, int n)
482{
483 struct device *dev = kobj_to_dev(kobj);
484 struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
485 struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
486
487 if (a == &dev_attr_security_sanitize.attr &&
488 !test_bit(CXL_SEC_ENABLED_SANITIZE, mds->security.enabled_cmds))
489 return 0;
490
491 if (a == &dev_attr_security_erase.attr &&
492 !test_bit(CXL_SEC_ENABLED_SECURE_ERASE, mds->security.enabled_cmds))
493 return 0;
494
495 return a->mode;
496}
497
480static struct attribute_group cxl_memdev_security_attribute_group = {498static struct attribute_group cxl_memdev_security_attribute_group = {
481 .name = "security",499 .name = "security",
482 .attrs = cxl_memdev_security_attributes,500 .attrs = cxl_memdev_security_attributes,
501 .is_visible = cxl_memdev_security_visible,
483};502};
484 503
485static const struct attribute_group *cxl_memdev_attribute_groups[] = {504static const struct attribute_group *cxl_memdev_attribute_groups[] = {
drivers/cxl/cxlmem.h+15−0
@@ -244,6 +244,19 @@ enum poison_cmd_enabled_bits { · 243 unmodified lines
244 CXL_POISON_ENABLED_MAX244 CXL_POISON_ENABLED_MAX
245};245};
246 246
247/* Device enabled security commands */
248enum security_cmd_enabled_bits {
249 CXL_SEC_ENABLED_SANITIZE,
250 CXL_SEC_ENABLED_SECURE_ERASE,
251 CXL_SEC_ENABLED_GET_SECURITY_STATE,
252 CXL_SEC_ENABLED_SET_PASSPHRASE,
253 CXL_SEC_ENABLED_DISABLE_PASSPHRASE,
254 CXL_SEC_ENABLED_UNLOCK,
255 CXL_SEC_ENABLED_FREEZE_SECURITY,
256 CXL_SEC_ENABLED_PASSPHRASE_SECURE_ERASE,
257 CXL_SEC_ENABLED_MAX
258};
259
247/**260/**
248 * struct cxl_poison_state - Driver poison state info261 * struct cxl_poison_state - Driver poison state info
249 *262 *
@@ -346,6 +359,7 @@ struct cxl_fw_state { · 96 unmodified lines
346 * struct cxl_security_state - Device security state359 * struct cxl_security_state - Device security state
347 *360 *
348 * @state: state of last security operation361 * @state: state of last security operation
362 * @enabled_cmds: All security commands enabled in the CEL
349 * @poll: polling for sanitization is enabled, device has no mbox irq support363 * @poll: polling for sanitization is enabled, device has no mbox irq support
350 * @poll_tmo_secs: polling timeout364 * @poll_tmo_secs: polling timeout
351 * @poll_dwork: polling work item365 * @poll_dwork: polling work item
@@ -353,6 +367,7 @@ struct cxl_fw_state { · 1 unmodified line
353 */367 */
354struct cxl_security_state {368struct cxl_security_state {
355 unsigned long state;369 unsigned long state;
370 DECLARE_BITMAP(enabled_cmds, CXL_SEC_ENABLED_MAX);
356 bool poll;371 bool poll;
357 int poll_tmo_secs;372 int poll_tmo_secs;
358 struct delayed_work poll_dwork;373 struct delayed_work poll_dwork;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t