From patchwork Thu Jul 27 16:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13330343 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0056FC0015E for ; Thu, 27 Jul 2023 16:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbjG0QLQ (ORCPT ); Thu, 27 Jul 2023 12:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbjG0QLP (ORCPT ); Thu, 27 Jul 2023 12:11:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0A1D2D4D for ; Thu, 27 Jul 2023 09:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690474226; 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=6riGtniLbVW/0RUbKJK18+ZXuUEMwjT27R+MDiLMQAI=; b=Yr+KFc4NEp50oiB13FUfSHin8zMoVr3JIt0JLJjbcJAMYxYePUvIIkJ5dugBATkKC8kPgE jetQrLjzubanMgSs78LHImhXxCiXddeXP7hQd5Z6wkBqSMp2LEj9jjOiXTYzXLiX9XWsFC /nytva2qcTkMxMnCRq54CqWZ1NUbvng= 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-nOoNmV6EMre8aO0nn0whDw-1; Thu, 27 Jul 2023 12:10:24 -0400 X-MC-Unique: nOoNmV6EMre8aO0nn0whDw-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 6BE30185A7A5; Thu, 27 Jul 2023 16:10:23 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC402C57964; Thu, 27 Jul 2023 16:10:21 +0000 (UTC) From: David Howells To: Hugh Dickins Cc: David Howells , Andrew Morton , Christoph Hellwig , Jens Axboe , Al Viro , John Hubbard , David Hildenbrand , Matthew Wilcox , Chuck Lever , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] shmem: Fix splice of a missing page Date: Thu, 27 Jul 2023 17:10:15 +0100 Message-ID: <20230727161016.169066-2-dhowells@redhat.com> In-Reply-To: <20230727161016.169066-1-dhowells@redhat.com> References: <20230727161016.169066-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Fix shmem_splice_read() to splice only part of the partial page at the end of a splice and not all of it. This can be seen by splicing from a tmpfs file that's not a multiple of PAGE_SIZE in size. Without this fix, it splices extra data to round up to PAGE_SIZE. Fixes: bd194b187115 ("shmem: Implement splice-read") Signed-off-by: David Howells cc: Hugh Dickins cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Chuck Lever cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2f2e0e618072..0164cccdcd71 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2841,7 +2841,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, folio_put(folio); folio = NULL; } else { - n = splice_zeropage_into_pipe(pipe, *ppos, len); + n = splice_zeropage_into_pipe(pipe, *ppos, part); } if (!n) From patchwork Thu Jul 27 16:10: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: 13330344 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D130CC0015E for ; Thu, 27 Jul 2023 16:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233597AbjG0QLU (ORCPT ); Thu, 27 Jul 2023 12:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233101AbjG0QLS (ORCPT ); Thu, 27 Jul 2023 12:11:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7D02D59 for ; Thu, 27 Jul 2023 09:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690474229; 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=TLR8tINgbBniZykrMZZb+ehfHyamxexwgaHRKDrxZjA=; b=WrgIRkUlhEgIcVfBBnruNTC1Z4mDv7HC5bKYmPbQszKce7sh3MhMrrTuzNb0xwb7bPYUe+ HG4qDfuKmZ8etQJEaMu3JsJXFnaU642t8HXUk8gXEOXXlEc4CS1YRFfOijjpVgqEcEQOaj +ArkA/Y2+8JnNvCllvV31CfSljChDQo= 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-500-vm9257bXN52QLdEzJBO93A-1; Thu, 27 Jul 2023 12:10:26 -0400 X-MC-Unique: vm9257bXN52QLdEzJBO93A-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 9DF87858EED; Thu, 27 Jul 2023 16:10:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1000740D2839; Thu, 27 Jul 2023 16:10:23 +0000 (UTC) From: David Howells To: Hugh Dickins Cc: David Howells , Andrew Morton , Christoph Hellwig , Jens Axboe , Al Viro , John Hubbard , David Hildenbrand , Matthew Wilcox , Chuck Lever , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/2] shmem: Apply a couple of filemap_splice_read() fixes to shmem_splice_read() Date: Thu, 27 Jul 2023 17:10:16 +0100 Message-ID: <20230727161016.169066-3-dhowells@redhat.com> In-Reply-To: <20230727161016.169066-1-dhowells@redhat.com> References: <20230727161016.169066-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Fix shmem_splice_read() to use the inode from in->f_mapping->host rather than file_inode(in) and to skip the splice if it starts after s_maxbytes, analogously with fixes to filemap_splice_read(). Fixes: bd194b187115 ("shmem: Implement splice-read") Signed-off-by: David Howells cc: Hugh Dickins cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: Chuck Lever cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- mm/shmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0164cccdcd71..8a16d4c7092b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2780,13 +2780,16 @@ 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 inode *inode = in->f_mapping->host; 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; + if (unlikely(*ppos >= inode->i_sb->s_maxbytes)) + return 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);