From patchwork Fri Feb 9 14:29:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 198930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp900157dyd; Fri, 9 Feb 2024 06:44:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBOKLskSsrU/6crCEkXViCJoCTV64iyPaPOwAOUWWkV/S1BTLazDsw1QLORINQ+v/v48Vu X-Received: by 2002:a17:903:40cc:b0:1d9:196:4dae with SMTP id t12-20020a17090340cc00b001d901964daemr2263379pld.8.1707489878183; Fri, 09 Feb 2024 06:44:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707489878; cv=pass; d=google.com; s=arc-20160816; b=YamXQ/G/HQTU9fIi+k325ALeapJg6b/an6ij/ZfBNvjTFkoT+dWXPMxv3D2yw+MfFH uNvE3ReTtUF5EZ5Djir5ebXVb5eTmQkif8p+jXUF5/eJVXteczL/ycKG6zm1iOOmPEks Uf0F5utYl4PN1gzEFNUUTezcIS5zoJGo09XOmgZFv5XsQkGR4ejtbx8uTltKsHs1kqdE M6MZUnAmsSW7pmp0VEuA5DyFQ8PbSecNWxQDrdGSjdEZsC38flwlJjMaF9w584BAdKxE boB9zAkI1Tbo/7Fp5IIs1DB35dRIOvamg4HysXRrEAfe6R+vWvDFTH+uBNLk2oaAs/rv +irw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-language :accept-language:in-reply-to:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-filter; bh=2ukBs3XODipZcH9UMRwa+Bu+eJvhDnac4gizoogX/Is=; fh=CPcpDWwGETcqC/iBrf8yeIgxT9c71+o8zXVoF1VeID4=; b=B2dhY3hn1gAL09B+FLnAIJwsFuSIHY1OkoYnVNtobdqucgwhOxf43agV7asa4Bx9Jz S3Wu5bpBxvd5SCsPxT4pGAWM+lytBFTlJr3LQMcsQZtEcXI9klHz4ikwg+J+Kb3nMU7L dhPD8d7utqLMV0OnRppW9hqNLYbexwNB/sSMzc+1QipUufRTA0mUGZINLNZwhug0aQSB EfY7OZ3gL2MFBU1l7wOV+2fE7DgjQuNexgyy80A61BUKxOLtjdS1raR4PLh06BkyhOFB jJuslyy63oTRA/LgVeM65/CED9PpGxmfnLHGEgjoX1K3c3LeAWXTEXx0/iQ02wR1q50R VAPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=RBme5bg9; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-59457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59457-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com X-Forwarded-Encrypted: i=2; AJvYcCX34phk5TWHC4g6T0ywoBKPTn9wcFP3jb772qmZOQ7FX6qOr1jb4I0OYWR5gIc70M0mSrWgH+kxCmE0SZinaZZmnMydDQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ma13-20020a170903094d00b001d8da1c6933si1823574plb.58.2024.02.09.06.44.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:44:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=RBme5bg9; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-59457-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59457-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B6D89B271BE for ; Fri, 9 Feb 2024 14:32:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0B0B7604D; Fri, 9 Feb 2024 14:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="RBme5bg9" Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 905AE69D3C for ; Fri, 9 Feb 2024 14:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707488952; cv=none; b=Q6eNJ2Cj4ek5Xji0bcU/SUlsIXhJ0h/3MkahE8YbYL5D9+jveuHnsTmYaglAeLkQ3H+05KIoIA/0hDbsgHG9y+GRX1KDWLy8YyAdlbuZmVmKaxGH0Mf6R6H5192kPIaVgCHLl6PECTk8lQWy3rsBIqUwarCkpegdPPI7c2D/1v8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707488952; c=relaxed/simple; bh=oTRfFe+/EH7DLR5K66X2qKeSonuT+RMKMk6eYxbGvf4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=cLKVBUVXQsNYOHRm/Ju3wMsRXIhhThWb0RqiV7d5ScgmIThczkchC45CyBO9GSKnLS1IeMrettVwLhUWCjO0Gbf8b3Wxn+FNG9TJrzJK8pk90mA9VIm9l5gDXTU/HSC7wC9trLp3NMv4ViIeavMa3XfpsESQJZRzdKPI40NlTjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=RBme5bg9; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20240209142907euoutp02a2b6a259c6689919044722ce24c21d11~yOCa8sUYT2144221442euoutp02j for ; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20240209142907euoutp02a2b6a259c6689919044722ce24c21d11~yOCa8sUYT2144221442euoutp02j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1707488947; bh=2ukBs3XODipZcH9UMRwa+Bu+eJvhDnac4gizoogX/Is=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=RBme5bg9CdOVU1oMxV4Ybb5Xo1Nj93LPn/TZtYuGuDM8JoXqabMx1IU3QdKo7ub71 br84AeHS1lrt3ijAYBC6HuMLYGxyp0VVNLhcqZ+bvQl9HOZFq7OxWRJ+FKG5t7UoD+ ozfa6KR1lEkjdqiPt4HA+LzBQOIeV3uqHiwc+BsA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240209142907eucas1p22dc004862a93d76c2817fc28c5432e48~yOCapm-8m0060200602eucas1p2G; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9D.2E.09552.3B636C56; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240209142907eucas1p2024d2809a150c6e58082de0937596290~yOCaQYIdi0486804868eucas1p2E; Fri, 9 Feb 2024 14:29:07 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240209142906eusmtrp1ee69ff838c2b80b9dc3c11119a3a418b~yOCaPfpUX0528405284eusmtrp1C; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) X-AuditID: cbfec7f5-0bd9da8000002550-a1-65c636b3a878 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 04.B3.10702.2B636C56; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240209142906eusmtip2e2024a73a312042137f498874cbdbfe6~yOCaHDNtj0196001960eusmtip2P; Fri, 9 Feb 2024 14:29:06 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 9 Feb 2024 14:29:06 +0000 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 9 Feb 2024 14:29:06 +0000 From: Daniel Gomez To: "viro@zeniv.linux.org.uk" , "brauner@kernel.org" , "jack@suse.cz" , "hughd@google.com" , "akpm@linux-foundation.org" CC: "dagmcr@gmail.com" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "willy@infradead.org" , "hch@infradead.org" , "mcgrof@kernel.org" , Pankaj Raghav , "gost.dev@samsung.com" , "Daniel Gomez" Subject: [RFC PATCH 7/9] shmem: check if a block is uptodate before splice into pipe Thread-Topic: [RFC PATCH 7/9] shmem: check if a block is uptodate before splice into pipe Thread-Index: AQHaW2RVHDRO8t3PIUKSo0ZMZU2cLg== Date: Fri, 9 Feb 2024 14:29:04 +0000 Message-ID: <20240209142901.126894-8-da.gomez@samsung.com> In-Reply-To: <20240209142901.126894-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHKsWRmVeSWpSXmKPExsWy7djPc7qbzY6lGhzsEbeYs34Nm8Xrw58Y Lc72/WazOD1hEZPF0099LBazpzczWezZe5LF4vKuOWwW99b8Z7W4MeEpo8X5v8dZLX7/mMPm wOOxc9Zddo8Fm0o9Nq/Q8ti0qpPNY9OnSeweJ2b8ZvE4s+AIu8fnTXIem568ZQrgjOKySUnN ySxLLdK3S+DK2Nt1ibXgMW/F1u2fGRsY73N1MXJySAiYSDT3bWbtYuTiEBJYwSixdU8vlPOF UeLjpW1MEM5nRolHX84wwbSsnzCDBSKxnFHi6ckvjHBVy/a+Z4dwTjNK3AK6G6QFbPKuqeog NpuApsS+k5vAikQEnj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1oYaRnaGmhZ2RiqWdobB5rZWSqpG9nk5Kak1mWWqRvl6CXsbfrEmvBY96K rds/MzYw3ufqYuTkkBAwkVg/YQZLFyMXh5DAUkaJaweuMEMkZCQ2frnKCmELS/y51sUGUfSR UeL/q5tQzmlGiZ4JO5kgnBWMEsc+dLOBtLAJaErsO7mJHSQhIvCUUWL670NgS5gFbjNLzGmf xQhSJSwQJtH48jI7iC0iEC1x/dsnZghbT+Lp1N9gk1gEVCTW7DgBVs8rYCVx8+tOsHohIHva 9tNgNZwC1hLzHq0HsxkFZCUerfwFVsMsIC5x68l8JognBCSW7DkP9ZyoxMvH/6Ce05E4e/0J I4RtILF16T4WCFtRouPYTTaIOXoSN6ZOgbK1JZYtfM0McY+gxMmZT1gmMErPQrJuFpKWWUha ZiFpWcDIsopRJLW0ODc9t9hIrzgxt7g0L10vOT93EyMwVW079nPLDsaVrz7qHWJk4mA8xCjB wawkwhuy5EiqEG9KYmVValF+fFFpTmrxIUZTYBhNZJYSTc4HJsu8knhDMwNTQxMzSwNTSzNj JXFez4KORCGB9MSS1OzU1ILUIpg+Jg5OqQamHrZNE+tE/n5ST+rf8t4pdfe+hpfaF18a/mAJ 6jJc6ar0y0CNY9qfh0ff+sstOslotzB9xZUnC8v93RibZiT2Piy/a9Ib6s7W52euIN84+aGC rH+dW3pxo/Zyc/NnAifeWU/o2XHtTUv8u1U3w4qUZKSeaH2+3PrCW1ws1k5h4YFynSlCG1nu zL0YLv9FRPeBx4eNS1qXp+7MexN0Tn65XkkdZ99bz+zQtGuPg+xfp/MpbHrY7LFx1rc79rNV lWL9Wbr0L9blVHez8rG/frrul67L7au7T3JE/Vvn/aC8qNrY44fPshtbanV7ei8s5YjdIu1b ZDsxXHvJjXU3CounL41h5OsTfW7yu7htIpMSS3FGoqEWc1FxIgA4VgMl3gMAAA== X-CMS-MailID: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 X-Msg-Generator: CA X-RootMTR: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240209142907eucas1p2024d2809a150c6e58082de0937596290 References: <20240209142901.126894-1-da.gomez@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790432906366716160 X-GMAIL-MSGID: 1790432906366716160 The splice_read() path assumes folios are always uptodate. Make sure all blocks in the given range are uptodate or else, splice zeropage into the pipe. Maximize the number of blocks that can be spliced into pipe at once by increasing the 'part' to the latest uptodate block found. Signed-off-by: Daniel Gomez --- mm/shmem.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 9fa86cb82da9..2d2eeb40f19b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3196,8 +3196,30 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, if (unlikely(*ppos >= isize)) break; part = min_t(loff_t, isize - *ppos, len); + if (folio && folio_test_large(folio) && + folio_test_private(folio)) { + unsigned long from = offset_in_folio(folio, *ppos); + unsigned int bfirst = from >> inode->i_blkbits; + unsigned int blast, blast_upd; + + len = min(folio_size(folio) - from, len); + blast = (from + len - 1) >> inode->i_blkbits; + + blast_upd = sfs_get_last_block_uptodate(folio, bfirst, + blast); + if (blast_upd <= blast) { + unsigned int bsize = 1 << inode->i_blkbits; + unsigned int blks = blast_upd - bfirst + 1; + unsigned int bbytes = blks << inode->i_blkbits; + unsigned int boff = (*ppos % bsize); + + part = min_t(loff_t, bbytes - boff, len); + } + } - if (folio) { + if (folio && shmem_is_block_uptodate( + folio, offset_in_folio(folio, *ppos) >> + inode->i_blkbits)) { /* * If users can be writing to this page using arbitrary * virtual addresses, take care about potential aliasing