Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1192433ybl; Wed, 28 Aug 2019 10:58:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0tPbP11pqDnxCefA0VQlimKCbqEPQzcO+1ijtDoziC25hihyIn7UDvExgVxsU9EWpKPXM X-Received: by 2002:aa7:9d07:: with SMTP id k7mr6097286pfp.94.1567015129708; Wed, 28 Aug 2019 10:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567015129; cv=none; d=google.com; s=arc-20160816; b=DKC9o77BtSlhM58NfED58g8DuaNSUpEbzFyQ+Ww6qX+IctTn49kQ8CXejsbpJYAEp8 AHOWTNZQSpb41Opx3y5CS9q9AY1PBoOIb1dL50p6VbSx7RWTfpEQvnkYZb3BV3EET83A OVi0FRd7EOvzcs3pLkCMFlsHFMboR5rpzPCl+yossC5GvyySHGnBYnobXZbKXLCbTW85 75YW8+vMp6QfSk9m2n64D35s7JnvdFgCW/9jfDDTEJd3qWrLz3xLg8bK34DlH9/GN3XR 3O4MII8qSTEAgGiGvbDjsR5dRd+1foC6KNOgUAUzRbpT9pWeMjWMp3jEB+N9Buh7ODPl ZY+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=WtGGRa4ikceSi7oeZjlZgk+dQ+zb0nl/Qo8Q6pUI06E=; b=XQxcDxJWlfn2BiScE8Dr9Yp5y7JoBgb+ulCmk3RwEMeMZAKN55G9yHXpcG8bYsb76a oCMS12f/Ad9vyqhO2LB78XKyQ5JdZKKB8yYMJdGC9KNixoFg2/UButOBOcJ+BeZqQOXp ytjiI9Xhbh8DycEdUbCpfDAUIwa0RgQ3ozB1OzDpObwGcWZTErcFdIlofEDUVisdzr+e nFEVZXrLtKYh8eZU6mo2MAlVMU/tIrauKRqBfRS2fay6ay1AvAG84JKnD1HJrSsTc8d4 9LUK2rZECVo6O8+yJDFR8aveLVMQ/p9OGx7LfW4hUJU7TTJQOrRGPIl/5Q/EHJdsRsCL Naaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h64si2650190pge.208.2019.08.28.10.58.33; Wed, 28 Aug 2019 10:58:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbfH1R5E (ORCPT + 99 others); Wed, 28 Aug 2019 13:57:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47789 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbfH1R5E (ORCPT ); Wed, 28 Aug 2019 13:57:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8355315C01C; Wed, 28 Aug 2019 17:57:03 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D8955C21E; Wed, 28 Aug 2019 17:57:03 +0000 (UTC) From: Jeff Moyer To: Dan Williams Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] libnvdimm/security: Tighten scope of nvdimm->busy vs security operations References: <156686728950.184120.5188743631586996901.stgit@dwillia2-desk3.amr.corp.intel.com> <156686729996.184120.3458026302402493937.stgit@dwillia2-desk3.amr.corp.intel.com> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Wed, 28 Aug 2019 13:57:02 -0400 In-Reply-To: <156686729996.184120.3458026302402493937.stgit@dwillia2-desk3.amr.corp.intel.com> (Dan Williams's message of "Mon, 26 Aug 2019 17:55:00 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 28 Aug 2019 17:57:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dan Williams writes: > An attempt to freeze DIMMs currently runs afoul of default blocking of > all security operations in the entry to the 'store' routine for the > 'security' sysfs attribute. > > The blanket blocking of all security operations while the DIMM is in > active use in a region is too restrictive. The only security operations > that need to be aware of the ->busy state are those that mutate the > state of data, i.e. erase and overwrite. > > Refactor the ->busy checks to be applied at the entry common entry point > in __security_store() rather than each of the helper routines to enable > freeze to be run regardless of busy state. > > Reviewed-by: Dave Jiang > Signed-off-by: Dan Williams Reviewed-by: Jeff Moyer > --- > drivers/nvdimm/dimm_devs.c | 33 ++++++++++++++++----------------- > drivers/nvdimm/security.c | 10 ---------- > 2 files changed, 16 insertions(+), 27 deletions(-) > > diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c > index 53330625fe07..d837cb9be83d 100644 > --- a/drivers/nvdimm/dimm_devs.c > +++ b/drivers/nvdimm/dimm_devs.c > @@ -424,9 +424,6 @@ static ssize_t __security_store(struct device *dev, const char *buf, size_t len) > unsigned int key, newkey; > int i; > > - if (atomic_read(&nvdimm->busy)) > - return -EBUSY; > - > rc = sscanf(buf, "%"__stringify(SEC_CMD_SIZE)"s" > " %"__stringify(KEY_ID_SIZE)"s" > " %"__stringify(KEY_ID_SIZE)"s", > @@ -451,23 +448,25 @@ static ssize_t __security_store(struct device *dev, const char *buf, size_t len) > } else if (i == OP_DISABLE) { > dev_dbg(dev, "disable %u\n", key); > rc = nvdimm_security_disable(nvdimm, key); > - } else if (i == OP_UPDATE) { > - dev_dbg(dev, "update %u %u\n", key, newkey); > - rc = nvdimm_security_update(nvdimm, key, newkey, NVDIMM_USER); > - } else if (i == OP_ERASE) { > - dev_dbg(dev, "erase %u\n", key); > - rc = nvdimm_security_erase(nvdimm, key, NVDIMM_USER); > + } else if (i == OP_UPDATE || i == OP_MASTER_UPDATE) { > + dev_dbg(dev, "%s %u %u\n", ops[i].name, key, newkey); > + rc = nvdimm_security_update(nvdimm, key, newkey, i == OP_UPDATE > + ? NVDIMM_USER : NVDIMM_MASTER); > + } else if (i == OP_ERASE || i == OP_MASTER_ERASE) { > + dev_dbg(dev, "%s %u\n", ops[i].name, key); > + if (atomic_read(&nvdimm->busy)) { > + dev_dbg(dev, "Unable to secure erase while DIMM active.\n"); > + return -EBUSY; > + } > + rc = nvdimm_security_erase(nvdimm, key, i == OP_ERASE > + ? NVDIMM_USER : NVDIMM_MASTER); > } else if (i == OP_OVERWRITE) { > dev_dbg(dev, "overwrite %u\n", key); > + if (atomic_read(&nvdimm->busy)) { > + dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); > + return -EBUSY; > + } > rc = nvdimm_security_overwrite(nvdimm, key); > - } else if (i == OP_MASTER_UPDATE) { > - dev_dbg(dev, "master_update %u %u\n", key, newkey); > - rc = nvdimm_security_update(nvdimm, key, newkey, > - NVDIMM_MASTER); > - } else if (i == OP_MASTER_ERASE) { > - dev_dbg(dev, "master_erase %u\n", key); > - rc = nvdimm_security_erase(nvdimm, key, > - NVDIMM_MASTER); > } else > return -EINVAL; > > diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c > index 5862d0eee9db..2166e627383a 100644 > --- a/drivers/nvdimm/security.c > +++ b/drivers/nvdimm/security.c > @@ -334,11 +334,6 @@ int nvdimm_security_erase(struct nvdimm *nvdimm, unsigned int keyid, > || !nvdimm->sec.flags) > return -EOPNOTSUPP; > > - if (atomic_read(&nvdimm->busy)) { > - dev_dbg(dev, "Unable to secure erase while DIMM active.\n"); > - return -EBUSY; > - } > - > rc = check_security_state(nvdimm); > if (rc) > return rc; > @@ -380,11 +375,6 @@ int nvdimm_security_overwrite(struct nvdimm *nvdimm, unsigned int keyid) > || !nvdimm->sec.flags) > return -EOPNOTSUPP; > > - if (atomic_read(&nvdimm->busy)) { > - dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); > - return -EBUSY; > - } > - > if (dev->driver == NULL) { > dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); > return -EINVAL; > > _______________________________________________ > Linux-nvdimm mailing list > Linux-nvdimm@lists.01.org > https://lists.01.org/mailman/listinfo/linux-nvdimm