Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1053705pxm; Wed, 23 Feb 2022 16:57:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwP/cW51+kivx+8GexU8C6J8xjnN+v+jYVsw1Zyg8LMWN2JaP+UDpuLoIZThQQ2mVa6U/z6 X-Received: by 2002:a17:90a:bf8f:b0:1bc:4ae6:e009 with SMTP id d15-20020a17090abf8f00b001bc4ae6e009mr217089pjs.127.1645664269381; Wed, 23 Feb 2022 16:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645664269; cv=none; d=google.com; s=arc-20160816; b=A7M5O6nklvLzgsxn4gQ9WbwKVwMUiIwS8beeszXX3kC7LA3K7dUXaC15ckKqtmhKvf lxAVqVTldXsWrHt6xJXuZ4Qjy462WmbynUr+OaofkwaVJ/msDpt0b7korXPjb5+PXQJH z6iCmtlu7qjuh/pRnhdBPrmgosTvZNua2fVmGQbJ+98/W/UK0Pz/6RfNVf8CJxL/bqq4 svDiiQc03A4JUBfou+6Ho5c93CUPZhu1s4UacNPrm3xu7JkZhW/u0xDo/NTC5arv5EIL 7b84EPcOSznGsjclBXStFtFyZ0DoUh8cKpkzx0o63Sz4o0Xw5OpTB+lOzS2YpDEy7aep waDw== 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=P25Zfn5c3BtqYaoA6/wRj29feqJY0Zz0Nev1IhUk9Dc=; b=w7CPYMhBADlgQg35VrCHE2yxJ8xPut8CRxfugEbE9fwUzdSe9v2DUI+iZWAOrtbPLk ISGe0FhCQOfl+e7y7DqWN/0ZVUj+FXTQkYSRUmS0skrJx9+eTOqQ/+jmqVf31842HX5F vfbPaNE+GorHpGOqBsQxVztnaVpUxYRApxNzOAFA+eO7qSMLoPvRfbEsO8ONDrZ7DotB MJ55UEDKbdOP/COsub8gG/T2h/aOvFjfBEkOnaugG9OwGk3w76U0iSUmEBLLk8lipCu5 DS4IjiqDAOe3yef6CHrekVRo71JQGdb52TbzTzBrMDdpSo3RY3wQqc3kwr7onx+Bz+7M StnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HfHAa2uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l10si1296305pgp.92.2022.02.23.16.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 16:57:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HfHAa2uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BDFA1F7452; Wed, 23 Feb 2022 16:50:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244747AbiBWXQK (ORCPT + 99 others); Wed, 23 Feb 2022 18:16:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236982AbiBWXQJ (ORCPT ); Wed, 23 Feb 2022 18:16:09 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2351357150; Wed, 23 Feb 2022 15:15:41 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id w7so728785ioj.5; Wed, 23 Feb 2022 15:15:41 -0800 (PST) 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; bh=P25Zfn5c3BtqYaoA6/wRj29feqJY0Zz0Nev1IhUk9Dc=; b=HfHAa2uKg47YCKjW0CQBrlojE22jxt/8JNZubtz/35jfAp6QaO8wnHBFEPeo2fSHkK SlW5+ZEyXEaPUU8AlTeR+Eaixz0FpST78wWFjKrpAKpQ9O+dAFJFZ9RzEtHzFygvvCJ+ Ypwhe6dTmaxzM8AXonk9ymSZPpsyYGxoLUMTJd68Yq5ahc5pSE4No3w0ybWVdkDpZ46r G4Rubvbu3Z9xV+KKf58+xb8TeYWX/97dGaGioNDNPx92V7kCUeBFObmLNJeRTQsaMNUK 25JhzDK+vd5H7pthS2OpoR/ffvFhd4p3UthPI131UoaRCQ9esrbZOUYHrkoJNG2024rk eS1g== 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; bh=P25Zfn5c3BtqYaoA6/wRj29feqJY0Zz0Nev1IhUk9Dc=; b=0r0zHnATpRnEAJre4YWhRGz3getxQq+71bFd8emRhnGnBHferDdgzOrDQWFT88o8bC +fmgyWiOI0DdTkWRBL/rVg95iopHBbSaHbsoKjIQBIAbyff6x33m5Du/LEusNP9VDcTh RgZoj4yPvYSHqFySW7faS2WmzhZavEApjqPjNrrvNJYYa9XEuspUZhQH+VvVVHPxfVaZ Newwq510RnTuY4IZ2PGQANPa34LjKETkxO8xI4QXgLPcGNa4c9G9UjNoNOgONtsWq2J/ X7eo+wpebBOUFc5cIeaXADr5W1jyamMcBt0T22HJPfnuZSpd3WjivLkGkeSuZmqdOmaR exnw== X-Gm-Message-State: AOAM5327tVoGUrquZNT+Er/7OUgVzQlkuJ0Ok9a8w5MGtLG9pMCJnDtj R31wESD69wCZehdcn4KVDt5899RTNs6YzpnXTR0= X-Received: by 2002:a05:6602:3c6:b0:63d:cac9:bd35 with SMTP id g6-20020a05660203c600b0063dcac9bd35mr8474iov.144.1645658140535; Wed, 23 Feb 2022 15:15:40 -0800 (PST) MIME-Version: 1.0 References: <20220222204236.2192513-1-stijn@linux-ipv6.be> In-Reply-To: From: Andrii Nakryiko Date: Wed, 23 Feb 2022 15:15:29 -0800 Message-ID: Subject: Re: [PATCH] libbpf: fix BPF_MAP_TYPE_PERF_EVENT_ARRAY auto-pinning To: Song Liu Cc: Stijn Tintel , =?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=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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? > > 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;