From nobody Sat Sep 26 20:51:00 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1788264301; cv=none; d=zohomail.com; s=zohoarc; b=VUg7BmHz0gP7zpC6pFJkdcFhDnXNAehouAQTh7mLMSD8W/avFqdB3EJn4zgf8PfPmVhfxdApVmB3z9Xu2ru/K83s55l5anma0CpZCBIl4k0S71zLcLigmcHcRJlKd7eM7ZjAwYT8KDIy5c06CrWx0jpbxoHtaOcs0r+JkLB4cGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788264301; 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=nl5WoyTpJvABJd28BYMkIJTV/gurT6ais6kK1GnNVYQ=; b=OJfKZaNqbLvT2JjBsorcbW9WUmbTCs5ogi7Qc3e/LfDk0db3/oxuau07c8e2QZ2fp6WAOg2km5rEgYfLCM8dCgAnL6c9igDZ7DLk00EZeY6q4MyHk2zmFLhDcs1GQYfyUJQ6N7vHH2lDRccJs8iNH/jbOAvLTYQCc9kuyqTGkQQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788264301685646.6983534033408; Tue, 1 Sep 2026 05:05:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x1NDv-0001wB-Jb; Tue, 01 Sep 2026 08:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x1NDu-0001w2-CA for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:18 -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 1x1NDt-00071t-1V for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:18 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-482-oYf4DGMfPnG1FYCkSBcVqg-1; Tue, 01 Sept 2026 08:04:13 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1FFE2195423B; Tue, 1 Sep 2026 12:04:12 +0000 (UTC) Received: from aesteve-thinkpadp1gen8.rmtes.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44E0E1955F01; Tue, 1 Sep 2026 12:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788264255; 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=nl5WoyTpJvABJd28BYMkIJTV/gurT6ais6kK1GnNVYQ=; b=P3v5g6X8hQSu6Rf6Bo2Ehnz1VczS3CWkck1/M0QUdlLuspHaqlhgq0QjsITgQcJBD4Pxim pP4qO2HqPksQG3d+oUMV7EqdqBNikYnEHWN0A2bk3W0u9358BI6NTVoKmIeA5rwjMpNV03 AlkgVIUiWVrWW6633q5SlEy7Lxe/QM4= X-MC-Unique: oYf4DGMfPnG1FYCkSBcVqg-1 X-Mimecast-MFC-AGG-ID: oYf4DGMfPnG1FYCkSBcVqg_1788264252 From: Albert Esteve Date: Tue, 01 Sep 2026 14:04:04 +0200 Subject: [PATCH v2 1/3] linux-headers: add VIRTIO_ID_MEDIA MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-virtio-media-v2-1-bd3cc9347ab9@redhat.com> References: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> In-Reply-To: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Stefano Garzarella , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Albert Esteve , manos.pitsidianakis@linaro.org, alex.bennee@linaro.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1788264246; l=767; i=aesteve@redhat.com; s=20260827; h=from:subject:message-id; bh=13a+ZK858Se7JrWgikDune+f94SBxk/pnOnvvFCPAeA=; b=CPjS8VzUHrmhf0vvCmmGWmW5IoqCNUtGlchr5o8+s3lJ498nCiwJfyEHQGKWxyEBJxqM57YDZ FtfJ+esIPkmAXLVMmKow9Gfq6/DByOpmguEgncVEzeXocydd8/RGoFC X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=zI2RBeZgocwYm3AkJW4CtjoJnKoDZrfBl1xe5Ed6h+U= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1788264304078158500 The ID was added in Linux commit 2187be212179 ("virtio: Add ID for virtio media") and is included in v7.3-rc1. Signed-off-by: Albert Esteve --- include/standard-headers/linux/virtio_ids.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6c12db16fa..f9056af0c6 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -69,6 +69,7 @@ #define VIRTIO_ID_BT 40 /* virtio bluetooth */ #define VIRTIO_ID_GPIO 41 /* virtio gpio */ #define VIRTIO_ID_SPI 45 /* virtio spi */ +#define VIRTIO_ID_MEDIA 48 /* virtio media */ =20 /* * Virtio Transitional IDs --=20 2.55.0 From nobody Sat Sep 26 20:51:00 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1788264301; cv=none; d=zohomail.com; s=zohoarc; b=M893XuEpYUMV4wFctL0XZTZjQ3L/N9i6Ta2XSO3P3qO5fNjf3eb3ayHD/XGhyg2hH7LvOMJJNvvvBlFIthtTNjU8uSw+olz+RVDx3gmJv2C35iAMAtOeGEwiKb15QQQAP/4qE/dwqcsaAxXmQVlVkHcxi9sukCWV0bdJDa7+V4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788264301; 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=h10pP2QLkEc4eP3iz0FxcoyxhmDBme6DJBJ+u9u16Fg=; b=Oxc0xhROzrstEzmo4h9MdjYohbNurVTRuUR5HQV+i5XDw41ZosKcoNScm3jEwMeaoT2r+i11Rg/y/B473waps/eY7wvuo1zzvfAAs5aNLqKc5qZP15xIYD/9eeOglztzkAP6Ud4O41uOPz5a9zGQbZPawd//QHJTX8RxMtSr8Wc= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788264301039702.1709227054223; Tue, 1 Sep 2026 05:05:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x1NDy-0001wy-6n; Tue, 01 Sep 2026 08:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x1NDw-0001wj-IB for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:20 -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 1x1NDt-00072x-Qh for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:20 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-x8rm_phoPziTEH7ebQi7Hg-1; Tue, 01 Sept 2026 08:04:15 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCF6819540DD; Tue, 1 Sep 2026 12:04:14 +0000 (UTC) Received: from aesteve-thinkpadp1gen8.rmtes.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 74ACB1955F01; Tue, 1 Sep 2026 12:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788264256; 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=h10pP2QLkEc4eP3iz0FxcoyxhmDBme6DJBJ+u9u16Fg=; b=FJKkEP5X2NY0bWpjM4FwrLHbOWgpnAXti5HttEOGn4OJpkvmQNd0kzMJgjqMJ0E04S1vqh wVkjdmL0Te2riXlCmFEvp+LJVrhhm/jWwmfeFg79V6QCZRQX2YytjGwL3JnvsATjTa9fdz inuiO3Vd6hrmN4H+x4yvnhjHUkVf/1g= X-MC-Unique: x8rm_phoPziTEH7ebQi7Hg-1 X-Mimecast-MFC-AGG-ID: x8rm_phoPziTEH7ebQi7Hg_1788264254 From: Albert Esteve Date: Tue, 01 Sep 2026 14:04:05 +0200 Subject: [PATCH v2 2/3] hw/display: add vhost-user-media device MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-virtio-media-v2-2-bd3cc9347ab9@redhat.com> References: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> In-Reply-To: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Stefano Garzarella , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Albert Esteve , manos.pitsidianakis@linaro.org, alex.bennee@linaro.org, Dorinda Bassey X-Developer-Signature: v=1; a=ed25519-sha256; t=1788264246; l=18130; i=aesteve@redhat.com; s=20260827; h=from:subject:message-id; bh=j4ZO9uOMCxqRwe/7qrRh6XRFYDJqbfN8TdEfziyamxo=; b=Ez8QAeDs7SLpvp09TjiORbgN9iu8u/n4ZyREzlRlM79u2ftUfoJ28W6nR0ynBVHMyUAre8gRh bwpD4CgmKX9Bhpasjgk5T672A4qL88+GVm5fbyBhBSWbksBuNlUFz40 X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=zI2RBeZgocwYm3AkJW4CtjoJnKoDZrfBl1xe5Ed6h+U= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1788264304230158500 Add the QEMU side of the vhost-user-media device, which connects to a virtio-media vhost-user backend daemon implementing the V4L2 API over the virtio-media protocol. The virtio-media device is specified in the VirtIO specification v1.4, section 5.22: https://docs.oasis-open.org/virtio/virtio/v1.4/cs01/virtio-v1.4-cs01.ht= ml Tested with the rust-vmm vhost-device-media backend [1]: cargo run -- -s /path/to/media.sock -d /dev/video0 --backend v4l2-proxy Example invocation: qemu-system-x86_64 \ -chardev socket,path=3D/path/to/media.sock,id=3Dmedia \ -device vhost-user-media-pci,chardev=3Dmedia,id=3Dmedia [1] https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-media Tested-by: Dorinda Bassey Signed-off-by: Albert Esteve --- MAINTAINERS | 6 + hw/display/Kconfig | 5 + hw/display/meson.build | 3 + hw/display/vhost-user-media-pci.c | 80 ++++++++ hw/display/vhost-user-media.c | 348 +++++++++++++++++++++++++++++++= ++++ hw/virtio/virtio.c | 3 +- include/hw/virtio/vhost-user-media.h | 46 +++++ 7 files changed, 490 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 4a49a40294..c96e066283 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2697,6 +2697,12 @@ S: Supported F: include/hw/virtio/vhost-user-rtc.h F: hw/virtio/vhost-user-rtc* =20 +vhost-user-media +M: Albert Esteve +S: Supported +F: hw/display/vhost-user-media* +F: include/hw/virtio/vhost-user-media.h + virtio-crypto M: Gonglei S: Supported diff --git a/hw/display/Kconfig b/hw/display/Kconfig index b3593fe981..060274b1e6 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -120,6 +120,11 @@ config VHOST_USER_VGA default y depends on VIRTIO_VGA && VHOST_USER_GPU =20 +config VHOST_USER_MEDIA + bool + default y + depends on VIRTIO && VHOST_USER + config DPCD bool select AUX diff --git a/hw/display/meson.build b/hw/display/meson.build index ffecedbf70..d8b4e121fe 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -37,6 +37,9 @@ system_ss.add(when: 'CONFIG_NEXTCUBE', if_true: files('ne= xt-fb.c')) system_ss.add(when: 'CONFIG_VGA', if_true: files('vga.c')) system_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-dmabuf.c')) system_ss.add(when: 'CONFIG_DM163', if_true: files('dm163.c')) +system_ss.add(when: 'CONFIG_VHOST_USER_MEDIA', if_true: files('vhost-user-= media.c')) +system_ss.add(when: ['CONFIG_VHOST_USER_MEDIA', 'CONFIG_VIRTIO_PCI'], + if_true: files('vhost-user-media-pci.c')) =20 stub_ss.add([files('acpi-vga-stub.c'), pixman]) if (config_all_devices.has_key('CONFIG_VGA_CIRRUS') or diff --git a/hw/display/vhost-user-media-pci.c b/hw/display/vhost-user-medi= a-pci.c new file mode 100644 index 0000000000..3e09fcfdd0 --- /dev/null +++ b/hw/display/vhost-user-media-pci.c @@ -0,0 +1,80 @@ +/* + * Vhost-user MEDIA virtio device PCI glue + * + * Copyright Red Hat, Inc. 2026 + * Authors: Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/core/qdev-properties.h" +#include "hw/virtio/vhost-user-media.h" +#include "hw/virtio/virtio-pci.h" + +#define TYPE_VHOST_USER_MEDIA_PCI "vhost-user-media-pci-base" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIAPCI, VHOST_USER_MEDIA_PCI) + +struct VHostUserMEDIAPCI { + VirtIOPCIProxy parent_obj; + VHostUserMEDIA vdev; +}; + +static const Property vumedia_pci_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), +}; + +static void vumedia_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(vpci_dev); + DeviceState *dev_state =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 1; + } + + if (!qdev_realize(dev_state, BUS(&vpci_dev->bus), errp)) { + return; + } +} + +static void vumedia_pci_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vumedia_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, vumedia_pci_properties); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_MULTIMEDIA_VIDEO; +} + +static void vumedia_pci_instance_init(Object *obj) +{ + VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_MEDIA); +} + +static const VirtioPCIDeviceTypeInfo vumedia_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_MEDIA_PCI, + .non_transitional_name =3D "vhost-user-media-pci", + .instance_size =3D sizeof(VHostUserMEDIAPCI), + .instance_init =3D vumedia_pci_instance_init, + .class_init =3D vumedia_pci_class_init, +}; + +static void vumedia_pci_register(void) +{ + virtio_pci_types_register(&vumedia_pci_info); +} + +type_init(vumedia_pci_register); diff --git a/hw/display/vhost-user-media.c b/hw/display/vhost-user-media.c new file mode 100644 index 0000000000..14edc7c668 --- /dev/null +++ b/hw/display/vhost-user-media.c @@ -0,0 +1,348 @@ +/* + * Vhost-user Media device + * + * Copyright Red Hat, Inc. 2026 + * + * This is the boilerplate for instantiating a vhost-user device + * implementing a virtio-media device. + * + * Authors: + * Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/core/qdev-properties-system.h" +#include "standard-headers/linux/virtio_ids.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-media.h" + +static const int feature_bits[] =3D { + VIRTIO_F_VERSION_1, + VIRTIO_F_NOTIFY_ON_EMPTY, + VIRTIO_RING_F_INDIRECT_DESC, + VIRTIO_RING_F_EVENT_IDX, + VIRTIO_F_RING_RESET, + VHOST_INVALID_FEATURE_BIT +}; + +static void +vu_media_get_config(VirtIODevice *vdev, uint8_t *config_data) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + Error *local_err =3D NULL; + int ret; + + memset(config_data, 0, sizeof(struct virtio_media_config)); + + ret =3D vhost_dev_get_config(&media->vhost_dev, + config_data, sizeof(struct virtio_media_con= fig), + &local_err); + if (ret) { + error_report_err(local_err); + return; + } +} + +static void vu_media_start(VirtIODevice *vdev) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&media->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, tr= ue); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + media->vhost_dev.acked_features =3D vdev->guest_features; + + media->vhost_dev.vq_index_end =3D media->vhost_dev.nvqs; + ret =3D vhost_dev_start(&media->vhost_dev, vdev, true); + if (ret < 0) { + error_report("Error starting vhost-user-media: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < media->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&media->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&media->vhost_dev, vdev); +} + +static void vu_media_stop(VirtIODevice *vdev) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&media->vhost_dev, vdev, true); + + ret =3D k->set_guest_notifiers(qbus->parent, media->vhost_dev.nvqs, fa= lse); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&media->vhost_dev, vdev); +} + +static int vu_media_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + bool should_start =3D virtio_device_should_start(vdev, status); + + if (vhost_dev_is_started(&media->vhost_dev) =3D=3D should_start) { + return 0; + } + + if (should_start) { + vu_media_start(vdev); + } else { + vu_media_stop(vdev); + } + return 0; +} + +static uint64_t vu_media_get_features(VirtIODevice *vdev, + uint64_t requested_features, + Error **errp) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + return vhost_get_features(&media->vhost_dev, feature_bits, + requested_features); +} + +static void vu_media_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vu_media_guest_notifier_mask(VirtIODevice *vdev, int idx, + bool mask) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return; + } + + vhost_virtqueue_mask(&media->vhost_dev, vdev, idx, mask); +} + +static bool vu_media_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (idx =3D=3D VIRTIO_CONFIG_IRQ_IDX) { + return false; + } + + return vhost_virtqueue_pending(&media->vhost_dev, idx); +} + +static int vu_media_handle_config_change(struct vhost_dev *dev) +{ + virtio_notify_config(dev->vdev); + return 0; +} + +static const VhostDevConfigOps media_ops =3D { + .vhost_dev_config_notifier =3D vu_media_handle_config_change, +}; + +static int vu_media_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (media->connected) { + return 0; + } + media->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vu_media_start(vdev); + } + + return 0; +} + +static void vu_media_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + if (!media->connected) { + return; + } + media->connected =3D false; + + if (vhost_dev_is_started(&media->vhost_dev)) { + vu_media_stop(vdev); + } +} + +static void vu_media_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vu_media_connect(dev) < 0) { + qemu_chr_fe_disconnect(&media->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vu_media_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserMEDIA *medi= a, + struct vhost_virtqueue *vhost_vqs) +{ + virtio_delete_queue(media->command_vq); + virtio_delete_queue(media->event_vq); + g_free(vhost_vqs); + virtio_cleanup(vdev); + vhost_user_cleanup(&media->vhost_user); +} + +static void vu_media_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev); + struct vhost_virtqueue *vhost_vqs; + int ret; + + if (!media->conf.chardev.chr) { + error_setg(errp, "vhost-user-media: chardev is mandatory"); + return; + } + + if (!vhost_user_init(&media->vhost_user, &media->conf.chardev, errp)) { + return; + } + + virtio_init(vdev, VIRTIO_ID_MEDIA, sizeof(struct virtio_media_config)); + + media->command_vq =3D virtio_add_queue(vdev, 128, vu_media_handle_outp= ut); + media->event_vq =3D virtio_add_queue(vdev, 128, vu_media_handle_output= ); + media->vhost_dev.nvqs =3D 2; + media->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, + media->vhost_dev.nvqs); + vhost_vqs =3D media->vhost_dev.vqs; + + vhost_dev_set_config_notifier(&media->vhost_dev, &media_ops); + media->vhost_user.supports_config =3D true; + + ret =3D vhost_dev_init(&media->vhost_dev, &media->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp); + if (ret < 0) { + do_vhost_user_cleanup(vdev, media, vhost_vqs); + return; + } + + qemu_chr_fe_set_handlers(&media->conf.chardev, NULL, + NULL, vu_media_event, + NULL, (void *)dev, NULL, true); +} + +static void vu_media_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev); + struct vhost_virtqueue *vhost_vqs =3D media->vhost_dev.vqs; + + /* This will stop vhost backend if appropriate. */ + vu_media_set_status(vdev, 0); + vhost_dev_cleanup(&media->vhost_dev); + do_vhost_user_cleanup(vdev, media, vhost_vqs); +} + +static const VMStateDescription vu_media_vmstate =3D { + .name =3D "vhost-user-media", + .unmigratable =3D 1, +}; + +static const Property vu_media_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserMEDIA, conf.chardev), +}; + +static void vu_media_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vu_media_properties); + dc->vmsd =3D &vu_media_vmstate; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize =3D vu_media_device_realize; + vdc->unrealize =3D vu_media_device_unrealize; + vdc->get_features =3D vu_media_get_features; + vdc->get_config =3D vu_media_get_config; + vdc->set_status =3D vu_media_set_status; + vdc->guest_notifier_mask =3D vu_media_guest_notifier_mask; + vdc->guest_notifier_pending =3D vu_media_guest_notifier_pending; +} + +static const TypeInfo vu_media_info =3D { + .name =3D TYPE_VHOST_USER_MEDIA, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserMEDIA), + .class_init =3D vu_media_class_init, +}; + +static void vu_media_register_types(void) +{ + type_register_static(&vu_media_info); +} + +type_init(vu_media_register_types) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index daa5607338..806a6811f5 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -198,7 +198,8 @@ const char *virtio_device_names[] =3D { [VIRTIO_ID_AUDIO_POLICY] =3D "virtio-audio-pol", [VIRTIO_ID_BT] =3D "virtio-bluetooth", [VIRTIO_ID_GPIO] =3D "virtio-gpio", - [VIRTIO_ID_SPI] =3D "virtio-spi" + [VIRTIO_ID_SPI] =3D "virtio-spi", + [VIRTIO_ID_MEDIA] =3D "virtio-media", }; =20 static const char *virtio_id_to_name(uint16_t device_id) diff --git a/include/hw/virtio/vhost-user-media.h b/include/hw/virtio/vhost= -user-media.h new file mode 100644 index 0000000000..d040c70f63 --- /dev/null +++ b/include/hw/virtio/vhost-user-media.h @@ -0,0 +1,46 @@ +/* + * vhost-user-media virtio device + * + * Copyright Red Hat, Inc. 2026 + * + * Authors: + * Albert Esteve + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VHOST_USER_MEDIA_H +#define QEMU_VHOST_USER_MEDIA_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "qom/object.h" + +#define TYPE_VHOST_USER_MEDIA "vhost-user-media-device" +OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIA, VHOST_USER_MEDIA) + +/* virtio-media config layout, spec 5.22.4 */ +struct virtio_media_config { + uint32_t device_caps; + uint32_t device_type; + uint8_t card[32]; +} QEMU_PACKED; + +typedef struct { + CharFrontend chardev; +} VHostUserMEDIAConf; + +struct VHostUserMEDIA { + /*< private >*/ + VirtIODevice parent; + VHostUserMEDIAConf conf; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *command_vq; + VirtQueue *event_vq; + bool connected; + /*< public >*/ +}; + +#endif /* QEMU_VHOST_USER_MEDIA_H */ --=20 2.55.0 From nobody Sat Sep 26 20:51:00 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1788264289; cv=none; d=zohomail.com; s=zohoarc; b=Bpw6AacWUOCGwXkm0xzl9e9oygLco9XWOnJ7UPGMNLDVGOI2hFsooO1E0ihEZuEFVJX5EmVuDLHzIv5anbu4vpzkdmMdDgYFchCD5TvxHbfv2+YkKnp385NCqab8/JNftA+hqL44KQsI7qM3vFKZP1O7nKPfBjh+LgYOVH5fk4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788264289; 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=TIcgWeDHp3iKmGpW6Lgkcfewds7jzt3Io0gG8YUmjcw=; b=JqEVGiiHuPxSNv4V9aQAPiRd+ODs+mKlZ10FU1ryszHKZkF6EMjdLmWnwZWwTGWDNo+Mk2Q25dVlX5PdWBx7UYP0jc0SqWxvGv28l3z4dmGunmmj3+YeJLloSbMC7Uvz0hd3nRtvy3Jt4dWp/2UQlCse69KCFAq0hv96iRkpYVQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788264289791311.0226895392667; Tue, 1 Sep 2026 05:04:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x1NE1-0001zt-TU; Tue, 01 Sep 2026 08:04:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x1NE0-0001yo-H4 for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:24 -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 1x1NDy-00074k-KB for qemu-devel@nongnu.org; Tue, 01 Sep 2026 08:04:24 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-Mglzu5xwMKqwaISloFII9g-1; Tue, 01 Sept 2026 08:04:18 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DABB19775FB; Tue, 1 Sep 2026 12:04:17 +0000 (UTC) Received: from aesteve-thinkpadp1gen8.rmtes.csb (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A4351955F01; Tue, 1 Sep 2026 12:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788264261; 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=TIcgWeDHp3iKmGpW6Lgkcfewds7jzt3Io0gG8YUmjcw=; b=Wx+0TLf2miFVkZIPOCtlSa/fF2PUhmPvAcjeKSnaWUjoqJzpc+gmfWMXEIIkf1pe3Lqmtm +QTEJs3dnUQSNkX0qN9lZ86O9kwgW/wbkUOcUIwipNQgeiYtmhmKYPr25Vd4pUwbbozgkG niUfku8xr4N37SwJHZCZO98dIzho5po= X-MC-Unique: Mglzu5xwMKqwaISloFII9g-1 X-Mimecast-MFC-AGG-ID: Mglzu5xwMKqwaISloFII9g_1788264257 From: Albert Esteve Date: Tue, 01 Sep 2026 14:04:06 +0200 Subject: [PATCH v2 3/3] hw/display/vhost-user-media: add shared memory region BAR MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-virtio-media-v2-3-bd3cc9347ab9@redhat.com> References: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> In-Reply-To: <20260901-virtio-media-v2-0-bd3cc9347ab9@redhat.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Stefano Garzarella , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Albert Esteve , manos.pitsidianakis@linaro.org, alex.bennee@linaro.org, Dorinda Bassey X-Developer-Signature: v=1; a=ed25519-sha256; t=1788264246; l=6072; i=aesteve@redhat.com; s=20260827; h=from:subject:message-id; bh=zIDnrimJu8SaF2bdSpoMB7As/XRQmE0mPXSQDHEFYng=; b=eLXzVQ1dNwpXua19FqgODBiowT1446Hl0cWR8mMIbsiCfmA7pJat8tNTtIf+BKnlV/VgeIFTq AASWNyYEGEbDCefgBzkvxi75qi4rAwrsunZewYt3oA8lVsgYCWP1CSd X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=zI2RBeZgocwYm3AkJW4CtjoJnKoDZrfBl1xe5Ed6h+U= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1788264292843154100 Expose virtio-media shared memory region 0 (spec 5.22.6.1.6) as a prefetchable 64-bit PCI BAR (BAR 2) with a VirtIO shm capability. The size is obtained through GET_SHMEM_CONFIG and requires at least one shared region. The guest maps host-provisioned MMAP buffers into this window; QEMU creates a container region on realize, not a full-sized RAM allocation. modern-pio-notify is rejected because it claims BAR 2. vhost-user still needs shareable guest RAM, e.g.: -object memory-backend-memfd,id=3Dmem,size=3D4G,share=3Don \ -numa node,memdev=3Dmem Tested-by: Dorinda Bassey Signed-off-by: Albert Esteve --- hw/display/vhost-user-media-pci.c | 35 ++++++++++++++++++++++++++++++++ hw/display/vhost-user-media.c | 42 +++++++++++++++++++++++++++++++++++= +++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/hw/display/vhost-user-media-pci.c b/hw/display/vhost-user-medi= a-pci.c index 3e09fcfdd0..7681f7505d 100644 --- a/hw/display/vhost-user-media-pci.c +++ b/hw/display/vhost-user-media-pci.c @@ -13,12 +13,18 @@ #include "hw/virtio/vhost-user-media.h" #include "hw/virtio/virtio-pci.h" =20 +/* BAR 2 is used for the shared memory region exposed to the guest */ +#define VIRTIO_MEDIA_PCI_SHM_BAR 2 + +#define VIRTIO_MEDIA_PCI_SHMCAP_ID_SHM 0 + #define TYPE_VHOST_USER_MEDIA_PCI "vhost-user-media-pci-base" OBJECT_DECLARE_SIMPLE_TYPE(VHostUserMEDIAPCI, VHOST_USER_MEDIA_PCI) =20 struct VHostUserMEDIAPCI { VirtIOPCIProxy parent_obj; VHostUserMEDIA vdev; + MemoryRegion shmbar; }; =20 static const Property vumedia_pci_properties[] =3D { @@ -32,14 +38,43 @@ static void vumedia_pci_realize(VirtIOPCIProxy *vpci_de= v, Error **errp) { VHostUserMEDIAPCI *dev =3D VHOST_USER_MEDIA_PCI(vpci_dev); DeviceState *dev_state =3D DEVICE(&dev->vdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev_state); + VirtioSharedMemory *shmem; + uint64_t shm_size; =20 if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { vpci_dev->nvectors =3D 1; } =20 + if (vpci_dev->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY) { + error_setg(errp, "modern-pio-notify is not supported due to PCI BA= R " + "layout limitations"); + return; + } + if (!qdev_realize(dev_state, BUS(&vpci_dev->bus), errp)) { return; } + + shmem =3D virtio_find_shmem_region(vdev, VIRTIO_MEDIA_PCI_SHMCAP_ID_SH= M); + if (!shmem) { + error_setg(errp, "vhost-user-media: missing shared memory region"); + return; + } + shm_size =3D memory_region_size(&shmem->mr); + + memory_region_init(&dev->shmbar, OBJECT(vpci_dev), + "vhost-media-pci-shmbar", shm_size); + memory_region_add_subregion(&dev->shmbar, 0, &shmem->mr); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_MEDIA_PCI_SHM_BAR, 0, + shm_size, VIRTIO_MEDIA_PCI_SHMCAP_ID_SHM); + + /* After 'realized' so the memory region exists */ + pci_register_bar(&vpci_dev->pci_dev, VIRTIO_MEDIA_PCI_SHM_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &dev->shmbar); } =20 static void vumedia_pci_class_init(ObjectClass *klass, const void *data) diff --git a/hw/display/vhost-user-media.c b/hw/display/vhost-user-media.c index 14edc7c668..eaf99dc6a2 100644 --- a/hw/display/vhost-user-media.c +++ b/hw/display/vhost-user-media.c @@ -19,6 +19,7 @@ #include "standard-headers/linux/virtio_ids.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/vhost-user-media.h" +#include "migration/blocker.h" =20 static const int feature_bits[] =3D { VIRTIO_F_VERSION_1, @@ -259,8 +260,9 @@ static void vu_media_device_realize(DeviceState *dev, E= rror **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserMEDIA *media =3D VHOST_USER_MEDIA(dev); + uint64_t memory_sizes[VIRTIO_MAX_SHMEM_REGIONS]; struct vhost_virtqueue *vhost_vqs; - int ret; + int ret, nregions; =20 if (!media->conf.chardev.chr) { error_setg(errp, "vhost-user-media: chardev is mandatory"); @@ -290,9 +292,47 @@ static void vu_media_device_realize(DeviceState *dev, = Error **errp) return; } =20 + ret =3D media->vhost_dev.vhost_ops->vhost_get_shmem_config(&media->vho= st_dev, + &nregions, + memory_sizes, + errp); + if (ret < 0) { + goto q_fail; + } + + if (!nregions || !memory_sizes[0]) { + error_setg(errp, "vhost-user-media: backend did not provide " + "shared memory region 0"); + goto q_fail; + } + + if (memory_sizes[0] % qemu_real_host_page_size() !=3D 0) { + error_setg(errp, "shared memory region 0 size must be a multiple " + "of the host page size"); + goto q_fail; + } + + if (media->vhost_dev.migration_blocker =3D=3D NULL) { + error_setg(&media->vhost_dev.migration_blocker, + "Migration disabled: devices with VIRTIO Shared Memory " + "Regions do not support migration yet."); + ret =3D migrate_add_blocker_normal(&media->vhost_dev.migration_blo= cker, + errp); + if (ret < 0) { + goto q_fail; + } + } + + virtio_new_shmem_region(vdev, 0, memory_sizes[0]); + qemu_chr_fe_set_handlers(&media->conf.chardev, NULL, NULL, vu_media_event, NULL, (void *)dev, NULL, true); + return; + +q_fail: + vhost_dev_cleanup(&media->vhost_dev); + do_vhost_user_cleanup(vdev, media, vhost_vqs); } =20 static void vu_media_device_unrealize(DeviceState *dev) --=20 2.55.0