From nobody Wed Feb 11 07:50:06 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 8112BC77B7D for ; Wed, 10 May 2023 13:49:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236808AbjEJNtb (ORCPT ); Wed, 10 May 2023 09:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237232AbjEJNtT (ORCPT ); Wed, 10 May 2023 09:49:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727561BE3; Wed, 10 May 2023 06:49:11 -0700 (PDT) Date: Wed, 10 May 2023 13:49:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1683726550; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=46hdFH2kJFRmyUO0PSjD3oY8ttFy+HiOOIKvoMeo0qQ=; b=qs9W96am12/lcomWsGMR/LFhQdcq1JuYTuBHDiI63Q+rV2tns+C2NQ8lTP5qwb9cQ/k559 Fg0ab1Rh8YHZJNQXxEqsVlNONkf8MqA5ziYyliYC+NJoQxniXPoU1NxvSLxQprthb1PMwC BUua1mkzYeqFJPoncOyAvBGK4LA/FW7/CTTxNnVGL356vo2ND8zQmq9Hs+tgVJIzNsrvjD uEGMqETmWE2I+mtq5T+5vxJpokmzti+uY+CBpLgZGuQpMm1366O9lhggb/Bq4J1YJrBHUN c8ISWIThtkEVH+lxeYer6EA9o1EORr88j19yh2mu3dCU6dr64uWJn4Pf2p612g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1683726550; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=46hdFH2kJFRmyUO0PSjD3oY8ttFy+HiOOIKvoMeo0qQ=; b=dbvhjKMWRTUMnTMrvhPi+OykNqN08XBvfll58Dj+MgcFhNU8rDWJHI8lkDMNxH99iTrKzY Ultb1PgCqL1kM/BQ== From: "tip-bot2 for Suren Baghdasaryan" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] psi: remove 500ms min window size limitation for triggers Cc: Sudarshan Rajagopalan , Suren Baghdasaryan , "Peter Zijlstra (Intel)" , Michal Hocko , Johannes Weiner , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168372654968.404.2819009900502474821.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 519fabc7aaba3f0847cf37d5f9a5740c370eb777 Gitweb: https://git.kernel.org/tip/519fabc7aaba3f0847cf37d5f9a5740c3= 70eb777 Author: Suren Baghdasaryan AuthorDate: Thu, 02 Mar 2023 17:13:46 -08:00 Committer: Peter Zijlstra CommitterDate: Mon, 08 May 2023 10:58:38 +02:00 psi: remove 500ms min window size limitation for triggers Current 500ms min window size for psi triggers limits polling interval to 50ms to prevent polling threads from using too much cpu bandwidth by polling too frequently. However the number of cgroups with triggers is unlimited, so this protection can be defeated by creating multiple cgroups with psi triggers (triggers in each cgroup are served by a single "psimon" kernel thread). Instead of limiting min polling period, which also limits the latency of psi events, it's better to limit psi trigger creation to authorized users only, like we do for system-wide psi triggers (/proc/pressure/* files can be written only by processes with CAP_SYS_RESOURCE capability). This also makes access rules for cgroup psi files consistent with system-wide ones. Add a CAP_SYS_RESOURCE capability check for cgroup psi file writers and remove the psi window min size limitation. Suggested-by: Sudarshan Rajagopalan Signed-off-by: Suren Baghdasaryan Signed-off-by: Peter Zijlstra (Intel) Acked-by: Michal Hocko Acked-by: Johannes Weiner Link: https://lore.kernel.org/all/cover.1676067791.git.quic_sudaraja@quicin= c.com/ --- kernel/cgroup/cgroup.c | 12 ++++++++++++ kernel/sched/psi.c | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 625d748..b26ae20 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3877,6 +3877,14 @@ static __poll_t cgroup_pressure_poll(struct kernfs_o= pen_file *of, return psi_trigger_poll(&ctx->psi.trigger, of->file, pt); } =20 +static int cgroup_pressure_open(struct kernfs_open_file *of) +{ + if (of->file->f_mode & FMODE_WRITE && !capable(CAP_SYS_RESOURCE)) + return -EPERM; + + return 0; +} + static void cgroup_pressure_release(struct kernfs_open_file *of) { struct cgroup_file_ctx *ctx =3D of->priv; @@ -5276,6 +5284,7 @@ static struct cftype cgroup_psi_files[] =3D { { .name =3D "io.pressure", .file_offset =3D offsetof(struct cgroup, psi_files[PSI_IO]), + .open =3D cgroup_pressure_open, .seq_show =3D cgroup_io_pressure_show, .write =3D cgroup_io_pressure_write, .poll =3D cgroup_pressure_poll, @@ -5284,6 +5293,7 @@ static struct cftype cgroup_psi_files[] =3D { { .name =3D "memory.pressure", .file_offset =3D offsetof(struct cgroup, psi_files[PSI_MEM]), + .open =3D cgroup_pressure_open, .seq_show =3D cgroup_memory_pressure_show, .write =3D cgroup_memory_pressure_write, .poll =3D cgroup_pressure_poll, @@ -5292,6 +5302,7 @@ static struct cftype cgroup_psi_files[] =3D { { .name =3D "cpu.pressure", .file_offset =3D offsetof(struct cgroup, psi_files[PSI_CPU]), + .open =3D cgroup_pressure_open, .seq_show =3D cgroup_cpu_pressure_show, .write =3D cgroup_cpu_pressure_write, .poll =3D cgroup_pressure_poll, @@ -5301,6 +5312,7 @@ static struct cftype cgroup_psi_files[] =3D { { .name =3D "irq.pressure", .file_offset =3D offsetof(struct cgroup, psi_files[PSI_IRQ]), + .open =3D cgroup_pressure_open, .seq_show =3D cgroup_irq_pressure_show, .write =3D cgroup_irq_pressure_write, .poll =3D cgroup_pressure_poll, diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index e072f6b..b49af59 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -160,7 +160,6 @@ __setup("psi=3D", setup_psi); #define EXP_300s 2034 /* 1/exp(2s/300s) */ =20 /* PSI trigger definitions */ -#define WINDOW_MIN_US 500000 /* Min window size is 500ms */ #define WINDOW_MAX_US 10000000 /* Max window size is 10s */ #define UPDATES_PER_WINDOW 10 /* 10 updates per window */ =20 @@ -1305,8 +1304,7 @@ struct psi_trigger *psi_trigger_create(struct psi_gro= up *group, if (state >=3D PSI_NONIDLE) return ERR_PTR(-EINVAL); =20 - if (window_us < WINDOW_MIN_US || - window_us > WINDOW_MAX_US) + if (window_us =3D=3D 0 || window_us > WINDOW_MAX_US) return ERR_PTR(-EINVAL); =20 /*