From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 A4C2E403B10 for ; Fri, 10 Jul 2026 10:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783680977; cv=none; b=tjNAyDopl2z9ozjBNgq4TaWdKjunWbvWb2UQLdoRKqSvJny3p1QtfeVBGhjvUDUegyaMhtx3ZvgO3sdUI29yPipo27iPR1BhKEeIyNsKritMwu0fjgjrwu3V2uIK2oJXgSi81jROL9hBeLkdAGReEr/1u9bOSTJTD50y1Yg4Eqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783680977; c=relaxed/simple; bh=1tffDtKfYzhzXnNGM0VQk/14O57tOr8UYvK500VoH0M=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JuS/QrmKJOCW2cVrJcmJ7+dHVzbg1yXYjU3W/TuuAs2s4ShpcWYYWd3CwoB/nY6RL2KAbhgjLwPnEWru0wkk0tTRmny3ut3zdHVEDS4SvsNjW3VuP178VcXOavb5FRWfDB2KtMrdU1DWMIH6lRXK2+WGztoLFRhkDWvT9hVPIFo= 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=GMDNp7E4; arc=none smtp.client-ip=95.215.58.182 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="GMDNp7E4" 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=1783680972; 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=eWvY20kWHieMA6+11z4cDiGGKYfy8NYj5myuJ6b5p2M=; b=GMDNp7E4For+Kybdkgwx08aUh3OFHXLN7F7uo2eMp8sQI0HY817TzzzxUfUxtIkan7NZaC b6tmXAsO40mSRDdaJiT/lkt/q4MMFlzbMM+BfX6q2rorPXm4h2lr+cVYPD+M+C6/CKLuAA SlJ8tfq0tyi3i5rvUTIPIOKgbwGaRVg= 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 v3 0/3] mm: handle device-private PMDs in walk callbacks Date: Fri, 10 Jul 2026 03:55:20 -0700 Message-ID: <20260710105557.1987433-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 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. --- v2 -> v3: https://lore.kernel.org/all/20260708122040.861335-1-usama.arif@linux.dev/ - Patch 1: use pmdp_get() instead of *pmd. (Zi) - Patches 2 and 3: drop the thp_migration_supported() guard and downgrade VM_BUG_ON to VM_WARN_ON_ONCE(). thp_migration_supported() expands to IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_SOFTLEAF), and both pmd_is_migration_entry() and pmd_is_device_private_entry() already return false without that config, so the guard suppresses only the case where the warning would already be silent. (David) 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 | 4 ++-- mm/madvise.c | 4 ++-- mm/mempolicy.c | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) -- 2.53.0-Meta