History

cxl/pmem: Add "Unlock" security command support

Create callback function to support the nvdimm_security_ops() ->unlock() callback. Translate the operation to send "Unlock" security command for CXL mem device. When the mem device is unlocked, cpu_cache_invalidate_memregion() is called in order to invalidate all CPU caches before attempting to access the mem device. See CXL rev3.0 spec section 8.2.9.8.6.4 for reference.

Dave Jiang committed 3 years ago

Commit 2bb692f1 parent 410926e4 files · +30 −0Browse files

Unified · Split

4 files
  1. drivers/cxl/core/mbox.c +1 −0
  2. drivers/cxl/cxlmem.h +1 −0
  3. drivers/cxl/security.c +27 −0
  4. include/uapi/linux/cxl_mem.h +1 −0
drivers/cxl/core/mbox.c+1−0
@@ -69,6 +69,7 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { · 68 unmodified lines
6969 CXL_CMD(SET_PASSPHRASE, 0x60, 0, 0),
7070 CXL_CMD(DISABLE_PASSPHRASE, 0x40, 0, 0),
7171 CXL_CMD(FREEZE_SECURITY, 0, 0, 0),
72+ CXL_CMD(UNLOCK, 0x20, 0, 0),
7273 };
7374
7475 /*
drivers/cxl/cxlmem.h+1−0
@@ -276,6 +276,7 @@ enum cxl_opcode { · 275 unmodified lines
276276 CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500,
277277 CXL_MBOX_OP_SET_PASSPHRASE = 0x4501,
278278 CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502,
279+ CXL_MBOX_OP_UNLOCK = 0x4503,
279280 CXL_MBOX_OP_FREEZE_SECURITY = 0x4504,
280281 CXL_MBOX_OP_MAX = 0x10000
281282 };
drivers/cxl/security.c+27−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include <linux/module.h>
66 #include <linux/async.h>
77 #include <linux/slab.h>
8+#include <linux/memregion.h>
89 #include "cxlmem.h"
910 #include "cxl.h"
1011
@@ -96,11 +97,37 @@ static int cxl_pmem_security_freeze(struct nvdimm *nvdimm) · 85 unmodified lines
9697 return cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_FREEZE_SECURITY, NULL, 0, NULL, 0);
9798 }
9899
100+static int cxl_pmem_security_unlock(struct nvdimm *nvdimm,
101+ const struct nvdimm_key_data *key_data)
102+{
103+ struct cxl_nvdimm *cxl_nvd = nvdimm_provider_data(nvdimm);
104+ struct cxl_memdev *cxlmd = cxl_nvd->cxlmd;
105+ struct cxl_dev_state *cxlds = cxlmd->cxlds;
106+ u8 pass[NVDIMM_PASSPHRASE_LEN];
107+ int rc;
108+
109+ if (!cpu_cache_has_invalidate_memregion())
110+ return -EINVAL;
111+
112+ memcpy(pass, key_data->data, NVDIMM_PASSPHRASE_LEN);
113+ rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_UNLOCK,
114+ pass, NVDIMM_PASSPHRASE_LEN, NULL, 0);
115+ if (rc < 0)
116+ return rc;
117+
118+ /* DIMM unlocked, invalidate all CPU caches before we read it */
119+ cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY);
120+ return 0;
121+}
122+
99123 static const struct nvdimm_security_ops __cxl_security_ops = {
100124 .get_flags = cxl_pmem_get_security_flags,
101125 .change_key = cxl_pmem_security_change_key,
102126 .disable = cxl_pmem_security_disable,
103127 .freeze = cxl_pmem_security_freeze,
128+ .unlock = cxl_pmem_security_unlock,
104129 };
105130
106131 const struct nvdimm_security_ops *cxl_security_ops = &__cxl_security_ops;
132+
133+MODULE_IMPORT_NS(DEVMEM);
include/uapi/linux/cxl_mem.h+1−0
@@ -45,6 +45,7 @@ · 44 unmodified lines
4545 ___C(SET_PASSPHRASE, "Set Passphrase"), \
4646 ___C(DISABLE_PASSPHRASE, "Disable Passphrase"), \
4747 ___C(FREEZE_SECURITY, "Freeze Security"), \
48+ ___C(UNLOCK, "Unlock"), \
4849 ___C(MAX, "invalid / last command")
4950
5051 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a

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