From patchwork Fri Jun 30 15:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A2CBEB64D7 for ; Fri, 30 Jun 2023 15:25:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A95D08E001F; Fri, 30 Jun 2023 11:25:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1F588E000F; Fri, 30 Jun 2023 11:25:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 898F08E001F; Fri, 30 Jun 2023 11:25:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7A1808E000F for ; Fri, 30 Jun 2023 11:25:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3FE0E160D48 for ; Fri, 30 Jun 2023 15:25:42 +0000 (UTC) X-FDA: 80959788924.14.6004343 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 6834114001C for ; Fri, 30 Jun 2023 15:25:40 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JbTL1wRB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HIKi0zHLnu1hjZ3YJMMoOoPZaQGGpdOq8FelXRkEWEM=; b=EK9cCzFOgpCUwPHOy9bR/B3MjDE65fdr3PHsVenMQkmi6qe/R3v7HacyxJv0qAy8zhcqdw l8z06zBDEdTZ+L+RncCvfRBpcEnykQLK59gpbX15ComOnca41Wx+cL8i8YwPbMNjYLPAec ILJfuOWy8F1A9SHmIaVlgif8IJcKO6k= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JbTL1wRB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138740; a=rsa-sha256; cv=none; b=8rS6Ms3fnzdhFJSLI5zneZ+s7m8doshTB3KP/9Iqs0Fl9StIn3Cm87Q19O9GBYsz4nSy2O PA79p9zPh/I4YhpXrjZiWT+gO7Wna3h5MOeNgSgq+770ZG4urZOnEeNHLmOW5Ar8rMc3Cm Ty6tKVdgLrWujNInBAHP2XDXUUZqMk0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HIKi0zHLnu1hjZ3YJMMoOoPZaQGGpdOq8FelXRkEWEM=; b=JbTL1wRBI3vo4o5i79c122awOVCh2biY3VoPHB9x14DJPhMvWMS8HNaVNkufugCq85EX+s K/J2pvNWsR0ZdPAEqlBST2ZgzGoODVxtBLYNCu+udgSD+Ew7iupyQWMcp7ujulBhIJUSO8 RjJAFK6L+B+IXe1Zci/HxakQS+UovR0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-119-VHeZZlbKNWaK3rGxPAwuUg-1; Fri, 30 Jun 2023 11:25:35 -0400 X-MC-Unique: VHeZZlbKNWaK3rGxPAwuUg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44F3B85A58A; Fri, 30 Jun 2023 15:25:34 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D5B3140E952; Fri, 30 Jun 2023 15:25:32 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Christian Brauner Subject: [RFC PATCH 02/11] vfs: Set IOCB_WRITE in iocbs that we're going to write from Date: Fri, 30 Jun 2023 16:25:15 +0100 Message-ID: <20230630152524.661208-3-dhowells@redhat.com> In-Reply-To: <20230630152524.661208-1-dhowells@redhat.com> References: <20230630152524.661208-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6834114001C X-Stat-Signature: ddph4p1mdpeub4b9kqb9x19jzzgojty1 X-HE-Tag: 1688138740-515371 X-H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dcGlnvuceNQ6Q9M1mgPcTsp8BdX0Kc+LdanXn90c7Dng1f2inFI2gqbxeWBaVdDqzzjMr1pIJquIXqatE8xNmkTvcokGcrjYhlaKvNGH0v5uiRAgYzLtNr05RqQcKqlM34kn5lhKqmSSYUFhMznVIWeivfyI/5iTpgFHi18fB8lgLg0Zc024hL91X1tQIz2OE5OFOARJtBbKqJ0pP5J4W/n8NLh12tDOAyhPp/uZDHRmF5QhqjxzqhDsTZO3Zu0CheaFqVQLOVYjdDfA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: IOCB_WRITE is set by aio, io_uring and cachefiles before submitting a write operation to the VFS, but it isn't set by, say, the write() system call. Fix this by adding an extra argument to init_sync_kiocb() to indicate the direction and setting that to READ or WRITE, which will cause IOCB_WRITE to be set as appropriate. Whilst we're at it, rename init_sync_kiocb() to init_kiocb(). This will allow drivers to use IOCB_WRITE instead of the iterator data source to determine the I/O direction. Signed-off-by: David Howells cc: Christoph Hellwig cc: Jens Axboe cc: Christian Brauner cc: Alexander Viro cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig --- fs/btrfs/ioctl.c | 4 ++-- fs/read_write.c | 10 +++++----- fs/seq_file.c | 2 +- fs/splice.c | 2 +- include/linux/fs.h | 6 +++++- mm/filemap.c | 2 +- mm/page_io.c | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a895d105464b..15870337dd26 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4422,7 +4422,7 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp, if (ret < 0) goto out_iov; - init_sync_kiocb(&kiocb, file); + init_kiocb(&kiocb, file, READ); kiocb.ki_pos = pos; ret = btrfs_encoded_read(&kiocb, &iter, &args); @@ -4523,7 +4523,7 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool if (ret < 0) goto out_end_write; - init_sync_kiocb(&kiocb, file); + init_kiocb(&kiocb, file, WRITE); ret = kiocb_set_rw_flags(&kiocb, 0); if (ret) goto out_end_write; diff --git a/fs/read_write.c b/fs/read_write.c index b07de77ef126..6fe517047095 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -382,7 +382,7 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo struct iov_iter iter; ssize_t ret; - init_sync_kiocb(&kiocb, filp); + init_kiocb(&kiocb, filp, READ); kiocb.ki_pos = (ppos ? *ppos : 0); iov_iter_ubuf(&iter, ITER_DEST, buf, len); @@ -422,7 +422,7 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) if (unlikely(!file->f_op->read_iter || file->f_op->read)) return warn_unsupported(file, "read"); - init_sync_kiocb(&kiocb, file); + init_kiocb(&kiocb, file, READ); kiocb.ki_pos = pos ? *pos : 0; iov_iter_kvec(&iter, ITER_DEST, &iov, 1, iov.iov_len); ret = file->f_op->read_iter(&kiocb, &iter); @@ -484,7 +484,7 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t struct iov_iter iter; ssize_t ret; - init_sync_kiocb(&kiocb, filp); + init_kiocb(&kiocb, filp, WRITE); kiocb.ki_pos = (ppos ? *ppos : 0); iov_iter_ubuf(&iter, ITER_SOURCE, (void __user *)buf, len); @@ -512,7 +512,7 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po if (unlikely(!file->f_op->write_iter || file->f_op->write)) return warn_unsupported(file, "write"); - init_sync_kiocb(&kiocb, file); + init_kiocb(&kiocb, file, WRITE); kiocb.ki_pos = pos ? *pos : 0; ret = file->f_op->write_iter(&kiocb, from); if (ret > 0) { @@ -723,7 +723,7 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, struct kiocb kiocb; ssize_t ret; - init_sync_kiocb(&kiocb, filp); + init_kiocb(&kiocb, filp, type); ret = kiocb_set_rw_flags(&kiocb, flags); if (ret) return ret; diff --git a/fs/seq_file.c b/fs/seq_file.c index f5fdaf3b1572..1ee6ffc630da 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -155,7 +155,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) struct iov_iter iter; ssize_t ret; - init_sync_kiocb(&kiocb, file); + init_kiocb(&kiocb, file, READ); iov_iter_init(&iter, ITER_DEST, &iov, 1, size); kiocb.ki_pos = *ppos; diff --git a/fs/splice.c b/fs/splice.c index 004eb1c4ce31..867357ebb2c3 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -362,7 +362,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, /* Do the I/O */ iov_iter_bvec(&to, ITER_DEST, bv, npages, len); - init_sync_kiocb(&kiocb, in); + init_kiocb(&kiocb, in, READ); kiocb.ki_pos = *ppos; ret = call_read_iter(in, &kiocb, &to); diff --git a/include/linux/fs.h b/include/linux/fs.h index d4b67bdeb53e..466eba253502 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2017,13 +2017,17 @@ static inline bool HAS_UNMAPPED_ID(struct mnt_idmap *idmap, !vfsgid_valid(i_gid_into_vfsgid(idmap, inode)); } -static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) +static inline void init_kiocb(struct kiocb *kiocb, struct file *filp, + unsigned int rw) { *kiocb = (struct kiocb) { .ki_filp = filp, .ki_flags = filp->f_iocb_flags, .ki_ioprio = get_current_ioprio(), }; + + if (rw == WRITE) + kiocb->ki_flags |= IOCB_WRITE; } static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src, diff --git a/mm/filemap.c b/mm/filemap.c index 9e44a49bbd74..cd763122d2a2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2905,7 +2905,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes)) return 0; - init_sync_kiocb(&iocb, in); + init_kiocb(&iocb, in, READ); iocb.ki_pos = *ppos; /* Work out how much data we can actually add into the pipe */ diff --git a/mm/page_io.c b/mm/page_io.c index 684cd3c7b59b..85cbadaf7395 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -312,7 +312,7 @@ static void swap_writepage_fs(struct page *page, struct writeback_control *wbc) } if (!sio) { sio = mempool_alloc(sio_pool, GFP_NOIO); - init_sync_kiocb(&sio->iocb, swap_file); + init_kiocb(&sio->iocb, swap_file, WRITE); sio->iocb.ki_complete = sio_write_complete; sio->iocb.ki_pos = pos; sio->pages = 0; @@ -443,7 +443,7 @@ static void swap_readpage_fs(struct page *page, } if (!sio) { sio = mempool_alloc(sio_pool, GFP_KERNEL); - init_sync_kiocb(&sio->iocb, sis->swap_file); + init_kiocb(&sio->iocb, sis->swap_file, READ); sio->iocb.ki_pos = pos; sio->iocb.ki_complete = sio_read_complete; sio->pages = 0;