qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Peng Liang" <tcx4c70@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Martin Kletzander" <mkletzan@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: QOM crash via soundhw_init()
Date: Thu, 12 Oct 2023 18:48:46 +0200	[thread overview]
Message-ID: <6522c5f6-0d78-1344-c3ee-76b83f39942b@linaro.org> (raw)
In-Reply-To: <af961171-6582-4d1e-b3bc-35d979849ff6@gmail.com>

On 12/10/23 18:26, Peng Liang wrote:
> On 10/12/2023 18:53, Philippe Mathieu-Daudé wrote:
>> Hi Martin, Paolo, Markus, Marc-André,
>>
>> With the following changes:
>>
>> -- >8 --
>> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
>> index 137276bcb9..291495f798 100644
>> --- a/hw/ppc/prep.c
>> +++ b/hw/ppc/prep.c
>> @@ -245,6 +245,7 @@ static void ibm_40p_init(MachineState *machine)
>>       uint32_t kernel_base = 0, initrd_base = 0;
>>       long kernel_size = 0, initrd_size = 0;
>>       char boot_device;
>> +    MemoryRegion rom;
>>
>>       if (kvm_enabled()) {
>>           error_report("machine %s does not support the KVM accelerator",
>> @@ -277,6 +278,9 @@ static void ibm_40p_init(MachineState *machine)
>>           exit(1);
>>       }
>>
>> +    memory_region_init_rom_nomigrate(&rom, OBJECT(machine), "test",
>> +                                     4 * KiB, &error_fatal);
>> +
>>       /* PCI -> ISA bridge */
>>       i82378_dev = DEVICE(pci_new(PCI_DEVFN(11, 0), "i82378"));
>>       qdev_connect_gpio_out(i82378_dev, 0,
>>
>> ---
> 
> I think it can be fixed by changing the type of rom to MemoryRegion*, such as:
> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> index 137276bcb9..b5c2345ec8 100644
> --- a/hw/ppc/prep.c
> +++ b/hw/ppc/prep.c
> @@ -245,6 +245,7 @@ static void ibm_40p_init(MachineState *machine)
>       uint32_t kernel_base = 0, initrd_base = 0;
>       long kernel_size = 0, initrd_size = 0;
>       char boot_device;
> +    MemoryRegion *rom = g_new0(MemoryRegion, 1);
> 
>       if (kvm_enabled()) {
>           error_report("machine %s does not support the KVM accelerator",
> @@ -277,6 +278,9 @@ static void ibm_40p_init(MachineState *machine)
>           exit(1);
>       }
> 
> +    memory_region_init_rom_nomigrate(rom, OBJECT(machine), "test", 4 * KiB,
> +                                     &error_fatal);
> +
>       /* PCI -> ISA bridge */
>       i82378_dev = DEVICE(pci_new(PCI_DEVFN(11, 0), "i82378"));
>       qdev_connect_gpio_out(i82378_dev, 0,
> ---
> 
> In the original patch, rom is an object on stack and machine will save a reference
> to rom in its properties after memory_region_init_rom_nomigrate. When the function
> returns, the stack frame is freed and the data in rom becomes to garbage. After that,
> when we call object_resolve_path_type, the properties of machine will be used to
> match the specific path and type, then we will use some garbage in rom (which is on
> stack).

YES! Stupid mistake... Thank you Peng, you saved my day :)



      reply	other threads:[~2023-10-12 16:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 10:53 QOM crash via soundhw_init() Philippe Mathieu-Daudé
2023-10-12 16:26 ` Peng Liang
2023-10-12 16:48   ` Philippe Mathieu-Daudé [this message]

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=6522c5f6-0d78-1344-c3ee-76b83f39942b@linaro.org \
    --to=philmd@linaro.org \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mkletzan@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tcx4c70@gmail.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 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).