* [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume
[not found] <20220301201629.18547-1-sashal@kernel.org>
@ 2022-03-01 20:16 ` Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Sasha Levin
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU Sasha Levin
2 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2022-03-01 20:16 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Wanpeng Li, Paolo Bonzini, Sasha Levin, kvm
From: Wanpeng Li <wanpengli@tencent.com>
[ Upstream commit 4cb9a998b1ce25fad74a82f5a5c45a4ef40de337 ]
I saw the below splatting after the host suspended and resumed.
WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm]
CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G W IOE 5.17.0-rc3+ #4
RIP: 0010:kvm_resume+0x2c/0x30 [kvm]
Call Trace:
<TASK>
syscore_resume+0x90/0x340
suspend_devices_and_enter+0xaee/0xe90
pm_suspend.cold+0x36b/0x3c2
state_store+0x82/0xf0
kernfs_fop_write_iter+0x1b6/0x260
new_sync_write+0x258/0x370
vfs_write+0x33f/0x510
ksys_write+0xc9/0x160
do_syscall_64+0x3b/0xc0
entry_SYSCALL_64_after_hwframe+0x44/0xae
lockdep_is_held() can return -1 when lockdep is disabled which triggers
this warning. Let's use lockdep_assert_not_held() which can detect
incorrect calls while holding a lock and it also avoids false negatives
when lockdep is disabled.
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Message-Id: <1644920142-81249-1-git-send-email-wanpengli@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
virt/kvm/kvm_main.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 13aff136e6eef..5309b3eaa0470 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5416,9 +5416,7 @@ static int kvm_suspend(void)
static void kvm_resume(void)
{
if (kvm_usage_count) {
-#ifdef CONFIG_LOCKDEP
- WARN_ON(lockdep_is_held(&kvm_count_lock));
-#endif
+ lockdep_assert_not_held(&kvm_count_lock);
hardware_enable_nolock(NULL);
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode
[not found] <20220301201629.18547-1-sashal@kernel.org>
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume Sasha Levin
@ 2022-03-01 20:16 ` Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU Sasha Levin
2 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2022-03-01 20:16 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Anton Romanov, Paolo Bonzini, Sasha Levin, tglx, mingo, bp,
dave.hansen, x86, kvm
From: Anton Romanov <romanton@google.com>
[ Upstream commit 3a55f729240a686aa8af00af436306c0cd532522 ]
If vcpu has tsc_always_catchup set each request updates pvclock data.
KVM_HC_CLOCK_PAIRING consumers such as ptp_kvm_x86 rely on tsc read on
host's side and do hypercall inside pvclock_read_retry loop leading to
infinite loop in such situation.
v3:
Removed warn
Changed return code to KVM_EFAULT
v2:
Added warn
Signed-off-by: Anton Romanov <romanton@google.com>
Message-Id: <20220216182653.506850-1-romanton@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kvm/x86.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 33cb065181248..c804122bb6e3a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8657,6 +8657,13 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr,
if (clock_type != KVM_CLOCK_PAIRING_WALLCLOCK)
return -KVM_EOPNOTSUPP;
+ /*
+ * When tsc is in permanent catchup mode guests won't be able to use
+ * pvclock_read_retry loop to get consistent view of pvclock
+ */
+ if (vcpu->arch.tsc_always_catchup)
+ return -KVM_EOPNOTSUPP;
+
if (!kvm_get_walltime_and_clockread(&ts, &cycle))
return -KVM_EOPNOTSUPP;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU
[not found] <20220301201629.18547-1-sashal@kernel.org>
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume Sasha Levin
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Sasha Levin
@ 2022-03-01 20:16 ` Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
2 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2022-03-01 20:16 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Wanpeng Li, Paolo Bonzini, Sasha Levin, tglx, mingo, bp,
dave.hansen, x86, kvm
From: Wanpeng Li <wanpengli@tencent.com>
[ Upstream commit ec756e40e271866f951d77c5e923d8deb6002b15 ]
Inspired by commit 3553ae5690a (x86/kvm: Don't use pvqspinlock code if
only 1 vCPU), on a VM with only 1 vCPU, there is no need to enable
pv tlb/ipi/sched_yield and we can save the memory for __pv_cpu_mask.
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Message-Id: <1645171838-2855-1-git-send-email-wanpengli@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kernel/kvm.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index b656456c3a944..811c7aaf23aac 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -457,19 +457,22 @@ static bool pv_tlb_flush_supported(void)
{
return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
- kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+ kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+ (num_possible_cpus() != 1));
}
static bool pv_ipi_supported(void)
{
- return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
+ return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
+ (num_possible_cpus() != 1));
}
static bool pv_sched_yield_supported(void)
{
return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
- kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+ kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+ (num_possible_cpus() != 1));
}
#define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume Sasha Levin
@ 2022-03-01 20:17 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-03-01 20:17 UTC (permalink / raw)
To: Sasha Levin, linux-kernel, stable; +Cc: Wanpeng Li, kvm
On 3/1/22 21:16, Sasha Levin wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> [ Upstream commit 4cb9a998b1ce25fad74a82f5a5c45a4ef40de337 ]
>
> I saw the below splatting after the host suspended and resumed.
>
> WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm]
> CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G W IOE 5.17.0-rc3+ #4
> RIP: 0010:kvm_resume+0x2c/0x30 [kvm]
> Call Trace:
> <TASK>
> syscore_resume+0x90/0x340
> suspend_devices_and_enter+0xaee/0xe90
> pm_suspend.cold+0x36b/0x3c2
> state_store+0x82/0xf0
> kernfs_fop_write_iter+0x1b6/0x260
> new_sync_write+0x258/0x370
> vfs_write+0x33f/0x510
> ksys_write+0xc9/0x160
> do_syscall_64+0x3b/0xc0
> entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> lockdep_is_held() can return -1 when lockdep is disabled which triggers
> this warning. Let's use lockdep_assert_not_held() which can detect
> incorrect calls while holding a lock and it also avoids false negatives
> when lockdep is disabled.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> Message-Id: <1644920142-81249-1-git-send-email-wanpengli@tencent.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> virt/kvm/kvm_main.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 13aff136e6eef..5309b3eaa0470 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5416,9 +5416,7 @@ static int kvm_suspend(void)
> static void kvm_resume(void)
> {
> if (kvm_usage_count) {
> -#ifdef CONFIG_LOCKDEP
> - WARN_ON(lockdep_is_held(&kvm_count_lock));
> -#endif
> + lockdep_assert_not_held(&kvm_count_lock);
> hardware_enable_nolock(NULL);
> }
> }
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Sasha Levin
@ 2022-03-01 20:17 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-03-01 20:17 UTC (permalink / raw)
To: Sasha Levin, linux-kernel, stable
Cc: Anton Romanov, tglx, mingo, bp, dave.hansen, x86, kvm
On 3/1/22 21:16, Sasha Levin wrote:
> From: Anton Romanov <romanton@google.com>
>
> [ Upstream commit 3a55f729240a686aa8af00af436306c0cd532522 ]
>
> If vcpu has tsc_always_catchup set each request updates pvclock data.
> KVM_HC_CLOCK_PAIRING consumers such as ptp_kvm_x86 rely on tsc read on
> host's side and do hypercall inside pvclock_read_retry loop leading to
> infinite loop in such situation.
>
> v3:
> Removed warn
> Changed return code to KVM_EFAULT
> v2:
> Added warn
>
> Signed-off-by: Anton Romanov <romanton@google.com>
> Message-Id: <20220216182653.506850-1-romanton@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/x86/kvm/x86.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 33cb065181248..c804122bb6e3a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8657,6 +8657,13 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr,
> if (clock_type != KVM_CLOCK_PAIRING_WALLCLOCK)
> return -KVM_EOPNOTSUPP;
>
> + /*
> + * When tsc is in permanent catchup mode guests won't be able to use
> + * pvclock_read_retry loop to get consistent view of pvclock
> + */
> + if (vcpu->arch.tsc_always_catchup)
> + return -KVM_EOPNOTSUPP;
> +
> if (!kvm_get_walltime_and_clockread(&ts, &cycle))
> return -KVM_EOPNOTSUPP;
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU Sasha Levin
@ 2022-03-01 20:17 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-03-01 20:17 UTC (permalink / raw)
To: Sasha Levin, linux-kernel, stable
Cc: Wanpeng Li, tglx, mingo, bp, dave.hansen, x86, kvm
On 3/1/22 21:16, Sasha Levin wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> [ Upstream commit ec756e40e271866f951d77c5e923d8deb6002b15 ]
>
> Inspired by commit 3553ae5690a (x86/kvm: Don't use pvqspinlock code if
> only 1 vCPU), on a VM with only 1 vCPU, there is no need to enable
> pv tlb/ipi/sched_yield and we can save the memory for __pv_cpu_mask.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> Message-Id: <1645171838-2855-1-git-send-email-wanpengli@tencent.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/x86/kernel/kvm.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index b656456c3a944..811c7aaf23aac 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -457,19 +457,22 @@ static bool pv_tlb_flush_supported(void)
> {
> return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
> !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
> - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
> + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
> + (num_possible_cpus() != 1));
> }
>
> static bool pv_ipi_supported(void)
> {
> - return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
> + return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
> + (num_possible_cpus() != 1));
> }
>
> static bool pv_sched_yield_supported(void)
> {
> return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
> !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
> - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
> + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
> + (num_possible_cpus() != 1));
> }
>
> #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
NACK
Not really necessary.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-03-01 20:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20220301201629.18547-1-sashal@kernel.org>
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 05/23] KVM: Fix lockdep false negative during host resume Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 06/23] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
2022-03-01 20:16 ` [PATCH AUTOSEL 5.15 10/23] x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU Sasha Levin
2022-03-01 20:17 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox