From: Jan Kiszka <jan.kiszka@web.de>
To: liu ping fan <qemulist@gmail.com>
Cc: Liu Ping Fan <pingfank@linux.vnet.ibm.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Avi Kivity <avi@redhat.com>,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [patch v4 12/16] e1000: apply fine lock on e1000
Date: Wed, 24 Oct 2012 09:17:26 +0200 [thread overview]
Message-ID: <50879606.3070004@web.de> (raw)
In-Reply-To: <CAJnKYQn2hEpQoeOufWZuAbz_ROgN1EuYFS-EC6if3ENKnmXC9w@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]
On 2012-10-24 08:31, liu ping fan wrote:
> On Tue, Oct 23, 2012 at 5:04 PM, Jan Kiszka <jan.kiszka@siemens.com> wrote:
>> On 2012-10-22 11:23, Liu Ping Fan wrote:
>>> Use local lock to protect e1000. When calling the system function,
>>> dropping the fine lock before acquiring the big lock. This will
>>> introduce broken device state, which need extra effort to fix.
>>>
>>> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>>> ---
>>> hw/e1000.c | 24 +++++++++++++++++++++++-
>>> 1 files changed, 23 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/hw/e1000.c b/hw/e1000.c
>>> index ae8a6c5..5eddab5 100644
>>> --- a/hw/e1000.c
>>> +++ b/hw/e1000.c
>>> @@ -85,6 +85,7 @@ typedef struct E1000State_st {
>>> NICConf conf;
>>> MemoryRegion mmio;
>>> MemoryRegion io;
>>> + QemuMutex e1000_lock;
>>>
>>> uint32_t mac_reg[0x8000];
>>> uint16_t phy_reg[0x20];
>>> @@ -223,13 +224,27 @@ static const uint32_t mac_reg_init[] = {
>>> static void
>>> set_interrupt_cause(E1000State *s, int index, uint32_t val)
>>> {
>>> + QemuThread *t;
>>> +
>>> if (val && (E1000_DEVID >= E1000_DEV_ID_82547EI_MOBILE)) {
>>> /* Only for 8257x */
>>> val |= E1000_ICR_INT_ASSERTED;
>>> }
>>> s->mac_reg[ICR] = val;
>>> s->mac_reg[ICS] = val;
>>> - qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0);
>>> +
>>> + t = pthread_getspecific(qemu_thread_key);
>>> + if (t->context_type == 1) {
>>> + qemu_mutex_unlock(&s->e1000_lock);
>>> + qemu_mutex_lock_iothread();
>>> + }
>>> + if (DEVICE(s)->state < DEV_STATE_STOPPING) {
>>> + qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0);
>>> + }
>>> + if (t->context_type == 1) {
>>> + qemu_mutex_unlock_iothread();
>>> + qemu_mutex_lock(&s->e1000_lock);
>>> + }
>>
>> This is ugly for many reasons. First of all, it is racy as the register
>> content may change while dropping the device lock, no? Then you would
>> raise or clear an IRQ spuriously.
>>
> Device state's intact is protected by busy flag, and will not broken
Except that the busy flag concept is broken in itself.
I see that we have a all-or-nothing problem here: to address this
properly, we need to convert the IRQ path to lock-less (or at least
compatible with holding per-device locks) as well.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
next prev parent reply other threads:[~2012-10-24 7:17 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 9:23 [Qemu-devel] [patch v4 00/16] push mmio dispatch out of big lock Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 01/16] atomic: introduce atomic operations Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 02/16] qom: apply atomic on object's refcount Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 03/16] hotplug: introduce qdev_unplug_complete() to remove device from views Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 04/16] pci: remove pci device from mem view when unplug Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 05/16] memory: introduce ref, unref interface for MemoryRegionOps Liu Ping Fan
2012-10-22 9:38 ` Avi Kivity
2012-10-23 11:51 ` Paolo Bonzini
2012-10-23 11:55 ` Avi Kivity
2012-10-23 11:57 ` Paolo Bonzini
2012-10-23 12:02 ` Avi Kivity
2012-10-23 12:06 ` Paolo Bonzini
2012-10-23 12:15 ` Avi Kivity
2012-10-23 12:32 ` Paolo Bonzini
2012-10-23 14:49 ` Avi Kivity
2012-10-23 15:26 ` Paolo Bonzini
2012-10-23 16:09 ` Avi Kivity
2012-10-24 7:29 ` Paolo Bonzini
2012-10-25 16:28 ` Avi Kivity
2012-10-26 15:05 ` Paolo Bonzini
2012-10-23 12:04 ` Jan Kiszka
2012-10-23 12:12 ` Paolo Bonzini
2012-10-23 12:16 ` Jan Kiszka
2012-10-23 12:28 ` Avi Kivity
2012-10-23 12:40 ` Jan Kiszka
2012-10-23 14:37 ` Avi Kivity
2012-10-22 9:23 ` [Qemu-devel] [patch v4 06/16] memory: document ref, unref interface Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 07/16] memory: make mmio dispatch able to be out of biglock Liu Ping Fan
2012-10-23 12:12 ` Jan Kiszka
2012-10-23 12:36 ` Avi Kivity
2012-10-24 6:31 ` liu ping fan
2012-10-24 6:56 ` liu ping fan
2012-10-25 8:57 ` Avi Kivity
2012-10-22 9:23 ` [Qemu-devel] [patch v4 08/16] QemuThread: make QemuThread as tls to store extra info Liu Ping Fan
2012-10-22 9:30 ` Jan Kiszka
2012-10-22 17:13 ` Peter Maydell
2012-10-23 5:58 ` liu ping fan
2012-10-23 11:48 ` Paolo Bonzini
2012-10-23 11:50 ` Peter Maydell
2012-10-23 11:51 ` Jan Kiszka
2012-10-23 12:00 ` Paolo Bonzini
2012-10-23 12:27 ` Peter Maydell
2012-11-18 10:02 ` Brad Smith
2012-11-18 16:14 ` Paolo Bonzini
2012-11-18 16:15 ` Paolo Bonzini
2012-10-22 9:23 ` [Qemu-devel] [patch v4 09/16] memory: introduce mmio request pending to anti nested DMA Liu Ping Fan
2012-10-22 10:28 ` Avi Kivity
2012-10-23 12:38 ` Gleb Natapov
2012-10-24 6:31 ` liu ping fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 10/16] memory: introduce lock ops for MemoryRegionOps Liu Ping Fan
2012-10-22 10:30 ` Avi Kivity
2012-10-23 5:53 ` liu ping fan
2012-10-23 8:53 ` Jan Kiszka
2012-10-22 9:23 ` [Qemu-devel] [patch v4 11/16] vcpu: push mmio dispatcher out of big lock Liu Ping Fan
2012-10-22 10:31 ` Avi Kivity
2012-10-22 10:36 ` Jan Kiszka
2012-10-22 9:23 ` [Qemu-devel] [patch v4 12/16] e1000: apply fine lock on e1000 Liu Ping Fan
2012-10-22 10:37 ` Avi Kivity
2012-10-23 9:04 ` Jan Kiszka
2012-10-24 6:31 ` liu ping fan
2012-10-24 7:17 ` Jan Kiszka [this message]
2012-10-25 9:01 ` Avi Kivity
2012-10-25 9:31 ` Jan Kiszka
2012-10-25 16:21 ` Avi Kivity
2012-10-25 16:39 ` Jan Kiszka
2012-10-25 17:02 ` Avi Kivity
2012-10-25 18:48 ` Jan Kiszka
2012-10-29 5:24 ` liu ping fan
2012-10-24 7:29 ` liu ping fan
2012-10-25 13:34 ` Jan Kiszka
2012-10-25 16:23 ` Avi Kivity
2012-10-25 16:41 ` Jan Kiszka
2012-10-25 17:03 ` Avi Kivity
2012-10-29 5:24 ` liu ping fan
2012-10-31 7:03 ` Jan Kiszka
2012-10-22 9:23 ` [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state Liu Ping Fan
2012-10-22 10:40 ` Avi Kivity
2012-10-23 5:52 ` liu ping fan
2012-10-23 9:06 ` Avi Kivity
2012-10-23 9:07 ` Jan Kiszka
2012-10-23 9:32 ` liu ping fan
2012-10-23 9:37 ` Avi Kivity
2012-10-24 6:36 ` liu ping fan
2012-10-25 8:55 ` Avi Kivity
2012-10-25 9:00 ` Peter Maydell
2012-10-25 9:04 ` Avi Kivity
2012-10-26 3:05 ` liu ping fan
2012-10-26 3:08 ` liu ping fan
2012-10-26 10:25 ` Jan Kiszka
2012-10-29 5:24 ` liu ping fan
2012-10-29 7:50 ` Peter Maydell
2012-10-22 9:23 ` [Qemu-devel] [patch v4 14/16] qdev: introduce stopping state Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 15/16] e1000: introduce unmap() to fix unplug issue Liu Ping Fan
2012-10-22 9:23 ` [Qemu-devel] [patch v4 16/16] e1000: implement MemoryRegionOps's ref&lock interface Liu Ping Fan
2012-10-25 14:04 ` [Qemu-devel] [patch v4 00/16] push mmio dispatch out of big lock Peter Maydell
2012-10-25 16:44 ` Jan Kiszka
2012-10-25 17:07 ` Avi Kivity
2012-10-25 17:13 ` Peter Maydell
2012-10-25 18:13 ` Marcelo Tosatti
2012-10-25 19:00 ` Jan Kiszka
2012-10-25 19:06 ` Peter Maydell
2012-10-29 15:24 ` Avi Kivity
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=50879606.3070004@web.de \
--to=jan.kiszka@web.de \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pingfank@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@gmail.com \
--cc=stefanha@gmail.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).