From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B05D3C433F5 for ; Tue, 26 Oct 2021 22:35:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39E0E6109D for ; Tue, 26 Oct 2021 22:35:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 39E0E6109D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 99FCE940007; Tue, 26 Oct 2021 18:35:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94F106B0074; Tue, 26 Oct 2021 18:35:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8162A940007; Tue, 26 Oct 2021 18:35:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id 6EDDE6B0073 for ; Tue, 26 Oct 2021 18:35:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3142231E71 for ; Tue, 26 Oct 2021 22:35:03 +0000 (UTC) X-FDA: 78740045286.18.8FB2370 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf24.hostedemail.com (Postfix) with ESMTP id DCF8CB0000BB for ; Tue, 26 Oct 2021 22:35:02 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id g184so948540pgc.6 for ; Tue, 26 Oct 2021 15:35:02 -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=tEaKx0CzKAhddjW+TyG3Ds3sT6FS7SR45apT6txoxWM=; b=Mf9CO+SSYy2+hNM/hbtQrQEKbmRd98Zmv2Zd4kjwrMRkDLsORIw3On/e+ABYOZdbV8 okUP/8ocevMi8nGIy/GcgcNilXDqJynro+zmnDl2OOkrkiJ7U/qovHORCHd9KmWQhCNO lYzmQLadQeNK74sbwaAb6NeA4u/d40CK2lSH/RpiP+rGnbHv4Ff5JS/piA0/2PlKUQL4 I9RDz9WtL6zj8+jlxCWta61nyoJx0J0DqLIvbcyxRR7vxt728iHWfVhONTIULfnw/tt0 WY1vK5pm1QcNVga3DRZWjnChPafGqWPcNKW+NPlf3Z/RKust944WRlz7DDK/KGRqRdyi 4qow== 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=tEaKx0CzKAhddjW+TyG3Ds3sT6FS7SR45apT6txoxWM=; b=W5cFRsHpfswjhhJLGzvCstWSTYtapoayxi/Hg+cpT/2Rr1ZMU1RxYYCpiNDh98GSOT aOqog1KsXAksFRTb2bs6XUGZm4VYJM/ePMbIcWf91/V0rsS07Ppns701JTeT0jR7p0FW jwglUwhXslH2LtBbtM6VihMmhTYj4bMeqS2aPLt2ed2WAW76bCdgX6WYViiR8+Q2uF10 whznOB+WX1c4rYTFH4YyxEtBD7aCjgXZPPbW1mupZspq765JVcKbN6YVlrtOtAv1x0yX nTI8toAGBVG0kynaa+T6kMC3AKwSxpQuyE1aWgKUkW5Sx2CSlyIfidNOfQIHwtpUzUg0 mB7g== X-Gm-Message-State: AOAM531Q7U+tv7OgZV2RQ4KCGSz8eW2N/6YbqTVmJ0eD/i+wHC/i/2rc +RjUdqRhgyRFdD2ZjIMfxIV1rS2SFdX/MsnZ+CcYIw== X-Google-Smtp-Source: ABdhPJwMRdYLyaqg28btVr8zIzdodWOtJD7yvmUHbb5TFicN57rzTl9Syx3sv1CC0R9Mm/slagNLV9jaP/1KVb2D/VE= X-Received: by 2002:aa7:8111:0:b0:47b:e311:cdae with SMTP id b17-20020aa78111000000b0047be311cdaemr20488242pfi.71.1635287701749; Tue, 26 Oct 2021 15:35:01 -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:34:51 -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: multipart/alternative; boundary="00000000000091df0505cf4916b4" X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DCF8CB0000BB X-Stat-Signature: yayx5tsadw1qbag3ouh16xszhn9m9rfk Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Mf9CO+SS; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of jevburton@google.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=jevburton@google.com X-HE-Tag: 1635287702-991952 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --00000000000091df0505cf4916b4 Content-Type: text/plain; charset="UTF-8" I missed 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 > > --00000000000091df0505cf4916b4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I missed up the mailing lists and will be resending this p= atch series in a moment. Apologies for the noise.

Best,<= /div>
Joe Burton

On Tue, Oct 26, 2021 at 3:27 PM Joe Burton <jevburton.kernel@gmail.com&= gt; wrote:
From:= Joe Burton <j= evburton@google.com>

Add a flag to `enum libbpf_strict_mode' to disable the global
`bpf_objects_list', preventing race conditions when concurrent threads<= br> 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.

=C2=A0 [0] Closes: https://github.com/libbpf/libbpf/issue= s/293

Signed-off-by: Joe Burton <jevburton@google.com>
---
=C2=A0tools/lib/bpf/libbpf.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 8 +++++++-
=C2=A0tools/lib/bpf/libbpf.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 3 ++-
=C2=A0tools/lib/bpf/libbpf_legacy.h | 6 ++++++
=C2=A03 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,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 s= ize_t obj_buf_sz,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 c= onst char *obj_name)
=C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool strict =3D (libbpf_mode & LIBBPF_STRIC= T_NO_OBJECT_LIST);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct bpf_object *obj;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 char *end;

@@ -1188,7 +1189,8 @@ static struct bpf_object *bpf_object__new(const char = *path,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 obj->loaded =3D false;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 INIT_LIST_HEAD(&obj->list);
-=C2=A0 =C2=A0 =C2=A0 =C2=A0list_add(&obj->list, &bpf_objects_li= st);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!strict)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0list_add(&obj-&= gt;list, &bpf_objects_list);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return obj;
=C2=A0}

@@ -7935,6 +7937,10 @@ struct bpf_object *
=C2=A0bpf_object__next(struct bpf_object *prev)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct bpf_object *next;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool strict =3D (libbpf_mode & LIBBPF_STRIC= T_NO_OBJECT_LIST);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (strict)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return NULL;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!prev)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 next =3D 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 *
=C2=A0bpf_object__find_program_by_name(const struct bpf_object *obj,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const 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 applic= ation code instead")
+struct bpf_object *bpf_object__next(struct bpf_object *prev);
=C2=A0#define bpf_object__for_each_safe(pos, tmp)=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for ((pos) =3D bpf_object__next(NULL),=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (tmp) =3D bpf_objec= t__next(pos);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
diff --git a/tools/lib/bpf/libbpf_legacy.h b/tools/lib/bpf/libbpf_legacy.h<= br> 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 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* function name instead of section name.<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0 =C2=A0 LIBBPF_STRICT_SEC_NAME =3D 0x04,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/*
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * Disable the global 'bpf_objects_list'= ;. Maintaining this list adds
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * a race condition to bpf_object__open() and b= pf_object__close().
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * Clients can maintain it on their own if it i= s valuable for them.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0LIBBPF_STRICT_NO_OBJECT_LIST =3D 0x08,

=C2=A0 =C2=A0 =C2=A0 =C2=A0 __LIBBPF_STRICT_LAST,
=C2=A0};
--
2.33.0.1079.g6e70778dc9-goog

--00000000000091df0505cf4916b4--