Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4102618imw; Tue, 12 Jul 2022 01:40:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sDKyV2BtU8jHqj8HoySqWIqyp43P7zrDSLXvX+wuE4Kh+5DgJSHM7DzOBDTMyvSEJ2LXhg X-Received: by 2002:a17:906:5055:b0:6ff:1dfb:1e2c with SMTP id e21-20020a170906505500b006ff1dfb1e2cmr23492884ejk.200.1657615244626; Tue, 12 Jul 2022 01:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657615244; cv=none; d=google.com; s=arc-20160816; b=XLLMPzgo7Q1rtRZmozTEmd3crdd6lLf704mOlxDO9JtXKW//TLMMZb5GIsiwCeG9g0 osNW8/p+2pEVqp7s0UtRzYf/0um8kQB3k4zSCqNhLTfC5NnReCOJs+44mPVdVn8SuekC ObeDR/ZQkxGfRMwdoW1j8JSCA4b29rmJEcbOY26jhQmFfbhAxsEOakCPmTbSmf+p7KzU N1F1hQdNDYo5eF2xsGVE3ALA3g9CKZI5eF2mVZVfIkVeG5gpCflOf9HbteGDOJ5eRrAz G/css/n39EkBSWXX97pflLnNw7YRjNHHVd2L+Qqal0SkIzBozqtZ9T+VILFkitU5cxR8 JI1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=Rw0D6MOQNgwtHVy5EHhS3LDpVuivadaMB6MVJn/OAoU=; b=03WP8e3ADB6CyKWkp0SEK/wW5RBzjllPIHF6afGiBw7E45HqxB8dvs0jgbK3E+WZtr fDjXMiRmH7iUpk8n1zA5U8ATt3+HIxdoPCloRV/y/N5TM+IlhrMNmoj0O5RxZ5OLDT2c DVqBPl3KpJE2bu9TFXjqbyJoanKbssE4QY4GqCyH3j/CWYnAU+8T0/SZhJd0/yZCr9/D M4LR2ORCUkb+6dzYdJdl04ylzJC1YisWyEelkbyW03pKfw02ZhaO/BiGsRoc6NSfM3+G MNUQhWiBaQylSPFUb+z9xAgmPY6P/EoJEweBPTo6OxeK36LUvK1PS5ZKDJyTgOO2zA+b BysA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QzuplMgf; 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 d21-20020a170906345500b00722fb2281c0si11952942ejb.417.2022.07.12.01.40.19; Tue, 12 Jul 2022 01:40:44 -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=QzuplMgf; 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 S232340AbiGLIb4 (ORCPT + 99 others); Tue, 12 Jul 2022 04:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232347AbiGLIbv (ORCPT ); Tue, 12 Jul 2022 04:31:51 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F0BA44C9; Tue, 12 Jul 2022 01:31:49 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id u12so13010210eja.8; Tue, 12 Jul 2022 01:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Rw0D6MOQNgwtHVy5EHhS3LDpVuivadaMB6MVJn/OAoU=; b=QzuplMgfE/kFHk61XSAFjXkGGpuBQb8Y4wEsuENnY4rAjcrt0BRibp8s0SR3/Q2ubn GgGQgJw5rN0SzQOG41e2Dpfo1zJNPW7JhLwTbWRER4JrUR5e0aPuxPWXjSc9Vile+IuV ozVYcMd5XDdrueeXqCWgYwRaRCXJPADE/PGCVHRhI9jlAkHVMJ3ihOT8v7SbH3YMbI4r NGdlCKDXzZVA5DPbqotjPS0Cd5INpaKe7/hJPms0iF22a4KW5egfcAhcUzPWNady0kEk LljI14XabSEc8dUlW/D3tnqeHRr4waCa60/k3BbQ714FGUGGnudFBhPltOuW8w9lyg25 qWNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Rw0D6MOQNgwtHVy5EHhS3LDpVuivadaMB6MVJn/OAoU=; b=KA2yYBd1tHPB7P2IIn6RKJKgwKd3K1Q55Vv4++j3u2Z8/cdiXRG0je9F7GhGqF8xt7 AIwWEuI/O5heT5SRKXccgJ9uvaIOgfLkWa3hS3CMprutjodBLDB+8o3wtu42n4f5/Hec h7uK6+yYY3jmoQslbcw3SBBsSZtQOQY6TJeiUTwM9emTCOq65N0iAlbOqbH9ZGXZVwi3 Ba+T0ay/gWqY55slgOSeVVhUwJPSQfBdtarEgs3GfDJbHxW6WdJvVP5XPkU5LRqssKL3 bI5gI1zk452BfKiA7sCtlabh45bdsU08rNlH+K9O+goqiXdD3SOeIL7+rOqM+Pw358MB VoPQ== X-Gm-Message-State: AJIora9gtHjbcbBCtS/LaCb7ap+KtnGVrpW/Jy8YKOiDbr1aFRB2WuL9 4uKb4dH48/VT1+RdRgq/ZT8= X-Received: by 2002:a17:907:2cca:b0:72b:4188:f95b with SMTP id hg10-20020a1709072cca00b0072b4188f95bmr14594494ejc.153.1657614708272; Tue, 12 Jul 2022 01:31:48 -0700 (PDT) Received: from krava ([151.14.22.253]) by smtp.gmail.com with ESMTPSA id fd9-20020a1709072a0900b006fed062c68esm3531509ejc.182.2022.07.12.01.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 01:31:47 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 12 Jul 2022 10:31:45 +0200 To: Anquan Wu Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] libbpf: fix the name of a reused map Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Tue, Jul 12, 2022 at 11:15:40AM +0800, Anquan Wu wrote: > BPF map name is limited to BPF_OBJ_NAME_LEN. > 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, > it can not get bpf_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="/sys/fs/bpf/process_pinned_map", > bpf_fd=0, file_flags=0}, 144) = -1 ENOENT (No such file or directory) > > bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, > value_size=4,max_entries=1024, map_flags=0, inner_map_fd=0, > map_name="process_pinned_",map_ifindex=0, btf_fd=3, btf_key_type_id=6, > btf_value_type_id=10,btf_vmlinux_value_type_id=0}, 72) = 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 > --- > > v2: compare against zero explicitly > > v1: https://lore.kernel.org/linux-kernel/OSZP286MB1725A2361FA2EE8432C4D5F4B8879@OSZP286MB1725.JPNP286.PROD.OUTLOOK.COM/ > --- > 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..7b4d3604dfb4 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 = {}; > __u32 len = sizeof(info); > + __u32 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 = strdup(info.name); > + name_len = strlen(info.name); > + if (name_len == BPF_OBJ_NAME_LEN - 1 && strncmp(map->name, info.name, name_len) == 0) so what if the map->name is different after 'name_len' ? jirka > + new_name = strdup(map->name); > + else > + new_name = strdup(info.name); > + > if (!new_name) > return libbpf_err(-errno); > > -- > 2.32.0 >