From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: fred.konrad@greensocs.com, qemu-devel@nongnu.org,
peter.maydell@linaro.org, alistair.francis@xilinx.com,
clg@kaod.org, mark.burton@greensocs.com
Subject: Re: [Qemu-devel] [RFC 4/5] exec: allow to get a pointer for some mmio memory region
Date: Sat, 4 Feb 2017 12:50:48 +0100 [thread overview]
Message-ID: <20170204115048.GM12995@toto> (raw)
In-Reply-To: <d64a7dfd-cb55-ba59-9731-282bb98cf20e@redhat.com>
On Fri, Feb 03, 2017 at 09:26:19AM -0800, Paolo Bonzini wrote:
>
>
> On 03/02/2017 09:06, fred.konrad@greensocs.com wrote:
> > + host = mr->ops->request_ptr(mr->opaque, addr - mr->addr, &size, &offset);
> > +
> > + if (!host || !size) {
> > + memory_region_transaction_commit();
> > + return false;
> > + }
> > +
> > + sub = g_new(MemoryRegion, 1);
> > + memory_region_init_ram_ptr(sub, OBJECT(mr), "mmio-map", size, host);
> > + memory_region_add_subregion(mr, offset, sub);
> > + memory_region_transaction_commit();
> > + return true;
> > +}
> > +
> > +void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset,
> > + unsigned size)
> > +{
> > + MemoryRegionSection section = memory_region_find(mr, offset, size);
> > +
> > + if (section.mr != mr) {
> > + memory_region_del_subregion(mr, section.mr);
> > + /* memory_region_find add a ref on section.mr */
> > + memory_region_unref(section.mr);
> > + object_unparent(OBJECT(section.mr));
>
> I think this would cause a use-after-free when using MTTCG. In general,
> creating and dropping MemoryRegions dynamically can cause bugs that are
> nondeterministic and hard to fix without rewriting everything.
>
> An alternative design could be:
>
> - memory_region_request_mmio_ptr returns a MemoryRegionCache instead of
> a pointer, so that the device can map a subset of the device (e.g. a
> single page)
>
> - memory_region_request_mmio_ptr and MemoryRegionOps.request_ptr accept
> a Notifier
>
> - the device adds the Notifier to a NotifierList. Before invalidating,
> it invokes the Notifier and empties the NotifierList.
>
> - for the TLB case, the Notifier calls tlb_flush_page.
Interesting! I totally missed the MemoryRegionCache patches. Cool concept.
I few lines about it in docs/memory.txt would have been nice too :-)
> I like the general idea though!
I think it's genial. I was expecting a solution for this to get ugly...
It solves some existing issues for us (like the QSPI one addressed in this series).
It also paves the way for certain use-cases when co-simulating with SystemC.
Nice one Fred!
Cheers,
Edgar
>
> Paolo
>
> > + }
> > +}
next prev parent reply other threads:[~2017-02-04 12:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 17:06 [Qemu-devel] [RFC 0/5] execute code from mmio area fred.konrad
2017-02-03 17:06 ` [Qemu-devel] [RFC 1/5] cputlb: cleanup get_page_addr_code to use VICTIM_TLB_HIT fred.konrad
2017-02-04 11:30 ` Edgar E. Iglesias
2017-02-04 12:16 ` Frederic Konrad
2017-02-03 17:06 ` [Qemu-devel] [RFC 2/5] cputlb: move get_page_addr_code fred.konrad
2017-02-03 17:06 ` [Qemu-devel] [RFC 3/5] cputlb: fix the way get_page_addr_code fills the tlb fred.konrad
2017-02-03 17:06 ` [Qemu-devel] [RFC 4/5] exec: allow to get a pointer for some mmio memory region fred.konrad
2017-02-03 17:26 ` Paolo Bonzini
2017-02-03 21:09 ` Frederic Konrad
2017-02-04 12:41 ` Paolo Bonzini
2017-02-04 13:59 ` Frederic Konrad
2017-02-07 9:52 ` Frederic Konrad
2017-02-04 11:50 ` Edgar E. Iglesias [this message]
2017-02-03 17:06 ` [Qemu-devel] [RFC 5/5] xilinx_spips: allow mmio execution fred.konrad
2017-02-04 12:33 ` [Qemu-devel] [RFC 0/5] execute code from mmio area Peter Maydell
2017-02-04 12:52 ` Frederic Konrad
2017-02-04 13:17 ` Peter Maydell
2017-02-04 14:01 ` Frederic Konrad
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=20170204115048.GM12995@toto \
--to=edgar.iglesias@xilinx.com \
--cc=alistair.francis@xilinx.com \
--cc=clg@kaod.org \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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 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.