From: Marc Zyngier <marc.zyngier@arm.com>
To: "Julien Grall" <julien.grall@arm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org,
Richard Henderson <richard.henderson@linaro.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 05/11] KVM: arm/arm64: Reset the VCPU without preemption and vcpu state loaded
Date: Mon, 4 Mar 2019 17:06:25 +0000 [thread overview]
Message-ID: <ec205905-6b7b-2a6d-f70f-9bca574dd593@arm.com> (raw)
In-Reply-To: <f6928433-8ae6-6cae-d86d-b392f5b4fea6@arm.com>
On 04/03/2019 16:30, Julien Grall wrote:
> Hi,
>
> I noticed some issues with this patch when rebooting a guest after using perf.
>
> [ 577.513447] BUG: sleeping function called from invalid context at
> kernel/locking/mutex.c:908
> [ 577.521926] in_atomic(): 1, irqs_disabled(): 0, pid: 2323, name: qemu-system aar
> [ 577.529354] 1 lock held by qemu-system-aar/2323:
> [ 577.533998] #0: 00000000f4f96804 (&vcpu->mutex){+.+.}, at:
> kvm_vcpu_ioctl+0x74/0xac0
> [ 577.541865] Preemption disabled at:
> [ 577.541871] [<ffff0000100cc82c>] kvm_reset_vcpu+0x1c/0x1d0
> [ 577.550882] CPU: 6 PID: 2323 Comm: qemu-system-aar Tainted: G W 5.0.0
> #1277
> [ 577.559137] Hardware name: AMD Seattle (Rev.B0) Development Board (Overdrive)
> (DT)
> [ 577.566698] Call trace:
> [ 577.569138] dump_backtrace+0x0/0x140
> [ 577.572793] show_stack+0x14/0x20
> [ 577.576103] dump_stack+0xa0/0xd4
> [ 577.579412] ___might_sleep+0x1e4/0x2b0
> [ 577.583241] __might_sleep+0x60/0xb8
> [ 577.586810] __mutex_lock+0x58/0x860
> [ 577.590378] mutex_lock_nested+0x1c/0x28
> [ 577.594294] perf_event_ctx_lock_nested+0xf4/0x238
> [ 577.599078] perf_event_read_value+0x24/0x60
> [ 577.603341] kvm_pmu_get_counter_value+0x80/0xe8
> [ 577.607950] kvm_pmu_stop_counter+0x2c/0x98
> [ 577.612126] kvm_pmu_vcpu_reset+0x58/0xd0
> [ 577.616128] kvm_reset_vcpu+0xec/0x1d0
> [ 577.619869] kvm_arch_vcpu_ioctl+0x6b0/0x860
> [ 577.624131] kvm_vcpu_ioctl+0xe0/0xac0
> [ 577.627876] do_vfs_ioctl+0xbc/0x910
> [ 577.631443] ksys_ioctl+0x78/0xa8
> [ 577.634751] __arm64_sys_ioctl+0x1c/0x28
> [ 577.638667] el0_svc_common+0x90/0x118
> [ 577.642408] el0_svc_handler+0x2c/0x80
> [ 577.646150] el0_svc+0x8/0xc
>
> This is happening because the vCPU reset code is now running with preemption
> disable. However, the perf code cannot be called with preemption disabled as it
> is using mutex.
>
> Do you have any suggestion on the way to fix this potential issue?
Given that the PMU is entirely emulated, it never has any state loaded
on the CPU. It thus doesn't need to be part of the non-preemptible section.
Can you please give this (untested) patchlet one a go? It's not exactly
pretty, but I believe it will do the trick.
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 54788eb9e695..16e773f3019f 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -128,6 +128,9 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
int ret = -EINVAL;
bool loaded;
+ /* Reset PMU outside of the non-preemptible section */
+ kvm_pmu_vcpu_reset(vcpu);
+
preempt_disable();
loaded = (vcpu->cpu != -1);
if (loaded)
@@ -177,9 +180,6 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
vcpu->arch.reset_state.reset = false;
}
- /* Reset PMU */
- kvm_pmu_vcpu_reset(vcpu);
-
/* Default workaround setup is enabled (if supported) */
if (kvm_arm_have_ssbd() == KVM_SSBD_KERNEL)
vcpu->arch.workaround_flags |= VCPU_WORKAROUND_2_FLAG;
Thanks,
M.
--
Jazz is not dead. It just smells funny...
next prev parent reply other threads:[~2019-03-04 17:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-07 13:18 [GIT PULL] KVM/ARM updates for 5.0-rc6 Marc Zyngier
2019-02-07 13:18 ` [PATCH 01/11] KVM: arm/arm64: vgic: Make vgic_irq->irq_lock a raw_spinlock Marc Zyngier
2019-02-07 13:18 ` [PATCH 02/11] KVM: arm/arm64: vgic: Make vgic_dist->lpi_list_lock " Marc Zyngier
2019-02-07 13:18 ` [PATCH 03/11] KVM: arm/arm64: vgic: Make vgic_cpu->ap_list_lock " Marc Zyngier
2019-02-07 13:18 ` [PATCH 04/11] arm64: KVM: Don't generate UNDEF when LORegion feature is present Marc Zyngier
2019-02-07 13:18 ` [PATCH 05/11] KVM: arm/arm64: Reset the VCPU without preemption and vcpu state loaded Marc Zyngier
2019-03-04 16:30 ` Julien Grall
2019-03-04 17:06 ` Marc Zyngier [this message]
2019-03-04 17:31 ` Julien Grall
2019-03-04 17:37 ` Marc Zyngier
2019-02-07 13:18 ` [PATCH 06/11] arm/arm64: KVM: Allow a VCPU to fully reset itself Marc Zyngier
2019-02-07 13:18 ` [PATCH 07/11] arm/arm64: KVM: Don't panic on failure to properly reset system registers Marc Zyngier
2019-02-07 13:18 ` [PATCH 08/11] KVM: arm/arm64: vgic: Always initialize the group of private IRQs Marc Zyngier
2019-02-07 13:18 ` [PATCH 09/11] arm: KVM: Add missing kvm_stage2_has_pmd() helper Marc Zyngier
2019-02-07 13:18 ` [PATCH 10/11] KVM: arm64: Relax the restriction on using stage2 PUD huge mapping Marc Zyngier
2019-02-07 13:18 ` [PATCH 11/11] KVM: arm64: Forbid kprobing of the VHE world-switch code Marc Zyngier
2019-02-13 18:39 ` [GIT PULL] KVM/ARM updates for 5.0-rc6 Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec205905-6b7b-2a6d-f70f-9bca574dd593@arm.com \
--to=marc.zyngier@arm.com \
--cc=julien.grall@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mhiramat@kernel.org \
--cc=pbonzini@redhat.com \
--cc=richard.henderson@linaro.org \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).