mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +09:00
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>
This commit is contained in:
committed by
Mostafa Saleh
parent
4c1082edb0
commit
0295ee70f1
@@ -384,8 +384,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;
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
@@ -68,4 +68,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
|
||||
|
||||
@@ -8,7 +8,7 @@ ccflags-y += -I $(srctree)/$(src)
|
||||
KVM=../../../virt/kvm
|
||||
|
||||
obj-$(CONFIG_KVM) += kvm.o
|
||||
obj-$(CONFIG_KVM) += hyp/
|
||||
obj-$(CONFIG_KVM) += hyp/ iommu/
|
||||
|
||||
kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \
|
||||
$(KVM)/vfio.o $(KVM)/irqchip.o $(KVM)/binary_stats.o \
|
||||
|
||||
@@ -1927,7 +1927,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
11
arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c
Normal file
11
arch/arm64/kvm/hyp/nvhe/iommu/s2mpu.c
Normal 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){};
|
||||
@@ -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;
|
||||
|
||||
6
arch/arm64/kvm/iommu/Makefile
Normal file
6
arch/arm64/kvm/iommu/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# Makefile for Kernel-based Virtual Machine module
|
||||
#
|
||||
|
||||
obj-$(CONFIG_KVM_S2MPU) += s2mpu.o
|
||||
13
arch/arm64/kvm/iommu/s2mpu.c
Normal file
13
arch/arm64/kvm/iommu/s2mpu.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user