From patchwork Sat May 11 16:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_B=C3=BChler?= X-Patchwork-Id: 10939775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 447B11575 for ; Sat, 11 May 2019 16:57:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 320AD212D8 for ; Sat, 11 May 2019 16:57:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 264D4212DA; Sat, 11 May 2019 16:57:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23253212D8 for ; Sat, 11 May 2019 16:57:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728678AbfEKQ5d (ORCPT ); Sat, 11 May 2019 12:57:33 -0400 Received: from mail.stbuehler.de ([5.9.32.208]:54204 "EHLO mail.stbuehler.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbfEKQ5c (ORCPT ); Sat, 11 May 2019 12:57:32 -0400 Received: from chromobil.fritz.box (unknown [IPv6:2a02:8070:a29c:5000:823f:5dff:fe0f:b5b6]) by mail.stbuehler.de (Postfix) with ESMTPSA id EFD73C00A01; Sat, 11 May 2019 16:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=stbuehler.de; s=stbuehler1; t=1557593848; bh=STFNScRNnbGZUwRYFatPPVfqe+/yGK93JsjoMiYTs6w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ln6Xy6P/WrNmJu4DR0YuSBKjEMZzqKBjQBkPaLddpLXL6xKecFIUmsqfs1oTd6VOX XPHJJuB4tlbrvD+TreMv1mYI7afRzfmMCP4DXCafg6lpY0HfRV4rhD3HfV/MgfD+RK At84mTmt+pWGH0VKgEB2DM8sLnI/7m85eahQE/C8= From: =?utf-8?q?Stefan_B=C3=BChler?= To: Jens Axboe , Alexander Viro , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/5] fs: RWF flags override default IOCB flags from file flags Date: Sat, 11 May 2019 18:57:23 +0200 Message-Id: <20190511165727.31599-1-source@stbuehler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Mapping between IOCB, RWF and file flags: IOCB_APPEND | RWF_APPEND | O_APPEND IOCB_HIPRI | RWF_HIPRI | - IOCB_DSYNC | RWF_DSYNC | O_DSYNC || IS_SYNC(f_mapping->host) IOCB_SYNC | RWF_SYNC | __O_SYNC IOCB_NOWAIT | RWF_NOWAIT | O_NONBLOCK && (f_mode & FMODE_NOWAIT) IOCB_DIRECT | - | io_is_direct() Most internal kernel functions taking rwf_t flags support taking _RWF_DEFAULT instead of individual flags to signal "use default flags from file flags"; APIs exposed to userspace should return EOPNOTSUPP when they are passed _RWF_DEFAULT. Also convert O_NONBLOCK file flag to IOCB_NOWAIT if supported by the file (i.e. FMODE_NOWAIT is set), so read_iter/write_iter implementations can consistently check for IOCB_NOWAIT instead of O_NONBLOCK. Signed-off-by: Stefan Bühler --- drivers/block/loop.c | 8 +++-- drivers/staging/android/ashmem.c | 2 +- drivers/target/target_core_file.c | 6 ++-- fs/coda/file.c | 6 ++-- fs/nfsd/vfs.c | 4 +-- fs/overlayfs/file.c | 21 ++----------- fs/read_write.c | 40 ++++++++++++++++++------ fs/splice.c | 11 +++++-- include/linux/fs.h | 51 +++++++++++++++++++++++++++++++ 9 files changed, 107 insertions(+), 42 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 102d79575895..cb06eef7d0d2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -280,7 +280,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos) loop_iov_iter_bvec(&i, WRITE, bvec, 1, bvec->bv_len); file_start_write(file); - bw = vfs_iter_write(file, &i, ppos, 0); + bw = vfs_iter_write(file, &i, ppos, _RWF_DEFAULT); file_end_write(file); if (likely(bw == bvec->bv_len)) @@ -356,7 +356,8 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq, rq_for_each_segment(bvec, rq, iter) { loop_iov_iter_bvec(&i, READ, &bvec, 1, bvec.bv_len); - len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0); + len = vfs_iter_read(lo->lo_backing_file, &i, &pos, + _RWF_DEFAULT); if (len < 0) return len; @@ -397,7 +398,8 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq, b.bv_len = bvec.bv_len; loop_iov_iter_bvec(&i, READ, &b, 1, b.bv_len); - len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0); + len = vfs_iter_read(lo->lo_backing_file, &i, &pos, + _RWF_DEFAULT); if (len < 0) { ret = len; goto out_free_page; diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 74d497d39c5a..813353d74eaf 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -307,7 +307,7 @@ static ssize_t ashmem_read_iter(struct kiocb *iocb, struct iov_iter *iter) * ashmem_release is called. */ mutex_unlock(&ashmem_mutex); - ret = vfs_iter_read(asma->file, iter, &iocb->ki_pos, 0); + ret = vfs_iter_read(asma->file, iter, &iocb->ki_pos, _RWF_DEFAULT); mutex_lock(&ashmem_mutex); if (ret > 0) asma->file->f_pos = iocb->ki_pos; diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 49b110d1b972..8ebfbf6bc56d 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -355,9 +355,9 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd, iov_iter_bvec(&iter, READ, bvec, sgl_nents, len); if (is_write) - ret = vfs_iter_write(fd, &iter, &pos, 0); + ret = vfs_iter_write(fd, &iter, &pos, _RWF_DEFAULT); else - ret = vfs_iter_read(fd, &iter, &pos, 0); + ret = vfs_iter_read(fd, &iter, &pos, _RWF_DEFAULT); if (is_write) { if (ret < 0 || ret != data_length) { @@ -491,7 +491,7 @@ fd_execute_write_same(struct se_cmd *cmd) } iov_iter_bvec(&iter, READ, bvec, nolb, len); - ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, 0); + ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, _RWF_DEFAULT); kfree(bvec); if (ret < 0 || ret != len) { diff --git a/fs/coda/file.c b/fs/coda/file.c index 1cbc1f2298ee..65d1cc7017e4 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -35,7 +35,8 @@ coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to) BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); - return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0); + return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, + _RWF_DEFAULT); } static ssize_t @@ -52,7 +53,8 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) host_file = cfi->cfi_container; file_start_write(host_file); inode_lock(coda_inode); - ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0); + ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, + _RWF_DEFAULT); coda_inode->i_size = file_inode(host_file)->i_size; coda_inode->i_blocks = (coda_inode->i_size + 511) >> 9; coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode); diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 7dc98e14655d..2d563d916b5c 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -943,7 +943,7 @@ __be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp, trace_nfsd_read_vector(rqstp, fhp, offset, *count); iov_iter_kvec(&iter, READ, vec, vlen, *count); - host_err = vfs_iter_read(file, &iter, &offset, 0); + host_err = vfs_iter_read(file, &iter, &offset, _RWF_DEFAULT); return nfsd_finish_read(rqstp, fhp, file, offset, count, host_err); } @@ -996,7 +996,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, int use_wgather; loff_t pos = offset; unsigned int pflags = current->flags; - rwf_t flags = 0; + rwf_t flags = rwf_flags(file); trace_nfsd_write_opened(rqstp, fhp, offset, *cnt); diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 84dd957efa24..8567f2cc189f 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -174,23 +174,6 @@ static void ovl_file_accessed(struct file *file) touch_atime(&file->f_path); } -static rwf_t ovl_iocb_to_rwf(struct kiocb *iocb) -{ - int ifl = iocb->ki_flags; - rwf_t flags = 0; - - if (ifl & IOCB_NOWAIT) - flags |= RWF_NOWAIT; - if (ifl & IOCB_HIPRI) - flags |= RWF_HIPRI; - if (ifl & IOCB_DSYNC) - flags |= RWF_DSYNC; - if (ifl & IOCB_SYNC) - flags |= RWF_SYNC; - - return flags; -} - static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) { struct file *file = iocb->ki_filp; @@ -207,7 +190,7 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) old_cred = ovl_override_creds(file_inode(file)->i_sb); ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(iocb)); + rwf_from_iocb_flags(iocb)); revert_creds(old_cred); ovl_file_accessed(file); @@ -242,7 +225,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) old_cred = ovl_override_creds(file_inode(file)->i_sb); file_start_write(real.file); ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(iocb)); + rwf_from_iocb_flags(iocb)); file_end_write(real.file); revert_creds(old_cred); diff --git a/fs/read_write.c b/fs/read_write.c index 61b43ad7608e..1bb37364cb44 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -670,6 +670,8 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, ssize_t ret; init_sync_kiocb(&kiocb, filp); + if (flags == _RWF_DEFAULT) + flags = rwf_flags(filp); ret = kiocb_set_rw_flags(&kiocb, flags); if (ret) return ret; @@ -690,7 +692,7 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, { ssize_t ret = 0; - if (flags & ~RWF_HIPRI) + if ((flags != _RWF_DEFAULT) && (flags & ~RWF_HIPRI)) return -EOPNOTSUPP; while (iov_iter_count(iter)) { @@ -1101,13 +1103,13 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec, SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec, unsigned long, vlen) { - return do_readv(fd, vec, vlen, 0); + return do_readv(fd, vec, vlen, _RWF_DEFAULT); } SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec, unsigned long, vlen) { - return do_writev(fd, vec, vlen, 0); + return do_writev(fd, vec, vlen, _RWF_DEFAULT); } SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec, @@ -1115,7 +1117,7 @@ SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec, { loff_t pos = pos_from_hilo(pos_h, pos_l); - return do_preadv(fd, vec, vlen, pos, 0); + return do_preadv(fd, vec, vlen, pos, _RWF_DEFAULT); } SYSCALL_DEFINE6(preadv2, unsigned long, fd, const struct iovec __user *, vec, @@ -1124,6 +1126,9 @@ SYSCALL_DEFINE6(preadv2, unsigned long, fd, const struct iovec __user *, vec, { loff_t pos = pos_from_hilo(pos_h, pos_l); + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_readv(fd, vec, vlen, flags); @@ -1135,7 +1140,7 @@ SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec, { loff_t pos = pos_from_hilo(pos_h, pos_l); - return do_pwritev(fd, vec, vlen, pos, 0); + return do_pwritev(fd, vec, vlen, pos, _RWF_DEFAULT); } SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec, @@ -1144,6 +1149,9 @@ SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec, { loff_t pos = pos_from_hilo(pos_h, pos_l); + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_writev(fd, vec, vlen, flags); @@ -1221,7 +1229,7 @@ COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd, const struct compat_iovec __user *,vec, unsigned long, vlen, loff_t, pos) { - return do_compat_preadv64(fd, vec, vlen, pos, 0); + return do_compat_preadv64(fd, vec, vlen, pos, _RWF_DEFAULT); } #endif @@ -1231,7 +1239,7 @@ COMPAT_SYSCALL_DEFINE5(preadv, compat_ulong_t, fd, { loff_t pos = ((loff_t)pos_high << 32) | pos_low; - return do_compat_preadv64(fd, vec, vlen, pos, 0); + return do_compat_preadv64(fd, vec, vlen, pos, _RWF_DEFAULT); } #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2 @@ -1239,6 +1247,9 @@ COMPAT_SYSCALL_DEFINE5(preadv64v2, unsigned long, fd, const struct compat_iovec __user *,vec, unsigned long, vlen, loff_t, pos, rwf_t, flags) { + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_compat_readv(fd, vec, vlen, flags); @@ -1253,6 +1264,9 @@ COMPAT_SYSCALL_DEFINE6(preadv2, compat_ulong_t, fd, { loff_t pos = ((loff_t)pos_high << 32) | pos_low; + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_compat_readv(fd, vec, vlen, flags); @@ -1303,7 +1317,7 @@ COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd, const struct compat_iovec __user *, vec, compat_ulong_t, vlen) { - return do_compat_writev(fd, vec, vlen, 0); + return do_compat_writev(fd, vec, vlen, _RWF_DEFAULT); } static long do_compat_pwritev64(unsigned long fd, @@ -1330,7 +1344,7 @@ COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd, const struct compat_iovec __user *,vec, unsigned long, vlen, loff_t, pos) { - return do_compat_pwritev64(fd, vec, vlen, pos, 0); + return do_compat_pwritev64(fd, vec, vlen, pos, _RWF_DEFAULT); } #endif @@ -1340,7 +1354,7 @@ COMPAT_SYSCALL_DEFINE5(pwritev, compat_ulong_t, fd, { loff_t pos = ((loff_t)pos_high << 32) | pos_low; - return do_compat_pwritev64(fd, vec, vlen, pos, 0); + return do_compat_pwritev64(fd, vec, vlen, pos, _RWF_DEFAULT); } #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2 @@ -1348,6 +1362,9 @@ COMPAT_SYSCALL_DEFINE5(pwritev64v2, unsigned long, fd, const struct compat_iovec __user *,vec, unsigned long, vlen, loff_t, pos, rwf_t, flags) { + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_compat_writev(fd, vec, vlen, flags); @@ -1361,6 +1378,9 @@ COMPAT_SYSCALL_DEFINE6(pwritev2, compat_ulong_t, fd, { loff_t pos = ((loff_t)pos_high << 32) | pos_low; + if (flags == _RWF_DEFAULT) + return -EOPNOTSUPP; + if (pos == -1) return do_compat_writev(fd, vec, vlen, flags); diff --git a/fs/splice.c b/fs/splice.c index 25212dcca2df..1b7fdcce5d6b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -302,6 +302,12 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, iov_iter_pipe(&to, READ, pipe, len); idx = to.idx; init_sync_kiocb(&kiocb, in); + /* + * SPLICE_F_NONBLOCK is only used on the pipe/socket end??? + * + * Don't set IOCB_NOWAIT based on it here (O_NONBLOCK might set + * IOCB_NOWAIT though). + */ kiocb.ki_pos = *ppos; ret = call_read_iter(in, &kiocb, &to); if (ret > 0) { @@ -355,7 +361,8 @@ static ssize_t kernel_readv(struct file *file, const struct kvec *vec, old_fs = get_fs(); set_fs(KERNEL_DS); /* The cast to a user pointer is valid due to the set_fs() */ - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, 0); + res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, + _RWF_DEFAULT); set_fs(old_fs); return res; @@ -742,7 +749,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, } iov_iter_bvec(&from, WRITE, array, n, sd.total_len - left); - ret = vfs_iter_write(out, &from, &sd.pos, 0); + ret = vfs_iter_write(out, &from, &sd.pos, _RWF_DEFAULT); if (ret <= 0) break; diff --git a/include/linux/fs.h b/include/linux/fs.h index 2f66e247ecba..bc159cb87ea5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -83,6 +83,12 @@ extern int sysctl_protected_fifos; extern int sysctl_protected_regular; typedef __kernel_rwf_t rwf_t; +/* + * kernel internal only value to signal using default flags from file; + * can't be combined with other flags and only used to simplify kernel + * APIs. + */ +#define _RWF_DEFAULT ((__force __kernel_rwf_t)-1) struct buffer_head; typedef int (get_block_t)(struct inode *inode, sector_t iblock, @@ -3332,11 +3338,21 @@ static inline int iocb_flags(struct file *file) res |= IOCB_DSYNC; if (file->f_flags & __O_SYNC) res |= IOCB_SYNC; + if ((file->f_flags & O_NONBLOCK) && (file->f_mode & FMODE_NOWAIT)) + res |= IOCB_NOWAIT; return res; } +/* does NOT handle _RWF_DEFAULT */ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) { + /* + * unset all flags controlled through RWF, right now all but: + * IOCB_EVENTFD, IOCB_DIRECT, IOCB_WRITE + */ + ki->ki_flags &= ~(IOCB_APPEND | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC | + IOCB_NOWAIT); + if (unlikely(flags & ~RWF_SUPPORTED)) return -EOPNOTSUPP; @@ -3356,6 +3372,41 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) return 0; } +static inline rwf_t rwf_flags(struct file *file) +{ + rwf_t flags = 0; + + if (file->f_flags & O_APPEND) + flags |= RWF_APPEND; + if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host)) + flags |= RWF_DSYNC; + if (file->f_flags & __O_SYNC) + flags |= RWF_SYNC; + if ((file->f_flags & O_NONBLOCK) && (file->f_mode & FMODE_NOWAIT)) + flags |= RWF_NOWAIT; + + return flags; +} + +static inline rwf_t rwf_from_iocb_flags(struct kiocb *iocb) +{ + int ifl = iocb->ki_flags; + rwf_t flags = 0; + + if (ifl & IOCB_APPEND) + flags |= RWF_APPEND; + if (ifl & IOCB_NOWAIT) + flags |= RWF_NOWAIT; + if (ifl & IOCB_HIPRI) + flags |= RWF_HIPRI; + if (ifl & IOCB_DSYNC) + flags |= RWF_DSYNC; + if (ifl & IOCB_SYNC) + flags |= RWF_SYNC; + + return flags; +} + static inline ino_t parent_ino(struct dentry *dentry) { ino_t res; From patchwork Sat May 11 16:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_B=C3=BChler?= X-Patchwork-Id: 10939765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72E11924 for ; Sat, 11 May 2019 16:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63EA1212D8 for ; Sat, 11 May 2019 16:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 584DF212DA; Sat, 11 May 2019 16:57:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 162AB212D8 for ; Sat, 11 May 2019 16:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728637AbfEKQ5a (ORCPT ); Sat, 11 May 2019 12:57:30 -0400 Received: from mail.stbuehler.de ([5.9.32.208]:54210 "EHLO mail.stbuehler.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbfEKQ5a (ORCPT ); Sat, 11 May 2019 12:57:30 -0400 Received: from chromobil.fritz.box (unknown [IPv6:2a02:8070:a29c:5000:823f:5dff:fe0f:b5b6]) by mail.stbuehler.de (Postfix) with ESMTPSA id 5DE1BC03030; Sat, 11 May 2019 16:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=stbuehler.de; s=stbuehler1; t=1557593848; bh=Sz0IqtVp0zqbISyZSsfHYQ6NljV1iL3lwcnJvx5rZy0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PhlNa/R+jW+U/UqufrFFNRpGK7MjamdVqEKemLD/JCRH5V4Rg/RcmH+W6PFscKlRS T05InqtjRBDvMHfFGiVFQOLsAUdNqe+8063wGKatw+kZiPGQkm5ILGchXOkyPRF55V aQ48Ry6kOCqMtWfw7WPyyg+ya8v5IJylkT7TKgO4= From: =?utf-8?q?Stefan_B=C3=BChler?= To: Jens Axboe , Alexander Viro , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/5] tcp: handle SPLICE_F_NONBLOCK in tcp_splice_read Date: Sat, 11 May 2019 18:57:24 +0200 Message-Id: <20190511165727.31599-2-source@stbuehler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190511165727.31599-1-source@stbuehler.de> References: <20190511165727.31599-1-source@stbuehler.de> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now both O_NONBLOCK and SPLICE_F_NONBLOCK will trigger non-blocking behavior. The spice man page is unclear about the exact semantics: First it says splice may still block if SPLICE_F_NONBLOCK is set but O_NONBLOCK isn't. Then it says it might return EAGAIN if one or the other is set (and on my debian system it says EAGAIN can only be returned if SPLICE_F_NONBLOCK was set). Signed-off-by: Stefan Bühler --- net/ipv4/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6baa6dc1b13b..65f9917ed8ca 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -784,6 +784,8 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos, long timeo; ssize_t spliced; int ret; + bool noblock = (sock->file->f_flags & O_NONBLOCK) || + (flags & SPLICE_F_NONBLOCK); sock_rps_record_flow(sk); /* @@ -796,7 +798,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos, lock_sock(sk); - timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK); + timeo = sock_rcvtimeo(sk, noblock); while (tss.len) { ret = __tcp_splice_read(sk, &tss); if (ret < 0) From patchwork Sat May 11 16:57:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_B=C3=BChler?= X-Patchwork-Id: 10939779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D40BA17E0 for ; Sat, 11 May 2019 16:57:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4CB3212D8 for ; Sat, 11 May 2019 16:57:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9455212DA; Sat, 11 May 2019 16:57:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 543A3212D8 for ; Sat, 11 May 2019 16:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728664AbfEKQ5b (ORCPT ); Sat, 11 May 2019 12:57:31 -0400 Received: from mail.stbuehler.de ([5.9.32.208]:54220 "EHLO mail.stbuehler.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbfEKQ5a (ORCPT ); Sat, 11 May 2019 12:57:30 -0400 Received: from chromobil.fritz.box (unknown [IPv6:2a02:8070:a29c:5000:823f:5dff:fe0f:b5b6]) by mail.stbuehler.de (Postfix) with ESMTPSA id A853BC030C0; Sat, 11 May 2019 16:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=stbuehler.de; s=stbuehler1; t=1557593848; bh=CMEz/QIJbaTDIQoqKRDXXFv3bSR004q+JIkQB31NCVQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=S1Y8gyJMi2pLIKmlc/ox042/DXlGILxJCmuOdmDLaYdZ26u5W3jXN93yvXBUVbMwF kbZJo5X1v6RUgeEWPMoksq2TkIJdpX7sTTOZK7LmpAvq60jFrfoMieyBLHCzBsrwN7 l2x8jf+zGi+QiokWD/gZA21MXdCEqsPmjF/72pdA= From: =?utf-8?q?Stefan_B=C3=BChler?= To: Jens Axboe , Alexander Viro , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 3/5] pipe: use IOCB_NOWAIT instead of O_NONBLOCK Date: Sat, 11 May 2019 18:57:25 +0200 Message-Id: <20190511165727.31599-3-source@stbuehler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190511165727.31599-1-source@stbuehler.de> References: <20190511165727.31599-1-source@stbuehler.de> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix pipe read_iter/write_iter implementations to handle IOCB_NOWAIT; for simple reads IOCB_NOWAIT will be set if O_NONBLOCK was set. Signed-off-by: Stefan Bühler --- fs/pipe.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 41065901106b..a122331cf30f 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -335,13 +335,13 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) break; if (!pipe->waiting_writers) { /* syscall merging: Usually we must not sleep - * if O_NONBLOCK is set, or if we got some data. + * if IOCB_NOWAIT is set, or if we got some data. * But if a writer sleeps in kernel space, then * we can wait for that data without violating POSIX. */ if (ret) break; - if (filp->f_flags & O_NONBLOCK) { + if (iocb->ki_flags & IOCB_NOWAIT) { ret = -EAGAIN; break; } @@ -446,7 +446,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) pipe->tmp_page = page; } /* Always wake up, even if the copy fails. Otherwise - * we lock up (O_NONBLOCK-)readers that sleep due to + * we lock up (IOCB_NOWAIT-)readers that sleep due to * syscall merging. * FIXME! Is this really true? */ @@ -477,7 +477,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) } if (bufs < pipe->buffers) continue; - if (filp->f_flags & O_NONBLOCK) { + if (iocb->ki_flags & IOCB_NOWAIT) { if (!ret) ret = -EAGAIN; break; @@ -780,6 +780,7 @@ int create_pipe_files(struct file **res, int flags) iput(inode); return PTR_ERR(f); } + f->f_mode |= FMODE_NOWAIT; f->private_data = inode->i_pipe; @@ -791,6 +792,7 @@ int create_pipe_files(struct file **res, int flags) return PTR_ERR(res[0]); } res[0]->private_data = inode->i_pipe; + res[0]->f_mode |= FMODE_NOWAIT; res[1] = f; return 0; } @@ -996,6 +998,8 @@ static int fifo_open(struct inode *inode, struct file *filp) goto err; } + filp->f_mode |= FMODE_NOWAIT; + /* Ok! */ __pipe_unlock(pipe); return 0; From patchwork Sat May 11 16:57:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_B=C3=BChler?= X-Patchwork-Id: 10939767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17DBA14B6 for ; Sat, 11 May 2019 16:57:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08CFB212D8 for ; Sat, 11 May 2019 16:57:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F16FC212DA; Sat, 11 May 2019 16:57:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86C01212D8 for ; Sat, 11 May 2019 16:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728674AbfEKQ5b (ORCPT ); Sat, 11 May 2019 12:57:31 -0400 Received: from mail.stbuehler.de ([5.9.32.208]:54232 "EHLO mail.stbuehler.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726775AbfEKQ5a (ORCPT ); Sat, 11 May 2019 12:57:30 -0400 Received: from chromobil.fritz.box (unknown [IPv6:2a02:8070:a29c:5000:823f:5dff:fe0f:b5b6]) by mail.stbuehler.de (Postfix) with ESMTPSA id 03623C030C3; Sat, 11 May 2019 16:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=stbuehler.de; s=stbuehler1; t=1557593849; bh=u5ZDNi+s7yZ4UvB+sA1PHHntIcDOLPWNW2D1Vl08doo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MCpeJayEpS4qKzxXEuDADy/+o5TFX6r5gO2MKltaTnCXyJcGl2vexaKbJPKoACuwP DkF29bNDkbx6XfpCoAMkuFcQZ6LsB4yYldngwuCph4HboQGAbP0Dh5PoqDWA1X4MoP QkUXPioHWQrtUnIMKoayzi4I/DTFJBxe1s2TIzfw= From: =?utf-8?q?Stefan_B=C3=BChler?= To: Jens Axboe , Alexander Viro , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 4/5] socket: use IOCB_NOWAIT instead of O_NONBLOCK Date: Sat, 11 May 2019 18:57:26 +0200 Message-Id: <20190511165727.31599-4-source@stbuehler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190511165727.31599-1-source@stbuehler.de> References: <20190511165727.31599-1-source@stbuehler.de> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix socket read_iter/write_iter implementations to handle IOCB_NOWAIT; for simple reads IOCB_NOWAIT will be set if O_NONBLOCK was set. Signed-off-by: Stefan Bühler --- net/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/socket.c b/net/socket.c index 8255f5bda0aa..1e2f6819ea2b 100644 --- a/net/socket.c +++ b/net/socket.c @@ -410,6 +410,7 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) sock_release(sock); return file; } + file->f_mode |= FMODE_NOWAIT; sock->file = file; file->private_data = sock; @@ -954,7 +955,7 @@ static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to) .msg_iocb = iocb}; ssize_t res; - if (file->f_flags & O_NONBLOCK) + if (iocb->ki_flags & IOCB_NOWAIT) msg.msg_flags = MSG_DONTWAIT; if (iocb->ki_pos != 0) @@ -979,7 +980,7 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_pos != 0) return -ESPIPE; - if (file->f_flags & O_NONBLOCK) + if (iocb->ki_flags & IOCB_NOWAIT) msg.msg_flags = MSG_DONTWAIT; if (sock->type == SOCK_SEQPACKET) From patchwork Sat May 11 16:57:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_B=C3=BChler?= X-Patchwork-Id: 10939771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF8BB1575 for ; Sat, 11 May 2019 16:57:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE863212D8 for ; Sat, 11 May 2019 16:57:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2DF4212DB; Sat, 11 May 2019 16:57:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BBA0212D9 for ; Sat, 11 May 2019 16:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728688AbfEKQ5d (ORCPT ); Sat, 11 May 2019 12:57:33 -0400 Received: from mail.stbuehler.de ([5.9.32.208]:54240 "EHLO mail.stbuehler.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728524AbfEKQ5b (ORCPT ); Sat, 11 May 2019 12:57:31 -0400 Received: from chromobil.fritz.box (unknown [IPv6:2a02:8070:a29c:5000:823f:5dff:fe0f:b5b6]) by mail.stbuehler.de (Postfix) with ESMTPSA id 598B3C030C4; Sat, 11 May 2019 16:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=stbuehler.de; s=stbuehler1; t=1557593849; bh=MWXSBGxPaBW/HBIO9l9nup2qTJSSGAZJVidtIRfiMQ0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HwCGi4ypIvMndly4XoW4wATu+dOxmlFQxV8388KTImdQ0/V6mwZv9b1raA/C7cLYE 3DSGBiqUq8FsxNgpbPQRzCRYgOfkbG5J+Kh8n52deNce/d/jXo7T8Wgkjf/JwhLpwW la3NmUZcVD9eIQP7RCyXSIJyBs+jq+EN6XgOHUn8= From: =?utf-8?q?Stefan_B=C3=BChler?= To: Jens Axboe , Alexander Viro , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 5/5] io_uring: use FMODE_NOWAIT to detect files supporting IOCB_NOWAIT Date: Sat, 11 May 2019 18:57:27 +0200 Message-Id: <20190511165727.31599-5-source@stbuehler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190511165727.31599-1-source@stbuehler.de> References: <20190511165727.31599-1-source@stbuehler.de> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This replaces the magic check looking for S_ISBLK(mode) || S_ISCHR(mode); given the io_uring file doesn't support read/write the check for io_uring_fops is useless anyway. Signed-off-by: Stefan Bühler --- fs/io_uring.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index e1c6ab63628f..396ce6804977 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -867,23 +867,6 @@ static struct file *io_file_get(struct io_submit_state *state, int fd) return state->file; } -/* - * If we tracked the file through the SCM inflight mechanism, we could support - * any file. For now, just ensure that anything potentially problematic is done - * inline. - */ -static bool io_file_supports_async(struct file *file) -{ - umode_t mode = file_inode(file)->i_mode; - - if (S_ISBLK(mode) || S_ISCHR(mode)) - return true; - if (S_ISREG(mode) && file->f_op != &io_uring_fops) - return true; - - return false; -} - static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s, bool force_nonblock) { @@ -896,7 +879,13 @@ static int io_prep_rw(struct io_kiocb *req, const struct sqe_submit *s, if (!req->file) return -EBADF; - if (force_nonblock && !io_file_supports_async(req->file)) + /* + * don't set IOCB_NOWAIT if not supported (forces async punt) + * + * we don't punt if NOWAIT is not supported but requested as + * kiocb_set_rw_flags will return EOPNOTSUPP + */ + if (force_nonblock && !(req->file->f_mode & FMODE_NOWAIT)) force_nonblock = false; kiocb->ki_pos = READ_ONCE(sqe->off);