From patchwork Tue Oct 26 22:27:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Burton X-Patchwork-Id: 12585847 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 903BEC433EF for ; Tue, 26 Oct 2021 22:27:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4523F60F56 for ; Tue, 26 Oct 2021 22:27:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4523F60F56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B2E91940007; Tue, 26 Oct 2021 18:27:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADD966B0074; Tue, 26 Oct 2021 18:27:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F3B9940007; Tue, 26 Oct 2021 18:27:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 8C8C56B0073 for ; Tue, 26 Oct 2021 18:27:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 40EDA8249980 for ; Tue, 26 Oct 2021 22:27:52 +0000 (UTC) X-FDA: 78740027184.08.ECA8A8E Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf01.hostedemail.com (Postfix) with ESMTP id ACCB35088FB1 for ; Tue, 26 Oct 2021 22:27:44 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id k2-20020a17090ac50200b001a218b956aaso598993pjt.2 for ; Tue, 26 Oct 2021 15:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l6j46Ws58hCljuR8NCqQZteT2C36qK9PN69x2iQopUA=; b=RiyH1MAUmDpDYAaqftu7hK2mF+EV9QSOtTteYwUlF9KfBFbDI36fHOlNpxBE3gFamQ ILnu/vcbTT57havEJQTW9sxR0CN7qoqErr4hI1S9veHhkdYz6/V3dDkPRt6K34/FlzRW Cba0NTPyKs9GcLUhhstUnzxYMsa2o8AOqkBW1UoKI0mzwcBj+EfZTx/FDnFQD7PEbpG6 8gCfbbqezjOqkGw9VQU41lHSy45d8OwpJVhRXYYaed6lUDA2gxk00uiSOwQAVZoW4MJK zBNUmoje8QNvfLBOxxHFwDBuNiXlZoq+7HidasNtcs9UVbWsC6FjGJIO2oKLnoFvInsu 1ZOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l6j46Ws58hCljuR8NCqQZteT2C36qK9PN69x2iQopUA=; b=tTo8QGs20f8SBHt572JD3jLtE3O8T4Iex68oRijeWeStrQbzVqWqlko8A7DveVkXY9 Ul01afe6EV8Y22uMt3fqlEPy2FQvTVm8OBOWTwRNBNgmyR7YBNqRHNLt7tCgN8Q2BHUH q/+ql6LzLOrMtwnAAN1mO8/jh3G/PYhD2TxL1H7essWKxr8NIfyo9WVD1xHltnk1QYRX xLqt+MXZzDkzSAVSmgd0ykn/MsI8x5Au665MI/cWJWXqEb/1z6lkMJLtdVdNKE0pCx9r cO5kDD1DCEr3N8U0cOrZSJR7bu6ZyksPAoYR/XX3YhLi4Cvz2ZcK3z2SQzBHXLw8Ax/j FY2A== X-Gm-Message-State: AOAM532dI5W81y5Jipnbg0Of+R4ntRLbIv0d4nQqiNV5cvfxToR0oMOq mbOjwZJ5p6t6Yt7ii/iBhA== X-Google-Smtp-Source: ABdhPJzUAlM/fZYGpnNP9uF9B6KtqvrrC1iPk+1bcWyA9dpLAH/tditgXJu9IkE+2tljnSzpDwmFQg== X-Received: by 2002:a17:90b:33c7:: with SMTP id lk7mr1707693pjb.172.1635287270856; Tue, 26 Oct 2021 15:27:50 -0700 (PDT) Received: from jevburton2.c.googlers.com.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id t22sm4401685pfg.63.2021.10.26.15.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 15:27:50 -0700 (PDT) From: Joe Burton To: Andrii Nakryiko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, trivial@kernel.org, Joe Burton Subject: [PATCH] libbpf: Deprecate bpf_objects_list Date: Tue, 26 Oct 2021 22:27:46 +0000 Message-Id: <20211026222746.403866-1-jevburton.kernel@gmail.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ACCB35088FB1 X-Stat-Signature: foo84tbewdt1j169i399ug378puqsmwo Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RiyH1MAU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of jevburton.kernel@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=jevburton.kernel@gmail.com X-HE-Tag: 1635287264-260050 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: 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, };