Skip to content

Commit 9bca8be

Browse files
fangyu0809avpatel
authored andcommitted
RISC-V: KVM: Fix pte settings within kvm_riscv_gstage_ioremap()
Currently, kvm_riscv_gstage_ioremap() is used to map IMSIC gpa to the spa of IMSIC guest interrupt file. The PAGE_KERNEL_IO property includes global setting whereas it does not include user mode settings, so when accessing the IMSIC address in the virtual machine, a guest page fault will occur, this is not expected. According to the RISC-V Privileged Architecture Spec, for G-stage address translation, all memory accesses are considered to be user-level accesses as though executed in U-mode. Fixes: 659ad6d ("RISC-V: KVM: Use PAGE_KERNEL_IO in kvm_riscv_gstage_ioremap()") Signed-off-by: Fangyu Yu <[email protected]> Reviewed-by: Radim Krčmář <[email protected]> Reviewed-by: Nutty Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 1b237f1 commit 9bca8be

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/riscv/kvm/mmu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int kvm_riscv_mmu_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa,
3939
unsigned long size, bool writable, bool in_atomic)
4040
{
4141
int ret = 0;
42+
pgprot_t prot;
4243
unsigned long pfn;
4344
phys_addr_t addr, end;
4445
struct kvm_mmu_memory_cache pcache = {
@@ -55,10 +56,12 @@ int kvm_riscv_mmu_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa,
5556

5657
end = (gpa + size + PAGE_SIZE - 1) & PAGE_MASK;
5758
pfn = __phys_to_pfn(hpa);
59+
prot = pgprot_noncached(PAGE_WRITE);
5860

5961
for (addr = gpa; addr < end; addr += PAGE_SIZE) {
6062
map.addr = addr;
61-
map.pte = pfn_pte(pfn, PAGE_KERNEL_IO);
63+
map.pte = pfn_pte(pfn, prot);
64+
map.pte = pte_mkdirty(map.pte);
6265
map.level = 0;
6366

6467
if (!writable)

0 commit comments

Comments
 (0)