From nobody Sat Feb 7 17:55:59 2026 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.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 DE9783B531A for ; Thu, 15 Jan 2026 15:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490457; cv=none; b=BMFoKrn4O0RHe23ZHJq3eA3XNwXqAgVDVM+iuHpT4dSeY0kraPKRJX6Ei4EA8Fmu8fzxcm6RIkJ+pGdA7XQNINLMLoycd4v3l4jVCC435EJrzSqhwZEqwvX4BGoRyNacURZt/XAMHoz+Ih07kGYf6ki/nHdqmr9m5D1KWjWs5yM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768490457; c=relaxed/simple; bh=/gkJg9IVFWdPTJ/KUF0SD0LhkJXLVBhh48Owqpafbh8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=pTniILj2I5r99dV2S2rt/tyzlUo0xxe3RXv1OzVKdMsM03XgooC+8yKhHA8dDXGmHl3QI4f8mxZwXQZSYEov7Bm8sbqzDviQ0BAWh08zqn9NwUIFBsTXauvTXMZpi8kJnPiINU7FntWUJXfZVa+CAypHQMtBEbVknWJZAMX17Ts= 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=nTVxOFoP; arc=none smtp.client-ip=74.125.82.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="nTVxOFoP" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-2ae29ddaed9so1063637eec.0 for ; Thu, 15 Jan 2026 07:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768490449; x=1769095249; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3WBE7yLTwXJvXQknW3m3j/e1SLsqAi1Kc4r688prtj4=; b=nTVxOFoP86xkwaK+7aZ8P7Wm1/z6k04KGbiNk9xqGDP+OGqmMJIf3ssmgDd5Sh0gyQ 2u/ayY7yfP0JPtkzuM9bsVdV0LfERkCVv6Giu9+SFN2sVr6XbaomYQnfHPV+381MMjfc wyYeo39jzAImgWbYQ2NoXa85XcTrmofHuszFREvW/JhmoRlewsokYQcRNPcuMAwkNTxV P3DV9Ipjc0SdiFRMQHA3m9QwxrfYpEtjTEqWgc3w+aR+U2rYFvgCwnWWpGhXLbHhTJl3 lbLfMT7bQMxgNkfjEP3AHcigSwRMulpXZWzKVqsbIod9DxrcRxlLTEngGHShS9OkjXz2 i4og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768490449; x=1769095249; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3WBE7yLTwXJvXQknW3m3j/e1SLsqAi1Kc4r688prtj4=; b=wIS2kfbgWafVdUeD4ArefdcQOfS82/PrikAmrDXPlYGEooXkPKyl//9T0EIDqZYHeM wpX+y5ZsA/vjgjBQUi83qZb8QMjwWWNpBZbwM+H6pfEAOTB8lZWZ1NLnjRCdlK3fCte/ 2Csv5ic1QWOOXgeOKJqFIJEWrDjGvJAGSqO3XWb0pI8tYQd56vSexIH74wLJf0PLPz8N n52v3oei17NaqV9aHQtTsgkMoi5/c2JqdvYM02EmG++YSkoyhSoJJUlSd0K0YMixiKI+ OfKFPZdwUEqrk0CWAWUU1PjZNZ2WO5bYnlHUGJzqrkxFh0mpwDczP/U069X8p+S+axoy Y+aw== X-Forwarded-Encrypted: i=1; AJvYcCUOUQrQr5XF9Vq9Zf3OE628bgENDZAZri5NwZIFuOs04ccJ4XP37/EhpiT5LLsoHzbbC2SFHG/atZpxCVQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yydvgc+cqxvJbeBBZq7Pjx1TmTtUkk79cHf/HWlClS5uW8fkIxQ xtjSeV06IqINPx4gJoGcHIqxgoTdvA0MzvTmAIR+y97OvT2G50Jayd1Y X-Gm-Gg: AY/fxX7yVe5y+yJ+oUPqk3DAlav6Ro6O2TlXZzgZIBbl4rpmJvn2GTl12Zj9CMNW3fK 7OQUWFynL5TWjfTV1WOfc6Zo+a+gGAuxiF8d29f5qRxQ+ZomtXsjoklidzqp9y4pAreVLPgu4It ZCFc9mtF0Faw0VuEoFX9I4eohIq/UYiaeGthKIpzSzyua3+OKE7PBMEXyM9GqAMsQfLaoX3VsnR 0iK8KnBdRsuPj2o3uJL58VcnU8chxNbg9NYOIggXaYn/6UAB1zKo+//7V5dNCQ4uGAZ+LklDFJd MvttRZGvCQqpDPfsPcBXyU/5vpiO8UYIk9NY1Y6DSG98I5BH+6gvniRmU6PyMoEbce5GxkRGDhy Iig9hKvxo29an7t3zwP/J1WOUKQraLQIQAUVaHMEy4qLPtDVBh3tlYCJm/1Un0Tb1ZeMSZK4EL9 3hFasIOOCWcr0YbsrTz0YYZ08= X-Received: by 2002:a05:7300:f60b:b0:2ab:f74a:6a63 with SMTP id 5a478bee46e88-2b6642f0eb1mr4561885eec.16.1768490448477; Thu, 15 Jan 2026 07:20:48 -0800 (PST) Received: from localhost.localdomain ([74.48.213.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b17078d9b1sm23544610eec.18.2026.01.15.07.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 07:20:48 -0800 (PST) From: wujing To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, wujing , Qiliang Yuan Subject: [PATCH] bpf/verifier: compress bpf_reg_state by using bitfields Date: Thu, 15 Jan 2026 23:20:37 +0800 Message-Id: <20260115152037.449362-1-realwujing@gmail.com> X-Mailer: git-send-email 2.39.5 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" The struct bpf_reg_state is 112 bytes long on 64-bit architectures, with several fields that have limited ranges. In particular, the bool 'precise' at the end causes 7 bytes of padding. This patch packs 'frameno', 'subreg_def', and 'precise' into a single u32/s32 bitfield block: - frameno: 4 bits (sufficient for MAX_CALL_FRAMES=3D8) - subreg_def: 27 bits (sufficient for 1M insns limit) - precise: 1 bit This reduces the size of struct bpf_reg_state from 112 to 104 bytes, saving 8 bytes per register. This also reduces the size of struct bpf_stack_state. Overall, it reduces peak memory usage of the verifier for complex programs with millions of states. The patch also updates states_maybe_looping() to use a non-bitfield boundary for memcmp(), as offsetof() cannot be used on bitfields. Signed-off-by: wujing Signed-off-by: Qiliang Yuan --- include/linux/bpf_verifier.h | 6 +++--- kernel/bpf/verifier.c | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 562f7e63be29..0f83360afb03 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -196,14 +196,14 @@ struct bpf_reg_state { * is used which is an index in bpf_verifier_state->frame[] array * pointing to bpf_func_state. */ - u32 frameno; + u32 frameno:4; /* Tracks subreg definition. The stored value is the insn_idx of the * writing insn. This is safe because subreg_def is used before any insn * patching which only happens after main verification finished. */ - s32 subreg_def; + s32 subreg_def:27; /* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */ - bool precise; + bool precise:1; }; =20 enum bpf_stack_slot_type { diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 378341e1177f..5e5b831a518c 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -19641,10 +19641,12 @@ static bool states_maybe_looping(struct bpf_verif= ier_state *old, =20 fold =3D old->frame[fr]; fcur =3D cur->frame[fr]; - for (i =3D 0; i < MAX_BPF_REG; i++) + for (i =3D 0; i < MAX_BPF_REG; i++) { if (memcmp(&fold->regs[i], &fcur->regs[i], - offsetof(struct bpf_reg_state, frameno))) + offsetof(struct bpf_reg_state, ref_obj_id) + + sizeof(fold->regs[i].ref_obj_id))) return false; + } return true; } =20 --=20 2.39.5