Skip to content

Commit 5076001

Browse files
committed
Merge tag 'loongarch-fixes-6.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
Pull LoongArch fixes from Huacai Chen: "Fix bugs about EFI screen info, hugetlb pte clear and Lockdep-RCU splat in KVM, plus some trival cleanups" * tag 'loongarch-fixes-6.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson: LoongArch: KVM: Protect kvm_io_bus_{read,write}() with SRCU LoongArch: KVM: Protect kvm_check_requests() with SRCU LoongArch: BPF: Adjust the parameter of emit_jirl() LoongArch: Add architecture specific huge_pte_clear() LoongArch/irq: Use seq_put_decimal_ull_width() for decimal values LoongArch: Fix reserving screen info memory for above-4G firmware
2 parents 0769a8f + 7f71507 commit 5076001

File tree

9 files changed

+56
-19
lines changed

9 files changed

+56
-19
lines changed

arch/loongarch/include/asm/hugetlb.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ static inline int prepare_hugepage_range(struct file *file,
2424
return 0;
2525
}
2626

27+
#define __HAVE_ARCH_HUGE_PTE_CLEAR
28+
static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
29+
pte_t *ptep, unsigned long sz)
30+
{
31+
pte_t clear;
32+
33+
pte_val(clear) = (unsigned long)invalid_pte_table;
34+
set_pte_at(mm, addr, ptep, clear);
35+
}
36+
2737
#define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
2838
static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
2939
unsigned long addr, pte_t *ptep)

arch/loongarch/include/asm/inst.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,17 @@ DEF_EMIT_REG2I16_FORMAT(blt, blt_op)
683683
DEF_EMIT_REG2I16_FORMAT(bge, bge_op)
684684
DEF_EMIT_REG2I16_FORMAT(bltu, bltu_op)
685685
DEF_EMIT_REG2I16_FORMAT(bgeu, bgeu_op)
686-
DEF_EMIT_REG2I16_FORMAT(jirl, jirl_op)
686+
687+
static inline void emit_jirl(union loongarch_instruction *insn,
688+
enum loongarch_gpr rd,
689+
enum loongarch_gpr rj,
690+
int offset)
691+
{
692+
insn->reg2i16_format.opcode = jirl_op;
693+
insn->reg2i16_format.immediate = offset;
694+
insn->reg2i16_format.rd = rd;
695+
insn->reg2i16_format.rj = rj;
696+
}
687697

688698
#define DEF_EMIT_REG2BSTRD_FORMAT(NAME, OP) \
689699
static inline void emit_##NAME(union loongarch_instruction *insn, \

arch/loongarch/kernel/efi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void __init init_screen_info(void)
9595
memset(si, 0, sizeof(*si));
9696
early_memunmap(si, sizeof(*si));
9797

98-
memblock_reserve(screen_info.lfb_base, screen_info.lfb_size);
98+
memblock_reserve(__screen_info_lfb_base(&screen_info), screen_info.lfb_size);
9999
}
100100

101101
void __init efi_init(void)

arch/loongarch/kernel/inst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
332332
return INSN_BREAK;
333333
}
334334

335-
emit_jirl(&insn, rj, rd, imm >> 2);
335+
emit_jirl(&insn, rd, rj, imm >> 2);
336336

337337
return insn.word;
338338
}

arch/loongarch/kernel/smp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void show_ipi_list(struct seq_file *p, int prec)
8282
for (i = 0; i < NR_IPI; i++) {
8383
seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i, prec >= 4 ? " " : "");
8484
for_each_online_cpu(cpu)
85-
seq_printf(p, "%10u ", per_cpu(irq_stat, cpu).ipi_irqs[i]);
85+
seq_put_decimal_ull_width(p, " ", per_cpu(irq_stat, cpu).ipi_irqs[i], 10);
8686
seq_printf(p, " LoongArch %d %s\n", i + 1, ipi_types[i]);
8787
}
8888
}

arch/loongarch/kvm/exit.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int kvm_handle_csr(struct kvm_vcpu *vcpu, larch_inst inst)
156156

157157
int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu)
158158
{
159-
int ret;
159+
int idx, ret;
160160
unsigned long *val;
161161
u32 addr, rd, rj, opcode;
162162

@@ -167,7 +167,6 @@ int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu)
167167
rj = inst.reg2_format.rj;
168168
opcode = inst.reg2_format.opcode;
169169
addr = vcpu->arch.gprs[rj];
170-
ret = EMULATE_DO_IOCSR;
171170
run->iocsr_io.phys_addr = addr;
172171
run->iocsr_io.is_write = 0;
173172
val = &vcpu->arch.gprs[rd];
@@ -207,20 +206,28 @@ int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu)
207206
}
208207

