Re: ‏ Crash in memory_region_init_ram call chain, when --bios command line parameter is presented.

2023-02-14 Thread Peter Maydell
On Tue, 14 Feb 2023 at 11:54, Alyosha Shevandin
 wrote:
>
> Thank you for your answer. I belive that 'owner' parameter is initialized: 1) 
> without --bios parameter the code does not crash; 2) I check the the owner 
> parameter before;
> Here is the fragment of my code:
>
> static void  my_soc_init(MachineState *machine)
> {
>
>   MySocState* state = OBJECT_CHECK(MySocState, machine, TYPE_MY_SOC);

This looks very confused. Generally in QEMU the 'board'
(inherits from MachineState) is a different object from
the SoC (inherits from DeviceState). This code seems to
think they are the same thing.

>   if (!state) {
> error_report("failed to convert from the parent MachineState to 
> derived MySocState");
> exit(1);
>   }
>
>   /*
>    * Setup the memories.
>    */
>   memory_region_init_ram(>ram,
>   OBJECT(state),
>   "mysoc.ram",
>   mysoc_memmap[MYSOCK_DEV_RAM].size,
>   _abort);

The 'owner' argument to memory_region_init_ram() must be
either NULL or something that inherits from DeviceState.
We use the former for memory regions created by boards, and
the latter for memory regions created by SoC models.
The (cast) MachineState object you are passing is neither,
so you end up with an assertion when the code tries to do
something to it that only works with a DeviceState.

(I'm not sure why this didn't assert in memory_region_init_ram()
when it does the DEVICE() cast on the owner pointer.)

thanks
-- PMM


Crash in memory_region_init_ram call chain, when --bios command line parameter is presented.

2023-02-14 Thread Alyosha Shevandin

I would appreciate any clue about the crash.

When I start my custom SoC emulation and the –bios command line parameter us 
presented, the QEMU processes crashes before the custom code even tries to load 
the firmware. It crashes in the *memory_region_init_ram* call chain with the 
follow stack:


#0 0x5613255a6932 in object_class_dynamic_cast_assert

(class=0x56006f6b756b, typename=0x5613259e94ee "bus", file=0x5613259e94a8 
"/project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h", line=217, 
func=0x5613259e9828 <__func__.18> "BUS_GET_CLASS")

at ../qom/object.c:963

#1 0x56132559e3a3 in BUS_GET_CLASS (obj=0x561326fd7830) at 
/project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h:217

#2 0x56132559f434 in qdev_get_dev_path (dev=0x561326d27800) at 
../hw/core/qdev.c:422

#3 0x5613254f489d in qemu_ram_set_idstr (new_block=0x56132710acc0, 
name=0x5613270e1760 "speedata.callisto.ddr1", dev=0x561326d27800) at 
../softmmu/physmem.c:1766

#4 0x5613250a1069 in vmstate_register_ram (mr=0x561326d27950, 
dev=0x561326d27800) at ../migration/savevm.c:3104

#5 0x5613254ee0c8 in memory_region_init_ram (mr=0x561326d27950, 
owner=0x561326d27800, name=0x561325983052 "speedata.callisto.ddr1", 
size=4294967296, errp=0x5613262c6178 )

at ../softmmu/memory.c:3543


It seems that the code domain where the crash occurs is unrelated with the 
–bios command line parameter processing.

I'm using the master branch, commit 13356edb87506c148b163b8c7eb0695647d00c2a


Regards,

Aleksey



Re: Suitable API do build the custom SoC emulation

2023-02-14 Thread Peter Maydell
On Tue, 14 Feb 2023 at 10:40, Alyosha Shevandin
 wrote:
>
> I wonder if there is any other way to build emulation for the custom SoC 
> except using QEMU C API? I mean, the C API the one, that is used in a lot of 
> examples under /hw folder. The other way – the high level abstractions – 
> based: XML, Json, Python etc.

No, at the moment the only way to write emulation of
a new SoC is to do it in C as part of the main QEMU
executable.

-- PMM



Suitable API do build the custom SoC emulation

2023-02-14 Thread Alyosha Shevandin
I wonder if there is any other way to build emulation for the custom SoC except 
using QEMU C API? I mean, the C API the one, that is used in a lot of examples 
under /hw folder. The other way – the high level abstractions – based: XML, 
Json, Python etc.

The custom hardware that I need to emulate:

  *   A55 CPU

  *   different kind of memories (RAM, SRAM, ROM) with some custom memory 
layout;

  *   UART

  *   ARM TF, BL1 loading (-bios command line parameter)


Regards,

Aleksey


Re:‏ Crash in memory_region_init_ram call chain, when --bios command line parameter is presented.

