From nobody Sun Dec 14 06:32:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1667861965; cv=none; d=zohomail.com; s=zohoarc; b=Tuk/8hkD5dqE1DvMytEc+9HopNqRgSKs2fdyeah0DLKP5QgwEXboCm8nqRy6dIy4SR3I6mqEv3IlWigsGaHYpx2ew2NWoJnak1sfDrXZzkoQYyDPt9mW7A6fsJF9h/M0brom/GvU1pa44DDTkwNIKRgnnHlKgycRMpNLmxJTibg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667861965; h=Content-Type: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=53cDP1F6gXOJDB503L4H7aDBSnQaypNNt0vv+nFB0O0=; b=PHcv1Njp7Y12hD6kYuJsDroyJfVRYo1YZkSG7c0ZompBzwbOWejMg67RDncKwJuJ7jEfO+Ge876Ft1k0pUQaNxQy9ZE14342mI9HO+55cu65j5rr2Vk/qDQxV3as4NaphTCBkE3Ca+4nEeyWMJGdYUgqQlDT/kLmayXcEeONsy8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1667861965103675.6044880921277; Mon, 7 Nov 2022 14:59:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osAwb-0000ul-W2; Mon, 07 Nov 2022 17:50:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osAwY-0000qI-Sb for qemu-devel@nongnu.org; Mon, 07 Nov 2022 17:50:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osAwX-0003jg-7n for qemu-devel@nongnu.org; Mon, 07 Nov 2022 17:50:14 -0500 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-663-tHM_3-KcN6yglgLJC24XDw-1; Mon, 07 Nov 2022 17:50:11 -0500 Received: by mail-qv1-f70.google.com with SMTP id e9-20020ad45369000000b004bbb737fcf9so8525261qvv.6 for ; Mon, 07 Nov 2022 14:50:11 -0800 (PST) Received: from redhat.com ([87.249.138.11]) by smtp.gmail.com with ESMTPSA id az36-20020a05620a172400b006ce9e880c6fsm7961705qkb.111.2022.11.07.14.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 14:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667861412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=53cDP1F6gXOJDB503L4H7aDBSnQaypNNt0vv+nFB0O0=; b=h5G5G5F5xSydBBi+K3dG/V58r0H1nmttbpxOm6wPJkkcqkSWWxaKixbzEDeOjBzMKd1NYd cfRbDOlS8SWqkPKBmm6dybo8Q/Ek8nT0EIs91ybqywgDGIWoRz4lFdlAp433oSzGR37vcs 8FgiCQOxoNNeya7zMv8K9jfTPMa/CbI= X-MC-Unique: tHM_3-KcN6yglgLJC24XDw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=53cDP1F6gXOJDB503L4H7aDBSnQaypNNt0vv+nFB0O0=; b=Ir1YoH9aFft+1M4IaU0NhS5S+bmhM7J8v1wgbkX5x/6RIvJPcSe1GL5nMPKTWOGTmm F0sW/HnGqrCUAKBiisKsue+pgWm+Qdv8EMmInR9Fz+eRn5zYIctZM6bWVdJNIEb7rr6y PDmKKLqrndtJg3MpW+zMBSHKSrY8V1JfJCv8hxaNG+WPx+dfZXZPVQJ+X59q+HkP6DYW 0T52O5/W++CFdGyWMgVFR1uYHppdB3jeiMCwsg57wWXdbLK8w64kJHb8JZvfwONLY31Z MSKwA9abKYh/27A91cJcl4xnO5CQ4Flpk6sB2eY1A/uPWT8vfJ7LuaZre/7qoEb8QA3c zVRg== X-Gm-Message-State: ACrzQf3beVmcILCoPoxrAUSMsRrEgBBAUfLoj0Z5Lm4VkyLl9OlEO6KP bJrxUi0ovRu8eB09a90IYMy59Od8/IOMyJlWeGK9IeFnznPQ38gCJx+G3I6R9knd4ACE9Pdd91N VzZy9cYLnAxYEgUCCA0ev+cf9+j6cZn7wUOk9u/oNOcsUudmd6bPml7loGwOn X-Received: by 2002:ac8:1202:0:b0:3a5:2997:cab8 with SMTP id x2-20020ac81202000000b003a52997cab8mr32175807qti.639.1667861410951; Mon, 07 Nov 2022 14:50:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM4yc4oD0Higkhd9vPcoHyrGpZKppwVqB7TyI/pIJ+ocFOARanwRlQjvMnvR2zN87eWxT1KX4g== X-Received: by 2002:ac8:1202:0:b0:3a5:2997:cab8 with SMTP id x2-20020ac81202000000b003a52997cab8mr32175785qti.639.1667861410614; Mon, 07 Nov 2022 14:50:10 -0800 (PST) Date: Mon, 7 Nov 2022 17:50:06 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Xuan Zhuo , Kangjie Xu , Jason Wang Subject: [PULL v4 31/83] virtio-pci: support queue reset Message-ID: <20221107224600.934080-32-mst@redhat.com> References: <20221107224600.934080-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221107224600.934080-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667861966962100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuan Zhuo PCI devices support vq reset. Based on this function, the driver can adjust the size of the ring, and quickly recycle the buffer in the ring. The migration of the virtio devices will not happen during a reset operation. This is becuase the global iothread lock is held. Migration thread also needs the lock. As a result, when migration of virtio devices starts, the 'reset' status of VirtIOPCIQueue will always be 0. Thus, we do not need to add it in vmstate_virtio_pci_modern_queue_state. Signed-off-by: Xuan Zhuo Signed-off-by: Kangjie Xu Acked-by: Jason Wang Message-Id: <20221017092558.111082-6-xuanzhuo@linux.alibaba.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-pci.h | 5 +++++ hw/virtio/virtio-pci.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 2446dcd9ae..938799e8f6 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -117,6 +117,11 @@ typedef struct VirtIOPCIRegion { typedef struct VirtIOPCIQueue { uint16_t num; bool enabled; + /* + * No need to migrate the reset status, because it is always 0 + * when the migration starts. + */ + bool reset; uint32_t desc[2]; uint32_t avail[2]; uint32_t used[2]; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 34db51e241..d4f2ffe986 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1251,6 +1251,9 @@ static uint64_t virtio_pci_common_read(void *opaque, = hwaddr addr, case VIRTIO_PCI_COMMON_Q_USEDHI: val =3D proxy->vqs[vdev->queue_sel].used[1]; break; + case VIRTIO_PCI_COMMON_Q_RESET: + val =3D proxy->vqs[vdev->queue_sel].reset; + break; default: val =3D 0; } @@ -1338,6 +1341,7 @@ static void virtio_pci_common_write(void *opaque, hwa= ddr addr, ((uint64_t)proxy->vqs[vdev->queue_sel].used[1]) << = 32 | proxy->vqs[vdev->queue_sel].used[0]); proxy->vqs[vdev->queue_sel].enabled =3D 1; + proxy->vqs[vdev->queue_sel].reset =3D 0; } else { virtio_error(vdev, "wrong value for queue_enable %"PRIx64, val= ); } @@ -1360,6 +1364,16 @@ static void virtio_pci_common_write(void *opaque, hw= addr addr, case VIRTIO_PCI_COMMON_Q_USEDHI: proxy->vqs[vdev->queue_sel].used[1] =3D val; break; + case VIRTIO_PCI_COMMON_Q_RESET: + if (val =3D=3D 1) { + proxy->vqs[vdev->queue_sel].reset =3D 1; + + virtio_queue_reset(vdev, vdev->queue_sel); + + proxy->vqs[vdev->queue_sel].reset =3D 0; + proxy->vqs[vdev->queue_sel].enabled =3D 0; + } + break; default: break; } @@ -1954,6 +1968,7 @@ static void virtio_pci_reset(DeviceState *qdev) =20 for (i =3D 0; i < VIRTIO_QUEUE_MAX; i++) { proxy->vqs[i].enabled =3D 0; + proxy->vqs[i].reset =3D 0; proxy->vqs[i].num =3D 0; proxy->vqs[i].desc[0] =3D proxy->vqs[i].desc[1] =3D 0; proxy->vqs[i].avail[0] =3D proxy->vqs[i].avail[1] =3D 0; --=20 MST