From: Paolo Bonzini <pbonzini@redhat.com>
To: "Xu, Anthony" <anthony.xu@intel.com>
Cc: "Zhong, Yang" <yang.zhong@intel.com>,
"Peng, Chao P" <chao.p.peng@intel.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v1 2/2] reduce qemu's heap Rss size from 12252kB to 2752KB
Date: Wed, 22 Mar 2017 12:46:21 +0100 [thread overview]
Message-ID: <b23eb236-6f32-fb2b-1a61-a831053e277b@redhat.com> (raw)
In-Reply-To: <4712D8F4B26E034E80552F30A67BE0B1A19A11@ORSMSX112.amr.corp.intel.com>
On 16/03/2017 21:02, Xu, Anthony wrote:
>>> memory_region_finalize.
>>> Let me know if you think otherwise.
>>
>> Yes, you can replace memory_region_del_subregion in
>> memory_region_finalize
>> with special code that does
>>
>> assert(!mr->enabled);
>> assert(subregion->container == mr);
>> subregion->container = NULL;
>> QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link);
>> memory_region_unref(subregion);
>>
>> The last four lines are shared with memory_region_del_subregion, so please
>> factor them in a new function, for example
>> memory_region_del_subregion_internal.
>
> After adding synchronize_rcu, I saw an infinite recursive call,
> mem_commit-> memory_region_finalize-> mem_commit->
> memory_region_finalize-> ......
> it caused a segment fault, because 8M stack space is used up, and found when
> memory_region_finalize is called, memory_region_transaction_depth is 0 and
> memory_region_update_pending is true. That's not normal!
Ok, this is a bug. This would fix it:
> Please review below patch
>
> diff --git a/memory.c b/memory.c
> index 64b0a60..4c95aaf 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -906,12 +906,6 @@ void memory_region_transaction_begin(void)
> ++memory_region_transaction_depth;
> }
>
> -static void memory_region_clear_pending(void)
> -{
> - memory_region_update_pending = false;
> - ioeventfd_update_pending = false;
> -}
> -
> void memory_region_transaction_commit(void)
> {
> AddressSpace *as;
> @@ -927,14 +921,14 @@ void memory_region_transaction_commit(void)
> QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> address_space_update_topology(as);
> }
> -
> + memory_region_update_pending = false;
> MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
> } else if (ioeventfd_update_pending) {
> QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
> address_space_update_ioeventfds(as);
> }
> + ioeventfd_update_pending = false;
> }
> - memory_region_clear_pending();
> }
> }
So please send it to the list with Signed-off-by line.
> The thing is, seems both address_space_translate and address_space_dispatch_free
> are called under the global lock. When synchronize_rcu is called, no other threads
> are in RCU critical section.
No, not necessarily. address_space_write for example is called outside
the global lock by KVM and it calls address_space_translate.
> Seems RCU is not that useful for address space.
I suggest that you study the code more closely... there is this in
kvm-all.c:
DPRINTF("handle_mmio\n");
/* Called outside BQL */
address_space_rw(&address_space_memory,
run->mmio.phys_addr, attrs,
run->mmio.data,
run->mmio.len,
run->mmio.is_write);
and adding a simple assert() would have quickly disproved your theory.
> After adding synchronize_rcu, we noticed a RCU dead loop. synchronize_rcu is called
> inside RCU critical section. It happened when guest OS programmed the PCI bar.
> The call trace is like,
> address_space_write-> pci_host_config_write_common ->
> memory_region_transaction_commit ->mem_commit-> synchronize_rcu
> pci_host_config_write_common is called inside RCU critical section.
>
> The address_space_write change fixed this issue.
It's not a fix if the code is not thread-safe anymore! But I think you
have the answer now as to why you cannot use synchronize_rcu.
Paolo
next prev parent reply other threads:[~2017-03-22 11:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-10 15:14 [Qemu-devel] [PATCH v1 1/2] reduce qemu's heap Rss size from 12252kB to 2752KB Yang Zhong
2017-03-10 8:41 ` Paolo Bonzini
2017-03-10 16:05 ` Xu, Anthony
2017-03-10 16:07 ` Paolo Bonzini
2017-03-10 19:30 ` Xu, Anthony
2017-03-11 17:02 ` Paolo Bonzini
2017-03-10 15:14 ` [Qemu-devel] [PATCH v1 2/2] " Yang Zhong
2017-03-10 9:14 ` Paolo Bonzini
2017-03-10 17:40 ` Xu, Anthony
2017-03-11 17:04 ` Paolo Bonzini
2017-03-14 5:14 ` Xu, Anthony
2017-03-14 10:14 ` Paolo Bonzini
2017-03-14 21:23 ` Xu, Anthony
2017-03-15 8:36 ` Paolo Bonzini
2017-03-15 19:05 ` Xu, Anthony
2017-03-15 20:21 ` Paolo Bonzini
2017-03-16 2:47 ` Zhong, Yang
2017-03-16 20:02 ` Xu, Anthony
2017-03-22 11:46 ` Paolo Bonzini [this message]
2017-03-22 18:26 ` Xu, Anthony
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=b23eb236-6f32-fb2b-1a61-a831053e277b@redhat.com \
--to=pbonzini@redhat.com \
--cc=anthony.xu@intel.com \
--cc=chao.p.peng@intel.com \
--cc=qemu-devel@nongnu.org \
--cc=yang.zhong@intel.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).