All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
@ 2022-02-10 13:28 Ani Sinha
  2022-02-10 16:10 ` Philippe Mathieu-Daudé via
  2022-02-23  9:04 ` Igor Mammedov
  0 siblings, 2 replies; 9+ messages in thread
From: Ani Sinha @ 2022-02-10 13:28 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	Michael S. Tsirkin, Marcel Apfelbaum
  Cc: Ani Sinha, kraxel

When adding E820_RESERVED entries we also accidentally allocate dynamic
entries. This is incorrect. We should simply return early with the count of
the number of reserved entries added.

fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
cc: kraxel@redhat.com
Signed-off-by: Ani Sinha <ani@anisinha.ca>
---
 hw/i386/e820_memory_layout.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
index bcf9eaf837..afb08253a4 100644
--- a/hw/i386/e820_memory_layout.c
+++ b/hw/i386/e820_memory_layout.c
@@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
         entry->type = cpu_to_le32(type);
 
         e820_reserve.count = cpu_to_le32(index);
+
+        return index;
     }
 
     /* new "etc/e820" file -- include ram too */
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-10 13:28 [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries Ani Sinha
@ 2022-02-10 16:10 ` Philippe Mathieu-Daudé via
  2022-02-11 11:19   ` Ani Sinha
  2022-02-23  9:04 ` Igor Mammedov
  1 sibling, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-02-10 16:10 UTC (permalink / raw)
  To: Ani Sinha, qemu-devel, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, Michael S. Tsirkin, Marcel Apfelbaum
  Cc: kraxel

On 10/2/22 14:28, Ani Sinha wrote:
> When adding E820_RESERVED entries we also accidentally allocate dynamic
> entries. This is incorrect. We should simply return early with the count of
> the number of reserved entries added.
> 
> fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")

8 years old, so this path is clearly untested (unused...?).

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> cc: kraxel@redhat.com
> Signed-off-by: Ani Sinha <ani@anisinha.ca>
> ---
>   hw/i386/e820_memory_layout.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> index bcf9eaf837..afb08253a4 100644
> --- a/hw/i386/e820_memory_layout.c
> +++ b/hw/i386/e820_memory_layout.c
> @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
>           entry->type = cpu_to_le32(type);
>   
>           e820_reserve.count = cpu_to_le32(index);
> +
> +        return index;
>       }
>   
>       /* new "etc/e820" file -- include ram too */



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-10 16:10 ` Philippe Mathieu-Daudé via
@ 2022-02-11 11:19   ` Ani Sinha
  0 siblings, 0 replies; 9+ messages in thread
From: Ani Sinha @ 2022-02-11 11:19 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Ani Sinha, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 718 bytes --]



On Thu, 10 Feb 2022, Philippe Mathieu-Daudé wrote:

> On 10/2/22 14:28, Ani Sinha wrote:
> > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > entries. This is incorrect. We should simply return early with the count of
> > the number of reserved entries added.
> >
> > fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
>
> 8 years old, so this path is clearly untested (unused...?).
>

untested, yes. unused? nope!

$ git grep e820_add_entry  2>/dev/null | grep E820_RESERVED
hw/i386/pc.c:        e820_add_entry(pcms->sgx_epc.base,
pcms->sgx_epc.size, E820_RESERVED);
target/i386/kvm/kvm.c:    ret = e820_add_entry(identity_base, 0x4000,
E820_RESERVED);

particulatly the kvm code path.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-10 13:28 [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries Ani Sinha
  2022-02-10 16:10 ` Philippe Mathieu-Daudé via
@ 2022-02-23  9:04 ` Igor Mammedov
  2022-02-23 12:00   ` Ani Sinha
  1 sibling, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2022-02-23  9:04 UTC (permalink / raw)
  To: Ani Sinha
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Thu, 10 Feb 2022 18:58:21 +0530
Ani Sinha <ani@anisinha.ca> wrote:

> When adding E820_RESERVED entries we also accidentally allocate dynamic
> entries. This is incorrect. We should simply return early with the count of
> the number of reserved entries added.

can you expand commit message to explain what's wrong and
how problem manifests ... etc.

> 
> fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
> cc: kraxel@redhat.com
> Signed-off-by: Ani Sinha <ani@anisinha.ca>
> ---
>  hw/i386/e820_memory_layout.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> index bcf9eaf837..afb08253a4 100644
> --- a/hw/i386/e820_memory_layout.c
> +++ b/hw/i386/e820_memory_layout.c
> @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
>          entry->type = cpu_to_le32(type);
>  
>          e820_reserve.count = cpu_to_le32(index);
> +
> +        return index;
>      }

