From patchwork Thu Mar 6 11:39:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: K Prateek Nayak X-Patchwork-Id: 14004336 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 7B219C282D1 for ; Thu, 6 Mar 2025 11:40:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B875280004; Thu, 6 Mar 2025 06:40:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36906280001; Thu, 6 Mar 2025 06:40:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 209C2280004; Thu, 6 Mar 2025 06:40:17 -0500 (EST) 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 02912280001 for ; Thu, 6 Mar 2025 06:40:16 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4F22656C5C for ; Thu, 6 Mar 2025 11:40:17 +0000 (UTC) X-FDA: 83190932874.11.78B9DC1 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2048.outbound.protection.outlook.com [40.107.223.48]) by imf08.hostedemail.com (Postfix) with ESMTP id 5CBDA16000F for ; Thu, 6 Mar 2025 11:40:14 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=us2hlPIc; spf=pass (imf08.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.223.48 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741261214; 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=hOpN0zEc8cInHConMJIJjTGl0oV1Z8GIpP/kTvr5DRw=; b=iv6xzUdgLv8iqJAocSF9HK8Perc87AQN5eSjjNCiIG9S3oP6tJ4lEtTl/ililvERr/1HWh KTxoFJEEk3d5Xg9oPI8mavQK3CvB6k42Z6J9/vCcpyTi4WTMC+ykfV3qZKDOttilB3V4s3 MRDIcHjpWxxrEt95UEIo+bN10f1ueYI= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1741261214; a=rsa-sha256; cv=pass; b=i15aYJ99litNegps9YC7NPAFTISZ/5H9mMyKKMsNwNxdFYeqjYoPfyfDY/1fre8Pkzo40R DZAMqAjHYeZ/vwwk01fXEQe7106ryd7flKOmumSFSh49WfxY4YKrPwljf2GeOd9Iz+WNh3 kbyZ4alPuLo4bDig259qO3VGfOx1Hq4= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=us2hlPIc; spf=pass (imf08.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.223.48 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YNFjfC4ziE8ui5LOWhxAIyOiB0Xcv+dsDBC9pc8T+MWhc87V44OPO8D69vwa1fJQxDyQFnSQnYuEJRDVKo1/7JBa3sD/MjscCGkRPrPbR+JCj7Ysi8rzx3bIucVqPHXQJTpb6yjhiOZy9vZHSgiU944/UXy2++FLIn7sPRi9t1FP6pr1gYMtZ50xXBSkQNFX/Bno5BVTOSnapooTfAbt3LKD8RIDsMcQg/uHY2Ei3SnyxHubdxIXjHdIEHBRQqhXPAPrKKSmNwvivachDoFh8q7R37WHUrgXfExfZWzKeiAiHHB2GIdNv5AZdMQmPOQsrnjvuWRWy+Kf9FgUe/0ATw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hOpN0zEc8cInHConMJIJjTGl0oV1Z8GIpP/kTvr5DRw=; b=qT9xm26XZ9rAadinxBhq0GZNDAFW12ZiDIVc2RmH1eWOBKMYhosbha+hacZEK5tJ8FFqRQhccYWvWD7tdspvjxkBBuADMlURwWJwsQtdz06JGQxCFkr8w4x+fNJz8KwHRxE+tNX+mMR7ynlC5Zgdz8PG4olZ6WcTmLminP5Z/GKWxYKuHibb1NIB5g9oiVL3PEzxeG5ARdb7vE0U0mHCUxJmDE0XR+qt6mm+j3mIpVnvErzx1+OMcLh5ElhFrbxI0Gq3lO7ERpxZZpdJchORtLJzHd5+97KttJDNrSOWGEmmMDtTOcU011OxuFvyT685mc1FPXfCbqXDw++bcyE+Jg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hOpN0zEc8cInHConMJIJjTGl0oV1Z8GIpP/kTvr5DRw=; b=us2hlPIcWDjpgaU8mKJHi7JjlfFgXVqZo8QOfNHQDrjZdF3cs3LjzSj14AWVCxom8Ux+dUdaZ0BAewS3i+h0fVlY25RArbMWwxeLaYzCweof/WWDYSvsnTDTQk6pauwaL8oANqQsASf2JE9BLOEixBHjO0seOHxIyN+uxg+MkN4= Received: from DS0PR17CA0017.namprd17.prod.outlook.com (2603:10b6:8:191::28) by MW6PR12MB8707.namprd12.prod.outlook.com (2603:10b6:303:241::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.16; Thu, 6 Mar 2025 11:40:06 +0000 Received: from CY4PEPF0000E9DC.namprd05.prod.outlook.com (2603:10b6:8:191:cafe::5) by DS0PR17CA0017.outlook.office365.com (2603:10b6:8:191::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.17 via Frontend Transport; Thu, 6 Mar 2025 11:40:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DC.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 11:40:06 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 6 Mar 2025 05:39:59 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Miklos Szeredi , Alexander Viro , Christian Brauner , "Andrew Morton" , Hugh Dickins , , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , "Gautham R. Shenoy" , Rasmus Villemoes , , , Swapnil Sapkal , K Prateek Nayak Subject: [RFC PATCH 1/3] fs/pipe: Limit the slots in pipe_resize_ring() Date: Thu, 6 Mar 2025 11:39:22 +0000 Message-ID: <20250306113924.20004-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306113924.20004-1-kprateek.nayak@amd.com> References: <20250306113924.20004-1-kprateek.nayak@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DC:EE_|MW6PR12MB8707:EE_ X-MS-Office365-Filtering-Correlation-Id: a0e95e4b-797a-41b0-d0f3-08dd5ca3a449 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: 0yM9AQMpbAR9/CONQ4MBXeTAcnB1zzZL/UNd4grn/8CEQhkzwjjvNvyga14XprcGJVtEPpHlLU8ejPlaW16MnmeZ2y8Rb5e2AmOB/ZZJBOoNnU58Axe4IecoCrZuTpfxOdDT0xdD+eO7pBBq2T7o06Kwn5bw50WIkMyLa6u1U8IJpEl7X8BI44HsUpNWGv0d7QuHSaIeO7nOFKRYg8vxUgqymfdqy9YPb/NeO3PkWelN+pRqk2AFEl6bfh7m4GhBh46v1zrioGCGnSVXkRWO+sQcQCS+97KOkeMRrpHitMqnFrCUXfkDtkFK8YTregz26O1RjJ8noWv7bza0KbE7JzvHR/4p4aPUnrMhM75n0j7/4KVlHk1Cx+sCQuL/s5lNWQzJ1v4Pufrqd+ltLyZ2TTfhruj5lca1dmUaxNPS4PcFlOR1TDQHNApij1X9GxMR5wEfJWfxKf+rzq9eaRHDjojppBLB/PsAb/2i1J9ubtwXWDFxVCeaSUpOil8TOBDb09gl/oQ0MRLfuE4BlFxN9eFRJjV5B9Aj2YNrTFKub3iBePCxoiSW3f8ejM73etYdLJq/Q9ascjhe5sDPKv2RrRCANtzqkvLbHXtpQ2CBvjlbBCPl9sn9ALeNTSvAQk4DcNwQ6k+wMJkTtoksyygYISF31nD9tR3Kq9/kHgQKeaTYWJpbPJH7ScTdzvJ1YO2kJfSGQs+KMyqAmX6IU8B6k6g9e1kmc7Aer+O+b185NOGwM4TVdETvsPkQB36yrvXaXRrjmC10FjSxCM0qCNAmT4PPfB2e7KA0qD9zA+TSgcdEzqUH/i04OWSFExcD7ClKuNMNblISj46FAx+iAO6TldWbEbLIucGx8JFMKurWPyWVxqzrhdEYMJMm1XOXImSan0QGF+kqMvuN7JTb/x5e4+PqaQa/OMkGfUHkw/N6efTDbDARww7/PsplS3rGAB6u9LmskymzxICIZt943ukq5wuIf91/6nGeqpSqlRU33dwWElB1dnrubh9XnVpuEFq37cOp/87ch0ehpvpKs66bPH7FagHZHMNLqlDtyrVvAQQ30EGqOPp8lK7Qa+w3o7CGJDHIkopN5B8XvrMPvb/JU2fGk2bvCL/Wx0Ivkn+GEa0+/Hy3FgCQRLCUSXeyoNp4bDHddxtOrM1X7t3nMmCjdcp6sI8fquGt3idtUjs0RyXMkZHOGSi6hMogt/kD2Lw3+aT42ODGi7qFOPLRvC9wghAJIGFDwNhJ8LBpm3LzI7VJd75iFL6N6EV6JLwx1+j4EfJp7WQ8AtMOWrs5lt5KMczo4xSdIsLWrqSo+7+TuDtKaTPgm0kvYJNGoJwgA20EaSKvrJdjr+ei1fvIrtcKP7q+HrhKmTv2X7uZbPCRXRLCVvfnZcgGjvDg4eXawIRLYhOGt0tjWFCUXoY0AbJnURZd0JWV9A6T3clhIL0lF4EUwaxiXatOqP7QJh6wDt4jPkqd/qO04ifQpBVne5CG6w8iyqbIRrtN7m1+nk1ZV79f1DJUn5aHcogEncfVAuiM X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 11:40:06.0329 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0e95e4b-797a-41b0-d0f3-08dd5ca3a449 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9DC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8707 X-Stat-Signature: qz8utpojat4fx584amza9fy9un8tccpf X-Rspamd-Queue-Id: 5CBDA16000F X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1741261214-202132 X-HE-Meta: U2FsdGVkX19OEMYtwPJkoI3/Gg525xHnVUEhZ7pvwIvOTClAAaUOltN87RjNuYSop7ESMfW0jQZVrUnIp+GDjkdSJHS0B4RSDv3Z7po/0O27TdKGc9qZqzSC5Gz4mEOOIa+aLdSPD/d0O+Psb+FfLD+V9g7hrRE93AR+oa4GiDnygyxyv87umF7YRGTdqt+H5PKdvPd0j7akUJJk0i02jgaBhlkmF4nLkyEcW9rmHNnhjmskjcrNR3O70XjTTiblOJ7IaIRX55FerCuVRGTqnsFiJBlBfqy4Sw6BvMdMuSDFXxlW3VT4fXfqLJA+Vj2P9mvlHlWA/W4T/1os6XtslPts8N8spRgsYHWYsXJPiDdc/OXtKvyA4pgQzE3A/bFfdqqnci7XtujEus4gjI8mOf0kqUVcMFhOemVm7YA+3bSmG9IHSbZOgwvG2qKQYb/VWTjinEMkRwrM+NuOiLE0RzO9CaoMoqBXb0b+LwFlrrkJJy2PuX4UDrSDblG/zEUoo6qZVoZwQa5UCOjBpMpHBu4edrPSRHkfpd6pDJk5VHlz4gF6TDd3vhuk/Ywp3bDeNjhHYLb1vLZmbajhB4Y/fLa7jvaBFLNN+DNsmMXfU1gTRKMmbAraUEMFx6/37i9SkXBiv4chFRx/zAI/pwb6ywmsjCx+FMH0H3mHG/DBpZ+r+bQOf+/qLL1TSulqXLVVCF3+jaXGoGrWtqfArwU0WEqDC0b4OiSnrvPgKMdQEeZjH94D7/lBzmZ7cesO6oEUCke0hYB1JZ1ejt2kGE6Kko6YWyB2INCdwVSvn7DN63sbghEdu4hhUFZcDpXgKBCfnngtAyvhBtD8zHZGMO+piPGVFCUKWte1a+o+piKGo9JhkYjpB2fvzVTeoklIklPimO/ZuEsjPdpzxFL1foHQyBPcZTU2+L39bZ0hgFCftALUudYB/VdFc/kyd0xtu2DnfEXC1WWikyrbSBBOqoo 7MYxlaT1 FmwvHeBHEQ2pCdcE4B6WNkno4xJwBCccZsdjDeblrOlCFJeHvJD2sOs3SAuQnRVa/YG621IqfBPyVe7VMk3/zIuK8mqJOPQW7VBji0R0CGpiGCOgjdcUMJSBY2pEVRA+JTqW9NAb4EbJ7ptJ3ZvHcSZaAcYKiPAgwjoFzD8thhc9wONQFK5NuueIKNwySLw6qH8AT/7L401yXvATSuO5UJ6uBdw11epSujNuW3Ouj0UQDY1Ecolal86uiu7F5Q5b/6wdanEtAb3m/R5CF9XduRv+J72lSg8Xx0Mg0rXDnxdWrcx5A9aiwSC/PDejPbb4MFKW9ypbLTasWhI3KrHuqVZwqDwMrWw5ctDTSCL9uhyDD/xvWLeBeIBin85cVHFubNt6i7thfrQIlpmXd5Hy9bOksCpx0ihHHhDj/igdG7m0C2KsFY5m0ADFuyNe9RzE9QLTz29S5qM/LAVAGefdPtEebS9pQzTl+xFfycQZII7pc24QWoAOO3LHTpBcUXKVp5ZSlhbXmffLmhMpj/JmMNAtB6ysijEXRKTnH8s+SaxkzuKk= 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: List-Subscribe: List-Unsubscribe: Limit the number of slots in pipe_resize_ring() to the maximum value representable by pipe->{head,tail}. Values beyond the max limit can lead to incorrect pipe_occupancy() calculations where the pipe will never appear full. Since nr_slots is always a power of 2 and the maximum size of pipe_index_t is 32 bits, BIT() is sufficient to represent the maximum value possible for nr_slots. Signed-off-by: K Prateek Nayak --- fs/pipe.c | 4 ++++ 1 file changed, 4 insertions(+) base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43 diff --git a/fs/pipe.c b/fs/pipe.c index e8e6698f3698..3ca3103e1de7 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1272,6 +1272,10 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots) struct pipe_buffer *bufs; unsigned int head, tail, mask, n; + /* nr_slots larger than limits of pipe->{head,tail} */ + if (unlikely(nr_slots > BIT(BITS_PER_TYPE(pipe_index_t) - 1))) + return -EINVAL; + bufs = kcalloc(nr_slots, sizeof(*bufs), GFP_KERNEL_ACCOUNT | __GFP_NOWARN); if (unlikely(!bufs)) From patchwork Thu Mar 6 11:39:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: K Prateek Nayak X-Patchwork-Id: 14004337 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 ECF34C282EC for ; Thu, 6 Mar 2025 11:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8663280005; Thu, 6 Mar 2025 06:40:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A355B280001; Thu, 6 Mar 2025 06:40:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D77C280005; Thu, 6 Mar 2025 06:40:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6B342280001 for ; Thu, 6 Mar 2025 06:40:32 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B58671214C3 for ; Thu, 6 Mar 2025 11:40:32 +0000 (UTC) X-FDA: 83190933504.22.4A0F385 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2083.outbound.protection.outlook.com [40.107.101.83]) by imf27.hostedemail.com (Postfix) with ESMTP id ABC4D40007 for ; Thu, 6 Mar 2025 11:40:29 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=r8RrzXk1; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf27.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.101.83 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741261229; 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=Qb6yW67yojK6bb6VWOs3X8iThjJoUbpShCGMeGQd/Qg=; b=2EaVxsWfPjOPZTiEmNfMqGzHFAGJwiGCdszUPri+bJOC1KOWfTc5y0aQTBd8xFmLA5XMT3 p6cpxIF2wvg2RCHtZ1AtB6sB8f1cMIwe0K58w4gBrxfrpP8tA8LNbD3pjSB8B3nXRhGfP/ hvfnmwzCALPgE0Op1fAHCwHUFBONLZw= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=r8RrzXk1; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf27.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.101.83 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1741261229; a=rsa-sha256; cv=pass; b=v0ntNRj7ECcS4IRY8/4prusDFlI9l7x/OXGwI4aJyKWWsb7XIgPi/H+Lawa5jCLHGRVyd7 UzPyoczdlQqv33BesKi0YjMiLgMKldyiZEO1UY+8j4oimnkrkRvlEE3at0hFN+aBxaavxz 2rA6cRw/ZcCaquGnaXkeEuQhOHv9RmE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OFP5sfrZOGG4SK5k1Hk72lDx/LlbGyGHtyqwxj0eE7r/6yKyC2gqIulROF3Y0JD/WxqGF2/Y2GaYSGLsYpI26ucAFqRKzvr8xqY0ClKYp5/25igVJklDOrOiVgKNPubyRN+5pf2dnl+cpe+xx5X8/1qUR5C6zlhTAs9T4i8ddCVMzbpUJ+LDMAdCQW8mPon7ICIaphcAGGvolJtWESdVKyLUtCRxUKFxR/vtO5Ggk2JD01P6qDY9u5I8XFDNOkqpSQHagRYn5LwxTDzmePW+YxuCVEsA6O8wmutWxSEFQ7MAJw/l2/Onmvr39RXB2P0sIQCTAGGizOXDXsacIoizOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Qb6yW67yojK6bb6VWOs3X8iThjJoUbpShCGMeGQd/Qg=; b=KyhC6Vcc2agVsxsYbS6UKNy5huMSYzYJ5FkHDPT5JwuhQEsMVOr71Ts88+5Glbm7UV4+yHJOd9326PkJKOStRv82IngY8XITJk6OhJBX+sD3kK/7yKyG4oD11Ovsym1Oe7vhm0QKXlFt1gyIn7fik/P8mzQx2BdSc/fUCkxAXHP9jhqMIS58pTCiq5M+NU+WESygOfaPMWXbkLQsGJ5eW/wVUJJfs5KoAbcIJCyM7pXOwwa9z+k2GQQX+sqqnN2pVS4a7dneEPV5KT2dPqwZ+CkKpRDkl2KPwjyFy8m9rKux/MQCLGnQ25MU9jjSjh+326Ba4mKxj5Kw5+JFBjoukg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qb6yW67yojK6bb6VWOs3X8iThjJoUbpShCGMeGQd/Qg=; b=r8RrzXk1t07TCv9KG5xroR5gzpk1YWZGb+AbEHJuhszrYnlwOHSasra+lYU36rNaJc8SA4wTSSXxYWHouUcpC35oyVoqaaVGWxb2cJzsmiMEHP2VAan2p6A+YY9ucfClWVVIvLeb//5qb7AFPKL1orZ+LD+G9fg55vyF3zXz7JM= Received: from PH1PEPF000132F0.NAMP220.PROD.OUTLOOK.COM (2603:10b6:518:1::33) by CY8PR12MB8066.namprd12.prod.outlook.com (2603:10b6:930:70::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.18; Thu, 6 Mar 2025 11:40:25 +0000 Received: from CY4PEPF0000E9D6.namprd05.prod.outlook.com (2a01:111:f403:f912::5) by PH1PEPF000132F0.outlook.office365.com (2603:1036:903:47::3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.18 via Frontend Transport; Thu, 6 Mar 2025 11:40:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D6.mail.protection.outlook.com (10.167.241.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 11:40:24 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 6 Mar 2025 05:40:18 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Miklos Szeredi , Alexander Viro , Christian Brauner , "Andrew Morton" , Hugh Dickins , , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , "Gautham R. Shenoy" , Rasmus Villemoes , , , Swapnil Sapkal , K Prateek Nayak Subject: [RFC PATCH 2/3] fs/splice: Atomically read pipe->{head,tail} in opipe_prep() Date: Thu, 6 Mar 2025 11:39:23 +0000 Message-ID: <20250306113924.20004-3-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306113924.20004-1-kprateek.nayak@amd.com> References: <20250306113924.20004-1-kprateek.nayak@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D6:EE_|CY8PR12MB8066:EE_ X-MS-Office365-Filtering-Correlation-Id: a6b719a1-e0be-4a11-f2ac-08dd5ca3af93 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: LmZ0tLhsi5yIhjYuciVW1JA6qxzTsqSiJE9RY9SbYuzrWnPCAzGD9wdkkwCQs8ztuX6LpIgZWeIGgRHLrzARu/Ua6t8La4EDth3U/gzz9n1MEcxLZVE2jKpbTvrXQpiN04tGhoiNyzVi9cxJj3o3Kn5yiWmI4dKjO5p7MLq41JzVWu71BBazcOMGC8Xw9yFq/pkA8h8wrBghheFe0lY8mI/GLur7t8h0v5UrJ/yoPQuqND35KbFbkkgtSOK0sIlLpQ+UsgVaTYOri0kKnqiLpmSw0TWfJActPoREyP1+OGvdo2HlbhuCFCf8PC8/+8Qmj09mQgtovFvaWX+VqleeZC49WUkA7JC/Jxdzs9e+eWJsDehYDGBccDrGf5RTa6IA8jc8nAX7+Wtn6KLUu2scwowXU2UniHNXleBS5NpI9Yj0KLaMSaR2KwJIi9wJCFXOx7BWNQtuJ/C+bDKslUenICbHBOiOEmnGtnhlbb37BaX3CVQ19Y5rRJjxbsjsp2Pb28rAs/JwEwUFXRpeEaOw6indLGl98LaZ8DSHuZ5cXyo6N4c8yffJRUmvsDQ5i9DOYAKtsDD2dA9GN/o3aSrqOP2UpIO3vYg7y2v0Ro/dY8uj5osJEZ6A/Ycfl9KcYVa8PQd2vZ3JwhtuRYf+wlPb5o6JRf830s0I2oeFaH0GmnkYQt6keXvj12bQ3juymy5DriMHyMR7vIkFsBDfNSoX0pI95UbSxaD2EZY/+UWJb2FG4ve6TSn31XMJMILYwRd/kJFV9LB/7hkdv+XN1QpVuxlmTUp58zDcNFY8O6uLiAKjumr6d7NlGuE3w8KvFEP2ot6t1UOjUoZgd6iAs4LWd9y6Yg8R25ECg2qD3AWVmyZKl6e++5wG6AwhDdPT6r8qhytM0pw2HNwhvkjUUSxyYbigyYRsE6N8V71JJmhLa0XI+aAl0pecNUZ6BsPLaL77JHW5zUCJYsU4wNHJjsbGupZU7sI3VhGlI8qXNJx0HpQ96hmkd0tlYynsGdPBSEvSAv7ynh+16p9RDBi6S4Onw1YTK/GneiXLRzhZvgvj35LCpa2dTvW5IotiyxtPWtVcYNTcZwcyTuHwWhgvmeHomLaTNVNJ+DZxGWk+Xr4ELlIYIkSr5LotDVBHCYteFw1P7yfVZWf5MIB5IMAtSfmbon3kQMUu7LLLey4L9TdJmRxIOL0NYjI8QxlQdUycvYpqEV1H6FuUUTcQR12BdA0ndfW6XbjMMhFR3N2mD70KoZI9ddPUDAKwtbQ41ZPNTZeMyKA3rkHzhrJJUZHO00sqbfTv4Xs2iVeNp/leSX3BFWvQwYll/r2xjLgJQoOwT3RViVvKekL1Rn5D2xpeZ8uLMH3JwV2amxfLAYTlYxt7lHg3EPJjRDXVkArjaD+8rw3MpFYGGhBogTNuKTJvy7VS1vYJuOQml8cWNOMZu6UuKqhlN+yrUIVDhejOBif2dQ+BESGhVifSc8Ae2dIlMRlrpTNc4nvsV8VbINmnw4u9EswEeZ5vHlU/D5a0///ERESs X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 11:40:24.9893 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6b719a1-e0be-4a11-f2ac-08dd5ca3af93 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8066 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ABC4D40007 X-Rspam-User: X-Stat-Signature: b75r835o6zebyzqtdis3f847hkxqpe6j X-HE-Tag: 1741261229-329179 X-HE-Meta: U2FsdGVkX1/uK+jxIkKbMT2JUNNh2varC34ewqveRy40QcQ14jd8OvYaDBGMtSBv6PFMpG9HPx4N7S8JODI3RDjk7APPsTS5rS8sbBKjXjULt6aK/TkvqrBcztNwMQAy12MjffLm8koGqmoNxtfmfLKlJzNv5ivbmeXKgepgHKp9QC8UAfe0vMdJjsFcWYKmcPp/MJnnUv84/8kvtYwMY0EH2nebgFHgNgPftj0DKuUBD5VKGzfMdpZFFwjB6lBoH8fLe73u+b//iTTZVDMNYVdRVQhjAW+jjnZMOrGCauKHmf/SvD8GAix8Pm0EmUfe/BVuTkTcjlLzBKL7zaMzDwUEIC4e49IYBoPkswzC/9WVCDId1mFoUno6K99IoWO96c47xH7jUo0vh1kXKpj5Ou6k9m1pSlXXh57j8EXiwmxT+II3CWJbT/Q1HtnJ/XVBP4F7sggh79zRc1c/e5PocvZZcyUhyWTmgrgDQJyu58Bo4F+5CRq2Ye7g0q5L7yDTenc6u18bX7xU+QVJAb81bbR+8tq3cePiQTNE2vDS2mzXV+28u1P7LfZd9aHDnpWINrPHEKqKsjOM0jbgBTHsv/5a6gsOadyJUEnbDtv6AMAfsl2rcb8kBgtvNJ9XhC6o0S9pNpYbj8OIR7TCsdb6bEgkGzprENpDkd38nC0DBIsWwUJsmznMSxPzf85NHcnDjjydeT6wWfkgx2GtC7mptbL86Ki80dfRMIXESmqhPfEuIlrDG3L/Od0lpJSYBvXo4uK7SkGCaqfhZLPZGLVqJDg83ZNllitRigIYBEkIa59eHpYp9brXQp3inPg5tfK4AMtHAPycwmaVOYQIL7Wzc3a2fGxkl5gVhgsWUVjTJqOY3+1TWS1HMIRN8ibWmyd9VVIpkwfcrSgpMaOpWAVClEmbP8CaEXCS09PM+506NR4OmiSh+OVhaflG10VwOs6SlhyqxwADta7mcdTu6Cd cOH7a28e VJ5dJuyBjmRIW725CENy/4oruTjN1dysyHk3BsRW8scGi95FhArWYlmM5dc77LOyJsBfjmvnQVqCyG3QKPud1+8IItQNBS6HvkcMxUxUGTPOll4XH8lQwJaW9BSPR+yVXRC7jFCS+d1shUSU1bRxjcknrvmDVkrwgdKGX9x4P7koEmblleiXr0XVuyx4bAvMtze4hJOb4r2loyeHQOi2Rkqcb/7lqfRg6b9qPIm5hi/wPlvb75+YQdTxMGQjrOvqZOXrClZANaVSOZSFmnejQ5+gAd30p3H30K/hNS2CrgbTc5mvMwV3VdTSq760/STK32Vk4afho8k8k/LxkFPjzFiYJtsNgc8h5tCcSyYG0w7FTunIXCVNcRIe9xPfqNDYc4KgaN9Rw2H0e+N9sLDa5phzkhJHvMX8BCDNDPqkanxBS/50etfbkOxD2nO39Zfk3Lu7EEoAThZPBvSmb89QreKVr2C6ASmwruCqs0i+wCMpoq/QmpwtMppA57VOrQH9ChKEGEMSl6J9Hpc7xwZUQJzp4ugzkhqUP0yj3xQZIOH2kfdg= 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: List-Subscribe: List-Unsubscribe: opipe_prep() checks pipe_full() before taking the "pipe->mutex". Use the newly introduced "pipe->head_tail" member to read the head and the tail atomically and not miss any updates between the reads. Signed-off-by: K Prateek Nayak --- fs/splice.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/splice.c b/fs/splice.c index 28cfa63aa236..e51f33aca032 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1682,13 +1682,14 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) */ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) { + union pipe_index idx = { .head_tail = READ_ONCE(pipe->head_tail) }; int ret; /* * Check pipe occupancy without the inode lock first. This function * is speculative anyways, so missing one is ok. */ - if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) + if (!pipe_full(idx.head, idx.tail, READ_ONCE(pipe->max_usage))) return 0; ret = 0; From patchwork Thu Mar 6 11:39:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: K Prateek Nayak X-Patchwork-Id: 14004348 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 C8417C282EC for ; Thu, 6 Mar 2025 11:40:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F164280006; Thu, 6 Mar 2025 06:40:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69F45280001; Thu, 6 Mar 2025 06:40:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 540D4280006; Thu, 6 Mar 2025 06:40:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 354A1280001 for ; Thu, 6 Mar 2025 06:40:57 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C35C85635F for ; Thu, 6 Mar 2025 11:40:57 +0000 (UTC) X-FDA: 83190934554.04.E08BE67 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) by imf01.hostedemail.com (Postfix) with ESMTP id ECE924000D for ; Thu, 6 Mar 2025 11:40:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ko7NujTm; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf01.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.94.79 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1741261254; a=rsa-sha256; cv=pass; b=Hv2VMw/s6eZ3YIKDwxGPi/rBATOUQ4oWbrr6g/w+nObCEYQOHKRLP52hismPJkXAJ0orcO bofU4qXhnPfWfIr4eZCivdPLxBbsR1UMdygovjB34dSTbTZ0mP0DTK/nbZvhg/lt2JvqQ1 KfeSjwFgYKZYPnXDmkoEAfcw97IMnMQ= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ko7NujTm; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf01.hostedemail.com: domain of KPrateek.Nayak@amd.com designates 40.107.94.79 as permitted sender) smtp.mailfrom=KPrateek.Nayak@amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741261254; 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=yWzYkgs+iTmA7ljf3vmtYL2QU3Kx0wKwUlGM4TzjI+o=; b=Z9J9SwypltqER2yRbDzENTtt2Gr8/4kPRSraxmfxhjtsGb/7rqPt0UcLwVRmTFxLofKro1 /CNa8iL9lCEAg9aXKkR/FTyHfiKRWTwjo0jheaC4KYghqFgJLEg5ZPbLO3dLZPSHznmV1O 78NYP7NcmPchxSUS8LgZgB2jtmvaM/8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LPlKUVx2PqfrKDuZSeuZc07kdXCrzZgWorQUjndWeXZlj9NO2/euLdx/KUmXDh0/bE+tSRvAiFGEdWqDKo7xOH8chO+JI6/eAqz4kRhcA/jrKf7cMID8JGtezr9T5+isZhUcKM9roUe5bRXZIko1joFvU4AWcyu0l/4GU32pMz9/T7BYEP0Zo1fIPUjlL4nkej0dfSzdoNsbaoO4kAISV2UDwGMVB90LLQGP7/wj9Tez5IcPlBKIs+NVDMfOIwAqktvUtVeH7tAntTg+v5Ozh/m4E6cGddkg8uc8+VDLot99pnan/GYfM0Dlgs4YuJuuvJqjNmYNBIP9MYocntr4fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yWzYkgs+iTmA7ljf3vmtYL2QU3Kx0wKwUlGM4TzjI+o=; b=FI41KlssoLRAt53HHz6lAphV3UPgBX6YS28unQDwC6l5JFPP1JTLQGsmFIqU29eXWAeezEfk00Ud/Z/08HWjq/8P0RD7nDmykgUGZXMGVaU4jaf3+Lqb4S5J+46tnfJMSBThdvxWRkhmjavIcg5JnxmX4hXY0E1FTedhLXEO5R2kAXLbSArsRawpU/LDUH9ITxuVzvInyiQA8fOIWLAh2fq3hHU3dTRpcYxrF6bwLptizrjjCS5TGYCJRAduUcpQCuzyY49mi4Kge5FqKPGcYkqvWBFYv4tJrLS+P/Eh5MEey0ouCpmBIiEWrTBI187ZruoqFDM4MdrDrMEfc2LJMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yWzYkgs+iTmA7ljf3vmtYL2QU3Kx0wKwUlGM4TzjI+o=; b=ko7NujTmsOe02u4tXvX60KO0azKxrGmPcoyF+EbuPmL408RwkLEvk4zvZPx9UpD8QhGAuEuxkf4XFg3lR/dCbhtEktVzD1s1A32K20dbbRUBZcfpkIzNcNfgo+A8cKRSmZlnkBGxZo4KoTTOg4lFBkq2BUY1VTWenXcJmEawvyk= Received: from DS7PR03CA0114.namprd03.prod.outlook.com (2603:10b6:5:3b7::29) by PH8PR12MB7135.namprd12.prod.outlook.com (2603:10b6:510:22c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8489.25; Thu, 6 Mar 2025 11:40:45 +0000 Received: from CY4PEPF0000E9D8.namprd05.prod.outlook.com (2603:10b6:5:3b7:cafe::e3) by DS7PR03CA0114.outlook.office365.com (2603:10b6:5:3b7::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.16 via Frontend Transport; Thu, 6 Mar 2025 11:40:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D8.mail.protection.outlook.com (10.167.241.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 11:40:44 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 6 Mar 2025 05:40:37 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Miklos Szeredi , Alexander Viro , Christian Brauner , "Andrew Morton" , Hugh Dickins , , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , "Gautham R. Shenoy" , Rasmus Villemoes , , , Swapnil Sapkal , K Prateek Nayak Subject: [RFC PATCH 3/3] treewide: pipe: Convert all references to pipe->{head,tail,max_usage,ring_size} to unsigned short Date: Thu, 6 Mar 2025 11:39:24 +0000 Message-ID: <20250306113924.20004-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250306113924.20004-1-kprateek.nayak@amd.com> References: <20250306113924.20004-1-kprateek.nayak@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D8:EE_|PH8PR12MB7135:EE_ X-MS-Office365-Filtering-Correlation-Id: e2bb570c-9619-45f3-0126-08dd5ca3baeb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: JBfInG+4LwF+sCA8FfcKj1Ta9XmXWjKnzsyDq5DfFGTqeyG9/4pgrUMHQKaBH8QKNtMnOuOBksUsszJ2mcZIhzUMgVWaiUC4enaNRw2KVxyO0/TxlC6RouE+IbBayX9Slfpy1aS7IdFH2Hy6dFWkpracg9NihRQ2CKHgVnt0EtFcqBSka5nyfSaYCLVRH3IM4wN/KAiemr4wYxCAyhTJZZROnRb+cF9UkKeOqZ9VHLwAp3YE3Rrg6miFTt1jXBL/oJQzjShNz2OqACktAvH7Mb4ycBq3VKmBZZXSr0Fq/gpJBe7kJi75BTjhXXAiMWMZc2uJ197+ZVKaAktImQVrSbkxwMpHuxR+vr7wWThVWeD2EG5xN9eHDObb/aikS99AkdYoPPGCFaANYDtQOz0xzl1d/8zgdirSH9k2a+Q5+6Q3YjhIMt/fpufyGDsXaOu4+1jfjdkbS2nGb2qO76YklFC3s8iFz8qw/wdEsCqpb/Qm4qMf4kgOcLxQwhmJFhjwrNtdo/7/0vPBFgFR0wgNCp6aKmAQaB8HQKxp/ddV2OtPhJjKHIiO/iDlSd3g9oDVvsLcYZvbhBAfLqSioGdnMc6GbYle3SiDi4GGqdhwVBqpNQrSb83ZTUiJoWYcb2Lv5gHroJ50UUpBlRVESzIV2rliKOJGWAdx2n0P7yvTs2fqxRpMk4iKOMR6Czc9u87XQicQdkUTFF5M5jLxZ67SZrkRZAT9xH2V+EROKpxMxhT7SekUmd6VRF4CFk7oY7ugGKnYy6fJcvRmkQV0K6273GHxXk6cS0nl9yN8Tsq/1xJdTLWuxoyCtjKsvIQhLMlQK6nLGyKI9thDzaaqvfsIlgL5C2OqfhRFqybmeruplzrw8+nqpoVWAHbdlX9/MaftrlS0zos/5YJNzUykTnezLTlS0Ar1a8cLPWpwig3LjMtvjyA/SwMle6uE3nPFwEQMjv99YCfST8JZIUlM558+UPhLyNVOwTwRUmkpre+kqHBSuEK7HhnL9ixtQVT4e/4j4OpBLUkVyX7RUI9qoCNECpCX4DWXiUz8z1Wh78IC7TqcC3VP8LiqtACF9c3gUvQnewEpXulzXM90Dt9H8U72LDkf9InVXrRI/EvrqKgc5wLs+sbl7ce+WWHRG1v/lCNIY0pyKEwM1TJe4HioK6HgBuBDVewAxLc44iWipAPCe1phhbw+Ybc4bSU09maFQMec9dIhQau5tP8L86I8v9hlitjPLZlMRmVCiTNta5dsY1+WSpAzsdp8s4DtW/zFMNJpHMOZ0XRzVkcmcpKGdFmnlzZbD9p+UrntekgIHjcvTZVIKfx3xrw+wkuKhJCame6xoQvITJkjnrblq4AsW0oz/Qr0SV+/A1safuV5DAUtnHzVmFwN629aFjaxabEYUzFsIQ5NTLrBhxRZIWYbJPvd6lsK5E4HrXArdnBH6nMNhqBV5Gx+UPewb1agRhR12ozm2/b8JP49Fkoi3KWhOFrZzV3ygrPe5uJoQAo4IIa6mmbMC2dM0XoqDW4S2a0CcCnB X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 11:40:44.0147 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2bb570c-9619-45f3-0126-08dd5ca3baeb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7135 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ECE924000D X-Stat-Signature: kej9wz6sdnx4hez73un316qo19jtqxi9 X-HE-Tag: 1741261253-420967 X-HE-Meta: U2FsdGVkX1+DeHpOACPjlDEnI3LjHftdDSNDy3vgf0666Lp6WckhPOn9gOAFmVk1MrTjL5lem2NVCuYF5vIp1NyEqx+ApwTRT0p/l4lq+/Al8OPxKDKFcz+CMhTYu35tUDBLC7w8j6eWdCTyW074TFOwg6hJE1UaAZRmqPe0yWFtzXyDGw8HgUDD3EEWHq6ju+glFyGbhWcxZEnZZeX8ShrNmfQ3pFHSssgDI9ZjMjoM0MsQ53XQrExIBjNXg791cx3aYnxXzCac60LNwMeSjTNarr6y4Ig5Mb3HcUt2YVxStddlF5U+Cvt/n6fczMXh5NYk7ZzElox4BJ4M/Ns0MUipxzs28EqydYeILL8avI0F5HidZtWZXDkChjal9isjXLpIv1jBlQERx02WHvmPe7f+l5s3gA/p3nGmt2LMQLgwuY2NLTDMml/48wM6YpQSrj4p9BKKTsSbcRiIznwt5OHGKDM2UcwjZwAJ1d/g3KgE9pJstu0K/nx+w6KgxRoU1sE/JGg7PmRReWNxXk+lMLjRc672MOjb3xNyKFXOS5Vev9HK2t6oJPD8797ZwkDzPatZFW56O9E1visB2vct2mG3df/FM8sQEeIrqnVjh4iumfSqh+z0JFFzZIG72xgxNlild8NFyIISSwQhjSTjIQOzhOCyUMxI7GL6/tJZvaDZXozQbAXAocroGSaTxV978F47j+430/6JymFwTI/MYRD6Ftz/aTIvBCxt6qPS4aTHSLFxAF/5YrHfgYmL3kft1OHMoB5FNv/KIxguKUj7zMP8PF88L3ft29uwfwOtA3N1tG7WrKoQrE3JWxDRhXPuk0mQc+InWHjFtkRorlFRyT4r842a2iSHoS2iQIZ/LTi4pepMg3p5rQDh1gL1A+tEvZ0HRzwgwHMYV8IrfDBaW+zwehZvs0tnyYYv6/5YsqE5GhDqbeWTk/87bM0q1SpaQGwuLY3D7H6IdUlbxJU 5lay3Yli isfOu+4m5mWpLcjSxxXG3HTmBtlhu2hlwX5MS+mIjakJbxg8AQtbyPSiEGN6ewFkUL3j+SqOYWf2HogDcIp+96WGAI6p9UTAu1TduQMUTkRREORGnQMOH95PrWK9Jx3wAiyKKMh3S4NhuAAPuEzrzEK+DPMVOP8h/0wQ2+98E05lWBWA7m/n95jgFX46ZtKmtHhAvOTTVd21yJLQV+jPSN9fMyO8kTPrJbtUZjy+/rLulSPF13UdH20d+7/XhuO5LGY9Nt2HOxBfpH6E5GGUHBI0corHsAvqCSjO5zsvvkAU1zBTmtNbtmIbOoMSly6GftJFePHakJooMV6ljE+GH/Zus2HNcO5LG/nFrkgGhTcartyGHxGo7NvrSu2jXiQCkTQBOkpn6zeWiIJBurBPN0d9XIH6q2yfTgYoqxfN95nu6iO+GgApuFUndU2AUylVeJJQGnbCqSPiGtfPzVfAoVoi008+Yqxi6BNk1EdT3aX3DcoTUPnAJkzVhO5QZhvD62PkaSmDXMYR+ZnwWx7/3SSBNLvT0LUr5EYndpDp9OVfo5IE= 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: List-Subscribe: List-Unsubscribe: Use 16-bit head and tail to track the pipe buffer production and consumption. Since "pipe->max_usage" and "pipe->ring_size" must fall between the head and the tail limits, convert them to unsigned short as well to catch any cases of unsigned arithmetic going wrong. Part of fs/fuse/dev.c, fs/splice.c, mm/filemap.c, and mm/shmem.c were touched to accommodate the "unsigned short" based calculations of pipe_occupancy(). pipe->tail is incremented always with both "pipe->mutex" and "pipe->rd_wait.lock" held for pipes with watch queue. pipe_write() exits early if pipe has a watch queue but otherwise takes the "pipe->muxtex" before updating pipe->head. post_one_notification() holds the "pipe->rd_wait.lock" when updating pipe->head. Updates to "pipe->head" and "pipe->tail" are always mutually exclusive, either guarded by "pipe->mutex" or by "pipe->rd_wait.lock". Even a RMW updates to the 16-bits fields should be safe because of those synchronization primitives on architectures that cannot do an atomic 16-bit store. Signed-off-by: K Prateek Nayak --- fs/fuse/dev.c | 7 +++--- fs/pipe.c | 31 +++++++++++++------------- fs/splice.c | 47 ++++++++++++++++++++------------------- include/linux/pipe_fs_i.h | 39 +++++++++++--------------------- kernel/watch_queue.c | 3 ++- mm/filemap.c | 5 +++-- mm/shmem.c | 5 +++-- 7 files changed, 65 insertions(+), 72 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 2b2d1b755544..993e6dc24de1 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1440,6 +1440,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, int page_nr = 0; struct pipe_buffer *bufs; struct fuse_copy_state cs; + unsigned short free_slots; struct fuse_dev *fud = fuse_get_dev(in); if (!fud) @@ -1457,7 +1458,8 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, if (ret < 0) goto out; - if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { + free_slots = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail); + if (free_slots < cs.nr_segs) { ret = -EIO; goto out; } @@ -2107,9 +2109,8 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, struct file *out, loff_t *ppos, size_t len, unsigned int flags) { - unsigned int head, tail, mask, count; + unsigned short head, tail, mask, count, idx; unsigned nbuf; - unsigned idx; struct pipe_buffer *bufs; struct fuse_copy_state cs; struct fuse_dev *fud; diff --git a/fs/pipe.c b/fs/pipe.c index 3ca3103e1de7..b8d87eabff79 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -216,9 +216,9 @@ static inline bool pipe_readable(const struct pipe_inode_info *pipe) return !pipe_empty(idx.head, idx.tail) || !writers; } -static inline unsigned int pipe_update_tail(struct pipe_inode_info *pipe, - struct pipe_buffer *buf, - unsigned int tail) +static inline unsigned short pipe_update_tail(struct pipe_inode_info *pipe, + struct pipe_buffer *buf, + unsigned short tail) { pipe_buf_release(pipe, buf); @@ -272,9 +272,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) */ for (;;) { /* Read ->head with a barrier vs post_one_notification() */ - unsigned int head = smp_load_acquire(&pipe->head); - unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; + unsigned short head = smp_load_acquire(&pipe->head); + unsigned short tail = pipe->tail; + unsigned short mask = pipe->ring_size - 1; #ifdef CONFIG_WATCH_QUEUE if (pipe->note_loss) { @@ -417,7 +417,7 @@ static inline int is_packetized(struct file *file) static inline bool pipe_writable(const struct pipe_inode_info *pipe) { union pipe_index idx = { .head_tail = READ_ONCE(pipe->head_tail) }; - unsigned int max_usage = READ_ONCE(pipe->max_usage); + unsigned short max_usage = READ_ONCE(pipe->max_usage); return !pipe_full(idx.head, idx.tail, max_usage) || !READ_ONCE(pipe->readers); @@ -428,7 +428,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) { struct file *filp = iocb->ki_filp; struct pipe_inode_info *pipe = filp->private_data; - unsigned int head; + unsigned short head; ssize_t ret = 0; size_t total_len = iov_iter_count(from); ssize_t chars; @@ -471,7 +471,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) was_empty = pipe_empty(head, pipe->tail); chars = total_len & (PAGE_SIZE-1); if (chars && !was_empty) { - unsigned int mask = pipe->ring_size - 1; + unsigned short mask = pipe->ring_size - 1; struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask]; int offset = buf->offset + buf->len; @@ -614,7 +614,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct pipe_inode_info *pipe = filp->private_data; - unsigned int count, head, tail, mask; + unsigned short head, tail, mask; + unsigned int count; switch (cmd) { case FIONREAD: @@ -1270,10 +1271,10 @@ unsigned int round_pipe_size(unsigned int size) int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots) { struct pipe_buffer *bufs; - unsigned int head, tail, mask, n; + unsigned short head, tail, mask, n; /* nr_slots larger than limits of pipe->{head,tail} */ - if (unlikely(nr_slots > BIT(BITS_PER_TYPE(pipe_index_t) - 1))) + if (unlikely(nr_slots > USHRT_MAX)) return -EINVAL; bufs = kcalloc(nr_slots, sizeof(*bufs), @@ -1298,13 +1299,13 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots) * and adjust the indices. */ if (n > 0) { - unsigned int h = head & mask; - unsigned int t = tail & mask; + unsigned short h = head & mask; + unsigned short t = tail & mask; if (h > t) { memcpy(bufs, pipe->bufs + t, n * sizeof(struct pipe_buffer)); } else { - unsigned int tsize = pipe->ring_size - t; + unsigned short tsize = pipe->ring_size - t; if (h > 0) memcpy(bufs + tsize, pipe->bufs, h * sizeof(struct pipe_buffer)); diff --git a/fs/splice.c b/fs/splice.c index e51f33aca032..891a7cf9fb55 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -198,9 +198,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) { unsigned int spd_pages = spd->nr_pages; - unsigned int tail = pipe->tail; - unsigned int head = pipe->head; - unsigned int mask = pipe->ring_size - 1; + unsigned short tail = pipe->tail; + unsigned short head = pipe->head; + unsigned short mask = pipe->ring_size - 1; ssize_t ret = 0; int page_nr = 0; @@ -245,9 +245,9 @@ EXPORT_SYMBOL_GPL(splice_to_pipe); ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { - unsigned int head = pipe->head; - unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; + unsigned short head = pipe->head; + unsigned short tail = pipe->tail; + unsigned short mask = pipe->ring_size - 1; int ret; if (unlikely(!pipe->readers)) { @@ -271,7 +271,7 @@ EXPORT_SYMBOL(add_to_pipe); */ int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) { - unsigned int max_usage = READ_ONCE(pipe->max_usage); + unsigned short max_usage = READ_ONCE(pipe->max_usage); spd->nr_pages_max = max_usage; if (max_usage <= PIPE_DEF_BUFFERS) @@ -327,12 +327,13 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, struct kiocb kiocb; struct page **pages; ssize_t ret; - size_t used, npages, chunk, remain, keep = 0; + size_t npages, chunk, remain, keep = 0; + unsigned short used; int i; /* 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); + npages = max_t(unsigned short, pipe->max_usage - used, 0); len = min_t(size_t, len, npages * PAGE_SIZE); npages = DIV_ROUND_UP(len, PAGE_SIZE); @@ -445,9 +446,9 @@ static void wakeup_pipe_writers(struct pipe_inode_info *pipe) static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, splice_actor *actor) { - unsigned int head = pipe->head; - unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; + unsigned short head = pipe->head; + unsigned short tail = pipe->tail; + unsigned short mask = pipe->ring_size - 1; int ret; while (!pipe_empty(head, tail)) { @@ -494,8 +495,8 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des /* We know we have a pipe buffer, but maybe it's empty? */ static inline bool eat_empty_buffer(struct pipe_inode_info *pipe) { - unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; + unsigned short tail = pipe->tail; + unsigned short mask = pipe->ring_size - 1; struct pipe_buffer *buf = &pipe->bufs[tail & mask]; if (unlikely(!buf->len)) { @@ -690,7 +691,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, while (sd.total_len) { struct kiocb kiocb; struct iov_iter from; - unsigned int head, tail, mask; + unsigned short head, tail, mask; size_t left; int n; @@ -809,7 +810,7 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, pipe_lock(pipe); while (len > 0) { - unsigned int head, tail, mask, bc = 0; + unsigned short head, tail, mask, bc = 0; size_t remain = len; /* @@ -960,7 +961,7 @@ static ssize_t do_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { - unsigned int p_space; + unsigned short p_space; if (unlikely(!(in->f_mode & FMODE_READ))) return -EBADF; @@ -1724,9 +1725,9 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, size_t len, unsigned int flags) { struct pipe_buffer *ibuf, *obuf; - unsigned int i_head, o_head; - unsigned int i_tail, o_tail; - unsigned int i_mask, o_mask; + unsigned short i_head, o_head; + unsigned short i_tail, o_tail; + unsigned short i_mask, o_mask; int ret = 0; bool input_wakeup = false; @@ -1861,9 +1862,9 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, size_t len, unsigned int flags) { struct pipe_buffer *ibuf, *obuf; - unsigned int i_head, o_head; - unsigned int i_tail, o_tail; - unsigned int i_mask, o_mask; + unsigned short i_head, o_head; + unsigned short i_tail, o_tail; + unsigned short i_mask, o_mask; ssize_t ret = 0; /* diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index e572e6fc4f81..0997c028548c 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -31,19 +31,6 @@ struct pipe_buffer { unsigned long private; }; -/* - * Really only alpha needs 32-bit fields, but - * might as well do it for 64-bit architectures - * since that's what we've historically done, - * and it makes 'head_tail' always be a simple - * 'unsigned long'. - */ -#ifdef CONFIG_64BIT -typedef unsigned int pipe_index_t; -#else -typedef unsigned short pipe_index_t; -#endif - /* * We have to declare this outside 'struct pipe_inode_info', * but then we can't use 'union pipe_index' for an anonymous @@ -51,10 +38,10 @@ typedef unsigned short pipe_index_t; * below. Annoying. */ union pipe_index { - unsigned long head_tail; + unsigned int head_tail; struct { - pipe_index_t head; - pipe_index_t tail; + unsigned short head; + unsigned short tail; }; }; @@ -89,15 +76,15 @@ struct pipe_inode_info { /* This has to match the 'union pipe_index' above */ union { - unsigned long head_tail; + unsigned int head_tail; struct { - pipe_index_t head; - pipe_index_t tail; + unsigned short head; + unsigned short tail; }; }; - unsigned int max_usage; - unsigned int ring_size; + unsigned short max_usage; + unsigned short ring_size; unsigned int nr_accounted; unsigned int readers; unsigned int writers; @@ -181,7 +168,7 @@ static inline bool pipe_has_watch_queue(const struct pipe_inode_info *pipe) * @head: The pipe ring head pointer * @tail: The pipe ring tail pointer */ -static inline bool pipe_empty(unsigned int head, unsigned int tail) +static inline bool pipe_empty(unsigned short head, unsigned short tail) { return head == tail; } @@ -191,9 +178,9 @@ static inline bool pipe_empty(unsigned int head, unsigned int tail) * @head: The pipe ring head pointer * @tail: The pipe ring tail pointer */ -static inline unsigned int pipe_occupancy(unsigned int head, unsigned int tail) +static inline unsigned short pipe_occupancy(unsigned short head, unsigned short tail) { - return (pipe_index_t)(head - tail); + return head - tail; } /** @@ -202,8 +189,8 @@ static inline unsigned int pipe_occupancy(unsigned int head, unsigned int tail) * @tail: The pipe ring tail pointer * @limit: The maximum amount of slots available. */ -static inline bool pipe_full(unsigned int head, unsigned int tail, - unsigned int limit) +static inline bool pipe_full(unsigned short head, unsigned short tail, + unsigned short limit) { return pipe_occupancy(head, tail) >= limit; } diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 5267adeaa403..c76cfebf46c8 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -101,7 +101,8 @@ static bool post_one_notification(struct watch_queue *wqueue, struct pipe_inode_info *pipe = wqueue->pipe; struct pipe_buffer *buf; struct page *page; - unsigned int head, tail, mask, note, offset, len; + unsigned short head, tail, mask; + unsigned int note, offset, len; bool done = false; spin_lock_irq(&pipe->rd_wait.lock); diff --git a/mm/filemap.c b/mm/filemap.c index d4564a79eb35..6007b2403471 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2943,9 +2943,10 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, { struct folio_batch fbatch; struct kiocb iocb; - size_t total_spliced = 0, used, npages; + size_t total_spliced = 0, npages; loff_t isize, end_offset; bool writably_mapped; + unsigned short used; int i, error = 0; if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes)) @@ -2956,7 +2957,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, /* 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); + npages = max_t(unsigned short, pipe->max_usage - used, 0); len = min_t(size_t, len, npages * PAGE_SIZE); folio_batch_init(&fbatch); diff --git a/mm/shmem.c b/mm/shmem.c index 4ea6109a8043..339084e5a8a1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3509,13 +3509,14 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, struct inode *inode = file_inode(in); struct address_space *mapping = inode->i_mapping; struct folio *folio = NULL; - size_t total_spliced = 0, used, npages, n, part; + size_t total_spliced = 0, npages, n, part; + unsigned short used; loff_t isize; int error = 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); + npages = max_t(unsigned short, pipe->max_usage - used, 0); len = min_t(size_t, len, npages * PAGE_SIZE); do {