Message ID | 20211208203544.2297121-11-pasha.tatashin@soleen.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 46AC7C433F5 for <linux-mm@archiver.kernel.org>; Wed, 8 Dec 2021 20:40:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAFC26B0081; Wed, 8 Dec 2021 15:36:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5CC26B0082; Wed, 8 Dec 2021 15:36:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C885F6B0083; Wed, 8 Dec 2021 15:36:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id BBB4A6B0081 for <linux-mm@kvack.org>; Wed, 8 Dec 2021 15:36:14 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8BCE08277E for <linux-mm@kvack.org>; Wed, 8 Dec 2021 20:36:04 +0000 (UTC) X-FDA: 78895783848.20.B9D702A Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by imf08.hostedemail.com (Postfix) with ESMTP id A07FC30000B4 for <linux-mm@kvack.org>; Wed, 8 Dec 2021 20:36:02 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id bu11so3361099qvb.0 for <linux-mm@kvack.org>; Wed, 08 Dec 2021 12:36:02 -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=TNgBFR2jfrvrXs2YyapfvQCLu5M2/StKJMmjuovUQTs=; b=omntkBN3Tfs3I1WBLg5+7c4phKsJBox+G8HICkXoS3kH+6yRdLxFcodJ9xKyl9IoiV tcjkm/7dOMBC+J7Y65mfQWP/VXOIqkIe1BYuVg0/UeqqgV14DIoWmhYOgqkvJ0dksWJM yhe24oVkmqp9IYnbA+WSyLvwzs/2ZXXEVDI9dgOsKtpHW9333ry5Y/tBjS02b3z53wAU hEg3UZCM2U/tNpwKAhlJ/g9l8ZB1Y1S4iGXr3Zb0/Dfe4/C4+U3+MqtYa+eWJW7GMml1 4TFuNEidQCzNw1ubewJk7/mM2ZuFcSrJ7+DY7PfV/zzmlIOlmnjljJ5d7q05ATvysKul sd9Q== 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=TNgBFR2jfrvrXs2YyapfvQCLu5M2/StKJMmjuovUQTs=; b=dLo8RwXiZ8aXa6hxTa+QuLsbKFq4Phqj6tBdWXuEldSDOOFKKQ1Dk7crpmS4Tn701d fO7OqiHch9gOMxMER0AJcZpxctqelAjr0ng4eSdBP/htsPKAksbZ5Fh6GCtY2Giyhsho qiNAeidt4muBUqXQYhdNelSk+T0vDywfcXNkkPJQe9skXvOKQOc3dVuQaNhIk+YBIZ3r em+oSJ/ukZnqxxpRnxr32o2dYDX2Xu9xZSO20ys5dHrWzw4+g1bIu5YQIqq7Y3Cpr2Nl IP15Sda7XQtHhc3ggd8B27YAeK78wmkiCgrbe3zH/WXB0Xl75dmQsNtaH8fehC1clsu/ 4RLg== X-Gm-Message-State: AOAM532WH4GnColmyTonh0TbfK/mpK4lyXyPwzecMtg1f/ICl1XdR2Gy R8R3rkmvNgD/6XcpvbwzPgzIrPOUkORz3w== X-Google-Smtp-Source: ABdhPJzMR03yNKnGfrXlWyU1obhS7MOvT1xu4hAl3EjL7RVWQooSmoKydvdAqAFgx2q/dwK3dHYJEQ== X-Received: by 2002:ad4:4ee4:: with SMTP id dv4mr10231097qvb.59.1638995762436; Wed, 08 Dec 2021 12:36:02 -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 143sm1898710qkg.87.2021.12.08.12.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 12:36:01 -0800 (PST) From: Pasha Tatashin <pasha.tatashin@soleen.com> 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 10/10] mm: use atomic_cmpxchg_acquire in page_ref_freeze(). Date: Wed, 8 Dec 2021 20:35:44 +0000 Message-Id: <20211208203544.2297121-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211208203544.2297121-1-pasha.tatashin@soleen.com> References: <20211208203544.2297121-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A07FC30000B4 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=omntkBN3; spf=pass (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.43 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Server: rspam04 X-Stat-Signature: pcbhrenw1epcqzj696gjwxbgm3bemqif X-HE-Tag: 1638995762-353699 Content-Transfer-Encoding: quoted-printable 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: <linux-mm.kvack.org> |
Series |
Hardening page _refcount
|
expand
|
diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h index 26676d3bcd58..ecd92d7f3eef 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);
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 <pasha.tatashin@soleen.com> --- include/linux/page_ref.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)