All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair23@gmail.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	Bin Meng <bmeng.cn@gmail.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer
Date: Sun, 17 Jan 2021 17:52:44 +0100	[thread overview]
Message-ID: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> (raw)
In-Reply-To: <CAKmqyKNvtuY2eaQHiM4YMKyy_bWAiHFrMan_R+7M_fw7=ioW=A@mail.gmail.com>

On 1/16/21 11:38 PM, Alistair Francis wrote:
> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>
>> On 1/16/21 12:00 AM, Alistair Francis wrote:
>>> We were accidently passing RISCVHartArrayState by value instead of
>>> pointer. The type is 824 bytes long so let's correct that and pass it by
>>> pointer instead.
>>>
>>> Fixes: Coverity CID 1438099
>>> Fixes: Coverity CID 1438100
>>> Fixes: Coverity CID 1438101
>>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>>> ---
>>>  include/hw/riscv/boot.h |  6 +++---
>>>  hw/riscv/boot.c         |  8 ++++----
>>>  hw/riscv/sifive_u.c     | 10 +++++-----
>>>  hw/riscv/spike.c        |  8 ++++----
>>>  hw/riscv/virt.c         |  8 ++++----
>>>  5 files changed, 20 insertions(+), 20 deletions(-)
...

>>> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
>>> index 83586aef41..acf77675b2 100644
>>> --- a/hw/riscv/boot.c
>>> +++ b/hw/riscv/boot.c
>>> @@ -33,14 +33,14 @@
>>>
>>>  #include <libfdt.h>
>>>
>>> -bool riscv_is_32bit(RISCVHartArrayState harts)
>>> +bool riscv_is_32bit(RISCVHartArrayState *harts)
>>>  {
>>> -    RISCVCPU hart = harts.harts[0];
>>> +    RISCVCPU hart = harts->harts[0];
>>
>> This doesn't look improved. Maybe you want:
>>
>>        return riscv_cpu_is_32bit(&harts->harts[0].env);
> 
> I suspect this ends up generating the same code.

If the compiler is smart enough, but I'm not sure it can figure out
only 1 element from the structure is accessed...
My understanding is "first copy the content pointed at '*harts' in
'hart' on the stack", then only use "env".

Cc'ing Eric/Richard to double check.

> 
> Either way, good point I have just squashed this change into the patch.

Thanks,

Phil.


WARNING: multiple messages have this Message-ID (diff)
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair23@gmail.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Bin Meng <bmeng.cn@gmail.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Eric Blake <eblake@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer
Date: Sun, 17 Jan 2021 17:52:44 +0100	[thread overview]
Message-ID: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> (raw)
In-Reply-To: <CAKmqyKNvtuY2eaQHiM4YMKyy_bWAiHFrMan_R+7M_fw7=ioW=A@mail.gmail.com>

On 1/16/21 11:38 PM, Alistair Francis wrote:
> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>
>> On 1/16/21 12:00 AM, Alistair Francis wrote:
>>> We were accidently passing RISCVHartArrayState by value instead of
>>> pointer. The type is 824 bytes long so let's correct that and pass it by
>>> pointer instead.
>>>
>>> Fixes: Coverity CID 1438099
>>> Fixes: Coverity CID 1438100
>>> Fixes: Coverity CID 1438101
>>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>>> ---
>>>  include/hw/riscv/boot.h |  6 +++---
>>>  hw/riscv/boot.c         |  8 ++++----
>>>  hw/riscv/sifive_u.c     | 10 +++++-----
>>>  hw/riscv/spike.c        |  8 ++++----
>>>  hw/riscv/virt.c         |  8 ++++----
>>>  5 files changed, 20 insertions(+), 20 deletions(-)
...

>>> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
>>> index 83586aef41..acf77675b2 100644
>>> --- a/hw/riscv/boot.c
>>> +++ b/hw/riscv/boot.c
>>> @@ -33,14 +33,14 @@
>>>
>>>  #include <libfdt.h>
>>>
>>> -bool riscv_is_32bit(RISCVHartArrayState harts)
>>> +bool riscv_is_32bit(RISCVHartArrayState *harts)
>>>  {
>>> -    RISCVCPU hart = harts.harts[0];
>>> +    RISCVCPU hart = harts->harts[0];
>>
>> This doesn't look improved. Maybe you want:
>>
>>        return riscv_cpu_is_32bit(&harts->harts[0].env);
> 
> I suspect this ends up generating the same code.

If the compiler is smart enough, but I'm not sure it can figure out
only 1 element from the structure is accessed...
My understanding is "first copy the content pointed at '*harts' in
'hart' on the stack", then only use "env".

Cc'ing Eric/Richard to double check.

> 
> Either way, good point I have just squashed this change into the patch.

Thanks,

Phil.


  reply	other threads:[~2021-01-17 16:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 23:00 [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Alistair Francis
2021-01-15 23:00 ` Alistair Francis
2021-01-15 23:03 ` Palmer Dabbelt
2021-01-15 23:03   ` Palmer Dabbelt
2021-01-16 16:30 ` Bin Meng
2021-01-16 16:30   ` Bin Meng
2021-01-16 17:50   ` Alistair Francis
2021-01-16 17:50     ` Alistair Francis
2021-01-16 18:55 ` Alistair Francis
2021-01-16 18:55   ` Alistair Francis
2021-01-16 22:32 ` Philippe Mathieu-Daudé
2021-01-16 22:32   ` Philippe Mathieu-Daudé
2021-01-16 22:38   ` Alistair Francis
2021-01-16 22:38     ` Alistair Francis
2021-01-17 16:52     ` Philippe Mathieu-Daudé [this message]
2021-01-17 16:52       ` Philippe Mathieu-Daudé
2021-01-19 21:50       ` Eric Blake
2021-01-19 21:50         ` Eric Blake
2021-01-18 17:14 ` Richard Henderson
2021-01-18 17:14   ` 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=31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org \
    --to=f4bug@amsat.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=rth@twiddle.net \
    /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.