From: Rafael Antognolli <rafael.antognolli@intel.com>
To: linux-nvme@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
Rafael Antognolli <rafael.antognolli@intel.com>
Subject: [PATCH 2/2] NVMe: Add ioctls to save and unlock an Opal locking range.
Date: Fri, 22 Apr 2016 16:12:12 -0700 [thread overview]
Message-ID: <1461366732-31779-3-git-send-email-rafael.antognolli@intel.com> (raw)
In-Reply-To: <1461366732-31779-1-git-send-email-rafael.antognolli@intel.com>
Two ioctls are added to the NVMe namespace: NVME_IOCTL_SAVE_OPAL_KEY and
NVME_IOCTL_UNLOCK_OPAL. These ioctls map directly to the respective
nvme_opal_register() and nvme_opal_unlock() functions.
Additionally, nvme_opal_unlock() is called upon nvme_revalidate_disk, so it
will try to unlock a locking range (if a password for it is saved) during PM
resume.
Signed-off-by: Rafael Antognolli <rafael.antognolli@intel.com>
---
drivers/nvme/host/core.c | 9 +++++++++
include/uapi/linux/nvme_ioctl.h | 7 +++++++
2 files changed, 16 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 643f457..1f4b78c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -30,6 +30,7 @@
#include <asm/unaligned.h>
#include "nvme.h"
+#include "opal.h"
#define NVME_MINORS (1U << MINORBITS)
@@ -517,6 +518,10 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
case SG_IO:
return nvme_sg_io(ns, (void __user *)arg);
#endif
+ case NVME_IOCTL_SAVE_OPAL_KEY:
+ return nvme_opal_register(ns, (void __user *)arg);
+ case NVME_IOCTL_UNLOCK_OPAL:
+ return nvme_opal_unlock(ns);
default:
return -ENOTTY;
}
@@ -675,6 +680,7 @@ static int nvme_revalidate_disk(struct gendisk *disk)
if (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)
nvme_config_discard(ns);
blk_mq_unfreeze_queue(disk->queue);
+ nvme_opal_unlock(ns);
kfree(id);
return 0;
@@ -1596,6 +1602,8 @@ int __init nvme_core_init(void)
goto unregister_chrdev;
}
+ nvme_opal_init();
+
return 0;
unregister_chrdev:
@@ -1607,6 +1615,7 @@ int __init nvme_core_init(void)
void nvme_core_exit(void)
{
+ nvme_opal_exit();
unregister_blkdev(nvme_major, "nvme");
class_destroy(nvme_class);
__unregister_chrdev(nvme_char_major, 0, NVME_MINORS, "nvme");
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index c4b2a3f..8f8ab02 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -53,6 +53,11 @@ struct nvme_passthru_cmd {
__u32 result;
};
+struct nvme_opal_key {
+ __u8 locking_range;
+ __u8 key[256];
+};
+
#define nvme_admin_cmd nvme_passthru_cmd
#define NVME_IOCTL_ID _IO('N', 0x40)
@@ -61,5 +66,7 @@ struct nvme_passthru_cmd {
#define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct nvme_passthru_cmd)
#define NVME_IOCTL_RESET _IO('N', 0x44)
#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45)
+#define NVME_IOCTL_SAVE_OPAL_KEY _IOW('N', 0X46, struct nvme_opal_key)
+#define NVME_IOCTL_UNLOCK_OPAL _IO('N', 0X47)
#endif /* _UAPI_LINUX_NVME_IOCTL_H */
--
1.9.1
next prev parent reply other threads:[~2016-04-22 23:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 23:12 [PATCH 0/2] Add Opal unlock support to NVMe Rafael Antognolli
2016-04-22 23:12 ` [PATCH 1/2] Add optane OPAL unlocking code Rafael Antognolli
2016-04-22 23:12 ` Rafael Antognolli [this message]
2016-04-25 8:24 ` [PATCH 0/2] Add Opal unlock support to NVMe Christoph Hellwig
2016-04-26 3:29 ` Elliott, Robert (Persistent Memory)
2016-04-26 21:33 ` Rafael Antognolli
2016-05-18 23:54 ` Rafael Antognolli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461366732-31779-3-git-send-email-rafael.antognolli@intel.com \
--to=rafael.antognolli@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®