From patchwork Fri Jul 26 15:19:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11061231 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 4851E1398 for ; Fri, 26 Jul 2019 15:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36497288A6 for ; Fri, 26 Jul 2019 15:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AE8D28B3E; Fri, 26 Jul 2019 15:20:27 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB634288A6 for ; Fri, 26 Jul 2019 15:20:26 +0000 (UTC) Received: from localhost ([::1]:41074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr21B-0002Qf-Iy for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jul 2019 11:20:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37502) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr20k-0000ld-QP for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr20j-0006v2-AM for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:58 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:37231) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr20j-0006sK-2Q for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:57 -0400 Received: by mail-wr1-x42b.google.com with SMTP id n9so29755678wrr.4 for ; Fri, 26 Jul 2019 08:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=T/xJHFrQoJ4wgCuUOjNgn0AYtE8Gq7pDtEMvN4Sp0P4=; b=pL+dJWWDO8lSq/SXLv2N5NtGOC3c4Uf04s1lDZjWUJJaCiP2zGoiqpaL/SC4l2g5vY ITP52zeWDOQ7CiJFsubb9Euteuh4aZj91isGqLzv9cOUL1T2npE88Ij7HuAEFbYTPpmC EZdwb38m57hzQS8ZM1ciDZJ296aJTMK33iTkNgQDayD+I6v/QqFaeSnB2ZnHGsUOvjM7 0kv05HhABn9dLf1FNuvO8FNkLYOwyeCKVxzkAg1KwxQ67w93wZwLY8V4ar+aQFBkhAPo N5Mbm1B2mZvlI2pn4W+fFWCcMei4fWSS62UK5Iu+P2t5GSHWfmC6tR6wj/UXiOPAY3HX L+eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T/xJHFrQoJ4wgCuUOjNgn0AYtE8Gq7pDtEMvN4Sp0P4=; b=d4tOwZuVm6wspFs3eROucuVXpXs0Cer/xVtmNBTsPXG/vsDRnVOWkvGyHPrJRYPu2R qcZACSJ1N6Q9Cat/5X/52FasXoNIwi1a9GnaYD8F+MhZA6b96+MpwFh1SuqOz0xBR0O7 KJOXMcoSPuTOJFaKDdBR/AEpfRsXq25zj2ldcL98Jbvtw1lk8SwAnvVx5XFFcvmq6jYd EyX2iG81k2FLOl6BEIJpfhaH1NrBw8XjvpxdM/L972vRqem89umCmtNRVi4d2eiu6Oyq y25SvwI+OonbPPJVfaxNfE1XjV//694cF37HWyDRW3u2E2W2QpaZVBd3rpYU3SiDnMMp BCsg== X-Gm-Message-State: APjAAAU5Aj0mBV+rLb3jhEO0av+bxy5+FTKFWAqLGzIgDSj+V1DmRhpk ugIhdYnswHSisC8eeZqj7h8bu+aykM1ufQ== X-Google-Smtp-Source: APXvYqxEq3otlCLAUDxob5yEP3gYI1a3UfpbOojkOTATUHI3OCwW4SILIiCdlH/rPdbRVhcvTn+qcw== X-Received: by 2002:a5d:4041:: with SMTP id w1mr91050824wrp.199.1564154395815; Fri, 26 Jul 2019 08:19:55 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v16sm32746844wrn.28.2019.07.26.08.19.54 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 08:19:55 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2019 16:19:48 +0100 Message-Id: <20190726151952.1932-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726151952.1932-1-peter.maydell@linaro.org> References: <20190726151952.1932-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42b Subject: [Qemu-devel] [PULL 1/5] pl330: fix vmstate description X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Damien Hedde Fix the pl330 main and queue vmstate description. There were missing POINTER flags causing crashes during incoming migration because: + PL330State chan field is a pointer to an array + PL330Queue queue field is a pointer to an array Also bump corresponding vmsd version numbers. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daude Acked-by: Dr. David Alan Gilbert Message-id: 20190724143553.21557-1-damien.hedde@greensocs.com Signed-off-by: Peter Maydell --- hw/dma/pl330.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/dma/pl330.c b/hw/dma/pl330.c index 58df965a468..a56a3e77713 100644 --- a/hw/dma/pl330.c +++ b/hw/dma/pl330.c @@ -218,11 +218,12 @@ typedef struct PL330Queue { static const VMStateDescription vmstate_pl330_queue = { .name = "pl330_queue", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { - VMSTATE_STRUCT_VARRAY_UINT32(queue, PL330Queue, queue_size, 1, - vmstate_pl330_queue_entry, PL330QueueEntry), + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(queue, PL330Queue, queue_size, + vmstate_pl330_queue_entry, + PL330QueueEntry), VMSTATE_END_OF_LIST() } }; @@ -278,12 +279,12 @@ struct PL330State { static const VMStateDescription vmstate_pl330 = { .name = "pl330", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { VMSTATE_STRUCT(manager, PL330State, 0, vmstate_pl330_chan, PL330Chan), - VMSTATE_STRUCT_VARRAY_UINT32(chan, PL330State, num_chnls, 0, - vmstate_pl330_chan, PL330Chan), + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(chan, PL330State, num_chnls, + vmstate_pl330_chan, PL330Chan), VMSTATE_VBUFFER_UINT32(lo_seqn, PL330State, 1, NULL, num_chnls), VMSTATE_VBUFFER_UINT32(hi_seqn, PL330State, 1, NULL, num_chnls), VMSTATE_STRUCT(fifo, PL330State, 0, vmstate_pl330_fifo, PL330Fifo), From patchwork Fri Jul 26 15:19:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11061237 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 BF5B2112C for ; Fri, 26 Jul 2019 15:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B07F6288E2 for ; Fri, 26 Jul 2019 15:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E6F28B2B; Fri, 26 Jul 2019 15:20:30 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5261C288E2 for ; Fri, 26 Jul 2019 15:20:29 +0000 (UTC) Received: from localhost ([::1]:41076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr21D-0002aw-N3 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jul 2019 11:20:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37523) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr20l-0000lk-4e for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr20k-0006xA-0S for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:59 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:45604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr20j-0006u6-Oi for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:57 -0400 Received: by mail-wr1-x444.google.com with SMTP id f9so54799355wre.12 for ; Fri, 26 Jul 2019 08:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Za/0QQNRcEYp14wTAGlfMqArIpeP/+fVrLhYpi/aXKo=; b=sxX5HRgdTWO/NTfywZMnJHz76vwBHIMqrxWN2WKCseCjmRK1ILIrP3W2Gmtd2Ii1O1 F+hytU+j9wDlHaumWML1uKbyT3n6aKu565k5zFJv+BsTXTWusJUQbtfsfAInnPVeWdBl RsUy/0yDlZwgyLPMohKXK53HlARzzRUthpM3p44/ITJ0CKHPHpZcfEpQA9RDvsM+a25T I744GIdL8oG0px7l1Quuh2aKBSg1hPkS9FzD7POHj/Rx8990QJjUkpVNPMCn6j20POb4 Q8bWSMZOmtBLcbt3bfesGxQ1cXCC2P6IS8Q5PPMZ3SerqR8s5/VR2Rek+7kRLrjoS//j vJlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Za/0QQNRcEYp14wTAGlfMqArIpeP/+fVrLhYpi/aXKo=; b=c+YCm8AHL4Yavhm3/Jlf7GxmJpdAsZfQcDY6alutLD/kaeMgHd3oI7RXIKD9i5tiD5 rLChV5QgSlU2G0xtrLQMMWFKZ1q18jEDJspqaX3QiX4CeylcvwuQ0JJvI/RfXGK0agy9 vOZ5J8unzlk9BOXKFE9aYa4fZbIzUWgtFcYiRxFzw+jXr0JOtx0vSWvE68qhFuKy6daR 7iM4dQe3CZKymhSZYiD9sasDNYB5bzBQdTJrVSRvoGxNG0ksSa1R1ukhPX6pgj9otvYU h9GbDCqODcw8pMFFJ992v2IDgm80iYV9tmn67fSwYPJ8IW2fLPftzB00MXFyIeHCYNWV VorA== X-Gm-Message-State: APjAAAVjCrbo7q2m0wAeyXPNtMfgGUpRroib3WDjJP9UlKpbmfb50/Hk EJOMa7iYR3vVYJ0IYyV8cXu8Q57sRJC5Lg== X-Google-Smtp-Source: APXvYqztAKgud2AK8jEVn/uM0V+/Er70pDUmafpVpB04i0kbrgbfD+zIERwauAY+wyDcOKJo5bt7DA== X-Received: by 2002:adf:f348:: with SMTP id e8mr997139wrp.76.1564154396609; Fri, 26 Jul 2019 08:19:56 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v16sm32746844wrn.28.2019.07.26.08.19.55 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 08:19:56 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2019 16:19:49 +0100 Message-Id: <20190726151952.1932-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726151952.1932-1-peter.maydell@linaro.org> References: <20190726151952.1932-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PULL 2/5] stellaris_input: Fix vmstate description of buttons field X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP gamepad_state::buttons is a pointer to an array of structs, not an array of structs, so should be declared in the vmstate with VMSTATE_STRUCT_VARRAY_POINTER_INT32; otherwise we corrupt memory on incoming migration. We bump the vmstate version field as the easiest way to deal with the migration break, since migration wouldn't have worked reliably before anyway. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Damien Hedde Message-id: 20190725163710.11703-2-peter.maydell@linaro.org --- hw/input/stellaris_input.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/input/stellaris_input.c b/hw/input/stellaris_input.c index 20c87d86f40..3a666d61d47 100644 --- a/hw/input/stellaris_input.c +++ b/hw/input/stellaris_input.c @@ -60,12 +60,14 @@ static const VMStateDescription vmstate_stellaris_button = { static const VMStateDescription vmstate_stellaris_gamepad = { .name = "stellaris_gamepad", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { VMSTATE_INT32(extension, gamepad_state), - VMSTATE_STRUCT_VARRAY_INT32(buttons, gamepad_state, num_buttons, 0, - vmstate_stellaris_button, gamepad_button), + VMSTATE_STRUCT_VARRAY_POINTER_INT32(buttons, gamepad_state, + num_buttons, + vmstate_stellaris_button, + gamepad_button), VMSTATE_END_OF_LIST() } }; From patchwork Fri Jul 26 15:19:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11061235 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 4334F14DB for ; Fri, 26 Jul 2019 15:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3244428B2B for ; Fri, 26 Jul 2019 15:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26AC928B2D; Fri, 26 Jul 2019 15:20:30 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 90D2C28B3E for ; Fri, 26 Jul 2019 15:20:29 +0000 (UTC) Received: from localhost ([::1]:41079 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr21E-0002eJ-9U for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jul 2019 11:20:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37594) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr20m-0000mk-Bl for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr20k-0006zn-VI for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:00 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:44128) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr20k-0006xI-NC for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:58 -0400 Received: by mail-wr1-x42e.google.com with SMTP id p17so54814585wrf.11 for ; Fri, 26 Jul 2019 08:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8Ez3hO5NBzLE8OGsz9miDbwv9XPAsoT5BmbFIkSdYCU=; b=zrudgZOKePIXYhIIBGLfOABPT0SHQZuKHPmPn3TT57RLA9CTpKg/lgSz1wOSVKOR7/ QR8fgQOEohByVgb+pBGH63sDDQjgTRpMs5oibYWb5Jn5tlhEFMe93oPTmCF1TOKCMIL3 Mu8/MSzVDUpCpjgVdTfkZJKw+CWUcoVqHSZnbNWBmjrIr6LXB2WasG2houjGL5xQVGPK JEI2dCRWp2sNSMLY4LHMizj+j5DkqjAjr8VLdW3kWDNET8eY/hOLL53V3BOZFr05cCGL kqjc66zoy+5N0Mm83RaDP0aWQzbnu2XHg1i3maH1eXT2GhQYKvaO10DVFDAZwSvi+m0t bkbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Ez3hO5NBzLE8OGsz9miDbwv9XPAsoT5BmbFIkSdYCU=; b=cP4KuxIs9204uqLIIXJb/VqRRv9VGsjkb9cJ4Ik46BrkJkPhhFEZqN8+ZzjNI4F1Ho 641gBPkRfdIjQQl8e090vxv1YGotsAxxsJcP27x/SiSHkL8E/L8VawPmhRo/P4hsNwEH QSqxKhBMIsd8miT/wPfr2toCrZk/eDEtsWVWEEf3AXUcsMMpFDy+jOr/wezXy5b+x/TQ 2JL6vQTGx0p3ufwIlJ6HIUheJk6H+8t4I5oi6FeI30kHzescQRWVx823xQ8n2k5hq3JR roLEnhQ6e9vVl3/e5S/wYwPeyVMFILXvbYUyVQ3kVX5LYTTCd7T7UTAu/BpYFJ3/oCob heXA== X-Gm-Message-State: APjAAAWjg3dZRD62i8ImsoYbYynNo3u9/Bp33S9EGXza0oxVt0xtyT59 dS09Ti7guZVqxICkcDUAMe5RWZW506XqKQ== X-Google-Smtp-Source: APXvYqzh9I3cGAPuZZ7M/P/nZ/XUII8DQaE4eNFJ19uV6aYXJsJbeEyi16DrwMWkKHuHieqSUtfe/g== X-Received: by 2002:adf:c70e:: with SMTP id k14mr105934337wrg.201.1564154397480; Fri, 26 Jul 2019 08:19:57 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v16sm32746844wrn.28.2019.07.26.08.19.56 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 08:19:57 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2019 16:19:50 +0100 Message-Id: <20190726151952.1932-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726151952.1932-1-peter.maydell@linaro.org> References: <20190726151952.1932-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [PULL 3/5] vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The VMSTATE_STRUCT_VARRAY_UINT32 macro is intended to handle migrating a field which is an array of structs, but where instead of migrating the entire array we only migrate a variable number of elements of it. The VMSTATE_STRUCT_VARRAY_POINTER_UINT32 macro is intended to handle migrating a field which is of pointer type, and points to a dynamically allocated array of structs of variable size. We weren't actually checking that the field passed to VMSTATE_STRUCT_VARRAY_UINT32 really is an array, with the result that accidentally using it where the _POINTER_ macro was intended would compile but silently corrupt memory on migration. Add type-checking that enforces that the field passed in is really of the right array type. This applies to all the VMSTATE macros which use flags including VMS_VARRAY_* but not VMS_POINTER. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Damien Hedde Tested-by: Damien Hedde Message-id: 20190725163710.11703-3-peter.maydell@linaro.org --- include/migration/vmstate.h | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index ca68584eba4..c2bfa7a7f0c 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -227,8 +227,22 @@ extern const VMStateInfo vmstate_info_bitmap; extern const VMStateInfo vmstate_info_qtailq; #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) +/* + * Check that type t2 is an array of type t1 of size n, + * e.g. if t1 is 'foo' and n is 32 then t2 must be 'foo[32]' + */ #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) +/* + * type of element 0 of the specified (array) field of the type. + * Note that if the field is a pointer then this will return the + * pointed-to type rather than complaining. + */ +#define typeof_elt_of_field(type, field) typeof(((type *)0)->field[0]) +/* Check that field f in struct type t2 is an array of t1, of any size */ +#define type_check_varray(t1, t2, f) \ + (type_check(t1, typeof_elt_of_field(t2, f)) \ + + QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(((t2 *)0)->f))) #define vmstate_offset_value(_state, _field, _type) \ (offsetof(_state, _field) + \ @@ -253,6 +267,10 @@ extern const VMStateInfo vmstate_info_qtailq; vmstate_offset_array(_state, _field, uint8_t, \ sizeof(typeof_field(_state, _field))) +#define vmstate_offset_varray(_state, _field, _type) \ + (offsetof(_state, _field) + \ + type_check_varray(_type, _state, _field)) + /* In the macros below, if there is a _version, that means the macro's * field will be processed only if the version being received is >= * the _version specified. In general, if you add a new field, you @@ -347,7 +365,7 @@ extern const VMStateInfo vmstate_info_qtailq; .info = &(_info), \ .size = sizeof(_type), \ .flags = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ @@ -376,7 +394,7 @@ extern const VMStateInfo vmstate_info_qtailq; .info = &(_info), \ .size = sizeof(_type), \ .flags = VMS_VARRAY_INT32, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ @@ -416,7 +434,7 @@ extern const VMStateInfo vmstate_info_qtailq; .info = &(_info), \ .size = sizeof(_type), \ .flags = VMS_VARRAY_UINT16, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } #define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \ @@ -520,7 +538,7 @@ extern const VMStateInfo vmstate_info_qtailq; .vmsd = &(_vmsd), \ .size = sizeof(_type), \ .flags = VMS_STRUCT|VMS_VARRAY_UINT8, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } /* a variable length array (i.e. _type *_field) but we know the @@ -573,7 +591,7 @@ extern const VMStateInfo vmstate_info_qtailq; .vmsd = &(_vmsd), \ .size = sizeof(_type), \ .flags = VMS_STRUCT|VMS_VARRAY_INT32, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } #define VMSTATE_STRUCT_VARRAY_UINT32(_field, _state, _field_num, _version, _vmsd, _type) { \ @@ -583,7 +601,7 @@ extern const VMStateInfo vmstate_info_qtailq; .vmsd = &(_vmsd), \ .size = sizeof(_type), \ .flags = VMS_STRUCT|VMS_VARRAY_UINT32, \ - .offset = offsetof(_state, _field), \ + .offset = vmstate_offset_varray(_state, _field, _type), \ } #define VMSTATE_STRUCT_VARRAY_ALLOC(_field, _state, _field_num, _version, _vmsd, _type) {\ From patchwork Fri Jul 26 15:19:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11061239 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 9E66B1398 for ; Fri, 26 Jul 2019 15:21:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D003289A3 for ; Fri, 26 Jul 2019 15:21:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80CF828A4E; Fri, 26 Jul 2019 15:21:01 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 21419289A3 for ; Fri, 26 Jul 2019 15:21:01 +0000 (UTC) Received: from localhost ([::1]:41095 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr21k-00054d-44 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jul 2019 11:21:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37631) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr20n-0000nA-0k for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr20l-00071n-PQ for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:00 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:40063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr20l-0006zi-I5 for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:19:59 -0400 Received: by mail-wm1-x343.google.com with SMTP id v19so48037739wmj.5 for ; Fri, 26 Jul 2019 08:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LvhsiHkVuNBsC4pCSoHsjH+VA0vVutJhC/fh+GMwzbk=; b=PqupO5IJLGb7Ylzsr5fR0dI09T7xdVdadgddGnI5C6BmTl9xeHAbYMhcp/E34J5dEk 4zBSnAtB1K7R+snzBH7edbX5G72nx5+f3BBJPmL3rMGDshQ9CLKCFloRvSpZDkY9BL/w w3P/wyDXPcbU2VlvBC6QFVD7eTG8/oL4DXz+Niuvsg/q0o8w5EsTvvlW5Axc+uLkFkZS Q+M3bcTYnnLdvOgJUpGFfuu/k1dIr0Q6GMMvZty8aV0yPi76gdiRuXyYR3g2nhJ0oYau XjuUBTJprgi3cT4AsoHiTUVvr4zmNu6VufBK2YVhduGNz689pbTuSLtRvdOEwgDVsthL E+FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LvhsiHkVuNBsC4pCSoHsjH+VA0vVutJhC/fh+GMwzbk=; b=sSsVI8MqlomeQYKCOS1774ANg7IKE/zt47BLNczq+0Q2rPiWYRBBchKWyUa0OiJ/pc Pk6y+8ptorA+pcMQy9CgBnbxHE2vEnl686kY/vxvBNYt4PjGwS+V0E7GSQLiDW8jz8Xa oSefhEGmfQvJ24TLfpI1WQaOPj+aUJzW1mBM/+BdaJKX3gWn1zYaIj9SQA1roJWV+kLd 1uyrT8ACWz3kLL0S3YEcAqc1SpZ0zBS2U//T/RGhalv8XKkFnbRd/XknCDNjoJLHXtFN qAya1Vw6fcEC3lwaqG1iZkunO7utE+yQ6nYfIT6AWIYrjNUOUjEvlwZQD7XxJMPsXcYR Ud9g== X-Gm-Message-State: APjAAAUednpwy/xd2B90JiCC305z12niZHzKch/LPdi6Vw6cmQ14hVww ipl1xbCtSVZitas1MABD/1rgk4T4RTau4g== X-Google-Smtp-Source: APXvYqxb0IlaZ9FF0JgRaU6WGDTk72JFdTtgJ7kgWMRA3dlGg+6QSW4HFN9iCynZAOkT2dHxadfYSA== X-Received: by 2002:a05:600c:212:: with SMTP id 18mr35875634wmi.88.1564154398294; Fri, 26 Jul 2019 08:19:58 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v16sm32746844wrn.28.2019.07.26.08.19.57 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 08:19:57 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2019 16:19:51 +0100 Message-Id: <20190726151952.1932-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726151952.1932-1-peter.maydell@linaro.org> References: <20190726151952.1932-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 4/5] hw/arm/boot: Rename elf_{low, high}_addr to image_{low, high}_addr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Rename the elf_low_addr and elf_high_addr variables to image_low_addr and image_high_addr -- in the next commit we will extend them to be set for other kinds of image file and not just ELF files. Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Tested-by: Mark Rutland Message-id: 20190722151804.25467-2-peter.maydell@linaro.org --- hw/arm/boot.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 1fb24fbef27..b7b31753aca 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -986,7 +986,9 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, int kernel_size; int initrd_size; int is_linux = 0; - uint64_t elf_entry, elf_low_addr, elf_high_addr; + uint64_t elf_entry; + /* Addresses of first byte used and first byte not used by the image */ + uint64_t image_low_addr, image_high_addr; int elf_machine; hwaddr entry; static const ARMInsnFixup *primary_loader; @@ -1014,24 +1016,24 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, info->nb_cpus = 1; /* Assume that raw images are linux kernels, and ELF images are not. */ - kernel_size = arm_load_elf(info, &elf_entry, &elf_low_addr, - &elf_high_addr, elf_machine, as); + kernel_size = arm_load_elf(info, &elf_entry, &image_low_addr, + &image_high_addr, elf_machine, as); if (kernel_size > 0 && have_dtb(info)) { /* * If there is still some room left at the base of RAM, try and put * the DTB there like we do for images loaded with -bios or -pflash. */ - if (elf_low_addr > info->loader_start - || elf_high_addr < info->loader_start) { + if (image_low_addr > info->loader_start + || image_high_addr < info->loader_start) { /* - * Set elf_low_addr as address limit for arm_load_dtb if it may be + * Set image_low_addr as address limit for arm_load_dtb if it may be * pointing into RAM, otherwise pass '0' (no limit) */ - if (elf_low_addr < info->loader_start) { - elf_low_addr = 0; + if (image_low_addr < info->loader_start) { + image_low_addr = 0; } info->dtb_start = info->loader_start; - info->dtb_limit = elf_low_addr; + info->dtb_limit = image_low_addr; } } entry = elf_entry; From patchwork Fri Jul 26 15:19:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11061241 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 EB247112C for ; Fri, 26 Jul 2019 15:21:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB258288A6 for ; Fri, 26 Jul 2019 15:21:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D007D28941; Fri, 26 Jul 2019 15:21:03 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5FAFE288A6 for ; Fri, 26 Jul 2019 15:21:03 +0000 (UTC) Received: from localhost ([::1]:41098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr21m-0005GA-Fc for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jul 2019 11:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37676) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr20n-0000ok-Qc for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr20m-00073Y-Hs for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:01 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36532) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr20m-00071j-BL for qemu-devel@nongnu.org; Fri, 26 Jul 2019 11:20:00 -0400 Received: by mail-wr1-x441.google.com with SMTP id n4so54909631wrs.3 for ; Fri, 26 Jul 2019 08:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GpPKP7yzwy7Lawm8Enx0xBuAIaMsB8U7zaH4ykghGlk=; b=q39QhqX2I/wBFcs3F9pHc9DhwtHgDQXq4zhJgy+rrbRLZGeO5fphWVIdcRXm8UcQOs ytUWZw+qOm/p4t2U4BbEzKqVhOXxg9VTbGqWbzPtO2DCiYFmb027hhHwsHuORTAPKfsK KI6z7gDyDE8VLJXuWRZxQ6XmiLVhqYcSsi0NXmC4qEdK+2GY4+luuqWLu+hZ/S10pgrH kVpC+mGgfUFJbVUbJsvDi6JyDaSdXTjI0mu/r+hXNCm7pGEcCdJIqBuIaJ6vOaDvl1Bs P3cfLs/TJfVq66uwPRfh4fHdkOXrC1SLaAjofQ3PksxiD314aJVMWdhbnEv4weEkP20C AK2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GpPKP7yzwy7Lawm8Enx0xBuAIaMsB8U7zaH4ykghGlk=; b=a7lgh9VpLQCPOHTQ+6qKD5ClgNfnT5vLGLhnvY1tFHTWT2fgMLekITIT7c7JKw7fzX PFwUAn+g/mr7PD/w94Y+PZNq96nVSFbVgRO7cNOCldjSQnchuUrmq6fwG7SJsZpHtsDb LL5B8+61etlvGBuvrGlw6WEPXQK3OhD6Wu9F4/kqlhP/rUjVWCrYDPD/CBLy0yYF0lpW EO+ZN65h89g2r6Jkx4ZsK5aJcgDyv9qh/eSkQy/PfRAHEl5h0rSaT85GorKX41QpEz0p eBJGnEPy8+7wx3c2TWTBBSnuQY01pvIgyFHPC2RBRFKAGySE0L0qq7DuqXFnrnGzuw6c 1Teg== X-Gm-Message-State: APjAAAVB30ddrAPxnzOsOAARK+OE2TnR/DPYEmCCLH77E/PHcA3tYffq hyhqCDLiaWxgv238YBIxOGOHw37+magjtg== X-Google-Smtp-Source: APXvYqyWSPw3FL8gCcO+ffqtQOVpLbO5U774wzcx+IUTXt/Ujnqnfu4P4NIjwdJm3s7rA7MKZ4UroQ== X-Received: by 2002:adf:fa42:: with SMTP id y2mr21056679wrr.170.1564154399117; Fri, 26 Jul 2019 08:19:59 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v16sm32746844wrn.28.2019.07.26.08.19.58 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 26 Jul 2019 08:19:58 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2019 16:19:52 +0100 Message-Id: <20190726151952.1932-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726151952.1932-1-peter.maydell@linaro.org> References: <20190726151952.1932-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PULL 5/5] hw/arm/boot: Further improve initrd positioning code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In commit e6b2b20d9735d4ef we made the boot loader code try to avoid putting the initrd on top of the kernel. However the expression used to calculate the start of the initrd: info->initrd_start = info->loader_start + MAX(MIN(info->ram_size / 2, 128 * 1024 * 1024), kernel_size); incorrectly uses 'kernel_size' as the offset within RAM of the highest address to avoid. This is incorrect because the kernel doesn't start at address 0, but slightly higher than that. This means that we can still incorrectly end up overlaying the initrd on the kernel in some cases, for example: * The kernel's image_size is 0x0a7a8000 * The kernel was loaded at 0x40080000 * The end of the kernel is 0x4A828000 * The DTB was loaded at 0x4a800000 To get this right we need to track the actual highest address used by the kernel and use that rather than kernel_size. We already set image_low_addr and image_high_addr for ELF images; set them also for the various other image types we support, and then use image_high_addr as the lowest allowed address for the initrd. (We don't use image_low_addr, but we set it for consistency with the existing code path for ELF files.) Fixes: e6b2b20d9735d4ef Reported-by: Mark Rutland Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Tested-by: Mark Rutland Message-id: 20190722151804.25467-3-peter.maydell@linaro.org --- hw/arm/boot.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index b7b31753aca..c2b89b3bb9b 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -988,7 +988,7 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, int is_linux = 0; uint64_t elf_entry; /* Addresses of first byte used and first byte not used by the image */ - uint64_t image_low_addr, image_high_addr; + uint64_t image_low_addr = 0, image_high_addr = 0; int elf_machine; hwaddr entry; static const ARMInsnFixup *primary_loader; @@ -1041,17 +1041,29 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, uint64_t loadaddr = info->loader_start + KERNEL_NOLOAD_ADDR; kernel_size = load_uimage_as(info->kernel_filename, &entry, &loadaddr, &is_linux, NULL, NULL, as); + if (kernel_size >= 0) { + image_low_addr = loadaddr; + image_high_addr = image_low_addr + kernel_size; + } } if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) { kernel_size = load_aarch64_image(info->kernel_filename, info->loader_start, &entry, as); is_linux = 1; + if (kernel_size >= 0) { + image_low_addr = entry; + image_high_addr = image_low_addr + kernel_size; + } } else if (kernel_size < 0) { /* 32-bit ARM */ entry = info->loader_start + KERNEL_LOAD_ADDR; kernel_size = load_image_targphys_as(info->kernel_filename, entry, ram_end - KERNEL_LOAD_ADDR, as); is_linux = 1; + if (kernel_size >= 0) { + image_low_addr = entry; + image_high_addr = image_low_addr + kernel_size; + } } if (kernel_size < 0) { error_report("could not load kernel '%s'", info->kernel_filename); @@ -1083,7 +1095,10 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, * we might still make a bad choice here. */ info->initrd_start = info->loader_start + - MAX(MIN(info->ram_size / 2, 128 * 1024 * 1024), kernel_size); + MIN(info->ram_size / 2, 128 * 1024 * 1024); + if (image_high_addr) { + info->initrd_start = MAX(info->initrd_start, image_high_addr); + } info->initrd_start = TARGET_PAGE_ALIGN(info->initrd_start); if (is_linux) {