linux/arch/mips
Huacai Chen e4de205769 MIPS: KVM: Fix NULL pointer dereference
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>
2023-07-03 16:06:19 +02:00
..
alchemy MIPS: Alchemy: Enable PATA_PLATFORM support 2023-06-09 09:53:11 +02:00
ar7 mips: ar7: include linux/gpio/driver.h 2023-03-10 13:40:18 +02:00
ath25 MIPS: ath25: Constify static irq_domain_ops 2022-02-22 09:39:03 +01:00
ath79 MIPS: ath79: remove obsolete ATH79_DEV_* configs 2023-03-17 10:28:04 +01:00
bcm47xx MIPS: BCM47XX: Add support for Huawei B593u-12 2023-03-14 17:05:14 +01:00
bcm63xx MIPS: BCM63xx: Add check for NULL for clk in clk_enable 2022-12-09 23:37:06 +01:00
bmips mips: bmips: BCM6358: disable RAC flush for TP1 2023-03-18 14:36:06 +01:00
boot MIPS: Loongson64: DTS: Add RTC support to Loongson-2K1000 2023-06-26 09:18:43 +02:00
cavium-octeon MIPS: OCTEON: octeon-usb: cleanup divider calculation 2023-06-23 15:06:40 +02:00
cobalt
configs MIPS: Loongson64: loongson3_defconfig: Enable amdgpu drm driver 2023-06-20 14:31:47 +02:00
crypto crypto: Kconfig - simplify cipher entries 2022-08-26 18:50:43 +08:00
dec MIPS: fix typos in comments 2022-05-04 22:22:59 +02:00
fw MIPS: fw: Allow firmware to pass a empty env 2023-04-12 15:07:36 +02:00
generic mips: ingenic: Enable EXT/2 divider on JZ4750/55/60 if EXT is 24 MHz 2023-06-09 09:54:17 +02:00
include MIPS: KVM: Fix NULL pointer dereference 2023-07-03 16:06:19 +02:00
ingenic MIPS: Kconfig: ingenic: Ensure MACH_INGENIC_GENERIC selects all SoCs 2021-06-01 11:44:47 +02:00
jazz MIPS: fix typos in comments 2022-05-04 22:22:59 +02:00
kernel MIPS: Loongson: Fix cpu_probe_loongson() again 2023-07-03 16:05:51 +02:00
kvm MIPS: KVM: Fix NULL pointer dereference 2023-07-03 16:06:19 +02:00
lantiq MIPS: vpe-mt: drop physical_memsize 2023-02-20 15:11:01 +01:00
lib MIPS: Simplify __bswapdi2() and __bswapsi2() 2022-09-30 16:50:00 +02:00
loongson2ef MIPS: loongson2ef: Add missing break in cs5536_isa 2023-04-12 15:12:24 +02:00
loongson32 MIPS: Loongson32: Remove reset.c 2023-05-23 10:48:30 +02:00
loongson64 Objtool changes for v6.4: 2023-04-28 14:02:54 -07:00
math-emu MIPS: Fix comment typo 2022-09-12 15:33:24 +02:00
mm MIPS: mm: Remove special handling for OCTEON CPUs 2023-06-20 14:30:35 +02:00
mti-malta MIPS: Remove deprecated CONFIG_MIPS_CMP 2023-04-12 15:01:09 +02:00
n64
net bpf, mips: Implement R4000 workarounds for JIT 2023-02-28 14:52:55 +01:00
pci mips: pci-mt7620: use dev_info() to log PCIe device detection result 2023-06-21 14:53:45 +02:00
pic32 MIPS: pic32: treat port as signed integer 2022-11-11 15:53:58 +01:00
power
ralink mips: ralink: match all supported system controller compatible strings 2023-06-23 15:00:37 +02:00
rb532 MIPS: rb532: move GPIOD definition into C-files 2022-03-30 20:26:26 +02:00
sgi-ip22 driver core: make struct bus_type.uevent() take a const * 2023-01-27 13:45:52 +01:00
sgi-ip27 MIPS: SGI-IP27: Fix platform-device leak in bridge_platform_create() 2022-09-19 16:33:27 +02:00
sgi-ip30 MIPS: SGI-IP30: Fix platform-device leak in bridge_platform_create() 2022-09-19 16:32:54 +02:00
sgi-ip32 MIPS: Allow modules to set board_be_handler 2021-11-09 16:07:26 +01:00
sibyte mips: Fix spacing issue 2023-06-09 09:49:59 +02:00
sni MIPS: sni: Fix the build 2021-10-18 18:09:54 +02:00
tools MIPS: fix typos in comments 2022-05-04 22:22:59 +02:00
txx9 MIPS: fix typos in comments 2022-05-04 22:22:59 +02:00
vdso vdso: Improve cmd_vdso_check to check all dynamic relocations 2023-03-21 21:15:34 +01:00
Kbuild kbuild: remove --include-dir MAKEFLAG from top Makefile 2023-02-05 18:51:22 +09:00
Kbuild.platforms MIPS: sibyte: Remove unused config option SIBYTE_BCM1x55 2023-03-17 10:27:08 +01:00
Kconfig MIPS: Select CONFIG_GENERIC_IDLE_POLL_SETUP 2023-06-09 10:34:26 +02:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile MIPS: Loongson: Move arch cflags to MIPS top level Makefile 2023-04-05 09:45:09 +02:00
Makefile.postlink kbuild: remove --include-dir MAKEFLAG from top Makefile 2023-02-05 18:51:22 +09:00