Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150534869
D46075.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D46075.diff
View Options
diff --git a/sys/arm64/vmm/io/vgic_v3.c b/sys/arm64/vmm/io/vgic_v3.c
--- a/sys/arm64/vmm/io/vgic_v3.c
+++ b/sys/arm64/vmm/io/vgic_v3.c
@@ -68,6 +68,7 @@
#include <arm64/vmm/hyp.h>
#include <arm64/vmm/mmu.h>
#include <arm64/vmm/arm64.h>
+#include <arm64/vmm/vmm_handlers.h>
#include "vgic.h"
#include "vgic_v3.h"
@@ -2252,7 +2253,7 @@
uint64_t ich_vtr_el2;
uint32_t pribits, prebits;
- ich_vtr_el2 = vmm_call_hyp(HYP_READ_REGISTER, HYP_REG_ICH_VTR);
+ ich_vtr_el2 = vmm_read_reg(HYP_REG_ICH_VTR);
/* TODO: These fields are common with the vgicv2 driver */
pribits = ICH_VTR_EL2_PRIBITS(ich_vtr_el2);
diff --git a/sys/arm64/vmm/vmm_arm64.c b/sys/arm64/vmm/vmm_arm64.c
--- a/sys/arm64/vmm/vmm_arm64.c
+++ b/sys/arm64/vmm/vmm_arm64.c
@@ -65,6 +65,7 @@
#include "io/vgic.h"
#include "io/vgic_v3.h"
#include "io/vtimer.h"
+#include "vmm_handlers.h"
#include "vmm_stat.h"
#define HANDLED 1
@@ -101,9 +102,6 @@
static vmem_t *el2_mem_alloc;
static void arm_setup_vectors(void *arg);
-static void vmm_pmap_clean_stage2_tlbi(void);
-static void vmm_pmap_invalidate_range(uint64_t, vm_offset_t, vm_offset_t, bool);
-static void vmm_pmap_invalidate_all(uint64_t);
DPCPU_DEFINE_STATIC(struct hypctx *, vcpu);
@@ -235,7 +233,6 @@
vm_paddr_t vmm_base;
uint64_t id_aa64mmfr0_el1, pa_range_bits, pa_range_field;
uint64_t cnthctl_el2;
- register_t daif;
int cpu, i;
bool rv __diagused;
@@ -291,9 +288,9 @@
/* Set up the stage 2 pmap callbacks */
MPASS(pmap_clean_stage2_tlbi == NULL);
- pmap_clean_stage2_tlbi = vmm_pmap_clean_stage2_tlbi;
- pmap_stage2_invalidate_range = vmm_pmap_invalidate_range;
- pmap_stage2_invalidate_all = vmm_pmap_invalidate_all;
+ pmap_clean_stage2_tlbi = vmm_clean_s2_tlbi;
+ pmap_stage2_invalidate_range = vmm_s2_tlbi_range;
+ pmap_stage2_invalidate_all = vmm_s2_tlbi_all;
/*
* Create an allocator for the virtual address space used by EL2.
@@ -429,9 +426,7 @@
vmem_add(el2_mem_alloc, next_hyp_va,
HYP_VM_MAX_ADDRESS - next_hyp_va, M_WAITOK);
- daif = intr_disable();
- cnthctl_el2 = vmm_call_hyp(HYP_READ_REGISTER, HYP_REG_CNTHCTL);
- intr_restore(daif);
+ cnthctl_el2 = vmm_read_reg(HYP_REG_CNTHCTL);
vgic_init();
vtimer_init(cnthctl_el2);
@@ -567,26 +562,6 @@
vmspace_free(vmspace);
}
-static void
-vmm_pmap_clean_stage2_tlbi(void)
-{
- vmm_call_hyp(HYP_CLEAN_S2_TLBI);
-}
-
-static void
-vmm_pmap_invalidate_range(uint64_t vttbr, vm_offset_t sva, vm_offset_t eva,
- bool final_only)
-{
- MPASS(eva > sva);
- vmm_call_hyp(HYP_S2_TLBI_RANGE, vttbr, sva, eva, final_only);
-}
-
-static void
-vmm_pmap_invalidate_all(uint64_t vttbr)
-{
- vmm_call_hyp(HYP_S2_TLBI_ALL, vttbr);
-}
-
static inline void
arm64_print_hyp_regs(struct vm_exit *vme)
{
@@ -1143,8 +1118,7 @@
vgic_flush_hwstate(hypctx);
/* Call into EL2 to switch to the guest */
- excp_type = vmm_call_hyp(HYP_ENTER_GUEST,
- hyp->el2_addr, hypctx->el2_addr);
+ excp_type = vmm_enter_guest(hyp, hypctx);
vgic_sync_hwstate(hypctx);
vtimer_sync_hwstate(hypctx);
diff --git a/sys/arm64/vmm/vmm_handlers.h b/sys/arm64/vmm/vmm_handlers.h
new file mode 100644
--- /dev/null
+++ b/sys/arm64/vmm/vmm_handlers.h
@@ -0,0 +1,48 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Arm Ltd
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _VMM_VMM_HANDLERS_H_
+#define _VMM_VMM_HANDLERS_H_
+
+#include <sys/types.h>
+
+struct hyp;
+struct hypctx;
+
+void vmm_clean_s2_tlbi(void);
+uint64_t vmm_enter_guest(struct hyp *, struct hypctx *);
+uint64_t vmm_read_reg(uint64_t);
+void vmm_s2_tlbi_range(uint64_t, vm_offset_t, vm_offset_t, bool);
+void vmm_s2_tlbi_all(uint64_t);
+
+void vmm_vhe_clean_s2_tlbi(void);
+uint64_t vmm_vhe_enter_guest(struct hyp *, struct hypctx *);
+uint64_t vmm_vhe_read_reg(uint64_t);
+void vmm_vhe_s2_tlbi_range(uint64_t, vm_offset_t, vm_offset_t, bool);
+void vmm_vhe_s2_tlbi_all(uint64_t);
+
+#endif /* _VMM_VMM_HANDLERS_H_ */
diff --git a/sys/arm64/vmm/vmm_handlers.c b/sys/arm64/vmm/vmm_handlers.c
new file mode 100644
--- /dev/null
+++ b/sys/arm64/vmm/vmm_handlers.c
@@ -0,0 +1,65 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Arm Ltd
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <machine/ifunc.h>
+
+#include "arm64.h"
+#include "vmm_handlers.h"
+
+uint64_t
+vmm_read_reg(uint64_t reg)
+{
+ return (vmm_call_hyp(HYP_READ_REGISTER, reg));
+}
+
+uint64_t
+vmm_enter_guest(struct hyp *hyp, struct hypctx *hypctx)
+{
+ return (vmm_call_hyp(HYP_ENTER_GUEST, hyp->el2_addr, hypctx->el2_addr));
+}
+
+void
+vmm_clean_s2_tlbi(void)
+{
+ vmm_call_hyp(HYP_CLEAN_S2_TLBI);
+}
+
+void
+vmm_s2_tlbi_range(uint64_t vttbr, vm_offset_t sva, vm_offset_t eva,
+ bool final_only)
+{
+ vmm_call_hyp(HYP_S2_TLBI_RANGE, vttbr, sva, eva, final_only);
+}
+
+void
+vmm_s2_tlbi_all(uint64_t vttbr)
+{
+ vmm_call_hyp(HYP_S2_TLBI_ALL, vttbr);
+}
diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64
--- a/sys/conf/files.arm64
+++ b/sys/conf/files.arm64
@@ -122,6 +122,7 @@
arm64/vmm/vmm_stat.c optional vmm
arm64/vmm/vmm_arm64.c optional vmm
arm64/vmm/vmm_reset.c optional vmm
+arm64/vmm/vmm_handlers.c optional vmm
arm64/vmm/vmm_call.S optional vmm
arm64/vmm/vmm_nvhe_exception.S optional vmm \
compile-with "${NOSAN_C:N-mbranch-protection*} -fpie" \
diff --git a/sys/modules/vmm/Makefile b/sys/modules/vmm/Makefile
--- a/sys/modules/vmm/Makefile
+++ b/sys/modules/vmm/Makefile
@@ -28,6 +28,7 @@
SRCS+= vmm_arm64.c \
vmm_reset.c \
vmm_call.S \
+ vmm_handlers.c \
vmm_mmu.c \
vmm_hyp_el2.S
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 3:24 AM (3 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30742463
Default Alt Text
D46075.diff (7 KB)
Attached To
Mode
D46075: arm64/vmm: Create functions to call into EL2
Attached
Detach File
Event Timeline
Log In to Comment