@@ -3,6 +3,7 @@ menuconfig LIBNVDIMM
depends on PHYS_ADDR_T_64BIT
depends on HAS_IOMEM
depends on BLK_DEV
+ depends on KEYS
help
Generic support for non-volatile memory devices including
ACPI-6-NFIT defined resources. On platforms that define an
@@ -437,9 +437,12 @@ static __init int libnvdimm_init(void)
{
int rc;
- rc = nvdimm_bus_init();
+ rc = nvdimm_devs_init();
if (rc)
return rc;
+ rc = nvdimm_bus_init();
+ if (rc)
+ goto err_bus;
rc = nvdimm_init();
if (rc)
goto err_dimm;
@@ -454,6 +457,8 @@ static __init int libnvdimm_init(void)
nvdimm_exit();
err_dimm:
nvdimm_bus_exit();
+ err_bus:
+ nvdimm_devs_exit();
return rc;
}
@@ -18,12 +18,15 @@
#include <linux/io.h>
#include <linux/fs.h>
#include <linux/mm.h>
+#include <linux/cred.h>
+#include <linux/key.h>
#include "nd-core.h"
#include "label.h"
#include "pmem.h"
#include "nd.h"
static DEFINE_IDA(dimm_ida);
+static struct key *nvdimm_keyring;
/*
* Retrieve bus and dimm handle and return if this bus supports
@@ -699,7 +702,31 @@ int nvdimm_bus_check_dimm_count(struct nvdimm_bus *nvdimm_bus, int dimm_count)
}
EXPORT_SYMBOL_GPL(nvdimm_bus_check_dimm_count);
-void __exit nvdimm_devs_exit(void)
+static int nvdimm_register_keyring(void)
{
+ nvdimm_keyring = keyring_alloc(".nvdimm",
+ GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
+ (KEY_POS_ALL & ~KEY_POS_SETATTR),
+ KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL);
+ if (IS_ERR(nvdimm_keyring))
+ return PTR_ERR(nvdimm_keyring);
+
+ return 0;
+}
+
+static void nvdimm_unregister_keyring(void)
+{
+ key_put(nvdimm_keyring);
+ key_revoke(nvdimm_keyring);
+}
+
+int __init nvdimm_devs_init(void)
+{
+ return nvdimm_register_keyring();
+}
+
+void nvdimm_devs_exit(void)
+{
+ nvdimm_unregister_keyring();
ida_destroy(&dimm_ida);
}
@@ -76,6 +76,7 @@ static inline bool is_memory(struct device *dev)
struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
int __init nvdimm_bus_init(void);
void nvdimm_bus_exit(void);
+int nvdimm_devs_init(void);
void nvdimm_devs_exit(void);
void nd_region_devs_exit(void);
void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev);
@@ -155,6 +155,9 @@ static inline struct nd_blk_region_desc *to_blk_region_desc(
}
+#define NVDIMM_PASSPHRASE_LEN 32
+#define NVDIMM_KEY_DESC_LEN 22
+
void badrange_init(struct badrange *badrange);
int badrange_add(struct badrange *badrange, u64 addr, u64 length);
void badrange_forget(struct badrange *badrange, phys_addr_t start,