Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4088408rdb; Thu, 14 Sep 2023 11:20:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/tnfDfSFWqMPmGMx6/l1GXWHmv92i+DKrcAvydpodB9nkfdiN/KS0CfatfhR1s6OEJ+e2 X-Received: by 2002:a17:90a:6b4e:b0:26d:1f75:7fa3 with SMTP id x14-20020a17090a6b4e00b0026d1f757fa3mr2804393pjl.4.1694715620083; Thu, 14 Sep 2023 11:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694715620; cv=none; d=google.com; s=arc-20160816; b=AOTRUeWUVrqqyUMlyH6YW2tRlqKs2dRUuMVnexEMrqqjZ4lhYflKOLPKX8RdUv5Osj VOMLP9rH56zTlmVcwn1jJVPhM8DFBuw6/gA/qzAGh1uQbsQIoZFExZJ77pBLMUWXPzCI p7U9hWJYsXImyzgEWCq8f0if0XvtP3PvOKFx5qMTTSG4DHGefhpxU2ipMEBHRhZCU8ME hy6ZLTOXuodfhrmNUYsc2VnKV62HKWwMSSh1ZfjKjTGdKgW9QhxZJA+lG3rcoaWlvPIO H29rTC4EQniQQWKCfboiN/FPbYWh6O6GoQYzkaQSieVgGorgkV6eplB5YE3lFTGapd5K hyeA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0rCvfJyQVclVcl+nE6KRDaf9jMIyS6A7Wyxgy4VzHmE=; fh=nfQSbTp1dWHt2Ier1Up8UhVNdXOqoJJLNvTrpT3jJEk=; b=LaudRh48GMQT8Qk3y+FG5ca94AgdVy3yAq/nQHJ3rlXEBeKhdBbqkjuEvOHkSeElQ3 69iHMI+ACYq8vuPSRf9UpN3kAxzqP7nC8Ex3RG8tQtpgwdz0/3caKvzK8UuAGsCv+qD6 X+88gHCC6/VNDkq7eCCyAkPBden+p1WMujhdzXqexkMpAHpq1e9kkFYVfdR5cHhv0pZ5 85y56mApwvcAf0WJ+JbR01nn7i8IPdtDRIzi6LMwd7QhyXzCC+6hKblRzpvsvWN6Btvg mhef27Idlw4gbKsg9kzhe3toCpl41fNnn37GAAPRJmmh9uRb54umai1AtMH1f/2SSbQh njNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TYMgdFjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h23-20020a17090ac39700b00268345e910csi2082190pjt.127.2023.09.14.11.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 11:20:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TYMgdFjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E84A7810C2F3; Wed, 13 Sep 2023 10:15:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbjIMRQB (ORCPT + 99 others); Wed, 13 Sep 2023 13:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229654AbjIMRQA (ORCPT ); Wed, 13 Sep 2023 13:16:00 -0400 Received: from out-222.mta1.migadu.com (out-222.mta1.migadu.com [IPv6:2001:41d0:203:375::de]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E21B98 for ; Wed, 13 Sep 2023 10:15:56 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1694625354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0rCvfJyQVclVcl+nE6KRDaf9jMIyS6A7Wyxgy4VzHmE=; b=TYMgdFjbt/Eo9/c1f+k7VBMopiQ5ELQvuAFxZx2mG4w5fYla84GACRt9mHYjc8VPC6hY1n PzTFY9MQ4IbYJVEAwdIh5X1A1wBrieX7KoSLaA+ZMLXosAUWrOS734vnP0yfp7RNTCW3/Q RaHcPG2lCnUbh38nQx0ZOsudkh1SFKg= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 06/19] lib/stackdepot: fix and clean-up atomic annotations Date: Wed, 13 Sep 2023 19:14:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 10:16:00 -0700 (PDT) From: Andrey Konovalov Simplify comments accompanying the use of atomic accesses in the stack depot code. Also drop smp_load_acquire from next_pool_required in depot_init_pool, as both depot_init_pool and the all smp_store_release's to this variable are executed under the stack depot lock. Signed-off-by: Andrey Konovalov --- This patch is not strictly required, as the atomic accesses are fully removed in one of the latter patches. However, I decided to keep the patch just in case we end up needing these atomics in the following iterations of this series. Changes v1->v2: - Minor comment fix as suggested by Marco. - Drop READ_ONCE marking for next_pool_required. --- lib/stackdepot.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 128ece21afe9..babd453261f0 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -225,10 +225,8 @@ static void depot_init_pool(void **prealloc) /* * If the next pool is already initialized or the maximum number of * pools is reached, do not use the preallocated memory. - * smp_load_acquire() here pairs with smp_store_release() below and - * in depot_alloc_stack(). */ - if (!smp_load_acquire(&next_pool_required)) + if (!next_pool_required) return; /* Check if the current pool is not yet allocated. */ @@ -249,8 +247,8 @@ static void depot_init_pool(void **prealloc) * At this point, either the next pool is initialized or the * maximum number of pools is reached. In either case, take * note that initializing another pool is not required. - * This smp_store_release pairs with smp_load_acquire() above - * and in stack_depot_save(). + * smp_store_release pairs with smp_load_acquire in + * stack_depot_save. */ smp_store_release(&next_pool_required, 0); } @@ -274,15 +272,15 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) /* * Move on to the next pool. * WRITE_ONCE pairs with potential concurrent read in - * stack_depot_fetch(). + * stack_depot_fetch. */ WRITE_ONCE(pool_index, pool_index + 1); pool_offset = 0; /* * If the maximum number of pools is not reached, take note * that the next pool needs to initialized. - * smp_store_release() here pairs with smp_load_acquire() in - * stack_depot_save() and depot_init_pool(). + * smp_store_release pairs with smp_load_acquire in + * stack_depot_save. */ if (pool_index + 1 < DEPOT_MAX_POOLS) smp_store_release(&next_pool_required, 1); @@ -324,7 +322,7 @@ static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle) union handle_parts parts = { .handle = handle }; /* * READ_ONCE pairs with potential concurrent write in - * depot_alloc_stack(). + * depot_alloc_stack. */ int pool_index_cached = READ_ONCE(pool_index); void *pool; @@ -413,8 +411,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, /* * Fast path: look the stack trace up without locking. - * The smp_load_acquire() here pairs with smp_store_release() to - * |bucket| below. + * smp_load_acquire pairs with smp_store_release to |bucket| below. */ found = find_stack(smp_load_acquire(bucket), entries, nr_entries, hash); if (found) @@ -424,8 +421,8 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * Check if another stack pool needs to be initialized. If so, allocate * the memory now - we won't be able to do that under the lock. * - * The smp_load_acquire() here pairs with smp_store_release() to - * |next_pool_inited| in depot_alloc_stack() and depot_init_pool(). + * smp_load_acquire pairs with smp_store_release in depot_alloc_stack + * and depot_init_pool. */ if (unlikely(can_alloc && smp_load_acquire(&next_pool_required))) { /* @@ -451,8 +448,8 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, if (new) { new->next = *bucket; /* - * This smp_store_release() pairs with - * smp_load_acquire() from |bucket| above. + * smp_store_release pairs with smp_load_acquire + * from |bucket| above. */ smp_store_release(bucket, new); found = new; -- 2.25.1