ANDROID: KVM: arm64: Create empty S2MPU driver

Create a skeleton driver for the S2MPU - an EL1 portion called during
KVM init which will parse the DT and configure the kernel, and an EL2
portion which will program the S2MPUs later at runtime. The code is
behind CONFIG_KVM_S2MPU.

Test: builds, boots
Bug: 190463801
Change-Id: I58206535f3493e1d989576a9db2112d370a1cb4d
Signed-off-by: David Brazdil <dbrazdil@google.com>
(cherry picked from commit b2de5483b7)
Signed-off-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
This commit is contained in:
David Brazdil
2021-07-07 14:54:24 +00:00
committed by Quentin Perret
parent 2bc6495fed
commit c4d2c4f644
10 changed files with 63 additions and 2 deletions

View File

@@ -381,8 +381,15 @@ extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS];
enum kvm_iommu_driver {
KVM_IOMMU_DRIVER_NONE,
KVM_IOMMU_DRIVER_S2MPU,
};
#ifdef CONFIG_KVM_S2MPU
int kvm_s2mpu_init(void);
#else
static inline int kvm_s2mpu_init(void) { return -ENODEV; }
#endif
struct vcpu_reset_state {
unsigned long pc;
unsigned long r0;

View File

@@ -143,5 +143,6 @@ struct kvm_iommu_ops {
};
extern struct kvm_iommu_ops kvm_iommu_ops;
extern const struct kvm_iommu_ops kvm_s2mpu_ops;
#endif /* __ARM64_KVM_HYP_H__ */

View File

@@ -69,4 +69,13 @@ config PROTECTED_NVHE_STACKTRACE
If unsure, or not using protected nVHE (pKVM), say N.
config KVM_S2MPU
bool "Stage-2 Memory Protection Unit support"
depends on KVM
help
Support for the Stage-2 Memory Protection Unit (S2MPU) and Stream
Security Mapping Table (SSMT) devices in KVM. This allows the
hypervisor to restrict DMA access to its memory and the memory of
protected guests.
endif # VIRTUALIZATION

View File

@@ -8,7 +8,7 @@ ccflags-y += -I $(srctree)/$(src)
include $(srctree)/virt/kvm/Makefile.kvm
obj-$(CONFIG_KVM) += kvm.o
obj-$(CONFIG_KVM) += hyp/
obj-$(CONFIG_KVM) += hyp/ iommu/
kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
inject_fault.o va_layout.o handle_exit.o \

View File

@@ -1921,7 +1921,13 @@ static bool init_psci_relay(void)
static int init_stage2_iommu(void)
{
return KVM_IOMMU_DRIVER_NONE;
int ret;
ret = kvm_s2mpu_init();
if (!ret)
return KVM_IOMMU_DRIVER_S2MPU;
return (ret == -ENODEV) ? KVM_IOMMU_DRIVER_NONE : ret;
}
static int init_subsystems(void)

View File

@@ -28,6 +28,8 @@ hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
hyp-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
hyp-obj-y += $(lib-objs)
hyp-obj-$(CONFIG_KVM_S2MPU) += iommu/s2mpu.o
##
## Build rules for compiling nVHE hyp code
## Output of this folder is `kvm_nvhe.o`, a partially linked object

View File

@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021 - Google LLC
* Author: David Brazdil <dbrazdil@google.com>
*/
#include <linux/kvm_host.h>
#include <asm/kvm_hyp.h>
const struct kvm_iommu_ops kvm_s2mpu_ops = (struct kvm_iommu_ops){};

View File

@@ -306,6 +306,12 @@ int select_iommu_ops(enum kvm_iommu_driver driver)
switch (driver) {
case KVM_IOMMU_DRIVER_NONE:
return 0;
case KVM_IOMMU_DRIVER_S2MPU:
if (IS_ENABLED(CONFIG_KVM_S2MPU)) {
kvm_iommu_ops = kvm_s2mpu_ops;
return 0;
}
break;
}
return -EINVAL;

View File

@@ -0,0 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for Kernel-based Virtual Machine module
#
obj-$(CONFIG_KVM_S2MPU) += s2mpu.o

View File

@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021 - Google LLC
* Author: David Brazdil <dbrazdil@google.com>
*/
#include <linux/kvm_host.h>
int kvm_s2mpu_init(void)
{
kvm_info("S2MPU driver initialized\n");
return 0;
}