From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Николай Зорин" <zorin@swemel.ru>
Cc: qemu-devel@nongnu.org, thuth@redhat.com, mst@redhat.com,
stefanha@redhat.com, kwolf@redhat.com,
marcandre.lureau@redhat.com, mark.cave-ayland@ilande.co.uk
Subject: Re: [PATCH] hw/display/tcx: use memmove instead of memcpy for overlapping blit memory regions
Date: Tue, 15 Sep 2026 17:31:28 +0100 [thread overview]
Message-ID: <aqly4GgJs7XSn3-D@redhat.com> (raw)
In-Reply-To: <da75d0f0-d98e-4e27-ac6c-c575a2d382ff@swemel.ru>
On Tue, Sep 15, 2026 at 07:20:46PM +0300, Николай Зорин wrote:
> SWSA#34e3af79-c6c2-4ad2-986f-313c1ce28e5a
^^^^^^^^^ what is this ?
I'm guessing it is a tag you're using for tracking issues, but
if so, it should be removed before sending commits upstream.
>
> In `tcx_blit_writel()`, memory copying occurs within the same video RAM
> buffers (`vram` and `vram24`) using source and destination offsets that
> can potentially overlap during blit operations.
>
> Using `memcpy()` on overlapping memory regions triggers undefined behavior
> according to the C standard. Depending on compiler optimizations, this
> can lead to graphical artifacts, memory corruption, or unexpected
> behavior in the guest system.
>
> Fix this by replacing `memcpy()` with `memmove()`, which explicitly
> guarantees safe and correct behavior when memory regions overlap.
>
> Signed-off-by: Nikolay N Zorin <zorin@swemel.ru>
> ---
> hw/display/tcx.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/display/tcx.c b/hw/display/tcx.c
> index 2cfc1e8f..fb48a199 100644
> --- a/hw/display/tcx.c
> +++ b/hw/display/tcx.c
> @@ -587,9 +587,9 @@ static void tcx_blit_writel(void *opaque, hwaddr addr,
> }
> }
> } else {
> - memcpy(&s->vram[addr], &s->vram[adsr], len);
> + memmove(&s->vram[addr], &s->vram[adsr], len);
> if (s->depth == 24) {
> - memcpy(&s->vram24[addr], &s->vram24[adsr], len * 4);
> + memmove(&s->vram24[addr], &s->vram24[adsr], len * 4);
> }
> }
> tcx_set_dirty(s, addr, len);
> --
> 2.43.0
>
>
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-09-15 16:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 16:20 [PATCH] hw/display/tcx: use memmove instead of memcpy for overlapping blit memory regions Николай Зорин
2026-09-15 16:31 ` Daniel P. Berrangé [this message]
2026-09-15 16:38 ` Николай Зорин
2026-09-15 16:50 ` Michael S. Tsirkin
2026-09-18 13:14 ` Mark Cave-Ayland
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=aqly4GgJs7XSn3-D@redhat.com \
--to=berrange@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
--cc=zorin@swemel.ru \
/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.