Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp332873pxb; Wed, 13 Jan 2021 05:01:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZW+CnvP/HeAajB4b/S7DReYVGeE3FuR4tl0771BUMOLnuhsT4J8yjvOxbvbE2rWeZ+xkF X-Received: by 2002:a05:6402:1caa:: with SMTP id cz10mr1694678edb.345.1610542911976; Wed, 13 Jan 2021 05:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610542911; cv=none; d=google.com; s=arc-20160816; b=Sl6oFf9S1zbtDNY69oA1DmRRmKpBPwevOJ4GEGBu3MvMiXXwiPumavZBxnXT0HTMI/ k3fElY+kqs+OYKULhvvlX6OuE6ql5r5Uc88EOpVkAnc0rF8dpFBja7A2LgUEZEWHQe61 w/lxGyyA5R2tYcy5RgXMF1J04y2EWMMqkc1OVBhUuJOOBPvqmIfmrW1/mMVdgpIe0Rr+ zHvmjzGIZv9HU5jrJcAlELZjpiGePjCEFJF00jd3HFQTuGgULFZv4+jswzlNHR4YQLYL kxstvkqX5U27q5iNgwpsckkayb92IK8GonGDEF93ndvL7BQL9K8p9gxLOFI366BWA7D0 DXCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8W+YeZCRHcgbsYU4MRilZbbZCOazPjouIMGS7e+DlSg=; b=evWEu69ZBTgkFo3W12OJyvh1Gg8IXo3c5zTernRTyEfWa7WFFI/3CfO4l9CiAg8jOz ZP8/zzSkUUdomBKL1YTjcIlCj/L241KPDNbXN1HayH5os5Dbej/Y+Fwkn1tLNc/aO+Ln e34J71cFhApUFs3y+3k7QyFkNSvfuspKOs4Pdv3YUcSMr8XvaOTw8Eg9hris4VteFCYv 8eVOkerK7iLwmKoJhruVn3TfS6FHXuEkyftv+8cVV5PgvtbV/JfFPQun0CvO07U5Xbam gL4Uly9zhRHWow2bYTZM/3QfMdWxGw5SUBVwRF6MjfsI4EH0zlCBkJhFJIVASXOheZyn 0rig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CXxXBMBw; 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 o6si836844ejj.354.2021.01.13.05.01.22; Wed, 13 Jan 2021 05:01:51 -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=@infradead.org header.s=casper.20170209 header.b=CXxXBMBw; 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 S1726456AbhAMM6C (ORCPT + 99 others); Wed, 13 Jan 2021 07:58:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbhAMM6B (ORCPT ); Wed, 13 Jan 2021 07:58:01 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 398E5C061794 for ; Wed, 13 Jan 2021 04:57:21 -0800 (PST) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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