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 C14F4422553 for ; Tue, 7 Jul 2026 13:53:17 +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=1783432399; cv=none; b=u1eayI7WJI1QfWu+Tdkhr/84VEdW6UBosqz3cmJSuXEKKtVWa2HwPvm9yhThv0u8k1uSBd9KQ63BMw42vjktyiTfmTHUVNlkuwY+3hDHFKY8dGQQd7c3G3eXnrgoYgF1HOmSloy/BGfkiDLzwTXvkf/5LvFWdr9ILF/bmpshloA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783432399; c=relaxed/simple; bh=ec/75jqfkr2Fd3szbSgtLe4I1+9ovTr1IlEYnB0GCy4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BpDm15cZYraqNPHbrx30M7CCEOq5hjUbGCDJ3Vius0rG0VAHIxdUqdc4rrtLL7FeLoRpRe9ufTjHm9FE773qiM+cl7e2VQpBnGfgYUevutYovzo+4vEK5XuFA9ix95l8o/85ZoZVRpydnPhvHlo/JfqOAGAeZjmOTe3qnVPOdDw= 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=to19MXZH; 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="to19MXZH" 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=1783432395; 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=TW//luzf+xXNmQVXXXLPR3JvmqQnE7kuTImybvRM7t8=; b=to19MXZH26e0lK1SUKTTJ/uF1uv1irzloYSgrhIXP/h2zaO7qKu2jEVZLEoqktGXDOHIoZ x174qMBX0FMFqTcolmCaR8/rwB/PPZLUa+BDIgxnwPmTuoCDzPQJWjqfJRX8ZBAUw69q/f CFrb4qGIIK3QWlv6sEGALnyP+ghvVcQ= From: Usama Arif To: Andrew Morton , apopple@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 Subject: [PATCH 1/3] mm/mempolicy: skip device-private PMDs when queueing folios Date: Tue, 7 Jul 2026 06:45:07 -0700 Message-ID: <20260707135255.292870-2-usama.arif@linux.dev> In-Reply-To: <20260707135255.292870-1-usama.arif@linux.dev> References: <20260707135255.292870-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 huge PMD - including a device-private swap entry. Passing such a PMD to pmd_folio() extracts garbage bits as a PFN and returns a bogus folio pointer. 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. Skip device-private PMDs, matching how queue_folios_pte_range() skips device-private PTE entries by checking !pte_present(). 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") Signed-off-by: Usama Arif --- mm/mempolicy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 914f81863db5..eda817539c77 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -659,6 +659,8 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk) qp->nr_failed++; return; } + if (unlikely(pmd_is_device_private_entry(*pmd))) + return; folio = pmd_folio(*pmd); if (is_huge_zero_folio(folio)) { walk->action = ACTION_CONTINUE; -- 2.53.0-Meta