[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251030035114.16840-4-alistair.francis@wdc.com>
Date: Thu, 30 Oct 2025 13:51:14 +1000
From: alistair23@...il.com
To: kbusch@...nel.org,
	axboe@...nel.dk,
	hch@....de,
	sagi@...mberg.me,
	hare@...e.de,
	kch@...dia.com,
	linux-nvme@...ts.infradead.org
Cc: linux-kernel@...r.kernel.org,
	alistair23@...il.com,
	Alistair Francis <alistair.francis@....com>
Subject: [PATCH 3/3] nvme: Allow reauth from sysfs
From: Alistair Francis <alistair.francis@....com>
Allow userspace to trigger a reauth (REPLACETLSPSK) from sysfs.
This can be done by writing the queue ID to te sysfs file.
echo 0 > /sys/devices/virtual/nvme-fabrics/ctl/nvme0/replace_psk
Note that only QID 0 (admin queue) is supported.
Signed-off-by: Alistair Francis <alistair.francis@....com>
---
 drivers/nvme/host/sysfs.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 29430949ce2f..f6994f35324f 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -246,6 +246,32 @@ static ssize_t nuse_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(nuse);
 
+static ssize_t nvme_sysfs_replace_psk(struct device *dev,
+				      struct device_attribute *attr, const char *buf,
+				      size_t count)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	int qid, rc;
+
+	rc = kstrtoint(buf, 10, &qid);
+	if (rc)
+		return rc;
+
+	if (qid >= ctrl->queue_count)
+		return -EINVAL;
+
+	rc = nvme_auth_negotiate(ctrl, qid);
+	if (rc < 0)
+		return rc;
+
+	rc = nvme_auth_wait(ctrl, qid);
+	if (rc < 0)
+		return rc;
+
+	return count;
+}
+static DEVICE_ATTR(replace_psk, S_IWUSR, NULL, nvme_sysfs_replace_psk);
+
 static struct attribute *nvme_ns_attrs[] = {
 	&dev_attr_wwid.attr,
 	&dev_attr_uuid.attr,
@@ -747,6 +773,7 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_dhchap_ctrl_secret.attr,
 #endif
 	&dev_attr_adm_passthru_err_log_enabled.attr,
+	&dev_attr_replace_psk.attr,
 	NULL
 };
 
@@ -776,6 +803,10 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
 	if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts)
 		return 0;
 #endif
+	if (a == &dev_attr_replace_psk.attr) {
+		if (!ctrl->opts || !ctrl->opts->concat)
+			return 0;
+	}
 
 	return a->mode;
 }
-- 
2.51.0
Powered by blists - more mailing lists
 
