From nobody Mon Apr 29 03:12:27 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; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1569937079; cv=none; d=zoho.com; s=zohoarc; b=K4El0uPdJdzUCaBFAv6KRt7khos4567YHbjb7RLrBIyTbAb3IpnBQr/PutuJW11P/wdlEULaeY2fU0gGqV0G5Doebt0Y+qZJ8WuK+oZMOm58PjarXLdSHaiuhEmAbT8awjdW2hQCOamqNDK6y8SGogxG+pohMo+QAAc+IEh9oRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569937079; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=25onto/LTkLxgqKF/wBKkgi24fKgK/f0z5Hk8aT4U+0=; b=fXrirXc0OIRHvR9UIgPtro5qIA2ZpuuyXlNBYdYRCzGDVMptL0rIOtwOIJyAb6LEOQ/Oqm9xHMkA1+IMfYthS8Mpe6o8L4KB454nMvb1XoQsGf4GCPKU/aI1wth4yxHmTBDtI3tDZh+u08sh3q/8nHFY+ay6JrKk1iTk/GuY1hY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569937079133102.6778475684232; Tue, 1 Oct 2019 06:37:59 -0700 (PDT) Received: from localhost ([::1]:42226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFILd-0006mi-V9 for importer@patchew.org; Tue, 01 Oct 2019 09:37:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41857) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFH7D-0008MD-Sq for qemu-devel@nongnu.org; Tue, 01 Oct 2019 08:18:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iFH75-0004jy-3D for qemu-devel@nongnu.org; Tue, 01 Oct 2019 08:18:47 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:42489) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iFH74-0004hy-Qp for qemu-devel@nongnu.org; Tue, 01 Oct 2019 08:18:43 -0400 Received: by mail-ed1-x544.google.com with SMTP id y91so11658460ede.9 for ; Tue, 01 Oct 2019 05:18:42 -0700 (PDT) Received: from msennikovskii2.pb.local ([2001:1438:4010:2558:d098:3701:97c4:7b4e]) by smtp.googlemail.com with ESMTPSA id u22sm1824156eja.23.2019.10.01.05.18.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Oct 2019 05:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=25onto/LTkLxgqKF/wBKkgi24fKgK/f0z5Hk8aT4U+0=; b=MMQnpSS+H3Tth3PtFwUWYKDc3MSrz59FYWVuwJmugM4TLkH4WEArVm1yl83jm7V+SN g3Lca9hQex7/SDsh75fybjYJxZ7IlYmKqqd4JBXK2riH9+F3+5g8vRwsj2DfV/Idnaxg 0j96oMg4sXHRs8WC8DRcJJJc7TmCEdKPcPcWKD9RGRcrGUS4egkHvu2zfHJbJ2Ool4Dw I1EgemLYHe2IsH44ZxLAT0d6gyU6D4lo2MnQy2PF9/BfubVbQgVWRR44bqPr1ln5l+Rj GipLJWJddjOA2OYIaGXli22TyUzJ0ZlvzVMRn0RA+vbg/VRlx2gLcLxifyjOHkDZaF2g QKgQ== 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; bh=25onto/LTkLxgqKF/wBKkgi24fKgK/f0z5Hk8aT4U+0=; b=Oslds6KyZlaZOZ4GCrV3KGIAOeu/B35WgeGx06D1+YBuZZXkag0NdjnukxpTdhtEoK eFMM2a4BEU0phXt9JBnRr78pMHpZPVdkCnMNy9xtsJGv0e/aOq+5jELWlpVyOK2Pcyfz gHmgpMMnauVDY00incNJD2tzvJH5Uc1kEzzk+tRRefzD3gcuU/5LJITSCLpTDNM1lsbx cY6npVWZ8mvw/gzhNbmQQx/uUFqgfiCBroJN+oqFWBG7OqAugFgU74K64P2976L67mvd +kFAnhY45h3n2z4jf/bwhBzKEeVBuMMCrnGndlghPaWYokWZsVIOUW7gvdJWSs0dSGX/ jW9w== X-Gm-Message-State: APjAAAXMXqBkCBVG37TdMIj+C0QBPTreCbzlvGB03CiiM9sxu99IL3LJ NR5xtKn4WfB1R+no1Etl5vRkLRtZIr4= X-Google-Smtp-Source: APXvYqy/N8o+/bBaiZHOgru4qli3LTuv58lqBbPwR9AFtoe+OAShZ3rXQZ7NIg74mMJ4iaiT/fJI1Q== X-Received: by 2002:a50:95c1:: with SMTP id x1mr24879683eda.180.1569932320732; Tue, 01 Oct 2019 05:18:40 -0700 (PDT) From: Mikhail Sennikovsky To: qemu-devel@nongnu.org Subject: [PATCH] virtio-net: prevent offloads reset on migration Date: Tue, 1 Oct 2019 14:18:28 +0200 Message-Id: <1569932308-30478-2-git-send-email-mikhail.sennikovskii@cloud.ionos.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569932308-30478-1-git-send-email-mikhail.sennikovskii@cloud.ionos.com> References: <1569932308-30478-1-git-send-email-mikhail.sennikovskii@cloud.ionos.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::544 X-Mailman-Approved-At: Tue, 01 Oct 2019 09:36:01 -0400 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: Mikhail Sennikovsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @cloud.ionos.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently offloads disabled by guest via the VIRTIO_NET_CTRL_GUEST_OFFLOADS= _SET command are not preserved on VM migration. Instead all offloads reported by guest features (via VIRTIO_PCI_GUEST_FEATU= RES) get enabled. What happens is: first the VirtIONet::curr_guest_offloads gets restored and= offloads are getting set correctly: #0 qemu_set_offload (nc=3D0x555556a11400, csum=3D1, tso4=3D0, tso6=3D0, e= cn=3D0, ufo=3D0) at net/net.c:474 #1 virtio_net_apply_guest_offloads (n=3D0x555557701ca0) at hw/net/virtio-= net.c:720 #2 virtio_net_post_load_device (opaque=3D0x555557701ca0, version_id=3D11)= at hw/net/virtio-net.c:2334 #3 vmstate_load_state (f=3D0x5555569dc010, vmsd=3D0x555556577c80 , opaque=3D0x555557701ca0, version_id=3D11) at migration/vmstate.c:168 #4 virtio_load (vdev=3D0x555557701ca0, f=3D0x5555569dc010, version_id=3D1= 1) at hw/virtio/virtio.c:2197 #5 virtio_device_get (f=3D0x5555569dc010, opaque=3D0x555557701ca0, size= =3D0, field=3D0x55555668cd00 <__compound_literal.5>) at hw/virtio/virtio.c:= 2036 #6 vmstate_load_state (f=3D0x5555569dc010, vmsd=3D0x555556577ce0 , opaque=3D0x555557701ca0, version_id=3D11) at migration/vmstat= e.c:143 #7 vmstate_load (f=3D0x5555569dc010, se=3D0x5555578189e0) at migration/sa= vevm.c:829 #8 qemu_loadvm_section_start_full (f=3D0x5555569dc010, mis=3D0x5555569eee= 20) at migration/savevm.c:2211 #9 qemu_loadvm_state_main (f=3D0x5555569dc010, mis=3D0x5555569eee20) at m= igration/savevm.c:2395 #10 qemu_loadvm_state (f=3D0x5555569dc010) at migration/savevm.c:2467 #11 process_incoming_migration_co (opaque=3D0x0) at migration/migration.c:= 449 However later on the features are getting restored, and offloads get reset = to everything supported by features: #0 qemu_set_offload (nc=3D0x555556a11400, csum=3D1, tso4=3D1, tso6=3D1, e= cn=3D0, ufo=3D0) at net/net.c:474 #1 virtio_net_apply_guest_offloads (n=3D0x555557701ca0) at hw/net/virtio-= net.c:720 #2 virtio_net_set_features (vdev=3D0x555557701ca0, features=3D5104441767)= at hw/net/virtio-net.c:773 #3 virtio_set_features_nocheck (vdev=3D0x555557701ca0, val=3D5104441767) = at hw/virtio/virtio.c:2052 #4 virtio_load (vdev=3D0x555557701ca0, f=3D0x5555569dc010, version_id=3D1= 1) at hw/virtio/virtio.c:2220 #5 virtio_device_get (f=3D0x5555569dc010, opaque=3D0x555557701ca0, size= =3D0, field=3D0x55555668cd00 <__compound_literal.5>) at hw/virtio/virtio.c:= 2036 #6 vmstate_load_state (f=3D0x5555569dc010, vmsd=3D0x555556577ce0 , opaque=3D0x555557701ca0, version_id=3D11) at migration/vmstat= e.c:143 #7 vmstate_load (f=3D0x5555569dc010, se=3D0x5555578189e0) at migration/sa= vevm.c:829 #8 qemu_loadvm_section_start_full (f=3D0x5555569dc010, mis=3D0x5555569eee= 20) at migration/savevm.c:2211 #9 qemu_loadvm_state_main (f=3D0x5555569dc010, mis=3D0x5555569eee20) at m= igration/savevm.c:2395 #10 qemu_loadvm_state (f=3D0x5555569dc010) at migration/savevm.c:2467 #11 process_incoming_migration_co (opaque=3D0x0) at migration/migration.c:= 449 This patch fixes this by adding an extra argument to the set_features callb= ack, specifying whether the offloads are to be reset, and setting it to false for the migration case. Signed-off-by: Mikhail Sennikovsky --- hw/display/virtio-gpu-base.c | 3 ++- hw/net/virtio-net.c | 5 +++-- hw/virtio/virtio.c | 10 +++++----- include/hw/virtio/virtio.h | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index 55e0799..04d8a23 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -193,7 +193,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, } =20 static void -virtio_gpu_base_set_features(VirtIODevice *vdev, uint64_t features) +virtio_gpu_base_set_features(VirtIODevice *vdev, uint64_t features, + bool reset_offloads) { static const uint32_t virgl =3D (1 << VIRTIO_GPU_F_VIRGL); VirtIOGPUBase *g =3D VIRTIO_GPU_BASE(vdev); diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b9e1cd7..5d108e5 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -743,7 +743,8 @@ static inline uint64_t virtio_net_supported_guest_offlo= ads(VirtIONet *n) return virtio_net_guest_offloads_by_features(vdev->guest_features); } =20 -static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) +static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features, + bool reset_offloads) { VirtIONet *n =3D VIRTIO_NET(vdev); int i; @@ -767,7 +768,7 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) n->rsc6_enabled =3D virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT)= && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO6); =20 - if (n->has_vnet_hdr) { + if (reset_offloads && n->has_vnet_hdr) { n->curr_guest_offloads =3D virtio_net_guest_offloads_by_features(features); virtio_net_apply_guest_offloads(n); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a94ea18..b89f7b0 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2042,14 +2042,14 @@ const VMStateInfo virtio_vmstate_info =3D { .put =3D virtio_device_put, }; =20 -static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val) +static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val, b= ool reset_offloads) { VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); bool bad =3D (val & ~(vdev->host_features)) !=3D 0; =20 val &=3D vdev->host_features; if (k->set_features) { - k->set_features(vdev, val); + k->set_features(vdev, val, reset_offloads); } vdev->guest_features =3D val; return bad ? -1 : 0; @@ -2065,7 +2065,7 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t = val) if (vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) { return -EINVAL; } - ret =3D virtio_set_features_nocheck(vdev, val); + ret =3D virtio_set_features_nocheck(vdev, val, true); if (!ret) { if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ @@ -2217,14 +2217,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, in= t version_id) * host_features. */ uint64_t features64 =3D vdev->guest_features; - if (virtio_set_features_nocheck(vdev, features64) < 0) { + if (virtio_set_features_nocheck(vdev, features64, false) < 0) { error_report("Features 0x%" PRIx64 " unsupported. " "Allowed features: 0x%" PRIx64, features64, vdev->host_features); return -1; } } else { - if (virtio_set_features_nocheck(vdev, features) < 0) { + if (virtio_set_features_nocheck(vdev, features, false) < 0) { error_report("Features 0x%x unsupported. " "Allowed features: 0x%" PRIx64, features, vdev->host_features); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b189788..fd8cac5 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -128,7 +128,7 @@ typedef struct VirtioDeviceClass { uint64_t requested_features, Error **errp); uint64_t (*bad_features)(VirtIODevice *vdev); - void (*set_features)(VirtIODevice *vdev, uint64_t val); + void (*set_features)(VirtIODevice *vdev, uint64_t val, bool reset_offl= oads); int (*validate_features)(VirtIODevice *vdev); void (*get_config)(VirtIODevice *vdev, uint8_t *config); void (*set_config)(VirtIODevice *vdev, const uint8_t *config); --=20 2.7.4