Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3746644imw; Mon, 11 Jul 2022 15:09:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sHFKDIoTqpP307F0EQ0GuP893m/bFz6cocn9znFqVOBzBCgktvcvjpm0ZJ9ycCjoqD/RAk X-Received: by 2002:a17:90b:4d85:b0:1ef:9fd2:b789 with SMTP id oj5-20020a17090b4d8500b001ef9fd2b789mr584927pjb.196.1657577390098; Mon, 11 Jul 2022 15:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657577390; cv=none; d=google.com; s=arc-20160816; b=rcCgbrkpkR4t640kzSijajU12dA5zytsxZ2tp96XXBIXT6MprMZ79nZUd9arkI2K7b mQq04ix4mEmpf1FhjvZEEE3kCMjsxv8uUl5YK7uBDEWhhzIoizsjMKQxMmIKMwOtuj9N lwptrLSM5g1DvJCO59YRveQyRa7AJkRqBEHrAO07EIGjw+edJm7DO8z85futs+rihXH4 VfxZ5ojKo7wsyT1i/lm8MukdLHqAeILj5gDhV3xAeavE7LyiAh2dOyuXymL/WEZUysS4 c5gAFa3cHRQsYu8i+nY/iKU2M3uwwCGoEbyGH+sdlFFV7BJDLYKZRS3yJIIMjTLZRqXs Y2kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=esp4On95It78UY+94ldWZ+H1EyZMthkKoxOCUCFzVnU=; b=nfwR5t6ltKxLEOPdmX99BKuxZIvK2RDFf8nKctdffRvBfEoLvbD+NE8Al5iSocTMI5 ies+2AFFCOyB/w7nTb2cUNOfebWYHGyXRlhT0VNgK0npzGQSp6pF6FG1dCB09Z82aO38 FIP5JCdg3xNAECRZvWW/ZRia6QCfHY9QcsJ+3UQwFdgmln2Uq4V24uZSYUgdYrcW5gWy SezFSVLIQAuq/nvsoBR4aQw6HAKZcfkQTx816Lc6FcHt2eJS2EDDoxPkCNqzsGZQl/hd 6VVXZ7eNQjMnH7cZLBfJ6hO/Msw0CZcDPTq1aCLjs/TARfaIUETvAtyWRgSAvyLgnc9f eFuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=obZrw5Lq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lk8-20020a17090b33c800b001ec85d2ffb3si14484127pjb.53.2022.07.11.15.09.37; Mon, 11 Jul 2022 15:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=obZrw5Lq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232100AbiGKVwR (ORCPT + 99 others); Mon, 11 Jul 2022 17:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbiGKVwN (ORCPT ); Mon, 11 Jul 2022 17:52:13 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F4961139 for ; Mon, 11 Jul 2022 14:52:12 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id h23so11041896ejj.12 for ; Mon, 11 Jul 2022 14:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=esp4On95It78UY+94ldWZ+H1EyZMthkKoxOCUCFzVnU=; b=obZrw5Lqskc4Y5dqaR7jt3QEsxsxFtfK7lWukJ43RxLFVf3xc931wi+gIrLdntuB/V U4unyM+XOaDIFZfJeJXkhqKqKro2lhZt8+lGJ867bS2QIfrwdd/Tr68a7iCX6HPXFfAL w0d/IscwKtQIeqyS6B2aKyx/lQZZMNjdcIg3dl1XKyTEeITZTqB3UePB3KTWO9JqQ/4P R+WqcNtoy4bqZ+WdtPTcyP4URUoFOkzJfwvD/EOSSKeW33RsBo6LLxdtTZHXuraFLbzr pOBYRiabq2poPMfeuRmOrSP3Lahh4llmWHqTEIX/DOoe9BQR5ya5LOi2ifuw314sAfSZ OBIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=esp4On95It78UY+94ldWZ+H1EyZMthkKoxOCUCFzVnU=; b=vVMs6esIe4g3X4+dpgY/tD29TK3u1XnoYj/01Aog3T2kUsHg1FjqonFeRIRd/RJcqu GaRYXwHJFvLJBa5eKcN/YcVMW5wRdqbMZn9m1ID61AvGP15UGeqKi4nUaC2NW45fxdwy TQytN7fCIWApRLq9pdUevDyRm8oDi43PU1mwPpaQ1n5OlPLynYjN8RJnR+OX1VFiSPTW pULtYUHmccHL2Da8duZx1elu/FXtXdhEgLAgRBtItgmfvqNlA01pLQik5lU1W1fT6gI8 zWv2PIU8/5x2UqWBzomjLgHRQcIcfF5wrJLEosQoLYhRxjXayNzGNkaRsjPlG+tDhGZY btMg== X-Gm-Message-State: AJIora+u9WjthgSfp5D/YjTe4ylhG48kFg08bL/P+IiZMKUaU4K18FU+ sI5WVCqD3CsCvDO4DQJoF4KBxhWlbDRT4IRs0is= X-Received: by 2002:a17:907:2808:b0:72b:4d49:b2e9 with SMTP id eb8-20020a170907280800b0072b4d49b2e9mr9693124ejc.176.1657576331202; Mon, 11 Jul 2022 14:52:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Mon, 11 Jul 2022 14:51:59 -0700 Message-ID: Subject: Re: [PATCH] libbpf: fix the name of a reused map To: "anquan.wu" Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , martin.lau@linux.dev, john fastabend , open list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 11, 2022 at 3:25 AM anquan.wu wrote: > > BPF map name was limited to BPF_OBJ_NAME_LEN. > If a map name is defined as being longer than BPF_OBJ_NAME_LEN, > it will be truncated to BPF_OBJ_NAME_LEN > when a userspace program calls libbpf to create the map. > A pinned map also generates a path in the /sys. > If the previous program wanted to reuse the map=EF=BC=8Cit can not get bp= f_map > by name, because the name of the map is only partially the same as > the name which get from pinned path. > > The syscall information below show that map name > "process_pinned_map" is truncated to process_pinned_" > > bpf(BPF_OBJ_GET, {pathname=3D"/sys/fs/bpf/process_pinned_map", > bpf_fd=3D0, file_flags=3D0}, 144) =3D -1 ENOENT (No such file or director= y) > > bpf(BPF_MAP_CREATE, {map_type=3DBPF_MAP_TYPE_HASH, key_size=3D4, value_si= ze=3D4, > max_entries=3D1024, map_flags=3D0, inner_map_fd=3D0, map_name=3D"process_= pinned_", > map_ifindex=3D0, btf_fd=3D3, btf_key_type_id=3D6, btf_value_type_id=3D10, > btf_vmlinux_value_type_id=3D0}, 72) =3D 4 > > This patch check that if the name of pinned map are the same as the > actual name for the first (BPF_OBJ_NAME_LEN - 1), > bpf map still uses the name which is included in bpf object. > > Signed-off-by: anquan.wu please use your complete and capitalized name in Signed-off-by Overall, looks good, I have a few stylistical nits, see below. But also you forgot to cc bpf@vger.kernel.org, please send v2 and don't forget to add mailing list. Without that our CI can't test your patch properly. > --- > tools/lib/bpf/libbpf.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index e89cc9c885b3..5ad52a8accd1 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -4328,6 +4328,7 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd) > { > struct bpf_map_info info =3D {}; > __u32 len =3D sizeof(info); > + __u32 name_len; nit: __u32 len =3D sizeof(info), name_len; > int new_fd, err; > char *new_name; > > @@ -4337,7 +4338,12 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd) > if (err) > return libbpf_err(err); > > - new_name =3D strdup(info.name); > + name_len =3D strlen(info.name); > + if ((BPF_OBJ_NAME_LEN - 1) =3D=3D name_len && !strncmp(map->name,= info.name, name_len)) nit, unnecessary () around BPF_OBJ_NAME_LEN, plus the order is a bit weird. I also have general preference with strncmp/strcmp to compare against zero explicitly, so can you rewrite this as: if (name_len =3D=3D BPF_OBJ_NAME_LEN - 1 && strncmp(map->name, info.name, name_len) =3D=3D 0) ? > + new_name =3D strdup(map->name); > + else > + new_name =3D strdup(info.name); > + > if (!new_name) > return libbpf_err(-errno); > > -- > 2.32.0 >