Skip to contentSkip to conversation

nvme: expose TLS mode

PATCH In review Daniel Wagner 5 participants 5 messages Apr 8 – Apr 16 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 nvme: expose TLS mode

It is not possible to determine the active TLS mode from the presence or absence of sysfs attributes like tls_key, tls_configured_key, or dhchap_secret.

With the introduction of the concat mode and optional DH-CHAP authentication, different configurations can result in identical sysfs state. This makes user space detection unreliable.

Expose the TLS mode explicitly to allow user space to unambiguously identify the active configuration and avoid fragile heuristics in nvme-cli.

---
Fixed visibilty condition, the previous version used opts->tls_key but it should opts->tls.

Original cover letter (with fixed example):

I am extending the test suite for nvme-cli to cover the use case of nvme connect --tls/--concat.

Currently, nvme-cli uses heuristics to determine whether --tls was used to initiate the connection. With the introduction of --concat, these heuristics are no longer reliable.

By exposing the TLS mode explicitly, nvme config can now generate a configuration based on the currently active connection.

$ nvme connect --transport tcp --traddr 192.168.30.30 --trsvcid 4420  \
  		--hostnqn nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36  \
		--nqn nqn.io-1 --concat  \
		--dhchap-secret=DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:   \
		--dump-config --output-format json
[
  {
    "hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
    "hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
    "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
    "subsystems":[
      {
        "nqn":"nqn.io-1",
        "ports":[
          {
            "transport":"tcp",
            "traddr":"192.168.30.30",
            "trsvcid":"4420",
            "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
            "concat":true
          }
        ]
      }
    ]
  }
]
$ nvme config --scan --dump --output-format json /dev/nvme1
[
  {
    "hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
    "hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
    "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
    "subsystems":[
      {
        "nqn":"nqn.io-1",
        "ports":[
          {
            "transport":"tcp",
            "traddr":"192.168.30.30",
            "trsvcid":"4420",
            "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
            "concat":true
          }
        ]
      }
    ]
  }
]
$ cat /sys/class/nvme-fabrics/ctl/nvme1/tls_mode
concat
---
Changes in v3:
- Fixed visibilty conditions to opts->tls instead of opts->tls_key
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- fixed the example output
- tls_mode only visible when either tls or concat is enabled. avoids 'none'
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/nvme/host/sysfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/nvme/host/sysfs.c +19 -0
index 16c6fea4b2db..df25c8fef063 100644
@@ -841,10 +841,26 @@ static ssize_t tls_keyring_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(tls_keyring);
 
+static ssize_t tls_mode_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	const char *mode;
+
+	if (ctrl->opts->tls)
+		mode = "tls";
+	else
+		mode = "concat";
+
+	return sysfs_emit(buf, "%s\n", mode);
+}
+static DEVICE_ATTR_RO(tls_mode);
+
 static struct attribute *nvme_tls_attrs[] = {
 	&dev_attr_tls_key.attr,
 	&dev_attr_tls_configured_key.attr,
 	&dev_attr_tls_keyring.attr,
+	&dev_attr_tls_mode.attr,
 	NULL,
 };
 
@@ -866,6 +882,9 @@ static umode_t nvme_tls_attrs_are_visible(struct kobject *kobj,
 	if (a == &dev_attr_tls_keyring.attr &&
 	    !ctrl->opts->keyring)
 		return 0;
+	if (a == &dev_attr_tls_mode.attr &&
+	    !ctrl->opts->tls && !ctrl->opts->concat)
+		return 0;
 
 	return a->mode;
 }

---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260401-expose-tls-mode-10fdb5d459d4

Best regards,

Signature · 1 line
Daniel Wagner <[email protected]>
Reviewed-by on v3 1/1
#2 lore raw
In reply to Daniel Wagner
Quoted 8 lines · Daniel Wagner

It is not possible to determine the active TLS mode from the presence or absence of sysfs attributes like tls_key, tls_configured_key, or dhchap_secret.

With the introduction of the concat mode and optional DH-CHAP authentication, different configurations can result in identical sysfs state. This makes user space detection unreliable.

Quoted 5 lines

Expose the TLS mode explicitly to allow user space to unambiguously identify the active configuration and avoid fragile heuristics in nvme-cli.

Looks good, I look forward to 'nvme config --scan --dump' being able to get these configurations correct. Thanks Daniel.

Reviewed-by on v3 1/1
#3 lore raw
In reply to Daniel Wagner
Quoted 127 lines · Daniel Wagner

