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 016A743B6E1 for ; Wed, 8 Jul 2026 12:20:59 +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=1783513261; cv=none; b=hRvJuMwJ+MWaprX8HhlypmyvWSCb4m+EE4GcYhguDvbBQ4JQgUrO5RoTK1DLV0z1dXGTs1HVREj/qQwz0s/cCqKvCUA472kmGZMh2/7+z4BplSzz0dn/6Hkndo4EOVh1+cNyyjTXK9Tx1Q3fD+/4PdWgTKGjV3YbXaVq48XeGgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783513261; c=relaxed/simple; bh=hcfXO1FwHvS4lII212fe7K/4042LkzgU7vpSSEXp+Dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MPIbtAlGuMVLu7GBqESypL2UJ8NPbLlj0FARLAiMU7/S8EpvzgSspHTo7QhA4FMFHwbuIkLJY3h7vuU+iwxDtnI46wvQBTWhC1X4bBqLOc7SpIpSnfsvTVOwl6fZIX4xIGk/f8cALI94HDKMxBYUnPMQFM2MucPc1+L996z2ZOU= 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=CtaObjrd; 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="CtaObjrd" 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=1783513257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Fn1VOZHGCiDZaYCm98LuGj7iddLxiK8xDaGMUh3nqA=; b=CtaObjrdR977XBk5Te7aEsP20O9ZZ1icNmNajWdyd2wpUY/OdU9o0CqFpIc2L3g1OKXtBF o5Vy+Rv/QkfN+NdURZyX6kVlf1nGAIIzF4AmBh24KQVSICX6gerC569Cb0Etg4f3HmitjY +rF24lBH4avmkC6JF2hd2DODvXvECAc= 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 Cc: sashiko-bot , stable@vger.kernel.org Subject: [PATCH v2 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Date: Wed, 8 Jul 2026 05:20:08 -0700 Message-ID: <20260708122040.861335-3-usama.arif@linux.dev> In-Reply-To: <20260708122040.861335-1-usama.arif@linux.dev> References: <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 madvise_cold_or_pageout_pte_range() takes pmd_trans_huge_lock(), whose pmd_is_huge() check returns true for a device-private PMD. The subsequent !pmd_present() branch has a VM_BUG_ON() asserting migration is the only allowed non-present case; a device-private PMD trips it. Allow device-private PMDs in that non-present assertion and continue to huge_unlock before calling pmd_folio(). This keeps the assertion for unexpected PMD softleafs while skipping device-private PMDs like other non-present PMDs in this path. Potential trigger: an HMM-based GPU driver races with madvise(MADV_COLD)/MADV_PAGEOUT: pmd_trans_huge(*pmd) reads true, then migrate_vma_pages() flips the PMD to a device-private entry before the PMD lock is acquired. Reported-by: sashiko-bot Link: https://sashiko.dev/#/patchset/20260703173903.3789516-1-usama.arif%40linux.dev?part=6 Fixes: 368076f52ebe ("mm/huge_memory: add device-private THP support to PMD operations") Cc: Reviewed-by: Joshua Hahn Reviewed-by: Zi Yan Reviewed-by: Balbir Singh Signed-off-by: Usama Arif --- mm/madvise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/madvise.c b/mm/madvise.c index 9292f60b19aa..1065b5a84ea7 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -389,7 +389,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (unlikely(!pmd_present(orig_pmd))) { VM_BUG_ON(thp_migration_supported() && - !pmd_is_migration_entry(orig_pmd)); + !pmd_is_migration_entry(orig_pmd) && + !pmd_is_device_private_entry(orig_pmd)); goto huge_unlock; } -- 2.53.0-Meta