From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB1BA43CEC4 for ; Wed, 8 Jul 2026 12:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783513250; cv=none; b=Cyl8T120xgl9V61tHQD0bJuZQssfzHGRrscwLGUSNmMDfmFYDYIco5SHlETL5hwCO5qYPSVmwTVin+ZJ7LbNrzMZH4cHnCuX537JpS4D0B6ur8iH7oDw0XLw1Ws8y2dnYPyY2bj/khwhn03SAb+mhewcKCu0kCSloh6CzTOH7yI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783513250; c=relaxed/simple; bh=cCQKx578zS9KvatM28ZWL/U0gzDyskcioiX40sno0x8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OGKdm/F7S6MveoZG4a40oCnnCHGOqDxUDl/PQzmPo6LHH1b0jM89ihaCmiGsGdPGWYC4mMU3JWgIDzZBIMmBVW1zHPVPGgjMaziXz0mOIAaBwfv30e4EZ29IDOzkQ2fX80e1jsZtaxMDheIekd/MigfMqWwZLXUbEyZKkuHy24g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=MoRVEU5I; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="MoRVEU5I" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783513246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=JE2eto0rTcmGeQDmN1z5HNPDhBhNNJkb6xZo9UCW1u4=; b=MoRVEU5IKS3apV7HlZfdXtZ/WUvo7E4qL1LcnrjycfrSCQlpQGlanolDS8Xv436G4Vr+sF hJI9Mgkj5/Sl/AkpURRpVaD2lS5PFDaMf+ZmumQWuy3DC+OSjIVKwxZUKkK0Fq1LSQkayo TBEUrAKEq2AG+v6GX/ra2MBKIbl1UDY= From: Usama Arif To: Andrew Morton , apopple@nvidia.com, balbirs@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, byungchul@sk.com, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, jannh@google.com, joshua.hahnjy@gmail.com, lance.yang@linux.dev, liam@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, matthew.brost@intel.com, npache@redhat.com, rakie.kim@sk.com, ryan.roberts@arm.com, usama.arif@linux.dev, vbabka@kernel.org, ying.huang@linux.alibaba.com, ziy@nvidia.com, shakeel.butt@linux.dev, hannes@cmpxchg.org Subject: [PATCH v2 0/3] mm: handle device-private PMDs in walk callbacks Date: Wed, 8 Jul 2026 05:20:06 -0700 Message-ID: <20260708122040.861335-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT I have followed Joshua's suggestion in [1] for v2. The patches look different but acheive the same goal, so I have kept the Reviewed-by tags from v1. Joshua, Zi and Balbir please let me know if this wasn't ok! Since commit 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations") a PMD may hold a device-private swap entry whenever an HMM-based GPU driver migrates an anonymous THP folio to device memory via migrate_vma_pages(). pmd_trans_huge_lock() succeeds for such PMDs (pmd_is_huge() returns true for any non-present, non-none huge PMD), so several MM walk callbacks that used to assume present THP or migration entry are now reachable with a device-private PMD. The results range from a VM_BUG_ON() firing on debug kernels, to an oops on a bogus vmemmap dereference, to silently isolating an unrelated live folio from LRU in the aliasing case. [1] https://lore.kernel.org/all/20260707191917.3213033-1-joshua.hahnjy@gmail.com/ v1 -> v2: https://lore.kernel.org/all/20260707135255.292870-1-usama.arif@linux.dev/ - Patch 1 now gates queue_folios_pmd() on !pmd_present() instead of checking only pmd_is_device_private_entry(). This matches the PTE path, keeps migration entries counted in qp->nr_failed, and skips other non-present PMDs such as device-private entries before calling pmd_folio(). (Joshua) - Patches 2 and 3 now fold device-private PMD handling into the existing !pmd_present() VM_BUG_ON() condition instead of using a separate early pmd_is_device_private_entry() check. (Joshua) - cc stable (Zi) Usama Arif (3): mm/mempolicy: skip non-present PMDs when queueing folios mm/madvise: skip device-private PMDs in cold and pageout walks mm/huge_memory: skip device-private PMDs in madvise_free_huge_pmd mm/huge_memory.c | 3 ++- mm/madvise.c | 3 ++- mm/mempolicy.c | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) -- 2.53.0-Meta