Skip to content

Commit b4bbb95

Browse files
committed
RISC-V: KVM: Add Sv57x4 mode support for G-stage
Latest QEMU supports G-stage Sv57x4 mode so this patch extends KVM RISC-V G-stage handling to detect and use Sv57x4 mode when available. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent 2670823 commit b4bbb95

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

arch/riscv/include/asm/csr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#define HGATP_MODE_SV32X4 _AC(1, UL)
118118
#define HGATP_MODE_SV39X4 _AC(8, UL)
119119
#define HGATP_MODE_SV48X4 _AC(9, UL)
120+
#define HGATP_MODE_SV57X4 _AC(10, UL)
120121

121122
#define HGATP32_MODE_SHIFT 31
122123
#define HGATP32_VMID_SHIFT 22

arch/riscv/kvm/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ int kvm_arch_init(void *opaque)
105105
case HGATP_MODE_SV48X4:
106106
str = "Sv48x4";
107107
break;
108+
case HGATP_MODE_SV57X4:
109+
str = "Sv57x4";
110+
break;
108111
default:
109112
return -ENODEV;
110113
}

arch/riscv/kvm/mmu.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,14 +751,23 @@ void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu)
751751
void kvm_riscv_gstage_mode_detect(void)
752752
{
753753
#ifdef CONFIG_64BIT
754+
/* Try Sv57x4 G-stage mode */
755+
csr_write(CSR_HGATP, HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT);
756+
if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV57X4) {
757+
gstage_mode = (HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT);
758+
gstage_pgd_levels = 5;
759+
goto skip_sv48x4_test;
760+
}
761+
754762
/* Try Sv48x4 G-stage mode */
755763
csr_write(CSR_HGATP, HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT);
756764
if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV48X4) {
757765
gstage_mode = (HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT);
758766
gstage_pgd_levels = 4;
759767
}
760-
csr_write(CSR_HGATP, 0);
768+
skip_sv48x4_test:
761769

770+
csr_write(CSR_HGATP, 0);
762771
__kvm_riscv_hfence_gvma_all();
763772
#endif
764773
}

0 commit comments

Comments
 (0)