Skip to content

Commit 1bb32a4

Browse files
author
Marc Zyngier
committed
KVM: arm/arm64: Keep GICv2 HYP VAs in kvm_vgic_global_state
As we're about to change the way we map devices at HYP, we need to move away from kern_hyp_va on an IO address. One way of achieving this is to store the VAs in kvm_vgic_global_state, and use that directly from the HYP code. This requires a small change to create_hyp_io_mappings so that it can also return a HYP VA. We take this opportunity to nuke the vctrl_base field in the emulated distributor, as it is not used anymore. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 807a378 commit 1bb32a4

7 files changed

Lines changed: 38 additions & 34 deletions

File tree

‎arch/arm/include/asm/kvm_mmu.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151

5252
int create_hyp_mappings(void *from, void *to, pgprot_t prot);
5353
int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
54-
void __iomem **kaddr);
54+
void __iomem **kaddr,
55+
void __iomem **haddr);
5556
void free_hyp_pgds(void);
5657

5758
void stage2_unmap_vm(struct kvm *kvm);

‎arch/arm64/include/asm/kvm_mmu.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ static inline unsigned long __kern_hyp_va(unsigned long v)
141141

142142
int create_hyp_mappings(void *from, void *to, pgprot_t prot);
143143
int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
144-
void __iomem **kaddr);
144+
void __iomem **kaddr,
145+
void __iomem **haddr);
145146
void free_hyp_pgds(void);
146147

147148
void stage2_unmap_vm(struct kvm *kvm);

‎arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int __hyp_text __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
6060
return -1;
6161

6262
rd = kvm_vcpu_dabt_get_rd(vcpu);
63-
addr = kern_hyp_va(hyp_symbol_addr(kvm_vgic_global_state)->vcpu_base_va);
63+
addr = hyp_symbol_addr(kvm_vgic_global_state)->vcpu_hyp_va;
6464
addr += fault_ipa - vgic->vgic_cpu_base;
6565

