Compare

bd22f7e63509fa758cf500d9af3e88a3d3df96be..ffbfd3f98f4393e91dffce3a46ccb7cf5329cf2f

drm/xe: Don't transfer shrinker pages for pinned bos on purgeable state change

Pinned bos have their pages removed from the shrinker's shrinkable /
purgeable counts on pin, and added back on unpin according to the
bo's purgeable state at that time.

However, xe_bo_set_purgeable_shrinker() unconditionally transfers
pages between the shrinkable and purgeable counts. If the purgeable
state of a pinned bo changes, for example by userspace madvising
DONTNEED on a VMA of a bo that is also pinned as a scanout buffer,
this underflows one count and, after unpin, leaves the other one
permanently inflated.

Only update the purgeable flag for pinned bos, and leave the page
accounting to unpin.

Fixes: 536a2ead3a8f ("drm/xe/bo: Add purgeable shrinker state helpers")
Cc: Arvind Yadav <arvind.yadav@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: intel-xe@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v7.1+
Assisted-by: LLM
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patch.msgid.link/20261009070053.7790-1-thomas.hellstrom@linux.intel.com
(cherry picked from commit afe6bc012034123fd838328668e609bf57e46bd3)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

Thomas Hellström <thomas.hellstrom@linux.intel.com> · 2026-10-09 07:00 UTC · committed by Rodrigo Vivi

Browse files
4 files changed, +9 −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
@@ -944,6 +944,8 @@ static int xe_bo_move_notify(struct xe_bo *bo,
944 944 *
945 945 * Transfers pages between shrinkable and purgeable buckets when the BO
946 946 * purgeable state changes. Called automatically from xe_bo_set_purgeable_state().
947 + * For pinned BOs, whose pages are not accounted, only the purgeable flag is
948 + * updated, so that the correct bucket is used when the BO is unpinned.
947 949 */
948 950 static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
949 951 enum xe_madv_purgeable_state new_state)
@@ -960,7 +962,8 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
960 962 return;
961 963
962 964 xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
963 - tt_pages = tt->num_pages;
965 + /* Pinned bos are not accounted. Only update the purgeable flag. */
966 + tt_pages = xe_bo_is_pinned(bo) ? 0 : tt->num_pages;
964 967
965 968 if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) {
966 969 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