Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp585442pxm; Wed, 23 Feb 2022 06:51:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyebTOVxLpaS3s2PjruqaKxWuIEGAVm5KfUTLQTydgtKXofel9FYFVUcb9kEVVYbjFrykvo X-Received: by 2002:aa7:d591:0:b0:411:6c4f:1725 with SMTP id r17-20020aa7d591000000b004116c4f1725mr31602997edq.342.1645627859995; Wed, 23 Feb 2022 06:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645627859; cv=none; d=google.com; s=arc-20160816; b=DrRpG7kC4UDwUfgLqCWdla5sPHVEFGBfyPPkKMmbWi7Fpv+NlYkkri9k1M/yP/6mk/ NvCsdflPb7v45SNCirjES86RBvkHs+c7w0KD6TsaS4JOSiWudaVk9+H26He7h622F5WV ocv9Qmeyn9nPiSKpgL33pdwMIKZUt0YHXj8pq01XOVj9M7iZ4wiyjQB41AXriMfN5cNJ kheGoAwXo49BYuH0EbsL5swAgLHEUF3pE8oE6A3XhKhuYFhl9qkeJcVDheAe9JSNlgPe b8koaCmuagL+prZYcMznEEPkQ9Bn8o9plQ1t+N8UqTNsqtlNL9wLyoooVGSLeGmrk8Vf 56mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=I4YatM9dVgUQ9bdK7Uto8GG/pTk0q7IjEJvpLqpQBUk=; b=z2uGcrKYrfaoh1PjmelN2yGWjZmFDjGHVFVM28QjwvxitxJ81SFa9WPgVVt49jKmFY UMlPluO9/XV24KT+9T9/VAm6TXt6xR7wcfeiJPxT1sd6SjGw0AxaP5Fjs2a2kVjfdVSw uzHu+wvP+Dupuk4Ti09qiiNEE+OWBvmVAeOUxZzslEXMZ8oKQ0VZGFVlb2aEFf1xK25K HVLEEQv1CQRCu/Yzo0uBNLTbKtqcLxaMMOUsc4IdMLsT/DAgDlS4izyJA6ckIVUxf51Y S1eSJ51TyNKpPJd0VWBbZ313cHEtSmb5X5U8gZsKcAe82tNCMELNCtVfpS4J7ABuhjtD R+tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dou2LJJB; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12si12508664ejy.969.2022.02.23.06.50.36; Wed, 23 Feb 2022 06:50:59 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=Dou2LJJB; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238552AbiBWCoh (ORCPT + 99 others); Tue, 22 Feb 2022 21:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238142AbiBWCnU (ORCPT ); Tue, 22 Feb 2022 21:43:20 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE8354BF2; Tue, 22 Feb 2022 18:37:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CAB8961526; Wed, 23 Feb 2022 02:37:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35F28C340E8; Wed, 23 Feb 2022 02:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645583829; bh=s9BOfYjtfR3/ei4Ry69xVXoQbSlqAO5tMLRCWBm+dQs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Dou2LJJB1YroYxY1ODiiNPrgTAQR1O4SUnKF7nCxU6gZLa+D3Eum4Eq7/Kmn3eTUO XQWQqa7Qe3Ezzm4Xh2zCmdGY+RVqaijVsZyRNK8He7/8Ko9DNBWhOD2MmPaLa5tWki oMjp2rVGyJSQ3o1SlPPo4yvgdWVOSt6BVLtjtd7uzoqcOsbrK1klAJIQwtLtJZsgBg 3p7Lq7toRyy2ZhiWSAsnLD6XSHkmSoSe21wZSnwyiYO54HqsICVfbolfjdoPNHLuuH sOndmDNtiOo2xUbHiPr6VenTi1Xh4QXPbz/r3DujOA4bCv+LAaeG4Bo8YbTF/9DdsC 8mDYjah3mia9Q== Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-2d6923bca1aso187037667b3.9; Tue, 22 Feb 2022 18:37:09 -0800 (PST) X-Gm-Message-State: AOAM533Us+KL4BmZR/3F+w3SXegwqEkIBeb0A7zR/ivikD6XEI0ks5pI sVUbE0d8sJVP/sobRZHuKp1QrLpjK4S+igP8c20= X-Received: by 2002:a81:c47:0:b0:2d6:beec:b381 with SMTP id 68-20020a810c47000000b002d6beecb381mr22304797ywm.148.1645583828298; Tue, 22 Feb 2022 18:37:08 -0800 (PST) MIME-Version: 1.0 References: <20220222204236.2192513-1-stijn@linux-ipv6.be> In-Reply-To: <20220222204236.2192513-1-stijn@linux-ipv6.be> From: Song Liu Date: Tue, 22 Feb 2022 18:36:57 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] libbpf: fix BPF_MAP_TYPE_PERF_EVENT_ARRAY auto-pinning To: Stijn Tintel Cc: =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Networking , bpf , open list , KP Singh , John Fastabend , Yonghong Song , Song Liu , Martin KaFai Lau , Andrii Nakryiko , Daniel Borkmann , Alexei Starovoitov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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, Feb 22, 2022 at 12:51 PM Stijn Tintel wrote: > > When a BPF map of type BPF_MAP_TYPE_PERF_EVENT_ARRAY doesn't have the > max_entries parameter set, this parameter will be set to the number of > possible CPUs. Due to this, the map_is_reuse_compat function will return > false, causing the following error when trying to reuse the map: > > libbpf: couldn't reuse pinned map at '/sys/fs/bpf/m_logging': parameter mismatch > > Fix this by checking against the number of possible CPUs if the > max_entries parameter is not set in the map definition. > > Fixes: 57a00f41644f ("libbpf: Add auto-pinning of maps when loading BPF objects") > Signed-off-by: Stijn Tintel Acked-by: Song Liu I think the following fix would be more future proof, but the patch as-is is better for stable backport? How about we add a follow up patch on top of current patch to fix def->max_entries once for all? Thanks, Song diff --git i/tools/lib/bpf/libbpf.c w/tools/lib/bpf/libbpf.c index ad43b6ce825e..a1bc1c80bc69 100644 --- i/tools/lib/bpf/libbpf.c +++ w/tools/lib/bpf/libbpf.c @@ -4881,10 +4881,9 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b return nr_cpus; } pr_debug("map '%s': setting size to %d\n", map->name, nr_cpus); - max_entries = nr_cpus; - } else { - max_entries = def->max_entries; + def->max_entries = nr_cpus; } + max_entries = def->max_entries; if (bpf_map__is_struct_ops(map)) create_attr.btf_vmlinux_value_type_id = map->btf_vmlinux_value_type_id;