[v2] sched/rt: move back to RT_GROUP_SCHED and rename it child

Message ID 20230802022408.529208-1-yajun.deng@linux.dev
State New
Headers
Series [v2] sched/rt: move back to RT_GROUP_SCHED and rename it child |

Commit Message

Yajun Deng Aug. 2, 2023, 2:24 a.m. UTC
  The member back in struct sched_rt_entity only related to RT_GROUP_SCHED,
it should not place out of RT_GROUP_SCHED, move back to RT_GROUP_SCHED
and rename it child.

Init child in init_tg_rt_entry(). Also, add WARN_ON_ONCE if parent is
NULL, because parent is only NULL when rt_se is NULL.

Introduce for_each_sched_rt_entity_reverse() to iterate rt_entity from
top to down.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 V1 -> V2: Add WARN_ON_ONCE in init_tg_rt_entry().
---
 include/linux/sched.h |  2 +-
 kernel/sched/rt.c     | 29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 13 deletions(-)
  

Comments

kernel test robot Aug. 3, 2023, 2:41 a.m. UTC | #1
Hello,

kernel test robot noticed "WARNING:at_kernel/sched/rt.c:#init_tg_rt_entry" on:

commit: 93f769bf3e5e50825784e72db9be3b5ab44292ab ("[PATCH v2] sched/rt: move back to RT_GROUP_SCHED and rename it child")
url: https://github.com/intel-lab-lkp/linux/commits/Yajun-Deng/sched-rt-move-back-to-RT_GROUP_SCHED-and-rename-it-child/20230802-102608
base: https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git 4efcc8bc7e08c09c58a2f5cbc2096fbda5b7cf5e
patch link: https://lore.kernel.org/all/20230802022408.529208-1-yajun.deng@linux.dev/
patch subject: [PATCH v2] sched/rt: move back to RT_GROUP_SCHED and rename it child

in testcase: boot

compiler: clang-16
test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G

(please refer to attached dmesg/kmsg for entire log/backtrace)



If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202308031034.4369b15b-oliver.sang@intel.com


