From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794588156; b=FUmQJzc2PEl/T2BjFfUjS/ogs04d+yRKh4nh1fbzNGaNHGtYa2rvq7PQFYnWFm92llAX lsAqwP/tq9aHZqlF7SuHPNzyTKdUdcp8weIBM0fSoD7hsoV30/hhHNI7dHPgj92q2BrSG d1SrkinWtuTkyGhY1U4PKxbBjeK4fjqyJC5XSFmllwYgdiS7gf3QpidNlrNjqKJCuwciY NZB5xvAKxqUZ415qWGyVGvvdT7TZd14pflm4e09ezB/R5EetxvxxZE7pBXxrTpiSuVjJ7 dinSW+3bX1qaapg5b1vpSEdva3m3s5OpJgGeWVv6G4+uSU7RtL1EE5lmSfJL0139hTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794588156; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=+CtJcrEtN9eDgrldMUwlTf29GauoIVdfb5xQnIMdbpo=; b=FlA+qEo3N5ZiuMHAHoqs1BaZ5ttdd5nTZcp380c4S+ajkeXQUnRE9WvlQ5TYZcknUVdC NF/Y8F0CF9IKreQzKtA5BcnDj6vEZQWdgt7pJkIDBmpPLiWY7sk183WAQJ6bLPyrFUzqL V2vviTwtyZloatsYES3xv3F8O0z7+s63jw0PMxBeWy8oon8kpGNuVgTPGa3I2w3NQ6yT6 0qh+hy4NfbBCyj5Zmjj9RzOxEwlTZ4egrnQ2t9QUASKv5TyeRT1pxj00c0ObRqSBwOHkc Tz+t5vA5tqktfYeecFa6vdIqLLGr4zbqSv57I7HccNU3OhS9I0GqLJjXVNbWUJJ4YmA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lX1+txxn; arc=none smtp.remote-ip=74.125.82.198 Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF8BD60A380C for ; Fri, 13 Nov 2026 16:42:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF8BD60A380C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lX1+txxn Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-370230d93efso5265948eec.1 for ; Fri, 13 Nov 2026 08:42:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794588155; x=1795192955; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+CtJcrEtN9eDgrldMUwlTf29GauoIVdfb5xQnIMdbpo=; b=lX1+txxnb/lLy3onI+QYS5gW63/Eg7pZ/GmJH6L9aAdO3XWRb2jT6LoIcQ4eRSgfoJ InLvOhychEuCB3ZCTCl7LUcJ5uzInuh+ZU6duO3cQuRCKrB70l4EwazLH4YIgcHmdu2x 8YBGkihmhM3kyJhS47G+QYmVINj2RSqvJAEX/T5t13alJJ9eWnLVpERRp9ngzoEt4TWQ WRmRZM4m36OgJJFMJHq9yoi8235J3tkT6e3HRuHdXI6uYlzMe0hcdG7qK75K+Mux0bQi 5sENdgXck/1sO9YLx0VXnl7+H4XHlGmpkkWO8+dujgAiGCZJP5ZgYMLy5jdqfLyobcp3 LtOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794588155; x=1795192955; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+CtJcrEtN9eDgrldMUwlTf29GauoIVdfb5xQnIMdbpo=; b=ry2jsMJEWO1k2u1YxRpEoXCnSNjAvYjtu5M6q8jl+oVmLCIuTgIH0Br6r18I6Y7AZT Z7EstrnCzNXfTOpOo/C5o1W1i0mWhQrNvEmdTxMiVRQ7itji0q61G+exWkLW/UMo1mNN 1KMk0Zmk31fp8++Wn81LDAxkliFP95uJlWWpYRPhk4I4Q5T8OVKKWEtwsmyU9UvNAn10 NrnK9UNO/Q0NnWpkDQbAwZQHZAbgpEL5sC2d4tFHQ8g1EL2lTuSuVxsre04INoGiGNgf UKO6+7X+WUBzYH31sZKwHxJdBkfsnHUTVw5+/8iOuYOzJRB742jz9noCq9IhIflFTfrE uqBA== X-Forwarded-Encrypted: i=1; AL+hErH1akRyULNhvMEXS1eQo8XGlbsvQYh+8tr8C0yKKbUpKMRWQ2jsxHxMp+ibO6WXj+ynjtAM1ptO+IhxcH4=@vger.kernel.org X-Gm-Message-State: APuU4Z/6FqHVI5T/eNeJUbhH1j7GkirL53OVOa7cyO4/4Grsta8LaILA 7QoI2puMbX/NhCI1op5Fxgbc9vXGmR+FI63QaRmJwiJNr6bUvIZ/GBeyguN0YLIWacZ0b2IXnbL VVDsCfYVK2g== X-Received: from dybou11.prod.google.com ([2002:a05:7300:e5cb:b0:369:68b5:ef]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:7a01:b0:376:5b99:a816 with SMTP id 5a478bee46e88-3796395425cmr2784047eec.3.1794588154664; Fri, 13 Nov 2026 08:42:34 -0800 (PST) Date: Fri, 13 Nov 2026 08:41:48 -0800 In-Reply-To: <20261113164152.2095566-1-irogers@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261113164152.2095566-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.703.gf848ed807c-goog Message-ID: <20261113164152.2095566-18-irogers@google.com> Subject: [PATCH v13 17/21] perf config: Add __guarded_by and __must_hold annotations From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, bvanassche@acm.org, elver@google.com, james.clark@linaro.org, jolsa@kernel.org, justinstitt@google.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev, mingo@redhat.com, morbo@google.com, nathan@kernel.org, ndesaulniers@google.com, peterz@infradead.org Content-Type: text/plain; charset="UTF-8" Add __guarded_by() and __must_hold() annotations to static parser and config state in util/config.c. Signed-off-by: Ian Rogers --- tools/perf/util/config.c | 47 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 287401f159e6..0e6b77a0a5e7 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -64,15 +64,29 @@ struct perf_stat_config stat_config = { char buildid_dir[MAXPATHLEN]; /* root dir for buildid, binary cache */ -static FILE *config_file; -static const char *config_file_name; -static int config_linenr; -static int config_file_eof; -static struct perf_config_set *config_set; +/* Parsing and rewriting share the static parser state. */ +static DEFINE_MUTEX(config_mutex); + +/* Serializes whole perf_config__set_variable() updates. */ +static DEFINE_MUTEX(config_update_mutex); + +/* + * Protects the global config_set. Separate from config_mutex because + * initializing config_set parses the config files, which acquires + * config_mutex. + */ +static DEFINE_MUTEX(config_set_mutex); + +static FILE *config_file __guarded_by(&config_mutex); +static const char *config_file_name __guarded_by(&config_mutex); +static int config_linenr __guarded_by(&config_mutex); +static int config_file_eof __guarded_by(&config_mutex); +static struct perf_config_set *config_set __guarded_by(&config_set_mutex); const char *config_exclusive_filename; static int get_next_char(void) + __must_hold(&config_mutex) { int c; FILE *f; @@ -99,8 +113,9 @@ static int get_next_char(void) } static char *parse_value(void) + __must_hold(&config_mutex) { - static char value[1024]; + static char value[1024] __guarded_by(&config_mutex); int quote = 0, comment = 0, space = 0; size_t len = 0; @@ -170,6 +185,7 @@ static inline int iskeychar(int c) } static int get_value(config_fn_t fn, void *data, char *name, unsigned int len) + __must_hold(&config_mutex) { int c; char *value; @@ -201,6 +217,7 @@ static int get_value(config_fn_t fn, void *data, char *name, unsigned int len) } static int get_extended_base_var(char *name, int baselen, int c) + __must_hold(&config_mutex) { do { if (c == '\n') @@ -237,6 +254,7 @@ static int get_extended_base_var(char *name, int baselen, int c) } static int get_base_var(char *name) + __must_hold(&config_mutex) { int baselen = 0; @@ -257,10 +275,11 @@ static int get_base_var(char *name) } static int perf_parse_file(config_fn_t fn, void *data) + __must_hold(&config_mutex) { int comment = 0; int baselen = 0; - static char var[MAXNAME]; + static char var[MAXNAME] __guarded_by(&config_mutex); /* U+FEFF Byte Order Mark in UTF8 */ static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf"; @@ -549,12 +568,6 @@ int perf_default_config(const char *var, const char *value, return 0; } -/* Parsing and rewriting share the static parser state. */ -static DEFINE_MUTEX(config_mutex); - -/* Serializes whole perf_config__set_variable() updates. */ -static DEFINE_MUTEX(config_update_mutex); - static int perf_config_from_file(config_fn_t fn, const char *filename, void *data) { int ret; @@ -737,6 +750,7 @@ static int set_value(struct perf_config_item *item, const char *value) static int collect_config(const char *var, const char *value, void *perf_config_set) + __must_hold(&config_mutex) { int ret = -1; char *ptr, *key; @@ -853,11 +867,8 @@ struct perf_config_set *perf_config_set__load_file(const char *file) return set; } -/* Not config_mutex: building the set parses the config files, which takes it. */ -static DEFINE_MUTEX(config_set_mutex); - -/* Called with config_set_mutex held. */ static int perf_config__init(void) + __must_hold(&config_set_mutex) { if (config_set == NULL) config_set = perf_config_set__new(); @@ -975,7 +986,7 @@ int perf_config__set_variable(const char *var, const char *value) /* Static: the parser publishes it as config_file_name. */ { - static char path[PATH_MAX]; + static char path[PATH_MAX] __guarded_by(&config_update_mutex); char *user_config = mkpath(path, sizeof(path), "%s/.perfconfig", getenv("HOME")); config_filename = config_exclusive_filename ?: user_config; -- 2.56.1.703.gf848ed807c-goog