From patchwork Fri Jan 18 22:31:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 10771727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C2F491E for ; Fri, 18 Jan 2019 22:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D28930128 for ; Fri, 18 Jan 2019 22:32:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41C7530148; Fri, 18 Jan 2019 22:32:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C062301D9 for ; Fri, 18 Jan 2019 22:32:54 +0000 (UTC) Received: from localhost ([127.0.0.1]:48253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkch3-00048H-Do for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Jan 2019 17:32:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkcgP-0003pJ-6W for qemu-devel@nongnu.org; Fri, 18 Jan 2019 17:32:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkcgN-0007bN-Aj for qemu-devel@nongnu.org; Fri, 18 Jan 2019 17:32:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkcgI-0007Rs-Hb for qemu-devel@nongnu.org; Fri, 18 Jan 2019 17:32:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F325CA396 for ; Fri, 18 Jan 2019 22:32:03 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-125-168.rdu2.redhat.com [10.10.125.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id D753E101960A; Fri, 18 Jan 2019 22:31:56 +0000 (UTC) From: Laszlo Ersek To: qemu devel list Date: Fri, 18 Jan 2019 23:31:52 +0100 Message-Id: <20190118223152.24183-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 Jan 2019 22:32:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] fw_cfg: fix the life cycle and the name of "qemu_extra_params_fw" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commit 19bcc4bc3213 ("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 Cc: Markus Armbruster Cc: Philippe Mathieu-Daudé Fixes: 19bcc4bc3213e78c303ad480a7a578f62258252d Signed-off-by: Laszlo Ersek Reviewed-by: Gerd Hoffmann Reviewed-by: Li Qiang Reviewed-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daudé --- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 53e8e010a8b7..7fdf04adc97f 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -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; @@ -132,6 +131,8 @@ 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," @@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s) 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 */