From nobody Fri Oct 3 16:44:17 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 4608D1A0711 for ; Wed, 27 Aug 2025 12:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756299091; cv=none; b=uZG5LjHV/0EkYJ4kPmlSwpNyglp9q3A1JCJwft1p/8tFUaNftbJwh9IntgQCg3XNu0XkKbnLO4dj7RhCqMLUkJ+K9rRVuHAwgafXPt+Gm3DtqF1Qb33agEWMXwk16Fibh4P8qQ4jvJ7hAMtirzONa+FBbxC71YXPqIBs3igJX/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756299091; c=relaxed/simple; bh=yn4FXu3iy4O7Ql52fLI1NEmcBVcFi7JOFNu4QpkWIFw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=YuPN5hle+svsObE3FPIQcpOB2zuCtgYC3hwO8p2G12Hc4gLkqwoGtDiWwpyo8Uh2vCMY1sBBoMn4NEkKoYeNPO4+BqMAPbPN5x+BuwVqTFQwGSEjhVg6rWMLt+t4oICpWmjA7IyqXh65yjEbBa1Bs4TjHdMc5mcBZ809RvvTUWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4cBks83S3wzqVXQ; Wed, 27 Aug 2025 20:50:20 +0800 (CST) Received: from dggemv712-chm.china.huawei.com (unknown [10.1.198.32]) by mail.maildlp.com (Postfix) with ESMTPS id 1B6201800B1; Wed, 27 Aug 2025 20:51:18 +0800 (CST) Received: from kwepemn500008.china.huawei.com (7.202.194.149) by dggemv712-chm.china.huawei.com (10.1.198.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 27 Aug 2025 20:51:17 +0800 Received: from huawei.com (10.67.174.57) by kwepemn500008.china.huawei.com (7.202.194.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 27 Aug 2025 20:51:17 +0800 From: Xia Fukun To: , , , , , CC: , , , , , Subject: [PATCH] sched/fair: Fix division-by-zero error in task_scan_max() Date: Wed, 27 Aug 2025 12:34:27 +0000 Message-ID: <20250827123427.1229183-1-xiafukun@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemn500008.china.huawei.com (7.202.194.149) Content-Type: text/plain; charset="utf-8" The error can be reproduced by following these steps: First, set sysctl_numa_balancing_scan_size to 0: echo 0 > /sys/kernel/debug/sched/numa_balancing/scan_size_mb Then trigger the clone system call, for example, by using pthread_create to create a new thread. Oops: divide error: 0000 [#1] SMP NOPTI CPU: 11 UID: 0 PID: 1 Comm: systemd Tainted: G S 6.17.0xfk_v2 #6 Tainted: [S]=3DCPU_OUT_OF_SPEC Hardware name: SuperCloud R5210 G12/X12DPi-N6, BIOS 1.1c 08/30/2021 RIP: 0010:task_scan_max+0x24/0x190 RSP: 0018:ff56485a001ebc98 EFLAGS: 00010246 ... Call Trace: init_numa_balancing+0xdb/0x1e0 __sched_fork+0x110/0x180 sched_fork+0xd/0x170 copy_process+0x821/0x1aa0 kernel_clone+0xbc/0x400 __do_sys_clone3+0xde/0x120 do_syscall_64+0xa4/0x260 entry_SYSCALL_64_after_hwframe+0x77/0x7f This patch fixes the issue by ensuring that the relevant value in task_scan_max() is at least 1. Fixes: 598f0ec0bc99 ("sched/numa: Set the scan rate proportional to the mem= ory usage of the task being scanned") Signed-off-by: Xia Fukun --- kernel/sched/fair.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b173a059315c..ea962e3bcb13 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1496,6 +1496,7 @@ static unsigned int task_nr_scan_windows(struct task_= struct *p) * on resident pages */ nr_scan_pages =3D sysctl_numa_balancing_scan_size << (20 - PAGE_SHIFT); + nr_scan_pages =3D max_t(unsigned long, nr_scan_pages, 1UL << (20 - PAGE_S= HIFT)); rss =3D get_mm_rss(p->mm); if (!rss) rss =3D nr_scan_pages; @@ -1510,6 +1511,7 @@ static unsigned int task_nr_scan_windows(struct task_= struct *p) static unsigned int task_scan_min(struct task_struct *p) { unsigned int scan_size =3D READ_ONCE(sysctl_numa_balancing_scan_size); + scan_size =3D max_t(unsigned int, scan_size, 1); unsigned int scan, floor; unsigned int windows =3D 1; =20 --=20 2.34.1