From patchwork Wed Sep 13 17:14:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13383620 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D0AEEE01F5 for ; Wed, 13 Sep 2023 17:16:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E82026B025E; Wed, 13 Sep 2023 13:15:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9F306B0269; Wed, 13 Sep 2023 13:15:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB9646B0260; Wed, 13 Sep 2023 13:15:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8D9306B025F for ; Wed, 13 Sep 2023 13:15:58 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4B515C0F01 for ; Wed, 13 Sep 2023 17:15:58 +0000 (UTC) X-FDA: 81232226796.24.173031B Received: from out-230.mta1.migadu.com (out-230.mta1.migadu.com [95.215.58.230]) by imf12.hostedemail.com (Postfix) with ESMTP id 4A61640024 for ; Wed, 13 Sep 2023 17:15:56 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TYMgdFjb; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.230 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694625356; a=rsa-sha256; cv=none; b=xvQRJ9zRUqeJhY80oMDi8KzLElv5lTh+ajD7mr4enH54mC5ch6MR3YElniv6zk4BXo0hcW /ig9PoG8jDqELOCgEgorthtMdoJGtDxhsMo6DZVhQ0YlenXJKasPXB6Eou5VzsTYKlu5bh pBI41+t0H+E/R1xdgraI3gzU6tcDH8s= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TYMgdFjb; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.230 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694625356; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0rCvfJyQVclVcl+nE6KRDaf9jMIyS6A7Wyxgy4VzHmE=; b=5A/FVTlc/u7KmRA3JPsNb9lokdb17vdVFe/EG5QVBo27s3+ziD+be08rfzi+/B4Z2BZo05 QcxSvQjqd3W8dz/XkjgIYF37IPJOI7HvQPdsuxHUY6GJKxbAqkxEk4uLutHTNIuIno8Z5o Jm2C2UR6yEq750PXcFqDKnCMIItUDI8= 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 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4A61640024 X-Stat-Signature: osab1uxtqcig63cjz8p9i1183z6gpg5p X-HE-Tag: 1694625356-18898 X-HE-Meta: U2FsdGVkX18oubyPPyd+GPbjPI6tr1KpXHSrIZaHObBJwkTh2naZWSnSuUQHfMGKWfNfx3TXTtOgSOaEj+PUClnRE+X0g15vffX4SqudrOJFtH2qB1BVJA7BpXOkPNK6n2zzuKkc25b5AZPdlOfNk2b87KMNfrmSLDOOBOYbfGiRAXkaIscFMH+CI4/4o07CqQVOSJUgi3Cz5bZt+EkJ53zSuPtJ/oFBJpBz+8UJK7i9VAgUDwNVUC4XtLaJTW1ETLaeLw+1xRfm/b6X+8V/JBamti5wXme9Aos0WMZJCi+OTcqA4iuJ8PXPjfjTJafDlXv1v4rQ8jAYTBLqJ+q9xAxwRdNmDb9A5+ttPiICqHmZ/C227dFeni7biUepynMpaSkNQRVvlUKXcnTkWhS8wZS75GY4ZhVQOphyzRTNy8pOA8SRcF+4ak+E2tGk/68AFXO8jxSHRuJvm2HwKY4k/k9s0TXqxVJODrIjTEwfdi49YfiANyWs3QGrFQvKhd5e6dSFy+GRbfxtb26ZA+ZiYVNq44X8djjWVKh76mzVPs9QmVa1SPbYztVY5+awiUXjD6eRIPnQcWalGMs4ztHWzsOYPeBWHqKTvZc0OvbjdKzG0u/qYNMT8G/0gnwG6A15pDm8FTvZHuIuwfcx5Mlr/x1mJQhGUrBiMsA/LNnLVKMQg8n0ru/8f+9gCeOostskadynsga4nCo2kwhnQVRZ7LsIRURwyHlNiBK8PgSxzBKiyTMzOXf1xMNnJgm+RB3+5FvSAJ89JNLOM3FCnxPSkpEkwt7gyaFN48v8NGM4+D56qx5uNh7FeBUnosbzkjrDoL4WkE3K4hDg6kNgWu5iC0k2sMjy3PNE+1fBUCi+5Rfwtk3YrJG+vnn+O24hmGSksGfm6QwTffnbd1FVh7OLp5MbPxhSOmMe7IgGyQpv+/XrjDKxYV2rW0QtN/zbElb8Z8ebukvPDxF46d7qNVT ub8SDwVI YguAkklBac2ByG+16smFT3z//tn/IJck6xF3JDkaLi44vD2Z5XQ6weJB37/vEs0sixR6Xahj0dHKc0H/rlR1+QlG6EPDbd8soKUhM 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: 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 Reviewed-by: Alexander Potapenko --- 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;