From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2070.outbound.protection.outlook.com [40.107.244.70]) (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 A4EF820C460; Thu, 6 Mar 2025 11:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.70 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741261192; cv=fail; b=AKwSaSsMMWHjL7R/72qhxiMmcKJJdZ5ILvK0llJs0cCWMCCE69CzlUQLstbem7aixhN/WrruNNneh197xCxvTopAtc5sD7PBuPDGVvlyVYFSOhqf+JtgqVUAeNeY607WrMxOZiHdouYAO86wyZhSyC/NjcQsDMU626zqH93eN3U= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741261192; c=relaxed/simple; bh=QhDI9x9ZkYzaaG5JxaLtg3l/rXukZE96D7hAlM/Czhw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V03Ux9ZC7iVMBA/Brefqz15OvEIPTb0UON958vR6wMXFf72mtyxRuN2ESFgt14qOyvHpY/qAsm64BIKp0vcTBQTPHKNA4NvPhBU4XKV1YhCfZW5Tjif9GLTPHnhCS8o0N6sInGyhfi0mDESjjgcXo7RLlgoFiAUbbjIE2lyrCcw= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=UVyywfKM; arc=fail smtp.client-ip=40.107.244.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="UVyywfKM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I8etNqU6FG00FQwR58BTy7hBPkPSb17xE2AZFO/i3OLgTElEPiKE8zGwm3UJNiLSNqxZf3UAzidZTbgwadVJbGUnVKrqKe+lzCvIan+7bQ3VU1HF3rZ2Y5F+zApSgU2xv+TjK0k/VWjy0BXTrKtljITQ1z/6PB25s/fSd8fFwSXZIrmaRdGuTEvIywH46mlqn0zdodez0NTFJQ9gW1ERZaWwvudxCeKmL+SADd/0AbgbaLw4TL7xGv5kX6Pf/+IcVQPQgWbc1mMPNLQI1ttkd4DM6Cm/TojWd8aj/k4TjBTXMhZJOMNr576f7buxAnxmplTAjzy3ozkYHAgwfWbqHw== 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=nGJo8b/IVO4Vpp/wFK/cKL4EIBmnd/uSe/g9Q/PEGGg=; b=QQY4ZW5Ke3HwL6DbOwSg9d14s1/mSo11FycmdSnEHuM4MLn5LbGjPzbfRruQa3V8Tk6ZoS8XwxYEvqQ7lvfMYWr5RX8aw2Ztw0O6qsW+av8XjqCXIGFNIf+RHnh69xF+NbTjDXr40foSxqM3Fr7qHbR/f/Yvn02Vm0NUvw1D85Oi9mWUJiwxtxJRCy7/iacHmB22lAHvnONDWc7SmdkIvjQK9vrUQY8MmGj/c2wKjwva/CcBMfbSdqyR2wQpUmTzD5ONukMbiIE77fUEhdugdU8MZyo8pTUbrAYRXzYfL9bUEXmH84cm4+OD/FZ8TeLNprVnllESwkGMjN8kpM6Opw== 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=nGJo8b/IVO4Vpp/wFK/cKL4EIBmnd/uSe/g9Q/PEGGg=; b=UVyywfKMRCFSHy6+Yln7BdvUbal7vBfGfX7wcckQIts9NjyYH2u54QC3jkWRGaOUt9iEnTBrwVGfb9GPv6BMTOD6gf6RWSBnqoosK3g8JClrPAJhdkPSx4mFB4yVlbMELS/SsuRDIv3wY7qDqcbXZ88SfeVKczs8XhOWgnZti6g= Received: from DS0PR17CA0012.namprd17.prod.outlook.com (2603:10b6:8:191::20) by BL4PR12MB9482.namprd12.prod.outlook.com (2603:10b6:208:58d::19) 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:39:47 +0000 Received: from CY4PEPF0000E9DC.namprd05.prod.outlook.com (2603:10b6:8:191:cafe::73) by DS0PR17CA0012.outlook.office365.com (2603:10b6:8:191::20) 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:39:47 +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:39:47 +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:40 -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 0/3] pipe: Convert pipe->{head,tail} to unsigned short Date: Thu, 6 Mar 2025 11:39:21 +0000 Message-ID: <20250306113924.20004-1-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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_|BL4PR12MB9482:EE_ X-MS-Office365-Filtering-Correlation-Id: f015c1c0-0590-472f-e312-08dd5ca39910 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?JMP8JP1mrOJ80elsX8BWvnWl2I24GCz7BhxhqBYTejiuIq7FGT3zFwyapcwZ?= =?us-ascii?Q?ci/4GkgTBBz89srqWeqeZFxJayZUO1d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?Q?0cZ8rzg3Ehf2KZusvNZbklriS1KSdD7I3KKBM9STqYnynV3BI8rcTgs45lya?= =?us-ascii?Q?CDRvsl9IjdeRchxOfQrrz+hnj489CymasFIZsYoGV9hszi+9qtwR2KM2Y4dA?= =?us-ascii?Q?ibKj2TqI/w/p9nhjB2tA4au02S5xR3PnUT8ltmLVCKjcQ/cHrvx0C9RCl+z/?= =?us-ascii?Q?t71XhHZLp9coy/6euSft4xIzUFMkkekcvV2MqM2pBPj/vOiNGT5xEV1x3gI3?= =?us-ascii?Q?g1C0PLkLp0srqY15yzvRJaLV+rokdPJd1hR8irabDSSUGnZ9uHfa2IcYsi3V?= =?us-ascii?Q?hwFnOy4/tO2eWW5PKutERw41+edHh6v6nSKIJtkI7TKtXFstgSG+c94Ua9ys?= =?us-ascii?Q?+1iBpEqX1+euusogDNymG2XhLB9pblyXAJO9HqeMmwniS0zA706yLB+Xgcst?= =?us-ascii?Q?8G3rQWPUyACx41ieC0pi12eDt7O/e0BqmtwWHu28ku76Jhi8IHpAZQDGciIl?= =?us-ascii?Q?6t3cwQOYroOer6dlTnjxlOP3RLBHeANOKKpuxChMRIgP5tAwgDmYsPaO7p3F?= =?us-ascii?Q?mZA9AfJtX0HbWCgMMjhuLYGwoS/P9Vb54ZVY?= 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)(36860700013)(1800799024)(82310400026)(7416014)(376014)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 11:39:47.2048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f015c1c0-0590-472f-e312-08dd5ca39910 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: BL4PR12MB9482 Here is an attempt at converting pipe->{head,tail} to unsigned short members. All local variables storing the head and the tail have been modified to unsigned short too the best of my knowledge) pipe_resize_ring() has added a check to make sure nr_slots can be contained within the limits of the pipe->{head,tail}. Building on that, pipe->{max_usage,ring_size} were also converted to unsigned short to catch any cases of incorrect unsigned arithmetic. This has been tested for a few hours with anon pipes on a 5th Generation AMD EPYC System and on a dual socket Intel Granite Rapids system without experiencing any obvious issues. pipe_write() was tagged with a debug trace_printk() on one of the test machines to make sure the head has indeed wrapped around behind the tail to ensure the wraparound scenarios are indeed happening. Few pipe_occupancy() and pipe->max_usage based checks have been converted to use unsigned short based arithmetic in fs/fuse/dev.c, fs/splice.c, mm/filemap.c, and mm/filemap.c. Few of the observations from Rasmus on a parallel thread [1] has been folded into Patch 3 (thanks a ton for chasing them). More eyes and testing is greatly appreciated. If my tests run into any issues, I'll report back on this thread. Series was tested with: hackbench -g 16 -f 20 --threads --pipe -l 10000000 -s 100 # Warp around stress-ng --oom-pipe 128 --oom-pipe-ops 100000 -t 600s # pipe resize stress-ng --splice 128 --splice-ops 100000000 -t 600s # splice stress-ng --vm-splice 128 --vm-splice-ops 100000000 -t 600s # splice stress-ng --tee 128 --tee-ops 100000000 -t 600s stress-ng --zlib 128 --zlib-ops 1000000 -t 600s stress-ng --sigpipe 128 -t 60s stress-ng did not report any failure in my testing. [1] https://lore.kernel.org/all/87cyeu5zgk.fsf@prevas.dk/ -- K Prateek Nayak (3): fs/pipe: Limit the slots in pipe_resize_ring() fs/splice: Atomically read pipe->{head,tail} in opipe_prep() treewide: pipe: Convert all references to pipe->{head,tail,max_usage,ring_size} to unsigned short fs/fuse/dev.c | 4 +++- fs/pipe.c | 33 +++++++++++++++----------- fs/splice.c | 50 ++++++++++++++++++++------------------- include/linux/pipe_fs_i.h | 39 ++++++++++-------------------- kernel/watch_queue.c | 3 ++- mm/filemap.c | 5 ++-- mm/shmem.c | 5 ++-- 7 files changed, 69 insertions(+), 70 deletions(-) base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43 -- 2.43.0