Skip to contentSkip to conversation

RISC-V: KVM: Enable ring-based dirty memory tracking

PATCH In review [email protected] 3 participants 8 messages Jun 13, 2025 – Jul 17, 2025

Subsystems (6)
Documentation KVM Kselftest RISC-V +2 more subsystems
lore
Share & tools
lore
#0 lore raw

cover RISC-V: KVM: Enable ring-based dirty memory tracking

From: Quan Zhou <[email protected]>

Enable ring-based dirty memory tracking and add some common KVM tests for riscv.

Quan Zhou (2):
RISC-V: KVM: Enable ring-based dirty memory tracking
KVM: riscv: selftests: Add common supported test cases

 Documentation/virt/kvm/api.rst                 |  2 +-
 arch/riscv/include/uapi/asm/kvm.h              |  1 +
 arch/riscv/kvm/Kconfig                         |  1 +
 arch/riscv/kvm/vcpu.c                          | 18 ++++++++++++++++--
 tools/testing/selftests/kvm/Makefile.kvm       | 12 ++++++++++++
 .../selftests/kvm/include/riscv/processor.h    |  2 ++
 tools/testing/selftests/rseq/rseq-riscv.h      |  3 +--
 7 files changed, 34 insertions(+), 5 deletions(-)
Signature · 7 lines
2.34.1


-- 
kvm-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kvm-riscv
#1 lore raw

PATCH 1/2 RISC-V: KVM: Enable ring-based dirty memory tracking

From: Quan Zhou <[email protected]>

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).

---
 Documentation/virt/kvm/api.rst    |  2 +-
 arch/riscv/include/uapi/asm/kvm.h |  1 +
 arch/riscv/kvm/Kconfig            |  1 +
 arch/riscv/kvm/vcpu.c             | 18 ++++++++++++++++--
 4 files changed, 19 insertions(+), 3 deletions(-)
Documentation/virt/kvm/api.rst +1 -1
index 1bd2d42e6424..5de0fbfe2fc0 100644
@@ -8316,7 +8316,7 @@ core crystal clock frequency, if a non-zero CPUID 0x15 is exposed to the guest.
 7.36 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL
 ----------------------------------------------------------
 
-:Architectures: x86, arm64
+:Architectures: x86, arm64, riscv
 :Type: vm
 :Parameters: args[0] - size of the dirty log ring
 
arch/riscv/include/uapi/asm/kvm.h +1 -0
index 5f59fd226cc5..ef27d4289da1 100644
@@ -18,6 +18,7 @@
 #define __KVM_HAVE_IRQ_LINE
 
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
+#define KVM_DIRTY_LOG_PAGE_OFFSET 64
 
 #define KVM_INTERRUPT_SET	-1U
 #define KVM_INTERRUPT_UNSET	-2U
arch/riscv/kvm/Kconfig +1 -0
index 704c2899197e..5a62091b0809 100644
@@ -25,6 +25,7 @@ config KVM
 	select HAVE_KVM_MSI
 	select HAVE_KVM_VCPU_ASYNC_IOCTL
 	select HAVE_KVM_READONLY_MEM
+	select HAVE_KVM_DIRTY_RING_ACQ_REL
 	select KVM_COMMON
 	select KVM_GENERIC_DIRTYLOG_READ_PROTECT
 	select KVM_GENERIC_HARDWARE_ENABLING
arch/riscv/kvm/vcpu.c +16 -2
index e0a01af426ff..0502125efb30 100644
@@ -690,7 +690,14 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 	}
 }
 
-static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
+/**
+ * check_vcpu_requests - check and handle pending vCPU requests
+ * @vcpu:	the VCPU pointer
+ *
+ * Return: 1 if we should enter the guest
+ *	    0 if we should exit to userspace
+ */
+static int kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
 {
 	struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
 
@@ -735,7 +742,12 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
 
 		if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
 			kvm_riscv_vcpu_record_steal_time(vcpu);
+
+		if (kvm_dirty_ring_check_request(vcpu))
+			return 0;
 	}
