Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp699903rdb; Sun, 3 Sep 2023 06:47:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmB07Yx/mYkzQfejiB4q++CA3EudXj0GUTFy8CdQzXhCk5qaSXLdH0FkjrjUfhZqNnprp1 X-Received: by 2002:a17:907:a04f:b0:9a5:d48f:c906 with SMTP id gz15-20020a170907a04f00b009a5d48fc906mr5111660ejc.15.1693748835118; Sun, 03 Sep 2023 06:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693748835; cv=none; d=google.com; s=arc-20160816; b=KNexesWzZV/VfgMUOElDJPP/uDAEZ1LdZBtZPkjOfX2iB2X8TSnUPRkNBHMOOYS/Nw /kjXJccf7epV/58r8BuyPYqCwfU35IEaVG6BLOEoEJ1xwQGQNcFvFafZuUZap2xovcz0 tdDqbM7SgBudX3Ac8DPMXoNRUhcCPAWQufiwISBup8G2uwcwL79Ya+D9ItdH6B5ZRPBK pQNeinExjq7jPU8TOHahzCgkcb7rUa9lV24d/y04w51RxMZJ22+govAZ1raRL8HVlZyb 2paRK0ikTHFNwHUf9MfIXUPiOzfHRqOfypTHPWyNGYlLWNexRh4d8H4amdJ1BooD6Pyr 9sGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=lM2jFMiCbU/7Z0Wt66YsVsUtlY4aIj0FUbivaBixA/c=; fh=cbtEgQXrHHN7FBURJ4dLQroZWS7iMpewbS0vpOd+8CE=; b=bw7MfCDBqbv5hE/KvQgE62oh4O/S6ZrXTyt56PthoL5wvMHUxaZ3jcqK/yA7XCc/vR hHhDT0i2yK2R//naB1iUofj76UwVirVzVHzEVhnbOzqWoK2t1YVWOoqIiL/oCR6vF+do aNcf+I2GrKG/9SVAKBncN2EQcG/hDwDGEpb+4KxIKJm6MCxpDzTltW3ZH0Iw1HkmVq4T 724R0+3jyMPRWlRwU5pzGCIlnTqgz7usO6KjFaFxY9YaTuy+DN6ZsuoeL+vui+kOhMLV xQzJ0nCf2ftHfZbK0mpnE9EDL35dxWzE53Jd3ufyNprZusiaIjVE2e0BD/eoN2TGyJ+8 BggA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=zT4zGINV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=ZsrMXAmA; 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 n13-20020a170906840d00b00992ad2f72fesi5100785ejx.537.2023.09.03.06.46.33; Sun, 03 Sep 2023 06:47:15 -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=@suse.cz header.s=susede2_rsa header.b=zT4zGINV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=ZsrMXAmA; 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 S1344816AbjIAIXd (ORCPT + 99 others); Fri, 1 Sep 2023 04:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236869AbjIAIXc (ORCPT ); Fri, 1 Sep 2023 04:23:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C86D193; Fri, 1 Sep 2023 01:23:26 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CBCAF1F45E; Fri, 1 Sep 2023 08:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1693556604; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lM2jFMiCbU/7Z0Wt66YsVsUtlY4aIj0FUbivaBixA/c=; b=zT4zGINVx2k3wPqz3jcmE9bmJBpBcsDBUwenKzhLerIp+oH2aCkG4+EXh39zRNryjQv5Db syu8c53NOsHAVW9SIMV7rmXaawFxBmlGIS7oN+eGtRpy7NQAkXpdI57c9wkvRp8eiDiXja uA4epJ/r7clJCygmuQc278PsV8l56iM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1693556604; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lM2jFMiCbU/7Z0Wt66YsVsUtlY4aIj0FUbivaBixA/c=; b=ZsrMXAmASwR20bAW12DsiBEXD871qEuKP0anx4duKH2O41WOTWfcG8WLKUJiaYTSgmrfs1 lQlapOLm5eLYniDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3A66A1358B; Fri, 1 Sep 2023 08:23:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BOk4DXyf8WREHQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 08:23:24 +0000 Message-ID: <2d9312bf-a5ad-0427-c197-fef6ea5cfe0a@suse.cz> Date: Fri, 1 Sep 2023 10:23:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [RFC PATCH v11 10/29] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable To: Matthew Wilcox , "Kirill A . Shutemov" Cc: Sean Christopherson , 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 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-11-seanjc@google.com> <20230725102403.xywjqlhyqkrzjok6@box.shutemov.name> Content-Language: en-US From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL 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 7/25/23 14:51, Matthew Wilcox wrote: > 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. > */ Incorporated to my attempt at a fix (posted separately per the requested process): https://lore.kernel.org/all/20230901082025.20548-2-vbabka@suse.cz/