Commit 75883719 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

bdev/nvme: specify allowed DH-HMAC-CHAP digests/dhgroups



Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Id4a422d63d7a1526e1e78a84bd6e3b8624c9e41b
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22021


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent c6480ea7
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -3922,6 +3922,8 @@ io_path_stat | Optional | boolean | Enable collecting I/O stat
allow_accel_sequence       | Optional | boolean     | Allow NVMe bdevs to advertise support for accel sequences if the controller also supports them.  Default: `false`.
rdma_max_cq_size           | Optional | number      | Set the maximum size of a rdma completion queue. Default: 0 (unlimited)
rdma_cm_event_timeout_ms   | Optional | number      | Time to wait for RDMA CM events. Default: 0 (0 means using default value of driver).
dhchap_digests             | Optional | list        | List of allowed DH-HMAC-CHAP digests.
dhchap_dhgroups            | Optional | list        | List of allowed DH-HMAC-CHAP DH groups.

#### Example

@@ -3943,6 +3945,14 @@ request:
    "action_on_timeout": "reset",
    "io_queue_requests" : 2048,
    "delay_cmd_submit": true
    "dhchap_digests": [
      "sha384",
      "sha512"
    ],
    "dhchap_dhgroups": [
      "ffdhe6144",
      "ffdhe8192"
    ]
  },
  "jsonrpc": "2.0",
  "method": "bdev_nvme_set_options",
+33 −1
Original line number Diff line number Diff line
@@ -110,6 +110,17 @@ struct nvme_probe_skip_entry {
static TAILQ_HEAD(, nvme_probe_skip_entry) g_skipped_nvme_ctrlrs = TAILQ_HEAD_INITIALIZER(
			g_skipped_nvme_ctrlrs);

#define BDEV_NVME_DEFAULT_DIGESTS (SPDK_BIT(SPDK_NVMF_DHCHAP_HASH_SHA256) | \
				   SPDK_BIT(SPDK_NVMF_DHCHAP_HASH_SHA384) | \
				   SPDK_BIT(SPDK_NVMF_DHCHAP_HASH_SHA512))

#define BDEV_NVME_DEFAULT_DHGROUPS (SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_NULL) | \
				    SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_2048) | \
				    SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_3072) | \
				    SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_4096) | \
				    SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_6144) | \
				    SPDK_BIT(SPDK_NVMF_DHCHAP_DHGROUP_8192))

static struct spdk_bdev_nvme_opts g_opts = {
	.action_on_timeout = SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE,
	.timeout_us = 0,
@@ -135,6 +146,8 @@ static struct spdk_bdev_nvme_opts g_opts = {
	.nvme_error_stat = false,
	.io_path_stat = false,
	.allow_accel_sequence = false,
	.dhchap_digests = BDEV_NVME_DEFAULT_DIGESTS,
	.dhchap_dhgroups = BDEV_NVME_DEFAULT_DHGROUPS,
};

#define NVME_HOTPLUG_POLL_PERIOD_MAX			10000000ULL
@@ -6093,6 +6106,9 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid,
			free_nvme_async_probe_ctx(ctx);
			return -ENOKEY;
		}

		ctx->drv_opts.dhchap_digests = g_opts.dhchap_digests;
		ctx->drv_opts.dhchap_dhgroups = g_opts.dhchap_dhgroups;
	}

	if (nvme_bdev_ctrlr_get_by_name(base_name) == NULL || multipath) {
@@ -8136,6 +8152,7 @@ static void
bdev_nvme_opts_config_json(struct spdk_json_write_ctx *w)
{
	const char *action;
	uint32_t i;

	if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET) {
		action = "reset";
@@ -8177,6 +8194,21 @@ bdev_nvme_opts_config_json(struct spdk_json_write_ctx *w)
	spdk_json_write_named_bool(w, "allow_accel_sequence", g_opts.allow_accel_sequence);
	spdk_json_write_named_uint32(w, "rdma_max_cq_size", g_opts.rdma_max_cq_size);
	spdk_json_write_named_uint16(w, "rdma_cm_event_timeout_ms", g_opts.rdma_cm_event_timeout_ms);
	spdk_json_write_named_array_begin(w, "dhchap_digests");
	for (i = 0; i < 32; ++i) {
		if (g_opts.dhchap_digests & SPDK_BIT(i)) {
			spdk_json_write_string(w, spdk_nvme_dhchap_get_digest_name(i));
		}
	}
	spdk_json_write_array_end(w);
	spdk_json_write_named_array_begin(w, "dhchap_dhgroups");
	for (i = 0; i < 32; ++i) {
		if (g_opts.dhchap_dhgroups & SPDK_BIT(i)) {
			spdk_json_write_string(w, spdk_nvme_dhchap_get_dhgroup_name(i));
		}
	}

	spdk_json_write_array_end(w);
	spdk_json_write_object_end(w);

	spdk_json_write_object_end(w);
+2 −0
Original line number Diff line number Diff line
@@ -302,6 +302,8 @@ struct spdk_bdev_nvme_opts {
	bool allow_accel_sequence;
	uint32_t rdma_max_cq_size;
	uint16_t rdma_cm_event_timeout_ms;
	uint32_t dhchap_digests;
	uint32_t dhchap_dhgroups;
};

struct spdk_nvme_qpair *bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ch);
+68 −0
Original line number Diff line number Diff line
@@ -42,6 +42,72 @@ rpc_decode_action_on_timeout(const struct spdk_json_val *val, void *out)
	return 0;
}

