From: Fabiano Rosas <farosas@suse.de>
To: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Elliot Berman" <elliotjb+anduril@elliotjb.com>,
qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-block@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH] hw/block/pflash: invalidate TBs on flash update
Date: Mon, 26 Oct 2026 18:02:34 -0300 [thread overview]
Message-ID: <87wlr4jhud.fsf@suse.de> (raw)
In-Reply-To: <f54905bf-8641-4554-ac44-6d526266876c@oss.qualcomm.com>
Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:
> Hi Elliot,
>
> On 16/10/26 21:15, Elliot Berman wrote:
>> When pflash_cfi01/02 are out of Read Array mode and being reprogrammed
>> or erased (such as a firmware update) by a guest under TCG, TBs from
>> when the guest was executing instructions from the pflash are never
>> invalidated. After re-enabling Read Array, the guest continues to
>> execute instructions from the stale TBs.
>>
>> Call memory_region_flush_rom_device() from pflash_update() so the TBs
>> over the updated range are invalidated.
>>
>> memory_region_flush_rom_device() asserted that the memory region was in
>> romd_mode (i.e. Read Array mode), but the pflash is not in romd_mode
>> when processing MemoryRegionOps->write() commands. Since the RAM can
>> change even when !romd_mode, relax the assertion so it only checks
>> rom_device.
>>
>> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4490
>> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
>> Signed-off-by: Elliot Berman <elliotjb+anduril@elliotjb.com>
>> ---
>> hw/block/pflash_cfi01.c | 5 ++++-
>> hw/block/pflash_cfi02.c | 3 +++
>> system/physmem.c | 2 +-
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>> index 486fc6350d..66ecdb0969 100644
>> --- a/hw/block/pflash_cfi01.c
>> +++ b/hw/block/pflash_cfi01.c
>> @@ -388,12 +388,15 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset,
>> return ret;
>> }
>>
>> -/* update flash content on disk */
>> +/* update flash content on disk and invalidate the guest view of RAM */
>
> /*
> * Flush modified flash content: mark the range dirty, invalidate the
> * TBs translated from it, and write it back to the block backend.
> */
>
>> static void pflash_update(PFlashCFI01 *pfl, int offset,
>> int size)
>> {
>> int offset_end;
>> int ret;
>> +
>> + memory_region_flush_rom_device(&pfl->mem, offset, size);
>> +
>> if (pfl->blk) {
>> offset_end = offset + size;
>> /* widen to sector boundaries */
>
> I'd like feedback from migration maintainers: could we be writing
> staled content during live migration? Or maybe we are already safe.
> invalidate_and_set_dirty() gets DIRTY_MEMORY_MIGRATION set via the
> memory_region_get_dirty_log_mask call. Hmm so this change also fixes
> migration then. If confirmed, worth mentioning in the patch description:
>
>
> Direct writes to the flash RAM were not marked dirty for migration,
> so pages reprogrammed during pre-copy were not re-sent, and
> postload_update_cb() wrote the stale content to the block backend.
> The memory_region_flush_rom_device() call now also fixes this.
>
Yes, this does seem to be the case. I couldn't find any path where the
writes from pflash_write() are invalidated.
next prev parent reply other threads:[~2026-10-26 21:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 19:15 [PATCH] hw/block/pflash: invalidate TBs on flash update Elliot Berman
2026-10-26 6:03 ` Philippe Mathieu-Daudé
2026-10-26 21:02 ` Fabiano Rosas [this message]
2026-10-27 3:30 ` Philippe Mathieu-Daudé
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=87wlr4jhud.fsf@suse.de \
--to=farosas@suse.de \
--cc=alex.bennee@linaro.org \
--cc=elliotjb+anduril@elliotjb.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-block@nongnu.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.