Message ID | 20211117012059.141450-10-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 C3086C433F5 for <linux-mm@archiver.kernel.org>; Wed, 17 Nov 2021 01:26:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 518E461C12 for <linux-mm@archiver.kernel.org>; Wed, 17 Nov 2021 01:26:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 518E461C12 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 5F4B56B0082; Tue, 16 Nov 2021 20:21:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A2806B0083; Tue, 16 Nov 2021 20:21:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 443756B0085; Tue, 16 Nov 2021 20:21:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 359C06B0082 for <linux-mm@kvack.org>; Tue, 16 Nov 2021 20:21:20 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F40728248D7C for <linux-mm@kvack.org>; Wed, 17 Nov 2021 01:21:09 +0000 (UTC) X-FDA: 78816668700.14.EE5B436 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf09.hostedemail.com (Postfix) with ESMTP id 397283000103 for <linux-mm@kvack.org>; Wed, 17 Nov 2021 01:21:08 +0000 (UTC) Received: by mail-qv1-f44.google.com with SMTP id u16so870646qvk.4 for <linux-mm@kvack.org>; Tue, 16 Nov 2021 17:21:09 -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=dKJmUx0S3b3gU9QerEdM5MtTK89f9bkEO3AdXrfthGg=; b=SiJvkIEmmAa+081NeDmkVtE5qXMKEyWz2TjohNpRU6u4LtKyx1uEhrJppd73vJzoFM 8BY29UHCMxrocLY5y8FJwbRKNg6rvaOr7/BCdVobyI3GcPT5w+zM9lIOzu7/Wbk0BEZR e9hAbvkI7utgriQ3AL8kzQ4cwOISlKrA9LJXK4vnEUb5RqZKIQHhhCxEx/UyFzJ1FY07 pRtmRje2wnvSN56pig/ow3liUabXKOy+ebNopsBKUDbYRi4Y95kZ+2Av9hHhlRUf9isj 9ihzFXX4IeTiln6zC9lZaS63ci3YUFDZCouE7fLp5n77zubKk27nRzSOQ6DI4RK6i71T CwOA== 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=dKJmUx0S3b3gU9QerEdM5MtTK89f9bkEO3AdXrfthGg=; b=bhBrOI1VaAmRUfMKljWmCt57rvKGpAZyDv1JpxyNunWNRRI0jrXwIstVLThuAnKCbx LaEp4kiOd+fqBHnXI7PoOuvIm81cpqn1On3aVs15Wm81ebeF8AWod1G0aE4KrioRYMGB EHJV4khIwTvzcqsJWzVv7INRJy7ETaAtQPsMcPeQY6r0zRAz6ObZw0K8Zhz7OpcmUP1n 6zN7DbTdhFDt6iV1pBiq42U5yCtxaIOvuGbtxUbcE7sLB9dSFVVVONFMtEUu7lH/TzkY DBUZdS5RbMKMUWCODO1yenxkdwDwwlqL4jq5wKhWOys/Qd4Qfo4WcHVi1cQUiKRXuyYz +bLg== X-Gm-Message-State: AOAM53286m7mQ/QW0LMT7NhrU2XSj3dlI8hK1sSlhfQgheK0wH6dl//m sE3FfUH7ljs/1Lppq24qztfjJw== X-Google-Smtp-Source: ABdhPJyGremPP9L92/6lcac/wA3df9Bul/Oomg4HlgGr7phDDIKwAGBqFNBXjyfBYYwK7urnRXunoQ== X-Received: by 2002:ad4:5fcd:: with SMTP id jq13mr49700248qvb.29.1637112069006; 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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 17:21:08 -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 09/10] mm: do not use atomic_set_release in page_ref_unfreeze() Date: Wed, 17 Nov 2021 01:20:58 +0000 Message-Id: <20211117012059.141450-10-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: rspam04 X-Rspamd-Queue-Id: 397283000103 X-Stat-Signature: anuozkawjsspni5gptzf4359cwo7ngir Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=SiJvkIEm; spf=pass (imf09.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.44 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-HE-Tag: 1637112068-828912 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000015, 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 8c76bf3bf7e1..26676d3bcd58 100644 --- a/include/linux/page_ref.h +++ b/include/linux/page_ref.h @@ -322,10 +322,9 @@ static inline int folio_ref_freeze(struct folio *folio, int count) static inline void page_ref_unfreeze(struct page *page, int count) { - VM_BUG_ON_PAGE(page_count(page) != 0, page); - VM_BUG_ON(count == 0); + int old_val = atomic_xchg_release(&page->_refcount, count); - atomic_set_release(&page->_refcount, count); + VM_BUG_ON_PAGE(count == 0 || old_val != 0, page); if (page_ref_tracepoint_active(page_ref_unfreeze)) __page_ref_unfreeze(page, count); }
In we set the old _refcount value after verifying that the old value was indeed 0. VM_BUG_ON_PAGE(page_count(page) != 0, page); < the _refcount may change here> atomic_set_release(&page->_refcount, count); To avoid the smal gap where _refcount may change lets verify the time of the _refcount at the time of the set operation. Use atomic_xchg_release() and at the set time verify that the value was 0. Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> --- include/linux/page_ref.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)