Skip to content

Commit ce990f1

Browse files
committed
Merge tag 'for-linus-5.17-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen updates from Juergen Gross: - a fix for the Xen gntdev driver - a fix for running as Xen dom0 booted via EFI and the EFI framebuffer being located above 4GB - a series for support of mapping other guest's memory by using zone device when running as Xen guest on Arm * tag 'for-linus-5.17-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: dt-bindings: xen: Clarify "reg" purpose arm/xen: Read extended regions from DT and init Xen resource xen/unpopulated-alloc: Add mechanism to use Xen resource xen/balloon: Bring alloc(free)_xenballooned_pages helpers back arm/xen: Switch to use gnttab_setup_auto_xlat_frames() for DT xen/unpopulated-alloc: Drop check for virt_addr_valid() in fill_list() xen/x86: obtain upper 32 bits of video frame buffer address for Dom0 xen/gntdev: fix unmap notification order
2 parents 64ad946 + 54bb4a9 commit ce990f1

File tree

10 files changed

+259
-36
lines changed

10 files changed

+259
-36
lines changed

Documentation/devicetree/bindings/arm/xen.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ the following properties:
77
compatible = "xen,xen-<version>", "xen,xen";
88
where <version> is the version of the Xen ABI of the platform.
99

10-
- reg: specifies the base physical address and size of a region in
11-
memory where the grant table should be mapped to, using an
12-
HYPERVISOR_memory_op hypercall. The memory region is large enough to map
13-
the whole grant table (it is larger or equal to gnttab_max_grant_frames()).
14-
This property is unnecessary when booting Dom0 using ACPI.
10+
- reg: specifies the base physical address and size of the regions in memory
11+
where the special resources should be mapped to, using an HYPERVISOR_memory_op
12+
hypercall.
13+
Region 0 is reserved for mapping grant table, it must be always present.
14+
The memory region is large enough to map the whole grant table (it is larger
15+
or equal to gnttab_max_grant_frames()).
16+
Regions 1...N are extended regions (unused address space) for mapping foreign
17+
GFNs and grants, they might be absent if there is nothing to expose.
1518

1619
- interrupts: the interrupt used by Xen to inject event notifications.
1720
A GIC node is also required.
18-
This property is unnecessary when booting Dom0 using ACPI.
1921

2022
To support UEFI on Xen ARM virtual platforms, Xen populates the FDT "uefi" node
2123
under /hypervisor with following parameters:

arch/arm/xen/enlighten.c

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ unsigned long xen_released_pages;
5959
struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
6060

6161
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
65+
#define EXT_REGION_INDEX 1
6266

6367
uint32_t xen_start_flags;
6468
EXPORT_SYMBOL(xen_start_flags);
@@ -300,9 +304,115 @@ static void __init xen_acpi_guest_init(void)
300304
#endif
301305
}
302306

