From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 5BF114248C0 for ; Wed, 5 Aug 2026 19:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785958557; cv=none; b=CZZ0K7Ekn5Rwh4IvjrZA7np81pMfA3ND3O0I3aGrtw+taa9xDGP9v9l3nGNQhXhSDqwBBsKDh+3qoMMSjJpi/25l9tJg6IBKwJTfCPhgn0VZI+ZhY7+oyBJfpqd/d4ggVCzuWGp6hYHPYTdNCVYOip0Lo/FcKZWeoNJtC3UyBOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785958557; c=relaxed/simple; bh=QYVG22Ril2YRFp2fcAJ/FBSXr0ANtT+bhitFTakpD74=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XBwonBO98aljjmi9znkqMoj4gunPCib0JTbvwpeiB5Vn5EOyOeqLspbc+43uJMj5cF6VyiqNpYrq9/q5Cux6gk/mpOaBE9ruS/I6LhUPjeeWNnHrIJM+CpEj2ZoJ/7jmsndohKluQbvGlAq0EYpW9Suzf9faqqea+hSTWkxCQ9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UrNPm7wa; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UrNPm7wa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785958547; x=1817494547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QYVG22Ril2YRFp2fcAJ/FBSXr0ANtT+bhitFTakpD74=; b=UrNPm7wa+ReTWzY0x1XjnJhlhjELjNpc2AY8WAGjyDlv0CEpNXvgbZOA 6q7TU4bzhjxHlBRjOHoN3vRVxqvcHN0pv2uDazuP/Dr4iBF9bRezGy0Fq vfI+iddk1unHywr45cWU5jGlXEBH6GnT7E6+QAUBmvndJ21TxvBEbAy6A +vg3deWGUs8R9QX0/UmyZrbVEl6CyAD6dS+jTCXoSV6Rg8FFcqzcZZe5K QYstMHDOW3piwVp6J4AnFZIYQdZ39IwUly+IgZkzo0BpxsOwOwe5C5C7L 9E3lo6U/6o6qXlq7Kpx9jnXHRRPiPFJd6x2aXTMZ4FIdOdd/9VXk89RHb w==; X-CSE-ConnectionGUID: fHhO9HYPSDiBO+Q9GkYcwg== X-CSE-MsgGUID: KUkSSfb+QvabhhC//nbFog== X-IronPort-AV: E=McAfee;i="6800,10657,11866"; a="109332985" X-IronPort-AV: E=Sophos;i="6.25,207,1779174000"; d="scan'208";a="109332985" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2026 12:35:45 -0700 X-CSE-ConnectionGUID: /fGuctSQS9q21fF+FOoZZg== X-CSE-MsgGUID: 9KQEbQ3VSVe6d7wvAWHz2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,207,1779174000"; d="scan'208";a="285263536" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2026 12:35:44 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Balbir Singh , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Francois Dugast Subject: [PATCH v2 5/5] drm/pagemap: Add fault injection for higher-order RAM folio allocation Date: Wed, 5 Aug 2026 12:35:36 -0700 Message-Id: <20260805193536.3756457-6-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260805193536.3756457-1-matthew.brost@intel.com> References: <20260805193536.3756457-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrating a device-private THP back to system memory has two distinct paths in __migrate_device_pages(): the fast path where both source and destination carry MIGRATE_PFN_COMPOUND, and the fallback path where the destination could only be satisfied with order-0 folios and the source THP therefore has to be split via migrate_vma_split_unmapped_folio(). The fallback path only triggers under genuine memory pressure, which makes it both rare and awkward to reproduce, yet it is the path where the interesting refcounting happens (the CPU fault holds an extra reference on the device folio taken by do_huge_pmd_device_private()). Add a fault_attr, modelled on backup_fault_inject in ttm_pool.c, that forces the higher-order allocation in drm_pagemap_migrate_populate_ram_pfn() to fail so the existing order-0 fallback is taken deterministically. The attribute is exposed at /sys/kernel/debug/drm_pagemap_fault_inject and requires CONFIG_FAULT_INJECTION_DEBUG_FS. With CONFIG_FAULT_INJECTION disabled the helper compiles out to a constant false and the injection has no cost. Cc: Andrew Morton Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Zi Yan Cc: Baolin Wang Cc: Liam R. Howlett Cc: Nico Pache Cc: Ryan Roberts Cc: Dev Jain Cc: Barry Song Cc: Lance Yang Cc: Usama Arif Cc: Joshua Hahn Cc: Rakie Kim Cc: Byungchul Park Cc: Gregory Price Cc: Ying Huang Cc: Alistair Popple Cc: Balbir Singh Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Simona Vetter Cc: Thomas Hellström Cc: Francois Dugast Cc: dri-devel@lists.freedesktop.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Assisted-by: GitHub_Copilot:claude-opus-5 Signed-off-by: Matthew Brost --- drivers/gpu/drm/drm_pagemap.c | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c index 05eb7254028f..01c639da767c 100644 --- a/drivers/gpu/drm/drm_pagemap.c +++ b/drivers/gpu/drm/drm_pagemap.c @@ -3,6 +3,7 @@ * Copyright © 2024-2025 Intel Corporation */ +#include #include #include #include @@ -12,6 +13,27 @@ #include #include +#ifdef CONFIG_FAULT_INJECTION +#include +static DECLARE_FAULT_ATTR(migrate_to_ram_fault_inject); + +/* + * Force a higher-order destination folio allocation to fail in + * drm_pagemap_migrate_populate_ram_pfn(), exercising the order-0 fallback + * (and, in turn, the THP split path in __migrate_device_pages()) without + * having to drive the system into actual memory pressure. + */ +static bool drm_pagemap_fault_inject_folio(void) +{ + return should_fail(&migrate_to_ram_fault_inject, 1); +} +#else +static bool drm_pagemap_fault_inject_folio(void) +{ + return false; +} +#endif + /** * DOC: Overview * @@ -960,7 +982,9 @@ static int drm_pagemap_migrate_populate_ram_pfn(struct vm_area_struct *vas, if (order) gfp |= __GFP_NOWARN; - if (vas) + if (order && drm_pagemap_fault_inject_folio()) + folio = NULL; + else if (vas) folio = vma_alloc_folio(gfp, order, vas, addr); else folio = folio_alloc(gfp, order); @@ -1554,6 +1578,16 @@ void drm_pagemap_destroy(struct drm_pagemap *dpagemap, bool is_atomic_or_reclaim kfree(dpagemap); } +static int __init drm_pagemap_module_init(void) +{ +#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_FAULT_INJECTION) + fault_create_debugfs_attr("drm_pagemap_fault_inject", NULL, + &migrate_to_ram_fault_inject); +#endif + return 0; +} +module_init(drm_pagemap_module_init); + static void drm_pagemap_exit(void) { flush_work(&drm_pagemap_work); -- 2.34.1