From patchwork Wed Mar 15 16:35:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176333 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 88125C61DA4 for ; Wed, 15 Mar 2023 16:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CA466B0075; Wed, 15 Mar 2023 12:36:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17AF56B0078; Wed, 15 Mar 2023 12:36:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01B986B007B; Wed, 15 Mar 2023 12:36:04 -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 E5D9E6B0075 for ; Wed, 15 Mar 2023 12:36:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A953DAB8B6 for ; Wed, 15 Mar 2023 16:36:04 +0000 (UTC) X-FDA: 80571684648.19.E92BE6F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 4D95914000F for ; Wed, 15 Mar 2023 16:36:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HSUrVCYu; spf=pass (imf26.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=1678898162; a=rsa-sha256; cv=none; b=esDLIYnwLH5mCmeONi3zILW5iHn39Ri3k5ITBT5rNqEIXKQ3U00JsyRs9yyNoXCpctPaWc y0CW7iFo5Y4+t+X0zO6b8o/1mpGtPBkOobMmyOdYrRt2VarsB61d1VleT/TiVcJgurL8ZB 8TLN7nl5q9zgAWt0dS08GOw8sfXGGFo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HSUrVCYu; spf=pass (imf26.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=1678898162; 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=fEHZtUBR4B7sSEpj4V24Co6bhAobBEWGUt1eQB77Iqg=; b=VJzWDb/n/pMjELeQcZdjZNoFG9mKWRVEo4/2zQqbBeSsgMegNvbI6EG2qRrLjGtWZ2jJ4R d6pwe9dsqWD48odCh2VCHfLnHZq72YSfIcpHsyd/hJgBctTpJ6oBXcpsfiFP8bLq3YVAz2 7Mm+tu3UME6h/jaQS6wEhzf6/fjkPwQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898161; 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=fEHZtUBR4B7sSEpj4V24Co6bhAobBEWGUt1eQB77Iqg=; b=HSUrVCYuVWzQ94ISqK4yiL55PIFlorse0niiDDscGX50Rh43co4F+XEsMWTzio9KUdSAfk ZeUkFLHjYFybeSXTJqOJagqP/h59VlDVs5W2mfY1/Lo5fjbi1RqWgADUJjzxuowu8sGw2q tI5oeHmBeb5e+AU9gMiXXsGcxqwS+cY= 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-202-Kzhf41MDNSGA4ALqB2MQAQ-1; Wed, 15 Mar 2023 12:35:57 -0400 X-MC-Unique: Kzhf41MDNSGA4ALqB2MQAQ-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 E32C2857F81; Wed, 15 Mar 2023 16:35:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C33412166B26; Wed, 15 Mar 2023 16:35:53 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 01/15] splice: Clean up direct_splice_read() a bit Date: Wed, 15 Mar 2023 16:35:35 +0000 Message-Id: <20230315163549.295454-2-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Queue-Id: 4D95914000F X-Rspamd-Server: rspam01 X-Stat-Signature: dst7dw4ku9m3zwbej345tmdp3g61o1og X-HE-Tag: 1678898162-269358 X-HE-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5iT9WR4xVdQ4BxdGGuJ5EiqsBsx+e5hVok3fnQIpObP5TH6YAQRRBgbTMwdZszP6wwm7+a/n2SMqXr7h2dvmDK8fJkJyK1sZPHt+ycs1OpHV+BbYwj0kUTOEkLdRDYHC1incCk6XTDwUSWIli7tPwH52lffhBkpMV3Vlic+v5zCn5zCfQDfg5p5F/sUX3XLShkjb4G2YEw3+e1uiIJE0xBB5E3O2iWltRIYE9HEUFkZlKRePr/C8GbDQgJC5qaslVr8JoksfYh6pSObjrWVgzeXAhzph5ahT3ex8SN79selCcnRl7S5GZN5C+KlHxOuqMQ1c6+6f3piql09Ha+LUBIqwoGlLLbTRhKB1XT4C+BZ+AhaOy4SPBVddN5kJmDiHuma/qX275lSpVkbi2CPEXHMzMugTMODhP83qETpV7w== 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: Do a couple of cleanups to direct_splice_read(): (1) Cast to struct page **, not void *. (2) Simplify the calculation of the number of pages to keep/reclaim in direct_splice_read(). Suggested-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: David Hildenbrand --- fs/splice.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 2e76dbb81a8f..abd21a455a2b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -295,7 +295,7 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos, struct kiocb kiocb; struct page **pages; ssize_t ret; - size_t used, npages, chunk, remain, reclaim; + size_t used, npages, chunk, remain, keep = 0; int i; /* Work out how much data we can actually add into the pipe */ @@ -309,7 +309,7 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos, if (!bv) return -ENOMEM; - pages = (void *)(bv + npages); + pages = (struct page **)(bv + npages); npages = alloc_pages_bulk_array(GFP_USER, npages, pages); if (!npages) { kfree(bv); @@ -332,11 +332,8 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos, kiocb.ki_pos = *ppos; ret = call_read_iter(in, &kiocb, &to); - reclaim = npages * PAGE_SIZE; - remain = 0; if (ret > 0) { - reclaim -= ret; - remain = ret; + keep = DIV_ROUND_UP(ret, PAGE_SIZE); *ppos = kiocb.ki_pos; file_accessed(in); } else if (ret < 0) { @@ -349,14 +346,12 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos, } /* Free any pages that didn't get touched at all. */ - reclaim /= PAGE_SIZE; - if (reclaim) { - npages -= reclaim; - release_pages(pages + npages, reclaim); - } + if (keep < npages) + release_pages(pages + keep, npages - keep); /* Push the remaining pages into the pipe. */ - for (i = 0; i < npages; i++) { + remain = ret; + for (i = 0; i < keep; i++) { struct pipe_buffer *buf = pipe_head_buf(pipe); chunk = min_t(size_t, remain, PAGE_SIZE); From patchwork Wed Mar 15 16:35:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176334 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 34DA8C6FD1D for ; Wed, 15 Mar 2023 16:36:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEE0E6B0078; Wed, 15 Mar 2023 12:36:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9EF56B007B; Wed, 15 Mar 2023 12:36:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B40EA6B007D; Wed, 15 Mar 2023 12:36:10 -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 A573C6B0078 for ; Wed, 15 Mar 2023 12:36:10 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6CF6F12085C for ; Wed, 15 Mar 2023 16:36:10 +0000 (UTC) X-FDA: 80571684900.04.7007534 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 9FB5FC000F for ; Wed, 15 Mar 2023 16:36:08 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UsJA5sxL; spf=pass (imf22.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=1678898168; 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=UYOaJrv+k3qRHTtCyS3jh/xO0Z1XCGBD7xHPEpqnnTw=; b=GuYhP/Kbh8wcwyymS2GoucZpHUJ/40KEgpdu1YLS5k1IIC4JbsBxDga7siyexMZHG0UD8u H6yB9CuxT6Gx4NqjuuzYzcrUmLHU5xuRnrsLR6MeCsNXj23JX/82D2Q98tbaocvYRwOkA/ 0U75HWWSKKCLrSh4Q7azvkCU9+1tDpA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UsJA5sxL; spf=pass (imf22.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=1678898168; a=rsa-sha256; cv=none; b=39HXrfw3R+KUuTR3uBkdBjTgIsFHqtpOuk2IVrw+domcXycJ4NlWlJHueED7XFVTYwA4PD KLsJ4WQL1KMdGkRAJEFrqU+UOko517mNdkuQeAPgVKK3vCVDYTFJokWOnT/aF/0mSDlGdO 4HvXhjfOVVDQPYi28PKYpSJvknapTps= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898167; 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=UYOaJrv+k3qRHTtCyS3jh/xO0Z1XCGBD7xHPEpqnnTw=; b=UsJA5sxLYzxWwZSz+4/jCzBhCDS+T0/S1ObJ3n5d1J+135GHMf2aUJE8wPtutUefukkzN7 cvsyqWY6iQsTNKtlYliFfA/X8NJwdJCtKdOt/vnXogMT1TNV5+XyfF/9flHY2pDBtnaocq hDaK6BjOBY7ZYKRD3KncrfMPUPVzdUs= 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-610-HjThJPlUMZe-gype1NTd7Q-1; Wed, 15 Mar 2023 12:36:04 -0400 X-MC-Unique: HjThJPlUMZe-gype1NTd7Q-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 E0D933C6675C; Wed, 15 Mar 2023 16:35:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95B66C164E7; Wed, 15 Mar 2023 16:35: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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Miklos Szeredi , John Hubbard , linux-unionfs@vger.kernel.org Subject: [PATCH v19 02/15] splice: Make do_splice_to() generic and export it Date: Wed, 15 Mar 2023 16:35:36 +0000 Message-Id: <20230315163549.295454-3-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9FB5FC000F X-Stat-Signature: 5tskkfgop7o91rqye5sobjipr8878uyj X-Rspam-User: X-HE-Tag: 1678898168-84336 X-HE-Meta: U2FsdGVkX1/rv82lERLW37fJzZR39RCfyUckXwKn7UFtPoS3sty1paI5ClKkbbAqiPdpBaYCnLho1v6Ipq4UZmgdWFhjuCCAmeiJ0YY9+Wypy78cIcbFzi7xj3V9HJFULSajzOKIC9Dx7TFez+rQFeFR6WZBpV6wlqu7eJ4GUwj+XY0JKAJW9kaQDsWY/yRWShH3QfQ20kjXB35wr2qQzL3R+afyOtnks+wRUB3Rrb+BNsKS7CtrbPEhxfMQJebcT7rsw+AV22ehKTobWUMFAxLj2FEVWcYiC/5aSXLpkrKl978MmWTWu49l46xqJ/SxCy1X8wCy+tWuDOgt0FBn1Vqh+xW1f7vgKvCBMUTuhwiz77iqCT5gcLmOfgkBK+K+fSXTJZt4XUOrtNsVgGUufqbOITxXjeeF95nmy9kZ7Y94DsZeLBqHOCRVFvVdhAWjYkZt472Ua5WDVEpvdBAClm/VUYhGnC+s+xrVEtKk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ender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rename do_splice_to() to vfs_splice_read() and export it so that it can be used as a helper when calling down to a lower layer filesystem as it performs all the necessary checks[1]. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Miklos Szeredi cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/CAJfpeguGksS3sCigmRi9hJdUec8qtM9f+_9jC1rJhsXT+dV01w@mail.gmail.com/ [1] Reviewed-by: David Hildenbrand --- fs/splice.c | 27 ++++++++++++++++++++------- include/linux/splice.h | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index abd21a455a2b..90ccd3666dca 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -851,12 +851,24 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, return out->f_op->splice_write(pipe, out, ppos, len, flags); } -/* - * Attempt to initiate a splice from a file to a pipe. +/** + * vfs_splice_read - Read data from a file and splice it into a pipe + * @in: File to splice from + * @ppos: Input file offset + * @pipe: Pipe to splice to + * @len: Number of bytes to splice + * @flags: Splice modifier flags (SPLICE_F_*) + * + * Splice the requested amount of data from the input file to the pipe. This + * is synchronous as the caller must hold the pipe lock across the entire + * operation. + * + * If successful, it returns the amount of data spliced, 0 if it hit the EOF or + * a hole and a negative error code otherwise. */ -static long do_splice_to(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) +long vfs_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) { unsigned int p_space; int ret; @@ -879,6 +891,7 @@ static long do_splice_to(struct file *in, loff_t *ppos, return warn_unsupported(in, "read"); return in->f_op->splice_read(in, ppos, pipe, len, flags); } +EXPORT_SYMBOL_GPL(vfs_splice_read); /** * splice_direct_to_actor - splices data directly between two non-pipes @@ -949,7 +962,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, size_t read_len; loff_t pos = sd->pos, prev_pos = pos; - ret = do_splice_to(in, &pos, pipe, len, flags); + ret = vfs_splice_read(in, &pos, pipe, len, flags); if (unlikely(ret <= 0)) goto out_release; @@ -1097,7 +1110,7 @@ long splice_file_to_pipe(struct file *in, pipe_lock(opipe); ret = wait_for_space(opipe, flags); if (!ret) - ret = do_splice_to(in, offset, opipe, len, flags); + ret = vfs_splice_read(in, offset, opipe, len, flags); pipe_unlock(opipe); if (ret > 0) wakeup_pipe_readers(opipe); diff --git a/include/linux/splice.h b/include/linux/splice.h index a55179fd60fc..8f052c3dae95 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -76,6 +76,9 @@ extern ssize_t splice_to_pipe(struct pipe_inode_info *, struct splice_pipe_desc *); extern ssize_t add_to_pipe(struct pipe_inode_info *, struct pipe_buffer *); +long vfs_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags); extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, splice_direct_actor *); extern long do_splice(struct file *in, loff_t *off_in, From patchwork Wed Mar 15 16:35:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176335 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 485A0C61DA4 for ; Wed, 15 Mar 2023 16:36:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3CD16B007D; Wed, 15 Mar 2023 12:36:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEC9E6B007E; Wed, 15 Mar 2023 12:36:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B66826B0080; Wed, 15 Mar 2023 12:36:12 -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 A5C856B007D for ; Wed, 15 Mar 2023 12:36:12 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7C963C014F for ; Wed, 15 Mar 2023 16:36:12 +0000 (UTC) X-FDA: 80571684984.16.3FF985F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id B4D1380021 for ; Wed, 15 Mar 2023 16:36:09 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hDdlS7x0; spf=pass (imf30.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=1678898169; 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=imlbxN8+e/h/7fdYpvOZBQo8e/sPfLa+LUB+/4kjN58=; b=qUfHIeJrD2DSr8hndnFG+M96sDN+GFyr7+y6lhAQlcunDbVN6J5aOUBY5TOWrNVAe2CUl1 lpsU+N+sS1b+bUiClRaNP8ZJNalhHddnS8a3h7SLwSYMlRGChelSuel2MDWcbT2xJEE9gt OZitAv4H2/48aJD37EVoPl1IpUlLKTY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hDdlS7x0; spf=pass (imf30.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=1678898169; a=rsa-sha256; cv=none; b=eTMRIM9P48EeeEBk0/8KZD91CH9kILgbfmOm2pBgmBmtZYHb3d4B5PcmCXK0FH7o6YGO3v LKXREhe8rZ+LKLlEASA52KNqGFNAyR9Jxb6oQ4cxFrEbMdJiB0a/serua5RBZKJ/dJKhTf VehP2+wJOPONQ+N1CAUemx6IcG8MS4A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898169; 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=imlbxN8+e/h/7fdYpvOZBQo8e/sPfLa+LUB+/4kjN58=; b=hDdlS7x0Kx7k9bTPLPOWdC6ADdKBuox3fHHmDLawq2HdACBj4gwu1SqQlA7eGYy0WJhWsL U588eiSoRgFX/k8WDCGkCxRiIVEqSMTu3QU3pyLEdfbOs43puz6oZxkZ59h1GRvJhMXOaA hypMvdrozCJ+OuU97IAaq1A30mXubXA= 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-296-Ki0JtdioOVChXpS3qKCPXQ-1; Wed, 15 Mar 2023 12:36:06 -0400 X-MC-Unique: Ki0JtdioOVChXpS3qKCPXQ-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 2BDF888B7A0; Wed, 15 Mar 2023 16:36:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DE122166B26; Wed, 15 Mar 2023 16:35: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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Daniel Golle , Guenter Roeck , Christoph Hellwig , John Hubbard , Hugh Dickins Subject: [PATCH v19 03/15] shmem: Implement splice-read Date: Wed, 15 Mar 2023 16:35:37 +0000 Message-Id: <20230315163549.295454-4-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Stat-Signature: rw5krwkgey4ey16f18u535iiieg1gp6s X-Rspam-User: X-Rspamd-Queue-Id: B4D1380021 X-Rspamd-Server: rspam06 X-HE-Tag: 1678898169-52830 X-HE-Meta: U2FsdGVkX190Pc8Wy9vxlKbbsTLqjpNIMfg5KGeSQEKTc1A91WcV+Log8zkR4kBTfmYNYDgZP7AOkKfIvgSHFDSCvekh6eSUA1/R05mh69dbQTxf2r+fmlflo+3h2g+MfEtXs7eOVpulAbN6okm2D08wPFjX2FG30UqItYhp7eBjh7R9Su55TpApEqi1FN1U3G1ysZA8SdI272r+wp++6CKIZf25h22o5BN07iUpPSdCxEV648ZYqk0PHfLPqA2QcLm0xwB33QAMrAD5bPOGQIKjeUAbKWbcS5e4vxfS40Yv3Nqa9WS+L3xkIkQjwq2ltFZkUhzKyHvYCjOTG3aWU8gbOEEKjE/7v8QZxJeq6w9YfHNGmhBXJiqgXE2I674cWP/TKeXo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XKT0DBz55+DZI5hamA0wRSI4QE1emy1rc1jLXWiBtqj+tqag5NHlxllJkjwomJqQsVVSK8Y3IuV8C4JYLDqksA== 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: The new filemap_splice_read() has an implicit expectation via filemap_get_pages() that ->read_folio() exists if ->readahead() doesn't fully populate the pagecache of the file it is reading from[1], potentially leading to a jump to NULL if this doesn't exist. shmem, however, (and by extension, tmpfs, ramfs and rootfs), doesn't have ->read_folio(), Work around this by equipping shmem with its own splice-read implementation, based on filemap_splice_read(), but able to paste in zero_page when there's a page missing. Signed-off-by: David Howells cc: Daniel Golle cc: Guenter Roeck cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Hugh Dickins cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/Y+pdHFFTk1TTEBsO@makrotopia.org/ [1] --- Notes: ver #19) - Remove a missed get_page() on the zero page. ver #18) - Don't take/release a ref on the zero page. mm/shmem.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..a0c268dcf7b8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2719,6 +2719,138 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return retval ? retval : error; } +static bool zero_pipe_buf_get(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ + return true; +} + +static void zero_pipe_buf_release(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ +} + +static bool zero_pipe_buf_try_steal(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ + return false; +} + +static const struct pipe_buf_operations zero_pipe_buf_ops = { + .release = zero_pipe_buf_release, + .try_steal = zero_pipe_buf_try_steal, + .get = zero_pipe_buf_get, +}; + +static size_t splice_zeropage_into_pipe(struct pipe_inode_info *pipe, + loff_t fpos, size_t size) +{ + size_t offset = fpos & ~PAGE_MASK; + + size = min_t(size_t, size, PAGE_SIZE - offset); + + if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { + struct pipe_buffer *buf = pipe_head_buf(pipe); + + *buf = (struct pipe_buffer) { + .ops = &zero_pipe_buf_ops, + .page = ZERO_PAGE(0), + .offset = offset, + .len = size, + }; + pipe->head++; + } + + return size; +} + +static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode = file_inode(in); + struct address_space *mapping = inode->i_mapping; + struct folio *folio = NULL; + size_t total_spliced = 0, used, npages, n, part; + loff_t isize; + int error = 0; + + /* Work out how much data we can actually add into the pipe */ + used = pipe_occupancy(pipe->head, pipe->tail); + npages = max_t(ssize_t, pipe->max_usage - used, 0); + len = min_t(size_t, len, npages * PAGE_SIZE); + + do { + if (*ppos >= i_size_read(inode)) + break; + + error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, SGP_READ); + if (error) { + if (error == -EINVAL) + error = 0; + break; + } + if (folio) { + folio_unlock(folio); + + if (folio_test_hwpoison(folio)) { + error = -EIO; + break; + } + } + + /* + * i_size must be checked after we know the pages are Uptodate. + * + * Checking i_size after the check allows us to calculate + * the correct value for "nr", which means the zero-filled + * part of the page is not copied back to userspace (unless + * another truncate extends the file - this is desired though). + */ + isize = i_size_read(inode); + if (unlikely(*ppos >= isize)) + break; + part = min_t(loff_t, isize - *ppos, len); + + if (folio) { + /* + * If users can be writing to this page using arbitrary + * virtual addresses, take care about potential aliasing + * before reading the page on the kernel side. + */ + if (mapping_writably_mapped(mapping)) + flush_dcache_folio(folio); + folio_mark_accessed(folio); + /* + * Ok, we have the page, and it's up-to-date, so we can + * now splice it into the pipe. + */ + n = splice_folio_into_pipe(pipe, folio, *ppos, part); + folio_put(folio); + folio = NULL; + } else { + n = splice_zeropage_into_pipe(pipe, *ppos, len); + } + + if (!n) + break; + len -= n; + total_spliced += n; + *ppos += n; + in->f_ra.prev_pos = *ppos; + if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) + break; + + cond_resched(); + } while (len); + + if (folio) + folio_put(folio); + + file_accessed(in); + return total_spliced ? total_spliced : error; +} + static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence) { struct address_space *mapping = file->f_mapping; @@ -3938,7 +4070,7 @@ static const struct file_operations shmem_file_operations = { .read_iter = shmem_file_read_iter, .write_iter = generic_file_write_iter, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, + .splice_read = shmem_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, #endif From patchwork Wed Mar 15 16:35:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176336 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 322A7C7618B for ; Wed, 15 Mar 2023 16:36:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C78816B007E; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C28DF6B0080; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA2626B0081; Wed, 15 Mar 2023 12:36:14 -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 980716B007E for ; Wed, 15 Mar 2023 12:36:14 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 35B7B160DB5 for ; Wed, 15 Mar 2023 16:36:14 +0000 (UTC) X-FDA: 80571685068.23.CBFF8A8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 7D75D4001C for ; Wed, 15 Mar 2023 16:36:12 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="JogAK2/A"; spf=pass (imf27.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=1678898172; 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=74aMisHJvcrsbS5g8R7662ZNEA+1A6hMiypJVvVd5yo=; b=dYj2cHeTi+L0GFXth78hEo7twXxpDbIFvcsIQSFsR8OYB8AngBToZSOH1FxJqeFg+9YrqE am1afH714pLzaODgT7ojAaD8d/gUa6RZOrzE3rUDNjbY51hs1MSf0mcr8fuSkw1U3pIyXI 4mg9oO89zGh2Rp89YhxOwbF337Yfar4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="JogAK2/A"; spf=pass (imf27.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=1678898172; a=rsa-sha256; cv=none; b=maq5ppCHNzJ4suej93y24V/+sONNSD9J/3XyoyztOBhOAEsWNrrGwg+iklaJ9fDcSGjOn0 VQO2k/C6E9IgwwnwTlmSU8qtKv8rZ7REwGXLCVHsYXUVHcJOEzRVQkT65m48bN05d1AxHT x2N09lWRy5iOSBam6tYgWgPnCr8QmYU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898171; 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=74aMisHJvcrsbS5g8R7662ZNEA+1A6hMiypJVvVd5yo=; b=JogAK2/AhjBAWlxTzpsgVTypL9q3zjnUGTTOwkHrk9HebcVKeyQJns0RECDhHi/tRZPIcD OMriBO2+k/pHJOMziVCsX8SEb2JoAGZ0gCDyQ/QwFsPiGUyBu7lvEj1j29c6u/HsT+EWt2 +ld6cukSjpMdFTGugLbTtelh8Jjvabc= 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-552-0l7YBVunPwOyKLm554H8jA-1; Wed, 15 Mar 2023 12:36:08 -0400 X-MC-Unique: 0l7YBVunPwOyKLm554H8jA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38265101A556; Wed, 15 Mar 2023 16:36:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D47622027040; Wed, 15 Mar 2023 16:36:02 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard , Miklos Szeredi , linux-unionfs@vger.kernel.org Subject: [PATCH v19 04/15] overlayfs: Implement splice-read Date: Wed, 15 Mar 2023 16:35:38 +0000 Message-Id: <20230315163549.295454-5-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6ny9w8gjnzg6tqmie66wdcqr9ah19q3u X-Rspamd-Queue-Id: 7D75D4001C X-HE-Tag: 1678898172-116418 X-HE-Meta: U2FsdGVkX18yYJCgz8/3v6Af6sKi0yTrDNQbKV4QhvKuNjO0jktePpTxqh5QzwdkDXaeThgfjcSYr6a4V1o5Bb+8q42kUabmZRY/22FGhFrxeRyw3iSHOPyjrTejd1FQA0dIyHuXQGUOSIyS79GQBXD+erY3Mrx6gfPGdb0WaBVh2U5geKDltRlwRKCqg2jFQJNVTavjQR8IBfgRZner4XUcICk+FFq28aMHdxc/zP+HpDFs1OrM++Y98vEYGlDlcA3my0u9bFiJ1dCzuYU6WE58A/ZUazB6fQnClIU2ZHPSsHfOz0GOeo0tJWemC0IMnHHb1vR4tsg2owbD6Yws3GG7IxPbgf/qWo9njWZizU99g+ud9gMc/DMQeqOyl8depjK14QJ6L+m47dt/aU9qVVhbhGQ7yGfLjVvyiXdDY7mQ5txYUFwooVnWXb54eEN1T1G4df2Xm4Aa08F7eM65e1MyeBg8o3ALcf7XbOvaWpPBRx3DaHxA26zpmd/Hrvl8zAxfd9pRtlvUj+2q9A+5nm40RVEyn+F99kkvv/omqWo9AOSHjoH1ZosqNHbH3Jl1VK3UiuOsYDPzvnIKGHYclzOTNmcM3D2EgejqhtbwSmNIKwhjeruW6ySSoBZtYpoKSk6B8+oJYntrd1lN+kh3UwqBoYtAYKrBFOaGsigLhi2K/PoSt6U0Xth54Zu3MV1IphgsLi2Q+OZYF12ynRs175M6GN3VTCvoesTBlwd6tdznJDVb7yDtazk7sanwYFUz0M0ricdK6MYo+XvXnelWGqPPiXUbh3XswIQ62MbR6TdpSNZoQAxWxbXAHq8lQBumF3qB4baw9Yvt13sPLTc6qbRVQeertj2BpPxDyuXVV6T5/gdzSDVexR2/ZQGcMdLJNFWsMsHS8ZsfFwWkO/shnI48LUi6MkJDhOrjAYhdhgc2IwZIF8yNdUwL5YMBoxyi5Rgid/19PsJsTb2VC3s KUTt3dTG 5FzCfuep+xSvpuYtV/YDk6Gj9rkTpm5f+ZZxcAO1DmkfZdkiIJ5GyDAROpvEOkBZXj3ST+nnx5I3NfN4LeVbALq/DaQL0WbseAXSHPH60GmxGL8hjttKpZbW/hvmMWUjXlJUKGr6UxMGH8pKMsSLU6jKOPH9WHb8sSSKvn237eweMWJSGKf9U+5FG+ceoUHW2x+yb05Ig1Fpa1Ki4i5bmxm3ZwFdB9n3SVGLJ/SFJys9DIl4qC/grXlRyMTV++9xJU7WwBxUGoGP1+ojRj6gmIe3C28y/C0Ij0UHwmGi9I5qYiPZYwIjVN8zdZxzTOnMITaPhj+NvCfOvkndH91da0VXGXeEE8Gos3voCrtpzCQdCnIElflMg6sqWTPIiqVXTjYyfPpiW9eMEPMWOA6+n10GpKD8VPujxvvB2e+iXfPB+EQVq1bm5ykPRfhjbP4DuB3xU 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: Implement splice-read for overlayfs by passing the request down a layer rather than going through generic_file_splice_read() which is going to be changed to assume that ->read_folio() is present on buffered files. Signed-off-by: David Howells cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Miklos Szeredi cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: Christian Brauner Reviewed-by: David Hildenbrand --- Notes: ver #17) - Use vfs_splice_read() helper rather than open-coding checks. ver #15) - Remove redundant FMODE_CAN_ODIRECT check on real file. - Do rw_verify_area() on the real file, not the overlay file. - Fix a file leak. fs/overlayfs/file.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 7c04f033aadd..86197882ff35 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -419,6 +419,27 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) return ret; } +static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) +{ + const struct cred *old_cred; + struct fd real; + ssize_t ret; + + ret = ovl_real_fdget(in, &real); + if (ret) + return ret; + + old_cred = ovl_override_creds(file_inode(in)->i_sb); + ret = vfs_splice_read(real.file, ppos, pipe, len, flags); + revert_creds(old_cred); + ovl_file_accessed(in); + + fdput(real); + return ret; +} + /* * Calling iter_file_splice_write() directly from overlay's f_op may deadlock * due to lock order inversion between pipe->mutex in iter_file_splice_write() @@ -695,7 +716,7 @@ const struct file_operations ovl_file_operations = { .fallocate = ovl_fallocate, .fadvise = ovl_fadvise, .flush = ovl_flush, - .splice_read = generic_file_splice_read, + .splice_read = ovl_splice_read, .splice_write = ovl_splice_write, .copy_file_range = ovl_copy_file_range, From patchwork Wed Mar 15 16:35:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176338 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 F0BA5C7618B for ; Wed, 15 Mar 2023 16:36:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A696B0081; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A6F6B0082; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683E26B0083; Wed, 15 Mar 2023 12:36:21 -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 593126B0081 for ; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 323FBA1135 for ; Wed, 15 Mar 2023 16:36:21 +0000 (UTC) X-FDA: 80571685362.08.6AE7EB6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 4DFA610001E for ; Wed, 15 Mar 2023 16:36:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QQjxKO+n; spf=pass (imf05.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=1678898178; 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=Mo6NWBR6hkfydtMnZeO+F5U5GhN+vbQRFCzRyccP/1I=; b=vhCFhncrWXl0tt17Zin3x2gqvZ60jVWqnhbUL3M/6D9vPeGr80lJGFKFOXfuQbRbQpsYYy ql6t++p5GXCFX8pOS8vrAYhAQ3vOrBn6q8ZfPaw3DVY/1DiiyIEcPuhfp25uLuBw+DvJj+ +FE89/PZUr6NyGfNQV/7ea2DqAUGsoI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QQjxKO+n; spf=pass (imf05.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=1678898178; a=rsa-sha256; cv=none; b=faQACnGOvDz2U1tNI0XnC/sdzR11gEdzmB+V7kQqKUsyueZ/kHbhVUcjJyHKygJNY8b7Hb sRjbR6w0/qDcg2XfO7MP70EvvN4eGX61oVYnIVIIBKYG4aa6KtVl7hddvZihBMoSZZjI9U rO7CMZh73v52DP5h8Ahfx5ABoQ55Usk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898177; 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=Mo6NWBR6hkfydtMnZeO+F5U5GhN+vbQRFCzRyccP/1I=; b=QQjxKO+nVYx7iAFg828rNSOk9aK470TkdzyNKixc/G4DJc8KEpc3VY7Et6yb7SFOHyCLVF 0pmwOnWC501xao0GmTMs2nRkKc6opViH+9kLD3p45oW1VEjN+aLyV1flHsjnJwE42T+J4C EYDERPcX3P0fq+LT8FuyBYQCYx1Yj2Q= 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-217-WMsh2JaSO0acjNRTd_X4qA-1; Wed, 15 Mar 2023 12:36:11 -0400 X-MC-Unique: WMsh2JaSO0acjNRTd_X4qA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9123C2807D8F; Wed, 15 Mar 2023 16:36:08 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEEBB4042AC2; Wed, 15 Mar 2023 16:36:05 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jan Harkes , Christoph Hellwig , John Hubbard , coda@cs.cmu.edu, codalist@coda.cs.cmu.edu, linux-unionfs@vger.kernel.org Subject: [PATCH v19 05/15] coda: Implement splice-read Date: Wed, 15 Mar 2023 16:35:39 +0000 Message-Id: <20230315163549.295454-6-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4DFA610001E X-Stat-Signature: rbstn4rd1c5escoe11933o417bparh34 X-Rspam-User: X-HE-Tag: 1678898178-627933 X-HE-Meta: U2FsdGVkX19g7qqmJfNqhW3Y6D8/n2DRLZjc0X/2uuRbq1AGq5r8YtMZgbdjk1GRbjiNJEZocxiw62zJep3fZ8hIJfV+HnxZaDS6nGO26GO0GEHd/RAtpZnSw1R4Vq4/ltw7wIr1aPkgp0DkhmhPxhqufEdM07Jcicwyy1q2p/GpgU+5kmy0GIJc7wm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VpRjH7bBtUTaPRPRSF283vpxHcFQ0apWh3I7UnBYn0TyzMx5YuMciOiSzI5eJVIqLr0IxiLU/xzxZY+6WrJlE1ls7w9P+cyncFjqKZ0UYeMBtq3hXMdEkoNH8ttZJ5a4cDNmbbXzwT+H05ARSlns2KAowOBAtP6QeE44sc 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: Implement splice-read for coda by passing the request down a layer rather than going through generic_file_splice_read() which is going to be changed to assume that ->read_folio() is present on buffered files. Signed-off-by: David Howells Acked-by: Jan Harkes cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: coda@cs.cmu.edu cc: codalist@coda.cs.cmu.edu cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- Notes: ver #17) - Use vfs_splice_read() helper rather than open-coding checks. fs/coda/file.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fs/coda/file.c b/fs/coda/file.c index 3f3c81e6b1ab..12b26bd13564 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "coda_psdev.h" @@ -94,6 +95,32 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t +coda_file_splice_read(struct file *coda_file, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *coda_inode = file_inode(coda_file); + struct coda_file_info *cfi = coda_ftoc(coda_file); + struct file *in = cfi->cfi_container; + loff_t ki_pos = *ppos; + ssize_t ret; + + ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), + &cfi->cfi_access_intent, + len, ki_pos, CODA_ACCESS_TYPE_READ); + if (ret) + goto finish_read; + + ret = vfs_splice_read(in, ppos, pipe, len, flags); + +finish_read: + venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode), + &cfi->cfi_access_intent, + len, ki_pos, CODA_ACCESS_TYPE_READ_FINISH); + return ret; +} + static void coda_vm_open(struct vm_area_struct *vma) { @@ -302,5 +329,5 @@ const struct file_operations coda_file_operations = { .open = coda_open, .release = coda_release, .fsync = coda_fsync, - .splice_read = generic_file_splice_read, + .splice_read = coda_file_splice_read, }; From patchwork Wed Mar 15 16:35:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176337 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 CF122C61DA4 for ; Wed, 15 Mar 2023 16:36:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6855E6B0080; Wed, 15 Mar 2023 12:36:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6359A6B0081; Wed, 15 Mar 2023 12:36:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D6376B0082; Wed, 15 Mar 2023 12:36:19 -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 3FBCB6B0080 for ; Wed, 15 Mar 2023 12:36:19 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DBEB8AB8BC for ; Wed, 15 Mar 2023 16:36:18 +0000 (UTC) X-FDA: 80571685236.30.B440BDE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id E83FE1A002C for ; Wed, 15 Mar 2023 16:36:15 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LfUDazEq; spf=pass (imf19.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=1678898176; 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=WFhWed43Sc7081L0WA9mMaa7Q22YwjW6QNRxMcW8x9U=; b=KA+EqEc9Cosqzdl/33RVYuKMXJZYp1XvND+G4av2jZgnMTslelajOKhmvX9t8tGrpCol9T d1AUfdlIC7IaPzCnqBx5+aSZXQsKnrCXg5/E3/c2Z1Bx7fNPu3O3mfKU1T/eo3lvn0f8cJ Ob86en4gg7iYyc4DQ3qmImOMKCICSTs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LfUDazEq; spf=pass (imf19.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=1678898176; a=rsa-sha256; cv=none; b=Ch18c4MRAHya8tqKg4vqJProv0ruPc07BouJEVZ9+OUmjKfDT0a9CndQMOuQoh9Ez0vdql jnwt09PoUMLNxxOyjKc5lOH5pTOLLjg8PXFw8gmnDk0Ea7oskGpeRYlCLfmLeyhkvuGSg/ QUGqylGx0qNrGDp1e+gW0qh3TBrnZZI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898175; 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=WFhWed43Sc7081L0WA9mMaa7Q22YwjW6QNRxMcW8x9U=; b=LfUDazEqz+gcomBEhOVq032MRFmMYrsNzXfE1rYaBpIAUwwl2HHAZVuB1YBjs2+hklN4ml 56YoNn/oD3+UQ51ZRh0zwwlJuhHT0gj8LfbLXebd6EmjLnQlL9RxLbTZ2gNwYQDgP+/0xT KY35rHDuJgCbjHDkaAK2gka5xgk3d6k= 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-483-kqwLoURCP6-7ZbSIoOf5VA-1; Wed, 15 Mar 2023 12:36:13 -0400 X-MC-Unique: kqwLoURCP6-7ZbSIoOf5VA-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 C5C89185A794; Wed, 15 Mar 2023 16:36:11 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47217400F4F; Wed, 15 Mar 2023 16:36:09 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Greg Kroah-Hartman , Christoph Hellwig , John Hubbard , Miklos Szeredi , Arnd Bergmann Subject: [PATCH v19 06/15] tty, proc, kernfs, random: Use direct_splice_read() Date: Wed, 15 Mar 2023 16:35:40 +0000 Message-Id: <20230315163549.295454-7-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: h8t4rur5izhqbbf9p5juhyxodf4ujxzg X-Rspam-User: X-Rspamd-Queue-Id: E83FE1A002C X-Rspamd-Server: rspam06 X-HE-Tag: 1678898175-839413 X-HE-Meta: U2FsdGVkX1/oHaAu89xml+V26iEPBumVOKBbKn/Ely/aL20eWuRsPTNFremqA8xDCgXqo7zLbKC8/225FWwWhogrtp44jdyWpANR1wtRojNrIQ6OecL4pwCAPXdHXJOfqtLBocmkaYWDdqtT+y/va1Ys4UwBjWANj/Mx/NF8laDCEWNejvR+j+emkCx8LK+2yplj8l7NveOBj3KM+Drhf7zyqCukEKwBsE5Tk0QCuUtJGDfkXHnxLVkAm3ABj/zHH6GrxAvI7kofwqShUf7op3PUWeaPgLgaqM3IbvcobJ9sSC9ESd2zSYJDUhnRmByBaBiDQFXUEA/yXjMdj9JUGH1IFIYRBnAh0wFian3JxXq0rKV3ZRx35bv6E7vmhvh8eeLYr15guu0gozUdtoKJfRO9Y8ujP7nX4ei9VtSDJGKZmxLTIsxNc8dR2pB6ARpYZjh3EbQyw2O33xZwaPmOUwXEbqOPcpN/K4N+U4fd+ZGcrTknjDVI/JGVNO22MRHrxiyrW2jVuYEvgV5z+OjRykDN68NDn/Hc/UdA1K7yzfVwJSD0RiUVnUTb/w2qtlPYQRsxtUOpfLgrUCz76Hl+1sOOGfpIP00QBsE7uRpfsmp7CTz2pLG8cqQEp3AYlHfTamvyLdgYDVJ2x17v0j7EiIUJn9uMm0LogfX9mDBXzHu5HOOia1W3JdKyUNDJO8qOcVMJHJJBLNp2LG8KL1JoHaRqBxdPaL1bL23cMjCtQxKBCQTFDXyRH1hCeTgmAxRDwqNR9IKZngpjrjtd1cvEgJ74UHczb8cp3KJzjROT1ZuNdICA+oMgan+eMJhOB2arsuwRVjkNow2gucJLbYOYXHSvoadd89HCgaAscjNWStNpdYEFz6mj+ZRYoln5TFt9u9QpYhjTNY0PfEVHMQzum6e4/uw5it52oeJ71G5Y7YYNa43Auv6RUXLkV74NLIjzVDJz5LP2XO6VyxsJd9y oAWZu+1E VkEImxp6Mvvj9Qcsf+oPpTIR21CehCGk3V15tizpDkbakVx31eNrcf6kg2LJ2/ZqIBixiQVK+w4MFryW4f4Iu7wzmwK0Y3VCYJUJJhTVbBqQ50ioUadazDVMYvKKFCPJS2IsRmE3ZWT4XlbF0npcPwFBC9XniB2gBMr8WwIISv73WhAgH6IN6XynfAmoXUR74IKqZtGTNpiYePgThVNVcuU6iAvU6IbQ/+oUdPBtxjpFJBQjC8xW0AH5R5YT8vPHyLkMwu0oGgi0bGzMcSUOY0dHlva5hNxz+sFYe515dKzVc6BRvqbX+X6SEOtodxS+vHAae3ALhCu/acjG5301NAKwqKL4n2pG1PCRyGBAVZiqx+pdbncAfCFfC29a8wcl0eU3Vu9+/26FTAsJh+Es0MiqWpPcoy5Fj5vE0YpPDapQFqlLncWMgrfeacxUdDkKaGBRpnDCuR0QkxsxiN2uznW3dUb1AsV5qKhwlUc+KLxptd+mvlj6K7yyYfukPV7EJB852mEaq3C71IK7w3+GyC+UKWjDk6S1HWhW2CP6xm/Pnm6ZBSqoOSONVug== 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: Use direct_splice_read() for tty, procfs, kernfs and random files rather than going through generic_file_splice_read() as they just copy the file into the output buffer and don't splice pages. This avoids the need for them to have a ->read_folio() to satisfy filemap_splice_read(). Signed-off-by: David Howells Acked-by: Greg Kroah-Hartman cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Miklos Szeredi cc: Arnd Bergmann cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- drivers/char/random.c | 4 ++-- drivers/tty/tty_io.c | 4 ++-- fs/kernfs/file.c | 2 +- fs/proc/inode.c | 4 ++-- fs/proc/proc_sysctl.c | 2 +- fs/proc_namespace.c | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index ce3ccd172cc8..792713616ba8 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1546,7 +1546,7 @@ const struct file_operations random_fops = { .compat_ioctl = compat_ptr_ioctl, .fasync = random_fasync, .llseek = noop_llseek, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, }; @@ -1557,7 +1557,7 @@ const struct file_operations urandom_fops = { .compat_ioctl = compat_ptr_ioctl, .fasync = random_fasync, .llseek = noop_llseek, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 36fb945fdad4..9d117e579dfb 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -466,7 +466,7 @@ static const struct file_operations tty_fops = { .llseek = no_llseek, .read_iter = tty_read, .write_iter = tty_write, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, .poll = tty_poll, .unlocked_ioctl = tty_ioctl, @@ -481,7 +481,7 @@ static const struct file_operations console_fops = { .llseek = no_llseek, .read_iter = tty_read, .write_iter = redirected_tty_write, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, .poll = tty_poll, .unlocked_ioctl = tty_ioctl, diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index e4a50e4ff0d2..9d23b8141db7 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -1011,7 +1011,7 @@ const struct file_operations kernfs_file_fops = { .release = kernfs_fop_release, .poll = kernfs_fop_poll, .fsync = noop_fsync, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/fs/proc/inode.c b/fs/proc/inode.c index f495fdb39151..711f12706469 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -591,7 +591,7 @@ static const struct file_operations proc_iter_file_ops = { .llseek = proc_reg_llseek, .read_iter = proc_reg_read_iter, .write = proc_reg_write, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .poll = proc_reg_poll, .unlocked_ioctl = proc_reg_unlocked_ioctl, .mmap = proc_reg_mmap, @@ -617,7 +617,7 @@ static const struct file_operations proc_reg_file_ops_compat = { static const struct file_operations proc_iter_file_ops_compat = { .llseek = proc_reg_llseek, .read_iter = proc_reg_read_iter, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .write = proc_reg_write, .poll = proc_reg_poll, .unlocked_ioctl = proc_reg_unlocked_ioctl, diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5851eb5bc726..e49f99657d1c 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -869,7 +869,7 @@ static const struct file_operations proc_sys_file_operations = { .poll = proc_sys_poll, .read_iter = proc_sys_read, .write_iter = proc_sys_write, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .splice_write = iter_file_splice_write, .llseek = default_llseek, }; diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 846f9455ae22..492abbbeff5e 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -324,7 +324,7 @@ static int mountstats_open(struct inode *inode, struct file *file) const struct file_operations proc_mounts_operations = { .open = mounts_open, .read_iter = seq_read_iter, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .llseek = seq_lseek, .release = mounts_release, .poll = mounts_poll, @@ -333,7 +333,7 @@ const struct file_operations proc_mounts_operations = { const struct file_operations proc_mountinfo_operations = { .open = mountinfo_open, .read_iter = seq_read_iter, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .llseek = seq_lseek, .release = mounts_release, .poll = mounts_poll, @@ -342,7 +342,7 @@ const struct file_operations proc_mountinfo_operations = { const struct file_operations proc_mountstats_operations = { .open = mountstats_open, .read_iter = seq_read_iter, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .llseek = seq_lseek, .release = mounts_release, }; From patchwork Wed Mar 15 16:35:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176339 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 D7A69C61DA4 for ; Wed, 15 Mar 2023 16:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9CF46B0082; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E248E6B0083; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C77586B0085; Wed, 15 Mar 2023 12:36:21 -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 B9E976B0082 for ; Wed, 15 Mar 2023 12:36:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7537412085C for ; Wed, 15 Mar 2023 16:36:21 +0000 (UTC) X-FDA: 80571685362.03.8EF7646 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id C924514001C for ; Wed, 15 Mar 2023 16:36:19 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nb0sQdrt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.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=1678898179; 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=tPHDzTeiqkehQq1hzvPvPGknkMXTxgyXWdFbtANbawg=; b=fQdGiCXKHqwcBoJFGafCICryhHB4xNZzThYVAM/NX9wqgb6FBmIWslVGD59nfIFpvVf35D TqBZhvxL9paOQpgQXO9RvGyWGZ6x7hNpj0hGFJBHmN4kHUWGFch95F6gptoEGBpGYkQ+Fk a2mWApH94vKMXUod1uSqnY0IBSV5N8I= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nb0sQdrt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.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=1678898179; a=rsa-sha256; cv=none; b=B+62PqnpnVPUw/liTLWJ08FVA6cw/v2mX5O83SJSSdug90nglQ6h5fT9HQAN5J+waOlB7a 89MMdi146h10u8Ua2iRkoMP3hKewOvRkpbmvvWiMZPZPsGvoxw3L6dQ0r2fnnr6eeZRUD1 +xY7o7yTmxJFfdIegcqt/AQUw3G1y0U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898179; 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=tPHDzTeiqkehQq1hzvPvPGknkMXTxgyXWdFbtANbawg=; b=Nb0sQdrtf2dD1zktfWNU3RbDJbtdQ+tUVZoLJCNifPR0WNex4bOo30pzFSjnyT053t6ZMx uPA65/gqaPAflu4Msjmg4e9fIzcsT3+5kUoGRxF3sUrH2hy75l+cUJ6fXwN1nO75byY/+/ 7+6PTOG/FTj0CTUU/mTGim+2Go4efgQ= 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-84-WUgqb5XdM1OrTaCbnHUsDQ-1; Wed, 15 Mar 2023 12:36:15 -0400 X-MC-Unique: WUgqb5XdM1OrTaCbnHUsDQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3540185A78F; Wed, 15 Mar 2023 16:36:14 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 639B01121314; Wed, 15 Mar 2023 16:36:12 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Steve French , John Hubbard , linux-cifs@vger.kernel.org Subject: [PATCH v19 07/15] splice: Do splice read from a file without using ITER_PIPE Date: Wed, 15 Mar 2023 16:35:41 +0000 Message-Id: <20230315163549.295454-8-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C924514001C X-Stat-Signature: tuihox71m3ziftw5t7yedzgh55puyxwx X-HE-Tag: 1678898179-483745 X-HE-Meta: U2FsdGVkX19oEIvHPel24p3etFM41u4RBvW3h0r63yUdkCyIRwgweXpFgwPlDqugvUlb+n5JTKNXZLmC0FpW7VEDsaVjA9M3g6f4rFPI9or7WNw45cpE3jcjEVZstxw7mk+WiQsBAsb9PDTaCfs112FiQKIUDyiaxsUQicI/viBVJcjQOLut1wJuuPMDugr2lf2Ll4lzMI4nXdHA6PZO7LepA0azMA2O5ZccjBcXKzRGCT4rPQN5ZGNh0JthCuboDhRJAs2Hhtu+c26rmCb+aw8FJ2F4Y2EaI+2ltNShaNeXsiXfyEufkTd1KEpFXblk9xGiSVhAQLQUHGg5fWEXBPVPA1+oOJY5Z0jZcmpOliWiJMDNC9+Bv6ldHFhBdxA+74jLFMqvYQ0s1w9F/2hKQqzSak7LNImTuizhEJcbfR2uAQBZaeGzdy/g/iQ6iQ+4VuNIniwUPrdbHrOXS96g5Kzx7wKhddgNf3QOArtgEsxYSr018caAKw8pF2CYE6r12Q7ID1EY0kpCYygXDhldAlqZ/h2vO+DMg84UAj9F6raDLkbkqKeGnfxeiTLCxkmkm82ZOFnRtxRdacNG1z1NO2TDUC9KKPZ2XELuZZmJWYFOfrhmzxCbDInKArgj+Tu7AUL22xP9fZAQ5ix93YE8rjN6Wfq+079dwAqOazICZV1l8aRULhkIw9sZuPpozbJ/Aqv89U7Jz48VxOq7w6PqF7wc4rby61UGekSeGRVIUXW3BIB0bh3wz5wm1G39GdOQDF+fWKbQnOebmzX2/KjjzZzdECHvqQPpx45h1yQDcguLo2j6ru3bcwRYKxXV/evaCJ5XIj1Ca/Iop1gx02ihyse73WZwWmungM/fpfA+VNvpTEr9kx/JCgzkDasPP3rJbJNaR/Z4EtrPWEmnSne4auxrlNmuxgmI8WwH3y5w7GT16hNxaIMc8yO5TlbyToF11Vls7kDDUn5SHTq8iw3 HXvZivtV K4nrrW/ekDh8+wAj8Of6Zv4XHAfowe747FeYVz7iGtyliN6m1iSSAZGRpDLRR7ULpiQPPfquO6klaAjvTjLBSNqvwQXKuTZFNmq5WV8qhbpPiq5OGwyer2bmwuOzcmw5er4W3jmi/kIIeIpKDe4pzGjy1TcRxH3uwk6eGYEKsExaylXMaid/dkPsbeNQqQkfDca8g1hvL4yo2dbWDt5xX813HMZjIr8MfM/nxvOWBNZbfKNnU+wvAVDfX0dbW6XIweyMgSfZ1RAxOwssmxPpEwiHtbST96/YkP1i/JGiGSc98FcEtsSjR4c6BYEldctxW/80neSB4xj0XTYXRmBBXzO3Ggz6PMHz8FpIB9uUQTKYqURn1tQmCnavaNxrkBsGfuqLB4brBw+LoUWvsY+r0ZvuC2UeT8Fz/YWaQYkguIQwo9/n8vSAb2pN8k2OmB6+FXXEYYoiNgeEJvfJLMLj2qhOG9JGD2zdr2sYqQf+hkNZRUVh7jHB2ugFX+lsffIec/RBL3nLfx9B9NUQCnhvpCemkBw== 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: Make generic_file_splice_read() use filemap_splice_read() and direct_splice_read() rather than using an ITER_PIPE and call_read_iter(). With this, ITER_PIPE is no longer used. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Steve French cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christian Brauner --- Notes: ver #18) - Split out the change to cifs to make it use generic_file_splice_read(). - Split out the unexport of filemap_splice_read() (still needed by cifs). fs/splice.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 90ccd3666dca..f46dd1fb367b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -387,29 +387,13 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { - struct iov_iter to; - struct kiocb kiocb; - int ret; - - iov_iter_pipe(&to, ITER_DEST, pipe, len); - init_sync_kiocb(&kiocb, in); - kiocb.ki_pos = *ppos; - ret = call_read_iter(in, &kiocb, &to); - if (ret > 0) { - *ppos = kiocb.ki_pos; - file_accessed(in); - } else if (ret < 0) { - /* free what was emitted */ - pipe_discard_from(pipe, to.start_head); - /* - * callers of ->splice_read() expect -EAGAIN on - * "can't put anything in there", rather than -EFAULT. - */ - if (ret == -EFAULT) - ret = -EAGAIN; - } - - return ret; + if (unlikely(*ppos >= file_inode(in)->i_sb->s_maxbytes)) + return 0; + if (unlikely(!len)) + return 0; + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + return filemap_splice_read(in, ppos, pipe, len, flags); } EXPORT_SYMBOL(generic_file_splice_read); From patchwork Wed Mar 15 16:35:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176341 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 285B8C61DA4 for ; Wed, 15 Mar 2023 16:36:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B67E66B0083; Wed, 15 Mar 2023 12:36:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF14E6B0087; Wed, 15 Mar 2023 12:36:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9436C6B0088; Wed, 15 Mar 2023 12:36:29 -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 830E76B0083 for ; Wed, 15 Mar 2023 12:36:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5C09312085C for ; Wed, 15 Mar 2023 16:36:29 +0000 (UTC) X-FDA: 80571685698.03.101D1F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 6005F18001F for ; Wed, 15 Mar 2023 16:36:26 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ivX44sAl; spf=pass (imf24.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=1678898186; 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=yFE/8AaBiLqJLRp8UNCaoGhfMwL8QvYGE4o0n7cdHXc=; b=0sRstyCk5+tw6IOOpywB5VWubfYmkoGKd4u4ZDYC/eGi4Ta13juFn0m5i7uWXOHdLYb0BE Hdf7exKDs0GlXyDV+qMHTF3M4mkKTaZMeDSSwvdYgFO0WLppnt4rXV6ex9jOOXt3gEKxgY BQ2uVsU+A8ff5+Pf0/tgOsd9/gVXrb8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ivX44sAl; spf=pass (imf24.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=1678898186; a=rsa-sha256; cv=none; b=awjHlh2D0+X6uA7dUIQr5JDtofp6ruEORXVqR7NLm6KHq1+gEqQ1OtA86VVO/eBMVqN0Ch bqvBToWo65PBKITB+XWb7pw07Muo9fgedZFb2aFSVzuEahd6COBJw9nIR7C+Wh5YAwIqMH Txkxi44nfRNZHzBQxgq6Pt7nIII6oyI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898185; 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=yFE/8AaBiLqJLRp8UNCaoGhfMwL8QvYGE4o0n7cdHXc=; b=ivX44sAlAIb0l1LrvumRjTB8WGNUOptOmkVhHjChdVcpuDBGI/0QgEzwQW61px2I8IjbIp kNVqiMsIOqBpeiH1q7PjGNdIxw9B/aqZbNu9boRdh46cQvmBVqnNVk8HFsUTVNLVz/CfsG 1UF4eBH098LtmAueZKU8NEOv6u6hE/U= 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-643-PMihXXm7NQapVKheb2ClNg-1; Wed, 15 Mar 2023 12:36:19 -0400 X-MC-Unique: PMihXXm7NQapVKheb2ClNg-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 D87E91C08967; Wed, 15 Mar 2023 16:36:17 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FCB147507A; Wed, 15 Mar 2023 16:36:15 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Paulo Alcantara , Steve French , John Hubbard , linux-cifs@vger.kernel.org Subject: [PATCH v19 08/15] cifs: Use generic_file_splice_read() Date: Wed, 15 Mar 2023 16:35:42 +0000 Message-Id: <20230315163549.295454-9-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-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: rspam04 X-Rspamd-Queue-Id: 6005F18001F X-Stat-Signature: acdzhsjq8wpk93zbbp4inwbkuidha79b X-HE-Tag: 1678898186-984366 X-HE-Meta: U2FsdGVkX18KbduKYmb6lhvmm0cYVyZ3VyoIXN3SwTApQWNejr2GXa/Ty7uGw4we6eVOgLZSaQvQWcsOfcMR47lKV7QEf+iszLD4LHFHbKxgw1NGAGn8nTrKRyUR0ZZcD9SQgReU3a5lRfkwsOrWZG2kMmBPiHIrivds4V91B9f8raZmY3He6PwygqzrmPlexInytH3x2okPPdY2TYpOLjFBeYQ0m4NHsLn4JlmVxtElrJj2Jv8RIRdrYcC0rY1w7JCKJE8HgkohPW4Qwprk6+QBiuhprTQPkggy2/UlB5CMg0YH9qPegotoF7EcPyFwfipqcHOzII3Nwzvce/d8XgeB3uwNZz9o0BKJDt+U32PzWudn8mIkQ8jj2/8pBADlXHLRlj9YlCg8tJq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QJBa9g9Vu/T8VGhVA= 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: Make cifs use generic_file_splice_read() rather than doing it for itself. As a consequence, filemap_splice_read() no longer needs to be exported. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: Paulo Alcantara (SUSE) cc: Jens Axboe cc: Steve French cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- Notes: ver #18) - Split out from change to generic_file_splice_read(). fs/cifs/cifsfs.c | 8 ++++---- fs/cifs/cifsfs.h | 3 --- fs/cifs/file.c | 16 ---------------- mm/filemap.c | 1 - 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index cbcf210d56e4..ba963a26cb19 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1359,7 +1359,7 @@ const struct file_operations cifs_file_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = cifs_splice_read, + .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1379,7 +1379,7 @@ const struct file_operations cifs_file_strict_ops = { .fsync = cifs_strict_fsync, .flush = cifs_flush, .mmap = cifs_file_strict_mmap, - .splice_read = cifs_splice_read, + .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1417,7 +1417,7 @@ const struct file_operations cifs_file_nobrl_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .splice_read = cifs_splice_read, + .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, @@ -1435,7 +1435,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .fsync = cifs_strict_fsync, .flush = cifs_flush, .mmap = cifs_file_strict_mmap, - .splice_read = cifs_splice_read, + .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 71fe0a0a7992..8b239854e590 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h @@ -100,9 +100,6 @@ extern ssize_t cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to); extern ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from); extern ssize_t cifs_direct_writev(struct kiocb *iocb, struct iov_iter *from); extern ssize_t cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from); -extern ssize_t cifs_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags); extern int cifs_flock(struct file *pfile, int cmd, struct file_lock *plock); extern int cifs_lock(struct file *, int, struct file_lock *); extern int cifs_fsync(struct file *, loff_t, loff_t, int); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 4d4a2d82636d..321f9b7c84c9 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -5066,19 +5066,3 @@ const struct address_space_operations cifs_addr_ops_smallbuf = { .launder_folio = cifs_launder_folio, .migrate_folio = filemap_migrate_folio, }; - -/* - * Splice data from a file into a pipe. - */ -ssize_t cifs_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) -{ - if (unlikely(*ppos >= file_inode(in)->i_sb->s_maxbytes)) - return 0; - if (unlikely(!len)) - return 0; - if (in->f_flags & O_DIRECT) - return direct_splice_read(in, ppos, pipe, len, flags); - return filemap_splice_read(in, ppos, pipe, len, flags); -} diff --git a/mm/filemap.c b/mm/filemap.c index 2723104cc06a..3a93515ae2ed 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2967,7 +2967,6 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, return total_spliced ? total_spliced : error; } -EXPORT_SYMBOL(filemap_splice_read); static inline loff_t folio_seek_hole_data(struct xa_state *xas, struct address_space *mapping, struct folio *folio, From patchwork Wed Mar 15 16:35:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176340 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 0B77AC6FD1D for ; Wed, 15 Mar 2023 16:36:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BA736B007E; Wed, 15 Mar 2023 12:36:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9695A6B0083; Wed, 15 Mar 2023 12:36:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80AC46B0087; Wed, 15 Mar 2023 12:36:28 -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 6FF906B0083 for ; Wed, 15 Mar 2023 12:36:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3477A805CD for ; Wed, 15 Mar 2023 16:36:28 +0000 (UTC) X-FDA: 80571685656.14.6CFF7ED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 3E2F08001C for ; Wed, 15 Mar 2023 16:36:26 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="c/jGgXEV"; spf=pass (imf30.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=1678898186; 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=XsRpjIP88f7UuB0TiBadjal83kAgF2un+t2WHwzlM/w=; b=QI0MXecN7Pedk3chZTF1ROKk5mSbyWU68np4fBUIPGSM+sJtHOz9tsMHkhHVb7jfUlWQWZ jSMVzbGXRvjie55c2vvlpnJKw9wVd9Bs1AKhDleh6P+UR6rCxG1KP/gd0uAknWXVwTgdoO +dPVqEKxDcH/En84rO9IwbH1ILsOc70= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="c/jGgXEV"; spf=pass (imf30.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=1678898186; a=rsa-sha256; cv=none; b=xkMFljcwyLT2clds9W5MNu0iPZwRZljGBkOM0HY75m7IpXKKlEUYlqPJdtNv9L3L61SKL3 qlgU5TfT6QwjYV2Z+fZm4rZfD1RpbVf2sMlWhEBmLgz0vi+4jGxMpApqLAgzOxTp8+UiyO VkcakDSGW6h5D2U8P1p7tQlj2MXF+Sw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898185; 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=XsRpjIP88f7UuB0TiBadjal83kAgF2un+t2WHwzlM/w=; b=c/jGgXEVzT6740oVvMpOiIOeV1nMCADBzoz46RBbA68BvmraPw1e3W+SgfGQA8GN//7M9D FPF9fjehRoPOVxMT8XUInp1vjuNZ3vT05U4TDZGZyaBHFf+QxiBEnO8V7/L+Ep41XboPPD ac4xS56Lrmb1ALxfgPaPDiFI5iqdVpU= 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-48-L1wUMuA2PWupoSIpynxtJg-1; Wed, 15 Mar 2023 12:36:21 -0400 X-MC-Unique: L1wUMuA2PWupoSIpynxtJg-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 B3F843C0F23B; Wed, 15 Mar 2023 16:36:20 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7985F2166B26; Wed, 15 Mar 2023 16:36:18 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 09/15] iov_iter: Kill ITER_PIPE Date: Wed, 15 Mar 2023 16:35:43 +0000 Message-Id: <20230315163549.295454-10-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3E2F08001C X-Stat-Signature: qira141dgjnajahidktko1obpjay9t3c X-Rspam-User: X-HE-Tag: 1678898186-249196 X-HE-Meta: U2FsdGVkX18bRzW4ZhzIf2qKUati0Nia+6kOGFqBzm9H1gdKL41uG+eGnAE/uJZTygoNjNdqHQP9svI2wsMbhU4mTAjEVqPvDWTQcSowdu4poPrfaju7JrPDs9vJSdd47HLhsVhD9dAkH9vHG+LaKUZzTQ2KtIoAieMjNGcJ2tiPMsLU4NR66K5782YpuN80cVxUvn7BdEDsakIY/XtODZJrW3+evR25iPLYVeG1NATfZC1e0r+xW3S+0I9j+Q8AoFBApxyThkXl98lRsKZrCjiGPTTMXyr9R2ZF034pr5iT+UFwe1B8+yGKZcD+PEESNVKRF0fZbP/Q6ZAD2Z6Otqq2b8gGHDJNBheAqYP7/TSQZL7aABVx226opeAKiaCPsZxKVCiXDuQNzA+3U1+1bIfExorw6gzkPNLvlelxfadtC3SjmB4Vi53yBaIS4C4xM/vkrDLWZMcLDUvT4FK+hzod/Ptp62k+z4RErrZNHd7o6VDZR7WiLjuolBDZ2kTK8m/mDpZk+kzmy1IPTF5erjpQk30fNnOIFbCeByayFsvhh5GU40elgLaNMaO+lsbgXKFA7aMFnO3CEEylkr6CZWw0WXMxA32MA+0pEE5/eO+UbtwtJ1miSoadsDc+Kvjy1tHL+kaLy/O4Ht6NtrMo+NINCqOj/sSeZNAc08ryvJQGLyI9ljoxmMA3NllgBfgjUF+cu1Bm2KRyDuzd0pbVgv9Ibg2LRl9v/5UWhnEsCVr0Owq2O0lrBH7TTsjXTjyRPyW4xLJVTYBxIk3lqW/L7/T9aHRJvkbqOCphee6RCkP/dvA+7ppAmieq+2b8NjSMLKRvu0Q3N+Q9ws6W1eJXfdHxY8WEfUjYfcgPqJX7t3Gvwa1Qjl3c9wqbvykWj3Pzi3ETq99AnQ61YSxX/brI1KpZ3+olXyijyk7RZd6Rtt3MCx4egJn97chWDuJbNj0OdCru1S9Pe162jEYzTgl 0HXlg3Sa Pd4GN0iGoQ6VMJfdzqBeCDFwgBPa9Uej3zsy8RUHrgst96UT9q1sCiDpvRH5BUo6DreI9EEpZkV0cAeTcQVDHpTx1Ux/kusDwtJD32vU/S2y3kbfRw0HLVPrGrPufBqg6JmhDXkmE620Pyw4RdinapBholVknOoNgYgWB+7uAfIFHCZ7ZpVy/KTKZu7HlDkM4VbXBREpUrYlC2qRLRazZkDBOv14t8hpbRs/1BNyS4Ppf1CTCOiTuYZneitF9fei8x/e/K7qaOcgGOVBoML2f/sFngSwGfrEmnpFuDDBIWKFVgKnbfVgQ7tTqXwkYCvxy099I+RcYjEiK9UlsTzeH31mkWGWkDuD5RONRsMk3/N2bFa7ZSoVPoHPxFTg2pGf+3g+bPfW0z5H3hANKkdEE9L31zAR2uBKtx/nbLgDmqgAdH0xgC0NuViJasVA6orELNt5N 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: The ITER_PIPE-type iterator was only used for generic_file_splice_read(), but that has now been switched to either pull pages directly from the pagecache for buffered file splice-reads or to use ITER_BVEC instead for O_DIRECT file splice-reads. This leaves ITER_PIPE unused - so remove it. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christian Brauner --- include/linux/uio.h | 14 -- lib/iov_iter.c | 429 +------------------------------------------- mm/filemap.c | 3 +- 3 files changed, 4 insertions(+), 442 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 27e3fd942960..74598426edb4 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -11,7 +11,6 @@ #include struct page; -struct pipe_inode_info; typedef unsigned int __bitwise iov_iter_extraction_t; @@ -25,7 +24,6 @@ enum iter_type { ITER_IOVEC, ITER_KVEC, ITER_BVEC, - ITER_PIPE, ITER_XARRAY, ITER_DISCARD, ITER_UBUF, @@ -55,15 +53,10 @@ struct iov_iter { const struct kvec *kvec; const struct bio_vec *bvec; struct xarray *xarray; - struct pipe_inode_info *pipe; void __user *ubuf; }; union { unsigned long nr_segs; - struct { - unsigned int head; - unsigned int start_head; - }; loff_t xarray_start; }; }; @@ -101,11 +94,6 @@ static inline bool iov_iter_is_bvec(const struct iov_iter *i) return iov_iter_type(i) == ITER_BVEC; } -static inline bool iov_iter_is_pipe(const struct iov_iter *i) -{ - return iov_iter_type(i) == ITER_PIPE; -} - static inline bool iov_iter_is_discard(const struct iov_iter *i) { return iov_iter_type(i) == ITER_DISCARD; @@ -247,8 +235,6 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction, const struct kvec unsigned long nr_segs, size_t count); void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_vec *bvec, unsigned long nr_segs, size_t count); -void iov_iter_pipe(struct iov_iter *i, unsigned int direction, struct pipe_inode_info *pipe, - size_t count); void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count); void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *xarray, loff_t start, size_t count); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 274014e4eafe..fad95e4cf372 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -14,8 +14,6 @@ #include #include -#define PIPE_PARANOIA /* for now */ - /* covers ubuf and kbuf alike */ #define iterate_buf(i, n, base, len, off, __p, STEP) { \ size_t __maybe_unused off = 0; \ @@ -186,150 +184,6 @@ static int copyin(void *to, const void __user *from, size_t n) return res; } -#ifdef PIPE_PARANOIA -static bool sanity(const struct iov_iter *i) -{ - struct pipe_inode_info *pipe = i->pipe; - unsigned int p_head = pipe->head; - unsigned int p_tail = pipe->tail; - unsigned int p_occupancy = pipe_occupancy(p_head, p_tail); - unsigned int i_head = i->head; - unsigned int idx; - - if (i->last_offset) { - struct pipe_buffer *p; - if (unlikely(p_occupancy == 0)) - goto Bad; // pipe must be non-empty - if (unlikely(i_head != p_head - 1)) - goto Bad; // must be at the last buffer... - - p = pipe_buf(pipe, i_head); - if (unlikely(p->offset + p->len != abs(i->last_offset))) - goto Bad; // ... at the end of segment - } else { - if (i_head != p_head) - goto Bad; // must be right after the last buffer - } - return true; -Bad: - printk(KERN_ERR "idx = %d, offset = %d\n", i_head, i->last_offset); - printk(KERN_ERR "head = %d, tail = %d, buffers = %d\n", - p_head, p_tail, pipe->ring_size); - for (idx = 0; idx < pipe->ring_size; idx++) - printk(KERN_ERR "[%p %p %d %d]\n", - pipe->bufs[idx].ops, - pipe->bufs[idx].page, - pipe->bufs[idx].offset, - pipe->bufs[idx].len); - WARN_ON(1); - return false; -} -#else -#define sanity(i) true -#endif - -static struct page *push_anon(struct pipe_inode_info *pipe, unsigned size) -{ - struct page *page = alloc_page(GFP_USER); - if (page) { - struct pipe_buffer *buf = pipe_buf(pipe, pipe->head++); - *buf = (struct pipe_buffer) { - .ops = &default_pipe_buf_ops, - .page = page, - .offset = 0, - .len = size - }; - } - return page; -} - -static void push_page(struct pipe_inode_info *pipe, struct page *page, - unsigned int offset, unsigned int size) -{ - struct pipe_buffer *buf = pipe_buf(pipe, pipe->head++); - *buf = (struct pipe_buffer) { - .ops = &page_cache_pipe_buf_ops, - .page = page, - .offset = offset, - .len = size - }; - get_page(page); -} - -static inline int last_offset(const struct pipe_buffer *buf) -{ - if (buf->ops == &default_pipe_buf_ops) - return buf->len; // buf->offset is 0 for those - else - return -(buf->offset + buf->len); -} - -static struct page *append_pipe(struct iov_iter *i, size_t size, - unsigned int *off) -{ - struct pipe_inode_info *pipe = i->pipe; - int offset = i->last_offset; - struct pipe_buffer *buf; - struct page *page; - - if (offset > 0 && offset < PAGE_SIZE) { - // some space in the last buffer; add to it - buf = pipe_buf(pipe, pipe->head - 1); - size = min_t(size_t, size, PAGE_SIZE - offset); - buf->len += size; - i->last_offset += size; - i->count -= size; - *off = offset; - return buf->page; - } - // OK, we need a new buffer - *off = 0; - size = min_t(size_t, size, PAGE_SIZE); - if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) - return NULL; - page = push_anon(pipe, size); - if (!page) - return NULL; - i->head = pipe->head - 1; - i->last_offset = size; - i->count -= size; - return page; -} - -static size_t copy_page_to_iter_pipe(struct page *page, size_t offset, size_t bytes, - struct iov_iter *i) -{ - struct pipe_inode_info *pipe = i->pipe; - unsigned int head = pipe->head; - - if (unlikely(bytes > i->count)) - bytes = i->count; - - if (unlikely(!bytes)) - return 0; - - if (!sanity(i)) - return 0; - - if (offset && i->last_offset == -offset) { // could we merge it? - struct pipe_buffer *buf = pipe_buf(pipe, head - 1); - if (buf->page == page) { - buf->len += bytes; - i->last_offset -= bytes; - i->count -= bytes; - return bytes; - } - } - if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) - return 0; - - push_page(pipe, page, offset, bytes); - i->last_offset = -(offset + bytes); - i->head = head; - i->count -= bytes; - return bytes; -} - /* * fault_in_iov_iter_readable - fault in iov iterator for reading * @i: iterator @@ -433,46 +287,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, } EXPORT_SYMBOL(iov_iter_init); -// returns the offset in partial buffer (if any) -static inline unsigned int pipe_npages(const struct iov_iter *i, int *npages) -{ - struct pipe_inode_info *pipe = i->pipe; - int used = pipe->head - pipe->tail; - int off = i->last_offset; - - *npages = max((int)pipe->max_usage - used, 0); - - if (off > 0 && off < PAGE_SIZE) { // anon and not full - (*npages)++; - return off; - } - return 0; -} - -static size_t copy_pipe_to_iter(const void *addr, size_t bytes, - struct iov_iter *i) -{ - unsigned int off, chunk; - - if (unlikely(bytes > i->count)) - bytes = i->count; - if (unlikely(!bytes)) - return 0; - - if (!sanity(i)) - return 0; - - for (size_t n = bytes; n; n -= chunk) { - struct page *page = append_pipe(i, n, &off); - chunk = min_t(size_t, n, PAGE_SIZE - off); - if (!page) - return bytes - n; - memcpy_to_page(page, off, addr, chunk); - addr += chunk; - } - return bytes; -} - static __wsum csum_and_memcpy(void *to, const void *from, size_t len, __wsum sum, size_t off) { @@ -480,44 +294,10 @@ static __wsum csum_and_memcpy(void *to, const void *from, size_t len, return csum_block_add(sum, next, off); } -static size_t csum_and_copy_to_pipe_iter(const void *addr, size_t bytes, - struct iov_iter *i, __wsum *sump) -{ - __wsum sum = *sump; - size_t off = 0; - unsigned int chunk, r; - - if (unlikely(bytes > i->count)) - bytes = i->count; - if (unlikely(!bytes)) - return 0; - - if (!sanity(i)) - return 0; - - while (bytes) { - struct page *page = append_pipe(i, bytes, &r); - char *p; - - if (!page) - break; - chunk = min_t(size_t, bytes, PAGE_SIZE - r); - p = kmap_local_page(page); - sum = csum_and_memcpy(p + r, addr + off, chunk, sum, off); - kunmap_local(p); - off += chunk; - bytes -= chunk; - } - *sump = sum; - return off; -} - size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) { if (WARN_ON_ONCE(i->data_source)) return 0; - if (unlikely(iov_iter_is_pipe(i))) - return copy_pipe_to_iter(addr, bytes, i); if (user_backed_iter(i)) might_fault(); iterate_and_advance(i, bytes, base, len, off, @@ -539,42 +319,6 @@ static int copyout_mc(void __user *to, const void *from, size_t n) return n; } -static size_t copy_mc_pipe_to_iter(const void *addr, size_t bytes, - struct iov_iter *i) -{ - size_t xfer = 0; - unsigned int off, chunk; - - if (unlikely(bytes > i->count)) - bytes = i->count; - if (unlikely(!bytes)) - return 0; - - if (!sanity(i)) - return 0; - - while (bytes) { - struct page *page = append_pipe(i, bytes, &off); - unsigned long rem; - char *p; - - if (!page) - break; - chunk = min_t(size_t, bytes, PAGE_SIZE - off); - p = kmap_local_page(page); - rem = copy_mc_to_kernel(p + off, addr + xfer, chunk); - chunk -= rem; - kunmap_local(p); - xfer += chunk; - bytes -= chunk; - if (rem) { - iov_iter_revert(i, rem); - break; - } - } - return xfer; -} - /** * _copy_mc_to_iter - copy to iter with source memory error exception handling * @addr: source kernel address @@ -594,9 +338,8 @@ static size_t copy_mc_pipe_to_iter(const void *addr, size_t bytes, * alignment and poison alignment assumptions to avoid re-triggering * hardware exceptions. * - * * ITER_KVEC, ITER_PIPE, and ITER_BVEC can return short copies. - * Compare to copy_to_iter() where only ITER_IOVEC attempts might return - * a short copy. + * * ITER_KVEC and ITER_BVEC can return short copies. Compare to + * copy_to_iter() where only ITER_IOVEC attempts might return a short copy. * * Return: number of bytes copied (may be %0) */ @@ -604,8 +347,6 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) { if (WARN_ON_ONCE(i->data_source)) return 0; - if (unlikely(iov_iter_is_pipe(i))) - return copy_mc_pipe_to_iter(addr, bytes, i); if (user_backed_iter(i)) might_fault(); __iterate_and_advance(i, bytes, base, len, off, @@ -711,8 +452,6 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, return 0; if (WARN_ON_ONCE(i->data_source)) return 0; - if (unlikely(iov_iter_is_pipe(i))) - return copy_page_to_iter_pipe(page, offset, bytes, i); page += offset / PAGE_SIZE; // first subpage offset %= PAGE_SIZE; while (1) { @@ -761,36 +500,8 @@ size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, } EXPORT_SYMBOL(copy_page_from_iter); -static size_t pipe_zero(size_t bytes, struct iov_iter *i) -{ - unsigned int chunk, off; - - if (unlikely(bytes > i->count)) - bytes = i->count; - if (unlikely(!bytes)) - return 0; - - if (!sanity(i)) - return 0; - - for (size_t n = bytes; n; n -= chunk) { - struct page *page = append_pipe(i, n, &off); - char *p; - - if (!page) - return bytes - n; - chunk = min_t(size_t, n, PAGE_SIZE - off); - p = kmap_local_page(page); - memset(p + off, 0, chunk); - kunmap_local(p); - } - return bytes; -} - size_t iov_iter_zero(size_t bytes, struct iov_iter *i) { - if (unlikely(iov_iter_is_pipe(i))) - return pipe_zero(bytes, i); iterate_and_advance(i, bytes, base, len, count, clear_user(base, len), memset(base, 0, len) @@ -821,32 +532,6 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt } EXPORT_SYMBOL(copy_page_from_iter_atomic); -static void pipe_advance(struct iov_iter *i, size_t size) -{ - struct pipe_inode_info *pipe = i->pipe; - int off = i->last_offset; - - if (!off && !size) { - pipe_discard_from(pipe, i->start_head); // discard everything - return; - } - i->count -= size; - while (1) { - struct pipe_buffer *buf = pipe_buf(pipe, i->head); - if (off) /* make it relative to the beginning of buffer */ - size += abs(off) - buf->offset; - if (size <= buf->len) { - buf->len = size; - i->last_offset = last_offset(buf); - break; - } - size -= buf->len; - i->head++; - off = 0; - } - pipe_discard_from(pipe, i->head + 1); // discard everything past this one -} - static void iov_iter_bvec_advance(struct iov_iter *i, size_t size) { const struct bio_vec *bvec, *end; @@ -898,8 +583,6 @@ void iov_iter_advance(struct iov_iter *i, size_t size) iov_iter_iovec_advance(i, size); } else if (iov_iter_is_bvec(i)) { iov_iter_bvec_advance(i, size); - } else if (iov_iter_is_pipe(i)) { - pipe_advance(i, size); } else if (iov_iter_is_discard(i)) { i->count -= size; } @@ -913,26 +596,6 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll) if (WARN_ON(unroll > MAX_RW_COUNT)) return; i->count += unroll; - if (unlikely(iov_iter_is_pipe(i))) { - struct pipe_inode_info *pipe = i->pipe; - unsigned int head = pipe->head; - - while (head > i->start_head) { - struct pipe_buffer *b = pipe_buf(pipe, --head); - if (unroll < b->len) { - b->len -= unroll; - i->last_offset = last_offset(b); - i->head = head; - return; - } - unroll -= b->len; - pipe_buf_release(pipe, b); - pipe->head--; - } - i->last_offset = 0; - i->head = head; - return; - } if (unlikely(iov_iter_is_discard(i))) return; if (unroll <= i->iov_offset) { @@ -1020,24 +683,6 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction, } EXPORT_SYMBOL(iov_iter_bvec); -void iov_iter_pipe(struct iov_iter *i, unsigned int direction, - struct pipe_inode_info *pipe, - size_t count) -{ - BUG_ON(direction != READ); - WARN_ON(pipe_full(pipe->head, pipe->tail, pipe->ring_size)); - *i = (struct iov_iter){ - .iter_type = ITER_PIPE, - .data_source = false, - .pipe = pipe, - .head = pipe->head, - .start_head = pipe->head, - .last_offset = 0, - .count = count - }; -} -EXPORT_SYMBOL(iov_iter_pipe); - /** * iov_iter_xarray - Initialise an I/O iterator to use the pages in an xarray * @i: The iterator to initialise. @@ -1162,19 +807,6 @@ bool iov_iter_is_aligned(const struct iov_iter *i, unsigned addr_mask, if (iov_iter_is_bvec(i)) return iov_iter_aligned_bvec(i, addr_mask, len_mask); - if (iov_iter_is_pipe(i)) { - size_t size = i->count; - - if (size & len_mask) - return false; - if (size && i->last_offset > 0) { - if (i->last_offset & addr_mask) - return false; - } - - return true; - } - if (iov_iter_is_xarray(i)) { if (i->count & len_mask) return false; @@ -1244,14 +876,6 @@ unsigned long iov_iter_alignment(const struct iov_iter *i) if (iov_iter_is_bvec(i)) return iov_iter_alignment_bvec(i); - if (iov_iter_is_pipe(i)) { - size_t size = i->count; - - if (size && i->last_offset > 0) - return size | i->last_offset; - return size; - } - if (iov_iter_is_xarray(i)) return (i->xarray_start + i->iov_offset) | i->count; @@ -1303,36 +927,6 @@ static int want_pages_array(struct page ***res, size_t size, return count; } -static ssize_t pipe_get_pages(struct iov_iter *i, - struct page ***pages, size_t maxsize, unsigned maxpages, - size_t *start) -{ - unsigned int npages, count, off, chunk; - struct page **p; - size_t left; - - if (!sanity(i)) - return -EFAULT; - - *start = off = pipe_npages(i, &npages); - if (!npages) - return -EFAULT; - count = want_pages_array(pages, maxsize, off, min(npages, maxpages)); - if (!count) - return -ENOMEM; - p = *pages; - for (npages = 0, left = maxsize ; npages < count; npages++, left -= chunk) { - struct page *page = append_pipe(i, left, &off); - if (!page) - break; - chunk = min_t(size_t, left, PAGE_SIZE - off); - get_page(*p++ = page); - } - if (!npages) - return -EFAULT; - return maxsize - left; -} - static ssize_t iter_xarray_populate_pages(struct page **pages, struct xarray *xa, pgoff_t index, unsigned int nr_pages) { @@ -1482,8 +1076,6 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, } return maxsize; } - if (iov_iter_is_pipe(i)) - return pipe_get_pages(i, pages, maxsize, maxpages, start); if (iov_iter_is_xarray(i)) return iter_xarray_get_pages(i, pages, maxsize, maxpages, start); return -EFAULT; @@ -1573,9 +1165,7 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, } sum = csum_shift(csstate->csum, csstate->off); - if (unlikely(iov_iter_is_pipe(i))) - bytes = csum_and_copy_to_pipe_iter(addr, bytes, i, &sum); - else iterate_and_advance(i, bytes, base, len, off, ({ + iterate_and_advance(i, bytes, base, len, off, ({ next = csum_and_copy_to_user(addr + off, base, len); sum = csum_block_add(sum, next, off); next ? 0 : len; @@ -1660,15 +1250,6 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) return iov_npages(i, maxpages); if (iov_iter_is_bvec(i)) return bvec_npages(i, maxpages); - if (iov_iter_is_pipe(i)) { - int npages; - - if (!sanity(i)) - return 0; - - pipe_npages(i, &npages); - return min(npages, maxpages); - } if (iov_iter_is_xarray(i)) { unsigned offset = (i->xarray_start + i->iov_offset) % PAGE_SIZE; int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE); @@ -1681,10 +1262,6 @@ EXPORT_SYMBOL(iov_iter_npages); const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags) { *new = *old; - if (unlikely(iov_iter_is_pipe(new))) { - WARN_ON(1); - return NULL; - } if (iov_iter_is_bvec(new)) return new->bvec = kmemdup(new->bvec, new->nr_segs * sizeof(struct bio_vec), diff --git a/mm/filemap.c b/mm/filemap.c index 3a93515ae2ed..470be06b6096 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2690,8 +2690,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, if (unlikely(iocb->ki_pos >= i_size_read(inode))) break; - error = filemap_get_pages(iocb, iter->count, &fbatch, - iov_iter_is_pipe(iter)); + error = filemap_get_pages(iocb, iter->count, &fbatch, false); if (error < 0) break; From patchwork Wed Mar 15 16:35:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176342 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 8E017C6FD1D for ; Wed, 15 Mar 2023 16:36:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3026F6B0080; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 294C56B0087; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 153926B0088; Wed, 15 Mar 2023 12:36:38 -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 063896B0080 for ; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C43064034B for ; Wed, 15 Mar 2023 16:36:37 +0000 (UTC) X-FDA: 80571686034.18.8409942 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 224A840026 for ; Wed, 15 Mar 2023 16:36:35 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NatCcCbg; spf=pass (imf12.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=1678898196; 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=w0CyxxuCfKyDxUhqZI8uZNDs4yTA+LT97JFfaSxmf5E=; b=Ie6o8fecRkR3XtgNoRbzB5Bb3+Wq1odRKBKPQoOXOujubJp9HoHFo6D0OT2f5g8EXctGmS GBnfYvO6gt7HZQF3Bk8jdm1sYZjiqfFa6Dd4uTh7mk3htXv5x6Df5IcRKWfRpq3njSlGOL nh/FcGAPOVQBVL+hvbjUYiT9TIuLtK4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NatCcCbg; spf=pass (imf12.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=1678898196; a=rsa-sha256; cv=none; b=sCuB9W+eSSE4ttuh89lZOFBL7RDED6mJjrfNKGX5BCkEQYeFZAZg9H6vT6zljZptqmCKIO X6dsaoefFfDJVo1aZgaZB7oGQrdAlT1/xkvI11qT5rbJjAUJGYc35xFHnppoRBYedmcoDC OyRgd6ImMbay+negWEE7mkoWjq/n9V8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898195; 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=w0CyxxuCfKyDxUhqZI8uZNDs4yTA+LT97JFfaSxmf5E=; b=NatCcCbgMVsN0LbAv9xZSVLFjodBDYMn8mbCU0I6VHntm626EbigU8kn0F7a81NsgPG1Gt T/z5WMCGtFH38gpqjFrzgBDbQAO9h5jSOagu5iZKbOwKLvtCNQY2DMJCHj+mIRChjMY3tg scalSDx2Xdf6pe58CGor6cmA/1Ro60I= 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-503-KRZAb1KrMEG4we92PR2NZA-1; Wed, 15 Mar 2023 12:36:27 -0400 X-MC-Unique: KRZAb1KrMEG4we92PR2NZA-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 316A48828C6; Wed, 15 Mar 2023 16:36:24 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A4C2C164E7; Wed, 15 Mar 2023 16:36:21 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, John Hubbard , Dave Chinner , Christoph Hellwig Subject: [PATCH v19 10/15] iomap: Don't get an reference on ZERO_PAGE for direct I/O block zeroing Date: Wed, 15 Mar 2023 16:35:44 +0000 Message-Id: <20230315163549.295454-11-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 224A840026 X-Rspam-User: X-Stat-Signature: g6pcq5q4caewjfg1h5q15wmw5kcps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UJtPJq6pBVY6qrONy+Ki+Wwmj0vOhtrdbqIRJ3HwSSq07dFH/0qa/CzIPZJvhErornED3QiIaMbO+3HoJRF9mAVphfUVcWE6kLcTcTl9xtoabaLlROgFDztLR+B1VKtXPNbQ2YJd3RHsAW+8Asmb1RUGJVoEajZ/1UNfy+HbIurEpK/3r+zVz5aNEwWOv0A17Oamnb0Fr20fJL9aHg+NxxZoQJsR4K+lsTo9sYr8L2ox3ugPhgV/sbR5LuKERTENDYyzwG+1TOGhH71s+pXp8/+Pvskd5zpwZDJ6pFMHwo7wxuLpkVl8jKs5DF0ckAQ0D63oGPpCpuK 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: ZERO_PAGE can't go away, no need to hold an extra reference. Signed-off-by: David Howells Reviewed-by: David Hildenbrand Reviewed-by: John Hubbard Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig cc: Al Viro cc: linux-fsdevel@vger.kernel.org --- fs/iomap/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f771001574d0..850fb9870c2f 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -202,7 +202,7 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - get_page(page); + bio_set_flag(bio, BIO_NO_PAGE_REF); __bio_add_page(bio, page, len, 0); iomap_dio_submit_bio(iter, dio, bio, pos); } From patchwork Wed Mar 15 16:35:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176343 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 645AEC7618B for ; Wed, 15 Mar 2023 16:36:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 749BE6B0087; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F8CF6B0088; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5718B6B0089; Wed, 15 Mar 2023 12:36:38 -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 32B5A6B0088 for ; Wed, 15 Mar 2023 12:36:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 08CED1A05D1 for ; Wed, 15 Mar 2023 16:36:38 +0000 (UTC) X-FDA: 80571686076.17.E6F58F6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 9C5CB180016 for ; Wed, 15 Mar 2023 16:36:34 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NAl65g0X; spf=pass (imf16.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=1678898194; 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=0+QymJ+GCZW28tJ8JK9HTXv9GxubpscA9882LeMgv9w=; b=Sr7DceMjTYlJicyWK22cov23wa/CGIoUNuNqq2Vzle10ML1SpNY3CD2V0I8rG49wpEfaoN Mi0mDkQVxywGAn/Q8UxSarXb9kC4Oo3T3/5avK+PudefmwM7KnWub/TB+BbEN5qpcw2uFK 1ezMxaFFmChLPiYcDPmNGer9d1Dzs9c= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NAl65g0X; spf=pass (imf16.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=1678898194; a=rsa-sha256; cv=none; b=ZVXW6yX8+UxMkcIh3CJDntl+voewOECBTmevSakpAiuVl3FtikmdxfQrXqhPubg9JbMgw+ yf1/cgy0jvtX/LXCM9iDfnuI4PGJBrx8MsKhum5/t3qYHXvRQmVXITxlTE9tNwyAIlJzO8 lGw8QSpOXBwdW5Hzacx5F5VQFjYF9pM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898194; 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=0+QymJ+GCZW28tJ8JK9HTXv9GxubpscA9882LeMgv9w=; b=NAl65g0XRxxRMByGwfkB6b2XFF1k6l4LoHxnoxY/0emKTJKeHUD6ENCPtcMRREi6oxXZhv HW/HegjFqpdAIO/1VFOSA2m9dnogfvDsEkMHXQAs2zIECQMKBSydIwUvhKqVDMdiZJ+HYm ls2xd94lDC4z/pf87Nmh2rTGkL+/o2E= 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-132-0_two9ifOYW8-fQttFHzIw-1; Wed, 15 Mar 2023 12:36:28 -0400 X-MC-Unique: 0_two9ifOYW8-fQttFHzIw-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 DCA38858297; Wed, 15 Mar 2023 16:36:26 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C161AC164E7; Wed, 15 Mar 2023 16:36:24 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 11/15] block: Fix bio_flagged() so that gcc can better optimise it Date: Wed, 15 Mar 2023 16:35:45 +0000 Message-Id: <20230315163549.295454-12-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9C5CB180016 X-Rspam-User: X-Stat-Signature: hdfp69jc6y48j6juamyawrp5f9ac58s7 X-HE-Tag: 1678898194-283591 X-HE-Meta: U2FsdGVkX18nwWXKpXBRM6uPUD7dEQdELuy4QkhtqwdF5dQsbOn79HBZs2gDOVr6yvRZxJSsDiSosDcCwjdXep8yJT7Nsj/wCtDxrS64Yr+wpQ6UtMIwSy3UKYnNBcGH7p89qX1HEuX6mhOMBStFnJycDEwXC/WQXio98fFzKHDeAO91ULR05EMaoZDxlZScBqvkImT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p8R8r3Am6ATqjPHO6T9dvkgJL5TiYGTf3uOL3E35K8u+umzNL6Ez2U+I0jopSCsJdgcHTi20LhfZ6Q5mz2Y6hvnKooBu0pZBlQZiAAVc9RDwK5dOGcBOHyipa5rMU4rausbSN3VOBbrbLJ9dY7li9OS47WAuubMDMquvRqUVW4/63/GLAQ1sGiXW+ilJtnyQ3p+sv0bAXRGUfQtMMXs= 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 bio_flagged() so that multiple instances of it, such as: if (bio_flagged(bio, BIO_PAGE_REFFED) || bio_flagged(bio, BIO_PAGE_PINNED)) can be combined by the gcc optimiser into a single test in assembly (arguably, this is a compiler optimisation issue[1]). The missed optimisation stems from bio_flagged() comparing the result of the bitwise-AND to zero. This results in an out-of-line bio_release_page() being compiled to something like: <+0>: mov 0x14(%rdi),%eax <+3>: test $0x1,%al <+5>: jne 0xffffffff816dac53 <+7>: test $0x2,%al <+9>: je 0xffffffff816dac5c <+11>: movzbl %sil,%esi <+15>: jmp 0xffffffff816daba1 <__bio_release_pages> <+20>: jmp 0xffffffff81d0b800 <__x86_return_thunk> However, the test is superfluous as the return type is bool. Removing it results in: <+0>: testb $0x3,0x14(%rdi) <+4>: je 0xffffffff816e4af4 <+6>: movzbl %sil,%esi <+10>: jmp 0xffffffff816dab7c <__bio_release_pages> <+15>: jmp 0xffffffff81d0b7c0 <__x86_return_thunk> instead. Also, the MOVZBL instruction looks unnecessary[2] - I think it's just 're-booling' the mark_dirty parameter. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Jens Axboe cc: linux-block@vger.kernel.org Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108370 [1] Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108371 [2] Link: https://lore.kernel.org/r/167391056756.2311931.356007731815807265.stgit@warthog.procyon.org.uk/ # v6 --- include/linux/bio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index d766be7152e1..d9d6df62ea57 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -229,7 +229,7 @@ static inline void bio_cnt_set(struct bio *bio, unsigned int count) static inline bool bio_flagged(struct bio *bio, unsigned int bit) { - return (bio->bi_flags & (1U << bit)) != 0; + return bio->bi_flags & (1U << bit); } static inline void bio_set_flag(struct bio *bio, unsigned int bit) From patchwork Wed Mar 15 16:35:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176347 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 A3CEFC61DA4 for ; Wed, 15 Mar 2023 16:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43AE06B0096; Wed, 15 Mar 2023 12:37:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EA1F6B0095; Wed, 15 Mar 2023 12:37:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9E06B0096; Wed, 15 Mar 2023 12:37:32 -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 1B4FF6B0093 for ; Wed, 15 Mar 2023 12:37:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76BCBC0981 for ; Wed, 15 Mar 2023 16:37:31 +0000 (UTC) X-FDA: 80571688302.23.DD3AEB1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 8A242120004 for ; Wed, 15 Mar 2023 16:37:29 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S2CEr5aV; spf=pass (imf29.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=1678898249; a=rsa-sha256; cv=none; b=Sb5taaHuL0drWZbcLV/5gVwhQMk4gvnrbQjepuVQBnI9PCYyLHxLsEa5wKzxtWItKKAThS TW4nKEZO9I4nha+h4N7wcJrgIjVyfxCGrgnnxbvhSYu6SRN6AgbKkWiR67f4Ya1lPDWMhP vKMjuhIlfATQ//bs0bZ4s/2i4L3AXNk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S2CEr5aV; spf=pass (imf29.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=1678898249; 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=cRZ6zwkATo5WH/jIVyGNX8/GaSvHJQOFy9f4tGJFuL8=; b=OxwWUi0N2qHuF3y6qQSH/64owKYZMh2qHd+rpzoZxw7M+gq4A2yReu8sc6PPSKTlWgHaIa 58+R9QHWFMFSGCPIVRblt/kTh7GXEt1Vre5mBahGYe/dH+2jsJ16ahEIhvkZQb3RM2hpeU LJzzLmC/Dr0vMpkj1Czjl2Mz8o7Y14I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898248; 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=cRZ6zwkATo5WH/jIVyGNX8/GaSvHJQOFy9f4tGJFuL8=; b=S2CEr5aVKIvd7bjjos5aUUAwsUW49PCZiro8LwoahWnG34N3GtqWTVUV7BOumhtmziHMf9 WfA263us4OLVeDDtub7VXGdsNRnbJ2ntqlfJGX3kbz1wfFBW/p06RbP+B783PUsLYdFJmx boxGcQIV5o8fbOo49A+9yUIgqqdh+Bo= 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-295-MaPgOrIuMoe73ChQ23sWJA-1; Wed, 15 Mar 2023 12:37:22 -0400 X-MC-Unique: MaPgOrIuMoe73ChQ23sWJA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2A3B2806054; Wed, 15 Mar 2023 16:36:29 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95C974042AC2; Wed, 15 Mar 2023 16:36:27 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 12/15] block: Replace BIO_NO_PAGE_REF with BIO_PAGE_REFFED with inverted logic Date: Wed, 15 Mar 2023 16:35:46 +0000 Message-Id: <20230315163549.295454-13-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Queue-Id: 8A242120004 X-Rspamd-Server: rspam01 X-Stat-Signature: 8hez96twkqcs4nau9dyyddkk4qnan95u X-HE-Tag: 1678898249-27750 X-HE-Meta: U2FsdGVkX19oZ/hyEa6QaI+LevlHBBum/IhvmOlPxZAt0Ddhw6PdfenVrPTsEIB1E4u7no87JelmY4q0XQOuMMqPClmmGJtAcE+XQ7KXonGLC4EWcsCsTRHx5Os+8z7JxhITIXuG7X+7vDyrwXVhcXhOFS1z3PdE0MtZFMaxLf/yXEcGXTkqEvN3eC45nfZ7CV5XiTltjt9/2oa/pNYuTt6mw66k1dxCXdJTXBCIZ27XfXb0A4LRn9fDxU1tcuZyPF6TSC1iSQ3LcaB/xM6Im0LO9alVI4Y0Z3uYYQFvX0PQtCyYv+yImNM/PnlC/prJpIbrjTISKAVtlmNwP2EnZPi0hM1RcpIuui98W3oRHUl41cBu79YYtvYsuqVtDd9sKb0Qg8GX06NIRnOVIlaE4latWpJQv+PVuqRe4U7MLeucPUm/tglvYgeZiO8+pCXKXdBPlobsYIXBzrM74scu9s6u6BriQjs0nYO6weDhbc/9JxEB0GBu9lQjhRrrTmk+Cjt2i2LiDQ4X4n/aB2IpAIoQiKllhY6450tcTBem6oPmA7ddV8bTOLSRh4TxTehSwl35mnS0RYq3Is7ECll6j2dZ1fq6J+mym/pldkU4zBCg5Sm731WRROyqMWs30EmJmjd7A/epNaon8kPQ16HiNVsICFIf++s2sZtjneHrE9mlZiOv6At4JnTQ9Q0SD0I4q94ow8mVaL4J1qz1AND7gYenCvFvP3dIAWrpHHJibvaqUO6hNgP1jQA65bQg9ggClGKZ9tDC3NJUIKBXNG669l/SuyzMO3lUbvLWKCM38NKkXMhpP84TtYhr9Iqa+9iL7g33BQgqMlOBv99HeCqZ2r6Gy+PxupTRBc7Km7wa+xMkc26MRpk754b7pQWJCsqy8Jj5ZLk1UqIz8Mo4G4l+OrnQtYxDMYW+3SYvic0IldQJBuxaLHVLSo5jZdF9QOZoGBHHBmb0rPIT0jr9EB5 rqt4MM3q wDouqmEAnAXX8Q+3iwAXk/puVcOcJrq2Xsm1H/J0GrXA1W8i70h/EZTyKFrE8OIKznD1+7A+qyGf8p7nTJTEmEtq8ARSUYRQIcEBPSiAZjGyxOk2Wp21PUNpbusDqhllLvsomo0YDXXKFMmy+k6cs8d4u1O7Rxf9v93TfZ15hlQXpj2ThVSsJ9OHDz5t4twZpKv9Cf6aOBz/arOEIHoLQ9YCBphdb7tWlmbXOsoilIAvkWO29qylLdwb25mXZlOG4XFVFBIfKC/TONccH0BWK9R92PQrgFAq0p2ba79AcCK5pHZXMsEDApbdxYSo9Jab00trIyx+W4eoheGy3YyYFn5dsvQEM/yxyCmfv6KSDiznjAqC8GQsymE3PequinmZbEZGxN7uTu/gX6J2K+fV3lLc0VQJlIv8PmQCb7777Hrc/HCqaE7blmj+JbPcSwLbqr3ZFIpkkU/UA3KcaHxGWNZXRssAXaOTKG1wtiJnyQ2VAffE2+yYxUaVLJQ== 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: From: Christoph Hellwig Replace BIO_NO_PAGE_REF with a BIO_PAGE_REFFED flag that has the inverted meaning is only set when a page reference has been acquired that needs to be released by bio_release_pages(). Signed-off-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #8) - Split out from another patch [hch]. - Don't default to BIO_PAGE_REFFED [hch]. ver #5) - Split from patch that uses iov_iter_extract_pages(). block/bio.c | 2 +- block/blk-map.c | 1 + fs/direct-io.c | 2 ++ fs/iomap/direct-io.c | 1 - include/linux/bio.h | 2 +- include/linux/blk_types.h | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index fd11614bba4d..4ff96a0e4091 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1190,7 +1190,6 @@ void bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter) bio->bi_io_vec = (struct bio_vec *)iter->bvec; bio->bi_iter.bi_bvec_done = iter->iov_offset; bio->bi_iter.bi_size = size; - bio_set_flag(bio, BIO_NO_PAGE_REF); bio_set_flag(bio, BIO_CLONED); } @@ -1335,6 +1334,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) return 0; } + bio_set_flag(bio, BIO_PAGE_REFFED); do { ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); diff --git a/block/blk-map.c b/block/blk-map.c index 9137d16cecdc..c77fdb1fbda7 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -281,6 +281,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { struct page **pages, *stack_pages[UIO_FASTIOV]; ssize_t bytes; diff --git a/fs/direct-io.c b/fs/direct-io.c index ab0d7ea89813..47b90c68b369 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -403,6 +403,8 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, bio->bi_end_io = dio_bio_end_aio; else bio->bi_end_io = dio_bio_end_io; + /* for now require references for all pages */ + bio_set_flag(bio, BIO_PAGE_REFFED); sdio->bio = bio; sdio->logical_offset_in_bio = sdio->cur_page_fs_offset; } diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 850fb9870c2f..ceeb0a183cea 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -202,7 +202,6 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - bio_set_flag(bio, BIO_NO_PAGE_REF); __bio_add_page(bio, page, len, 0); iomap_dio_submit_bio(iter, dio, bio, pos); } diff --git a/include/linux/bio.h b/include/linux/bio.h index d9d6df62ea57..b537d03377f0 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -488,7 +488,7 @@ void zero_fill_bio(struct bio *bio); static inline void bio_release_pages(struct bio *bio, bool mark_dirty) { - if (!bio_flagged(bio, BIO_NO_PAGE_REF)) + if (bio_flagged(bio, BIO_PAGE_REFFED)) __bio_release_pages(bio, mark_dirty); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 99be590f952f..7daa261f4f98 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -318,7 +318,7 @@ struct bio { * bio flags */ enum { - BIO_NO_PAGE_REF, /* don't put release vec pages */ + BIO_PAGE_REFFED, /* put pages in bio_release_pages() */ BIO_CLONED, /* doesn't own data */ BIO_BOUNCED, /* bio is a bounce bio */ BIO_QUIET, /* Make BIO Quiet */ From patchwork Wed Mar 15 16:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176344 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 F2C2FC7618D for ; Wed, 15 Mar 2023 16:36:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 796BA6B0088; Wed, 15 Mar 2023 12:36:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71F9A6B0089; Wed, 15 Mar 2023 12:36:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1216B008A; Wed, 15 Mar 2023 12:36:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4204E6B0088 for ; Wed, 15 Mar 2023 12:36:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EEA25C0FA3 for ; Wed, 15 Mar 2023 16:36:39 +0000 (UTC) X-FDA: 80571686118.21.302ED8B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id EAD2A16001F for ; Wed, 15 Mar 2023 16:36:37 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeTNWLHu; spf=pass (imf08.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=1678898198; 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=HEPrb4kIqMqW7eebyDDmobfSBttcdx5+yTOr0krGf5g=; b=liEcgau4p8t+mwUGuoaRedgxlmnzEgbJS9Vz3WDlJV3dVI6X1IfqyaxWRCo4Bsm9dZ9Q0r hCqPWfUvXP/oRKMJ0tgNQGt1EVAcp8ZU0eNUcjiESnRjlwifJ1wNxSQKUzUw1HcK/OK5ua GIqdQAZuRBcqNQdshoN5/4qayghjD00= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SeTNWLHu; spf=pass (imf08.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=1678898198; a=rsa-sha256; cv=none; b=V97d6ppYN/Hu1UWq2joI4QJPmgC3snSiAqez1iBOJxHC0cC0FYcQrAdjIbHLClrWjH08aa TJX27IPrSJXPZR76hcadJKyEVUHsHU0AJ1Fv3AFTpN1rre/HcWvjomZbevgygYyMmFaXEG r9p+1KZHLn01koRWhHA5Lv0SYd6m8eA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898197; 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=HEPrb4kIqMqW7eebyDDmobfSBttcdx5+yTOr0krGf5g=; b=SeTNWLHuXb3U+4tuTrMT4SqtNLRGP1zcVVGe7k9cfjERkphU1RJz7IK2ZDu+AE9h270v3Z 6dhQa4xVs1fPDOgHE09zbY1L22Y8I/tCu+iQf+u09XWkwqfo1i4etFcbUy6M55/RkoPlb8 adOCYBEld02KEQM5HC1k/eRg3My9nyM= 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-493-vcA44ovXN1e4qlJZz1bDQA-1; Wed, 15 Mar 2023 12:36:33 -0400 X-MC-Unique: vcA44ovXN1e4qlJZz1bDQA-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 6ED473814594; Wed, 15 Mar 2023 16:36:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54816400F4F; Wed, 15 Mar 2023 16:36:30 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 13/15] block: Add BIO_PAGE_PINNED and associated infrastructure Date: Wed, 15 Mar 2023 16:35:47 +0000 Message-Id: <20230315163549.295454-14-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: EAD2A16001F X-Stat-Signature: urudky8zejb3uej3r4wny5h5su6m1ig8 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678898197-492326 X-HE-Meta: U2FsdGVkX193BuErVpJrlnTkzTF6+QIeByew9gfCW+r8irIptvpwkRHw7YoKcOXO31VRUR3LqBU1Rf8yhY5agt1/zZhbWNmiydEJghpqJ3xg+xJ1I5N7gY5dKNenYm5kKKOU/S8+kOOsMz5SheALbjb+BivwsAnbLUBBdogsyywsV7y5xx2yzJ8npUvfNNcSY9McpQKl1DSOYdYWL2ZPh4vjf6UrGAxmj11Xgjz2vEllIDzrjjrmgzb82bWoXfJfq7l7wjWOSdH/aidsL6bidr8e49KpGacgQKkvi3/1HsMesJJA2h+05GDFAyX4Hb9MLRrZQpfKYJmU0JMc8jIF1atZq03ofoDar3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Pe0zlEd4dhatxtZVwkBoMxNirFuNDWPcqthzpW/16lSEBA== 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: Add BIO_PAGE_PINNED to indicate that the pages in a bio are pinned (FOLL_PIN) and that the pin will need removing. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #9) - Only consider pinning in bio_set_cleanup_mode(). Ref'ing pages in struct bio is going away. - page_put_unpin() is removed; call unpin_user_page() and put_page() directly. - Use bio_release_page() in __bio_release_pages(). - BIO_PAGE_PINNED and BIO_PAGE_REFFED can't both be set, so use if-else when testing both of them. ver #8) - Move the infrastructure to clean up pinned pages to this patch [hch]. - Put BIO_PAGE_PINNED before BIO_PAGE_REFFED as the latter should probably be removed at some point. FOLL_PIN can then be renumbered first. block/bio.c | 6 +++--- block/blk.h | 12 ++++++++++++ include/linux/bio.h | 3 ++- include/linux/blk_types.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 4ff96a0e4091..51ae957cc4b6 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1168,7 +1168,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty) bio_for_each_segment_all(bvec, bio, iter_all) { if (mark_dirty && !PageCompound(bvec->bv_page)) set_page_dirty_lock(bvec->bv_page); - put_page(bvec->bv_page); + bio_release_page(bio, bvec->bv_page); } } EXPORT_SYMBOL_GPL(__bio_release_pages); @@ -1488,8 +1488,8 @@ void bio_set_pages_dirty(struct bio *bio) * the BIO and re-dirty the pages in process context. * * It is expected that bio_check_pages_dirty() will wholly own the BIO from - * here on. It will run one put_page() against each page and will run one - * bio_put() against the BIO. + * here on. It will unpin each page and will run one bio_put() against the + * BIO. */ static void bio_dirty_fn(struct work_struct *work); diff --git a/block/blk.h b/block/blk.h index cc4e8873dfde..d65d96994a94 100644 --- a/block/blk.h +++ b/block/blk.h @@ -432,6 +432,18 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset, unsigned int max_sectors, bool *same_page); +/* + * Clean up a page appropriately, where the page may be pinned, may have a + * ref taken on it or neither. + */ +static inline void bio_release_page(struct bio *bio, struct page *page) +{ + if (bio_flagged(bio, BIO_PAGE_PINNED)) + unpin_user_page(page); + else if (bio_flagged(bio, BIO_PAGE_REFFED)) + put_page(page); +} + struct request_queue *blk_alloc_queue(int node_id); int disk_scan_partitions(struct gendisk *disk, fmode_t mode); diff --git a/include/linux/bio.h b/include/linux/bio.h index b537d03377f0..d8c30c791a9a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -488,7 +488,8 @@ void zero_fill_bio(struct bio *bio); static inline void bio_release_pages(struct bio *bio, bool mark_dirty) { - if (bio_flagged(bio, BIO_PAGE_REFFED)) + if (bio_flagged(bio, BIO_PAGE_REFFED) || + bio_flagged(bio, BIO_PAGE_PINNED)) __bio_release_pages(bio, mark_dirty); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 7daa261f4f98..a0e339ff3d09 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -318,6 +318,7 @@ struct bio { * bio flags */ enum { + BIO_PAGE_PINNED, /* Unpin pages in bio_release_pages() */ BIO_PAGE_REFFED, /* put pages in bio_release_pages() */ BIO_CLONED, /* doesn't own data */ BIO_BOUNCED, /* bio is a bounce bio */ From patchwork Wed Mar 15 16:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176345 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 2914DC61DA4 for ; Wed, 15 Mar 2023 16:36:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B40016B0075; Wed, 15 Mar 2023 12:36:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF07C6B0089; Wed, 15 Mar 2023 12:36:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B8616B008A; Wed, 15 Mar 2023 12:36:44 -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 882096B0075 for ; Wed, 15 Mar 2023 12:36:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 15286141149 for ; Wed, 15 Mar 2023 16:36:44 +0000 (UTC) X-FDA: 80571686328.04.496FB9E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 3133518001B for ; Wed, 15 Mar 2023 16:36:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HAwWi3tR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1678898202; 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=7b6tezcmsCRtrHxO2uDV+B0gtFM5s5ObrJQQe5H2QZI=; b=8ozYm8j+EY1POTiONJh2ewj0bNR9Gu/R4uoG/LsoOQZP+N3JItoR2mn4UDAbRcG1qdSU02 q/PORn3BDx3hL9prRM/Kqv7+HgAtqT4k8XWLCsn4hhIFFeXnsul5gceD6LCDfnvgJQeqb8 viYfTvDa1I2ijWeW1lepdlhFuu5X0yQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HAwWi3tR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1678898202; a=rsa-sha256; cv=none; b=zH/85OF25MYkFRWTtsyeBZ9EXADAnG/jQx5NC0e/BC0n9ST3SKYfFbu6IwkN/8HsBd2DRJ sUC8kX2BaYr9b2s43Qz4wUutgkxHlK9YkkCj1TH/4P+KYWa9VsTzRTsDuPplNKYzCltcR4 aFltStHEuGtrBnfTTx2nyy0+S+faUdk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898201; 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=7b6tezcmsCRtrHxO2uDV+B0gtFM5s5ObrJQQe5H2QZI=; b=HAwWi3tRb3H1uODIqQO+dtwF+RtpYnIuK6cYO/BFOcD7ay0dKJ1/12vS/jRGViFH+8RBNs 0DmRuUmxT2AndKVISX+Si5MGR8869a9FUEtOpXkprtpeZNeE/4+F1o0n4352Atrlo22chz rOxnNDNuzio/mwNq54Xv2GDQOcfZf6E= 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-166-eXTazPypPp6eK0h5OKSezQ-1; Wed, 15 Mar 2023 12:36:36 -0400 X-MC-Unique: eXTazPypPp6eK0h5OKSezQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40B00185A792; Wed, 15 Mar 2023 16:36:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22FDE2A68; Wed, 15 Mar 2023 16:36:33 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 14/15] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Wed, 15 Mar 2023 16:35:48 +0000 Message-Id: <20230315163549.295454-15-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3133518001B X-Stat-Signature: xahfos1faubxcp3p59dgh8mehnbsi8o5 X-HE-Tag: 1678898202-261353 X-HE-Meta: U2FsdGVkX1++DV9y859lAiXg4wpWY1fBsdux7DEjlO7gjne2eN0xGp50yD2HRGlVf4KHI0ggLVmwzkaqo+u916zYISR7g35qAFHUgUKIYTHFE6aOsTopwBvBAvUgwjh74BqSW+QTSHF0qGhq0PWStUwhMdQ+v7NZ49DQaNjy2mTAHPIIR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QfyfY+Uy3IooB0ps238ggAW6bZUm+jkNYWtVQ28UW7y87fRTepjLdeuiZviVTtRBjlb+UHteyrXZ/y5fUbSyfsTmNg5HGGVJ4aQKEVLjovZmnh33Ikjtt8DPjtm5lU8nA4AxUSh+BGGUpY+4Oo6M71im3THiqeaGZwdYxFapP6gb+y6x/U6fyV7u0OY9LFxCVdqNHbQB40GpNW223eydTWaNWOIEqV3jg== 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: 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 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 could otherwise end up being affected by/visible to the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/bio.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/bio.c b/block/bio.c index 51ae957cc4b6..fc98c1c723ca 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1204,7 +1204,7 @@ static int bio_iov_add_page(struct bio *bio, struct page *page, } if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1218,7 +1218,7 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, queue_max_zone_append_sectors(q), &same_page) != len) return -EINVAL; if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1229,10 +1229,10 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, * @bio: bio to add pages to * @iter: iov iterator describing the region to be mapped * - * Pins pages from *iter and appends them to @bio's bvec array. The - * pages will have to be released using put_page() when done. - * For multi-segment *iter, this function only adds pages from the - * next non-empty segment of the iov iterator. + * Extracts pages from *iter and appends them to @bio's bvec array. The pages + * 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. */ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { @@ -1264,9 +1264,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * result to ensure the bio's total size is correct. The remainder of * the iov data will be picked up in the next bio iteration. */ - size = iov_iter_get_pages(iter, pages, - UINT_MAX - bio->bi_iter.bi_size, - nr_pages, &offset, extraction_flags); + size = iov_iter_extract_pages(iter, &pages, + UINT_MAX - bio->bi_iter.bi_size, + nr_pages, extraction_flags, &offset); if (unlikely(size <= 0)) return size ? size : -EFAULT; @@ -1299,7 +1299,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) iov_iter_revert(iter, left); out: while (i < nr_pages) - put_page(pages[i++]); + bio_release_page(bio, pages[i++]); return ret; } @@ -1334,7 +1334,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) return 0; } - bio_set_flag(bio, BIO_PAGE_REFFED); + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); do { ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); From patchwork Wed Mar 15 16:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176346 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 F1954C7618D for ; Wed, 15 Mar 2023 16:36:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833416B0089; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E27C6B008A; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683986B008C; Wed, 15 Mar 2023 12:36:53 -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 57F326B0089 for ; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 00A70C081E for ; Wed, 15 Mar 2023 16:36:52 +0000 (UTC) X-FDA: 80571686664.15.CF67DC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 3E13D40027 for ; Wed, 15 Mar 2023 16:36:51 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P2AOPD+b; spf=pass (imf04.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=1678898211; 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=gIKMSgtKI0+T2jjDihR3uNZ9dKHoZzHE/RnqYef6EBU=; b=vt2uOWVgp5fKOHH8UEZ/PXCfiWtqqQ4S6Ax2mT6r+9cz3JUF5aeUAuWnkNNzTzIHM+b2xp hu+wpYm/D5cXQFBXS7AoD/z8oBlV/0rRIxYuLsDyZKzC6mNylv5hq0Iw0qpuE9AWJTK7BD T2jTqZHg1kGlg8YR3OwOrmRqvYp5vr4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P2AOPD+b; spf=pass (imf04.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=1678898211; a=rsa-sha256; cv=none; b=okSJ5Mtm2hssLX9f9rkJSYwjplqk1ICDJ011T3kIDHfUrG+awXLMlTSE8QtogQ4X5KAmAh Rw44eNSMR0lnmLNLHa6afg5+h34JYSYUbxqvzGFvsMTIikFGm+htaJKyKwYBl+OGo5hfFZ sl+NtENA7AJTtqSMYU3AHEfWGy1abCQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898210; 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=gIKMSgtKI0+T2jjDihR3uNZ9dKHoZzHE/RnqYef6EBU=; b=P2AOPD+bppm4Wo/8L6cSalSo3tl8nwERthPm3V6ZaZ8sVGOu8tDbyNhZhH2bj6c2TD1Dtg /ifMqHO/1bZa/RrvB6phZ5aRUljxPSCY+Q9x47q1IOZ2gRtgu2XGsigtoexTEnjUuXv/d2 Yq6r9S3D0jmmiu4V4MwOT6Rjf5FpOMU= 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-623-xwMSkeoeMNWvPvIQXGfjEA-1; Wed, 15 Mar 2023 12:36:47 -0400 X-MC-Unique: xwMSkeoeMNWvPvIQXGfjEA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02AAC88B7A7; Wed, 15 Mar 2023 16:36:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D85421121314; Wed, 15 Mar 2023 16:36:35 +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 , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v19 15/15] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Wed, 15 Mar 2023 16:35:49 +0000 Message-Id: <20230315163549.295454-16-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 3E13D40027 X-Stat-Signature: dtdtqa4wgi8qdn77hn9ayqug1ywcqkte X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678898211-714225 X-HE-Meta: U2FsdGVkX18qzlLUqb48AVX0xIe5UGKOuGPqYAcNQWDTAwMC/R06WEDM7MIMf7sZRg2S3bzmiui0Dciz4JiP4LCoe2EzQP6n7MJ9jW6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EtCI0CZakTbhxBBmlRdylddvGfbD9CwFzPhey7v7rBKLWIyTFTviPhTNPTScPgGiFd12K/oD+rrkEE5erpmdv3ExVhivnCueF22FSJR76K2WdwJjsaUC2yZ0tn9rSQvr6dW0Vwh0grz9FUcxUGtkQozFiivwBUWnIAgKVyVnCGN4cWiJaYMo/xgRMgck4ma9vleS0tMQRSTjAPpjFH2kR6pwzOKD9PBunfkpA1WaQWN8fYSE3LYjcSaNV9HUFtU019Beebi15tOHBb7u3QO9r+bXeYYNr/ryT0NVrLUuFEHIJd26mbOVxA== 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: 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 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 could otherwise end up being visible to/affected by the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/blk-map.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index c77fdb1fbda7..7b12f4bb4d4c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -280,22 +280,21 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); - bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { - struct page **pages, *stack_pages[UIO_FASTIOV]; + struct page *stack_pages[UIO_FASTIOV]; + struct page **pages = stack_pages; ssize_t bytes; size_t offs; int npages; - if (nr_vecs <= ARRAY_SIZE(stack_pages)) { - pages = stack_pages; - bytes = iov_iter_get_pages(iter, pages, LONG_MAX, - nr_vecs, &offs, extraction_flags); - } else { - bytes = iov_iter_get_pages_alloc(iter, &pages, - LONG_MAX, &offs, extraction_flags); - } + if (nr_vecs > ARRAY_SIZE(stack_pages)) + pages = NULL; + + bytes = iov_iter_extract_pages(iter, &pages, LONG_MAX, + nr_vecs, extraction_flags, &offs); if (unlikely(bytes <= 0)) { ret = bytes ? bytes : -EFAULT; goto out_unmap; @@ -317,7 +316,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (!bio_add_hw_page(rq->q, bio, page, n, offs, max_sectors, &same_page)) { if (same_page) - put_page(page); + bio_release_page(bio, page); break; } @@ -329,7 +328,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, * release the pages we didn't map into the bio, if any */ while (j < npages) - put_page(pages[j++]); + bio_release_page(bio, pages[j++]); if (pages != stack_pages) kvfree(pages); /* couldn't stuff something into bio? */