From patchwork Fri Apr 22 23:12:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Antognolli X-Patchwork-Id: 8916181 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 430C0BF29F for ; Fri, 22 Apr 2016 23:13:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5ACD7201C7 for ; Fri, 22 Apr 2016 23:13:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71D30201C0 for ; Fri, 22 Apr 2016 23:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753285AbcDVXNT (ORCPT ); Fri, 22 Apr 2016 19:13:19 -0400 Received: from mga11.intel.com ([192.55.52.93]:20739 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753288AbcDVXNR (ORCPT ); Fri, 22 Apr 2016 19:13:17 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 22 Apr 2016 16:13:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,519,1455004800"; d="scan'208";a="790522198" Received: from di-604.jf.intel.com (HELO nadine2.fso.intel.com.com) ([10.7.199.72]) by orsmga003.jf.intel.com with ESMTP; 22 Apr 2016 16:13:14 -0700 From: Rafael Antognolli To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Rafael Antognolli Subject: [PATCH 2/2] NVMe: Add ioctls to save and unlock an Opal locking range. Date: Fri, 22 Apr 2016 16:12:12 -0700 Message-Id: <1461366732-31779-3-git-send-email-rafael.antognolli@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1461366732-31779-1-git-send-email-rafael.antognolli@intel.com> References: <1461366732-31779-1-git-send-email-rafael.antognolli@intel.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #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 */