From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ED93C433DB for ; Wed, 13 Jan 2021 12:57:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CB90A233F6 for ; Wed, 13 Jan 2021 12:57:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB90A233F6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 154628D004F; Wed, 13 Jan 2021 07:57:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12A648D002E; Wed, 13 Jan 2021 07:57:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019228D004F; Wed, 13 Jan 2021 07:57:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id DD8608D002E for ; Wed, 13 Jan 2021 07:57:11 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AA010180AD815 for ; Wed, 13 Jan 2021 12:57:11 +0000 (UTC) X-FDA: 77700752262.29.sort77_3b10a2f2751e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 59B08180868E3 for ; Wed, 13 Jan 2021 12:57:11 +0000 (UTC) X-HE-Tag: sort77_3b10a2f2751e X-Filterd-Recvd-Size: 4669 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 12:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8W+YeZCRHcgbsYU4MRilZbbZCOazPjouIMGS7e+DlSg=; b=CXxXBMBwjMrPcvbKXw9qj+Y013 3o/bKQmMdi6oApNqXGFrPPTLJuq1trU+edOVn2owS4/yYaBB797T7rEibLGPb5wybmpPZZ1bq76Zu RaAokAIO1V+kbxfx1oEEs1ivOFpxeVQNGDOFBIZIyk5NR0oHMRyHWKVfxat1BMCnQ4JgCG9hhEO6g 8FY4iszlgKKnTfp+9wcy5Zo2Ql3r1EUCccwkgfSASvD+WhbeLO/V7q4/h/QJNvYYPyEEqAXEGoOWG tBKkvJDFA0R1aWzxsViOBzz795I4OSeR8YhTn7XVQbKTn1/YpTaB57n1FjqrZgTf+6HVRaIUsLmiG +siVW3XA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1kzfgS-006GlI-R6; Wed, 13 Jan 2021 12:56:04 +0000 Date: Wed, 13 Jan 2021 12:55:32 +0000 From: Matthew Wilcox To: "Kirill A. Shutemov" Cc: Linus Torvalds , John Hubbard , Andrea Arcangeli , Andrew Morton , Linux-MM , Linux Kernel Mailing List , Yu Zhao , Andy Lutomirski , Peter Xu , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , Minchan Kim , Will Deacon , Peter Zijlstra , Hugh Dickins , Oleg Nesterov , Jann Horn , Kees Cook , Leon Romanovsky , Jason Gunthorpe , Jan Kara , Kirill Tkhai , Nadav Amit , Jens Axboe Subject: Re: [PATCH 0/1] mm: restore full accuracy in COW page reuse Message-ID: <20210113125532.GN35215@casper.infradead.org> References: <45806a5a-65c2-67ce-fc92-dc8c2144d766@nvidia.com> <20210113021619.GL35215@casper.infradead.org> <20210113123232.62vv6xsrpitne7hc@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210113123232.62vv6xsrpitne7hc@box> 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: On Wed, Jan 13, 2021 at 03:32:32PM +0300, Kirill A. Shutemov wrote: > On Tue, Jan 12, 2021 at 07:31:07PM -0800, Linus Torvalds wrote: > > On Tue, Jan 12, 2021 at 6:16 PM Matthew Wilcox wrote: > > > > > > The thing about the speculative page cache references is that they can > > > temporarily bump a refcount on a page which _used_ to be in the page > > > cache and has now been reallocated as some other kind of page. > > > > Oh, and thinking about this made me think we might actually have a > > serious bug here, and it has nothing what-so-ever to do with COW, GUP, > > or even the page count itself. > > > > It's unlikely enough that I think it's mostly theoretical, but tell me > > I'm wrong. > > > > PLEASE tell me I'm wrong: > > > > CPU1 does page_cache_get_speculative under RCU lock > > > > CPU2 frees and re-uses the page > > > > CPU1 CPU2 > > ---- ---- > > > > page = xas_load(&xas); > > if (!page_cache_get_speculative(page)) > > goto repeat; > > .. succeeds .. > > > > remove page from XA > > release page > > reuse for something else > > How can it be reused if CPU1 hold reference to it? Yes, Linus mis-stated it: page = xas_load(&xas); remove page from XA release page reuse for something else if (!page_cache_get_speculative(page)) goto repeat; if (unlikely(page != xas_reload(&xas))) { put_page(page); ... but as David pointed out, I fixed this in e320d3012d25