Skip to contentSkip to conversation

KVM: drop 32-bit host support on all architectures

PATCH In review Arnd Bergmann 8 participants 13 messages Dec 21, 2024 – Feb 3, 2025

Subsystems (11)
x86 KVM PowerPC MIPS +7 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover KVM: drop 32-bit host support on all architectures

From: Arnd Bergmann <[email protected]>

I've updated my RFC patches based on the feedback, changing mainly the powerpc code.

I submitted a patch to remove KVM support for x86-32 hosts earlier this month, but there were still concerns that this might be useful for testing 32-bit host in general, as that remains supported on three other architectures. I have gone through those three now and prepared similar patches, as all of them seem to be equally obsolete.

Support for 32-bit KVM host on Arm hardware was dropped back in 2020 because of lack of users, despite Cortex-A7/A15/A17 based SoCs being much more widely deployed than the other virtualization capable 32-bit CPUs (Intel Core Duo/Silverthorne, PowerPC e300/e500/e600, MIPS P5600) combined.

I hope this can get merged through the KVM tree as a whole series.

Arnd

---
v2 changes:
- rebase to kvm #next branch
- improve changelog text for x86
- many updates for powerpc, thanks to Christophe Leroy for suggestions

Cc Thomas Bogendoerfer <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Jiaxun Yang <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Crystal Wood <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Vitaly Kuznetsov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Paul Durrant <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc "A. Wilcox" <[email protected]>

Arnd Bergmann (5):
mips: kvm: drop support for 32-bit hosts
riscv: kvm: drop 32-bit host support
powerpc: kvm: drop 32-bit booke
powerpc: kvm: drop 32-bit book3s
x86: kvm drop 32-bit host support

 MAINTAINERS                                 |   2 +-
 arch/mips/Kconfig                           |   3 -
 arch/mips/include/asm/kvm_host.h            |   4 -
 arch/mips/kvm/Kconfig                       |   1 +
 arch/mips/kvm/emulate.c                     |   8 -
 arch/mips/kvm/msa.S                         |  12 -
 arch/mips/kvm/vz.c                          |  22 -
 arch/powerpc/include/asm/kvm_book3s.h       |  17 -
 arch/powerpc/include/asm/kvm_book3s_32.h    |  36 --
 arch/powerpc/include/asm/kvm_book3s_asm.h   |  10 -
 arch/powerpc/include/asm/kvm_booke.h        |   4 -
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   2 -
 arch/powerpc/include/asm/kvm_host.h         |   2 +-
 arch/powerpc/include/asm/kvm_ppc.h          |   2 +-
 arch/powerpc/include/asm/processor.h        |   3 -
 arch/powerpc/kernel/asm-offsets.c           |  21 +-
 arch/powerpc/kernel/head_32.h               |  10 -
 arch/powerpc/kernel/head_85xx.S             |  14 -
 arch/powerpc/kernel/head_book3s_32.S        |   5 -
 arch/powerpc/kernel/head_booke.h            |  39 --
 arch/powerpc/kvm/Kconfig                    |  44 +-
 arch/powerpc/kvm/Makefile                   |  30 --
 arch/powerpc/kvm/book3s.c                   |  18 -
 arch/powerpc/kvm/book3s_32_mmu_host.c       | 396 --------------
 arch/powerpc/kvm/book3s_emulate.c           |  37 --
 arch/powerpc/kvm/book3s_interrupts.S        |  11 -
 arch/powerpc/kvm/book3s_mmu_hpte.c          |  12 -
 arch/powerpc/kvm/book3s_pr.c                | 122 +----
 arch/powerpc/kvm/book3s_rmhandlers.S        | 110 ----
 arch/powerpc/kvm/book3s_segment.S           |  30 +-
 arch/powerpc/kvm/booke.c                    | 268 ----------
 arch/powerpc/kvm/booke.h                    |   8 -
 arch/powerpc/kvm/booke_emulate.c            |  44 --
 arch/powerpc/kvm/booke_interrupts.S         | 535 -------------------
 arch/powerpc/kvm/bookehv_interrupts.S       | 102 ----
 arch/powerpc/kvm/e500.c                     | 553 --------------------
 arch/powerpc/kvm/e500.h                     |  40 --
 arch/powerpc/kvm/e500_emulate.c             | 100 ----
 arch/powerpc/kvm/e500_mmu_host.c            |  54 --
 arch/powerpc/kvm/e500mc.c                   |   5 +-
 arch/powerpc/kvm/emulate.c                  |   2 -
 arch/powerpc/kvm/powerpc.c                  |   2 -
 arch/powerpc/kvm/trace_booke.h              |  14 -
 arch/riscv/kvm/Kconfig                      |   2 +-
 arch/riscv/kvm/aia.c                        | 105 ----
 arch/riscv/kvm/aia_imsic.c                  |  34 --
 arch/riscv/kvm/mmu.c                        |   8 -
 arch/riscv/kvm/vcpu_exit.c                  |   4 -
 arch/riscv/kvm/vcpu_insn.c                  |  12 -
 arch/riscv/kvm/vcpu_sbi_pmu.c               |   8 -
 arch/riscv/kvm/vcpu_sbi_replace.c           |   4 -
 arch/riscv/kvm/vcpu_sbi_v01.c               |   4 -
 arch/riscv/kvm/vcpu_timer.c                 |  20 -
 arch/x86/kvm/Kconfig                        |   6 +-
 arch/x86/kvm/Makefile                       |   4 +-
 arch/x86/kvm/cpuid.c                        |   2 +-
 arch/x86/kvm/emulate.c                      |  34 +-
 arch/x86/kvm/fpu.h                          |   4 -
 arch/x86/kvm/hyperv.c                       |   5 +-
 arch/x86/kvm/i8254.c                        |   4 -
 arch/x86/kvm/kvm_cache_regs.h               |   2 -
 arch/x86/kvm/kvm_emulate.h                  |   8 -
 arch/x86/kvm/lapic.c                        |   4 -
 arch/x86/kvm/mmu.h                          |   4 -
 arch/x86/kvm/mmu/mmu.c                      | 134 -----
 arch/x86/kvm/mmu/mmu_internal.h             |   9 -
 arch/x86/kvm/mmu/paging_tmpl.h              |   9 -
 arch/x86/kvm/mmu/spte.h                     |   5 -
 arch/x86/kvm/mmu/tdp_mmu.h                  |   4 -
 arch/x86/kvm/smm.c                          |  19 -
 arch/x86/kvm/svm/sev.c                      |   2 -
 arch/x86/kvm/svm/svm.c                      |  23 +-
 arch/x86/kvm/svm/vmenter.S                  |  20 -
 arch/x86/kvm/trace.h                        |   4 -
 arch/x86/kvm/vmx/main.c                     |   2 -
 arch/x86/kvm/vmx/nested.c                   |  24 +-
 arch/x86/kvm/vmx/vmcs.h                     |   2 -
 arch/x86/kvm/vmx/vmenter.S                  |  25 +-
 arch/x86/kvm/vmx/vmx.c                      | 117 +----
 arch/x86/kvm/vmx/vmx.h                      |  23 +-
 arch/x86/kvm/vmx/vmx_ops.h                  |   7 -
 arch/x86/kvm/vmx/x86_ops.h                  |   2 -
 arch/x86/kvm/x86.c                          |  74 +--
 arch/x86/kvm/x86.h                          |   4 -
 arch/x86/kvm/xen.c                          |  61 +--
 85 files changed, 66 insertions(+), 3536 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/kvm_book3s_32.h
 delete mode 100644 arch/powerpc/kvm/book3s_32_mmu_host.c
 delete mode 100644 arch/powerpc/kvm/booke_interrupts.S
 delete mode 100644 arch/powerpc/kvm/e500.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v2 1/5 mips: kvm: drop support for 32-bit hosts

From: Arnd Bergmann <[email protected]>

KVM support on MIPS was added in 2012 with both 32-bit and 64-bit mode included, but there is only one CPU implementation that actually includes the required VZ support with the Warrior P5600 core. Support for the one SoC using this core did not fully get merged into mainline, and very likely never will.

Simplify the KVM code by dropping the corresponding #ifdef checks for 32-bit mode, leaving only 64-bit mode available in Loongson, Cavium, Mobileye and Fungible SoCs.

---
 arch/mips/Kconfig                |  3 ---
 arch/mips/include/asm/kvm_host.h |  4 ----
 arch/mips/kvm/Kconfig            |  1 +
 arch/mips/kvm/emulate.c          |  8 --------
 arch/mips/kvm/msa.S              | 12 ------------
 arch/mips/kvm/vz.c               | 22 ----------------------
 6 files changed, 1 insertion(+), 49 deletions(-)
arch/mips/Kconfig +0 -3
index a33f05e1ad6d..7705d634d9c7 100644
@@ -1415,7 +1415,6 @@ config CPU_MIPS32_R5
 	select CPU_SUPPORTS_32BIT_KERNEL
 	select CPU_SUPPORTS_HIGHMEM
 	select CPU_SUPPORTS_MSA
-	select CPU_SUPPORTS_VZ
 	select MIPS_O32_FP64_SUPPORT
 	help
 	  Choose this option to build a kernel for release 5 or later of the
@@ -1431,7 +1430,6 @@ config CPU_MIPS32_R6
 	select CPU_SUPPORTS_32BIT_KERNEL
 	select CPU_SUPPORTS_HIGHMEM
 	select CPU_SUPPORTS_MSA
-	select CPU_SUPPORTS_VZ
 	select MIPS_O32_FP64_SUPPORT
 	help
 	  Choose this option to build a kernel for release 6 or later of the
@@ -1517,7 +1515,6 @@ config CPU_P5600
 	select CPU_SUPPORTS_HIGHMEM
 	select CPU_SUPPORTS_MSA
 	select CPU_SUPPORTS_CPUFREQ
-	select CPU_SUPPORTS_VZ
 	select CPU_MIPSR2_IRQ_VI
 	select CPU_MIPSR2_IRQ_EI
 	select MIPS_O32_FP64_SUPPORT
arch/mips/include/asm/kvm_host.h +0 -4
index f7222eb594ea..1a506892322d 100644
@@ -261,11 +261,7 @@ enum emulation_result {
 	EMULATE_HYPERCALL,	/* HYPCALL instruction */
 };
 
-#if defined(CONFIG_64BIT)
 #define VPN2_MASK		GENMASK(cpu_vmbits - 1, 13)
-#else
-#define VPN2_MASK		0xffffe000
-#endif
 #define KVM_ENTRYHI_ASID	cpu_asid_mask(&boot_cpu_data)
 #define TLB_IS_GLOBAL(x)	((x).tlb_lo[0] & (x).tlb_lo[1] & ENTRYLO_G)
 #define TLB_VPN2(x)		((x).tlb_hi & VPN2_MASK)
arch/mips/kvm/Kconfig +1 -0
index ab57221fa4dd..2508ebbf49ba 100644
@@ -18,6 +18,7 @@ if VIRTUALIZATION
 config KVM
 	tristate "Kernel-based Virtual Machine (KVM) support"
 	depends on CPU_SUPPORTS_VZ
+	depends on 64BIT
 	depends on MIPS_FP_SUPPORT
 	select EXPORT_UASM
 	select KVM_COMMON
arch/mips/kvm/emulate.c +0 -8
index 0feec52222fb..c84eaf21643c 100644
@@ -994,7 +994,6 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,
 		goto out_fail;
 
 	switch (inst.i_format.opcode) {
-#if defined(CONFIG_64BIT)
 	case sd_op:
 		run->mmio.len = 8;
 		*(u64 *)data = vcpu->arch.gprs[rt];
@@ -1003,7 +1002,6 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,
 			  vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
 			  vcpu->arch.gprs[rt], *(u64 *)data);
 		break;
-#endif
 
 	case sw_op:
 		run->mmio.len = 4;
@@ -1092,7 +1090,6 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,
 			  vcpu->arch.gprs[rt], *(u32 *)data);
 		break;
 
-#if defined(CONFIG_64BIT)
 	case sdl_op:
 		run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
 					vcpu->arch.host_cp0_badvaddr) & (~0x7);
@@ -1186,7 +1183,6 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,
 			  vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
 			  vcpu->arch.gprs[rt], *(u64 *)data);
 		break;
-#endif
 
 #ifdef CONFIG_CPU_LOONGSON64
 	case sdc2_op:
@@ -1299,7 +1295,6 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst,
 
 	vcpu->mmio_needed = 2;	/* signed */
 	switch (op) {
-#if defined(CONFIG_64BIT)
 	case ld_op:
 		run->mmio.len = 8;
 		break;
@@ -1307,7 +1302,6 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst,
 	case lwu_op:
 		vcpu->mmio_needed = 1;	/* unsigned */
 		fallthrough;
-#endif
 	case lw_op:
 		run->mmio.len = 4;
 		break;
@@ -1374,7 +1368,6 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst,
 		}
 		break;
 
-#if defined(CONFIG_64BIT)
 	case ldl_op:
 		run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
 					vcpu->arch.host_cp0_badvaddr) & (~0x7);
@@ -1446,7 +1439,6 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst,
 			break;
 		}
 		break;
-#endif
 
 #ifdef CONFIG_CPU_LOONGSON64
 	case ldc2_op:
arch/mips/kvm/msa.S +0 -12
index d02f0c6cc2cc..c73858efb975 100644
@@ -93,20 +93,8 @@ LEAF(__kvm_restore_msa)
 	.macro	kvm_restore_msa_upper	wr, off, base
 	.set	push
 	.set	noat
-#ifdef CONFIG_64BIT
 	ld	$1, \off(\base)
 	insert_d \wr, 1
-#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
-	lw	$1, \off(\base)
-	insert_w \wr, 2
-	lw	$1, (\off+4)(\base)
-	insert_w \wr, 3
-#else /* CONFIG_CPU_BIG_ENDIAN */
-	lw	$1, (\off+4)(\base)
-	insert_w \wr, 2
-	lw	$1, \off(\base)
-	insert_w \wr, 3
-#endif
 	.set	pop
 	.endm
 
arch/mips/kvm/vz.c +0 -22
index ccab4d76b126..b376ac870256 100644
@@ -746,7 +746,6 @@ static int kvm_vz_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
 			*gpa = gva32 & 0x1fffffff;
 			return 0;
 		}
