From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10083.outbound.protection.outlook.com [40.107.1.83]) by dpdk.org (Postfix) with ESMTP id 0FF961C0B for ; Tue, 22 May 2018 14:08:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v5C5JoFZQWJzjbX8PPRz1NMLh0/RQDZXbSfEYxNciDA=; b=pVyzFY3PvlUY5E6WpFo+dnRWX4sBHmIHFqf0qjV5LULRjSAdvEqi1HTbYsNW5dQRVwZxiQpae2dNrgMIrmDoAFPH967PE6CUQfdSYNDMcaI8Ug+ohW8OVAw18QLvCNcGw9HuisjcSe1ZjAPR5lRtNngZxnl/fgh4qFisT1EQDSA= Received: from VI1PR0501MB2608.eurprd05.prod.outlook.com (10.168.137.20) by VI1PR0501MB1966.eurprd05.prod.outlook.com (10.166.45.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 12:08:55 +0000 Received: from VI1PR0501MB2608.eurprd05.prod.outlook.com ([fe80::1035:58f9:b94c:2180]) by VI1PR0501MB2608.eurprd05.prod.outlook.com ([fe80::1035:58f9:b94c:2180%18]) with mapi id 15.20.0776.015; Tue, 22 May 2018 12:08:55 +0000 From: Matan Azrad To: Thomas Monjalon , "dev@dpdk.org" CC: "ferruh.yigit@intel.com" , "anatoly.burakov@intel.com" , "gaetan.rivet@6wind.com" Thread-Topic: [PATCH v3] bus/vdev: replace device list lock by a recursive one Thread-Index: AQHT8cFK8TkGJv+QpU2mloRP8vcstaQ7p6PQ Date: Tue, 22 May 2018 12:08:55 +0000 Message-ID: References: <2833093.uzJjkH71XI@xps> <20180522113727.3116-1-thomas@monjalon.net> In-Reply-To: <20180522113727.3116-1-thomas@monjalon.net> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR0501MB1966; 7:7wv2AoljdKCQ5fThjtFxiA+IPDli4ZR/Ib3/nh0FP0gmAFrk+HrasKTLilfVyUxURsYqCxuNBfMySkXSqxI1/eYoeTEGQFVK0yrlz0oUkLDzjSwKY5STbHdTWlRWjY8diDNgnrZY0+3ihJeyqh/79iyTVYFxX+u3cjjXii7A6LsSIMjpXJKy3CD9mreUENEEeUjGqLdbXSe1EtNa5K9HGpQFE5KWE0k1Xz55CvveVTxtl17qFwWbe2RQ1pa5Nxyv x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB1966; x-ms-traffictypediagnostic: VI1PR0501MB1966: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(788757137089)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:VI1PR0501MB1966; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB1966; x-forefront-prvs: 0680FADD48 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(346002)(39380400002)(366004)(396003)(199004)(189003)(54906003)(9686003)(86362001)(3846002)(7736002)(6116002)(8676002)(486006)(81156014)(81166006)(6506007)(2906002)(59450400001)(25786009)(106356001)(66066001)(102836004)(7696005)(105586002)(76176011)(99286004)(305945005)(55016002)(33656002)(53936002)(110136005)(97736004)(11346002)(476003)(6436002)(446003)(68736007)(8936002)(316002)(229853002)(4326008)(5660300001)(14454004)(3660700001)(74316002)(6246003)(2900100001)(186003)(2501003)(3280700002)(5250100002)(478600001)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB1966; H:VI1PR0501MB2608.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 8x91MYqFl9Qprn5GYdjJN7GZkoUGaoXQZP7J7mGDY98zWbwZ2TiouGwgUXyuDBNtlYx54URDOIoVIT2GmBqJhP+dTzW+wfv7WOVB8Onvvd+RBiDlWR9RWrVOJ1mf1i1HNiZQm3TPqvUlGNQHqNBNgH0NG65LB/Q41y389Nja/slZ6ouyGrEdPxy0v9+DpOFt spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 06296dc8-245a-4a30-2baa-08d5bfdccaa1 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06296dc8-245a-4a30-2baa-08d5bfdccaa1 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2018 12:08:55.4969 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB1966 Subject: Re: [dpdk-dev] [PATCH v3] bus/vdev: replace device list lock by a recursive one X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2018 12:08:57 -0000 From: Thomas Monjalon > A device like failsafe can manage sub-devices. > When removing such device, it removes its sub-devices and try to take the > same vdev_device_list_lock. > It was causing a deadlock because the lock was not recursive. >=20 > Fixes: 35f462839b69 ("bus/vdev: add lock on device list") >=20 > Suggested-by: Anatoly Burakov > Signed-off-by: Thomas Monjalon Tested-by: Matan Azrad > --- > v3: try recursive lock > WARNING: not yet tested! > --- > drivers/bus/vdev/vdev.c | 26 ++++++++++++++------------ > 1 file changed, 14 insertions(+), 12 deletions(-) >=20 > diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index > 099b9ff85..6139dd551 100644 > --- a/drivers/bus/vdev/vdev.c > +++ b/drivers/bus/vdev/vdev.c > @@ -36,7 +36,9 @@ TAILQ_HEAD(vdev_device_list, rte_vdev_device); >=20 > static struct vdev_device_list vdev_device_list =3D > TAILQ_HEAD_INITIALIZER(vdev_device_list); > -static rte_spinlock_t vdev_device_list_lock =3D RTE_SPINLOCK_INITIALIZER= ; > +/* The lock needs to be recursive because a vdev can manage another > +vdev. */ static rte_spinlock_recursive_t vdev_device_list_lock =3D > + RTE_SPINLOCK_RECURSIVE_INITIALIZER; >=20 > struct vdev_driver_list vdev_driver_list =3D > TAILQ_HEAD_INITIALIZER(vdev_driver_list); > @@ -249,7 +251,7 @@ rte_vdev_init(const char *name, const char *args) > struct rte_devargs *devargs; > int ret; >=20 > - rte_spinlock_lock(&vdev_device_list_lock); > + rte_spinlock_recursive_lock(&vdev_device_list_lock); > ret =3D insert_vdev(name, args, &dev); > if (ret =3D=3D 0) { > ret =3D vdev_probe_all_drivers(dev); > @@ -263,7 +265,7 @@ rte_vdev_init(const char *name, const char *args) > free(dev); > } > } > - rte_spinlock_unlock(&vdev_device_list_lock); > + rte_spinlock_recursive_unlock(&vdev_device_list_lock); > return ret; > } >=20 > @@ -293,7 +295,7 @@ rte_vdev_uninit(const char *name) > if (name =3D=3D NULL) > return -EINVAL; >=20 > - rte_spinlock_lock(&vdev_device_list_lock); > + rte_spinlock_recursive_lock(&vdev_device_list_lock); >=20 > dev =3D find_vdev(name); > if (!dev) { > @@ -311,7 +313,7 @@ rte_vdev_uninit(const char *name) > free(dev); >=20 > unlock: > - rte_spinlock_unlock(&vdev_device_list_lock); > + rte_spinlock_recursive_unlock(&vdev_device_list_lock); > return ret; > } >=20 > @@ -355,7 +357,7 @@ vdev_action(const struct rte_mp_msg *mp_msg, const > void *peer) > ou->num =3D 1; > num =3D 0; >=20 > - rte_spinlock_lock(&vdev_device_list_lock); > + rte_spinlock_recursive_lock(&vdev_device_list_lock); > TAILQ_FOREACH(dev, &vdev_device_list, next) { > devname =3D rte_vdev_device_name(dev); > if (strlen(devname) =3D=3D 0) { > @@ -369,7 +371,7 @@ vdev_action(const struct rte_mp_msg *mp_msg, const > void *peer) > devname, strerror(rte_errno)); > num++; > } > - rte_spinlock_unlock(&vdev_device_list_lock); > + rte_spinlock_recursive_unlock(&vdev_device_list_lock); >=20 > ou->type =3D VDEV_SCAN_REP; > ou->num =3D num; > @@ -445,10 +447,10 @@ vdev_scan(void) > if (!dev) > return -1; >=20 > - rte_spinlock_lock(&vdev_device_list_lock); > + rte_spinlock_recursive_lock(&vdev_device_list_lock); >=20 > if (find_vdev(devargs->name)) { > - rte_spinlock_unlock(&vdev_device_list_lock); > + > rte_spinlock_recursive_unlock(&vdev_device_list_lock); > free(dev); > continue; > } > @@ -459,7 +461,7 @@ vdev_scan(void) >=20 > TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); >=20 > - rte_spinlock_unlock(&vdev_device_list_lock); > + rte_spinlock_recursive_unlock(&vdev_device_list_lock); > } >=20 > return 0; > @@ -498,7 +500,7 @@ vdev_find_device(const struct rte_device *start, > rte_dev_cmp_t cmp, > const struct rte_vdev_device *vstart; > struct rte_vdev_device *dev; >=20 > - rte_spinlock_lock(&vdev_device_list_lock); > + rte_spinlock_recursive_lock(&vdev_device_list_lock); > if (start !=3D NULL) { > vstart =3D RTE_DEV_TO_VDEV_CONST(start); > dev =3D TAILQ_NEXT(vstart, next); > @@ -510,7 +512,7 @@ vdev_find_device(const struct rte_device *start, > rte_dev_cmp_t cmp, > break; > dev =3D TAILQ_NEXT(dev, next); > } > - rte_spinlock_unlock(&vdev_device_list_lock); > + rte_spinlock_recursive_unlock(&vdev_device_list_lock); >=20 > return dev ? &dev->device : NULL; > } > -- > 2.16.2