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 D3B58C433DB for ; Wed, 13 Jan 2021 12:33:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82B0F23339 for ; Wed, 13 Jan 2021 12:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbhAMMdQ (ORCPT ); Wed, 13 Jan 2021 07:33:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbhAMMdP (ORCPT ); Wed, 13 Jan 2021 07:33:15 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 503BEC061575 for ; Wed, 13 Jan 2021 04:32:35 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id o17so2506057lfg.4 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=rdqSrrmHTusQIIUQJOinQ1pGW7eW+hmvIWRIg1+Z28d/XMlt4T3kkTUOvsrN78J6Ot UZ4N36a9YGRIqpfP25J99bbtcI8VXZfWuqRcVItOKGvndyeibP3mCsTuwFmhl7W9EIrH lcYEeLZRDJSwJnGCk9Xy43aQPkgfZI2HKZxT5FuyKnJlhag3lH81R8tvjNCV3rA0ngy4 hpSjL0mwZ++dQPGiXIPoHjepofs4bTvxeiquHyvIrKizd5ajoEalsYampJXpGJAvqxwu 4Y7euyEHxHSXKOmV5gSBvLqo2IXaEh6Ngza+Dz9bMurnUfE+n7zJmQeGfHGUbO8UpsZb zbYQ== X-Gm-Message-State: AOAM531qfYHO+S9/EdBYKbSgC2WasTuO+XUTz3FAEGI8+xxqaYA8y0wE m5ybdJzAYIZowI4jda+GshGglw== 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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