Skip to content

Commit

Permalink
fw_cfg: fix the life cycle and the name of "qemu_extra_params_fw"
Browse files Browse the repository at this point in the history
Commit 19bcc4b ("fw_cfg: Make qemu_extra_params_fw locally",
2019-01-04) changed the storage duration of the "qemu_extra_params_fw"
array from static to automatic. This broke the interface contract on the
fw_cfg_add_file() function, which is documented as follows, in
"include/hw/nvram/fw_cfg.h":

> [...] The data referenced by the starting pointer is only linked, NOT
> copied, into the data structure of the fw_cfg device. [...]

As a result, when guest firmware fetches the "etc/boot-menu-wait" fw_cfg
file, it now sees garbage. Fix the regression by changing the storage
duration to allocated. (The call is reached at most once, on the realize
path of the board-specific fw_cfg sysbus device.)

While at it, clean up the name and the assignment of the object as well.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Fixes: 19bcc4b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
  • Loading branch information
lersek authored and mstsirkin committed Feb 5, 2019
1 parent 24cf541 commit 3b3df3e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions hw/nvram/fw_cfg.c
Expand Up @@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s)
{
const char *boot_splash_filename = NULL;
const char *boot_splash_time = NULL;
uint8_t qemu_extra_params_fw[2];
char *filename, *file_data;
gsize file_size;
int file_type;
Expand All @@ -132,16 +131,18 @@ static void fw_cfg_bootsplash(FWCfgState *s)
/* insert splash time if user configurated */
if (boot_splash_time) {
int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1);
uint16_t bst_le16;

/* validate the input */
if (bst_val < 0 || bst_val > 0xffff) {
error_report("splash-time is invalid,"
"it should be a value between 0 and 65535");
exit(1);
}
/* use little endian format */
qemu_extra_params_fw[0] = (uint8_t)(bst_val & 0xff);
qemu_extra_params_fw[1] = (uint8_t)((bst_val >> 8) & 0xff);
fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
bst_le16 = cpu_to_le16(bst_val);
fw_cfg_add_file(s, "etc/boot-menu-wait",
g_memdup(&bst_le16, sizeof bst_le16), sizeof bst_le16);
}

/* insert splash file if user configurated */
Expand Down

0 comments on commit 3b3df3e

Please sign in to comment.