From patchwork Thu Jan 4 21:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 759879 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7183737wrw; Thu, 4 Jan 2024 13:12:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSbos4L8eTvZ62HKS4OvUegGDRupCipuOMS+gqrF8K9rn9HkYpMuGRaFhgH/7cOBpo1BJp X-Received: by 2002:a25:910c:0:b0:dbd:ad04:1cf6 with SMTP id v12-20020a25910c000000b00dbdad041cf6mr1073260ybl.27.1704402751339; Thu, 04 Jan 2024 13:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704402751; cv=none; d=google.com; s=arc-20160816; b=nMh35PZYuN4QmpNonfg3mAEltVJLxQwYDtyhGJU5+opwcFxJ+mUt58O5e2qCwW16B6 TjscetrD5m+xHSEIofU1Q/JKMelFrOil6a7nnx953e+OyASfFSaK6OwGtFtrz4xgziGR DjaLR+ujss9pFmaAABPz0g+LbROc1HzQaC7sTLDFTF/Q3znOZUxqmIWTTuD1SHQgCf3g +e0omY+7ErGNdETuEt0yKmVwhbUn+GHtubHLBdF6f9bIhs/Tg+UGdEdhUTBCf6PsQOrJ mK3p1CUqK/dZtSjwMycuPDqczO60AjwJdY4wObNQ1CDL6AXDDlA1VPSFCPiKX3Qdwmx6 DOTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; fh=Ud52xLVns4YOXK9oAfV6buiiCgh2jRAKo3BCP7q+jII=; b=HYUtzLXnIeuHKimJIKhT5HxlO9dJpMo/mC8s3Esc6vk/K0Vr3NOM8UoBsCtpOpFnWz PajvXleEvDi7b3kdrqv/+JiEajNIxVpKomCKOnMKjFbiAbKdDeGXAabLI/MsYZ6Rt/gq a/Di2Z9saLXwTPPsWSNdura3U+vtkRow2o7zdFXyHIlXdSaz2MFJCjs9GK7ppqx+EKCU PitM3FjnUdATjDfLwrFvJzGcalmF69dmwIz/n/EUidjnbEM1zuQxrjaNPHlQ0CIWMD6B 6V16Q6YPF+z1l0DQCF292u5R2/CkG2u6QX369e4CfX7E4AAv9GtYNl46zbsQmp4vQqFU YTGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOKRMYXj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 17-20020ac85951000000b004288831c10csi390111qtz.180.2024.01.04.13.12.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2024 13:12:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOKRMYXj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUzV-0007oI-KV; Thu, 04 Jan 2024 16:11:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUyW-0006xd-V7 for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:10:04 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLUyT-0007VA-1F for qemu-devel@nongnu.org; Thu, 04 Jan 2024 16:09:59 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3367632ce7bso685406f8f.2 for ; Thu, 04 Jan 2024 13:09:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704402595; x=1705007395; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; b=gOKRMYXj0XR5JMaNzepaez0PaMD37d/3Cr75TrriUzoOjTQPE2qu1ube7hGYyc5zRX UETsDwFsPs/U17YH66GL846/Wo2RnSFn5i2dPM85vZYZC5ohD+ka8wIflukQrYZh3AWe ebBEkfETayg6p96YdipMyFZUAsIKhy3ATnt90wr0X2PmjTvEHXzbdR4IywzSGKiFH8p7 qEcE6cIvPdLbBd2u0D4TIlhX0BJN9Gv3xq9hPgI9FmDl8P2LBEYumTEIomdIcgqIBEL6 nhjFcJUrbw2HHYnGcx23TU5okhuXTQK3z2M9TMejO+FeR+XBhyV7//3UA2lgLG2/Eo22 cuKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704402595; x=1705007395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YUt/1uqyWaURmVAVVhlqD6XH9TChabURPi6+UCY421E=; b=eGXC0efE0KXWpkpJugKDBm+jmscuARaAugvjTlgS2al5A3B/Myii5+DhGd6ab6Wl5t hzQ95Wft2ZnUE2i0MHI99CWuNxp8F7xH1w6YYrlZuBTcKxp4UMLUSYmr/GeOlCHp2KFn Wj/pFA3mN8lSska+iB1srS53dlRueOYEjT5ep0u/dqQlL/HUX0KuoMTbzu4oi3qKGSAZ 7uvFVH5VzRtwFub4sQt1MjDqrcCsY7HH/LhmyuMeYP2CQFUEmlvd/Ex/H1foVNTOqka5 JG7Qm13q1kznVYKuqAzv8szM42Zu1icxJvxo8l7orMzKiw6lrte7Ap5PY4+ddC1PIgcY nx3Q== X-Gm-Message-State: AOJu0YySppVL5g71i/LwtwWN7xcb7jl0059/Q7YEGHLR6b5u1aX4QxAP IV249gvIcj034PML9VvFfRnGZwDzjjM8FQ== X-Received: by 2002:a5d:5d0e:0:b0:336:7a5c:ffdf with SMTP id ch14-20020a5d5d0e000000b003367a5cffdfmr902957wrb.13.1704402595038; Thu, 04 Jan 2024 13:09:55 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f17-20020adfc991000000b0033609b71825sm107862wrh.35.2024.01.04.13.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:09:53 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2B0755F92F; Thu, 4 Jan 2024 21:09:46 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Mathieu Poirier , Kevin Wolf , Mark Cave-Ayland , Jason Wang , Erik Schilling , Eric Blake , Fam Zheng , =?utf-8?q?Marc-?= =?utf-8?q?Andr=C3=A9_Lureau?= , Eduardo Habkost , virtio-fs@redhat.com, Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , =?utf-8?q?Daniel_P=2E?= =?utf-8?q?_Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , "Gonglei (Arei)" , "Michael S. Tsirkin" , Raphael Norwitz , Paolo Bonzini , Viresh Kumar , Stefan Hajnoczi , Leo Yan Subject: [PATCH v9 11/11] hw/virtio: derive vhost-user-input from vhost-user-base Date: Thu, 4 Jan 2024 21:09:45 +0000 Message-Id: <20240104210945.1223134-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104210945.1223134-1-alex.bennee@linaro.org> References: <20240104210945.1223134-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Leo Yan This patch derives vhost-user-input from vhost-user-base class, so make the input stub as a simpler boilerplate wrapper. With the refactoring, vhost-user-input adds the property 'chardev', this leads to conflict with the vhost-user-input-pci adds the same property. To resolve the error, remove the duplicate property from vhost-user-input-pci. Signed-off-by: Leo Yan Reviewed-by: Manos Pitsidianakis Message-Id: <20231120043721.50555-5-leo.yan@linaro.org> Signed-off-by: Alex Bennée --- include/hw/virtio/virtio-input.h | 6 +- hw/virtio/vhost-user-input-pci.c | 3 - hw/virtio/vhost-user-input.c | 114 +++++-------------------------- 3 files changed, 21 insertions(+), 102 deletions(-) diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h index a6c97036440..e69c0aeca38 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -1,6 +1,8 @@ #ifndef QEMU_VIRTIO_INPUT_H #define QEMU_VIRTIO_INPUT_H +#include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-base.h" #include "ui/input.h" #include "sysemu/vhost-user-backend.h" @@ -97,9 +99,7 @@ struct VirtIOInputHost { }; struct VHostUserInput { - VirtIOInput parent_obj; - - VhostUserBackend *vhost; + VHostUserBase parent_obj; }; void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event); diff --git a/hw/virtio/vhost-user-input-pci.c b/hw/virtio/vhost-user-input-pci.c index b858898a363..3f4761ce88a 100644 --- a/hw/virtio/vhost-user-input-pci.c +++ b/hw/virtio/vhost-user-input-pci.c @@ -30,9 +30,6 @@ static void vhost_user_input_pci_instance_init(Object *obj) virtio_instance_init_common(obj, &dev->vhi, sizeof(dev->vhi), TYPE_VHOST_USER_INPUT); - - object_property_add_alias(obj, "chardev", - OBJECT(&dev->vhi), "chardev"); } static const VirtioPCIDeviceTypeInfo vhost_user_input_pci_info = { diff --git a/hw/virtio/vhost-user-input.c b/hw/virtio/vhost-user-input.c index 4ee3542106e..bedec0468c3 100644 --- a/hw/virtio/vhost-user-input.c +++ b/hw/virtio/vhost-user-input.c @@ -5,83 +5,25 @@ */ #include "qemu/osdep.h" -#include "qemu/error-report.h" -#include "qapi/error.h" - #include "hw/virtio/virtio-input.h" -static int vhost_input_config_change(struct vhost_dev *dev) -{ - error_report("vhost-user-input: unhandled backend config change"); - return -1; -} - -static const VhostDevConfigOps config_ops = { - .vhost_dev_config_notifier = vhost_input_config_change, +static Property vinput_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), + DEFINE_PROP_END_OF_LIST(), }; -static void vhost_input_realize(DeviceState *dev, Error **errp) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(dev); - VirtIOInput *vinput = VIRTIO_INPUT(dev); - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - - vhost_dev_set_config_notifier(&vhi->vhost->dev, &config_ops); - vinput->cfg_size = sizeof_field(virtio_input_config, u); - if (vhost_user_backend_dev_init(vhi->vhost, vdev, 2, errp) == -1) { - return; - } -} - -static void vhost_input_change_active(VirtIOInput *vinput) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(vinput); - - if (vinput->active) { - vhost_user_backend_start(vhi->vhost); - } else { - vhost_user_backend_stop(vhi->vhost); - } -} - -static void vhost_input_get_config(VirtIODevice *vdev, uint8_t *config_data) -{ - VirtIOInput *vinput = VIRTIO_INPUT(vdev); - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - Error *local_err = NULL; - int ret; - - memset(config_data, 0, vinput->cfg_size); - - ret = vhost_dev_get_config(&vhi->vhost->dev, config_data, vinput->cfg_size, - &local_err); - if (ret) { - error_report_err(local_err); - return; - } -} - -static void vhost_input_set_config(VirtIODevice *vdev, - const uint8_t *config_data) +static void vinput_realize(DeviceState *dev, Error **errp) { - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - int ret; + VHostUserBase *vub = VHOST_USER_BASE(dev); + VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); - ret = vhost_dev_set_config(&vhi->vhost->dev, config_data, - 0, sizeof(virtio_input_config), - VHOST_SET_CONFIG_TYPE_FRONTEND); - if (ret) { - error_report("vhost-user-input: set device config space failed"); - return; - } + /* Fixed for input device */ + vub->virtio_id = VIRTIO_ID_INPUT; + vub->num_vqs = 2; + vub->vq_size = 4; + vub->config_size = sizeof(virtio_input_config); - virtio_notify_config(vdev); -} - -static struct vhost_dev *vhost_input_get_vhost(VirtIODevice *vdev) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(vdev); - return &vhi->vhost->dev; + vubc->parent_realize(dev, errp); } static const VMStateDescription vmstate_vhost_input = { @@ -91,40 +33,20 @@ static const VMStateDescription vmstate_vhost_input = { static void vhost_input_class_init(ObjectClass *klass, void *data) { - VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass); - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_vhost_input; - vdc->get_config = vhost_input_get_config; - vdc->set_config = vhost_input_set_config; - vdc->get_vhost = vhost_input_get_vhost; - vic->realize = vhost_input_realize; - vic->change_active = vhost_input_change_active; -} - -static void vhost_input_init(Object *obj) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(obj); - - vhi->vhost = VHOST_USER_BACKEND(object_new(TYPE_VHOST_USER_BACKEND)); - object_property_add_alias(obj, "chardev", - OBJECT(vhi->vhost), "chardev"); -} - -static void vhost_input_finalize(Object *obj) -{ - VHostUserInput *vhi = VHOST_USER_INPUT(obj); - - object_unref(OBJECT(vhi->vhost)); + device_class_set_props(dc, vinput_properties); + device_class_set_parent_realize(dc, vinput_realize, + &vubc->parent_realize); + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } static const TypeInfo vhost_input_info = { .name = TYPE_VHOST_USER_INPUT, - .parent = TYPE_VIRTIO_INPUT, + .parent = TYPE_VHOST_USER_BASE, .instance_size = sizeof(VHostUserInput), - .instance_init = vhost_input_init, - .instance_finalize = vhost_input_finalize, .class_init = vhost_input_class_init, };