From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 939ACC77B7F for ; Thu, 18 May 2023 01:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbjERBmT (ORCPT ); Wed, 17 May 2023 21:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjERBmR (ORCPT ); Wed, 17 May 2023 21:42:17 -0400 Received: from out-29.mta1.migadu.com (out-29.mta1.migadu.com [95.215.58.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D4F123 for ; Wed, 17 May 2023 18:42:15 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1684374130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n3gOJF+MXOBVq1iRu2W9W0FS9rlAZbKgdHYpF5mdLYw=; b=RwU0TiOxw2327F+kMmXihTAd02Cf701OOjP6FIfyfSwLCMe+5ycqEHxO7MkapmNHhUgOod AcQ0y+gwx7ckF42fBknrcDX8s3rp+wiyro0mZdGDtyrqe2EtxncGed5ryW6E2oxtBs5VDX j2+9myDtAVqH1UktlLEJFbwifSlgY7E= Date: Wed, 17 May 2023 18:42:06 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next] bpf: btf: restore resolve_mode when popping the resolve stack Content-Language: en-US To: Lorenz Bauer Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa References: <20230515121521.30569-1-lmb@isovalent.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/17/23 2:01 AM, Lorenz Bauer wrote: > On Wed, May 17, 2023 at 7:26 AM Martin KaFai Lau wrote: >> >> On 5/15/23 5:15 AM, Lorenz Bauer wrote: >>> In commit 9b459804ff99 ("btf: fix resolving BTF_KIND_VAR after ARRAY, STRUCT, UNION, PTR") >>> I fixed a bug that occurred during resolving of a DATASEC by strategically resetting >>> resolve_mode. This fixes the immediate bug but leaves us open to future bugs where >>> nested types have to be resolved. >> >> hmm... future bugs like when adding new BTF_KIND in the future? > > It could just be refactoring of the codebase? What is the downside of > restoring the mode when popping the item? It also makes push and pop > symmetrical. I can see your point to refactor it to make it work for all different BTF_KIND. Other than BTF_KIND_DATASEC, env->resolve_mode stays the same for all other kinds once it is decided. It is why resolve_mode is in the "env" instead of "v". My concern is this will hide some bugs (existing or future) that accidentally changed the resolve_mode in the middle. If there is another legit case that could be found other than BTF_KIND_DATASEC, that will be a better time to do this refactoring with a proper test case considering most bpf progs need btf to load nowadays and probably need to veristat test also. If it came to that, might as well consider moving resolve_mode from "env" to "v". btf_datasec_resolve() is acting as a very top level resolver like btf_resolve(), so it reset env->resolve_mode before resolving its var member like how btf_resolve() does. imo, together with env->resolve_mode stays the same for others, it is more straight forward to reason. I understand that it is personal preference and could argue either way.