From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 7E177420E79 for ; Tue, 7 Jul 2026 13:53:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783432407; cv=none; b=DazDEae8Yyo6spnaZxSYKPA+xpoFnbu9nCeXFleVYwlFSbOhIV/8mMKS2jkt/kjx8ixZG6Jc25qYJKntxqcQjBKOjmVObP2BfBpdnTKR8v3b2hY/qwUycGxm9TrOCm3nxhA+Hb068I+stAghTKqkjNx3NpW5DW/Yrz5DYsub2mo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783432407; c=relaxed/simple; bh=u9wrXQB7GOFx0E5BBxOuAdCOef1NFwP0eAAmnY34TgY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=geDfBBcqyUvf8Nddc1ONYry+Ko9g9W93enu9PlR1I/SgZlg9VN4f+fUEGOV3rarPP6ZHIT3i1siBjW4cshZu9ZOm+qU8IQJjh/U+SaUvOqaSImIXsiJTfUsPAYtRkJxcdWr9tBogIIvsHI12eMdYTG1yeev/s0C5bYs6KhFpzG4= 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=bYkSyVJT; arc=none smtp.client-ip=95.215.58.188 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="bYkSyVJT" 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=1783432403; 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=ZNieEZShBstUzDyBdKEZjg40ErjOe3pCONmkHz2f2NU=; b=bYkSyVJTtzsRN0UiAcHbt/cyKKroaVboVIWR3bg/YXaqXEkK2FTX+ZAGB6DDLW+Wby0YNr ggDdrVmcF2HoNHs60oL7e3lzWqxQCoKfPHvJKBQdOsJCUd9GWUHo1/amQmGExaFWDnYwce 2z424wczcPb+6ghfs4nVRGIeNg61Wf8= 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 2/3] mm/madvise: skip device-private PMDs in cold and pageout walks Date: Tue, 7 Jul 2026 06:45:08 -0700 Message-ID: <20260707135255.292870-3-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 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. 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. Skip device-private PMDs after taking the lock, before the !pmd_present() check. 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/madvise.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 9292f60b19aa..870be398c6f3 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -384,6 +384,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, return 0; orig_pmd = *pmd; + if (pmd_is_device_private_entry(orig_pmd)) + goto huge_unlock; + if (is_huge_zero_pmd(orig_pmd)) goto huge_unlock; -- 2.53.0-Meta