Skip to contentSkip to conversation

riscv: kvm: use generic entry for TIF_NOTIFY_RESUME and misc

PATCH In review Jisheng Zhang 4 participants 8 messages Sep 25, 2022 – Oct 1, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover riscv: kvm: use generic entry for TIF_NOTIFY_RESUME and misc

This series is a preparation series to add PREEMPT_RT support to riscv:
patch1 adds the missing number of signal exits in vCPU stat patch2 switches to the generic guest entry infrastructure patch3 select HAVE_POSIX_CPU_TIMERS_TASK_WORK which is a requirement for RT

After these three patches merged, the left RT patches are similar as other arch.

Since v2:
- splict the series into two separate ones, one for next another for

    RT.

Since v1:
- send to related maillist, I press ENTER too quickly when sending v1
- remove the signal_pending() handling because that's covered by generic guest entry infrastructure

Jisheng Zhang (3):
RISC-V: KVM: Record number of signal exits as a vCPU stat
RISC-V: KVM: Use generic guest entry infrastructure
riscv: select HAVE_POSIX_CPU_TIMERS_TASK_WORK

 arch/riscv/Kconfig                |  1 +
 arch/riscv/include/asm/kvm_host.h |  1 +
 arch/riscv/kvm/Kconfig            |  1 +
 arch/riscv/kvm/vcpu.c             | 18 +++++++-----------
 4 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 RISC-V: KVM: Record number of signal exits as a vCPU stat

Record a statistic indicating the number of times a vCPU has exited due to a pending signal.

---
 arch/riscv/include/asm/kvm_host.h | 1 +
 arch/riscv/kvm/vcpu.c             | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/include/asm/kvm_host.h +1 -0
index 60c517e4d576..dbbf43d52623 100644
@@ -67,6 +67,7 @@ struct kvm_vcpu_stat {
 	u64 mmio_exit_kernel;
 	u64 csr_exit_user;
 	u64 csr_exit_kernel;
+	u64 signal_exits;
 	u64 exits;
 };
 
arch/riscv/kvm/vcpu.c +2 -0
index d0f08d5b4282..3da459fedc28 100644
@@ -28,6 +28,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
 	STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
 	STATS_DESC_COUNTER(VCPU, csr_exit_user),
 	STATS_DESC_COUNTER(VCPU, csr_exit_kernel),
+	STATS_DESC_COUNTER(VCPU, signal_exits),
 	STATS_DESC_COUNTER(VCPU, exits)
 };
 