+
+	return 1;
 }
 
 static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
@@ -917,7 +929,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 		kvm_riscv_gstage_vmid_update(vcpu);
 
-		kvm_riscv_check_vcpu_requests(vcpu);
+		ret = kvm_riscv_check_vcpu_requests(vcpu);
+		if (ret <= 0)
+			continue;
 
 		preempt_disable();
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/2
#2 lore raw
Quoted 12 lines · On Fri, Jun 13, 2025 at 5:08 PM <[email protected]> wrote:

From: Quan Zhou <[email protected]>

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.

Quoted 5 lines

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).

LGTM.

Queued this patch for Linux-6.17

Thanks,
Anup

Quoted 91 lines
---
 Documentation/virt/kvm/api.rst    |  2 +-
 arch/riscv/include/uapi/asm/kvm.h |  1 +
 arch/riscv/kvm/Kconfig            |  1 +
 arch/riscv/kvm/vcpu.c             | 18 ++++++++++++++++--
 4 files changed, 19 insertions(+), 3 deletions(-)
Documentation/virt/kvm/api.rst +1 -1
index 1bd2d42e6424..5de0fbfe2fc0 100644
@@ -8316,7 +8316,7 @@ core crystal clock frequency, if a non-zero CPUID 0x15 is exposed to the guest.
 7.36 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL
 ----------------------------------------------------------
 
-:Architectures: x86, arm64
+:Architectures: x86, arm64, riscv
 :Type: vm
 :Parameters: args[0] - size of the dirty log ring
 
arch/riscv/include/uapi/asm/kvm.h +1 -0
index 5f59fd226cc5..ef27d4289da1 100644
@@ -18,6 +18,7 @@
 #define __KVM_HAVE_IRQ_LINE
 
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
+#define KVM_DIRTY_LOG_PAGE_OFFSET 64
 
 #define KVM_INTERRUPT_SET      -1U
 #define KVM_INTERRUPT_UNSET    -2U
arch/riscv/kvm/Kconfig +1 -0
index 704c2899197e..5a62091b0809 100644
@@ -25,6 +25,7 @@ config KVM
        select HAVE_KVM_MSI
        select HAVE_KVM_VCPU_ASYNC_IOCTL
        select HAVE_KVM_READONLY_MEM
+       select HAVE_KVM_DIRTY_RING_ACQ_REL
        select KVM_COMMON
        select KVM_GENERIC_DIRTYLOG_READ_PROTECT
        select KVM_GENERIC_HARDWARE_ENABLING
arch/riscv/kvm/vcpu.c +16 -3
index e0a01af426ff..0502125efb30 100644
@@ -690,7 +690,14 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
        }
 }
 
-static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
+/**
+ * check_vcpu_requests - check and handle pending vCPU requests
+ * @vcpu:      the VCPU pointer
+ *
+ * Return: 1 if we should enter the guest
+ *         0 if we should exit to userspace
+ */
+static int kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
 {
        struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
 
@@ -735,7 +742,12 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
 
                if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
                        kvm_riscv_vcpu_record_steal_time(vcpu);
+
+               if (kvm_dirty_ring_check_request(vcpu))
+                       return 0;
        }
+
+       return 1;
 }
 
 static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
@@ -917,7 +929,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
                kvm_riscv_gstage_vmid_update(vcpu);
 
-               kvm_riscv_check_vcpu_requests(vcpu);
+               ret = kvm_riscv_check_vcpu_requests(vcpu);
+               if (ret <= 0)
+                       continue;
 
                preempt_disable();
 
--

2.34.1

#3 lore raw

PATCH 2/2 KVM: riscv: selftests: Add common supported test cases

In reply to [email protected]

From: Quan Zhou <[email protected]>

Some common KVM test cases are supported on riscv now as following:

access_tracking_perf_test
demand_paging_test
dirty_log_perf_test
dirty_log_test
guest_print_test
kvm_binary_stats_test
kvm_create_max_vcpus
kvm_page_table_test
memslot_modification_stress_test
memslot_perf_test
rseq_test
set_memory_region_test

Add missing headers for tests and fix RISCV_FENCE redefinition in rseq-riscv.h by using the existing macro from <asm/fence.h>.

---
 tools/testing/selftests/kvm/Makefile.kvm             | 12 ++++++++++++
 .../testing/selftests/kvm/include/riscv/processor.h  |  2 ++
 tools/testing/selftests/rseq/rseq-riscv.h            |  3 +--
 3 files changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +12 -0
index 38b95998e1e6..565e191e99c8 100644
@@ -197,6 +197,18 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += get-reg-list
 TEST_GEN_PROGS_riscv += steal_time
+TEST_GEN_PROGS_riscv += access_tracking_perf_test
+TEST_GEN_PROGS_riscv += demand_paging_test
+TEST_GEN_PROGS_riscv += dirty_log_perf_test
+TEST_GEN_PROGS_riscv += dirty_log_test
+TEST_GEN_PROGS_riscv += guest_print_test
+TEST_GEN_PROGS_riscv += kvm_binary_stats_test
+TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
+TEST_GEN_PROGS_riscv += kvm_page_table_test
+TEST_GEN_PROGS_riscv += memslot_modification_stress_test
+TEST_GEN_PROGS_riscv += memslot_perf_test
+TEST_GEN_PROGS_riscv += rseq_test
+TEST_GEN_PROGS_riscv += set_memory_region_test
 
 TEST_GEN_PROGS_loongarch += coalesced_io_test
 TEST_GEN_PROGS_loongarch += demand_paging_test
tools/testing/selftests/kvm/include/riscv/processor.h +2 -0
index 162f303d9daa..4cf5ae11760f 100644
@@ -9,7 +9,9 @@
 
 #include <linux/stringify.h>
 #include <asm/csr.h>
+#include <asm/vdso/processor.h>
 #include "kvm_util.h"
+#include "ucall_common.h"
 
 #define INSN_OPCODE_MASK	0x007c
 #define INSN_OPCODE_SHIFT	2
tools/testing/selftests/rseq/rseq-riscv.h +1 -2
index 67d544aaa9a3..06c840e81c8b 100644
@@ -8,6 +8,7 @@
  * exception when executed in all modes.
  */
 #include <endian.h>
+#include <asm/fence.h>
 
 #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
 #define RSEQ_SIG   0xf1401073  /* csrr mhartid, x0 */
@@ -24,8 +25,6 @@
 #define REG_L	__REG_SEL("ld ", "lw ")
 #define REG_S	__REG_SEL("sd ", "sw ")
 
