Skip to content

Commit e46b7c3

Browse files
author
CKI KWF Bot
committed
Merge: io_uring: update to v6.14
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7243 Update io_uring to v6.14 + fixes and stable Ccs JIRA: https://issues.redhat.com/browse/RHEL-105612 Omitted-fix: 334f795 ("Revert "io_uring/rsrc: simplify the bvec iter count calculation"") This isn't a fix for a patch in this series. It only references a patch here, and the tooling suggests it might be an issue (but it isn't). Omitted-fix: af74e5f ("tools headers: Update the VFS headers with the kernel sources") Omitted-fix: ed86525 ("tools/include: Sync network socket headers with the kernel sources") Omitted-fix: c64eff3 ("io_uring/kbuf: fix signedness in this_len calculation") This commit identified the wrong buggy commit (it should have had fixes for cf9536e). We don't have the buggy commit. Signed-off-by: Jeff Moyer <jmoyer@redhat.com> Approved-by: Antoine Tenart <atenart@redhat.com> Approved-by: Brian Foster <bfoster@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents ec5f4d3 + bcf5345 commit e46b7c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4484
-2788
lines changed

block/blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ blk_mode_t file_to_blk_mode(struct file *file);
615615
int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode,
616616
loff_t lstart, loff_t lend);
617617
long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg);
618+
int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags);
618619
long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg);
619620

620621
extern const struct address_space_operations def_blk_aops;

block/fops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/init.h>
88
#include <linux/mm.h>
99
#include <linux/blkdev.h>
10+
#include <linux/blk-integrity.h>
1011
#include <linux/buffer_head.h>
1112
#include <linux/mpage.h>
1213
#include <linux/uio.h>
@@ -17,6 +18,7 @@
1718
#include <linux/fs.h>
1819
#include <linux/iomap.h>
1920
#include <linux/module.h>
21+
#include <linux/io_uring/cmd.h>
2022
#include "blk.h"
2123

2224
static inline struct inode *bdev_file_inode(struct file *file)
@@ -655,6 +657,8 @@ static int blkdev_open(struct inode *inode, struct file *filp)
655657

656658
if (bdev_can_atomic_write(bdev))
657659
filp->f_mode |= FMODE_CAN_ATOMIC_WRITE;
660+
if (blk_get_integrity(bdev->bd_disk))
661+
filp->f_mode |= FMODE_HAS_METADATA;
658662

659663
ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
660664
if (ret)
@@ -916,6 +920,7 @@ const struct file_operations def_blk_fops = {
916920
.splice_read = generic_file_splice_read,
917921
.splice_write = iter_file_splice_write,
918922
.fallocate = blkdev_fallocate,
923+
.uring_cmd = blkdev_uring_cmd,
919924
.fop_flags = FOP_BUFFER_RASYNC,
920925
};
921926

block/ioctl.c

Lines changed: 144 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <linux/blktrace_api.h>
1212
#include <linux/pr.h>
1313
#include <linux/uaccess.h>
14+
#include <linux/pagemap.h>
15+
#include <linux/io_uring/cmd.h>
16+
#include <uapi/linux/blkdev.h>
1417
#include "blk.h"
1518

1619
static int blkpg_do_ioctl(struct block_device *bdev,
@@ -92,42 +95,55 @@ static int compat_blkpg_ioctl(struct block_device *bdev,
9295
}
9396
#endif
9497

98+
/*
99+
* Check that [start, start + len) is a valid range from the block device's
100+
* perspective, including verifying that it can be correctly translated into
101+
* logical block addresses.
102+
*/
103+
static int blk_validate_byte_range(struct block_device *bdev,
104+
uint64_t start, uint64_t len)
105+
{
106+
unsigned int bs_mask = bdev_logical_block_size(bdev) - 1;
107+
uint64_t end;
108+
109+
if ((start | len) & bs_mask)
110+
return -EINVAL;
111+
if (!len)
112+
return -EINVAL;
113+
if (check_add_overflow(start, len, &end) || end > bdev_nr_bytes(bdev))
114+
return -EINVAL;
115+
116+
return 0;
117+
}
118+
95119
static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
96120
unsigned long arg)
97121
{
98-
unsigned int bs_mask = bdev_logical_block_size(bdev) - 1;
99122
struct inode *inode = bdev->bd_inode;
100-
uint64_t range[2], start, len, end;
123+
uint64_t range[2], start, len;
101124
struct bio *prev = NULL, *bio;
102125
sector_t sector, nr_sects;
103126
struct blk_plug plug;
104127
int err;
105128

106-
if (!(mode & BLK_OPEN_WRITE))
107-
return -EBADF;
108-
109-
if (!bdev_max_discard_sectors(bdev))
110-
return -EOPNOTSUPP;
111-
if (bdev_read_only(bdev))
112-
return -EPERM;
113-
114129
if (copy_from_user(range, (void __user *)arg, sizeof(range)))
115130
return -EFAULT;
116-
117131
start = range[0];
118132
len = range[1];
119133

120-
if (!len)
121-
return -EINVAL;
122-
if ((start | len) & bs_mask)
123-
return -EINVAL;
134+
if (!bdev_max_discard_sectors(bdev))
135+
return -EOPNOTSUPP;
124136

125-
if (check_add_overflow(start, len, &end) ||
126-
end > bdev_nr_bytes(bdev))
127-
return -EINVAL;
137+
if (!(mode & BLK_OPEN_WRITE))
138+
return -EBADF;
139+
if (bdev_read_only(bdev))
140+
return -EPERM;
141+
err = blk_validate_byte_range(bdev, start, len);
142+
if (err)
143+
return err;
128144

129145
filemap_invalidate_lock(inode->i_mapping);
130-
err = truncate_bdev_range(bdev, mode, start, end - 1);
146+
err = truncate_bdev_range(bdev, mode, start, start + len - 1);
131147
if (err)
132148
goto fail;
133149

@@ -734,3 +750,112 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
734750
return ret;
735751
}
736752
#endif
753+
754+
struct blk_iou_cmd {
755+
int res;
756+
bool nowait;
757+
};
758+
759+
static void blk_cmd_complete(struct io_uring_cmd *cmd, unsigned int issue_flags)
760+
{
761+
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
762+
763+
if (bic->res == -EAGAIN && bic->nowait)
764+
io_uring_cmd_issue_blocking(cmd);
765+
else
766+
io_uring_cmd_done(cmd, bic->res, 0, issue_flags);
767+
}
768+
769+
static void bio_cmd_bio_end_io(struct bio *bio)
770+
{
771+
struct io_uring_cmd *cmd = bio->bi_private;
772+
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
773+
774+
if (unlikely(bio->bi_status) && !bic->res)
775+
bic->res = blk_status_to_errno(bio->bi_status);
776+
777+
io_uring_cmd_do_in_task_lazy(cmd, blk_cmd_complete);
778+
bio_put(bio);
779+
}
780+
781+
static int blkdev_cmd_discard(struct io_uring_cmd *cmd,
782+
struct block_device *bdev,
783+
uint64_t start, uint64_t len, bool nowait)
784+
{
785+
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
786+
gfp_t gfp = nowait ? GFP_NOWAIT : GFP_KERNEL;
787+
sector_t sector = start >> SECTOR_SHIFT;
788+
sector_t nr_sects = len >> SECTOR_SHIFT;
789+
struct bio *prev = NULL, *bio;
790+
int err;
791+
792+
if (!bdev_max_discard_sectors(bdev))
793+
return -EOPNOTSUPP;
794+
if (!(file_to_blk_mode(cmd->file) & BLK_OPEN_WRITE))
795+
return -EBADF;
796+
if (bdev_read_only(bdev))
797+
return -EPERM;
798+
err = blk_validate_byte_range(bdev, start, len);
799+
if (err)
800+
return err;
801+
802+
err = filemap_invalidate_pages(bdev->bd_inode->i_mapping, start,
803+
start + len - 1, nowait);
804+
if (err)
805+
return err;
806+
807+
while (true) {
808+
bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects, gfp);
809+
if (!bio)
810+
break;
811+
if (nowait) {
812+
/*
813+
* Don't allow multi-bio non-blocking submissions as
814+
* subsequent bios may fail but we won't get a direct
815+
* indication of that. Normally, the caller should
816+
* retry from a blocking context.
817+
*/
818+
if (unlikely(nr_sects)) {
819+
bio_put(bio);
820+
return -EAGAIN;
821+
}
822+
bio->bi_opf |= REQ_NOWAIT;
823+
}
824+
825+
prev = bio_chain_and_submit(prev, bio);
826+
}
827+
if (unlikely(!prev))
828+
return -EAGAIN;
829+
if (unlikely(nr_sects))
830+
bic->res = -EAGAIN;
831+
832+
prev->bi_private = cmd;
833+
prev->bi_end_io = bio_cmd_bio_end_io;
834+
submit_bio(prev);
835+
return -EIOCBQUEUED;
836+
}
837+
838+
int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
839+
{
840+
struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host);
841+
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
842+
const struct io_uring_sqe *sqe = cmd->sqe;
843+
u32 cmd_op = cmd->cmd_op;
844+
uint64_t start, len;
845+
846+
if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
847+
sqe->rw_flags || sqe->file_index))
848+
return -EINVAL;
849+
850+
bic->res = 0;
851+
bic->nowait = issue_flags & IO_URING_F_NONBLOCK;
852+
853+
start = READ_ONCE(sqe->addr);
854+
len = READ_ONCE(sqe->addr3);
855+
856+
switch (cmd_op) {
857+
case BLOCK_URING_CMD_DISCARD:
858+
return blkdev_cmd_discard(cmd, bdev, start, len, bic->nowait);
859+
}
860+
return -EINVAL;
861+
}

fs/aio.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,24 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events)
591591

