All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Clark <mjc@sifive.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	Palmer Dabbelt <palmer@sifive.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	"Richard W.M. Jones" <rjones@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3] RISC-V: Fix riscv_isa_string memory size bug
Date: Mon, 19 Mar 2018 11:35:51 -0700	[thread overview]
Message-ID: <CAHNT7Nuv9G+e3-m-356HZDoiLju=vPCucfWhXLJ0QHPGM7NSQw@mail.gmail.com> (raw)
In-Reply-To: <dec4f79c-a46e-f341-ef17-7ba85086bc9a@amsat.org>

On Sun, Mar 18, 2018 at 4:22 PM, Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:

> On 03/16/2018 06:26 PM, Michael Clark wrote:
> > This version uses a constant size memory buffer sized for
> > the maximum possible ISA string length. It also uses g_new
> > instead of g_new0, uses more efficient logic to append
> > extensions and adds manual zero termination of the string.
> >
> > Cc: Palmer Dabbelt <palmer@sifive.com>
> > Cc: Peter Maydell <peter.maydell@linaro.org>
> > Cc: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > Signed-off-by: Michael Clark <mjc@sifive.com>
> > ---
> >  target/riscv/cpu.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > index 4851890..298abbd 100644
> > --- a/target/riscv/cpu.c
> > +++ b/target/riscv/cpu.c
> > @@ -391,16 +391,16 @@ static const TypeInfo riscv_cpu_type_info = {
> >  char *riscv_isa_string(RISCVCPU *cpu)
> >  {
> >      int i;
> > -    size_t maxlen = 5 + ctz32(cpu->env.misa);
> > -    char *isa_string = g_new0(char, maxlen);
> > -    snprintf(isa_string, maxlen, "rv%d", TARGET_LONG_BITS);
> > +    const size_t maxlen = sizeof("rv128") + sizeof(riscv_exts) + 1;
> > +    char *isa_str = g_new(char, maxlen);
> > +    char *p = isa_str + snprintf(isa_str, maxlen, "rv%d",
> TARGET_LONG_BITS);
> >      for (i = 0; i < sizeof(riscv_exts); i++) {
> >          if (cpu->env.misa & RV(riscv_exts[i])) {
> > -            isa_string[strlen(isa_string)] = riscv_exts[i] - 'A' + 'a';
> > -
> > +            *p++ = riscv_exts[i] - 'A' + 'a';
>                                                  /* tolower() */
>
> I prefer unobfuscated code (think newcomers and reviewers) :|
>

Thanks! Done.

I think i'll add the riscv_isa_string fix onto the RISC-V post-merge spec
conformance and cleanup series, and send I'll send out a (hopefully final)
version of it today, so we can merge all of the spec conformance, bug fixes
and cleanups in one PR.

The RISC-V post-merge spec conformance and cleanup series has had a lot of
testing. I've been using it to compile QEMU inside of QEMU using the RISC-V
Fedora Image and its native RISC-V GCC toolchain running inside SMP Linux
4.16-rc2. It appears to be pretty rock-solid. The rcu lock fix would likely
only affect users who are ballooning memory while a guest is under load.
The page walker changes have also been tested under load (including
performance tests).

FYI - I also have an experimental branch containing a RISC-V TCG back-end
that I started on during the RISC-V Hackathon in Portland last week:

- https://github.com/michaeljclark/riscv-qemu/tree/wip-riscv-tcg-backend

I'm able to run a very simple x86_64 hello world program on RISC-V,
avoiding all of the usual libc startup. However, it may be some time before
I submit a patch series for this branch. So far the RISC-V TCG backend
doesn't implement softmmu, have bigendian byteswapping in its load/store
implementation or 64-bit on 32-bit support (brcond2/setcond2). This will
come, however, at present I'm still testing the basic codegen. That being
said, it has meant that i've been using the RISC-V QEMU Fedora image pretty
extensively as my main development machine, with the  RISC-V post-merge
spec conformance and cleanup series applied, performing a lot of parallel
makes on a quad-core i7. The only thing I am really missing is gdb. The
current RISC-V GDB port seems to be missing user-space debugging support as
I believe the focus has been on the JTAG remote debugging use case.

[mclark@stage4 riscv-qemu]$ uname -a
Linux stage4.fedoraproject.org 4.16.0-rc2-00328-gebea62367bc4 #4 SMP Mon
Feb 26 16:05:16 GMT 2018 riscv64 riscv64 riscv64 GNU/Linux
[mclark@stage4 riscv-qemu]$ ./riscv64-linux-user/qemu-riscv64 hello.riscv64
Hello World
[mclark@stage4 riscv-qemu]$ ./x86_64-linux-user/qemu-x86_64 hello.x86_64
Hello World

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> >          }
> >      }
> > -    return isa_string;
> > +    *p = '\0';
> > +    return isa_str;
> >  }
> >
> >  void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf)
> >
>

  reply	other threads:[~2018-03-19 18:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 17:26 [Qemu-devel] [PATCH v3] RISC-V: Fix riscv_isa_string memory size bug Michael Clark
2018-03-18 23:22 ` Philippe Mathieu-Daudé
2018-03-19 18:35   ` Michael Clark [this message]
2018-03-19 19:42     ` Richard W.M. Jones
2018-03-19 21:39       ` Michael Clark
2018-03-22 21:06         ` Michael Clark
2018-03-22 22:09           ` Richard W.M. Jones
2018-03-22 22:17             ` DJ Delorie
2018-03-22 22:21               ` Michael Clark
2018-03-23 20:01               ` Palmer Dabbelt
2018-03-20  4:43     ` Richard Henderson
2018-03-20 18:06       ` Michael Clark
2018-03-24  4:35         ` Richard Henderson

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='CAHNT7Nuv9G+e3-m-356HZDoiLju=vPCucfWhXLJ0QHPGM7NSQw@mail.gmail.com' \
    --to=mjc@sifive.com \
    --cc=f4bug@amsat.org \
    --cc=palmer@sifive.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    /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.