On 17/11/2026 13:19, Michael S. Tsirkin wrote:
[Some people who received this message don't often get email from 
[email protected]. Learn why this is important at 
https://aka.ms/LearnAboutSenderIdentification ]

On Sat, Nov 07, 2026 at 12:59:48AM +0100, Anton Kuchin wrote:
build_crs() collects used resources without any information about
valid address windows. These resources can therefore lie outside
the interval passed to crs_replace_with_free_ranges().

crs_replace_with_free_ranges() assumed all used ranges lie within
the interval.

you mean assumes?


I suppose. Not sure now if this is a typo or I wanted to indicate that before this patch function "assumed", but after this patch it no longer has this assumption and is ready to handle any crazy list of regions (that are aligned correctly, I didn't change the alignment assumption).

Ranges outside it could therefore produce free ranges
extending below or above its bounds.

could in what sense? does it produce them?
in what configuratoons?


It definetely does. With limits [0x10000000-0x1fffffff] for range [0x00000000-0x00000fff] which is below the window it will return [0x00001000-0x1fffffff] instead of [0x10000000-0x1fffffff].

And for region [0x30000000-0x30000fff] which is above the window it will return [0x10000000-0x2fffffff] instead of [0x10000000-0x1fffffff].


As a result, the guest kernel
may assign a device an invalid address range.

And does it? what guest?


It does. Guest treats resulting free ranges as resources that can be allocated for device BARs. So with enough devices some of them get BARs in this invalid region.


Skip ranges with limit below the interval start or with base above
the interval's end.

and then what happens?


If device's BAR happens to be in invalid portion of region device doesn't work.

If we skip such irrelevant regions resulting free ranges fully belong to MMIO window and work correctly.


Signed-off-by: Anton Kuchin <[email protected]>
---
  hw/acpi/aml-build.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 990abc64cd8b..90837b513e69 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -124,7 +124,7 @@ static gint crs_range_compare(gconstpointer a, 
gconstpointer b)
  }

  /*
- * crs_replace_with_free_ranges - given the 'used' ranges within [start - end]
+ * crs_replace_with_free_ranges - given the 'used' ranges and [start - end]
   * interval, computes the 'free' ranges from the same interval.
   * Example: If the input array is { [a1 - a2],[b1 - b2] }, the function
   * will return { [base - a1], [a2 - b1], [b2 - limit] }.
@@ -140,6 +140,16 @@ void crs_replace_with_free_ranges(GPtrArray *ranges,
      for (i = 0; i < ranges->len; i++) {
          CrsRangeEntry *used = g_ptr_array_index(ranges, i);

+        /* skip ranges below the window */
+        if (used->limit < free_base) {
+            continue;
+        }
+
+        /* skip ranges above the window */
+        if (used->base > end) {
+            break;
+        }
+
          if (free_base < used->base) {
              crs_range_insert(free_ranges, free_base, used->base - 1);
          }

--
2.43.0



Reply via email to