Skip to content

Commit 0e6c4fe

Browse files
arndbaxboe
authored andcommitted
nvme: tcp: fix compile-time checks for TLS mode
When CONFIG_NVME_KEYRING is enabled as a loadable module, but the TCP host code is built-in, it fails to link: arm-linux-gnueabi-ld: drivers/nvme/host/tcp.o: in function `nvme_tcp_setup_ctrl': tcp.c:(.text+0x1940): undefined reference to `nvme_tls_psk_default' The problem is that the compile-time conditionals are inconsistent here, using a mix of #ifdef CONFIG_NVME_TCP_TLS, IS_ENABLED(CONFIG_NVME_TCP_TLS) and IS_ENABLED(CONFIG_NVME_KEYRING) checks, with CONFIG_NVME_KEYRING controlling whether the implementation is actually built. Change it to use IS_ENABLED(CONFIG_NVME_KEYRING) checks consistently, which should help readability and make it less error-prone. Combining it with the check for the ctrl->opts->tls flag lets the compiler drop all the TLS code in configurations without this feature, which also helps runtime behavior in addition to avoiding the link failure. To make it possible for the compiler to build the dead code, both the tls_handshake_timeout variable and the TLS specific members of nvme_tcp_queue need to be moved out of the #ifdef block as well, but at least the former of these gets optimized out again. Signed-off-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 65e2a74 commit 0e6c4fe

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

drivers/nvme/host/tcp.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ static int so_priority;
3636
module_param(so_priority, int, 0644);
3737
MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
3838

39-
#ifdef CONFIG_NVME_TCP_TLS
4039
/*
4140
* TLS handshake timeout
4241
*/
4342
static int tls_handshake_timeout = 10;
43+
#ifdef CONFIG_NVME_TCP_TLS
4444
module_param(tls_handshake_timeout, int, 0644);
4545
MODULE_PARM_DESC(tls_handshake_timeout,
4646
"nvme TLS handshake timeout in seconds (default 10)");
@@ -161,10 +161,8 @@ struct nvme_tcp_queue {
161161
struct ahash_request *snd_hash;
162162
__le32 exp_ddgst;
163163
__le32 recv_ddgst;
164-
#ifdef CONFIG_NVME_TCP_TLS
165164
struct completion tls_complete;
166165
int tls_err;
167-
#endif
168166
struct page_frag_cache pf_cache;
169167

170168
void (*state_change)(struct sock *);
@@ -207,6 +205,14 @@ static inline int nvme_tcp_queue_id(struct nvme_tcp_queue *queue)
207205
return queue - queue->ctrl->queues;
208206
}
209207

208+
static inline bool nvme_tcp_tls(struct nvme_ctrl *ctrl)
209+
{
210+
if (!IS_ENABLED(CONFIG_NVME_TCP_TLS))
211+
return 0;
212+
213+
return ctrl->opts->tls;
214+
}
215+
210216
static inline struct blk_mq_tags *nvme_tcp_tagset(struct nvme_tcp_queue *queue)
211217
{
212218
u32 queue_idx = nvme_tcp_queue_id(queue);
@@ -1412,7 +1418,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
14121418
memset(&msg, 0, sizeof(msg));
14131419
iov.iov_base = icresp;
14141420
iov.iov_len = sizeof(*icresp);
1415-
if (queue->ctrl->ctrl.opts->tls) {
1421+
if (nvme_tcp_tls(&queue->ctrl->ctrl)) {
14161422
msg.msg_control = cbuf;
14171423
msg.msg_controllen = sizeof(cbuf);
14181424
}
@@ -1424,7 +1430,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
14241430
goto free_icresp;
14251431
}
14261432
ret = -ENOTCONN;
1427-
if (queue->ctrl->ctrl.opts->tls) {
1433+
if (nvme_tcp_tls(&queue->ctrl->ctrl)) {
14281434
ctype = tls_get_record_type(queue->sock->sk,
14291435
(struct cmsghdr *)cbuf);
14301436
if (ctype != TLS_RECORD_TYPE_DATA) {
@@ -1548,7 +1554,6 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
15481554
queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
15491555
}
15501556

1551-
#ifdef CONFIG_NVME_TCP_TLS
15521557
static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid)
15531558
{
15541559
struct nvme_tcp_queue *queue = data;
@@ -1625,14 +1630,6 @@ static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl,
16251630
}
16261631
return ret;
16271632
}
1628-
#else
1629-
static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl,
1630-
struct nvme_tcp_queue *queue,
1631-
key_serial_t pskid)
1632-
{
1633-
return -EPROTONOSUPPORT;
1634-
}
1635-
#endif
16361633

16371634
static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
16381635
key_serial_t pskid)
@@ -1759,7 +1756,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
17591756
}
17601757

17611758
/* If PSKs are configured try to start TLS */
1762-
if (pskid) {
1759+
if (IS_ENABLED(CONFIG_NVME_TCP_TLS) && pskid) {
17631760
ret = nvme_tcp_start_tls(nctrl, queue, pskid);
17641761
if (ret)
17651762
goto err_init_connect;
@@ -1916,7 +1913,7 @@ static int nvme_tcp_alloc_admin_queue(struct nvme_ctrl *ctrl)
19161913
int ret;
19171914
key_serial_t pskid = 0;
19181915

1919-
if (IS_ENABLED(CONFIG_NVME_TCP_TLS) && ctrl->opts->tls) {
1916+
if (nvme_tcp_tls(ctrl)) {
19201917
if (ctrl->opts->tls_key)
19211918
pskid = key_serial(ctrl->opts->tls_key);
19221919
else
@@ -1949,7 +1946,7 @@ static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl)
19491946
{
19501947
int i, ret;
19511948

1952-
if (ctrl->opts->tls && !ctrl->tls_key) {
1949+
if (nvme_tcp_tls(ctrl) && !ctrl->tls_key) {
19531950
dev_err(ctrl->device, "no PSK negotiated\n");
19541951
return -ENOKEY;
19551952
}

0 commit comments

Comments
 (0)