All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Hedde <damien.hedde@greensocs.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Alistair Francis" <alistair23@gmail.com>
Cc: Alistair Francis <alistair@alistair23.me>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [PATCH] generic-loader: remove the ram_size limit when a loading binary file
Date: Fri, 8 Oct 2021 12:38:41 +0200	[thread overview]
Message-ID: <97f817b9-9455-9899-ff20-530baa77190d@greensocs.com> (raw)
In-Reply-To: <6b919273-ab23-6822-fdeb-66e18009f70a@redhat.com>



On 10/7/21 09:59, Philippe Mathieu-Daudé wrote:
> On 10/7/21 08:41, Alistair Francis wrote:
>> On Wed, Oct 6, 2021 at 10:04 PM Damien Hedde <damien.hedde@greensocs.com> wrote:
>>> On 10/6/21 13:49, Philippe Mathieu-Daudé wrote:
>>>> On 10/6/21 13:37, Damien Hedde wrote:
>>>>> Right now, we cannot load some binary file if it is bigger than the
>>>>> machine's ram size. This limitation only occurs when loading a
>>>>> binary file: we can load a corresponding elf file without this
>>>>> limitation.
>>>>>
>>>>> This is an issue for machines that have small ram or do not use the
>>>>> ram_size feature at all.
>>>>>
>>>>> Also get rid of "hw/boards.h" include, since we needed it only
>>>>> to access `current_machine`.
>>>>>
>>>>> Fixes: e481a1f63c9 ("generic-loader: Add a generic loader")
>>>>> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
>>>>> ---
>>>>>
>>>>> Hi Alistair,
>>>>>
>>>>> I found this while experimenting with a ram_size=0 machine.
>>>
>>>
>>>
>>>>
>>>> Where are you loading your file?
>>>>
>>>
>>> In a rom.
>>>
>>> The loader does not check at all that we are loading to the machine's
>>> ram. It just check the size for the raw binary file format.
>>
>> Hmmm... This is probably correct, in that a user might want to load a
>> binary into ROM and doesn't want to be blocked by the ram size.
>>
>> In general though a user would expect an error if they are loading a
>> file into RAM that is larger then the RAM. So I'm not fully convinced
>> we want this change.
> 
> I agree with Damien using current_machine->ram_size is not ideal,
> for example some machines have the RAM split and mapped at different
> regions, so even if ram_size is enough for the image to load,
> a region might not be big enough and I'd expect load_image_targphys_as()
> to fail.
> 
> Maybe we can call memory_region_find(s->addr) then on match:
> 
>   if (memory_region_is_ram*(match)) {
>     size = memory_region_size(match);
>   } else {
>     size = -1;
>   }
> 

So I worked a bit on this.

We could call memory_region_find(get_system_memory(), addr, ...) like 
Philippe proposed.
and check that the memory is big enough and has the proper "type" (ram, 
rom, ...)

Note that we will check only the current state of the address space. So 
it means the region must already exists (sounds reasonable to me).

If this sounds like a good direction to you, I'll propose an updated 
version of the patch.

regarding relying on load_image_targphys to check this. I don't know...
all these functions (load_targphys_...() and rom_add_...()) just put 
rom(s) in a list. The list is checked afterward against overlap and 
loaded at reset.
It is possible but it changes the behavior of all rom_add_...() functions.

We could also check, during the reset, that the rom loading works. But 
maybe some part of qemu expects that we silently skip some missing bits.
Maybe a log/warning there ?

Thanks,
Damien


  reply	other threads:[~2021-10-08 10:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 11:37 [PATCH] generic-loader: remove the ram_size limit when a loading binary file Damien Hedde
2021-10-06 11:49 ` Philippe Mathieu-Daudé
2021-10-06 11:58   ` Damien Hedde
2021-10-06 15:40     ` Alex Bennée
2021-10-07  7:54       ` Philippe Mathieu-Daudé
2021-10-07 10:12         ` Damien Hedde
2021-10-07 11:01           ` Philippe Mathieu-Daudé
2021-10-07  6:41     ` Alistair Francis
2021-10-07  7:59       ` Philippe Mathieu-Daudé
2021-10-08 10:38         ` Damien Hedde [this message]
2021-10-10 23:06           ` Alistair Francis
2021-10-07 10:12       ` Damien Hedde

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=97f817b9-9455-9899-ff20-530baa77190d@greensocs.com \
    --to=damien.hedde@greensocs.com \
    --cc=alistair23@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=philmd@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.