@@ -973,6 +974,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		if (signal_pending(current)) {
 			ret = -EINTR;
 			run->exit_reason = KVM_EXIT_INTR;
+			++vcpu->stat.signal_exits;
 		}
 
 		/*
Signature · 1 line
2.34.1
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] RISC-V: KVM: Record number of signal exits as a vCPU stat

? linux git:(master) grep signal_exits arch/arm64 -r arch/arm64/kvm/guest.c: STATS_DESC_COUNTER(VCPU, signal_exits),
arch/arm64/include/asm/kvm_host.h: u64 signal_exits;

By the way, do you know why arm64 is defined, but not used?

Quoted 43 lines · Jisheng Zhang

Record a statistic indicating the number of times a vCPU has exited due to a pending signal.

---
 arch/riscv/include/asm/kvm_host.h | 1 +
 arch/riscv/kvm/vcpu.c             | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/include/asm/kvm_host.h +1 -0
index 60c517e4d576..dbbf43d52623 100644
@@ -67,6 +67,7 @@ struct kvm_vcpu_stat {
        u64 mmio_exit_kernel;
        u64 csr_exit_user;
        u64 csr_exit_kernel;
+       u64 signal_exits;
        u64 exits;
 };
 
arch/riscv/kvm/vcpu.c +2 -1
index d0f08d5b4282..3da459fedc28 100644
@@ -28,6 +28,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
        STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
        STATS_DESC_COUNTER(VCPU, csr_exit_user),
        STATS_DESC_COUNTER(VCPU, csr_exit_kernel),
+       STATS_DESC_COUNTER(VCPU, signal_exits),
        STATS_DESC_COUNTER(VCPU, exits)
 };
 
@@ -973,6 +974,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
                if (signal_pending(current)) {
                        ret = -EINTR;
                        run->exit_reason = KVM_EXIT_INTR;
+                       ++vcpu->stat.signal_exits;
                }
 
                /*
--
Quoted 2 lines

2.34.1

--
Best Regards
Guo Ren

#3 lore raw

Re: [PATCH v3 1/3] RISC-V: KVM: Record number of signal exits as a vCPU stat

Quoted 7 lines · Guo Ren

? linux git:(master) grep signal_exits arch/arm64 -r arch/arm64/kvm/guest.c: STATS_DESC_COUNTER(VCPU, signal_exits),
arch/arm64/include/asm/kvm_host.h: u64 signal_exits;

By the way, do you know why arm64 is defined, but not used?

It is. arm64 uses generic xfer to guest mode work, like this series introduces for riscv.

Thanks,
drew

Quoted 58 lines · Jisheng Zhang
Quoted 43 lines

Record a statistic indicating the number of times a vCPU has exited due to a pending signal.

---
 arch/riscv/include/asm/kvm_host.h | 1 +
 arch/riscv/kvm/vcpu.c             | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/include/asm/kvm_host.h +1 -0
index 60c517e4d576..dbbf43d52623 100644
@@ -67,6 +67,7 @@ struct kvm_vcpu_stat {
        u64 mmio_exit_kernel;
        u64 csr_exit_user;
        u64 csr_exit_kernel;
+       u64 signal_exits;
        u64 exits;
 };
 
arch/riscv/kvm/vcpu.c +2 -1
index d0f08d5b4282..3da459fedc28 100644
@@ -28,6 +28,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
        STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
        STATS_DESC_COUNTER(VCPU, csr_exit_user),
        STATS_DESC_COUNTER(VCPU, csr_exit_kernel),
+       STATS_DESC_COUNTER(VCPU, signal_exits),
        STATS_DESC_COUNTER(VCPU, exits)
 };
 
@@ -973,6 +974,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
                if (signal_pending(current)) {
                        ret = -EINTR;
                        run->exit_reason = KVM_EXIT_INTR;
+                       ++vcpu->stat.signal_exits;
                }
 
                /*
--
Quoted 2 lines

2.34.1

--
Best Regards
Guo Ren

Signature · 3 lines
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
#4 lore raw

PATCH v3 2/3 RISC-V: KVM: Use generic guest entry infrastructure

In reply to Jisheng Zhang

Use generic guest entry infrastructure to properly handle TIF_NOTIFY_RESUME.

---
 arch/riscv/kvm/Kconfig |  1 +
 arch/riscv/kvm/vcpu.c  | 18 ++++++------------
 2 files changed, 7 insertions(+), 12 deletions(-)
arch/riscv/kvm/Kconfig +1 -0
index f5a342fa1b1d..f36a737d5f96 100644
@@ -24,6 +24,7 @@ config KVM
 	select PREEMPT_NOTIFIERS
 	select KVM_MMIO
 	select KVM_GENERIC_DIRTYLOG_READ_PROTECT
+	select KVM_XFER_TO_GUEST_WORK
 	select HAVE_KVM_VCPU_ASYNC_IOCTL
 	select HAVE_KVM_EVENTFD
 	select SRCU
arch/riscv/kvm/vcpu.c +6 -12
index 3da459fedc28..e3e6b8608288 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/entry-kvm.h>
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/kdebug.h>
@@ -959,7 +960,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	run->exit_reason = KVM_EXIT_UNKNOWN;
 	while (ret > 0) {
 		/* Check conditions before entering the guest */
-		cond_resched();
+		ret = xfer_to_guest_mode_handle_work(vcpu);
+		if (!ret)
+			ret = 1;
 
 		kvm_riscv_gstage_vmid_update(vcpu);
 
@@ -967,16 +970,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 		local_irq_disable();
 
