From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 F3E444071FC for ; Fri, 10 Jul 2026 10:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783680993; cv=none; b=ZXber2ZFwarkHncUJULmpYu56pYlhbWCz4Xqvqu4wEUNdG8Z3gVCuYbDZXcyXk7wrAB1WwsAi8bi+GkiuDvWa2C+Nq2WdRN4hr3Qky4DJUFUDgvEu7WEOs37dQd1wG880rbW//9ovv98En1MMVo/na6tIs3G8uUu2fMw4mViMiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783680993; c=relaxed/simple; bh=vYqCA5l4YYyso/Zv6g8ueWerNWkYhpLDNjGM/O+OJQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=heiVy5yM3TpGpL0/a2AeuGzpiF+Kmm2cpVTVYGzPJPaObcYQ52eRZTZJB8byEdDZsgKYyHVC3ozACnFLnhmGmzur96WLO5RDIqA/VmPRjU9NKGxhpd/YO8c+csdArPoD38FqqahLrpHhB17IbYuBNz48KtahJHaVAUorQG0SDZc= 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=bmuMWEqB; arc=none smtp.client-ip=95.215.58.172 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="bmuMWEqB" 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=1783680989; 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=wJFhjNRrGWhFd4/UKA3CK1oa3jEQdlfP2tw+6VJV9xw=; b=bmuMWEqByFKDrkHgq9LDQ6o45YZlph9ybTzEW8i06SsYucuVvujsPEGBhDUpbjqtdhsKfL jhwH5WR8sqYPFgztSmKHzp0vKZBjKMZpxrZHRBlZp3njKcJL/ax8+eKpsEOYAEIe0qumbn AFi3rsYxug8QgbCe+Ffc0PToTIGkSeM= 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 v3 1/3] mm/mempolicy: skip non-present PMDs when queueing folios Date: Fri, 10 Jul 2026 03:55:21 -0700 Message-ID: <20260710105557.1987433-2-usama.arif@linux.dev> In-Reply-To: <20260710105557.1987433-1-usama.arif@linux.dev> References: <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 queue_folios_pmd() is called under pmd_trans_huge_lock(), whose pmd_is_huge() check returns true for any non-present, non-none PMD softleaf. Passing such a PMD to pmd_folio() treats the softleaf encoding as a hardware PFN and can return a bogus folio pointer. Mirror queue_folios_pte_range(): handle non-present entries before looking up a folio. Keep migration entries counted as failures, but skip other non-present PMDs such as device-private entries. Potential trigger: an HMM-based GPU driver migrates an anonymous THP folio to device memory via migrate_vma_pages(), leaving a device-private PMD. Userspace then calls mbind(), migrate_pages() or set_mempolicy_home_node() on that range. 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 Acked-by: David Hildenbrand (Arm) Signed-off-by: Usama Arif --- mm/mempolicy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 914f81863db5..69a00a324ef5 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -654,12 +654,14 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk) { struct folio *folio; struct queue_pages *qp = walk->private; + pmd_t pmdval = pmdp_get(pmd); - if (unlikely(pmd_is_migration_entry(*pmd))) { - qp->nr_failed++; + if (unlikely(!pmd_present(pmdval))) { + if (pmd_is_migration_entry(pmdval)) + qp->nr_failed++; return; } - folio = pmd_folio(*pmd); + folio = pmd_folio(pmdval); if (is_huge_zero_folio(folio)) { walk->action = ACTION_CONTINUE; return; -- 2.53.0-Meta