-#ifdef CONFIG_64BIT
 	} else if ((gva & 0xc000000000000000) == 0x8000000000000000) {
 		/* XKPHYS */
 		if (cpu_guest_has_segments) {
@@ -771,7 +770,6 @@ static int kvm_vz_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
 		 */
 		*gpa = gva & 0x07ffffffffffffff;
 		return 0;
-#endif
 	}
 
 tlb_mapped:
@@ -1740,9 +1738,7 @@ static u64 kvm_vz_get_one_regs[] = {
 	KVM_REG_MIPS_CP0_CONFIG4,
 	KVM_REG_MIPS_CP0_CONFIG5,
 	KVM_REG_MIPS_CP0_CONFIG6,
-#ifdef CONFIG_64BIT
 	KVM_REG_MIPS_CP0_XCONTEXT,
-#endif
 	KVM_REG_MIPS_CP0_ERROREPC,
 
 	KVM_REG_MIPS_COUNT_CTL,
@@ -1752,9 +1748,7 @@ static u64 kvm_vz_get_one_regs[] = {
 
 static u64 kvm_vz_get_one_regs_contextconfig[] = {
 	KVM_REG_MIPS_CP0_CONTEXTCONFIG,
-#ifdef CONFIG_64BIT
 	KVM_REG_MIPS_CP0_XCONTEXTCONFIG,
-#endif
 };
 
 static u64 kvm_vz_get_one_regs_segments[] = {
@@ -1937,13 +1931,11 @@ static int kvm_vz_get_one_reg(struct kvm_vcpu *vcpu,
 			return -EINVAL;
 		*v = read_gc0_userlocal();
 		break;
-#ifdef CONFIG_64BIT
 	case KVM_REG_MIPS_CP0_XCONTEXTCONFIG:
 		if (!cpu_guest_has_contextconfig)
 			return -EINVAL;
 		*v = read_gc0_xcontextconfig();
 		break;
-#endif
 	case KVM_REG_MIPS_CP0_PAGEMASK:
 		*v = (long)read_gc0_pagemask();
 		break;
@@ -2083,11 +2075,9 @@ static int kvm_vz_get_one_reg(struct kvm_vcpu *vcpu,
 			return -EINVAL;
 		*v = kvm_read_sw_gc0_maari(&vcpu->arch.cop0);
 		break;
-#ifdef CONFIG_64BIT
 	case KVM_REG_MIPS_CP0_XCONTEXT:
 		*v = read_gc0_xcontext();
 		break;
-#endif
 	case KVM_REG_MIPS_CP0_ERROREPC:
 		*v = (long)read_gc0_errorepc();
 		break;
@@ -2163,13 +2153,11 @@ static int kvm_vz_set_one_reg(struct kvm_vcpu *vcpu,
 			return -EINVAL;
 		write_gc0_userlocal(v);
 		break;
-#ifdef CONFIG_64BIT
 	case KVM_REG_MIPS_CP0_XCONTEXTCONFIG:
 		if (!cpu_guest_has_contextconfig)
 			return -EINVAL;
 		write_gc0_xcontextconfig(v);
 		break;
-#endif
 	case KVM_REG_MIPS_CP0_PAGEMASK:
 		write_gc0_pagemask(v);
 		break;
@@ -2360,11 +2348,9 @@ static int kvm_vz_set_one_reg(struct kvm_vcpu *vcpu,
 			return -EINVAL;
 		kvm_write_maari(vcpu, v);
 		break;
-#ifdef CONFIG_64BIT
 	case KVM_REG_MIPS_CP0_XCONTEXT:
 		write_gc0_xcontext(v);
 		break;
-#endif
 	case KVM_REG_MIPS_CP0_ERROREPC:
 		write_gc0_errorepc(v);
 		break;
@@ -2632,11 +2618,9 @@ static int kvm_vz_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 	kvm_restore_gc0_context(cop0);
 	if (cpu_guest_has_contextconfig)
 		kvm_restore_gc0_contextconfig(cop0);
-#ifdef CONFIG_64BIT
 	kvm_restore_gc0_xcontext(cop0);
 	if (cpu_guest_has_contextconfig)
 		kvm_restore_gc0_xcontextconfig(cop0);
-#endif
 	kvm_restore_gc0_pagemask(cop0);
 	kvm_restore_gc0_pagegrain(cop0);
 	kvm_restore_gc0_hwrena(cop0);
@@ -2717,11 +2701,9 @@ static int kvm_vz_vcpu_put(struct kvm_vcpu *vcpu, int cpu)
 	kvm_save_gc0_context(cop0);
 	if (cpu_guest_has_contextconfig)
 		kvm_save_gc0_contextconfig(cop0);
-#ifdef CONFIG_64BIT
 	kvm_save_gc0_xcontext(cop0);
 	if (cpu_guest_has_contextconfig)
 		kvm_save_gc0_xcontextconfig(cop0);
-#endif
 	kvm_save_gc0_pagemask(cop0);
 	kvm_save_gc0_pagegrain(cop0);
 	kvm_save_gc0_wired(cop0);
@@ -3030,12 +3012,10 @@ static int kvm_vz_check_extension(struct kvm *kvm, long ext)
 		/* we wouldn't be here unless cpu_has_vz */
 		r = 1;
 		break;
-#ifdef CONFIG_64BIT
 	case KVM_CAP_MIPS_64BIT:
 		/* We support 64-bit registers/operations and addresses */
 		r = 2;
 		break;
-#endif
 	case KVM_CAP_IOEVENTFD:
 		r = 1;
 		break;
@@ -3179,12 +3159,10 @@ static int kvm_vz_vcpu_setup(struct kvm_vcpu *vcpu)
 	if (cpu_guest_has_contextconfig) {
 		/* ContextConfig */
 		kvm_write_sw_gc0_contextconfig(cop0, 0x007ffff0);
-#ifdef CONFIG_64BIT
 		/* XContextConfig */
 		/* bits SEGBITS-13+3:4 set */
 		kvm_write_sw_gc0_xcontextconfig(cop0,
 					((1ull << (cpu_vmbits - 13)) - 1) << 4);
-#endif
 	}
 
 	/* Implementation dependent, use the legacy layout */
Signature · 1 line
2.39.5
#2 lore raw

PATCH v2 2/5 riscv: kvm: drop 32-bit host support

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

KVM support on RISC-V includes both 32-bit and 64-bit host mode, but in practice, all RISC-V SoCs that may use this are 64-bit:

As of linux-6.13, there is no mainline Linux support for any specific 32-bit SoC in arch/riscv/, although the generic qemu model should work.

The available RV32 CPU implementations are mostly built for microcontroller applications and are lacking a memory management unit. There are a few CPU cores with an MMU, but those still lack the hypervisor extensions needed for running KVM.

This is unlikely to change in the future, so remove the 32-bit host code and simplify the test matrix.

---
 arch/riscv/kvm/Kconfig            |   2 +-
 arch/riscv/kvm/aia.c              | 105 ------------------------------
 arch/riscv/kvm/aia_imsic.c        |  34 ----------
 arch/riscv/kvm/mmu.c              |   8 ---
 arch/riscv/kvm/vcpu_exit.c        |   4 --
 arch/riscv/kvm/vcpu_insn.c        |  12 ----
 arch/riscv/kvm/vcpu_sbi_pmu.c     |   8 ---
 arch/riscv/kvm/vcpu_sbi_replace.c |   4 --
 arch/riscv/kvm/vcpu_sbi_v01.c     |   4 --
 arch/riscv/kvm/vcpu_timer.c       |  20 ------
 10 files changed, 1 insertion(+), 200 deletions(-)
arch/riscv/kvm/Kconfig +1 -1
index 0c3cbb0915ff..7405722e4433 100644
@@ -19,7 +19,7 @@ if VIRTUALIZATION
 
 config KVM
 	tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)"
-	depends on RISCV_SBI && MMU
+	depends on RISCV_SBI && MMU && 64BIT
 	select HAVE_KVM_IRQCHIP
 	select HAVE_KVM_IRQ_ROUTING
 	select HAVE_KVM_MSI
arch/riscv/kvm/aia.c +0 -105

187 lines not on this page · raw message

arch/riscv/kvm/aia_imsic.c +0 -34
index a8085cd8215e..16c44b10ee97 100644
@@ -258,13 +258,7 @@ static u32 imsic_mrif_topei(struct imsic_mrif *mrif, u32 nr_eix, u32 nr_msis)
 		eix = &mrif->eix[ei];
 		eipend[0] = imsic_mrif_atomic_read(mrif, &eix->eie[0]) &
 			    imsic_mrif_atomic_read(mrif, &eix->eip[0]);
-#ifdef CONFIG_32BIT
-		eipend[1] = imsic_mrif_atomic_read(mrif, &eix->eie[1]) &
-			    imsic_mrif_atomic_read(mrif, &eix->eip[1]);
-		if (!eipend[0] && !eipend[1])
-#else
 		if (!eipend[0])
-#endif
 			continue;
 
 		imin = ei * BITS_PER_TYPE(u64);
@@ -296,10 +290,8 @@ static int imsic_mrif_isel_check(u32 nr_eix, unsigned long isel)
 	default:
 		return -ENOENT;
 	}
-#ifndef CONFIG_32BIT
 	if (num & 0x1)
 		return -EINVAL;
-#endif
 	if ((num / 2) >= nr_eix)
 		return -EINVAL;
 
@@ -337,13 +329,9 @@ static int imsic_mrif_rmw(struct imsic_mrif *mrif, u32 nr_eix,
 			return -EINVAL;
 		eix = &mrif->eix[num / 2];
 
-#ifndef CONFIG_32BIT
 		if (num & 0x1)
 			return -EINVAL;
 		ei = (pend) ? &eix->eip[0] : &eix->eie[0];
-#else
-		ei = (pend) ? &eix->eip[num & 0x1] : &eix->eie[num & 0x1];
-#endif
 
 		/* Bit0 of EIP0 or EIE0 is read-only */
 		if (!num)
@@ -395,10 +383,6 @@ static void imsic_vsfile_local_read(void *data)
 			eix = &mrif->eix[i];
 			eix->eip[0] = imsic_eix_swap(IMSIC_EIP0 + i * 2, 0);
 			eix->eie[0] = imsic_eix_swap(IMSIC_EIE0 + i * 2, 0);
-#ifdef CONFIG_32BIT
-			eix->eip[1] = imsic_eix_swap(IMSIC_EIP0 + i * 2 + 1, 0);
-			eix->eie[1] = imsic_eix_swap(IMSIC_EIE0 + i * 2 + 1, 0);
-#endif
 		}
 	} else {
 		mrif->eidelivery = imsic_vs_csr_read(IMSIC_EIDELIVERY);
@@ -407,10 +391,6 @@ static void imsic_vsfile_local_read(void *data)
 			eix = &mrif->eix[i];
 			eix->eip[0] = imsic_eix_read(IMSIC_EIP0 + i * 2);
 			eix->eie[0] = imsic_eix_read(IMSIC_EIE0 + i * 2);
-#ifdef CONFIG_32BIT
-			eix->eip[1] = imsic_eix_read(IMSIC_EIP0 + i * 2 + 1);
-			eix->eie[1] = imsic_eix_read(IMSIC_EIE0 + i * 2 + 1);
-#endif
 		}
 	}
 
@@ -469,10 +449,8 @@ static void imsic_vsfile_local_rw(void *data)
 		break;
 	case IMSIC_EIP0 ... IMSIC_EIP63:
 	case IMSIC_EIE0 ... IMSIC_EIE63:
-#ifndef CONFIG_32BIT
 		if (idata->isel & 0x1)
 			break;
-#endif
 		if (idata->write)
 			imsic_eix_write(idata->isel, idata->val);
 		else
@@ -536,10 +514,6 @@ static void imsic_vsfile_local_clear(int vsfile_hgei, u32 nr_eix)
 	for (i = 0; i < nr_eix; i++) {
 		imsic_eix_write(IMSIC_EIP0 + i * 2, 0);
 		imsic_eix_write(IMSIC_EIE0 + i * 2, 0);
-#ifdef CONFIG_32BIT
-		imsic_eix_write(IMSIC_EIP0 + i * 2 + 1, 0);
-		imsic_eix_write(IMSIC_EIE0 + i * 2 + 1, 0);
-#endif
 	}
 
 	csr_write(CSR_HSTATUS, old_hstatus);
@@ -573,10 +547,6 @@ static void imsic_vsfile_local_update(int vsfile_hgei, u32 nr_eix,
 		eix = &mrif->eix[i];
 		imsic_eix_set(IMSIC_EIP0 + i * 2, eix->eip[0]);
 		imsic_eix_set(IMSIC_EIE0 + i * 2, eix->eie[0]);
-#ifdef CONFIG_32BIT
-		imsic_eix_set(IMSIC_EIP0 + i * 2 + 1, eix->eip[1]);
-		imsic_eix_set(IMSIC_EIE0 + i * 2 + 1, eix->eie[1]);
-#endif
 	}
 	imsic_vs_csr_write(IMSIC_EITHRESHOLD, mrif->eithreshold);
 	imsic_vs_csr_write(IMSIC_EIDELIVERY, mrif->eidelivery);
@@ -667,10 +637,6 @@ static void imsic_swfile_update(struct kvm_vcpu *vcpu,
 		eix = &mrif->eix[i];
 		imsic_mrif_atomic_or(smrif, &seix->eip[0], eix->eip[0]);
 		imsic_mrif_atomic_or(smrif, &seix->eie[0], eix->eie[0]);
-#ifdef CONFIG_32BIT
-		imsic_mrif_atomic_or(smrif, &seix->eip[1], eix->eip[1]);
-		imsic_mrif_atomic_or(smrif, &seix->eie[1], eix->eie[1]);
-#endif
 	}
 
 	imsic_swfile_extirq_update(vcpu);
arch/riscv/kvm/mmu.c +0 -8
index 1087ea74567b..2aee1100d450 100644
@@ -19,15 +19,9 @@
 #include <asm/page.h>
 #include <asm/pgtable.h>
 
-#ifdef CONFIG_64BIT
 static unsigned long gstage_mode __ro_after_init = (HGATP_MODE_SV39X4 << HGATP_MODE_SHIFT);
 static unsigned long gstage_pgd_levels __ro_after_init = 3;
 #define gstage_index_bits	9
-#else
-static unsigned long gstage_mode __ro_after_init = (HGATP_MODE_SV32X4 << HGATP_MODE_SHIFT);
-static unsigned long gstage_pgd_levels __ro_after_init = 2;
-#define gstage_index_bits	10
-#endif
 
 #define gstage_pgd_xbits	2
 #define gstage_pgd_size	(1UL << (HGATP_PAGE_SHIFT + gstage_pgd_xbits))
@@ -739,7 +733,6 @@ void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu)
 
 void __init kvm_riscv_gstage_mode_detect(void)
 {
-#ifdef CONFIG_64BIT
 	/* Try Sv57x4 G-stage mode */
 	csr_write(CSR_HGATP, HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT);
 	if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV57X4) {
@@ -758,7 +751,6 @@ void __init kvm_riscv_gstage_mode_detect(void)
 
 	csr_write(CSR_HGATP, 0);
 	kvm_riscv_local_hfence_gvma_all();
-#endif
 }
 
 unsigned long __init kvm_riscv_gstage_mode(void)
arch/riscv/kvm/vcpu_exit.c +0 -4
index fa98e5c024b2..f5d598f6acfc 100644
@@ -107,11 +107,7 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu,
 			".option push\n"
 			".option norvc\n"
 			"add %[ttmp], %[taddr], 0\n"
-#ifdef CONFIG_64BIT
 			HLV_D(%[val], %[addr])
-#else
-			HLV_W(%[val], %[addr])
-#endif
 			".option pop"
 		: [val] "=&r" (val),
 		  [taddr] "+&r" (taddr), [ttmp] "+&r" (ttmp)
arch/riscv/kvm/vcpu_insn.c +0 -12
index 97dec18e6989..913c454bee26 100644
@@ -78,11 +78,7 @@
 
 #define INSN_LEN(insn)		(INSN_IS_16BIT(insn) ? 2 : 4)
 
-#ifdef CONFIG_64BIT
 #define LOG_REGBYTES		3
-#else
-#define LOG_REGBYTES		2
-#endif
 #define REGBYTES		(1 << LOG_REGBYTES)
 
 #define SH_RD			7
@@ -522,19 +518,16 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	} else if ((insn & INSN_MASK_LBU) == INSN_MATCH_LBU) {
 		len = 1;
 		shift = 8 * (sizeof(ulong) - len);
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
 	} else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) {
 		len = 4;
-#endif
 	} else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) {
 		len = 2;
 		shift = 8 * (sizeof(ulong) - len);
 	} else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) {
 		len = 2;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
@@ -543,7 +536,6 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		   ((insn >> SH_RD) & 0x1f)) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
-#endif
 	} else if ((insn & INSN_MASK_C_LW) == INSN_MATCH_C_LW) {
 		len = 4;
 		shift = 8 * (sizeof(ulong) - len);
@@ -645,13 +637,10 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		len = 4;
 	} else if ((insn & INSN_MASK_SB) == INSN_MATCH_SB) {
 		len = 1;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) {
 		len = 8;
-#endif
 	} else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) {
 		len = 2;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
 		len = 8;
 		data64 = GET_RS2S(insn, &vcpu->arch.guest_context);
@@ -659,7 +648,6 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		   ((insn >> SH_RD) & 0x1f)) {
 		len = 8;
 		data64 = GET_RS2C(insn, &vcpu->arch.guest_context);
-#endif
 	} else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) {
 		len = 4;
 		data32 = GET_RS2S(insn, &vcpu->arch.guest_context);
arch/riscv/kvm/vcpu_sbi_pmu.c +0 -8
index e4be34e03e83..0871265416fa 100644
@@ -35,11 +35,7 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		ret = kvm_riscv_vcpu_pmu_ctr_info(vcpu, cp->a0, retdata);
 		break;
 	case SBI_EXT_PMU_COUNTER_CFG_MATCH:
-#if defined(CONFIG_32BIT)
-		temp = ((uint64_t)cp->a5 << 32) | cp->a4;
-#else
 		temp = cp->a4;
-#endif
 		/*
 		 * This can fail if perf core framework fails to create an event.
 		 * No need to forward the error to userspace and exit the guest.
@@ -50,11 +46,7 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 						       cp->a2, cp->a3, temp, retdata);
 		break;
 	case SBI_EXT_PMU_COUNTER_START:
-#if defined(CONFIG_32BIT)
-		temp = ((uint64_t)cp->a4 << 32) | cp->a3;
-#else
 		temp = cp->a3;
-#endif
 		ret = kvm_riscv_vcpu_pmu_ctr_start(vcpu, cp->a0, cp->a1, cp->a2,
 						   temp, retdata);
 		break;
arch/riscv/kvm/vcpu_sbi_replace.c +0 -4
index 9c2ab3dfa93a..9276140644d1 100644
@@ -26,11 +26,7 @@ static int kvm_sbi_ext_time_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	}
 
 	kvm_riscv_vcpu_pmu_incr_fw(vcpu, SBI_PMU_FW_SET_TIMER);
-#if __riscv_xlen == 32
-	next_cycle = ((u64)cp->a1 << 32) | (u64)cp->a0;
-#else
 	next_cycle = (u64)cp->a0;
-#endif
 	kvm_riscv_vcpu_timer_next_event(vcpu, next_cycle);
 
 	return 0;
arch/riscv/kvm/vcpu_sbi_v01.c +0 -4
index 8f4c4fa16227..e06ba01392d6 100644
@@ -35,11 +35,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		retdata->uexit = true;
 		break;
 	case SBI_EXT_0_1_SET_TIMER:
-#if __riscv_xlen == 32
-		next_cycle = ((u64)cp->a1 << 32) | (u64)cp->a0;
-#else
 		next_cycle = (u64)cp->a0;
-#endif
 		ret = kvm_riscv_vcpu_timer_next_event(vcpu, next_cycle);
 		break;
 	case SBI_EXT_0_1_CLEAR_IPI:
arch/riscv/kvm/vcpu_timer.c +0 -20
index 96e7a4e463f7..fc32338b8cf8 100644
@@ -71,12 +71,7 @@ static int kvm_riscv_vcpu_timer_cancel(struct kvm_vcpu_timer *t)
 
 static int kvm_riscv_vcpu_update_vstimecmp(struct kvm_vcpu *vcpu, u64 ncycles)
 {
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_VSTIMECMP, ncycles & 0xFFFFFFFF);
-	ncsr_write(CSR_VSTIMECMPH, ncycles >> 32);
-#else
 	ncsr_write(CSR_VSTIMECMP, ncycles);
-#endif
 	return 0;
 }
 
@@ -288,12 +283,7 @@ static void kvm_riscv_vcpu_update_timedelta(struct kvm_vcpu *vcpu)
 {
 	struct kvm_guest_timer *gt = &vcpu->kvm->arch.timer;
 
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_HTIMEDELTA, (u32)(gt->time_delta));
-	ncsr_write(CSR_HTIMEDELTAH, (u32)(gt->time_delta >> 32));
-#else
 	ncsr_write(CSR_HTIMEDELTA, gt->time_delta);
-#endif
 }
 
 void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu)
@@ -305,12 +295,7 @@ void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu)
 	if (!t->sstc_enabled)
 		return;
 
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_VSTIMECMP, (u32)t->next_cycles);
-	ncsr_write(CSR_VSTIMECMPH, (u32)(t->next_cycles >> 32));
-#else
 	ncsr_write(CSR_VSTIMECMP, t->next_cycles);
-#endif
 
 	/* timer should be enabled for the remaining operations */
 	if (unlikely(!t->init_done))
@@ -326,12 +311,7 @@ void kvm_riscv_vcpu_timer_sync(struct kvm_vcpu *vcpu)
 	if (!t->sstc_enabled)
 		return;
 
-#if defined(CONFIG_32BIT)
 	t->next_cycles = ncsr_read(CSR_VSTIMECMP);
-	t->next_cycles |= (u64)ncsr_read(CSR_VSTIMECMPH) << 32;
-#else
-	t->next_cycles = ncsr_read(CSR_VSTIMECMP);
-#endif
 }
 
 void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu)
Signature · 1 line
2.39.5
Tested-by Acked-by on v2 2/5
#3 lore raw

Re: [PATCH v2 2/5] riscv: kvm: drop 32-bit host support

Quoted 590 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

KVM support on RISC-V includes both 32-bit and 64-bit host mode, but in practice, all RISC-V SoCs that may use this are 64-bit:

As of linux-6.13, there is no mainline Linux support for any specific 32-bit SoC in arch/riscv/, although the generic qemu model should work.

The available RV32 CPU implementations are mostly built for microcontroller applications and are lacking a memory management unit. There are a few CPU cores with an MMU, but those still lack the hypervisor extensions needed for running KVM.

This is unlikely to change in the future, so remove the 32-bit host code and simplify the test matrix.

---
 arch/riscv/kvm/Kconfig            |   2 +-
 arch/riscv/kvm/aia.c              | 105 ------------------------------
 arch/riscv/kvm/aia_imsic.c        |  34 ----------
 arch/riscv/kvm/mmu.c              |   8 ---
 arch/riscv/kvm/vcpu_exit.c        |   4 --
 arch/riscv/kvm/vcpu_insn.c        |  12 ----
 arch/riscv/kvm/vcpu_sbi_pmu.c     |   8 ---
 arch/riscv/kvm/vcpu_sbi_replace.c |   4 --
 arch/riscv/kvm/vcpu_sbi_v01.c     |   4 --
 arch/riscv/kvm/vcpu_timer.c       |  20 ------
 10 files changed, 1 insertion(+), 200 deletions(-)
arch/riscv/kvm/Kconfig +1 -1
index 0c3cbb0915ff..7405722e4433 100644
@@ -19,7 +19,7 @@ if VIRTUALIZATION
 
 config KVM
 	tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)"
-	depends on RISCV_SBI && MMU
+	depends on RISCV_SBI && MMU && 64BIT
 	select HAVE_KVM_IRQCHIP
 	select HAVE_KVM_IRQ_ROUTING
 	select HAVE_KVM_MSI
arch/riscv/kvm/aia.c +0 -105
index 19afd1f23537..a399a5a9af0e 100644
@@ -66,33 +66,6 @@ static inline unsigned long aia_hvictl_value(bool ext_irq_pending)
 	return hvictl;
 }
 
-#ifdef CONFIG_32BIT
-void kvm_riscv_vcpu_aia_flush_interrupts(struct kvm_vcpu *vcpu)
-{
-	struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
-	unsigned long mask, val;
-
-	if (!kvm_riscv_aia_available())
-		return;
-
-	if (READ_ONCE(vcpu->arch.irqs_pending_mask[1])) {
-		mask = xchg_acquire(&vcpu->arch.irqs_pending_mask[1], 0);
-		val = READ_ONCE(vcpu->arch.irqs_pending[1]) & mask;
-
-		csr->hviph &= ~mask;
-		csr->hviph |= val;
-	}
-}
-
-void kvm_riscv_vcpu_aia_sync_interrupts(struct kvm_vcpu *vcpu)
-{
-	struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
-
-	if (kvm_riscv_aia_available())
-		csr->vsieh = ncsr_read(CSR_VSIEH);
-}
-#endif
-
 bool kvm_riscv_vcpu_aia_has_interrupts(struct kvm_vcpu *vcpu, u64 mask)
 {
 	int hgei;
@@ -101,12 +74,6 @@ bool kvm_riscv_vcpu_aia_has_interrupts(struct kvm_vcpu *vcpu, u64 mask)
 	if (!kvm_riscv_aia_available())
 		return false;
 
-#ifdef CONFIG_32BIT
-	if (READ_ONCE(vcpu->arch.irqs_pending[1]) &
-	    (vcpu->arch.aia_context.guest_csr.vsieh & upper_32_bits(mask)))
-		return true;
-#endif
-
 	seip = vcpu->arch.guest_csr.vsie;
 	seip &= (unsigned long)mask;
 	seip &= BIT(IRQ_S_EXT);
@@ -128,9 +95,6 @@ void kvm_riscv_vcpu_aia_update_hvip(struct kvm_vcpu *vcpu)
 	if (!kvm_riscv_aia_available())
 		return;
 
-#ifdef CONFIG_32BIT
-	ncsr_write(CSR_HVIPH, vcpu->arch.aia_context.guest_csr.hviph);
-#endif
 	ncsr_write(CSR_HVICTL, aia_hvictl_value(!!(csr->hvip & BIT(IRQ_VS_EXT))));
 }
 
@@ -147,22 +111,10 @@ void kvm_riscv_vcpu_aia_load(struct kvm_vcpu *vcpu, int cpu)
 		nacl_csr_write(nsh, CSR_VSISELECT, csr->vsiselect);
 		nacl_csr_write(nsh, CSR_HVIPRIO1, csr->hviprio1);
 		nacl_csr_write(nsh, CSR_HVIPRIO2, csr->hviprio2);
-#ifdef CONFIG_32BIT
-		nacl_csr_write(nsh, CSR_VSIEH, csr->vsieh);
-		nacl_csr_write(nsh, CSR_HVIPH, csr->hviph);
-		nacl_csr_write(nsh, CSR_HVIPRIO1H, csr->hviprio1h);
-		nacl_csr_write(nsh, CSR_HVIPRIO2H, csr->hviprio2h);
-#endif
 	} else {
 		csr_write(CSR_VSISELECT, csr->vsiselect);
 		csr_write(CSR_HVIPRIO1, csr->hviprio1);
 		csr_write(CSR_HVIPRIO2, csr->hviprio2);
-#ifdef CONFIG_32BIT
-		csr_write(CSR_VSIEH, csr->vsieh);
-		csr_write(CSR_HVIPH, csr->hviph);
-		csr_write(CSR_HVIPRIO1H, csr->hviprio1h);
-		csr_write(CSR_HVIPRIO2H, csr->hviprio2h);
-#endif
 	}
 }
 
@@ -179,22 +131,10 @@ void kvm_riscv_vcpu_aia_put(struct kvm_vcpu *vcpu)
 		csr->vsiselect = nacl_csr_read(nsh, CSR_VSISELECT);
 		csr->hviprio1 = nacl_csr_read(nsh, CSR_HVIPRIO1);
 		csr->hviprio2 = nacl_csr_read(nsh, CSR_HVIPRIO2);
-#ifdef CONFIG_32BIT
-		csr->vsieh = nacl_csr_read(nsh, CSR_VSIEH);
-		csr->hviph = nacl_csr_read(nsh, CSR_HVIPH);
-		csr->hviprio1h = nacl_csr_read(nsh, CSR_HVIPRIO1H);
-		csr->hviprio2h = nacl_csr_read(nsh, CSR_HVIPRIO2H);
-#endif
 	} else {
 		csr->vsiselect = csr_read(CSR_VSISELECT);
 		csr->hviprio1 = csr_read(CSR_HVIPRIO1);
 		csr->hviprio2 = csr_read(CSR_HVIPRIO2);
-#ifdef CONFIG_32BIT
-		csr->vsieh = csr_read(CSR_VSIEH);
-		csr->hviph = csr_read(CSR_HVIPH);
-		csr->hviprio1h = csr_read(CSR_HVIPRIO1H);
-		csr->hviprio2h = csr_read(CSR_HVIPRIO2H);
-#endif
 	}
 }
 
@@ -226,10 +166,6 @@ int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu,
 	if (kvm_riscv_aia_available()) {
 		((unsigned long *)csr)[reg_num] = val;
 
-#ifdef CONFIG_32BIT
-		if (reg_num == KVM_REG_RISCV_CSR_AIA_REG(siph))
-			WRITE_ONCE(vcpu->arch.irqs_pending_mask[1], 0);
-#endif
 	}
 
 	return 0;
@@ -282,19 +218,8 @@ static u8 aia_get_iprio8(struct kvm_vcpu *vcpu, unsigned int irq)
 		hviprio = ncsr_read(CSR_HVIPRIO1);
 		break;
 	case 1:
-#ifndef CONFIG_32BIT
 		hviprio = ncsr_read(CSR_HVIPRIO2);
 		break;
-#else
-		hviprio = ncsr_read(CSR_HVIPRIO1H);
-		break;
-	case 2:
-		hviprio = ncsr_read(CSR_HVIPRIO2);
-		break;
-	case 3:
-		hviprio = ncsr_read(CSR_HVIPRIO2H);
-		break;
-#endif
 	default:
 		return 0;
 	}
@@ -315,19 +240,8 @@ static void aia_set_iprio8(struct kvm_vcpu *vcpu, unsigned int irq, u8 prio)
 		hviprio = ncsr_read(CSR_HVIPRIO1);
 		break;
 	case 1:
-#ifndef CONFIG_32BIT
-		hviprio = ncsr_read(CSR_HVIPRIO2);
-		break;
-#else
-		hviprio = ncsr_read(CSR_HVIPRIO1H);
-		break;
-	case 2:
 		hviprio = ncsr_read(CSR_HVIPRIO2);
 		break;
-	case 3:
-		hviprio = ncsr_read(CSR_HVIPRIO2H);
-		break;
-#endif
 	default:
 		return;
 	}
@@ -340,19 +254,8 @@ static void aia_set_iprio8(struct kvm_vcpu *vcpu, unsigned int irq, u8 prio)
 		ncsr_write(CSR_HVIPRIO1, hviprio);
 		break;
 	case 1:
-#ifndef CONFIG_32BIT
 		ncsr_write(CSR_HVIPRIO2, hviprio);
 		break;
-#else
-		ncsr_write(CSR_HVIPRIO1H, hviprio);
-		break;
-	case 2:
-		ncsr_write(CSR_HVIPRIO2, hviprio);
-		break;
-	case 3:
-		ncsr_write(CSR_HVIPRIO2H, hviprio);
-		break;
-#endif
 	default:
 		return;
 	}
@@ -366,10 +269,8 @@ static int aia_rmw_iprio(struct kvm_vcpu *vcpu, unsigned int isel,
 	unsigned long old_val;
 	u8 prio;
 
-#ifndef CONFIG_32BIT
 	if (isel & 0x1)
 		return KVM_INSN_ILLEGAL_TRAP;
-#endif
 
 	nirqs = 4 * (BITS_PER_LONG / 32);
 	first_irq = (isel - ISELECT_IPRIO0) * 4;
@@ -577,12 +478,6 @@ void kvm_riscv_aia_enable(void)
 	csr_write(CSR_HVICTL, aia_hvictl_value(false));
 	csr_write(CSR_HVIPRIO1, 0x0);
 	csr_write(CSR_HVIPRIO2, 0x0);
-#ifdef CONFIG_32BIT
-	csr_write(CSR_HVIPH, 0x0);
-	csr_write(CSR_HIDELEGH, 0x0);
-	csr_write(CSR_HVIPRIO1H, 0x0);
-	csr_write(CSR_HVIPRIO2H, 0x0);
-#endif
 
 	/* Enable per-CPU SGEI interrupt */
 	enable_percpu_irq(hgei_parent_irq,
arch/riscv/kvm/aia_imsic.c +0 -34
index a8085cd8215e..16c44b10ee97 100644
@@ -258,13 +258,7 @@ static u32 imsic_mrif_topei(struct imsic_mrif *mrif, u32 nr_eix, u32 nr_msis)
 		eix = &mrif->eix[ei];
 		eipend[0] = imsic_mrif_atomic_read(mrif, &eix->eie[0]) &
 			    imsic_mrif_atomic_read(mrif, &eix->eip[0]);
-#ifdef CONFIG_32BIT
-		eipend[1] = imsic_mrif_atomic_read(mrif, &eix->eie[1]) &
-			    imsic_mrif_atomic_read(mrif, &eix->eip[1]);
-		if (!eipend[0] && !eipend[1])
-#else
 		if (!eipend[0])
-#endif
 			continue;
 
 		imin = ei * BITS_PER_TYPE(u64);
@@ -296,10 +290,8 @@ static int imsic_mrif_isel_check(u32 nr_eix, unsigned long isel)
 	default:
 		return -ENOENT;
 	}
-#ifndef CONFIG_32BIT
 	if (num & 0x1)
 		return -EINVAL;
-#endif
 	if ((num / 2) >= nr_eix)
 		return -EINVAL;
 
@@ -337,13 +329,9 @@ static int imsic_mrif_rmw(struct imsic_mrif *mrif, u32 nr_eix,
 			return -EINVAL;
 		eix = &mrif->eix[num / 2];
 
-#ifndef CONFIG_32BIT
 		if (num & 0x1)
 			return -EINVAL;
 		ei = (pend) ? &eix->eip[0] : &eix->eie[0];
-#else
-		ei = (pend) ? &eix->eip[num & 0x1] : &eix->eie[num & 0x1];
-#endif
 
 		/* Bit0 of EIP0 or EIE0 is read-only */
 		if (!num)
@@ -395,10 +383,6 @@ static void imsic_vsfile_local_read(void *data)
 			eix = &mrif->eix[i];
 			eix->eip[0] = imsic_eix_swap(IMSIC_EIP0 + i * 2, 0);
 			eix->eie[0] = imsic_eix_swap(IMSIC_EIE0 + i * 2, 0);
-#ifdef CONFIG_32BIT
-			eix->eip[1] = imsic_eix_swap(IMSIC_EIP0 + i * 2 + 1, 0);
-			eix->eie[1] = imsic_eix_swap(IMSIC_EIE0 + i * 2 + 1, 0);
-#endif
 		}
 	} else {
 		mrif->eidelivery = imsic_vs_csr_read(IMSIC_EIDELIVERY);
@@ -407,10 +391,6 @@ static void imsic_vsfile_local_read(void *data)
 			eix = &mrif->eix[i];
 			eix->eip[0] = imsic_eix_read(IMSIC_EIP0 + i * 2);
 			eix->eie[0] = imsic_eix_read(IMSIC_EIE0 + i * 2);
-#ifdef CONFIG_32BIT
-			eix->eip[1] = imsic_eix_read(IMSIC_EIP0 + i * 2 + 1);
-			eix->eie[1] = imsic_eix_read(IMSIC_EIE0 + i * 2 + 1);
-#endif
 		}
 	}
 
