From nobody Sun Apr 28 20:38:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571126232; cv=none; d=zoho.com; s=zohoarc; b=JNBShri4VFgzM7NIhLZ4/KqQ5QmApg5XXLWWs7xn/+WCFiw1kHnScSrUevl1NotWsoBderq95ycf8sPRTtDBVidJddYolUcxT+NNaqUwS32Pxgkl2VGXrKTDtlBgV/GlKrZ/07wCz7xAEIiiNNN4jR2m2DpK7wZy0PwzyXj20uE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571126232; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nyugE5fUnOG1NQuji82adEqjDgSIVn/Jt6BINWKIvkw=; b=nlg7/5WvNt539c4HAKKDd+zpBGU/1Y2/ulfs81iLojZ+3rhPQGeTC6tjJaBiqO3FLlRdLCl29u+kPEltHr5fb3pQJYgfa+nyQsAwzi5DtdhIh96oaE9N9cJJIItqHU56CIGLp59oehl/E9gYGCgdzDSLgXf7m3VNgKtvVsM/zSM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571126232290347.4403108049373; Tue, 15 Oct 2019 00:57:12 -0700 (PDT) Received: from localhost ([::1]:36522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKHhf-0003ib-7B for importer@patchew.org; Tue, 15 Oct 2019 03:57:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52333) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKHfb-0001ho-31 for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKHfZ-0005hN-RB for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKHfZ-0005h3-Iy for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:01 -0400 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A25125313B for ; Tue, 15 Oct 2019 07:55:00 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id r7so15352906pfg.2 for ; Tue, 15 Oct 2019 00:55:00 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r30sm24599850pfl.42.2019.10.15.00.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 00:54:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Prhq+elVYNderg0JL2udm40c7DMFWGn25Wjwjz4GK2c=; b=tFJW8n7gbP4AxuhaWzsMzFjq8AJpWKQDll5u7s8PGjzQ0bsk+pkdANLGD3WY0TbjxN Rygf9cXz/2dDoqFUd7ObZ/GeJbwhUeVnVgn2l3kBLXxuxwurvMwwZfhwqbN9Ft+P9JB7 Qmm+mPcO8Q+iEFuWNvZ0v8JypnIAzbkcPcrjjKovvHmgVSbK99gQ8CveSotqunUClUTY uR/biaYgIWIMCKp5SFR5X1hDh+8JoBn/rwtEZmmzU9Ur8leB8plktGj5QFYwiKlhZC9L KtmqCQ3S+4DImrRqIddo+DzjL4maFBJ56aBzT/zJAraETCqzvm8ep0JVJqKMKoIZwaNT IgMA== X-Gm-Message-State: APjAAAUUrmauxYx0XOMu2smKmYcKEMAkUgRTq6sUIvwez/OUHYM9ciNy pEQOz3OgcQzy0JBWS1aZ06Df9X3nxg+xmsVuRRJukheK7PGKFgnzupuADBrGBK9THauvwbgaokl 04GAgZGfxtXkQx7E= X-Received: by 2002:a17:90a:aa98:: with SMTP id l24mr40658711pjq.96.1571126099652; Tue, 15 Oct 2019 00:54:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKohrDHIiBy1fV/g+wU/ofwOOjwcZDoKQMEMzESTPKg8Zl3n/XjGr3U2g97PG5xPoyskcz+Q== X-Received: by 2002:a17:90a:aa98:: with SMTP id l24mr40658675pjq.96.1571126099130; Tue, 15 Oct 2019 00:54:59 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 1/2] migration: Boost SaveStateEntry.instance_id to 64 bits Date: Tue, 15 Oct 2019 15:54:43 +0800 Message-Id: <20191015075444.10955-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191015075444.10955-1-peterx@redhat.com> References: <20191015075444.10955-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: , Cc: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It was "int" and used as 32bits fields (see save_section_header()). It's unsafe already because sizeof(int) could be 2 on i386, I think. So at least uint32_t would suite more. While it also uses "-1" as a placeholder of "we want to generate the instance ID automatically". Hence a more proper value should be int64_t. This will start to be useful after next patch in which we can start to convert a real uint32_t value as instance ID. Signed-off-by: Peter Xu --- include/migration/register.h | 2 +- include/migration/vmstate.h | 4 ++-- migration/savevm.c | 10 +++++----- stubs/vmstate.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index a13359a08d..54f42c7413 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -69,7 +69,7 @@ typedef struct SaveVMHandlers { } SaveVMHandlers; =20 int register_savevm_live(const char *idstr, - int instance_id, + int64_t instance_id, int version_id, const SaveVMHandlers *ops, void *opaque); diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1fbfd099dd..6a7498463c 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1114,14 +1114,14 @@ int vmstate_save_state_v(QEMUFile *f, const VMState= Description *vmsd, bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); =20 /* Returns: 0 on success, -1 on failure */ -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(DeviceState *dev, int64_t instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, Error **errp); =20 /* Returns: 0 on success, -1 on failure */ -static inline int vmstate_register(DeviceState *dev, int instance_id, +static inline int vmstate_register(DeviceState *dev, int64_t instance_id, const VMStateDescription *vmsd, void *opaque) { diff --git a/migration/savevm.c b/migration/savevm.c index bb9462a54d..dc9281c897 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -233,7 +233,7 @@ typedef struct CompatEntry { typedef struct SaveStateEntry { QTAILQ_ENTRY(SaveStateEntry) entry; char idstr[256]; - int instance_id; + int64_t instance_id; int alias_id; int version_id; /* version id read from the stream */ @@ -668,7 +668,7 @@ void dump_vmstate_json_to_file(FILE *out_file) static int calculate_new_instance_id(const char *idstr) { SaveStateEntry *se; - int instance_id =3D 0; + int64_t instance_id =3D 0; =20 QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (strcmp(idstr, se->idstr) =3D=3D 0 @@ -730,7 +730,7 @@ static void savevm_state_handler_insert(SaveStateEntry = *nse) Meanwhile pass -1 as instance_id if you do not already have a clearly distinguishing id for all instances of your device class. */ int register_savevm_live(const char *idstr, - int instance_id, + int64_t instance_id, int version_id, const SaveVMHandlers *ops, void *opaque) @@ -784,7 +784,7 @@ void unregister_savevm(DeviceState *dev, const char *id= str, void *opaque) } } =20 -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(DeviceState *dev, int64_t instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, int required_for_version, @@ -1566,7 +1566,7 @@ int qemu_save_device_state(QEMUFile *f) return qemu_file_get_error(f); } =20 -static SaveStateEntry *find_se(const char *idstr, int instance_id) +static SaveStateEntry *find_se(const char *idstr, int64_t instance_id) { SaveStateEntry *se; =20 diff --git a/stubs/vmstate.c b/stubs/vmstate.c index e1e89b87f0..699003f3b0 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -4,7 +4,7 @@ const VMStateDescription vmstate_dummy =3D {}; =20 int vmstate_register_with_alias_id(DeviceState *dev, - int instance_id, + int64_t instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, --=20 2.21.0 From nobody Sun Apr 28 20:38:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571126327; cv=none; d=zoho.com; s=zohoarc; b=fpHZUMaBY15o8En3aZh52acgVokjeCcYtWK2iF38KJpagPnKIa4STcx3Vjv0hApZxfmnLBxBUotSnANFHHEwgD427iZgkfKrQLdASLJr/wlj99H60V5Qb3ugd/eREJB8P+zI0MDQ3MCjpYa7ed3Nb+J2vjqrJBQkC27/qQgcOAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571126327; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r7UpnHpFNlo3WhyDD6OuUPnkxLBU7cRNU8X0KLGN1pk=; b=Q/GgjIFvy5W6D7EhWfqoyJIBILIzM2SGgbEX+jrCf50U11OGzkXCakqMYPDONUOr3FN9bv9FfVVPaVUT3eGPXx5r3FxizJePGBrCeDeTDN3ZWBnSBUfeQLen9jI6cqut6xiJ1tg5RNbo/zBuJBaKAZjlhPhd4UgAu9tNjO439JA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571126327794604.7739323446324; Tue, 15 Oct 2019 00:58:47 -0700 (PDT) Received: from localhost ([::1]:36558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKHj9-0005m2-IS for importer@patchew.org; Tue, 15 Oct 2019 03:58:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52347) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKHff-0001mJ-1n for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKHfc-0005iT-W8 for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iKHfc-0005i7-Mf for qemu-devel@nongnu.org; Tue, 15 Oct 2019 03:55:04 -0400 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7C4AAD881 for ; Tue, 15 Oct 2019 07:55:03 +0000 (UTC) Received: by mail-pg1-f200.google.com with SMTP id b14so4485910pgm.22 for ; Tue, 15 Oct 2019 00:55:03 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r30sm24599850pfl.42.2019.10.15.00.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 00:55:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4lnoz4PkLYCAulCk1xBitbDt3OgijwPGGC0TddpxLB4=; b=EUNGZZdGtsIYJ3TBolNFJONKKUmQ+3He6Cfne7SW8xGn6SLCUJTBOtmKt/52YsRRDK HHzdZ06AunvHvhcH4a54UJ/3cx0rGXVvGoPIKw5xujKVdO1f5rvLXE33hony3CwjTFPe pZGrnpBB0zDJtJki+C2nS++yKUC9riTGppia5oOIDknpWtRgVIbHU7HGNDew3iz9hQug Be2SpRrQ0oYGm5ruguRpB5v7776DCRxbFGgkKaZiCv8L8yv0topHpnfzHl8hkOEUBWl5 2yBBAbfBN66RMifkgkd9wT4HHUPgcyySLoy4Yg3c45fug1/vrEXxyqAnuZzF06/DXPm9 XLUw== X-Gm-Message-State: APjAAAWIc5xInXQQ1K0RBVF9Kk+b/Ykp0LmmQL1VctGEWfKkc1K1c9iR hf2fiVNUjEZJ1VewU8gqHolbQZ7pO8rJsOBcuoh1iD46Tsk0BCUou6iTGOZD9lvxR3w2HnbkJXK UGESnyBTg0f7X80k= X-Received: by 2002:a17:902:900c:: with SMTP id a12mr23391367plp.30.1571126102693; Tue, 15 Oct 2019 00:55:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE4SBCDfSEOhFhRENGfi5KEMlgYGPWZDEYGu9H+pOXotfrmwTIjfraTok8iQqa8umxNPTDkg== X-Received: by 2002:a17:902:900c:: with SMTP id a12mr23391340plp.30.1571126102408; Tue, 15 Oct 2019 00:55:02 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 2/2] apic: Use 32bit APIC ID for migration instance ID Date: Tue, 15 Oct 2019 15:54:44 +0800 Message-Id: <20191015075444.10955-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191015075444.10955-1-peterx@redhat.com> References: <20191015075444.10955-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: , Cc: Eduardo Habkost , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Migration is silently broken now with x2apic config like this: -smp 200,maxcpus=3D288,sockets=3D2,cores=3D72,threads=3D2 \ -device intel-iommu,intremap=3Don,eim=3Don After migration, the guest kernel could hang at anything, due to x2apic bit not migrated correctly in IA32_APIC_BASE on some vcpus, so any operations related to x2apic could be broken then (e.g., RDMSR on x2apic MSRs could fail because KVM would think that the vcpu hasn't enabled x2apic at all). The issue is that the x2apic bit was never applied correctly for vcpus whose ID > 255 when migrate completes, and that's because when we migrate APIC we use the APICCommonState.id as instance ID of the migration stream, while that's too short for x2apic. Let's use the newly introduced initial_apic_id for that. Signed-off-by: Peter Xu --- hw/intc/apic_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index aafd8e0e33..6024a3e06a 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -315,7 +315,7 @@ static void apic_common_realize(DeviceState *dev, Error= **errp) APICCommonState *s =3D APIC_COMMON(dev); APICCommonClass *info; static DeviceState *vapic; - int instance_id =3D s->id; + int64_t instance_id =3D s->initial_apic_id; =20 info =3D APIC_COMMON_GET_CLASS(s); info->realize(dev, errp); --=20 2.21.0