From 1a139995bc4639b2492ea2ed68db4dab737ea701 Mon Sep 17 00:00:00 2001 From: jsg Date: Tue, 12 Mar 2024 05:42:37 +0000 Subject: [PATCH] drm/buddy: fix range bias From Matthew Auld 5e476625fa8a36d7483ec3396a2bd124c2c02066 in linux-6.6.y/6.6.21 f41900e4a6ef019d64a70394b0e0c3bd048d4ec8 in mainline linux --- sys/dev/pci/drm/drm_buddy.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/dev/pci/drm/drm_buddy.c b/sys/dev/pci/drm/drm_buddy.c index 03457c65ac7..7d47a58a518 100644 --- a/sys/dev/pci/drm/drm_buddy.c +++ b/sys/dev/pci/drm/drm_buddy.c @@ -342,6 +342,7 @@ alloc_range_bias(struct drm_buddy *mm, u64 start, u64 end, unsigned int order) { + u64 req_size = mm->chunk_size << order; struct drm_buddy_block *block; struct drm_buddy_block *buddy; DRM_LIST_HEAD(dfs); @@ -377,6 +378,15 @@ alloc_range_bias(struct drm_buddy *mm, if (drm_buddy_block_is_allocated(block)) continue; + if (block_start < start || block_end > end) { + u64 adjusted_start = max(block_start, start); + u64 adjusted_end = min(block_end, end); + + if (round_down(adjusted_end + 1, req_size) <= + round_up(adjusted_start, req_size)) + continue; + } + if (contains(start, end, block_start, block_end) && order == drm_buddy_block_order(block)) { /* -- 2.20.1