Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp318332pxb; Wed, 13 Jan 2021 04:35:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9j+yirOxFrxP1zLV7miu9I8fmiEVsOIhe0Xuv6T4K6vNbiGA+UUdhrFtPGpoAuwS9fdgy X-Received: by 2002:a17:906:410e:: with SMTP id j14mr1400697ejk.253.1610541348838; Wed, 13 Jan 2021 04:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610541348; cv=none; d=google.com; s=arc-20160816; b=LD+AW6xRzY0yzqIxyO6tF2cHtWxuNL5mzGf8lY2qSVeaQ9+TkJLxu58eb1TizEClBR WUqomzkMJzFPviLNpVobVybn3m2YZznBpmAr6vkl7+B+VelSYz6Hvr1fzrKu2ZlOR/ld /DXepS+BJ97jpCyBmcN0Cdr1bGO8n74tWQz8/BFFJBFA5CsSwfELZb8Xw38Q6ECxPWSP rsPmiy/paYgAKePmgtNY4KjIBEuNTKSAAQEgYaZroBrQcWaLJ56WYPh/KcBrn80GKIkV 4V6pB7gFoXPwQSCik3KUcL406kIGrlp/t9rPNwp51FmVoRtsgB3aXsM8CddSHWw2DQJR kpLg== 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=G4I/u23B9cutM4KrBlaPjQW4iYtRm9vAHciYINpRKrU=; b=imQE0AyazqGhv46YM6aPj5UVSePEMhUjPHEbTTUmJABJ+Ok6A+GhdCUAlzofSswuG4 52Q2fLxVVf0TNcuHebrKPGpqZECfVTWxmCHFTCE4a/y4v43E7gnCDF4Uo4v3znJaTucp Cs6x2mu0iX/DCTF0OD1ZBBsh8S5GuKg9W8pncJ1K5GXkve+GMC5MvITCzLcKzYTjKI17 2Gj6ZvrvkaifAoMNfaB7t5yjhaeYnuhhuHoZWuCuNNAL0HD9UHWUknZTZ+7GTsHmmBL8 4lU12FRN0BnaUaM9OrjNnyNFOPZBdLjuEJBZoqbzIusQqsfrLkJv87LPtmWnFb6FrTd5 Rutg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=YCjdWD0D; 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 l3si856431edi.333.2021.01.13.04.35.25; Wed, 13 Jan 2021 04:35:48 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=YCjdWD0D; 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 S1726948AbhAMMdQ (ORCPT + 99 others); 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-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