From nobody Sat May 18 14:25:28 2024 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=1712647996; cv=none; d=zohomail.com; s=zohoarc; b=gskiWuUVkzmapTwhfJe3ddbIvJ2YlY93Mb85pF2Vb7xXVlYu/iicKybUWZPOxrmehSP/8B74vRQ9uxHWjO5WjMJcZTpCjNiiWmHzEDsLzqsN8bCB62ueOejCieV0e89oqWBhYeKjmHIO6EmII8FdYv7z1q2iL/5UloBaulZTZX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712647996; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6Ar5SWOW/SD+yCxJFbLHklHMSf0AwZRo7BFFW580sUw=; b=LtKvZwACYuDpHIBPD6wpdWqiBeO2Q31ZNB8OU6Q9EfmD6+WafZe3YJJT9uvmdZmcqkfMp18PNEy5weZcO//4dXh/CYxuHJ5TjgUicpPxZm23lAW5rBj5TlUbS6rpj+jDakBqu8wIiX1VaJz4udNqnhBD/eJeiOmb/P6c/qykN/c= 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 171264799695548.33192800682173; Tue, 9 Apr 2024 00:33:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5y2-0006kf-VR; Tue, 09 Apr 2024 03:32:31 -0400 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 1ru5y0-0006cQ-Bq for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:28 -0400 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 1ru5xx-0001cd-Gh for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:28 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-eJr0F4R5PEGUaMyM7d2LZw-1; Tue, 09 Apr 2024 03:32:22 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a51c76700adso179928366b.0 for ; Tue, 09 Apr 2024 00:32:20 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id qs25-20020a170906459900b00a51cb282819sm3097684ejc.216.2024.04.09.00.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647944; 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=6Ar5SWOW/SD+yCxJFbLHklHMSf0AwZRo7BFFW580sUw=; b=PlaBxUC5eGB5CSLNLoyLJDf4NJ1SRcmJmsVhl7VDXDex7n+0OKpMH+B7ldV8G7uc8YrBJ3 q61e5F9gMWZS72gGr98Wb42vOfBzdER+Ld0XOkh1QvpO5EdRucNeTZcLY5mZcA2W0954ag AfGtO5k3KmHFZm6K0E0R6nCxIXD/aFw= X-MC-Unique: eJr0F4R5PEGUaMyM7d2LZw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647939; x=1713252739; 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=6Ar5SWOW/SD+yCxJFbLHklHMSf0AwZRo7BFFW580sUw=; b=H2pb1dxfiJbnFps2q4xztAyzP5/+/a0kIsVhD2vaHgXWMUcn1GHJ7m73WoNNyCnwPc ASoAWLXzY1o9nWhi8tHHqje2+ixSXcC8ObeyXUorKrk9MreTU4BJOv6tB9SK+ny4jGkg qzM3yKjqfbgiKlwkHUT6Ep9PZbK1f11PHBThJnfpLfBBwvzNYCZdF8MqaUNgUFSxqp4E vwtkvs5UQxSfdej2ugcWfCO49daaxNGIheBYbYFm3I2DKl6qLTuqmDog7ZkvgLWpn+Tl uvReZh7Aysy/Zp3xZjvNIqRfW2iB1AhBB45szfLtk8LkGhx1JaLsQgcBBO2I52wrhChx zHOQ== X-Gm-Message-State: AOJu0Yxn8bR0oCrAmigb8lcnkuDYIrTWs7Rzy/9u/PrsqvuGlkJMJoei mQzifecpQz1ang3kEtuv5frZhUmoeV5jlMQNM+Nrm3tuRopWpisriO5P8tHloeNbEWDUsHPWcoZ vYpyMIm9Rhh2oziFVfD6JlcQNLaxL4Oct8t8CUmH5/C7590Eh4l1zHrCasIhd40G3HOH2W2HY1e Vej4/FOqN8YitewarqtwjNxvknZbR8nA== X-Received: by 2002:a17:906:2b5b:b0:a51:c19f:2e13 with SMTP id b27-20020a1709062b5b00b00a51c19f2e13mr1551377ejg.2.1712647938621; Tue, 09 Apr 2024 00:32:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyNagYMKHB8W9EgOrUAohbtjVKHIqfRJjEV0cpJm5qO4nsfjhZiME3KECSf7/riHquIK0zFw== X-Received: by 2002:a17:906:2b5b:b0:a51:c19f:2e13 with SMTP id b27-20020a1709062b5b00b00a51c19f2e13mr1551351ejg.2.1712647937838; Tue, 09 Apr 2024 00:32:17 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:15 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jason Wang , Cornelia Huck , Paolo Bonzini Subject: [PULL 1/7] Revert "hw/virtio: Add support for VDPA network simulation devices" Message-ID: <4034159c1a4f5c433ae4987ff35e037a071272b7.1712647890.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712647997315100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit cd341fd1ffded978b2aa0b5309b00be7c42e347c. The patch adds non-upstream code in include/standard-headers/linux/virtio_pci.h which would make maintainance harder. Revert for now. Suggested-by: Jason Wang Message-Id: Acked-by: Jason Wang Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-pci.h | 5 - include/hw/virtio/virtio.h | 19 -- include/standard-headers/linux/virtio_pci.h | 7 - hw/net/virtio-net.c | 16 -- hw/virtio/virtio-pci.c | 189 +------------------- hw/virtio/virtio.c | 39 ---- MAINTAINERS | 5 - docs/system/device-emulation.rst | 1 - docs/system/devices/vdpa-net.rst | 121 ------------- 9 files changed, 3 insertions(+), 399 deletions(-) delete mode 100644 docs/system/devices/vdpa-net.rst diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 4d57a9c751..59d88018c1 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -43,7 +43,6 @@ enum { VIRTIO_PCI_FLAG_INIT_FLR_BIT, VIRTIO_PCI_FLAG_AER_BIT, VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT, - VIRTIO_PCI_FLAG_VDPA_BIT, }; =20 /* Need to activate work-arounds for buggy guests at vmstate load. */ @@ -90,9 +89,6 @@ enum { #define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \ (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT) =20 -/* VDPA supported flags */ -#define VIRTIO_PCI_FLAG_VDPA (1 << VIRTIO_PCI_FLAG_VDPA_BIT) - typedef struct { MSIMessage msg; int virq; @@ -144,7 +140,6 @@ struct VirtIOPCIProxy { }; VirtIOPCIRegion regs[5]; }; - VirtIOPCIRegion lm; MemoryRegion modern_bar; MemoryRegion io_bar; uint32_t legacy_io_bar_idx; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b3c74a1bca..c8f72850bc 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -35,9 +35,6 @@ (0x1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \ (0x1ULL << VIRTIO_F_ANY_LAYOUT)) =20 -#define LM_DISABLE 0x00 -#define LM_ENABLE 0x01 - struct VirtQueue; =20 static inline hwaddr vring_align(hwaddr addr, @@ -98,11 +95,6 @@ enum virtio_device_endian { VIRTIO_DEVICE_ENDIAN_BIG, }; =20 -typedef struct BitmapMemoryRegionCaches { - struct rcu_head rcu; - MemoryRegionCache bitmap; -} BitmapMemoryRegionCaches; - /** * struct VirtIODevice - common VirtIO structure * @name: name of the device @@ -136,14 +128,6 @@ struct VirtIODevice uint32_t generation; int nvectors; VirtQueue *vq; - uint8_t lm_logging_ctrl; - uint32_t lm_base_addr_low; - uint32_t lm_base_addr_high; - uint32_t lm_end_addr_low; - uint32_t lm_end_addr_high; - - BitmapMemoryRegionCaches *caches; - MemoryListener listener; uint16_t device_id; /* @vm_running: current VM running state via virtio_vmstate_change() */ @@ -395,11 +379,8 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, = int n); hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); -unsigned int virtio_queue_get_vring_states(VirtIODevice *vdev, int n); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx); -void virtio_queue_set_vring_states(VirtIODevice *vdev, int n, - unsigned int idx); void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n); void virtio_queue_update_used_idx(VirtIODevice *vdev, int n); diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard= -headers/linux/virtio_pci.h index 86733278ba..3e2bc2c97e 100644 --- a/include/standard-headers/linux/virtio_pci.h +++ b/include/standard-headers/linux/virtio_pci.h @@ -221,13 +221,6 @@ struct virtio_pci_cfg_cap { #define VIRTIO_PCI_COMMON_ADM_Q_IDX 60 #define VIRTIO_PCI_COMMON_ADM_Q_NUM 62 =20 -#define LM_LOGGING_CTRL 0 -#define LM_BASE_ADDR_LOW 4 -#define LM_BASE_ADDR_HIGH 8 -#define LM_END_ADDR_LOW 12 -#define LM_END_ADDR_HIGH 16 -#define LM_VRING_STATE_OFFSET 0x20 - #endif /* VIRTIO_PCI_NO_MODERN */ =20 /* Admin command status. */ diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 58014a92ad..24e5e7d347 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2039,22 +2039,6 @@ static ssize_t virtio_net_receive_rcu(NetClientState= *nc, const uint8_t *buf, goto err; } =20 - /* Mark dirty page's bitmap of guest memory */ - if (vdev->lm_logging_ctrl =3D=3D LM_ENABLE) { - uint64_t chunk =3D elem->in_addr[i] / VHOST_LOG_CHUNK; - /* Get chunk index */ - BitmapMemoryRegionCaches *caches =3D qatomic_rcu_read(&vdev->c= aches); - uint64_t index =3D chunk / 8; - uint64_t shift =3D chunk % 8; - uint8_t val =3D 0; - address_space_read_cached(&caches->bitmap, index, &val, - sizeof(val)); - val |=3D 1 << shift; - address_space_write_cached(&caches->bitmap, index, &val, - sizeof(val)); - address_space_cache_invalidate(&caches->bitmap, index, sizeof(= val)); - } - elems[i] =3D elem; lens[i] =3D total; i++; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index eaaf86402c..cb6940fc0e 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1442,155 +1442,6 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, return virtio_pci_add_mem_cap(proxy, &cap.cap); } =20 -/* Called within call_rcu(). */ -static void bitmap_free_region_cache(BitmapMemoryRegionCaches *caches) -{ - assert(caches !=3D NULL); - address_space_cache_destroy(&caches->bitmap); - g_free(caches); -} - -static void lm_disable(VirtIODevice *vdev) -{ - BitmapMemoryRegionCaches *caches; - caches =3D qatomic_read(&vdev->caches); - qatomic_rcu_set(&vdev->caches, NULL); - if (caches) { - call_rcu(caches, bitmap_free_region_cache, rcu); - } -} - -static void lm_enable(VirtIODevice *vdev) -{ - BitmapMemoryRegionCaches *old =3D vdev->caches; - BitmapMemoryRegionCaches *new =3D NULL; - hwaddr addr, end, size; - int64_t len; - - addr =3D vdev->lm_base_addr_low | ((hwaddr)(vdev->lm_base_addr_high) <= < 32); - end =3D vdev->lm_end_addr_low | ((hwaddr)(vdev->lm_end_addr_high) << 3= 2); - size =3D end - addr; - if (size <=3D 0) { - error_report("Invalid lm size."); - return; - } - - new =3D g_new0(BitmapMemoryRegionCaches, 1); - len =3D address_space_cache_init(&new->bitmap, vdev->dma_as, addr, siz= e, - true); - if (len < size) { - virtio_error(vdev, "Cannot map bitmap"); - goto err_bitmap; - } - qatomic_rcu_set(&vdev->caches, new); - - if (old) { - call_rcu(old, bitmap_free_region_cache, rcu); - } - - return; - -err_bitmap: - address_space_cache_destroy(&new->bitmap); - g_free(new); -} - -static uint64_t virtio_pci_lm_read(void *opaque, hwaddr addr, - unsigned size) -{ - VirtIOPCIProxy *proxy =3D opaque; - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - hwaddr offset_end =3D LM_VRING_STATE_OFFSET + - virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MA= X; - uint32_t val; - int qid; - - if (vdev =3D=3D NULL) { - return UINT64_MAX; - } - switch (addr) { - case LM_LOGGING_CTRL: - val =3D vdev->lm_logging_ctrl; - break; - case LM_BASE_ADDR_LOW: - val =3D vdev->lm_base_addr_low; - break; - case LM_BASE_ADDR_HIGH: - val =3D vdev->lm_base_addr_high; - break; - case LM_END_ADDR_LOW: - val =3D vdev->lm_end_addr_low; - break; - case LM_END_ADDR_HIGH: - val =3D vdev->lm_end_addr_high; - break; - default: - if (addr >=3D LM_VRING_STATE_OFFSET && addr <=3D offset_end) { - qid =3D (addr - LM_VRING_STATE_OFFSET) / - virtio_pci_queue_mem_mult(proxy); - val =3D virtio_queue_get_vring_states(vdev, qid); - } else - val =3D 0; - - break; - } - - return val; -} - -static void virtio_pci_lm_write(void *opaque, hwaddr addr, - uint64_t val, unsigned size) -{ - VirtIOPCIProxy *proxy =3D opaque; - VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); - hwaddr offset_end =3D LM_VRING_STATE_OFFSET + - virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MA= X; - int qid; - - if (vdev =3D=3D NULL) { - return; - } - - switch (addr) { - case LM_LOGGING_CTRL: - vdev->lm_logging_ctrl =3D val; - switch (val) { - case LM_DISABLE: - lm_disable(vdev); - break; - case LM_ENABLE: - lm_enable(vdev); - break; - default: - virtio_error(vdev, "Unsupport LM_LOGGING_CTRL value: %"PRIx64, - val); - break; - }; - - break; - case LM_BASE_ADDR_LOW: - vdev->lm_base_addr_low =3D val; - break; - case LM_BASE_ADDR_HIGH: - vdev->lm_base_addr_high =3D val; - break; - case LM_END_ADDR_LOW: - vdev->lm_end_addr_low =3D val; - break; - case LM_END_ADDR_HIGH: - vdev->lm_end_addr_high =3D val; - break; - default: - if (addr >=3D LM_VRING_STATE_OFFSET && addr <=3D offset_end) { - qid =3D (addr - LM_VRING_STATE_OFFSET) / - virtio_pci_queue_mem_mult(proxy); - virtio_queue_set_vring_states(vdev, qid, val); - } else - virtio_error(vdev, "Unsupport addr: %"PRIx64, addr); - break; - } -} - static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { @@ -1972,15 +1823,6 @@ static void virtio_pci_modern_regions_init(VirtIOPCI= Proxy *proxy, }, .endianness =3D DEVICE_LITTLE_ENDIAN, }; - static const MemoryRegionOps lm_ops =3D { - .read =3D virtio_pci_lm_read, - .write =3D virtio_pci_lm_write, - .impl =3D { - .min_access_size =3D 1, - .max_access_size =3D 4, - }, - .endianness =3D DEVICE_LITTLE_ENDIAN, - }; g_autoptr(GString) name =3D g_string_new(NULL); =20 g_string_printf(name, "virtio-pci-common-%s", vdev_name); @@ -2017,14 +1859,6 @@ static void virtio_pci_modern_regions_init(VirtIOPCI= Proxy *proxy, proxy, name->str, proxy->notify_pio.size); - if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { - g_string_printf(name, "virtio-pci-lm-%s", vdev_name); - memory_region_init_io(&proxy->lm.mr, OBJECT(proxy), - &lm_ops, - proxy, - name->str, - proxy->lm.size); - } } =20 static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, @@ -2187,10 +2021,6 @@ static void virtio_pci_device_plugged(DeviceState *d= , Error **errp) virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->device, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->notify, ¬ify.ca= p); - if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { - memory_region_add_subregion(&proxy->modern_bar, - proxy->lm.offset, &proxy->lm.mr); - } =20 if (modern_pio) { memory_region_init(&proxy->io_bar, OBJECT(proxy), @@ -2260,9 +2090,6 @@ static void virtio_pci_device_unplugged(DeviceState *= d) virtio_pci_modern_mem_region_unmap(proxy, &proxy->isr); virtio_pci_modern_mem_region_unmap(proxy, &proxy->device); virtio_pci_modern_mem_region_unmap(proxy, &proxy->notify); - if (proxy->flags & VIRTIO_PCI_FLAG_VDPA) { - memory_region_del_subregion(&proxy->modern_bar, &proxy->lm.mr); - } if (modern_pio) { virtio_pci_modern_io_region_unmap(proxy, &proxy->notify_pio); } @@ -2317,17 +2144,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, E= rror **errp) proxy->notify_pio.type =3D VIRTIO_PCI_CAP_NOTIFY_CFG; =20 /* subclasses can enforce modern, so do this unconditionally */ - if (!(proxy->flags & VIRTIO_PCI_FLAG_VDPA)) { - memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", - /* PCI BAR regions must be powers of 2 */ - pow2ceil(proxy->notify.offset + proxy->notify.s= ize)); - } else { - proxy->lm.offset =3D proxy->notify.offset + proxy->notify.size; - proxy->lm.size =3D 0x20 + VIRTIO_QUEUE_MAX * 4; - memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", - /* PCI BAR regions must be powers of 2 */ - pow2ceil(proxy->lm.offset + proxy->lm.size)); - } + memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", + /* PCI BAR regions must be powers of 2 */ + pow2ceil(proxy->notify.offset + proxy->notify.size)= ); =20 if (proxy->disable_legacy =3D=3D ON_OFF_AUTO_AUTO) { proxy->disable_legacy =3D pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO= _OFF; @@ -2482,8 +2301,6 @@ static Property virtio_pci_properties[] =3D { VIRTIO_PCI_FLAG_INIT_FLR_BIT, true), DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_AER_BIT, false), - DEFINE_PROP_BIT("vdpa", VirtIOPCIProxy, flags, - VIRTIO_PCI_FLAG_VDPA_BIT, false), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index fb6b4ccd83..d229755eae 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3368,18 +3368,6 @@ static uint16_t virtio_queue_split_get_last_avail_id= x(VirtIODevice *vdev, return vdev->vq[n].last_avail_idx; } =20 -static uint32_t virtio_queue_split_get_vring_states(VirtIODevice *vdev, - int n) -{ - struct VirtQueue *vq =3D &vdev->vq[n]; - uint16_t avail, used; - - avail =3D vq->last_avail_idx; - used =3D vq->used_idx; - - return avail | (uint32_t)used << 16; -} - unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n) { if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { @@ -3389,33 +3377,6 @@ unsigned int virtio_queue_get_last_avail_idx(VirtIOD= evice *vdev, int n) } } =20 -unsigned int virtio_queue_get_vring_states(VirtIODevice *vdev, int n) -{ - if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { - return -1; - } else { - return virtio_queue_split_get_vring_states(vdev, n); - } -} - -static void virtio_queue_split_set_vring_states(VirtIODevice *vdev, - int n, uint32_t idx) -{ - struct VirtQueue *vq =3D &vdev->vq[n]; - vq->last_avail_idx =3D (uint16_t)(idx & 0xffff); - vq->shadow_avail_idx =3D (uint16_t)(idx & 0xffff); - vq->used_idx =3D (uint16_t)(idx >> 16); -} - -void virtio_queue_set_vring_states(VirtIODevice *vdev, int n, uint32_t idx) -{ - if (virtio_vdev_has_feature(vdev, VIRTIO_F_RING_PACKED)) { - return; - } else { - virtio_queue_split_set_vring_states(vdev, n, idx); - } -} - static void virtio_queue_packed_set_last_avail_idx(VirtIODevice *vdev, int n, unsigned int idx) { diff --git a/MAINTAINERS b/MAINTAINERS index e71183eef9..249b678fc6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2370,11 +2370,6 @@ F: hw/virtio/vhost-user-scmi* F: include/hw/virtio/vhost-user-scmi.h F: tests/qtest/libqos/virtio-scmi.* =20 -vdpa-net -M: Hao Chen -S: Maintained -F: docs/system/devices/vdpa-net.rst - virtio-crypto M: Gonglei S: Supported diff --git a/docs/system/device-emulation.rst b/docs/system/device-emulatio= n.rst index e4a27f53c8..f19777411c 100644 --- a/docs/system/device-emulation.rst +++ b/docs/system/device-emulation.rst @@ -99,4 +99,3 @@ Emulated Devices devices/canokey.rst devices/usb-u2f.rst devices/igb.rst - devices/vdpa-net.rst diff --git a/docs/system/devices/vdpa-net.rst b/docs/system/devices/vdpa-ne= t.rst deleted file mode 100644 index 323d8c926a..0000000000 --- a/docs/system/devices/vdpa-net.rst +++ /dev/null @@ -1,121 +0,0 @@ -vdpa net -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -This document explains the setup and usage of the vdpa network device. -The vdpa network device is a paravirtualized vdpa emulate device. - -Description ------------ - -VDPA net devices support dirty page bitmap mark and vring state saving and= recovery. - -Users can use this VDPA device for live migration simulation testing in a = nested virtualization environment. - -Registers layout ----------------- - -The vdpa device add live migrate registers layout as follow:: - - Offset Register Name Bitwidth Associated vq - 0x0 LM_LOGGING_CTRL 4bits - 0x10 LM_BASE_ADDR_LOW 32bits - 0x14 LM_BASE_ADDR_HIGH 32bits - 0x18 LM_END_ADDR_LOW 32bits - 0x1c LM_END_ADDR_HIGH 32bits - 0x20 LM_RING_STATE_OFFSET 32bits vq0 - 0x24 LM_RING_STATE_OFFSET 32bits vq1 - 0x28 LM_RING_STATE_OFFSET 32bits vq2 - ...... - 0x20+1023*4 LM_RING_STATE_OFFSET 32bits vq1023 - -These registers are extended at the end of the notify bar space. - -Architecture diagram --------------------- -:: - - |-----------------------------------------------------------------------= -| - | guest-L1-user-space = | - | = | - | |---------------------------------------= -| - | | [virtio-net driver] = | - | | ^ guest-L2-src(iommu=3Do= n) | - | |--------------|------------------------= -| - | | | qemu-L2-src(viommu) = | - | [dpdk-vdpa]<->[vhost socket]<-+->[vhost-user backend(iommu=3Don)] = | - ------------------------------------------------------------------------= -- - ------------------------------------------------------------------------= -- - | ^ guest-L1-kernel-space = | - | | = | - | [VFIO] = | - | ^ = | - | | guest-L1-src(iommu=3Don) = | - --------|---------------------------------------------------------------= -- - --------|---------------------------------------------------------------= -- - | [vdpa net device(iommu=3Don)] [manager nic device] = | - | | | = | - | | | = | - | [tap device] qemu-L1-src(viommu) | = | - ------------------------------------------------+-----------------------= -- - | - | - --------------------- | - | kernel net bridge |<----- - | virbr0 |<----------------------------= ------ - --------------------- = | - = | - = | - ------------------------------------------------------------------------= -- | - | guest-L1-user-space = | | - | = | | - | |---------------------------------------= -| | - | | [virtio-net driver] = | | - | | ^ guest-L2-dst(iommu=3Do= n) | | - | |--------------|------------------------= -| | - | | | qemu-L2-dst(viommu) = | | - | [dpdk-vdpa]<->[vhost socket]<-+->[vhost-user backend(iommu=3Don)] = | | - ------------------------------------------------------------------------= -- | - ------------------------------------------------------------------------= -- | - | ^ guest-L1-kernel-space = | | - | | = | | - | [VFIO] = | | - | ^ = | | - | | guest-L1-dst(iommu=3Don) = | | - --------|---------------------------------------------------------------= -- | - --------|---------------------------------------------------------------= -- | - | [vdpa net device(iommu=3Don)] [manager nic device]-------------= ---+---- - | | = | - | | = | - | [tap device] qemu-L1-dst(viommu) = | - ------------------------------------------------------------------------= -- - - -Device properties ------------------ - -The Virtio vdpa device can be configured with the following properties: - - * ``vdpa=3Don`` open vdpa device emulated. - -Usages --------- -This patch add virtio sriov support and vdpa live migrate support. -You can open vdpa by set xml file as follow:: - - - - - - - - - - -Limitations ------------ -1. Dependent on tap device with param ``vhost=3Doff``. -2. Nested virtualization environment only supports ``q35`` machines. -3. Current only support split vring live migrate. - - - --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712648020; cv=none; d=zohomail.com; s=zohoarc; b=Hx4s5vPRrRmVZTyRhlvJGqPGWzHHuSfpGAKpgmkNVivNCKRkTVw01bdw+s3qjyrtZq4s+3OoXIvmxgEwEnaTYsVYH2i1drTLxVXe3ZBEothk+IKE6vI3/WWZFJXeALurlgtAEGiy/upZZh2xVqzWdjnbDmjdgy+reyXb0IqqIsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712648020; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=13FuLCNcJSjRaX6g3RxQK/vpt27WSempKd9hfNRZ2Ts=; b=KWm6lPUBKVyxWO62ODAO44DbSvwYaXj2yAw2S/b6XAErAASR/RBlt3QqUUOlktT1UQn9lDWsDTgfYKD1rAVQxz5F+3Oab4hRCpbtpkwANkGh2i4sqWMRla8UKAGEW6dzdzccYQil9J2013ceHyEpIy2qd/GjJd9Dai6o8t1EfqM= 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 1712648020888910.1387351462839; Tue, 9 Apr 2024 00:33:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5y1-0006ff-5N; Tue, 09 Apr 2024 03:32:29 -0400 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 1ru5xz-0006cH-My for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru5xy-0001ck-5S for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:27 -0400 Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-q_LInYb5PlGzlb8exSaRJQ-1; Tue, 09 Apr 2024 03:32:24 -0400 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d87f5937fcso19555781fa.0 for ; Tue, 09 Apr 2024 00:32:24 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id g3-20020a170906394300b00a4e40e48f8dsm5294629eje.185.2024.04.09.00.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647945; 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=13FuLCNcJSjRaX6g3RxQK/vpt27WSempKd9hfNRZ2Ts=; b=Z1EpSMBbn90XZoutDIuNdhbZOlaWTtXR0S9uXW2MS3BmVdVkiXU+bE90MRLwhNaxTboUnz dZSDQlmVMpDF8J3amPm3wdWaRCY3sG0NTfG+12EBj/Qj7swE1q9OvyZpsFrX9xNrXOjvzv sWqHxw6GaB5i+EIn9pM99IxL8Ome0/M= X-MC-Unique: q_LInYb5PlGzlb8exSaRJQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647942; x=1713252742; 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=13FuLCNcJSjRaX6g3RxQK/vpt27WSempKd9hfNRZ2Ts=; b=IpQJYaEKnL3C8GVNTdwcVqEaH0jloKWzHbvXcZ4CUJ9sAOTlIMJD+KnWT0eEZLgWqU W+a9VjsjG58rFnXnjCK0VlQCsqGeqbLGFdmYo59gj6VGphp7+TdVGOo5v6JcWQ50yzQ6 bnOpyEArtHp5YCIGxsaLOydUTfFifR3WjLq8hZLUGyJb9q5majx4RFqtZwZ6q2NqxU3h 1n5gXNqK1bcDRIj4BaJD/Ufx0xuvsqEjoqAhH11uvwmDxrGvpXgjyQwkaW8aaQH6E8bb CQ0wurf4tgG5XlNMI/P3pMyovl2Nv/7GwEo/q/v+4IbrF6LhmfM3wo51xoJmWo/Cu3YY Hk+A== X-Gm-Message-State: AOJu0YzCKixmO/jrdhRFj8p0AF8S9g1/bmq5ljHEVqA8bK+Ns6OXjXKJ JADRKz1ANJcolALKHXGG20KCHc13bbNvv6o1j8EZ9YmqNqG1blqHip2l5b+/zGugRi2M0q4enDU 9v7tJCNcDekbu5gTlFAFGdodRozCyC+iUdu0ZbzD4Uyv/eNzBgk4r1U2HuGd+PZJN4RHkB/nIta bsszwFcsmx55VTIvdrELbBZHgprCMI4Q== X-Received: by 2002:ac2:4c01:0:b0:515:ad59:d46a with SMTP id t1-20020ac24c01000000b00515ad59d46amr9200573lfq.21.1712647942010; Tue, 09 Apr 2024 00:32:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEStqoInFBKTBk/e8ilFKodfzI6qXC+C2bEC/lO9gzdrEOvV+1zYd2Otq7jZgW+x2V5HTzwBA== X-Received: by 2002:ac2:4c01:0:b0:515:ad59:d46a with SMTP id t1-20020ac24c01000000b00515ad59d46amr9200541lfq.21.1712647941283; Tue, 09 Apr 2024 00:32:21 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zheyu Ma , Manos Pitsidianakis , Gerd Hoffmann Subject: [PULL 2/7] virtio-snd: Enhance error handling for invalid transfers Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712648021327100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zheyu Ma This patch improves error handling in virtio_snd_handle_tx_xfer() and virtio_snd_handle_rx_xfer() in the VirtIO sound driver. Previously, 'goto' statements were used for error paths, leading to unnecessary processing and potential null pointer dereferences. Now, 'continue' is used to skip the rest of the current loop iteration for errors such as message size discrepancies or null streams, reducing crash risks. ASAN log illustrating the issue addressed: ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000b4 #0 0x57cea39967b8 in qemu_mutex_lock_impl qemu/util/qemu-thread-posix.c= :92:5 #1 0x57cea128c462 in qemu_mutex_lock qemu/include/qemu/thread.h:122:5 #2 0x57cea128d72f in qemu_lockable_lock qemu/include/qemu/lockable.h:95= :5 #3 0x57cea128c294 in qemu_lockable_auto_lock qemu/include/qemu/lockable= .h:105:5 #4 0x57cea1285eb2 in virtio_snd_handle_rx_xfer qemu/hw/audio/virtio-snd= .c:1026:9 #5 0x57cea2caebbc in virtio_queue_notify_vq qemu/hw/virtio/virtio.c:226= 8:9 #6 0x57cea2cae412 in virtio_queue_host_notifier_read qemu/hw/virtio/vir= tio.c:3671:9 #7 0x57cea39822f1 in aio_dispatch_handler qemu/util/aio-posix.c:372:9 #8 0x57cea3979385 in aio_dispatch_handlers qemu/util/aio-posix.c:414:20 #9 0x57cea3978eb1 in aio_dispatch qemu/util/aio-posix.c:424:5 #10 0x57cea3a1eede in aio_ctx_dispatch qemu/util/async.c:360:5 Signed-off-by: Zheyu Ma Reviewed-by: Manos Pitsidianakis Message-Id: <20240322110827.568412-1-zheyuma97@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/audio/virtio-snd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index e604d8f30c..30493f06a8 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -913,13 +913,13 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) &hdr, sizeof(virtio_snd_pcm_xfer)); if (msg_sz !=3D sizeof(virtio_snd_pcm_xfer)) { - goto tx_err; + continue; } stream_id =3D le32_to_cpu(hdr.stream_id); =20 if (stream_id >=3D s->snd_conf.streams || s->pcm->streams[stream_id] =3D=3D NULL) { - goto tx_err; + continue; } =20 stream =3D s->pcm->streams[stream_id]; @@ -995,13 +995,13 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *v= dev, VirtQueue *vq) &hdr, sizeof(virtio_snd_pcm_xfer)); if (msg_sz !=3D sizeof(virtio_snd_pcm_xfer)) { - goto rx_err; + continue; } stream_id =3D le32_to_cpu(hdr.stream_id); =20 if (stream_id >=3D s->snd_conf.streams || !s->pcm->streams[stream_id]) { - goto rx_err; + continue; } =20 stream =3D s->pcm->streams[stream_id]; --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712648030; cv=none; d=zohomail.com; s=zohoarc; b=SVnlxpLoCEJVgR8wXgw21z5zicbFaA6vWBPrY2/2dGr6ANvGWrA4KVczOvBNuTQJEIClp1nuw6e8IaZf6z7ukgaRDdPjjAfoOyey46DlWp04ZmuEtR27A4wlD36ZRRMuCyE1WpjcNSwGEzJpyoCjmHG3Mx4GiXQFwjaq1bskHzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712648030; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LWDhehH7wmu/YDkzC1AQ1ScvZA4zxlmQ/2HFjTowbXA=; b=W228XJndkLxweywtLxLsgV4O8FFQuFjbJPfC42/7NcQLzchfD8aA3odFjaUVZR9/Jvqx+Uf5zylx3jv2DW6sZX75WrQlEm2OQsRbyKb/mxI5dDgtofem9z2Hz6PG/PKL88V2zD1SkIUmg4E/Rec6+77YWgyWcDXXb227ZcQoxSw= 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 1712648030349708.358062483671; Tue, 9 Apr 2024 00:33:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5y4-0006oi-9r; Tue, 09 Apr 2024 03:32:32 -0400 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 1ru5y3-0006mK-KF for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:31 -0400 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 1ru5y1-0001d5-AL for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:31 -0400 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-lRFOqLklMWiQ83TGg93v7g-1; Tue, 09 Apr 2024 03:32:26 -0400 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-56e242ec7ffso2472003a12.3 for ; Tue, 09 Apr 2024 00:32:26 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id cw23-20020a170906c79700b00a51bf5932aesm3814519ejb.28.2024.04.09.00.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647948; 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=LWDhehH7wmu/YDkzC1AQ1ScvZA4zxlmQ/2HFjTowbXA=; b=cyM3lS3bjBfN2afEwjdE1Y8horatZ+Ez+ehiP17tJX6icBloSn077kMO/MR9AD5DtB8oTu G8jnctNuWK0VfeLYFtrxqdttaVkv2xL+DaNZ/yPIV1eHnlqzLXneFx0KhzGHqHay+dGvQo 62VFLH//I8en3wTRiGIc8HmypFAE3R8= X-MC-Unique: lRFOqLklMWiQ83TGg93v7g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647945; x=1713252745; 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=LWDhehH7wmu/YDkzC1AQ1ScvZA4zxlmQ/2HFjTowbXA=; b=HJccNYNQhnSRJn4hn8FbRddWIJg4AWsyaRf59WzK0qyn+MSQEDkGpa2w6uf10BUJ/w BzRH2GdENbdEM17NVo4vPCEFQUVZSERgIyRBJhbHEpvl3CxoTnWjQ+/SyqgKNvkrwEoC I6XEg9o5DL9Fyyg9XgkgUvEm6JaziZfBMBJKneZiLhlvb57ihD/eee6NGHPz4M8h37Uc wcKya6OcY+mao9cC3hEreRH0S++cxT3wiuYDutyJtnMu2idVJQNwLAWt91dnB1EiNrZS 9uhfvTWdc62ozjIXIwYmCHOq6H1vNKh2aqwnahaibe5nzXf6pHclUeGfqMH6Fb3g2Du6 mnQg== X-Gm-Message-State: AOJu0YyQZ+eORIKhIBtOADXeJ/aifw27xaEAfdM8NpxiG/IKS1DNtLba vM/hbmypFr/F/wT+hs+fPQJWZnshfCGMHsZAhx4kRSxXSKKd5XIppe8Ekc19cGsDeEqIaJ8n1xk qdqIYXrpm03EUU8v//wkYibkELjdir8P+E2ByWmzpwNRHjCLlUF6nHSClA8VTjVtgiin/PqTs3G ByprVDRUQBclaNH3czFxp4qClabXkCcA== X-Received: by 2002:a17:906:cce6:b0:a4d:ffcb:1f4e with SMTP id ot38-20020a170906cce600b00a4dffcb1f4emr5429065ejb.75.1712647944800; Tue, 09 Apr 2024 00:32:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqu8lUNRb1sMNTGDqhKI9fo17fz7ExE4PiqihgeH5ybLxB/zp5bHKxHgr/tASPJjwrIu97jw== X-Received: by 2002:a17:906:cce6:b0:a4d:ffcb:1f4e with SMTP id ot38-20020a170906cce600b00a4dffcb1f4emr5429041ejb.75.1712647944031; Tue, 09 Apr 2024 00:32:24 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:21 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Manos Pitsidianakis , Gerd Hoffmann Subject: [PULL 3/7] virtio-snd: rewrite invalid tx/rx message handling Message-ID: <731655f87f319fd06f27282c6cafbc2467ac8045.1712647890.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712648031438100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis The current handling of invalid virtqueue elements inside the TX/RX virt queue handlers is wrong. They are added in a per-stream invalid queue to be processed after the handler is done examining each message, but the invalid message might not be specifying any stream_id; which means it's invalid to add it to any stream->invalid queue since stream could be NULL at this point. This commit moves the invalid queue to the VirtIOSound struct which guarantees there will always be a valid temporary place to store them inside the tx/rx handlers. The queue will be emptied before the handler returns, so the queue must be empty at any other point of the device's lifetime. Signed-off-by: Manos Pitsidianakis Message-Id: Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/audio/virtio-snd.h | 16 +++- hw/audio/virtio-snd.c | 137 +++++++++++++++------------------- 2 files changed, 77 insertions(+), 76 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 3d79181364..8dafedb276 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -151,7 +151,6 @@ struct VirtIOSoundPCMStream { QemuMutex queue_mutex; bool active; QSIMPLEQ_HEAD(, VirtIOSoundPCMBuffer) queue; - QSIMPLEQ_HEAD(, VirtIOSoundPCMBuffer) invalid; }; =20 /* @@ -223,6 +222,21 @@ struct VirtIOSound { QemuMutex cmdq_mutex; QTAILQ_HEAD(, virtio_snd_ctrl_command) cmdq; bool processing_cmdq; + /* + * Convenience queue to keep track of invalid tx/rx queue messages ins= ide + * the tx/rx callbacks. + * + * In the callbacks as a first step we are emptying the virtqueue to h= andle + * each message and we cannot add an invalid message back to the queue= : we + * would re-process it in subsequent loop iterations. + * + * Instead, we add them to this queue and after finishing examining ev= ery + * virtqueue element, we inform the guest for each invalid message. + * + * This queue must be empty at all times except for inside the tx/rx + * callbacks. + */ + QSIMPLEQ_HEAD(, VirtIOSoundPCMBuffer) invalid; }; =20 struct virtio_snd_ctrl_command { diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 30493f06a8..90d9a2796e 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -456,7 +456,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, = uint32_t stream_id) stream->s =3D s; qemu_mutex_init(&stream->queue_mutex); QSIMPLEQ_INIT(&stream->queue); - QSIMPLEQ_INIT(&stream->invalid); =20 /* * stream_id >=3D s->snd_conf.streams was checked before so this is @@ -611,9 +610,6 @@ static size_t virtio_snd_pcm_get_io_msgs_count(VirtIOSo= undPCMStream *stream) QSIMPLEQ_FOREACH_SAFE(buffer, &stream->queue, entry, next) { count +=3D 1; } - QSIMPLEQ_FOREACH_SAFE(buffer, &stream->invalid, entry, next) { - count +=3D 1; - } } return count; } @@ -831,47 +827,36 @@ static void virtio_snd_handle_event(VirtIODevice *vde= v, VirtQueue *vq) trace_virtio_snd_handle_event(); } =20 +/* + * Must only be called if vsnd->invalid is not empty. + */ static inline void empty_invalid_queue(VirtIODevice *vdev, VirtQueue *vq) { VirtIOSoundPCMBuffer *buffer =3D NULL; - VirtIOSoundPCMStream *stream =3D NULL; virtio_snd_pcm_status resp =3D { 0 }; VirtIOSound *vsnd =3D VIRTIO_SND(vdev); - bool any =3D false; =20 - for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { - stream =3D vsnd->pcm->streams[i]; - if (stream) { - any =3D false; - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - while (!QSIMPLEQ_EMPTY(&stream->invalid)) { - buffer =3D QSIMPLEQ_FIRST(&stream->invalid); - if (buffer->vq !=3D vq) { - break; - } - any =3D true; - resp.status =3D cpu_to_le32(VIRTIO_SND_S_BAD_MSG); - iov_from_buf(buffer->elem->in_sg, - buffer->elem->in_num, - 0, - &resp, - sizeof(virtio_snd_pcm_status)); - virtqueue_push(vq, - buffer->elem, - sizeof(virtio_snd_pcm_status)); - QSIMPLEQ_REMOVE_HEAD(&stream->invalid, entry); - virtio_snd_pcm_buffer_free(buffer); - } - if (any) { - /* - * Notify vq about virtio_snd_pcm_status responses. - * Buffer responses must be notified separately later. - */ - virtio_notify(vdev, vq); - } - } - } + g_assert(!QSIMPLEQ_EMPTY(&vsnd->invalid)); + + while (!QSIMPLEQ_EMPTY(&vsnd->invalid)) { + buffer =3D QSIMPLEQ_FIRST(&vsnd->invalid); + /* If buffer->vq !=3D vq, our logic is fundamentally wrong, so bai= l out */ + g_assert(buffer->vq =3D=3D vq); + + resp.status =3D cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + iov_from_buf(buffer->elem->in_sg, + buffer->elem->in_num, + 0, + &resp, + sizeof(virtio_snd_pcm_status)); + virtqueue_push(vq, + buffer->elem, + sizeof(virtio_snd_pcm_status)); + QSIMPLEQ_REMOVE_HEAD(&vsnd->invalid, entry); + virtio_snd_pcm_buffer_free(buffer); } + /* Notify vq about virtio_snd_pcm_status responses. */ + virtio_notify(vdev, vq); } =20 /* @@ -883,15 +868,14 @@ static inline void empty_invalid_queue(VirtIODevice *= vdev, VirtQueue *vq) */ static void virtio_snd_handle_tx_xfer(VirtIODevice *vdev, VirtQueue *vq) { - VirtIOSound *s =3D VIRTIO_SND(vdev); - VirtIOSoundPCMStream *stream =3D NULL; + VirtIOSound *vsnd =3D VIRTIO_SND(vdev); VirtIOSoundPCMBuffer *buffer; VirtQueueElement *elem; size_t msg_sz, size; virtio_snd_pcm_xfer hdr; uint32_t stream_id; /* - * If any of the I/O messages are invalid, put them in stream->invalid= and + * If any of the I/O messages are invalid, put them in vsnd->invalid a= nd * return them after the for loop. */ bool must_empty_invalid_queue =3D false; @@ -901,7 +885,7 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *vde= v, VirtQueue *vq) } trace_virtio_snd_handle_tx_xfer(); =20 - for (;;) { + for (VirtIOSoundPCMStream *stream =3D NULL;; stream =3D NULL) { elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; @@ -913,16 +897,16 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) &hdr, sizeof(virtio_snd_pcm_xfer)); if (msg_sz !=3D sizeof(virtio_snd_pcm_xfer)) { - continue; + goto tx_err; } stream_id =3D le32_to_cpu(hdr.stream_id); =20 - if (stream_id >=3D s->snd_conf.streams - || s->pcm->streams[stream_id] =3D=3D NULL) { - continue; + if (stream_id >=3D vsnd->snd_conf.streams + || vsnd->pcm->streams[stream_id] =3D=3D NULL) { + goto tx_err; } =20 - stream =3D s->pcm->streams[stream_id]; + stream =3D vsnd->pcm->streams[stream_id]; if (stream->info.direction !=3D VIRTIO_SND_D_OUTPUT) { goto tx_err; } @@ -942,13 +926,11 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) continue; =20 tx_err: - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - must_empty_invalid_queue =3D true; - buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer)); - buffer->elem =3D elem; - buffer->vq =3D vq; - QSIMPLEQ_INSERT_TAIL(&stream->invalid, buffer, entry); - } + must_empty_invalid_queue =3D true; + buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer)); + buffer->elem =3D elem; + buffer->vq =3D vq; + QSIMPLEQ_INSERT_TAIL(&vsnd->invalid, buffer, entry); } =20 if (must_empty_invalid_queue) { @@ -965,15 +947,14 @@ tx_err: */ static void virtio_snd_handle_rx_xfer(VirtIODevice *vdev, VirtQueue *vq) { - VirtIOSound *s =3D VIRTIO_SND(vdev); - VirtIOSoundPCMStream *stream =3D NULL; + VirtIOSound *vsnd =3D VIRTIO_SND(vdev); VirtIOSoundPCMBuffer *buffer; VirtQueueElement *elem; size_t msg_sz, size; virtio_snd_pcm_xfer hdr; uint32_t stream_id; /* - * if any of the I/O messages are invalid, put them in stream->invalid= and + * if any of the I/O messages are invalid, put them in vsnd->invalid a= nd * return them after the for loop. */ bool must_empty_invalid_queue =3D false; @@ -983,7 +964,7 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *vde= v, VirtQueue *vq) } trace_virtio_snd_handle_rx_xfer(); =20 - for (;;) { + for (VirtIOSoundPCMStream *stream =3D NULL;; stream =3D NULL) { elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); if (!elem) { break; @@ -995,16 +976,16 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *v= dev, VirtQueue *vq) &hdr, sizeof(virtio_snd_pcm_xfer)); if (msg_sz !=3D sizeof(virtio_snd_pcm_xfer)) { - continue; + goto rx_err; } stream_id =3D le32_to_cpu(hdr.stream_id); =20 - if (stream_id >=3D s->snd_conf.streams - || !s->pcm->streams[stream_id]) { - continue; + if (stream_id >=3D vsnd->snd_conf.streams + || !vsnd->pcm->streams[stream_id]) { + goto rx_err; } =20 - stream =3D s->pcm->streams[stream_id]; + stream =3D vsnd->pcm->streams[stream_id]; if (stream =3D=3D NULL || stream->info.direction !=3D VIRTIO_SND_D= _INPUT) { goto rx_err; } @@ -1021,13 +1002,11 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice = *vdev, VirtQueue *vq) continue; =20 rx_err: - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - must_empty_invalid_queue =3D true; - buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer)); - buffer->elem =3D elem; - buffer->vq =3D vq; - QSIMPLEQ_INSERT_TAIL(&stream->invalid, buffer, entry); - } + must_empty_invalid_queue =3D true; + buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer)); + buffer->elem =3D elem; + buffer->vq =3D vq; + QSIMPLEQ_INSERT_TAIL(&vsnd->invalid, buffer, entry); } =20 if (must_empty_invalid_queue) { @@ -1127,6 +1106,7 @@ static void virtio_snd_realize(DeviceState *dev, Erro= r **errp) virtio_add_queue(vdev, 64, virtio_snd_handle_rx_xfer); qemu_mutex_init(&vsnd->cmdq_mutex); QTAILQ_INIT(&vsnd->cmdq); + QSIMPLEQ_INIT(&vsnd->invalid); =20 for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { status =3D virtio_snd_set_pcm_params(vsnd, i, &default_params); @@ -1376,13 +1356,20 @@ static void virtio_snd_unrealize(DeviceState *dev) =20 static void virtio_snd_reset(VirtIODevice *vdev) { - VirtIOSound *s =3D VIRTIO_SND(vdev); + VirtIOSound *vsnd =3D VIRTIO_SND(vdev); virtio_snd_ctrl_command *cmd; =20 - WITH_QEMU_LOCK_GUARD(&s->cmdq_mutex) { - while (!QTAILQ_EMPTY(&s->cmdq)) { - cmd =3D QTAILQ_FIRST(&s->cmdq); - QTAILQ_REMOVE(&s->cmdq, cmd, next); + /* + * Sanity check that the invalid buffer message queue is emptied at th= e end + * of every virtio_snd_handle_tx_xfer/virtio_snd_handle_rx_xfer call, = and + * must be empty otherwise. + */ + g_assert(QSIMPLEQ_EMPTY(&vsnd->invalid)); + + WITH_QEMU_LOCK_GUARD(&vsnd->cmdq_mutex) { + while (!QTAILQ_EMPTY(&vsnd->cmdq)) { + cmd =3D QTAILQ_FIRST(&vsnd->cmdq); + QTAILQ_REMOVE(&vsnd->cmdq, cmd, next); virtio_snd_ctrl_cmd_free(cmd); } } --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712648028; cv=none; d=zohomail.com; s=zohoarc; b=B50j/0JczD6c1DZES48GCEqfXJbieFlE0MgU9wZYPs4F4TB8zNuhwjwWLKi1u/+yKZcPus+nWdQutAeTDPLK95af81QENwqISx3pe45f9wZMz9agTKL/iwUcwCS7OMwQpJ2TsIXei4waZwKouu0ye1+YvQCISg32vBms0wXm98A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712648028; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SAP4+njt1pIwAfQTze1NdkgjAQFF4DuHgSbUxqb26Ps=; b=K066r+uqUohsCXjxwHBqtnVMvn6E6xpQaSUjscxY2K7+HMx6jQ38BhHHndheX2ZZsnbzdgQCeCtRasdpHe0hvbUT5C6ePn7hCVVEtvbIy6hOlbJEi04M3CFGvanzqShZs0gk6IFnpDWIz9ueBywozylleXL+Yv9FGrSKpYwDCvY= 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 171264802799875.14885799683009; Tue, 9 Apr 2024 00:33:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5y6-0006tw-FD; Tue, 09 Apr 2024 03:32:34 -0400 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 1ru5y4-0006rO-Tf for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru5y3-0001dG-7w for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:32 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-NIN-NNbXPZKoaSfZ9U_d6Q-1; Tue, 09 Apr 2024 03:32:29 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a4e9ac44d37so322820566b.0 for ; Tue, 09 Apr 2024 00:32:28 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id dr19-20020a170907721300b00a4a33cfe593sm5318274ejc.39.2024.04.09.00.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647950; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SAP4+njt1pIwAfQTze1NdkgjAQFF4DuHgSbUxqb26Ps=; b=GuwXt5lXXgyOXNsiTSF1ocpNH38oA9jbm7z901ZtQA0li47avqH2B/wwF+0UeAfZ6Zqbd1 cPccVyho5a7PXhRfbJj/Jkg3b59Jjl0XBPS5fqHfuIu0LXYsLbqZnilFK+1/w2Ply9D5ii XJUA5catIlld2cnJ1mX68VsaIer3kbU= X-MC-Unique: NIN-NNbXPZKoaSfZ9U_d6Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647947; x=1713252747; h=in-reply-to:content-transfer-encoding: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=SAP4+njt1pIwAfQTze1NdkgjAQFF4DuHgSbUxqb26Ps=; b=j6cYMv94r2HXkD0uIR0CPL8hF8kvScoZpJFBHTUPYN9U5SnZGpXPc1dvmlG0pVq25N B7wqdafkFyUbaiKsYpNupm+O63UATM8I/A+6m3U2AnawqV0DIT7fr6i8tdN4UiZRfIQ8 b9/ssV2gzxh3kPHS8XVrxDVvu2PBqI9GVRCaR0h1SXJ/yBV/3OMdz3C631iT81jJg71A xiclmlx3AojIbiBBimgS+Q9G75b8snFh8W8SD6NMUj/VYJq00IZ/fIdQT+2LqBaVwAro 6XshC3uTK3CzJ//7L6Z1Ix6x0mrJytUfbEX9iyunkoFM/1/XYKUssEZONe0wZbP3OryS PUVg== X-Gm-Message-State: AOJu0YwKZoGFaHzwZrQpa83AjuTovb6rxxo7FEDiKKw9QcqgpHeP1RKU zlgLdrIpHfhFyYG3Eq2VrXl2W7197AlxVxxWo9kXtltQj90eEOEwkO/KUjPUBeDu1QQsw4tlDYe Ld32y4cZgumHdHuawD02r/25d5R1r4EgbXByJn79B7V1sMitbi3eIP+zEQ/1NwIoQZhWsJkAOgp B5WtrRuLflUO/TifisiXD5PezY7ekfXA== X-Received: by 2002:a17:907:5c1:b0:a51:ce66:cf12 with SMTP id wg1-20020a17090705c100b00a51ce66cf12mr4481929ejb.35.1712647947367; Tue, 09 Apr 2024 00:32:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEX+/QWPXxLBP0Thn2cYzJlES9HupbUQf0gFgQztgqNYiXItXGpewIPScieYwI5v6meEx/0JA== X-Received: by 2002:a17:907:5c1:b0:a51:ce66:cf12 with SMTP id wg1-20020a17090705c100b00a51ce66cf12mr4481907ejb.35.1712647946825; Tue, 09 Apr 2024 00:32:26 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:24 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Wafer , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PULL 4/7] hw/virtio: Fix packed virtqueue flush used_idx Message-ID: <2d9a31b3c27311eca1682cb2c076d7a300441960.1712647890.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: 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.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712648029421100001 From: Wafer In the event of writing many chains of descriptors, the device must write just the id of the last buffer in the descriptor chain, skip forward the number of descriptors in the chain, and then repeat the operations for the rest of chains. Current QEMU code writes all the buffer ids consecutively, and then skips all the buffers altogether. This is a bug, and can be reproduced with a VirtIONet device with _F_MRG_RXBUB and without _F_INDIRECT_DESC: If a virtio-net device has the VIRTIO_NET_F_MRG_RXBUF feature but not the VIRTIO_RING_F_INDIRECT_DESC feature, 'VirtIONetQueue->rx_vq' will use the merge feature to store data in multiple 'elems'. The 'num_buffers' in the virtio header indicates how many elements are merg= ed. If the value of 'num_buffers' is greater than 1, all the merged elements will be filled into the descriptor ring. The 'idx' of the elements should be the value of 'vq->used_idx' plus 'ndesc= s'. Fixes: 86044b24e8 ("virtio: basic packed virtqueue support") Acked-by: Eugenio P=C3=A9rez Signed-off-by: Wafer Message-Id: <20240407015451.5228-2-wafer@jaguarmicro.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d229755eae..c5bedca848 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -957,12 +957,20 @@ static void virtqueue_packed_flush(VirtQueue *vq, uns= igned int count) return; } =20 + /* + * For indirect element's 'ndescs' is 1. + * For all other elemment's 'ndescs' is the + * number of descriptors chained by NEXT (as set in virtqueue_packed_p= op). + * So When the 'elem' be filled into the descriptor ring, + * The 'idx' of this 'elem' shall be + * the value of 'vq->used_idx' plus the 'ndescs'. + */ + ndescs +=3D vq->used_elems[0].ndescs; for (i =3D 1; i < count; i++) { - virtqueue_packed_fill_desc(vq, &vq->used_elems[i], i, false); + virtqueue_packed_fill_desc(vq, &vq->used_elems[i], ndescs, false); ndescs +=3D vq->used_elems[i].ndescs; } virtqueue_packed_fill_desc(vq, &vq->used_elems[0], 0, true); - ndescs +=3D vq->used_elems[0].ndescs; =20 vq->inuse -=3D ndescs; vq->used_idx +=3D ndescs; --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712647969; cv=none; d=zohomail.com; s=zohoarc; b=PeJemfGxafzWhN8ElwZf0yFYtFOTkSyQglb7K1fCHUo1G3hmrp3Q00h7GrK0nE1kg34wBXDbhlUm+48o6V53jweY3B4dtK/xPUmH6ELVj99kvH/mYlzp1syKRYfi3XxMLrsCgpZrcxmYS9aZNYYi1WN/invmhDeWPDrwEQcoJkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712647969; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vH5L5pFLaSI06lO9xjFE/z5WyjmKBK04Tet3f92vU6A=; b=GlNHkqzX0F3gG1Bgotl5YFy9uHimEZFoyqxAapbSYAinHTVpYKX0LOJatv1TA2P1WmtmW5+P6zg6S07ZJqDc87ZZfLBlN9jCChOD9WIsVIBDfSRxTiGYjGc5mKYB4GTa/tBtAochMlV8SFIdBPjLPGMXhoM00+oRq0w7AaSpk8E= 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 1712647969190662.3816756583813; Tue, 9 Apr 2024 00:32:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5y9-00070W-W7; Tue, 09 Apr 2024 03:32:38 -0400 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 1ru5y8-0006uJ-08 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:36 -0400 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 1ru5y6-0001dj-I5 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:35 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-H2D3u9lrPviAi5CWT4jYSQ-1; Tue, 09 Apr 2024 03:32:32 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5684bf1440dso2015061a12.3 for ; Tue, 09 Apr 2024 00:32:32 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id q18-20020aa7d452000000b0056e247de8e3sm4928413edr.1.2024.04.09.00.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647953; 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=vH5L5pFLaSI06lO9xjFE/z5WyjmKBK04Tet3f92vU6A=; b=QPpZ4paws40fXcfih4ZXaSSrhCExmXzVEpj5We2PR39RfN7IyAJvyLUXtlyMC0xeP9yJ9U OsJ60KknqM2HsnM/b+DF25qXq/z3K7efgWtTvn5fDBbRVF6E3FRKk/xnrfuBDA+zZVb5U5 lbp7TEJU8yvv30gHl5ROhNI23Y1Moww= X-MC-Unique: H2D3u9lrPviAi5CWT4jYSQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647950; x=1713252750; 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=vH5L5pFLaSI06lO9xjFE/z5WyjmKBK04Tet3f92vU6A=; b=cZIsy39Ooe8BEpQCESqVjrRkQHoDlNXiYWctjzNuSL3rOUXFI3ADdq1O4lncQS+EgW YViLAPUTHjfcYLsA/dZldPm1LHTkGGm2tOfOl0wMO5DKzjnmRlaxkpL4sBp1syKvmJou uUjo4qgQm0/a5E62Z6v65z2/Jqc5b2s5LRGYtsPgj+JJHjobtG4obCzqXOlzXcm+I/cZ X0Y1gUko6kpR8EcUgTEWzByZW9n3FiUa1CxwrbZondVU4Y5sQXPJJzIK3725cdEbBW05 eU3jUS1AAAfAbM2aBSmdwpGzKEB1+ZBFjQbCtWs4ZySMUZAYc6gz1zcl+VkhV70PJtWq oziw== X-Gm-Message-State: AOJu0Yx0FTi1xNWbwQQ0/rlNr5LX0jAc7iSPQ+ZARPl4/MfTlCGSAY44 sChcIGx7EX1j/hrLbh7jE1Lv4mVScOdjlFXDtI4moJuNiqTovaeQhAOXK/WN8mIEZQZe+FY9RU1 D8cmAC7WiGgwZ9/eTnM54LuEyUFOdr8UIs2cPa/8U6g/6wsNLQB1RKbPAa4jDF02ctYg8/GP2Rf XdT3fejdhavQzG9YY+QFToXG3ABrd0RA== X-Received: by 2002:a50:9b56:0:b0:56b:fd17:3522 with SMTP id a22-20020a509b56000000b0056bfd173522mr7971078edj.14.1712647950465; Tue, 09 Apr 2024 00:32:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfmI15z1iU+N/YJLVDAItEnxPyp/nYlAdrcAtTJS3jYozitVZVbWUZBXkcu36NpRQzo9+b4w== X-Received: by 2002:a50:9b56:0:b0:56b:fd17:3522 with SMTP id a22-20020a509b56000000b0056bfd173522mr7971038edj.14.1712647949828; Tue, 09 Apr 2024 00:32:29 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:27 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , lyx634449800 , Jason Wang , Eugenio =?utf-8?B?UMOpcmV6?= , Kevin Wolf , Richard Henderson Subject: [PULL 5/7] vdpa-dev: Fix the issue of device status not updating when configuration interruption is triggered Message-ID: <6ae72f609a21cfc56bf655cd4bcded5d07691ce7.1712647890.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712647971224100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: lyx634449800 The set_config callback function vhost_vdpa_device_get_config in vdpa-dev does not fetch the current device status from the hardware device, causing the guest os to not receive the latest device status information. The hardware updates the config status of the vdpa device and then notifies the os. The guest os receives an interrupt notification, triggering a get_config access in the kernel, which then enters qemu internally. Ultimately, the vhost_vdpa_device_get_config function of vdpa-dev is called One scenario encountered is when the device needs to bring down the vdpa net device. After modifying the status field of virtio_net_config in the hardware, it sends an interrupt notification. However, the guest os always receives the STATUS field as VIRTIO_NET_S_LINK_UP. Signed-off-by: Yuxue Liu Acked-by: Jason Wang Message-Id: <20240408020003.1979-1-yuxue.liu@jaguarmicro.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vdpa-dev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 13e87f06f6..64b96b226c 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -195,7 +195,14 @@ static void vhost_vdpa_device_get_config(VirtIODevice *vdev, uint8_t *config) { VhostVdpaDevice *s =3D VHOST_VDPA_DEVICE(vdev); + int ret; =20 + ret =3D vhost_dev_get_config(&s->dev, s->config, s->config_size, + NULL); + if (ret < 0) { + error_report("get device config space failed"); + return; + } memcpy(config, s->config, s->config_size); } =20 --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712648331; cv=none; d=zohomail.com; s=zohoarc; b=adrXk38CUNtGR/splJssb4jdmd9xag/cCGr6nU4gvTKkFRMT1w9t/Nc4dTWEKAqtzDTOfOfan9u6va7ZlWMQq/9dmK2ec+JMEv/bFhcoWkUxpEzui3AMN4yR/5baO77C8j3XVaZcfGF/gr2gHU9D8nSVPxLRBQdSMzcwPIZlwPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712648331; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y+PBU8FJD1KavZSixahSE19h37gczE5W26EChIaJ/bY=; b=H7kgl2VrG1On2fa4YOFX3ero/rJfq8Rb9IliomvZzn2j5gz1/Lk2H6sZG9jq+MOT1G0J+JafX7qL/7jpJ/yemjwZUOsE8H931a4e9r/W5t+fYoKV8Fwfrl7u4CP7TodUVIEtoH5DAQNim6r1gRftgCGJpQvAI+EKxz4nHsgMqNk= 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 1712648331049105.05458337430275; Tue, 9 Apr 2024 00:38:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru63t-0003x1-Ae; Tue, 09 Apr 2024 03:38:33 -0400 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 1ru63r-0003wt-Lg for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:38:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru63p-0002lX-Rm for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:38:31 -0400 Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-t1n1LgohMe-RJMPW63uR2A-1; Tue, 09 Apr 2024 03:38:27 -0400 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d85b4ca694so41433381fa.1 for ; Tue, 09 Apr 2024 00:38:26 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id xb8-20020a170907070800b00a4e07760215sm5328761ejb.69.2024.04.09.00.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712648309; 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=Y+PBU8FJD1KavZSixahSE19h37gczE5W26EChIaJ/bY=; b=GONpPoDufyyy5/f5fJv7AqRdcyVRHB1xwL7WrSQyT4xlFG3mh3fvdCD+qF9qfHcfxKeCy5 +iAYjNaYAPR5VbZJMh1dc/+nutfYjdDIwrvYpannOYnls+QR5R6ExdyYMRo4MKEhRC17Wy wbGHh3Y/DpxE+jT3Phx24JBoJKjORMw= X-MC-Unique: t1n1LgohMe-RJMPW63uR2A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712648305; x=1713253105; 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=Y+PBU8FJD1KavZSixahSE19h37gczE5W26EChIaJ/bY=; b=oobGv/IkPS/jtaA6xKnIR50XiWrZ24cJ9Dh1gaEuMpuiukt5vera3abnCc7hmr+gnL Bcyyw04O+Zg694ihL2EsCJzqc+21blBWNtrqG8ydNWMnPwcrRXtAtxRstmBvpIiLwQbl MocfbI5p78rOTN3ee78akYAGX3uDR7dterFKa/HQ3WjeFwBFaCBMfmUMs9am+cxLFWD6 hmkxAr6x0usxRBNrMVLqGhFskMyhUnYHwsY31zLBR+ZFHIVgT4wnKyLIhF++C/1xXFV4 iHeXN3llK6V/Mhq2E1ig3853kwgBbDRi3dhjgBaZoiBWbm+IUGRkZQ8PZY4N/ymtueXd Cvbw== X-Gm-Message-State: AOJu0Yzs6ofBYF4JrPHMXHr9HuBIYUAC4P4jlQG56D5LWbsp/CSbrk7D L5+SjOJxLrladZxN6q4m+JpHYPTowqGqUnJXEJUxGxvyYWDX8x4Szw1CSQiJYAHt63lYPnFmh0p zxISoALPOsORspFFGxtB4U+0MlohpHgGRuwlY6xSk7ToIgUXqwQCHKST++3kRBUf6l3PvXykx9Y kQYuYIQ0IL1P4Mezh7LeaaVtK6PHRHAg== X-Received: by 2002:a2e:a306:0:b0:2d8:52b2:2002 with SMTP id l6-20020a2ea306000000b002d852b22002mr8073647lje.47.1712648304680; Tue, 09 Apr 2024 00:38:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXXDfbE4JnVQpsEyVRsjA0X7rBrJmVg7ldtlU+/qygahVV9t0aHOX2zG+KcXx3AHcsGXayhA== X-Received: by 2002:a17:906:235b:b0:a46:6fe4:af27 with SMTP id m27-20020a170906235b00b00a466fe4af27mr7504136eja.24.1712647952949; Tue, 09 Apr 2024 00:32:32 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:30 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Vladimir Sementsov-Ogievskiy , Raphael Norwitz , Raphael Norwitz , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org Subject: [PULL 6/7] vhost-user-blk: simplify and fix vhost_user_blk_handle_config_change Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1712648332681100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Let's not care about what was changed and update the whole config, reasons: 1. config->geometry should be updated together with capacity, so we fix a bug. 2. Vhost-user protocol doesn't say anything about config change limitation. Silent ignore of changes doesn't seem to be correct. 3. vhost-user-vsock reads the whole config 4. on realize we don't do any checks on retrieved config, so no reason to care here Comment "valid for resize only" exists since introduction the whole hw/block/vhost-user-blk.c in commit 00343e4b54ba0685e9ebe928ec5713b0cf7f1d1c "vhost-user-blk: introduce a new vhost-user-blk host device", seems it was just an extra limitation. Also, let's notify guest unconditionally: 1. So does vhost-user-vsock 2. We are going to reuse the functionality in new cases when we do want to notify the guest unconditionally. So, no reason to create extra branches in the logic. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Message-Id: <20240329183758.3360733-2-vsementsov@yandex-team.ru> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/block/vhost-user-blk.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 6a856ad51a..9e6bbc6950 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -91,7 +91,6 @@ static void vhost_user_blk_set_config(VirtIODevice *vdev,= const uint8_t *config) static int vhost_user_blk_handle_config_change(struct vhost_dev *dev) { int ret; - struct virtio_blk_config blkcfg; VirtIODevice *vdev =3D dev->vdev; VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); Error *local_err =3D NULL; @@ -100,19 +99,15 @@ static int vhost_user_blk_handle_config_change(struct = vhost_dev *dev) return 0; } =20 - ret =3D vhost_dev_get_config(dev, (uint8_t *)&blkcfg, + ret =3D vhost_dev_get_config(dev, (uint8_t *)&s->blkcfg, vdev->config_len, &local_err); if (ret < 0) { error_report_err(local_err); return ret; } =20 - /* valid for resize only */ - if (blkcfg.capacity !=3D s->blkcfg.capacity) { - s->blkcfg.capacity =3D blkcfg.capacity; - memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); - virtio_notify_config(dev->vdev); - } + memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); + virtio_notify_config(dev->vdev); =20 return 0; } --=20 MST From nobody Sat May 18 14:25:28 2024 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=1712647989; cv=none; d=zohomail.com; s=zohoarc; b=AiN3MwPCC3nneVoas0BiBj6gzXAHqxks/7hYDOEVV7kgtJFdoQVyg18DJwDEulFfVlJAKT+m6m1SivGlRlxDb3yiov2V3QTZ/KRo8VTxns+roSUc9awWq873h915GfTifnLVX68L8V8CTQkiQOaGBFbNry0oCgqYws8lS7TxW/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712647989; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SjJapfA0EMdaBP1MiLjrwUGdMH/J/+78hWE+vX3muqw=; b=nc7vFwLR2D0AQ0IUhVecyH/IXjvHmtbm9B6jVBZX9mVvxD+XRFLvrbtXoRa/1eRj6Jw/P9AkUTYGydSSmg3GeujYKfkJE5op3YqA24ZyuhmuBs1qDhdi6nc0sunkjA7aAo7x26UnhE+Svfot4l6mMzPNqXDp/7Sef3c/Gul86tE= 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 171264798952868.16435998738405; Tue, 9 Apr 2024 00:33:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru5yN-0007Sx-UR; Tue, 09 Apr 2024 03:32:53 -0400 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 1ru5yH-0007Mo-29 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru5yE-0001eL-1F for qemu-devel@nongnu.org; Tue, 09 Apr 2024 03:32:44 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-e9Py1mDsOj2mS7wckG8-Rg-1; Tue, 09 Apr 2024 03:32:38 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a519e10623bso268642566b.0 for ; Tue, 09 Apr 2024 00:32:38 -0700 (PDT) Received: from redhat.com ([2.52.134.26]) by smtp.gmail.com with ESMTPSA id ld11-20020a170906f94b00b00a51d8a3a632sm1966027ejb.168.2024.04.09.00.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712647960; 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=SjJapfA0EMdaBP1MiLjrwUGdMH/J/+78hWE+vX3muqw=; b=VLs76ezz02nsPGnbEaXqTUKe7RMr68hFrmhx3h3rF4bzOZLU/TtKFID3OGjtZez0Z8WNl1 oWSw3cZKyjxGr5PDf1qGWOj8Irc4OENXXTQOcrD+1RYgMtJixqhOMNpL0EvScfUZe6RoL7 Qb3WqrhLWAcva3eEVELQYHvezZaViG4= X-MC-Unique: e9Py1mDsOj2mS7wckG8-Rg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712647957; x=1713252757; 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=SjJapfA0EMdaBP1MiLjrwUGdMH/J/+78hWE+vX3muqw=; b=Y3y7A1LbfVEBPCW6AaJAIKScRZX7Xw2+htrqllWCJEKQR45oEDZ1IJg6f77qF4svec tPHF369PVvs2x+LlDBb3efAvkbDnU9cmQXgyuRBtvaEl7xZ61YQKFJHJ4hOhVlB+rU4m Isekp6W+noEyLlhpinSB44JqqIc8iJRvptlPq76c92TGvAO8GJNzQNd/B7QF2LA1lRYf iK9TCBSjraeUKxT/W3chCPXGtbNw+lW7cNF+qQbMSyzEAhJ1NXLxaXhXCN12C+saiIYa fgVFW5835kCSt5AjkON2m3pg+e8ynpTMRvUEnIHa70TjNuhO9OVSzaAjWiL7cnbwW9oF VtgQ== X-Gm-Message-State: AOJu0YzqHvc36JNXF8vF5AvqBNTuC2R7V6hl//TGMbPeyCZvEw0Ar2ED VyAzfLujSV/JLPlrrXZ5RZEk8cJZCQdNmlUaRZmbVZIW4rw1gxbmPoPJMrY8dWSfSPV6EUYzfoS 3PaUpP+TPd70eB1+0PHiOcI4Nwm4G4CYW+VtCiSX5j1La0Nzf5Z4XVyL4oDLWB1Zc5P3nn/Qzve vjVJCxwFJdGT4bCCAIX0NkcXzMdaRz6w== X-Received: by 2002:a17:906:bc48:b0:a4e:8c9d:a724 with SMTP id s8-20020a170906bc4800b00a4e8c9da724mr7418231ejv.69.1712647956738; Tue, 09 Apr 2024 00:32:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0WH62Gjd0zz7nrdwhT+Up4RR+3xeh8r8Au3kZ5XRTAh6A3Yv/zE9zH2qJ73uYgKAr2sCq2A== X-Received: by 2002:a17:906:bc48:b0:a4e:8c9d:a724 with SMTP id s8-20020a170906bc4800b00a4e8c9da724mr7418209ejv.69.1712647956282; Tue, 09 Apr 2024 00:32:36 -0700 (PDT) Date: Tue, 9 Apr 2024 03:32:33 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Paolo Bonzini , Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Eduardo Habkost Subject: [PULL 7/7] qdev-monitor: fix error message in find_device_state() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.494, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1712647991210100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This "hotpluggable" here is misleading. Actually we check is object a device or not. Let's drop the word. Suggested-by: Markus Armbruster Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster Message-Id: <20240329183758.3360733-3-vsementsov@yandex-team.ru> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- system/qdev-monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index c1243891c3..840177d19f 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -891,7 +891,7 @@ static DeviceState *find_device_state(const char *id, E= rror **errp) =20 dev =3D (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE); if (!dev) { - error_setg(errp, "%s is not a hotpluggable device", id); + error_setg(errp, "%s is not a device", id); return NULL; } =20 --=20 MST