From nobody Tue Feb 10 11:14:38 2026 Received: from fout-a6-smtp.messagingengine.com (fout-a6-smtp.messagingengine.com [103.168.172.149]) (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 918CB22B5A3 for ; Sat, 10 Jan 2026 01:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768009160; cv=none; b=W+BdkJNSgP/OV7G0vRBX864neqX6CmOZlQC4URZva/naZg9U/CXoqI66FY8aWPjIVdhE5xhIwHgSIzgPR4x12h1YePLTh9qznq7odWz3ecjAgE1wl9kMPkdszIB7quETum+sZoenf2m0g+JbwLu6nxFaIMA8R466muj5s27xJ6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768009160; c=relaxed/simple; bh=h0ShMIi+pT6lnNcWSLqshk/hcavuY6GKaZQdB5PEuvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9bk+v9LjIgvZoXi7f2YEgWNAYbI7TzK6I9kY5KbX3slaaQrJk6Cr5ELg7utuJGIoqcoPtZ6de+PE3IxXAXb0i5RtPSABNJsXS8ZQqtxwUOxle0v6QjqMWkbeWSvH6gCeAzUv5jCIV/vk8splXGWQgXK1+66q2SwLF9xlyQrAmQ= 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=etsWmFQo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=M+JabEGm; arc=none smtp.client-ip=103.168.172.149 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="etsWmFQo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="M+JabEGm" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id CF868EC0129; Fri, 9 Jan 2026 20:39:17 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 09 Jan 2026 20:39:17 -0500 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=fm2; t=1768009157; x= 1768095557; bh=bgkZrJie3U4WbN7TceY0STDRrtzjsYUXJEYO4Gsh+BM=; b=e tsWmFQoz+XriFWomAAAf0Dc0w47MIwLofnUqktEz7cjZpVG2vSiyNPFctLLrUXPl Z3sm0wHzofEIXZN/eCM0+VkU9j5+ixbWP0hLq+0FbOqq3Mn7tpaI7vhi5SwDTMMn q4gNcCRmShSTiWfq5KaSPQBx1Yk2t54fInzsxMOOKoFuLO7fiR1EH24Inz+oXn5N 5dK5i0kBhlzjTKLB/gaLb331LTV2mwfytctDZShwcwoRa1i09O9Ww+lm40PvqgsG sED92t+mzDBQEjicFF2NgVbXs3RTNO2zqqPcq9oAFCxIb2thbzwC1JnpBYaL56P/ k7Q0YG52yWN/oyeHK/llQ== 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-sender :x-me-sender:x-sasl-enc; s=fm2; t=1768009157; x=1768095557; bh=b gkZrJie3U4WbN7TceY0STDRrtzjsYUXJEYO4Gsh+BM=; b=M+JabEGmT3ucfjEyp TLlwMMYViq7IzrPGWeIKmxI4r2tDEqWNX3tKB69qqQg6a/uM+32Rz8xMoReXUzxt gHIkWb9ZnOeTIx8/iqJoMrSbNxMYOQEqdgzSVVnk9fT428hl+0sUCYAoFZ5AVCOJ Lyz7bGx18V+vfUROdnTUYdf9xonRMx3Gdz15WiK5y1aNnIewQthUhIt90Pk9W3X3 2+/h5OmvnsgwPYcXCIe2Yo6s6o7pZSBBXUc23WapLvaTau8qW4E75hu+BSblDW0A di0cQdj97m1pou3guLuHPp6wYAgC52eBBAMmcAre2NDhhg6+a/xOQjyIkAFg7Jl8 cppyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduuddtfeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgjeeuvd fguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvghlsehlihhsthhsrdhsohhurh gtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhgghesnhhvihguihgrrdgtohhm X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jan 2026 20:39:16 -0500 (EST) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, jgg@nvidia.com Subject: [PATCH 2/8] firewire: core: use mutex instead of spinlock for client isochronous context Date: Sat, 10 Jan 2026 10:39:05 +0900 Message-ID: <20260110013911.19160-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260110013911.19160-1-o-takashi@sakamocchi.jp> References: <20260110013911.19160-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" There is a restriction that the userspace client associated to a file descriptor can hold one isochronous context. The client-level spinning lock is used to guarantee it, however the lock is also used for multi-purposes. Additionally, there is no need to use this type of lock, and the mutex is available, instead. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 40 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 49dc1612c691..2b8a878c8aae 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -63,6 +63,7 @@ struct client { u64 bus_reset_closure; =20 struct fw_iso_context *iso_context; + struct mutex iso_context_mutex; u64 iso_closure; struct fw_iso_buffer buffer; unsigned long vm_start; @@ -306,6 +307,7 @@ static int fw_device_op_open(struct inode *inode, struc= t file *file) INIT_LIST_HEAD(&client->phy_receiver_link); INIT_LIST_HEAD(&client->link); kref_init(&client->kref); + mutex_init(&client->iso_context_mutex); =20 file->private_data =3D client; =20 @@ -1088,26 +1090,27 @@ static int ioctl_create_iso_context(struct client *= client, union ioctl_arg *arg) context->drop_overflow_headers =3D true; =20 // We only support one context at this time. - guard(spinlock_irq)(&client->lock); - - if (client->iso_context !=3D NULL) { - fw_iso_context_destroy(context); - - return -EBUSY; - } - if (!client->buffer_is_mapped) { - ret =3D fw_iso_buffer_map_dma(&client->buffer, - client->device->card, - iso_dma_direction(context)); - if (ret < 0) { + scoped_guard(mutex, &client->iso_context_mutex) { + if (client->iso_context !=3D NULL) { fw_iso_context_destroy(context); =20 - return ret; + return -EBUSY; } - client->buffer_is_mapped =3D true; + // The DMA mapping operation is available if the buffer is already alloc= ated by + // mmap(2) system call. If not, it is delegated to the system call. + if (!client->buffer_is_mapped) { + ret =3D fw_iso_buffer_map_dma(&client->buffer, client->device->card, + iso_dma_direction(context)); + if (ret < 0) { + fw_iso_context_destroy(context); + + return ret; + } + client->buffer_is_mapped =3D true; + } + client->iso_closure =3D a->closure; + client->iso_context =3D context; } - client->iso_closure =3D a->closure; - client->iso_context =3D context; =20 a->handle =3D 0; =20 @@ -1826,7 +1829,9 @@ static int fw_device_op_mmap(struct file *file, struc= t vm_area_struct *vma) if (ret < 0) return ret; =20 - scoped_guard(spinlock_irq, &client->lock) { + scoped_guard(mutex, &client->iso_context_mutex) { + // The direction of DMA can be determined if the isochronous context is = already + // allocated. If not, the DMA mapping operation is postponed after the a= llocation. if (client->iso_context) { ret =3D fw_iso_buffer_map_dma(&client->buffer, client->device->card, iso_dma_direction(client->iso_context)); @@ -1879,6 +1884,7 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) =20 if (client->iso_context) fw_iso_context_destroy(client->iso_context); + mutex_destroy(&client->iso_context_mutex); =20 if (client->buffer.pages) fw_iso_buffer_destroy(&client->buffer, client->device->card); --=20 2.51.0