From patchwork Tue Dec 21 15:01:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12689819 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 D75C3C433F5 for ; Tue, 21 Dec 2021 15:02:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60C706B0085; Tue, 21 Dec 2021 10:02:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BB526B0087; Tue, 21 Dec 2021 10:02:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 484DD6B0088; Tue, 21 Dec 2021 10:02:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 3764F6B0085 for ; Tue, 21 Dec 2021 10:02:25 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 015798CA2A for ; Tue, 21 Dec 2021 15:02:25 +0000 (UTC) X-FDA: 78942117450.07.0DFA693 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf15.hostedemail.com (Postfix) with ESMTP id C6399A011D for ; Tue, 21 Dec 2021 15:01:46 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id o10so12663545qvc.5 for ; Tue, 21 Dec 2021 07:01:53 -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=ujiBeyeY0ZhWFNLdTCKueYw4ysMT9Aw/7apPybkWG1s=; b=PA3Q/yDh7W+DgSnKOTeVJUsVJL2iHQHGtRuXH0oQMCfi3NgBzbAlRtnkbB9VslFuln JgUXIsrq1dntIqfnKtVub3TAjFSBwovezuGjEs3vddMSz4B5E6iP75xXidJlVHdWmWRJ K2Hka8iaYZ5H/DI+OAzA2Wp0g/1hRTlVUi1AkgHDGaUEHi4zkn+tCPyqgXJyaUlevaHs LbEjFWY6ySLuQAHYvgf2ziB9zfVBqb9otAVbfhkvHbGoUQrnySsFwdw6XlQqKyE9RhVo XBcZRWgYNo4vWOlPwLvSnUALA/P7VH0q92uNKhHlNB67+Ut18sXhqjf6Ed+1ptUU0jls bK+Q== 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=ujiBeyeY0ZhWFNLdTCKueYw4ysMT9Aw/7apPybkWG1s=; b=OjjNqQGohZtPYwonEf+8ISAKlcdFiuvOsxp6H2vNIWEWoKftW6ki/x9JJ/X578pGOn IjEbJLLkEHq+DjJVXsg4llg2dagddJ6w02yKQmxcqCslNJy4u4wSWnut57fjOPY++++k dHf12sqNE99X7IPLGndsmLnSAlc4mrF3FG6F5LvddO9HILgEZ4jBXysa8hhPGf0rcQf9 PJHgb1RmwzbUZAm3p39fg/ddHzwYpt1x1Fq9cb8w10ioBvVIxln9x95Ief8yetoB3T/F /wrBJJkFyn+rACQgTMMk4Tde3h5f0RplR2pZDJAfjSkc5FxV/ZMT1mQQVks/kKIvI0Og dp6A== X-Gm-Message-State: AOAM532eNuwolUvwv3Te1BxDWjd9D1f8nt2UDX1423WFVDl8Lw8M8jSC hDKFnBpbw5uG1pmPfSSjujsR4g== X-Google-Smtp-Source: ABdhPJwstE7x+0HpgXRt/GfFm68tAcQrAuhOR2pvSynOcMLtQsVanoM/IfrenS7mms+J84bIphIm9Q== X-Received: by 2002:ad4:5aad:: with SMTP id u13mr2841845qvg.46.1640098913240; Tue, 21 Dec 2021 07:01:53 -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 d4sm1991371qkn.79.2021.12.21.07.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 07:01:52 -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 Subject: [PATCH v2 9/9] mm: use atomic_cmpxchg_acquire in page_ref_freeze(). Date: Tue, 21 Dec 2021 15:01:40 +0000 Message-Id: <20211221150140.988298-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.34.1.307.g9b7440fafd-goog In-Reply-To: <20211221150140.988298-1-pasha.tatashin@soleen.com> References: <20211221150140.988298-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="PA3Q/yDh"; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Queue-Id: C6399A011D X-Stat-Signature: f5grw533n97wxkj1r6jogqsr6yh87fme X-Rspamd-Server: rspam04 X-HE-Tag: 1640098906-248390 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: 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);