[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <202407032053257877vuVsFfB1hh0DKSowPd8p@zte.com.cn>
Date: Wed, 3 Jul 2024 20:53:25 +0800 (CST)
From: <xu.xin16@....com.cn>
To: <mingo@...hat.com>, <peterz@...radead.org>, <juri.lelli@...hat.com>,
<vincent.guittot@...aro.org>, <ietmar.eggemann@....com>,
<ostedt@...dmis.org>, <bsegall@...gle.com>, <mgorman@...e.de>,
<bristot@...hat.com>, <he.peilin@....com.cn>, <yang.yang29@....com.cn>,
<tu.qiang35@....com.cn>, <jiang.kun2@....com.cn>,
<zhang.yunkai@....com.cn>, <liu.chun2@....com.cn>,
<fan.yu9@....com.cn>, <linux-kernel@...r.kernel.org>
Subject: [PATCH linux-next v2] sched/core: Add WARN() to check overflow in migrate_disable()
From: Peilin He <he.peilin@....com.cn>
Background
==========
When repeated migrate_disable() calls are made with missing the
corresponding migrate_enable() calls, there is a risk of
'migration_disabled' going upper overflow because
'migration_disabled' is a type of unsigned short whose max value is
65535.
In PREEMPT_RT kernel, if 'migration_disabled' goes upper overflow, it may
make the migrate_disable() ineffective within local_lock_irqsave(). This
is because, during the scheduling procedure, the value of
'migration_disabled' will be checked, which can trigger CPU migration.
Consequently, the count of 'rcu_read_lock_nesting' may leak due to
local_lock_irqsave() and local_unlock_irqrestore() occurring on different
CPUs.
Usecase
========
For example, When I developed a driver, I encountered a warning like
"WARNING: CPU: 4 PID: 260 at kernel/rcu/tree_plugin.h:315
rcu_note_context_switch+0xa8/0x4e8" warning. It took me half a month
to locate this issue. Ultimately, I discovered that the lack of upper
overflow detection mechanism in migrate_disable() was the root cause,
leading to a significant amount of time spent on problem localization.
If the upper overflow detection mechanism was added to migrate_disable(),
the root cause could be very quickly and easily identified.
Effect
======
Using WARN() to check if 'migration_disabled' is upper overflow can help
developers identify the issue quickly.
Signed-off-by: Peilin He<he.peilin@....com.cn>
Signed-off-by: xu xin <xu.xin16@....com.cn>
Reviewed-by: Yunkai Zhang <zhang.yunkai@....com.cn>
Reviewed-by: Qiang Tu <tu.qiang35@....com.cn>
Reviewed-by: Kun Jiang <jiang.kun2@....com.cn>
Reviewed-by: Fan Yu <fan.yu9@....com.cn>
Cc: Yang Yang <yang.yang29@....com.cn>
Cc: Liu Chun <liu.chun2@....com.cn>
---
v1->v2:
Some fixes according to:
https://lore.kernel.org/all/20240702124334.762dbd5a@rorschach.local.home/
1.Merge if conditions into WARN().
2.Remove the newline character '\n'. Right, we don't need the redundant \n.
kernel/sched/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8cc4975d6b2b..327010af6ce9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2259,6 +2259,7 @@ void migrate_disable(void)
struct task_struct *p = current;
if (p->migration_disabled) {
+ WARN(p->migration_disabled == USHRT_MAX, "migration_disabled has encountered an overflow.");
p->migration_disabled++;
return;
}
--
2.17.1
Powered by blists - more mailing lists