Skip to content

Commit 7c8de08

Browse files
avpatelbonzini
authored andcommitted
RISC-V: KVM: Fix GPA passed to __kvm_riscv_hfence_gvma_xyz() functions
The parameter passed to HFENCE.GVMA instruction in rs1 register is guest physical address right shifted by 2 (i.e. divided by 4). Unfortunately, we overlooked the semantics of rs1 registers for HFENCE.GVMA instruction and never right shifted guest physical address by 2. This issue did not manifest for hypervisors till now because: 1) Currently, only __kvm_riscv_hfence_gvma_all() and SBI HFENCE calls are used to invalidate TLB. 2) All H-extension implementations (such as QEMU, Spike, Rocket Core FPGA, etc) that we tried till now were conservatively flushing everything upon any HFENCE.GVMA instruction. This patch fixes GPA passed to __kvm_riscv_hfence_gvma_vmid_gpa() and __kvm_riscv_hfence_gvma_gpa() functions. Fixes: fd7bb4a ("RISC-V: KVM: Implement VMID allocator") Reported-by: Ian Huang <[email protected]> Signed-off-by: Anup Patel <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0a86512 commit 7c8de08

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

arch/riscv/include/asm/kvm_host.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
214214

215215
#define KVM_ARCH_WANT_MMU_NOTIFIER
216216

217-
void __kvm_riscv_hfence_gvma_vmid_gpa(unsigned long gpa, unsigned long vmid);
217+
void __kvm_riscv_hfence_gvma_vmid_gpa(unsigned long gpa_divby_4,
218+
unsigned long vmid);
218219
void __kvm_riscv_hfence_gvma_vmid(unsigned long vmid);
219-
void __kvm_riscv_hfence_gvma_gpa(unsigned long gpa);
220+
void __kvm_riscv_hfence_gvma_gpa(unsigned long gpa_divby_4);
220221
void __kvm_riscv_hfence_gvma_all(void);
221222

222223
int kvm_riscv_stage2_map(struct kvm_vcpu *vcpu,

arch/riscv/kvm/tlb.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
ENTRY(__kvm_riscv_hfence_gvma_vmid_gpa)
3333
/*
34-
* rs1 = a0 (GPA)
34+
* rs1 = a0 (GPA >> 2)
3535
* rs2 = a1 (VMID)
3636
* HFENCE.GVMA a0, a1
3737
* 0110001 01011 01010 000 00000 1110011
@@ -53,7 +53,7 @@ ENDPROC(__kvm_riscv_hfence_gvma_vmid)
5353

5454
ENTRY(__kvm_riscv_hfence_gvma_gpa)
5555
/*
56-
* rs1 = a0 (GPA)
56+
* rs1 = a0 (GPA >> 2)
5757
* rs2 = zero
5858
* HFENCE.GVMA a0
5959
* 0110001 00000 01010 000 00000 1110011

0 commit comments

Comments
 (0)