From: Stefan Hajnoczi <stefanha@redhat.com>
To: Keqian Zhu <zhukeqian1@huawei.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Fam Zheng <famz@redhat.com>,
kuhn.chenqun@huawei.com, qemu-devel@nongnu.org,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
qemu-arm@nongnu.org, wanghaibin.wang@huawei.com,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 1/2] ramlist: Make dirty bitmap blocks of ramlist resizable
Date: Thu, 17 Dec 2020 10:05:01 +0000 [thread overview]
Message-ID: <20201217100501.GE4338@stefanha-x1.localdomain> (raw)
In-Reply-To: <20201130131104.10600-2-zhukeqian1@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]
On Mon, Nov 30, 2020 at 09:11:03PM +0800, Keqian Zhu wrote:
> @@ -1839,15 +1841,26 @@ static void dirty_memory_extend(ram_addr_t old_ram_size,
> new_blocks = g_malloc(sizeof(*new_blocks) +
> sizeof(new_blocks->blocks[0]) * new_num_blocks);
>
> - if (old_num_blocks) {
> + if (cpy_num_blocks) {
> memcpy(new_blocks->blocks, old_blocks->blocks,
> - old_num_blocks * sizeof(old_blocks->blocks[0]));
> + cpy_num_blocks * sizeof(old_blocks->blocks[0]));
> }
>
> - for (j = old_num_blocks; j < new_num_blocks; j++) {
> - new_blocks->blocks[j] = bitmap_new(DIRTY_MEMORY_BLOCK_SIZE);
> + if (extend) {
> + for (j = cpy_num_blocks; j < new_num_blocks; j++) {
> + new_blocks->blocks[j] = bitmap_new(DIRTY_MEMORY_BLOCK_SIZE);
> + }
> + } else {
> + for (j = cpy_num_blocks; j < old_num_blocks; j++) {
> + /* We are safe to free it, for that it is out-of-use */
> + g_free(old_blocks->blocks[j]);
This looks unsafe because this code uses Read Copy Update (RCU):
old_blocks = qatomic_rcu_read(&ram_list.dirty_memory[i]);
Other threads may still be accessing old_blocks so we cannot modify it
immediately. Changes need to be deferred until the next RCU period.
g_free_rcu() needs to be used to do this.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-12-18 17:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 13:11 [PATCH v2 0/2] bugfix: Decrease dirty bitmap blocks after we remove ramblock Keqian Zhu
2020-11-30 13:11 ` [PATCH v2 1/2] ramlist: Make dirty bitmap blocks of ramlist resizable Keqian Zhu
2020-12-17 10:05 ` Stefan Hajnoczi [this message]
2020-12-21 7:37 ` Keqian Zhu
2020-12-26 7:11 ` Keqian Zhu
2021-03-08 10:52 ` Stefan Hajnoczi
2020-11-30 13:11 ` [PATCH v2 2/2] ramlist: Resize dirty bitmap blocks after remove ramblock Keqian Zhu
2020-12-03 14:02 ` Ping: [PATCH v2 0/2] bugfix: Decrease dirty bitmap blocks after we " zhukeqian
2020-12-17 10:09 ` Stefan Hajnoczi
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=20201217100501.GE4338@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=dgilbert@redhat.com \
--cc=famz@redhat.com \
--cc=kuhn.chenqun@huawei.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wanghaibin.wang@huawei.com \
--cc=zhukeqian1@huawei.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).