6666
if (kvm_vcpu_dabt_iswrite(vcpu)) {

‎include/kvm/arm_vgic.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ struct vgic_global {
5757
/* Physical address of vgic virtual cpu interface */
5858
phys_addr_t vcpu_base;
5959

60-
/* GICV mapping */
60+
/* GICV mapping, kernel VA */
6161
void __iomem *vcpu_base_va;
62+
/* GICV mapping, HYP VA */
63+
void __iomem *vcpu_hyp_va;
6264

63-
/* virtual control interface mapping */
65+
/* virtual control interface mapping, kernel VA */
6466
void __iomem *vctrl_base;
67+
/* virtual control interface mapping, HYP VA */
68+
void __iomem *vctrl_hyp;
6569

6670
/* Number of implemented list registers */
6771
int nr_lr;
@@ -209,10 +213,6 @@ struct vgic_dist {
209213

210214
int nr_spis;
211215

212-
/* TODO: Consider moving to global state */
213-
/* Virtual control interface mapping */
214-
void __iomem *vctrl_base;
215-
216216
/* base addresses in guest physical address space: */
217217
gpa_t vgic_dist_base; /* distributor */
218218
union {

‎virt/kvm/arm/mmu.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,28 +713,38 @@ int create_hyp_mappings(void *from, void *to, pgprot_t prot)
713713
* @phys_addr: The physical start address which gets mapped
714714
* @size: Size of the region being mapped
715715
* @kaddr: Kernel VA for this mapping
716-
*
717-
* The resulting HYP VA is the same as the kernel VA, modulo
718-
* HYP_PAGE_OFFSET.
716+
* @haddr: HYP VA for this mapping
719717
*/
720718
int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
721-
void __iomem **kaddr)
719+
void __iomem **kaddr,
720+
void __iomem **haddr)
722721
{
723722
unsigned long start, end;
723+
int ret;
724724

725725
*kaddr = ioremap(phys_addr, size);
726726
if (!*kaddr)
727727
return -ENOMEM;
728728

729729
if (is_kernel_in_hyp_mode()) {
730+
*haddr = *kaddr;
730731
return 0;
731732
}
732733

733734

734735
start = kern_hyp_va((unsigned long)*kaddr);
735736
end = kern_hyp_va((unsigned long)*kaddr + size);
736-
return __create_hyp_mappings(hyp_pgd, PTRS_PER_PGD, start, end,
737+
ret = __create_hyp_mappings(hyp_pgd, PTRS_PER_PGD, start, end,
737738
__phys_to_pfn(phys_addr), PAGE_HYP_DEVICE);
739+
740+
if (ret) {
741+
iounmap(*kaddr);
742+
*kaddr = NULL;
743+
return ret;
744+
}
745+
746+
*haddr = (void __iomem *)start;
747+
return 0;
738748
}
739749

740750
/**

‎virt/kvm/arm/vgic/vgic-init.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
166166
kvm->arch.vgic.in_kernel = true;
167167
kvm->arch.vgic.vgic_model = type;
168168

169-
/*
170-
* kvm_vgic_global_state.vctrl_base is set on vgic probe (kvm_arch_init)
171-
* it is stored in distributor struct for asm save/restore purpose
172-
*/
173-
kvm->arch.vgic.vctrl_base = kvm_vgic_global_state.vctrl_base;
174-
175169
kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
176170
kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
177171
kvm->arch.vgic.vgic_redist_base = VGIC_ADDR_UNDEF;

‎virt/kvm/arm/vgic/vgic-v2.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
363363

364364
ret = create_hyp_io_mappings(info->vcpu.start,
365365
resource_size(&info->vcpu),
366-
&kvm_vgic_global_state.vcpu_base_va);
366+
&kvm_vgic_global_state.vcpu_base_va,
367+
&kvm_vgic_global_state.vcpu_hyp_va);
367368
if (ret) {
368369
kvm_err("Cannot map GICV into hyp\n");
369370
goto out;
@@ -374,7 +375,8 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
374375

375376
ret = create_hyp_io_mappings(info->vctrl.start,
376377
resource_size(&info->vctrl),
377-
&kvm_vgic_global_state.vctrl_base);
378+
&kvm_vgic_global_state.vctrl_base,
379+
&kvm_vgic_global_state.vctrl_hyp);
378380
if (ret) {
379381
kvm_err("Cannot map VCTRL into hyp\n");
380382
goto out;
@@ -429,9 +431,7 @@ static void save_lrs(struct kvm_vcpu *vcpu, void __iomem *base)
429431

430432
void vgic_v2_save_state(struct kvm_vcpu *vcpu)
431433
{
432-
struct kvm *kvm = vcpu->kvm;
433-
struct vgic_dist *vgic = &kvm->arch.vgic;
434-
void __iomem *base = vgic->vctrl_base;
434+
void __iomem *base = kvm_vgic_global_state.vctrl_base;
435435
u64 used_lrs = vcpu->arch.vgic_cpu.used_lrs;
436436

437437
if (!base)
@@ -445,10 +445,8 @@ void vgic_v2_save_state(struct kvm_vcpu *vcpu)
445445

446446
void vgic_v2_restore_state(struct kvm_vcpu *vcpu)
447447
{
448-
struct kvm *kvm = vcpu->kvm;
449-
struct vgic_dist *vgic = &kvm->arch.vgic;
450448
struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
451-
void __iomem *base = vgic->vctrl_base;
449+
void __iomem *base = kvm_vgic_global_state.vctrl_base;
452450
u64 used_lrs = vcpu->arch.vgic_cpu.used_lrs;
453451
int i;
454452

@@ -467,17 +465,17 @@ void vgic_v2_restore_state(struct kvm_vcpu *vcpu)
467465
void vgic_v2_load(struct kvm_vcpu *vcpu)
468466
{
469467
struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
470-
struct vgic_dist *vgic = &vcpu->kvm->arch.vgic;
471468

472-
writel_relaxed(cpu_if->vgic_vmcr, vgic->vctrl_base + GICH_VMCR);
473-
writel_relaxed(cpu_if->vgic_apr, vgic->vctrl_base + GICH_APR);
469+
writel_relaxed(cpu_if->vgic_vmcr,
470+
kvm_vgic_global_state.vctrl_base + GICH_VMCR);
471+
writel_relaxed(cpu_if->vgic_apr,
472+
kvm_vgic_global_state.vctrl_base + GICH_APR);
474473
}
475474

476475
void vgic_v2_put(struct kvm_vcpu *vcpu)
477476
{
478477
struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
479-
struct vgic_dist *vgic = &vcpu->kvm->arch.vgic;
480478

481-
cpu_if->vgic_vmcr = readl_relaxed(vgic->vctrl_base + GICH_VMCR);
482-
cpu_if->vgic_apr = readl_relaxed(vgic->vctrl_base + GICH_APR);
479+
cpu_if->vgic_vmcr = readl_relaxed(kvm_vgic_global_state.vctrl_base + GICH_VMCR);
480+
cpu_if->vgic_apr = readl_relaxed(kvm_vgic_global_state.vctrl_base + GICH_APR);
483481
}

0 commit comments

Comments
 (0)