307+
#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
308+
/*
309+
* A type-less specific Xen resource which contains extended regions
310+
* (unused regions of guest physical address space provided by the hypervisor).
311+
*/
312+
static struct resource xen_resource = {
313+
.name = "Xen unused space",
314+
};
315+
316+
int __init arch_xen_unpopulated_init(struct resource **res)
317+
{
318+
struct device_node *np;
319+
struct resource *regs, *tmp_res;
320+
uint64_t min_gpaddr = -1, max_gpaddr = 0;
321+
unsigned int i, nr_reg = 0;
322+
int rc;
323+
324+
if (!xen_domain())
325+
return -ENODEV;
326+
327+
if (!acpi_disabled)
328+
return -ENODEV;
329+
330+
np = of_find_compatible_node(NULL, NULL, "xen,xen");
331+
if (WARN_ON(!np))
332+
return -ENODEV;
333+
334+
/* Skip region 0 which is reserved for grant table space */
335+
while (of_get_address(np, nr_reg + EXT_REGION_INDEX, NULL, NULL))
336+
nr_reg++;
337+
338+
if (!nr_reg) {
339+
pr_err("No extended regions are found\n");
340+
return -EINVAL;
341+
}
342+
343+
regs = kcalloc(nr_reg, sizeof(*regs), GFP_KERNEL);
344+
if (!regs)
345+
return -ENOMEM;
346+
347+
/*
348+
* Create resource from extended regions provided by the hypervisor to be
349+
* used as unused address space for Xen scratch pages.
350+
*/
351+
for (i = 0; i < nr_reg; i++) {
352+
rc = of_address_to_resource(np, i + EXT_REGION_INDEX, &regs[i]);
353+
if (rc)
354+
goto err;
355+
356+
if (max_gpaddr < regs[i].end)
357+
max_gpaddr = regs[i].end;
358+
if (min_gpaddr > regs[i].start)
359+
min_gpaddr = regs[i].start;
360+
}
361+
362+
xen_resource.start = min_gpaddr;
363+
xen_resource.end = max_gpaddr;
364+
365+
/*
366+
* Mark holes between extended regions as unavailable. The rest of that
367+
* address space will be available for the allocation.
368+
*/
369+
for (i = 1; i < nr_reg; i++) {
370+
resource_size_t start, end;
371+
372+
/* There is an overlap between regions */
373+
if (regs[i - 1].end + 1 > regs[i].start) {
374+
rc = -EINVAL;
375+
goto err;
376+
}
377+
378+
/* There is no hole between regions */
379+
if (regs[i - 1].end + 1 == regs[i].start)
380+
continue;
381+
382+
start = regs[i - 1].end + 1;
383+
end = regs[i].start - 1;
384+
385+
tmp_res = kzalloc(sizeof(*tmp_res), GFP_KERNEL);
386+
if (!tmp_res) {
387+
rc = -ENOMEM;
388+
goto err;
389+
}
390+
391+
tmp_res->name = "Unavailable space";
392+
tmp_res->start = start;
393+
tmp_res->end = end;
394+
395+
rc = insert_resource(&xen_resource, tmp_res);
396+
if (rc) {
397+
pr_err("Cannot insert resource %pR (%d)\n", tmp_res, rc);
398+
kfree(tmp_res);
399+
goto err;
400+
}
401+
}
402+
403+
*res = &xen_resource;
404+
405+
err:
406+
kfree(regs);
407+
408+
return rc;
409+
}
410+
#endif
411+
303412
static void __init xen_dt_guest_init(void)
304413
{
305414
struct device_node *xen_node;
415+
struct resource res;
306416

307417
xen_node = of_find_compatible_node(NULL, NULL, "xen,xen");
308418
if (!xen_node) {
@@ -311,13 +421,19 @@ static void __init xen_dt_guest_init(void)
311421
}
312422

313423
xen_events_irq = irq_of_parse_and_map(xen_node, 0);
424+
425+
if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) {
426+
pr_err("Xen grant table region is not found\n");
427+
return;
428+
}
429+
xen_grant_frames = res.start;
314430
}
315431

316432
static int __init xen_guest_init(void)
317433
{
318434
struct xen_add_to_physmap xatp;
319435
struct shared_info *shared_info_page = NULL;
320-
int cpu;
436+
int rc, cpu;
321437

322438
if (!xen_domain())
323439
return 0;
@@ -370,12 +486,16 @@ static int __init xen_guest_init(void)
370486
for_each_possible_cpu(cpu)
371487
per_cpu(xen_vcpu_id, cpu) = cpu;
372488

373-
xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames();
374-
if (xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn,
375-
&xen_auto_xlat_grant_frames.vaddr,
376-
xen_auto_xlat_grant_frames.count)) {
489+
if (!xen_grant_frames) {
490+
xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames();
491+
rc = xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn,
492+
&xen_auto_xlat_grant_frames.vaddr,
493+
xen_auto_xlat_grant_frames.count);
494+
} else
495+
rc = gnttab_setup_auto_xlat_frames(xen_grant_frames);
496+
if (rc) {
377497
free_percpu(xen_vcpu_info);
378-
return -ENOMEM;
498+
return rc;
379499
}
380500
gnttab_init();
381501

arch/x86/xen/vga.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,18 @@ void __init xen_init_vga(const struct dom0_vga_console_info *info, size_t size)
6262
break;
6363
}
6464

65-
if (size >= offsetof(struct dom0_vga_console_info,
66-
u.vesa_lfb.gbl_caps)
67-
+ sizeof(info->u.vesa_lfb.gbl_caps))
68-
screen_info->capabilities = info->u.vesa_lfb.gbl_caps;
6965
if (size >= offsetof(struct dom0_vga_console_info,
7066
u.vesa_lfb.mode_attrs)
7167
+ sizeof(info->u.vesa_lfb.mode_attrs))
7268
screen_info->vesa_attributes = info->u.vesa_lfb.mode_attrs;
69+
70+
if (size >= offsetof(struct dom0_vga_console_info,
71+
u.vesa_lfb.ext_lfb_base)
72+
+ sizeof(info->u.vesa_lfb.ext_lfb_base)
73+
&& info->u.vesa_lfb.ext_lfb_base) {
74+
screen_info->ext_lfb_base = info->u.vesa_lfb.ext_lfb_base;
75+
screen_info->capabilities |= VIDEO_CAPABILITY_64BIT_BASE;
76+
}
7377
break;
7478
}
7579
}