209208
if (run->iocsr_io.is_write) {
210-
if (!kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val))
209+
idx = srcu_read_lock(&vcpu->kvm->srcu);
210+
ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val);
211+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
212+
if (ret == 0)
211213
ret = EMULATE_DONE;
212-
else
214+
else {
215+
ret = EMULATE_DO_IOCSR;
213216
/* Save data and let user space to write it */
214217
memcpy(run->iocsr_io.data, val, run->iocsr_io.len);
215-
218+
}
216219
trace_kvm_iocsr(KVM_TRACE_IOCSR_WRITE, run->iocsr_io.len, addr, val);
217220
} else {
218-
if (!kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val))
221+
idx = srcu_read_lock(&vcpu->kvm->srcu);
222+
ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val);
223+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
224+
if (ret == 0)
219225
ret = EMULATE_DONE;
220-
else
226+
else {
227+
ret = EMULATE_DO_IOCSR;
221228
/* Save register id for iocsr read completion */
222229
vcpu->arch.io_gpr = rd;
223-
230+
}
224231
trace_kvm_iocsr(KVM_TRACE_IOCSR_READ, run->iocsr_io.len, addr, NULL);
225232
}
226233

@@ -359,7 +366,7 @@ static int kvm_handle_gspr(struct kvm_vcpu *vcpu)
359366

360367
int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst)
361368
{
362-
int ret;
369+
int idx, ret;
363370
unsigned int op8, opcode, rd;
364371
struct kvm_run *run = vcpu->run;
365372

@@ -464,8 +471,10 @@ int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst)
464471
* it need not return to user space to handle the mmio
465472
* exception.
466473
*/
474+
idx = srcu_read_lock(&vcpu->kvm->srcu);
467475
ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, vcpu->arch.badv,
468476
run->mmio.len, &vcpu->arch.gprs[rd]);
477+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
469478
if (!ret) {
470479
update_pc(&vcpu->arch);
471480
vcpu->mmio_needed = 0;
@@ -531,7 +540,7 @@ int kvm_complete_mmio_read(struct kvm_vcpu *vcpu, struct kvm_run *run)
531540

532541
int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst)
533542
{
534-
int ret;
543+
int idx, ret;
535544
unsigned int rd, op8, opcode;
536545
unsigned long curr_pc, rd_val = 0;
537546
struct kvm_run *run = vcpu->run;
@@ -631,7 +640,9 @@ int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst)
631640
* it need not return to user space to handle the mmio
632641
* exception.
633642
*/
643+
idx = srcu_read_lock(&vcpu->kvm->srcu);
634644
ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, vcpu->arch.badv, run->mmio.len, data);
645+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
635646
if (!ret)
636647
return EMULATE_DONE;
637648

arch/loongarch/kvm/intc/ipi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void write_mailbox(struct kvm_vcpu *vcpu, int offset, uint64_t data, int
9898

9999
static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
100100
{
101-
int i, ret;
101+
int i, idx, ret;
102102
uint32_t val = 0, mask = 0;
103103

104104
/*
@@ -107,7 +107,9 @@ static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
107107
*/
108108
if ((data >> 27) & 0xf) {
109109
/* Read the old val */
110+
idx = srcu_read_lock(&vcpu->kvm->srcu);
110111
ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, sizeof(val), &val);
112+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
111113
if (unlikely(ret)) {
112114
kvm_err("%s: : read date from addr %llx failed\n", __func__, addr);
113115
return ret;
@@ -121,7 +123,9 @@ static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
121123
val &= mask;
122124
}
123125
val |= ((uint32_t)(data >> 32) & ~mask);
126+
idx = srcu_read_lock(&vcpu->kvm->srcu);
124127
ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, sizeof(val), &val);
128+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
125129
if (unlikely(ret))
126130
kvm_err("%s: : write date to addr %llx failed\n", __func__, addr);
127131

arch/loongarch/kvm/vcpu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void kvm_late_check_requests(struct kvm_vcpu *vcpu)
240240
*/
241241
static int kvm_enter_guest_check(struct kvm_vcpu *vcpu)
242242
{
243-
int ret;
243+
int idx, ret;
244244

245245
/*
246246
* Check conditions before entering the guest
@@ -249,7 +249,9 @@ static int kvm_enter_guest_check(struct kvm_vcpu *vcpu)
249249
if (ret < 0)
250250
return ret;
251251

252+
idx = srcu_read_lock(&vcpu->kvm->srcu);
252253
ret = kvm_check_requests(vcpu);
254+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
253255

254256
return ret;
255257
}

arch/loongarch/net/bpf_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ static void __build_epilogue(struct jit_ctx *ctx, bool is_tail_call)
181181
/* Set return value */
182182
emit_insn(ctx, addiw, LOONGARCH_GPR_A0, regmap[BPF_REG_0], 0);
183183
/* Return to the caller */
184-
emit_insn(ctx, jirl, LOONGARCH_GPR_RA, LOONGARCH_GPR_ZERO, 0);
184+
emit_insn(ctx, jirl, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_RA, 0);
185185
} else {
186186
/*
187187
* Call the next bpf prog and skip the first instruction
188188
* of TCC initialization.
189189
*/
190-
emit_insn(ctx, jirl, LOONGARCH_GPR_T3, LOONGARCH_GPR_ZERO, 1);
190+
emit_insn(ctx, jirl, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_T3, 1);
191191
}
192192
}
193193

@@ -904,7 +904,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
904904
return ret;
905905

906906
move_addr(ctx, t1, func_addr);
907-
emit_insn(ctx, jirl, t1, LOONGARCH_GPR_RA, 0);
907+
emit_insn(ctx, jirl, LOONGARCH_GPR_RA, t1, 0);
908908
move_reg(ctx, regmap[BPF_REG_0], LOONGARCH_GPR_A0);
909909
break;
910910

0 commit comments

Comments
 (0)