From nobody Sat May 9 09:31:42 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 7A23EC433F5 for ; Tue, 17 May 2022 06:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239125AbiEQGSs (ORCPT ); Tue, 17 May 2022 02:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234922AbiEQGSp (ORCPT ); Tue, 17 May 2022 02:18:45 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1981377F6 for ; Mon, 16 May 2022 23:18:43 -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=1652768321; 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=bgJcNcSW/ZMq/16RJL24GCiAZ43k7Fqc2lbAAdZ14Xs=; b=jneRRm0m2sLAnjS4N+rQ+VNuOuFSWtEIZcbdT9qYQWRU7gh6o8xuTj/louzAlPl/TsVyK4 x4web+QTyQPXp3wh7Rh6UpLYkD7/tK5azSRFiicguS5F0sJHHJCst5Y8q/Btk5Kf6MmZM0 Q3lQd5e/xaNxXT+LjEWh4ktZA96/uwk= 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 v3] sched/rt: fix the case where sched_rt_period_us is negative Date: Tue, 17 May 2022 14:18:12 +0800 Message-Id: <20220517061812.95276-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(). v3: - 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 --- kernel/sched/rt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 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(); --=20 2.25.1