Skip to content

Commit 0492747

Browse files
Sebastian Andrzej Siewiorctmarinas
authored andcommitted
arm64: KVM: Invoke compute_layout() before alternatives are applied
compute_layout() is invoked as part of an alternative fixup under stop_machine(). This function invokes get_random_long() which acquires a sleeping lock on -RT which can not be acquired in this context. Rename compute_layout() to kvm_compute_layout() and invoke it before stop_machine() applies the alternatives. Add a __init prefix to kvm_compute_layout() because the caller has it, too (and so the code can be discarded after boot). Reviewed-by: James Morse <[email protected]> Acked-by: Marc Zyngier <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent df325e0 commit 0492747

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ alternative_cb_end
9191

9292
void kvm_update_va_mask(struct alt_instr *alt,
9393
__le32 *origptr, __le32 *updptr, int nr_inst);
94+
void kvm_compute_layout(void);
9495

9596
static inline unsigned long __kern_hyp_va(unsigned long v)
9697
{

arch/arm64/kernel/smp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/of.h>
3232
#include <linux/irq_work.h>
3333
#include <linux/kexec.h>
34+
#include <linux/kvm_host.h>
3435

3536
#include <asm/alternative.h>
3637
#include <asm/atomic.h>
@@ -39,6 +40,7 @@
3940
#include <asm/cputype.h>
4041
#include <asm/cpu_ops.h>
4142
#include <asm/daifflags.h>
43+
#include <asm/kvm_mmu.h>
4244
#include <asm/mmu_context.h>
4345
#include <asm/numa.h>
4446
#include <asm/pgtable.h>
@@ -408,6 +410,8 @@ static void __init hyp_mode_check(void)
408410
"CPU: CPUs started in inconsistent modes");
409411
else
410412
pr_info("CPU: All CPU(s) started at EL1\n");
413+
if (IS_ENABLED(CONFIG_KVM_ARM_HOST))
414+
kvm_compute_layout();
411415
}
412416

413417
void __init smp_cpus_done(unsigned int max_cpus)

arch/arm64/kvm/va_layout.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static u8 tag_lsb;
2222
static u64 tag_val;
2323
static u64 va_mask;
2424

25-
static void compute_layout(void)
25+
__init void kvm_compute_layout(void)
2626
{
2727
phys_addr_t idmap_addr = __pa_symbol(__hyp_idmap_text_start);
2828
u64 hyp_va_msb;
@@ -110,9 +110,6 @@ void __init kvm_update_va_mask(struct alt_instr *alt,
110110

111111
BUG_ON(nr_inst != 5);
112112

113-
if (!has_vhe() && !va_mask)
114-
compute_layout();
115-
116113
for (i = 0; i < nr_inst; i++) {
117114
u32 rd, rn, insn, oinsn;
118115

@@ -156,9 +153,6 @@ void kvm_patch_vector_branch(struct alt_instr *alt,
156153
return;
157154
}
158155

159-
if (!va_mask)
160-
compute_layout();
161-
162156
/*
163157
* Compute HYP VA by using the same computation as kern_hyp_va()
164158
*/

0 commit comments

Comments
 (0)