Message ID | 20211117012059.141450-11-pasha.tatashin@soleen.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <SRS0=rmuZ=QE=kvack.org=owner-linux-mm@kernel.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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF17CC433F5 for <linux-mm@archiver.kernel.org>; Wed, 17 Nov 2021 01:26:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5248261BFE for <linux-mm@archiver.kernel.org>; Wed, 17 Nov 2021 01:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5248261BFE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 335876B0083; Tue, 16 Nov 2021 20:21:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E3E76B0085; Tue, 16 Nov 2021 20:21:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1ABCC6B0087; Tue, 16 Nov 2021 20:21:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id 0DD066B0083 for <linux-mm@kvack.org>; Tue, 16 Nov 2021 20:21:21 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CF4C785D6F for <linux-mm@kvack.org>; Wed, 17 Nov 2021 01:21:10 +0000 (UTC) X-FDA: 78816668700.28.A91BAEE Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf04.hostedemail.com (Postfix) with ESMTP id B3DA350000A1 for <linux-mm@kvack.org>; Wed, 17 Nov 2021 01:21:09 +0000 (UTC) Received: by mail-qv1-f44.google.com with SMTP id j9so837102qvm.10 for <linux-mm@kvack.org>; Tue, 16 Nov 2021 17:21:10 -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=175Dn+OmrWLalikvHXgtLaL0RinzWYRBjCoX9yGsvr8=; b=nRlJZzzt9m88Z0nj/5kEB+Zes3UkJ20EFtCk6ZM48f4cGo5kl2wcnggusHD2Dz7vhJ qAtHdjH9IyoAgHS5377lUw68u2uP7GUDcU3rk+mbiS+vyiLJ2e58T5UIfkY4HOqj+Qeh g5ad5XTxjzetjTTUD987sYt0ChOKZBfxwprjP9ti8pdDaQBQ1JSj++YdhF2SGP4twv82 bZcrCJDYcvlP/eZ8w5pR8rsbjnUKX5BfxJsKwXkQii6xqYCMXp6kPm5uV5rH29tXYxks n3rvnnTdxpxz4g4VdgvhLT5lNrq7flTarDX62meRhLNYdqUFQ0rmod1NjGyVyV9mUfIH /26A== 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=175Dn+OmrWLalikvHXgtLaL0RinzWYRBjCoX9yGsvr8=; b=QEUS+/u3i0XCG6NiWBagGbDtrcvKQ3EW8qu20Udyw4gnf/j+qivrUabtJATLGpBoqr 47AWntWB1S58b6eBp8qlmXYYredO4mPqJArZy/G1EE/ahcSuGlpCRQt6BvgMyLnVY6ir I2i++r2gPlzWIGzpbfec9PdjTAK8+WSrBLoLwj/+91wMBUeLP5qc8br2IrUXO7HMIdof 8TQA+LqqKNAwsbkffITB4J86jNFx2LDbd3FxTOPLPLP8IduPmEOYPAUMiNaAbJd4WrzW 5NgBxowUbTR7uY4JBrJrHOzTQ3KNsNTRyaXSQ3AoiipmnE79Z4Q4ClYFXAAZKQN9lJeK H5MQ== X-Gm-Message-State: AOAM531toKEvbn99sSh5ojrLr4c9+TJUllpWkn5IlttvRPSqNPddUcdK 2/ry1MEjPYUwB+2uZL9THjQhIw== X-Google-Smtp-Source: ABdhPJxOZPahTDzBZTUSHs/wzhS9iI2h8iV/m3zGhfmCPnFCVKUT0V4XucRscYGgLdy3/nkIiDQutQ== X-Received: by 2002:a0c:e98a:: with SMTP id z10mr50125465qvn.43.1637112069776; Tue, 16 Nov 2021 17:21:09 -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 i6sm3482289qti.40.2021.11.16.17.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 17:21:09 -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: [RFC v2 10/10] mm: use atomic_cmpxchg_acquire in page_ref_freeze(). Date: Wed, 17 Nov 2021 01:20:59 +0000 Message-Id: <20211117012059.141450-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211117012059.141450-1-pasha.tatashin@soleen.com> References: <20211117012059.141450-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B3DA350000A1 X-Stat-Signature: cexi5pk1b49uprt4cybzj3yqa9oy75mi Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=nRlJZzzt; dmarc=none; spf=pass (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.44 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1637112069-97028 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(-)