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 C5EB4A00C3; Thu, 21 Apr 2022 10:20:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A6BF340042; Thu, 21 Apr 2022 10:20:03 +0200 (CEST) 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 77EC140040 for ; Thu, 21 Apr 2022 10:20:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650529202; 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=CJpkOVHhaqh2IozgOfRLvbwZs4CDxn9aMJPO1Hs5b9I=; b=JpE7U3+8BaOIf+4c90sLmz+pdtbD9jM3RUBvvTnSXzR9/tnfTgiG+BibJrePNCEfvLDTBt AZzWzCNFs58cQbF+im/iV5rXI2oJrjtnPSTdYHdV1xdVeMszhn/awWwdA2Pjpg+lry1foe qVxJXPtki2pnSIe8KUgBb0gHk1ubjWQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-230-gZKZcVhfOUmrn-sxhKK_6w-1; Thu, 21 Apr 2022 04:19:58 -0400 X-MC-Unique: gZKZcVhfOUmrn-sxhKK_6w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31CD01014A61; Thu, 21 Apr 2022 08:19:58 +0000 (UTC) Received: from [10.39.208.35] (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 461987C4E; Thu, 21 Apr 2022 08:19:57 +0000 (UTC) Message-ID: Date: Thu, 21 Apr 2022 10:19:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v2 6/7] vdpa/mlx5: support device cleanup callback To: Xueming Li , dev@dpdk.org Cc: Matan Azrad , Viacheslav Ovsiienko References: <20220224132820.1939650-1-xuemingl@nvidia.com> <20220224155101.1991626-1-xuemingl@nvidia.com> <20220224155101.1991626-7-xuemingl@nvidia.com> From: Maxime Coquelin In-Reply-To: <20220224155101.1991626-7-xuemingl@nvidia.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 2/24/22 16:51, Xueming Li wrote: > This patch supports device cleanup callback API which called when device > disconnected with VM. "This patch supports device cleanup callback API which is called when the device is disconnected from the VM." > Cached resources like VM MR and VQ memory are > released. > > Signed-off-by: Xueming Li > --- > drivers/vdpa/mlx5/mlx5_vdpa.c | 23 +++++++++++++++++++++++ > drivers/vdpa/mlx5/mlx5_vdpa.h | 1 + > 2 files changed, 24 insertions(+) > > diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c > index 38ed45f95f7..47874c9b1ff 100644 > --- a/drivers/vdpa/mlx5/mlx5_vdpa.c > +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c > @@ -270,6 +270,8 @@ mlx5_vdpa_dev_close(int vid) > if (priv->lm_mr.addr) > mlx5_os_wrapped_mkey_destroy(&priv->lm_mr); > priv->state = MLX5_VDPA_STATE_PROBED; > + if (!priv->connected) > + mlx5_vdpa_dev_cache_clean(priv); > priv->vid = 0; > /* The mutex may stay locked after event thread cancel - initiate it. */ > pthread_mutex_init(&priv->vq_config_lock, NULL); > @@ -294,6 +296,7 @@ mlx5_vdpa_dev_config(int vid) > return -1; > } > priv->vid = vid; > + priv->connected = true; > if (mlx5_vdpa_mtu_set(priv)) > DRV_LOG(WARNING, "MTU cannot be set on device %s.", > vdev->device->name); > @@ -431,12 +434,32 @@ mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid) > return mlx5_vdpa_virtq_stats_reset(priv, qid); > } > > +static int > +mlx5_vdpa_dev_clean(int vid) mlx5_vdpa_dev_cleanup > +{ > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > + struct mlx5_vdpa_priv *priv; > + > + if (vdev == NULL) > + return -1; > + priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); > + if (priv == NULL) { > + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); > + return -1; > + } > + if (priv->state == MLX5_VDPA_STATE_PROBED) > + mlx5_vdpa_dev_cache_clean(priv); > + priv->connected = false; > + return 0; > +} > + > static struct rte_vdpa_dev_ops mlx5_vdpa_ops = { > .get_queue_num = mlx5_vdpa_get_queue_num, > .get_features = mlx5_vdpa_get_vdpa_features, > .get_protocol_features = mlx5_vdpa_get_protocol_features, > .dev_conf = mlx5_vdpa_dev_config, > .dev_close = mlx5_vdpa_dev_close, > + .dev_cleanup = mlx5_vdpa_dev_clean, > .set_vring_state = mlx5_vdpa_set_vring_state, > .set_features = mlx5_vdpa_features_set, > .migration_done = NULL, > diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h > index 540bf87a352..24bafe85b44 100644 > --- a/drivers/vdpa/mlx5/mlx5_vdpa.h > +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h > @@ -121,6 +121,7 @@ enum mlx5_dev_state { > > struct mlx5_vdpa_priv { > TAILQ_ENTRY(mlx5_vdpa_priv) next; > + bool connected; > enum mlx5_dev_state state; > pthread_mutex_t vq_config_lock; > uint64_t no_traffic_counter; Other then that: Reviewed-by: Maxime Coquelin Thanks, Maxime