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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 11D74C433E1 for ; Mon, 18 May 2020 14:58:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B11BF20756 for ; Mon, 18 May 2020 14:58:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=szeredi.hu header.i=@szeredi.hu header.b="jNxiiFVf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B11BF20756 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=szeredi.hu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4184B900003; Mon, 18 May 2020 10:58:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C76E900002; Mon, 18 May 2020 10:58:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28DBC900003; Mon, 18 May 2020 10:58:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 124E2900002 for ; Mon, 18 May 2020 10:58:19 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BB18F181AEF15 for ; Mon, 18 May 2020 14:58:18 +0000 (UTC) X-FDA: 76830145476.15.pie84_82b34e57dab3d X-HE-Tag: pie84_82b34e57dab3d X-Filterd-Recvd-Size: 4003 Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Mon, 18 May 2020 14:58:18 +0000 (UTC) Received: by mail-ej1-f68.google.com with SMTP id s3so9071276eji.6 for ; Mon, 18 May 2020 07:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DaljLdaQEqjIwG5s3riYxKTAYKM7jSvuGLXyEfayG+w=; b=jNxiiFVfs7pxf9eRib5F6j64/BEJZYOo6MRhu4yXLcyO+4obcNW971sHWzMTvUXdMv LFDQ+P2vbh9N7eUlbK9Z7CdtKfnjT2MNOLQI0r0J6ai843uC4nQ95r5HAenLNQzMnBra tf4/93uD6OfR4AeYqWb1xvT8Y8yaztEI5ixig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DaljLdaQEqjIwG5s3riYxKTAYKM7jSvuGLXyEfayG+w=; b=VLyhyXW/1XGG2DB2poP0ucf4CWYO7IvhMvCDFzFZ75LwNlguDosVZ0R3mcLT/nrJ1O +xAoEziuHeKszX7zjsPJ9zMi88ZPHsz4HmCd3mZ0tbfZS+QzJb751ZoQCXP03R2YmWbJ DmhmF9A0je1ah0zJpP06x9ByvBazqa+LY3vigsR8LkYcGhUyqZb9dEDy2hqZI3SyC+6C VNik+QNjiamK/KIgLKvT7dhiZamnrycLzyMCPPaFczfkGRkGIm3XplpoeeWPgqXeBu8n 1llJzzoPypfzwkFOGHzh7OPAu6p/p+VFpNwxSE2svwO5UewqxxdhINAx+nz9ZcvY0Aey iJGw== X-Gm-Message-State: AOAM533JJQx8N/xancsQcDLVSYaZy+/JvAzvDblz44zGXUJN/lPK+YMD p+26ULBitF5N8MYgyCZjd+x98ze5WR+r0FUIdbwd4Q== X-Google-Smtp-Source: ABdhPJwfPCg+ZFk8Sq/8O1mJJLB55LOH/sio1h+rP8/Wr1EQxFfHgOkepSWHZFhuItr7OWYcAu3+WC+9KxcyIrOAQIM= X-Received: by 2002:a17:906:82d9:: with SMTP id a25mr15825176ejy.43.1589813896578; Mon, 18 May 2020 07:58:16 -0700 (PDT) MIME-Version: 1.0 References: <87a72qtaqk.fsf@vostro.rath.org> <877dxut8q7.fsf@vostro.rath.org> <20200503032613.GE29705@bombadil.infradead.org> <87368hz9vm.fsf@vostro.rath.org> <20200503102742.GF29705@bombadil.infradead.org> <20200518144853.GT16070@bombadil.infradead.org> In-Reply-To: <20200518144853.GT16070@bombadil.infradead.org> From: Miklos Szeredi Date: Mon, 18 May 2020 16:58:05 +0200 Message-ID: Subject: Re: [fuse-devel] fuse: trying to steal weird page To: Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, fuse-devel , linux-mm , miklos , Gabriel Krisman Bertazi , =?UTF-8?Q?Andr=C3=A9_Almeida?= Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.001612, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, May 18, 2020 at 4:48 PM Matthew Wilcox wrote: > > On Mon, May 18, 2020 at 02:45:02PM +0200, Miklos Szeredi wrote: > > page_cache_pipe_buf_steal() calls remove_mapping() which calls > > page_ref_unfreeze(page, 1). That sets the refcount to 1, right? > > > > What am I missing? > > find_get_entry() calling page_cache_get_speculative(). > > In a previous allocation, this page belonged to the page cache. Then it > was freed, but another thread is in the middle of a page cache lookup and > has already loaded the pointer. It is now delayed by a few clock ticks. > > Now the page is allocated to FUSE, which calls page_ref_unfreeze(). > And then the refcount gets bumped to 2 by page_cache_get_speculative(). > find_get_entry() calls xas_reload() and discovers this page is no longer > at that index, so it calls put_page(), but in that narrow window, FUSE > checks the refcount and finds it's not 1. What if that page_cache_get_speculative() happens just before page_ref_unfreeze()? The speculative reference would be lost and on put_page() the page would be freed, even though fuse is still holding the pointer. Thanks, Miklos