qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: ksourav <sourav.jb1988@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Thomas Huth <thuth@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	qemu-arm <qemu-arm@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-arm] object owner argument of memory_region_init_ram
Date: Wed, 23 Jan 2019 21:20:10 +0530	[thread overview]
Message-ID: <CAAJhNeta4fWX7y-ap-CSUhrHDGrZH_Xss6tyDa6=vn_uUJSk0Q@mail.gmail.com> (raw)
In-Reply-To: <CAFEAcA8jvRRpphFS7jvisU+f0SEvU1DOhrBxgKSRWEMkZV3eOw@mail.gmail.com>

Thanks for the reply.
Should I send patches for socs using NULL owner to qemu-trivial@nongnu.org ?

I have been reading qemu source code for soc and different device
implementation for past few days to understand qemu internals.
While I have a rough idea of qemu object model, I would like to have your input.
If someone has to learn about qemu object model or soc implementation,
what would be the correct way ?
So far I have implemented a minimal platform device and experimented
with it using linux driver on qemu. But I am wondering is there any
other way of doing things to develop understanding.

Thanks in Advance

On Wed, Jan 23, 2019 at 4:23 PM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Wed, 23 Jan 2019 at 06:10, Thomas Huth <thuth@redhat.com> wrote:
> > On 2019-01-23 04:07, ksourav wrote:
> > > I am trying to learn how qemu implements different soc.
> > > While reading the source code, I found that in some socs, object owner
> > > is passed as NULL to the routine memory_region_init_ram() (for example
> > > in nrf51 soc) and in some socs(for example in Allwinner A10) an
> > > object(non NULL) is passed to memory_region_initi_ram().
> > > When I checked docs/devel/memory.txt, I found below lines.
> > > "For regions that "have no owner" (NULL is passed at creation time), the
> > > machine object is actually used as the owner."
> > > Is the machine object refers to the actual board instance that will
> > > use the soc? For example microbit in case of nrf51 soc ?
> > > Is there any reason of not passing object as owner or in other words,
> > > when do we pass NULL or an object to memory_region_initi_ram() ?
> >
> > I'm not an expert here, but when you look at the description of
> > memory_region_init_ram() in include/exec/memory.h:
> >
> >  * @owner: the object that tracks the region's reference count (must be
> >  *         TYPE_DEVICE or a subclass of TYPE_DEVICE, or NULL)
> >
> > So if you're calling memory_region_init_ram() from a device's
> > instance_init() or realize() function, you should use the current device
> > state as owner. But if you want to call the function from a
> > MachineClass->init function instead already, you don't have a
> > DeviceState* yet, so you have to use NULL there.
>
> Yes. Also old-style boards which don't use MachineState directly
> will pass a NULL owner, as will very old non-QOM devices, and
> probably one or two devices with bugs. Don't copy those examples :-)
> (the nrf51_soc you mention above is an example of a bug.)
>
> The reason the owner matters here is so we clean things up correctly
> when the device goes away. So for a machine model it doesn't matter
> because the machine is never destroyed. For an SoC, that is also
> typically never destroyed and so bugs where the owner was not set
> easily go unnoticed. But there is a corner case where the user can
> introspect an object, which causes a temporary copy to go through
> instance_init, which can result in leaks if ownership is wrong.
>
> We really need to make sure we have a good grasp of this kind of
> thing and write it up somewhere (in particular the object life cycle,
> what can or should be done in instance_init, how things need to
> be parented to ensure there are no leaks, etc.)
>
> thanks
> -- PMM

  reply	other threads:[~2019-01-23 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23  3:07 [Qemu-devel] object owner argument of memory_region_init_ram ksourav
2019-01-23  6:10 ` Thomas Huth
2019-01-23 10:53   ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2019-01-23 15:50     ` ksourav [this message]
2019-01-25 12:40       ` Thomas Huth

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='CAAJhNeta4fWX7y-ap-CSUhrHDGrZH_Xss6tyDa6=vn_uUJSk0Q@mail.gmail.com' \
    --to=sourav.jb1988@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@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).