Commit 625086f8 authored by Zenghui Yu's avatar Zenghui Yu Committed by lishusen
Browse files

KVM: arm64: Add support for probing Hisi ncsnp capability

virt inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8TN8N


CVE: NA

----------------------------------------------------

Kunpeng 920 offers the HHA ncsnp capability, with which hypervisor doesn't
need to perform a lot of cache maintenance like before (in case the guest
has some non-cacheable Stage-1 mappings). Currently we apply this hardware
capability when

 - vCPU switching MMU+caches on/off
 - creating Stage-2 mappings for Daborts

Signed-off-by: default avatarZenghui Yu <yuzenghui@huawei.com>
Signed-off-by: default avatarYanan Wang <wangyanan55@huawei.com>
Signed-off-by: default avatarlishusen <lishusen2@huawei.com>
parent dab235e2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ enum hisi_cpu_type {
};

extern enum hisi_cpu_type hi_cpu_type;
extern bool kvm_ncsnp_support;

void probe_hisi_cpu_type(void);
void probe_hisi_ncsnp_support(void);
#endif /* __HISI_CPU_MODEL_H__ */
+1 −1
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ static inline void __clean_dcache_guest_page(void *va, size_t size)
	 * faulting in pages. Furthermore, FWB implies IDC, so cleaning to
	 * PoU is not required either in this case.
	 */
	if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB))
	if (kvm_ncsnp_support || cpus_have_const_cap(ARM64_HAS_STAGE2_FWB))
		return;

	kvm_flush_dcache_to_poc(va, size);
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ static bool vgic_present, kvm_arm_initialised;

/* Hisi cpu type enum */
enum hisi_cpu_type hi_cpu_type = UNKNOWN_HI_TYPE;
bool kvm_ncsnp_support;

static DEFINE_PER_CPU(unsigned char, kvm_hyp_initialized);
DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use);
@@ -2420,6 +2421,7 @@ static __init int kvm_arm_init(void)

	/* Probe the Hisi CPU type */
	probe_hisi_cpu_type();
	probe_hisi_ncsnp_support();

	in_hyp_mode = is_kernel_in_hyp_mode();

+34 −0
Original line number Diff line number Diff line
@@ -81,3 +81,37 @@ void probe_hisi_cpu_type(void)
	if (hi_cpu_type == UNKNOWN_HI_TYPE)
		pr_warn("UNKNOWN Hisi cpu type.\n");
}

#define NCSNP_MMIO_BASE	0x20107E238

/*
 * We have the fantastic HHA ncsnp capability on Kunpeng 920,
 * with which hypervisor doesn't need to perform a lot of cache
 * maintenance like before (in case the guest has non-cacheable
 * Stage-1 mappings).
 */
void probe_hisi_ncsnp_support(void)
{
	void __iomem *base;
	unsigned int high;

	kvm_ncsnp_support = false;

	if (hi_cpu_type != HI_1620)
		goto out;

	base = ioremap(NCSNP_MMIO_BASE, 4);
	if (!base) {
		pr_err("Unable to map MMIO region when probing ncsnp!\n");
		goto out;
	}

	high = readl_relaxed(base) >> 28;
	iounmap(base);
	if (high != 0x1)
		kvm_ncsnp_support = true;

out:
	kvm_info("Hisi ncsnp: %s\n", kvm_ncsnp_support ? "enabled" :
							 "disabled");
}
+1 −1
Original line number Diff line number Diff line
@@ -1342,7 +1342,7 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size)
		.arg	= pgt,
	};

	if (stage2_has_fwb(pgt))
	if (kvm_ncsnp_support || stage2_has_fwb(pgt))
		return 0;

	return kvm_pgtable_walk(pgt, addr, size, &walker);