From patchwork Mon Aug 6 12:34:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 953852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41kcZv4xgTz9s3q for ; Mon, 6 Aug 2018 22:36:23 +1000 (AEST) Received: from localhost ([::1]:33901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmekH-0003eH-Bu for incoming@patchwork.ozlabs.org; Mon, 06 Aug 2018 08:36:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmej2-00033g-IW for qemu-devel@nongnu.org; Mon, 06 Aug 2018 08:35:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmej1-0006fq-D2 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 08:35:04 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:44086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fmeiy-0006ZZ-8E; Mon, 06 Aug 2018 08:35:00 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fmeiu-0000yI-0K; Mon, 06 Aug 2018 13:34:56 +0100 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 6 Aug 2018 13:34:45 +0100 Message-Id: <20180806123445.1459-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806123445.1459-1-peter.maydell@linaro.org> References: <20180806123445.1459-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-3.0 v2 5/5] hw/intc/arm_gicv3_common: Move gicd shift bug handling to gicv3_post_load 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: Shannon Zhao , Shannon Zhao , Juan Quintela , "Dr . David Alan Gilbert" , patches@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The code currently in gicv3_gicd_no_migration_shift_bug_post_load() that handles migration from older QEMU versions with a particular bug is misplaced. We need to run this after migration in all cases, not just the cases where the "arm_gicv3/gicd_no_migration_shift_bug" subsection is present, so it must go in a post_load hook for the top level VMSD, not for the subsection. Move it. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- hw/intc/arm_gicv3_common.c | 77 ++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index 8175889f1e7..52480c3b4cf 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -29,6 +29,41 @@ #include "hw/arm/linux-boot-if.h" #include "sysemu/kvm.h" + +static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs) +{ + if (cs->gicd_no_migration_shift_bug) { + return; + } + + /* Older versions of QEMU had a bug in the handling of state save/restore + * to the KVM GICv3: they got the offset in the bitmap arrays wrong, + * so that instead of the data for external interrupts 32 and up + * starting at bit position 32 in the bitmap, it started at bit + * position 64. If we're receiving data from a QEMU with that bug, + * we must move the data down into the right place. + */ + memmove(cs->group, (uint8_t *)cs->group + GIC_INTERNAL / 8, + sizeof(cs->group) - GIC_INTERNAL / 8); + memmove(cs->grpmod, (uint8_t *)cs->grpmod + GIC_INTERNAL / 8, + sizeof(cs->grpmod) - GIC_INTERNAL / 8); + memmove(cs->enabled, (uint8_t *)cs->enabled + GIC_INTERNAL / 8, + sizeof(cs->enabled) - GIC_INTERNAL / 8); + memmove(cs->pending, (uint8_t *)cs->pending + GIC_INTERNAL / 8, + sizeof(cs->pending) - GIC_INTERNAL / 8); + memmove(cs->active, (uint8_t *)cs->active + GIC_INTERNAL / 8, + sizeof(cs->active) - GIC_INTERNAL / 8); + memmove(cs->edge_trigger, (uint8_t *)cs->edge_trigger + GIC_INTERNAL / 8, + sizeof(cs->edge_trigger) - GIC_INTERNAL / 8); + + /* + * While this new version QEMU doesn't have this kind of bug as we fix it, + * so it needs to set the flag to true to indicate that and it's necessary + * for next migration to work from this new version QEMU. + */ + cs->gicd_no_migration_shift_bug = true; +} + static int gicv3_pre_save(void *opaque) { GICv3State *s = (GICv3State *)opaque; @@ -46,6 +81,8 @@ static int gicv3_post_load(void *opaque, int version_id) GICv3State *s = (GICv3State *)opaque; ARMGICv3CommonClass *c = ARM_GICV3_COMMON_GET_CLASS(s); + gicv3_gicd_no_migration_shift_bug_post_load(s); + if (c->post_load) { c->post_load(s); } @@ -161,45 +198,6 @@ static int gicv3_pre_load(void *opaque) return 0; } -static int gicv3_gicd_no_migration_shift_bug_post_load(void *opaque, - int version_id) -{ - GICv3State *cs = opaque; - - if (cs->gicd_no_migration_shift_bug) { - return 0; - } - - /* Older versions of QEMU had a bug in the handling of state save/restore - * to the KVM GICv3: they got the offset in the bitmap arrays wrong, - * so that instead of the data for external interrupts 32 and up - * starting at bit position 32 in the bitmap, it started at bit - * position 64. If we're receiving data from a QEMU with that bug, - * we must move the data down into the right place. - */ - memmove(cs->group, (uint8_t *)cs->group + GIC_INTERNAL / 8, - sizeof(cs->group) - GIC_INTERNAL / 8); - memmove(cs->grpmod, (uint8_t *)cs->grpmod + GIC_INTERNAL / 8, - sizeof(cs->grpmod) - GIC_INTERNAL / 8); - memmove(cs->enabled, (uint8_t *)cs->enabled + GIC_INTERNAL / 8, - sizeof(cs->enabled) - GIC_INTERNAL / 8); - memmove(cs->pending, (uint8_t *)cs->pending + GIC_INTERNAL / 8, - sizeof(cs->pending) - GIC_INTERNAL / 8); - memmove(cs->active, (uint8_t *)cs->active + GIC_INTERNAL / 8, - sizeof(cs->active) - GIC_INTERNAL / 8); - memmove(cs->edge_trigger, (uint8_t *)cs->edge_trigger + GIC_INTERNAL / 8, - sizeof(cs->edge_trigger) - GIC_INTERNAL / 8); - - /* - * While this new version QEMU doesn't have this kind of bug as we fix it, - * so it needs to set the flag to true to indicate that and it's necessary - * for next migration to work from this new version QEMU. - */ - cs->gicd_no_migration_shift_bug = true; - - return 0; -} - static bool needed_always(void *opaque) { return true; @@ -210,7 +208,6 @@ const VMStateDescription vmstate_gicv3_gicd_no_migration_shift_bug = { .version_id = 1, .minimum_version_id = 1, .needed = needed_always, - .post_load = gicv3_gicd_no_migration_shift_bug_post_load, .fields = (VMStateField[]) { VMSTATE_BOOL(gicd_no_migration_shift_bug, GICv3State), VMSTATE_END_OF_LIST()