From patchwork Wed Jan 26 18:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12725593 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 E0CB4C28CF5 for ; Wed, 26 Jan 2022 18:34:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A3636B0081; Wed, 26 Jan 2022 13:34:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62AFD6B0082; Wed, 26 Jan 2022 13:34:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CB1A6B0083; Wed, 26 Jan 2022 13:34:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 357C26B0081 for ; Wed, 26 Jan 2022 13:34:42 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F1A1918189161 for ; Wed, 26 Jan 2022 18:34:41 +0000 (UTC) X-FDA: 79073289204.28.F38BD31 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf18.hostedemail.com (Postfix) with ESMTP id 95E191C0019 for ; Wed, 26 Jan 2022 18:34:41 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id d8so644624qvv.2 for ; Wed, 26 Jan 2022 10:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=l8kTegpTqMksygyMNd7O9r7qJ6myjdhmrXkVSbv/IzA=; b=dcgO/hZ6elZPBdqxd4MboPCo3EmolMnIS887io5RaZKDoH7H3DsIKjWe4xL0M92rAN NGAs7DZ4N0Cm3Mu1BqA/u4YPeEnAejo0/rDUXvOGHwdQqDTzgDduz/YPu8cTYag6DNR2 pZks0Czhk7nN87F+uqzoh7CXPfDmtA2bXmMEn5cLDfgC74eDx4rtj9zlO5y9Gz/6RdQY QYtkCpcN6yotcPm74Tik/4EYy8j0Ppcfy9AOeQyVai8riP0oJXWDwXI7oyJNNCbj4jxC H/r9ApPE7qNwyGQk9KJq0YaO8bT0ni9gz3Tm8obbCQhHb9KIqrUiniiwj2Db7oc6jaKC ByKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l8kTegpTqMksygyMNd7O9r7qJ6myjdhmrXkVSbv/IzA=; b=3JZNOPdBmd08HnX1LeLd6+mnuRAyMI2RneFkdHuYcyg8ytFTcLc3r7Uv30q6FA1kuL uep1teImv0icKQ98SkAkPbSr3kCjSFFkpfK0BP5WYQxM+nefn4fasG6kXFRdmqDUw8EH kCREwhcPSHv9KaNR1+3P6AQq/rTFnidQeFTWSHFptwbvso4ey3gsSnMbzTVlns4dpzn2 80zLEglQluwuwEqoftrJC7Dp4gUBLQBZvkGE6ogJUtCIs7UwLKCuFAiPwdZAWCa1fP1T XlXJRGdOM5gLFtEkzpb9nS9nqqZKHCzoNAMJBFqTy7YsFt/5hPrIlk2S6q+4xeYhqAYH iodQ== X-Gm-Message-State: AOAM532T2+eGQ1Ona8Po/D3QEMrF//k95wPUFpLG5D+QZ+1b/gVy/60A FbYsWnNdXExu5IJmnNOmUnEOwA== X-Google-Smtp-Source: ABdhPJx1uUL1QguAQjuOjaCUHuB84L0yLxyE8YceJm8x5PIc7mOwOmi6RJ2+VMz5b+XHNn1KPA5orA== X-Received: by 2002:ad4:5ca4:: with SMTP id q4mr24120qvh.64.1643222080942; Wed, 26 Jan 2022 10:34:40 -0800 (PST) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id u17sm35886qki.12.2022.01.26.10.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 10:34:40 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-m68k@lists.linux-m68k.org, anshuman.khandual@arm.com, willy@infradead.org, akpm@linux-foundation.org, william.kucharski@oracle.com, mike.kravetz@oracle.com, vbabka@suse.cz, geert@linux-m68k.org, schmitzmic@gmail.com, rostedt@goodmis.org, mingo@redhat.com, hannes@cmpxchg.org, guro@fb.com, songmuchun@bytedance.com, weixugc@google.com, gthelen@google.com, rientjes@google.com, pjt@google.com, hughd@google.com Subject: [PATCH v3 9/9] mm: use atomic_cmpxchg_acquire in page_ref_freeze(). Date: Wed, 26 Jan 2022 18:34:29 +0000 Message-Id: <20220126183429.1840447-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220126183429.1840447-1-pasha.tatashin@soleen.com> References: <20220126183429.1840447-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 95E191C0019 X-Stat-Signature: poum316os3r94d1qfkucoenzcfkfdwe7 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="dcgO/hZ6"; dmarc=none; spf=pass (imf18.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Rspam-User: nil X-HE-Tag: 1643222081-489765 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000024, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: page_ref_freeze and page_ref_unfreeze are designed to be used as a pair. They protect critical sections where struct page can be modified. page_ref_unfreeze() is protected by _release() atomic operation, but page_ref_freeze() is not as it is assumed that cmpxch provides the full barrier. Instead, use the appropriate atomic_cmpxchg_acquire() to ensure that memory model is excplicitly followed. Signed-off-by: Pasha Tatashin --- include/linux/page_ref.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h index 9efabeff4e06..45be731d8919 100644 --- a/include/linux/page_ref.h +++ b/include/linux/page_ref.h @@ -308,7 +308,8 @@ static inline bool folio_try_get_rcu(struct folio *folio) static inline int page_ref_freeze(struct page *page, int count) { - int ret = likely(atomic_cmpxchg(&page->_refcount, count, 0) == count); + int old_val = atomic_cmpxchg_acquire(&page->_refcount, count, 0); + int ret = likely(old_val == count); if (page_ref_tracepoint_active(page_ref_freeze)) __page_ref_freeze(page, count, ret);