History

ublk: read any SQE values upfront

Since SQE memory is shared with userspace, we should only be reading it once. We cannot read it multiple times, particularly when it's read once for validation and then read again for the actual use. ublk_ch_uring_cmd() is safe when called as a retry operation, as the memory backing is stable at that point. But for normal issue, we want to ensure that we only read ublksrv_io_cmd once. Wrap the function in a helper that reads the value into an on-stack copy of the struct.

Jens Axboe committed 3 years ago

Commit 8c68ae31 parent 38a8c4d1 file · +20 −2Browse files

Unified · Split

drivers/block/ublk_drv.c+20−2
@@ -1261,9 +1261,10 @@ static void ublk_handle_need_get_data(struct ublk_device *ub, int q_id, · 1260 unmodified lines
12611261 ublk_queue_cmd(ubq, req);
12621262 }
12631263
1264−static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
1264+static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
1265+ unsigned int issue_flags,
1266+ struct ublksrv_io_cmd *ub_cmd)
12651267 {
1266− struct ublksrv_io_cmd *ub_cmd = (struct ublksrv_io_cmd *)cmd->cmd;
12671268 struct ublk_device *ub = cmd->file->private_data;
12681269 struct ublk_queue *ubq;
12691270 struct ublk_io *io;
@@ -1362,6 +1363,23 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) · 92 unmodified lines
13621363 return -EIOCBQUEUED;
13631364 }
13641365
1366+static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
1367+{
1368+ struct ublksrv_io_cmd *ub_src = (struct ublksrv_io_cmd *) cmd->cmd;
1369+ struct ublksrv_io_cmd ub_cmd;
1370+
1371+ /*
1372+ * Not necessary for async retry, but let's keep it simple and always
1373+ * copy the values to avoid any potential reuse.
1374+ */
1375+ ub_cmd.q_id = READ_ONCE(ub_src->q_id);
1376+ ub_cmd.tag = READ_ONCE(ub_src->tag);
1377+ ub_cmd.result = READ_ONCE(ub_src->result);
1378+ ub_cmd.addr = READ_ONCE(ub_src->addr);
1379+
1380+ return __ublk_ch_uring_cmd(cmd, issue_flags, &ub_cmd);
1381+}
1382+
13651383 static const struct file_operations ublk_ch_fops = {
13661384 .owner = THIS_MODULE,
13671385 .open = ublk_ch_open,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t