Message ID | 20250104012037.159386-1-shr@devkernel.io (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 C1D3CE77188 for <linux-mm@archiver.kernel.org>; Sat, 4 Jan 2025 01:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 008346B0082; Fri, 3 Jan 2025 20:20:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED2536B0088; Fri, 3 Jan 2025 20:20:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4D0F6B0089; Fri, 3 Jan 2025 20:20:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B09326B0082 for <linux-mm@kvack.org>; Fri, 3 Jan 2025 20:20:49 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3EEF31A0BCB for <linux-mm@kvack.org>; Sat, 4 Jan 2025 01:20:49 +0000 (UTC) X-FDA: 82968015018.05.B2052AA Received: from fout-a2-smtp.messagingengine.com (fout-a2-smtp.messagingengine.com [103.168.172.145]) by imf06.hostedemail.com (Postfix) with ESMTP id 3852C180004 for <linux-mm@kvack.org>; Sat, 4 Jan 2025 01:20:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=e21MOVU1; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=FczubmTm; dmarc=none; spf=pass (imf06.hostedemail.com: domain of shr@devkernel.io designates 103.168.172.145 as permitted sender) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735953647; a=rsa-sha256; cv=none; b=kUUUDwABlT9WSXpcpkW1Oe6mqTmj4f6CjFMuU2A936ZaK/3MoaLbzPinBPUdRXJBgfvdhE ChZPuS1c/DwlxikNOdhiqkAblQPp4atvYHpx4S2/PtwOfQMXSZCiPbCbnzaQwP264t62YX aKHJEgF4ryri/EJnD6yHRJ4vI0Of2fo= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm3 header.b=e21MOVU1; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=FczubmTm; dmarc=none; spf=pass (imf06.hostedemail.com: domain of shr@devkernel.io designates 103.168.172.145 as permitted sender) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735953647; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=hC/m9P7PjtOpQenVYa1xGaGlnEienU5z/T5QpgQf3jM=; b=bT+0HuIhW6ycKDqLA/KlIO7MRatMtTWjCg4LEpkpTiCvPjRVKb+Zps4hfc4RATYs0edM8Q ZGSBTq2R2xNQWPdNkyRFuYIg6HE72AhJwS7KOXnFxruCt2nXVlf6AbAH59rMU5gbITj1Lu s/6DSrjK4M4SWbOH0pRRoyBC6Ln4XSo= Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id D93931380232; Fri, 3 Jan 2025 20:20:41 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 03 Jan 2025 20:20:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devkernel.io; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm3; t=1735953641; x=1736040041; bh=hC/m9P7PjtOpQenVYa1xG aGlnEienU5z/T5QpgQf3jM=; b=e21MOVU1eRNlsIxk3nWMB/Ddz6BPPVzWU2RYo aGUHJx3da2ipdgQDGTWnBnamF1p8lKbzS2G4T8pzVtw6Ta0yPawy2ykokvVFKYdf jvsQPcL1/hNbipwzIylauhf5lBHQv6AE8NKV7qUaSrPg4P/X2X2uqPxo5fNq7NOX wnPdq396r6WMqsY5sBkPThTL2gPe1VxmH0FdimT0KjtamG1Mp/ypvt0XW9j0D4Jt /ojKhJCYc0uWzwDH1HpIivTzYpRruDxsfI0OBYvfOe7Oxx+i87wxHdTrpKrke87Q 2Y44BKqgLu4pHJM9FfmxVRgBFdXfWuLs5K4M5+2TqEc0NRwZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1735953641; x=1736040041; bh=hC/m9P7PjtOpQenVYa1xGaGlnEienU5z/T5 QpgQf3jM=; b=FczubmTm+fOLHVKbblEEnkDjkyoVHXPtvLq5IBbuxOe3j0+MU/9 oi+bsC76kWmdfQk3RczjY0XUTPcS+kBxXInmbO1sg59E9ibwM0xQj0fRCqhKTa0r PAzzx+Z9jCZEAEylnTJmg0Kc/zThdIVEJs75JV/sxvOrSlDM3AaoL30r8b6sAy6B 05R9cK7EkXjIvP4CFgjFBk5OQwJmqA2YpdLuwiAgJd6Y4onjvD/qvVwlV3gWAyHN vVz6B5/HrdJ9SfmhE03r4VZRsa/qxzkXGXb8hiNVETQ5dreD3kmcxDM0N8PkXXX+ Xk902WhPbVQ3um5R1MWbPufXLzEly5Eymeg== X-ME-Sender: <xms:6Yx4Z_Qw0MfiG9B5ymsfAfbvAzE5h9lWZ2LALvqA5RIeqhd0PnZovA> <xme:6Yx4ZwwshiA2TtDwhiUjcSjiTKL-V_mznG0Nb2hHD7rlZC5PytKCnS4uTgbD-zY7F _cUA0kCixmetn75zeU> X-ME-Received: <xmr:6Yx4Z03hI1-Z0hKQ5K2dbD9E5X8lgDgfYEiMWbu1_foQ7fZhB85ZkoQgyt4d8AA9-THyZPGqE28GJxRJOC17pH7VbuapApHBgHo> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudefhedgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuthgvfhgrnhcutfhovghstghhuceo shhhrhesuggvvhhkvghrnhgvlhdrihhoqeenucggtffrrghtthgvrhhnpeevieegfeffhf ekudeuieelgfeljeekgedthfeiveeltedukeegfeeuvdelvdejueenucffohhmrghinhep khgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepshhhrhesuggvvhhkvghrnhgvlhdrihhopdhnsggprhgtphhtthhopeei pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeifihhllhihsehinhhfrhgruggvrg gurdhorhhgpdhrtghpthhtohepiiiiqhhqtddutdefrdhhvgihsehgmhgrihhlrdgtohhm pdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprh gtphhtthhopehlihhnuhigqdhmmheskhhvrggtkhdrohhrghdprhgtphhtthhopehlihhn uhigqdhfshguvghvvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsh hhrhesuggvvhhkvghrnhgvlhdrihho X-ME-Proxy: <xmx:6Yx4Z_CHkXyteKf0cGKyTVaNd73HCTI86umkGAv8eQZKGn9XH35B8g> <xmx:6Yx4Z4hFnHckja2MwOfMsPtz7hMk_t_fidzHnlFDRtXmBYA8ToWYgw> <xmx:6Yx4ZzpnSN6_F6FKz8dwgSk2ok0qhDVzAJMn8V3duIw2P4kIiZczRg> <xmx:6Yx4Zzihp5n0VcwFpKfzoVxOspRH32C5zc78eeGoGSVVLQl_zW6SAg> <xmx:6Yx4ZzW7O7Ye-bsdjrccJvYQEcsG7kq4LKLPwwlSWetztKF_-VINVfvp> Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 3 Jan 2025 20:20:40 -0500 (EST) From: Stefan Roesch <shr@devkernel.io> To: willy@infradead.org, zzqq0103.hey@gmail.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: shr@devkernel.io Subject: [PATCH v1] mm: fix div by zero in bdi_ratio_from_pages Date: Fri, 3 Jan 2025 17:20:37 -0800 Message-ID: <20250104012037.159386-1-shr@devkernel.io> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3852C180004 X-Stat-Signature: 98h5d5a8d56inomjbwsf5t4as6zejs1o X-HE-Tag: 1735953644-943075 X-HE-Meta: U2FsdGVkX18rwghv6HvT9EQrG8Rt9eWdPaBU/Ilm7jaTy19Slr1wdhvvHgtWN2skCPxYkEn+KbFtdsNKlkBH5Sxk+/twK/jxLfRXQHLq8PPQEjQ+PzQjARU/CPKRiwNO5otR4HF6zdu7DH0PuHK5ckH9khPTxj4R4tlOZ3D/dm8Lqkho7kjqVIQ0IL+2gVuzHfypO/u5UqpnJ6wIqUSDcnCIneWfvJqW1hJqX+oERmQxn0Weio8bwm2Fi6IZ/7J/hCpshSF3BsqMZltAUu6N6Q9bD2GxNjKPZRLoeIWRPvWcOonf8HjNVrzDMSbrfgU0nw/YWsCG39SKa1wxu5fYxU0bDwWJLbWp7pu20J++RedM1hb3+QI6HgaXRrkKebpQmjuM5iCo2tqIvcL0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linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
[v1] mm: fix div by zero in bdi_ratio_from_pages
|
expand
|
diff --git a/mm/page-writeback.c b/mm/page-writeback.c index d213ead95675..91aa7a5c0078 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -692,6 +692,8 @@ static unsigned long bdi_ratio_from_pages(unsigned long pages) unsigned long ratio; global_dirty_limits(&background_thresh, &dirty_thresh); + if (!dirty_thresh) + return -EINVAL; ratio = div64_u64(pages * 100ULL * BDI_RATIO_SCALE, dirty_thresh); return ratio;
During testing it has been detected, that it is possible to get div by zero error in bdi_set_min_bytes. The error is caused by the function bdi_ratio_from_pages(). bdi_ratio_from_pages() calls global_dirty_limits. If the dirty threshold is 0, the div by zero is raised. This can happen if the root user is setting: echo 0 > /proc/sys/vm/dirty_ration. The following is a test case: echo 0 > /proc/sys/vm/dirty_ratio cd /sys/class/bdi/<device> echo 1 > strict_limit echo 8192 > min_bytes ==> error is raised. The problem is addressed by returning -EINVAL if dirty_ratio or dirty_bytes is set to 0. Reported-by: cheung wall <zzqq0103.hey@gmail.com> Closes: https://lore.kernel.org/linux-mm/87pll35yd0.fsf@devkernel.io/T/#t Signed-off-by: Stefan Roesch <shr@devkernel.io> --- mm/page-writeback.c | 2 ++ 1 file changed, 2 insertions(+) base-commit: 0bc21e701a6ffacfdde7f04f87d664d82e8a13bf