From patchwork Fri May 19 07:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247756 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 A45B2C77B7A for ; Fri, 19 May 2023 07:41:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 285F9900007; Fri, 19 May 2023 03:41:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20D04900003; Fri, 19 May 2023 03:41:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0603C900007; Fri, 19 May 2023 03:41:16 -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 E737B900003 for ; Fri, 19 May 2023 03:41:15 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C05D1A09A2 for ; Fri, 19 May 2023 07:41:15 +0000 (UTC) X-FDA: 80806208910.04.6799015 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id F1DBF40013 for ; Fri, 19 May 2023 07:41:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Atd8wBv4; spf=pass (imf17.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=1684482074; a=rsa-sha256; cv=none; b=M3jqbIOodt+lSdLYSS+WegskZuEoqTZP3Qlz+GlkW7lMzAMfPgL2AxSwfjqUDQ+jrySEgs 0u3TGtO9Q+xc9Gl4SFQ4YbXoasHOeUhvjUZs6rn0C/Jui6wK4e4e9S6npTKn0FVp9X9zGO 0upmbNGHWwUz8ZM6AmRctkvbGLqIBCA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Atd8wBv4; spf=pass (imf17.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=1684482074; 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=BN8k90GM05xGcXUwqmiE5oyub34c+VlFBbq2fGi5jWo=; b=XT99TzcvQ6mK3c1vWGxp4F3cp3fbhUzZ5LnRTFZ2BcnIIjTU68eswM9Ag3Pxp1Kz920fDX /8hxW6qG2/UguENzzBjavUy01VRZYmcYjFVnnWFXIcDri/Tu2WTNrEFOPwQLAFSJi2DsJ0 KirUKl1Dcld6Y1wt4mJHIXxBA/34nx4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482073; 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=BN8k90GM05xGcXUwqmiE5oyub34c+VlFBbq2fGi5jWo=; b=Atd8wBv4C3HOntXIH5KpI41nfIOqi3PwRTW3eYLArD3OPPIXeX3WbDF8XiPezaBC/izVCK HQmQZqXjg5KE9v+JFaK82G5cU4sF0c7pHc19dTqzew19VnfdCCxpGOI0PH84DI0OCjhFGp HQpyvXU3FUr0uxG4dNPvkm1M2o078FE= 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-541-i2ERw50uOo69R7scCkPSwg-1; Fri, 19 May 2023 03:41:08 -0400 X-MC-Unique: i2ERw50uOo69R7scCkPSwg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCDB029AB3E6; Fri, 19 May 2023 07:41:06 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6BAC1121314; Fri, 19 May 2023 07:41:04 +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, Steve French , Christoph Hellwig , John Hubbard Subject: [PATCH v20 01/32] splice: Fix filemap of a blockdev Date: Fri, 19 May 2023 08:40:16 +0100 Message-Id: <20230519074047.1739879-2-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: F1DBF40013 X-Stat-Signature: adq5dgjxuw43jid7kf895xmjisedk54f X-Rspam-User: X-HE-Tag: 1684482073-235291 X-HE-Meta: U2FsdGVkX1/wsXeZhRMpDERGsbyfOwDfU8M08dCnSNIOsAm9PeotqCyXI+4FypAtW6cj/ORULIzqKirTEh/NIF+fpRAiOH03TmAc9LMWQPw6juyXR9ta4rRfBLfL72mVZZjOLwDxvVeSZLrudcz9uGd2wRAHDKth/ajgFzJvRYWRssy/hHxd952MrAMzdjakyZDA8fIkU8PahzkqY3t/bC4IGAgXc2PYR8eBEV+1+GJJooCzT1D42e+iIz86Xkn0PC7XWTE8Bo0/VfB3Q5MqhSsRee+Ls4jwVO963hCYVZ3wZWYQxha56iUjAxVLvnfJ41WHVA4DsoZapltclbekYAV2IVpQ/+yHJiNY7EtNxCAT39Kv2NrrqqUxGy1vGOiAuaTEj59OVJujs1gD42Qgfq0njc728uxJ7MoWuSNIEf1ruBhAe8r1HctES3KumBgJcO9B5fYRI9qWvKC0BEh8udBBXFg3c7l22Uzv0YAD2x7R1ioA7Sg44V+/UBjKrNOe+SuKm6MKCeRVh/64Qdt9JOLEocdSwOqOI/RlIcUIaaarJGe9SNzYeg6yOWUWiBepg2q+mVBvKFcz36VB26F1jQ8U7CTySUUuH19Os4PRs7yiYIQG+bRLspQjqfMmEOqt+SaWOXGgFA8qSqZBeleCp13iQKhnxptTTaCcPDb2offMAUao9Go+UI1obAd3htuPYoNvBsvewcGHc5Hmo3vqRCrBbgPXm2mniSIsPqCEmD1/NkIqHrTgIYQlv7MMDDEnNzlMwbg4oDnwaTe8qKtNx+TJX4pTKxlVst87zqrC+6a3kHowB6x0eoqiYSgKBi0KwErf65YXzA5hQbauN+iPDyzb1JcHqhKryWTllNszTttMWtXHT/ZYouWJu2hcMkpPcjzkpepn2csTS+RoIZCHLSWkpaQm09zvWhnSGMHfGoWPlYkNBJAOnSTiOPNph06nysvQNdGp/cPAEC2aI50 nKIPybU1 KDK9+syEQ5SSCFggC9NhNuzaYof4jbDUcWeNuE+AccFlBQFdBshZrd2Fs6cxDanXvTFAZkHo3P8W6yiSKWQ4V62jf0zkrRwzltnYrFUT77UN26VJxa+EAm/4D/yfLKtNGqRrQthsNiw+G9DBHIXRMLvz5Udi0pD1+y8QhJR0tzZKieDyUAOscsmBjKsvSgEq/N+iB2mf0hSSWexiWsy2OyVVsPntaEbAqdkTU3Zk8TuSQWOttNsNkGkWGa+7tBUEdkYCEHdpq6xTXgw2dLtrmMak8YrU2pufRkXi0fCWZ6iYt6H0PLFEk9thWazGOA5LBKWau3cbJRc69/UGKjGv2zbCcxFV18kyHdocezEMhXP/gpR4xMzs9/IizFPU9pU2TlhUQB5KhIt8tqXY= 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 filemap_splice_read() to use file->f_mapping->host, not file->f_inode, as the source of the file size because in the case of a block device, file->f_inode points to the block-special file (which is typically 0 length) and not the backing store. Fixes: 07073eb01c5f ("splice: Add a func to do a splice from a buffered file without ITER_PIPE") Signed-off-by: David Howells cc: Steve French cc: Jens Axboe cc: Christoph Hellwig cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig --- mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b4c9bd368b7e..a2006936a6ae 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2900,7 +2900,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, do { cond_resched(); - if (*ppos >= i_size_read(file_inode(in))) + if (*ppos >= i_size_read(in->f_mapping->host)) break; iocb.ki_pos = *ppos; @@ -2916,7 +2916,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, * part of the page is not copied back to userspace (unless * another truncate extends the file - this is desired though). */ - isize = i_size_read(file_inode(in)); + isize = i_size_read(in->f_mapping->host); if (unlikely(*ppos >= isize)) break; end_offset = min_t(loff_t, isize, *ppos + len); From patchwork Fri May 19 07:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247759 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 2D435C7EE2A for ; Fri, 19 May 2023 07:41:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BABD790000A; Fri, 19 May 2023 03:41:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3502900003; Fri, 19 May 2023 03:41:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AEE590000A; Fri, 19 May 2023 03:41:24 -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 84CDA900003 for ; Fri, 19 May 2023 03:41:24 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5B70EA09E8 for ; Fri, 19 May 2023 07:41:24 +0000 (UTC) X-FDA: 80806209288.08.A695F9B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id A43D540013 for ; Fri, 19 May 2023 07:41:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bke55Y4t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.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=1684482082; 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=sXlwBEApq0PjRnmqqIdGIYb9yjH9GX5fVKdD8XUANt8=; b=h6nLmoexVtBWLWymO90X0sgtxnspidDBbzbICWHF8jFTYPKDw80r3UAbPPzNOPA5GBQ3Oi bjNbLf3Ck1EblzyKIfaNEOxUMEqqzZQ2f1XuPOwU5Fx+Ngi3vtDXkqGZO0TsehoD3SBfF/ cfwZxQE7IiUninxGUvUkhFyay3DQ+hQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bke55Y4t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.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=1684482082; a=rsa-sha256; cv=none; b=pZBp2eUaVj8+sQpIePnpv7qYG+NO7MWdFmrnudHM5+15GaDba1oRDrQhRKMB1gyDoifULO Vcohls+hsVOskNnkMXKsoIN9BwkvxX9xBqTsarmFWOk74gghZ0X84qdZ2+X4wIxhoVKARQ LjPwKkbUm+4VFP+dy62kNY9L2PxfKv4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482082; 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=sXlwBEApq0PjRnmqqIdGIYb9yjH9GX5fVKdD8XUANt8=; b=bke55Y4tkS5A7duHl1U8gjo/oH/lcZCoMhyPHkoSVYX+flsjJn6u93M5oPB4cqI1DiLorx a4lA+zjjEByjiyTlR8DubY+GGL3nR8UWb9ES2mqd0YU5YOwzJ1Eegn5FMp8Vyzxb4LLYQh dv/4yuUZ6k0KL2a7UAEXyQtD4llCa2Y= 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-1-IyiQq-xAM9m13EaOaEApEQ-1; Fri, 19 May 2023 03:41:10 -0400 X-MC-Unique: IyiQq-xAM9m13EaOaEApEQ-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 E69E5380450F; Fri, 19 May 2023 07:41:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B6F2166B25; Fri, 19 May 2023 07:41: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 v20 02/32] splice: Clean up direct_splice_read() a bit Date: Fri, 19 May 2023 08:40:17 +0100 Message-Id: <20230519074047.1739879-3-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: A43D540013 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: agx4xpm7c3kxy4ghj9ukhyssakzp7ryg X-HE-Tag: 1684482082-93894 X-HE-Meta: U2FsdGVkX1+9N60a+t7PSS7h/TS2NFZpgjnRKd7ogfrbh7fHuAtZ7wq8aYJpXACvED7DO+DKdxF7rPOC8BDgTzM+mqGAKDb6eDtI+m6o0PWUQygKJ5xrR3v3VOuCKLZYDQ/u/oqpsEvN0nHkVeaNZW+cRNaOhrYsyXV+v+caI/9UIMors6XYPCfIqjBTuKbiYyAlJeVYwQi+ctZ9QWVzUF0RaaXynRTDJ8q0VY0XgkPrw8Awe9EVsujfxSUMdQVU/0Z3Ldtx40AtMe4YpH+O0WFQKkQSDOIORcVg1E19wphiMJKE6ALErCyrjQt78wo3AKxJ3upUpGQ67ZRcE4iT2fSO+ZXQnVh/h8RzDCLSZq1pRmuO/qOeAa8blPfTQrAO6V7NRWH5wTtPFV3UmfQxv4OH2MJhLok1ZHyPD7VQdouf6DnbdIdT+Hs0zaNvx24aTiXqMZ7I4bl/Dh7AeCGlm47dXfLsvudOslkguWxJyEMCrAvZ7Jsr+HSXzKYeQQ9d5/42hKYNCa73H4zWqEcXG8LdPi5giAuAwZ2tF8OcK85ymjgjrxts5uFrHz9Jb+UsBcAlgU6D8V0re7wrnUDmb6x56Gh93o0aHz4KZj9JNdHUZROmJFxXJs4l876c4NPzOMekM7V0S9+0J4u4Vptz0CKncRopaAekVOlC1pjnqVxGJ9CHDigiTDndipKH8at/yN4Pkq5phIAg0V/ttz0HbCMCc7f5N1He8YJYu634QTzg1cc8jqfXTezKEVE34hyYqcQNRrCedhrJVO6md56Qcr/5f8A60w7PQGdH55tzuOtcxd7zI7OoJqTd2Fsh1NsXmAsE2Hit1EZkOd0Bzm1fn8ruDx6PrCAYXb1QD7fe6f09hBdMtO6Hex7lV99lyXTxbNC8nEb2ydxIPBMSFVvBBjvfK9a+5RX+UwIsRQvsol3IuxVtUy3mH1SfljSUv0r2jPr+Pp0LpDvBxImpYct ljo7wQ/T aJi6ulIF9UumI3pcHPAboC7y77HCyEUT6JN7Aig8UOw5amHXDZXHJl8wxuNco/1WECLvuTy9l56CPGeNVGyZAN0NZmyDiGCT9Z1SfoPcMaEkwU4nRoCXPiPo9h48x88TPRKumSV6oOVFzDz20zOw2IBPoQqB1zbniF5jJ7Gly8ucDeeBDlVMUxOHpisxi1t1CMYDCYuQEXUQaG9hGsx3DmI1sg7JxBoxO9eKr8F4CFfHh5wG/ZqScmIHLZtdsUQbXRd5JyvoXcxi2DFWxww2GwV1tRr/pzL2qYAzu8myOpIlX0yWpSKARaTAlsTK7kywZpR4s3hGH0saLz2MDr1KBjmGLYNuhR41+lNU5bubHITUjGa+HMkSpMPmEeDuPdRGR2+WspBf2SEb/7TsjnUBZKLkeP9GrZWmV/HJHAgWUbq2ukxX6+aMEqbmd+C12uH4zsBvtsyiBs0jQoSxc+tqkDnDHICO2mdkyF0/d 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 3e06611d19ae..4db3eee49423 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -312,7 +312,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 */ @@ -326,7 +326,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); @@ -349,11 +349,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) { @@ -366,14 +363,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 Fri May 19 07:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247757 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 CF091C77B7F for ; Fri, 19 May 2023 07:41:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34836900008; Fri, 19 May 2023 03:41:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F6F2900003; Fri, 19 May 2023 03:41:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14B89900008; Fri, 19 May 2023 03:41:18 -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 F1D64900003 for ; Fri, 19 May 2023 03:41:17 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B9D8516099D for ; Fri, 19 May 2023 07:41:17 +0000 (UTC) X-FDA: 80806208994.22.9E203FA 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 F282480016 for ; Fri, 19 May 2023 07:41:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CQGiE8Uq; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482076; 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=HJSls9joKnzamhDgZoRi/AKfts16br7tyBuA30GIBac=; b=QY2C8juFDPW/wwMQj/0SmeqX+mkOdSvMY4c3sZPaAKrEpm0CPwI7ExaizuEEOdLII5cTN+ e4uT7pkzhyrZsNSYWymqf+Om8LJpWj6kMap7BLtAfTfp+oKcn3udrtWJ6CvxuNTHPfdDWr ut0ttZwXmSearc2Rn3UNv6vKB+L6UtE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482076; a=rsa-sha256; cv=none; b=MhAq850JpKPd+Ar57yENIoJJxMXXbnEV8cDeP5abS4Hq6BCJ6rwWEfL+m/TnbkuFHYnpK5 1VT+/0KtRCjMcl0S/udFelNR7udhfqI/06BKKjEaUy1zmoKPjfYqBZ5R+cOTLtNCbdUO/R 8wF49A7axzkCapj5DN/Ff6uDIaWhwH0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CQGiE8Uq; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482075; 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=HJSls9joKnzamhDgZoRi/AKfts16br7tyBuA30GIBac=; b=CQGiE8UqMr9jcRe9axTcrKq+cI+7GSi7q5/skysxPFw52ESeth/625+JuWqnqOJxrkkg4S hmWVZXpEjb+7lWC3KweMUhAW8p4nKXUmnLzoPLgzRD+hkOkO585x4Pv7SdxdOfV0E1027i /aPCjFG1WUdC//9qYbgV/TiByRKaY8I= 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-662-unilBiGRMYCJnhOgY90jPw-1; Fri, 19 May 2023 03:41:13 -0400 X-MC-Unique: unilBiGRMYCJnhOgY90jPw-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 B0BCD29AB3E8; Fri, 19 May 2023 07:41:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 894042166B28; Fri, 19 May 2023 07:41: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 Subject: [PATCH v20 03/32] splice: Make direct_read_splice() limit to eof where appropriate Date: Fri, 19 May 2023 08:40:18 +0100 Message-Id: <20230519074047.1739879-4-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: F282480016 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qeq9456euhxg35ydsd4g5wpnazhqrsao X-HE-Tag: 1684482075-726476 X-HE-Meta: U2FsdGVkX1+fV6VgP8gby3OZ07C8jntPmwFsdz1qrQpQmzEY5VtWpQJBc1QozPhsgMHMJv0YZFp54J6hFKYNSLh+9iPqHGr7a4cdOX5SCBC6SVG0j16k9K3O9ms8h/l4sY/pZDd+8DwYi2Y3NUjg/2tG7AHbeDV0DCEla4/Wu2GyCvDhvs6Gb24QX9sU/7xqeWuGoHh6Nygg4fL9z5IdZ6Z0V9AjKNeerSCqj6HNFVoVfx0AAyPp0t8TsccUVqde7ODVSlhoOuHxheTcGiwJBQsQ5mwUjbmCD5p/Ec0AslWW+d+RLZ7qfY/1N2ii0XSkeFHRhuEoCKRK66ckiE+YHCIDLymx2/HMfKx/Cx4VHr0BVY7gqi/N/TMa/FKUurcMoA9IN1wBTgG1QDVavHyhRw7pqxcpaVCHTTn35CisMsS1v1df9yYwmX2m3U4/ycd3Sm6d1MpUdcQqWZ6dd0QfPASXOwZzpbY8u7wwnfAgWifjH7LREuBBmII58klR4oNO9CuZuc/mn/jS0+JpmIkBYWEwNrkAZA0pNCDQVHsVuANPVPZW4iwpfB2g+tcEbor4l3sVFuSvQJ4DoNSJHNsz/jSiDnm/B7UpxZ3or7o7EXjm/4hbQRLzAoyLMq7aZJAxe7FbklxpoMHkwj7ExKnlaCMlEx79VXSv9RZD4H1EaCPH2ZTYxWucQmHMBkKnIYg3moaXS78cQ/kTaib2nbPVjSs1hBzOOiwhfVEgBrqSQwnyKGCxSJea6nUKuS98TAlA3aAWnSu3U3NgIh40EWu3GfS8sQE06A8ZTU94qhXb6WVkUcDY2WR4OnPIbBPm7VwhivrJX5ZpGVjl+IJ7+HsI67LBBDPNU2fOYkE773ynL2hhSezQ8uwx4hsmw+ZPdssrBrNb+yq5vlId/iWOew9cKS81bJCir+MOldg7gFyy5QMETVrXkEryt3zlcqr7NJr6JmB10RngmwiIpSOncAN zrArsa3w V8WPHVOAx9D49HA4IBpL6TFhzWgxZtCMIWkwjUJ7WdisXWxDCjL4OgS5ARRQjE+e62ZbCsxJOYrfKsMiGLOPyIjmLDzE7GsUWdPf/pAYikCZYWN/b0EvE3KNZtDLmPIbbH7VbeHO3gLAUs7pkzzbtAiW2xz+FzsAFp9CeYZrNMeRVIhI4Nj1vcf2+bYp36fRc8dZZpsjZoKcFmTYodP3VOOYEi4eTwhgKZafdtoOtdbKSNjZbmudkITbh1+psX6BY5yxkOulSBGYxZwSSMRz8t5sZh7cKUi83ONY+nIPrgayPasXGHLJOfcYaJpWwHDp1jSYszFIMIs8SbcjRVF1dEHc1p/5ZFtOtjqrnxGjWiq3vKgrPErnvRUyLbqvbaXrabLJprPc2km3QaoA= 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 direct_read_splice() limit the read to the end of the file for regular files and block devices, thereby reducing the amount of allocation it will do in such a case. This means that the blockdev code doesn't require any special handling as filemap_read_splice() also limits to i_size. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/splice.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/splice.c b/fs/splice.c index 4db3eee49423..89c8516554d1 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -315,6 +315,19 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos, size_t used, npages, chunk, remain, keep = 0; int i; + if (!len) + return 0; + + if (S_ISREG(file_inode(in)->i_mode) || + S_ISBLK(file_inode(in)->i_mode)) { + loff_t i_size = i_size_read(in->f_mapping->host); + + if (*ppos >= i_size) + return 0; + if (len > i_size - *ppos) + len = i_size - *ppos; + } + /* 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); From patchwork Fri May 19 07:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247758 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 A8299C77B7F for ; Fri, 19 May 2023 07:41:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CE12900009; Fri, 19 May 2023 03:41:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4567A900003; Fri, 19 May 2023 03:41:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D0D4900009; Fri, 19 May 2023 03:41:23 -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 191A7900003 for ; Fri, 19 May 2023 03:41:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DE048140952 for ; Fri, 19 May 2023 07:41:22 +0000 (UTC) X-FDA: 80806209204.18.0380792 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 2311B4000D for ; Fri, 19 May 2023 07:41:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XhlFMc0R; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482081; 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=ajb+DQf4ARiWjgPxDf7oBmcuXX7xbhqUpLXrqXXlXzo=; b=zUxFwbB9wFBozoShpdbuV6uYIrB+8z48MCOGIf5HEvMjSXmbMjevdlAsveMbyBWLZwAhFZ 7yJ6CcFBkt3wYYgnXH+Kmi2IaUHU1YOPCfB4/zsSg41F85iF0ZFrSQXgAoUJ7tlsFfjR/I fcH1UATbOU4DzItnY7d6ZqEon+gtXxU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XhlFMc0R; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482081; a=rsa-sha256; cv=none; b=s+ZIf1fjR2ndXTKJreDjpJekFK85fxFou2Do5zOapW+CB7oaFvFukliacVlX5ZEap79rDT YYACpcyVtrINSshK8YxtpuNOf6IAEn5PSSfpoDD/1fsjosmoLONAAWJQS52EINxJ06QESp RdJGRWokTU/vbc8LTwD1Lpob8HWfWfQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482080; 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=ajb+DQf4ARiWjgPxDf7oBmcuXX7xbhqUpLXrqXXlXzo=; b=XhlFMc0RFcHJIcCRU/SK8YyKjYUG95u+8/SICN1xjrB06mOikvFjnwfCYHV3yfsjMy29fN caaUPRecK33avpZot0RTcERGU9RONf51mbKEfcbX0rcrRBrk/+/dduTUziJ2qfajb+DG0S uUYIHsJewSfIFTDjRlBXP+VHN6/PGg8= 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-650-m-DjV4UkMcasoW9pDJqpqQ-1; Fri, 19 May 2023 03:41:17 -0400 X-MC-Unique: m-DjV4UkMcasoW9pDJqpqQ-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 4A7D7185A791; Fri, 19 May 2023 07:41:16 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EEE77C2A; Fri, 19 May 2023 07:41: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, Christoph Hellwig , Miklos Szeredi , John Hubbard , linux-unionfs@vger.kernel.org Subject: [PATCH v20 04/32] splice: Make do_splice_to() generic and export it Date: Fri, 19 May 2023 08:40:19 +0100 Message-Id: <20230519074047.1739879-5-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2311B4000D X-Stat-Signature: k4jtrtui7h5homfm5t5suzyt5r7opkh5 X-Rspam-User: X-HE-Tag: 1684482080-567712 X-HE-Meta: U2FsdGVkX18u17O4VLCc4LBNGS1f2WjyUQ+F5S0jsZ8BjmkgNGG7hLFeCUss5fnSpoYTeofRZRGKoTpDxaLr34f3UlOJClBR3GbHsV3xWJHv8TdWCBJlHl+Sc3YQ0PceKz1jou2tRDM0X/m9UiK5U1RRAqocnGM6t8zOh5FgEYrmow7N+/abtCWMRJYOhkmMbiHkireMukNoqoJzpt1ShfOREVZEB7LJfVOpESHAFMVooEcDaYjU2J6RyoFQB5padLoubUbTeYCjTNiJpNpnN8jH7uKG6jFvvWbUdmBnc2eVB79+qyflGCRlD4lbYYg1pbj83zr7RLp/qf8BjwJgxx42LTeV4lgyXKzgbMp8oJjsa+0taQGtA4d4v2+ud4k6jW7XDA+ZAxo1bdmiue5CITRcOpNkzUFIrUI7PiyN3koZbLRIQY2534VD0DV+MhjnLSUrwYIbS/ieK4vPxsOskfdjwVZHchgcLsdTPjiQdsnqP+cND6jWQhfFs4BjeNFdyQvFoiOV16P+2xk3/+wgbQYIIRC/6n+wkb6DaJ8F+0IyaGVJKuDQAdBAxUHcIuLTQJalM1nPdwPWu7OsFSEEMvoMZ5/Ae4oTAlvdUC2qYnPAEMqfHbztYvRRgL/byJpWfcuFM88Z/ArHkMteUhtM0Fw5yUowDHiK81d19wR6sTjJ4QyJm3SrKWg2tMZay9zkDeVish9BuuOrkpIxQRYRor8uU/cAz4QWEtZWJ4W3rIlF06/3QnNeFhpgvcnsWmp70KlZnIEi6J6KYQjaVqgdjtGvZWGPLcPg6uYc2siJGiThE702nDKx3WS2NEMSrzDcS41g5YnF3M4u2L6Eo97HX4pD5jeOGVNG3tRO1gfjrfcABbxePA36M8smeleqMp+zkdSQxhlFv1GBFAofXLfnQbnNnPdyKaKxzACIr9Y6nV9AdZ/St+JMKFZqBEU4eWYByAb7C9Kn1csuCfOY+vm byHFPsI+ w7qcIhsR+7GoUtZByvWJV2+fikzXF3S2sKJik7JXRwbw/5I7DZYmd01h9LhLRjNTCnJd/ycWc2gASaL1rvYD+xotGr/3tZ3XqNqgwaXM1WtZ3x31aoiA7vRnZNGb8HWtmoZCMKr+4ryjYbugVsLHHtGLtYu2vfNUYU5exTZ/E65mbgfsJf7s2UtBCZ/beEujH9pJqLTbvbF/g1K2Fz2bOohWCLxbHKCTtIjdK9CLMGDUAuF2MDw1hg+Aun7BlJSP+CreBfGtqNtbe4ph6VmGcwxWFqrP9SXd7Cz+6tl5beVtn4e3bjfFMohO4nWv2wY4meDwipbU9PuVGBOyyNH5eqFN2nLNYfFf077vFKynSiQfuomxyqR83bvJOIPObO2qxQyUqTfVZ3HF5Vx4Q0Ewg5u1mrBBu/f7PWFOkiQo8TtUS6muXzDHecJlXPVY4qFSkrviZx5jnVkXYJ4e5WBwGgeAzDEMA0uGq0uUFkkKWKihTsMW3UzDLQl0WHFWVjXnyPeNx 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 89c8516554d1..1e0b7c7038b5 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -881,12 +881,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; @@ -909,6 +921,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 @@ -978,7 +991,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; @@ -1126,7 +1139,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 Fri May 19 07:40:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247760 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 069BCC77B7A for ; Fri, 19 May 2023 07:41:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 988E590000B; Fri, 19 May 2023 03:41:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94280900003; Fri, 19 May 2023 03:41:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78C8690000B; Fri, 19 May 2023 03:41:27 -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 69C28900003 for ; Fri, 19 May 2023 03:41:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3D5CD1609C2 for ; Fri, 19 May 2023 07:41:27 +0000 (UTC) X-FDA: 80806209414.29.F504B28 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 925448000D for ; Fri, 19 May 2023 07:41:25 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bLMgAMpI; spf=pass (imf30.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=1684482085; a=rsa-sha256; cv=none; b=BlBQmyxPQqqPDtu5cxsYyA4V+RTZWnxk8SX+GEO9vki/Azg0SkhoIL+ioT0WoeqJ6AkxMR oGCVphpwaD6e6MK/L4kTciHOcFsaFe+goCvG1zmY8okXscn8v+5Zct3Fhc+kVPo+CwlIVD RNeL4d47ySlPuxuis9qF5Kybfrdawnk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bLMgAMpI; spf=pass (imf30.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=1684482085; 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=ChgLSgSgCciGGEj2txPdAcXunor0ElTQJtr+fuEaFtA=; b=pbL6BnJw8uVt2Xb5uAJQtVfipzP6noLxMm2YqiLsJwa7h4qrfOIgNnW8TQnXiBnC2+rxNe Z/1QTyOxGQNPzealgw5e6GlcZMfmQaC/kOOxfPBNvAyMBCGPw8eicb9TMIWzyw/ZmisTpf yuHbESClaLtpnRwtMgspBwGTFEhABOg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482084; 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=ChgLSgSgCciGGEj2txPdAcXunor0ElTQJtr+fuEaFtA=; b=bLMgAMpIsVYMz8TJBPhEXzAnq2HPR8IS/mb78WVND7HX4uzTMCL9cyazAj6p1CXnYAZ/Iw RvMAQCGklDEu2euc32X5nYHjDH63BP4NG34+RLK9lbjdQc3f+lFqUTEmS/ilIc/tbumZrC 6+WscMEpCfY/i8yA3RRIamjXmJG5B60= 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-673-2UnIjJkHPT6ZoSIApCo6vg-1; Fri, 19 May 2023 03:41:20 -0400 X-MC-Unique: 2UnIjJkHPT6ZoSIApCo6vg-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 3C96E101A58B; Fri, 19 May 2023 07:41:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D833E2166B27; Fri, 19 May 2023 07:41: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 , linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH v20 05/32] splice: Make splice from a DAX file use direct_splice_read() Date: Fri, 19 May 2023 08:40:20 +0100 Message-Id: <20230519074047.1739879-6-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 925448000D X-Stat-Signature: 7tgf6ubbta76ksmkkniz6t597x9anyam X-Rspam-User: X-HE-Tag: 1684482085-200866 X-HE-Meta: U2FsdGVkX1+bm0KvuUl6Ka58hBsxMsJTNdCPaiPUaLiHaPu2NEbMl28NLmZeKYGLLXJD/fkEe1FchhDj17BUAouaD8bGn3grS+jC5GKwAbCQ9RZAwpHRBjReiM43XB4rHi6dQU0fbhgmQL0DPOWxfqL00xVBezNozGWN0AlhXLEBflPR7DXbt5a5WD4xleyjR0EMyU8PqNXeYsjhRsCtmehCup/Zp1VBV/m23he8SIM9Nlvrwaocl3czeZoA1Tr2ikCJm7pUa5dp4WkrDqyQdn87xqpnK3ZrtsSEZpgEwTq0YE0lGsfEMfS1oAAbhjB/OVBvagBaNcoXbh3iVl+Tj6Aw3g21pjIi6hS6V47XkCaHHA1GZhIpFshS8ZjiSuVZNTYnVNMN5Iz9EXLguM01GbCuVic1DV3Y2hkAh5ZpR/9ZYXdsM/AOl1QmrZGwLRwOXyzCv+UUpb8SqnXcN1jkIJiY+zeLVEnFqGwNS+GmPV7rTgjaj21FvZfoyJZrebXDVQwA1uqN3b7wdMNGEQp4MRQmzyuWZLR6vBSZqAzY+gFShsS/sjvLtx1qd/zaNzyt6HH93PCom6Xw+1Y75BLxDespDYOXnj7jFg54jDf3gfwXj9Lc9d1nCWEMQ3GYWOmZR3uMY24WzHyGS5Ot8Z3JZF03Tmtw/LOH8EiTkMo4u1MrfrV7ajWovkSQus6rEvhJQCA3LKZtKBpP6mp4kEXL0R9uFoIMMLIv3kU4YBgwKyAHqH1m0SVlOIirB6s0JlO9LlJR7qZLQ8EU8gdCmRktEiR63Cs32L2lOPFCpUAfxOs6HGixqftI5hsliAez+JS4pDp4sPQ2p2c5iul0TQOSOKYDGKdMKvrtrxKULLA/IusqgAT9MX8tiHMBXciL9FAlmYWFtACO0oIW0DwoWpcSUbxut2slvAw7Y46K0gntDB5vyleEcYOzoQMw7XcJ+a7Zs/8lu2ldThOnKQJHdCt GAOFxl2g hdEj0rM6BiCiZXSGqS5wTFK02XlOiCO7f1DWDlSqbIgpaeauIM/+Y+cEh84cwZDDOYh1KUxoxXNa9lZDntLAlpFp0ySqAvDIXOJBnpcWJ/dnustv6XQA/8P13QkvpZZah/WmGmgc3kDdOOBc/M727Pt5N15AGUkCj5raPRN+xOPllanMaGzsDZm+SDXXoFTot2G/h9bs9L7OosItH/rwRhk+0JP3yvGGmtLM+Z47SGsgKJWAuCOUCL6kgS28Z+iiGUie2MERaWCIxWRBGdFmhswg+iff6//beaWhM20/WGz+K9yU8PGo4x34Iik+yM6O1BAe3V7Z6wWkeUr5apcAgN5AnOsHq3hkduKd6FbHvjN5hAHl5LsELo75yxy+xTI4QFDgs4DAckIwtGbN9C48swQLsRe3h9NuDxZxN1eRbYvp3/AoUtZ/EXB+n5ffluHT/0KE3xTVRET5hFbw= 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 a read splice from a DAX file go directly to direct_splice_read() to do the reading as filemap_splice_read() is unlikely to find any pagecache to splice. I think this affects only erofs, Ext2, Ext4, fuse and XFS. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: linux-erofs@lists.ozlabs.org cc: linux-ext4@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/splice.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/splice.c b/fs/splice.c index 1e0b7c7038b5..7b818b5b18d4 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -421,6 +421,11 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, struct kiocb kiocb; int ret; +#ifdef CONFIG_FS_DAX + if (IS_DAX(in->f_mapping->host)) + return direct_splice_read(in, ppos, pipe, len, flags); +#endif + iov_iter_pipe(&to, ITER_DEST, pipe, len); init_sync_kiocb(&kiocb, in); kiocb.ki_pos = *ppos; From patchwork Fri May 19 07:40:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247761 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 2087CC77B7F for ; Fri, 19 May 2023 07:41:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC1F090000C; Fri, 19 May 2023 03:41:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4AFB900003; Fri, 19 May 2023 03:41:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 828A790000C; Fri, 19 May 2023 03:41:29 -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 6D5BF900003 for ; Fri, 19 May 2023 03:41:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 360D2802A9 for ; Fri, 19 May 2023 07:41:29 +0000 (UTC) X-FDA: 80806209498.13.5EE3E4E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 8191510000F for ; Fri, 19 May 2023 07:41:27 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="c/j2Pl56"; spf=pass (imf14.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=1684482087; a=rsa-sha256; cv=none; b=Zba3hAPNLpjYQQ+ADTcxcqAHHHrf/nt4kkEBAS+Cy37kFSeLPZl1MYXn4kSN0bb5RQ5CpV lEKLze5XOLbUE+z5nknUjewj4CNpmue1jciYEAd+Juu/3yzDn+M+LCUxBT80WHJwJD/rnz GR8iGh14tRMzc2+gCK6uPCMEHa1vuoQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="c/j2Pl56"; spf=pass (imf14.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=1684482087; 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=KUqjynheJXCaLvUnn68NO8vUOrcgRITgr951Lzay0lM=; b=Wo/7zWjJCa2cEyBiyrgbMTdVu2j9xEs2bydCqX71SI4Q06znPyQ4nToTxQilADesAUOZfV pSpb8qcppfMqHXsfalixUZGxVqAv7fUlDuiriziugSA3vnbPmhKpaCpNvzGoESfzzJp04d 3ViPiWbDvqs38qBD1x3420eyfFE91LI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482086; 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=KUqjynheJXCaLvUnn68NO8vUOrcgRITgr951Lzay0lM=; b=c/j2Pl56MKGlL9FpkmZw+GJfSbhBjaDsR9L/8vXwdXhOtdwzA3vc4ZudM3i/r90O1Jksbc 7/7Fw2qGkjqf4MDSJyxRJgkluDOt/tOh/zsR5Ou/s8/p/8aEiIfVVHJ0vgPzGSrpR7AWDF mlHDve4EScYpWKZ7kYAFKWLH4Zcj7ZM= 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-81-zAQ1Er1WNnaKexqCxzJVJg-1; Fri, 19 May 2023 03:41:23 -0400 X-MC-Unique: zAQ1Er1WNnaKexqCxzJVJg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 63CC129AB3F4; Fri, 19 May 2023 07:41:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB0B51121314; Fri, 19 May 2023 07:41: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, Daniel Golle , Guenter Roeck , Christoph Hellwig , John Hubbard , Hugh Dickins Subject: [PATCH v20 06/32] shmem: Implement splice-read Date: Fri, 19 May 2023 08:40:21 +0100 Message-Id: <20230519074047.1739879-7-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8191510000F X-Stat-Signature: 9jspb8b3jgbpxwzi9e8qo69kdwnzqmyu X-Rspam-User: X-HE-Tag: 1684482087-192775 X-HE-Meta: U2FsdGVkX1/JJnOyxbzywXMYpx6d5IhjAV38ByWGt5gG4N9T9EqOV6a493aaOhe7UKalaryW3Swm3IthApCIT3eYQ6s0a1G9TTKTZ6KvX4nrgPNxBkKGiTNwYkzA2ML32/2PhsMzSVTVAIgKCMhN+6OLrwJR09tNDr2EjXTvA3TMfWhem59L6dfQrDGY7qjfFPD8Bfhs9EbZZ0xNJzZwFzPtl0/GFPZ3epw3XtbcvAFJzsZQzdxuURS6YYukkjJbuH3pRJ4rlSOhrDs71hIyJD3JhfTJ6OzouVNrespoRuM5VAV7TYV+TAHc2dXw1c4mnGIi98nFuO2oDycDi1RZ6jW703nM0/2OnzxDLsQixgvSaYxHHQnn3mfjKXKMR33BNDc0zlnTnZAEnI7ELCT875ljjqMryEHoaBcGHZc9uDhm3qYHhTC5uBYHe2dBsGVQohuixJ15t5UbjJ8GM8T9SzpzbU2ahTKaShNA9RZ0acYKJdWWwnMJh5i+T/IV7MIR184NOQOiYVsx/n9UFOm3kdlejShAjaEAqpmnSCkIasUFAm+IS/uDUOtShxbod5LFUCTY15GmPzsGwxCkc1k2fnfh29pFqPCcTbbcdWOMGm0Z/T4fToV6XNXBBwSYyj77Iile5Vk7HjwVTowA5Wzx8FVtVmNNbLRuOdPFE3BF8PJyMjNpUrRt1MwwUCsJqBa3UXkK+F8xMBpp4fjqV7Ebl6kx5MOiY282bZ+uyewwbciAdCgC60c0jXHuv5ZV6PZ/IuLXC0qssSPWOWd2zRpoz0+5V7/D9Hh65d/yFzWkMYBc7ed0W0USxKQ6kMllYyD2K7+5PaSPJhcP6a8n46c+OiirIeIew3iSyfvEARtsfdqsC0uG9X9fZpwd2KRy1B8XKXVB7lldzABX2HF4tVe66J0FtKv7lN4hvEnoWCMDuV8o+vVxi9U57yMILRsC/pv7qjZa8q0cyZTsjBJT85X 5lUlzb57 yP91Fk9cijW4WWmlOgQ1gIc24EmQ97qNi7Vbjb9Wt7D9/xHYg71RBLAHNO/qKHIXroD3hF4ZsXnTDJIBBBndElpNkDE0TLr9GljnqTqNO5OGj5beWGbRimedhjK534V0BC8anmxIFUxFvniwLCjKzQwQiSnASm8LKsVNm5YF157JgF/caqeR4TksZSuh5lg5xnGFaD6Q6IQiVETD58X3EGty9WugzKMnstKzytKYgdc+aMahLfX73fEDyF8q7OPEjO2U2Hf9hlrWy7ntHUz+gJ+UjD0VU1a4dQkdzdAdhUrov5GNPb9+/lAp7HAliqINRV6se5fwwRboioccDY2h8cwVKJzdCpuuEJM4hmkkvZWpLBvhKNz9eNZhLtcoB/u1xwdTbZakX6l3pRLXJvPq+glAaXnmCYg8zYs8+kgEcQoF9nbI/0O1pNJCaDgfY2tGePbt0tP9Eq0P8HTbdi9hg11To8GVqBQBOcqH6AZVbWd1cTbOvYK1ddx8qeafsMcCHOcxTDy91No3aC/N0s+pzjc8UC6EpdvSSlUqA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The new filemap_splice_read() has an implicit expectation via filemap_get_pages() that ->read_folio() exists if ->readahead() doesn't fully populate the pagecache of the file it is reading from[1], potentially leading to a jump to NULL if this doesn't exist. shmem, however, (and by extension, tmpfs, ramfs and rootfs), doesn't have ->read_folio(), Work around this by equipping shmem with its own splice-read implementation, based on filemap_splice_read(), but able to paste in zero_page when there's a page missing. Signed-off-by: David Howells cc: Daniel Golle cc: Guenter Roeck cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Hugh Dickins cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/Y+pdHFFTk1TTEBsO@makrotopia.org/ [1] --- Notes: ver #19) - Remove a missed get_page() on the zero page. ver #18) - Don't take/release a ref on the zero page. mm/shmem.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index e40a08c5c6d7..1f504ed982cf 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2731,6 +2731,138 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return retval ? retval : error; } +static bool zero_pipe_buf_get(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ + return true; +} + +static void zero_pipe_buf_release(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ +} + +static bool zero_pipe_buf_try_steal(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) +{ + return false; +} + +static const struct pipe_buf_operations zero_pipe_buf_ops = { + .release = zero_pipe_buf_release, + .try_steal = zero_pipe_buf_try_steal, + .get = zero_pipe_buf_get, +}; + +static size_t splice_zeropage_into_pipe(struct pipe_inode_info *pipe, + loff_t fpos, size_t size) +{ + size_t offset = fpos & ~PAGE_MASK; + + size = min_t(size_t, size, PAGE_SIZE - offset); + + if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { + struct pipe_buffer *buf = pipe_head_buf(pipe); + + *buf = (struct pipe_buffer) { + .ops = &zero_pipe_buf_ops, + .page = ZERO_PAGE(0), + .offset = offset, + .len = size, + }; + pipe->head++; + } + + return size; +} + +static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode = file_inode(in); + struct address_space *mapping = inode->i_mapping; + struct folio *folio = NULL; + size_t total_spliced = 0, used, npages, n, part; + loff_t isize; + int error = 0; + + /* Work out how much data we can actually add into the pipe */ + used = pipe_occupancy(pipe->head, pipe->tail); + npages = max_t(ssize_t, pipe->max_usage - used, 0); + len = min_t(size_t, len, npages * PAGE_SIZE); + + do { + if (*ppos >= i_size_read(inode)) + break; + + error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, SGP_READ); + if (error) { + if (error == -EINVAL) + error = 0; + break; + } + if (folio) { + folio_unlock(folio); + + if (folio_test_hwpoison(folio)) { + error = -EIO; + break; + } + } + + /* + * i_size must be checked after we know the pages are Uptodate. + * + * Checking i_size after the check allows us to calculate + * the correct value for "nr", which means the zero-filled + * part of the page is not copied back to userspace (unless + * another truncate extends the file - this is desired though). + */ + isize = i_size_read(inode); + if (unlikely(*ppos >= isize)) + break; + part = min_t(loff_t, isize - *ppos, len); + + if (folio) { + /* + * If users can be writing to this page using arbitrary + * virtual addresses, take care about potential aliasing + * before reading the page on the kernel side. + */ + if (mapping_writably_mapped(mapping)) + flush_dcache_folio(folio); + folio_mark_accessed(folio); + /* + * Ok, we have the page, and it's up-to-date, so we can + * now splice it into the pipe. + */ + n = splice_folio_into_pipe(pipe, folio, *ppos, part); + folio_put(folio); + folio = NULL; + } else { + n = splice_zeropage_into_pipe(pipe, *ppos, len); + } + + if (!n) + break; + len -= n; + total_spliced += n; + *ppos += n; + in->f_ra.prev_pos = *ppos; + if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) + break; + + cond_resched(); + } while (len); + + if (folio) + folio_put(folio); + + file_accessed(in); + return total_spliced ? total_spliced : error; +} + static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence) { struct address_space *mapping = file->f_mapping; @@ -3971,7 +4103,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 Fri May 19 07:40:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247762 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 E657FC7EE2A for ; Fri, 19 May 2023 07:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 803E790000D; Fri, 19 May 2023 03:41:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78AD9900003; Fri, 19 May 2023 03:41:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B6C490000D; Fri, 19 May 2023 03:41:32 -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 4BE3D900003 for ; Fri, 19 May 2023 03:41:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 16E418098C for ; Fri, 19 May 2023 07:41:32 +0000 (UTC) X-FDA: 80806209624.02.5B1A022 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 543DC20013 for ; Fri, 19 May 2023 07:41:30 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D2SHVNFa; spf=pass (imf03.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=1684482090; a=rsa-sha256; cv=none; b=FWBkJyrsDRElA3aiUsqX8MMx7CHqz/0MgO7mMhFvAKYdcNg3u3yPyogKfFVFTRZ8WH7qru MmhmJY5J+a6AwhTixI62ogu+b7P1e3PkI5DEUURKoe3XWHEngEgda7vJRNQL/TuL8i69+o pXl9QrpJmR+Qj7yLfDdiODiNa4DUw7U= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D2SHVNFa; spf=pass (imf03.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=1684482090; 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=Lnbg1Aqcg2VN9k9RG4NO8lyEKAYVqP4uqJvLGQhJTanEntCnayun31nkNdK7u5ZwVbFVNJ vmZnPLY2eWFY7CDaPOzDUEuIDLQOtTRRe+2iUTLGwc0an8EPGBPjV1Qdt1qWl0N9DIBLHs t7x0RjufA2mc3n6W07Jf2A/eDuL6leE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482089; 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=D2SHVNFaVrDaOMXstah3E9Ncve1zCPNrv5du4jxn4QC/KvAeVNMvt47UYocxaDllK5eOe6 TUczKNUVrUpR/ib8YXL5kM2XPaiiaJ+Qb9d3Ll3R3rApbCvQZaWg9V1pigLgZ4SQrJJ+mt NRRMLH4hLNxSLi8XCFYTyVFeOE+iBGk= 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-271-zhDNyJpoN6uuRXwKl_ogyg-1; Fri, 19 May 2023 03:41:26 -0400 X-MC-Unique: zhDNyJpoN6uuRXwKl_ogyg-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 591D03804098; Fri, 19 May 2023 07:41:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1119C2166B25; Fri, 19 May 2023 07:41: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, Christoph Hellwig , John Hubbard , Miklos Szeredi , linux-unionfs@vger.kernel.org Subject: [PATCH v20 07/32] overlayfs: Implement splice-read Date: Fri, 19 May 2023 08:40:22 +0100 Message-Id: <20230519074047.1739879-8-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 543DC20013 X-Stat-Signature: yof99n4m1qtzdfsmp86eugx61qw5uzr9 X-Rspam-User: X-HE-Tag: 1684482090-844376 X-HE-Meta: U2FsdGVkX19Tj03wO5d2UVJA3B3y7ZmQv50gZWeuV4XWImPh9nM69w79/pAi2RalnVJPXeMuOrvkxlKDjtkVKVGlrZizmr1+NFvkZLP9s2RUMGLvy5PJ5sjvimR7mq/iDYbsVwv77ekrpzCbDODeMqgJzRNp4mOGspfiKv+hNnTh/heAzLTDZD+4cpfmLeXEoxqv+eGF4fZZDObA9L1Y+vIh/zrU+mJ3UyAkPhgGMb5UTJOy5ckcJP9PmCIPZ4VuBbnjCfGiEDxSekKUhFxMGZsKh3GPtMQ1jTEZRsvA2WmJSAIokifgPgZgSiC+ECqsae9BjkwF9O1vzAcmQ97ZwsxOzrhY4TAw9CLKJfLbDnX9OfIAvaKToYmyzgpRKL8bkkedXAM9WQiCGpMWzgMQVKtk4o7pY+VOP877zV6f5xJqWxB4XqomzSLP4PlP0O52/gtdwXY9YNjGjzkrUbtFWMye7eRviV1Kdm3zrGy5b/o5y+irCuxhCKcut1GRIIBe0EKeUZQCFh5DasjILN9+nLkWuzblKNiZFUTkgOxNXc6Ei64foikljr+inwCn8YGqlzJl0VA1ZOg2vdnHF4MFVogOS3eFRo9a5W7gohjwQm9LpNjZ8ueQm6fBruCXcYSbMPsaiHCosfDOcL+gKShN+fHKFGcwGhHZxVFkZm1Hh2SneCD83W06juNhMn9EMVmq3rQp4SCbn9La+hGReJRtSrfBN7ZOGEjbj/BzEEM2KVaKdaAttxzsB8OIEyCfEn5iTBwA1I10UoTvk3xHN0uCmJx2yXzDX9bGCkLMMMxDz8lbezXhKfJGWLj0Q3ZT3uoGpu07fI4FZAgwt9pjL9B9tYH9t9r/ZXVojhdDl7Uus5g1T9cGaEb54V4AqBcHTuPiZfh6x0qsD6pHib6nkHjCK7oc7TshbWvmUpnzZTmQ68I/yQYiS9rh6UiILtRmt3aS46oFsrbCQAJuWS+d16T V7Rg4tQ6 No/f28nzyXMUveGYk3XydHU9Qxty4gUogKlqi0Fls7NPR7MTQJ49k8aDew6QgSJgGJ/zG1cracWZFEuiwbQmetRUiJgWwoYNkoxn1o8AkF435ffcYlpzaxv7oln7UZUa4gkZ6HiAdvyskRGNx5Y2GPortSK++9NxVqZMvHIrK3HjbszO5TZaaYIC1d9vo4dX4vKAGd9PXsr9toHi4cH+R6Au7z00cC/CNk5q21uzvfeiV3mPWyYUssyK6/XymgAwuoyRUdrFx0cN/3hLyiO7jMKEJJIZdOuIQIj+ADBol0CAoOTXYBiCN//hEX0pg1rv1RJLm9I5JuyPToN/HSbjEBdU0v23LZfGNQsfgHwgubQDRJzgMgPfTjvanOcORai9Icxs1DMGL0gYD8Gtg0zTqHEI5z79PUrMTQkotir62bi5X6vyFMojwH1KRrA== 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 Fri May 19 07:40:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247763 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 5A89CC77B7F for ; Fri, 19 May 2023 07:41:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EDD290000E; Fri, 19 May 2023 03:41:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E57900003; Fri, 19 May 2023 03:41:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A30990000E; Fri, 19 May 2023 03:41:33 -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 59FB4900003 for ; Fri, 19 May 2023 03:41:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2640A1609B2 for ; Fri, 19 May 2023 07:41:33 +0000 (UTC) X-FDA: 80806209666.24.A9B2F4D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 7A0728000D for ; Fri, 19 May 2023 07:41:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="T/rNQk3U"; spf=pass (imf30.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=1684482091; 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=vPjrjhiQt/5heMfgoC9V3vUMTVvHc0mi6B7m+VDoI8vYuMhneoMntYswZn7HMD44mDQ+F9 rOHiVXJwLPWsvCy3TYAkXxT1XWShU05Ql2yIrHy93e2yBtjHzM/wdqmeoqpNEwKAzeVV+p m9vAFZon9tK9i9UBmkjthx8KiuTePbo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482091; a=rsa-sha256; cv=none; b=eTMTS9EWIzwcTsmBveSkBv3Aty0kZU3052MQVENtE+eRVS6T9eOFujVPNP7NM0C0CC0vqM QA/ivUYmBe2vfrYwRyuUAATELYPMZnT3/3bfujYsRX6Qr/0rnA4tG3cKENb8Eo+u7fGNpi 5EdLqkxivr78O3RcwgcoTMSx8TXvV8M= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="T/rNQk3U"; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482090; 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=T/rNQk3UCv5M3nTihypGmgF4aLgMwedgpWDFujJj7t3gVnuW277JshR5vGBg34Ulg3+L6+ RlfQ8/bntSIfBcxj4QzDrZ/cUOrw4PtPzYed0PMrvveSHuMGfT/gNTp+ZJeEU7kg/jVaIa 16rDQZx5McKeqjvcZ7AmeFmEsutoXsc= 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-587-n4p8TgQ6OGG9Vxma9vRnxA-1; Fri, 19 May 2023 03:41:29 -0400 X-MC-Unique: n4p8TgQ6OGG9Vxma9vRnxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C01A5800141; Fri, 19 May 2023 07:41:28 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10DF940CFD45; Fri, 19 May 2023 07:41:25 +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 v20 08/32] coda: Implement splice-read Date: Fri, 19 May 2023 08:40:23 +0100 Message-Id: <20230519074047.1739879-9-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 7A0728000D X-Rspam-User: X-Stat-Signature: ri4quoksigfmpsdi3tc3yasu6ihjuixo X-Rspamd-Server: rspam03 X-HE-Tag: 1684482091-418536 X-HE-Meta: U2FsdGVkX19U+KRjXUSXqEbAcjxEYUQyQODYzAZEQ/7ARgkCtrb+Y8jqUkSj69jhyMBoQCdASXBQXL9O4ayVY7SlxHXV/+ETrwuW2ASW68yn5e49E8pPPmBL8ZiUwfrANpOgaTDH8Ifrygb/PwMo4kGjBo8CMjWzq61IwXHU4rorDB7y8zyQIlywpjMlMBUCyeua800WqgjOUwB6FLZpJH5e0S1EkP+1p7O3JVi3ulkHv2mmbjmz+hj5lf9G8zTsH3N663ZyobHrRs6FZP3oqGtUr3Aa8rIMIG8aMgEw09iTTEDiGK9CA56ek4lQNnsn/ITbyOI58tnEQrJgizaU0JDzVROWo8UA5gFkyqfrqxKohfyKu+gEF/8B1dDeI+6BTd6B5Wdoi4qbrW8/0Gz9XOCOT0dH6d3PQAI2XcHo3FrVpEPvDXtcy5GdkGIiC8B+4h39orFg46sCGVRxZgIBaxhh2t1FDcalgWD2W81jppiMcPpoOzIuA4g4Y9Xj35r3TfybWnwHG6JpVURKFiP3SAka799/NANeRdW5IqmDui2dcGJOWKGT6DDIrcfSuTO6P3ShpvQJ0fw/AMWj4xNOudHeShCoLCY6SFNZ6iCWZgFl2CRz4C4KB72RoW7H7DiA1NGZW7qJPV+QuX4viQedS6BPMkqVBDUy60JSH8vMq7s9eDLuFBed+pyeLn+cHdTkN3IGOCJ7bkmqWYC7VPTE428WIHc4lrxyKW3xTkGmWPaP/JgScNTahmcwfF6/VLhcKBuyjHCGdI6bUkCdbOJZbwlUiNR3+U4399Go7RFr923LbdUfg1Iy1X3E5k1WXPRLqUbJFwcmkXklJg1PRfXmivnem58+hd4eIAdwv78qR90inFlhyHiHUz6w4CtftBHo02xcW6wnK1hSzO9yujxQ/Mk4UO/ZT85qOPwUIVmby96h1sn6SuHEgydhkbItcFzgdOgmB0l9H5SHtnpxTfj Oir7Jkre 1gFEaINx+HnyXB8Az7dhuRjkC6rVdTILBs674m2j75deASX0QUTR31y3iQ0TB99Jw+boR1O2y7yG1yoZs8ZmclPiUjr+6hdKZoMS2KLg/b5kJPC2WozegUURC34r+3JllnU0auTSjEVzrDxpHCbU18sbJf1GYgUT7JlTFx/MHXaHrGW54le9BNcsyggY/MSeVufmh9SNj+wSW1IvFviy54rS4C5U/kactikfKGHOcysDqoGkFERzGNq7QZANuQlpHJguekB5BQoFzPbDEYFbsGWvPFFwEAUd2BNqEf2fTXeCB3GXT6y+Y3HG5a2yPj8minc/wOFxeCL+DGLxeBk06Kv8fO0KqZQzSRCDYXlKrvRN5Utv69gRVBAXjSpo5whyzksqF49uOcXMHypf5UluKXkVIa+q+jivQCPn9DPwzxOTXi8ffttqLHhF4rg== 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 Fri May 19 07:40:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247764 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 62419C77B7F for ; Fri, 19 May 2023 07:41:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0122E90000F; Fri, 19 May 2023 03:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F04D7900003; Fri, 19 May 2023 03:41:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5DA90000F; Fri, 19 May 2023 03:41:43 -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 C78C7900003 for ; Fri, 19 May 2023 03:41:43 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A8124140928 for ; Fri, 19 May 2023 07:41:43 +0000 (UTC) X-FDA: 80806210086.24.EB253A1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id AA6E440019 for ; Fri, 19 May 2023 07:41:41 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hcNXnPZK; spf=pass (imf17.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=1684482102; 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=+X2utfWiaKbqYICogIU/HgPsAYww5xpYEgZObAx+E9M=; b=S7KC8AHKZKCdVVRjYu1jMxczcXRUk0ofPkU/yTeLtuUI0CGIYaLwzTEc1rhQslmz92M/SS McOcfOTvsTPS71pfMV3B0BDO+b0tO7HUoG3jbYcu8XStWWSJfZIJs/cDiFd2L2hJ5vnhY5 v+r+REFBAFxeZF/nQS9bcMKXr/ExV30= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482102; a=rsa-sha256; cv=none; b=Trmk2XnM5csMwo1SUUsMy6ZQtvXwmG7nOYtIHPdEMeMkyPO6brPeLJgLIwl0yD/fkx5YNW 4IMVKGj0jfrREf9ysLwxY4mXXMotzSqCpXSrYAbRzx6YbS9YHeCx4dt121EEHFo4vqtvxP Pa0IJpbstT26USXJjDwnQqEoAQCJyj0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hcNXnPZK; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482100; 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=+X2utfWiaKbqYICogIU/HgPsAYww5xpYEgZObAx+E9M=; b=hcNXnPZK/KmKKK7rT5MhQTYvZbyhKkVCIqHsoSOlawm1ri/0slEFHv4rTz0Izxxr9uKu/v vtdC04J8kf5FlhVjp6CdDXaCOPBuAYAf7k39x+CWEpLJVcrJaDLr33XDk6s+RdtulWOyLp 9yNHdP8GN34MVCwO4+0u3d6m2jYg6L4= 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-647-T0SjJP-GMVq8ZCGHan-Apg-1; Fri, 19 May 2023 03:41:34 -0400 X-MC-Unique: T0SjJP-GMVq8ZCGHan-Apg-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 F0B92380406F; Fri, 19 May 2023 07:41:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62C2DC0004B; Fri, 19 May 2023 07:41: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, Greg Kroah-Hartman , Christoph Hellwig , John Hubbard , Miklos Szeredi , Arnd Bergmann Subject: [PATCH v20 09/32] tty, proc, kernfs, random: Use direct_splice_read() Date: Fri, 19 May 2023 08:40:24 +0100 Message-Id: <20230519074047.1739879-10-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Stat-Signature: gfyb11re7o54ej48pxchirs4rragi7un X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: AA6E440019 X-Rspam-User: X-HE-Tag: 1684482101-431363 X-HE-Meta: U2FsdGVkX1+ZgU9fl3nzym9jxzLmxDhRlGzRhMYZxNBQqR4mEs7QSNNsl6qel1f46D77t/fukkRY7ayqj9yE6Ek/hNmEuMjEboxPifgf2ctmoBs1z8XZTXWjEyYosSIn6iDH060zj7bHPvQZbO3VSgCHUJ5ABX7SPvuVnx2Yi5Wb5o3HX0m4bk062Peh0MVlaL1JlvxSmBd27TQv31V5005ruNfo3q3npAlrchxDOn3k490/yBtVEvMaZcG0lGRX09EcDedVMWku+9HsubjUeJFC4lcl3PVs5SW81T5VyycuqA+8uQ+Cz6h8e4G5iFOLiB3WVC5rD5G0iSMzDalHICqWc81usx02oOK6H8CdndsTs+ashRvvNFl0oF2xS+LxgqNAGfcteTxwVoyVc/0jgeRPL4qwQpQqqr999dkrL62zt9ngM0WYXEfsKW2m0m4y9dbbrCfp9Jw5wvroXYtqy+ega28vxl9oGxwgzpET+BaPkPSaqYi1Vy5zzv2zXmE14UYd612XP2GwTojjz20rfUWn+wU9PmQ+l10NQKCV4SfCBgwDHKS3gi0ObGtSZOCxSwQGoiTZCHz6rzSSqs8t48aZiyQ3v7gzEms/2XiZVoBcZvErdOQNnDtzOJO+YVtyiaTSqvtTJVo9dfbI7IlN1GcK4c6FcHKmSD7ZqgPN4mNXwIdUcYJ/6262lIpnzrbB1FSSTVUe/weR2cDBFc8V6cVyY9kd/R4M/M6CuqLnbrWWSQqWdoPAtGZx56E2MPP5Ftwi0gwMXfvLYr0SHuZHVM7V8e6nc5pgkgxoEZRL8jn2bJ+CwhPbPQSMdolp4Sfrfh3x7T/kBwSRnSr+hDoFDYbXx3an+kJ6AZGnY7jIY25K+6XMXBfIqwPxLKQKieyxyi3ZUxDeOM9x/W/zO9vJPbJGjr8kFU5Hyl77DcRIDlObGbjdahCGLJy97NjQBuujBXK0Mv4fzoTjZXoS+2g WGyqwqGW aOya9oBc5fXEMTYNAjGejCMQCsYNFocq+/N6+ldOHGTZAbPZRuBamZjfvZBIJsv4OsUanJnHd/ywhVzuXPclZZIdPj3fTZLWpvnQx5IZsgOpjVv+Tq3oLD6rEd+D1GZZjXKJjKWC4OoZyCErxNw1aHWp2QSwKmQj5BlAISBtpR6QaclETUgQ9oiGQYezrlYIEuEqE60XXqN9Tj9PhIZH62F7t+S/vJTK7CCoWaRmPIzVTKKu1SBj1WKW3wne5LTIjqGEzO+4J57FMyfv2UhmWGlfK9JIiUjAC2apdNYeDBKh8KJrPBoFIYmfMmPpFKB+6sULZ4KlCnZZrl98ZNSInOgCmadyxCiVNb0O/fbsSSjneAUr67NZ+NId4XoFK2O3CGfas0khGgjFZsQFySHo1QZc0q+t3fapK9bcASLr+YHueFHk4dAlB6ZfaJKoRRfiCOHGPi3RQ5MjF/hKwvdaKxUVvnZ1CgsEnEdJiQ8Wb2OFBPs9NXFajF+ALWH+egSY3hj1Dp5AEFUveT1EI0T9P9/svijeiP3a1JpKU 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 253f2ddb8913..2b47b500126c 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 c84be40fb8df..0b910a2af8e4 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 40c4661f15b7..be43afa2138d 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 8038833ff5b0..72f1a8ac7802 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -868,7 +868,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 Fri May 19 07:40:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247765 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 8F4A9C7EE2A for ; Fri, 19 May 2023 07:41:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28441900010; Fri, 19 May 2023 03:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20E60900003; Fri, 19 May 2023 03:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01163900010; Fri, 19 May 2023 03:41:45 -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 E72B7900003 for ; Fri, 19 May 2023 03:41:45 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B742E120683 for ; Fri, 19 May 2023 07:41:45 +0000 (UTC) X-FDA: 80806210170.11.87CC9EF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 70306180005 for ; Fri, 19 May 2023 07:41:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UjgRJ0Le; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482102; 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=ronE9gr+sRXtILb6fInqA45jNbZvtaGttVkSNNlZgW8=; b=QvHNEstWYkoIr9vmaPhZhNvCN+ovWM3E2ByoMoQaVIvx0+sNW5/CGh3tCGOtU9KfeknR9C 910Ki5EpfWC/7pSOQvIh5C392V/f4j0H2m92zswDshDbOIjQFlVeUscrLH9vws1EtRoha0 dtsOAnKSAVHsmIQYMkPGm7PRarwQ9io= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UjgRJ0Le; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482102; a=rsa-sha256; cv=none; b=Cz8OIBHGDbNPZBXbduUtXG+fDhu5fdOkB+q+EllQsNeJI4WrsaauHWEmZXARB1XFLwx5K+ UUHa9iacbvCTVLj2Lim0ZrFdkSNWHYtPFMzx138IaOxQTxCMDUPMGdpbnjA2quOvLt+pT+ K2hkvVZENjKvSbnIYrtYDRmUDYMifcY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482101; 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=ronE9gr+sRXtILb6fInqA45jNbZvtaGttVkSNNlZgW8=; b=UjgRJ0LeK/qsAUp6X1o/IDJbDD8ZC616UKIcLlXTsHSK/RegjmuwIFH0v+HiO88Px52G2T 21XVii48iv1vLuWi4QSIE64TJwg1cAsYLUC8CcW+BurYNGYBqxLmeYzLAhQ+ExN+R0+lXF bObd0ihqR1QjT6ws8LVcx8HWYAW35NQ= 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-274-frHc13ceOAyBYDJKrmNfcw-1; Fri, 19 May 2023 03:41:37 -0400 X-MC-Unique: frHc13ceOAyBYDJKrmNfcw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39B0C80120A; Fri, 19 May 2023 07:41:36 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A860140CFD45; Fri, 19 May 2023 07:41:33 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christoph Hellwig , netdev@vger.kernel.org Subject: [PATCH v20 10/32] net: Make sock_splice_read() use direct_splice_read() by default Date: Fri, 19 May 2023 08:40:25 +0100 Message-Id: <20230519074047.1739879-11-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 70306180005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: i5yqt6ebn6dhjkpbw9f6watgehn5rera X-HE-Tag: 1684482102-221342 X-HE-Meta: U2FsdGVkX1/+aMB2ubp4ElY5L7GaErncp9Oqgompi5yWD10051+JKhvkv3Kkuv4vvbSurGgpixd+18iyl30oDMmDs+n6SPamt3nYpNL3TEkoOrHezohon5adGtrrpErZIKy90K6UuRjbzCD9Sgzz6jAB72hgSCtLOpl2mxoiKBEa908GeaT04W9Fj0MsxXdDUuG7EYeabpDgPF0RLhSTQOy77EVh2BXC/u/kRHLtlFsXZheEpopVkTyKYqv4iWUeeveYYsWVFFCOz5FcuC/h8NRfeOeSUY/tfzl5aadgbP7nC6G7f9DAPj4P7p3e4Yw+NWUSvkCXpks7mNl01pCer+VmWmO+y9An0BM/RjfbC0HkLZCYpYHiCREBXlVhzffPiaaScvmd/A7c6OEYWzyHLr84/p55MTqssRgOMgbf9yMibeFe63TjxBICiyNQrbePjI6nahRXkAPJE7LSzsG14jQnlxeoCOeVu4sc0Z51BnhsK+7rBkVE8VaINP5Omth/UO1UBd8lEnga4pfHy1oFjEy5r3GG/OfLYQQryH6LQBQpObePLGEAHlSVV2RMRK5GzzoKyj4FuLRzSX8uSPmr42Fc9eAelX2tPJHT5jsmPhPejLk1/RwhvpOPv18bOmd5lnEDGDbhxfbwliz3dM9AtZk4WaPA3XZhuYH9+7w4PsBDCSbAzaj+P4v5ZeGd2PROtBOdg0IDGxI9fJYK/lqGWikmReHvSacFZMd07UfmsRxHqzuQharlbQRyfihowk+Dl3Qhmom2VYVK5oYGSqgOatETtjT07MyhmyFMvNkBZuyQ6LD7S1scPNG9O4KtrAlkVaijiCYbAuo+a/XdmZKmak8XZTefRJESAP3mU1CDsBG1IDpeavygZd16vIGgfnhlUA5M2x3zOK8LGnp0sh9MyyvxAOWGcLMRM9Cu+LShlYN0YfssjjwsFL+ffnRHtArNSDXEfkUszPtthYl1Kdw dOa8zpR7 yDeTKNi288IMLnCwizopOPjDGOI8fbo09/f491CdJHED5B5hyz37aqIhjU1lANej65x2sznbfFcmCivPRjrVIDB7f1ziCoAn3LmbUHWI5Zq4/m3CWLvy85iuisIz7x3R7Pn60lACYP4ESwmCvADIj/BIh3XitWJ1ocLY79qow9bnFR2ow0niQFrPa6Dv9cOb1V54bkFLq+cNvpKley0Ghd6apMXNEvsAv97AOCX20g0uUgy2OsBcRMGWrQPrTiuz5/Zgkszxa1jbddx53OE9C7v8K8XhkTVgt7NPLAaej86ZgVG+x5cF/4aa4936Gm0KQlqnjm8MpyHP3tJA9Iv17waC15qCBHMKBJtiDRXIphDd1dkzv+5C6IaOIfE7szgorNDF+IxyHlzrPnblEM+RKL5NXqySL9Lj7fPoTFVrPn8sYMAriIyg0/J0DSDlgFUh0fLYCqEZB+3sEV/gWSJsM94gk85A8KL2I4xJy 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 sock_splice_read() use direct_splice_read() by default as file_splice_read() will return immediately with 0 as a socket has no pagecache and is a zero-size file. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: netdev@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- net/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/socket.c b/net/socket.c index b7e01d0fe082..40b204a47aba 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1093,7 +1093,7 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos, struct socket *sock = file->private_data; if (unlikely(!sock->ops->splice_read)) - return generic_file_splice_read(file, ppos, pipe, len, flags); + return direct_splice_read(file, ppos, pipe, len, flags); return sock->ops->splice_read(sock, ppos, pipe, len, flags); } From patchwork Fri May 19 07:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247766 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 ACCD8C77B7A for ; Fri, 19 May 2023 07:41:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54371900011; Fri, 19 May 2023 03:41:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CBC1900003; Fri, 19 May 2023 03:41:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36CA5900011; Fri, 19 May 2023 03:41:49 -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 26397900003 for ; Fri, 19 May 2023 03:41:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F2492140955 for ; Fri, 19 May 2023 07:41:48 +0000 (UTC) X-FDA: 80806210296.26.493CABC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 2E473A0006 for ; Fri, 19 May 2023 07:41:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y1Y4ogU9; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482107; 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=g820KSNTP7OMqJOKF462B/JivphTXg8NZzTw8fVuImA=; b=lJtftJirDTagA19rRrdDD7JuJkWGgr/9H6rQTWerx7fuL1LhJoDy1yOgmafZjCdM2kgAyW 5aLdQD9x247r9oPbBfgdTmOsGc9x1YVLp2WVYFQENCtMF6iZtL8+0B2DWOuycams70+WXM owCNINzu/UgWM0D7JdO8FqU4YWBlx3U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482107; a=rsa-sha256; cv=none; b=WWEupISHd5ChglXvdy9U7/KsLjjD/t0Yre+oIvYPRfWQyT9raWmJMU1EDKwmWxFCAwWe1c NtzgE/Ks9xqybNO9ls4avsqMoBybtyiKEavjjuTBcUb9oNV/f9lFMX77b9XKrzYUUtnQhc 2OEBAodQzRJsw3OJzS28eklhR091BWs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y1Y4ogU9; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482106; 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=g820KSNTP7OMqJOKF462B/JivphTXg8NZzTw8fVuImA=; b=Y1Y4ogU9sVFKhucR6tVRqjC7fEBt3N7wXjv1pxFWgr0x3HNU2528XdrNM7UttaghDTDSMR TinyBQAE/7rNU+8Gh3ZeGqMYFIQdXFHRrkrgxBUx+9UOulFt2jifSHczl5mMWQ0xxjRtEI Ee14dxk42yx7COKtGjSQ51q0GMTI9cY= 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-438-CWsHB0HDM6aXruJL4c8kbg-1; Fri, 19 May 2023 03:41:40 -0400 X-MC-Unique: CWsHB0HDM6aXruJL4c8kbg-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 B8C7E29AB3F4; Fri, 19 May 2023 07:41:39 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D58D7C0004B; Fri, 19 May 2023 07:41:36 +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 , Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Christian Schoenebeck , v9fs@lists.linux.dev Subject: [PATCH v20 11/32] 9p: Add splice_read stub Date: Fri, 19 May 2023 08:40:26 +0100 Message-Id: <20230519074047.1739879-12-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 2E473A0006 X-Rspam-User: X-Stat-Signature: 7w51s7w5c95u5bmsnnqtrsp9eupkaamo X-Rspamd-Server: rspam03 X-HE-Tag: 1684482106-268632 X-HE-Meta: U2FsdGVkX1/GhgaE95Ve4YPbq7R/NQLGTmbhABhSenTamAJZdRD3pnLRd0wDv8RW9W0PE6TWi2Hxm9UQqH5Lws922uXFWYDWiOCVyEy73QHj+Udtu1vO46SimTV/d2zMOrBPKYSAnFc+IjDxhTBTFpXMDr7KPrY+xR7XaH7M5kD2x4Ip7VpRTfL3JAdvdDlv60pSjA7PBc4Ve+iO1niHlzDOazIcEbU1zqZ3HzkrJ6NNns5f8BcCbUlfx1G+keOCV7BnbzlUpELoiPEOJoWsum7cIViORCYQXfnUa89z6IlDc5R1vFXHxieP++VT3K5KvpBsCnCZcTrKkgzTnOMU9g6wBEZhsuU8ehuZJkOF7FzuoCeUQZN7FWKbDhfLqkm3+m/TXGLHz3pYliJJGNll53g+VcQXM9OMzzkjQYONUm6aNXg/IsQVca4OabPul05CLzFh4qWezmntzg6uYFs8dotbR6e34Dsx5QWbyIBJqpUGl/d04neRBQm9oPjZwDMHoXmi3D9voRvl/aQ1Bq/FiR8z+39K87y2EYoFbl/TTglb/YtNZVKIx6fnH4d0AbP+NRsCj+Vs2/kQfqMrOlxIbQ6QjGHCDtkstCCmtNd798WS+WAe87+R5setpMkFl4ltixNb9sg8d7JHlJ5X0D9GPuFkK0yPwI3yw/yQb5doc1Z3JP/oe2nstKLH3LVRxI6kH+9SIA6dXlyPjaJ5yLgHZ1El0JaU+6yMyu+pC9dPOhDSHl951a7HanpHyrwziIDtgRbidDl4jtncK8nXq5I/IIWH/zk6mcMFwlpm4vJ36IQ39kSNRNwKg86glOVroKbArdHuocJfef43stznGWNZA6JVYgLnCJ7b5tr8dLQVinao0ppayzMIAUxjhJqZZ/U8FTQcKcZ6iF3LpRc4G65OQVQdaZpdh16AFygm+OR6Ak3qsQYrkf/xf1AmkGSWgmA5veVknQHZ35hDAwoIC8E bMzzKD37 NXX0uf25Y0hUxLCrKS3dpovjtgKc4kV+lkO/ylKSF1W1lZCIrPcaYTGv/2tAvb0SYqNaSz67XJhckGZpLTPPI7SJ8JWrvv2yusLyDj19vm2FDJPtv8ESFQDBvsU+MhuxyyMUjtirx+tNllCZW9a58k122smeIf8V3WKj/LQ/HuT7HQBpkoiowdAWkdw2k4QQJkL2X72garD2dTX0gRB/QrqcwjVxe5QawRuS+ztfB1s2NaAHxSY5YbJOL+HICW88Mkw7PdBX49S+61cb/Up5PHzFYbjjbsGzPngUaDD/4lEYzktA+Q8TmUJ0u7yUtWjAvKyIb6ucTEZqi6QIoGUpBWvoWOUxbHOrXzaew5xxWqk6D/1GC1uozaWTGPxz4dzsYrySkS5Mfp/JTX/Dw8WSDGyZue8U4vHre+zdlUDS1jm3aTyx9uSXJk4bUJU5KYuNYN1kU+c86nBRbLqPJCAbBv5lphay7WyBjh7Gj440rhOj6+Im2DptUwBzLt8OmeathrgJTA7bK64S7+OxDTy3/eY1Mi+h1zuXdOD8+6bJmCg4W1BZD/85z3Br1geg0urBbQLh0maHUzUgz9YE= 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 a splice_read stub for 9p. We should use direct_splice_read() if 9PL_DIRECT is set and filemap_splice_read() otherwise. Note that this doesn't seem to be particularly related to O_DIRECT. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Dominique Martinet cc: Eric Van Hensbergen cc: Latchesar Ionkov cc: Christian Schoenebeck cc: v9fs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/9p/vfs_file.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 6c31b8c8112d..0f3cb439ab2d 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -374,6 +374,28 @@ v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +/* + * v9fs_file_splice_read - splice-read from a file + * @in: The 9p file to read from + * @ppos: Where to find/update the file position + * @pipe: The pipe to splice into + * @len: The maximum amount of data to splice + * @flags: SPLICE_F_* flags + */ +static ssize_t v9fs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct p9_fid *fid = in->private_data; + + p9_debug(P9_DEBUG_VFS, "fid %d count %zu offset %lld\n", + fid->fid, len, *ppos); + + if (fid->mode & P9L_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + return filemap_splice_read(in, ppos, pipe, len, flags); +} + /** * v9fs_file_write_iter - write to a file * @iocb: The operation parameters @@ -569,7 +591,7 @@ const struct file_operations v9fs_file_operations = { .release = v9fs_dir_release, .lock = v9fs_file_lock, .mmap = generic_file_readonly_mmap, - .splice_read = generic_file_splice_read, + .splice_read = v9fs_file_splice_read, .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync, }; @@ -583,7 +605,7 @@ const struct file_operations v9fs_file_operations_dotl = { .lock = v9fs_file_lock_dotl, .flock = v9fs_file_flock_dotl, .mmap = v9fs_file_mmap, - .splice_read = generic_file_splice_read, + .splice_read = v9fs_file_splice_read, .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync_dotl, }; From patchwork Fri May 19 07:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247767 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 5399AC77B7F for ; Fri, 19 May 2023 07:41:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB972900012; Fri, 19 May 2023 03:41:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4292900003; Fri, 19 May 2023 03:41:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE25D900012; Fri, 19 May 2023 03:41:52 -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 B7826900003 for ; Fri, 19 May 2023 03:41:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8AC501209DD for ; Fri, 19 May 2023 07:41:52 +0000 (UTC) X-FDA: 80806210464.09.6B2DBE3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id D0274A0005 for ; Fri, 19 May 2023 07:41:50 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EYxiqhl+; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482110; 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=zBEjCltxDmlnA0oSyuagNhPyHRx1meJicqC3uPUtKyk=; b=2I4UR+EZk80gZp1kglwMuhk9MfPh4ytQOx2MOu7bcxMcRWhHk4lpT692eiO3tB5rlMqBF8 1LblLHDCw5iCBrQnjQbYDaXiSx7nxx912HI7iGgxpfZNES3DCauGXCeq3x9pTUFnfZ0DgA eP+56rNMm/3X+UBbf4pTszZoY851ll8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482110; a=rsa-sha256; cv=none; b=H+f4swdf/kSfmh1nfXfls00Xl+AxnDp/fsVGbIBv7RPQEiZdimeSDZ4FVkKpapvGbf7dEK xdYZcC737LC9+WdrNKTmFH4AR43TMtlahLlSX4lglR9NRUeeo635pWbsWU2Kf8tiyIkJPF yOov6JahXyjP2py3W3ngmwqewRuMIs8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EYxiqhl+; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482110; 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=zBEjCltxDmlnA0oSyuagNhPyHRx1meJicqC3uPUtKyk=; b=EYxiqhl++3sqvm3CcX3n7fgqDodqw8MRLIzTkLYnzZrGhPxFM4EctmSnUEnL+IB/JrurKY WTj7FfnTmfqQOF1hn/GacI5n1wp1+cydMA2e/oXwAYnQTRVuPjqzrn5zlMLfrGUx33xwN7 uXlnzMRAzH2UlubYnyryLzu1PLyv6Ig= 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-500-_1BGeCTTMTyFaYpS14WWgQ-1; Fri, 19 May 2023 03:41:43 -0400 X-MC-Unique: _1BGeCTTMTyFaYpS14WWgQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B00A03C02180; Fri, 19 May 2023 07:41:42 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7169740CFD45; Fri, 19 May 2023 07:41: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 , Marc Dionne , linux-afs@lists.infradead.org Subject: [PATCH v20 12/32] afs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:27 +0100 Message-Id: <20230519074047.1739879-13-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: D0274A0005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qay8hb64yh1pw6x16h7aqb7cfw6oyg1f X-HE-Tag: 1684482110-423679 X-HE-Meta: U2FsdGVkX1+SNTyE5NCnympOvZ7xdJUUVTBQz3ckp7ijA9Yaj4bep5maSQRH3XCokuecunnarLUQjB4aBhCY3v5bbhJzkijXwq02N6/YcAYWggsn5NQukfsfQwBjH+WOz10nDiNKBcUvSVGOp7FLfzvS0j6NAaau9v6X8n+xQ70wpjhBOdko/afagMqeTJ3j0mCz72NvVJl7IAucOiJAZp754TjtZkKgJOHlMKYDaWZQrjuTgmnH3vuoeRhjNtVK6AYnP8MUXvNyazTO14sFX+K0EMQmfs1MRX8pX6h8xkR90JXmwdGy0b0Tg7u6RLEcxGwhQ7wFRxFkjf8VXvbGe5/1EnUc+OZyopQu5PyYLwjOjoqPNXHkPkKPfuqVrJofv03xnLBSqM5xinNZgUZwosGeso8PUIFjWSzmTVVGJlzLVwH7PCtFPlj2LSboNgopbKjOqDVPUMP+UxUtk+Pauqt/WNf/RlDz4RnMA5avtQ3eWSz0/TvBijFqTsfPPtKg2AyN5G8N0hRG1PBLTvn03ugP/hImOkrRDqtq4JizqwwVjB5dd1P1lLhSRmTHClIO0b69VOyRui9aZFppTZpBgZX6BHAPauvri4efk6vaIofAYTtVJ12pDg7lBT5Gg8xIuAmZZMJqzl49yhHm/rVN/Dfuv0l7JP/WioVGswfR4Zf9uZeMhmb9yyaqBLlzJ7fDMDz6BBFlPY8QE8PQOxQ4rzNONla1Cw5LGEgahRUHyaUswMnxmh8MuRiSCnBqRNgjpRfNhF+1frjdhLbwNvrgeU34E7Y9AKKFUjDGFack+RxbbCnSfOuX1IpI+CQG/q9dkCqVpFjo9BhDzJoOoT2Uedxu6a9ExlqjllkjTFsF2jiqs7nzb5y9qa9d31IMmgknUtGaq+sAjoeh9DILGxDxefbgZU9yuAYwf/xn1iccN8Oqw2v+x2oiLgKM7Jj+TWur6g2E/7uSz4lQNDwylwy uz1tTs7H 6F2/fXAW2RhUXJIYTuqOzFoycUzakaZGvON8UdcCN+Uo9+yEFBW7bsOR8wCPe8t402Qp3PCXWiXLUPBDddbO3Wvv1r/UvGjNzk2KAtUkDzDQDdCyMt7zwuifAl7tQvnUmRy82+JrHM17QBBwNCM8vGDuxa+ddpAo7qKolsx/buLoweFdJY/lyUpY9/vUQ3tr+924r0UIdLhTIzB7m3fCmWLdf4rOw+c1qWV1dRFyZnh7sSsP55wg897zBGxReoeIZr582BhWxFJWuqTB8u6HjqxmYrBkG6nthiuESYI7N1THxRt76FGGqA4ArWJMYrW7A9kxeL8krCGUlEKsEumvV1zvnchm50P1aVsJWH1WfGnDa/pP5Eun2sBLPhTM6Gx2iKidOvSD/pDH9H/as13PKgFWy7zAZxAwlfA7j8KpF15o4U5dOI0rlAmojZKlF1VXT3Ze+4EQsKGzsGO/W5F1E+5vioA== 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: Provide a splice_read stub for AFS to call afs_validate() before going into generic_file_splice_read() so that i_size can be brought as up to date as possible. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/afs/file.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/afs/file.c b/fs/afs/file.c index 719b31374879..d8a6b09dadf7 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -25,6 +25,9 @@ static void afs_invalidate_folio(struct folio *folio, size_t offset, static bool afs_release_folio(struct folio *folio, gfp_t gfp_flags); static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter); +static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags); static void afs_vm_open(struct vm_area_struct *area); static void afs_vm_close(struct vm_area_struct *area); static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff); @@ -36,7 +39,7 @@ const struct file_operations afs_file_operations = { .read_iter = afs_file_read_iter, .write_iter = afs_file_write, .mmap = afs_file_mmap, - .splice_read = generic_file_splice_read, + .splice_read = afs_file_splice_read, .splice_write = iter_file_splice_write, .fsync = afs_fsync, .lock = afs_lock, @@ -587,3 +590,18 @@ static ssize_t afs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) return generic_file_read_iter(iocb, iter); } + +static ssize_t afs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct afs_vnode *vnode = AFS_FS_I(file_inode(in)); + struct afs_file *af = in->private_data; + int ret; + + ret = afs_validate(vnode, af->key); + if (ret < 0) + return ret; + + return generic_file_splice_read(in, ppos, pipe, len, flags); +} From patchwork Fri May 19 07:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247768 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 71B98C77B7A for ; Fri, 19 May 2023 07:41:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE095900015; Fri, 19 May 2023 03:41:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E693A900003; Fri, 19 May 2023 03:41:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0960900015; Fri, 19 May 2023 03:41:53 -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 BDDE8900003 for ; Fri, 19 May 2023 03:41:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 946C41209D7 for ; Fri, 19 May 2023 07:41:53 +0000 (UTC) X-FDA: 80806210506.06.5BDC812 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id CF4371A0014 for ; Fri, 19 May 2023 07:41:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=alQPVGHa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1684482111; a=rsa-sha256; cv=none; b=KK6nfJgNkis0lsB20ClCKwQh9yI8Bn4qAKhwcv9HxxJ6OfkW97a8fFZCTxEhrzxmJpjm2H RRXcPST1U64tHYt8/eFzDcSZf9fsyYOCMgz/IZ1JD50OcO+mmd3XYfYbJtWpleAAtJ1De0 0hq6yOg6UlNGFcDCFk7SSxj4gTumZoA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=alQPVGHa; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1684482111; 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=ul54+Rfc7Xx/QmGKIvy0/Dk3iAPI5N6ujIbh8BdRPD4=; b=INizpurw4A8mu/qzvGZt8g5TKa6YFX+B8fZneryUrdvKYhIWt/5nbPTbvjwT4SSxPaj0jT noX05MS5h61igXTGHb2eAK9zuSJcylJKMIW9Lc0m+fB37czsO/O7mpmxLZhCmM/cyujoc/ PjX+udxe9YoNDGS//ahZAasyGHLLXn8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482111; 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=ul54+Rfc7Xx/QmGKIvy0/Dk3iAPI5N6ujIbh8BdRPD4=; b=alQPVGHazrC4pQCWsQAtVhkqcugywhpxOr478yBOxrIk+FTfKzF84bFaSbeCGVldrO7USD dp6JCBS8USHlNd8MbZtZBbtzGFV8fpgtfX8CUf4K9Yu4shRZVP+55y91lER2POjM7YvRN5 QsfO58Zx+0P3aSzZy3wIyu5z2l5KD0Q= 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-542-yZVFR8FJO82q_4bbCE1uzg-1; Fri, 19 May 2023 03:41:46 -0400 X-MC-Unique: yZVFR8FJO82q_4bbCE1uzg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B75B6185A78E; Fri, 19 May 2023 07:41:45 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D4D04F2DDE; Fri, 19 May 2023 07:41: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 , Xiubo Li , Ilya Dryomov , ceph-devel@vger.kernel.org Subject: [PATCH v20 13/32] ceph: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:28 +0100 Message-Id: <20230519074047.1739879-14-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CF4371A0014 X-Stat-Signature: q9akf5nuz3mfq96mr9ry96exrktx388o X-HE-Tag: 1684482111-221042 X-HE-Meta: U2FsdGVkX18chB0CdQZtYd9Pp9emZWBLNV1X368aj3/5lnnh2fpLRhe2lepbrct0vdrPz8z45n9bjd+CO2sOoQVeuD2mIxNeuQkxDntUWARsK276V0nY3PpcDcL63PobSOfjhnVHsFEglPHwqIcS+Sidv3yUE/IbNAyPOH/UfWxzloIAf0ZdVeUmweaKiCNATj5quMUe5XDer3pdvYgQ6UTfsu8eWwN2vO4Ey68qG2m70K/OUHcRyzoav/12z/I/ixjUTh+UUuHnyNTihUunWjVqRBf01/0DqKuXk0JL9uRcV2grBmwaqht8Rbgt/e32hIammOXIc0yXH8LAao6u18HkbFnNMRpQZb8yGR/SSSrMUfVy3qD8yJ9qcRGTN1iVnrTNEQPvDkkpaGngH4x033xQUGw4WsahDLGH4Cy8j7MMXhrVlJtsqW3w8a5r/Vxa/L/rcJmmdxUEH5X6RrbJXvTTWmWX/X0IrMTVHIWXk7yBVHbt4vb8UmmdGBrFufHHmrXPDsVb0EP2mj3llJELiIxMQftAX48nnZAPhFkneb0YVZfHKTmeAu86TwvAYXq3Bqa+Z8+sXgQjv6m5FLanii728KYpeTiGZoot/aoahizAktCHBfr4Rys3cYUVWDJpuI5Yl8qbDFdLwzdLY92H2xSZE8jx4vHddO3vRU5HEg6qQ4OmTIUzHL8JkOJDa0pWy5cCeOE0IdLo0vJ4WXwPqnN5K+X2W4SJhh/68JicAD7XHvJlJ9p/omtMGzz7kBJoxfg4ug+rLgKG/xdHk8Frblx9hTTMPqKm+Nwvahbs/wB+jr4LnkmK4fovc9TwnC0TGhJ6D/R+QCqP0cL/sTEqCeWZLgjBIFS7w+8VgKTVb0VWtUcaPOLl/SC8xqQuBg+eMJNGTG0uGPUbvGhf6bT5d5h9g327+3tWcXbJkk2s3bKEjA48Wb5bmmG2PjacTrIjB1wUw6mJspARXTZrExk /Lk7AfMK fqn4MJTRpW36HsQ2TThkVnl3gdau5aGVE2+bB1iezyHFsqGJlhkfXjGTr4Onr5xJ3UTBwlAtUimqIosmdY/Qbg4YtDI6PX+fju200KTamPFA4tutSRzdS4hbIUieMiCf7/xq6sN3YSDk9srtM0gHhW1Vkdtlp9UMzg6V9IjVLGuq5CEcw1slnSWZ/H9IMkPpiL525KWWRxkJuoB8OhyYR0neimiRNLd7WDa+fXrviHhHGzlXDGhACpc/Jp4giqtair0gP4kxxCuSA92nyV+4JEifYswXxWRIc+fcVIkDnJJURhD00ndBnWqp13tKKuVoVOXFhSZecYERBNPeF6DyhzZXhy0RYSUoCC9JKMqwSat3hoiqE4ho7iRWVIA== 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: Provide a splice_read stub for Ceph. This does the inode shutdown check before proceeding and jumps to direct_splice_read() if O_DIRECT is set, the file has inline data or is a synchronous file. We try and get FILE_RD and either FILE_CACHE and/or FILE_LAZYIO caps and hold them across filemap_splice_read(). If we fail to get FILE_CACHE or FILE_LAZYIO capabilities, we use direct_splice_read() instead. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Xiubo Li cc: Ilya Dryomov cc: Jeff Layton cc: ceph-devel@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/ceph/file.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88..382dd5901748 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1745,6 +1745,70 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +/* + * Wrap filemap_splice_read with checks for cap bits on the inode. + * Atomically grab references, so that those bits are not released + * back to the MDS mid-read. + */ +static ssize_t ceph_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct ceph_file_info *fi = in->private_data; + struct inode *inode = file_inode(in); + struct ceph_inode_info *ci = ceph_inode(inode); + ssize_t ret; + int want = 0, got = 0; + CEPH_DEFINE_RW_CONTEXT(rw_ctx, 0); + + dout("splice_read %p %llx.%llx %llu~%zu trying to get caps on %p\n", + inode, ceph_vinop(inode), *ppos, len, inode); + + if (ceph_inode_is_shutdown(inode)) + return -ESTALE; + + if ((in->f_flags & O_DIRECT) || + ceph_has_inline_data(ci) || + (fi->flags & CEPH_F_SYNC)) + return direct_splice_read(in, ppos, pipe, len, flags); + + ceph_start_io_read(inode); + + want = CEPH_CAP_FILE_CACHE; + if (fi->fmode & CEPH_FILE_MODE_LAZY) + want |= CEPH_CAP_FILE_LAZYIO; + + ret = ceph_get_caps(in, CEPH_CAP_FILE_RD, want, -1, &got); + if (ret < 0) { + ceph_end_io_read(inode); + return ret; + } + + if ((got & (CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO)) == 0) { + dout("splice_read/sync %p %llx.%llx %llu~%zu got cap refs on %s\n", + inode, ceph_vinop(inode), *ppos, len, + ceph_cap_string(got)); + + ceph_end_io_read(inode); + return direct_splice_read(in, ppos, pipe, len, flags); + } + + dout("splice_read %p %llx.%llx %llu~%zu got cap refs on %s\n", + inode, ceph_vinop(inode), *ppos, len, ceph_cap_string(got)); + + rw_ctx.caps = got; + ceph_add_rw_context(fi, &rw_ctx); + ret = filemap_splice_read(in, ppos, pipe, len, flags); + ceph_del_rw_context(fi, &rw_ctx); + + dout("splice_read %p %llx.%llx dropping cap refs on %s = %zd\n", + inode, ceph_vinop(inode), ceph_cap_string(got), ret); + ceph_put_cap_refs(ci, got); + + ceph_end_io_read(inode); + return ret; +} + /* * Take cap references to avoid releasing caps to MDS mid-write. * @@ -2593,7 +2657,7 @@ const struct file_operations ceph_file_fops = { .lock = ceph_lock, .setlease = simple_nosetlease, .flock = ceph_flock, - .splice_read = generic_file_splice_read, + .splice_read = ceph_splice_read, .splice_write = iter_file_splice_write, .unlocked_ioctl = ceph_ioctl, .compat_ioctl = compat_ptr_ioctl, From patchwork Fri May 19 07:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247769 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 7A490C77B7F for ; Fri, 19 May 2023 07:42:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1738C900016; Fri, 19 May 2023 03:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12264900003; Fri, 19 May 2023 03:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F07F0900016; Fri, 19 May 2023 03:41:59 -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 DEEAE900003 for ; Fri, 19 May 2023 03:41:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AEF021A09D0 for ; Fri, 19 May 2023 07:41:59 +0000 (UTC) X-FDA: 80806210758.29.F54CBA7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id DC1201C000D for ; Fri, 19 May 2023 07:41:57 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RjUwTfw4; spf=pass (imf20.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=1684482118; 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=/4iKO0WOSo1UJaMQGu6hpLFM8tphuArX0rBWtTeeSuo=; b=QDUikbAiZ1qANfGTbUAIx2aK/B0rNQIVHU8xDRvdAyQ4AW2zs5KzJfbuYPr99lXctCFLHD lho6PBlIruat/6yxaVORC0KPNf+ib+dFRlOL1Dc06NlpALsqA1PUit+45agOekXrt1+kd+ qbzrBFXfdilNMHGeoygXQpXYic9QKdo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482118; a=rsa-sha256; cv=none; b=rXLDb6QsSLENa7PQB8uRqD2M192gdxT89zzZlaW4+3XMLz+FJOtVauKTXcTVgBzGvAFGik 6bMPxWhFw9W4tOaKoot28Pwm5gLAr0Ueo4qIOSmLHwc9S7KSV5kfbvhi0t4N0XhlUgKUHm UmJWDPrQ6Iy4s31FJFU6G00f6RhwZpY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RjUwTfw4; spf=pass (imf20.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482117; 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=/4iKO0WOSo1UJaMQGu6hpLFM8tphuArX0rBWtTeeSuo=; b=RjUwTfw4TcmG/eSTagvVhVjRMCFC+AUMQ4KfyFL0+JjUyoWjr1M6H4sYXFIsFCre9UffoB L1GYsP+kxPkRWvpKTlx9UBOkgqyk1WoHjcIQuvVolDeClCjqlQcK/ohjVdRiRTgffIsfJ6 CJw3081niw7aP9rZFclmND2dhT7Crrg= 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-187-6zZLhNJbPDyDHIrP4_P9AQ-1; Fri, 19 May 2023 03:41:50 -0400 X-MC-Unique: 6zZLhNJbPDyDHIrP4_P9AQ-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 1A33D29AB3F0; Fri, 19 May 2023 07:41:49 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 767167C2A; Fri, 19 May 2023 07:41: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 , Tyler Hicks , ecryptfs@vger.kernel.org Subject: [PATCH v20 14/32] ecryptfs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:29 +0100 Message-Id: <20230519074047.1739879-15-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: DC1201C000D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1uzrefchcb7bmzgni588ruczwq15eawu X-HE-Tag: 1684482117-934757 X-HE-Meta: U2FsdGVkX18yWHPT6eIoPPgegyab9bjDRLJkoEDdWtV9UvNKrs5gRQBYRfnApZwyPqcD9YQ7KHYezqNsuOfe9fPs465TClZD2ylpp3K9s+Q93MYJXAtAYQlJrZt946rZNzodV4VNfIrEE4/3n2wg6lxO/XUSS25w2a4bnKNhpLA43ZB+xOrWvtpR1Qdpbow3Ow0whon6QW4nYAx+6MrKF3PXO5FHavXAFohkwBrRPUkF2ozLPVlCNvC9+C/0HCXwnuOtgQqcfgYSZqn9MZGGSgyIKKzeDYxZilxSDAWZmJIQtOdTw60+LOymZlhVeT7uUe1Djc8Rrop3z648lL4qsdDsPAIZmQd/3xXPCtv0LoaYAGkXzkxwJc5oSyF8lDTU4AVe63d40rLw47QMKkkcTrdRzk3IeXfT9+68UXTVA0wHwDh4WGGRVWDu/XPRQMgwuTJ3p/rlDjJvnkuiHvWOglAgfzc1km6SvBCsHpMYuNq5k5HWGu/wtsyTT2f6y+NVjDtvFEENDV1eGj925YMvL4/3ZuoF7iuE67rvKIf1f3r/Te/q6sDVO0RuOB1fIsHzzPSbIiPXbPJ26SNhdMceko9AgJX1OnhbLCEnNiTWxlavHhNKq2TXVL3nXzHcP7oY8OJk0utFZtDVPmpHzyIRaQVep8umMucAZW55Tb0jNXgvU/MyLz43dDdS5/KWp9wmxFpqBjIW8cTISqTNeg0vH9TupqwuO9QODe68skq4bGCudiEbEV8zLKj8NHrgeyz6/GoDqtSCNPGe+sVn9MC9GXVxNBrWpqwFgIXe49v/+Au0QeopMENyTZZ7k0WD4WumZ6L22VGEy5WUR5/MNwrIrnowUwqeCWKmY5C9DLEFHUNeUHVzc5M9KSH1ftpC8yKuhPUwd4IupNYCbd1acbRX8OmgBrWfNy4NZ1fQsCr4JQR9v5z+oOVXqAVN9HtGofNEpkmhrfJaT1VavcOBrf0 BfpVdJHV km5rHCqKZDCaqoAZ7v/UBTDRLcPFLtrLIW9EgQDHKmpdJ1CdTc/QiqxSjI2baE3ZEXARC/v/taqQKFQDtsWKY5YUy4DoDp6gGzKfm1QQXCfxz9bFbbv5L3+XxvtLZF4D/30jguxAt8PA1DHgXDCGIngEsnOPpVv02XKTjvSuhWSP1M8Xhw9oNRWPbpORAjrI3UuddMCnR01ZbdMvw7OIGevpU7X1PKCi6hE/2NwcM8JrfSzE/6qt87O6kf38EYnGb5X/29M8mXhG1o+mvAZGIpklW0Fi+84cUfa/sTj5ebGjPCA/skk2WO/S+vegUbB06gMMpWWzz06PYC9n/DhI2Pr861Ci5YObRpL26uVBehxq1w6Gt+ysq33Z+rtz3L3TL8ClaTbKsRFbr8z0ZYfAaOZjzUFFB7TG+UuIZ 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: Provide a splice_read stub for ecryptfs to update the access time on the lower file after the operation. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Tyler Hicks cc: ecryptfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/ecryptfs/file.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 268b74499c28..284395587be0 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c @@ -44,6 +44,31 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, return rc; } +/* + * ecryptfs_splice_read_update_atime + * + * generic_file_splice_read updates the atime of upper layer inode. But, it + * doesn't give us a chance to update the atime of the lower layer inode. This + * function is a wrapper to generic_file_read. It updates the atime of the + * lower level inode if generic_file_read returns without any errors. This is + * to be used only for file reads. The function to be used for directory reads + * is ecryptfs_read. + */ +static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + ssize_t rc; + const struct path *path; + + rc = generic_file_splice_read(in, ppos, pipe, len, flags); + if (rc >= 0) { + path = ecryptfs_dentry_to_lower_path(in->f_path.dentry); + touch_atime(path); + } + return rc; +} + struct ecryptfs_getdents_callback { struct dir_context ctx; struct dir_context *caller; @@ -414,5 +439,5 @@ const struct file_operations ecryptfs_main_fops = { .release = ecryptfs_release, .fsync = ecryptfs_fsync, .fasync = ecryptfs_fasync, - .splice_read = generic_file_splice_read, + .splice_read = ecryptfs_splice_read_update_atime, }; From patchwork Fri May 19 07:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247770 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 15F4CC77B7A for ; Fri, 19 May 2023 07:42:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FEAB900017; Fri, 19 May 2023 03:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98D27900003; Fri, 19 May 2023 03:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8008A900017; Fri, 19 May 2023 03:42:01 -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 6F125900003 for ; Fri, 19 May 2023 03:42:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4B384C0907 for ; Fri, 19 May 2023 07:42:01 +0000 (UTC) X-FDA: 80806210842.19.4F9BC7A 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 98FF7100012 for ; Fri, 19 May 2023 07:41:59 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TZkaK4N+; 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=1684482119; a=rsa-sha256; cv=none; b=zv1owCOhRC53o8X8qxPhyiqHrtVyeSlkoHY4t7H7r4yVyWGT9G+wCSYKPT1rvsokQdBGzd F1OeqK4/ULEf1GjcW+LwSt3/p0qNfLcAd4LnIcimR1AVSCk6AG68PCyC+NGfmmE9fntg4N NUE9Ri9M4blpsuOru0ylo/RcyX8FgfE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TZkaK4N+; 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=1684482119; 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=VhlnyEb6mYomF+UXhy/zVZBJsDbPWQmGyqF6ugPT8o4=; b=lGDlW5/cKHhnn/QXPVbVAOBTmfcdOTWqUuughj4rLS0yb0MvH09nyqBjHUh+eBNj9eZGqT l9UwnkZZXn6HkvQO5Te+O/gC6I8kCYMan0ZC0Mu87aSdi85sPHGze8Em+f7IWQdvopPYqP l1cz3n449HELS7R3+h4rFmFZpSIqvZU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482118; 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=VhlnyEb6mYomF+UXhy/zVZBJsDbPWQmGyqF6ugPT8o4=; b=TZkaK4N+TbufBFr72NolMZvwSvdXOic0/ofYyT5HQJbvYaccCrAobnGd4geBJLXGGlxYpA MQVsPMlFP70qBeGpRTiWcTgj0Qb5MU6bC8HYlMAsI+WDys+ZOeVadLnuxnfYUCzi96Q3x0 1HlL0H/cP0eokpf8WHpgANmQByi0eXg= 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-290-tq44QnmUO9KmQ-WGEl3PcA-1; Fri, 19 May 2023 03:41:53 -0400 X-MC-Unique: tq44QnmUO9KmQ-WGEl3PcA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7B949800B2A; Fri, 19 May 2023 07:41:52 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8AEB4F2DE0; Fri, 19 May 2023 07:41:49 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , "Theodore Ts'o" , Andreas Dilger , linux-ext4@vger.kernel.org Subject: [PATCH v20 15/32] ext4: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:30 +0100 Message-Id: <20230519074047.1739879-16-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 98FF7100012 X-Stat-Signature: am7bjmfmydew1auxmd6zdxk8a159tn5d X-Rspam-User: X-HE-Tag: 1684482119-998041 X-HE-Meta: U2FsdGVkX1+O5ZQ10He58oatQMWAbSy4NUQQzTyropgXoxWM/zie0mzaERwzn5+BrqG8ok2wLBSVwAY73MslPEuiQjy0hI+EeIX8n0VfV3l7R4o7q8cPoHvq4bIFAcpjrIBQdKfH4Yr2t5D7YPorOKvF7AWb3++NKmgpe21UeHXKyz4YN9pXwTW/AzK7yCVRnprnhLhyRzXXVI4LsxiK3+Cjgx7Nnf+1WCN/BK1DEzSIuXnqMlHDg+iU0gwhjsGiOFGwHOGTRML/TTUGvtW8taZe4B24fiDEIMwzFGd2L499TYVuXP7RznYcl+NbRo6iw3h+8mKihi9pylYLOCnodXBmq8gJLGPuiXg3PKHnn7IznOYFmWHWdtntHhtcWnmOY0DiqUFix8sNDaNAwNim5rRfYVPN7MAomhpRphXxdTkaLLqkvbse3wTEsNs9x61FG9HBCZSsCiH8ILruNMEg9bU4nB2PHgRCp9V3WyI5xHdJ58OG/tCGw52AkCrY8EJF6dRSoIo613hKBq0w1odmbgGndRDYd4VEKEAzQZpyixZhzqOUnRtgvEQ/kZcnvpFe0xexS/m7VNtT7EMQW3qmWk4OOYkIHWyJzX4HiDdQEsGnuXoe+VD6JailEBIRMaLhCn4WASPLk3Irg/vWXEqvpdH4GFgcCb743etpo9U8gj63my0hFCaAMV0PsSZchaXSqR/s7TWaXzdMWPTKEfq5lDPpgeQ8aQlPSna9zyyhFbSSMJXFbMm2WA4Zf/OEYZHaWp9EwWmEW/reB+gXdiYcUl+t8oj6J3UAOh/y7X9zohJCcsZNxoRSimle0KqRCm2NwWv6t4H+c5S0jg8TCmpXwEY9xAUgyIxr9KDCjcUzqD34xWHTt5KeJ+Xyz0m3pdh8ZSyiVyrd5BVKtBT1qhBvfsmqwwArgBrIRNjk+GYx/HDz0Su3D9MrASjdPZJG7L+kmgq17uXCQu+Y1dIAiMu NmoJsBmq J3zWFD8eK8ZeydmmK9nPBOxtawp/LJxLhzYWZ+99En2WRCczKV+2bPxQkKDRdtHsRc/XnPhf/TUFG49bil1VcpW4QZ2PkADh0CB/3DXLfco8Zwu3pqsXAN1SzUaYVBXHK5FiObFh6EubEVkPN9YH6oDoWH3gX5vwAml5ltsu0vPnZtHHmnXWc0XEEeIwmEfsibJezmY8qdpRsbbongFUm4OCKNTsZi6I+Dk1yy6gt2gLYGC5ErU7kC6CmyFJ8+25tU+dyFZuenPMwK/ftgIDTcayKqE2K3EVo5HfePb9iQxtGvElhf0xdxy8KVwHS3ryMLqQp0x1XRWYR4zq1i3He+603y7ObbqGWo3P8BZ4APjSClL8yEbCBCMQtveH65tbChtgwdFGIlGUsPREMc9xJINLxkmFPgTxWSick 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: Provide a splice_read stub for Ext4. This does the inode shutdown check before proceeding. Splicing from DAX files is handled by generic_file_splice_read(). Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: "Theodore Ts'o" cc: Andreas Dilger cc: linux-ext4@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/ext4/file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index d101b3b0c7da..9f8bbd9d131c 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -147,6 +147,17 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return generic_file_read_iter(iocb, to); } +static ssize_t ext4_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); + + if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) + return -EIO; + return generic_file_splice_read(in, ppos, pipe, len, flags); +} + /* * Called when an inode is released. Note that this is different * from ext4_file_open: open gets called at every open, but release @@ -957,7 +968,7 @@ const struct file_operations ext4_file_operations = { .release = ext4_release_file, .fsync = ext4_sync_file, .get_unmapped_area = thp_get_unmapped_area, - .splice_read = generic_file_splice_read, + .splice_read = ext4_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, }; From patchwork Fri May 19 07:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247771 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 4DB85C7EE2C for ; Fri, 19 May 2023 07:42:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBED4900018; Fri, 19 May 2023 03:42:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4595900003; Fri, 19 May 2023 03:42:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE635900018; Fri, 19 May 2023 03:42:06 -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 9DFB8900003 for ; Fri, 19 May 2023 03:42:06 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 77077140928 for ; Fri, 19 May 2023 07:42:06 +0000 (UTC) X-FDA: 80806211052.18.1BA5704 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id C326140013 for ; Fri, 19 May 2023 07:42:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkAWxd+t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482124; a=rsa-sha256; cv=none; b=onMaeZ3z9RDZM+DqJmtnacCwzzy8wcqzftffies+R+hn0bDZue1/wjlCqYsPuo2IZRNix4 fZ227IAbe51a1z/xB5c6zJkJieGPrq7h0Wj5zrNd146cXvdioXl2QlVtn9RyOskH4GpFon qRtnmOVMydO896CYxzGj9S/Bg6XOpMI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkAWxd+t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482124; 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=r5qDgkT4BMNnpU06yXa6htF6MTIyeI5iJgctjYsdWto=; b=jhHorrHVhaCVSTWpXcfF0YD7qgX9DFcZYnpGnXwUP2hFPVQvR60GYZbXoTVi/Ha0YfBwNo LO2MqpwNnl2d3z/V3ouzxHKB8FfDrko46AKqtvad/nfQ28HJu/4aj9I+T4IEPeSSxCi4t7 rgiEudPborpRimBSJJo5AABTz7YdqSQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482124; 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=r5qDgkT4BMNnpU06yXa6htF6MTIyeI5iJgctjYsdWto=; b=CkAWxd+tnzBvrvZkNPcdTTWBZO4EbktfAvmMHvMLkwgEmfdT/Dc0a/yOfu080htf1hVzDO qqfMYQCFlsP3MKrd6gIHXBsRas8j3QwNWjHcgcbl0Iv8KzBm3gGCjOv3Wo65aWNp+pdfj3 0rzvmbw5HjUnq7HHg+MilZrIuhdFzf4= 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-636-UwmqYBTZNaOSEg7543TOgw-1; Fri, 19 May 2023 03:41:56 -0400 X-MC-Unique: UwmqYBTZNaOSEg7543TOgw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABE8E1C04B50; Fri, 19 May 2023 07:41:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 367671121314; Fri, 19 May 2023 07:41:53 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v20 16/32] f2fs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:31 +0100 Message-Id: <20230519074047.1739879-17-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C326140013 X-Stat-Signature: 561kek6tbqkiytrziifi1w7xcnqzhgsr X-HE-Tag: 1684482124-783283 X-HE-Meta: U2FsdGVkX19Wa7KipNb4L34W5pS07tSWw9AN30j460mZnM1IAVDnO8KxKahzP6t+x9SiEgD7Js6mbkKGHvhClYGDzQNDi2221afcPHsv+EzwzHI2xxKIoo97CMqfHyagI1qUDpvtQdvvPI23klDUlp/s+0OY40L91wmKU7oyFM2ducM21fTMm7hxv3U9260D3XzL5B/H8Ll/hI9yfGlz6Qm7g8gDobGO09MYZdjbKcGpBRRt8stI4fuy98wvvyHvFRFDoIhlD0q8Q1pn7I5y47Z/SEXT9CJ79HAIervORRj/RoRfeMeaBkHI+2cZDRK8OGrwxnLefGRAbrKRk8DDtZ1cEj2KXkjsestubFYpei/bgUMu8xwLq1xUt8mVFjMjc1zSxyQcNoLfOE7bwyGBzzk/uUglht5Z4d3TguehYfDeFJkQI40PuuTGrimVXAHDlunVpROZaZI1VM31u12g1IFDC3Cp+5bC0f90u3W/FtMdfPSBLeX0KSEvq7OVZlv2aFx6fIFwAQNNsEwcdm04DXEYitD4tS7HDxO9AV5PlIq/WLHM17Y1YrHHS4/6Y67uaTh0W+VAEQVd/bpaezMW0wE8677buhReHowSo3774FUFlCmSzPrY9wweual/JW0xJrdv/QBjSgA5CPSyysfiK6q+Pkjywo87b3I/fPb7+0p3mbzFwL0jXLpNvYMB96a0QDud9eJ2maJyTv4Pni+5aNIvKKrjtWMvnQdL8MqTprvFCuEScdR00e/4RlkF+CeAPSjOR1C9Dzbrqi1yKuvyzSrWGtyFyGjXJyfQlIOx1iS8JQh77EYlLlTDxGx89lkpe6L2aDdTHo9HwBN6HKKmDznMtsdCg7WQLLbPeuI5y58T0v0FXnmhs8mOp/P5plsWo5zMnfwVlOsoeFne1nls4c1K0JBbt9zvXHnvjR/w/6uA/yEwzigns/QRnUb4doHFpK79wlG9cdWRWs3KNkh yxyppbeL VTGynbhjKH7TzU86POo4bmEk6sw2TIynpf3ddDjqMEt+0TP/vDlrdNkNQ5YPkp4J0pRmhVB/P89WU7GuNRgF0jv7llowalsHeey4HreQBmX4s4tvy9zXznAlM/37TCDODqmwCb34UNFLTaX3G2L+yHJFUMB1+xclgrE6TMGKOsDJYzip66RPAvso+TLEuNeJBgReyDq5KeumsXnySYL57qw0B5T1eSwaZ2VpmSV3PxBfmYAm7sp09L/msv9M54xD6KQl9fhNkTWd/zA7APkld6W78yD9QZiFoQaNjprW6DakRGeHoNY86DvU1VyYtdpoeKdaiNToiAE4nCJFXBYZ8IKvsww/OuqIO7NJtpwRODa9dd17LAVLKNOYLeg== 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: Provide a splice_read stub for f2fs. This does some checks and tracing before proceeding and will switch from direct-I/O to buffered I/O if forced or if misaligned. It also updates the iostats after doing a buffered I/O. [Note: I wonder if I should only do the tracing if I call filemap_splice_read() as direct_splice_read() will call f2fs_file_read_iter().] Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Jaegeuk Kim cc: Chao Yu cc: linux-f2fs-devel@lists.sourceforge.net cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/f2fs/file.c | 68 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5ac53d2627d2..3723387f4a87 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4367,22 +4367,23 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } -static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) +static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, + int rw) { - struct inode *inode = file_inode(iocb->ki_filp); + struct inode *inode = file_inode(file); char *buf, *path; buf = f2fs_getname(F2FS_I_SB(inode)); if (!buf) return; - path = dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX); + path = dentry_path_raw(file_dentry(file), buf, PATH_MAX); if (IS_ERR(path)) goto free_buf; if (rw == WRITE) - trace_f2fs_datawrite_start(inode, iocb->ki_pos, count, + trace_f2fs_datawrite_start(inode, pos, count, current->pid, path, current->comm); else - trace_f2fs_dataread_start(inode, iocb->ki_pos, count, + trace_f2fs_dataread_start(inode, pos, count, current->pid, path, current->comm); free_buf: f2fs_putname(buf); @@ -4398,7 +4399,8 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return -EOPNOTSUPP; if (trace_f2fs_dataread_start_enabled()) - f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + iov_iter_count(to), READ); if (f2fs_should_use_dio(inode, iocb, to)) { ret = f2fs_dio_read_iter(iocb, to); @@ -4413,6 +4415,55 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t f2fs_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); + const loff_t pos = *ppos; + ssize_t ret; + + if (!f2fs_is_compress_backend_ready(inode)) + return -EOPNOTSUPP; + + if (trace_f2fs_dataread_start_enabled()) + f2fs_trace_rw_file_path(in, pos, len, READ); + + if (in->f_flags & O_DIRECT) { + if (f2fs_force_buffered_io(inode, READ)) + goto buffered; + + /* + * Direct I/O not aligned to the disk's logical_block_size will + * be attempted, but will fail with -EINVAL. + * + * f2fs additionally requires that direct I/O be aligned to the + * filesystem block size, which is often a stricter + * requirement. However, f2fs traditionally falls back to + * buffered I/O on requests that are logical_block_size-aligned + * but not fs-block aligned. + * + * The below logic implements this behavior. + */ + if (!IS_ALIGNED(pos, i_blocksize(inode)) && + IS_ALIGNED(pos, bdev_logical_block_size(inode->i_sb->s_bdev))) + goto buffered; + ret = direct_splice_read(in, ppos, pipe, len, flags); + goto done; + } + +buffered: + ret = filemap_splice_read(in, ppos, pipe, len, flags); + if (ret > 0) + f2fs_update_iostat(F2FS_I_SB(inode), inode, + APP_BUFFERED_READ_IO, ret); + +done: + if (trace_f2fs_dataread_end_enabled()) + trace_f2fs_dataread_end(inode, pos, ret); + return ret; +} + static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -4714,7 +4765,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ret = preallocated; } else { if (trace_f2fs_datawrite_start_enabled()) - f2fs_trace_rw_file_path(iocb, orig_count, WRITE); + f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos, + orig_count, WRITE); /* Do the actual write. */ ret = dio ? @@ -4919,7 +4971,7 @@ const struct file_operations f2fs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = f2fs_compat_ioctl, #endif - .splice_read = generic_file_splice_read, + .splice_read = f2fs_file_splice_read, .splice_write = iter_file_splice_write, .fadvise = f2fs_file_fadvise, }; From patchwork Fri May 19 07:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247772 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 BFAE4C77B7F for ; Fri, 19 May 2023 07:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D10B900019; Fri, 19 May 2023 03:42:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 456A7900003; Fri, 19 May 2023 03:42:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D208900019; Fri, 19 May 2023 03:42:08 -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 1B946900003 for ; Fri, 19 May 2023 03:42:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DFA07140957 for ; Fri, 19 May 2023 07:42:07 +0000 (UTC) X-FDA: 80806211094.08.D1C6A99 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 30F9340002 for ; Fri, 19 May 2023 07:42:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K+9wDHTi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1684482125; 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=NhBgu+YPWWuhiMuhxeBoG/WfhrSyIDZx4YN21OB8Xyg=; b=EpK0xpLM3SGkk5U3H5TIR++FcYMHsat/93Bm3Ts2cfulEl2DEX2hOx5AVFPPySshya7jpt EEl5YaxEJY6yGGUAMUq+hF4QFn7vMHA/QUF2d9fFeSj6BSLK3AyirtspWfK9CRo3iF8VAf xgzhv2fnOPE3jULfp5qaM0FL3sey1c8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K+9wDHTi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1684482125; a=rsa-sha256; cv=none; b=Qztbj3LwxOhr35+2SwThybYQLPZUXFsAC8BbcbDwl5LIUOhIXxiTLYAdvkU6iOiGRocFY+ rSKtAXE3nL1qbcz/fOELmgr1N84rJERK8FxMGzGJT9jiX6yO7TRBh6u52rLTx5iLdZxwvs KrQeArfDwD49MIa1Ek2U0CDzkYQtooY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482124; 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=NhBgu+YPWWuhiMuhxeBoG/WfhrSyIDZx4YN21OB8Xyg=; b=K+9wDHTiJ0B88mO4oyOUKCWHCR8UY6/nx8lSDGQ18tvwaiUYyXSfQNyOloniLt0HN0zqk6 2KJcX8SO+FfCmLvJYrslZnF8VrNrIyZYka9dhpQEoLm8xWN06XKTpj2ehSi6aYwTiv1/1v 72n/AkdfwZRk1fZsiiB1nds2F9qYq0M= 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-675-eDOVwGWEMCmaAhO0IYU1iA-1; Fri, 19 May 2023 03:41:59 -0400 X-MC-Unique: eDOVwGWEMCmaAhO0IYU1iA-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 EABBE3C01D8C; Fri, 19 May 2023 07:41:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AC6F2166B28; Fri, 19 May 2023 07:41:56 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v20 17/32] nfs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:32 +0100 Message-Id: <20230519074047.1739879-18-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: 30F9340002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: gqw146n6b4gguxx46xtxaoq8skn9tob4 X-HE-Tag: 1684482125-434751 X-HE-Meta: U2FsdGVkX19yLstGcfI+IL4SCewDEj5zi8xJhqsyq59auydNcVC7xwtB2kI/DWzdDR8bPy0ULV6MLjYAREsAqiP54YK5t4EWeRKXu9DpELCtgqoX2kz6K6KBdZ0NagZq88Wy5esliSK8eKIcFP1yMlO7w7wp3LZZv9Hfd01jk5PRgiCGL2jRzde+YscH2exjDtIrr6Nwod4+HKyXgCQ7Rmhh6HOVwhWbF8lKdmWX4FOQf2nnBSATtdIVwyII1orpTpKv4FKZ3PntyvGlJ1DNd8dDntjZBrQ+nbL9T1eI9gdCHM3h8PjLRr4Mubu8BtN3jjnCm02hv1jUln4JQHWsTvUQazwL1uO9fUzQJKgBy7yzi+W9LYi0bs+Tt6GHaCI8P7rQ04xk7k4MLlcQoTksPGEaLPTyqILHVIlAU5b6eDEEvyuykOeFXOa+kpnHyMfRSy9oeBimGAEmX2coL+VUkzweAO2JImoIodG+WUGo6zA6Du/8MDP3z2/Z1odo8l8+LqlWGz46AxeI8ofmlmV7LbgleGFAr7hTcEqo9HP0NLfhGB7m7whwF9neqNdkn3u2UvArl0KbCxS840KitsTZKcny0ircxDf5rHeKCSJEMSUrEmrPKQzhNeCZZzvzmsAko8xHfxA2b0fSWlaCo2GW/QNPjK5yVWZsd9L9TOO7218feItuRLLIJJFrYKJ4pb65nhLi+eZAOVkPprbxNWYVfyPzB9fUP6IC01v6N+YeAsah4SYvqhUczmu6HGvvnbNwx6njd9l7HFTxIhCJGkdgIaacAOCQO04T/6Fw4unjALUm1MDs+ysYKNDQpg3xLOCkjI2FjGNo9AWKCQO2v/k6JLUwkhO+8O3z1ek/xcr2pcTytm4mE5omjwvBWGYfkXGOuzywMllQ8CB0Ie42nJzY8uvN+6B7VFqXC3QB5T7KMmsfddoDV1zLxPge7B0B/X2qfeGhucxzWOXFBOa7sxZ iiyeIRc6 d6LHEL4tuqVXe1sevhBjxKIs43JowqgE8x4lj8i7HGEnA3R/pEVvqGBrprcBry7LSm5XhN6eD+0L/EAIXzYquweoqmYFd1I9Q3wHNqVZfaZ6Sr8kuForDYnIhehBa8BdYj0JKZZukkqyvU66N20Q3WtZRBLbpICMNeG9RvmSPKFnC/yOwz0aVo1dr+1nMpPsv41Vg9KSh/o83hLUJmlb9eMNAI5VPqddQRLYJ1kAtK7NFW2TDBgqD/tLPrUHqovelbwZ1W5MvQ4Nh5B00JXqdS6P2/ZrutF6AfrQbUQO4kyXYgL76zcpGec+RoKma4MxQlXirGphtTz7lF18wVVYoUGzNe6lSjQi6IDcOwtg4DqHvo3crOA9bVPZ6j7a5h6m4OYOnKpjhnnEb4qyZKKjaSO5z9oJDR1bk0vB5 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: Provide a splice_read stub for NFS. This locks the inode around filemap_splice_read() and revalidates the mapping. It cannot do this around direct_splice_read() as that calls ->read_iter(). Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Trond Myklebust cc: Anna Schumaker cc: linux-nfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/nfs/file.c | 26 +++++++++++++++++++++++++- fs/nfs/internal.h | 2 ++ fs/nfs/nfs4file.c | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f0edf5a36237..91fe48b47f3c 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -178,6 +178,30 @@ nfs_file_read(struct kiocb *iocb, struct iov_iter *to) } EXPORT_SYMBOL_GPL(nfs_file_read); +ssize_t +nfs_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); + ssize_t result; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + dprintk("NFS: splice_read(%pD2, %zu@%lu)\n", in, len, *pos); + + nfs_start_io_read(inode); + result = nfs_revalidate_mapping(inode, in->f_mapping); + if (!result) { + result = filemap_splice_read(in, ppos, pipe, len, flags); + if (result > 0) + nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result); + } + nfs_end_io_read(inode); + return result; +} +EXPORT_SYMBOL_GPL(nfs_file_splice_read); + int nfs_file_mmap(struct file * file, struct vm_area_struct * vma) { @@ -879,7 +903,7 @@ const struct file_operations nfs_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, + .splice_read = nfs_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = simple_nosetlease, diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 3cc027d3bd58..b5f21d35d30e 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -416,6 +416,8 @@ static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server) int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); loff_t nfs_file_llseek(struct file *, loff_t, int); ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); +ssize_t nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, + size_t len, unsigned int flags); int nfs_file_mmap(struct file *, struct vm_area_struct *); ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); int nfs_file_release(struct inode *, struct file *); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 2563ed8580f3..4aeadd6e1a6d 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -454,7 +454,7 @@ const struct file_operations nfs4_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, + .splice_read = nfs_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = nfs4_setlease, From patchwork Fri May 19 07:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247773 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 24EE0C7EE2C for ; Fri, 19 May 2023 07:42:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83D590001A; Fri, 19 May 2023 03:42:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B349B900003; Fri, 19 May 2023 03:42:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AFBB90001A; Fri, 19 May 2023 03:42:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 88140900003 for ; Fri, 19 May 2023 03:42:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5480C409CA for ; Fri, 19 May 2023 07:42:10 +0000 (UTC) X-FDA: 80806211220.23.D6E734F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 8E5611A0015 for ; Fri, 19 May 2023 07:42:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fWKYlf9S; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1684482128; 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=MIKgygGFPP04jCWudTIx6Exr1BpE2idki489iWC06JA=; b=s4JP9l7jLo+rKCkv0q+qySkORURCBu9d+PFlGDBRSlc67LYlE9W0ciKZL+91xz1Ylh4zFf yp7OeoLMd3eR6YFrNN5obCIwqdIG53Yx/31+HT+/m+ADkjhsrFXCPtok/MWPYxYe8vy4Fs ohqckGxEdxii+CpDfDf8tR/GnSEFnv4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fWKYlf9S; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.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=1684482128; a=rsa-sha256; cv=none; b=Zk2yFBJ11AZXC6Ob0lfGBMTsan6WndvT7oPfUD9K3RQa7hqasLB+5v1+cHF9EB2akmNYgX ya58R7fjoCbVilogRdh0xM5auJwPgXFkNXWXYNAkagC5vCTGDM/nj04bbcWcCmGb+rQs1+ /LL9RQqRIXlquTnpwIvzy3x+AuHSFYQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482128; 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=MIKgygGFPP04jCWudTIx6Exr1BpE2idki489iWC06JA=; b=fWKYlf9SfLfRFTbAO//ZuAUpo9j6xAMRkplXQTESAh5Hn8BtiSTFb/nkvxg2bc0iRoRzUY Owy0Q6ILjsKVVsqi1AfVrG1HOlaV9L/HbRPiTxA7LrYZcAM3OaxP7gCIO5HlQIgIvQ0nJb JvxLLDhwpHOAnrMrXVKUfN5DhzKgdzA= 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-76-BiSEfFWJO5ihxPcX24ACRw-1; Fri, 19 May 2023 03:42:03 -0400 X-MC-Unique: BiSEfFWJO5ihxPcX24ACRw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADED48027F5; Fri, 19 May 2023 07:42:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BEDF40CFD45; Fri, 19 May 2023 07:41:59 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Konstantin Komarov , ntfs3@lists.linux.dev Subject: [PATCH v20 18/32] ntfs3: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:33 +0100 Message-Id: <20230519074047.1739879-19-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8E5611A0015 X-Stat-Signature: gbhywhttfoirntxrpubfsubuipbccte7 X-HE-Tag: 1684482128-927225 X-HE-Meta: U2FsdGVkX185rYZSaeqYb6OQiJ3KMVoiFj4dzyZVg+GoIVcN5KFZiIvBgIiBBpjl5EWaQy5vgPEJX9OmLHHaLBDAV35v2rnk5yjcZaJ/URLM+NCGHApoMi7zqFxdmNopXRUgm7xw6oeeNa8GDH/uGd4oLp8lh4uoNE732t76a3aq01PnbiVkJxlrlumdF5x/f4ZPaXxKu8x5nl0Clk/SFKhmoMBJZNbaNR+lWcdNSHNwiqr4ryEPVjb5Ky27m9LIjCLZvWCEQUPT9APi4UnEXrhH5saLYQG7TPsst+cNmkfrgAXAdUvqbNlbqVGWD8jqptvGBZvtD5SawR4O0ck65ec/G1t72zhSeMmfYkuRyi+Y9I23n2GZMCAutMZg5e4tCH5onsX5dcvsNzIv+0Yup6AANEAdfWXYZYh8We/d3mzJiMeOHQiVCzCBVvF5M8NAg8xhfzKZ6mJiQ6wo3UKr8QsWNfGPHdgv3TEkPQ0BTSGv7W9sSZ++u3AudZoebHhkv1IAyAlwrO4iQZsu2RIRbLGSPsS57Wux/WhRM0xqLKKjI7j37yX6YRf1nnBO7NtmDWRPnv/eLkAmZDh1JtnA8f4qV+Nxm7eXdzb4rTJXFhf+YWK+vO/Fc9mjFuCjcSaZDK3FanjIG/8O81r2xk2CsJrlQzVAQTsJ8KiQLd3Ew9cjoXtcj0UpBn2MiMLin1uAwu26QvxkWeC8SE0td7WfCZCT+QS145zvGByQkSyIbtoPmk+wvxBG+VyWCl2BR6bNZUfjT5HDR9585OQ3QQ+cod+3/A/oGAvmv+ut5DocjQ1ypb6NSWpMwwDXVnnkxKsrFOwv7MxT/6ua+IYMW8ra4ADP9F0D0RrqrCIskex7pDTm4QkghqSn0vuuPUB0iWMMtyQHgNEEQ0+FzT0PKfVwcZbtVT3UmBe6mirJDhmT584FRBFu2vURUPz/+qKGSiCWIop0lgm88jTth8GmN/h TgsoISzj 3Pb0NdQO2hI8tqxhDLfowmbGqydw4Nbf3LBmb9bdhgykABZf2HbuJo6cGSAYgMMUdR4CG2CjstqBZ25frxHmaBIIh0dvoPIUFNOlM4+nOjzJ2I3dU3PIduP8CbjDRcVPSJ5PUdzFA6vq7dFGx9iQ2JiOpF82jJpiIKoZnRq5X7GkUthuC8QrzYwfY7Nx1+/kcpMIT+02uUymrWMQnU+PWJM+lkxM5ylSbTEorzQtzr9wKiSg/jAxVI4FjV5vnl8foJm7XbWAJ5+zrKvCiOuzufnnoyYbv4DgoYYGzN56vB4PgCSMQDFYrcDnxYq8p5CR5e50Vi+2tgW/QWtReTOSjhPSWHXWydFL8oRiDU5rNNWUhdFxf0C4B8k1174k2b1c/k4XWsYTgBm4zLJZMRPsYjcyfQQwEawTTZZIo 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: Provide a splice_read stub for NTFS3 to perform various checks before allowing the operation to proceed. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Konstantin Komarov cc: ntfs3@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/ntfs3/file.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 9a3d55c367d9..c27814946aa3 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -744,6 +744,40 @@ static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) return generic_file_read_iter(iocb, iter); } +static ssize_t ntfs_file_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode = in->f_mapping->host; + struct ntfs_inode *ni = ntfs_i(inode); + + if (is_encrypted(ni)) { + ntfs_inode_warn(inode, "encrypted i/o not supported"); + return -EOPNOTSUPP; + } + + if (is_compressed(ni) && (in->f_flags & O_DIRECT)) { + ntfs_inode_warn(inode, "direct i/o + compressed not supported"); + return -EOPNOTSUPP; + } + +#ifndef CONFIG_NTFS3_LZX_XPRESS + if (ni->ni_flags & NI_FLAG_COMPRESSED_MASK) { + ntfs_inode_warn( + inode, + "activate CONFIG_NTFS3_LZX_XPRESS to read external compressed files"); + return -EOPNOTSUPP; + } +#endif + + if (is_dedup(ni)) { + ntfs_inode_warn(inode, "read deduplicated not supported"); + return -EOPNOTSUPP; + } + + return generic_file_splice_read(in, ppos, pipe, len, flags); +} + /* * ntfs_get_frame_pages * @@ -1159,7 +1193,7 @@ const struct file_operations ntfs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = ntfs_compat_ioctl, #endif - .splice_read = generic_file_splice_read, + .splice_read = ntfs_file_splice_read, .mmap = ntfs_file_mmap, .open = ntfs_file_open, .fsync = generic_file_fsync, From patchwork Fri May 19 07:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247776 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 3E918C77B7F for ; Fri, 19 May 2023 07:42:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B84F890001D; Fri, 19 May 2023 03:42:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B34F3900003; Fri, 19 May 2023 03:42:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D4CF90001D; Fri, 19 May 2023 03:42:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 87249900003 for ; Fri, 19 May 2023 03:42:21 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 56F2C80991 for ; Fri, 19 May 2023 07:42:21 +0000 (UTC) X-FDA: 80806211682.18.B85D490 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 92390C000B for ; Fri, 19 May 2023 07:42:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=auxAEAlw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482138; 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=gBG1rbAQ+/pvrFxoUU2GMJeglrqrT3cq++hcE5SQo7w=; b=nD2CAncEWgrZsdmMYbDp6p/vmxZn8jKTwYwlbBYxf1wqvtBKtavQhjIbhVi9b5u5liaRq1 atHbs4kppR7U3WTH/Av++5zrSC8r3eAyvqikRKXZ9lnKZVej3OhUq97VDEyR3u5eWupkUD cs0PANCQPDU6VbYiXq7DWWna8TdT+AE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=auxAEAlw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482138; a=rsa-sha256; cv=none; b=pM4eOuDwu9Kexy+ihhlFmcO6e6KdgcXq+AibjufzOe9rgNVxWWcRwthve7NMGXSlTGClM9 3+/3gUa3arHIJpmZhkbDR21A9j40B4nHCwdOozfbgChPSocdG9D/9zYBXd4l1huLnV1YeN iGsWz4iZNUv/JM+BKUdc8L1tbzD8wpI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482137; 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=gBG1rbAQ+/pvrFxoUU2GMJeglrqrT3cq++hcE5SQo7w=; b=auxAEAlwthRjC6xSIlM/ZpgRq1TpplkHsMleVoLeA5Lg2NvLq90AmP7LWovhBuNss6Mt7S Jv+nPgQDe9H0mBZdEro8Y+m8m11EmF4gyesoAE/IPX8Rg/M0MIUmoqD28s81HJPKPUbU3H wBj41jSAHZ7/wxBTMCK/xgBHkG9wjy0= 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-465-_MfV9O_bPYGXDbkMXz1GRA-1; Fri, 19 May 2023 03:42:06 -0400 X-MC-Unique: _MfV9O_bPYGXDbkMXz1GRA-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 F0AF585A5BA; Fri, 19 May 2023 07:42:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 505E5C0004B; Fri, 19 May 2023 07:42:03 +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 , Mark Fasheh , Joel Becker , Joseph Qi , ocfs2-devel@oss.oracle.com Subject: [PATCH v20 19/32] ocfs2: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:34 +0100 Message-Id: <20230519074047.1739879-20-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-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: rspam12 X-Rspamd-Queue-Id: 92390C000B X-Stat-Signature: w7yn48am9zrknszzhsd77hm6ztj8hnc6 X-HE-Tag: 1684482138-793890 X-HE-Meta: U2FsdGVkX1/3Saha5efv167+YwP6ruc4c++8ZbUTGvjhZUZYtsxCD8RWgZUNg4qVEk2i1EZaPF62z2tpsOwJNlbz2BeD/r94AD9blhcaWRvjSnHmptzlyUID9k2hII3PsL83901XNZcP13k1bdev7dMY+w+3gFYOvKvKkmex7EnNX3NWVNKUZt4slmHNoFr06w89m9IM8hnTqhtXcPB2uBW/CZY8PS/SkS6+zOzg7SYtw/Plc+jnTYusVMXj+PYb6FFkaIx57UYx+3dl7FWLmrcN+p6swl64/whkJpgLh2ATYNy9mf9Syg/RrWwUVrqbyHQnrjrF6yVjwXIiJJRnFla7m0/cXftoIvvw43S4BVpqOkeHYA6vUgDiJA3uI1tnNjLf4CvsySFl2gALDn1npnlJBUokJmUM38HQD74KykgxeZPKBxc080SMeksFj/rP0Qht52qrMSmu2FL/emfcJ/Fpj/6ZWZVi0AqKXTEpPWxAIdyZ6L0FYYD+tVw0UmtC2114T3fLk11uiYZ3k1bB2eMWOEXbbqTm7CqwaMYkNrCthi/R11HFhjX+yLCddzTqa/r/eKW/hQ9DAXxQUIMFPDe0ve2ICO9xkxjedb2ZuurBVisNAwNwoLekvrE1ZRUk2grOJkZucWpOFu9v7LloWGQfoKrSBpf5MFPOC+wyNNxlhJaxn6uzNJaKXvjm57PjwBWLnxT9Rghn5qRfulxS4wxGvMrKODEBqVwc0tWajDhus4yF7pvyoLL5epzYIaMNy1zMvmDp7NS61jtt8atI6uNp3csdjnD6kuOTVAgCuK/0iMAsz9TXtXzfcR5UviXt+8KY9GNzk/Fqq6AM1XZG+kHJY6BbYbJPAWwBRdW/DbuiPMCcRH1hBMCWXS7zjbDaNBw9XdAVqb6yYyk9PJbvb+wEp1gbtfxVrh/cwp6PyWY+kXgGidDsMhAM9vO8U/0/OeUBSw6AKHwPlaIG9ln HZZfvHxJ mXxYhdyNuw5nbbJssce4aMt40jk8KVw/UmpB7GtlXA7AyxvYnaEcR0qYEgrQ7pv7yKeeA7c+VhEUXz0fmYhsFb80e4LUIf0lMq9J5rgXzXx5KAGAGRjBmH3OLBKb1u3NlIoWc+MlG1vMTMGG30KZQtiyDvNj9UMIY2lu8n+RjLw9RqQm8hPJM91jFGbNW9Z8IYE4bSi5/Rx3GIf8h2p4e2O9Brh/ope2/pwU4Ynpkb6+XEw3+lcJO3bDOXTZlOU3/nP7rJIVrWxlm73uBoG5jgG/Vt1VbuomIKO0NS2kuxbtSvKmRq0PaZFgUqhqvvk8dPrJ1lDZ9jtFYL1tFjP/fx5WGfquvUdosTD40KQhGO68Yd+fbpmGPS6WipqFG9gYk4/6XnCMSiKOCxQdw/cfYFgQegRnp6ENHFbZSqPI0slo/HuX43Azd7CPiMXl8zknAi8hWP+nAOASkl+igWwr+NtB+9JZPzF0l7MwHLuAZH/xhWSyZgon6GjtQK0L9Yx66peHfICusgStcZL8= 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: Provide a splice_read stub for ocfs2. This emits trace lines and does an atime lock/update before calling filemap_splice_read(). It doesn't do this for around direct_splice_read() as that will call ->read_iter(). A couple of new tracepoints are added for this purpose. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Mark Fasheh cc: Joel Becker cc: Joseph Qi cc: ocfs2-devel@oss.oracle.com cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/ocfs2/file.c | 42 +++++++++++++++++++++++++++++++++++++++++- fs/ocfs2/ocfs2_trace.h | 3 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index efb09de4343d..27c54a71ec57 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2581,6 +2581,46 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, return ret; } +static ssize_t ocfs2_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); + ssize_t ret = 0; + int lock_level = 0; + + trace_ocfs2_file_splice_read(inode, in, in->f_path.dentry, + (unsigned long long)OCFS2_I(inode)->ip_blkno, + in->f_path.dentry->d_name.len, + in->f_path.dentry->d_name.name, + 0); + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + /* + * We're fine letting folks race truncates and extending writes with + * read across the cluster, just like they can locally. Hence no + * rw_lock during read. + * + * Take and drop the meta data lock to update inode fields like i_size. + * This allows the checks down below generic_file_splice_read() a + * chance of actually working. + */ + ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level, true); + if (ret < 0) { + if (ret != -EAGAIN) + mlog_errno(ret); + goto bail; + } + ocfs2_inode_unlock(inode, lock_level); + + ret = filemap_splice_read(in, ppos, pipe, len, flags); + trace_filemap_splice_read_ret(ret); +bail: + return ret; +} + /* Refer generic_file_llseek_unlocked() */ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence) { @@ -2744,7 +2784,7 @@ const struct file_operations ocfs2_fops = { #endif .lock = ocfs2_lock, .flock = ocfs2_flock, - .splice_read = generic_file_splice_read, + .splice_read = ocfs2_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, .remap_file_range = ocfs2_remap_file_range, diff --git a/fs/ocfs2/ocfs2_trace.h b/fs/ocfs2/ocfs2_trace.h index dc4bce1649c1..b8c3d1702076 100644 --- a/fs/ocfs2/ocfs2_trace.h +++ b/fs/ocfs2/ocfs2_trace.h @@ -1319,6 +1319,8 @@ DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_write); DEFINE_OCFS2_FILE_OPS(ocfs2_file_read_iter); +DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_read); + DEFINE_OCFS2_ULL_ULL_ULL_EVENT(ocfs2_truncate_file); DEFINE_OCFS2_ULL_ULL_EVENT(ocfs2_truncate_file_error); @@ -1470,6 +1472,7 @@ TRACE_EVENT(ocfs2_prepare_inode_for_write, ); DEFINE_OCFS2_INT_EVENT(generic_file_read_iter_ret); +DEFINE_OCFS2_INT_EVENT(filemap_splice_read_ret); /* End of trace events for fs/ocfs2/file.c. */ From patchwork Fri May 19 07:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247774 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 01B47C7EE33 for ; Fri, 19 May 2023 07:42:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89E9390001B; Fri, 19 May 2023 03:42:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E30900003; Fri, 19 May 2023 03:42:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F03B90001B; Fri, 19 May 2023 03:42:16 -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 5C801900003 for ; Fri, 19 May 2023 03:42:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 366961C7929 for ; Fri, 19 May 2023 07:42:16 +0000 (UTC) X-FDA: 80806211472.23.B43FE02 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 7ACDA40012 for ; Fri, 19 May 2023 07:42:14 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RiFdtn8r; spf=pass (imf17.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=1684482134; 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=uuCSAVZVpWhK4klEEqx7Ct2l0SGs5ZJdbhyX0+gkImI=; b=WScUWxKfN3OtVTFCOEykeXIGK/6tV/52EnOpK8r2o1LVcj86rPvZdbypQzxtjWM4Ox+sS5 Ul3YBbXHPG/dk5t83FLMCpHiAXPnDNNxnOXI9OrZqLj2lUIbJnBbmty7Z+dxFIomcs/05A 33SmvZdKKjAqyD6LNjwo/xavBCF9OQ4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482134; a=rsa-sha256; cv=none; b=DPhmgfgLg5Fr35fcgVKQoXeT06Bl308GV65k8Ssk1/M5Uiesd5eOEbzY0dw3UDo2ASlpv6 dro7tj79nz7fyFTylP8ByYbvbZF8TfaEAtkruhHG4BFPaJ9vWn9xb1uMHXcVFuxP32qdyX //ToRzb86PfsB/GkwL/2Fe55ODhG5eA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RiFdtn8r; spf=pass (imf17.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482133; 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=uuCSAVZVpWhK4klEEqx7Ct2l0SGs5ZJdbhyX0+gkImI=; b=RiFdtn8rdi0r6MqnwRMpeS9k8j4SYLjZ278vKPRVJcIkLDB2cQlDnp1kHX9gpE1gItNp3k 9kgaRnq9vAV6IVlcJ5nNRKEk3SBbRyci7a6W5GoXop0zaeIiHXU8/2jUuaye/ofJz6NATs 6xfcwwpAznSFgRT+u+0HdLLFF8qTvog= 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-570-9WYmFVhKPfigCOXLKK6NJQ-1; Fri, 19 May 2023 03:42:10 -0400 X-MC-Unique: 9WYmFVhKPfigCOXLKK6NJQ-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 43746101A53B; Fri, 19 May 2023 07:42:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A998E40D1B60; Fri, 19 May 2023 07:42:06 +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 , Mike Marshall , Martin Brandenburg , devel@lists.orangefs.org Subject: [PATCH v20 20/32] orangefs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:35 +0100 Message-Id: <20230519074047.1739879-21-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Stat-Signature: de1txn8q6pzetcrntpinjmmgcmkfwsg4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7ACDA40012 X-Rspam-User: X-HE-Tag: 1684482134-540029 X-HE-Meta: U2FsdGVkX199AHX9kAGUb+S1D/FBxtMy4kITSv7LTyoJc4DMq1q3tMfrloQdFD0FE2Fxvaqz8Dv3Q5CkSXJNNsQmEzek4AAuJCccOIBCcMNXi/lnWsKIpJZq9qvRRDueG/CQxY6BhfLGtyw3xB+CiUiavdqW3hA8/7jqs9AmF0+t3IiuYyFC7CDv2msBiMNDKB2DNVOxefJKFIdiAqxltzeEbFuhSgEyzMU5hQ5iwAqhXAhWZZJb5Pef2RmoqYt2rYkao0sTwVspnncH4KKC+pNOSwCVtBKdv3VmY7jSIk63WOLRogzHpy/Z5OG0unlLINsnsP8YhC/QRG077vzhJUFnCsA0syrOm0waSK63IbNOxGRXG7sreKR8aaSXerrL7R/iV416IfOgEHHlRBp5cMNHqzgg36pU4CI2vqrFquCDegIIfJy5M/85QRiWQNS4xa2UbYaPRXbrIX9EqRiMJdZhcdDk6KadwWChRHlg9g2HmGxGkiURGIzU2EvRNffTiHWbYbVC1ox+IIw6MMbY+EvLRpPfEOaLl2C6SDWtCY7MXEP3C3nj30g3KX8SH0xYTKdHhoa2CaVVZjjS0ltyzjamW9LvkoeBJxTWttV6sd3hPhRid+e+qd7EBMx4ou7K6HtKSCOh8F4ao22KKBzbsZ2GRHqidtcUlZcH3RoeN3Mw+2xYkkF3gOJHhkouC0rzNK4YHqQaNrfyeBrYoNSTySmfTtaHOHo5zNqggStNzNENYlgqVIfC/5JEoSREGdfSlEp7CtTusYCVif2Vy+PXkUQ6K1c97vvgTnIKwqLhL49yv2bXs+ED3GpkEX+kI7p4XiREuzQBWRGnuyKsXhSYlJdOKUixThVKiSiJm1jUGxmnwJLcJOL5LQ4ajXeK/tKN2pXKyuKKypz09uMpdyFupaFD6ynnCJCqHgIN2ADIlZCfBupVJu3KjPRASVfm6hiQec1dxSRqm1uKfR/ob2y I8p6RCnI vV76ZUGdjNVlJh+skG6Dv7zQ6ryaXQj0LmUG9YPJF4FPlvgwb37jrz5wRAbLvgFr0M+0DUiLp7vCpYhku7ZuT2ZrQ1ui+ltvMbjmLwBof/MDWCJwTFqproA3WT4vVnRXaHdmmsfJlE5JIgogODRs5bG/rYH3NqzsTkoJCRV78VuICvJXLm53IPHai56trwN/XZQKjNtGAdbHv1FqaQ6PKwha28/kyBbdEf6aoWGgsxv/pNmfp8vUfKggTUfYs6HQOk1xxEJs2l9WlO8+weXXp3qEekVVHJ/IAO7sK2h7pDcE9Pghcoy1p9gk4REfr7knJ95kNy/cIHt3rYjPH6FCFhW4esmwlJvIzDcnGE4H9rhNktTUPNhutygkmYcpa9ZVa/WT2IxKFMO2+Xuo0YVNXbwjNCqHLMEn0mbXiIrDRyidiDVSdx2c6ba7Ect3TJuYI6lSzqj2aftE/RI4VkVIo+wEWfw== 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: Provide a splice_read stub for ocfs2. This increments the read stats and then locks the inode across the call to filemap_splice_read() and a revalidation of the mapping. The lock must not be held across the call to direct_splice_read() as this calls ->read_iter(); this might also mean that the stat increment doesn't need to be done in DIO mode. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Mike Marshall cc: Martin Brandenburg cc: devel@lists.orangefs.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/orangefs/file.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c index 1a4301a38aa7..c1eae145e4a8 100644 --- a/fs/orangefs/file.c +++ b/fs/orangefs/file.c @@ -337,6 +337,29 @@ static ssize_t orangefs_file_read_iter(struct kiocb *iocb, return ret; } +static ssize_t orangefs_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); + ssize_t ret; + + orangefs_stats.reads++; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + down_read(&inode->i_rwsem); + ret = orangefs_revalidate_mapping(inode); + if (ret) + goto out; + + ret = filemap_splice_read(in, ppos, pipe, len, flags); +out: + up_read(&inode->i_rwsem); + return ret; +} + static ssize_t orangefs_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) { @@ -556,7 +579,7 @@ const struct file_operations orangefs_file_operations = { .lock = orangefs_lock, .mmap = orangefs_file_mmap, .open = generic_file_open, - .splice_read = generic_file_splice_read, + .splice_read = orangefs_file_splice_read, .splice_write = iter_file_splice_write, .flush = orangefs_flush, .release = orangefs_file_release, From patchwork Fri May 19 07:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247775 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 49716C77B7A for ; Fri, 19 May 2023 07:42:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBD6490001C; Fri, 19 May 2023 03:42:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C457B900003; Fri, 19 May 2023 03:42:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4B1490001C; Fri, 19 May 2023 03:42:17 -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 909B1900003 for ; Fri, 19 May 2023 03:42:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71105140955 for ; Fri, 19 May 2023 07:42:17 +0000 (UTC) X-FDA: 80806211514.14.823D61D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id B450B20013 for ; Fri, 19 May 2023 07:42:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmMBN4ke; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482135; 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=xmbbe/+Pf//AKyGpf7irbs4+/+24QQIbTBxvLgLUtSY=; b=Hkk1YlU7l4u5KDKkQRJoRhASGHTeyELDVXduD8A8T79pwJZ8egjsxc2R3UZkzis0gbvQi3 tbC2XVeqOQq8T1fgkuFczJbWLpXNaIZL5h4OKASURmcYrow72cJ0r4PBvVwXCKpJTLqMHs 6FAH0ZEJJKZubC66VXclnlmRsNKWOMs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GmMBN4ke; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482135; a=rsa-sha256; cv=none; b=al1t4Xhm0VufPL+z09C6ZZ+F/+7JKyBVUSES77cd6QNw46NBaNBQsD5K6AIqN88xrjuvdg PElNY6Tl+A2hnjzGl4n9rpntQtR58ndFf6qzDxkKnDvnu0zbg0QMtok60Nk3xGebmjEltX PQYg1JJLVIsXWz7vlnBpfhxUUXQDeWY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482134; 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=xmbbe/+Pf//AKyGpf7irbs4+/+24QQIbTBxvLgLUtSY=; b=GmMBN4kecnjlKfmwIz82ZBWaSD5LCcyCDe9H5JpTob09PSAjuCLkmZOlQmKo2zbnMqUuiJ I1ktkcPds7CM0//BOsSSYmMiBUepQp5HJrIFaTOtXwqFIe8lpc998lpveTKQ85WiLmqJiO r7sVQxIyklV8iWDwxvGhtHzfLCfhg6M= 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-498-MoZDh_T_MgiO891JIsJM_g-1; Fri, 19 May 2023 03:42:13 -0400 X-MC-Unique: MoZDh_T_MgiO891JIsJM_g-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 337F7101A55C; Fri, 19 May 2023 07:42:12 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D137B492B0A; Fri, 19 May 2023 07:42:09 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , "Darrick J . Wong" , linux-xfs@vger.kernel.org Subject: [PATCH v20 21/32] xfs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:36 +0100 Message-Id: <20230519074047.1739879-22-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: gawttsoyc5iye47jj3skhck5etoeziao X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B450B20013 X-HE-Tag: 1684482135-964277 X-HE-Meta: U2FsdGVkX1/vHjh/pW5IzdwZ8ACLr8VqjTHWx3rAkuSmjMSee13DM0fk+Nt5v/2CDc5bmH/InFWTsUVXYr1T5sGxzVbyWnM46mvisu2ym1fFcKz3ThHjwlMlkqgKQ0nh6Khy9wslnnJO6FU7GdRyqV7Z4xg3rygXEK2pzN0sFtdPZMeY0kOZ8ogqBA2KLAzlFAAz8xmq9EWdGHs1zNPHoF2Q27OKkAR6q8cskmuM4kEP/O8bVL6H4KtXgJw+koFK1598NWHSE0mvuTYMVk4oW4+NandK6ADQoQg1n5CyLWB3k0Vc02/vJIO1lgGa2O3Ht/PEfWdtzQVWuRhvDZw5gvFv6irXKb7bqadDW+FHQAZVwqOYbPCuEkSNNRJ+oL/DpPmH99jP1J3VtsWf7NwXiKUBPBL8AZ+Ql/RCVfwK3VSjIkFrhBg143BYXXuIPWxXO/qcfaoiAdeltOq/K0t5P8mhBriutK1TTqVd1whTonT8jmvXXJzE9M7ZJCFTlTJd62QcjEqZR5MaFOa4GRstxM8fXPIcaLMBrBLCWSRAdOAC+CekA+FJ4Hmkf3TKX1tZ+DdjxwMDh6zJMOLeC6WIMcER9qj+pG+65msGUtIaX2AcUb588iJRa6xp/57M0kld2FGlblnvLwenuDk1gZFxAcyOM6BTCOV38HjznK14qLDaVXb9n39yRCcidl8m2rqod5VQoH1bXU13erUitJPF2Hx/X25w/RBn8QHogVCE3snOGtrPwd4eF6no2T0qdaxzyKdz1S5qcGmWpuZGgbdE16Mfh5KQ9BPYh3wzX+eQk1eeBR93ubxx+ZZJQ23JXHAQxBEuiTEr+9xagmrMqU7MRYiy2LDuypaKLEubl2ILwL3rbzrxkqr+5AL3M1HEjph8euRvLaihB1Lh0vlNY+gzC+RtBYLOT+F4fHlcE+/anJQq1bxtZHpdMYfq0e2Xnlb6DF6mZarsFkn0Odgbg+m O66EsDIA 4kUojAlRioI0+nOBdpexV7kjeTfINXf9z5d2kPwbV2fwCfOSUAZMUmxxyHofzBL2yDbrTgwjhxI/dp0BvroTWs74EDSuJtxtvEs2vwQULPM6jfME5ls0i66rercJHEeYaOSnBqoGvrepROx7Qks5lvcLPpb5GVxKM6s32fsDD4UCZe0MZ4kHnmlas1xzV9nMq2kB8K8yqMQ46Gl/RdbKtpZLRHioSfHJNZORY2tCf/MG4QmQeSly36rgJ+eBetuRT4jS4MmpkD6EOYkZZ1zM5d5g+ukftdSCvfDviR2BRk1WjF7/pHzxpiuldBvK520smI6e/DqZv/aoWEIs0WACn2h+sV7h5s3iwJM4a 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: Provide a splice_read stub for XFS. This does a stat count and a shutdown check before proceeding. For buffered I/O, it emits a new trace line and locks the inode across the call to filemap_splice_read() and adds to the stats afterwards. Splicing from DAX files either copies the data into a buffer (DIO) or splices from the pagecache. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Darrick J. Wong cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/xfs/xfs_file.c | 33 ++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aede746541f8..bb1ec755a709 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -306,6 +306,37 @@ xfs_file_read_iter( return ret; } +STATIC ssize_t +xfs_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 xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; + ssize_t ret = 0; + + XFS_STATS_INC(mp, xs_read_calls); + + if (xfs_is_shutdown(mp)) + return -EIO; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + trace_xfs_file_splice_read(ip, *ppos, len); + + xfs_ilock(ip, XFS_IOLOCK_SHARED); + ret = filemap_splice_read(in, ppos, pipe, len, flags); + xfs_iunlock(ip, XFS_IOLOCK_SHARED); + if (ret > 0) + XFS_STATS_ADD(mp, xs_read_bytes, ret); + return ret; +} + /* * Common pre-write limit and setup checks. * @@ -1423,7 +1454,7 @@ const struct file_operations xfs_file_operations = { .llseek = xfs_file_llseek, .read_iter = xfs_file_read_iter, .write_iter = xfs_file_write_iter, - .splice_read = generic_file_splice_read, + .splice_read = xfs_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iocb_bio_iopoll, .unlocked_ioctl = xfs_file_ioctl, diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index cd4ca5b1fcb0..4db669203149 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -1445,7 +1445,6 @@ DEFINE_RW_EVENT(xfs_file_direct_write); DEFINE_RW_EVENT(xfs_file_dax_write); DEFINE_RW_EVENT(xfs_reflink_bounce_dio_write); - DECLARE_EVENT_CLASS(xfs_imap_class, TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count, int whichfork, struct xfs_bmbt_irec *irec), @@ -1535,6 +1534,7 @@ DEFINE_SIMPLE_IO_EVENT(xfs_zero_eof); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_unwritten); DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_append); +DEFINE_SIMPLE_IO_EVENT(xfs_file_splice_read); DECLARE_EVENT_CLASS(xfs_itrunc_class, TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), From patchwork Fri May 19 07:40:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247779 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 B07B7C77B7F for ; Fri, 19 May 2023 07:42:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48037900020; Fri, 19 May 2023 03:42:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E336900003; Fri, 19 May 2023 03:42:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D006900020; Fri, 19 May 2023 03:42:32 -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 16D02900003 for ; Fri, 19 May 2023 03:42:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EA6EE1A09BB for ; Fri, 19 May 2023 07:42:31 +0000 (UTC) X-FDA: 80806212102.17.800634B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 39D0CC0009 for ; Fri, 19 May 2023 07:42:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a2d6JkgF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1684482150; 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=pyQng7zN0KcMKuuU4UJQFoNAdqIUtbeSzOIbMt9WEc4=; b=5iO6cjGkP6M6H5b6n4BVUHPPraCFJQNKYVbV7lO97+6wRY9CmO5LmmgMDhLDr99zLC+MgA F4CARajTdSytcv2ibScsWGP88R/NivMSDx/JBM9LloeAFd8qwzGYsAObvDSCoxCsNizzHd DjesmgI7HA2o+lN4f95HNPfK5vEOy44= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a2d6JkgF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1684482150; a=rsa-sha256; cv=none; b=cBygi+0a79RfEXt3XcsT6aPNkZpgw24/6NQ31NWJPFQvvnc4Y6jkL9qv9YCVnLmrt18/3n xQRzi05TStyjaNu8DNLSS9dtozCldxje3A3uUTV5W7sgNeDU0ahD0jC4J1pky/SV7+47x+ 4ISu/liMd3vx8kAK/mRnL5fVFCrMAeI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482149; 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=pyQng7zN0KcMKuuU4UJQFoNAdqIUtbeSzOIbMt9WEc4=; b=a2d6JkgF0Pj+9vX0vDxYRFLU7T2uMJqdWVXQgBxApSMok3vGHQ6nKHflciYrcw+HvavLpU 0HUB1+lK55Jv+bo7uU8jwdO3TbUSL8RDsmQTsoroYPIhS9z1BBqExlpkw9hsMWQpijiJPT NUP/y5AVjxmfbQaoQxc1o75a5Iu5uKA= 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-368-9SkW8NWEPuqdpOcKe74MkQ-1; Fri, 19 May 2023 03:42:16 -0400 X-MC-Unique: 9SkW8NWEPuqdpOcKe74MkQ-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 CAF9738035B0; Fri, 19 May 2023 07:42:15 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id E84F4492B0A; Fri, 19 May 2023 07:42:12 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , "Darrick J . Wong" , linux-xfs@vger.kernel.org Subject: [PATCH v20 22/32] zonefs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:37 +0100 Message-Id: <20230519074047.1739879-23-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: j8oybkiob5amhoc63ahj4gzoqazos8u4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 39D0CC0009 X-HE-Tag: 1684482150-392045 X-HE-Meta: U2FsdGVkX1/PnTIq2NWUYEXCgGYBWlKkYFAoODM60hpeo13/Lz+sYFn2IHSiTveRBWE9rotmduO4xMY156NnID6RyFI2wQOBb6zJ25dI8p6zsS15lmEHjlFmywZsXi0FZubgzDi5+7Zu6ZTW9dSLpFtPBEYZpcevpTT1EMBtP82XPl8j5FLX8hGBVBcmdUDJJCl668Dq7A1rz9PIbkQ0ExPUnXy4yaBjH5yDuh82hroI/JvPMCPOGCOjaMk0JDhXWQ9i7PnyXRYDqi0M80k+ICko0ytYwthRp8fffS18LPfeknjY2qnLi8mifV9IFBjow8ndIv3MsPqHx6hnytKISdkktUXvYLRntgIsaLXMS1g8wL6Bzf41tmcPw2qvFNh+18jvVUUzKqr/eyjfHvpGpj0DHID9RgSn31nv7LeOMgjUvxzLOjxAEy2x/Q9hSJua3iYaCDJAZNY74czAd7Q4ysGuJT4AeHd/M00IyCIw5drFmTnZWadUISk8jCK+rVaKWAfe/IbtSewFVFqUsMfOuBLVD3pqtNJmBQwcNI2fUhnLegTlDPiNY55KQukFd1eziqE2qP7MOxHMxQA0Y9muiZF2EaFxv1Rk7+3BJREAXBrvlXjDIt4IVUzR9ZnW+VPiID7C1XdwwdddmlxAlPXj4D/Okz1KyNu+oUO0LC+tQyLUFH0gsoTwrzymCGVYs2afSYFoOkyqnkW6fa3aJQzKbQGDqm9rDvn0uqq9KgYCIMWjC8OmuYLnvrQ6rD3JvRGML75yZu+El2Otu/o8cPWpuRbE7uNsRqge4lF/E6A8DzGDIKfww0itV/oHQVocWoCMl/IIha4JAXlASJvYTaBf/8NIzoOyQ0Ea0ZGCUwQWq4TQuv8rziUCPviF5YUIXcfUN8pvS6xAXNLpAiHQI+fssFjaVK7JJf2jXnlzz1DZcsSJCTKzj6OGshkKAf0SoFCwwQ8Q0uakNtX8c3DcAtW PCqs7GdS ZMh6pr8HotjWZ6HPw622zVbHUXj1E2Ilw5GkmpLvUG3GqBwsDKxv1C44GqXS+hknxHDtSMIrz9QCqrkYxxn6NJ/U5/ryRYpQzOMf5SnIH1VIYZ25xyxEgRWq1y8lXBvwqdKEiqF9lihMKpNmViE52lFWfxnfMFxzCHgVDX81JGpYMl8QzRFOiv+/n1VUtGHNa9BPRG2ELSg2nShFRwwFYZFS/aipnDbOHIYak6X0SZSElacFJHmv1vhEOSUqX2+24v0rYlF0wCLuuEmCB4OE8H+o8B58C8i5+9WsuDMT1WheeFVvWASyFHc+lLqJ8YeggV4yVYZcyiomMhPegBrNNxdxR5xCmK/u8XptH 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: Provide a splice_read stub for zonefs. This does some checks before proceeding. For buffered I/O, it locks the inode across the call to filemap_splice_read() and does a size check in case of truncation. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Darrick J. Wong cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- fs/zonefs/file.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 132f01d3461f..a8d7bae4910d 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -752,6 +752,47 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t zonefs_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 zonefs_inode_info *zi = ZONEFS_I(inode); + struct zonefs_zone *z = zonefs_inode_zone(inode); + loff_t isize; + ssize_t ret = 0; + + /* Offline zones cannot be read */ + if (unlikely(IS_IMMUTABLE(inode) && !(inode->i_mode & 0777))) + return -EPERM; + + if (*ppos >= z->z_capacity) + return 0; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + inode_lock_shared(inode); + + /* Limit read operations to written data */ + mutex_lock(&zi->i_truncate_mutex); + isize = i_size_read(inode); + if (*ppos >= isize) + len = 0; + else + len = min_t(loff_t, len, isize - *ppos); + mutex_unlock(&zi->i_truncate_mutex); + + if (len > 0) { + ret = filemap_splice_read(in, ppos, pipe, len, flags); + if (ret == -EIO) + zonefs_io_error(inode, false); + } + + inode_unlock_shared(inode); + return ret; +} + /* * Write open accounting is done only for sequential files. */ @@ -896,7 +937,7 @@ const struct file_operations zonefs_file_operations = { .llseek = zonefs_file_llseek, .read_iter = zonefs_file_read_iter, .write_iter = zonefs_file_write_iter, - .splice_read = generic_file_splice_read, + .splice_read = zonefs_file_splice_read, .splice_write = iter_file_splice_write, .iopoll = iocb_bio_iopoll, }; From patchwork Fri May 19 07:40:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247777 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 7D5E7C77B7A for ; Fri, 19 May 2023 07:42:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14A9790001E; Fri, 19 May 2023 03:42:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D562900003; Fri, 19 May 2023 03:42:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB6E190001E; Fri, 19 May 2023 03:42:27 -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 D935A900003 for ; Fri, 19 May 2023 03:42:27 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BB597ADE61 for ; Fri, 19 May 2023 07:42:27 +0000 (UTC) X-FDA: 80806211934.14.96F89B2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id E5F881A0014 for ; Fri, 19 May 2023 07:42:25 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bYPeSm6y; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482146; a=rsa-sha256; cv=none; b=GRBFxUSJFR2kDe/c/wMoq4xlE/E1pNnHdmuzY8SCPhF3esp/MeR9Tqo3CQMeZWvQ8YuQTG ZMX/U36F59Cb9rHFHd5c7wrV+0TPPQVWXHiCGBfNSlbWYfEFQPsx1lDTQlk+38SR5jsksc plN0V4Vw1NBQYbswjJLNIxZ4fmeCadU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bYPeSm6y; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482145; 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=mbYjI1mFg3thAEdOWfyRBtPSF9SFp7VqzA4DBX9XOaM=; b=lnrVbbh/c2+oYWc8/7VqVNfMcNM7j+mb5N6UueR1Kt6xpV52Jt0zxR6yyXugGWmoyTP0d5 PAR3WOCEwlxjZHMNjyF7ybIQfzE3ktlFmNGkJfZ3BQlmEq666JdBHgeYx9v4v0A1BFqdOb WpK+XYpMohWEmi0UxAZGl/meO75+PbA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482145; 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=mbYjI1mFg3thAEdOWfyRBtPSF9SFp7VqzA4DBX9XOaM=; b=bYPeSm6yGvTCA6pQmfGKyHlMB3X3SVeeOm5r6FLHdfZ4/IkRRv1oM/NmJ5CJjVKp7KyBc7 6pLOi9JOSR+sMVfmvSEL2CCfw01QNB7+H/Kj3gTAqNjCrO7uXsldEXwv5CjJnM9YkDhBO2 SpDWXf3B2QJ/v5BQ+Uqgyo3wcKSj28E= 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-633-8jk5gKwVNnagZwC444Xzmg-1; Fri, 19 May 2023 03:42:19 -0400 X-MC-Unique: 8jk5gKwVNnagZwC444Xzmg-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 DF47D800C81; Fri, 19 May 2023 07:42:18 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 759107AE4; Fri, 19 May 2023 07:42: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 , Steven Rostedt , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Subject: [PATCH v20 23/32] splice: Convert trace/seq to use direct_splice_read() Date: Fri, 19 May 2023 08:40:38 +0100 Message-Id: <20230519074047.1739879-24-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E5F881A0014 X-Stat-Signature: wjbjeynyinidg7nc7m6wtaydezwwfsqd X-Rspam-User: X-HE-Tag: 1684482145-461921 X-HE-Meta: U2FsdGVkX19vyScXAteqdzR9jNY91k+q7mN7WUgqFbwUaDxVXtWsiqFPO1ylSVE0KDIG4z8KwJa8qYDH8WbP0pvwqtZ/ww9G4zk8qi54l5Jug74TP5c2J7SR87GQvjrI2eFBF1f94Mjd7kOpIH5/RhjohfQRz7Pp9t6t6KA8kqmyCFkBL6Bi+tuoquExKdJIc6daPyGzDvqkz04APZ53dSfaZkp6uFQbuoEPRU0isDYVwEzlen9A/KXuHcTtJN3sqap9jZYL4x7TKHGHQvclfR0ViloUhCLjhZ188Ctzp7RGtSTA7qJdlvKOizFghyjPnKqOltRzqvxnhC1uJ1JrfZLuSmY5pxyIrDzwWxrrjDUhgNMvcDCbY3QBhueT4i4XwHcpDPmgJy98A2scMx3yxlYY0hryLSj+E5/b1Pu53p5b9tClWOceW/6JuPtTNRf96G/JqZR5uUFB7RA32e8wemq766ksOpE+yQ2XcpIlbXELJL/DHrSeTbA5nVfqpo75YGkYa46A2OMvuiqNhJAbDtY6waQrgMbjpOqQYMp8uIp5XfFDmyVgszCUi6L8bExzd8SkE9drk8Wc/x0K6yCe99x8e91Qnqa1cUfGi0f/RPF34gveyTnyt0wqtw3UD3NkdvfN9xgVDbeBY6ZP4yCTJva193K2QGfn7VAh5U/OhM0S3Q0WTQYtySk6AudevnaUqcsXnCTC3YaUQfUh6z9bXxcGxvNMGRxcbX+uwEOyBUXW8YAVC0YfexXL3/fzpa4nismhkLhiy48bXn0hzOmrv0+Sq87PwdFt326jmbW8oesH9rdeCd8pnT50Y+0nC/3g2sRxXxmPiiECcb+05vtIj7jKrycBu5WdQF2idVidX2zHQNqt5HoAPUnrHiAgihSbNyzP9l4t91j0ORZ+7OtdssxvXp64LficaN9RL/oqgF63bi3q1DEgUzMljS/GePGo55F6gsQyM7ensByAmcH RCxevDx5 EkqDZM903eoGGibqBSnFropY2jitTmxbMAnymCWGFEWEVS4SlNspSVI4If2cVfVZtjbngGdjuxJeUEjOv6bNx4pX/mRkdcHKCpnkoVlWgghxtSuBgurCkumB6WHfO07IIni+dSMIcRnEPr3G8KLdywFA+G2yNgWPpN4WwrSXzMxo+SSEiaNuyxUSGBa+ogMRjeRQTjDm5dKQ9X4YpTaK4SXPIz6fqOAaUv2iPtABMy8Sog4LW2NCKBungXSOgzxnyR1PiRD2Gn4z4QZJaFkNjnhnXALg6zjLxJYF5Bu08/fvL2oK156wWlBQQHqr09SbqqrJgLgB4LWz7CU33GMTzIV3vHNhq7LFZUI6m+MgLA0s7iBlbUtriVWzrp0l5azBcWEUZbL1IHEwoTBtbTMqz82Tr/6z0j39a5nQW2G9Kgyct8JtnNJXIOahW8tJty1WWIqdny2PuSJTdKgE= 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: For the splice from the trace seq buffer, just use direct_splice_read(). In the future, something better can probably be done by gifting pages from seq->buf into the pipe, but that would require changing seq->buf into a vmap over an array of pages. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Steven Rostedt cc: Masami Hiramatsu cc: linux-kernel@vger.kernel.org cc: linux-trace-kernel@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org Acked-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index ebc59781456a..b664020efcb7 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5171,7 +5171,7 @@ static const struct file_operations tracing_fops = { .open = tracing_open, .read = seq_read, .read_iter = seq_read_iter, - .splice_read = generic_file_splice_read, + .splice_read = direct_splice_read, .write = tracing_write_stub, .llseek = tracing_lseek, .release = tracing_release, From patchwork Fri May 19 07:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247778 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 3C207C77B7A for ; Fri, 19 May 2023 07:42:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C95A290001F; Fri, 19 May 2023 03:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C463B900003; Fri, 19 May 2023 03:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0E8290001F; Fri, 19 May 2023 03:42:30 -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 9ED19900003 for ; Fri, 19 May 2023 03:42:30 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7569E409CF for ; Fri, 19 May 2023 07:42:30 +0000 (UTC) X-FDA: 80806212060.25.468E167 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id B09A2160016 for ; Fri, 19 May 2023 07:42:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ImHqwYuC; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482148; a=rsa-sha256; cv=none; b=f5foa3udcfa0Ydx5t7KpX3IfG2WJ136ItgdsJpFMUS7FBxVcyupD6+QAOMClAz/qp2pjZR JnFGiYA+3Br40U5IXbYLaiSB8njs3u3CGTDnHdkPB5wE7q7s9ROKhIFEOwrB2hGecc5JqN rdL3giDtvBuRbqq5OxMF4FjTb2HmsbI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ImHqwYuC; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482148; 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=KIPsbdoO43iq3tUvemirM6xG5g+su+9PgNJxpKHBcQ0=; b=taybhhOB26zgiswb2qcowbFHo4d1/N0uXnp+lMEROTmDi2aiWpg4M9EtNYdqiQIPENdXZv 0Sn4a1wrhXH8GcBAR2aprOC1+4lBwW52fGik7aQgTynN0AhskKDN76dZqHrbdAu0KqeWLt hDzxzpylZ4dnmm6kHKmnsKnxdYSxoHk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482148; 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=KIPsbdoO43iq3tUvemirM6xG5g+su+9PgNJxpKHBcQ0=; b=ImHqwYuCM6e61440x6M1EklX4wrAKsPqPDIuMT3wI5lpQf3Sy5kmLoYYQyjRk5Ll4iAyhT /dsKiYwzV4anogKQebCTP6vY54QO09vdEPs96SzJ09UzU9X1RDhhjNgMehqOpouWu2TOdL u0KaB8MDI5Tof498BWTgKpl3eGsDsiU= 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-581-aSvtV5ZQOk2ZrLbIVY_T4A-1; Fri, 19 May 2023 03:42:23 -0400 X-MC-Unique: aSvtV5ZQOk2ZrLbIVY_T4A-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 80C8380013A; Fri, 19 May 2023 07:42:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE32492B0A; Fri, 19 May 2023 07:42:20 +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 v20 24/32] splice: Do splice read from a file without using ITER_PIPE Date: Fri, 19 May 2023 08:40:39 +0100 Message-Id: <20230519074047.1739879-25-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B09A2160016 X-Stat-Signature: bm64t1rnnagyhyqxh6xz7iwc8o1xn5o9 X-Rspam-User: X-HE-Tag: 1684482148-913325 X-HE-Meta: U2FsdGVkX19aQEdG2VkSiPZ7/ZfeluD0NHP9xx2+oR0P5WWcyzkCtd7ndUehZbPAc6JM34lafFmd+TcPlUMfKx3l5mkqndAlbAQHcEEfMKRz7s2WhAn3NM6y4izicsB7zJxZpKaS602XjK9jT3slxY6a3t3rbwGzwWkpTpV1hgG91bfebqVMzfXVsjXZ8PqGk1PESEtBH2JDehZ9ahpRuj3lQNPjD9rPB6ykngTU3ulWClKLjOgp79VSc7T+wcOmgUGCV08uP1mzCZ2OWz0m2CuXUathhbhHw1neZatEoR8FJPuBUUT/dQCTHDU+fKnRwBWxrnGbV5YPD7JnWTTMmevrvCqlnQhMJ47qI6iTOUgSJuyUWG+MTdmwDDXtNN9vRXAZsxgppT1F6W5WSgJRvS/H26krM6wY6IAagI4mIirCo1w5c5SIEshz3RHmP57WP508MnX7LN1PqDP8zpyqHqUsbayAuipldiEQtuTffNIDiNqtJMyd+iSMo7zsC2guDSsJfAjULcjwuC1p+Lq+D75BpQlup0mVN6g45hofEP/Ob8niTGitqAUS8RADfJMracB3UyUSJ+Ro2Kjn6KLSNWHmmPClNTuiBgmINMfEoyo79tTu4gPy84H6wVVOQPCdJnDGJTJIC2PzYmnByREwNYPDiClkmiFVV8sgUkSLRWYE8tMYtp4jcC8YpTcOuEoCe1em8NGdfiodIfHxm7a1ytZfmz8gkIUk2mL3P9PSIfhg3sBYPBIuIOtVsaXCUCXx/2TAygltvSUbCb/5oobZoHzvf42yKoYtUffEUPwqLpVv9ENBzY2G+t9MRil9Zcyn30pwA0TRkYLyYWwQgpN/IoNCKhmhcbe+oavA45BTun0xUqacd80IeIEib3t+R0r9w/MX2ZU5xI5faIn/DvdQxp+WEn5nawhFl+DpRwFD+BpGgSHpi/3z0i9I/UWEvVQgAMyeKcHjlXzVLx2LinX Idp+B+PN 8hmlRSMp/8szi/Uh1fniiYtJRSg7QFbFOtT5jq4J77dfeB45sSusChxkMoH9FyjgBlmu6kjHDzWuDOB/gsO5z0OlhOa1nIRR3K4ZCiL0mpI9r5HspLlaRKE2OUhB8FNOLjMuLE+PAw/bUysVRr6ceM6+HOMid7Oux/dZOIrUoZ9RyGYj90QiqF/3+UPfAFskRSXRKysidH4cHXT1pewdEXEvSbG/U2SZQFUnmpA1m07e750QuERrwpgkVAGZ8Qp8yDhfrFVNuYeK8Ke5/6IMBKgDDw6Xh3hlKvj0yOF8H28k49r7RhDW5xXXxZYTuvT94xfwLB4Gx04rTR8lB+fY5fCNhK1buGBhAsdVN+ef/DvUSACwssksPg4GRpm2G38ZjwwcrlZR+lfNew0SGmICL7UOlOBn14ZoPe4ninbgcw8F2/cOYX3JBgN+tiEDYUL/v/uMJNjZs3ZL0sGfzUx4eE4ObgnZmhZ5C5I2jXlY2lskh6lw6l0hohljf5AKus7DOnVf4 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 #20) - Use s_maxbytes from the backing store (in->f_mapping), not the front inode (especially for a blockdev). 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 | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 7b818b5b18d4..56d9802729d0 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -417,34 +417,17 @@ 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; - + if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes)) + return 0; + if (unlikely(!len)) + return 0; #ifdef CONFIG_FS_DAX if (IS_DAX(in->f_mapping->host)) return direct_splice_read(in, ppos, pipe, len, flags); #endif - - 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 ((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 Fri May 19 07:40:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247780 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 32F2EC7EE2D for ; Fri, 19 May 2023 07:42:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C22BD900021; Fri, 19 May 2023 03:42:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAAD2900003; Fri, 19 May 2023 03:42:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4997900021; Fri, 19 May 2023 03:42:34 -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 913CB900003 for ; Fri, 19 May 2023 03:42:34 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6C2D2409CA for ; Fri, 19 May 2023 07:42:34 +0000 (UTC) X-FDA: 80806212228.29.1B6FD15 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id B67771A0014 for ; Fri, 19 May 2023 07:42:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ijTF70p8; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482151; 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=g1kSgt8JtA0JiFV4X1i6k/i3VuOpNNHzBh5elSR8Nt8=; b=EDwGi4rANtYSMuHMBBWtzVt2lZ2hNLYB4YgMHzWKLocBbd7MMSVREPjKnpiPDsIZGHqx4/ eU1/lQxOY9zNUsqnA/osf/OEiCIJBVYWe3IHhony1JTAW3636ezMWBXS3iSTp8QX1DPvjx PUKtGcbjS9ZwpLTOtn9y2GNB4a5/Nkk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482151; a=rsa-sha256; cv=none; b=GDyL9NvpBgltnpTwsPHiyQJ7R0lECPlKhcxRKiGoOf57RmsrFnKBuU4NJnRGhR35NRlATO XDWlRaaMOosjz3jmrScxdLaef/qYaTgpsfLElXjw4bDyYfAefe9FngyDOKJ/WP/ms/0lmO GAFTCRUj9iRJSVXJyyCQJelMRo9UDUY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ijTF70p8; spf=pass (imf19.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482151; 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=g1kSgt8JtA0JiFV4X1i6k/i3VuOpNNHzBh5elSR8Nt8=; b=ijTF70p85j7rirTh/SBjTp6GYNtEhFIBQGVLBrKeTonACIQ/y8sXhWsdtjOT/3qYQePq7/ DjLMcM4L7r8mtsrl/P/3fqO4dSxYS1isKeVJsaOJNytRJcpvAD9Zhk37VcV8zLhYmj/b6E WfYUwTeh+1qWDQYXnLcMhxcZVZaSROY= 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-189-_2ymUi_4PoOAUMbTHfhg_A-1; Fri, 19 May 2023 03:42:27 -0400 X-MC-Unique: _2ymUi_4PoOAUMbTHfhg_A-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 AAB49101A55C; Fri, 19 May 2023 07:42:26 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D994C0004B; Fri, 19 May 2023 07:42:23 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Paulo Alcantara , Steve French , John Hubbard , linux-cifs@vger.kernel.org Subject: [PATCH v20 25/32] cifs: Use generic_file_splice_read() Date: Fri, 19 May 2023 08:40:40 +0100 Message-Id: <20230519074047.1739879-26-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: B67771A0014 X-Rspam-User: X-Stat-Signature: uaz5kucnerwnyerb6i9c7mq36dy8hy95 X-Rspamd-Server: rspam03 X-HE-Tag: 1684482151-218986 X-HE-Meta: U2FsdGVkX1/7gWCuuX4qKo9OIQ9cXHdDtqnmEOkO68GCWadkabpgfbVhf09Kq6ZsyZc0eIAEO4QSJNl9eGfcAmd2nRIea+o+j+Ly4K2FsZ3KaGZtH5XrOfaQUFcoFRcNTg1XWC3/cbnoCHRXrwJr6vpPgblyxyhn4M/adoH4UC1oQEu1kSnohrV9SVLnNir/hEVWvv0lKzoXLVZdWZ4jtaBBmou8uB9wxZCNixUzKIiaPkEDULs29cVDsTiUaqv+LAbc6jJhE0wWeNYGoKlN7FMQBisgOrebrhmPecVXGY0YDKfYBGTBWStlVkSqkFulZxqqblMjiuLCO/thpclTiHwbttyuPyoiSOHVyKhJwsJZ85WEomG+fGvBqAZe8kNHhe/cpMSt4IGFHb+M27KPqlynTNN4wntcbVHEobDcu8xnu/tPuD4a020Hmm/CkbAUHLnlkOSqRYX2dbHGupnBUtL/86Bdcd/wZ4o1eMulUzE3XB4hdykmyoONPA+fDmdJ89EfFe8oDKoudCUfeB4fJd32S7eVtQk1RreCqxNlWYwFJk/4z9m9i+44SlqoG+UCit6fnAULVL++jmMSUsNjHrBnASYUgbrMRk6tA7UGLRD8cIz88dbhCa7oVXuXwOpggw2z6RiRA6hnuXvP7T4xrOh0xfbT3YVqx+Zdy2W6k3ZTZwa/wXxmkpWCV0L95MwA3kIJ8HC92lKxMqdYxaUMCP1OhsG0BJt/7bXzCQegkcOi5zI+6qdXFmeRkrES5Kanm8RNAth1b2tjPD/DyRYFDgCdBH0UQmYLfn9gYsEhg264zEb/V7rj5Tfz+UI6hBc2IBdP4fl78y71ns2yaAWjy56YJWK1fDhRYjiANLu9B4qIRMFNSN0UgmVhPAjaMfrutdcooUzgG5JiMCV56AYeIe01/M/e21lrTYlYKKYBy2RBtKW1F+Vu8vFnUrH2tNZPnIQnVbVc7q07v7FsDmp 4Ag79Ary yyrOYi8fkrtqJMjML0GK9aJBdxnkmc+YbUyAhRt2fTw+IiJpQJWvue2+H5lKurO+vmOhda9BdaP1aV2XuoK+OyYEtwCW9G/ZinDQ8SgCvX2W1PAZDefv0uN6FOENH3mYSSkP6L/usWSJPr1/VkASwLmxOc07Vid4A3DlTerzzeX3aAUCY7Hc0pZ8l53pVv6aj7Zk3/FD2HihBaZvSSGGBhM7ecV3LI+3fBpJ+HEbGPFHz1tG+j6Fvm8CSuMA84uoDNrPREbAYdGsGMh005rznJxLH2y8t5XfS9g91whCDAQmUuWaGnVqC77ZY7COIMHSh6yhpBoJlPpGqQ9qtx5RvHGmZ3VnUq5+eecq/MwRHwugKx//Y84u1bfQV1hyVXIRWBjEDb/5VWlbVbihZ1abNnLOvoelgZEzjSdDhSqbbQvRM6JYh6pj+lCVJQhjjsJpMlqTTAcinTKMHqUeRz0IEutCyQjMOE+n/XHAAxFhLMKHvbQZ3Wkt7QFgAI1O0zI+bdLT5 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. Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: Paulo Alcantara (SUSE) cc: Jens Axboe cc: Steve French cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- Notes: ver #20) - Don't remove the export of filemap_splice_read(). 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 ---------------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 43a4d8603db3..257587a6cade 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1376,7 +1376,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, @@ -1396,7 +1396,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, @@ -1434,7 +1434,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, @@ -1452,7 +1452,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 74cd6fafb33e..d7274eefc666 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 c5fcefdfd797..375a8037a3f3 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -5078,19 +5078,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); -} From patchwork Fri May 19 07:40:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247781 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 EFBEEC77B7A for ; Fri, 19 May 2023 07:42:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89EEF900003; Fri, 19 May 2023 03:42:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E50280001; Fri, 19 May 2023 03:42:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 715FF900022; Fri, 19 May 2023 03:42:37 -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 5969B900003 for ; Fri, 19 May 2023 03:42:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 238B08098C for ; Fri, 19 May 2023 07:42:37 +0000 (UTC) X-FDA: 80806212354.22.0B0AE13 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 68D8120004 for ; Fri, 19 May 2023 07:42:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eFB2WGUr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1684482154; a=rsa-sha256; cv=none; b=mzvDOogbSTc8DaSLtLEPoItzWEcOU6YLemlNaFiTYtp93E3bEQx16VKjM45tBeKz+7gmL9 RBQU0zKZVKQGx1eSWlxgRM4woEtj1wkqKS2D2nvgjMJg9i4BBEt8qs2ZQ4+n2mmm7fJORr tzw7kJxVfmaAsb7e+KzvDlZvKlhUd+c= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eFB2WGUr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1684482154; 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=IZTA75AA4bfNT3x36ufDNmpN8ZwenJYqDvE37aQ1sUs=; b=NwRLclgmKPbjU6NxPJnFeazLablpQQK9u2dDp70sePBcEbdGB+wFFd+4xvmidPLnHogKDT gwS3siZk6YoIFK59gYlSVskjDRjsWfj2NbL6JI7fBQJ2SJSjPiKJ8R6b0R+hk1GOKPGYmE 0fGrlpMsIM9cuGxdYXTBzZN3clGl9iM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482153; 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=IZTA75AA4bfNT3x36ufDNmpN8ZwenJYqDvE37aQ1sUs=; b=eFB2WGUrPoPXNoriOctusQ277EHyOd/dmY6Yp9vMdUi7qVBwBUW4mkEheA9qVEievSNFdZ x1fw9Rt9wgC2ZKMJ2m/jsDpbjnX1ZJ+PyfxuZK7gCdQ7gs5pQvm+Kf8OofK4bMyzY+uTBX 7sf3IQvisbjPyZTjJEkkzrearyMRNQk= 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-88-pnfp-Ae-NcKTG-EYqodLzg-1; Fri, 19 May 2023 03:42:30 -0400 X-MC-Unique: pnfp-Ae-NcKTG-EYqodLzg-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 AB1E638035AD; Fri, 19 May 2023 07:42:29 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6053DC54184; Fri, 19 May 2023 07:42:27 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v20 26/32] iov_iter: Kill ITER_PIPE Date: Fri, 19 May 2023 08:40:41 +0100 Message-Id: <20230519074047.1739879-27-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-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: rspam06 X-Rspamd-Queue-Id: 68D8120004 X-Stat-Signature: dygjeks5ka8n99qjui9qcr6qt4cfbrxn X-HE-Tag: 1684482154-659514 X-HE-Meta: U2FsdGVkX1/yjzuhYigbkdGmXfjTKCCIROLJw9Ddy+346c4gik7IWkIvU/tnao2iFXar6KM3kzsVwcxZE4LJBBOAiNQo+qn6AJXKz795jZ+60W4Kdhlm3WBXNSUwhEaAeoRuz4H3rc07vcPnmZ/J8MKf+v1mEcxOlPoWv6fJ22avM7GQxeC/rShl20bZL8Fk2I/lGkU7vO1qy+72l7BQjg0Vf01w0F0MKcX6ng0uIyt4ALFPfIx1U54aTKUeBESGMFyoiySlNaqcLKB2krgnLcsET0sKTaXYA1g1Ka2S5k52Wx0njET324u6oJk32j+qWYcu4E+E0npwPbgNrUuQHpL2IbOMeBNjBhLI42CmQ2Iy7lcDp8X4Pq3sA0BUX3frU4NLBd0FlcvzLgyMXEvJalA9NS7Q2aecv32G6rH9pMH7YpV2cUcnxqcEgR5l6p2H9TJphjjIrsac3fFuExN6uFnaddMQLF5bn5z7FatzvCedpnZT4I/3rAcKPmPEQKbzOADMkB9kWcFV61IYlaNlf8khpmvpG33DHONjNdcsfbejhH879MIiycMwfKyCGcO90rnqgg2wOq+5QjBdguWSyVqX6lb7cx+M0bpxwmxSERMqcuMH/x3APSvW/iR6k++19oZjzPCx7GPSx9P58NvdxUyumuBYk3FDaWTgVoqi+gH6O1s66R3+mtaXXO7XCNcaEtUh9fKx5OGFo7JxqCt6OU4JAy/7p0XuA8V7gAoqhD+QlNpmABowJTN/zCZ/7uHQNKOjYzCHMy0ac1CAuI1Ac6f60UIymFSFhYP2HEN/b6mWGmQPzVZekA6UCBsZtahzS3ZCRtpUCb+WZYFNfU+j7MV2DtXfRmWatqFn548Q9gx6Au5lk6Hy+ypl9zMBEPampJrDW7gF2w6Eu/jsnHLN5NH6Kk0DM85R0/DyeilFl6JDgeEQgSfr0u3BzyZacoYfifiUC9JC72cIF3ULl1x fo7DlESf DYDl1Cu0FSUBLAPcnv67k3pD5i45JLXyTtaJY7i7Vtd+TAgaSX1kHQzdpdUu8O+/Y2p/gEkYstB73EzwFBKmR2H6Uuyobr9hnn4tiUzTr+pRIylzHlSflXn8eKAKQnAPqMJBBkkWrajDqMfbdRd3szZOBGKTTTcI1X+ojn1e/734WDlN3mv2UaOOaCU1zJkUIY0iXZ7G2ymuXwWJNMpZge6XFujlddZJ2fkrxB3H6+2G4eI07WucJKRpSjse+po16bK+BNl9z05lMI/lihAM7pTG7bYot/LVIfzydWt5woiIZoVt8n2GSUV0ujYBS6zVeyGiBSkJLc/Up5CbpEYb0/jiGw6B49jNwrsyY9N+6ecYmI53jb1/H0REh7IAaWvCIjG65I1SdLrexrhgcCMAHYH6WLmW10H1MAedFYSOYfO9p7Wo= 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 --- Notes: ver #20) - Rebase and remove additional pipe reference. include/linux/uio.h | 14 -- lib/iov_iter.c | 431 +------------------------------------------- mm/filemap.c | 3 +- 3 files changed, 4 insertions(+), 444 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 044c1d8c230c..60c342bb7ab8 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, @@ -74,7 +72,6 @@ struct iov_iter { const struct kvec *kvec; const struct bio_vec *bvec; struct xarray *xarray; - struct pipe_inode_info *pipe; void __user *ubuf; }; size_t count; @@ -82,10 +79,6 @@ struct iov_iter { }; union { unsigned long nr_segs; - struct { - unsigned int head; - unsigned int start_head; - }; loff_t xarray_start; }; }; @@ -133,11 +126,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; @@ -286,8 +274,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 960223ed9199..f18138e0292a 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; \ @@ -198,150 +196,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 @@ -446,46 +300,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) { @@ -493,44 +307,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, @@ -552,42 +332,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 @@ -607,9 +351,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) */ @@ -617,8 +360,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, @@ -732,8 +473,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) { @@ -764,8 +503,6 @@ size_t copy_page_to_iter_nofault(struct page *page, unsigned offset, size_t byte 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) { @@ -818,36 +555,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) @@ -878,32 +587,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; @@ -955,8 +638,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; } @@ -970,26 +651,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) { @@ -1079,24 +740,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. @@ -1224,19 +867,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; @@ -1307,14 +937,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; @@ -1367,36 +989,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) { @@ -1547,8 +1139,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; @@ -1638,9 +1228,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; @@ -1725,15 +1313,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); @@ -1746,10 +1325,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 a2006936a6ae..394db0c1f197 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2687,8 +2687,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 Fri May 19 07:40:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247782 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 D164DC77B7F for ; Fri, 19 May 2023 07:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F048280002; Fri, 19 May 2023 03:42:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A0AC280001; Fri, 19 May 2023 03:42:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5199F280002; Fri, 19 May 2023 03:42:41 -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 3EC03280001 for ; Fri, 19 May 2023 03:42:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1DD281C6FAE for ; Fri, 19 May 2023 07:42:41 +0000 (UTC) X-FDA: 80806212522.21.0165F37 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 78641140012 for ; Fri, 19 May 2023 07:42:39 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NQG0AUXj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684482159; 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=oZIY9GTPXEPoSMZhe+ryqBhZXmHTyjPJq3hYdlaANCY=; b=bVHRSn78bv2WLH1N/JcHu+lyUuHEuJocIR8qr67QTuPzCuny6PjBt5qoVKBkuIesyUpRWQ FmanADE+VQrExKKrcpZNyoGz3sujBs3ofu+ICYZ9cUgpgB7NiTNIxkwXxIN4Qv5ASHgFHh 5bvFItKvbEeK+ZcctKJ5FpcNExLfDMQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NQG0AUXj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684482159; a=rsa-sha256; cv=none; b=Uysyrqqr1g+xhdT4/3tYf1LfqOEu0pweJ3KLYbaY3c20Bwlka4SUt7fonnH4dGsNqYEVVc X/bZyjnILqyGP1r5+AMdj3c0307+ZxxoQ2je9s6P+pyMq+EWgCGi+lUQmIpRT1dVKh8vcn bAuN4S0tBLLgheh/o4FdOIv/r5ZLnj4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482158; 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=oZIY9GTPXEPoSMZhe+ryqBhZXmHTyjPJq3hYdlaANCY=; b=NQG0AUXjacrQIoHcSmZtkMjpL1A3xLx5PfM0aZuG8vflZzB8GW1hXtv10Poft2H8sOCigC NZNDFyi4zhQKwfPUeAY3Hthl1MfXsHOhUWyTOlx1Nz88w68w04p2cKAJ1tddoaNt2U0cXU b2wUPnWGFBz/31j4Kwua4w50I4ndw1o= 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-218-S_Amoo1cMROA4t9BdXJr9g-1; Fri, 19 May 2023 03:42:33 -0400 X-MC-Unique: S_Amoo1cMROA4t9BdXJr9g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E12685A5AA; Fri, 19 May 2023 07:42:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 503291121314; Fri, 19 May 2023 07:42:30 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, John Hubbard , Dave Chinner , Christoph Hellwig Subject: [PATCH v20 27/32] iomap: Don't get an reference on ZERO_PAGE for direct I/O block zeroing Date: Fri, 19 May 2023 08:40:42 +0100 Message-Id: <20230519074047.1739879-28-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 78641140012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ma749mrubfbgb6ucx1edq156i4m3rrab X-HE-Tag: 1684482159-721062 X-HE-Meta: U2FsdGVkX19be/5OYoNLyK6jp12hxVONLgNhrWJy1nyqIuebXEEz+MblZDO2fDhKaFNNHFHBsWFOuxrHdLjc0IF7XyoxwNnfqfNyg2/M+vqP171m0gJ42YSiL285z+3eNnVGMdS6KYOtKwjtpgUB+UlyGUFKYWdoN1cfLH4DhwLIziYIVFRm9fGHyQmOacw57vdu6BSjaDPVSlRfOim5P2Rh8idcA/wfHcRU0GWc7QAmLS0LF7yhYgHoVyRfrXYjd/k2CD2Zg+hBzrbmtvB2iha59gQKAbQ2RYIuvB07TcJyzI23VNz6AhhiTTcAs8Kvqm0Qs4nDAHBt6+EWyzIM1pjQAC4WX8LhkUYTIKvIUcwaz+Fe9YZw6oUmvL9QNbUQrkDkO6iaPZKO8Bj8VoUijf261ZeG855AldhId4x5Fcy0tdZV/91fibwdi43ijhyQiiSc+9WA3wuIU8SPsN87d5GtaHnNotWLDO2AnOX41m6DwNeNeNZtZgDt+2xLJrjXY0JC/a3HYXsa8QbMARkVdna4rrFmgvG+sk1JfGPST9/xYvh6Ih+vYkOwutaTLC+NxO+encwxrUQFaBLO62SxFeaTd/d7H/9fw6oJ0uX7THshm3bF7RPDXi7RsJAN+N/bjY2LWh6jXEZVAGjr6k4PwYmZKI1men3PBDxnTjYH19V4ad8ik4Ad0oVCMNGvOUitXlAYGnQxGeYVMEGRuk2q37uQxFMz5zQyuoqvpKUy9pM16l22n79Yh2R1StzSQ9mEzpU+38jWYgJV2An2U3HZ7j9uj9j6156YQglZAxXa5F17YEYf/mmymkuMJBMiT5sLJpVZpTT21lcmlkcmF+X9gReSaTSfU321sHAtFe4pDa3a1aHuwCfNqfhIhnC417ycOk1bAfnUq8ZuICBZSY3NmTB3nHS9C1aGBnhiabInmP7C/pafBPf6ASOGw4NUwc3Wd0S4jDwkkmoz9pHhlip XeYT5Kr0 k3cnapHnQ826VgoOS4bqUUuUeTBdsEWmayfSq4Ur4+uGgZFKBtKA17mJMP2k4nYQgYziiudldltY4zKjZRRJ3MUTkNmIo5WbkoMj7aDfui3ind9X3BNCke/atbFT1b3wftCz/TLtok3x9AeSkLDhCEbdBVEOuLc1CXAeV+l+iwTyGD3mw1hk7I6P7J1/rshXEHRmm9C1t30MnWWyFFdaAumCgtXgRzbxDDx6l1lgE5OZp0VAcGlkKuObGMQ1r1CHssr/T+8oXZa8AR2+QWBr/eKjXSEXtaJBYVa3G5f7dWFeVcuHReWkGty98nwpEbL1xzVJ1OQgdW78uUif8CGayPPV0ln2RRjcAWaPgaH0fAK0/+0Fb/g8QrIj439BgLlnC1Hf9 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 019cc87d0fb3..66a9f10e3207 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -203,7 +203,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 Fri May 19 07:40: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: 13247783 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 27346C77B7A for ; Fri, 19 May 2023 07:42:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0EFF280003; Fri, 19 May 2023 03:42:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A744C280001; Fri, 19 May 2023 03:42:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82747280003; Fri, 19 May 2023 03:42:42 -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 70A29280001 for ; Fri, 19 May 2023 03:42:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5339880991 for ; Fri, 19 May 2023 07:42:42 +0000 (UTC) X-FDA: 80806212564.14.15575C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 8E20518000F for ; Fri, 19 May 2023 07:42:40 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gdaDYS6F; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482160; 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=edStQDA/gh3f03KMzWRlpjb2e/gxKf5/7u3ht9bl6/4=; b=Wp0yKMaKZggAfT0fZmDr8Ish0sOPANaN8dM2VXsS1Wy9JWKQsfhyRmXDdTP2jMsEh1vevB acBp9ipXi2g73t0WMIxY2LaWxEDoj7p91x49ncF1jo/q4H2uamyLn+mBZy5HJDNHWlVTbE XIp4An/3vh4yfAAudHz4X+dErCvVDC8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gdaDYS6F; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482160; a=rsa-sha256; cv=none; b=3cd+WMWdfWBVPjM8fyVZiedqDA8Cy1Zqtcqcc2Edo5Ja5XgzJ+FBhjsv7DEoG5TgNhtKeI x44lwIaRrPsWl/CvGD0eEy3NEXho5h82kD+CTTPCkZKDD5tD/8iKxzeq789uXN9wDi+9Fi n/mbBqPp1Vq8CaAoiUbBdI+a0U/7IjQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482159; 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=edStQDA/gh3f03KMzWRlpjb2e/gxKf5/7u3ht9bl6/4=; b=gdaDYS6FFkw6F3YB4HIVdAp/+jefoPf8tqBAHV/C8htfAr9q5M+KM6bKv0co2bIWb7pbLI upNJ8chTvAjZKFqp0SWDbXFTfVQmhP/QypT9rkGwLs8/0dyV2CJfPNe8WeSo/M6p6/tehb kXt5bnM8W0zhbFfyqncLr/OQtwJi/vg= 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-558-Zn02uDUqNWychxCT98RFHQ-1; Fri, 19 May 2023 03:42:36 -0400 X-MC-Unique: Zn02uDUqNWychxCT98RFHQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 654BA101A531; Fri, 19 May 2023 07:42:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 468A240CFD46; Fri, 19 May 2023 07:42:33 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v20 28/32] block: Fix bio_flagged() so that gcc can better optimise it Date: Fri, 19 May 2023 08:40:43 +0100 Message-Id: <20230519074047.1739879-29-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspam-User: X-Stat-Signature: jijr4wcfgd5iz4ip3j8e3zr54tnsbiug X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8E20518000F X-HE-Tag: 1684482160-698889 X-HE-Meta: U2FsdGVkX18kugZyfnof2d5YiVCNv53XR4ofkAvKaCDoyHUKIebd0jpJNK2fZEqtDqp8ruyYm4cOKnCoIsgJqw+A5rBPE83HtjUDLbuk4h36Mc6X15F7EMe52/WTEvg9jtpIyiskOoWh6Y3dX4bkat18w3KOo7qNo2DWCcqfahkNqZGmdtlUqNVfkS1z2qLrDPNa/lNpKFVSb/C+XNug0GXpbcL2KCN09SQYnpRRmSWdkQ9FqHYw1mSM8HJJv2O8XAeSKqvBi31s0qy984QS2eXG5buokoV/Ow+SjjD5iVdm172cX8Y8kZc9eEtbBlK0xxz44pZDum6mfK/qzF6OEgnZ4ZNkqIfdJUts8v48IHsuD0YSYaBRY/UKfesFcLV6y2xYR04gdb0zZDpm3ROc599bF2LeE0buVxWnOBpGsVCMesriX+X0L7c0QkAQfmzcyDpvCKhqLbGGUecG8lQTXDgrqYVfyIqCZ1dl6DH9/aGwTzCbcP8ZKEOVHe1NIP7biwzDdAy9OevIy5zQPQDVVdSWAVTJM3h0RrelcG+1S5PEM7HaLjLtS92pMVcu0YQdn4Kxc/H/6AH3bTLkqUICyVwL/0gMuo0QLLDey/L/DEuuPJ+R+0FrglHfb+v2ugcV0Tnj6uKp75CYd6Ei5K8D3DTtEQQ0pWIk/KQE0BzsszwbvKN8cBHccx0LbTzEFHuLaazqxsMDyoGGpoLZBJYSuKWQHtePjT3jWnNY8Fis3iKt3fvv77DnNQ3a/Rv7wgXY4Gxl4HlGBi5t5O47flc7u6hC+uQpKVBUtWBORQE4bF3VckvjjxX84QWlqnvYT8SAbrO3zZ6he6l39c+PgfjB3cLZ+4fK3LiUwPA6HzLiSqp35vhcxnbSgBo61buLNc4XIRm8i1nM3MXTKQkcdCSW7Rc2zuCJRMiPBlDTriI8jKq78hpj3tedYj9bCbpdHBlhehy3MoJq+5TqunDPnRp mt4gSv5/ kmWrNIjvJGdo/dIoidgDjjCDA/m0euadKLWUuQRYYEG/HGL+qP3KHFiZ9K53rJAAEQqhPeL+Nw7nceS71XWqOXqnQpDOXLSyBXeulrVzMjIDlDHciVPn41OnBiz6Qx9GWf/iEwrEpvun+F+k+A50RfRWEVmdwH90bOJCqJJhmIekkFe+iPPWeDx4KNM6FO+rwt4vxPR60N0ezhlMl3dsb2e5bGgHzc82EBHAfBcbR4fZIcnR260J9dAm3/dk3GFPJxFyU3kLF2Cka5aQV7LMfl0V6ovLoixxgBNGRK3wKuDjVEYHS1pOxyMnI5bb3aimc7q6cYLY4t2pdP1pd7QJAJq89OcqCB+8L84GkWvZYRcMcg/4ik/498zfEbrKIx2HFdCOIiHHRK8fs40KyVRNSg2iockXvUW02+1CNZWw1SjY6oHIZnt+7X93JwFsmc/8+XeJ0xeh5gUXcyfOGfGh1duM55w== 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 b3e7529ff55e..7f53be035cf0 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 Fri May 19 07:40: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: 13247784 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 84352C7EE2C for ; Fri, 19 May 2023 07:42:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CE49280004; Fri, 19 May 2023 03:42:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 568B9280001; Fri, 19 May 2023 03:42:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BC8D280004; Fri, 19 May 2023 03:42:43 -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 21417280001 for ; Fri, 19 May 2023 03:42:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F06CAAE209 for ; Fri, 19 May 2023 07:42:42 +0000 (UTC) X-FDA: 80806212564.09.17C907E 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 3C61E140018 for ; Fri, 19 May 2023 07:42:41 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OroUoxew; 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=1684482161; 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=TuE+HSvYodh9xYXD2lD0nf71BaZqaWOFZeqfoTjFcWg=; b=JUYTC+cpfv3KTiGLbT1+vM//1eR54mk75uEM/tGckQSCb52WDefJ7bNdqWCnk2EWoNn/6n Mf2jrW1QGxPqaMpMCNxc3yWyPi7XSGCr1ug8jdN6BpYKuTGKqVJi+xdo0/WJQUR/XYPmg+ 8DfWuXWVaDSup9tKJMYmIrNhIOcv+Yo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482161; a=rsa-sha256; cv=none; b=gdvv8KBrASSc5Jty00BSIB+jMvOKb2JXz/qs85GjumYk0b1X4qGn1PMQpUagvTna0RVxt4 Dnh59C/lyK0WSgMybrco8+zAFA3hIsg5ksvSL7uzTOa6u/xD3hC2yswGkcEAiuejv+pj3n 85D65IsgdLuDKXnLnAst2GV29/hHTmI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OroUoxew; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482160; 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=TuE+HSvYodh9xYXD2lD0nf71BaZqaWOFZeqfoTjFcWg=; b=OroUoxewgvmFpGb1wDCNW5cx0/FJmkaOO3BAaLvpv3dbh5Mi04ZBQFHWZKDr00gCn+rLPW wBz1f3Bi9+Dl9bcRTpjyrIcziZpT1jLaHSrsG5vRLl/netq62LLfnedVSvusvuaYULMWv4 jbPRjSLDqzs1U/gggb6YTYGxacRZ08g= 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-536-qF_O3km6NpKFWdiM07-vLQ-1; Fri, 19 May 2023 03:42:39 -0400 X-MC-Unique: qF_O3km6NpKFWdiM07-vLQ-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 41BD880027F; Fri, 19 May 2023 07:42:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CB432026D49; Fri, 19 May 2023 07:42:35 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v20 29/32] block: Replace BIO_NO_PAGE_REF with BIO_PAGE_REFFED with inverted logic Date: Fri, 19 May 2023 08:40:44 +0100 Message-Id: <20230519074047.1739879-30-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 3C61E140018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: stdk5irfhb1id3hnzw1gjze4s3td8jpt X-HE-Tag: 1684482161-681373 X-HE-Meta: U2FsdGVkX18JsAIt4NSe8FjtiNv+tgwD7J4VHk+C+p35hG6cwYH0w+550Dd35957FcHYJHkVHzp3oPm573t4Ci3029svcxJpgbODQM4qM/W7fcC4a/lQwg1NoHccKPzlh4R+C8B/BxcckTz0PeIvgp6TPkMZgB50xOaAbNgoDYIz5AqRnI4nWLrBv+EPXjtrKC36NSIB7mbiHDLTopyWHKTfWPTeOSK5UK86/mgyGY9unNDT+D1pOagE8wZ9sz0tGFGEDi+gN1FyJ4IkmaWD95eGm/i7ZU2oN7wCmYmYCWdRSj1KYWwpFnt5+XeWeWrjfcDrAo4e1TbJ39kWPbKtz8UhOFTbEiyoWaZ8yJjPczw+WLZQjokgPa1ndEf9jWbPzapWgJXQ3rN8PRbC/3+L9NJD6Nbs6g/0zTqJ4t9RG0A4yAYORr44TrAi1PoN+9t4TrSYyCii6s3Qz3+4niCnhkW2IHu8VcB3Y4WW8huoFgrTBEbguW0IOwJdE1ybB6pL9AIHECh7hmNwHvYB5+NVBfERxhJoOPlxQRBuWFG25MaZ+BUQCrFPGeHS19yRXQXO60YX/CNHM1J8R86oSrHjDJyJ0c/e4yCe3llczRh26GASM6eVOgWXzRtMXH6W/NeCRUjC5AcE6Y5UPlgn434P95DxEjwxMvOJzn6FzkEmEw7NFX2b6fg7jCyZ4jBgzcyoVqNxf0sgbz/ejlBgKjXGWt77/Mj279Nv/D1SY/n7pO0+Jqn0fBEFuHPTbBzlEZeyrLNGofRPW9IMKUnx0A4vsorx9B6Px5t79sRXA3g7h1KfQuJb1fXstSS0mjVxL1Sh6/uqkx5vUDdXWKfhy3EFzqJymzimo8mGE2j/AqLrRuQT7QX35joLYKx4yHRpkRq921G8eTKNrtNWVRFQzgS81xzZa0nj1Yy5doh08eeKdFDiomImLZatEKIASKUm7q3mdQxa8hfzxL77+cG6C4o 2tfAklsK ZmvTTI91NUhnJhF+9WH9YccyhRk9nAkt1TYKOb+uHW8qg5HlcnipwFVGpDdL9vyUQqyRnbMSqShCyQlMF/ITo1gfDoJBOeNajauG1t7clJf7imaeMlxTeAjXSQd0i5503cnfSKWb6vdXH7l7DHJ4sNwhResIgpC2Tk1ety9oS3/yhJKexUjS5PfZ7m4qDLRWTnfxQ14i3Sj1qjGk1YPt0XOMFY5ovLVU7y4JipwYYKitIP5KAAub8Am2+AUc71oqdpvbTDeajSwqhPPYXhh3dGFEpZMDJiXNi3G3HSSu+W1JoWaLO1j9akcwllqK7eOKO2yS1+RD3mbgWZUHcg6LVkJRR6I5SCk+1K4fbQ6NdY8FpgzTjf16kh5454MKVQXVZYWMqBud8tq+j7z04vm+vOlqQcX6iUwSgwPtimjGCmXCVlshSckPm1T1+5DwiHWZt4R5erfdHNDshQzz8KwDp9SW8OnjaSpxzDJNM 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 Reviewed-by: Kent Overstreet --- 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 043944fd46eb..8516adeaea26 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1191,7 +1191,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); } @@ -1336,6 +1335,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 04c55f1c492e..33d9f6e89ba6 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -282,6 +282,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 0b380bb8a81e..ad20f3428bab 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -402,6 +402,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 66a9f10e3207..08873f0627dd 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -203,7 +203,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 7f53be035cf0..0922729acd26 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 740afe80f297..dfd2c2cb909d 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -323,7 +323,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 Fri May 19 07:40: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: 13247786 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 38458C7EE2C for ; Fri, 19 May 2023 07:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFCE4280006; Fri, 19 May 2023 03:42:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5AF5280001; Fri, 19 May 2023 03:42:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9ADFF280006; Fri, 19 May 2023 03:42:52 -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 83938280001 for ; Fri, 19 May 2023 03:42:52 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5BC2E1209DF for ; Fri, 19 May 2023 07:42:52 +0000 (UTC) X-FDA: 80806212984.18.271B002 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 8E2EA120013 for ; Fri, 19 May 2023 07:42:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bpfgVJSB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1684482170; 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=xt8MS4tNW7WMUMs3pTsS0U26gIFNlNPWhaB+SXg4cNY=; b=fL0O3ft2QMQpfUVXlLj5IINe/ysMY94Qkmut7yyguyYDO6l0uVZIz6QmFli1hlzluy1IEM qKLwDaL8R6zqNF60Eh2/N3t2iwUjIg/bhKQQKIaxVkLg4h/9gMzhJPfm9aIkQiBPuWgww/ ZKFaFHcLAL4El6kIlbV0XJSu+apDH8M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bpfgVJSB; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1684482170; a=rsa-sha256; cv=none; b=0re5hFDQsyce2dQmJQH1zZHXUhL5GjHDNW70youngzCPAeXFZ2pkVRCvvplo/5XNWkIQKl xav/5r1hV9BPc4s22tcQteLojx2Z22MbzzPr6M/Y8hca5IEMkMkcfF4ienplwomNmKEXOe a3hnhGhZQ93HOb6TAKZYYSg3kyOylf0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482169; 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=xt8MS4tNW7WMUMs3pTsS0U26gIFNlNPWhaB+SXg4cNY=; b=bpfgVJSBAPsVysZmedCdysBWEZyH57vnfkqcommb+/2wXFwcr698Van/MjFu1GUpFld4Yl UOVbUmhIM+m0ljYEhb3/+Imp65v+3TNJ3KNBlKJPexjmQiYc2gaqn+b7dCxJziygV3tZWi hPIOyQUZIRt4GTyHbPORu2GXUSH1sRo= 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-263-MOrBiR8-MCq-_mwud5C3yw-1; Fri, 19 May 2023 03:42:42 -0400 X-MC-Unique: MOrBiR8-MCq-_mwud5C3yw-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 3E6753C01DB1; Fri, 19 May 2023 07:42:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01B372026D49; Fri, 19 May 2023 07:42:38 +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 v20 30/32] block: Add BIO_PAGE_PINNED and associated infrastructure Date: Fri, 19 May 2023 08:40:45 +0100 Message-Id: <20230519074047.1739879-31-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Stat-Signature: q1rqx1168zi3jcsug6h7pisxrpc4yxti X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8E2EA120013 X-HE-Tag: 1684482170-434547 X-HE-Meta: U2FsdGVkX1/mAAiIGZz5oIWdH3od80BgPjmaGG6q8NXNdN2I+iLOyFgbjRwoqTsOi8JmEkeOe3UElJSsq3nuBstwYW/OLsHXuBxoeCkWQ84FPWvDZZaaOL0jB3VAG6FZB79UPALg3bQBKGADe4Le3vSvc2oTJfwVlOLmATLG0WW3tdJKU9+/TGfhRdxnd/tO+jNryjf1dMklMYWaFus3HmqGxrIo3gJHpgj1cEw02jCRgO+cORgF0hdiJ7x5yppSRaqEtYooPmtACUV/6cd9EXHrW3iQClJ9BXMYIL8RsTkLZshA2J0uaWNWRbWk/++61+EUF8yO9dGo7vZd9tK0g0DpMyAhaC43SBQegC0HLp/CE3LvCUm/sp2lyIJr+x9jg6n1I/ZylTShEelzTnxuO+fzJFDnah8++AXzgGlT/QY6aAr0EUuSvhggYakYeuGz9x+CKnl04Kt9Om/llXTCkDglTpHgboQnBuEVXdvc+i6KOJiELTY8h+bK1l/KbxThrMfoXfTtPDTzvjIRqogDIpxfVM5WAR0fITx+B7yh8i+a3EAXYmGKL3EcSxBi0lHP76y80As4xYTl8QI78KcbwdZnhGQ+13YcbjVshVtHojEpv2X9mFhjyGcWGQGQ62w+NXtyl0qKo8nh9bDwtxEHzb82CVoV8P/itPV2EUHGBDGbcL14N0iMgaEAaktWCmSuDaA7iuCHpmupjeZIsGc6JpT+zPhXy7KUoQtGTmtJabEUN6zSaiQJo8SI1IMSuWiMSMUGUtcodEy54hbRXBTBTYihhVuH1iLbQwk8uoxjw4HHlMYJmlnqnvecnVNmeyYDlFQuU8vE1ThdTbT90Tx9zyJX/04Hi+eFl8J6VSmdLz6i1jLoAaTzLfSL6DfnofLcPtgKs4q8ScDyCxeR5e38NlH7jCkrsE1UfvvpHIxGPWMYr6XTJZLyD53MIE5jpydHu4oWlTtBVOGl3e9gehH MMCWw2TY P1CMsTU00rqyYJv34DeWbk/Goto0OCn+bIJy+SYngUFMTacqanc09oZ73u0dTRHd6piE8/OcGR8vPheUnnb3h7fCsd85/7mZatEi9vBgWmv4QiL5oln7g11a3Qgh5cPxwTNHPuPkWEq+B4WB4rmH6TNamMPcZ5CK8sa/3Lo2XzOjBxm30oh9IDkHYfZ1uNEd2toYS0nE48AfnzWLcn1auvP5wuKueDPHAx4VhVBSmg1cwHvUTkwbobQsfBMEsS6FUv4UPAxfVG4M9uO9NGSDhZbXUgAiqOiesE957h+mbRj6tWG+CenwgFUdYMiQ4V4UaJwmH164hUYj+LhbtV+W+B19411ZKS0SFWfnS5xdMeAUxyoB2gwguDg8FXwgoaHhy9bXVX9DqtlNNXaWUaHq4yIR/8fxFVN55nUTTu96FV217Ub/FRkeZwXpwW5Ew5K0UGwUtFwNBgNkCdaNDvhspYXJNfTL/YWWbcyHa 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 8516adeaea26..17bd01ecde36 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1169,7 +1169,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); @@ -1489,8 +1489,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 45547bcf1119..e1ded2ccb3ca 100644 --- a/block/blk.h +++ b/block/blk.h @@ -420,6 +420,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 0922729acd26..8588bcfbc6ef 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 dfd2c2cb909d..8ef209e3aa96 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -323,6 +323,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 Fri May 19 07:40: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: 13247785 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 B3194C77B7F for ; Fri, 19 May 2023 07:42:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51C83280005; Fri, 19 May 2023 03:42:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A419280001; Fri, 19 May 2023 03:42:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36C0A280005; Fri, 19 May 2023 03:42:51 -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 25F84280001 for ; Fri, 19 May 2023 03:42:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 080651C6FAE for ; Fri, 19 May 2023 07:42:51 +0000 (UTC) X-FDA: 80806212942.27.ACFDEB1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 12DCA1C0006 for ; Fri, 19 May 2023 07:42:48 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c8+BWHH1; spf=pass (imf21.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=1684482169; a=rsa-sha256; cv=none; b=Klmbl95MBNMSoAEkKeuFRvaDQF1EU3BfwTpw08o/PV8d5F4wYRazNzFAnoC18Yjt6ivg7+ 0EdO/7HYckOmzwFqRwNFwEui6rWM3yXfK3l7RG7EbyKZmjLcBfPdAzhiP8HcQlrdrg93Jj YzZgrOrqcd8qNxpdK0h6VvD6Vavmhn0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c8+BWHH1; spf=pass (imf21.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=1684482169; 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=ehlvfIu1rrXcuy8/PZvsT00k//DN+ilG0RL3yAJWLmk=; b=sxfVW+KYAzQax0Oq113/jDtol9CxoIN+0XXpxw/tZJHea2IflTPDgzmN14aODQZHFrSW0/ 2iJcnil969TWRLlDrAfQTDznTCIc9cry8jdXLIpzCubSMqRPhKZ1k3Mx47S94EWsTzCcAz A9MLugrSDMF0O0vZsRjezfa8VRCo1Y8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482168; 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=ehlvfIu1rrXcuy8/PZvsT00k//DN+ilG0RL3yAJWLmk=; b=c8+BWHH1lTBsk3AP6A7tlZaHAhNYQJjufrw4m47qRARYrIKf/hpUJ1l9ZpjT68qiPxp+mg 0U6ye5s/Vf4B3XWOasi19z+NS2K5BTR5d/0aPJ2un2gRAIoIqElUVS9gMH/+CpUNAYM+91 22ufAYB6JFxGd3+EIejNZkdsicQXobE= 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-373-Z2TszftPOkqunDI3f5UAzQ-1; Fri, 19 May 2023 03:42:45 -0400 X-MC-Unique: Z2TszftPOkqunDI3f5UAzQ-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 F2D9438035AD; Fri, 19 May 2023 07:42:43 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7B90C0004B; Fri, 19 May 2023 07:42:41 +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 v20 31/32] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Fri, 19 May 2023 08:40:46 +0100 Message-Id: <20230519074047.1739879-32-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 12DCA1C0006 X-Stat-Signature: ttgedw613rr1kxcobd4buzhwywboe1fw X-Rspam-User: X-HE-Tag: 1684482168-116250 X-HE-Meta: U2FsdGVkX19djOAZQA2c6VdNEfcuAtthMDPp4JijlMfseOtC+9sNkKgXbWDzxWt14eNIXtcz6lszQfYKEgaCgNTXbcIXkixz2qVVHxXgjXQtHkZH7cD6st68fE+y5B4lCaIOJ+g7zSAgcpSCSoyT428LBcLo+lYRgRrcK9rZv8hBay8RlFt3pq5A4ZgVmOM/sfJEZjV+PlQRc4zHRvNsY119tUBD/3Q/62Ul5Rq5mffk3zxDJceqPpM+cmcUJIfSZJc6EBRTToidV1pSWngBkUyiMSVnnOjXDmlpLPnKN6vgj+szoBpn7pBQhmFnZEAX65SxPbDg/Me31cyeLu1P2s3pRIyMus7Pn7WTxgBHVf0A2m8j0KijI9+ZsgKIAzK1sweASMEFSM0Yj3M57MECMdDJUeFLowox8Kp2dTjzkP23M7nildL7J9Hd0t/to9o5zxUuDzRTTnkRqj257V488qkyPhMHhLsofD8ZDqdqJWAhMvcAMec4BznzewBRMWG9tognXShDLw/R8LMRbiWOKERnIN91Oe49KDFag98bOcE2vONOBY6piKfdxB1ytxZgzaRE30kN1Ug5yA0i8o/qkGKih2Rm9PmpKMPWsTv23zhPwQZzi7gTjzVo5lCla7vYMMAOXu3oD6A8woEx9UGGdheVz0xoqYlr/Ki0f+POlVmgb30LI6lSlzJ3SV/iIJwVidkwWSX1Yj5mTpkvxJnDsPsP0JD2qBm2qwbAqExEXIb21/Aqxr7kME2U2DMffW7DoaMC03ugnedqnniSCsHJ+wsby2GDWp0hzsKA19qH7AQWn7b2YuM8ljnrUE8jR4NqNl7PUPu2Z5GGqYyyob0Jwa8BUHjUf0y8SlSuaQ5Tjfe9NsXaQ4peAZpfPggErpExZ43WAT1jHZaznR/JMBMqcm0CyLHVtzZvNlTZif4hQHpFhgnRCD2PjE2y3QjDJVAENInsD+MQ1PhM4vT8hE8 sgoRSINX leLgzv/T6SQq7i8NHvxuOtWOsJNMZ01LZ2msx2qxHBCroIcTTf3kyHswTCQ1ppQQRmWhVNGNT0puPc/Kl/QM7wVcFUj9/+lbk35WQV7ZTm6kf1LQ2W0+V6JidSMe2eh0J8qAm++7nQKhNSqWMB3i1OcQkxwRrDYdGpuv9D0wY+p9ms6Inf8CYuaWNglNlMDdNH5IbEYDD2Stm3AcRlUCc8OtRHeOqDA4or5gi80bbFlAeA+8Yi1ShgBM6Rv/OfoE32CE9AkHtxdzv03opMSY9HMDO0GAWe6oIE6gWY6YKVyaYpcoDO7BgkhJ4MYgHcQXXiIR0NsNJCROWX8pfl0tglOwKfbZR5KTuwKJJ14qDSU5M+NRkyBqaeO/aroi+GwfhMbsK1Hd5NtxFFRDIetm10nFxEwgOVwLbSbBolXNO9Yl2jrfbBIpa1xoEV6PEvhac+z8dPm8SaQj6502S989/nzEKrio5cWg2+ArA 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 17bd01ecde36..798cc4cf3bd2 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1205,7 +1205,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; } @@ -1219,7 +1219,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; } @@ -1230,10 +1230,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) { @@ -1265,9 +1265,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; @@ -1300,7 +1300,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; } @@ -1335,7 +1335,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 Fri May 19 07:40: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: 13247787 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 3E7B4C7EE2F for ; Fri, 19 May 2023 07:42:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6F25280007; Fri, 19 May 2023 03:42:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD2DF280001; Fri, 19 May 2023 03:42:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A239B280007; Fri, 19 May 2023 03:42: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 907ED280001 for ; Fri, 19 May 2023 03:42:54 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 594341609CD for ; Fri, 19 May 2023 07:42:54 +0000 (UTC) X-FDA: 80806213068.08.73A4DC2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 9F16C80014 for ; Fri, 19 May 2023 07:42:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UXocrjfW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684482172; 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=dIfwp0u3TEOxDMU0SzMKHpZq0cYqRy8msS5IGLBkSdxxIq/pJ5210jer0zQ13bOa0nYTVL RiGgz+VRuCJ+GNIvqhpHR7P27RpeZHpnM35eaOf54Lppv37TnTFKla4auZ8Kw+XqSnj1WY zx78gpnHeQdhMBo9k8CpFRirLnw+faM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UXocrjfW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482172; a=rsa-sha256; cv=none; b=gaHssFL9n/I5xIglp4m/Z7k4b5A0twrBU265GPbW+DMs2avxMKyNISa+B1mOdFcEyAhpcd 6PTyaqGV3hY/Rq5VcOLM735DuVzzi1iPIYeRpeo+gJVcEBXBc7nKWrBnb/L/bmdSzyKRlU zjk0LD1H36oh7B7F9E9inv9PypKUmcQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482172; 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=UXocrjfW1HFRQk9mzDW7kOk8JUaKjhOnilpcfz+JZ50IFmrcZ3zc4sYUKVnzCy4qybyDhD dvC7cUioXrcVcn6NOS29nTZbFOiRXtjVLq2k+3+StXVyPIh4Q9MhfMWw58RpGRtBkoO9Gy FRVnjPlZF9WrtrFB4j1NbonQ00bG7FQ= 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-437-iVklZYPOP7qgZhTLOyp__w-1; Fri, 19 May 2023 03:42:47 -0400 X-MC-Unique: iVklZYPOP7qgZhTLOyp__w-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 C287E38035AD; Fri, 19 May 2023 07:42:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A83937C2A; Fri, 19 May 2023 07:42:44 +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 v20 32/32] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Fri, 19 May 2023 08:40:47 +0100 Message-Id: <20230519074047.1739879-33-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-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: rspam12 X-Rspamd-Queue-Id: 9F16C80014 X-Stat-Signature: j1ggqqxkmjnrytpdq8g5na5t6f6orjbw X-HE-Tag: 1684482172-93883 X-HE-Meta: U2FsdGVkX1/SQb6Ua0S0UxBUo5/46gRY907SDgK54eUzWKu2QhC28j4tSgTJlgSwvEKDiIYhNfcn0DXsThuscZl/gIl9Pny/RymVTQL8POLbMw7dMJ/38U7DAZD/R509ANyqIxoJqvWjWQSISnT3ydOscA2Utq5aw5jhKE5uZwUnhkQrUR7qQkUm52mm23LVxJ4ZmuoBtD7PGca4UY4UdsxlN0gyppLZ+BQICG+4Kl7G9gxcow/6EZmyuJ9lL29/sxhlS3sX/qSu7BLxBRBD0JJWAN5JJNIPPCNBMkRwL4qqe0fSmtIi4wEWK+xe5IWiYVbGYZJr2PnOSvrAEDSZ4ma3Dce+Abssc53qwafh3hhq0flRahghAYEwmM+C2BG0AbcnvlZlLpRqfxW1Ck8G2PL0dzpoRG176FXUIWu5WtAqU0zEGiVtxEib1OCshjRH2sTBfySJbToi8XAy5lVIudg943OlEFbXfGCk052Bf+jHExyxoSzXuvn1oDG6KmcDkRw5qCED8GN/m4K6yd60MlzbPWFEmQQ1av0ykz92WvHkS8MCgBtg5v1XFYZMtcSU+ZNrsF35XenUxPXppSDiGg2knoQs5RNksD2Gp+qesUmz/p/+s9J6gD3ojQ0sfwgqW6GJIoZT7CCHwos6q5BfBuLLpHEN11NteUAMIgL4X9ri6qBsmiXXwof4pjHn1iIevkVzLzB/07o1pyaNW9VjUxqJVMLulEW+PYFoyZRB1ZvxWYbdZxhi3VW17DTkISTWsjZKHk8oSmyImtsquWVIeVmBTXoHfL0husNAraoViIIbPs+eWUQX+EMWQ5XQb2C9L46K5/BWzeZ2P8ZChcQ39DCqtjHG7vU+bChhkTeuCt+zjp7JTTbqXYQbpOi/e/cVh5AfF7wT9uBs441qn04Jtx+17fKnE2zlIGXhmEBfpRd0QVB9qaQ0kkbvAd72rPh+7xXRX7BVq2D9X9A68I2 sS+gSRr5 3QT46mIdIyxxnujIZ4na/8P/dScUe4RQEwrjKovdvEXFp9l3dGE8BmgPM7r2PtPb2FaGdV0xJ4IhI0TDkQKwdcVJlDRcLCq3FyAlEjN256ahSbuz7IFUL3kqmEdkWotxV+d7cvfGmVWXl0+iq8u6AnMVTosvkZavd0D4qy0UOrdOmRnRPKoafP3kajMJFJtDOkVEvS88hv5glsX6vsgCzhFUjPnbHbH+a+TypSi+XlTYvmb55tJGperHhccV2cwmk/wkWjvDw7KB5AUn5nTwGrL06+v60VGk20NijIlT9KKU9rP29uH/itmp0uZyEpCp6BbeYZ3z/MtR7IaqhTO8DHubGsgep1mcGOH4MBJqrnHFnyy0wk2O8SXHKY2HF9Y6o15untSwssbVlV+Z51mhC7FkQtvv8O+k97/aLGpQlFabotyJvelpzaxWD1C8ZIQtVAs44HL8Kuh8o5QdT3W6UeOlo4WQJnNW8Ij9X 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 33d9f6e89ba6..3551c3ff17cf 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -281,22 +281,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; @@ -318,7 +317,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; } @@ -330,7 +329,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? */