From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9490C5517A for ; Thu, 12 Nov 2020 06:40:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95B562100A for ; Thu, 12 Nov 2020 06:40:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="cEorBUDR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726319AbgKLGkh (ORCPT ); Thu, 12 Nov 2020 01:40:37 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:15476 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgKLGkc (ORCPT ); Thu, 12 Nov 2020 01:40:32 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 11 Nov 2020 22:40:26 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 12 Nov 2020 06:40:31 +0000 From: Parav Pandit To: CC: , , , , Subject: [PATCH 3/7] vdpa: Extend routine to accept vdpa device name Date: Thu, 12 Nov 2020 08:40:01 +0200 Message-ID: <20201112064005.349268-4-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201112064005.349268-1-parav@nvidia.com> References: <20201112064005.349268-1-parav@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1605163226; bh=1Lj3uhvlUAqek+U0OdG3uZU0WHYgkHYKA+te4VxyX1E=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=cEorBUDR3PYSlNlGuqprm/ZQA+sNHw6jvxe2MPOXD8048lm87mGGTavVjF84lwzVP E05iOwzIWDbutAuK6qR5rlmBdcmai5D3kBd+k9jeaeeHHiALHG5iiiA3l9cDEuOoWL LG/zYST3ul1ErB6tn9VBZGqysBT5ONPH5ieA9ZQ8Rnwz7ZIyLyZNy5ksdmCoe5kz5h AikyuODijgWo7jVhCEJ8FNKkkjq67vaGSnFmSF85PTjInBkXt88vESuZ2jJhoZWMwG 9SB2OBcUmO6Slzjbf7huP+E6wxEfwYfWlj1r9vD/VGoDIfcb3m9oJyeQyoMc41yJ/5 yCcnI6d0TyBiw== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In a subsequent patch, when user initiated command creates a vdpa device, the user chooses the name of the vdpa device. To support it, extend the device allocation API to consider this name specified by the caller driver. Split the device unregistration to device delete and device put so that device can be removed from the list after its deleted. Signed-off-by: Parav Pandit Reviewed-by: Eli Cohen Acked-by: Jason Wang --- drivers/vdpa/ifcvf/ifcvf_main.c | 2 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- drivers/vdpa/vdpa.c | 36 +++++++++++++++++++++++++++---- drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- include/linux/vdpa.h | 7 +++--- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_mai= n.c index 8b4028556cb6..23474af7da40 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -439,7 +439,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const stru= ct pci_device_id *id) =20 adapter =3D vdpa_alloc_device(struct ifcvf_adapter, vdpa, dev, &ifc_vdpa_ops, - IFCVF_MAX_QUEUE_PAIRS * 2); + IFCVF_MAX_QUEUE_PAIRS * 2, NULL); if (adapter =3D=3D NULL) { IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); return -ENOMEM; diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 5316e51e72d4..cf9fc51071c8 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1958,7 +1958,7 @@ static int mlx5v_probe(struct auxiliary_device *adev, max_vqs =3D min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS); =20 ndev =3D vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device= , &mlx5_vdpa_ops, - 2 * mlx5_vdpa_max_qps(max_vqs)); + 2 * mlx5_vdpa_max_qps(max_vqs), NULL); if (IS_ERR(ndev)) return PTR_ERR(ndev); =20 diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index c0825650c055..3c9cade05233 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -12,6 +12,8 @@ #include #include =20 +/* A global mutex that protects vdpa parent and device level operations. *= / +static DEFINE_MUTEX(vdpa_dev_mutex); static DEFINE_IDA(vdpa_index_ida); =20 static int vdpa_dev_probe(struct device *d) @@ -63,6 +65,7 @@ static void vdpa_release_dev(struct device *d) * @config: the bus operations that is supported by this device * @nvqs: number of virtqueues supported by this device * @size: size of the parent structure that contains private data + * @name: name of the vdpa device; optional. * * Driver should use vdpa_alloc_device() wrapper macro instead of * using this directly. @@ -72,8 +75,7 @@ static void vdpa_release_dev(struct device *d) */ struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, - int nvqs, - size_t size) + int nvqs, size_t size, const char *name) { struct vdpa_device *vdev; int err =3D -EINVAL; @@ -101,7 +103,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device = *parent, vdev->features_valid =3D false; vdev->nvqs =3D nvqs; =20 - err =3D dev_set_name(&vdev->dev, "vdpa%u", vdev->index); + if (name) + err =3D dev_set_name(&vdev->dev, "%s", name); + else + err =3D dev_set_name(&vdev->dev, "vdpa%u", vdev->index); if (err) goto err_name; =20 @@ -118,6 +123,13 @@ struct vdpa_device *__vdpa_alloc_device(struct device = *parent, } EXPORT_SYMBOL_GPL(__vdpa_alloc_device); =20 +static int vdpa_name_match(struct device *dev, const void *data) +{ + struct vdpa_device *vdev =3D container_of(dev, struct vdpa_device, dev); + + return (strcmp(dev_name(&vdev->dev), data) =3D=3D 0); +} + /** * vdpa_register_device - register a vDPA device * Callers must have a succeed call of vdpa_alloc_device() before. @@ -127,7 +139,21 @@ EXPORT_SYMBOL_GPL(__vdpa_alloc_device); */ int vdpa_register_device(struct vdpa_device *vdev) { - return device_add(&vdev->dev); + struct device *dev; + int err; + + mutex_lock(&vdpa_dev_mutex); + dev =3D bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_= match); + if (dev) { + put_device(dev); + err =3D -EEXIST; + goto name_err; + } + + err =3D device_add(&vdev->dev); +name_err: + mutex_unlock(&vdpa_dev_mutex); + return err; } EXPORT_SYMBOL_GPL(vdpa_register_device); =20 @@ -137,7 +163,9 @@ EXPORT_SYMBOL_GPL(vdpa_register_device); */ void vdpa_unregister_device(struct vdpa_device *vdev) { + mutex_lock(&vdpa_dev_mutex); device_unregister(&vdev->dev); + mutex_unlock(&vdpa_dev_mutex); } EXPORT_SYMBOL_GPL(vdpa_unregister_device); =20 diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 6a90fdb9cbfc..aed1bb7770ab 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -357,7 +357,7 @@ static struct vdpasim *vdpasim_create(void) else ops =3D &vdpasim_net_config_ops; =20 - vdpasim =3D vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ= _NUM); + vdpasim =3D vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ= _NUM, NULL); if (!vdpasim) goto err_alloc; =20 diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 0fefeb976877..5700baa22356 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -245,15 +245,14 @@ struct vdpa_config_ops { =20 struct vdpa_device *__vdpa_alloc_device(struct device *parent, const struct vdpa_config_ops *config, - int nvqs, - size_t size); + int nvqs, size_t size, const char *name); =20 -#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs) \ +#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs, name) = \ container_of(__vdpa_alloc_device( \ parent, config, nvqs, \ sizeof(dev_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ - dev_struct, member))), \ + dev_struct, member)), name), \ dev_struct, member) =20 int vdpa_register_device(struct vdpa_device *vdev); --=20 2.26.2