From patchwork Fri Jun 30 15:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298352 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 456CCEB64D7 for ; Fri, 30 Jun 2023 15:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D54C88E001E; Fri, 30 Jun 2023 11:25:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D05E28E000F; Fri, 30 Jun 2023 11:25:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7EC88E001E; Fri, 30 Jun 2023 11:25:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AA43F8E000F for ; Fri, 30 Jun 2023 11:25:39 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 53756A0E7E for ; Fri, 30 Jun 2023 15:25:39 +0000 (UTC) X-FDA: 80959788798.30.C71852B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id C5E4810001D for ; Fri, 30 Jun 2023 15:25:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O+a2Rsvs; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1688138736; 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=sac/z7qt8qX/jw2GCw1Fghx39S+xMjFejmZ6Kx/zzF8=; b=lLBoW5OOWrFipieI7eSdE+XTAt/eluny3JGfxQczAVlqikjC2+iAmfFYWTGwSuuFI/XA7f Bm4W09x6vGn7Qrf0wceu6gi93qZx3613HBGRU6sUGGlX6hFece2PLcF3Q9FBo7qYsHHgik ErjbCayZQvyQj6mvmIXVcjjN5aSdcaw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O+a2Rsvs; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138736; a=rsa-sha256; cv=none; b=z0sL0CmtoeChEECo1gZo25G73BAHVn9W71l+47BLw96KwPy7yhQNvD25RHn2onKpbt4234 mPzo1X1xI/RpSSfCjTAnuP8K89m+5lwdok6mB+u8PNqL/W7odUIMh+K7Zwpt6iYapRB4II XNp2McXaQ63mqy0Mn1r4D3Q66rBxCp0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138736; 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=sac/z7qt8qX/jw2GCw1Fghx39S+xMjFejmZ6Kx/zzF8=; b=O+a2RsvsMFDuJurZzF/1/8p/+8qIZikN9H92ttfHC3i92x694Hy51dYpM2QzfwAGFJw9bn YTIfTVDdgXhR6jB+kbp/uI4YVQF54OtL4c+qiQ0w/7SeTAWRlNvEhbn/I9XnUORk8lHwGa 1A+nwnVhYi8kjgIyVf/SgMcQggaqHEk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-CdKJCRj1OimaFZheAWzHmw-1; Fri, 30 Jun 2023 11:25:32 -0400 X-MC-Unique: CdKJCRj1OimaFZheAWzHmw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 782421C07545; Fri, 30 Jun 2023 15:25:31 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33F2A492B02; Fri, 30 Jun 2023 15:25:29 +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 01/11] iov_iter: Fix comment refs to iov_iter_get_pages/pages_alloc() Date: Fri, 30 Jun 2023 16:25:14 +0100 Message-ID: <20230630152524.661208-2-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.9 X-Rspamd-Queue-Id: C5E4810001D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pb91q747xnimbnot9koidzjb1gmyga8c X-HE-Tag: 1688138736-657661 X-HE-Meta: U2FsdGVkX1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GpAr08Wc2t4DGretXrZDHdQb6SDydAJSqwsFpMXtqZlSx8qOMKzJHSeiYJoFRZpPPIZ0ntmIwWb2TkS/gj2ZiJ3gESAjV50Gr7ZS3mzii9MUP4jewPM3WNzaaIV9w/HaB3AOsNC1lW3+z1I6D4XIYQIiozJK5EXfzsCGF9JP0CxS/awPqseyflLucgwt93ow1ysFhWR+G72vnWdvCkTQTcWXjNjl6DetJXi6Wij5er667G6y7lae6N2KA== 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: Fix references to iov_iter_get_pages/pages_alloc() in comments to refer to the *2 interfaces instead. 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 --- fs/ceph/file.c | 4 ++-- include/linux/mm_types.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index b1925232dc08..3bb27b9ce751 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -75,7 +75,7 @@ static __le32 ceph_flags_sys2wire(u32 flags) */ /* - * How many pages to get in one call to iov_iter_get_pages(). This + * How many pages to get in one call to iov_iter_get_pages2(). This * determines the size of the on-stack array used as a buffer. */ #define ITER_GET_BVECS_PAGES 64 @@ -115,7 +115,7 @@ static ssize_t __iter_get_bvecs(struct iov_iter *iter, size_t maxsize, } /* - * iov_iter_get_pages() only considers one iov_iter segment, no matter + * iov_iter_get_pages2() only considers one iov_iter segment, no matter * what maxsize or maxpages are given. For ITER_BVEC that is a single * page. * diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index de10fc797c8e..f49029c943b0 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1249,7 +1249,7 @@ enum { /* * FOLL_LONGTERM indicates that the page will be held for an indefinite * time period _often_ under userspace control. This is in contrast to - * iov_iter_get_pages(), whose usages are transient. + * iov_iter_get_pages2(), whose usages are transient. */ FOLL_LONGTERM = 1 << 8, /* split huge pmd before returning */ 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: r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H8l AxQgphDX mi1u2mJvQVL80eBHuVzq8JT2kWdf7kmypg0hp5NYZYLJg8aFj+/dm+qeBHSH0M4Xs9qNzFcqYo4dcGlnvuceNQ6Q9M1mgPcTsp8BdX0Kc+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; From patchwork Fri Jun 30 15:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298355 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 99739EB64DA for ; Fri, 30 Jun 2023 15:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36A078E0020; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F9298E000F; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05AD48E0020; Fri, 30 Jun 2023 11:25:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DC1F58E000F for ; Fri, 30 Jun 2023 11:25:48 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A786DA0E7D for ; Fri, 30 Jun 2023 15:25:48 +0000 (UTC) X-FDA: 80959789176.26.C16E652 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id A73F780020 for ; Fri, 30 Jun 2023 15:25:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IdsPsrgu; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1688138746; 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=jdlHa+W7u2onhke2f0yOnHTE0908QZoN85mOH5J+0KA=; b=NX+s+HqSegr7fVRu/9vE8KoCvY47Ukx6Eo2IziVmBWMbT2Ej3bOqZ/7KjXBeWcCwXGPaNm JO1SUtREd2rIjutoD7UfDos8lcqQ8nN/9aKI41bCayxiBq/LI/ohcxdSexH1Ovbzik0cmB KfLomiPshSXC4c8nsofMhfuDAJB5qdQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IdsPsrgu; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1688138746; a=rsa-sha256; cv=none; b=qX8MiQ77B79PZw5Z62WfUKELbGy6yIbDMoPKO7fhgUk6I8fcJf0WoHJ+RkJSp0Q7EPkaez rli0xAClxi6Qc0uRasHYXIlHCurmrF+0fkoOggVuJK7r9fQleEde46ErfTxgurgUJo0MGX LEm75DaSOLD7b0PHjOSwLzvIJyKjk2s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138745; 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=jdlHa+W7u2onhke2f0yOnHTE0908QZoN85mOH5J+0KA=; b=IdsPsrguZF9asE2D5ofEurLisK0qn1GGMGaPKwseDgM8zhP67Bti6Zci34B2bH7x2Mp90z Q0enFy0yxkBPVPEyGXGfKg4wjFcIKdUSP01AZq/NOGiUORVZpf8A2jbyZL/xvsGtlzz0+w 87epKBnHN+B+9FEMaEwfiOkdrdva6jI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-471-87Ss81i6PaiGVn_k9Z4wDg-1; Fri, 30 Jun 2023 11:25:38 -0400 X-MC-Unique: 87Ss81i6PaiGVn_k9Z4wDg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2096B29AA2CC; Fri, 30 Jun 2023 15:25:37 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5A0B492C13; Fri, 30 Jun 2023 15:25:34 +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 03/11] vfs: Use init_kiocb() to initialise new IOCBs Date: Fri, 30 Jun 2023 16:25:16 +0100 Message-ID: <20230630152524.661208-4-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.10 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A73F780020 X-Stat-Signature: 3ut3tddk9rzpkpxb9at8keikfysmpfoq X-HE-Tag: 1688138746-224884 X-HE-Meta: U2FsdGVkX18OhHqNJIFNK8qFcxKyj/yxufl/LVQ4JH8MIdpfUAeiQY0vzjm3leaW8nuSzglMye0OVHVxdCiJlzgNFSnof7lFLl/LYVQi5XJlsbcynze2ERKmdmrjyV2qQ8xs2B6yHLTVY3yWCWers3S8KBtEvQdTEYnFM5quBlgUFTotVK7GmuclTt26c6yIrkQeprWM8vgjIqBzQLUhUay4IKlAxYbyThlptoL3UeLmU6JhJ2J+EldJjnoRdrCdsZ11PJC4PrRY0i8u4Gf5L38BmDmDAqsZyk119nwbEntG1JPb7JJgLJyeWFSlwksi0dqxM3VAuwAB1lvuLSDPpiaadaYLHSAJ9ria5FxbuaUA1LGkoAk5I/01hT5iTnNAWE3lBIcts3LDyfrJ0L9ZVsRCMqxRasjfv6Rulj03K2uXuQIWOwOotPCXW+bguSUOzsW55TPjeWqyH03jiLC08JnOmP524Rm/qCaPAfX9jt62bF0h6UALXcBKwar0kUmTuPiQxR6MFPrNWJZvLrJpTMXH7y4BJzwI/ar1A1+Be7GXWuI1eNtIhIAr21b4tQnqFE8bbyXUkY92fTNNXzsxavYbgU8p4hobsPn/y/7oOKsuovjPT7+VZHYtqRfQ77Dogexze0ctFvvnmJk0heKoP4JANxyUN6pQW8wDZfMaVIX2V5l4KIFuEWJ9YMMw5bKbjHizarFvWlWBl+yNEVs65iCvPqYyxHyNGut2dPqxcZgH6LVsvW3RtrqP5vQuXknRIJYzi4/mTxnOwfZadhmHXXru6IIHD3/0+3bD+/zz9/fT9TGiSWfFCOYxXurNTyhjw2Xg0WJKWm+f1RRIEl4A7fHjWlE+8NjYMCBVl+AjazLZp2Yst6jd0uggeSl4Hy9z93QAi5W8hHW7P7G6JP/RhYXWs9puAgyHUPq6KvkqyWf1GIfIzYSczU7zoREMSg4Hp2NVjFKeI4q6hSe7Ofv 3BVSkKo6 613QqjWOrjV9n4L9O8zmo6U1wJI8zWeY+iauXCPrnIFa2QwRYD07ycBNQ0nd/qZSqjQRV0ux2iqABAb+UpGY9ELAxcsqQSzuZPyRCaXPr1WsVRf/0yqzyfZGEtzFu4D3ElILVsa5PcwFFu7QC/HqwVJ14zGk1AQt6B3vJ/qpC72TxPojo2c/gtrGKUQ6P4ZMM34EsAJ+RnIwCfAQyGXM49xN/9G5N2OKbIqqwGcAhd7+/bm2Sg7dWY2aHHsUCyMYPTqYHHiJBkDtKAbKscOtYIhtcM4KpP1AqGnkM2P0R5wPh0cjeSv/fF1toJO+0G8ehxSAUlWCtuuGQBJUipbx/VH2Nsw== 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: A number of places that generate kiocbs didn't use init_sync_kiocb() to initialise the new kiocb. Fix these to always use init_kiocb(). Note that aio and io_uring pass information in through ki_filp through an overlaid union before I can call init_kiocb(), so that gets reinitialised. I don't think it clobbers anything else. After this point, IOCB_WRITE is only set by init_kiocb(). 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 --- drivers/block/loop.c | 11 ++++++----- drivers/nvme/target/io-cmd-file.c | 5 +++-- drivers/target/target_core_file.c | 2 +- fs/aio.c | 9 ++++----- fs/cachefiles/io.c | 10 ++++------ io_uring/rw.c | 10 +++++----- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 37511d2b2caf..ea92235c5ba2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -439,16 +439,17 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, } atomic_set(&cmd->ref, 2); - iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq)); + iov_iter_bvec(&iter, rw == WRITE ? ITER_SOURCE : ITER_DEST, + bvec, nr_bvec, blk_rq_bytes(rq)); iter.iov_offset = offset; + init_kiocb(&cmd->iocb, file, rw); cmd->iocb.ki_pos = pos; - cmd->iocb.ki_filp = file; cmd->iocb.ki_complete = lo_rw_aio_complete; cmd->iocb.ki_flags = IOCB_DIRECT; cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0); - if (rw == ITER_SOURCE) + if (rw == WRITE) ret = call_write_iter(file, &cmd->iocb, &iter); else ret = call_read_iter(file, &cmd->iocb, &iter); @@ -490,12 +491,12 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE); case REQ_OP_WRITE: if (cmd->use_aio) - return lo_rw_aio(lo, cmd, pos, ITER_SOURCE); + return lo_rw_aio(lo, cmd, pos, WRITE); else return lo_write_simple(lo, rq, pos); case REQ_OP_READ: if (cmd->use_aio) - return lo_rw_aio(lo, cmd, pos, ITER_DEST); + return lo_rw_aio(lo, cmd, pos, READ); else return lo_read_simple(lo, rq, pos); default: diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 2d068439b129..0b6577d51b69 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -85,17 +85,18 @@ static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos, if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA)) ki_flags |= IOCB_DSYNC; call_iter = req->ns->file->f_op->write_iter; + init_kiocb(iocb, req->ns->file, WRITE); rw = ITER_SOURCE; } else { call_iter = req->ns->file->f_op->read_iter; + init_kiocb(iocb, req->ns->file, READ); rw = ITER_DEST; } iov_iter_bvec(&iter, rw, req->f.bvec, nr_segs, count); + iocb->ki_flags |= ki_flags; iocb->ki_pos = pos; - iocb->ki_filp = req->ns->file; - iocb->ki_flags = ki_flags | iocb->ki_filp->f_iocb_flags; return call_iter(iocb, &iter); } diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index ce0e000b74fc..d70cf89959dc 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -287,11 +287,11 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, } iov_iter_bvec(&iter, is_write, aio_cmd->bvecs, sgl_nents, len); + init_kiocb(&aio_cmd->iocb, file, is_write); aio_cmd->cmd = cmd; aio_cmd->len = len; aio_cmd->iocb.ki_pos = cmd->t_task_lba * dev->dev_attrib.block_size; - aio_cmd->iocb.ki_filp = file; aio_cmd->iocb.ki_complete = cmd_rw_aio_complete; aio_cmd->iocb.ki_flags = IOCB_DIRECT; diff --git a/fs/aio.c b/fs/aio.c index 77e33619de40..26e173be9448 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1461,14 +1461,14 @@ static void aio_complete_rw(struct kiocb *kiocb, long res) iocb_put(iocb); } -static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) +static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb, int rw) { int ret; + init_kiocb(req, req->ki_filp, rw); req->ki_complete = aio_complete_rw; req->private = NULL; req->ki_pos = iocb->aio_offset; - req->ki_flags = req->ki_filp->f_iocb_flags; if (iocb->aio_flags & IOCB_FLAG_RESFD) req->ki_flags |= IOCB_EVENTFD; if (iocb->aio_flags & IOCB_FLAG_IOPRIO) { @@ -1539,7 +1539,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, struct file *file; int ret; - ret = aio_prep_rw(req, iocb); + ret = aio_prep_rw(req, iocb, READ); if (ret) return ret; file = req->ki_filp; @@ -1566,7 +1566,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, struct file *file; int ret; - ret = aio_prep_rw(req, iocb); + ret = aio_prep_rw(req, iocb, WRITE); if (ret) return ret; file = req->ki_filp; @@ -1592,7 +1592,6 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, sb_start_write(file_inode(file)->i_sb); __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE); } - req->ki_flags |= IOCB_WRITE; aio_rw_done(req, call_write_iter(file, req, &iter)); } kfree(iovec); diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index 175a25fcade8..2c47788f38d2 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -134,11 +134,10 @@ static int cachefiles_read(struct netfs_cache_resources *cres, if (!ki) goto presubmission_error; + init_kiocb(&ki->iocb, file, READ); refcount_set(&ki->ki_refcnt, 2); - ki->iocb.ki_filp = file; + ki->iocb.ki_flags |= IOCB_DIRECT; ki->iocb.ki_pos = start_pos + skipped; - ki->iocb.ki_flags = IOCB_DIRECT; - ki->iocb.ki_ioprio = get_current_ioprio(); ki->skipped = skipped; ki->object = object; ki->inval_counter = cres->inval_counter; @@ -306,10 +305,9 @@ int __cachefiles_write(struct cachefiles_object *object, } refcount_set(&ki->ki_refcnt, 2); - ki->iocb.ki_filp = file; + init_kiocb(&ki->iocb, file, WRITE); ki->iocb.ki_pos = start_pos; - ki->iocb.ki_flags = IOCB_DIRECT | IOCB_WRITE; - ki->iocb.ki_ioprio = get_current_ioprio(); + ki->iocb.ki_flags |= IOCB_DIRECT; ki->object = object; ki->start = start_pos; ki->len = len; diff --git a/io_uring/rw.c b/io_uring/rw.c index 1bce2208b65c..1cade1567162 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -655,12 +655,13 @@ static bool need_complete_io(struct io_kiocb *req) S_ISBLK(file_inode(req->file)->i_mode); } -static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) +static int io_rw_init_file(struct io_kiocb *req, unsigned int io_direction) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); struct kiocb *kiocb = &rw->kiocb; struct io_ring_ctx *ctx = req->ctx; struct file *file = req->file; + fmode_t mode = (io_direction == WRITE) ? FMODE_WRITE : FMODE_READ; int ret; if (unlikely(!file || !(file->f_mode & mode))) @@ -669,7 +670,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) if (!(req->flags & REQ_F_FIXED_FILE)) req->flags |= io_file_get_flags(file); - kiocb->ki_flags = file->f_iocb_flags; + init_kiocb(kiocb, file, io_direction); ret = kiocb_set_rw_flags(kiocb, rw->flags); if (unlikely(ret)) return ret; @@ -738,7 +739,7 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags) iov_iter_restore(&s->iter, &s->iter_state); iovec = NULL; } - ret = io_rw_init_file(req, FMODE_READ); + ret = io_rw_init_file(req, READ); if (unlikely(ret)) { kfree(iovec); return ret; @@ -870,7 +871,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) iov_iter_restore(&s->iter, &s->iter_state); iovec = NULL; } - ret = io_rw_init_file(req, FMODE_WRITE); + ret = io_rw_init_file(req, WRITE); if (unlikely(ret)) { kfree(iovec); return ret; @@ -914,7 +915,6 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) __sb_writers_release(file_inode(req->file)->i_sb, SB_FREEZE_WRITE); } - kiocb->ki_flags |= IOCB_WRITE; if (likely(req->file->f_op->write_iter)) ret2 = call_write_iter(req->file, kiocb, &s->iter); From patchwork Fri Jun 30 15:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298354 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 7506FEB64DC for ; Fri, 30 Jun 2023 15:25:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05D028E0022; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F29E78E0021; Fri, 30 Jun 2023 11:25:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D53A58E0020; Fri, 30 Jun 2023 11:25:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C3CFE8E000F for ; Fri, 30 Jun 2023 11:25:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 63FF0B0AA6 for ; Fri, 30 Jun 2023 15:25:48 +0000 (UTC) X-FDA: 80959789176.30.678E61E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 3C46FC0020 for ; Fri, 30 Jun 2023 15:25:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ilT1Bxkq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1688138746; 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=qTAo5WyNhYPHTqroVSIv35KW6e6h/y8Wf6WLMg0PsSM=; b=Jw41/3xzrSZ54TVHjOoSsHi8//IS+G6Ksdm+9xz8W714GML+IbwhepojYnFCj4amcVSfZR 3EdZgLzy2yIOA//jHuSfQHB2h8oTs2DGZPLnkvpE8zRASG6aYVu0zHQC0oY5DoJnTHrwsg +CeNy8z0xutPEfAX7vXF0p6Fdv08DVs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ilT1Bxkq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1688138746; a=rsa-sha256; cv=none; b=GYidPeUZQWEWnQl1HQ2wCbJUzzh74lMY8EUtAsN0vDt73LMFsYs0U14S1DCtmAWvczCY3d xkCK9Jr3zByeIlGrw51VttxMTa9opuOviob1DDxrKIWHiPzGO0Iu2s92HLznVnQm0sio+O IZyKI2SZYB3ew/ZNmBZDaBtUnRap8cs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138745; 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=qTAo5WyNhYPHTqroVSIv35KW6e6h/y8Wf6WLMg0PsSM=; b=ilT1BxkqNHnajlXRKLi0GRTDscupBnWdU7Vteo9uAl6cdHrHQwQl/YwYwMVrnC2g+OWX+N j8tYsS2V4wAbd6aibr51B/fIBDduT/lNhB3W2bH7jQqJPqkZbgHvjOWJ51HDTzVjMp9tHs WDPP0BokUehccVzd4GW4Jnyl7net81U= 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-669-Mw6G-2_pMeSIKzFWrVhLrA-1; Fri, 30 Jun 2023 11:25:41 -0400 X-MC-Unique: Mw6G-2_pMeSIKzFWrVhLrA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D632F8631DF; Fri, 30 Jun 2023 15:25:39 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id C700DC00049; Fri, 30 Jun 2023 15:25:37 +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 04/11] iov_iter: Use IOCB_WRITE rather than iterator direction Date: Fri, 30 Jun 2023 16:25:17 +0100 Message-ID: <20230630152524.661208-5-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.8 X-Rspamd-Queue-Id: 3C46FC0020 X-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4gHotiWYXBfNa2UZasPKwi1yVDNR1BgH8tbp9KVyuRN52l8HGuFXakKvWZVepLG+QWixu/F5RRj/n5jhV1A9gyMWbF3bVXAxbFjvn0I2RFwoV0RD86Ei6sj2QO68hdqwcCP4feixeJKlYnX5pAKf2N2fh7+fi72JU066nwNnH7A3bKn2WVfAS9U/0jDAjA7tuOlBTn6DQjaSkn/cLD/F7AH3ZYD8uhrqQwUMoF4WEisD7Lj1cnmed4sGGVg9q8Vl4U7z2f41pD+fxJjBeA0cAQW9ebajFbVmyInm+yGrnjocnhOoldT2E7zL5UES3QPgL9eLV382SM9LoVGz4Eq5qSIw== 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: If a kiocb is available, use the IOCB_WRITE flag instead of the iterator 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 --- block/fops.c | 8 ++++---- fs/9p/vfs_addr.c | 2 +- fs/affs/file.c | 4 ++-- fs/ceph/file.c | 2 +- fs/dax.c | 2 +- fs/direct-io.c | 22 +++++++++++----------- fs/exfat/inode.c | 6 +++--- fs/ext2/inode.c | 2 +- fs/f2fs/file.c | 10 +++++----- fs/fat/inode.c | 4 ++-- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 8 ++++---- fs/hfs/inode.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/iomap/direct-io.c | 2 +- fs/jfs/inode.c | 2 +- fs/nfs/direct.c | 2 +- fs/nilfs2/inode.c | 2 +- fs/ntfs3/inode.c | 2 +- fs/ocfs2/aops.c | 2 +- fs/orangefs/inode.c | 2 +- fs/reiserfs/inode.c | 2 +- fs/udf/inode.c | 2 +- include/linux/fs.h | 10 ++++++++++ 24 files changed, 57 insertions(+), 47 deletions(-) diff --git a/block/fops.c b/block/fops.c index a286bf3325c5..e70a5ef4d447 100644 --- a/block/fops.c +++ b/block/fops.c @@ -73,7 +73,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, return -ENOMEM; } - if (iov_iter_rw(iter) == READ) { + if (iocb_is_read(iocb)) { bio_init(&bio, bdev, vecs, nr_pages, REQ_OP_READ); if (user_backed_iter(iter)) should_dirty = true; @@ -88,7 +88,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, goto out; ret = bio.bi_iter.bi_size; - if (iov_iter_rw(iter) == WRITE) + if (iocb_is_write(iocb)) task_io_account_write(ret); if (iocb->ki_flags & IOCB_NOWAIT) @@ -174,7 +174,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, struct blk_plug plug; struct blkdev_dio *dio; struct bio *bio; - bool is_read = (iov_iter_rw(iter) == READ), is_sync; + bool is_read = iocb_is_read(iocb), is_sync; blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); loff_t pos = iocb->ki_pos; int ret = 0; @@ -311,7 +311,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, unsigned int nr_pages) { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); - bool is_read = iov_iter_rw(iter) == READ; + bool is_read = iocb_is_read(iocb); blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); struct blkdev_dio *dio; struct bio *bio; diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 8a635999a7d6..18bce4f8a158 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -257,7 +257,7 @@ v9fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ssize_t n; int err = 0; - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { n = p9_client_write(file->private_data, pos, iter, &err); if (n) { struct inode *inode = file_inode(file); diff --git a/fs/affs/file.c b/fs/affs/file.c index e43f2f007ac1..ad70ff27e5f2 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -400,7 +400,7 @@ affs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) loff_t offset = iocb->ki_pos; ssize_t ret; - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { loff_t size = offset + count; if (AFFS_I(inode)->mmu_private < size) @@ -408,7 +408,7 @@ affs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) } ret = blockdev_direct_IO(iocb, inode, iter, affs_get_block); - if (ret < 0 && iov_iter_rw(iter) == WRITE) + if (ret < 0 && iocb_is_write(iocb)) affs_write_failed(mapping, offset + count); return ret; } diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 3bb27b9ce751..453429e9b9e6 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1280,7 +1280,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, struct timespec64 mtime = current_time(inode); size_t count = iov_iter_count(iter); loff_t pos = iocb->ki_pos; - bool write = iov_iter_rw(iter) == WRITE; + bool write = iocb_is_write(iocb); bool should_dirty = !write && user_backed_iter(iter); if (write && ceph_snap(file_inode(file)) != CEPH_NOSNAP) diff --git a/fs/dax.c b/fs/dax.c index 2ababb89918d..5c6ebe64a3fd 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1573,7 +1573,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, if (!iomi.len) return 0; - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { lockdep_assert_held_write(&iomi.inode->i_rwsem); iomi.flags |= IOMAP_WRITE; } else { diff --git a/fs/direct-io.c b/fs/direct-io.c index 7bc494ee56b9..2b517cc5b32d 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -1125,7 +1125,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, */ /* watch out for a 0 len io from a tricksy fs */ - if (iov_iter_rw(iter) == READ && !count) + if (iocb_is_read(iocb) && !count) return 0; dio = kmem_cache_alloc(dio_cache, GFP_KERNEL); @@ -1139,7 +1139,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, memset(dio, 0, offsetof(struct dio, pages)); dio->flags = flags; - if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) { + if (dio->flags & DIO_LOCKING && iocb_is_read(iocb)) { /* will be released by direct_io_worker */ inode_lock(inode); } @@ -1147,7 +1147,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, /* Once we sampled i_size check for reads beyond EOF */ dio->i_size = i_size_read(inode); - if (iov_iter_rw(iter) == READ && offset >= dio->i_size) { + if (iocb_is_read(iocb) && offset >= dio->i_size) { retval = 0; goto fail_dio; } @@ -1160,7 +1160,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, goto fail_dio; } - if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) { + if (dio->flags & DIO_LOCKING && iocb_is_read(iocb)) { struct address_space *mapping = iocb->ki_filp->f_mapping; retval = filemap_write_and_wait_range(mapping, offset, end - 1); @@ -1176,13 +1176,13 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, */ if (is_sync_kiocb(iocb)) dio->is_async = false; - else if (iov_iter_rw(iter) == WRITE && end > i_size_read(inode)) + else if (iocb_is_write(iocb) && end > i_size_read(inode)) dio->is_async = false; else dio->is_async = true; dio->inode = inode; - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { dio->opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; if (iocb->ki_flags & IOCB_NOWAIT) dio->opf |= REQ_NOWAIT; @@ -1194,7 +1194,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, * For AIO O_(D)SYNC writes we need to defer completions to a workqueue * so that we can call ->fsync. */ - if (dio->is_async && iov_iter_rw(iter) == WRITE) { + if (dio->is_async && iocb_is_write(iocb)) { retval = 0; if (iocb_is_dsync(iocb)) retval = dio_set_defer_completion(dio); @@ -1230,7 +1230,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, spin_lock_init(&dio->bio_lock); dio->refcount = 1; - dio->should_dirty = user_backed_iter(iter) && iov_iter_rw(iter) == READ; + dio->should_dirty = user_backed_iter(iter) && iocb_is_read(iocb); sdio.iter = iter; sdio.final_block_in_request = end >> blkbits; @@ -1287,7 +1287,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, * we can let i_mutex go now that its achieved its purpose * of protecting us from looking up uninitialized blocks. */ - if (iov_iter_rw(iter) == READ && (dio->flags & DIO_LOCKING)) + if (iocb_is_read(iocb) && (dio->flags & DIO_LOCKING)) inode_unlock(dio->inode); /* @@ -1299,7 +1299,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, */ BUG_ON(retval == -EIOCBQUEUED); if (dio->is_async && retval == 0 && dio->result && - (iov_iter_rw(iter) == READ || dio->result == count)) + (iocb_is_read(iocb) || dio->result == count)) retval = -EIOCBQUEUED; else dio_await_completion(dio); @@ -1312,7 +1312,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, return retval; fail_dio: - if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) + if (dio->flags & DIO_LOCKING && iocb_is_read(iocb)) inode_unlock(inode); kmem_cache_free(dio_cache, dio); diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 481dd338f2b8..706db9cd1b4e 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -411,10 +411,10 @@ static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = mapping->host; loff_t size = iocb->ki_pos + iov_iter_count(iter); - int rw = iov_iter_rw(iter); + bool writing = iocb_is_write(iocb); ssize_t ret; - if (rw == WRITE) { + if (writing) { /* * FIXME: blockdev_direct_IO() doesn't use ->write_begin(), * so we need to update the ->i_size_aligned to block boundary. @@ -433,7 +433,7 @@ static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * condition of exfat_get_block() and ->truncate(). */ ret = blockdev_direct_IO(iocb, inode, iter, exfat_get_block); - if (ret < 0 && (rw & WRITE)) + if (ret < 0 && writing) exfat_write_failed(mapping, size); return ret; } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 26f135e7ffce..b239c16ab7ee 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -919,7 +919,7 @@ ext2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ssize_t ret; ret = blockdev_direct_IO(iocb, inode, iter, ext2_get_block); - if (ret < 0 && iov_iter_rw(iter) == WRITE) + if (ret < 0 && iocb_is_write(iocb)) ext2_write_failed(mapping, offset + count); return ret; } diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 2435111a8532..7ef596b901d9 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -805,7 +805,7 @@ int f2fs_truncate(struct inode *inode) return 0; } -static bool f2fs_force_buffered_io(struct inode *inode, int rw) +static bool f2fs_force_buffered_io(struct inode *inode, bool writing) { struct f2fs_sb_info *sbi = F2FS_I_SB(inode); @@ -823,9 +823,9 @@ static bool f2fs_force_buffered_io(struct inode *inode, int rw) * for blkzoned device, fallback direct IO to buffered IO, so * all IOs can be serialized by log-structured write. */ - if (f2fs_sb_has_blkzoned(sbi) && (rw == WRITE)) + if (f2fs_sb_has_blkzoned(sbi) && writing) return true; - if (f2fs_lfs_mode(sbi) && rw == WRITE && F2FS_IO_ALIGNED(sbi)) + if (f2fs_lfs_mode(sbi) && writing && F2FS_IO_ALIGNED(sbi)) return true; if (is_sbi_flag_set(sbi, SBI_CP_DISABLED)) return true; @@ -861,7 +861,7 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path, unsigned int bsize = i_blocksize(inode); stat->result_mask |= STATX_DIOALIGN; - if (!f2fs_force_buffered_io(inode, WRITE)) { + if (!f2fs_force_buffered_io(inode, true)) { stat->dio_mem_align = bsize; stat->dio_offset_align = bsize; } @@ -4280,7 +4280,7 @@ static bool f2fs_should_use_dio(struct inode *inode, struct kiocb *iocb, if (!(iocb->ki_flags & IOCB_DIRECT)) return false; - if (f2fs_force_buffered_io(inode, iov_iter_rw(iter))) + if (f2fs_force_buffered_io(inode, iocb_is_write(iocb))) return false; /* diff --git a/fs/fat/inode.c b/fs/fat/inode.c index d99b8549ec8f..237e20891df2 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -261,7 +261,7 @@ static ssize_t fat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) loff_t offset = iocb->ki_pos; ssize_t ret; - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { /* * FIXME: blockdev_direct_IO() doesn't use ->write_begin(), * so we need to update the ->mmu_private to block boundary. @@ -281,7 +281,7 @@ static ssize_t fat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * condition of fat_get_block() and ->truncate(). */ ret = blockdev_direct_IO(iocb, inode, iter, fat_get_block); - if (ret < 0 && iov_iter_rw(iter) == WRITE) + if (ret < 0 && iocb_is_write(iocb)) fat_write_failed(mapping, offset + count); return ret; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 8e74f278a3f6..7bfbe1783462 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -720,7 +720,7 @@ static bool file_extending_write(struct kiocb *iocb, struct iov_iter *from) { struct inode *inode = file_inode(iocb->ki_filp); - return (iov_iter_rw(from) == WRITE && + return (iocb_is_write(iocb) && ((iocb->ki_pos) >= i_size_read(inode) || (iocb->ki_pos + iov_iter_count(from) > i_size_read(inode)))); } diff --git a/fs/fuse/file.c b/fs/fuse/file.c index bc4115288eec..f43a39faa8e4 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2911,7 +2911,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) inode = file->f_mapping->host; i_size = i_size_read(inode); - if ((iov_iter_rw(iter) == READ) && (offset >= i_size)) + if (iocb_is_read(iocb) && (offset >= i_size)) return 0; io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); @@ -2923,7 +2923,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) io->bytes = -1; io->size = 0; io->offset = offset; - io->write = (iov_iter_rw(iter) == WRITE); + io->write = iocb_is_write(iocb); io->err = 0; /* * By default, we want to optimize all I/Os with async request @@ -2956,7 +2956,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) io->done = &wait; } - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { ret = fuse_direct_io(io, iter, &pos, FUSE_DIO_WRITE); fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE); } else { @@ -2979,7 +2979,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) kref_put(&io->refcnt, fuse_io_release); - if (iov_iter_rw(iter) == WRITE) { + if (iocb_is_write(iocb)) { fuse_write_update_attr(inode, pos, ret); /* For extending writes we already hold exclusive lock */ if (ret < 0 && offset + count > i_size) diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index 441d7fc952e3..d95ac1f559b5 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -141,7 +141,7 @@ static ssize_t hfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * In case of error extending write may have instantiated a few * blocks outside i_size. Trim these off again. */ - if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) { + if (unlikely(iocb_is_write(iocb) && ret < 0)) { loff_t isize = i_size_read(inode); loff_t end = iocb->ki_pos + count; diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 7d1a675e037d..9851a6cb9e3b 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -138,7 +138,7 @@ static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * In case of error extending write may have instantiated a few * blocks outside i_size. Trim these off again. */ - if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) { + if (unlikely(iocb_is_write(iocb) && ret < 0)) { loff_t isize = i_size_read(inode); loff_t end = iocb->ki_pos + count; diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index ea3b868c8355..a56099470185 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -510,7 +510,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (iocb->ki_flags & IOCB_NOWAIT) iomi.flags |= IOMAP_NOWAIT; - if (iov_iter_rw(iter) == READ) { + if (iocb_is_read(iocb)) { if (iomi.pos >= dio->i_size) goto out_free_dio; diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c index 8ac10e396050..0d1f94ac9488 100644 --- a/fs/jfs/inode.c +++ b/fs/jfs/inode.c @@ -334,7 +334,7 @@ static ssize_t jfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * In case of error extending write may have instantiated a few * blocks outside i_size. Trim these off again. */ - if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) { + if (unlikely(iocb_is_write(iocb) && ret < 0)) { loff_t isize = i_size_read(inode); loff_t end = iocb->ki_pos + count; diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 9a18c5a69ace..5f4522dd05b5 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -133,7 +133,7 @@ int nfs_swap_rw(struct kiocb *iocb, struct iov_iter *iter) VM_BUG_ON(iov_iter_count(iter) != PAGE_SIZE); - if (iov_iter_rw(iter) == READ) + if (iocb_is_read(iocb)) ret = nfs_file_direct_read(iocb, iter, true); else ret = nfs_file_direct_write(iocb, iter, true); diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index a8ce522ac747..93c61fcb5e91 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -289,7 +289,7 @@ nilfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct inode *inode = file_inode(iocb->ki_filp); - if (iov_iter_rw(iter) == WRITE) + if (iocb_is_write(iocb)) return 0; /* Needs synchronization with the cleaner */ diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 6c560245eef4..5b50c4653ff8 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -774,7 +774,7 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) struct ntfs_inode *ni = ntfs_i(inode); loff_t vbo = iocb->ki_pos; loff_t end; - int wr = iov_iter_rw(iter) & WRITE; + bool wr = iocb_is_write(iocb); size_t iter_count = iov_iter_count(iter); loff_t valid; ssize_t ret; diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 8dfc284e85f0..e8afc0c13f71 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2456,7 +2456,7 @@ static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) !ocfs2_supports_append_dio(osb)) return 0; - if (iov_iter_rw(iter) == READ) + if (iocb_is_read(iocb)) get_block = ocfs2_lock_get_block; else get_block = ocfs2_dio_wr_get_block; diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index 9014bbcc8031..120a9a6c0f3b 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -513,7 +513,7 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb, */ struct file *file = iocb->ki_filp; loff_t pos = iocb->ki_pos; - enum ORANGEFS_io_type type = iov_iter_rw(iter) == WRITE ? + enum ORANGEFS_io_type type = iocb_is_write(iocb) ? ORANGEFS_IO_WRITE : ORANGEFS_IO_READ; loff_t *offset = &pos; struct inode *inode = file->f_mapping->host; diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index 77bd3b27059f..ca57930178f4 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c @@ -3248,7 +3248,7 @@ static ssize_t reiserfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * In case of error extending write may have instantiated a few * blocks outside i_size. Trim these off again. */ - if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) { + if (unlikely(iocb_is_write(iocb) && ret < 0)) { loff_t isize = i_size_read(inode); loff_t end = iocb->ki_pos + count; diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 1e71e04ae8f6..d49c12c1f4d9 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -311,7 +311,7 @@ static ssize_t udf_direct_IO(struct kiocb *iocb, struct iov_iter *iter) if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) return 0; ret = blockdev_direct_IO(iocb, inode, iter, udf_get_block); - if (unlikely(ret < 0 && iov_iter_rw(iter) == WRITE)) + if (unlikely(ret < 0 && iocb_is_write(iocb))) udf_write_failed(mapping, iocb->ki_pos + count); return ret; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 466eba253502..e344db819498 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -368,6 +368,16 @@ static inline bool is_sync_kiocb(struct kiocb *kiocb) return kiocb->ki_complete == NULL; } +static inline bool iocb_is_write(const struct kiocb *kiocb) +{ + return kiocb->ki_flags & IOCB_WRITE; +} + +static inline bool iocb_is_read(const struct kiocb *kiocb) +{ + return !iocb_is_write(kiocb); +} + struct address_space_operations { int (*writepage)(struct page *page, struct writeback_control *wbc); int (*read_folio)(struct file *, struct folio *); From patchwork Fri Jun 30 15:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298356 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 A9DDCEB64D7 for ; Fri, 30 Jun 2023 15:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 936A48E0021; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E6088E000F; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 786D38E0021; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 63F718E000F for ; Fri, 30 Jun 2023 11:25:49 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2BA701C9214 for ; Fri, 30 Jun 2023 15:25:49 +0000 (UTC) X-FDA: 80959789218.21.B4EFFDD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 4068A1C0004 for ; Fri, 30 Jun 2023 15:25:47 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HM6m+C3A; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138747; 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=BxhEpe1dWPNZ3l1c5/r0hZMnotB6Lyrh5knFFcDG1mA=; b=TS7jBlDDirLxkoJ6YmWK+wptJZxD1deTnX0YPO/xTu2fHwuDMljrplLB/FjriwOxngYH32 pcpKqw7xr7qCBMW/9hUpji7ERMbV6koknPNGDG11fsP1Tfpnu6aohHZ7dQJgptjfdm8lM8 m6oKxsALrd4HrFC3qWtWYdo4WHBxVMc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138747; a=rsa-sha256; cv=none; b=XKDI8dAgfV7YJk6O2L7Fa8Skl6YBc0xjxqt+XffkwTNh8CS3qIOPF3YCiaMfMpQzQm1nhs mMFz65X0RxTyMN1fVTqQDyOGtD7x7DEfJTC/RG9sgbdJvTNuLHSE27zZT1pHQWKpP3mwrV Z89cPrtzG9K61ydonoibBaoL+QzQFT0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HM6m+C3A; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138746; 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=BxhEpe1dWPNZ3l1c5/r0hZMnotB6Lyrh5knFFcDG1mA=; b=HM6m+C3AuYnptEN8blSC112/Z1KLz1/5igWNRoI7EnLIlqaqyR9qkxbtm37PgdSGKdNGBk tNNLj1uYCfG6/gti26VThxtnykqsRrKyFWwCnvzLZbz7fzuASubOG8Jzm2xdtFea102sYM exoiSRqfPc4h0LM+5IdO6qOsENIfxxE= 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-225-mxE03HUqMrK2T8QUGz-gSw-1; Fri, 30 Jun 2023 11:25:43 -0400 X-MC-Unique: mxE03HUqMrK2T8QUGz-gSw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65555858290; Fri, 30 Jun 2023 15:25:42 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 703104087C6A; Fri, 30 Jun 2023 15:25:40 +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 05/11] iov_iter: Use IOMAP_WRITE rather than iterator direction Date: Fri, 30 Jun 2023 16:25:18 +0100 Message-ID: <20230630152524.661208-6-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.2 X-Rspamd-Queue-Id: 4068A1C0004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 48yarecbki6f9ittbyfugnxtnyncbjtj X-HE-Tag: 1688138747-121569 X-HE-Meta: U2FsdGVkX19nHmKA6/AA0VzYNYHY7SucXF+DtkXlZpFf0WO1NQQQ9LCUlywPR1+14WVTELL/Q83JptaOK+KiwrMsjiHk4ikBQLhcu1cxnZ7LMIQ14WKcROJSJfK9QV/qMCTGYnX4hZeMDKqnp+xeBvwRWAcVQKKCdsGfmScu1hLBWKoTKzoCQr7kRkAASjhCHWcwySwonJtQl9yf8JciZvPIRcVWf6WzfVMGvS8i3yshMiNl+oZdGjZSr6bgIY+JHhzs/G9m4a79/6PXP1IJOrgzVBIaTY7cXKhn8TuQVSJBa4r/O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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If an iomap_iter is available, use the IOMAP_WRITE flag instead of the iterator 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 --- fs/dax.c | 4 ++-- fs/iomap/direct-io.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 5c6ebe64a3fd..d49480675fc0 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1438,7 +1438,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, loff_t pos = iomi->pos; struct dax_device *dax_dev = iomap->dax_dev; loff_t end = pos + length, done = 0; - bool write = iov_iter_rw(iter) == WRITE; + bool write = iomi->flags & IOMAP_WRITE; bool cow = write && iomap->flags & IOMAP_F_SHARED; ssize_t ret = 0; size_t xfer; @@ -1498,7 +1498,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), DAX_ACCESS, &kaddr, NULL); - if (map_len == -EIO && iov_iter_rw(iter) == WRITE) { + if (map_len == -EIO && write) { map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), DAX_RECOVERY_WRITE, &kaddr, NULL); diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index a56099470185..3095091af680 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -587,7 +587,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, * Revert iter to a state corresponding to that as some callers (such * as the splice code) rely on it. */ - if (iov_iter_rw(iter) == READ && iomi.pos >= dio->i_size) + if (!(iomi.flags & IOMAP_WRITE) && iomi.pos >= dio->i_size) iov_iter_revert(iter, iomi.pos - dio->i_size); if (ret == -EFAULT && dio->size && (dio_flags & IOMAP_DIO_PARTIAL)) { From patchwork Fri Jun 30 15:25:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298357 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 0A32BEB64D7 for ; Fri, 30 Jun 2023 15:25:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A21DD8E0023; Fri, 30 Jun 2023 11:25:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D0988E000F; Fri, 30 Jun 2023 11:25:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8727C8E0023; Fri, 30 Jun 2023 11:25:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 719F18E000F for ; Fri, 30 Jun 2023 11:25:55 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 41B424056C for ; Fri, 30 Jun 2023 15:25:55 +0000 (UTC) X-FDA: 80959789470.06.FEE3E12 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 07B1F40014 for ; Fri, 30 Jun 2023 15:25:52 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M6aDf7kB; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138753; 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=A03JyOO/f7iAqHJBZB+sdm2rxbR0PVujtNmj3kIoBeA=; b=XwdAYvu5mSXKa2BfE5OxRjfKfcfoOZk2GF2Cd+MZJwRTDiHCLIMNU3Ctnm7a9V0V8dqJY6 /GmNt0qiJ4FARkT+QQJt7RzqSqLCsud6Dax2Uy0VBRRO8wGc4szsNZGYgFE2LwMNnCdPCF mTqqUtDBA3Zp9imTjlde7uEB4+EcSy4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M6aDf7kB; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138753; a=rsa-sha256; cv=none; b=AMVvKHE1iefV8rKGvKas3EQmJzZ4h4L35JA7E2qniNzbl0NJ2Bl/h2xhv/sd5+VLUj1V+f zNEmUTrOuX9/zwXzGCFodXIc8OXu99qvrO/jz2OkSOkCTgw4w5W8ZIHCSXVubU5QRZT4Df BGnujUqAGtC2yWK70PJNNCKW+YEvO9Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138752; 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=A03JyOO/f7iAqHJBZB+sdm2rxbR0PVujtNmj3kIoBeA=; b=M6aDf7kBczJIeMtD3t1Y5pAIEnykXo6DE3kXJZreacxQ5/3LWbV+kNRJp1OyAwwMJtIP4k S2IzoK4RNmkjHOTKasXtgqRrPIqNQU8g9dQQIONxDjoZEXKLYHFo/qUV817WsXTAP2RbbO +15xSM7+NV68+elYFZ8hH8DrPJx+Ttw= 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-601-N6FLg4pXOKyVIzUdiDErog-1; Fri, 30 Jun 2023 11:25:47 -0400 X-MC-Unique: N6FLg4pXOKyVIzUdiDErog-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2467A185A793; Fri, 30 Jun 2023 15:25:45 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 187E348FB01; Fri, 30 Jun 2023 15:25:43 +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 06/11] iov_iter: Use op_is_write() rather than iterator direction Date: Fri, 30 Jun 2023 16:25:19 +0100 Message-ID: <20230630152524.661208-7-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.9 X-Rspamd-Queue-Id: 07B1F40014 X-Rspam-User: X-Stat-Signature: to8a7a946z8gybad1qdbiy5qmwxi3316 X-Rspamd-Server: rspam01 X-HE-Tag: 1688138752-619745 X-HE-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z8YZ/Y7FMlnmPM3X8Uc+As4QCa70Pc2nlRCqHpNZ3e40A8P0wg+SCr9cEaVxFERxHTBs+TjGEP33tUYAyPiHqDXGFkqzY8AGcx5HoJHQxBT2bxjrxHWtda+rMY6mQuUSRPgCUchwnPUk23b+uvozVe9S5PZ76Y0otdsiiNfE4mgOivsAtTZw8YDfAQhh1YjX71UoSfHVmCca4ASAjcEjN27zIgXU85Bh7U9WC0kWKhsLCJpZaHQNWHPoQymJrA== 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: If a request struct is available, use op_is_write() instead of the iterator 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 --- block/blk-map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-map.c b/block/blk-map.c index 44d74a30ddac..f8fe114ae433 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -205,7 +205,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data, /* * success */ - if ((iov_iter_rw(iter) == WRITE && + if ((op_is_write(rq->cmd_flags) && (!map_data || !map_data->null_mapped)) || (map_data && map_data->from_user)) { ret = bio_copy_from_iter(bio, iter); From patchwork Fri Jun 30 15:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298358 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 66F0BEB64DC for ; Fri, 30 Jun 2023 15:25:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA3D38E0024; Fri, 30 Jun 2023 11:25:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2E0E8E000F; Fri, 30 Jun 2023 11:25:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B319E8E0024; Fri, 30 Jun 2023 11:25:57 -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 99E818E000F for ; Fri, 30 Jun 2023 11:25:57 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71F58140E2B for ; Fri, 30 Jun 2023 15:25:57 +0000 (UTC) X-FDA: 80959789554.26.1205CC0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 5DFE92001E for ; Fri, 30 Jun 2023 15:25:55 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YHvs6nfM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1688138755; 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=7s8hoY7EpXAbXFSpowadN1tdtKV1KZLtOvJuBTKdpmw=; b=usIYz6PXTuOEZCt4zTSWy1hKGtMGP0y2WBuN3WlLmunBCCN3jlq2Z0537RsRkc7N+eznig P7h/5Hr7u131SZgxjOdx8a5BhRn6e6lMLT1KDz9P+S/omip5oDu+Xtk0mFHqNVJ7wW44o2 3q5Tzr8Hwtw5XvBa3uH+QEt0XsRfZ8Y= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YHvs6nfM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138755; a=rsa-sha256; cv=none; b=qz/62v9XtGp9jRZhlUOTDxps7Wr75NXwndYw/8oQmyZXWefsBO6+LMvikVfVSt26oNPu8X FGVwjv+QAiSv3BPfqIijbzltrMQnr3dJ/Rf1SsL5v80xWoZO9UhV0iIJUSGKAQnWHCmWRP qww3o7RmkS3Z3AcFApD5OwI1WCx44F8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138754; 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=7s8hoY7EpXAbXFSpowadN1tdtKV1KZLtOvJuBTKdpmw=; b=YHvs6nfMrlelXUUxOaaac9F8Jb2zDHjntPQXJCj6OETiVTBEw/8F26hZWlpmMy04LlVlPr jrQMvZV4XHp93HfE41C3W6f55gYf81dM3wCmNFTfR86QPUESuYi6Am71SMpRitNTVhjEWq r0qGVSSOCMYLmEYBx5zhx5lpWxqstdQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-338-Zp02hgoBNIOVX0nerBYChA-1; Fri, 30 Jun 2023 11:25:50 -0400 X-MC-Unique: Zp02hgoBNIOVX0nerBYChA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C5C23C0E456; Fri, 30 Jun 2023 15:25:49 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18E074087C6A; Fri, 30 Jun 2023 15:25:45 +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, Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Christoph Hellwig , Christian Brauner , linux-cifs@vger.kernel.org Subject: [RFC PATCH 07/11] cifs: Drop the check using iov_iter_rw() Date: Fri, 30 Jun 2023 16:25:20 +0100 Message-ID: <20230630152524.661208-8-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.2 X-Rspam-User: X-Stat-Signature: ra17csc4pnhyc4m9w1cx346qbzjznxhj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5DFE92001E X-HE-Tag: 1688138755-106028 X-HE-Meta: U2FsdGVkX1+XBkOJbOAJrnQdG/ejMYZRJdXsXgkqREAcJvLn+yEsWoqC2hjzR+p7/sYQ3VSBEyWqSLsIlI/XMxouBj8hUO3/JxdF7P4fuLKwl8uV5DpqoaoBQSbG7qx7Xod0hoAqLeJJOhUy/KJbEppuFbKK8IRdicmaxirHsOQu1KXStFopzyy04CD0qw2zHZyNSFss2P9r8y6gKRs1oYKpDschTFxt3iESV2qutOH73SOXtl/wo+0TSadd+xyJYCCBIb8doVr0af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P5yDpA9PvSHflHGgbeYrcVKNDDxt9doR/AhUoVgmybOBGS3kgsNMUx3bynms5BsCNfQ0lrG7xo7DthhBEkmz41h1YpyLT5TsxdbtuMgUPZ5rc5zt4u5Xv5Ha7ZCdq 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: smbd_recv() has a check that the iterator is the correct direction. Drop this check as we're getting rid of iov_iter_rw(). Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Ronnie Sahlberg cc: Shyam Prasad N cc: Tom Talpey cc: Christoph Hellwig cc: Jens Axboe cc: Christian Brauner cc: Alexander Viro cc: linux-cifs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/smbdirect.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c index 223e17c16b60..672078d00207 100644 --- a/fs/smb/client/smbdirect.c +++ b/fs/smb/client/smbdirect.c @@ -1906,14 +1906,6 @@ int smbd_recv(struct smbd_connection *info, struct msghdr *msg) unsigned int to_read, page_offset; int rc; - if (iov_iter_rw(&msg->msg_iter) == WRITE) { - /* It's a bug in upper layer to get there */ - cifs_dbg(VFS, "Invalid msg iter dir %u\n", - iov_iter_rw(&msg->msg_iter)); - rc = -EINVAL; - goto out; - } - switch (iov_iter_type(&msg->msg_iter)) { case ITER_KVEC: buf = msg->msg_iter.kvec->iov_base; @@ -1935,7 +1927,6 @@ int smbd_recv(struct smbd_connection *info, struct msghdr *msg) rc = -EINVAL; } -out: /* SMBDirect will read it all or nothing */ if (rc > 0) msg->msg_iter.count = 0; From patchwork Fri Jun 30 15:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298359 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 08E2CEB64D7 for ; Fri, 30 Jun 2023 15:26:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D4068E0025; Fri, 30 Jun 2023 11:26:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95BE48E000F; Fri, 30 Jun 2023 11:26:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FCC08E0025; Fri, 30 Jun 2023 11:26:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6FACE8E000F for ; Fri, 30 Jun 2023 11:26:02 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4CE7816015E for ; Fri, 30 Jun 2023 15:26:02 +0000 (UTC) X-FDA: 80959789764.23.7118F05 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 6F79BA0007 for ; Fri, 30 Jun 2023 15:25:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tbd3Zv1O; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138760; a=rsa-sha256; cv=none; b=k2s2i4NNpEZP4qexE/+C93cyPMoLDUQTA901hN/sTSSnHE5H9o06wV/8//yZuezu5XrQeX enbpt+9Qf4Itas22gC/SRE+HUUN1tRstOS9aBpqZIg34lB6J8LueGcB1+tGWwBb78LxQzM whvORgb7W38/pPs6FU05+Zmutiq4vm8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tbd3Zv1O; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138760; 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=4Jdd9WWzw52HFg7DtTsZeyIq/lnUM49zKvJ/hNK831U=; b=kKuvReNeWvnE3Tz9iujZC8Li7liH0CPDkP7VtdKAQP3dWHm0OgV/NagAvG12tkd9o8iWgN oosEoSQYZbV0vBtsR1cHg26ApVAg4gUXTtyENowns7XhlVQx8IJnzP0M7vNL/Zz+7/sYu/ exCBkBt8FfL2mpMA6+FRVO4LQg3Rl8E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138759; 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=4Jdd9WWzw52HFg7DtTsZeyIq/lnUM49zKvJ/hNK831U=; b=Tbd3Zv1OK4NlKF7NtYKlcD1wwOnM+rRCOStz2x3BM5g/WFl9GlQcnQ9NqFKqQnu+/1s4c4 VwYY29tAEs77ffBQv3uO+Ndj8M0qqUZ5j7Z7agAn0rGPvvN+tIx0SomC0EUhqSUDJrC5Fh 7L99bv4xsyFlqhonvHh18jSjAQCcDDA= 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-636-JWUOtE-7PZaOWCY4vn-G4w-1; Fri, 30 Jun 2023 11:25:52 -0400 X-MC-Unique: JWUOtE-7PZaOWCY4vn-G4w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06884800B35; Fri, 30 Jun 2023 15:25:52 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4B2F2166B2D; Fri, 30 Jun 2023 15:25:49 +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 08/11] iov_iter: Drop iov_iter_rw() and fold in last user Date: Fri, 30 Jun 2023 16:25:21 +0100 Message-ID: <20230630152524.661208-9-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.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6F79BA0007 X-Stat-Signature: iphjq38i6dnq6q938frb3ktu6krhf19c X-Rspam-User: X-HE-Tag: 1688138759-502366 X-HE-Meta: U2FsdGVkX185I4461WhpuBpbc37a1b4S/VPHAAiOqjh47c//kz0/MGsvbXWGtBF5L2ArthC35sz21u/tmfzcq09g0gn8JuPEvP6tXibuqI3qL7mXxG2rOT08PHrTee++8Gh9uCYtw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CEJ7vP+FYW9kWebzo6uSFGB33Cq02J5kO+afa63cu5O+9BEASqvLhGOiKUk7SAiMrJs6Le8H6QV3be77o+L+obpc7VTGD10N12UfJiZjje1UJbkG+Q== 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: Drop the last usage of iov_iter_rw() into __iov_iter_get_pages_alloc(). 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 --- include/linux/uio.h | 5 ----- lib/iov_iter.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index ff81e5ccaef2..70e12f536f8f 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -136,11 +136,6 @@ static inline bool iov_iter_is_xarray(const struct iov_iter *i) return iov_iter_type(i) == ITER_XARRAY; } -static inline unsigned char iov_iter_rw(const struct iov_iter *i) -{ - return i->data_source ? WRITE : READ; -} - static inline bool user_backed_iter(const struct iov_iter *i) { return i->user_backed; diff --git a/lib/iov_iter.c b/lib/iov_iter.c index b667b1e2f688..b8c52231a6ff 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1097,7 +1097,7 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, unsigned long addr; int res; - if (iov_iter_rw(i) != WRITE) + if (i->data_source == ITER_SOURCE) gup_flags |= FOLL_WRITE; if (i->nofault) gup_flags |= FOLL_NOFAULT; From patchwork Fri Jun 30 15:25:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298360 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 E975CEB64DC for ; Fri, 30 Jun 2023 15:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8258B8E0026; Fri, 30 Jun 2023 11:26:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D5B38E000F; Fri, 30 Jun 2023 11:26:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 628188E0026; Fri, 30 Jun 2023 11:26:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4ADAB8E000F for ; Fri, 30 Jun 2023 11:26:04 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EBA47140E36 for ; Fri, 30 Jun 2023 15:26:03 +0000 (UTC) X-FDA: 80959789806.06.42C6E31 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id EF882180012 for ; Fri, 30 Jun 2023 15:26:00 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lr5JxFvR; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138761; 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=P3QvI++UbaCvzRYqDPfp6daxW4hAI54iCb+OZBSflyU=; b=C2sybzoEhSDoKpOLXTxvN56RDoSS/b0ZWPlFsxytXds5joC/Fl26LPhC9r1EH5PriAFvgH tgDqXBWiq1JJ6U/S/6cNiVSZRcgCCFNMgQ++LzbIe2PGboY0baW4J6Jiczk5j4hhcPWkXO MLqWSFFhScIMtDFHu041rURlFYgm8ww= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lr5JxFvR; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138761; a=rsa-sha256; cv=none; b=wtYjHkSnb12Lwg9mr3WW1XgPKLRGtbOZdhLYbKSw5X7LffKVSVKn1LzyGh8aS0WqObfQHL VNd12euG9FV677NXXKUz0CUwP1F5oIqgEWwXkb/X+BDnG0YJHX9BxS6vlnVJu/KFUGusIU BkM7nlYcWqu0oxjg7UDbfQD6EPiTpPQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138760; 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=P3QvI++UbaCvzRYqDPfp6daxW4hAI54iCb+OZBSflyU=; b=Lr5JxFvRLsowevKJXY5u2yoeAYGOPLjBgIAypB6P1rHGgU3Nu6Hx6cGFA7pfZBB9yS1h0A VyZQvTykwrx6AL4gJamQ31W4KsZE5a12YeQE9W+dPEcYGbMtvLYA7FzCErU5JwVIApl0hn hauKX1nunEnXPMLWdc1bubD5KGhuWwA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-lk4SxSCmM8ygJqJYozNQNg-1; Fri, 30 Jun 2023 11:25:56 -0400 X-MC-Unique: lk4SxSCmM8ygJqJYozNQNg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F085D3C0F39A; Fri, 30 Jun 2023 15:25:55 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9061D48FB01; Fri, 30 Jun 2023 15:25:52 +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 , Herbert Xu , linux-crypto@vger.kernel.org Subject: [RFC PATCH 09/11] iov_iter: Use I/O dir flags with iov_iter_extract_pages() Date: Fri, 30 Jun 2023 16:25:22 +0100 Message-ID: <20230630152524.661208-10-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.9 X-Rspamd-Queue-Id: EF882180012 X-Rspam-User: X-Stat-Signature: bk6moc5awcia3jcxq1654gb71rdx3nki X-Rspamd-Server: rspam01 X-HE-Tag: 1688138760-325254 X-HE-Meta: U2FsdGVkX19AdgDDMwtT07478eG0Ad1feBetHCjDFeN+rT5VmTU1tOZMOjsLSUk/gKty51RuM5aCk5znWN39/cGeZ1Bvr0YoN54pCur19jkOotms9+PrliwJpDn0butp8gVdqBfNY6sQkRSf9+zSfauw1AFxQqfk2ViJYQUzbAi4CD50lWBDkRuHEZ8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o0HYjWIvHPhk047WBb2iuYdaBWLIw+XIyCfikl1GIoqYyIExJ6kG0m+vMirxn8XO/o+rvqmfnYfp8O3IzzWiyZvcfCc66a89s2zfbNqbNab8efnYXsTXTg== 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: Define flags to pass into iov_iter_extract_pages() to indicate I/O direction. A warning is issued and the function fails if neither or both flags are set. The flag is also checked against the iterator's data_source flag. Also make extract_iter_to_sg() check the flags and propagate them to iov_iter_extract_pages(). Finally, make the callers pass the flags into iov_iter_extract_pages() and extract_iter_to_sg(). Signed-off-by: David Howells cc: Christoph Hellwig cc: Jens Axboe cc: Christian Brauner cc: Alexander Viro cc: Herbert Xu cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-crypto@vger.kernel.org --- block/bio.c | 6 ++++++ block/blk-map.c | 3 +++ crypto/af_alg.c | 5 +++-- crypto/algif_hash.c | 3 ++- fs/direct-io.c | 6 +++++- include/linux/bio.h | 18 ++++++++++++++++-- include/linux/uio.h | 5 ++++- lib/iov_iter.c | 12 ++++++++++-- lib/scatterlist.c | 12 ++++++++++-- 9 files changed, 59 insertions(+), 11 deletions(-) diff --git a/block/bio.c b/block/bio.c index 8672179213b9..440d4889ba13 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1242,6 +1242,8 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, * will have to be cleaned up in the way indicated by the BIO_PAGE_PINNED flag. * For a multi-segment *iter, this function only adds pages from the next * non-empty segment of the iov iterator. + * + * The I/O direction is determined from the bio operation type. */ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { @@ -1263,6 +1265,8 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) BUILD_BUG_ON(PAGE_PTRS_PER_BVEC < 2); pages += entries_left * (PAGE_PTRS_PER_BVEC - 1); + extraction_flags |= bio_is_write(bio) ? WRITE_FROM_ITER : READ_INTO_ITER; + if (bio->bi_bdev && blk_queue_pci_p2pdma(bio->bi_bdev->bd_disk->queue)) extraction_flags |= ITER_ALLOW_P2PDMA; @@ -1332,6 +1336,8 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * fit into the bio, or are requested in @iter, whatever is smaller. If * MM encounters an error pinning the requested pages, it stops. Error * is returned only if 0 pages could be pinned. + * + * The bio operation indicates the data direction. */ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { diff --git a/block/blk-map.c b/block/blk-map.c index f8fe114ae433..71de2cf9bf4e 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -279,6 +279,9 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (bio == NULL) return -ENOMEM; + extraction_flags |= + bio_is_write(bio) ? WRITE_FROM_ITER : READ_INTO_ITER; + if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; if (iov_iter_extract_will_pin(iter)) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 6218c773d71c..c62ac5e32aeb 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1042,7 +1042,8 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, }; plen = extract_iter_to_sg(&msg->msg_iter, len, &sgtable, - MAX_SGL_ENTS - sgl->cur, 0); + MAX_SGL_ENTS - sgl->cur, + WRITE_FROM_ITER); if (plen < 0) { err = plen; goto unlock; @@ -1247,7 +1248,7 @@ int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags, sg_init_table(rsgl->sgl.sgt.sgl, ALG_MAX_PAGES); err = extract_iter_to_sg(&msg->msg_iter, seglen, &rsgl->sgl.sgt, - ALG_MAX_PAGES, 0); + ALG_MAX_PAGES, READ_INTO_ITER); if (err < 0) { rsgl->sg_num_bytes = 0; return err; diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 0ab43e149f0e..b343c4973dbf 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c @@ -115,7 +115,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ctx->sgl.need_unpin = iov_iter_extract_will_pin(&msg->msg_iter); err = extract_iter_to_sg(&msg->msg_iter, LONG_MAX, - &ctx->sgl.sgt, npages, 0); + &ctx->sgl.sgt, npages, + WRITE_FROM_ITER); if (err < 0) goto unlock_free; len = err; diff --git a/fs/direct-io.c b/fs/direct-io.c index 2b517cc5b32d..3316d2f8f21c 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -168,10 +168,14 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) { struct page **pages = dio->pages; const enum req_op dio_op = dio->opf & REQ_OP_MASK; + unsigned int extraction_flags; ssize_t ret; + extraction_flags = + op_is_write(dio_op) ? WRITE_FROM_ITER : READ_INTO_ITER; + ret = iov_iter_extract_pages(sdio->iter, &pages, LONG_MAX, - DIO_PAGES, 0, &sdio->from); + DIO_PAGES, extraction_flags, &sdio->from); if (ret < 0 && sdio->blocks_available && dio_op == REQ_OP_WRITE) { /* diff --git a/include/linux/bio.h b/include/linux/bio.h index c4f5b5228105..d4b4c477e69b 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -42,11 +42,25 @@ static inline unsigned int bio_max_segs(unsigned int nr_segs) #define bio_sectors(bio) bvec_iter_sectors((bio)->bi_iter) #define bio_end_sector(bio) bvec_iter_end_sector((bio)->bi_iter) +/** + * bio_is_write - Query if the I/O direction is towards the disk + * @bio: The bio to query + * + * Return true if this is some sort of write operation - ie. the data is going + * towards the disk. + */ +static inline bool bio_is_write(const struct bio *bio) +{ + return op_is_write(bio_op(bio)); +} + /* * Return the data direction, READ or WRITE. */ -#define bio_data_dir(bio) \ - (op_is_write(bio_op(bio)) ? WRITE : READ) +static inline int bio_data_dir(const struct bio *bio) +{ + return bio_is_write(bio) ? WRITE : READ; +} /* * Check whether this bio carries any data or not. A NULL bio is allowed. diff --git a/include/linux/uio.h b/include/linux/uio.h index 70e12f536f8f..6ea7c1b589c1 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -379,8 +379,11 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, }; } /* Flags for iov_iter_get/extract_pages*() */ +/* Indicate if we are going to be writing from the buffer or reading into it. */ +#define WRITE_FROM_ITER ((__force iov_iter_extraction_t)0x01) // == WRITE +#define READ_INTO_ITER ((__force iov_iter_extraction_t)0x02) /* Allow P2PDMA on the extracted pages */ -#define ITER_ALLOW_P2PDMA ((__force iov_iter_extraction_t)0x01) +#define ITER_ALLOW_P2PDMA ((__force iov_iter_extraction_t)0x04) ssize_t iov_iter_extract_pages(struct iov_iter *i, struct page ***pages, size_t maxsize, unsigned int maxpages, diff --git a/lib/iov_iter.c b/lib/iov_iter.c index b8c52231a6ff..d31f40b69da5 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1791,8 +1791,10 @@ static ssize_t iov_iter_extract_user_pages(struct iov_iter *i, * that the caller allocated a page list at least @maxpages in size and this * will be filled in. * - * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA - * be allowed on the pages extracted. + * @extraction_flags should have either WRITE_FROM_ITER or READ_INTO_ITER to + * indicate the direction the data is intended to flow to/from the buffer and + * can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be allowed on the + * pages extracted. * * The iov_iter_extract_will_pin() function can be used to query how cleanup * should be performed. @@ -1823,6 +1825,12 @@ ssize_t iov_iter_extract_pages(struct iov_iter *i, iov_iter_extraction_t extraction_flags, size_t *offset0) { + unsigned int dir = extraction_flags & (READ_INTO_ITER | WRITE_FROM_ITER); + + if (WARN_ON_ONCE(dir != READ_INTO_ITER && dir != WRITE_FROM_ITER) || + WARN_ON_ONCE((dir & WRITE) != i->data_source)) + return -EFAULT; + maxsize = min_t(size_t, min_t(size_t, maxsize, i->count), MAX_RW_COUNT); if (!maxsize) return 0; diff --git a/lib/scatterlist.c b/lib/scatterlist.c index e97d7060329e..116ce320eb36 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -1326,8 +1326,10 @@ static ssize_t extract_xarray_to_sg(struct iov_iter *iter, * * No end mark is placed on the scatterlist; that's left to the caller. * - * @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA - * be allowed on the pages extracted. + * @extraction_flags should have either WRITE_FROM_ITER or READ_INTO_ITER to + * indicate the direction the data is intended to flow to/from the buffer and + * can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be allowed on the + * pages extracted. * * If successful, @sgtable->nents is updated to include the number of elements * added and the number of bytes added is returned. @sgtable->orig_nents is @@ -1340,6 +1342,12 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize, struct sg_table *sgtable, unsigned int sg_max, iov_iter_extraction_t extraction_flags) { + unsigned int dir = extraction_flags & (READ_INTO_ITER | WRITE_FROM_ITER); + + if (WARN_ON_ONCE(dir != READ_INTO_ITER && dir != WRITE_FROM_ITER) || + WARN_ON_ONCE((dir & WRITE) != iter->data_source)) + return -EFAULT; + if (maxsize == 0) return 0; From patchwork Fri Jun 30 15:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298361 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 0B974EB64DA for ; Fri, 30 Jun 2023 15:26:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D2D78E0027; Fri, 30 Jun 2023 11:26:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95BF88E000F; Fri, 30 Jun 2023 11:26:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 823A08E0027; Fri, 30 Jun 2023 11:26:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 719FE8E000F for ; Fri, 30 Jun 2023 11:26:08 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 42D8780558 for ; Fri, 30 Jun 2023 15:26:08 +0000 (UTC) X-FDA: 80959790016.07.090FD71 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 2B98540023 for ; Fri, 30 Jun 2023 15:26:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HkfgA793; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1688138766; 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=YvuuosyDox1jyrnioRFOxuFzcr1YzhZJrvdziq8YYeo=; b=VL5ynegdshpEvPIQt6UIHpF7I5L/Aa8W2/f3NNF/VW7EwbK+89Rc9skjpEdpx2g0hE3tI1 nUfcIMv0dwJfYF/iXdZtIkc6s7HWmK1ZzG7JyBOthZ+qUROUfLbLxIn8l8Y0vo4qjfNzQ0 zocxJOX/u6NqGmQo5/Xh4qE9W7vRnps= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HkfgA793; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138766; a=rsa-sha256; cv=none; b=pAsPuQqBplM8ROvDX9YTxorA2OU9x0oC7Z5HLNeiijgXslqWjYF66A5csbAgjJSXEyxOff YpVBQrF6Yycl17mLtVX9YURub5wxa15WN56EdaugDDl/1qnrdNajFcH6BQ6zMYzEKXQmKz YxipWVUVftUmHkbWkMkoCoaau/C3oBQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138765; 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=YvuuosyDox1jyrnioRFOxuFzcr1YzhZJrvdziq8YYeo=; b=HkfgA793iVSrB64AlEspG6dR5iY+ruW4MUn09hU+poc8Jc2hy1QrZVZvRoZVd/jFZO1yOP hTW1H0NEeWBXfFVQH6gZ4JagFGtw6CwBza/ypnfsIoZGYhS72USbN9UaD8pUdyNHAhLHro kdch2yzBOCe18NM3tBEvkZH46QHCI6o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-n-OmuebeNTmap1grquelDQ-1; Fri, 30 Jun 2023 11:26:00 -0400 X-MC-Unique: n-OmuebeNTmap1grquelDQ-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 5340229AA2CC; Fri, 30 Jun 2023 15:25:59 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7DBB14682FA; Fri, 30 Jun 2023 15:25:56 +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, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Christian Schoenebeck , v9fs-developer@lists.sourceforge.net Subject: [RFC PATCH 10/11] 9p: Pin pages rather than ref'ing if appropriate Date: Fri, 30 Jun 2023 16:25:23 +0100 Message-ID: <20230630152524.661208-11-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-Stat-Signature: z745jxw5jw6ooqmpyzwzm64ybgkarz5j X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2B98540023 X-HE-Tag: 1688138765-139493 X-HE-Meta: U2FsdGVkX1/i53wjMk4sBQnxaYiYzZg13PIFDvc7nBjPNECHnWIfmVQKyqRHOni0fp4qFg6IGobjtz8ME5AYnbkbG4z+03fSc+Kr/e8qEXzgHLq+oH6FvK6RkQnjjqac0odbXUoxg5027mfL9vJRBhSFUKjIRzVx7gagxbGh6iY7+NbJx+WS+19RKmyGZkbL5FTgX2U9aBH0e81+bKNQ5K8V/2qfeFPvWc8nbLp6r/Zrq2Cbjk3LUINVCX4QGZIOUSUZuSopIDfmjEm+CB/yJwEugEOxTucqRLgTib/8/6FaA/EdcPezUttuUny3GDzHPfiUbbpnkrxLGYZKapdPZHWWijGEzlI9HQp/7/rV1YKujHncDrpp7T2nWx5H2p9LN2u5Btj+AKZxHQ2QvYlwOxA/srUy85R9kv8gNoymJx8gpU2B6yDPHLUvLyz4XbkYxXB/sH1WmiuYsCmonb6QRST90m7yvL5m+jgO3ZsFgspAq1lsGMLRNe33BcNwbUkb5bev6h1X8+FOjy8SR4uqT2GFvC0+RtEZyJS6vlFZ7YHiR0BIm5wbTMVMY8H0cM6HTlDs+qLsRL0XwhC9LXGHHgDuhov+EGbMR8UtkDEz75Esi/YdK6ZC9y3YNIjKPugFV8IihP6hcG48mVmOzepmH0p/bWuZWUAoHC49APkZEEccvtJkTHtgXNFB/myO6IgKYBlAIU6RJFABk9cOfOKR1psUVv859eUK/lLvHYBJz73EeF8AesR21QTUkI0gOHrtJIBvEXdckPbF6FV3jZh+kq/5KU6hE+mZ2/hour1/euO9WGA331JXvRuRnY/ObLGaqv0iTmW/VEq+ju1LOOiOHXjUND1VaP1DXiN0/R9ogPSOeRMBMxMFbLMPvzUmyOZ6XsM8e7tNbmDRR/HuTKvMPP4l1t9wwtiPP2/skAYj0MRlqmP4djqeuVIhIX8M6Z3xIKqQRdIYT4H+BJsjAL1 zBpgJ0+P bzJjImO1m8nDGAUP7lrVkPzlfo2AgSEjFR91aCAEbyobkniOsxy35SMS/Q2+XyRrpFhCfM/oILFshb7MuzKinhw+/smD58D14yhmw+GmqISjKCqSzU4aKtTN1JI+PE2jioMtyj8krYAmFx/Rn0ICt25hfNErRsf+G9bV3Pb3SJCtkAxkQ3XYiaIcEvMfv3ODnklNAtOKCXXcHjscPWUYhS423N0HrcDSg3f+S86WSVuI75ckaIoH5e7zjIQvmoCfnB8ZqwZGpS/bxYQvhzY8Jn0FY4QVVzl+KbMjZp3ZiGdTQXDHL3ukW88BytFSCehnrBTA4YEhkmibUdnbU3tudBxT12C3+ZanWAaO0cjP5bA/xcG6xNz/7sPUL5kYlwMJfdyloGBZCx2UZOY5lmkOwDQJGzOQegO/bjxiY4GcbmpFOfk0= 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: Convert the 9p filesystem to use iov_iter_extract_pages() instead of iov_iter_get_pages(). This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO-read rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O would otherwise end up only visible to the child process and not the parent). Signed-off-by: David Howells cc: Dominique Martinet cc: Eric Van Hensbergen cc: Latchesar Ionkov cc: Christian Schoenebeck cc: v9fs-developer@lists.sourceforge.net --- net/9p/trans_common.c | 8 ++-- net/9p/trans_common.h | 2 +- net/9p/trans_virtio.c | 92 ++++++++++++++----------------------------- 3 files changed, 34 insertions(+), 68 deletions(-) diff --git a/net/9p/trans_common.c b/net/9p/trans_common.c index c827f694551c..4342de18f08b 100644 --- a/net/9p/trans_common.c +++ b/net/9p/trans_common.c @@ -9,16 +9,16 @@ #include "trans_common.h" /** - * p9_release_pages - Release pages after the transaction. + * p9_unpin_pages - Unpin pages after the transaction. * @pages: array of pages to be put * @nr_pages: size of array */ -void p9_release_pages(struct page **pages, int nr_pages) +void p9_unpin_pages(struct page **pages, int nr_pages) { int i; for (i = 0; i < nr_pages; i++) if (pages[i]) - put_page(pages[i]); + unpin_user_page(pages[i]); } -EXPORT_SYMBOL(p9_release_pages); +EXPORT_SYMBOL(p9_unpin_pages); diff --git a/net/9p/trans_common.h b/net/9p/trans_common.h index 32134db6abf3..fd94c48aba5b 100644 --- a/net/9p/trans_common.h +++ b/net/9p/trans_common.h @@ -4,4 +4,4 @@ * Author Venkateswararao Jujjuri */ -void p9_release_pages(struct page **pages, int nr_pages); +void p9_unpin_pages(struct page **pages, int nr_pages); diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 3c27ffb781e3..93569de2bdba 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -310,71 +310,35 @@ static int p9_get_mapped_pages(struct virtio_chan *chan, struct iov_iter *data, int count, size_t *offs, - int *need_drop) + bool *need_unpin, + iov_iter_extraction_t extraction_flags) { int nr_pages; int err; + int n; if (!iov_iter_count(data)) return 0; - if (!iov_iter_is_kvec(data)) { - int n; - /* - * We allow only p9_max_pages pinned. We wait for the - * Other zc request to finish here - */ - if (atomic_read(&vp_pinned) >= chan->p9_max_pages) { - err = wait_event_killable(vp_wq, - (atomic_read(&vp_pinned) < chan->p9_max_pages)); - if (err == -ERESTARTSYS) - return err; - } - n = iov_iter_get_pages_alloc2(data, pages, count, offs); - if (n < 0) - return n; - *need_drop = 1; - nr_pages = DIV_ROUND_UP(n + *offs, PAGE_SIZE); - atomic_add(nr_pages, &vp_pinned); - return n; - } else { - /* kernel buffer, no need to pin pages */ - int index; - size_t len; - void *p; - - /* we'd already checked that it's non-empty */ - while (1) { - len = iov_iter_single_seg_count(data); - if (likely(len)) { - p = data->kvec->iov_base + data->iov_offset; - break; - } - iov_iter_advance(data, 0); - } - if (len > count) - len = count; - - nr_pages = DIV_ROUND_UP((unsigned long)p + len, PAGE_SIZE) - - (unsigned long)p / PAGE_SIZE; - - *pages = kmalloc_array(nr_pages, sizeof(struct page *), - GFP_NOFS); - if (!*pages) - return -ENOMEM; - - *need_drop = 0; - p -= (*offs = offset_in_page(p)); - for (index = 0; index < nr_pages; index++) { - if (is_vmalloc_addr(p)) - (*pages)[index] = vmalloc_to_page(p); - else - (*pages)[index] = kmap_to_page(p); - p += PAGE_SIZE; - } - iov_iter_advance(data, len); - return len; + /* + * We allow only p9_max_pages pinned. We wait for the + * Other zc request to finish here + */ + if (atomic_read(&vp_pinned) >= chan->p9_max_pages) { + err = wait_event_killable(vp_wq, + (atomic_read(&vp_pinned) < chan->p9_max_pages)); + if (err == -ERESTARTSYS) + return err; } + + n = iov_iter_extract_pages(data, pages, count, INT_MAX, + extraction_flags, offs); + if (n < 0) + return n; + *need_unpin = iov_iter_extract_will_pin(data); + nr_pages = DIV_ROUND_UP(n + *offs, PAGE_SIZE); + atomic_add(nr_pages, &vp_pinned); + return n; } static void handle_rerror(struct p9_req_t *req, int in_hdr_len, @@ -429,7 +393,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, struct virtio_chan *chan = client->trans; struct scatterlist *sgs[4]; size_t offs; - int need_drop = 0; + bool need_unpin; int kicked = 0; p9_debug(P9_DEBUG_TRANS, "virtio request\n"); @@ -437,7 +401,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, if (uodata) { __le32 sz; int n = p9_get_mapped_pages(chan, &out_pages, uodata, - outlen, &offs, &need_drop); + outlen, &offs, &need_unpin, + WRITE_FROM_ITER); if (n < 0) { err = n; goto err_out; @@ -456,7 +421,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, memcpy(&req->tc.sdata[0], &sz, sizeof(sz)); } else if (uidata) { int n = p9_get_mapped_pages(chan, &in_pages, uidata, - inlen, &offs, &need_drop); + inlen, &offs, &need_unpin, + READ_INTO_ITER); if (n < 0) { err = n; goto err_out; @@ -542,13 +508,13 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, * Non kernel buffers are pinned, unpin them */ err_out: - if (need_drop) { + if (need_unpin) { if (in_pages) { - p9_release_pages(in_pages, in_nr_pages); + p9_unpin_pages(in_pages, in_nr_pages); atomic_sub(in_nr_pages, &vp_pinned); } if (out_pages) { - p9_release_pages(out_pages, out_nr_pages); + p9_unpin_pages(out_pages, out_nr_pages); atomic_sub(out_nr_pages, &vp_pinned); } /* wakeup anybody waiting for slots to pin pages */ From patchwork Fri Jun 30 15:25:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13298362 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 D478AEB64D7 for ; Fri, 30 Jun 2023 15:26:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C5168E0028; Fri, 30 Jun 2023 11:26:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6754E8E000F; Fri, 30 Jun 2023 11:26:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 517238E0028; Fri, 30 Jun 2023 11:26:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3EF9E8E000F for ; Fri, 30 Jun 2023 11:26:11 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 147B1B0A56 for ; Fri, 30 Jun 2023 15:26:11 +0000 (UTC) X-FDA: 80959790142.26.9635A23 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 370DE20009 for ; Fri, 30 Jun 2023 15:26:09 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CNw32d7J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1688138769; 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=dTUg/mVQyhhJfywizixeKkySOuaXp8UTsLqq+KCOGUE=; b=0G9TG/m1mdScxRedyEr3EHw5zqjBjINKeWpO1q0gBnjzay/Ka1bbAGOPFaODj6nQgkcuxj 4iZYmuWrCm65ZCH6ZtS5xugfipe/zKN7mlBRPUeVRDEP8QSnIPPaKXyXtUQK62jahrH9kY v1ilICpFM0Y2i1R+5JXKh9PngrHhFaU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CNw32d7J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138769; a=rsa-sha256; cv=none; b=nXuXzjWkIrszJxp3yqw5WA0TxtpcsqwpF+TuWAfSy9v99vnhGEh3roMvBmzC+cZj+R976K s5gWnjc2aDVIMVbNJmWJTXQBoP07hdEFb/QRNdubgRntPxXTfex31BQcPBgRwkCsjv5nHx KdNX178v92mxQZP59okFwiVuJXXkBJU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138768; 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=dTUg/mVQyhhJfywizixeKkySOuaXp8UTsLqq+KCOGUE=; b=CNw32d7JAW6urqSl6UNmJoV0SXENeHbPY610lJJ7dpjueERs8jubMeUuX7H9pd32rGHkAa Yy7o+hd6uW9tcyT/XNnxrj2gNADY/0wC05AJBUQka0fFK41bbyBslplGgRt3DE0U6sJsO3 zcE/pXuTWJwwe9SrWIi08W4eTWWm2z0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-342-ykgDuP25MHy7G1d5_4sdcQ-1; Fri, 30 Jun 2023 11:26:03 -0400 X-MC-Unique: ykgDuP25MHy7G1d5_4sdcQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 21B6D1C0512E; Fri, 30 Jun 2023 15:26:02 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF05540C6CCD; Fri, 30 Jun 2023 15:25:59 +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, "James E . J . Bottomley" , "Martin K . Petersen" , Christoph Hellwig , linux-scsi@vger.kernel.org Subject: [RFC PATCH 11/11] scsi: Use extract_iter_to_sg() Date: Fri, 30 Jun 2023 16:25:24 +0100 Message-ID: <20230630152524.661208-12-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.2 X-Rspamd-Queue-Id: 370DE20009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 8tgoo96o31hrqn869xzbxdk956a9ahru X-HE-Tag: 1688138769-238931 X-HE-Meta: U2FsdGVkX18q0ErS/8yXQaOXFnxlu8QZGquGMI7nbOo6yQpQtybNIHb04AQLD2BRzbQEboI9oHFjuRMqzF6DXqzsWy0jI/5Me6CogvOvtDcoFScB1XX6P/K8tp3yMf4bj5sXb2tzzPQVVLzaadM7Af35n5jHHwC4r0BFula1xgHPYAYXHrqzIblhPPY25BhQr05SofL/CJBIIbArf4gCBQZunS/FGiGuS5HMnezTN9fd/yxHKooQr/4tX6E+OoxKm3ic9ByDOAIiPNSqk4IyLncSm1UOYq+5kZAk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sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use extract_iter_to_sg() to build a scatterlist from an iterator. Signed-off-by: David Howells cc: James E.J. Bottomley cc: Martin K. Petersen cc: Christoph Hellwig cc: linux-scsi@vger.kernel.org --- drivers/vhost/scsi.c | 79 +++++++++++++------------------------------- 1 file changed, 23 insertions(+), 56 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index bb10fa4bb4f6..7bb41e2a0d64 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -75,6 +75,9 @@ struct vhost_scsi_cmd { u32 tvc_prot_sgl_count; /* Saved unpacked SCSI LUN for vhost_scsi_target_queue_cmd() */ u32 tvc_lun; + /* Cleanup modes for scatterlists */ + unsigned int tvc_need_unpin; + unsigned int tvc_prot_need_unpin; /* Pointer to the SGL formatted memory from virtio-scsi */ struct scatterlist *tvc_sgl; struct scatterlist *tvc_prot_sgl; @@ -327,14 +330,13 @@ static void vhost_scsi_release_cmd_res(struct se_cmd *se_cmd) struct vhost_scsi_inflight *inflight = tv_cmd->inflight; int i; - if (tv_cmd->tvc_sgl_count) { + if (tv_cmd->tvc_need_unpin && tv_cmd->tvc_sgl_count) for (i = 0; i < tv_cmd->tvc_sgl_count; i++) - put_page(sg_page(&tv_cmd->tvc_sgl[i])); - } - if (tv_cmd->tvc_prot_sgl_count) { + unpin_user_page(sg_page(&tv_cmd->tvc_sgl[i])); + + if (tv_cmd->tvc_prot_need_unpin && tv_cmd->tvc_prot_sgl_count) for (i = 0; i < tv_cmd->tvc_prot_sgl_count; i++) - put_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); - } + unpin_user_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); sbitmap_clear_bit(&svq->scsi_tags, se_cmd->map_tag); vhost_scsi_put_inflight(inflight); @@ -606,38 +608,6 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg, return cmd; } -/* - * Map a user memory range into a scatterlist - * - * Returns the number of scatterlist entries used or -errno on error. - */ -static int -vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, - struct iov_iter *iter, - struct scatterlist *sgl, - bool write) -{ - struct page **pages = cmd->tvc_upages; - struct scatterlist *sg = sgl; - ssize_t bytes; - size_t offset; - unsigned int npages = 0; - - bytes = iov_iter_get_pages2(iter, pages, LONG_MAX, - VHOST_SCSI_PREALLOC_UPAGES, &offset); - /* No pages were pinned */ - if (bytes <= 0) - return bytes < 0 ? bytes : -EFAULT; - - while (bytes) { - unsigned n = min_t(unsigned, PAGE_SIZE - offset, bytes); - sg_set_page(sg++, pages[npages++], n, offset); - bytes -= n; - offset = 0; - } - return npages; -} - static int vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls) { @@ -661,24 +631,19 @@ vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls) static int vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write, struct iov_iter *iter, - struct scatterlist *sg, int sg_count) + struct scatterlist *sg, int sg_count, + unsigned int *need_unpin) { - struct scatterlist *p = sg; - int ret; + struct sg_table sgt = { .sgl = sg }; + ssize_t ret; - while (iov_iter_count(iter)) { - ret = vhost_scsi_map_to_sgl(cmd, iter, sg, write); - if (ret < 0) { - while (p < sg) { - struct page *page = sg_page(p++); - if (page) - put_page(page); - } - return ret; - } - sg += ret; - } - return 0; + ret = extract_iter_to_sg(iter, LONG_MAX, &sgt, sg_count, + write ? WRITE_FROM_ITER : READ_INTO_ITER); + if (ret > 0) + sg_mark_end(sg + sgt.nents - 1); + + *need_unpin = iov_iter_extract_will_pin(iter); + return ret; } static int @@ -702,7 +667,8 @@ vhost_scsi_mapal(struct vhost_scsi_cmd *cmd, ret = vhost_scsi_iov_to_sgl(cmd, write, prot_iter, cmd->tvc_prot_sgl, - cmd->tvc_prot_sgl_count); + cmd->tvc_prot_sgl_count, + &cmd->tvc_prot_need_unpin); if (ret < 0) { cmd->tvc_prot_sgl_count = 0; return ret; @@ -719,7 +685,8 @@ vhost_scsi_mapal(struct vhost_scsi_cmd *cmd, cmd->tvc_sgl, cmd->tvc_sgl_count); ret = vhost_scsi_iov_to_sgl(cmd, write, data_iter, - cmd->tvc_sgl, cmd->tvc_sgl_count); + cmd->tvc_sgl, cmd->tvc_sgl_count, + &cmd->tvc_need_unpin); if (ret < 0) { cmd->tvc_sgl_count = 0; return ret;