On 12/09/18 11:28, James Morse wrote:
On 28/08/18 16:51, Julien Thierry wrote:
The cpu_enable callback for VHE feature requires all alternatives to have
been applied. This prevents applying VHE alternative separately from the
rest.
Use an alternative depending on VHE feature to know whether VHE
alternatives have already been applied.
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 1e433ac..3bc1c8b 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1022,8 +1024,15 @@ static void cpu_copy_el2regs(const struct arm64_cpu_capabilities *__unused)
ÂÂÂÂÂÂ * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to
ÂÂÂÂÂÂ * do anything here.
ÂÂÂÂÂÂ */
-ÂÂÂ if (!alternatives_applied)
-ÂÂÂÂÂÂÂ write_sysreg(read_sysreg(tpidr_el1), tpidr_el2);
+ÂÂÂ asm volatile(ALTERNATIVE(
+ÂÂÂÂÂÂÂ "mrsÂÂÂ %0, tpidr_el1\n"
+ÂÂÂÂÂÂÂ "msrÂÂÂ tpidr_el2, %0",
+ÂÂÂÂÂÂÂ "nop\n"
+ÂÂÂÂÂÂÂ "nop",
+ÂÂÂÂÂÂÂ ARM64_HAS_VIRT_HOST_EXTN)
+ÂÂÂÂÂÂÂ : "+r" (tmp)
+ÂÂÂÂÂÂÂ :
+ÂÂÂÂÂÂÂ : "memory");
 }
 #endif
Catalin's preference was to keep this all in C:
https://patchwork.kernel.org/patch/10007977/
, for which we need to know if 'the' alternative has been applied.
I suspect there may be more registers in this list if we have to switch to
another EL2 register using alternatives. (but I don't have an example).
Could we make 'alternatives_applied' a macro that takes the cap as an argument?
I wanted to do this initially, the issue was that the alternatives framework works on regions to patch rather than caps to apply. So I found it a bit odd to associate the "code corresponding to cap was applied" with the alternative application.