From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BD7E284B29 for ; Thu, 21 May 2026 04:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779336931; cv=none; b=MHcD3ozUX6/lOB1mSLIFmH0w558wmt4at5Awv+nzDZaSbwLAUBMK/GhQM5F8uBlizVDSup05VpdefQ8bJU3I4QcDMMO7R3WguAixdE/nqLSEtx16NcWJVbgE/kV5n5uPtKunfSTVXVadH06T73AOGH8Hz1QjA3XdDfqYgZPfZeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779336931; c=relaxed/simple; bh=7pJINburNI2s6aoo69b+PuHHTBy7UiG91NoFj7AaxeM=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Cc:Subject: References:In-Reply-To; b=RnNMYG9o/t6mRw8994WrTeEqVierVBnDdiIYCoxU5yovCvwxnQ3JqUuksBxGQ3a1kKBPBGxW6k8VhxgjSYUe09ELVjrA6KAI/zp3Ti+/+QaXcT4fkcW86EOnWdBIX1KAJNqf4uf4L8g13NF1KqrZvBHw9elpwgixjEU5NT9yhn0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b=B2A88vOW; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b="B2A88vOW" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2b4583f0a1aso36657215ad.3 for ; Wed, 20 May 2026 21:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1779336927; x=1779941727; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8mx7h0My419s2P7k1BFl0yESBgvzIQJC2piNf13boJc=; b=B2A88vOW5GiHweAa5SCUw4eKLZTrn6SEVetyoM65ZB5PftP31vQCiFTWg4urzncQ3H v9VBtUJ6gWDYFQb9n1lNzSulmB4UHXy4rtUmoY7sLBXDHm516SN5+nn5HlBrLYy5+2Pv yl+/a7/v+dICGBcrdIXhs0NJwAp05D+B5UIKNOFSsqU5eUjYxVW8y8bNLxvcFsR1kP3B sAyHfAwt2Xn2A+7JEKFtDdY5Z8yB3St7LS/emdV65RvT/eHpovrwjQvd/eDIFT8iacSW NHQ4HYhQ+SAydnayyJ+o55EarWU1NNiysvIO2bpGzkNa5vBx2XRsPvk0NZEEBDt0Np9o +CNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779336927; x=1779941727; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8mx7h0My419s2P7k1BFl0yESBgvzIQJC2piNf13boJc=; b=HYI/GsDFpBMlX8mDPxHIUf5n3UaH8TANC594uyM0xlvMHogj1aX73et/H8pJw6e2k3 d02IGhH+nI/y9rCgg6HbHo3u6BxVFZmpi0t+EOIT1GMWvsUKP0OT3Mv6EQyvbD12EBiO lEnQsZwctxkLxIrqfw9mWG5b++dydxG7sF0tPyqSYDg6QO3+jp07F+sg6yrOdk9LGBW5 xJEAB/Y4dayPIQLuvghDv0DnKLWrFeGW2oSddTtpap6siEXLej9DvZm0SBlsxNwl5buT yRv9MmUcWBYxW2+vHJCX+txwZqYbJ56RVluY2xJIFVueSYRkSa2O+gGVrvKk88j2xukd xCFw== X-Forwarded-Encrypted: i=1; AFNElJ/nJJZeHjSGT9iZnVLfPHbULcMchS9VVPko7uVgg5V9aNByH9RTmceJprJNDMv6lqI9Tzqx8awzjae4NgM=@vger.kernel.org X-Gm-Message-State: AOJu0YwO8D4zygUmzvkhYCrQDTrDdbinhpOJStcBVCVF9+lflTyzyUTf Fq+RLNZYkg0wm64F9uXhQtZzBfY6JGtpd4DQPxiFopHUv6QQBetSdUUXRvi5AAvy2Rk= X-Gm-Gg: Acq92OFWrEVEJ0L8DlYMyYaVmG2JceBq6Tb7Tdv3YeFyVgdHFHL2ULflBEcBTfap7zb IIF90/laMbleN3lRxibz2GlnnTd0j6gUFyQOxPowJfO04DSfil3+1VaNCzLNmMwxyP8dIuLEfgh w/5g4NEwsmzSnRJuTw5THiFDqmncbEUyV05dayTTKYJZ5CCBuAUDa6jtIIcICxnUyEXuIuWEU1G bfIJ9EuTkD2O//cTrTCE/PfeW4xFiBYED7Iri3uTIK7Ubfrg8mDNbl/L3ZKEZHYWR6+2eWwicdh mlCgHFe32qwDtaAYUXsL+v7xPDdEzyenlJfshpXA5xL/zkdtgqcLKJgBB+d5XzZneXe2bz+gWHo v0+rWZR7Yn8lJijihLQZLWatDMMHqo72Jj4T2d7MoQH7U+sSK9CIOPz2RpRMY7PrtZENPve5HCG mhA4YRx0QLwrAK+Inam0Rzwa31gwm+QJelJcU= X-Received: by 2002:a17:902:c946:b0:2ae:5629:ac55 with SMTP id d9443c01a7336-2bea331d50dmr10441855ad.21.1779336927286; Wed, 20 May 2026 21:15:27 -0700 (PDT) Received: from localhost ([2001:569:58a0:da00:a5c8:c4ce:f7c1:40c1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5d234540sm234841675ad.79.2026.05.20.21.15.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 May 2026 21:15:26 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 21 May 2026 00:15:26 -0400 Message-Id: From: "Emil Tsalapatis" To: "Tejun Heo" , "David Vernet" , "Andrea Righi" , "Changwoo Min" , "Alexei Starovoitov" , "Andrii Nakryiko" , "Daniel Borkmann" , "Martin KaFai Lau" , "Kumar Kartikeya Dwivedi" Cc: "Peter Zijlstra" , "Catalin Marinas" , "Will Deacon" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "Andrew Morton" , "David Hildenbrand" , "Mike Rapoport" , "Emil Tsalapatis" , , , , , , Subject: Re: [PATCH 6/8] sched_ext: Require an arena for cid-form schedulers X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260520235052.4180316-1-tj@kernel.org> <20260520235052.4180316-7-tj@kernel.org> In-Reply-To: <20260520235052.4180316-7-tj@kernel.org> On Wed May 20, 2026 at 7:50 PM EDT, Tejun Heo wrote: > Upcoming patches will let the kernel place arena-resident scratch shared > with the BPF program (e.g. per-CPU set_cmask cmask) so the BPF side can > dereference it directly via __arena pointers, replacing the current > cmask_copy_from_kernel() probe-read loop. That requires each cid-form > scheduler to expose its arena to the kernel. Kernel- side accesses are > recovered by the per-arena scratch-page mechanism. > > bpf_scx_reg_cid() walks the struct_ops member progs via > bpf_struct_ops_for_each_prog() and reads each prog's arena via > bpf_prog_arena(). The verifier enforces one arena per program, so each > member prog contributes at most one arena. All non-NULL contributions mus= t > match and at least one member prog must use an arena. The map ref is held= on > scx_sched and dropped on sched destroy. cpu-form schedulers (bpf_scx_reg) > are unchanged - no arena requirement. > > Signed-off-by: Tejun Heo > --- > kernel/sched/ext.c | 56 ++++++++++++++++++++++++++++++++++++- > kernel/sched/ext_internal.h | 8 ++++++ > 2 files changed, 63 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c > index 9c458552d14f..56f94ac32ba0 100644 > --- a/kernel/sched/ext.c > +++ b/kernel/sched/ext.c > @@ -5003,6 +5003,8 @@ static void scx_sched_free_rcu_work(struct work_str= uct *work) > =20 > rhashtable_free_and_destroy(&sch->dsq_hash, NULL, NULL); > free_exit_info(sch->exit_info); > + if (sch->arena_map) > + bpf_map_put(sch->arena_map); > kfree(sch); > } > =20 > @@ -6746,6 +6748,7 @@ struct scx_enable_cmd { > struct sched_ext_ops_cid *ops_cid; > }; > bool is_cid_type; > + struct bpf_map *arena_map; /* arena ref to transfer to sch */ > int ret; > }; > =20 > @@ -6913,6 +6916,15 @@ static struct scx_sched *scx_alloc_and_add_sched(s= truct scx_enable_cmd *cmd, > return ERR_PTR(ret); > } > #endif /* CONFIG_EXT_SUB_SCHED */ > + > + /* > + * Consume the arena_map ref bpf_scx_reg_cid() took. Defer to here so > + * earlier failure paths leave cmd->arena_map set and bpf_scx_reg_cid > + * drops the ref. After this point, sch owns the ref and any cleanup > + * runs through scx_sched_free_rcu_work() which puts it. > + */ > + sch->arena_map =3D cmd->arena_map; > + cmd->arena_map =3D NULL; > return sch; > =20 > #ifdef CONFIG_EXT_SUB_SCHED > @@ -7898,11 +7910,53 @@ static int bpf_scx_reg(void *kdata, struct bpf_li= nk *link) > return scx_enable(&cmd, link); > } > =20 > +struct scx_arena_scan { > + struct bpf_map *arena; > + int err; Can we skip the int err here... > +}; > + > +/* > + * The verifier enforces one arena per BPF program, so each struct_ops > + * member prog contributes at most one arena via bpf_prog_arena(). > + * Require all non-NULL contributions to match. > + */ > +static int scx_arena_scan_prog(struct bpf_prog *prog, void *data) > +{ > + struct scx_arena_scan *s =3D data; > + struct bpf_map *arena =3D bpf_prog_arena(prog); > + > + if (!arena) > + return 0; > + if (s->arena && s->arena !=3D arena) { > + s->err =3D -EINVAL; ...and just directly return -EINVAL here? bpf_struct_ops_for_each_prog breaks when we return non-zero so do we need the extra scx_arena_scan struct? > + return 1; > + } > + s->arena =3D arena; > + return 0; > +} > + > static int bpf_scx_reg_cid(void *kdata, struct bpf_link *link) > { > struct scx_enable_cmd cmd =3D { .ops_cid =3D kdata, .is_cid_type =3D tr= ue }; > + struct scx_arena_scan scan =3D {}; > + int ret; > =20 > - return scx_enable(&cmd, link); > + bpf_struct_ops_for_each_prog(kdata, scx_arena_scan_prog, &scan); > + if (scan.err) { > + pr_err("sched_ext: cid-form scheduler uses multiple arena maps\n"); > + return scan.err; > + } > + if (!scan.arena) { > + pr_err("sched_ext: cid-form scheduler must use a BPF arena map\n"); > + return -EINVAL; > + } > + > + bpf_map_inc(scan.arena); > + cmd.arena_map =3D scan.arena; > + ret =3D scx_enable(&cmd, link); > + if (cmd.arena_map) /* not consumed by scx_alloc_and_add_sched() */ > + bpf_map_put(cmd.arena_map); > + return ret; > } > =20 > static void bpf_scx_unreg(void *kdata, struct bpf_link *link) > diff --git a/kernel/sched/ext_internal.h b/kernel/sched/ext_internal.h > index 7258aea94b9f..d40cfd29ddaa 100644 > --- a/kernel/sched/ext_internal.h > +++ b/kernel/sched/ext_internal.h > @@ -1111,6 +1111,14 @@ struct scx_sched { > struct sched_ext_ops_cid ops_cid; > }; > bool is_cid_type; /* true if registered via bpf_sched_ext_ops_cid */ > + > + /* > + * Arena map auto-discovered from member progs at struct_ops attach. > + * cid-form schedulers must use exactly one arena across all member > + * progs. NULL on cpu-form. > + */ > + struct bpf_map *arena_map; > + > DECLARE_BITMAP(has_op, SCX_OPI_END); > =20 > /*