Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1771929ybn; Thu, 26 Sep 2019 01:53:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUxtka/O7uZZ0/kASH7s9H7TNw7nXfQvxau0ey5BbI/HAclHRdKp7wYM6lzyVwbA9BsiXE X-Received: by 2002:a50:9fe5:: with SMTP id c92mr2348425edf.280.1569488021231; Thu, 26 Sep 2019 01:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569488021; cv=none; d=google.com; s=arc-20160816; b=fCiX2wQ+F110C15RxordyUedk+zR4dOHRZ4s4Ic0Oh9WXvgWEeOH6wmLiSAxzSTw6T v1lKSxxzvZSxPXQJCoPZjRjcwDAvo8RewDqlNsNsUMjiRYJq7dMWRWrMdE4Re8T9a1VR Mx8u/UBu8elIWnCkSpcWQW8JFyXvKVphaA3q2IRPkbvICPP9JOP5DhJU+rB8K6P0/CsQ hOuh+PPafFRhsceu8gJ8YEMUGx4Sbax6J5Hu3cqmsIfAAghK5bTz2wFv0J2FOygQ+Eqx LvSmQTvv0hHUZ+3CkIvdTr+mu1S/pZfH4+0bMZ/Iz6dNUq4yPSYlJIgpBfI4KeD8Y2fT 9IZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=z/I3kJAxeP9vdAUcYchKoI07LQS8bBjcrtLkIzAX8o0=; b=slJr3gNB4bPJzM16rV954PnbirRpaPpLgYTzj5vb3+KC8msrxGo6P5lHvIoeyMHGbi WzGHK2r06XMtDxfiW457eSqPupEzU+nWk6qIyQfhE56C1af7v7r1Q7qWXSofbS5Z9fIs r6cIACRLXYemBHdlkCut4JYaEadajylgbRsxHzcft1crMX+KaR/DEvf1vLLm4b8aJKzj VzrLnH8vAjb3CGVRiXnS56HL/4BWI6DHiKxfAlPQ2INs0TZ7ygMHkVNct5U+sR6/urnb Z1Cg9kl3MMi98+sL9ascO4/1yv98rznoQI5em/ilvFuzBE5fG+gGZ1hXO9SV4odZtWni fHvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=dxfzvyoY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si969680edk.16.2019.09.26.01.53.18; Thu, 26 Sep 2019 01:53:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=dxfzvyoY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393167AbfIXVnl (ORCPT + 99 others); Tue, 24 Sep 2019 17:43:41 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33160 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391667AbfIXVnl (ORCPT ); Tue, 24 Sep 2019 17:43:41 -0400 Received: by mail-qt1-f193.google.com with SMTP id r5so4077444qtd.0 for ; Tue, 24 Sep 2019 14:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=z/I3kJAxeP9vdAUcYchKoI07LQS8bBjcrtLkIzAX8o0=; b=dxfzvyoYzd+MaLowVdU8lfd3vRiqV8QDbzsg9zMKqnZatDJWbwAV/uchh+oFmCZjm1 tnNto9pqqZ1eC1vo0f8Airoj+Sz9bci1GlX+YWQP+4MslqXQh9B+Tq5wEAMgMb3lQT9W YAH4AA9ju8lGOW+gJjj/WadWNSauJ+s9s2cuJEodK8AXSzKFeKrnXBOcIT0+rHj5qHEl lHXjbfwvyZuGS75wpxOVU9I096RWBw8F2thGg/GqclaRaFc1BMRip6AZUeu+Szt6f2dJ Gsiyfk+0lVYkR1+Ck3pBRHmaUzr/7zW5OQZr9fbChajg2BAtL7ggntW50WnR//f4Ogyx rlpg== 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:user-agent; bh=z/I3kJAxeP9vdAUcYchKoI07LQS8bBjcrtLkIzAX8o0=; b=aPSVa6uE2JixU8XUWBaDejfkGEWaVjTKJuZpEABROa0ETF1hqwnBLAMv26fg/2u9WY H2XGuKBUgkyvOsQALrQXeTe3G9nyUF8M+KTlMwIFa7dkbCufhuYbL8Zd+rYe1urenzx9 erTeJz+ORYuAepOSiqxqvGlVotmSS/BwnRx+fB1MaTFfAhiM/4N3edEtWpSb/ywjewPF FxfDY0PqdCaN/3Hae/tsaJTaNmRjaB5KrylJdvElTsoZtm/Ykd5/EJye5m3ebgyswEVw WYB3cMhfJ0TOKJos+y1q9irA3b7UBecCbpm0XKkOk8NTKz2kCP5O1ez6T5GiA5vGsEDm vsGg== X-Gm-Message-State: APjAAAXBEywdUJeX0Ej8B0yzyUqPAAzpW7Bi12/u3ybF0eay+eS1vnAo 6iSeyPRt0CtpKHgF4/6dDrvThsY4Leo= X-Received: by 2002:ac8:2782:: with SMTP id w2mr5341601qtw.145.1569361418500; Tue, 24 Sep 2019 14:43:38 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::a51]) by smtp.gmail.com with ESMTPSA id 54sm1746463qts.75.2019.09.24.14.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2019 14:43:37 -0700 (PDT) Date: Tue, 24 Sep 2019 17:43:37 -0400 From: Johannes Weiner To: Matthew Wilcox Cc: Andrew Morton , Josef Bacik , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: drop mmap_sem before calling balance_dirty_pages() in write fault Message-ID: <20190924214337.GA17405@cmpxchg.org> References: <20190924171518.26682-1-hannes@cmpxchg.org> <20190924174809.GH1855@bombadil.infradead.org> <20190924194238.GA29030@cmpxchg.org> <20190924204608.GI1855@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190924204608.GI1855@bombadil.infradead.org> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 24, 2019 at 01:46:08PM -0700, Matthew Wilcox wrote: > On Tue, Sep 24, 2019 at 03:42:38PM -0400, Johannes Weiner wrote: > > > I'm not a fan of moving file_update_time() to _before_ the > > > balance_dirty_pages call. > > > > Can you elaborate why? If the filesystem has a page_mkwrite op, it > > will have already called file_update_time() before this function is > > entered. If anything, this change makes the sequence more consistent. > > Oh, that makes sense. I thought it should be updated after all the data > was written, but it probably doesn't make much difference. > > > > Also, this is now the third place that needs > > > maybe_unlock_mmap_for_io, see > > > https://lore.kernel.org/linux-mm/20190917120852.x6x3aypwvh573kfa@box/ > > > > Good idea, I moved the helper to internal.h and converted to it. > > > > I left the shmem site alone, though. It doesn't require the file > > pinning, so it shouldn't pointlessly bump the file refcount and > > suggest such a dependency - that could cost somebody later quite a bit > > of time trying to understand the code. > > The problem for shmem is this: > > spin_unlock(&inode->i_lock); > schedule(); > > spin_lock(&inode->i_lock); > finish_wait(shmem_falloc_waitq, &shmem_fault_wait); > spin_unlock(&inode->i_lock); > > While scheduled, the VMA can go away and the inode be reclaimed, making > this a use-after-free. The initial suggestion was an increment on > the inode refcount, but since we already have a pattern which involves > pinning the file, I thought that was a better way to go. I completely read over the context of that email you linked - that there is a bug in the existing code - and looked at it as mere refactoring patch. My apologies. Switching that shmem site to maybe_unlock_mmap_for_io() to indirectly pin the inode (in a separate bug fix patch) indeed makes sense to me. > > Signed-off-by: Johannes Weiner > > Reviewed-by: Matthew Wilcox (Oracle) Thanks, Matthew.