From nobody Tue Aug 20 09:02:16 2024 X-Original-To: dev-commits-src-all@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 4Wp3Pj0F2wz5Sj69; Tue, 20 Aug 2024 09:02:17 +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 4Wp3Ph4bbCz4vL2; Tue, 20 Aug 2024 09:02:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724144536; 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=9GdlMqGAxGfXnMzTTO1tv1qYed0AdK0BkFKGi5lBzIs=; b=kXdAvMh1xFYxFUc/zj3Ted5vDXe9O8HP3q4hsRLn2RyUlugBvRQfCiI7679B3Brh+2pifa eL8P4UEF+nP0EObtMmH+fRqMBSP81IJkASYMbDh43bZ08ODLn6UjXw2vfKOSDJoeq9erFg kcqxgWXmbzsz2StXF/NgWsYVtWEUAbutmer+Nlq5mG6V9gB+sSX2Y4tHYg9DaqJuDlLEqx KAlh7TU2jCyvXLvrBaBWnYJ7aHEUhY53/5Lay56cAZ8FZdjKxe+OKgpTgBoJrJNwEn9wlQ KRlpjvOuDCqxgaeCrZ2ABawOad56/MrhbSd4nWpvPHuyXnmPWHJtvyzv73NEqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724144536; a=rsa-sha256; cv=none; b=IdW0kYmZb+7mSx/ggrvq7wuWk4tBMKEfLNgODnI6h7pNTcZd2bh7txNC6YqvJ4NGHHIfo+ fMsx0mmZkVL7fYnBflNiXSBFK8SXMTDGm2UxN3RMPYve4GSvLVYwKDMX+CriLBH7Kv/KSP xVYJlR7+VxESHz0Z8Kd96mBwD8rbVEfNGllbbEKSwASgWXNajlUBo5DDPY5TnATj5EGF3V rCP7KfkZn51sOSxTaHli2tgRARhJqRN22ltdOL5c7VwArXkA0n0bi7btVURbh1x4I4CLOr crWY2ErnmemXbcx2pyK65W7szdn3HC+H1ICLd5xskPfbcjlvhFlFmD9nzHJVQQ== 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=1724144536; 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=9GdlMqGAxGfXnMzTTO1tv1qYed0AdK0BkFKGi5lBzIs=; b=H1t9Y0jB5+nJxIYozC092cKtaN2x9IVlisHKijn2X79zeT+dJMzVeW8IQVPqFwXDyZ2iKa VIZttzfpifAXFKLB4zQhp9peH78vxfilXdGR1u4soX95/9Pphsuwsc+9w9CLnue+8oLK2p bhCOMwD3Aa4ovoN/yxTPxUviM0zWuzMhUR3p+ELcO/E22FdpJOEdAFu5Y1rJW7K95sYwn1 ikfSqCxKCeDvaCpjqTsGklSgpnY+Pq2CXRBe8YZQvpBHuXzf61/9vPkQkxIUm2fSfXX70r 1ZsxHNJQV4zroHT3cSn7UVgwu28Qj2Yw40W/vUV1mbNFTcclfyK3ioduoC6JHQ== 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 4Wp3Ph49pKztnm; Tue, 20 Aug 2024 09:02:16 +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 47K92GeE078297; Tue, 20 Aug 2024 09:02:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K92GJk078294; Tue, 20 Aug 2024 09:02:16 GMT (envelope-from git) Date: Tue, 20 Aug 2024 09:02:16 GMT Message-Id: <202408200902.47K92GJk078294@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: a745cdc19b7f - main - arm64/vmm: Teach the vtimer about VHE List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: a745cdc19b7f92b490f7c332abad82945f3b06cb Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=a745cdc19b7f92b490f7c332abad82945f3b06cb commit a745cdc19b7f92b490f7c332abad82945f3b06cb Author: Andrew Turner AuthorDate: 2024-08-19 12:43:37 +0000 Commit: Andrew Turner CommitDate: 2024-08-20 08:49:15 +0000 arm64/vmm: Teach the vtimer about VHE Teach the virtual timer about the cnthctl_el2 field layout under VHE. As with non-VHE we need to trap the physical timer and not trap the virtual timer. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46074 --- sys/arm64/include/hypervisor.h | 4 ++++ sys/arm64/vmm/io/vtimer.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/sys/arm64/include/hypervisor.h b/sys/arm64/include/hypervisor.h index 011f86e83fdf..4c501e2722a9 100644 --- a/sys/arm64/include/hypervisor.h +++ b/sys/arm64/include/hypervisor.h @@ -41,6 +41,10 @@ #define CNTHCTL_EL1PCTEN (1 << 0) /* Allow physical counter access */ #define CNTHCTL_EL1PCEN (1 << 1) /* Allow physical timer access */ /* Valid if HCR_EL2.E2H == 1 */ +#define CNTHCTL_E2H_EL0PCTEN (1 << 0) /* Allow EL0 physical counter access */ +#define CNTHCTL_E2H_EL0VCTEN (1 << 1) /* Allow EL0 virtual counter access */ +#define CNTHCTL_E2H_EL0VTEN (1 << 8) +#define CNTHCTL_E2H_EL0PTEN (1 << 9) #define CNTHCTL_E2H_EL1PCTEN (1 << 10) /* Allow physical counter access */ #define CNTHCTL_E2H_EL1PTEN (1 << 11) /* Allow physical timer access */ /* Unconditionally valid */ diff --git a/sys/arm64/vmm/io/vtimer.c b/sys/arm64/vmm/io/vtimer.c index aa0b3ff1588e..f59d7ebc1ad4 100644 --- a/sys/arm64/vmm/io/vtimer.c +++ b/sys/arm64/vmm/io/vtimer.c @@ -129,14 +129,42 @@ vtimer_vminit(struct hyp *hyp) { uint64_t now; + hyp->vtimer.cnthctl_el2 = cnthctl_el2_reg; + /* * Configure the Counter-timer Hypervisor Control Register for the VM. - * - * CNTHCTL_EL1PCEN: trap access to CNTP_{CTL, CVAL, TVAL}_EL0 from EL1 - * CNTHCTL_EL1PCTEN: trap access to CNTPCT_EL0 */ - hyp->vtimer.cnthctl_el2 = cnthctl_el2_reg & ~CNTHCTL_EL1PCEN; - hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_EL1PCTEN; + if (in_vhe()) { + /* + * CNTHCTL_E2H_EL0PCTEN: trap EL0 access to CNTP{CT,CTSS}_EL0 + * CNTHCTL_E2H_EL1VCTEN: don't trap EL0 access to + * CNTV{CT,CTSS}_EL0 + * CNTHCTL_E2H_EL0VTEN: don't trap EL0 access to + * CNTV_{CTL,CVAL,TVAL}_EL0 + * CNTHCTL_E2H_EL0PTEN: trap EL0 access to + * CNTP_{CTL,CVAL,TVAL}_EL0 + * CNTHCTL_E2H_EL1PCEN: trap EL1 access to + CNTP_{CTL,CVAL,TVAL}_EL0 + * CNTHCTL_E2H_EL1PCTEN: trap access to CNTPCT_EL0 + * + * TODO: Don't trap when FEAT_ECV is present + */ + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_E2H_EL0PCTEN; + hyp->vtimer.cnthctl_el2 |= CNTHCTL_E2H_EL0VCTEN; + hyp->vtimer.cnthctl_el2 |= CNTHCTL_E2H_EL0VTEN; + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_E2H_EL0PTEN; + + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_E2H_EL1PTEN; + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_E2H_EL1PCTEN; + } else { + /* + * CNTHCTL_EL1PCEN: trap access to CNTP_{CTL, CVAL, TVAL}_EL0 + * from EL1 + * CNTHCTL_EL1PCTEN: trap access to CNTPCT_EL0 + */ + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_EL1PCEN; + hyp->vtimer.cnthctl_el2 &= ~CNTHCTL_EL1PCTEN; + } now = READ_SPECIALREG(cntpct_el0); hyp->vtimer.cntvoff_el2 = now;