drivers/xen/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ config XEN_FRONT_PGDIR_SHBUF
327327

328328
config XEN_UNPOPULATED_ALLOC
329329
bool "Use unpopulated memory ranges for guest mappings"
330-
depends on X86 && ZONE_DEVICE
330+
depends on ZONE_DEVICE
331331
default XEN_BACKEND || XEN_GNTDEV || XEN_DOM0
332332
help
333333
Use unpopulated memory ranges in order to create mappings for guest

drivers/xen/balloon.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ void balloon_set_new_target(unsigned long target)
581581
}
582582
EXPORT_SYMBOL_GPL(balloon_set_new_target);
583583

584-
#ifndef CONFIG_XEN_UNPOPULATED_ALLOC
585584
static int add_ballooned_pages(unsigned int nr_pages)
586585
{
587586
enum bp_state st;
@@ -610,12 +609,12 @@ static int add_ballooned_pages(unsigned int nr_pages)
610609
}
611610

612611
/**
613-
* xen_alloc_unpopulated_pages - get pages that have been ballooned out
612+
* xen_alloc_ballooned_pages - get pages that have been ballooned out
614613
* @nr_pages: Number of pages to get
615614
* @pages: pages returned
616615
* @return 0 on success, error otherwise
617616
*/
618-
int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)
617+
int xen_alloc_ballooned_pages(unsigned int nr_pages, struct page **pages)
619618
{
620619
unsigned int pgno = 0;
621620
struct page *page;
@@ -652,23 +651,23 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)
652651
return 0;
653652
out_undo:
654653
mutex_unlock(&balloon_mutex);
655-
xen_free_unpopulated_pages(pgno, pages);
654+
xen_free_ballooned_pages(pgno, pages);
656655
/*
657-
* NB: free_xenballooned_pages will only subtract pgno pages, but since
656+
* NB: xen_free_ballooned_pages will only subtract pgno pages, but since
658657
* target_unpopulated is incremented with nr_pages at the start we need
659658
* to remove the remaining ones also, or accounting will be screwed.
660659
*/
661660
balloon_stats.target_unpopulated -= nr_pages - pgno;
662661
return ret;
663662
}
664-
EXPORT_SYMBOL(xen_alloc_unpopulated_pages);
663+
EXPORT_SYMBOL(xen_alloc_ballooned_pages);
665664

666665
/**
667-
* xen_free_unpopulated_pages - return pages retrieved with get_ballooned_pages
666+
* xen_free_ballooned_pages - return pages retrieved with get_ballooned_pages
668667
* @nr_pages: Number of pages
669668
* @pages: pages to return
670669
*/
671-
void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)
670+
void xen_free_ballooned_pages(unsigned int nr_pages, struct page **pages)
672671
{
673672
unsigned int i;
674673

@@ -687,9 +686,9 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)
687686

688687
mutex_unlock(&balloon_mutex);
689688
}
690-
EXPORT_SYMBOL(xen_free_unpopulated_pages);
689+
EXPORT_SYMBOL(xen_free_ballooned_pages);
691690

692-
#if defined(CONFIG_XEN_PV)
691+
#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC)
693692
static void __init balloon_add_region(unsigned long start_pfn,
694693
unsigned long pages)
695694
{
@@ -712,7 +711,6 @@ static void __init balloon_add_region(unsigned long start_pfn,
712711
balloon_stats.total_pages += extra_pfn_end - start_pfn;
713712
}
714713
#endif
715-
#endif
716714

717715
static int __init balloon_init(void)
718716
{

drivers/xen/gntdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
250250
if (!refcount_dec_and_test(&map->users))
251251
return;
252252

253+
if (map->pages && !use_ptemod)
254+
unmap_grant_pages(map, 0, map->count);
255+
253256
if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) {
254257
notify_remote_via_evtchn(map->notify.event);
255258
evtchn_put(map->notify.event);
256259
}
257-
258-
if (map->pages && !use_ptemod)
259-
unmap_grant_pages(map, 0, map->count);
260260
gntdev_free_map(map);
261261
}
262262

0 commit comments

Comments
 (0)