-#define RISCV_FENCE(p, s) \
-	__asm__ __volatile__ ("fence " #p "," #s : : : "memory")
 #define rseq_smp_mb()	RISCV_FENCE(rw, rw)
 #define rseq_smp_rmb()	RISCV_FENCE(r, r)
 #define rseq_smp_wmb()	RISCV_FENCE(w, w)
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases

Quoted 4 lines · On Fri, Jun 13, 2025 at 07:30:13PM +0800, [email protected] wrote:

From: Quan Zhou <[email protected]>

Some common KVM test cases are supported on riscv now as following:

Quoted 12 lines

access_tracking_perf_test
demand_paging_test
dirty_log_perf_test
dirty_log_test
guest_print_test
kvm_binary_stats_test
kvm_create_max_vcpus
kvm_page_table_test
memslot_modification_stress_test
memslot_perf_test
rseq_test
set_memory_region_test

Half this list is already build for riscv since they're common. See TEST_GEN_PROGS_COMMON. If the other half can be built and run then please send a separate patch, not something tacked onto this series, since they're all unrelated to the series.

Quoted 39 lines

Add missing headers for tests and fix RISCV_FENCE redefinition in rseq-riscv.h by using the existing macro from <asm/fence.h>.

---
 tools/testing/selftests/kvm/Makefile.kvm             | 12 ++++++++++++
 .../testing/selftests/kvm/include/riscv/processor.h  |  2 ++
 tools/testing/selftests/rseq/rseq-riscv.h            |  3 +--
 3 files changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +12 -0
index 38b95998e1e6..565e191e99c8 100644
@@ -197,6 +197,18 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += get-reg-list
 TEST_GEN_PROGS_riscv += steal_time
+TEST_GEN_PROGS_riscv += access_tracking_perf_test
+TEST_GEN_PROGS_riscv += demand_paging_test
+TEST_GEN_PROGS_riscv += dirty_log_perf_test
+TEST_GEN_PROGS_riscv += dirty_log_test
+TEST_GEN_PROGS_riscv += guest_print_test
+TEST_GEN_PROGS_riscv += kvm_binary_stats_test
+TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
+TEST_GEN_PROGS_riscv += kvm_page_table_test
+TEST_GEN_PROGS_riscv += memslot_modification_stress_test
+TEST_GEN_PROGS_riscv += memslot_perf_test
+TEST_GEN_PROGS_riscv += rseq_test
+TEST_GEN_PROGS_riscv += set_memory_region_test
 
 TEST_GEN_PROGS_loongarch += coalesced_io_test
 TEST_GEN_PROGS_loongarch += demand_paging_test
tools/testing/selftests/kvm/include/riscv/processor.h +0 -0
index 162f303d9daa..4cf5ae11760f 100644

tools/testing/selftests/kvm/include/riscv/processor.h line 14

Quoted 6 lines
tools/testing/selftests/kvm/include/riscv/processor.h +2 -0
@@ -9,7 +9,9 @@
 
 #include <linux/stringify.h>
 #include <asm/csr.h>
+#include <asm/vdso/processor.h>
 #include "kvm_util.h"
+#include "ucall_common.h"

These should be included directly from the tests that need them.

Quoted 26 lines
tools/testing/selftests/kvm/include/riscv/processor.h +0 -0
 #define INSN_OPCODE_MASK	0x007c
 #define INSN_OPCODE_SHIFT	2
tools/testing/selftests/rseq/rseq-riscv.h +1 -2
index 67d544aaa9a3..06c840e81c8b 100644
@@ -8,6 +8,7 @@
  * exception when executed in all modes.
  */
 #include <endian.h>
+#include <asm/fence.h>
 
 #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
 #define RSEQ_SIG   0xf1401073  /* csrr mhartid, x0 */
@@ -24,8 +25,6 @@
 #define REG_L	__REG_SEL("ld ", "lw ")
 #define REG_S	__REG_SEL("sd ", "sw ")
 
-#define RISCV_FENCE(p, s) \
-	__asm__ __volatile__ ("fence " #p "," #s : : : "memory")
 #define rseq_smp_mb()	RISCV_FENCE(rw, rw)
 #define rseq_smp_rmb()	RISCV_FENCE(r, r)
 #define rseq_smp_wmb()	RISCV_FENCE(w, w)
Signature · 1 line
2.34.1

tools/testing/selftests/rseq isn't under KVM's purview, so this should be a separate patch CC'ing the appropriate people and lists.

Thanks,
drew

author
#5 lore raw

Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases

Quoted 101 lines · Andrew Jones
Quoted 4 lines · On Fri, Jun 13, 2025 at 07:30:13PM +0800, [email protected] wrote:

From: Quan Zhou <[email protected]>

Some common KVM test cases are supported on riscv now as following:

Quoted 12 lines

access_tracking_perf_test
demand_paging_test
dirty_log_perf_test
dirty_log_test
guest_print_test
kvm_binary_stats_test
kvm_create_max_vcpus
kvm_page_table_test
memslot_modification_stress_test
memslot_perf_test
rseq_test
set_memory_region_test

Half this list is already build for riscv since they're common. See TEST_GEN_PROGS_COMMON. If the other half can be built and run then please send a separate patch, not something tacked onto this series, since they're all unrelated to the series.

Quoted 39 lines

Add missing headers for tests and fix RISCV_FENCE redefinition in rseq-riscv.h by using the existing macro from <asm/fence.h>.

---
  tools/testing/selftests/kvm/Makefile.kvm             | 12 ++++++++++++
  .../testing/selftests/kvm/include/riscv/processor.h  |  2 ++
  tools/testing/selftests/rseq/rseq-riscv.h            |  3 +--
  3 files changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +12 -0
index 38b95998e1e6..565e191e99c8 100644
@@ -197,6 +197,18 @@ TEST_GEN_PROGS_riscv += arch_timer
  TEST_GEN_PROGS_riscv += coalesced_io_test
  TEST_GEN_PROGS_riscv += get-reg-list
  TEST_GEN_PROGS_riscv += steal_time
+TEST_GEN_PROGS_riscv += access_tracking_perf_test
+TEST_GEN_PROGS_riscv += demand_paging_test
+TEST_GEN_PROGS_riscv += dirty_log_perf_test
+TEST_GEN_PROGS_riscv += dirty_log_test
+TEST_GEN_PROGS_riscv += guest_print_test
+TEST_GEN_PROGS_riscv += kvm_binary_stats_test
+TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
+TEST_GEN_PROGS_riscv += kvm_page_table_test
+TEST_GEN_PROGS_riscv += memslot_modification_stress_test
+TEST_GEN_PROGS_riscv += memslot_perf_test
+TEST_GEN_PROGS_riscv += rseq_test
+TEST_GEN_PROGS_riscv += set_memory_region_test
 
  TEST_GEN_PROGS_loongarch += coalesced_io_test
  TEST_GEN_PROGS_loongarch += demand_paging_test
tools/testing/selftests/kvm/include/riscv/processor.h +0 -0
index 162f303d9daa..4cf5ae11760f 100644

tools/testing/selftests/kvm/include/riscv/processor.h line 14

Quoted 6 lines
tools/testing/selftests/kvm/include/riscv/processor.h +2 -0
@@ -9,7 +9,9 @@
 
  #include <linux/stringify.h>
  #include <asm/csr.h>
+#include <asm/vdso/processor.h>
  #include "kvm_util.h"
+#include "ucall_common.h"

These should be included directly from the tests that need them.

Quoted 26 lines
tools/testing/selftests/kvm/include/riscv/processor.h +0 -0
  #define INSN_OPCODE_MASK	0x007c
  #define INSN_OPCODE_SHIFT	2
tools/testing/selftests/rseq/rseq-riscv.h +1 -2
index 67d544aaa9a3..06c840e81c8b 100644
@@ -8,6 +8,7 @@
   * exception when executed in all modes.
   */
  #include <endian.h>
+#include <asm/fence.h>
 
  #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
  #define RSEQ_SIG   0xf1401073  /* csrr mhartid, x0 */
@@ -24,8 +25,6 @@
  #define REG_L	__REG_SEL("ld ", "lw ")
  #define REG_S	__REG_SEL("sd ", "sw ")
 
-#define RISCV_FENCE(p, s) \
-	__asm__ __volatile__ ("fence " #p "," #s : : : "memory")
  #define rseq_smp_mb()	RISCV_FENCE(rw, rw)
  #define rseq_smp_rmb()	RISCV_FENCE(r, r)
  #define rseq_smp_wmb()	RISCV_FENCE(w, w)
Signature · 1 line
2.34.1

tools/testing/selftests/rseq isn't under KVM's purview, so this should be a separate patch CC'ing the appropriate people and lists.

Quoted 2 lines

Thanks,
drew

Thanks so much for your review, I'll split and modify this set of patches.

Regards,
Quan

maintainer
#6 lore raw

Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases

In reply to [email protected]
Quoted 18 lines · On Fri, Jun 13, 2025 at 5:08 PM <[email protected]> wrote:

From: Quan Zhou <[email protected]>

Some common KVM test cases are supported on riscv now as following:

access_tracking_perf_test
demand_paging_test
dirty_log_perf_test
dirty_log_test
guest_print_test
kvm_binary_stats_test
kvm_create_max_vcpus
kvm_page_table_test
memslot_modification_stress_test
memslot_perf_test
rseq_test
set_memory_region_test

Quoted 4 lines

Add missing headers for tests and fix RISCV_FENCE redefinition in rseq-riscv.h by using the existing macro from <asm/fence.h>.

Please address Drew's comments and send v2 of only this patch. The first patch of this series is already queued.

Regards,
Anup

Quoted 67 lines
---
 tools/testing/selftests/kvm/Makefile.kvm             | 12 ++++++++++++
 .../testing/selftests/kvm/include/riscv/processor.h  |  2 ++
 tools/testing/selftests/rseq/rseq-riscv.h            |  3 +--
 3 files changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +12 -0
index 38b95998e1e6..565e191e99c8 100644
@@ -197,6 +197,18 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += get-reg-list
 TEST_GEN_PROGS_riscv += steal_time
+TEST_GEN_PROGS_riscv += access_tracking_perf_test
+TEST_GEN_PROGS_riscv += demand_paging_test
+TEST_GEN_PROGS_riscv += dirty_log_perf_test
+TEST_GEN_PROGS_riscv += dirty_log_test
+TEST_GEN_PROGS_riscv += guest_print_test
+TEST_GEN_PROGS_riscv += kvm_binary_stats_test
+TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
+TEST_GEN_PROGS_riscv += kvm_page_table_test
+TEST_GEN_PROGS_riscv += memslot_modification_stress_test
+TEST_GEN_PROGS_riscv += memslot_perf_test
+TEST_GEN_PROGS_riscv += rseq_test
+TEST_GEN_PROGS_riscv += set_memory_region_test
 
 TEST_GEN_PROGS_loongarch += coalesced_io_test
 TEST_GEN_PROGS_loongarch += demand_paging_test
tools/testing/selftests/kvm/include/riscv/processor.h +2 -0
index 162f303d9daa..4cf5ae11760f 100644
@@ -9,7 +9,9 @@
 
 #include <linux/stringify.h>
 #include <asm/csr.h>
+#include <asm/vdso/processor.h>
 #include "kvm_util.h"
+#include "ucall_common.h"
 
 #define INSN_OPCODE_MASK       0x007c
 #define INSN_OPCODE_SHIFT      2
tools/testing/selftests/rseq/rseq-riscv.h +1 -3
index 67d544aaa9a3..06c840e81c8b 100644
@@ -8,6 +8,7 @@
  * exception when executed in all modes.
  */
 #include <endian.h>
+#include <asm/fence.h>
 
 #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
 #define RSEQ_SIG   0xf1401073  /* csrr mhartid, x0 */
@@ -24,8 +25,6 @@
 #define REG_L  __REG_SEL("ld ", "lw ")
 #define REG_S  __REG_SEL("sd ", "sw ")
 
-#define RISCV_FENCE(p, s) \
-       __asm__ __volatile__ ("fence " #p "," #s : : : "memory")
 #define rseq_smp_mb()  RISCV_FENCE(rw, rw)
 #define rseq_smp_rmb() RISCV_FENCE(r, r)
 #define rseq_smp_wmb() RISCV_FENCE(w, w)
--

2.34.1

author
#7 lore raw

Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases

Quoted 22 lines · Anup Patel
Quoted 21 lines · On Fri, Jun 13, 2025 at 5:08 PM <[email protected]> wrote:

From: Quan Zhou <[email protected]>

Some common KVM test cases are supported on riscv now as following:

access_tracking_perf_test
demand_paging_test
dirty_log_perf_test
dirty_log_test
guest_print_test
kvm_binary_stats_test
kvm_create_max_vcpus
kvm_page_table_test
memslot_modification_stress_test
memslot_perf_test
rseq_test
set_memory_region_test

Add missing headers for tests and fix RISCV_FENCE redefinition in rseq-riscv.h by using the existing macro from <asm/fence.h>.

Quoted 7 lines
Quoted 1 line

Please address Drew's comments and send v2 of only this patch. The first patch of this series is already queued.

Regards,
Anup

Okay, I'll split and modify this set of patches. Thanks.

Regards,
Quan

Quoted 68 lines
Quoted 68 lines
---
  tools/testing/selftests/kvm/Makefile.kvm             | 12 ++++++++++++
  .../testing/selftests/kvm/include/riscv/processor.h  |  2 ++
  tools/testing/selftests/rseq/rseq-riscv.h            |  3 +--
  3 files changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +12 -0
index 38b95998e1e6..565e191e99c8 100644
@@ -197,6 +197,18 @@ TEST_GEN_PROGS_riscv += arch_timer
  TEST_GEN_PROGS_riscv += coalesced_io_test
  TEST_GEN_PROGS_riscv += get-reg-list
  TEST_GEN_PROGS_riscv += steal_time
+TEST_GEN_PROGS_riscv += access_tracking_perf_test
+TEST_GEN_PROGS_riscv += demand_paging_test
+TEST_GEN_PROGS_riscv += dirty_log_perf_test
+TEST_GEN_PROGS_riscv += dirty_log_test
+TEST_GEN_PROGS_riscv += guest_print_test
+TEST_GEN_PROGS_riscv += kvm_binary_stats_test
+TEST_GEN_PROGS_riscv += kvm_create_max_vcpus
+TEST_GEN_PROGS_riscv += kvm_page_table_test
+TEST_GEN_PROGS_riscv += memslot_modification_stress_test
+TEST_GEN_PROGS_riscv += memslot_perf_test
+TEST_GEN_PROGS_riscv += rseq_test
+TEST_GEN_PROGS_riscv += set_memory_region_test
 
  TEST_GEN_PROGS_loongarch += coalesced_io_test
  TEST_GEN_PROGS_loongarch += demand_paging_test
tools/testing/selftests/kvm/include/riscv/processor.h +2 -0
index 162f303d9daa..4cf5ae11760f 100644
@@ -9,7 +9,9 @@
 
  #include <linux/stringify.h>
  #include <asm/csr.h>
+#include <asm/vdso/processor.h>
  #include "kvm_util.h"
+#include "ucall_common.h"
 
  #define INSN_OPCODE_MASK       0x007c
  #define INSN_OPCODE_SHIFT      2
tools/testing/selftests/rseq/rseq-riscv.h +1 -3
index 67d544aaa9a3..06c840e81c8b 100644
@@ -8,6 +8,7 @@
   * exception when executed in all modes.
   */
  #include <endian.h>
+#include <asm/fence.h>
 
  #if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __LITTLE_ENDIAN) : defined(__LITTLE_ENDIAN)
  #define RSEQ_SIG   0xf1401073  /* csrr mhartid, x0 */
@@ -24,8 +25,6 @@
  #define REG_L  __REG_SEL("ld ", "lw ")
  #define REG_S  __REG_SEL("sd ", "sw ")
 
-#define RISCV_FENCE(p, s) \
-       __asm__ __volatile__ ("fence " #p "," #s : : : "memory")
  #define rseq_smp_mb()  RISCV_FENCE(rw, rw)
  #define rseq_smp_rmb() RISCV_FENCE(r, r)
  #define rseq_smp_wmb() RISCV_FENCE(w, w)
--

2.34.1