From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DC1AE45F2F for ; Tue, 24 Dec 2024 16:50:17 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F2A94402E6; Tue, 24 Dec 2024 16:50:13 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id CDAE0402DC for ; Tue, 24 Dec 2024 16:50:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735055412; 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=J4NE0797w43n7qPEvtn22nscXA8xcJaIjVaLRyzfORw=; b=jOSga3vuEs7G7KvDNysiQDyP1bwHMaJ1kwssfBcZXDVeI1BmC1oft6nv4xFmxLIdf/34Iu 2gPGuGGJ1B2xZG6UF2KVHOVWg2Xa3YY5J+LKe83RgF4RLmyODBVsNgV0/SxC9KvN1bQbhs gs89IqjRlQARackHpLkJfOyxwTZNJio= Received: from mx-prod-mc-04.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-694-Ke7cIvEFN2-jKdgCJ5DIFA-1; Tue, 24 Dec 2024 10:50:09 -0500 X-MC-Unique: Ke7cIvEFN2-jKdgCJ5DIFA-1 X-Mimecast-MFC-AGG-ID: Ke7cIvEFN2-jKdgCJ5DIFA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44ABD19560A2; Tue, 24 Dec 2024 15:50:08 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BCA41956086; Tue, 24 Dec 2024 15:50:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [RFC 2/3] vhost: fix vhost-user socket cleanup order Date: Tue, 24 Dec 2024 16:49:57 +0100 Message-ID: <20241224154958.146852-3-maxime.coquelin@redhat.com> In-Reply-To: <20241224154958.146852-1-maxime.coquelin@redhat.com> References: <20241224154958.146852-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2zmK0zQtyzHluNDVkrbop2L4eU-Jejyl9i0LJkJFQaU_1735055408 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org This patch leverages the new FD entry cleanup callback to properly cleanup the vhost-user socket on disconnection from the frontend. Fixes: 0e38b42bf61c ("vhost: manage FD with epoll") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/socket.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index e301efb367..898570606c 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -86,6 +86,7 @@ struct vhost_user { static void vhost_user_server_new_connection(int fd, void *data, int *remove); static void vhost_user_read_cb(int fd, void *dat, int *remove); +static void vhost_user_cleanup_cb(int fd, void *dat); static int create_unix_socket(struct vhost_user_socket *vsocket); static int vhost_user_start_client(struct vhost_user_socket *vsocket); @@ -263,7 +264,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) conn->vsocket = vsocket; conn->vid = vid; ret = fdset_add(vhost_user.fdset, fd, vhost_user_read_cb, - NULL, NULL, conn); + NULL, vhost_user_cleanup_cb, conn); if (ret < 0) { VHOST_CONFIG_LOG(vsocket->path, ERR, "failed to add fd %d into vhost server fdset", @@ -306,35 +307,40 @@ static void vhost_user_read_cb(int connfd, void *dat, int *remove) { struct vhost_user_connection *conn = dat; - struct vhost_user_socket *vsocket = conn->vsocket; int ret; ret = vhost_user_msg_handler(conn->vid, connfd); - if (ret < 0) { - struct virtio_net *dev = get_device(conn->vid); - - close(connfd); + if (ret < 0) *remove = 1; +} - if (dev) - vhost_destroy_device_notify(dev); +static void +vhost_user_cleanup_cb(int connfd, void *dat) +{ + struct vhost_user_connection *conn = dat; + struct vhost_user_socket *vsocket = conn->vsocket; + struct virtio_net *dev = get_device(conn->vid); - if (vsocket->notify_ops->destroy_connection) - vsocket->notify_ops->destroy_connection(conn->vid); + close(connfd); - vhost_destroy_device(conn->vid); + if (dev) + vhost_destroy_device_notify(dev); - if (vsocket->reconnect) { - create_unix_socket(vsocket); - vhost_user_start_client(vsocket); - } + if (vsocket->notify_ops->destroy_connection) + vsocket->notify_ops->destroy_connection(conn->vid); - pthread_mutex_lock(&vsocket->conn_mutex); - TAILQ_REMOVE(&vsocket->conn_list, conn, next); - pthread_mutex_unlock(&vsocket->conn_mutex); + vhost_destroy_device(conn->vid); - free(conn); + if (vsocket->reconnect) { + create_unix_socket(vsocket); + vhost_user_start_client(vsocket); } + + pthread_mutex_lock(&vsocket->conn_mutex); + TAILQ_REMOVE(&vsocket->conn_list, conn, next); + pthread_mutex_unlock(&vsocket->conn_mutex); + + free(conn); } static int -- 2.47.1