Skip to content

Commit 1c656b1

Browse files
committed
Merge tag 'loongarch-fixes-6.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
Pull LoongArch fixes from Huacai Chen: "Fix a lot of build warnings for LTO-enabled objtool check, increase COMMAND_LINE_SIZE up to 4096, rename a missing GCC_PLUGIN_STACKLEAK to KSTACK_ERASE, and fix some bugs about arch timer, module loading, LBT and KVM" * tag 'loongarch-fixes-6.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson: LoongArch: KVM: Add address alignment check in pch_pic register access LoongArch: KVM: Use kvm_get_vcpu_by_id() instead of kvm_get_vcpu() LoongArch: KVM: Fix stack protector issue in send_ipi_data() LoongArch: KVM: Make function kvm_own_lbt() robust LoongArch: Rename GCC_PLUGIN_STACKLEAK to KSTACK_ERASE LoongArch: Save LBT before FPU in setup_sigcontext() LoongArch: Optimize module load time by optimizing PLT/GOT counting LoongArch: Add cpuhotplug hooks to fix high cpu usage of vCPU threads LoongArch: Increase COMMAND_LINE_SIZE up to 4096 LoongArch: Pass annotate-tablejump option if LTO is enabled objtool/LoongArch: Get table size correctly if LTO is enabled
2 parents 32b7144 + 538c06e commit 1c656b1

File tree

12 files changed

+109
-32
lines changed

12 files changed

+109
-32
lines changed

arch/loongarch/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ KBUILD_CFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)
102102

103103
ifdef CONFIG_OBJTOOL
104104
ifdef CONFIG_CC_HAS_ANNOTATE_TABLEJUMP
105+
# The annotate-tablejump option can not be passed to LLVM backend when LTO is enabled.
106+
# Ensure it is aware of linker with LTO, '--loongarch-annotate-tablejump' also needs to
107+
# be passed via '-mllvm' to ld.lld.
105108
KBUILD_CFLAGS += -mannotate-tablejump
109+
ifdef CONFIG_LTO_CLANG
110+
KBUILD_LDFLAGS += -mllvm --loongarch-annotate-tablejump
111+
endif
106112
else
107113
KBUILD_CFLAGS += -fno-jump-tables # keep compatibility with older compilers
108114
endif

arch/loongarch/include/asm/stackframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
.endm
5959

6060
.macro STACKLEAK_ERASE
61-
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
61+
#ifdef CONFIG_KSTACK_ERASE
6262
bl stackleak_erase_on_task_stack
6363
#endif
6464
.endm
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
3+
#ifndef _UAPI_ASM_LOONGARCH_SETUP_H
4+
#define _UAPI_ASM_LOONGARCH_SETUP_H
5+
6+
#define COMMAND_LINE_SIZE 4096
7+
8+
#endif /* _UAPI_ASM_LOONGARCH_SETUP_H */

arch/loongarch/kernel/module-sections.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/module.h>
99
#include <linux/moduleloader.h>
1010
#include <linux/ftrace.h>
11+
#include <linux/sort.h>
1112

