From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QB9K0PZA" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [IPv6:2001:41d0:203:375::aa]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFEE10D9 for ; Fri, 8 Dec 2023 20:16:01 -0800 (PST) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702095359; 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=N4mWm4jjvNU/rXOEij3EsaxTs47CVNTndbWcwE88nEc=; b=QB9K0PZAOy8Dg4ZahcEVMmWs7qbr+7zH3wIK7e53gMbHri2NO1vMvHAXEedXyMBDQLlY8n DTwmmhAacaZRRHeCSULLdRbPTCEtasJ2BmLSAkds3/PbYsNb0HSfXq+LmSzlCGVrnTkBfH tm6ErW05SLHefi4cYSNuwW3LsMYTRCE= Date: Fri, 8 Dec 2023 20:15:50 -0800 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 6/7] libbpf: BPF Static Keys support Content-Language: en-GB To: Alexei Starovoitov , Andrii Nakryiko Cc: Anton Protopopov , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Jiri Olsa , Martin KaFai Lau , Stanislav Fomichev , bpf References: <20231206141030.1478753-1-aspsk@isovalent.com> <20231206141030.1478753-7-aspsk@isovalent.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 12/8/23 8:05 PM, Alexei Starovoitov wrote: > On Fri, Dec 8, 2023 at 2:04 PM Andrii Nakryiko > wrote: >> >> I feel like embedding some sort of ID inside the instruction is very.. >> unusual, shall we say? > yeah. no magic numbers inside insns pls. > > I don't like JA_CFG name, since I read CFG as control flow graph, > while you probably meant CFG as configurable. > How about BPF_JA_OR_NOP ? > Then in combination with BPF_JMP or BPF_JMP32 modifier > the insn->off|imm will be used. > 1st bit in src_reg can indicate the default action: nop or jmp. > In asm it may look like asm("goto_or_nop +5") How does the C source code looks like in order to generate BPF_JA_OR_NOP insn? Any source examples? > >> 2. bpf_static_branch_{likely,unlikely}() macro accepts a reference to >> one such special global variable and and instructs compiler to emit >> relocation between static key variable and JMP_CFG instruction. >> >> Libbpf will properly update these relocations during static linking >> and subprog rearrangement, just like we do it for map references >> today. > Right. libbpf has RELO_SUBPROG_ADDR. > This new relo will be pretty much that. > And we have proper C syntax for taking an address: &&label. > The bpf_static_branch macro can use it. > We wanted to add it for a long time to support proper > switch() and jmp tables. > > I don't like IDs and new map type for this. > The macro can have 'branch_name' as one of the arguments and > it will populate addresses of insns into "name.static_branch" section. > > From libbpf pov it will be yet another global section which > is represented as a traditional bpf array of one element. > No extra handling on the libbpf side. > > The question is how to represent the "address" of the insn. > I think 4 byte prog_id + 4 byte insn_idx will do. > > Then bpf prog can pass such "address" into bpf_static_branch_enable/disable > kfunc. > > The user space can iterate over 8 byte "addresses" > in that 1 element array map and call BPF_STATIC_BRANCH_ENABLE/DISABLE > syscall cmds. > We can have a helper on libbpf side for that. > > I see no need to introduce a new map type just to reuse map_update_elem cmd. >