diff mbox series

[4/6] arm64: Factor out checking of a feature against the override into a macro

Message ID 20220627151412.1496361-5-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series arm64: Disabling SVE/SME from the command-line | expand

Commit Message

Marc Zyngier June 27, 2022, 3:14 p.m. UTC
Checking for a feature being supported from assembly code is
a bit tedious if we need to factor in the idreg override.

Since we already have such code written for forcing nVHE, move
the whole thing into a macro. This heavily relies on the override
structure being called foo_override for foo_el1.

No functional change.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kernel/hyp-stub.S | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

Comments

Mark Brown June 28, 2022, 11:28 a.m. UTC | #1
On Mon, Jun 27, 2022 at 04:14:10PM +0100, Marc Zyngier wrote:
> Checking for a feature being supported from assembly code is
> a bit tedious if we need to factor in the idreg override.
> 
> Since we already have such code written for forcing nVHE, move
> the whole thing into a macro. This heavily relies on the override
> structure being called foo_override for foo_el1.

Reviwed-by: Mark Brown <broonie@kernel.org>
Marc Zyngier June 29, 2022, 3:46 p.m. UTC | #2
On Tue, 28 Jun 2022 12:28:32 +0100,
Mark Brown <broonie@kernel.org> wrote:
> 
> On Mon, Jun 27, 2022 at 04:14:10PM +0100, Marc Zyngier wrote:
> > Checking for a feature being supported from assembly code is
> > a bit tedious if we need to factor in the idreg override.
> > 
> > Since we already have such code written for forcing nVHE, move
> > the whole thing into a macro. This heavily relies on the override
> > structure being called foo_override for foo_el1.
> 
> Reviwed-by: Mark Brown <broonie@kernel.org>

Reviewed?

	M.
Mark Brown June 29, 2022, 4 p.m. UTC | #3
On Wed, Jun 29, 2022 at 04:46:55PM +0100, Marc Zyngier wrote:
> On Tue, 28 Jun 2022 12:28:32 +0100,
> Mark Brown <broonie@kernel.org> wrote:
> > 
> > On Mon, Jun 27, 2022 at 04:14:10PM +0100, Marc Zyngier wrote:
> > > Checking for a feature being supported from assembly code is
> > > a bit tedious if we need to factor in the idreg override.
> > > 
> > > Since we already have such code written for forcing nVHE, move
> > > the whole thing into a macro. This heavily relies on the override
> > > structure being called foo_override for foo_el1.
> > 
> > Reviwed-by: Mark Brown <broonie@kernel.org>
> 
> Reviewed?

Yes, sorry.

Reviewed-by: Mark Brown <broonie@kernel.org>
diff mbox series

Patch

diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S
index 26206e53e0c9..4a02a73650db 100644
--- a/arch/arm64/kernel/hyp-stub.S
+++ b/arch/arm64/kernel/hyp-stub.S
@@ -16,6 +16,23 @@ 
 #include <asm/ptrace.h>
 #include <asm/virt.h>
 
+.macro check_override idreg, fld, pass, fail
+	mrs	x1, \idreg\()_el1
+	ubfx	x1, x1, #\fld, #4
+	cbz	x1, \fail
+
+	adr_l	x1, \idreg\()_override
+	ldr	x2, [x1, FTR_OVR_VAL_OFFSET]
+	ldr	x1, [x1, FTR_OVR_MASK_OFFSET]
+	ubfx	x2, x2, #\fld, #4
+	ubfx	x1, x1, #\fld, #4
+	cmp	x1, xzr
+	and	x2, x2, x1
+	csinv	x2, x2, xzr, ne
+	cbnz	x2, \pass
+	b	\fail
+.endm
+
 	.text
 	.pushsection	.hyp.text, "ax"
 
@@ -80,20 +97,7 @@  SYM_CODE_START_LOCAL(__finalise_el2)
 	tbnz	x1, #0, 1f
 
 	// Needs to be VHE capable, obviously
-	mrs	x1, id_aa64mmfr1_el1
-	ubfx	x1, x1, #ID_AA64MMFR1_VHE_SHIFT, #4
-	cbz	x1, 1f
-
-	// Check whether VHE is disabled from the command line
-	adr_l	x1, id_aa64mmfr1_override
-	ldr	x2, [x1, FTR_OVR_VAL_OFFSET]
-	ldr	x1, [x1, FTR_OVR_MASK_OFFSET]
-	ubfx	x2, x2, #ID_AA64MMFR1_VHE_SHIFT, #4
-	ubfx	x1, x1, #ID_AA64MMFR1_VHE_SHIFT, #4
-	cmp	x1, xzr
-	and	x2, x2, x1
-	csinv	x2, x2, xzr, ne
-	cbnz	x2, 2f
+	check_override id_aa64mmfr1 ID_AA64MMFR1_VHE_SHIFT 2f 1f
 
 1:	mov_q	x0, HVC_STUB_ERR
 	eret