All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: liu ping fan <qemulist@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>
Subject: Re: [Qemu-devel] memory: could we add extra input param for memory_region_init_io()?
Date: Tue, 21 Aug 2012 13:13:36 +0300	[thread overview]
Message-ID: <50335F50.9080104@redhat.com> (raw)
In-Reply-To: <CAJnKYQkRMNfLwEJxATNEjVh=TXFR+1YkLWQ7QPyhzSY3V+vp2g@mail.gmail.com>

On 08/21/2012 12:25 PM, liu ping fan wrote:
> On Tue, Aug 21, 2012 at 4:57 PM, Avi Kivity <avi@redhat.com> wrote:
>> On 08/21/2012 07:48 AM, liu ping fan wrote:
>>> On Sun, Aug 19, 2012 at 7:36 PM, Avi Kivity <avi@redhat.com> wrote:
>>>> On 08/19/2012 02:23 PM, Peter Maydell wrote:
>>>>> On 19 August 2012 11:12, Avi Kivity <avi@redhat.com> wrote:
>>>>>> On 08/17/2012 10:41 AM, liu ping fan wrote:
>>>>>>> And something like omap_mpu_timer_init() in file hw/omap1.c , the
>>>>>>> opaque(omap_mpu_timer_s) is got from g_malloc0, which makes things
>>>>>>> even harder to handle.  And the DO_CAST can not work for such issue.
>>>>>>
>>>>>> IMO omap_mpu_timer_s should be a DeviceState.  Peter?
>>>>>
>>>>> Ideally, yes, but qemu is full of devices that haven't yet made the leap
>>>>> to QOM.
>>>>>
>>>>> omap1 is particularly tricky because I don't actually have any test images
>>>>> for it, so refactoring it is a leap in the dark. [I've tried asking on this list
>>>>> if anybody had test images a couple of times without success.]
>>>>
>>>> Okay.  Most of the options in this thread don't involve wholesale
>>>> conversion of the opaque parameter in memory_region_init_io() to type
>>>> Object *, so it's not necessary to convert everything.
>>>>
>>> But I think if the mr belongs to mem address space, it can not avoid
>>> object_ref(Object *opaque) in mmio-dispatch code. ( If we use extra
>>> flag to indicate whether the opaque is Object or not, then we lose the
>>> meaning to transfer opaque to Object type, and maybe
>>> memory_region_set_object() is a better choice).
>>
>> I'm not sure I understand.  What do you mean by "ability to transfer
>> opaque to Object type"?
>>
> Maybe I misunderstand your meaning of "Okay.  Most of the options in
> this thread don't involve wholesale ..., so it's not necessary to
> convert everything"
> I think you mean that "omap_mpu_timer_s" need NOT to convert.  

That is what I meant.

> But as
> it will also take the code path which has object_ref(Object*), so it
> has to convert, otherwise the code will corrupt.
> That is what I want to express.

Option 2, for example, had MemoryRegionOps::object(MemoryRegion *) which
can be used to convert the opaque to an Object, or return NULL.  With
that option, there would be no corruption:

  qemu_mutex_lock(&mem_map_lock);
  MemoryRegionSection mrs = walk(&phys_map);
  Object *object = mrs.mr->ops->object(mrs.mr);
  if (object) {
      object_ref(object);
  }
  qemu_mutex_unlock(&mem_map_unlock);

So there is no memory corruption.  However, as I point out below, we
also lack the reference count.  Maybe we could do something like:

  qemu_mutex_lock(&mem_map_lock);
  MemoryRegionSection mrs = walk(&phys_map);
  Object *object = mrs.mr->ops->object(mrs.mr);
  if (object) {
      object_ref(object);
  } else {
      goto retry_with_qemu_lock_held;
  }
  qemu_mutex_unlock(&mem_map_unlock);

But that's very inelegant.

>>
>> Agree.  The best example is device assignment, where BARs will need to
>> turn into Objects.  It means that an assigned device can disappear while
>> one of its BARs remain, so the code will have to handle this case.
>>
> How about the initialization of BAR inc ref of assigned device; and
> finalization of BAR dec it?

If we can avoid a cycle.  Won't the device need to hold refs to the BAR?
>> Unfortunately, requiring a 1:1 opaque:Object relationship means huge
>> churn in the code.  But I don't think it can be avoided, even with
>> memory_region_set_object().
>>
> Yeah, and I am studying the different case to see how to resolve and
> make plans about the huge conversion.

Ok.  One one hand, I think the conversion is unavoidable, and is also
beneficial: I never liked opaques.

On the other hand, those conversions are very tedious, introduce
regressions, and delay the result.

Anthony, any insight on this?

-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-08-21 10:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14  8:30 [Qemu-devel] memory: could we add extra input param for memory_region_init_io()? liu ping fan
2012-08-14 10:49 ` Avi Kivity
2012-08-16  3:22   ` liu ping fan
2012-08-16  9:23     ` Avi Kivity
2012-08-17  2:52       ` liu ping fan
2012-08-17  7:41         ` liu ping fan
2012-08-19 10:12           ` Avi Kivity
2012-08-19 11:23             ` Peter Maydell
2012-08-19 11:36               ` Avi Kivity
2012-08-21  4:48                 ` liu ping fan
2012-08-21  8:57                   ` Avi Kivity
2012-08-21  9:25                     ` liu ping fan
2012-08-21 10:13                       ` Avi Kivity [this message]
2012-08-21 11:18                         ` liu ping fan
2012-08-21 12:41                           ` Avi Kivity
2012-08-24  9:47                             ` liu ping fan
2012-08-19 12:03               ` Peter Maydell
2012-08-19 13:05                 ` Blue Swirl
2012-08-19 10:10         ` 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=50335F50.9080104@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.