mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-12 09:58:36 +00:00
arm64/vmm: Start to extract code not needed by VHE
We can share some of the vmm code between VHE and non-VHE modes. To support this create new files that include the common code and create macros to name what will be the common functions. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46072
This commit is contained in:
parent
4db15ab2c6
commit
3d61bcf1eb
@ -41,7 +41,7 @@ struct hypctx;
|
||||
|
||||
uint64_t vmm_hyp_enter(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
|
||||
uint64_t, uint64_t, uint64_t);
|
||||
uint64_t vmm_enter_guest(struct hypctx *);
|
||||
uint64_t VMM_HYP_FUNC(do_call_guest)(struct hypctx *);
|
||||
|
||||
static void
|
||||
vmm_hyp_reg_store(struct hypctx *hypctx, struct hyp *hyp, bool guest)
|
||||
@ -496,7 +496,7 @@ vmm_hyp_call_guest(struct hyp *hyp, struct hypctx *hypctx)
|
||||
WRITE_SPECIALREG(mdcr_el2, hypctx->mdcr_el2);
|
||||
|
||||
/* Call into the guest */
|
||||
ret = vmm_enter_guest(hypctx);
|
||||
ret = VMM_HYP_FUNC(do_call_guest)(hypctx);
|
||||
|
||||
WRITE_SPECIALREG(mdcr_el2, host_hypctx.mdcr_el2);
|
||||
isb();
|
||||
@ -566,8 +566,20 @@ vmm_hyp_call_guest(struct hyp *hyp, struct hypctx *hypctx)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
vmm_hyp_read_reg(uint64_t reg)
|
||||
VMM_STATIC uint64_t
|
||||
VMM_HYP_FUNC(enter_guest)(struct hyp *hyp, struct hypctx *hypctx)
|
||||
{
|
||||
uint64_t ret;
|
||||
|
||||
do {
|
||||
ret = vmm_hyp_call_guest(hyp, hypctx);
|
||||
} while (ret == EXCP_TYPE_REENTER);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
VMM_STATIC uint64_t
|
||||
VMM_HYP_FUNC(read_reg)(uint64_t reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case HYP_REG_ICH_VTR:
|
||||
@ -579,18 +591,16 @@ vmm_hyp_read_reg(uint64_t reg)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
vmm_clean_s2_tlbi(void)
|
||||
VMM_STATIC void
|
||||
VMM_HYP_FUNC(clean_s2_tlbi)(void)
|
||||
{
|
||||
dsb(ishst);
|
||||
__asm __volatile("tlbi alle1is");
|
||||
dsb(ish);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
vm_s2_tlbi_range(uint64_t vttbr, vm_offset_t sva, vm_size_t eva,
|
||||
VMM_STATIC void
|
||||
VMM_HYP_FUNC(s2_tlbi_range)(uint64_t vttbr, vm_offset_t sva, vm_offset_t eva,
|
||||
bool final_only)
|
||||
{
|
||||
uint64_t end, r, start;
|
||||
@ -634,12 +644,10 @@ vm_s2_tlbi_range(uint64_t vttbr, vm_offset_t sva, vm_size_t eva,
|
||||
/* Switch back t othe host vttbr */
|
||||
WRITE_SPECIALREG(vttbr_el2, host_vttbr);
|
||||
isb();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
vm_s2_tlbi_all(uint64_t vttbr)
|
||||
VMM_STATIC void
|
||||
VMM_HYP_FUNC(s2_tlbi_all)(uint64_t vttbr)
|
||||
{
|
||||
uint64_t host_vttbr;
|
||||
|
||||
@ -656,8 +664,6 @@ vm_s2_tlbi_all(uint64_t vttbr)
|
||||
/* Switch back t othe host vttbr */
|
||||
WRITE_SPECIALREG(vttbr_el2, host_vttbr);
|
||||
isb();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -705,27 +711,25 @@ uint64_t
|
||||
vmm_hyp_enter(uint64_t handle, uint64_t x1, uint64_t x2, uint64_t x3,
|
||||
uint64_t x4, uint64_t x5, uint64_t x6, uint64_t x7)
|
||||
{
|
||||
uint64_t ret;
|
||||
|
||||
switch (handle) {
|
||||
case HYP_ENTER_GUEST:
|
||||
do {
|
||||
ret = vmm_hyp_call_guest((struct hyp *)x1,
|
||||
(struct hypctx *)x2);
|
||||
} while (ret == EXCP_TYPE_REENTER);
|
||||
return (ret);
|
||||
return (VMM_HYP_FUNC(enter_guest)((struct hyp *)x1,
|
||||
(struct hypctx *)x2));
|
||||
case HYP_READ_REGISTER:
|
||||
return (vmm_hyp_read_reg(x1));
|
||||
return (VMM_HYP_FUNC(read_reg)(x1));
|
||||
case HYP_CLEAN_S2_TLBI:
|
||||
return (vmm_clean_s2_tlbi());
|
||||
VMM_HYP_FUNC(clean_s2_tlbi());
|
||||
return (0);
|
||||
case HYP_DC_CIVAC:
|
||||
return (vmm_dc_civac(x1, x2));
|
||||
case HYP_EL2_TLBI:
|
||||
return (vmm_el2_tlbi(x1, x2, x3));
|
||||
case HYP_S2_TLBI_RANGE:
|
||||
return (vm_s2_tlbi_range(x1, x2, x3, x4));
|
||||
VMM_HYP_FUNC(s2_tlbi_range)(x1, x2, x3, x4);
|
||||
return (0);
|
||||
case HYP_S2_TLBI_ALL:
|
||||
return (vm_s2_tlbi_all(x1));
|
||||
VMM_HYP_FUNC(s2_tlbi_all)(x1);
|
||||
return (0);
|
||||
case HYP_CLEANUP: /* Handled in vmm_hyp_exception.S */
|
||||
default:
|
||||
break;
|
||||
|
@ -349,12 +349,12 @@ LEND(handle_el2_el1_error64)
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* uint64_t vmm_enter_guest(struct hypctx *hypctx)
|
||||
* uint64_t vmm_do_call_guest(struct hypctx *hypctx)
|
||||
*
|
||||
* Expecting:
|
||||
* x0 - hypctx address
|
||||
*/
|
||||
ENTRY(vmm_enter_guest)
|
||||
ENTRY(VMM_HYP_FUNC(do_call_guest))
|
||||
/* Save hypctx address */
|
||||
msr tpidr_el2, x0
|
||||
|
||||
@ -363,7 +363,7 @@ ENTRY(vmm_enter_guest)
|
||||
|
||||
/* Enter guest */
|
||||
ERET
|
||||
END(vmm_enter_guest)
|
||||
END(VMM_HYP_FUNC(do_call_guest))
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
|
31
sys/arm64/vmm/vmm_nvhe.c
Normal file
31
sys/arm64/vmm/vmm_nvhe.c
Normal file
@ -0,0 +1,31 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define VMM_STATIC static
|
||||
#define VMM_HYP_FUNC(func) vmm_nvhe_ ## func
|
||||
|
||||
#include "vmm_hyp.c"
|
30
sys/arm64/vmm/vmm_nvhe_exception.S
Normal file
30
sys/arm64/vmm/vmm_nvhe_exception.S
Normal file
@ -0,0 +1,30 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define VMM_HYP_FUNC(func) vmm_nvhe_ ## func
|
||||
|
||||
#include "vmm_hyp_exception.S"
|
@ -123,14 +123,14 @@ arm64/vmm/vmm_stat.c optional vmm
|
||||
arm64/vmm/vmm_arm64.c optional vmm
|
||||
arm64/vmm/vmm_reset.c optional vmm
|
||||
arm64/vmm/vmm_call.S optional vmm
|
||||
arm64/vmm/vmm_hyp_exception.S optional vmm \
|
||||
arm64/vmm/vmm_nvhe_exception.S optional vmm \
|
||||
compile-with "${NOSAN_C:N-mbranch-protection*} -fpie" \
|
||||
no-obj
|
||||
arm64/vmm/vmm_hyp.c optional vmm \
|
||||
arm64/vmm/vmm_nvhe.c optional vmm \
|
||||
compile-with "${NOSAN_C:N-mbranch-protection*} -fpie" \
|
||||
no-obj
|
||||
vmm_hyp_blob.elf.full optional vmm \
|
||||
dependency "vmm_hyp.o vmm_hyp_exception.o" \
|
||||
dependency "vmm_nvhe.o vmm_hyp_exception.o" \
|
||||
compile-with "${SYSTEM_LD_BASECMD} -o ${.TARGET} ${.ALLSRC} --defsym=_start='0x0' --defsym=text_start='0x0'" \
|
||||
no-obj no-implicit-rule
|
||||
vmm_hyp_blob.elf optional vmm \
|
||||
|
@ -38,19 +38,20 @@ SRCS+= vgic.c \
|
||||
vgic_v3.c \
|
||||
vtimer.c
|
||||
|
||||
CLEANFILES+= vmm_hyp_exception.o vmm_hyp.o
|
||||
CLEANFILES+= vmm_nvhe_exception.o vmm_nvhe.o
|
||||
|
||||
CLEANFILES+= vmm_hyp_blob.elf.full
|
||||
CLEANFILES+= vmm_hyp_blob.elf vmm_hyp_blob.bin
|
||||
|
||||
vmm_hyp_exception.o: vmm_hyp_exception.S
|
||||
vmm_nvhe_exception.o: vmm_nvhe_exception.S
|
||||
${CC} -c -x assembler-with-cpp -DLOCORE \
|
||||
${NOSAN_CFLAGS:N-mbranch-protection*} ${.IMPSRC} -o ${.TARGET} -fpie
|
||||
|
||||
vmm_hyp.o: vmm_hyp.c
|
||||
vmm_nvhe.o: vmm_nvhe.c
|
||||
${CC} -c ${NOSAN_CFLAGS:N-mbranch-protection*} ${.IMPSRC} \
|
||||
-o ${.TARGET} -fpie
|
||||
|
||||
vmm_hyp_blob.elf.full: vmm_hyp_exception.o vmm_hyp.o
|
||||
vmm_hyp_blob.elf.full: vmm_nvhe_exception.o vmm_nvhe.o
|
||||
${LD} -m ${LD_EMULATION} -Bdynamic -L ${SYSDIR}/conf -T ${SYSDIR}/conf/ldscript.arm64 \
|
||||
${_LDFLAGS:N-zbti-report*} --no-warn-mismatch --warn-common --export-dynamic \
|
||||
--dynamic-linker /red/herring -X -o ${.TARGET} ${.ALLSRC} \
|
||||
|
Loading…
Reference in New Issue
Block a user