From patchwork Mon Oct 23 16:22:37 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: 13433188 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 BDD12C001E0 for ; Mon, 23 Oct 2023 16:24:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD8386B0102; Mon, 23 Oct 2023 12:24:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A604E6B0101; Mon, 23 Oct 2023 12:24:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A0A06B0104; Mon, 23 Oct 2023 12:24:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 62B4F6B0101 for ; Mon, 23 Oct 2023 12:24:08 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5DA4E160B3A for ; Mon, 23 Oct 2023 16:24:07 +0000 (UTC) X-FDA: 81377248134.05.83DAE97 Received: from out-207.mta1.migadu.com (out-207.mta1.migadu.com [95.215.58.207]) by imf13.hostedemail.com (Postfix) with ESMTP id 7E7FC20028 for ; Mon, 23 Oct 2023 16:24:05 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tTmhSqri; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.207 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=1698078245; 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=6w0l/5/OLmmiPtUBy12XvNW481vH2W+yw4PJnFK30wA=; b=2cWOBSHCn+1jHtkFjxxc7DuKg8ZchoEr++jhuJ53wJRFZJruy8bqwPgJ1ZbyYeMqq9oKVq /HGJ3KQrEuyIDCrl09lUgqvyOEwLR743vYiak27FAsTZV9WpV1osms1koeKpuy/xBtcTkN /cv30JP6AyAvnz4LCGpCZ8g0n3pFaO0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tTmhSqri; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.207 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698078245; a=rsa-sha256; cv=none; b=U9aLEPcdfHtHINXNluVa9spOiTbIVTazt6NJYGuTQv7rTeQwg/mqbPYCeFO/i9qY3nRJ+Y ol84ooT3IUTCAWUrYFR5kiJguGLgaYeuhQdPBcjw9tVOnJno03RGUaFYC9gqp0KMGYHakb DrqtHJ5z+Hr821QMJdcvV6JATLcI4QQ= 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 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7E7FC20028 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: dr5ipf11gu6n1jg9ic1oex63fg5or64z X-HE-Tag: 1698078245-198402 X-HE-Meta: U2FsdGVkX19RLp/9/jnX2SOt1dqF6lswEX+p04f0QGt/+s1cdOgQA/kFahaVO7DqJbcL+28Q5N6YnSb4y1qigJ9Kl3nFuYLn0CmptpUOvvZ/4IPt44emFSjzqeTWHYWUXQm6ptrdXsOo0hPx0BvKrMdc6XwVzlsiFRQcmgmU9OGlhxN1yJnJ7VGVZu09e5nXD2849tXRLNo6RdNuu1kXtMtHIOrLoluYKrxSk7q1tndlT48g5UurTJzZX4iEGZp4fB5MesGb7cRss430/jRY9Hmam3cB6udVxpwZnyPVzMXv//QJVq8k2aCOwXNoPtHeBkEgfwdrzPfjengOzNeX7jz6ZqSK8SzcOHYB1D7bJsu7v9E2Zy2Yc1F2GaiCxQqIpMNBql08MzA7UqCv7iYabYAgtiRW2q4XYzEsjAmlyZBslr1lIhy0dGXpkPO7+ucQAfk9VkwMskS+Brmw126wmferyUiBXZMUM4vULQA1d10RwQB4Bn8PbM+n3V5thC6E8x1ABpYYjZHuoht2pjDz//xbhHdug5fzK4++9EdQiKvlfQUarQOrD2ux01vjS5/KolchwxbfKMjnlz6pk/TRA2F1Q4denewoCX1W3dj7swJPYPaZgF2UBXVl1Trgv/aY07LFOutna5E45ZcWuIToqZ4EPbfNljOT4S2y2Xz4Vx69ldNQr0bBXMN843NQ96IIb0trTpkRe9djFPXrZQQx+Xg2mCI0rooFszl0nZccgve9+2CbOvKO95dV6IKgmT11zoM8G+sIRgaUS7pnlZzZmihXlNMiWViaICtQffr/jcM4o7rZiRkUsWgsm72eMGABL3OdK17JFXrmMzOPeVdUhj5m58iX4tDlTXO9BY8b2icSptp05iGEh0eHxVbL8cnPLKcZbegdOfm7Vcw7huriuRL01qZOE6f0VZ4/K7wEAish+SRr3WajK4Vu0lBnfXyk7z45mfDnEpEssNoAujM JeBaOY0X tEQ/8MgvysyZMDzwf9VfqOebeU0MdvepVmlsP1z+q23nurVS/HjhUEPBqXaIsjmD5eQ2FmzIRCZkyZfSvl9nxpPyFPm1sA08DaCwE 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: List-Subscribe: List-Unsubscribe: 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;