From patchwork Tue Mar 14 22:07: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: 13175044 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 5BE73C6FD1F for ; Tue, 14 Mar 2023 22:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE2D8E0002; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAE918E0003; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 927B08E0002; Tue, 14 Mar 2023 18:08:17 -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 82E476B0071 for ; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 56187A42B3 for ; Tue, 14 Mar 2023 22:08:17 +0000 (UTC) X-FDA: 80568893034.26.A083815 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8737D140008 for ; Tue, 14 Mar 2023 22:08:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GiNbBaSg; spf=pass (imf23.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=1678831694; 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=ic1+BPyUOtQ8yaTiYOoqjTBqrVBjWr4M+jQMTWsfAxBqJlNiS4k+Bd9ukmxrARXXJkmMAl CbB3foo4rmlhbimij44pDZpIDFkcy8+xeuS/tF+px1PyjRdzjk/if9pFpi1NMnAFJmBkPr 8t1oXBCsfBB3s6SMkUmMmbJT2TzDTzk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GiNbBaSg; spf=pass (imf23.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=1678831694; a=rsa-sha256; cv=none; b=zPU/pk1xMARoXTDfI1OBxShhJF0H9cyt+0TjhpTFRouC5u/8gcZyExQw6Q6wxikulFDHCE vEhCaEJ/g9tPF3TedrTaYVh0KosjeQOCGmZ0YuOSPAR/d7RARiZIafmhDIKihUvxc/FXFH hZ1G7eHwqwfezzA8wJeBhLmKbR7Tcmo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831693; 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=GiNbBaSghhcxzvdmL6iS8IcJZavYOXc/NxCR8hc7CocyipG82TM/pAbORFaQ/vpBu5+Nne yp07J2E1QydctJL83U5l5xuE3aUpPCKZKSFTi5CnA5/qcqEyfeTcOMw9P7/ywS9Yiwf8Rj 67MkCWP/+sIOKn8HdSar9DsWOIAUZ9g= 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-412-DdUmrbONMJOLxGdg1BeEdA-1; Tue, 14 Mar 2023 18:08:10 -0400 X-MC-Unique: DdUmrbONMJOLxGdg1BeEdA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1B623806702; Tue, 14 Mar 2023 22:08:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6B8840C6E67; Tue, 14 Mar 2023 22:08:07 +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 v18 01/15] splice: Clean up direct_splice_read() a bit Date: Tue, 14 Mar 2023 22:07:43 +0000 Message-Id: <20230314220757.3827941-2-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8737D140008 X-Stat-Signature: 9jfe934xxgptudupkf6sqgot8n1eyb3s X-Rspam-User: X-HE-Tag: 1678831694-833384 X-HE-Meta: U2FsdGVkX18oYjstf9lri1oibZOJvps9NgHHTVjgy0c6ysnZoUKX5bR7pXOogA2i8SKTp0ozIH78gTGrF0MarluMFdyOtBKTzv72n6C2rVpUPZQK4uIPKvn9hSXF4uW4jU5xikwErg308h/tlNsbYCtWzQVCs/PlEEBZCkJwBN6sI/hMERCvF+GLN9FQp/TSBgf9eB6o5FkJ0pgVG9hcqhlXbXmQsa9S87XLlssoETJmtdACWfqQEREORVhLdTrHU0PeAOIDSfBA9rvlBaxp/Er2zjF28aseHNHSrLFHO/qwZkYqCPMQkvIFYrxAJXHB8Sr38Gsw5x92M6GZlopnxMx2KYwJwpEmsbqAWFESiQODZvFBDLKj03vIBOnVQGRtt7t8CTiUfGvNBNxpZcB1Z/ML4APV1UAcgHcQrNKugEs/89OZYNSFrfC9AIVyHKlCbnNh14QeOH6B4sZ8M/sBPFqATNI9ki7qRFqTQ9yA2Zi1CasUmEr+WCaJxd+5qIDQmQGh5220xVKWJ8i9RUzvlHbOSMI0njqLg3WIP94B1EEDwJMkPOJ2/7mfCucbjcuRIZzhx64XXT/VfV6TW5bB/qo9xUmVgDWI4EUW7H6EO1Ij+IYmt8IHO7RgmDcWTtaaLKvFmAerAjlLwy890dJ6YqWWkn9Q2a74tiEB5oT7To6SsPh9ox7JRMI80xRExNa7lcRoOdFp5BhyCh+4y9YZJf/xCmSK0cQRpapT0k/I7GUOBPvPvd3HEyKLBFoulgMrfwkzsg1oecHb9nLLIBn3qNIdKxuENLskWEwL2qsrJU+qGozztNaslE0QcberNz9xb2T9t3LcGZsd7R4Fd+YHN/cybZL8kuUzWpQxpfEWAfChycL4b4AOiOn4BkvzfQh0c3aATg4CoKlGHNsIOvCqcQDQpm4DMSCxCu+RF71rl2sQXKi9bsRQ78NITFJgibHUSyZJGbv8DE7GQTccF9C 9vX/34XY q1rrhuEnptp119NHMQrmMNoiPQ5CrFP0bqjHUJO1uXuP/vleqvO+BR2sXIqJb/Ol0HZK2gXGyPJsIJ2tw+hk8ESpUHTpNN83YueKrFe7pmTLjLGMuCSCljfIWUD8q2QCjqgymii7NdDs5QjAMnjQ9YpI/AneAfDi0agHHXrJH2sjEJliDF58XCx0+WEBB4/98qjw0syMceMIeFik/bzAYCV4fQJuZThAxSNXcGsN+WycUwD0MuDqeREBKypyx2EyHPcKhNZGKANEbfOTl3k/44gLMPf6gS898Ql+iLpNKy/nmfo4gWroYsUG6DYR80vXYrruwFdQSVwiKUwN4Pbks6ZMdszafFHCaUKtjV00D0sDYWp+pKDRPwUr9rLd5yF4oz4LGwDAahgnbBfzIqCE018C3PCn8JLwjtXRUBgPLW2iKTejmqxUqCFMS1wRaNV91GWG9LhCPHVZpqXL+WtAmjGqNDZGQN9X0FYTqyD1JvmjaQddQtd3fXrikfw== 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 --- 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 Tue Mar 14 22:07: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: 13175045 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 3A53EC7618B for ; Tue, 14 Mar 2023 22:08:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4D636B0071; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C82698E0005; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5FF86B0078; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 95E896B0071 for ; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6825FA74E9 for ; Tue, 14 Mar 2023 22:08:17 +0000 (UTC) X-FDA: 80568893034.24.94DA537 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id B0C3F1C0005 for ; Tue, 14 Mar 2023 22:08:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pc5CipQn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1678831695; 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=h9YnNk1WbVJK9YcC17xQprtV/K7OFq1I8IxAE1tNpuuIJlDUG8d3LYT69oQFVEXEv1PZzr voWLz1Lj1LzNL053/3w9Z/YdwMR+RpR9SqqGenz1jxfkHurNGDsu/f7d4Q7D955xuPBkGZ VDl3qxIek1f8+z6Dh+PqcLSuv4PREDI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pc5CipQn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1678831695; a=rsa-sha256; cv=none; b=RU0tX05N4wNP4j+emgU1FrRLj77DspV+5cCV7K6pujjDezJBVpx2HYOFXiD1B/BlEUCHXs kvzQmiCPyhwddJHo4VgsHpY/2cKp0PknMA84407aa0wpse42UseJiROs5eBRnNmmKiirwA PZ/xaFGWcxe+0nsV13EC4MZB91aBoeE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831695; 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=Pc5CipQnKmUagsl6lG9tJGgx+vp/q3nZWEjzUWnRZbqvIzIjzMU9+Da1yZkWa0+B9l0lS/ HX8vzJDXWYh0/UsGB1IQpEdHVwbVM65WKVS+dHiQgs/bJU28/qVNDcDWa58JbdUrkwZDpn 57BrK+zGRLn3/e0RmJWP5kFjX79sRGY= 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-564-uckJpSsoOA-vkKCPnjkJ1Q-1; Tue, 14 Mar 2023 18:08:13 -0400 X-MC-Unique: uckJpSsoOA-vkKCPnjkJ1Q-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 DDFE73C10C69; Tue, 14 Mar 2023 22:08:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93A36400F4F; Tue, 14 Mar 2023 22:08:10 +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 v18 02/15] splice: Make do_splice_to() generic and export it Date: Tue, 14 Mar 2023 22:07:44 +0000 Message-Id: <20230314220757.3827941-3-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: B0C3F1C0005 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: iaai8yfo3nctnn664esin3rzwaonn9hb X-HE-Tag: 1678831695-117657 X-HE-Meta: U2FsdGVkX185gDHAPQeYPzLFH21tcxNFAoMaNeG6NwY7wqw+5EOtUXBstWy9JuZWVvqZf2UREhBpfMHQf+YYmj67CUOYm2K/kBHohPbtzn8VvYdH7JMH5HzfG+FKwmEpIqFWTeEsFc/GpZ/GPsqxNow/kJQTVzrSSVETO6jzw/u/Bi8lRVjYYJ6vMR8WOArvDcaow+l4vf7UuJsV2GEelTb9OeB0X1ibT9RC409TVacu/XVi15g4orRT0jinuEnYfAX49+n96+O/1RXEj3furBkQvA3xEEfTXlwK9uzTJVJQRrRP7ArqsywzBBG82mCZTo9YJEjiTcQr6HP7Jd2KKeus6tBJcK/BTldM3jkqmp1E+xjEKtbcH75rTD7KuQk216jUyzhHofHTwQor16W4lrhXZHrQuSVo2HJpp4yqPJUdfbH1+LS4txvUl04NHIdD1v8YfBkeQHAAhVRulKOpmIFzgklMZFJl7LbpehLr+thDfJ9Ac3b/jr9RDCa1SNCtVUWmCwARA/ZYFSLuiDuSh6uahmFhJafaCQjeTcY1Sz7Z4fe3a8IATXPLJmlAII7TcjmaRYcwjQSiDhLFJrT6B5x8uW2Fwpaj3c+80ulNd1RdaXdhHjYj7t4Z/vRvzJ2nFP3Ooz4Mtge6QaZbaEWWVr1ZFDybbzQv8san4aBJ23I5p03rv8EWyoi0E1griiMykm5HHrwECNNUe2hTuj/kJfHS6GKCpXU6JbII1LFwVnrD+2sc48AaxDXv4mSyro4VLDxmquQvlCZXdK0frdnmpakDcZiodDyJMdpMSDDb1Goi8fryNgaSQDw6GXIUw36bLWKhIG02+Mb5IgWzn/QSBdcsylHWMk+2MXSu4COqOyTrAu+uMwqikuxxvIIHdqDJ/9tIc8TqDfdZxLYpEtwYdNlSiS4GA8BJM+aGL551TiJhZWiJO2u99Eta64vdGA1CsnZ1xdw7jXmbHvodSBs F+GShaPa e/QpHa0T6Fzq3Y/wFVisA+JxrA0zXhtH0lkyUPtiOLtHdRjeqner3ffrw6M7hmOqLd1RnEmn8R/84jzeiNcfb5O0uhrEaHcWKEaUNPoeI0iS/WUyaMww4lbhpIfmS95KCylYvcvcSJnOvmUWqq/GRcTxBbqyAQlmfmgs9NP8TniEQtM8griejRfySQk2ryQtlLF/IzH/L2dUkJmqRkxTwiud9ZofmNesV2ir3FV0j3kvBnSSbQDEoQv/7O2lTfrC0RStI5DSK9LvTcvgbCpT+UAIC22XBWDJ6n+cksktQt8PgiqrWI8yHk8zDd/nFcQ+jFGOrGDh6N7evgT2mPIO7Eqhje7eOyc/OFYO5w8gUthONFy/qLPAPKVPWv93T9DfOJyTs6VcvxHw/UuuaRYLL+Qse2BZOdzkMgQj2Z1dl1M/v/OqNra/jXIcCssn2gcbkOWBG07x/2/vRNffijwiCwqKO9v/Kn0+t8dqUsmDvBxIInqSa9YuJA43/PdKsoVQ+rBLpgcqf80eWG3hYWHvpWj4B1A== 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: 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] --- 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 Tue Mar 14 22:07: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: 13175046 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 ADEBAC6FD1F for ; Tue, 14 Mar 2023 22:08:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4957D6B0075; Tue, 14 Mar 2023 18:08:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 445888E0003; Tue, 14 Mar 2023 18:08:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C01C6B007B; Tue, 14 Mar 2023 18:08:24 -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 1A86D6B0075 for ; Tue, 14 Mar 2023 18:08:24 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DED8B80412 for ; Tue, 14 Mar 2023 22:08:23 +0000 (UTC) X-FDA: 80568893286.04.988FECA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id AB2E418000B for ; Tue, 14 Mar 2023 22:08:20 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ar5bR6s7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1678831700; 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=heZSQWfJIKu8jtTOtaLdAQASJgWXT3zt4HqfOvFO50s=; b=WZ9k8T5QGrcY96ECnriTu1R9oE+Z2SMpLNwf38zQH9YUdCdDOo1YJw/1he+qgzwuyV418/ WIQdJkoNlO1/Fxi/ghdtikTIxhnOAVH5Jais03gRhZWY+JiD5UlQgtwEoPF9zGzgKg/zBb QVd2a377r2aEfyBOaHU+tp7CBd3n4EQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ar5bR6s7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1678831700; a=rsa-sha256; cv=none; b=xl7qHm186x5oFwMiM6JBZPcrKzy+fJRqtK6T7GTaCo32lq0oXfByZDVuQwGcI6TLRQyrxJ iPFok6brW2OGQKXiifDMgQQZKE46PkDjmzk/5YTmE7Ld79H5gk2RgU15hT1t1M7zjOHPHk cwZPsqtvf7RMGjeKYBT2raDG3Xhvh5g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831700; 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=heZSQWfJIKu8jtTOtaLdAQASJgWXT3zt4HqfOvFO50s=; b=Ar5bR6s7ik99XYj8s+PdTXsqJdsi8VCq6201WsWhvNoFiqv6LxMnK6n8Y35sdXF00Zffuf 5VVauLqrddH4N3Hhe8ih7BgTuKFX3pmdIFE6u0i2z8lDjm1xK3VTzYK+x8dSEJi5RaLywQ SxNpZBX2W1F4098+1FHhoVN7B2Tcm8o= 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-640-z5OC_9_mMIaJCG3_XEaAYw-1; Tue, 14 Mar 2023 18:08:16 -0400 X-MC-Unique: z5OC_9_mMIaJCG3_XEaAYw-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 EBBA5802C18; Tue, 14 Mar 2023 22:08:15 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8126C51FF; Tue, 14 Mar 2023 22:08:13 +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 v18 03/15] shmem: Implement splice-read Date: Tue, 14 Mar 2023 22:07:45 +0000 Message-Id: <20230314220757.3827941-4-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-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: AB2E418000B X-Stat-Signature: zzmhzwik6cqb1ag1jbjdk1rrrdniij57 X-HE-Tag: 1678831700-661419 X-HE-Meta: U2FsdGVkX1/VSzOBNBJIrM9YufexWss70NbQwStgcDrdntgGmoCyMByNAxWO+0eu7+sVocGEX+xj3ogWudQ6HUrnmuGbhdVg0NqBt5dOY1xs6KRM2rnj91dqD3M5FxNsDMdP+2/9CHunILTXOUMpk/gUy5AdV/tDCGU+YW3EGEAnmCboq0WXa8xa3QdFisGpOJWXqc1L+qdFgR9S/+93EiCl4s9Enys6ow8CmI9s7beaT07qrSHlZm6Uaxy/Oq+BDeDsDh8inSP9ihF18QUCFEd85+Qyv0ioDEx8k99E1UWfOyANshIC9aEzdYhUdHBC0gX4shm2qZSQQf1XXdrVQjyLhvSHlG3uVIZFvtDKqzHMPvP9XSsNuNH6APUsa8ccKEMJO7jh9Fatv0T3hhFMP9PCxXMaRp1Hiwcl2pOG0HNxrVBxPfnUugzZsDbFPST9FpOJH83nZJ/TkJ+zr/b5M7vRjgYZwftpj1ErlO2FCSXBW9JUTVSuvYaLX3qLyLJMyj94qo5X/xYbcNkiWz0Dhf6FZTggh4Hmotc4Rk/ZMQLly5q4Ib/Mne6wFzh07FXP98o5BpqU4dA7WcHXfeLGuoyImXSBuiSt+pFUIZ0xTTMXYT9+FmnFmqPLSaIKLdMG13xP7qB5wzTSO6QO6G3VumTWPWOz12VkIzV/6L7yzuAC7bfxYpyKUAqWfAoCKf1XcoKtWjwuBNGyD9rvavumj6lSo9mq69I2c/7eYRDUFjiTYfAuHe9RuT78J2vEPoD5mlhPGucZQBihg/5iZIKzWpgdMFwjmK7Orp5xRpAD9AqOuqojQnJWVRKk3wxJheOA/aKlDXuJmPxVab5M88Urca4rLy/S9QNBY4UQ2RtBuhZTqZnCEERp2Z1l1ZQPSyC5QWgBK04ievDEG6GvCaaYhp5d0+KmCuoTVx1MlusjEL3DyLtcujOrkL3gwG28kZTffcHwN36eXAirJiZQ13N Ymtz2+M3 VrBrfvbUguneL/+kYsmZKEVjIZfhGgD6GWxg1uznRe0q68w6k/expomTmqTV4Q6ETHc4pxa7pUZb6ERXAtTk3xWNxz0pZCABmACAmArMtTOU8NVu8lxt7YZPVB4X6kE6RGgkAg/tx52fCQac7tnv3TiMsVL2Wu9P+z1NnRfZgNqQd+7uNqcl4gnZD7Cnttg+YxQUB9bceQawM6KCLRuvLMeg/wB+Dl08WhU0xvyO24Z8s8FzorH1jBnlbY+ClTw3wjd+QUGwTfpL7NFrv6fPUHzyUipB2p1DyNhnuHtFUIO5H7u5O80C/LI86EWtALqOCIsbUtyMSqrQNNOpPohHeEuJ8DnN/viVFnEWGCAnpokZl/4lkxbI+qR/eN1uDAxskW1HJfRj5P+W6SV/S8aHR2tAaLSNFp9cNgr0AmVGTojuIbIij+x4LWRKh33AesVXvKhK/LpLc6r43Zi5oa8+USPe++ipdHx+oPYCq+GoOIJhMJ0jLhk/c5urp2T+voxUpjHYAwFkMB/SNFthKAJW1NLmBQAfpIWrOoSlVO749IXTdwc2SF1W2Euq/Cg== 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 #18) - Don't take/release a ref on the zero page. mm/shmem.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..d9b60ab556fe 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2719,6 +2719,139 @@ 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, + }; + get_page(buf->page); + 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 +4071,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 Tue Mar 14 22:07: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: 13175047 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 9038EC7618B for ; Tue, 14 Mar 2023 22:08:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24C128E0005; Tue, 14 Mar 2023 18:08:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FE288E0003; Tue, 14 Mar 2023 18:08:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04E648E0005; Tue, 14 Mar 2023 18:08:25 -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 E6CF48E0003 for ; Tue, 14 Mar 2023 18:08:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9A28A160E0D for ; Tue, 14 Mar 2023 22:08:25 +0000 (UTC) X-FDA: 80568893370.17.44CE238 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id E451B40014 for ; Tue, 14 Mar 2023 22:08:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eG6ejL6M; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1678831703; 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=x6T/VFwqZCZhXGUjG9IKv0jR22f9aMgpSQxHJhZ/aiNJdGwFXl+lPNNicnLmynCJOT22YT 3ZWZHoSwKjvdY+/w1GG4wNfkwI5z7ayfbKzEOhoHDRsGwDY6kG/fhu3zLba5+qNVyySPik j3BpJiX4fG0opUD+4c8fuOVEdtnVEu0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eG6ejL6M; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1678831703; a=rsa-sha256; cv=none; b=stfdLkm0nkd0nsoqCXI2aJBux1n5fSOJ9MPGnm0b+GTsxDbERYLN4XBQB1SzVVTQRdWctK 43LGqCqHaV7y8ZmZy7nr18e9+6lflmJubdCGe+VE5ZHF16kgnpCaymmgGvp77e30OFna9K uF2gnGqbqQ6amtofjT/q6irkuOrjjsU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831703; 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=eG6ejL6MxEJrZU/a70OVDPXbUjEFK0vJK9NbZmX1dG7gtMEcIhPUDANpZ7FQCLkfWWzkui 6n5IDXXywLzyD58+t18fY5dwNtsH/hKaDIkXiHeV/FqoRT78qC0Dx6ot0OJKlP6ct2J+O2 GyrKFfvnIeC6JoJ6yNmgmwXli5UPNwg= 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-482-OmsvrtS9MnWFP7mBkgbzgQ-1; Tue, 14 Mar 2023 18:08:20 -0400 X-MC-Unique: OmsvrtS9MnWFP7mBkgbzgQ-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 15FA9811E6E; Tue, 14 Mar 2023 22:08:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B11D347507A; Tue, 14 Mar 2023 22:08:16 +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 v18 04/15] overlayfs: Implement splice-read Date: Tue, 14 Mar 2023 22:07:46 +0000 Message-Id: <20230314220757.3827941-5-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-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: rspam02 X-Rspamd-Queue-Id: E451B40014 X-Stat-Signature: askwbjo3omxx3ky7hkasncgwrewq8tz7 X-HE-Tag: 1678831703-92276 X-HE-Meta: U2FsdGVkX18upqDQWPVLTQXSpmXdlToASvdr84q9lZZmtC9rCy3lZ8urv+ORxgawxjjNPZSoTbfrP6twsrTCMhKDIydpNsStOdmc/qIpWajcuZYBxPwGTRm5epQfyQb7c6hUAsY4a88sidrPJtcJw+d9iJUEOhrq87K78Sy/mKW4Ofoz1znsIW+j5CfTlMlMyMRTzABMUWUUK5/BxY5wDa6Kiqfm9AXcUoSHSZOYbKlMVWmU/ydD/uaQ5ZsLzFL6e9zdwBJ8JTZIfxD0I/7Wr266kIW3t/KbDgzw0AYykRpeXqpDGgi2bfnxuk2hKiXZF9UncK64oH1RNktKzfBvtPnJBKAT43R7U3XdqP/Jzv2PMgb3H4W5tGjj1mWwB5fIFl7orGTM4KCcJpT+mCvRSADu8yCk0STNPTST5TnVq6G3Bcmn1uherT5Izf749wUAueZhX6A239eTC6CO+MqX61/gjBQFFpZB4y5cr4wSKX3Q1aMKJl+0S6HPM5t0VqsFVUb/biPoWlKXB6A9eCpBeXoGQ6i/5oY2iEe4ZuyqXg8P8XW8L7/Zz5FkTDCOvuFkbLZl65g9S/jE+FX5/ULuFwar4y2ojCG9xYmZ/75s/nXMvfMG4s4MDq0ILLDUSi0bdG8hj4zX722aWcDE/0cN7hoWJCNfSYlolcp+MCcVQSkUWjpvfkdTL1NrU0Zm9QymPbLfgfze02smetYz0mU2DBzcoGA5fmmvZXoTEIcZrUz6rDuHNVR5KrRfHkXuTfGpH4jFToaNzIbXgftoJTg0IwzUoY9UYSFStH/vNxVZzgG6z9scuUEnekwnEcF+sEjyqlw1uSLUuHHL/o+HiSnEnzuVBlHY4O3PwqJECjP1xpV5VpzISbN2TpqsvS3J5A/qdlwBJ9ugRWDJn4csVPoaa5VlxgXMb5Wdg3tNDyYErvjbHIKdwmmZuw397O9actMTDFSwq7lc+piFFlAB1F2 1mR7VNkg blutZupqXidEWmhyi2hFNNt49HEqTKtigL4TcPCnhcv842aDG1OE/Qp3IhVbIptEy7kp9SdOUyKy3vbWkbOjR4y8HT+OQTIeeNHqhPAe5/qZ1A0Eh3LqU0rhV+1eSxG2fXh4USTRl+SVO5fj9RbMWa6/EqPqDEN6eivJvQikQRHs/cwhpog5Ei0yY32wagRl1zkSKLvNPDnI0RavvD0aPjSWfUF7brHvCL5YayGlxDVcqZR3DUTLhiurqcVMS13Uf6DOTIWXCUgRhkXT2TVbZqZWhG8v5WPWRQ7QjFT5fEme2iSY1JyeOFC60zEXzUvf79GXhMoRrSeVTlLVxvB0WOqkGxlgX93/geesu542xJCkZUtLu0SYm9Jbc7I5U5Q/48ij3R1DasyHRhFvRH1b6iU/ulgEuPjmOoFZYg8G6/pB/bXXPUwSTFB7vLa428v9/dAUB 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 --- 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 Tue Mar 14 22:07: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: 13175049 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 04D5DC7618D for ; Tue, 14 Mar 2023 22:08:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 496E28E0007; Tue, 14 Mar 2023 18:08:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 448B18E0003; Tue, 14 Mar 2023 18:08:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19CA48E0007; Tue, 14 Mar 2023 18:08:31 -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 0230C8E0003 for ; Tue, 14 Mar 2023 18:08:31 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D3D3CA74E9 for ; Tue, 14 Mar 2023 22:08:30 +0000 (UTC) X-FDA: 80568893580.02.AF5C671 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 34328A0004 for ; Tue, 14 Mar 2023 22:08:29 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NGglUErH; spf=pass (imf15.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=1678831709; 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=nHNy4nJmQ/a4IoNX2QKH+L39mDVFpf5RihnjQdBGf3dRrNxD/dijAN+muv3j6a0QSvRy3T 3tBDD5OffdVjA7ialu6X4rTvpUqAeW3PHlgw5c10oGKin7jUutc7f3qXA6FX1SoZjIvoIp 9H+mAnHpXpQsdPdyWsknYavE+70mRmM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NGglUErH; spf=pass (imf15.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=1678831709; a=rsa-sha256; cv=none; b=lY3E+7g0dVBeOeY3ASdKlI8raY/jjzBbfEUqCike9n8xi77+ZDMWQ71fZNZIebeZyn2BGk Q4kYUxWLLt9eMj7/b5zHoMWz6AHtVwlsZmRtPmfw9VpzVOt5XVhLh2u9LA+Yq9cArjCdok zchnUoYOHhc17RdWsDd654BeEySLHlY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831708; 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=NGglUErH5fcSEvmD9vw9W/isAS1FhkxYEGh5+SdoHN9pDUhVGvsUCHGxmg2tfVLhpOsEo6 pZYbztVsYUUjw5oHD5asoHi1NQPtprj0XEscnIt2iHSgbNRP9qeASB7GNcEamHJVAQ9Hda m+4JtBwug1Un5Y0FszBTl6Z+BBRUzQg= 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-355-ou2O4Fm_MEqdgyGyXimoSw-1; Tue, 14 Mar 2023 18:08:25 -0400 X-MC-Unique: ou2O4Fm_MEqdgyGyXimoSw-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 538CA85D060; Tue, 14 Mar 2023 22:08:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD5082166B26; Tue, 14 Mar 2023 22:08:19 +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 v18 05/15] coda: Implement splice-read Date: Tue, 14 Mar 2023 22:07:47 +0000 Message-Id: <20230314220757.3827941-6-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: om8pm8ig7tqznqfh8774rhfifudrzygb X-Rspamd-Queue-Id: 34328A0004 X-HE-Tag: 1678831709-684405 X-HE-Meta: U2FsdGVkX1+dMK+M2WxuMTMhwkBuvDMBoN2KVSNj2w8a/Zi3BnSFJTCLTbYrnme4Mtl7i3ATt/YEiqjorfuW1Nx+LGmyEzl3pjm1GfFiLzca6SjP5//l1ZpPyQfOaky/uuxBY/mMMXksykzeXllr+OZP5Ca60yRZtazBzs0j9yRvKPRwoeYSSr+UPSml7KlA+wWrASgEr/o4Do2CyeYiWNehjZELh1wnUWjj0rePz84PGC4rvgIvFNgjPRxE/v+cx/GUw7gs+BDR0LW+ERXUOlFC29YR87Onkr4M1jz/fZFhK+3Gb+b0Wu95Vt6GeHsj2nxFiwkbHkX8cSvdFsEkCr+YcSwGzv3HKaz8ulV3nb+HcCcVBHncc448tNvF5u7neso04ypDxyklJax02BmemPt8Sy5RTcCPZL4O8DK55nxKPXRCmkI6zRfw4zuMLKSQQF1cN1Zn1ljn48nfMMv5PLzLcWJlxjAJjY8JlkGmq6hiLobxA1bPGOgE8WCJZuyWa7Qm2IJIRe1NgUZpQrOhOD7nty6xz5M34l8xQurmI4d0B9tcUJyiS5As0c5zTAmB2OgKQWJCfUh5+9gZUTMyw1ZI6K94zOhYozuvovI5qhC/3aVfMArMlHUO5cc/sd0TNFHfF3tWAQXsO/yss+9Dmn4noSDuhq0C/7zWU1SWqhT0QyEzfgyi0dNwhzaqEQ1Wf3nn4qv6xpcHix5CqZ19dpjrGInTL/r/yPjWdMleBCRkATd7YaILA5mzWvewFKmVcaKadWcAyaiVR5MgNF3lcWIGS+g5C22/59rC9EcDyYHEIkr8DbRpOyWLYFC7ZrAP1GrsgkbGsC9xsN+LCE1x6nQGFu7Y/ODpUZmRIFNLSBFJy11CGGurfwgfVWNqlC9RfwO0fgi4xpKrq7yTfAw7vjzM5JkGBD0Yr5V4Mnn+U/OJ8H4TBSa4Ozz2G65+UotZ9Pjrw9Ymt4+obrcXfq5 pwOtG5zo 6cWKjgj3y4MYzyQf4qmf61OUPKcRauV9orayDLJOExEMn/Yj8RbctdojozDgqz9CmjlrrfKTbkT9cS2iRnIl8jxYE5Kj2tjOMi1OYyUTYBl2Q39oY5X57TrgMD9D71xY1/+B7xUeMeusE1HZM49fi9FNYOZbqp93JVNxGXOQfqs+oYTfG+RISMy08h6vRaMG0csHEiAT2VO53syz58PduODj2gPDLng//FK9oVIAtL7ACQosXEncbRtBm7CMCarx1YN9LUxm/b0cOpIqQ4BxALbk3ekobEmQd6eM7LvMwlNhFb19Pa/kcm8gKOv4c0CV8W+BDJ7CgDf1xdwLZQw4GOcYMncn3iZP7N3I1cFAqGPDsYUS0dcNmYRLZ4uwFzjnf/2tN659cy8SQSHOOiqQiqua8eeE/+uFohwUeuimmvd8JDU8yBC0KLoVmqz0iY4Oj0J7J 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 Tue Mar 14 22:07: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: 13175048 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 C563CC76195 for ; Tue, 14 Mar 2023 22:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F4AA8E0006; Tue, 14 Mar 2023 18:08:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A4EB8E0003; Tue, 14 Mar 2023 18:08:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 447758E0006; Tue, 14 Mar 2023 18:08:30 -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 2FA608E0003 for ; Tue, 14 Mar 2023 18:08:30 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F2695C06C4 for ; Tue, 14 Mar 2023 22:08:29 +0000 (UTC) X-FDA: 80568893538.11.4C8624E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 446AC10000E for ; Tue, 14 Mar 2023 22:08:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CCFHBplS; spf=pass (imf05.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=1678831708; 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=1SUMrhxj01iyjS3t+GwH6HEFu7W3nIouk0kNOO4v00+4pW0Hu22wwrRgiqw3L5IaLezN6M xxUkzlIYNUplrRQY9TWPd/yvkU0Nv1OwScW2y1698c3+jB4ETQ8BbE5OxBmT+JaT9WbWX8 T/akhE49HAsww9NuvWmnSlqvrLr6Ff4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CCFHBplS; spf=pass (imf05.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=1678831708; a=rsa-sha256; cv=none; b=hPhkqKlruJja38bjVF+BtOG9fpv9dgJ++Wpt8QcDKqWp2yaWbDiabJLB5YTXzuzefF1EaH bqfSvrSMFb61TzA0MD9wNgMFlADiQ87K0O0856A/KVLN7RgMTy8VUBdPxB/YJH51rAfO7h vf05NwLg+/5Ya2t1yr7uR7zFJ7MCDWI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831707; 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=CCFHBplSNDfd9s6efdfhDp03DZhRPgKUennMSet8vHtU1LYr441XCr1Y/yEEfWzWrYB1aB QqHvydJ4h3z0M6zvNRlYGDynY023wAfRzzhoVa1t5qMWxlLR4DnH5ippXHqiHb9smKcWhG niTud3hFIsrj+ZRAWUcVLLacOuL9jqY= 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-664-YVi37OcXM4WmpK94EDl53A-1; Tue, 14 Mar 2023 18:08:26 -0400 X-MC-Unique: YVi37OcXM4WmpK94EDl53A-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 78AEC802D2A; Tue, 14 Mar 2023 22:08:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 144332166B26; Tue, 14 Mar 2023 22:08:22 +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 v18 06/15] tty, proc, kernfs, random: Use direct_splice_read() Date: Tue, 14 Mar 2023 22:07:48 +0000 Message-Id: <20230314220757.3827941-7-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 446AC10000E X-Stat-Signature: pdir393gzyhzz36pawf9b6btjebong6e X-HE-Tag: 1678831708-507944 X-HE-Meta: U2FsdGVkX1+OfJPJPAxXfqKTWeO9vyosMqRwaduu4Q9feHoAFumV5VjLWyzZxSU99Ph9j3mgxyZTLJkG97I6Mi9RAjyq3qEwZZLndKqtD8/vyoTlOY9mSmQq9AjeS763oG+pIS97sLi3z1MEz5vIhKEMxHCqqz1WcHUDcURVCaRjSOyy44rGcZasD7bhi0o6wXNWMbVpW8ieNmSOCTESFYLNqhY+yfaM5pJGO+DHQbLQTulN2/67wjEiOUyNblFo0iQNoal+413NkzON+yLVWJjIXMbV4Hw6D410bzZAe1bFPSL2XlrRr16r0S9Wm8/HitDqkIgrF/PhJagNOWjGGcMO4n3kZFdGz24Htq6kpcPpmNw0e05vHZQMVUCgYMu7eE2rkg3V6dkoLAASgBtqZAcSTAZFTmmykHu8o0QHlEWLvH7tOUKKxafT47zraAcMG6p0ogRJW0eMeD4Y30r0Y+2cVMPC5xDUseDdlY23a8StKfED8wVaBjZon6lNq+LvJ7IOySmOS+eT1GOjEQG4+6w3VWcU+YyJtnHUfzCBHsAn9sjKfNCoI9+sI9rD8HS6NKhrZ+J2KEsPHnjBFsDeXMOX+K8xc1Fv8rOPmE1VSQMsyatd6xJP1WyLc59EUsS9PcpgPiqicjJFcx6BdvwdS9koSdxnDRnLYPpDOv7FDXGY9smIXTyMeQr6PmfFwWff+s/1qRVOICjaWqSoyEKJsO2gSRXT1oPdjDLRrvShXleJ8jvxiA1BN2JvFZRvjGq6ra38p+4QJgylQvK+HLpQzJJGH7z10ytkiDlS/qsXP2xnCnTzXmz/wvbB8tN5bKivbaYjAkqhKzMTBOAJiYWMsUArAXPVLfThQHL8R0JdCHV3Mq/WRLfWvVU6mGLzRu9iIJNgnUJMqW7OFtBJVscTSIn9oZS9Dvfrsf8Wbe+JZrJ7PDbKc3Kqo4A1C4TO5HOjiw+44mXwp8bfq941y3I 0DeDvMwA p/7zDS7lEsUF+00JEzIbLYZeGLb8Vem20wSG9cMeLf/g6P/XG4KvmYuKXBi4De4kiDE4C1WrBX5u80xr0/2Gzlju8ApGVbBBpL6yIaBYSFTbh//Zq/ZwrERMZy3eSY2KYeLiIqICBSyz4jJZCNj8IRdU1IKIVaeAxepdxiCFI7xbyAvUaN1oYAS/n8l9tFA115wRDbXsh3ekCtkuvjO0Rrsti7z6W4jPcI+vXPEkSBR5Tw1E6FyH3YnwVRXPKIgzk6TJzyFSx+6YeyrwwbvajP/3EKApfMXlyh7ZcBS++PClmytpfw0rQLKJvqxhLHdsrLq/uBH/GsMnw9VDI6JNJBYZRKefFsEBQqwaZMdk3RtX6JikcB2x5IFy/jHU2YrN8KTfU0YjEIPkrhCaZvZe2usskyYSLk399AQkW0o3qZ/Gz4u+u2zwSJ3Z7YywW3igISHhn+LPCzTRrR+ZGHDtbv2ygdOGHYcytPN3hUN28T+jRvSfWZ8aSyk4XQtoiQ39Ssj/y84zLhEIPUshtwS55VCY9tnuZXkPvQooygpk7JAdQt+DR5W953YIGTQ== 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 Tue Mar 14 22:07: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: 13175050 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 39353C7618B for ; Tue, 14 Mar 2023 22:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C84828E0008; Tue, 14 Mar 2023 18:08:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C348A8E0003; Tue, 14 Mar 2023 18:08:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD5908E0008; Tue, 14 Mar 2023 18:08:37 -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 9D89D8E0003 for ; Tue, 14 Mar 2023 18:08:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6169B1C5EF1 for ; Tue, 14 Mar 2023 22:08:37 +0000 (UTC) X-FDA: 80568893874.09.4B252CB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 8E1B640002 for ; Tue, 14 Mar 2023 22:08:35 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iAWWcarj; spf=pass (imf01.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=1678831715; a=rsa-sha256; cv=none; b=Az+8R/edc23u9McaYPFDuWUp//4AtP7QBoVcapw+6cCiroiMrVjbFyj5WqawBw3sGhkRzT FnBfIV2u5pIxbQ/b36GnWLRNLhAsEFURSWT8bb8eu6T7uEbxygF2Fmsti0MD0VjLDS4I86 0S9zCc8F8cOj2VyAKPavyjdPGjd2hlk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iAWWcarj; spf=pass (imf01.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=1678831715; 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=zUs5GvOuAJgClT7x7fY/o7luIn6OzemHKj4dHTJyIzS1ul2MO9z5Tw6jKIt29EUf1jC7G/ r8zXWw6mn33zsE7Swc0t6kNebN6WfqMRgnJrr4yKiVvb3E1ogUHNz1lLStFrA5pYfWV77d 5CSXpWa74bX5QSVfMbimaP/qaSbuyXE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831714; 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=iAWWcarjZGORj1XpTrs7WLkU66Wn02dGKlo5PTlXGVjAdzAsofefD1xWo2OBQtOQC7bBX6 X6Uil+99G8eTLlui2H6BmTKJm1oIki8ZNdChyFbLpLwzJr972u1O6CmmSmbsNdvcEprXtB KtyG0/7t2phJ4M8jObdASNgJy//9M9E= 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-607-yinWqeU4PtWbq9L6irR4zQ-1; Tue, 14 Mar 2023 18:08:29 -0400 X-MC-Unique: yinWqeU4PtWbq9L6irR4zQ-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 6700D85A5A3; Tue, 14 Mar 2023 22:08:28 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B9EAC164E7; Tue, 14 Mar 2023 22:08:26 +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 v18 07/15] splice: Do splice read from a file without using ITER_PIPE Date: Tue, 14 Mar 2023 22:07:49 +0000 Message-Id: <20230314220757.3827941-8-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: 8E1B640002 X-Rspamd-Server: rspam01 X-Stat-Signature: 6ackccq6txusxj481wpha45quwmez64c X-HE-Tag: 1678831715-906463 X-HE-Meta: U2FsdGVkX19XBQLicr5uGDgk4FuLMvkM/5jaL2AuOUAZ0+l4eup6OVkA5T1d95HZx7TSj4VZQAliWQHscj9Omv5R13DW/RYXJ8FbPEZMziKO54jPn/DCXOn+VwWFbAQxhangVDa/jDbnXjGgnMWX1w3bTdFJ0vGlYicCG9XmPFwkDiK8xixpsKUMkGZ/OyfOp3FzFKXBeTlftQqheSebutDBsE8ljXd483Dsku5oZan43gp1h9pQ/0yVr4AhVgq1uFgDjNvGCV+EFy9AlQHX/QxNEH0yIYzLH5BGmvG0OwDXZHq2vnQvkc9ocb5Z35UJDr59hlyx9+c4q8nzyG5oB83CmBFwnxR7RTb05AeOeTs3CKAhqgxvJLZvIptH0RHu8h2CqBRqvqYkrhxYzHI3DtYpVJqJwQ4amY6GpNQaz0lI6bJNnsVjsMIXbRNu2p1fvVq+DeBMx2wippRmhQQEQX9QHWMro8z31knTarBMFD9wR7bqwyfUkI1vLBLEXn2O2TLj/YuhhxC4zr6nxq2rGTzTobz5eqTovrbGAAi6/Pvj23e3KMqkF7LB0IEQoIudcf+orovZDwWM1m5kqa8jp2qpmXitPiLQ6ZllVzqVrNKeGZ3zTbTyo7hLgKoxnZiNtlZJ2Mnx2cecpj9fnmLLQOxPM8vpplvDl9/TXTj5A6XX0CYZDO3KanNQUavXcBI4sO8Y0ypJPe9vx2Dv9jntWastj3OMwj/Emrsc9CwDMUOmbnFbEQ4MQ33899thvi7hUrDOvvm/V8At87J+yMAUY6pR/fxbiHJluyK5S80ZWIqWnXB0YEUp56v6ETPEguNhqjiy3cx7GIdAOfLoCue3s2Zvp5WfoWbTmPnCqbwLYU69kcKYWzgWQfcQs0EywPF1WOSHSKzbMhtjnH73cUFle4+dVG30gjgvlERN3cP8AwXYippDs3mDRp9byjpxCBPe/2f82N9Q73ChtEK2C5A ViJ5OM2H JSa9W5QDU0rhWlry5ijraMQybglOtR350R7Vw/TWoCXfeGGn+mnYSCH9GOX1VR7dXy2H7D5CCGc4X0y7nlQQWfhV6cMxCuJRcQdRL25bhua0G0UxuklUysL+ezbjfPwF+pLpoX2HrySQyRJty4NAncD6CZCN6ttuFeeSYnkuqGRVWt8bmdVWjmK4LOUdR0ghPidZRSuCoq1QqNN9YtSwbARBjRUHuRpKLjX3sA8K1KLqw1lDP59sjV0D5CZztwkiBV9UUPgZumuYkEGEP675I82QF7UhwxgEW8Krhw+QfQOzneO9I5cjde49VnBqS2lhm38jDRvHpMmJbkz0miRcFF0h0Oag5rIMc6kLDZ6s/P9UDWviDd/3DX3a4gVcVKffZgAc1jzdQuJdrlDzIhtYMXYpfH3sdTx+YaNoxkM+nR1rz8/LjyWl0TI8eKHEHc2JVw1AOeBKkyrsRZoR74DCFp6XWM1KG3gcXO4ZbBH8Q2wCNIiLb+a73SF/Q7WT6d961a8yvB7GXnlHTQRgPRjrDu23MJg== 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 --- 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 Tue Mar 14 22:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175051 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 464A7C6FD1D for ; Tue, 14 Mar 2023 22:08:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB17E8E0009; Tue, 14 Mar 2023 18:08:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3A7A8E0003; Tue, 14 Mar 2023 18:08:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 865618E0009; Tue, 14 Mar 2023 18:08: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 6B9858E0003 for ; Tue, 14 Mar 2023 18:08:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3CAC880309 for ; Tue, 14 Mar 2023 22:08:38 +0000 (UTC) X-FDA: 80568893916.01.0B37DBB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 5010A1C0006 for ; Tue, 14 Mar 2023 22:08:36 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DuoRCLgW; spf=pass (imf20.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=1678831716; a=rsa-sha256; cv=none; b=WY2nEZFdxQ0zaMuZqMJtCUEnGUmSm6ZaBtGQpYkMq/QiobAQtWvhlzYIUcu0byGUyackpw v/ktc9S4i4PvUYebCiD03Cxq0HFXJwO+3+6BCo21wWe7p7nujD0mR175y9v2jgooWlJhHv LuRkyQGE0srxVeusVO7dHRNtRej4SVA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DuoRCLgW; spf=pass (imf20.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=1678831716; 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=Yootx8bbeyulREhTGqw/9V6YBWQoBVubDxv8tYVrS7Y=; b=0VAs3rE3hozJc6NwlD5DVWsBcPM6wT9ezwPs67DGQT7YrvCBsll/GcUJBfI7l9U86CRNcI WEHC0/KC0b/gxNrYIAjCXdApEFD3/shJk2Ky6iUaH1Jr11+m465aL4sjWXVVjCYA4wJ9X6 senkbHy8+NIFcf5Ib9//lrckUEqtL2k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831715; 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=Yootx8bbeyulREhTGqw/9V6YBWQoBVubDxv8tYVrS7Y=; b=DuoRCLgWtBFKoZYCtEBLsoj5laEr+zmArMORsgJZJS2jQSjHQCqPdh5RzhRlMCMh7dvoL9 fbqrV/QHvGrj2PpL32TjZRfopvBZlWrebtIt8uK4MsweZ7IGYW6O4Wv4k7I/g+Kj2z8k9y wiJ95ddNUlPFe3VNrjBZ/ulgA7eZlTs= 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-658-u_kIG66EP2GhMcQ32ruiqg-1; Tue, 14 Mar 2023 18:08:32 -0400 X-MC-Unique: u_kIG66EP2GhMcQ32ruiqg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 73A3B3C10C6E; Tue, 14 Mar 2023 22:08:31 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E8040C6E68; Tue, 14 Mar 2023 22:08:29 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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 v18 08/15] cifs: Use generic_file_splice_read() Date: Tue, 14 Mar 2023 22:07:50 +0000 Message-Id: <20230314220757.3827941-9-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Queue-Id: 5010A1C0006 X-Rspamd-Server: rspam01 X-Stat-Signature: 9ci4we1ytrsxfg5hcbyy9ut8n5wgdegz X-HE-Tag: 1678831716-438297 X-HE-Meta: U2FsdGVkX1+lgtiTtwoyoS/42cnt2QjRYH/UCf4XiPR8Mcdr1totff/g1ix2GMfMt1X0tyNr4nI7M8voiRCRA4nlOUNa9Z0w05qdQCUW0kqF0KHi0O80Jn7TV1dDSlfKn9i8yls1K7eV+U2oDy8DyeiXIuzjvEEwsCdW/KCOqRJvuOPGuOGLG+UVsqZw1sXxT6YxbKhgTgy/AMip2/RFT2MXV8Rigxm/2upYntN38BsL6zurn4398lJrnnNH+gDQeXUXq9zavsv5eOYkd52pX4FvBiBO8TTNaUao2kk1VZ7qIfkSTESUKE/QkRoMZqdv+pwofOr0f/Tq8Au8tZ454X03+aauyu8VDf7V75hqWvvL2pQzrKrl4FGNXhQluwJ7BKUqqgsY6y3f+R17aBPXpXnoHZ69KdiGLEb/QZMcX6YArAavU82fcJ1qHrWMr3l1aNQoYP2wQUnHF4VY0QdECZtIHPyXwN6wRKbGUCovyjRes/kToDbrqrqo6JnIMa5RVi69a7tmBa/zZhhQ8AG6POPTjNjXaUCEah/sdnDTqT3/X2wfEfGcE9/RtKvAmc/e9JPI+LX/+BoB/tRu/9ZNFwKN3pOh9TRHV84I7b3AZkLKBSIbPJuqeSVR19U3XMbJGVB+q3TyRdT3/FlSkz5l7nH/PmZH/uTX5KJ6YQ1zr1XqR0PCEF43yWNwewzei0rPvaUJD7JhBx9khogORrW4uPe8rXkhZwmvBCOM+yvgwn9nHdFfMmFYrsbdN/JJ7WELw1VnNvikf/DkrqFVNphdgnLyi+DhUbbx+NBq8vYMoiSUivwcoRairBgTiXx88UeuOe/00n5NIl342yoB/JuSFbxor3Hd3W4ZyiNJxfghWpL1o1iSkPhsXspDybgouYSwfNbkvLpKL+R0NE/0gxyBDRNLVge54KsAORUx+1RtLmBAf40xHz6DXCPByBpvg9lfTVVwXEB34JByjdb1hWk ghZAnctL 9NIb5J5pjidgscbx0boQ/iCJvGeRXXHKpKirlZD//2jwiZFFlVBxXvWvQIzWqzK9eLRIHyev3GLEiUKTRAe1d7wJX49y6E/xO98Ik8Fv46iXyTN4KhFbBTBAXPhGHmR0bF5hpM4TDh05iqx/C8YxgxgjN+OXn9M7IDb92a1BnSmx7nInMlPc5pnS2CqaJGMznJz7TxszGPVZWfnOsSxwAb4R9rpgGWht8plqytUxzeG4V9V6Qtdr0yrs/AX8RZArcU09FyuhT+oS8isIBHVzs5wPihXt9O51oI33CZqms/S8pGwEs/Ks6wGBgEzqcHubTFr+2Qifk2qAY0hWZFZndPDK3a3FJ7WGN1cbD6eME0TeWSv+o1U8b47edcyJIQpa4Cmx3N9ZYPOJN4uBY58KQY2FmhhHXHsRoLWdul5nFpEWk72y8bcxX5HqouDPfznAi2fz33qmCwlYLVgGUJvcuR57GZA== 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 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: Paulo Alcantara (SUSE) --- 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 Tue Mar 14 22:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175053 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 63C27C6FD1D for ; Tue, 14 Mar 2023 22:08:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D95C48E000A; Tue, 14 Mar 2023 18:08:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D45FB8E0003; Tue, 14 Mar 2023 18:08:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC0548E000A; Tue, 14 Mar 2023 18:08:44 -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 AB0C28E0003 for ; Tue, 14 Mar 2023 18:08:44 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6F784A03BA for ; Tue, 14 Mar 2023 22:08:44 +0000 (UTC) X-FDA: 80568894168.14.AB4A8E4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id BC705140013 for ; Tue, 14 Mar 2023 22:08:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H5+RzAvi; spf=pass (imf09.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=1678831722; 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=JUZaohBsqxdIXWoVfhkIUP8PLigaOsoL0K+EM4hzJ6/txQaqczzeVB2xbSW5gocK/a6vdR giCW+zLHlh8C9IylaAW1YAsCOWw6GHrHsjlWZaeUUeVCeLii0hCYQwQvhPgqrFXetDfzeo h3Uo07z/mmrEzKgqlFjePT1HJ0zUdiU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H5+RzAvi; spf=pass (imf09.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=1678831722; a=rsa-sha256; cv=none; b=vABb8tw4sI/QkWgeIsGn0LgyooX979Pf615utp2kQ/yZ7JPEpbbU4YYhQVlGVMWpps/CZO 4JIDX05lwrHXifIGABg9kQGW7k37y4pE010rwvtZpqLanukZa3boa3HFWl3LJeMkbGk+6h j5UkiiwTE8KGwAB6d7aVtxPUecpHplY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831722; 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=H5+RzAvisAIGzhcD2a2B8jceJD7im8GG1utVwXzYEnnCWkQGTrBZBvG+UwegQLnYk8zCnP 9IzxfI2D7m/kcMXaCqHxk/bfAHSx784DaLZQE79mHmSslVvBDXE4qi3lhiaIRVAKuaNbRQ MpMbpkWWw2e6joZpSkQzdj2TXz7d4kg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-471-UzMxamwfOWSFWleMPlRw_Q-1; Tue, 14 Mar 2023 18:08:35 -0400 X-MC-Unique: UzMxamwfOWSFWleMPlRw_Q-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 490522808E6F; Tue, 14 Mar 2023 22:08:34 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16576C017D7; Tue, 14 Mar 2023 22:08:31 +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 v18 09/15] iov_iter: Kill ITER_PIPE Date: Tue, 14 Mar 2023 22:07:51 +0000 Message-Id: <20230314220757.3827941-10-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BC705140013 X-Stat-Signature: tirosixoizdjtbshao7fdu5i5nbdhzk7 X-HE-Tag: 1678831722-506770 X-HE-Meta: U2FsdGVkX1/VV0HFWOGI22UrH0UpGw1uZhuC68zQVpL7xZPEiuZYC3wVMGk+7kam56yBJFENQuQ/vzM1iB0OmCyZk03S9MnQEl2MY+U6c4lrn6x6xppQyQY6hw2jtH27wWCz9bpf88GQimCc2+wK386fKHEkGR+rrmPqQSRurVEPz/A90nOwGojAy2FUIyDGvwz+GSRIrCBSzxhI9Fdc9UQ9QOlkReJNGK9mlcmlVXbqvnOP6ZrQckDgRfA17EHUhaakfKj2Q3yKI7kp4hu1UD6sYfEvUgKzNQS6iq5ow3llzVZCAPM14nOXh82Whaxfm8TPJDSyztu7tg1ijHHVa2pMM9TLauohXSE4ZObTYcPn+7t9LQ9Vxz26K0vumsD714pjf8NRchk8XaQo02UQ31iqM+7FVNJdHDyVEj6gC/FtVlCPOa7v3l7nFN36NeHWWT3zDwOWN+/PnHOjeZ0xbK8LfGCNeUnbRfOMfyhNutDO5bUIs7KmLWbnxrOK+EiiC8nPaBNXho8hILqkOu4SWEjUAeBM6SDsOZ1LVUYIEwT5roAJBYxVhlku/Fi2GUVPmYcK7t87m6ObJ6f6QHIdRhyZweUp/9LKfCYkR/O7W3sPJMshmjm29HwkKJyYXX6AyFF6e6C0wqKgqhdvG8lo3fp3uiy/vwQy7oUPsRAMNgBFJJ2R3xQ81GdlJwjb7tiIEw+hb8SxFGtv0igj8ngwlL5mhr1POsvCDiKyE2S8hBQBNLvp/C7e85B9tkhZb+IKcFvEonol+Hyod+EMQNMM7RE+Fd0uDtWSVpHQQI6eKW2sc3rQnpbufoP8ZnuRNzD36mhw1YPV4CJFRhxg+q09k4UORcBKUBKYRKyaZlyghhN1FoiyKw2V3lhYwbS1omcQcHwNf6JgzXH21M8SF9m9/w/o5XzbyUB5YjxrYMAARMcxG68Vu7pIS3XVSMDenhaz1gWdv642h0o5lsMr5T9 pq6FhI7Z A5/fPkQr/yeIFRxwKYklY//ABGd4ydXlDgYHsWyVSNv7ruavQGS7x9ql7BBHKSnR7Z5HtVFjPFapfPFSBGbUYamPlSKf3h0eWBp4iVzRRvTGfJSHJtGYqXUbJkCzmwaa7Ma/mSZdakYQgelisOvE/aAB1zWKMlBwQDMbXkU14cXv/4DSIhSF0FC3kHkNPx+HJpOlap42+DT6ov9ErJmg8Vw7PnsMdZe9jSijuHcNrDhkTJwzWkfgyNHAby1P2MGn9+F/X8q5XZ569Dqz7NaZyUJgBsMoadWYplD4vGuc93zYlGwR+qHd3uR+E8R+n81wPPq7uqLl17b8aBVejgXgBDlcji308OmRcbcmLZKH7e0mpz0edIfRdXoNuzd6iYA4dJENLOODzWysIilbBwQnVSmzkR1Pb2lQJUr8ZGApeGOD2Xbte4X6WZhV4CvSe52Jutrav 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 --- 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 Tue Mar 14 22:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175052 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 67B5AC7618B for ; Tue, 14 Mar 2023 22:08:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29A498E0003; Tue, 14 Mar 2023 18:08:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24AA08E000B; Tue, 14 Mar 2023 18:08:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EAAB8E0003; Tue, 14 Mar 2023 18:08:45 -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 E89B58E000B for ; Tue, 14 Mar 2023 18:08:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BF947C034D for ; Tue, 14 Mar 2023 22:08:44 +0000 (UTC) X-FDA: 80568894168.10.3899EB6 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 0300514000F for ; Tue, 14 Mar 2023 22:08:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CtyCMb7a; 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=1678831723; a=rsa-sha256; cv=none; b=Q5HzGOP30SKR/WUD/CQYNeOQcz2uzMca8jijbrZ+LIL9BawLGYMW1Mr37LKJb9Yj9jr33p p4dRy5o+LcBmues5QAs6+uUmFGIrnUBvUiNImIy05SYoqrTMR8GmAD0PR2grvlLtvHlunZ xd2wuq0gLjAZL8Li3UynvPCrLhnjj+0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CtyCMb7a; 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=1678831723; 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=A2EHI1bTUepnrjQqUWlBjesr1JRtSB8dSgIzpGZxZ0VJLloeqUtYT/eOhZUNAGU9KvmEQL ZLMcLDEk3EGUHzu3LP4tO88GGIWoGFRzr49ISTQUmCFw5vChUtlMd9jOyY3U5dWTl10Zzt Xu5em/ZGBMPkKMavqThkoPkvXuUsUBU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831722; 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=CtyCMb7aBJ8fWcpExxmq1/s+SIYJ+ukszw/icB+LCoM2iQLzL9k/dn9W6MUzcltnI2M9Qz /wUcCtEZ9lET1bFpjTQe3gURxp/O65CRoxCVitu+/OOq5VaxJvL3TTbqjdLCTHlTU8fI6R 7OtZuQ1zzHc9Pp+d5L4UlY2I6HKQRqI= 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-240-WXoXZ4YbN7yQ7YG_W8vEZA-1; Tue, 14 Mar 2023 18:08:38 -0400 X-MC-Unique: WXoXZ4YbN7yQ7YG_W8vEZA-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 34E3B85D062; Tue, 14 Mar 2023 22:08:37 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 042542166B26; Tue, 14 Mar 2023 22:08:34 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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 v18 10/15] iomap: Don't get an reference on ZERO_PAGE for direct I/O block zeroing Date: Tue, 14 Mar 2023 22:07:52 +0000 Message-Id: <20230314220757.3827941-11-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-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: 0300514000F X-Rspamd-Server: rspam01 X-Stat-Signature: e6mrtpcrqza3fkr8s51xbceww7wohfax X-HE-Tag: 1678831722-757402 X-HE-Meta: U2FsdGVkX1+kbAbmL4Cx1EJgbuY//9WZAT57FUsIcc6UpeTYOGKiFN1lDENd/5A2aLvFdXLeynh4Cqu7hHy5ZDddhtcNig9xWXA3pkgNiE2dzdNj6ybv+rnRep0bVyVHm9sNBmCbYVDbxGUsvz1pQA3j4Vm/v8DpFBwocN6jMiA3Nfym0fGSYL1h2xx0YzHgdrFu3IfJ15QiSK1fHRFVlY7nI6D4PUdSZ60JycPXDtFCruKrnzYxQmpYCseDfWv+BA++CzvtNPEF2Gjk7fKln5CwAOP0mlT6W3gAKMerFWSUhM/uade1kvzH7epaBCSsYh8GYOTPdJ3WKYPfCbeMxEeFGvLSaXorPKx2uIZyofviifUJ+WLY4SCBgX2cVaTfIRKG/miGW4iEjnHVu3dob2c7XMBKz13xw4MQazcoGzSy+iVjoq7SOH0KbqenQ9jyr3oI0i21EThkukrK4JFsyfWND4QAZbou3RM1139s1GZA9ETIuZ/Av00SDRw1kxN7ux6AstSR2itTpI6V6C1q4VGE2iGfx1wSJ29nYtAPlPzP74b7i0us61Efn7hyJrGMUKcXGrToXqdxm3kQZ4dwCTpCCXXLeWvOez0CTPUSJ1/7igdAGogw3b6zV0b0pi1HnusDx5AsYWFkYvTVMCP+Jo8eNR5HOmxXHEE6/0DkunFOOH0Q0UYURmxTCSVNrGz4CvpiCPyKjey7QsMSKC4L8NSNjOld1ylqU7BJqGAhfdQ2i7eroroNHI0UQk0WwgDvMP8x5Cab+GzViZZhsiCbKRKNITEHfNeJx54+pdMJ25MZUWWYLYDi5wyk65k3WaxOqTVrJzE15KAv5Ost9SrMbXLjesZzA56m02GXX4DC4mUCX1rRHSBchQ+rUh2Iu0p+BcBbecgeaRhfv0v+ab9ZAb04wpdpm1KHdQqLZc+XOkExsBuRlL6VfxasxTMypie8hu0GKFlWgtunNi9oNm5 OKtui3Ex L1mJR50wCIBgh+vl4aEF5kvyk1ROl8I49gY8t/H01G2h1ZpPU3AYLpfKS7+05M3Xcls1BcKKvZgeuhspAFr4EhM0C0pM4LdQAZvI451cTtPxHBsUdKMu0K39HOAsiQanYu4uBuMzsoiQrMu1RugG5FiNFASiDWuO1+d1zX6nj81dtfgh9Tq+J7ByNwOhAG84Nh4B7WrxicGRD35iiWfchuZQP3mT6+bgGxr1WHnblRPild8LjhlD2gn5R9b2oaG1aHSMl9bWQx3gmEWZUH690ir770ja7CS3LJP4fIyHQEe/95YGKgMBRrr1Uz8G/Yvl/LbHfw+rPi4SJdTgHDwufgsyt29TA27DNee5RtpDpfm5mIGAofCvbcPRxCvvepASwSPk+ 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 Tue Mar 14 22:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175054 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 38E77C76195 for ; Tue, 14 Mar 2023 22:08:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87578E000C; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9C0A8E000B; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C52B8E000C; Tue, 14 Mar 2023 18:08:46 -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 83E398E000B for ; Tue, 14 Mar 2023 18:08:46 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 61A4740739 for ; Tue, 14 Mar 2023 22:08:46 +0000 (UTC) X-FDA: 80568894252.28.36DC034 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 AC1F780011 for ; Tue, 14 Mar 2023 22:08:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QX/VJIgu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1678831724; 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=DvzTowaB0L6uwPv7n20vdUNEGVX8RHFti2LhKhOYcWjGHMMAbulkwpPHm23bhxmXvSp8um 87Zk/9YcUeEekqz4Rswj91Hw22MasTqvBga9xlNXguKUxTIXK2q+ZYjBvZpaM7H5YeQD4P SWBHAKyQlN2cFpsKRv8wbEQOuX5I6nk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QX/VJIgu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.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=1678831724; a=rsa-sha256; cv=none; b=KFczbCLNYbn0HOJ+4RqbwV/TTZm6XjQCA3zjJdgaqXaGM3iNQA/PRvkCodJKTGDMJ6dKFP n/Z3RbNUL8/6AUx/abLGNosUbHLva/TSUbmREa1AxLWFALHq2xI/vSF5ryqHugJBz1ioBe exeVW9XZJquo9+Ab9P57PHw0dX/Cm5o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831724; 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=QX/VJIgulNoojTu5UAIXOZ1OgNai1qAq/9n6c+mTK7Z5XZWd5vvC0qhA3r9GgeDDCtQUtq bcuQ9f+DJ5OU5O2bOI7aWfL5elSn69HpnEXOKc+Jt1Ly7A4myiKuKhC1YIaFiL44ktc1k8 XF2aeWq0JFmHqgAq1lras657KAnn4tk= 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-102-n0ZfiDmHMfGhrz83iRoe6A-1; Tue, 14 Mar 2023 18:08:40 -0400 X-MC-Unique: n0ZfiDmHMfGhrz83iRoe6A-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 E35971C08798; Tue, 14 Mar 2023 22:08:39 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CADA6C164E7; Tue, 14 Mar 2023 22:08:37 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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 v18 11/15] block: Fix bio_flagged() so that gcc can better optimise it Date: Tue, 14 Mar 2023 22:07:53 +0000 Message-Id: <20230314220757.3827941-12-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: AC1F780011 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 86un5o1isubj3kr9ra8t3fi37ek7qqpc X-HE-Tag: 1678831724-548372 X-HE-Meta: U2FsdGVkX19tkwzspeZtXjp6iXsHet/2quGijwWYlxKZ39xurV1qR6w8JWDa/Z5GF1DIMV/mAn07sWXaBwWjnSHIEgA+EijKbAUPb5FUhy6uyQFW1cskzm1DTih40cp52O29j82rGz2jmtooqO/RItBjrLOp/KUJE9ByTfiDg0a8gNYNnt0NK7c4WX1ffTpDPtbKHygV+e8L5XVFpJ9/4bcb7ODRBsJKM92I5u3z/w+UM4fOv4XZV0Qx7eycrOBUa8zGeS67XSR0LwFdsU9MDSSq2w9/FfKqrA7pB0Zsv/XHzxGVFds9hDNHnx4IAoPIS8ydJHzz+K3mYYaOJotW/TzEwieNb0gxF6DgsAVQjikazjjYhfYZYdAZcppSU9Z8Gqxwhp5by075Ncm/abULWGraUj0JuHoxvtdafUOVvzhrKpbkMwHyHwgrKXPUaRajDIAivG2BpW3bmDU8BJYOyuH6whMzQNsbNfglCnqbMC2X5oifN7NJ/wQMicck1o5hGDEKjowb0KQItcOaCXPs/WZbUuH3DwprX4KvbXSk7trwV+/8vCRWzJxiJ8DPzPjVgdIaeKgrXrrMrT5Fe847jfrlpGMHaGWmPsKgRXpwLVdnO4p4ao4zE3TyP0Pes70G12MzNLoz+1eGPsqt408jHxLM2+FAo7CghEXdVMzXo5jw7vUv92fb5s3nf9TyK2UzR113xaYpoc8BL7PcuopnCdh/1PD5qVVx3iU/6GV46wlnBBlXP7FKjc9gfuxktSJe519pyCFxs/shLAm677rnvg1GbeuZPQt+0eSFkxmACIj7AHo00CAUvAsBWqJbzWuPDcH6u5vLd4EMhj3jXRVVemgTjMs7BXqXBAJ6+kRR/QWAlfKNR1XqZfkqn8Tdo/meNNVvLqbBWayJygX/rJ0GTA11graqpt5lkRUdML1mC6bRQMxN8w07jECopqe202f1dDWZQdq9EfI1U2kJ6rl Ionhq9k5 PD5v8XFddU9XfRBJjGo3k/tUVBLTw8/3yM5rPLtt/m4N+iuIpP8lYCf+0wB0GX6Q99ajC5WI1b+unde0TOhRLvGeEVkXbOr/RZPJtnWRFyIz1HZcCqSeyNd2/7U8SxLzN07iTTZm6AM1fQfZ3xGGpfNFScv06TzHcOvidtLTgezSVnWkjBTuPlRTk8FHcYZkseikphAPxAmzijJSgH3M0JHnO4rj6j63RQXI/3+riCNlLIIGaYe6FKdFDoJPsSm0m2TDIyvgEPzSm3ykSJ+xwsRUjLgBNr8j/Px/8ZBe6WNqAkjnizGwxfybuCDIpVOhXnko/7Y6HTP61ttZmWyLq2P+SjU1RRPvvvOsEsg0499zNPGnJ8G8OD+8Thx2kMmNUbbxSurDiZi3nLGLL2kfek0OAgEVpnFOV4tBvkqAsMJMcsnFYyQCS6Gg5/23sLEe999irsH9i6InW8RA/NddHJjJ3OIeBagam4lOfeqCRFRkHpA0= 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 Tue Mar 14 22:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175055 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 200D0C6FD1D for ; Tue, 14 Mar 2023 22:08:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4C048E000D; Tue, 14 Mar 2023 18:08:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFC488E000B; Tue, 14 Mar 2023 18:08:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C3B08E000D; Tue, 14 Mar 2023 18:08:51 -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 89DF68E000B for ; Tue, 14 Mar 2023 18:08:51 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6BFBF80128 for ; Tue, 14 Mar 2023 22:08:51 +0000 (UTC) X-FDA: 80568894462.13.A24E9B0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id A35B04000B for ; Tue, 14 Mar 2023 22:08:49 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bvU+uDHF; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678831729; a=rsa-sha256; cv=none; b=BTd6x5J0HO8ChIANOhsf1MHX0U1WhOP7P7hjn3oduzizGOHae7QyJH1uZZhazKrOJryNow EpTtv0hkes64bZrmp5yoj09ZsvECgMuOlUhjeGrkboXUEiaHF1AC/3iXBzDQbKYr8ZFWNL WjTjPSZHwk6lD6iAqA8TcWq1t1QcMyU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bvU+uDHF; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678831729; 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=yOkAWbYdtdDhtqI5151V3ATx+1kJETVkbJWTHlOO5qwalmmklyG3cVnN++OCEZL0V+apci rfpJed80uyL47AtNyVFeJX+zqKSbW7MSFQaj4ItpmO3y+adkfEyGDptWrF1djRGE36/bny BzgF+dPF66E+BT+SZWWn+UOp1UFwc/o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831729; 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=bvU+uDHFXYTZOHf1WINih5m0rFkR0vKMrs3XPwErVY70L1shDArypORN//nFKtXeDrPwgf Dw+IfcNPzW08ZYREkpQBXVlddJdoBJci2EhxCtGuMqaUWShSn1adGH0VANMJmKWqrD7K9L ZTy81o8FNMXlkJtsxkEOgVIaD73uyX8= 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-593-kYMP19KTPWa8UCkAvUpFpA-1; Tue, 14 Mar 2023 18:08:43 -0400 X-MC-Unique: kYMP19KTPWa8UCkAvUpFpA-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 BFA7E3811F2A; Tue, 14 Mar 2023 22:08:42 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5915C158C2; Tue, 14 Mar 2023 22:08:40 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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 v18 12/15] block: Replace BIO_NO_PAGE_REF with BIO_PAGE_REFFED with inverted logic Date: Tue, 14 Mar 2023 22:07:54 +0000 Message-Id: <20230314220757.3827941-13-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: A35B04000B X-Rspamd-Server: rspam01 X-Stat-Signature: bufwo1jpmigkrhuhm6jabqqthpc1e3oi X-HE-Tag: 1678831729-582118 X-HE-Meta: U2FsdGVkX1+otcxVVOGTGPIdhx6sCuFk7z0/rULlMPpbgbEtJiBx4EG/j89Jbdh9NkSn5fqGAPQ0D5gAwJkPgHOaHzhY2SwgJvvLCOr9b1DC+J0O6Sp3dvh1YWoF94iRG5dgp3oFCvCaCEI6TN4u5gFdP1v6c2AdX07TecOT1arHABFBnya7jRPViRvpz2KgsWKVkRQDDE5pRQPrbLVP2yS36lOIWVRTUfDwrA2kOX6FpQ9sOXS26HiMEFZ3Y8rC+u+BOPNuRd5+H3bJtbDmuFw26q5pIBB145jiOPR86sZUA4ZMIyDyFjmAsxbNa6YsLtbTA1L2y2Kyy8RNTuSB6ezK90y2Wra8uExCuwNsDir/MJJ/OTKf3XAwRV1RItBYzGlUczyukiNcN6co/GcMVgG9Syq2QMcOPkg+W48aZy2+9ZYTrt9JVJc+eLQRBgjdGXaxh+uP7xMtR7p3Iog/kprSjVy0nPcjp7jR7kK3vA9IqrTtUyOYK8swZid9nUFDIwRZRelrH97VJyZjNPj6jGMGhoZwK+DY6XA28AzWrNtpf99BctdRzMfQ8Bp72nMFGfGijwIvYl2oImAFGNoe0wHHeKEVzVkEdmBBcitDJIZtafgwyAUQzo+xr04BmRk8xJiZig7q7AlUSukybRAcWlNMTtnGUYENvr7wJBknOJmjjT5vFeDCMaVIhPZZkxoaAlQJjmQybGE7kh+OXEEPiy12PqA+tMsyUTH3rSaZX8k3CbuuyLOtSyZdshorEW4KsmefLUIEuSRK4qVGUfr9TtTln90p3Zy733H6+TETkukWh/LjTaj9bA8y/ZU7pwl+aV59hTkOkAWlnq/9fMXu8UPsteOErtQdy9tS9aG3c2NJONi3E2lzQw0/eCeV0BGyqjrj9mIqca4kyeIqnmK6Yq2TNwZ4eQ8LnDxTGHsKI6WhIwqzd6k+HmgRIqAkk+7i3vCxUYM0s3vStawUh76 /FJrJqS9 iCKFagzLo6cNShcISiDWGirzus5Wb1R/dK19pMHsetbiTKtMiJFZdp35Sy3JpxqwwVnN/rFJvFu3F9wXYeMGr0+x2kz3hziiP98Vcd5AbK6dr8l7yKSRr/5QpDU1Ci/8Xw9nCSRneY5CmUadF4xsuzPQi22Rfyv5Bv2x0jW5AhtsyGSmvXh4aMN4LwEg9gwFjzQVqZVIhZBB3j0l4WhLhKmjRk32OyJwcGh7kAo83yUoXv9tWDgM0LV4V0EPeMBkDQz780jVsM11Ra8HInhOOmhiJC2+H5U+aBRaU7h95UaS56Q03RC6c1Jaap47/QZsKrTgH1d0Y9W/KAZVsRnY/Ap9BSqE1pjnVlQpGEWlZvvWREd/QYAtlNRNo9BTeWcdL1GXlMZMIm3EWVxGFbfNnbFBGY0o0wBJtSvgNSqt/XmF6uo7eqmI2rAqXCU7N4oZn9f9N7xtSmcn7ahaciPS4ZT3WDRHnmIcogYu+p/fZM2hcsXY2c0yL06Uriw== 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 Tue Mar 14 22:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175056 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 E03DDC6FD1F for ; Tue, 14 Mar 2023 22:08:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C9148E000E; Tue, 14 Mar 2023 18:08:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77AAC8E000B; Tue, 14 Mar 2023 18:08:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F3848E000E; Tue, 14 Mar 2023 18:08:54 -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 4ED098E000B for ; Tue, 14 Mar 2023 18:08:54 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2989C1A082C for ; Tue, 14 Mar 2023 22:08:54 +0000 (UTC) X-FDA: 80568894588.22.BD35A1D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 7850FA0004 for ; Tue, 14 Mar 2023 22:08:52 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N4u1qumQ; spf=pass (imf15.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=1678831732; 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=qzhkRlr9Viq9xqYmtM7yKfRN+n+U1cmYspomXcu/Iv6PGJR2qITbx01xFQfn4YzVd6sYdA gAg7IU8D4pETkZaIwMjZlzNu5IVUDgmt+wTskRriHHaCiBlwQVjVA5Sj7orNGrla2mAZ/h byx2gZBRNCt7zVnqX836VyjnldJtN54= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N4u1qumQ; spf=pass (imf15.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=1678831732; a=rsa-sha256; cv=none; b=1u4QvUS+NX+dlexJxzaYILdXcDyoTdWz+G53Q9eJW7RI6fCHFON5+n/cF4tooentfj+8Wo JeUGqnQMbKAUbbqnvsvPUYtdOhgRyFP7Fx8q6WoJsPcv0ZM/5NBt36P01AQ7dZ6Ra1VUVv atxu72NrBvYKfmh9rCFK3dzin5QVYzw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831731; 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=N4u1qumQpRsqw7rLxBgMSVWKZ/FPwUNRfwiCeP6OFdtQdhgo7WwlYXl1cgVpP0Qy4gKrWS H5mM1wjPruI3giSNoRXYs+l91rsEAxb0akIvh7/LaniZnVXuVZL8Pe9H38GsqXJ5sqsIbT COujTMzGBDpNikHUgvcbhoeuGtg1/bE= 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-401-HMAWkB5kOk2gDdlhaGNCIA-1; Tue, 14 Mar 2023 18:08:46 -0400 X-MC-Unique: HMAWkB5kOk2gDdlhaGNCIA-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 7FB4429AA3BC; Tue, 14 Mar 2023 22:08:45 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 631E1202701E; Tue, 14 Mar 2023 22:08:43 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , 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 v18 13/15] block: Add BIO_PAGE_PINNED and associated infrastructure Date: Tue, 14 Mar 2023 22:07:55 +0000 Message-Id: <20230314220757.3827941-14-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-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: wy8oagiysm5wx3meh7tiqbecier6i9jt X-Rspamd-Queue-Id: 7850FA0004 X-HE-Tag: 1678831732-349913 X-HE-Meta: U2FsdGVkX18TI34ftwPuWxxt8hh815lRo5V2f3nRoIjXzgcZCkUd+MsmnLFI+u2gf3zJFmvUC8YOAsHlJTETxZvLcDple2ZJQkVRIHuBK5w/mBd148FJ+2zauiZU6XXRFJt1cSq56NA8bGcOnuypcqWK4HyBLnWL0MtqiFfA/nC/KdhYY4LRoI2q/TRJCKo1KCGiAghiKycTumspzxlUyHPjAYAWNX6pP0FNOLsrdKbXn9lkVGJhzvDSAqLU8ePkVspROytSCQY6t7UnoTiGnkC6bx8VfjT2RfsQxPacVHTkuWh9/OuBdvZQRMP0mnH73BTePJHKwNNFAqhfLBeWnRaBmBxg80lRtJmbI6sUvLJF2aMLKbR6i9ABcHe8qPhNgBAlrZuuQO/hHZKXBzC2edB2X84ntY8I1sUkcLnn3rgrBdRn5Sr24lxDZiteDyZJTzRLZUwE2t6oDuNdjXj5Tl/b/lGj6w5o+9iwE2EWmBW/RCVTxcU6rk/cMU8GJ+ZMSR9716OlBOockAp2FASOT1KT1Syov0twwLehS1suOfdaytaZBajHX891zoy0BWt3hqsM8CGSsEfWhgUOgS3Cv80oQxMHNMeJ+eTZIgGYg4iHV0glYzwx2ksoa7tnSKMOKK5UPK0eYXN8yOcQaX5d4FqyfV5O447jmhZ6Ewlb2yYI+nDVVwyZqnRmG5K67QsQAy6Dwx+1PoPv6Ak9T3abFKQ+g+UZ1mG1VPa/CZkppolFf/g/DJfmDpTwDYbewQiLDBa0lc60XGa/OqwF/IDajXs2FTaklX6GdD5oOII2XeAwMWQh6Gf1ygJHRQf1PlBW0Pkss+dFY/6PmKlYAlxfl2HTxhaIVMRWs9dKCUkvpbkA795jRsmjrVjg0NoR32FDJIJye3EgAEawAt+Ly/RvgneRnikxVLKkFEhYg4qcbIVg6+6/m66pbWmFHdXO2vNUlIGj3CMc/hJnWfufe0h poeUQSXq fx8YS/GnzFTq5z+gJo9GHQx6vf1jzTQsX4LQx1d8aLeNrjFrzDAfJ5yoOuqFCZNg+72jl4kZ9niGkM3J+xqM9RGM1ZaBtdhBawFj4hy6/Uwp9rWgxXzFKNyZNC0vRI2NH+300XmsH5nlvt86cGT5JQYUFojDc9QRLJbAVGtenXFL7GHFKcSTbwmekwtWTIYKoGQgL1eakh0VHU+t22rvAK3dVIAc+srfwMKH0RGYt7F3ZPw7IsCu3K++WgKCtKjJYfnl5FcDc1f0sZkQ8uYda+Zw3EAr8QRCpqcilM3uLbPGIc7mkDUmW7wANBy26y6FP71/DXki+C+nI9RlGXDDfjNvU2kWUZ000z/9xhzTol6t1jGrXMQeTMVBV4wKBIfrTxDvHzYIlj3UzFQIjLA1tORtx6zJvSO+oufUH0nAkKr/WVhIsg4WFYxLHJAtpyTClC3naPEbkHQED8D4r6gcBXnHpsshATVwdE8dTGDdQ9MMbilAgzntgFr27Sw== 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 Tue Mar 14 22:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175057 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 1BF7EC6FD1D for ; Tue, 14 Mar 2023 22:08:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB08D8E000F; Tue, 14 Mar 2023 18:08:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A86A58E000B; Tue, 14 Mar 2023 18:08:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 950218E000F; Tue, 14 Mar 2023 18:08:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7EEBC8E000B for ; Tue, 14 Mar 2023 18:08:58 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 44B3740E19 for ; Tue, 14 Mar 2023 22:08:58 +0000 (UTC) X-FDA: 80568894756.14.34F70AB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 70256A000D for ; Tue, 14 Mar 2023 22:08:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QhDjKM60; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678831735; 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=acuDnM9Bn3yrh3mcbVZkpPHkscJFMJ6CCER/Wwk+ySOeCft7BqkuCnmdU69Dj1bAhxqdix txGzJsHRXIL8N3uujyZeVNhMZcdWC3x6+kGTqE+ULCryXr0o5OEYmm6QTKK7aYRp0dxkNG M6yw2i04nzLH3+FgqCoLKxFDQUi3Shk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QhDjKM60; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678831735; a=rsa-sha256; cv=none; b=pcH+tS+HhT1nNcpcQVFDOhEuISainIgXoLjONe7MowI1q0tCOV87sEJ2kA6Zxk62vX4qZF NxvIoOigzcucxvaJFvevtgCSjNKDAtqAzO79q8u8BQK59GLw+3HykINq3oGONCFuFncVpd E/asjiKAwpTDjz2lbszbGIU6Z+rNRWU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831734; 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=QhDjKM600ULGK1g6M1RfXBLQcHCisyTC9Nk0NNT2/5uaMsW9M7AqF4gP8ZPu+yZ+G04a6i Uqf5eHSKK63JpfacJPZNx75pT+rP7a/S5/LI20h6x+Z7lJZ4OH3/toveWdp8Aua6Tfbdk2 LueR3lr5tLEk5+4O1O0ZR+Ch33V7H20= 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-205-uCyo1JtYN4mZpNcBA20adQ-1; Tue, 14 Mar 2023 18:08:49 -0400 X-MC-Unique: uCyo1JtYN4mZpNcBA20adQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5506729AA3BC; Tue, 14 Mar 2023 22:08:48 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A57E140EBF4; Tue, 14 Mar 2023 22:08:46 +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 v18 14/15] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Tue, 14 Mar 2023 22:07:56 +0000 Message-Id: <20230314220757.3827941-15-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Queue-Id: 70256A000D X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: rime5rjjccknd8c97b956wh41a15zery X-HE-Tag: 1678831735-299826 X-HE-Meta: U2FsdGVkX18njn1v95mmq+IOUYf4NUUMdOIjy/Bw3nsGMGPL48ENUnI/g6A45h7zlKrGiEDVLcNaZ77ZqDfT0gv0Ni13firJCtazrMTARvHRmGIBylcW+gA5embecqTaxH2fB8NfazCrlSKySdLp1ctS/60Sdlg7ERzd2xQ3UrThUhpCXOkGPzoFgn7Ph+Fyznxb+/YlwLu4ouZkLNMp5Hc/ihIL11lSwSGmaVaKtk8w3UqyJD4rr98fs7IFuRe5ce5JDHUCBPr3RRYvjxqokySiP2Npz2QAf0TuaMlxvImK7MAm5IqtOKObAl2esR41pfQ/louZ4QGTwka/PFLjwHrLi0hZ8/OE0gHlpU8IayCCYuPJGZXFrWS9OrZ8nd8TNbozE7PdFUTTjZxtWw9U4nYOvIuc/mvWcg2z6+ZiDjO3YR27x27PRUn2TGY1OLhscwAvhzzOt4Xd5CwqNVREBlVvg5k9dXafNoX1K02IhN9OhOJiLHySrnZbhURVC80+iHhchGt+ZcoCidpwDrzbR8T5IraxWzBara87eftVCtbtCaGMiWeAf4C8wh62EJ+78Tu9Pgv1WYpE6lpy7llS68qGrVw9cRJKMvFWlmy1eRlkqmkzl3W89kBjm69fLDkOfGaxAst3pScdwxeEZShWhcmXuowwp9uUzd7zpMivCOBT4Kg9/Hr4arvt9z3+P8rswy+rDi86vbrb0Dw0fM2dhzrKAMtGFWzmpgyCc6L0P+hfGwT3pZr+WtwS9wYymkQZdoLhhIeO7PG+9/6wZYfH4AxHLNWtfCX+kpNUEW1RD7DQxOIfZosxr0hophvnUp4KP8GbWexJ4q5C+tcJLPivJHrWdKqLtBIE78MGCglcgeNCZ2Q6Mlgb3Ubndu/Gvz3Rxw5Ho4QDfcGBrU3jBUirmH4oY4oGUv+Lsh5HnbyWU02I/ItqXcpT4+XFBX71ZNCHg5L5okIq61tWq2gkvuJ y8UXNgl2 U+7feAlydTzZOTO8IrcMMqisOzQuTr1yNZHzeQOCqBApLcbr3WQW82AQ3WkhDJRH7Le0xOR3I6lTCyRL7EgLEkBZlreifBl7BAX5wRKEwnx/FNsYXknKB3ZSaOLHrIuj1ctstnWVdghPX0V+DhIw2IfkCk1giz2KOAjT9xjy1lYFsqazNkM6LUyxiFyzrRv2LmNKnbcZNhVURaJibJOAbvKvA1Tndz05NrOl/1ZM2lOO9Vwfd94eFgnWFzuJoFaTUIa3jAehQ+4iBMyAzyJowPizNFGeWKm7n5+OZguvUgHXHJNay694fvnMfMoHoeQm5bZie12q+3rQMXcPUaTpxkBhkGRrRYVL+zYac+0514DrM/2Ni0JnUvJYeRuJIJDVkLqFIUupykutMyDKPIxMmaFOxgRATKSvm0pY3aQjdL8v62+4MjigjDYkDOdrUWpebqEaCpbt1KiDegaEVO0gp4EPU5J/TBQb83SglIxRGnOpRZV4m8HXmuhaZqA== 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 Tue Mar 14 22:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175058 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 CB5D2C7618D for ; Tue, 14 Mar 2023 22:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 669FF8E0010; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61A158E000B; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1BE8E0010; Tue, 14 Mar 2023 18:09:05 -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 3F0508E000B for ; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 13F8BA037E for ; Tue, 14 Mar 2023 22:09:05 +0000 (UTC) X-FDA: 80568895050.23.C63B3DC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 590D22001E for ; Tue, 14 Mar 2023 22:09:03 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gigarPfn; spf=pass (imf13.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=1678831743; 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=aeS9tKbIZKULa0AyWq3uuRPvVmQvXtuHBH4vTUau3iEWxVP9F+SJZgrT3U+N5Fhh4XIjle IP+SkAM0+9lOititEGzjyLHMl4pzeq9q7F9106f8R7j1ZyBCxlCwTXQj+OBYixPCtT9oWw Ig3q1/n1jTCztRHmMQK2HCNiwJht/ts= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gigarPfn; spf=pass (imf13.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=1678831743; a=rsa-sha256; cv=none; b=Ve+FCjAYGMJ+Is1ig2VZFmt0/bS8rgJUKBB+6xxTEb2tmI0+eYZ2i3UbI4W9UkeCQiLmlD gMvJPezKWD7pkSikB+zudbkKzyjRTC16bPC2pfGvtABYohHgfhV+YJZrXpnsKFUhE42qZR s2k4Ob7M8QeXSvGd/JAwIN7BhpKP84A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831742; 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=gigarPfncQ24JpmGkxEkWHw52jpUSt1R5Zkkc6NS8lVbiXt8YWMDLy5G0Cm3lolXdf+GAt 4jcm63l23iAei4M93G2Myo0QpY90x5qZC6D13mlkjlQsKNIflujGyvJt5lQtwzTRX4wwTb JkRPVXbIHQdYGpLw/EHf/9pqID/kHzA= 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-167-ZOrmw3hpN2OQ1vha5UlzMg-1; Tue, 14 Mar 2023 18:08:52 -0400 X-MC-Unique: ZOrmw3hpN2OQ1vha5UlzMg-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 129C91C08791; Tue, 14 Mar 2023 22:08:51 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC4CA47507A; Tue, 14 Mar 2023 22:08:48 +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 v18 15/15] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Tue, 14 Mar 2023 22:07:57 +0000 Message-Id: <20230314220757.3827941-16-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: 1rkeupjkxtk8uh8t4f1h466tohrbyi66 X-Rspam-User: X-Rspamd-Queue-Id: 590D22001E X-Rspamd-Server: rspam06 X-HE-Tag: 1678831743-166531 X-HE-Meta: U2FsdGVkX18ccTQ/RssDZ817jXgXs765T8L6m8wh9YPFN07VnzAPlpNBPiZ1ntZMNiCuayHyrns2W+5xM2u5N/tIOY0Hn9JBCpA6Y54EF7Xm8IHJFaHpkz5whnrac8k1WwOxRLFWGbwyAN6WnD7tJahx4SJBimfu1tCmwqb5UTqQliibmKQPKoBe6EzcDH9C+JtlPsmStIuIhE3DyHr1e5WNgALk67pE5kTwwbYdJKJL6X/dgnWTm+j+7fJ9DtcKtgF3rct2UXurxElEktEAG4SktfHkj72dYhUBWg/IAkDV3W+SRHEtuizw+cok9GvVg+Cv4dvLVVVxlo5Wv+6lvrOPt/ev97laj2WMeVstodKlKy5ivuRw9pDI4Yroc03kJEz//jCxOOw+ca6OeyMHiCzijfDrHuj4G/oHP/X4yQDBqohDMqvLcrQQgQRWaEqZ5HaDszgniVniplkOCdWb+6EGznnKhmSLwjjugpGG2sNIpxlwKrKffnHOCZypghH9QGNNRDJMpU7FkAD6gEegWn/c1H46Xa2OHCtbS3dR72RNTQtITXqmtrADs4tPF7YLyP2EfDRelFpc23t8QmA7mLAC6JnTF73vIhHxKx28LQbhXA7xY7zOHjuJnxqk+BueNbh8Fbz4dkLGdctuVZamtNMof2OoB6Rh2ck44p9xPBTyBTt10dmj+zuqRddMLuQLpGwfwX6aRCra+1Su2k3SwSIEwvBnhGVfi6rXvOlqL6+VfXxSO8SYcKeexndZ3w8bI2GDnsSEbyk6ymtuc3AyHjH1OALp/yu8/87+z+Gg/P8pOWbcg/KW2stU8ET+/Jow8S1E8wkEj0gEw95U8QBU8RtPHpY7ieo7gn1S5/gaLmvvvkHFKcf/y7Bp0Xkj1cL6WBBSq9xjtte6JrBAYeOMFWnPe2yt05AUp4/Ww5mJEPhbstRuPNnfG+oKQXdhgJzvi86jM5bkP9uXucV4yxl nVkYZVZK L/ddUNd36Gk/WMfIZF/mPesF+7aXerRh5YmnX0NTe1uqRx6B/mSHqI50PqewhuwTCBn0RsmPf3MP1gXW7PrR54btmP10qjuQlPo/w6ZBrnKN2/DrL+4HgFGzhOwRpXQunXVlLxZBFnJ5sxOHLvVkEHOaHOW6YPVdi8CrgyfzJ0uD2SvWlczM6HxPLn2+xNsCLfhrSZ/b3V6lg0Nk6LofxyCmavpjHlxbkZWHf5v3DNu1/r2ESDIrqWamQD+cdD38N1WmCW/8OmJpBhVS237CaWeNHxDnhXg3PthyX8p4zuHP2lgInGxrtBlbI8sYEX15ijWFk3HxnZV4MQzs0Z4nPPKebYFgUwbAwXsL6un6idRFprcymdqMpKpDXLmfISSsLHPSamrpNksm0DEYoWYofHFRCfQCE9rkQ9cVdnqiWAY7kPGBvwdim6krIg9t36iMod31tUZttw1CO+uCOl399aHotOd3DFnabKCsmrzsYH+v/jhySAxSnoAJPqw== 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? */