0

CrOS: core scheduling check for kernel support before enabling

In cr/6228004 we made a change to prevent spurious warning messages.
However, Betty VM doesn't use a real CPU and uses
a CPU config from QEMU and doesn't expose vulnerabilities.

Split the available check into two parts, one which checks for
kernel support and another which checks for vulnerabilities so
that it can be enabled in Betty VM tests.

BUG=b:394617911

Change-Id: Ie5b6c3b604e5d2e40f258fda389341b30cb44911
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6234007
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Reviewed-by: Zhengzheng Liu <zhzhliu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1416626}
This commit is contained in:
Brian Geffon
2025-02-05 23:22:28 -08:00
committed by Chromium LUCI CQ
parent 6e60b62699
commit 4081177740

@ -47,23 +47,8 @@ namespace {
BASE_FEATURE(kCoreScheduling,
"CoreSchedulingEnabled",
base::FEATURE_ENABLED_BY_DEFAULT);
}
void EnableCoreSchedulingIfAvailable() {
if (!IsCoreSchedulingAvailable() ||
!base::FeatureList::IsEnabled(kCoreScheduling)) {
return;
}
// prctl(2) will return EINVAL for unknown functions. We're tolerant to this
// and will log an error message for non EINVAL errnos.
if (prctl(PR_SET_CORE_SCHED, 1) == -1 &&
prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, PIDTYPE_PID, 0) == -1) {
PLOG_IF(WARNING, errno != EINVAL) << "Unable to set core scheduling";
}
}
bool IsCoreSchedulingAvailable() {
bool KernelSupportsCoreScheduling() {
static const bool kernel_support = []() {
// Test for kernel 4.19, 5.4 downstream support.
// Pass bad param `prctl(0x200, 2)`. If it is supported, we will get ERANGE
@ -91,7 +76,28 @@ bool IsCoreSchedulingAvailable() {
VLOG(1) << "Core scheduling not supported in kernel";
return false;
}();
if (!kernel_support) {
return kernel_support;
}
}
void EnableCoreSchedulingIfAvailable() {
if (!KernelSupportsCoreScheduling() ||
!base::FeatureList::IsEnabled(kCoreScheduling)) {
return;
}
// prctl(2) will return EINVAL for unknown functions. We're tolerant to this
// and will log an error message for non EINVAL errnos.
if (prctl(PR_SET_CORE_SCHED, 1) == -1 &&
prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, PIDTYPE_PID, 0) == -1) {
PLOG_IF(WARNING, errno != EINVAL) << "Unable to set core scheduling";
}
}
bool IsCoreSchedulingAvailable() {
if (!KernelSupportsCoreScheduling()) {
return false;
}