From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60CF217B425 for ; Fri, 16 May 2025 09:28:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747387739; cv=none; b=RP1FAf3grYsyuRg523/fiBy6T12yORvG5C1ly80y778TIMUNKyoOkyXHSFgIw3xmGdMj4ZFnmcAkDBKG35CHlLHoHTz+ngIFgU1MjZofuLe6xXHuAtsTGBLGlDYu8uX4Iakg5g0WwDMvmSgqJqK2AcvztL94K1d6aF6iN+soYBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747387739; c=relaxed/simple; bh=C1cSy2xki2wOWUPUW6I0rnyp/Sf3WYwzapviu29pDzI=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=PzCf2dc20r3riIDP2j4i+VTdfcRVv/PK7SN7hYFfQ+UOqjKxLI9umYQDrddZ5bAa2TwwFD1VpH1G2Wxnhr/CiGSjNiO0dWrML87O92vGihYA7+HrB04O3E2UAvjgB/nm7uftP4lVo6odZ3E7dtkbDmEKnZ8ELN+VxbHFSUn3nnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pMoRjdwE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pMoRjdwE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6567C4CEE4; Fri, 16 May 2025 09:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747387738; bh=C1cSy2xki2wOWUPUW6I0rnyp/Sf3WYwzapviu29pDzI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pMoRjdwEZOifjh9RLx4oKclSMQBYE2awSKuA283WPcrDrh7dfsFNwEDomiLpDWYce 2cTzVGmNcC+u5MCSy6w+ECCpum5y3zt+8Ve1O8JuJX043PuyQwk00Fi6/srzUaCm+c cP+qp+SyfuDVpVZT9UXKivzba1NVbHOQttOodqGvTDQ82ohlsgp5rbD/WAGs1J56EN 6XXAbgte/IpCmA0Yz831Dxc9C5RRvgWe51Qyn7PMKed9VFHmcFgTLP/d76amFMraoi a2P1JtfJm2Xttdn4i1PXaLhFWtgkPzFGXcOkdbLHKLLpqyPw8w+IoMRape0mlLg82f 0jj3A1HmU6UNQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uFrNA-00FVXj-EC; Fri, 16 May 2025 10:28:56 +0100 Date: Fri, 16 May 2025 10:28:56 +0100 Message-ID: <86frh4gazr.wl-maz@kernel.org> From: Marc Zyngier To: Youngmin Nam Cc: Mark Rutland , Daniel Lezcano , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, junhosj.choi@samsung.com, hajun.sung@samsung.com, joonki.min@samsung.com, d7271.choe@samsung.com, jkkkkk.choi@samsung.com, jt1217.kim@samsung.com, qperret@google.com, willdeacon@google.com, dhyun.cha@samsung.com, kn_hong.choi@samsung.com, mankyum.kim@samsung.com Subject: Re: [QUESTION] arch_counter_register() restricts CNTPT access when booted in EL1, even if EL2 is supported In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: youngmin.nam@samsung.com, mark.rutland@arm.com, daniel.lezcano@linaro.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, junhosj.choi@samsung.com, hajun.sung@samsung.com, joonki.min@samsung.com, d7271.choe@samsung.com, jkkkkk.choi@samsung.com, jt1217.kim@samsung.com, qperret@google.com, willdeacon@google.com, dhyun.cha@samsung.com, kn_hong.choi@samsung.com, mankyum.kim@samsung.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 16 May 2025 07:53:58 +0100, Youngmin Nam wrote: >=20 > [1 ] > Hi arm arch timer experts, >=20 > While reviewing the arm_arch_timer code in Linux 6.12, > I noticed that the function arch_counter_register() restricts the > use of the physical counter (cntpct_el0) on systems where the kernel > is running in EL1, even if EL2 is supported and cntpct_el0 is > accessible. >=20 > In our case: > - We are not using pKVM. > - The kernel is booted in EL1. > - We disabled VIRT_PPI and explicitly selected PHYS_NONSECURE_PPI for the= timer refering to below code. That's not legal. The architecture guarantees that there is a virtual timer and a physical timer. No ifs, no buts. [...] > As I understand it, `is_hyp_mode_available()` checks whether the > kernel booted into EL2 =E2=80=94 not whether EL2 is *supported* by the > hardware. >=20 > Therefore, even on systems where EL2 exists and `cntpct_el0` is > accessible from EL1, the kernel still forces the use of `cntvct_el0` > if the boot EL is EL1. Yes, because it isn't architecturally valid to not have a virtual timer. This isn't about EL2 being present of not. The switch to the physical timer is purely an optimisation for KVM so that it doesn't have to switch the virtual timer back and forth when running a guest, as the virtual timer is the most likely used timer. > Is this restriction to `cntvct_el0` in EL1 an architectural > requirement, or simply a conservative default to avoid possible > traps on some systems? Both. Crucially, it isn't possible to trap the virtual timer on some older implementations. > If the hardware clearly supports EL2 and allows CNTPT access from > EL1, could this restriction be relaxed? Absolutely not. Having the virtual timer is a hard requirement from both the architecture *and* Linux. Feel free to emulate it from EL2 if you want (and can trap it). Thanks, M. --=20 Without deviation from the norm, progress is not possible.