@@ -469,10 +449,8 @@ static void imsic_vsfile_local_rw(void *data)
 		break;
 	case IMSIC_EIP0 ... IMSIC_EIP63:
 	case IMSIC_EIE0 ... IMSIC_EIE63:
-#ifndef CONFIG_32BIT
 		if (idata->isel & 0x1)
 			break;
-#endif
 		if (idata->write)
 			imsic_eix_write(idata->isel, idata->val);
 		else
@@ -536,10 +514,6 @@ static void imsic_vsfile_local_clear(int vsfile_hgei, u32 nr_eix)
 	for (i = 0; i < nr_eix; i++) {
 		imsic_eix_write(IMSIC_EIP0 + i * 2, 0);
 		imsic_eix_write(IMSIC_EIE0 + i * 2, 0);
-#ifdef CONFIG_32BIT
-		imsic_eix_write(IMSIC_EIP0 + i * 2 + 1, 0);
-		imsic_eix_write(IMSIC_EIE0 + i * 2 + 1, 0);
-#endif
 	}
 
 	csr_write(CSR_HSTATUS, old_hstatus);
@@ -573,10 +547,6 @@ static void imsic_vsfile_local_update(int vsfile_hgei, u32 nr_eix,
 		eix = &mrif->eix[i];
 		imsic_eix_set(IMSIC_EIP0 + i * 2, eix->eip[0]);
 		imsic_eix_set(IMSIC_EIE0 + i * 2, eix->eie[0]);
-#ifdef CONFIG_32BIT
-		imsic_eix_set(IMSIC_EIP0 + i * 2 + 1, eix->eip[1]);
-		imsic_eix_set(IMSIC_EIE0 + i * 2 + 1, eix->eie[1]);
-#endif
 	}
 	imsic_vs_csr_write(IMSIC_EITHRESHOLD, mrif->eithreshold);
 	imsic_vs_csr_write(IMSIC_EIDELIVERY, mrif->eidelivery);
@@ -667,10 +637,6 @@ static void imsic_swfile_update(struct kvm_vcpu *vcpu,
 		eix = &mrif->eix[i];
 		imsic_mrif_atomic_or(smrif, &seix->eip[0], eix->eip[0]);
 		imsic_mrif_atomic_or(smrif, &seix->eie[0], eix->eie[0]);
-#ifdef CONFIG_32BIT
-		imsic_mrif_atomic_or(smrif, &seix->eip[1], eix->eip[1]);
-		imsic_mrif_atomic_or(smrif, &seix->eie[1], eix->eie[1]);
-#endif
 	}
 
 	imsic_swfile_extirq_update(vcpu);
arch/riscv/kvm/mmu.c +0 -8
index 1087ea74567b..2aee1100d450 100644
@@ -19,15 +19,9 @@
 #include <asm/page.h>
 #include <asm/pgtable.h>
 
-#ifdef CONFIG_64BIT
 static unsigned long gstage_mode __ro_after_init = (HGATP_MODE_SV39X4 << HGATP_MODE_SHIFT);
 static unsigned long gstage_pgd_levels __ro_after_init = 3;
 #define gstage_index_bits	9
-#else
-static unsigned long gstage_mode __ro_after_init = (HGATP_MODE_SV32X4 << HGATP_MODE_SHIFT);
-static unsigned long gstage_pgd_levels __ro_after_init = 2;
-#define gstage_index_bits	10
-#endif
 
 #define gstage_pgd_xbits	2
 #define gstage_pgd_size	(1UL << (HGATP_PAGE_SHIFT + gstage_pgd_xbits))
@@ -739,7 +733,6 @@ void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu)
 
 void __init kvm_riscv_gstage_mode_detect(void)
 {
-#ifdef CONFIG_64BIT
 	/* Try Sv57x4 G-stage mode */
 	csr_write(CSR_HGATP, HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT);
 	if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV57X4) {
@@ -758,7 +751,6 @@ void __init kvm_riscv_gstage_mode_detect(void)
 
 	csr_write(CSR_HGATP, 0);
 	kvm_riscv_local_hfence_gvma_all();
-#endif
 }
 
 unsigned long __init kvm_riscv_gstage_mode(void)
arch/riscv/kvm/vcpu_exit.c +0 -4
index fa98e5c024b2..f5d598f6acfc 100644
@@ -107,11 +107,7 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu,
 			".option push\n"
 			".option norvc\n"
 			"add %[ttmp], %[taddr], 0\n"
-#ifdef CONFIG_64BIT
 			HLV_D(%[val], %[addr])
-#else
-			HLV_W(%[val], %[addr])
-#endif
 			".option pop"
 		: [val] "=&r" (val),
 		  [taddr] "+&r" (taddr), [ttmp] "+&r" (ttmp)
arch/riscv/kvm/vcpu_insn.c +0 -12
index 97dec18e6989..913c454bee26 100644
@@ -78,11 +78,7 @@
 
 #define INSN_LEN(insn)		(INSN_IS_16BIT(insn) ? 2 : 4)
 
-#ifdef CONFIG_64BIT
 #define LOG_REGBYTES		3
-#else
-#define LOG_REGBYTES		2
-#endif
 #define REGBYTES		(1 << LOG_REGBYTES)
 
 #define SH_RD			7
@@ -522,19 +518,16 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	} else if ((insn & INSN_MASK_LBU) == INSN_MATCH_LBU) {
 		len = 1;
 		shift = 8 * (sizeof(ulong) - len);
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
 	} else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) {
 		len = 4;
-#endif
 	} else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) {
 		len = 2;
 		shift = 8 * (sizeof(ulong) - len);
 	} else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) {
 		len = 2;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
@@ -543,7 +536,6 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		   ((insn >> SH_RD) & 0x1f)) {
 		len = 8;
 		shift = 8 * (sizeof(ulong) - len);
-#endif
 	} else if ((insn & INSN_MASK_C_LW) == INSN_MATCH_C_LW) {
 		len = 4;
 		shift = 8 * (sizeof(ulong) - len);
@@ -645,13 +637,10 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		len = 4;
 	} else if ((insn & INSN_MASK_SB) == INSN_MATCH_SB) {
 		len = 1;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) {
 		len = 8;
-#endif
 	} else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) {
 		len = 2;
-#ifdef CONFIG_64BIT
 	} else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
 		len = 8;
 		data64 = GET_RS2S(insn, &vcpu->arch.guest_context);
@@ -659,7 +648,6 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		   ((insn >> SH_RD) & 0x1f)) {
 		len = 8;
 		data64 = GET_RS2C(insn, &vcpu->arch.guest_context);
-#endif
 	} else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) {
 		len = 4;
 		data32 = GET_RS2S(insn, &vcpu->arch.guest_context);
arch/riscv/kvm/vcpu_sbi_pmu.c +0 -8
index e4be34e03e83..0871265416fa 100644
@@ -35,11 +35,7 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		ret = kvm_riscv_vcpu_pmu_ctr_info(vcpu, cp->a0, retdata);
 		break;
 	case SBI_EXT_PMU_COUNTER_CFG_MATCH:
-#if defined(CONFIG_32BIT)
-		temp = ((uint64_t)cp->a5 << 32) | cp->a4;
-#else
 		temp = cp->a4;
-#endif
 		/*
 		 * This can fail if perf core framework fails to create an event.
 		 * No need to forward the error to userspace and exit the guest.
@@ -50,11 +46,7 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 						       cp->a2, cp->a3, temp, retdata);
 		break;
 	case SBI_EXT_PMU_COUNTER_START:
-#if defined(CONFIG_32BIT)
-		temp = ((uint64_t)cp->a4 << 32) | cp->a3;
-#else
 		temp = cp->a3;
-#endif
 		ret = kvm_riscv_vcpu_pmu_ctr_start(vcpu, cp->a0, cp->a1, cp->a2,
 						   temp, retdata);
 		break;
arch/riscv/kvm/vcpu_sbi_replace.c +0 -4
index 9c2ab3dfa93a..9276140644d1 100644
@@ -26,11 +26,7 @@ static int kvm_sbi_ext_time_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 	}
 
 	kvm_riscv_vcpu_pmu_incr_fw(vcpu, SBI_PMU_FW_SET_TIMER);
-#if __riscv_xlen == 32
-	next_cycle = ((u64)cp->a1 << 32) | (u64)cp->a0;
-#else
 	next_cycle = (u64)cp->a0;
-#endif
 	kvm_riscv_vcpu_timer_next_event(vcpu, next_cycle);
 
 	return 0;
arch/riscv/kvm/vcpu_sbi_v01.c +0 -4
index 8f4c4fa16227..e06ba01392d6 100644
@@ -35,11 +35,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		retdata->uexit = true;
 		break;
 	case SBI_EXT_0_1_SET_TIMER:
-#if __riscv_xlen == 32
-		next_cycle = ((u64)cp->a1 << 32) | (u64)cp->a0;
-#else
 		next_cycle = (u64)cp->a0;
-#endif
 		ret = kvm_riscv_vcpu_timer_next_event(vcpu, next_cycle);
 		break;
 	case SBI_EXT_0_1_CLEAR_IPI:
arch/riscv/kvm/vcpu_timer.c +0 -20
index 96e7a4e463f7..fc32338b8cf8 100644
@@ -71,12 +71,7 @@ static int kvm_riscv_vcpu_timer_cancel(struct kvm_vcpu_timer *t)
 
 static int kvm_riscv_vcpu_update_vstimecmp(struct kvm_vcpu *vcpu, u64 ncycles)
 {
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_VSTIMECMP, ncycles & 0xFFFFFFFF);
-	ncsr_write(CSR_VSTIMECMPH, ncycles >> 32);
-#else
 	ncsr_write(CSR_VSTIMECMP, ncycles);
-#endif
 	return 0;
 }
 
@@ -288,12 +283,7 @@ static void kvm_riscv_vcpu_update_timedelta(struct kvm_vcpu *vcpu)
 {
 	struct kvm_guest_timer *gt = &vcpu->kvm->arch.timer;
 
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_HTIMEDELTA, (u32)(gt->time_delta));
-	ncsr_write(CSR_HTIMEDELTAH, (u32)(gt->time_delta >> 32));
-#else
 	ncsr_write(CSR_HTIMEDELTA, gt->time_delta);
-#endif
 }
 
 void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu)
@@ -305,12 +295,7 @@ void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu)
 	if (!t->sstc_enabled)
 		return;
 
-#if defined(CONFIG_32BIT)
-	ncsr_write(CSR_VSTIMECMP, (u32)t->next_cycles);
-	ncsr_write(CSR_VSTIMECMPH, (u32)(t->next_cycles >> 32));
-#else
 	ncsr_write(CSR_VSTIMECMP, t->next_cycles);
-#endif
 
 	/* timer should be enabled for the remaining operations */
 	if (unlikely(!t->init_done))
@@ -326,12 +311,7 @@ void kvm_riscv_vcpu_timer_sync(struct kvm_vcpu *vcpu)
 	if (!t->sstc_enabled)
 		return;
 
-#if defined(CONFIG_32BIT)
 	t->next_cycles = ncsr_read(CSR_VSTIMECMP);
-	t->next_cycles |= (u64)ncsr_read(CSR_VSTIMECMPH) << 32;
-#else
-	t->next_cycles = ncsr_read(CSR_VSTIMECMP);
-#endif
 }
 
 void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu)
Signature · 1 line
2.39.5

I've tested this patch with my rv64 kvm environment, and it's okay.

#4 lore raw

Re: [PATCH v2 2/5] riscv: kvm: drop 32-bit host support

In reply to Arnd Bergmann

Hi Arnd,

Quoted 105 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

KVM support on RISC-V includes both 32-bit and 64-bit host mode, but in practice, all RISC-V SoCs that may use this are 64-bit:

As of linux-6.13, there is no mainline Linux support for any specific 32-bit SoC in arch/riscv/, although the generic qemu model should work.

The available RV32 CPU implementations are mostly built for microcontroller applications and are lacking a memory management unit. There are a few CPU cores with an MMU, but those still lack the hypervisor extensions needed for running KVM.

This is unlikely to change in the future, so remove the 32-bit host code and simplify the test matrix.

---
 arch/riscv/kvm/Kconfig            |   2 +-
 arch/riscv/kvm/aia.c              | 105 ------------------------------
 arch/riscv/kvm/aia_imsic.c        |  34 ----------
 arch/riscv/kvm/mmu.c              |   8 ---
 arch/riscv/kvm/vcpu_exit.c        |   4 --
 arch/riscv/kvm/vcpu_insn.c        |  12 ----
 arch/riscv/kvm/vcpu_sbi_pmu.c     |   8 ---
 arch/riscv/kvm/vcpu_sbi_replace.c |   4 --
 arch/riscv/kvm/vcpu_sbi_v01.c     |   4 --
 arch/riscv/kvm/vcpu_timer.c       |  20 ------
 10 files changed, 1 insertion(+), 200 deletions(-)
arch/riscv/kvm/Kconfig +1 -1
index 0c3cbb0915ff..7405722e4433 100644
@@ -19,7 +19,7 @@ if VIRTUALIZATION
 
 config KVM
 	tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)"
-	depends on RISCV_SBI && MMU
+	depends on RISCV_SBI && MMU && 64BIT
 	select HAVE_KVM_IRQCHIP
 	select HAVE_KVM_IRQ_ROUTING
 	select HAVE_KVM_MSI
arch/riscv/kvm/aia.c +0 -36
index 19afd1f23537..a399a5a9af0e 100644
@@ -66,33 +66,6 @@ static inline unsigned long aia_hvictl_value(bool ext_irq_pending)
 	return hvictl;
 }
 
-#ifdef CONFIG_32BIT
-void kvm_riscv_vcpu_aia_flush_interrupts(struct kvm_vcpu *vcpu)
-{
-	struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
-	unsigned long mask, val;
-
-	if (!kvm_riscv_aia_available())
-		return;
-
-	if (READ_ONCE(vcpu->arch.irqs_pending_mask[1])) {
-		mask = xchg_acquire(&vcpu->arch.irqs_pending_mask[1], 0);
-		val = READ_ONCE(vcpu->arch.irqs_pending[1]) & mask;
-
-		csr->hviph &= ~mask;
-		csr->hviph |= val;
-	}
-}
-
-void kvm_riscv_vcpu_aia_sync_interrupts(struct kvm_vcpu *vcpu)
-{
-	struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
-
-	if (kvm_riscv_aia_available())
-		csr->vsieh = ncsr_read(CSR_VSIEH);
-}
-#endif
-
 bool kvm_riscv_vcpu_aia_has_interrupts(struct kvm_vcpu *vcpu, u64 mask)
 {
 	int hgei;
@@ -101,12 +74,6 @@ bool kvm_riscv_vcpu_aia_has_interrupts(struct kvm_vcpu *vcpu, u64 mask)
 	if (!kvm_riscv_aia_available())
 		return false;
 
-#ifdef CONFIG_32BIT
-	if (READ_ONCE(vcpu->arch.irqs_pending[1]) &
-	    (vcpu->arch.aia_context.guest_csr.vsieh & upper_32_bits(mask)))
-		return true;
-#endif
-
 	seip = vcpu->arch.guest_csr.vsie;
 	seip &= (unsigned long)mask;
 	seip &= BIT(IRQ_S_EXT);
@@ -128,9 +95,6 @@ void kvm_riscv_vcpu_aia_update_hvip(struct kvm_vcpu *vcpu)
 	if (!kvm_riscv_aia_available())
 		return;
 
-#ifdef CONFIG_32BIT
-	ncsr_write(CSR_HVIPH, vcpu->arch.aia_context.guest_csr.hviph);
-#endif
 	ncsr_write(CSR_HVICTL, aia_hvictl_value(!!(csr->hvip & BIT(IRQ_VS_EXT))));
 }
 

arch/riscv/kvm/aia.c void kvm_riscv_vcpu_aia_load(struct kvm_vcpu *vcpu, int cpu) · line 155

Quoted 9 lines
arch/riscv/kvm/aia.c +0 -6
@@ -147,22 +111,10 @@ void kvm_riscv_vcpu_aia_load(struct kvm_vcpu *vcpu, int cpu)
 		nacl_csr_write(nsh, CSR_VSISELECT, csr->vsiselect);
 		nacl_csr_write(nsh, CSR_HVIPRIO1, csr->hviprio1);
 		nacl_csr_write(nsh, CSR_HVIPRIO2, csr->hviprio2);
-#ifdef CONFIG_32BIT
-		nacl_csr_write(nsh, CSR_VSIEH, csr->vsieh);
-		nacl_csr_write(nsh, CSR_HVIPH, csr->hviph);
-		nacl_csr_write(nsh, CSR_HVIPRIO1H, csr->hviprio1h);
-		nacl_csr_write(nsh, CSR_HVIPRIO2H, csr->hviprio2h);
-#endif

One minor cleanup: since this patch removes all accesses to these 32-bit-only high-half CSRs, the corresponding members should also be removed from struct kvm_vcpu_aia_csr in asm/kvm_aia.h.

Regards,
Samuel

#5 lore raw

PATCH v2 3/5 powerpc: kvm: drop 32-bit booke

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

KVM on PowerPC BookE was introduced in 2008 and supported IBM 44x, Freescale e500v2 (32-bit mpc85xx, QuorIQ P1/P2), e500mc (32bit QorIQ P2/P3/P4), e5500 (64-bit QorIQ P5/T1) and e6500 (64-bit QorIQ T2/T4).

Support for 44x was dropped in 2014 as it was seeing very little use, but e500v2 and e500mc are still supported as most of the code is shared with the 64-bit e5500/e6500 implementation.

The last of those 32-bit chips were introduced in 2010 but not widely adopted when the following 64-bit PowerPC and Arm variants ended up being more successful.

The 64-bit e5500/e6500 are still known to be used with KVM, but I could not find any evidence of continued use of the 32-bit ones, so drop discontinue those in order to simplify the implementation. The changes are purely mechanical, dropping all #ifdef checks for CONFIG_64BIT, CONFIG_KVM_E500V2, CONFIG_KVM_E500MC, CONFIG_KVM_BOOKE_HV, CONFIG_PPC_85xx, CONFIG_PPC_FPU, CONFIG_SPE and CONFIG_SPE_POSSIBLE, which are all known on e5500/e6500.

Support for 64-bit hosts remains unchanged, for both 32-bit and 64-bit guests.

---
 arch/powerpc/include/asm/kvm_book3s_32.h    |  36 --
 arch/powerpc/include/asm/kvm_booke.h        |   4 -
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   2 -
 arch/powerpc/kernel/head_85xx.S             |  14 -
 arch/powerpc/kernel/head_booke.h            |  39 --
 arch/powerpc/kvm/Kconfig                    |  22 +-
 arch/powerpc/kvm/Makefile                   |  15 -
 arch/powerpc/kvm/book3s_32_mmu_host.c       | 396 --------------
 arch/powerpc/kvm/booke.c                    | 268 ----------
 arch/powerpc/kvm/booke.h                    |   8 -
 arch/powerpc/kvm/booke_emulate.c            |  44 --
 arch/powerpc/kvm/booke_interrupts.S         | 535 -------------------
 arch/powerpc/kvm/bookehv_interrupts.S       | 102 ----
 arch/powerpc/kvm/e500.c                     | 553 --------------------
 arch/powerpc/kvm/e500.h                     |  40 --
 arch/powerpc/kvm/e500_emulate.c             | 100 ----
 arch/powerpc/kvm/e500_mmu_host.c            |  54 --
 arch/powerpc/kvm/e500mc.c                   |   5 +-
 arch/powerpc/kvm/trace_booke.h              |  14 -
 19 files changed, 4 insertions(+), 2247 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/kvm_book3s_32.h
 delete mode 100644 arch/powerpc/kvm/book3s_32_mmu_host.c
 delete mode 100644 arch/powerpc/kvm/booke_interrupts.S
 delete mode 100644 arch/powerpc/kvm/e500.c
arch/powerpc/include/asm/kvm_book3s_32.h deleted +0 -36
deleted file mode 100644
index e9d2e8463105..000000000000
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- *
- * Copyright SUSE Linux Products GmbH 2010
- *
- * Authors: Alexander Graf <[email protected]>
- */
-
-#ifndef __ASM_KVM_BOOK3S_32_H__
-#define __ASM_KVM_BOOK3S_32_H__
-
-static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get(struct kvm_vcpu *vcpu)
-{
-	return vcpu->arch.shadow_vcpu;
-}
-
-static inline void svcpu_put(struct kvmppc_book3s_shadow_vcpu *svcpu)
-{
-}
-
-#define PTE_SIZE	12
-#define VSID_ALL	0
-#define SR_INVALID	0x00000001	/* VSID 1 should always be unused */
-#define SR_KP		0x20000000
-#define PTE_V		0x80000000
-#define PTE_SEC		0x00000040
-#define PTE_M		0x00000010
-#define PTE_R		0x00000100
-#define PTE_C		0x00000080
-
-#define SID_SHIFT	28
-#define ESID_MASK	0xf0000000
-#define VSID_MASK	0x00fffffff0000000ULL
-#define VPN_SHIFT	12
-
-#endif /* __ASM_KVM_BOOK3S_32_H__ */
arch/powerpc/include/asm/kvm_booke.h +0 -4
index 7c3291aa8922..59349cb5a94c 100644
@@ -109,10 +109,6 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
 static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu)
 {
 	/* Magic page is only supported on e500v2 */
-#ifdef CONFIG_KVM_E500V2
-	return true;
-#else
 	return false;
-#endif
 }
 #endif /* __ASM_KVM_BOOKE_H__ */
arch/powerpc/include/asm/kvm_booke_hv_asm.h +0 -2
index 7487ef582121..5bc10d113575 100644
@@ -54,14 +54,12 @@
  * Only the bolted version of TLB miss exception handlers is supported now.
  */
 .macro DO_KVM intno srr1
-#ifdef CONFIG_KVM_BOOKE_HV
 BEGIN_FTR_SECTION
 	mtocrf	0x80, r11	/* check MSR[GS] without clobbering reg */
 	bf	3, 1975f
 	b	kvmppc_handler_\intno\()_\srr1
 1975:
 END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
-#endif
 .endm
 
 #endif /*__ASSEMBLY__ */
arch/powerpc/kernel/head_85xx.S +0 -14
index f9a73fae6464..661903d31b54 100644
@@ -425,16 +425,10 @@ interrupt_base:
 	mtspr	SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
 	mfspr	r10, SPRN_SPRG_THREAD
 	stw	r11, THREAD_NORMSAVE(0)(r10)
-#ifdef CONFIG_KVM_BOOKE_HV
-BEGIN_FTR_SECTION
-	mfspr	r11, SPRN_SRR1
-END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
-#endif
 	stw	r12, THREAD_NORMSAVE(1)(r10)
 	stw	r13, THREAD_NORMSAVE(2)(r10)
 	mfcr	r13
 	stw	r13, THREAD_NORMSAVE(3)(r10)
-	DO_KVM	BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1
 START_BTB_FLUSH_SECTION
 	mfspr r11, SPRN_SRR1
 	andi. r10,r11,MSR_PR
@@ -517,16 +511,10 @@ END_BTB_FLUSH_SECTION
 	mtspr	SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
 	mfspr	r10, SPRN_SPRG_THREAD
 	stw	r11, THREAD_NORMSAVE(0)(r10)
-#ifdef CONFIG_KVM_BOOKE_HV
-BEGIN_FTR_SECTION
-	mfspr	r11, SPRN_SRR1
-END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
-#endif
 	stw	r12, THREAD_NORMSAVE(1)(r10)
 	stw	r13, THREAD_NORMSAVE(2)(r10)
 	mfcr	r13
 	stw	r13, THREAD_NORMSAVE(3)(r10)
-	DO_KVM	BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR1
 START_BTB_FLUSH_SECTION
 	mfspr r11, SPRN_SRR1
 	andi. r10,r11,MSR_PR
@@ -660,8 +648,6 @@ END_BTB_FLUSH_SECTION
 	DEBUG_DEBUG_EXCEPTION
 	DEBUG_CRIT_EXCEPTION
 
-	GUEST_DOORBELL_EXCEPTION
-
 	CRITICAL_EXCEPTION(0, GUEST_DBELL_CRIT, CriticalGuestDoorbell, \
 			   unknown_exception)
 
arch/powerpc/kernel/head_booke.h +0 -39
index 0b5c1993809e..d1ffef4d05b5 100644
@@ -3,8 +3,6 @@
 #define __HEAD_BOOKE_H__
 
 #include <asm/ptrace.h>	/* for STACK_FRAME_REGS_MARKER */
-#include <asm/kvm_asm.h>
-#include <asm/kvm_booke_hv_asm.h>
 #include <asm/thread_info.h>	/* for THREAD_SHIFT */
 
 #ifdef __ASSEMBLY__
@@ -52,7 +50,6 @@ END_BTB_FLUSH_SECTION
 	stw	r13, THREAD_NORMSAVE(2)(r10);				     \
 	mfcr	r13;			/* save CR in r13 for now	   */\
 	mfspr	r11, SPRN_SRR1;		                                     \
-	DO_KVM	BOOKE_INTERRUPT_##intno SPRN_SRR1;			     \
 	andi.	r11, r11, MSR_PR;	/* check whether user or kernel    */\
 	LOAD_REG_IMMEDIATE(r11, MSR_KERNEL);				\
 	mtmsr	r11;							\
@@ -114,25 +111,7 @@ END_BTB_FLUSH_SECTION
 
 .macro SYSCALL_ENTRY trapno intno srr1
 	mfspr	r10, SPRN_SPRG_THREAD
-#ifdef CONFIG_KVM_BOOKE_HV
-BEGIN_FTR_SECTION
-	mtspr	SPRN_SPRG_WSCRATCH0, r10
-	stw	r11, THREAD_NORMSAVE(0)(r10)
-	stw	r13, THREAD_NORMSAVE(2)(r10)
-	mfcr	r13			/* save CR in r13 for now	   */
-	mfspr	r11, SPRN_SRR1
-	mtocrf	0x80, r11	/* check MSR[GS] without clobbering reg */
-	bf	3, 1975f
-	b	kvmppc_handler_\intno\()_\srr1
-1975:
-	mr	r12, r13
-	lwz	r13, THREAD_NORMSAVE(2)(r10)
-FTR_SECTION_ELSE
 	mfcr	r12
-ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
-#else
-	mfcr	r12
-#endif
 	mfspr	r9, SPRN_SRR1
 	BOOKE_CLEAR_BTB(r11)
 	mr	r11, r1
@@ -198,7 +177,6 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
 	stw	r11,GPR11(r8);						     \
 	stw	r9,_CCR(r8);		/* save CR on stack		   */\
 	mfspr	r11,exc_level_srr1;	/* check whether user or kernel    */\
-	DO_KVM	BOOKE_INTERRUPT_##intno exc_level_srr1;		             \
 	BOOKE_CLEAR_BTB(r10)						\
 	andi.	r11,r11,MSR_PR;						     \
 	LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE));	\
@@ -272,23 +250,6 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
 		EXC_LEVEL_EXCEPTION_PROLOG(MC, trapno+4, MACHINE_CHECK, \
 			SPRN_MCSRR0, SPRN_MCSRR1)
 
-/*
- * Guest Doorbell -- this is a bit odd in that uses GSRR0/1 despite
- * being delivered to the host.  This exception can only happen
- * inside a KVM guest -- so we just handle up to the DO_KVM rather
- * than try to fit this into one of the existing prolog macros.
- */
-#define GUEST_DOORBELL_EXCEPTION \
-	START_EXCEPTION(GuestDoorbell);					     \
-	mtspr	SPRN_SPRG_WSCRATCH0, r10;	/* save one register */	     \
-	mfspr	r10, SPRN_SPRG_THREAD;					     \
-	stw	r11, THREAD_NORMSAVE(0)(r10);				     \
-	mfspr	r11, SPRN_SRR1;		                                     \
-	stw	r13, THREAD_NORMSAVE(2)(r10);				     \
-	mfcr	r13;			/* save CR in r13 for now	   */\
-	DO_KVM	BOOKE_INTERRUPT_GUEST_DBELL SPRN_GSRR1;			     \
-	trap
-
 /*
  * Exception vectors.
  */
arch/powerpc/kvm/Kconfig +3 -19
index dbfdc126bf14..e2230ea512cf 100644
@@ -185,25 +185,9 @@ config KVM_EXIT_TIMING
 
 	  If unsure, say N.
 
-config KVM_E500V2
-	bool "KVM support for PowerPC E500v2 processors"
-	depends on PPC_E500 && !PPC_E500MC
-	depends on !CONTEXT_TRACKING_USER
-	select KVM
-	select KVM_MMIO
-	select KVM_GENERIC_MMU_NOTIFIER
-	help
-	  Support running unmodified E500 guest kernels in virtual machines on
-	  E500v2 host processors.
-
-	  This module provides access to the hardware capabilities through
-	  a character device node named /dev/kvm.
-
-	  If unsure, say N.
-
 config KVM_E500MC
-	bool "KVM support for PowerPC E500MC/E5500/E6500 processors"
-	depends on PPC_E500MC
+	bool "KVM support for PowerPC E5500/E6500 processors"
+	depends on PPC_E500MC && 64BIT
 	depends on !CONTEXT_TRACKING_USER
 	select KVM
 	select KVM_MMIO
@@ -211,7 +195,7 @@ config KVM_E500MC
 	select KVM_GENERIC_MMU_NOTIFIER
 	help
 	  Support running unmodified E500MC/E5500/E6500 guest kernels in
-	  virtual machines on E500MC/E5500/E6500 host processors.
+	  virtual machines on E5500/E6500 host processors.
 
 	  This module provides access to the hardware capabilities through
 	  a character device node named /dev/kvm.
arch/powerpc/kvm/Makefile +0 -15
index 4bd9d1230869..294f27439f7f 100644
@@ -11,20 +11,6 @@ common-objs-y += powerpc.o emulate_loadstore.o
 obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o
 obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o
 
-AFLAGS_booke_interrupts.o := -I$(objtree)/$(obj)
-
-kvm-e500-objs := \
-	$(common-objs-y) \
-	emulate.o \
-	booke.o \
-	booke_emulate.o \
-	booke_interrupts.o \
-	e500.o \
-	e500_mmu.o \
-	e500_mmu_host.o \
-	e500_emulate.o
-kvm-objs-$(CONFIG_KVM_E500V2) := $(kvm-e500-objs)
-
 kvm-e500mc-objs := \
 	$(common-objs-y) \
 	emulate.o \
@@ -127,7 +113,6 @@ kvm-objs-$(CONFIG_KVM_MPIC) += mpic.o
 
 kvm-y += $(kvm-objs-m) $(kvm-objs-y)
 
-obj-$(CONFIG_KVM_E500V2) += kvm.o
 obj-$(CONFIG_KVM_E500MC) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
arch/powerpc/kvm/book3s_32_mmu_host.c deleted +0 -396

396 lines not on this page · raw message

arch/powerpc/kvm/booke.c +0 -268

509 lines not on this page · raw message

arch/powerpc/kvm/booke.h +0 -8
index 9c5b8e76014f..72a8d2a0b0a2 100644
@@ -21,15 +21,8 @@
 #define BOOKE_IRQPRIO_ALIGNMENT 2
 #define BOOKE_IRQPRIO_PROGRAM 3
 #define BOOKE_IRQPRIO_FP_UNAVAIL 4
-#ifdef CONFIG_SPE_POSSIBLE
-#define BOOKE_IRQPRIO_SPE_UNAVAIL 5
-#define BOOKE_IRQPRIO_SPE_FP_DATA 6
-#define BOOKE_IRQPRIO_SPE_FP_ROUND 7
-#endif
-#ifdef CONFIG_PPC_E500MC
 #define BOOKE_IRQPRIO_ALTIVEC_UNAVAIL 5
 #define BOOKE_IRQPRIO_ALTIVEC_ASSIST 6
-#endif
 #define BOOKE_IRQPRIO_SYSCALL 8
 #define BOOKE_IRQPRIO_AP_UNAVAIL 9
 #define BOOKE_IRQPRIO_DTLB_MISS 10
@@ -59,7 +52,6 @@
 			  (1 << BOOKE_IRQPRIO_WATCHDOG) | \
 			  (1 << BOOKE_IRQPRIO_CRITICAL))
 
-extern unsigned long kvmppc_booke_handlers;
 extern unsigned long kvmppc_booke_handler_addr[];
 
 void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
arch/powerpc/kvm/booke_emulate.c +0 -44

96 lines not on this page · raw message

arch/powerpc/kvm/booke_interrupts.S deleted +0 -535

535 lines not on this page · raw message

arch/powerpc/kvm/bookehv_interrupts.S +0 -102

136 lines not on this page · raw message

arch/powerpc/kvm/e500.c deleted +0 -553

553 lines not on this page · raw message

arch/powerpc/kvm/e500.h +0 -40
index 6d0d329cbb35..325c190cc771 100644
@@ -46,10 +46,6 @@ struct tlbe_priv {
 	struct tlbe_ref ref;
 };
 
-#ifdef CONFIG_KVM_E500V2
-struct vcpu_id_table;
-#endif
-
 struct kvmppc_e500_tlb_params {
 	int entries, ways, sets;
 };
@@ -88,13 +84,6 @@ struct kvmppc_vcpu_e500 {
 	/* Minimum and maximum address mapped my TLB1 */
 	unsigned long tlb1_min_eaddr;
 	unsigned long tlb1_max_eaddr;
-
-#ifdef CONFIG_KVM_E500V2
-	u32 pid[E500_PID_NUM];
-
-	/* vcpu id table */
-	struct vcpu_id_table *idt;
-#endif
 };
 
 static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
@@ -140,12 +129,6 @@ int kvmppc_get_one_reg_e500_tlb(struct kvm_vcpu *vcpu, u64 id,
 int kvmppc_set_one_reg_e500_tlb(struct kvm_vcpu *vcpu, u64 id,
 			       union kvmppc_one_reg *val);
 
-#ifdef CONFIG_KVM_E500V2
-unsigned int kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 *vcpu_e500,
-				 unsigned int as, unsigned int gid,
-				 unsigned int pr, int avoid_recursion);
-#endif
-
 /* TLB helper functions */
 static inline unsigned int
 get_tlb_size(const struct kvm_book3e_206_tlb_entry *tlbe)
@@ -257,13 +240,6 @@ static inline int tlbe_is_host_safe(const struct kvm_vcpu *vcpu,
 	if (!get_tlb_v(tlbe))
 		return 0;
 
-#ifndef CONFIG_KVM_BOOKE_HV
-	/* Does it match current guest AS? */
-	/* XXX what about IS != DS? */
-	if (get_tlb_ts(tlbe) != !!(vcpu->arch.shared->msr & MSR_IS))
-		return 0;
-#endif
-
 	gpa = get_tlb_raddr(tlbe);
 	if (!gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT))
 		/* Mapping is not for RAM. */
@@ -283,7 +259,6 @@ void kvmppc_e500_tlbil_one(struct kvmppc_vcpu_e500 *vcpu_e500,
 			   struct kvm_book3e_206_tlb_entry *gtlbe);
 void kvmppc_e500_tlbil_all(struct kvmppc_vcpu_e500 *vcpu_e500);
 
-#ifdef CONFIG_KVM_BOOKE_HV
 #define kvmppc_e500_get_tlb_stid(vcpu, gtlbe)       get_tlb_tid(gtlbe)
 #define get_tlbmiss_tid(vcpu)           get_cur_pid(vcpu)
 #define get_tlb_sts(gtlbe)              (gtlbe->mas1 & MAS1_TS)
@@ -306,21 +281,6 @@ static inline int get_lpid(struct kvm_vcpu *vcpu)
 {
 	return get_thread_specific_lpid(vcpu->kvm->arch.lpid);
 }
-#else
-unsigned int kvmppc_e500_get_tlb_stid(struct kvm_vcpu *vcpu,
-				      struct kvm_book3e_206_tlb_entry *gtlbe);
-
-static inline unsigned int get_tlbmiss_tid(struct kvm_vcpu *vcpu)
-{
-	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-	unsigned int tidseld = (vcpu->arch.shared->mas4 >> 16) & 0xf;
-
-	return vcpu_e500->pid[tidseld];
-}
-
-/* Force TS=1 for all guest mappings. */
-#define get_tlb_sts(gtlbe)              (MAS1_TS)
-#endif /* !BOOKE_HV */
 
 static inline bool has_feature(const struct kvm_vcpu *vcpu,
 			       enum vcpu_ftr ftr)
arch/powerpc/kvm/e500_emulate.c +0 -100

172 lines not on this page · raw message

arch/powerpc/kvm/e500_mmu_host.c +0 -54

97 lines not on this page · raw message

arch/powerpc/kvm/e500mc.c +1 -4
index e476e107a932..844b2d6b6b49 100644
@@ -202,10 +202,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
 
 	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
-				 SPRN_EPCR_DUVD;
-#ifdef CONFIG_64BIT
-	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM;
-#endif
+				 SPRN_EPCR_DUVD | SPRN_EPCR_ICM;
 	vcpu->arch.shadow_msrp = MSRP_UCLEP | MSRP_PMMP;
 
 	vcpu->arch.pvr = mfspr(SPRN_PVR);
arch/powerpc/kvm/trace_booke.h +0 -14
index eff6e82dbcd4..dbc54059327f 100644
@@ -135,25 +135,11 @@ TRACE_EVENT(kvm_booke206_ref_release,
 		__entry->pfn, __entry->flags)
 );
 
-#ifdef CONFIG_SPE_POSSIBLE
-#define kvm_trace_symbol_irqprio_spe \
-	{BOOKE_IRQPRIO_SPE_UNAVAIL, "SPE_UNAVAIL"}, \
-	{BOOKE_IRQPRIO_SPE_FP_DATA, "SPE_FP_DATA"}, \
-	{BOOKE_IRQPRIO_SPE_FP_ROUND, "SPE_FP_ROUND"},
-#else
-#define kvm_trace_symbol_irqprio_spe
-#endif
-
-#ifdef CONFIG_PPC_E500MC
 #define kvm_trace_symbol_irqprio_e500mc \
 	{BOOKE_IRQPRIO_ALTIVEC_UNAVAIL, "ALTIVEC_UNAVAIL"}, \
 	{BOOKE_IRQPRIO_ALTIVEC_ASSIST, "ALTIVEC_ASSIST"},
-#else
-#define kvm_trace_symbol_irqprio_e500mc
-#endif
 
 #define kvm_trace_symbol_irqprio \
-	kvm_trace_symbol_irqprio_spe \
 	kvm_trace_symbol_irqprio_e500mc \
 	{BOOKE_IRQPRIO_DATA_STORAGE, "DATA_STORAGE"}, \
 	{BOOKE_IRQPRIO_INST_STORAGE, "INST_STORAGE"}, \
Signature · 1 line
2.39.5
#6 lore raw

Re: [PATCH v2 3/5] powerpc: kvm: drop 32-bit booke

Quoted 27 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

KVM on PowerPC BookE was introduced in 2008 and supported IBM 44x, Freescale e500v2 (32-bit mpc85xx, QuorIQ P1/P2), e500mc (32bit QorIQ P2/P3/P4), e5500 (64-bit QorIQ P5/T1) and e6500 (64-bit QorIQ T2/T4).

Support for 44x was dropped in 2014 as it was seeing very little use, but e500v2 and e500mc are still supported as most of the code is shared with the 64-bit e5500/e6500 implementation.

The last of those 32-bit chips were introduced in 2010 but not widely adopted when the following 64-bit PowerPC and Arm variants ended up being more successful.

The 64-bit e5500/e6500 are still known to be used with KVM, but I could not find any evidence of continued use of the 32-bit ones, so drop discontinue those in order to simplify the implementation. The changes are purely mechanical, dropping all #ifdef checks for CONFIG_64BIT, CONFIG_KVM_E500V2, CONFIG_KVM_E500MC, CONFIG_KVM_BOOKE_HV, CONFIG_PPC_85xx, CONFIG_PPC_FPU, CONFIG_SPE and CONFIG_SPE_POSSIBLE, which are all known on e5500/e6500.

Support for 64-bit hosts remains unchanged, for both 32-bit and 64-bit guests.

Quoted 9 lines
---
 arch/powerpc/include/asm/kvm_book3s_32.h    |  36 --
 arch/powerpc/include/asm/kvm_booke.h        |   4 -
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   2 -
 arch/powerpc/kernel/head_85xx.S             |  14 -
 arch/powerpc/kernel/head_booke.h            |  39 --
 arch/powerpc/kvm/Kconfig                    |  22 +-
 arch/powerpc/kvm/Makefile                   |  15 -
 arch/powerpc/kvm/book3s_32_mmu_host.c       | 396 --------------

Why are book3s files removed by this patch?

arch/powerpc/kvm/booke.c static inline void kvmppc_save_guest_altivec(struct kvm_vcpu *vcpu) · line 234

