From patchwork Mon Jun 12 18:10:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277161 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 1AE0DC7EE2E for ; Mon, 12 Jun 2023 18:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbjFLSp0 (ORCPT ); Mon, 12 Jun 2023 14:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233586AbjFLSpZ (ORCPT ); Mon, 12 Jun 2023 14:45:25 -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 7CE5B184 for ; Mon, 12 Jun 2023 11:45:24 -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 CAB656C19AD; Mon, 12 Jun 2023 18:45:23 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 377FE6C29F7; Mon, 12 Jun 2023 18:45:23 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595523; a=rsa-sha256; cv=none; b=nRaGPjRMagQ98Jc7Fxbn7nb9Nhbzuo8A+fcSDMu83DSMJsVbGd8JWffkqEDZNkYw0qQJm2 GkW9Ue4fNT6wZ3rpbCKVjVEPdPBP7LjIywh0Nrg3FrXGpbZcvP7kZ6eVb7fajqH4A0KHoz M2Yz8ttFKqHLgrM6OTQTBB9a99lBdKfbaqEsqqPQuTHQQ6p5tz7/GznqNyqmCEm6sjh3Mo jnBKtMQD/AmzZ3Fx7IWf6inJd6SKBLJwUqNwKVjYqrxgP4H620AFx2InbQ2JpLsVP3ctsy dbQv1bvechhA9D8O5LVRh44W/0lWnraFtV12Uhca6NHxuRdJECuHoqxYRV/olQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595523; 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=0k20K5jL/JRKSzlK03R/s3Lcb5oxhDJApBvL4XqqMaQ=; b=oM+IgYEmwTGiahm2A7ivzxHDUFl0p0aoC2R8tZgrXpCgzEUQ6z5afKuz+YweO4mgxlJGiZ hdBgDOiMFv70ueOdQnwtwUPzxLKgdrQB7TOD26TR66u5rN1yb3OCTKGZicEUOaGD286ogZ af0KRXvvD3WuiNwp/wi1Erhs2LOmeoVd1I1XtQ4gsiYiZjY9x1a1TYlX9jYvwAh//R7q3G G4/IPhhTTKJBmtMbJYk3ahBJGsUqIHv2qADgqNa6N/uF91VadaqnmAz0azNRXxfeIa6+hX wpP9dZ04W9Ax6upFoAN11mQ/uc/3vJcEBv6WUtxFGLqtYozS/8UKGgnnHi6Ixg== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-p8dcm; 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-Bottle-Macabre: 15963fa658c9ff10_1686595523546_2939337686 X-MC-Loop-Signature: 1686595523546:4244141998 X-MC-Ingress-Time: 1686595523545 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.163.21 (trex/6.8.1); Mon, 12 Jun 2023 18:45:23 +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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xG3QQcz63; Mon, 12 Jun 2023 11:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595523; bh=0k20K5jL/JRKSzlK03R/s3Lcb5oxhDJApBvL4XqqMaQ=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=B6g3TazEyVaAPWUNcUgcsh3mVJE99UDC3zDO2+dzF/d8WoQ1ETBN+whZ944F61iM7 i7lat3TMMWvyiY7mcMcqLOwnhfcOn+81slNxoRyW0Qpi/M6PyUav2EpqNv+zSBhK0J jOTFV1tRelhpMET3EUUPcMHoL/ITQ3CcDB8AP/14FIPsOP5zvI4e7IbDXoCGDiOwBg OPTpVRyTQE+afrtQ1xInwsdxpPgjr/kZy+Tlla+uEUMGkBvw20PjlYMSCW3SHSXiFk L6pJsIwfLgI8cXCIwCxA6II2GsyYh5OMiNp6WNkdu9KjObiRFhyuE6Ip6DpYw6aqbS VB7trHBrqH65w== 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, Jonathan Cameron Subject: [PATCH 1/7] cxl/mbox: Allow for IRQ_NONE case in the isr Date: Mon, 12 Jun 2023 11:10:32 -0700 Message-ID: <20230612181038.14421-2-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-1-dave@stgolabs.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org For cases when the mailbox background operation is not complete, do not "handle" the interrupt, as it was not from this device. And furthermore there are no racy scenarios such as the hw being out of sync with the driver and starting a new background op behind its back. Reported-by: Jonathan Cameron Fixes: ccadf1310fb (cxl/mbox: Add background cmd handling machinery) Signed-off-by: Davidlohr Bueso Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang --- drivers/cxl/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index a78e40e6d0e0..4b2575502f49 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -118,9 +118,11 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) struct cxl_dev_id *dev_id = id; struct cxl_dev_state *cxlds = dev_id->cxlds; + if (!cxl_mbox_background_complete(cxlds)) + return IRQ_NONE; + /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ - if (cxl_mbox_background_complete(cxlds)) - rcuwait_wake_up(&cxlds->mbox_wait); + rcuwait_wake_up(&cxlds->mbox_wait); return IRQ_HANDLED; } From patchwork Mon Jun 12 18:10:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277162 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 259C0C7EE2F for ; Mon, 12 Jun 2023 18:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233586AbjFLSp1 (ORCPT ); Mon, 12 Jun 2023 14:45:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234484AbjFLSp0 (ORCPT ); Mon, 12 Jun 2023 14:45:26 -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 74593189 for ; Mon, 12 Jun 2023 11:45:25 -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 B081A141BF4; Mon, 12 Jun 2023 18:45:24 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 060A514176D; Mon, 12 Jun 2023 18:45:24 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595524; a=rsa-sha256; cv=none; b=K7Vzu3dTt8HhBOsav3CEblKKgd42vJRIbFMUOc7vLSYX9CNL9TJ5xAEeuI2kypw3AT7bMA xebfTnFmYq7ma5g+PjClADeJp16w3FJ2Q9/XDmnKsxh5HNYlOC/VSCFPBs7Rr7TtBd184l xzfaM4paV3eWjxEAd1VvDfwrJXcrfGOlaorqf8cmKEc1QXw/E2wbMvJVbrD/6fhnVglQ6U mgVATEUYPkjrdG4D4TS3IXdCE6ar8jl1eMJnisWfOHy9ZVm4DOTrVO+pCSzeCaWnenR4GB a0Twa+wnIftFnUcAywWG13XQrr7MT9vcBOfYoPEseC1DkGtRUmpl65LsnUolLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595524; 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=JSkW/AbJnGyuWN6X0hmjYxQ7Qm9s4hbO+3fDpZXzSV8=; b=eJG2BAuE+1e5RofvwoT/WpddE7KFOTMfj3Btq2W/Zhg3ppejDT4AFR462331SCDvDmBWR1 ap1p+rbSl4AZps2Do+p7HH8qWySPwazTs5qKgqvuLpchnl3LOYMtVgpXka+WW2OJJWrPzq Jhmi+OHfoZeRbgRYIbgB5Ll9rp00ttobQvPO15MNpL30cUwHWdFBTevozy4VOYvoNDH/gE j2mgU030FrJByy+rFaRTTjdRZ+NijkQDgGKw4HjQvfeImfRdSnjICiAT8mtilyLCnt1THy xQdrgNRit8sJxlBXHgydvTkfYBPQsGwUKaCMSOkH5zT3SjO6W6gX17k2EwTL1w== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-x5df5; 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-Daffy-Coil: 71be2f8d189b2b2d_1686595524456_1116937861 X-MC-Loop-Signature: 1686595524456:4128173717 X-MC-Ingress-Time: 1686595524456 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.30.17 (trex/6.8.1); Mon, 12 Jun 2023 18:45:24 +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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xH18vmzXL; Mon, 12 Jun 2023 11:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595523; bh=JSkW/AbJnGyuWN6X0hmjYxQ7Qm9s4hbO+3fDpZXzSV8=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=d+85juhSRGJ9TKldaWfRLCV/4/4XNI2MWbl0W5KPSFv7Sy+m2ToboY6i/MX1lxHMg rCOHdD9U4lesuT9wIcMml0j/Y20CtvXOsu0JpjYyyvPb7SI/S1TfAlKMiLkXODqt/b 9xlQhZ3l73ek+CrsU9s8ZKNL8ulLmV3aI4UhSO/VH1epAJ+IXusa/Vx1MHIKf+UEEj QoZcBxhXDUJKWILpsBLcp+qotW3w31AKtPIF3oOuhv/eXhsE1oe0+IijA46A+gYbOl z1nGtZNIsHIsOulfnz3cHv2fk4L9DT44S+G2q33Sqxr25e6d5IIy5XslVKpAuJ6GKW I3UTqL7mJVrOQ== 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/7] cxl/mem: Introduce security state sysfs file Date: Mon, 12 Jun 2023 11:10:33 -0700 Message-ID: <20230612181038.14421-3-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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. Reviewed-by: Jonathan Cameron Reviewed-by: Fan Ni Signed-off-by: Davidlohr Bueso Reviewed-by: Dave Jiang --- Documentation/ABI/testing/sysfs-bus-cxl | 10 ++++++++ drivers/cxl/core/memdev.c | 33 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 10 ++++++++ drivers/cxl/security.c | 3 +++ 4 files changed, 56 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..1bbb7e39fc93 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, }; diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 1d8e81c87c6a..091f1200736b 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 * @@ -336,6 +345,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 Mon Jun 12 18:10:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277167 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 9DC62C88CB7 for ; Mon, 12 Jun 2023 18:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235905AbjFLSpd (ORCPT ); Mon, 12 Jun 2023 14:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbjFLSpb (ORCPT ); Mon, 12 Jun 2023 14:45:31 -0400 Received: from tiger.tulip.relay.mailchannels.net (tiger.tulip.relay.mailchannels.net [23.83.218.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CC3EE73 for ; Mon, 12 Jun 2023 11:45:28 -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 EA0AA101CA6; Mon, 12 Jun 2023 18:45:24 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6843D101D52; Mon, 12 Jun 2023 18:45:24 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595524; a=rsa-sha256; cv=none; b=mRo0zQLg2Bg9B/ZPD3d5nlENWzq8ty3jvOaFbyqDFDUL42sCFQNK+keb87Q3Ud9BUeW1ef Q/WmaQ3Cn8bnxn7iI88XfmNjeFR4OOtmzfIcmJIVJtJdwUCWucL9EmUNSZhrS+/oTu5iHw roPNWHwjGjmcge8q+6Exrz1i64gyGHjH9UM01/ph/1W9UBLfPpVwee/olI8zaGJC8ZY87G Qt7COVwgmC5wP7yPWCZ66ghwVVpUN/vI4AmKEFIru5kOeRZAw/vrHYaIafw+EsoG+KWXkc Y+PairanoHEjDzcLkNZVguPzxVvxOitDW1x0/mw9BfAmB9X1IB8lFpC4qQSiWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595524; 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=eBD1Co068xhnB0vmLO6xcn0kgLtwJxPxxxxwf2m906k=; b=bs05gforqirMwsnZvfS9p1zozPu7VG7uLxNn6PDy5hPczTOZ5hi/aN57Y1NiZ1FRyCCNJS gZFnJ709vPqFIZQ5INiew7te/crltKl7QFHIukgH3icRaffr5DAhRutIlGUtb2RTWCjQvO Guo6GrYwtR0Wazbuc2/p6dBiC68NmgmvYHH2k8Oxn1gxt1JpJ3MXeyqK3DdLU8O2y2fF+X tR0BGQcUY4QjJ6GtRF+/XAj2n9eS70Oey4KmtRhisTgBknZLOGd4HlRh1cijGq60BhGnMj QnspArf3L+6PZSAwU50+iecCxnnEHjicwtOC2JwfNfa0bbrdzdl4Lw+wX3eKPg== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-szjxp; 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-Wipe-Trade: 156dfcc139e59b83_1686595524770_655619332 X-MC-Loop-Signature: 1686595524769:1410291216 X-MC-Ingress-Time: 1686595524769 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.2 (trex/6.8.1); Mon, 12 Jun 2023 18:45:24 +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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xH5YYfzRV; Mon, 12 Jun 2023 11:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595524; bh=eBD1Co068xhnB0vmLO6xcn0kgLtwJxPxxxxwf2m906k=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=mp40jON/jhv6rW04U4MvFscMDupZSvFkKawSGdRfL+nqtwF0II+7pCz0v1KswnRgv a74hTmEw32/oknBy3Btt5u2Kc6GtRxL9Ar/2EVot10uz7djBKNBs0Kx6BFB1dKuVFz KNeQlmk4eMroSmgQBDAjeT4OTgVShUlUW/LpBHqIts0MIckZ8TTpc7Ep3nkdR7TqAQ 4pXNwiDaYl04+P7Ib+CRJ9ckY5CHSKHblDX6oOnSo36f62ySlz4UH+DYcQhMXdtFf6 4fBU9M20p1dY2Mw8z8QDqDu5h5mVJFnOwPVuAIYDpiM/4PXn99KpbR/F8BWRIL6cNZ QXsrIovH0mgwA== 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/7] cxl/mbox: Add sanitation handling machinery Date: Mon, 12 Jun 2023 11:10:34 -0700 Message-ID: <20230612181038.14421-4-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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. The irq case is much simpler as hardware will serialize/error appropriately. Reviewed-by: Dave Jiang Signed-off-by: Davidlohr Bueso Reviewed-by: Jonathan Cameron --- drivers/cxl/core/memdev.c | 10 +++++ drivers/cxl/cxlmem.h | 7 ++++ drivers/cxl/pci.c | 77 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 1bbb7e39fc93..834f418b6bcb 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) + 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 091f1200736b..3a9df1044144 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -264,9 +264,15 @@ struct cxl_poison_state { * struct cxl_security_state - Device security state * * @state: state of last security operation + * @poll: polling for sanitation is enabled, device has no mbox irq support + * @poll_tmo_secs: polling timeout + * @poll_dwork: polling work item */ struct cxl_security_state { unsigned long state; + bool poll; + int poll_tmo_secs; + struct delayed_work poll_dwork; }; /** @@ -379,6 +385,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 4b2575502f49..c92eab55a5a7 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -115,18 +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; if (!cxl_mbox_background_complete(cxlds)) return IRQ_NONE; - /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ - rcuwait_wake_up(&cxlds->mbox_wait); + 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); + } 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. @@ -187,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) { @@ -235,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), @@ -270,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); @@ -382,6 +450,9 @@ static int cxl_pci_setup_mailbox(struct cxl_dev_state *cxlds) } mbox_poll: + cxlds->security.poll = true; + INIT_DELAYED_WORK(&cxlds->security.poll_dwork, cxl_mbox_sanitize_work); + dev_dbg(cxlds->dev, "Mailbox interrupts are unsupported"); return 0; } From patchwork Mon Jun 12 18:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277164 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 B7C63C7EE2E for ; Mon, 12 Jun 2023 18:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234484AbjFLSpa (ORCPT ); Mon, 12 Jun 2023 14:45:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235364AbjFLSp3 (ORCPT ); Mon, 12 Jun 2023 14:45:29 -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 C9137189 for ; Mon, 12 Jun 2023 11:45: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 D1B546C2BD3; Mon, 12 Jun 2023 18:45:25 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 08BC36C1C6B; Mon, 12 Jun 2023 18:45:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595525; a=rsa-sha256; cv=none; b=1E92gjjqBc4w2jg/gBlPAbfU/FA5Oo93nhiuH6Va23l/CMUgLV2mBasNrOWP/RyPWhYsxK xuvTVIA4xudvofvm/P5OzlE9Nf0ktJSnqwL2ZNWYLYukuqUgQTCThYp/a61po80C0cQmZo KigHfzSFD5xmLhtxL7qqbgD4TnGNfamNcZC+7mpHyhL0gzQoYt/4yG/7KP1MHeUGNqcjOz E6PtGcax3fslyfi8b9Vy9UGHuJyJKJdmlJvugDRLArSes/Z5RoEmvsVpGctPbHAe3Y5jsg +rH2NLZhlbhL/kaxdpKhkXvoTGn8J0pJj+Cs4Zq1PO/LsILP0AmbCDW+YErsNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595525; 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=qxA8rkRFgSymGiwMHWm5egB5lIREURj6avGFeswDpLM=; b=HVSKI8fkf6kzvPHbIepXBOnkr2zd0Ft9Sh5vGEMXgw9uHraL8e70e+gW1q2+EcsJYTQW5A DhMM3aufVmCl0qspqYKeYAkRayPQHXSjdszCYqjHnXFi8Vv+sjW1lboPVUdqGYZzpWXz7q 6g6GkiOSW+I1mu1gOAlNUEYikgWLg/lRAPCshRwlSZj0bCI/hWxZwuxaFL76joc27ISES7 Qaa1/PqS3Tzv0Hnu4WG5pNACZFb66dNq12xavLStVucXSfUXw5bU3Yyf4fv8LT9JNV6Vxh rkLdAMskAP4EERy3rAiuBKh8d9Q42f7zwp0cOdAIXBssFjnYQMsG+t9kdMm9Gw== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-szjxp; 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-Stretch-Macabre: 396dc7040a5bf952_1686595525679_3940440547 X-MC-Loop-Signature: 1686595525679:2227229573 X-MC-Ingress-Time: 1686595525679 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.24.98 (trex/6.8.1); Mon, 12 Jun 2023 18:45: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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xJ2pW1z63; Mon, 12 Jun 2023 11:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595524; bh=qxA8rkRFgSymGiwMHWm5egB5lIREURj6avGFeswDpLM=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=mAF4m5hvmcOVM2K5sqmX0fwetfzMzc/IN2uoeVacVHzyrH589rKI2mpTmtfnAVpL8 NvjoFQzxvc/5eUP4J3oJVdHhdkE5IxRMfBeqsGXIi7+W+XhTNv/oJlH0qJW2JPPtl6 tsVZNxviLg2Xyg/eKgsAOypi92dqRrmSpznRV7rb0JnAfdXHZ8V0vvOLVtIO5kzjAy W9GFJdpcF7DQrISoeXaj+1rxWzxxq5qZlLjxt9R2rMNVqANUClcWMrBrB9cG+QzKTO 1KVmykFtIeIVSptT4JVaCPfvbKl1GTWb1PL39dnuc/DXIdljVfu9PdVu8vwbpc1jA6 usRms4hJqK+yg== 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/7] cxl/mem: Wire up Sanitation support Date: Mon, 12 Jun 2023 11:10:35 -0700 Message-ID: <20230612181038.14421-5-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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 to trigger the operation and extend the status file to make it 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 Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Signed-off-by: Davidlohr Bueso --- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++- drivers/cxl/core/mbox.c | 55 ++++++++++++++++++++ drivers/cxl/core/memdev.c | 67 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 4 ++ drivers/cxl/pci.c | 6 +++ 5 files changed, 151 insertions(+), 2 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 834f418b6bcb..bdd1edfd62e8 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,6 +629,34 @@ 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; + + 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 devm_add_action_or_reset(cxlds->dev, put_sanitize, cxlds); + } + struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) { struct cxl_memdev *cxlmd; @@ -622,6 +685,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 3a9df1044144..177a76578a94 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -267,12 +267,14 @@ struct cxl_poison_state { * @poll: polling for sanitation is enabled, device has no mbox irq support * @poll_tmo_secs: polling timeout * @poll_dwork: polling work item + * @sanitize_node: sanitation sysfs file to notify */ struct cxl_security_state { unsigned long state; bool poll; int poll_tmo_secs; struct delayed_work poll_dwork; + struct kernfs_node *sanitize_node; }; /** @@ -746,6 +748,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 c92eab55a5a7..d1df23c19245 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() */ @@ -150,6 +153,9 @@ static void cxl_mbox_sanitize_work(struct work_struct *work) 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 { int timeout = cxlds->security.poll_tmo_secs + 10; From patchwork Mon Jun 12 18:10:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277168 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 E0390C7EE2F for ; Mon, 12 Jun 2023 18:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236093AbjFLSpf (ORCPT ); Mon, 12 Jun 2023 14:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbjFLSpd (ORCPT ); Mon, 12 Jun 2023 14:45:33 -0400 Received: from tiger.tulip.relay.mailchannels.net (tiger.tulip.relay.mailchannels.net [23.83.218.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B05184 for ; Mon, 12 Jun 2023 11:45: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 EE843141F7B; Mon, 12 Jun 2023 18:45:27 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A56AF141E34; Mon, 12 Jun 2023 18:45:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595525; a=rsa-sha256; cv=none; b=3UcSZhNbJ9sJwpf0KF3oiB5e+bHOy298+1iWKw9YUhqLqa2SozUdMR7yl8bqy1n4LE/zVQ vb65BfybGKB7XD/e5EUObBhMzZGmqTITAlwGsCkSLgC6ItiRiBxeqS/A+6mIeyv6wrJ/p1 zoCqWq5gXkTXX2pu9epvNZ0d/IfSuUQaHEJTJUtQ28t8sPN9aCK22Bdu/B+FE4CzAVIf7y OvnLoIvdcRkCJQZ61g0NVOQ39TZlCenhdRBYWX2YaGkhEvtrc5ktqlYISLUoUQO4EW5dkp MUb7wSQEHmAdJjWR9y4tvL1QYtnmt77TdoC1748FLTQpQIsorkbAiyVJQigxeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595525; 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=SYR1NzqvlOdPtUIClEJ40zzrZ9ngdRKg2ieOzKpEG9Q=; b=gDxBQ/QB4sPt8fUSDLoZ3sR2GpWpiKChJ6HwjI5ngkTYWkY9Xpk5fZm0csi9TNtA+ggYoz TRH7gzoUspGj5FRtvtXG+sEq+V7J4sovkRFOCsuVlF4KaFTRRUkaFU84ose/0/UJYbxeiS PZHLF1qTuM0oECo2ybsTi4nJMXQDfDux1UGOVZev8tJgkdpVOpwv3M90SpEg/sG+HvXJdM TQqvhVa2le7e6dF1iXW/UR/2Z7ffAxuMq0vQrlobFsbvPQ4ahDQZJPZq0pQgk1/3SP/53G OOUYkRcQNhUVRRAkf2eBb01pMNEOhJiIXrY9QoVSLtmmg0Pvs9Rti++YMBTcYw== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-swvgs; 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-Average-Tart: 214cc1ea7d7e1892_1686595525985_1131337458 X-MC-Loop-Signature: 1686595525985:2382123884 X-MC-Ingress-Time: 1686595525985 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.24.98 (trex/6.8.1); Mon, 12 Jun 2023 18:45: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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xK08c8z6Y; Mon, 12 Jun 2023 11:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595525; bh=SYR1NzqvlOdPtUIClEJ40zzrZ9ngdRKg2ieOzKpEG9Q=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=eCS/o0Ji3oTnVJf8sdgCCzFyjvsXfl06tbMsF+p44R6lS6Tc4/seEe0HYNKCN7y7O sxKobu0oD3cxatlT274jmW7XKGApZylHLVH1ec2/9PvC6Myk6uR61fbdRIguB6zpf2 lhhlkBiSSgBYoE+I3ollGF/EYkkiNz/MwOXng4fw5TNONJLDnH7d5Llm67k5pggmP4 zMPpeKAiZH5wq04BBExushEYt1keTabIcbZTkbANhwViThTILmMH5DW/RQno/pf258 GhdT1eBAVLx/8T+EKnI0QHUFuy80bSj+dJCT78w+qq5GXtpr6CCna3ATTKpDxddmWN wvrVR9NmdxVeg== 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/7] cxl/test: Add Sanitize opcode support Date: Mon, 12 Jun 2023 11:10:36 -0700 Message-ID: <20230612181038.14421-6-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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 Mon Jun 12 18:10:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277163 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 907F6C88CB2 for ; Mon, 12 Jun 2023 18:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235411AbjFLSp3 (ORCPT ); Mon, 12 Jun 2023 14:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234484AbjFLSp3 (ORCPT ); Mon, 12 Jun 2023 14:45:29 -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 0E2C1E6F for ; Mon, 12 Jun 2023 11:45: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 C94F5640B87; Mon, 12 Jun 2023 18:45:26 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 46141641A6E; Mon, 12 Jun 2023 18:45:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595526; a=rsa-sha256; cv=none; b=QurRa4ndvCjcm0Myqm36MYijaBt/RrbnxmR6vvknhTgsCcFAd9/bntXttxz8rbxWPl79D6 6zi8d+bL0hwfZX+ucUib2tRHXAs9299z/KrE9W5iOAyMLAN4S+tcXDPl9VE2MaR3d/GDoo YOvLSR9HK4pprxmQAkCzIHk0E+bYdZ9V3N//7uI5nQAqc/WgJ68j6Pwm7tr1zFYsYp6NPP RCc13wYWqXDAWr3plfbh79yUK8rESGfJ/BF15i6HqARbngJFib3D9IEJxpJATURfPqAQcF Gn3yAibyC14B4kFTO3KHlXMKCEFH2w/tuaqVUpkRpN/vcgPGCaxu2rRHYXRTtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595526; 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=rb2nYuaQG7yq6MtzRrO1hwtQIlFYtLZezlkfpakDVbM=; b=KOCn9Dmof5rpuNCLWVTLXQ2WNiJTe92MsJlWcWstDcaQYfbPay9E4u64rzHv982KOtanVh qexzxG98dg9mcGj0pZNO6n3k9S2AlL2gpSLL0CixQ9CE9knwkcZZLkORuluZtlt1bY5OQA WnEpXwYgNyJx6Sskz8iied719Nuw6DcPAAVbiupCSYo90YZW0/GLaL7fBs6shKEyCjSK3d zYP9TkW4lRWNLv8CYs9542Q0rjXA1OUx9E2liBpkQr1C+vcE58AVhgFzwHdkPz3jyzwv07 HpaHpGUllwGbospSXcxGB25XoMXYFT9ygPCoNKKH3+uhAAVpXB+u6dpC4dfczg== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-p8dcm; 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-Descriptive-Company: 3ee2f3993cb21c8f_1686595526627_2966272992 X-MC-Loop-Signature: 1686595526627:3912530023 X-MC-Ingress-Time: 1686595526627 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.59.15 (trex/6.8.1); Mon, 12 Jun 2023 18:45: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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xK4c6nzXL; Mon, 12 Jun 2023 11:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595526; bh=rb2nYuaQG7yq6MtzRrO1hwtQIlFYtLZezlkfpakDVbM=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=c4qwLM7otxYwXVj68G/uz7B8WC3fbKzejpaO7i9W5IrQmTrY4UreFMcg8tfOdhU41 kg9KX3x5W+VNY24MRMN0el3hIyJHBqck0iLgqueKFHcd+DSYvRTFyzqyqlq+34zRu9 tip1/TvbtY4EFpajnBSggB6feej78CAk8PD/l7XMG1UH/QMCmzTityTrTo76Adc3BV O9AvPaMQ+Me3oBxTb0nQfeM+4u0a0jnM51Y9aAzkXfNcFB0iWoielpZMtc8rq3e/Wc m12JpLPPFI53zNbIGCLSbTONBsecEaIsCVJ9xRmKxu5ABfpU/qsDoIHAX3CbUNdv1+ PVop7ULCgdF9w== 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/7] cxl/mem: Support Secure Erase Date: Mon, 12 Jun 2023 11:10:37 -0700 Message-ID: <20230612181038.14421-7-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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 Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Reviewed-by: Fan Ni Signed-off-by: Davidlohr Bueso --- 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 bdd1edfd62e8..ed8de7efddef 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 177a76578a94..e57db7adb2a3 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -388,6 +388,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 Mon Jun 12 18:10:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 13277166 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 23BF7C88CB2 for ; Mon, 12 Jun 2023 18:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235711AbjFLSpc (ORCPT ); Mon, 12 Jun 2023 14:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235905AbjFLSpb (ORCPT ); Mon, 12 Jun 2023 14:45: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 C269A189 for ; Mon, 12 Jun 2023 11:45: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 8DBC25C0F9E; Mon, 12 Jun 2023 18:45:27 +0000 (UTC) Received: from pdx1-sub0-mail-a316.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id F2E325C1F5D; Mon, 12 Jun 2023 18:45:26 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686595527; a=rsa-sha256; cv=none; b=uPhxwpRwPsIxm5QRY7o0jA07jgSEtAnCTMHnYc6HNvxHa8ASn/Ve4DXrQW3Git3JerHsSa vhWydEdAkSY0eUPIZaQrE6GVi/Jl/mFs1ctHXS4T9u5SGnVacaaLlfPPxhTFWct3WRd9/y loEvMewZD8qrXjsQb6+yql5AXUQa5OsX8ccMaVQ/qnU3gZwTMdf7hVtXGOuibtm3NHlm9H vB5WDqn1NrmK1mb/INn9okcdJ44MRPt4072CxvHppfPulhM34jX+mqI+0yq71FkVeW7/f+ ZKMGq7sl3g3boESrpuqjZY9YunUT3iDvEmPEnrUoyr8PeCcOZeuyc0D3IFqjJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686595527; 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=L57OL2I0km+iVH2GRtjxDe9Nt335wagH+I9yCKu5UY0=; b=RRQiYraIzadg1EQj8CwGnH/flkwsi8PGAujjhwb+gmoqvGh6ElzirtgyVWMkDO3fPnlSHB GsPnVOxqQyvUilqcR2CFPMb1BRH7rnybeU7z7ed2fMU9ipJgfX2weplOclYlqTs8ihjkzI WWBq0KiPGz14LNIsTmtkuaZi2YFkScaOD4Xb3oYVwAMnDgWAIUvkZOohJp/k/3bXY/9KH0 30OJCrUs5bXCAa7AddulgKLMgKr8Tep3XnV+SGymYX4051CCzXEjJ96Cr3QEQDETPnLBe2 D7s9bwvckV3u8nxXusBC4Ik5+0/fOI4vsuYICLnZx3PEbPfo0mRYaixnU1kwLw== ARC-Authentication-Results: i=1; rspamd-6c69b8658d-szjxp; 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-Dime-Tank: 7ac5083a0cd34650_1686595527297_741114936 X-MC-Loop-Signature: 1686595527297:3373070763 X-MC-Ingress-Time: 1686595527297 Received: from pdx1-sub0-mail-a316.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.59.15 (trex/6.8.1); Mon, 12 Jun 2023 18:45: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-a316.dreamhost.com (Postfix) with ESMTPSA id 4Qg0xL1wdSz63; Mon, 12 Jun 2023 11:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1686595526; bh=L57OL2I0km+iVH2GRtjxDe9Nt335wagH+I9yCKu5UY0=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=Gqv6yP5Uv5g8YOeF7jZeBWSiXu7bSlM2L8ApKtwrVHAGrOpPDhyQRFr7LKtmJFRCX ZiUmTP2Ztn4MIIzbf28JiSvpWDlRiC+l8c46PTb5lWhUpS1g1TXGorV1wbE8MXL/zQ rOL8uRP56NVJU1x8hY7qRI+KvBbfm5fGPJb2lU8RDR13Z2Y3K0h1oQfRK88+/eHLHd SpOfRuvekgpp5D6/o4/fiPUERRxhc0BLXBlXbLpkNMdJC0zr5KOZ9f7nry0DA1MVTm XGpXZ4IJrx1nqF/Yqj2daRaQ/P3VtZwYHpUOhLeMuJTLn8U6wd2f/JSeG4RfptkCEE FVB1mPGSkxzgw== 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 7/7] cxl/test: Add Secure Erase opcode support Date: Mon, 12 Jun 2023 11:10:38 -0700 Message-ID: <20230612181038.14421-8-dave@stgolabs.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612181038.14421-1-dave@stgolabs.net> References: <20230612181038.14421-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;