From patchwork Mon May 16 10:39:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 572979 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1590:0:0:0:0 with SMTP id w16csp1021606map; Mon, 16 May 2022 05:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjXEbIfbNRnZrojKFoolAnHULK8C5++fEaGwMuQQIdkJnH1F5EazXUAAzaGu/3z5MieewS X-Received: by 2002:a05:620a:1981:b0:507:4a52:f310 with SMTP id bm1-20020a05620a198100b005074a52f310mr12219363qkb.611.1652704327758; Mon, 16 May 2022 05:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652704327; cv=none; d=google.com; s=arc-20160816; b=wN1Vy0lzBa3GqdyjrFT0p3m9SB6ZjyGXpiTJX78dSn3K/K8RkYZlEcboV5txzkLQhU UtlVG9BK8OFl4QGJXcfxZZKjhd+ODADSQAhtkeqE/j58mp+VuuYC737iXuWBh/xrE4NO QLOZQ55V9yTe5NVobgYhT6VzCCjay8o4LKdHT3AOG29M89HLYLZGhz9JEmcKXpElvswv n66Gb9S+v5drybIRsx3WlO6Aik5OQtxoCoAJeoh45Me2AYtkClDw3LbThDyg1icza7rS 1x8GWCZaOk1Yv1ULhIQK7XguAR8pkSXom1D0Y574h8k3/DiEPB1siCR492RB7pKcVdPg H++Q== 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=B1nDZq61p1Fo9R+kfzgjGxckxAqyZiNflr6I94N0EOM=; b=YpO7pLsB37GP8thN9figCB/kszqudDLDFynjvzxYawXxNx5Oj8PzWLPOaCN30IxNxR NsSrlrxxt3F/XH6m5BduhC4tAO7myV/Z6s2TY2GwbWy1rnCLWJMWmjmUFSe6ZBRq0ZhE hxElvqKhPRx9Zj6aTEiVmUe+T5dT5UUxxU51ZAoMLTF0/raI4NsqFVflkbEEiK+cIODp YGLEgAjOstR75ZkVLo7tWMqzwhoeSnIHaM/2OGwxpDYKKNGLi75wCb/03deNLCdiYu5i tGtBOcJ7su8RSgJC7GYNiE1nmBrHtkG/9e9SrEgz+te/AzvdV3GTe+wC1w2uW+TWUsxH frqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Te1KlFh0; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j5-20020a05620a410500b0069f167f0d6asi7521740qko.16.2022.05.16.05.32.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 May 2022 05:32:07 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=Te1KlFh0; 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=redhat.com Received: from localhost ([::1]:59436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqZtO-0001QV-Ow for patch@linaro.org; Mon, 16 May 2022 08:32:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY8Y-0001JI-DS for qemu-devel@nongnu.org; Mon, 16 May 2022 06:39:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY8W-0005eZ-GG for qemu-devel@nongnu.org; Mon, 16 May 2022 06:39:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652697575; 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=B1nDZq61p1Fo9R+kfzgjGxckxAqyZiNflr6I94N0EOM=; b=Te1KlFh0gHiCnQKOs780mNswy00OVYkF5uTsLO8/60pk5lzDWbOK22p4rjDkKOAam8c5cS iMDCwp+EVppr6nbSoSljuHTMDKj2lSSMnwl6h1lpnrNhNKDLRk7axLdQtjBVJzePod07HM YojjiIqB06qqSd1q45YXW71sMOLltLQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-tybkcoMtNhK8mMA3aFMhjA-1; Mon, 16 May 2022 06:39:34 -0400 X-MC-Unique: tybkcoMtNhK8mMA3aFMhjA-1 Received: by mail-wm1-f69.google.com with SMTP id z23-20020a05600c221700b003942fd37764so10138188wml.8 for ; Mon, 16 May 2022 03:39:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=B1nDZq61p1Fo9R+kfzgjGxckxAqyZiNflr6I94N0EOM=; b=CkqoNO2BhDhf13EAdVjdfh2G5mQ3QVvkHN9eVDFRwqbYQLh6r7fwg+eFFlUOmcCoJ8 +as9bXf4WZJpLB4j8Ye5rcCXMPnbPro51n9aWJ9bN990QtyTDrRUucngJEIaE5M5xYAc PK7oSLFkkIfHa9ML8756+0eovMFLMJ+GwwPwC+iSf9CH7+LcrgRDGwRivQ2HjS+uVCr5 raFs2Ha0tyaIMHXTEbszLlmwsDPF4+fP0+U1ySTconhV2qwcIZkfdq4oGl5sZC9M/qST bar0aDJ/LA4SU2J/6F7Jk3lI5MRRthaWjtWeV+4PbXY164r2DTFgHdfM8JtkmdndtOC5 Z7vg== X-Gm-Message-State: AOAM530Bq0iyIcaPW20EQmQhugD+T3Y7UamBT/mylKAKaCxIDp+H6B00 BpjOIy7NJuL8lP0uKos+u4hESG7B02mbcXDHFoumlFE22Ur6X0Q3HYdLR74DlwDzn9jQWKvETAc dcBjCofXcTIkPFutn8rSUrSpgrKUn3EHirBF6d3BVVRt5duHzIq4/pR2UeyC5 X-Received: by 2002:adf:b60a:0:b0:20c:d5f0:82b5 with SMTP id f10-20020adfb60a000000b0020cd5f082b5mr13850612wre.329.1652697573291; Mon, 16 May 2022 03:39:33 -0700 (PDT) X-Received: by 2002:adf:b60a:0:b0:20c:d5f0:82b5 with SMTP id f10-20020adfb60a000000b0020cd5f082b5mr13850592wre.329.1652697572916; Mon, 16 May 2022 03:39:32 -0700 (PDT) Received: from redhat.com ([2.55.141.66]) by smtp.gmail.com with ESMTPSA id x16-20020adfbb50000000b0020d11ee1bcesm195648wrg.82.2022.05.16.03.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 03:39:32 -0700 (PDT) Date: Mon, 16 May 2022 06:39:30 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Alex =?utf-8?q?Benn=C3=A9e?= , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Subject: [PULL 67/91] include/hw: start documenting the vhost API Message-ID: <20220516095448.507876-68-mst@redhat.com> References: <20220516095448.507876-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220516095448.507876-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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" From: Alex Bennée While trying to get my head around the nest of interactions for vhost devices I though I could start by documenting the key API functions. This patch documents the main API hooks for creating and starting a vhost device as well as how the configuration changes are handled. Signed-off-by: Alex Bennée Cc: Michael S. Tsirkin Cc: Stefan Hajnoczi Cc: Marc-André Lureau Message-Id: <20220321153037.3622127-11-alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 132 +++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 10 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 58a73e7b7a..b291fe4e24 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -61,6 +61,12 @@ typedef struct VhostDevConfigOps { } VhostDevConfigOps; struct vhost_memory; + +/** + * struct vhost_dev - common vhost_dev structure + * @vhost_ops: backend specific ops + * @config_ops: ops for config changes (see @vhost_dev_set_config_notifier) + */ struct vhost_dev { VirtIODevice *vdev; MemoryListener memory_listener; @@ -108,15 +114,129 @@ struct vhost_net { NetClientState *nc; }; +/** + * vhost_dev_init() - initialise the vhost interface + * @hdev: the common vhost_dev structure + * @opaque: opaque ptr passed to backend (vhost/vhost-user/vdpa) + * @backend_type: type of backend + * @busyloop_timeout: timeout for polling virtqueue + * @errp: error handle + * + * The initialisation of the vhost device will trigger the + * initialisation of the backend and potentially capability + * negotiation of backend interface. Configuration of the VirtIO + * itself won't happen until the interface is started. + * + * Return: 0 on success, non-zero on error while setting errp. + */ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout, Error **errp); + +/** + * vhost_dev_cleanup() - tear down and cleanup vhost interface + * @hdev: the common vhost_dev structure + */ void vhost_dev_cleanup(struct vhost_dev *hdev); -int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); + +/** + * vhost_dev_enable_notifiers() - enable event notifiers + * @hdev: common vhost_dev structure + * @vdev: the VirtIODevice structure + * + * Enable notifications directly to the vhost device rather than being + * triggered by QEMU itself. Notifications should be enabled before + * the vhost device is started via @vhost_dev_start. + * + * Return: 0 on success, < 0 on error. + */ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); + +/** + * vhost_dev_disable_notifiers - disable event notifications + * @hdev: common vhost_dev structure + * @vdev: the VirtIODevice structure + * + * Disable direct notifications to vhost device. + */ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); +/** + * vhost_dev_start() - start the vhost device + * @hdev: common vhost_dev structure + * @vdev: the VirtIODevice structure + * + * Starts the vhost device. From this point VirtIO feature negotiation + * can start and the device can start processing VirtIO transactions. + * + * Return: 0 on success, < 0 on error. + */ +int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); + +/** + * vhost_dev_stop() - stop the vhost device + * @hdev: common vhost_dev structure + * @vdev: the VirtIODevice structure + * + * Stop the vhost device. After the device is stopped the notifiers + * can be disabled (@vhost_dev_disable_notifiers) and the device can + * be torn down (@vhost_dev_cleanup). + */ +void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); + +/** + * DOC: vhost device configuration handling + * + * The VirtIO device configuration space is used for rarely changing + * or initialisation time parameters. The configuration can be updated + * by either the guest driver or the device itself. If the device can + * change the configuration over time the vhost handler should + * register a @VhostDevConfigOps structure with + * @vhost_dev_set_config_notifier so the guest can be notified. Some + * devices register a handler anyway and will signal an error if an + * unexpected config change happens. + */ + +/** + * vhost_dev_get_config() - fetch device configuration + * @hdev: common vhost_dev_structure + * @config: pointer to device appropriate config structure + * @config_len: size of device appropriate config structure + * + * Return: 0 on success, < 0 on error while setting errp + */ +int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, + uint32_t config_len, Error **errp); + +/** + * vhost_dev_set_config() - set device configuration + * @hdev: common vhost_dev_structure + * @data: pointer to data to set + * @offset: offset into configuration space + * @size: length of set + * @flags: @VhostSetConfigType flags + * + * By use of @offset/@size a subset of the configuration space can be + * written to. The @flags are used to indicate if it is a normal + * transaction or related to migration. + * + * Return: 0 on success, non-zero on error + */ +int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags); + +/** + * vhost_dev_set_config_notifier() - register VhostDevConfigOps + * @hdev: common vhost_dev_structure + * @ops: notifier ops + * + * If the device is expected to change configuration a notifier can be + * setup to handle the case. + */ +void vhost_dev_set_config_notifier(struct vhost_dev *dev, + const VhostDevConfigOps *ops); + + /* Test and clear masked event pending status. * Should be called after unmask to avoid losing events. */ @@ -136,14 +256,6 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file); int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write); -int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, - uint32_t config_len, Error **errp); -int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data, - uint32_t offset, uint32_t size, uint32_t flags); -/* notifier callback in case vhost device config space changed - */ -void vhost_dev_set_config_notifier(struct vhost_dev *dev, - const VhostDevConfigOps *ops); void vhost_dev_reset_inflight(struct vhost_inflight *inflight); void vhost_dev_free_inflight(struct vhost_inflight *inflight);