Quoted 8 lines
arch/powerpc/kvm/booke.c +0 -2
@@ -228,23 +176,16 @@ static inline void kvmppc_save_guest_altivec(struct kvm_vcpu *vcpu)
 static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
 {
 	/* Synchronize guest's desire to get debug interrupts into shadow MSR */
-#ifndef CONFIG_KVM_BOOKE_HV
 	vcpu->arch.shadow_msr &= ~MSR_DE;
 	vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_DE;
-#endif

This is an ifndef... the contents should be removed.

-Crystal

#7 lore raw

PATCH v2 4/5 powerpc: kvm: drop 32-bit book3s

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Support for KVM on 32-bit Book III-s implementations was added in 2010 and supports PowerMac, CHRP, and embedded platforms using the Freescale G4 (mpc74xx), e300 (mpc83xx) and e600 (mpc86xx) CPUs from 2003 to 2009.

Earlier 603/604/750 machines might work but would be even more limited by their available memory.

The only likely users of KVM on any of these were the final Apple PowerMac/PowerBook/iBook G4 models with 2GB of RAM that were at the high end 20 years ago but are just as obsolete as their x86-32 counterparts. The code has been orphaned since 2023.

There is still a need to support 32-bit guests in order to better debug problems on ppc32 kernels. This should work in theory on both 64-bit booke and on 64-bit book3s hosts, but it would be good to confirm that this is still the case before the known working option gets removed.

---
 MAINTAINERS                               |   2 +-
 arch/powerpc/include/asm/kvm_book3s.h     |  17 ---
 arch/powerpc/include/asm/kvm_book3s_asm.h |  10 --
 arch/powerpc/include/asm/kvm_host.h       |   2 +-
 arch/powerpc/include/asm/kvm_ppc.h        |   2 +-
 arch/powerpc/include/asm/processor.h      |   3 -
 arch/powerpc/kernel/asm-offsets.c         |  21 +---
 arch/powerpc/kernel/head_32.h             |  10 --
 arch/powerpc/kernel/head_book3s_32.S      |   5 -
 arch/powerpc/kvm/Kconfig                  |  22 ----
 arch/powerpc/kvm/Makefile                 |  15 ---
 arch/powerpc/kvm/book3s.c                 |  18 ----
 arch/powerpc/kvm/book3s_emulate.c         |  37 -------
 arch/powerpc/kvm/book3s_interrupts.S      |  11 --
 arch/powerpc/kvm/book3s_mmu_hpte.c        |  12 ---
 arch/powerpc/kvm/book3s_pr.c              | 122 +---------------------
 arch/powerpc/kvm/book3s_rmhandlers.S      | 110 -------------------
 arch/powerpc/kvm/book3s_segment.S         |  30 +-----
 arch/powerpc/kvm/emulate.c                |   2 -
 arch/powerpc/kvm/powerpc.c                |   2 -
 20 files changed, 7 insertions(+), 446 deletions(-)
MAINTAINERS +1 -1
index 52ba21efdd65..d9a20d934d95 100644
@@ -12717,7 +12717,7 @@ L:	[email protected]
 L:	[email protected]
 S:	Maintained (Book3S 64-bit HV)
 S:	Odd fixes (Book3S 64-bit PR)
-S:	Orphan (Book3E and 32-bit)
+S:	Orphan (Book3E)
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git topic/ppc-kvm
 F:	arch/powerpc/include/asm/kvm*
 F:	arch/powerpc/include/uapi/asm/kvm*
arch/powerpc/include/asm/kvm_book3s.h +0 -17
index e1ff291ba891..7e13e48dbc6b 100644
@@ -36,21 +36,14 @@ struct kvmppc_sid_map {
 #define SID_MAP_NUM     (1 << SID_MAP_BITS)
 #define SID_MAP_MASK    (SID_MAP_NUM - 1)
 
-#ifdef CONFIG_PPC_BOOK3S_64
 #define SID_CONTEXTS	1
-#else
-#define SID_CONTEXTS	128
-#define VSID_POOL_SIZE	(SID_CONTEXTS * 16)
-#endif
 
 struct hpte_cache {
 	struct hlist_node list_pte;
 	struct hlist_node list_pte_long;
 	struct hlist_node list_vpte;
 	struct hlist_node list_vpte_long;
-#ifdef CONFIG_PPC_BOOK3S_64
 	struct hlist_node list_vpte_64k;
-#endif
 	struct rcu_head rcu_head;
 	u64 host_vpn;
 	u64 pfn;
@@ -112,14 +105,9 @@ struct kvmppc_vcpu_book3s {
 	u64 hior;
 	u64 msr_mask;
 	u64 vtb;
-#ifdef CONFIG_PPC_BOOK3S_32
-	u32 vsid_pool[VSID_POOL_SIZE];
-	u32 vsid_next;
-#else
 	u64 proto_vsid_first;
 	u64 proto_vsid_max;
 	u64 proto_vsid_next;
-#endif
 	int context_id[SID_CONTEXTS];
 
 	bool hior_explicit;		/* HIOR is set by ioctl, not PVR */
@@ -128,9 +116,7 @@ struct kvmppc_vcpu_book3s {
 	struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG];
 	struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE];
 	struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG];
-#ifdef CONFIG_PPC_BOOK3S_64
 	struct hlist_head hpte_hash_vpte_64k[HPTEG_HASH_NUM_VPTE_64K];
-#endif
 	int hpte_cache_count;
 	spinlock_t mmu_lock;
 };
@@ -391,9 +377,6 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
 
 /* Also add subarch specific defines */
 
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-#include <asm/kvm_book3s_32.h>
-#endif
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
 #include <asm/kvm_book3s_64.h>
 #endif
arch/powerpc/include/asm/kvm_book3s_asm.h +0 -10
index a36797938620..98174363946e 100644
@@ -113,11 +113,9 @@ struct kvmppc_host_state {
 	u64 dec_expires;
 	struct kvm_split_mode *kvm_split_mode;
 #endif
-#ifdef CONFIG_PPC_BOOK3S_64
 	u64 cfar;
 	u64 ppr;
 	u64 host_fscr;
-#endif
 };
 
 struct kvmppc_book3s_shadow_vcpu {
@@ -134,20 +132,12 @@ struct kvmppc_book3s_shadow_vcpu {
 	u32 fault_dsisr;
 	u32 last_inst;
 
-#ifdef CONFIG_PPC_BOOK3S_32
-	u32     sr[16];			/* Guest SRs */
-
-	struct kvmppc_host_state hstate;
-#endif
-
-#ifdef CONFIG_PPC_BOOK3S_64
 	u8 slb_max;			/* highest used guest slb entry */
 	struct  {
 		u64     esid;
 		u64     vsid;
 	} slb[64];			/* guest SLB */
 	u64 shadow_fscr;
-#endif
 };
 
 #endif /*__ASSEMBLY__ */
arch/powerpc/include/asm/kvm_host.h +1 -1
index 6e1108f8fce6..56b01a135fcb 100644
@@ -793,7 +793,7 @@ struct kvm_vcpu_arch {
 	struct machine_check_event mce_evt; /* Valid if trap == 0x200 */
 
 	struct kvm_vcpu_arch_shared *shared;
-#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
+#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
 	bool shared_big_endian;
 #endif
 	unsigned long magic_page_pa; /* phys addr to map the magic page to */
arch/powerpc/include/asm/kvm_ppc.h +1 -1
index ca3829d47ab7..001cd00d18f0 100644
@@ -951,7 +951,7 @@ static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)
  */
 static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)
 {
-#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
+#if defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
 	/* Only Book3S_64 PR supports bi-endian for now */
 	return vcpu->arch.shared_big_endian;
 #elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__)
arch/powerpc/include/asm/processor.h +0 -3
index 6b94de17201c..d77092554788 100644
@@ -223,9 +223,6 @@ struct thread_struct {
 	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
 	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-	void*		kvm_shadow_vcpu; /* KVM internal data */
-#endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
 #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
 	struct kvm_vcpu	*kvm_vcpu;
 #endif
arch/powerpc/kernel/asm-offsets.c +2 -19
index 7a390bd4f4af..c4186061694c 100644
@@ -147,9 +147,6 @@ int main(void)
 	OFFSET(THREAD_USED_SPE, thread_struct, used_spe);
 #endif /* CONFIG_SPE */
 #endif /* CONFIG_PPC64 */
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-	OFFSET(THREAD_KVM_SVCPU, thread_struct, kvm_shadow_vcpu);
-#endif
 #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
 	OFFSET(THREAD_KVM_VCPU, thread_struct, kvm_vcpu);
 #endif
@@ -401,7 +398,7 @@ int main(void)
 	OFFSET(VCPU_SHARED, kvm_vcpu, arch.shared);
 	OFFSET(VCPU_SHARED_MSR, kvm_vcpu_arch_shared, msr);
 	OFFSET(VCPU_SHADOW_MSR, kvm_vcpu, arch.shadow_msr);
-#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
+#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
 	OFFSET(VCPU_SHAREDBE, kvm_vcpu, arch.shared_big_endian);
 #endif
 
@@ -511,19 +508,13 @@ int main(void)
 	OFFSET(VCPU_TAR_TM, kvm_vcpu, arch.tar_tm);
 #endif
 
-#ifdef CONFIG_PPC_BOOK3S_64
 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
 	OFFSET(PACA_SVCPU, paca_struct, shadow_vcpu);
 # define SVCPU_FIELD(x, f)	DEFINE(x, offsetof(struct paca_struct, shadow_vcpu.f))
 #else
 # define SVCPU_FIELD(x, f)
 #endif
-# define HSTATE_FIELD(x, f)	DEFINE(x, offsetof(struct paca_struct, kvm_hstate.f))
-#else	/* 32-bit */
-# define SVCPU_FIELD(x, f)	DEFINE(x, offsetof(struct kvmppc_book3s_shadow_vcpu, f))
-# define HSTATE_FIELD(x, f)	DEFINE(x, offsetof(struct kvmppc_book3s_shadow_vcpu, hstate.f))
-#endif
-
+#define HSTATE_FIELD(x, f)	DEFINE(x, offsetof(struct paca_struct, kvm_hstate.f))
 	SVCPU_FIELD(SVCPU_CR, cr);
 	SVCPU_FIELD(SVCPU_XER, xer);
 	SVCPU_FIELD(SVCPU_CTR, ctr);
@@ -547,14 +538,9 @@ int main(void)
 	SVCPU_FIELD(SVCPU_FAULT_DAR, fault_dar);
 	SVCPU_FIELD(SVCPU_LAST_INST, last_inst);
 	SVCPU_FIELD(SVCPU_SHADOW_SRR1, shadow_srr1);
-#ifdef CONFIG_PPC_BOOK3S_32
-	SVCPU_FIELD(SVCPU_SR, sr);
-#endif
-#ifdef CONFIG_PPC64
 	SVCPU_FIELD(SVCPU_SLB, slb);
 	SVCPU_FIELD(SVCPU_SLB_MAX, slb_max);
 	SVCPU_FIELD(SVCPU_SHADOW_FSCR, shadow_fscr);
-#endif
 
 	HSTATE_FIELD(HSTATE_HOST_R1, host_r1);
 	HSTATE_FIELD(HSTATE_HOST_R2, host_r2);
@@ -601,12 +587,9 @@ int main(void)
 	OFFSET(KVM_SPLIT_NAPPED, kvm_split_mode, napped);
 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
 
-#ifdef CONFIG_PPC_BOOK3S_64
 	HSTATE_FIELD(HSTATE_CFAR, cfar);
 	HSTATE_FIELD(HSTATE_PPR, ppr);
 	HSTATE_FIELD(HSTATE_HOST_FSCR, host_fscr);
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
 #else /* CONFIG_PPC_BOOK3S */
 	OFFSET(VCPU_CR, kvm_vcpu, arch.regs.ccr);
 	OFFSET(VCPU_XER, kvm_vcpu, arch.regs.xer);
arch/powerpc/kernel/head_32.h +0 -10
index 9cba7dbf58dd..6a9bf5762d72 100644
@@ -168,21 +168,11 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 /*
  * Exception vectors.
  */
-#ifdef CONFIG_PPC_BOOK3S
 #define	START_EXCEPTION(n, label)		\
 	__HEAD;					\
 	. = n;					\
-	DO_KVM n;				\
 label:
 
-#else
-#define	START_EXCEPTION(n, label)		\
-	__HEAD;					\
-	. = n;					\
-label:
-
-#endif
-
 #define EXCEPTION(n, label, hdlr)		\
 	START_EXCEPTION(n, label)		\
 	EXCEPTION_PROLOG n label;		\
arch/powerpc/kernel/head_book3s_32.S +0 -5
index cb2bca76be53..505d0009ddc9 100644
@@ -30,7 +30,6 @@
 #include <asm/asm-offsets.h>
 #include <asm/ptrace.h>
 #include <asm/bug.h>
-#include <asm/kvm_book3s_asm.h>
 #include <asm/feature-fixups.h>
 #include <asm/interrupt.h>
 
@@ -861,10 +860,6 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
 	rfi
 #endif /* CONFIG_SMP */
 
-#ifdef CONFIG_KVM_BOOK3S_HANDLER
-#include "../kvm/book3s_rmhandlers.S"
-#endif
-
 /*
  * Load stuff into the MMU.  Intended to be called with
  * IR=0 and DR=0.
arch/powerpc/kvm/Kconfig +0 -22
index e2230ea512cf..d0a6e2f6df81 100644
@@ -27,11 +27,6 @@ config KVM
 config KVM_BOOK3S_HANDLER
 	bool
 
-config KVM_BOOK3S_32_HANDLER
-	bool
-	select KVM_BOOK3S_HANDLER
-	select KVM_MMIO
-
 config KVM_BOOK3S_64_HANDLER
 	bool
 	select KVM_BOOK3S_HANDLER
@@ -44,23 +39,6 @@ config KVM_BOOK3S_PR_POSSIBLE
 config KVM_BOOK3S_HV_POSSIBLE
 	bool
 
-config KVM_BOOK3S_32
-	tristate "KVM support for PowerPC book3s_32 processors"
-	depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT
-	depends on !CONTEXT_TRACKING_USER
-	select KVM
-	select KVM_BOOK3S_32_HANDLER
-	select KVM_BOOK3S_PR_POSSIBLE
-	select PPC_FPU
-	help
-	  Support running unmodified book3s_32 guest kernels
-	  in virtual machines on book3s_32 host processors.
-
-	  This module provides access to the hardware capabilities through
-	  a character device node named /dev/kvm.
-
-	  If unsure, say N.
-
 config KVM_BOOK3S_64
 	tristate "KVM support for PowerPC book3s_64 processors"
 	depends on PPC_BOOK3S_64
arch/powerpc/kvm/Makefile +0 -15
index 294f27439f7f..059b4c153d97 100644
@@ -95,27 +95,12 @@ kvm-book3s_64-module-objs := \
 
 kvm-objs-$(CONFIG_KVM_BOOK3S_64) := $(kvm-book3s_64-module-objs)
 
-kvm-book3s_32-objs := \
-	$(common-objs-y) \
-	emulate.o \
-	fpu.o \
-	book3s_paired_singles.o \
-	book3s.o \
-	book3s_pr.o \
-	book3s_emulate.o \
-	book3s_interrupts.o \
-	book3s_mmu_hpte.o \
-	book3s_32_mmu_host.o \
-	book3s_32_mmu.o
-kvm-objs-$(CONFIG_KVM_BOOK3S_32) := $(kvm-book3s_32-objs)
-
 kvm-objs-$(CONFIG_KVM_MPIC) += mpic.o
 
 kvm-y += $(kvm-objs-m) $(kvm-objs-y)
 
 obj-$(CONFIG_KVM_E500MC) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
-obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
 
 obj-$(CONFIG_KVM_BOOK3S_64_PR) += kvm-pr.o
 obj-$(CONFIG_KVM_BOOK3S_64_HV) += kvm-hv.o
arch/powerpc/kvm/book3s.c +0 -18
index d79c5d1098c0..75f4d397114f 100644
@@ -898,12 +898,9 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
 
 int kvmppc_core_init_vm(struct kvm *kvm)
 {
-
-#ifdef CONFIG_PPC64
 	INIT_LIST_HEAD_RCU(&kvm->arch.spapr_tce_tables);
 	INIT_LIST_HEAD(&kvm->arch.rtas_tokens);
 	mutex_init(&kvm->arch.rtas_token_lock);
-#endif
 
 	return kvm->arch.kvm_ops->init_vm(kvm);
 }
@@ -912,10 +909,8 @@ void kvmppc_core_destroy_vm(struct kvm *kvm)
 {
 	kvm->arch.kvm_ops->destroy_vm(kvm);
 
-#ifdef CONFIG_PPC64
 	kvmppc_rtas_tokens_free(kvm);
 	WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
-#endif
 
 #ifdef CONFIG_KVM_XICS
 	/*
@@ -1069,10 +1064,6 @@ static int kvmppc_book3s_init(void)
 	r = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
 	if (r)
 		return r;
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-	r = kvmppc_book3s_init_pr();
-#endif
-
 #ifdef CONFIG_KVM_XICS
 #ifdef CONFIG_KVM_XIVE
 	if (xics_on_xive()) {
@@ -1089,17 +1080,8 @@ static int kvmppc_book3s_init(void)
 
 static void kvmppc_book3s_exit(void)
 {
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-	kvmppc_book3s_exit_pr();
-#endif
 	kvm_exit();
 }
 
 module_init(kvmppc_book3s_init);
 module_exit(kvmppc_book3s_exit);
-
-/* On 32bit this is our one and only kernel module */
-#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-MODULE_ALIAS_MISCDEV(KVM_MINOR);
-MODULE_ALIAS("devname:kvm");
-#endif
arch/powerpc/kvm/book3s_emulate.c +0 -37
index de126d153328..30a117d6e70c 100644
@@ -351,7 +351,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_vcpu *vcpu,
 			vcpu->arch.mmu.tlbie(vcpu, addr, large);
 			break;
 		}
-#ifdef CONFIG_PPC_BOOK3S_64
 		case OP_31_XOP_FAKE_SC1:
 		{
 			/* SC 1 papr hypercalls */
@@ -378,7 +377,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_vcpu *vcpu,
 			emulated = EMULATE_EXIT_USER;
 			break;
 		}
-#endif
 		case OP_31_XOP_EIOIO:
 			break;
 		case OP_31_XOP_SLBMTE:
@@ -762,7 +760,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 	case SPRN_GQR7:
 		to_book3s(vcpu)->gqr[sprn - SPRN_GQR0] = spr_val;
 		break;
-#ifdef CONFIG_PPC_BOOK3S_64
 	case SPRN_FSCR:
 		kvmppc_set_fscr(vcpu, spr_val);
 		break;
@@ -810,7 +807,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 		tm_disable();
 
 		break;
-#endif
 #endif
 	case SPRN_ICTC:
 	case SPRN_THRM1:
@@ -829,7 +825,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 	case SPRN_WPAR_GEKKO:
 	case SPRN_MSSSR0:
 	case SPRN_DABR:
-#ifdef CONFIG_PPC_BOOK3S_64
 	case SPRN_MMCRS:
 	case SPRN_MMCRA:
 	case SPRN_MMCR0:
@@ -839,7 +834,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 	case SPRN_UAMOR:
 	case SPRN_IAMR:
 	case SPRN_AMR:
-#endif
 		break;
 unprivileged:
 	default:
@@ -943,7 +937,6 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
 	case SPRN_GQR7:
 		*spr_val = to_book3s(vcpu)->gqr[sprn - SPRN_GQR0];
 		break;
-#ifdef CONFIG_PPC_BOOK3S_64
 	case SPRN_FSCR:
 		*spr_val = vcpu->arch.fscr;
 		break;
@@ -978,7 +971,6 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
 			*spr_val = mfspr(SPRN_TFIAR);
 		tm_disable();
 		break;
-#endif
 #endif
 	case SPRN_THRM1:
 	case SPRN_THRM2:
@@ -995,7 +987,6 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
 	case SPRN_WPAR_GEKKO:
 	case SPRN_MSSSR0:
 	case SPRN_DABR:
-#ifdef CONFIG_PPC_BOOK3S_64
 	case SPRN_MMCRS:
 	case SPRN_MMCRA:
 	case SPRN_MMCR0:
@@ -1006,7 +997,6 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
 	case SPRN_UAMOR:
 	case SPRN_IAMR:
 	case SPRN_AMR:
-#endif
 		*spr_val = 0;
 		break;
 	default:
@@ -1038,35 +1028,8 @@ u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst)
 
 ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst)
 {
-#ifdef CONFIG_PPC_BOOK3S_64
 	/*
 	 * Linux's fix_alignment() assumes that DAR is valid, so can we
 	 */
 	return vcpu->arch.fault_dar;
-#else
-	ulong dar = 0;
-	ulong ra = get_ra(inst);
-	ulong rb = get_rb(inst);
-
-	switch (get_op(inst)) {
-	case OP_LFS:
-	case OP_LFD:
-	case OP_STFD:
-	case OP_STFS:
-		if (ra)
-			dar = kvmppc_get_gpr(vcpu, ra);
-		dar += (s32)((s16)inst);
-		break;
-	case 31:
-		if (ra)
-			dar = kvmppc_get_gpr(vcpu, ra);
-		dar += kvmppc_get_gpr(vcpu, rb);
-		break;
-	default:
-		printk(KERN_INFO "KVM: Unaligned instruction 0x%x\n", inst);
-		break;
-	}
-
-	return dar;
-#endif
 }
arch/powerpc/kvm/book3s_interrupts.S +0 -11
index f4bec2fc51aa..c5b88d5451b7 100644
@@ -14,7 +14,6 @@
 #include <asm/exception-64s.h>
 #include <asm/asm-compat.h>
 
-#if defined(CONFIG_PPC_BOOK3S_64)
 #ifdef CONFIG_PPC64_ELF_ABI_V2
 #define FUNC(name) 		name
 #else
@@ -22,12 +21,6 @@
 #endif
 #define GET_SHADOW_VCPU(reg)    addi	reg, r13, PACA_SVCPU
 
-#elif defined(CONFIG_PPC_BOOK3S_32)
-#define FUNC(name)		name
-#define GET_SHADOW_VCPU(reg)	lwz     reg, (THREAD + THREAD_KVM_SVCPU)(r2)
-
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
 #define VCPU_LOAD_NVGPRS(vcpu) \
 	PPC_LL	r14, VCPU_GPR(R14)(vcpu); \
 	PPC_LL	r15, VCPU_GPR(R15)(vcpu); \
@@ -89,7 +82,6 @@ kvm_start_lightweight:
 	nop
 	REST_GPR(3, r1)
 
-#ifdef CONFIG_PPC_BOOK3S_64
 	/* Get the dcbz32 flag */
 	PPC_LL	r0, VCPU_HFLAGS(r3)
 	rldicl	r0, r0, 0, 63		/* r3 &= 1 */
@@ -118,7 +110,6 @@ sprg3_little_endian:
 
 after_sprg3_load:
 	mtspr	SPRN_SPRG3, r4
-#endif /* CONFIG_PPC_BOOK3S_64 */
 
 	PPC_LL	r4, VCPU_SHADOW_MSR(r3)	/* get shadow_msr */
 
@@ -157,14 +148,12 @@ after_sprg3_load:
 	bl	FUNC(kvmppc_copy_from_svcpu)
 	nop
 
-#ifdef CONFIG_PPC_BOOK3S_64
 	/*
 	 * Reload kernel SPRG3 value.
 	 * No need to save guest value as usermode can't modify SPRG3.
 	 */
 	ld	r3, PACA_SPRG_VDSO(r13)
 	mtspr	SPRN_SPRG_VDSO_WRITE, r3
-#endif /* CONFIG_PPC_BOOK3S_64 */
 
 	/* R7 = vcpu */
 	PPC_LL	r7, GPR3(r1)
arch/powerpc/kvm/book3s_mmu_hpte.c +0 -12
index d904e13e069b..91614ca9f969 100644
@@ -45,13 +45,11 @@ static inline u64 kvmppc_mmu_hash_vpte_long(u64 vpage)
 		       HPTEG_HASH_BITS_VPTE_LONG);
 }
 
-#ifdef CONFIG_PPC_BOOK3S_64
 static inline u64 kvmppc_mmu_hash_vpte_64k(u64 vpage)
 {
 	return hash_64((vpage & 0xffffffff0ULL) >> 4,
 		       HPTEG_HASH_BITS_VPTE_64K);
 }
-#endif
 
 void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
 {
@@ -80,12 +78,10 @@ void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
 	hlist_add_head_rcu(&pte->list_vpte_long,
 			   &vcpu3s->hpte_hash_vpte_long[index]);
 
-#ifdef CONFIG_PPC_BOOK3S_64
 	/* Add to vPTE_64k list */
 	index = kvmppc_mmu_hash_vpte_64k(pte->pte.vpage);
 	hlist_add_head_rcu(&pte->list_vpte_64k,
 			   &vcpu3s->hpte_hash_vpte_64k[index]);
-#endif
 
 	vcpu3s->hpte_cache_count++;
 
@@ -113,9 +109,7 @@ static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
 	hlist_del_init_rcu(&pte->list_pte_long);
 	hlist_del_init_rcu(&pte->list_vpte);
 	hlist_del_init_rcu(&pte->list_vpte_long);
-#ifdef CONFIG_PPC_BOOK3S_64
 	hlist_del_init_rcu(&pte->list_vpte_64k);
-#endif
 	vcpu3s->hpte_cache_count--;
 
 	spin_unlock(&vcpu3s->mmu_lock);
@@ -222,7 +216,6 @@ static void kvmppc_mmu_pte_vflush_short(struct kvm_vcpu *vcpu, u64 guest_vp)
 	rcu_read_unlock();
 }
 
-#ifdef CONFIG_PPC_BOOK3S_64
 /* Flush with mask 0xffffffff0 */
 static void kvmppc_mmu_pte_vflush_64k(struct kvm_vcpu *vcpu, u64 guest_vp)
 {
@@ -243,7 +236,6 @@ static void kvmppc_mmu_pte_vflush_64k(struct kvm_vcpu *vcpu, u64 guest_vp)
 
 	rcu_read_unlock();
 }
-#endif
 
 /* Flush with mask 0xffffff000 */
 static void kvmppc_mmu_pte_vflush_long(struct kvm_vcpu *vcpu, u64 guest_vp)
@@ -275,11 +267,9 @@ void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 guest_vp, u64 vp_mask)
 	case 0xfffffffffULL:
 		kvmppc_mmu_pte_vflush_short(vcpu, guest_vp);
 		break;
-#ifdef CONFIG_PPC_BOOK3S_64
 	case 0xffffffff0ULL:
 		kvmppc_mmu_pte_vflush_64k(vcpu, guest_vp);
 		break;
-#endif
 	case 0xffffff000ULL:
 		kvmppc_mmu_pte_vflush_long(vcpu, guest_vp);
 		break;
@@ -355,10 +345,8 @@ int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu)
 				  ARRAY_SIZE(vcpu3s->hpte_hash_vpte));
 	kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte_long,
 				  ARRAY_SIZE(vcpu3s->hpte_hash_vpte_long));
-#ifdef CONFIG_PPC_BOOK3S_64
 	kvmppc_mmu_hpte_init_hash(vcpu3s->hpte_hash_vpte_64k,
 				  ARRAY_SIZE(vcpu3s->hpte_hash_vpte_64k));
-#endif
 
 	spin_lock_init(&vcpu3s->mmu_lock);
 
arch/powerpc/kvm/book3s_pr.c +1 -121

344 lines not on this page · raw message

arch/powerpc/kvm/book3s_rmhandlers.S +0 -110

129 lines not on this page · raw message

arch/powerpc/kvm/book3s_segment.S +1 -29
index 202046a83fc1..eec41008d815 100644
@@ -11,31 +11,16 @@
 #include <asm/asm-compat.h>
 #include <asm/feature-fixups.h>
 
-#if defined(CONFIG_PPC_BOOK3S_64)
-
 #define GET_SHADOW_VCPU(reg)    \
 	mr	reg, r13
 
-#elif defined(CONFIG_PPC_BOOK3S_32)
-
-#define GET_SHADOW_VCPU(reg)    			\
-	tophys(reg, r2);       			\
-	lwz     reg, (THREAD + THREAD_KVM_SVCPU)(reg);	\
-	tophys(reg, reg)
-
-#endif
-
 /* Disable for nested KVM */
 #define USE_QUICK_LAST_INST
 
 
 /* Get helper functions for subarch specific functionality */
 
-#if defined(CONFIG_PPC_BOOK3S_64)
 #include "book3s_64_slb.S"
-#elif defined(CONFIG_PPC_BOOK3S_32)
-#include "book3s_32_sr.S"
-#endif
 
 /******************************************************************************
  *                                                                            *
@@ -81,7 +66,6 @@ kvmppc_handler_trampoline_enter:
 	/* Switch to guest segment. This is subarch specific. */
 	LOAD_GUEST_SEGMENTS
 
-#ifdef CONFIG_PPC_BOOK3S_64
 BEGIN_FTR_SECTION
 	/* Save host FSCR */
 	mfspr	r8, SPRN_FSCR
@@ -108,8 +92,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 	mtspr   SPRN_HID5,r0
 no_dcbz32_on:
 
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
 	/* Enter guest */
 
 	PPC_LL	r8, SVCPU_CTR(r3)
@@ -170,13 +152,11 @@ kvmppc_interrupt_pr:
 	 * HSTATE.SCRATCH0 = guest R12
 	 * HSTATE.SCRATCH2 = guest R9
 	 */
-#ifdef CONFIG_PPC64
 	/* Match 32-bit entry */
 	ld	r9,HSTATE_SCRATCH2(r13)
 	rotldi	r12, r12, 32		  /* Flip R12 halves for stw */
 	stw	r12, HSTATE_SCRATCH1(r13) /* CR is now in the low half */
 	srdi	r12, r12, 32		  /* shift trap into low half */
