From patchwork Tue Aug 29 17:11:16 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: 13369235 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 96AC2C83F21 for ; Tue, 29 Aug 2023 17:12:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A5618E0033; Tue, 29 Aug 2023 13:12:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2531B8E002F; Tue, 29 Aug 2023 13:12:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F51A8E0033; Tue, 29 Aug 2023 13:12:43 -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 ED19E8E002F for ; Tue, 29 Aug 2023 13:12:42 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BA90EA0235 for ; Tue, 29 Aug 2023 17:12:42 +0000 (UTC) X-FDA: 81177786564.22.66B0F10 Received: from out-249.mta1.migadu.com (out-249.mta1.migadu.com [95.215.58.249]) by imf25.hostedemail.com (Postfix) with ESMTP id CE28EA0013 for ; Tue, 29 Aug 2023 17:12:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=xUAvBItl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.249 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=1693329161; 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=+57664S6bw4mOO/qPj8h7l/H8qh2Ip2xAdoPp4fmyag=; b=IvsHwssZQ3vLWaD7S7JbOJ+MgGJh0dE46WplhuyqF0UU04ymTcyEF1iu+ZGN2SVasMZ2Iz CaK812gOnCHykh7AgHVA+iJKkcdvQnIDq3kTwcNHes5sM7/Z3zbyy1YyKVR+QBxY/1CbH+ y1y9vC+rHbcNFiuH9gBJpbibchvzsuE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=xUAvBItl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693329161; a=rsa-sha256; cv=none; b=jtzNntCqgCnmzt7N8NIFitBVEHbum+QNulI2qnH/REwioJLSyETisaFaZYoDNSHhwGBg6j iVwWKL16wltHbxOcJM1x8ryg7dbVXkTg6hVRAPi7oqz79aVQY6tIPTHuuq4RkaGJY79ll0 01bNUg+cumUYzKyTTVHFSwXdtfyTMM8= 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=1693329159; 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=+57664S6bw4mOO/qPj8h7l/H8qh2Ip2xAdoPp4fmyag=; b=xUAvBItl08LNbG+js05Euj/uDwk7mnKgQkEClKLARFeIBi8pvWrOlUBmEdpKyMjEBpe08t MZxZZK8u8HPHUPrktgetKtdD93OVx+rnbApYTVTui9WIUJLSE/Xb3wolF7HpROmuiVuy/N gklA8fWRmILe9ypho6CUw2WGHHwPn0E= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 06/15] stackdepot: fix and clean-up atomic annotations Date: Tue, 29 Aug 2023 19:11:16 +0200 Message-Id: <8ad8f778b43dab49e4e6214b8d90bed31b75436f.1693328501.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: CE28EA0013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: krj8t9rs83bw7e33d9yiy6a4najxt9zd X-HE-Tag: 1693329160-672446 X-HE-Meta: U2FsdGVkX19xvSdge75skjUX/VJhBUuVuXj6pDg05VsmuYukDgirR+bkDZ1SCp9MvONhqSrLmsWsk4CjBOt9EiFuQHEMCHDwbAj+6Gn+wJCQQgT3T+q4NfknwEg5Fxs5o9uIDBGbNaJr1RP+OLpo/fEvTPVHv0j23vqoO8f/TKw3QcIM3YUUEctBr1zZprwNX6lsOk0RGWU0ayejpjM7TVMd6/nHFt04FD2b4LjuKxkNqNMZ+5BkWzMHGCSt/F3hO3tmyfQ9aTEtHkGbWDoCXhGaS8NzdB7n9A6CHscaKsbcmehtk5bxZNLp/BHmo/KuioSj8gYeC9ARpcQg+6KS1FbwZiLEHzMSMOBBtMpwaQ3mCScsHKrz7mWlWQug5S9OjiF/ezOClRw5Dt7KQYhxvH9gzTSqwsbYVLy8Gu9P7dDuuCbGOYrWLgFSOskfTo05G1+ieGpOaNtoGofSwmg6zCGEq45qZM9lnsIlw3vMe3QxzrtnVCSUMitsx1xXgb0CKcLrgOlKU5KmTF2YE7UfQekndd+YYxbX4j9NpL5UA52gr4YP+JSXn8NFsuMGLX4JIrwlr34PG47ku/odrqJwLmYKjAF4/ImiZ56qPT9hBjeFw+mK8sGwqqr+KRgOdECHI5iv33UtfukwvQPU2PoFfBKqG+6AWrKp8wOIc+4SDvJKQLuQ2FFEKwESs3d9Cy6KhzdqdXXB8n/C/dtBn+DlJWGSuMge1owDOe6S0h7u1wmf0dYAUSo8bq5OMr9GWLC6YW6kFv0hM6X/r+hUC8eK63QHx0cwQz/SE0Ho6sOkjX/HpxOi/RYD2rm4WeGpvvXvE+lhir4j2O9DDeANNSZg/Tm57HgQuRO0i5Ss9pwZysxtxEktCF+tl+FQpGcTsyFukqVvnONjmTG6seQGcRJfThc1H3zEyeltijSQIDFvZ5rZQKtxZLHjAEeu8lsI5XSQcryEAODqEUG9olI2Rl8 P+/UlzrB 3HdphzJ9lJ6strll6o3L5q7ATSLe9T9QIBjno9jxkswOF2mqhCrtHdbYoozZMVh4NUbaCtMHNbXaFqC/GXSCsLAVL4Q== 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 turn smp_load_acquire from next_pool_required in depot_init_pool into READ_ONCE, 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. --- lib/stackdepot.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 93191ee70fc3..9ae71e1ef1a7 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -226,10 +226,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(). + * READ_ONCE is only used to mark the variable as atomic, + * there are no concurrent writes. */ - if (!smp_load_acquire(&next_pool_required)) + if (!READ_ONCE(next_pool_required)) return; /* Check if the current pool is not yet allocated. */ @@ -250,8 +250,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); } @@ -275,15 +275,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); @@ -414,8 +414,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) @@ -425,8 +424,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))) { /* @@ -452,8 +451,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;