From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 ADC5B27E05E for ; Sun, 19 Apr 2026 16:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776617623; cv=none; b=LNKta1L0X8d+kXzqOPSPYD58p85w8P04pqA3x9PRRRV8cqsvyQgIxSBFCgBlYh+tVzmcxUTHZNYG0XQOT1zU8lvbBywnH4W/tdZl6L8wvSyzRZm9OwzmpZ37KQWw4eqfearIqdg8sP7JwENIVdp1dqJGOeqAaMM70IAswVqRT1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776617623; c=relaxed/simple; bh=gDEl4ZUxo7xE4AjfX/5d3nOtZRhMgIZF1i1VSNDKRKA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hW+oWWFdMBehtxIGjXOc1lTbROH+9dAzDXvCgD9eVU4Uopc+U1XpKiq4QnD7EQVuw9fJW9zHDocYW4IlyTAuPuZJ2+Kjri4T6l2Ai8vR9JSnMbR/wWu5UtpXHdC8PQ5XzvPM/1veOewHRoAeTxFW3XlJlAXSJ7/vX8oIi7FrOwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UX6byNZg; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UX6byNZg" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c06cb8004e8so736951a12.0 for ; Sun, 19 Apr 2026 09:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776617622; x=1777222422; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NpKw7UI5egXRxsxNzZMiABMaGX0LC5tOT30a5oqSUY8=; b=UX6byNZgx8R84QFmMUs2H/fbpUu/RwYrlnMwKkyyzzpKh/WzDBbpPJqN2cIOhkgEG4 iRpIpgjLZEYR+NPbbOOlSUT1oE53hISlGTxA88VRsIcxUxCrARUs8kyvNrSz9gJdUUBt 16+gl48QU8Dn96oU/wjFPSIzrOrKKg86onREFLIGq9N7Nw/1Q7CiF2efGRYbqCY98HoB MUXdsHi4w5uJtXXAtqLdscbXE4JbTcG8eIWKoLpA9ROJx8sPDxNO5snjfKsCPhg7MArz gwEAsb34/LpLG/Lx6F/qyb9yslKf25dXLfw5Y7Ch5VO56R3II9KCyMiwfseWw3I3Xkxa FGyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776617622; x=1777222422; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NpKw7UI5egXRxsxNzZMiABMaGX0LC5tOT30a5oqSUY8=; b=hQWktiGOTHof2xvG5gEJ1sQ55zA8GpGDwB8df3iDgfUi0Kjj+uWeynPnOWgDD0IwvS UVy4Gvt31xxFz02wXRzZHjHnC+vp98D30DNLyWXs/ic8Yyr8bSRz8vW+F4CkzlyDJIsD vr/g8M8mVcCjqtM44RLb4tSXuLfNCK3+gHu2V6BIy4hlnf3CME5PRIaaqpwd3k2q6iLd E4JhqSZCXaTsCrdvU+jG8UsVMmkVWnQUUp6CM9HvUDiL/LMIQQgCNcJf/r3YXletxwxp yeUPd6AxMs9J10YQ39EudgWtDA+mb3P8K6mWFjT695JEQPcbC6AMCUYcChsFZHyyr8EA S5jQ== X-Forwarded-Encrypted: i=1; AFNElJ9g/iosveV0FVMRZWsYCoOCpSO0AUc2kKg5XJ+ZazFaTlC7FUjoLJGvExSNfFHNBwPS5vYxrrrx5f4wvlk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw67E28S2ycca0egSNsEJbvHExT+Bb0lRDlw7BYyd+CKYhX0CsO NiMBy+v4xqDhH5X8pQq2yX290lpivNq+lDo+Nus9fgIiJFhhvID9IcwX X-Gm-Gg: AeBDieubqTmdhKNfYOJZ2BKL5NXDfeVFChoj00pgfdPEWuOJEzfjxCFgwIcawlDIt2q jQAtrpmlcrYt80PdE0kFmePo7M8sG/5sa1m8kex3uhhEZg3M4H6wnNjMHT76/0KQU8oBsS+CILj 07VAvfzUZEsrSDlAG4hIVsb8xCUJWg2V8rxLYMLjIrfNYn5PEwXE995jNwxh+bwu1u5DWhVfEnv pJUoTLwtSjzTFo8UFYO7ZTaDOBDBZysch0hqki6QVvwno7HYghF/JVec7cAQ3ESUcolZ6YGPPqO K8Ba8IAwDsqW0rJTT9do6J5WuKe+8SKC0OqN2R1PqxrHOTeHev5SSItoQ0ASd1GxEF7awOebd6t a0YsCbLeP4JZlEAsfVZeGyoDRBokhoALNVp0tie1UpkmyNNOenaW16aa8/axoWIbF8JVQiuIThO xuvEFnPrXi/QbQsCNLcgHtmtVU2SBUtzn4ZBmQeqnd67YcVOvW1mafZ2poQzQtlQLsT7bPG/LBG FFED+TPrv+GaFq6 X-Received: by 2002:a05:6a20:1594:b0:3a1:d516:36e5 with SMTP id adf61e73a8af0-3a1d5163aa5mr2390295637.46.1776617621872; Sun, 19 Apr 2026 09:53:41 -0700 (PDT) Received: from cchengyang.duckdns.org (36-225-119-66.dynamic-ip.hinet.net. [36.225.119.66]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976fa40b2sm5466027a12.13.2026.04.19.09.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2026 09:53:41 -0700 (PDT) Date: Mon, 20 Apr 2026 00:53:37 +0800 From: Cheng-Yang Chou To: Tejun Heo Cc: David Vernet , Andrea Righi , Changwoo Min , sched-ext@lists.linux.dev, Emil Tsalapatis , linux-kernel@vger.kernel.org, Ching-Chun Huang , Chia-Ping Tsai Subject: Re: [PATCH sched_ext/for-7.2] sched_ext: Document the ops compat strategy in compat.h/compat.bpf.h Message-ID: <20260420004823.Gde1c@cchengyang.duckdns.org> References: <75aaaf7a4dd540191bd8550dd181528b@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <75aaaf7a4dd540191bd8550dd181528b@kernel.org> Hi Tejun, On Sun, Apr 19, 2026 at 06:18:52AM -1000, Tejun Heo wrote: > The comments around SCX_OPS_DEFINE() and SCX_OPS_OPEN() were vague about > how backward compatibility actually works. Expand them to describe the two > mechanisms: load-time BTF fix-up for additive changes, and multi-variant > struct_ops for incompatible ones. Thanks for improving this. It is much clearer now. Acked-by: Cheng-Yang Chou > > Signed-off-by: Tejun Heo > --- > tools/sched_ext/include/scx/compat.bpf.h | 6 ++++-- > tools/sched_ext/include/scx/compat.h | 23 +++++++++++++++++++---- > 2 files changed, 23 insertions(+), 6 deletions(-) > > --- a/tools/sched_ext/include/scx/compat.bpf.h > +++ b/tools/sched_ext/include/scx/compat.bpf.h > @@ -423,8 +423,10 @@ static inline void scx_bpf_dsq_reenq(u64 > } > > /* > - * Define sched_ext_ops. This may be expanded to define multiple variants for > - * backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH(). > + * Define sched_ext_ops. See compat.h::SCX_OPS_OPEN() for how backward > + * compatibility is handled (this macro can be expanded to emit multiple > + * variants for incompatible op changes; SCX_OPS_OPEN() handles purely > + * additive changes at load time). > */ > #define SCX_OPS_DEFINE(__name, ...) \ > SEC(".struct_ops.link") \ > --- a/tools/sched_ext/include/scx/compat.h > +++ b/tools/sched_ext/include/scx/compat.h > @@ -149,10 +149,24 @@ static inline long scx_hotplug_seq(void) > } > > /* > - * struct sched_ext_ops can change over time. If compat.bpf.h::SCX_OPS_DEFINE() > - * is used to define ops and compat.h::SCX_OPS_LOAD/ATTACH() are used to load > - * and attach it, backward compatibility is automatically maintained where > - * reasonable. > + * Open the sched_ext_ops skeleton. > + * > + * struct sched_ext_ops can change over time. Two complementary mechanisms > + * keep BPF schedulers built against newer headers running on older kernels: > + * > + * 1. Load-time fix-up (this macro). For each optional ops callback or field > + * added to struct sched_ext_ops, an explicit stanza below probes the > + * running kernel's BTF via __COMPAT_struct_has_field() and, if the field > + * is missing, clears it in the in-memory struct_ops (with a warning to > + * stderr) before load. Handles additive changes - a new stanza must be > + * added here for each new optional field. > + * > + * 2. Multi-variant struct_ops via compat.bpf.h::SCX_OPS_DEFINE(). That > + * macro can be expanded to emit several variants of struct sched_ext_ops, > + * and SCX_OPS_LOAD()/ATTACH() can pick the right one based on what the > + * kernel supports. Needed when an existing operation has to change > + * incompatibly (e.g. a callback signature changes); the load-time > + * fix-up above only handles purely additive changes. This is very clear now, thank u! ^0^ > * > * ec7e3b0463e1 ("implement-ops") in https://github.com/sched-ext/sched_ext is > * the current minimum required kernel version. > @@ -225,6 +239,7 @@ static inline void __scx_ops_assoc_prog( > } > #endif > > +/* See SCX_OPS_OPEN() above for backward-compatibility handling. */ > #define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \ > struct bpf_program *__prog; \ > UEI_SET_SIZE(__skel, __ops_name, __uei_name); \ -- Cheers, Cheng-Yang