Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5538097pxb; Wed, 26 Jan 2022 14:28:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6qiONLTzHNKEWfWhTlxyLG/AgfeYT7WHWDoPuMOx/2KCm+mJ6WxRmUbZTZw6UXCBbDjjT X-Received: by 2002:a05:6402:1e92:: with SMTP id f18mr1083675edf.34.1643236110774; Wed, 26 Jan 2022 14:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643236110; cv=none; d=google.com; s=arc-20160816; b=N+MmE6jGuvnkYHUEe1VeQtFiC1fdYxtAwk/eP0s+iKLeQlhyKsx7Bi4QqmVK/uTfV/ 0zi9lz68wsEJnJIqCPgoO4ea6q4vGxLec0at8m51lFkSJkdtYDiXscrDrunOHDLQXebA lWr8qIlD8MZBJJzQAfwLRksV3NHiKkT2OMGOhsVr1uWazw9gYkdChfaw92k3VaP+8516 tMOflcRTGpA5TmRpHePZRoPvEmek8PiP3CiyR39AUIass439kjheSx5KvlfVspG6cDlZ wwCIzxcZnYSiEwvkkF8KPN84oHltGxcXp+Jvgs7Q0qYdFFwE0v7xB9Cw+H4+MXZXZ1hK IDgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=l8kTegpTqMksygyMNd7O9r7qJ6myjdhmrXkVSbv/IzA=; b=aqOfsNUcB1PW4wt4KGoNHTQhamSqlf8pNNySSw1WfBPw2vXgeehAWj6bj1QrUcGCVv dXrR0KBlGucMdGK0km9q8locKQkAAtDOOHJAfSoqj5gJuisbD+Of+NzsRIfkI5Z4WmwM L4YzZdhCFQueDlT0Q4g/1qKF7oB7odvRowvsmVwM+CcaJzDVtQpEEaArPOq2rhaMqrTl tzoH8C36FKalSMH7pieqGOVwuBh6H1QA2eb7TiLf8HNScB/1coI2UL9kxQMPJjOm6yuw +UcOU+sU1UYWkBPDtgpSMkOk6Ue1iy8oB+dnC7jj6oecVN8GZD7wqa1UYMUyZMVxHwTc 8FOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="dcgO/hZ6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si253610edq.27.2022.01.26.14.28.03; Wed, 26 Jan 2022 14:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="dcgO/hZ6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244217AbiAZSe6 (ORCPT + 99 others); Wed, 26 Jan 2022 13:34:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244138AbiAZSel (ORCPT ); Wed, 26 Jan 2022 13:34:41 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8BCC061749 for ; Wed, 26 Jan 2022 10:34:41 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id k9so607751qvv.9 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=ZzSUiejvpBeUd/M4O9kbf5kFlrVbqCzvE+C5r+54cAC4sLQWQHRevJlfQZf6KPM2hh Dohz8WCslGFsd6OmV5dVPaB9NHBstzOK37BySm3ZqsppTFyfuLPzX+U7FKmN1Q/JZ/FX bEQRbK6iUpjMgwKqeQ655EULOsIQL9Y5vLCOZcoAIMU8kgoq1cmFTGiFjnn8BDg2e3AJ YtZ98r+5Be96fRsMyxJYAANQ2d9FvCJzIGJeAiOPKW+6VTj4+PYDwI6Iztv5dv3FFfXZ C8yWw4VEQ12PcsJmV4dttJguyJnYy6zOKlrkf7jtZSk+VHa6WliSXAblCfm1o/6pCCqo FfCA== X-Gm-Message-State: AOAM532MYRnKuU3mZuDmZ1lrSQ/y6VA+OKvmOPFrTqncq+FHYNX0yBT0 6ziiqUFAJazs/ECO0cHk7tOl4A== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.35.0.rc0.227.g00780c9af4-goog