static int
rpc_decode_digest(const struct spdk_json_val *val, void *out)
{
	uint32_t *flags = out;
	char *digest = NULL;
	int rc;

	rc = spdk_json_decode_string(val, &digest);
	if (rc != 0) {
		return rc;
	}

	rc = spdk_nvme_dhchap_get_digest_id(digest);
	if (rc >= 0) {
		*flags |= SPDK_BIT(rc);
		rc = 0;
	}
	free(digest);

	return rc;
}

static int
rpc_decode_digest_array(const struct spdk_json_val *val, void *out)
{
	uint32_t *flags = out;
	size_t count;

	*flags = 0;

	return spdk_json_decode_array(val, rpc_decode_digest, out, 32, &count, 0);
}

static int
rpc_decode_dhgroup(const struct spdk_json_val *val, void *out)
{
	uint32_t *flags = out;
	char *dhgroup = NULL;
	int rc;

	rc = spdk_json_decode_string(val, &dhgroup);
	if (rc != 0) {
		return rc;
	}

	rc = spdk_nvme_dhchap_get_dhgroup_id(dhgroup);
	if (rc >= 0) {
		*flags |= SPDK_BIT(rc);
		rc = 0;
	}
	free(dhgroup);

	return rc;
}

static int
rpc_decode_dhgroup_array(const struct spdk_json_val *val, void *out)
{
	uint32_t *flags = out;
	size_t count;

	*flags = 0;

	return spdk_json_decode_array(val, rpc_decode_dhgroup, out, 32, &count, 0);
}

static const struct spdk_json_object_decoder rpc_bdev_nvme_options_decoders[] = {
	{"action_on_timeout", offsetof(struct spdk_bdev_nvme_opts, action_on_timeout), rpc_decode_action_on_timeout, true},
	{"timeout_us", offsetof(struct spdk_bdev_nvme_opts, timeout_us), spdk_json_decode_uint64, true},
@@ -71,6 +137,8 @@ static const struct spdk_json_object_decoder rpc_bdev_nvme_options_decoders[] =
	{"allow_accel_sequence", offsetof(struct spdk_bdev_nvme_opts, allow_accel_sequence), spdk_json_decode_bool, true},
	{"rdma_max_cq_size", offsetof(struct spdk_bdev_nvme_opts, rdma_max_cq_size), spdk_json_decode_uint32, true},
	{"rdma_cm_event_timeout_ms", offsetof(struct spdk_bdev_nvme_opts, rdma_cm_event_timeout_ms), spdk_json_decode_uint16, true},
	{"dhchap_digests", offsetof(struct spdk_bdev_nvme_opts, dhchap_digests), rpc_decode_digest_array, true},
	{"dhchap_dhgroups", offsetof(struct spdk_bdev_nvme_opts, dhchap_dhgroups), rpc_decode_dhgroup_array, true},
};

static void
+10 −1
Original line number Diff line number Diff line
@@ -620,7 +620,8 @@ def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeo
                          transport_ack_timeout=None, ctrlr_loss_timeout_sec=None, reconnect_delay_sec=None,
                          fast_io_fail_timeout_sec=None, disable_auto_failback=None, generate_uuids=None,
                          transport_tos=None, nvme_error_stat=None, rdma_srq_size=None, io_path_stat=None,
                          allow_accel_sequence=None, rdma_max_cq_size=None, rdma_cm_event_timeout_ms=None):
                          allow_accel_sequence=None, rdma_max_cq_size=None, rdma_cm_event_timeout_ms=None,
                          dhchap_digests=None, dhchap_dhgroups=None):
    """Set options for the bdev nvme. This is startup command.

    Args:
@@ -669,6 +670,8 @@ def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeo
        controller also supports them. (optional)
        rdma_max_cq_size: The maximum size of a rdma completion queue. Default: 0 (unlimited) (optional)
        rdma_cm_event_timeout_ms: Time to wait for RDMA CM event. Only applicable for RDMA transports.
        dhchap_digests: List of allowed DH-HMAC-CHAP digests. (optional)
        dhchap_dhgroups: List of allowed DH-HMAC-CHAP DH groups. (optional)

    """
    params = {}
@@ -758,6 +761,12 @@ def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeo
    if rdma_cm_event_timeout_ms is not None:
        params['rdma_cm_event_timeout_ms'] = rdma_cm_event_timeout_ms

    if dhchap_digests is not None:
        params['dhchap_digests'] = dhchap_digests

    if dhchap_dhgroups is not None:
        params['dhchap_dhgroups'] = dhchap_dhgroups

    return client.call('bdev_nvme_set_options', params)


Loading