All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH vz10 01/32] sched/loadavg: fix build with CONFIG_CGROUP_SCHED=n
@ 2026-08-21 16:36 Konstantin Khorenko
  2026-08-21 16:42 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko
  0 siblings, 1 reply; 7+ messages in thread
From: Konstantin Khorenko @ 2026-08-21 16:36 UTC (permalink / raw)


From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>

get_avenrun_tg() dereferences struct task_group, which is only defined
under CONFIG_CGROUP_SCHED in kernel/sched/sched.h.  Both the function
and its unconditional caller are compiled regardless of that option:
kernel/sched/loadavg.c is pulled into build_utility.c, and do_sysinfo()
calls get_avenrun_tg() from a branch that is dead at runtime with
CONFIG_VE=n but still compiled.  So CONFIG_CGROUP_SCHED=n does not
build:

  kernel/sched/loadavg.c: error: invalid use of undefined type
                          'struct task_group'

Compile get_avenrun_tg() only when CONFIG_CGROUP_SCHED is enabled and
provide a stub otherwise.  The stub returns -ENOSYS, the same error the
real implementation returns when there is no per-Container task group to
report.  do_sysinfo() ignores the return value and info->loads is
already zeroed by memset(), so no caller has to change.

calc_load_ve() walks the very same task_group internals, so require
CONFIG_CGROUP_SCHED there as well: the dependency then stands where the
code is, instead of being implied by the select list of CONFIG_VE.

Fixes: c80eee4588ff ("ve/sched/loadavg: Calculate avenrun for Containers root cpu cgroups")
Feature: statistics: loadavg virtualization
https://virtuozzo.atlassian.net/browse/VSTOR-134732
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 include/linux/sched/loadavg.h | 11 ++++++++++-
 kernel/sched/loadavg.c        |  6 ++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/linux/sched/loadavg.h b/include/linux/sched/loadavg.h
index 771e753e4670..b97635dc47d4 100644
--- a/include/linux/sched/loadavg.h
+++ b/include/linux/sched/loadavg.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_SCHED_LOADAVG_H
 #define _LINUX_SCHED_LOADAVG_H
 
+#include <linux/errno.h>
 #include <linux/types.h>
 
 /*
@@ -18,8 +19,16 @@ extern unsigned long avenrun[];		/* Load averages */
 extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
 
 struct task_group;
+#ifdef CONFIG_CGROUP_SCHED
 extern int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
 			  unsigned long offset, int shift);
+#else
+static inline int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
+				 unsigned long offset, int shift)
+{
+	return -ENOSYS;
+}
+#endif
 
 #define FSHIFT		11		/* nr of bits of precision */
 #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
@@ -51,7 +60,7 @@ extern unsigned long calc_load_n(unsigned long load, unsigned long exp,
 
 extern bool calc_global_load(void);
 
-#ifdef CONFIG_VE
+#if defined(CONFIG_VE) && defined(CONFIG_CGROUP_SCHED)
 extern void calc_load_ve(void);
 #else
 #define calc_load_ve() do { } while (0)
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index bc0b6bcdae2d..2f66772750ea 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -78,6 +78,7 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
+#ifdef CONFIG_CGROUP_SCHED
 int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
 		   unsigned long offset, int shift)
 {
@@ -93,6 +94,7 @@ int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
 
 	return 0;
 }
+#endif /* CONFIG_CGROUP_SCHED */
 
 long calc_load_fold_active(struct rq *this_rq, long adjust)
 {
@@ -109,7 +111,7 @@ long calc_load_fold_active(struct rq *this_rq, long adjust)
 	return delta;
 }
 
-#ifdef CONFIG_VE
+#if defined(CONFIG_VE) && defined(CONFIG_CGROUP_SCHED)
 extern struct list_head ve_root_list;
 extern raw_spinlock_t load_ve_lock;
 
@@ -166,7 +168,7 @@ void calc_load_ve(void)
 	kstat_glob.nr_unint_avg[2] = calc_load(kstat_glob.nr_unint_avg[2], EXP_15, nr_unint);
 	write_seqcount_end(&kstat_glob.nr_unint_avg_seq);
 }
-#endif /* CONFIG_VE */
+#endif /* CONFIG_VE && CONFIG_CGROUP_SCHED */
 
 /**
  * fixed_power_int - compute: x^n, in O(log n) time
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-21 16:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260625220832.2201873-1-eva.kurchatova@virtuozzo.com>
2026-08-20 16:57 ` [Devel] [PATCH RHEL10 COMMIT] sched/loadavg: fix build with CONFIG_CGROUP_SCHED=n Konstantin Khorenko
2026-08-20 16:57 ` [Devel] [PATCH RHEL10 COMMIT] sched/core: guard cpu_cgrp_subsys.depends_on with CONFIG_CGROUP_CPUACCT Konstantin Khorenko
2026-08-20 16:57 ` [Devel] [PATCH RHEL10 COMMIT] sched: move MAX_CPU_RATE out of CONFIG_CFS_CPULIMIT Konstantin Khorenko
2026-08-20 16:57 ` [Devel] [PATCH RHEL10 COMMIT] sched/cpuacct: guard ve_root_tg() with CONFIG_CFS_CPULIMIT Konstantin Khorenko
     [not found] ` <20260625220832.2201873-2-eva.kurchatova@virtuozzo.com>
2026-08-21 14:03   ` [Devel] [PATCH vz10 02/14] mm: fix VZ build errors with CONFIG_MEMCG=n Konstantin Khorenko
2026-08-21 16:48 ` [Devel] [PATCH vz10 01/14] sched: fix VZ build errors with CONFIG_CGROUP_SCHED=n Konstantin Khorenko
2026-08-21 16:36 [Devel] [PATCH vz10 01/32] sched/loadavg: fix build " Konstantin Khorenko
2026-08-21 16:42 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.