Skip to content

Commit 9968c9d

Browse files
Davidlohr Buesodjbw
authored andcommitted
cxl/mem: Introduce security state sysfs file
Add a read-only sysfs file to display the security state of a device (currently only pmem): /sys/bus/cxl/devices/memX/security/state This introduces a cxl_security_state structure that is to be the placeholder for common CXL security features. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/20230612181038.14421-3-dave@stgolabs.net Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 8ea9c33 commit 9968c9d

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ Description:
5858
affinity for this device.
5959

6060

61+
What: /sys/bus/cxl/devices/memX/security/state
62+
Date: June, 2023
63+
KernelVersion: v6.5
64+
Contact: linux-cxl@vger.kernel.org
65+
Description:
66+
(RO) Reading this file will display the CXL security state for
67+
that device. Such states can be: 'disabled', or those available
68+
only for persistent memory: 'locked', 'unlocked' or 'frozen'.
69+
70+
6171
What: /sys/bus/cxl/devices/*/devtype
6272
Date: June, 2021
6373
KernelVersion: v5.14

drivers/cxl/core/memdev.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
107107
}
108108
static DEVICE_ATTR_RO(numa_node);
109109

110+
static ssize_t security_state_show(struct device *dev,
111+
struct device_attribute *attr,
112+
char *buf)
113+
{
114+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
115+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
116+
unsigned long state = cxlds->security.state;
117+
118+
if (!(state & CXL_PMEM_SEC_STATE_USER_PASS_SET))
119+
return sysfs_emit(buf, "disabled\n");
120+
if (state & CXL_PMEM_SEC_STATE_FROZEN ||
121+
state & CXL_PMEM_SEC_STATE_MASTER_PLIMIT ||
122+
state & CXL_PMEM_SEC_STATE_USER_PLIMIT)
123+
return sysfs_emit(buf, "frozen\n");
124+
if (state & CXL_PMEM_SEC_STATE_LOCKED)
125+
return sysfs_emit(buf, "locked\n");
126+
else
127+
return sysfs_emit(buf, "unlocked\n");
128+
}
129+
static struct device_attribute dev_attr_security_state =
130+
__ATTR(state, 0444, security_state_show, NULL);
131+
110132
static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
111133
{
112134
struct cxl_dev_state *cxlds = cxlmd->cxlds;
@@ -352,6 +374,11 @@ static struct attribute *cxl_memdev_ram_attributes[] = {
352374
NULL,
353375
};
354376

377+
static struct attribute *cxl_memdev_security_attributes[] = {
378+
&dev_attr_security_state.attr,
379+
NULL,
380+
};
381+
355382
static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a,
356383
int n)
357384
{
@@ -375,10 +402,16 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = {
375402
.attrs = cxl_memdev_pmem_attributes,
376403
};
377404

405+
static struct attribute_group cxl_memdev_security_attribute_group = {
406+
.name = "security",
407+
.attrs = cxl_memdev_security_attributes,
408+
};
409+
378410
static const struct attribute_group *cxl_memdev_attribute_groups[] = {
379411
&cxl_memdev_attribute_group,
380412
&cxl_memdev_ram_attribute_group,
381413
&cxl_memdev_pmem_attribute_group,
414+
&cxl_memdev_security_attribute_group,
382415
NULL,
383416
};
384417

drivers/cxl/cxlmem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ struct cxl_poison_state {
260260
struct mutex lock; /* Protect reads of poison list */
261261
};
262262

263+
/**
264+
* struct cxl_security_state - Device security state
265+
*
266+
* @state: state of last security operation
267+
*/
268+
struct cxl_security_state {
269+
unsigned long state;
270+
};
271+
263272
/**
264273
* struct cxl_dev_state - The driver device state
265274
*
@@ -336,6 +345,7 @@ struct cxl_dev_state {
336345

337346
struct cxl_event_state event;
338347
struct cxl_poison_state poison;
348+
struct cxl_security_state security;
339349

340350
struct rcuwait mbox_wait;
341351
int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);

drivers/cxl/security.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm,
3434
return 0;
3535

3636
sec_out = le32_to_cpu(out.flags);
37+
/* cache security state */
38+
cxlds->security.state = sec_out;
39+
3740
if (ptype == NVDIMM_MASTER) {
3841
if (sec_out & CXL_PMEM_SEC_STATE_MASTER_PASS_SET)
3942
set_bit(NVDIMM_SECURITY_UNLOCKED, &security_flags);

0 commit comments

Comments
 (0)