From f34e62b8d317bfff425ad77c7b27a42eb6c68652 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Thu, 12 Aug 2021 14:40:05 +0200
Subject: [PATCH 079/158] sched: Trigger warning if ->migration_disabled
 counter underflows.

If migrate_enable() is used more often than its counter part then it
remains undetected and rq::nr_pinned will underflow, too.

Add a warning if migrate_enable() is attempted if without a matching a
migrate_disable().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)

Index: linux-5.15.19-rt29/kernel/sched/core.c
===================================================================
--- linux-5.15.19-rt29.orig/kernel/sched/core.c
+++ linux-5.15.19-rt29/kernel/sched/core.c
@@ -2152,6 +2152,8 @@ void migrate_enable(void)
 	if (p->migration_disabled > 1) {
 		p->migration_disabled--;
 		return;
+	} else if (WARN_ON_ONCE(p->migration_disabled == 0)) {
+		return;
 	}
 
 	/*