592592
void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
593593
{
594-
struct aio_kiocb *req = container_of(iocb, struct aio_kiocb, rw);
595-
struct kioctx *ctx = req->ki_ctx;
594+
struct aio_kiocb *req;
595+
struct kioctx *ctx;
596596
unsigned long flags;
597597

598+
/*
599+
* kiocb didn't come from aio or is neither a read nor a write, hence
600+
* ignore it.
601+
*/
602+
if (!(iocb->ki_flags & IOCB_AIO_RW))
603+
return;
604+
605+
req = container_of(iocb, struct aio_kiocb, rw);
606+
598607
if (WARN_ON_ONCE(!list_empty(&req->ki_list)))
599608
return;
600609

610+
ctx = req->ki_ctx;
611+
601612
spin_lock_irqsave(&ctx->ctx_lock, flags);
602613
list_add_tail(&req->ki_list, &ctx->active_reqs);
603614
req->ki_cancel = cancel;
@@ -1481,7 +1492,7 @@ static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb, int rw_type)
14811492
req->ki_complete = aio_complete_rw;
14821493
req->private = NULL;
14831494
req->ki_pos = iocb->aio_offset;
1484-
req->ki_flags = iocb_flags(req->ki_filp);
1495+
req->ki_flags = iocb_flags(req->ki_filp) | IOCB_AIO_RW;
14851496
if (iocb->aio_flags & IOCB_FLAG_RESFD)
14861497
req->ki_flags |= IOCB_EVENTFD;
14871498
if (iocb->aio_flags & IOCB_FLAG_IOPRIO) {

include/linux/fs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
164164
/* File supports DIRECT IO */
165165
#define FMODE_CAN_ODIRECT ((__force fmode_t)0x400000)
166166

167+
/* Supports IOCB_HAS_METADATA */
168+
#define FMODE_HAS_METADATA ((__force fmode_t)0x800000)
169+
167170
/* File was opened by fanotify and shouldn't generate fanotify events */
168171
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
169172

@@ -332,6 +335,8 @@ struct readahead_control;
332335
* unrelated IO (like cache flushing, new IO generation, etc).
333336
*/
334337
#define IOCB_DIO_CALLER_COMP (1 << 22)
338+
/* kiocb is a read or write operation submitted by fs/aio.c. */
339+
#define IOCB_AIO_RW (1 << 23)
335340
#define IOCB_HAS_METADATA (1 << 24)
336341

337342
/* for use in trace events */

include/linux/io_uring.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ const char *io_uring_get_opcode(u8 opcode);
1414

1515
static inline void io_uring_files_cancel(void)
1616
{
17-
if (current->io_uring) {
18-
io_uring_unreg_ringfd();
17+
if (current->io_uring)
1918
__io_uring_cancel(false);
20-
}
2119
}
2220
static inline void io_uring_task_cancel(void)
2321
{

include/linux/io_uring/cmd.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@ struct io_uring_cmd {
1818
u8 pdu[32]; /* available inline for free use */
1919
};
2020

21+
struct io_uring_cmd_data {
22+
void *op_data;
23+
struct io_uring_sqe sqes[2];
24+
};
25+
2126
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
2227
{
2328
return sqe->cmd;
2429
}
2530

31+
static inline void io_uring_cmd_private_sz_check(size_t cmd_sz)
32+
{
33+
BUILD_BUG_ON(cmd_sz > sizeof_field(struct io_uring_cmd, pdu));
34+
}
35+
#define io_uring_cmd_to_pdu(cmd, pdu_type) ( \
36+
io_uring_cmd_private_sz_check(sizeof(pdu_type)), \
37+
((pdu_type *)&(cmd)->pdu) \
38+
)
39+
2640
#if defined(CONFIG_IO_URING)
2741
int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
2842
struct iov_iter *iter, void *ioucmd,
@@ -35,7 +49,7 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
3549
* Note: the caller should never hard code @issue_flags and is only allowed
3650
* to pass the mask provided by the core io_uring code.
3751
*/
38-
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
52+
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, u64 res2,
3953
unsigned issue_flags);
4054

4155
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
@@ -49,6 +63,9 @@ void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
4963
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
5064
unsigned int issue_flags);
5165

66+
/* Execute the request from a blocking context */
67+
void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd);
68+
5269
#else
5370
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
5471
struct iov_iter *iter, void *ioucmd,
@@ -57,7 +74,7 @@ static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
5774
return -EOPNOTSUPP;
5875
}
5976
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
60-
ssize_t ret2, unsigned issue_flags)
77+
u64 ret2, unsigned issue_flags)
6178
{
6279
}
6380
static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
@@ -69,6 +86,9 @@ static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
6986
unsigned int issue_flags)
7087
{
7188
}
89+
static inline void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd)
90+
{
91+
}
7292
#endif
7393

7494
/*
@@ -97,7 +117,12 @@ static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
97117

98118
static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
99119
{
100-
return cmd_to_io_kiocb(cmd)->task;
120+
return cmd_to_io_kiocb(cmd)->tctx->task;
121+
}
122+
123+
static inline struct io_uring_cmd_data *io_uring_cmd_get_async_data(struct io_uring_cmd *cmd)
124+
{
125+
return cmd_to_io_kiocb(cmd)->async_data;
101126
}
102127

103128
#endif /* _LINUX_IO_URING_CMD_H */

0 commit comments

Comments
 (0)