From nobody Tue Aug 20 09:02:28 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wp3Px3pJmz5SjCg; Tue, 20 Aug 2024 09:02:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wp3Px0gtWz4vf3; Tue, 20 Aug 2024 09:02:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724144549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Hiu+cNk0y5r/2ZIERIPD+fm++fr5Jw0Q3tVewGBYMsg=; b=XOF66POelRX2QitIVPtHmBqdG4xkU3S5e/4AYNpmGSaJ/k4iWZdz8nWCyjMYKqAaDd9rFf cpB3+wRlq0gQwGDwS0YWq8jr/KqfaTf0sO1IIv6uFcFMNK1mEzRyqyBwfFCepqKUSBmsqy CqGNj0X52PTwNNHaLMuvUJteLvNdRbiK1p6TCKHNL/dKCBWNNjYyhCmoo05AeZtGEjsa5d eqMRM3q6WYf7GabxbVftY5QolqHE+Zw0usLoS/jIae5FytxDJ60cTOp9Gv5Emumbu5t1mE WybgUJKcveEUR4pDbAR+RuxazkKS4wumHPzeI/zGD3EIcr9LKzJdq51lTNef7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724144549; a=rsa-sha256; cv=none; b=qD6ImKPKIkYFiJY81kwjHdKkkdKDdWR9v0tvzMJrM2TmXPX8a2zCDPnvFH5UBWZ5J2uSy1 tpCMdQscvehwc7XQzaGAAyNw2K0kwGUzsItTF2MffyoI97E52OCkVcL1DxU7Sz4bFbXwWd wT2TeyEoT7uxV+vZsCkvCMeKWMAPH8Mzc3tP6BgZLL898wK5+T3QKis2u+cvDXhkReMjNT i9c23HX1NYjN/3Hn3dHPAcu8hGvcbs2jIDew9EXItpsWbF7hjseOkIMYP3OQKM/RL9hfQJ p7HBGxEagC6gZhNfqqTx5O105qZUSWvA3WJnmwLKdyaL2l8cuZ9HR3ZjzgKv7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724144549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Hiu+cNk0y5r/2ZIERIPD+fm++fr5Jw0Q3tVewGBYMsg=; b=VrpfcVuMXT6hxAhUmGyIzgK+Cjrwtom4j74TuyOolUcFzgoHUXi+IArApMP/cLj11KrkTE cBzzAw1pXDg9Dtqkt/WDA0PsH/sc9leWNTr0oMEIPhESkS0NhCvM43kjHGdz4w+2erXkHK 4FGP1JxjkyKsTN9kqVB93QpBJxLnAwrq6TxyPoK/L8weCrqVjfABi6qdkYTQ6+hPDZ3QmO aYngjLCeatxlagmzxmlUjyKdidXPhtEI4swPQYKgjUEi9dU4oDSgaWIcnqeQ2QzrO2QQrs ad5gJ69UNDSktTpbClSEbFd0++nw29rBlSvihuUs373DpDJYFk3vDsvBo5pP5w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wp3Pw75bRzv4b; Tue, 20 Aug 2024 09:02:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47K92SEd081990; Tue, 20 Aug 2024 09:02:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K92SbR081986; Tue, 20 Aug 2024 09:02:28 GMT (envelope-from git) Date: Tue, 20 Aug 2024 09:02:28 GMT Message-Id: <202408200902.47K92SbR081986@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 7279fa6af13d - main - arm64/vmm: Convert the handlers into ifuncs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7279fa6af13d1c370f9bcb293562c694090d849d Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=7279fa6af13d1c370f9bcb293562c694090d849d commit 7279fa6af13d1c370f9bcb293562c694090d849d Author: Andrew Turner AuthorDate: 2024-08-19 12:45:54 +0000 Commit: Andrew Turner CommitDate: 2024-08-20 08:49:16 +0000 arm64/vmm: Convert the handlers into ifuncs Now we have support for both VHE and non-VHE update the handlers to use an ifunc to decide which version to use. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46084 --- sys/arm64/vmm/vmm_handlers.c | 68 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/sys/arm64/vmm/vmm_handlers.c b/sys/arm64/vmm/vmm_handlers.c index 2ce674d5ba46..c567b585eb06 100644 --- a/sys/arm64/vmm/vmm_handlers.c +++ b/sys/arm64/vmm/vmm_handlers.c @@ -33,33 +33,81 @@ #include "arm64.h" #include "vmm_handlers.h" -uint64_t -vmm_read_reg(uint64_t reg) +/* Read an EL2 register */ +static uint64_t +vmm_nvhe_read_reg(uint64_t reg) { return (vmm_call_hyp(HYP_READ_REGISTER, reg)); } -uint64_t -vmm_enter_guest(struct hyp *hyp, struct hypctx *hypctx) +DEFINE_IFUNC(, uint64_t, vmm_read_reg, (uint64_t reg)) +{ + if (in_vhe()) + return (vmm_vhe_read_reg); + return (vmm_nvhe_read_reg); +} + +/* Enter the guest */ +static uint64_t +vmm_nvhe_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) +DEFINE_IFUNC(, uint64_t, vmm_enter_guest, + (struct hyp *hyp, struct hypctx *hypctx)) +{ + if (in_vhe()) + return (vmm_vhe_enter_guest); + return (vmm_nvhe_enter_guest); +} + +/* Clean the TLB for all guests */ +static void +vmm_nvhe_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, +DEFINE_IFUNC(, void, vmm_clean_s2_tlbi, (void)) +{ + if (in_vhe()) + return (vmm_vhe_clean_s2_tlbi); + return (vmm_nvhe_clean_s2_tlbi); +} + +/* + * Switch to a guest vttbr and clean the TLB for a range of guest + * virtual address space. + */ +static void +vmm_nvhe_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) +DEFINE_IFUNC(, void, vmm_s2_tlbi_range, + (uint64_t vttbr, vm_offset_t sva, vm_offset_t eva, bool final_only)) +{ + if (in_vhe()) + return (vmm_vhe_s2_tlbi_range); + return (vmm_nvhe_s2_tlbi_range); +} + +/* + * Switch to a guest vttbr and clean the TLB for all the guest + * virtual address space. + */ +static void +vmm_nvhe_s2_tlbi_all(uint64_t vttbr) { vmm_call_hyp(HYP_S2_TLBI_ALL, vttbr); } + +DEFINE_IFUNC(, void, vmm_s2_tlbi_all, (uint64_t vttbr)) +{ + if (in_vhe()) + return (vmm_vhe_s2_tlbi_all); + return (vmm_nvhe_s2_tlbi_all); +}