Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp416906pxb; Wed, 27 Oct 2021 05:31:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMcheG5b2fBDNN0tCpvrkGsg7UFeMb80FTi9GaW0Y0ZtM4mxz356kUcH1CalOceSc3VR3d X-Received: by 2002:a17:906:2cc9:: with SMTP id r9mr38640880ejr.138.1635337879152; Wed, 27 Oct 2021 05:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635337879; cv=none; d=google.com; s=arc-20160816; b=DhqDVyqU8pLOB88kyjrsAXsUskVjN5/sUrkdde7VytxPdbtyGpSOtmuwYDIfmFW0ZU 0fjL0ELyFusy5Ppa/LHLMtIgNN+GELwYOtTfXlO625rNTHjYgH91yjEhlCfxGSBbFD4m J2NA4Bd6JkMeo6TGc096N72UDoyFfhvBVSioAK7sGCNouv32gdMnsm9ATRq7HVOiHJFD mZQ0PGcoLCI37Xg79C/pnuZGhZMDHwrqykzP3StIjAI7bC17vjPud/cXg7+DIS8yTxA9 yWYiTr1m0Mtsnr72jL4awVbDD3+Rz7KAXw41rC2rGxNDy0Aq5exkDDdQ7T8VFQeXkmVQ CG1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l6j46Ws58hCljuR8NCqQZteT2C36qK9PN69x2iQopUA=; b=SZ/0zmxA+URgI/YF32hNKJjg/LR5szbXlYHWDtGKlHrux5TKQ95bibTdjyBDEt/xoe 7eqOXnRMlImwdCe4jhGL68swtOFqVQaMNz5gEK5tuzsJjUi1kJc0r4rDXa/u+c4velxU k1oedVi8N3aR533kPhMK+f0CBJmjaiMFZ23Hz64ONgYCy3UVRa3Iif/V1ZqmiUE2RStT UhGldDhuw+zYXZDBsVDaQuNshDXsCHB0gR+AlfMQbrQMgfLnUkpC31pZk+mxODkKjg7+ V5LLjZJGFGcJRX4kMRUwIE8XeKyAms8HUojFkWfQer5/N5NU9v+3TamJ3puGzvTy4PJ/ YB6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RiyH1MAU; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd11si21955700ejc.222.2021.10.27.05.30.08; Wed, 27 Oct 2021 05:31:19 -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=@gmail.com header.s=20210112 header.b=RiyH1MAU; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240012AbhJZWaY (ORCPT + 99 others); Tue, 26 Oct 2021 18:30:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239993AbhJZWaP (ORCPT ); Tue, 26 Oct 2021 18:30:15 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5986AC061570 for ; Tue, 26 Oct 2021 15:27:51 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id n11so590538plf.4 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=GdXG/LJIYlIWU7KedjzW3QNwqTB7+4bO8Pp1GrOGcHidTHIxIQxn1vr8lTbtPcfyeT 8pVYjy/ZG+4JIHvJiZakELQn0LYSiQc3DKax0XrpAADDyRlU3IWjkooFac87V13KYJxt iXSxNUslGq0a9PsHIchMDQzDyWgPMn2HcWmbSqinA0We4qS9YDpzthEKkDoQpaor2wcL ltwZ332bROnGma9BiazgOPIl72JE/gYpvJmD4ZxuQJlzgSksF6bm8CrfyogpNM9cUPJ9 YOF5UposT+sQI4skCsbkbqFEpfsO2yTEKTKLiyja2Dt42I2p9joe550sflAp39y2/vLd xN0Q== X-Gm-Message-State: AOAM530QHKl8jfwnCdqWU1EGWTvtlf33Ge+x1xwyqEZIg0aHVbtLMj1F F0CIQZRma5dwHJifstxcMPHikVP5/A== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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