Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm/xen: Switch to use gnttab_setup_auto_xlat_frames() for DT

Read the start address of the grant table space from DT
(region 0).

This patch mostly restores behaviour before commit 3cf4095d7446
("arm/xen: Use xen_xlate_map_ballooned_pages to setup grant table")
but trying not to break the ACPI support added after that commit.
So the patch touches DT part only and leaves the ACPI part with
xen_xlate_map_ballooned_pages(). Also in order to make a code more
resilient use a fallback to xen_xlate_map_ballooned_pages() if grant
table region wasn't found.

This is a preparation for using Xen extended region feature
where unused regions of guest physical address space (provided
by the hypervisor) will be used to create grant/foreign/whatever
mappings instead of wasting real RAM pages from the domain memory
for establishing these mappings.

The immediate benefit of this change:
- Avoid superpage shattering in Xen P2M when establishing
stage-2 mapping (GFN <-> MFN) for the grant table space
- Avoid wasting real RAM pages (reducing the amount of memory
usuable) for mapping grant table space
- The grant table space is always mapped at the exact
same place (region 0 is reserved for the grant table)

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Link: https://lore.kernel.org/r/1639080336-26573-3-git-send-email-olekstysh@gmail.com
Signed-off-by: Juergen Gross <jgross@suse.com>

authored by

Oleksandr Tyshchenko and committed by
Juergen Gross
5e1cdb8e fbf3a5c3

+20 -6
+20 -6
arch/arm/xen/enlighten.c
··· 59 59 struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata; 60 60 61 61 static __read_mostly unsigned int xen_events_irq; 62 + static __read_mostly phys_addr_t xen_grant_frames; 63 + 64 + #define GRANT_TABLE_INDEX 0 62 65 63 66 uint32_t xen_start_flags; 64 67 EXPORT_SYMBOL(xen_start_flags); ··· 306 303 static void __init xen_dt_guest_init(void) 307 304 { 308 305 struct device_node *xen_node; 306 + struct resource res; 309 307 310 308 xen_node = of_find_compatible_node(NULL, NULL, "xen,xen"); 311 309 if (!xen_node) { ··· 315 311 } 316 312 317 313 xen_events_irq = irq_of_parse_and_map(xen_node, 0); 314 + 315 + if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) { 316 + pr_err("Xen grant table region is not found\n"); 317 + return; 318 + } 319 + xen_grant_frames = res.start; 318 320 } 319 321 320 322 static int __init xen_guest_init(void) 321 323 { 322 324 struct xen_add_to_physmap xatp; 323 325 struct shared_info *shared_info_page = NULL; 324 - int cpu; 326 + int rc, cpu; 325 327 326 328 if (!xen_domain()) 327 329 return 0; ··· 380 370 for_each_possible_cpu(cpu) 381 371 per_cpu(xen_vcpu_id, cpu) = cpu; 382 372 383 - xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames(); 384 - if (xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn, 385 - &xen_auto_xlat_grant_frames.vaddr, 386 - xen_auto_xlat_grant_frames.count)) { 373 + if (!xen_grant_frames) { 374 + xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames(); 375 + rc = xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn, 376 + &xen_auto_xlat_grant_frames.vaddr, 377 + xen_auto_xlat_grant_frames.count); 378 + } else 379 + rc = gnttab_setup_auto_xlat_frames(xen_grant_frames); 380 + if (rc) { 387 381 free_percpu(xen_vcpu_info); 388 - return -ENOMEM; 382 + return rc; 389 383 } 390 384 gnttab_init(); 391 385