tools/testing/cxl: add mechanism to lock mem device for testing
The mock cxl mem devs needs a way to go into "locked" status to simulate when the platform is rebooted. Add a sysfs mechanism so the device security state is set to "locked" and the frozen state bits are cleared. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/166983617602.2734609.7042497620931694717.stgit@djiang5-desk3.ch.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
parent
bd429e5355
commit
18fa556375
|
@ -245,7 +245,7 @@ static int mock_set_passphrase(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd
|
||||||
|
|
||||||
static int mock_disable_passphrase(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
static int mock_disable_passphrase(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
||||||
{
|
{
|
||||||
struct cxl_mock_mem_pdata *mdata = dev_get_platdata(cxlds->dev);
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
|
||||||
struct cxl_disable_pass *dis_pass;
|
struct cxl_disable_pass *dis_pass;
|
||||||
|
|
||||||
if (cmd->size_in != sizeof(*dis_pass))
|
if (cmd->size_in != sizeof(*dis_pass))
|
||||||
|
@ -316,7 +316,7 @@ static int mock_disable_passphrase(struct cxl_dev_state *cxlds, struct cxl_mbox_
|
||||||
|
|
||||||
static int mock_freeze_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
static int mock_freeze_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
||||||
{
|
{
|
||||||
struct cxl_mock_mem_pdata *mdata = dev_get_platdata(cxlds->dev);
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
|
||||||
|
|
||||||
if (cmd->size_in != 0)
|
if (cmd->size_in != 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -333,7 +333,7 @@ static int mock_freeze_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd
|
||||||
|
|
||||||
static int mock_unlock_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
static int mock_unlock_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
|
||||||
{
|
{
|
||||||
struct cxl_mock_mem_pdata *mdata = dev_get_platdata(cxlds->dev);
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
|
||||||
|
|
||||||
if (cmd->size_in != NVDIMM_PASSPHRASE_LEN)
|
if (cmd->size_in != NVDIMM_PASSPHRASE_LEN)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -376,7 +376,7 @@ static int mock_unlock_security(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd
|
||||||
static int mock_passphrase_secure_erase(struct cxl_dev_state *cxlds,
|
static int mock_passphrase_secure_erase(struct cxl_dev_state *cxlds,
|
||||||
struct cxl_mbox_cmd *cmd)
|
struct cxl_mbox_cmd *cmd)
|
||||||
{
|
{
|
||||||
struct cxl_mock_mem_pdata *mdata = dev_get_platdata(cxlds->dev);
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
|
||||||
struct cxl_pass_erase *erase;
|
struct cxl_pass_erase *erase;
|
||||||
|
|
||||||
if (cmd->size_in != sizeof(*erase))
|
if (cmd->size_in != sizeof(*erase))
|
||||||
|
@ -650,6 +650,45 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t security_lock_show(struct device *dev,
|
||||||
|
struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
|
||||||
|
|
||||||
|
return sysfs_emit(buf, "%u\n",
|
||||||
|
!!(mdata->security_state & CXL_PMEM_SEC_STATE_LOCKED));
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t security_lock_store(struct device *dev, struct device_attribute *attr,
|
||||||
|
const char *buf, size_t count)
|
||||||
|
{
|
||||||
|
struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
|
||||||
|
u32 mask = CXL_PMEM_SEC_STATE_FROZEN | CXL_PMEM_SEC_STATE_USER_PLIMIT |
|
||||||
|
CXL_PMEM_SEC_STATE_MASTER_PLIMIT;
|
||||||
|
int val;
|
||||||
|
|
||||||
|
if (kstrtoint(buf, 0, &val) < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (val == 1) {
|
||||||
|
if (!(mdata->security_state & CXL_PMEM_SEC_STATE_USER_PASS_SET))
|
||||||
|
return -ENXIO;
|
||||||
|
mdata->security_state |= CXL_PMEM_SEC_STATE_LOCKED;
|
||||||
|
mdata->security_state &= ~mask;
|
||||||
|
} else {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DEVICE_ATTR_RW(security_lock);
|
||||||
|
|
||||||
|
static struct attribute *cxl_mock_mem_attrs[] = {
|
||||||
|
&dev_attr_security_lock.attr,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
ATTRIBUTE_GROUPS(cxl_mock_mem);
|
||||||
|
|
||||||
static const struct platform_device_id cxl_mock_mem_ids[] = {
|
static const struct platform_device_id cxl_mock_mem_ids[] = {
|
||||||
{ .name = "cxl_mem", },
|
{ .name = "cxl_mem", },
|
||||||
{ },
|
{ },
|
||||||
|
@ -661,6 +700,7 @@ static struct platform_driver cxl_mock_mem_driver = {
|
||||||
.id_table = cxl_mock_mem_ids,
|
.id_table = cxl_mock_mem_ids,
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = KBUILD_MODNAME,
|
.name = KBUILD_MODNAME,
|
||||||
|
.dev_groups = cxl_mock_mem_groups,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue