From nobody Tue Feb 10 09:57:10 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 0392819ADBB for ; Mon, 12 Aug 2024 23:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506743; cv=none; b=bwflAse7SfkMFQHHO3k2yqDqygO1OKTSAnm8fFe8soyKCYrIF6J4G1a/gztDSa55zn9lYSAcJ6MIma0wM9xsM3HEyOKI1w66bwZwTYrZt7UFSx9hioTrefD3XQLIK1t18yw7aMqq7cMhf0ONNno/i8cd+2+IfWamb8eqkaEBPe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506743; c=relaxed/simple; bh=kohYd9tWqkktZ/r6GCVdidIRPztYnRzPFgJogqa383E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N2QN6HxUrWEkTfc9k6vNDTN9Bb4QrfjqhHD3IGVsTp93z6AbNC0b5W3nPojYYZ5RdmjpTK1wBgfx3ymt57TFUIkCgqWsOgKwBQVpP4eOrhMbmbnWhrfFKCdX6pBWEhv5A5OjVyHr6onTSAasXZYsniL2YGA5/Zks30Sq41h1b54= 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=Yj+NBlbM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tgMS1M/1; arc=none smtp.client-ip=103.168.172.159 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="Yj+NBlbM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tgMS1M/1" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1BE981151B66; Mon, 12 Aug 2024 19:52:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 12 Aug 2024 19:52:20 -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=1723506740; x= 1723593140; bh=AGCPcXuZ+EA8kPdWP5AdSF60xmqg9P1trpkWAYoUGEs=; b=Y j+NBlbMicM5yraVen81NvyprMxGoB2u/JKxxtxNOoHzRjXV9h1Mr4OvjHyH3qma0 V+TmeOMeJ4VrTyfk0H736ioGrWIlwrCjwkaKYMlu2sdrlRVRsCWRQ+NRYEa15uNb x49iWoKdgOgpftVkrMc9IHLxSOD0NDbbRCQwK9VY5NQWtKHUxGac1wkG2k5zgWdd kKvHKWkUg1LiS/P67b6rPG3lLe7Taz83ys513En5lr1UvdP/Gag3O47+no1mvFF3 a5Hogz9jeRlCykTz3NdG6J9bldnhE4acBktxsQ6YDiHEnYs7Na83rDwoaBTfcX0g O2tWxuPdw26afeKQ9oM8w== 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=1723506740; x= 1723593140; bh=AGCPcXuZ+EA8kPdWP5AdSF60xmqg9P1trpkWAYoUGEs=; b=t gMS1M/1oZ3c+jAsRYbMdyJmoWXICDdDpneYCYRVOTgHspDK7D8RNq+hBvgmgNOoA Y00Nm1mlmWYSHcshavfR+xLbJWVbh3nkHNzy/nrFvHNxkHYKQarC0Rclau5alegQ KKWKwzKo4zgHpyh+DThHX6fV7jYqjrYcRswYcvOYvFu2KaK+uIKftcyJAuXM3OJK LhtPo72IRE/NWIiAgaVITF1yDCC8X9xneZCH+Par/+BIbP4NdAjWArMLk8pETytV 0VhEhuLNRU1ErizdKieHYgkwIR7uKyeE3L8TwDdwVCLOnm3T1gxQULtIuLKNc5wS wuTBimEve7o1o6I8CUnOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:18 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] firewire: core: use xarray instead of idr to maintain client resource Date: Tue, 13 Aug 2024 08:52:10 +0900 Message-ID: <20240812235210.28458-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-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 some client resource structures 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 resource instances. The instance of XArray is allocated per client with XA_FLAGS_ALLOC1 so that the index of allocated entry is greater than zero and returns to user space client as handle of the resource. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 66 +++++++++++++++++++----------------- drivers/firewire/core.h | 1 - 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 83d25327c1d3..3ea220d96c31 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -54,7 +53,7 @@ struct client { =20 spinlock_t lock; bool in_shutdown; - struct idr resource_idr; + struct xarray resource_xa; struct list_head event_list; wait_queue_head_t wait; wait_queue_head_t tx_flush_wait; @@ -297,7 +296,7 @@ static int fw_device_op_open(struct inode *inode, struc= t file *file) =20 client->device =3D device; spin_lock_init(&client->lock); - idr_init(&client->resource_idr); + xa_init_flags(&client->resource_xa, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH); INIT_LIST_HEAD(&client->event_list); init_waitqueue_head(&client->wait); init_waitqueue_head(&client->tx_flush_wait); @@ -407,7 +406,7 @@ static void queue_bus_reset_event(struct client *client) { struct bus_reset_event *e; struct client_resource *resource; - int id; + unsigned long index; =20 e =3D kzalloc(sizeof(*e), GFP_KERNEL); if (e =3D=3D NULL) @@ -420,7 +419,7 @@ static void queue_bus_reset_event(struct client *client) =20 guard(spinlock_irq)(&client->lock); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { if (is_iso_resource(resource)) schedule_iso_resource(to_iso_resource(resource), 0); } @@ -501,31 +500,33 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) return ret ? -EFAULT : 0; } =20 -static int add_client_resource(struct client *client, - struct client_resource *resource, gfp_t gfp_mask) +static int add_client_resource(struct client *client, struct client_resour= ce *resource, + gfp_t gfp_mask) { - bool preload =3D gfpflags_allow_blocking(gfp_mask); int ret; =20 - if (preload) - idr_preload(gfp_mask); - scoped_guard(spinlock_irqsave, &client->lock) { - if (client->in_shutdown) + u32 index; + + if (client->in_shutdown) { ret =3D -ECANCELED; - else - ret =3D idr_alloc(&client->resource_idr, resource, 0, 0, GFP_NOWAIT); + } else { + if (gfpflags_allow_blocking(gfp_mask)) { + ret =3D xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b, + GFP_NOWAIT); + } else { + ret =3D xa_alloc_bh(&client->resource_xa, &index, resource, + xa_limit_32b, GFP_NOWAIT); + } + } if (ret >=3D 0) { - resource->handle =3D ret; + resource->handle =3D index; client_get(client); if (is_iso_resource(resource)) schedule_iso_resource(to_iso_resource(resource), 0); } } =20 - if (preload) - idr_preload_end(); - return ret < 0 ? ret : 0; } =20 @@ -533,17 +534,18 @@ static int release_client_resource(struct client *cli= ent, u32 handle, client_resource_release_fn_t release, struct client_resource **return_resource) { + unsigned long index =3D handle; struct client_resource *resource; =20 scoped_guard(spinlock_irq, &client->lock) { if (client->in_shutdown) return -EINVAL; =20 - resource =3D idr_find(&client->resource_idr, handle); + resource =3D xa_load(&client->resource_xa, index); if (!resource || resource->release !=3D release) return -EINVAL; =20 - idr_remove(&client->resource_idr, handle); + xa_erase(&client->resource_xa, handle); } =20 if (return_resource) @@ -566,9 +568,10 @@ static void complete_transaction(struct fw_card *card,= int rcode, u32 request_ts { struct outbound_transaction_event *e =3D data; struct client *client =3D e->client; + unsigned long index =3D e->r.resource.handle; =20 scoped_guard(spinlock_irqsave, &client->lock) { - idr_remove(&client->resource_idr, e->r.resource.handle); + xa_erase(&client->resource_xa, index); if (client->in_shutdown) wake_up(&client->tx_flush_wait); } @@ -619,7 +622,7 @@ static void complete_transaction(struct fw_card *card, = int rcode, u32 request_ts break; } =20 - /* Drop the idr's reference */ + // Drop the xarray's reference. client_put(client); } =20 @@ -1317,6 +1320,7 @@ static void iso_resource_work(struct work_struct *wor= k) struct iso_resource *r =3D container_of(work, struct iso_resource, work.work); struct client *client =3D r->client; + unsigned long index =3D r->resource.handle; int generation, channel, bandwidth, todo; bool skip, free, success; =20 @@ -1351,7 +1355,7 @@ static void iso_resource_work(struct work_struct *wor= k) todo =3D=3D ISO_RES_ALLOC_ONCE); /* * Is this generation outdated already? As long as this resource sticks - * in the idr, it will be scheduled again for a newer generation or at + * in the xarray, it will be scheduled again for a newer generation or at * shutdown. */ if (channel =3D=3D -EAGAIN && @@ -1366,10 +1370,10 @@ static void iso_resource_work(struct work_struct *w= ork) if (r->todo =3D=3D ISO_RES_ALLOC) r->todo =3D ISO_RES_REALLOC; // Allocation or reallocation failure? Pull this resource out of the - // idr and prepare for deletion, unless the client is shutting down. + // xarray and prepare for deletion, unless the client is shutting down. if (r->todo =3D=3D ISO_RES_REALLOC && !success && !client->in_shutdown && - idr_remove(&client->resource_idr, r->resource.handle)) { + xa_erase(&client->resource_xa, index)) { client_put(client); free =3D true; } @@ -1839,11 +1843,11 @@ static int fw_device_op_mmap(struct file *file, str= uct vm_area_struct *vma) static bool has_outbound_transactions(struct client *client) { struct client_resource *resource; - int id; + unsigned long index; =20 guard(spinlock_irq)(&client->lock); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { if (is_outbound_transaction_resource(resource)) return true; } @@ -1856,7 +1860,7 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) struct client *client =3D file->private_data; struct event *event, *next_event; struct client_resource *resource; - int id; + unsigned long index; =20 scoped_guard(spinlock_irq, &client->device->card->lock) list_del(&client->phy_receiver_link); @@ -1870,17 +1874,17 @@ static int fw_device_op_release(struct inode *inode= , struct file *file) if (client->buffer.pages) fw_iso_buffer_destroy(&client->buffer, client->device->card); =20 - /* Freeze client->resource_idr and client->event_list */ + // Freeze client->resource_xa and client->event_list. scoped_guard(spinlock_irq, &client->lock) client->in_shutdown =3D true; =20 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { resource->release(client, resource); client_put(client); } - idr_destroy(&client->resource_idr); + xa_destroy(&client->resource_xa); =20 list_for_each_entry_safe(event, next_event, &client->event_list, link) kfree(event); diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 8cace026090c..57d101c01e36 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include --=20 2.43.0