[   10.946775][    T1] systemd[1]: RTC configured in localtime, applying delta of 0 minutes to system time.
[   10.955700][    T1] systemd[1]: Inserted module 'autofs4'
[   10.980165][    T1] ------------[ cut here ]------------
[   10.980563][    T1] WARNING: CPU: 0 PID: 1 at kernel/sched/rt.c:231 init_tg_rt_entry+0xb1/0xf0
[   10.981123][    T1] Modules linked in: autofs4
[   10.981413][    T1] CPU: 0 PID: 1 Comm: systemd Tainted: G                T  6.5.0-rc2-00018-g93f769bf3e5e #1 4d2b47299fa695b94fbb133b8210d53b6ca7680c
[   10.982395][    T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[   10.983049][    T1] EIP: init_tg_rt_entry+0xb1/0xf0
[   10.983366][    T1] Code: da 31 c9 6a 00 e8 df b1 0d 00 83 c4 04 8b 4d 0c 8b 41 24 89 46 20 89 7e 24 89 4e 1c 89 71 18 8d 46 08 89 46 08 89 46 0c eb 15 <0f> 0b b8
 98 c0 68 c2 89 da 31 c9 6a 00 e8 ad b1 0d 00 83 c4 04 5e
[   10.984589][    T1] EAX: 00000001 EBX: 00000001 ECX: 00000000 EDX: ffffffff
[   10.985039][    T1] ESI: ee1c0a40 EDI: ed807400 EBP: c02abf04 ESP: c02abef8
[   10.985476][    T1] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 EFLAGS: 00210246
[   10.986233][    T1] CR0: 80050033 CR2: b7d2e260 CR3: 2e147000 CR4: 00040690
[   10.986678][    T1] Call Trace:
[   10.986887][    T1]  ? show_regs+0x53/0x60
[   10.987155][    T1]  ? init_tg_rt_entry+0xb1/0xf0
[   10.987469][    T1]  ? __warn+0xae/0x270
[   10.987742][    T1]  ? init_tg_rt_entry+0xb1/0xf0
[   10.988055][    T1]  ? init_tg_rt_entry+0xb1/0xf0
[   10.988362][    T1]  ? report_bug+0xaf/0x130
[   10.988653][    T1]  ? exc_overflow+0x40/0x40
[   10.988939][    T1]  ? handle_bug+0x2c/0x50
[   10.989210][    T1]  ? exc_invalid_op+0x17/0x40
[   10.989506][    T1]  ? handle_exception+0x101/0x101
[   10.989858][    T1]  ? exc_overflow+0x40/0x40
[   10.990147][    T1]  ? init_tg_rt_entry+0xb1/0xf0
[   10.990453][    T1]  ? exc_overflow+0x40/0x40
[   10.990736][    T1]  ? init_tg_rt_entry+0xb1/0xf0
[   10.991042][    T1]  alloc_rt_sched_group+0x315/0x370
[   10.991369][    T1]  sched_create_group+0x3b/0x70
[   10.991674][    T1]  sched_autogroup_create_attach+0x4a/0x1f0
[   10.992046][    T1]  ksys_setsid+0xd2/0xe0
[   10.992316][    T1]  __ia32_sys_setsid+0xd/0x10
[   10.992618][    T1]  do_int80_syscall_32+0x7d/0xa0
[   10.992934][    T1]  ? exc_page_fault+0x112/0x160
[   10.993240][    T1]  entry_INT80_32+0xf0/0xf0
[   10.993526][    T1] EIP: 0xb7f87092
[   10.993789][    T1] Code: 00 00 00 e9 90 ff ff ff ff a3 24 00 00 00 68 30 00 00 00 e9 80 ff ff ff ff a3 f8 ff ff ff 66 90 00 00 00 00 00 00 00 00 cd 80 <c3> 8d b4 26 00 00 00 00 8d b6 00 00 00 00 8b 1c 24 c3 8d b4 26 00
[   10.994983][    T1] EAX: ffffffda EBX: 005e4cb8 ECX: 00000000 EDX: ffffffff
[   10.995420][    T1] ESI: bf95bb78 EDI: bf95bb88 EBP: bf95bc48 ESP: bf95baf8
[   10.995855][    T1] DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 007b EFLAGS: 00200202
[   10.996332][    T1] irq event stamp: 4152391
[   10.996616][    T1] hardirqs last  enabled at (4152399): [<c10d9014>] __up_console_sem+0x64/0xb0
[   10.997170][    T1] hardirqs last disabled at (4152406): [<c10d8ffb>] __up_console_sem+0x4b/0xb0
[   10.997716][    T1] softirqs last  enabled at (4152356): [<c1c9fddc>] __do_softirq+0x4cc/0x535
[   10.998289][    T1] softirqs last disabled at (4152423): [<c100c7c5>] do_softirq_own_stack+0x55/0x60
[   10.998863][    T1] ---[ end trace 0000000000000000 ]---



To reproduce:

        # build kernel
	cd linux
	cp config-6.5.0-rc2-00018-g93f769bf3e5e .config
	make HOSTCC=clang-16 CC=clang-16 ARCH=i386 olddefconfig prepare modules_prepare bzImage modules
	make HOSTCC=clang-16 CC=clang-16 ARCH=i386 INSTALL_MOD_PATH=<mod-install-dir> modules_install
	cd <mod-install-dir>
	find lib/ | cpio -o -H newc --quiet | gzip > modules.cgz


        git clone https://github.com/intel/lkp-tests.git
        cd lkp-tests
        bin/lkp qemu -k <bzImage> -m modules.cgz job-script # job-script is attached in this email

        # if come across any failure that blocks the test,
        # please remove ~/.lkp and /lkp dir to run from a clean state.
  

Patch

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 177b3f3676ef..5635655d6c35 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -594,8 +594,8 @@  struct sched_rt_entity {
 	unsigned short			on_rq;
 	unsigned short			on_list;
 
-	struct sched_rt_entity		*back;
 #ifdef CONFIG_RT_GROUP_SCHED
+	struct sched_rt_entity		*child;
 	struct sched_rt_entity		*parent;
 	/* rq on which this entity is (to be) queued: */
 	struct rt_rq			*rt_rq;
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 00e0e5074115..8e577c7b9257 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -228,13 +228,13 @@  void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
 	if (!rt_se)
 		return;
 
-	if (!parent)
-		rt_se->rt_rq = &rq->rt;
-	else
-		rt_se->rt_rq = parent->my_q;
+	if (WARN_ON_ONCE(!parent))
+		return;
 
+	rt_se->rt_rq = parent->my_q;
 	rt_se->my_q = rt_rq;
 	rt_se->parent = parent;
+	parent->child = rt_se;
 	INIT_LIST_HEAD(&rt_se->run_list);
 }
 
@@ -564,6 +564,9 @@  static inline struct task_group *next_task_group(struct task_group *tg)
 #define for_each_sched_rt_entity(rt_se) \
 	for (; rt_se; rt_se = rt_se->parent)
 
+#define for_each_sched_rt_entity_reverse(rt_se) \
+	for (; rt_se; rt_se = rt_se->child)
+
 static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
 {
 	return rt_se->my_q;
@@ -669,6 +672,9 @@  typedef struct rt_rq *rt_rq_iter_t;
 #define for_each_sched_rt_entity(rt_se) \
 	for (; rt_se; rt_se = NULL)
 
+#define for_each_sched_rt_entity_reverse(rt_se) \
+	for_each_sched_rt_entity(rt_se)
+
 static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
 {
 	return NULL;
@@ -1481,22 +1487,21 @@  static void __dequeue_rt_entity(struct sched_rt_entity *rt_se, unsigned int flag
  */
 static void dequeue_rt_stack(struct sched_rt_entity *rt_se, unsigned int flags)
 {
-	struct sched_rt_entity *back = NULL;
+	struct sched_rt_entity *root;
 	unsigned int rt_nr_running;
 
-	for_each_sched_rt_entity(rt_se) {
-		rt_se->back = back;
-		back = rt_se;
-	}
+	for_each_sched_rt_entity(rt_se)
+		root = rt_se;
 
-	rt_nr_running = rt_rq_of_se(back)->rt_nr_running;
+	rt_nr_running = rt_rq_of_se(root)->rt_nr_running;
 
-	for (rt_se = back; rt_se; rt_se = rt_se->back) {
+	rt_se = root;
+	for_each_sched_rt_entity_reverse(rt_se) {
 		if (on_rt_rq(rt_se))
 			__dequeue_rt_entity(rt_se, flags);
 	}
 
-	dequeue_top_rt_rq(rt_rq_of_se(back), rt_nr_running);
+	dequeue_top_rt_rq(rt_rq_of_se(root), rt_nr_running);
 }
 
 static void enqueue_rt_entity(struct sched_rt_entity *rt_se, unsigned int flags)