From: Avi Kivity <avi@redhat.com>
To: liu ping fan <qemulist@gmail.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
Liu Ping Fan <pingfank@linux.vnet.ibm.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 10/10] qdev: fix create in place obj's life cycle problem
Date: Wed, 05 Sep 2012 12:52:56 +0300 [thread overview]
Message-ID: <504720F8.9020104@redhat.com> (raw)
In-Reply-To: <CAJnKYQmhafAQEy7RODCABaBUyChvweXxCRmijOQQTf7fD54UOQ@mail.gmail.com>
On 09/05/2012 11:19 AM, liu ping fan wrote:
> [...]
>>>
>>>>>> We could externalize the refcounting and push it into device code. This
>>>>>> means:
>>>>>>
>>>>>> memory_region_init_io(&s->mem, dev)
>>>>>>
>>>>>> ...
>>>>>>
>>>>>> object_ref(dev)
>>>>>> memory_region_add_subregion(..., &dev->mr)
>>>>>>
>>>>>> ...
>>>>>>
>>>>>> memory_region_del_subregion(..., &dev->mr) // implied flush
>>>>>> object_unref(dev)
>>>>>>
>>>>> I think "object_ref(dev)" just another style to push
>>>>> MemoryRegionOps::object() to device level. And I think we can bypass
>>>>> it. The caller (unplug, pci-reconfig ) of
>>>>> memory_region_del_subregion() ensure the @dev is valid.
>>>>> If the implied flush is implemented in synchronize, _del_subregion()
>>>>> will guarantee no reader for @dev->mr and @dev exist any longer.
>>>>
>>>> The above code has a deadlock. memory_region_del_subregion() may be
>>>> called under the device lock (since it may be the result of mmio to the
>>>> device), and if the flush uses synchronized_rcu(), it will wait forever
>>>> for the read-side critical section to complete.
>>>>
>>> But if _del_subregion() just wait for mr-X quiescent period, while
>>> calling in mr-Y's read side critical section, then we can avoid
>>> deadlock. I saw in pci-mapping, we delete mr-X in mr-Y read side.
>>>
>>>>> So I
>>>>> think we can save both object_ref/unref(dev) for memory system.
>>>>> The only problem is that whether we can implement it as synchronous or
>>>>> not, is it possible that we can launch a _del_subregion(mr-X) in
>>>>> mr-X's dispatcher?
>>>>
>>>> Yes. Real cases exist.
>>>
>>> Oh, I find the sample code, then, the deadlock is unavoidable in this method.
>>>>
>>>> What alternatives remain?
>>>>
>>> I think a way out may be async+refcnt
>>>
>> If we consider the relationship of MemoryRegionImpl and device as the
>> one between file and file->private_data in Linux. Then the creation
>> of impl will object_ref(dev) and when impl->ref=0, it will
>> object_unref(dev)
>> But this is an async model, for those client which need to know the
>> end of flush, we can adopt callback just like call_rcu().
>>
>>
> During this thread, it seems that no matter we adopt refcnt on
> MemoryRegionImpl or not, protecting MemoryRegion::opaque during
> dispatch is still required.
Right. So MemoryRegionImpl is pointless.
My current preference is MemoryRegionOps::ref(MemoryRegion *mr) (and a
corresponding unref), which has the following requirements:
- if the refcount is nonzero, MemoryRegion::opaque is safe to use
- if the refcount is nonzero, the MemoryRegion itself is stable.
Later we can change other callbacks to also use mr instead of opaque.
Usually the callback will be able to derive the device object from the
region, only special cases will require
memory_region_opaque(MemoryRegion *). We can even drop the opaque from
memory_region_init_io() and replace it with memory_region_set_opaque(),
to be used in those special cases.
> It is challenging to substitute
> memory_region_init_io() 's 3rd parameter from void* to Object*, owning
> to the conflict that life-cycle management need the host of opaque,
> while Object and mr need 1:1 map. So I think, I will move forward on
> the way based on MemoryRegionOps::object(). Right?
As outlined above, I now prefer MemoryRegionOps::ref/unref.
Advantages compared to MemoryRegionOps::object():
- decoupled from the QOM framework
Disadvantages:
- more boilerplate code in converted devices
Since we are likely to convert few devices to lockless dispatch, I
believe the tradeoff is justified. But let's hear Jan and the others.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2012-09-05 9:53 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-24 9:49 [Qemu-devel] [PATCH 0/10] rework on hot unplug Liu Ping Fan
2012-08-24 9:49 ` [Qemu-devel] [PATCH 01/10] qom: add, remove of link property need to ref, unref its target Liu Ping Fan
2012-08-24 14:52 ` Paolo Bonzini
2012-08-24 9:49 ` [Qemu-devel] [PATCH 02/10] qdev: change iterator callback seq Liu Ping Fan
2012-08-24 9:49 ` [Qemu-devel] [PATCH 03/10] qom: export object_property_is_child, object_property_is_link Liu Ping Fan
2012-08-24 14:51 ` Paolo Bonzini
2012-08-25 7:43 ` liu ping fan
2012-08-25 8:04 ` Blue Swirl
2012-08-24 9:49 ` [Qemu-devel] [PATCH 04/10] qdev: introduce new interface to remove composite sub-tree Liu Ping Fan
2012-08-24 9:49 ` [Qemu-devel] [PATCH 05/10] qdev: finalize of qbus, qdev will not the right place to free children Liu Ping Fan
2012-08-24 14:50 ` Paolo Bonzini
2012-08-24 9:49 ` [Qemu-devel] [PATCH 06/10] qom: expose object_property_del_child Liu Ping Fan
2012-08-24 14:44 ` Paolo Bonzini
2012-08-24 9:49 ` [Qemu-devel] [PATCH 07/10] unplug: using new intf qdev_delete_subtree in acpi_piix_eject_slot Liu Ping Fan
2012-08-24 10:24 ` Paolo Bonzini
2012-08-25 7:05 ` liu ping fan
2012-08-24 9:49 ` [Qemu-devel] [PATCH 08/10] qdev: rename qdev_unplug to qdev_unplug_req Liu Ping Fan
2012-08-24 14:48 ` Paolo Bonzini
2012-08-24 9:49 ` [Qemu-devel] [PATCH 09/10] mon: release dev's ref hold by qdev_get_peripheral Liu Ping Fan
2012-08-24 9:49 ` [Qemu-devel] [PATCH 10/10] qdev: fix create in place obj's life cycle problem Liu Ping Fan
2012-08-24 14:42 ` Paolo Bonzini
2012-08-25 7:42 ` liu ping fan
2012-08-27 7:01 ` Paolo Bonzini
2012-08-27 7:47 ` Jan Kiszka
2012-08-27 8:17 ` liu ping fan
2012-08-27 8:27 ` Jan Kiszka
2012-08-27 17:09 ` Avi Kivity
2012-08-27 17:14 ` Jan Kiszka
2012-08-27 18:09 ` Avi Kivity
2012-08-27 18:17 ` Jan Kiszka
2012-08-27 18:20 ` Avi Kivity
2012-08-27 18:39 ` Jan Kiszka
2012-08-27 18:52 ` Avi Kivity
2012-08-27 19:38 ` Jan Kiszka
2012-08-27 20:53 ` Avi Kivity
2012-08-28 1:01 ` Jan Kiszka
2012-08-29 17:13 ` Avi Kivity
2012-08-29 17:21 ` Jan Kiszka
2012-08-29 17:27 ` Avi Kivity
2012-08-29 17:41 ` Jan Kiszka
2012-09-03 9:09 ` Avi Kivity
2012-08-28 3:09 ` liu ping fan
2012-08-28 3:38 ` liu ping fan
2012-08-28 9:42 ` Jan Kiszka
2012-08-28 10:05 ` Paolo Bonzini
2012-08-29 17:23 ` Avi Kivity
2012-08-29 17:30 ` Jan Kiszka
2012-08-29 17:40 ` Avi Kivity
2012-08-29 17:49 ` Jan Kiszka
2012-09-01 8:31 ` Avi Kivity
2012-09-01 8:57 ` Jan Kiszka
2012-09-01 9:30 ` Avi Kivity
2012-08-30 5:54 ` liu ping fan
2012-08-30 7:08 ` Jan Kiszka
2012-08-30 7:47 ` liu ping fan
2012-09-01 8:46 ` Avi Kivity
2012-09-03 7:44 ` liu ping fan
2012-09-03 8:52 ` Avi Kivity
2012-09-03 10:06 ` liu ping fan
2012-09-03 10:16 ` Avi Kivity
2012-09-04 2:33 ` liu ping fan
2012-09-04 2:34 ` liu ping fan
2012-09-05 8:19 ` liu ping fan
2012-09-05 9:52 ` Avi Kivity [this message]
2012-09-05 10:36 ` Jan Kiszka
2012-09-05 10:53 ` Avi Kivity
2012-09-05 11:11 ` Jan Kiszka
2012-09-05 11:25 ` Avi Kivity
2012-09-05 12:02 ` Jan Kiszka
2012-09-05 12:17 ` Avi Kivity
2012-08-27 13:19 ` Anthony Liguori
2012-08-27 15:02 ` Jan Kiszka
2012-08-27 15:14 ` Anthony Liguori
2012-08-27 15:26 ` Jan Kiszka
2012-08-27 16:24 ` Anthony Liguori
2012-08-27 16:59 ` Jan Kiszka
2012-08-27 18:35 ` Avi Kivity
2012-08-27 19:17 ` Anthony Liguori
2012-08-27 19:22 ` Jan Kiszka
2012-08-27 20:58 ` Avi Kivity
2012-08-27 21:34 ` Paolo Bonzini
2012-08-27 18:27 ` 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=504720F8.9020104@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=jan.kiszka@siemens.com \
--cc=pbonzini@redhat.com \
--cc=pingfank@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemulist@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).