-#endif
 
 .global kvmppc_handler_trampoline_exit
 kvmppc_handler_trampoline_exit:
@@ -209,7 +189,6 @@ kvmppc_handler_trampoline_exit:
 	PPC_LL	r2, HSTATE_HOST_R2(r13)
 
 	/* Save guest PC and MSR */
-#ifdef CONFIG_PPC64
 BEGIN_FTR_SECTION
 	andi.	r0, r12, 0x2
 	cmpwi	cr1, r0, 0
@@ -219,7 +198,7 @@ BEGIN_FTR_SECTION
 	andi.	r12,r12,0x3ffd
 	b	2f
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
-#endif
+
 1:	mfsrr0	r3
 	mfsrr1	r4
 2:
@@ -265,7 +244,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 	beq	ld_last_prev_inst
 	cmpwi	r12, BOOK3S_INTERRUPT_ALIGNMENT
 	beq-	ld_last_inst
-#ifdef CONFIG_PPC64
 BEGIN_FTR_SECTION
 	cmpwi	r12, BOOK3S_INTERRUPT_H_EMUL_ASSIST
 	beq-	ld_last_inst
@@ -274,7 +252,6 @@ BEGIN_FTR_SECTION
 	cmpwi	r12, BOOK3S_INTERRUPT_FAC_UNAVAIL
 	beq-	ld_last_inst
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
-#endif
 
 	b	no_ld_last_inst
 
@@ -317,7 +294,6 @@ no_ld_last_inst:
 	/* Switch back to host MMU */
 	LOAD_HOST_SEGMENTS
 
-#ifdef CONFIG_PPC_BOOK3S_64
 
 	lbz	r5, HSTATE_RESTORE_HID5(r13)
 	cmpwi	r5, 0
@@ -342,8 +318,6 @@ no_fscr_save:
 	mtspr	SPRN_FSCR, r8
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 
-#endif /* CONFIG_PPC_BOOK3S_64 */
-
 	/*
 	 * For some interrupts, we need to call the real Linux
 	 * handler, so it can do work for us. This has to happen
@@ -386,13 +360,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 #endif
 	PPC_LL	r8, HSTATE_VMHANDLER(r13)
 
-#ifdef CONFIG_PPC64
 BEGIN_FTR_SECTION
 	beq	cr1, 1f
 	mtspr	SPRN_HSRR1, r6
 	mtspr	SPRN_HSRR0, r8
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
-#endif
 1:	/* Restore host msr -> SRR1 */
 	mtsrr1	r6
 	/* Load highmem handler address */
arch/powerpc/kvm/emulate.c +0 -2
index 355d5206e8aa..74508516df51 100644
@@ -229,9 +229,7 @@ int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu)
 		switch (get_xop(inst)) {
 
 		case OP_31_XOP_TRAP:
-#ifdef CONFIG_64BIT
 		case OP_31_XOP_TRAP_64:
-#endif
 #ifdef CONFIG_PPC_BOOK3S
 			kvmppc_core_queue_program(vcpu, SRR1_PROGTRAP);
 #else
arch/powerpc/kvm/powerpc.c +0 -2
index ce1d91eed231..8059876abf23 100644
@@ -1163,11 +1163,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu)
 
 	if (vcpu->arch.mmio_sign_extend) {
 		switch (run->mmio.len) {
-#ifdef CONFIG_PPC64
 		case 4:
 			gpr = (s64)(s32)gpr;
 			break;
-#endif
 		case 2:
 			gpr = (s64)(s16)gpr;
 			break;
Signature · 1 line
2.39.5
#8 lore raw

Re: [PATCH v2 4/5] powerpc: kvm: drop 32-bit book3s

Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Support for KVM on 32-bit Book III-s implementations was added in 2010 and supports PowerMac, CHRP, and embedded platforms using the Freescale G4 (mpc74xx), e300 (mpc83xx) and e600 (mpc86xx) CPUs from 2003 to 2009.

Earlier 603/604/750 machines might work but would be even more limited by their available memory.

The only likely users of KVM on any of these were the final Apple PowerMac/PowerBook/iBook G4 models with 2GB of RAM that were at the high end 20 years ago but are just as obsolete as their x86-32 counterparts. The code has been orphaned since 2023.

Quoted 5 lines

There is still a need to support 32-bit guests in order to better debug problems on ppc32 kernels. This should work in theory on both 64-bit booke and on 64-bit book3s hosts, but it would be good to confirm that this is still the case before the known working option gets removed.

I can confirm that running 6.12.5 on a P9 host, trying to boot a 6.6 32-bit kernel gave me:

Detected RAM kernel at 400000 (1330c8c bytes)
Welcome to Open Firmware

Copyright (c) 2004, 2017 IBM Corporation All rights reserved. This program and the accompanying materials are made available under the terms of the BSD License available at
http://www.opensource.org/licenses/bsd-license.php

Booting from memory...

( 380 ) Data Segment Exception [ -bfc00000 ]

    R0 .. R7           R8 .. R15         R16 .. R23         R24 .. R31
00000000014a1124   0000000000000000   000000000135b4ac   0000000000000000   
000000000dc70f30   ffffffffc0000000   000000000dc70fa4   000000000173600c   
0000000000000000   000000000e477010   0000000000000000   0000000000400000   
ffffffff0141be4c   000000000149ab74   00000000ffffffff   0000000000000008   
00000000c0014b6c   0000000020000402   0000000040400000   00000000016f2000   
ffffffff40400000   0000000000000000   0000000000000000   000000000dc70f60   
0000000000000000   0000000000000000   000000000e73d490   000000000149f000   
0000000000000000   000000000e756118   000000000dc70fa0   ffffffff40400000   

CR / XER LR / CTR SRR0 / SRR1 DAR / DSISR
80000402 00000000014a1124 00000000014a1128 ffffffff0141be4c
0000000020040000 0000000000000000 8000000000003000 00000000

2 >

Which is the same thing that happens if you boot a 32-bit Linux kernel on a physical 64-bit Power machine. This is probably because KVM is so much more accurate than TCG for Power emulation :)

That said, I would like to keep the support alive for more than just ppc32 kernel testing. There are plenty of Power Macs with enough memory to run some environments within KVM. Adélie’s new release boots a full XFCE desktop in under 300 MB RAM, so even a 1 GB machine has enough memory to run AmigaOS, Mac OS 9, or another XFCE in KVM.

I have found a few bugs in testing newer kernels, and one of them affects all targets lower than Power7, which means 32-bit and 64-bit BE. I am preparing to send those patches in. I will continue shaking out any remaining bugs on my 32-bit host. I hope that these patches can be useful, and possibly stimulate more interest so 32-bit support can be maintained again.

In fairness, I do agree that there is very little value in keeping 32-bit MIPS or RISC-V support since the chips that support it are so limited. 32-bit Power however serves actual purposes. 32-bit x86 could be useful to make sure “KVM on 32-bit in general” is easier to keep going, but if it is causing maintenance issues then I suppose it can go.

Sincerely,
-Anna

#9 lore raw

Re: [PATCH v2 4/5] powerpc: kvm: drop 32-bit book3s

Quoted 35 lines · A. Wilcox
Quoted 1 line · Arnd Bergmann

I can confirm that running 6.12.5 on a P9 host, trying to boot a 6.6 32-bit kernel gave me:

Detected RAM kernel at 400000 (1330c8c bytes)
Welcome to Open Firmware

Copyright (c) 2004, 2017 IBM Corporation All rights reserved. This program and the accompanying materials are made available under the terms of the BSD License available at
http://www.opensource.org/licenses/bsd-license.php

Booting from memory...

( 380 ) Data Segment Exception [ -bfc00000 ]

    R0 .. R7           R8 .. R15         R16 .. R23         R24 .. R31
00000000014a1124   0000000000000000   000000000135b4ac   0000000000000000   
000000000dc70f30   ffffffffc0000000   000000000dc70fa4   000000000173600c   
0000000000000000   000000000e477010   0000000000000000   0000000000400000   
ffffffff0141be4c   000000000149ab74   00000000ffffffff   0000000000000008   
00000000c0014b6c   0000000020000402   0000000040400000   00000000016f2000   
ffffffff40400000   0000000000000000   0000000000000000   000000000dc70f60   
0000000000000000   0000000000000000   000000000e73d490   000000000149f000   
0000000000000000   000000000e756118   000000000dc70fa0   ffffffff40400000   

CR / XER LR / CTR SRR0 / SRR1 DAR / DSISR
80000402 00000000014a1124 00000000014a1128 ffffffff0141be4c
0000000020040000 0000000000000000 8000000000003000 00000000

Quoted 5 lines

2 >

Which is the same thing that happens if you boot a 32-bit Linux kernel on a physical 64-bit Power machine. This is probably because KVM is so much more accurate than TCG for Power emulation :)

Did you ask kvm to emulate a 32-bit platform though? Since the register dump shows 64-bit registers, my guess is that this is the result of trying to load a 32-bit kernel on "-machine pseries -cpu native", which is not supported by the guest kernel. I would expect that you need at least a 32-bit machine type (mac99, pegasos2) and likely also a 32-bit CPU (7447a, e600).

According to what Paolo said, that may require PR state instead of HV mode:
https://lore.kernel.org/lkml/[email protected]/

I am not familiar enough with the details, but from the source code I see that this is not usually enabled, and you may have to turn off CONFIG_VIRT_CPU_ACCOUNTING_GEN and CONFIG_CONTEXT_TRACKING_USER in order to enable CONFIG_KVM_BOOK3S_64_PR, as well as possibly turning off CONFIG_KVM_BOOK3S_64_HV (it looks like it should be possible to have both HV and PR coexist, but there may be bugs). You also need to ensure that you have loaded kvm_pr.ko instead of kvm_hv.ko, and that CONFIG_PPC_RADIX_MMU is turned off if you are running on a power9 host, otherwise kvm_pr.ko fails to load, see kvmppc_core_check_processor_compat_pr().

Quoted 6 lines

That said, I would like to keep the support alive for more than just ppc32 kernel testing. There are plenty of Power Macs with enough memory to run some environments within KVM. Adélie’s new release boots a full XFCE desktop in under 300 MB RAM, so even a 1 GB machine has enough memory to run AmigaOS, Mac OS 9, or another XFCE in KVM.

Quoted 6 lines

I have found a few bugs in testing newer kernels, and one of them affects all targets lower than Power7, which means 32-bit and 64-bit BE. I am preparing to send those patches in. I will continue shaking out any remaining bugs on my 32-bit host. I hope that these patches can be useful, and possibly stimulate more interest so 32-bit support can be maintained again.

Do you mean 32-bit host KVM support specifically, or more generally powerpc32 kernels? As far as I can tell, powerpc32 kernel support itself remains actively maintained, though almost all of the work is on the embedded freescale parts rather than on desktop. PowerMac and KVM on book3s32 were marked as orphaned last year, but hadn't seen much activity for a while before that.

Quoted 5 lines

In fairness, I do agree that there is very little value in keeping 32-bit MIPS or RISC-V support since the chips that support it are so limited. 32-bit Power however serves actual purposes. 32-bit x86 could be useful to make sure “KVM on 32-bit in general” is easier to keep going, but if it is causing maintenance issues then I suppose it can go.

I think it comes down to how much of a hassle the book3s32 KVM support is for both the continued book3s32 architecture support and the KVM book3s64 codebase. I think both of these benefit from no longer having to worry about the orphaned book3s32 kvm code, but I can't tell how that should be weighed against how useful it is for you and other users that occasionally use KVM on that hardware.

Arnd

#10 lore raw

Re: [PATCH v2 4/5] powerpc: kvm: drop 32-bit book3s

Quoted 24 lines · Arnd Bergmann
Quoted 17 lines · A. Wilcox

On Dec 21, 2024, at 3:42 PM, Arnd Bergmann <[email protected]> wrote:

    R0 .. R7           R8 .. R15         R16 .. R23         R24 .. R31
00000000014a1124   0000000000000000   000000000135b4ac   0000000000000000   
000000000dc70f30   ffffffffc0000000   000000000dc70fa4   000000000173600c   
0000000000000000   000000000e477010   0000000000000000   0000000000400000   
ffffffff0141be4c   000000000149ab74   00000000ffffffff   0000000000000008   
00000000c0014b6c   0000000020000402   0000000040400000   00000000016f2000   
ffffffff40400000   0000000000000000   0000000000000000   000000000dc70f60   
0000000000000000   0000000000000000   000000000e73d490   000000000149f000   
0000000000000000   000000000e756118   000000000dc70fa0   ffffffff40400000   

CR / XER LR / CTR SRR0 / SRR1 DAR / DSISR
80000402 00000000014a1124 00000000014a1128 ffffffff0141be4c
0000000020040000 0000000000000000 8000000000003000 00000000

Quoted 5 lines

2 >

Which is the same thing that happens if you boot a 32-bit Linux kernel on a physical 64-bit Power machine. This is probably because KVM is so much more accurate than TCG for Power emulation :)

Quoted 6 lines

Did you ask kvm to emulate a 32-bit platform though? Since the register dump shows 64-bit registers, my guess is that this is the result of trying to load a 32-bit kernel on "-machine pseries -cpu native", which is not supported by the guest kernel. I would expect that you need at least a 32-bit machine type (mac99, pegasos2) and likely also a 32-bit CPU (7447a, e600).

SLOF always shows 64-bit registers; SLOF only ever runs as 64-bit program. The *client* program can be 32-bit of course, but the dump of SRR1 here shows SF=1 (the top bit there). No idea what was running at the time, but something in the kernel I guess?

(To show the last set client state, use
ciregs .regs
the thing exceptions print is via
eregs .regs
so you'll probably figure out the format ;-) )

If the client program is a 32-bit ELF file, SLOF starts the client program with SF=0.

Segher

Signature · 3 lines
kvm-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kvm-riscv
#11 lore raw

Re: [PATCH v2 4/5] powerpc: kvm: drop 32-bit book3s

In reply to A. Wilcox
Quoted 21 lines · A. Wilcox
Quoted 20 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Support for KVM on 32-bit Book III-s implementations was added in 2010 and supports PowerMac, CHRP, and embedded platforms using the Freescale G4 (mpc74xx), e300 (mpc83xx) and e600 (mpc86xx) CPUs from 2003 to 2009.

Earlier 603/604/750 machines might work but would be even more limited by their available memory.

The only likely users of KVM on any of these were the final Apple PowerMac/PowerBook/iBook G4 models with 2GB of RAM that were at the high end 20 years ago but are just as obsolete as their x86-32 counterparts. The code has been orphaned since 2023.

There is still a need to support 32-bit guests in order to better debug problems on ppc32 kernels. This should work in theory on both 64-bit booke and on 64-bit book3s hosts, but it would be good to confirm that this is still the case before the known working option gets removed.

[...]

Quoted 5 lines

That said, I would like to keep the support alive for more than just ppc32 kernel testing. There are plenty of Power Macs with enough memory to run some environments within KVM. Adélie’s new release boots a full XFCE desktop in under 300 MB RAM, so even a 1 GB machine has enough memory to run AmigaOS, Mac OS 9, or another XFCE in KVM.

FWIW, I second this. I do intend to get KVM to run on my e300-based board for some relatively light guests such as Mac OS 9. I suspect I won't be able to contribute much to the maintenance, though.

Best regards,
J. Neuschäfer

Signature · 3 lines
kvm-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kvm-riscv
#12 lore raw

PATCH v2 5/5 x86: kvm drop 32-bit host support

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>

There are very few 32-bit machines that support KVM, the main exceptions are the "Yonah" Generation Xeon-LV and Core Duo from 2006 and the Atom Z5xx "Silverthorne" from 2008 that were all released just before their 64-bit counterparts.

The main usecase for KVM in x86-32 kernels these days is to verify that 32-bit KVM is still working, by running it on 64-bit hardware. With KVM support on other 32-bit architectures going away, and x86-32 kernels on 64-bit hardware becoming more limited in available RAM, this usecase becomes much less interesting.

Remove this support to make KVM exclusive to 64-bit hosts on all architectures, and stop testing 32-bit host mode.

---
 arch/x86/kvm/Kconfig            |   6 +-
 arch/x86/kvm/Makefile           |   4 +-
 arch/x86/kvm/cpuid.c            |   2 +-
 arch/x86/kvm/emulate.c          |  34 ++------
 arch/x86/kvm/fpu.h              |   4 -
 arch/x86/kvm/hyperv.c           |   5 +-
 arch/x86/kvm/i8254.c            |   4 -
 arch/x86/kvm/kvm_cache_regs.h   |   2 -
 arch/x86/kvm/kvm_emulate.h      |   8 --
 arch/x86/kvm/lapic.c            |   4 -
 arch/x86/kvm/mmu.h              |   4 -
 arch/x86/kvm/mmu/mmu.c          | 134 --------------------------------
 arch/x86/kvm/mmu/mmu_internal.h |   9 ---
 arch/x86/kvm/mmu/paging_tmpl.h  |   9 ---
 arch/x86/kvm/mmu/spte.h         |   5 --
 arch/x86/kvm/mmu/tdp_mmu.h      |   4 -
 arch/x86/kvm/smm.c              |  19 -----
 arch/x86/kvm/svm/sev.c          |   2 -
 arch/x86/kvm/svm/svm.c          |  23 +-----
 arch/x86/kvm/svm/vmenter.S      |  20 -----
 arch/x86/kvm/trace.h            |   4 -
 arch/x86/kvm/vmx/main.c         |   2 -
 arch/x86/kvm/vmx/nested.c       |  24 +-----
 arch/x86/kvm/vmx/vmcs.h         |   2 -
 arch/x86/kvm/vmx/vmenter.S      |  25 +-----
 arch/x86/kvm/vmx/vmx.c          | 117 +---------------------------
 arch/x86/kvm/vmx/vmx.h          |  23 +-----
 arch/x86/kvm/vmx/vmx_ops.h      |   7 --
 arch/x86/kvm/vmx/x86_ops.h      |   2 -
 arch/x86/kvm/x86.c              |  74 ++----------------
 arch/x86/kvm/x86.h              |   4 -
 arch/x86/kvm/xen.c              |  61 ++++++---------
 32 files changed, 53 insertions(+), 594 deletions(-)
arch/x86/kvm/Kconfig +3 -3
index ea2c4f21c1ca..7bdc7639aa8d 100644
@@ -7,6 +7,7 @@ source "virt/kvm/Kconfig"
 
 menuconfig VIRTUALIZATION
 	bool "Virtualization"
+	depends on X86_64
 	default y
 	help
 	  Say Y here to get to see options for using your Linux host to run other
@@ -50,7 +51,6 @@ config KVM_X86
 
 config KVM
 	tristate "Kernel-based Virtual Machine (KVM) support"
-	depends on X86_LOCAL_APIC
 	help
 	  Support hosting fully virtualized guest machines using hardware
 	  virtualization extensions.  You will need a fairly recent
@@ -82,7 +82,7 @@ config KVM_WERROR
 config KVM_SW_PROTECTED_VM
 	bool "Enable support for KVM software-protected VMs"
 	depends on EXPERT
-	depends on KVM && X86_64
+	depends on KVM
 	help
 	  Enable support for KVM software-protected VMs.  Currently, software-
 	  protected VMs are purely a development and testing vehicle for
@@ -141,7 +141,7 @@ config KVM_AMD
 config KVM_AMD_SEV
 	bool "AMD Secure Encrypted Virtualization (SEV) support"
 	default y
-	depends on KVM_AMD && X86_64
+	depends on KVM_AMD
 	depends on CRYPTO_DEV_SP_PSP && !(KVM_AMD=y && CRYPTO_DEV_CCP_DD=m)
 	select ARCH_HAS_CC_PLATFORM
 	select KVM_GENERIC_PRIVATE_MEM
arch/x86/kvm/Makefile +1 -3
index f9dddb8cb466..46654dc0428f 100644
@@ -8,9 +8,7 @@ include $(srctree)/virt/kvm/Makefile.kvm
 kvm-y			+= x86.o emulate.o i8259.o irq.o lapic.o \
 			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
 			   debugfs.o mmu/mmu.o mmu/page_track.o \
-			   mmu/spte.o
-
-kvm-$(CONFIG_X86_64) += mmu/tdp_iter.o mmu/tdp_mmu.o
+			   mmu/spte.o mmu/tdp_iter.o mmu/tdp_mmu.o
 kvm-$(CONFIG_KVM_HYPERV) += hyperv.o
 kvm-$(CONFIG_KVM_XEN)	+= xen.o
 kvm-$(CONFIG_KVM_SMM)	+= smm.o
arch/x86/kvm/cpuid.c +1 -1
index edef30359c19..819b3ff2afc3 100644
@@ -1085,7 +1085,7 @@ void kvm_set_cpu_caps(void)
 		F(3DNOW),
 	);
 
-	if (!tdp_enabled && IS_ENABLED(CONFIG_X86_64))
+	if (!tdp_enabled)
 		kvm_cpu_cap_set(X86_FEATURE_GBPAGES);
 
 	kvm_cpu_cap_init(CPUID_8000_0007_EDX,
arch/x86/kvm/emulate.c +8 -26
index 60986f67c35a..ebac76a10fbd 100644
@@ -265,12 +265,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
 #define EFLAGS_MASK (X86_EFLAGS_OF|X86_EFLAGS_SF|X86_EFLAGS_ZF|X86_EFLAGS_AF|\
 		     X86_EFLAGS_PF|X86_EFLAGS_CF)
 
-#ifdef CONFIG_X86_64
-#define ON64(x) x
-#else
-#define ON64(x)
-#endif
-
 /*
  * fastop functions have a special calling convention:
  *
@@ -341,7 +335,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP1E(op##b, al) \
 	FOP1E(op##w, ax) \
 	FOP1E(op##l, eax) \
-	ON64(FOP1E(op##q, rax))	\
+	FOP1E(op##q, rax) \
 	FOP_END
 
 /* 1-operand, using src2 (for MUL/DIV r/m) */
@@ -350,7 +344,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP1E(op, cl) \
 	FOP1E(op, cx) \
 	FOP1E(op, ecx) \
-	ON64(FOP1E(op, rcx)) \
+	FOP1E(op, rcx) \
 	FOP_END
 
 /* 1-operand, using src2 (for MUL/DIV r/m), with exceptions */
@@ -359,7 +353,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP1EEX(op, cl) \
 	FOP1EEX(op, cx) \
 	FOP1EEX(op, ecx) \
-	ON64(FOP1EEX(op, rcx)) \
+	FOP1EEX(op, rcx) \
 	FOP_END
 
 #define FOP2E(op,  dst, src)	   \
