Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4470538rwo; Tue, 25 Jul 2023 06:39:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1sBIHxwavgDJMhTqe5pG/Y4skp4JYfHc16Pj7aKYjQMNlztcb2nD1IIhtnLZ9SoNFn4fn X-Received: by 2002:a05:6512:3e09:b0:4f9:cd02:4af1 with SMTP id i9-20020a0565123e0900b004f9cd024af1mr9041638lfv.34.1690292361508; Tue, 25 Jul 2023 06:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690292361; cv=none; d=google.com; s=arc-20160816; b=MsaM7qcXyDGSpZJGz64NAfcypnxxIwBrECBHXY/jJwVN+sTe0a9DMnIL4iZeQVVt3P LzmSv3ec/IMARNG9Ffyu1+jyKniW1cj7jLEpptFHe/kzyDKxp9YZuV6IJ3k73j33yvAQ 2pB+4zm9LZyhuTBzn2lUnMEaTLoqGcwAf5NEdCAQLTTJKwnErFIn2G7qGyHvd4/Kaogs 89+XMIqCppbSTJGkkJ4oH0vUE7Ej9ONOToFbLB4N8GPTa1r4aJjMFtzCeq7xCX7unhkS sIxV2gVW5fRrZZ+3c2Wz1tDFQ2Mcj9yWtP3KhqdzRaW96HX54t2FDGg8diFsFXMtAG9Y gdmg== 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=cip1L4+WNN72lEdlEtgKKz6+Th/GNW6kyU+RnxFbZZ8=; fh=qVyjkxIdh06dqvj2gKFCX7FVmLaO2IpE4whhCFlbbSs=; b=uGSew5th24bN8ZNIHB3YtVKzvVF3q3f2lvp0H82v3H8MgQi6S/KE9sbt9vlqjs+Nyt WOPP4n4XXt9ja2zBjIHwIf71/GP9kjn9HB5tWPyqvLZ9NOnrWP9tUyXKSph2FX9qL/ay 42A/T9own81M9bDaoIFR2JSeBQsO3J60bQmIfA0f9nc8bM1BXs/qhvljqhLwzR0DO9Mp 9BvjkUR1XArPW00F+VutuqDnkTGKzgr3QrjhwY9Lftm4r8X/fgFEwc4rKPTcTiMb7wXj n1TvlQtSGxqwoMVXrzgGCZRDDqVywIDhZYwQWpoKesFM6nr6M1eiaAOdeZmDr5LjSy+V YFEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UgAJBFRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k18-20020a170906a39200b00982a3005cf7si7720286ejz.605.2023.07.25.06.38.56; Tue, 25 Jul 2023 06:39:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UgAJBFRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbjGYMw2 (ORCPT + 99 others); Tue, 25 Jul 2023 08:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbjGYMw0 (ORCPT ); Tue, 25 Jul 2023 08:52:26 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04449DB; Tue, 25 Jul 2023 05:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cip1L4+WNN72lEdlEtgKKz6+Th/GNW6kyU+RnxFbZZ8=; b=UgAJBFRLO20d1Q4UeecSqlBQIs PFHuz0NUmB/1Y+2cEVFvwqnHb1BSxWW4RhQ2P8kvsu3ACbwOqr57viJKTa7uG+qe1fdufl5rqF2qr jHy5L3HlBpbKr1Vl5EefvCAyn8+oe9n/K+eN0UUCvHZ3OgwtPhyspcNh4yAoE49KOIUkQVp2v0HR9 +xKnn/gm3dSYH0IDK2KkKvdpo4YPQW6CLliHGifFEImfRxrevzUzbI0xJBT7SCfU6e7LIrXsQ1mlT uc0IdyK39Z/Ut2VF+t8tpW9pm9g50y0Q3SwS/URKZyTPqyVYvUikuYgn7PDUb1oSxM38pOnLhiEyt M5/wJdyg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qOHW7-005Tcv-AA; Tue, 25 Jul 2023 12:51:55 +0000 Date: Tue, 25 Jul 2023 13:51:55 +0100 From: Matthew Wilcox To: "Kirill A . Shutemov" Cc: Sean Christopherson , Vlastimil Babka , Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata Subject: Re: [RFC PATCH v11 10/29] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable Message-ID: References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-11-seanjc@google.com> <20230725102403.xywjqlhyqkrzjok6@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230725102403.xywjqlhyqkrzjok6@box.shutemov.name> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 25, 2023 at 01:24:03PM +0300, Kirill A . Shutemov wrote: > On Tue, Jul 18, 2023 at 04:44:53PM -0700, Sean Christopherson wrote: > > diff --git a/mm/compaction.c b/mm/compaction.c > > index dbc9f86b1934..a3d2b132df52 100644 > > --- a/mm/compaction.c > > +++ b/mm/compaction.c > > @@ -1047,6 +1047,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > > if (!mapping && (folio_ref_count(folio) - 1) > folio_mapcount(folio)) > > goto isolate_fail_put; > > > > + /* The mapping truly isn't movable. */ > > + if (mapping && mapping_unmovable(mapping)) > > + goto isolate_fail_put; > > + > > I doubt that it is safe to dereference mapping here. I believe the folio > can be truncated from under us and the mapping freed with the inode. > > The folio has to be locked to dereference mapping safely (given that the > mapping is still tied to the folio). There's even a comment to that effect later on in the function: /* * Only pages without mappings or that have a * ->migrate_folio callback are possible to migrate * without blocking. However, we can be racing with * truncation so it's necessary to lock the page * to stabilise the mapping as truncation holds * the page lock until after the page is removed * from the page cache. */ (that could be reworded to make it clear how dangerous dereferencing ->mapping is without the lock ... and it does need to be changed to say "folio lock" instead of "page lock", so ...) How does this look? /* * Only folios without mappings or that have * a ->migrate_folio callback are possible to * migrate without blocking. However, we can * be racing with truncation, which can free * the mapping. Truncation holds the folio lock * until after the folio is removed from the page * cache so holding it ourselves is sufficient. */