Skip to content

Commit 638c191

Browse files
committed
Merge tag 'cxl-fixes-6.5-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl
Pull cxl fixes from Vishal Verma: - Fixup the Sanitixe device ABI that was merged for v6.5 to hide some sysfs files when the necessary support is missing. Update the ABI documentation around this as well. * tag 'cxl-fixes-6.5-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl: cxl/memdev: Only show sanitize sysfs files when supported cxl/memdev: Document security state in kern-doc cxl/memdev: Improve sanitize ABI descriptions
2 parents 999f663 + ad64f59 commit 638c191

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ Description:
8282
whether it resides in persistent capacity, volatile capacity,
8383
or the LSA, is made permanently unavailable by whatever means
8484
is appropriate for the media type. This functionality requires
85-
the device to be not be actively decoding any HPA ranges.
85+
the device to be disabled, that is, not actively decoding any
86+
HPA ranges. This permits avoiding explicit global CPU cache
87+
management, relying instead for it to be done when a region
88+
transitions between software programmed and hardware committed
89+
states. If this file is not present, then there is no hardware
90+
support for the operation.
8691

8792

8893
What /sys/bus/cxl/devices/memX/security/erase
@@ -92,7 +97,13 @@ Contact: linux-cxl@vger.kernel.org
9297
Description:
9398
(WO) Write a boolean 'true' string value to this attribute to
9499
secure erase user data by changing the media encryption keys for
95-
all user data areas of the device.
100+
all user data areas of the device. This functionality requires
101+
the device to be disabled, that is, not actively decoding any
102+
HPA ranges. This permits avoiding explicit global CPU cache
103+
management, relying instead for it to be done when a region
104+
transitions between software programmed and hardware committed
105+
states. If this file is not present, then there is no hardware
106+
support for the operation.
96107

97108

98109
What: /sys/bus/cxl/devices/memX/firmware/

drivers/cxl/core/mbox.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,45 @@ static bool cxl_is_security_command(u16 opcode)
121121
return false;
122122
}
123123

124+
static 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+
124163
static bool cxl_is_poison_command(u16 opcode)
125164
{
126165
#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)
677716
u16 opcode = le16_to_cpu(cel_entry[i].opcode);
678717
struct cxl_mem_command *cmd = cxl_mem_find_command(opcode);
679718

680-
if (!cmd && !cxl_is_poison_command(opcode)) {
719+
if (!cmd && (!cxl_is_poison_command(opcode) ||
720+
!cxl_is_security_command(opcode))) {
681721
dev_dbg(dev,
682722
"Opcode 0x%04x unsupported by driver\n", opcode);
683723
continue;
@@ -689,6 +729,9 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
689729
if (cxl_is_poison_command(opcode))
690730
cxl_set_poison_cmd_enabled(&mds->poison, opcode);
691731

732+
if (cxl_is_security_command(opcode))
733+
cxl_set_security_cmd_enabled(&mds->security, opcode);
734+
692735
dev_dbg(dev, "Opcode 0x%04x enabled\n", opcode);
693736
}
694737
}

drivers/cxl/core/memdev.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,28 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = {
477477
.attrs = cxl_memdev_pmem_attributes,
478478
};
479479

480+
static 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+
480498
static struct attribute_group cxl_memdev_security_attribute_group = {
481499
.name = "security",
482500
.attrs = cxl_memdev_security_attributes,
501+
.is_visible = cxl_memdev_security_visible,
483502
};
484503

485504
static const struct attribute_group *cxl_memdev_attribute_groups[] = {

drivers/cxl/cxlmem.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ enum poison_cmd_enabled_bits {
244244
CXL_POISON_ENABLED_MAX
245245
};
246246

247+
/* Device enabled security commands */
248+
enum 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+
247260
/**
248261
* struct cxl_poison_state - Driver poison state info
249262
*
@@ -346,13 +359,15 @@ struct cxl_fw_state {
346359
* struct cxl_security_state - Device security state
347360
*
348361
* @state: state of last security operation
362+
* @enabled_cmds: All security commands enabled in the CEL
349363
* @poll: polling for sanitization is enabled, device has no mbox irq support
350364
* @poll_tmo_secs: polling timeout
351365
* @poll_dwork: polling work item
352366
* @sanitize_node: sanitation sysfs file to notify
353367
*/
354368
struct cxl_security_state {
355369
unsigned long state;
370+
DECLARE_BITMAP(enabled_cmds, CXL_SEC_ENABLED_MAX);
356371
bool poll;
357372
int poll_tmo_secs;
358373
struct delayed_work poll_dwork;
@@ -434,6 +449,7 @@ struct cxl_dev_state {
434449
* @next_persistent_bytes: persistent capacity change pending device reset
435450
* @event: event log driver state
436451
* @poison: poison driver state info
452+
* @security: security driver state info
437453
* @fw: firmware upload / activation state
438454
* @mbox_send: @dev specific transport for transmitting mailbox commands
439455
*

0 commit comments

Comments
 (0)