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=-5.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 4748EC4360C for ; Fri, 4 Oct 2019 13:24:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 00DDD207FF for ; Fri, 4 Oct 2019 13:24:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="BhRNITA6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00DDD207FF 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 9FB736B0007; Fri, 4 Oct 2019 09:24:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ACBF6B0008; Fri, 4 Oct 2019 09:24:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89D9A6B000A; Fri, 4 Oct 2019 09:24:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 6825E6B0007 for ; Fri, 4 Oct 2019 09:24:11 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 1EA69181AC9AE for ; Fri, 4 Oct 2019 13:24:11 +0000 (UTC) X-FDA: 76006170702.15.fight39_418d3677d5f49 X-HE-Tag: fight39_418d3677d5f49 X-Filterd-Recvd-Size: 7724 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 4 Oct 2019 13:24:10 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id r4so5826877edy.4 for ; Fri, 04 Oct 2019 06:24:10 -0700 (PDT) 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:content-transfer-encoding:in-reply-to :user-agent; bh=kC0wou+Dasn/pd1LnI7XBoVoqfoHQBaDPYzRoYPpQxM=; b=BhRNITA6NTYE/ZXWEXJV/K+t8yiBZHujBRRNrxtrKVoLvxG54Jju2AsHqVYpqDl66d 5IMDajpyyDGlD1YO/U95nfJpF/4jV+Ey/euGrG9fR4Vk+3uapwprtymiREEa63kwohhe D1rZimm8b/8e6awZyPZF/1P/LA0YNNQpN5Gqk/jETdi4WgQLWW9APZebz2nHsa7BCAjL cZN8pVP9ytNzsSIahA8CFyrSkwC+kVaDr0yse/8rmb067xI5ZrfvAa5amu+X46qpFX/j EEi+/nd4y5bteKQEFeBrZE4ICHV47H9nKFxONMVwcYUHZeLB3fGBn033B2WTLzGgttCA ugkw== 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:content-transfer-encoding :in-reply-to:user-agent; bh=kC0wou+Dasn/pd1LnI7XBoVoqfoHQBaDPYzRoYPpQxM=; b=tPUiLbegObmIIXgYk8F6Q71A+E8lVgBCmjjot15by/wqic5hGAeLBXNCbJbLbr3ygI gQAilfjIIwl6JeU9MXzdA/XHDPRL89L8ecgLL5Z/hAdZ+xvB3cgYcA/4vvnd70A5sNkN zVFDuztHPuJ9odSMpp7H8ZYHQ6ov6OHsZ+gYtpiU93uWEvwou/KI0QQlf3s3Trc7/Jpm 29z4iSvD0lroz2SQ5UqUH17nkDQGJ4N3w7dQkU8QxeLd2lM5IV3zGxD2G1UHESiwRQZ2 WvdKJRJYwlbZD+shnCjKXRAVmk3errznRBC2nVFnUuHROyxlQ7WvUe+to3aYwq13scF6 bf8A== X-Gm-Message-State: APjAAAUEhzmlpHDVr0ZmF5B43e6m0BGXs6mhQUAtsP495XZX1SliWCZC jMwy9VFndh9tK8h7VSoxSkIENw== X-Google-Smtp-Source: APXvYqwKMovkTP9ls7BP16QYMpDJXtQ1KEBlJSMu1r2z/XB6HGs81c1HF+I/xgQ/Y7dvK5Ygt7OdXQ== X-Received: by 2002:a50:9402:: with SMTP id p2mr15211536eda.111.1570195448996; Fri, 04 Oct 2019 06:24:08 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id ha2sm601859ejb.63.2019.10.04.06.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 06:24:08 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 4C3FE102143; Fri, 4 Oct 2019 16:24:07 +0300 (+03) Date: Fri, 4 Oct 2019 16:24:07 +0300 From: "Kirill A. Shutemov" To: Thomas =?utf-8?Q?Hellstr=C3=B6m_=28VMware=29?= , Matthew Wilcox , Dan Williams Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, Thomas Hellstrom , Andrew Morton , Will Deacon , Peter Zijlstra , Rik van Riel , Minchan Kim , Michal Hocko , Huang Ying , =?utf-8?B?SsOpcsO0bWU=?= Glisse Subject: Re: [PATCH v3 2/7] mm: Add a walk_page_mapping() function to the pagewalk code Message-ID: <20191004132407.gzttci7lio6be467@box> References: <20191002134730.40985-1-thomas_os@shipmail.org> <20191002134730.40985-3-thomas_os@shipmail.org> <20191003111708.sttkkrhiidleivc6@box> <20191004123732.xpr3vroee5mhg2zt@box.shutemov.name> <8ef9fff3-df8d-cc14-35f9-d83db62e874f@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <8ef9fff3-df8d-cc14-35f9-d83db62e874f@shipmail.org> User-Agent: NeoMutt/20180716 Content-Transfer-Encoding: quoted-printable 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 Fri, Oct 04, 2019 at 02:58:59PM +0200, Thomas Hellstr=F6m (VMware) wro= te: > On 10/4/19 2:37 PM, Kirill A. Shutemov wrote: > > On Thu, Oct 03, 2019 at 01:32:45PM +0200, Thomas Hellstr=F6m (VMware)= wrote: > > > > > + * If @mapping allows faulting of huge pmds and puds, it is = desirable > > > > > + * that its huge_fault() handler blocks while this function = is running on > > > > > + * @mapping. Otherwise a race may occur where the huge entry= is split when > > > > > + * it was intended to be handled in a huge entry callback. T= his requires an > > > > > + * external lock, for example that @mapping->i_mmap_rwsem is= held in > > > > > + * write mode in the huge_fault() handlers. > > > > Em. No. We have ptl for this. It's the only lock required (plus m= map_sem > > > > on read) to split PMD entry into PTE table. And it can happen not= only > > > > from fault path. > > > >=20 > > > > If you care about splitting compound page under you, take a pin o= r lock a > > > > page. It will block split_huge_page(). > > > >=20 > > > > Suggestion to block fault path is not viable (and it will not hap= pen > > > > magically just because of this comment). > > > >=20 > > > I was specifically thinking of this: > > >=20 > > > https://elixir.bootlin.com/linux/latest/source/mm/pagewalk.c#L103 > > >=20 > > > If a huge pud is concurrently faulted in here, it will immediatly g= et split > > > without getting processed in pud_entry(). An external lock would pr= otect > > > against that, but that's perhaps a bug in the pagewalk code?=A0 For= pmds the > > > situation is not the same since when pte_entry is used, all pmds wi= ll > > > unconditionally get split. > > I *think* it should be fixed with something like this (there's no > > pud_trans_unstable() yet): > >=20 > > diff --git a/mm/pagewalk.c b/mm/pagewalk.c > > index d48c2a986ea3..221a3b945f42 100644 > > --- a/mm/pagewalk.c > > +++ b/mm/pagewalk.c > > @@ -102,10 +102,11 @@ static int walk_pud_range(p4d_t *p4d, unsigned = long addr, unsigned long end, > > break; > > continue; > > } > > + } else { > > + split_huge_pud(walk->vma, pud, addr); > > } > > - split_huge_pud(walk->vma, pud, addr); > > - if (pud_none(*pud)) > > + if (pud_none(*pud) || pud_trans_unstable(*pud)) > > goto again; > > if (ops->pmd_entry || ops->pte_entry) >=20 > Yes, this seems better. I was looking at implementing a pud_trans_unsta= ble() > as a basis of fixing problems like this, but when I looked at > pmd_trans_unstable I got a bit confused: >=20 > Why are devmap huge pmds considered stable? I mean, couldn't anybody ju= st > run madvise() to clear those just like transhuge pmds? Matthew, Dan, could you comment on this? > > Or better yet converted to what we do on pmd level. > >=20 > > Honestly, all the code around PUD THP missing a lot of ground work. > > Rushing it upstream for DAX was not a right move. > >=20 > > > There's a similar more scary race in > > >=20 > > > https://elixir.bootlin.com/linux/latest/source/mm/memory.c#L3931 > > >=20 > > > It looks like if a concurrent thread faults in a huge pud just afte= r the > > > test for pud_none in that pmd_alloc, things might go pretty bad. > > Hm? It will fail the next pmd_none() check under ptl. Do you have a > > particular racing scenarion? > >=20 > Yes, I misinterpreted the code somewhat, but here's the scenario that l= ooks > racy: >=20 > Thread 1 Thread 2 > huge_fault(pud) - Fell back, for example because of write fault on = dirty-tracking. > huge_fault(pud) - Taken, read fault. > pmd_alloc() - Will fail pmd_none ch= eck and return a pmd_offset() I see. It also misses pud_tans_unstable() check or its variant. --=20 Kirill A. Shutemov