this changes e820_table size/content, which is added by fw_cfg_add_file() to fwcfg,
as result it breaks ABI in case of migration.
>  
>      /* new "etc/e820" file -- include ram too */



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-23  9:04 ` Igor Mammedov
@ 2022-02-23 12:00   ` Ani Sinha
  2022-02-24  9:03     ` Igor Mammedov
  0 siblings, 1 reply; 9+ messages in thread
From: Ani Sinha @ 2022-02-23 12:00 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Wed, Feb 23, 2022 at 2:34 PM Igor Mammedov <imammedo@redhat.com> wrote:
>
> On Thu, 10 Feb 2022 18:58:21 +0530
> Ani Sinha <ani@anisinha.ca> wrote:
>
> > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > entries. This is incorrect. We should simply return early with the count of
> > the number of reserved entries added.
>
> can you expand commit message to explain what's wrong and
> how problem manifests ... etc.

The issue has been present for the last 8 years without apparent
visible issues. I think the only issue is that the bug allocates more
memory in the firmware than is actually needed.

>
> >
> > fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
> > cc: kraxel@redhat.com
> > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > ---
> >  hw/i386/e820_memory_layout.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> > index bcf9eaf837..afb08253a4 100644
> > --- a/hw/i386/e820_memory_layout.c
> > +++ b/hw/i386/e820_memory_layout.c
> > @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
> >          entry->type = cpu_to_le32(type);
> >
> >          e820_reserve.count = cpu_to_le32(index);
> > +
> > +        return index;
> >      }
>
> this changes e820_table size/content, which is added by fw_cfg_add_file() to fwcfg,
> as result it breaks ABI in case of migration.

Ugh. So should we keep the bug? or do we add config setting to handle
the ABI breakage.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-23 12:00   ` Ani Sinha
@ 2022-02-24  9:03     ` Igor Mammedov
  2022-02-24 12:44       ` Ani Sinha
  0 siblings, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2022-02-24  9:03 UTC (permalink / raw)
  To: Ani Sinha
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Wed, 23 Feb 2022 17:30:34 +0530
Ani Sinha <ani@anisinha.ca> wrote:

> On Wed, Feb 23, 2022 at 2:34 PM Igor Mammedov <imammedo@redhat.com> wrote:
> >
> > On Thu, 10 Feb 2022 18:58:21 +0530
> > Ani Sinha <ani@anisinha.ca> wrote:
> >  
> > > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > > entries. This is incorrect. We should simply return early with the count of
> > > the number of reserved entries added.  
> >
> > can you expand commit message to explain what's wrong and
> > how problem manifests ... etc.  
> 
> The issue has been present for the last 8 years without apparent
> visible issues. I think the only issue is that the bug allocates more
> memory in the firmware than is actually needed.

let me repeat: Why do you think it's an issue or why it's wrong