1213
Elf_Addr module_emit_got_entry(struct module *mod, Elf_Shdr *sechdrs, Elf_Addr val)
1314
{
@@ -61,39 +62,38 @@ Elf_Addr module_emit_plt_entry(struct module *mod, Elf_Shdr *sechdrs, Elf_Addr v
6162
return (Elf_Addr)&plt[nr];
6263
}
6364

64-
static int is_rela_equal(const Elf_Rela *x, const Elf_Rela *y)
65-
{
66-
return x->r_info == y->r_info && x->r_addend == y->r_addend;
67-
}
65+
#define cmp_3way(a, b) ((a) < (b) ? -1 : (a) > (b))
6866

69-
static bool duplicate_rela(const Elf_Rela *rela, int idx)
67+
static int compare_rela(const void *x, const void *y)
7068
{
71-
int i;
69+
int ret;
70+
const Elf_Rela *rela_x = x, *rela_y = y;
7271

73-
for (i = 0; i < idx; i++) {
74-
if (is_rela_equal(&rela[i], &rela[idx]))
75-
return true;
76-
}
72+
ret = cmp_3way(rela_x->r_info, rela_y->r_info);
73+
if (ret == 0)
74+
ret = cmp_3way(rela_x->r_addend, rela_y->r_addend);
7775

78-
return false;
76+
return ret;
7977
}
8078

8179
static void count_max_entries(Elf_Rela *relas, int num,
8280
unsigned int *plts, unsigned int *gots)
8381
{
84-
unsigned int i, type;
82+
unsigned int i;
83+
84+
sort(relas, num, sizeof(Elf_Rela), compare_rela, NULL);
8585

8686
for (i = 0; i < num; i++) {
87-
type = ELF_R_TYPE(relas[i].r_info);
88-
switch (type) {
87+
if (i && !compare_rela(&relas[i-1], &relas[i]))
88+
continue;
89+
90+
switch (ELF_R_TYPE(relas[i].r_info)) {
8991
case R_LARCH_SOP_PUSH_PLT_PCREL:
9092
case R_LARCH_B26:
91-
if (!duplicate_rela(relas, i))
92-
(*plts)++;
93+
(*plts)++;
9394
break;
9495
case R_LARCH_GOT_PC_HI20:
95-
if (!duplicate_rela(relas, i))
96-
(*gots)++;
96+
(*gots)++;
9797
break;
9898
default:
9999
break; /* Do nothing. */

arch/loongarch/kernel/signal.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,18 +677,18 @@ static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
677677
for (i = 1; i < 32; i++)
678678
err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
679679

680+
#ifdef CONFIG_CPU_HAS_LBT
681+
if (extctx->lbt.addr)
682+
err |= protected_save_lbt_context(extctx);
683+
#endif
684+
680685
if (extctx->lasx.addr)
681686
err |= protected_save_lasx_context(extctx);
682687
else if (extctx->lsx.addr)
683688
err |= protected_save_lsx_context(extctx);
684689
else if (extctx->fpu.addr)
685690
err |= protected_save_fpu_context(extctx);
686691

687-
#ifdef CONFIG_CPU_HAS_LBT
688-
if (extctx->lbt.addr)
689-
err |= protected_save_lbt_context(extctx);
690-
#endif
691-
692692
/* Set the "end" magic */
693693
info = (struct sctx_info *)extctx->end.addr;
694694
err |= __put_user(0, &info->magic);

arch/loongarch/kernel/time.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
66
*/
77
#include <linux/clockchips.h>
8+
#include <linux/cpuhotplug.h>
89
#include <linux/delay.h>
910
#include <linux/export.h>
1011
#include <linux/init.h>
@@ -102,6 +103,23 @@ static int constant_timer_next_event(unsigned long delta, struct clock_event_dev
102103
return 0;
103104
}
104105

106+
static int arch_timer_starting(unsigned int cpu)
107+
{
108+
set_csr_ecfg(ECFGF_TIMER);
109+
110+
return 0;
111+
}
112+
113+
static int arch_timer_dying(unsigned int cpu)
114+
{
115+
constant_set_state_shutdown(this_cpu_ptr(&constant_clockevent_device));
116+
117+
/* Clear Timer Interrupt */
118+
write_csr_tintclear(CSR_TINTCLR_TI);
119+
120+
return 0;
121+
}
122+
105123
static unsigned long get_loops_per_jiffy(void)
106124
{
107125
unsigned long lpj = (unsigned long)const_clock_freq;
@@ -172,6 +190,10 @@ int constant_clockevent_init(void)
172190
lpj_fine = get_loops_per_jiffy();
173191
pr_info("Constant clock event device register\n");
174192

193+
cpuhp_setup_state(CPUHP_AP_LOONGARCH_ARCH_TIMER_STARTING,
194+
"clockevents/loongarch/timer:starting",
195+
arch_timer_starting, arch_timer_dying);
196+
175197
return 0;
176198
}
177199

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
4545
}
4646

4747
cpu = s->sw_coremap[irq];
48-
vcpu = kvm_get_vcpu(s->kvm, cpu);
48+
vcpu = kvm_get_vcpu_by_id(s->kvm, cpu);
49+
if (unlikely(vcpu == NULL)) {
50+
kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
51+
return;
52+
}
53+
4954
if (level) {
5055
/* if not enable return false */
5156
if (!test_bit(irq, (unsigned long *)s->enable.reg_u32))

arch/loongarch/kvm/intc/ipi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void write_mailbox(struct kvm_vcpu *vcpu, int offset, uint64_t data, int
9999
static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
100100
{
101101
int i, idx, ret;
102-
uint32_t val = 0, mask = 0;
102+
uint64_t val = 0, mask = 0;
103103

104104
/*
105105
* Bit 27-30 is mask for byte writing.
@@ -108,7 +108,7 @@ static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
108108
if ((data >> 27) & 0xf) {
109109
/* Read the old val */
110110
idx = srcu_read_lock(&vcpu->kvm->srcu);
111-
ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, sizeof(val), &val);
111+
ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, 4, &val);
112112
srcu_read_unlock(&vcpu->kvm->srcu, idx);
113113
if (unlikely(ret)) {
114114
kvm_err("%s: : read data from addr %llx failed\n", __func__, addr);
@@ -124,7 +124,7 @@ static int send_ipi_data(struct kvm_vcpu *vcpu, gpa_t addr, uint64_t data)
124124
}
125125
val |= ((uint32_t)(data >> 32) & ~mask);
126126
idx = srcu_read_lock(&vcpu->kvm->srcu);
127-
ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, sizeof(val), &val);
127+
ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, 4, &val);
128128
srcu_read_unlock(&vcpu->kvm->srcu, idx);
129129
if (unlikely(ret))
130130
kvm_err("%s: : write data to addr %llx failed\n", __func__, addr);
@@ -298,7 +298,7 @@ static int kvm_ipi_regs_access(struct kvm_device *dev,
298298
cpu = (attr->attr >> 16) & 0x3ff;
299299
addr = attr->attr & 0xff;
300300

301-
vcpu = kvm_get_vcpu(dev->kvm, cpu);
301+
vcpu = kvm_get_vcpu_by_id(dev->kvm, cpu);
302302
if (unlikely(vcpu == NULL)) {
303303
kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
304304
return -EINVAL;

arch/loongarch/kvm/intc/pch_pic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ static int kvm_pch_pic_read(struct kvm_vcpu *vcpu,
195195
return -EINVAL;
196196
}
197197

198+
if (addr & (len - 1)) {
199+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
200+
return -EINVAL;
201+
}
202+
198203
/* statistics of pch pic reading */
199204
vcpu->stat.pch_pic_read_exits++;
200205
ret = loongarch_pch_pic_read(s, addr, len, val);
@@ -302,6 +307,11 @@ static int kvm_pch_pic_write(struct kvm_vcpu *vcpu,
302307
return -EINVAL;
303308
}
304309

310+
if (addr & (len - 1)) {
311+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
312+
return -EINVAL;
313+
}
314+
305315
/* statistics of pch pic writing */
306316
vcpu->stat.pch_pic_write_exits++;
307317
ret = loongarch_pch_pic_write(s, addr, len, val);

arch/loongarch/kvm/vcpu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,9 +1283,11 @@ int kvm_own_lbt(struct kvm_vcpu *vcpu)
12831283
return -EINVAL;
12841284

12851285
preempt_disable();
1286-
set_csr_euen(CSR_EUEN_LBTEN);
1287-
_restore_lbt(&vcpu->arch.lbt);
1288-
vcpu->arch.aux_inuse |= KVM_LARCH_LBT;
1286+
if (!(vcpu->arch.aux_inuse & KVM_LARCH_LBT)) {
1287+
set_csr_euen(CSR_EUEN_LBTEN);
1288+
_restore_lbt(&vcpu->arch.lbt);
1289+
vcpu->arch.aux_inuse |= KVM_LARCH_LBT;
1290+
}
12891291
preempt_enable();
12901292

12911293
return 0;

0 commit comments

Comments
 (0)