linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] RISC-V: KVM: Enable ring-based dirty memory tracking
@ 2025-06-13 11:29 zhouquan
  2025-06-13 11:29 ` [PATCH 1/2] " zhouquan
  2025-06-13 11:30 ` [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases zhouquan
  0 siblings, 2 replies; 8+ messages in thread
From: zhouquan @ 2025-06-13 11:29 UTC (permalink / raw)
  To: anup, ajones, atishp, paul.walmsley, palmer
  Cc: linux-kernel, linux-riscv, kvm, kvm-riscv, Quan Zhou

From: Quan Zhou <zhouquan@iscas.ac.cn>

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

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] RISC-V: KVM: Enable ring-based dirty memory tracking
  2025-06-13 11:29 [PATCH 0/2] RISC-V: KVM: Enable ring-based dirty memory tracking zhouquan
@ 2025-06-13 11:29 ` zhouquan
  2025-07-17  6:10   ` Anup Patel
  2025-06-13 11:30 ` [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases zhouquan
  1 sibling, 1 reply; 8+ messages in thread
From: zhouquan @ 2025-06-13 11:29 UTC (permalink / raw)
  To: anup, ajones, atishp, paul.walmsley, palmer
  Cc: linux-kernel, linux-riscv, kvm, kvm-riscv, Quan Zhou

From: Quan Zhou <zhouquan@iscas.ac.cn>

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

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 1bd2d42e6424..5de0fbfe2fc0 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -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
 
diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h
index 5f59fd226cc5..ef27d4289da1 100644
--- a/arch/riscv/include/uapi/asm/kvm.h
+++ b/arch/riscv/include/uapi/asm/kvm.h
@@ -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
diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig
index 704c2899197e..5a62091b0809 100644
--- a/arch/riscv/kvm/Kconfig
+++ b/arch/riscv/kvm/Kconfig
@@ -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
diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index e0a01af426ff..0502125efb30 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases
  2025-06-13 11:29 [PATCH 0/2] RISC-V: KVM: Enable ring-based dirty memory tracking zhouquan
  2025-06-13 11:29 ` [PATCH 1/2] " zhouquan
