linux/arch/mips/include/asm
Huacai Chen bd9cf2a5f9 MIPS: KVM: Fix NULL pointer dereference
commit e4de205769 upstream.

After commit 45c7e8af4a ("MIPS: Remove KVM_TE support") we
get a NULL pointer dereference when creating a KVM guest:

[  146.243409] Starting KVM with MIPS VZ extensions
[  149.849151] CPU 3 Unable to handle kernel paging request at virtual address 0000000000000300, epc == ffffffffc06356ec, ra == ffffffffc063568c
[  149.849177] Oops[#1]:
[  149.849182] CPU: 3 PID: 2265 Comm: qemu-system-mip Not tainted 6.4.0-rc3+ #1671
[  149.849188] Hardware name: THTF CX TL630 Series/THTF-LS3A4000-7A1000-ML4A, BIOS KL4.1F.TF.D.166.201225.R 12/25/2020
[  149.849192] $ 0   : 0000000000000000 000000007400cce0 0000000000400004 ffffffff8119c740
[  149.849209] $ 4   : 000000007400cce1 000000007400cce1 0000000000000000 0000000000000000
[  149.849221] $ 8   : 000000240058bb36 ffffffff81421ac0 0000000000000000 0000000000400dc0
[  149.849233] $12   : 9800000102a07cc8 ffffffff80e40e38 0000000000000001 0000000000400dc0
[  149.849245] $16   : 0000000000000000 9800000106cd0000 9800000106cd0000 9800000100cce000
[  149.849257] $20   : ffffffffc0632b28 ffffffffc05b31b0 9800000100ccca00 0000000000400000
[  149.849269] $24   : 9800000106cd09ce ffffffff802f69d0
[  149.849281] $28   : 9800000102a04000 9800000102a07cd0 98000001106a8000 ffffffffc063568c
[  149.849293] Hi    : 00000335b2111e66
[  149.849295] Lo    : 6668d90061ae0ae9
[  149.849298] epc   : ffffffffc06356ec kvm_vz_vcpu_setup+0xc4/0x328 [kvm]
[  149.849324] ra    : ffffffffc063568c kvm_vz_vcpu_setup+0x64/0x328 [kvm]
[  149.849336] Status: 7400cce3 KX SX UX KERNEL EXL IE
[  149.849351] Cause : 1000000c (ExcCode 03)
[  149.849354] BadVA : 0000000000000300
[  149.849357] PrId  : 0014c004 (ICT Loongson-3)
[  149.849360] Modules linked in: kvm nfnetlink_queue nfnetlink_log nfnetlink fuse sha256_generic libsha256 cfg80211 rfkill binfmt_misc vfat fat snd_hda_codec_hdmi input_leds led_class snd_hda_intel snd_intel_dspcfg snd_hda_codec snd_hda_core snd_pcm snd_timer snd serio_raw xhci_pci radeon drm_suballoc_helper drm_display_helper xhci_hcd ip_tables x_tables
[  149.849432] Process qemu-system-mip (pid: 2265, threadinfo=00000000ae2982d2, task=0000000038e09ad4, tls=000000ffeba16030)
[  149.849439] Stack : 9800000000000003 9800000100ccca00 9800000100ccc000 ffffffffc062cef4
[  149.849453]         9800000102a07d18 c89b63a7ab338e00 0000000000000000 ffffffff811a0000
[  149.849465]         0000000000000000 9800000106cd0000 ffffffff80e59938 98000001106a8920
[  149.849476]         ffffffff80e57f30 ffffffffc062854c ffffffff811a0000 9800000102bf4240
[  149.849488]         ffffffffc05b0000 ffffffff80e3a798 000000ff78000000 000000ff78000010
[  149.849500]         0000000000000255 98000001021f7de0 98000001023f0078 ffffffff81434000
[  149.849511]         0000000000000000 0000000000000000 9800000102ae0000 980000025e92ae28
[  149.849523]         0000000000000000 c89b63a7ab338e00 0000000000000001 ffffffff8119dce0
[  149.849535]         000000ff78000010 ffffffff804f3d3c 9800000102a07eb0 0000000000000255
[  149.849546]         0000000000000000 ffffffff8049460c 000000ff78000010 0000000000000255
[  149.849558]         ...
[  149.849565] Call Trace:
[  149.849567] [<ffffffffc06356ec>] kvm_vz_vcpu_setup+0xc4/0x328 [kvm]
[  149.849586] [<ffffffffc062cef4>] kvm_arch_vcpu_create+0x184/0x228 [kvm]
[  149.849605] [<ffffffffc062854c>] kvm_vm_ioctl+0x64c/0xf28 [kvm]
[  149.849623] [<ffffffff805209c0>] sys_ioctl+0xc8/0x118
[  149.849631] [<ffffffff80219eb0>] syscall_common+0x34/0x58

The root cause is the deletion of kvm_mips_commpage_init() leaves vcpu
->arch.cop0 NULL. So fix it by making cop0 from a pointer to an embedded
object.

Fixes: 45c7e8af4a ("MIPS: Remove KVM_TE support")
Cc: stable@vger.kernel.org
Reported-by: Yu Zhao <yuzhao@google.com>
Suggested-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-07-23 13:49:33 +02:00
..
dec
fw MIPS: pic32: treat port as signed integer 2022-11-11 15:53:58 +01:00
ip32
mach-ar7 MIPS: AR7: remove orphan declarations from arch/mips/include/asm/mach-ar7/ar7.h 2022-09-19 16:37:27 +02:00
mach-ath25
mach-ath79
mach-au1x00
mach-bcm47xx MIPS: BCM47XX: Add support for Netgear WNR3500L v2 2022-07-15 14:22:47 +02:00
mach-bcm63xx
mach-bmips
mach-cavium-octeon
mach-cobalt
mach-db1x00
mach-dec
mach-generic
mach-ingenic
mach-ip22
mach-ip27
mach-ip28
mach-ip30 MIPS: IP30: Remove incorrect `cpu_has_fpu' override 2022-05-04 22:23:18 +02:00
mach-ip32
mach-jazz
mach-lantiq
mach-loongson2ef
mach-loongson32
mach-loongson64 irqchip/loongson-liointc: Add ACPI init support 2022-07-20 12:09:21 +01:00
mach-malta
mach-n64
mach-pic32
mach-ralink mips: ralink: mt7621: define MT7621_SYSC_BASE with __iomem 2022-12-21 17:48:03 +01:00
mach-rc32434 MIPS: Fix a compilation issue 2023-03-17 08:50:30 +01:00
mach-rm
mach-sibyte
mach-tx49xx
mips-boards
octeon MIPS: Octeon: remove orphan octeon_hal_setup_reserved32() declaration 2022-09-19 16:35:50 +02:00
pci
sgi
sibyte MIPS: remove orphan sb1250_time_init() declaration 2022-09-24 11:46:58 +02:00
sn MIPS: remove define-only GDA_MAGIC, previously magic number 2022-09-24 14:17:18 +02:00
txx9
vdso
xtalk
abi.h
addrspace.h
amon.h
arch_hweight.h
asm-eva.h
asm-offsets.h
asm-prototypes.h
asm.h
asmmacro-32.h
asmmacro-64.h
asmmacro.h
atomic.h
barrier.h
bcache.h
bitops.h
bitrev.h
bmips-spaces.h
bmips.h
bootinfo.h
branch.h
break.h
bug.h
bugs.h
cache.h
cacheflush.h
cacheops.h
cdmm.h
cevt-r4k.h
checksum.h MIPS: Rewrite `csum_tcpudp_nofold' in plain C 2022-05-23 11:29:59 +02:00
clocksource.h
cmp.h
cmpxchg.h
compat-signal.h
compat.h
compiler.h
cop2.h
cpu-features.h MIPS: adding a safety check for cpu_has_fpu 2022-05-04 22:26:02 +02:00
cpu-info.h
cpu-type.h MIPS: Remove VR41xx support 2022-07-14 11:52:29 +02:00
cpu.h MIPS: Remove VR41xx support 2022-07-14 11:52:29 +02:00
cpufeature.h
debug.h
delay.h
div64.h
dma-direct.h
dma-mapping.h
dma.h PCI: Move isa_dma_bridge_buggy out of asm/dma.h 2022-07-22 17:24:47 -05:00
dmi.h
ds1287.h
dsemul.h
dsp.h
edac.h
elf.h
elfcore-compat.h
errno.h
eva.h
exec.h
extable.h
fb.h
fixmap.h
floppy.h
fpregdef.h
fpu_emulator.h
fpu.h
ftrace.h
futex.h
ginvt.h
gio_device.h
gt64120.h
hardirq.h
hazards.h
highmem.h
hpet.h
hugetlb.h mm: change huge_ptep_clear_flush() to return the original pte 2022-05-13 16:48:55 -07:00
hw_irq.h
i8259.h
ide.h
idle.h
inst.h
io.h added support for Netgear WNR3500L v2 2022-08-06 16:47:19 -07:00
irq_cpu.h
irq_gt641xx.h
irq_regs.h
irq.h MIPS: IRQ: remove orphan allocate_irqno() declaration 2022-09-24 11:47:18 +02:00
irqflags.h
isa-rev.h
isadep.h
jazz.h
jazzdma.h
jump_label.h jump_label: make initial NOP patching the special case 2022-06-24 09:48:55 +02:00
Kbuild
kdebug.h
kexec.h
kgdb.h
kprobes.h
kvm_host.h MIPS: KVM: Fix NULL pointer dereference 2023-07-23 13:49:33 +02:00
kvm_types.h
linkage.h
local.h
maar.h
machine.h
mc146818-time.h
mc146818rtc.h
mips_mt.h
mips-cm.h
mips-cpc.h
mips-cps.h
mips-gic.h
mips-r2-to-r6-emul.h
mipsmtregs.h
mipsprom.h
mipsregs.h MIPS: Remove VR41xx support 2022-07-14 11:52:29 +02:00
mmiowb.h
mmu_context.h
mmu.h
mmzone.h
module.h
msa.h
msc01_ic.h
paccess.h
page.h
pci.h PCI: Remove pci_get_legacy_ide_irq() and asm-generic/pci.h 2022-07-22 17:23:45 -05:00
perf_event.h
pgalloc.h mips: rename PGD_ORDER to PGD_TABLE_ORDER 2022-07-17 17:14:42 -07:00
pgtable-32.h added support for Netgear WNR3500L v2 2022-08-06 16:47:19 -07:00
pgtable-64.h added support for Netgear WNR3500L v2 2022-08-06 16:47:19 -07:00
pgtable-bits.h
pgtable.h mm: add dummy pmd_young() for architectures not having it 2022-11-30 14:49:41 -08:00
pm-cps.h
pm.h
prefetch.h
processor.h kernel: exit: cleanup release_thread() 2022-09-11 21:55:07 -07:00
prom.h
ptrace.h
r4k-timer.h
r4kcache.h
reboot.h
reg.h
regdef.h
rtlx.h
seccomp.h
setup.h
sgialib.h
sgiarcs.h
shmparam.h
sigcontext.h
signal.h
sim.h
smp-cps.h
smp-ops.h
smp.h
sni.h MIPS: remove orphan sni_cpu_time_init() declaration 2022-09-19 16:36:55 +02:00
socket.h
sparsemem.h
spinlock_types.h
spinlock.h
spram.h
stackframe.h
stackprotector.h
stacktrace.h
string.h
switch_to.h
sync.h
syscall.h mips: fix syscall_get_nr 2023-03-10 09:34:26 +01:00
thread_info.h
time.h
timex.h mips: use fallback for random_get_entropy() instead of just c0 random 2022-05-13 23:59:23 +02:00
tlb.h
tlbdebug.h
tlbex.h
tlbflush.h
tlbmisc.h
topology.h
traps.h
txx9irq.h
txx9pio.h
txx9tmr.h
types.h
uaccess.h
uasm.h
unaligned-emul.h
unistd.h
unroll.h
uprobes.h
vdso.h
vermagic.h MIPS: Remove VR41xx support 2022-07-14 11:52:29 +02:00
vga.h
vmalloc.h
vpe.h
watch.h
wbflush.h
yamon-dt.h