Move KVM's morphing of pending signals into userspace exits into KVM proper, and drop the @vcpu param from xfer_to_guest_mode_handle_work(). How KVM responds to -EINTR is a detail that really belongs in KVM itself, and invoking kvm_handle_signal_exit() from kernel code creates an inverted module dependency. E.g. attempting to move kvm_handle_signal_exit() into kvm_main.c would generate an linker error when building kvm.ko as a module. Dropping KVM details will also converting the KVM "entry" code into a more generic virtualization framework so that it can be used when running as a Hyper-V root partition. Lastly, eliminating usage of "struct kvm_vcpu" outside of KVM is also nice to have for KVM x86 developers, as keeping the details of kvm_vcpu purely within KVM allows changing the layout of the structure without having to boot into a new kernel, e.g. allows rebuilding and reloading kvm.ko with a modified kvm_vcpu structure as part of debug/development.
Unified · Split
| @@ -6,7 +6,6 @@ · 5 unmodified lines | ||
| 6 | 6 | |
| 7 | 7 | #include <linux/bug.h> |
| 8 | 8 | #include <linux/cpu_pm.h> |
| 9 | −#include <linux/entry-kvm.h> | |
| 10 | 9 | #include <linux/errno.h> |
| 11 | 10 | #include <linux/err.h> |
| 12 | 11 | #include <linux/kvm_host.h> |
| @@ -1177,7 +1176,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · 1164 unmodified lines | ||
| 1177 | 1176 | /* |
| 1178 | 1177 | * Check conditions before entering the guest |
| 1179 | 1178 | */ |
| 1180 | − ret = xfer_to_guest_mode_handle_work(vcpu); | |
| 1179 | + ret = kvm_xfer_to_guest_mode_handle_work(vcpu); | |
| 1181 | 1180 | if (!ret) |
| 1182 | 1181 | ret = 1; |
| 1183 | 1182 | |
| @@ -4,7 +4,6 @@ · 3 unmodified lines | ||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | #include <linux/kvm_host.h> |
| 7 | −#include <linux/entry-kvm.h> | |
| 8 | 7 | #include <asm/fpu.h> |
| 9 | 8 | #include <asm/lbt.h> |
| 10 | 9 | #include <asm/loongarch.h> |
| @@ -251,7 +250,7 @@ static int kvm_enter_guest_check(struct kvm_vcpu *vcpu) · 240 unmodified lines | ||
| 251 | 250 | /* |
| 252 | 251 | * Check conditions before entering the guest |
| 253 | 252 | */ |
| 254 | − ret = xfer_to_guest_mode_handle_work(vcpu); | |
| 253 | + ret = kvm_xfer_to_guest_mode_handle_work(vcpu); | |
| 255 | 254 | if (ret < 0) |
| 256 | 255 | return ret; |
| 257 | 256 | |
| @@ -7,7 +7,6 @@ · 6 unmodified lines | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | #include <linux/bitops.h> |
| 10 | −#include <linux/entry-kvm.h> | |
| 11 | 10 | #include <linux/errno.h> |
| 12 | 11 | #include <linux/err.h> |
| 13 | 12 | #include <linux/kdebug.h> |
| @@ -910,7 +909,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · 896 unmodified lines | ||
| 910 | 909 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 911 | 910 | while (ret > 0) { |
| 912 | 911 | /* Check conditions before entering the guest */ |
| 913 | − ret = xfer_to_guest_mode_handle_work(vcpu); | |
| 912 | + ret = kvm_xfer_to_guest_mode_handle_work(vcpu); | |
| 914 | 913 | if (ret) |
| 915 | 914 | continue; |
| 916 | 915 | ret = 1; |
| @@ -28,7 +28,6 @@ · 27 unmodified lines | ||
| 28 | 28 | #include <linux/slab.h> |
| 29 | 29 | #include <linux/tboot.h> |
| 30 | 30 | #include <linux/trace_events.h> |
| 31 | −#include <linux/entry-kvm.h> | |
| 32 | 31 | |
| 33 | 32 | #include <asm/apic.h> |
| 34 | 33 | #include <asm/asm.h> |
| @@ -59,7 +59,6 @@ · 58 unmodified lines | ||
| 59 | 59 | #include <linux/sched/stat.h> |
| 60 | 60 | #include <linux/sched/isolation.h> |
| 61 | 61 | #include <linux/mem_encrypt.h> |
| 62 | −#include <linux/entry-kvm.h> | |
| 63 | 62 | #include <linux/suspend.h> |
| 64 | 63 | #include <linux/smp.h> |
| 65 | 64 | |
| @@ -11241,7 +11240,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) · 11175 unmodified lines | ||
| 11241 | 11240 | |
| 11242 | 11241 | if (__xfer_to_guest_mode_work_pending()) { |
| 11243 | 11242 | kvm_vcpu_srcu_read_unlock(vcpu); |
| 11244 | − r = xfer_to_guest_mode_handle_work(vcpu); | |
| 11243 | + r = kvm_xfer_to_guest_mode_handle_work(vcpu); | |
| 11245 | 11244 | kvm_vcpu_srcu_read_lock(vcpu); |
| 11246 | 11245 | if (r) |
| 11247 | 11246 | return r; |
| @@ -21,8 +21,6 @@ · 20 unmodified lines | ||
| 21 | 21 | _TIF_NOTIFY_SIGNAL | _TIF_NOTIFY_RESUME | \ |
| 22 | 22 | ARCH_XFER_TO_GUEST_MODE_WORK) |
| 23 | 23 | |
| 24 | −struct kvm_vcpu; | |
| 25 | − | |
| 26 | 24 | /** |
| 27 | 25 | * arch_xfer_to_guest_mode_handle_work - Architecture specific xfer to guest |
| 28 | 26 | * mode work handling function. |
| @@ -32,12 +30,10 @@ struct kvm_vcpu; · 3 unmodified lines | ||
| 32 | 30 | * Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be |
| 33 | 31 | * replaced by architecture specific code. |
| 34 | 32 | */ |
| 35 | −static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu, | |
| 36 | − unsigned long ti_work); | |
| 33 | +static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work); | |
| 37 | 34 | |
| 38 | 35 | #ifndef arch_xfer_to_guest_mode_work |
| 39 | −static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu, | |
| 40 | − unsigned long ti_work) | |
| 36 | +static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work) | |
| 41 | 37 | { |
| 42 | 38 | return 0; |
| 43 | 39 | } |
| @@ -46,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu, · 2 unmodified lines | ||
| 46 | 42 | /** |
| 47 | 43 | * xfer_to_guest_mode_handle_work - Check and handle pending work which needs |
| 48 | 44 | * to be handled before going to guest mode |
| 49 | − * @vcpu: Pointer to current's VCPU data | |
| 50 | 45 | * |
| 51 | 46 | * Returns: 0 or an error code |
| 52 | 47 | */ |
| 53 | −int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu); | |
| 48 | +int xfer_to_guest_mode_handle_work(void); | |
| 54 | 49 | |
| 55 | 50 | /** |
| 56 | 51 | * xfer_to_guest_mode_prepare - Perform last minute preparation work that |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef __KVM_HOST_H |
| 3 | 3 | #define __KVM_HOST_H |
| 4 | 4 | |
| 5 | − | |
| 5 | +#include <linux/entry-kvm.h> | |
| 6 | 6 | #include <linux/types.h> |
| 7 | 7 | #include <linux/hardirq.h> |
| 8 | 8 | #include <linux/list.h> |
| @@ -2450,6 +2450,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) · 2441 unmodified lines | ||
| 2450 | 2450 | vcpu->run->exit_reason = KVM_EXIT_INTR; |
| 2451 | 2451 | vcpu->stat.signal_exits++; |
| 2452 | 2452 | } |
| 2453 | + | |
| 2454 | +static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) | |
| 2455 | +{ | |
| 2456 | + int r = xfer_to_guest_mode_handle_work(); | |
| 2457 | + | |
| 2458 | + if (r) { | |
| 2459 | + WARN_ON_ONCE(r != -EINTR); | |
| 2460 | + kvm_handle_signal_exit(vcpu); | |
| 2461 | + } | |
| 2462 | + return r; | |
| 2463 | +} | |
| 2453 | 2464 | #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ |
| 2454 | 2465 | |
| 2455 | 2466 | /* |
| @@ -1,17 +1,14 @@ | ||
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | 2 | |
| 3 | 3 | #include <linux/entry-kvm.h> |
| 4 | −#include <linux/kvm_host.h> | |
| 5 | 4 | |
| 6 | −static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) | |
| 5 | +static int xfer_to_guest_mode_work(unsigned long ti_work) | |
| 7 | 6 | { |
| 8 | 7 | do { |
| 9 | 8 | int ret; |
| 10 | 9 | |
| 11 | − if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { | |
| 12 | − kvm_handle_signal_exit(vcpu); | |
| 10 | + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) | |
| 13 | 11 | return -EINTR; |
| 14 | − } | |
| 15 | 12 | |
| 16 | 13 | if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) |
| 17 | 14 | schedule(); |
| @@ -19,7 +16,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) · 1 unmodified line | ||
| 19 | 16 | if (ti_work & _TIF_NOTIFY_RESUME) |
| 20 | 17 | resume_user_mode_work(NULL); |
| 21 | 18 | |
| 22 | − ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work); | |
| 19 | + ret = arch_xfer_to_guest_mode_handle_work(ti_work); | |
| 23 | 20 | if (ret) |
| 24 | 21 | return ret; |
| 25 | 22 | |
| @@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) · 2 unmodified lines | ||
| 28 | 25 | return 0; |
| 29 | 26 | } |
| 30 | 27 | |
| 31 | −int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) | |
| 28 | +int xfer_to_guest_mode_handle_work(void) | |
| 32 | 29 | { |
| 33 | 30 | unsigned long ti_work; |
| 34 | 31 | |
| @@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) · 9 unmodified lines | ||
| 44 | 41 | if (!(ti_work & XFER_TO_GUEST_MODE_WORK)) |
| 45 | 42 | return 0; |
| 46 | 43 | |
| 47 | − return xfer_to_guest_mode_work(vcpu, ti_work); | |
| 44 | + return xfer_to_guest_mode_work(ti_work); | |
| 48 | 45 | } |
| 49 | 46 | EXPORT_SYMBOL_GPL(xfer_to_guest_mode_handle_work); |