Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp720447pxm; Fri, 25 Feb 2022 18:16:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+qC4AqHDaAUrq/GfzjAl+sUJvi9Veo47RhXsb9dtq4qO4moyArnAufqRZ8Oxeh7dc/jAw X-Received: by 2002:a17:903:41cd:b0:150:25f6:72d3 with SMTP id u13-20020a17090341cd00b0015025f672d3mr6451224ple.162.1645841781775; Fri, 25 Feb 2022 18:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645841781; cv=none; d=google.com; s=arc-20160816; b=p0QRqUj9qzhw3OJjQjHJIa9aCChdtihqWX0PmEOC5M8IyLBUAQLy+PctDKxFDOvFxL lZOp7dgz3wvrVKaZ7p8nWvvYWsGJQvFhU0smEYeQWPz0qu0GDPfEJebf0TZjzS6ThAyP UuiNDw//+JQEeIu4diQFrXa4x0p6bSaemk/fWOvz4sEjtxwL0gIm7Y1vteSOsUYOr7TS ZL3bjdkslyzfOWgBBz+a47/GOOLQL/7o3Hid/paCwyUZx/MM3HWVTKraYTiF9h66o2PL QrZYB5yZUCr5LsC3ftCTbmFQeB4LXWdgvtDRJlUCErCgl9Ec8Xo9iCJRvrAQlcd05ccV 9Lmg== 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=TgXYH8j2FJr1LILDF/hRmhyDS9MNzgumIXS4nA17ut4=; b=BOY8bHbGHKQSlTPtxl23yGsMUaumOIxPaOKKlbSTY16ndw5ejPPhABNP/wQ9JECXkQ qIlPyv4nq5Aq1Vx3f5qgS0bj5sSXRM6+6zcC7C772UOKp17cnL/fNEjQWdikDdL34JR1 x2Zc/q17vi9qHay2DE1D3I1xEDmEr2tca5ytbXEGgTEUwfKY4BnlA9tIQIdNByTPYvS2 fTHs09ST7e2mq/qHgP827F4KeJVzbHYdw2TtuSwd/QKhbEigEnEq4QfiRbmIV75QlDeS UczpS94x6O9yXevEB9vaQoBswzDiZ0bfzr7ipbSkF1omzYRyaWwdRIDecOizxG929jDf 8vfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PTsKY8Kv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y12-20020a17090322cc00b0014f109b73b1si3502644plg.138.2022.02.25.18.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:16:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PTsKY8Kv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6E467261015; Fri, 25 Feb 2022 17:49:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237115AbiBYDss (ORCPT + 99 others); Thu, 24 Feb 2022 22:48:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbiBYDsr (ORCPT ); Thu, 24 Feb 2022 22:48:47 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673BF100740; Thu, 24 Feb 2022 19:48:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id 20B1BB82AB8; Fri, 25 Feb 2022 03:48:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECC2C36AE7; Fri, 25 Feb 2022 03:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645760893; bh=XbIdx5w3wAprKXy+9pfHp8DmIKHPkFnU3GHbmyvUfIA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PTsKY8KvrAMKpjcPQRV+T71bV3SdCbVYzuBinz9JIyrKnj45DxpR6nXk92NW7MEBk 0CzovK3Z9cIrJWuF26NvBKI1n8GE5rkNDfW3qbgcJj2OOGfjEX9sfDDfxUsO3RI/qk 81TCenbM7mVCaHgcS4u8i3BjwvgjvkdCL6OZOvmSQm+FkaB8Vlqx7cEQ5jvDIrJznQ E9C5egYT1iyhLt4FH+P65Mo9UcMdz3B1rdt0pFV6AU1s34Po9HOkXaOUI9qnt458Qg gj5zO2TOehM53nvUnqLoSWkupD9tuf+gffOyhXWP57O2/hHTSXVuqlqCQ3L5xubj82 ASsxGYl45Ludg== Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-2d310db3812so20384727b3.3; Thu, 24 Feb 2022 19:48:13 -0800 (PST) X-Gm-Message-State: AOAM533/B59SyY+9o7VwzTGVV6oU/sYRZJIl5qPP8YX41ttjXhJNHyh1 /RxZ+Sj1mCEJu8mZvqTirjHPKF5XEKgnIl72FNM= X-Received: by 2002:a0d:fb45:0:b0:2d0:d09a:576c with SMTP id l66-20020a0dfb45000000b002d0d09a576cmr5794606ywf.447.1645760892770; Thu, 24 Feb 2022 19:48:12 -0800 (PST) MIME-Version: 1.0 References: <20220222204236.2192513-1-stijn@linux-ipv6.be> <0f1fb86b-f8df-b209-9a89-512cbc142e04@linux-ipv6.be> In-Reply-To: <0f1fb86b-f8df-b209-9a89-512cbc142e04@linux-ipv6.be> From: Song Liu Date: Thu, 24 Feb 2022 19:48:01 -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: Andrii Nakryiko , =?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=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, Feb 24, 2022 at 7:38 AM Stijn Tintel wrote: > > On 24/02/2022 12:08, Stijn Tintel wrote: > > On 24/02/2022 01:15, Andrii Nakryiko wrote: > >> On Tue, Feb 22, 2022 at 6:37 PM Song Liu wrote: > >>> 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? > >> Keeping special logic for PERF_EVENT_ARRAY in one place is > >> preferrable. With this, the changes in map_is_reuse_compat() shouldn't > >> be necessary at all. Stijn, can you please send v2 with Song's > >> proposed changes? > >> > > Will do! > > Unfortunately that doesn't work. In bpf_object__create_maps, we call > bpf_object__reuse_map and map_is_reuse_compat before > bpf_object__create_map, so we check map_info.max_entries == > map->def.max_entries before the latter is being overwritten. > > So I propose to send a v2 based on my initial submission, but use __u32 > for def_max_entries instead of int, unless someone has another suggestion? How about we move if (def->type == BPF_MAP_TYPE_PERF_EVENT_ARRAY && !def->max_entries) { ... } to bpf_object__create_maps() before bpf_object__reuse_map(). And maybe add a helper function with it? Thanks, Song