mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
xen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region
The number of Redistributor regions allowed for dom0 is hardcoded
to a define MAX_RDIST_COUNT which is 4. Some systems, especially
latest server chips, may have more than 4 redistributors. Either we
have to increase MAX_RDIST_COUNT to a bigger number or allocate
memory based on the number of redistributors that are found in MADT
table. In the worst case scenario, the macro MAX_RDIST_COUNT should
be equal to CONFIG_NR_CPUS in order to support per CPU Redistributors.
Increasing MAX_RDIST_COUNT has a effect, it blows 'struct domain'
size and hits BUILD_BUG_ON() in domain build code path.
struct domain *alloc_domain_struct(void)
{
struct domain *d;
BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
d = alloc_xenheap_pages(0, 0);
if ( d == NULL )
return NULL;
...
This patch uses the second approach to fix the BUILD_BUG().
Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
1 parent
cede771011
commit
611c1befab
5 files changed
+34
-4
No files matched your search
@@ -699,9 +699,15 @@ static int vgic_v2_domain_init(struct domain *d)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vgic_v2_domain_free(struct domain *d)
|
||||
{
|
||||
/* Nothing to be cleanup for this driver */
|
||||
}
|
||||
|
||||
static const struct vgic_ops vgic_v2_ops = {
|
||||
.vcpu_init = vgic_v2_vcpu_init,
|
||||
.domain_init = vgic_v2_domain_init,
|
||||
.domain_free = vgic_v2_domain_free,
|
||||
.max_vcpus = 8,
|
||||
};
|
||||
|
||||
|
||||
+24
-3
@@ -1391,9 +1391,26 @@ static int vgic_v3_vcpu_init(struct vcpu *v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline unsigned int vgic_v3_rdist_count(struct domain *d)
|
||||
{
|
||||
return is_hardware_domain(d) ? vgic_v3_hw.nr_rdist_regions :
|
||||
GUEST_GICV3_RDIST_REGIONS;
|
||||
}
|
||||
|
||||
static int vgic_v3_domain_init(struct domain *d)
|
||||
{
|
||||
int i;
|
||||
struct vgic_rdist_region *rdist_regions;
|
||||
int rdist_count, i;
|
||||
|
||||
/* Allocate memory for Re-distributor regions */
|
||||
rdist_count = vgic_v3_rdist_count(d);
|
||||
|
||||
rdist_regions = xzalloc_array(struct vgic_rdist_region, rdist_count);
|
||||
if ( !rdist_regions )
|
||||
return -ENOMEM;
|
||||
|
||||
d->arch.vgic.nr_regions = rdist_count;
|
||||
d->arch.vgic.rdist_regions = rdist_regions;
|
||||
|
||||
/*
|
||||
* Domain 0 gets the hardware address.
|
||||
@@ -1426,7 +1443,6 @@ static int vgic_v3_domain_init(struct domain *d)
|
||||
|
||||
first_cpu += size / d->arch.vgic.rdist_stride;
|
||||
}
|
||||
d->arch.vgic.nr_regions = vgic_v3_hw.nr_rdist_regions;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1435,7 +1451,6 @@ static int vgic_v3_domain_init(struct domain *d)
|
||||
/* XXX: Only one Re-distributor region mapped for the guest */
|
||||
BUILD_BUG_ON(GUEST_GICV3_RDIST_REGIONS != 1);
|
||||
|
||||
d->arch.vgic.nr_regions = GUEST_GICV3_RDIST_REGIONS;
|
||||
d->arch.vgic.rdist_stride = GUEST_GICV3_RDIST_STRIDE;
|
||||
|
||||
/* The first redistributor should contain enough space for all CPUs */
|
||||
@@ -1467,9 +1482,15 @@ static int vgic_v3_domain_init(struct domain *d)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vgic_v3_domain_free(struct domain *d)
|
||||
{
|
||||
xfree(d->arch.vgic.rdist_regions);
|
||||
}
|
||||
|
||||
static const struct vgic_ops v3_ops = {
|
||||
.vcpu_init = vgic_v3_vcpu_init,
|
||||
.domain_init = vgic_v3_domain_init,
|
||||
.domain_free = vgic_v3_domain_free,
|
||||
.emulate_sysreg = vgic_v3_emulate_sysreg,
|
||||
/*
|
||||
* We use both AFF1 and AFF0 in (v)MPIDR. Thus, the max number of CPU
|
||||
|
||||
@@ -179,6 +179,7 @@ void domain_vgic_free(struct domain *d)
|
||||
}
|
||||
}
|
||||
|
||||
d->arch.vgic.handler->domain_free(d);
|
||||
xfree(d->arch.vgic.shared_irqs);
|
||||
xfree(d->arch.vgic.pending_irqs);
|
||||
xfree(d->arch.vgic.allocated_irqs);
|
||||
|
||||
@@ -107,7 +107,7 @@ struct arch_domain
|
||||
paddr_t base; /* Base address */
|
||||
paddr_t size; /* Size */
|
||||
unsigned int first_cpu; /* First CPU handled */
|
||||
} rdist_regions[MAX_RDIST_COUNT];
|
||||
} *rdist_regions;
|
||||
int nr_regions; /* Number of rdist regions */
|
||||
uint32_t rdist_stride; /* Re-Distributor stride */
|
||||
#endif
|
||||
|
||||
@@ -128,6 +128,8 @@ struct vgic_ops {
|
||||
int (*vcpu_init)(struct vcpu *v);
|
||||
/* Domain specific initialization of vGIC */
|
||||
int (*domain_init)(struct domain *d);
|
||||
/* Release resources that were allocated by domain_init */
|
||||
void (*domain_free)(struct domain *d);
|
||||
/* vGIC sysreg emulation */
|
||||
int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
|
||||
/* Maximum number of vCPU supported */
|
||||
|
||||