From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 74D0F42EEA0 for ; Wed, 8 Jul 2026 10:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783508109; cv=none; b=nPJzhgFLquDACIKgeDAscyotQwYXA5VRGwr83gBAB+iF750hfoQVvrlRHhURD2EjRPpKHb0/yctxK0ggguYkN/xMVmKDdoWaqV3ae+aOHiiovRWmDatc3P9JOUvaFJzoWpxA3WDVvg0f5iuG1alCQ2Tf8AA68hS3Y8x0i8I4pzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783508109; c=relaxed/simple; bh=4Y7rXKVaB4C1tkswEZlL30pSx2GjJJjUIR4rjoi4jgI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=e1iWoCMFu7ymxgZ0z9tYSh5c1LVTno9Q0kLbUOtHGKQ61IXGavHpqosbVL+A67ppu2QVoDWs7gdj68IXs/6WF133O0uqbgM19IvVESFAfmLNhXq1CoA/Qr5W8vB5bHrHwDTlPEf9s/TIqxnC7mV+Lt+AqIyzrVipo3Q9njqweMc= 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=hBGjxBIV; arc=none smtp.client-ip=91.218.175.170 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="hBGjxBIV" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783508093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JveTwJK57T6ULV8wGRHvMbz3OkN7QKv1Z6kFde8Y6dM=; b=hBGjxBIVkNpmPteQ8+ZqbJNVdiWpgtg4nqsV4oWOHTykXOkHpkIIOo89EalcDLIojQXOwF E/q2qOpZ1JsgypIzRkzEmZXKiFaSHjo7CLkcDBm5iAWJwogxzMZdQgKDxnxJ3lJByGFG8M AGsZlm6myQAIz2USBc+SzY1KiZUPC0U= Date: Wed, 8 Jul 2026 11:54:44 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/3] mm/mempolicy: skip device-private PMDs when queueing folios To: Zi Yan , 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, vbabka@kernel.org, ying.huang@linux.alibaba.com, shakeel.butt@linux.dev, hannes@cmpxchg.org Cc: sashiko-bot References: <20260707135255.292870-1-usama.arif@linux.dev> <20260707135255.292870-2-usama.arif@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 07/07/2026 21:33, Zi Yan wrote: > On Tue Jul 7, 2026 at 9:45 AM EDT, Usama Arif wrote: >> 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; > > Should it also increase qp->nr_failed like pmd migration entry above? > It also applies to your "if (unlikely(pmd_is_swap_entry(*pmd)))" in the > PMD-level swap patchset. The PTE path only increments nr_failed for migration entries, other non-present entries, including device-private and swap, are skipped. I kept things aligned with the PTE path. > In addition, since pmd_is_huge() returns true for all non-present > non-none pmds, other softleaf entries should also be excluded here? Oh, > because there is no PMD level hwpoison or pmd marker. > I think what Joshua recommended in [1] makes sense, I will change the PMD code to gate on !pmd_present() instead. That keeps migration entry accounting, skips device-private now, and will also avoid calling pmd_folio() on any future non-present PMD softleaf such as PMD swap. [1] https://lore.kernel.org/all/20260707191917.3213033-1-joshua.hahnjy@gmail.com/