From patchwork Mon Apr 17 04:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13213248 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 5B4ACC77B70 for ; Mon, 17 Apr 2023 04:46:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D08D28E0002; Mon, 17 Apr 2023 00:46:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB8F98E0001; Mon, 17 Apr 2023 00:46:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B80A08E0002; Mon, 17 Apr 2023 00:46:34 -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 A957E8E0001 for ; Mon, 17 Apr 2023 00:46:34 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 72F4D803C3 for ; Mon, 17 Apr 2023 04:46:34 +0000 (UTC) X-FDA: 80689647108.07.0119296 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by imf20.hostedemail.com (Postfix) with ESMTP id B9A511C0010 for ; Mon, 17 Apr 2023 04:46:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=c1lvjA2Y; spf=pass (imf20.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681706792; 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:in-reply-to: references:dkim-signature; bh=7RMbe6t8cwMwC4L+hDo6tlAvnHa7eL2NdAx0QI15tWA=; b=7E5A5TyuRIIYLEeDpLStZWV9WrveW/WYvDu5rXBDrQOfIrwgRJcD2CqbDA74LfMkANuaTK CGLgftKZ+tDZ5+wkP/WOQ01pLI1PVW5rfWR+aHGFrUgBZlucRuSJRWofzqpC85uBnSsQYM hMZodzzVGW/uob/vwf1+qXnA+5Vpf98= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=c1lvjA2Y; spf=pass (imf20.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681706792; a=rsa-sha256; cv=none; b=xYSwN4eWnQ5+sACK8OBTgON/xkacrwFF3/yLvXiDqWtBFRtfAxUV5KCoZ06ltc2tlKn8pO 7zkziNioMJfFyfGxw0JCPwI51NbAp+A4hZ9IlUXhw6RqXzwh5B9U142d7K+/i5+SXsPm77 c8E0LLIenTaKdds7PbuhZmaD2OjFFOE= Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-54fc337a650so154171417b3.4 for ; Sun, 16 Apr 2023 21:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681706792; x=1684298792; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=7RMbe6t8cwMwC4L+hDo6tlAvnHa7eL2NdAx0QI15tWA=; b=c1lvjA2Ydr0KKWFVOurlEuJLUUiQc/fd5uFEN6VsS61oIZ+QIKo9crxs9j3T2Iaqb8 O0bQpK7v7bm+8V4tAh2R8nFUz7Ugm61CMH66mrUWcnaW3cUBj0dra+tYZ1dM7R3ctbu7 l/L43imdrVY+1oDd+OPtXfYeEVbXrW73SmRKmSwjTBWAaZi8+hYGbksw0BetMOlV2hOm s+CLHiAKG797aQeXHH3LJQGarc2O476afCnrfdwgInbC6MI63fsZSBNG7r1ZJx7r28NE nobICetFvaOEDfIzUUzzyi8cUeTNUEO8mJIHwZXxYulQBrZQ+AXdzWfGxnHNKh9SSvbq rYuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681706792; x=1684298792; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7RMbe6t8cwMwC4L+hDo6tlAvnHa7eL2NdAx0QI15tWA=; b=F1OdX4w/cfZ+XjffdCvgLEZ/a576IPM4YUvAwRfv4ph0T7n+EPCeqt1WyTpOLBxpV9 OzTV3GJKKPalLj35bQdmpij+fJ/k0bcgwzZBUde4+o/HmWMbK5MsQRJbVb09kzajXh/J +UZr3ilZOe47HekLjSDV6r8jiOlZUF6GtXa42kKmYAd92PtPk+pZ+garAaOyw5Crrzot Ho46jAmXORYh9LS5TgyMD1MBwHFnc34m88TN8zRRO9tgSCv7SCk3lwZd6VUZIme7YJC7 lhEj1VnwLSeun9D46tk8gY+Raw1jFZiZRZn1nfIh2xedFos8IBryb0Uy6LnMa7X8fLjs thDQ== X-Gm-Message-State: AAQBX9cvU089g9D9ZJBlsdXDnI878aJW2KOEnHDTelwoUzXkcG8KiFwh Eo1OLmU1BTSBQ8xeRwBVU4A/Wg== X-Google-Smtp-Source: AKy350bB7WbtLMHSyStHV27G5/XguAU1bkC12dSQmwfI/VO4RT1/tD2O8SYSmrnwX7w62M2HdexZQQ== X-Received: by 2002:a81:4951:0:b0:54f:e0e7:c6fb with SMTP id w78-20020a814951000000b0054fe0e7c6fbmr9832191ywa.8.1681706790262; Sun, 16 Apr 2023 21:46:30 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id cm19-20020a05690c0c9300b00545a08184e0sm2903022ywb.112.2023.04.16.21.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Apr 2023 21:46:29 -0700 (PDT) Date: Sun, 16 Apr 2023 21:46:16 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: David Howells cc: Jens Axboe , Andrew Morton , Matthew Wilcox , Naoya Horiguchi , David Hildenbrand , Yang Shi , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH next] shmem: minor fixes to splice-read implementation Message-ID: <2d5fa5e3-dac5-6973-74e5-eeedf36a42b@google.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B9A511C0010 X-Stat-Signature: bcnuknnpicn5uydpcbce67ymxg7ycp8p X-HE-Tag: 1681706792-414172 X-HE-Meta: U2FsdGVkX19/Pod62pm6bTX36Rl0VzxtkP6d80o9XfIUgz4vyxf3bAeGQ6t73cYcF4fx0fUsBT7qhSwtxRo/78f5KyQGpPFQR69czl0Lue8KH4LQgGYiDwJ5IUDLi+H8C9XOKJpjTgaZ2cdf4VMCYF6Ee/4vFkdMphQ24PR4nu2LF/AOzCZPU5B2qdLJWZlexdX7JyvSXmp+hsKu2tY1mFJ5r0aVWXVvvYqceQgKIG36U369jIskBmbNd3aBkHfwHOiSeRBpuhMWn2eZmLKqIYIE7l2W0tJACciF/OHzlKgtA3D6HmSePGv1ZMetRKHYIkU/NhP93SAA6TI6Cp5pwcdMjpH4Ctq/Snmo6WjM+V7oGm5PuekvcAhRRE56sUVCEjWIqXYh550Xzll1gBrRtpwUQzjpGScYz9nVzIDyGYcqWXFETkYYVr2tp493ZG1rGaJA3ydRlW9qcIphRCjhIajJKiPDCUkRv1JChGZNRgqUG0DO4siH6XimNDTxGWkvHLyavuMlrHLm01MQffNUBEBKlS1vAeiy4oG9sXREp3Nt0rrvstxjsXkPGFPPJJCQol7egrinOckuBWHVoNF/iiMhhVhcCr5/y3IcCIiRXCbz1tl4tMvvYLhjkbJPlQK+ckC2hPf5f10rMRxpWChliZX442uX6sVfj3pFcudca9cywuawDsLxkxi4oRXmuynLqlQnNllR+4VTbLDHi3Lz7M41GGdGyDwL/Fp40YyxQfzPubP0FJmC+UHjh9qIoFGtt2zoui+Th1PrkBQ0LL1zFv9JPfq9X2BPhEHv7aZs01HV5dMFz8eFsFTWvW5R5A94TZusDS7tTjuNHWn//XrbHNQMkz9j6UuHlih9Fs7k7WqbVeg+eAgAFlyaaJLWjUKsYgCR/GGGRvsGsR9641vHW7jSmnP8P3nADn8dRS62AxNHQwiYKK7X0CKdSrV9fmKkj9dwhfg6FEvb/wmAClT /r7uZG07 VGayTYKWSVJW947N/aUxoOInL7gnWbkJiHmYWvhWKn4dAJaM3JRmMvDPUzgdSPt2/V3DimlffDRDZfYjAYhk7EgOBkEYRmLClSLseilZwkihI83cqTb4v8j69SXpq4BPdiC0fharU8j+oT1zQCiBxrlkSDl8tMYBNnhTc4FYZp7jMbZOKOHc0oofqbHHBmBTCIvznqjnb3Gajpy4ozNJo3oymSpHPfgrZoxg9XtFrvplcZGRY13mr/E3gMUX2SGAFt3bFz6sql0LhYgNqDhDutXyW910HO6CvjeLNRN1wTx+LIp0L5I7ZTpTpfAS+ZVgif2uKXp+WZImn4MdRU/ryP+rqKtcB5dNHSlmPsclj7Q1YzJtDa1h53ABKNZsMZ/J9jdZK3fVVN0z500sB3dn0bC2ohw== 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: 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 Reviewed-by: David Howells --- 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)