Skip to contentSkip to conversation

arm64: KVM: Guests can skip __install_bp_hardening_cb()s HYP work

PATCH In review James Morse 3 participants 3 messages Sep 21, 2018 – Oct 19, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: KVM: Guests can skip __install_bp_hardening_cb()s HYP work

enable_smccc_arch_workaround_1() passes NULL as the hyp_vecs start and end if the HVC conduit is in use, and ARM_SMCCC_ARCH_WORKAROUND_1 is detected.

If the guest kernel happened to be built with KVM_INDIRECT_VECTORS, we go on to allocate a slot, memcpy() the empty workaround in and do the appropriate cache maintenance.

This works as we always tell memcpy() the range is 0, so it never accesses the NULL src pointer, but we still do the cache maintenance.

If hyp_vecs_start is NULL we know we're a guest, just update the fn like the !KVM_INDIRECT_VECTORS version.

---
 arch/arm64/kernel/cpu_errata.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kernel/cpu_errata.c +9 -0
index dec10898d688..25305f8a8670 100644
@@ -116,6 +116,15 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn,
 	static DEFINE_SPINLOCK(bp_lock);
 	int cpu, slot = -1;
 
+	/*
+	 * enable_smccc_arch_workaround_1() passes NULL for the hyp_vecs
+	 * start/end if we're a guest. Skip the hyp-vectors work.
+	 */
+	if (!hyp_vecs_start) {
+		__this_cpu_write(bp_hardening_data.fn, fn);
+		return;
+	}
+
 	spin_lock(&bp_lock);
 	for_each_possible_cpu(cpu) {
 		if (per_cpu(bp_hardening_data.fn, cpu) == fn) {
Signature · 1 line
2.18.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · James Morse

enable_smccc_arch_workaround_1() passes NULL as the hyp_vecs start and end if the HVC conduit is in use, and ARM_SMCCC_ARCH_WORKAROUND_1 is detected.

If the guest kernel happened to be built with KVM_INDIRECT_VECTORS, we go on to allocate a slot, memcpy() the empty workaround in and do the appropriate cache maintenance.

Quoted 8 lines

This works as we always tell memcpy() the range is 0, so it never accesses the NULL src pointer, but we still do the cache maintenance.

If hyp_vecs_start is NULL we know we're a guest, just update the fn like the !KVM_INDIRECT_VECTORS version.

Catalin: could you sneak this one in for 4.20? It is strictly a KVM patch, but its location makes it more suitable for the arm64 tree...

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
maintainer
#2 lore raw
Quoted 15 lines · Marc Zyngier
Quoted 14 lines · James Morse

enable_smccc_arch_workaround_1() passes NULL as the hyp_vecs start and end if the HVC conduit is in use, and ARM_SMCCC_ARCH_WORKAROUND_1 is detected.

If the guest kernel happened to be built with KVM_INDIRECT_VECTORS, we go on to allocate a slot, memcpy() the empty workaround in and do the appropriate cache maintenance.

This works as we always tell memcpy() the range is 0, so it never accesses the NULL src pointer, but we still do the cache maintenance.

If hyp_vecs_start is NULL we know we're a guest, just update the fn like the !KVM_INDIRECT_VECTORS version.

Quoted 7 lines
Quoted 2 lines

Catalin: could you sneak this one in for 4.20? It is strictly a KVM patch, but its location makes it more suitable for the arm64 tree...

Done.

Signature · 1 line
Catalin