linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Hugh Dickins <hughd@google.com>, David Howells <dhowells@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	Naoya Horiguchi <naoya.horiguchi@nec.com>,
	Yang Shi <shy828301@gmail.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH next] shmem: minor fixes to splice-read implementation
Date: Mon, 17 Apr 2023 13:21:50 +0200	[thread overview]
Message-ID: <dfa218f9-1a99-f877-4c9d-a4d185b6ebd5@redhat.com> (raw)
In-Reply-To: <2d5fa5e3-dac5-6973-74e5-eeedf36a42b@google.com>

On 17.04.23 06:46, Hugh Dickins wrote:
> generic_file_splice_read() makes a couple of preliminary checks (for
> s_maxbytes and zero len), but shmem_file_splice_read() is called without
> those: so check them inside it.  (But shmem does not support O_DIRECT,
> so no need for that one here - and even if O_DIRECT support were stubbed
> in, it would still just be using the page cache.)
> 
> HWPoison: my reading of folio_test_hwpoison() is that it only tests the
> head page of a large folio, whereas splice_folio_into_pipe() will splice
> as much of the folio as it can: so for safety we should also check the
> has_hwpoisoned flag, set if any of the folio's pages are hwpoisoned.
> (Perhaps that ugliness can be improved at the mm end later.)
> 
> The call to splice_zeropage_into_pipe() risked overrunning past EOF:
> ask it for "part" not "len".
> 
> Fixes: b81d7b89becc ("shmem: Implement splice-read")
> Signed-off-by: Hugh Dickins <hughd@google.com>
> ---
> Thank you, David, for attending to tmpfs in your splice update:
> yes, I too wish it could have just used the generic, but I'm sure
> you're right that there's a number of reasons it needs its own.
> 
>   mm/shmem.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2902,6 +2902,11 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
>   	loff_t isize;
>   	int error = 0;
>   
> +	if (unlikely(*ppos >= MAX_LFS_FILESIZE))
> +		return 0;
> +	if (unlikely(!len))
> +		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);
> @@ -2911,7 +2916,8 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
>   		if (*ppos >= i_size_read(inode))
>   			break;
>   
> -		error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, SGP_READ);
> +		error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio,
> +					SGP_READ);
>   		if (error) {
>   			if (error == -EINVAL)
>   				error = 0;
> @@ -2920,7 +2926,9 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
>   		if (folio) {
>   			folio_unlock(folio);
>   
> -			if (folio_test_hwpoison(folio)) {
> +			if (folio_test_hwpoison(folio) ||
> +			    (folio_test_large(folio) &&
> +			     folio_test_has_hwpoisoned(folio))) {
>   				error = -EIO;
>   				break;
>   			}
> @@ -2956,7 +2964,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)
> 

FWIW, looks good to me.


-- 
Thanks,

David / dhildenb


  parent reply	other threads:[~2023-04-17 11:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17  4:46 [PATCH next] shmem: minor fixes to splice-read implementation Hugh Dickins
2023-04-17  7:18 ` David Howells
2023-04-17 11:21 ` David Hildenbrand [this message]
2023-04-17 13:48 ` Jens Axboe
2023-06-29  4:42   ` Hugh Dickins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfa218f9-1a99-f877-4c9d-a4d185b6ebd5@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=dhowells@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=naoya.horiguchi@nec.com \
    --cc=shy828301@gmail.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).