From patchwork Tue Mar 13 13:09:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Rabenstein X-Patchwork-Id: 10278653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B4946602C2 for ; Tue, 13 Mar 2018 13:10:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7D712903E for ; Tue, 13 Mar 2018 13:10:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A65722902E; Tue, 13 Mar 2018 13:10:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2355C29043 for ; Tue, 13 Mar 2018 13:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932607AbeCMNKD (ORCPT ); Tue, 13 Mar 2018 09:10:03 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:51789 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932553AbeCMNKC (ORCPT ); Tue, 13 Mar 2018 09:10:02 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de (mx-rz-2.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx-rz-2.rrze.uni-erlangen.de (Postfix) with ESMTPS id 400wF44l2QzPjsQ; Tue, 13 Mar 2018 14:10:00 +0100 (CET) Authentication-Results: mx-rz-2.rrze.uni-erlangen.de; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Quarantine-ID: X-Virus-Scanned: amavisd-new at boeck4.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3c2:e00:dbd1:5c46:f440:b630 Received: from fau.de (p200300D503C20E00DBD15C46F440B630.dip0.t-ipconnect.de [IPv6:2003:d5:3c2:e00:dbd1:5c46:f440:b630]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX1+v/pNLdmtMHZ+2gsLvmCU3HhAKfCjIKpQ=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 400wDt0mVtzPlQ7; Tue, 13 Mar 2018 14:09:50 +0100 (CET) From: Jonas Rabenstein To: Jonas Rabenstein , Scott Bauer , Jonathan Derrick , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] block: sed-opal: add ioctl for done-mark of shadow mbr Date: Tue, 13 Mar 2018 14:09:00 +0100 Message-Id: X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable users to mark the shadow mbr as done without completely deactivating the shadow mbr feature. This may be useful on reboots, when the power to the disk is not disconnected in between and the shadow mbr stores the required boot files. Of course, this saves also the (few) commands required to enable the feature if it is already enabled and one only wants to mark the shadow mbr as done. Signed-off-by: Jonas Rabenstein --- block/sed-opal.c | 33 +++++++++++++++++++++++++++++++-- include/linux/sed-opal.h | 1 + include/uapi/linux/sed-opal.h | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/block/sed-opal.c b/block/sed-opal.c index f169e621279a..b201c96d23a3 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -1987,13 +1987,39 @@ static int opal_erase_locking_range(struct opal_dev *dev, static int opal_enable_disable_shadow_mbr(struct opal_dev *dev, struct opal_mbr_data *opal_mbr) { + u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE + ? OPAL_TRUE : OPAL_FALSE; const struct opal_step mbr_steps[] = { { opal_discovery0, }, { start_admin1LSP_opal_session, &opal_mbr->key }, - { set_mbr_done, &opal_mbr->enable_disable }, + { set_mbr_done, &token }, { end_opal_session, }, { start_admin1LSP_opal_session, &opal_mbr->key }, - { set_mbr_enable_disable, &opal_mbr->enable_disable }, + { set_mbr_enable_disable, &token }, + { end_opal_session, }, + { NULL, } + }; + int ret; + + if (opal_mbr->enable_disable != OPAL_MBR_ENABLE && + opal_mbr->enable_disable != OPAL_MBR_DISABLE) + return -EINVAL; + + mutex_lock(&dev->dev_lock); + setup_opal_dev(dev, mbr_steps); + ret = next(dev); + mutex_unlock(&dev->dev_lock); + return ret; +} + +static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr) +{ + u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE + ? OPAL_TRUE : OPAL_FALSE; + const struct opal_step mbr_steps[] = { + { opal_discovery0, }, + { start_admin1LSP_opal_session, &opal_mbr->key }, + { set_mbr_done, &token }, { end_opal_session, }, { NULL, } }; @@ -2339,6 +2365,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg) case IOC_OPAL_ENABLE_DISABLE_MBR: ret = opal_enable_disable_shadow_mbr(dev, p); break; + case IOC_OPAL_MBR_STATUS: + ret = opal_mbr_status(dev, p); + break; case IOC_OPAL_ERASE_LR: ret = opal_erase_locking_range(dev, p); break; diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h index 04b124fca51e..b38dc602cae3 100644 --- a/include/linux/sed-opal.h +++ b/include/linux/sed-opal.h @@ -47,6 +47,7 @@ static inline bool is_sed_ioctl(unsigned int cmd) case IOC_OPAL_ENABLE_DISABLE_MBR: case IOC_OPAL_ERASE_LR: case IOC_OPAL_SECURE_ERASE_LR: + case IOC_OPAL_MBR_STATUS: return true; } return false; diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h index 627624d35030..0cb9890cdc04 100644 --- a/include/uapi/linux/sed-opal.h +++ b/include/uapi/linux/sed-opal.h @@ -116,5 +116,6 @@ struct opal_mbr_data { #define IOC_OPAL_ENABLE_DISABLE_MBR _IOW('p', 229, struct opal_mbr_data) #define IOC_OPAL_ERASE_LR _IOW('p', 230, struct opal_session_info) #define IOC_OPAL_SECURE_ERASE_LR _IOW('p', 231, struct opal_session_info) +#define IOC_OPAL_MBR_STATUS _IOW('p', 232, struct opal_mbr_data) #endif /* _UAPI_SED_OPAL_H */