Skip to content

Commit 7b6871f

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/pkvm-cleanups-5.17 into kvmarm-master/next
* kvm-arm64/pkvm-cleanups-5.17: : . : pKVM cleanups from Quentin Perret: : : This series is a collection of various fixes and cleanups for KVM/arm64 : when running in nVHE protected mode. The first two patches are real : fixes/improvements, the following two are minor cleanups, and the last : two help satisfy my paranoia so they're certainly optional. : . KVM: arm64: pkvm: Make kvm_host_owns_hyp_mappings() robust to VHE KVM: arm64: pkvm: Stub io map functions KVM: arm64: Make __io_map_base static KVM: arm64: Make the hyp memory pool static KVM: arm64: pkvm: Disable GICv2 support KVM: arm64: pkvm: Fix hyp_pool max order Signed-off-by: Marc Zyngier <[email protected]>
2 parents 94b4a6d + 64a1fbd commit 7b6871f

File tree

7 files changed

+19
-6
lines changed

7 files changed

+19
-6
lines changed

arch/arm64/kvm/hyp/include/nvhe/mm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
extern struct kvm_pgtable pkvm_pgtable;
1414
extern hyp_spinlock_t pkvm_pgd_lock;
15-
extern struct hyp_pool hpool;
16-
extern u64 __io_map_base;
1715

1816
int hyp_create_idmap(u32 hyp_va_bits);
1917
int hyp_map_vectors(void);

arch/arm64/kvm/hyp/nvhe/mm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
struct kvm_pgtable pkvm_pgtable;
2121
hyp_spinlock_t pkvm_pgd_lock;
22-
u64 __io_map_base;
2322

2423
struct memblock_region hyp_memory[HYP_MEMBLOCK_REGIONS];
2524
unsigned int hyp_memblock_nr;
2625

26+
static u64 __io_map_base;
27+
2728
static int __pkvm_create_mappings(unsigned long start, unsigned long size,
2829
unsigned long phys, enum kvm_pgtable_prot prot)
2930
{

arch/arm64/kvm/hyp/nvhe/page_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages,
241241
int i;
242242

243243
hyp_spin_lock_init(&pool->lock);
244-
pool->max_order = min(MAX_ORDER, get_order(nr_pages << PAGE_SHIFT));
244+
pool->max_order = min(MAX_ORDER, get_order((nr_pages + 1) << PAGE_SHIFT));
245245
for (i = 0; i < pool->max_order; i++)
246246
INIT_LIST_HEAD(&pool->free_area[i]);
247247
pool->range_start = phys;

arch/arm64/kvm/hyp/nvhe/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <nvhe/mm.h>
1919
#include <nvhe/trap_handler.h>
2020

21-
struct hyp_pool hpool;
2221
unsigned long hyp_nr_cpus;
2322

2423
#define hyp_percpu_size ((unsigned long)__per_cpu_end - \
@@ -28,6 +27,7 @@ static void *vmemmap_base;
2827
static void *hyp_pgt_base;
2928
static void *host_s2_pgt_base;
3029
static struct kvm_pgtable_mm_ops pkvm_pgtable_mm_ops;
30+
static struct hyp_pool hpool;
3131

3232
static int divide_memory_pool(void *virt, unsigned long size)
3333
{

arch/arm64/kvm/mmu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ void free_hyp_pgds(void)
239239

240240
static bool kvm_host_owns_hyp_mappings(void)
241241
{
242+
if (is_kernel_in_hyp_mode())
243+
return false;
244+
242245
if (static_branch_likely(&kvm_protected_mode_initialized))
243246
return false;
244247

@@ -407,6 +410,9 @@ int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
407410
unsigned long addr;
408411
int ret;
409412

413+
if (is_protected_kvm_enabled())
414+
return -EPERM;
415+
410416
*kaddr = ioremap(phys_addr, size);
411417
if (!*kaddr)
412418
return -ENOMEM;
@@ -650,6 +656,9 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
650656
KVM_PGTABLE_PROT_R |
651657
(writable ? KVM_PGTABLE_PROT_W : 0);
652658

659+
if (is_protected_kvm_enabled())
660+
return -EPERM;
661+
653662
size += offset_in_page(guest_ipa);
654663
guest_ipa &= PAGE_MASK;
655664

arch/arm64/kvm/vgic/vgic-v2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
345345
int ret;
346346
u32 vtr;
347347

348+
if (is_protected_kvm_enabled()) {
349+
kvm_err("GICv2 not supported in protected mode\n");
350+
return -ENXIO;
351+
}
352+
348353
if (!info->vctrl.start) {
349354
kvm_err("GICH not present in the firmware table\n");
350355
return -ENXIO;

arch/arm64/kvm/vgic/vgic-v3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
651651
} else if (!PAGE_ALIGNED(info->vcpu.start)) {
652652
pr_warn("GICV physical address 0x%llx not page aligned\n",
653653
(unsigned long long)info->vcpu.start);
654-
} else {
654+
} else if (kvm_get_mode() != KVM_MODE_PROTECTED) {
655655
kvm_vgic_global_state.vcpu_base = info->vcpu.start;
656656
kvm_vgic_global_state.can_emulate_gicv2 = true;
657657
ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2);

0 commit comments

Comments
 (0)