From nobody Mon Feb 9 13:23:33 2026 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5493E22638 for ; Mon, 12 Aug 2024 01:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723426980; cv=none; b=QDO+fqj7f2bHwK5RnsfafVaW092oajWSOrNEPDx6HkQGhCsZKHOA++YzJGcZ7OoisEc0RgDihzSgzAYxSu78lc7wcueOdhLNTgLm2ZwmsDZbGVCLKZk6w/CucHkc2k09hb4IcwKoAq2eOvtKKx758XV72L4zI5ThESrWiW+3Z8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723426980; c=relaxed/simple; bh=PYQ1jIab+DAWLIEOngr/G0WZ+P2lmVZYoE01Sx8SjiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dp/Oc7xskv0aZe4+uYHsgfCFGwTa0Y59Tsgm0DdKRWEZp4CNGGH/dUFsZMcoZZgfxGd5hDHWdB7AvkiAYAmghDIQIQMqvo1n2JDEyIG9op/3c6jK84Q/CEhlximflec5vBuIUTM5btqscLotlD8jPRa6jwpXBsdhHlw+G83SURs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=Ftb8xj+f; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EuK/Fy7o; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Ftb8xj+f"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EuK/Fy7o" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 4C4A0138CCB0; Sun, 11 Aug 2024 21:42:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 11 Aug 2024 21:42:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1723426977; x= 1723513377; bh=d+Q8xmS6L9yVQUeDWKp7OwnnCRhmxeh/w4QcD6dPneg=; b=F tb8xj+fz5gAeltKKXo71CJsgc+Eer0cl1tywhxKkb0CAYWR807qrZKgfW+nHWCLt AGi4rZ0l/L/mXNuhqsSr9F4KNShGCAvc7sqhvjgj2evZtoyKYtl39UHkrsIuK3Sh jcixFH4wQX2pbwAtHgKTc8rp13ssZa/9u+J6kFSl8BweTMLITDZrD5F51akCGe0q 5O5EnyEDkvu7rPkFcbjSHe4mfwoZyTctCDkGXGFkFpw6BUxSAnSO/awvoMEYkysv rLEjfmlSVjzWw+5JRrDJPFvFbPThHZ8lxksKrX+4eUZSvhiewDJNOWkvHm5BXN0i SYTFdE/JqYspkvAYg+Etg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1723426977; x= 1723513377; bh=d+Q8xmS6L9yVQUeDWKp7OwnnCRhmxeh/w4QcD6dPneg=; b=E uK/Fy7oAqLdKpnJtwbXlrqXII2WB3HfG01D9L2K03df3z4/1mPZKYjpV+bM/EPNf /0DJqqFwoJy11O3tlexCIeJ4X/he/W/91KGjLizR4eC6WQ0vOFle4cNw8NMOS/YK f+c9cjK+ZGkR78pQNOciTZYBtXxToF+UePSInzZ8TaN2/OAMxu0aO9o2mWGBRjW3 Yf5/Z34rHCf/SfwfRrXDEtv4jrSho34AtXZnP5wuYxqAQXEuQUXBCtO9O8EK1ffz cgLwf/xDF+rTHguWO5m+9BQTJ/C/eLfrcsr+y9PdKAL1wlTYjeajM9Q1ULM7ZqJb oR1UjDKoCf0ba/5KOccOw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrleelgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefuff fkofgjfhgggfestdekredtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhho thhouceoohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrth htvghrnhepvdejgfejuedvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffek vddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepoh dqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtohepvddp mhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidufeelgedquggvvhgvlh eslhhishhtshdrshhouhhrtggvfhhorhhgvgdrnhgvthdprhgtphhtthhopehlihhnuhig qdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 11 Aug 2024 21:42:56 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] firewire: core: replace IDR with XArray to maintain fw_device Date: Mon, 12 Aug 2024 10:42:50 +0900 Message-ID: <20240812014251.165492-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812014251.165492-1-o-takashi@sakamocchi.jp> References: <20240812014251.165492-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In core function, the instances of fw_device corresponding to firewire devi= ce node in system are maintained by IDR. As of kernel v6.0, IDR has been superseded by XArray and deprecated. This commit replaces the usage of IDR with XArray to maintain the device instances. The instance of XArray is allocated statically, and initialized with XA_FLAGS_ALLOC so that the index of allocated entry starts with zero and available as the minor identifier of device node. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-device.c | 21 +++++++++++---------- drivers/firewire/core-transaction.c | 3 +-- drivers/firewire/core.h | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index bec7e05f6ab8..9f3276aa463a 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -813,7 +812,7 @@ static int shutdown_unit(struct device *device, void *d= ata) */ DECLARE_RWSEM(fw_device_rwsem); =20 -DEFINE_IDR(fw_device_idr); +DEFINE_XARRAY_ALLOC(fw_device_xa); int fw_cdev_major; =20 struct fw_device *fw_device_get_by_devt(dev_t devt) @@ -822,7 +821,7 @@ struct fw_device *fw_device_get_by_devt(dev_t devt) =20 guard(rwsem_read)(&fw_device_rwsem); =20 - device =3D idr_find(&fw_device_idr, MINOR(devt)); + device =3D xa_load(&fw_device_xa, MINOR(devt)); if (device) fw_device_get(device); =20 @@ -858,7 +857,6 @@ static void fw_device_shutdown(struct work_struct *work) { struct fw_device *device =3D container_of(work, struct fw_device, work.work); - int minor =3D MINOR(device->device.devt); =20 if (time_before64(get_jiffies_64(), device->card->reset_jiffies + SHUTDOWN_DELAY) @@ -877,7 +875,7 @@ static void fw_device_shutdown(struct work_struct *work) device_unregister(&device->device); =20 scoped_guard(rwsem_write, &fw_device_rwsem) - idr_remove(&fw_device_idr, minor); + xa_erase(&fw_device_xa, MINOR(device->device.devt)); =20 fw_device_put(device); } @@ -1049,7 +1047,8 @@ static void fw_device_init(struct work_struct *work) container_of(work, struct fw_device, work.work); struct fw_card *card =3D device->card; struct device *revived_dev; - int minor, ret; + u32 minor; + int ret; =20 /* * All failure paths here set node->data to NULL, so that we @@ -1087,9 +1086,11 @@ static void fw_device_init(struct work_struct *work) device_initialize(&device->device); =20 fw_device_get(device); + scoped_guard(rwsem_write, &fw_device_rwsem) { - minor =3D idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, GFP_KERNE= L); - if (minor < 0) + // The index of allocated entry is used for minor identifier of device n= ode. + ret =3D xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), = GFP_KERNEL); + if (ret < 0) goto error; } =20 @@ -1152,9 +1153,9 @@ static void fw_device_init(struct work_struct *work) =20 error_with_cdev: scoped_guard(rwsem_write, &fw_device_rwsem) - idr_remove(&fw_device_idr, minor); + xa_erase(&fw_device_xa, minor); error: - fw_device_put(device); /* fw_device_idr's reference */ + fw_device_put(device); // fw_device_xa's reference. =20 put_device(&device->device); /* our reference */ } diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index 14af84541e83..e141d24a7644 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -1359,7 +1358,7 @@ static void __exit fw_core_cleanup(void) unregister_chrdev(fw_cdev_major, "firewire"); bus_unregister(&fw_bus_type); destroy_workqueue(fw_workqueue); - idr_destroy(&fw_device_idr); + xa_destroy(&fw_device_xa); } =20 module_init(fw_core_init); diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 189e15e6ba82..8cace026090c 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -133,7 +134,7 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, st= ruct fw_packet *p); /* -device */ =20 extern struct rw_semaphore fw_device_rwsem; -extern struct idr fw_device_idr; +extern struct xarray fw_device_xa; extern int fw_cdev_major; =20 static inline struct fw_device *fw_device_get(struct fw_device *device) --=20 2.43.0 From nobody Mon Feb 9 13:23:33 2026 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83BD5482DB for ; Mon, 12 Aug 2024 01:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723426981; cv=none; b=OAtDgEToR21RwC1CR6zWe3W9rrlFj4ohuSXx0048mbgFvRWgwYX4hKegrrWZxGKni5x23GuRFz3x97a+6SL76ScK0H7gdHU5TEOCPRtsjUeR/OGkk57p0XLZwtwesxU0M4th6u5HskoVUCqkvcod7op4iCrlUaPAUUz26Jm6/bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723426981; c=relaxed/simple; bh=TpYQD071S1KYSOCy8p4Xq+KnhZa0VI3Yd7ChhcLowQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jweGqOPwn6/enbVpZKHkgnwWmMXiFd/UJmrrURjr6RbBBxTzlpZcYAgfXiNJe5gI7rSLPQXbbGZ4BTYNVTPnNWfT7BudJ80c4v0wcjK+D82sZRZFqCG0K64n+OC3PXzOEFx24Doi6dXZ1O0dA7MCVWQ1kkLwHQp0VSEF39EQpK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=S856z2uj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sOX8uFj9; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="S856z2uj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sOX8uFj9" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 955AD138CD52; Sun, 11 Aug 2024 21:42:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 11 Aug 2024 21:42:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1723426978; x= 1723513378; bh=losiMWDobhTks5tA1JStZawdF4CWd89Wr88BY0X0J1I=; b=S 856z2ujthWfeYklekkjlx4LFhUWDfY9dFo4sjr9oFyDNhHzuHQT0obhKuipSSOf2 yRngsinvk6+x6Y4FM6zcf8R/UQVF3mk4j+IFxFwalVjzU4CEdd1QdWklaeZBFE2q +iuuPocxPHYXjkCijVTlaTXJ/zTD7U/azmRQwrFUfpDRbs61PWuY7T/jMuKUb9G0 sxEGaErkNkQKBnIpwIZkiQcLq2mlsaTdTiP0ngWc0SIMy7DeBT/b4rf80WrRvJv8 aKWn2wZnE+qEFyFIJAjNtoVqct/2eAgdJ7Im8PE9IYT633rhV5hBYMloo/+7FLdH q09l/y3dXfL3iNpwAoonw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1723426978; x= 1723513378; bh=losiMWDobhTks5tA1JStZawdF4CWd89Wr88BY0X0J1I=; b=s OX8uFj9c3FMexS4a0P6Ju4eFPhBgIkojEOXkQX2r8kosbSPVuNIXkdAGnXNAdAhr MjHDUd/q3v+v6R6vmxzP2C8TQfIEuWaYneMWoSnDywirhXr/hdkO1ZxjtJ7aqmRs f3lvxifm6WjYptGzE+SQj7L+0EywXEXPjQ28KbOrcTdiCFB8/24O/biRznMTEBhr izV9b3+yjNLP+uXexF41L2Cx4wvbvJxkuRTzBWhjca+pGSYbERiNDUrY+xWAJPcH 5iGPQRYKfvWUICDN0EjyO7k9iHZZRi7F8TldBEcKRbNRpR9bh3YKl0NugcutPpVH e50ZQgLyb0fh6QsHXZiTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrleelgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefuff fkofgjfhgggfestdekredtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhho thhouceoohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrth htvghrnhepvdejgfejuedvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffek vddtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepoh dqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtohepvddp mhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidufeelgedquggvvhgvlh eslhhishhtshdrshhouhhrtggvfhhorhhgvgdrnhgvthdprhgtphhtthhopehlihhnuhig qdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 11 Aug 2024 21:42:57 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] firewire: core: use lock in Xarray instead of local R/W semaphore Date: Mon, 12 Aug 2024 10:42:51 +0900 Message-ID: <20240812014251.165492-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812014251.165492-1-o-takashi@sakamocchi.jp> References: <20240812014251.165492-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The data of XArray structure includes spinlock and requires no external lock, while the data is still under the critical section by fw_device_rwsem. This commit deletes the critical section. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-device.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 9f3276aa463a..32ac0f115793 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -806,7 +806,6 @@ static int shutdown_unit(struct device *device, void *d= ata) =20 /* * fw_device_rwsem acts as dual purpose mutex: - * - serializes accesses to fw_device_idr, * - serializes accesses to fw_device.config_rom/.config_rom_length and * fw_unit.directory, unless those accesses happen at safe occasions */ @@ -819,8 +818,6 @@ struct fw_device *fw_device_get_by_devt(dev_t devt) { struct fw_device *device; =20 - guard(rwsem_read)(&fw_device_rwsem); - device =3D xa_load(&fw_device_xa, MINOR(devt)); if (device) fw_device_get(device); @@ -874,8 +871,7 @@ static void fw_device_shutdown(struct work_struct *work) device_for_each_child(&device->device, NULL, shutdown_unit); device_unregister(&device->device); =20 - scoped_guard(rwsem_write, &fw_device_rwsem) - xa_erase(&fw_device_xa, MINOR(device->device.devt)); + xa_erase(&fw_device_xa, MINOR(device->device.devt)); =20 fw_device_put(device); } @@ -1087,12 +1083,10 @@ static void fw_device_init(struct work_struct *work) =20 fw_device_get(device); =20 - scoped_guard(rwsem_write, &fw_device_rwsem) { - // The index of allocated entry is used for minor identifier of device n= ode. - ret =3D xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), = GFP_KERNEL); - if (ret < 0) - goto error; - } + // The index of allocated entry is used for minor identifier of device no= de. + ret =3D xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), G= FP_KERNEL); + if (ret < 0) + goto error; =20 device->device.bus =3D &fw_bus_type; device->device.type =3D &fw_device_type; @@ -1152,8 +1146,7 @@ static void fw_device_init(struct work_struct *work) return; =20 error_with_cdev: - scoped_guard(rwsem_write, &fw_device_rwsem) - xa_erase(&fw_device_xa, minor); + xa_erase(&fw_device_xa, minor); error: fw_device_put(device); // fw_device_xa's reference. =20 --=20 2.43.0