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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 C6590C43381 for ; Wed, 13 Jan 2021 12:32:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3027623339 for ; Wed, 13 Jan 2021 12:32:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3027623339 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8EF6E8D004C; Wed, 13 Jan 2021 07:32:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 879768D002E; Wed, 13 Jan 2021 07:32:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743528D004C; Wed, 13 Jan 2021 07:32:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 581A48D002E for ; Wed, 13 Jan 2021 07:32:36 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 125E2180AD820 for ; Wed, 13 Jan 2021 12:32:36 +0000 (UTC) X-FDA: 77700690312.06.dime31_2906eb62751e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id E7814100480A0 for ; Wed, 13 Jan 2021 12:32:35 +0000 (UTC) X-HE-Tag: dime31_2906eb62751e X-Filterd-Recvd-Size: 5831 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 12:32:35 +0000 (UTC) Received: by mail-lf1-f42.google.com with SMTP id o13so2507460lfr.3 for ; Wed, 13 Jan 2021 04:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=G4I/u23B9cutM4KrBlaPjQW4iYtRm9vAHciYINpRKrU=; b=YCjdWD0DN/Sz51SeG2Vf99qoFIZeSDy2px9F0Z3ObU5M2sN+GRf14GX8WeuK/nh+2y I+BN787g/iaQwOS7ttXO1puD5Cg10RQnUykfy9JNLIYQOsKP4OcSOrlvbyx7vYD5mSz4 T6kI0yRI3nB5x212HwSIBAvZioG0ax6acgqVdqufAWt+zsObVYU0Uxa2M7oC1+7M8qjQ ygsUFujWf8C5TKD5aaPWHR6sADMF+KhlfeIGf9F3Ft3DLCJMvekzvXhANulVAfhn4/uP +Gu+vA+Q9tNuTtlKH0YI3N9rUl30bCmIfPuvk2L28OZuU5QeU2bO74v4rSlaeF5kya+B paeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=G4I/u23B9cutM4KrBlaPjQW4iYtRm9vAHciYINpRKrU=; b=ppCzVzDfCozDvaQ/L+SS9bVK2bAPVUIv30ONAbP4qEhqle0I2jSakgXhdtI3vWyca/ cINTDI6v72yXbMQE/u/m9S6ENAn/9XD5d9LZvDsSAKLvKpKbzZf8amgh/sh6lyB+8qlK e/LsiMjCS2RswXXlJKxV2PCFF2gDPZEWl8yS89VBA2cyDNewbpBIR1vI/vJSFaQkfA7c URrwiDfJF6UUGIyxAOd5YiDs/j78gMmWnGccW5/hDVF85BHVCRykMTyPhodo1jMWJRkd QBibZQhBQCNUGiWgv0elJpGlOQ5KkS6IO4pqdXhytxORESMKcRWU5z4oxuBO3griGHon 163g== X-Gm-Message-State: AOAM531VGakfpjHEcJYOZMSgf69bqa/tLKXl8DbxcoqccdwRjYJ4hhco 6YKRyqxVaf88yn6fiMJlMZVBfw== X-Google-Smtp-Source: ABdhPJwys7kzAKkTMVE5V6fYyRNsRneoayL3CuYZfpkTNZMZMOPcNttxH9fAr4vxP0c03o8XhZi4dg== X-Received: by 2002:a19:381c:: with SMTP id f28mr770707lfa.339.1610541153879; Wed, 13 Jan 2021 04:32:33 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id g4sm197824lfc.85.2021.01.13.04.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:32:33 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 1661E102D04; Wed, 13 Jan 2021 15:32:32 +0300 (+03) Date: Wed, 13 Jan 2021 15:32:32 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds Cc: Matthew Wilcox , 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: <20210113123232.62vv6xsrpitne7hc@box> References: <45806a5a-65c2-67ce-fc92-dc8c2144d766@nvidia.com> <20210113021619.GL35215@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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? > > .. and then re-check .. > if (unlikely(page != xas_reload(&xas))) { > put_page(page); > goto repeat; > } > -- Kirill A. Shutemov