qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	BALATON Zoltan <balaton@eik.bme.hu>,
	qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Joelle van Dyne <j@getutm.app>
Subject: Re: Display update issue on M1 Macs
Date: Sat, 14 Jan 2023 11:41:19 +0900	[thread overview]
Message-ID: <28025639-840a-1e19-01d5-c817235ca423@gmail.com> (raw)
In-Reply-To: <3bad40aa-7920-0484-ca23-b9d424ad56f6@eik.bme.hu>

On 2023/01/13 22:43, BALATON Zoltan wrote:
> On Thu, 5 Jan 2023, BALATON Zoltan wrote:
>> Hello,
>>
>> I got reports from several users trying to run AmigaOS4 on sam460ex on 
>> Apple silicon Macs that they get missing graphics that I can't 
>> reproduce on x86_64. With help from the users who get the problem 
>> we've narrowed it down to the following:
>>
>> It looks like that data written to the sm501's ram in 
>> qemu/hw/display/sm501.c::sm501_2d_operation() is then not seen from 
>> sm501_update_display() in the same file. The sm501_2d_operation() 
>> function is called when the guest accesses the emulated card so it may 
>> run in a different thread than sm501_update_display() which is called 
>> by the ui backend but I'm not sure how QEMU calls these. Is device 
>> code running in iothread and display update in main thread? The 
>> problem is also independent of the display backend and was reproduced 
>> with both -display cocoa and -display sdl.
>>
>> We have confirmed it's not the pixman routines that 
>> sm501_2d_operation() uses as the same issue is seen also with QEMU 4.x 
>> where pixman wasn't used and with all versions up to 7.2 so it's also 
>> not some bisectable change in QEMU. It also happens with 
>> --enable-debug so it doesn't seem to be related to optimisation either 
>> and I don't get it on x86_64 but even x86_64 QEMU builds run on Apple 
>> M1 with Rosetta 2 show the problem. It also only seems to affect 
>> graphics written from sm501_2d_operation() which AmigaOS4 uses 
>> extensively but other OSes don't and just render graphics with the 
>> vcpu which work without problem also on the M1 Macs that show this 
>> problem with AmigaOS4. Theoretically this could be some missing 
>> syncronisation which is something ARM and PPC may need while x86 
>> doesn't but I don't know if this is really the reason and if so where 
>> and how to fix it). Any idea what may cause this and what could be a 
>> fix to try?
> 
> Any idea anyone? At least some explanation if the above is plausible or 
> if there's an option to disable the iothread and run everyting in a 
> single thread to verify the theory could help. I've got reports from at 
> least 3 people getting this problem but I can't do much to fix it 
> without some help.
> 
>> (Info on how to run it is here:
>> http://zero.eik.bme.hu/~balaton/qemu/amiga/#amigaos
>> but AmigaOS4 is not freely distributable so it's a bit hard to 
>> reproduce. Some Linux X servers that support sm501/sm502 may also use 
>> the card's 2d engine but I don't know about any live CDs that readily 
>> run on sam460ex.)
>>
>> Thank you,
>> BALATON Zoltan

Sorry, I missed the email.

Indeed the ui backend should call sm501_update_display() in the main 
thread, which should be different from the thread calling 
sm501_2d_operation(). However, if I understand it correctly, both of the 
functions should be called with iothread lock held so there should be no 
race condition in theory.

But there is an exception: memory_region_snapshot_and_clear_dirty() 
releases iothread lock, and that broke raspi3b display device:
https://lore.kernel.org/qemu-devel/CAFEAcA9odnPo2LPip295Uztri7JfoVnQbkJ=Wn+k8dQneB_ynQ@mail.gmail.com/T/

It is unexpected that gfx_update() callback releases iothread lock so it 
may break things in peculiar ways.

Peter, is there any change in the situation regarding the race 
introduced by memory_region_snapshot_and_clear_dirty()?

For now, to workaround the issue, I think you can create another mutex 
and make the entire sm501_2d_engine_write() and sm501_update_display() 
critical sections.

Regards,
Akihiko Odaki


  reply	other threads:[~2023-01-14  2:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 23:24 Display update issue on M1 Macs BALATON Zoltan
2023-01-13 13:43 ` BALATON Zoltan
2023-01-14  2:41   ` Akihiko Odaki [this message]
2023-01-14 18:11     ` BALATON Zoltan
2023-01-19 13:10       ` Akihiko Odaki
2023-01-22 23:28         ` BALATON Zoltan
2023-01-28  4:01           ` Akihiko Odaki
2023-01-30 23:58             ` BALATON Zoltan
2023-01-31  7:37               ` Akihiko Odaki
2023-01-31 14:15                 ` BALATON Zoltan
2023-02-02 10:51                   ` BALATON Zoltan
2023-02-03 10:16                     ` Akihiko Odaki
2023-02-03 13:45                       ` BALATON Zoltan
2023-02-04  5:19                         ` Akihiko Odaki

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=28025639-840a-1e19-01d5-c817235ca423@gmail.com \
    --to=akihiko.odaki@gmail.com \
    --cc=balaton@eik.bme.hu \
    --cc=j@getutm.app \
    --cc=kraxel@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).