@ 2025-06-13 11:30 ` zhouquan
  2025-06-24 14:10   ` Andrew Jones
  2025-07-17  6:12   ` Anup Patel
  1 sibling, 2 replies; 8+ messages in thread
From: zhouquan @ 2025-06-13 11:30 UTC (permalink / raw)
  To: anup, ajones, atishp, paul.walmsley, palmer
  Cc: linux-kernel, linux-riscv, kvm, kvm-riscv, Quan Zhou

From: Quan Zhou <zhouquan@iscas.ac.cn>

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

Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
---
 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(-)

diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 38b95998e1e6..565e191e99c8 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -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
diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h
index 162f303d9daa..4cf5ae11760f 100644
--- a/tools/testing/selftests/kvm/include/riscv/processor.h
+++ b/tools/testing/selftests/kvm/include/riscv/processor.h
@@ -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
diff --git a/tools/testing/selftests/rseq/rseq-riscv.h b/tools/testing/selftests/rseq/rseq-riscv.h
index 67d544aaa9a3..06c840e81c8b 100644
--- a/tools/testing/selftests/rseq/rseq-riscv.h
+++ b/tools/testing/selftests/rseq/rseq-riscv.h
@@ -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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases
  2025-06-13 11:30 ` [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases zhouquan
@ 2025-06-24 14:10   ` Andrew Jones
  2025-07-17  9:24     ` Quan Zhou
  2025-07-17  6:12   ` Anup Patel
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2025-06-24 14:10 UTC (permalink / raw)
  To: zhouquan
  Cc: anup, atishp, paul.walmsley, palmer, linux-kernel, linux-riscv,
	kvm, kvm-riscv

On Fri, Jun 13, 2025 at 07:30:13PM +0800, zhouquan@iscas.ac.cn wrote:
> From: Quan Zhou <zhouquan@iscas.ac.cn>
> 
> 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

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.

> 
> Add missing headers for tests and fix RISCV_FENCE redefinition
> in `rseq-riscv.h` by using the existing macro from <asm/fence.h>.
> 
> Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
> ---
>  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(-)
> 
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index 38b95998e1e6..565e191e99c8 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -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
> diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h
> index 162f303d9daa..4cf5ae11760f 100644
> --- a/tools/testing/selftests/kvm/include/riscv/processor.h
> +++ b/tools/testing/selftests/kvm/include/riscv/processor.h
> @@ -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.

>  
>  #define INSN_OPCODE_MASK	0x007c
>  #define INSN_OPCODE_SHIFT	2
> diff --git a/tools/testing/selftests/rseq/rseq-riscv.h b/tools/testing/selftests/rseq/rseq-riscv.h
> index 67d544aaa9a3..06c840e81c8b 100644
> --- a/tools/testing/selftests/rseq/rseq-riscv.h
> +++ b/tools/testing/selftests/rseq/rseq-riscv.h
> @@ -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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] RISC-V: KVM: Enable ring-based dirty memory tracking
  2025-06-13 11:29 ` [PATCH 1/2] " zhouquan
@ 2025-07-17  6:10   ` Anup Patel
  0 siblings, 0 replies; 8+ messages in thread
From: Anup Patel @ 2025-07-17  6:10 UTC (permalink / raw)
  To: zhouquan
  Cc: ajones, atishp, paul.walmsley, palmer, linux-kernel, linux-riscv,
	kvm, kvm-riscv

On Fri, Jun 13, 2025 at 5:08 PM <zhouquan@iscas.ac.cn> wrote:
>
> From: Quan Zhou <zhouquan@iscas.ac.cn>
>
> 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>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>

Queued this patch for Linux-6.17

Thanks,
Anup

> ---
>  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(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index 1bd2d42e6424..5de0fbfe2fc0 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -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
>
> diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h
> index 5f59fd226cc5..ef27d4289da1 100644
> --- a/arch/riscv/include/uapi/asm/kvm.h
> +++ b/arch/riscv/include/uapi/asm/kvm.h
> @@ -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
> diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig
> index 704c2899197e..5a62091b0809 100644
> --- a/arch/riscv/kvm/Kconfig
> +++ b/arch/riscv/kvm/Kconfig
> @@ -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
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index e0a01af426ff..0502125efb30 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases
  2025-06-13 11:30 ` [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases zhouquan
  2025-06-24 14:10   ` Andrew Jones
@ 2025-07-17  6:12   ` Anup Patel
  2025-07-17  9:21     ` Quan Zhou
  1 sibling, 1 reply; 8+ messages in thread
From: Anup Patel @ 2025-07-17  6:12 UTC (permalink / raw)
  To: zhouquan
  Cc: ajones, atishp, paul.walmsley, palmer, linux-kernel, linux-riscv,
	kvm, kvm-riscv

On Fri, Jun 13, 2025 at 5:08 PM <zhouquan@iscas.ac.cn> wrote:
>
> From: Quan Zhou <zhouquan@iscas.ac.cn>
>
> 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>.
>
> Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>

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

Regards,
Anup

> ---
>  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(-)
>
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index 38b95998e1e6..565e191e99c8 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -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
> diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h
> index 162f303d9daa..4cf5ae11760f 100644
> --- a/tools/testing/selftests/kvm/include/riscv/processor.h
> +++ b/tools/testing/selftests/kvm/include/riscv/processor.h
> @@ -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
> diff --git a/tools/testing/selftests/rseq/rseq-riscv.h b/tools/testing/selftests/rseq/rseq-riscv.h
> index 67d544aaa9a3..06c840e81c8b 100644
> --- a/tools/testing/selftests/rseq/rseq-riscv.h
> +++ b/tools/testing/selftests/rseq/rseq-riscv.h
> @@ -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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases
  2025-07-17  6:12   ` Anup Patel
@ 2025-07-17  9:21     ` Quan Zhou
  0 siblings, 0 replies; 8+ messages in thread
From: Quan Zhou @ 2025-07-17  9:21 UTC (permalink / raw)
  To: Anup Patel
  Cc: ajones, atishp, paul.walmsley, palmer, linux-kernel, linux-riscv,
	kvm, kvm-riscv



On 2025/7/17 14:12, Anup Patel wrote:
> On Fri, Jun 13, 2025 at 5:08 PM <zhouquan@iscas.ac.cn> wrote:
>>
>> From: Quan Zhou <zhouquan@iscas.ac.cn>
>>
>> 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>.
>>
>> Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
> 
> 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

> 
>> ---
>>   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(-)
>>
>> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
>> index 38b95998e1e6..565e191e99c8 100644
>> --- a/tools/testing/selftests/kvm/Makefile.kvm
>> +++ b/tools/testing/selftests/kvm/Makefile.kvm
>> @@ -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
>> diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h
>> index 162f303d9daa..4cf5ae11760f 100644
>> --- a/tools/testing/selftests/kvm/include/riscv/processor.h
>> +++ b/tools/testing/selftests/kvm/include/riscv/processor.h
>> @@ -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
>> diff --git a/tools/testing/selftests/rseq/rseq-riscv.h b/tools/testing/selftests/rseq/rseq-riscv.h
>> index 67d544aaa9a3..06c840e81c8b 100644
>> --- a/tools/testing/selftests/rseq/rseq-riscv.h
>> +++ b/tools/testing/selftests/rseq/rseq-riscv.h
>> @@ -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
>>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases
  2025-06-24 14:10   ` Andrew Jones
@ 2025-07-17  9:24     ` Quan Zhou
  0 siblings, 0 replies; 8+ messages in thread
From: Quan Zhou @ 2025-07-17  9:24 UTC (permalink / raw)
  To: Andrew Jones
  Cc: anup, atishp, paul.walmsley, palmer, linux-kernel, linux-riscv,
	kvm, kvm-riscv



On 2025/6/24 22:10, Andrew Jones wrote:
> On Fri, Jun 13, 2025 at 07:30:13PM +0800, zhouquan@iscas.ac.cn wrote:
>> From: Quan Zhou <zhouquan@iscas.ac.cn>
>>
>> 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
> 
> 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.
> 
>>
>> Add missing headers for tests and fix RISCV_FENCE redefinition
>> in `rseq-riscv.h` by using the existing macro from <asm/fence.h>.
>>
>> Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
>> ---
>>   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(-)
>>
>> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
>> index 38b95998e1e6..565e191e99c8 100644
>> --- a/tools/testing/selftests/kvm/Makefile.kvm
>> +++ b/tools/testing/selftests/kvm/Makefile.kvm
>> @@ -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
>> diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h
>> index 162f303d9daa..4cf5ae11760f 100644
>> --- a/tools/testing/selftests/kvm/include/riscv/processor.h
>> +++ b/tools/testing/selftests/kvm/include/riscv/processor.h
>> @@ -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.
> 
>>   
>>   #define INSN_OPCODE_MASK	0x007c
>>   #define INSN_OPCODE_SHIFT	2
>> diff --git a/tools/testing/selftests/rseq/rseq-riscv.h b/tools/testing/selftests/rseq/rseq-riscv.h
>> index 67d544aaa9a3..06c840e81c8b 100644
>> --- a/tools/testing/selftests/rseq/rseq-riscv.h
>> +++ b/tools/testing/selftests/rseq/rseq-riscv.h
>> @@ -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
> 
> 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

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

Regards,
Quan


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-17  9:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 11:29 [PATCH 0/2] RISC-V: KVM: Enable ring-based dirty memory tracking zhouquan
2025-06-13 11:29 ` [PATCH 1/2] " zhouquan
2025-07-17  6:10   ` Anup Patel
2025-06-13 11:30 ` [PATCH 2/2] KVM: riscv: selftests: Add common supported test cases zhouquan
2025-06-24 14:10   ` Andrew Jones
2025-07-17  9:24     ` Quan Zhou
2025-07-17  6:12   ` Anup Patel
2025-07-17  9:21     ` Quan Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).