From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796043312; b=erW1Dv3dxliMc+2OdbT0uhMg22SIqxUOsMiCGkaoSiPmr6xDv7FMdzCe/zVKMI/ktU4e EPRzlBKzmsFzFSEYx4UwUyKW6HX2LW+qyP6ySvYLk+fNslUVf/Q0fOtckC5Eu9ON81sbr rfQc8HazfRjLYrxsHyXTPrOxMVosbQsc67KPv4MtUkezz3KGKg7g3mutD+2PFkM8llhot xGok0nLbqHESbT30E4Hl94YyWtG4zDs/s6LyNrfNzMJrHnMkTamliYlZjfHH2nKan9G+A UhWkmJA3dxBBdV1ICTgFnWoygI0bUtagTZRG/A6MfJCXwOfb54qTjF79mfuN7RXcT9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796043312; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=BerYar88yhCkwdV3av57cQSY3At5GPoHkSSitZDJHX0=; b=v0p22vDoRsvNc8ERgkQlnYQv5DbVNM8yOzuFESLPCP5JR3usq1EmGDUSPgat3/p2fQJf oxw6SDzb1Lrqw55R1s4uzu3omFW3Fu7oz6SU2rD7DCxS8+8of3OIXHw61YxIE1+wXG9Zy C/3Ld3RLMXGsxlaXcTT2y8zI2X/hrtKNZ8Q3UNoqxHegcoWf22hyJPTsPL7Gyegb3BikP aTmUnriKa7Dd189DleCsb22NhCmqOWSpVGrCcBmEBC7ryivJ89/gKz6nhMx6R7rdivGRG I5Xh17pRynWHXxWtkpb+uWT6HLjtHRjQUr7gRPjU1ytzfhFRMNL2AjPDXqzmK1rGAdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=OQAM8J6q; arc=none smtp.remote-ip=209.85.128.70 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A5E2606A31C for ; Mon, 30 Nov 2026 12:55:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A5E2606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=OQAM8J6q Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4994d67d0e3so64533375e9.2 for ; Mon, 30 Nov 2026 04:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796043310; x=1796648110; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=BerYar88yhCkwdV3av57cQSY3At5GPoHkSSitZDJHX0=; b=OQAM8J6qcifvim5DW8jS5MRG9R3QO20I70hA6idgIz/GkfilmcscfMR+7wvGNkiqgT 33kdKYicqHc9f5ntvtpFAozJuKZ4tZSd7No8NyGA+bA1ebIBPW7Rl5E8/xWpzK6XdV5X X5OXQoSkFT5ZMIwmPab6M8e56wrzZLeUeDWXz8HFoTVBq5UN4qRH92tWxVKQA+6egBFw xhngwy3DpsbHWCIDmrFvYqzj8jTJyw8eKJ4a1ImxyL8ELE0Ct2vP4SMAOQZnTLxYJGX7 SKlhtFFCa1QNgOsbOncAVRbnG3etXOkd3GZMENn8I7RI+5pqKoP1/rr07q42KhEuR/m1 A6dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796043310; x=1796648110; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BerYar88yhCkwdV3av57cQSY3At5GPoHkSSitZDJHX0=; b=VBoOhKe/JY6RRKWjsz5NX5PTp2yUGmLFClY2UwIU/+FX6bEPEUPEX+jzKg0tFMF3pX JPljJgS/PSRNmUGouBMddhuWHMJsewOPQhunt5LtTXpYWS+eWyYPlCAcZfxjw0aPO1GE s10clbyRoBbKiud68lW6E+dhAn0UDOfS+U4FdyyeseRONKiHcDpS1NTIPx1YEXLrdK8m iBWiwqJd+S9JjtJG4YXVNunT1ERgluUGBYYpY7hGLyx1EP1nVTP1Kj55Nl2GwTns3zcn Xw8tkINSghqkDQmeH3W/wcvwnbaxRy8Y88ZarkDDzg5hsSUrWK2EDj9YXGG2TBzstw/v qjAA== X-Forwarded-Encrypted: i=1; AL+hErHp1BujvzhANESslawC5yOxh+LNAyBU7E2x/QZaWf4P8SH8meXWXti6QqT+L/lel34y7okICfGiejK0tS8=@vger.kernel.org X-Gm-Message-State: APuU4Z/eS9/bCTkkZCGNPwYCmyQDhzdi2zzJq13Az/DEdyyFLrkKNzUw y1OW5CdKv2v12kR8TWvSnvoEFdK8LGAQ0A9m++O8l0/0PCsNvvWEPQZCLUKRzrhnSyvN45OI5fO RBrhMWrAeS0DNkA== X-Received: from wmbjd22.prod.google.com ([2002:a05:600c:68d6:b0:4bb:5200:da9e]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e16:b0:4bb:69b2:d3df with SMTP id 5b1f17b1804b1-4bb88813024mr676302265e9.25.1796043309613; Mon, 30 Nov 2026 04:55:09 -0800 (PST) Date: Mon, 30 Nov 2026 12:55:09 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130125422.3895514-1-jpiecuch@google.com> Subject: [PATCH sched_ext/for-7.4-fixes] sched_ext: Clarify ops.sub_caps_updated() context and intended use From: Kuba Piecuch To: Tejun Heo , David Vernet , Andrea Righi , Changwoo Min Cc: Kuba Piecuch , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" The doc comment on ops.sub_caps_updated() states that the callback is "delivered asynchronously after the change is recorded", which can be misread as running in a separate unlocked context. In reality, scx_bpf_sub_grant() and scx_bpf_sub_revoke() deliver ops.sub_caps_updated() synchronously before returning, after releasing the shard locks. When called from an SCX op, ops.sub_caps_updated() inherits whatever locking context the parent holds (such as an rq lock), while grants during ops.sub_attach() are seeded unlocked via scx_sub_seed_caps(). As discussed on the list, synchronous delivery is intentional to keep competing updates ordered; ops.sub_caps_updated() is only for tracking held caps and propagating grants/revokes to children, whereas acting on caps (such as calling scx_bpf_cidperf_set()) belongs in ops.sub_ecaps_updated(), which runs with the cid's rq lock held once the change is in effect. Clarify the execution context and intended scope in the doc comments on @sub_caps_updated, struct scx_caps_updated, scx_bpf_sub_grant(), and scx_bpf_sub_revoke(). Link: https://lore.kernel.org/all/8e4043f995e96c0d4642287bc5009000@kernel.org/ Signed-off-by: Kuba Piecuch --- This patch was written with the help of an AI coding assistant. I have reviewed the patch and verified the tests run by the tool. kernel/sched/ext/internal.h | 25 ++++++++++++++++--------- kernel/sched/ext/sub.c | 7 +++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h index c77f62cd7bc9..ce8cf284b484 100644 --- a/kernel/sched/ext/internal.h +++ b/kernel/sched/ext/internal.h @@ -902,13 +902,19 @@ struct sched_ext_ops { * all changes since the last delivery. Direction (set vs cleared) isn't * encoded. Query current state with scx_bpf_sub_caps(). * - * Delivered asynchronously after the change is recorded, and may run - * before it takes effect on any given cpu. Use it to track which caps - * the sub-sched holds and propagate to its own children, not to decide - * if a task can run on a cpu now. sub_ecaps_updated() reports that per - * cpu, once it is in effect. - * - * May call scx_bpf_sub_grant() / scx_bpf_sub_revoke() on children. + * Delivered synchronously from the parent's scx_bpf_sub_grant() / + * scx_bpf_sub_revoke() after the shard lock is released, or unlocked + * from scx_sub_seed_caps() when seeding caps granted during + * ops.sub_attach(). It therefore inherits whatever locking context + * the parent holds (e.g. an rq lock, or unlocked from an unlocked + * caller) and may run before the change takes effect on any given cpu. + * + * Use this only to track held caps and propagate grants and revokes to + * children via scx_bpf_sub_grant() / scx_bpf_sub_revoke(). Do not act + * on caps here (e.g. deciding if a task can run on a cpu or calling + * rq-lock-sensitive kfuncs such as scx_bpf_cidperf_set()); anything + * that acts on caps belongs in ops.sub_ecaps_updated(), which runs + * with the cid's rq lock held once the change is in effect on the cpu. */ void (*sub_caps_updated)(const struct scx_cmask *cmask, u64 caps); @@ -1664,8 +1670,9 @@ enum scx_cap_flags { * delivery is in flight per shard. Further changes fold into the same buffer * and ship as the next callback, so a shard's callbacks fire in order. * - * (3) leads to deferred delivery. Events accumulate during grant/revoke and are - * delivered after the shard lock is released. + * (3) leads to delivering outside the shard lock. Events accumulate under the + * shard lock and are delivered synchronously after the shard lock is released, + * before grant/revoke returns. */ struct scx_caps_updated { raw_spinlock_t lock; diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c index 7c069a289766..cc5f6dfc7e37 100644 --- a/kernel/sched/ext/sub.c +++ b/kernel/sched/ext/sub.c @@ -2862,6 +2862,11 @@ static s32 sub_cap_preamble(u64 cgroup_id, u64 caps, const struct bpf_prog_aux * * All-or-nothing keeps the caller-visible result binary per cid, so the denied * mask is one mask to interpret rather than a per-cap matrix. * + * Any resulting ops.sub_caps_updated() callbacks are delivered synchronously + * after the shard locks are released (inheriting the caller's locking context), + * except when called from ops.sub_attach(), where scx_sub_seed_caps() delivers + * them unlocked once the child's ops are ready. + * * Return 0 on full success, -EPERM if any cid was refused, -ENODEV if the child * is gone or being disabled, or a negative errno on other failures. */ @@ -2995,6 +3000,8 @@ __bpf_kfunc s32 scx_bpf_sub_grant(u64 cgroup_id, u64 caps, * Clear @caps bits on @cmask__arena from the child named by @cgroup_id and all * its descendants. The origin parent's pshard lock is held across the subtree * walk so a concurrent grant from the origin parent observes the revoked state. + * Any resulting ops.sub_caps_updated() callbacks are delivered synchronously + * after the shard locks are released, inheriting the caller's locking context. */ __bpf_kfunc void scx_bpf_sub_revoke(u64 cgroup_id, u64 caps, const struct scx_cmask *cmask__arena, base-commit: d43078a237230fd8fb6bf082ff285c93d0ccd763 -- 2.56.1.839.g22a8290db9-goog