From: Frederic Konrad <fred.konrad@greensocs.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org,
mark.burton@greensocs.com, qemu-devel@nongnu.org,
alistair.francis@xilinx.com, clg@kaod.org
Subject: Re: [Qemu-devel] [RFC 4/5] exec: allow to get a pointer for some mmio memory region
Date: Sat, 4 Feb 2017 14:59:35 +0100 [thread overview]
Message-ID: <d81969f9-1e64-22ff-80eb-e5da72f8ad76@greensocs.com> (raw)
In-Reply-To: <14c737f4-b965-a1b8-ba3c-003e5fa9e3fd@redhat.com>
On 02/04/2017 01:41 PM, Paolo Bonzini wrote:
>
...
>>
>> Doesn't hotplug use dynamic MemoryRegion? In which case we better
>> make that work with MTTCG. I wonder if we can't simply handle that
>> with a safe_work for this case?
>
> Hot-unplug works because the backing memory is only freed when the
> device gets instance_finalize, so at that point the region cannot have
> any references.
>
> What can go wrong is the following (from the docs):
>
> - the memory region's owner had a reference taken via memory_region_ref
> (for example by address_space_map)
>
> - the region is unparented, and has no owner anymore
>
> - when address_space_unmap is called, the reference to the memory
> region's owner is leaked.
true.
>
> In your case you have phys_section_add/phys_section_destroy instead of
> address_space_map/unmap, but the problem is the same.
>
> I am a bit unsure about using the same lqspi_buf for caching different
> addresses, and about using the same buffer for MMIO execution and read.
> What if you allocate a different buffer every time
> lqspi_request_mmio_ptr is called (adding a char* argument to
> lqspi_load_cache) and free the old one from the safe_work item, after a
> global TLB flush? Then you don't need the Notifiers which were the
> complicated and handwavy part of my proposal.
Actually this was just because it was the way xilinx_qspi worked.
It load 1K of SPI data and fill the buffer.
In some other case we don't want to free the pointer at all, just make
it not accessible for execution / read.
(BTW I'll add the read-only property to this).
What about a simple Object eg: mmio-execution-interface which has a
MemoryRegion? Instead of creating the MemoryRegion in request_pointer,
We create a mmio-execution-interface object which create and map the
region on the subregion.
Then in invalidate: we unplug the mmio-execution-interface, unref it and
it is freed all by magic when the map doesn't need it.
This avoid the reference issue and probably the bug with MTTCG.
Fred
>
> Paolo
>
>>
>> BTW the tests I have seems to pass without issues.
>>
>>>
>>> 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)
>>
>> I'm not aware of this MemoryRegionCache yet, it seems pretty new.
>> I'll take a look.
>>
>> Thanks,
>> Fred
>>
>>>
>>> - 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.
>>>
>>> I like the general idea though!
>>>
>>> Paolo
>>>
>>>> + }
>>>> +}
>>
>>
>>
next prev parent reply other threads:[~2017-02-04 13:59 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 [this message]
2017-02-07 9:52 ` Frederic Konrad
2017-02-04 11:50 ` Edgar E. Iglesias
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=d81969f9-1e64-22ff-80eb-e5da72f8ad76@greensocs.com \
--to=fred.konrad@greensocs.com \
--cc=alistair.francis@xilinx.com \
--cc=clg@kaod.org \
--cc=edgar.iglesias@xilinx.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 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).