2023-02-14 Thread Alyosha Shevandin
Thank you for your answer. I belive that 'owner' parameter is initialized: 1) 
without --bios parameter the code does not crash; 2) I check the the owner 
parameter before;
Here is the fragment of my code:
static void  my_soc_init(MachineState *machine)
{ 

  MySocState* state = OBJECT_CHECK(MySocState, machine, TYPE_MY_SOC);
  if (!state) {
error_report("failed to convert from the parent MachineState to 
derived MySocState");
exit(1);
  }

  /*
   * Setup the memories.
   */
  memory_region_init_ram(>ram,
  OBJECT(state),
  "mysoc.ram",
  mysoc_memmap[MYSOCK_DEV_RAM].size,
  _abort);

Regards,
Aleksey

מאת: Peter Maydell 
‏‏נשלח: יום שלישי 14 פברואר 2023 13:07
‏‏אל: Alyosha Shevandin 
עותק: qemu-discuss@nongnu.org 
‏‏נושא: Re: Crash in memory_region_init_ram call chain, when --bios command 
line parameter is presented.

On Tue, 14 Feb 2023 at 11:03, Alyosha Shevandin
 wrote:
>
>
> I would appreciate any clue about the crash.
>
> When I start my custom SoC emulation and the –bios command line parameter us 
> presented, the QEMU processes crashes before the custom code even tries to 
> load the firmware. It crashes in the *memory_region_init_ram* call chain with 
> the follow stack:
>
>
> #0 0x5613255a6932 in object_class_dynamic_cast_assert
>
> (class=0x56006f6b756b, typename=0x5613259e94ee "bus", file=0x5613259e94a8 
> "/project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h", line=217, 
> func=0x5613259e9828 <__func__.18> "BUS_GET_CLASS")
>
> at ../qom/object.c:963
>
> #1 0x56132559e3a3 in BUS_GET_CLASS (obj=0x561326fd7830) at 
> /project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h:217
>
> #2 0x56132559f434 in qdev_get_dev_path (dev=0x561326d27800) at 
> ../hw/core/qdev.c:422
>
> #3 0x5613254f489d in qemu_ram_set_idstr (new_block=0x56132710acc0, 
> name=0x5613270e1760 "speedata.callisto.ddr1", dev=0x561326d27800) at 
> ../softmmu/physmem.c:1766
>
> #4 0x5613250a1069 in vmstate_register_ram (mr=0x561326d27950, 
> dev=0x561326d27800) at ../migration/savevm.c:3104
>
> #5 0x5613254ee0c8 in memory_region_init_ram (mr=0x561326d27950, 
> owner=0x561326d27800, name=0x561325983052 "speedata.callisto.ddr1", 
> size=4294967296, errp=0x5613262c6178 )
>
> at ../softmmu/memory.c:3543

Looking at the back trace, my guess is that you've passed in
an 'owner' argument to memory_region_init_ram() that isn't
a valid initialized device object.

-- PMM


Re: Crash in memory_region_init_ram call chain, when --bios command line parameter is presented.

2023-02-14 Thread Peter Maydell
On Tue, 14 Feb 2023 at 11:03, Alyosha Shevandin
 wrote:
>
>
> I would appreciate any clue about the crash.
>
> When I start my custom SoC emulation and the –bios command line parameter us 
> presented, the QEMU processes crashes before the custom code even tries to 
> load the firmware. It crashes in the *memory_region_init_ram* call chain with 
> the follow stack:
>
>
> #0 0x5613255a6932 in object_class_dynamic_cast_assert
>
> (class=0x56006f6b756b, typename=0x5613259e94ee "bus", file=0x5613259e94a8 
> "/project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h", line=217, 
> func=0x5613259e9828 <__func__.18> "BUS_GET_CLASS")
>
> at ../qom/object.c:963
>
> #1 0x56132559e3a3 in BUS_GET_CLASS (obj=0x561326fd7830) at 
> /project/users/ashevandin/qemu-speedata/include/hw/qdev-core.h:217
>
> #2 0x56132559f434 in qdev_get_dev_path (dev=0x561326d27800) at 
> ../hw/core/qdev.c:422
>
> #3 0x5613254f489d in qemu_ram_set_idstr (new_block=0x56132710acc0, 
> name=0x5613270e1760 "speedata.callisto.ddr1", dev=0x561326d27800) at 
> ../softmmu/physmem.c:1766
>
> #4 0x5613250a1069 in vmstate_register_ram (mr=0x561326d27950, 
> dev=0x561326d27800) at ../migration/savevm.c:3104
>
> #5 0x5613254ee0c8 in memory_region_init_ram (mr=0x561326d27950, 
> owner=0x561326d27800, name=0x561325983052 "speedata.callisto.ddr1", 
> size=4294967296, errp=0x5613262c6178 )
>
> at ../softmmu/memory.c:3543

Looking at the back trace, my guess is that you've passed in
an 'owner' argument to memory_region_init_ram() that isn't
a valid initialized device object.

-- PMM