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

KVM: arm64: Probe Hisi CPU TYPE from ACPI/DTB

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


CVE: NA

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

Parse ACPI/DTB to get where the hypervisor is running.

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 fa30d756
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright(c) 2019 Huawei Technologies Co., Ltd
 */

#ifndef __HISI_CPU_MODEL_H__
#define __HISI_CPU_MODEL_H__

enum hisi_cpu_type {
	HI_1612,
	HI_1616,
	HI_1620,
	UNKNOWN_HI_TYPE
};

extern enum hisi_cpu_type hi_cpu_type;

void probe_hisi_cpu_type(void);
#endif /* __HISI_CPU_MODEL_H__ */
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <asm/fpsimd.h>
#include <asm/kvm.h>
#include <asm/kvm_asm.h>
#include <asm/hisi_cpu_model.h>

#define __KVM_HAVE_ARCH_INTC_INITIALIZED

+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
	 guest.o debug.o reset.o sys_regs.o stacktrace.o \
	 vgic-sys-reg-v3.o fpsimd.o pkvm.o \
	 arch_timer.o trng.o vmid.o emulate-nested.o nested.o \
	 hisi_cpu_model.o \
	 vgic/vgic.o vgic/vgic-init.o \
	 vgic/vgic-irqfd.o vgic/vgic-v2.o \
	 vgic/vgic-v3.o vgic/vgic-v4.o \
+6 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ DECLARE_KVM_NVHE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);

static bool vgic_present, kvm_arm_initialised;

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

static DEFINE_PER_CPU(unsigned char, kvm_hyp_initialized);
DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use);

@@ -2415,6 +2418,9 @@ static __init int kvm_arm_init(void)
		return err;
	}

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

	in_hyp_mode = is_kernel_in_hyp_mode();

	if (cpus_have_final_cap(ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) ||
+83 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright(c) 2019 Huawei Technologies Co., Ltd
 */

#include <linux/acpi.h>
#include <linux/of.h>
#include <linux/init.h>
#include <linux/kvm_host.h>

#ifdef CONFIG_ACPI

/* ACPI Hisi oem table id str */
const char *oem_str[] = {
	"HIP06",	/* Hisi 1612 */
	"HIP07",	/* Hisi 1616 */
	"HIP08"		/* Hisi 1620 */
};

/*
 * Get Hisi oem table id.
 */
static void acpi_get_hw_cpu_type(void)
{
	struct acpi_table_header *table;
	acpi_status status;
	int i, str_size = ARRAY_SIZE(oem_str);

	/* Get oem table id from ACPI table header */
	status = acpi_get_table(ACPI_SIG_DSDT, 0, &table);
	if (ACPI_FAILURE(status)) {
		pr_err("Failed to get ACPI table: %s\n",
		       acpi_format_exception(status));
		return;
	}

	for (i = 0; i < str_size; ++i) {
		if (!strncmp(oem_str[i], table->oem_table_id, 5)) {
			hi_cpu_type = i;
			return;
		}
	}
}

#else
static void acpi_get_hw_cpu_type(void) {}
#endif

/* of Hisi cpu model str */
const char *of_model_str[] = {
	"Hi1612",
	"Hi1616"
};

static void of_get_hw_cpu_type(void)
{
	const char *cpu_type;
	int ret, i, str_size = ARRAY_SIZE(of_model_str);

	ret = of_property_read_string(of_root, "model", &cpu_type);
	if (ret < 0) {
		pr_err("Failed to get Hisi cpu model by OF.\n");
		return;
	}

	for (i = 0; i < str_size; ++i) {
		if (strstr(cpu_type, of_model_str[i])) {
			hi_cpu_type = i;
			return;
		}
	}
}

void probe_hisi_cpu_type(void)
{
	if (!acpi_disabled)
		acpi_get_hw_cpu_type();
	else
		of_get_hw_cpu_type();

	if (hi_cpu_type == UNKNOWN_HI_TYPE)
		pr_warn("UNKNOWN Hisi cpu type.\n");
}