From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 25DFC17A309 for ; Tue, 16 Dec 2025 02:38:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765852738; cv=none; b=TSRSax9yKCg/AUrSD8DLayz5IQDvbvNS1DS7Ix9igQecnDLxM86hHn2P6g7c9HIOAtbdQkgQc6iS0h3MVvOb7ep4TFLarXxbd//FTekbz+a9agg6yxXj951h98zHco+yUB5OoaXXxRYg2ET6cAGqE9HedGBuV2/c2G8B1X3TQao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765852738; c=relaxed/simple; bh=CRqvv3fNFlF/pMhl/fYHATl3VT03MbTVoZsGl5GO+QA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=ZoxPd1CzNNPvPLvsd0OPHiTFwHcARNyouStOESVuYKbqme1N/+3+GmEHkkZ7aJSjLFvtp8ve2mQNTB7IWjgXernECYgVXmDcmob+o275wTx0LAuTmbOKy49+zdFVbsePz/9kmcwCW9LmWldap83lvFnIWD5EWQTJUpvWPi+qFZ4= 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=KI60THRW; arc=none smtp.client-ip=209.85.210.181 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="KI60THRW" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7aae5f2633dso4369385b3a.3 for ; Mon, 15 Dec 2025 18:38:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765852736; x=1766457536; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=PFYZGHPIDqEcscjEAD6wlaUMrMUa0OQ70xZuQLsYAvQ=; b=KI60THRWvUfwjZyfazfiOG3enHDWoYijAokjxAqVpx4IL7nsdSmsqS/mxGYpC89QkG WXOZ8jTxlOhxLYQwAd6JGB1RKV2lEienrcMv2dX0ht65qsRhrXtPB9samXUejzxBwczh HrFDux3KXLJi27iZPYh+6+JelljLCzz1/QCogkkfXlu7N9+DrfkewbjSclTi1XeaH3kL LrSIeDPH8YV/rArcldbF01ZPnwniCLf8W+xo10wAi3M4UzWa/jy5IgezhxUMP6giddIN 3S2biSdvx0n97qmxWa/oVHxocGg1le8OhrMNO7u/CCyHzWvMncXCIaElFvkuMIo5YvsM vWvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765852736; x=1766457536; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PFYZGHPIDqEcscjEAD6wlaUMrMUa0OQ70xZuQLsYAvQ=; b=FNMQYd+4PjEgaKXqSFdvglnTZOF/jCj/qRd99XKpe3Uotw8ue0Y7iZLCG64cf2mhV5 2hO23NszxL5fQ/ubsI0XOVXD309pf6AJqTmUSQ+je4elSU9jfDRQgu5r1LODwD0G5K70 yWmjbz7lVlaZeIyQkLyewbXy6yZ4mR7F/YLwWXObOT07zT+rmqTkVNY881lUhSSYZOhO C6e9gZrfNdZr5jDs5+A6zC5mT/jLBuwEIml7VY/RtBUagrw61hTfBL3N581LONexuLnM JFri3qFQonWxGQzmQgFG25hyWTgKHHO2aflTK1OUmEeDSy0roNDRB6VcIcJgRTgsPgQ4 Y9Hg== X-Forwarded-Encrypted: i=1; AJvYcCWattrYo+CuABAARvu7JNAYnz/6fJrHX79wUSYO6VLr9xzB0To6aIM+J+/1RvSfLmyNlr9E/u6Gj8Zbfjw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5260D9IXAmlf7nl/40CiB1iIVr5AbroL1djQAudmnj6ojJzOW pEqoZ7di18XB9l/VUbrLGfyMPOVzkYsmWmMq7hSsxQjfVkpTTd3dw7rv X-Gm-Gg: AY/fxX4orfwnS4paK/jnien3Ek4EivPtofL3vKmhTuHCKqG71oBH0IE05wUEyjeo0iJ atHm4ymJodHwUFgEgpf/zzUpqbCHV6aHmaF6j+a6S6L6GCn13E42s31dnl0AQIqEoApLl37OOD9 Rf5wx4nB72V3jH2IwCUqJcVd+qj8Wv1vNYXzu5QUmLzplAstdogptkczTQiqJ0r0MYhoU/IbrLo /pQszLTaeZHCy8IGfjGTvHss75T046kFXHxQy/73rF6AJ9Rac2nQGugEGV0bzcPyUOKhPYoQmYB Tlqgj78u5Tlwk9tgAWCxCmX98loZyFylFEtqnZTo0kRBWnJtvKPA8aZyT52VwqoqnNs4mZM8T8C nS13SdMe6S8m5227GlEFRINzg/Oeg+0/yPGvS1WpT0AQvtQJHMCFDa6o+xyJ2RQMdNFNro9OA8v fOvinxtcJs X-Google-Smtp-Source: AGHT+IHEIg3J+lGR4aNsRmfuVPwq4rJAZ56la77XOJ3WlFamSh1GHnswzh6XaH/onObOFEP5iTw7DA== X-Received: by 2002:a05:6a20:3d05:b0:35d:8881:e6a4 with SMTP id adf61e73a8af0-369b4c32d75mr12649177637.25.1765852736157; Mon, 15 Dec 2025 18:38:56 -0800 (PST) Received: from [192.168.0.226] ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c11d3e8af1asm8153533a12.2.2025.12.15.18.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Dec 2025 18:38:55 -0800 (PST) Message-ID: Subject: Re: [PATCH bpf-next v3 3/6] resolve_btfids: Introduce enum btf_id_kind From: Eduard Zingerman To: Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrew Morton , Nathan Chancellor , Nicolas Schier , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Shuah Khan , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Date: Mon, 15 Dec 2025 18:38:52 -0800 In-Reply-To: References: <20251205223046.4155870-1-ihor.solodrai@linux.dev> <20251205223046.4155870-4-ihor.solodrai@linux.dev> <386068b11e146a9dbb502f770d7e012e3dea950f.camel@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2025-12-15 at 18:31 -0800, Ihor Solodrai wrote: > On 12/11/25 11:09 PM, Eduard Zingerman wrote: > > On Fri, 2025-12-05 at 14:30 -0800, Ihor Solodrai wrote: > > > Instead of using multiple flags, make struct btf_id tagged with an > > > enum value indicating its kind in the context of resolve_btfids. > > >=20 > > > Signed-off-by: Ihor Solodrai > > > --- > >=20 > > Acked-by: Eduard Zingerman > >=20 > > (But see a question below). > >=20 > > > @@ -213,14 +218,19 @@ btf_id__add(struct rb_root *root, char *name, b= ool unique) > > > p =3D &(*p)->rb_left; > > > else if (cmp > 0) > > > p =3D &(*p)->rb_right; > > > - else > > > - return unique ? NULL : id; > > > + else if (kind =3D=3D BTF_ID_KIND_SYM && id->kind =3D=3D BTF_ID_KIN= D_SYM) > >=20 > > Nit: I'd keep the 'unique' parameter alongside 'kind' and resolve this > > condition on the function callsite. >=20 > I don't like the boolean args, they're always opaque on the callsite. >=20 > We want to allow duplicates for _KIND_SYM and forbid for other kinds. > Since we are passing the kind from outside, I think it makes sense to > check for this inside the function. It makes the usage simpler. On the contrary, the callsite knows exactly what it wants: unique or non-unique entries. Here you need additional logic to figure out the intent. Arguably the uniqueness is associated not with entry type, but with a particular tree the entry is added to. And that is a property of the callsite. > > > + return id; > > > + else { > > > + pr_err("Unexpected duplicate symbol %s of kind %d\n", name, id->k= ind); > > > + return NULL; > > > + } > >=20 > > [...] > >=20 > > > @@ -491,28 +515,24 @@ static int symbols_collect(struct object *obj) > > > id =3D add_symbol(&obj->funcs, prefix, sizeof(BTF_FUNC) - 1); > > > /* set8 */ > > > } else if (!strncmp(prefix, BTF_SET8, sizeof(BTF_SET8) - 1)) { > > > - id =3D add_set(obj, prefix, true); > > > + id =3D add_set(obj, prefix, BTF_ID_KIND_SET8); > > > /* > > > * SET8 objects store list's count, which is encoded > > > * in symbol's size, together with 'cnt' field hence > > > * that - 1. > > > */ > > > - if (id) { > > > + if (id) > > > id->cnt =3D sym.st_size / sizeof(uint64_t) - 1; > > > - id->is_set8 =3D true; > > > - } > > > /* set */ > > > } else if (!strncmp(prefix, BTF_SET, sizeof(BTF_SET) - 1)) { > > > - id =3D add_set(obj, prefix, false); > > > + id =3D add_set(obj, prefix, BTF_ID_KIND_SET); > > > /* > > > * SET objects store list's count, which is encoded > > > * in symbol's size, together with 'cnt' field hence > > > * that - 1. > > > */ > > > - if (id) { > > > + if (id) > >=20 > > Current patch is not a culprit, but shouldn't resolve_btfids fail if > > `id` cannot be added? (here and in a hunk above). >=20 > By the existing design, resolve_btfids generally fails if > CONFIG_WERROR is set and `warnings > 0`. >=20 > And in this particular place it would fails with -ENOMEM a bit below: >=20 > [...] > } else if (!strncmp(prefix, BTF_SET, sizeof(BTF_SET) - 1)) { > id =3D add_set(obj, prefix, BTF_ID_KIND_SET); > /* > * SET objects store list's count, which is encoded > * in symbol's size, together with 'cnt' field hence > * that - 1. > */ > if (id) > id->cnt =3D sym.st_size / sizeof(int) - 1; > } else { > pr_err("FAILED unsupported prefix %s\n", prefix); > return -1; > } >=20 > /* --> */ if (!id) > return -ENOMEM; >=20 > So I think an error code change may be appropriate, and that's about it. Oh, ok, sorry, didn't notice that. >=20 > >=20 > > > id->cnt =3D sym.st_size / sizeof(int) - 1; > > > - id->is_set =3D true; > > > - } > > > } else { > > > pr_err("FAILED unsupported prefix %s\n", prefix); > > > return -1; > >=20 > > [...] > >=20