Compare

bd22f7e63509fa758cf500d9af3e88a3d3df96be..448e76cbdc6652ccd3ba337b7a6e1f028859f2ed

drm/xe: skip eviction of a BO with no resource

xe_evict_flags() switches on tbo->resource->mem_type to choose an
eviction placement. An xe BO can reach eviction with no ttm.resource,
e.g. an imported dma-buf BO whose resource was freed during teardown
while its attachment is still live: the exporter then invalidates it via
xe_dma_buf_move_notify() -> xe_bo_evict(), and the switch dereferences a
NULL resource and faults.

A BO with no resource has nothing placed or mapped, so there is nothing
to evict. Return an empty placement (num_placement = 0), mirroring the
handling already used for non-xe scatter-gather BOs just above;
ttm_bo_validate() then takes the pipeline-gutting path and returns 0.

Without the fix the xe_dma_buf@xe_test_dmabuf_move_notify_no_resource
dynamic live selftest will fail with below stack.

BUG: kernel NULL pointer dereference, address: 0000000000000010
RIP: 0010:xe_evict_flags+0xf4/0x140 [xe]
Call Trace:
 <TASK>
 xe_bo_evict+0x40/0xa0 [xe]
 ? ttm_bo_pipeline_gutting+0x71/0x180 [ttm]
 xe_test_dmabuf_move_notify_no_resource+0x182/0x440 [xe]
 xe_dma_buf_kunit+0x387/0x580 [xe]

v2: Add Fixes tag and failure info in commit text (Matt Brost)

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Assisted-by: GitHub-Copilot:claude-opus-4.8
Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Reviewed-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
Link: https://patch.msgid.link/20261012215014.1495677-5-niranjana.vishwanathapura@intel.com
(cherry picked from commit dbcfaac6331f1fcb0c2fe3ad3e9adb1e5d43ec0c)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com> · 2026-10-12 21:50 UTC · committed by Rodrigo Vivi

Browse files
4 files changed, +15 −16
modified drivers/gpio/gpio-nct6694.c
@@ -444,7 +444,7 @@ static int nct6694_gpio_probe(struct platform_device *pdev)
444 444 data->gpio.set_config = nct6694_set_config;
445 445 data->gpio.init_valid_mask = nct6694_init_valid_mask;
446 446 data->gpio.base = -1;
447 - data->gpio.can_sleep = true;
447 + data->gpio.can_sleep = false;
448 448 data->gpio.owner = THIS_MODULE;
449 449 data->gpio.ngpio = NCT6694_NR_GPIO;
450 450
modified drivers/gpio/gpiolib-shared.c
@@ -450,6 +450,7 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
450 450 const char *con_id, unsigned long lflags)
451 451 {
452 452 const char *dev_id = dev_name(consumer);
453 + struct gpiod_lookup_table *lookup;
453 454 struct gpio_shared_entry *entry;
454 455 struct gpio_shared_ref *ref;
455 456
@@ -479,22 +480,18 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
479 480 if (!key)
480 481 return -ENOMEM;
481 482
482 - struct gpiod_lookup_table *lookup __free(kfree) =
483 - kzalloc_flex(*lookup, table, 2);
483 + lookup = kzalloc_flex(*lookup, table, 2);
484 484 if (!lookup)
485 485 return -ENOMEM;
486 486
487 487 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
488 488 dev_id, key, ref->con_id ?: "none");
489 489
490 - lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
491 - if (!lookup->dev_id)
492 - return -ENOMEM;
493 -
490 + lookup->dev_id = dev_id;
494 491 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
495 492 ref->con_id, lflags);
496 493
497 - ref->lookup = no_free_ptr(lookup);
494 + ref->lookup = lookup;
498 495 gpiod_add_lookup_table(ref->lookup);
499 496
500 497 return 0;
@@ -614,7 +611,6 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
614 611 if (ref->lookup) {
615 612 gpiod_remove_lookup_table(ref->lookup);
616 613 kfree(ref->lookup->table[0].key);
617 - kfree(ref->lookup->dev_id);
618 614 kfree(ref->lookup);
619 615 ref->lookup = NULL;
620 616 }
modified drivers/gpu/drm/xe/xe_bo.c
@@ -330,6 +330,12 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
330 330 return;
331 331 }
332 332
333 + /* No resource: nothing is placed/mapped, so there is nothing to evict. */
334 + if (!tbo->resource) {
335 + placement->num_placement = 0;
336 + return;
337 + }
338 +
333 339 bo = ttm_to_xe_bo(tbo);
334 340 if (bo->flags & XE_BO_FLAG_CPU_ADDR_MIRROR) {
335 341 *placement = sys_placement;
@@ -944,6 +950,8 @@ static int xe_bo_move_notify(struct xe_bo *bo,
944 950 *
945 951 * Transfers pages between shrinkable and purgeable buckets when the BO
946 952 * purgeable state changes. Called automatically from xe_bo_set_purgeable_state().
953 + * For pinned BOs, whose pages are not accounted, only the purgeable flag is
954 + * updated, so that the correct bucket is used when the BO is unpinned.
947 955 */
948 956 static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
949 957 enum xe_madv_purgeable_state new_state)
@@ -960,7 +968,8 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
960 968 return;
961 969
962 970 xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
963 - tt_pages = tt->num_pages;
971 + /* Pinned bos are not accounted. Only update the purgeable flag. */
972 + tt_pages = xe_bo_is_pinned(bo) ? 0 : tt->num_pages;
964 973
965 974 if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) {
966 975 xe_tt->purgeable = true;
modified tools/gpio/Makefile
@@ -7,13 +7,7 @@ bindir ?= /usr/bin
7 7 # isn't set and when invoked from selftests build, where srctree
8 8 # is set to ".". building_out_of_srctree is undefined for in srctree
9 9 # builds
10 - ifeq ($(srctree),)
11 - update_srctree := 1
12 - endif
13 10 ifndef building_out_of_srctree
14 - update_srctree := 1
15 - endif
16 - ifeq ($(update_srctree),1)
17 11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
18 12 srctree := $(patsubst %/,%,$(dir $(srctree)))
19 13 endif