It is not possible to determine the active TLS mode from the presence or absence of sysfs attributes like tls_key, tls_configured_key, or dhchap_secret.

With the introduction of the concat mode and optional DH-CHAP authentication, different configurations can result in identical sysfs state. This makes user space detection unreliable.

Expose the TLS mode explicitly to allow user space to unambiguously identify the active configuration and avoid fragile heuristics in nvme-cli.

---
Fixed visibilty condition, the previous version used opts->tls_key but it should opts->tls.

Original cover letter (with fixed example):

I am extending the test suite for nvme-cli to cover the use case of nvme connect --tls/--concat.

Currently, nvme-cli uses heuristics to determine whether --tls was used to initiate the connection. With the introduction of --concat, these heuristics are no longer reliable.

By exposing the TLS mode explicitly, nvme config can now generate a configuration based on the currently active connection.

$ nvme connect --transport tcp --traddr 192.168.30.30 --trsvcid 4420  \
   		--hostnqn nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36  \
		--nqn nqn.io-1 --concat  \
		--dhchap-secret=DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:   \
		--dump-config --output-format json
[
   {
     "hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
     "hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
     "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
     "subsystems":[
       {
         "nqn":"nqn.io-1",
         "ports":[
           {
             "transport":"tcp",
             "traddr":"192.168.30.30",
             "trsvcid":"4420",
             "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
             "concat":true
           }
         ]
       }
     ]
   }
]
$ nvme config --scan --dump --output-format json /dev/nvme1
[
   {
     "hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36",
     "hostid":"befdec4c-2234-11b2-a85c-ca77c773af36",
     "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
     "subsystems":[
       {
         "nqn":"nqn.io-1",
         "ports":[
           {
             "transport":"tcp",
             "traddr":"192.168.30.30",
             "trsvcid":"4420",
             "dhchap_key":"DHHC-1:01:1+pb0VSbn3cBrOhwP5SHa6gwlbPikdZ0mmBKKXC74Sm0s0pb:",
             "concat":true
           }
         ]
       }
     ]
   }
]
$ cat /sys/class/nvme-fabrics/ctl/nvme1/tls_mode
concat
---
Changes in v3:
- Fixed visibilty conditions to opts->tls instead of opts->tls_key
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- fixed the example output
- tls_mode only visible when either tls or concat is enabled. avoids 'none'
- Link to v1: https://patch.msgid.link/[email protected]

---
  drivers/nvme/host/sysfs.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/nvme/host/sysfs.c +16 -0
index 16c6fea4b2db..df25c8fef063 100644
@@ -841,10 +841,26 @@ static ssize_t tls_keyring_show(struct device *dev,
  }
  static DEVICE_ATTR_RO(tls_keyring);
 
+static ssize_t tls_mode_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	const char *mode;
+
+	if (ctrl->opts->tls)
+		mode = "tls";
+	else
+		mode = "concat";
+
+	return sysfs_emit(buf, "%s\n", mode);
+}
+static DEVICE_ATTR_RO(tls_mode);
+
  static struct attribute *nvme_tls_attrs[] = {
  	&dev_attr_tls_key.attr,
  	&dev_attr_tls_configured_key.attr,
  	&dev_attr_tls_keyring.attr,
+	&dev_attr_tls_mode.attr,
  	NULL,
  };
 

drivers/nvme/host/sysfs.c static umode_t nvme_tls_attrs_are_visible(struct kobject *kobj, · line 890

Quoted 9 lines
drivers/nvme/host/sysfs.c +3 -0
@@ -866,6 +882,9 @@ static umode_t nvme_tls_attrs_are_visible(struct kobject *kobj,
  	if (a == &dev_attr_tls_keyring.attr &&
  	    !ctrl->opts->keyring)
  		return 0;
+	if (a == &dev_attr_tls_mode.attr &&
+	    !ctrl->opts->tls && !ctrl->opts->concat)
+		return 0;
 
  	return a->mode;
  }

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
maintainer
#4 lore raw
In reply to Daniel Wagner
Quoted 11 lines · Daniel Wagner

It is not possible to determine the active TLS mode from the presence or absence of sysfs attributes like tls_key, tls_configured_key, or dhchap_secret.

With the introduction of the concat mode and optional DH-CHAP authentication, different configurations can result in identical sysfs state. This makes user space detection unreliable.

Expose the TLS mode explicitly to allow user space to unambiguously identify the active configuration and avoid fragile heuristics in nvme-cli.

I'd applied v2 earlier, but I'll force push this one instead since we haven't done a pull request since then.