mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
Merge tag 'loongarch-fixes-7.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
Pull LoongArch fixes from Huacai Chen: "Fix several bugs in ACPI IOVT, KEXEC, Hibernation, BPF JIT and KVM" * tag 'loongarch-fixes-7.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson: LoongArch: KVM: Reject repeated PCH-PIC CTRL_INIT LoongArch: KVM: Propagate real error code in kvm_pch_pic_create() LoongArch: KVM: Clear device pointer in irqchip destroy callbacks LoongArch: BPF: Make use of beqz and bnez for trampoline branches LoongArch: BPF: Make arena support depend on 128-bit cmpxchg LoongArch: Restore KFENCE pages through DMW on resume LoongArch: kexec_file: Fix elf_headers memory leak in retry loop LoongArch: kexec_file: Fix a modified cmdline leak ACPI: LoongArch: Validate ACPI IOVT device entries ACPI: LoongArch: Add checksum validation for ACPI IOVT table ACPI: LoongArch: Fix incorrect pointer in acpi_iovt_init()
This commit is contained in:
@@ -535,6 +535,8 @@ u32 larch_insn_gen_lu32id(enum loongarch_gpr rd, int imm);
|
||||
u32 larch_insn_gen_lu52id(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm);
|
||||
u32 larch_insn_gen_beq(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm);
|
||||
u32 larch_insn_gen_bne(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm);
|
||||
u32 larch_insn_gen_beqz(enum loongarch_gpr rj, int imm);
|
||||
u32 larch_insn_gen_bnez(enum loongarch_gpr rj, int imm);
|
||||
u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm);
|
||||
|
||||
static inline bool signed_imm_check(long val, unsigned int bit)
|
||||
@@ -592,6 +594,25 @@ DEF_EMIT_REG1I20_FORMAT(lu12iw, lu12iw_op)
|
||||
DEF_EMIT_REG1I20_FORMAT(lu32id, lu32id_op)
|
||||
DEF_EMIT_REG1I20_FORMAT(pcaddu18i, pcaddu18i_op)
|
||||
|
||||
#define DEF_EMIT_REG1I21_FORMAT(NAME, OP) \
|
||||
static inline void emit_##NAME(union loongarch_instruction *insn, \
|
||||
enum loongarch_gpr rj, int offset) \
|
||||
{ \
|
||||
unsigned int immediate_l, immediate_h; \
|
||||
\
|
||||
immediate_l = offset & 0xffff; \
|
||||
offset >>= 16; \
|
||||
immediate_h = offset & 0x1f; \
|
||||
\
|
||||
insn->reg1i21_format.opcode = OP; \
|
||||
insn->reg1i21_format.immediate_l = immediate_l; \
|
||||
insn->reg1i21_format.rj = rj; \
|
||||
insn->reg1i21_format.immediate_h = immediate_h; \
|
||||
}
|
||||
|
||||
DEF_EMIT_REG1I21_FORMAT(beqz, beqz_op)
|
||||
DEF_EMIT_REG1I21_FORMAT(bnez, bnez_op)
|
||||
|
||||
#define DEF_EMIT_REG2_FORMAT(NAME, OP) \
|
||||
static inline void emit_##NAME(union loongarch_instruction *insn, \
|
||||
enum loongarch_gpr rd, \
|
||||
|
||||
@@ -428,6 +428,34 @@ u32 larch_insn_gen_bne(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
|
||||
return insn.word;
|
||||
}
|
||||
|
||||
u32 larch_insn_gen_beqz(enum loongarch_gpr rj, int imm)
|
||||
{
|
||||
union loongarch_instruction insn;
|
||||
|
||||
if ((imm & 3) || imm < -SZ_4M || imm >= SZ_4M) {
|
||||
pr_warn("The generated beqz instruction is out of range.\n");
|
||||
return INSN_BREAK;
|
||||
}
|
||||
|
||||
emit_beqz(&insn, rj, imm >> 2);
|
||||
|
||||
return insn.word;
|
||||
}
|
||||
|
||||
u32 larch_insn_gen_bnez(enum loongarch_gpr rj, int imm)
|
||||
{
|
||||
union loongarch_instruction insn;
|
||||
|
||||
if ((imm & 3) || imm < -SZ_4M || imm >= SZ_4M) {
|
||||
pr_warn("The generated bnez instruction is out of range.\n");
|
||||
return INSN_BREAK;
|
||||
}
|
||||
|
||||
emit_bnez(&insn, rj, imm >> 2);
|
||||
|
||||
return insn.word;
|
||||
}
|
||||
|
||||
u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm)
|
||||
{
|
||||
union loongarch_instruction insn;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/of_fdt.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/sched/task_stack.h>
|
||||
|
||||
@@ -56,6 +57,7 @@ int machine_kexec_prepare(struct kimage *kimage)
|
||||
*/
|
||||
memcpy((void *)KEXEC_CMDLINE_ADDR, (void *)kimage->arch.cmdline_ptr,
|
||||
strlen((char *)kimage->arch.cmdline_ptr) + 1);
|
||||
kfree((void *)kimage->arch.cmdline_ptr);
|
||||
kimage->arch.cmdline_ptr = (unsigned long)KEXEC_CMDLINE_ADDR;
|
||||
} else {
|
||||
/* Find the command line */
|
||||
|
||||
@@ -166,6 +166,10 @@ int load_other_segments(struct kimage *image,
|
||||
vfree(headers);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
if (unlikely(image->elf_headers))
|
||||
vfree(image->elf_headers);
|
||||
|
||||
image->elf_headers = headers;
|
||||
image->elf_load_addr = kbuf.mem;
|
||||
image->elf_headers_sz = headers_sz;
|
||||
|
||||
@@ -146,6 +146,7 @@ static void kvm_dmsintc_destroy(struct kvm_device *dev)
|
||||
return;
|
||||
|
||||
kfree(dev->kvm->arch.dmsintc);
|
||||
dev->kvm->arch.dmsintc = NULL;
|
||||
kfree(dev);
|
||||
}
|
||||
|
||||
|
||||
@@ -675,6 +675,7 @@ static void kvm_eiointc_destroy(struct kvm_device *dev)
|
||||
|
||||
kvm = dev->kvm;
|
||||
eiointc = kvm->arch.eiointc;
|
||||
kvm->arch.eiointc = NULL;
|
||||
mutex_lock(&kvm->slots_lock);
|
||||
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device);
|
||||
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device_vext);
|
||||
|
||||
@@ -441,6 +441,7 @@ static void kvm_ipi_destroy(struct kvm_device *dev)
|
||||
|
||||
kvm = dev->kvm;
|
||||
ipi = kvm->arch.ipi;
|
||||
kvm->arch.ipi = NULL;
|
||||
mutex_lock(&kvm->slots_lock);
|
||||
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &ipi->device);
|
||||
mutex_unlock(&kvm->slots_lock);
|
||||
|
||||
@@ -281,16 +281,25 @@ static int kvm_pch_pic_init(struct kvm_device *dev, u64 addr)
|
||||
struct kvm_io_device *device;
|
||||
struct loongarch_pch_pic *s = dev->kvm->arch.pch_pic;
|
||||
|
||||
s->pch_pic_base = addr;
|
||||
device = &s->device;
|
||||
mutex_lock(&kvm->slots_lock);
|
||||
if (s->device.ops) {
|
||||
ret = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
s->pch_pic_base = addr;
|
||||
/* init device by pch pic writing and reading ops */
|
||||
kvm_iodevice_init(device, &kvm_pch_pic_ops);
|
||||
mutex_lock(&kvm->slots_lock);
|
||||
/* register pch pic device */
|
||||
ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, addr, PCH_PIC_SIZE, device);
|
||||
if (ret) {
|
||||
s->pch_pic_base = 0;
|
||||
s->device.ops = NULL;
|
||||
}
|
||||
out:
|
||||
mutex_unlock(&kvm->slots_lock);
|
||||
|
||||
return (ret < 0) ? -EFAULT : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* used by user space to get or set pch pic registers */
|
||||
@@ -444,7 +453,7 @@ static int kvm_pch_pic_create(struct kvm_device *dev, u32 type)
|
||||
|
||||
ret = kvm_setup_default_irq_routing(kvm);
|
||||
if (ret)
|
||||
return -ENOMEM;
|
||||
return ret;
|
||||
|
||||
s = kzalloc_obj(struct loongarch_pch_pic);
|
||||
if (!s)
|
||||
@@ -483,6 +492,7 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)
|
||||
|
||||
kvm = dev->kvm;
|
||||
s = kvm->arch.pch_pic;
|
||||
kvm->arch.pch_pic = NULL;
|
||||
/* unregister pch pic device and free it's memory */
|
||||
mutex_lock(&kvm->slots_lock);
|
||||
kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device);
|
||||
|
||||
@@ -1819,7 +1819,7 @@ static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_image *im,
|
||||
/* update branch with beqz */
|
||||
if (ctx->image) {
|
||||
int offset = (void *)(&ctx->image[ctx->idx]) - (void *)branch;
|
||||
*branch = larch_insn_gen_beq(LOONGARCH_GPR_A0, LOONGARCH_GPR_ZERO, offset);
|
||||
*branch = larch_insn_gen_beqz(LOONGARCH_GPR_A0, offset);
|
||||
}
|
||||
|
||||
/* arg1: prog */
|
||||
@@ -2132,9 +2132,10 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
|
||||
emit_insn(ctx, std, regmap[BPF_REG_0], LOONGARCH_GPR_FP, -(retval_off - 8));
|
||||
}
|
||||
|
||||
/* update branches with bnez */
|
||||
for (i = 0; ctx->image && i < fmod_ret->nr_nodes; i++) {
|
||||
int offset = (void *)(&ctx->image[ctx->idx]) - (void *)branches[i];
|
||||
*branches[i] = larch_insn_gen_bne(LOONGARCH_GPR_T1, LOONGARCH_GPR_ZERO, offset);
|
||||
*branches[i] = larch_insn_gen_bnez(LOONGARCH_GPR_T1, offset);
|
||||
}
|
||||
|
||||
/* Set "is_return" flag for fsession */
|
||||
@@ -2489,7 +2490,16 @@ bool bpf_jit_bypass_spec_v4(void)
|
||||
|
||||
bool bpf_jit_supports_arena(void)
|
||||
{
|
||||
return true;
|
||||
/*
|
||||
* The arena range tree uses kmalloc_nolock(), which requires
|
||||
* 128-bit atomic cmpxchg; this is provided by not only hardware
|
||||
* SCQ extension but also assembler support on LoongArch.
|
||||
*/
|
||||
#ifdef system_has_cmpxchg128
|
||||
return system_has_cmpxchg128();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bpf_jit_supports_fsession(void)
|
||||
|
||||
@@ -59,6 +59,12 @@ extern int swsusp_asm_resume(void);
|
||||
|
||||
int swsusp_arch_resume(void)
|
||||
{
|
||||
#ifdef CONFIG_KFENCE
|
||||
struct pbe *pbe;
|
||||
|
||||
for (pbe = restore_pblist; pbe; pbe = pbe->next)
|
||||
pbe->orig_address = __va(virt_to_phys(pbe->orig_address));
|
||||
#endif
|
||||
/* Avoid TLB mismatch during and after kernel resume */
|
||||
local_flush_tlb_all();
|
||||
return swsusp_asm_resume();
|
||||
|
||||
@@ -18,9 +18,20 @@ struct iovt_fwnode {
|
||||
struct list_head ep_list;
|
||||
};
|
||||
|
||||
static bool checksum_valid;
|
||||
static LIST_HEAD(iovt_fwnode_list);
|
||||
static DEFINE_SPINLOCK(iovt_fwnode_lock);
|
||||
|
||||
static u8 acpi_iovt_checksum(u8 *buffer, u32 len)
|
||||
{
|
||||
u8 sum = 0, *end = buffer + len;
|
||||
|
||||
while (buffer < end)
|
||||
sum += *buffer++;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu)
|
||||
{
|
||||
@@ -73,10 +84,43 @@ static int __init iovt_get_pci_iommu_fwnode(struct iovt_fwnode *np, u16 segment,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init iovt_validate_entries(struct acpi_iovt_iommu *iommu)
|
||||
{
|
||||
int i, done = 1;
|
||||
struct acpi_iovt_device_entry *ep;
|
||||
|
||||
ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_entry_offset);
|
||||
for (i = 0; i < iommu->device_entry_num; i++) {
|
||||
switch (ep->type) {
|
||||
case ACPI_IOVT_DEVICE_ENTRY_START:
|
||||
if (!done)
|
||||
return -EINVAL;
|
||||
|
||||
done = 0;
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_END:
|
||||
if (done)
|
||||
return -EINVAL;
|
||||
|
||||
done = 1;
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_SINGLE:
|
||||
default: /* Reserved for future */
|
||||
if (!done)
|
||||
return -EINVAL;
|
||||
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, ep, ep->length);
|
||||
}
|
||||
|
||||
return done ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu)
|
||||
{
|
||||
int i, ret;
|
||||
bool is_start = false;
|
||||
struct iovt_fwnode *np;
|
||||
struct iovt_device_entry *entry;
|
||||
struct acpi_iovt_device_entry *ep;
|
||||
@@ -110,23 +154,24 @@ static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu)
|
||||
if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT)
|
||||
goto skip;
|
||||
|
||||
if (iovt_validate_entries(iommu) < 0) {
|
||||
kfree(np);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&np->ep_list);
|
||||
ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_entry_offset);
|
||||
for (i = 0; i < iommu->device_entry_num; i++) {
|
||||
switch (ep->type) {
|
||||
case ACPI_IOVT_DEVICE_ENTRY_START:
|
||||
is_start = true;
|
||||
entry->start_devid = ep->device_id;
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_END:
|
||||
if (!is_start)
|
||||
break;
|
||||
|
||||
entry = kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC);
|
||||
if (!entry)
|
||||
return -ENOMEM;
|
||||
|
||||
is_start = false;
|
||||
entry->start_devid = ep->device_id;
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_END:
|
||||
/* START & END are paired */
|
||||
entry->end_devid = ep->device_id;
|
||||
list_add_tail(&entry->list, &np->ep_list);
|
||||
break;
|
||||
@@ -135,7 +180,6 @@ static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu)
|
||||
if (!entry)
|
||||
return -ENOMEM;
|
||||
|
||||
is_start = false;
|
||||
entry->start_devid = ep->device_id;
|
||||
entry->end_devid = ep->device_id;
|
||||
list_add_tail(&entry->list, &np->ep_list);
|
||||
@@ -184,7 +228,14 @@ void __init acpi_iovt_init(void)
|
||||
return;
|
||||
}
|
||||
|
||||
iovt = (struct acpi_table_iovt *)&hdr;
|
||||
if (acpi_iovt_checksum((unsigned char *)hdr, hdr->length)) {
|
||||
pr_err("IOVT invalid checksum\n");
|
||||
acpi_put_table(hdr);
|
||||
return;
|
||||
}
|
||||
|
||||
checksum_valid = true;
|
||||
iovt = (struct acpi_table_iovt *)hdr;
|
||||
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset);
|
||||
for (i = 0; i < iovt->iommu_count; i++) {
|
||||
iovt_enable_acs(iommu);
|
||||
@@ -199,6 +250,9 @@ void __init acpi_iovt_late_init(void)
|
||||
acpi_status status;
|
||||
struct acpi_table_header *hdr;
|
||||
|
||||
if (!checksum_valid)
|
||||
return;
|
||||
|
||||
status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
if (status != AE_NOT_FOUND)
|
||||
|
||||
Reference in New Issue
Block a user