On 17/11/2026 13:20, Michael S. Tsirkin wrote:
On Sat, Nov 07, 2026 at 12:59:49AM +0100, Anton Kuchin wrote:
crs_replace_with_free_ranges() advances its cursor past each used
range by adding one to the range's limit. If the limit is
UINT64_MAX,
when is it UINT64_MAX?
I don't know. Never reproduced this specific one. Just noticed that
theoretically it can be. And if it does it breaks the logic.
the cursor wraps to zero, potentially producing free
ranges outside the requested window or overlapping used resources.
Adjust free_base and stop processing when a used range reaches or
exceeds the interval's upper bound to avoid cursor wrapping and
final free range insertion.
was this tested? how?
This particular case with UINT64_MAX limit hasn't not been seen in
production so I don't have a recipe to reproduce it. I just extracted
crs_replace_with_free_ranges into a standalone executable after I fixed
the "reserved range below the window" case and threw at it all the
inputs I could imagine to test different corner cases.
If you are asking about the series in general these changes has been
merged into our internal qemu branches few months ago, and now is
running on all our hosts both arm64 and x86_64.
Signed-off-by: Anton Kuchin <[email protected]>
---
hw/acpi/aml-build.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 90837b513e69..b71d82b5e8a9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -154,6 +154,12 @@ void crs_replace_with_free_ranges(GPtrArray *ranges,
crs_range_insert(free_ranges, free_base, used->base - 1);
}
+ /* avoid free_base overflow when used->limit equals UINT64_MAX */
+ if (used->limit >= end) {
+ free_base = end;
+ break;
+ }
+
free_base = used->limit + 1;
}
--
2.43.0