From nobody Thu May 7 23:11:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB105C433F5 for ; Tue, 17 May 2022 06:29:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbiEQG3q (ORCPT ); Tue, 17 May 2022 02:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbiEQG3n (ORCPT ); Tue, 17 May 2022 02:29:43 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE1E44A30 for ; Mon, 16 May 2022 23:29:37 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1652768975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EYuU2KAmRFN0la5XUelyDTOtLmGGgkX2vWYUFCGpMoU=; b=Ba2gbFEWM1atesbV76OXslfVhi7Wg+eQ89L+SZIZZQTCsBvFkxzDATMh+kS0GHGLU/D8qS KO2zup7H017Xw9PzN/91aceTxNaaGCV1lWmuBU5rBGhnX+leeCi8dQGe1Y3AUv3oWhd+5u aF91Z75SuvlC/0M/9rfkyaP8/MjXCsE= From: Yajun Deng To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com Cc: linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v4] sched/rt: fix the case where sched_rt_period_us is negative Date: Tue, 17 May 2022 14:29:18 +0800 Message-Id: <20220517062918.104482-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The proc_dointvec() is for integer, but sysctl_sched_rt_period is a unsigned integer, proc_dointvec() would convert negative number into positive number. So both proc_dointvec() and sched_rt_global_validate() aren't return error even if we set a negative number. Use proc_dointvec_minmax() instead of proc_dointvec() and use extra1 limit the minimum value for sched_rt_period_us/sched_rt_runtime_us. Make sysctl_sched_rt_period integer to match proc_dointvec_minmax(). v4: - Make sysctl_sched_rt_period integer (Valentin Schneider) v2: - Remove sched_rr_timeslice_ms related changes (Valentin Schneider) Fixes: d0b27fa77854 ("sched: rt-group: synchonised bandwidth period") Signed-off-by: Yajun Deng Reviewed-by: Valentin Schneider --- kernel/sched/rt.c | 11 +++++------ kernel/sched/sched.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 8c9ed9664840..cafc580edbe4 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -16,7 +16,7 @@ struct rt_bandwidth def_rt_bandwidth; * period over which we measure -rt task CPU usage in us. * default: 1s */ -unsigned int sysctl_sched_rt_period =3D 1000000; +int sysctl_sched_rt_period =3D 1000000; =20 /* * part of the period that we allow rt tasks to run in us. @@ -34,9 +34,10 @@ static struct ctl_table sched_rt_sysctls[] =3D { { .procname =3D "sched_rt_period_us", .data =3D &sysctl_sched_rt_period, - .maxlen =3D sizeof(unsigned int), + .maxlen =3D sizeof(int), .mode =3D 0644, .proc_handler =3D sched_rt_handler, + .extra1 =3D SYSCTL_ONE, }, { .procname =3D "sched_rt_runtime_us", @@ -44,6 +45,7 @@ static struct ctl_table sched_rt_sysctls[] =3D { .maxlen =3D sizeof(int), .mode =3D 0644, .proc_handler =3D sched_rt_handler, + .extra1 =3D SYSCTL_NEG_ONE, }, { .procname =3D "sched_rr_timeslice_ms", @@ -2960,9 +2962,6 @@ static int sched_rt_global_constraints(void) #ifdef CONFIG_SYSCTL static int sched_rt_global_validate(void) { - if (sysctl_sched_rt_period <=3D 0) - return -EINVAL; - if ((sysctl_sched_rt_runtime !=3D RUNTIME_INF) && ((sysctl_sched_rt_runtime > sysctl_sched_rt_period) || ((u64)sysctl_sched_rt_runtime * @@ -2993,7 +2992,7 @@ static int sched_rt_handler(struct ctl_table *table, = int write, void *buffer, old_period =3D sysctl_sched_rt_period; old_runtime =3D sysctl_sched_rt_runtime; =20 - ret =3D proc_dointvec(table, write, buffer, lenp, ppos); + ret =3D proc_dointvec_minmax(table, write, buffer, lenp, ppos); =20 if (!ret && write) { ret =3D sched_rt_global_validate(); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 1f97f357aacd..1cb4d47b3e47 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -115,7 +115,7 @@ extern long calc_load_fold_active(struct rq *this_rq, l= ong adjust); =20 extern void call_trace_sched_update_nr_running(struct rq *rq, int count); =20 -extern unsigned int sysctl_sched_rt_period; +extern int sysctl_sched_rt_period; extern int sysctl_sched_rt_runtime; extern int sched_rr_timeslice; =20 --=20 2.25.1