Skip to content

Commit e205ff4

Browse files
committed
Merge tag 'block-6.15-20250502' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - NVMe pull request via Christoph: - fix queue unquiesce check on PCI slot_reset (Keith Busch) - fix premature queue removal and I/O failover in nvme-tcp (Michael Liang) - don't restore null sk_state_change (Alistair Francis) - select CONFIG_TLS where needed (Alistair Francis) - always free derived key data (Hannes Reinecke) - more quirks (Wentao Guan) - ublk zero copy fix - ublk selftest fix for UBLK_F_NEED_GET_DATA * tag 'block-6.15-20250502' of git://git.kernel.dk/linux: nvmet-auth: always free derived key data nvmet-tcp: don't restore null sk_state_change nvmet-tcp: select CONFIG_TLS from CONFIG_NVME_TARGET_TCP_TLS nvme-tcp: select CONFIG_TLS from CONFIG_NVME_TCP_TLS nvme-tcp: fix premature queue removal and I/O failover nvme-pci: add quirks for WDC Blue SN550 15b7:5009 nvme-pci: add quirks for device 126f:1001 nvme-pci: fix queue unquiesce check on slot_reset ublk: remove the check of ublk_need_req_ref() from __ublk_check_and_get_req ublk: enhance check for register/unregister io buffer command ublk: decouple zero copy from user copy selftests: ublk: fix UBLK_F_NEED_GET_DATA
2 parents 731e5e1 + 6d732e8 commit e205ff4

File tree

12 files changed

+133
-36
lines changed

12 files changed

+133
-36
lines changed

drivers/block/ublk_drv.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,10 @@ struct ublk_params_header {
201201
static void ublk_stop_dev_unlocked(struct ublk_device *ub);
202202
static void ublk_abort_queue(struct ublk_device *ub, struct ublk_queue *ubq);
203203
static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
204-
struct ublk_queue *ubq, int tag, size_t offset);
204+
const struct ublk_queue *ubq, int tag, size_t offset);
205205
static inline unsigned int ublk_req_build_flags(struct request *req);
206206
static inline struct ublksrv_io_desc *ublk_get_iod(struct ublk_queue *ubq,
207207
int tag);
208-
static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub)
209-
{
210-
return ub->dev_info.flags & (UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY);
211-
}
212-
213208
static inline bool ublk_dev_is_zoned(const struct ublk_device *ub)
214209
{
215210
return ub->dev_info.flags & UBLK_F_ZONED;
@@ -609,23 +604,31 @@ static void ublk_apply_params(struct ublk_device *ub)
609604
ublk_dev_param_zoned_apply(ub);
610605
}
611606

607+
static inline bool ublk_support_zero_copy(const struct ublk_queue *ubq)
608+
{
609+
return ubq->flags & UBLK_F_SUPPORT_ZERO_COPY;
610+
}
611+
612612
static inline bool ublk_support_user_copy(const struct ublk_queue *ubq)
613613
{
614-
return ubq->flags & (UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY);
614+
return ubq->flags & UBLK_F_USER_COPY;
615615
}
616616

617617
static inline bool ublk_need_map_io(const struct ublk_queue *ubq)
618618
{
619-
return !ublk_support_user_copy(ubq);
619+
return !ublk_support_user_copy(ubq) && !ublk_support_zero_copy(ubq);
620620
}
621621

622622
static inline bool ublk_need_req_ref(const struct ublk_queue *ubq)
623623
{
624624
/*
625625
* read()/write() is involved in user copy, so request reference
626626
* has to be grabbed
627+
*
628+
* for zero copy, request buffer need to be registered to io_uring
629+
* buffer table, so reference is needed
627630
*/
628-
return ublk_support_user_copy(ubq);
631+
return ublk_support_user_copy(ubq) || ublk_support_zero_copy(ubq);
629632
}
630633

631634
static inline void ublk_init_req_ref(const struct ublk_queue *ubq,
@@ -1946,13 +1949,20 @@ static void ublk_io_release(void *priv)
19461949
}
19471950

19481951
static int ublk_register_io_buf(struct io_uring_cmd *cmd,
1949-
struct ublk_queue *ubq, unsigned int tag,
1952+
const struct ublk_queue *ubq, unsigned int tag,
19501953
unsigned int index, unsigned int issue_flags)
19511954
{
19521955
struct ublk_device *ub = cmd->file->private_data;
1956+
const struct ublk_io *io = &ubq->ios[tag];
19531957
struct request *req;
19541958
int ret;
19551959

1960+
if (!ublk_support_zero_copy(ubq))
1961+
return -EINVAL;
1962+
1963+
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
1964+
return -EINVAL;
1965+
19561966
req = __ublk_check_and_get_req(ub, ubq, tag, 0);
19571967
if (!req)
19581968
return -EINVAL;
@@ -1968,8 +1978,17 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
19681978
}
19691979

19701980
static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
1981+
const struct ublk_queue *ubq, unsigned int tag,
19711982
unsigned int index, unsigned int issue_flags)
19721983
{
1984+
const struct ublk_io *io = &ubq->ios[tag];
1985+
1986+
if (!ublk_support_zero_copy(ubq))
1987+
return -EINVAL;
1988+
1989+
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
1990+
return -EINVAL;
1991+
19731992
return io_buffer_unregister_bvec(cmd, index, issue_flags);
19741993
}
19751994

@@ -2073,7 +2092,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
20732092
case UBLK_IO_REGISTER_IO_BUF:
20742093
return ublk_register_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
20752094
case UBLK_IO_UNREGISTER_IO_BUF:
2076-
return ublk_unregister_io_buf(cmd, ub_cmd->addr, issue_flags);
2095+
return ublk_unregister_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
20772096
case UBLK_IO_FETCH_REQ:
20782097
ret = ublk_fetch(cmd, ubq, io, ub_cmd->addr);
20792098
if (ret)
@@ -2125,13 +2144,10 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
21252144
}
21262145

21272146
static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
2128-
struct ublk_queue *ubq, int tag, size_t offset)
2147+
const struct ublk_queue *ubq, int tag, size_t offset)
21292148
{
21302149
struct request *req;
21312150

2132-
if (!ublk_need_req_ref(ubq))
2133-
return NULL;
2134-
21352151
req = blk_mq_tag_to_rq(ub->tag_set.tags[ubq->q_id], tag);
21362152
if (!req)
21372153
return NULL;
@@ -2245,6 +2261,9 @@ static struct request *ublk_check_and_get_req(struct kiocb *iocb,
22452261
if (!ubq)
22462262
return ERR_PTR(-EINVAL);
22472263

2264+
if (!ublk_support_user_copy(ubq))
2265+
return ERR_PTR(-EACCES);
2266+
22482267
if (tag >= ubq->q_depth)
22492268
return ERR_PTR(-EINVAL);
22502269

@@ -2783,13 +2802,18 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
27832802
ub->dev_info.flags |= UBLK_F_CMD_IOCTL_ENCODE |
27842803
UBLK_F_URING_CMD_COMP_IN_TASK;
27852804

2786-
/* GET_DATA isn't needed any more with USER_COPY */
2787-
if (ublk_dev_is_user_copy(ub))
2805+
/* GET_DATA isn't needed any more with USER_COPY or ZERO COPY */
2806+
if (ub->dev_info.flags & (UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY))
27882807
ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA;
27892808

2790-
/* Zoned storage support requires user copy feature */
2809+
/*
2810+
* Zoned storage support requires reuse `ublksrv_io_cmd->addr` for
2811+
* returning write_append_lba, which is only allowed in case of
2812+
* user copy or zero copy
2813+
*/
27912814
if (ublk_dev_is_zoned(ub) &&
2792-
(!IS_ENABLED(CONFIG_BLK_DEV_ZONED) || !ublk_dev_is_user_copy(ub))) {
2815+
(!IS_ENABLED(CONFIG_BLK_DEV_ZONED) || !(ub->dev_info.flags &
2816+
(UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY)))) {
27932817
ret = -EINVAL;
27942818
goto out_free_dev_number;
27952819
}

drivers/nvme/host/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ config NVME_TCP_TLS
102102
depends on NVME_TCP
103103
select NET_HANDSHAKE
104104
select KEYS
105+
select TLS
105106
help
106107
Enables TLS encryption for NVMe TCP using the netlink handshake API.
107108

drivers/nvme/host/pci.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3575,7 +3575,7 @@ static pci_ers_result_t nvme_slot_reset(struct pci_dev *pdev)
35753575

35763576
dev_info(dev->ctrl.device, "restart after slot reset\n");
35773577
pci_restore_state(pdev);
3578-
if (!nvme_try_sched_reset(&dev->ctrl))
3578+
if (nvme_try_sched_reset(&dev->ctrl))
35793579
nvme_unquiesce_io_queues(&dev->ctrl);
35803580
return PCI_ERS_RESULT_RECOVERED;
35813581
}
@@ -3623,6 +3623,9 @@ static const struct pci_device_id nvme_id_table[] = {
36233623
.driver_data = NVME_QUIRK_BOGUS_NID, },
36243624
{ PCI_DEVICE(0x1217, 0x8760), /* O2 Micro 64GB Steam Deck */
36253625
.driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, },
3626+
{ PCI_DEVICE(0x126f, 0x1001), /* Silicon Motion generic */
3627+
.driver_data = NVME_QUIRK_NO_DEEPEST_PS |
3628+
NVME_QUIRK_IGNORE_DEV_SUBNQN, },
36263629
{ PCI_DEVICE(0x126f, 0x2262), /* Silicon Motion generic */
36273630
.driver_data = NVME_QUIRK_NO_DEEPEST_PS |
36283631
NVME_QUIRK_BOGUS_NID, },
@@ -3646,6 +3649,9 @@ static const struct pci_device_id nvme_id_table[] = {
36463649
NVME_QUIRK_IGNORE_DEV_SUBNQN, },
36473650
{ PCI_DEVICE(0x15b7, 0x5008), /* Sandisk SN530 */
36483651
.driver_data = NVME_QUIRK_BROKEN_MSI },
3652+
{ PCI_DEVICE(0x15b7, 0x5009), /* Sandisk SN550 */
3653+
.driver_data = NVME_QUIRK_BROKEN_MSI |
3654+
NVME_QUIRK_NO_DEEPEST_PS },
36493655
{ PCI_DEVICE(0x1987, 0x5012), /* Phison E12 */
36503656
.driver_data = NVME_QUIRK_BOGUS_NID, },
36513657
{ PCI_DEVICE(0x1987, 0x5016), /* Phison E16 */

drivers/nvme/host/tcp.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ static void __nvme_tcp_stop_queue(struct nvme_tcp_queue *queue)
19461946
cancel_work_sync(&queue->io_work);
19471947
}
19481948

1949-
static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
1949+
static void nvme_tcp_stop_queue_nowait(struct nvme_ctrl *nctrl, int qid)
19501950
{
19511951
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
19521952
struct nvme_tcp_queue *queue = &ctrl->queues[qid];
@@ -1965,6 +1965,31 @@ static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
19651965
mutex_unlock(&queue->queue_lock);
19661966
}
19671967

1968+
static void nvme_tcp_wait_queue(struct nvme_ctrl *nctrl, int qid)
1969+
{
1970+
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
1971+
struct nvme_tcp_queue *queue = &ctrl->queues[qid];
1972+
int timeout = 100;
1973+
1974+
while (timeout > 0) {
1975+
if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags) ||
1976+
!sk_wmem_alloc_get(queue->sock->sk))
1977+
return;
1978+
msleep(2);
1979+
timeout -= 2;
1980+
}
1981+
dev_warn(nctrl->device,
1982+
"qid %d: timeout draining sock wmem allocation expired\n",
1983+
qid);
1984+
}
1985+
1986+
static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
1987+
{
1988+
nvme_tcp_stop_queue_nowait(nctrl, qid);
1989+
nvme_tcp_wait_queue(nctrl, qid);
1990+
}
1991+
1992+
19681993
static void nvme_tcp_setup_sock_ops(struct nvme_tcp_queue *queue)
19691994
{
19701995
write_lock_bh(&queue->sock->sk->sk_callback_lock);
@@ -2032,7 +2057,9 @@ static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl)
20322057
int i;
20332058

