Sort the fw_cfg file list
PATCH v2 1/1 Sort the fw_cfg file list
From: Gerd Hoffmann <[email protected]>
Entries are inserted at the correct place instead of being appended to the end in case sorting is enabled.
Added a machine type handling for compatibility.
---
Don't add a new machine type in this version, just use the 2.6 one.
hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/nvram/fw_cfg.c | 32 ++++++++++++++++++++++++++------ include/hw/boards.h | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-)
hw/i386/pc_piix.c +1 -0
@@ -429,6 +429,7 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) m->alias =NULL ; m->is_default =0 ; pcmc->save_tsc_khz = false; + m->dont_sort_fw_cfgs =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }
hw/i386/pc_q35.c +1 -0
@@ -354,6 +354,7 @@ static void pc_q35_2_5_machine_options(MachineClass *m)pc_q35_2_6_machine_options (m); m->alias =NULL ; pcmc->save_tsc_khz = false; + m->dont_sort_fw_cfgs =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }
hw/nvram/fw_cfg.c +26 -6
@@ -28,6 +28,7 @@#include "hw/isa/isa.h" #include "hw/nvram/fw_cfg.h" #include "hw/sysbus.h" +#include "hw/boards.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/config-file.h"
@@ -669,8 +670,9 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, FWCfgReadCallback callback, void *callback_opaque, void *data, size_t len) { - int i, index; + int i, index, count;size_t dsize; +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ());if (!s->files) { dsize =sizeof (uint32_t ) +sizeof (FWCfgFile) *FW_CFG_FILE_SLOTS ;
@@ -678,13 +680,31 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,fw_cfg_add_bytes (s,FW_CFG_FILE_DIR , s->files, dsize); } - index =be32_to_cpu (s->files->count); -assert (index <FW_CFG_FILE_SLOTS ); + count =be32_to_cpu (s->files->count); +assert (count <FW_CFG_FILE_SLOTS ); + + index = count; +if (!mc->dont_sort_fw_cfgs) { +while (index >0 &&strcmp (filename, s->files->f[index-1 ].name) <0 ) { + s->files->f[index] = + s->files->f[index -1 ]; + s->files->f[index].select = +cpu_to_be16 (FW_CFG_FILE_FIRST + index); + s->entries[0 ][FW_CFG_FILE_FIRST + index] = + s->entries[0 ][FW_CFG_FILE_FIRST + index -1 ]; + index--; + } +memset (&s->files->f[index], +0 ,sizeof (FWCfgFile)); +memset (&s->entries[0 ][FW_CFG_FILE_FIRST + index], +0 ,sizeof (FWCfgEntry)); + }pstrcpy (s->files->f[index].name,sizeof (s->files->f[index].name), filename); -for (i =0 ; i < index; i++) { -if (strcmp (s->files->f[index].name, s->files->f[i].name) ==0 ) { +for (i =0 ; i <= count; i++) { +if (i != index && +strcmp (s->files->f[index].name, s->files->f[i].name) ==0 ) {error_report ("duplicate fw_cfg file name: %s" , s->files->f[index].name);exit (1 );
@@ -698,7 +718,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, s->files->f[index].select =cpu_to_be16 (FW_CFG_FILE_FIRST + index);trace_fw_cfg_add_file (s, index, s->files->f[index].name, len); - s->files->count =cpu_to_be32 (index+1 ); + s->files->count =cpu_to_be32 (count+1 ); } void fw_cfg_add_file(FWCfgState *s, const char *filename,
include/hw/boards.h +2 -1
@@ -85,7 +85,8 @@ struct MachineClass { no_sdcard:1, has_dynamic_sysbus:1, no_tco:1, - pci_allow_0_address:1; + pci_allow_0_address:1, + dont_sort_fw_cfgs:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
Signature · 1 line
2.5.0
Quoted 5 lines · On Mon, Mar 14, 2016 at 11:55:31PM +0700, [email protected] wrote:
From: Gerd Hoffmann <[email protected]>
Entries are inserted at the correct place instead of being appended to the end in case sorting is enabled.
Quoted 8 lines
Signed-off-by Gerd Hoffmann <[email protected]>Added a machine type handling for compatibility.
Signed-off-by Corey Minyard <[email protected]>---
Don't add a new machine type in this version, just use the 2.6 one.
Unfortunately this patch won't help any, as your next patch reorders fw cfg files which will affect the old machine types.
What is needed is not dont_sort_fw_cfgs, instead we need to create a list of existing fw cfg files in the order they appear currently, and sort them according to this predefined order (at least for old machine types).
Quoted 114 lines
hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/nvram/fw_cfg.c | 32 ++++++++++++++++++++++++++------ include/hw/boards.h | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-)hw/i386/pc_piix.c +1
-0@@ -429,6 +429,7 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) m->alias =NULL ; m->is_default =0 ; pcmc->save_tsc_khz = false; + m->dont_sort_fw_cfgs =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }hw/i386/pc_q35.c +1
-0@@ -354,6 +354,7 @@ static void pc_q35_2_5_machine_options(MachineClass *m)pc_q35_2_6_machine_options (m); m->alias =NULL ; pcmc->save_tsc_khz = false; + m->dont_sort_fw_cfgs =1 ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_5 ); }hw/nvram/fw_cfg.c +26
-6@@ -28,6 +28,7 @@#include "hw/isa/isa.h" #include "hw/nvram/fw_cfg.h" #include "hw/sysbus.h" +#include "hw/boards.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/config-file.h" @@ -669,8 +670,9 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, FWCfgReadCallback callback, void *callback_opaque, void *data, size_t len) { - int i, index; + int i, index, count;size_t dsize; +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ());if (!s->files) { dsize =sizeof (uint32_t ) +sizeof (FWCfgFile) *FW_CFG_FILE_SLOTS ;@@ -678,13 +680,31 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,fw_cfg_add_bytes (s,FW_CFG_FILE_DIR , s->files, dsize); } - index =be32_to_cpu (s->files->count); -assert (index <FW_CFG_FILE_SLOTS ); + count =be32_to_cpu (s->files->count); +assert (count <FW_CFG_FILE_SLOTS ); + + index = count; +if (!mc->dont_sort_fw_cfgs) { +while (index >0 &&strcmp (filename, s->files->f[index-1 ].name) <0 ) { + s->files->f[index] = + s->files->f[index -1 ]; + s->files->f[index].select = +cpu_to_be16 (FW_CFG_FILE_FIRST + index); + s->entries[0 ][FW_CFG_FILE_FIRST + index] = + s->entries[0 ][FW_CFG_FILE_FIRST + index -1 ]; + index--; + } +memset (&s->files->f[index], +0 ,sizeof (FWCfgFile)); +memset (&s->entries[0 ][FW_CFG_FILE_FIRST + index], +0 ,sizeof (FWCfgEntry)); + }pstrcpy (s->files->f[index].name,sizeof (s->files->f[index].name), filename); -for (i =0 ; i < index; i++) { -if (strcmp (s->files->f[index].name, s->files->f[i].name) ==0 ) { +for (i =0 ; i <= count; i++) { +if (i != index && +strcmp (s->files->f[index].name, s->files->f[i].name) ==0 ) {error_report ("duplicate fw_cfg file name: %s" , s->files->f[index].name);exit (1 );@@ -698,7 +718,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, s->files->f[index].select =cpu_to_be16 (FW_CFG_FILE_FIRST + index);trace_fw_cfg_add_file (s, index, s->files->f[index].name, len); - s->files->count =cpu_to_be32 (index+1 ); + s->files->count =cpu_to_be32 (count+1 ); } void fw_cfg_add_file(FWCfgState *s, const char *filename,include/hw/boards.h +2
-1@@ -85,7 +85,8 @@ struct MachineClass { no_sdcard:1, has_dynamic_sysbus:1, no_tco:1, - pci_allow_0_address:1; + pci_allow_0_address:1, + dont_sort_fw_cfgs:1;int is_default;const char *default_machine_opts;const char *default_boot_order;Signature · 1 line
2.5.0
Hi,
Quoted 4 lines
Quoted 1 line
Don't add a new machine type in this version, just use the 2.6 one.
Unfortunately this patch won't help any, as your next patch reorders fw cfg files which will affect the old machine types.
We can make that depend on dont_sort_fw_cfgs too, to keep things as-is
on old machine types. Which probably implies only new machine types
will see the new smbios entries.
cheers,
Gerd
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
Quoted 1 line
Don't add a new machine type in this version, just use the 2.6 one.
Unfortunately this patch won't help any, as your next patch reorders fw cfg files which will affect the old machine types.
We can make that depend on
dont_sort_fw_cfgstoo, to keep things as-is on old machine types.
Yes, except the name is a bit off then. It's more "legacy_fw_cfg_order" than "dont_sort_fw_cfgs".
Quoted 5 lines
Which probably implies only new machine types
will see the new smbios entries.cheers,
Gerd
Not really I think.
If there's a new device triggering a new smbios entry, we don't care how it's sorted since by then there's no question of cross-version migration with old QEMU.
Signature · 1 line
MST
Quoted 17 lines · Michael S. Tsirkin
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
Quoted 1 line
Don't add a new machine type in this version, just use the 2.6 one.
Unfortunately this patch won't help any, as your next patch reorders fw cfg files which will affect the old machine types.
We can make that depend on
dont_sort_fw_cfgstoo, to keep things as-is on old machine types.Yes, except the name is a bit off then. It's more "
legacy_fw_cfg_order" than "dont_sort_fw_cfgs".Quoted 3 lines
Which probably implies only new machine types
will see the new smbios entries.
Quoted 7 lines
Quoted 2 lines
cheers,
GerdNot really I think.
If there's a new device triggering a new smbios entry, we don't care how it's sorted since by then there's no question of cross-version migration with old QEMU.
As I understand things the smbios fw_cfg file must be created later to make new entries (created by devices) are actually visible. So we can make that initialization order change depend on dont_sort_fw_cfgs (or legacy_fw_cfg_order) too. That way we maintain the ordering for old machine types. But old machine types then will also not see the entries added by devices. Which isn't a problem I think, old qemu versions don't have support for that device in the first place ...
Corey, can you please send all this in a patch series? This should make those dependencies more clear ...
thanks,
Gerd
Quoted 1 line
Quoted 26 lines · Gerd Hoffmann
Quoted 17 lines · Michael S. Tsirkin
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
Quoted 1 line
Don't add a new machine type in this version, just use the 2.6 one.
Unfortunately this patch won't help any, as your next patch reorders fw cfg files which will affect the old machine types.
We can make that depend on
dont_sort_fw_cfgstoo, to keep things as-is on old machine types.Yes, except the name is a bit off then. It's more "
legacy_fw_cfg_order" than "dont_sort_fw_cfgs".Quoted 3 lines
Which probably implies only new machine types
will see the new smbios entries.Quoted 7 lines
Quoted 2 lines
cheers,
GerdNot really I think.
If there's a new device triggering a new smbios entry, we don't care how it's sorted since by then there's no question of cross-version migration with old QEMU.
Quoted 5 lines
As I understand things the smbios
fw_cfgfile must be created later to make new entries (created by devices) are actually visible. So we can make that initialization order change depend ondont_sort_fw_cfgs(orlegacy_fw_cfg_order) too. That way we maintain the ordering for old machine types.
Yes.
Quoted 3 lines
But old machine types then will also not see the entries added by devices. Which isn't a problem I think, old qemu versions don't have support for that device in the first place ...
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them. It's trivially easy and more user-friendly. Simply sort anything that is not on the list alphabetically and add it at the end.
Quoted 7 lines
Corey, can you please send all this in a patch series? This should make those dependencies more clear ...
thanks,
GerdQuoted 1 line
So like this:
fw_cfg_find(a) {
for (index = 0; index < fw_cfg_legacy_array_size; ++index)
if (!strcmp(a, ...))
break;
return index;
}fw_cfg_cmp(a, b) {
in cmp;
if (legacy_fw_cfg_order) {
int list1 = find(a);
int list2 = find(b);
if (list1 < list2)
return -1;
if (list1 > list2)
return 1;
}
return strcmp(a, b);
}This way anything not on list is sorted,
with !legacy_fw_cfg_order list is assumed empty.
Signature · 1 line
MST
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.
Not a new fw_cfg file.
It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the fw_cfg directory.
So old machine types initialize smbios early (for compatibility).
New machine types initialize smbios late (so guests see the new records).
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the fw_cfg directory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.
cheers,
Gerd
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.
Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.
Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);
where:
fw_cfg_find(a) {
for (index = 0; index < fw_cfg_legacy_array_size; ++index)
if (!strcmp(a, ...))
break;
return index;
}fw_cfg_cmp(a, b) {
in cmp;
if (legacy_fw_cfg_order) {
int list1 = find(a);
int list2 = find(b);
if (list1 < list2)
return -1;
if (list1 > list2)
return 1;
}
return strcmp(a, b);
}Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
Gerd
What exactly do you mean by directory entries here?
Signature · 1 line
MST
Quoted 45 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order. for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }
Quoted 14 lines
fw_cfg_cmp(a, b) {
in cmp;
if (legacy_fw_cfg_order) {
int list1 = find(a);
int list2 = find(b);
if (list1 < list2)
return -1;
if (list1 > list2)
return 1;
}
return strcmp(a, b);
}Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
Instead, you could add a "legacy_order" parameter to the fw_cfg_add functions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass in NO_FW_CFG_LEGACY_ORDER or something like that and be pasted onto the end in legacy mode.
-corey
Quoted 15 lines
Quoted 6 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Quoted 58 lines · Corey Minyard
Quoted 57 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; }
Quoted 7 lines
Quoted 2 lines
return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.
Quoted 9 lines
Instead, you could add a "
legacy_order" parameter to thefw_cfg_addfunctions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass inNO_FW_CFG_LEGACY_ORDERor something like that and be pasted onto the end in legacy mode.-corey
OK but it's a much larger change and less well contained.
Quoted 15 lines
Quoted 15 lines
Quoted 6 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Quoted 64 lines · Michael S. Tsirkin
Quoted 57 lines · Corey Minyard
Quoted 56 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order. for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; }Quoted 6 lines
Quoted 2 lines
return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
Quoted 5 lines
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.
You get a warning if it doesn't start with "opt/", but that is not enforced.
Quoted 11 lines
Quoted 10 lines
Instead, you could add a "
legacy_order" parameter to thefw_cfg_addfunctions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass inNO_FW_CFG_LEGACY_ORDERor something like that and be pasted onto the end in legacy mode.-corey
OK but it's a much larger change and less well contained.
True, it is less well contained. If we want to assume the command line entries always start with "opt/", then going with a list of file names works and is simpler. Otherwise I don't see another way to preserve order.
-corey
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Hi,
Quoted 8 lines
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
What is the point of using *two* ways to sort entries?
Sure, we can explicitly write down the current order of fw_cfg entries and use that to sort them, so order stays as-is even if the initialization order changes. But when going that route I would do that *instead* of the alphabetical ordering, for all machine types.
cheers,
Gerd
Quoted 13 lines · Gerd Hoffmann
Hi,
Quoted 8 lines
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:What is the point of using *two* ways to sort entries?
Quoted 7 lines
Sure, we can explicitly write down the current order of
fw_cfgentries and use that to sort them, so order stays as-is even if the initialization order changes. But when going that route I would do that *instead* of the alphabetical ordering, for all machine types.cheers,
Gerd
That's fine too.
The only question is for when we add new fw cfg entries:
do you want to add these to the list as well?
Sorting new entries after old ones will help
avoid future maintainance for this list:
we set it once and never change it.
Signature · 1 line
MST
Quoted 65 lines · Corey Minyard
Quoted 64 lines · Michael S. Tsirkin
Quoted 63 lines · Corey Minyard
Quoted 44 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }Quoted 14 lines
fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; } return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
Quoted 8 lines
Quoted 5 lines
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.You get a warning if it doesn't start with "opt/", but that is not enforced.
Why don't we enforce it? It seems very dangerous to allow arbitrary names as they may conflict with builtin ones down the road. Here's a patch - pls feel free to include this in your patchset.
--->
vl.c: disallow command line fw cfg without opt/
Allowing arbitary file names on command line is setting us up for
failure: future guests will look for a specific QEMU-specified name and will get confused finding a user file there.
---
vl.c | 1 + 1 file changed, 1 insertion(+)
vl.c +1 -0
@@ -2321,6 +2321,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)if (strncmp (name,"opt/" ,4 ) !=0 ) {error_report ("warning: externally provided fw_cfg item names " "should be prefixed with \"opt/\"" ); +return -1 ; }if (nonempty_str (str)) { size =strlen (str);/* NUL terminator NOT included in fw_cfg blob */
Signature · 1 line
MST
Quoted 83 lines · Corey Minyard
Quoted 64 lines · Michael S. Tsirkin
Quoted 57 lines · Corey Minyard
Quoted 56 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; }Quoted 6 lines
Quoted 2 lines
return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
Quoted 5 lines
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.You get a warning if it doesn't start with "opt/", but that is not enforced.
Quoted 9 lines
Quoted 9 lines
Instead, you could add a "
legacy_order" parameter to thefw_cfg_addfunctions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass inNO_FW_CFG_LEGACY_ORDERor something like that and be pasted onto the end in legacy mode.
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
-corey
OK but it's a much larger change and less well contained.
True, it is less well contained. If we want to assume the command line entries always start with "opt/",
Basically what Gerd and Paolo say, yes it is safe to assume this, even if QEMU does not exit, using a different prefix is user's problem.
Quoted 20 lines
then going
with a list of file names works and is simpler. Otherwise I don't see another way to preserve order.-corey
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Corey Minyard
Quoted 26 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order. for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);
I've hit a bit of a snag here. For 0.11 and before, PCI option ROMs were loaded via fw_cfg, not in the PCI ROM BAR. This causes two issues:
* The order depends on the device initialization order, which I'm not sure is quantifiable. I believe it depends on how they are listed on the command line.
* Users can load their own romfile with their own name, which means it can't be in the list.
Also, for the ISA VGA ROMs, their order will also depend on the device list order.
Outside of that, I have an order of file names.
I think if I treat the device ROMs separately and handle them in init order, and then stick that device list in the proper location, that will work. Does that sound reasonable?
Thanks,
-corey
Quoted 58 lines
Quoted 21 lines
Quoted 21 lines
where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; }Quoted 6 lines
Quoted 2 lines
return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.Quoted 9 lines
Instead, you could add a "
legacy_order" parameter to thefw_cfg_addfunctions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass inNO_FW_CFG_LEGACY_ORDERor something like that and be pasted onto the end in legacy mode.-corey
OK but it's a much larger change and less well contained.
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Quoted 54 lines · Corey Minyard
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Corey Minyard
Quoted 26 lines · Michael S. Tsirkin
Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Depends on how you code it up. We have a list, we look each file there and sort accordingly. Fine.
New devices will not be on this list, I guess you can just ignore them and guests will not see them. OK but I think it is better to make old machine types see them.Quoted 8 lines
Not a new
fw_cfgfile.It's existing smbios file which gets new records added by a new device. So when initializing it early (old order) it doesn't (yet) contain the new records. When initializing it late it has them, but also has a different place in the
fw_cfgdirectory.So old machine types initialize smbios early (for compatibility).
I see. So in this model, we'd have to somehow keep track of the old initialization order forever, and
add hacks whenever we change it.
IMHO That would just be too hard to maintain. I have an alternative proposal.Quoted 2 lines
New machine types initialize smbios late (so guests see the new records).
So here is what I propose instead:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- always initialize it late
- sort late, a machine done, not when inserting entries
- figure out what the order of existing entries is currently, and fill an array listing them in this order.
for old machine types, insert the existing entries in this specific order by using a sorting function:
qsort(....., fw_cfg_cmp);I've hit a bit of a snag here. For 0.11 and before, PCI option ROMs were loaded via
fw_cfg, not in the PCI ROM BAR. This causes two issues:* The order depends on the device initialization order, which I'm not sure is quantifiable. I believe it depends on how they are listed on the command line.
* Users can load their own romfile with their own name, which means it can't be in the list.
Also, for the ISA VGA ROMs, their order will also depend on the device list order.
Outside of that, I have an order of file names.
Quoted 7 lines
I think if I treat the device ROMs separately and handle them in init order, and then stick that device list in the proper location, that will work. Does that sound reasonable?
Thanks,
-corey
I think so. By the time this becomes an issue we might decide to disable migration from 0.11
Quoted 58 lines
Quoted 58 lines
Quoted 21 lines
Quoted 21 lines
where:
fw_cfg_find(a) { for (index = 0; index < fw_cfg_legacy_array_size; ++index) if (!strcmp(a, ...)) break; return index; }fw_cfg_cmp(a, b) { in cmp; if (legacy_fw_cfg_order) { int list1 = find(a); int list2 = find(b); if (list1 < list2) return -1; if (list1 > list2) return 1; }Quoted 6 lines
Quoted 2 lines
return strcmp(a, b); }Last night I had an idea something like this. Sorting by filename may not work because the user may pass in the file from the command line and you wouldn't be able to track the file name that way.
command line files must all have a consistent prefix, so we can skip sorting them.
I'll need to look at the code - don't they already? If not we IMHO absolutely must fix that before release and give them consistent prefixes.Quoted 9 lines
Instead, you could add a "
legacy_order" parameter to thefw_cfg_addfunctions. Then figure out the current order add the numeric order to each call. Then sort by the numeric order. As long as you don't reorder things with the same numeric value I think that would work and be fairly simple to implement. New calls could pass inNO_FW_CFG_LEGACY_ORDERor something like that and be pasted onto the end in legacy mode.-corey
OK but it's a much larger change and less well contained.
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 7 lines
While mucking with the file ordering anyway: Good opportunity to make new machine types also sort the
fw_cfgdirectory entries, so they get a fixed order independent from the order they are created, and we will not face this problem again.cheers,
GerdWhat exactly do you mean by directory entries here?
Quoted 22 lines · Michael S. Tsirkin
Quoted 20 lines · Corey Minyard
I've hit a bit of a snag here. For 0.11 and before, PCI option ROMs were loaded via
fw_cfg, not in the PCI ROM BAR. This causes two issues:* The order depends on the device initialization order, which I'm not sure is quantifiable. I believe it depends on how they are listed on the command line.
* Users can load their own romfile with their own name, which means it can't be in the list.
Also, for the ISA VGA ROMs, their order will also depend on the device list order.
Outside of that, I have an order of file names.
I think if I treat the device ROMs separately and handle them in init order, and then stick that device list in the proper location, that will work. Does that sound reasonable?
Quoted 6 lines
Quoted 3 lines
Thanks,
-corey
I think so. By the time this becomes an issue we might decide to disable migration from 0.11
One more thing here. I've realized that this is used for non-x86, too, and I'm wondering how much those matter. It's going to be really hard to figure out an order for these, as different boards/arches use the same names and install them in different orders.
For legacy mode, can I just put them in order for non-x86? Is there an easy way to detect that you are running x86?
-corey
Quoted 8 lines · Corey Minyard
One more thing here. I've realized that this is used for non-x86, too, and I'm wondering how much those matter. It's going to be really hard to figure out an order for these, as different boards/arches use the same names and install them in different orders.
For legacy mode, can I just put them in order for non-x86? Is there an easy way to detect that you are running x86?
Of all boards that support fw-cfg, only x86 does versioning so they are not a problem.
Paolo
Quoted 36 lines · Corey Minyard
Quoted 22 lines · Michael S. Tsirkin
Quoted 20 lines · Corey Minyard
I've hit a bit of a snag here. For 0.11 and before, PCI option ROMs were loaded via
fw_cfg, not in the PCI ROM BAR. This causes two issues:* The order depends on the device initialization order, which I'm not sure is quantifiable. I believe it depends on how they are listed on the command line.
* Users can load their own romfile with their own name, which means it can't be in the list.
Also, for the ISA VGA ROMs, their order will also depend on the device list order.
Outside of that, I have an order of file names.
I think if I treat the device ROMs separately and handle them in init order, and then stick that device list in the proper location, that will work. Does that sound reasonable?
Quoted 6 lines
Quoted 3 lines
Thanks,
-corey
I think so. By the time this becomes an issue we might decide to disable migration from 0.11
One more thing here. I've realized that this is used for non-x86, too, and I'm wondering how much those matter. It's going to be really hard to figure out an order for these, as different boards/arches use the same names and install them in different orders.
Quoted 4 lines
For legacy mode, can I just put them in order for non-x86? Is there an easy way to detect that you are running x86?
-corey
We only care about the order because of ability to migrate guests between QEMU versions.
Only architectures that version their machine types support this.
AFAIK at this point this means x86 and s390.
Signature · 1 line
MST