From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 843C9247DE1 for ; Sat, 30 May 2026 01:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780104211; cv=none; b=bikYFiP6/rXz8/+g1mBuC5WreddFWuX19z08GxEKraDvP0N19iZVl3v+LbdKxVj6M5zmQ+XqKYxvd+m48TiJUrXb3wU0jVvy3twU/7fRYt5+IWdRMQWF5UI9dI4TI1k04etUGYBYFf3sXyov9uD6ztORwre/+PQF+itYOxBzqYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780104211; c=relaxed/simple; bh=BtaYKpTPJilCTGNFssblfegA2Q/llZ2Ei2qTZMpuJQ8=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=IDDZFtqIRLCgPZQhq2kzi8a2By8zVxtYEscSt3iRoOi0ik6bxqKT3TTPqFxKoImnnSaATtj7Og1dD53znPRUiZcs65/YYzyW2pOHPeu+NIJWh65tL5FFYl+GJReczetWl5eqOXrFU/JsHyuwAInnxDQACY4d939LlOCWowyOuZ4= 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=g5b6N6hy; arc=none smtp.client-ip=209.85.210.44 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="g5b6N6hy" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7e61da76fd9so5184277a34.0 for ; Fri, 29 May 2026 18:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780104209; x=1780709009; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tfTiRoOM8MzpyQ3L15jEBMe4g863/IvoH5IPT22XTg0=; b=g5b6N6hyOXYuFMjhD6fZWBOiORGJf3Yg7DPvBAStagCuCBp9RqB/RXy0PPLFwlE5IK Rb0k1giFoafrOPvQwaJDkzyTYH6rqzBILvGWYaVdo7+q55oocgna5e9VnCnLIK8wcJyU wtnkXcg6Xvt9YJfa/6//eAyCIv3ksnTW/U2tjgz31oce8ekIudgZLUGzZ+tfufMGIYFG FT1Ye5ttp2PCardBqolnEq1Xr/rIVaLgnINY2IH5pKDqwWI5ZZ7UUqcbHsbFoVd7Vjzc qi+UCsD3h0j6uaB0heEVP2KPnhpBQhBJVrb4hFChWXFOFArYpdpOx9O3LuLjVLQHRLrO KGhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780104209; x=1780709009; h=in-reply-to:references:to:from:subject:cc: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=tfTiRoOM8MzpyQ3L15jEBMe4g863/IvoH5IPT22XTg0=; b=C9+j35y7qrY9PnuBmBaDp17Ef/ql/YvDwE3aMe5zfXsDjjubm9JaSXo8+MowOSPsqE v9NvTOCj6nucU/mYHoxt1J0bbEkQVNdut5DhIBLeuD0HrcrE+fW1Lpj1sZs/9I/uYFxf rsFWAp+i5afQ0n7PHQgf7InCNFEuz+aYR59v9rBocUC6vudxDX6UFUQnLJMlf/NvpEWT 3N5nVUcq47aVJyaf1k4ZWY7Ry1QchzhEECsttcm54iTvV2KK5suvOfT2v8vK80TEUocs 4hlMfwfln7ULC2ZXr0dvNixKqwn2dbKfAoE+P2AFj0oRZ+gztFivrJNj4AYHCtHEjFsk RBDw== X-Forwarded-Encrypted: i=1; AFNElJ9/RBpx1pBshOsND2fgNri5sAutFJ0dfZg8AZxMclkCvVttPV4A3nl7ki+4LoHRprPxfRtolGKtGcpK0k8=@vger.kernel.org X-Gm-Message-State: AOJu0YyPPGarjH206szLSZMGg9gLpLUum854EXYMCFoM1UY9qSsri1Dc kaHRVP4R8o2wXd0lwYWYI6Z+Z0AiGTctQvKAocyTUveDvwiGVMNdlyTVsI/orw== X-Gm-Gg: Acq92OFpctp+fWkDTJ6m4/Z+Sj62SfQCAGIZWn2ujAZayJP3SN1mFi/1btXYo1jYhYf GuBSyY3j2T3nksSN2R//MoMSXW3iL7r2Yu+q9IkMl1L+S29/eii8yBi5+TBQXWWiPR5oAabHy3g CLiUx13wl19Gn3K027Qhp+5EQ9UwPhJGlEyu8lNOv/alHSy6S2uA7NEdQ87WPkxXXq5tf9y6RTy qD5vQ6NHhEd4EM2fX+dHeuIMQYnpr++Z5mS2d9qh9QlpNeZbAV4YCrqfRjnf2fbvt8Ie05K4PU7 YCYoghmPBDFb4YHeKV3LAAXIIrQBgNCfuDsSWpEdqf0tzdb5qh4QNsIOlWNVOH46G6s84okmc4Z P60v3H7o1rCqSuVtzpwZy4YoiLXmh4MQuaBJPqCZEm6hWUoAPury3cMa8Sw6lXDHqmhbY8eiO2E jahm19O9JicggNh2T7cPl0df9BbRXQZfEmrAWvgCYSv8vpW7f+lZfmXqZxTHEh6KH6qRp00R0z2 xlzyhwO3exGxVdqrO900Xudr7o= X-Received: by 2002:a05:6820:4df9:b0:69d:eccd:f54a with SMTP id 006d021491bc7-69e10308376mr832561eaf.23.1780104209345; Fri, 29 May 2026 18:23:29 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:9::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69e0677268dsm2056831eaf.1.2026.05.29.18.23.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 May 2026 18:23:28 -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: Fri, 29 May 2026 18:23:26 -0700 Message-Id: Cc: , , "Song Liu" , "Andrii Nakryiko" Subject: Re: [PATCH RFC] bpf: add DAG fast-path in verifier to skip redundant state pruning From: "Alexei Starovoitov" To: "Seunghyeon Lee" , "Alexei Starovoitov" , "Daniel Borkmann" X-Mailer: aerc References: <178004391665.3522.4865582628003357086@gmail.com> In-Reply-To: <178004391665.3522.4865582628003357086@gmail.com> On Fri May 29, 2026 at 1:38 AM PDT, Seunghyeon Lee wrote: > bpf: add DAG fast-path in verifier to skip redundant state pruning > > The BPF verifier's state-equivalence loop (is_state_visited / > states_equal) dominates load time for programs with acyclic control > flow graphs (DAGs). In a DAG, every instruction is reached via exactly > one path: no state is ever revisited, making state-pruning comparisons > mathematically vacuous. > > This RFC proposes three components: > > 1. compute_dag_topo() -- replaces a simple is_acyclic_dag() bool. > Uses Kahn's algorithm (O(V+E), O(V) space, no recursion) to detect > back-edges AND preserve the topological visit order for use in (2). > Handles BPF_JMP32, BPF_LD_IMM64 wide instructions, and falls back > conservatively on BPF-to-BPF subprogram calls. > > 2. do_check_dag() -- fast-path verifier for confirmed-DAG programs. > Critical correctness property: maintains a per-instruction state > table (states[insn_cnt]) and, at every join point (in_degree > 1), > calls merge_verifier_state() to conservatively merge all incoming > paths BEFORE processing the instruction. This ensures the verifier > never sees a register as initialized when any predecessor path left > it NOT_INIT. > > Skips is_state_visited() / states_equal() entirely; provably safe > because topological order guarantees each instruction is processed > exactly once. > > 3. Full fallback: if compute_dag_topo() returns NULL (cyclic program, > subprog, or allocation failure), or if do_check_dag() returns an > error, the unmodified do_check() runs unchanged. > > Register-state correctness at join points > ----------------------------------------- > When paths A and B converge at instruction N, the verifier must hold > the least precise state that is safe for both paths. > > Path A arrives at insn N: R2 =3D scalar [0, 5] > Path B arrives at insn N: R2 =3D NOT_INIT > merge_verifier_state() result: R2 =3D NOT_INIT > -> verifier correctly rejects any use of R2 at N > > Without this merge (a flaw in naive linear-scan approaches), the > verifier would see only the state from whichever path was processed > last in memory order, potentially accepting a program that > dereferences an uninitialized register at runtime. > > RFC design question: > -------------------- > do_check_dag()'s inner per-instruction verification step requires > calling into do_check()'s inner loop logic, which is not currently > factored as a callable sub-function. We propose two integration > options and request maintainer guidance: > > Option A: Extract a verify_one_insn() helper from do_check()'s > inner loop; do_check_dag() calls it per topological step. Specializing the verifier for DAG only case is not interesting. Almost all programs now contain loops. But the approach to use do_check_insn() as a transfer function in the data flow analysis is totally viable. I've been prototyping such transfer + join verifier for some time. Will share soon. What merge_verifier_state() does is a key.