> 
> >  
> > >
> > > fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
> > > cc: kraxel@redhat.com
> > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > ---
> > >  hw/i386/e820_memory_layout.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> > > index bcf9eaf837..afb08253a4 100644
> > > --- a/hw/i386/e820_memory_layout.c
> > > +++ b/hw/i386/e820_memory_layout.c
> > > @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
> > >          entry->type = cpu_to_le32(type);
> > >
> > >          e820_reserve.count = cpu_to_le32(index);
> > > +
> > > +        return index;
> > >      }  
> >
> > this changes e820_table size/content, which is added by fw_cfg_add_file() to fwcfg,
> > as result it breaks ABI in case of migration.  
> 
> Ugh. So should we keep the bug? or do we add config setting to handle
> the ABI breakage.
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-24  9:03     ` Igor Mammedov
@ 2022-02-24 12:44       ` Ani Sinha
  2022-02-24 13:21         ` Igor Mammedov
  0 siblings, 1 reply; 9+ messages in thread
From: Ani Sinha @ 2022-02-24 12:44 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Thu, Feb 24, 2022 at 2:33 PM Igor Mammedov <imammedo@redhat.com> wrote:
>
> On Wed, 23 Feb 2022 17:30:34 +0530
> Ani Sinha <ani@anisinha.ca> wrote:
>
> > On Wed, Feb 23, 2022 at 2:34 PM Igor Mammedov <imammedo@redhat.com> wrote:
> > >
> > > On Thu, 10 Feb 2022 18:58:21 +0530
> > > Ani Sinha <ani@anisinha.ca> wrote:
> > >
> > > > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > > > entries. This is incorrect. We should simply return early with the count of
> > > > the number of reserved entries added.
> > >
> > > can you expand commit message to explain what's wrong and
> > > how problem manifests ... etc.
> >
> > The issue has been present for the last 8 years without apparent
> > visible issues. I think the only issue is that the bug allocates more
> > memory in the firmware than is actually needed.
>
> let me repeat: Why do you think it's an issue or why it's wrong

Allocating more memory than what we need unnecessarily bloats up the
rom. We should not be allocating memory that we do not use.

>
> >
> > >
> > > >
> > > > fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
> > > > cc: kraxel@redhat.com
> > > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > > ---
> > > >  hw/i386/e820_memory_layout.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > >
> > > > diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> > > > index bcf9eaf837..afb08253a4 100644
> > > > --- a/hw/i386/e820_memory_layout.c
> > > > +++ b/hw/i386/e820_memory_layout.c
> > > > @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
> > > >          entry->type = cpu_to_le32(type);
> > > >
> > > >          e820_reserve.count = cpu_to_le32(index);
> > > > +
> > > > +        return index;
> > > >      }
> > >
> > > this changes e820_table size/content, which is added by fw_cfg_add_file() to fwcfg,
> > > as result it breaks ABI in case of migration.
> >
> > Ugh. So should we keep the bug? or do we add config setting to handle
> > the ABI breakage.
> >
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-24 12:44       ` Ani Sinha
@ 2022-02-24 13:21         ` Igor Mammedov
  2022-02-28 10:28           ` Ani Sinha
  0 siblings, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2022-02-24 13:21 UTC (permalink / raw)
  To: Ani Sinha
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Thu, 24 Feb 2022 18:14:35 +0530
Ani Sinha <ani@anisinha.ca> wrote:

> On Thu, Feb 24, 2022 at 2:33 PM Igor Mammedov <imammedo@redhat.com> wrote:
> >
> > On Wed, 23 Feb 2022 17:30:34 +0530
> > Ani Sinha <ani@anisinha.ca> wrote:
> >  
> > > On Wed, Feb 23, 2022 at 2:34 PM Igor Mammedov <imammedo@redhat.com> wrote:  
> > > >
> > > > On Thu, 10 Feb 2022 18:58:21 +0530
> > > > Ani Sinha <ani@anisinha.ca> wrote:
> > > >  
> > > > > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > > > > entries. This is incorrect. We should simply return early with the count of
> > > > > the number of reserved entries added.  
> > > >
> > > > can you expand commit message to explain what's wrong and
> > > > how problem manifests ... etc.  
> > >
> > > The issue has been present for the last 8 years without apparent
> > > visible issues. I think the only issue is that the bug allocates more
> > > memory in the firmware than is actually needed.  
> >
> > let me repeat: Why do you think it's an issue or why it's wrong  
> 
> Allocating more memory than what we need unnecessarily bloats up the
> rom. We should not be allocating memory that we do not use.

see how firmware uses "etc/e820" fwcfg file first, to make up
mind on 'need' part.

