In coco guests, hotpluggable memory ranges are initially unaccepted. While a previous change expanded the unaccepted memory bitmap boundaries to include these hotplug spaces, the actual bits inside the bitmap are not yet marked as unaccepted.
Walks SRAT a second time after the bitmap is allocated and sets the bits corresponding to hotpluggable ranges. This ensures the bitmap state accurately reflects all static and hotplug memory ranges before booting kernel. Signed-off-by: Zhenzhong Duan <[email protected]> --- .../firmware/efi/libstub/unaccepted_memory.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/firmware/efi/libstub/unaccepted_memory.c b/drivers/firmware/efi/libstub/unaccepted_memory.c index bfbb78bd7b8a..01bed8e751ca 100644 --- a/drivers/firmware/efi/libstub/unaccepted_memory.c +++ b/drivers/firmware/efi/libstub/unaccepted_memory.c @@ -92,6 +92,23 @@ static void update_mem_boundaries(struct acpi_srat_mem_affinity *mem, struct sra *(ctx->mem_end) = range_end; } +static void mark_hotplug_memory_unaccepted(struct acpi_srat_mem_affinity *mem, + struct srat_parse_ctx *ctx) +{ + u64 unit_size = unaccepted_table->unit_size; + u64 start, end; + + start = round_up(mem->base_address, unit_size); + end = round_down(mem->base_address + mem->length, unit_size); + + /* Translate to offsets from the beginning of the bitmap */ + start -= unaccepted_table->phys_base; + end -= unaccepted_table->phys_base; + + bitmap_set(unaccepted_table->bitmap, + start / unit_size, (end - start) / unit_size); +} + efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc, struct efi_boot_memmap *map) { @@ -169,6 +186,7 @@ efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc, unaccepted_table->phys_base = unaccepted_start; unaccepted_table->size = bitmap_size; memset(unaccepted_table->bitmap, 0, bitmap_size); + parse_acpi_srat_regions(mark_hotplug_memory_unaccepted, &ctx); status = efi_bs_call(install_configuration_table, &unaccepted_table_guid, unaccepted_table); -- 2.52.0

