From patchwork Fri May 26 03:33:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F0CC7EE2F for ; Fri, 26 May 2023 04:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233019AbjEZEHb (ORCPT ); Fri, 26 May 2023 00:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbjEZEH2 (ORCPT ); Fri, 26 May 2023 00:07:28 -0400 Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B56D513D for ; Thu, 25 May 2023 21:07:26 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id EBAE25C1EC1; Fri, 26 May 2023 04:07:25 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5812D5C2098; Fri, 26 May 2023 04:07:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074045; a=rsa-sha256; cv=none; b=6aAedEFqbZn4caQDeb5BF6ZXZUXMmt8d2Vpx1gTHevSBaVaH7msZlHenjsCZacNAwi+w77 BG2Q/r8Y2/l6eSwlsfpaePcOntjM+D8Ca7EK2mrJxXRMEVw/qSkstktDZoMKkgn6o90BP/ 0iwEizQg2dt5eaX8ouCNN0+rs82lro3FLxjdSub2Z2M+V42YPmBsNp38w0txUQ9FhjzsTW xbJtZ7C4m0c22VjxaCWC/jfl06IOqTL2NOaietCO4g2cVD0EtyG5IRfVaQzrtPPePJz2TT mvfh+QCgALzrhEE1/2/9ag2OVLAcOySsLECyupjBUZPZ8m2VERvN9IMEo7JWPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZDT4VoEtbPHgSTLCgWFCzT/wRnykxMJ/gJ2uAXppXHo=; b=79EObgZbQLKYh2FbDjONEENHRwjexQD8gZ8YBC52ZrqhIkXhUfmkWwS1oAJT/Cw5sGOhjy 62G2z5jLf6jc5WlEw4FULoPjZn2wKriRxCMZ5yVVGzDf9eOLqRuzO3BIgQ7z7sqoMl7fXu apbzagvBY27UxMQ+qUAcjn7izINUv9TwBd250EdVdAhTg3yGnKQL/eU5qloZcbAoiTjRTo 5FG3b2plrIrlVmOVT5SQfTIWL9jZGGwCEi/zAWIcdNmdOSf6sOlRQXLgaM/0sqY14QNwf1 ABUmJWJ93LE+aF3gfd32wbTXVBd1IDkc3isaMzYAVVaPLAcSPd5RM5HJ00ejXw== ARC-Authentication-Results: i=1; rspamd-7d4b855556-pn845; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Whispering-Shoe: 153aba085164f95e_1685074045744_806699063 X-MC-Loop-Signature: 1685074045744:727372571 X-MC-Ingress-Time: 1685074045744 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.46 (trex/6.8.1); Fri, 26 May 2023 04:07:25 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG43V29zCV; Thu, 25 May 2023 21:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074045; bh=ZDT4VoEtbPHgSTLCgWFCzT/wRnykxMJ/gJ2uAXppXHo=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=rixUbI8fhCifDOfrVKy3xvgZfT8+gGZNoUurBo6/3ITNepzud5cSCE+T3PQKO7v2c czlNIDj7fswSfrwxMiiNk8U6AXQcoDJ+WginHPaI+eG/WVq9Q4vGRLuBp8z5KrePqn fQdKE8jXunCbIdA+OGRHDT8YX0KgxGFBztIfGY08xmz8qEbEfOP7evpSX3WuM/4Pf/ l+8Ys+XwRKl3hGkUOK7VghBCnfqnDdb9ggHCBDQcATjsZc0o+cd6LuSB9kiX9fyrfF 7Qmb5V9lG7pYg7RKgGFJI6iq3sxo1eMQKTLezD6joHTxrNrZFVPFi27OdOauMy7dqG 0Y0k+givud65A== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 1/6] cxl/mem: Introduce security state sysfs file Date: Thu, 25 May 2023 20:33:39 -0700 Message-Id: <20230526033344.17167-2-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add a read-only sysfs file to display the security state of a device (currently only pmem): /sys/bus/cxl/devices/memX/security/state This introduces a cxl_security_state structure that is to be the placeholder for common CXL security features. Signed-off-by: Davidlohr Bueso Reviewed-by: Jonathan Cameron Reviewed-by: Fan Ni --- Documentation/ABI/testing/sysfs-bus-cxl | 10 ++++++ drivers/cxl/core/memdev.c | 46 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 11 ++++++ drivers/cxl/security.c | 3 ++ 4 files changed, 70 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 48ac0d911801..721a44d8a482 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -58,6 +58,16 @@ Description: affinity for this device. +What: /sys/bus/cxl/devices/memX/security/state +Date: June, 2023 +KernelVersion: v6.5 +Contact: linux-cxl@vger.kernel.org +Description: + (RO) Reading this file will display the CXL security state for + that device. Such states can be: 'disabled', or those available + only for persistent memory: 'locked', 'unlocked' or 'frozen'. + + What: /sys/bus/cxl/devices/*/devtype Date: June, 2021 KernelVersion: v5.14 diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 057a43267290..6e1d7d3610a2 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -107,6 +107,28 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(numa_node); +static ssize_t security_state_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + unsigned long state = cxlds->security.state; + + if (!(state & CXL_PMEM_SEC_STATE_USER_PASS_SET)) + return sysfs_emit(buf, "disabled\n"); + if (state & CXL_PMEM_SEC_STATE_FROZEN || + state & CXL_PMEM_SEC_STATE_MASTER_PLIMIT || + state & CXL_PMEM_SEC_STATE_USER_PLIMIT) + return sysfs_emit(buf, "frozen\n"); + if (state & CXL_PMEM_SEC_STATE_LOCKED) + return sysfs_emit(buf, "locked\n"); + else + return sysfs_emit(buf, "unlocked\n"); +} +static struct device_attribute dev_attr_security_state = + __ATTR(state, 0444, security_state_show, NULL); + static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd) { struct cxl_dev_state *cxlds = cxlmd->cxlds; @@ -352,6 +374,11 @@ static struct attribute *cxl_memdev_ram_attributes[] = { NULL, }; +static struct attribute *cxl_memdev_security_attributes[] = { + &dev_attr_security_state.attr, + NULL, +}; + static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, int n) { @@ -375,10 +402,16 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = { .attrs = cxl_memdev_pmem_attributes, }; +static struct attribute_group cxl_memdev_security_attribute_group = { + .name = "security", + .attrs = cxl_memdev_security_attributes, +}; + static const struct attribute_group *cxl_memdev_attribute_groups[] = { &cxl_memdev_attribute_group, &cxl_memdev_ram_attribute_group, &cxl_memdev_pmem_attribute_group, + &cxl_memdev_security_attribute_group, NULL, }; @@ -551,6 +584,15 @@ static const struct file_operations cxl_memdev_fops = { .llseek = noop_llseek, }; +static int cxl_memdev_security_init(struct cxl_memdev *cxlmd) +{ + struct cxl_dev_state *cxlds = cxlmd->cxlds; + + cxlds->security.state = 0; + + return 0; +} + struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) { struct cxl_memdev *cxlmd; @@ -579,6 +621,10 @@ struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) if (rc) goto err; + rc = cxl_memdev_security_init(cxlmd); + if (rc) + goto err; + rc = devm_add_action_or_reset(cxlds->dev, cxl_memdev_unregister, cxlmd); if (rc) return ERR_PTR(rc); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 1d8e81c87c6a..5329274b0076 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -260,6 +260,15 @@ struct cxl_poison_state { struct mutex lock; /* Protect reads of poison list */ }; +/** + * struct cxl_security_state - Device security state + * + * @state: state of last security operation + */ +struct cxl_security_state { + unsigned long state; +}; + /** * struct cxl_dev_state - The driver device state * @@ -297,6 +306,7 @@ struct cxl_poison_state { * @serial: PCIe Device Serial Number * @event: event log driver state * @poison: poison driver state info + * @security: device security state * @mbox_send: @dev specific transport for transmitting mailbox commands * * See section 8.2.9.5.2 Capacity Configuration and Label Storage for @@ -336,6 +346,7 @@ struct cxl_dev_state { struct cxl_event_state event; struct cxl_poison_state poison; + struct cxl_security_state security; struct rcuwait mbox_wait; int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd); diff --git a/drivers/cxl/security.c b/drivers/cxl/security.c index 4ad4bda2d18e..9da6785dfd31 100644 --- a/drivers/cxl/security.c +++ b/drivers/cxl/security.c @@ -34,6 +34,9 @@ static unsigned long cxl_pmem_get_security_flags(struct nvdimm *nvdimm, return 0; sec_out = le32_to_cpu(out.flags); + /* cache security state */ + cxlds->security.state = sec_out; + if (ptype == NVDIMM_MASTER) { if (sec_out & CXL_PMEM_SEC_STATE_MASTER_PASS_SET) set_bit(NVDIMM_SECURITY_UNLOCKED, &security_flags); From patchwork Fri May 26 03:33:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10C11C7EE23 for ; Fri, 26 May 2023 04:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232723AbjEZEHa (ORCPT ); Fri, 26 May 2023 00:07:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjEZEH2 (ORCPT ); Fri, 26 May 2023 00:07:28 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24275183 for ; Thu, 25 May 2023 21:07:27 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9A3F3101A19; Fri, 26 May 2023 04:07:26 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 141B310157F; Fri, 26 May 2023 04:07:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074046; a=rsa-sha256; cv=none; b=3vl3X0iIurvZHVHP3GmQYWTfg3CJU1LKVwfyBO2OSRw5sZmRGPgJrZUr1f9YHLrPghhspt qAPN0rdfaSUuvpSVmSUo6PHwA8GuQMVmuUS8nf5fSw9GqKnFWTn+8q/0gXQZKzVOP8iJip /g75YwFxgt13fDcWpjs1mZIzRiMZlW9wUGXw1GElkDT5L6Nf0cNC60172IUp6s9xdni0Yr Yn8QDyGjYg+4S0Yy3tEXODAJ+E6fVxziNqUmjXsaFEX7z10xQiDs/M6fAQv6OubB51XO9S hH+82GF7I/g7HKP6cQ2Q0p8nKmsBuxGEtkNIyI2OO3lv0wyyM8C9Uj1ynKn/uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vOnOye1HDT3dummA83nLeK3SCXz4EarHieWOzwkty7M=; b=NtgQE6t8ov7Y4sZGqimBX4BxBQoOY+DSQAA+rmwQCRckJwS4tuoGHa44CFFfuBuiUq6ryO 4PAv9LwpZOtTddghTWh1OtHGXyu2cY3gHSOFxUHv7cjKcC3ubgpBpGuwIvcHevhfAJU+du GjGDw7JuC3SjAC83qdCZAzM4o+HCA0XGMrhZJX3o+/FkydTnrbW/dfVVWBBGt4sM9mKAYO nQmwWmsGj6bx7ITK+8QdhVLh7WRehR052au3NsnwRy5wdr3fgww4sFJwdiG/068rNIgTAQ pdypQqBwZXSgPOt296nus3xIFQHMTUxgxyNMyv4B9d5BUxi1c+35hk0CQsgZRA== ARC-Authentication-Results: i=1; rspamd-7d4b855556-8m4kk; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Trade-Eyes: 1f54494379320c04_1685074046395_1891032754 X-MC-Loop-Signature: 1685074046394:3837721383 X-MC-Ingress-Time: 1685074046394 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.46 (trex/6.8.1); Fri, 26 May 2023 04:07:26 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG52fqLz36; Thu, 25 May 2023 21:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074045; bh=vOnOye1HDT3dummA83nLeK3SCXz4EarHieWOzwkty7M=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=facGoaUJa8mVq4ilsaygtz15nn27xnQLXGzqt2dpHmz+cpy5aqWRK+gmHBYE7ZNsR 3ypD8RQWytnfcvpArk6uP8zqolqb+v6p0F/HsnBrqNCZEoj3hJm/E/A2NaY0Tmlc6Y uaY0uyD/q5LounuGbEmOnxxSOBco/Rp9b5pNGoyw78mAxTQG5DgzkQKELE1Ids2JLy 8i3xHjwYx04nzSmu+s0rJ8tmqkZvdT1KvjAJFTRRWbwXQYyqdXNoIQTlQnuW+VQs/o qg8h3liAMPAdwwKfzC1xuWUBZkiYj4gRJc3tSEYsH8ZqXi/lvZzvN1mBL530V4A95F eFIE1ffXujCpQ== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 2/6] cxl/mbox: Add sanitation handling machinery Date: Thu, 25 May 2023 20:33:40 -0700 Message-Id: <20230526033344.17167-3-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Sanitation is by definition a device-monopolizing operation, and thus the timeslicing rules for other background commands do not apply. As such handle this special case asynchronously and return immediately. Subsequent changes will allow completion to be pollable from userspace via a sysfs file interface. For devices that don't support interrupts for notifying background command completion, self-poll with the caveat that the poller can be out of sync with the ready hardware, and therefore care must be taken to not allow any new commands to go through until the poller sees the hw completion. The poller takes the mbox_mutex to stabilize the flagging, minimizing any runtime overhead in the send path to check for 'sanitize_tmo' for uncommon poll scenarios. This flag also serves for sanitation (the only user of async polling) to know when to queue work or simply rely on irqs. The irq case is much simpler as hardware will serialize/error appropriately. Signed-off-by: Davidlohr Bueso Reviewed-by: Dave Jiang --- drivers/cxl/core/memdev.c | 10 +++++ drivers/cxl/cxlmem.h | 10 +++++ drivers/cxl/pci.c | 83 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 4 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 6e1d7d3610a2..02763e83545c 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -460,11 +460,21 @@ void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cm } EXPORT_SYMBOL_NS_GPL(clear_exclusive_cxl_commands, CXL); +static void cxl_memdev_security_shutdown(struct device *dev) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + + if (cxlds->security.poll_tmo_secs != -1) + cancel_delayed_work_sync(&cxlds->security.poll_dwork); +} + static void cxl_memdev_shutdown(struct device *dev) { struct cxl_memdev *cxlmd = to_cxl_memdev(dev); down_write(&cxl_memdev_rwsem); + cxl_memdev_security_shutdown(dev); cxlmd->cxlds = NULL; up_write(&cxl_memdev_rwsem); } diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 5329274b0076..02ec68f97de2 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -264,9 +264,18 @@ struct cxl_poison_state { * struct cxl_security_state - Device security state * * @state: state of last security operation + * @poll_tmo_secs: polling timeout + * @poll_dwork: polling work item + * + * Polling (sanitation) is only used when device mbox irqs are not + * supported. As such, @poll_tmo_secs == -1 indicates that polling + * is disabled. Otherwise, when enabled, @poll_tmo_secs is maxed + * at 15 minutes and serialized by the mbox_mutex. */ struct cxl_security_state { unsigned long state; + int poll_tmo_secs; + struct delayed_work poll_dwork; }; /** @@ -380,6 +389,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303, CXL_MBOX_OP_SCAN_MEDIA = 0x4304, CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305, + CXL_MBOX_OP_SANITIZE = 0x4400, CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500, CXL_MBOX_OP_SET_PASSPHRASE = 0x4501, CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502, diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index a78e40e6d0e0..a0d93719ab18 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -115,16 +115,52 @@ static bool cxl_mbox_background_complete(struct cxl_dev_state *cxlds) static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) { + u64 reg; + u16 opcode; struct cxl_dev_id *dev_id = id; struct cxl_dev_state *cxlds = dev_id->cxlds; - /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ - if (cxl_mbox_background_complete(cxlds)) - rcuwait_wake_up(&cxlds->mbox_wait); + if (!cxl_mbox_background_complete(cxlds)) + goto done; + reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); + opcode = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); + if (opcode == CXL_MBOX_OP_SANITIZE) { + dev_dbg(cxlds->dev, "Sanitation operation ended\n"); + } else { + /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ + rcuwait_wake_up(&cxlds->mbox_wait); + } +done: return IRQ_HANDLED; } +/* + * Sanitation operation polling mode. + */ +static void cxl_mbox_sanitize_work(struct work_struct *work) +{ + struct cxl_dev_state *cxlds; + + cxlds = container_of(work, + struct cxl_dev_state, security.poll_dwork.work); + + mutex_lock(&cxlds->mbox_mutex); + if (cxl_mbox_background_complete(cxlds)) { + cxlds->security.poll_tmo_secs = 0; + put_device(cxlds->dev); + + dev_dbg(cxlds->dev, "Sanitation operation ended\n"); + } else { + int timeout = cxlds->security.poll_tmo_secs + 10; + + cxlds->security.poll_tmo_secs = min(15 * 60, timeout); + queue_delayed_work(system_wq, &cxlds->security.poll_dwork, + timeout * HZ); + } + mutex_unlock(&cxlds->mbox_mutex); +} + /** * __cxl_pci_mbox_send_cmd() - Execute a mailbox command * @cxlds: The device state to communicate with. @@ -185,6 +221,16 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, return -EBUSY; } + /* + * With sanitize polling, hardware might be done and the poller still + * not be in sync. Ensure no new command comes in until so. Keep the + * hardware semantics and only allow device health status. + */ + if (unlikely(cxlds->security.poll_tmo_secs > 0)) { + if (mbox_cmd->opcode != CXL_MBOX_OP_GET_HEALTH_INFO) + return -EBUSY; + } + cmd_reg = FIELD_PREP(CXLDEV_MBOX_CMD_COMMAND_OPCODE_MASK, mbox_cmd->opcode); if (mbox_cmd->size_in) { @@ -233,11 +279,34 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, */ if (mbox_cmd->return_code == CXL_MBOX_CMD_RC_BACKGROUND) { u64 bg_status_reg; - int i, timeout = mbox_cmd->poll_interval_ms; + int i, timeout; + + /* + * Sanitation is a special case which monopolizes the device + * and cannot be timesliced. Handle asynchronously instead, + * and allow userspace to poll(2) for completion. + */ + if (mbox_cmd->opcode == CXL_MBOX_OP_SANITIZE) { + if (cxlds->security.poll_tmo_secs != -1) { + /* hold the device throughout */ + get_device(cxlds->dev); + + /* give first timeout a second */ + timeout = 1; + cxlds->security.poll_tmo_secs = timeout; + queue_delayed_work(system_wq, + &cxlds->security.poll_dwork, + timeout * HZ); + } + + dev_dbg(dev, "Sanitation operation started\n"); + goto success; + } dev_dbg(dev, "Mailbox background operation (0x%04x) started\n", mbox_cmd->opcode); + timeout = mbox_cmd->poll_interval_ms; for (i = 0; i < mbox_cmd->poll_count; i++) { if (rcuwait_wait_event_timeout(&cxlds->mbox_wait, cxl_mbox_background_complete(cxlds), @@ -268,6 +337,7 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_dev_state *cxlds, return 0; /* completed but caller must check return_code */ } +success: /* #7 */ cmd_reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_CMD_OFFSET); out_len = FIELD_GET(CXLDEV_MBOX_CMD_PAYLOAD_LENGTH_MASK, cmd_reg); @@ -376,10 +446,15 @@ static int cxl_pci_setup_mailbox(struct cxl_dev_state *cxlds) ctrl |= CXLDEV_MBOX_CTRL_BG_CMD_IRQ; writel(ctrl, cxlds->regs.mbox + CXLDEV_MBOX_CTRL_OFFSET); + /* flag that irqs are enabled */ + cxlds->security.poll_tmo_secs = -1; return 0; } mbox_poll: + cxlds->security.poll_tmo_secs = 0; + INIT_DELAYED_WORK(&cxlds->security.poll_dwork, + cxl_mbox_sanitize_work); dev_dbg(cxlds->dev, "Mailbox interrupts are unsupported"); return 0; } From patchwork Fri May 26 03:33:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48EFBC77B7C for ; Fri, 26 May 2023 04:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229479AbjEZEHh (ORCPT ); Fri, 26 May 2023 00:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233859AbjEZEHe (ORCPT ); Fri, 26 May 2023 00:07:34 -0400 Received: from crane.ash.relay.mailchannels.net (crane.ash.relay.mailchannels.net [23.83.222.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42844183 for ; Thu, 25 May 2023 21:07:30 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 42FA35C10D1; Fri, 26 May 2023 04:07:27 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C94575C2120; Fri, 26 May 2023 04:07:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074046; a=rsa-sha256; cv=none; b=tLwSy2NGGf4K1Ske0czpqbUsPx4+cifO6UVkcNfJTiKWCUgKT1RKo9wdQH1ER9iaITEiVo +5AXiwG8PeGhCsZX3Xzd3xsFRUE3crVI4dr6spgxxn+S9ZxI68YrNtwEwaFUEDef1r1HIV DGr4IevYY3YfjhS1t2S4J+DKTNBz3dgH97JMfXo6jiRfIqell0/e59Ow6zR04+mg1Tu9G8 aq87lf0c0EQ1nNRDWRObfJZ5y3T2luUUbQWh1rAlqRuzOvvTP5KxtMZNbrUF42FgsiYS/u XG4LRJc/VfdMSt+3AEmE5XNX0u+gypdsNysKLmupQaeTCQHWa+V5uT9kS47wow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+KMvGNkoB7GuKKdj8iuHLcxT/SxAHJ6rYY5I2PIiZV0=; b=2rk7kfm5NyEYwa9AmtSiTxar1V1puBJCZz0rmCgFf8McNQRnaakA4snvZtFdNb8pNJfInl naKZKlbRed9Jc+9X8W+k1MFkboqaKazeSGdA4qQNkWoQ34vWmDeXPPLGfcBZQyuS9tlCWU OnV0hTlBG+MlGhVWCJFH7jf3IGI5GbsOHI5sfjpGS0rjZFxJlxwm23j51Z7L6UN3MqolAi YHHOzt1PxX5GHTMKWpDXr/YrYPE4C+mB2h5bzTjNjakIBVZKqYZoEUfYsoNyvdHJYcn9Nk ZyP/sYFx2qesBoftmLGqDmXF59KY8Hytwa6vkNvHmGlsqs6kFo68JNDPoG3WDA== ARC-Authentication-Results: i=1; rspamd-7d4b855556-z6wlw; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Trade-Irritate: 13e5771d36187fa8_1685074047135_2875938992 X-MC-Loop-Signature: 1685074047135:2811523810 X-MC-Ingress-Time: 1685074047135 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.30.34 (trex/6.8.1); Fri, 26 May 2023 04:07:27 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG60qW7zCV; Thu, 25 May 2023 21:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074046; bh=+KMvGNkoB7GuKKdj8iuHLcxT/SxAHJ6rYY5I2PIiZV0=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=UA977Cwe1SwLlpFhtoVfWpYSdahjfiR8p7wkXEgPegaLQcfsKWjTuskeKDEimK6Lo IWijZ0YLw1oB7L2t1L0E48PMBAMuB7Ayn3XJVHpe35Tv0BPMrlM30LdzPIIXYATg0W 4olIPscMZnsjRXTH2LccWS/UDbRUveUJjOLqZhhwzWFzlbcqnw9ixDMHh77tP00jmB B5dVXMlQuEB4ziNV+f/HfZrGgVvSlEF1CNuZordVK+0b3oJcABPd5LGYHXvAKunvg4 MwuddFGlFKnLk4138b6kKk/js9D3wQmD42szyBhNK1wCddYUHbm+BrocbxQJ2wP8Ja W0xCV/SBRGtFQ== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 3/6] cxl/mem: Wire up Sanitation support Date: Thu, 25 May 2023 20:33:41 -0700 Message-Id: <20230526033344.17167-4-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Implement support for CXL 3.0 8.2.9.8.5.1 Sanitize. This is done by adding a security/sanitize' memdev sysfs file, which is poll(2)-capable for completion. Unlike all other background commands, this is the only operation that is special and monopolizes the device for long periods of time. In addition to the traditional pmem security requirements, all regions must also be offline in order to perform the operation. This permits avoiding explicit global CPU cache management, relying instead on attach_target() setting CXL_REGION_F_INCOHERENT upon reconnect. The expectation is that userspace can use it such as: cxl disable-memdev memX echo 1 > /sys/bus/cxl/devices/memX/security/sanitize cxl wait-sanitize memX cxl enable-memdev memX Signed-off-by: Davidlohr Bueso Reviewed-by: Dave Jiang with above update. Reviewed-by: Jonathan Cameron --- Documentation/ABI/testing/sysfs-bus-cxl | 21 ++++++++- drivers/cxl/core/mbox.c | 55 ++++++++++++++++++++++++ drivers/cxl/core/memdev.c | 57 ++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 4 ++ drivers/cxl/pci.c | 5 +++ 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 721a44d8a482..5753cba98692 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -64,8 +64,25 @@ KernelVersion: v6.5 Contact: linux-cxl@vger.kernel.org Description: (RO) Reading this file will display the CXL security state for - that device. Such states can be: 'disabled', or those available - only for persistent memory: 'locked', 'unlocked' or 'frozen'. + that device. Such states can be: 'disabled', 'sanitize', when + a sanitation is currently underway; or those available only + for persistent memory: 'locked', 'unlocked' or 'frozen'. This + sysfs entry is select/poll capable from userspace to notify + upon completion of a sanitize operation. + + +What: /sys/bus/cxl/devices/memX/security/sanitize +Date: June, 2023 +KernelVersion: v6.5 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) Write a boolean 'true' string value to this attribute to + sanitize the device to securely re-purpose or decommission it. + This is done by ensuring that all user data and meta-data, + whether it resides in persistent capacity, volatile capacity, + or the LSA, is made permanently unavailable by whatever means + is appropriate for the media type. This functionality requires + the device to be not be actively decoding any HPA ranges. What: /sys/bus/cxl/devices/*/devtype diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 5993261e3e08..51c64829f20a 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1075,6 +1075,61 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds) } EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL); +/** + * cxl_mem_sanitize() - Send a sanitation command to the device. + * @cxlds: The device data for the operation + * @cmd: The specific sanitation command opcode + * + * Return: 0 if the command was executed successfully, regardless of + * whether or not the actual security operation is done in the background, + * such as for the Sanitize case. + * Error return values can be the result of the mailbox command, -EINVAL + * when security requirements are not met or invalid contexts. + * + * See CXL 3.0 @8.2.9.8.5.1 Sanitize and @8.2.9.8.5.2 Secure Erase. + */ +int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd) +{ + int rc; + u32 sec_out = 0; + struct cxl_get_security_output { + __le32 flags; + } out; + struct cxl_mbox_cmd sec_cmd = { + .opcode = CXL_MBOX_OP_GET_SECURITY_STATE, + .payload_out = &out, + .size_out = sizeof(out), + }; + struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd }; + + if (cmd != CXL_MBOX_OP_SANITIZE) + return -EINVAL; + + rc = cxl_internal_send_cmd(cxlds, &sec_cmd); + if (rc < 0) { + dev_err(cxlds->dev, "Failed to get security state : %d", rc); + return rc; + } + + /* + * Prior to using these commands, any security applied to + * the user data areas of the device shall be DISABLED (or + * UNLOCKED for secure erase case). + */ + sec_out = le32_to_cpu(out.flags); + if (sec_out & CXL_PMEM_SEC_STATE_USER_PASS_SET) + return -EINVAL; + + rc = cxl_internal_send_cmd(cxlds, &mbox_cmd); + if (rc < 0) { + dev_err(cxlds->dev, "Failed to sanitize device : %d", rc); + return rc; + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_sanitize, CXL); + static int add_dpa_res(struct device *dev, struct resource *parent, struct resource *res, resource_size_t start, resource_size_t size, const char *type) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 02763e83545c..90f23e53d483 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2020 Intel Corporation. */ +#include #include #include #include @@ -114,6 +115,12 @@ static ssize_t security_state_show(struct device *dev, struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_dev_state *cxlds = cxlmd->cxlds; unsigned long state = cxlds->security.state; + u64 reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); + u32 pct = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_PCT_MASK, reg); + u16 cmd = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); + + if (cmd == CXL_MBOX_OP_SANITIZE && pct != 100) + return sysfs_emit(buf, "sanitize\n"); if (!(state & CXL_PMEM_SEC_STATE_USER_PASS_SET)) return sysfs_emit(buf, "disabled\n"); @@ -129,6 +136,33 @@ static ssize_t security_state_show(struct device *dev, static struct device_attribute dev_attr_security_state = __ATTR(state, 0444, security_state_show, NULL); +static ssize_t security_sanitize_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_port *port = dev_get_drvdata(&cxlmd->dev); + ssize_t rc; + bool sanitize; + + if (kstrtobool(buf, &sanitize) || !sanitize) + return -EINVAL; + + if (!port || !is_cxl_endpoint(port)) + return -EINVAL; + + /* ensure no regions are mapped to this memdev */ + if (port->commit_end != -1) + return -EBUSY; + + rc = cxl_mem_sanitize(cxlds, CXL_MBOX_OP_SANITIZE); + + return rc ? rc : len; +} +static struct device_attribute dev_attr_security_sanitize = + __ATTR(sanitize, 0200, NULL, security_sanitize_store); + static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd) { struct cxl_dev_state *cxlds = cxlmd->cxlds; @@ -376,6 +410,7 @@ static struct attribute *cxl_memdev_ram_attributes[] = { static struct attribute *cxl_memdev_security_attributes[] = { &dev_attr_security_state.attr, + &dev_attr_security_sanitize.attr, NULL, }; @@ -594,13 +629,33 @@ static const struct file_operations cxl_memdev_fops = { .llseek = noop_llseek, }; +static void put_sanitize(void *data) +{ + struct cxl_dev_state *cxlds = data; + + sysfs_put(cxlds->security.sanitize_node); +} + static int cxl_memdev_security_init(struct cxl_memdev *cxlmd) { struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct device *dev = &cxlmd->dev; + struct kernfs_node *sec; cxlds->security.state = 0; + sec = sysfs_get_dirent(dev->kobj.sd, "security"); + if (!sec) { + dev_err(dev, "sysfs_get_dirent 'security' failed\n"); + return -ENODEV; + } + cxlds->security.sanitize_node = sysfs_get_dirent(sec, "state"); + sysfs_put(sec); + if (!cxlds->security.sanitize_node) { + dev_err(dev, "sysfs_get_dirent 'state' failed\n"); + return -ENODEV; + } - return 0; + return devm_add_action_or_reset(cxlds->dev, put_sanitize, cxlds); } struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 02ec68f97de2..408ec33c8480 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -266,6 +266,7 @@ struct cxl_poison_state { * @state: state of last security operation * @poll_tmo_secs: polling timeout * @poll_dwork: polling work item + * @sanitize_node: sanitation sysfs file to notify * * Polling (sanitation) is only used when device mbox irqs are not * supported. As such, @poll_tmo_secs == -1 indicates that polling @@ -276,6 +277,7 @@ struct cxl_security_state { unsigned long state; int poll_tmo_secs; struct delayed_work poll_dwork; + struct kernfs_node *sanitize_node; }; /** @@ -750,6 +752,8 @@ static inline void cxl_mem_active_dec(void) } #endif +int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd); + struct cxl_hdm { struct cxl_component_regs regs; unsigned int decoder_count; diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index a0d93719ab18..195c4267d3db 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -126,6 +126,9 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); opcode = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); if (opcode == CXL_MBOX_OP_SANITIZE) { + if (cxlds->security.sanitize_node) + sysfs_notify_dirent(cxlds->security.sanitize_node); + dev_dbg(cxlds->dev, "Sanitation operation ended\n"); } else { /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ @@ -149,6 +152,8 @@ static void cxl_mbox_sanitize_work(struct work_struct *work) if (cxl_mbox_background_complete(cxlds)) { cxlds->security.poll_tmo_secs = 0; put_device(cxlds->dev); + if (cxlds->security.sanitize_node) + sysfs_notify_dirent(cxlds->security.sanitize_node); dev_dbg(cxlds->dev, "Sanitation operation ended\n"); } else { From patchwork Fri May 26 03:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB3B5C7EE2F for ; Fri, 26 May 2023 04:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233414AbjEZEHh (ORCPT ); Fri, 26 May 2023 00:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233844AbjEZEHe (ORCPT ); Fri, 26 May 2023 00:07:34 -0400 Received: from crane.ash.relay.mailchannels.net (crane.ash.relay.mailchannels.net [23.83.222.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10CB212F for ; Thu, 25 May 2023 21:07:31 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 02CC176142F; Fri, 26 May 2023 04:07:28 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 7A8BC76107A; Fri, 26 May 2023 04:07:27 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074047; a=rsa-sha256; cv=none; b=z7Cl/se0ATLL0tVjaF4mDQ4iXpr0VhslkYDB/ne90jPzq2GcGe36Re7HK4NR40Rcq3CaAt ZKfdMD90f/3reycfkpdcH3DYJIij95xulkC70/5ugLrtvkT9y0+/20toTD4zWs8puwR9ZQ CsjzE/IgAklAfATkIRL2mvo+jd3GsacbVWjzBE1YKh3tBYRvjK2wLuIPPspYDI2CwL+qca HFwsj+JtTkG/hrUgm3SaEH4xrL19RkscSm2LtVlbBIJai0dEi4msv7zHj0MQgZR8dO77uT NlDjtzVWRn28JjzecjnFDawIY4QVYEYgnD+mFcNWda64smwpVbvR0U7n5uByWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EzW8plH9Cn2oCq96jajWEloNSjbDvAL6TKoIJ9/5lqE=; b=9/6LnWpy59IwN+5hqJCht1bFQj4Z+0xj2CH6vHYe86lOolyaHXS86qkItSVtb/bdeJ+s4i 7elc8eFxQcEtKQS06OEGLkiItmSepfkqr+hp515uLKjcQufSIt2wuMfaYRa6GDXAgfFZ56 3nDNoEsdxIL7Q1Q1HEUnTK11I9RPytIImyqVqwaOXyl6t/0rUoTxPBLCrf5tJAdxipOlIL sltFd4HoE4kIgtiT/7i8hiHIVqOWn4sgdn5BoeF4xJ8xlSuRgzoO7JUi/pkMSBujcPKq/j 8JO+fMBPNjD0EBySxgVQ9Sz3rhaYqltmXLxdOm2J8rEKL4rRM3lHydGLz/UM6w== ARC-Authentication-Results: i=1; rspamd-7d4b855556-8m4kk; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Imminent-Tangy: 301fc9055c7e297a_1685074047795_3860556627 X-MC-Loop-Signature: 1685074047795:2832264115 X-MC-Ingress-Time: 1685074047795 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.59.37 (trex/6.8.1); Fri, 26 May 2023 04:07:27 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG65rlgz36; Thu, 25 May 2023 21:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074047; bh=EzW8plH9Cn2oCq96jajWEloNSjbDvAL6TKoIJ9/5lqE=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=OntKWziWefy5oOwgp1p78TDXfP8mnZ0zbX71f1liWhGg2xfl9OLTanQAh+vRENGZg 9yicYevJbFlHoPip9hi0YPdrwUGI0RtEqub9/YR8NZw2ruh2PybdrZ6ZkgRmqZFxU0 x2CmY0Eq7OUdJOS1Y9sMrWfciWYhrNXd9gzj2K8kwT31ZmmktlUx7U5ajruVkUJ2x4 4ALfwJ4VkAnWlL9n8T2dolUyLrl+LeGedf++dVLhTZFTPO3FiBbZ/gf+30MePOuE1O /klIXOTWChxMNqGROzVbeGKcu67moB8izTslLESiWHcBPEDrMjbWtJQercflHnu6Ag VA4hNBjn2qe7A== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 4/6] cxl/test: Add Sanitize opcode support Date: Thu, 25 May 2023 20:33:42 -0700 Message-Id: <20230526033344.17167-5-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add support to emulate the "Sanitize" operation, without incurring in the background. Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Signed-off-by: Davidlohr Bueso --- tools/testing/cxl/test/mem.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index 34b48027b3de..faa484ea5b0b 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -535,6 +535,28 @@ static int mock_partition_info(struct cxl_dev_state *cxlds, return 0; } +static int mock_sanitize(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) +{ + struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev); + + if (cmd->size_in != 0) + return -EINVAL; + + if (cmd->size_out != 0) + return -EINVAL; + + if (mdata->security_state & CXL_PMEM_SEC_STATE_USER_PASS_SET) { + cmd->return_code = CXL_MBOX_CMD_RC_SECURITY; + return -ENXIO; + } + if (mdata->security_state & CXL_PMEM_SEC_STATE_LOCKED) { + cmd->return_code = CXL_MBOX_CMD_RC_SECURITY; + return -ENXIO; + } + + return 0; /* assume less than 2 secs, no bg */ +} + static int mock_get_security_state(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) { @@ -1153,6 +1175,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd * case CXL_MBOX_OP_GET_HEALTH_INFO: rc = mock_health_info(cxlds, cmd); break; + case CXL_MBOX_OP_SANITIZE: + rc = mock_sanitize(cxlds, cmd); + break; case CXL_MBOX_OP_GET_SECURITY_STATE: rc = mock_get_security_state(cxlds, cmd); break; From patchwork Fri May 26 03:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD6EEC77B7C for ; Fri, 26 May 2023 04:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230260AbjEZEHd (ORCPT ); Fri, 26 May 2023 00:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjEZEHb (ORCPT ); Fri, 26 May 2023 00:07:31 -0400 Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E88B12F for ; Thu, 25 May 2023 21:07:29 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C8B382613EE; Fri, 26 May 2023 04:07:28 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 464B1260E4C; Fri, 26 May 2023 04:07:28 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074048; a=rsa-sha256; cv=none; b=rSaKtNu+QhKb4UuGoMJhHISIDv1uO8anf0YcO9oVzZZkb1Wsr0ZmhFAeByaFYizuGVBDse hf45LZ9GCfI/SJVbw0jDAw0j/tTtB2nwAA9djiECI3V14XQJxQ+Jye1gh5qhUlxvpvO0fc yAwASi5cYmj8NbZvM6Pi5zL/R4ehm4vGyd9LSawpcylfLEEm43Dp8eeYtVvVPr8lU9RDBx 0GOyQJOjlPPhxZNeulhTenxuc6bLixXPjSsDqY1HljWU8I2ObgiapWdJ9X/dmsG+FclmNr b1YrGvjEe6FgiRpftKvvuVfx8iYzvH2A8fb4J7l9oS3TbMYNw6aNU5OL/RIv9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hlJe/5lHkRV4ma+TL2Wmt8zinlWFRKi30n4a+pYrJL0=; b=2WpSGAOfxCejtbB7cmwnT17NgSikqpciMHyxxiQFFU5+vqtJ6xb26KSGvKyZ8yRY2LWopq lQ5g+Xqxs+AqGmLcUXVYMT2OsMbuYYteZhR06Fp4ysy7Y6iaDNbPquhGFxbCiWnH2ruCWm h2a4clt72ouSbthiTbLM62XSfxGRs12gC5FTizX+/KsKLWZmHwmkUO/TMtV6hvbnPuTdut Jj7z6w/4KBSFUImvEm/NgcC5HqsPMv+q9o+01sisvyMmA3K0591GibvtEUEs36KYSMGhBp KqFZ7uvFOiuAtd6rEi08QAY7atGbz4blIAH+t/azUA1RT7SJLSdqMoexVZ1a5w== ARC-Authentication-Results: i=1; rspamd-7d4b855556-pn845; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Relation-Skirt: 7adc57a2547ed57a_1685074048587_2408068052 X-MC-Loop-Signature: 1685074048587:1264517250 X-MC-Ingress-Time: 1685074048587 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.46 (trex/6.8.1); Fri, 26 May 2023 04:07:28 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG73k63zCV; Thu, 25 May 2023 21:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074048; bh=hlJe/5lHkRV4ma+TL2Wmt8zinlWFRKi30n4a+pYrJL0=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=HAtXlcNB72lkVFRCOygjFj8ltLHJF/58aaNcsU9hhzC2ijMrr9YX+/2Mw9+EfJo8B H/FASxI6jRqUyvnIxLwAkLo5SXBE2MC6ZUJDDZefe8t8LHpirbcvx4BhQmkdEewmDo j8577lFd/N0L6qB92qhqubEJYrDyoMR7YyMf94zWswypM8ZPRZS4Frp4HtM4lhIa8s g2LAJzbj2gSTN+bLyzdK8GxXAFMH2LQvD9AU3P4tUXJ7U5jVvbWzq2IxU9uG4xe+/U mce0gHSJ00xntG6j3Wr5vxzekc4YWauI8MuBBfLWBrXuH4WXDRxzOes3MeGKziONZU V+kxKJmYxucPw== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 5/6] cxl/mem: Support Secure Erase Date: Thu, 25 May 2023 20:33:43 -0700 Message-Id: <20230526033344.17167-6-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Implement support for the non-pmem exclusive secure erase, per CXL specs. Create a write-only 'security/erase' sysfs file to perform the requested operation. As with the sanitation this requires the device being offline and thus no active HPA-DPA decoding. The expectation is that userspace can use it such as: cxl disable-memdev memX echo 1 > /sys/bus/cxl/devices/memX/security/erase cxl enable-memdev memX Signed-off-by: Davidlohr Bueso Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Reviewed-by: Fan Ni --- Documentation/ABI/testing/sysfs-bus-cxl | 10 +++++++++ drivers/cxl/core/mbox.c | 6 +++++- drivers/cxl/core/memdev.c | 28 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 1 + 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 5753cba98692..f224c1215f22 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -85,6 +85,16 @@ Description: the device to be not be actively decoding any HPA ranges. +What /sys/bus/cxl/devices/memX/security/erase +Date: June, 2023 +KernelVersion: v6.5 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) Write a boolean 'true' string value to this attribute to + secure erase user data by changing the media encryption keys for + all user data areas of the device. + + What: /sys/bus/cxl/devices/*/devtype Date: June, 2021 KernelVersion: v5.14 diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 51c64829f20a..6622eac66bf1 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1102,7 +1102,7 @@ int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd) }; struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd }; - if (cmd != CXL_MBOX_OP_SANITIZE) + if (cmd != CXL_MBOX_OP_SANITIZE && cmd != CXL_MBOX_OP_SECURE_ERASE) return -EINVAL; rc = cxl_internal_send_cmd(cxlds, &sec_cmd); @@ -1120,6 +1120,10 @@ int cxl_mem_sanitize(struct cxl_dev_state *cxlds, u16 cmd) if (sec_out & CXL_PMEM_SEC_STATE_USER_PASS_SET) return -EINVAL; + if (cmd == CXL_MBOX_OP_SECURE_ERASE && + sec_out & CXL_PMEM_SEC_STATE_LOCKED) + return -EINVAL; + rc = cxl_internal_send_cmd(cxlds, &mbox_cmd); if (rc < 0) { dev_err(cxlds->dev, "Failed to sanitize device : %d", rc); diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 90f23e53d483..d06c8539e82c 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -163,6 +163,33 @@ static ssize_t security_sanitize_store(struct device *dev, static struct device_attribute dev_attr_security_sanitize = __ATTR(sanitize, 0200, NULL, security_sanitize_store); +static ssize_t security_erase_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_port *port = dev_get_drvdata(&cxlmd->dev); + ssize_t rc; + bool erase; + + if (kstrtobool(buf, &erase) || !erase) + return -EINVAL; + + if (!port || !is_cxl_endpoint(port)) + return -EINVAL; + + /* ensure no regions are mapped to this memdev */ + if (port->commit_end != -1) + return -EBUSY; + + rc = cxl_mem_sanitize(cxlds, CXL_MBOX_OP_SECURE_ERASE); + + return rc ? rc : len; +} +static struct device_attribute dev_attr_security_erase = + __ATTR(erase, 0200, NULL, security_erase_store); + static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd) { struct cxl_dev_state *cxlds = cxlmd->cxlds; @@ -411,6 +438,7 @@ static struct attribute *cxl_memdev_ram_attributes[] = { static struct attribute *cxl_memdev_security_attributes[] = { &dev_attr_security_state.attr, &dev_attr_security_sanitize.attr, + &dev_attr_security_erase.attr, NULL, }; diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 408ec33c8480..758fea7b9dbf 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -392,6 +392,7 @@ enum cxl_opcode { CXL_MBOX_OP_SCAN_MEDIA = 0x4304, CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305, CXL_MBOX_OP_SANITIZE = 0x4400, + CXL_MBOX_OP_SECURE_ERASE = 0x4401, CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500, CXL_MBOX_OP_SET_PASSPHRASE = 0x4501, CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502, From patchwork Fri May 26 03:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13256364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C88DDC7EE2E for ; Fri, 26 May 2023 04:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjEZEHe (ORCPT ); Fri, 26 May 2023 00:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233414AbjEZEHb (ORCPT ); Fri, 26 May 2023 00:07:31 -0400 Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDD213D for ; Thu, 25 May 2023 21:07:30 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 85EE11418A9; Fri, 26 May 2023 04:07:29 +0000 (UTC) Received: from pdx1-sub0-mail-a281.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E265214097C; Fri, 26 May 2023 04:07:28 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685074049; a=rsa-sha256; cv=none; b=z6vDWiKDcaVDYrqI//UVwwB3nsxT0TKlpTCHUmPFPBiptK2GCnRQ5DJg8katk5xISFJHU4 P5rCT7cvTMspzSrI0vs8vlrUtjZzeVVO+zjiYlZqLiRllLKXG/2ZdTmQ08GnAXTDlwArLI H0xe2L7RJSb591ZPPGyvE0xmMuQI5PMdgDAv6nzh9+wNmZ0RGy1CuLI8yCkwxdvCPyIZI/ Tx29nnNTpK5+XREovq2lhuBfdUf2WjUOgwzyp18e9alSSlW5vJnAE8hZ78HnYwJr2OXq5r A4jkRpxziEbtu5v7PRwYqNHYjepB4HvGa3Gxs5jMywLdEBASz1kU4jP0u9Ci5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685074049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5kFRLMZaWI3QVK5U9m8zFRl7JLxzfW57oqqEF93hP6k=; b=28VY0lUZdhXO6zi2A1O5UNu7U4OFfnYarKjeOw6qagVFNhPVe5UbXoUlirha5nLCpePI3m 0NBYF5mAevIO6qTOiFVPo9CAh7bBDCTW9XvLKg4bDLdC7PvtjnELL9TYM65gJp7J5PrDPE 9uHyBeA+2F5OsonOgmn4a2KgEQ4efxtYDpf/bAKYjAgqcwX97w9SMnNUVha2jS6fzimju2 /b+ONaxtGiVtDsxdfVBapJqNthawPTRI6fuJDDDeUH12dEkwhmYBAqUXldQd0U0bSsvxrw 3WT8p2l47RyGJeCfCSguSHk8bbe5mBJFsADx59TTakeyLPWaqWNAp4iKoMLGBg== ARC-Authentication-Results: i=1; rspamd-7d4b855556-vcjp2; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Quick-Vacuous: 141864191ee87c0c_1685074049342_1439482764 X-MC-Loop-Signature: 1685074049342:4041502261 X-MC-Ingress-Time: 1685074049342 Received: from pdx1-sub0-mail-a281.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.163.32 (trex/6.8.1); Fri, 26 May 2023 04:07:29 +0000 Received: from localhost.localdomain (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a281.dreamhost.com (Postfix) with ESMTPSA id 4QSBG81d70zRt; Thu, 25 May 2023 21:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1685074048; bh=5kFRLMZaWI3QVK5U9m8zFRl7JLxzfW57oqqEF93hP6k=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=XNm3NUEw1/75g5zxGLMu4vhED7+nydsOhG5ISXvWH9TxwKSCR3XJheDEFbXgr+4b1 bvo1I7PQDEQZheUSeYNO7LAwqDlootN5zPlVIbPhqtxUW1g+zOKuptzvcLLs0VZltr zEimcPaSkCDf7ITuqjR2lkuFXjUBjGYXn3G41mlWxcW4saCfFmOlI1cNrDZ4zrIXET if5bh+FbLSF0Tu5O7VxokruOKQQC/BmTkFpjzyD2cc0xlY0t3BwIQ7MYsfuOy4gIR0 G0I4p5IZawxemURkgH7fiI+KbiDA7/WK4tt8xLFJ2O12RjwkhPXbrC6usu5lM6kl67 7p0SvXKXvzA4g== From: Davidlohr Bueso To: dan.j.williams@intel.com Cc: dave.jiang@intel.com, vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com, fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, linux-cxl@vger.kernel.org Subject: [PATCH 6/6] cxl/test: Add Secure Erase opcode support Date: Thu, 25 May 2023 20:33:44 -0700 Message-Id: <20230526033344.17167-7-dave@stgolabs.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526033344.17167-1-dave@stgolabs.net> References: <20230526033344.17167-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add support to emulate the CXL the "Secure Erase" operation. Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Signed-off-by: Davidlohr Bueso --- tools/testing/cxl/test/mem.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index faa484ea5b0b..97de0d3b2fd0 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -557,6 +557,30 @@ static int mock_sanitize(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) return 0; /* assume less than 2 secs, no bg */ } +static int mock_secure_erase(struct cxl_dev_state *cxlds, + struct cxl_mbox_cmd *cmd) +{ + struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev); + + if (cmd->size_in != 0) + return -EINVAL; + + if (cmd->size_out != 0) + return -EINVAL; + + if (mdata->security_state & CXL_PMEM_SEC_STATE_USER_PASS_SET) { + cmd->return_code = CXL_MBOX_CMD_RC_SECURITY; + return -ENXIO; + } + + if (mdata->security_state & CXL_PMEM_SEC_STATE_LOCKED) { + cmd->return_code = CXL_MBOX_CMD_RC_SECURITY; + return -ENXIO; + } + + return 0; +} + static int mock_get_security_state(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) { @@ -1178,6 +1202,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd * case CXL_MBOX_OP_SANITIZE: rc = mock_sanitize(cxlds, cmd); break; + case CXL_MBOX_OP_SECURE_ERASE: + rc = mock_secure_erase(cxlds, cmd); + break; case CXL_MBOX_OP_GET_SECURITY_STATE: rc = mock_get_security_state(cxlds, cmd); break;