Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1339366rda; Mon, 23 Oct 2023 09:31:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxODQia8cKLSmIaOgaFh815yDppKoZx1o4A7eXRmeltdjOhjSDxIoCp97P2di7NMYWb5Jr X-Received: by 2002:a17:902:ed83:b0:1c5:9c73:c91c with SMTP id e3-20020a170902ed8300b001c59c73c91cmr7604567plj.48.1698078691942; Mon, 23 Oct 2023 09:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698078691; cv=none; d=google.com; s=arc-20160816; b=O1DZu8AWNx622QdZbtK/3RD4fLi7jpZaavimAIC1/NhT7qzaryn0xf6p0ShkzA/Nz+ kDpSs/F2B9EVJme6GIsjQUFwO32IugqcxUxaZt+xfpDF/OzpyDyEjNDq8Ebdmf8FR/sR qpdPrzMalFF7vh553f51mteQdJHccTMPpU/He4efMV/7RyFb64u9OfMOw2LFiwU5fAUL BhmzHBVFvLMi+WmQ6xzA3sQ2MVtT7Y/3Z9pcRXwdGP5EhqPHAwJvxkKDniDbUUtS0rdy LAwIYZhs4Qf0831wgbdjvseuAELEUe+7GUgsm3wmeSfAgB111+5stv+bkji1h8elEb4G w07Q== 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=6w0l/5/OLmmiPtUBy12XvNW481vH2W+yw4PJnFK30wA=; fh=nfQSbTp1dWHt2Ier1Up8UhVNdXOqoJJLNvTrpT3jJEk=; b=vJYyODJ5QsIefqHIs+YxmqYvnJffQk6+PHANKuwCtXzYHfjaF4Adw9+zif3MSe/7g0 tZEm7G8hXUe7eSrmCri8xJrdDbGUsND09dOD0OWO5QNr3SPEiCcKZSvRNP3hihFz46sU PP72mVXCrTcloWX1FrgjeJtyw6B4Y8Umpb4hW2fAYZhZrfb7fAn+zoYUbZW51/BVsWol ByXvJ1ehc1LOktoJsK55gTzeKz6R0QLCghDxn+8Hq59gB33h6QsVX2705cUbcUMzpGTP FZCZV8+dF9i2zFBiEy2KT23F6IQ6w942JCBKQqK5ccHJdNAbS3pPrOWARsx/fWstCh4c VSkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tTmhSqri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id u7-20020a17090341c700b001c5d09c7b0dsi6868973ple.458.2023.10.23.09.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 09:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tTmhSqri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 074748081CFD; Mon, 23 Oct 2023 09:30:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233687AbjJWQ3n (ORCPT + 99 others); Mon, 23 Oct 2023 12:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbjJWQ3f (ORCPT ); Mon, 23 Oct 2023 12:29:35 -0400 Received: from out-201.mta1.migadu.com (out-201.mta1.migadu.com [95.215.58.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5572E4 for ; Mon, 23 Oct 2023 09:29:31 -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=1698078243; 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=6w0l/5/OLmmiPtUBy12XvNW481vH2W+yw4PJnFK30wA=; b=tTmhSqriTq1xAUwIMKx9hsGiOaqTSZIq/wKJLXRg6daSa2A/wpp5RWjZ1i+KFXZWKiTvL7 FT80+nqHJsuFFL2EcMj7absCsQ1tHdiG6bPU8EWrNzLrOT2cqyLQvL1bQUd/tEodCi1gSB pSo03HvvDVMKsmPPsyN4xZhauDuuzOs= 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 v3 06/19] lib/stackdepot: fix and clean-up atomic annotations Date: Mon, 23 Oct 2023 18:22:37 +0200 Message-Id: <8f649d7e5919c56bcc5d2d356c9584fdcb87800e.1698077459.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Mon, 23 Oct 2023 09:30:36 -0700 (PDT) From: Andrey Konovalov 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. Also simplify and clean up comments accompanying the use of atomic accesses in the stack depot code. Reviewed-by: Alexander Potapenko 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 v2->v3: - Keep parentheses when referring to functions in comments. - Add comment that explains why depot_init_pool reads next_pool_required non-atomically. Changes v1->v2: - Minor comment fix as suggested by Marco. - Drop READ_ONCE marking for next_pool_required. --- lib/stackdepot.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 128ece21afe9..60aea549429a 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -225,10 +225,10 @@ 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(). + * Access next_pool_required non-atomically, as there are no concurrent + * write accesses to this variable. */ - if (!smp_load_acquire(&next_pool_required)) + if (!next_pool_required) return; /* Check if the current pool is not yet allocated. */ @@ -249,8 +249,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); } @@ -273,7 +273,7 @@ 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 + * WRITE_ONCE() pairs with potential concurrent read in * stack_depot_fetch(). */ WRITE_ONCE(pool_index, pool_index + 1); @@ -281,8 +281,8 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) /* * 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); @@ -323,7 +323,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 + * READ_ONCE() pairs with potential concurrent write in * depot_alloc_stack(). */ int pool_index_cached = READ_ONCE(pool_index); @@ -413,8 +413,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 +423,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 +450,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