From mboxrd@z Thu Jan 1 00:00:00 1970 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 56683C77B77 for ; Mon, 17 Apr 2023 11:21:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD52F8E0002; Mon, 17 Apr 2023 07:21:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5DAB8E0001; Mon, 17 Apr 2023 07:21:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD7418E0002; Mon, 17 Apr 2023 07:21:58 -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 AF5168E0001 for ; Mon, 17 Apr 2023 07:21:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4670240471 for ; Mon, 17 Apr 2023 11:21:58 +0000 (UTC) X-FDA: 80690643516.25.18F97C7 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 250BDA0011 for ; Mon, 17 Apr 2023 11:21:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HO0+YObt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681730516; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mkcwhp5zTW1yRaiHiJTdOs9s0Tvzr5julsI/kTPOe68=; b=8ALbg81YHMS1bsEqYiwYBXvBZoXMNoPPVazGSygR/IS8VwxcNuhW9bEIokLCqbXsYqWpDr wYU3RXPMcXPndSMfCPYq1MKajxegTIV0wJ0fP5HMvlyVYa51k5mNJUmmsg+eGR8sxb16/z tLqwkRYIy/q4nNcWaMKOP9S/Jolak/I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HO0+YObt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681730516; a=rsa-sha256; cv=none; b=3OVZruafJztMb8lP5bRCRbuz42veYt7UCJrTEJlOlkkfldhD0l7XLIRAPLEvNqkGzEvv5c ZWKFZN7NrOMoFYT+idYlHaS96FOXN/tDJfYJYQURsXuLW7PbubRFjpwqhXhbmQrS0HMyIh OdKyvtDGrbrK0f9GQRVRJVK/sGJMHI0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681730515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mkcwhp5zTW1yRaiHiJTdOs9s0Tvzr5julsI/kTPOe68=; b=HO0+YObt/3aVi67/IEtOuxKqjMnIa2b6AQnoxpD+Gcb6sAHnKpfwQKeHYCmROOwttBH0Jy j/zqCpSjP+IljcpWrOpIGI8+jFP6J0ZJa1lV6L2w/fReU+M/zjYojNePlTpZNjj8v6fQxX h3i/J92KNj0+x+slDLHNO1MCpcxW5JA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-le5TJnGDPnyJ6xEnZ1Rjlg-1; Mon, 17 Apr 2023 07:21:54 -0400 X-MC-Unique: le5TJnGDPnyJ6xEnZ1Rjlg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-2eef9c48d49so680013f8f.0 for ; Mon, 17 Apr 2023 04:21:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681730513; x=1684322513; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mkcwhp5zTW1yRaiHiJTdOs9s0Tvzr5julsI/kTPOe68=; b=DIxqaHlRk1QthUy6JFeFKykHWB1DKTi8HjyXhOmilCoIvb7lhf3SasR7FMCgM5H7Li mYnNbsn69rhAXRt1lsHbjdpAvdjfabrxG6DvRvdiRLp6lDpHZDhFajW0bq7TznP0WVQr ukGjDdBUblvfXkKhQ5jr/c9M5n79+GFDkfpK4kOIEiwSOCVfWA77TerK6Ggeik0qs5h/ 6hACNqaBGGOJK+TxN8p4g5SN9Uc/J/TaFn7CK/abjUHpJyROTRPTBko62fmCiyoRaWxa cPTGy10mo0MwKOhZLmkbJkB+AqRrJWXgGksfB713y6vOrrh1jru5Zb5KgLxcziwdMqND UKtw== X-Gm-Message-State: AAQBX9etnnavmgdpAB2WguQdbtzw+FCqtX2XmfkxEzn9mpokqbXzvNDV JOLyzhRmTWz7ljqEViEETWnXBM8VoFOOrrIL+Gvc0uuVlHPTeo9JqZ0eGi1jUrJMh9TZaNE0r/H MplgwTk5eItI= X-Received: by 2002:adf:ff85:0:b0:2f9:dfab:1b8c with SMTP id j5-20020adfff85000000b002f9dfab1b8cmr2581411wrr.50.1681730513175; Mon, 17 Apr 2023 04:21:53 -0700 (PDT) X-Google-Smtp-Source: AKy350abZRZAOfdMv9lYJhbEZufnC86FDoAE2OKI65tR0JXtMEmI74JIW99/H3RyhX6ngBR4MbJnEg== X-Received: by 2002:adf:ff85:0:b0:2f9:dfab:1b8c with SMTP id j5-20020adfff85000000b002f9dfab1b8cmr2581395wrr.50.1681730512826; Mon, 17 Apr 2023 04:21:52 -0700 (PDT) Received: from ?IPV6:2003:cb:c700:fc00:db07:68a9:6af5:ecdf? (p200300cbc700fc00db0768a96af5ecdf.dip0.t-ipconnect.de. [2003:cb:c700:fc00:db07:68a9:6af5:ecdf]) by smtp.gmail.com with ESMTPSA id e6-20020adff346000000b002efac42ff35sm10294758wrp.37.2023.04.17.04.21.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Apr 2023 04:21:52 -0700 (PDT) Message-ID: Date: Mon, 17 Apr 2023 13:21:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH next] shmem: minor fixes to splice-read implementation To: Hugh Dickins , David Howells Cc: Jens Axboe , Andrew Morton , Matthew Wilcox , Naoya Horiguchi , Yang Shi , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <2d5fa5e3-dac5-6973-74e5-eeedf36a42b@google.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <2d5fa5e3-dac5-6973-74e5-eeedf36a42b@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 250BDA0011 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 6r646o54sjiiujr3t7odx7jjmo6ddx49 X-HE-Tag: 1681730515-844837 X-HE-Meta: U2FsdGVkX1+l1r8oUb+sUJRMa96r69ozmmfRs7bo7HNE4GPFo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TYNsH8R7x82rM0P5D1ctsJ2wBDDdG16cpGVCdLUNZr4ApYxc3Suoj9OblS3zUeJqgMHuDRSYydLAWaj7N4+Q/QfkYn2g/XrhfyJ1ilKbqL5Gjt2d3RqjSZ1/GLYCR2cblKCMBw21WMq/8CNSt85tx+1Gmet2xKjFXa0kgmJtLFEIZui0m3AUTd0/PvcPtHJN+L+Cyp5JrApQiFEbtY48j6GcUr2TDsA4g1beatd+/t/Ye6yL44TKDricaPlXsJuxZVSDNIJpGAAQNS8ZXQoFHa5KWWDm0= 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: 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 > --- > 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