OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: [Devel] [PATCH RHEL10 COMMIT] sched/loadavg: fix build with CONFIG_CGROUP_SCHED=n
Date: Thu, 20 Aug 2026 18:57:16 +0200	[thread overview]
Message-ID: <202608201657.67KGvGOf829038@hci8VM.finist.virtuozzo.com> (raw)
In-Reply-To: <20260625220832.2201873-1-eva.kurchatova@virtuozzo.com>

The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.6.vz10
------>
commit f869ffa52901a2949cf1554e573e3500b9f85f32
Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Date:   Thu Aug 20 18:42:45 2026 +0200

    sched/loadavg: fix build with CONFIG_CGROUP_SCHED=n
    
    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 instead of relying on CONFIG_VE
    selecting it.
    
    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>
---
 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

       reply	other threads:[~2026-08-20 16:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260625220832.2201873-1-eva.kurchatova@virtuozzo.com>
2026-08-20 16:57 ` Konstantin Khorenko [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202608201657.67KGvGOf829038@hci8VM.finist.virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox