* [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts @ 2023-07-21 9:47 Thomas Huth 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Thomas Huth @ 2023-07-21 9:47 UTC (permalink / raw) To: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei The tests/avocado/riscv_opensbi.py avocado test is currently failing on big endian hosts since the console of the Spike machine is not working there. With two small patches, this can be fixed: First patch fixes riscv64, and the second one fixes riscv32. Thomas Huth (2): hw/char/riscv_htif: Fix printing of console characters on big endian hosts hw/char/riscv_htif: Fix the console syscall on big endian hosts hw/char/riscv_htif.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- 2.39.3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts 2023-07-21 9:47 [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts Thomas Huth @ 2023-07-21 9:47 ` Thomas Huth 2023-07-21 10:10 ` Bin Meng ` (3 more replies) 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth 2023-07-23 22:58 ` [PATCH 0/2] riscv: Fix the console of the Spike machine " Alistair Francis 2 siblings, 4 replies; 11+ messages in thread From: Thomas Huth @ 2023-07-21 9:47 UTC (permalink / raw) To: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei The character that should be printed is stored in the 64 bit "payload" variable. The code currently tries to print it by taking the address of the variable and passing this pointer to qemu_chr_fe_write(). However, this only works on little endian hosts where the least significant bits are stored on the lowest address. To do this in a portable way, we have to store the value in an uint8_t variable instead. Fixes: 5033606780 ("RISC-V HTIF Console") Signed-off-by: Thomas Huth <thuth@redhat.com> --- hw/char/riscv_htif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 37d3ccc76b..f96df40124 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) s->tohost = 0; /* clear to indicate we read */ return; } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { - qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); + uint8_t ch = (uint8_t)payload; + qemu_chr_fe_write(&s->chr, &ch, 1); resp = 0x100 | (uint8_t)payload; } else { qemu_log("HTIF device %d: unknown command\n", device); -- 2.39.3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth @ 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza ` (2 subsequent siblings) 3 siblings, 0 replies; 11+ messages in thread From: Bin Meng @ 2023-07-21 10:10 UTC (permalink / raw) To: Thomas Huth Cc: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng, qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On Fri, Jul 21, 2023 at 5:48 PM Thomas Huth <thuth@redhat.com> wrote: > > The character that should be printed is stored in the 64 bit "payload" > variable. The code currently tries to print it by taking the address > of the variable and passing this pointer to qemu_chr_fe_write(). However, > this only works on little endian hosts where the least significant bits > are stored on the lowest address. To do this in a portable way, we have > to store the value in an uint8_t variable instead. > > Fixes: 5033606780 ("RISC-V HTIF Console") > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > hw/char/riscv_htif.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > Reviewed-by: Bin Meng <bmeng@tinylab.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth 2023-07-21 10:10 ` Bin Meng @ 2023-07-21 10:20 ` Daniel Henrique Barboza 2023-07-21 13:26 ` Philippe Mathieu-Daudé 2023-07-23 22:38 ` Alistair Francis 3 siblings, 0 replies; 11+ messages in thread From: Daniel Henrique Barboza @ 2023-07-21 10:20 UTC (permalink / raw) To: Thomas Huth, qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Liu Zhiwei On 7/21/23 06:47, Thomas Huth wrote: > The character that should be printed is stored in the 64 bit "payload" > variable. The code currently tries to print it by taking the address > of the variable and passing this pointer to qemu_chr_fe_write(). However, > this only works on little endian hosts where the least significant bits > are stored on the lowest address. To do this in a portable way, we have > to store the value in an uint8_t variable instead. > > Fixes: 5033606780 ("RISC-V HTIF Console") > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > hw/char/riscv_htif.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c > index 37d3ccc76b..f96df40124 100644 > --- a/hw/char/riscv_htif.c > +++ b/hw/char/riscv_htif.c > @@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) > s->tohost = 0; /* clear to indicate we read */ > return; > } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { > - qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); > + uint8_t ch = (uint8_t)payload; > + qemu_chr_fe_write(&s->chr, &ch, 1); > resp = 0x100 | (uint8_t)payload; > } else { > qemu_log("HTIF device %d: unknown command\n", device); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza @ 2023-07-21 13:26 ` Philippe Mathieu-Daudé 2023-07-23 22:38 ` Alistair Francis 3 siblings, 0 replies; 11+ messages in thread From: Philippe Mathieu-Daudé @ 2023-07-21 13:26 UTC (permalink / raw) To: Thomas Huth, qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On 21/7/23 11:47, Thomas Huth wrote: > The character that should be printed is stored in the 64 bit "payload" > variable. The code currently tries to print it by taking the address > of the variable and passing this pointer to qemu_chr_fe_write(). However, > this only works on little endian hosts where the least significant bits > are stored on the lowest address. To do this in a portable way, we have > to store the value in an uint8_t variable instead. > > Fixes: 5033606780 ("RISC-V HTIF Console") > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > hw/char/riscv_htif.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters on big endian hosts 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth ` (2 preceding siblings ...) 2023-07-21 13:26 ` Philippe Mathieu-Daudé @ 2023-07-23 22:38 ` Alistair Francis 3 siblings, 0 replies; 11+ messages in thread From: Alistair Francis @ 2023-07-23 22:38 UTC (permalink / raw) To: Thomas Huth Cc: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng, qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On Fri, Jul 21, 2023 at 7:48 PM Thomas Huth <thuth@redhat.com> wrote: > > The character that should be printed is stored in the 64 bit "payload" > variable. The code currently tries to print it by taking the address > of the variable and passing this pointer to qemu_chr_fe_write(). However, > this only works on little endian hosts where the least significant bits > are stored on the lowest address. To do this in a portable way, we have > to store the value in an uint8_t variable instead. > > Fixes: 5033606780 ("RISC-V HTIF Console") > Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Alistair > --- > hw/char/riscv_htif.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c > index 37d3ccc76b..f96df40124 100644 > --- a/hw/char/riscv_htif.c > +++ b/hw/char/riscv_htif.c > @@ -232,7 +232,8 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) > s->tohost = 0; /* clear to indicate we read */ > return; > } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { > - qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); > + uint8_t ch = (uint8_t)payload; > + qemu_chr_fe_write(&s->chr, &ch, 1); > resp = 0x100 | (uint8_t)payload; > } else { > qemu_log("HTIF device %d: unknown command\n", device); > -- > 2.39.3 > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts 2023-07-21 9:47 [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts Thomas Huth 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth @ 2023-07-21 9:47 ` Thomas Huth 2023-07-21 10:10 ` Bin Meng ` (2 more replies) 2023-07-23 22:58 ` [PATCH 0/2] riscv: Fix the console of the Spike machine " Alistair Francis 2 siblings, 3 replies; 11+ messages in thread From: Thomas Huth @ 2023-07-21 9:47 UTC (permalink / raw) To: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei Values that have been read via cpu_physical_memory_read() from the guest's memory have to be swapped in case the host endianess differs from the guest. Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") Signed-off-by: Thomas Huth <thuth@redhat.com> --- hw/char/riscv_htif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index f96df40124..40de6b8b77 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -30,6 +30,7 @@ #include "qemu/timer.h" #include "qemu/error-report.h" #include "exec/address-spaces.h" +#include "exec/tswap.h" #include "sysemu/dma.h" #define RISCV_DEBUG_HTIF 0 @@ -209,11 +210,11 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) } else { uint64_t syscall[8]; cpu_physical_memory_read(payload, syscall, sizeof(syscall)); - if (syscall[0] == PK_SYS_WRITE && - syscall[1] == HTIF_DEV_CONSOLE && - syscall[3] == HTIF_CONSOLE_CMD_PUTC) { + if (tswap64(syscall[0]) == PK_SYS_WRITE && + tswap64(syscall[1]) == HTIF_DEV_CONSOLE && + tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { uint8_t ch; - cpu_physical_memory_read(syscall[2], &ch, 1); + cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); qemu_chr_fe_write(&s->chr, &ch, 1); resp = 0x100 | (uint8_t)payload; } else { -- 2.39.3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth @ 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza 2023-07-23 22:37 ` Alistair Francis 2 siblings, 0 replies; 11+ messages in thread From: Bin Meng @ 2023-07-21 10:10 UTC (permalink / raw) To: Thomas Huth Cc: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng, qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On Fri, Jul 21, 2023 at 5:48 PM Thomas Huth <thuth@redhat.com> wrote: > > Values that have been read via cpu_physical_memory_read() from the > guest's memory have to be swapped in case the host endianess differs typo: endianness > from the guest. > > Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > hw/char/riscv_htif.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > Reviewed-by: Bin Meng <bmeng@tinylab.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth 2023-07-21 10:10 ` Bin Meng @ 2023-07-21 10:20 ` Daniel Henrique Barboza 2023-07-23 22:37 ` Alistair Francis 2 siblings, 0 replies; 11+ messages in thread From: Daniel Henrique Barboza @ 2023-07-21 10:20 UTC (permalink / raw) To: Thomas Huth, qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng Cc: qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Liu Zhiwei On 7/21/23 06:47, Thomas Huth wrote: > Values that have been read via cpu_physical_memory_read() from the > guest's memory have to be swapped in case the host endianess differs > from the guest. > > Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > hw/char/riscv_htif.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c > index f96df40124..40de6b8b77 100644 > --- a/hw/char/riscv_htif.c > +++ b/hw/char/riscv_htif.c > @@ -30,6 +30,7 @@ > #include "qemu/timer.h" > #include "qemu/error-report.h" > #include "exec/address-spaces.h" > +#include "exec/tswap.h" > #include "sysemu/dma.h" > > #define RISCV_DEBUG_HTIF 0 > @@ -209,11 +210,11 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) > } else { > uint64_t syscall[8]; > cpu_physical_memory_read(payload, syscall, sizeof(syscall)); > - if (syscall[0] == PK_SYS_WRITE && > - syscall[1] == HTIF_DEV_CONSOLE && > - syscall[3] == HTIF_CONSOLE_CMD_PUTC) { > + if (tswap64(syscall[0]) == PK_SYS_WRITE && > + tswap64(syscall[1]) == HTIF_DEV_CONSOLE && > + tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { > uint8_t ch; > - cpu_physical_memory_read(syscall[2], &ch, 1); > + cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); > qemu_chr_fe_write(&s->chr, &ch, 1); > resp = 0x100 | (uint8_t)payload; > } else { ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall on big endian hosts 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza @ 2023-07-23 22:37 ` Alistair Francis 2 siblings, 0 replies; 11+ messages in thread From: Alistair Francis @ 2023-07-23 22:37 UTC (permalink / raw) To: Thomas Huth Cc: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng, qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On Fri, Jul 21, 2023 at 7:48 PM Thomas Huth <thuth@redhat.com> wrote: > > Values that have been read via cpu_physical_memory_read() from the > guest's memory have to be swapped in case the host endianess differs > from the guest. > > Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") > Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Alistair > --- > hw/char/riscv_htif.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c > index f96df40124..40de6b8b77 100644 > --- a/hw/char/riscv_htif.c > +++ b/hw/char/riscv_htif.c > @@ -30,6 +30,7 @@ > #include "qemu/timer.h" > #include "qemu/error-report.h" > #include "exec/address-spaces.h" > +#include "exec/tswap.h" > #include "sysemu/dma.h" > > #define RISCV_DEBUG_HTIF 0 > @@ -209,11 +210,11 @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) > } else { > uint64_t syscall[8]; > cpu_physical_memory_read(payload, syscall, sizeof(syscall)); > - if (syscall[0] == PK_SYS_WRITE && > - syscall[1] == HTIF_DEV_CONSOLE && > - syscall[3] == HTIF_CONSOLE_CMD_PUTC) { > + if (tswap64(syscall[0]) == PK_SYS_WRITE && > + tswap64(syscall[1]) == HTIF_DEV_CONSOLE && > + tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { > uint8_t ch; > - cpu_physical_memory_read(syscall[2], &ch, 1); > + cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); > qemu_chr_fe_write(&s->chr, &ch, 1); > resp = 0x100 | (uint8_t)payload; > } else { > -- > 2.39.3 > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts 2023-07-21 9:47 [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts Thomas Huth 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth @ 2023-07-23 22:58 ` Alistair Francis 2 siblings, 0 replies; 11+ messages in thread From: Alistair Francis @ 2023-07-23 22:58 UTC (permalink / raw) To: Thomas Huth Cc: qemu-devel, Marc-André Lureau, Palmer Dabbelt, Alistair Francis, Bin Meng, qemu-stable, Paolo Bonzini, qemu-riscv, Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei On Fri, Jul 21, 2023 at 7:48 PM Thomas Huth <thuth@redhat.com> wrote: > > The tests/avocado/riscv_opensbi.py avocado test is currently failing > on big endian hosts since the console of the Spike machine is not > working there. With two small patches, this can be fixed: First patch > fixes riscv64, and the second one fixes riscv32. > > Thomas Huth (2): > hw/char/riscv_htif: Fix printing of console characters on big endian > hosts > hw/char/riscv_htif: Fix the console syscall on big endian hosts Thanks! Applied to riscv-to-apply.next Alistair > > hw/char/riscv_htif.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > -- > 2.39.3 > > ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-07-23 22:59 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-07-21 9:47 [PATCH 0/2] riscv: Fix the console of the Spike machine on big endian hosts Thomas Huth 2023-07-21 9:47 ` [PATCH 1/2] hw/char/riscv_htif: Fix printing of console characters " Thomas Huth 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza 2023-07-21 13:26 ` Philippe Mathieu-Daudé 2023-07-23 22:38 ` Alistair Francis 2023-07-21 9:47 ` [PATCH 2/2] hw/char/riscv_htif: Fix the console syscall " Thomas Huth 2023-07-21 10:10 ` Bin Meng 2023-07-21 10:20 ` Daniel Henrique Barboza 2023-07-23 22:37 ` Alistair Francis 2023-07-23 22:58 ` [PATCH 0/2] riscv: Fix the console of the Spike machine " Alistair Francis
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).