@@ -372,7 +366,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP2E(op##b, al, dl) \
 	FOP2E(op##w, ax, dx) \
 	FOP2E(op##l, eax, edx) \
-	ON64(FOP2E(op##q, rax, rdx)) \
+	FOP2E(op##q, rax, rdx) \
 	FOP_END
 
 /* 2 operand, word only */
@@ -381,7 +375,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOPNOP() \
 	FOP2E(op##w, ax, dx) \
 	FOP2E(op##l, eax, edx) \
-	ON64(FOP2E(op##q, rax, rdx)) \
+	FOP2E(op##q, rax, rdx) \
 	FOP_END
 
 /* 2 operand, src is CL */
@@ -390,7 +384,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP2E(op##b, al, cl) \
 	FOP2E(op##w, ax, cl) \
 	FOP2E(op##l, eax, cl) \
-	ON64(FOP2E(op##q, rax, cl)) \
+	FOP2E(op##q, rax, cl) \
 	FOP_END
 
 /* 2 operand, src and dest are reversed */
@@ -399,7 +393,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOP2E(op##b, dl, al) \
 	FOP2E(op##w, dx, ax) \
 	FOP2E(op##l, edx, eax) \
-	ON64(FOP2E(op##q, rdx, rax)) \
+	FOP2E(op##q, rdx, rax) \
 	FOP_END
 
 #define FOP3E(op,  dst, src, src2) \
@@ -413,7 +407,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 	FOPNOP() \
 	FOP3E(op##w, ax, dx, cl) \
 	FOP3E(op##l, eax, edx, cl) \
-	ON64(FOP3E(op##q, rax, rdx, cl)) \
+	FOP3E(op##q, rax, rdx, cl) \
 	FOP_END
 
 /* Special case for SETcc - 1 instruction per cc */
@@ -1508,7 +1502,6 @@ static int get_descriptor_ptr(struct x86_emulate_ctxt *ctxt,
 
 	addr = dt.address + index * 8;
 
-#ifdef CONFIG_X86_64
 	if (addr >> 32 != 0) {
 		u64 efer = 0;
 
@@ -1516,7 +1509,6 @@ static int get_descriptor_ptr(struct x86_emulate_ctxt *ctxt,
 		if (!(efer & EFER_LMA))
 			addr &= (u32)-1;
 	}
-#endif
 
 	*desc_addr_p = addr;
 	return X86EMUL_CONTINUE;
@@ -2399,7 +2391,6 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt)
 
 	*reg_write(ctxt, VCPU_REGS_RCX) = ctxt->_eip;
 	if (efer & EFER_LMA) {
-#ifdef CONFIG_X86_64
 		*reg_write(ctxt, VCPU_REGS_R11) = ctxt->eflags;
 
 		ops->get_msr(ctxt,
@@ -2410,7 +2401,6 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt)
 		ops->get_msr(ctxt, MSR_SYSCALL_MASK, &msr_data);
 		ctxt->eflags &= ~msr_data;
 		ctxt->eflags |= X86_EFLAGS_FIXED;
-#endif
 	} else {
 		/* legacy mode */
 		ops->get_msr(ctxt, MSR_STAR, &msr_data);
@@ -2575,9 +2565,7 @@ static bool emulator_io_port_access_allowed(struct x86_emulate_ctxt *ctxt,
 	if (desc_limit_scaled(&tr_seg) < 103)
 		return false;
 	base = get_desc_base(&tr_seg);
-#ifdef CONFIG_X86_64
 	base |= ((u64)base3) << 32;
-#endif
 	r = ops->read_std(ctxt, base + 102, &io_bitmap_ptr, 2, NULL, true);
 	if (r != X86EMUL_CONTINUE)
 		return false;
@@ -2612,7 +2600,6 @@ static void string_registers_quirk(struct x86_emulate_ctxt *ctxt)
 	 * Intel CPUs mask the counter and pointers in quite strange
 	 * manner when ECX is zero due to REP-string optimizations.
 	 */
-#ifdef CONFIG_X86_64
 	u32 eax, ebx, ecx, edx;
 
 	if (ctxt->ad_bytes != 4)
@@ -2634,7 +2621,6 @@ static void string_registers_quirk(struct x86_emulate_ctxt *ctxt)
 	case 0xab:	/* stosd/w */
 		*reg_rmw(ctxt, VCPU_REGS_RDI) &= (u32)-1;
 	}
-#endif
 }
 
 static void save_state_to_tss16(struct x86_emulate_ctxt *ctxt,
@@ -3641,11 +3627,9 @@ static int em_lahf(struct x86_emulate_ctxt *ctxt)
 static int em_bswap(struct x86_emulate_ctxt *ctxt)
 {
 	switch (ctxt->op_bytes) {
-#ifdef CONFIG_X86_64
 	case 8:
 		asm("bswap %0" : "+r"(ctxt->dst.val));
 		break;
-#endif
 	default:
 		asm("bswap %0" : "+r"(*(u32 *)&ctxt->dst.val));
 		break;
@@ -4767,12 +4751,10 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len, int
 	case X86EMUL_MODE_PROT32:
 		def_op_bytes = def_ad_bytes = 4;
 		break;
-#ifdef CONFIG_X86_64
 	case X86EMUL_MODE_PROT64:
 		def_op_bytes = 4;
 		def_ad_bytes = 8;
 		break;
-#endif
 	default:
 		return EMULATION_FAILED;
 	}
arch/x86/kvm/fpu.h +0 -4
index 3ba12888bf66..56a402dbf24a 100644
@@ -26,7 +26,6 @@ static inline void _kvm_read_sse_reg(int reg, sse128_t *data)
 	case 5: asm("movdqa %%xmm5, %0" : "=m"(*data)); break;
 	case 6: asm("movdqa %%xmm6, %0" : "=m"(*data)); break;
 	case 7: asm("movdqa %%xmm7, %0" : "=m"(*data)); break;
-#ifdef CONFIG_X86_64
 	case 8: asm("movdqa %%xmm8, %0" : "=m"(*data)); break;
 	case 9: asm("movdqa %%xmm9, %0" : "=m"(*data)); break;
 	case 10: asm("movdqa %%xmm10, %0" : "=m"(*data)); break;
@@ -35,7 +34,6 @@ static inline void _kvm_read_sse_reg(int reg, sse128_t *data)
 	case 13: asm("movdqa %%xmm13, %0" : "=m"(*data)); break;
 	case 14: asm("movdqa %%xmm14, %0" : "=m"(*data)); break;
 	case 15: asm("movdqa %%xmm15, %0" : "=m"(*data)); break;
-#endif
 	default: BUG();
 	}
 }
@@ -51,7 +49,6 @@ static inline void _kvm_write_sse_reg(int reg, const sse128_t *data)
 	case 5: asm("movdqa %0, %%xmm5" : : "m"(*data)); break;
 	case 6: asm("movdqa %0, %%xmm6" : : "m"(*data)); break;
 	case 7: asm("movdqa %0, %%xmm7" : : "m"(*data)); break;
-#ifdef CONFIG_X86_64
 	case 8: asm("movdqa %0, %%xmm8" : : "m"(*data)); break;
 	case 9: asm("movdqa %0, %%xmm9" : : "m"(*data)); break;
 	case 10: asm("movdqa %0, %%xmm10" : : "m"(*data)); break;
@@ -60,7 +57,6 @@ static inline void _kvm_write_sse_reg(int reg, const sse128_t *data)
 	case 13: asm("movdqa %0, %%xmm13" : : "m"(*data)); break;
 	case 14: asm("movdqa %0, %%xmm14" : : "m"(*data)); break;
 	case 15: asm("movdqa %0, %%xmm15" : : "m"(*data)); break;
-#endif
 	default: BUG();
 	}
 }
arch/x86/kvm/hyperv.c +1 -4
index 6a6dd5a84f22..bc78cca5a57b 100644
@@ -2532,14 +2532,11 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 		return 1;
 	}
 
-#ifdef CONFIG_X86_64
 	if (is_64_bit_hypercall(vcpu)) {
 		hc.param = kvm_rcx_read(vcpu);
 		hc.ingpa = kvm_rdx_read(vcpu);
 		hc.outgpa = kvm_r8_read(vcpu);
-	} else
-#endif
-	{
+	} else {
 		hc.param = ((u64)kvm_rdx_read(vcpu) << 32) |
 			    (kvm_rax_read(vcpu) & 0xffffffff);
 		hc.ingpa = ((u64)kvm_rbx_read(vcpu) << 32) |
arch/x86/kvm/i8254.c +0 -4
index d7ab8780ab9e..f50a7b386c0a 100644
@@ -40,11 +40,7 @@
 #include "i8254.h"
 #include "x86.h"
 
-#ifndef CONFIG_X86_64
-#define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
-#else
 #define mod_64(x, y) ((x) % (y))
-#endif
 
 #define RW_STATE_LSB 1
 #define RW_STATE_MSB 2
arch/x86/kvm/kvm_cache_regs.h +0 -2
index 36a8786db291..66d12dc5b243 100644
@@ -32,7 +32,6 @@ BUILD_KVM_GPR_ACCESSORS(rdx, RDX)
 BUILD_KVM_GPR_ACCESSORS(rbp, RBP)
 BUILD_KVM_GPR_ACCESSORS(rsi, RSI)
 BUILD_KVM_GPR_ACCESSORS(rdi, RDI)
-#ifdef CONFIG_X86_64
 BUILD_KVM_GPR_ACCESSORS(r8,  R8)
 BUILD_KVM_GPR_ACCESSORS(r9,  R9)
 BUILD_KVM_GPR_ACCESSORS(r10, R10)
@@ -41,7 +40,6 @@ BUILD_KVM_GPR_ACCESSORS(r12, R12)
 BUILD_KVM_GPR_ACCESSORS(r13, R13)
 BUILD_KVM_GPR_ACCESSORS(r14, R14)
 BUILD_KVM_GPR_ACCESSORS(r15, R15)
-#endif
 
 /*
  * Using the register cache from interrupt context is generally not allowed, as
arch/x86/kvm/kvm_emulate.h +0 -8
index 73072585e164..36e1d61ae56d 100644
@@ -307,11 +307,7 @@ typedef void (*fastop_t)(struct fastop *);
  * also uses _eip, RIP cannot be a register operand nor can it be an operand in
  * a ModRM or SIB byte.
  */
-#ifdef CONFIG_X86_64
 #define NR_EMULATOR_GPRS	16
-#else
-#define NR_EMULATOR_GPRS	8
-#endif
 
 struct x86_emulate_ctxt {
 	void *vcpu;
@@ -503,11 +499,7 @@ enum x86_intercept {
 };
 
 /* Host execution mode. */
-#if defined(CONFIG_X86_32)
-#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32
-#elif defined(CONFIG_X86_64)
 #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64
-#endif
 
 int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len, int emulation_type);
 bool x86_page_table_writing_insn(struct x86_emulate_ctxt *ctxt);
arch/x86/kvm/lapic.c +0 -4
index 010129582ef4..430974a17e5f 100644
@@ -46,11 +46,7 @@
 #include "hyperv.h"
 #include "smm.h"
 
-#ifndef CONFIG_X86_64
-#define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
-#else
 #define mod_64(x, y) ((x) % (y))
-#endif
 
 /* 14 is the version for Xeon and Pentium 8.4.8*/
 #define APIC_VERSION			0x14UL
arch/x86/kvm/mmu.h +0 -4
index caec3d11638d..f6014b7963ed 100644
@@ -238,11 +238,7 @@ static inline bool kvm_shadow_root_allocated(struct kvm *kvm)
 	return smp_load_acquire(&kvm->arch.shadow_root_allocated);
 }
 
-#ifdef CONFIG_X86_64
 extern bool tdp_mmu_enabled;
-#else
-#define tdp_mmu_enabled false
-#endif
 
 static inline bool kvm_memslots_have_rmaps(struct kvm *kvm)
 {
arch/x86/kvm/mmu/mmu.c +0 -134

210 lines not on this page · raw message

arch/x86/kvm/mmu/mmu_internal.h +0 -9
index 72de71f4bc8b..5eed5653d977 100644
@@ -116,21 +116,12 @@ struct kvm_mmu_page {
 	 * isn't properly aligned, etc...
 	 */
 	struct list_head possible_nx_huge_page_link;
-#ifdef CONFIG_X86_32
-	/*
-	 * Used out of the mmu-lock to avoid reading spte values while an
-	 * update is in progress; see the comments in __get_spte_lockless().
-	 */
-	int clear_spte_count;
-#endif
 
 	/* Number of writes since the last time traversal visited this page.  */
 	atomic_t write_flooding_count;
 
-#ifdef CONFIG_X86_64
 	/* Used for freeing the page asynchronously if it is a TDP MMU page. */
 	struct rcu_head rcu_head;
-#endif
 };
 
 extern struct kmem_cache *mmu_page_header_cache;
arch/x86/kvm/mmu/paging_tmpl.h +0 -9
index f4711674c47b..fa6493641429 100644
@@ -29,11 +29,7 @@
 	#define PT_GUEST_DIRTY_SHIFT PT_DIRTY_SHIFT
 	#define PT_GUEST_ACCESSED_SHIFT PT_ACCESSED_SHIFT
 	#define PT_HAVE_ACCESSED_DIRTY(mmu) true
-	#ifdef CONFIG_X86_64
 	#define PT_MAX_FULL_LEVELS PT64_ROOT_MAX_LEVEL
-	#else
-	#define PT_MAX_FULL_LEVELS 2
-	#endif
 #elif PTTYPE == 32
 	#define pt_element_t u32
 	#define guest_walker guest_walker32
@@ -862,11 +858,6 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
 	gpa_t gpa = INVALID_GPA;
 	int r;
 
-#ifndef CONFIG_X86_64
-	/* A 64-bit GVA should be impossible on 32-bit KVM. */
-	WARN_ON_ONCE((addr >> 32) && mmu == vcpu->arch.walk_mmu);
-#endif
-
 	r = FNAME(walk_addr_generic)(&walker, vcpu, mmu, addr, access);
 
 	if (r) {
arch/x86/kvm/mmu/spte.h +0 -5
index af10bc0380a3..6806ca4553a4 100644
@@ -160,13 +160,8 @@ static_assert(MMIO_SPTE_GEN_LOW_BITS == 8 && MMIO_SPTE_GEN_HIGH_BITS == 11);
  * For VMX EPT, bit 63 is ignored if #VE is disabled. (EPT_VIOLATION_VE=0)
  *              bit 63 is #VE suppress if #VE is enabled. (EPT_VIOLATION_VE=1)
  */
-#ifdef CONFIG_X86_64
 #define SHADOW_NONPRESENT_VALUE	BIT_ULL(63)
 static_assert(!(SHADOW_NONPRESENT_VALUE & SPTE_MMU_PRESENT_MASK));
-#else
-#define SHADOW_NONPRESENT_VALUE	0ULL
-#endif
-
 
 /*
  * True if A/D bits are supported in hardware and are enabled by KVM.  When
arch/x86/kvm/mmu/tdp_mmu.h +0 -4
index f03ca0dd13d9..c137fdd6b347 100644
@@ -67,10 +67,6 @@ int kvm_tdp_mmu_get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes,
 u64 *kvm_tdp_mmu_fast_pf_get_last_sptep(struct kvm_vcpu *vcpu, gfn_t gfn,
 					u64 *spte);
 
-#ifdef CONFIG_X86_64
 static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return sp->tdp_mmu_page; }
-#else
-static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; }
-#endif
 
 #endif /* __KVM_X86_MMU_TDP_MMU_H */
arch/x86/kvm/smm.c +0 -19
index e0ab7df27b66..e1187a5b43c0 100644
@@ -165,7 +165,6 @@ static void enter_smm_save_seg_32(struct kvm_vcpu *vcpu,
 	state->flags = enter_smm_get_segment_flags(&seg);
 }
 
-#ifdef CONFIG_X86_64
 static void enter_smm_save_seg_64(struct kvm_vcpu *vcpu,
 				  struct kvm_smm_seg_state_64 *state,
 				  int n)
@@ -178,7 +177,6 @@ static void enter_smm_save_seg_64(struct kvm_vcpu *vcpu,
 	state->limit = seg.limit;
 	state->base = seg.base;
 }
-#endif
 
 static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
 				    struct kvm_smram_state_32 *smram)
@@ -223,7 +221,6 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vcpu,
 	smram->int_shadow = kvm_x86_call(get_interrupt_shadow)(vcpu);
 }
 
-#ifdef CONFIG_X86_64
 static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
 				    struct kvm_smram_state_64 *smram)
 {
@@ -269,7 +266,6 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu,
 
 	smram->int_shadow = kvm_x86_call(get_interrupt_shadow)(vcpu);
 }
-#endif
 
 void enter_smm(struct kvm_vcpu *vcpu)
 {
@@ -282,11 +278,9 @@ void enter_smm(struct kvm_vcpu *vcpu)
 
 	memset(smram.bytes, 0, sizeof(smram.bytes));
 
-#ifdef CONFIG_X86_64
 	if (guest_cpu_cap_has(vcpu, X86_FEATURE_LM))
 		enter_smm_save_state_64(vcpu, &smram.smram64);
 	else
-#endif
 		enter_smm_save_state_32(vcpu, &smram.smram32);
 
 	/*
@@ -352,11 +346,9 @@ void enter_smm(struct kvm_vcpu *vcpu)
 	kvm_set_segment(vcpu, &ds, VCPU_SREG_GS);
 	kvm_set_segment(vcpu, &ds, VCPU_SREG_SS);
 
-#ifdef CONFIG_X86_64
 	if (guest_cpu_cap_has(vcpu, X86_FEATURE_LM))
 		if (kvm_x86_call(set_efer)(vcpu, 0))
 			goto error;
-#endif
 
 	kvm_update_cpuid_runtime(vcpu);
 	kvm_mmu_reset_context(vcpu);
@@ -394,8 +386,6 @@ static int rsm_load_seg_32(struct kvm_vcpu *vcpu,
 	return X86EMUL_CONTINUE;
 }
 
-#ifdef CONFIG_X86_64
-
 static int rsm_load_seg_64(struct kvm_vcpu *vcpu,
 			   const struct kvm_smm_seg_state_64 *state,
 			   int n)
@@ -409,7 +399,6 @@ static int rsm_load_seg_64(struct kvm_vcpu *vcpu,
 	kvm_set_segment(vcpu, &desc, n);
 	return X86EMUL_CONTINUE;
 }
-#endif
 
 static int rsm_enter_protected_mode(struct kvm_vcpu *vcpu,
 				    u64 cr0, u64 cr3, u64 cr4)
@@ -507,7 +496,6 @@ static int rsm_load_state_32(struct x86_emulate_ctxt *ctxt,
 	return r;
 }
 
-#ifdef CONFIG_X86_64
 static int rsm_load_state_64(struct x86_emulate_ctxt *ctxt,
 			     const struct kvm_smram_state_64 *smstate)
 {
@@ -559,7 +547,6 @@ static int rsm_load_state_64(struct x86_emulate_ctxt *ctxt,
 
 	return X86EMUL_CONTINUE;
 }
-#endif
 
 int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
 {
@@ -585,7 +572,6 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
 	 * CR0/CR3/CR4/EFER.  It's all a bit more complicated if the vCPU
 	 * supports long mode.
 	 */
-#ifdef CONFIG_X86_64
 	if (guest_cpu_cap_has(vcpu, X86_FEATURE_LM)) {
 		struct kvm_segment cs_desc;
 		unsigned long cr4;
@@ -601,14 +587,12 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
 		cs_desc.s = cs_desc.g = cs_desc.present = 1;
 		kvm_set_segment(vcpu, &cs_desc, VCPU_SREG_CS);
 	}
-#endif
 
 	/* For the 64-bit case, this will clear EFER.LMA.  */
 	cr0 = kvm_read_cr0(vcpu);
 	if (cr0 & X86_CR0_PE)
 		kvm_set_cr0(vcpu, cr0 & ~(X86_CR0_PG | X86_CR0_PE));
 
-#ifdef CONFIG_X86_64
 	if (guest_cpu_cap_has(vcpu, X86_FEATURE_LM)) {
 		unsigned long cr4, efer;
 
@@ -621,7 +605,6 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
 		efer = 0;
 		kvm_set_msr(vcpu, MSR_EFER, efer);
 	}
-#endif
 
 	/*
 	 * FIXME: When resuming L2 (a.k.a. guest mode), the transition to guest
@@ -633,11 +616,9 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
 	if (kvm_x86_call(leave_smm)(vcpu, &smram))
 		return X86EMUL_UNHANDLEABLE;
 
-#ifdef CONFIG_X86_64
 	if (guest_cpu_cap_has(vcpu, X86_FEATURE_LM))
 		ret = rsm_load_state_64(ctxt, &smram.smram64);
 	else
-#endif
 		ret = rsm_load_state_32(ctxt, &smram.smram32);
 
 	/*
arch/x86/kvm/svm/sev.c +0 -2
index 4b0ef13c7496..bb22b87235ca 100644
@@ -830,7 +830,6 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
 	save->rbp = svm->vcpu.arch.regs[VCPU_REGS_RBP];
 	save->rsi = svm->vcpu.arch.regs[VCPU_REGS_RSI];
 	save->rdi = svm->vcpu.arch.regs[VCPU_REGS_RDI];
-#ifdef CONFIG_X86_64
 	save->r8  = svm->vcpu.arch.regs[VCPU_REGS_R8];
 	save->r9  = svm->vcpu.arch.regs[VCPU_REGS_R9];
 	save->r10 = svm->vcpu.arch.regs[VCPU_REGS_R10];
@@ -839,7 +838,6 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
 	save->r13 = svm->vcpu.arch.regs[VCPU_REGS_R13];
 	save->r14 = svm->vcpu.arch.regs[VCPU_REGS_R14];
 	save->r15 = svm->vcpu.arch.regs[VCPU_REGS_R15];
-#endif
 	save->rip = svm->vcpu.arch.regs[VCPU_REGS_RIP];
 
 	/* Sync some non-GPR registers before encrypting */
arch/x86/kvm/svm/svm.c +1 -22
index 78daedf6697b..305a6716f6eb 100644
@@ -89,14 +89,12 @@ static const struct svm_direct_access_msrs {
 	{ .index = MSR_IA32_SYSENTER_CS,		.always = true  },
 	{ .index = MSR_IA32_SYSENTER_EIP,		.always = false },
 	{ .index = MSR_IA32_SYSENTER_ESP,		.always = false },
-#ifdef CONFIG_X86_64
 	{ .index = MSR_GS_BASE,				.always = true  },
 	{ .index = MSR_FS_BASE,				.always = true  },
 	{ .index = MSR_KERNEL_GS_BASE,			.always = true  },
 	{ .index = MSR_LSTAR,				.always = true  },
 	{ .index = MSR_CSTAR,				.always = true  },
 	{ .index = MSR_SYSCALL_MASK,			.always = true  },
-#endif
 	{ .index = MSR_IA32_SPEC_CTRL,			.always = false },
 	{ .index = MSR_IA32_PRED_CMD,			.always = false },
 	{ .index = MSR_IA32_FLUSH_CMD,			.always = false },
@@ -286,11 +284,7 @@ u32 svm_msrpm_offset(u32 msr)
 
 static int get_npt_level(void)
 {
-#ifdef CONFIG_X86_64
 	return pgtable_l5_enabled() ? PT64_ROOT_5LEVEL : PT64_ROOT_4LEVEL;
-#else
-	return PT32E_ROOT_LEVEL;
-#endif
 }
 
 int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
@@ -1858,7 +1852,6 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 	u64 hcr0 = cr0;
 	bool old_paging = is_paging(vcpu);
 
-#ifdef CONFIG_X86_64
 	if (vcpu->arch.efer & EFER_LME) {
 		if (!is_paging(vcpu) && (cr0 & X86_CR0_PG)) {
 			vcpu->arch.efer |= EFER_LMA;
@@ -1872,7 +1865,6 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 				svm->vmcb->save.efer &= ~(EFER_LMA | EFER_LME);
 		}
 	}
-#endif
 	vcpu->arch.cr0 = cr0;
 
 	if (!npt_enabled) {
@@ -2866,7 +2858,6 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	case MSR_STAR:
 		msr_info->data = svm->vmcb01.ptr->save.star;
 		break;
-#ifdef CONFIG_X86_64
 	case MSR_LSTAR:
 		msr_info->data = svm->vmcb01.ptr->save.lstar;
 		break;
@@ -2885,7 +2876,6 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	case MSR_SYSCALL_MASK:
 		msr_info->data = svm->vmcb01.ptr->save.sfmask;
 		break;
-#endif
 	case MSR_IA32_SYSENTER_CS:
 		msr_info->data = svm->vmcb01.ptr->save.sysenter_cs;
 		break;
@@ -3097,7 +3087,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 	case MSR_STAR:
 		svm->vmcb01.ptr->save.star = data;
 		break;
-#ifdef CONFIG_X86_64
 	case MSR_LSTAR:
 		svm->vmcb01.ptr->save.lstar = data;
 		break;
@@ -3116,7 +3105,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 	case MSR_SYSCALL_MASK:
 		svm->vmcb01.ptr->save.sfmask = data;
 		break;
-#endif
 	case MSR_IA32_SYSENTER_CS:
 		svm->vmcb01.ptr->save.sysenter_cs = data;
 		break;
@@ -5321,14 +5309,6 @@ static __init int svm_hardware_setup(void)
 		kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE);
 	}
 
-	/*
-	 * KVM's MMU doesn't support using 2-level paging for itself, and thus
-	 * NPT isn't supported if the host is using 2-level paging since host
-	 * CR4 is unchanged on VMRUN.
-	 */
-	if (!IS_ENABLED(CONFIG_X86_64) && !IS_ENABLED(CONFIG_X86_PAE))
-		npt_enabled = false;
-
 	if (!boot_cpu_has(X86_FEATURE_NPT))
 		npt_enabled = false;
 
@@ -5376,8 +5356,7 @@ static __init int svm_hardware_setup(void)
 
 	if (vls) {
 		if (!npt_enabled ||
-		    !boot_cpu_has(X86_FEATURE_V_VMSAVE_VMLOAD) ||
-		    !IS_ENABLED(CONFIG_X86_64)) {
+		    !boot_cpu_has(X86_FEATURE_V_VMSAVE_VMLOAD)) {
 			vls = false;
 		} else {
 			pr_info("Virtual VMLOAD VMSAVE supported\n");
arch/x86/kvm/svm/vmenter.S +0 -20
index 2ed80aea3bb1..2e8c0f5a238a 100644
@@ -19,7 +19,6 @@
 #define VCPU_RSI	(SVM_vcpu_arch_regs + __VCPU_REGS_RSI * WORD_SIZE)
 #define VCPU_RDI	(SVM_vcpu_arch_regs + __VCPU_REGS_RDI * WORD_SIZE)
 
-#ifdef CONFIG_X86_64
 #define VCPU_R8		(SVM_vcpu_arch_regs + __VCPU_REGS_R8  * WORD_SIZE)
 #define VCPU_R9		(SVM_vcpu_arch_regs + __VCPU_REGS_R9  * WORD_SIZE)
 #define VCPU_R10	(SVM_vcpu_arch_regs + __VCPU_REGS_R10 * WORD_SIZE)
@@ -28,7 +27,6 @@
 #define VCPU_R13	(SVM_vcpu_arch_regs + __VCPU_REGS_R13 * WORD_SIZE)
 #define VCPU_R14	(SVM_vcpu_arch_regs + __VCPU_REGS_R14 * WORD_SIZE)
 #define VCPU_R15	(SVM_vcpu_arch_regs + __VCPU_REGS_R15 * WORD_SIZE)
-#endif
 
 #define SVM_vmcb01_pa	(SVM_vmcb01 + KVM_VMCB_pa)
 
@@ -101,15 +99,10 @@
 SYM_FUNC_START(__svm_vcpu_run)
 	push %_ASM_BP
 	mov  %_ASM_SP, %_ASM_BP
-#ifdef CONFIG_X86_64
 	push %r15
 	push %r14
 	push %r13
 	push %r12
-#else
-	push %edi
-	push %esi
-#endif
 	push %_ASM_BX
 
 	/*
@@ -157,7 +150,6 @@ SYM_FUNC_START(__svm_vcpu_run)
 	mov VCPU_RBX(%_ASM_DI), %_ASM_BX
 	mov VCPU_RBP(%_ASM_DI), %_ASM_BP
 	mov VCPU_RSI(%_ASM_DI), %_ASM_SI
-#ifdef CONFIG_X86_64
 	mov VCPU_R8 (%_ASM_DI),  %r8
 	mov VCPU_R9 (%_ASM_DI),  %r9
 	mov VCPU_R10(%_ASM_DI), %r10
@@ -166,7 +158,6 @@ SYM_FUNC_START(__svm_vcpu_run)
 	mov VCPU_R13(%_ASM_DI), %r13
 	mov VCPU_R14(%_ASM_DI), %r14
 	mov VCPU_R15(%_ASM_DI), %r15
-#endif
 	mov VCPU_RDI(%_ASM_DI), %_ASM_DI
 
 	/* Enter guest mode */
@@ -186,7 +177,6 @@ SYM_FUNC_START(__svm_vcpu_run)
 	mov %_ASM_BP,   VCPU_RBP(%_ASM_AX)
 	mov %_ASM_SI,   VCPU_RSI(%_ASM_AX)
 	mov %_ASM_DI,   VCPU_RDI(%_ASM_AX)
-#ifdef CONFIG_X86_64
 	mov %r8,  VCPU_R8 (%_ASM_AX)
 	mov %r9,  VCPU_R9 (%_ASM_AX)
 	mov %r10, VCPU_R10(%_ASM_AX)
@@ -195,7 +185,6 @@ SYM_FUNC_START(__svm_vcpu_run)
 	mov %r13, VCPU_R13(%_ASM_AX)
 	mov %r14, VCPU_R14(%_ASM_AX)
 	mov %r15, VCPU_R15(%_ASM_AX)
-#endif
 
 	/* @svm can stay in RDI from now on.  */
 	mov %_ASM_AX, %_ASM_DI
@@ -239,7 +228,6 @@ SYM_FUNC_START(__svm_vcpu_run)
 	xor %ebp, %ebp
 	xor %esi, %esi
 	xor %edi, %edi
-#ifdef CONFIG_X86_64
 	xor %r8d,  %r8d
 	xor %r9d,  %r9d
 	xor %r10d, %r10d
@@ -248,22 +236,16 @@ SYM_FUNC_START(__svm_vcpu_run)
 	xor %r13d, %r13d
 	xor %r14d, %r14d
 	xor %r15d, %r15d
-#endif
 
 	/* "Pop" @spec_ctrl_intercepted.  */
 	pop %_ASM_BX
 
 	pop %_ASM_BX
 
-#ifdef CONFIG_X86_64
 	pop %r12
 	pop %r13
 	pop %r14
 	pop %r15
-#else
-	pop %esi
-	pop %edi
-#endif
 	pop %_ASM_BP
 	RET
 
@@ -293,7 +275,6 @@ SYM_FUNC_END(__svm_vcpu_run)
 #ifdef CONFIG_KVM_AMD_SEV
 
 
-#ifdef CONFIG_X86_64
 #define SEV_ES_GPRS_BASE 0x300
 #define SEV_ES_RBX	(SEV_ES_GPRS_BASE + __VCPU_REGS_RBX * WORD_SIZE)
 #define SEV_ES_RBP	(SEV_ES_GPRS_BASE + __VCPU_REGS_RBP * WORD_SIZE)
@@ -303,7 +284,6 @@ SYM_FUNC_END(__svm_vcpu_run)
 #define SEV_ES_R13	(SEV_ES_GPRS_BASE + __VCPU_REGS_R13 * WORD_SIZE)
 #define SEV_ES_R14	(SEV_ES_GPRS_BASE + __VCPU_REGS_R14 * WORD_SIZE)
 #define SEV_ES_R15	(SEV_ES_GPRS_BASE + __VCPU_REGS_R15 * WORD_SIZE)
-#endif
 
 /**
  * __svm_sev_es_vcpu_run - Run a SEV-ES vCPU via a transition to SVM guest mode
arch/x86/kvm/trace.h +0 -4
index 0b844cb97978..d11cf415d3f5 100644
@@ -908,8 +908,6 @@ TRACE_EVENT(kvm_write_tsc_offset,
 		  __entry->previous_tsc_offset, __entry->next_tsc_offset)
 );
 
-#ifdef CONFIG_X86_64
-
 #define host_clocks					\
 	{VDSO_CLOCKMODE_NONE, "none"},			\
 	{VDSO_CLOCKMODE_TSC,  "tsc"}			\
@@ -966,8 +964,6 @@ TRACE_EVENT(kvm_track_tsc,
 		  __print_symbolic(__entry->host_clock, host_clocks))
 );
 
-#endif /* CONFIG_X86_64 */
-
 /*
  * Tracepoint for PML full VMEXIT.
  */
arch/x86/kvm/vmx/main.c +0 -2
index 3d31ea1ab3e3..60c0733623d9 100644
@@ -134,10 +134,8 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
 	.pi_update_irte = vmx_pi_update_irte,
 	.pi_start_assignment = vmx_pi_start_assignment,
 
-#ifdef CONFIG_X86_64
 	.set_hv_timer = vmx_set_hv_timer,
 	.cancel_hv_timer = vmx_cancel_hv_timer,
-#endif
 
 	.setup_mce = vmx_setup_mce,
 
arch/x86/kvm/vmx/nested.c +2 -22
index 864bd97cc5c5..242bde903b16 100644
@@ -86,11 +86,7 @@ static void init_vmcs_shadow_fields(void)
 
 		clear_bit(field, vmx_vmread_bitmap);
 		if (field & 1)
-#ifdef CONFIG_X86_64
 			continue;
-#else
-			entry.offset += sizeof(u32);
-#endif
 		shadow_read_only_fields[j++] = entry;
 	}
 	max_shadow_read_only_fields = j;
@@ -134,11 +130,7 @@ static void init_vmcs_shadow_fields(void)
 		clear_bit(field, vmx_vmwrite_bitmap);
 		clear_bit(field, vmx_vmread_bitmap);
 		if (field & 1)
-#ifdef CONFIG_X86_64
 			continue;
-#else
-			entry.offset += sizeof(u32);
-#endif
 		shadow_read_write_fields[j++] = entry;
 	}
 	max_shadow_read_write_fields = j;
@@ -283,10 +275,8 @@ static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx,
 
 	vmx_set_host_fs_gs(dest, src->fs_sel, src->gs_sel, src->fs_base, src->gs_base);
 	dest->ldt_sel = src->ldt_sel;
-#ifdef CONFIG_X86_64
 	dest->ds_sel = src->ds_sel;
 	dest->es_sel = src->es_sel;
-#endif
 }
 
 static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
@@ -695,7 +685,6 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
 	 * Always check vmcs01's bitmap to honor userspace MSR filters and any
 	 * other runtime changes to vmcs01's bitmap, e.g. dynamic pass-through.
 	 */
-#ifdef CONFIG_X86_64
 	nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
 					 MSR_FS_BASE, MSR_TYPE_RW);
 
@@ -704,7 +693,7 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
 
 	nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
 					 MSR_KERNEL_GS_BASE, MSR_TYPE_RW);
-#endif
+
 	nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
 					 MSR_IA32_SPEC_CTRL, MSR_TYPE_RW);
 
@@ -2375,11 +2364,9 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0
 	vmx->nested.l1_tpr_threshold = -1;
 	if (exec_control & CPU_BASED_TPR_SHADOW)
 		vmcs_write32(TPR_THRESHOLD, vmcs12->tpr_threshold);
-#ifdef CONFIG_X86_64
 	else
 		exec_control |= CPU_BASED_CR8_LOAD_EXITING |
 				CPU_BASED_CR8_STORE_EXITING;
-#endif
 
 	/*
 	 * A vmexit (to either L1 hypervisor or L0 userspace) is always needed
@@ -3002,11 +2989,10 @@ static int nested_vmx_check_controls(struct kvm_vcpu *vcpu,
 static int nested_vmx_check_address_space_size(struct kvm_vcpu *vcpu,
 				       struct vmcs12 *vmcs12)
 {
-#ifdef CONFIG_X86_64
 	if (CC(!!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE) !=
 		!!(vcpu->arch.efer & EFER_LMA)))
 		return -EINVAL;
-#endif
+
 	return 0;
 }
 
@@ -6995,9 +6981,7 @@ static void nested_vmx_setup_exit_ctls(struct vmcs_config *vmcs_conf,
 
 	msrs->exit_ctls_high = vmcs_conf->vmexit_ctrl;
 	msrs->exit_ctls_high &=
-#ifdef CONFIG_X86_64
 		VM_EXIT_HOST_ADDR_SPACE_SIZE |
-#endif
 		VM_EXIT_LOAD_IA32_PAT | VM_EXIT_SAVE_IA32_PAT |
 		VM_EXIT_CLEAR_BNDCFGS;
 	msrs->exit_ctls_high |=
@@ -7018,9 +7002,7 @@ static void nested_vmx_setup_entry_ctls(struct vmcs_config *vmcs_conf,
 
 	msrs->entry_ctls_high = vmcs_conf->vmentry_ctrl;
 	msrs->entry_ctls_high &=
-#ifdef CONFIG_X86_64
 		VM_ENTRY_IA32E_MODE |
-#endif
 		VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_BNDCFGS;
 	msrs->entry_ctls_high |=
 		(VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR | VM_ENTRY_LOAD_IA32_EFER |
@@ -7043,9 +7025,7 @@ static void nested_vmx_setup_cpubased_ctls(struct vmcs_config *vmcs_conf,
 		CPU_BASED_HLT_EXITING | CPU_BASED_INVLPG_EXITING |
 		CPU_BASED_MWAIT_EXITING | CPU_BASED_CR3_LOAD_EXITING |
 		CPU_BASED_CR3_STORE_EXITING |
-#ifdef CONFIG_X86_64
 		CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING |
-#endif
 		CPU_BASED_MOV_DR_EXITING | CPU_BASED_UNCOND_IO_EXITING |
 		CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_TRAP_FLAG |
 		CPU_BASED_MONITOR_EXITING | CPU_BASED_RDPMC_EXITING |
arch/x86/kvm/vmx/vmcs.h +0 -2
index b25625314658..487137da7860 100644
@@ -39,9 +39,7 @@ struct vmcs_host_state {
 	unsigned long rsp;
 
 	u16           fs_sel, gs_sel, ldt_sel;
-#ifdef CONFIG_X86_64
 	u16           ds_sel, es_sel;
-#endif
 };
 
 struct vmcs_controls_shadow {
arch/x86/kvm/vmx/vmenter.S +1 -24
index f6986dee6f8c..5a548724ca1f 100644
@@ -20,7 +20,6 @@
 #define VCPU_RSI	__VCPU_REGS_RSI * WORD_SIZE
 #define VCPU_RDI	__VCPU_REGS_RDI * WORD_SIZE
 
-#ifdef CONFIG_X86_64
 #define VCPU_R8		__VCPU_REGS_R8  * WORD_SIZE
 #define VCPU_R9		__VCPU_REGS_R9  * WORD_SIZE
 #define VCPU_R10	__VCPU_REGS_R10 * WORD_SIZE
@@ -29,7 +28,6 @@
 #define VCPU_R13	__VCPU_REGS_R13 * WORD_SIZE
 #define VCPU_R14	__VCPU_REGS_R14 * WORD_SIZE
 #define VCPU_R15	__VCPU_REGS_R15 * WORD_SIZE
-#endif
 
 .macro VMX_DO_EVENT_IRQOFF call_insn call_target
 	/*
@@ -40,7 +38,6 @@
 	push %_ASM_BP
 	mov %_ASM_SP, %_ASM_BP
 
-#ifdef CONFIG_X86_64
 	/*
 	 * Align RSP to a 16-byte boundary (to emulate CPU behavior) before
 	 * creating the synthetic interrupt stack frame for the IRQ/NMI.
@@ -48,7 +45,6 @@
 	and  $-16, %rsp
 	push $__KERNEL_DS
 	push %rbp
-#endif
 	pushf
 	push $__KERNEL_CS
 	\call_insn \call_target
@@ -79,15 +75,10 @@
 SYM_FUNC_START(__vmx_vcpu_run)
 	push %_ASM_BP
 	mov  %_ASM_SP, %_ASM_BP
-#ifdef CONFIG_X86_64
 	push %r15
 	push %r14
 	push %r13
 	push %r12
-#else
-	push %edi
-	push %esi
-#endif
 	push %_ASM_BX
 
 	/* Save @vmx for SPEC_CTRL handling */
@@ -148,7 +139,6 @@ SYM_FUNC_START(__vmx_vcpu_run)
 	mov VCPU_RBP(%_ASM_AX), %_ASM_BP
 	mov VCPU_RSI(%_ASM_AX), %_ASM_SI
 	mov VCPU_RDI(%_ASM_AX), %_ASM_DI
-#ifdef CONFIG_X86_64
 	mov VCPU_R8 (%_ASM_AX),  %r8
 	mov VCPU_R9 (%_ASM_AX),  %r9
 	mov VCPU_R10(%_ASM_AX), %r10
@@ -157,7 +147,7 @@ SYM_FUNC_START(__vmx_vcpu_run)
 	mov VCPU_R13(%_ASM_AX), %r13
 	mov VCPU_R14(%_ASM_AX), %r14
 	mov VCPU_R15(%_ASM_AX), %r15
-#endif
+
 	/* Load guest RAX.  This kills the @regs pointer! */
 	mov VCPU_RAX(%_ASM_AX), %_ASM_AX
 
@@ -210,7 +200,6 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	mov %_ASM_BP, VCPU_RBP(%_ASM_AX)
 	mov %_ASM_SI, VCPU_RSI(%_ASM_AX)
 	mov %_ASM_DI, VCPU_RDI(%_ASM_AX)
-#ifdef CONFIG_X86_64
 	mov %r8,  VCPU_R8 (%_ASM_AX)
 	mov %r9,  VCPU_R9 (%_ASM_AX)
 	mov %r10, VCPU_R10(%_ASM_AX)
@@ -219,7 +208,6 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	mov %r13, VCPU_R13(%_ASM_AX)
 	mov %r14, VCPU_R14(%_ASM_AX)
 	mov %r15, VCPU_R15(%_ASM_AX)
-#endif
 
 	/* Clear return value to indicate VM-Exit (as opposed to VM-Fail). */
 	xor %ebx, %ebx
@@ -244,7 +232,6 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	xor %ebp, %ebp
 	xor %esi, %esi
 	xor %edi, %edi
-#ifdef CONFIG_X86_64
 	xor %r8d,  %r8d
 	xor %r9d,  %r9d
 	xor %r10d, %r10d
@@ -253,7 +240,6 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	xor %r13d, %r13d
 	xor %r14d, %r14d
 	xor %r15d, %r15d
-#endif
 
 	/*
 	 * IMPORTANT: RSB filling and SPEC_CTRL handling must be done before
@@ -281,15 +267,10 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL)
 	mov %_ASM_BX, %_ASM_AX
 
 	pop %_ASM_BX
-#ifdef CONFIG_X86_64
 	pop %r12
 	pop %r13
 	pop %r14
 	pop %r15
-#else
-	pop %esi
-	pop %edi
-#endif
 	pop %_ASM_BP
 	RET
 
@@ -325,14 +306,12 @@ SYM_FUNC_START(vmread_error_trampoline)
 	push %_ASM_AX
 	push %_ASM_CX
 	push %_ASM_DX
-#ifdef CONFIG_X86_64
 	push %rdi
 	push %rsi
 	push %r8
 	push %r9
 	push %r10
 	push %r11
-#endif
 
 	/* Load @field and @fault to arg1 and arg2 respectively. */
 	mov 3*WORD_SIZE(%_ASM_BP), %_ASM_ARG2
@@ -343,14 +322,12 @@ SYM_FUNC_START(vmread_error_trampoline)
 	/* Zero out @fault, which will be popped into the result register. */
 	_ASM_MOV $0, 3*WORD_SIZE(%_ASM_BP)
 
-#ifdef CONFIG_X86_64
 	pop %r11
 	pop %r10
 	pop %r9
 	pop %r8
 	pop %rsi
 	pop %rdi
-#endif
 	pop %_ASM_DX
 	pop %_ASM_CX
 	pop %_ASM_AX
arch/x86/kvm/vmx/vmx.c +4 -113

377 lines not on this page · raw message

arch/x86/kvm/vmx/vmx.h +2 -21
index 892302022094..01669880344d 100644
@@ -19,11 +19,7 @@
 
 #define X2APIC_MSR(r) (APIC_BASE_MSR + ((r) >> 4))
 
-#ifdef CONFIG_X86_64
 #define MAX_NR_USER_RETURN_MSRS	7
-#else
-#define MAX_NR_USER_RETURN_MSRS	4
-#endif
 
 #define MAX_NR_LOADSTORE_MSRS	8
 
@@ -273,10 +269,8 @@ struct vcpu_vmx {
 	 */
 	struct vmx_uret_msr   guest_uret_msrs[MAX_NR_USER_RETURN_MSRS];
 	bool                  guest_uret_msrs_loaded;
-#ifdef CONFIG_X86_64
 	u64		      msr_host_kernel_gs_base;
 	u64		      msr_guest_kernel_gs_base;
-#endif
 
 	u64		      spec_ctrl;
 	u32		      msr_ia32_umwait_control;
@@ -471,14 +465,10 @@ static inline u8 vmx_get_rvi(void)
 
 #define __KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS				\
 	(VM_ENTRY_LOAD_DEBUG_CONTROLS)
-#ifdef CONFIG_X86_64
 	#define KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS			\
 		(__KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS |			\
 		 VM_ENTRY_IA32E_MODE)
-#else
-	#define KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS			\
-		__KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS
-#endif
+
 #define KVM_OPTIONAL_VMX_VM_ENTRY_CONTROLS				\
 	(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |				\
 	 VM_ENTRY_LOAD_IA32_PAT |					\
@@ -490,14 +480,10 @@ static inline u8 vmx_get_rvi(void)
 #define __KVM_REQUIRED_VMX_VM_EXIT_CONTROLS				\
 	(VM_EXIT_SAVE_DEBUG_CONTROLS |					\
 	 VM_EXIT_ACK_INTR_ON_EXIT)
-#ifdef CONFIG_X86_64
 	#define KVM_REQUIRED_VMX_VM_EXIT_CONTROLS			\
 		(__KVM_REQUIRED_VMX_VM_EXIT_CONTROLS |			\
 		 VM_EXIT_HOST_ADDR_SPACE_SIZE)
-#else
-	#define KVM_REQUIRED_VMX_VM_EXIT_CONTROLS			\
-		__KVM_REQUIRED_VMX_VM_EXIT_CONTROLS
-#endif
+
 #define KVM_OPTIONAL_VMX_VM_EXIT_CONTROLS				\
 	      (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL |			\
 	       VM_EXIT_SAVE_IA32_PAT |					\
@@ -530,15 +516,10 @@ static inline u8 vmx_get_rvi(void)
 	 CPU_BASED_RDPMC_EXITING |					\
 	 CPU_BASED_INTR_WINDOW_EXITING)
 
-#ifdef CONFIG_X86_64
 	#define KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL		\
 		(__KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL |		\
 		 CPU_BASED_CR8_LOAD_EXITING |				\
 		 CPU_BASED_CR8_STORE_EXITING)
-#else
-	#define KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL		\
-		__KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL
-#endif
 
 #define KVM_OPTIONAL_VMX_CPU_BASED_VM_EXEC_CONTROL			\
 	(CPU_BASED_RDTSC_EXITING |					\
arch/x86/kvm/vmx/vmx_ops.h +0 -7
index 633c87e2fd92..72031b669925 100644
@@ -171,11 +171,7 @@ static __always_inline u64 vmcs_read64(unsigned long field)
 	vmcs_check64(field);
 	if (kvm_is_using_evmcs())
 		return evmcs_read64(field);
-#ifdef CONFIG_X86_64
 	return __vmcs_readl(field);
-#else
-	return __vmcs_readl(field) | ((u64)__vmcs_readl(field+1) << 32);
-#endif
 }
 
 static __always_inline unsigned long vmcs_readl(unsigned long field)
@@ -250,9 +246,6 @@ static __always_inline void vmcs_write64(unsigned long field, u64 value)
 		return evmcs_write64(field, value);
 
 	__vmcs_writel(field, value);
-#ifndef CONFIG_X86_64
-	__vmcs_writel(field+1, value >> 32);
-#endif
 }
 
 static __always_inline void vmcs_writel(unsigned long field, unsigned long value)
arch/x86/kvm/vmx/x86_ops.h +0 -2
index ce3295a67c04..9802d73fab4f 100644
@@ -113,11 +113,9 @@ u64 vmx_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu);
 void vmx_write_tsc_offset(struct kvm_vcpu *vcpu);
 void vmx_write_tsc_multiplier(struct kvm_vcpu *vcpu);
 void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
-#ifdef CONFIG_X86_64
 int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc,
 		     bool *expired);
 void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu);
-#endif
 void vmx_setup_mce(struct kvm_vcpu *vcpu);
 
 #endif /* __KVM_X86_VMX_X86_OPS_H */
arch/x86/kvm/x86.c +6 -68

363 lines not on this page · raw message

arch/x86/kvm/x86.h +0 -4
index 7a87c5fc57f1..82db7880c9f3 100644
@@ -166,11 +166,7 @@ static inline bool is_protmode(struct kvm_vcpu *vcpu)
 
 static inline bool is_long_mode(struct kvm_vcpu *vcpu)
 {
-#ifdef CONFIG_X86_64
 	return !!(vcpu->arch.efer & EFER_LMA);
-#else
-	return false;
-#endif
 }
 
 static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu)
arch/x86/kvm/xen.c +23 -38

171 lines not on this page · raw message

Signature · 1 line
2.39.5