20342059
for (i = 1; i < ctrl->queue_count; i++)
2035-
nvme_tcp_stop_queue(ctrl, i);
2060+
nvme_tcp_stop_queue_nowait(ctrl, i);
2061+
for (i = 1; i < ctrl->queue_count; i++)
2062+
nvme_tcp_wait_queue(ctrl, i);
20362063
}
20372064

20382065
static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl,

drivers/nvme/target/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ config NVME_TARGET_TCP_TLS
9898
bool "NVMe over Fabrics TCP target TLS encryption support"
9999
depends on NVME_TARGET_TCP
100100
select NET_HANDSHAKE
101+
select TLS
101102
help
102103
Enables TLS encryption for the NVMe TCP target using the netlink handshake API.
103104

drivers/nvme/target/auth.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,12 @@ void nvmet_auth_insert_psk(struct nvmet_sq *sq)
600600
pr_warn("%s: ctrl %d qid %d failed to refresh key, error %ld\n",
601601
__func__, sq->ctrl->cntlid, sq->qid, PTR_ERR(tls_key));
602602
tls_key = NULL;
603-
kfree_sensitive(tls_psk);
604603
}
605604
if (sq->ctrl->tls_key)
606605
key_put(sq->ctrl->tls_key);
607606
sq->ctrl->tls_key = tls_key;
608607
#endif
609-
608+
kfree_sensitive(tls_psk);
610609
out_free_digest:
611610
kfree_sensitive(digest);
612611
out_free_psk:

drivers/nvme/target/tcp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,9 @@ static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue)
15601560
{
15611561
struct socket *sock = queue->sock;
15621562

1563+
if (!queue->state_change)
1564+
return;
1565+
15631566
write_lock_bh(&sock->sk->sk_callback_lock);
15641567
sock->sk->sk_data_ready = queue->data_ready;
15651568
sock->sk->sk_state_change = queue->state_change;

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ TEST_PROGS += test_generic_03.sh
99
TEST_PROGS += test_generic_04.sh
1010
TEST_PROGS += test_generic_05.sh
1111
TEST_PROGS += test_generic_06.sh
12+
TEST_PROGS += test_generic_07.sh
1213

1314
TEST_PROGS += test_null_01.sh
1415
TEST_PROGS += test_null_02.sh

tools/testing/selftests/ublk/kublk.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,17 @@ int ublk_queue_io_cmd(struct ublk_queue *q, struct ublk_io *io, unsigned tag)
536536
if (!(io->flags & UBLKSRV_IO_FREE))
537537
return 0;
538538

539-
/* we issue because we need either fetching or committing */
539+
/*
540+
* we issue because we need either fetching or committing or
541+
* getting data
542+
*/
540543
if (!(io->flags &
541-
(UBLKSRV_NEED_FETCH_RQ | UBLKSRV_NEED_COMMIT_RQ_COMP)))
544+
(UBLKSRV_NEED_FETCH_RQ | UBLKSRV_NEED_COMMIT_RQ_COMP | UBLKSRV_NEED_GET_DATA)))
542545
return 0;
543546

544-
if (io->flags & UBLKSRV_NEED_COMMIT_RQ_COMP)
547+
if (io->flags & UBLKSRV_NEED_GET_DATA)
548+
cmd_op = UBLK_U_IO_NEED_GET_DATA;
549+
else if (io->flags & UBLKSRV_NEED_COMMIT_RQ_COMP)
545550
cmd_op = UBLK_U_IO_COMMIT_AND_FETCH_REQ;
546551
else if (io->flags & UBLKSRV_NEED_FETCH_RQ)
547552
cmd_op = UBLK_U_IO_FETCH_REQ;
@@ -658,6 +663,9 @@ static void ublk_handle_cqe(struct io_uring *r,
658663
assert(tag < q->q_depth);
659664
if (q->tgt_ops->queue_io)
660665
q->tgt_ops->queue_io(q, tag);
666+
} else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
667+
io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
668+
ublk_queue_io_cmd(q, io, tag);
661669
} else {
662670
/*
663671
* COMMIT_REQ will be completed immediately since no fetching
@@ -1237,7 +1245,7 @@ static void __cmd_create_help(char *exe, bool recovery)
12371245

12381246
printf("%s %s -t [null|loop|stripe|fault_inject] [-q nr_queues] [-d depth] [-n dev_id]\n",
12391247
exe, recovery ? "recover" : "add");
1240-
printf("\t[--foreground] [--quiet] [-z] [--debug_mask mask] [-r 0|1 ] [-g 0|1]\n");
1248+
printf("\t[--foreground] [--quiet] [-z] [--debug_mask mask] [-r 0|1 ] [-g]\n");
12411249
printf("\t[-e 0|1 ] [-i 0|1]\n");
12421250
printf("\t[target options] [backfile1] [backfile2] ...\n");
12431251
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
@@ -1313,7 +1321,7 @@ int main(int argc, char *argv[])
13131321

13141322
opterr = 0;
13151323
optind = 2;
1316-
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:az",
1324+
while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:gaz",
13171325
longopts, &option_idx)) != -1) {
13181326
switch (opt) {
13191327
case 'a':
@@ -1351,9 +1359,7 @@ int main(int argc, char *argv[])
13511359
ctx.flags |= UBLK_F_USER_RECOVERY | UBLK_F_USER_RECOVERY_REISSUE;
13521360
break;
13531361
case 'g':
1354-
value = strtol(optarg, NULL, 10);
1355-
if (value)
1356-
ctx.flags |= UBLK_F_NEED_GET_DATA;
1362+
ctx.flags |= UBLK_F_NEED_GET_DATA;
13571363
break;
13581364
case 0:
13591365
if (!strcmp(longopts[option_idx].name, "debug_mask"))

tools/testing/selftests/ublk/kublk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct ublk_io {
115115
#define UBLKSRV_NEED_FETCH_RQ (1UL << 0)
116116
#define UBLKSRV_NEED_COMMIT_RQ_COMP (1UL << 1)
117117
#define UBLKSRV_IO_FREE (1UL << 2)
118+
#define UBLKSRV_NEED_GET_DATA (1UL << 3)
118119
unsigned short flags;
119120
unsigned short refs; /* used by target code only */
120121

0 commit comments

Comments
 (0)