Skip to content

Commit f55ffaf

Browse files
zcxGGmuavpatel
authored andcommitted
RISC-V: KVM: Enable ring-based dirty memory tracking
Enable ring-based dirty memory tracking on riscv: - Enable CONFIG_HAVE_KVM_DIRTY_RING_ACQ_REL as riscv is weakly ordered. - Set KVM_DIRTY_LOG_PAGE_OFFSET for the ring buffer's physical page offset. - Add a check to kvm_vcpu_kvm_riscv_check_vcpu_requests for checking whether the dirty ring is soft full. To handle vCPU requests that cause exits to userspace, modified the `kvm_riscv_check_vcpu_requests` to return a value (currently only returns 0 or 1). Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20e116efb1f7aff211dd8e3cf8990c5521ed5f34.1749810735.git.zhouquan@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 7826c8f commit f55ffaf

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8373,7 +8373,7 @@ core crystal clock frequency, if a non-zero CPUID 0x15 is exposed to the guest.
83738373
7.36 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL
83748374
----------------------------------------------------------
83758375

8376-
:Architectures: x86, arm64
8376+
:Architectures: x86, arm64, riscv
83778377
:Type: vm
83788378
:Parameters: args[0] - size of the dirty log ring
83798379

arch/riscv/include/uapi/asm/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define __KVM_HAVE_IRQ_LINE
1919

2020
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
21+
#define KVM_DIRTY_LOG_PAGE_OFFSET 64
2122

2223
#define KVM_INTERRUPT_SET -1U
2324
#define KVM_INTERRUPT_UNSET -2U

arch/riscv/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config KVM
2525
select HAVE_KVM_MSI
2626
select HAVE_KVM_VCPU_ASYNC_IOCTL
2727
select HAVE_KVM_READONLY_MEM
28+
select HAVE_KVM_DIRTY_RING_ACQ_REL
2829
select KVM_COMMON
2930
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
3031
select KVM_GENERIC_HARDWARE_ENABLING

arch/riscv/kvm/vcpu.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,14 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
682682
}
683683
}
684684

685-
static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
685+
/**
686+
* check_vcpu_requests - check and handle pending vCPU requests
687+
* @vcpu: the VCPU pointer
688+
*
689+
* Return: 1 if we should enter the guest
690+
* 0 if we should exit to userspace
691+
*/
692+
static int kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
686693
{
687694
struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
688695

@@ -723,7 +730,12 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
723730

724731
if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
725732
kvm_riscv_vcpu_record_steal_time(vcpu);
733+
734+
if (kvm_dirty_ring_check_request(vcpu))
735+
return 0;
726736
}
737+
738+
return 1;
727739
}
728740

729741
static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
@@ -905,7 +917,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
905917

906918
kvm_riscv_gstage_vmid_update(vcpu);
907919

908-
kvm_riscv_check_vcpu_requests(vcpu);
920+
ret = kvm_riscv_check_vcpu_requests(vcpu);
921+
if (ret <= 0)
922+
continue;
909923

910924
preempt_disable();
911925

0 commit comments

Comments
 (0)