From: Christian Borntraeger <borntraeger@de.ibm.com>
To: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
KVM list <kvm@vger.kernel.org>,
Cornelia Huck <cornelia.huck@de.ibm.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [s390] possible deadlock in handle_sigp?
Date: Mon, 19 Sep 2016 10:15:08 +0200 [thread overview]
Message-ID: <18e8d5ed-c6f7-4617-0426-be203beb1965@de.ibm.com> (raw)
In-Reply-To: <20160915212142.5fd5048e@thinkpad-w530>
On 09/15/2016 09:21 PM, David Hildenbrand wrote:
>> On 09/12/2016 08:03 PM, Paolo Bonzini wrote:
>>>
>>>
>>> On 12/09/2016 19:37, Christian Borntraeger wrote:
>>>> On 09/12/2016 06:44 PM, Paolo Bonzini wrote:
>>>>> I think that two CPUs doing reciprocal SIGPs could in principle end up
>>>>> waiting on each other to complete their run_on_cpu. If the SIGP has to
>>>>> be synchronous the fix is not trivial (you'd have to put the CPU in a
>>>>> state similar to cpu->halted = 1), otherwise it's enough to replace
>>>>> run_on_cpu with async_run_on_cpu.
>>>>
>>>> IIRC the sigps are supossed to be serialized by the big QEMU lock. WIll
>>>> have a look.
>>>
>>> Yes, but run_on_cpu drops it when it waits on the qemu_work_cond
>>> condition variable. (Related: I stumbled upon it because I wanted to
>>> remove the BQL from run_on_cpu work items).
>>
>> Yes, seems you are right. If both CPUs have just exited from KVM doing a
>> crossover sigp, they will do the arch_exit handling before the run_on_cpu
>> stuff which might result in this hang. (luckily it seems quite unlikely
>> but still we need to fix it).
>> We cannot simply use async as the callbacks also provide the condition
>> code for the initiater, so this requires some rework.
>>
>>
>
> Smells like having to provide a lock per CPU. Trylock that lock, if that's not
> possible, cc=busy. SIGP SET ARCHITECTURE has to lock all CPUs.
>
> That was the initital design, until I realized that this was all protected by
> the BQL.
>
> David
We only do the slow path things in QEMU. Maybe we could just have one lock that
we trylock and return a condition code of 2 (busy) if we fail. That seems the
most simple solution while still being architecturally correct. Something like
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index f348745..5706218 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -133,6 +133,8 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
KVM_CAP_LAST_INFO
};
+static QemuMutex qemu_sigp_mutex;
+
static int cap_sync_regs;
static int cap_async_pf;
static int cap_mem_op;
@@ -358,6 +360,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
rc = compat_disable_facilities(s, fac_mask, ARRAY_SIZE(fac_mask));
}
+ qemu_mutex_init(&qemu_sigp_mutex);
+
return rc;
}
@@ -1845,6 +1849,11 @@ static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)
status_reg = &env->regs[r1];
param = (r1 % 2) ? env->regs[r1] : env->regs[r1 + 1];
+ if (qemu_mutex_trylock(&qemu_sigp_mutex)) {
+ setcc(cpu, SIGP_CC_BUSY );
+ return 0;
+ }
+
switch (order) {
case SIGP_SET_ARCH:
ret = sigp_set_architecture(cpu, param, status_reg);
@@ -1854,6 +1863,7 @@ static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)
dst_cpu = s390_cpu_addr2state(env->regs[r3]);
ret = handle_sigp_single_dst(dst_cpu, order, param, status_reg);
}
+ qemu_mutex_unlock(&qemu_sigp_mutex);
trace_kvm_sigp_finished(order, CPU(cpu)->cpu_index,
dst_cpu ? CPU(dst_cpu)->cpu_index : -1, ret);
next prev parent reply other threads:[~2016-09-19 8:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 16:44 [Qemu-devel] [s390] possible deadlock in handle_sigp? Paolo Bonzini
2016-09-12 17:37 ` Christian Borntraeger
2016-09-12 18:03 ` Paolo Bonzini
2016-09-13 13:06 ` Christian Borntraeger
2016-09-15 19:21 ` David Hildenbrand
2016-09-15 20:50 ` Paolo Bonzini
2016-09-19 8:15 ` Christian Borntraeger [this message]
2016-09-19 11:25 ` David Hildenbrand
2016-09-19 11:45 ` Christian Borntraeger
2016-09-20 11:57 ` [Qemu-devel] [PATCH] s390x/kvm: Fix potential deadlock in sigp handling Christian Borntraeger
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=18e8d5ed-c6f7-4617-0426-be203beb1965@de.ibm.com \
--to=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dahi@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).