From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: Matthew Wilcox <willy@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Xiubo Li <xiubli@redhat.com>,
Ilya Dryomov <idryomov@gmail.com>,
Christian Brauner <brauner@kernel.org>,
Theodore Ts'o <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
Chao Yu <chao@kernel.org>, Miklos Szeredi <miklos@szeredi.hu>,
Andreas Gruenbacher <agruenba@redhat.com>,
"Darrick J. Wong" <djwong@kernel.org>,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Anna Schumaker <anna@kernel.org>,
Damien Le Moal <dlemoal@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-block@vger.kernel.org, ceph-devel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com,
linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-mm@kvack.org, Hannes Reinecke <hare@suse.de>
Subject: Re: [PATCH 03/12] filemap: update ki_pos in generic_perform_write
Date: Mon, 28 Aug 2023 02:04:43 +0100 [thread overview]
Message-ID: <20230828010443.GV3390869@ZenIV> (raw)
In-Reply-To: <20230827194122.GA325446@ZenIV>
On Sun, Aug 27, 2023 at 08:41:22PM +0100, Al Viro wrote:
> That part is somewhat fishy - there's a case where you return a positive value
> and advance ->ki_pos by more than that amount. I really wonder if all callers
> of ->write_iter() are OK with that.
Speaking of which, in case of negative return value we'd better *not* use
->ki_pos; consider e.g. generic_file_write_iter() with O_DSYNC and
vfs_fsync_range() failure. An error gets returned, but ->ki_pos is left
advanced. Normal write(2) is fine - it will only update file->f_pos if
->write_iter() has returned a non-negative. However, io_uring
kiocb_done() starts with
if (req->flags & REQ_F_CUR_POS)
req->file->f_pos = rw->kiocb.ki_pos;
if (ret >= 0 && (rw->kiocb.ki_complete == io_complete_rw)) {
if (!__io_complete_rw_common(req, ret)) {
/*
* Safe to call io_end from here as we're inline
* from the submission path.
*/
io_req_io_end(req);
io_req_set_res(req, final_ret,
io_put_kbuf(req, issue_flags));
return IOU_OK;
}
} else {
io_rw_done(&rw->kiocb, ret);
}
Note that ->f_pos update is *NOT* conditional upon ret >= 0 - it happens
no matter what, provided that original request had ->kiocb.ki_pos equal
to -1 (on a non-FMODE_STREAM file).
Jens, is there any reason for doing that unconditionally? IMO it's
a bad idea - there's a wide scope for fuckups that way, especially
since write(2) is not sensitive to that and this use of -1 ki_pos
is not particularly encouraged on io_uring side either, AFAICT.
Worse, it's handling of failure exits in the first place, which
already gets little testing...
WARNING: multiple messages have this Message-ID (diff)
From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: "Darrick J. Wong" <djwong@kernel.org>,
linux-mm@kvack.org, Miklos Szeredi <miklos@szeredi.hu>,
Matthew Wilcox <willy@infradead.org>,
cluster-devel@redhat.com, Ilya Dryomov <idryomov@gmail.com>,
linux-ext4@vger.kernel.org, Chao Yu <chao@kernel.org>,
linux-nfs@vger.kernel.org, linux-block@vger.kernel.org,
Damien Le Moal <dlemoal@kernel.org>,
Hannes Reinecke <hare@suse.de>, Jaegeuk Kim <jaegeuk@kernel.org>,
ceph-devel@vger.kernel.org, Xiubo Li <xiubli@redhat.com>,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Jens Axboe <axboe@kernel.dk>,
Christian Brauner <brauner@kernel.org>,
Theodore Ts'o <tytso@mit.edu>,
linux-f2fs-devel@lists.sourceforge.net,
linux-xfs@vger.kernel.org, Anna Schumaker <anna@kernel.org>,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [Cluster-devel] [PATCH 03/12] filemap: update ki_pos in generic_perform_write
Date: Mon, 28 Aug 2023 02:04:43 +0100 [thread overview]
Message-ID: <20230828010443.GV3390869@ZenIV> (raw)
In-Reply-To: <20230827194122.GA325446@ZenIV>
On Sun, Aug 27, 2023 at 08:41:22PM +0100, Al Viro wrote:
> That part is somewhat fishy - there's a case where you return a positive value
> and advance ->ki_pos by more than that amount. I really wonder if all callers
> of ->write_iter() are OK with that.
Speaking of which, in case of negative return value we'd better *not* use
->ki_pos; consider e.g. generic_file_write_iter() with O_DSYNC and
vfs_fsync_range() failure. An error gets returned, but ->ki_pos is left
advanced. Normal write(2) is fine - it will only update file->f_pos if
->write_iter() has returned a non-negative. However, io_uring
kiocb_done() starts with
if (req->flags & REQ_F_CUR_POS)
req->file->f_pos = rw->kiocb.ki_pos;
if (ret >= 0 && (rw->kiocb.ki_complete == io_complete_rw)) {
if (!__io_complete_rw_common(req, ret)) {
/*
* Safe to call io_end from here as we're inline
* from the submission path.
*/
io_req_io_end(req);
io_req_set_res(req, final_ret,
io_put_kbuf(req, issue_flags));
return IOU_OK;
}
} else {
io_rw_done(&rw->kiocb, ret);
}
Note that ->f_pos update is *NOT* conditional upon ret >= 0 - it happens
no matter what, provided that original request had ->kiocb.ki_pos equal
to -1 (on a non-FMODE_STREAM file).
Jens, is there any reason for doing that unconditionally? IMO it's
a bad idea - there's a wide scope for fuckups that way, especially
since write(2) is not sensitive to that and this use of -1 ki_pos
is not particularly encouraged on io_uring side either, AFAICT.
Worse, it's handling of failure exits in the first place, which
already gets little testing...
WARNING: multiple messages have this Message-ID (diff)
From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: "Darrick J. Wong" <djwong@kernel.org>,
linux-mm@kvack.org, Andreas Gruenbacher <agruenba@redhat.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Matthew Wilcox <willy@infradead.org>,
cluster-devel@redhat.com, Ilya Dryomov <idryomov@gmail.com>,
linux-ext4@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-block@vger.kernel.org, Damien Le Moal <dlemoal@kernel.org>,
Hannes Reinecke <hare@suse.de>, Jaegeuk Kim <jaegeuk@kernel.org>,
ceph-devel@vger.kernel.org, Xiubo Li <xiubli@redhat.com>,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Jens Axboe <axboe@kernel.dk>,
Christian Brauner <brauner@kernel.org>,
Theodore Ts'o <tytso@mit.edu>,
linux-f2fs-devel@lists.sourceforge.net,
linux-xfs@vger.kernel.org, Anna Schumaker <anna@kernel.org>,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [f2fs-dev] [PATCH 03/12] filemap: update ki_pos in generic_perform_write
Date: Mon, 28 Aug 2023 02:04:43 +0100 [thread overview]
Message-ID: <20230828010443.GV3390869@ZenIV> (raw)
In-Reply-To: <20230827194122.GA325446@ZenIV>
On Sun, Aug 27, 2023 at 08:41:22PM +0100, Al Viro wrote:
> That part is somewhat fishy - there's a case where you return a positive value
> and advance ->ki_pos by more than that amount. I really wonder if all callers
> of ->write_iter() are OK with that.
Speaking of which, in case of negative return value we'd better *not* use
->ki_pos; consider e.g. generic_file_write_iter() with O_DSYNC and
vfs_fsync_range() failure. An error gets returned, but ->ki_pos is left
advanced. Normal write(2) is fine - it will only update file->f_pos if
->write_iter() has returned a non-negative. However, io_uring
kiocb_done() starts with
if (req->flags & REQ_F_CUR_POS)
req->file->f_pos = rw->kiocb.ki_pos;
if (ret >= 0 && (rw->kiocb.ki_complete == io_complete_rw)) {
if (!__io_complete_rw_common(req, ret)) {
/*
* Safe to call io_end from here as we're inline
* from the submission path.
*/
io_req_io_end(req);
io_req_set_res(req, final_ret,
io_put_kbuf(req, issue_flags));
return IOU_OK;
}
} else {
io_rw_done(&rw->kiocb, ret);
}
Note that ->f_pos update is *NOT* conditional upon ret >= 0 - it happens
no matter what, provided that original request had ->kiocb.ki_pos equal
to -1 (on a non-FMODE_STREAM file).
Jens, is there any reason for doing that unconditionally? IMO it's
a bad idea - there's a wide scope for fuckups that way, especially
since write(2) is not sensitive to that and this use of -1 ki_pos
is not particularly encouraged on io_uring side either, AFAICT.
Worse, it's handling of failure exits in the first place, which
already gets little testing...
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2023-08-28 1:05 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-01 14:58 cleanup the filemap / direct I/O interaction v4 Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:58 ` [PATCH 01/12] backing_dev: remove current->backing_dev_info Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-07-06 0:18 ` [f2fs-dev] " patchwork-bot+f2fs
2023-07-06 0:18 ` patchwork-bot+f2fs
2023-07-06 0:18 ` [Cluster-devel] " patchwork-bot+f2fs
2023-06-01 14:58 ` [PATCH 02/12] iomap: update ki_pos a little later in iomap_dio_complete Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:58 ` [PATCH 03/12] filemap: update ki_pos in generic_perform_write Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-08-27 19:41 ` Al Viro
2023-08-27 19:41 ` [f2fs-dev] " Al Viro
2023-08-27 19:41 ` [Cluster-devel] " Al Viro
2023-08-27 21:45 ` Al Viro
2023-08-27 21:45 ` [f2fs-dev] " Al Viro
2023-08-27 21:45 ` [Cluster-devel] " Al Viro
2023-08-28 12:32 ` Christoph Hellwig
2023-08-28 12:32 ` [f2fs-dev] " Christoph Hellwig
2023-08-28 12:32 ` [Cluster-devel] " Christoph Hellwig
2023-08-28 13:56 ` Al Viro
2023-08-28 13:56 ` [f2fs-dev] " Al Viro
2023-08-28 13:56 ` [Cluster-devel] " Al Viro
2023-08-28 14:15 ` Christoph Hellwig
2023-08-28 14:15 ` [f2fs-dev] " Christoph Hellwig
2023-08-28 14:15 ` [Cluster-devel] " Christoph Hellwig
2023-09-13 11:00 ` Christoph Hellwig
2023-09-13 11:00 ` [f2fs-dev] " Christoph Hellwig
2023-09-13 11:00 ` [Cluster-devel] " Christoph Hellwig
2023-09-13 16:33 ` Christian Brauner
2023-09-13 16:33 ` [f2fs-dev] " Christian Brauner
2023-09-13 16:33 ` [Cluster-devel] " Christian Brauner
2023-08-28 1:04 ` Al Viro [this message]
2023-08-28 1:04 ` [f2fs-dev] " Al Viro
2023-08-28 1:04 ` [Cluster-devel] " Al Viro
2023-08-28 12:30 ` Christoph Hellwig
2023-08-28 12:30 ` [f2fs-dev] " Christoph Hellwig
2023-08-28 12:30 ` [Cluster-devel] " Christoph Hellwig
2023-08-28 14:02 ` Al Viro
2023-08-28 14:02 ` [f2fs-dev] " Al Viro
2023-08-28 14:02 ` [Cluster-devel] " Al Viro
2023-06-01 14:58 ` [PATCH 04/12] filemap: add a kiocb_write_and_wait helper Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:58 ` [PATCH 05/12] filemap: add a kiocb_invalidate_pages helper Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:58 ` [PATCH 06/12] filemap: add a kiocb_invalidate_post_direct_write helper Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:58 ` [PATCH 07/12] iomap: update ki_pos in iomap_file_buffered_write Christoph Hellwig
2023-06-01 14:58 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:58 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:59 ` [PATCH 08/12] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Christoph Hellwig
2023-06-01 14:59 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:59 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:59 ` [PATCH 09/12] fs: factor out a direct_write_fallback helper Christoph Hellwig
2023-06-01 14:59 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:59 ` [Cluster-devel] " Christoph Hellwig
2023-06-06 0:04 ` Darrick J. Wong
2023-06-06 0:04 ` [f2fs-dev] " Darrick J. Wong
2023-06-06 0:04 ` [Cluster-devel] " Darrick J. Wong
2023-06-06 6:43 ` Christoph Hellwig
2023-06-06 6:43 ` [f2fs-dev] " Christoph Hellwig
2023-06-06 6:43 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:59 ` [PATCH 10/12] fuse: update ki_pos in fuse_perform_write Christoph Hellwig
2023-06-01 14:59 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:59 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:59 ` [PATCH 11/12] fuse: drop redundant arguments to fuse_perform_write Christoph Hellwig
2023-06-01 14:59 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:59 ` [Cluster-devel] " Christoph Hellwig
2023-06-01 14:59 ` [PATCH 12/12] fuse: use direct_write_fallback Christoph Hellwig
2023-06-01 14:59 ` [f2fs-dev] " Christoph Hellwig
2023-06-01 14:59 ` [Cluster-devel] " Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2023-05-31 7:50 cleanup the filemap / direct I/O interaction v3 (full series now) Christoph Hellwig
2023-05-31 7:50 ` [PATCH 03/12] filemap: update ki_pos in generic_perform_write Christoph Hellwig
2023-06-01 4:06 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230828010443.GV3390869@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=agruenba@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=anna@kernel.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=chao@kernel.org \
--cc=cluster-devel@redhat.com \
--cc=djwong@kernel.org \
--cc=dlemoal@kernel.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=idryomov@gmail.com \
--cc=jaegeuk@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=trond.myklebust@hammerspace.com \
--cc=tytso@mit.edu \
--cc=willy@infradead.org \
--cc=xiubli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.