All of lore.kernel.org
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH] hw/acpi: Set memory regions to native endian as a work around
Date: Tue, 7 Mar 2023 16:21:30 +0100 (CET)	[thread overview]
Message-ID: <f16d495e-3f7b-d253-601f-c2566c49e521@eik.bme.hu> (raw)
In-Reply-To: <357c8c40-8b16-d53c-c453-b8cebe4a312f@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3331 bytes --]

On Tue, 7 Mar 2023, Paolo Bonzini wrote:
> On 3/7/23 13:54, BALATON Zoltan wrote:
>>> evt 3 1 write 1      // enable timer
>>> evt 0 2 read
>>> evt 0 2 write 1      // just writes again the same value, clearing sts
>>> 
>>> I am quite confident that the second guess is correct, because "write the 
>>> same value that was read" only makes sense for evt_sts and not for evt_en.
>> 
>> It could also make sense if the guest is trying to flip a bit that's 
>> already set or cleared.
>
> No, I checked what the guest actually does and it's read followed immediately 
> by a write, with no other ALU values in the middle.
>
>> AFAIU the device is little endian (VT8231 is a PCI device and primarily a 
>> PC part so it's expected to be little endian) but the guest also knows this 
>> and writes byte swaped values to it. But since the memory region is set to 
>> LITTLE_ENDIAN and we're on a big endian CPU QEMU will byte swap it again 
>> which it should not do as the guest already did that.
>
> It's the opposite.
>
> The CPU first swaps the value that was in the register, when it executes 
> sthbrx instructions.  With DEVICE_LITTLE_ENDIAN, QEMU does the second swap 
> and restores the value that was in the register.  With DEVICE_NATIVE_ENDIAN 
> it happens to fix the cases that matter for your testcase, but it breaks 
> others.
>
>>> This means that the first write is almost certainly to evt_en.  On a 
>>> little-endian machine the write would set bit 8 of evt.en (power button), 
>>> but what about a big-endian machine like yours?  Should it set bit 0 or 
>>> bit 8? If it's bit 0 (which resides at offset 2 according to the device), 
>>> who flips the low bit of the address?  Why is bit 0 flipped but not bit 1?
>> 
>> I think the guest already writes byte swapped value so it should work the 
>> same as on little endian machine but the QEMU memory layer gets in the way.
>
> The write in question is "evt addr=3 size=1 value=1" so it's a one-byte 
> write.  There's no byte swapping involved here, rather the question is how 
> the addresses are interpreted.
>
>>> - get a real machine, and figure out whether the write to offset 3 
>>> corresponds to the PM timer or the power button.
>> 
>> I don't have real machine but know somebody who does but I'm not sure what 
>> to ast to test on it. Can you describe it what you want to see or maybe 
>> write a sctipt for the fimrware to test it (if you're familiar enough with 
>> Forth for that). I can try to find some more info on this but so far I was 
>> concentrating on other bigger issues. This is a minor annoyance but would 
>> be nice to fix eventually.
>
> I didn't even have an idea that Forth was involved, honestly, or how to write 
> Forth code for this machine that I barely know exists. :)

It's supposed to be CHRP compatible which mandates OpenFirmware so it 
should work about the same as similar IBM and Apple machines but those are 
also kind of obscure. If you can describe what you want tested I can try 
to make that a script and ask somebody to run it on real machine but I'm 
not sure what to test.

Regards,
BALATON Zoltan

>>> - continue the trace up to the point the OS runs, and see if you get some 
>>> clues similar to the one above that placed evt_sts at offset 2.
>
> I'll try this once the machine is back in shape.
>
> Paolo
>
>

  reply	other threads:[~2023-03-07 15:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 13:05 [PATCH] hw/acpi: Set memory regions to native endian as a work around BALATON Zoltan
2021-11-08 13:32 ` Michael S. Tsirkin
2021-11-08 15:22   ` BALATON Zoltan
2021-12-16 10:27   ` Michael S. Tsirkin
2021-11-08 14:30 ` Paolo Bonzini
2021-11-08 15:04   ` Paolo Bonzini
2021-11-08 15:16     ` BALATON Zoltan
2021-11-13 18:47       ` BALATON Zoltan
2022-01-19  9:19         ` Michael S. Tsirkin
2022-02-22 14:40           ` Michael S. Tsirkin
2023-02-20 18:24             ` BALATON Zoltan
2023-02-20 22:33               ` Michael S. Tsirkin
2023-02-20 23:25                 ` BALATON Zoltan
2023-02-21  8:30                   ` Paolo Bonzini
2023-02-21 12:48                     ` BALATON Zoltan
2023-02-21 12:55                       ` BALATON Zoltan
2023-03-06 22:56                         ` Paolo Bonzini
2023-03-06 23:11                           ` BALATON Zoltan
2023-03-06 23:36                           ` Paolo Bonzini
2023-03-07  0:06                             ` BALATON Zoltan
2023-03-07  5:58                               ` Paolo Bonzini
2023-03-07 10:01                                 ` BALATON Zoltan
2023-03-07 11:26                                   ` Paolo Bonzini
2023-03-07 12:54                                     ` BALATON Zoltan
2023-03-07 15:14                                       ` Paolo Bonzini
2023-03-07 15:21                                         ` BALATON Zoltan [this message]
2023-03-07 16:48                                           ` Paolo Bonzini
2023-04-30 23:10                                     ` BALATON Zoltan
2023-04-30 23:26                                       ` BALATON Zoltan
2023-02-21 14:02                       ` Paolo Bonzini
2023-03-02 13:42                         ` BALATON Zoltan
2023-03-06 18:34                           ` Michael S. Tsirkin
2023-03-03  8:22                         ` Michael S. Tsirkin
2023-03-11 20:59                     ` Michael S. Tsirkin

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=f16d495e-3f7b-d253-601f-c2566c49e521@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --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.