Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp416578pxb; Wed, 27 Oct 2021 05:31:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1Wr3iphSxct68tV/EOra7xYWrv5uRFu02jzguOe4TL5HyK6TvjZI58JPDI+xI6zAULLhv X-Received: by 2002:a05:6402:270f:: with SMTP id y15mr14409303edd.256.1635337864914; Wed, 27 Oct 2021 05:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635337864; cv=none; d=google.com; s=arc-20160816; b=xtCCMlo5JUaQLtCK+Trzmwv9Ew6vBVS7At+4yegkZyB9Uweka0xyrAQVm67U23xY1x +EMNZ3jJ23f2j7ODV10Na+Ulh81X+a/QrEMZX/JO52mBwaPLp+2FfyhDiZjpyYWfILXd M6GIbNy1kd7TyinbFtoU3N/XY3ehdkabWFUB2/yEJdRsl8kh5LcX46yt1kBYWks4A3jq 0+TxDBnvwTdBso34klEJ+B1p/ZjkpxyIJXp5ssnRwTpFFq+W+ZPB95H1Oe9D6pyX3SbB oEHTmFGT2KJ+BgEbfDLjduzaP+CMVxPNf6d+D8BfyW3m4Nkf8iHumlNtRoOQzErGg0pY 4grg== 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=zi+Ls5+JAndy1ZPzSuOjFuN6VdKyUSUs7sXCMvCwlGg=; b=T55vD3HM+zjoiYNj3yHLvwiDbwtgJafOj9h0WB0clnq5EVU3GXCXu5RNkb4qogUIpu UNRN5mXe3vSCmiMYGUXoTeUHCcifBQDmIHtDovuL9zbia/Xc7EplUjPFXyl2gGPCo7XE XTJsChYXAmXSFvQ+iaTM78+rxFlH2cKUksLOVKkhl6SgyvzWv6U4Qric1G17GCthyO2V vy/k+LL8OQCRFLUp8PB2O504aCLjQA0C8X+H4VcI+zLyc/La4ohoeH8Qy/wZHOcfJt5b q7XyEI/F8XWDapP9jH+1lAdbGWcpyki842K2Py39SVlDR3zDIS52dnIxyOtAG1yen02u 3EKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LJEq0GmS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt7si12593478ejc.688.2021.10.27.05.30.09; Wed, 27 Oct 2021 05:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LJEq0GmS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240095AbhJZWiu (ORCPT + 99 others); Tue, 26 Oct 2021 18:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbhJZWis (ORCPT ); Tue, 26 Oct 2021 18:38:48 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A543C061570 for ; Tue, 26 Oct 2021 15:36:24 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id c4so924774pgv.11 for ; Tue, 26 Oct 2021 15:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zi+Ls5+JAndy1ZPzSuOjFuN6VdKyUSUs7sXCMvCwlGg=; b=LJEq0GmSDjII5qoqNXb8I5W6PisdeBh1LIyMwhPfeH8jzXHP4ZrLifdIwzNQXW8ND+ 56t95Ea/Oqnfk5EEZkWGv95L5UKMfXuEpMIbUg4d2KfjhFvvEHFYMDk4APFQZNapynog DhJ2UCdsyAqV8hPYK36maA4WMOe5o0Op6Zh9He6znf/VlsRMkJ+NiMj4film9/LelDPm XiDOAiK8cMpHJgCHZtb8Uv/+Ko0zhFnqv0fpM4uhiaCjkNvDeNL9YbnC9FFAVxCI0KYT ORxkP+gOODKPJ+VnagaB/IDqovDoYYUu3bs0HutZs8cfVbm9psDQk/fzFx4QVipzGMiL qv6g== 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=zi+Ls5+JAndy1ZPzSuOjFuN6VdKyUSUs7sXCMvCwlGg=; b=EECZre5+ObwuM4C8wp9JwZJrxM6cq413hgAOt/CD3FIb2d+5sRn+qVvxMY4CV3EwuB NG9Qnr0IfwWXc5JlPnydVZ10Rk6WvFzOKO5fgW2cibhjTfIuSOqtR3czEeBQ+iF5oVTw bRs8CkLuOel23VNeoLJoSwz9AuBmscjQmY0If5lBo14nNL/DQxysJBWTKKbB+KG1DMkF ltnIZh0l3T7z6jRlXwhb7Ypv00JEsg0d3i8yyQXMxd7Ly2z4u6pF8uNJNtXJq6sG/aUv PUkTl7EWOcRQtju5nW5s+HxGYLqOTVZgXL5MbfKdKkiMCxFin4k0KrIGSYyzCH8Eo+OS 2Qtw== X-Gm-Message-State: AOAM530cFg9Q0y47EVi/z4d0EWK/8X6O29L1RoLcTf1iwkk/TJs2KauO +q437AHKGkjRKfEMK5nAV0KSQ99ObH1pW4IYaqpOaw== X-Received: by 2002:a65:6215:: with SMTP id d21mr21410794pgv.62.1635287783574; Tue, 26 Oct 2021 15:36:23 -0700 (PDT) MIME-Version: 1.0 References: <20211026222746.403866-1-jevburton.kernel@gmail.com> In-Reply-To: <20211026222746.403866-1-jevburton.kernel@gmail.com> From: Joe Burton Date: Tue, 26 Oct 2021 15:36:12 -0700 Message-ID: Subject: Re: [PATCH] libbpf: Deprecate bpf_objects_list To: Joe Burton Cc: Andrii Nakryiko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, trivial@kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I messed up the mailing lists and will be resending this patch series in a moment. Apologies for the noise. Best, Joe Burton On Tue, Oct 26, 2021 at 3:27 PM Joe Burton wrote: > > From: Joe Burton > > Add a flag to `enum libbpf_strict_mode' to disable the global > `bpf_objects_list', preventing race conditions when concurrent threads > call bpf_object__open() or bpf_object__close(). > > bpf_object__next() will return NULL if this option is set. > > Callers may achieve the same workflow by tracking bpf_objects in > application code. > > [0] Closes: https://github.com/libbpf/libbpf/issues/293 > > Signed-off-by: Joe Burton > --- > tools/lib/bpf/libbpf.c | 8 +++++++- > tools/lib/bpf/libbpf.h | 3 ++- > tools/lib/bpf/libbpf_legacy.h | 6 ++++++ > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 2fbed2d4a645..59d39ce9f375 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -1148,6 +1148,7 @@ static struct bpf_object *bpf_object__new(const char *path, > size_t obj_buf_sz, > const char *obj_name) > { > + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST); > struct bpf_object *obj; > char *end; > > @@ -1188,7 +1189,8 @@ static struct bpf_object *bpf_object__new(const char *path, > obj->loaded = false; > > INIT_LIST_HEAD(&obj->list); > - list_add(&obj->list, &bpf_objects_list); > + if (!strict) > + list_add(&obj->list, &bpf_objects_list); > return obj; > } > > @@ -7935,6 +7937,10 @@ struct bpf_object * > bpf_object__next(struct bpf_object *prev) > { > struct bpf_object *next; > + bool strict = (libbpf_mode & LIBBPF_STRICT_NO_OBJECT_LIST); > + > + if (strict) > + return NULL; > > if (!prev) > next = list_first_entry(&bpf_objects_list, > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index e1900819bfab..defabdbe7760 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -168,7 +168,8 @@ LIBBPF_API struct bpf_program * > bpf_object__find_program_by_name(const struct bpf_object *obj, > const char *name); > > -LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev); > +LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "track bpf_objects in application code instead") > +struct bpf_object *bpf_object__next(struct bpf_object *prev); > #define bpf_object__for_each_safe(pos, tmp) \ > for ((pos) = bpf_object__next(NULL), \ > (tmp) = bpf_object__next(pos); \ > diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h > index 29ccafab11a8..5ba5c9beccfa 100644 > --- a/tools/lib/bpf/libbpf_legacy.h > +++ b/tools/lib/bpf/libbpf_legacy.h > @@ -57,6 +57,12 @@ enum libbpf_strict_mode { > * function name instead of section name. > */ > LIBBPF_STRICT_SEC_NAME = 0x04, > + /* > + * Disable the global 'bpf_objects_list'. Maintaining this list adds > + * a race condition to bpf_object__open() and bpf_object__close(). > + * Clients can maintain it on their own if it is valuable for them. > + */ > + LIBBPF_STRICT_NO_OBJECT_LIST = 0x08, > > __LIBBPF_STRICT_LAST, > }; > -- > 2.33.0.1079.g6e70778dc9-goog >