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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 041CEC001DE for ; Fri, 28 Jul 2023 16:03:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 760DD8D0003; Fri, 28 Jul 2023 12:03:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 712308D0001; Fri, 28 Jul 2023 12:03:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D9068D0003; Fri, 28 Jul 2023 12:03:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 50CAD8D0001 for ; Fri, 28 Jul 2023 12:03:57 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 09FC51211BC for ; Fri, 28 Jul 2023 16:03:57 +0000 (UTC) X-FDA: 81061491714.23.63A2488 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf17.hostedemail.com (Postfix) with ESMTP id 9ECC94013B for ; Fri, 28 Jul 2023 16:02:49 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="LuP/9ao2"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PJkmStLE; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690560169; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=CvY0+v4nvg0O0BVEhEc8BmZfYzpPNCFFCMaJmCODeHg=; b=NKjJmr9dv1r+4vxnJNFTlc2BL3qAVrC/wUWTaIc2FgFIWUdSV9NaHyChM1c08HE2Mi++3r T6ON/YeXe46PV3YYJ6sP7ERIlrhkZT+KFq6DSSvfTCCcxoSzLK5nQSpWAsYG593lbWKaUr bO9EZeBsMVfPWFUKLKkE+8DVktBfgew= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="LuP/9ao2"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PJkmStLE; dmarc=none; spf=pass (imf17.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690560169; a=rsa-sha256; cv=none; b=2kwOO9BO9OabCl51avZT6JW9vXrguS92jndzG0Ih3zpo/LJFC5n94rgqLjrzGdqUw9v/kq cCmJdleYNepUDTkL4Xn9Oc49rvBryGwtf7+LOO0pJI4pRnXT6Hx10BFnzmn8ZD1d0GhkGu EvNC0ErexKyQv+rgQ7ByqQbx5YmO0OU= 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 9DB191F854; Fri, 28 Jul 2023 16:02:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1690560167; 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=CvY0+v4nvg0O0BVEhEc8BmZfYzpPNCFFCMaJmCODeHg=; b=LuP/9ao2mrKjhPvKezWW1/W17SEYJs2q92vl0M2JCYXcddXuljTTEbIYow9womJUw6LJrg qzowp5BeJWVnf+lzn5JU5UBXET439G9aZl2Cej4L8DEUkkS2Xabj9scGTntFuX4nFsk5BK jGFVo1NW+KmbJNwVJQIyJlgnQrU5Tm8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1690560167; 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=CvY0+v4nvg0O0BVEhEc8BmZfYzpPNCFFCMaJmCODeHg=; b=PJkmStLEQ4tX3u5n/JqYexTLZ62i3tFelBIXmZgBwUht8ehxcz9TNcF+IDGXx4zqKelWMj 1J0IPH/P9l/ZmiCA== 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 0504113276; Fri, 28 Jul 2023 16:02:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vp1JAKfmw2ReUwAAMHmgww (envelope-from ); Fri, 28 Jul 2023 16:02:47 +0000 Message-ID: <692b09f7-70d9-1119-7fe2-3e7396ec259d@suse.cz> Date: Fri, 28 Jul 2023 18:02:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC PATCH v11 10/29] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable Content-Language: en-US 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> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 9ECC94013B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bj5ohmm4jfucnbq9umdf6hwcquiod1fo X-HE-Tag: 1690560169-858236 X-HE-Meta: U2FsdGVkX18uwd/GRg6WKMrQEEr7wG5l2TXPG/RMOBiT54NNSqAf1RqmiMo9AmHsym1TaISa+NLB7R9ssOH0gP3M/C5s2RTiTU6E0hCyMUjUW4zMyXHMdVlSFLcGptPxQnKUgo15tStOCB4T315iI9IZMirRDaxkzzo4NGTYM+XUPRH2YGiP9CwLpu/88UIjAPhF+pAc9frfSuiFP3FWK0OVxpEkQDgRe9KapTNQ+5yac39jXjuv2aTNHgCb/VWQeIhgWzzpR9+LHqwBDdw1E+YURuIp7ih4mAQzwB/4CF+2Sd4UlfUJHz53GUIvTlQaoswrs5tli+CNScOZu8Xk/gvcAI2JLp8gN4pitWRLGPIpI2bUNkeG14TX4q1ckf6o3amIWbIkE6cHWf2WOy6nrOFLRPUfHltMdQuhhAZj++Hk550KOsHakYUaHAu4VJWbUTMWqkG+ZvQiWg6XXUwK1KOPFLPoLyWyLBvz7Js98Z94NLH7pan9gCKOeeTBvW1Ra/AJ9eYDjBhsdDM9Kqr3gGKudJe6DlmgFXtSJ3EuxKKueIzX1uRfrZkAIsXtCM+ZgLyyVoAMu3xRU2mR3qUzT1edJzYZWe5V4/yiLD6c4LXbOfhnFoj/DrIGxhGocJvkBRSO1qliDZvkqResD7bAogiQLFJyzdAhY+3u36KhsiZ34+5XpBqLBEdO6wVVEWwaE1jqMovoK0dcnK8EO3qri0zphWKfZ/r5mSqzchUJ6XpH8dMV7GqFaMBjd+9UqTmVZCC/iwM3r1FA/XQOPAaQceiLmPt1GPWquSBgNeoh1mNu950SYbZjq3x+Fz+f7/lSkq6BbOMZiob+Iwzf5j+dwU+dd7IPNr/RZzY0yYu6ly63tkM+v4KdOLh5RLfTHSH3jyWgXPHEw34peQBuFYI9Q+uM7AZTmxLLmCnrKpoENaJh4Tf9e9BbMsv9DRA3nEZ4Pn43/KXWHtoESHgEFgj 2LSIBK3T D8klY462Ac3RGWmIPlThV6UjMoY7ixGF/mCwc4GvqxQxPs4na+6i3hcnBldW/ubwUK32k6tuS9rcoMTnIJajowcxCFq0mx+liyySPWDJe6qGUSmBQ0ktIygnGC5hPuzf19IMXfZo+hyLbuvsYIpOIEw6AAL81EYIrPaXG2onfZUa8dFIU2IBlD/+012J+4qKUyQ6Xa1JiT989jKtnk4BKylgXDqkvTW3rNoNsQEeb0pS274F7f3+iiOhosgG4p8d2JfQ++GyT3PPKP1SDUeCK2Oa/t9TKL4ciRqXRhPfg5+KL1TSPHuyB1hZ0H1MxsGqpcjRE 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 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: Hmm, well spotted. But it wouldn't be so great if we now had to lock every inspected page (and not just dirty pages), just to check the AS_ bit. But I wonder if this is leftover from previous versions. Are the guest pages even PageLRU currently? (and should they be, given how they can't be swapped out or anything?) If not, isolate_migratepages_block will skip them anyway. > > /* > * 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. > */ >