From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TFwHDhuW; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 2221C5A004E for ; Thu, 19 Dec 2024 15:35:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734618903; 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=Nz62zSCqTEZVrDyKE+1VVn2KmqSI3OkaLPUIlE9f+HM=; b=TFwHDhuWnftP4XBQ/u4lOrpzOjBcPkqZUic95bVDFih5apkuni/BR42tSfg0pv6T9bBd/6 RS+KtcoFNCpVzVljtfq0237PddFBazzDJZS7OdtGcHfZzZfz4DbkMyIEzFlBRXZwZE8tV0 YkVDTOsGEGCL0g2/BBWBLXQ8LtwRJ7I= Received: from mx-prod-mc-02.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-121-EbBwZrReMd-p2ybGWJPqQQ-1; Thu, 19 Dec 2024 06:14:08 -0500 X-MC-Unique: EbBwZrReMd-p2ybGWJPqQQ-1 X-Mimecast-MFC-AGG-ID: EbBwZrReMd-p2ybGWJPqQQ Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED21D19560A1 for ; Thu, 19 Dec 2024 11:14:07 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.39.193.37]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 079D419560A2; Thu, 19 Dec 2024 11:14:06 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 3/9] vhost-user: add VHOST_USER_SET_LOG_FD command Date: Thu, 19 Dec 2024 12:13:54 +0100 Message-ID: <20241219111400.2352110-4-lvivier@redhat.com> In-Reply-To: <20241219111400.2352110-1-lvivier@redhat.com> References: <20241219111400.2352110-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 80epbolPb9hVYurhDMRTl3YEMVs-9iU94mD7MtgPtro_1734606848 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: WCQZ2KLTMJVXE5BQ33UN7SAZMXXCEGLH X-Message-ID-Hash: WCQZ2KLTMJVXE5BQ33UN7SAZMXXCEGLH X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: VHOST_USER_SET_LOG_FD is an optional message with an eventfd in ancillary data, it may be used to inform the front-end that the log has been modified. Signed-off-by: Laurent Vivier --- vhost_user.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vhost_user.h | 1 + virtio.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/vhost_user.c b/vhost_user.c index 48226a8b7686..ce4373d9eeca 100644 --- a/vhost_user.c +++ b/vhost_user.c @@ -504,6 +504,57 @@ static bool vu_set_mem_table_exec(struct vu_dev *vdev, return false; } +/** + * vu_close_log() - Close the logging file descriptor + * @vdev: vhost-user device + */ +static void vu_close_log(struct vu_dev *vdev) +{ + if (vdev->log_call_fd != -1) { + close(vdev->log_call_fd); + vdev->log_call_fd = -1; + } +} + +/** + * vu_log_kick() - Inform the front-end that the log has been modified + * @vdev: vhost-user device + */ +/* cppcheck-suppress unusedFunction */ +void vu_log_kick(const struct vu_dev *vdev) +{ + if (vdev->log_call_fd != -1) { + int rc; + + rc = eventfd_write(vdev->log_call_fd, 1); + if (rc == -1) + die_perror("vhost-user kick eventfd_write()"); + } +} + +/** + * vu_set_log_fd_exec() -- Set the eventfd used to report logging update + * @vdev: vhost-user device + * @vmsg: vhost-user message + * + * Return: False as no reply is requested + */ +static bool vu_set_log_fd_exec(struct vu_dev *vdev, + struct vhost_user_msg *msg) +{ + if (msg->fd_num != 1) + die("Invalid log_fd message"); + + if (vdev->log_call_fd != -1) + close(vdev->log_call_fd); + + vdev->log_call_fd = msg->fds[0]; + + debug("Got log_call_fd: %d", vdev->log_call_fd); + + return false; +} + /** * vu_set_vring_num_exec() - Set the size of the queue (vring size) * @vdev: vhost-user device @@ -864,8 +915,10 @@ void vu_init(struct ctx *c) .notification = true, }; } + c->vdev->log_call_fd = -1; } + /** * vu_cleanup() - Reset vhost-user device * @vdev: vhost-user device @@ -909,6 +962,8 @@ void vu_cleanup(struct vu_dev *vdev) } } vdev->nregions = 0; + + vu_close_log(vdev); } /** @@ -929,6 +984,7 @@ static bool (*vu_handle[VHOST_USER_MAX])(struct vu_dev *vdev, [VHOST_USER_GET_QUEUE_NUM] = vu_get_queue_num_exec, [VHOST_USER_SET_OWNER] = vu_set_owner_exec, [VHOST_USER_SET_MEM_TABLE] = vu_set_mem_table_exec, + [VHOST_USER_SET_LOG_FD] = vu_set_log_fd_exec, [VHOST_USER_SET_VRING_NUM] = vu_set_vring_num_exec, [VHOST_USER_SET_VRING_ADDR] = vu_set_vring_addr_exec, [VHOST_USER_SET_VRING_BASE] = vu_set_vring_base_exec, diff --git a/vhost_user.h b/vhost_user.h index fbacb5560755..2fc0342ff5ba 100644 --- a/vhost_user.h +++ b/vhost_user.h @@ -240,5 +240,6 @@ static inline bool vu_queue_started(const struct vu_virtq *vq) void vu_print_capabilities(void); void vu_init(struct ctx *c); void vu_cleanup(struct vu_dev *vdev); +void vu_log_kick(const struct vu_dev *vdev); void vu_control_handler(struct vu_dev *vdev, int fd, uint32_t events); #endif /* VHOST_USER_H */ diff --git a/virtio.h b/virtio.h index 0af259df7dac..3b0df343d6b6 100644 --- a/virtio.h +++ b/virtio.h @@ -103,6 +103,7 @@ struct vu_dev_region { * @regions: Guest shared memory regions * @features: Vhost-user features * @protocol_features: Vhost-user protocol features + * @log_call_fd: Eventfd to report logging update */ struct vu_dev { struct ctx *context; @@ -111,6 +112,7 @@ struct vu_dev { struct vu_virtq vq[VHOST_USER_MAX_QUEUES]; uint64_t features; uint64_t protocol_features; + int log_call_fd; }; /** -- 2.47.1