> 
> >  
> > >  
> > > >  
> > > > >
> > > > > fixes: 7d67110f2d9a6("pc: add etc/e820 fw_cfg file")
> > > > > cc: kraxel@redhat.com
> > > > > Signed-off-by: Ani Sinha <ani@anisinha.ca>
> > > > > ---
> > > > >  hw/i386/e820_memory_layout.c | 2 ++
> > > > >  1 file changed, 2 insertions(+)
> > > > >
> > > > > diff --git a/hw/i386/e820_memory_layout.c b/hw/i386/e820_memory_layout.c
> > > > > index bcf9eaf837..afb08253a4 100644
> > > > > --- a/hw/i386/e820_memory_layout.c
> > > > > +++ b/hw/i386/e820_memory_layout.c
> > > > > @@ -31,6 +31,8 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
> > > > >          entry->type = cpu_to_le32(type);
> > > > >
> > > > >          e820_reserve.count = cpu_to_le32(index);
> > > > > +
> > > > > +        return index;
> > > > >      }  
> > > >
> > > > this changes e820_table size/content, which is added by fw_cfg_add_file() to fwcfg,
> > > > as result it breaks ABI in case of migration.  
> > >
> > > Ugh. So should we keep the bug? or do we add config setting to handle
> > > the ABI breakage.
> > >  
> >  
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries
  2022-02-24 13:21         ` Igor Mammedov
@ 2022-02-28 10:28           ` Ani Sinha
  0 siblings, 0 replies; 9+ messages in thread
From: Ani Sinha @ 2022-02-28 10:28 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
	qemu-devel, kraxel, Paolo Bonzini

On Thu, Feb 24, 2022 at 6:51 PM Igor Mammedov <imammedo@redhat.com> wrote:
>
> On Thu, 24 Feb 2022 18:14:35 +0530
> Ani Sinha <ani@anisinha.ca> wrote:
>
> > On Thu, Feb 24, 2022 at 2:33 PM Igor Mammedov <imammedo@redhat.com> wrote:
> > >
> > > On Wed, 23 Feb 2022 17:30:34 +0530
> > > Ani Sinha <ani@anisinha.ca> wrote:
> > >
> > > > On Wed, Feb 23, 2022 at 2:34 PM Igor Mammedov <imammedo@redhat.com> wrote:
> > > > >
> > > > > On Thu, 10 Feb 2022 18:58:21 +0530
> > > > > Ani Sinha <ani@anisinha.ca> wrote:
> > > > >
> > > > > > When adding E820_RESERVED entries we also accidentally allocate dynamic
> > > > > > entries. This is incorrect. We should simply return early with the count of
> > > > > > the number of reserved entries added.
> > > > >
> > > > > can you expand commit message to explain what's wrong and
> > > > > how problem manifests ... etc.
> > > >
> > > > The issue has been present for the last 8 years without apparent
> > > > visible issues. I think the only issue is that the bug allocates more
> > > > memory in the firmware than is actually needed.
> > >
> > > let me repeat: Why do you think it's an issue or why it's wrong
> >
> > Allocating more memory than what we need unnecessarily bloats up the
> > rom. We should not be allocating memory that we do not use.
>
> see how firmware uses "etc/e820" fwcfg file first, to make up
> mind on 'need' part.
>

This patch is certainly wrong. For ref, please see the following
commit in seabios from Gerd:

ce39bd40318203dd30faa ("Add support for etc/e820 fw_cfg file")

"etc/e820" is supposed to have both E820_RESERVED and E820_RAM entries.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-28 10:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 13:28 [PATCH] hw/i386/pc: when adding reserved E820 entries do not allocate dynamic entries Ani Sinha
2022-02-10 16:10 ` Philippe Mathieu-Daudé via
2022-02-11 11:19   ` Ani Sinha
2022-02-23  9:04 ` Igor Mammedov
2022-02-23 12:00   ` Ani Sinha
2022-02-24  9:03     ` Igor Mammedov
2022-02-24 12:44       ` Ani Sinha
2022-02-24 13:21         ` Igor Mammedov
2022-02-28 10:28           ` Ani Sinha

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.