* [Qemu-devel] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas
@ 2019-06-12 2:07 Alexey Kardashevskiy
2019-06-12 6:07 ` David Gibson
2019-06-17 8:25 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
0 siblings, 2 replies; 5+ messages in thread
From: Alexey Kardashevskiy @ 2019-06-12 2:07 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexey Kardashevskiy, qemu-ppc, David Gibson
At the moment the rtas's Makefile uses generic QEMU rules which means
that when QEMU is compiled on a little endian system, the spapr-rtas.bin
is compiled as little endian too which is incorrect as it is always
executed in big endian mode.
This enforces -mbig by defining %.o:%.S rule as spapr-rtas.bin is
a standalone guest binary which should not depend on QEMU flags anyway.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
pc-bios/spapr-rtas/Makefile | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/pc-bios/spapr-rtas/Makefile b/pc-bios/spapr-rtas/Makefile
index f26dd428b79e..4b9bb1230658 100644
--- a/pc-bios/spapr-rtas/Makefile
+++ b/pc-bios/spapr-rtas/Makefile
@@ -14,8 +14,11 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/spapr-rtas)
build-all: spapr-rtas.bin
+%.o: %.S
+ $(call quiet-command,$(CCAS) -mbig -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
+
%.img: %.o
- $(call quiet-command,$(CC) -nostdlib -o $@ $<,"Building","$(TARGET_DIR)$@")
+ $(call quiet-command,$(CC) -nostdlib -mbig -o $@ $<,"Building","$(TARGET_DIR)$@")
%.bin: %.img
$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"Building","$(TARGET_DIR)$@")
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas
2019-06-12 2:07 [Qemu-devel] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas Alexey Kardashevskiy
@ 2019-06-12 6:07 ` David Gibson
2019-06-17 8:25 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2019-06-12 6:07 UTC (permalink / raw)
To: Alexey Kardashevskiy; +Cc: qemu-ppc, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]
On Wed, Jun 12, 2019 at 12:07:23PM +1000, Alexey Kardashevskiy wrote:
> At the moment the rtas's Makefile uses generic QEMU rules which means
> that when QEMU is compiled on a little endian system, the spapr-rtas.bin
> is compiled as little endian too which is incorrect as it is always
> executed in big endian mode.
>
> This enforces -mbig by defining %.o:%.S rule as spapr-rtas.bin is
> a standalone guest binary which should not depend on QEMU flags anyway.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Applied to ppc-for-4.1, thanks.
> ---
> pc-bios/spapr-rtas/Makefile | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/pc-bios/spapr-rtas/Makefile b/pc-bios/spapr-rtas/Makefile
> index f26dd428b79e..4b9bb1230658 100644
> --- a/pc-bios/spapr-rtas/Makefile
> +++ b/pc-bios/spapr-rtas/Makefile
> @@ -14,8 +14,11 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/spapr-rtas)
>
> build-all: spapr-rtas.bin
>
> +%.o: %.S
> + $(call quiet-command,$(CCAS) -mbig -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
> +
> %.img: %.o
> - $(call quiet-command,$(CC) -nostdlib -o $@ $<,"Building","$(TARGET_DIR)$@")
> + $(call quiet-command,$(CC) -nostdlib -mbig -o $@ $<,"Building","$(TARGET_DIR)$@")
>
> %.bin: %.img
> $(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"Building","$(TARGET_DIR)$@")
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas
2019-06-12 2:07 [Qemu-devel] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas Alexey Kardashevskiy
2019-06-12 6:07 ` David Gibson
@ 2019-06-17 8:25 ` Greg Kurz
2019-06-17 11:12 ` David Gibson
1 sibling, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2019-06-17 8:25 UTC (permalink / raw)
To: Alexey Kardashevskiy; +Cc: qemu-ppc, qemu-devel, David Gibson
On Wed, 12 Jun 2019 12:07:23 +1000
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> At the moment the rtas's Makefile uses generic QEMU rules which means
> that when QEMU is compiled on a little endian system, the spapr-rtas.bin
> is compiled as little endian too which is incorrect as it is always
> executed in big endian mode.
>
I'm naively thinking that executing code compiled as little endian
in big endian mode would result in an exception... Can you explain
how/why this ever worked ?
> This enforces -mbig by defining %.o:%.S rule as spapr-rtas.bin is
> a standalone guest binary which should not depend on QEMU flags anyway.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> pc-bios/spapr-rtas/Makefile | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/pc-bios/spapr-rtas/Makefile b/pc-bios/spapr-rtas/Makefile
> index f26dd428b79e..4b9bb1230658 100644
> --- a/pc-bios/spapr-rtas/Makefile
> +++ b/pc-bios/spapr-rtas/Makefile
> @@ -14,8 +14,11 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/spapr-rtas)
>
> build-all: spapr-rtas.bin
>
> +%.o: %.S
> + $(call quiet-command,$(CCAS) -mbig -c -o $@ $<,"CCAS","$(TARGET_DIR)$@")
> +
> %.img: %.o
> - $(call quiet-command,$(CC) -nostdlib -o $@ $<,"Building","$(TARGET_DIR)$@")
> + $(call quiet-command,$(CC) -nostdlib -mbig -o $@ $<,"Building","$(TARGET_DIR)$@")
>
> %.bin: %.img
> $(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"Building","$(TARGET_DIR)$@")
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas
2019-06-17 8:25 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2019-06-17 11:12 ` David Gibson
2019-06-17 12:48 ` Greg Kurz
0 siblings, 1 reply; 5+ messages in thread
From: David Gibson @ 2019-06-17 11:12 UTC (permalink / raw)
To: Greg Kurz; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]
On Mon, Jun 17, 2019 at 10:25:10AM +0200, Greg Kurz wrote:
65;5603;1c> On Wed, 12 Jun 2019 12:07:23 +1000
> Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
>
> > At the moment the rtas's Makefile uses generic QEMU rules which means
> > that when QEMU is compiled on a little endian system, the spapr-rtas.bin
> > is compiled as little endian too which is incorrect as it is always
> > executed in big endian mode.
>
> I'm naively thinking that executing code compiled as little endian
> in big endian mode would result in an exception... Can you explain
> how/why this ever worked ?
Because basically nobody actually built the rtas blob from the
sources, they just used the pre-compiled blob, which is correctly
built BE.
That said executing LE code in BE mode won't necessarily result in an
exception - it'll just execute whatever the instructions are you get
when you byte reverse the ones you inteded, which may or may not be
valid. It's *likely* to cause an exception fairly soon, but the
opcode space is densely populated enough that there's a good chance it
won't cause an immediate illegal instruction.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas
2019-06-17 11:12 ` David Gibson
@ 2019-06-17 12:48 ` Greg Kurz
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2019-06-17 12:48 UTC (permalink / raw)
To: David Gibson; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]
On Mon, 17 Jun 2019 21:12:05 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Mon, Jun 17, 2019 at 10:25:10AM +0200, Greg Kurz wrote:
> 65;5603;1c> On Wed, 12 Jun 2019 12:07:23 +1000
> > Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> >
> > > At the moment the rtas's Makefile uses generic QEMU rules which means
> > > that when QEMU is compiled on a little endian system, the spapr-rtas.bin
> > > is compiled as little endian too which is incorrect as it is always
> > > executed in big endian mode.
> >
> > I'm naively thinking that executing code compiled as little endian
> > in big endian mode would result in an exception... Can you explain
> > how/why this ever worked ?
>
> Because basically nobody actually built the rtas blob from the
> sources, they just used the pre-compiled blob, which is correctly
> built BE.
>
Ah ! Everyone has been using blob from this pre-ppc64le commit:
commit d818bfc5c34c59e9c6d03b3b9983bb5435967292
Author: Aurelien Jarno <aurelien@aurel32.net>
Date: Fri Apr 1 20:04:24 2011 +0200
pc-bios/spapr-rtas.bin: remove executable flag
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> That said executing LE code in BE mode won't necessarily result in an
> exception - it'll just execute whatever the instructions are you get
> when you byte reverse the ones you inteded, which may or may not be
> valid. It's *likely* to cause an exception fairly soon, but the
> opcode space is densely populated enough that there's a good chance it
> won't cause an immediate illegal instruction.
>
In theory yes, but in this precise case, the first instruction of the
rtas blob is 7c641b78 ('mr r4, r3') and I've manually checked that
781b647c raises an exception on both POWER8 and POWER9.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-17 12:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-12 2:07 [Qemu-devel] [PATCH qemu REPOST] spapr/rtas: Force big endian compile for rtas Alexey Kardashevskiy
2019-06-12 6:07 ` David Gibson
2019-06-17 8:25 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2019-06-17 11:12 ` David Gibson
2019-06-17 12:48 ` Greg Kurz
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).