-		/*
-		 * Exit if we have a signal pending so that we can deliver
-		 * the signal to user space.
-		 */
-		if (signal_pending(current)) {
-			ret = -EINTR;
-			run->exit_reason = KVM_EXIT_INTR;
-			++vcpu->stat.signal_exits;
-		}
-
 		/*
 		 * Ensure we set mode to IN_GUEST_MODE after we disable
 		 * interrupts and before the final VCPU requests check.
@@ -999,7 +992,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 
 		if (ret <= 0 ||
 		    kvm_riscv_gstage_vmid_ver_changed(&vcpu->kvm->arch.vmid) ||
-		    kvm_request_pending(vcpu)) {
+		    kvm_request_pending(vcpu) ||
+		    xfer_to_guest_mode_work_pending()) {
 			vcpu->mode = OUTSIDE_GUEST_MODE;
 			local_irq_enable();
 			kvm_vcpu_srcu_read_lock(vcpu);
Signature · 1 line
2.34.1
#5 lore raw

PATCH v3 3/3 riscv: select HAVE_POSIX_CPU_TIMERS_TASK_WORK

In reply to Jisheng Zhang

Move POSIX CPU timer expiry and signal delivery into task context to allow PREEMPT_RT setups to coexist with KVM.

---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index 79e52441e18b..7a8134fd7ec9 100644
@@ -104,6 +104,7 @@ config RISCV
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
+	select HAVE_POSIX_CPU_TIMERS_TASK_WORK
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select HAVE_STACKPROTECTOR
Signature · 1 line
2.34.1
Reviewed-by on the v3 series
#6 lore raw
In reply to Jisheng Zhang
Quoted 23 lines · Jisheng Zhang

This series is a preparation series to add PREEMPT_RT support to riscv:
patch1 adds the missing number of signal exits in vCPU stat patch2 switches to the generic guest entry infrastructure patch3 select HAVE_POSIX_CPU_TIMERS_TASK_WORK which is a requirement for RT

After these three patches merged, the left RT patches are similar as other arch.

Since v2:
- splict the series into two separate ones, one for next another for

    RT.

Since v1:
- send to related maillist, I press ENTER too quickly when sending v1
- remove the signal_pending() handling because that's covered by generic guest entry infrastructure

Jisheng Zhang (3):
RISC-V: KVM: Record number of signal exits as a vCPU stat
RISC-V: KVM: Use generic guest entry infrastructure
riscv: select HAVE_POSIX_CPU_TIMERS_TASK_WORK

Quoted 9 lines
 arch/riscv/Kconfig                |  1 +
 arch/riscv/include/asm/kvm_host.h |  1 +
 arch/riscv/kvm/Kconfig            |  1 +
 arch/riscv/kvm/vcpu.c             | 18 +++++++-----------
 4 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1

For the series

maintainer
#7 lore raw
In reply to Jisheng Zhang
Quoted 19 lines · Jisheng Zhang

This series is a preparation series to add PREEMPT_RT support to riscv:
patch1 adds the missing number of signal exits in vCPU stat patch2 switches to the generic guest entry infrastructure patch3 select HAVE_POSIX_CPU_TIMERS_TASK_WORK which is a requirement for RT

After these three patches merged, the left RT patches are similar as other arch.

Since v2:
- splict the series into two separate ones, one for next another for

    RT.

Since v1:
- send to related maillist, I press ENTER too quickly when sending v1
- remove the signal_pending() handling because that's covered by generic guest entry infrastructure

Quoted 4 lines

Jisheng Zhang (3):
RISC-V: KVM: Record number of signal exits as a vCPU stat
RISC-V: KVM: Use generic guest entry infrastructure
riscv: select HAVE_POSIX_CPU_TIMERS_TASK_WORK

I have queued this series for Linux-6.1

Thanks,
Anup

Quoted 10 lines
 arch/riscv/Kconfig                |  1 +
 arch/riscv/include/asm/kvm_host.h |  1 +
 arch/riscv/kvm/Kconfig            |  1 +
 arch/riscv/kvm/vcpu.c             | 18 +++++++-----------
 4 files changed, 10 insertions(+), 11 deletions(-)

--
2.34.1