From patchwork Fri Mar 7 05:29:16 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: 14005958 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2049.outbound.protection.outlook.com [40.107.220.49]) (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 71E3B1922DC; Fri, 7 Mar 2025 05:30:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325403; cv=fail; b=kJJVFVB+vnoX4Q4OmFyfrCiY0pBWs7WyyWJouvmLaU0Fqx9v6ONcfAmuV2btGe9J07NLj1X5Ghi39zwPcCqwRjZv1uW36FZg3aniElOCY90p1FtPUybWVPKj+/O9W4Tbt5INBoWxFwfBe33LzUNF3eshUGcYQGT6oha1Jx68r6M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325403; c=relaxed/simple; bh=RHQszQJBCkYI8rF22lGfiCrZC6wKb4h9A1ftK6cIElA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aHHBa6ZOGm07V7eZISIqLggW9zux0Axxavspc1i0NXUj/QqHUYhfcqGXeXKitPWjzM4zNorBNGVEbv3xGge8AWG16rHiHX75nfzBj1W1yPVDeoe6i8uQ/OuWhtd/1O7kOcQLkJK4SuQmGr3yGTl6f8vF3vIkvmt+jQy9ArtUCKM= 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=Qn54MTsy; arc=fail smtp.client-ip=40.107.220.49 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="Qn54MTsy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iGaabzeDk4IadjDXN7HFhMdwwC6yTWezGnW4H04iEPDjng8b2Ji9UMwygdPHGrCDFr04Qwsrug3FSHuOGve1PbjNv8NvQI6MldKOLC2t2FtH2vTRyJ9Vm27Jns99NECleFB1XdIZi5nfa91r2Fzrry7ceTM0Bsz65bJGVohWYvO8t39dru48sQwAi5EizILCOc6VcOb4ftR8ZROBUHCO81u47mZSU7ikdg+lLndowcivVk5PfOq8q0aN3b58mOZCvuNUmnG8z+j+QrkphjU/zDsU49Yeo9bMykXLxONfuO/q/OzU9LNmtIwrKmaD3j024lIUsSBMZlPDI/zLqF+axQ== 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=v4dq2kVhCacGMXsY+LnxsOmAOHoZ6wqtkfgmdeQqVAQ=; b=CiTWsihHwOvrqLgCg3MK1ZCYgGDJTNdWZQ1kxYpJHbvzHhzgOKIpRJ9p6jmEGSQmeIaU++hbsWmVOpjrCkmGJmuTC5jjybHCNvPSRTbq3ZeqUXVjyV1C0zvUHcNABCgkbduwCMduyxgSPo8wQ/dXBGxLoGbSdSAYDqHsT10tfVTrQM+P1VQ/kOyTZXP1tFZZrYcjMp+PMebq26wyzoVcXUHgcS4pY82fFm818GPVoEHCftM7lWWAcU38PFssvTkfpUHrJNbrYldO2RaV1Fyiit9m7vf0Er6mXgy4J4tMcC/M5/OSJTqrRYolPz69eWjSKFyGjlITeEqETpH69fIhUw== 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=v4dq2kVhCacGMXsY+LnxsOmAOHoZ6wqtkfgmdeQqVAQ=; b=Qn54MTsykmvSccaXjwkJ7nV9VJEqgMJVknW6KrybmT5j6lNzzfKx0s83KcHByMORJhEcUcEU9/mf/cPl5xIBi39uSl01b6g/wSVLamtpvgjJlilYE7gpE/SdESIqXdQt2QwejFhV8d5gEMOKEf9atGXhx8ecjhSSOVGKDvlliPo= Received: from PH8PR21CA0006.namprd21.prod.outlook.com (2603:10b6:510:2ce::18) by PH7PR12MB7236.namprd12.prod.outlook.com (2603:10b6:510:207::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.17; Fri, 7 Mar 2025 05:29:57 +0000 Received: from MWH0EPF000A6730.namprd04.prod.outlook.com (2603:10b6:510:2ce:cafe::fe) by PH8PR21CA0006.outlook.office365.com (2603:10b6:510:2ce::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.14 via Frontend Transport; Fri, 7 Mar 2025 05:29:57 +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 MWH0EPF000A6730.mail.protection.outlook.com (10.167.249.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Fri, 7 Mar 2025 05:29:57 +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 23:29:51 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Alexander Viro , "Christian Brauner" , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , Rasmus Villemoes , "Gautham R. Shenoy" , , , Swapnil Sapkal , "K Prateek Nayak" Subject: [PATCH v2 1/4] fs/pipe: Limit the slots in pipe_resize_ring() Date: Fri, 7 Mar 2025 05:29:16 +0000 Message-ID: <20250307052919.34542-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307052919.34542-1-kprateek.nayak@amd.com> References: <20250307052919.34542-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: MWH0EPF000A6730:EE_|PH7PR12MB7236:EE_ X-MS-Office365-Filtering-Correlation-Id: dab82b50-eb0c-4a69-5922-08dd5d391946 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: JnzYpyzBmyQxmY4EgcJZrdP5C6RPD6MetDbzuwAw0po1AN4ffcqwtVn/qNhye50xgkxDnxw8puWNb1oOESiJ/JQTtKORBDjeLKgz6tf24G4ahBYD1jGsEKDBtQLacjfAoeAPi9dculM2gwl1lzv0SjTZZarzDcNr+ng8A+6MgJWe6ppeD4YfV978ZeDHe4k24IcZ2vrSt43F886jdgvnt2QwwFrqPKp9SpPPz3lx0tNdE0Yz+ZmK2mjXEgg0m3objOB+if/r4F5sBIXOoF9XGfjPVA9bF5fBtLWCISuyqHU0BI+L7Qfyqo6t9c92trlg+MnWYvBuXXnupR90L+pQdrEI4nfL429hz1BtbPhvpXPoxihGjonL2UKW/FZh7pNL5uKnMqvCllswhrc6zk4dXHu+oGdZXmYiVDtM6sQLQ1NFWD98ztmKTP4bHrloD/e6VS7zkTV6zNH7mvAh1+cJHsyPNeXhRLYRx1VTEEc58t2Lrf0P/Ho3svCC0YzcysJC9IaIuoh0eiH6t9fV9to/2idnOuvOv85S+X7ZaQ2LNdTXEnzgJQ2qXig7hxygW9qB6wCkjikzz4Lu7M3eVfu5Df2lXdndxqTaJron4RuiTuKcB5Hy4egTACa4xBqWYFXqviXZk+4bcsrulpQpLQaA5+vbdY8IcTmzQcbsind4gzReq2CE4PMxFfqFle4CV005vE9I/btY55nzSHFh1eL5Fb9YSzUmqcgCTa3tBhdoyf2O58z7S958FeUsD4kKPJ7AQvEKkKxkZTPYjZ0G5dM//1QJG54UjuF9Ms3Y19phN9sU0Xqy6tYJMV4WUR2V9tC/gvUeOeY7Q4VMeeZzb8deA93Wg9IdWqiZQJG8HSdMs7y53zQEMLvmUIonWqscT8MjIL3uWaeJ7fr8JKm67kgt3WJsC8aRAOhRDFIkkXZOff/VtG9dqFon/ZlRqxYM3HczYpdUgxI1RpRMiXcl+QwTzJ5l8kj+44uDcKSjXVrq4NvN3ZdHUKub2RcOtbecT1LTecjAsB1QZJT/9ZXhRb0ZSl52I7LGix9wqqc1KXh3q6BeGehrcSqch5/p7eiXJ5YJMTY8tRUNLjPIj8+vlUNADn/rTqHD41A6zJv2+0KhAJHdCWUmD2BbHFYxmDJI1lsZ8Kd9Tx0ITqFObcek3c41Clkjm16rvQMMwD8ax/L6jS+7OQTeT9uxcoq3flPunmVcVG9ek4tSWe+fD9/HOA3+gnOG7yCqMRHPJYg+csYhso6ptmCqlMKY0UabGZaYTL8dfCqlyadVFpcUBdtFmDMBW8CsjQ1aj59x85jPwRaqj9zDtLx/kuA+z5pc/7jGfd9BOnqegYpm+d/Fhm192BOLGeDfWtzK2rSU/hR8H+yVve/V9qu2Mvz8PliRFc2ErcuIwaR/D8X7Ua6/OcPFlOzy4a9q6zDZx1Z92MJYET5BzKTb/Y7Q9ZjoTFgDLsKCHc+r2TWH6XH9HWUGHrDhod6LF/2YC7LUhsri1lUTZpGDLug= 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)(1800799024)(36860700013)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2025 05:29:57.3319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dab82b50-eb0c-4a69-5922-08dd5d391946 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: MWH0EPF000A6730.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7236 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 related calculations where the pipe will never appear full. Suggested-by: Linus Torvalds Signed-off-by: K Prateek Nayak Reviewed-by: Oleg Nesterov --- Changelog: RFC v1..v2: o Use (pipe_index_t)-1u as the limit instead of BITS_PER_TYPE() hackery. (Oleg) o Added the "Suggested-by:" tag. --- fs/pipe.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/pipe.c b/fs/pipe.c index 4d0799e4e719..88e81f84e3ea 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1271,6 +1271,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 > (pipe_index_t)-1u)) + return -EINVAL; + bufs = kcalloc(nr_slots, sizeof(*bufs), GFP_KERNEL_ACCOUNT | __GFP_NOWARN); if (unlikely(!bufs)) From patchwork Fri Mar 7 05:29:17 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: 14005959 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2077.outbound.protection.outlook.com [40.107.237.77]) (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 E8D4C10E4; Fri, 7 Mar 2025 05:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325422; cv=fail; b=ZM+hDocIDMN2g/pIOVh5VoHasLtoRHOzuwMVLrDbarXi3wKvxFuNpPaJh2B0c+6NF6c8bRV0ULbKG2DxMRYUS9lx3vvfTaQMzv8fQIAMmYSlsRRfwe5skNRI3lwRkHwmxWJueabpSoTdjiPCTizXqhPxSE8viCq65GmmMpzroWA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325422; c=relaxed/simple; bh=xKSvsqplKs397uvJ86IP99n0l87p+1fQl/qlWBIXo3A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WxBOWBUgYR8OIJG62q0TqkS1g84vBuUzSMKltoxQZaPFLKFOm+KUWtcDQTLIFptxjv6wmG4+EVIVvSVo9nz2cqHu1aT9S1yX6kTwxlL2xvrU+jTwYuLpK3UIMTPfdhh/U72MRtNhOHuFaPEPzjtJCoDSF+4pLqhIH95hqcQX2tc= 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=e5+6qiMo; arc=fail smtp.client-ip=40.107.237.77 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="e5+6qiMo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=caa5GJGdLgxGhE9hqfFZ3zWGd5PCaD09BJi6HpPkT8d5RkXiaqG2K0hKq/4BKaXs6Hin0C4DolK+EYu0hrVnBTGXbwxkEaPHL2UChpAFZvhoueceTryr6NGsRHZtttkZQR6ltw8fmTxJgRZZRrGVQcvMwehlgYrhwRK8iLNVqRblApBXBWfoufN4LEq5SR1NjTHW3XIqyB4TzxiHJhx0dQmzggDPPGlTMvii5nBSn4U5/2JOe4xiBcax2Rc2qCtOb2yynEjWhOyqmqb7lcsRZkmNqADWT9GUuMgsFNuuZyo4uLzJZ/+RqRJDB+VA6aU1UJdcPAvn1QX8Q9q0LvGftQ== 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=iiP2qiR8gLuSVVOWR0tyRnMR1UGprbqzHrSdraYZfnI=; b=OS0sPe5vFbeFwB0+Dw7KXD44D56muJbzYGcvXFQlMTy6e7gyrxIU2bjs6miw1GtWQb+YKDSz7EQqXR+4lleHB3JKN3HS5/pA5ccA/le1KEw9Ha+AASPflp7PKepd3R+i+MLAIt9ok5ab6hrDxCbS2uIyx1R+B4m3GNQZp5ZlCEvxB7wwcE3iJnz9bdHbSBb4b0T9PZxPwTRyFpl2RZ1Q+/tLeqkX/5NvCKqk38S2M8U8CHjkzfWz8MXOKykGx6DQ+M6y/f5Zvix4cs3+isVcuw19xy9sHAn9KkH4c7BTy0kB87dOLNx39FHf2nYvubvUVB3ligRoZnEoalfpyMDxGA== 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=iiP2qiR8gLuSVVOWR0tyRnMR1UGprbqzHrSdraYZfnI=; b=e5+6qiMozXxUH2W8lzR6OyfDzYNxTQ2kIOmlQMXYlhqMSa+ONlfcwSrKhZsukzyAIQ0LxNI6m/S+aUPuyO+pD5/h3+eKJjlvpXJ+UXJKfhWRLDvVDJ7sj2sgJP7hi8O7L6/EpsAlGiJeSEfd7U8fSVuZ8EgNQa2W9Tt0BYBahqI= Received: from SJ0PR03CA0106.namprd03.prod.outlook.com (2603:10b6:a03:333::21) by PH8PR12MB6724.namprd12.prod.outlook.com (2603:10b6:510:1cf::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.19; Fri, 7 Mar 2025 05:30:14 +0000 Received: from SJ1PEPF000023D4.namprd21.prod.outlook.com (2603:10b6:a03:333:cafe::f) by SJ0PR03CA0106.outlook.office365.com (2603:10b6:a03:333::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.19 via Frontend Transport; Fri, 7 Mar 2025 05:30:14 +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 SJ1PEPF000023D4.mail.protection.outlook.com (10.167.244.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8549.1 via Frontend Transport; Fri, 7 Mar 2025 05:30:14 +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 23:30:09 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Alexander Viro , "Christian Brauner" , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , Rasmus Villemoes , "Gautham R. Shenoy" , , , Swapnil Sapkal , "K Prateek Nayak" Subject: [PATCH v2 2/4] kernel/watch_queue: Use pipe_buf() to retrieve the pipe buffer Date: Fri, 7 Mar 2025 05:29:17 +0000 Message-ID: <20250307052919.34542-3-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307052919.34542-1-kprateek.nayak@amd.com> References: <20250307052919.34542-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ1PEPF000023D4:EE_|PH8PR12MB6724:EE_ X-MS-Office365-Filtering-Correlation-Id: c0ac77e8-fc05-41d9-0e82-08dd5d392356 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: wVjEC7J50k8HB/y4KkQ69VE6+AsUeAvkE6KsUusEeBq7lVeEVA3+0dalaRL4xq4RoD4etUScpM4xwa1ItqRk6Kal19d6DIzFgzEv0u4FktSPB072wgOOwPDhX8/FEO+OwMj84ZA8idpLXQiycmMIhPdHZeW5As3Q7inRtDPnK00OvuQ8/OHRBJ57OuJxAPnbB8XnWuyvHd0kENA/UddC+3VHh3Gx95d1+jfnZHTxsByKdG4uplz4k/Zx3SLq5A4oSDwn/NaOHkUbm2ZqRThYOh9hzQV3sDMdyB2YE/Ed/KZ2z8dbvq0q52Q/MvHKO8UWBrIn4iXZVVNjBjbLqzJJxPgpGHzrv0nK/kwFuaFACg7g3Sc6kC2YaBq88DLbGfozTA4yf0ZgzhWQEYGAB7liSYmlGvP2Jxkc90jQWC17bHX0iyd+4C8dOE2pwjp1GDD153vxI7yT3v8Gjhs71jAl+3O5o+EtcYjfu+jSTTck1Uyh9nFvLXAQ6Fc4WvNCPtoNZ8gtkDNfM6RR2PwoUqM/FmL51wLT4MNXwdHHiIjZJupL/wjw7nTmY+Uh573yTaM1Yp9MMjqAorKSfvj4B6TzNTbbQCaZsxTHbGMp+kKQrmA/nn0VTqBnZUB7OWKStl3hOHRlRY4qw2MyTdk02ZarETDtYDqkbrjp5QlEWVsmkpdHSkKxPSW0xwlh0erk1pncLcw98JTX3bz7WcBDCUzLqSO19SqJiJdngFZph96vhxbAHJqihqcNPRLArfFLEM4cPlw9iAySS/4odIbMMSVPxlB24SXKvwfHZhfCCgWjUyVAL7YWpwk1P2KkBSMWB8w3hpCugqmBdmrJ3mmiV2s60rg4BOr7KduJjumEg0Ez+wCHG2ANJz58ePQjXKUH+O5JO0NQhbKNOMcQjxvXPXE96HbOxUCViunUXLuugjrjBFuPA4OlxhAtU3Wp2WQcdptE09E/H26jIqC1qAfzZkzLa8PqO0bTyrIOWqJhzkAIPfa/GabZ2pEKPUYqY6yL3JygSdokXT88g8mUf1cruckOt/vT8IfQs1wTQBJtgCFzB7uCjiC4yocuIiXNUKmzsfOvi64xoBH2tNqK98DnsXXRFIWsSONZSee4ePbxn39/xNfrjOyFt0+fOwSCVk2Y/ogyJ+bDZ1JpNBckPFkyaIsPEZMF5HXDVtlRbWWOVTHpyBdhmYvJcXFdRB4d0JbxTw7FVdtRO4+kkXoajQEtqwo3FmGLubiReZF9G66p2hbfXM3MrqpP9zB29WN1VY/gScvnJP+CbSH8QFDwCbAN1Oi50+vSJR49IZVI56z2sCveqnyGvOc8IpHtbtCVrXzlVi1r4cc8QW42V2eEK1SlQQg28aROFIMhXmwLNY2ej1l+BhWWAF7m4+vpJXeexjB+GjrzklJsaqBeyjq9fv3rCv7u/mmZoPZNPGTeagn6PozFS1d9HS8GQC9xIGDcwkkFfx7R0pFaniVJTxs2SwbLUAnfTw== 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)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2025 05:30:14.2902 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0ac77e8-fc05-41d9-0e82-08dd5d392356 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: SJ1PEPF000023D4.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6724 Use pipe_buf() helper to retrieve the pipe buffer in post_one_notification() replacing the open-coded the logic. Suggested-by: Oleg Nesterov Signed-off-by: K Prateek Nayak --- Changelog: RFC v1..v2: o New patch. --- kernel/watch_queue.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 5267adeaa403..605129eb61a1 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -101,12 +101,11 @@ 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 int head, tail, note, offset, len; bool done = false; spin_lock_irq(&pipe->rd_wait.lock); - mask = pipe->ring_size - 1; head = pipe->head; tail = pipe->tail; if (pipe_full(head, tail, pipe->ring_size)) @@ -124,7 +123,7 @@ static bool post_one_notification(struct watch_queue *wqueue, memcpy(p + offset, n, len); kunmap_atomic(p); - buf = &pipe->bufs[head & mask]; + buf = pipe_buf(pipe, head); buf->page = page; buf->private = (unsigned long)wqueue; buf->ops = &watch_queue_pipe_buf_ops; @@ -147,7 +146,7 @@ static bool post_one_notification(struct watch_queue *wqueue, return done; lost: - buf = &pipe->bufs[(head - 1) & mask]; + buf = pipe_buf(pipe, head - 1); buf->flags |= PIPE_BUF_FLAG_LOSS; goto out; } From patchwork Fri Mar 7 05:29:18 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: 14005960 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2050.outbound.protection.outlook.com [40.107.92.50]) (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 4A71E18A95A; Fri, 7 Mar 2025 05:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325439; cv=fail; b=bC8m4NW6xx38gObhc6E3iq/bTj2KCSArhLO6c4wBHvlM4qUe7SE0Mqryf2ZjrXuOTF7YNwJQ4etS4MX960wO/p4qG3x9Ci/5DmDXPKajKkjvFIqdeTE5X61oaVp7OP31hD+0oU/l8K7bRJC+Tc4g3A9M4NGfwd6mVhV5wURziRs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325439; c=relaxed/simple; bh=Q73WcTB2+VlRXzqa7ev84/LZi527mPNM2QyejGvA3+4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QId27ap56DdOCntPrD5GRWs5ZNcUhc1drHc5C25afc6Dm0vF3KSf/cBkVlbeljPvAo72kGcKqN2025Iy9G5n+V9rYETdaKRA7l63oi8CbgfdYmvUhokFzR6xH4EYPSPVCKid+Bc3gGQ/C5Ot8JwFMMPzaNrwk2OCFooXDc1rGKw= 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=hEV8g9Sj; arc=fail smtp.client-ip=40.107.92.50 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="hEV8g9Sj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hUX82IsCWkEAnEMdBoImhHYIU6JyzTlNTJuEmVKoP3fVtrZTk6vycZ7iq5CV2YNJvlZT2TiqM8sj1pvCMVDTT+wOgxBJm6wYBwyxxrkabklkeJZDL8/qD8eLhkLTs/8GrUFHA1aOiNEtfQXEigN7tg4W2zhmrBm/ViGknxuAvuiFCoa5EA8ChpIX7YHb8ufqkgtizBvde+raGSvoOes+SMOxv8bBlZXNWyT6Oe0+ugyCUSepje3mSL6+KVGZufyQAuhS/941noDCUE5yfaMQGHioKHFLnN9yxxr5VMFJhTCBOxEAkPBNxwKSsm7ilE6zZA233ZDWRrwmdXZ3TtcUww== 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=4VfVGspq/P3N40fr9urCp2EonRGH1D/vz4xu2onNWug=; b=SPCtSOyAMrU9+SzdI4bqPf4a9fNj4mVKDAden/ptkEuVhAbQ2Ac3psfVoNRsGB/phhmEO1L80TFB/XrtqYu+/ZDJ5fb4s7cPwt4Ssz73QxttR0haon2eB1lNTkWrD5+snFpoH2SIYISg3o2m3XFFE8bUL8EEMeeMkGDm2MIoTY4lOlwRnafngrujI3ENTOWGLI5dz9szcJx0YoftspTKB0dr9i88KLBucAFO7Lc9k2xvEoGVD9sLSH5qL202S+LOf1tSQm9Q2a0GIke2C9IkUXu2k48JmZ7jPZwU0IQhw9GCB5oo8Pq/qw8dD160qwkyuAFlXtv/uBwV8K79peQauA== 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=4VfVGspq/P3N40fr9urCp2EonRGH1D/vz4xu2onNWug=; b=hEV8g9SjYpiv+G2hoDQdW/pdYyOvr1IOeuqzk8AJqOq1vmldbpX1lQhO6PBRDCjYydxJY/f2jKtx7cRtiFsSCtirVeGOXDeSqDk08fGIaNWYO1qRSiQz2EQZt19XU8kl7m9u4TFNNzlgY9ZV1fuGV7iew8aV4NdyuVEwnWsLCnM= Received: from MW4PR04CA0325.namprd04.prod.outlook.com (2603:10b6:303:82::30) by IA0PR12MB7649.namprd12.prod.outlook.com (2603:10b6:208:437::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.19; Fri, 7 Mar 2025 05:30:31 +0000 Received: from MWH0EPF000A672F.namprd04.prod.outlook.com (2603:10b6:303:82:cafe::30) by MW4PR04CA0325.outlook.office365.com (2603:10b6:303:82::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.19 via Frontend Transport; Fri, 7 Mar 2025 05:30:31 +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 MWH0EPF000A672F.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Fri, 7 Mar 2025 05:30:31 +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 23:30:26 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Alexander Viro , "Christian Brauner" , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , Rasmus Villemoes , "Gautham R. Shenoy" , , , Swapnil Sapkal , "K Prateek Nayak" Subject: [PATCH v2 3/4] fs/pipe: Use pipe_buf() helper to retrieve pipe buffer Date: Fri, 7 Mar 2025 05:29:18 +0000 Message-ID: <20250307052919.34542-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307052919.34542-1-kprateek.nayak@amd.com> References: <20250307052919.34542-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: MWH0EPF000A672F:EE_|IA0PR12MB7649:EE_ X-MS-Office365-Filtering-Correlation-Id: 202d39c6-833a-4a06-4771-08dd5d392da6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: JzwlEVZH8MPXplRF6mE1H7n63I4/DGIWxLJye01myOlVcjZcnRzXgPHE9aD1VP0Vaq8NM+XlKSNBtFxN6GCTpFdGj7gDe4SGLFVWpcHwbobR7iBNo5f/eTDbpn2yC0VXunQptVW6wc129H99+nUFQXCY/YpVPrS0EfQ3l3UkY7yHhdeI/fTm432cBFeMNIiQSyqjg/C3+fH5YJI/3nbne7oAUr3Bofbpl6C4XQWKyKJh9A+TOERg75JxApGHZRVPbSNcbWBubsxMZYsjlG38bHYWlYUt5RoLW3EIQOn+VRgBF8T6ZPIdrUtky8nD9xKQyccM527xmmP0HlITUmhe9MJQg0hmNvugjsyQR9WR12wMT+TX+H2e5GWslIQhPur2mt5MvPgukOOCpPy5AQuF8t65XUg6nRd1FYt5uxpvx2RM50NreQTN6ipbJ9YKOGqz469PrEQsAhuECPLdCpJ3XedbNZNb6D8MDYJtbXOBq7CtmFEqxjPjdCUkd5f2nC71fxAQti+9T7yuj3XNvJvgSXyLBjjKuZ4RLVlTkDtE5ham8eQLoznibvJzfrRLDRVpve1lmj1M5+vr6XLTU/Q/zKXHMFG/0Ix9Zcze4TuKsrfuOuCcjvfhwPvyCBa0vtK9ykLuM3m/l/7NU4kRpstO3/Cy1ho5+dPypqL/rXdLZayNKiwHx7ZZNYXXbiKcG+qjjSJnCffT7rd/Sg55pRy7mE6/snaQnpplCIO/Zla/goB3QM0r9NLczXWln5B+ZCijm/9yyl7O29ZxWGlSjPadkhET0/KfYgK5GRzBbMcndcdDTLIwCygnhwpzoHu90sjRkpxm8c/1J1+6O53dGX0ecYelSpTlSwn3qa5/Uj1loju9rSqzqnuBN9YBuGXWaQ3/HPVi5usAANDK58YbSmvSjdJx9MnyjAOINfrGp97bopPjFPpPMxsLFPANDc3WMZdnvYfPl2aNH0KEAGWP3fYQ5nyFfmy+B0jGR9EI1z7oXlyCViDQdFoj85BX034GGgOym+J3ego9pozqNC6HYgo23od1Rs48ROrG7+hO4Buym2OdJSpwFnf1Df29AZfDNRkVKAvrAbOSpaWXTHF4bgjqAMC0i4wX9lyy4VTw99P2BZE24FK2q4Obcw5xHoiItfAdvJiuYoPBeoFo/scPYzCvQXo4D+5FDyAmYEJHjYfq3oDX+5kE3R0Ztvanyu2dBjF7jp26Df1CdHv0ycc9AyFzxTrCP1/9kKFxyq/ELdS0R7z/IAnBT38roppLt4jOMwgStlTc3r0VNvA+Dxk4b50/NvbrRfSrgDvHXjXcRylrN3reMLkZiezjExSMQQgRWtwe5AD4J/pBEWqM+8aa97kD1ZoZEOMiN0t5oPQqZrbvvFmpNqi4F8GnRJEwXn0nLxv2rXI034OwtMCg3HtcUu/rfNJM3TCfpSUBVzBeIzPMk2Zk+Dk43hO0kr6GCnxueZvAD3XvME/XvSamAHzKcKGI/JatavYYGQImbykU5pzvLDg= 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)(7416014)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2025 05:30:31.5306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 202d39c6-833a-4a06-4771-08dd5d392da6 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: MWH0EPF000A672F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7649 Use pipe_buf() helper to retrieve the pipe buffer throughout the file replacing the open-coded the logic. Suggested-by: Oleg Nesterov Signed-off-by: K Prateek Nayak --- Changelog: RFC v1..v2: o New patch. --- fs/pipe.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 88e81f84e3ea..4d6ca0f892b1 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -274,7 +274,6 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) /* 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; #ifdef CONFIG_WATCH_QUEUE if (pipe->note_loss) { @@ -301,7 +300,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) #endif if (!pipe_empty(head, tail)) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); size_t chars = buf->len; size_t written; int error; @@ -471,8 +470,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; - struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, head - 1); int offset = buf->offset + buf->len; if ((buf->flags & PIPE_BUF_FLAG_CAN_MERGE) && @@ -503,7 +501,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) head = pipe->head; if (!pipe_full(head, pipe->tail, pipe->max_usage)) { - unsigned int mask = pipe->ring_size - 1; struct pipe_buffer *buf; struct page *page = pipe->tmp_page; int copied; @@ -525,7 +522,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) pipe->head = head + 1; /* Insert it into the buffer array */ - buf = &pipe->bufs[head & mask]; + buf = pipe_buf(pipe, head); buf->page = page; buf->ops = &anon_pipe_buf_ops; buf->offset = 0; From patchwork Fri Mar 7 05:29:19 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: 14005961 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2043.outbound.protection.outlook.com [40.107.220.43]) (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 CC8E8157A48; Fri, 7 Mar 2025 05:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325456; cv=fail; b=eUxILQQbj/88PEwIPj4hbgX1972lB0c9QKXc9kIsLoliqbQnD5lwOQMa6hwGDb06oeYpn8USnIeB0b1wXEi61N1AfzL8jcmdnxw2QoagV/hwPc/AODUrBkLUkW3BeJaOPOoXdB2Ns0GoCdN0PIzMJqE3s9jnRBnyKKtc7GqUUao= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741325456; c=relaxed/simple; bh=A9d/q1YpQvLlyUbELP2m65tW8cqxGx7CgZxDrZDYz54=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rPeog0zpqORn/9b1Xxi9trQrEoObwLc0EIgVYR3WMuB+CP6pHhscUOw1ey5//WtWUCAuBEUXAS3UfJTdTbzA4tvJtEK2EFavv9XSqUd7a91EAnnzMpVDGouhgChzbx9tzE31RIOrvg7MUCQs9+Uvny5LwMWMld+m/0tHs+Nitps= 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=wZqWOEGF; arc=fail smtp.client-ip=40.107.220.43 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="wZqWOEGF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oZ0Ifu1dT/zK+2KWEd+0Gi7zARp8dPYojFSe404ocWR3Y3OVAMaa3DF9vdLN4A4dKGWTJXWrYk4mfVOYz1KEFyMUY2B/LTfkr6dBoTvvtV/J1tDM2AUZzbxgPIE7gWBdhxrqNawCjCm0Af9IB7gO/JxSGjbV5VD9fRGFSHfRX260GqRbB6ddS74jemPWRt8sl72r5SEki5hxhiVlagYA+HG2Lh23DS8tN5OQwXkabgI3R7PVz3whuaLeixYKbT6MKMRNPPToe4suSnXQBlj4EUaYCBsDNQu4YOtKVEZFjZP5N1MVjCqfcv/a07Giycl6K+SgRjVUyO+nzwqKm1QeWw== 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=U/LEbqWXu9+405LHQ0kI8kGwEk0uesBShmGPBh9BRwk=; b=ynUE7kt4mq0qPw9YupWyTVLocVlprgo7JtDQKmqH7Zms84QtivmPpbibpSUmYp28Hv4295b1Y3Y+mtTHSliHvGRsOHhL0hnF6bYOej9uXLXCtOVDxQ5XoYw69HAMo7kZ6ff+d7cd7yRCFSHhfKlRHQbpiOeWalNo/H0mzdgb9qj3u0uLpP9R6k3DMOi5T+0maxP0fmq2NXGhe//47NQBXeSJ5gE5Hfx0sdlq8bOYJ69+DnqVUDnpYaOg4PcadskN6434gN2Eqns93ML2Xx9K+BNSWCBSm1tGNXViXSI0QZYFFSC4L3x0nr17ifYWouSVOb8lsAh9aGIumMBQQTaz1w== 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=U/LEbqWXu9+405LHQ0kI8kGwEk0uesBShmGPBh9BRwk=; b=wZqWOEGF2tD6dAJPtE/CHdjRxuMCdcr09N3FeHT6S3T5lU4oENotc8JJasYVColrfwXEipfe0Et05As5wKbvf0FF0xaQiwMW2Kz0F7BX9Y/E5Fpd0fdl5JRcXETOl1Z9XHVDg6gBkYOvIazGofTMwCAjHWCuzU26Qm9rC+i4K8U= Received: from SJ0PR03CA0183.namprd03.prod.outlook.com (2603:10b6:a03:2ef::8) by DM4PR12MB7624.namprd12.prod.outlook.com (2603:10b6:8:107::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.18; Fri, 7 Mar 2025 05:30:50 +0000 Received: from MWH0EPF000A6732.namprd04.prod.outlook.com (2603:10b6:a03:2ef:cafe::a4) by SJ0PR03CA0183.outlook.office365.com (2603:10b6:a03:2ef::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.17 via Frontend Transport; Fri, 7 Mar 2025 05:30:50 +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 MWH0EPF000A6732.mail.protection.outlook.com (10.167.249.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Fri, 7 Mar 2025 05:30:49 +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 23:30:44 -0600 From: K Prateek Nayak To: Linus Torvalds , Oleg Nesterov , Alexander Viro , "Christian Brauner" , , CC: Jan Kara , "Matthew Wilcox (Oracle)" , Mateusz Guzik , Rasmus Villemoes , "Gautham R. Shenoy" , , , Swapnil Sapkal , "K Prateek Nayak" Subject: [PATCH v2 4/4] fs/splice: Use pipe_buf() helper to retrieve pipe buffer Date: Fri, 7 Mar 2025 05:29:19 +0000 Message-ID: <20250307052919.34542-5-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307052919.34542-1-kprateek.nayak@amd.com> References: <20250307052919.34542-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: MWH0EPF000A6732:EE_|DM4PR12MB7624:EE_ X-MS-Office365-Filtering-Correlation-Id: 1237710a-2928-47f8-fcbe-08dd5d393881 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: sa5CPHCw+cy5F1qcj41/yZdn4U0MJ1n6hcYtuBqihPQfkQbQIvRbAHcyQsMcayv/7+us3Hs5Ni1hqEre19NRJTgVZEb5sKppVlS8ta+Jh+lHPrgDejItZp2V71ovlld3m1D3lQl1NlVvlisUgTSspmr3Tn5e5QVEUxDet2MuPLQEUcamqP1UeAF1aP5febTJ1XBG29LLKwnTkmbNSpTTjT2t0qWJzOK/HMSC9KMdGFZYhDVPUoHddXBcqUssA6cZwB3CnCwcsvCs1DC0EsBuelSk+X4PMwP0Qr5/488DoIX3RfWEEzMtHb5hHWv+EAD8tGT339eeLKY8g28LURAt+6pGNlbaQPcpOiE+LOT0Q8DOggM1qS+csaEZiAVcv2lI5dIZyDtkOeKrVfdC4ANGBULLmiiOx7Y0ibqhRE7SwW8LuEz9gTh6yZb22zwYEjP9e3qcdJ+cx95KS3G6B2PSNgKf3IWMG2GXjVvu7p4d46P0g48FXVgT3vQBpBLAPJ1LF9jI1VJr6evdZmYnJRdjh6kmGiL3gPva+KS7dkxrmFdYdK9EoKhuRobgtZkNn/RZi/qoPhVDKUaOa5ExJmObG1492mhga6xsfLrhaGpp736IoVEFL3KHwpcufoUGOn1qtn6TZ6ZGqIYo3IucxhEVPasWgV53KcJt/lFyv9lykvKBZJH6c5SW6q4BPnzg0xdlosE94wuIwYJ3hi2Ndemvzvq9TbVKgWN4Db0Qk2p2TnC7LZmyy2anSR7JGWEI8ug/YKC+Od81K+AbotqtnVLYg1trvqeNdgvoC6HYCzbQscrBUgRbbt0bRAOLHSO4suFdORguhIhYy6i/RP7dljbVhkwAyZVzyaVMiiPY3nNnGoMPJ0oE/acAU/3YTPnujTVmrJwIYQk/+TgU81EvBjbDYkZHpvkYLs43zeBHwVvhD4FaioLG2gwJBvFpXUj0cqPG2rNAG5eRTXKsohFHyoHIiIV4/sgfjmuVuzo7KJEZhONEDfgcww+7n3B9DTo5bgCxmu5/2NKZJ7BezMP31+ZNytdHDRlFds0aIkaAMBBtzqW/9IMvIrQvp4rLSjSU0NI2NQ6ia1D27ynIRLSnX/p49WIM6/3owLqEUEEQ9BhzWIyFL4QTAfqlRvGnZ5GFRcgWf8juHGxzmNhs0dr+sCW86m2s/y9XCpmRhPeFVvCrzNSlvLWgervJQqqefWNF0H8I+bCmc8CLbMKOWYmgAhXNwS2P9Pc8ZlkCrxO3CRVG6a8Gf1Zj7kGtwP2nqLJs+6T1Tmv2zsRmcT2TNLCCienWNHN53AkA5cQZVsqqegO8C3CDY2a7PxOV6hNPqdNdnVaBjI2VSdnt6qRAAo5Nh2onMgd2g06xc9wGjPpH3/T8Pfo1m1sgHEoMJS3Q/EBB7vIsta0R6FEiBRAQEcf9mRpqK+TcrypO/XWFAzKcl58efI1SshxMUDfGSy8A4OLZcD7j8jMtAbMZBZ56qBTu+5tmiA== 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);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2025 05:30:49.7321 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1237710a-2928-47f8-fcbe-08dd5d393881 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: MWH0EPF000A6732.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7624 Use pipe_buf() helper to retrieve the pipe buffer throughout the file replacing the open-coded the logic. Suggested-by: Oleg Nesterov Signed-off-by: K Prateek Nayak --- Changelog: RFC v1..v2: o New patch. --- fs/splice.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 23fa5561b944..90d464241f15 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -200,7 +200,6 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, unsigned int spd_pages = spd->nr_pages; unsigned int tail = pipe->tail; unsigned int head = pipe->head; - unsigned int mask = pipe->ring_size - 1; ssize_t ret = 0; int page_nr = 0; @@ -214,7 +213,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, } while (!pipe_full(head, tail, pipe->max_usage)) { - struct pipe_buffer *buf = &pipe->bufs[head & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, head); buf->page = spd->pages[page_nr]; buf->offset = spd->partial[page_nr].offset; @@ -247,7 +246,6 @@ 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; int ret; if (unlikely(!pipe->readers)) { @@ -256,7 +254,7 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) } else if (pipe_full(head, tail, pipe->max_usage)) { ret = -EAGAIN; } else { - pipe->bufs[head & mask] = *buf; + *pipe_buf(pipe, head) = *buf; pipe->head = head + 1; return buf->len; } @@ -447,11 +445,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des { unsigned int head = pipe->head; unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; int ret; while (!pipe_empty(head, tail)) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); sd->len = buf->len; if (sd->len > sd->total_len) @@ -495,8 +492,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des static inline bool eat_empty_buffer(struct pipe_inode_info *pipe) { unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); if (unlikely(!buf->len)) { pipe_buf_release(pipe, buf); @@ -690,7 +686,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 int head, tail; size_t left; int n; @@ -711,12 +707,11 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, head = pipe->head; tail = pipe->tail; - mask = pipe->ring_size - 1; /* build the vector */ left = sd.total_len; for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); size_t this_len = buf->len; /* zero-length bvecs are not supported, skip them */ @@ -752,7 +747,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, /* dismiss the fully eaten buffers, adjust the partial one */ tail = pipe->tail; while (ret) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); if (ret >= buf->len) { ret -= buf->len; buf->len = 0; @@ -809,7 +804,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 int head, tail, bc = 0; size_t remain = len; /* @@ -846,10 +841,9 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, head = pipe->head; tail = pipe->tail; - mask = pipe->ring_size - 1; while (!pipe_empty(head, tail)) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); size_t seg; if (!buf->len) { @@ -894,7 +888,7 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, len -= ret; tail = pipe->tail; while (ret > 0) { - struct pipe_buffer *buf = &pipe->bufs[tail & mask]; + struct pipe_buffer *buf = pipe_buf(pipe, tail); size_t seg = min_t(size_t, ret, buf->len); buf->offset += seg; @@ -1725,7 +1719,6 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, struct pipe_buffer *ibuf, *obuf; unsigned int i_head, o_head; unsigned int i_tail, o_tail; - unsigned int i_mask, o_mask; int ret = 0; bool input_wakeup = false; @@ -1747,9 +1740,7 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, pipe_double_lock(ipipe, opipe); i_tail = ipipe->tail; - i_mask = ipipe->ring_size - 1; o_head = opipe->head; - o_mask = opipe->ring_size - 1; do { size_t o_len; @@ -1792,8 +1783,8 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, goto retry; } - ibuf = &ipipe->bufs[i_tail & i_mask]; - obuf = &opipe->bufs[o_head & o_mask]; + ibuf = pipe_buf(ipipe, i_tail); + obuf = pipe_buf(opipe, o_head); if (len >= ibuf->len) { /* @@ -1862,7 +1853,6 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, struct pipe_buffer *ibuf, *obuf; unsigned int i_head, o_head; unsigned int i_tail, o_tail; - unsigned int i_mask, o_mask; ssize_t ret = 0; /* @@ -1873,9 +1863,7 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, pipe_double_lock(ipipe, opipe); i_tail = ipipe->tail; - i_mask = ipipe->ring_size - 1; o_head = opipe->head; - o_mask = opipe->ring_size - 1; do { if (!opipe->readers) { @@ -1896,8 +1884,8 @@ static ssize_t link_pipe(struct pipe_inode_info *ipipe, pipe_full(o_head, o_tail, opipe->max_usage)) break; - ibuf = &ipipe->bufs[i_tail & i_mask]; - obuf = &opipe->bufs[o_head & o_mask]; + ibuf = pipe_buf(ipipe, i_tail); + obuf = pipe_buf(opipe, o_head); /* * Get a reference to this pipe buffer,