fs: create kiocb_{start,end}_write() helpers
Subsystems (5)
Amir Goldstein
maintainerPATCH v2 1/1 fs: create kiocb_{start,end}_write() helpers
aio, io_uring, cachefiles and overlayfs, all open code an ugly variant of file_{start,end}_write() to silence lockdep warnings.
Create helpers for this lockdep dance and use the helpers in all the callers.
Use a new iocb flag IOCB_WRITE_STARTED to indicate if sb_start_write() was called.
---
Christian,
This is an attempt to consolidate the open coded lockdep fooling in all those async io submitters into a single helper.
The idea to do that consolidation was suggested by Jan. The (questionable) idea to use an IOCB_ flag was mine.
This re-factoring is part of a larger vfs cleanup I am doing for fanotify permission events. The complete series is not ready for prime time yet, but this one patch is independent and I would love to get it reviewed/merged a head of the rest.
Thanks,
Amir.
Changes since v1:
- Leave ISREG checks in callers (Jens)
- Leave setting IOCB_WRITE flag in callers
fs/aio.c | 26 +++---------------- fs/cachefiles/io.c | 16 +++--------- fs/overlayfs/file.c | 15 +++++------ include/linux/fs.h | 62 +++++++++++++++++++++++++++++++++++++++++++-- io_uring/rw.c | 36 +++++--------------------- 5 files changed, 79 insertions(+), 76 deletions(-)
fs/aio.c +4 -22
@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); - -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE ) +kiocb_end_write (kiocb); iocb->ki_res.res = res; iocb->ki_res.res2 =0 ;
@@ -1581,17 +1572,8 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,return ret; ret =rw_verify_area (WRITE , file, &req->ki_pos,iov_iter_count (&iter));if (!ret) { -/* -* Open-code file_start_write here to grab freeze protection, -* which will be released by another thread in -* aio_complete_rw(). Fool lockdep by telling it the lock got -* released so that it doesn't complain about the held lock when -* we return to userspace. -*/ -if (S_ISREG (file_inode (file)->i_mode)) { -sb_start_write (file_inode (file)->i_sb); -__sb_writers_release (file_inode (file)->i_sb,SB_FREEZE_WRITE ); - } +if (S_ISREG (file_inode (file)->i_mode)) +kiocb_start_write (req); req->ki_flags |=IOCB_WRITE ;aio_rw_done (req,call_write_iter (file, req, &iter)); }
fs/cachefiles/io.c +3 -13
@@ -259,9 +259,7 @@ static void cachefiles_write_complete(struct kiocb *iocb, long ret)_enter ("%ld" , ret); -/* Tell lockdep we inherited freeze protection from submission thread */ -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -__sb_end_write (inode->i_sb,SB_FREEZE_WRITE ); +kiocb_end_write (iocb);if (ret <0 ) trace_cachefiles_io_error(object, inode, ret,
@@ -286,7 +284,6 @@ int __cachefiles_write(struct cachefiles_object *object, {struct cachefiles_cache *cache;struct cachefiles_kiocb *ki; -struct inode *inode;unsigned int old_nofs;ssize_t ret;size_t len =iov_iter_count (iter);
@@ -322,19 +319,12 @@ int __cachefiles_write(struct cachefiles_object *object, ki->iocb.ki_complete = cachefiles_write_complete;atomic_long_add (ki->b_writing, &cache->b_writing); -/* Open-code file_start_write here to grab freeze protection, which -* will be released by another thread in aio_complete_rw(). Fool -* lockdep by telling it the lock got released so that it doesn't -* complain about the held lock when we return to userspace. -*/ - inode =file_inode (file); -__sb_start_write (inode->i_sb,SB_FREEZE_WRITE ); -__sb_writers_release (inode->i_sb,SB_FREEZE_WRITE ); +kiocb_start_write (ki);get_file (ki->iocb.ki_filp);cachefiles_grab_object (object, cachefiles_obj_get_ioreq); -trace_cachefiles_write (object, inode, ki->iocb.ki_pos, len); +trace_cachefiles_write (object,file_inode (file), ki->iocb.ki_pos, len); old_nofs =memalloc_nofs_save (); ret =cachefiles_inject_write_error ();if (ret ==0 )
fs/overlayfs/file.c +6 -9
@@ -290,10 +290,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)if (iocb->ki_flags &IOCB_WRITE ) {struct inode *inode =file_inode (orig_iocb->ki_filp); -/* Actually acquired in ovl_write_iter() */ -__sb_writers_acquired (file_inode (iocb->ki_filp)->i_sb, -SB_FREEZE_WRITE ); -file_end_write (iocb->ki_filp); +kiocb_end_write (iocb);ovl_copyattr (inode); }
@@ -362,6 +359,9 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)return ret; } +/* IOCB flags that may be propagated to real file io */ +#define OVL_IOCB_MASK ~(IOCB_WRITE_STARTED) +static ssize_t ovl_write_iter (struct kiocb *iocb,struct iov_iter *iter) {struct file *file = iocb->ki_filp;
@@ -369,7 +369,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)struct fd real;const struct cred *old_cred;ssize_t ret; -int ifl = iocb->ki_flags; +int ifl = iocb->ki_flags &OVL_IOCB_MASK ;if (!iov_iter_count (iter))return 0 ;
@@ -409,10 +409,6 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)if (!aio_req) goto out; -file_start_write (real.file); -/* Pacify lockdep, same trick as done in aio_write() */ -__sb_writers_release (file_inode (real.file)->i_sb, -SB_FREEZE_WRITE ); aio_req->fd = real; real.flags =0 ; aio_req->orig_iocb = iocb;
@@ -420,6 +416,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) aio_req->iocb.ki_flags = ifl; aio_req->iocb.ki_complete = ovl_aio_rw_complete;refcount_set (&aio_req->ref,2 ); +kiocb_start_write (&aio_req->iocb); ret =vfs_iocb_iter_write (real.file, &aio_req->iocb, iter);ovl_aio_put (aio_req);if (ret != -EIOCBQUEUED )
include/linux/fs.h +60 -2
90 lines not on this page · raw message
io_uring/rw.c +6 -30
@@ -220,20 +220,6 @@ static bool io_rw_should_reissue(struct io_kiocb *req) }#endif -static void kiocb_end_write (struct io_kiocb *req) -{ -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (req->flags &REQ_F_ISREG ) { -struct super_block *sb =file_inode (req->file)->i_sb; - -__sb_writers_acquired (sb,SB_FREEZE_WRITE ); -sb_end_write (sb); - } -} -/* * Trigger the notifications after having done some IO, and finish the write * accounting, if any.
@@ -243,7 +229,7 @@ static void io_req_io_end(struct io_kiocb *req) struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);if (rw->kiocb.ki_flags &IOCB_WRITE ) { -kiocb_end_write (req); +kiocb_end_write (&rw->kiocb);fsnotify_modify (req->file); }else {fsnotify_access (req->file);
@@ -313,7 +299,7 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res)struct io_kiocb *req =cmd_to_io_kiocb (rw);if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);if (unlikely (res != req->cqe.res)) {if (res == -EAGAIN &&io_rw_should_reissue (req)) { req->flags |=REQ_F_REISSUE |REQ_F_PARTIAL_IO ;
@@ -902,18 +888,8 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)return ret; } -/* -* Open-code file_start_write here to grab freeze protection, -* which will be released by another thread in -* io_complete_rw(). Fool lockdep by telling it the lock got -* released so that it doesn't complain about the held lock when -* we return to userspace. -*/ -if (req->flags &REQ_F_ISREG ) { -sb_start_write (file_inode (req->file)->i_sb); -__sb_writers_release (file_inode (req->file)->i_sb, -SB_FREEZE_WRITE ); - } +if (req->flags &REQ_F_ISREG ) +kiocb_start_write (kiocb); kiocb->ki_flags |=IOCB_WRITE ;if (likely (req->file->f_op->write_iter))
@@ -961,7 +937,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) io->bytes_done += ret2;if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);return ret ? ret : -EAGAIN ; } done:
@@ -972,7 +948,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) ret =io_setup_async_rw (req, iovec, s, false);if (!ret) {if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);return -EAGAIN ; }return ret;
Signature · 1 line
2.34.1
Quoted 11 lines · Amir Goldstein
aio,
io_uring, cachefiles and overlayfs, all open code an ugly variant of file_{start,end}_write() to silence lockdep warnings.Create helpers for this lockdep dance and use the helpers in all the callers.
Use a new iocb flag
IOCB_WRITE_STARTEDto indicate ifsb_start_write()was called.Suggested-by Jan Kara <[email protected]>Signed-off-by Amir Goldstein <[email protected]>
Yeah, looks like a good cleanup to me. Feel free to add:
Honza
Quoted 354 lines
---
Christian,
This is an attempt to consolidate the open coded lockdep fooling in all those async io submitters into a single helper.
The idea to do that consolidation was suggested by Jan. The (questionable) idea to use anIOCB_flag was mine.This re-factoring is part of a larger vfs cleanup I am doing for fanotify permission events. The complete series is not ready for prime time yet, but this one patch is independent and I would love to get it reviewed/merged a head of the rest.
Thanks,
Amir.Changes since v1:
- Leave ISREG checks in callers (Jens)
- Leave settingIOCB_WRITEflag in callersfs/aio.c | 26 +++---------------- fs/cachefiles/io.c | 16 +++--------- fs/overlayfs/file.c | 15 +++++------ include/linux/fs.h | 62 +++++++++++++++++++++++++++++++++++++++++++-- io_uring/rw.c | 36 +++++--------------------- 5 files changed, 79 insertions(+), 76 deletions(-)fs/aio.c +4
-22@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); - -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE ) +kiocb_end_write (kiocb); iocb->ki_res.res = res; iocb->ki_res.res2 =0 ;@@ -1581,17 +1572,8 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,return ret; ret =rw_verify_area (WRITE , file, &req->ki_pos,iov_iter_count (&iter));if (!ret) { -/* -* Open-code file_start_write here to grab freeze protection, -* which will be released by another thread in -* aio_complete_rw(). Fool lockdep by telling it the lock got -* released so that it doesn't complain about the held lock when -* we return to userspace. -*/ -if (S_ISREG (file_inode (file)->i_mode)) { -sb_start_write (file_inode (file)->i_sb); -__sb_writers_release (file_inode (file)->i_sb,SB_FREEZE_WRITE ); - } +if (S_ISREG (file_inode (file)->i_mode)) +kiocb_start_write (req); req->ki_flags |=IOCB_WRITE ;aio_rw_done (req,call_write_iter (file, req, &iter)); }fs/cachefiles/io.c +3
-13@@ -259,9 +259,7 @@ static void cachefiles_write_complete(struct kiocb *iocb, long ret)_enter ("%ld" , ret); -/* Tell lockdep we inherited freeze protection from submission thread */ -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -__sb_end_write (inode->i_sb,SB_FREEZE_WRITE ); +kiocb_end_write (iocb);if (ret <0 ) trace_cachefiles_io_error(object, inode, ret,@@ -286,7 +284,6 @@ int __cachefiles_write(struct cachefiles_object *object, {struct cachefiles_cache *cache;struct cachefiles_kiocb *ki; -struct inode *inode;unsigned int old_nofs;ssize_t ret;size_t len =iov_iter_count (iter);@@ -322,19 +319,12 @@ int __cachefiles_write(struct cachefiles_object *object, ki->iocb.ki_complete = cachefiles_write_complete;atomic_long_add (ki->b_writing, &cache->b_writing); -/* Open-code file_start_write here to grab freeze protection, which -* will be released by another thread in aio_complete_rw(). Fool -* lockdep by telling it the lock got released so that it doesn't -* complain about the held lock when we return to userspace. -*/ - inode =file_inode (file); -__sb_start_write (inode->i_sb,SB_FREEZE_WRITE ); -__sb_writers_release (inode->i_sb,SB_FREEZE_WRITE ); +kiocb_start_write (ki);get_file (ki->iocb.ki_filp);cachefiles_grab_object (object, cachefiles_obj_get_ioreq); -trace_cachefiles_write (object, inode, ki->iocb.ki_pos, len); +trace_cachefiles_write (object,file_inode (file), ki->iocb.ki_pos, len); old_nofs =memalloc_nofs_save (); ret =cachefiles_inject_write_error ();if (ret ==0 )fs/overlayfs/file.c +6
-9@@ -290,10 +290,7 @@ static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)if (iocb->ki_flags &IOCB_WRITE ) {struct inode *inode =file_inode (orig_iocb->ki_filp); -/* Actually acquired in ovl_write_iter() */ -__sb_writers_acquired (file_inode (iocb->ki_filp)->i_sb, -SB_FREEZE_WRITE ); -file_end_write (iocb->ki_filp); +kiocb_end_write (iocb);ovl_copyattr (inode); }@@ -362,6 +359,9 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)return ret; } +/* IOCB flags that may be propagated to real file io */ +#define OVL_IOCB_MASK ~(IOCB_WRITE_STARTED) +static ssize_t ovl_write_iter (struct kiocb *iocb,struct iov_iter *iter) {struct file *file = iocb->ki_filp;@@ -369,7 +369,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)struct fd real;const struct cred *old_cred;ssize_t ret; -int ifl = iocb->ki_flags; +int ifl = iocb->ki_flags &OVL_IOCB_MASK ;if (!iov_iter_count (iter))return 0 ;@@ -409,10 +409,6 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)if (!aio_req) goto out; -file_start_write (real.file); -/* Pacify lockdep, same trick as done in aio_write() */ -__sb_writers_release (file_inode (real.file)->i_sb, -SB_FREEZE_WRITE ); aio_req->fd = real; real.flags =0 ; aio_req->orig_iocb = iocb;@@ -420,6 +416,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) aio_req->iocb.ki_flags = ifl; aio_req->iocb.ki_complete = ovl_aio_rw_complete;refcount_set (&aio_req->ref,2 ); +kiocb_start_write (&aio_req->iocb); ret =vfs_iocb_iter_write (real.file, &aio_req->iocb, iter);ovl_aio_put (aio_req);if (ret != -EIOCBQUEUED )include/linux/fs.h +60
-2@@ -338,6 +338,8 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* file_start_write() was called */ +#define IOCB_WRITE_STARTED (1 << 22)/* for use in trace events */ #define TRACE_IOCB_STRINGS \@@ -351,7 +353,8 @@ enum rw_hint { { IOCB_WRITE, "WRITE" }, \ { IOCB_WAITQ, "WAITQ" }, \ { IOCB_NOIO, "NOIO" }, \ - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ + { IOCB_WRITE_STARTED, "WRITE_STARTED" } struct kiocb {struct file *ki_filp;@@ -2545,6 +2548,13 @@ static inline bool inode_wrong_type(const struct inode *inode, umode_t mode)return (inode->i_mode ^ mode) &S_IFMT ; } +/** +* file_start_write - get write access to a superblock for regular file io +* @file: the file we want to write to +* +* This is a variant of sb_start_write() which is a noop on non-regualr file. +* Should be matched with a call to file_end_write(). +*/ static inline void file_start_write (struct file *file) {if (!S_ISREG (file_inode (file)->i_mode))@@ -2559,11 +2569,59 @@ static inline bool file_start_write_trylock(struct file *file)return sb_start_write_trylock (file_inode (file)->i_sb); } +/** +* file_end_write - drop write access to a superblock of a regular file +* @file: the file we wrote to +* +* Should be matched with a call to file_start_write(). +*/ static inline void file_end_write (struct file *file) {if (!S_ISREG (file_inode (file)->i_mode))return ; -__sb_end_write (file_inode (file)->i_sb,SB_FREEZE_WRITE ); +sb_end_write (file_inode (file)->i_sb); +} + +/** +* kiocb_start_write - get write access to a superblock for async file io +* @iocb: the io context we want to submit the write with +* +* This is a variant of file_start_write() for async io submission. +* Should be matched with a call to kiocb_end_write(). +*/ +static inline void kiocb_start_write (struct kiocb *iocb) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +if (WARN_ON_ONCE (iocb->ki_flags &IOCB_WRITE_STARTED )) +return ; +sb_start_write (inode->i_sb); +/* +* Fool lockdep by telling it the lock got released so that it +* doesn't complain about the held lock when we return to userspace. +*/ +__sb_writers_release (inode->i_sb,SB_FREEZE_WRITE ); + iocb->ki_flags |=IOCB_WRITE_STARTED ; +} + +/** +* kiocb_end_write - drop write access to a superblock after async file io +* @iocb: the io context we sumbitted the write with +* +* Should be matched with a call to kiocb_start_write(). +*/ +static inline void kiocb_end_write (struct kiocb *iocb) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +if (!(iocb->ki_flags &IOCB_WRITE_STARTED )) +return ; +/* +* Tell lockdep we inherited freeze protection from submission thread. +*/ +__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); +sb_end_write (inode->i_sb); + iocb->ki_flags &= ~IOCB_WRITE_STARTED ; }/* io_uring/rw.c +6
-30@@ -220,20 +220,6 @@ static bool io_rw_should_reissue(struct io_kiocb *req) }#endif -static void kiocb_end_write (struct io_kiocb *req) -{ -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (req->flags &REQ_F_ISREG ) { -struct super_block *sb =file_inode (req->file)->i_sb; - -__sb_writers_acquired (sb,SB_FREEZE_WRITE ); -sb_end_write (sb); - } -} -/* * Trigger the notifications after having done some IO, and finish the write * accounting, if any. @@ -243,7 +229,7 @@ static void io_req_io_end(struct io_kiocb *req) struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);if (rw->kiocb.ki_flags &IOCB_WRITE ) { -kiocb_end_write (req); +kiocb_end_write (&rw->kiocb);fsnotify_modify (req->file); }else {fsnotify_access (req->file);@@ -313,7 +299,7 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res)struct io_kiocb *req =cmd_to_io_kiocb (rw);if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);if (unlikely (res != req->cqe.res)) {if (res == -EAGAIN &&io_rw_should_reissue (req)) { req->flags |=REQ_F_REISSUE |REQ_F_PARTIAL_IO ;@@ -902,18 +888,8 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)return ret; } -/* -* Open-code file_start_write here to grab freeze protection, -* which will be released by another thread in -* io_complete_rw(). Fool lockdep by telling it the lock got -* released so that it doesn't complain about the held lock when -* we return to userspace. -*/ -if (req->flags &REQ_F_ISREG ) { -sb_start_write (file_inode (req->file)->i_sb); -__sb_writers_release (file_inode (req->file)->i_sb, -SB_FREEZE_WRITE ); - } +if (req->flags &REQ_F_ISREG ) +kiocb_start_write (kiocb); kiocb->ki_flags |=IOCB_WRITE ;if (likely (req->file->f_op->write_iter))@@ -961,7 +937,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) io->bytes_done += ret2;if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);return ret ? ret : -EAGAIN ; } done:@@ -972,7 +948,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) ret =io_setup_async_rw (req, iovec, s, false);if (!ret) {if (kiocb->ki_flags &IOCB_WRITE ) -kiocb_end_write (req); +kiocb_end_write (kiocb);return -EAGAIN ; }return ret;Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jens Axboe
maintainerQuoted 8 lines · Amir Goldstein
aio,
io_uring, cachefiles and overlayfs, all open code an ugly variant of file_{start,end}_write() to silence lockdep warnings.Create helpers for this lockdep dance and use the helpers in all the callers.
Use a new iocb flag
IOCB_WRITE_STARTEDto indicate ifsb_start_write()was called.
Looks better now, but I think you should split this into a prep patch that adds the helpers, and then one for each conversion. We've had bugs with this accounting before which causes fs freeze issues, would be prudent to have it split because of that.
Quoted 11 lines
fs/aio.c +0
-3@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); -
fs/aio.c static void aio_complete_rw(struct kiocb *kiocb, long res) · line 1448
Quoted 10 lines
fs/aio.c +2
-8-/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE ) +kiocb_end_write (kiocb);
Can't we just call kiocb_end_write() here, it checks WRITE_STARTED anyway? Not a big deal, and honestly I'd rather just get rid of WRITE_STARTED if we're not using it like that. It doesn't serve much of a purpose, if we're gating this one IOCB_WRITE anyway (which I do like better than WRITE_STARTED). And it avoids writing to the kiocb at the end too, which is a nice win.
Quoted 13 lines
index
b2adee67f9b2..8e5d410a1be5100644include/linux/fs.h +2
-0@@ -338,6 +338,8 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* file_start_write() was called */ +#define IOCB_WRITE_STARTED (1 << 22)/* for use in trace events */ #define TRACE_IOCB_STRINGS \
include/linux/fs.h enum rw_hint { · line 360
Quoted 9 lines
include/linux/fs.h +2
-1@@ -351,7 +353,8 @@ enum rw_hint { { IOCB_WRITE, "WRITE" }, \ { IOCB_WAITQ, "WAITQ" }, \ { IOCB_NOIO, "NOIO" }, \ - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ + { IOCB_WRITE_STARTED, "WRITE_STARTED" } struct kiocb {struct file *ki_filp;
These changes will conflict with other changes in linux-next that are going upstream. I'd prefer to stage this one after those changes, once we get to a version that looks good to everybody.
Signature · 1 line
Jens Axboe
Amir Goldstein
maintainerQuoted 8 lines · Jens Axboe
Quoted 6 lines · Amir Goldstein
aio,
io_uring, cachefiles and overlayfs, all open code an ugly variant of file_{start,end}_write() to silence lockdep warnings.Create helpers for this lockdep dance and use the helpers in all the callers.
Quoted 8 lines
Quoted 2 lines
Use a new iocb flag
IOCB_WRITE_STARTEDto indicate ifsb_start_write()was called.Looks better now, but I think you should split this into a prep patch that adds the helpers, and then one for each conversion. We've had bugs with this accounting before which causes fs freeze issues, would be prudent to have it split because of that.
Sure, no problem.
Quoted 20 lines
Quoted 20 lines
fs/aio.c +1
-11@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); - -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE )
Quoted 9 lines
fs/aio.c static void aio_complete_rw(struct kiocb *kiocb, long res) · line 1448
Quoted 1 line
fs/aio.c +1
-0+kiocb_end_write (kiocb);Can't we just call
kiocb_end_write()here, it checksWRITE_STARTEDanyway? Not a big deal, and honestly I'd rather just get rid ofWRITE_STARTEDif we're not using it like that. It doesn't serve much of a purpose, if we're gating this oneIOCB_WRITEanyway (which I do like better thanWRITE_STARTED). And it avoids writing to the kiocb at the end too, which is a nice win.
What I don't like about it is that kiocb_{start,end}_write() calls will not be balanced, so it is harder for a code reviewer to realize that the code is correct (as opposed to have excess end_write calls). That's the reason I had ISREG check inside the helpers in v1, so like file_{start,end}_write(), the calls will be balanced and easy to review.
I am not sure, but I think that getting rid of WRITE_STARTED will make the code more subtle, because right now, IOCB_WRITE is not set by kiocb_start_write() and many times it is set much sooner. So I'd rather keep the WRITE_STARTED flag for a more roust code if that's ok with you.
Quoted 20 lines
Quoted 20 lines
index
b2adee67f9b2..8e5d410a1be5100644include/linux/fs.h +4
-1@@ -338,6 +338,8 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* file_start_write() was called */ +#define IOCB_WRITE_STARTED (1 << 22)/* for use in trace events */ #define TRACE_IOCB_STRINGS \@@ -351,7 +353,8 @@ enum rw_hint { { IOCB_WRITE, "WRITE" }, \ { IOCB_WAITQ, "WAITQ" }, \ { IOCB_NOIO, "NOIO" }, \ - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ + { IOCB_WRITE_STARTED, "WRITE_STARTED" }
Quoted 6 lines
include/linux/fs.h enum rw_hint { · line 360
Quoted 2 lines
include/linux/fs.h +0
-0struct kiocb {struct file *ki_filp;These changes will conflict with other changes in linux-next that are going upstream. I'd prefer to stage this one after those changes, once we get to a version that looks good to everybody.
Changes coming to linux-next from your tree? I was basing my patches on Christian's vfs.all branch. Do you mean that you would like to stage this cleanup? It's fine by me.
Thanks,
Amir.
Jens Axboe
maintainerQuoted 30 lines · Amir Goldstein
Quoted 20 lines
Quoted 20 lines
fs/aio.c +1
-11@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); - -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE )Quoted 9 lines
fs/aio.c static void aio_complete_rw(struct kiocb *kiocb, long res) · line 1448
Quoted 1 line
fs/aio.c +1
-0+kiocb_end_write (kiocb);Can't we just call
kiocb_end_write()here, it checksWRITE_STARTEDanyway? Not a big deal, and honestly I'd rather just get rid ofWRITE_STARTEDif we're not using it like that. It doesn't serve much of a purpose, if we're gating this oneIOCB_WRITEanyway (which I do like better thanWRITE_STARTED). And it avoids writing to the kiocb at the end too, which is a nice win.
Quoted 5 lines
What I don't like about it is that kiocb_{start,end}_write() calls will not be balanced, so it is harder for a code reviewer to realize that the code is correct (as opposed to have excess
end_writecalls). That's the reason I had ISREG check inside the helpers in v1, so like file_{start,end}_write(), the calls will be balanced and easy to review.
If you just gate it on IOCB_WRITE and local IS_REG test, then it should be balanced.
Quoted 5 lines
I am not sure, but I think that getting rid of
WRITE_STARTEDwill make the code more subtle, because right now,IOCB_WRITEis not set bykiocb_start_write()and many times it is set much sooner. So I'd rather keep theWRITE_STARTEDflag for a more roust code if that's ok with you.
Adding random flags to protect against that is not a good idea imho. It adds overhead and while it may seem like it's hardening, it's also then just making it easier to misuse.
I would start with just adding the helpers, and having the callers gate them with IOCB_WRITE && IS_REG like they do now.
Quoted 27 lines
Quoted 20 lines
index
b2adee67f9b2..8e5d410a1be5100644Quoted 19 lines
include/linux/fs.h +4
-1@@ -338,6 +338,8 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* file_start_write() was called */ +#define IOCB_WRITE_STARTED (1 << 22)/* for use in trace events */ #define TRACE_IOCB_STRINGS \@@ -351,7 +353,8 @@ enum rw_hint { { IOCB_WRITE, "WRITE" }, \ { IOCB_WAITQ, "WAITQ" }, \ { IOCB_NOIO, "NOIO" }, \ - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ + { IOCB_WRITE_STARTED, "WRITE_STARTED" }Quoted 6 lines
include/linux/fs.h enum rw_hint { · line 360
Quoted 2 lines
include/linux/fs.h +0
-0struct kiocb {struct file *ki_filp;These changes will conflict with other changes in linux-next that are going upstream. I'd prefer to stage this one after those changes, once we get to a version that looks good to everybody.
Quoted 4 lines
Changes coming to linux-next from your tree? I was basing my patches on Christian's vfs.all branch. Do you mean that you would like to stage this cleanup? It's fine by me.
From the xfs tree, if you look at linux-next you should see them. I don't care who stages it, but I don't want to create needless merge conflicts because people weren't aware of these conflicts.
Signature · 1 line
Jens Axboe
Amir Goldstein
maintainerQuoted 47 lines · Jens Axboe
Quoted 30 lines · Amir Goldstein
Quoted 20 lines
Quoted 20 lines
fs/aio.c +1
-11@@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)if (!list_empty_careful (&iocb->ki_list))aio_remove_iocb (iocb); -if (kiocb->ki_flags &IOCB_WRITE ) { -struct inode *inode =file_inode (kiocb->ki_filp); - -/* -* Tell lockdep we inherited freeze protection from submission -* thread. -*/ -if (S_ISREG (inode->i_mode)) -__sb_writers_acquired (inode->i_sb,SB_FREEZE_WRITE ); -file_end_write (kiocb->ki_filp); - } +if (kiocb->ki_flags &IOCB_WRITE )Quoted 9 lines
fs/aio.c static void aio_complete_rw(struct kiocb *kiocb, long res) · line 1448
Quoted 1 line
fs/aio.c +1
-0+kiocb_end_write (kiocb);Can't we just call
kiocb_end_write()here, it checksWRITE_STARTEDanyway? Not a big deal, and honestly I'd rather just get rid ofWRITE_STARTEDif we're not using it like that. It doesn't serve much of a purpose, if we're gating this oneIOCB_WRITEanyway (which I do like better thanWRITE_STARTED). And it avoids writing to the kiocb at the end too, which is a nice win.Quoted 5 lines
What I don't like about it is that kiocb_{start,end}_write() calls will not be balanced, so it is harder for a code reviewer to realize that the code is correct (as opposed to have excess
end_writecalls). That's the reason I had ISREG check inside the helpers in v1, so like file_{start,end}_write(), the calls will be balanced and easy to review.If you just gate it on
IOCB_WRITEand localIS_REGtest, then it should be balanced.Quoted 5 lines
I am not sure, but I think that getting rid of
WRITE_STARTEDwill make the code more subtle, because right now,IOCB_WRITEis not set bykiocb_start_write()and many times it is set much sooner. So I'd rather keep theWRITE_STARTEDflag for a more roust code if that's ok with you.
Quoted 7 lines
Adding random flags to protect against that is not a good idea imho. It adds overhead and while it may seem like it's hardening, it's also then just making it easier to misuse.
I would start with just adding the helpers, and having the callers gate them with
IOCB_WRITE&&IS_REGlike they do now.
All right.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
index
b2adee67f9b2..8e5d410a1be5100644Quoted 12 lines
include/linux/fs.h +2
-0@@ -338,6 +338,8 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* file_start_write() was called */ +#define IOCB_WRITE_STARTED (1 << 22)/* for use in trace events */ #define TRACE_IOCB_STRINGS \include/linux/fs.h enum rw_hint { · line 360
Quoted 9 lines
include/linux/fs.h +2
-1@@ -351,7 +353,8 @@ enum rw_hint { { IOCB_WRITE, "WRITE" }, \ { IOCB_WAITQ, "WAITQ" }, \ { IOCB_NOIO, "NOIO" }, \ - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ + { IOCB_WRITE_STARTED, "WRITE_STARTED" } struct kiocb {struct file *ki_filp;These changes will conflict with other changes in linux-next that are going upstream. I'd prefer to stage this one after those changes, once we get to a version that looks good to everybody.
Quoted 9 lines
Quoted 4 lines
Changes coming to linux-next from your tree? I was basing my patches on Christian's vfs.all branch. Do you mean that you would like to stage this cleanup? It's fine by me.
From the xfs tree, if you look at linux-next you should see them. I don't care who stages it, but I don't want to create needless merge conflicts because people weren't aware of these conflicts.
Ok. I got rid of IOCB_WRITE_STARTED, so there is no conflict now.
Thanks,
Amir.
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Amir,
kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on mszeredi-vfs/overlayfs-next jack-fs/for_next linus/master v6.5-rc6] [cannot apply to vfs-idmapping/for-next mszeredi-vfs/next next-20230816]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Amir-Goldstein/fs-create-kiocb_-start-end-_write-helpers/20230816-165807 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20230816085439.894112-1-amir73il%40gmail.com patch subject: [PATCH v2] fs: create kiocb_{start,end}_write() helpers config: arm-randconfig-r046-20230816 (https://download.01.org/0day-ci/archive/20230817/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230817/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/cachefiles/io.c: In function '__cachefiles_write':
>> fs/cachefiles/io.c:322:27: error: passing argument 1 of 'kiocb_start_write' from incompatible pointer type [-Werror=incompatible-pointer-types]
322 | kiocb_start_write(ki);
| ^~
| |
| struct cachefiles_kiocb *
In file included from include/linux/fscache.h:17,
from include/trace/events/fscache.h:13,
from fs/cachefiles/io.c:14: include/linux/fs.h:2673:52: note: expected 'struct kiocb *' but argument is of type 'struct cachefiles_kiocb *'
2673 | static inline void kiocb_start_write(struct kiocb *iocb)
| ~~~~~~~~~~~~~~^~~~
cc1: some warnings being treated as errors
vim +/kiocb_start_write +322 fs/cachefiles/io.c
274
275 /*
276 * Initiate a write to the cache.
277 */
278 int __cachefiles_write(struct cachefiles_object *object,
279 struct file *file,
280 loff_t start_pos,
281 struct iov_iter *iter,
282 netfs_io_terminated_t term_func,
283 void *term_func_priv)
284 {
285 struct cachefiles_cache *cache;
286 struct cachefiles_kiocb *ki;
287 unsigned int old_nofs;
288 ssize_t ret;
289 size_t len = iov_iter_count(iter);
290
291 fscache_count_write();
292 cache = object->volume->cache;
293
294 _enter("%pD,%li,%llx,%zx/%llx",
295 file, file_inode(file)->i_ino, start_pos, len,
296 i_size_read(file_inode(file)));
297
298 ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL);
299 if (!ki) {
300 if (term_func)
301 term_func(term_func_priv, -ENOMEM, false);
302 return -ENOMEM;
303 }
304
305 refcount_set(&ki->ki_refcnt, 2);
306 ki->iocb.ki_filp = file;
307 ki->iocb.ki_pos = start_pos;
308 ki->iocb.ki_flags = IOCB_DIRECT | IOCB_WRITE;
309 ki->iocb.ki_ioprio = get_current_ioprio();
310 ki->object = object;
311 ki->start = start_pos;
312 ki->len = len;
313 ki->term_func = term_func;
314 ki->term_func_priv = term_func_priv;
315 ki->was_async = true;
316 ki->b_writing = (len + (1 << cache->bshift) - 1) >> cache->bshift;
317
318 if (ki->term_func)
319 ki->iocb.ki_complete = cachefiles_write_complete;
320 atomic_long_add(ki->b_writing, &cache->b_writing);
321
> 322 kiocb_start_write(ki); 323
324 get_file(ki->iocb.ki_filp);
325 cachefiles_grab_object(object, cachefiles_obj_get_ioreq);
326
327 trace_cachefiles_write(object, file_inode(file), ki->iocb.ki_pos, len);
328 old_nofs = memalloc_nofs_save();
329 ret = cachefiles_inject_write_error();
330 if (ret == 0)
331 ret = vfs_iocb_iter_write(file, &ki->iocb, iter);
332 memalloc_nofs_restore(old_nofs);
333 switch (ret) {
334 case -EIOCBQUEUED:
335 goto in_progress;
336
337 case -ERESTARTSYS:
338 case -ERESTARTNOINTR:
339 case -ERESTARTNOHAND:
340 case -ERESTART_RESTARTBLOCK:
341 /* There's no easy way to restart the syscall since other AIO's
342 * may be already running. Just fail this IO with EINTR.
343 */
344 ret = -EINTR;
345 fallthrough;
346 default:
347 ki->was_async = false;
348 cachefiles_write_complete(&ki->iocb, ret);
349 if (ret > 0)
350 ret = 0;
351 break;
352 }
353
354 in_progress:
355 cachefiles_put_kiocb(ki);
356 _leave(" = %zd", ret);
357 return ret;
358 }
359
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Amir,
kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on mszeredi-vfs/overlayfs-next jack-fs/for_next linus/master] [cannot apply to vfs-idmapping/for-next mszeredi-vfs/next next-20230816] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Amir-Goldstein/fs-create-kiocb_-start-end-_write-helpers/20230816-165807 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20230816085439.894112-1-amir73il%40gmail.com patch subject: [PATCH v2] fs: create kiocb_{start,end}_write() helpers config: riscv-randconfig-r042-20230816 (https://download.01.org/0day-ci/archive/20230817/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230817/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:751:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
751 | insw(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw'
105 | #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/cachefiles/io.c:14:
In file included from include/trace/events/fscache.h:13:
In file included from include/linux/fscache.h:18:
In file included from include/linux/netfs.h:19:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:759:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
759 | insl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl'
106 | #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/cachefiles/io.c:14:
In file included from include/trace/events/fscache.h:13:
In file included from include/linux/fscache.h:18:
In file included from include/linux/netfs.h:19:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:768:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
768 | outsb(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb'
118 | #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/cachefiles/io.c:14:
In file included from include/trace/events/fscache.h:13:
In file included from include/linux/fscache.h:18:
In file included from include/linux/netfs.h:19:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:777:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
777 | outsw(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw'
119 | #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/cachefiles/io.c:14:
In file included from include/trace/events/fscache.h:13:
In file included from include/linux/fscache.h:18:
In file included from include/linux/netfs.h:19:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:786:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
786 | outsl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl'
120 | #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/cachefiles/io.c:14:
In file included from include/trace/events/fscache.h:13:
In file included from include/linux/fscache.h:18:
In file included from include/linux/netfs.h:19:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:1134:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1134 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^
>> fs/cachefiles/io.c:322:20: error: incompatible pointer types passing 'struct cachefiles_kiocb *' to parameter of type 'struct kiocb *' [-Werror,-Wincompatible-pointer-types]
322 | kiocb_start_write(ki);
| ^~ include/linux/fs.h:2673:52: note: passing argument to parameter 'iocb' here
2673 | static inline void kiocb_start_write(struct kiocb *iocb)
| ^
13 warnings and 1 error generated.
vim +322 fs/cachefiles/io.c
274
275 /*
276 * Initiate a write to the cache.
277 */
278 int __cachefiles_write(struct cachefiles_object *object,
279 struct file *file,
280 loff_t start_pos,
281 struct iov_iter *iter,
282 netfs_io_terminated_t term_func,
283 void *term_func_priv)
284 {
285 struct cachefiles_cache *cache;
286 struct cachefiles_kiocb *ki;
287 unsigned int old_nofs;
288 ssize_t ret;
289 size_t len = iov_iter_count(iter);
290
291 fscache_count_write();
292 cache = object->volume->cache;
293
294 _enter("%pD,%li,%llx,%zx/%llx",
295 file, file_inode(file)->i_ino, start_pos, len,
296 i_size_read(file_inode(file)));
297
298 ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL);
299 if (!ki) {
300 if (term_func)
301 term_func(term_func_priv, -ENOMEM, false);
302 return -ENOMEM;
303 }
304
305 refcount_set(&ki->ki_refcnt, 2);
306 ki->iocb.ki_filp = file;
307 ki->iocb.ki_pos = start_pos;
308 ki->iocb.ki_flags = IOCB_DIRECT | IOCB_WRITE;
309 ki->iocb.ki_ioprio = get_current_ioprio();
310 ki->object = object;
311 ki->start = start_pos;
312 ki->len = len;
313 ki->term_func = term_func;
314 ki->term_func_priv = term_func_priv;
315 ki->was_async = true;
316 ki->b_writing = (len + (1 << cache->bshift) - 1) >> cache->bshift;
317
318 if (ki->term_func)
319 ki->iocb.ki_complete = cachefiles_write_complete;
320 atomic_long_add(ki->b_writing, &cache->b_writing);
321
> 322 kiocb_start_write(ki); 323
324 get_file(ki->iocb.ki_filp);
325 cachefiles_grab_object(object, cachefiles_obj_get_ioreq);
326
327 trace_cachefiles_write(object, file_inode(file), ki->iocb.ki_pos, len);
328 old_nofs = memalloc_nofs_save();
329 ret = cachefiles_inject_write_error();
330 if (ret == 0)
331 ret = vfs_iocb_iter_write(file, &ki->iocb, iter);
332 memalloc_nofs_restore(old_nofs);
333 switch (ret) {
334 case -EIOCBQUEUED:
335 goto in_progress;
336
337 case -ERESTARTSYS:
338 case -ERESTARTNOINTR:
339 case -ERESTARTNOHAND:
340 case -ERESTART_RESTARTBLOCK:
341 /* There's no easy way to restart the syscall since other AIO's
342 * may be already running. Just fail this IO with EINTR.
343 */
344 ret = -EINTR;
345 fallthrough;
346 default:
347 ki->was_async = false;
348 cachefiles_write_complete(&ki->iocb, ret);
349 if (ret > 0)
350 ret = 0;
351 break;
352 }
353
354 in_progress:
355 cachefiles_put_kiocb(ki);
356 _leave(" = %zd", ret);
357 return ret;
358 }
359
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki