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 360C3C0219E for ; Mon, 10 Feb 2025 23:05:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90CAC280008; Mon, 10 Feb 2025 18:05:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BCF6280001; Mon, 10 Feb 2025 18:05:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75DE1280008; Mon, 10 Feb 2025 18:05:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4A170280001 for ; Mon, 10 Feb 2025 18:05:21 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CF77E80738 for ; Mon, 10 Feb 2025 23:05:20 +0000 (UTC) X-FDA: 83105568000.23.4497A8A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id A6B3C140009 for ; Mon, 10 Feb 2025 23:05:18 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=ywk5yFm7; dmarc=none; spf=pass (imf09.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739228718; a=rsa-sha256; cv=none; b=8j3VDVUiz970LpdFp+5IMB8iOIKplmKJort/BIenvDjj54pLYeuL9N4kieryaO1oXP0YHD 2kGMAJTY2O2oVU0mJwjfBlpufwJaMQtDeXbjLtuC0OFoyV9XTsNCzQ2hA9WOGm5GaHoHWH jIe5qqUoHdg3uY+TQ3qfIOAfe11E5ZM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=ywk5yFm7; dmarc=none; spf=pass (imf09.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739228718; 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=4F8WsnIYsa/SeTPP4n2Hm7LeQ+y6kuAkR8c+zeaznxg=; b=3+BQ7F40sJrE5yIag9STEFBo47OAt9sSKEmb/pIuGITLj5gumDCbff0pVUVQZLh1yDDhSz fE/HD00feNjTCuRk3kfxG4wN2V6xjXMMuPsdxy6p9a1rIBDxgVy+LBxbtmVfCPp+tKonuV K3u8SnzVG8xxTlNJLBfftmwH3fHDeFY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B134B5C54A5; Mon, 10 Feb 2025 23:04:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDB13C4CED1; Mon, 10 Feb 2025 23:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1739228717; bh=a+20u3F0olFhn2ger6QyJLQ5lx1Ke3LUoxDGzvt6t8E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ywk5yFm7ctuCPKJQ9+BCPXUz/RzUhWb19Ww4mTtphZcClJDthieFzci4pzmtFsB2I Yp0xaownlpeRYsr5jbwGmNoxuPqSzXm8ItDVb71qJ3LuODj6XFApcFUVl6eL6hlFDA RkQ1jhvczfJ6AIkjUhJS3bVUC+B1AyLXWs+uA/LA= Date: Mon, 10 Feb 2025 15:05:15 -0800 From: Andrew Morton To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, damon@lists.linux.dev, =?ISO-8859-1?Q?J?= =?ISO-8859-1?Q?=E9r=F4me?= Glisse , Jonathan Corbet , Alex Shi , Yanteng Si , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , SeongJae Park , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pasha Tatashin , Peter Xu , Alistair Popple , Jason Gunthorpe , Barry Song Subject: Re: [PATCH v2 00/17] mm: fixes for device-exclusive entries (hmm) Message-Id: <20250210150515.c71078f212ff4661eafc15bf@linux-foundation.org> In-Reply-To: <20250210193801.781278-1-david@redhat.com> References: <20250210193801.781278-1-david@redhat.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: A6B3C140009 X-Rspamd-Server: rspam12 X-Stat-Signature: mywcpti1hmcbdm8iff6ca658qk9bupwr X-HE-Tag: 1739228718-475351 X-HE-Meta: U2FsdGVkX1/w2qHugSL68vH7GxnNV6j6YocHAo9Wm2a+EKTd1D0c4ZzrnRo+QoUQqgOl7/6vu7eHIZnikz9rPuMdBGRBS1BBMZE2JA2HiWV3unPpyooxZe1K6qbtMVdrc5h1Lteu79pgEDGtfY2SxZf2KL2oUGwNe4b96oohoEHvMYd+AHgtcdun0wPM4jvB0FxbLnJVnhnw0c0fmJTU/CCeMS0ysmhgNi920hXpOIlp66Qgiq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ogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, 10 Feb 2025 20:37:42 +0100 David Hildenbrand wrote: > Against mm-hotfixes-stable for now. > > Discussing the PageTail() call in make_device_exclusive_range() with > Willy, I recently discovered [1] that device-exclusive handling does > not properly work with THP, making the hmm-tests selftests fail if THPs > are enabled on the system. > > Looking into more details, I found that hugetlb is not properly fenced, > and I realized that something that was bugging me for longer -- how > device-exclusive entries interact with mapcounts -- completely breaks > migration/swapout/split/hwpoison handling of these folios while they have > device-exclusive PTEs. > > The program below can be used to allocate 1 GiB worth of pages and > making them device-exclusive on a kernel with CONFIG_TEST_HMM. > > Once they are device-exclusive, these folios cannot get swapped out > (proc$pid/smaps_rollup will always indicate 1 GiB RSS no matter how > much one forces memory reclaim), and when having a memory block onlined > to ZONE_MOVABLE, trying to offline it will loop forever and complain about > failed migration of a page that should be movable. > > # echo offline > /sys/devices/system/memory/memory136/state > # echo online_movable > /sys/devices/system/memory/memory136/state > # ./hmm-swap & > ... wait until everything is device-exclusive > # echo offline > /sys/devices/system/memory/memory136/state > [ 285.193431][T14882] page: refcount:2 mapcount:0 mapping:0000000000000000 > index:0x7f20671f7 pfn:0x442b6a > [ 285.196618][T14882] memcg:ffff888179298000 > [ 285.198085][T14882] anon flags: 0x5fff0000002091c(referenced|uptodate| > dirty|active|owner_2|swapbacked|node=1|zone=3|lastcpupid=0x7ff) > [ 285.201734][T14882] raw: ... > [ 285.204464][T14882] raw: ... > [ 285.207196][T14882] page dumped because: migration failure > [ 285.209072][T14882] page_owner tracks the page as allocated > [ 285.210915][T14882] page last allocated via order 0, migratetype > Movable, gfp_mask 0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO), > id 14926, tgid 14926 (hmm-swap), ts 254506295376, free_ts 227402023774 > [ 285.216765][T14882] post_alloc_hook+0x197/0x1b0 > [ 285.218874][T14882] get_page_from_freelist+0x76e/0x3280 > [ 285.220864][T14882] __alloc_frozen_pages_noprof+0x38e/0x2740 > [ 285.223302][T14882] alloc_pages_mpol+0x1fc/0x540 > [ 285.225130][T14882] folio_alloc_mpol_noprof+0x36/0x340 > [ 285.227222][T14882] vma_alloc_folio_noprof+0xee/0x1a0 > [ 285.229074][T14882] __handle_mm_fault+0x2b38/0x56a0 > [ 285.230822][T14882] handle_mm_fault+0x368/0x9f0 > ... > > This series fixes all issues I found so far. Cool. Barry, could you please redo your series "mm: batched unmap lazyfree large folios during reclamation" on top of this (on top of mm-unstable, ideally).