From 2cb178cea5eb5b0505a1e61b2f747fd478e4acc9 Mon Sep 17 00:00:00 2001 From: Mostafa Saleh Date: Wed, 2 Aug 2023 11:19:08 +0000 Subject: [PATCH] ANDROID: KVM: arm64: devices: Add initial device definitions In preparation for supporting device assignment in pKVM, the hypervisor should be able to authenticate assigned devices by providing HVCs to the guest to get trusted description about the device. To be able to do this the hypervisor should get assignable devices description at boot when the kernel is still trusted. Bug: 357781595 Bug: 348382247 Change-Id: I8bf38c253786eb56cbb1368531b2a3dea048ae88 Signed-off-by: Mostafa Saleh --- arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/device/device.c | 8 +++++ include/kvm/device.h | 42 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/device/device.c create mode 100644 include/kvm/device.h diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index 3ea29d6442ca..c3efa66b672a 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -8,7 +8,7 @@ CFLAGS_switch.nvhe.o += -Wno-override-init hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ hyp-main.o hyp-smp.o psci-relay.o alloc.o early_alloc.o page_alloc.o \ cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o ffa.o \ - serial.o alloc_mgt.o iommu/iommu.o power/hvc.o power/scmi.o + serial.o alloc_mgt.o iommu/iommu.o power/hvc.o power/scmi.o device/device.o hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o diff --git a/arch/arm64/kvm/hyp/nvhe/device/device.c b/arch/arm64/kvm/hyp/nvhe/device/device.c new file mode 100644 index 000000000000..4e8085fb4321 --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/device/device.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Google LLC + * Author: Mostafa Saleh + */ + +struct pkvm_device *registered_devices; +unsigned long registered_devices_nr; diff --git a/include/kvm/device.h b/include/kvm/device.h new file mode 100644 index 000000000000..5e53a98d757c --- /dev/null +++ b/include/kvm/device.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Google LLC + * Author: Mostafa Saleh + */ + +#ifndef __KVM_DEVICE_H +#define __KVM_DEVICE_H + +#include + +/* + * @base: physical address of MMIO resource. + * @size: size of resource in bytes. + */ +struct pkvm_dev_resource { + u64 base; + u64 size; +}; + +/* + * @id: hypervisor ID of the IOMMU as defined by the driver. + * @endpoint: endpoint ID of the device. + */ +struct pkvm_dev_iommu { + u64 id; + u64 endpoint; +}; + +#define PKVM_DEVICE_MAX_RESOURCE 32 +#define PKVM_DEVICE_MAX_IOMMU 32 + +struct pkvm_device { + struct pkvm_dev_resource resources[PKVM_DEVICE_MAX_RESOURCE]; + struct pkvm_dev_iommu iommus[PKVM_DEVICE_MAX_IOMMU]; + u32 nr_resources; + u32 nr_iommus; + u32 group_id; + void *ctxt; /* Current context of the device*/ +}; + +#endif /* #ifndef __KVM_DEVICE_H */