mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/9] firewire: cdev: add context analysis annotations for isochronous context
Date: Mon, 2 Nov 2026 19:40:42 +0900	[thread overview]
Message-ID: <20261102104042.GA1197999@sakamocchi.jp> (raw)
In-Reply-To: <20261102041913.1187814-4-o-takashi@sakamocchi.jp>

On Mon, Nov 02, 2026 at 01:19:07PM +0900, Takashi Sakamoto wrote:
> A client can operate on a single isochronous context at a time. A mutex
> is used to ensure exclusive access to the context.
> 
> Use guard annotations to describe the synchronization requirements for
> accessing the context.
> 
> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> ---
>  drivers/firewire/core-cdev.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
> index 512afa589e2e..418b72cb8835 100644
> --- a/drivers/firewire/core-cdev.c
> +++ b/drivers/firewire/core-cdev.c
> @@ -62,7 +62,7 @@ struct client {
>  	wait_queue_head_t tx_flush_wait;
>  	u64 bus_reset_closure;
>  
> -	struct fw_iso_context *iso_context;
> +	struct fw_iso_context *iso_context __pt_guarded_by(iso_context_mutex);
>  	struct mutex iso_context_mutex;
>  	u64 iso_closure;
>  	struct fw_iso_buffer buffer;
> @@ -1129,8 +1129,11 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
>  static int ioctl_set_iso_channels(struct client *client, union ioctl_arg *arg)
>  {
>  	struct fw_cdev_set_iso_channels *a = &arg->set_iso_channels;
> -	struct fw_iso_context *ctx = client->iso_context;
> +	struct fw_iso_context *ctx;
>  
> +	guard(mutex)(&client->iso_context_mutex);
> +
> +	ctx = client->iso_context;
>  	if (ctx == NULL || a->handle != 0)
>  		return -EINVAL;
>  
> @@ -1149,12 +1152,15 @@ static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg)
>  {
>  	struct fw_cdev_queue_iso *a = &arg->queue_iso;
>  	struct fw_cdev_iso_packet __user *p, *end, *next;
> -	struct fw_iso_context *ctx = client->iso_context;
> +	struct fw_iso_context *ctx;
>  	unsigned long payload, buffer_end, transmit_header_bytes = 0;
>  	u32 control;
>  	int count;
>  	DEFINE_RAW_FLEX(struct fw_iso_packet, u, header, 64);
>  
> +	guard(mutex)(&client->iso_context_mutex);

Sashiko reports that get_user()/copy_from_user() under mutex locking can
cause A-B/B-A deadlock between the above mutex and mm->mmap_lock.

https://sashiko.dev/#/patchset/20261102041913.1187814-1-o-takashi%40sakamocchi.jp

Let me rework for the series.

> +	ctx = client->iso_context;
>  	if (ctx == NULL || a->handle != 0)
>  		return -EINVAL;
>
> @@ -1252,6 +1258,8 @@ static int ioctl_start_iso(struct client *client, union ioctl_arg *arg)
>  	    FW_CDEV_ISO_CONTEXT_MATCH_TAG3 != FW_ISO_CONTEXT_MATCH_TAG3 ||
>  	    FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS != FW_ISO_CONTEXT_MATCH_ALL_TAGS);
>  
> +	guard(mutex)(&client->iso_context_mutex);
> +
>  	if (client->iso_context == NULL || a->handle != 0)
>  		return -EINVAL;
>  
> @@ -1267,6 +1275,8 @@ static int ioctl_stop_iso(struct client *client, union ioctl_arg *arg)
>  {
>  	struct fw_cdev_stop_iso *a = &arg->stop_iso;
>  
> +	guard(mutex)(&client->iso_context_mutex);
> +
>  	if (client->iso_context == NULL || a->handle != 0)
>  		return -EINVAL;
>  
> @@ -1277,6 +1287,8 @@ static int ioctl_flush_iso(struct client *client, union ioctl_arg *arg)
>  {
>  	struct fw_cdev_flush_iso *a = &arg->flush_iso;
>  
> +	guard(mutex)(&client->iso_context_mutex);
> +
>  	if (client->iso_context == NULL || a->handle != 0)
>  		return -EINVAL;
>  
> @@ -1937,8 +1949,10 @@ static int fw_device_op_release(struct inode *inode, struct file *file)
>  	scoped_guard(mutex, &client->device->client_list_mutex)
>  		list_del(&client->link);
>  
> -	if (client->iso_context)
> -		fw_iso_context_destroy(client->iso_context);
> +	scoped_guard(mutex, &client->iso_context_mutex) {
> +		if (client->iso_context)
> +			fw_iso_context_destroy(client->iso_context);
> +	}
>  	mutex_destroy(&client->iso_context_mutex);
>  
>  	if (client->buffer.pages)
> -- 
> 2.53.0

Regards

Takashi Sakamoto

  reply	other threads:[~2026-11-02 10:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  4:19 [PATCH 0/9] firewire: cdev: add annotations for compiler-based context analysis Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 1/9] firewire: core: add context analysis annotations for address handler Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 2/9] firewire: cdev: add context analysis annotations for phy_receiver_list Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 3/9] firewire: cdev: add context analysis annotations for isochronous context Takashi Sakamoto
2026-11-02 10:40   ` Takashi Sakamoto [this message]
2026-11-02  4:19 ` [PATCH 4/9] firewire: cdev: annotate data length in inbound_transaction_resource Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 5/9] firewire: core: add context analysis annotation to queue_bus_reset_event() Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 6/9] firewire: cdev: add context analysis annotations for client shutdown flag and event list Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 7/9] firewire: cdev: use cleanup function for outbound transaction event allocation Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 8/9] firewire: cdev: use cleanup function for descriptor_resource allocation Takashi Sakamoto
2026-11-02  4:19 ` [PATCH 9/9] firewire: cdev: enable compiler-based context analysis Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261102104042.GA1197999@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®